Bug &
Posted: Wed May 23, 2012 3:11 am
Hi
Bug &
I need help to fix a bug that causes a repetition of & in links.
The links are added via admin area and the site used MYSql database.
Link should be: http://www.mycompany.com/?page=contact- ... iry=Locate but its renderd as http://www.mycompany.com/?page=contact- ... iry=Locate and the ;amp increases when i update the links
Please help to fix this, i'm not advance in PHP.
Thanks
Code attached.
Bug &
I need help to fix a bug that causes a repetition of & in links.
The links are added via admin area and the site used MYSql database.
Link should be: http://www.mycompany.com/?page=contact- ... iry=Locate but its renderd as http://www.mycompany.com/?page=contact- ... iry=Locate and the ;amp increases when i update the links
Please help to fix this, i'm not advance in PHP.
Thanks
Code attached.
Code: Select all
<?php
class Divisions{
function Divisions(){
global $body;
$msg = '';
$VarSecurity = new VarSecurity();
if(isset($_POST['division_id'])) $_POST['division_id'] = $VarSecurity->Security($_POST['division_id']);
if(isset($_POST['weight'])) $_POST['weight'] = $VarSecurity->Security($_POST['weight']);
if(isset($_POST['create'])) $_POST['create'] = $VarSecurity->Security($_POST['create']);
if(isset($_GET['id'])) $_GET['id'] = $VarSecurity->Security($_GET['id']);
if(isset($_POST['delete'])) $_POST['delete'] = $VarSecurity->Security($_POST['delete']);
if(isset($_GET['tblid'])) $_GET['tblid'] = $VarSecurity->Security($_GET['tblid']);
if(isset($_POST['blurb'])) $_POST['blurb'] = $VarSecurity->Security($_POST['blurb']);
if(isset($_POST['article'])) $_POST['article'] = $VarSecurity->Security($_POST['article']);
if(isset($_POST['date_order'])) $_POST['date_order'] = $VarSecurity->Security($_POST['date_order']);
if(isset($_POST['date_down'])) $_POST['date_down'] = $VarSecurity->Security($_POST['date_down']);
if(isset($_POST['title'])) $_POST['title'] = $VarSecurity->Security($_POST['title']);
if(isset($_POST['image_href'])) $_POST['image_href'] = $VarSecurity->Security($_POST['image_href']);
if(isset($_POST['image_over_href'])) $_POST['image_over_href'] = $VarSecurity->Security($_POST['image_over_href']);
if(isset($_POST['display_price'])) $_POST['display_price'] = $VarSecurity->Security($_POST['display_price']);
if(isset($_POST['display_cat_price_no'])) $_POST['display_cat_price_no'] = $VarSecurity->Security($_POST['display_cat_price_no']);
if(isset($_POST['incl_group'])) $_POST['incl_group'] = $VarSecurity->Security($_POST['incl_group']);
if(isset($_POST['home_divs'])) $_POST['home_divs'] = $VarSecurity->Security($_POST['home_divs']);
if(isset($_POST['mainmenu'])) $_POST['mainmenu'] = $VarSecurity->Security($_POST['mainmenu']);
if(isset($_POST['mainmenu_new'])) $_POST['mainmenu_new'] = $VarSecurity->Security($_POST['mainmenu_new']);
if(isset($_POST['id'])) $_POST['id'] = $VarSecurity->Security($_POST['id']);
if(isset($_POST['deletemenu'])) $_POST['deletemenu'] = $VarSecurity->Security($_POST['deletemenu']);
if(isset($_POST['updatehomephp'])) $_POST['updatehomephp'] = $VarSecurity->Security($_POST['updatehomephp']);
if(isset($_POST['updatemenus'])) $_POST['updatemenus'] = $VarSecurity->Security($_POST['updatemenus']);
if(isset($_POST['display_divs'])) $_POST['display_divs'] = $VarSecurity->Security($_POST['display_divs']);
if(isset($_POST['menu_session'])) $_POST['menu_session'] = $VarSecurity->Security($_POST['menu_session']);
if(isset($_POST['option_val'])) $_POST['option_val'] = $VarSecurity->Security($_POST['option_val']);
if(isset($_POST['menu_parent'])) $_POST['menu_parent'] = $VarSecurity->Security($_POST['menu_parent']);
if(isset($_POST['menu_link'])) $_POST['menu_link'] = $VarSecurity->Security($_POST['menu_link']);
if(isset($_POST['type'])) $_POST['type'] = $VarSecurity->Security($_POST['type']);
if(isset($_POST['updatesitemap'])) $_POST['updatesitemap'] = $VarSecurity->Security($_POST['updatesitemap']);
if(isset($_POST['updatesitemap'])) $_POST['updatesitemap'] = $VarSecurity->Security($_POST['updatesitemap']);
if(isset($_POST['updatesitemap'])) $_POST['updatesitemap'] = $VarSecurity->Security($_POST['updatesitemap']);
if(isset($_POST['create'])){
if(!empty($_POST['division_id'])){
$msg = $this->Save();
$this->Show($msg);
}
} elseif(isset($_POST['delete'])){
if(isset($_POST['division_id'])){
$msg = $this->Delete($_POST['division_id']);
$this->Show($msg);
}
}elseif(isset($_POST['update'])){
if(isset($_POST['division_id'])){
$msg = $this->Update($_POST['division_id']);
$this->Show($msg);
}
} elseif(isset($_POST['home_divs'])){
$msg = $this->HomeDivsUpdate();
$this->Show($msg);
} elseif(isset($_POST['mainmenu'])){
if(isset($_POST['id'])){
$msg = $this->MainMenuUpdate($_POST['id'],null);
$this->Show($msg);
}
} elseif(isset($_POST['mainmenu_new'])){
if(isset($_POST['type'])){
$msg = $this->MainMenuUpdate(null,$_POST['type']);
$this->Show($msg);
}
} elseif(isset($_POST['deletemenu'])){
if(isset($_POST['id'])){
$msg = $this->DeleteMenu($_POST['id']);
$this->Show($msg);
}
} elseif(isset($_POST['updatehomephp'])){
$msg = $this->UpdateHomePage();
$this->Show($msg);
} elseif(isset($_POST['updatemenus'])){
if($_POST['updatemenus']=="Update header menus"){
$msg = $this->UpdateMenus();
}elseif($_POST['updatemenus']=="Update footer menus"){
$msg = $this->UpdateFootMenus();
}
$this->Show($msg);
} elseif(isset($_POST['updatesitemap'])){
$msg = $this->UpdateSiteMap();
$this->Show($msg);
}else {
$this->Show($msg);
}
}
function Show($msg){
$query = @mysql_query('SELECT * FROM web_admin_options WHERE type="division" order by division_id');
$list = '<div class="articles" style="float:left;">';
while($data = @mysql_fetch_array($query)){
$div_id = (empty($data['division_id']))?'Enter the division ID':$data['division_id'];
$div_title = (empty($data['title']))?'Enter the title (home page)':$data['title'];
$div_img = (empty($data['image_href']))?'Enter the image location as src/img/home/...gif':$data['image_href'];
$div_img_ovr = (empty($data['image_over_href']))?'Enter the hover image location as src/img/home/...gif':$data['image_over_href'];
$div_price_all = (empty($data['display_price']))?'':$data['display_price'];
$div_price_cat = (empty($data['display_cat_price_no']))?'':$data['display_cat_price_no'];
$query2 = @mysql_query('SELECT distinct web_inventtable.dimension3_, web_olapprodcat.description FROM web_inventtable,web_olapprodcat WHERE web_inventtable.olapproductgroup="'.$div_id.'" and web_inventtable.dimension3_ = web_olapprodcat.catid ORDER BY dimension3_');
$cats = explode(":",$div_price_cat);
$options = '';
while($data2 = @mysql_fetch_array($query2)){
foreach($cats as $row2){
if($row2==$data2['dimension3_']){
$sel = 'selected';
break;
}else{
$sel = '';
}
}
$options .= '<option value="'.$data2['dimension3_'].'" '.$sel.'>'.$data2['dimension3_'].': '.$data2['description'].'</option>';
}
$list .= '<div class="formbox"><form name="form" id="form" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<p><label for="division_id">AX Product Group ID</label><input type="text" class="input" name="division_id" id="division_id" cols="150" value="'.$div_id.'"></p>
<br/>
<p><label for="title">Product Group Name</label><input type="text" name="title" class="input" cols="150" value="'.$div_title.'" id="title"></p>
<br/>
<p><label for="image">Homepage image</label><img src="../'.$div_img.'"></p>
<br/>
<p><label for="image">Homepage image (new)</label><input type="file" name="image" id="image" class="input" cols="150"></p>
<br/>
<p><label for="image_over">Homepage image (hover - new)</label><input type="file" name="image_over" id="image_over" class="input" cols="150"></p>
<br/>
<p><label>Display prices for whole group?</label><select name="display_price" id="display_price" class="select"><option value="2" '.(($div_price_all==2)?"selected":"").'>No</option><option value="1" '.(($div_price_all==1)?"selected":"").'>Yes</option><option value="0" '.(($div_price_all==0)?"selected":"").'>Categories only</option></select></p>
<br/>';
if($div_price_all==0){
$list .='<p><label>Select the categories <strong>NOT</strong> to display prices for?</label><select multiple size="10" name="display_price_cat[]" id="display_price_cat[]" class="select">'.$options.'</select></p>
<br/>';
}
$list .='<p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';"><input type="submit" name="delete" value="Delete" class="submit-khaki" onclick="return Delete(\''.$div_title.'\');"><input type="submit" name="update" value="Update" class="submit-khaki" onclick="return Division();"></p>
</form></div>';
}
$list .='</div>';
global $body;
$body .= '<p class="error">'.$msg.'</p>
<div class="formbox-option">
<form name="form" id="form8" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<p><input type="submit" name="updatehomephp" value="Update homepage layout" class="submit-khaki">
<input type="submit" name="updatemenus" value="Update header menus" class="submit-khaki">
<input type="submit" name="updatemenus" value="Update footer menus" class="submit-khaki">
<input type="submit" name="updatesitemap" value="Update sitemap" class="submit-khaki"></p>
</form>
</div>
<h1>Divisions & Menu Admin</h1><br/>';
$body .= '<div class="articles admin">
<div class="formbox-option">'
.$this->HomeDivs().
'<br/>'
.$this->MainMenu().
'<br/>'
.$this->FootMenu().
'<br/>'
.$this->DeleteMenuShow().
'</div>
'.$list.'
</div>
<div class="articles"><div class="formbox"><form name="form" id="form" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<p><h2>Add new division</h2></p><br/>
<p><label for="division_id">AX Product Group ID</label><input type="text" class="input" name="division_id" id="division_id" cols="150" value=""></p>
<br/>
<p><label for="title">Product Group Name</label><input type="text" name="title" class="input" cols="150" value="" id="title"></p>
<br/>
<p><label for="image">Homepage image</label><input type="file" name="image" id="image" class="input" cols="150"></p>
<br/>
<p><label for="image_over">Homepage image (hover)</label><input type="file" name="image_over" id="image_over" class="input" cols="150"></p>
<br/>
<p><label>Display prices for product group?</label><select name="display_price" id="display_price" class="select"><option value="2">No</option><option value="1">Yes</option><option value="0">Categories only</option></select></p>
<br/>
<p><label>Select the categories <strong>NOT</strong> to display prices for?</label><span>Please save the division first and then update the necessary categories if applicable</span></p>
<br/>
<p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';"><input type="submit" name="create" value="Create" class="submit-khaki" onclick="return Division();"></p>
</form></div></div>';
return $body;
}
function Save(){
$file = NULL;
$file2 = NULL;
$Addfile = new AcceptFile();
if(isset($_FILES["image"]["type"])) $file = $Addfile->AddFile_division("image");
if(isset($_FILES["image_over"]["type"])) $file2 = $Addfile->AddFile_division("image_over");
$query = @mysql_query('INSERT INTO web_admin_options
(title,division_id,image_href,image_over_href,display_price,type)
VALUES
(
"'.$_POST['title'].'",
"'.$_POST['division_id'].'",
"'.$file.'",
"'.$file2.'",
'.((isset($_POST['display_price']))?$_POST['display_price']:0).',
"division")');
if(!$query){
return ' : MySQL error ('.mysql_error().')';
}
return 'The '.$_POST['title'].' group has been created';
}
function Update($id){
$file = NULL;
$Addfile = new AcceptFile();
$up_file = NULL;
if(isset($_FILES["image"]["type"])){
$up_file = $Addfile->AddFile_division("image");
if($up_file!='Invalid file - jpg files only, max 2mb'){
$file = $up_file;
}else{
echo 'sdfdf';
}
}
$file2 = NULL;
$Addfile = new AcceptFile();
$up_file2 = NULL;
if(isset($_FILES["image_over"]["type"])){
$up_file2 = $Addfile->AddFile_division("image_over");
if($up_file2!='Invalid file - jpg files only, max 2mb'){
$file2 = $up_file2;
}
}
$cat_id = (!isset($_POST['display_price_cat']))?'':$_POST['display_price_cat'];
$cats='';
$cat_ids = '';
if(is_array($cat_id)){
foreach($cat_id as $row){
$cat_ids .= $row.':';
}
$cats = (isset($cat_ids))?substr($cat_ids,0,(strlen($cat_ids)-1)):'';
}
if(isset($_POST['display_price']) && ($_POST['display_price']==1 || $_POST['display_price']==2)) $cats='';
$query = @mysql_query('UPDATE web_admin_options SET
title="'.$_POST['title'].'", '
.(($file==NULL)?'':'image_href="'.$file.'",
image_over_href="'.$file2.'", ').
'display_price='.((isset($_POST['display_price']))?$_POST['display_price']:0).',
display_cat_price_no="'.$cats.'"
WHERE division_id='.$id);
if(!$query){
return ' : MySQL error ('.mysql_error().')';
}
return 'The '.$_POST['title'].' group has been updated';
}
function Delete($id){
if(!empty($id)){
$query = @mysql_query('DELETE FROM web_admin_options WHERE division_id='.$id);
}
if(!$query){
return ' : MySQL error ('.mysql_error().')';
}
return 'The '.$id.' group has been deleted';
}
function HomeDivs(){
$query2 = @mysql_query('SELECT option_val from web_admin_options where division_id = "home_div" limit 0,1');
$options = array("129","119","109","99","89");
$opt = '';
while($data2 = @mysql_fetch_array($query2)){
foreach($options as $row2){
if($row2==$data2['option_val']){
$opt .= '<option value="'.$data2['option_val'].'" selected>'.$data2['option_val'].'px</option>';
break;
}
}
$homediv = '<form name="form" id="form1" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<p><h2>Adjust homepage display options</h2></p><br/>
<p><label>Adjust the height of the division boxes (homepage):</label>
<select name="display_divs" id="display_divs" class="select">'.$opt.'<option value="129">129px</option><option value="119">119px</option><option value="109">109px</option><option value="99">99px</option><option value="89">89px</option></select></p>
<br/><p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';">
<input type="submit" name="home_divs" value="Update Homepage" class="submit-khaki""></p>
</form>';
return $homediv;
}
}
function HomeDivsUpdate(){
if(isset($_POST['display_divs'])){
$query = @mysql_query('UPDATE web_admin_options SET
option_val="'.$_POST['display_divs'].'"
WHERE division_id="home_div"');
}
$query = @mysql_query('SELECT image_href,image_over_href FROM web_admin_options WHERE type="division" order by division_id');
while($data = @mysql_fetch_array($query)){
echo $data['image_href'];
if(!file_exists('../'.(str_replace(".jpg","-".$_POST['display_divs'].".jpg",$data['image_href'])))){
$img = imagecreatefromjpeg('../'.$data['image_href']);
$path = '../'.(str_replace(".jpg","-".$_POST['display_divs'].".jpg",$data['image_href']));
list($width, $height) = getimagesize('../'.$data['image_href']);
if($_POST['display_divs']==129){
$new_height = 129;
$new_width = 108;
}else{
$new_percent = $_POST['display_divs']/$height;
$new_height = $height * $new_percent;
$new_width = $width * $new_percent;
}
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, $path);
imagedestroy($image_p);
imagedestroy($img);
}
if(!file_exists('../src/img/home/'.(str_replace(".jpg","-".$_POST['display_divs'].".jpg",$data['image_over_href'])))){
$img = imagecreatefromjpeg('../'.$data['image_over_href']);
$path = '../'.(str_replace(".jpg","-".$_POST['display_divs'].".jpg",$data['image_over_href']));
list($width, $height) = getimagesize('../'.$data['image_over_href']);
if($_POST['display_divs']==129){
$new_height = 129;
$new_width = 108;
}else{
$new_percent = $_POST['display_divs']/$width;
$new_height = $height * $new_percent;
$new_width = $width * $new_percent;
}
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, $path);
imagedestroy($image_p);
imagedestroy($img);
}
}
if(!$query){
return ' : MySQL error ('.mysql_error().')';
}
return 'Homepage div blocks size has been set';
}
function MainMenu(){
$query2 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent from web_admin_options where type = "mainmenu" order by menu_parent,option_val');
$options = array();
$count = 0;
$parents = '';
$body='<form name="form" id="form2" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<p><h2>Header menu items</h2></p><br/>';
while($data2 = @mysql_fetch_array($query2)){
if($data2['menu_parent']==0){
$txt = '<br/><p><label style="width:60px;">'.$data2['title'].'</label>
<input type="text" class="input" name="title[]" id="title[]" cols="80" value="'.$data2['title'].'">
<input type="text" class="input" name="menu_link[]" id="menu_link[]" cols="150" value="'.$data2['menu_link'].'">
<input type="text" class="input input-small" name="option_val[]" id="option_val[]" cols="5" value="'.$data2['option_val'].'">
<select name="menu_session[]" id="menu_session[]" class="select input-small2"><option value="0" '.(($data2['menu_session']==0)?'selected':'').'>No session</option><option value="1" '.(($data2['menu_session']==1)?'selected':'').'>Show logged out</option><option value="2" '.(($data2['menu_session']==2)?'selected':'').'>Show logged in</option></select>
<input type="hidden" name="menu_parent[]" id="menu_parent[]" value="'.$data2['menu_parent'].'">
<input type="hidden" name="id[]" id="id[]" value="'.$data2['id'].'"></p>';
$options[$count] = array("id"=>$data2['id'],"title"=>$data2['title'],"parent"=>$txt,"child"=>"");
$count++;
}
}
for($i=0;$i<count($options);$i++){
$parents .= '<option value="'.$options[$i]['id'].'">'.$options[$i]['id'].' - '.$options[$i]['title'].'</option>';
}
$query3 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent from web_admin_options where type = "submenu" order by menu_parent,option_val');
while($data3 = @mysql_fetch_array($query3)){
if($data3['menu_parent']!=0){
$txt = '<p style="padding-left:20px;"><label style="width:60px;">Submenu</label>
<input type="text" class="input" name="title[]" id="title[]" cols="80" value="'.$data3['title'].'">
<input type="text" class="input" name="menu_link[]" id="menu_link[]" cols="150" value="'.$data3['menu_link'].'">
<input type="text" class="input input-small" name="option_val[]" id="option_val[]" cols="5" value="'.$data3['option_val'].'">
<select name="menu_parent[]" id="menu_parent[]" class="select input-small2"><option value="'.$data3['menu_parent'].'">'.$data3['menu_parent'].'</option>'.$parents.'</select>
<select name="menu_session[]" id="menu_session[]" class="select input-small2"><option value="0" '.(($data3['menu_session']==0)?'selected':'').'>No session</option><option value="1" '.(($data3['menu_session']==1)?'selected':'').'>Show logged out</option><option value="2" '.(($data3['menu_session']==2)?'selected':'').'>Show logged in</option></select></p><p class="clear">
<input type="hidden" name="id[]" id="id[]" value="'.$data3['id'].'"></p>';
for($i=0;$i<count($options);$i++){
if($options[$i]['id']==$data3['menu_parent']){
$options[$i]['child'] .= $txt;
break;
}
}
}
}
foreach($options as $row){
$body .= $row['parent'] .$row['child'] ;
}
$body .='<br/><p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';"><input type="submit" name="mainmenu" value="Update main menu" class="submit-khaki""></p>
</form>
<form name="form" id="form3" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<br/><p><h2>Add header menus</h2></p>';
if(count($options)<6){
$body .='<br/><p><label style="width:80px;">Header menu::</label>
<input type="text" class="input" name="title[]" id="title[]" cols="80" value="Add new menu item">
<input type="text" class="input" name="menu_link[]" id="menu_link[]" cols="150" value="Menu link">
<input type="text" class="input input-small" name="option_val[]" id="option_val[]" value="order">
<select name="menu_session[]" id="menu_session[]" class="select input-small2"><option value="0">No session</option><option value="1">Show logged out</option><option value="2">Show logged in</option></select>
<input type="hidden" name="menu_parent[]" id="menu_parent[]" value="0">
<input type="hidden" name="type[]" id="type[]" value="mainmenu"></p>';
}
$body .= '<br/><p style="padding-left:20px;"><label style="width:60px;">Submenu</label>
<input type="text" class="input" name="title[]" id="title[]" cols="80" value="Add a submenu">
<input type="text" class="input" name="menu_link[]" id="menu_link[]" cols="150" value="menu link">
<input type="text" class="input input-small" name="option_val[]" id="option_val[]" cols="5" value="order">
<select name="menu_parent[]" id="menu_parent[]" class="select input-small2">'.$parents.'</select>
<select name="menu_session[]" id="menu_session[]" class="select input-small2"><option value="0">No session</option><option value="1">Show logged out</option><option value="2">Show logged in</option></select>
<input type="hidden" name="type[]" id="type[]" value="submenu"></p>';
$body .='<br/><p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';"><input type="submit" name="mainmenu_new" value="Update main menu" class="submit-khaki""></p>
</form>';
return $body;
}
function FootMenu(){
$query2 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent from web_admin_options where type = "footmenu" order by menu_parent,option_val');
$options = array();
$count = 0;
$parents = '';
$body='<form name="form" id="form4" action="index.php?page=Divisions" method="post" enctype="multipart/form-data">
<p><h2>Footer menu items</h2></p><br/>';
while($data2 = @mysql_fetch_array($query2)){
if($data2['menu_parent']==0){
$txt = '<br/><p><label>'.$data2['title'].'</label><input type="text" class="input" name="title[]" id="title[]" cols="80" value="'.$data2['title'].'">
<input type="text" class="input" name="menu_link[]" id="menu_link[]" cols="150" value="'.$data2['menu_link'].'">
<input type="text" class="input input-small" name="option_val[]" id="option_val[]" cols="5" value="'.$data2['option_val'].'">
<input type="hidden" name="menu_parent[]" id="menu_parent[]" value="'.$data2['menu_parent'].'">
<input type="hidden" name="id[]" id="id[]" value="'.$data2['id'].'">
<input type="hidden" name="menu_session[]" id="menu_session[]" value="0"></p>';
$options[$count] = array("id"=>$data2['id'],"title"=>$data2['title'],"parent"=>$txt,"child"=>"");
$count++;
}
}
foreach($options as $row){
$body .= $row['parent'] ;
}
$body .='<br/><p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';"><input type="submit" name="mainmenu" value="Update footer menu" class="submit-khaki"></p>
</form>
<form name="form" id="form5" action="index.php?page=Divisions" method="post" enctype="multipart/form-data"><br/>
<p><h2>Add footer menus</h2></p>';
$body .='<br/><p><label>Footer menu item::</label>
<input type="text" class="input" name="title[]" id="title[]" cols="80" value="Add new menu item">
<input type="text" class="input" name="menu_link[]" id="menu_link[]" cols="150" value="Menu link">
<input type="text" class="input input-small" name="option_val[]" id="option_val[]" value="order">
<input type="hidden" name="menu_parent[]" id="menu_parent[]" value="0">
<input type="hidden" name="type[]" id="type[]" value="footmenu">
<input type="hidden" name="menu_session[]" id="menu_session[]" value="0"></p>';
$body .='<br/><p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';"><input type="submit" name="mainmenu_new" value="Add new footer menu" class="submit-khaki"></p>
</form>';
return $body;
}
function DeleteMenuShow(){
$query2 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent from web_admin_options where type = "mainmenu" or type = "submenu" or type = "footmenu" order by id');
$parents = '';
$body ='<form name="form" id="form7" action="index.php?page=Divisions" method="post" enctype="multipart/form-data"><br/>
<p><h2>Delete menu items</h2></p>';
while($data2 = @mysql_fetch_array($query2)){
$parents .= '<option value="'.$data2['id'].'">'.$data2['id'].' - '.$data2['title'].'</option>';
}
$body .='<br/><p><label>Delete a menu item::</label>
<select name="id" id="id" class="select">'.$parents.'</select></p><p class="clear"></p>
<br/><p><input type="submit" value="Back" class="submit-khaki" onclick="document.form.action=\'?page=Divisions\';">
<input type="submit" name="deletemenu" value="Delete menu item" class="submit-khaki"></p>
</form>';
return $body;
}
function MainMenuUpdate($id,$type){
if(count($id)>0){
for($i=0;$i<count($id);$i++){
$query2 = @mysql_query('UPDATE web_admin_options set title = "'.$_POST['title'][$i].'",menu_link = "'.htmlspecialchars($_POST['menu_link'][$i]).'",menu_session = '.$_POST['menu_session'][$i].',option_val = "'.$_POST['option_val'][$i].'",menu_parent = '.$_POST['menu_parent'][$i].' where id = '.$id[$i]);
}
}elseif(count($type)>0){
for($i=0;$i<count($type);$i++){
if($_POST['title'][$i]!='Add new menu item' && $_POST['title'][$i]!='Add a submenu'){
$query2 = @mysql_query('INSERT INTO web_admin_options (type,title,menu_link,menu_session,option_val,menu_parent) values ("'.$_POST['type'][$i].'", "'.$_POST['title'][$i].'", "'.htmlspecialchars($_POST['menu_link'][$i]).'", '.$_POST['menu_session'][$i].', "'.$_POST['option_val'][$i].'",'.$_POST['menu_parent'][$i].')');
}
}
}
if(!$query2){
return ' : MySQL error ('.mysql_error().')';
}
return 'Menus have been updated';
}
function DeleteMenu($id){
if(!empty($id)){
$query2 = @mysql_query('DELETE from web_admin_options where id = '.$id);
}
return 'Menus have been deleted';
}
function UpdateHomePage(){
$divs = 129;
$div_cnt = 3;
$count = 0;
$query2 = @mysql_query('SELECT option_val from web_admin_options where division_id = "home_div" limit 0,1');
while($data2 = @mysql_fetch_array($query2)){
$divs = $data2['option_val'];
}
$style='<style type="text/css">
.home-category{
height: '.$divs.'px;
}
.home-category a{
display: block;
position: absolute;
width: 310px;
height: '.$divs.'px;
}
.home-category a:link{
text-decoration: none;
}
.home-category a:visited{
text-decoration: none;
}
.home-category span{
display: block;
margin-left: 10px;
}
.home-category .h1{
margin-top: 10px;
font-size: 22px;
margin-left: 8px;
font-weight: bold;
font-family: arial;
}
.home-category .h3{
margin-top: 10px;
font-size: 14px;
margin-left: 8px;
font-weight: bold;
font-family: arial;
color:#F00;
}
.home-newprod-block{
width:150px;
height:150px;
padding-top:10px;
padding-left:10px;
}
.home-newprod-name{
text-align: center;
width:280px;
height:15px;
overflow: hidden;
padding: 2px;
}
.home-newprod-name2{
margin-left: 25px;
width:280px;
height:27px;
float:0px;
overflow:hidden;
}
.home-dealer-input{
float: left;
border: none;
width: 160px;
}
.home-dealer-login label{
width: 80px;
color: #666;
margin: 5px 0 0 5px;
}
.home-dealer-login a:link{
font-weight: bold;
color: #666;
}
.home-dealer-login a:visited{
font-weight: bold;
color: #666;
}
';
$query = @mysql_query('SELECT title,image_href,image_over_href,division_id FROM web_admin_options WHERE type="division" order by division_id');
$list = '<div class="column-310 float-left">';
while($data = @mysql_fetch_array($query)){
$list .='<div class="home-category block-khaki">
<a href="?page=Products&division='.$data['division_id'].'" class="home-'.$data['title'].'-icon">
<span class="h1">'.$data['title'].'</span>
<span class="bold">List Range</span>
</a>
</div>
<div class="gap-hoz-small"></div>';
$style .='a.home-'.$data['title'].'-icon{
position: absolute;
background: url("'.((str_replace(".jpg","-".$divs.".jpg",$data['image_href']))).'") right top no-repeat;
}
';
$style .='a.home-'.$data['title'].'-icon:hover{
background: url("'.((str_replace(".jpg","-".$divs.".jpg",$data['image_over_href']))).'") #c0d099 right top no-repeat;
}
';
$count++;
}
$list .='</div>';
if($count>3) $div_cnt = $count;
//set div block heights as a percentage of total height, given 3 product division links (default product division div height 129px)
$div_heights = array("highlights"=>0.33,"newprod"=>0.67,"dealer-login"=>0.47,"new"=>0.25,"going-green"=>0.28);
$div_col_ht = ($divs*$div_cnt)+$div_cnt;
$left_col = $div_col_ht-2;
$right_col = $div_col_ht-3;
foreach($div_heights as $row=>$val){
if($row=="highlights" || $row=="newprod"){
$style .= '.home-'.$row.'{
height: '.(round($val*$left_col,0)).'px !important;
}
';
}elseif($row=="dealer-login"){
$style .= '.home-'.$row.'{
height: '.(round($val*$right_col,1)).'px !important;
}
';
}else{
$style .= '.home-'.$row.'{
height: '.(round($val*$right_col,1)).'px !important;
overflow: hidden;
}
';
}
}
$style .= '</style>
';
$body_w = '<?php
$Tips = new Tips();
$Highlights = new Highlights();
$Newproducts = new NewProducts();
global $body;
$body = \''.$style.'
<div class="column-310 float-left">
<div class="block-khaki home-highlights">
<div class="padding-10">
<h1 class="text-white">Products updates</h1>
<br/>
<p> <h4>Product recall</h4> </p> <p> <a href="http://www.MYCOMPANY.co.za/?page=product_recall"><br>Click here</a> for lot numbers </p>
</div>
</div>
<div class="gap-hoz-small"></div>
<div class="block-khaki home-newprod">
<div class="padding-10">
<h1 class="text-white">New Products</h1>
</div>
\'.$Newproducts->Display().\'
</div>
</div>
<div class="gap-vert float-left"></div>'
.$list.
'<div class="gap-vert float-left"></div>
<div class="column-310 float-left">
<div class="block-yellow home-dealer-login">
<div class="padding-10">
\'.$Dealer->LoginDisplay($message).\'
</div>
</div>
<div class="gap-hoz-small"></div>
<div class="block-khaki home-new">
<div class="padding-10">
<h1 class="text-white">News</h1>
<br/>
\'.$Highlights->Display().\'
</div>
</div>
<div class="gap-hoz-small"></div>
<div class="block-khaki home-going-green">
<div class="padding-10">
<h1 class="text-white">Going Green</h1>
<br/>
\'.$Tips->Display().\'
</div>
</div>
</div>
<p class="clear"></p>\';
?>';
$home_page ="../src/php/views/home.php";
$home = "";
// Let's make sure the file exists and is writable first.
if (is_writable($home_page)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($home_page, 'wb')) {
return "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $body_w) === FALSE) {
return "Cannot write to file ($filename)";
exit;
}
fclose($handle);
return "Homepage display has been update - please check!!";
} else {
return "The file $filename is not writable";
}
}
function UpdateMenus(){
$menuarray = "";
$options = array();
$count = 0;
$parents = '';
$query2 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent,type from web_admin_options where type = "mainmenu" or type = "submenu" order by menu_parent,option_val,id');
while($data2 = @mysql_fetch_array($query2)){
if($data2['menu_parent']==0 && $data2['type']=="mainmenu"){
if($data2['menu_session']==2){
$txt = '<?php if($Session->ID() != NULL):?>
<li><a href="'.$data2['menu_link'].'" class="menu-link" onmouseover="SubMenu();">'.$data2['title'].'</a></li>
<?php endif;?>
';
}elseif($data2['menu_session']==1){
$txt = '<?php if($Session->ID()== NULL):?>
<li><a href="'.$data2['menu_link'].'" class="menu-link" onmouseover="SubMenu();">'.$data2['title'].'</a></li>
<?php endif;?>
';
}else{
$txt = '
<li><a href="'.$data2['menu_link'].'" class="menu-link" onmouseover="SubMenu();">'.$data2['title'].'</a></li>
';
}
$options[$count] = array("id"=>$data2['id'],"title"=>$data2['title'],"parent"=>$txt,"child"=>"");
$count++;
}
}
$query3 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent from web_admin_options where type = "submenu" order by menu_parent,option_val');
while($data3 = @mysql_fetch_array($query3)){
if($data3['menu_parent']!=0){
if($data3['menu_session']==2){
$txt = '<?php if($Session->ID() != NULL):?>
<a href="'.$data3['menu_link'].'" class="sub-menu-link">'.$data3['title'].'</a>
<?php endif;?>
';
}elseif($data3['menu_session']==1){
$txt = '<?php if($Session->ID() == NULL):?>
<a href="'.$data3['menu_link'].'" class="sub-menu-link">'.$data3['title'].'</a>
<?php endif;?>
';
}else{
$txt = '<a href="'.$data3['menu_link'].'" class="sub-menu-link">'.$data3['title'].'</a>
';
}
for($i=0;$i<count($options);$i++){
if($options[$i]['id']==$data3['menu_parent']){
$options[$i]['child'] .= $txt;
break;
}
}
}
}
foreach($options as $row){
if(!empty($row['child'])){
$menuarray .= "'". $row['title'] ."',";
$repx = array('<li>','SubMenu();');
$repy = array('<li>
<div id="sub-menu-'. $row['title'] .'" class="sub-menu">
<div class="menu-highlight"></div>
'.$row['child'].'</div>
','SubMenu(\''. $row['title'] .'\');');
$x = str_replace($repx,$repy,$row['parent']);
$row['parent'] = $x;
}
$parents .= $row['parent'];
}
if(substr($menuarray,(strlen($menuarray)-1))==","){
$x = substr($menuarray,0,(strlen($menuarray)-1));
$menuarray = $x;
}
$body_w = '<?php if(isset($_GET[\'prnt\'])&&$_GET[\'prnt\']==\'YES\'):?>
<div id="menu">
<ul>
<br/>
<p><h5>Johannesburg<br/>(tel)+27 11 386-0000 // (fax)+27 11 448-1428</h5><br/></p>
<p><h5>Cape Town<br/>(tel)+27 21 521-2500 // (fax)+27 21 557-5846</h5></p>
<p><h5>Durban<br/>(tel)+27 31 563 9636/0413 // (fax)+27 31 563 5232</h5></p>
</ul>
</div>
<?php else:?>
<script type="text/javascript">
function SubMenu(id){
var sub_menus = Array('.$menuarray.');
for(var key in sub_menus){
document.getElementById(\'sub-menu-\'+sub_menus[key]).style.display = \'none\';
}
if(id != null){
document.getElementById(\'sub-menu-\'+id).style.display = \'block\';
}
}
</script>
<div id="menu">
<ul>
'.$parents.'
</ul>
</div>
<?php endif?>';
$home_page ="../src/inc/menu.php";
$home = "";
// Let's make sure the file exists and is writable first.
if (is_writable($home_page)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($home_page, 'wb')) {
return "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $body_w) === FALSE) {
return "Cannot write to file ($filename)";
exit;
}
fclose($handle);
return "Header menu display has been update - please check!!";
} else {
return "The file $filename is not writable";
}
}
function UpdateFootMenus(){
$menuarray = "";
$options = array();
$count = 0;
$parents = '';
$query2 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent,type from web_admin_options where type ="footmenu" order by option_val,id');
while($data2 = @mysql_fetch_array($query2)){
if($data2['menu_parent']==0 && $data2['type']=="footmenu"){
$txt = '<a href="'.$data2['menu_link'].'" class="footer-link">'.$data2['title'].'</a><span class="pipe">|</span>
';
$options[$count] = array("id"=>$data2['id'],"title"=>$data2['title'],"parent"=>$txt,"child"=>"");
$count++;
}
}
foreach($options as $row){
$parents .= $row['parent'];
}
$body_w = '<!-- print view footer-->
<?php if(isset($_GET[\'prnt\'])&&$_GET[\'prnt\']==\'YES\'):?>
<div id="footer">
<div class="float-left"><p>Switch to MYCOMPANY products for a brighter, greener future.</p></div>
<div class="float-right"><p>Thanks for visiting our site. Please visit our showrooms in Johannesburg or Cape Town. <?php echo date("D M j H:i");?></p></div>
<p class="clear"></p>
</div>
<!-- begin footer menu-->
<?php else:?>
<div id="footer">
<br/>
<div class="float-left">
<p>Switch to MYCOMPANY products for a brighter, greener future</p>
</div>
<div class="float-right">
'.$parents.'
</div>
<div class="float-none"></div>
<p class="clear"></p>
</div>
<?php endif?>
<!-- end footer menu-->';
$home_page ="../src/inc/footer.php";
$home = "";
// Let's make sure the file exists and is writable first.
if (is_writable($home_page)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($home_page, 'wb')) {
return "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $body_w) === FALSE) {
return "Cannot write to file ($filename)";
exit;
}
fclose($handle);
return "Footer menu display has been update - please check!!";
} else {
return "The file $filename is not writable";
}
}
function UpdateSiteMap(){
$options = array();
$count = 0;
$parents = '';
$parentsxml = '';
$query2 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent,type from web_admin_options where type = "mainmenu" or type = "submenu" or type = "footmenu" order by type desc, menu_parent asc,option_val asc ,id asc');
while($data2 = @mysql_fetch_array($query2)){
if($data2['menu_parent']==0){
if($data2['menu_session']!=2){
$txtxml = '
<url><loc>http://www.MYCOMPANY.co.za/'.$data2['menu_link'].'</loc><changefreq>daily</changefreq><priority>0.85</priority></url>
';
}
$options[$count] = array("id"=>$data2['id'],"title"=>$data2['title'],"parentxml"=>$txtxml,"childxml"=>"");
$count++;
}
}
$query3 = @mysql_query('SELECT id,title,menu_link,menu_session,option_val,menu_parent from web_admin_options where type = "submenu" order by menu_parent,option_val');
while($data3 = @mysql_fetch_array($query3)){
if($data3['menu_parent']!=0){
if($data3['menu_session']!=2){
$txtxml = '
<url><loc>http://www.MYCOMPANY.co.za/'.$data3['menu_link'].'</loc><changefreq>daily</changefreq><priority>0.85</priority></url>
';
for($i=0;$i<count($options);$i++){
if($options[$i]['id']==$data3['menu_parent'] && $options[$i]['title']=='Products' && strpos($data3['menu_link'],'division=')!==false){
$options[$i]['childxml'] .= $txtxml;
$div = substr($data3['menu_link'],(strpos($data3['menu_link'],'division=')+strlen('division=')));
$query_string = @mysql_query('SELECT web_olapprodcat.CATID, web_olapprodsubcat.SUBCATID, web_inventtable.ItemId, web_inventtable.ItemName, web_inventtable.Group, web_olapprodcat.Description as catdesc, web_olapprodsubcat.Description as subcatdesc
FROM (web_inventtable INNER JOIN web_olapprodcat ON web_inventtable.Dimension3_ = web_olapprodcat.CATID) INNER JOIN web_olapprodsubcat ON web_inventtable.Dimension4_ = web_olapprodsubcat.SUBCATID
WHERE web_inventtable.OLAPProductGroup = "'.$div.'"
ORDER BY web_olapprodcat.CATID, web_olapprodsubcat.SUBCATID, web_inventtable.ItemId');
$cat1 = '';
$cat2 = '';
$subcat = '';
$subcat2 = '';
while($cats = @mysql_fetch_array($query_string)){
$cat2 = $cats['CATID'];
if($cat2!=$cat1){
$cat1 = $cat2;
$txtxml = '
<url><loc>http://www.MYCOMPANY.co.za/?page=Search&division='.$div.'&c_id='.$cats['CATID'].'</loc><changefreq>daily</changefreq><priority>0.69</priority></url>
';
$options[$i]['childxml'] .= $txtxml;
}
$subcat2 = $cats['SUBCATID'];
if($subcat2!=$subcat){
$subcat = $subcat2;
$txtxml = '
<url><loc>http://www.MYCOMPANY.co.za/?page=Search&division='.$div.'&c_id='.$cats['CATID'].'&sc_id='.$cats['SUBCATID'].'</loc><changefreq>daily</changefreq><priority>0.69</priority></url>
';
$options[$i]['childxml'] .= $txtxml;
}
$txtxml = '
<url><loc>http://www.MYCOMPANY.co.za/?page=Product&id='.$cats['ItemId'].'&group='.$cats['Group'].'</loc><changefreq>daily</changefreq><priority>0.69</priority></url>
';
$options[$i]['childxml'] .= $txtxml;
}
break;
}elseif($options[$i]['id']==$data3['menu_parent']){
$options[$i]['childxml'] .= $txtxml;
break;
}
}
}
}
}
$body_w = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
';
foreach($options as $row){
$body_w .= $row['parentxml'].$row['childxml'];
}
$body_w .= '</urlset>';
$home_page ="../sitemap.xml";
$home = "";
// Let's make sure the file exists and is writable first.
if (is_writable($home_page)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($home_page, 'wb')) {
return "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $body_w) === FALSE) {
return "Cannot write to file ($filename)";
exit;
}
fclose($handle);
return "Sitemap has been update - please check!!";
} else {
return "The file $filename is not writable";
}
}
}
?>