Portions created by the Initial Developer are Copyright (C) 2008-2015 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz Call Block is written by Gerrit Visser */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('call_block_edit') || permission_exists('call_block_add')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //define the call_block_get_extensions function function call_block_get_extensions($select_extension) { global $db, $text; //list voicemail $sql = "select extension, user_context, description from v_extensions "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and enabled = 'true' "; $sql .= "order by extension asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); echo "\n"; foreach ($result as &$row) { $extension = $row["extension"]; $context = $row["user_context"]; $description = $row["description"]; if ($extension == $select_extension) $selected = "selected='selected'"; echo " \n"; $selected = ""; } echo "\n"; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $call_block_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get http post variables and set them to php variables if (count($_POST) > 0) { $call_block_name = check_str($_POST["call_block_name"]); $call_block_number = check_str($_POST["call_block_number"]); $call_block_action = check_str($_POST["call_block_action"]); $call_block_enabled = check_str($_POST["call_block_enabled"]); } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { //$call_block_uuid = check_str($_POST["call_block_uuid"]); } //check for all required data if (strlen($call_block_name) == 0) { $msg .= $text['label-provide-name']."
\n"; } if ($action == "add") { if (strlen($call_block_number) == 0) { $msg .= $text['label-provide-number']."
\n"; } } if (strlen($call_block_enabled) == 0) { $msg .= $text['label-provide-enabled']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add or update the database if (($_POST["persistformvar"] != "true")>0) { if ($action == "add" || $action == "update") { //ensure call block is enabled in the dialplan $sql = "update v_dialplans set "; $sql .= "dialplan_enabled = 'true' "; $sql .= "where "; $sql .= "app_uuid = 'b1b31930-d0ee-4395-a891-04df94599f1f' and "; $sql .= "domain_uuid = '".$domain_uuid."' and "; $sql .= "dialplan_enabled <> 'true' "; $db->exec(check_sql($sql)); unset($sql); } if ($action == "add") { $sql = "insert into v_call_block "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "call_block_uuid, "; $sql .= "call_block_name, "; $sql .= "call_block_number, "; $sql .= "call_block_count, "; $sql .= "call_block_action, "; $sql .= "call_block_enabled, "; $sql .= "date_added "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "'".uuid()."', "; $sql .= "'$call_block_name', "; $sql .= "'$call_block_number', "; $sql .= "0, "; $sql .= "'$call_block_action', "; $sql .= "'$call_block_enabled', "; $sql .= "'".time()."' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); messages::add($text['label-add-complete']); header("Location: call_block.php"); return; } //if ($action == "add") if ($action == "update") { $sql = " select c.call_block_number, d.domain_name from v_call_block as c "; $sql .= "JOIN v_domains as d ON c.domain_uuid=d.domain_uuid "; $sql .= "where c.domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and c.call_block_uuid = '$call_block_uuid'"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); $result_count = count($result); if ($result_count > 0) { //set the domain_name $domain_name = $result[0]["domain_name"]; //clear the cache $cache = new cache; $cache->delete("app:call_block:".$domain_name.":".$call_block_number); } unset ($prep_statement, $sql); $sql = "update v_call_block set "; $sql .= "call_block_name = '$call_block_name', "; $sql .= "call_block_number = '$call_block_number', "; $sql .= "call_block_action = '$call_block_action', "; $sql .= "call_block_enabled = '$call_block_enabled' "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and call_block_uuid = '$call_block_uuid'"; $db->exec(check_sql($sql)); unset($sql); messages::add($text['label-update-complete']); header("Location: call_block.php"); return; } //if ($action == "update") } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $call_block_uuid = $_GET["id"]; $sql = "select * from v_call_block "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and call_block_uuid = '$call_block_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); foreach ($result as &$row) { $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"]; break; //limit to 1 row } unset ($prep_statement, $sql); } //show the header require_once "resources/header.php"; //show the content echo ""; // Show last 5-10 calls first, with add button echo "
\n"; echo "\n"; echo "\n"; if ($action == "add") { echo "\n"; } if ($action == "update") { echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " "; echo "
".$text['label-edit-add']."".$text['label-edit-edit'].""; echo " "; echo " \n"; echo "
\n"; if ($action == "add") { echo $text['label-add-note']."

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

\n"; } echo "
\n"; echo " ".$text['label-number']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-number']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-name']."\n"; echo "
\n"; echo " ".$text['label-action']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-action']."\n"; echo "\n"; echo "
\n"; echo " ".$text['label-enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enable']."\n"; echo "\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "

"; echo "
"; //get recent calls from the db (if not editing an existing call block record) if (!isset($_REQUEST["id"])) { $sql = "select caller_id_number, caller_id_name, start_epoch, direction, hangup_cause, duration, billsec, uuid from v_xml_cdr "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and direction != 'outbound' "; $sql .= "order by start_stamp DESC "; $sql .= "limit 20 "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); $result_count = count($result); unset ($prep_statement); echo "".$text['label-edit-add-recent'].""; echo "

"; 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 ""; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; if ($result_count > 0) { foreach($result as $row) { $tr_onclick = " onclick=\"call_block_recent('".$row['uuid']."','".urlencode($row['caller_id_name'])."');\" "; 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']); } 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_local_failed.png") && file_exists($_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_local_connected.png") ) { echo " \n"; } else { 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"; if ($c==0) { $c=1; } else { $c=0; } } } //end foreach unset($sql, $result, $row_count); echo "
  
"; switch ($row['direction']) { case "inbound" : if ($row['billsec'] == 0) echo "".$text[\n"; else echo "".$text[\n"; break; case "local" : if ($row['billsec'] == 0) 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("admin") || if_group("superadmin")) { echo " ".$v_link_label_view.""; } echo "".$v_link_label_add.""; echo "
"; echo "

"; } //end if results else { echo ""; echo "

"; echo "

"; } } // end of Display Last 5-10 Calls //include the footer require_once "resources/footer.php"; ?>