Skip to content

Commit 92bea0b

Browse files
committed
Updated the remoting functions.
1 parent b92d708 commit 92bea0b

File tree

2 files changed

+91
-12
lines changed

2 files changed

+91
-12
lines changed

interface/lib/classes/remoting.inc.php

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,19 @@ public function logout($session_id)
8181
return ($app->db->affectedRows() == 1);
8282
}
8383

84+
//* Get mail domain details
85+
public function mail_domain_get($session_id, $domain_id)
86+
{
87+
if(!$this->checkPerm($session_id, 'mail_domain_get')) {
88+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
89+
return false;
90+
}
91+
$app->uses('remoting_lib');
92+
$app->remoting_lib->loadFormDef('../mail/form/mail_domain.tform.php');
93+
return $app->remoting_lib->getDataRecord($domain_id);
94+
}
8495

96+
//* Add a mail domain
8597
public function mail_domain_add($session_id, $client_id, $params)
8698
{
8799
if(!$this->checkPerm($session_id, 'mail_domain_add')) {
@@ -92,21 +104,34 @@ public function mail_domain_add($session_id, $client_id, $params)
92104
return $domain_id;
93105
}
94106

107+
//* Update a mail domain
95108
public function mail_domain_update($session_id, $client_id, $domain_id, $params)
96109
{
97110
if(!$this->checkPerm($session_id, 'mail_domain_update')) {
98111
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
99112
return false;
100113
}
101-
$domain_id = $this->updateQuery('../mail/form/mail_domain.tform.php',$client_id,$domain_id,$params);
102-
return $domain_id;
114+
$affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php',$client_id,$domain_id,$params);
115+
return $affected_rows;
116+
}
117+
118+
//* Delete a mail domain
119+
public function mail_domain_delete($session_id, $domain_id)
120+
{
121+
if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
122+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
123+
return false;
124+
}
125+
$affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php',$domain_id);
126+
return $affected_rows;
103127
}
104128

105129

106130

107131
//** private functions -----------------------------------------------------------------------------------
108132

109-
private function updateQuery($formdef_file, $client_id, $primary_id, $params)
133+
134+
private function insertQuery($formdef_file, $client_id, $params)
110135
{
111136
global $app;
112137

@@ -119,7 +144,7 @@ private function updateQuery($formdef_file, $client_id, $primary_id, $params)
119144
$app->remoting_lib->loadUserProfile($client_id);
120145

121146
//* Get the SQL query
122-
$sql = $app->remoting_lib->getSQL($params,'UPDATE',$primary_id);
147+
$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
123148
if($app->remoting_lib->errorMessage != '') {
124149
$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
125150
return false;
@@ -132,16 +157,22 @@ private function updateQuery($formdef_file, $client_id, $primary_id, $params)
132157
return false;
133158
}
134159

135-
$affected_rows = $app->db->affectedRows();
160+
$insert_id = $app->db->insertID();
136161

137-
//* TODO: Save changes to Datalog
162+
//* Save changes to Datalog
163+
if($app->remoting_lib->formDef["db_history"] == 'yes') {
164+
$new_rec = $app->remoting_lib->getDataRecord($insert_id);
165+
$app->tform->datalogSave('INSERT',$primary_id,array(),$new_rec);
166+
}
138167

139168

140169

141-
return $affected_rows;
170+
171+
return $insert_id;
142172
}
143173

144-
private function insertQuery($formdef_file, $client_id, $params)
174+
175+
private function updateQuery($formdef_file, $client_id, $primary_id, $params)
145176
{
146177
global $app;
147178

@@ -154,27 +185,63 @@ private function insertQuery($formdef_file, $client_id, $params)
154185
$app->remoting_lib->loadUserProfile($client_id);
155186

156187
//* Get the SQL query
157-
$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
188+
$sql = $app->remoting_lib->getSQL($params,'UPDATE',$primary_id);
158189
if($app->remoting_lib->errorMessage != '') {
159190
$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
160191
return false;
161192
}
162193

194+
$old_rec = $app->remoting_lib->getDataRecord($primary_id);
195+
163196
$app->db->query($sql);
164197

165198
if($app->db->errorMessage != '') {
166199
$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
167200
return false;
168201
}
169202

170-
$insert_id = $app->db->insertID();
203+
$affected_rows = $app->db->affectedRows();
171204

172-
//* TODO: Save changes to Datalog
205+
//* Save changes to Datalog
206+
if($app->remoting_lib->formDef["db_history"] == 'yes') {
207+
$new_rec = $app->remoting_lib->getDataRecord($primary_id);
208+
$app->tform->datalogSave('UPDATE',$primary_id,$old_rec,$new_rec);
209+
}
173210

174211

175212

213+
return $affected_rows;
214+
}
215+
216+
private function deleteQuery($formdef_file, $primary_id)
217+
{
218+
global $app;
176219

177-
return $insert_id;
220+
$app->uses('remoting_lib');
221+
222+
//* Load the form definition
223+
$app->remoting_lib->loadFormDef($formdef_file);
224+
225+
//* Get the SQL query
226+
$sql = $app->remoting_lib->getDeleteSQL($primary_id);
227+
228+
$app->db->query($sql);
229+
230+
if($app->db->errorMessage != '') {
231+
$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
232+
return false;
233+
}
234+
235+
$affected_rows = $app->db->affectedRows();
236+
237+
//* Save changes to Datalog
238+
if($app->remoting_lib->formDef["db_history"] == 'yes') {
239+
$rec = $app->remoting_lib->getDataRecord($primary_id);
240+
$app->tform->datalogSave('DELETE',$primary_id,$rec,array());
241+
}
242+
243+
244+
return $affected_rows;
178245
}
179246

180247

interface/lib/classes/remoting_lib.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,18 @@ function getSQL($record, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '
584584

585585
return $sql;
586586
}
587+
588+
function getDeleteSQL($primary_id) {
589+
590+
if(stristr($this->formDef['db_table'],'.')) {
591+
$escape = '';
592+
} else {
593+
$escape = '`';
594+
}
595+
596+
$sql = "DELETE FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
597+
return $sql;
598+
}
587599

588600

589601
function getDataRecord($primary_id) {

0 commit comments

Comments
 (0)