Пример #1
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $userGroupID = SJB_Request::getVar('user_group_id', 0);
     $user = SJB_UsersExportController::createUser($userGroupID);
     $searchFormBuilder = new SJB_SearchFormBuilder($user);
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $user);
     $searchFormBuilder->registerTags($tp);
     $searchFormBuilder->setCriteria($criteria);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $exportProperties = SJB_Request::getVar('export_properties', array());
         if (empty($exportProperties)) {
             SJB_FlashMessages::getInstance()->addWarning('EMPTY_EXPORT_PROPERTIES');
         } else {
             $innerJoin = false;
             if (isset($_REQUEST['product']['multi_like']) && $_REQUEST['product']['multi_like'] != '') {
                 $products = $_REQUEST['product']['multi_like'];
                 if (is_array($products)) {
                     $products = implode(',', $products);
                 }
                 $whereParam = implode(',', explode(',', SJB_DB::quote($products)));
                 $innerJoin = array('contracts' => array('join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'INNER JOIN', 'where' => "AND FIND_IN_SET(`contracts`.`product_sid`, '{$whereParam}')"));
                 unset($criteria['system']['product']);
             }
             $searcher = new SJB_UserSearcher(false, 'parent_sid', 'ASC', $innerJoin);
             $searchAliases = SJB_UsersExportController::getSearchPropertyAliases();
             $foundUsersSid = $searcher->getObjectsSIDsByCriteria($criteria, $searchAliases);
             if (!empty($foundUsersSid)) {
                 $result = SJB_UsersExportController::createExportDirectories();
                 if ($result === true) {
                     $exportProperties['extUserID'] = 1;
                     $exportProperties['parent_sid'] = 1;
                     $exportAliases = SJB_UsersExportController::getExportPropertyAliases();
                     $exportData = SJB_UsersExportController::getExportData($foundUsersSid, $exportProperties, $exportAliases);
                     $fileName = 'users.xls';
                     SJB_UsersExportController::makeExportFile($exportData, $fileName);
                     if (!file_exists(SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY') . "/{$fileName}")) {
                         SJB_FlashMessages::getInstance()->addWarning('CANT_CREATE_EXPORT_FILES');
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/users/archive-and-send-export-data/");
                     }
                 }
             } else {
                 SJB_FlashMessages::getInstance()->addWarning('EMPTY_EXPORT_DATA');
             }
         }
     }
     $userSystemProperties = SJB_UserManager::getAllUserSystemProperties();
     $userGroups = SJB_UserGroupManager::getAllUserGroupsInfo();
     $userCommonProperties = array();
     foreach ($userGroups as $userGroup) {
         $userGroupProperties = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($userGroup['sid']);
         $userCommonProperties[$userGroup['id']] = $userGroupProperties;
     }
     $tp->assign('userSystemProperties', $userSystemProperties);
     $tp->assign('userCommonProperties', $userCommonProperties);
     $tp->assign('selected_user_group_id', $userGroupID);
     $tp->display('export_users.tpl');
 }
Пример #2
0
 public function execute()
 {
     $guestAlert = new SJB_GuestAlert(array());
     $guestAlert->addSubscriptionDateProperty();
     $guestAlert->addStatusProperty();
     $search_form_builder = new SJB_SearchFormBuilder($guestAlert);
     $criteria_saver = new SJB_GuestAlertCriteriaSaver();
     $criteria = $search_form_builder->extractCriteriaFromRequestData($criteria_saver->getCriteria(), $guestAlert);
     $sortingField = SJB_Request::getVar('sorting_field', 'subscription_date');
     $sortingOrder = SJB_Request::getVar('sorting_order', 'DESC');
     $searcher = new SJB_GuestAlertSearcher(false, $sortingField, $sortingOrder);
     $foundGuestAlerts = $searcher->getObjectsSIDsByCriteria($criteria);
     foreach ($foundGuestAlerts as $id => $guestAlertSID) {
         $foundGuestAlerts[$id] = SJB_GuestAlertManager::getGuestAlertInfoBySID($guestAlertSID);
     }
     $type = SJB_Request::getVar('type', 'csv');
     $fileName = 'guest_alerts_' . date('Y-m-d');
     SJB_StatisticsExportController::createExportDirectory();
     switch ($type) {
         case 'csv':
             $ext = 'csv';
             SJB_StatisticsExportController::makeCSVExportFile($foundGuestAlerts, $fileName . '.' . $ext, 'Guest Alerts');
             break;
         default:
         case 'xls':
             $ext = 'xls';
             SJB_StatisticsExportController::makeXLSExportFile($foundGuestAlerts, $fileName . '.' . $ext, 'Guest Alerts');
             break;
     }
     SJB_StatisticsExportController::archiveAndSendExportFile($fileName, $ext);
 }
Пример #3
0
 public function showSearchForm()
 {
     $guestAlert = new SJB_GuestAlert(array());
     $guestAlert->addSubscriptionDateProperty();
     $guestAlert->addStatusProperty();
     $searchFormBuilder = new SJB_SearchFormBuilder($guestAlert);
     $this->criteriaSaver = new SJB_GuestAlertCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $this->criteriaSaver->getCriteria());
     }
     $this->criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $guestAlert);
     $searchFormBuilder->setCriteria($this->criteria);
     $searchFormBuilder->registerTags($this->tp);
     $this->tp->display('search_form.tpl');
 }
Пример #4
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $listingTypeId = SJB_Request::getVar('listing_type_id', 0);
     if (!$listingTypeId) {
         $listingTypeId = SJB_Request::getVar('listing_type', 0);
         if ($listingTypeId) {
             $listingTypeId = $listingTypeId['equal'];
         }
     }
     $exportProperties = SJB_Request::getVar('export_properties', array());
     $listing = SJB_ExportController::createListing($listingTypeId);
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST, $listing);
     $searchFormBuilder = new SJB_SearchFormBuilder($listing);
     $searchFormBuilder->registerTags($tp);
     $searchFormBuilder->setCriteria($criteria);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (empty($exportProperties)) {
             SJB_FlashMessages::getInstance()->addWarning('EMPTY_EXPORT_PROPERTIES');
         } else {
             $searcher = new SJB_ListingSearcher();
             $searchAliases = SJB_ExportController::getSearchPropertyAliases();
             $foundListingsSid = $searcher->getObjectsSIDsByCriteria($criteria, $searchAliases);
             if (empty($foundListingsSid)) {
                 SJB_FlashMessages::getInstance()->addWarning('EMPTY_EXPORT_DATA');
             } else {
                 $result = SJB_ExportController::createExportDirectories();
                 if ($result === true) {
                     $exportProperties['extUserID'] = 1;
                     $exportAliases = SJB_ExportController::getExportPropertyAliases();
                     $exportData = SJB_ExportController::getExportData($foundListingsSid, $exportProperties, $exportAliases);
                     $fileName = 'export.xls';
                     SJB_ExportController::makeExportFile($exportData, $fileName);
                     if (!file_exists(SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY') . "/{$fileName}")) {
                         SJB_FlashMessages::getInstance()->addWarning('CANT_CREATE_EXPORT_FILES');
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/archive-and-send-export-data');
                     }
                 }
             }
         }
     }
     $listingPropertiesId = SJB_ListingManager::getAllListingPropertiesID($listingTypeId);
     $tp->assign('properties_id', $listingPropertiesId);
     $tp->assign('selected_listing_type_id', $listingTypeId);
     $tp->display('export_listings.tpl');
 }
Пример #5
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
     $countListings = array();
     foreach ($listing_types as $type) {
         $requested_data = array();
         $requested_data['action'] = 'search';
         $requested_data['active']['equal'] = '1';
         $requested_data['listing_type']['equal'] = $type['id'];
         $requireApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($type['sid']);
         if ($requireApprove) {
             $requested_data['status']['equal'] = 'approved';
         }
         $listing = new SJB_Listing(array(), $type['sid']);
         $id_alias_info = $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $username_alias_info = $listing->addUsernameProperty();
         $listing_type_id_info = $listing->addListingTypeIDProperty();
         $listing->addCompanyNameProperty();
         if ($type['id'] == 'Resume') {
             $requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
         }
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($requested_data, $listing);
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($id_alias_info);
         $aliases->addAlias($username_alias_info);
         $aliases->addAlias($listing_type_id_info);
         $searcher = new SJB_ListingSearcher();
         $countListings[$type['id']] = $searcher->countRowsByCriteria($criteria, $aliases);
     }
     $tp->assign('listings_types', $countListings);
     $tp->display('count_listings.tpl');
 }
Пример #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $listingTypeSID = 0;
     $listingTypeID = 0;
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $params = SJB_FixedUrlParamProvider::getParams($_REQUEST);
         if ($params) {
             $listingTypeID = array_pop($params);
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
         }
     }
     if (!$listingTypeSID) {
         $errors['WRONG_LISTING_TYPE_ID_SPECIFIED'] = true;
     }
     $listing = new SJB_Listing(array(), $listingTypeSID);
     $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addUsernameProperty();
     $listing->addKeywordsProperty();
     $listing->addPicturesProperty();
     $listing->addListingTypeIDProperty();
     $listing->addPostedWithinProperty();
     $search_form_builder = new SJB_SearchFormBuilder($listing);
     $search_form_builder->registerTags($tp);
     $form_fields = $search_form_builder->getFormFieldsInfo();
     $tp->assign('form_fields', $form_fields);
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
     $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listingTypeID);
     $formBuilder->setChargedTemplateProcessor($tp);
     $tp->assign('listingTypeInfo', SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID));
     $tp->assign('builderMode', true);
     $tp->assign('currentTheme', SJB_TemplateSupplier::getUserCurrentTheme());
     SJB_System::getTemplateProcessor();
     $tp->display('bf_searchform.tpl');
 }
Пример #7
0
 protected function _get_Captions_with_Counts_Grouped_by_Captions($request_data, array $listingSids = array())
 {
     $items = array();
     if (!empty($request_data[$this->field['field']]['tree'])) {
         $this->parent = $items = explode(',', $request_data[$this->field['field']]['tree']);
         $treeValues = $this->tree_values;
         $this->tree_values = array();
     }
     if (SJB_Settings::getValue('enableBrowseByCounter')) {
         $request_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($request_data);
         $sqlTranslator = new SJB_SearchSqlTranslator('listings');
         $whereStatement = $sqlTranslator->_getWhereStatement($criteria);
         $sql = "`{$this->field['field']}` != ''";
         if (count($items) > 1) {
             $sql = " AND (";
             foreach ($items as $key => $item) {
                 if ($key == 0) {
                     $sql .= " FIND_IN_SET('{$item}',`{$this->field['field']}`) ";
                 } else {
                     $sql .= " OR FIND_IN_SET('{$item}',`{$this->field['field']}`) ";
                 }
                 if (isset($treeValues[$item])) {
                     $this->tree_values[$item] = $treeValues[$item];
                 }
             }
             $sql .= ")";
         }
         if (!empty($listingSids)) {
             $sql .= ' AND `listings`.`sid` IN (' . implode(',', $listingSids) . ')';
         }
         $sql = "SELECT `?w` AS caption, `sid` AS object_sid FROM `listings` {$whereStatement} AND {$sql}";
         $result = SJB_DB::query($sql, $this->field['field']);
         $result = self::_getCountsByItems($result);
     } else {
         if (count($items) > 1) {
             foreach ($items as $item) {
                 $this->tree_values[$item] = $treeValues[$item];
             }
         }
         $result = self::getTreeItems($this->tree_values, SJB_ListingFieldTreeManager::getTreeDepthBySID($this->field['sid']));
     }
     return $result;
 }
Пример #8
0
 protected function _get_Captions_with_Counts_Grouped_by_Captions($request_data, array $listingSids = array())
 {
     $columns = '?w as caption';
     if (SJB_Settings::getValue('enableBrowseByCounter')) {
         $columns .= ', count(*) as count';
     }
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($request_data);
     $sqlTranslator = new SJB_SearchSqlTranslator('listings');
     $whereStatement = $sqlTranslator->_getWhereStatement($criteria);
     if (!empty($listingSids)) {
         $whereStatement .= 'AND `listings`.`sid` IN (' . implode(',', $listingSids) . ')';
     }
     $res = SJB_DB::query("select {$columns} from listings {$whereStatement} and ?w != '' group by ?w", $this->field['field'], $this->field['field'], $this->field['field']);
     $result = array();
     foreach ($res as $value) {
         if (SJB_Settings::getValue('enableBrowseByCounter')) {
             $result[$value['caption']] = $value['count'];
         } else {
             $result[$value['caption']] = '';
         }
     }
     return $result;
 }
Пример #9
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $restore = SJB_Request::getVar('restore', false);
     $action = SJB_Request::getVar('action_name', 'view_log');
     $action = $action == 'search' ? 'view_log' : $action;
     $paginator = new SJB_EmailLogPagination();
     $display_error = SJB_Request::getVar('display_error', false);
     $savedErrors = SJB_Session::getValue(self::EMAIL_ERRORS);
     SJB_Session::unsetValue(self::EMAIL_ERRORS);
     $this->errors = $savedErrors ? $savedErrors : array();
     $message = SJB_Session::getValue(self::EMAIL_LOG_MESSAGE);
     SJB_Session::unsetValue(self::EMAIL_LOG_MESSAGE);
     switch ($action) {
         case 'display_message':
             $sid = SJB_Request::getVar('sid', false);
             $email = SJB_EmailLogManager::getEmailInfoBySID($sid);
             $tp->assign('display_error', $display_error);
             $tp->assign('email', $email);
             $tp->display('display_log_message.tpl');
             return true;
             break;
         case 'resend':
             try {
                 SJB_Settings::saveSetting(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION, SJB_Request::getVar(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION));
                 $this->resendEmails();
                 SJB_Session::setValue(self::EMAIL_LOG_MESSAGE, 'The message(s) were successfully resent.');
             } catch (Exception $e) {
                 array_push($this->errors, $e->getMessage());
             }
             SJB_Session::setValue(self::EMAIL_ERRORS, $this->errors);
             $searchFields = SJB_Request::getVar('searchFields');
             SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/email-log/?sorting_field=' . $paginator->sortingField . '&sorting_order=' . $paginator->sortingOrder . '&items_per_page=' . $paginator->itemsPerPage . $searchFields);
             break;
         case 'view_log':
             $userSID = SJB_Request::getVar('user_sid', false);
             if ($userSID) {
                 $template = 'user_email_log.tpl';
                 $_REQUEST['username']['equal'] = $userSID;
                 $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
                 $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
                 $tp->assign('userGroupInfo', $userGroupInfo);
                 $tp->assign('display_error', $display_error);
                 $tp->assign('user_info', $userInfo);
                 $tp->assign('user_sid', $userSID);
             }
             $email = new SJB_EmailLog($_REQUEST);
             $search_form_builder = new SJB_SearchFormBuilder($email);
             $criteria_saver = new SJB_EmailLogCriteriaSaver();
             if ($restore) {
                 $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
             }
             $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $email);
             if (!$userSID) {
                 $template = 'email_log.tpl';
                 $search_form_builder->setCriteria($criteria);
                 $search_form_builder->registerTags($tp);
                 $tp->display("email_log_search_form.tpl");
             }
             $order_info = array('sorting_field' => $paginator->sortingField, 'sorting_order' => $paginator->sortingOrder);
             $criteria_saver->setSessionForOrderInfo($order_info);
             $criteria_saver->setSessionForCurrentPage($paginator->currentPage);
             $criteria_saver->setSessionForListingsPerPage($paginator->itemsPerPage);
             $searcher = new SJB_EmailLogSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder);
             $found_emails = $searcher->getObjectsSIDsByCriteria($criteria);
             $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
             foreach ($found_emails as $id => $emailSID) {
                 $emailInfo = SJB_EmailLogManager::getEmailInfoBySID($emailSID);
                 $found_emails[$id] = $emailInfo;
                 $found_emails[$id]['user'] = !empty($emailInfo['username']) ? SJB_UserManager::getUserInfoBySID($emailInfo['username']) : array();
                 $found_emails[$id]['admin'] = array();
                 if (!empty($emailInfo['admin'])) {
                     if (is_numeric($emailInfo['admin'])) {
                         $found_emails[$id]['admin'] = SJB_SubAdminManager::getSubAdminInfoBySID($emailInfo['admin']);
                     } else {
                         $found_emails[$id]['admin']['username'] = '******';
                     }
                 }
             }
             $paginator->setItemsCount($searcher->getAffectedRows());
             $searchFields = '';
             foreach ($_REQUEST as $key => $val) {
                 if (is_array($val)) {
                     foreach ($val as $fieldName => $fieldValue) {
                         $searchFields .= "&{$key}[{$fieldName}]={$fieldValue}";
                     }
                 }
             }
             $tp->assign(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION, SJB_Settings::getSettingByName(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION));
             $tp->assign('message', $message);
             $tp->assign('errors', $this->errors);
             $tp->assign("searchFields", $searchFields);
             $tp->assign('paginationInfo', $paginator->getPaginationInfo());
             $tp->assign("found_emails", $found_emails);
             $tp->display($template);
             break;
     }
 }
Пример #10
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('display_template');
     $page = 1;
     $searchId = strip_tags(SJB_Request::getVar('searchId', time()));
     if (!empty($_REQUEST["page"])) {
         $page = intval($_REQUEST["page"]);
     }
     $items_per_page = SJB_Request::getVar('companies_per_page', false);
     $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($_REQUEST["listing_type_id"]);
     $alphabets = SJB_AlphabetManager::getAlphabetsForDisplay();
     $abArr = array();
     foreach ($alphabets as $alphabet) {
         $abArr[] = explode(' ', $alphabet['value']);
     }
     $action = SJB_Request::getVar('action', 'search_form');
     if (SJB_Request::getVar('first_char')) {
         $action = 'search';
         $_REQUEST['CompanyName']['first_char_like'] = SJB_Request::getVar('first_char');
     } elseif (!isset($_REQUEST['CompanyName']) || $_REQUEST['CompanyName']['like'] == '') {
         $_REQUEST['CompanyName']['not_empty'] = true;
     }
     $userGroupSid = SJB_UserGroupManager::getUserGroupSIDByID('Employer');
     $userGroupFields = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($userGroupSid);
     foreach ($userGroupFields as $key => $userGroupField) {
         if ($userGroupField['type'] == 'location') {
             $userGroupFields[$key]['fields'] = array();
             $userGroupFields[$key]['fields'][$userGroupField['sid']] = $userGroupField;
         }
     }
     $user = new SJB_User(array(), $userGroupSid);
     $_REQUEST['active']['equal'] = 1;
     $search_form_builder = new SJB_SearchFormBuilder($user);
     $criteria_saver = new SJB_UserCriteriaSaver($searchId);
     $criteria_saver->setSessionForOrderInfo($_REQUEST);
     if (isset($_REQUEST['searchId'])) {
         $action = 'search';
         $criteria = $criteria_saver->getCriteria();
         if (!empty($_REQUEST['sorting_field'])) {
             unset($criteria['sorting_field']);
         } else {
             $orderInfo = $criteria_saver->getOrderInfo();
             if (!empty($orderInfo['sorting_order'])) {
                 $criteria['sorting_order'] = $orderInfo['sorting_order'];
             }
         }
         $_REQUEST = array_merge($_REQUEST, $criteria);
         if (!$items_per_page) {
             $items_per_page = $criteria_saver->listings_per_page;
         }
     }
     $items_per_page = $items_per_page ? $items_per_page : 10;
     $criteria = $search_form_builder->extractCriteriaFromRequestData(array_merge($_REQUEST, array('username' => array('not_equal' => 'jobg8'))), $user);
     if ($items_per_page) {
         $criteria_saver->setSessionForListingsPerPage($items_per_page);
     }
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $form_fields = $search_form_builder->getFormFieldsInfo();
     $tp->assign('form_fields', $form_fields);
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
     $tp->assign('userGroupFields', $userGroupFields);
     $tp->assign('action', $action);
     $tp->assign('alphabets', $abArr);
     if ($action == 'search') {
         $sorting_field = SJB_Request::getVar('sorting_field', false);
         $sorting_order = SJB_Request::getVar('sorting_order', false);
         if (isset($_REQUEST['searchId']) && !$sorting_field) {
             $order_info = $criteria_saver->order_info;
             if ($order_info) {
                 $sorting_field = $order_info['sorting_field'];
                 $sorting_order = $order_info['sorting_order'];
             }
         }
         if (!$sorting_field) {
             $sorting_field = 'CompanyName';
             $sorting_order = 'ASC';
         }
         $inner_join = array();
         if ($sorting_field == 'number_of_jobs') {
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid) == 1) {
                 $count = "sum( if( `listings`.`status` = 'approved', `listings`.`active`, 0 ) )";
             } else {
                 $count = "sum(`listings`.`active`)";
             }
             $inner_join = array('listings' => array('sort_field' => $count, 'noPresix' => true, 'join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'LEFT JOIN', 'groupBy' => '`users`.`sid`'));
         } elseif ($sorting_field == 'Location_State') {
             $inner_join = array('states' => array('sort_field' => 'state_name', 'noPresix' => true, 'join_field' => 'sid', 'join_field2' => 'Location_State', 'join' => 'LEFT JOIN'));
         }
         $searcher = new SJB_UserSearcher(false, $sorting_field, $sorting_order, $inner_join, array('limit' => ($page - 1) * $items_per_page, 'num_rows' => $items_per_page));
         $found_users = array();
         $found_users_sids = array();
         $found_users_by_criteria = $searcher->getObjectsByCriteria($criteria, null, array(), true);
         $foundObjectSIDs = $searcher->getFoundObjectSIDs();
         // display search form
         $tp->display($template);
         $criteria_saver->setSession($_REQUEST, $foundObjectSIDs);
         if (count($foundObjectSIDs) > 0) {
             $listingType = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_type_sid);
             $countListings = SJB_ListingDBManager::getActiveAndApproveJobsNumberForUsers($foundObjectSIDs, $listingType);
         }
         foreach ($found_users_by_criteria as $id => $user) {
             $listingsNumber = isset($countListings[$id]) ? $countListings[$id] : 0;
             $user->addProperty(array('id' => 'countListings', 'type' => 'string', 'value' => $listingsNumber));
             if ($user->getProperty('CompanyName')) {
                 $found_users_sids[$user->getSID()] = $user->getSID();
                 $found_users[$id] = $user;
             }
         }
         $usersCount = $searcher->getAffectedRows();
         $form_collection = new SJB_FormCollection($found_users);
         $form_collection->registerTags($tp);
         $pages = array();
         for ($i = $page - 3; $i < $page + 3; $i++) {
             if ($i > 0) {
                 $pages[] = $i;
             }
             if ($i * $items_per_page > $usersCount) {
                 break;
             }
         }
         $totalPages = ceil($usersCount / $items_per_page);
         if (empty($totalPages)) {
             $totalPages = 1;
         }
         if (array_search(1, $pages) === false) {
             array_unshift($pages, 1);
         }
         if (array_search($totalPages, $pages) === false) {
             array_push($pages, $totalPages);
         }
         $tp->assign("sorting_order", $sorting_order);
         $tp->assign("sorting_field", $sorting_field);
         $tp->assign("found_users_sids", $found_users_sids);
         $tp->assign("companies_per_page", $items_per_page);
         $tp->assign("searchId", $searchId);
         $tp->assign("usersCount", $usersCount);
         $tp->assign("current_page", $page);
         $tp->assign("pages_number", $totalPages);
         $tp->display('search_result_company.tpl');
     } else {
         // display search form
         $tp->display($template);
     }
 }
Пример #11
0
 public function execute()
 {
     if (!function_exists('_filter_data')) {
         function _filter_data(&$array, $key, $pattern)
         {
             if (isset($array[$key])) {
                 if (!preg_match($pattern, $array[$key])) {
                     unset($array[$key]);
                 }
             }
         }
     }
     _filter_data($_REQUEST, 'sorting_field', "/^[_\\w\\d]+\$/");
     _filter_data($_REQUEST, 'sorting_order', "/(^DESC\$)|(^ASC\$)/i");
     _filter_data($_REQUEST, 'default_sorting_field', "/^[_\\w\\d]+\$/");
     _filter_data($_REQUEST, 'default_sorting_order', "/(^DESC\$)|(^ASC\$)/i");
     $tp = SJB_System::getTemplateProcessor();
     if (!SJB_UserManager::isUserLoggedIn()) {
         $errors['NOT_LOGGED_IN'] = true;
         $tp->assign("ERRORS", $errors);
         $tp->display("error.tpl");
         return;
     }
     $this->defineRequestedListingTypeID();
     if (!$this->listingTypeID) {
         $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo());
         $tp->display('my_available_listing_types.tpl');
         return;
     }
     $this->listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID);
     if (!$this->listingTypeSID) {
         SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/my-listings/');
         return;
     }
     $currentUser = SJB_UserManager::getCurrentUser();
     $userSID = $currentUser->getSID();
     $this->requestCriteria = array('user_sid' => array('equal' => $userSID), 'listing_type_sid' => array('equal' => $this->listingTypeSID));
     $acl = SJB_Acl::getInstance();
     if ($currentUser->isSubuser()) {
         $subUserInfo = $currentUser->getSubuserInfo();
         if (!$acl->isAllowed('subuser_manage_listings', $subUserInfo['sid'])) {
             $this->requestCriteria['subuser_sid'] = array('equal' => $subUserInfo['sid']);
         }
     }
     SJB_ListingManager::deletePreviewListingsByUserSID($userSID);
     $searcher = new SJB_ListingSearcher();
     // to save criteria in the session different from search_results
     $criteriaSaver = new SJB_ListingCriteriaSaver('MyListings');
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria());
     }
     if (isset($_REQUEST['listings'])) {
         $listingsSIDs = $_REQUEST['listings'];
         if (isset($_REQUEST['action_deactivate'])) {
             $this->executeAction($listingsSIDs, 'deactivate');
         } elseif (isset($_REQUEST['action_activate'])) {
             $redirectToShoppingCard = false;
             $activatedListings = array();
             foreach ($listingsSIDs as $listingSID => $value) {
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSID);
                 $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
                 if ($listingInfo['active']) {
                     continue;
                 } else {
                     if (SJB_ListingManager::getIfListingHasExpiredBySID($listingSID) && isset($productInfo['renewal_price']) && $productInfo['renewal_price'] > 0) {
                         $redirectToShoppingCard = true;
                         $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
                         $newProductName = "Reactivation of \"{$listingInfo['Title']}\" {$listingTypeId}";
                         $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSID, $productInfo['product_sid'], $listingSID, $productInfo['renewal_price'], $newProductName, 'activateListing');
                         SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSID);
                     } else {
                         if ($listingInfo['checkouted'] == 0) {
                             $redirectToShoppingCard = true;
                         } else {
                             if (SJB_ListingManager::activateListingBySID($listingSID, false)) {
                                 $listing = SJB_ListingManager::getObjectBySID($listingSID);
                                 SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                                 $activatedListings[] = $listingSID;
                             }
                         }
                     }
                 }
             }
             SJB_BrowseDBManager::addListings($activatedListings);
             if ($redirectToShoppingCard) {
                 $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/';
                 SJB_HelperFunctions::redirect($shoppingUrl);
             }
         } else {
             if (isset($_REQUEST['action_delete'])) {
                 $this->executeAction($listingsSIDs, 'delete');
                 $allowedPostBeforeCheckout = SJB_Settings::getSettingByName('allow_to_post_before_checkout');
                 foreach ($listingsSIDs as $listingSID => $value) {
                     if ($allowedPostBeforeCheckout == true) {
                         $this->deleteCheckoutedListingFromShopCart($listingSID, $userSID);
                     }
                 }
             } elseif (isset($_REQUEST['action_sendToApprove'])) {
                 $processListingsIds = array();
                 foreach ($listingsSIDs as $listingSID => $value) {
                     $processListingsIds[] = $listingSID;
                 }
                 SJB_ListingManager::setListingApprovalStatus($processListingsIds, 'pending');
             }
         }
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-listings/{$this->listingTypeID}/");
     }
     $listing = new SJB_Listing(array(), $this->listingTypeSID);
     $idAliasInfo = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addKeywordsProperty();
     $listing->addPicturesProperty();
     $listingTypeIdAliasInfo = $listing->addListingTypeIDProperty();
     $sortingFields = array();
     $innerJoin = array();
     $sortingField = SJB_Request::getVar("sorting_field", null);
     $sortingOrder = SJB_Request::getVar("sorting_order", null);
     if (isset($sortingField, $sortingOrder)) {
         $orderInfo = array('sorting_field' => $sortingField, 'sorting_order' => $sortingOrder);
     } else {
         $orderInfo = $criteriaSaver->getOrderInfo();
     }
     if ($orderInfo['sorting_field'] == 'applications') {
         $innerJoin['applications'] = array('count' => 'count(`applications`.id) as appCount', 'join' => 'LEFT JOIN', 'join_field' => 'listing_id', 'join_field2' => 'sid', 'main_table' => 'listings');
         $sortingFields['appCount'] = $orderInfo['sorting_order'];
         $searcher->setGroupByField(array('listings' => 'sid'));
     } else {
         if ($orderInfo['sorting_field'] == 'id') {
             $sortingFields['sid'] = $orderInfo['sorting_order'];
         } else {
             if ($orderInfo['sorting_field'] == 'subuser_sid') {
                 $innerJoin['users'] = array('join' => 'LEFT JOIN', 'join_field' => 'sid', 'join_field2' => 'subuser_sid', 'main_table' => 'listings');
                 $sortingFields['username'] = $orderInfo['sorting_order'];
             } else {
                 $property = $listing->getProperty($sortingField);
                 if (!empty($property) && $property->isSystem()) {
                     $sortingFields[$orderInfo['sorting_field']] = $orderInfo['sorting_order'];
                 } else {
                     $sortingFields['activation_date'] = 'DESC';
                 }
             }
         }
     }
     $this->requestCriteria['sorting_field'] = $orderInfo['sorting_field'];
     $this->requestCriteria['sorting_order'] = $orderInfo['sorting_order'];
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($_REQUEST, $this->requestCriteria), $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($idAliasInfo);
     $aliases->addAlias($listingTypeIdAliasInfo);
     $foundListingsSIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields, $innerJoin);
     $searchFormBuilder = new SJB_SearchFormBuilder($listing);
     $searchFormBuilder->registerTags($tp);
     $searchFormBuilder->setCriteria($criteria);
     // получим информацию о имеющихся листингах
     $listingsInfo = array();
     $currentUserInfo = SJB_UserManager::getCurrentUserInfo();
     $contractInfo['extra_info']['listing_amount'] = 0;
     if ($acl->isAllowed('post_' . $this->listingTypeID)) {
         $permissionParam = $acl->getPermissionParams('post_' . $this->listingTypeID);
         if (empty($permissionParam)) {
             $contractInfo['extra_info']['listing_amount'] = 'unlimited';
         } else {
             $contractInfo['extra_info']['listing_amount'] = $permissionParam;
         }
     }
     $currentUser = SJB_UserManager::getCurrentUser();
     $contractsSIDs = $currentUser->getContractID();
     $listingsInfo['listingsNum'] = SJB_ContractManager::getListingsNumberByContractSIDsListingType($contractsSIDs, $this->listingTypeID);
     $listingsInfo['listingsMax'] = $contractInfo['extra_info']['listing_amount'];
     if ($listingsInfo['listingsMax'] === 'unlimited') {
         $listingsInfo['listingsLeft'] = 'unlimited';
     } else {
         $listingsInfo['listingsLeft'] = $listingsInfo['listingsMax'] - $listingsInfo['listingsNum'];
         $listingsInfo['listingsLeft'] = $listingsInfo['listingsLeft'] < 0 ? 0 : $listingsInfo['listingsLeft'];
     }
     $tp->assign('listingTypeID', $this->listingTypeID);
     $tp->assign('listingTypeName', SJB_ListingTypeManager::getListingTypeNameBySID($this->listingTypeSID));
     $tp->assign('listingsInfo', $listingsInfo);
     $tp->display('my_listings_form.tpl');
     $page = SJB_Request::getVar('page', 1);
     $listingsPerPage = $criteriaSaver->getListingsPerPage();
     //save 'listings per page' in the session
     if (empty($listingsPerPage)) {
         $listingsPerPage = 10;
     }
     $listingsPerPage = SJB_Request::getVar('listings_per_page', $listingsPerPage);
     $criteriaSaver->setSessionForListingsPerPage($listingsPerPage);
     $criteriaSaver->setSessionForCurrentPage($page);
     $criteriaSaver->setSessionForCriteria($_REQUEST);
     $criteriaSaver->setSessionForOrderInfo($orderInfo);
     $criteriaSaver->setSessionForObjectSIDs($foundListingsSIDs);
     // get Applications
     $appsGroups = SJB_Applications::getAppGroupsByEmployer($currentUserInfo['sid']);
     $apps = array();
     foreach ($appsGroups as $group) {
         $apps[$group['listing_id']] = $group['count'];
     }
     $searchCriteriaStructure = $criteriaSaver->createTemplateStructureForCriteria();
     $listingSearchStructure = $criteriaSaver->createTemplateStructureForSearch();
     /**************** P A G I N G *****************/
     if ($listingSearchStructure['current_page'] > $listingSearchStructure['pages_number']) {
         $listingSearchStructure['current_page'] = $listingSearchStructure['pages_number'];
     }
     if ($listingSearchStructure['current_page'] < 1) {
         $listingSearchStructure['current_page'] = 1;
     }
     $sortedFoundListingsSIDsByPages = array_chunk($foundListingsSIDs, $listingSearchStructure['listings_per_page'], true);
     /************* S T R U C T U R E **************/
     $listingsStructure = array();
     $listingStructureMetaData = array();
     if (isset($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1])) {
         foreach ($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1] as $sid) {
             $listing = SJB_ListingManager::getObjectBySID($sid);
             $listing->addPicturesProperty();
             $listingStructure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $listingsStructure[$listing->getID()] = $listingStructure;
             if (isset($listingStructure['METADATA'])) {
                 $listingStructureMetaData = array_merge($listingStructureMetaData, $listingStructure['METADATA']);
             }
         }
     }
     /*************** D I S P L A Y ****************/
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $metadata = array();
     $metadata['listing'] = $metaDataProvider->getMetaData($listingStructureMetaData);
     $waitApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($this->listingTypeSID);
     $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates'));
     $tp->assign('show_comments', SJB_Settings::getSettingByName('show_comments'));
     $tp->assign('METADATA', $metadata);
     $tp->assign('sorting_field', $listingSearchStructure['sorting_field']);
     $tp->assign('sorting_order', $listingSearchStructure['sorting_order']);
     $tp->assign('property', $this->getSortableProperties());
     $tp->assign('listing_search', $listingSearchStructure);
     $tp->assign('search_criteria', $searchCriteriaStructure);
     $tp->assign('listings', $listingsStructure);
     $tp->assign('waitApprove', $waitApprove);
     $tp->assign('apps', $apps);
     $hasSubusersWithListings = false;
     $subusers = SJB_UserManager::getSubusers($currentUserInfo['sid']);
     foreach ($subusers as $subuser) {
         if ($acl->isAllowed('subuser_add_listings', $subuser['sid']) || $acl->isAllowed('subuser_manage_listings', $subuser['sid'])) {
             $hasSubusersWithListings = true;
             break;
         }
     }
     $tp->assign('hasSubusersWithListings', $hasSubusersWithListings);
     $tp->display('my_listings.tpl');
 }
Пример #12
0
 private function getListingSidCollectionFromRequest($requested_data, $listing_type_sid, $criteria_saver)
 {
     $listing = new SJB_Listing(array(), $listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     // select only accessible listings by user sid
     // see SearchCriterion.php, AccessibleCriterion class
     $requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
     $criteria = $criteria_saver->getCriteria();
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($criteria, $requested_data), $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $sortingFields = array();
     $orderInfo = $criteria_saver->getOrderInfo();
     $property = $listing->getProperty($orderInfo['sorting_field']);
     if (!empty($property) && $property->isSystem()) {
         $sortingFields = array('priority' => 'desc', $orderInfo['sorting_field'] => $orderInfo['sorting_order']);
     }
     $searcher = new SJB_ListingSearcher();
     return $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields);
 }
Пример #13
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $userInfo = SJB_Authorization::getCurrentUserInfo();
     if (empty($userInfo)) {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
     $template = SJB_Request::getVar('template', 'my_invoices.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl');
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $_REQUEST['user_sid']['equal'] = $userInfo['sid'];
     if (!isset($_REQUEST['date'])) {
         $i18n = SJB_ObjectMother::createI18N();
         $_REQUEST['date']['not_less'] = $i18n->getDate(date('Y-m-d', time() - 30 * 24 * 60 * 60));
         $_REQUEST['date']['not_more'] = $i18n->getDate(date('Y-m-d'));
     }
     $invoice = new SJB_Invoice(array());
     $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserDBManager::getUserSIDsLikeSearchString'));
     $searchFormBuilder = new SJB_SearchFormBuilder($invoice);
     $criteriaSaver = new SJB_InvoiceCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria());
     }
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice);
     $searchFormBuilder->setCriteria($criteria);
     $searchFormBuilder->registerTags($tp);
     $tp->display($searchTemplate);
     /********************** S O R T I N G *********************/
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice);
     $searcher = new SJB_InvoiceSearcher();
     $foundInvoices = array();
     $foundInvoicesInfo = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases);
         $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $foundInvoices = $criteriaSaver->getObjectsFromSession();
     }
     foreach ($foundInvoices as $id => $invoice) {
         $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID()));
         $subUserSid = $invoice->getPropertyValue('subuser_sid');
         if ($subUserSid) {
             $payer = SJB_UserManager::getUserNameByUserSID($subUserSid);
         } else {
             $userSid = $invoice->getPropertyValue('user_sid');
             $payer = SJB_UserManager::getUserNameByUserSID($userSid);
         }
         $invoice->addProperty(array('id' => 'payer', 'type' => 'string', 'value' => $payer));
         $foundInvoices[$id] = $invoice;
         $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID());
     }
     $sortingField = SJB_Request::getVar('sorting_field', 'sid');
     $sortingOrder = SJB_Request::getVar('sorting_order', 'DESC');
     if ($invoice->propertyIsSet($sortingField)) {
         $sortArray = array();
         $sortedFoundInvoicesInfo = array();
         foreach ($foundInvoices as $id => $invoice) {
             $sortArray[$id] = $invoice->getPropertyValue($sortingField);
         }
         if ($sortingOrder == 'ASC') {
             asort($sortArray);
         } elseif ($sortingOrder == 'DESC') {
             arsort($sortArray);
         }
         foreach ($sortArray as $id => $value) {
             $sortedFoundInvoicesInfo[$id] = $foundInvoicesInfo[$id];
         }
     } else {
         $sortedFoundInvoicesInfo = $foundInvoicesInfo;
     }
     $formCollection = new SJB_FormCollection($foundInvoices);
     $formCollection->registerTags($tp);
     $subUsers = SJB_UserManager::getSubUsers($userInfo['sid']);
     $isSubUserExists = !empty($subUsers) ? true : false;
     $tp->assign('isSubUserExists', $isSubUserExists);
     $tp->assign('sorting_field', $sortingField);
     $tp->assign('sorting_order', $sortingOrder);
     $tp->assign('found_invoices', $sortedFoundInvoicesInfo);
     $tp->display($template);
 }
Пример #14
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $networkFeeds = array();
     $template = 'social_media.tpl';
     $formSubmitted = SJB_Request::getVar('submit');
     $action = SJB_Request::getVar('action');
     $subAction = SJB_Request::getVar('sub_action');
     $sid = SJB_Request::getVar('sid');
     $groups = array();
     $accountInfo = null;
     $messages = array();
     $savedSettings = array();
     if (SJB_Request::getVar('error', false)) {
         $errors[] = SJB_Request::getVar('error', false);
     }
     if (SJB_Request::getVar('message', false)) {
         $messages[] = SJB_Request::getVar('message', false);
     }
     $socNetworks = array('facebook' => array('name' => 'Facebook'), 'linkedin' => array('name' => 'Linkedin'), 'twitter' => array('name' => 'Twitter'), 'googleplus' => array('name' => 'Google+'), 'bitly' => array('name' => 'Bitly'));
     $network = SJB_Request::getVar('passed_parameters_via_uri');
     if (empty($network)) {
         $network = SJB_Request::getVar('soc_network');
     }
     switch ($network) {
         case 'facebook':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_FacebookSocial';
             break;
         case 'linkedin':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_LinkedInSocial';
             break;
         case 'twitter':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_TwitterSocial';
             break;
         case 'googleplus':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_GooglePlusSocial';
             break;
         default:
             $network = '';
             $action = '';
             $objectName = '';
             break;
     }
     switch ($action) {
         case 'add_feed':
             SJB_Session::unsetValue($network);
             SJB_Session::unsetValue($network . 'Feed');
             $template = 'feed_input_form.tpl';
             $accountID = SJB_Request::getVar('account_id', false);
             $isAuthorized = SJB_Request::getVar('authorized', false);
             if ($accountID) {
                 $tp->assign('accountID', $accountID);
             }
             $feed = new $objectName();
             $addForm = new SJB_Form($feed);
             $addForm->registerTags($tp);
             $searchFormBuilder = new SJB_SearchFormBuilder($feed);
             $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
             $searchFormBuilder->setCriteria($criteria);
             $searchFormBuilder->registerTags($tp);
             $systemFields = $feed->details->systemFields;
             $postingFields = $feed->details->postingFields;
             $listingFields = $feed->details->commonFields;
             $tp->assign('authorized', $isAuthorized);
             $tp->assign('listingFields', $listingFields);
             $tp->assign('postingFields', $postingFields);
             $tp->assign('systemFields', $systemFields);
             $tp->assign('action', $action);
             break;
         case 'save_feed':
             $template = 'feed_input_form.tpl';
             $fieldErrors = array();
             $mediaObject = $objectName . 'Media';
             $networkSocialMedia = new $mediaObject();
             $isAuthorized = SJB_Request::getVar('authorized', false);
             $actionFeed = SJB_Request::getVar('action_feed');
             if ($actionFeed != 'add_feed' && $network != 'twitter') {
                 try {
                     $accountInfo = $networkSocialMedia->getAccountInfo($sid);
                 } catch (Exception $e) {
                     $isAuthorized = false;
                     $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
                 }
             }
             $isGroupsExist = !empty($accountInfo['groups']);
             if (SJB_Request::getVar('process_token', false)) {
                 $_REQUEST = unserialize(SJB_Session::getValue($network . 'Feed'));
                 $_REQUEST['process_token'] = 1;
             }
             $feed = new $objectName($_REQUEST, $isGroupsExist, $isAuthorized);
             if ($isGroupsExist) {
                 $groups = $accountInfo['groups'];
             }
             if ($sid) {
                 $feed->setSID($sid);
                 $tp->assign('feed_sid', $sid);
             }
             $criteriaSaver = new SJB_ListingCriteriaSaver();
             $criteriaSaver->setSessionForCriteria($_REQUEST);
             $requestedData = $criteriaSaver->getCriteria();
             $searchFormBuilder = new SJB_SearchFormBuilder($feed);
             $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
             $searchFormBuilder->setCriteria($criteria);
             $searchFormBuilder->registerTags($tp);
             $properties = $feed->getProperties();
             foreach ($properties as $key => $property) {
                 if (!$property->isSystem()) {
                     $feed->deleteProperty($key);
                 }
             }
             $this->checkToken($tp, $networkSocialMedia, $errors, array(), $network, $sid);
             $addForm = new SJB_Form($feed);
             $addForm->registerTags($tp);
             if ($addForm->isDataValid($fieldErrors)) {
                 if ($network == 'twitter') {
                     try {
                         $accessToken = $networkSocialMedia->getAccessToken($sid, $action, $errors);
                     } catch (Exception $e) {
                         $accessToken = false;
                         $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
                     }
                     if (empty($errors) && $accessToken != false) {
                         $feed->addProperty(array('id' => 'access_token', 'type' => 'text', 'value' => serialize($accessToken), 'is_system' => true));
                     }
                 } else {
                     if ($network == 'facebook' && !empty($accountInfo)) {
                         $feed->addProperty(array('id' => 'access_token', 'type' => 'text', 'value' => serialize($accountInfo['access_token']), 'is_system' => true));
                         $feed->addProperty(array('id' => 'account_name', 'type' => 'text', 'value' => serialize($accountInfo['account_name']), 'is_system' => true));
                     }
                 }
                 if (empty($errors)) {
                     unset($requestedData['groups']);
                     $feed->addProperty(array('id' => 'search_data', 'type' => 'text', 'value' => serialize($requestedData), 'is_system' => true));
                     $feed->saveFeed($feed, $action);
                     if ($formSubmitted == 'save') {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network . '#postJobs');
                     }
                     $tp->assign('feed_sid', $feed->getSID());
                 }
             }
             $systemFields = $feed->details->systemFields;
             $postingFields = $feed->details->postingFields;
             $listingFields = $feed->details->commonFields;
             $changeAccountUrl = "action=authorize&sid={$sid}&sub_action=change_account&soc_network={$network}";
             $tp->assign('field_errors', $fieldErrors);
             $tp->assign('change_url', $changeAccountUrl);
             $tp->assign('listingFields', $listingFields);
             $tp->assign('postingFields', $postingFields);
             $tp->assign('systemFields', $systemFields);
             $tp->assign('action', $actionFeed);
             $tp->assign('authorized', $isAuthorized);
             $tp->assign('allGroups', $groups);
             break;
         case 'grant':
             $mediaObject = $objectName . 'Media';
             $networkSocialMedia = new $mediaObject();
             $error = '';
             try {
                 $accountInfo = $networkSocialMedia->getAccountInfo($sid, $subAction);
             } catch (Exception $e) {
                 $tp->assign('authorized', false);
                 $error = $e->getMessage();
             }
             if (empty($error)) {
                 $networkSocialMedia->updateAccessToken($sid, $accountInfo['account_id'], $accountInfo['account_name']);
                 $logoutUrl = SJB_System::getSystemSettings('SITE_URL') . "/social-media/{$network}?message=ACCOUNT_UPDATED#postJobs";
             } else {
                 $logoutUrl = SJB_System::getSystemSettings('SITE_URL') . "/social-media/{$network}?error={$error}#postJobs";
             }
             // After clicking the 'Grant Permission' button and login to Facebook we are redirected to the feeds list.
             SJB_HelperFunctions::redirect($logoutUrl);
             break;
         case 'edit_feed':
             if (!SJB_Request::getVar('oauth_token', false)) {
                 SJB_Session::unsetValue($network);
             }
             if (!SJB_Request::getVar('process_token', false)) {
                 SJB_Session::unsetValue($network . 'Feed');
             }
             if ($sid) {
                 $changeAccountUrl = "action=authorize&sid={$sid}&sub_action=change_account&soc_network={$network}";
                 $feedInfo = $objectName::getFeedInfoByNetworkIdAndSID($network, $sid);
                 $feedInfo = array_merge($feedInfo, $_REQUEST);
                 $criteriaInfo = $feedInfo['search_data'] ? unserialize($feedInfo['search_data']) : '';
                 $mediaObject = $objectName . 'Media';
                 $networkSocialMedia = new $mediaObject();
                 $isAuthorized = true;
                 if ($network != 'twitter') {
                     try {
                         $accountInfo = $networkSocialMedia->getAccountInfo($sid, $subAction);
                     } catch (Exception $e) {
                         $isAuthorized = false;
                         $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
                     }
                 }
                 $isGroupsExist = !empty($accountInfo['groups']);
                 if ($isGroupsExist) {
                     $groups = $accountInfo['groups'];
                 }
                 if ($accountInfo && $subAction == 'changed') {
                     $feedInfo = array_merge($feedInfo, $accountInfo);
                 }
                 $feed = new $objectName($feedInfo, $isGroupsExist, $isAuthorized);
                 $editForm = new SJB_Form($feed);
                 $editForm->registerTags($tp);
                 $searchFormBuilder = new SJB_SearchFormBuilder($feed);
                 $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($criteriaInfo);
                 $searchFormBuilder->setCriteria($criteria);
                 $searchFormBuilder->registerTags($tp);
                 $systemFields = $feed->details->systemFields;
                 $postingFields = $feed->details->postingFields;
                 $listingFields = $feed->details->commonFields;
                 $this->checkToken($tp, $networkSocialMedia, $errors, $feedInfo, $network, $sid);
                 $tp->assign('listingFields', $listingFields);
                 $tp->assign('postingFields', $postingFields);
                 $tp->assign('systemFields', $systemFields);
                 $tp->assign('feed_sid', $sid);
                 $tp->assign('authorized', $isAuthorized);
                 $tp->assign('allGroups', $groups);
                 $tp->assign('action', $action);
                 $tp->assign('change_url', $changeAccountUrl);
                 $template = 'feed_input_form.tpl';
             }
             break;
         case 'authorize':
             if (!SJB_Request::getVar('oauth_token', false)) {
                 SJB_Session::unsetValue($network);
             }
             $mediaObject = $objectName . 'Media';
             $networkSocialMedia = new $mediaObject();
             try {
                 if ($network == 'twitter') {
                     $accessToken = $networkSocialMedia->getAccessToken($sid, $subAction, $errors);
                     $networkSocialMedia->updateFeedToken($sid, $accessToken);
                     if (SJB_Request::getVar('sub_action', null, 'GET') == 'grant') {
                         if (empty($errors)) {
                             $messages[] = 'Account is successfully updated.';
                         }
                         break;
                     }
                 } else {
                     $accountInfo = $networkSocialMedia->getAccountInfo($sid, $subAction);
                 }
             } catch (Exception $e) {
                 $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
             }
             $changeAccountUrl = "action=authorize&sub_action=change_account&soc_network={$network}";
             $template = 'feed_input_form.tpl';
             $isAuthorized = isset($accountInfo['account_id']);
             $isGroupsExist = !empty($accountInfo['groups']);
             $feed = new $objectName($accountInfo, $isGroupsExist, $isAuthorized);
             if ($isGroupsExist) {
                 $groups = $accountInfo['groups'];
             }
             $addForm = new SJB_Form($feed);
             $addForm->registerTags($tp);
             $searchFormBuilder = new SJB_SearchFormBuilder($feed);
             $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
             $searchFormBuilder->setCriteria($criteria);
             $searchFormBuilder->registerTags($tp);
             $systemFields = $feed->details->systemFields;
             $postingFields = $feed->details->postingFields;
             $listingFields = $feed->details->commonFields;
             $tp->assign('listingFields', $listingFields);
             $tp->assign('postingFields', $postingFields);
             $tp->assign('systemFields', $systemFields);
             $tp->assign('action', $action);
             $tp->assign('authorized', $isAuthorized);
             $tp->assign('change_url', $changeAccountUrl);
             $tp->assign('allGroups', $groups);
             break;
         case 'delete_feed':
             $sid = SJB_Request::getVar('sid');
             if ($sid) {
                 $feed = new $objectName();
                 $feed->deleteFeed($sid);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network . '#postJobs');
             }
             break;
         case 'status':
             $sid = SJB_Request::getVar('sid');
             $active = SJB_Request::getVar('active');
             $feedInfo = $objectName::getFeedInfoByNetworkIdAndSID($network, $sid);
             if ($feedInfo != null && ($active == '1' || $active == '0')) {
                 $objectName::updateFeedStatus($network . '_feeds', $active, $sid);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network . '#postJobs');
             } else {
                 $errors[] = 'Feed does not exist';
             }
             break;
         case 'save_settings':
             $request = $_REQUEST;
             $error = $this->checkFields($request, $objectName);
             if (!$error) {
                 SJB_Settings::updateSettings($request);
                 if ($formSubmitted == 'save') {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/');
                 } else {
                     if ($formSubmitted == 'apply') {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network);
                     }
                 }
             }
             $savedSettings = $request;
             break;
     }
     if ($network) {
         if (empty($savedSettings)) {
             $savedSettings = SJB_Settings::getSettings();
         }
         SJB_Event::dispatch('RedefineSavedSetting', $savedSettings, true);
         if ($network != 'googleplus' && $action != 'edit_feed' && $action != 'add_feed' && $action != 'save_feed') {
             $networkFeeds = SJB_SocialMedia::getFeedsInfoByNetworkID($network);
             $currentDate = date('Y-m-d', time());
             foreach ($networkFeeds as $key => $feed) {
                 if (SJB_SocialMedia::isFeedExpired($feed, $currentDate)) {
                     $networkFeeds[$key]['expired'] = true;
                 }
             }
         }
         $tp->assign('network', $network);
         $tp->assign('savedSettings', $savedSettings);
         $tp->assign('networkFeeds', $networkFeeds);
         $tp->assign('networkName', $socNetworks[$network]['name']);
         if ($network != 'twitter') {
             $networkObject = new $objectName();
             $settings = $networkObject->getConnectSettings();
             $tp->assign('settings', $settings);
         }
     } else {
         $tp->assign('socNetworks', $socNetworks);
     }
     $tp->assign('networkFeeds', $networkFeeds);
     $tp->assign('socNetworks', $socNetworks);
     $tp->assign('errors', $errors);
     $tp->assign('messages', $messages);
     $tp->display($template);
 }
Пример #15
0
 private function displaySearchForm()
 {
     $this->searchFormBuilder->setCriteria($this->searchingCriteria);
     $this->searchFormBuilder->registerTags($this->templateProcessor);
     $this->templateProcessor->display("payment_log_search_form.tpl");
 }
Пример #16
0
 function _getListingSidCollectionFromRequest()
 {
     $listing = new SJB_Listing(array(), $this->listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addFeaturedProperty();
     $listing->addFeaturedLastShowedProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     // select only accessible listings by user sid
     // see SearchCriterion.php, AccessibleCriterion class
     if ($this->listing_type_id == 'Resume') {
         $this->requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
     }
     $criteria = $this->criteria_saver->getCriteria();
     if (isset($this->requested_data['PostedWithin']['multi_like'][0]) || isset($criteria['PostedWithin']['multi_like'][0])) {
         $within_period = '';
         if (isset($this->requested_data['PostedWithin']['multi_like'][0])) {
             $within_period = $this->requested_data['PostedWithin']['multi_like'][0];
             unset($this->requested_data['PostedWithin']['multi_like']);
         }
         if (isset($criteria['PostedWithin']['multi_like'][0])) {
             $within_period = $criteria['PostedWithin']['multi_like'][0];
             unset($criteria['PostedWithin']);
         }
         $i18n = SJB_I18N::getInstance();
         $this->requested_data['activation_date']['not_less'] = $i18n->getDate(date('Y-m-d', strtotime("- {$within_period} days")));
     }
     if (isset($this->requested_data['CompanyName']['multi_like_and'][0]) || isset($criteria['CompanyName']['multi_like_and'][0])) {
         if (isset($this->requested_data['CompanyName']['multi_like_and'][0])) {
             $companyName = $this->requested_data['CompanyName']['multi_like_and'][0];
             unset($this->requested_data['CompanyName']);
         }
         if (isset($criteria['CompanyName']['multi_like_and'][0])) {
             $companyName = $criteria['CompanyName']['multi_like_and'][0];
             unset($criteria['CompanyName']);
         }
         $userName = SJB_UserManager::getUserNameByCompanyName($companyName);
         if ($userName) {
             $this->requested_data['username']['equal'] = $userName;
         }
     }
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($criteria, $this->requested_data), $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $sortingFields = array();
     if ($this->usePriority) {
         $sortingFields['priority'] = 'DESC';
     }
     $innerJoin = array();
     $orderInfo = $this->criteria_saver->getOrderInfo();
     if (is_array($orderInfo['sorting_field'])) {
         $requestedSortingField = array();
         foreach ($orderInfo['sorting_field'] as $orderInfoProperty) {
             $fieldName = strstr($orderInfoProperty, '_', true);
             $id = $this->getLocationProperty($fieldName, $listing, $orderInfoProperty);
             if (!empty($id)) {
                 switch ($orderInfoProperty) {
                     case 'Location_State':
                         $innerJoin['states'] = array('stateName' => '`states`.`state_code`', 'join' => 'LEFT JOIN', 'join_field' => 'sid', 'join_field2' => $orderInfoProperty, 'main_table' => 'listings');
                         break;
                     case 'Location_Country':
                         $innerJoin['countries'] = array('countryName' => '`countries`.`country_name`', 'join' => 'LEFT JOIN', 'join_field' => 'sid', 'join_field2' => $orderInfoProperty, 'main_table' => 'listings');
                         break;
                     default:
                         break;
                 }
                 $sortingFields[$orderInfoProperty] = $orderInfo['sorting_order'];
                 $requestedSortingField[] = $orderInfoProperty;
             }
             $this->requested_data['sorting_field'] = $requestedSortingField;
             $this->requested_data['sorting_order'] = $orderInfo['sorting_order'];
         }
     } else {
         $property = $listing->getProperty($orderInfo['sorting_field']);
         if (!empty($property) && $property->isSystem()) {
             $sortingFields[$orderInfo['sorting_field']] = $orderInfo['sorting_order'];
             if ($property->getID() == 'CompanyName') {
                 $innerJoin['users'] = array('join' => 'INNER JOIN', 'join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'listings');
             }
             $this->requested_data['sorting_field'] = $orderInfo['sorting_field'];
             $this->requested_data['sorting_order'] = $orderInfo['sorting_order'];
         } else {
             $sortingFields['activation_date'] = 'DESC';
             $this->requested_data['sorting_field'] = 'activation_date';
             $this->requested_data['sorting_order'] = 'DESC';
         }
     }
     $searcher = new SJB_ListingSearcher();
     if ($this->listingsLimit) {
         $searcher->setLimit($this->listingsLimit);
     }
     $this->listing_search_structure['sorting_field'] = $this->requested_data['sorting_field'];
     $this->listing_search_structure['sorting_order'] = $this->requested_data['sorting_order'];
     return $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields, $innerJoin, $this->relevance);
 }
Пример #17
0
 /**
  * @param $fieldName
  * @param $fieldID
  * @param SJB_SearchResultsTP $stp
  * @param $userField
  * @return mixed
  */
 public static function countListingsByFieldName($fieldName, $fieldID, $stp, $userField)
 {
     $refineSearchLimit = SJB_Settings::getSettingByName('refine_search_items_limit');
     $limit = $refineSearchLimit ? ' LIMIT 0, ' . $refineSearchLimit : '';
     $listing = new SJB_Listing(array(), $stp->listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addFeaturedProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     $requestedCriteria = $stp->criteria_saver->getCriteria();
     if (isset($requestedCriteria['PostedWithin']) && $requestedCriteria['PostedWithin']['multi_like'][0] != '') {
         $within_period = $requestedCriteria['PostedWithin']['multi_like'][0];
         $i18n = SJB_I18N::getInstance();
         $requestedCriteria['activation_date']['not_less'] = $i18n->getDate(date('Y-m-d', strtotime("- {$within_period} days")));
         unset($requestedCriteria['PostedWithin']);
     }
     if (isset($requestedCriteria['CompanyName']['multi_like_and'][0])) {
         $userName = SJB_UserManager::getUserNameByCompanyName($requestedCriteria['CompanyName']['multi_like_and'][0]);
         unset($requestedCriteria['CompanyName']);
         if ($userName) {
             $requestedCriteria['username']['equal'] = $userName;
         }
     }
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($requestedCriteria, $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $aliases->changeAliasValuesInCriteria($criteria);
     $sqlTranslator = new SJB_SearchSqlTranslator('listings');
     $whereStatement = $sqlTranslator->_getWhereStatement($criteria);
     $objectSids = implode(',', $stp->found_listings_sids);
     if ($userField == 1) {
         $field = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldID);
     } else {
         $field = SJB_ListingFieldDBManager::getListingFieldInfoBySID($fieldID);
     }
     $result = array();
     $cache = SJB_Cache::getInstance();
     if (!empty($field['parent_sid'])) {
         $parentInfo = SJB_ListingFieldManager::getFieldInfoBySID($field['parent_sid']);
         $fieldName = $parentInfo['id'] . "_" . $fieldName;
         $field['id'] = $fieldName;
         $field['parentID'] = $parentInfo['id'];
     }
     switch ($field['type']) {
         case 'list':
         case 'multilist':
             if ($userField == 1) {
                 $query = "SELECT up.`{$fieldName}` as caption, count(`listings`.`sid`) as count\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t INNER JOIN `users` `up` ON `listings`.`user_sid` = `up`.`sid`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t {$whereStatement}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND up.`{$fieldName}` != ''\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY `up`.`{$fieldName}` ORDER BY count DESC";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_USERS));
                 }
             } else {
                 $query = "SELECT `{$fieldName}` as caption, count(`{$fieldName}`) as count FROM `listings` {$whereStatement} AND `{$fieldName}` != '' GROUP BY `{$fieldName}` ORDER BY count DESC";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS));
                 }
             }
             self::breakMultiCategory($result);
             $newResult = array();
             $listItem = new SJB_ListingFieldListItemManager();
             foreach ($result as $key => $val) {
                 if (!empty($field['parent_sid'])) {
                     $caption = '';
                     if ($field['id'] == $field['parentID'] . '_State') {
                         $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $field['display_as']);
                     } else {
                         $listValues = $field['list_values'];
                     }
                     foreach ($listValues as $listValue) {
                         if ($listValue['id'] == $val['caption']) {
                             $caption = $listValue['caption'];
                             break;
                         }
                     }
                 } else {
                     $itemInfo = $listItem->getListItemBySID($val['caption']);
                     $caption = $itemInfo ? $itemInfo->getValue() : null;
                 }
                 if ($caption != null) {
                     $newResult[$key]['count'] = $val['count'];
                     $newResult[$key]['value'] = $caption;
                     $newResult[$key]['sid'] = $val['caption'];
                 }
             }
             arsort($newResult);
             $result = $newResult;
             if (count($result) > $refineSearchLimit) {
                 $result = array_slice($result, 0, $refineSearchLimit);
             }
             break;
         case 'tree':
             $query = "SELECT `lt`.`sid` as `sid`, `lt`.`caption` as `value`, count(`listings`.`sid`) as `count`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `listing_field_tree` `lt` ON `lt`.`field_sid` = {$field['sid']} AND find_in_set(`lt`.`sid`, `listings`.`{$fieldName}`)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$whereStatement} GROUP BY `lt`.`sid` having `lt`.`sid` IS NOT NULL ORDER BY `count` DESC {$limit}";
             if (!($propertyValue = $cache->load(md5($query)))) {
                 $propertyValue = SJB_DB::query($query);
                 $cache->save($propertyValue, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_FIELDS));
             }
             foreach ($propertyValue as $value) {
                 $result[$value['sid']] = $value;
             }
             break;
         default:
             if ($userField == 1) {
                 $companyColumn = "up.`{$fieldName}`";
                 $query = "SELECT {$companyColumn} as `value`, count(listings.`sid`) as `count`\n\t\t\t\t\t\t\t\t\t\t\t FROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t INNER JOIN `users` `up` ON `listings`.`user_sid` = `up`.`sid`\n\t\t\t\t\t\t\t\t\t\t\t {$whereStatement}\n\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$companyColumn} ORDER BY `count` DESC {$limit}";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_USERS));
                 }
             } else {
                 if ($field['type'] == 'complex') {
                     $query = "SELECT `value`, count(`value`) as count FROM `listings_properties` WHERE `id`='{$fieldName}' AND `value` != '' AND `object_sid` in ({$objectSids}) GROUP BY `value` ORDER BY count DESC {$limit}";
                 } else {
                     $query = "SELECT `{$fieldName}` as value, count(`{$fieldName}`) as count FROM `listings` {$whereStatement} AND `{$fieldName}` != '' GROUP BY `{$fieldName}` ORDER BY count DESC {$limit}";
                 }
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS));
                 }
             }
             break;
     }
     $returnArr['caption'] = $field['caption'];
     $returnArr['values'] = $result;
     return $returnArr;
 }
Пример #18
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('template', 'users.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'user_search_form.tpl');
     $passedParametersViaUri = SJB_UrlParamProvider::getParams();
     $userGroupID = $passedParametersViaUri ? array_shift($passedParametersViaUri) : false;
     $userGroupSID = $userGroupID ? SJB_UserGroupManager::getUserGroupSIDByID($userGroupID) : null;
     $errors = array();
     /********** A C T I O N S   W I T H   U S E R S **********/
     $action = SJB_Request::getVar('action_name');
     if (!empty($action)) {
         $users_sids = SJB_Request::getVar('users', array());
         $_REQUEST['restore'] = 1;
         switch ($action) {
             case 'approve':
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     SJB_UserManager::setApprovalStatusByUserName($username, 'Approved');
                     SJB_UserManager::activateUserByUserName($username);
                     SJB_UserDBManager::deleteActivationKeyByUsername($username);
                     if (!SJB_SocialPlugin::getProfileSocialID($user_sid)) {
                         SJB_Notifications::sendUserWelcomeLetter($user_sid);
                     } else {
                         SJB_Notifications::sendUserApprovedLetter($user_sid);
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'reject':
                 $rejection_reason = SJB_Request::getVar('rejection_reason', '');
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     SJB_UserManager::setApprovalStatusByUserName($username, 'Rejected', $rejection_reason);
                     SJB_UserManager::deactivateUserByUserName($username);
                     SJB_Notifications::sendUserRejectedLetter($user_sid);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'activate':
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     $userinfo = SJB_UserManager::getUserInfoByUserName($username);
                     SJB_UserManager::activateUserByUserName($username);
                     if ($userinfo['approval'] == 'Approved') {
                         SJB_UserDBManager::deleteActivationKeyByUsername($username);
                         SJB_Notifications::sendUserApprovedLetter($user_sid);
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'deactivate':
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     SJB_UserManager::deactivateUserByUserName($username);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'delete':
                 foreach (array_keys($users_sids) as $user_sid) {
                     try {
                         SJB_UserManager::deleteUserById($user_sid);
                     } catch (Exception $e) {
                         $errors[] = $e->getMessage();
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'send_activation_letter':
                 foreach ($users_sids as $user_sid => $value) {
                     SJB_Notifications::sendUserActivationLetter($user_sid);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'change_product':
                 $productToChange = SJB_Request::getVar('product_to_change');
                 if (empty($productToChange)) {
                     $productToChange = 0;
                 }
                 foreach ($users_sids as $user_sid => $value) {
                     $user = SJB_UserManager::getObjectBySID($user_sid);
                     // UNSUBSCRIBE selected
                     if ($productToChange == 0) {
                         SJB_ContractManager::deleteAllContractsByUserSID($user_sid);
                     } else {
                         $productInfo = SJB_ProductsManager::getProductInfoBySID($productToChange);
                         $listingNumber = SJB_Request::getVar('number_of_listings', null);
                         if (is_null($listingNumber) && !empty($productInfo['number_of_listings'])) {
                             $listingNumber = $productInfo['number_of_listings'];
                         }
                         $contract = new SJB_Contract(array('product_sid' => $productToChange, 'numberOfListings' => $listingNumber, 'is_recurring' => 0));
                         $contract->setUserSID($user_sid);
                         $contract->saveInDB();
                         if ($contract->isFeaturedProfile()) {
                             SJB_UserManager::makeFeaturedBySID($user_sid);
                         }
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'ban_ip':
                 $cantBanUsers = array();
                 foreach ($users_sids as $user_sid => $value) {
                     $user = SJB_UserManager::getUserInfoBySID($user_sid);
                     if ($user['ip'] && !SJB_IPManager::getBannedIPByValue($user['ip'])) {
                         SJB_IPManager::makeIPBanned($user['ip']);
                     } else {
                         $cantBanUsers[] = $user['username'];
                     }
                 }
                 if ($cantBanUsers) {
                     $tp->assign('cantBanUsers', $cantBanUsers);
                 } else {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 }
                 break;
             case 'unban_ip':
                 $cantUnbanIPs = array();
                 foreach ($users_sids as $user_sid => $value) {
                     $user = SJB_UserManager::getUserInfoBySID($user_sid);
                     if ($user['ip'] !== '') {
                         if (SJB_IPManager::getBannedIPByValue($user['ip'])) {
                             SJB_IPManager::makeIPEnabledByValue($user['ip']);
                         } elseif (SJB_UserManager::checkBan($errors, $user['ip'])) {
                             $cantUnbanIPs[] = $user['ip'];
                         }
                     }
                 }
                 if ($cantUnbanIPs) {
                     $tp->assign('rangeIPs', $cantUnbanIPs);
                 } else {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 }
                 break;
             default:
                 unset($_REQUEST['restore']);
                 break;
         }
         if (empty($errors)) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
         }
     }
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $user = new SJB_User(array(), $userGroupSID);
     $user->addProperty(array('id' => 'user_group', 'type' => 'list', 'value' => '', 'is_system' => true, 'list_values' => SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions()));
     $user->addProperty(array('id' => 'registration_date', 'type' => 'date', 'value' => '', 'is_system' => true));
     $user->addProperty(array('id' => 'approval', 'caption' => 'Approval', 'type' => 'list', 'list_values' => array(array('id' => 'Pending', 'caption' => 'Pending'), array('id' => 'Approved', 'caption' => 'Approved'), array('id' => 'Rejected', 'caption' => 'Rejected')), 'length' => '10', 'is_required' => false, 'is_system' => true));
     // get array of accessible products
     $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userGroupSID);
     $products = array();
     foreach ($productsSIDs as $key => $productSID) {
         $product = SJB_ProductsManager::getProductInfoBySID($productSID);
         $products[$key] = $product;
         if (!empty($product['pricing_type']) && $product['pricing_type'] == 'volume_based' && !empty($product['volume_based_pricing'])) {
             $volumeBasedPricing = $product['volume_based_pricing'];
             $minListings = min($volumeBasedPricing['listings_range_from']);
             $maxListings = max($volumeBasedPricing['listings_range_to']);
             $countListings = array();
             for ($i = $minListings; $i <= $maxListings; $i++) {
                 $countListings[] = $i;
             }
             $products[$key]['count_listings'] = $countListings;
         }
     }
     $user->addProperty(array('id' => 'product', 'type' => 'list', 'value' => '', 'list_values' => $products, 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'user_group', 'real_id' => 'user_group_sid', 'transform_function' => 'SJB_UserGroupManager::getUserGroupSIDByID'));
     $aliases->addAlias(array('id' => 'product', 'real_id' => 'product_sid'));
     $_REQUEST['user_group']['equal'] = $userGroupSID;
     $search_form_builder = new SJB_SearchFormBuilder($user);
     $criteria_saver = new SJB_UserCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $user);
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userGroupSID);
     if (SJB_Request::getVar('online', '') == '1') {
         $tp->assign("online", true);
     }
     $tp->assign('userGroupInfo', $userGroupInfo);
     $tp->assign('products', $products);
     $tp->assign('selectedProduct', isset($_REQUEST['product']['simple_equal']) ? $_REQUEST['product']['simple_equal'] : '');
     $tp->display($searchTemplate);
     /********************** S O R T I N G *********************/
     $paginator = new SJB_UsersPagination($userGroupInfo, SJB_Request::getVar('online', ''), $template);
     $firstLastName = '';
     if (!empty($_REQUEST['FirstName']['equal'])) {
         $name['FirstName']['any_words'] = $name['LastName']['any_words'] = $_REQUEST['FirstName']['equal'];
         $firstLastName = $_REQUEST['FirstName'];
         unset($_REQUEST['FirstName']);
         $_REQUEST['FirstName']['fields_or'] = $name;
     }
     $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $user);
     $inner_join = false;
     // if search by product field
     if (isset($_REQUEST['product']['simple_equal']) && $_REQUEST['product']['simple_equal'] != '') {
         $inner_join = array('contracts' => array('join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'INNER JOIN'));
     }
     if (SJB_Request::getVar('online', '') == '1') {
         $maxLifeTime = ini_get("session.gc_maxlifetime");
         $currentTime = time();
         $innerJoinOnline = array('user_session_data_storage' => array('join_field' => 'user_sid', 'join_field2' => 'sid', 'select_field' => 'session_id', 'join' => 'INNER JOIN', 'where' => "AND unix_timestamp(`user_session_data_storage`.`last_activity`) + {$maxLifeTime} > {$currentTime}"));
         if ($inner_join) {
             $inner_join = array_merge($inner_join, $innerJoinOnline);
         } else {
             $inner_join = $innerJoinOnline;
         }
     }
     $searcher = new SJB_UserSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $inner_join);
     $found_users = array();
     $found_users_sids = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $found_users = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $found_users = $criteria_saver->getObjectsFromSession();
     }
     foreach ($found_users as $id => $userID) {
         $user_info = SJB_UserManager::getUserInfoBySID($userID);
         $contractInfo = SJB_ContractManager::getAllContractsInfoByUserSID($user_info['sid']);
         $user_info['products'] = count($contractInfo);
         $found_users[$id] = $user_info;
     }
     $paginator->setItemsCount($searcher->getAffectedRows());
     $sorted_found_users_sids = $found_users_sids;
     /****************************************************************/
     $tp->assign("userGroupInfo", $userGroupInfo);
     $tp->assign("found_users", $found_users);
     $searchFields = '';
     foreach ($_REQUEST as $key => $val) {
         if (is_array($val)) {
             foreach ($val as $fieldName => $fieldValue) {
                 if (is_array($fieldValue)) {
                     foreach ($fieldValue as $fieldSubName => $fieldSubValue) {
                         $searchFields .= "&{$key}[{$fieldSubName}]=" . array_pop($fieldSubValue);
                     }
                 } else {
                     $searchFields .= "&{$key}[{$fieldName}]={$fieldValue}";
                 }
             }
         }
     }
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign("searchFields", $searchFields);
     $tp->assign("found_users_sids", $sorted_found_users_sids);
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
Пример #19
0
 private function sendSearchedNotifications()
 {
     $savedSearches = SJB_SavedSearches::getAutoNotifySavedSearches();
     $listing = new SJB_Listing();
     $this->notifiedSavedSearchesSID = array();
     $notificationsLimit = (int) SJB_Settings::getSettingByName('num_of_listings_sent_in_email_alerts');
     foreach ($savedSearches as $savedSearch) {
         $searcher = new SJB_ListingSearcher();
         $listing->addActivationDateProperty();
         $dataSearch = unserialize($savedSearch['data']);
         $dataSearch['active']['equal'] = 1;
         $dateArray = explode('-', $savedSearch['last_send']);
         $savedSearch['last_send'] = strftime($this->lang['date_format'], mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));
         $dataSearch['activation_date']['not_less'] = $savedSearch['last_send'];
         $dataSearch['activation_date']['not_more'] = $this->currentDate;
         $listingTypeSID = 0;
         if ($dataSearch['listing_type']['equal']) {
             $listingTypeID = $dataSearch['listing_type']['equal'];
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listingTypeSID)) {
                 $dataSearch['status']['equal'] = 'approved';
             }
         }
         $idAliasInfo = $listing->addIDProperty();
         $usernameAliasInfo = $listing->addUsernameProperty();
         $listingTypeIDInfo = $listing->addListingTypeIDProperty();
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($idAliasInfo);
         $aliases->addAlias($usernameAliasInfo);
         $aliases->addAlias($listingTypeIDInfo);
         $dataSearch['access_type'] = array('accessible' => $savedSearch['user_sid']);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($dataSearch, $listing);
         $searcher->found_object_sids = array();
         $searcher->setLimit($notificationsLimit);
         $foundListingsIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         if (count($foundListingsIDs)) {
             $savedSearch['activation_date'] = $savedSearch['last_send'];
             if (SJB_Notifications::sendUserNewListingsFoundLetter($foundListingsIDs, $savedSearch['user_sid'], $savedSearch, $listingTypeSID)) {
                 SJB_Statistics::addStatistics('sentAlert', $listingTypeSID, $savedSearch['sid']);
                 SJB_DB::query('UPDATE `saved_searches` SET `last_send` = CURDATE() WHERE `sid` = ?n', $savedSearch['sid']);
             }
             $this->notifiedSavedSearchesSID[] = $savedSearch['sid'];
         }
     }
 }
Пример #20
0
 public function execute()
 {
     $listingTypeSid = SJB_Request::getVar('listing_type_sid', false);
     $template_processor = SJB_System::getTemplateProcessor();
     if (isset($_REQUEST['restore']) && isset($listingSearcher['criteria_values']['listing_type_sid'])) {
         $listingSearcher = SJB_Session::getValue('ListingSearcher', null);
         $listingTypeSid = $listingSearcher['criteria_values']['listing_type_sid']['equal'];
     }
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSid);
     $template_processor->assign('showApprovalStatusField', $listingTypeInfo['waitApprove']);
     $template_processor->assign('listingsType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
     $show_search_form = true;
     if (empty($_REQUEST['action']) && empty($_REQUEST['restore'])) {
         $show_search_form = false;
     }
     $template_processor->assign('show_search_form', $show_search_form);
     /**************** S E A R C H   F O R M ****************/
     $listing = SJB_ObjectMother::createListing(array(), $listingTypeSid);
     $id_alias_info = $listing->addIDProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $productAliasInfo = $listing->addProductProperty($listingTypeSid);
     $listing->addCompanyNameProperty();
     $listing->addActivationDateProperty();
     $listing->addExpirationDateProperty();
     $listing->addActiveProperty();
     $listing->addKeywordsProperty();
     $listing->addDataSourceProperty();
     $listing->addPriorityProperty();
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($productAliasInfo);
     $search_form_builder = new SJB_SearchFormBuilder($listing);
     $criteria_saver = SJB_ObjectMother::createListingCriteriaSaver();
     $keywords = NULL;
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
         $criteria = $criteria_saver->getCriteria();
         $listingSid = SJB_Array::getPath($criteria, 'sid') ? $criteria['sid']['equal'] : '';
         $keywords = SJB_Array::getPath($criteria, 'keywords') ? $criteria['keywords']['like'] : $listingSid;
     }
     if ($listingTypeSid) {
         $_REQUEST['listing_type_sid'] = array('equal' => $listingTypeSid);
     }
     $template_processor->assign('companyName', isset($_REQUEST['company_name']['like']) ? $_REQUEST['company_name']['like'] : '');
     $template_processor->assign('idKeyword', isset($_REQUEST['idKeyword']) ? $_REQUEST['idKeyword'] : $keywords);
     $this->prepareRequestedCriteria();
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST, $listing);
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($template_processor);
     $template_processor->display("manage_listings.tpl");
     /************* S E A R C H   F O R M   R E S U L T S *************/
     $paginator = new SJB_ListingPagination($listingTypeInfo);
     $searcher = SJB_ObjectMother::createListingSearcher();
     $inner_join = array();
     if (SJB_Request::getVar('action', '') == 'search' || isset($_REQUEST['restore'])) {
         if (!isset($_REQUEST['restore'])) {
             $criteria_saver->resetSearchResultsDisplay();
         }
         if (isset($_REQUEST['company_name']['like']) && $_REQUEST['company_name']['like'] != '') {
             $inner_join = array('users' => array('join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'listings', 'join' => 'INNER JOIN'));
         }
         $foundListingsSIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases, array(), $inner_join);
         //get found listing sids
         if (empty($foundListingsSIDs) && $paginator->currentPage != 1) {
             if ($listingTypeInfo['id'] == 'Job' || $listingTypeInfo['id'] == 'Resume') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingTypeInfo['id']) . 's/?page=1&restore=1');
             } else {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingTypeInfo['id']) . '-listings/?page=1&restore=1');
             }
         }
         $criteria_saver->setSessionForListingsPerPage($paginator->itemsPerPage);
         $criteria_saver->setSessionForCurrentPage($paginator->currentPage);
         $criteria_saver->setSessionForCriteria($_REQUEST);
         $orderInfo = array('sorting_field' => $paginator->sortingField, 'sorting_order' => $paginator->sortingOrder);
         $criteria_saver->setSessionForOrderInfo($orderInfo);
     } else {
         $criteria_saver->resetSearchResultsDisplay();
         return;
     }
     $criteria_saver->setSessionForObjectSIDs($foundListingsSIDs);
     $listing_search_structure = $criteria_saver->createTemplateStructureForSearch();
     /**************** S O R T I N G *****************/
     $empty_listing = SJB_ObjectMother::createListing(array(), $listingTypeSid);
     $empty_listing->addPicturesProperty();
     $empty_listing->addIDProperty();
     $empty_listing->addListingTypeIDProperty();
     $empty_listing->addActivationDateProperty();
     $empty_listing->addExpirationDateProperty();
     $empty_listing->addUsernameProperty();
     $empty_listing->addPicturesProperty();
     $empty_listing->addNumberOfViewsProperty();
     $empty_listing->addActiveProperty();
     $empty_listing->addKeywordsProperty();
     $empty_listing->addDataSourceProperty();
     $listing->addRejectReasonProperty();
     if ($empty_listing->propertyIsSet($listing_search_structure['sorting_field']) && !empty($foundListingsSIDs)) {
         $sorting_field = $listing_search_structure['sorting_field'];
         $sorting_order = $listing_search_structure['sorting_order'];
         switch ($sorting_field) {
             case 'username':
                 $ids = join(", ", $foundListingsSIDs);
                 $sql = "\tSELECT\t\tlistings.*\n\t\t\t\t\t\tFROM \t\tlistings\n\t\t\t\t\t\tLEFT JOIN\tusers on listings.user_sid = users.sid\n\t\t\t\t\t\tWHERE \t\tlistings.sid IN ({$ids})\n\t\t\t\t\t\tORDER BY users.username {$sorting_order}";
                 $listings_info = SJB_DB::query($sql);
                 break;
             case 'listing_type':
                 $ids = join(", ", $foundListingsSIDs);
                 $sql = "\tSELECT\t\tlistings.*\n\t\t\t\t\t\tFROM \t\tlistings\n\t\t\t\t\t\tLEFT JOIN\tlisting_types on listings.listing_type_sid = listing_types.sid\n\t\t\t\t\t\tWHERE \t\tlistings.sid IN ({$ids})\n\t\t\t\t\t\tORDER BY listing_types.id {$sorting_order}";
                 $listings_info = SJB_DB::query($sql);
                 break;
             case 'id':
                 $ids = join(", ", $foundListingsSIDs);
                 $sql = "\tSELECT\t\tlistings.*\n\t\t\t\t\t\tFROM \t\tlistings\n\t\t\t\t\t\tWHERE\t\tlistings.sid IN ({$ids})\n\t\t\t\t\t\tORDER BY sid {$sorting_order}";
                 $listings_info = SJB_DB::query($sql);
                 break;
             default:
                 $property = $empty_listing->getProperty($sorting_field);
                 $listing_request_creator = new SJB_ListingRequestCreator($foundListingsSIDs, array('property' => $property, 'sorting_order' => $sorting_order));
                 $listings_info = SJB_DB::query($listing_request_creator->getRequest());
                 break;
         }
         $listings_sids = array();
         foreach ($listings_info as $listing_info) {
             $listings_sids[$listing_info['sid']] = $listing_info['sid'];
         }
         $sortedFoundListingsSIDs = array_keys($listings_sids);
         $criteria_saver->setSessionForObjectSIDs($sortedFoundListingsSIDs);
     } else {
         $sortedFoundListingsSIDs = $foundListingsSIDs;
         $criteria_saver->setSessionForObjectSIDs($foundListingsSIDs);
     }
     /**************** P A G I N G *****************/
     $sortedFoundListingsSIDsByPages = array_chunk($sortedFoundListingsSIDs, $paginator->itemsPerPage, true);
     $paginator->setItemsCount(count($sortedFoundListingsSIDs));
     /************* S T R U C T U R E **************/
     $listings_structure = array();
     if (isset($sortedFoundListingsSIDsByPages[$paginator->currentPage - 1])) {
         foreach ($sortedFoundListingsSIDsByPages[$paginator->currentPage - 1] as $sid) {
             $listing = SJB_ListingManager::getObjectBySID($sid);
             $listing->addPicturesProperty();
             $listings_structure[$listing->getID()] = SJB_ListingManager::createTemplateStructureForListing($listing);
         }
     }
     /*************** D I S P L A Y ****************/
     $template_processor->assign("search_criteria", $criteria_saver->createTemplateStructureForCriteria());
     $template_processor->assign('paginationInfo', $paginator->getPaginationInfo());
     $template_processor->assign('listings', $listings_structure);
     $template_processor->display('display_results.tpl');
 }
Пример #21
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     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);
     }
     $listing_type_sid = 0;
     if (!empty($listing_type_id)) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
     }
     if (!isset($_REQUEST['listing_type']['equal']) && isset($listing_type_id)) {
         $_REQUEST['listing_type']['equal'] = $listing_type_id;
     }
     if (isset($_REQUEST['searchId'])) {
         $criteria_saver = new SJB_ListingCriteriaSaver($_REQUEST['searchId']);
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $empty_listing = new SJB_Listing(array(), $listing_type_sid);
     $empty_listing->addIDProperty();
     $empty_listing->addActivationDateProperty();
     $empty_listing->addUsernameProperty();
     $empty_listing->addKeywordsProperty();
     $empty_listing->addPicturesProperty();
     $empty_listing->addListingTypeIDProperty();
     $empty_listing->addPostedWithinProperty();
     $search_form_builder = new SJB_SearchFormBuilder($empty_listing);
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
     $properties = $empty_listing->getProperties();
     foreach ($properties as $propertyName => $property) {
         if ($property->getType() == 'location') {
             $propertyInfo = $property->type->property_info;
             if ($propertyInfo['enable_search_by_radius'] == 1) {
                 if (!isset($criteria['system'][$propertyName])) {
                     $value = array('value' => '', 'radius' => '10');
                     $criterion = SJB_SearchCriterion::getCriterionByType('location');
                     $criterion->setProperty($property);
                     $criterion->setPropertyName($propertyName);
                     $criterion->setValue($value);
                     $criteria['system'][$propertyName][] = $criterion;
                 }
             }
         }
     }
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $form_fields = $search_form_builder->getFormFieldsInfo();
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $template = SJB_Request::getVar('form_template', 'search_form.tpl');
     $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listing_type_id);
     $formBuilder->setChargedTemplateProcessor($tp);
     if ($template == 'quick_search.tpl') {
         $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('Location');
         if ($fieldSID) {
             $fields = SJB_ListingFieldManager::getFieldInfoBySID($fieldSID);
             if (!empty($fields['fields'])) {
                 foreach ($fields['fields'] as $field) {
                     $form_fields[$fields['id'] . '_' . $field['id']] = $field;
                 }
             }
             $tp->assign('locationFields', array($fields));
         }
     }
     $tp->assign('form_fields', $form_fields);
     $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
     $tp->display($template);
 }
Пример #22
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('template', 'manage_invoices.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl');
     $action = SJB_Request::getVar('action_name');
     if (!empty($action)) {
         $invoicesSIDs = SJB_Request::getVar('invoices', array());
         $_REQUEST['restore'] = 1;
         switch ($action) {
             case 'paid':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSID);
                     $userSID = $invoice->getPropertyValue('user_sid');
                     if (SJB_UserManager::isUserExistsByUserSid($userSID)) {
                         $items = $invoice->getPropertyValue('items');
                         $productSIDs = $items['products'];
                         foreach ($productSIDs as $key => $productSID) {
                             if ($productSID != -1) {
                                 if (SJB_ProductsManager::isProductExists($productSID)) {
                                     $productInfo = $invoice->getItemValue($key);
                                     $listingNumber = $productInfo['qty'];
                                     $contract = new SJB_Contract(array('product_sid' => $productSID, 'numberOfListings' => $listingNumber, 'is_recurring' => $invoice->isRecurring()));
                                     $contract->setUserSID($userSID);
                                     $contract->setPrice($items['amount'][$key]);
                                     if ($contract->saveInDB()) {
                                         SJB_ListingManager::activateListingsAfterPaid($userSID, $productSID, $contract->getID(), $listingNumber);
                                         SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $userSID);
                                         $bannerInfo = $productInfo['banner_info'];
                                         if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) {
                                             $bannersObj = new SJB_Banners();
                                             $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $userSID, $contract->getID());
                                             $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                             SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup);
                                         }
                                         if ($contract->isFeaturedProfile()) {
                                             SJB_UserManager::makeFeaturedBySID($userSID);
                                         }
                                         if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) {
                                             SJB_Notifications::sendSubscriptionActivationLetter($userSID, $productInfo);
                                         }
                                     }
                                 }
                             } else {
                                 $type = SJB_Array::getPath($items, 'custom_info/' . $key . '/type');
                                 switch ($type) {
                                     case 'featuredListing':
                                         $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id');
                                         SJB_ListingManager::makeFeaturedBySID($listingId);
                                         break;
                                     case 'priorityListing':
                                         $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id');
                                         SJB_ListingManager::makePriorityBySID($listingId);
                                         break;
                                     case 'activateListing':
                                         $listingsIds = explode(",", SJB_Array::getPath($items, 'custom_info/' . $key . '/listings_ids'));
                                         foreach ($listingsIds as $listingId) {
                                             SJB_ListingManager::activateListingBySID($listingId);
                                         }
                                         break;
                                 }
                             }
                         }
                         SJB_Statistics::addStatisticsFromInvoice($invoice);
                     }
                     $total = $invoice->getPropertyValue('total');
                     if ($total > 0) {
                         $gatewayID = $invoice->getPropertyValue('payment_method');
                         $gatewayID = isset($gatewayID) ? $gatewayID : 'cash_payment';
                         $transactionId = md5($invoiceSID . $gatewayID);
                         $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoiceSID, 'amount' => $total, 'payment_method' => $gatewayID, 'user_sid' => $invoice->getPropertyValue('user_sid'));
                         $transaction = new SJB_Transaction($transactionInfo);
                         SJB_TransactionManager::saveTransaction($transaction);
                     }
                     SJB_InvoiceManager::markPaidInvoiceBySID($invoiceSID);
                     SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-invoices/");
                 break;
             case 'unpaid':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     SJB_InvoiceManager::markUnPaidInvoiceBySID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/');
                 break;
             case 'delete':
                 foreach (array_keys($invoicesSIDs) as $invoiceSID) {
                     SJB_InvoiceManager::deleteInvoiceBySID($invoiceSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/');
                 break;
             default:
                 unset($_REQUEST['restore']);
                 break;
         }
     }
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $invoice = new SJB_Invoice(array());
     $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserDBManager::getUserSIDsLikeSearchString'));
     $searchFormBuilder = new SJB_SearchFormBuilder($invoice);
     $criteriaSaver = new SJB_InvoiceCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria());
     }
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice);
     $searchFormBuilder->setCriteria($criteria);
     $searchFormBuilder->registerTags($tp);
     $tp->display($searchTemplate);
     /********************** S O R T I N G *********************/
     $paginator = new SJB_InvoicePagination();
     $innerJoin = false;
     if ($paginator->sortingField == 'username') {
         $innerJoin = array('users' => array('sort_field' => array(36 => array('FirstName', 'LastName'), 41 => 'CompanyName'), 'join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'invoices', 'join' => 'LEFT JOIN'));
     }
     $searcher = new SJB_InvoiceSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $innerJoin);
     $foundInvoices = array();
     $foundInvoicesInfo = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases);
         if (empty($foundInvoices) && $paginator->currentPage != 1) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/?page=1');
         }
         $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $foundInvoices = $criteriaSaver->getObjectsFromSession();
     }
     foreach ($foundInvoices as $id => $invoice) {
         $subUserSID = $invoice->getPropertyValue('subuser_sid');
         if ($subUserSID) {
             $subUserInfo = SJB_UserManager::getUserInfoBySID($subUserSID);
             $parentInfo = SJB_UserManager::getUserInfoBySID($subUserInfo['parent_sid']);
             $username = $parentInfo['CompanyName'];
         } else {
             $userSID = $invoice->getPropertyValue('user_sid');
             $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
             if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'Employer') {
                 $username = $userInfo['CompanyName'];
             } else {
                 if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'JobSeeker') {
                     $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'];
                 } else {
                     $username = $userInfo['username'];
                 }
             }
         }
         $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID()));
         $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username));
         $foundInvoices[$id] = $invoice;
         $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID());
         $foundInvoicesInfo[$invoice->getSID()]['userExists'] = !empty($username) ? 1 : 0;
     }
     /****************************************************************/
     $paginator->setItemsCount($searcher->getAffectedRows());
     $form_collection = new SJB_FormCollection($foundInvoices);
     $form_collection->registerTags($tp);
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign("found_invoices", $foundInvoicesInfo);
     $tp->display($template);
 }
Пример #23
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     /********** A C T I O N S   W I T H   T R A N S A C T I O N S **********/
     $action = SJB_Request::getVar('action_name', SJB_Request::getVar('action', false));
     $transactions_sids = SJB_Request::getVar('transactions', false);
     if ($action && $transactions_sids) {
         $_REQUEST['restore'] = 1;
         if ($action == 'delete') {
             // DELETE
             foreach ($transactions_sids as $transaction_sid => $value) {
                 SJB_TransactionManager::deleteTransactionBySID($transaction_sid);
             }
         } else {
             unset($_REQUEST['restore']);
         }
     }
     /**********  D E F A U L T   V A L U E S   F O R   S E A R C H  **********/
     $_REQUEST['action'] = 'filter';
     $i18n = SJB_ObjectMother::createI18N();
     if (!isset($_REQUEST['date'])) {
         $_REQUEST['date']['not_less'] = $i18n->getDate(date('Y-m-d', time() - 30 * 24 * 60 * 60));
         $_REQUEST['date']['not_more'] = $i18n->getDate(date('Y-m-d', time() + 24 * 60 * 60));
     } else {
         if (!$i18n->isValidDate($_REQUEST['date']['not_less']) && !empty($_REQUEST['date']['not_less'])) {
             $errors[] = 'INVALID_PERIOD_FROM';
         }
         if (!$i18n->isValidDate($_REQUEST['date']['not_more']) && !empty($_REQUEST['date']['not_more'])) {
             $errors[] = 'INVALID_PERIOD_TO';
         }
     }
     /************************ S E A R C H   F O R M ***************************/
     $transaction = new SJB_Transaction();
     $transaction->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserManager::getUserSIDsLikeUsername'));
     $search_form_builder = new SJB_SearchFormBuilder($transaction);
     $criteria_saver = new SJB_TransactionCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $transaction);
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $tp->display('payment_form.tpl');
     /********************  S E A R C H  ************************/
     $paginator = new SJB_TransactionHistoryPagination();
     $searcher = new SJB_TransactionSearcher($paginator);
     if (SJB_Request::getVar('action', '') == 'filter') {
         $transactions = $searcher->getObjectsByCriteria($criteria, $aliases);
         if (empty($transactions) && $paginator->currentPage != 1) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/payments/?page=1');
         }
         $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $transactions = $criteria_saver->getObjectsFromSession();
     }
     $paginator->setItemsCount($searcher->getAffectedRows());
     $found_trans = array();
     $found_trans_sids = array();
     foreach ($transactions as $transaction) {
         $user_sid = $transaction->getPropertyValue('user_sid');
         $username = SJB_UserManager::getUserNameByUserSID($user_sid);
         $transaction->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username));
         $found_trans[$transaction->getSID()] = $transaction;
         $found_trans_sids[$transaction->getSID()] = $transaction->getSID();
     }
     $sorted_found_trans_sids = $found_trans_sids;
     $form_collection = new SJB_FormCollection($found_trans);
     $form_collection->registerTags($tp);
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign('errors', $errors);
     $tp->assign('found_transactions_sids', $sorted_found_trans_sids);
     $tp->display('payments.tpl');
 }
Пример #24
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;
     }
 }