From 306606f7c6f327b9798df94659e6cac37eca7817 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 11 Jan 2020 19:06:34 -0700 Subject: [PATCH] Call Block: Action bar, list view and button updates, bulk add (with class) from CDR, etc. --- app/call_block/app_languages.php | 46 ++- app/call_block/call_block.php | 28 +- app/call_block/call_block_edit.php | 312 ++++++++++-------- .../resources/classes/call_block.php | 133 +++++++- 4 files changed, 358 insertions(+), 161 deletions(-) diff --git a/app/call_block/app_languages.php b/app/call_block/app_languages.php index edc9c93ec5..b3d2972834 100644 --- a/app/call_block/app_languages.php +++ b/app/call_block/app_languages.php @@ -673,4 +673,48 @@ $text['description-action']['ru-ru'] = "Установите действие д $text['description-action']['sv-se'] = "Välj en aktion för samtal från detta nummer."; $text['description-action']['uk-ua'] = "Встановіть дію для дзвінків з цього номера."; -?> +$text['confirm-block']['en-us'] = "Do you really want to block this?"; +$text['confirm-block']['ar-eg'] = "Do you really want to block this?"; +$text['confirm-block']['de-at'] = "Do you really want to block this?"; +$text['confirm-block']['de-ch'] = "Do you really want to block this?"; +$text['confirm-block']['de-de'] = "Do you really want to block this?"; +$text['confirm-block']['el-gr'] = "Do you really want to block this?"; +$text['confirm-block']['es-cl'] = "Do you really want to block this?"; +$text['confirm-block']['es-mx'] = "Do you really want to block this?"; +$text['confirm-block']['fr-ca'] = "Do you really want to block this?"; +$text['confirm-block']['fr-fr'] = "Do you really want to block this?"; +$text['confirm-block']['he-il'] = "Do you really want to block this?"; +$text['confirm-block']['it-it'] = "Do you really want to block this?"; +$text['confirm-block']['nl-nl'] = "Do you really want to block this?"; +$text['confirm-block']['pl-pl'] = "Do you really want to block this?"; +$text['confirm-block']['pt-br'] = "Do you really want to block this?"; +$text['confirm-block']['pt-pt'] = "Do you really want to block this?"; +$text['confirm-block']['ro-ro'] = "Do you really want to block this?"; +$text['confirm-block']['ru-ru'] = "Do you really want to block this?"; +$text['confirm-block']['sv-se'] = "Do you really want to block this?"; +$text['confirm-block']['uk-ua'] = "Do you really want to block this?"; +$text['confirm-block']['tr-tr'] = "Do you really want to block this?"; + +$text['button-block']['en-us'] = "Block"; +$text['button-block']['ar-eg'] = "Block"; +$text['button-block']['de-at'] = "Block"; +$text['button-block']['de-ch'] = "Block"; +$text['button-block']['de-de'] = "Block"; +$text['button-block']['el-gr'] = "Block"; +$text['button-block']['es-cl'] = "Block"; +$text['button-block']['es-mx'] = "Block"; +$text['button-block']['fr-ca'] = "Block"; +$text['button-block']['fr-fr'] = "Block"; +$text['button-block']['he-il'] = "Block"; +$text['button-block']['it-it'] = "Block"; +$text['button-block']['nl-nl'] = "Block"; +$text['button-block']['pl-pl'] = "Block"; +$text['button-block']['pt-br'] = "Block"; +$text['button-block']['pt-pt'] = "Block"; +$text['button-block']['ro-ro'] = "Block"; +$text['button-block']['ru-ru'] = "Block"; +$text['button-block']['sv-se'] = "Block"; +$text['button-block']['uk-ua'] = "Block"; +$text['button-block']['tr-tr'] = "Block"; + +?> \ No newline at end of file diff --git a/app/call_block/call_block.php b/app/call_block/call_block.php index cf052f713f..a777108bfb 100644 --- a/app/call_block/call_block.php +++ b/app/call_block/call_block.php @@ -195,11 +195,11 @@ echo th_order_by('extension', $text['label-extension'], $order_by, $order); echo th_order_by('call_block_name', $text['label-name'], $order_by, $order); echo th_order_by('call_block_number', $text['label-number'], $order_by, $order); - echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "class='center'"); + echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "class='center hide-sm-dn'"); 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, null, "class='center'"); - echo th_order_by('date_added', $text['label-date-added'], $order_by, $order); - echo " ".$text['label-description']."\n"; + echo th_order_by('date_added', $text['label-date-added'], $order_by, $order, null, "class='shrink no-wrap'"); + echo "".$text['label-description']."\n"; if (permission_exists('call_block_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo "  \n"; } @@ -223,29 +223,19 @@ echo $text['label-all']; } else { - echo "".escape($row['extension']).""; + echo escape($row['extension']); } echo " \n"; - + echo " ".escape($row['call_block_name'])."\n"; echo " "; if (permission_exists('call_block_edit')) { - echo "".escape($row['call_block_name']).""; + echo "".escape(format_phone($row['call_block_number'])).""; } else { - echo escape($row['call_block_name']); + echo escape(format_phone($row['call_block_number'])); } echo " \n"; - - echo " "; - if (permission_exists('call_block_edit')) { - echo "".escape($row['call_block_number']).""; - } - else { - echo escape($row['call_block_number']); - } - echo " \n"; - - echo " ".escape($row['call_block_count'])."\n"; + echo " ".escape($row['call_block_count'])."\n"; echo " ".$text['label-'.$row['call_block_app']]." ".escape($row['call_block_data'])."\n"; if (permission_exists('call_block_edit')) { echo " "; @@ -256,7 +246,7 @@ echo $text['label-'.$row['call_block_enabled']]; } echo " \n"; - echo " ".date("j M Y H:i:s".(defined('TIME_24HR') && TIME_24HR == 1 ? 'a' : null), $row['date_added'])."\n"; + echo " ".date('j M Y', $row['date_added'])." ".date(($_SESSION['domain']['time_format']['text'] == '12h' ? 'h:i:s a' : 'H:i:s'), $row['date_added'])."\n"; echo " ".escape($row['call_block_description'])."\n"; if (permission_exists('call_block_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo " "; diff --git a/app/call_block/call_block_edit.php b/app/call_block/call_block_edit.php index 6d4a178631..ae174fa493 100644 --- a/app/call_block/call_block_edit.php +++ b/app/call_block/call_block_edit.php @@ -66,19 +66,33 @@ //handle the http post if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { - //delete the call block - if (permission_exists('call_block_delete')) { - if ($_POST['action'] == 'delete' && is_uuid($call_block_uuid)) { - //prepare - $array[0]['checked'] = 'true'; - $array[0]['uuid'] = $call_block_uuid; - //delete - $obj = new call_block; - $obj->delete($array); - //redirect - header('Location: call_block.php'); - exit; + //handle action + if ($_POST['action'] != '') { + switch ($_POST['action']) { + case 'delete': + if (permission_exists('call_block_delete') && is_uuid($call_block_uuid)) { + //prepare + $array[0]['checked'] = 'true'; + $array[0]['uuid'] = $call_block_uuid; + //delete + $obj = new call_block; + $obj->delete($array); + } + break; + case 'add': + $xml_cdrs = $_POST['xml_cdrs']; + if (permission_exists('call_block_add') && is_array($xml_cdrs) && @sizeof($xml_cdrs) != 0) { + $obj = new call_block; + $obj->extension_uuid = $extension_uuid; + $obj->call_block_app = $call_block_app; + $obj->call_block_data = $call_block_data; + $obj->add($xml_cdrs); + } + break; } + + header('Location: call_block.php'); + exit; } //validate the token @@ -261,42 +275,46 @@ require_once "resources/header.php"; //show the content - echo "
\n"; - echo "\n"; - echo "\n"; + echo "\n"; + + echo "
\n"; + echo "
"; if ($action == "add") { - echo "
\n"; + echo "".$text['label-edit-add']."\n"; } if ($action == "update") { - echo "\n"; + echo "".$text['label-edit-edit']."\n"; } - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo "

\n"; + + echo "
".$text['label-edit-add']."".$text['label-edit-edit'].""; - echo " "; + + echo "\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'call_block.php']); if ($action == 'update' && permission_exists('call_block_delete')) { - echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'action','value'=>'delete','onclick'=>"if (confirm('".$text['confirm-delete']."')) { document.getElementById('frm').submit(); } else { this.blur(); return false; }",'style'=>'margin-right: 15px;']); + echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'action','value'=>'delete','style'=>'margin-right: 15px;','onclick'=>"if (confirm('".$text['confirm-delete']."')) { document.getElementById('frm').submit(); } else { this.blur(); return false; }"]); } - echo " \n"; - echo "
\n"; + echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save']]); + echo " \n"; + echo "
\n"; + echo "\n"; + if ($action == "add") { - echo $text['label-add-note']."

\n"; + echo $text['label-add-note']."\n"; } if ($action == "update") { - echo $text['label-edit-note']."

\n"; + echo $text['label-edit-note']."\n"; } - echo "
\n"; if (permission_exists('call_block_all')) { echo "\n"; - echo "\n"; - echo "\n"; echo "\n"; echo "\n"; - echo " \n"; - echo " \n"; - echo " "; echo "
\n"; + echo "\n"; echo " ".$text['label-extension']."\n"; echo "\n"; + echo "\n"; echo " \n"; - echo " \n"; + if ($label) { + echo " \n"; } - } - if (permission_exists('call_block_voicemail')) { - if (is_array($voicemails) && sizeof($voicemails) != 0) { - echo " \n"; - foreach ($voicemails as &$row) { - $selected = ($call_block_app == 'voicemail' && $call_block_data == $row['voicemail_id']) ? "selected='selected'" : null; - echo " \n"; - } - echo " \n"; + if ($call_block_app == "reject") { + echo " \n"; } + else { + echo " \n"; + } + if ($call_block_app == "busy") { + echo " \n"; + } + else { + echo " \n"; + } + if ($call_block_app == "hold") { + echo " \n"; + } + else { + echo " \n"; + } + if (permission_exists('call_block_extension')) { + if (is_array($extensions) && sizeof($extensions) != 0) { + echo " \n"; + foreach ($extensions as &$row) { + $selected = ($call_block_app == 'extension' && $call_block_data == $row['extension']) ? "selected='selected'" : null; + echo " \n"; + } + echo " \n"; + } + } + if (permission_exists('call_block_voicemail')) { + if (is_array($voicemails) && sizeof($voicemails) != 0) { + echo " \n"; + foreach ($voicemails as &$row) { + $selected = ($call_block_app == 'voicemail' && $call_block_data == $row['voicemail_id']) ? "selected='selected'" : null; + echo " \n"; + } + echo " \n"; + } + } + echo " \n"; } - echo " \n"; + call_block_action_select(); echo "
\n"; echo $text['description-action']."\n"; echo "\n"; @@ -411,18 +436,14 @@ echo "
\n"; - if ($action == "update") { - echo " \n"; - } - echo " \n"; - echo "
"; - echo " \n"; - echo "
"; echo "

"; + + if ($action == "update") { + echo "\n"; + } + echo "\n"; + echo "
"; //get recent calls from the db (if not editing an existing call block record) @@ -474,99 +495,110 @@ $result = $database->select($sql, $parameters, 'all'); } - echo "".$text['label-edit-add-recent'].""; - echo "

"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo "
".$text['label-edit-add-recent']."
\n"; + echo "
\n"; + if (permission_exists('call_block_all')) { + echo " \n"; + } + call_block_action_select(true); + echo button::create(['type'=>'button','label'=>$text['button-block'],'icon'=>'ban','onclick'=>"if (confirm('".$text['confirm-block']."')) { list_form_submit('form_list'); } else { this.blur(); return false; }"]); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo "
 
\n"; + echo "\n"; + echo " \n"; + echo "\n"; echo th_order_by('caller_id_name', $text['label-name'], $order_by, $order); echo th_order_by('caller_id_number', $text['label-number'], $order_by, $order); echo th_order_by('start_stamp', $text['label-called-on'], $order_by, $order); - echo th_order_by('duration', $text['label-duration'], $order_by, $order); - //echo "\n"; + echo th_order_by('duration', $text['label-duration'], $order_by, $order, null, "class='right hide-sm-dn'"); echo ""; - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - - if (is_array($result) && sizeof($result) != 0) { - foreach($result as $row) { - $extension_uuids = ''; - if (!permission_exists('call_block_all') && is_array($_SESSION['user']['extension'])) { - foreach ($_SESSION['user']['extension'] as $field) { - if (is_uuid($field['extension_uuid'])) { - $extension_uuids .= "&extension_uuid=".$field['extension_uuid']; - } - } - } - $tr_href = " href='call_block_cdr_add.php?id=".urlencode($row['xml_cdr_uuid'])."&name=".urlencode($row['caller_id_name']).$extension_uuids."' "; + if (is_array($result) && @sizeof($result) != 0) { + $x = 0; + foreach ($result as $row) { + $list_row_onclick_uncheck = "if (!this.checked) { document.getElementById('checkbox_all').checked = false; }"; + $list_row_onclick_toggle = "onclick=\"document.getElementById('checkbox_".$x."').checked = document.getElementById('checkbox_".$x."').checked ? false : true; ".$list_row_onclick_uncheck."\""; if (strlen($row['caller_id_number']) >= 7) { if (defined('TIME_24HR') && TIME_24HR == 1) { - $tmp_start_epoch = date("j M Y H:i:s", $row['start_epoch']); - } else { - $tmp_start_epoch = date("j M Y h:i:sa", $row['start_epoch']); + $tmp_start_epoch = date('j M Y', $row['start_epoch'])." ".date('H:i:s', $row['start_epoch']).''; } - echo "\n"; + else { + $tmp_start_epoch = date('j M Y', $row['start_epoch'])." ".date('h:i:sa', $row['start_epoch']).''; + } + echo "\n"; + echo " \n"; if ( - file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_inbound_missed.png") && - file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_inbound_connected.png") && + file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_inbound_voicemail.png") && + file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_inbound_answered.png") && file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_local_failed.png") && - file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_local_connected.png") + file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_local_answered.png") ) { - echo " \n"; } else { - echo " "; + echo " "; } - echo " \n"; - echo " \n"; - echo " \n"; - $seconds = ($row['hangup_cause']=="ORIGINATOR_CANCEL") ? $row['duration'] : $row['billsec']; //If they cancelled, show the ring time, not the bill time. - echo " \n"; - //echo " "; + echo " \n"; + echo " \n"; + echo " \n"; + $seconds = ($row['hangup_cause'] == "ORIGINATOR_CANCEL") ? $row['duration'] : $row['billsec']; //if they cancelled, show the ring time, not the bill time. + echo " \n"; echo "\n"; - $c = $c == 1 ? 0 : 1; + $x++; } } unset($result); } - echo "
\n"; + echo " \n"; + echo "   
\n"; + echo " \n"; + echo " \n"; + echo " "; + echo " "; switch ($row['direction']) { case "inbound" : - if ($row['billsec'] == 0) - echo "".$text[\n"; - else - echo "".$text[\n"; + if ($row['billsec'] == 0) { + echo "".$text[\n"; + } + else { + echo "".$text[\n"; + } break; case "local" : - if ($row['billsec'] == 0) + if ($row['billsec'] == 0) { echo "".$text[\n"; - else - echo "".$text[\n"; + } + else { + echo "".$text[\n"; + } break; } echo "   "; - echo $row['caller_id_name'].' '; - echo " "; - if (is_numeric($row['caller_id_number'])) { - echo format_phone($row['caller_id_number']).' '; - } - else { - echo $row['caller_id_number'].' '; - } - echo " ".$tmp_start_epoch."".gmdate("G:i:s", $seconds).""; - //if (if_group("superadmin")) { - // echo " ".$v_link_label_view.""; - //} - //echo " ".$v_link_label_add.""; - //echo " ".$row['caller_id_name']." ".format_phone($row['caller_id_number'])."".$tmp_start_epoch."".gmdate("G:i:s", $seconds)."
"; - echo "
"; + echo "\n"; + echo "
\n"; + echo "\n"; + echo "\n"; } //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/call_block/resources/classes/call_block.php b/app/call_block/resources/classes/call_block.php index 37d38e1909..fcb61a6555 100644 --- a/app/call_block/resources/classes/call_block.php +++ b/app/call_block/resources/classes/call_block.php @@ -20,6 +20,13 @@ if (!class_exists('call_block')) { private $toggle_field; private $toggle_values; + /** + * declare public variables + */ + public $extension_uuid; + public $call_block_app; + public $call_block_data; + /** * called when the object is created */ @@ -270,7 +277,131 @@ if (!class_exists('call_block')) { } } - } + /** + * add records + */ + public function add($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; + } + + //add the checked records + if (is_array($records) && @sizeof($records) != 0) { + + //filter checked records + foreach ($records as $x => $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $uuids[] = "'".$record['uuid']."'"; + } + } + + //get the caller id info from cdrs + if (is_array($uuids) && @sizeof($uuids) != 0) { + $sql = "select caller_id_name, caller_id_number from v_xml_cdr "; + $sql .= "where xml_cdr_uuid in (".implode(', ', $uuids).") "; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + unset($sql); + } + + //loop through records + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $x => $row) { + + //build insert array + if (permission_exists('call_block_all')) { + $array['call_block'][$x]['call_block_uuid'] = uuid(); + $array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; + if (is_uuid($this->extension_uuid)) { + $array['call_block'][$x]['extension_uuid'] = $this->extension_uuid; + } + $array['call_block'][$x]['call_block_name'] = trim($row["caller_id_name"]); + $array['call_block'][$x]['call_block_number'] = trim($row["caller_id_number"]); + $array['call_block'][$x]['call_block_count'] = 0; + $array['call_block'][$x]['call_block_app'] = $this->call_block_app; + $array['call_block'][$x]['call_block_data'] = $this->call_block_data; + $array['call_block'][$x]['call_block_enabled'] = 'true'; + $array['call_block'][$x]['date_added'] = time(); + $x++; + } + else { + if (is_array($_SESSION['user']['extension'])) { + foreach ($_SESSION['user']['extension'] as $field) { + if (is_uuid($field['extension_uuid'])) { + $array['call_block'][$x]['call_block_uuid'] = uuid(); + $array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; + $array['call_block'][$x]['extension_uuid'] = $field['extension_uuid']; + $array['call_block'][$x]['call_block_name'] = trim($row["caller_id_name"]); + $array['call_block'][$x]['call_block_number'] = trim($row["caller_id_number"]); + $array['call_block'][$x]['call_block_count'] = 0; + $array['call_block'][$x]['call_block_app'] = $this->call_block_app; + $array['call_block'][$x]['call_block_data'] = $this->call_block_data; + $array['call_block'][$x]['call_block_enabled'] = 'true'; + $array['call_block'][$x]['date_added'] = time(); + $x++; + } + } + } + } + + } + } + + //add records + if (is_array($array) && @sizeof($array) != 0) { + + //ensure call block is enabled in the dialplan (build update array) + $sql = "select dialplan_uuid from v_dialplans "; + $sql .= "where domain_uuid = :domain_uuid "; + $sql .= "and app_uuid = '".$this->app_uuid."' "; + $sql .= "and dialplan_enabled <> 'true' "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $x => $row) { + $array['dialplans'][$x]['dialplan_uuid'] = $row['dialplan_uuid']; + $array['dialplans'][$x]['dialplan_enabled'] = 'true'; + } + } + unset($rows, $parameters); + + //grant temporary permissions + $p = new permissions; + $p->add('dialplan_edit', 'temp'); + + //save the array + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + $response = $database->message; + unset($array); + + //revoke temporary permissions + $p->delete('dialplan_edit', 'temp'); + + //set message + message::add($text['message-add']); + + } + + } + + } + } //method + + } //class } ?> \ No newline at end of file