Additional work to improve the install, template and the menu.

This commit is contained in:
markjcrane 2016-03-26 12:22:15 -06:00
parent 0e649f9020
commit ba095f3852
5 changed files with 157 additions and 151 deletions

View File

@ -124,12 +124,6 @@
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//set a default template
$default_template = 'default';
if (isset($_SESSION['domain']['template']['name']) and strlen($_SESSION['domain']['template']['name']) != 0) {
$default_template = $_SESSION['domain']['template']['name'];
}
//set a default enviroment if first_time //set a default enviroment if first_time
//initialize some varibles to cut down on warnings //initialize some varibles to cut down on warnings
$_SESSION['message'] = ''; $_SESSION['message'] = '';
@ -138,9 +132,6 @@
$default_login = 0; $default_login = 0;
$onload = ''; $onload = '';
//get the contents of the template and save it to the template variable
$template = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$default_template.'/template.php');
//buffer the content //buffer the content
ob_end_clean(); //clean the buffer ob_end_clean(); //clean the buffer
ob_start(); ob_start();
@ -215,7 +206,7 @@
echo " <input type='hidden' name='return_install_step' value='select_language'/>\n"; echo " <input type='hidden' name='return_install_step' value='select_language'/>\n";
echo " <input type='hidden' name='install_step' value='detect_config'/>\n"; echo " <input type='hidden' name='install_step' value='detect_config'/>\n";
echo " <div style='text-align:right'>\n"; echo " <div style='text-align:right'>\n";
echo " <button type='submit' id='next'>".$text['button-next']."</button>\n"; echo " <button type='submit' class='btn' id='next'>".$text['button-next']."</button>\n";
echo " </div>\n"; echo " </div>\n";
echo "</form>\n"; echo "</form>\n";
} elseif($install_step == 'detect_config'){ } elseif($install_step == 'detect_config'){
@ -232,14 +223,14 @@
echo " <input type='hidden' name='event_port' value='$event_port'/>\n"; echo " <input type='hidden' name='event_port' value='$event_port'/>\n";
echo " <input type='hidden' name='event_password' value='$event_password'/>\n"; echo " <input type='hidden' name='event_password' value='$event_password'/>\n";
echo " <div style='text-align:right'>\n"; echo " <div style='text-align:right'>\n";
echo " <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n"; echo " <button type='button' class='btn' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
echo " <button type='submit' id='next'>".$text['button-next']."</button>\n"; echo " <button type='submit' class='btn' id='next'>".$text['button-next']."</button>\n";
echo " </div>\n"; echo " </div>\n";
echo "</form>\n"; echo "</form>\n";
} else { } else {
echo "<form method='post' name='frm' action=''>\n"; echo "<form method='post' name='frm' action=''>\n";
echo " <div style='text-align:right'>\n"; echo " <div style='text-align:right'>\n";
echo " <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n"; echo " <button type='button' class='btn' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
echo " </div>\n"; echo " </div>\n";
echo "</form>\n"; echo "</form>\n";
} }
@ -329,8 +320,8 @@
}else { }else {
echo "<form method='post' name='frm' action=''>\n"; echo "<form method='post' name='frm' action=''>\n";
echo " <div style='text-align:right'>\n"; echo " <div style='text-align:right'>\n";
echo " <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n"; echo " <button type='button' class='btn' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
echo " <button type='button' onclick=\"location.reload(true);\">".$text['button-execute']."</button>\n"; echo " <button type='button' class='btn' onclick=\"location.reload(true);\">".$text['button-execute']."</button>\n";
echo " </div>\n"; echo " </div>\n";
echo "</form>\n"; echo "</form>\n";
} }
@ -340,44 +331,47 @@
echo "<p>Unkown install_step '$install_step'</p>\n"; echo "<p>Unkown install_step '$install_step'</p>\n";
} }
//get the default theme
$set_session_theme = 1;
$domains_processed = 1;
include "themes/".$default_template."/template.php";
unset($set_session_theme, $domains_processed);
//initialize some defaults so we can be 'logged in' //initialize some defaults so we can be 'logged in'
//$_SESSION['username'] = 'install_enabled'; //$_SESSION['username'] = 'install_enabled';
//$_SESSION['permissions'][]['permission_name'] = 'superadmin'; //$_SESSION['permissions'][]['permission_name'] = 'superadmin';
//$_SESSION['menu'] = ''; //$_SESSION['menu'] = '';
//show errors
ini_set('display_errors', '1');
//error_reporting (E_ALL); // Report everything
//error_reporting (E_ALL ^ E_NOTICE); // Report everything
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings
//add the content to the template and then send output //add the content to the template and then send output
$body = ob_get_contents(); //get the output from the buffer $body = ob_get_contents(); //get the output from the buffer
ob_end_clean(); //clean the buffer ob_end_clean(); //clean the buffer
//replace known used constants //set a default template
$body = str_replace ("<!--{project_path}-->", PROJECT_PATH, $body); //defined in /resources/menu.php $default_template = 'default';
$_SESSION['domain']['template']['name'] = $default_template;
//set the default template path
$template_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$default_template.'/template.php';
//get the content of the template
$template_content = file_get_contents($template_path);
//replace the variables in the template
$template_content = str_replace ("<!--{title}-->", $document['title'], $template_content); //<!--{title}--> defined in each individual page
$template_content = str_replace ("<!--{head}-->", '', $template_content); //<!--{head}--> defined in each individual page
//$template_content = str_replace ("<!--{menu}-->", $_SESSION["menu"], $template_content); //included in the theme
$template_content = str_replace ("<!--{body}-->", $body, $template_content); //defined in /themes/default/template.php
$template_content = str_replace ("<!--{project_path}-->", PROJECT_PATH, $template_content); //defined in /themes/default/template.php
//get the contents of the template and save it to the template variable
ob_start(); ob_start();
eval('?>' . $template . '<?php '); require_once "resources/classes/menu.php";
$template = ob_get_contents(); //get the output from the buffer eval('?>' . $template_content . '<?php ');
$content = ob_get_contents(); //get the output from the buffer
ob_end_clean(); //clean the buffer ob_end_clean(); //clean the buffer
//echo $content;
$custom_head = ''; //send the content to the browser and then clear the variable
$output = str_replace ("<!--{title}-->", $document['title'], $template); //<!--{title}--> defined in each individual page echo $content;
$output = str_replace ("<!--{head}-->", $custom_head, $output); //<!--{head}--> defined in each individual page
$output = str_replace ("<!--{menu}-->", $_SESSION["menu"], $output); //defined in /resources/menu.php
$output = str_replace ("<!--{project_path}-->", PROJECT_PATH, $output); //defined in /resources/menu.php
$pos = strrpos($output, "<!--{body}-->");
if ($pos === false) {
$output = $body; //if tag not found just show the body
}
else {
//replace the body
$output = str_replace ("<!--{body}-->", $body, $output);
}
echo $output;
unset($output);
?> ?>

View File

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

View File

@ -61,7 +61,7 @@ require_once "resources/require.php";
} }
} }
//start the output buffer //get the template
ob_start(); ob_start();
$template = $_SESSION["template_content"]; $template = $_SESSION["template_content"];
eval('?>' . $template . '<?php '); eval('?>' . $template . '<?php ');

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012 Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):

View File

@ -1717,7 +1717,7 @@
<td width='100%' style='padding-right: 15px;' align='right' valign='middle'> <td width='100%' style='padding-right: 15px;' align='right' valign='middle'>
<?php <?php
// login form // login form
if ($_SERVER['PHP_SELF'] != PROJECT_PATH."/resources/install.php" && !$default_login) { if ($_SERVER['PHP_SELF'] != PROJECT_PATH."/core/install/install.php" && !$default_login) {
if (strlen($_SESSION["username"]) == 0) { if (strlen($_SESSION["username"]) == 0) {
//add multi-lingual support //add multi-lingual support
require_once "core/user_settings/app_languages.php"; require_once "core/user_settings/app_languages.php";