<?php
include_once('c_poll_theme_card.php');
class c_page_cab_poll_theme_card_editor extends c_page_cab_poll_theme_card
{
    public $h1='Опрос - карточка темы - редактировать';
    var $use_textarea_autosize=0 ;
    var $use_ckeditor5=0 ;
    var $arr_moment=array(1=>'После авторизации',2=>'Во время измерения давления',3=>'Перед подписью') ;
    var $arr_allow_days=array(0=>'Все',1=>'Нечетные',2=>'Четные') ;

    function block_main()
    {
        $this->page_title();
        $this->panel_poll_theme() ;
    }

    function panel_poll_theme()
    {
        $arr_groups=execSQL('select pkey,parent,obj_name from obj_site_account where clss in (1,206) order by parent,obj_name');
        $arr_groups2=$arr_groups;
        convert_list_to_tree($arr_groups2,$arr_tree);
        $this->convert_tree_to_select_options_arr($arr_tree,$arr_groups,$options_list);

        //damp_array($rec_rasdel);
        $form=new i_form();
        $form->form_open(array('class'=>'form-horizontal','col_count'=>6,'col_count_title'=>3,'post_array_name'=>'section')) ;
        $form->filter_section_input_text('name','Название раздела:',4,array('cur_value'=>$this->rec_section['obj_name'],'required'=>1));
        $form->section_radio(['name'=>'enabled','title'=>'Активность','cur_value'=>$this->rec_section['enabled'],'recs'=>[1=>'Включено',0=>'Выключено']]);
        //$form->filter_section_input_text('date_from','Начало опроса',4,array('class'=>'datepicker','value'=>($this->rec_section['date_from'])? date('d.m.Y',$this->rec_section['date_from']):''));
        //$form->filter_section_input_text('date_to','Окончание опроса',4,array('class'=>'datepicker','value'=>($this->rec_section['date_to'])? date('d.m.Y',$this->rec_section['date_to']):''));
        //$form->filter_section_select_multiple('group_ids','Место проведения опроса',8,$options_list,array('cur_values'=>$this->rec_section['group_ids'],'nospace_element'=>1));
        //$form->filter_section_select('allow_days','Дни проведения опроса',8,$this->arr_allow_days,array('cur_value'=>$this->rec_section['allow_days'],'nospace_element'=>1));
        //$form->filter_section_select('moment','Момент проведения опроса (на терминале МТ)',8,$this->arr_moment,array('cur_value'=>$this->rec_section['moment'],'nospace_element'=>1));

        $form->button('Сохранить','poll/section_save',['item_id'=>$this->rec_section['pkey'],'item_type'=>'theme','id'=>'button_save']);
        if ($this->rec_section['parent']>0) $form->button('Удалить раздел','poll/get_panel_theme_delete',['item_id'=>$this->rec_section['pkey'],'item_type'=>'theme']);
        $form->button('Экспортировать раздел','poll/get_panel_theme_export',['id'=>$this->rec_section['pkey'],'item_type'=>'theme']);
        $form->row_close();
        $form->form_close();


    }

     function panel_params_edit_left()
    {
        $arr_groups=execSQL('select pkey,parent,obj_name from obj_site_account where clss in (1,206) order by parent,obj_name');
        $arr_groups2=$arr_groups;
        convert_list_to_tree($arr_groups2,$arr_tree);
        $this->convert_tree_to_select_options_arr($arr_tree,$arr_groups,$options_list);

        $form=new i_form(['post_array_name'=>'data']);
        $form->form_open();
        $form->row_open();
        if(!$this->rec_event['date_from']) $this->rec_event['date_from']=time();
        if(!$this->rec_event['date_to']) $this->rec_event['date_to']=time();
        ?><input type="hidden" name="data[dyn_pass]" value="1"><?


        $form->label('Наименование мероприятия:',4);
        $form->filter_section_input_text('name','',8,array('value'=>$this->rec_event['obj_name']));
        $form->label('Переодичность прохождения:',4);
        $form->filter_section_select('close_period','',8,POLL()->arr_events_close_period,array('cur_value'=>$this->rec_event['_ext_info']['close_period'],'nospace_element'=>1));
        $form->label('Условия прохождения:',4);
        $form->filter_section_select('close_status','',8,POLL()->arr_events_close_status,array('cur_value'=>$this->rec_event['_ext_info']['close_status'],'nospace_element'=>1));
        $form->label('Срок проведения:',4);
        $form->filter_section_input_text('date_from','',4,array('class'=>'datepicker','value'=>date('d.m.Y',$this->rec_event['date_from'])));
        $form->filter_section_input_text('date_to','',4,array('class'=>'datepicker','value'=>date('d.m.Y',$this->rec_event['date_to'])));
        $form->label('Место доведения контента:',4);
        $form->filter_section_select_multiple('group_ids','',8,$options_list,array('cur_values'=>$this->rec_event['_ext_info']['group_ids'],'nospace_element'=>1));
        $form->label('Дни показа контента:',4);
        $form->filter_section_select('allow_days','',8,$this->obj_event->arr_allow_days,array('cur_value'=>$this->rec_event['_ext_info']['allow_days'],'nospace_element'=>1));
        $form->label('Архив:',4);
        ?>
        <section class="col col-4">
        <input type="hidden" name="data[arhive]" value="0">
        <label class="checkbox"><input type="checkbox" name="data[arhive]" value="1" <? if($this->rec_event['status']==5) echo 'checked' ?>><i></i> В архиве</label>
        </section><?

        $form->row_close();
        $form->panel_button_apply(array('cmd_method'=>'v1','cmd'=>'save_event'));
        /*?><input type="hidden" name="data[enabled]" value="1"><?*/
        $form->form_close();
        //damp_array($form) ;
        //damp_array($this->rec_event) ;
    }

    function panel_poll_editor()
            {  ?><!-- This container will become the editable. -->
               <div class="document-editor">
                   <div id="container">
                       <div class="document-editor__editable-container">
                           <div id="editor" class="document-editor__editable"><?
                               if (!$this->rec_section['json_data']) echo $this->rec_section['manual'] ;

                               //echo $this->rec_section['manual']
                               ?></div>
                       </div>
                   </div>
               </div>
                <script type="text/javascript">
                var section_id=<?echo $this->rec_section['pkey']?> ;
                $j(document).ready(function()
                { // Application data will be available under a global variable `appData`.
                  ClassicEditor.create( document.getElementById( 'editor' ),
                          {   language: 'ru',
                              toolbar: {
                                      items: [
                                        'heading', 'insertTable', 'bold', 'italic', 'link', 'undo', 'redo',  'bulletedList', 'numberedList'
                                      ]
                                    },
                              table: {
                                contentToolbar: ['tableColumn', 'tableRow', 'mergeTableCells']
                              },
                              restrictedEditing: {
                                      allowedCommands: ['knowledgebase'],
                                      allowedAttributes: ['kbarticle']
                                    },
                              //blockToolbar: ['knowledgebase'],
                              //extraPlugins: [ 'ConvertDivAttributes' ],
                          }
                   		)
                   			.then( editor => {
                   				window.editor = editor;
                   				console.log('then') ;
                                <?if ($this->rec_section['json_data']) {?>editor.setData(JSON.parse('<?echo $this->rec_section['json_data']?>')) ;<?}?>
                   			} )
                   			.catch( error => {
                   				console.error( 'There was a problem initializing the editor.', error );
                   			} );

                }) ;

                </script><?

            }
}

?>
