<?php
include_once('c_events_event_pass.php');
class c_page_cab_events_event_pass_db extends c_page_cab_events_event_pass
{
  public $h1='Карточка участника мероприятия - исходные данные' ;

  function block_main()
  { $this->page_title() ;
    $arr=[$this->rec_pass] ;
	print_2x_arr($arr) ;
	?><h2>История статусов участия в мероприятии</h2><?
	$rec_history=execSQL('select * from obj_site_events_pass_status where event_id='.$this->rec_event['pkey'].' and personal_id='.$this->rec_personal['pkey'].' order by pkey') ;
	print_2x_arr($rec_history) ;
	?><h2>Сообщения, связанные с данным участием</h2><?
	$rec_mess=execSQL('select * from obj_site_personal_mess where personal_id='.$this->rec_personal['pkey'].' order by pkey') ;
	print_2x_arr($rec_mess) ;

/*	?><h2>История показа медиаконтента</h2><?
	$rec_history=execSQL('select * from media_content_view where event_id='.$this->rec_event['pkey'].' and personal_id='.$this->rec_personal['pkey'].' order by pkey') ;
	print_2x_arr($rec_history) ;
*/


    ?><h3>Изменить данные</h3><?
    $event_obj=EVENTS()->get_event_obj_by_id($this->rec_pass['event_id']) ;
    $this->form->form_open();
    $this->form->row_open();
    $this->form->section_select(['title'=>'Статус','name'=>'status','recs'=>$event_obj->arr_status,'value'=>$this->rec_pass['status']]);
    $this->form->section_input(['title'=>'Срок действия от','name'=>'data_from','class'=>'datetimepicker','cur_value'=>(($this->rec_pass['data_from'])? date('d.m.Y H:i:s',$this->rec_pass['data_from']):'')]);
    $this->form->section_input(['title'=>'Срок действия до','name'=>'data_to','class'=>'datetimepicker','cur_value'=>(($this->rec_pass['data_to'])? date('d.m.Y H:i:s',$this->rec_pass['data_to']):'')]);
    $this->form->row_close();
    ?><div class="left"><input type="submit" class="button v2" cmd=events/pass_save value="Применить" pass_id=<?echo $this->rec_pass['pkey']?> style="float:none;" value="Сохранить"></div><?
    $this->form->form_close();

    if (method_exists($event_obj,'check_personals_status')) $event_obj->check_personals_status($this->rec_pass['personal_id']) ;


    ?>
      <?

    ?>
      <form method="post" style="width:150px;">
          <h3>Отменить статус</h3><input type="text" name="repeat_to_pass_status" value="<? ?>"><input type="submit" class="button" value="Применить">
      </form>
      <div class="clear"></div>
      <?

    //damp_array($this->rec_event);

  }

  function select_obj_info()
  {   parent::select_obj_info();
      if ($_POST['new_status'])
      { if ($_POST['new_status']==1) PERSONAL()->messages_personal_close($this->rec_personal['pkey'],$this->rec_event['ext'],['event_id'=>$this->rec_event['pkey'],'comment'=>'Ручной перевод в статус 1']) ;
        EVENTS()->set_personals_status($this->rec_event['pkey'],$this->rec_personal['pkey'],$_POST['new_status']) ;
        execSQL_update('delete from obj_site_events_pass_status where event_id='.$this->rec_event['pkey'].' and personal_id='.$this->rec_personal['pkey'],array('debug'=>0)) ;
        execSQL_update('delete from media_content_view where event_id='.$this->rec_event['pkey'].' and personal_id='.$this->rec_personal['pkey'],array('debug'=>0)) ;

      }
      if ($_POST['repeat_to_pass_status'])
      {
          execSQL_update('delete from obj_site_events_pass_status where event_id='.$this->rec_event['pkey'].' and personal_id='.$this->rec_personal['pkey'].' and pkey>'.$_POST['repeat_to_pass_status'],array('debug'=>2)) ;
          $last_status=execSQL_value('select status_new from obj_site_events_pass_status where pkey='.$_POST['repeat_to_pass_status']) ;
          execSQL_update('update obj_site_events_pass set status='.$last_status.' where event_id='.$this->rec_event['pkey'].' and personal_id='.$this->rec_personal['pkey'],array('debug'=>2)) ;

      }
	  parent::select_obj_info();
  }
}



?>
