Work in progress on template edit.
authorNik Okuntseff <support@anuko.com>
Fri, 8 Mar 2019 17:54:42 +0000 (17:54 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 8 Mar 2019 17:54:42 +0000 (17:54 +0000)
WEB-INF/templates/template_edit.tpl [new file with mode: 0644]
template_edit.php [new file with mode: 0644]

diff --git a/WEB-INF/templates/template_edit.tpl b/WEB-INF/templates/template_edit.tpl
new file mode 100644 (file)
index 0000000..6f3e406
--- /dev/null
@@ -0,0 +1,34 @@
+{$forms.templateForm.open}
+<table cellspacing="4" cellpadding="7" border="0">
+  <tr>
+    <td>
+      <table cellspacing="1" cellpadding="2" border="0">
+        <tr>
+          <td align="right">{$i18n.label.thing_name} (*):</td>
+          <td>{$forms.templateForm.name.control}</td>
+        </tr>
+        <tr>
+          <td align="right">{$i18n.label.description}:</td>
+          <td>{$forms.templateForm.description.control}</td>
+        </tr>
+        <tr>
+          <td align="right">{$i18n.label.template} (*):</td>
+          <td>{$forms.templateForm.content.control}</td>
+        </tr>
+        <tr>
+          <td align = "right">{$i18n.label.status}:</td>
+          <td>{$forms.templateForm.status.control}</td>
+        </tr>
+        <tr>
+          <td height="40"></td>
+          <td>{$i18n.label.required_fields}</td>
+        </tr>
+        <tr><td>&nbsp;</td></tr>
+        <tr>
+          <td colspan="2" align="center" height="50">{$forms.templateForm.btn_submit.control}</td>
+        </tr>
+      </table>
+    </td>
+  </tr>
+</table>
+{$forms.templateForm.close}
diff --git a/template_edit.php b/template_edit.php
new file mode 100644 (file)
index 0000000..90e5f56
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// |    notice or license removed or altered. (Distributing in compiled
+// |    forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// |    that bears insufficient indications that the modifications are
+// |    not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
+
+require_once('initialize.php');
+import('form.Form');
+import('ttTemplateHelper');
+
+// Access checks.
+if (!ttAccessAllowed('manage_advanced_settings')) {
+  header('Location: access_denied.php');
+  exit();
+}
+if (!$user->isPluginEnabled('tp')) {
+  header('Location: feature_disabled.php');
+  exit();
+}
+$cl_template_id = (int) $request->getParameter('id');
+$template = ttTemplateHelper::get($cl_template_id);
+if (!$template) {
+  header('Location: access_denied.php');
+  exit();
+}
+// End of access checks.
+
+if ($request->isPost()) {
+  $cl_name = trim($request->getParameter('name'));
+  $cl_description = trim($request->getParameter('description'));
+  $cl_content = trim($request->getParameter('content'));
+  $cl_status = $request->getParameter('status');
+} else {
+  $cl_name = $template['name'];
+  $cl_description = $template['description'];
+  $cl_content = $template['content'];
+  $cl_status = $template['status'];
+}
+
+$form = new Form('templateForm');
+$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_template_id));
+$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','style'=>'width: 250px;','value'=>$cl_name));
+$form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
+$form->addInput(array('type'=>'textarea','name'=>'content','style'=>'width: 250px; height: 80px;','value'=>$cl_content));
+$form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status,
+  'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive'))));
+$form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
+
+if ($request->isPost()) {
+  // Validate user input.
+  if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
+  if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
+  if (!ttValidString($cl_content)) $err->add($i18n->get('error.field'), $i18n->get('label.template'));
+  // Finished validating user input.
+
+  if ($err->no()) {
+    if (ttTemplateHelper::update(array(
+        'id' => $cl_template_id,
+        'name' => $cl_name,
+        'description' => $cl_description,
+        'content' => $cl_content,
+        'status' => $cl_status))) {
+        header('Location: templates.php');
+        exit();
+      } else
+        $err->add($i18n->get('error.db'));
+  }
+} // isPost
+
+$smarty->assign('forms', array($form->getName()=>$form->toArray()));
+$smarty->assign('title', $i18n->get('title.edit_template'));
+$smarty->assign('content_page_name', 'template_edit.tpl');
+$smarty->display('index.tpl');