예제 #1
0
 public function newAction()
 {
     if ($this->request->isPost()) {
         $countryId = $this->request->getPost('country_id');
         $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'id LIKE :id:', 'bind' => array('id' => $countryId)));
         $countryName = '';
         if ($country) {
             $countryName = $country->country;
         }
         $address = str_replace(' ', '+', $this->request->getPost('street') . '+' . $this->request->getPost('city') . '+' . $countryName);
         $userSession = $this->session->get("userSession");
         $content = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&key=AIzaSyAbpLPfBH8sNdVSzMULD_BZN9qrAqbL3V8');
         $json = json_decode($content, true);
         $lat = $json['results'][0]['geometry']['location']['lat'];
         $lng = $json['results'][0]['geometry']['location']['lng'];
         //error_log('LAT : '.$lat.' LONG : '.$lng);
         $business = new Business();
         $business->created = date('Y-m-d H:i:s');
         $business->modified = date('Y-m-d H:i:s');
         $business->member_id = $userSession['id'];
         $business->name = $this->request->getPost('name');
         $business->website = $this->request->getPost('website');
         $business->telephone = $this->request->getPost('telephone');
         $business->street = $this->request->getPost('street');
         $business->city = $this->request->getPost('city');
         $business->country_id = $this->request->getPost('country_id');
         $business->lat = $lat;
         $business->lng = $lng;
         $business->business_category_id = $this->request->getPost('business_category_id');
         if ($business->create()) {
             $id = $business->id;
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>New business has been created');
             if (!empty($this->request->getPost('review'))) {
                 $review = new Reviews();
                 $review->created = date('Y-m-d H:i:s');
                 $review->modified = date('Y-m-d H:i:s');
                 $review->member_id = $userSession['id'];
                 $review->business_id = $business->id;
                 $review->content = $this->request->getPost('review');
                 $review->rate = $this->request->getPost('rate');
                 if ($review->create()) {
                     $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>You\'re review has been submitted.');
                 }
             }
             return $this->response->redirect('business/view/' . $id);
         }
     }
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
     $realtyConditions = RealtyConditions::find();
     $this->view->setVar('realtyConditions', $realtyConditions);
     $realtyTypes = RealtyTypes::find();
     $this->view->setVar('realtyTypes', $realtyTypes);
     $realtyCategories = RealtyCategories::find();
     $this->view->setVar('realtyCategories', $realtyCategories);
 }
예제 #2
0
 public function indexAction()
 {
     $searchWords = '';
     $business = array();
     if (isset($_GET["page"])) {
         $currentPage = (int) $_GET["page"];
     } else {
         $currentPage = 1;
     }
     if ($this->request->isPost()) {
         $businessName = $this->request->getPost('name');
         $businessAddress = $this->request->getPost('address');
         $businessCategoryId = $this->request->getPost('business_category_id');
         $businessCategory = BusinessCategories::findFirst($businessCategoryId);
         $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'country LIKE :country:', 'bind' => array('country' => $businessAddress)));
         $countryId = '';
         if ($country) {
             $countryId = $country->id;
         }
         $conditions = '';
         $bind = array();
         if (!empty($businessName)) {
             $conditions .= ' OR name LIKE :name:';
             $bind['name'] = '%' . $businessName . '%';
             $searchWords .= ', ' . $businessName;
         }
         if (!empty($businessAddress)) {
             $conditions .= ' OR street LIKE :street:';
             $bind['street'] = '%' . $businessAddress . '%';
             $conditions .= ' OR city LIKE :city:';
             $bind['city'] = '%' . $businessAddress . '%';
             $searchWords .= ', ' . $businessAddress;
         }
         if (!empty($countryId)) {
             $conditions .= ' OR country_id LIKE :country_id:';
             $bind['country_id'] = $countryId;
             $searchWords .= ', ' . $country->country;
         }
         if (!empty($businessCategoryId)) {
             $conditions .= ' OR business_category_id = :business_category_id:';
             $bind['business_category_id'] = $businessCategoryId;
             $searchWords .= ', ' . $businessCategory->name;
         }
         $business = Business::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     } else {
         $business = Business::find();
     }
     // Create a Model paginator, show 10 rows by page starting from $currentPage
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $business, "limit" => 10, "page" => $currentPage));
     $page = $paginator->getPaginate();
     $this->view->setVar('searchWords', $searchWords);
     $this->view->setVar('business', $page);
     $businessCategories = BusinessCategories::find();
     $this->view->setVar('businessCategories', $businessCategories);
 }
 public function countryInfoAction()
 {
     $this->view->disable();
     $country = Countries::findFirst("countryCode='" . $_POST["id"] . "'");
     $list = $this->jquery->semantic()->htmlList("");
     $list->addHeader(3, "")->asImage("https://lipis.github.io/flag-icon-css/flags/4x3/" . strtolower($_POST["id"]) . ".svg", $country->getCountryName(), $country->getContinentName());
     $list->addItem("Population : " . number_format($country->getPopulation()))->addIcon("users");
     $list->addItem("Currency code : " . $country->getCurrencyCode())->addIcon("payment");
     $list->addItem("Capital : " . $country->getCapital())->addIcon("diamond");
     echo $list->setDivided();
 }
예제 #4
0
 public function update_businessAction($businessId = null)
 {
     $business = Business::findFirst($businessId);
     if (!$business) {
         return $this->response->redirect('biz/business_search');
     }
     if ($this->request->isPost()) {
         $countryId = $this->request->getPost('country_id');
         $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'id LIKE :id:', 'bind' => array('id' => $countryId)));
         $countryName = '';
         if ($country) {
             $countryName = $country->country;
         }
         $address = str_replace(' ', '+', $this->request->getPost('street') . '+' . $this->request->getPost('city') . '+' . $countryName);
         $userSession = $this->session->get("userSession");
         $content = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&key=AIzaSyAbpLPfBH8sNdVSzMULD_BZN9qrAqbL3V8');
         $json = json_decode($content, true);
         $lat = $json['results'][0]['geometry']['location']['lat'];
         $lng = $json['results'][0]['geometry']['location']['lng'];
         $business->modified = date('Y-m-d H:i:s');
         $business->member_id = $userSession['id'];
         $business->name = $this->request->getPost('name');
         $business->website = $this->request->getPost('website');
         $business->telephone = $this->request->getPost('telephone');
         $business->street = $this->request->getPost('street');
         $business->city = $this->request->getPost('city');
         $business->country_id = $this->request->getPost('country_id');
         $business->lat = $lat;
         $business->lng = $lng;
         $opened = '';
         if (!empty($this->request->getPost('opened'))) {
             $opened = 'Opened';
         }
         if (empty($this->request->getPost('opened'))) {
             $opened = 'Opening Soon';
         }
         $business->opened = $opened;
         if ($business->update()) {
             if (!empty($this->request->getPost('business_category_ids'))) {
                 $bCtegories = $this->request->getPost('business_category_ids');
                 $bCtegoryIds = explode(',', $bCtegories);
                 BusinessCategoryLists::find('business_id="' . $businessId . '"')->delete();
                 foreach ($bCtegoryIds as $key => $bCtegoryId) {
                     $businessCategoryLists = new BusinessCategoryLists();
                     $businessCategoryLists->created = date('Y-m-d H:i:s');
                     $businessCategoryLists->business_id = $businessId;
                     $businessCategoryLists->business_category_id = $bCtegoryId;
                     $businessCategoryLists->create();
                 }
             }
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>Business has been updated');
             return $this->response->redirect('business/view/' . $businessId);
         }
     }
     $this->view->setVar('business', $business);
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
     $businessCategoryLists = BusinessCategoryLists::find('business_id="' . $businessId . '"');
     $this->view->setVar('businessCategoryLists', $businessCategoryLists);
 }
예제 #5
0
 public function updateAction($id = null)
 {
     if ($this->request->isPost()) {
         $id = $this->request->getPost('id');
         $countryId = $this->request->getPost('country_id');
         $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'id LIKE :id:', 'bind' => array('id' => $countryId)));
         $countryName = '';
         if ($country) {
             $countryName = $country->country;
         }
         $address = str_replace(' ', '+', $this->request->getPost('street') . '+' . $this->request->getPost('city') . '+' . $countryName);
         $userSession = $this->session->get("userSession");
         $content = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&key=AIzaSyAbpLPfBH8sNdVSzMULD_BZN9qrAqbL3V8');
         $json = json_decode($content, true);
         $lat = $json['results'][0]['geometry']['location']['lat'];
         $lng = $json['results'][0]['geometry']['location']['lng'];
         //error_log('LAT : '.$lat.' LONG : '.$lng);
         $property = Realties::findFirst($id);
         $property->modified = date('Y-m-d H:i:s');
         $property->member_id = $userSession['id'];
         $property->name = $this->request->getPost('name');
         $property->details = $this->request->getPost('details');
         $property->price = str_replace(',', '', $this->request->getPost('price'));
         $property->street = $this->request->getPost('street');
         $property->city = $this->request->getPost('city');
         $property->country_id = $this->request->getPost('country_id');
         $property->lat = $lat;
         $property->lng = $lng;
         $property->realty_condition_id = $this->request->getPost('realty_condition_id');
         $property->realty_category_id = $this->request->getPost('realty_category_id');
         $property->realty_type_id = $this->request->getPost('realty_type_id');
         $property->house_area = $this->request->getPost('house_area');
         $property->lot_area = $this->request->getPost('lot_area');
         $property->bedrooms = $this->request->getPost('bedrooms');
         $property->bathrooms = $this->request->getPost('bathrooms');
         $property->parking = $this->request->getPost('parking');
         $property->pets_allowed = $this->request->getPost('pets_allowed');
         if ($property->update()) {
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>New property has been updated');
             for ($i = 1; $i <= 7; $i++) {
                 $fileId = $this->request->getPost('fileId' . $i);
                 if (!empty($fileId)) {
                     $realtyPhotos = RealtyPhotos::findFirst($fileId);
                     $realtyPhotos->created = date('Y-m-d H:i:s');
                     $realtyPhotos->modified = date('Y-m-d H:i:s');
                     $realtyPhotos->member_id = $userSession['id'];
                     $realtyPhotos->caption = $this->request->getPost('caption' . $i);
                     $realtyPhotos->update();
                 }
             }
             if ($this->request->hasFiles() == true) {
                 //ini_set('upload_max_filesize', '64M');
                 set_time_limit(1200);
                 $uploads = $this->request->getUploadedFiles();
                 $isUploaded = false;
                 #do a loop to handle each file individually
                 foreach ($uploads as $upload) {
                     $imageName = $upload->getKey();
                     //$this->request->getPost('image'.$ctr);
                     $inputRow = str_replace('image', '', $imageName);
                     $fileId = $this->request->getPost('fileId' . $inputRow);
                     #define a “unique” name and a path to where our file must go
                     $fileName = $upload->getName();
                     $fileInfo = new SplFileInfo($fileName);
                     $fileExt = $fileInfo->getExtension();
                     $fileExt = strtolower($fileExt);
                     $newFileName = substr(md5(uniqid(rand(), true)), 0, 10) . date('ymdhis') . '.' . $fileExt;
                     //$fileExt = $upload->getExtension();
                     $fileImageExt = array('jpeg', 'jpg', 'png');
                     $fileType = '';
                     $filePath = '';
                     $path = '';
                     if (in_array($fileExt, $fileImageExt)) {
                         $path = 'img/realty/' . $newFileName;
                         $filePath = 'img/realty/';
                         //$fileType = 'Image';
                     }
                     #move the file and simultaneously check if everything was ok
                     $upload->moveTo($path) ? $isUploaded = true : ($isUploaded = false);
                     if ($isUploaded) {
                         if (!empty($fileId)) {
                             $realtyPhotos = RealtyPhotos::findFirst($fileId);
                             $realtyPhotos->modified = date('Y-m-d H:i:s');
                             $realtyPhotos->member_id = $userSession['id'];
                             $realtyPhotos->file_path = $filePath;
                             $realtyPhotos->filename = $newFileName;
                             $realtyPhotos->update();
                         } else {
                             $realtyPhotos = new RealtyPhotos();
                             $realtyPhotos->created = date('Y-m-d H:i:s');
                             $realtyPhotos->modified = date('Y-m-d H:i:s');
                             $realtyPhotos->member_id = $userSession['id'];
                             $realtyPhotos->realty_id = $id;
                             $realtyPhotos->file_path = $filePath;
                             $realtyPhotos->filename = $newFileName;
                             $realtyPhotos->caption = $this->request->getPost('caption' . $inputRow);
                             $realtyPhotos->create();
                         }
                     }
                 }
                 #if any file couldn't be moved, then throw an message
             }
             return $this->response->redirect('real_estate/view/' . $id);
         }
     }
     $property = Realties::findFirst($id);
     if (!$property) {
         return $this->response->redirect('real_estate/index');
     }
     $this->view->setVar('property', $property);
     $realtyPhotos = RealtyPhotos::find('realty_id ="' . $id . '"');
     $this->view->setVar('realtyPhotos', $realtyPhotos);
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
     $realtyConditions = RealtyConditions::find();
     $this->view->setVar('realtyConditions', $realtyConditions);
     $realtyTypes = RealtyTypes::find();
     $this->view->setVar('realtyTypes', $realtyTypes);
     $realtyCategories = RealtyCategories::find();
     $this->view->setVar('realtyCategories', $realtyCategories);
 }
예제 #6
0
 public function indexAction()
 {
     $searchWords = '';
     $jobs = array();
     if (isset($_GET["page"])) {
         $currentPage = (int) $_GET["page"];
     } else {
         $currentPage = 1;
     }
     if ($this->request->isPost()) {
         $position = $this->request->getPost('position');
         $company = $this->request->getPost('company');
         $address = $this->request->getPost('address');
         $jobCategoryId = $this->request->getPost('job_category_id');
         $salaryFrom = $this->request->getPost('salary_from');
         $salaryTo = $this->request->getPost('salary_to');
         $this->view->position = $position;
         $jobCategory = JobCategories::findFirst($jobCategoryId);
         $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'country LIKE :country:', 'bind' => array('country' => $address)));
         $countryId = '';
         if ($country) {
             $countryId = $country->id;
         }
         $conditions = '';
         $bind = array();
         if (!empty($position)) {
             $conditions .= ' OR position LIKE :position:';
             $bind['position'] = '%' . $position . '%';
             $searchWords .= ', ' . $position;
         }
         if (!empty($company)) {
             $conditions .= ' OR company LIKE :company:';
             $bind['company'] = '%' . $company . '%';
             $searchWords .= ', ' . $company;
         }
         if (!empty($address)) {
             $conditions .= ' OR street LIKE :street:';
             $bind['street'] = '%' . $address . '%';
             $conditions .= ' OR city LIKE :city:';
             $bind['city'] = '%' . $address . '%';
             $searchWords .= ', ' . $address;
         }
         if (!empty($countryId)) {
             $conditions .= ' OR country_id LIKE :country_id:';
             $bind['country_id'] = $countryId;
             $searchWords .= ', ' . $country->country;
         }
         if (!empty($jobCategoryId)) {
             $conditions .= ' OR job_category_id LIKE :job_category_id:';
             $bind['job_category_id'] = $jobCategoryId;
             $searchWords .= ', ' . $jobCategory->name;
         }
         if (!empty($salaryFrom)) {
             $conditions .= ' OR salary_from LIKE :salary_from:';
             $bind['salary_from'] = $salaryFrom;
             $searchWords .= ', ' . $salaryFrom;
         }
         if (!empty($salaryTo)) {
             $conditions .= ' OR salary_to LIKE :salary_to:';
             $bind['salary_to'] = $salaryTo;
             $searchWords .= ', ' . $salaryTo;
         }
         $searchWords = substr($searchWords, 2);
         $jobs = Jobs::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     } else {
         $jobs = Jobs::find();
     }
     // Create a Model paginator, show 10 rows by page starting from $currentPage
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $jobs, "limit" => 10, "page" => $currentPage));
     $page = $paginator->getPaginate();
     $this->view->setVar('searchWords', $searchWords);
     $this->view->setVar('jobs', $page);
     $jobCategories = JobCategories::find();
     $this->view->setVar('jobCategories', $jobCategories);
 }
예제 #7
0
 public function searchAction()
 {
     $keyword = $this->request->get("find");
     $location = $this->request->get("near");
     $searchWords = '';
     $this->view->setVar('find', $keyword);
     $this->view->setVar('near', $near);
     $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'country LIKE :country:', 'bind' => array('country' => $location)));
     $countryId = '';
     if ($country) {
         $countryId = $country->id;
     }
     $conditions = '';
     if (!empty($keyword)) {
         $conditions .= ' OR name LIKE :name:';
         $bind['name'] = '%' . $keyword . '%';
         $searchWords .= ', ' . $keyword;
     }
     if (!empty($location)) {
         $conditions .= ' OR street LIKE :street: OR city LIKE :city:';
         $bind['street'] = '%' . $location . '%';
         $bind['city'] = '%' . $location . '%';
         $searchWords .= ', ' . $location;
     }
     if (!empty($countryId)) {
         $conditions .= ' OR country_id = :country_id:';
         $bind['country_id'] = $countryId;
         $searchWords .= ', ' . $country->country;
     }
     $searchWords = substr($searchWords, 2);
     $business = Business::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     $this->view->setVar('business', $business);
     //CARS and TRUCKS
     $conditions = '';
     $bind = array();
     if (!empty($keyword)) {
         $conditions = ' OR name LIKE :name:';
         $bind['name'] = '%' . $keyword . '%';
     }
     if (!empty($keyword)) {
         $conditions .= ' OR brand LIKE :brand:';
         $bind['brand'] = '%' . $keyword . '%';
     }
     if (!empty($keyword)) {
         $conditions .= ' OR model LIKE :model:';
         $bind['model'] = '%' . $keyword . '%';
     }
     if (!empty($location)) {
         $conditions .= ' OR location LIKE :location:';
         $bind['location'] = $location;
     }
     $autos = Automotives::find(['columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind]);
     $this->view->setVar('autos', $autos);
     $conditions = '';
     $bind = array();
     if (!empty($keyword)) {
         $conditions = 'name LIKE :name:';
         $bind['name'] = '%' . $keyword . '%';
     }
     $things = Things::find(['columns' => '*', 'conditions' => $conditions, 'bind' => $bind]);
     $this->view->setVar('things', $things);
     //JOBS
     $conditions = '';
     $bind = array();
     if (!empty($keyword)) {
         $conditions .= ' OR position LIKE :position:';
         $bind['position'] = '%' . $keyword . '%';
         $searchWords .= ', ' . $keyword;
     }
     if (!empty($keyword)) {
         $conditions .= ' OR company LIKE :company:';
         $bind['company'] = '%' . $keyword . '%';
         $searchWords .= ', ' . $keyword;
     }
     if (!empty($location)) {
         $conditions .= ' OR street LIKE :street:';
         $bind['street'] = '%' . $location . '%';
         $conditions .= ' OR city LIKE :city:';
         $bind['city'] = '%' . $location . '%';
         $searchWords .= ', ' . $location;
     }
     if (!empty($countryId)) {
         $conditions .= ' OR country_id LIKE :country_id:';
         $bind['country_id'] = $countryId;
         $searchWords .= ', ' . $country->country;
     }
     $jobs = Jobs::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     $this->view->setVar('jobs', $jobs);
 }
예제 #8
0
 public function deleteAction($id = null)
 {
     if (empty($id)) {
         $this->getFlashSession('error', 'Invalid country.', true);
         // Forward to index
         return $this->response->redirect("/country");
     }
     $country = Countries::findFirst(array("id = :id:", "bind" => array('id' => $id)));
     if (!empty($country)) {
         // delete
         if ($country->delete() == false) {
             $this->logger->log("Failed to delete country", \Phalcon\Logger::ERROR);
             foreach ($country->getMessages() as $message) {
                 $this->logger->log($message, \Phalcon\Logger::ERROR);
             }
             $this->getFlashSession('error', 'Sorry, we could not delete the record. Please try again.', true);
         } else {
             $this->getFlashSession('success', 'Country record deleted.', true);
             // Forward to dashboard
             return $this->response->redirect("/country");
         }
     } else {
         $this->getFlashSession('error', 'Invalid country record.', true);
         // Forward to dashboard
         return $this->response->redirect("/country");
     }
     // Forward to dashboard
     return $this->response->redirect("/country");
 }