From aa150015a52cfdf30949b6b19fdd43b6550ce067 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Tue, 16 Dec 2008 22:04:39 +0000 Subject: [PATCH] Improved Client templates. --- .../lib/classes/custom_datasource.inc.php | 46 +++ interface/web/client/client_template_edit.php | 18 +- interface/web/client/form/client.tform.php | 9 +- interface/web/client/lib/lang/en_client.lng | 2 + .../client/templates/client_edit_limits.htm | 264 +++++++++--------- interface/web/client/tools.inc.php | 4 +- interface/web/js/scrigo.js.php | 27 +- 7 files changed, 216 insertions(+), 154 deletions(-) create mode 100644 interface/lib/classes/custom_datasource.inc.php diff --git a/interface/lib/classes/custom_datasource.inc.php b/interface/lib/classes/custom_datasource.inc.php new file mode 100644 index 000000000..298e99741 --- /dev/null +++ b/interface/lib/classes/custom_datasource.inc.php @@ -0,0 +1,46 @@ +db->queryAllRecords("SELECT template_id,template_name FROM client_template WHERE template_type ='m'"); + $records_new[0] = $app->lng('Custom'); + foreach($records as $rec) { + $key = $rec['template_id']; + $records_new[$key] = $rec['template_name']; + } + return $records_new; + } + +} + +?> \ No newline at end of file diff --git a/interface/web/client/client_template_edit.php b/interface/web/client/client_template_edit.php index 7368063ec..bf2795937 100644 --- a/interface/web/client/client_template_edit.php +++ b/interface/web/client/client_template_edit.php @@ -52,13 +52,29 @@ $app->load('tform_actions'); class page_action extends tform_actions { + function onBeforeUpdate() { + global $app; + + if(isset($this->dataRecord['template_type'])) { + //* Check if the template_type has been changed + $rec = $app->db->queryOneRecord("SELECT template_type from client_template WHERE template_id = ".$this->id); + if($rec['template_type'] != $this->dataRecord['template_type']) { + //* Add a error message and switch back to old server + $app->tform->errorMessage .= $app->lng('The template type can not be changed.'); + $this->dataRecord['template_type'] = $rec['template_type']; + } + unset($rec); + } + } + + /* This function is called automatically right after the data was successful updated in the database. */ function onAfterUpdate() { global $app; - + /* * the template has changed. apply the new data to all clients */ diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php index 8be3de8a2..1124c7e09 100644 --- a/interface/web/client/form/client.tform.php +++ b/interface/web/client/form/client.tform.php @@ -301,12 +301,11 @@ $form["tabs"]['limits'] = array ( 'datatype' => 'INTEGER', 'formtype' => 'SELECT', 'default' => '1', - 'datasource' => array ( 'type' => 'SQL', - 'querystring' => "SELECT template_id,template_name FROM client_template WHERE template_type ='m'", - 'keyfield'=> 'template_id', - 'valuefield'=> 'template_name' + 'datasource' => array ( 'type' => 'CUSTOM', + 'class'=> 'custom_datasource', + 'function'=> 'master_templates' ), - 'value' => array('0' => 'custom') + 'value' => '' ), 'template_additional' => array ( 'datatype' => 'VARCHAR', diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng index 8f7661628..8d0854980 100644 --- a/interface/web/client/lib/lang/en_client.lng +++ b/interface/web/client/lib/lang/en_client.lng @@ -82,4 +82,6 @@ $wb["default_dbserver_txt"] = 'Default Database Server'; $wb["limit_database_txt"] = 'Max. number of Databases'; $wb["limit_database_error_notint"] = 'The database limit must be a number.'; $wb["username_error_regex"] = 'The Username contains invalid chracaters.'; +$wb["template_master_txt"] = 'Master'; +$wb["template_additional_txt"] = 'Addon'; ?> diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm index 5e4232b9a..ff8d6ae79 100644 --- a/interface/web/client/templates/client_edit_limits.htm +++ b/interface/web/client/templates/client_edit_limits.htm @@ -1,134 +1,130 @@ -

- -
- -
-
Client-Template - - - - -
-
Additional-Templates - - - - {tmpl_var name='template_additional_list'} - -
- - -
-
-
Limits - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - -
-
- -
+

+ +
+ +
+
Templates +
+ + +
+ + + + + + + +
+
Limits + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + +
+
+ +
diff --git a/interface/web/client/tools.inc.php b/interface/web/client/tools.inc.php index 9cbf8eb1d..d66afc16e 100644 --- a/interface/web/client/tools.inc.php +++ b/interface/web/client/tools.inc.php @@ -28,7 +28,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ function applyClientTemplates($clientId){ - global $app; + global $app,$page; /* * Get the master-template for the client */ @@ -44,7 +44,7 @@ function applyClientTemplates($clientId){ $sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId); $limits = $app->db->queryOneRecord($sql); } else { - $limits = $this->dataRecord; + $limits = $page->dataRecord; } /* diff --git a/interface/web/js/scrigo.js.php b/interface/web/js/scrigo.js.php index 8831141ea..67f885619 100644 --- a/interface/web/js/scrigo.js.php +++ b/interface/web/js/scrigo.js.php @@ -102,7 +102,8 @@ function submitForm(formname,target) { } }, failure: function(o) { - alert('Ajax Request was not successful. 1'); + var parts = o.responseText.split(':'); + alert('Ajax Request was not successful. '+parts[1]); } } @@ -411,17 +412,19 @@ function pass_contains(pass, check) { function addAdditionalTemplate(){ var tpl_add = document.getElementById('template_additional').value; - var tpl_list = document.getElementById('template_additional_list').innerHTML; - var addTemplate = document.getElementById('tpl_add_select').value.split('|',2); - var addTplId = addTemplate[0]; - var addTplText = addTemplate[1]; - var newVal = tpl_add + '/' + addTplId + '/'; - newVal = newVal.replace('//', '/'); - var newList = tpl_list + '
' + addTplText; - newList = newList.replace('

', '
'); - document.getElementById('template_additional').value = newVal; - document.getElementById('template_additional_list').innerHTML = newList; - alert('additional template ' + addTplText + ' added to customer'); + if(tpl_add != '') { + var tpl_list = document.getElementById('template_additional_list').innerHTML; + var addTemplate = document.getElementById('tpl_add_select').value.split('|',2); + var addTplId = addTemplate[0]; + var addTplText = addTemplate[1]; + var newVal = tpl_add + '/' + addTplId + '/'; + newVal = newVal.replace('//', '/'); + var newList = tpl_list + '
' + addTplText; + newList = newList.replace('

', '
'); + document.getElementById('template_additional').value = newVal; + document.getElementById('template_additional_list').innerHTML = newList; + alert('additional template ' + addTplText + ' added to customer'); + } } function delAdditionalTemplate(){ -- GitLab