<?
include_once(_DIR_EXT.'/HTML/c_page_XML_AJAX.php') ;
class c_page_ajax extends c_page_XML_AJAX
{
   function help_content_save()
   {  $id=execSQL_value('select pkey from help_content where obj_name="'.$_POST['url'].'"') ;
	  $data=array('obj_name'=>$_POST['url'],'content'=>$_POST['CKeditor_content']) ;
	  if ($id) update_rec_in_table('help_content',$data,'pkey='.$id) ;
	  else     adding_rec_to_table('help_content',$data) ;
	  $this->add_element('show_notife','Сохранено',array('color'=>'green')) ;
	  $this->update_page=1;
       //damp_array($_POST) ;
	  //$this->add_element('show_modal_window','HTML',array('title'=>'HELP save')) ;   // показываем модальное окно
   }

   function edit_help_content()
   {   ob_start() ;
       ?><div id="panel_help_content_inner"><?
	       $cur_url=$_POST['url'] ;
		   ?><p><strong>Редактирование помощи для страницы "<?echo $cur_url?>"</strong></p><?
		   $form=new i_form() ;
		   $form->form_open() ;
		   $content=execSQL_value('select content from help_content where obj_name="'.$cur_url.'"') ;
		   $form->textarea_ckeditor('content',array('value'=>$content));
		   ?><br><input type="submit" class="btn btn-sm btn-primary v2" cmd="help/help_content_save" get_ckeditor_content=1 value="Сохранить" url="<?echo $cur_url?>"><?
		   $form->form_close() ;
	   ?></div>
	   <script type="text/javascript">
		   if (!$j('div#panel_help_content').hasClass('viewer')) $j('div#panel_help_content').toggleClass('open') ;
		   if ($j('div#panel_help_content').hasClass('open')) $j('div#panel_help_content').addClass('editor') ;
		   else                                               $j('div#panel_help_content').removeClass('editor') ;
		   $j('div#panel_help_content').removeClass('viewer') ;
	   </script>
	   <?
	   $text=ob_get_clean() ;
	   $this->add_element('panel_help_content.HTML',$text) ;
   }

   function get_help_content()
   {   ob_start() ;
	   ?><div id="panel_help_content_inner"><i class="fa fa-info-circle"></i><?
           $cur_url=$_POST['url'] ;
           $content=execSQL_value('select content from help_content where obj_name="'.$cur_url.'"') ;
           echo $content ;
	       /*?><button class="btn btn-sm btn-primary v2" cmd="help/help_content_close">Закрыть</button><?*/
	   	   ?><script type="text/javascript">
	        if (!$j('div#panel_help_content').hasClass('editor')) $j('div#panel_help_content').toggleClass('open') ;
	        if ($j('div#panel_help_content').hasClass('open')) $j('div#panel_help_content').addClass('viewer') ;
	        else                                               $j('div#panel_help_content').removeClass('viewer') ;
		    $j('div#panel_help_content').removeClass('editor') ;
	       </script><?
	   ?></div><?
       $text=ob_get_clean() ;
       $this->add_element('panel_help_content.HTML',$text) ;
   }

   function help_content_close()
   {
	   $this->add_element('panel_help_content.HTML','') ;
   }
}
