back
Welcome {$_SESSION["admin_user"]["name"]}

"; // $name = ucwords(str_replace(array(".php", "_", "/site/listings/"), array("", " ", ""), $_SERVER["PHP_SELF"])); // if (!isset($_SESSION["admin_user"]["access"]) || !in_array($name, array_values($_SESSION["admin_user"]["access"]))) { // print "Access Denied"; // exit; } //end $action = $_REQUEST["action"]; if (is_array($action)) { $id = array_shift(array_keys($action)); if (is_array($action[$id])) { $action = $id; } else { $action = $action[$id]; } } else { if (isset($_REQUEST["id"])) $id = $_REQUEST["id"]; } switch ($action) { case "Edit Listing": setup_post($id, false); break; case "Edit Request Listing": setup_post($id, true); break; case "Add Location": if (!isset($_POST["listing"]["new"]["locations"])) $_POST["listing"]["new"]["locations"] = array(); $_POST["listing"]["new"]["locations"][] = array( "id" => -1, "contact_name" => "", "address1" => "", "address2" => "", "city" => "", "country_id" => "", "province_id" => "", "pcode" => "", "phone" => "", "fax" => "", "cell" => "", "tollfree" => "", "email" => "", "email2" => "", "website" => "" ); break; case "Remove Location": unset($_POST["listing"]["new"]["locations"][$id]); break; case "Remove Category": $new_categories = array(); foreach ($_POST["listing"]["new"]["categories"] as $id => $value) { if (!in_array($value, $_POST["remove_categories"])) $new_categories[] = $value; } $_POST["listing"]["new"]["categories"] = $new_categories; break; case "Add Category": foreach ($_POST["new_categories"] as $id => $value) { $_POST["listing"]["new"]["categories"][] = $value; } break; case "Cancel Changes": //----kevin----new code 08-24: admin user header to admin/index.php if (isset($_POST['is_admin']) && $_POST['is_admin'] == true) header("location:/admin/index.php"); else header("location:../main.php"); //end exit; break; case "Delete Listing": $errors = delete_listing($_POST["listing"]["current"]["info"]); if (!count($errors)) { //----kevin----new code 08-24: admin user header to admin/index.php if (isset($_POST['is_admin']) && $_POST['is_admin'] == true) header("location:/admin/index.php"); else header("location:../main.php"); //end exit; } else { $_SESSION["error"] = join("
", $errors); } break; case "Save Changes": if($_POST['is_request_listings_operations'] == true) { $errors = save_listing1(); } else{ $errors = save_listing(); // echo "high"; } if (!count($errors)) { //----kevin----new code 08-24: admin user header to admin/index.php if (isset($_POST['is_admin']) && $_POST['is_admin'] == true) if ($_POST['is_request_listings_operations'] == true) echo 'adction add'; // header("location:/admin/functions/listings_requests.php"); else header("location:/admin/index.php"); else header("location:/site/listings/paypalpage.php"); // echo "It has succesfully been update";} // if ($title == "Add A New Listing") { /* print <<
To subscribe now for as low as $49.00/year, click on the subscribe button below
Payment Options
EOD; // } //end */ exit; } else { $_SESSION["error"] = join("
", $errors); } break; } function save_listing() { global $_POST, $_SESSION; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/dbi.inc"; $db = new Database(); $errors = array(); if (strlen($_POST["listing"]["new"]["info"]["name"]) < 5) $errors[] = "The name must be greater than 4 characters."; if (strlen($_POST["listing"]["new"]["info"]["name"]) > 500) $errors[] = "The name must be less than 500 characters."; if (strlen($_POST["listing"]["new"]["info"]["description"]) < 5) $errors[] = "The description must be greater than 4 characters."; if (!validEmail($_POST["listing"]["new"]["info"]["update_email"])) $errors[] = "You must enter a valid administrator email address, this will be used to confirm changes to the listing but will not be displayed in the listing"; if (count($_POST["listing"]["new"]["locations"]) == 0) $errors[] = "You must include at least one location."; else $errors = array_merge($errors, check_locations()); if (count($_POST["listing"]["new"]["categories"]) == 0) $errors[] = "You must select at least one category."; if (count($errors) > 0) return $errors; // if admin add new listing, data goes to table listings // if customer add new listings, data goes to table request_listings.. $listings_tbl = ""; $listing_business_types_tbl = ""; $listing_locations_tbl = ""; if (isset($_POST['is_admin']) && $_POST['is_admin'] == true) { $listings_tbl = "listings"; $listing_business_types_tbl = "listing_business_types"; $listing_locations_tbl = "listing_locations"; } else { $listings_tbl = "request_listings"; $listing_business_types_tbl = "request_listing_business_types"; $listing_locations_tbl = "request_listing_locations"; } //$id=$_POST["listing"]["current"]["info"]["id"]; $uuid = md5(uniqid()); $_POST["listing"]["new"]["info"]["uuid"] = $uuid; $sql = "insert into " . $listings_tbl . " (name,description,update_to_id,update_confirmation_id,update_email) values ('[name]','[description]','[id]','[uuid]','[update_email]')"; if (!$id = $db->set_data_return_id($sql, $_POST["listing"]["new"]["info"])) { $errors[] = "Unable to update/add listing. " . $db->lasterror; return $errors; } $update_to_id = $_POST["listing"]["new"]["info"]["id"]; $_POST["listing"]["new"]["info"]["id"] = $id; $_POST["listing"]["current"]["info"] = $_POST["listing"]["new"]["info"]; if (isset($_POST["listing"]["new"]["locations"])) { $errors = array_merge($errors, save_locations($id, $db, $listing_locations_tbl)); } if (isset($_POST["listing"]["new"]["categories"])) { $errors = array_merge($errors, save_categories($id, $db, $listing_business_types_tbl)); } if (count($errors)) { $errors[] = "Unable to update listing."; $sql = " delete from " . $listings_tbl . " where id=[id]; delete from " . $listing_locations_tbl . " where listing_id=[id]; delete from " . $listing_business_types_tbl . " where listing_id=[id]; "; $db->set_data_multi($sql, array("id" => $id)); return $errors; } if ($_POST["is_admin"] == "true") { $_REQUEST["action"] = "update"; $_REQUEST["uuid"] = $uuid; $_REQUEST["update_to_id"] = $update_to_id; include "update.php"; exit; } else { //mail($_POST["listing"]["new"]["info"]["update_email"], "Oildirectory.com Update Confirmation", $message, $headers); } return $errors; } function save_listing1() { ini_set('display_errors', 1); PRINT 'save1'; // print 'lisstiungs addnew'.$_POST["listing"]["new"]["info"]["notes"]; print 'lisstiungs addcurrent'.$_POST["listing"]["current"]["info"]["notes"]; global $_POST, $_SESSION; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/dbi.inc"; $db = new Database(); $errors = array(); if (strlen($_POST["listing"]["new"]["info"]["name"]) < 5) $errors[] = "The name must be greater than 4 characters."; if (strlen($_POST["listing"]["new"]["info"]["name"]) > 500) $errors[] = "The name must be less than 500 characters."; if (strlen($_POST["listing"]["new"]["info"]["description"]) < 5) $errors[] = "The description must be greater than 4 characters."; if (!validEmail($_POST["listing"]["new"]["info"]["update_email"])) $errors[] = "You must enter a valid administrator email address, this will be used to confirm changes to the listing but will not be displayed in the listing"; if (count($_POST["listing"]["new"]["locations"]) == 0) $errors[] = "You must include at least one location."; else $errors = array_merge($errors, check_locations()); if (count($_POST["listing"]["new"]["categories"]) == 0) $errors[] = "You must select at least one category."; if (count($errors) > 0) return $errors; //$id=$_POST["listing"]["current"]["info"]["id"]; PRINT 'notescurrent'.$_POST["listing"]["current"]["info"]["notes"]; // PRINT 'notesnew'.$_POST["listing"]["new"]["info"]["notes"]; // PRINT 'notesinfo'.$_POST["info"]["notes"]; PRINT 'testststs'; PRINT 'namecurrent'.$_POST["listing"]["current"]["info"]["name"]; PRINT 'namenew'.$_POST["listing"]["new"]["info"]["name"]; print 'notesactionadd'.[notes]; $sql = "update request_listings set name='[name]',description='[description]',notes='[notes]',update_email='[update_email]' where id = '[id]'"; $db->set_data($sql, $_POST["listing"]["new"]["info"]); $_POST["listing"]["current"]["info"] = $_POST["listing"]["new"]["info"]; if (isset($_POST["listing"]["new"]["locations"])) { // save locations, delete first, then add $sql = "delete from request_listing_locations where listing_id = '[id]'"; $db->set_data($sql, $_POST["listing"]["new"]["info"]); $locations = $_POST["listing"]["new"]["locations"]; $errors1 = array(); //check for errors in updated or added locations foreach ($locations as $locnum => $info) { //add new location $sql = array(); $sql = <<set_data_return_id($sql, $info)) { $errors1[] = "Unable to add location #{$locnum}. " . $db->lasterror; } } $errors = array_merge($errors, $errors1); } if (isset($_POST["listing"]["new"]["categories"])) { // save categories, delete first, then add $sql = "delete from request_listing_business_types where listing_id = '[id]'"; $db->set_data($sql, $_POST["listing"]["new"]["info"]); $errors1 = array(); //check for new categories $sql = array(); $listing_id = $_POST["listing"]["new"]["info"]['id']; foreach ($_POST["listing"]["new"]["categories"] as $rownum => $id) { //add category $sql[] = "insert into request_listing_business_types (listing_id,business_type_id) values ([listing_id],{$id});"; } if ($db->set_data_multi($sql, array("listing_id" => $listing_id))) { //$_POST["listing"]["current"]["categories"][] = $id; } else { $errors1[] = "Category add failed"; } $errors = array_merge($errors, $errors1); } if (count($errors)) { $errors[] = "Unable to update request listings."; return $errors; } return $errors; } function check_locations() { global $_POST; $locations = $_POST["listing"]["new"]["locations"]; $errors = array(); //check for errors in updated or added locations foreach ($locations as $locnum => $info) { if (strlen($info["phone"]) < 7) $errors[] = "The Phone for Location #{$locnum} must be greater than 7 characters."; if (strlen($info["province_id"]) == 0) $errors[] = "You must choose a Province/State for Location #{$locnum}."; if (strlen($info["country_id"]) == 0) $errors[] = "You must choose a Country for Location #{$locnum}."; } return $errors; } function save_locations($listing_id, &$db, $tbl) { global $_POST; $locations = $_POST["listing"]["new"]["locations"]; $errors = array(); //check for errors in updated or added locations foreach ($locations as $locnum => $info) { //add new location $sql = array(); $sql = " insert into " . $tbl . " ( listing_id,contact_name,phone,fax,cell,tollfree,address1,address2, city,province_id,country_id,pcode,email,email2,website ) values ( [listing_id],'[contact_name]','[phone]','[fax]','[cell]','[tollfree]', '[address1]','[address2]','[city]','[province_id]', '[country_id]','[pcode]','[email]','[email2]','[website]') "; $info["listing_id"] = $_POST["listing"]["current"]["info"]["id"]; if (!$id = $db->set_data_return_id($sql, $info)) { $errors[] = "Unable to add location #{$locnum}. " . $db->lasterror; } } return $errors; } function save_categories($listing_id, &$db, $tbl) { global $_POST; $errors = array(); //check for new categories $sql = array(); foreach ($_POST["listing"]["new"]["categories"] as $rownum => $id) { //add category $sql[] = "insert into " . $tbl . " (listing_id,business_type_id) values ([listing_id],{$id});"; } if ($db->set_data_multi($sql, array("listing_id" => $listing_id))) { $_POST["listing"]["current"]["categories"][] = $id; } else { $errors[] = "Category add failed"; } return $errors; } function delete_listing($listing) { global $_POST, $_SESSION; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/dbi.inc"; $db = new Database(); $errors = array(); $sql = array(); $sql[] = "update listings set update_confirmation_id='[uuid]' where id=[listing_id];"; $uuid = md5(uniqid()); $rtnval = $db->set_data_multi($sql, array("listing_id" => $listing["id"], "uuid" => $uuid)); if (strlen($db->lasterror)) { $errors[] = "Unable to delete listing. " . $db->lasterror; } else { $_SESSION["error"] = <<service@oildirectory.com to update the email address and try again. EOD; $message = <<
To confirm this deletion and have your listing removed from Oildirectory.com, please click here. EOD; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: ' . $_POST["listing"]["new"]["info"]["update_email"] . "\r\n"; $headers .= 'From: Oildirectory.com ' . "\r\n"; if ($_POST["is_admin"] == "true") { $_REQUEST["action"] = "delete"; $_REQUEST["id"] = $uuid; include "update.php"; exit; } else { // mail($listing["update_email"], "Oildirectory.com Deletion Confirmation", $message, $headers); } } return $errors; } //following added function setup_post($listing_id, $is_request_tbl) { global $_POST, $_SESSION; $_POST["listing"] = array( "current" => array( "info" => array(), "locations" => array(), "categories" => array() ), "premium" => false, "expires" => "Not Available" ); $_POST["is_request_listings_operations"] = $is_request_tbl; // if $is_request_tbl == false, retrieve data from listings table // else if $is_request_tbl == true, retrieve data from request_listings table $listings_tbl = ""; $listing_business_types_tbl = ""; $listing_locations_tbl = ""; if ($is_request_tbl == false) { $listings_tbl = "listings"; $listing_business_types_tbl = "listing_business_types"; $listing_locations_tbl = "listing_locations"; } else { $listings_tbl = "request_listings"; $listing_business_types_tbl = "request_listing_business_types"; $listing_locations_tbl = "request_listing_locations"; } //get the data from the db require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/dbi.inc"; $db = new Database(); //get the listing $sql = "select id,name,description,notes,update_email from [listings_tbl] where id=[id]"; if (!$data = $db->get_data($sql, array("listings_tbl" => $listings_tbl,"id" => $listing_id)) or count($data) != 2) { $_SESSION["error"] = "Unable to retrieve listing, please try again."; return false; } else { $_POST["listing"]["current"]["info"] = $data[1]; } $update_to_id = $data[1]['update_to_id']; //get the locations $sql = <<get_data($sql, array("listing_locations_tbl" => $listing_locations_tbl, "id" => $listing_id))) { $_SESSION["error"] = "Unable to retrieve listing, please try again."; return false; } else { array_shift($data); //remove the header row $_POST["listing"]["current"]["locations"] = $data; } //get the locations $sql = "select * from [listing_business_types_tbl] where listing_id=[id]"; if (!$data = $db->get_data($sql, array("listing_business_types_tbl" => $listing_business_types_tbl, "id" => $listing_id))) { $_SESSION["error"] = "Unable to retrieve listing, please try again."; return false; } else { array_shift($data); //remove the header row foreach ($data as $rownum => $row) { $_POST["listing"]["current"]["categories"][] = $row["business_type_id"]; } } if ($is_request_tbl == true) $listing_id = $update_to_id; //see if they are already premium $_POST["listing"]["premium"] = false; $_POST["listing"]["expires"] = "Not Available"; $sql = "select *,case when expiresget_data($sql, array("id" => $listing_id))) { if (count($data) == 2) { if ($data[1]["expired"] == 0) { $_POST["listing"]["premium"] = true; $_POST["listing"]["expires"] = $data[1]["expires"]; } } } //setup the new to = current $_POST["listing"]["new"] = $_POST["listing"]["current"]; return true; } function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex + 1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen - 1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) { $isValid = false; } } if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain ,"A"))) { // domain not found in DNS $isValid = false; } } return $isValid; } ?>