<? include_once("../settings.inc.php");
include_once("../db_fns.php");
/*
* Global functions for alarisMenu
*/
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Authorization functions #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Check valid user #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function check_valid_user()
# check if somebody is logged in and nofity them if not
{
global $valid_user;
if(session_is_registered("valid_user"))
{
return 1;
}
else{
# they are not logged in
display_header("Problem");
start_main_table();
echo "<br><b>! You are not authorized to enter here - Please login first !</b><br>";
do_url("login.php","Login here");
echo "<br>";
end_main_table();
display_footer();
exit;
}
}
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# HTML output functions #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Login form for validation #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function display_login_form()
{
?>
<form method="post" action="validate_user.php">
<table>
<tr>
<td colspan=2>Please login here:</td>
</tr>
<tr>
<td>Username:</td>
<td><input class="textfield" type="text" name="username"></td></tr>
</tr>
<tr>
<td>Password:</td>
<td><input class="textfield" type="password" name="password"></td></tr>
</tr>
<tr>
<td colspan=2 align="right">
<input class="button" type=submit value="Log in"></td></tr>
</tr>
</table></form>
<?
}
# Display admin header #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function display_header($title){
global $DOCUMENT_ROOT;
?>
<!--
*********************************
* \copyright Alaris Consulting\ *
*********************************
* Design and programming by *
* Rasmus L. Petersen @ *
* http://www.alaris.dk *
* All rights reserved *
*********************************
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>alarisMenu : <?=$title?></title>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="author" content="Rasmus Petersen @ www.alaris.dk">
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" href="./admin_style.css">
</head>
<body bgcolor="#cccc99" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?
}
# End the main table of the content #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function end_main_table(){
global $DOCUMENT_ROOT, $version;
?>
</td>
<td bgcolor="#999966"> </td>
<td align=center valign=bottom> </td>
</tr>
</table>
<table border="0" align="center">
<tr>
<td class="text">You are using AlarisMenu © version <?echo $version; ?> - For updates please visit <a class="menu" target="_blank" href="http://www.alaris.dk">www.alaris.dk</a></td>
</tr>
</table>
<?
}
# Display the footer #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function display_footer(){
?>
</center>
</body>
</html>
<?
}
# Display the start of the main table with navigation #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function start_main_table(){
global $valid_user;
?>
<center>
<table bgcolor="#cccc99" border=1 width="100%" cellspacing=0 cellpadding=0 bordercolordark="#cccc99" bordercolorlight="#999966" bordercolor="#999966">
<tr height=10>
<td> </td>
<td> </td>
<td valign=top height=10> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="400"> </td>
<td> </td>
<td bgcolor="#ffffff" width="760" align=center height="75">
<table border=0 bgcolor="#ffffff" width="750" height="90%" cellspacing=5 cellpadding=0>
<tr>
<td align="right"><img src="./powered_by.gif" height="45" width="120"></td>
</tr>
</table>
</td>
<td> </td>
<td width="400"> </td>
</tr>
<tr height="10">
<td> </td>
<td> </td>
<td valign="top" height="10">
<?
if(session_is_registered("valid_user")){?>
<a class="menu" href="alarisAdmin.php"><span>Home</span></a>
<a class="menu" href="alarisAdmin.php?view=menu"><span>Edit Menu</span></a>
<a class="menu" href="alarisAdmin.php?view=users"><span>Edit Users</span></a>
<? }else{
echo " ";
}?>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td bgcolor="#999966"> </td>
<td bgcolor="#ffffff" width="760" align="center" valign="top">
<?
}
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Database functions #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Get entries into select structure #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function query_select($name, $query, $default="")
{
db_connect();
$result = mysql_query($query);
if (!$result)
return(0);
$select = "<SELECT NAME=\"$name\">";
$select .= "<OPTION VALUE=\"\">-- Choose parent --</OPTION>";
for ($i=0; $i < mysql_num_rows($result); $i++) {
$opt_code = mysql_result($result, $i, 0);
$opt_desc = mysql_result($result, $i, 1);
$select .= "<OPTION VALUE=\"$opt_code\"";
if ($opt_code == $default) {
$select .= " SELECTED";
}
$select .= ">[$opt_code] $opt_desc</OPTION>";
}
$select .= "</SELECT>\n";
return($select);
db_close();
}
# Get the entries in the submenus #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function get_submenu($edit_sub){
global $result;
$query = "SELECT sub_id, parent_id as sub_parent_id, title_sub, url_sub, target_sub FROM alaris_sub_menu WHERE sub_id=$edit_sub";
db_connect();
$result = sql_ask_and_answer($query);
db_close();
return $result[0];
}
# Get the entries in the menus #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function get_menu($edit){
global $result;
$query = "SELECT parent_id, title, width, url, target FROM alaris_menu WHERE parent_id=$edit";
db_connect();
$result = sql_ask_and_answer($query);
db_close();
return $result[0];
}
# Get user info #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function get_user($edit){
global $result;
$query = "SELECT * FROM alaris_users WHERE user_id=$edit";
db_connect();
$result = sql_ask_and_answer($query);
db_close();
return $result[0];
}
# Common sql queries #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function sql_ask_and_answer($query) {
$result = mysql_query($query);
if(!$result) {
write_error("Could not complete: <em>$query</em>");
}
$result_array = array();
while($raekke = mysql_fetch_array($result)) {
$result_array[] = $raekke;
}
return $result_array;
}
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Additional functions #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
# Check submission of database queries #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function confirm_submit()
# Check if the user is ok with changing the database
{
?>
<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("You are about to edit the database! Do you wish to continue?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>
<?
}
# Output URL #
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #
function do_url($url, $name)
{
// output URL as link and br
?>
<br><a href="<?=$url?>"><?=$name?></a><br>
<?
}
?>