Portions created by the Initial Developer are Copyright (C) 2008-2017 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('destination_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //get the http values and set them as variables $search = check_str($_GET["search"]); $order_by = check_str($_GET["order_by"]); $order = check_str($_GET["order"]); //includes and title require_once "resources/header.php"; $document['title'] = $text['title-destinations']; require_once "resources/paging.php"; //get total destination count from the database $sql = "select count(*) as num_rows from v_destinations "; if ($_GET['showall'] && permission_exists('destination_all')) { if (strlen($search) > 0) { $sql .= "where "; } } else { $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; if (strlen($search) > 0) { $sql .= "and "; } } if (strlen($search) > 0) { $sql .= "("; $sql .= " destination_type like '%".$search."%' "; $sql .= " or destination_number like '%".$search."%' "; $sql .= " or lower(destination_context) like '%".strtolower($search)."%' "; $sql .= " or destination_enabled like '%".$search."%' "; $sql .= " or lower(destination_description) like '%".strtolower($search)."%' "; $sql .= ") "; } $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); $num_rows = $row['num_rows']; } else { $num_rows = 0; } //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $param = "&search=".$search; if ($_GET['showall'] && permission_exists('destination_all')) { $param .= "&showall=true"; } $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); $offset = $rows_per_page * $page; //get the list $sql = "select * from v_destinations "; if ($_GET['showall'] && permission_exists('destination_all')) { if (strlen($search) > 0) { $sql .= " where "; } } else { $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; if (strlen($search) > 0) { $sql .= " and "; } } if (strlen($search) > 0) { $sql .= " ("; $sql .= " destination_type like '%".$search."%' "; $sql .= " or destination_number like '%".$search."%' "; $sql .= " or lower(destination_context) like '%".strtolower($search)."%' "; $sql .= " or destination_enabled like '%".$search."%' "; $sql .= " or lower(destination_description) like '%".strtolower($search)."%' "; $sql .= ") "; } if (strlen($order_by) > 0) { if ($order_by == 'destination_type') { $sql .= "order by destination_type ".$order.", destination_number asc "; } else { $sql .= "order by ".$order_by." ".$order." "; } } else { $sql .= "order by destination_type asc, destination_number asc "; } $sql .= "limit $rows_per_page offset $offset "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $destinations = $prep_statement->fetchAll(); unset ($prep_statement, $sql); //show the content echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['header-destinations']." (".$num_rows.")
\n"; if (permission_exists('destination_all')) { if ($_GET['showall'] == 'true') { echo " "; } else { echo " \n"; } } echo " "; echo " "; echo "
\n"; echo " ".$text['description-destinations']."

\n"; echo "
\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo "\n"; echo "\n"; if ($_GET['showall'] && permission_exists('destination_all')) { echo th_order_by('domain_name', $text['label-domain-name'], $order_by, $order, '', '', $param); } echo th_order_by('destination_type', $text['label-destination_type'], $order_by, $order, '', '', $param); echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, '', '', $param); echo th_order_by('destination_context', $text['label-destination_context'], $order_by, $order, '', '', $param); echo th_order_by('destination_enabled', $text['label-destination_enabled'], $order_by, $order, '', '', $param); echo th_order_by('destination_description', $text['label-destination_description'], $order_by, $order, '', '', $param); echo "\n"; echo "\n"; if ($num_rows > 0) { foreach($destinations as $row) { $tr_link = "href='destination_edit.php?id=".$row['destination_uuid']."'"; echo "\n"; if ($_GET['showall'] && permission_exists('destination_all')) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } //end foreach unset($sql, $destinations, $row_count); } //end if results echo "\n"; if ($_GET['showall'] && permission_exists('destination_all')) { echo "\n"; echo "\n"; echo "
"; if (permission_exists('destination_add')) { if ($_SESSION['limit']['destinations']['numeric'] == '' || ($_SESSION['limit']['destinations']['numeric'] != '' && $num_rows < $_SESSION['limit']['destinations']['numeric'])) { echo "".$v_link_label_add.""; } } echo "
".$_SESSION['domains'][$row['domain_uuid']]['domain_name']."".ucwords($row['destination_type'])."".format_phone($row['destination_number'])."".$row['destination_context']."".$text['label-'.$row['destination_enabled']]."".$row['destination_description']." "; if (permission_exists('destination_edit')) { echo "".$v_link_label_edit.""; } if (permission_exists('destination_delete')) { echo "".$v_link_label_delete.""; } echo "
\n"; } else { echo "\n"; } if (permission_exists('destination_add')) { if ($_SESSION['limit']['destinations']['numeric'] == '' || ($_SESSION['limit']['destinations']['numeric'] != '' && $num_rows < $_SESSION['limit']['destinations']['numeric'])) { echo "".$v_link_label_add.""; } } echo "
"; echo "
".$paging_controls."
\n"; echo "

"; //include the footer require_once "resources/footer.php"; ?>