action.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /** SCREENVIDEO **/
  3. //Récuperation d'une liste de screenvideo
  4. Action::register('screenshare_screen_video_search',function(&$response){
  5. global $myUser,$_;
  6. User::check_access('screenshare','read');
  7. require_once(__DIR__.SLASH.'ScreenVideo.class.php');
  8. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  9. $query = 'SELECT * FROM '.ScreenVideo::tableName().' WHERE 1';
  10. $data = array();
  11. //Recherche simple
  12. if(!empty($_['filters']['keyword'])){
  13. $query .= ' AND label LIKE ?';
  14. $data[] = '%'.$_['filters']['keyword'].'%';
  15. }
  16. $query .= ' AND creator = ?';
  17. $data[] = $myUser->login;
  18. //Recherche avancée
  19. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('label'),$query,$data);
  20. //Tri des colonnes
  21. $query.=' ORDER BY created ';
  22. //Pagination
  23. $response['pagination'] = ScreenVideo::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
  24. $screenvideos = ScreenVideo::staticQuery($query,$data,true,0);
  25. foreach($screenvideos as $screenvideo){
  26. $row = $screenvideo->toArray();
  27. if($row['expire']==0){
  28. unset($row['expire']);
  29. }else{
  30. $row['expireDate'] = date('d/m/Y',$row['expire']);
  31. $row['expireHour'] = date('H:i',$row['expire']);
  32. }
  33. $row['url'] = ROOT_URL.'/index.php?module=screenshare&page=screen.play&slug='.$row['slug'];
  34. $response['rows'][] = $row;
  35. }
  36. });
  37. Action::register('screenshare_screen_video_preview',function(&$response){
  38. global $myUser,$_;
  39. require_once(__DIR__.SLASH.'ScreenVideo.class.php');
  40. if(isset($_['id'])){
  41. User::check_access('screenshare','read');
  42. $video = ScreenVideo::getById($_['id']);
  43. if($video->creator!=$myUser->login) throw new Exception("Vous n'avez pas la permission");
  44. }else if(isset($_['slug'])){
  45. $video = ScreenVideo::load(array('slug'=>$_['slug']));
  46. }
  47. File::downloadFile($video->file(),null,null,isset($_['download']));
  48. });
  49. //Ajout ou modification d'élément screenvideo
  50. Action::register('screenshare_screen_video_save',function(&$response){
  51. global $myUser,$_,$conf;
  52. User::check_access('screenshare','edit');
  53. require_once(__DIR__.SLASH.'ScreenVideo.class.php');
  54. $item = ScreenVideo::provide();
  55. $defaultExpire = $conf->get('screenshare_default_expire') == '' ? 24: $conf->get('screenshare_default_expire');
  56. if($item->id==0){
  57. $item->slug = sha1(md5('9523145'.mt_rand(0,1000).'dev'.time()));
  58. $item->label = 'Capture du '.date('d-m-Y H:i:s');
  59. $item->expire = time() + (3600*$defaultExpire) ;
  60. }
  61. if(isset($_['label']))$item->label = $_['label'];
  62. $item->expire = 0;
  63. if(!empty($_['expireDate'])){
  64. $date = explode('/',$_['expireDate']);
  65. $hour = !empty($_['expireHour']) ? explode(':',$_['expireHour']) : array(0,0);
  66. $time = mktime($hour[0],$hour[1],0,$date[1],$date[0],$date[2]);
  67. $item->expire = $time;
  68. }
  69. if(isset($_['comment'])) $item->comment = $_['comment'];
  70. $item->save();
  71. if(isset($_FILES['data'])) move_uploaded_file($_FILES['data']['tmp_name'], $item->file());
  72. $response['item'] = $item->toArray();
  73. });
  74. //Suppression d'élement screenvideo
  75. Action::register('screenshare_screen_video_delete',function(&$response){
  76. global $myUser,$_;
  77. User::check_access('screenshare','delete');
  78. require_once(__DIR__.SLASH.'ScreenVideo.class.php');
  79. $capture = ScreenVideo::getById($_['id']);
  80. if($myUser->login!=$capture->creator && !$myUser->superAdmin) throw new Exception("Vous devez être le créateur de cette capture pour la supprimer");
  81. $capture->remove();
  82. });
  83. //Sauvegarde des configurations de screenshare
  84. Action::register('screenshare_setting_save',function(&$response){
  85. global $myUser,$_,$conf;
  86. User::check_access('screenshare','configure');
  87. //Si input file "multiple", possibilité de normlaiser le
  88. //tableau $_FILES récupéré avec la fonction => normalize_php_files();
  89. foreach(Configuration::setting('screenshare') as $key=>$value){
  90. if(!is_array($value)) continue;
  91. $allowed[] = $key;
  92. }
  93. foreach ($_['fields'] as $key => $value) {
  94. if(in_array($key, $allowed))
  95. $conf->put($key,$value);
  96. }
  97. });
  98. ?>