"+d+""';
//$script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")";
$script = '';
return '[javascript protected email address] '.$script;
}
// check for a paid listing
function isPaidCustomer($profileid,$userid="")
{
global $pdo;
$paid = false;
$select = "SELECT * FROM listings WHERE listing_type!='0' AND profileid='$profileid'";
$query = $pdo->query($select);
if($query->rowCount() != "0")
{
$paid = true;
}
return $paid;
}
// convert date
function convertDate($date,$format="d M Y")
{
$strtotime = strToTime($date);
$output = date($format,$strtotime);
return $output;
}
function daysUntil($d1,$d2)
{
if($d1 == "")
{
$d1 = date("Y-m-d");
}
$date1 = new DateTime($d1);
$date2 = new DateTime($d2);
$diff = $date2->diff($date1)->format("%a");
$extra = ($diff == "1") ? " day" : " days";
$diff = "$diff$extra";
return $diff;
}
// Update profile views
function updateProfileViews($profileid,$type="")
{
global $pdo;
$month= date("m");
$year = date("Y");
if($type == "")
{
$variable = "organic";
}
else{
$variable = $type;
}
$update = "UPDATE profile_impressions SET $variable=$variable+1 WHERE profile_id='$profileid' AND actionmonth='$month' AND actionyear='$year'";
$query = $pdo->query($update);
if($query->rowCount() == "0")
{
// there are none for today
$insert = "INSERT INTO profile_impressions (profile_id, $variable, actionmonth, actionyear) VALUES ('$profileid','1','$month','$year')";
$query2 = $pdo->query($insert);
}
}
// Update impressions
function updateImpressions($profileid)
{
global $pdo;
$month= date("m");
$year = date("Y");
$update = "UPDATE listing_impressions SET impressions=impressions+1 WHERE listing_id='$profileid' AND actionmonth='$month' AND actionyear='$year'";
$query = $pdo->query($update);
if($query->rowCount() == "0")
{
// there are none for today
$insert = "INSERT INTO listing_impressions (listing_id, impressions, actionmonth, actionyear) VALUES ('$profileid','1','$month','$year')";
$query2 = $pdo->query($insert);
}
}
function updateClicks($profileid)
{
global $pdo;
$month= date("m");
$year = date("Y");
$update = "UPDATE listing_impressions SET clicks=clicks+1 WHERE listing_id='$profileid' AND actionmonth='$month' AND actionyear='$year'";
$query = $pdo->query($update);
if($query->rowCount() == "0")
{
// there are none for today
$insert = "INSERT INTO listing_impressions (listing_id, clicks, actionmonth, actionyear) VALUES ('$profileid','1','$month','$year')";
$query2 = $pdo->query($insert);
}
}
// Impressions for adverts
function updateImpressionsAd($profileid)
{
global $pdo;
$month= date("m");
$year = date("Y");
$update = "UPDATE advert_impressions SET impressions=impressions+1 WHERE advert_id='$profileid' AND actionmonth='$month' AND actionyear='$year'";
$query = $pdo->query($update);
if($query->rowCount() == "0")
{
// there are none for today
$insert = "INSERT INTO advert_impressions (advert_id, impressions, actionmonth, actionyear) VALUES ('$profileid','1','$month','$year')";
$query2 = $pdo->query($insert);
}
}
function updateClicksAd($profileid)
{
global $pdo;
$month= date("m");
$year = date("Y");
$update = "UPDATE advert_impressions SET clicks=clicks+1 WHERE advert_id='$profileid' AND actionmonth='$month' AND actionyear='$year'";
$query = $pdo->query($update);
if($query->rowCount() == "0")
{
// there are none for today
$insert = "INSERT INTO advert_impressions (advert_id, clicks, actionmonth, actionyear) VALUES ('$profileid','1','$month','$year')";
$query2 = $pdo->query($insert);
}
}
/* Function Name: generatePassword(Length, Strenght)
/* Generates a random password
*/
function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength & 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength & 2) {
$vowels .= "AEUY";
}
if ($strength & 4) {
$consonants .= '23456789';
}
if ($strength & 8) {
$consonants .= '@#$%';
}
$password = '';
$alt = time() % 2;
for ($i = 0; $i < $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}
/* Function Name: generateCountiesArray()
/* Adds the array for counties - ideally for select lists
*/
function generateCountiesArray()
{
$countiesarray = array(
'Aberdeenshire',
'Anglesey / Sir Fon',
'Angus',
'Argyll and Bute',
'Ayrshire',
'Bedfordshire',
'Berkshire',
'Blaenau Gwent',
'Bridgend',
'Bristol',
'Buckinghamshire',
'Caerphilly',
'Cambridgeshire',
'Cardiff',
'Carmarthenshire',
'Ceredigion',
'Cheshire',
'Clackmannanshire',
'Conwy',
'Cornwall',
'County Antrim',
'County Armagh',
'County Down',
'County Fermanagh',
'County Londonderry',
'County Tyrone',
'Cumbria',
'Denbighshire',
'Derbyshire',
'Devon',
'Dorset',
'Dumfries and Galloway',
'Dunbartonshire',
'Dundee',
'Durham',
'East Lothian',
'East Riding of Yorkshire',
'East Sussex',
'Edinburgh',
'Essex',
'Falkirk',
'Fife',
'Flintshire',
'Glamorgan',
'Glasgow',
'Gloucestershire',
'Greater Manchester',
'Gwynedd',
'Hampshire',
'Hereford and Worcester',
'Hertfordshire',
'Highland',
'Inverclyde',
'Isle of Man',
'Isle of Wight',
'Kent',
'Lanarkshire',
'Lancashire',
'Leicestershire',
'Lincolnshire',
'London',
'Merseyside',
'Merthyr Tydfil',
'Middlesex',
'Midlothian',
'Monmouthshire',
'Moray',
'Neath Port Talbot',
'Newport',
'Norfolk',
'North Yorkshire',
'Northamptonshire',
'Northumberland',
'Nottinghamshire',
'Orkney',
'Oxfordshire',
'Pembrokeshire',
'Perth and Kinross',
'Powys',
'Renfrewshire',
'Rhondda Cynon Taff',
'Rutland',
'Scottish Borders',
'Shetland Isles',
'Shropshire',
'Somerset',
'South Yorkshire',
'Staffordshire',
'Stirlingshire',
'Suffolk',
'Surrey',
'Swansea',
'Torfaen',
'Tyne and Wear',
'Warwickshire',
'West Lothian',
'West Midlands',
'West Sussex',
'West Yorkshire',
'Western Isles',
'Wiltshire',
'Wrexham',
'Other (non-UK)'
);
return $countiesarray;
}
/* Function Name: generateCountriesArray()
/* Adds the array for countries - ideally for select lists
*/
function generateCountriesArray()
{
$countriesarray = array("United Kingdom","United States","Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe");
return $countriesarray;
}
/* Function Name: customerLog($customerid,)
/* Adds a customer change log record - THIS FUNCTION IS IN GLOBAL BECAUSE ITS CALLED AT LOGOUT AND LOGIN
*/
function customerLog($customerid,$action_user,$action_admin="",$byadmin = "0",$flag = "0", $notification = "0")
{
global $pdo;
$dateadded = time();
$ipaddress = getRealIpAddr();
$byuser = $_SESSION['control_firstname']." ".$_SESSION['control_surname'];
if(isset($_SESSION['control_adminid']) && $_SESSION['control_adminid'] != "")
{
$byadmin = "1";
}
$query = $pdo->prepare("INSERT INTO user_log (user, actionedby, timestamp, action_user, action_admin, byadmin, ipaddress, flagreview, notification) VALUES (:customer_id, :by_user, :date_added, :action_user, :action_admin, :byadmin, :ipaddress, :flag, :notification)");
$query->bindParam(":customer_id", $customerid);
$query->bindParam(":by_user", $byuser);
$query->bindParam(":date_added", $dateadded);
$query->bindParam(":action_user", $action_user);
$query->bindParam(":action_admin", $action_admin);
$query->bindParam(":byadmin", $byadmin);
$query->bindParam(":ipaddress", $ipaddress);
$query->bindParam(":flag", $flag);
$query->bindParam(":notification", $notification);
$query->execute();
}
/* Function Name: getRealIpAddr()
/* gets IP of user
*/
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
/* Function Name: global_topmenu()
/* Creates the main top menu for members/admin area
*/
function global_topmenu()
{
global $_IN, $files, $cfg, $_USER, $_url, $pdo;
$menus = array();
$loginstate = (!isset($_SESSION['control_id']) || $_SESSION['control_id'] == "") ? "1" : "2";
//$menu = "SELECT * FROM menu WHERE type='10' AND status='1' AND parent='0' AND (loginstate='0' OR loginstate='$loginstate') ORDER BY morder ASC";
$menu = "SELECT * FROM menu WHERE type='10' AND status='1' AND parent='0' AND (loginstate='0' OR loginstate=".$pdo->quote($loginstate).") ORDER BY morder ASC";
//echo $menu;
//$menu2 = mysql_query($menu) or die(mysql_error());
$menu = $pdo->query($menu);
while($menu_item = $menu->fetch(PDO::FETCH_ASSOC))
{
$keys = explode(",",$menu_item["keys"]);
$submenus = array();
// Check children
//$select = "SELECT * FROM menu WHERE type='10' AND status='1' AND parent='$menu_item[id]' ORDER BY morder ASC";
$select = "SELECT * FROM menu WHERE type='10' AND status='1' AND parent=".$pdo->quote($menu_item['id'])." ORDER BY morder ASC";
//$query = mysql_query($select);
//$query123 = mysql_query($select) or die(mysql_error());
$query = $pdo->query($select);
$query123 = $pdo->query($select);
while($menu_item2 = $query->fetch(PDO::FETCH_ASSOC))
{
//$usedirfix2 = (substr($menu_item2["link"], -1) == "#") ? "" : "{dir_fix}";
$usedirfix2 = "";
$link2 = $usedirfix2.$menu_item2["link"];
array_push($submenus,array("icon" => "$menu_item2[icon]", "priv" => "customers", "title" => "$menu_item2[title]", "link" =>$link2, "target" => "$menu_item2[target]", "onloadopen"=>"$menu_item2[onloadopen]","keys" => $keys,"items"=>$sidemenu,"class"=>"$menu_item2[class]","data-modal-class"=>$menu_item2["data-modal-class"],"data-modal-title"=>$menu_item2["data-modal-title"]));
}
//$usedirfix = (substr($menu_item["link"], -1) == "#") ? "" : "{dir_fix}";
$usedirfix = "";
$link = ($query->fetchColumn() != "0") ? "#" : $usedirfix.$menu_item["link"];
$sidemenu = "";
//$sidemenu = control_sidemenu($menu_item[keys],$menu_item[id],$menu_item[onloadopen]);
array_push($menus,array("icon" => "$menu_item[icon]", "priv" => "customers", "title" => "$menu_item[title]", "link" =>$link, "target" => "$menu_item[target]", "onloadopen"=>"$menu_item[onloadopen]","keys" => $keys,"items"=>$sidemenu,"class"=>"$menu_item[class]","data-modal-class"=>$menu_item["data-modal-class"],"data-modal-title"=>$menu_item["data-modal-title"],"submenu"=>$submenus));
}
$template = $files->read('control/lib/html/1.0/global/global-menu.html', true);
$ret = "";
$menu_details ="";
$ret .= replace_elements($template["start"], $menu_details);
foreach($menus as $menu_details)
{
$keys = implode(",",$menu_details['keys']);
//$select = "SELECT * FROM menu WHERE type='2' AND status='1' AND subsec='$keys'";
$select = "SELECT * FROM menu WHERE type='2' AND status='1' AND subsec=".$pdo->quote($keys);
//$query123 = mysql_query($select) or die(mysql_error());
$query123 = $pdo->query($select);
//echo $select;
$menu_details['hassubmenu'] = "";
// $me
//echo mysql_num_rows($query123);
if($query123->fetchColumn() != "0")
{
$menu_details['hassubmenu'] = " class=\"hasSubmenu\"";
}
// menu items
foreach($menu_details as $menu_details2)
$menu_details['sub-menu'] = "";
if(!empty($menu_details['submenu']))
{
$menu_details["sub-menu"] .= replace_elements($template["start-submenu-active"]);
foreach($menu_details['submenu'] as $menu_details3)
{
$current_template = ($menu_details3[title] == " ") ? $template["hr"] : $template["item"];
$menu_details3["sub-menu"] = "";
$menu_details["sub-menu"] .= replace_elements($current_template, $menu_details3);
}
$menu_details["sub-menu"] .= replace_elements($template["end-submenu"]);
}
if ($menu_details["target"] == "")
{
$menu_details["target"] = "_self";
}
$fullurl = implode("/",$_url);
// $fullurl2 = array_merge(array(), $_url);
// array_pop($fullurl2); //removes last
// $fullurl = implode("/",$fullurl2)."/";
//echo $fullurl;
//if(isset($_url[0]))
//{
$current_template = (!in_array($fullurl, $menu_details["keys"])) ? $template["item"] : $template["active"];
/*}
else
{
$current_template = (!in_array("", $menu_details["keys"])) ? $template["item"] : $template["active"];
}*/
$ret .= replace_elements($current_template, $menu_details);
}
$menu->closeCursor();
$query->closeCursor();
$query123->closeCursor();
$ret .= replace_elements($template["end"], $menu_details);
return $ret;
}
/* OLD FUNCTIONS BELOW _ NEED CLEANING */
## Time Zone ################################
date_default_timezone_set('Europe/London');
//session_start();
#- End Time Zone ----------------------------
## Functions ################################
function form_processing($page) {
$honeytrap = $_POST['newsletter'];
if($honeytrap != "")
{
// dont submit form - we have a bot thats filled this newsletter field.
exit;
}
if($_POST['page_name'] == "newsletter.html")
{
$name = $_POST['newsletter_name'];
$email = $_POST['newsletter_email'];
subscribe_mailchimp($name,$email,true); // true to redirect to newsletter-thanks.html
exit;
}
ini_set('output_buffering', true);
ini_set("display_errors","1");
// include('Mail.php');
// include("Mail/mime.php");
/*
if($page[template]!="content-eform.html")
{
echo "non form";
exit;
}
*/
$fromEmail = base('1013');
$toEmail = base('1013');
$fromname = base('1004');
$basedir = base('1012');
// Assign recipients and message subject
//$to="aaron@clonestudios.co.uk";
//$cc = "carl@clonestudios.co.uk";
$subject = $_POST['subject'];
//$from = "$fromname <$email[value]>";
//$from = "$_POST[name] <$_POST[email]>";
$redirect = str_replace(".html","-thanks.html",$_POST['page_name']);
// Generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$type="image/jpeg";
// Create the message body
$page = $_SERVER['REQUEST_URI'];
if($_POST['message'] != "") {
$postmessage = str_replace(array("\r\n", "\n", "\r"), " ", $_POST['message']);
} else {
$postmessage = "[no message entered]";
}
$telephone = $_POST['telephone'] != "" ? $_POST['telephone'] : "-";
// Create the main email content
foreach ($_POST['include'] as $key => $value)
{
foreach ($value as $field => $text)
{
if ($field == "Email address")
{
$replyemail = $value;
}
else if ($field=="Message")
{
$messagecontent .= "$field: ";
}else
{
$messagecontent .= "
$field: ";
}
if($text == "-1")
{
$text = "[Nothing Entered]";
}
$messagecontent .= ($text != "") ? str_replace(array("\\r\\n", "\\r", "\\n"), " ", $text) : "[Nothing Entered]";
$messagecontent .= "
";
}
}
//$filename = "/home/cloneser/public_html/clients/docmotodev/email/template.html";
$filename = base("1050")."email/template.html";
$handle = fopen($filename, "r");
$template = fread($handle, filesize($filename));
$emailheader = $_POST['heading'];
$messagebody = str_replace("{site-url}",base("1012"),$template);
$messagebody = str_replace("{email_content}","$messagecontent",$messagebody);
$messagebody = str_replace("{email_heading}","$emailheader",$messagebody);
$messagebody = str_replace("{email-subject}","$subject",$messagebody);
$message = new Mail_mime();
$message->setTXTBody($text);
$message->setHTMLBody($messagebody);
$body = $message->get();
$sitename = base('1004');
// echo $sitename; echo $fromEmail; echo $toEmail; echo $subject;
// exit;
$extraheaders = array(
"From" => "$sitename <$fromEmail>",
"Subject" => "$subject",
"To" => "$toEmail",
"Bcc" => "aaron@aaronbailey.co.uk"
);
// Set enquiry form email to use the enquirer's email address
if ($replyemail) {
$extraheaders["Reply-To"] = $replyemail;
}
$headers = $message->headers($extraheaders);
// $mail = Mail::factory("mail", array('Return-Path' => sprintf("-f %s", "$email[value]")));
// $mail->send("$to", $headers, $body);
$mail = @Mail::factory("mail", array('Return-Path' => sprintf("-f %s", "$fromEmail")));
// $mail = Mail::factory("mail", array('Return-Path' => sprintf("-f %s", "info@onlinerepro.co.uk")));
// $mail = Mail::factory("mail");
$email .= "$toEmail";
$mail->send("$toEmail", $headers, $body);
// Show the thanks message
$success = true;
fclose($handle);
header("Location: $basedir/$redirect");
exit;
}
function getToken($thisString) {
// List the possible tokens
$Tokens = array(
"Status",
"StatusDetail",
"VendorTxCode",
"VPSTxId",
"TxAuthNo",
"Amount",
"AVSCV2",
"AddressResult",
"PostCodeResult",
"CV2Result",
"GiftAid",
"3DSecureStatus",
"CardType",
"Last4Digits",
"CAVV" );
// Initialise arrays
$output = array();
$resultArray = array();
// Get the next token in the sequence
for ($i = count($Tokens)-1; $i >= 0 ; $i--){
// Find the position in the string
$start = strpos($thisString, $Tokens[$i]);
// If it's present
if ($start !== false){
// Record position and token name
$resultArray[$i]->start = $start;
$resultArray[$i]->token = $Tokens[$i];
}
}
// Sort in order of position
sort($resultArray);
// Go through the result array, getting the token values
for ($i = 0; $istart + strlen($resultArray[$i]->token) + 1;
// Get the length of the value
if ($i==(count($resultArray)-1)) {
$output[$resultArray[$i]->token] = substr($thisString, $valueStart);
} else {
$valueLength = $resultArray[$i+1]->start - $resultArray[$i]->start - strlen($resultArray[$i]->token) - 2;
$output[$resultArray[$i]->token] = substr($thisString, $valueStart, $valueLength);
}
}
// Return the ouput array
return $output;
}
// Randomise based on time
function randomise() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function txtform_crypt($input)
{
$ret = "";
if (!empty($input))
{
foreach($input as $key => $value)
{
$ret .= $key." = ".$value."\n";
}
}
return $ret;
}
function simpleXor($InString, $Key)
{
$KeyList = array();
$ret = "";
for($i = 0; $i < strlen($Key); $i++)
{
$KeyList[$i] = ord(substr($Key, $i, 1));
}
for($i = 0; $i < strlen($InString); $i++)
{
$ret .= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
}
return $ret;
}
function base64Encode($plain)
{
$ret = "";
$ret = base64_encode($plain);
return $ret;
}
function base64Decode($scrambled)
{
$ret = "";
$scrambled = str_replace(" ", "+", $scrambled);
$ret = base64_decode($scrambled);
return $ret;
}
function modulecheck($module)
{
$query = "SELECT * FROM modules WHERE name ='$module' AND enabled='1'";
$result = mysql_query($query);
if (mysql_num_rows($result) == "1") { return "1"; } else { return "0";}
}
function selected ($value,$compareto,$type)
{
if ($value == $compareto)
{
if ($type == "radio" ) { echo "CHECKED";}
if ($type == "select") { echo "SELECTED";}
}
else
{
}
}
###### Function: Base Function
###### Description: Looks up base references from database
function base($ref)
{
global $pdo, $cfg;
switch($ref){
default:
$query = "SELECT * FROM settings WHERE id = ".$pdo->quote($ref);
$result = $pdo->query($query);
$fetch = $result->fetch(PDO::FETCH_ASSOC);
$value = $fetch['value'];
$result->closeCursor();
return $value;
break;
case "1012":case "1050":
if(isset($cfg['dev']) && $cfg["dev"]["enable"] == 1){
return $cfg["dev"]["base"][$ref];
}else{
$query = "SELECT * FROM settings WHERE id = ".$pdo->quote($ref);
$result = $pdo->query($query);
$fetch = $result->fetch(PDO::FETCH_ASSOC);
$value = $fetch['value'];
$result->closeCursor();
return $value;
}
break;
}
}
function rbase($ref)
{
$query = "SELECT * FROM settings WHERE id = ".$pdo->quote($ref);
/*$result = mysql_query($query);
$fetch = mysql_fetch_array($result);
$value = $fetch[value];
return $value; */
$result = $pdo->query($query);
$fetch = $result->fetch(PDO::FETCH_ASSOC);
$value = $fetch['value'];
$result->closeCursor();
return $value;
}
###### Function: Title Lookup
###### Description: Looks up page title from database
function pglookup($ref,$what)
{
if ($ref == "") { $query1 = "SELECT * FROM settings WHERE id ='1011'";
$result1 = mysql_query($query1);
$fetch1 = mysql_fetch_array($result1);
$ref = $fetch1['value'];}
$query = "SELECT * FROM pages WHERE name ='$ref'";
$result = mysql_query($query);
$fetch = mysql_fetch_array($result);
$value = $fetch[$what];
echo $value;
}
###### Function: Build Menu
###### Description: Builds Menu from database
function buildmenu()
{
$query = "SELECT * FROM menu WHERE active='1' ORDER BY id ASC";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
$count = $rows;
echo "";
}
###### Function: Build Page
###### Description: Builds Menu from database
function buildpage($ref)
{
$query = "SELECT * FROM pages WHERE name ='$ref'";
$result = mysql_query($query);
if (mysql_num_rows($result) == "0")
{header("HTTP/1.0 404 Not Found");
exit;}
$fetch = mysql_fetch_array($result);
$value = $fetch['content'];
echo $value;
if ($fetch['module'] != "0")
{
$query = "SELECT * FROM modules WHERE id ='$fetch[module]'";
$result = mysql_query($query);
$fetch = mysql_fetch_array($result);
require("core/$fetch[function]");
}
}
###### Function: Default Page
###### Description: Finds defaultpage from database
function defaultpage()
{
$query = "SELECT * FROM settings WHERE id ='1011'";
$result = mysql_query($query);
$fetch = mysql_fetch_array($result);
$value = $fetch['value'];
buildpage($value);
}
###### Function: Default Page
###### Description: Finds defaultpage from database
function buildslide($ref)
{
if ($ref == "") { $query1 = "SELECT * FROM settings WHERE id ='1011'";
$result1 = mysql_query($query1);
$fetch1 = mysql_fetch_array($result1);
$ref = $fetch1['value'];}
$query = "SELECT * FROM pages WHERE name ='$ref'";
$result = mysql_query($query);
$fetch = mysql_fetch_array($result);
$value = $fetch['slide'];
if ($value == "1")
{
?>
TinySlideshow v1
core/images/slide/img3.png
test
TinySlideshow v1
core/images/slide/img4.png
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ut urna. Mauris nulla. Donec nec mauris. Proin nulla dolor, bibendum et, dapibus in, euismod ut, felis.
}
}
function orderStatus($status)
{
$query = "SELECT * FROM orderstatus WHERE status='$status'";
$result = mysql_query($query);
$fetch = mysql_fetch_array($result);
echo $fetch['name'];
}
#- End Functions ----------------------------
function privCheck($app)
{
$userprivsel1 = "SELECT * FROM usergrouppriv WHERE id='$_SESSION[usergroup]'";
$userprivsel2 = mysql_query($userprivsel1);
$userprivsel3 = mysql_fetch_array($userprivsel2);
if ($userprivsel3[$app] == "0") { return 0;}
}
function checkboxCheck($id)
{
if ($id == "1") {return "checked=\"checked\""; }
}
function groupName($id)
{
$query = "SELECT * FROM usergroup WHERE id='$id'";
$query2 = mysql_query($query);
$query3 = mysql_fetch_array($query2);
return $query3['name'];
}
function doSelectGroup($table,$select)
{ $query = "SELECT * FROM $table WHERE display='1'";
$query2 = mysql_query($query);
while($query3 = mysql_fetch_array($query2))
{
$ret .= "read("lib/html/contentdefault-nl.html");
$el["tab-title"] = " 404 ";
$el["content"] = "Page not found";
$ret = array();
$ret["content"] = replace_elements($template, $el);
return $ret;
}
/*
function content_homepage()
{
global $cfg, $files;
$ret = array();
$ret["content"] = $files->read("lib/".$cfg["app"]["version"]."/html/content-homepage.html");
return $ret;
}
*/
function content_compile()
{
global $cfg, $files;
$ret = array();
$ret["content"] = $files->read("lib/".$cfg["app"]["version"]."/html/html/content-compile.html");
return $ret;
}
function replace_elements($template, $el="", $tag_start = "{", $tag_end = "}",$arrayuse="")
{
$ret = $template;
if (!empty($el))
{
foreach($el as $key => $value)
{
if($arrayuse == "")
{
if (!is_array($value)) $useval = strval($value);
else $useval = "";
}
else
{
// print_r($value);
if(!is_array($value))
{
$item = $value;
}
else
{
$item = $value[$arrayuse];
}
$useval = strval($item);
// $useval = "";
}
$key = str_replace("/","\/",$key);
//$ret = ereg_replace($tag_start.$key.$tag_end, $useval, $ret);
$ret = preg_replace("/".$tag_start.$key.$tag_end."/", $useval, $ret);
}
}
return $ret;
}
function select_options($items, $selected = false)
{
$ret = "";
if (!empty($items))
{
foreach($items as $key => $value)
{
$ret .= " ";
}
}
return $ret;
}
function checkbox_html($status)
{
if ($status == "Y")
return " checked";
else
return "";
}
//
// read template file and return array with template elements
//
function templatefile_read($file, $tag_start = "[!--", $tag_end = "--]")
{
$template = array();
$content = @file_get_contents($file);
$parts = explode($tag_start, $content);
unset($parts[0]);
if(!empty($parts))
{
foreach($parts as $key => $element)
{
// echo "*".$element."*";
$items = explode($tag_end, $element);
if (!empty($items))
{
$part_name = preg_replace("/ /", "", strtolower($items[0]));
$part_html = $items[1];
$template[$part_name] = $part_html;
}
}
}
return $template;
}
function html_list($items, $el, $file)
{
global $files;
$template = $files->read($file, true);
$ret = "";
$ret .= $template["start"];
if (!empty($items))
{
$count = 0;
$number_of_items = sizeof($items);
foreach($items as $key => $item)
{
$count++;
$item["row"] = $count;
$item["row_f"] = ($count/2 != floor($count/2)) ? "1" : "2";
$ret .= replace_elements($template["item"], $item);
}
}
else
{
$ret .= $template["no-items"];
}
$ret .= $template["end"];
$ret .= $template["buttons"];
$ret = replace_elements($ret, $el);
return $ret;
}
function read_template($file)
{
$ret = array();
$template = file_read($file);
$temp = explode("{repeat}", $template);
$ret["start"] = $temp[0];
$temp = explode("{/repeat}", $temp[1]);
$ret["item"] = $temp[0];
$ret["end"] = $temp[1];
return $ret;
}
function get_breadcrumb($items, $divider = " \ ")
{
$ret = "";
if (!empty($items))
{
$count = 0;
$total = count($items);
foreach($items as $details)
{
$count++;
$ret .= " ".$details["title"]." ";
if ($count < $total)
$ret .= $divider;
}
}
return $ret;
}
function get_tabs($tabs, $tabs_active = false)
{
global $cfg;
$ret = "";
if (!empty($tabs))
{
$template = templatefile_read("lib/".$cfg["app"]["version"]."/html/html/default-tabs.html");
$ret .= $template["start"];
$count = 0;
$total = count($tabs);
foreach($tabs as $key => $details)
{
$count++;
$c_template = "";
if ($key == $tabs_active)
{
if ($count == 1)
$c_template = "active-first";
else if ($count == $total)
$c_template = "active-last";
else
$c_template = "active-item";
}
else
{
if ($count == 1)
$c_template = "normal-first";
else if ($count == $total)
$c_template = "normal-last";
else
$c_template = "normal-item";
}
$ret .= replace_elements($template[$c_template], $details);
}
$ret .= $template["end"];
}
return $ret;
}
function get_breadcrumb_public($menu_id, $dir_fix, $lang_suffix)
{
global $cfg, $db;
$data = $db->query("SELECT meit_id, meit_menu_id, meit_parent, meit_order, meit_title, meit_page_id, meit_link FROM ".$cfg["mysql"]["prefix"]."menu_item WHERE meit_id='".$menu_id."' and meit_status='Y' limit 1");
foreach ($data as $details)
{
$data2 = $db->query("select page_url from ".$cfg["mysql"]["prefix"]."page where page_id=".$details['meit_page_id']);
if (!empty($data))
$data2 = $data2[0];
//$ret[] = ''.$details['meit_title'].' ';
$ret[] = $details['meit_title'];
if ($details['meit_parent'] > 0)
{
$ret[] = get_breadcrumb_public($details['meit_parent'], $dir_fix, $lang_suffix);
}
}
return join(' / ', array_reverse($ret));
}
function url_string($str, $file = true)
{
$str = trim($str);
$str = strtolower($str);
$str = preg_replace("/[^a-z0-9\s]/", "", $str);
$str = str_replace(" ", " ", $str);
$str = str_replace(" ", "-", $str);
if ($file)
$str .= '.html';
return $str;
}
function render_datatable($div_name, $table)
{
global $cfg, $_encoder;
return "
";
}
function decode_get_2()
{
global $cfg, $_IN, $_encoder;
$_IN = array();
$str = $_GET['itl'];
$str = $_encoder->decode($str);
$temp = explode("&", $str);
if(!empty($temp))
{
foreach($temp as $key => $keyval)
{
$temp2 = explode("=", $keyval);
$in_key = array_shift($temp2);
if ($in_key != "")
{
$in_value = implode("=", $temp2);
$_IN[$in_key] = $in_value;
}
}
}
}
function strsplit($str, $l = 1)
{
do
{
$ret[] = substr($str, 0, $l);
$str = substr($str, $l);
}
while($str != "");
return $ret;
}
function crpyt_obfuscate($str)
{
$ret = "";
$split = strsplit($str, ceil(strlen($str)/2));
$str_l = $split[0];
$str_r = $split[1];
for($i=0; $i $keyval)
{
$temp2 = explode("=", $keyval);
$in_key = array_shift($temp2);
$in_value = implode("=", $temp2);
$_IN[$in_key] = $in_value;
}
}
}
}
function link_encode($url)
{
global $cfg, $_IN;
$link = "";
$temp = explode("?", $url);
$link = $temp[0];
if (isset($temp[1]))
{
$link .= "?itl=".cm_encrypt($temp[1]);
}
return $link;
}
function link_encodepub($url)
{
global $cfg, $_IN;
$link = "";
$temp = explode("?", $url);
$link = $temp[0];
if (isset($temp[1]))
{
$link .= cm_encrypt($temp[1]);
}
return $link;
}
function redirect($url, $url_obfuscate = true)
{
$link = ($url_obfuscate) ? link_encode($url) : $url;
header("location: ".$link);
die();
}
function newsmenu()
{
global $_IN, $files, $cfg, $_USER, $_url, $pdo;
//lets get out the url
if ($_url[0] == "news")
{
$first = "0";
$first2 = "0";
$first3 = "0";
$roothome = "0";
$catTitle = $_url[1];
if($_url[1] == "index.html")
{
// default news page - set first item to be active
$first = "1";
$first2 = "0";
$first3 = "1";
$roothome = "1";
}
//we are on a store page
if ($_url[2] == "index.html")
{
// WE HAVE ONLY ONE CAT, THIS PAGE SHOWS THIS CATS PRODUCTS
$catTitle = $_url[1];
$first2 = "1";
}
else
{
//the first char. of the second part of the url is not a number, thismeans we havea sub cat to show.
//lets work out if theres is a product to show in this cat, or if to show the subcat page
if ($_url[3] == "index.html")
{
// THERE IS NO PROD SELECTRED - SHOW SUBCAT
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
else
{
// WE HAVE A PROD SELECTED IN THE SUBCAT - SHOW
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
}
}
$productsArray = array();
$childrenArray = array();
$catsel = "SELECT * FROM news_sec WHERE status='1' ORDER BY korder ASC";
$catselr = $pdo->query($catsel);
while ($cat = $catselr->fetch(PDO::FETCH_ASSOC))
{
$selectkids = "SELECT COUNT(*) FROM news_items WHERE status='1' AND sec='$cat[id]' ORDER BY korder ASC";
$kidq = $pdo->query($selectkids);
$numkids = $kidq->fetchColumn();
$url = image_filename($cat[title]);
$urlor = $url;
$url = "{dir_fix}news/$url/";
$title = $cat['title'];
if($numkids != "0")
{
$childrenArray = array();
//$url = "#";
$selectkids = "SELECT * FROM news_items WHERE status='1' AND sec='$cat[id]' ORDER BY korder ASC";
$kidq = $pdo->query($selectkids);
while($child = $kidq->fetch(PDO::FETCH_ASSOC))
{
$url2 = image_filename($child['title']);
$title2 = $child['title'];
$test = array("id" => "$title2", "title" => "$title2", "url" => "{dir_fix}news/$urlor/$url2/", "target" => "", "keys" => array("$url2"), "children" => "");
array_push($childrenArray,$test);
}
$childrenArray2[] = array("title" => $cfg["html"]["title"], "items" => $childrenArray);
// print_r($childrenArray);
$test = array("id" => "$title", "title" => "$title", "url" => "$url", "target" => "", "keys" => array("$urlor"), "children" => $childrenArray2 );
array_push($productsArray,$test);
}
// moved last two lines above } so only gets added if there are children as there is no top level only page here
unset($childrenArray);
unset($childrenArray2);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
//print_r($menus);
$template = $files->read("control/lib/html/1.0/public/news.html", true);
foreach($menus as $menu_details)
{
$ret .= replace_elements($template["menu-start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
if($item_details["children"] != "")
{
/* BEGIN SUB CAT */
// if($first == "1")
// {
// $headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start-active"] : $template["menu-item-start-active"];
// $first = "0";
// }
// else
// {
$headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start"] : $template["menu-item-start-active"];
// }
$item_details["children1"] .= replace_elements($headtemplate, $menu_details_sub);
$subfirst = "0";
foreach($item_details["children"] as $menu_details_sub)
{
foreach($menu_details_sub["items"] as $item_details_sub)
{
if ($item_details_sub["target"] == "")
{
$item_details_sub["target"] = "_self";
}
$item_details_sub["children1"] = "";
if(in_array($catTitle, $item_details["keys"]) && $first2 == "1" || $roothome == "1" && $first2 == "1")
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
$first2 = "0";
}
else
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
}
$item_details["children1"] .= replace_elements($current_template2, $item_details_sub);
}
}
$item_details["children1"] .= replace_elements($template["menu-end"], $menu_details_sub);
/*END SUB CAT */
}
else
{
$item_details["children1"] = "";
}
//if($first3 == "1")
//{
// $current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
// $first3 = "0";
//}
//else
//{
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
//}
$ret .= replace_elements($current_template, $item_details);
}
}
$ret .= replace_elements($template["menu-end"], $menu_details);
}
return $ret;
}
function jamenu()
{
global $_IN, $files, $cfg, $_USER, $_url, $pdo;
$archivedate = strtotime(base('1040').' weeks ago');
//lets get out the url
if ($_url[0] == "jobs-auditions")
{
$first = "0";
$first2 = "0";
$first3 = "0";
$roothome = "0";
$catTitle = $_url[1];
if($_url[1] == "index.html")
{
// default support page - set first item to be active
$first = "1";
$first2 = "0";
$first3 = "1";
$roothome = "1";
}
//we are on a store page
if ($_url[2] == "index.html")
{
// WE HAVE ONLY ONE CAT, THIS PAGE SHOWS THIS CATS PRODUCTS
$catTitle = $_url[1];
$first2 = "1";
}
else
{
//the first char. of the second part of the url is not a number, thismeans we havea sub cat to show.
//lets work out if theres is a product to show in this cat, or if to show the subcat page
if ($_url[3] == "index.html")
{
// THERE IS NO PROD SELECTRED - SHOW SUBCAT
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
else
{
// WE HAVE A PROD SELECTED IN THE SUBCAT - SHOW
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
}
}
$productsArray = array();
$childrenArray = array();
$catsel = "SELECT * FROM job_cats WHERE status='1' ORDER BY title ASC";
$catselr = $pdo->query($catsel);
while ($cat = $catselr->fetch(PDO::FETCH_ASSOC))
{
$url = image_filename($cat['title']);
$urlor = $url;
$url = "{dir_fix}jobs-auditions/$url/";
$title = $cat['title'];
$getall = "SELECT * FROM jobs_listedcats WHERE value='" . $cat['id'] . "'";
$queryall = $pdo->query($getall);
$countjobs = 0;
while($all = $queryall->fetch(PDO::FETCH_ASSOC))
{
//print_r($all);
//exit;
//Array ( [id] => 227 [jobid] => 234 [userid] => 2739 [label] => 2 [value] => 2 )
// get item
$getall2 = "SELECT * FROM jobs WHERE id='" . $all['jobid'] . "'";
$queryall2 = $pdo->query($getall2);
$all2 = $queryall2->fetch(PDO::FETCH_ASSOC);
if ("" == $all2) continue;
if($all2['job_status'] == "1" && $all2['dateadded'] >= $archivedate)
{
$countjobs++;
}
}
if($countjobs == "0")
{
$extra = "";
}
else
{
$extra = " ($countjobs) ";
}
// print_r($childrenArray);
$test = array("id" => "$title", "title" => "$title$extra", "url" => "$url", "target" => "", "keys" => array("$urlor"));
array_push($productsArray,$test);
// moved last two lines above } so only gets added if there are children as there is no top level only page here
unset($childrenArray);
unset($childrenArray2);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
//print_r($menus);
$template = $files->read("control/lib/html/1.0/public/jobs_auditions.html", true);
foreach($menus as $menu_details)
{
$ret .= replace_elements($template["menu-start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
if(isset($item_details["children"] ) && $item_details["children"] != "")
{
/* BEGIN SUB CAT */
// if($first == "1")
// {
// $headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start-active"] : $template["menu-item-start-active"];
// $first = "0";
// }
// else
// {
$headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start"] : $template["menu-item-start-active"];
// }
$item_details["children1"] .= replace_elements($headtemplate, $menu_details_sub);
$subfirst = "0";
foreach($item_details["children"] as $menu_details_sub)
{
foreach($menu_details_sub["items"] as $item_details_sub)
{
if ($item_details_sub["target"] == "")
{
$item_details_sub["target"] = "_self";
}
$item_details_sub["children1"] = "";
if(in_array($catTitle, $item_details["keys"]) && $first2 == "1" || $roothome == "1" && $first2 == "1")
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
$first2 = "0";
}
else
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
}
$item_details["children1"] .= replace_elements($current_template2, $item_details_sub);
}
}
$item_details["children1"] .= replace_elements($template["menu-end"], $menu_details_sub);
/*END SUB CAT */
}
else
{
$item_details["children1"] = "";
}
//if($first3 == "1")
//{
// $current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
// $first3 = "0";
//}
//else
//{
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
//}
$ret .= replace_elements($current_template, $item_details);
}
}
$ret .= replace_elements($template["menu-end"], $menu_details);
}
return $ret;
}
function kbmenu()
{
global $_IN, $files, $cfg, $_USER, $_url, $pdo;
//lets get out the url
if ($_url[0] == "support")
{
$first = "0";
$first2 = "0";
$first3 = "0";
$roothome = "0";
$catTitle = $_url[1];
if($_url[1] == "index.html")
{
// default support page - set first item to be active
$first = "1";
$first2 = "0";
$first3 = "1";
$roothome = "1";
}
//we are on a store page
if ($_url[2] == "index.html")
{
// WE HAVE ONLY ONE CAT, THIS PAGE SHOWS THIS CATS PRODUCTS
$catTitle = $_url[1];
$first2 = "1";
}
else
{
//the first char. of the second part of the url is not a number, thismeans we havea sub cat to show.
//lets work out if theres is a product to show in this cat, or if to show the subcat page
if ($_url[3] == "index.html")
{
// THERE IS NO PROD SELECTRED - SHOW SUBCAT
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
else
{
// WE HAVE A PROD SELECTED IN THE SUBCAT - SHOW
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
}
}
$productsArray = array();
$childrenArray = array();
$catsel = "SELECT * FROM knowledgebase_sec WHERE status='1' ORDER BY korder ASC";
$catselr = $pdo->query($catsel);
while ($cat = $catselr->fetch(PDO::FETCH_ASSOC))
{
$selectkids = "SELECT COUNT(*) FROM knowledgebase_items WHERE status='1' AND sec='$cat[id]' ORDER BY korder ASC";
$kidq = $pdo->query($selectkids);
$numkids = $kidq->fetchColumn();
$url = image_filename($cat['title']);
$urlor = $url;
$url = "{dir_fix}support/$url/";
$title = $cat['title'];
if($numkids != "0")
{
$childrenArray = array();
//$url = "#";
$selectkids = "SELECT * FROM knowledgebase_items WHERE status='1' AND sec='$cat[id]' ORDER BY korder ASC";
$kidq = $pdo->query($selectkids);
while($child = $kidq->fetch(PDO::FETCH_ASSOC))
{
$url2 = image_filename($child['title']);
$title2 = $child['title'];
$test = array("id" => "$title2", "title" => "$title2", "url" => "{dir_fix}support/$urlor/$url2/", "target" => "", "keys" => array("$url2"), "children" => "");
array_push($childrenArray,$test);
}
$childrenArray2[] = array("title" => $cfg["html"]["title"], "items" => $childrenArray);
// print_r($childrenArray);
$test = array("id" => "$title", "title" => "$title", "url" => "$url", "target" => "", "keys" => array("$urlor"), "children" => $childrenArray2 );
array_push($productsArray,$test);
}
// moved last two lines above } so only gets added if there are children as there is no top level only page here
unset($childrenArray);
unset($childrenArray2);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
//print_r($menus);
$template = $files->read("control/lib/html/1.0/public/support.html", true);
foreach($menus as $menu_details)
{
$ret .= replace_elements($template["menu-start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
if($item_details["children"] != "")
{
/* BEGIN SUB CAT */
// if($first == "1")
// {
// $headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start-active"] : $template["menu-item-start-active"];
// $first = "0";
// }
// else
// {
$headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start"] : $template["menu-item-start-active"];
// }
$item_details["children1"] .= replace_elements($headtemplate, $menu_details_sub);
$subfirst = "0";
foreach($item_details["children"] as $menu_details_sub)
{
foreach($menu_details_sub["items"] as $item_details_sub)
{
if ($item_details_sub["target"] == "")
{
$item_details_sub["target"] = "_self";
}
$item_details_sub["children1"] = "";
if(in_array($catTitle, $item_details["keys"]) && $first2 == "1" || $roothome == "1" && $first2 == "1")
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
$first2 = "0";
}
else
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
}
$item_details["children1"] .= replace_elements($current_template2, $item_details_sub);
}
}
$item_details["children1"] .= replace_elements($template["menu-end"], $menu_details_sub);
/*END SUB CAT */
}
else
{
$item_details["children1"] = "";
}
//if($first3 == "1")
//{
// $current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
// $first3 = "0";
//}
//else
//{
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
//}
$ret .= replace_elements($current_template, $item_details);
}
}
$ret .= replace_elements($template["menu-end"], $menu_details);
}
return $ret;
}
// KB SEARCH
// Some functions
function search_split_terms($terms){
$terms = preg_replace("/\"(.*?)\"/", "search_transform_term('\$1')", $terms);
$terms = preg_split("/\s+|,/", $terms);
$out = array();
foreach($terms as $term){
$term = preg_replace("/\{WHITESPACE-([0-9]+)\}/", "chr(\$1)", $term);
$term = preg_replace("/\{COMMA\}/", ",", $term);
$out[] = $term;
}
return $out;
}
function search_transform_term($term){
$term = preg_replace("/(\s)/", "'{WHITESPACE-'.ord('\$1').'}'", $term);
$term = preg_replace("/,/", "{COMMA}", $term);
return $term;
}
function search_escape_rlike($string){
return preg_replace("/([.\[\]*^\$])/", '\\\$1', $string);
}
function search_db_escape_terms($terms){
$out = array();
foreach($terms as $key=>$term){
// If string length is 4 or above - will leave a 3
if(strlen($term) >= 4)
{
// Remove Trailing S (should get rid of plurals)
$term = preg_replace("/s$/","",$term);
// Remove Trailing ED - eg minced - mince
$term = preg_replace("/ed$/","e",$term);
}
// $out[] = '[[:<:]]'.AddSlashes(search_escape_rlike($term)).'[[:>:]]';
if($term == "&"){
$out[] = ''.AddSlashes(search_escape_rlike($term)).'';
}
else if(strlen($term) < 3)
{
//echo strlen($term);
if($term == "-"){
unset($terms[$key]);
}else
{
$out[] = '[[:<:]]'.AddSlashes(search_escape_rlike($term)).'[[:>:]]';
}
}
else
{
$out[] = '[[:<:]]'.AddSlashes(search_escape_rlike($term)).'.*[[:>:]]';
}
}
return $out;
}
function search_highlight_do($fragment, $color){
return "".
"$fragment ";
}
function search_highlight_inner($text, $terms_rx){
$colors = search_get_highlight_colors();
foreach($terms_rx as $term_rx){
$color = array_shift($colors);
$text = preg_replace(
"/($term_rx)/ise",
"search_highlight_do(StripSlashes('\\1'), \$color)",
$text
);
}
return $text;
}
function search_get_highlight_colors(){
return array(
array('#ffff66','#000000'),
array('#A0FFFF','#000000'),
array('#99ff99','#000000'),
array('#ff9999','#000000'),
array('#ff66ff','#000000'),
array('#880000','#ffffff'),
array('#00aa00','#ffffff'),
array('#886800','#ffffff'),
array('#004699','#ffffff'),
array('#990099','#ffffff'),
);
}
function search_highlight($text, $terms_rx){
$start = '(^)';
$end = '($)';
// $start = '';
// $end = '';
return preg_replace(
"/$start(.*?)$end/se",
"StripSlashes('\\1').".
"search_highlight_inner(StripSlashes('\\2'), \$terms_rx).".
"StripSlashes('\\3')",
$text
);
}
function search_perform($terms,$database){
global $pdo;
$terms = search_split_terms($terms);
$terms_db = search_db_escape_terms($terms);
$terms_rx = search_rx_escape_terms($terms);
$parts = array();
foreach($terms_db as $term_db){
/* if($database == "knowledgebase_items")
{
$parts[] = "(title RLIKE '$term_db' OR itemcontent RLIKE '$term_db')";
}
else if($database == "news_items")
{
$parts[] = "((title RLIKE '$term_db' OR itemcontent RLIKE '$term_db') AND itemcontent!='')";
}*/
if($database == "knowledgebase_items")
{
$parts[] = "((title RLIKE '$term_db' OR itemcontent RLIKE '$term_db') AND status='1')";
}
else if($database == "news_items")
{
$parts[] = "((title RLIKE '$term_db' OR itemcontent RLIKE '$term_db') AND itemcontent!='' AND status='1')";
}
else
{
$parts[] = "(shortname RLIKE '$term_db' OR subpagecontent RLIKE '$term_db')";
}
}
$parts = implode(' AND ', $parts);
$sql = "SELECT * FROM $database WHERE $parts";
// echo $sql;
$rows = array();
$result = $pdo->query($sql);
while($row = $result->fetch(PDO::FETCH_ASSOC)){
// print_r($terms_rx);
$content = $row['itemcontent'];
$row['content'] = $content;
// echo $content;
// Get the base score of the category this item is in
//$getcat= "SELECT * FROM shop_itemcats WHERE itemid='$row[id]'";
//$getcat2 = mysql_query($getcat);
//$cat = mysql_fetch_array($getcat2);
// Lookup cat name
//$getcatname = "SELECT * FROM shop_cats WHERE id ='$cat[catid]'";
// $getcatname2 = mysql_query($getcatname);
//$catdetails = mysql_fetch_array($getcatname2);
$row['thiscat'] = "$row[korder]";
$row['score'] = 0;
foreach($terms_rx as $term_rx){
$row['score'] += preg_match_all("/$term_rx/i", $row['itemcontent'], $null);
}
$rows[] = $row;
// foreach($terms_rx as $term_rx){
// $row[score] += preg_match_all("/$term_rx/i", $row[title], $null);
// echo $terms_rx;
// echo $catdetails[cat_order]; echo $row[title]; echo $row[score]; echo " ";
// }
// $rows[] = $row;
}
// print_r($rows);
uasort($rows, 'search_sort_results');
return $rows;
}
function search_rx_escape_terms($terms){
$out = array();
foreach($terms as $term){
$out[] = '\b'.preg_quote($term, '/').'\b';
}
return $out;
}
function search_sort_results($a, $b){
// $cx = $a[thiscat];
// $dx = $b[thiscat];
// if ($cx == $dx){ return 0; }
// return ($cx < $dx) ? -1 : 1;
$ax = $a['score'];
$bx = $b['score'];
if ($ax == $bx){ return 0; }
return ($ax > $bx) ? -1 : 1;
}
function search_html_escape_terms($terms){
$out = array();
foreach($terms as $term){
if (preg_match("/\s|,/", $term)){
$out[] = '"'.HtmlSpecialChars($term).'"';
}else{
$out[] = HtmlSpecialChars($term);
}
}
return $out;
}
function search_pretty_terms($terms_html){
if (count($terms_html) == 1){
return array_pop($terms_html);
}
$last = array_pop($terms_html);
return implode(', ', $terms_html)." and $last";
}
// Feature Menu
function featuremenu()
{
global $_IN, $files, $cfg, $_USER, $_url;
//lets get out the url
if ($_url[0] == "features")
{
$first = "0";
$first2 = "0";
$first3 = "0";
$roothome = "0";
$catTitle = $_url[1];
if($_url[1] == "index.html")
{
// default support page - set first item to be active
$first = "1";
$first2 = "0";
$first3 = "1";
$roothome = "1";
}
//we are on a store page
if ($_url[2] == "index.html")
{
// WE HAVE ONLY ONE CAT, THIS PAGE SHOWS THIS CATS PRODUCTS
$catTitle = $_url[1];
$first2 = "1";
}
else
{
//the first char. of the second part of the url is not a number, thismeans we havea sub cat to show.
//lets work out if theres is a product to show in this cat, or if to show the subcat page
if ($_url[3] == "index.html")
{
// THERE IS NO PROD SELECTRED - SHOW SUBCAT
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
else
{
// WE HAVE A PROD SELECTED IN THE SUBCAT - SHOW
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
}
}
$productsArray = array();
$childrenArray = array();
$catsel = "SELECT * FROM features WHERE status='1' AND subpagecontent!='' ORDER BY forder ASC";
$catselr = mysql_query($catsel);
while ($cat = mysql_fetch_array($catselr))
{
$title = "$cat[shortname]";
$url = image_filename($cat['shortname']);
$urlor = $url;
$url = "{dir_fix}features/$url/";
$test = array("id" => "$title", "title" => "$title", "url" => "$url", "target" => "", "keys" => array("$urlor") );
array_push($productsArray,$test);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
//print_r($menus);
$template = $files->read("control/lib/public/html/1.0/features.html", true);
foreach($menus as $menu_details)
{
$ret .= replace_elements($template["menu-start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
//if($first3 == "1")
//{
// $current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
// $first3 = "0";
//}
//else
//{
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
//}
$ret .= replace_elements($current_template, $item_details);
}
}
$ret .= replace_elements($template["menu-end"], $menu_details);
}
return $ret;
}
//
function myTruncate($string, $limit, $break=".", $pad="...")
{
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
//replaces pre content with html entities
function pre_entities($matches) {
return str_replace($matches[1],htmlentities($matches[1]),$matches[0]);
}
// function inline image
//parseInlineImg($item1['itemcontent'],"knowledgebase_img",$item1,"gorder","knowledgebase");
function parseInlineImg($in,$db2,$item1,$title,$order,$field)
{
global $_IN, $files, $cfg, $_USER, $_url, $el, $pdo;
//print_r($item1);
$ret = preg_replace_callback('/(.*?)<\/pre>/imsu',pre_entities, $in);
preg_match_all('/\[image(?:[^][]|(?R))*\]/', $in, $matches);
foreach ($matches as $insidematches)
{
foreach ($insidematches as $key=>$value)
{
$org_replace = $value;
$value = str_replace("[","",$value); $value = str_replace("]","",$value);
$imagearray = explode(" ",$value);
$src = strpos($value,"imagesrc");
if ($src === false) {
// was not imagesrc
$type = "1";
$imageorderid = str_replace("image","",$imagearray[0]);
} else {
// we want an image src
$type = "2";
$imageorderid = str_replace("imagesrc","",$imagearray[0]);
}
$selectimg = "SELECT * FROM $db2 WHERE $order=".$pdo->quote($imageorderid)." AND $field=".$pdo->quote($item1['pageid']);
//echo $selectimg;
$queryimg = $pdo->query($selectimg);
$image = $queryimg->fetch(PDO::FETCH_ASSOC);
//echo $selectimg;
//echo $image
switch("$_url[0]")
{
default:
$resizetype = "resize";
$width = "800";
$height = "0";
$quality = "100";
$alt = $image['imgalt'];
break;
case "news":
$resizetype = "resize";
$width = "800";
$height = "0";
$quality = "100";
$alt = $image['idesc'];
break;
}
$filename = ($item1 == "")? "image.jpg" : image_filename($item1[$title]).".jpg";
$align = "";
unset($imagearray[0]);
foreach($imagearray as $variable)
{
//echo $variable;
$exploded = explode("=",$variable);
switch($exploded[0])
{
case "width":
$width = $exploded[1];
break;
case "height":
$height = $exploded[1];
break;
case "quality":
$quality = $exploded[1];
break;
case "type":
$resizetype = $exploded[1];
break;
case "filename":
$filename = $exploded[1];
break;
case "alt":
$alt = $exploded[1];
break;
case "align":
$align = "class=\"";
switch($exploded[1])
{
case "right":
$align .="align-right";
break;
case "left":
$align .="align-left";
break;
case "center":
$align .="align-center";
break;
}
$align .= "\"";
break;
case "clear":
$clear = $exploded[1];
if($clear != "")
{
$align2 = "";
switch($clear)
{
case "right":
$align2 ="right;";
break;
case "left":
$align2 ="left";
break;
case "both":
$align2 ="both";
break;
}
$clear = "
";
}
break;
}
}
if($type == "1")
{
// Image tag
$newvalue = ' '.$clear.'';
}
else if($type == "2")
{
// Just src please
$newvalue = '/images/'.$image['imgid'].'/'.$width.'/'.$height.'/'.$quality.'/'.$resizetype.'/'.$filename;
}
$ret = str_replace($org_replace,$newvalue,$ret);
// print_r($imagearray);
}
}
return $ret;
}
/* MOVED FROM CLASS */
function pageCacheable($page)
{
$select = "SELECT * FROM pages WHERE url='$page'";
$query = mysql_query($select);
if(mysql_num_rows($query) != "0")
{
$result = mysql_fetch_array($query);
return $result['cache'];
}
else
{
// No results found for this page. We could be using a different sort of module, eg store etc.
$_url = explode("/",$page);
if($_url[1] == "ajax" || $_url[0] == "store" || $_url[0] == "gallery" || $_url[0] == "news" || $_url[0] == "login.html" || $_url[0] == "basket.html" || $_url[0] == "checkout.html" || $_url[0] == "checkout2.html" || $_url[0] == "index.html")
{
return "0";
}
else
{
return "1";
}
}
}
function fopen_recursive($path, $mode, $chmod=0755)
{
$directory = DIRNAME($path);
$file = BASENAME($path);
// echo $directory;
IF (!IS_DIR($directory)) {
unlink($directory);
MKDIR($directory, $chmod, 1);
}
RETURN FOPEN ($path, $mode);
}
function searchArray($array, $key, $value)
{
$results = array();
if (is_array($array))
{
if ($array[$key] == $value)
$results[] = $array;
foreach ($array as $subarray)
$results = array_merge($results, searchArray($subarray, $key, $value));
}
return $results;
}
function case_url($in)
{
//$get case
$get = "SELECT * FROM casestudies WHERE id='$in'";
$query = mysql_query($get);
$case = mysql_fetch_array($query);
$url .= "{dir_fix}case-study/";
$url .= image_filename($case['title']);
$url .= "-$in.html";
$url = str_replace("--","-",$url);
return $url;
}
function image_filename($in)
{
$title = $in;
$title = strtolower($title);
$title = str_replace(" ", "-", $title);
$title = str_replace("&", "and", $title);
$title = str_replace("&", "and", $title);
$title = str_replace(" ","-",$title);
$title = str_replace(" ","-",$title);
$title = str_replace("/","-",$title);
$title = str_replace("(","",$title);
$title = str_replace(")","",$title);
$title = str_replace("---","-",$title);
$title = str_replace("--","-",$title);
$title = preg_replace('|[^a-z0-9-]|', '', $title);
$title = ($title[0] == "-") ? substr($title,1) : $title;
return $title;
}
function checkoutProgress()
{
/*
*/
global $_url, $template, $files, $checkoutArray;
$ret = "";
$template = $files->read("control/lib/html/1.0/checkout-progress.html", true);
$checkoutArray = array();
$checkoutArray[] = array("url"=>array("login.html","register.html"),"title"=>"login","link"=>"login.html");
$checkoutArray[] = array("url"=>array("checkout.html"),"title"=>"delivery","link"=>"checkout.html");
$checkoutArray[] = array("url"=>array("checkout2.html"),"title"=>"verify","link"=>"checkout2.html");
$checkoutArray[] = array("url"=>array("checkout3.html"),"title"=>"payment","link"=>"checkout3.html");
$checkoutArray[] = array("url"=>array("order-failure.html","order-successful.html"),"title"=>"confirmation","link"=>"order-successful.html");
if (isset($template["start"])) $ret .= $template["start"];
$touse = "visited";
foreach ($checkoutArray as $item)
{
if(in_array($_url[0], $item["url"]))
{
$ret .= replace_elements($template["active"], $item);
$touse = "disabled";
}
else
{
if (is_null($touse) || is_null($template)) {}
else $ret .= replace_elements($template[$touse], $item);
}
}
if (is_array($template)) $ret .= $template["end"];
return $ret;
}
function pagesideMenuHeader($page)
{
global $_IN, $files, $cfg, $_USER, $_url, $items, $pdo;
//Find in $items array the id.
// $ret = searchArray($items,"id","$page");
//return $ret[0][title];
$psel= "SELECT * FROM pages WHERE id=".$pdo->quote($page);
$pselr = $pdo->query($psel);
$page_f = $pselr->fetch(PDO::FETCH_ASSOC);
return $page_f['title'];
}
function pagesideMenu($page)
{
global $_IN, $files, $cfg, $_USER, $_url, $pdo;
$productsArray = array();
$psel= "SELECT * FROM pages WHERE id=".$pdo->quote($page);
$pselr = $pdo->query($psel);
$page_f = $pselr->fetch(PDO::FETCH_ASSOC);
$getcontent2 = "SELECT * FROM pagecontent WHERE pageid=".$pdo->quote($page);
$querycontent2 = $pdo->query($getcontent2);
$content2 = $querycontent2->fetch(PDO::FETCH_ASSOC);
$ptitle = $page_f['name'];
$purl = $page_f['url'];
$ptest = array("id" => "$ptitle", "title" => "$page_f[menutitle]", "menutitle"=>"$page_f[menuname]","url" => "$purl/", "target" => "", "keys" => array("$purl"), "children" => "" );
array_push($productsArray,$ptest);
$urlarray = implode($_url,"/");
$urlarray = str_replace("/index.html","",$urlarray);
$catTitle = $urlarray;
$catsel = "SELECT * FROM pages WHERE status='1' AND menustatus='1' AND parent=".$pdo->quote($page)." ORDER BY porder ASC";
$catselr = $pdo->query($catsel);
while ($pages = $catselr->fetch(PDO::FETCH_ASSOC))
{
$getcontent = "SELECT * FROM pagecontent WHERE pageid=".$pdo->quote($pages['id']);
$querycontent = $pdo->query($getcontent);
$content = $querycontent->fetch(PDO::FETCH_ASSOC);
$url = $pages['url'];
$title = $pages['name'];
// check for children
$select1c = "SELECT * FROM pages WHERE status='1' AND menustatus='1' AND parent=".$pdo->quote($pages['id'])." ORDER BY porder ASC";
$query1c = $pdo->query($select1c);
if($query1c->fetchColumn() == "0")
{
$childrenarray = "";
}
else
{
$select1 = "SELECT * FROM pages WHERE status='1' AND menustatus='1' AND parent=".$pdo->quote($pages['id'])." ORDER BY porder ASC";
$query1 = $pdo->query($select1);
$childrenarray = array();
while($parentcheck1 = $query1->fetch(PDO::FETCH_ASSOC))
{
$getcontent3 = "SELECT * FROM pagecontent WHERE pageid=".$pdo->quote($parentcheck1['id']);
$querycontent3 = $pdo->query($getcontent3);
$content3 = $querycontent3->fetch(PDO::FETCH_ASSOC);
$ptitle2 = $parentcheck1['name'];
$purl2 = $parentcheck1['url'];
$ptest2 = array("id" => "$ptitle2", "title" => "$parentcheck1[menutitle]", "menutitle"=>"$page_f[menuname]","url" => "$purl2", "target" => "", "keys" => array("$purl2"), "children" => "" );
array_push($childrenarray,$ptest2);
}
}
$test = array("id" => "$title", "title" => "$pages[menutitle]", "menutitle"=>"$page_f[menuname]","url" => "$url", "target" => "", "keys" => array("$url"), "children" => $childrenarray );
array_push($productsArray,$test);
// print_r($productsArray);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
/* echo "";
print_r($menus);
echo " ";*/
$template = $files->read("control/lib/html/1.0/public/content-page-submenu.html", true);
foreach($menus as $menu_details)
{
$menu_details['menutitle'] = $page_f['menuname'];
$ret .= replace_elements($template["start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if($item_details["type"] == "div")
{
$ret .= $template["div"];
}
else
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
// print_r($item_details);
if($item_details["children"] != "")
{
/* BEGIN SUB CAT */
$headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["start-sub"] : $template["start"];
$item_details["children1"] .= replace_elements($headtemplate, $menu_details_sub);
foreach($item_details["children"] as $item_details_sub)
{
// foreach($menu_details_sub["items"] as $item_details_sub)
// {
if ($item_details_sub["target"] == "")
{
$item_details_sub["target"] = "_self";
}
$item_details_sub["children1"] = "";
$current_template2 = (!in_array($catTitle, $item_details_sub["keys"])) ? $template["item"] : $template["active"];
$item_details["children1"] .= replace_elements($current_template2, $item_details_sub);
// }
}
$item_details["children1"] .= replace_elements($template["end"], $menu_details_sub);
/*END SUB CAT */
$catTitle2 = explode("/",$catTitle);
// print_r($catTitle2);
// print_r($item_details);
$testarray= array();
foreach($item_details["keys"] as $key=>$value)
{
$value = str_replace("/","",$value);
$key2 = $value;
array_push($testarray,$key2);
}
$keys123 = str_replace("/","",$item_details["keys"][0]);
$current_template = ($catTitle2[0] != $keys123) ? $template["item"] : $template["active"];
$ret .= replace_elements($current_template, $item_details);
}
else
{
$item_details["children1"] = "";
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["item"] : $template["active"];
$ret .= replace_elements($current_template, $item_details);
}
}
}
}
$ret .= replace_elements($template["end"], $menu_details);
}
return $ret;
}
function priceDisplay($productID)
{
/* Price logic as follows:
* If no children - display price from control
* If we have chlidren:
* - if all children are the same price - display price
* - else if prices different - display from
*/
//Lookup Product
$select_product_query = "SELECT * FROM shop_items WHERE id='$productID'";
$select_product_result = mysql_query($select_product_query);
$product = mysql_fetch_array($select_product_result);
//Has children
$select_children_query = "SELECT * FROM shop_items WHERE parent_sku = '$product[sku]' ORDER BY price ASC";
$select_children_result = mysql_query($select_children_query);
if(mysql_num_rows($select_children_result) == "0")
{
// No children found - we format & display price from control
$price = number_format($product['price'],2);
if($product['price_per'] == "3")
{
$price = $price*0.1;
$price = number_format($price,2);
}
$returnPrice = "£$price";
}
else
{
// Children found - we need to work out if all the child prices are equal.
$allSame = 1;
while($child = mysql_fetch_array($select_children_result))
{
if(!isset($value))
{
// This is the first child - nothing to compare to yet, so set the value
$value = $child['price'];
}
else
{
// This is not the first child, lets compare it to the first child
if($value != $child['price'])
{
// Price is NOT the same as the previous one - lets update the all same variable otherwise nothing will happen.
$allSame = 0;
}
}
}
$price = number_format($value,2);
// Now we have been through and checked all the children
if($allSame != "1")
{
// The prices are not the same we need to add FROM into the price.
$returnPrice = "from £$price";
}
else
{
// Prices all the same, return just price
$returnPrice = "£$price";
}
}
if ($product['price_per'])
{
$unit = ($product['price_per'] == "1") ? "Kg" : "100g";
$unit = ($product['price_per'] == "2") ? "Each" : $unit;
$returnPrice = "$returnPrice/$unit";
}
//Finally - Check if the price is 0.00 if so then we dont want to display it
if (strpos($returnPrice, "0.00"))
{
return " ";
}
else
{
return $returnPrice;
}
}
function generate_meta(&$page, &$main_el)
{
global $pdo;
// Title
if ($page['pagetitle'] != "")
{
$main_el['pagetitle'] = $page['pagetitle'];
}
else
{
$selectdefault = "SELECT * FROM settings WHERE id='1009'";
$selectdefaultt = $pdo->query($selectdefault);
$titlet = $selectdefaultt->fetch(PDO::FETCH_ASSOC);
$dt = $titlet['value'];
$main_el['pagetitle'] = "$dt";
}
// Keywords
if ($page['metakeywords'] != "")
{
$main_el['metakeywords'] = $page['metakeywords'];
}
else
{
$selectdefault = "SELECT * FROM settings WHERE id='1002'";
$selectdefaultt = $pdo->query($selectdefault);
$keywordt = $selectdefaultt->fetch(PDO::FETCH_ASSOC);
$dk = $keywordt['value'];
$main_el['metakeywords'] = "$dk";
}
// Description
if ($page['metadescription'] != "")
{
$main_el['metadesc'] = $page['metadescription'];
}
else
{
$selectdefault = "SELECT * FROM settings WHERE id='1003'";
$selectdefaultt = $pdo->query($selectdefault);
$desct = $selectdefaultt->fetch(PDO::FETCH_ASSOC);
$dd = $desct['value'];
$main_el['metadesc'] = "$dd";
}
// Default meta tags
if ($page['metatags'] != "")
{
$main_el['default-meta-tags'] = $page['metatags'];
}
else
{
$main_el['default-meta-tags'] = base("1034");
}
//$selectdefaultt->closeCursor();
}
function generate_countries($selected = "")
{
/*$query = "SELECT * FROM shop_country WHERE status='1' ORDER BY ctry_name ASC";
$select = mysql_query($query);
while($country = mysql_fetch_array($select))
{
if ($country["ctry_name"] == $selected)
{
$countries .= "$country[ctry_name] ";
}
else
{
$countries .= "$country[ctry_name] ";
}
}
return $countries;*/
}
function generate_countries_iso($selected = "")
{
/* $query = "SELECT * FROM shop_country WHERE status='1' ORDER BY ctry_name ASC";
$select = mysql_query($query);
while($country = mysql_fetch_array($select))
{
if ($country["ctry_iso_code"] == $selected)
{
$countries .= "$country[ctry_name] ";
}
else
{
$countries .= "$country[ctry_name] ";
}
}
return $countries;*/
}
function product_menu()
{
global $_IN, $files, $cfg, $_USER, $_url;
//lets get out the url
if ($_url[0] == "store")
{
$catTitle = $_url[1];
//we are on a store page
if ($_url[2] == "index.html")
{
// WE HAVE ONLY ONE CAT, THIS PAGE SHOWS THIS CATS PRODUCTS
$catTitle = $_url[1];
}
else
{
// WE COULD HAVE A SUBCAT OR A PRODUCT ID
$firstletter = substr($_url[2], 0, 1);
if (!is_numeric($firstletter))
{
//the first char. of the second part of the url is not a number, thismeans we havea sub cat to show.
//lets work out if theres is a product to show in this cat, or if to show the subcat page
if ($_url[3] == "index.html")
{
// THERE IS NO PROD SELECTRED - SHOW SUBCAT
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
else
{
// WE HAVE A PROD SELECTED IN THE SUBCAT - SHOW
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
}
else
{
//first char of url2 is numeric, this is the prod id of the product.
}
}
}
$productsArray = array();
$catsel = "SELECT * FROM shop_cats WHERE status='1' AND parent_id='0' AND id!='99' ORDER BY cat_order ASC";
$catselr = mysql_query($catsel);
while ($cat = mysql_fetch_array($catselr))
{ $childrenArray = array();
//has children?
$selectkids = "SELECT * FROM shop_cats WHERE status='1' AND parent_id='$cat[id]'";
$kidq = mysql_query($selectkids);
$numkids = mysql_num_rows($kidq);
$url = shop_url($cat['title']);
$title = $cat['title'];
if($numkids != "0")
{
while($child = mysql_fetch_array($kidq))
{
$url2 = shop_url($child['title']);
$title2 = $child['title'];
$test = array("id" => "$title2", "title" => "$title2", "url" => "store/$url/$url2", "target" => "", "keys" => array("$url2"), "children" => "");
array_push($childrenArray,$test);
}
$childrenArray2[] = array("title" => $cfg["html"]["title"], "items" => $childrenArray);
}
$test = array("id" => "$title", "title" => "$title", "url" => "store/$url", "target" => "", "keys" => array("$url"), "children" => $childrenArray2 );
array_push($productsArray,$test);
// print_r($productsArray);
unset($childrenArray);
unset($childrenArray2);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
//print_r($menus);
$template = $files->read("control/lib/public/html/1.0/store-menu.html", true);
foreach($menus as $menu_details)
{
$ret .= replace_elements($template["start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if($item_details["type"] == "div")
{
$ret .= $template["div"];
}
else
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
if($item_details["children"] != "")
{
/* BEGIN SUB CAT */
$headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["start-sub"] : $template["start"];
$item_details["children1"] .= replace_elements($headtemplate, $menu_details_sub);
foreach($item_details["children"] as $menu_details_sub)
{
foreach($menu_details_sub["items"] as $item_details_sub)
{
if ($item_details_sub["target"] == "")
{
$item_details_sub["target"] = "_self";
}
$item_details_sub["children1"] = "";
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["item"] : $template["active"];
$item_details["children1"] .= replace_elements($current_template2, $item_details_sub);
}
}
$item_details["children1"] .= replace_elements($template["end"], $menu_details_sub);
/*END SUB CAT */
}
else
{
$item_details["children1"] = "";
}
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["item"] : $template["active"];
$ret .= replace_elements($current_template, $item_details);
}
}
}
$ret .= replace_elements($template["end"], $menu_details);
}
return $ret;
}
function shop_url($in)
{
$title = $in;
$title = strtolower($title);
$title = str_replace(" ", "-", $title);
$title = str_replace("&", "and", $title);
$title = str_replace("&", "and", $title);
$title = str_replace("/", "_", $title);
$title = str_replace(",","",$title);
$title = image_filename($title);
return $title;
}
function return_url()
{
global $cfg, $_url, $_SERVER;
$current = $_SERVER["SCRIPT_NAME"];
//$request = $_SERVER["REDIRECT_URL"];
$request = $_SERVER["REQUEST_URI"];
//$request = $_SERVER["REQUEST_URI"]; // changed from REQUEST_URL TO URI as suddenly stopped working on heartinternet
//echo "*".$current." ".$request;
//print_R($_SERVER); echo "* ";
$server = explode(".", $_SERVER["HTTP_HOST"]);
/*if (count($server) > 1)
{
if ($server[0] != "www")
{
$redirect = "http://www.".implode(".", $server).$_SERVER["REDIRECT_URL"];
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$redirect);
}
}*/
/*if (!empty($_GET))
{
$redirect = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REDIRECT_URL"];
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$redirect);
}*/
$temp = explode("/", $current);
$temp2 = explode("/", $request);
$remove = count($temp)-1;
for($i = 0; $i < $remove; $i++)
{
array_shift($temp2);
}
$last = $temp2[count($temp2)-1];
$depth = count($temp2)-1;
$cfg["url"]["depth_fix"] = str_repeat("../", $depth);
if ($last == "")
{
$temp2[count($temp2)-1] = "index.html";
}
else
{
$last_temp = explode("&", $last);
$temp2[count($temp2)-1] = $last_temp[0];
$last = $temp2[count($temp2)-1];
$redirect = $cfg["url"]["depth_fix"].implode("/", $temp2)."/";
if (!strpos($last, "."))
{
header("location: ".$redirect);
}
}
$_url = $temp2;
$ret = implode("/", $temp2);
//echo "*** ".$ret." ***";
return $ret;
}
function directorySelect($parent = "")
{
global $pdo, $_url;
$content = "";
$select = "SELECT * FROM directory_cats WHERE parent='0' AND status='1' ORDER BY title ASC";
$query = $pdo->query($select);
while($fetch = $query->fetch(PDO::FETCH_ASSOC))
{
$url = image_filename($fetch['title']);
if (!array_key_exists(1, $_url)) $_url[1] = "";
$selected = ($_url[1] == $url) ? " selected=\"selected\"" : "";
$content .= "$fetch[title] ";
}
return $content;
}
function directorymenu($parenttitle="")
{
global $_IN, $files, $cfg, $_USER, $_url, $pdo;
if($parenttitle!="")
{
$catTitle = $parenttitle;
}
//lets get out the url
if ($_url[0] == "directory")
{
$first = "0";
$first2 = "0";
$first3 = "0";
$roothome = "0";
$catTitle = $_url[1];
if($_url[1] == "index.html")
{
// default support page - set first item to be active
$first = "1";
$first2 = "0";
$first3 = "1";
$roothome = "1";
}
//we are on a store page
if ($_url[2] == "index.html")
{
// WE HAVE ONLY ONE CAT, THIS PAGE SHOWS THIS CATS PRODUCTS
$catTitle = $_url[1];
$first2 = "1";
}
else
{
//the first char. of the second part of the url is not a number, thismeans we havea sub cat to show.
//lets work out if theres is a product to show in this cat, or if to show the subcat page
if ($_url[3] == "index.html")
{
// THERE IS NO PROD SELECTRED - SHOW SUBCAT
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
else
{
// WE HAVE A PROD SELECTED IN THE SUBCAT - SHOW
$catTitle = $_url[1];
$catTitle2 = $_url[2];
}
}
}
$productsArray = array();
$childrenArray = array();
$catsel = "SELECT * FROM directory_cats WHERE status='1' AND parent='0' ORDER BY title ASC";
$catselr = $pdo->query($catsel);
while ($cat = $catselr->fetch(PDO::FETCH_ASSOC))
{
$url = image_filename($cat['title']);
$urlor = $url;
$url = "{dir_fix}directory/$url/";
$title = $cat['title'];
// print_r($childrenArray);
$test = array("id" => "$title", "title" => "$title", "url" => "$url", "target" => "", "keys" => array("$urlor"));
array_push($productsArray,$test);
// moved last two lines above } so only gets added if there are children as there is no top level only page here
unset($childrenArray);
unset($childrenArray2);
}
$menus[] = array("title" => $cfg["html"]["title"], "items" => $productsArray);
//print_r($menus);
$template = $files->read("control/lib/html/1.0/public/directory.html", true);
$ret = "";
foreach($menus as $menu_details)
{
$ret .= replace_elements($template["menu-start"], $menu_details);
// menu items
if (!empty($menu_details["items"]))
{
foreach($menu_details["items"] as $item_details)
{
if ($item_details["target"] == "")
{
$item_details["target"] = "_self";
}
if(array_key_exists("children", $item_details) && $item_details["children"] != "")
{
/* BEGIN SUB CAT */
// if($first == "1")
// {
// $headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start-active"] : $template["menu-item-start-active"];
// $first = "0";
// }
// else
// {
$headtemplate = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-start"] : $template["menu-item-start-active"];
// }
$item_details["children1"] .= replace_elements($headtemplate, $menu_details_sub);
$subfirst = "0";
foreach($item_details["children"] as $menu_details_sub)
{
foreach($menu_details_sub["items"] as $item_details_sub)
{
if ($item_details_sub["target"] == "")
{
$item_details_sub["target"] = "_self";
}
$item_details_sub["children1"] = "";
if(in_array($catTitle, $item_details["keys"]) && $first2 == "1" || $roothome == "1" && $first2 == "1")
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
$first2 = "0";
}
else
{
$current_template2 = (!in_array($catTitle2, $item_details_sub["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
}
$item_details["children1"] .= replace_elements($current_template2, $item_details_sub);
}
}
$item_details["children1"] .= replace_elements($template["menu-end"], $menu_details_sub);
/*END SUB CAT */
}
else
{
$item_details["children1"] = "";
}
//if($first3 == "1")
//{
// $current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item-active"] : $template["menu-item-active"];
// $first3 = "0";
//}
//else
//{
if (!isset($catTitle)) $catTitle = "";
$current_template = (!in_array($catTitle, $item_details["keys"])) ? $template["menu-item"] : $template["menu-item-active"];
//}
$ret .= replace_elements($current_template, $item_details);
}
}
$ret .= replace_elements($template["menu-end"], $menu_details);
}
return $ret;
}