public static function buildCriteriaFields($criteria) { $criteria_fields = array(); foreach ($criteria as $criteria_name => $criteria_values) { $criteria_fields[$criteria_name] = SJB_SavedSearches::buildCriterionField($criteria_name, $criteria_values); } return $criteria_fields; }
public static function deleteUserById($id) { $user = SJB_UserManager::getObjectBySID($id); if (empty($user)) { SJB_UserDBManager::deleteEmptyUsers(); return true; } SJB_Event::dispatch('onBeforeUserDelete', $user); $listings = SJB_ListingDBManager::getListingsSIDByUserSID($id); SJB_ListingManager::deleteListingBySID($listings); $subusers = self::getSubusers($id); foreach ($subusers as $subuser) { self::deleteUserById($subuser['sid']); } // delete user logo file $pictProp = $user->getProperty('Logo'); if ($pictProp) { SJB_UploadFileManager::deleteUploadedFileByID($pictProp->value); } $videoProp = $user->getProperty('video'); if ($videoProp) { SJB_UploadFileManager::deleteUploadedFileByID($videoProp->value); } // delete social info $socialReference = SJB_SocialPlugin::getProfileSocialID($user->getSID()); if ($socialReference) { SJB_SocialPlugin::deleteProfileSocialInfoByReference($socialReference); } $result = SJB_UserDBManager::deleteUserById($id) && SJB_ContractManager::deleteAllContractsByUserSID($id) && SJB_Rating::deleteRatingByUserSID($id); SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_USERS)); return $result && SJB_SavedSearches::deleteUserSearchesFromDB($id); }
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']; } } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $isAlert = $enableNotify = isset($_REQUEST["alert"]); $tp->assign('is_alert', $isAlert); if (SJB_UserManager::isUserLoggedIn()) { $cu = SJB_UserManager::getCurrentUser(); if ($cu->isSubuser()) { $current_user_info = $cu->getSubuserInfo(); } else { $current_user_info = SJB_UserManager::getCurrentUserInfo(); } $criteria_saver = new SJB_ListingCriteriaSaver(SJB_Request::getVar("searchId", "")); $requested_data = $criteria_saver->getCriteria(); if (isset($requested_data['listing_type'])) { $current_listing_type = array_pop($requested_data['listing_type']); } else { $current_listing_type = ''; if (isset($requested_data['listing_type_sid'])) { $listing_type_sid = array_pop($requested_data['listing_type_sid']); $current_listing_type = SJB_ListingTypeManager::getListingTypeIDBySID($listing_type_sid); } } $errors = array(); if (!$isAlert && !SJB_Acl::getInstance()->isAllowed('save_searches')) { $errors[] = "DENIED_SAVE_JOB_SEARCH"; } elseif ($isAlert && !SJB_Acl::getInstance()->isAllowed('use_' . trim($current_listing_type) . '_alerts')) { $errors[] = "DENIED_SAVE_JOB_SEARCH"; } switch (SJB_Request::getVar("action")) { case 'edit': unset($_GET['action']); if (isset($_GET['id_saved'])) { $id_saved = $_GET['id_saved']; unset($_GET['id_saved']); $errors = array(); SJB_SavedSearches::updateSearchOnDB($_GET, $id_saved, $current_user_info['sid'], 0); if (!empty($errors)) { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } else { $url = SJB_System::getSystemSettings('SITE_URL') . "/saved-searches/"; if ($isAlert) { $url = SJB_System::getSystemSettings('SITE_URL') . "/job-alerts/"; } $tp->assign("url", $url); $tp->display("save_search_success.tpl"); } } break; case 'save': $search_name = SJB_Request::getVar("search_name"); $errors = array(); $criteria_saver = new SJB_ListingCriteriaSaver(SJB_Request::getVar("searchId", "")); $requested_data = $criteria_saver->getCriteria(); if (is_array($criteria_saver->order_info)) { $requested_data = array_merge($requested_data, $criteria_saver->order_info); } $requested_data['listings_per_page'] = $criteria_saver->listings_per_page; $emailFrequency = SJB_Request::getVar("email_frequency", 'daily'); SJB_SavedSearches::saveSearchOnDB($requested_data, $search_name, $current_user_info['sid'], $enableNotify, $isAlert, $emailFrequency); if (!empty($errors)) { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } else { if (isset($_REQUEST['url'])) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . $_REQUEST['url'] . "?alert=added"); } $tp->display("save_search_success.tpl"); } break; default: if (!empty($errors)) { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } else { $tp->assign("searchId", SJB_Request::getVar("searchId", "")); $tp->assign("listing_type_id", SJB_Session::getValue('listing_type_id')); $tp->display("save_search_form.tpl"); } break; } } else { $tp->assign("return_url", base64_encode(SJB_Navigator::getURIThis())); $tp->assign("ajaxRelocate", true); $tp->display("../users/login.tpl"); } }
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; } }
public function execute() { // xml-feeds table $feedsTable = 'listing_feeds'; $feed_mimetype = 'text/xml'; $feedId = SJB_Request::getVar('feedId', ''); $searchSID = SJB_Request::getVar('searchSID', false); $feed = SJB_DB::query("SELECT * FROM {$feedsTable} WHERE `sid` = ?n", $feedId); $feed = array_pop($feed); if (empty($feed) && $searchSID === false) { $tp = SJB_System::getTemplateProcessor(); $errors[] = 'RSS is not exists'; $template = 'feed_error.tpl'; $tp->assign('errors', $errors); } else { if ($searchSID) { $template = 'feed_saved_search.tpl'; $count_listings = SJB_Request::getVar('count_listings', 10); if ($count_user_defined = SJB_Request::getVar('count_listings', false, 'GET')) { $count_listings = $count_user_defined; } // get saved search results for feed $searches = SJB_SavedSearches::getSavedJobAlertFromDBBySearchSID($searchSID); $searches = array_pop($searches); $listing_type_id = null; foreach ($searches['data']['listing_type'] as $val) { $listing_type_id = $val; break; } $searches['data']['default_sorting_field'] = 'activation_date'; $searches['data']['default_sorting_order'] = 'DESC'; $searches['data']['default_listings_per_page'] = $count_listings; $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listing_type_id); $tp = $searchResultsTP->getChargedTemplateProcessor(); // TODO: нужно абстрагировать получение переменной из шаблонизатора $tp->assign("listings", $tp->getVariable('listings')->value); $tp->assign('listing_type_id', $listing_type_id); $tp->assign("search_name", $searches['name']); $tp->assign("feed", $feed); $tp->assign("query_string", htmlspecialchars($_SERVER['QUERY_STRING'])); $tp->assign("lastBuildDate", date('D, d M Y H:i:s')); } else { $template = $feed['template']; $count_listing = $feed['count']; $feed_type = $feed['type']; $feed_mimetype = $feed['mime_type']; if ($count_listing == 0) { $count_listing = 1000000; } $listing_type = SJB_ListingTypeManager::getListingTypeIDBySID($feed_type); $searches['data']['listing_type']['equal'] = $listing_type; $searches['data']['default_sorting_field'] = 'activation_date'; $searches['data']['default_sorting_order'] = 'DESC'; $searches['data']['default_listings_per_page'] = $count_listing; $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listing_type); $tp = $searchResultsTP->getChargedTemplateProcessor(); $tp->assign('feed', $feed); $tp->assign('count_listing', $count_listing); $tp->assign('lastBuildDate', date('D, d M Y H:i:s')); } } for ($i = 0; $i < ob_get_level(); $i++) { ob_end_clean(); } header('Content-Type: ' . $feed_mimetype); $tp->display($template); exit; }
private function prepareTplVarsForAlert() { $savedSearches = SJB_SavedSearches::getAutoNotifySavedSearchesForET(); if (!empty($savedSearches)) { $this->tp->assign('searchTplVars', $this->echoVars($savedSearches)); } }