action.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /** SMS **/
  3. //Sauvegarde des configurations de sms
  4. Action::register('sms_setting_save',function(&$response){
  5. global $myUser,$_,$conf;
  6. User::check_access('sms','configure');
  7. foreach(Configuration::setting('sms') as $key=>$value){
  8. if(!is_array($value)) continue;
  9. $allowed[] = $key;
  10. }
  11. foreach ($_['fields'] as $key => $value) {
  12. if(in_array($key, $allowed))
  13. $conf->put($key,$value);
  14. }
  15. });
  16. //Ajout ou modification d'élément sms
  17. Action::register('sms_send',function(&$response){
  18. global $myUser,$_,$conf;
  19. User::check_access('sms','edit');
  20. Plugin::callHook('sms_send',array($_['phone'],html_entity_decode($_['message'])));
  21. $history = new History();
  22. $history->scope = 'sms';
  23. $history->uid = $_['phone'];
  24. $history->comment = '';
  25. $history->type = 'send';
  26. $history->save();
  27. });
  28. /** HISTORY **/
  29. //Récuperation d'une liste de history
  30. Action::register('sms_histories_search',function(&$response){
  31. global $myUser,$_;
  32. User::check_access('sms','read');
  33. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  34. $query = 'SELECT * FROM '.History::tableName().' WHERE 1 AND scope = ? AND type = ? ';
  35. $data = array('sms','send');
  36. //Recherche simple
  37. if(!empty($_['filters']['keyword'])){
  38. $query .= ' AND uid LIKE ?';
  39. $data[] = '%'.$_['filters']['keyword'].'%';
  40. }
  41. //Recherche avancée
  42. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('uid','creator','created'),$query,$data);
  43. $query.=' ORDER BY id DESC';
  44. //Pagination
  45. $response['pagination'] = History::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
  46. $historys = History::staticQuery($query,$data,true,0);
  47. foreach($historys as $history){
  48. $row = $history->toArray();
  49. $row['phone'] = $row['uid'];
  50. $row['createdReadable'] = complete_date($row['created']).' à '.date('H:i:s',$row['created']);
  51. $row['created'] = date('d/m/Y H:i:s',$row['created']);
  52. $row['fullname'] = User::byLogin($row['creator'])->fullName();
  53. $response['rows'][] = $row;
  54. }
  55. });
  56. ?>