· 8 years ago · Jan 15, 2018, 02:18 PM
1<?php
2
3//Working with unique_sessions table
4//store information about
5//begin session, end session
6//input parameters:
7//us_id : id of unque session, used only on end session call and get session call
8//proj_id : id of project for session, given from projects
9//sess_id : id of session template, given from sessions
10//tal_id : id of talent, given from talents
11//prod_id : id of producer, given from producers
12//action : description of action [begin|end|get]
13//TODO dntknw this
14//s_start_t : date and time of begin session call timestamp ???
15//s_stop_t : date and time of end session call timestamp ???
16//table structure:
17//CREATE TABLE IF NOT EXISTS `unique_sessions` (
18// `us_id` int(6) unsigned NOT NULL AUTO_INCREMENT,
19// `proj_id` int(6) NOT NULL,
20// `sess_id` int(11) NOT NULL,
21// `tal_id` int(11) NOT NULL,
22// `prod_id` int(6) NOT NULL,
23// `sess_start_time` datetime NOT NULL,
24// `sess_down_time` datetime NOT NULL,
25// PRIMARY KEY (`us_id`)
26//) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
27
28require_once ("slashes.php");
29require_once ('header.php');
30require_once ($config['ROOT_PATH'] . '/lib/common/functions.php');
31
32$errorMessage = '';
33$resultMessage = '';
34$tableName = 'unique_sessions';
35if (isset($_REQUEST['action']))
36{
37 $action = mysql_real_escape_string($_REQUEST['action']);
38
39 if ($action == 'begin' &&
40 isset($_REQUEST['proj_id']) &&
41 isset($_REQUEST['sess_id']) &&
42 isset($_REQUEST['tal_id']) &&
43 isset($_REQUEST['prod_id']))
44 {
45 //there we inserting new unique session into db
46 //set begin time == down time - it will be interpreted as
47 //session incomplete - the session is not closed correctly
48 $proj_id = mysql_real_escape_string($_REQUEST['proj_id']);
49 $sess_id = mysql_real_escape_string($_REQUEST['sess_id']);
50 $tal_id = mysql_real_escape_string($_REQUEST['tal_id']);
51 $prod_id = mysql_real_escape_string($_REQUEST['prod_id']);
52 $begin_time = date();
53 $insert_array = array(
54 'proj_id' => $proj_id,
55 'sess_id' => $sess_id,
56 'tal_id' => $tal_id,
57 'prod_id' => $prod_id,
58 'sess_start_time' => $begin_time,
59 'sess_down_time' => $begin_time
60 );
61 if ($db->db_insert($tableName, $insert_array, false))
62 {
63 //ok, row inserted
64 $new_uniq_sess_id = mysql_insert_id();
65 } else
66 {
67 $errorMessage = 'Unable to insert new unique session';
68 }
69 } else
70 if ($action == 'end')
71 {
72 if (isset($_REQUEST['us_id']))
73 {
74 //there we update unique session in db and set sess_down_time for it
75 //there the session marked as closed correctly
76 $end_time = date();
77 $update_array = array(
78 'sess_down_time' => $end_time
79 );
80 $where = 'sess_id = ' . mysql_real_escape_string($_REQUEST['us_id']);
81 if ($db->db_update($tableName, $update_array, $where))
82 {
83 //ok, row updated
84 } else
85 {
86 $errorMessage = 'Unable to update db!';
87 }
88 } else
89 {
90 $errorMessage = 'Unique session ID is not set!';
91 }
92 }if ($action == 'get')
93 {
94
95 if (isset($_REQUEST['us_id']))
96 {
97 //there we return 1 unique session from db
98 $columns = '*';
99 $where = 'us_id = ' . mysql_real_escape_string($_REQUEST['us_id']);
100 $unique_session = $db->db_get_one_record($tableName, $columns, $where);
101 if (count($unique_session))
102 {
103 //ok, row get
104
105 }
106 } else
107 {
108 $errorMessage = 'Unique session ID is not set!';
109 }
110 } else
111 {
112 $errorMessage = 'Unknows action : ' . $action;
113 }
114}
115?>