/**
  * @return array
  */
 public function getListingsSIDsByFeedCriteria()
 {
     $searchData = $this->prepareSearchData($this->feedInfo['search_data']);
     $searchResultsTP = new SJB_SearchResultsTP($searchData, $this->listingTypeID);
     $searchResultsTP->getChargedTemplateProcessor();
     return $searchResultsTP->found_listings_sids;
 }
Пример #2
0
 public function execute()
 {
     $template = SJB_Request::getVar('template', 'featured_listings.tpl');
     $listingType = SJB_Request::getVar('listing_type', 'Job');
     $searches['data']['listing_type']['equal'] = $listingType;
     $searches['data']['featured']['equal'] = 1;
     $searches['data']['default_listings_per_page'] = SJB_Request::getVar('items_count', 1);
     $searches['data']['sorting_field'] = 'featured_last_showed';
     $searches['data']['default_sorting_field'] = 'featured_last_showed';
     $searches['data']['default_sorting_order'] = 'ASC';
     $searches['data']['sorting_order'] = 'ASC';
     // фичерные листинги кешировать не будем
     $cache = SJB_Cache::getInstance();
     $caching = $cache->getOption('caching');
     $cache->setOption('caching', false);
     $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listingType);
     $searchResultsTP->setLimit(SJB_Request::getVar('items_count', 1));
     $tp = $searchResultsTP->getChargedTemplateProcessor();
     $featuredListingSIDs = $searchResultsTP->getListingSidCollectionForCurrentPage();
     if ($featuredListingSIDs) {
         SJB_DB::query('UPDATE `listings` SET `featured_last_showed` = NOW() WHERE `sid` in (?w)', implode(',', $featuredListingSIDs));
         SJB_Statistics::addSearchStatistics($featuredListingSIDs, $listingType);
     }
     $cache->setOption('caching', $caching);
     $tp->assign('number_of_cols', SJB_Request::getVar('number_of_cols', 1));
     $tp->display($template);
 }
Пример #3
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $count_listing = SJB_Request::getVar('count_listing', 10, null, 'int');
     $current_user = SJB_UserManager::getCurrentUser();
     if (SJB_UserManager::isUserLoggedIn()) {
         $lastAddedListing = SJB_ListingManager::getLastAddedListingByUserSID($current_user->getSID());
         if ($lastAddedListing) {
             $properties = $current_user->getProperties();
             $phrase['title'] = $lastAddedListing->getPropertyValue('Title');
             foreach ($properties as $property) {
                 if ($property->getType() == 'location') {
                     $fields = $property->type->child;
                     $childProperties = $fields->getProperties();
                     foreach ($childProperties as $childProperty) {
                         if (in_array($childProperty->getID(), array('City', 'State', 'Country'))) {
                             $value = $childProperty->getValue();
                             switch ($childProperty->getType()) {
                                 case 'list':
                                     if ($childProperty->getID() == 'State') {
                                         $displayAS = $childProperty->display_as;
                                         $displayAS = $displayAS ? $displayAS : 'state_name';
                                         $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS);
                                     } else {
                                         $listValues = $childProperty->type->list_values;
                                     }
                                     foreach ($listValues as $values) {
                                         if ($value == $values['id']) {
                                             $phrase[strtolower($childProperty->getID())] = $values['caption'];
                                         }
                                     }
                                     break;
                                 default:
                                     $phrase[strtolower($childProperty->getID())] = $value;
                                     break;
                             }
                         }
                     }
                 }
             }
             $phrase = array_diff($phrase, array(''));
             $phrase = implode(" ", $phrase);
             $listing_type_id = "Job";
             $request['action'] = 'search';
             $request['listing_type']['equal'] = $listing_type_id;
             $request['default_listings_per_page'] = $count_listing;
             $request['default_sorting_field'] = "activation_date";
             $request['default_sorting_order'] = "DESC";
             $request['keywords']['relevance'] = $phrase;
             $searchResultsTP = new SJB_SearchResultsTP($request, $listing_type_id, array('field' => 'keywords', 'value' => $phrase));
             $tp = $searchResultsTP->getChargedTemplateProcessor();
         }
         $tp->display('suggested_jobs.tpl');
     }
 }
Пример #4
0
 public function execute()
 {
     $template = SJB_Request::getVar('template', 'latest_listings.tpl');
     if (isset($this->params['mime_type'])) {
         header("Content-type: " . $this->params['mime_type']);
     }
     $listing_type = SJB_Request::getVar('listing_type', 'Job');
     $items_count = SJB_Request::getVar('items_count', 1);
     $searches['data']['listing_type']['equal'] = $listing_type;
     $searches['data']['default_sorting_field'] = 'activation_date';
     $searches['data']['default_sorting_order'] = 'DESC';
     $searches['data']['default_listings_per_page'] = $items_count;
     $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listing_type);
     $searchResultsTP->setLimit($items_count);
     $tp = $searchResultsTP->getChargedTemplateProcessor();
     $tp->assign('lastBuildDate', date('D, d M Y H:i:s'));
     $tp->assign('number_of_cols', SJB_Request::getVar('number_of_cols', 1));
     $tp->display($template);
 }
Пример #5
0
 public static function getRefineSearchBlock()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listingTypeId = SJB_Request::getVar('listing_type');
     if (!isset($listingTypeId['equal'])) {
         $_REQUEST['listing_type']['equal'] = SJB_Session::getValue('listing_type_id');
     }
     $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listingTypeId['equal']);
     $searchCriteria = $searchResultsTP->getCriteriaSaver()->getCriteria();
     if (SJB_Request::getVar('showRefineFields', false)) {
         $refineFields = SJB_RefineSearch::getRefineFieldsByCriteria($searchResultsTP, $searchCriteria);
         $tp->assign('refineFields', $refineFields);
     }
     $currentSearch = SJB_RefineSearch::getCurrentSearchByCriteria($searchCriteria);
     $tp->assign('currentSearch', $currentSearch);
     $tp->assign('searchId', SJB_Request::getVar('searchId'));
     $tp->assign('view', SJB_Request::getVar('view'));
     $tp->display('../classifieds/search_results_refine_block.tpl');
 }
Пример #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $current_user = SJB_UserManager::getCurrentUser();
         if ($current_user->isSubuser()) {
             // У саб-юзера должны быть свои алерты
             $current_user = $current_user->getSubuserInfo();
         } else {
             $current_user = SJB_UserManager::getCurrentUserInfo();
         }
         $listing_type_id = '';
         /************************************************************/
         $tp = SJB_System::getTemplateProcessor();
         $tp->assign('action', 'list');
         $errors = array();
         $redirectUri = '/saved-searches/';
         if (isset($_REQUEST['is_alert'])) {
             if (isset($_REQUEST['listing_type_id'])) {
                 $listing_type_id = $_REQUEST['listing_type_id'];
                 SJB_Session::setValue('listing_type_id', $listing_type_id);
             } elseif (isset($_REQUEST['restore'])) {
                 $listing_type_id = SJB_Session::getValue('listing_type_id');
             } else {
                 SJB_Session::setValue('listing_type_id', null);
             }
             if (!SJB_Acl::getInstance()->isAllowed("use_{$listing_type_id}_alerts")) {
                 $errors = array('NOT_SUBSCRIBE' => true);
                 $tp->assign('ERRORS', $errors);
                 $tp->display('error.tpl');
                 return;
             } else {
                 $redirectUri = '/' . strtolower($listing_type_id) . '-alerts/';
             }
         } else {
             if (isset($_REQUEST['listing_type_id'])) {
                 $listing_type_id = $_REQUEST['listing_type_id'];
             }
             if (!SJB_Acl::getInstance()->isAllowed('save_searches')) {
                 $errors = array('NOT_SUBSCRIBE' => true);
                 $tp->assign('ERRORS', $errors);
                 $tp->display('error.tpl');
                 return;
             }
         }
         $isSubmittedForm = SJB_Request::getVar('submit', false);
         $listing_type_sid = !empty($listing_type_id) ? SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id) : 0;
         if (!isset($_REQUEST['listing_type']['equal']) && isset($listing_type_id)) {
             $_REQUEST['listing_type']['equal'] = $listing_type_id;
         }
         $action = SJB_Request::getVar('action', 'list');
         switch ($action) {
             case 'save':
                 if ($isSubmittedForm) {
                     $search_name = SJB_Request::getVar('name');
                     $emailFrequency = SJB_Request::getVar('email_frequency');
                     if (empty($search_name['equal'])) {
                         $errors['EMPTY_VALUE'] = 1;
                         $tp->assign('action', 'save');
                     } else {
                         unset($_REQUEST['name']);
                         unset($_REQUEST['email_frequency']);
                         if ($emailFrequency) {
                             $emailFrequency = array_pop($emailFrequency);
                             $emailFrequency = '&email_frequency=' . array_pop($emailFrequency);
                         } else {
                             $emailFrequency = '';
                         }
                         $search_name = $search_name['equal'];
                         $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listing_type_id);
                         $tp = $searchResultsTP->getChargedTemplateProcessor();
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/save-search/?alert=true&url=' . $redirectUri . '&action=save&search_name=' . $search_name . '&searchId=' . $searchResultsTP->searchId . $emailFrequency);
                     }
                 } else {
                     $tp->assign('action', 'save');
                 }
                 break;
             case 'edit':
                 if (isset($_REQUEST['id_saved'])) {
                     if ($isSubmittedForm) {
                         $id_saved = $_REQUEST['id_saved'];
                         $name = $_REQUEST['name'];
                         $search_name = SJB_Request::getVar('name');
                         $emailFrequency = SJB_Request::getVar('email_frequency');
                         if (empty($search_name['equal'])) {
                             $errors['EMPTY_VALUE'] = 1;
                         } else {
                             unset($_REQUEST['name']);
                             unset($_REQUEST['email_frequency']);
                             if ($emailFrequency) {
                                 $emailFrequency = array_pop($emailFrequency);
                                 $emailFrequency = array_pop($emailFrequency);
                             } else {
                                 $emailFrequency = 'daily';
                             }
                             $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listing_type_id);
                             $tp = $searchResultsTP->getChargedTemplateProcessor();
                             $criteria_saver = new SJB_ListingCriteriaSaver($searchResultsTP->searchId);
                             $requested_data = $criteria_saver->getCriteria();
                             SJB_SavedSearches::updateSearchOnDB($requested_data, $id_saved, $current_user['sid'], $name['equal'], $emailFrequency);
                         }
                         if (!empty($errors)) {
                             $tp->assign('action', 'edit');
                             $tp->assign('id_saved', $_REQUEST['id_saved']);
                         } else {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . $redirectUri . '?alert=is_update');
                         }
                     } else {
                         $tp->assign('action', 'edit');
                         $tp->assign('id_saved', $_REQUEST['id_saved']);
                     }
                 }
                 break;
             case 'edit_alert':
                 $tp->assign('action', 'edit');
                 $tp->assign('id_saved', $_REQUEST['id_saved']);
                 break;
             case 'edit_search':
                 $tp->assign('action', 'edit');
                 $tp->assign('id_saved', $_REQUEST['id_saved']);
                 $_REQUEST['form_template'] = SJB_Request::getVar('formTemplateNem');
                 break;
             case 'new':
                 $tp->assign('action', 'save');
                 break;
             case 'delete':
                 if (isset($_REQUEST['search_id'])) {
                     $search_id = $_REQUEST['search_id'];
                     SJB_SavedSearches::deleteSearchFromDBBySID($search_id);
                 }
                 break;
             case 'disable_notify':
                 if (isset($_REQUEST['search_id'])) {
                     SJB_SavedSearches::disableSearchAutoNotify($current_user['sid'], $_REQUEST['search_id']);
                 }
                 break;
             case 'enable_notify':
                 if (isset($_REQUEST['search_id'])) {
                     SJB_SavedSearches::enableSearchAutoNotify($current_user['sid'], $_REQUEST['search_id']);
                 }
                 break;
         }
         if ($action != 'new' && $action != 'edit_alert') {
             $saved_searches = SJB_SavedSearches::getSavedSearchesFromDB($current_user['sid']);
             if (isset($_REQUEST['is_alert'])) {
                 $saved_searches = SJB_SavedSearches::getSavedJobAlertFromDB($current_user['sid']);
             }
             foreach ($saved_searches as $key => $saved_search) {
                 $saved_searches[$key]['data'] = SJB_SavedSearches::buildCriteriaFields($saved_search['data']);
                 if (isset($saved_search['data']['listing_type']['equal'])) {
                     $saved_searches[$key]['listing_type'] = $saved_search['data']['listing_type']['equal'];
                 }
             }
             $tp->assign('saved_searches', $saved_searches);
         }
         $listing = new SJB_Listing(array(), $listing_type_sid);
         $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $listing->addUsernameProperty();
         $listing->addKeywordsProperty();
         $listing->addPicturesProperty();
         $listing->addEmailFrequencyProperty();
         $listing->addListingTypeIDProperty();
         $listing->addPostedWithinProperty();
         $search_form_builder = new SJB_SearchFormBuilder($listing);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
         $search_form_builder->setCriteria($criteria);
         $search_form_builder->registerTags($tp);
         $form_fields = $search_form_builder->getFormFieldsInfo();
         $tp->assign('form_fields', $form_fields);
         if (!empty($_REQUEST['name'])) {
             $tp->assign('search_name', $_REQUEST['name']);
         }
         if (!empty($_REQUEST['email_frequency'])) {
             $tp->assign('email_frequency', $_REQUEST['email_frequency']);
         }
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $form_template = SJB_Request::getVar('form_template', 'search_form.tpl');
         switch (SJB_Request::getVar('alert')) {
             case 'added':
                 $tp->assign('alert_added', 'added');
                 break;
             case 'is_update':
                 $tp->assign('alert_update', 'update');
                 break;
         }
         if (!$listing_type_id && isset($saved_search['data']['listing_type']['equal'])) {
             $listing_type_id = $saved_search['data']['listing_type']['equal'];
         }
         $tp->assign('errors', $errors);
         $tp->assign('user_logged_in', true);
         $tp->assign('listing_type_id', $listing_type_id);
         $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listing_type_id);
         $formBuilder->setChargedTemplateProcessor($tp);
         $tp->display($form_template);
     } else {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
 }
Пример #7
0
 public function execute()
 {
     // xml-feeds table
     $feedsTable = 'listing_feeds';
     $feed_mimetype = 'text/xml';
     $feedId = SJB_Request::getVar('feedId', '');
     $searchSID = SJB_Request::getVar('searchSID', false);
     $feed = SJB_DB::query("SELECT * FROM {$feedsTable} WHERE `sid` = ?n", $feedId);
     $feed = array_pop($feed);
     if (empty($feed) && $searchSID === false) {
         $tp = SJB_System::getTemplateProcessor();
         $errors[] = 'RSS is not exists';
         $template = 'feed_error.tpl';
         $tp->assign('errors', $errors);
     } else {
         if ($searchSID) {
             $template = 'feed_saved_search.tpl';
             $count_listings = SJB_Request::getVar('count_listings', 10);
             if ($count_user_defined = SJB_Request::getVar('count_listings', false, 'GET')) {
                 $count_listings = $count_user_defined;
             }
             // get saved search results for feed
             $searches = SJB_SavedSearches::getSavedJobAlertFromDBBySearchSID($searchSID);
             $searches = array_pop($searches);
             $listing_type_id = null;
             foreach ($searches['data']['listing_type'] as $val) {
                 $listing_type_id = $val;
                 break;
             }
             $searches['data']['default_sorting_field'] = 'activation_date';
             $searches['data']['default_sorting_order'] = 'DESC';
             $searches['data']['default_listings_per_page'] = $count_listings;
             $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listing_type_id);
             $tp = $searchResultsTP->getChargedTemplateProcessor();
             // TODO: нужно абстрагировать получение переменной из шаблонизатора
             $tp->assign("listings", $tp->getVariable('listings')->value);
             $tp->assign('listing_type_id', $listing_type_id);
             $tp->assign("search_name", $searches['name']);
             $tp->assign("feed", $feed);
             $tp->assign("query_string", htmlspecialchars($_SERVER['QUERY_STRING']));
             $tp->assign("lastBuildDate", date('D, d M Y H:i:s'));
         } else {
             $template = $feed['template'];
             $count_listing = $feed['count'];
             $feed_type = $feed['type'];
             $feed_mimetype = $feed['mime_type'];
             if ($count_listing == 0) {
                 $count_listing = 1000000;
             }
             $listing_type = SJB_ListingTypeManager::getListingTypeIDBySID($feed_type);
             $searches['data']['listing_type']['equal'] = $listing_type;
             $searches['data']['default_sorting_field'] = 'activation_date';
             $searches['data']['default_sorting_order'] = 'DESC';
             $searches['data']['default_listings_per_page'] = $count_listing;
             $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listing_type);
             $tp = $searchResultsTP->getChargedTemplateProcessor();
             $tp->assign('feed', $feed);
             $tp->assign('count_listing', $count_listing);
             $tp->assign('lastBuildDate', date('D, d M Y H:i:s'));
         }
     }
     for ($i = 0; $i < ob_get_level(); $i++) {
         ob_end_clean();
     }
     header('Content-Type: ' . $feed_mimetype);
     $tp->display($template);
     exit;
 }
Пример #8
0
 /**
  * @param SJB_BrowseManager $browseManager
  * @param $listingTypeId
  * @return SJB_TemplateProcessor
  */
 protected function getTemplateProcessor($browseManager, $listingTypeId)
 {
     if ($browseManager->canBrowse()) {
         $browsing_meta_data = $browseManager->getBrowsingMetaData();
         $tp = SJB_System::getTemplateProcessor();
         $tp->assign('METADATA', $browsing_meta_data);
     } else {
         $requestData = $browseManager->getRequestDataForSearchResults();
         $requestData['default_listings_per_page'] = 10;
         $requestData['default_sorting_field'] = "activation_date";
         $requestData['default_sorting_order'] = "DESC";
         if (isset($_REQUEST['restore'])) {
             $requestData['restore'] = 1;
         } else {
             $requestData['action'] = 'search';
         }
         if (isset($_REQUEST['searchId'])) {
             $requestData['searchId'] = SJB_Request::getVar('searchId');
         }
         if (isset($_REQUEST['sorting_field'])) {
             $requestData['sorting_field'] = $_REQUEST['sorting_field'];
         }
         if (isset($_REQUEST['sorting_order'])) {
             $requestData['sorting_order'] = $_REQUEST['sorting_order'];
         }
         if (isset($_REQUEST['listings_per_page'])) {
             $requestData['listings_per_page'] = SJB_Request::getVar('listings_per_page', null);
         }
         $requestData['page'] = SJB_Request::getVar('page', null);
         // fix for mapView in search results
         $requestData['view'] = SJB_Request::getVar('view', null);
         $useRefine = false;
         if ($requestData['view'] == 'map') {
             $useRefine = true;
         }
         $searchResultsTP = new SJB_SearchResultsTP($requestData, $listingTypeId, false, $useRefine);
         $searchResultsTP->usePriority(true);
         $tp = $searchResultsTP->getChargedTemplateProcessor();
         SJB_Statistics::addSearchStatistics($searchResultsTP->getListingSidCollectionForCurrentPage(), $listingTypeId);
         $tp->assign('errors', $searchResultsTP->pluginErrors);
         $tp->assign('listing_type', $listingTypeId);
     }
     $tp->assign('columns', SJB_Request::getVar('columns', 1));
     return $tp;
 }
Пример #9
0
 public function execute()
 {
     $this->redirectToListingByKeywords();
     // SEO friendly URL for company profile
     $m = array();
     $isCompanyProfilePage = false;
     if (preg_match('#/company/([0-9]+)/.*#', SJB_Navigator::getURI(), $m)) {
         $isCompanyProfilePage = true;
         $params = SJB_FixedUrlParamProvider::getParams($_REQUEST);
         if (!empty($params)) {
             $aliasUsername = SJB_UserManager::getUserNameByUserSID($m[1]);
             if (!empty($aliasUsername)) {
                 $_REQUEST['username']['equal'] = $aliasUsername;
                 $_REQUEST['anonymous']['equal'] = 0;
             }
         }
     }
     if (!empty($_REQUEST['username']['equal']) && is_int($_REQUEST['username']['equal'])) {
         $aliasUsername = SJB_UserManager::getUserNameByUserSID(intval($_REQUEST['username']['equal']));
         if (!empty($aliasUsername)) {
             $_REQUEST['username']['equal'] = $aliasUsername;
         }
     }
     $listingTypeId = SJB_Request::getVar('listing_type_id', 0);
     if (!$listingTypeId) {
         $listingTypeId = isset($_REQUEST['listing_type']['equal']) ? $_REQUEST['listing_type']['equal'] : SJB_Session::getValue('listing_type_id');
     }
     if ($listingTypeId) {
         $_REQUEST['listing_type']['equal'] = $listingTypeId;
     }
     $action = SJB_Request::getVar('action', 'search');
     //XSS defense
     $searchId = SJB_Request::getVar('searchId', false);
     if ($searchId && !is_numeric($searchId)) {
         $_REQUEST['searchId'] = false;
     }
     $request = $_REQUEST;
     if (SJB_System::getSettingByName('turn_on_refine_search_' . $listingTypeId)) {
         switch ($action) {
             case 'refine':
                 $searchID = SJB_Request::getVar('searchId', false);
                 unset($request['searchId']);
                 $criteria_saver = new SJB_ListingCriteriaSaver($searchID);
                 $request = SJB_RefineSearch::mergeCriteria($criteria_saver->getCriteria(), $request);
                 break;
             case 'undo':
                 $param = SJB_Request::getVar('param', false);
                 $field_type = SJB_Request::getVar('type', false);
                 $value = SJB_Request::getVar('value', false);
                 if ($param && $field_type && $value) {
                     $searchID = SJB_Request::getVar('searchId', false);
                     unset($request['searchId']);
                     $criteria_saver = new SJB_ListingCriteriaSaver($searchID);
                     $criteria = $criteria_saver->criteria;
                     if (isset($criteria[$param][$field_type])) {
                         switch ($field_type) {
                             case 'geo':
                                 if ($criteria[$param][$field_type]['location'] == $value) {
                                     unset($criteria[$param]);
                                 }
                                 break;
                             case 'monetary':
                                 if ($criteria[$param][$field_type]['not_less'] == $value) {
                                     $criteria[$param][$field_type]['not_less'] = "";
                                 }
                                 if ($criteria[$param][$field_type]['not_more'] == $value) {
                                     $criteria[$param][$field_type]['not_more'] = "";
                                 }
                                 break;
                             case 'tree':
                                 // search params incoming as string, where params separated by ','
                                 // we need to undo one of them
                                 $params = explode(',', $criteria[$param][$field_type]);
                                 $params = array_flip($params);
                                 unset($params[$value]);
                                 $params = array_flip($params);
                                 $criteria[$param][$field_type] = implode(',', $params);
                                 break;
                             default:
                                 if (is_array($criteria[$param][$field_type])) {
                                     foreach ($criteria[$param][$field_type] as $key => $val) {
                                         if ($val == $value) {
                                             unset($criteria[$param][$field_type][$key]);
                                         }
                                     }
                                 } else {
                                     unset($criteria[$param]);
                                 }
                                 break;
                         }
                     }
                     $criteria['default_sorting_field'] = $request['default_sorting_field'];
                     $criteria['default_sorting_order'] = $request['default_sorting_order'];
                     $criteria['default_listings_per_page'] = $request['default_listings_per_page'];
                     $criteria['results_template'] = $request['results_template'];
                     $request = array_merge($criteria, $request);
                 }
                 break;
         }
     }
     $searchResultsTP = new SJB_SearchResultsTP($request, $listingTypeId, false, true);
     $searchResultsTP->usePriority(true);
     $template = SJB_Request::getVar("results_template", "search_results.tpl");
     $allowViewContactInfo = false;
     if (!empty($_REQUEST['username']['equal'])) {
         $pageID = 'contact_info';
         $username = $_REQUEST['username']['equal'];
         if (SJB_UserManager::isUserLoggedIn()) {
             $current_user = SJB_UserManager::getCurrentUser();
             if (SJB_ContractManager::isPageViewed($current_user->getSID(), $pageID, $username) || $this->acl->isAllowed('view_' . $listingTypeId . '_contact_info') && in_array($this->acl->getPermissionParams('view_' . $listingTypeId . '_contact_info'), array('', '0'))) {
                 $allowViewContactInfo = true;
             } elseif ($this->acl->isAllowed('view_' . $listingTypeId . '_contact_info')) {
                 $viewContactInfo['count_views'] = 0;
                 $contractIDs = $current_user->getContractID();
                 $numberOfContactViewed = SJB_ContractManager::getNumbeOfPagesViewed($current_user->getSID(), $contractIDs, $pageID);
                 foreach ($contractIDs as $contractID) {
                     if ($this->acl->getPermissionParams('view_' . $listingTypeId . '_contact_info', $contractID, 'contract')) {
                         $params = $this->acl->getPermissionParams('view_' . $listingTypeId . '_contact_info', $contractID, 'contract');
                         if (isset($viewContactInfo['count_views'])) {
                             $viewContactInfo['count_views'] += $params;
                             $viewContactInfo['contract_id'] = $contractID;
                         }
                     }
                 }
                 if ($viewContactInfo && $viewContactInfo['count_views'] > $numberOfContactViewed) {
                     $allowViewContactInfo = true;
                     SJB_ContractManager::addViewPage($current_user->getSID(), $pageID, $username, $viewContactInfo['contract_id']);
                 }
             }
         } elseif ($this->acl->isAllowed('view_' . $listingTypeId . '_contact_info')) {
             $allowViewContactInfo = true;
         }
     }
     $tp = $searchResultsTP->getChargedTemplateProcessor();
     SJB_Statistics::addSearchStatistics($searchResultsTP->getListingSidCollectionForCurrentPage(), $listingTypeId);
     $userForm = null;
     if ($isCompanyProfilePage) {
         $user = SJB_UserManager::getObjectBySID(intval($m[1]));
         $userForm = new SJB_Form($user);
         $userForm->registerTags($tp);
     }
     $errors = array();
     if (!empty($searchResultsTP->pluginErrors)) {
         foreach ($searchResultsTP->pluginErrors as $err) {
             $errors[] = $err;
         }
     }
     $tp->assign('errors', $errors);
     $tp->assign('is_company_profile_page', $isCompanyProfilePage);
     $tp->assign("listing_type_id", $listingTypeId);
     $tp->assign('allowViewContactInfo', $allowViewContactInfo);
     if ($userForm) {
         $tp->assign('form_fields', $userForm->getFormFieldsInfo());
     }
     $tp->display($template);
 }