var_name])) { $this->id = $_COOKIE[$this->var_name]; if($promotion_record = $this->get_promotion_record('id', $this->id)) { $this->set_promotion_values($promotion_record); } else { unset($this->id); // may happen if promo gets removed from db Utilities::remove_cookie($this->var_name); } } } function set_cookie($num_days_to_live=0) { // default to expiring at end of session $ttl = ($num_days_to_live == 0) ? 0 : time()+60*60*24*$num_days_to_live; setcookie($this->var_name, $this->id, $ttl, '/'); } function get_promotion_record($by = 'code', $search) { return(Database::ado_get_row("SELECT * FROM promotions WHERE $by='".strtoupper(trim(addslashes($search)))."'")); } function set_promotion_values($promotion_record) { $this->id = $promotion_record['id']; $this->title = $promotion_record['title']; $this->code = $promotion_record['code']; $this->discount_pct = $promotion_record['discount_pct']; $this->discount_dol = $promotion_record['discount_dol']; } function check_code($code) { $this->code = $code; // queries db w/ code to find out if a valid one exists. if so, is it expired or current. if(trim($this->code) == '') { $this->error = TRUE; $this->error_msg = "Please enter the code"; } else { if($promotion_record = $this->get_promotion_record('code', $code)) { if($this->is_current($promotion_record['date_end'])) { $this->set_promotion_values($promotion_record); $this->set_cookie();// eventually would want a db lookup for expiry } else { $this->error = TRUE; $this->error_msg = "This promotion has expired"; } } else { $this->error = TRUE; $this->error_msg = "This code is invalid. Please try again"; } } } function is_current($end_date) { if(Utilities::date_in_past($end_date)) { return(false); } else { return(true); } } function get_code() { return($this->code); } function get_id() { return(isset($this->id)) ? $this->id : FALSE; } function get_discount_pct() { return(isset($this->discount_pct)) ? $this->discount_pct : FALSE; } function get_discount_dol() { return(isset($this->discount_dol)) ? $this->discount_dol : FALSE; } function is_error() { return($this->error) ? TRUE : FALSE; } function get_error_msg() { return($this->error_msg); } } ?>