okay , first of all thank you guys for your help but i still didn't get that done yet ,
Code: Select all
<?php require_once("/includes/initialize.php"); ?>
<?php include ("layouts/header.php");
//require_once(LIB_PATH.DS."phpMailer".DS."language".DS."phpmailer.lang-en.php");
//require_once(LIB_PATH.DS."phpMailer".DS."class.phpmailer.php");
//require_once(LIB_PATH.DS."phpMailer".DS."class.smtp.php");
?>
<div class="art-content-layout">
<div class="art-content-layout-row">
<div id="accordion">
<?php
if(isset($_POST['submit']))
{echo "form fileds submited</br></br>";
$table_name= $_GET["table_name"];
$disc = trim($_POST['disc']);
$type = trim($_POST['type']);
$address = trim($_POST['address']);
$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$email = trim($_POST['email']);
$email2 = trim($_POST['email2']);
$phone = trim($_POST['phone']);
$hphone = trim($_POST['hphone']);
if(isset($_POST['sqr'])) {$sqr = $_POST['sqr'];}else {$sqr = 0;}
$Price = trim($_POST['Price']);
$note = trim($_POST['note']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
$Country = trim($_POST['Country']);
$n_bed = trim($_POST['n_bed']);
$n_bath = trim($_POST['n_bath']);
$datetime = trim($_POST['datetime']);
$user_code = trim($_POST['user_code']);
if(isset($_POST['mileage'])) {$mileage = $_POST['mileage'];}else {$mileage = 0;}
if(isset($_POST['year'])) {$mileage = $_POST['year'];}else {$year = 0;}
$zipcode = "n/a";
$activation = "n/a";
if ($table_name == "ad_d_apart")
{
$new_ad = ad::MakeObjectApart($table_name,$lname,$fname,$Price,$sqr,$type,$email,$hphone,$phone,
$n_bed,$n_bath,$activation,$disc,$note,$datetime,$zipcode,$state,$address,$Country,$city,$user_code);
}
if ($table_name == "ad_d_cars")
{
$new_ad = ad::MakeObjectcars($table_name,$lname,$fname,$Price,$mileage,$type,$email,$hphone,$phone,
$year ,$activation,$disc,$note,$datetime,$zipcode,$state,$address,$Country,$city,$user_code);
} echo $tablename = $table_name ;
if ($table_name == "ad_d_jobs")
{
$new_ad = ad::MakeObjectjobs($table_name,$lname,$fname,$Price,$sqr,$type,$email,$hphone,$phone,
$n_bed,$n_bath,$activation,$disc,$note,$datetime,$zipcode,$state,$address,$Country,$city,$user_code);
}
if ($table_name == "ad_d_donation")
{
$new_ad = ad::MakeObjectdonation($table_name,$lname,$fname,$Price,$sqr,$type,$email,$hphone,$phone,
$n_bed,$n_bath,$activation,$disc,$note,$datetime,$zipcode,$state,$address,$Country,$city,$user_code);
}
if($new_ad && $new_ad->create($tablename))
{
// comment saved
// No message needed; seeing the comment is proof enough.
// Send email
//$new_ad->try_to_send_notification();
echo "object created and saved";
// Important! You could just let the page render from here.
// But then if the page is reloaded, the form will try
// to resubmit the comment. So redirect instead:
//redirect_to("photo.php?id={$photo->id}");
} else
{
// Failed
echo $message = "There was an error that prevented the comment from being saved.";
}
}
else
{
$table_name= $_GET["table_name"];
$disc = "";
$address = "";
$fname = "";
$lname = "";
$email = "";
$email2 = "";
$phone = "";
$hphone = "";
$sqr = "";
$Price = "";
$note = "";
$city = "";
$state = "";
$Country = "";
$n_bed = "";
$n_bath = "";
$type = "";
$datetime = "";
$user_code = "";
}
?>
<h1>Post Another AD</h1>
<h1>Go To Housing Ads</h1>
</div>
<?php include ("layouts/footer.php"); ?>
Code: Select all
<?php
// If it's going to need the database, then it's
// probably smart to require it before we start.
require_once(LIB_PATH.DS.'database.php');
class ad extends DatabaseObject {
protected static $table_name ="ad_d_cars";
//protected static $table_name2 ="ad_d_apart";
protected static $db_fields ;
public $item_code;
public $price ;
public $sqr;
public $type ;
public $n_bed;
public $n_bath;
public $activation;
public $disc;
public $note;
public $datetime;
public $has_pic ;
public $state;
public $address;
public $city;
public $zipcode;
public $fname;
public $lname;
public $email;
public $phone;
public $mileage ;
public $hphone;
public $year;
public $Country;
public $user_code = 1;
//private $temp_path;
//protected $upload_dir="images";
public static function MakeObjectApart ($table_name,$lname,$fname,$Price,$sqr,$type,$email,$hphone,$phone,
$n_bed,$n_bath,$activation,$disc,$note,$datetime,$zipcode,$state,$address,$Country,$city,$user_code)
{global $db_fields ;
$db_fields = array('item_code', 'price','fname','lname','email', 'sqr', 'type','n_bed',
'n_bath','phone','hphone','activation', 'disc','note','datetime','has_pic','address',
'state','city','Country','zipcode','user_code');
print_r ($db_fields);
$ad = new ad();
//$ad->created = strftime("%Y-%m-%d %H:%M:%S", time());
$ad->table_name = $table_name;
$ad->lname = $lname;
$ad->fname = $fname;
$ad->email = $email;
$ad->hphone = $hphone;
$ad->phone = $phone;
$ad->price = $Price;
$ad->sqr = $sqr;
$ad->type = $type;
$ad->n_bed = $n_bed;
$ad->n_bath = $n_bath;
$ad->activation = $activation;
$ad->disc = $disc;
$ad->note = $note;
$ad->address = $address;
$ad->zipcode = $zipcode;
$ad->datetime = $datetime;
$ad->city = $city;
$ad->user_code = $user_code;
$ad->state = $state;
$ad->Country = $Country;
//echo "object created";
return $ad;
}
public static function MakeObjectcars($table_name,$lname,$fname,$Price,$mileage,$type,$email,$hphone,$phone,
$year ,$activation,$disc,$note,$datetime,$zipcode,$state,$address,$Country,$city,$user_code)
{
$db_fields = array('item_code', 'price','fname','lname','email', 'sqr', 'type',
'phone','hphone','activation', 'disc','note','datetime','has_pic','address',
'state','city','Country','zipcode','user_code','year','mileage');
print_r ($db_fields); $ad = new ad();
//$ad->created = strftime("%Y-%m-%d %H:%M:%S", time());
$ad->table_name = $table_name;
$ad->lname = $lname;
$ad->fname = $fname;
$ad->email = $email;
$ad->hphone = $hphone;
$ad->phone = $phone;
$ad->price = $Price;
$ad->mileage = $mileage;
$ad->type = $type;
$ad->year = $year;
$ad->n_bath = $n_bath;
$ad->activation = $activation;
$ad->disc = $disc;
$ad->note = $note;
$ad->address = $address;
$ad->zipcode = $zipcode;
$ad->datetime = $datetime;
$ad->city = $city;
$ad->user_code = $user_code;
$ad->state = $state;
$ad->Country = $Country;
//echo "object created";
return $ad;
}
function getjobtype($id)
{
$sql = "SELECT * FROM jobs_type" ;
$sql .= " where id=$id LIMIT 1";
$jobtypes = DatabaseObject::find_by_sql($sql);
foreach($jobtypes as $jobtype):
$jobname = $jobtype->type;
endforeach;
return $jobname;
}
function delete_ad ($cat_type,$ad_code) /// To Add Ad
{
global $connection;
$tablename = select_table($cat_type);
$pic_tablename = select_pic_tablename($cat_type);
$query1 = " DELETE FROM $pic_tablename
WHERE item_code=$ad_code ";
echo $query1;
$delete_ad_pic = mysql_query($query1,$connection);
confirm_query($delete_ad_pic);
$query2 = " DELETE FROM $tablename
WHERE item_code=$ad_code ";
echo $query2;
$delete_ad = mysql_query($query2,$connection);
confirm_query($delete_ad);
return $delete_ad;
}
function select_ad_update ($user_code,$tablenumb) // to review the resent ads for one user
{
global $connection;
//echo $tablenumb ;
$tablename = select_table($tablenumb);
$query = " select $tablename.disc , $tablename.item_code ";
$query .= " from $tablename ,ads_deitals_items ";
$query .= " where activation = 1 and ads_deitals_items.item_code = $tablename.item_code and ads_deitals_items.user_name = \"$user_code\"";
$query .= " ORDER BY $tablename.datetime DESC";
echo $query;
$select_ad_update_apart = mysql_query($query,$connection);
return $select_ad_update_apart;
}
function user_ads ($tablename,$user_code) /// to view all the ads for the same user
{ global $connection;
$query = " SELECT * ";
$query .= " from $tablename , ads_deitals_items ";
if ($tablename=="ad_d_jobs")
{
$query .= " ,jobs_type";
}
if ($tablename=="ad_d_furnisher")
{
$query .= " ,furnisher_categ";
}
if ($tablename=="ad_d_needs")
{
$query .= " ,need_categ";
}
if ($tablename=="ad_d_donation")
{
$query .= " ,donation_categ";
}
$query .= " where activation = 1 and ads_deitals_items.item_code = $tablename.item_code and ads_deitals_items.user_name = \"$user_code\"";
if ($tablename=="ad_d_jobs")
{
$query .= " and ad_d_jobs.job_type = jobs_type.jobs_type_code ";
}
if ($tablename=="ad_d_furnisher")
{
$query .= " and ad_d_furnisher.item_categ_code = furnisher_categ.furnisher_categ_code ";
}
if ($tablename=="ad_d_needs")
{
$query .= " and ad_d_needs.need_categ_code = need_categ.need_categ_code ";
}
if ($tablename=="ad_d_donation")
{
$query .= " and ad_d_donation.donation_categ_code = donation_categ.donation_categ_code ";
}
$query .= " ORDER BY ads_deitals_items.datetime DESC";
// echo "$query.<BR><BR>";
$user_ads = mysql_query($query,$connection);
confirm_query($user_ads);
return $user_ads;
}
function resent_ads ($tablename,$per_categ) // to review the resent ads
{ global $connection;
$query = " SELECT * ";
$query .= " from $tablename ";
$query .= " where activation = 1 ";
$query .= " ORDER BY datetime DESC";
$query .= " LIMIT $per_categ ";
if ($tablename=="ad_d_jobs")
{
$query = " SELECT * ";
$query .= " from $tablename ,jobs_type ";
$query .= " where activation = 1 and ad_d_jobs.job_type = jobs_type.jobs_type_code ";
$query .= " ORDER BY datetime DESC";
$query .= " LIMIT $per_categ ";
}
echo $query;
//$result = mysql_query($query, $database->connection);
$resent_ads = mysql_query($query,$connection);
confirm_query($resent_ads);
return $resent_ads;
}
function select_ads_note ($tablename,$ad_code) // select add rec
{ global $connection;
$query = "SELECT * ";
$query .= "from $tablename ";
$query .= "where activation = 1 , item_code = $ad_code";
echo $query;
$result_ads = mysql_query($query,$connection);
confirm_query($result_ads_note);
return $result_ads_note;
}
function repost_ad ($tablenumb,$ad_code)
{
global $connection;
$tablename = select_table($tablenumb);
$query = " UPDATE ads_deitals_items , $tablename SET
ads_deitals_items.datetime = NOW(),$tablename.datetime = NOW()
WHERE ads_deitals_items.item_code=$ad_code and $tablename.item_code=$ad_code ";
echo $query;
$update_ad = mysql_query($query,$connection);
confirm_query($update_ad);
return $update_ad;
}
function select_ads ($tablename,$per_page,$start,$order,$tablenumb)
{ global $connection;
$query = " SELECT * ";
$query .= " from $tablename ";
$query .= " where activation = 1 ";
$query .= " order by $order DESC ";
$query .= " ORDER BY datetime DESC";
$query .= " LIMIT $start , $per_page ";
echo $query;
$result_ads = mysql_query($query,$connection);
confirm_query($result_ads);
return $result_ads;
}
function select_not_ad ($tablename,$item_code)
{ global $connection;
$query = "SELECT * ";
$query .= "from $tablename ";
$query .= "where item_code = $item_code ";
//echo $query;
$result_not_ad = mysql_query($query,$connection);
confirm_query($result_not_ad);
return ($result_not_ad);
}
function get_not_ad($tablenumb,$item_code)
{
$tablename = select_table($tablenumb);
$not_ad_data= ad::select_not_ad ($tablename,$item_code);
//echo $tablename;
//$data = select_ads ($tablename);
return ($not_ad_data);
}
/////////////// get the search resaults /////////////
function get_ads_search ($cat_type,$per_page,$start,$order,$search_or_no,$disc,$has_pic,$only_titel,$min_price,$max_price,$region,$state,$zipcode,$radius,
$min_year,$max_year,$model,$min_mileage,$max_mileage,$shiping,$apart_type,$n_bed,$max_Foot,$min_Foot,$furn_categ,$doun_categ,
$rating,$exp_year,$jobs_code,$UTI_categ)
{
$tablename = select_table($cat_type);
// echo "</br>stat".$city."</br>";
// echo "</br>city".$city."</br>";
$region=city::select_city_by_id($region);
$state=city::select_state_by_id($state);
$state=ucfirst(strtolower($state)); // upper case
$zipcodes_list = get_zip_by_citys($region,$state);
while ($ad = mysql_fetch_array($zipcodes_list))
{
$zipcodes=$ad['zip_code'] ;
// echo $zipcodes ;
}
//$string = var_export($zipcodes, true); //print array as string
$data = ad::select_ads_search ($tablename,$per_page,$start,$order,$search_or_no,$disc,$has_pic,$only_titel,$min_price,$max_price,$region,$state,$zipcode,$radius,
$min_year,$max_year,$model,$min_mileage,$max_mileage,$shiping,$apart_type,$n_bed,$max_Foot,$min_Foot,$furn_categ,$doun_categ,
$rating,$exp_year,$jobs_code,$UTI_categ,$zipcodes); // the user search
return ($data);
} // ads search
function select_ads_search ($tablename,$per_page,$start,$order,$search_or_no,$disc,$has_pic,$only_titel,$min_price,$max_price,$region,$state,$zipcode,$radius,
$min_year,$max_year,$model,$min_mileage,$max_mileage,$shiping,$apart_type,$n_bed,$max_Foot,$min_Foot,$furn_categ,$doun_categ,
$rating,$exp_year,$jobs_code,$UTI_categ,$zipcodes)
{ global $connection;
// echo "</br>region:".$region."</br>";
// echo $zipcodes[0];
$query = " SELECT * ";
$query .= " from $tablename ";
$query .= " where activation = 1";
if ($disc)
{
$query .= " and disc LIKE '%$disc%'" ;
}
if ($apart_type <> 0)
{
$query .= " and type = $apart_type" ;
}
if ($doun_categ <> 0)
{
$query .= " and donation_categ_code = $doun_categ" ;
}
if ($UTI_categ <> 0)
{
$query .= " and need_categ_code = $UTI_categ" ;
}
if ($furn_categ<>0) // furnither
{
$query .= " and item_categ_code = $furn_categ" ;
}
if ($has_pic == 1 )
{
$query .= " and has_pic = 1" ;
// echo "</br>$query</br>";
}
if ($jobs_code <> 0)
{
$query .= " and job_type = $jobs_code" ;
}
if ($rating)
{
// echo "insed rating";
$query .= " and rating = \"$rating\"" ;
// echo "</br>$query</br>";
}
if ($exp_year <> 0)
{
$query .= " and years_exprin = $exp_year" ;
// echo "</br>$query</br>";
}
if ($min_price && $max_price)
{ //echo "min_price:$min_price</br>" ;
$query .= " and price BETWEEN $min_price AND $max_price" ;
//echo "</br>$query</br>";
}
if ($min_price && !$max_price )
{
$query .= " and price >= $min_price" ;
// echo "</br>$query</br>";
}
if (!$min_price && $max_price )
{
$query .= " and price <= $max_price" ;
// echo "</br>$query</br>";
}
if ($shiping <> 0)
{
$query .= " and shiping_police = $shiping" ;
// echo "</br>$query</br>";
}
if ($model)
{
if ($model<>0){$query .= " and c_model = $model" ; // if it's = 0 that's mean that he need all the models
// echo "</br>$query</br>";
}
}
//////////////
if ($min_mileage && $max_mileage)
{
$query .= " and mileage BETWEEN $min_mileage AND $max_mileage" ;
// echo "</br>$query</br>";
}
if ($min_mileage && !$max_mileage )
{
$query .= " and mileage >= $min_mileage" ;
// echo "</br>$query</br>";
}
if (!$min_mileage && $max_mileage )
{
$query .= " and mileage <= $max_mileage" ;
// echo "</br>$query</br>";
}
//////
if ($min_year && $max_year)
{
$query .= " and year BETWEEN $min_year AND $max_year" ;
// echo "</br>$query</br>";
}
if ($min_year && !$max_year )
{
$query .= " and year >= $min_year" ;
// echo "</br>$query</br>";
}
if (!$min_year && $max_year )
{
$query .= " and year <= $max_year" ;
// echo "</br>$query</br>";
}
if ($n_bed && $n_bed <> "Any" )
{
$query .= " and n_bed = $n_bed" ;
// echo "</br>$query</br>";
}
if ($min_Foot && $max_Foot)
{
$query .= " and sqr BETWEEN $min_Foot AND $max_Foot" ;
// echo "</br>$query</br>";
}
if ($min_Foot && !$max_Foot )
{
$query .= " and sqr >= $min_Foot" ;
// echo "</br>$query</br>";
}
if (!$min_Foot && $max_Foot )
{
$query .= " and sqr <= $max_Foot" ;
// echo "</br>$query</br>";
}
if ($region && $state )
{
// echo "66666666";
// echo "radius not 0.</br>";
// $zipcodes = mysql_fetch_array($zipcodes) ;
$z = new zipcode_class;
//echo"</br>radius:".$radius."</br>";
$zips = $z->get_zips_in_range($zipcodes,$radius, _ZIPS_SORT_BY_DISTANCE_ASC, true);
if ($zips === false) echo ' Error: '.$z->last_error;
else {
$zip_list = $zipcodes ;
//echo "the current zipcode: ".$zip_list."</br>";
foreach ($zips as $key => $value)
{
//echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>$zipcodes</b>.<br />"; // to print each zipcode and how many maile deffrence with the main zipcode
$zip_list .= "," ;
$zip_list .= $key ;
}
$query .= " and zipcode IN($zip_list)" ;
// global $zips;
// echo "number: $zip_list";
// One thing you may want to do with this is create SQL from it. For example,
// iterate through the array to create SQL that is something like:
// WHERE zip_code IN ('93001 93002 93004')
// and then use that condition in your query to find all pizza joints or
// whatever you're using it for. Make sense? Hope so.
// echo "<br /><i>get_zips_in_range() executed in <b>".$z->last_time."</b> seconds.</i><br />";
} // $query .= " and city = \"$city\"" ; // if it's = 0 that's mean that he need all the models
// echo "</br>$query</br>";
}
$query .= " order by $order DESC ";
// $query .= " ORDER BY datetime DESC";
$query .= " LIMIT $start , $per_page ";
echo $query;
$result_ads = mysql_query($query,$connection);
confirm_query($result_ads);
$num_rows = mysql_num_rows($result_ads);
if ($num_rows == 0)
{
die("Tray to use a differant Conditions for the search");
}
else
//echo "$num_rows Rows\n";
return $result_ads;
}
function get_ads($tablenumb,$per_page,$start,$order,$search_or_no)
{
$tablename = select_table($tablenumb);
//echo $tablename;
if ($search_or_no == 1 )
{
$data = select_ads_search ($cat_type,$per_page,$start,$order,$search_or_no,$disc,$has_pic,$only_titel,$min_price,$max_price,$city,$state,$radius,$zipcodes,
$min_year,$max_year,$model,$min_mileage,$max_mileage,
$apart_type,$n_bed,$max_Foot,$min_Foot,$furn_categ,$doun_categ); // the user search
}
else
$data = select_ads ($tablename,$per_page,$start,$order,$tablenumb); // the user see all the ads
return ($data);
}
function select_cars_models () // use the table name and put it in the select statment and then call confirm function
{ global $connection;
$query = " SELECT * ";
$query .= " from cars_marke ";
$query .= " ORDER BY cars_model_name ASC";
//echo $query;
$cars_models = mysql_query($query,$connection);
confirm_query($cars_models);
return $cars_models;
}
function select_cars_model_note ($c_model)
{ global $connection;
$query = " SELECT cars_model_name ";
$query .= " from cars_marke ";
$query .= " where cars_marke_code = $c_model ";
//echo $query;
$cars_models = mysql_query($query,$connection);
confirm_query($cars_models);
return $cars_models;
}
function select_jobs_types () // use the table name and put it in the select statment and then call confirm function
{ global $connection;
$query = " SELECT * ";
$query .= " from jobs_type ";
$query .= " ORDER BY jobs_type, jobs_name ASC";
//echo $query;
$jobs_types = mysql_query($query,$connection);
confirm_query($jobs_types);
return $jobs_typs;
}
function select_jobs_types_note ($job_type) // use the table name and put it in the select statment and then call confirm function
{ global $connection;
$query = " SELECT jobs_name , jobs_type ";
$query .= " from jobs_type ";
$query .= " where jobs_type_code = $job_type ";
//echo $query;
$job_type = mysql_query($query,$connection);
confirm_query($job_type);
return $job_type;
}
function select_furnisher_categ_note ($furnisher_categ)
{ global $connection;
$query = " SELECT furnisher_categ_name ";
$query .= " from furnisher_categ ";
$query .= " where furnisher_categ_code = $furnisher_categ ";
//echo $query;
$furnisher_type = mysql_query($query,$connection);
confirm_query($furnisher_type);
return $furnisher_type;
}
function select_dounation_categ_note ($dounation_categ) // use the table name and put it in the select statment and then call confirm function
{ global $connection;
$query = " SELECT donation_categ_name ";
$query .= " from donation_categ ";
$query .= " where donation_categ_code = $dounation_categ ";
//echo $query;
$dounation_type = mysql_query($query,$connection);
confirm_query($dounation_type);
return $dounation_type;
}
function select_apart_types_note ($apart_types) // use the table name and put it in the select statment and then call confirm function
{ global $connection;
$query = " SELECT apart_type_code , apart_type_name ";
$query .= " from apart_type ";
$query .= " where apart_type_code = $apart_types ";
//echo $query;
$apart_types = mysql_query($query,$connection);
confirm_query($apart_types);
return $apart_types;
}
function select_furn_categ ()
{ global $connection;
$query = " SELECT * ";
$query .= " from furnisher_categ ";
$query .= " ORDER BY furnisher_main_categ,furnisher_categ_name ASC";
//echo $query;
$select_categs = mysql_query($query,$connection);
confirm_query($select_categs);
return $select_categs;
}
function select_donation_categ ()
{ global $connection;
$query = " SELECT * ";
$query .= " from donation_categ ";
$query .= " ORDER BY donation_main_categ , donation_categ_name ASC";
//echo $query;
$select_categs = mysql_query($query,$connection);
confirm_query($select_categs);
return $select_categs;
}
function select_need_categ ()
{ global $connection;
$query = " SELECT * ";
$query .= " from need_categ ";
$query .= " ORDER BY need_categ_name ASC";
//echo $query;
$need_categs = mysql_query($query,$connection);
confirm_query($need_categs);
return $need_categs;
}
function select_housing_types ()
{ global $connection;
$query = " SELECT * ";
$query .= " from apart_type ";
$query .= " ORDER BY apart_type_name ASC";
//echo $query;
$housing_types = mysql_query($query,$connection);
//confirm_query($housing_types);
return $housing_types;
}
}
?>