-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
756 lines (641 loc) · 17.5 KB
/
index.php
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
<?php
// include configuration file
include_once 'config/core.php';
// include the head template
//include_once "layout_head.php";
require_once 'config/database.php';
/* ini_set("post_max_size", "30M");
ini_set("upload_max_filesize", "30M"); */
session_start();
//include 'index1.php';
$_SESSION['app_error'] = '';
$_SESSION['company_disp_name'] = 'Suncom Mobile';
// Exception Handler starts
// Kuppuram has added following 2 lines on 30-Nov-2017 - to overcome 500 Internal Server Error
// After adding following 2 lines, the class files not found was disclosed as error.
ini_set('display_errors', 1);
error_reporting(E_ALL);
set_exception_handler('exception_handler');
set_error_handler("error_handler");
function error_handler($code, $message, $file, $line)
{
if (0 == error_reporting())
{
return;
}
throw new ErrorException($message, 0, $code, $file, $line);
}
function exception_handler($e) {
// public message
$results = array();
$results['errorReturnAction'] = "";
$err = '';
$retresult['success'] = false;
if (contains($e->getMessage(), '18KSoftec Error:'))
{
$retresult['errors'] = strstr($e->getMessage(), '18KSoftec Error:');
$results['errorMessage'] = strstr($e->getMessage(), '18KSoftec Error:');
K18_utility::saveError(strstr($e->getMessage(), '18KSoftec Error:'));
}
else
{
$retresult['errors'] = $e->getMessage();
$results['errorMessage'] = '18K Softec Error : ' . $e->getMessage() . ' - Source of Error : line - ' . $e->getLine() . ' in ' . $e->getFile() . ' Please send screen shot to Kuppuram' ;
$err = '18K Softec Error : ' . $e->getMessage() . ' - Source of Error : line - ' . $e->getLine() . ' in ' . $e->getFile() . ' Please send screen shot to Kuppuram' ;
K18_utility::saveError($err);
}
//echo $results['errorMessage'];
echo json_encode($retresult);
//echo "<a href='" . TEMPLATE_PATH . "/errorDialog.php'" . " target=\'_blank\'>Error</a>";
//echo '[{"Error - status":"' . $results['errorMessage'] . '"}]'; // It seems this is good json format. but it is not returning back to called ajax function
//trigger_error( '[{"Error - status":"' . $results['errorMessage'] . '"}]');
//trigger_error( $results['errorMessage']);
//require( TEMPLATE_PATH . "/errorDialog.php" );
//viewError();
}
// Exception Handler ends
global $controller;
global $controllerAction;
if(isset($_GET['uid'])&&isset($_GET['type']))
{
if(checkUserAccess($_GET['uid'],$_GET['type']) > 0)
{
login();
}
else
{
require( TEMPLATE_PATH . "/login_page.php" );
exit;
}
}
else
{
if(isset($_GET['action']) || isset($_POST['action']))
{
if(isset($_SESSION['uid']) || isset($_POST['login']))
{
if(isset($_GET['action']))
$action = $_GET['action'];
else
$action = $_POST['action'];
if(function_exists($action))
{
$action();
}
else
{
logout();
}
}
else
{
require( TEMPLATE_PATH . "/login_page.php" );
exit;
}
}
else
{
require( TEMPLATE_PATH . "/login_page.php" );
exit;
}
}
function login()
{
require( TEMPLATE_PATH . "/district_views_page.php" );
}
function logout()
{
session_destroy();
require( TEMPLATE_PATH . "/login_page.php" );
}
function inprocess()
{
require( TEMPLATE_PATH . "/inprocess_page.php" );
}
function globalsearch()
{
require( TEMPLATE_PATH . "/global_search.php" );
}
function settings()
{
require( TEMPLATE_PATH . "/settings_page.php" );
}
function marketPage()
{
require( TEMPLATE_PATH . "/market_views_page.php" );
}
function regionPage()
{
require( TEMPLATE_PATH . "/region_views_page.php" );
}
function storesPage()
{
require( TEMPLATE_PATH . "/stores_views_page.php" );
}
function blankPage()
{
require( TEMPLATE_PATH . "/blankPage.php" );
}
function DMPage()
{
require( TEMPLATE_PATH . "/district_views_page.php" );
}
function homePage()
{
require( TEMPLATE_PATH . "/district_views_page.php" );
}
function viewChangePasswordPage()
{
require( TEMPLATE_PATH . "/changePassword_page.php" );
}
function usersPage()
{
require( TEMPLATE_PATH . "/users_views_page.php" );
}
function hrreportPage()
{
require( TEMPLATE_PATH . "/upload_hr_report_views_page.php" );
}
function rentfilePage()
{
require( TEMPLATE_PATH . "/upload_rent_file_views_page.php" );
}
function dailydashboard()
{
require( TEMPLATE_PATH . "/dailydashboard_views_page.php" );
}
function storesdocsPage()
{
require( TEMPLATE_PATH . "/stores_docs_views_page.php" );
}
function monthlyEbitPage()
{
require( TEMPLATE_PATH . "/monthly_ebit_upload_views_page.php" );
}
function Export_Store_Masterlist()
{
require( TEMPLATE_PATH . "/stores_export_page.php" );
}
function userAuthPage()
{
require( TEMPLATE_PATH . "/user_auth_views_page.php" );
}
// Save Regular Expense
function saveRegExp() {
$results = array();
$results['errorReturnAction'] = "saveRegExp";
if ($_REQUEST['mode'] == 'add')
{
regular_expense::add();
}
else if ($_REQUEST['mode'] == 'update')
{
regular_expense::update();
}
if ($_REQUEST['mode'] == 'approve')
{
regular_expense::approve();
}
}
function userCreation() {
$results = array();
$results['errorReturnAction'] = "userCreation";
if ($_REQUEST['mode'] == 'add')
{
userCreation::add();
}
else if ($_REQUEST['mode'] == 'update')
{
userCreation::update();
}
if ($_REQUEST['mode'] == 'delete')
{
userCreation::deleteuser();
}
}
function storesCreation() {
$results = array();
$results['errorReturnAction'] = "storesCreation";
if ($_REQUEST['mode'] == 'add')
{
storesCreation::add();
}
else if ($_REQUEST['mode'] == 'update')
{
storesCreation::update();
}
if ($_REQUEST['mode'] == 'delete')
{
storesCreation::deletestores();
}
}
function userProfileUpdate() {
$results = array();
$results['errorReturnAction'] = "userProfileUpdate";
userProfile::update();
}
// Assign Ticket Tech
function saveSettings()
{
$results = array();
$results['errorReturnAction'] = "storesCreation";
if ($_REQUEST['mode'] == 'add')
{
settings_op::add_settings();
}
else if ($_REQUEST['mode'] == 'update')
{
settings_op::update_settings();
}
else if($_REQUEST['mode'] == 'delete')
{
settings_op::delete_settings();
}
}
function saveDistrict()
{
$results = array();
$results['errorReturnAction'] = "saveDistrict";
if ($_REQUEST['mode'] == 'add')
{
district_op::add_district();
}
else if ($_REQUEST['mode'] == 'update')
{
district_op::update_district();
}
else if($_REQUEST['mode'] == 'delete')
{
district_op::delete_district();
}
}
function saveMarket()
{
$results = array();
$results['errorReturnAction'] = "saveMarket";
if ($_REQUEST['mode'] == 'add')
{
market_op::add_market();
}
else if ($_REQUEST['mode'] == 'update')
{
market_op::update_market();
}
else if($_REQUEST['mode'] == 'delete')
{
market_op::delete_market();
}
}
function saveRegion()
{
$results = array();
$results['errorReturnAction'] = "saveRegion";
if ($_REQUEST['mode'] == 'add')
{
region_op::add_region();
}
else if($_REQUEST['mode'] == 'delete')
{
region_op::delete_region();
}
}
function saveStore()
{
$results = array();
$results['errorReturnAction'] = "saveStore";
if ($_REQUEST['mode'] == 'add')
{
store_op::add_store();
}
else if ($_REQUEST['mode'] == 'update')
{
store_op::update_store();
}
else if($_REQUEST['mode'] == 'delete')
{
store_op::delete_store();
}
}
function saveUsers()
{
try
{
$results = array();
$results['errorReturnAction'] = "saveUsers";
if ($_REQUEST['mode'] == 'add')
{
users_op::add_users();
}
else if($_REQUEST['mode'] == 'update')
{
users_op::update_users();
}
else if($_REQUEST['mode'] == 'delete')
{
users_op::delete_users();
}
else if($_REQUEST['mode'] == 'clearFlood')
{
users_op::clear_flood();
}
}
catch (Exception $e)
{
$retresult['success'] = false;
if (contains($e->getMessage(), '18KSoftec Error:'))
{
$retresult['errors'] = strstr($e->getMessage(), '18KSoftec Error:');
}
else
{
$retresult['errors'] = "Submission is not successful" . $e->getMessage();
}
echo json_encode($retresult);
$conn = null;
return;
}
}
function saveHRReport()
{
$results = array();
$results['errorReturnAction'] = "saveHRReport";
hrreport_op::update_hrreport();
}
function saveRentFile()
{
$results = array();
$results['errorReturnAction'] = "saveRentFile";
rentfile_op::update_rentfile();
}
function saveDocType()
{
$results = array();
$results['errorReturnAction'] = "saveRegion";
if ($_REQUEST['mode'] == 'add')
{
doc_type_op::add_doctype();
}
else if($_REQUEST['mode'] == 'update')
{
doc_type_op::update_doctype();
}
}
function saveUrlAuth()
{
$results = array();
$results['errorReturnAction'] = "saveUrlAuth";
if ($_REQUEST['mode'] == 'add')
{
user_url_access::addURL();
}
else if ($_REQUEST['mode'] == 'delete')
{
user_url_access::deleteURL();
}
}
function saveMonthlyebit()
{
$results = array();
$results['errorReturnAction'] = "saveMonthlyebit";
monthlyebit_op::update_monthlyebit();
}
function checkUserAccess($uid,$type)
{
$database = new Database();
$conn = $database->getConnection();
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$qry = "select count(SA.auth_id) from sun_settings_user_auth SA,
users U
where SA.uid=$uid
and SA.auth_type='$type'
and U.uid=SA.uid
and U.status=1";
$st = $conn->prepare( $qry );
$st->execute();
$number_of_rows = $st->fetchColumn();
if($number_of_rows > 0)
{
$qry = "select count(SA.auth_id),U.uid,U.name from sun_settings_user_auth SA,
users U
where SA.uid=$uid
and SA.auth_type='$type'
and U.uid=SA.uid
and U.status=1";
$st = $conn->prepare( $qry );
$st->execute();
$row = $st->fetchAll(PDO::FETCH_ASSOC);
foreach ($row as $key => $value) {
$_SESSION['uid'] = $value["uid"];
$_SESSION['name'] = $value["name"];
}
}
return $number_of_rows;
}
//trigger_error("before calling getUsers");
//$action();
// returns true if $needle is a substring of $haystack
function contains($haystack, $needle)
{
return strpos($haystack, $needle) !== false;
}
/* function login()
{
require (TEMPLATE_PATH . "/login_form.html");
}
*/
function login_form() {
$_SESSION['conn'] = null;
$_SESSION['18K_user'] = null;
$results = array();
if ( isset( $_POST['login'] ) ) {
// User has posted the login form: attempt to log the user in
//session_id(uniqid());
//session_start();
$_SESSION['app_error'] = '';
$user_pwd = $_POST['user_pwd'];
$_SESSION['user_pwd'] = $_POST['user_pwd'];
$_SESSION['user_id'] = $_POST['user_id'];
$_SESSION['fin_year'] = $_POST['fin_year'];
$_SESSION['group_name'] = "";
$now = new DateTime('now');
$_SESSION['curr_date'] = strval($now->format('Y-m-d'));
$_SESSION['curr_month'] = intval($now->format('m'));
$_SESSION['curr_year'] = intval($now->format('Y'));
/* echo ' $_SESSION[curr_month] - ' . $_SESSION['curr_month'];
echo ' $_SESSION[curr_year] - ' . $_SESSION['curr_year'];
echo ' $_SESSION[fin_year] - ' . $_SESSION['fin_year']; */
//echo ' $_SESSION[curr_date] - ' . $_SESSION['curr_date'];
if ($user = K18_user::checkuserid( $_POST['user_id'] , $_POST['user_pwd']))
{
$_SESSION['18K_user'] = $user;
$_SESSION['session_id'] = session_id();
$_SESSION['login_status'] = 'SUCCESS';
$_SESSION['company_id'] = $user->company_id;
$_SESSION['company_seq'] = $user->company_seq;
$_SESSION['company_name'] = $user->company_name;
$_SESSION['user_id'] = $user->login_user_id;
$_SESSION['user_name'] = $user->user_name;
$_SESSION['login_user_id'] = $user->login_user_id;
$_SESSION['last_master_update_date'] = $user->last_master_update_date;
$_SESSION['company_address1'] = $user->company_address1;
$_SESSION['company_address2'] = $user->company_address2;
$_SESSION['company_city'] = $user->company_city;
$_SESSION['company_state'] = $user->company_state;
$_SESSION['company_pincode'] = $user->company_pincode;
$_SESSION['company_country'] = $user->company_country;
$_SESSION['cin_no'] = $user->cin_no;
$_SESSION['company_phone'] = $user->company_phone;
$_SESSION['company_email'] = $user->company_email;
$_SESSION['tin_no'] = $user->tin_no;
$_SESSION['cst_no'] = $user->cst_no;
$_SESSION['cst_date'] = $user->cst_date;
$_SESSION['service_tax_no'] = $user->service_tax_no;
$_SESSION['pancard_no'] = $user->pancard_no;
$_SESSION['ucwords'] = "";
$_SESSION['uid'] = $user->uid;
$_SESSION['name'] = $user->name;
$_SESSION['reporting_to'] = $user->login_user_id;
$_SESSION['reportees'] = '';
if (!isset($_SESSION['reportees']))
{
$_SESSION['reportees'] = '';
}
$_SESSION['short_designation'] = substr($_SESSION['user_id'],0,2);
$_SESSION['user_name'] = $user->user_name;
$_SESSION['user_email'] = $user->user_email;
$_SESSION['department'] = $user->department;
$_SESSION['designation'] = $user->designation;
$_SESSION['region_code'] = $user->region_code;
//$_SESSION['role'] = $user->role;
$_SESSION['reporting_to'] = $user->reporting_to;
$_SESSION['division_code'] = $user->division_code;
// The following lines were added by Kuppuram - 14-11-2017
$user_name = $_SESSION['login_user_id'];
//$all_menu_rights = $_SESSION['uar'];
//homePage();
$retresult['success'] = true;
$retresult['msg'] = "Login successful";
$_SESSION['app_error'] = $retresult['success'];
echo json_encode($retresult);
/* if ( $user->checkPassword( $_POST['user_pwd'] ) ) {
// If checkPassword is enabled, session variables should be assigned here.
}
else
{
$results['errorReturnAction'] = "login";
$results['errorMessage'] = "User Not Found or Incorrect user id or password. Please try again.";
//require( TEMPLATE_PATH . "/errorDialog.php" );
$retresult['success'] = false;
$retresult['errors'] = "User Not Found or Incorrect user id or password. Please try again.";
$_SESSION['app_error'] = $retresult['success'];
echo json_encode($retresult);
} */
}
else {
$retresult['success'] = false;
$retresult['errors'] = "User Not Found or Incorrect user id or password. Please try again.";
$_SESSION['app_error'] = $retresult['success'];
echo json_encode($retresult);
}
} else {
// User has not posted the login form yet: display the form
//echo 'Login successful - time - ' . time(); ;
require( TEMPLATE_PATH . "/login_page.php" );
//require( TEMPLATE_PATH . "/login_form.html" );
//require( "index.html" );
}
}
/* function excelOpen()
{
require( TEMPLATE_PATH . "/excelOpen.php" );
} */
function handleRequest()
{
$controller = "K18_Controller";
$controllerAction = "";
if (isset($_REQUEST['c']))
{
$controller = $_REQUEST['c'];
$controllerAction = $_REQUEST['a'];
}
$c = null;
//echo $controller . " - " . $controllerAction;
switch ($controller)
{
case "K18_Controller" :
$c = new K18_Controller();
$c->handleRequest($controllerAction);
break;
}
}
// Changes Password
// Password reset
function staticresetpwd() {
$login_user_id = isset( $_REQUEST['reset_login_user_id'] ) ? $_REQUEST['reset_login_user_id'] : "";
K18_User::staticresetpwd($login_user_id);
echo '<script>window.location="index.php?action=homePage"</script>';
//homePage();
}
function changePassword() {
$results = array();
$results['errorReturnAction'] = "changePassword";
// User has posted the password edit form
$retresult = array();
$currentPassword = isset( $_REQUEST['currentPassword'] ) ? $_REQUEST['currentPassword'] : "";
$newPassword = isset( $_REQUEST['newPassword'] ) ? $_REQUEST['newPassword'] : "";
$newPasswordConfirm = isset( $_REQUEST['newPasswordConfirm'] ) ? $_REQUEST['newPasswordConfirm'] : "";
$user = K18_User::checkuserid( $_SESSION['company_id'],$_SESSION['user_id'], $currentPassword );
if (!$user)
{
$retresult['success'] = false;
$retresult['errors'] = "18KSoftec Error: Please give correct credentials.";
K18_utility::saveError("18KSoftec Error: Please give correct credentials.");
trigger_error("18KSoftec Error: Please give correct credentials.");
/* $results['errorMessage'] = "Please give correct credentials.";
require( TEMPLATE_PATH . "/errorDialog.php" ); */
return;
}
// Do some checks
// Change Log - 2014.04.30-1
// 30-Apr-2014 - Kuppuram
// Checking for correct Current Password
if ( !$user->checkPassword( $currentPassword ) )
{
$results['errorMessage'] = "Current Password is not valid. Please try again.";
trigger_error("18KSoftec Error: Please give correct credentials.");
//require( TEMPLATE_PATH . "/errorDialog.php" );
return;
}
/* if ( $newPassword == $currentPassword ) {
$results['errorMessage'] = "Current Password and New Password cannot be the same. Please try again.";
require( TEMPLATE_PATH . "/errorDialog.php" );
return;
}
if ( !$currentPassword || !$newPassword || !$newPasswordConfirm ) {
$results['errorMessage'] = "Please fill in all the fields in the form.";
require( TEMPLATE_PATH . "/errorDialog.php" );
return;
}
if ( $newPassword != $newPasswordConfirm ) {
$results['errorMessage'] = "The two new passwords you entered didn't match. Please try again.";
require( TEMPLATE_PATH . "/errorDialog.php" );
return;
} */
// All OK: change password
$ret = $user->updatepwd($currentPassword, $newPassword );
if ($ret = 'SUCCESS')
{
$retresult['success'] = true;
$retresult['errors'] = "18KSoftec Error: Password has been changed successfully.";
//echo json_encode($retresult);
return;
}
else
{
$retresult['success'] = false;
$retresult['errors'] = "18KSoftec Error: Password change failed...Please try again...";
//echo json_encode($retresult);
return;
}
}
?>