PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/action/www/cti/presences.php

https://gitlab.com/xivo.solutions/xivo-web-interface
PHP | 377 lines | 286 code | 72 blank | 19 comment | 42 complexity | b546871f1f9bc4b4041b1e33bb8e299b MD5 | raw file
  1. <?php
  2. #
  3. # XiVO Web-Interface
  4. # Copyright (C) 2006-2014 Avencall
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. $ctistatus = &$ipbx->get_module('ctistatus');
  20. $act = isset($_QR['act']) === true ? $_QR['act'] : '';
  21. $idpresences = isset($_QR['idpresences']) === true ? dwho_uint($_QR['idpresences'],1) : 1;
  22. $page = isset($_QR['page']) === true ? dwho_uint($_QR['page'],1) : 1;
  23. $param = array();
  24. $param['act'] = 'list';
  25. $param['idpresences'] = $idpresences;
  26. $info = $result = array();
  27. $info['access_status'] = array();
  28. $info['access_status']['info'] = array();
  29. $info['access_status']['slt'] = array();
  30. $element = array();
  31. $element['ctistatus'] = $ctistatus->get_element();
  32. switch($act)
  33. {
  34. case 'add':
  35. $app = &$ipbx->get_application('ctipresences');
  36. $result = $fm_save = null;
  37. if(isset($_QR['fm_send']) === true
  38. && dwho_issa('presences',$_QR) === true)
  39. {
  40. if($app->set_add($_QR) === false
  41. || $app->add() === false)
  42. {
  43. $fm_save = false;
  44. $result = $app->get_result();
  45. }
  46. else
  47. $_QRY->go($_TPL->url('cti/presences'),$param);
  48. }
  49. dwho::load_class('dwho_sort');
  50. $_TPL->set_var('info',$result);
  51. $_TPL->set_var('fm_save',$fm_save);
  52. $dhtml = &$_TPL->get_module('dhtml');
  53. $dhtml->set_js('js/jscolor/jscolor.js');
  54. break;
  55. case 'edit':
  56. $app = &$ipbx->get_application('ctipresences');
  57. if(isset($_QR['idpresences']) === false
  58. || ($info = $app->get($_QR['idpresences'])) === false)
  59. $_QRY->go($_TPL->url('cti/presences'),$param);
  60. $result = $fm_save = null;
  61. $return = &$info;
  62. if(isset($_QR['fm_send']) === true
  63. && dwho_issa('presences',$_QR) === true)
  64. {
  65. $return = &$result;
  66. if($app->set_edit($_QR) === false
  67. || $app->edit() === false)
  68. {
  69. $fm_save = false;
  70. $result = $app->get_result();
  71. }
  72. else
  73. $_QRY->go($_TPL->url('cti/presences'),$param);
  74. }
  75. dwho::load_class('dwho_sort');
  76. $_TPL->set_var('idpresences',$info['presences']['id']);
  77. $_TPL->set_var('info',$return);
  78. $_TPL->set_var('fm_save',$fm_save);
  79. $dhtml = &$_TPL->get_module('dhtml');
  80. $dhtml->set_js('js/jscolor/jscolor.js');
  81. break;
  82. case 'delete':
  83. $param['page'] = $page;
  84. $app = &$ipbx->get_application('ctipresences');
  85. if(isset($_QR['idpresences']) === false
  86. || ($info = $app->get($_QR['idpresences'])) === false)
  87. $_QRY->go($_TPL->url('cti/presences'),$param);
  88. $app->delete();
  89. $_QRY->go($_TPL->url('cti/presences'),$param);
  90. break;
  91. case 'liststatus':
  92. $prevpage = $page - 1;
  93. $nbbypage = XIVO_SRE_IPBX_AST_NBBYPAGE;
  94. $app = &$ipbx->get_application('ctistatus',null,false);
  95. $order = array();
  96. $order['name'] = SORT_ASC;
  97. $limit = array();
  98. $limit[0] = $prevpage * $nbbypage;
  99. $limit[1] = $nbbypage;
  100. $list = $app->get_status_list($idpresences);
  101. $total = $app->get_cnt();
  102. if($list === false && $total > 0 && $prevpage > 0)
  103. {
  104. $param['page'] = $prevpage;
  105. $_QRY->go($_TPL->url('cti/presences'),$param);
  106. }
  107. $_TPL->set_var('pager',dwho_calc_page($page,$nbbypage,$total));
  108. $_TPL->set_var('list',$list);
  109. break;
  110. case 'editstatus':
  111. $param['act'] = 'liststatus';
  112. $idstatus = $param['idstatus'] = $_QR['idstatus'];
  113. $info = array();
  114. $app = &$ipbx->get_application('ctistatus');
  115. $raw_status_list = $app->get_status_list($idpresences);
  116. $status_list = array();
  117. foreach($raw_status_list as $k => $sl)
  118. {
  119. $sl_key = $sl['ctistatus']['id'];
  120. $status_list[$sl_key] = $sl['ctistatus'];
  121. }
  122. $actionslist = explode(',', $status_list[$idstatus]['actions']);
  123. if($actionslist[0] == '')
  124. $actionslist = null;
  125. if(isset($_QR['idstatus']) === false
  126. || ($info = $app->getstatus($_QR['idstatus'])) === false)
  127. $_QRY->go($_TPL->url('cti/presences'),$param);
  128. $result = $fm_save = null;
  129. $return = &$info;
  130. if(isset($_QR['fm_send']) === true
  131. && dwho_issa('status',$_QR) === true)
  132. {
  133. $return = &$result;
  134. if(array_key_exists('access_status', $_QR) === true)
  135. {
  136. $as_str = array();
  137. foreach($_QR['access_status'] as $k => $as)
  138. {
  139. $as_str[] = $as;
  140. }
  141. $_QR['status']['access_status'] = implode(',', $as_str);
  142. }
  143. else
  144. $_QR['status']['access_status'] = '';
  145. if(array_key_exists('actionsargs', $_QR) === true)
  146. {
  147. $actarr = array();
  148. foreach($_QR['actionsargs'] as $k => $as)
  149. {
  150. $actarr[] = $_QR['actionslist'][$k] . '(' . $as . ')';
  151. }
  152. $_QR['status']['actions'] = implode(',', $actarr);
  153. }
  154. else
  155. $_QR['status']['actions'] = '';
  156. $_QR['status']['presence_id'] = $idpresences;
  157. $_QR['status']['deletable'] = $status_list[$idstatus]['deletable'];
  158. if($app->set_edit($_QR) === false
  159. || $app->edit() === false)
  160. {
  161. $fm_save = false;
  162. $result = $app->get_result();
  163. }
  164. else
  165. $_QRY->go($_TPL->url('cti/presences'),$param);
  166. }
  167. $info['access_status']['slt'] = array();
  168. if(($info['access_status']['list'] = $app->get_status_list($idpresences, null, null, true)) !== false)
  169. {
  170. if(isset($info['status']['access_status']) && dwho_has_len($info['status']['access_status']))
  171. {
  172. $sel = explode(',', $info['status']['access_status']);
  173. $selected = array();
  174. foreach($sel as $s => $k)
  175. {
  176. $selected[] = array('id' => $k);
  177. }
  178. $info['access_status']['slt'] =
  179. dwho_array_intersect_key(
  180. $selected,
  181. $info['access_status']['list'],
  182. 'id');
  183. $info['access_status']['list'] =
  184. dwho_array_diff_key(
  185. $info['access_status']['list'],
  186. $info['access_status']['slt']);
  187. }
  188. }
  189. dwho::load_class('dwho_sort');
  190. $_TPL->set_var('idstatus',$info['status']['id']);
  191. $_TPL->set_var('idpresences',$idpresences);
  192. $_TPL->set_var('info',$info);
  193. $_TPL->set_var('element',$element);
  194. $_TPL->set_var('actionslist',$actionslist);
  195. $_TPL->set_var('fm_save',$fm_save);
  196. $dhtml = &$_TPL->get_module('dhtml');
  197. $dhtml->set_js('js/jscolor/jscolor.js');
  198. break;
  199. case 'addstatus':
  200. $param['act'] = 'liststatus';
  201. $app = &$ipbx->get_application('ctistatus');
  202. $raw_status_list = $app->get_status_list($idpresences);
  203. #$info['access_status']['info'] = $app->get();
  204. $result = $fm_save = null;
  205. $return = &$info;
  206. if(isset($_QR['fm_send']) === true
  207. && dwho_issa('status',$_QR) === true)
  208. {
  209. $return = &$result;
  210. if(array_key_exists('access_status', $_QR) === true)
  211. {
  212. $as_str = array();
  213. foreach($_QR['access_status'] as $k => $as)
  214. {
  215. $as_str[] = $as;
  216. }
  217. $_QR['status']['access_status'] = implode(',', $as_str);
  218. }
  219. else
  220. $_QR['status']['access_status'] = '';
  221. if(array_key_exists('actionsargs', $_QR) === true)
  222. {
  223. $actarr = array();
  224. foreach($_QR['actionsargs'] as $k => $as)
  225. {
  226. $actarr[] = $_QR['actionslist'][$k] . '(' . $as . ')';
  227. }
  228. $_QR['status']['actions'] = implode(',', $actarr);
  229. }
  230. else
  231. $_QR['status']['actions'] = '';
  232. $_QR['status']['presence_id'] = $idpresences;
  233. $_QR['status']['deletable'] = 1;
  234. if($app->set_add($_QR) === false
  235. || $app->add() === false)
  236. {
  237. $fm_save = false;
  238. $result = $app->get_result();
  239. }
  240. else
  241. $_QRY->go($_TPL->url('cti/presences'),$param);
  242. }
  243. $info['access_status']['slt'] = array();
  244. if(($info['access_status']['list'] = $app->get_status_list($idpresences, null, null, true)) !== false)
  245. {
  246. if(isset($info['status']['access_status']) && dwho_has_len($info['status']['access_status']))
  247. {
  248. $sel = explode(',', $info['status']['access_status']);
  249. $selected = array();
  250. foreach($sel as $s => $k)
  251. {
  252. $selected[] = array('id' => $k);
  253. }
  254. $info['access_status']['slt'] = array();
  255. }
  256. }
  257. dwho::load_class('dwho_sort');
  258. $info['status'] = null;
  259. $_TPL->set_var('info',$info);
  260. $_TPL->set_var('element',$element);
  261. $_TPL->set_var('fm_save',$fm_save);
  262. $dhtml = &$_TPL->get_module('dhtml');
  263. $dhtml->set_js('js/jscolor/jscolor.js');
  264. break;
  265. case 'deletestatus':
  266. $param['page'] = $page;
  267. $param['act'] = 'liststatus';
  268. $app = &$ipbx->get_application('ctistatus');
  269. if(isset($_QR['idstatus']) === false
  270. || ($info = $app->get($_QR['idstatus'])) === false)
  271. $_QRY->go($_TPL->url('cti/presences'),$param);
  272. $app->delete();
  273. $_QRY->go($_TPL->url('cti/presences'),$param);
  274. break;
  275. default:
  276. $act = 'list';
  277. $prevpage = $page - 1;
  278. $nbbypage = XIVO_SRE_IPBX_AST_NBBYPAGE;
  279. $app = &$ipbx->get_application('ctipresences',null,false);
  280. $order = array();
  281. $order['name'] = SORT_ASC;
  282. $limit = array();
  283. $limit[0] = $prevpage * $nbbypage;
  284. $limit[1] = $nbbypage;
  285. $list = $app->get_presences_list();
  286. $total = $app->get_cnt();
  287. if($list === false && $total > 0 && $prevpage > 0)
  288. {
  289. $param['page'] = $prevpage;
  290. $_QRY->go($_TPL->url('cti/presences'),$param);
  291. }
  292. $_TPL->set_var('pager',dwho_calc_page($page,$nbbypage,$total));
  293. $_TPL->set_var('list',$list);
  294. }
  295. $_TPL->set_var('act',$act);
  296. $_TPL->set_var('idpresences',$idpresences);
  297. #$_TPL->set_var('group',$group);
  298. $menu = &$_TPL->get_module('menu');
  299. $menu->set_top('top/user/'.$_USR->get_info('meta'));
  300. $menu->set_left('left/cti/menu');
  301. $menu->set_toolbar('toolbar/cti/presences');
  302. $_TPL->set_bloc('main','/cti/presences/'.$act);
  303. $_TPL->set_struct('service/ipbx/'.$ipbx->get_name());
  304. $_TPL->display('index');
  305. ?>