From 18ad12139f489cfc5a0721e68b2b3e6aa0175b89 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 8 Mar 2019 16:30:13 +0000 Subject: [PATCH] Implemented template add. --- WEB-INF/lib/ttTemplateHelper.class.php | 113 +++++++++++++++++++++++++ template_add.php | 4 +- 2 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 WEB-INF/lib/ttTemplateHelper.class.php diff --git a/WEB-INF/lib/ttTemplateHelper.class.php b/WEB-INF/lib/ttTemplateHelper.class.php new file mode 100644 index 00000000..e2e565a3 --- /dev/null +++ b/WEB-INF/lib/ttTemplateHelper.class.php @@ -0,0 +1,113 @@ +getGroup(); + $org_id = $user->org_id; + + $sql = "select id, name, description, content from tt_templates". + " where id = $id and group_id = $group_id and org_id = $org_id". + " and status is not null"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val) { + return $val; + } + } + return false; + } + + // delete - marks a template as deleted in tt_templates table in database. + static function delete($id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "update from tt_templates set status = null". + " where id = $id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + return true; + } + + // insert function inserts a new template into database. + static function insert($fields) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $name = $fields['name']; + $description = $fields['description']; + $content = $fields['content']; + + $sql = "insert into tt_templates (group_id, org_id, name, description, content)". + " values ($group_id, $org_id, ".$mdb2->quote($name). + ", ".$mdb2->quote($description).", ".$mdb2->quote($content).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + return true; + } + + // update function - updates a template in database. + static function update($fields) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $template_id = (int) $fields['id']; + $name = $fields['name']; + $description = $fields['description']; + $content = $fields['content']; + + $sql = "update tt_templates set name = ".$mdb2->quote($name). + ", description = ".$mdb2->quote($description). + ", content = ".$mdb2->quote($content). + " where id = $template_id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } +} diff --git a/template_add.php b/template_add.php index 4fed72d5..6fb0238e 100644 --- a/template_add.php +++ b/template_add.php @@ -28,7 +28,7 @@ require_once('initialize.php'); import('form.Form'); -// import('ttTemplateHelper'); +import('ttTemplateHelper'); // Access checks. if (!ttAccessAllowed('manage_advanced_settings')) { @@ -64,7 +64,7 @@ if ($request->isPost()) { if (ttTemplateHelper::insert(array( 'name' => $cl_name, 'description' => $cl_description, - 'coontent' => $cl_content))) { + 'content' => $cl_content))) { header('Location: templates.php'); exit(); } else -- 2.20.1