Call Block: List view updates.

This commit is contained in:
Nate 2019-10-19 19:14:34 -06:00
parent 32b2be71ef
commit e29c4df126
4 changed files with 390 additions and 66 deletions

View File

@ -106,5 +106,9 @@
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "block_call_enabled";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enable/disable blocking the call.";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'call_block_description';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the description.';
?>
?>

View File

@ -28,9 +28,10 @@
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
require_once "resources/check_auth.php";
if (!permission_exists('call_block_view')) {
echo "access denied"; exit;
}
@ -39,27 +40,74 @@
$language = new text;
$text = $language->get();
//additional includes
require_once "resources/header.php";
require_once "resources/paging.php";
//get posted data
if (is_array($_POST['call_blocks'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$call_blocks = $_POST['call_blocks'];
}
//copy the call blocks
if (permission_exists('call_block_add')) {
if ($action == 'copy' && is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//copy
$obj = new call_block;
$obj->copy($call_blocks);
//redirect
header('Location: call_block.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//toggle the call blocks
if (permission_exists('call_block_edit')) {
if ($action == 'toggle' && is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//toggle
$obj = new call_block;
$obj->toggle($call_blocks);
//redirect
header('Location: call_block.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//delete the call blocks
if (permission_exists('call_block_delete')) {
if ($action == 'delete' && is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//delete
$obj = new call_block;
$obj->delete($call_blocks);
//redirect
header('Location: call_block.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//get variables used to control the order
$order_by = $_GET["order_by"] != '' ? $_GET["order_by"] : 'call_block_number';
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//show the content
echo "<b>".$text['title-call-block']."</b>\n";
echo "<br /><br />\n";
echo $text['description-call-block']."\n";
echo "<br /><br />\n";
//add the search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = " (";
$sql_search .= " lower(call_block_name) like :search ";
$sql_search .= " or lower(call_block_number) like :search ";
$sql_search .= " or lower(call_block_description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//prepare to page the results
$sql = "select count(*) from v_call_block ";
$sql .= "where domain_uuid = :domain_uuid ";
if (isset($sql_search)) {
$sql .= "and ".$sql_search;
}
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
unset($parameters);
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
@ -67,85 +115,130 @@
$page = $_GET['page'];
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_mini, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//get the list
$sql = "select * from v_call_block ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= order_by($order_by, $order);
//get the list
$sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order, 'call_block_number');
$sql .= limit_offset($rows_per_page, $offset);
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$result = $database->select($sql, $parameters, 'all');
unset($parameters);
unset($sql, $parameters);
//table headers
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include the header
require_once "resources/header.php";
//show the content
echo "<div class='action_bar' id='action_bar'>\n";
echo " <b style='float: left;'>".$text['title-call-block']." (".$num_rows.")</b>\n";
if (permission_exists('call_block_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'call_block_edit.php']);
}
if (permission_exists('call_block_add')) {
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('call_block_edit')) {
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('call_block_delete')) {
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; }"]);
}
/*
if (permission_exists('bridge_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
}
}
*/
echo "<form id='form_search' class='inline' method='get'>\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 button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'call_block.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo "</form>\n";
echo "</div>\n";
echo $text['description-call-block']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' value='' onclick='list_all_toggle();'>\n";
echo " </th>\n";
echo th_order_by('call_block_number', $text['label-number'], $order_by, $order);
echo th_order_by('call_block_name', $text['label-name'], $order_by, $order);
echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "style='text-align: center;'");
echo th_order_by('date_added', $text['label-date-added'], $order_by, $order);
echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "class='center'");
echo th_order_by('call_block_action', $text['label-action'], $order_by, $order);
echo th_order_by('call_block_enabled', $text['label-enabled'], $order_by, $order);
echo "<td class='list_control_icons'>";
if (permission_exists('call_block_add')) {
echo "<a href='call_block_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
echo th_order_by('call_block_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('date_added', $text['label-date-added'], $order_by, $order);
echo " <th>".$text['label-description']."</th>\n";
if (permission_exists('call_block_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</td>\n";
echo "</tr>\n";
//show the results
if (is_array($result)) {
$x = 0;
foreach($result as $row) {
$tr_link = (permission_exists('call_block_edit')) ? "href='call_block_edit.php?id=".escape($row['call_block_uuid'])."'" : null;
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]."'>";
if (permission_exists('call_block_edit')) {
echo "<a ".$tr_link."'>".escape($row['call_block_number'])."</a>";
$list_row_url = "call_block_edit.php?id=".escape($row['call_block_uuid']);
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='call_blocks[".$x."][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='call_blocks[".$x."][call_block_uuid]' value='".escape($row['call_block_uuid'])."' />\n";
echo " </td>\n";
echo " <td>";
if (permission_exists('call_block_edit')) {
echo "<a href='".$list_row_url."'>".escape($row['call_block_number'])."</a>";
}
else {
echo escape($row['call_block_number']);
}
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['call_block_name'])."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: center;'>".escape($row['call_block_count'])."</td>\n";
if (defined('TIME_24HR') && TIME_24HR == 1) {
$tmp_date_added = date("j M Y H:i:s", $row['date_added']);
} else {
$tmp_date_added = date("j M Y h:i:sa", $row['date_added']);
echo " <td>".escape($row['call_block_name'])."</td>\n";
echo " <td class='center'>".escape($row['call_block_count'])."</td>\n";
echo " <td>".escape($row['call_block_action'])."</td>\n";
echo " <td class='no-link center'>";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['call_block_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
echo " </td>\n";
echo " <td>".date("j M Y H:i:s".(defined('TIME_24HR') && TIME_24HR == 1 ? 'a' : null), $row['date_added'])."</td>\n";
echo " <td class='description overflow'>".escape($row['call_block_description'])."</td>\n";
if (permission_exists('call_block_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 " <td valign='top' class='".$row_style[$c]."'>".$tmp_date_added."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['call_block_action'])."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$text['label-'.escape($row['call_block_enabled'])]."</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('call_block_edit')) {
echo "<a href='call_block_edit.php?id=".escape($row['call_block_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
}
if (permission_exists('call_block_delete')) {
echo "<a href='call_block_delete.php?id=".escape($row['call_block_uuid'])."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
};
echo " </td>";
echo "</tr>\n";
$c = $c == 1 ? 0 : 1;
} //end foreach
unset($sql, $result, $row_count);
} //end if results
//complete the content
echo "</table>\n";
if (permission_exists('call_block_add')) {
echo "<div style='float: right;'>\n";
echo " <a href='call_block_edit.php' alt=\"".$text['button-add']."\">".$v_link_label_add."</a>";
echo "</div>\n";
$x++;
}
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 "</form>\n";
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@ -81,6 +81,7 @@
$call_block_number = $_POST["call_block_number"];
$call_block_action = $_POST["call_block_action"];
$call_block_enabled = $_POST["call_block_enabled"];
$call_block_description = $_POST["call_block_description"];
}
//handle the http post
@ -157,6 +158,7 @@
$array['call_block'][0]['call_block_action'] = $call_block_action;
$array['call_block'][0]['call_block_enabled'] = $call_block_enabled;
$array['call_block'][0]['date_added'] = time();
$array['call_block'][0]['call_block_description'] = $call_block_description;
$database = new database;
$database->app_name = 'call_block';
@ -197,6 +199,7 @@
$array['call_block'][0]['call_block_action'] = $call_block_action;
$array['call_block'][0]['call_block_enabled'] = $call_block_enabled;
$array['call_block'][0]['date_added'] = time();
$array['call_block'][0]['call_block_description'] = $call_block_description;
$database = new database;
$database->app_name = 'call_block';
@ -228,8 +231,8 @@
$call_block_name = $row["call_block_name"];
$call_block_number = $row["call_block_number"];
$call_block_action = $row["call_block_action"];
$blocked_call_destination = $row["blocked_call_destination"];
$call_block_enabled = $row["call_block_enabled"];
$call_block_description = $row["call_block_description"];
}
unset($sql, $parameters, $row);
}
@ -352,6 +355,17 @@
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='call_block_description' maxlength='255' value=\"".escape($call_block_description)."\">\n";
echo "<br />\n";
echo $text['description-description']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
if ($action == "update") {

View File

@ -0,0 +1,213 @@
<?php
/**
* call block class
*
* @method null download
*/
if (!class_exists('call_block')) {
class call_block {
/**
* Called when the object is created
*/
public function __construct() {
}
/**
* Called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
/**
* delete call block
*/
public function delete($call_blocks) {
if (permission_exists('call_block_delete')) {
//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: call_block.php');
exit;
}
//delete multiple call blocks
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//build the delete array
foreach($call_blocks as $x => $row) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) {
$array['call_block'][$x]['call_block_uuid'] = $row['call_block_uuid'];
$array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
}
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->delete($array);
unset($array);
//set message
message::add($text['message-delete']);
}
unset($call_blocks);
}
}
}
/**
* toggle call block
*/
public function toggle($call_blocks) {
if (permission_exists('call_block_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: call_block.php');
exit;
}
//toggle the checked call blocks
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//get current enabled state of checked call block
foreach($call_blocks as $x => $row) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) {
$call_block_uuids[] = "call_block_uuid = '".$row['call_block_uuid']."'";
}
}
if (is_array($call_block_uuids) && @sizeof($call_block_uuids) != 0) {
$sql = "select call_block_uuid, call_block_enabled from v_call_block ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $call_block_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) {
$call_block_states[$row['call_block_uuid']] = $row['call_block_enabled'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach($call_block_states as $call_block_uuid => $call_block_state) {
$array['call_block'][$x]['call_block_uuid'] = $call_block_uuid;
$array['call_block'][$x]['call_block_enabled'] = $call_block_state == 'true' ? 'false' : 'true';
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($call_blocks, $call_block_states);
}
}
}
/**
* copy call blocks
*/
public function copy($call_blocks) {
if (permission_exists('call_block_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: call_block.php');
exit;
}
//copy the checked call blocks
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//get checked call blocks
foreach($call_blocks as $x => $row) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) {
$call_block_uuids[] = "call_block_uuid = '".$row['call_block_uuid']."'";
}
}
//create insert array from existing data
if (is_array($call_block_uuids) && @sizeof($call_block_uuids) != 0) {
$sql = "select * from v_call_block ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $call_block_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) {
$array['call_block'][$x]['call_block_uuid'] = uuid();
$array['call_block'][$x]['domain_uuid'] = $row['domain_uuid'];
$array['call_block'][$x]['call_block_name'] = $row['call_block_name'];
$array['call_block'][$x]['call_block_number'] = $row['call_block_number'];
$array['call_block'][$x]['call_block_count'] = 0;
$array['call_block'][$x]['call_block_action'] = $row['call_block_action'];
$array['call_block'][$x]['date_added'] = $row['date_added'];
$array['call_block'][$x]['call_block_enabled'] = $row['call_block_enabled'];
$array['call_block'][$x]['call_block_description'] = trim($row['call_block_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 = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->save($array);
unset($array);
//set message
message::add($text['message-copy']);
}
unset($call_blocks);
}
}
}
}
}
/*
$obj = new call_block;
$obj->delete();
*/
?>