|
@@ -386,24 +386,102 @@
|
|
|
//create the menu array
|
|
|
function menu_array($sql, $menu_item_level) {
|
|
|
|
|
|
- $db = $this->db;
|
|
|
+ //get the database connnection return immediately if it doesn't exist
|
|
|
+ if ($this->db) {
|
|
|
+ $db = $this->db;
|
|
|
+ }else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!isset($_SESSION['groups'])) {
|
|
|
- $_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
- }
|
|
|
+ //if there are no groups then set the public group
|
|
|
+ if (!isset($_SESSION['groups'])) {
|
|
|
+ $_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
+ }
|
|
|
+
|
|
|
+ //get the menu from the database
|
|
|
+ if (strlen($sql) == 0) { //default sql for base of the menu
|
|
|
+ $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_uuid, i.menu_item_parent_uuid ";
|
|
|
+ $sql .= "from v_menu_items as i, v_menu_languages as l ";
|
|
|
+ $sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
|
|
|
+ $sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' ";
|
|
|
+ $sql .= "and l.menu_uuid = '".$this->menu_uuid."' ";
|
|
|
+ $sql .= "and i.menu_uuid = '".$this->menu_uuid."' ";
|
|
|
+ $sql .= "and i.menu_item_parent_uuid is null ";
|
|
|
+ $sql .= "and i.menu_item_uuid in ";
|
|
|
+ $sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' ";
|
|
|
+ $sql .= "and ( ";
|
|
|
+ if (!isset($_SESSION['groups'])) {
|
|
|
+ $sql .= "group_name = 'public' ";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $x = 0;
|
|
|
+ foreach($_SESSION['groups'] as $row) {
|
|
|
+ if ($x == 0) {
|
|
|
+ $sql .= "group_name = '".$row['group_name']."' ";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $sql .= "or group_name = '".$row['group_name']."' ";
|
|
|
+ }
|
|
|
+ $x++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sql .= ") ";
|
|
|
+ $sql .= "and menu_item_uuid is not null ";
|
|
|
+ $sql .= ") ";
|
|
|
+ $sql .= "order by i.menu_item_order asc ";
|
|
|
+ }
|
|
|
+ $prep_statement = $db->prepare(check_sql($sql));
|
|
|
+ $prep_statement->execute();
|
|
|
+ $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
|
- if (strlen($sql) == 0) { //default sql for base of the menu
|
|
|
+ //save the menu into an array
|
|
|
+ $x = 0;
|
|
|
+ foreach($result as $row) {
|
|
|
+ //add the row to the array
|
|
|
+ $a[$x] = $row;
|
|
|
+
|
|
|
+ //add the sub menus to the array
|
|
|
+ $menu_item_level = 0;
|
|
|
+ if (strlen($row['menu_item_uuid']) > 0) {
|
|
|
+ $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $row['menu_item_uuid']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //increment the row number
|
|
|
+ $x++;
|
|
|
+ } //end for each
|
|
|
+
|
|
|
+ //unset the variables
|
|
|
+ unset($prep_statement, $sql, $result);
|
|
|
+
|
|
|
+ //return the array
|
|
|
+ return $a;
|
|
|
+ }
|
|
|
+
|
|
|
+ //create the sub menus
|
|
|
+ function menu_child_array($menu_item_level, $menu_item_uuid) {
|
|
|
+
|
|
|
+ //get the database connnection return immediately if it doesn't exist
|
|
|
+ if ($this->db) {
|
|
|
+ $db = $this->db;
|
|
|
+ }else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //set the level
|
|
|
+ $menu_item_level = $menu_item_level+1;
|
|
|
+
|
|
|
+ //get the child menu from the database
|
|
|
$sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_uuid, i.menu_item_parent_uuid ";
|
|
|
$sql .= "from v_menu_items as i, v_menu_languages as l ";
|
|
|
$sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
|
|
|
$sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' ";
|
|
|
$sql .= "and l.menu_uuid = '".$this->menu_uuid."' ";
|
|
|
$sql .= "and i.menu_uuid = '".$this->menu_uuid."' ";
|
|
|
- $sql .= "and i.menu_item_parent_uuid is null ";
|
|
|
+ $sql .= "and i.menu_item_parent_uuid = '$menu_item_uuid' ";
|
|
|
$sql .= "and i.menu_item_uuid in ";
|
|
|
$sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' ";
|
|
|
$sql .= "and ( ";
|
|
|
- if (!isset($_SESSION['groups'])) {
|
|
|
+ if (count($_SESSION['groups']) == 0) {
|
|
|
$sql .= "group_name = 'public' ";
|
|
|
}
|
|
|
else {
|
|
@@ -419,111 +497,45 @@
|
|
|
}
|
|
|
}
|
|
|
$sql .= ") ";
|
|
|
- $sql .= "and menu_item_uuid is not null ";
|
|
|
$sql .= ") ";
|
|
|
- $sql .= "order by i.menu_item_order asc ";
|
|
|
- }
|
|
|
- try {
|
|
|
- $prep_statement = $db->prepare(check_sql($sql));
|
|
|
- $prep_statement->execute();
|
|
|
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
- }
|
|
|
- catch (Exception $e) {
|
|
|
- //menu is not available
|
|
|
- }
|
|
|
-
|
|
|
- $x = 0;
|
|
|
- foreach($result as $row) {
|
|
|
- //add the row to the array
|
|
|
- $a[$x] = $row;
|
|
|
-
|
|
|
- //add the sub menus to the array
|
|
|
- $menu_item_level = 0;
|
|
|
- if (strlen($row['menu_item_uuid']) > 0) {
|
|
|
- $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $row['menu_item_uuid']);
|
|
|
- }
|
|
|
-
|
|
|
- //increment the row number
|
|
|
- $x++;
|
|
|
- } //end for each
|
|
|
-
|
|
|
- unset($prep_statement, $sql, $result);
|
|
|
- return $a;
|
|
|
- }
|
|
|
+ $sql .= "order by l.menu_item_title, i.menu_item_order asc ";
|
|
|
+ $sub_prep_statement = $db->prepare($sql);
|
|
|
+ $sub_prep_statement->execute();
|
|
|
+ $sub_result = $prep_statement_2->fetchAll(PDO::FETCH_NAMED);
|
|
|
+
|
|
|
+ //save the child menu into an array
|
|
|
+ if (count($sub_result) > 0) {
|
|
|
+ foreach($sub_result as $row) {
|
|
|
+ //set the variables
|
|
|
+ $menu_item_link = $row['menu_item_link'];
|
|
|
+ $menu_item_category = $row['menu_item_category'];
|
|
|
+ $menu_item_uuid = $row['menu_item_uuid'];
|
|
|
+ $menu_item_parent_uuid = $row['menu_item_parent_uuid'];
|
|
|
|
|
|
- //create the sub menus
|
|
|
- function menu_child_array($menu_item_level, $menu_item_uuid) {
|
|
|
+ //add the row to the array
|
|
|
+ $a[$x] = $row;
|
|
|
|
|
|
- $db = $this->db;
|
|
|
- $menu_item_level = $menu_item_level+1;
|
|
|
+ //prepare the protected menus
|
|
|
+ if ($row['menu_item_protected'] == "true") {
|
|
|
+ $a[$x]['menu_item_title'] = $row['menu_item_title'];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $a[$x]['menu_item_title'] = $row['menu_language_title'];
|
|
|
+ }
|
|
|
|
|
|
- if (count($_SESSION['groups']) == 0) {
|
|
|
- $_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
- }
|
|
|
+ //get sub menu for children
|
|
|
+ if (strlen($menu_item_uuid) > 0) {
|
|
|
+ $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid);
|
|
|
+ //$str_child_menu =
|
|
|
+ }
|
|
|
|
|
|
- $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_uuid, i.menu_item_parent_uuid ";
|
|
|
- $sql .= "from v_menu_items as i, v_menu_languages as l ";
|
|
|
- $sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
|
|
|
- $sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' ";
|
|
|
- $sql .= "and l.menu_uuid = '".$this->menu_uuid."' ";
|
|
|
- $sql .= "and i.menu_uuid = '".$this->menu_uuid."' ";
|
|
|
- $sql .= "and i.menu_item_parent_uuid = '$menu_item_uuid' ";
|
|
|
- $sql .= "and i.menu_item_uuid in ";
|
|
|
- $sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' ";
|
|
|
- $sql .= "and ( ";
|
|
|
- if (count($_SESSION['groups']) == 0) {
|
|
|
- $sql .= "group_name = 'public' ";
|
|
|
- }
|
|
|
- else {
|
|
|
- $x = 0;
|
|
|
- foreach($_SESSION['groups'] as $row) {
|
|
|
- if ($x == 0) {
|
|
|
- $sql .= "group_name = '".$row['group_name']."' ";
|
|
|
- }
|
|
|
- else {
|
|
|
- $sql .= "or group_name = '".$row['group_name']."' ";
|
|
|
+ //increment the row
|
|
|
+ $x++;
|
|
|
}
|
|
|
- $x++;
|
|
|
+ unset($sql, $sub_result);
|
|
|
+ return $a;
|
|
|
}
|
|
|
- }
|
|
|
- $sql .= ") ";
|
|
|
- $sql .= ") ";
|
|
|
- $sql .= "order by l.menu_item_title, i.menu_item_order asc ";
|
|
|
- $prep_statement_2 = $db->prepare($sql);
|
|
|
- $prep_statement_2->execute();
|
|
|
- $result_2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED);
|
|
|
- if (count($result_2) > 0) {
|
|
|
- foreach($result_2 as $row) {
|
|
|
- //set the variables
|
|
|
- $menu_item_link = $row['menu_item_link'];
|
|
|
- $menu_item_category = $row['menu_item_category'];
|
|
|
- $menu_item_uuid = $row['menu_item_uuid'];
|
|
|
- $menu_item_parent_uuid = $row['menu_item_parent_uuid'];
|
|
|
-
|
|
|
- //add the row to the array
|
|
|
- $a[$x] = $row;
|
|
|
-
|
|
|
- //prepare the protected menus
|
|
|
- if ($row['menu_item_protected'] == "true") {
|
|
|
- $a[$x]['menu_item_title'] = $row['menu_item_title'];
|
|
|
- }
|
|
|
- else {
|
|
|
- $a[$x]['menu_item_title'] = $row['menu_language_title'];
|
|
|
- }
|
|
|
-
|
|
|
- //get sub menu for children
|
|
|
- if (strlen($menu_item_uuid) > 0) {
|
|
|
- $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid);
|
|
|
- //$str_child_menu =
|
|
|
- }
|
|
|
-
|
|
|
- //increment the row
|
|
|
- $x++;
|
|
|
- }
|
|
|
- unset($sql, $result_2);
|
|
|
- return $a;
|
|
|
- }
|
|
|
- unset($prep_statement_2, $sql);
|
|
|
+ unset($sub_prep_statement, $sql);
|
|
|
}
|
|
|
}
|
|
|
|