diff --git a/core/menu/menu.php b/core/menu/menu.php index 6aa2e65a24..bb53388773 100644 --- a/core/menu/menu.php +++ b/core/menu/menu.php @@ -17,118 +17,194 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008 - 2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ -require_once "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -if (permission_exists('menu_add') || permission_exists('menu_edit') || permission_exists('menu_delete')) { - //access granted -} -else { - echo "access denied"; - exit; -} + +//includes + require_once "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('menu_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; $text = $language->get(); -//includes and title - require_once "resources/header.php"; - $document['title'] = $text['title-menus']; - require_once "resources/paging.php"; +//get the http post data + if (is_array($_POST['menus'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $menus = $_POST['menus']; + } -//get variables used to control the order +//process the http post data by action + if ($action != '' && is_array($menus) && @sizeof($menus) != 0) { + switch ($action) { + case 'copy': + //if (permission_exists('menu_add')) { + // $obj = new menus; + // $obj->copy($menus); + //} + break; + case 'toggle': + //if (permission_exists('menu_edit')) { + // $obj = new menus; + // $obj->toggle($menus); + //} + break; + case 'delete': + if (permission_exists('menu_delete')) { + $obj = new menus; + $obj->delete($menus); + } + break; + } + + header('Location: menu.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + +//get order and order by $order_by = $_GET["order_by"]; $order = $_GET["order"]; -//show the content - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['header-menus']." 
\n"; - echo " ".$text['description-menus']."

\n"; - echo "
\n"; - - //prepare to page the results - $sql = "select count(*) from v_menus "; - $database = new database; - $num_rows = $database->select($sql, null, 'column'); - - //prepare to page the results - $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $param = ""; - $page = $_GET['page']; - if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); - $offset = $rows_per_page * $page; - - //get the list - $sql = "select * from v_menus "; - $sql .= order_by($order_by, $order); - $sql .= limit_offset($rows_per_page, $offset); - $database = new database; - $result = $database->select($sql, null, 'all'); - unset($sql); - - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - - echo "\n"; - echo "\n"; - echo th_order_by('menu_name', $text['label-name'], $order_by, $order); - echo th_order_by('menu_language', $text['label-language'], $order_by, $order); - echo th_order_by('menu_description', $text['label-description'], $order_by, $order); - echo "\n"; - echo "\n"; - - if (is_array($result) && sizeof($result) != 0) { - foreach($result as $row) { - $tr_link = "href='menu_edit.php?id=".$row['menu_uuid']."'"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } - } +//add the search string + if (isset($_GET["search"])) { + $search = strtolower($_GET["search"]); + $sql_search = " ("; + $sql_search .= " lower(menu_name) like :search "; + $sql_search .= " or lower(menu_language) like :search "; + $sql_search .= " or lower(menu_description) like :search "; + $sql_search .= ") "; + $parameters['search'] = '%'.$search.'%'; } - unset($result, $row); - echo "\n"; - echo "\n"; +//get the count + $sql = "select count(menu_uuid) from v_menus "; + if (isset($sql_search)) { + $sql .= "where ".$sql_search; + } + $database = new database; + $num_rows = $database->select($sql, $parameters, 'column'); + +//get the list + $sql = str_replace('count(menu_uuid)', '*', $sql); + $sql .= order_by($order_by, $order, 'menu_name', 'asc'); + $sql .= limit_offset($rows_per_page, $offset); + $database = new database; + $menus = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//include the header + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "
".$text['title-menus']." (".$num_rows.")
\n"; + echo "
\n"; + if (permission_exists('menu_add')) { + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'menu_edit.php']); + } + //if (permission_exists('menu_add') && $menus) { + // 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('menu_edit') && $menus) { + // 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('menu_delete') && $menus) { + 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 "\n"; + echo ""; + 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'=>'menu.php','style'=>($search == '' ? 'display: none;' : null)]); + if ($paging_controls_mini != '') { + echo "".$paging_controls_mini."\n"; + } + echo " \n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-menus']."\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
"; - echo "$v_link_label_add"; - echo "
".escape($row['menu_name'])."".escape($row['menu_language'])."".escape($row['menu_description'])." "; - echo "$v_link_label_edit"; - echo "$v_link_label_delete"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - echo "$v_link_label_add"; - echo "
\n"; - echo "
\n"; + echo "\n"; + if (permission_exists('menu_add') || permission_exists('menu_edit') || permission_exists('menu_delete')) { + echo " \n"; + } + echo th_order_by('menu_name', $text['label-menu_name'], $order_by, $order); + echo th_order_by('menu_language', $text['label-menu_language'], $order_by, $order); + echo " \n"; + if (permission_exists('menu_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } echo "\n"; - echo "
\n"; + echo " \n"; + echo " ".$text['label-menu_description']." 
"; - echo "

"; + if (is_array($menus) && @sizeof($menus) != 0) { + $x = 0; + foreach ($menus as $row) { + if (permission_exists('menu_edit')) { + $list_row_url = "menu_edit.php?id=".urlencode($row['menu_uuid']); + } + echo "\n"; + if (permission_exists('menu_add') || permission_exists('menu_edit') || permission_exists('menu_delete')) { + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + } + echo " \n"; + if (permission_exists('menu_edit')) { + echo " ".escape($row['menu_name'])."\n"; + } + else { + echo " ".escape($row['menu_name']); + } + echo " \n"; + echo " ".escape($row['menu_language'])."\n"; + echo " ".escape($row['menu_description'])."\n"; + if (permission_exists('menu_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo " \n"; + } + echo "\n"; + $x++; + } + unset($menus); + } + + echo "\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + echo "\n"; + echo "\n"; //include the footer require_once "resources/footer.php"; + ?>