forked from boxwise/dropapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile.php
More file actions
134 lines (109 loc) · 4.71 KB
/
mobile.php
File metadata and controls
134 lines (109 loc) · 4.71 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
<?php
error_reporting(E_ALL);
ini_set('display_errors',true);
$login = true; #tell core not to check login, because we use an alternate version
require_once('library/core.php');
date_default_timezone_set('Europe/Athens');
db_query('SET time_zone = "+02:00"');
$tpl = new Zmarty;
if($_GET['logout']!='') {
logout($settings['rootdir'].'/mobile.php');
}
checkmobilesession();
if($_POST && $_POST['action']=='login') {
require_once('mobile/login.php');
}
/* new: fill the camp selection menu -------------------------------------------- */
if($_GET['camp']) {
if($_SESSION['user']['is_admin']) {
$_SESSION['camp'] = db_row('SELECT c.* FROM camps AS c WHERE c.id = :camp',array('camp'=>$_GET['camp']));
} else {
$_SESSION['camp'] = db_row('SELECT c.* FROM camps AS c, cms_users_camps AS x WHERE c.id = x.camps_id AND c.id = :camp AND x.cms_users_id = :id',array('camp'=>$_GET['camp'], 'id'=>$_SESSION['user']['id']));
}
}
if($_SESSION['user']['is_admin']) {
$camplist = db_array('SELECT c.* FROM camps AS c');
} else {
$camplist = db_array('SELECT c.* FROM camps AS c, cms_users_camps AS x WHERE x.camps_id = c.id AND x.cms_users_id = :id',array('id'=>$_SESSION['user']['id']));
}
if(!isset($_SESSION['camp'])) $_SESSION['camp'] = $camplist[0];
$tpl->assign('camps',$camplist);
$tpl->assign('currentcamp',$_SESSION['camp']);
/* end of the camp menu addition -------------------------------------------- */
if($_GET['message']) $data['message'] = $_GET['message'];
if($_GET['warning']) $data['warning'] = true;
if(!$_SESSION['user']) {
$data['destination'] = $_SERVER['REQUEST_URI'];
$tpl->assign('include','mobile_login.tpl');
} elseif(!$_SESSION['camp']['id']) {
$data['message'] = 'You don\'t have access to this camp. Ask your coordinator to correct this!';
# $tpl->assign('include','mobile_message.tpl');
} else {
# Boxlabel is scanned
if($_GET['barcode']!='' || $_GET['boxid']!='') {
require_once('mobile/barcode.php');
# Assign a QR code to existing box
} elseif($_GET['assignbox']!='') {
require_once('mobile/assignbox.php');
# Save assignbox selection
} elseif($_GET['saveassignbox']!='') {
require_once('mobile/saveassignbox.php');
# Make a new box with this QR code
} elseif($_GET['newbox']!='') {
require_once('mobile/newbox.php');
# Edit the info for existing box
} elseif($_GET['editbox']!='') {
require_once('mobile/editbox.php');
# Save a new box with this QR code
} elseif($_GET['savebox']!='') {
require_once('mobile/savebox.php');
# Move this box to a new location
} elseif($_GET['move']!='') {
require_once('mobile/move.php');
# Change the amount of items in this box
} elseif($_GET['changeamount']!='') {
require_once('mobile/changeamount.php');
# Save the new amount of items in this box
} elseif($_GET['saveamount']!='') {
require_once('mobile/saveamount.php');
# Save the new amount of items in this box
} elseif(isset($_GET['vieworders'])) {
require_once('mobile/vieworders.php');
# Find a box by manually entered number
} elseif($_GET['findbox']!='') {
require_once('mobile/findbox.php');
} else {
require_once('mobile/start.php');
}
}
$data['favicon16'] = $settings['rootdir']. (file_exists("uploads/favicon-16x16.png") ? '/uploads/favicon-16x16.png' : '/assets/img/favicon-16x16.png');
$data['favicon32'] = $settings['rootdir']. (file_exists("uploads/favicon-32x32.png") ? '/uploads/favicon-32x32.png' : '/assets/img/favicon-32x32.png');
$data['faviconapple'] = $settings['rootdir']. (file_exists("uploads/apple-touch-icon.png") ? '/uploads/apple-touch-icon.png' : '/assets/img/apple-touch-icon.png');
$tpl->assign('data',$data);
$tpl->display('mobile.tpl');
function checkmobilesession() {
global $settings;
if(isset($_SESSION['user'])) { # a valid session exists
db_query('UPDATE '.$settings['cms_usertable'].' SET lastaction = NOW() WHERE id = :id', array('id'=>$_SESSION['user']['id']));
} else { # no valid session exists
if(isset($_COOKIE['autologin_user'])) { # a autologin cookie exists
$user = db_row('SELECT * FROM '.$settings['cms_usertable'].' WHERE email != "" AND email = :email AND pass = :pass',array('email'=>$_COOKIE['autologin_user'], 'pass'=>$_COOKIE['autologin_pass']));
if($user) {
$_SESSION['user'] = $user;
db_query('UPDATE '.$settings['cms_usertable'].' SET lastlogin = NOW(), lastaction = NOW() WHERE id = :id',array('id'=>$_SESSION['user']['id']));
}
}
}
}
function generateBoxID($length = 6, $possible = '0123456789') {
$password = "";
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
return $password;
}