From a4fa1b40ce35e3f79bb5815af9a1d5b6fd72ffae Mon Sep 17 00:00:00 2001 From: Devin Smith Date: Tue, 3 Mar 2015 14:17:57 -0800 Subject: [PATCH] more query fixes --- include/library/Cockpit/Admin.php | 8 ++++---- include/library/Crunchbutton/Order.php | 4 ++-- include/library/Crunchbutton/Promo.php | 10 +++++----- include/library/Crunchbutton/Suggestion.php | 12 ++++++------ include/library/Crunchbutton/Support.php | 8 ++++---- include/library/Crunchbutton/User/Auth.php | 18 +++++++++--------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/library/Cockpit/Admin.php b/include/library/Cockpit/Admin.php index 1f7e8ba7b..a6d99172f 100644 --- a/include/library/Cockpit/Admin.php +++ b/include/library/Cockpit/Admin.php @@ -68,15 +68,15 @@ class Cockpit_Admin extends Crunchbutton_Admin { public function deliveries() { if (!isset($this->_deliveries)) { - $o = Order::q(' + $o = Order::q(" select o.*, oa.type as status, oa.timestamp as status_time from `order` o left join order_action oa using (id_order) where - id_admin="'.$this->id_admin.'" - and (oa.type="delivery-pickedup" or oa.type="delivery-accepted" or oa.type="delivery-delivered" or oa.type="delivery-rejected" or oa.type="delivery-transfered") + id_admin=? + and (oa.type='delivery-pickedup' or oa.type='delivery-accepted' or oa.type='delivery-delivered' or oa.type='delivery-rejected' or oa.type='delivery-transfered') and o.date >= (curdate() - interval 50 day) order by oa.timestamp asc - '); + ", [$this->id_admin]); $orders = []; foreach ($o as $order) { if (!$orders[$order->id_order]) { diff --git a/include/library/Crunchbutton/Order.php b/include/library/Crunchbutton/Order.php index acd10d08a..1710850fe 100644 --- a/include/library/Crunchbutton/Order.php +++ b/include/library/Crunchbutton/Order.php @@ -805,12 +805,12 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange { } public function accepted() { - $nl = Notification_Log::q('select * from notification_log where id_order=? and status="accepted"', [$this->id_order]); + $nl = Notification_Log::q("select * from notification_log where id_order=? and status='accepted'", [$this->id_order]); return $nl->count() ? true : false; } public function fax_succeeds() { - $nl = Notification_Log::q('select * from notification_log where id_order=? and type="phaxio" and status="success"', [$this->id_order]); + $nl = Notification_Log::q("select * from notification_log where id_order=? and type='phaxio' and status='success'", [$this->id_order]); return $nl->count() ? true : false; } diff --git a/include/library/Crunchbutton/Promo.php b/include/library/Crunchbutton/Promo.php index 9c99a0ca8..b9fb4c0d5 100644 --- a/include/library/Crunchbutton/Promo.php +++ b/include/library/Crunchbutton/Promo.php @@ -422,25 +422,25 @@ class Crunchbutton_Promo extends Cana_Table $query = 'SELECT `promo`.*, user.name FROM `promo` LEFT JOIN restaurant USING(id_restaurant) LEFT OUTER JOIN user USING(id_user) WHERE id_promo IS NOT NULL '; if ($search['type']) { - $query .= ' and type="'.$search['type'].'" '; + $query .= " and type='".$search['type']."' "; } if ($search['start']) { $s = new DateTime($search['start']); - $query .= ' and DATE(`date`)>="'.$s->format('Y-m-d').'" '; + $query .= " and DATE(`date`)>='".$s->format('Y-m-d')."' "; } if ($search['end']) { $s = new DateTime($search['end']); - $query .= ' and DATE(`date`)<="'.$s->format('Y-m-d').'" '; + $query .= " and DATE(`date`)<='".$s->format('Y-m-d')."' "; } if ($search['restaurant']) { - $query .= ' and `promo`.id_restaurant="'.$search['restaurant'].'" '; + $query .= " and `promo`.id_restaurant=".$search['restaurant']." "; } if ($search['id_user']) { - $query .= ' and `promo`.id_user="'.$search['id_user'].'" '; + $query .= " and `promo`.id_user='".$search['id_user']."' "; } $query .= 'ORDER BY `id_promo` DESC'; diff --git a/include/library/Crunchbutton/Suggestion.php b/include/library/Crunchbutton/Suggestion.php index 7beee609b..8fc7c7a85 100644 --- a/include/library/Crunchbutton/Suggestion.php +++ b/include/library/Crunchbutton/Suggestion.php @@ -39,29 +39,29 @@ class Crunchbutton_Suggestion extends Cana_Table { $query = 'SELECT `suggestion`.* FROM `suggestion` LEFT JOIN restaurant USING(id_restaurant) WHERE id_suggestion IS NOT NULL '; if ($search['type']) { - $query .= ' and type="'.$search['type'].'" '; + $query .= " and type='".$search['type']."' "; } if ($search['status']) { - $query .= ' and status="'.$search['status'].'" '; + $query .= " and status='".$search['status']."' "; } if ($search['start']) { $s = new DateTime($search['start']); - $query .= ' and DATE(`date`)>="'.$s->format('Y-m-d').'" '; + $query .= " and DATE(`date`)>='".$s->format('Y-m-d')."' "; } if ($search['end']) { $s = new DateTime($search['end']); - $query .= ' and DATE(`date`)<="'.$s->format('Y-m-d').'" '; + $query .= " and DATE(`date`)<='".$s->format('Y-m-d')."' "; } if ($search['restaurant']) { - $query .= ' and `suggestion`.id_restaurant="'.$search['restaurant'].'" '; + $query .= ' and `suggestion`.id_restaurant='.$search['restaurant'].' '; } if ($search['community']) { - $query .= ' and `suggestion`.id_community="'.$search['community'].'" '; + $query .= ' and `suggestion`.id_community='.$search['community'].' '; } if ($search['search']) { diff --git a/include/library/Crunchbutton/Support.php b/include/library/Crunchbutton/Support.php index c9e03dd77..901745695 100644 --- a/include/library/Crunchbutton/Support.php +++ b/include/library/Crunchbutton/Support.php @@ -533,21 +533,21 @@ class Crunchbutton_Support extends Cana_Table_Trackchange { $query = 'SELECT `support`.* FROM `support` WHERE id_support IS NOT NULL '; if ($search['type']) { - $query .= ' and type="'.$search['type'].'" '; + $query .= " and type='".$search['type']."' "; } if ($search['status']) { - $query .= ' and status="'.$search['status'].'" '; + $query .= " and status='".$search['status']."' "; } if ($search['start']) { $s = new DateTime($search['start']); - $query .= ' and DATE(`date`)>="'.$s->format('Y-m-d').'" '; + $query .= " and DATE(`date`)>='".$s->format('Y-m-d')."' "; } if ($search['end']) { $s = new DateTime($search['end']); - $query .= ' and DATE(`date`)<="'.$s->format('Y-m-d').'" '; + $query .= " and DATE(`date`)<='".$s->format('Y-m-d')."' "; } if ($search['search']) { diff --git a/include/library/Crunchbutton/User/Auth.php b/include/library/Crunchbutton/User/Auth.php index b7452176f..7545b9501 100644 --- a/include/library/Crunchbutton/User/Auth.php +++ b/include/library/Crunchbutton/User/Auth.php @@ -26,25 +26,25 @@ class Crunchbutton_User_Auth extends Cana_Table { SELECT * FROM user_auth WHERE - type="'.$type.'" - AND auth="'.$id.'" + type=? + AND auth=? LIMIT 1 - '); + ', [$type, $id]); return new Crunchbutton_User_Auth($row); } public static function localLogin( $email, $password ) { $password = static::passwordEncrypt( $password ); - $query = ' + $query = " SELECT * FROM user_auth WHERE - type="local" + type='local' AND email=:email AND auth=:password AND active=true LIMIT 1 - '; + "; $row = Cana::db()->get($query, ['email' => $email, 'password' => $password]); if( $row->_items && $row->_items[0] ){ @@ -207,15 +207,15 @@ class Crunchbutton_User_Auth extends Cana_Table { } public function validateResetCode( $code ){ - $query = ' + $query = " SELECT * FROM user_auth WHERE - type="local" + type='local' AND reset_code=:code AND active=true LIMIT 1 - '; + "; $row = Cana::db()->get( $query, ['code' => $code]); if( $row->_items && $row->_items[0] ){ $row = $row->_items[0];