diff --git a/app/email_templates/email_templates.php b/app/email_templates/email_templates.php
index 074dc6eb4d..83ae6ab439 100644
--- a/app/email_templates/email_templates.php
+++ b/app/email_templates/email_templates.php
@@ -46,6 +46,7 @@
//get posted data
if (is_array($_POST['email_templates'])) {
$action = $_POST['action'];
+ $category = $_POST['category'];
$search = $_POST['search'];
$email_templates = $_POST['email_templates'];
}
@@ -73,7 +74,7 @@
break;
}
- header('Location: email_templates.php'.($search != '' ? '?search='.urlencode($search) : null));
+ header('Location: email_templates.php?'.($search != '' ? '&search='.urlencode($search) : null).($category != '' ? '&category='.urlencode($category) : null));
exit;
}
@@ -81,12 +82,21 @@
$order_by = $_GET["order_by"];
$order = $_GET["order"];
+//add the category
+ $category = strtolower($_GET["category"]);
+ if ($category) {
+ $sql_category = "and (";
+ $sql_category .= " lower(template_category) = :category";
+ $sql_category .= ") ";
+ $parameters['category'] = $category;
+ }
+
//add the search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = " (";
$sql_search .= " lower(template_language) like :search ";
- $sql_search .= " or lower(template_category) like :search ";
+ //$sql_search .= " or lower(template_category) like :search ";
$sql_search .= " or lower(template_subcategory) like :search ";
$sql_search .= " or lower(template_subject) like :search ";
$sql_search .= " or lower(template_body) like :search ";
@@ -98,19 +108,20 @@
}
//prepare to page the results
- $sql = "select count(*) from v_email_templates ";
+ $sql = "select count(*) from v_email_templates where true ";
if ($_GET['show'] == "all" && permission_exists('email_template_all')) {
if ($sql_search != '') {
- $sql .= "where ".$sql_search;
+ $sql .= "and ".$sql_search;
}
}
else {
- $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
+ $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
if ($sql_search != '') {
$sql .= "and ".$sql_search;
}
$parameters['domain_uuid'] = $domain_uuid;
}
+ $sql .= $sql_category;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
@@ -138,6 +149,18 @@
$result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
+//get email template categories
+ $sql = "select distinct template_category from v_email_templates ";
+ $sql .= "order by template_category asc ";
+ $database = new database;
+ $rows = $database->select($sql, $parameters, 'all');
+ if (is_array($rows) && @sizeof($rows) != 0) {
+ foreach ($rows as $row) {
+ $template_categories[$row['template_category']] = ucwords(str_replace('_',' ',$row['template_category']));
+ }
+ }
+ unset($sql, $parameters);
+
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
@@ -171,6 +194,15 @@
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
}
}
+ echo "\n";
echo "";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'email_templates.php','style'=>($search == '' ? 'display: none;' : null)]);