action.php 2.2 KB

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