Jehanramadhan

Controler Admin

Jan 29th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.85 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) header('Location: ../index.php/error/403');
  2.  
  3. class Admin extends Controller {
  4.  
  5. public $title = 'Hawk Intellitrac Admin';
  6.  
  7. /**
  8. * Admin Model Object
  9. * @var Admin_model
  10. */
  11. public $adm;
  12.  
  13. /**
  14. * User Model Object
  15. * @var User_model
  16. */
  17. public $user;
  18.  
  19. /**
  20. * Client Model Object
  21. * @var Client_model
  22. */
  23. public $client;
  24.  
  25. /**
  26. * Device Model Object
  27. * @var Device_model
  28. */
  29. public $device;
  30.  
  31. function __construct()
  32. {
  33. session_start();
  34. parent::__construct();
  35. $this->load_model('admin_model', 'adm');
  36. if( ! isset($_SESSION['is_logged_in']) ) $_SESSION['is_logged_in'] = FALSE;
  37. }
  38.  
  39. public function index()
  40. {
  41. $this->_goto_login_page();
  42.  
  43. /*if($_SESSION['level'] !== 1)
  44. {
  45. pageRedirect('admin/user');
  46. }*/
  47.  
  48. $data = $this->_generate_data('dashboard');
  49.  
  50. $data['include'] = 'admin/dashboard';
  51.  
  52. $assets = $GLOBALS['config']['base_url'] . 'assets/';
  53. $admin = $assets . "admin";
  54.  
  55. $data['ajs'][] = "$admin/js/app/node-ctrl.js";
  56.  
  57. $this->load->view('admin/base', $data);
  58. }
  59.  
  60. public function user()
  61. {
  62. $this->_goto_login_page();
  63.  
  64. $data = $this->_generate_data('user');
  65.  
  66. $data['include'] = 'admin/user';
  67.  
  68. $this->load->view('admin/base', $data);
  69. }
  70.  
  71. public function message()
  72. {
  73. $this->_goto_login_page();
  74.  
  75. $data = $this->_generate_data('message');
  76.  
  77. $data['include'] = 'admin/message';
  78.  
  79. $this->load->view('admin/base', $data);
  80. }
  81.  
  82. public function log()
  83. {
  84. $this->_goto_login_page();
  85.  
  86. $data = $this->_generate_data('log');
  87.  
  88. $data['include'] = 'admin/log';
  89.  
  90. $this->load->view('admin/base', $data);
  91. }
  92.  
  93. public function device()
  94. {
  95. $this->_goto_login_page();
  96.  
  97. $data = $this->_generate_data('device');
  98.  
  99. $assets = $GLOBALS['config']['base_url'] . 'assets/';
  100. $admin = $assets . "admin";
  101.  
  102. $data['include'] = 'admin/device';
  103. // $data['ajs']['chosen'] = "$admin/js/chosen.js";
  104.  
  105. $this->load->view('admin/base', $data);
  106. }
  107.  
  108. public function admin_user()
  109. {
  110. $this->_goto_login_page();
  111.  
  112. if($_SESSION['level'] !== 1)
  113. {
  114. pageRedirect('admin/');
  115. }
  116.  
  117. $data = $this->_generate_data('admin_user');
  118.  
  119. $data['include'] = 'admin/admin_user';
  120.  
  121. $this->load->view('admin/base', $data);
  122. }
  123.  
  124. public function profile()
  125. {
  126. $this->_goto_login_page();
  127.  
  128. $data = $this->_generate_data('profile');
  129.  
  130. $data['include'] = 'admin/profile';
  131.  
  132. $this->load->view('admin/base', $data);
  133. }
  134.  
  135. public function recache_pos()
  136. {
  137. $this->_goto_login_page();
  138.  
  139. $data = $this->_generate_data('recache_pos');
  140.  
  141. $assets = $GLOBALS['config']['base_url'] . 'assets/';
  142. $admin = $assets . "admin";
  143.  
  144. $data['include'] = 'admin/recache_pos';
  145. $data['ajs'][] = "$admin/js/app/node-ctrl.js";
  146.  
  147. $this->load->view('admin/base', $data);
  148. }
  149.  
  150. public function monitor(){
  151.  
  152. $this->_goto_login_page();
  153.  
  154. $data = $this->_generate_data('monitor');
  155.  
  156. $assets = $GLOBALS['config']['base_url'] . 'assets/';
  157. $admin = $assets . "admin";
  158.  
  159. $data['include'] = 'admin/monitor';
  160.  
  161. $this->load->view('admin/base', $data);
  162.  
  163. $data['ajs'][] = "http://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js";
  164. $data['ajs'][] = "$admin/js/app/monitor-ctrl.js";
  165.  
  166. }
  167.  
  168. private function _generate_data($page)
  169. {
  170. $assets = $GLOBALS['config']['base_url'] . 'assets/';
  171. $angularjs = $assets . 'vendor/angular/angular.js';
  172. $socketio = $assets . 'vendor/socket.io/socket.io.js';
  173. $favicon = $assets . 'img/favicon.ico';
  174. $admin = $assets . "admin";
  175. $jsData = array(
  176. 'userdata' => $this->adm->admin_detail($_SESSION['userdata']['id']),
  177. 'sioPort' => $GLOBALS['config']['socketio_port'],
  178. 'sioHttp' => $GLOBALS['config']['socketio_scheme']
  179. );
  180.  
  181. $data = array(
  182. 'assets_path' => $admin,
  183. 'page_path' => $GLOBALS['config']['base_url'] . 'index.php/admin/',
  184. 'favicon' => $favicon,
  185. 'topjs' => array(
  186. "$admin/js/jquery-1.7.2.min.js",
  187. $angularjs,
  188. $socketio
  189. ),
  190. 'myJS' => json_encode($jsData),
  191. 'username' => $_SESSION['username'],
  192. 'level' => $_SESSION['level'],
  193. 'page_title' => $this->title,
  194. 'page' => $page,
  195. 'ajs' => array(
  196. "{$assets}js/vendor/chosen.jquery.min.js",
  197. "$admin/js/chosen.js",
  198. "$admin/js/moment.min.js",
  199. "$admin/js/app/app.js",
  200. "$admin/js/app/$page-ctrl.js",
  201. "$admin/js/bootstrap.js",
  202. "$admin/js/jquery.datetimepicker.full.min.js",
  203. "$assets../bower_components/ng-ckeditor/libs/ckeditor/ckeditor.js",
  204. "$assets../bower_components/ng-ckeditor/ng-ckeditor.min.js"
  205. // $assets . "js/watcher/services.js",
  206. // $assets . "js/watcher/filters.js",
  207. // $assets . "js/watcher/directives.js"
  208. ),
  209. 'acss' => array(
  210. // $assets . "css/vendor/bootstrap.css",
  211. // $assets . "css/vendor/bootstrap-responsive.css"
  212. "{$assets}css/vendor/chosen.css",
  213. "$admin/css/bootstrap.min.css",
  214. "$admin/css/bootstrap-responsive.min.css",
  215. "$admin/css/font-awesome.css",
  216. "$admin/css/style.css",
  217. "$admin/css/jquery.datetimepicker.css",
  218. "$admin/css/pages/dashboard.css",
  219. "$assets../bower_components/ng-ckeditor/ng-ckeditor.css"
  220. )
  221. );
  222. return $data;
  223. }
  224.  
  225. public function update_user_message()
  226. {
  227. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  228.  
  229. $this->load_model('user_model', 'user');
  230. $data = array(
  231. 'status' => 0,
  232. 'statusText' => 'Did not updated'
  233. );
  234.  
  235. if($this->has_request('username'))
  236. {
  237. $username = $this->get_input('username');
  238. $messageId = $this->get_input('message');
  239. $update = $this->user->update_additional($username, 'login_message', $messageId);
  240.  
  241. if($update)
  242. {
  243. $data = array(
  244. 'status' => 1,
  245. 'statusText' => 'Updated'
  246. );
  247. }
  248. }
  249.  
  250. header('Content-Type: application/json');
  251. echo json_encode($data);
  252. }
  253.  
  254. public function update_block()
  255. {
  256. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  257.  
  258. $this->load_model('user_model', 'user');
  259. $data = array(
  260. 'status' => 0,
  261. 'statusText' => 'Did not updated'
  262. );
  263.  
  264. if($this->has_request('username'))
  265. {
  266. $username = $this->get_input('username');
  267. $blocked = $this->get_input('blocked');
  268. $update = $this->user->update_additional($username, 'blocked', $blocked);
  269. $active = $blocked == '1' ? 0 : 1;
  270. $this->user->set_active($username, $active);
  271.  
  272. if($update)
  273. {
  274. $data = array(
  275. 'status' => 1,
  276. 'statusText' => 'Updated'
  277. );
  278. }
  279. }
  280.  
  281. header('Content-Type: application/json');
  282. echo json_encode($data);
  283. }
  284.  
  285. public function get_users()
  286. {
  287. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  288.  
  289. $this->load_model('user_model', 'user');
  290.  
  291. $m_array = array(
  292. 'username' => 'admin',
  293. 'rights' => 64,
  294. 'clientid' => 'global'
  295. );
  296. $data = $this->user->get_users($m_array);
  297.  
  298. foreach ($data as $k => $v) {
  299. $client = $this->user->complete_details($v['username']);
  300.  
  301. $data[$k]['tradingname'] = $v['clientid'];
  302. $data[$k]['message'] = NULL;
  303. $data[$k]['blocked'] = NULL;
  304.  
  305. if($client['status'] === 1)
  306. {
  307. $data[$k]['tradingname'] = $client['data']['client_details']['tradingname'];
  308. }
  309.  
  310. $additional = $this->user->get_additional_data($v['username']);
  311.  
  312. if(isset($additional['login_message']))
  313. {
  314. $data[$k]['message'] = $additional['login_message'];
  315. }
  316. if(isset($additional['blocked']))
  317. {
  318. $data[$k]['blocked'] = $additional['blocked'];
  319. }
  320. }
  321.  
  322.  
  323. $this->_get_last_activity($data);
  324.  
  325. header('Content-Type: application/json');
  326. echo json_encode($data);
  327. }
  328.  
  329. public function get_admin_users()
  330. {
  331. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  332.  
  333. $data = $this->adm->get_users();
  334.  
  335. header('Content-Type: application/json');
  336. echo json_encode($data);
  337. }
  338.  
  339. public function get_company()
  340. {
  341. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  342. $this->load_model('client_model', 'client');
  343. $data = $this->client->get_all();
  344.  
  345. header('Content-Type: application/json');
  346. echo json_encode($data);
  347. }
  348.  
  349. public function get_device()
  350. {
  351. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  352.  
  353. $this->load_model('device_model', 'device');
  354. $clientid = $this->get_input("clientid");
  355. $data = $this->device->gw_clientid($clientid);
  356. $devices = array();
  357.  
  358. if(count($data) > 0)
  359. {
  360. $devices = $data[0]['devices'];
  361. foreach ($devices as $k => $v)
  362. {
  363. $devices[$k]['param'] = $this->device->technical_details($v['deviceid']);
  364. }
  365. }
  366.  
  367. header('Content-Type: application/json');
  368. echo json_encode($devices);
  369. }
  370.  
  371. public function load_all_devices()
  372. {
  373. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  374.  
  375. $this->load_model('device_model', 'device');
  376. $devices_data = $this->device->get_all();
  377. $devices = array();
  378.  
  379. if (is_array($devices_data))
  380. {
  381. $devices = array_reduce($devices_data, function ($arr, $v) {
  382. foreach ($v['devices'] as $_i => $_v) {
  383. $arr[] = array(
  384. 'deviceid' => $_v['deviceid'],
  385. 'name' => $_v['name'],
  386. );
  387. }
  388. return $arr;
  389. }, array());
  390.  
  391. usort($devices, function ($a, $b) {
  392. $n1 = $a['name'];
  393. $n2 = $b['name'];
  394.  
  395. return $n1 === $n2 ? 0 : $n1 > $n2 ? 1 : -1;
  396. });
  397. }
  398.  
  399. header('Content-Type: application/json');
  400. echo json_encode($devices);
  401. }
  402.  
  403. public function get_message_template()
  404. {
  405. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  406.  
  407. $data = $this->adm->get_login_message();
  408.  
  409. header('Content-Type: application/json');
  410. echo json_encode($data);
  411. }
  412.  
  413. public function create_message()
  414. {
  415. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  416.  
  417. $resp = array(
  418. 'status' => 0,
  419. 'statusText' => 'Message not created'
  420. );
  421.  
  422. if($this->has_request('admin_id'))
  423. {
  424. $data = array(
  425. 'title' => $this->get_input("title"),
  426. 'content' => $this->get_input("content"),
  427. 'admin_id' => $this->get_input("admin_id")
  428. );
  429.  
  430. $create = $this->adm->create_message($data);
  431.  
  432. if($create)
  433. {
  434. $resp = array(
  435. 'status' => 1,
  436. 'statusText' => 'Created'
  437. );
  438. }
  439. }
  440.  
  441. header('Content-Type: application/json');
  442. echo json_encode($resp);
  443. }
  444.  
  445. public function update_message()
  446. {
  447. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  448.  
  449. $resp = array(
  450. 'status' => 0,
  451. 'statusText' => 'Message not updated'
  452. );
  453.  
  454. if($this->has_request('id'))
  455. {
  456. $data = array( 'id' => $this->get_input("id") );
  457.  
  458. if($this->has_request( "title" )) $data['title'] = $this->get_input( "title" );
  459. if($this->has_request( "content" )) $data['content'] = $this->get_input( "content" );
  460. if($this->has_request( "default" )) $data['default'] = $this->get_input( "default" );
  461.  
  462. $update = $this->adm->update_message($data);
  463.  
  464. if($update)
  465. {
  466. $resp = array(
  467. 'status' => 1,
  468. 'statusText' => 'Updated'
  469. );
  470. }
  471. }
  472.  
  473. header('Content-Type: application/json');
  474. echo json_encode($resp);
  475. }
  476.  
  477. public function remove_message()
  478. {
  479. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  480.  
  481. $resp = array(
  482. 'status' => 0,
  483. 'statusText' => 'Message not removed'
  484. );
  485.  
  486. if($this->has_request('id'))
  487. {
  488. $id = $this->get_input("id");
  489. $remove = $this->adm->remove_message($id);
  490.  
  491. if($remove)
  492. {
  493. $resp = array(
  494. 'status' => 1,
  495. 'statusText' => 'Removed'
  496. );
  497. }
  498. }
  499.  
  500. header('Content-Type: application/json');
  501. echo json_encode($resp);
  502. }
  503.  
  504. public function update_admin()
  505. {
  506. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  507.  
  508. $resp = array(
  509. 'status' => 0,
  510. 'statusText' => 'User data not updated'
  511. );
  512.  
  513. $update = FALSE;
  514.  
  515. if($this->has_request('username'))
  516. {
  517. $id = $this->get_input('id');
  518.  
  519. $data = array(
  520. 'username' => $this->get_input('username'),
  521. 'fullname' => $this->get_input('fullname'),
  522. 'email' => $this->get_input('email')
  523. );
  524.  
  525. $update = FALSE;
  526.  
  527. if($this->has_request('new_password'))
  528. {
  529. $data['password'] = md5($this->get_input('new_password'));
  530. $old_password = $this->get_input('old_password');
  531. $is_exist = $this->adm->is_admin_exist($data['username'], $old_password);
  532.  
  533. if($is_exist)
  534. {
  535. $update = $this->adm->update_admin($id, $data);
  536. }
  537. else
  538. {
  539. $resp = array(
  540. 'status' => 2,
  541. 'statusText' => 'Your old password is wrong.'
  542. );
  543. }
  544. }
  545. else
  546. {
  547. $update = $this->adm->update_admin($id, $data);
  548. }
  549. }
  550.  
  551. if($update)
  552. {
  553. $resp = array(
  554. 'status' => 1,
  555. 'statusText' => 'Updated'
  556. );
  557. }
  558.  
  559. header('Content-Type: application/json');
  560. echo json_encode($resp);
  561. }
  562.  
  563. public function log_message($page = 1, $limit = 20, $filter = '')
  564. {
  565. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  566.  
  567. $pointer = ($page - 1) * $limit;
  568. $data = $this->adm->log_message($pointer, $limit, $filter);
  569. header('Content-Type: application/json');
  570. echo json_encode($data);
  571. }
  572.  
  573. public function log_php($page = 1, $limit = 20, $filter = '')
  574. {
  575. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  576.  
  577. $pointer = ($page - 1) * $limit;
  578. $data = $this->adm->log_php($pointer, $limit, $filter);
  579.  
  580. header('Content-Type: application/json');
  581. echo json_encode($data);
  582. }
  583.  
  584. public function log_php_update($id , $status)
  585. {
  586. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  587.  
  588. $update = $this->adm->log_php_update($id , $status);
  589.  
  590. header('Content-Type: application/json');
  591.  
  592. if($update)
  593. {
  594. echo json_encode(array(
  595. 'status' => 1,
  596. 'statusText' => 'SUCCESS'
  597. ));
  598. return;
  599. }
  600. echo json_encode(array(
  601. 'status' => 0,
  602. 'statusText' => 'FAILED'
  603. ));
  604. }
  605.  
  606. public function log_php_remove($id)
  607. {
  608. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  609.  
  610. $remove = $this->adm->log_php_remove($id);
  611.  
  612. header('Content-Type: application/json');
  613.  
  614. if($remove)
  615. {
  616. echo json_encode(array(
  617. 'status' => 1,
  618. 'statusText' => 'SUCCESS'
  619. ));
  620. return;
  621. }
  622. echo json_encode(array(
  623. 'status' => 0,
  624. 'statusText' => 'FAILED'
  625. ));
  626. }
  627.  
  628. public function log_js($page = 1, $limit = 20, $filter = '')
  629. {
  630. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  631.  
  632. $pointer = ($page - 1) * $limit;
  633. $data = $this->adm->log_js($pointer, $limit, $filter);
  634.  
  635. header('Content-Type: application/json');
  636. echo json_encode($data);
  637. }
  638.  
  639. public function log_js_update($id , $status)
  640. {
  641. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  642.  
  643. $update = $this->adm->log_js_update($id , $status);
  644.  
  645. header('Content-Type: application/json');
  646.  
  647. if($update)
  648. {
  649. echo json_encode(array(
  650. 'status' => 1,
  651. 'statusText' => 'SUCCESS'
  652. ));
  653. return;
  654. }
  655. echo json_encode(array(
  656. 'status' => 0,
  657. 'statusText' => 'FAILED'
  658. ));
  659. }
  660.  
  661. public function log_js_remove($id)
  662. {
  663. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  664.  
  665. $remove = $this->adm->log_js_remove($id);
  666.  
  667. header('Content-Type: application/json');
  668.  
  669. if($remove)
  670. {
  671. echo json_encode(array(
  672. 'status' => 1,
  673. 'statusText' => 'SUCCESS'
  674. ));
  675. return;
  676. }
  677. echo json_encode(array(
  678. 'status' => 0,
  679. 'statusText' => 'FAILED'
  680. ));
  681. }
  682.  
  683. public function get_data_monitor()
  684. {
  685. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  686.  
  687.  
  688. }
  689.  
  690. public function login()
  691. {
  692. $this->_goto_home_page();
  693.  
  694. $assets = $GLOBALS['config']['base_url'] . 'assets/';
  695. $favicon = $assets . 'img/favicon.ico';
  696. $admin = $assets . "admin";
  697.  
  698. $data = array(
  699. 'assets_path' => $admin,
  700. 'favicon' => $favicon,
  701. 'topjs' => array(),
  702. 'page_title' => $this->title,
  703. 'ajs' => array(
  704. "$admin/js/jquery-1.7.2.min.js",
  705. // "$admin/js/app/controllers.js",
  706. ),
  707. 'acss' => array(
  708. // $assets . "css/vendor/bootstrap.css",
  709. // $assets . "css/vendor/bootstrap-responsive.css"
  710. "$admin/css/bootstrap.min.css",
  711. "$admin/css/bootstrap-responsive.min.css",
  712. "$admin/css/font-awesome.css",
  713. "$admin/css/style.css",
  714. "$admin/css/pages/signin.css"
  715. )
  716. );
  717. $this->load->view('admin/login', $data);
  718. }
  719.  
  720. public function logout()
  721. {
  722. $_SESSION = array();
  723. session_destroy();
  724. $this->_goto_login_page();
  725. }
  726.  
  727. public function login_check()
  728. {
  729. if($_SESSION['is_logged_in'] === TRUE) die('You are already logged in');
  730.  
  731. $username = $this->get_input('username');
  732. $password = $this->get_input('password');
  733.  
  734. $check = $this->adm->login_check($username, $password);
  735.  
  736. if($check['status'] === 1)
  737. {
  738. $_SESSION['is_logged_in'] = TRUE;
  739. $_SESSION['username'] = $check['data']['username'];
  740. $_SESSION['level'] = $check['data']['level'];
  741. $_SESSION['userdata'] = $check['data'];
  742. }
  743.  
  744. header('Content-Type: application/json');
  745. echo json_encode($check);
  746. die();
  747. }
  748.  
  749. public function start_recache()
  750. {
  751. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  752.  
  753. $location = __DIR__ . '/../tmp/caching_position/';
  754. $start_date = $this->get_input('start_date');
  755. $end_date = $this->get_input('end_date');
  756. $devices = $this->get_input('devices');
  757.  
  758. foreach ($devices as $k => $v)
  759. {
  760. $content = array(
  761. 'start_date' => $start_date,
  762. 'end_date' => $end_date,
  763. 'deviceid' => $v,
  764. );
  765. $touch_file = $this->_touch_recache_file($location, $content);
  766. }
  767.  
  768. header('Content-Type: application/json');
  769. echo json_encode(array(
  770. 'status' => $touch_file ? 1 : 0,
  771. 'statusText' => $touch_file ? 'SUCCESS' : 'FAILED',
  772. ));
  773. }
  774.  
  775. public function start_recache_dj()
  776. {
  777. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  778.  
  779. $location = __DIR__ . '/../tmp/caching_drv_journey/';
  780. $start_date = $this->get_input('start_date');
  781. $end_date = $this->get_input('end_date');
  782. $clientid = $this->get_input('clientid');
  783.  
  784. $content = array(
  785. 'start_date' => $start_date,
  786. 'end_date' => $end_date,
  787. 'clientid' => $clientid,
  788. );
  789.  
  790. $touch_file = $this->_touch_recache_file($location, $content);
  791.  
  792. header('Content-Type: application/json');
  793. echo json_encode(array(
  794. 'status' => $touch_file ? 1 : 0,
  795. 'statusText' => $touch_file ? 'SUCCESS' : 'FAILED',
  796. ));
  797. }
  798.  
  799. public function get_incomplete_caching()
  800. {
  801. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  802.  
  803. $location = __DIR__ . '/../tmp/caching_position/';
  804. $incomple_data = $this->_read_incomplete_caching($location);
  805.  
  806. header('Content-Type: application/json');
  807. echo json_encode($incomple_data);
  808. }
  809.  
  810. public function get_incomplete_caching_dj()
  811. {
  812. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  813.  
  814. $location = __DIR__ . '/../tmp/caching_drv_journey/';
  815. $incomple_data = $this->_read_incomplete_caching($location);
  816.  
  817. header('Content-Type: application/json');
  818. echo json_encode($incomple_data);
  819. }
  820.  
  821.  
  822. public function log_js_ignore()
  823. {
  824. if($_SESSION['is_logged_in'] !== TRUE) die('You are not authorized!');
  825.  
  826. $file = $this->get_input('file');
  827. $message = $this->get_input('message');
  828.  
  829. $success = $this->adm->log_js_ignore($file, $message);
  830.  
  831. header('Content-Type: application/json');
  832.  
  833. if($success)
  834. {
  835. echo json_encode(array(
  836. 'status' => 1,
  837. 'statusText' => 'SUCCESS'
  838. ));
  839. return;
  840. }
  841.  
  842. echo json_encode(array(
  843. 'status' => 0,
  844. 'statusText' => 'FAILED'
  845. ));
  846. }
  847.  
  848. private function _get_last_activity(&$data)
  849. {
  850. $users = array();
  851.  
  852. $filename = $GLOBALS['config']['real_path'] . 'log/access.log';
  853. $lineCount = 0;
  854. $handle = fopen($filename, "r");
  855.  
  856. if(!file_exists($filename)) return $data;
  857.  
  858. // $timer = microtime(true);
  859.  
  860. while( ! feof($handle) )
  861. {
  862. $line = fgets($handle);
  863. $test = preg_match("/^(\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d)\s\|\s([\w\.]+)/", $line, $match);
  864.  
  865. if($test === 1) $users[$match[2]] = $match[1];
  866.  
  867. $lineCount++;
  868. }
  869.  
  870. foreach ($data as $k => $v)
  871. {
  872. $user = explode('@', $v['username']);
  873. $username = $user[0];
  874.  
  875. $data[$k]['last_active'] = " - ";
  876.  
  877. if(isset($users[$username]))
  878. {
  879. $data[$k]['last_active'] = strtotime($users[$username]) * 1000;
  880. }
  881. }
  882.  
  883. return $data;
  884. }
  885.  
  886. private function _goto_login_page()
  887. {
  888. if( ! isset($_SESSION['is_logged_in']) ) $_SESSION['is_logged_in'] = FALSE;
  889.  
  890. if($_SESSION['is_logged_in'] !== TRUE)
  891. {
  892. pageRedirect('admin/login');
  893. }
  894. }
  895.  
  896. private function _goto_home_page()
  897. {
  898. if( ! isset($_SESSION['is_logged_in']) ) $_SESSION['is_logged_in'] = FALSE;
  899.  
  900. if($_SESSION['is_logged_in'] === TRUE)
  901. {
  902. pageRedirect('admin');
  903. }
  904. }
  905.  
  906. private function _touch_recache_file($location, $content)
  907. {
  908. $put = 0;
  909.  
  910. if(!file_exists($location))
  911. {
  912. mkdir($location);
  913. chmod($location, 0775);
  914. }
  915.  
  916. $json_data = json_encode($content);
  917. $file_name = md5($json_data);
  918. $full_path = $location . $file_name;
  919.  
  920. if(!file_exists($full_path))
  921. {
  922. $put = file_put_contents($full_path, $json_data);
  923. }
  924.  
  925. return $put > 0;
  926. }
  927.  
  928. private function _read_incomplete_caching($location)
  929. {
  930. $output = array();
  931. if(is_dir($location))
  932. {
  933. $files = scandir($location);
  934. foreach ($files as $i => $v)
  935. {
  936. if($v === '.' || $v === '..') continue;
  937.  
  938. $full_path = $location . $v;
  939. if(!file_exists($full_path)) continue;
  940.  
  941. $elapsed_time = time() - filemtime($full_path);
  942. $req = json_decode(file_get_contents($full_path), TRUE);
  943. $req['elapsed_time'] = $elapsed_time;
  944. $output[] = $req;
  945. }
  946. }
  947.  
  948. return $output;
  949. }
  950. }
  951.  
  952. /* End of file admin.php */
  953. /* Location: ./controllers/admin.php */
Add Comment
Please, Sign In to add comment