<?php
include_once("c_events.php");
include_once(_DIR_EXT.'/esmo_magnit_instruction/i_event_instruction.php');
class c_page_cab_events_new extends c_page_cab_events
{
  public $h1='Новое мероприятие' ;
  var $rec_event ;
  var $obj_event ;

  var $arr_events=array('esmo_magnit_pmo/i_event_pmo',
                        'esmo_magnit_instruction/i_event_instruction1',
                        'esmo_magnit_instruction/i_event_instruction2',
                        'esmo_magnit_instruction/i_event_instruction3',
                        'esmo_magnit_instruction/i_event_training',
                        'events_meeting/i_event_meeting',
                        'events_docs/i_event_docs',
                        'events_opo/i_event_opo',
                       ) ;

  function __construct($options = array())
  { parent::__construct($options);
    if ($GLOBALS['_SETTING']['modules']['quiz']) $this->arr_events[]='events_quiz/i_event_quiz' ;
    if ($GLOBALS['_SETTING']['modules']['media_content']) $this->arr_events[]='events_media/i_event_media' ;
    if ($GLOBALS['_SETTING']['modules']['poll']) $this->arr_events[]='events_poll/i_event_poll' ;
  }

  function CMD_create_event()
  {
     if ($_POST['filter']['type'] and isset($this->arr_events[$_POST['filter']['type']-1]))
     { $event_ext=$this->arr_events[$_POST['filter']['type']-1] ;
       $this->obj_event=EVENTS()->get_event_obj_by_ext($event_ext) ;
       if (!$this->obj_event->error)
         { $this->obj_event->default_settings['ext']=$event_ext ;
           $id=EVENTS()->reg_event($this->obj_event->default_settings) ;
           ?><script type="text/javascript">
             window.open("<?echo $this->obj_event->url_page_event_card.$id.'/edit/step1/'?>",'111','status=1,dependent=1,width='+LS_popup_window_width+',height='+LS_popup_window_height+',left=0,top=0, resizable=1, scrollbars=yes');
            </script><?
           //redirect_301_to($this->obj_event->url_page_event_card.$id.'/edit/step1/') ;
           //echo 'Редирект на страницу <strong>'.$this->obj_event->url_page_event_create.'</strong><br>' ;
         } else echo '<strong>'.$event_ext.'</strong> '.$this->obj_event->error.'<br>' ;
     }
      //damp_array($_POST) ;
      //$event_id=EVENTS()->reg_event($_POST['filter']) ;
      //if ($event_id) redirect_301_to('/cab/events/new/step2/[event_id='.$event_id.']/') ;
  }

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

  function panel_event_create($options=array())
  {  $arr_select_items=array() ;
     if (_sizeof($this->arr_events)) foreach($this->arr_events as $event_ext)
     {  $this->obj_event=EVENTS()->get_event_obj_by_ext($event_ext) ;
        if (!$this->obj_event->error) $arr_select_items[]=$this->obj_event->name ;
        else echo '<strong>'.$event_ext.'</strong> '.$this->obj_event->error.'<br>' ;
     }
      ?><div id="panel_filter">
            <form id="sky-form" class="sky-form">
                 <fieldset>
                     <h2>Выберите тип мероприятия</h2><br>
                     <div class="row">
                           <section class="col col-4">
                             <label class="label">Тип мероприятия:</label>
                             <label class="select">
                                 <select name="filter[type]" data-required><option></option>
                                   <? if ($arr_select_items) foreach($arr_select_items as $indx=>$name)
                                   {  ?><option value="<?echo $indx+1?>"><?echo $name?></option><?

                                   }?>
                                 </select>
                             </label>
                            </section>
                         <section class="col col-2">
                             <label class="label"></label>
                             <label><input type="submit" class="button v1" cmd="create_event" value="Далее" validate="form" style="float:left;position:relative;top:8px;margin-left:0;"></label>
                            </section>
                     </div>
                 </fieldset>
             </form>
      </div><br>
    <?
  }

}



?>
