Exemple #1
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int');
     $listingType = SJB_Request::getVar('listing_type', null);
     if (!$listingType) {
         if ($listingId) {
             $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
             $listingType = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
         } else {
             $listingType = 'job';
         }
     }
     $displayForm = SJB_Request::getVar('displayForm', false);
     $error = null;
     if (!SJB_Acl::getInstance()->isAllowed('save_' . trim($listingType))) {
         $error = 'DENIED_SAVE_LISTING';
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         if (!$error) {
             if (!is_null($listingId)) {
                 if (SJB_UserManager::isUserLoggedIn()) {
                     SJB_SavedListings::saveListingOnDB($listingId, SJB_UserManager::getCurrentUserSID());
                     SJB_Statistics::addStatistics('saveListing', SJB_ListingTypeManager::getListingTypeSIDByID($listingType), $listingId);
                 } else {
                     SJB_SavedListings::saveListingInCookie($listingId);
                 }
                 $template_processor->assign('saved_listing', SJB_SavedListings::getSavedListingsByUserAndListingSid(SJB_UserManager::getCurrentUserSID(), $listingId));
             } else {
                 $error = 'LISTING_ID_NOT_SPECIFIED';
             }
         }
         $params = SJB_Request::getVar('params', false);
         $searchId = SJB_Request::getVar('searchId', false);
         $page = SJB_Request::getVar('page', false);
         $template_processor->assign("params", $params);
         $template_processor->assign("searchId", $searchId);
         $template_processor->assign("page", $page);
         $template_processor->assign("listing_type", $listingType);
         $template_processor->assign("listing_sid", $listingId);
         $template_processor->assign("from_login", SJB_Request::getVar("from_login", false));
         $template_processor->assign("error", $error);
         $template_processor->assign("displayForm", $displayForm);
         $template_processor->assign("view", SJB_Request::getVar('view'));
         $template_processor->display("save_listing.tpl");
     } else {
         $template_processor->assign("return_url", base64_encode(SJB_Navigator::getURIThis() . "&from_login=1"));
         $template_processor->assign("ajaxRelocate", true);
         $template_processor->display("../users/login.tpl");
     }
 }
Exemple #2
0
 public function current()
 {
     $listing_structure = array();
     $info = current($this->array);
     if (is_numeric($info)) {
         $sid = $info;
         $cache = SJB_Cache::getInstance();
         $cacheID = md5('ListingIterator::SJB_ListingManager::getObjectBySID' . $sid);
         if ($cache->test($cacheID)) {
             $listing = $cache->load($cacheID);
         } else {
             $listing = SJB_ListingManager::getObjectBySID($sid);
             $cache->save($listing, $cacheID, array(SJB_Cache::TAG_LISTINGS));
         }
         $listing->addPicturesProperty();
         $cacheId = md5('SJB_ListingTypeManager::getListingTypeIDBySID' . $listing->getListingTypeSID());
         if (SJB_MemoryCache::has($cacheId)) {
             $listing_type = SJB_MemoryCache::get($cacheId);
         } else {
             $listing_type = SJB_ListingTypeManager::getListingTypeIDBySID($listing->getListingTypeSID());
             SJB_MemoryCache::set($cacheId, $listing_type);
         }
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
         $listing_structure = SJB_ListingManager::newValueFromSearchCriteria($listing_structure, $this->criteria);
         if ($this->user_logged_in) {
             $listing_structure['saved_listing'] = SJB_SavedListings::getSavedListingsByUserAndListingSid($this->current_user_sid, $listing->getID());
         }
         $listing_structure['activation_date'] = date('Y-m-d H:i:s', strtotime($listing_structure['activation_date']));
         $listing_structure['expiration_date'] = date('Y-m-d H:i:s', strtotime($listing_structure['expiration_date']));
         $listing_structure['listing_url'] = SJB_System::getSystemSettings('SITE_URL') . "/display-" . strtolower($listing_type) . "/" . $listing->getSID() . "/";
         if (isset($listing->details->properties['EmploymentType'])) {
             $employmentInfo = $listing->details->properties['EmploymentType']->type->property_info;
             $employmentTypes = array();
             $employment = explode(",", $employmentInfo['value']);
             foreach ($employmentInfo['list_values'] as $type) {
                 $empType = str_replace(" ", "", $type['caption']);
                 $employmentTypes[$empType] = 0;
                 if (in_array($type['id'], $employment)) {
                     $employmentTypes[$empType] = 1;
                 }
             }
             $listing_structure['myEmploymentType'] = $employmentTypes;
         }
         // GOOGLE MAP SEARCH RESULTS CUSTOMIZATION
         if ($this->view == 'map') {
             $zipCode = $listing_structure['Location']['ZipCode'];
             // get 'latitude' and 'longitude' from zipCode field, if it not set
             $latitude = isset($listing_structure['latitude']) ? $listing_structure['latitude'] : '';
             $longitude = isset($listing_structure['longitude']) ? $listing_structure['longitude'] : '';
             if (!empty($zipCode) && empty($latitude) && empty($longitude)) {
                 $result = SJB_DB::query("SELECT * FROM `locations` WHERE `name` = ?s LIMIT 1", $zipCode);
                 if ($result) {
                     $current_coordinates = array($result[0]['latitude'], $result[0]['longitude']);
                     if (in_array($current_coordinates, self::$coordinates)) {
                         self::$index += 0.0001;
                     }
                     $listing_structure['latitude'] = $result[0]['latitude'] + self::$index;
                     $listing_structure['longitude'] = $result[0]['longitude'] + self::$index;
                     self::$coordinates = array_merge(self::$coordinates, array($current_coordinates));
                 }
             } elseif (!empty($listing_structure['Location']['City']) && !empty($listing_structure['Location']['State']) && !empty($listing_structure['Location']['Country'])) {
                 $address = $listing_structure['Location']['City'] . ', ' . $listing_structure['Location']['State'] . ', ' . $listing_structure['Location']['Country'];
                 $address = urlencode($address);
                 $cache = SJB_Cache::getInstance();
                 $parameters = array('City' => $listing_structure['Location']['City'], 'State' => $listing_structure['Location']['State'], 'Country' => $listing_structure['Location']['Country']);
                 $hash = md5('google_map' . serialize($parameters));
                 $data = $cache->load($hash);
                 if (!$data) {
                     try {
                         $geoCod = SJB_HelperFunctions::getUrlContentByCurl("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=false");
                         $geoCod = json_decode($geoCod);
                         if ($geoCod->status == 'OK') {
                             $cache->save($geoCod, $hash);
                         }
                     } catch (Exception $e) {
                         $backtrace = SJB_Logger::getBackTrace();
                         SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace)))));
                     }
                 } else {
                     $geoCod = $data;
                 }
                 try {
                     if (!is_object($geoCod)) {
                         throw new Exception("Map object nave not been Created");
                     }
                     if ($geoCod->status != 'OK') {
                         throw new Exception("Status is not OK");
                     }
                     $location = $geoCod->results[0]->geometry->location;
                     $current_coordinates = array($location->lat, $location->lng);
                     if (in_array($current_coordinates, self::$coordinates)) {
                         self::$index += 0.0001;
                     }
                     $listing_structure['latitude'] = $location->lat + self::$index;
                     $listing_structure['longitude'] = $location->lng + self::$index;
                     self::$coordinates = array_merge(self::$coordinates, array($current_coordinates));
                 } catch (Exception $e) {
                     $backtrace = SJB_Logger::getBackTrace();
                     SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace)))));
                 }
             }
         }
     } elseif ($info) {
         $listing_structure = $info;
     }
     return $listing_structure;
 }
Exemple #3
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $actionPage = SJB_Request::getVar('action');
     $page = SJB_Request::getVar('page', false);
     $action = SJB_Request::getVar('actionNew');
     $close = SJB_Request::getVar('close', false);
     $closeWindow = SJB_Request::getVar('closeWindow', false);
     $action = $action ? $action : $actionPage;
     $action = isset($close) && $close != '' ? 'close' : $action;
     if (!$page) {
         $sid = SJB_Request::getVar('listing_sid');
         $tp->assign("listing_sid", $sid);
     } elseif ($page == 'apps') {
         $sid = SJB_Request::getVar('apps_id');
         $action = $action != 'add' ? $action . '_apps' : $action;
         $tp->assign("page", $page);
         $tp->assign("apps_id", $sid);
         $tp->assign("listing_sid", $sid);
     }
     if ($sid) {
         switch ($action) {
             case 'add':
                 $action = 'edit';
                 $tp->assign("saved_listing", false);
                 break;
             case 'save':
                 $noteSaved = false;
                 $note = SJB_Request::getVar('note');
                 if (SJB_SavedListings::saveNoteOnDB(SJB_UserManager::getCurrentUserSID(), $sid, $note)) {
                     $noteSaved = true;
                 }
                 $tp->assign("noteText", $note);
                 $tp->assign("noteSaved", $noteSaved);
                 break;
             case 'edit':
                 $saved_listing = SJB_SavedListings::getSavedListingsByUserAndListingSid(SJB_UserManager::getCurrentUserSID(), $sid);
                 $tp->assign("saved_listing", $saved_listing);
                 break;
             case 'save_apps':
                 $noteSaved = false;
                 $note = SJB_Request::getVar('note');
                 if (SJB_Applications::saveNoteOnDB($note, $sid)) {
                     $noteSaved = true;
                 }
                 $action = 'save';
                 $tp->assign("noteSaved", $noteSaved);
                 break;
             case 'edit_apps':
                 $apps = SJB_Applications::getById($sid);
                 $action = 'edit';
                 $tp->assign("saved_listing", $apps);
                 break;
             case 'close_apps':
                 $apps = SJB_Applications::getById($sid);
                 $action = 'close';
                 $tp->assign("saved_listing", $apps);
                 break;
             case 'close':
                 $saved_listing = SJB_SavedListings::getSavedListingsByUserAndListingSid(SJB_UserManager::getCurrentUserSID(), $sid);
                 $tp->assign("saved_listing", $saved_listing);
                 break;
         }
     } else {
         if (!$page) {
             $errors['UNDEFINED_LISTING_ID'] = true;
         } else {
             $errors['UNDEFINED_APPS_ID'] = true;
         }
     }
     $tp->assign('view', SJB_Request::getVar('view'));
     $tp->assign("closeWindow", $closeWindow);
     $tp->assign("action", $action);
     $tp->assign("errors", $errors);
     $tp->display('notes.tpl');
 }
Exemple #4
0
 function getListingCollectionStructure($sorted_found_listings_sids_for_current_page)
 {
     $listings_structure = array();
     $currentUserSID = SJB_UserManager::getCurrentUserSID();
     $isUserLoggedIn = SJB_UserManager::isUserLoggedIn();
     foreach ($sorted_found_listings_sids_for_current_page as $sid) {
         $listing = SJB_ListingManager::getObjectBySID($sid);
         $listing->addPicturesProperty();
         $listings_structure[$listing->getID()] = SJB_ListingManager::createTemplateStructureForListing($listing);
         $listings_structure[$listing->getID()] = SJB_ListingManager::newValueFromSearchCriteria($listings_structure[$listing->getID()], $this->criteria_saver->criteria);
         if ($isUserLoggedIn) {
             $listings_structure[$listing->getID()]['saved_listing'] = SJB_SavedListings::getSavedListingsByUserAndListingSid($currentUserSID, $listing->getID());
         }
     }
     return $listings_structure;
 }