<?php
include_once("c_events_media_card.php");
class c_page_cab_events_media_card_edit_step1 extends c_page_cab_events_media_card
{
  public $h1='Редактирование параметров доведения контента' ;
  var $after_save_url ;
  var $use_highslide=1 ;

  function second_menu_config()
  {  if ($this->rec_event['pkey'])
       { $this->second_menu['/window/events_media/card/'.$this->rec_event['pkey'].'/edit/step1/']='Параметры мероприятия' ;
         $this->second_menu['/window/events_media/card/'.$this->rec_event['pkey'].'/edit/step2/']='Выбор участников' ;
       }
  }
   
  function block_main()
  { $this->page_title() ;
    $this->panel_params_edit() ;   // вызываем панель настроек из класса
    $this->panel_report() ;
    //damp_array($this->rec_event,1,-1) ;
  }

  function CMD_save_event()
  { // проверка, что данный тип документа еще не покрыт мероприятием
    if (!isset($_POST['data']['group_ids'])) $_POST['data']['group_ids']=array() ;
  	EVENTS()->save_events($this->rec_event['pkey'],$_POST['data']) ;
    $this->select_obj_info() ;
  }

  function panel_params_edit()
  {  ?><table class="col2x"><tr><td><?$this->panel_params_edit_left()?></td><td><?$this->panel_append_content()?></td></tr></table>
       <style type="text/css">
           table.col2x{}
           table.col2x td{vertical-align:top;}
       </style>
      <?
  }


  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 ; $options_list=array() ; $arr_tree=array() ;
          convert_list_to_tree($arr_groups2,$arr_tree) ;
          $this->convert_tree_to_select_options_arr($arr_tree,$arr_groups,$options_list) ;

         //damp_array($this->rec_event) ;

          $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() ;
          $form->label('Активность:',4) ;
          ?><section class="col col-8">
                                  <label class="radio"><input type="radio" name="data[enabled]" value="1" <?if ($this->rec_event['enabled']) echo 'checked'?>><i></i> Включено</label>
                                  <label class="radio"><input type="radio" name="data[enabled]" value="0" <?if (!$this->rec_event['enabled']) echo 'checked'?>><i></i> Выключено </label>
            </section><?
          
          $form->label('Наименование мероприятия:',4) ;
          $form->filter_section_input_text('name','',8,array('value'=>$this->rec_event['obj_name'])) ;
          $form->label('Срок действия, от:',4) ;
          $form->filter_section_input_text('date_from','',8,array('class'=>'datepicker','value'=>date('d.m.Y',$this->rec_event['date_from']))) ;
          $form->label('Срок действия, до:',4) ;
          $form->filter_section_input_text('date_to','',8,array('class'=>'datepicker','value'=>date('d.m.Y',$this->rec_event['date_to']))) ;
          $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) ;
          $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('mo_content_mode','',8,$this->obj_event->arr_mo_content_mode,array('cur_value'=>$this->rec_event['_ext_info']['mo_content_mode'],'nospace_element'=>1)) ;
          $form->label('Порядок доведения контента:',4) ;
          $form->filter_section_select('select_content_mode','',8,$this->obj_event->arr_select_content_mode,array('cur_value'=>$this->rec_event['_ext_info']['select_content_mode'],'nospace_element'=>1)) ;
          $form->label('Объем доведения контента<br>(для прохождения мероприятия):',4) ;
          $form->filter_section_select('full_content_mode','',8,$this->obj_event->arr_full_content_mode,array('cur_value'=>$this->rec_event['_ext_info']['full_content_mode'],'nospace_element'=>1)) ;
          $form->row_close() ;
          $form->panel_button_apply(array('cmd_method'=>'v1','cmd'=>'save_event'));
          /*?><input type="hidden" name="filter[enabled]" value="1"><?*/
          $form->form_close() ;
          //damp_array($form) ;
      }


  function panel_append_content()
  { ?><div style="margin:10px 0;text-align:center;">
          <button class="select_media_content" desc="media_text">Текст</button>
          <button class="select_media_content" desc="media_photo">Фото</button>
          <button class="select_media_content" desc="media_video">Видео</button>
      </div>
    <form>
    <? include(_DIR_EXT.'/upload_files/panel_upload_files.php')  ;?>
    <div id="panels_content">
        <div id="media_text" class="panel_content" style="font-size:18px;text-align:center;">
            <textarea style="width:400px;height:150px;font-size:18px;text-align:center;" name="event_text"><?/*echo htmlspecialchars($this->rec_event['_ext_info']['message1'])*/?></textarea>
            <button class="v2" cmd="events_media/append_event_text" event_id="<?echo $this->rec_event['pkey']?>">Добавить текст</button>
        </div>
        <div id="media_photo" class="panel_content hidden">
            <? panel_upload_files(array('text'=>'Перетяните и отпустите сюда<br>изображение',
                                       'upload_url'=>'/services/events_media/upload_file/',
                                       'upload_params'=>array('event_id'=>$this->rec_event['pkey']),
                                       'file_filter'=>'jpg;',
                                       'SendFormOnUploadSuccess'=>0,
                                       'view_debug_panel'=>0,
                                       'style_panel'=>'width:400px;margin:20px auto;',
                                       'onUploadSuccessFunction'=>'onUploadSuccessFunction',
                      )) ;
            ?>
        </div>
        <div id="media_video" class="panel_content hidden">
            <?  panel_upload_files(array('text'=>'Перетяните и отпустите сюда<br>видео',
                                         'upload_url'=>'/services/events_media/upload_file/',
                                         'upload_params'=>array('event_id'=>$this->rec_event['pkey']),
                                          'file_filter'=>'mkv;avi;3gp;mp4;mpeg;',
                                          'SendFormOnUploadSuccess'=>0,
                                          'view_debug_panel'=>0,
                                          'style_panel'=>'width:400px;margin:20px auto;;',
                                          'onUploadSuccessFunction'=>'onUploadSuccessFunction',
                                    )) ;
        ?></div>

    </div><div class="clear"></div>
    </form>
    <style type="text/css">
      div#panels_content{position:relative;width:500px;margin:0 auto;}
      div#panels_content div#media_text textarea{padding:10px;margin-bottom:10px;}
      div#panels_content div#panel_file_upload{float:left;}
      div#panels_content div#report{float:left;}
      div#panels_content div#debug{float:left;clear:none;}
    </style>
    <script type="text/javascript">
     $j(document).ready(function()
     {
        //$j('body').on('button.select_media_content','click',function()
        $j('button.select_media_content').on('click',function()
        {
          var desc=$j(this).attr('desc') ;
          console.log(desc) ;
          $j('div#panels_content .panel_content').hide() ;
          $j('div#panels_content #'+desc+'.panel_content').show() ;

        })

      }) ;

     function  onUploadSuccessFunction(data)
     {
        console.log('===============') ;
        if (data.PanelReportHTML!=null) $j('div#panel_report').html(data.PanelReportHTML) ;
     }

    </script>
    <?
    //damp_array($this->rec_event) ;
  }

  function panel_report()
  { ?><div id="panel_report"><?
    include_once(_DIR_EXT.'/events_media/report_events_media_content.php') ;
    $report_obj=new report_events_media_content() ;
    $report_obj->filter['order']='pkey desc';
    $report_obj->event_id=$this->rec_event['pkey'] ;
    $report_obj->view() ;
    ?></div><?
  }



}



?>