<?php
class report_events_media_content_info extends c_report
{
 var $title='Контент мероприятия' ;
 var $view_by_space_filter=1 ;
 var $event_id ;


 function setting($options=array())
 {
   //damp_array(ENGINE()->reports_list['napravlenie']['']) ;

   if ($this->ext)
   { $ext=str_replace('%','',$this->ext) ;
     if (_sizeof($this->arr_types))  foreach($this->arr_types as $code=>$title) if (strpos($code,$ext)!==false) $arr[$code]=$title ;
   } else $arr=$this->arr_types ;

      ?><div id="panel_filter">
             <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                  <fieldset>
                      <div class="row">
                          <?
                          $this->filter_section_input_text('name','Наименование:',2,array('_auto_complete'=>"autocomplette_personal_name")) ;
                          $this->filter_section_select('type','Тип мероприятия:',2,$arr) ;
                          //$this->filter_section_select('status','Статус мероприятия:',2,$_SESSION['ARR_events_status']) ;
                          $this->filter_section_input_text('data_from','От:',2,array('class'=>'datetimepicker')) ;
                          $this->filter_section_input_text('data_to','До:',2,array('class'=>'datetimepicker')) ;
                          ?>
                        </div>
                  </fieldset>
                  <?$this->panel_buttons();?>
              </form>
       </div><br>
     <?
  }

  function panel_report_buttons()
    { if (MEMBER()->rol==1)
      { if ($this->status!=5) {?><button use_form="form_report" class="button v2" cmd="events/check_to_arhive">В архив</button>&nbsp;&nbsp;<?}
    else                  {?><button use_form="form_report" class="button v2" cmd="events/check_out_arhive">Из архива</button>&nbsp;&nbsp;<?}
      }

  }

  function create_usl_select_obj($_params,&$options)
  {  $usl=array() ;
     //damp_array($this->filter) ;
     $usl[]='enabled=1' ;
     $usl[]='event_id='.$this->event_id ;

     /*if ($this->type) $usl[]='type='.$this->type ;
     if ($this->filter['group_id'])
     {   $arr1=ACCOUNTS()->tree[$this->filter['group_id']]->get_arr_child() ; echo '<br>' ;
         $arr2=ACCOUNTS()->tree[$this->filter['group_id']]->get_arr_parent() ; echo '<br>' ;
         $arr_ids=array_merge($arr1,$arr2) ;
         if (_sizeof($arr_ids)) $usl[]='group_id in ('.implode(',',$arr_ids).')'  ;
     }
     if ($this->filter['name'])        $usl[]='obj_name like "%'.$this->filter['name'].'%"' ;
     if ($this->filter['data_from'])        $usl[]='c_data>='.strtotime($this->filter['data_from']) ;
     if ($this->filter['data_to'])         $usl[]='c_data<='.strtotime($this->filter['data_to']) ;
     if ($this->status)                    $usl[]='status='.$this->status ;
      else                                 $usl[]='status!=5' ;
     if ($this->filter['status'])          $usl[]='status='.$this->filter['status'] ;
     if ($this->ext)                       $usl[]='ext like "'.$this->ext.'%"' ;
     if ($this->filter['type'])            $usl[]='ext="'.addslashes(str_replace('.','/',$this->filter['type'])).'"' ;
     // если у сотрудника есть фильтр по персоналу, то показывать только те мероприятия, в которых участвуют его сотрудники
     if (MEMBER()->rol!=1) // фильтр сортрудников аккаунта
      { $event_ids=execSQL_line('select distinct(event_id)
                                 from view_event_personals t1
                                 left join '.MEMBER()->personal_viewer_name.' t2 on t2.pkey=t1.personal_id
                                 where not t2.pkey is null
                                 ') ;
         if (_sizeof($event_ids)) $usl[]='pkey in ('.implode(',',$event_ids).')' ;
         else                    $usl[]=0 ;
      }

     */
     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl,1,-1) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   /*//if ($this->filter['group_id'])        $info['Группа']=ACCOUNTS()->get_member_name_by_id($this->filter['group_id']) ;
   //if ($this->filter['personal_id'])     $info['Сотрудник']=PERSONAL()->get_name_by_id($this->filter['personal_id']) ;
   if ($this->filter['name'])              $info['Наименование']='"'.htmlspecialchars_decode($this->filter['name']).'"' ;
   if ($this->filter['type'])              $info['Тип мероприятия']='"'.$this->arr_types[$this->filter['type']].'"' ;
   if ($this->filter['status'])            $info['Cтатус']='"'.$_SESSION['ARR_events_status'][$this->filter['status']].'"' ;
   if ($this->status)                      $info['Cтатус']='"'.$_SESSION['ARR_events_status'][$this->status].'"' ;
   if ($this->filter['data_from'])         $info['дата от']='"'.$this->filter['data_from'].'"' ;
   if ($this->filter['data_to'])           $info['дата до']='"'.$this->filter['data_to'].'"' ;
   */
   if (_sizeof($info)) foreach($info as $title=>$value) $_str[]=$title.': <strong>'.$value.'</strong>' ;
   if (_sizeof($_str)) $title='<p class=center>'.implode(' ',$_str).'</p>' ;
   return $title ;
 }

  function get_cnt_items($usl,$options=array())
  { $cnt=execSQL_value('select count(pkey)
                        from  media_content
                        where '.$usl,$options) ;
    return($cnt) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    //$order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by pkey desc' ;
    $order=($options['order'])? ' order by '.$options['order']:' order by pkey desc' ;
    //$options['debug']=2 ;
 	$list_rec=execSQL('select * from  media_content where '.$usl.$order.$limit,$options) ;
    //if (_sizeof($list_rec)) foreach($list_rec as $id=>$rec) EVENTS()->prepare_public_info_to_event($list_rec[$id],$options) ;
    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    $arr_moment=array(1=>'После авторизации',2=>'Во время измерения давления',3=>'Перед подписью') ;
    //print_2x_arr($list_recs)   ;
    //return;
    $this->obj_event=EVENTS()->get_event_obj_by_id($this->event_id) ;
    $form=new i_form() ;
    $form->form_open(array('id'=>'test')) ;
    $form->row_open() ;
    ?><? $form->row_close() ;?>
      <table class="basic fz_small full auto" <?echo $id?>>
        <tr><th>№</th><th>Дата/время<br>добавления</th><th>Наименование</th><th>Момент доведения</th><th>Длительность показа, сек</th><th>Тип</th><th>Содержимое</th><th>Размер файла</th></tr><?
          if (_sizeof($list_recs)) foreach($list_recs as $rec)
          {   ?><tr>
                  <td><?echo $rec['pkey']?></td>
                  <td><?echo date('d.m.Y H:i',$rec['c_data'])?><??></td>
                  <td class="left"><?if ($rec['type']!='text')echo $rec['obj_name']?></td>
                  <td><?echo $this->obj_event->arr_moment[$rec['moment']]?></td>
                  <td><?echo $rec['len'].' сек.'?></td>
                  <td><?echo $rec['type']?></td>
                  <td><?
                      if ($rec['type']=='text') echo $rec['manual'];
                      if (strpos($rec['type'],'image')!==false){?><img src="<?echo $rec['file_name']?>" class="zoom" height="150"><?}
                      if (strpos($rec['type'],'video')!==false)  $this->player_code_avi($rec['file_name']) ;
                      ?>
                  <td><?echo ($rec['size'])? '<div>'.show_size($rec['size']).'</div>':''?>
                      <?echo ($rec['width'])? '<div>'.$rec['width'].'x'.$rec['height'].'</div>':'' ?>
                    </td>
              </tr><?
          }
       ?></table><?
      //print_2x_arr($list_recs) ;
      $form->form_close() ;
  }

    function player_code_avi($video_url,$options=array())
       {  $video_width=($options['video_width'])? $options['video_width']:400 ;
          $video_height=($options['video_height'])? $options['video_height']:300 ;
          //damp_array($options,1,-1) ;
           ?><br>
           <video controls width="<?echo $video_width?>" height="<?echo $video_height?>" <?if ($options['video_rotare']) echo 'style="transform:rotate('.$options['video_rotare'].'deg);"'?>>
             <source src="<?echo $video_url?>">
           </video>
           <div id="panel_filter" class="button_to_upload_video"><form id="sky-form" class="sky-form">
                     <!--<a class="button" href="/services/get_video/?url=<? echo $video_url?>">Скачать</a>-->
                  </form></div>
                  <style type="text/css">
                      div#panel_filter.button_to_upload_video{text-align:center;}
                      div#panel_filter.button_to_upload_video p.info{margin:50px 100px 50px 100px;font-size:16px;}
                      div#panel_filter.button_to_upload_video a.button{float:none;margin:30px 100px 30px 100px;}
                  </style>
           <?
       }


}

?>
