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