Menu Class: Database class integration.

This commit is contained in:
Nate
2019-09-03 09:59:37 -06:00
parent e9cdfbcf11
commit 07cb911e70
+206 -234
View File
@@ -33,48 +33,52 @@ if (!class_exists('menu')) {
//delete items in the menu that are not protected //delete items in the menu that are not protected
public function delete() { public function delete() {
//set the variable
$db = $this->db;
//remove existing menu languages //remove existing menu languages
$sql = "delete from v_menu_languages "; $sql = "delete from v_menu_languages ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' "; $sql .= "where menu_uuid = :menu_uuid ";
$sql .= "and menu_item_uuid in ( "; $sql .= "and menu_item_uuid in ( ";
$sql .= " select menu_item_uuid "; $sql .= " select menu_item_uuid ";
$sql .= " from v_menu_items "; $sql .= " from v_menu_items ";
$sql .= " where menu_uuid = '".$this->menu_uuid."' "; $sql .= " where menu_uuid = :menu_uuid ";
$sql .= " and ( "; $sql .= " and ( ";
$sql .= " menu_item_protected <> 'true' "; $sql .= " menu_item_protected <> 'true' ";
$sql .= " or menu_item_protected is null "; $sql .= " or menu_item_protected is null ";
$sql .= " ) "; $sql .= " ) ";
$sql .= ");"; $sql .= ") ";
$db->exec(check_sql($sql)); $parameters['menu_uuid'] = $this->menu_uuid;
$database = new database;
$database->execute($sql, $parameters);
unset($sql, $parameters);
//remove existing unprotected menu item groups //remove existing unprotected menu item groups
$sql = "delete from v_menu_item_groups "; $sql = "delete from v_menu_item_groups ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' "; $sql .= "where menu_uuid = :menu_uuid ";
$sql .= "and menu_item_uuid in ( "; $sql .= "and menu_item_uuid in ( ";
$sql .= " select menu_item_uuid "; $sql .= " select menu_item_uuid ";
$sql .= " from v_menu_items "; $sql .= " from v_menu_items ";
$sql .= " where menu_uuid = '".$this->menu_uuid."' "; $sql .= " where menu_uuid = :menu_uuid ";
$sql .= " and ( "; $sql .= " and ( ";
$sql .= " menu_item_protected <> 'true' "; $sql .= " menu_item_protected <> 'true' ";
$sql .= " or menu_item_protected is null "; $sql .= " or menu_item_protected is null ";
$sql .= " ) "; $sql .= " ) ";
$sql .= ");"; $sql .= ") ";
$db->exec(check_sql($sql)); $parameters['menu_uuid'] = $this->menu_uuid;
$database = new database;
$database->execute($sql, $parameters);
unset($sql, $parameters);
//remove existing unprotected menu items //remove existing unprotected menu items
$sql = "delete from v_menu_items "; $sql = "delete from v_menu_items ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' "; $sql .= "where menu_uuid = :menu_uuid ";
$sql .= "and (menu_item_protected <> 'true' "; $sql .= "and (menu_item_protected <> 'true' ";
$sql .= "or menu_item_protected is null);"; $sql .= "or menu_item_protected is null) ";
$db->exec(check_sql($sql)); $parameters['menu_uuid'] = $this->menu_uuid;
$database = new database;
$database->execute($sql, $parameters);
unset($sql, $parameters);
} }
//restore the menu //restore the menu
public function restore() { public function restore() {
//set the variables
$db = $this->db;
//get the $apps array from the installed apps from the core and mod directories //get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php"); $config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php");
$x = 0; $x = 0;
@@ -95,16 +99,12 @@ if (!class_exists('menu')) {
} }
} }
//begin the transaction
if ($db_type == "sqlite") {
$db->beginTransaction();
}
//get the list of languages //get the list of languages
$language = new text; $language = new text;
//use the app array to restore the default menu //use the app array to restore the default menu
if (is_array($apps)) { if (is_array($apps)) {
$x = 0;
foreach ($apps as $row) { foreach ($apps as $row) {
if (is_array($row['menu'])) { if (is_array($row['menu'])) {
foreach ($row['menu'] as $menu) { foreach ($row['menu'] as $menu) {
@@ -127,93 +127,74 @@ if (!class_exists('menu')) {
$menu_item_exists = true; $menu_item_exists = true;
//if the item uuid is not currently in the db then add it //if the item uuid is not currently in the db then add it
$sql = "select * from v_menu_items "; $sql = "select count(*) from v_menu_items ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' "; $sql .= "where menu_uuid = :menu_uuid ";
$sql .= "and menu_item_uuid = '".$menu_item_uuid."' "; $sql .= "and menu_item_uuid = :menu_item_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['menu_uuid'] = $this->menu_uuid;
if ($prep_statement) { $parameters['menu_item_uuid'] = $menu_item_uuid;
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); $num_rows = $database->select($sql, $parameters, 'column');
if (count($result) == 0) { if ($num_rows == 0) {
//menu found the menu
$menu_item_exists = false;
//menu found the menu if ($menu_item_uuid != $menu_item_parent_uuid) {
$menu_item_exists = false; //build insert array
$array['menu_items'][$x]['menu_item_uuid'] = $menu_item_uuid;
//insert the default menu into the database $array['menu_items'][$x]['menu_uuid'] = $this->menu_uuid;
$sql = "insert into v_menu_items "; $array['menu_items'][$x]['menu_item_title'] = $menu_item_title;
$sql .= "("; $array['menu_items'][$x]['menu_item_link'] = $menu_item_path;
$sql .= "menu_item_uuid, "; $array['menu_items'][$x]['menu_item_category'] = $menu_item_category;
$sql .= "menu_uuid, "; $array['menu_items'][$x]['menu_item_icon'] = $menu_item_icon;
$sql .= "menu_item_title, ";
$sql .= "menu_item_link, ";
$sql .= "menu_item_category, ";
$sql .= "menu_item_icon, ";
if (strlen($menu_item_order) > 0) { if (strlen($menu_item_order) > 0) {
$sql .= "menu_item_order, "; $array['menu_items'][$x]['menu_item_order'] = $menu_item_order;
} }
if (strlen($menu_item_parent_uuid) > 0) { if (is_uuid($menu_item_parent_uuid)) {
$sql .= "menu_item_parent_uuid, "; $array['menu_items'][$x]['menu_item_parent_uuid'] = $menu_item_parent_uuid;
} }
$sql .= "menu_item_description "; $array['menu_items'][$x]['menu_item_description'] = $menu_item_description;
$sql .= ") "; $x++;
$sql .= "values ";
$sql .= "(";
$sql .= "'".$menu_item_uuid."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".check_str($menu_item_title)."', ";
$sql .= "'$menu_item_path', ";
$sql .= "'$menu_item_category', ";
$sql .= "'$menu_item_icon', ";
if (strlen($menu_item_order) > 0) {
$sql .= "'$menu_item_order', ";
}
if (strlen($menu_item_parent_uuid) > 0) {
$sql .= "'$menu_item_parent_uuid', ";
}
$sql .= "'$menu_item_description' ";
$sql .= ")";
if ($menu_item_uuid == $menu_item_parent_uuid) {
//echo $sql."<br />\n";
}
else {
$db->exec(check_sql($sql));
}
unset($sql);
} }
} }
unset($sql, $parameters, $num_rows);
//set the menu languages //set the menu languages
if (!$menu_item_exists and is_array($language->languages)) { if (!$menu_item_exists && is_array($language->languages)) {
foreach ($language->languages as $menu_language) { foreach ($language->languages as $menu_language) {
$menu_item_title = $menu["title"][$menu_language]; $menu_item_title = $menu["title"][$menu_language];
if(strlen($menu_item_title) == 0) { if (strlen($menu_item_title) == 0) {
$menu_item_title = $menu["title"]['en-us']; $menu_item_title = $menu["title"]['en-us'];
} }
$menu_language_uuid = uuid(); $menu_language_uuid = uuid();
$sql = "insert into v_menu_languages "; //build insert array
$sql .= "("; $array['menu_languages'][$x]['menu_language_uuid'] = $menu_language_uuid;
$sql .= "menu_language_uuid, "; $array['menu_languages'][$x]['menu_item_uuid'] = $menu_item_uuid;
$sql .= "menu_item_uuid, "; $array['menu_languages'][$x]['menu_uuid'] = $this->menu_uuid;
$sql .= "menu_uuid, "; $array['menu_languages'][$x]['menu_language'] = $menu_language;
$sql .= "menu_language, "; $array['menu_languages'][$x]['menu_item_title'] = $menu_item_title;
$sql .= "menu_item_title "; $x++;
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$menu_language_uuid."', ";
$sql .= "'".$menu_item_uuid."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$menu_language."', ";
$sql .= "'".check_str($menu_item_title)."' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
} }
} }
} }
} }
} }
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('menu_item_add', 'temp');
$p->add('menu_language_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'menu';
$database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('menu_item_add', 'temp');
$p->delete('menu_language_add', 'temp');
}
} }
//make sure the default user groups exist //make sure the default user groups exist
@@ -223,71 +204,69 @@ if (!class_exists('menu')) {
//get default global group_uuids //get default global group_uuids
$sql = "select group_uuid, group_name from v_groups "; $sql = "select group_uuid, group_name from v_groups ";
$sql .= "where domain_uuid is null "; $sql .= "where domain_uuid is null ";
$prep_statement = $db->prepare(check_sql($sql)); $database = new database;
$prep_statement->execute(); $result = $database->select($sql, null, 'all');
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (is_array($result) && @sizeof($result) != 0) {
if (is_array($result)) {
foreach ($result as $row) { foreach ($result as $row) {
$group_uuids[$row['group_name']] = $row['group_uuid']; $group_uuids[$row['group_name']] = $row['group_uuid'];
} }
} }
unset($sql, $prep_statement, $result); unset($sql, $result, $row);
//if there are no groups listed in v_menu_item_groups under menu_item_uuid then add the default groups //if there are no groups listed in v_menu_item_groups under menu_item_uuid then add the default groups
if (is_array($apps)) { if (is_array($apps)) {
$x = 0;
foreach($apps as $app) { foreach($apps as $app) {
if (is_array($apps)) { if (is_array($apps)) {
foreach ($app['menu'] as $sub_row) { foreach ($app['menu'] as $sub_row) {
if (isset($sub_row['groups'])) foreach ($sub_row['groups'] as $group) { if (isset($sub_row['groups'])) {
$sql = "select count(*) as count from v_menu_item_groups "; foreach ($sub_row['groups'] as $group) {
$sql .= "where menu_item_uuid = '".$sub_row['uuid']."' "; $sql = "select count(*) from v_menu_item_groups ";
$sql .= "and menu_uuid = '".$this->menu_uuid."' "; $sql .= "where menu_item_uuid = :menu_item_uuid ";
$sql .= "and group_name = '".$group."' "; $sql .= "and menu_uuid = :menu_uuid ";
$sql .= "and group_uuid = '".$group_uuids[$group]."' "; $sql .= "and group_name = :group_name ";
//echo $sql."<br>"; $sql .= "and group_uuid = :group_uuid ";
$prep_statement = $db->prepare($sql); $parameters['menu_item_uuid'] = $sub_row['uuid'];
$prep_statement->execute(); $parameters['menu_uuid'] = $this->menu_uuid;
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); $parameters['group_name'] = $group;
unset ($prep_statement); $parameters['group_uuid'] = $group_uuids[$group];
if ($sub_result['count'] == 0) { $database = new database;
//no menu item groups found add the defaults $num_rows = $database->select($sql, $parameters, 'column');
$sql = "insert into v_menu_item_groups "; if ($num_rows == 0) {
$sql .= "( "; //no menu item groups found, build insert array for defaults
$sql .= "menu_item_group_uuid, "; $array['menu_item_groups'][$x]['menu_item_group_uuid'] = uuid();
$sql .= "menu_uuid, "; $array['menu_item_groups'][$x]['menu_uuid'] = $this->menu_uuid;
$sql .= "menu_item_uuid, "; $array['menu_item_groups'][$x]['menu_item_uuid'] = $sub_row['uuid'];
$sql .= "group_name, "; $array['menu_item_groups'][$x]['group_name'] = $group;
$sql .= "group_uuid "; $array['menu_item_groups'][$x]['group_uuid'] = $group_uuids[$group];
$sql .= ") "; $x++;
$sql .= "values "; }
$sql .= "( "; unset($sql, $parameters, $num_rows);
$sql .= "'".uuid()."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$sub_row['uuid']."', ";
$sql .= "'".$group."', ";
$sql .= "'".$group_uuids[$group]."' ";
$sql .= ") ";
//echo $sql."<br>";
$db->exec(check_sql($sql));
unset($sql);
} }
} }
} }
} }
} }
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('menu_item_group_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'menu';
$database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('menu_item_group_add', 'temp');
}
} }
//commit the transaction }
if ($db_type == "sqlite") {
$db->commit();
}
} //end function
//create the menu //create the menu
public function build_html($menu_item_level = 0) { public function build_html($menu_item_level = 0) {
$db = $this->db;
$menu_html_full = ''; $menu_html_full = '';
$menu_array = $this->menu_array(); $menu_array = $this->menu_array();
@@ -361,7 +340,7 @@ if (!class_exists('menu')) {
} }
return $menu_html_full; return $menu_html_full;
} //end function }
//create the sub menus //create the sub menus
private function build_child_html($menu_item_level, $submenu_array) { private function build_child_html($menu_item_level, $submenu_array) {
@@ -425,16 +404,10 @@ if (!class_exists('menu')) {
return $submenu_html; return $submenu_html;
} }
} //end function }
//create the menu array //create the menu array
public function menu_array($sql = '', $menu_item_level = 0) { public function menu_array($menu_item_level = 0) {
//get the database connnection
$db = $this->db;
//database object does not exist return immediately
if (!$db) { return Array(); }
//if there are no groups then set the public group //if there are no groups then set the public group
if (!isset($_SESSION['groups'][0]['group_name'])) { if (!isset($_SESSION['groups'][0]['group_name'])) {
@@ -442,42 +415,44 @@ if (!class_exists('menu')) {
} }
//get the menu from the database //get the menu from the database
if (strlen($sql) == 0) { $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, ".
$sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, ". $sql .= "i.menu_item_title, i.menu_item_protected, i.menu_item_category, ";
$sql .= "i.menu_item_title, i.menu_item_protected, i.menu_item_category, "; $sql .= "i.menu_item_icon, i.menu_item_uuid, i.menu_item_parent_uuid ";
$sql .= "i.menu_item_icon, i.menu_item_uuid, i.menu_item_parent_uuid "; $sql .= "from v_menu_items as i, v_menu_languages as l ";
$sql .= "from v_menu_items as i, v_menu_languages as l "; $sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
$sql .= "where i.menu_item_uuid = l.menu_item_uuid "; $sql .= "and l.menu_language = :menu_language ";
$sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' "; $sql .= "and l.menu_uuid = :menu_uuid ";
$sql .= "and l.menu_uuid = '".$this->menu_uuid."' "; $sql .= "and i.menu_uuid = :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 is null "; $sql .= "and i.menu_item_uuid in ";
$sql .= "and i.menu_item_uuid in "; $sql .= "( ";
$sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' "; $sql .= "select menu_item_uuid ";
$sql .= "and ( "; $sql .= "from v_menu_item_groups ";
$x = 0; $sql .= "where menu_uuid = :menu_uuid ";
foreach($_SESSION['groups'] as $row) { $x = 0;
if ($x == 0) { foreach($_SESSION['groups'] as $row) {
$sql .= "group_name = '".$row['group_name']."' "; $sql_where_or[] = "group_name = :group_name_".$x;
} $parameters['group_name_'.$x] = $row['group_name'];
else { $x++;
$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)); if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
$prep_statement->execute(); $sql .= "and ( ";
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $sql .= implode(' or ', $sql_where_or);
$sql .= ") ";
}
$sql .= "and menu_item_uuid is not null ";
$sql .= ") ";
$sql .= "order by i.menu_item_order asc ";
$parameters['menu_language'] = $_SESSION['domain']['language']['code'];
$parameters['menu_uuid'] = $this->menu_uuid;
$database = new database;
$result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//save the menu into an array //save the menu into an array
$x = 0; $x = 0;
$a = Array(); $a = Array();
if (is_array($result)) { if (is_array($result) && @sizeof($result) != 0) {
foreach($result as $row) { foreach($result as $row) {
//add the row to the array //add the row to the array
$a[$x] = $row; $a[$x] = $row;
@@ -490,27 +465,19 @@ if (!class_exists('menu')) {
//increment the row number //increment the row number
$x++; $x++;
} //end for each }
} }
unset($result, $row);
//unset the variables
unset($prep_statement, $sql, $result);
//return the array //return the array
return $a; return $a;
} //end function }
//create the sub menus //create the sub menus
private function menu_child_array($menu_item_level, $menu_item_uuid) { private function menu_child_array($menu_item_level, $menu_item_uuid) {
//get the database connnection
$db = $this->db;
//database ojbect does not exist return immediately
if (!$db) { return; }
//set the level //set the level
$menu_item_level = $menu_item_level+1; $menu_item_level = $menu_item_level + 1;
//if there are no groups then set the public group //if there are no groups then set the public group
if (!isset($_SESSION['groups'][0]['group_name'])) { if (!isset($_SESSION['groups'][0]['group_name'])) {
@@ -521,32 +488,39 @@ if (!class_exists('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_icon, i.menu_item_uuid, i.menu_item_parent_uuid "; $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_icon, i.menu_item_uuid, i.menu_item_parent_uuid ";
$sql .= "from v_menu_items as i, v_menu_languages as l "; $sql .= "from v_menu_items as i, v_menu_languages as l ";
$sql .= "where i.menu_item_uuid = l.menu_item_uuid "; $sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
$sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' "; $sql .= "and l.menu_language = :menu_language ";
$sql .= "and l.menu_uuid = '".$this->menu_uuid."' "; $sql .= "and l.menu_uuid = :menu_uuid ";
$sql .= "and i.menu_uuid = '".$this->menu_uuid."' "; $sql .= "and i.menu_uuid = :menu_uuid ";
$sql .= "and i.menu_item_parent_uuid = '$menu_item_uuid' "; $sql .= "and i.menu_item_parent_uuid = :menu_item_parent_uuid ";
$sql .= "and i.menu_item_uuid in "; $sql .= "and i.menu_item_uuid in ";
$sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' "; $sql .= "( ";
$sql .= "and ( "; $sql .= "select menu_item_uuid ";
$sql .= "from v_menu_item_groups ";
$sql .= "where menu_uuid = :menu_uuid ";
$x = 0; $x = 0;
foreach($_SESSION['groups'] as $row) { foreach($_SESSION['groups'] as $row) {
if ($x == 0) { $sql_where_or[] = "group_name = :group_name_".$x;
$sql .= "group_name = '".$row['group_name']."' "; $parameters['group_name_'.$x] = $row['group_name'];
}
else {
$sql .= "or group_name = '".$row['group_name']."' ";
}
$x++; $x++;
} }
$sql .= ") "; if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
$sql .= "and ( ";
$sql .= implode(' or ', $sql_where_or);
$sql .= ") ";
}
$sql .= ") "; $sql .= ") ";
$sql .= "order by l.menu_item_title, i.menu_item_order asc "; $sql .= "order by l.menu_item_title, i.menu_item_order asc ";
$sub_prep_statement = $db->prepare($sql); $parameters['menu_language'] = $_SESSION['domain']['language']['code'];
$sub_prep_statement->execute(); $parameters['menu_uuid'] = $this->menu_uuid;
$sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED); $parameters['menu_item_parent_uuid'] = $menu_item_uuid;
$database = new database;
$sub_result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//save the child menu into an array //save the child menu into an array
if (is_array($sub_result)) { $x = 0;
$a = Array();
if (is_array($sub_result) && @sizeof($sub_result) != 0) {
foreach($sub_result as $row) { foreach($sub_result as $row) {
//set the variables //set the variables
$menu_item_link = $row['menu_item_link']; $menu_item_link = $row['menu_item_link'];
@@ -569,17 +543,17 @@ if (!class_exists('menu')) {
//get sub menu for children //get sub menu for children
if (strlen($menu_item_uuid) > 0) { if (strlen($menu_item_uuid) > 0) {
$a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid); $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid);
//$str_child_menu =
} }
//increment the row //increment the row
$x++; $x++;
} }
unset($sql, $sub_result);
return $a;
} }
unset($sub_prep_statement, $sql); unset($sub_result, $row);
} //end function
//return the array
return $a;
}
//add the default menu when no menu exists //add the default menu when no menu exists
public function menu_default() { public function menu_default() {
@@ -587,38 +561,36 @@ if (!class_exists('menu')) {
$this->menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286'; $this->menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
//check to see if any menu exists //check to see if any menu exists
$sql = "select count(*) as count from v_menus "; $sql = "select count(*) as count from v_menus ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' "; $sql .= "where menu_uuid = :menu_uuid ";
$prep_statement = $this->db->prepare(check_sql($sql)); $parameters['menu_uuid'] = $this->menu_uuid;
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetch(PDO::FETCH_NAMED); $num_rows = $database->select($sql, $parameters, 'column');
unset($sql, $prep_statement); if ($num_rows == 0) {
if ($result['count'] == 0) { //built insert array
//set the menu variables $array['menus'][0]['menu_uuid'] = $this->menu_uuid;
$menu_name = 'default'; $array['menus'][0]['menu_name'] = 'default';
$menu_language = 'en-us'; $array['menus'][0]['menu_language'] = 'en-us';
$menu_description = 'Default Menu'; $array['menus'][0]['menu_description'] = 'Default Menu';
//add the menu //grant temporary permissions
$sql = "insert into v_menus "; $p = new permissions;
$sql .= "("; $p->add('menu_add', 'temp');
$sql .= "menu_uuid, ";
$sql .= "menu_name, "; //execute insert
$sql .= "menu_language, "; $database = new database;
$sql .= "menu_description "; $database->app_name = 'menu';
$sql .= ") "; $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$sql .= "values "; $database->save($array);
$sql .= "("; unset($array);
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'$menu_name', "; //revoke temporary permissions
$sql .= "'$menu_language', "; $p->delete('menu_add', 'temp');
$sql .= "'$menu_description' ";
$sql .= ");";
$this->db->exec($sql);
//add the menu items //add the menu items
$this->restore(); $this->restore();
} }
} //end function unset($sql, $parameters, $result, $row);
}
} }
} }