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

/BMTmobile-master/application/controllers/backup/logJSON.php

https://gitlab.com/webservers/codeigniter_mobile_dev_server
PHP | 129 lines | 73 code | 5 blank | 51 comment | 13 complexity | 8506ba4e14ce5bd3e0e8f1c671cf7b40 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once('base.php');
  3. class logJSON extends base {
  4. /**
  5. * Index Page for this controller.
  6. *
  7. * Maps to the following URL
  8. * http://example.com/index.php/welcome
  9. * - or -
  10. * http://example.com/index.php/welcome/index
  11. * - or -
  12. * Since this controller is set as the default controller in
  13. * config/routes.php, it's displayed at http://example.com/
  14. *
  15. * So any other public methods not prefixed with an underscore will
  16. * map to /index.php/welcome/<method_name>
  17. * @see http://codeigniter.com/user_guide/general/urls.html
  18. *
  19. * -------- These are the same -------
  20. * http://localhost/phoneGap/index.php/Log/
  21. * http://localhost/phoneGap/index.php/Log/view
  22. *
  23. * ----- The Functions -----
  24. * http://localhost/phoneGap/index.php/Log/insert?message=%22test0%22
  25. * http://localhost/phoneGap/index.php/Log/clear
  26. *
  27. */
  28. function __construct(){
  29. parent::__construct();
  30. $this->load->model('Log_model');
  31. }
  32. //TODO would have to utilize the "Last activity" = 1353148039 field to determine
  33. //if session is inactive, default would've been 7200 and automatic
  34. //but I wanted to save the UserAgent etc for binding to Logs
  35. //without the need for a seperate table.
  36. //I could also parse By UserName or whatever else I can stuff in the "User Data" Field
  37. //
  38. // I could also Parse Out this users session that accesses the Admin Page
  39. // but would like to find a solution that allows mobile web Access as well as App Logging.
  40. // $this->log_Model->getSessionEquals();
  41. public function jsonLogsBySessionsActivity(){
  42. //"SELECT DISTINCT `Logs`.Session_id FROM `Logs`;"
  43. //"SELECT `session_id` FROM `ci_sessions`;"
  44. $r = $this->Log_model->LogsFromInactiveSession();
  45. $matches = array(); //Logs with active sessions
  46. $notMatches = array();
  47. //var_dump($r);
  48. //0: Logs
  49. //1: ci_sessions
  50. //Match the Session Id's
  51. for($i=0;$i<count($r[0]);$i++){
  52. for($j=0;$j<count($r[1]);$j++){
  53. if($r[0][$i]->Session_id == $r[1][$j]->session_id){
  54. //echo "match: ".$i.", ".$r[0][$i]->Session_id."\n";
  55. $matches[] = $r[0][$i]->Session_id;
  56. }
  57. }
  58. }
  59. //weed out the Id's that don't have a match,
  60. //these don't have an entry in the ci_sessions TABLE, because they expired
  61. for($i=0;$i<count($r[0]);$i++){
  62. if( array_search($r[0][$i]->Session_id, $matches) === false ){
  63. //echo "!match: ".$i.", ".$r[0][$i]->Session_id."\n";
  64. $notMatches[] = $r[0][$i]->Session_id;
  65. }
  66. }
  67. //Json Encoding an object provides the best results
  68. $o = new stdClass();
  69. $o->Logs = array();
  70. if(count($matches) > 0)
  71. $o->Logs['active'] = $matches;
  72. else
  73. $o->Logs['active'] = null;
  74. if(count($notMatches) > 0)
  75. $o->Logs['inActive'] = $notMatches;
  76. else
  77. $o->Logs['inActive'] = null;
  78. //var_dump($o);
  79. echo json_encode($o);
  80. }
  81. public function jsonAllSessions(){
  82. //'SELECT * FROM ci_sessions;'
  83. $aSess = $this->Log_model->activeSessions();
  84. $this->parseUserAgent($aSess);
  85. //var_dump($aSess);
  86. echo '{"Sessions":'.json_encode($aSess).'}';
  87. }
  88. public function jsonLog(){
  89. if( isset($_POST['session_id']) ){
  90. $data = $this->Log_model->LogsFromSession(); //gets variables from post vars
  91. }
  92. else{
  93. $data = $this->Log_model->get_last_ten_entries();
  94. }
  95. $o = new stdClass(); $o->Logs = $data; echo json_encode($o);
  96. }
  97. public function jsonAccess(){
  98. $data = $this->Log_model->get_last_ten_Access();
  99. //$this->load->view('db_output_test', $data);
  100. $o = new stdClass();
  101. $o->Access = $data;
  102. echo json_encode($o);
  103. }
  104. public function index(){
  105. $this->jsonLog();
  106. }
  107. public function yourSession(){
  108. $o = new stdClass(); $o->Logs = $this->session->userdata;
  109. echo json_encode($o);
  110. }
  111. public function jsonInsertLog(){
  112. //echo $_GET['message'];
  113. if($this->Log_model->insert($this->session->userdata)) $this->echoJSONSuccess();
  114. else $this->echoJSONFailure("Database Error or message argument not set! '.json_encode($_POST).'");
  115. }
  116. public function jsonClearLogs(){
  117. if( $this->Log_model->clear() )
  118. $this->echoJSONSuccess();
  119. else
  120. $this->echoJSONFailure("error clearing Logs");
  121. }
  122. }
  123. /* End of file welcome.php */
  124. /* Location: ./application/controllers/welcome.php */