/BMTmobile-master/application/controllers/backup/logJSON.php
PHP | 129 lines | 73 code | 5 blank | 51 comment | 13 complexity | 8506ba4e14ce5bd3e0e8f1c671cf7b40 MD5 | raw file
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once('base.php');
- class logJSON extends base {
- /**
- * Index Page for this controller.
- *
- * Maps to the following URL
- * http://example.com/index.php/welcome
- * - or -
- * http://example.com/index.php/welcome/index
- * - or -
- * Since this controller is set as the default controller in
- * config/routes.php, it's displayed at http://example.com/
- *
- * So any other public methods not prefixed with an underscore will
- * map to /index.php/welcome/<method_name>
- * @see http://codeigniter.com/user_guide/general/urls.html
- *
- * -------- These are the same -------
- * http://localhost/phoneGap/index.php/Log/
- * http://localhost/phoneGap/index.php/Log/view
- *
- * ----- The Functions -----
- * http://localhost/phoneGap/index.php/Log/insert?message=%22test0%22
- * http://localhost/phoneGap/index.php/Log/clear
- *
- */
- function __construct(){
- parent::__construct();
- $this->load->model('Log_model');
- }
- //TODO would have to utilize the "Last activity" = 1353148039 field to determine
- //if session is inactive, default would've been 7200 and automatic
- //but I wanted to save the UserAgent etc for binding to Logs
- //without the need for a seperate table.
- //I could also parse By UserName or whatever else I can stuff in the "User Data" Field
- //
- // I could also Parse Out this users session that accesses the Admin Page
- // but would like to find a solution that allows mobile web Access as well as App Logging.
- // $this->log_Model->getSessionEquals();
- public function jsonLogsBySessionsActivity(){
- //"SELECT DISTINCT `Logs`.Session_id FROM `Logs`;"
- //"SELECT `session_id` FROM `ci_sessions`;"
- $r = $this->Log_model->LogsFromInactiveSession();
- $matches = array(); //Logs with active sessions
- $notMatches = array();
- //var_dump($r);
- //0: Logs
- //1: ci_sessions
- //Match the Session Id's
- for($i=0;$i<count($r[0]);$i++){
- for($j=0;$j<count($r[1]);$j++){
- if($r[0][$i]->Session_id == $r[1][$j]->session_id){
- //echo "match: ".$i.", ".$r[0][$i]->Session_id."\n";
- $matches[] = $r[0][$i]->Session_id;
- }
- }
- }
- //weed out the Id's that don't have a match,
- //these don't have an entry in the ci_sessions TABLE, because they expired
- for($i=0;$i<count($r[0]);$i++){
- if( array_search($r[0][$i]->Session_id, $matches) === false ){
- //echo "!match: ".$i.", ".$r[0][$i]->Session_id."\n";
- $notMatches[] = $r[0][$i]->Session_id;
- }
- }
-
- //Json Encoding an object provides the best results
- $o = new stdClass();
- $o->Logs = array();
- if(count($matches) > 0)
- $o->Logs['active'] = $matches;
- else
- $o->Logs['active'] = null;
- if(count($notMatches) > 0)
- $o->Logs['inActive'] = $notMatches;
- else
- $o->Logs['inActive'] = null;
- //var_dump($o);
- echo json_encode($o);
- }
- public function jsonAllSessions(){
- //'SELECT * FROM ci_sessions;'
- $aSess = $this->Log_model->activeSessions();
- $this->parseUserAgent($aSess);
- //var_dump($aSess);
- echo '{"Sessions":'.json_encode($aSess).'}';
- }
- public function jsonLog(){
- if( isset($_POST['session_id']) ){
- $data = $this->Log_model->LogsFromSession(); //gets variables from post vars
- }
- else{
- $data = $this->Log_model->get_last_ten_entries();
- }
- $o = new stdClass(); $o->Logs = $data; echo json_encode($o);
- }
- public function jsonAccess(){
- $data = $this->Log_model->get_last_ten_Access();
- //$this->load->view('db_output_test', $data);
- $o = new stdClass();
- $o->Access = $data;
- echo json_encode($o);
- }
- public function index(){
- $this->jsonLog();
- }
- public function yourSession(){
- $o = new stdClass(); $o->Logs = $this->session->userdata;
- echo json_encode($o);
- }
- public function jsonInsertLog(){
- //echo $_GET['message'];
- if($this->Log_model->insert($this->session->userdata)) $this->echoJSONSuccess();
- else $this->echoJSONFailure("Database Error or message argument not set! '.json_encode($_POST).'");
- }
- public function jsonClearLogs(){
- if( $this->Log_model->clear() )
- $this->echoJSONSuccess();
- else
- $this->echoJSONFailure("error clearing Logs");
- }
- }
- /* End of file welcome.php */
- /* Location: ./application/controllers/welcome.php */