[go: up one dir, main page]

Menu

[3822d7]: / core / Activity.php  Maximize  Restore  History

Download this file

319 lines (264 with data), 7.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
namespace ICT\Core;
/* * ***************************************************************
* Copyright © 2022 ICT Innovations Pakistan All Rights Reserved *
* Developed By: Nasir Iqbal *
* Website : http://www.ictinnovations.com/ *
* Mail : nasir@ictinnovations.com *
* *************************************************************** */
use ICT\Core\DB;
use ICT\Core\User;
use ICT\Core\Corelog;
use ICT\Core\Transmission;
class Activity
{
private static $table = NULL;
private static $fields = array(
'activity_id',
'user_id',
'ip_address',
'activities',
'fax_id',
'sourceid',
'sourcename',
'sourcephone',
'callerid',
'destination',
'destinationname',
'faxstatus',
'duration',
'pending',
'processing',
'origin',
'date'
);
private static $read_only = array(
'activity_id',
);
/**
* @var integer
*/
public $activity_id = NULL;
/**
* @var integer
*/
public $user_id = NULL;
/**
* @var string
*/
public $ip = NULL;
/**
* @var string
*/
public $log = NULL;
/**
* @var integer
*/
public $fax_id = NULL;
/**
* @var string
*/
public $username = NULL;
/** @var integer */
public $phone = NULL;
/** @var integer */
public $callerid = NULL;
/** @var integer */
public $destinationphone = NULL;
/** @var string */
public $destinationname = NULL;
/** @var string */
public $faxstatus = NULL;
/** @var string */
public $response = NULL;
/** @var string */
public $coverpage = NULL;
/** @var int */
public $pages = NULL;
/** @var string */
public $duration = NULL;
/** @var string */
public $pending = NULL;
/** @var string */
public $processing = NULL;
/** @var string */
public $result = NULL;
/** @var string */
public $origin = NULL;
/** @var string */
public $date = NULL;
public function userlogs($log,$userid=NULL,$username=NULL ){
$this->user_id = $userid;
$this->username = $username;
$this->set_essen($log);
self::$table = 'activitylogs';
$this->usersave();
}
public function faxlogs($trans_id , $response){
$this->set_essen();
$this->fax_id = $trans_id;
$trans = new Transmission($trans_id);
$this->faxstatus = $trans->status;
$this->date = date('Y/m/d H:i:s');
$this->origin = $trans->origin;
$this->response = $response;
self::$table = 'faxlogs';
$programid = $trans->program_id;
$query = "SELECT s.*, a.application_id
FROM spool_result s
JOIN application a ON s.application_id = a.application_id
WHERE a.program_id = $programid AND s.name = 'pages'";
$result = DB::query('spool_result' , $query);
$data = mysqli_fetch_assoc($result);
$this->pages = $data['data'];
$this->faxsave();
}
public function faxactivity($log,$trans_id){
$this->set_essen($log);
$this->fax_id = $trans_id;
self::$table = 'faxactivity';
$this->faxactivitysave();
}
public static function systemactivity($aFilter = array() )
{
$aactivities = array();
$from_str = 'activitylogs';
$aWhere = array();
foreach ($aFilter as $search_field => $search_value) {
switch ($search_field) {
case 'id':
$aWhere[] = "id = $search_value";
break;
case 'user_id':
$aWhere[] = "user_id = '$search_value'";
break;
case 'activities':
case 'username':
$aWhere[] = "$search_field LIKE '%$search_value'";
break;
}
}
if (!empty($aWhere)) {
$from_str .= ' WHERE ' . implode(' AND ', $aWhere);
}
$query = "SELECT * FROM " . $from_str ." ORDER BY id DESC";;
$result = DB::query('activitylogs', $query);
while ($data = mysqli_fetch_assoc($result)) {
$aactivities[] = $data;
}
return $aactivities;
}
public function faxactivitysave()
{
$data = array(
'faxid' => $this->fax_id,
'faxactivity' => $this->log,
'date' => $this->date
);
$result = DB::update(self::$table, $data, false);
return $result;
}
public function set_essen($log = NULL){
$ip = $_SERVER['REMOTE_ADDR'];
if(empty($this->user_id)){
$this->user_id = Session::get_instance()->user->user_id;
}
if(empty($this->username)){
$this->username = Session::get_instance()->user->username;
}
if($this->user_id == -1){
$this->username = "Retention";
}
$this->phone = Session::get_instance()->user->phone;
$coverpage = Session::get_instance()->user->cover;
if($coverpage == 1){
$this->coverpage = "Yes";
}
else{
$this->coverpage = "No";
}
if(Session::get_instance()->transmission){
$this->callerid = Session::get_instance()->transmission->source->phone;
$this->destinationphone = Session::get_instance()->transmission->destination->phone;
$this->destinationname = Session::get_instance()->transmission->destination->username;
}
$this->date = date('Y/m/d H:i:s');
$this->ip = $ip;
$this->log = $log;
}
public function usersave()
{
$data = array(
'activity_id' => $this->activity_id,
'username' => $this->username,
'user_id' => $this->user_id,
'ip_address' => $this->ip,
'activities' => $this->log,
'date' => strtotime($this->date)
);
$result = DB::update(self::$table, $data, false);
$userSessionData = array(
'user_id' => $this->user_id,
'username' => $this->username,
'activities' => $this->log,
'date' => $this->date
);
// Check if the user already exists in the usersession table
$query = "SELECT * FROM usersession WHERE user_id = {$this->user_id}";
$userSessionResult = DB::query('usersession', $query);
if (mysqli_num_rows($userSessionResult) > 0) {
// Update the existing record
$result = DB::update('usersession', $userSessionData, 'user_id');
} else {
// Insert a new record
$result = DB::update('usersession', $userSessionData, false);
}
return $result;
}
public function faxsave()
{
$data = array(
'faxid' => $this->fax_id,
'sourceid' => $this->user_id,
'sourcename' => $this->username,
'sourcephone' => $this->phone,
'callerid' =>$this->callerid,
'coverpage' =>$this->coverpage,
'destination' => $this->destinationphone,
'destinationname' => $this->destinationname,
'faxstatus' => $this->faxstatus,
'duration' => $this->duration,
'origin' => $this->origin,
'date' => $this->date
);
if(isset($this->fax_id)){
$query = "select * from faxlogs where faxid = $this->fax_id";
$result = DB::query(self::$table , $query);
if(mysqli_num_rows($result) > 0){
$data = array(
'faxid' => $this->fax_id,
'callerid' => $this->callerid,
'destination' => $this->destinationphone,
'destinationname' => $this->destinationname,
'pages' => $this->pages,
'faxstatus' => $this->faxstatus,
'origin' => $this->origin,
'response' => $this->response,
);
if($this->faxstatus === 'processing'){
$data['processing'] = date('Y/m/d H:i:s');
}
if($this->faxstatus === 'completed'){
$data['result'] = date('Y/m/d H:i:s');
}
$result = DB::update(self::$table, $data, 'faxid');
}
else{
$data['pending'] = date('Y/m/d H:i:s');
$result = DB::update(self::$table, $data, false);
}
}
return $result;
}
}
?>