api.androidapp.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. <?php
  2. /**
  3. * Android application implementation
  4. * https://github.com/romaznova/ubilling
  5. */
  6. class AndroidApp {
  7. /**
  8. * Contains data for next convert on json data
  9. *
  10. * @var array
  11. */
  12. protected $json = array();
  13. /**
  14. * USER LOGGED flag
  15. *
  16. * @var bool
  17. */
  18. protected $loggedIn = false;
  19. /**
  20. * Access status flag
  21. *
  22. * @var bool
  23. */
  24. public $access = false;
  25. /**
  26. * Operation status flag
  27. *
  28. * @var bool
  29. */
  30. protected $success = true;
  31. /**
  32. * Debug status flag
  33. *
  34. * @var bool
  35. */
  36. protected $debug = false;
  37. /**
  38. * Some information massege
  39. *
  40. * @var void
  41. */
  42. protected $message = '';
  43. /**
  44. * Main data conteiner
  45. *
  46. * @var array
  47. */
  48. protected $data = array();
  49. /**
  50. * Contains debug message and information
  51. *
  52. * @var array
  53. */
  54. protected $debug_message = array();
  55. /**
  56. * Contains current user login
  57. *
  58. * @var string
  59. */
  60. protected $adminLogin = '';
  61. /**
  62. * Contains action for API
  63. *
  64. * @var string
  65. */
  66. protected $getModuleAction = '';
  67. /**
  68. * Contains date at function curdate()
  69. *
  70. * @var string
  71. */
  72. protected $getDate = '';
  73. /**
  74. * Contains date at function curdate()
  75. *
  76. * @var string
  77. */
  78. protected $getStartDate = '';
  79. /**
  80. * Contains date at function curdate()
  81. *
  82. * @var string
  83. */
  84. protected $getEndDate = '';
  85. /**
  86. * Change default $getDate that getting from $_GET
  87. *
  88. * @var bool
  89. */
  90. protected $setGetDate = false;
  91. /**
  92. * Change default $getStartDate that getting from $_GET
  93. *
  94. * @var bool
  95. */
  96. protected $setGetStartDate = false;
  97. /**
  98. * Return all needed permissions
  99. *
  100. * @var array
  101. */
  102. protected $permissions = array();
  103. /**
  104. * Return all checking permissions
  105. *
  106. * @var array
  107. */
  108. protected $needRights = array();
  109. /**
  110. * Conteins users data
  111. *
  112. * @var array
  113. */
  114. protected $usersData = array();
  115. /**
  116. * Contains admns Name as admin_login => admin_name
  117. *
  118. * @var array
  119. */
  120. protected $adminsName = array();
  121. /**
  122. * Current user login. Must be set in constructor
  123. *
  124. * @var string
  125. */
  126. public $login = '';
  127. /**
  128. * UbillingCache object placeholder
  129. *
  130. * @var object
  131. */
  132. protected $cache = '';
  133. public function __construct() {
  134. // Check if user logged
  135. if (LOGGED_IN) {
  136. // Only once need change this parametr
  137. $this->loggedIn = true;
  138. // Check who logged
  139. $this->setLogin();
  140. $this->loadAdminsName();
  141. if (cfr('ANDROID')) {
  142. $this->access = true;
  143. $this->initDebug();
  144. $this->setGetModuleAction();
  145. $this->setGetDate();
  146. $this->initUsernameLogin();
  147. $this->loadPermissionCheckGlobal();
  148. }
  149. } else {
  150. $this->json['message'] = 'First you need login';
  151. }
  152. }
  153. /**
  154. * Check getting module
  155. *
  156. * @return void
  157. */
  158. protected function setGetModuleAction() {
  159. if (wf_CheckGet(array('action'))) {
  160. $this->getModuleAction = vf($_GET['action']);
  161. } else {
  162. $this->getModuleAction = 'taskman';
  163. }
  164. }
  165. /**
  166. * Check getting date
  167. *
  168. * @return void
  169. */
  170. protected function setGetDate() {
  171. $this->getDate = curdate();
  172. $this->getStartDate = curdate();
  173. $this->getEndDate = curdate();
  174. // Change parametrs days if needed
  175. if (wf_CheckGet(array('date'))) {
  176. $this->getDate = date("Y-m-d", strtotime($_GET['date']));
  177. $this->setGetDate = true;
  178. } elseif (wf_CheckGet(array('startdate'))) {
  179. $this->getStartDate = date("Y-m-d", strtotime($_GET['startdate']));
  180. // Check if we getting endDate
  181. if (wf_CheckGet(array('enddate'))) {
  182. $testEndDate = date("Y-m-d", strtotime($_GET['enddate']));
  183. // We check that we are not trying to cheat
  184. if ($testEndDate > $this->getStartDate) {
  185. $this->getEndDate = $testEndDate;
  186. }
  187. }
  188. $this->setGetStartDate = true;
  189. }
  190. $this->DebugMessageAdd('date', array('getDate' => $this->getDate, 'getStartDate' => $this->getStartDate, 'getEndDate' => $this->getEndDate));
  191. }
  192. /**
  193. * Set check permissons for modules that use global
  194. *
  195. * @return void
  196. */
  197. protected function loadPermissionCheckGlobal() {
  198. $this->permissionCheckAdd('taskmansearch');
  199. $this->permissionCheckAdd('taskman');
  200. $this->permissionCheckAdd('userprofile');
  201. $this->permissionCheckAdd('useredit');
  202. $this->permissionCheckAdd('pl_dhcp');
  203. $this->permissionCheckAdd('pl_pinger');
  204. $this->permissionCheckAdd('useredit');
  205. $this->permissionCheckAdd('passwordedit');
  206. $this->permissionCheckAdd('realnameedit');
  207. $this->permissionCheckAdd('phoneedit');
  208. $this->permissionCheckAdd('mobileedit');
  209. $this->permissionCheckAdd('mailedit');
  210. $this->permissionCheckAdd('downedit');
  211. $this->permissionCheckAdd('passiveedit');
  212. $this->permissionCheckAdd('notesedit');
  213. $this->permissionCheckAdd('reset');
  214. $this->permissionCheckAdd('condetedit');
  215. $this->permissionCheckAdd('addcash');
  216. $this->permissionCheckAdd('usersearch');
  217. $this->permissionCheckAdd('macedit');
  218. }
  219. /**
  220. *
  221. *
  222. * @return void
  223. */
  224. public function loadData() {
  225. if ($this->access) {
  226. switch ($this->getModuleAction) {
  227. case 'getallcashtypes':
  228. $this->getAllCashTypes();
  229. break;
  230. case 'getalljobtypes':
  231. $this->getJobTypes();
  232. break;
  233. case 'admins':
  234. $this->data = unserialize(ts_GetAllEmployeeLoginsCached());
  235. break;
  236. case 'emploees':
  237. $this->data = ts_GetAllEmployee();
  238. break;
  239. case 'usersearch':
  240. if (cfr('USERSEARCH')) {
  241. $this->renderSerchUsersData();
  242. } else {
  243. $this->updateSuccessAndMessage('Permission denied');
  244. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'USERSEARCH', 'getModuleAction' => 'usersearch'));
  245. }
  246. break;
  247. case 'userprofile':
  248. case 'addcash':
  249. if (cfr('USERPROFILE')) {
  250. $this->renderUserData();
  251. } else {
  252. $this->updateSuccessAndMessage('Permission denied');
  253. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'USERPROFILE', 'getModuleAction' => 'usersearch'));
  254. }
  255. break;
  256. case 'useredit':
  257. if (cfr('USEREDIT')) {
  258. $this->renderUserData();
  259. } else {
  260. $this->updateSuccessAndMessage('Permission denied');
  261. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'USEREDIT', 'getModuleAction' => 'useredit'));
  262. }
  263. break;
  264. case 'pl_dhcp':
  265. if (cfr('PLDHCP')) {
  266. $this->renderUserData();
  267. } else {
  268. $this->updateSuccessAndMessage('Permission denied');
  269. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'PLDHCP', 'getModuleAction' => 'pl_dhcp'));
  270. }
  271. break;
  272. case 'pl_pinger':
  273. if (cfr('PLPINGER')) {
  274. $this->renderUserData();
  275. } else {
  276. $this->updateSuccessAndMessage('Permission denied');
  277. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'PLPINGER', 'getModuleAction' => 'pl_pinger'));
  278. }
  279. break;
  280. case 'taskmanundone':
  281. if (cfr('TASKMAN')) {
  282. $this->getTasks(false, true);
  283. } else {
  284. $this->updateSuccessAndMessage('Permission denied');
  285. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'TASKMAN', 'getModuleAction' => 'taskman'));
  286. }
  287. break;
  288. case 'taskmandone':
  289. if (cfr('TASKMAN')) {
  290. $this->getTasks(true, false);
  291. } else {
  292. $this->updateSuccessAndMessage('Permission denied');
  293. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'TASKMAN', 'getModuleAction' => 'taskmandone'));
  294. }
  295. break;
  296. case 'taskman':
  297. if (cfr('TASKMAN')) {
  298. $this->getTasks();
  299. } else {
  300. $this->updateSuccessAndMessage('Permission denied');
  301. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'TASKMAN', 'getModuleAction' => 'taskman'));
  302. }
  303. break;
  304. default:
  305. if (cfr('TASKMAN')) {
  306. $this->getTasks();
  307. } else {
  308. $this->success = false;
  309. $this->message = __('Permission denied');
  310. $this->updateSuccessAndMessage('Permission denied');
  311. $this->DebugMessageAdd('Permission denied for', array('function' => 'loadData', 'cfr' => 'TASKMAN', 'getModuleAction' => 'default'));
  312. }
  313. }
  314. }
  315. }
  316. /**
  317. * Get user dhcp log
  318. *
  319. * @return void
  320. */
  321. public function getUserDhcpLog() {
  322. global $ubillingConfig;
  323. if ($this->login) {
  324. $this->usersData = zb_UserGetAllData($this->login);
  325. // Check that we have some data user
  326. if (current($this->usersData)) {
  327. $config = $ubillingConfig->getBilling();
  328. $alter_conf = $ubillingConfig->getAlter();
  329. $cat_path = $config['CAT'];
  330. $grep_path = $config['GREP'];
  331. $tail_path = $config['TAIL'];
  332. $sudo_path = $config['SUDO'];
  333. $leasefile = $ubillingConfig->getAlterParam('NMLEASES');
  334. $command = $sudo_path . ' ' . $cat_path . ' ' . $leasefile . ' | ' . $grep_path . ' ' . $this->usersData[$this->login]['mac'] . ' | ' . $tail_path . ' -n 30';
  335. $output = shell_exec($command);
  336. $this->usersData[$this->login]['dhcp'] = $output;
  337. } else {
  338. $this->updateSuccessAndMessage('Username cannot be empty');
  339. }
  340. }
  341. }
  342. /**
  343. * Get user ping result
  344. *
  345. * @return void
  346. */
  347. public function getUserPingResult() {
  348. global $ubillingConfig;
  349. if ($this->login) {
  350. $this->usersData = zb_UserGetAllData($this->login);
  351. // Check that we have some data user
  352. if (current($this->usersData)) {
  353. $config = $ubillingConfig->getBilling();
  354. $alter_conf = $ubillingConfig->getAlter();
  355. $ping_path = $config['PING'];
  356. $sudo_path = $config['SUDO'];
  357. $command = $sudo_path . ' ' . $ping_path . ' -i 0.01 -c 10 ' . $this->usersData[$this->login]['ip'];
  358. $output = shell_exec($command);
  359. $this->usersData[$this->login]['ping'] = $output;
  360. } else {
  361. $this->updateSuccessAndMessage('Username cannot be empty');
  362. }
  363. }
  364. }
  365. /**
  366. * Initalizes system cache object for further usage
  367. *
  368. * @return void
  369. */
  370. protected function initCache() {
  371. $this->cache = new UbillingCache();
  372. }
  373. /**
  374. * Clear scope cache object
  375. *
  376. * @return void
  377. */
  378. protected function clearScopeCache() {
  379. $this->cache->delete('ADCOMMENTS_TASKMAN');
  380. }
  381. /**
  382. * Filtering variables
  383. *
  384. * @param string $str some string for filter
  385. *
  386. * @return void
  387. */
  388. public function filterStr($strOrigin) {
  389. $str = strip_tags($strOrigin);
  390. $str = trim($str);
  391. $str = stripslashes($str);
  392. $str = htmlspecialchars($str);
  393. $this->DebugMessageAdd('function', array('filterStr' => array('origin' => $strOrigin, 'return' => $str)));
  394. return $str;
  395. }
  396. /**
  397. * Creates new comment in database
  398. *
  399. * @param string $text text for new comment
  400. *
  401. * @return void
  402. */
  403. public function createComment($id, $text) {
  404. $curdate = curdatetime();
  405. $text = mysql_real_escape_string($text);
  406. $query = "INSERT INTO `adcomments` (`id`, `scope`, `item`, `date`, `admin`, `text`) "
  407. . "VALUES (NULL, 'TASKMAN', '" . $id . "', '" . $curdate . "', '" . $this->adminLogin . "', '" . $text . "');";
  408. nr_query($query);
  409. log_register("ADCOMM CREATE SCOPE `TASKMAN` ITEM [" . $id . "]");
  410. $this->initCache();
  411. $this->clearScopeCache();
  412. }
  413. /**
  414. *
  415. *
  416. * @return void
  417. */
  418. public function getUserData() {
  419. global $ubillingConfig;
  420. if ($this->login) {
  421. $this->usersData = zb_UserGetAllData($this->login);
  422. // Check that we have some data user
  423. if (current($this->usersData)) {
  424. // check thate need add contract date
  425. if ($ubillingConfig->getAlterParam('CONTRACTDATE_IN_PROFILE')) {
  426. $contract = $this->usersData[$this->login]['contract'];
  427. if (!empty($contract)) {
  428. $contractDates = new ContractDates();
  429. $allContractDates = $contractDates->getAllDatesBasic($contract);
  430. $contractDate = (isset($allContractDates[$contract])) ? $allContractDates[$contract] : '';
  431. $this->usersData[$this->login]['contractdate'] = $contractDate;
  432. }
  433. }
  434. //additional mobile data
  435. if ($ubillingConfig->getAlterParam('MOBILES_EXT')) {
  436. $extMob = new MobilesExt();
  437. if (version_compare(phpversion(), '5.5.0', '<')) {
  438. $allExt = array();
  439. $allExtTemp = $extMob->getUserMobiles($this->login);
  440. foreach ($allExtTemp as $ia => $eachExt) {
  441. $allExt[] = $eachExt['mobile'];
  442. }
  443. } else {
  444. $allExt = array_column($extMob->getUserMobiles($this->login), 'mobile');
  445. }
  446. $additionalNumbers = implode(', ', $allExt);
  447. $this->usersData[$this->login]['additionalNumbers'] = $additionalNumbers;
  448. }
  449. // User payment ID
  450. if ($ubillingConfig->getAlterParam('OPENPAYZ_SUPPORT')) {
  451. if ($ubillingConfig->getAlterParam('OPENPAYZ_REALID')) {
  452. $this->usersData[$this->login]['paymantid'] = zb_PaymentIDGet($this->login);
  453. } else {
  454. $this->usersData[$this->login]['paymantid'] = ip2int($this->usersData[$this->login]['ip']);
  455. }
  456. } else {
  457. $this->usersData[$this->login]['paymantid'] = '';
  458. }
  459. $this->usersData[$this->login]['notes'] = zb_UserGetNotes($this->login);
  460. // gets and preformats last activity time
  461. if ($ubillingConfig->getAlterParam('PROFILE_LAT')) {
  462. //if ($this->usersData[$this->login]['LastActivityTime'] != 0) {
  463. //$data = date("Y-m-d H:i:s", $this->usersData[$this->login]['LastActivityTime']);
  464. // $this->usersData[$this->login]['LastActivityTime'] = $data;
  465. //}
  466. }
  467. // Returns user connection details
  468. if ($ubillingConfig->getAlterParam('CONDET_ENABLED')) {
  469. $conDet = new ConnectionDetails();
  470. $connectionDetails = $conDet->getByLogin($this->login);
  471. $this->usersData[$this->login]['ConnectionDetails'] = $conDet->renderData($this->login);
  472. $this->usersData[$this->login]['seal'] = (isset($connectionDetails['seal'])) ? $connectionDetails['seal'] : '';
  473. $this->usersData[$this->login]['length'] = (isset($connectionDetails['length'])) ? $connectionDetails['length'] : '';
  474. $this->usersData[$this->login]['price'] = (isset($connectionDetails['price'])) ? $connectionDetails['price'] : '';
  475. }
  476. // Returns user PON signal from cache
  477. if ($ubillingConfig->getAlterParam('PON_ENABLED') and $ubillingConfig->getAlterParam('SIGNAL_IN_PROFILE')) {
  478. $searched = __('No');
  479. $query = "SELECT `id`,`mac`,`oltid`,`serial` FROM `pononu` WHERE `login`='" . $this->login . "'";
  480. $onu_data = simple_query($query);
  481. if (!empty($onu_data)) {
  482. $availCacheData = rcms_scandir(PONizer::SIGCACHE_PATH, $onu_data['oltid'] . "_" . PONizer::SIGCACHE_EXT);
  483. if (!empty($availCacheData)) {
  484. foreach ($availCacheData as $io => $each) {
  485. $raw = file_get_contents(PONizer::SIGCACHE_PATH . $each);
  486. $raw = unserialize($raw);
  487. foreach ($raw as $mac => $signal) {
  488. if ($mac == $onu_data['mac'] or $mac == $onu_data['serial']) {
  489. $searched = $signal;
  490. }
  491. }
  492. }
  493. }
  494. $this->usersData[$this->login]['signal'] = $searched;
  495. }
  496. }
  497. }
  498. } else {
  499. $this->updateSuccessAndMessage('Username cannot be empty');
  500. }
  501. }
  502. /**
  503. *
  504. *
  505. * @return void
  506. */
  507. protected function renderUserData() {
  508. if (!empty($this->usersData)) {
  509. $this->data = $this->usersData;
  510. $this->DebugMessageAdd('function', array('renderUserData' => $this->usersData));
  511. } else {
  512. $this->updateSuccessAndMessage('EMPTY_DATABASE_USERDATA');
  513. $this->DebugMessageAdd('function', array('login' => $this->login));
  514. }
  515. }
  516. /**
  517. *
  518. *
  519. * @return void
  520. */
  521. public function searchUsersQuery($query) {
  522. if (strlen($query) >= 3) {
  523. $this->usersData = array_intersect_key(zb_UserGetAllDataCache(), array_flip(zb_UserSearchAllFields($query, false)));
  524. } else {
  525. $this->success = false;
  526. $this->message = __('At least 3 characters are required for search');
  527. }
  528. }
  529. /**
  530. *
  531. *
  532. * @return void
  533. */
  534. protected function renderSerchUsersData() {
  535. $this->data = $this->usersData;
  536. $this->DebugMessageAdd('SQLquery', array('renderSerchUsersData' => $this->usersData));
  537. }
  538. /**
  539. *
  540. *
  541. * @return void
  542. */
  543. protected function getTasks($showDone = false, $showUndone = false) {
  544. global $ubillingConfig;
  545. $SQLwhere = '';
  546. $SQLwhereArr = array();
  547. // Check if we want get tasks for all emploees
  548. if (isset($_GET['emploee']) and $_GET['emploee'] == 'all') {
  549. $SQLwhereArr['emploee'] = '';
  550. } elseif (isset($_GET['emploee']) and ! empty($_GET['emploee'])) {
  551. $SQLwhereArr['emploee'] = "`employee`='" . vf($_GET['emploee'], 3) . "'";
  552. } else {
  553. $SQLwhereArr['emploee'] = "`employee`='" . ts_GetEmployeeByLogin($this->adminLogin) . "'";
  554. }
  555. // Check if need show undone tasks
  556. if ($showUndone) {
  557. $SQLwhereArr['status'] = "status = '0'";
  558. }
  559. // Check if need show only done tasks
  560. if ($showDone) {
  561. $SQLwhereArr['status'] = "status = '1'";
  562. }
  563. if ($showUndone) {
  564. $SQLwhereArr['date'] = "startdate < '" . curdate() . "'";
  565. }
  566. if ($this->setGetDate) {
  567. $SQLwhereArr['date'] = "(`startdate` = '" . $this->getDate . "' OR `enddate` = '" . $this->getDate . "')";
  568. }
  569. if ($this->setGetStartDate) {
  570. $SQLwhereArr['date'] = "`startdate` BETWEEN '" . $this->getStartDate . "' AND '" . $this->getEndDate . "'";
  571. }
  572. // Create and WHERE to query
  573. if (!empty($SQLwhereArr)) {
  574. $SQLwhereArrFilter = array_filter($SQLwhereArr);
  575. $SQLwhere = " WHERE " . implode(" AND ", $SQLwhereArrFilter);
  576. }
  577. $query = "SELECT `taskman`.*, `jobtypes`.`jobname`
  578. FROM `taskman`
  579. LEFT JOIN `jobtypes` ON `taskman`.`jobtype` = `jobtypes`.`id`
  580. " . $SQLwhere . "
  581. ORDER BY `date` ASC";
  582. $tasksArr = simple_queryall($query);
  583. //additional comments
  584. if ($ubillingConfig->getAlterParam('ADCOMMENTS_ENABLED')) {
  585. if (!empty($tasksArr)) {
  586. array_walk($tasksArr, function ($item, $key) use (&$tasksArr) {
  587. $query = "SELECT * from `adcomments` WHERE `scope`='TASKMAN' AND `item`='" . $item['id'] . "' ORDER BY `date` ASC;";
  588. $all = simple_queryall($query);
  589. $tasksArr[$key]['comments'] = $all;
  590. return($tasksArr);
  591. }
  592. );
  593. }
  594. }
  595. $this->data = $tasksArr;
  596. $this->DebugMessageAdd('SQLwhere', $SQLwhere);
  597. $this->DebugMessageAdd('SQLwhereArr', $SQLwhereArr);
  598. $this->DebugMessageAdd('SQLwhereArrFilter', $SQLwhereArrFilter);
  599. $this->DebugMessageAdd('SQLwhereImlode', implode(" AND ", $SQLwhereArr));
  600. $this->DebugMessageAdd('SQLwhereImlode', implode(" AND ", $SQLwhereArrFilter));
  601. $this->DebugMessageAdd('SQLquery', array('GetUndoneTasksForToDay' => $query));
  602. }
  603. /**
  604. * Return array of all available cashtypes as id=>name
  605. *
  606. * @return void
  607. */
  608. protected function getAllCashTypes() {
  609. $result = zb_CashGetAllCashTypes();
  610. $this->data = $result;
  611. $this->DebugMessageAdd('Use function', array('function' => 'getAllCashTypes'));
  612. }
  613. /**
  614. *
  615. *
  616. * @return void
  617. */
  618. protected function getJobTypes() {
  619. $result = ts_GetAllJobtypes();
  620. $this->data = $result;
  621. $this->DebugMessageAdd('Use function', array('function' => 'getJobTypes'));
  622. }
  623. /**
  624. * Sets current user login
  625. *
  626. * @return void
  627. */
  628. protected function initDebug() {
  629. if (isset($_GET['debug']) and $_GET['debug'] == 'true') {
  630. if ($this->access and cfr('ANDROIDDEBUG')) {
  631. $this->debug = true;
  632. } else {
  633. $this->success = false;
  634. $this->message = __('Permission denied');
  635. }
  636. }
  637. }
  638. /**
  639. * Sets current user login
  640. *
  641. * @return void
  642. */
  643. protected function setLogin() {
  644. $this->adminLogin = whoami();
  645. }
  646. /**
  647. * Sets current user login
  648. *
  649. * @return void
  650. */
  651. protected function initUsernameLogin() {
  652. if (isset($_GET['username'])) {
  653. $login = vf($_GET['username']);
  654. $login = $this->filterStr($login);
  655. $this->login = mysql_real_escape_string($login);
  656. $this->DebugMessageAdd('Use function', array('function' => 'initUsernameLogin', 'login' => $this->login));
  657. }
  658. }
  659. /**
  660. * Loads admis Name
  661. *
  662. * @return void
  663. */
  664. protected function loadAdminsName() {
  665. @$employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached());
  666. if (!empty($employeeLogins)) {
  667. foreach ($employeeLogins as $login => $name) {
  668. $this->adminsName[$login] = $name;
  669. }
  670. }
  671. }
  672. /**
  673. * Function for add debug information from function
  674. *
  675. * @return array
  676. */
  677. protected function DebugMessageAddArr($module, $data) {
  678. $this->debug_message[$module][] = $data;
  679. }
  680. /**
  681. * Function for add GLOBAL debug information
  682. *
  683. * @return array
  684. */
  685. protected function DebugGlobalMessageAdd() {
  686. $this->debug_message['DEBUG_POST'] = $_POST;
  687. $this->debug_message['DEBUG_GET'] = $_GET;
  688. $this->debug_message['DEBUG_COOKIE'] = $_COOKIE;
  689. }
  690. /**
  691. * Function for add debug information
  692. *
  693. * @return array
  694. */
  695. public function DebugMessageAdd($module = '', $data = '') {
  696. if ($this->debug) {
  697. $this->DebugMessageAddArr($module, $data);
  698. }
  699. }
  700. /**
  701. * Function for add information about module permission
  702. *
  703. * @return array
  704. */
  705. protected function permissionCheckAdd($module = '') {
  706. global $system;
  707. if (!empty($module)) {
  708. $permission_arr = @$system->modules['main'][$module]['rights'];
  709. if (!empty($permission_arr)) {
  710. foreach ($permission_arr as $right => $desc) {
  711. $this->permissions[$right]['desc'] = $desc;
  712. $this->permissions[$right]['rights'] = cfr($right);
  713. }
  714. }
  715. }
  716. }
  717. /**
  718. * Function for add debug information
  719. *
  720. * @return array
  721. */
  722. public function checkRight($right = '') {
  723. $result = false;
  724. if (!empty($right)) {
  725. $this->needRights[] = $right;
  726. $result = cfr($right);
  727. }
  728. return $result;
  729. }
  730. /**
  731. * Check getting date
  732. *
  733. * @return void
  734. */
  735. public function updateSuccessAndMessage($message = 'SOME_ERROR') {
  736. $this->success = false;
  737. $this->message = __($message);
  738. }
  739. /**
  740. * Crete Json objects
  741. *
  742. * @return array
  743. */
  744. protected function CreateJsonData() {
  745. // Load default debug message
  746. if ($this->debug) {
  747. $this->DebugGlobalMessageAdd();
  748. }
  749. $this->json['logged_in'] = $this->loggedIn;
  750. $this->json['access'] = $this->access;
  751. $this->json['success'] = $this->success;
  752. $this->json['admin'] = $this->adminLogin;
  753. $this->json['admin_name'] = (isset($this->adminsName[$this->adminLogin])) ? $this->adminsName[$this->adminLogin] : $this->adminLogin;
  754. $this->json['message'] = $this->message;
  755. $this->json['module'] = $this->getModuleAction;
  756. $this->json['needrights'] = $this->needRights;
  757. $this->json['rights'] = $this->permissions;
  758. $this->json['data'] = $this->data;
  759. $this->json['debug'] = $this->debug_message;
  760. }
  761. /**
  762. * GENERAL FUNCTION
  763. * Render Json objects
  764. *
  765. * @return array/json
  766. */
  767. public function RenderJson() {
  768. $this->CreateJsonData();
  769. // Send main headers
  770. header('Last-Modified: ' . gmdate('r'));
  771. header('Content-Type: application/json; charset=UTF-8');
  772. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  773. header("Pragma: no-cache");
  774. return (json_encode($this->json));
  775. }
  776. }
  777. ?>