/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { try { $model = ProGlobalEnquiry::model()->findByPk($id); if ($model === null) { Yii::log("The requested page does not exist."); throw new CHttpException(404, 'The requested page does not exist.'); } return $model; } catch (Exception $e) { Yii::log("Exception " . print_r($e, true), 'error'); throw new CHttpException("Exception " . print_r($e, true)); } }
* Time: 3:36 PM * To change this template use File | Settings | File Templates. */ class EnquiryController extends Controller { public function actionSendGlobal() { $model = new ProGlobalEnquiry('create'); if (isset($_POST['ProGlobalEnquiry'])) { $model->attributes = $_POST['ProGlobalEnquiry']; if ($model->type_enquiry == 'Buy') { $model->scenario = 'remove'; } if ($model->type_enquiry == 'Rent' && $model->rent_type == 'Tenant') { $model->scenario = 'remove'; } if ($model->validate()) { $model->choosetype = isset($_POST['choosetype']) ? $_POST['choosetype'] : 0; $model->property_type_code = isset($_POST['property_type_code']) ? is_array($_POST['property_type_code']) ? implode(',', $_POST['property_type_code']) : "" : ''; $model->location_list_id = isset($_POST['location_list_id']) ? is_array($_POST['location_list_id']) ? implode(',', $_POST['location_list_id']) : "" : ''; if (!empty($model->min_price) && !empty($model->max_price)) { $model->price = $model->min_price . " - " . $model->max_price; } elseif (!empty($model->min_price)) { $model->price = "Over " . $model->min_price; } elseif (!empty($model->max_price)) { $model->price = "Lower than " . $model->max_price; } if (!empty($model->min_bedroom) && !empty($model->max_bedroom)) { $model->bedrooms = $model->min_bedroom . " - " . $model->max_bedroom; } elseif (!empty($model->min_bedroom)) { $model->bedrooms = "Over " . $model->min_bedroom; } elseif (!empty($model->max_bedroom)) { $model->bedrooms = "Lower than " . $model->max_bedroom; } if (!empty($model->min_bathroom) && !empty($model->max_bathroom)) { $model->bathrooms = $model->min_bathroom . " - " . $model->max_bathroom; } elseif (!empty($model->min_bathroom)) { $model->bathrooms = "Over " . $model->min_bathroom; } elseif (!empty($model->max_bathroom)) { $model->bathrooms = "Lower than " . $model->max_bathroom; } if (!empty($model->min_floor_size) && !empty($model->max_floor_size)) { $model->floor_size = $model->min_floor_size . " - " . $model->max_floor_size; } elseif (!empty($model->min_floor_size)) { $model->floor_size = "Over " . $model->min_floor_size; } elseif (!empty($model->max_floor_size)) { $model->floor_size = "Lower than " . $model->max_floor_size; } if (!empty($model->min_unit) && !empty($model->max_unit)) { $model->unit = $model->min_unit . " - " . $model->max_unit; } elseif (!empty($model->min_unit)) { $model->unit = "Over " . $model->min_unit; } elseif (!empty($model->max_unit)) { $model->unit = "Lower than " . $model->max_unit; } // if(!empty($model->furnishing_include) && $model->type_enquiry =='Buy' ){ if (!empty($model->furnishing_include)) { $model->furnishing_include = json_encode($model->furnishing_include); } if (!empty($model->special_features) && $model->type_enquiry == 'Sell') { $model->special_features = json_encode($model->special_features); } if (!empty($model->tenancy_expiry_datepicker)) { $model->tenancy_expiry_datepicker = date('Y-m-d', strtotime($model->tenancy_expiry_datepicker)); } else { $model->tenancy_expiry_datepicker = NULL; } $model->created_date = date('Y-m-d H:i:s'); if ($model->save()) { // Jun 07, 2014 ANH DUNG update file id ProEnquiryGlobalFile::UpdateEnquiryGlobalId($model->id, $model->file_id); //insert Subscriber if (!empty($_POST['ProGlobalEnquiry']['get_update'])) { Subscriber::saveSubscriberPublic($model->email, 2, $model->name); } //email to Admin SendEmail::sendMailEnquiryGlobalToAdmin($model); //email to sub Admin // SendEmail::sendMailEnquiryGlobalToSubAdmin($model); //email to sender - Jan 23, 2015 ANH DUNG if (trim($model->email)) { SendEmail::sendMailEnquiryGlobalToSender($model); } $thankYouEnquiry = Pages::getPageById(PAGE_THANK_ENQUIRY_GLOBAL); Yii::app()->user->setFlash('success', $thankYouEnquiry->content); $this->redirect(Yii::app()->createAbsoluteUrl('page/index', array('slug' => $thankYouEnquiry->slug))); } else { $this->redirect(Yii::app()->createAbsoluteUrl('/')); } } else { $this->redirect(Yii::app()->createAbsoluteUrl('/'));