Email Templates: List view updates.

This commit is contained in:
Nate 2019-11-18 09:22:59 -07:00
parent 399627d995
commit f2f1d9069f
3 changed files with 373 additions and 165 deletions

View File

@ -41,7 +41,7 @@
$text['title-email_template']['sv-se'] = ''; $text['title-email_template']['sv-se'] = '';
$text['title-email_template']['uk-ua'] = ''; $text['title-email_template']['uk-ua'] = '';
$text['title_description-email_template']['en-us'] = ''; $text['title_description-email_template']['en-us'] = 'Define and manage dynamic templates used for system generated outbound emails.';
$text['title_description-email_template']['ar-eg'] = ''; $text['title_description-email_template']['ar-eg'] = '';
$text['title_description-email_template']['de-at'] = ''; $text['title_description-email_template']['de-at'] = '';
$text['title_description-email_template']['de-ch'] = ''; $text['title_description-email_template']['de-ch'] = '';

View File

@ -24,9 +24,10 @@
//includes //includes
require_once "root.php"; require_once "root.php";
require_once "resources/require.php"; require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions //check permissions
require_once "resources/check_auth.php";
if (permission_exists('email_template_view')) { if (permission_exists('email_template_view')) {
//access granted //access granted
} }
@ -39,26 +40,45 @@
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//get the action //get posted data
if (is_array($_POST["email_templates"])) { if (is_array($_POST['email_templates'])) {
$email_templates = $_POST["email_templates"]; $action = $_POST['action'];
foreach($email_templates as $row) { $search = $_POST['search'];
if ($row['action'] == 'delete') { $email_templates = $_POST['email_templates'];
$action = 'delete'; }
break;
} //copy the email_templates
if (permission_exists('email_template_add')) {
if ($action == 'copy' && is_array($email_templates) && @sizeof($email_templates) != 0) {
//copy
$obj = new email_templates;
$obj->copy($email_templates);
//redirect
header('Location: email_templates.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//toggle the email_templates
if (permission_exists('email_template_edit')) {
if ($action == 'toggle' && is_array($email_templates) && @sizeof($email_templates) != 0) {
//toggle
$obj = new email_templates;
$obj->toggle($email_templates);
//redirect
header('Location: email_templates.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
} }
} }
//delete the email_templates //delete the email_templates
if (permission_exists('email_template_delete')) { if (permission_exists('email_template_delete')) {
if ($action == "delete") { if ($action == 'delete' && is_array($email_templates) && @sizeof($email_templates) != 0) {
//download //delete
$obj = new email_templates; $obj = new email_templates;
$obj->delete($email_templates); $obj->delete($email_templates);
//redirect //redirect
message::add($text['message-delete']); header('Location: email_templates.php'.($search != '' ? '?search='.urlencode($search) : null));
header('Location: '.$_SERVER['PHP_SELF']);
exit; exit;
} }
} }
@ -74,8 +94,8 @@
$sql_search .= " lower(template_language) like :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_subcategory) like :search ";
//$sql_search .= " or lower(template_subject) like :search "; $sql_search .= " or lower(template_subject) like :search ";
//$sql_search .= " or lower(template_body) like :search "; $sql_search .= " or lower(template_body) like :search ";
$sql_search .= " or lower(template_type) like :search "; $sql_search .= " or lower(template_type) like :search ";
$sql_search .= " or lower(template_enabled) like :search "; $sql_search .= " or lower(template_enabled) like :search ";
$sql_search .= " or lower(template_description) like :search "; $sql_search .= " or lower(template_description) like :search ";
@ -83,10 +103,6 @@
$parameters['search'] = '%'.$search.'%'; $parameters['search'] = '%'.$search.'%';
} }
//additional includes
require_once "resources/header.php";
require_once "resources/paging.php";
//prepare to page the results //prepare to page the results
$sql = "select count(*) from v_email_templates "; $sql = "select count(*) from v_email_templates ";
if ($_GET['show'] == "all" && permission_exists('email_template_all')) { if ($_GET['show'] == "all" && permission_exists('email_template_all')) {
@ -106,156 +122,164 @@
//prepare to page the results //prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = ""; $param = "&search=".$search;
$page = $_GET['page']; $page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page; $offset = $rows_per_page * $page;
//get the list //get the list
$sql = str_replace('count(*)', '*', $sql); $sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order, 'template_language', 'asc'); if ($order_by) {
$sql .= order_by($order_by, $order);
}
else {
$sql .= "order by domain_uuid, template_language asc, template_category asc, template_subcategory asc, template_type asc, template_description asc ";
}
$sql .= limit_offset($rows_per_page, $offset); $sql .= limit_offset($rows_per_page, $offset);
$database = new database; $database = new database;
$result = $database->select($sql, $parameters, 'all'); $result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters); unset($sql, $parameters);
//alternate the row style //create token
$c = 0; $object = new token;
$row_style["0"] = "row_style0"; $token = $object->create($_SERVER['PHP_SELF']);
$row_style["1"] = "row_style1";
//define the checkbox_toggle function //additional includes
echo "<script type=\"text/javascript\">\n"; require_once "resources/header.php";
echo " function checkbox_toggle(item) {\n";
echo " var inputs = document.getElementsByTagName(\"input\");\n";
echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
echo " if (inputs[i].type === 'checkbox') {\n";
echo " if (document.getElementById('checkbox_all').checked == true) {\n";
echo " inputs[i].checked = true;\n";
echo " }\n";
echo " else {\n";
echo " inputs[i].checked = false;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//show the content //show the content
echo "<table width='100%' border='0'>\n"; echo "<div class='action_bar' id='action_bar'>\n";
echo " <tr>\n"; echo " <div class='heading'><b>".$text['title-email_templates']." (".$num_rows.")</b></div>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-email_templates']."</b></td>\n"; echo " <div class='actions'>\n";
echo " <form method='get' action=''>\n"; if (permission_exists('email_template_add')) {
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n"; echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'email_template_edit.php']);
}
if (permission_exists('email_template_add') && $result) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
if (permission_exists('email_template_edit') && $result) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
if (permission_exists('email_template_delete') && $result) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('email_template_all')) { if (permission_exists('email_template_all')) {
if ($_GET['show'] == 'all') { if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>"; echo " <input type='hidden' name='show' value='all'>";
} }
else { else {
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='email_templates.php?show=all';\">\n"; echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
} }
} }
echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".escape($search)."'>\n"; echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n"; echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo " </td>\n"; 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)]);
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo " </form>\n"; echo " </form>\n";
echo " </tr>\n"; echo " </div>\n";
echo "</table>\n"; echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<form method='post' action=''>\n"; echo $text['title_description-email_template']."\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n"; echo "<br /><br />\n";
echo "<tr>\n";
echo " <th style='width:30px;'>\n"; echo "<form id='form_list' method='post'>\n";
echo " <input type='checkbox' name='checkbox_all' id='checkbox_all' value='' onclick=\"checkbox_toggle();\">\n"; echo "<input type='hidden' id='action' name='action' value=''>\n";
echo " </th>\n"; echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('email_template_add') || permission_exists('email_template_edit') || permission_exists('email_template_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($result ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
if ($_GET['show'] == "all" && permission_exists('email_template_all')) { if ($_GET['show'] == "all" && permission_exists('email_template_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, '', '', $param); echo "<th>".$text['label-domain']."</th>\n";
//echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param);
} }
echo th_order_by('template_language', $text['label-template_language'], $order_by, $order); echo th_order_by('template_language', $text['label-template_language'], $order_by, $order, null, "class='shrink'", $param);
echo th_order_by('template_category', $text['label-template_category'], $order_by, $order); echo th_order_by('template_category', $text['label-template_category'], $order_by, $order, null, "class='shrink' style='min-width: 15%'", $param);
echo th_order_by('template_subcategory', $text['label-template_subcategory'], $order_by, $order); echo th_order_by('template_subcategory', $text['label-template_subcategory'], $order_by, $order, null, "class='shrink' style='min-width: 15%'", $param);
//echo th_order_by('domain_uuid', $text['label-domain_uuid'], $order_by, $order); echo th_order_by('template_subject', $text['label-template_subject'], $order_by, $order, null, "class='hide-sm-dn' style='min-width: 20%'", $param);
echo th_order_by('template_type', $text['label-template_type'], $order_by, $order); echo th_order_by('template_type', $text['label-template_type'], $order_by, $order, null, "class='shrink'", $param);
echo th_order_by('template_enabled', $text['label-template_enabled'], $order_by, $order); echo th_order_by('template_enabled', $text['label-template_enabled'], $order_by, $order, null, "class='center' style='min-width: 15%'", $param);
echo th_order_by('template_description', $text['label-template_description'], $order_by, $order); echo th_order_by('template_description', $text['label-template_description'], $order_by, $order, null, "class='hide-sm-dn'", $param);
echo " <td class='list_control_icons'>"; if (permission_exists('email_template_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
if (permission_exists('email_template_add')) { echo " <td class='action-button'>&nbsp;</td>\n";
echo " <a href='email_template_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
} }
else { echo "</tr>\n";
echo "&nbsp;\n";
}
echo " </td>\n";
echo "<tr>\n";
if (is_array($result) && @sizeof($result) != 0) { if (is_array($result) && @sizeof($result) != 0) {
$x = 0; $x = 0;
foreach($result as $row) { foreach($result as $row) {
if (permission_exists('email_template_edit')) { if (permission_exists('email_template_edit')) {
$tr_link = "href='email_template_edit.php?id=".escape($row['email_template_uuid'])."'"; $list_row_url = "email_template_edit.php?id=".urlencode($row['email_template_uuid']);
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('email_template_add') || permission_exists('email_template_edit') || permission_exists('email_template_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='email_templates[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='email_templates[$x][uuid]' value='".escape($row['email_template_uuid'])."' />\n";
echo " </td>\n";
} }
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='align: center; padding: 3px 3px 0px 8px;'>\n";
echo " <input type='checkbox' name=\"email_templates[$x][checked]\" id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('chk_all_".$x."').checked = false; }\">\n";
echo " <input type='hidden' name=\"email_templates[$x][email_template_uuid]\" value='".escape($row['email_template_uuid'])."' />\n";
echo " </td>\n";
if ($_GET['show'] == "all" && permission_exists('email_template_all')) { if ($_GET['show'] == "all" && permission_exists('email_template_all')) {
if (strlen($_SESSION['domains'][$row['domain_uuid']]['domain_name']) > 0) { echo " <td>";
$domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name']; if (is_uuid($row['domain_uuid'])) {
echo escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']);
} }
else { else {
$domain = $text['label-global']; echo $text['label-global'];
} }
echo " <td valign='top' class='".$row_style[$c]."'>".escape($domain)."</td>\n"; echo "</td>\n";
} }
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_language'])."&nbsp;</td>\n"; echo " <td>".escape($row['template_language'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_category'])."&nbsp;</td>\n"; echo " <td>".escape($row['template_category'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_subcategory'])."&nbsp;</td>\n"; echo " <td>".escape($row['template_subcategory'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_subject'])."&nbsp;</td>\n"; echo " <td class='overflow hide-sm-dn'>";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_body'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['domain_uuid'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_type'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['template_enabled'])."&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg'>".escape($row['template_description'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('email_template_edit')) { if (permission_exists('email_template_edit')) {
echo "<a href='email_template_edit.php?id=".escape($row['email_template_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>"; echo "<a href='".$list_row_url."'>".escape($row['template_subject'])."</a>";
} }
if (permission_exists('email_template_delete')) { else {
echo "<button type='submit' class='btn btn-default list_control_icon' name=\"email_templates[$x][action]\" alt='".$text['button-delete']."' value='delete'><span class='fas fa-minus'></span></button>"; echo escape($row['template_subject']);
} }
echo " </td>\n"; echo " </td>\n";
echo " <td>".escape($row['template_type'])."&nbsp;</td>\n";
if (permission_exists('email_template_edit')) {
echo " <td class='no-link center'>";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['template_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
}
else {
echo " <td class='center'>";
echo $text['label-'.$row['template_enabled']];
}
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['template_description'])."</td>\n";
if (permission_exists('email_template_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n"; echo "</tr>\n";
$x++; $x++;
if ($c==0) { $c=1; } else { $c=0; }
} }
} }
unset($result, $row); unset($result);
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "<tr>\n";
echo "<td colspan='8' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('email_template_add')) {
echo "<a href='email_template_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
else {
echo "&nbsp;";
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</form>\n"; echo "</form>\n";
echo "<br /><br />";
//include the footer //include the footer
require_once "resources/footer.php"; require_once "resources/footer.php";
?> ?>

View File

@ -1,30 +1,64 @@
<?php <?php
/*
FusionPBX
Version: MPL 1.1
/** The contents of this file are subject to the Mozilla Public License Version
* call_recordings class 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* @method null download http://www.mozilla.org/MPL/
*/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2019
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//define the email templates class
if (!class_exists('email_templates')) { if (!class_exists('email_templates')) {
class email_templates { class email_templates {
public $db; /**
* declare private variables
*/
private $app_name;
private $app_uuid;
private $permission_prefix;
private $list_page;
private $table;
private $uuid_prefix;
private $toggle_field;
private $toggle_values;
/** /**
* Called when the object is created * called when the object is created
*/ */
public function __construct() { public function __construct() {
//connect to the database if not connected
if (!$this->db) { //assign private variables
require_once "resources/classes/database.php"; $this->app_name = 'email_templates';
$database = new database; $this->app_uuid = '8173e738-2523-46d5-8943-13883befd2fd';
$database->connect(); $this->permission_prefix = 'email_template_';
$this->db = $database->db; $this->list_page = 'email_templates.php';
} $this->table = 'email_templates';
$this->uuid_prefix = 'email_template_';
$this->toggle_field = 'template_enabled';
$this->toggle_values = ['true','false'];
} }
/** /**
* Called when there are no references to a particular object * called when there are no references to a particular object
* unset the variables used in the class * unset the variables used in the class
*/ */
public function __destruct() { public function __destruct() {
@ -34,42 +68,192 @@ if (!class_exists('email_templates')) {
} }
/** /**
* delete email_templates * delete records
*/ */
public function delete($email_templates) { public function delete($records) {
if (permission_exists('email_template_delete')) { if (permission_exists($this->permission_prefix.'delete')) {
//delete multiple email_templates //add multi-lingual support
if (is_array($email_templates)) { $language = new text;
//get the action $text = $language->get();
foreach($email_templates as $row) {
if ($row['action'] == 'delete') { //validate the token
$action = 'delete'; $token = new token;
break; if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
} }
} }
//delete the checked rows //delete the checked rows
if ($action == 'delete') { if (is_array($array) && @sizeof($array) != 0) {
foreach($email_templates as $row) {
if ($row['checked'] == 'true') { //execute delete
$sql = "delete from v_email_templates "; $database = new database;
$sql .= "where email_template_uuid = '".$row['email_template_uuid']."'; "; $database->app_name = $this->app_name;
$this->db->query($sql); $database->app_uuid = $this->app_uuid;
unset($sql); $database->delete($array);
} unset($array);
}
unset($email_templates); //set message
message::add($text['message-delete']);
} }
unset($records);
} }
} }
} //end the delete function }
} //end the class /**
* toggle records
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix.'edit')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
}
/**
* copy records
*/
public function copy($records) {
if (permission_exists($this->permission_prefix.'add')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//copy the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get checked records
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
//create insert array from existing data
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select * from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) {
//copy data
$array[$this->table][$x] = $row;
//overwrite
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
$array[$this->table][$x]['template_description'] = trim($row['template_description'].' ('.$text['label-copy'].')');
}
}
unset($sql, $parameters, $rows, $row);
}
//save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-copy']);
}
unset($records);
}
}
}
}
} }
/* ?>
$obj = new email_templates;
$obj->delete();
*/
?>