예제 #1
0
파일: ajax.php 프로젝트: Maxlander/shixi
 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');
 }
예제 #2
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action');
     $field_id = SJB_Request::getVar('field_id', false);
     if ($field_id || $action == 'save_setting') {
         switch ($action) {
             case 'save':
                 $listing_type_sid = SJB_Request::getVar('listing_type_sid', false);
                 $userField = 0;
                 if ($listing_type_sid) {
                     if (strstr($field_id, 'user_')) {
                         $field_id = str_replace('user_', '', $field_id);
                         $userField = 1;
                     }
                     if (!SJB_RefineSearch::getFieldByFieldSIDListingTypeSID($field_id, $listing_type_sid, $userField)) {
                         SJB_RefineSearch::addField($field_id, $listing_type_sid, $userField);
                     }
                 }
                 break;
             case 'save_setting':
                 $listing_type_id = SJB_Request::getVar('listing_type_id', false);
                 $refine_search_items_limit = SJB_Request::getVar('refine_search_items_limit', false);
                 if ($listing_type_id) {
                     $settingValue = SJB_Request::getVar('turn_on_refine_search_' . $listing_type_id, 0);
                     if (SJB_Settings::getSettingByName('turn_on_refine_search_' . $listing_type_id) === false) {
                         SJB_Settings::addSetting('turn_on_refine_search_' . $listing_type_id, $settingValue);
                     } else {
                         SJB_Settings::updateSetting('turn_on_refine_search_' . $listing_type_id, $settingValue);
                     }
                 } elseif ($refine_search_items_limit) {
                     if (SJB_Settings::getSettingByName('refine_search_items_limit') === false) {
                         SJB_Settings::addSetting('refine_search_items_limit', $refine_search_items_limit);
                     } else {
                         SJB_Settings::updateSetting('refine_search_items_limit', $refine_search_items_limit);
                     }
                 }
                 break;
             case 'delete':
                 SJB_RefineSearch::removeField($field_id);
                 break;
             case 'move_up':
                 $listing_type_sid = SJB_Request::getVar('listing_type_sid', false);
                 if ($listing_type_sid) {
                     SJB_RefineSearch::moveUpFieldBySID($field_id, $listing_type_sid);
                 }
                 break;
             case 'move_down':
                 $listing_type_sid = SJB_Request::getVar('listing_type_sid', false);
                 if ($listing_type_sid) {
                     SJB_RefineSearch::moveDownFieldBySID($field_id, $listing_type_sid);
                 }
                 break;
         }
     }
     $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo();
     foreach ($listingTypes as $key => $listingType) {
         $fields = array_merge(SJB_ListingFieldManager::getCommonListingFieldsInfo(), SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingType['sid']));
         foreach ($fields as $field_key => $field) {
             if ($field['type'] == 'location') {
                 if (is_array($field['fields'])) {
                     $fields = array_merge($fields, $field['fields']);
                 }
             }
             if (!in_array($field['type'], array('list', 'multilist', 'string', 'boolean', 'tree')) || in_array($field['id'], array('ApplicationSettings', 'access_type', 'anonymous', 'screening_questionnaire'))) {
                 foreach ($fields as $fieldKey => $searchField) {
                     if ($searchField['id'] == $field['id']) {
                         unset($fields[$fieldKey]);
                     }
                 }
             }
         }
         $listingTypes[$key]['fields'] = $fields;
         if ($key == 'Job') {
             $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'");
             if (!empty($userFieldSID)) {
                 $listingTypes[$key]['user_fields'] = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID);
             }
         }
         $listingTypes[$key]['saved_fields'] = SJB_RefineSearch::getFieldsByListingTypeSID($listingType['sid']);
         $listingTypes[$key]['setting'] = SJB_Settings::getSettingByName('turn_on_refine_search_' . $listingType['id']);
     }
     $tp->assign('refine_search_items_limit', SJB_Settings::getSettingByName('refine_search_items_limit'));
     $tp->assign('listingTypes', $listingTypes);
     $tp->display('refine_search.tpl');
 }
예제 #3
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);
 }
예제 #4
0
 public static function getFieldValues($refineField, $criteria, SJB_SearchResultsTP $searchResultsTP, $fieldName)
 {
     $isMultiSelectFieldType = in_array($refineField['type'], array('multilist', 'tree'));
     $foundListingsByFieldName = array();
     if ($isMultiSelectFieldType && !empty($criteria)) {
         $foundListingsByFieldName = $searchResultsTP->criteria_saver->getSessionForRefine($refineField['field_name']);
     }
     if (empty($foundListingsByFieldName)) {
         $foundListingsByFieldName = SJB_RefineSearch::countListingsByFieldName($fieldName, $refineField['field_id'], $searchResultsTP, $refineField['user_field']);
     }
     if ($isMultiSelectFieldType && empty($criteria)) {
         $searchResultsTP->criteria_saver->setSessionForRefine($refineField['field_name'], $foundListingsByFieldName);
     }
     return $foundListingsByFieldName;
 }