<?php
include_once("c_events_quiz_card_edit_step1.php");
class c_page_cab_events_quiz_card_edit_step3 extends c_page_cab_events_quiz_card_edit_step1
{
  public $h1='Редактирование параметров собрания - выбор тем КЗ' ;

  function select_obj_info()
  {  parent::select_obj_info();
     if ($this->rec_event['pkey'])
     { $this->h1=$this->obj_event->name.' "'.$this->rec_event['obj_name'].'" - выбор тем КЗ' ;
       if ($this->rec_event['enabled']) $this->after_save_url=$this->rec_event['__href'].'edit/step2/' ;
       else                             $this->after_save_url=$this->rec_event['__href'].'edit/step3/' ;
     }
  }


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

    function panel_select_themes($options=array())
        { ?>
            <link href="/<? echo _CLASS_ ?>/ext/interface/jfinder/finderjs.css" media="all" rel="stylesheet">
            <script src="/<? echo _CLASS_ ?>/ext/interface/jfinder/jquery.finder.js"></script>
            <script src="/<? echo _CLASS_ ?>/ext/interface/jfinder/script_jfinder.js"></script>
            <div id="panel_filter">
                <form id="sky-form" class="sky-form">
                    <? $arr_themes_ids=(_sizeof($this->rec_event['_ext_info']['themes_ids']))? array_keys($this->rec_event['_ext_info']['themes_ids']):[];
                    // удаляем ID родительской темы из списка, если в списке есть её потомки
                    if(_sizeof($arr_themes_ids)) $arr_themes_ids=$this->clear_parent_themes($arr_themes_ids);
                    $event_id=$this->rec_event['pkey'];
                    ?>
                    <label class="label"><strong>Темы контроля знаний</strong></label>
                    <div id="current_themes">
                        <ul>
                            <? if(_sizeof($arr_themes_ids)) foreach($arr_themes_ids as $theme_id)
                            {
                                $arr=TREE('quiz_themes')->get_arr_parents_names($theme_id,array('from_level'=>2));
                                $theme_full_name=implode(' / ',$arr);
                                ?>
                                <li><? echo $theme_full_name ?>
                                <input type="hidden" name="data[themes_ids][<? echo $theme_id ?>]" value="1">
                                <i class="fa fa-trash red v2" cmd="events_quiz/event_quiz_delete_theme" event_id="<? echo $event_id ?>" theme_id="<? echo $theme_id ?>"></i>
                                </li><?
                            }
                            ?>
                        </ul>
                    </div>
                    <br>
                    <div id="container_jfinder"></div>
                    <br>
                    <div id="panel_item"></div>

                    <script type="text/javascript">
                        $j('#container_jfinder').jfinder({
                                                             upload_url: '/services/events_quiz/get_themes/',
                                                             upload_params: {event_id:<?echo $this->rec_event['pkey']?>},
                                                             checkbox_name: 'data[themes_ids]',// element_click_cmd:  'quiz/get_panel_element',
                                                             debug: 0
                                                         });
                    </script>
                    <div id="panel_buttons">
                        <input type="submit" class="button v1" cmd="save_event" value="Сохранить" validate="form"></div>
                </form>
            </div><br>
            <style>
                div.event_info strong
                {font-size: 18px;font-weight: normal;}

                div#current_themes
                {margin-left: 20px;}

                label.label.info
                {color: #4CAF50;font-size: 12px;line-height: 1.2em;margin-top: 10px;}
            </style>

            <?
        }

        function clear_parent_themes($arr_ids)
        {
            $arr_result=$arr_ids;
            $recs=execSQL('select pkey,parent1,parent2,parent3,parent4,parent5,parent6,parent7,parent8,parent9 from quiz_themes where pkey in ('.implode(',',$arr_ids).')');
            if(_sizeof($arr_ids)) foreach($arr_ids as $i=>$id)
            {
                foreach($recs as $rec) if($id!=$rec['pkey'])
                {
                    if(!($id!=$rec['parent1'] and $id!=$rec['parent2'] and $id!=$rec['parent3'] and $id!=$rec['parent4'] and $id!=$rec['parent5'] and $id!=$rec['parent6'] and $id!=$rec['parent7'] and $id!=$rec['parent8'] and $id!=$rec['parent9'])) unset($arr_result[$i]);
                }
            }
            return ($arr_result);
        }

}
?>
