-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmobjdbop.php
114 lines (102 loc) · 2.52 KB
/
mmobjdbop.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
<?php // mmobjdbop.php
require_once 'mmsession.php';
use mondrakeNG\mm\classes\MMUser;
use mondrakeNG\mm\classes\MMUserLogin;
require_once 'mmexchdl.php';
if (isset($_SESSION['mmToken'])) {
$ulo = new MMUserLogin;
$ulo->readToken($_SESSION['mmToken']);
$user = new MMUSer;
$user->read($ulo->user_id);
$currEnvId = $user->currentEnvironmentId;
$currEnvDesc = isset($user->currentEnvironment->description) ? $user->currentEnvironment->description : NULL;
$user->setSessionContext(array( 'user' => $ulo->user_id,
'environment' => $ulo->environment_id,
'client' => $ulo->client_id,));
}
else {
header("Location: index.php"); die;
}
if (!isset($_POST['obj']))
die("Missing parameter.");
$objName = $_POST['obj'];
$obj = new $objName;
// delete object
if($_POST['mmaction'] == 'Del') {
$primaryKey = $_POST['primaryKey'];
$obj->read(base64_decode($primaryKey));
$ret = $obj->delete();
header("Location: $_POST[referer]");
die;
}
$colDets = $obj->getColumnProperties();
// add object
if($_POST['mmaction'] == 'Add') {
foreach ($colDets as $a => $b) {
switch ($b['type']) {
case 'boolean':
$obj->$a = $_POST[$a];
if (is_null($obj->$a) or $obj->$a == 0)
$obj->$a = 0;
else
$obj->$a = 1;
break;
default:
if (isset($_POST[$a]) ) {
$obj->$a = stripslashes($_POST[$a]);
}
}
}
// try {
$ret = $obj->create();
header("Location: $_POST[referer]");
die;
/* }
catch(Exception $e){
$errMsg = $e->getCode() . ' - ' . $e->getMessage();
$obj = new MMUser;
foreach ($obj->getLog() as $msg) {
$errMsg .= "<br/>$msg->text";
}
echo "Err: $errMsg";
die;
}*/
}
if (!isset($_POST['obj']) or !isset($_POST['primaryKey']))
die("<br /><br />Missing parameter.");
else {
$primaryKey = $_POST['primaryKey'];
$obj->read(base64_decode($primaryKey));
foreach ($colDets as $a => $b) {
switch ($b['type']) {
case 'boolean':
$obj->$a = $_POST[$a];
if (is_null($obj->$a) or $obj->$a == 0)
$obj->$a = 0;
else
$obj->$a = 1;
break;
default:
if (isset($_POST[$a]) ) {
$obj->$a = stripslashes($_POST[$a]);
}
}
}
// try {
$ret = $obj->update();
header("Location: $_POST[referer]");
die;
/* }
catch(Exception $e){
$errMsg = 'Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage(). '<br/><br/>';
echo $errMsg;
$obj = new MMUser;
foreach ($obj->getLog() as $msg) {
echo "$msg->className - $msg->severity - [$msg->id] - $msg->fullText <br/>";
}
echo '<br/><br/>';
$trace = $e->getTrace();
print_r($trace);
die;
}*/
}