Example #1
0
 public static function updateSettings($settings)
 {
     if (!self::isLoaded()) {
         self::loadSettings();
     }
     foreach ($settings as $name => $value) {
         if ($name == 'disable_bots') {
             $ds = DIRECTORY_SEPARATOR;
             $path = SJB_BASE_DIR . "system{$ds}cache{$ds}agents_bots.txt";
             file_put_contents($path, $value);
         } else {
             // convert array value to string for multilist
             if (is_array($value)) {
                 $value = implode(',', $value);
             }
             if (self::getValue($name, false) === false) {
                 self::addSetting($name, $value);
             } else {
                 SJB_DB::query("UPDATE `settings` SET `value` = ?s WHERE `name` = ?s", $value, $name);
             }
             if ($name == 'enableBrowseByCounter' && $value && !self::getValue('enableBrowseByCounter')) {
                 self::$settings[$name] = $value;
                 SJB_BrowseDBManager::rebuildBrowses();
             } else {
                 self::$settings[$name] = $value;
             }
         }
     }
 }
Example #2
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $listingTypeSID = isset($_REQUEST['sid']) ? $_REQUEST['sid'] : null;
     if (!is_null($listingTypeSID)) {
         $form_submitted = SJB_Request::getVar('action', '');
         $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID);
         $approveSettingChanged = $listing_type_info['waitApprove'] != SJB_Request::getVar('waitApprove');
         $listing_type_info = array_merge($listing_type_info, $_REQUEST);
         $listingType = new SJB_ListingType($listing_type_info);
         $listingType->setSID($listingTypeSID);
         $edit_form = new SJB_Form($listingType);
         $listingTypeEmailAlert = $listingType->getPropertyValue('email_alert');
         if (empty($listingTypeEmailAlert)) {
             $listingType->setPropertyValue('email_alert', 0);
         }
         $listingTypeEmailAlertForGuests = $listingType->getPropertyValue('guest_alert_email');
         if (empty($listingTypeEmailAlertForGuests)) {
             $listingType->setPropertyValue('guest_alert_email', 0);
         }
         $errors = array();
         if ($form_submitted && $edit_form->isDataValid($errors)) {
             SJB_Breadcrumbs::updateBreadcrumbsByListingTypeSID($listingTypeSID, $listingType->getPropertyValue('name'));
             SJB_PageManager::updatePagesByListingTypeSID($listingTypeSID, $listingType->getPropertyValue('name'));
             SJB_ListingTypeManager::saveListingType($listingType);
             if ($approveSettingChanged) {
                 SJB_BrowseDBManager::rebuildBrowses();
             }
             if ($form_submitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/listing-types/');
             }
         }
         $template_processor->assign('errors', $errors);
         $template_processor->assign('listing_type_sid', $listingTypeSID);
         $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeSID);
         $listing_fields = array();
         $listing_field_sids = array();
         foreach ($listing_fields_info as $listing_field_info) {
             if ($listing_field_info['type'] == 'logo') {
                 continue;
             }
             $listing_field = new SJB_ListingField($listing_field_info);
             $listing_field->setSID($listing_field_info['sid']);
             $listing_fields[] = $listing_field;
             $listing_field_sids[] = $listing_field_info['sid'];
         }
         $edit_form->registerTags($template_processor);
         $template_processor->assign("listing_type_info", $listing_type_info);
         $template_processor->assign("form_fields", $edit_form->getFormFieldsInfo());
         $template_processor->display("edit_listing_type.tpl");
         $form_collection = new SJB_FormCollection($listing_fields);
         $form_collection->registerTags($template_processor);
         $template_processor->assign("listing_field_sids", $listing_field_sids);
         $template_processor->display("listing_type_fields.tpl");
     }
 }
Example #3
0
 public function isAccessible()
 {
     $browseUrl = SJB_Request::getVar('browseUrl', false);
     if ($browseUrl) {
         $parameters = SJB_BrowseDBManager::getBrowseParametersByUri($browseUrl);
         $this->parameters = array_merge($_REQUEST, unserialize($parameters));
     } else {
         $this->parameters = $_REQUEST;
     }
     $listingTypeId = SJB_Request::getVar('listing_type_id', '');
     $browseManager = SJB_ObjectMother::createBrowseManager($listingTypeId, $this->parameters);
     $params = $browseManager->getParams();
     if (empty($params)) {
         return true;
     }
     $this->setPermissionLabel('view_' . strtolower($listingTypeId) . '_search_results');
     return parent::isAccessible();
 }
Example #4
0
 public static function setListingApprovalStatus($listingSids, $status, $updateBrowsePages = true)
 {
     $statusValues = array('pending', 'approved', 'rejected');
     if (in_array($status, $statusValues)) {
         if (!is_array($listingSids)) {
             $listingSids = array($listingSids);
         }
         if ($updateBrowsePages) {
             SJB_BrowseDBManager::deleteListings($listingSids);
         }
         switch ($status) {
             case 'pending':
                 // set status to 'pending' and clear reject reason
                 SJB_DB::queryExec("UPDATE `listings` SET `status`=?s, `reject_reason` = '' WHERE `sid` IN (?l)", $status, $listingSids);
                 break;
             case 'approved':
                 SJB_DB::queryExec("UPDATE `listings` SET `status`=?s WHERE `sid` IN (?l)", $status, $listingSids);
                 break;
             case 'rejected':
                 $rejectReason = $_REQUEST['rejectReason'] != '' ? $_REQUEST['rejectReason'] : 'rejected with no reason';
                 SJB_DB::queryExec("UPDATE `listings` SET `status`=?s, `reject_reason` = ?s WHERE `sid` IN (?l)", $status, $rejectReason, $listingSids);
                 break;
         }
         SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_LISTINGS));
         if ($updateBrowsePages && $status == 'approved') {
             SJB_BrowseDBManager::addListings($listingSids);
         }
     }
 }
Example #5
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null;
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $productSID = SJB_Request::getVar('product_sid', 0);
     $errors = array();
     if ($listingTypeID && $productSID) {
         $acl = SJB_Acl::getInstance();
         $resource = 'post_' . strtolower($listingTypeID);
         if (!$acl->isAllowed($resource, $productSID, 'product')) {
             $errors[] = 'You cannot import listings of this type under the selected product';
         }
     }
     if (!empty($file_info)) {
         $extension = SJB_Request::getVar('file_type');
         if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) {
             $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true;
         }
     }
     if (empty($file_info) || $file_info['error'] || $errors) {
         if (isset($file_info['error']) && $file_info['error'] > 0) {
             $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1;
         }
         $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
         $products = SJB_ProductsManager::getProductsByProductType('post_listings');
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('listing_types', $listing_types);
         $tp->assign('products', $products);
         $tp->assign('errors', $errors);
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->display('import_listings.tpl');
     } else {
         $i18n = SJB_I18N::getInstance();
         $csv_delimiter = SJB_Request::getVar('csv_delimiter', null);
         $activeStatus = SJB_Request::getVar('active', 0);
         $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d'));
         $activationDate = $i18n->getInput('date', $activationDate);
         $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null);
         $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
         if (empty($productInfo['listing_duration'])) {
             $expirationDate = '';
         } else {
             $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days');
             $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp));
         }
         $extension = $_REQUEST['file_type'];
         if ($extension == 'xls') {
             $import_file = new SJB_ImportFileXLS($file_info);
         } elseif ($extension == 'csv') {
             $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter);
         }
         $import_file->parse($encodingFromCharset);
         $listing = $this->CreateListing(array(), $listingTypeID);
         $imported_data = $import_file->getData();
         $isFileImported = true;
         $count = 0;
         $addedListingsSids = array();
         $nonExistentUsers = array();
         foreach ($imported_data as $key => $importedColumn) {
             if ($key == 1) {
                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                 continue;
             }
             if (!$importedColumn) {
                 continue;
             }
             $count++;
             $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn);
             $doc = new DOMDocument();
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $doc->loadXML($listingInfo[$property->id]);
                     $results = $doc->getElementsByTagName($property->id . 's');
                     $listingInfo[$property->id] = array();
                     foreach ($results as $complexparent) {
                         $i = 1;
                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                             $resultXML = simplexml_import_dom($result);
                             foreach ($childFields as $childField) {
                                 if (isset($resultXML->{$childField}['id'])) {
                                     $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']);
                                 }
                             }
                             $i++;
                         }
                     }
                 } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) {
                     $value = $listingInfo[$property->id];
                     $listingInfo[$property->id] = array();
                     $listingInfo[$property->id]['value'] = $value;
                     $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency();
                     $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code'];
                     $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode);
                     $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : '';
                     if (isset($listingInfo[$property->id . "Currency"])) {
                         unset($listingInfo[$property->id . "Currency"]);
                     }
                 } elseif ($property->getType() == 'location') {
                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode');
                     $locationFieldAdded = array();
                     foreach ($locationFields as $locationField) {
                         if (array_key_exists($locationField, $listingInfo)) {
                             switch ($locationField) {
                                 case $property->id . '.Country':
                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 case $property->id . '.State':
                                     $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 default:
                                     $value = $listingInfo[$locationField];
                                     break;
                             }
                             $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                         }
                     }
                     if ($property->id == 'Location') {
                         $locationFields = array('Country', 'State', 'City', 'ZipCode');
                         foreach ($locationFields as $locationField) {
                             if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                 switch ($locationField) {
                                     case 'Country':
                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     case 'State':
                                         $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     default:
                                         $value = $listingInfo[$locationField];
                                         break;
                                 }
                                 $listingInfo[$property->id][$locationField] = $value;
                             }
                         }
                     }
                 }
             }
             $listing = $this->CreateListing($listingInfo, $listingTypeID);
             $pictures = array();
             if (isset($listingInfo['pictures'])) {
                 $listing->addPicturesProperty();
                 $explodedPictures = explode(';', $listingInfo['pictures']);
                 foreach ($explodedPictures as $picture) {
                     if (!empty($picture)) {
                         $pictures[] = $picture;
                     }
                 }
                 $listing->setPropertyValue('pictures', count($pictures));
             }
             $listing->addActiveProperty($activeStatus);
             $listing->addActivationDateProperty($activationDate);
             $listing->addExpirationDateProperty($expirationDate);
             SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid);
             $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID));
             $listing->setPropertyValue('access_type', 'everyone');
             $listing->setPropertyValue('status', 'approved');
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'tree' && $property->value !== '') {
                     try {
                         $treeImportHelper = new SJB_FieldTreeImportHelper($property->value);
                         $treeValues = $treeImportHelper->parseAndGetValues();
                         $listing->setPropertyValue($property->id, $treeValues);
                         $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues;
                     } catch (Exception $e) {
                         $listing->setPropertyValue($property->id, '');
                         $listing->details->properties[$property->id]->type->property_info['value'] = '';
                         SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage());
                     }
                 } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) {
                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1);
                     } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2);
                     } else {
                         $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                     }
                     //put empty if not valid email or url
                     $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings'];
                 } elseif ($property->getType() == 'complex') {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $complexChildValues = $property->value;
                     foreach ($childFields as $childField) {
                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                             $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                             if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) {
                                 $isFileImported = false;
                             }
                         }
                         if ($property->type->complex->details->properties[$childField['id']]->value == null) {
                             $property->type->complex->details->properties[$childField['id']]->value = array(1 => '');
                             $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => '');
                         }
                     }
                 }
                 // The import of files at import of listings
                 if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') {
                     $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                     if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) {
                         $isFileImported = false;
                     }
                 }
             }
             if ($non_existed_values_flag == 'add') {
                 $this->UpdateListValues($listing);
             }
             if ($listing->getUserSID()) {
                 SJB_ListingManager::saveListing($listing);
                 $listingSid = $listing->getSID();
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid);
                 SJB_ListingManager::activateListingBySID($listingSid, false);
                 if (!$this->fillGallery($listingSid, $pictures)) {
                     $isFileImported = false;
                 }
                 $addedListingsSids[] = $listingSid;
             } else {
                 $nonExistentUsers[] = $listingInfo['username'];
                 $count--;
             }
         }
         SJB_BrowseDBManager::addListings($addedListingsSids);
         SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids));
         if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) {
             SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'));
         }
         $tp->assign('imported_listings_count', $count);
         $tp->assign('nonExistentUsers', $nonExistentUsers);
         $tp->display('import_listings_result.tpl');
     }
 }
Example #6
0
 public function execute()
 {
     $formToken = SJB_Request::getVar('form_token');
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('form_token', $formToken);
     $post_max_size_orig = ini_get('post_max_size');
     $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
     // get post_max_size in bytes
     $val = trim($post_max_size_orig);
     $tmp = substr($val, strlen($val) - 1);
     $tmp = strtolower($tmp);
     switch ($tmp) {
         case 'g':
             $val *= 1024;
             break;
         case 'm':
             $val *= 1024;
             break;
         case 'k':
             $val *= 1024;
             break;
     }
     $post_max_size = $val;
     $errors = array();
     if (SJB_Request::getVar('from-preview', false, 'POST') && !SJB_Request::getVar('action_add', false, 'POST')) {
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $previewListingId = SJB_Session::getValue('preview_listing_sid');
         if ($previewListingId && SJB_ListingManager::isListingExists($previewListingId)) {
             $listingId = $previewListingId;
         }
     } else {
         $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int');
     }
     $template = SJB_Request::getVar('edit_template', 'edit_listing.tpl');
     $filename = SJB_Request::getVar('filename', false);
     if ($filename) {
         SJB_UploadFileManager::openFile($filename, $listingId);
         // if file not found - set error here
         $errors['NO_SUCH_FILE'] = true;
     }
     if (empty($_POST) && $server_content_length > $post_max_size) {
         $errors['MAX_FILE_SIZE_EXCEEDED'] = 1;
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $tp->assign('post_max_size', $post_max_size_orig);
     }
     $current_user = SJB_UserManager::getCurrentUser();
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
     // for listing preview
     $formSubmittedFromPreview = false;
     if (empty($listingInfo)) {
         $listingId = SJB_Session::getValue('preview_listing_sid');
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
         if (!empty($listingInfo)) {
             // if on preview page 'POST' button was pressed
             $formSubmittedFromPreview = SJB_Request::getVar('action_add', false, 'POST') && SJB_Request::getVar('from-preview', false, 'POST');
             if ($formSubmittedFromPreview) {
                 $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
                 $properties = $listing->getProperties();
                 foreach ($properties as $fieldID => $property) {
                     switch ($property->getType()) {
                         case 'date':
                             if (!empty($listingInfo[$fieldID])) {
                                 $listingInfo[$fieldID] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID]);
                             }
                             break;
                         case 'complex':
                             $complex = $property->type->complex;
                             $complexProperties = $complex->getProperties();
                             foreach ($complexProperties as $complexfieldID => $complexProperty) {
                                 if ($complexProperty->getType() == 'date') {
                                     $values = $complexProperty->getValue();
                                     foreach ($values as $index => $value) {
                                         if (!empty($listingInfo[$fieldID][$complexfieldID][$index])) {
                                             $listingInfo[$fieldID][$complexfieldID][$index] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID][$complexfieldID][$index]);
                                         }
                                     }
                                 }
                             }
                             break;
                     }
                 }
             }
         } else {
             $listingId = null;
             SJB_Session::unsetValue('preview_listing_sid');
         }
     }
     // if preview button was pressed
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (SJB_UserManager::isUserLoggedIn()) {
         if ($listingInfo['user_sid'] != $current_user->getID()) {
             $errors['NOT_OWNER_OF_LISTING'] = $listingId;
         } elseif (!is_null($listingInfo)) {
             $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingInfo['listing_type_sid']);
             $form_is_submitted = SJB_Request::getVar('action', '') == 'save_info' || SJB_Request::getVar('action', '') == 'add' || $isPreviewListingRequested || $formSubmittedFromPreview;
             if (!$form_is_submitted && !SJB_Request::getVar('from-preview', false, 'POST')) {
                 SJB_Session::unsetValue('previewListingId');
                 SJB_Session::unsetValue('preview_listing_sid_or');
             }
             // fill listing from an array of social data if allowed
             $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listingInfo['listing_type_sid']);
             $listingTypeID = $listing_type_info['id'];
             $aAutoFillData = array('formSubmitted' => $form_is_submitted, 'listingTypeID' => $listingTypeID);
             SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
             $listingInfo = array_merge($listingInfo, $_REQUEST);
             $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
             $listing->deleteProperty('ListingLogo');
             $listing->deleteProperty('featured');
             $listing->deleteProperty('priority');
             $listing->deleteProperty('reject_reason');
             $listing->deleteProperty('status');
             $list_emp_ids = SJB_Request::getVar('list_emp_ids');
             $listing->setSID($listingId);
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID());
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $value = SJB_Request::getVar('screening_questionnaire');
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true));
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             //--->CLT-2637
             $properties = $listing->getProperties();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page = array_merge(SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']), $listing_fields_by_page);
             }
             foreach ($properties as $property) {
                 if (!in_array($property->getID(), array_keys($listing_fields_by_page))) {
                     $listing->deleteProperty($property->getID());
                 }
             }
             //--->CLT-2637
             // if user is not registered using linkedin , delete linkedin sync property, also if sync is turned off in admin part
             $aAutoFillData = array('oListing' => &$listing, 'userSID' => $current_user->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo);
             SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
             $listing_edit_form = new SJB_Form($listing);
             $listing_edit_form->registerTags($tp);
             $extraInfo = $listingInfo['product_info'];
             if ($extraInfo) {
                 $extraInfo = unserialize($extraInfo);
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $listingSidForPictures = SJB_Session::getValue('preview_listing_sid_or') ? SJB_Session::getValue('preview_listing_sid_or') : $listingId;
                 $tp->assign('pic_limit', $numberOfPictures);
                 $tp->assign('listingSidForPictures', $listingSidForPictures);
             }
             if ($form_is_submitted) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
             }
             $field_errors = array();
             if ($form_is_submitted && ($formSubmittedFromPreview || $listing_edit_form->isDataValid($field_errors))) {
                 $or_listing_id = SJB_Session::getValue('preview_listing_sid_or');
                 /* preview listing */
                 if ($isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') != $listing->getSID()) {
                     SJB_Session::setValue('preview_listing_sid_or', $listing->getSID());
                     $listing->setSID(null);
                 } elseif (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listing->getSID() && $or_listing_id && $or_listing_id != $listingId) {
                     $listing->setSID($or_listing_id);
                 }
                 if ($isPreviewListingRequested) {
                     $listing->addProperty(array('id' => 'preview', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 } else {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 }
                 if ($isPreviewListingRequested) {
                     $listing->product_info = $extraInfo;
                     if (SJB_Session::getValue('previewListingId')) {
                         $listing->setSID(SJB_Session::getValue('previewListingId'));
                     }
                 } else {
                     SJB_BrowseDBManager::deleteListings($listing->getID());
                 }
                 $listingSidsForCopy = array('filesFrom' => $listingId, 'picturesFrom' => $isPreviewListingRequested && (!$or_listing_id || $or_listing_id === $listingId) ? $listingId : null);
                 SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                 if (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listingId && $or_listing_id && $or_listing_id != $listingId) {
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_ListingManager::deleteListingBySID($listingId);
                 }
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listing->getSID());
                 if ($listingInfo['active']) {
                     SJB_ListingManager::activateListingKeywordsBySID($listing->getSID());
                     SJB_BrowseDBManager::addListings($listing->getID());
                 }
                 // >>> SJB-1197
                 // SET VALUES FROM TEMPORARY SESSION STORAGE
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken);
                 if (is_array($tempFieldsData)) {
                     foreach ($tempFieldsData as $fieldId => $fieldData) {
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldData['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                     }
                     SJB_ListingManager::saveListing($listing);
                     // recreate form object for saved listing
                     // it fix display of complex file fields
                     $listing = SJB_ListingManager::getObjectBySID($listing->getSID());
                     $listing->deleteProperty('featured');
                     $listing->deleteProperty('priority');
                     $listing->deleteProperty('reject_reason');
                     $listing->deleteProperty('status');
                     $listing_edit_form = new SJB_Form($listing);
                     $listing_edit_form->registerTags($tp);
                 }
                 // <<< SJB-1197
                 if ($isPreviewListingRequested) {
                     SJB_Session::setValue('previewListingId', $listing->getSID());
                 }
                 /* preview listing */
                 if ($isPreviewListingRequested) {
                     $listing->setUserSID($current_user->getSID());
                     SJB_Session::setValue('preview_listing_sid', $listing->getSID());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/');
                 } else {
                     /* normal */
                     $listingSid = $listing->getSID();
                     SJB_Event::dispatch('listingEdited', $listingSid);
                     $tp->assign('display_preview', 1);
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-' . strtolower($listingTypeID) . '-details/' . $listing->getSID() . '/');
                 }
             }
             $listing->deleteProperty('access_list');
             $tp->assign('form_is_submitted', $form_is_submitted);
             $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $form_fields = $listing_edit_form->getFormFieldsInfo();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                 foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) {
                     if (!$listing->propertyIsSet($field)) {
                         unset($listing_fields_by_page[$page['page_name']][$field]);
                     }
                 }
             }
             // delete sync fields from posting pages that are not in array $form_fields
             $aAutoFillData = array('listing_fields_by_page' => &$listing_fields_by_page, 'pages' => &$pages, 'form_fields' => $form_fields);
             SJB_Event::dispatch('SocialSynchronizationFieldsOnPostingPages', $aAutoFillData);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             if (!isset($listing_structure['access_type'])) {
                 $listing_structure['access_type'] = 'everyone';
             }
             $listing_access_list = SJB_ListingManager::getListingAccessList($listingId, $listing->getPropertyValue('access_type'));
             $tp->assign('contract_id', $listingInfo['contract_id']);
             $tp->assign('extraInfo', $extraInfo);
             $tp->assign('listing', $listing_structure);
             $tp->assign('pages', $listing_fields_by_page);
             $tp->assign('countPages', count($listing_fields_by_page));
             $tp->assign('field_errors', $field_errors);
             $tp->assign('listing_access_list', $listing_access_list);
             $tp->assign('listingTypeID', $listingTypeID);
             $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
             // only for Resume listing types
             $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $current_user->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
         }
     } else {
         $errors['NOT_LOGGED_IN'] = 1;
     }
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
Example #7
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');
 }
Example #8
0
 public static function update_page($pageInfo)
 {
     $ID = $pageInfo['ID'];
     $uri = $pageInfo['uri'];
     $module = $pageInfo['module'];
     $function = $pageInfo['function'];
     $template = $pageInfo['template'];
     $title = $pageInfo['title'];
     $keywords = $pageInfo['keywords'];
     $description = $pageInfo['description'];
     $pass_parameters_via_uri = isset($pageInfo['pass_parameters_via_uri']) ? 1 : 0;
     if (empty($uri) || empty($module) || empty($function)) {
         return false;
     }
     $previousPage = self::getPageById($ID);
     $serialized_parameters = serialize($pageInfo['parameters']);
     $sql_result = SJB_DB::query("UPDATE `pages` SET `uri`=?s, `module`=?s, `function`=?s," . " `template`=?s, `title`=?s, `parameters`=?s, `keywords`=?s," . " `description`=?s, `pass_parameters_via_uri`=?n" . " WHERE `ID`=?s", $uri, $module, $function, $template, $title, $serialized_parameters, $keywords, $description, $pass_parameters_via_uri, $ID);
     if ($sql_result != false) {
         if ($previousPage['function'] == 'browse') {
             SJB_BrowseDBManager::deleteBrowseByUri($previousPage['uri']);
         }
         if ($function == 'browse') {
             SJB_BrowseDBManager::addBrowseByUri($uri);
         }
         return $sql_result;
     }
     return false;
 }
Example #9
0
    private function runTaskScheduler()
    {
        // Deactivate Expired Listings & Send Notifications
        $listingsExpiredID = SJB_ListingManager::getExpiredListingsSID();
        foreach ($listingsExpiredID as $listingExpiredID) {
            SJB_ListingManager::deactivateListingBySID($listingExpiredID, true);
            $listing = SJB_ListingManager::getObjectBySID($listingExpiredID);
            $listingInfo = SJB_ListingManager::createTemplateStructureForListing($listing);
            if (SJB_UserNotificationsManager::isUserNotifiedOnListingExpiration($listing->getUserSID())) {
                SJB_Notifications::sendUserListingExpiredLetter($listingInfo);
            }
            // notify admin
            SJB_AdminNotifications::sendAdminListingExpiredLetter($listingInfo);
        }
        $listingsDeactivatedID = array();
        if (SJB_Settings::getSettingByName('automatically_delete_expired_listings')) {
            $listingsDeactivatedID = SJB_ListingManager::getDeactivatedListingsSID();
            foreach ($listingsDeactivatedID as $listingID) {
                SJB_ListingManager::deleteListingBySID($listingID);
            }
        }
        SJB_ListingManager::unFeaturedListings();
        SJB_ListingManager::unPriorityListings();
        SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_LISTINGS));
        /////////////////////////// Send remind notifications about expiration of LISTINGS
        // 1. get user sids and days count of 'remind listing notification' setting = 1 from user_notifications table
        // 2. foreach user:
        //   - get listings with that expiration remind date
        //   - check every listing sid in DB table of sended. If sended - remove from send list
        //   - send notification with listings to user
        //   - write listings sid in DB table of sended notifications
        $notificationData = SJB_UserNotificationsManager::getUsersAndDaysOnListingExpirationRemind();
        foreach ($notificationData as $elem) {
            $userSID = $elem['user_sid'];
            $days = $elem['days'];
            $listingSIDs = SJB_ListingManager::getListingsIDByDaysLeftToExpired($userSID, $days);
            if (empty($listingSIDs)) {
                continue;
            }
            $listingsInfo = array();
            // check listings remind sended
            foreach ($listingSIDs as $key => $sid) {
                if (SJB_ListingManager::isListingNotificationSended($sid)) {
                    unset($listingSIDs[$key]);
                    continue;
                }
                $info = SJB_ListingManager::getListingInfoBySID($sid);
                $listingsInfo[$sid] = $info;
            }
            if (!empty($listingsInfo)) {
                // now only unsended listings we have in array
                // send listing notification
                foreach ($listingSIDs as $sid) {
                    SJB_Notifications::sendRemindListingExpirationLetter($userSID, $sid, $days);
                }
                // write listing id in DB table of sended notifications
                SJB_ListingManager::saveListingIDAsSendedNotificationsTable($listingSIDs);
            }
        }
        // Send Notifications for Expired Contracts
        $contractsExpiredID = SJB_ContractManager::getExpiredContractsID();
        foreach ($contractsExpiredID as $contractExpiredID) {
            $contractInfo = SJB_ContractManager::getInfo($contractExpiredID);
            $productInfo = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']);
            $userInfo = SJB_UserManager::getUserInfoBySID($contractInfo['user_sid']);
            $serializedExtraInfo = unserialize($contractInfo['serialized_extra_info']);
            if (!empty($serializedExtraInfo['featured_profile']) && !empty($userInfo['featured'])) {
                $contracts = SJB_ContractManager::getAllContractsInfoByUserSID($userInfo['sid']);
                $isFeatured = 0;
                foreach ($contracts as $contract) {
                    if ($contract['id'] != $contractExpiredID) {
                        $serializedExtraInfo = unserialize($contract['serialized_extra_info']);
                        if (!empty($serializedExtraInfo['featured'])) {
                            $isFeatured = 1;
                        }
                    }
                }
                if (!$isFeatured) {
                    SJB_UserManager::removeFromFeaturedBySID($userInfo['sid']);
                }
            }
            if (SJB_UserNotificationsManager::isUserNotifiedOnContractExpiration($contractInfo['user_sid'])) {
                SJB_Notifications::sendUserContractExpiredLetter($userInfo, $contractInfo, $productInfo);
            }
            // notify admin
            SJB_AdminNotifications::sendAdminUserContractExpiredLetter($userInfo['sid'], $contractInfo, $productInfo);
            SJB_ContractManager::deleteContract($contractExpiredID, $contractInfo['user_sid']);
        }
        //////////////////////// Send remind notifications about expiration of contracts
        // 1. get user sids and days count of 'remind subscription notification' setting = 1 from user_notifications table
        // 2. foreach user:
        //   - get contracts with that expiration remind date
        //   - check every contract sid in DB table of sended. If sended - remove from send list
        //   - send notification with contracts to user
        //   - write contract sid in DB table of sended contract notifications
        $notificationData = SJB_UserNotificationsManager::getUsersAndDaysOnSubscriptionExpirationRemind();
        foreach ($notificationData as $elem) {
            $userSID = $elem['user_sid'];
            $days = $elem['days'];
            $contractSIDs = SJB_ContractManager::getContractsIDByDaysLeftToExpired($userSID, $days);
            if (empty($contractSIDs)) {
                continue;
            }
            $contractsInfo = array();
            // check contracts sended
            foreach ($contractSIDs as $key => $sid) {
                if (SJB_ContractManager::isContractNotificationSended($sid)) {
                    unset($contractSIDs[$key]);
                    continue;
                }
                $info = SJB_ContractManager::getInfo($sid);
                $info['extra_info'] = !empty($info['serialized_extra_info']) ? unserialize($info['serialized_extra_info']) : '';
                $contractsInfo[$sid] = $info;
            }
            if (!empty($contractsInfo)) {
                // now only unsended contracts we have in array
                // send contract notification
                foreach ($contractSIDs as $sid) {
                    SJB_Notifications::sendRemindSubscriptionExpirationLetter($userSID, $contractsInfo[$sid], $days);
                }
                // write contract id in DB table of sended contract notifications
                SJB_ContractManager::saveContractIDAsSendedNotificationsTable($contractSIDs);
            }
        }
        // delete applications with no employer and job seeker
        $emptyApplications = SJB_DB::query('SELECT `id` FROM `applications` WHERE `show_js` = 0 AND `show_emp` = 0');
        foreach ($emptyApplications as $application) {
            SJB_Applications::remove($application['id']);
        }
        // NEWS
        $expiredNews = SJB_NewsManager::getExpiredNews();
        foreach ($expiredNews as $article) {
            SJB_NewsManager::deactivateItemBySID($article['sid']);
        }
        // LISTING XML IMPORT
        SJB_XmlImport::runImport();
        // UPDATE PAGES WITH FUNCTION EQUAL BROWSE(e.g. /browse-by-city/)
        SJB_BrowseDBManager::rebuildBrowses();
        //-------------------sitemap generator--------------------//
        SJB_System::executeFunction('miscellaneous', 'sitemap_generator');
        // CLEAR `error_log` TABLE
        $errorLogLifetime = SJB_System::getSettingByName('error_log_lifetime');
        $lifeTime = strtotime("-{$errorLogLifetime} days");
        if ($lifeTime > 0) {
            SJB_DB::query('DELETE FROM `error_log` WHERE `date` < ?t', $lifeTime);
        }
        SJB_Settings::updateSetting('task_scheduler_last_executed_date', $this->currentDate);
        $this->tp->assign('expired_listings_id', $listingsExpiredID);
        $this->tp->assign('deactivated_listings_id', $listingsDeactivatedID);
        $this->tp->assign('expired_contracts_id', $contractsExpiredID);
        $this->tp->assign('notified_saved_searches_id', $this->notifiedSavedSearchesSID);
        $schedulerLog = $this->tp->fetch('task_scheduler_log.tpl');
        SJB_HelperFunctions::writeCronLogFile('task_scheduler.log', $schedulerLog);
        SJB_DB::query('INSERT INTO `task_scheduler_log`
			(`last_executed_date`, `notifieds_sent`, `expired_listings`, `expired_contracts`, `log_text`)
			VALUES ( NOW(), ?n, ?n, ?n, ?s)', count($this->notifiedSavedSearchesSID), count($listingsExpiredID), count($contractsExpiredID), $schedulerLog);
        SJB_System::getModuleManager()->executeFunction('social', 'linkedin');
        SJB_System::getModuleManager()->executeFunction('social', 'facebook');
        SJB_System::getModuleManager()->executeFunction('classifieds', 'linkedin');
        SJB_System::getModuleManager()->executeFunction('classifieds', 'facebook');
        SJB_System::getModuleManager()->executeFunction('classifieds', 'twitter');
        SJB_Event::dispatch('task_scheduler_run');
    }
Example #10
0
 public function execute()
 {
     $restore = 'restore=';
     if (isset($_REQUEST['action_name'], $_REQUEST['listings'])) {
         $listings_ids = $_REQUEST['listings'];
         switch (strtolower($_REQUEST['action_name'])) {
             case 'activate':
                 $activatedListings = array();
                 foreach ($listings_ids as $listingId => $value) {
                     if (SJB_ListingManager::activateListingBySID($listingId, false)) {
                         $activatedListings[] = $listingId;
                     }
                     $listing = SJB_ListingManager::getObjectBySID($listingId);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingActivation($listing->getUserSID())) {
                         SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                     }
                 }
                 SJB_BrowseDBManager::addListings($activatedListings);
                 break;
             case 'deactivate':
                 $this->executeAction($listings_ids, 'deactivate');
                 break;
             case 'delete':
                 $this->executeAction($listings_ids, 'delete');
                 break;
             case 'datemodify':
                 if (isset($_REQUEST['date_to_change'])) {
                     $dateToUpdate = $_REQUEST['date_to_change'];
                     $date = SJB_I18N::getInstance()->getInput('date', $dateToUpdate);
                     foreach ($listings_ids as $listing_id => $value) {
                         $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
                         $result = SJB_DB::query('UPDATE `listings` SET `expiration_date` = ?s WHERE `sid` = ?n', $date, $listingInfo['sid']);
                     }
                 }
                 break;
             case 'approve':
                 $this->executeAction($listings_ids, 'approve');
                 foreach ($listings_ids as $listing_id => $value) {
                     $user_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingApprove($user_sid)) {
                         SJB_Notifications::sendUserListingApproveOrRejectLetter($listing_id, $user_sid, 'approve');
                     }
                 }
                 break;
             case 'reject':
                 $this->executeAction($listings_ids, 'reject');
                 foreach ($listings_ids as $listing_id => $value) {
                     $user_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingReject($user_sid)) {
                         SJB_Notifications::sendUserListingApproveOrRejectLetter($listing_id, $user_sid, 'reject');
                     }
                 }
                 break;
             default:
                 $restore = '';
                 break;
         }
     }
     $listingTypeId = SJB_Request::getVar('listingTypeId', null);
     $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's';
     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingType) . '/?action=search&' . $restore);
 }
Example #11
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_info['listing_type_sid']);
     if (!is_null($listing_info)) {
         $filename = SJB_Request::getVar('filename', false);
         if ($filename) {
             $file = SJB_UploadFileManager::openFile($filename, $listing_id);
             $errors['NO_SUCH_FILE'] = true;
         }
         if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && !$_REQUEST['Occupations']['tree']) {
             unset($_REQUEST['Occupations']['tree']);
         }
         $listing_info = array_merge($listing_info, $_REQUEST);
         if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && $_REQUEST['Occupations']['tree']) {
             $listing_info['Occupations'] = $_REQUEST['Occupations']['tree'];
         }
         $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
         $listing->setSID($listing_id);
         $listing_edit_form = new SJB_Form($listing);
         $form_is_submitted = SJB_Request::getVar('action');
         $errors = array();
         if ($form_is_submitted) {
             $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
         }
         if ($form_is_submitted && $listing_edit_form->isDataValid($errors)) {
             $listingSid = $listing->getID();
             SJB_BrowseDBManager::deleteListings($listingSid);
             SJB_ListingManager::saveListing($listing);
             SJB_BrowseDBManager::addListings($listingSid);
             $formToken = SJB_Request::getVar('form_token');
             $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
             $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
             if (!empty($uploadedFields)) {
                 foreach ($uploadedFields as $fieldId => $fieldValue) {
                     // get field of listing
                     $isComplex = false;
                     if (strpos($fieldId, ':') !== false) {
                         $isComplex = true;
                     }
                     $tmpUploadedFileId = $fieldValue['file_id'];
                     // rename it to real listing field value
                     $newFileId = $fieldId . "_" . $listing->getSID();
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                     if ($isComplex) {
                         list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                         $parentProp = $listing->getProperty($parentField);
                         $parentValue = $parentProp->getValue();
                         // look for complex property with current $fieldID and set it to new value of property
                         if (!empty($parentValue)) {
                             foreach ($parentValue as $id => $value) {
                                 if ($id == $subField) {
                                     $parentValue[$id][$complexStep] = $newFileId;
                                 }
                             }
                             $listing->setPropertyValue($parentField, $parentValue);
                         }
                     } else {
                         $listing->setPropertyValue($fieldId, $newFileId);
                     }
                     // unset value from session temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                 }
                 //and remove token key from temporary storage
                 $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                 SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                 SJB_ListingManager::saveListing($listing);
             }
             SJB_Event::dispatch('listingEdited', $listingSid);
             if (SJB_Request::isAjax()) {
                 echo '<p class="green">Listing Saved</p>';
                 exit;
             }
             if ($form_is_submitted == 'save_info') {
                 $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
                 $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's';
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/manage-" . strtolower($listingType) . "/?restore=1");
             }
         }
         $listing->deleteProperty('access_list');
         $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id);
         $comments_total = count($comments);
         $rate = SJB_Rating::getRatingNumToListing($listing_id);
         $form_fields = $listing_edit_form->getFormFieldsInfo();
         $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing->getListingTypeSID());
         $realFormFields = array();
         foreach ($pages as $page) {
             $listingFields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
             foreach ($listingFields as $fieldID => $listingField) {
                 if (isset($form_fields[$fieldID])) {
                     $realFormFields[$fieldID] = $form_fields[$fieldID];
                 }
             }
         }
         $adminFields = array();
         foreach ($form_fields as $fieldName => $field) {
             if (!isset($realFormFields[$fieldName])) {
                 $adminFields[$fieldName] = $field;
             }
         }
         $realFormFields = array_merge($adminFields, $realFormFields);
         $tp = SJB_System::getTemplateProcessor();
         $listing_edit_form->registerTags($tp);
         $extraInfo = $listing_info['product_info'];
         if ($extraInfo) {
             $extraInfo = unserialize($extraInfo);
             $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
             $tp->assign("listing_duration", $extraInfo['listing_duration']);
             $tp->assign("pic_limit", $numberOfPictures);
         }
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
         if (!isset($listing_structure['access_type'])) {
             $listing_structure['access_type'] = 'everyone';
         }
         $listing_access_list = SJB_ListingManager::getListingAccessList($listing_id, $listing->getPropertyValue('access_type'));
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('form_fields', $realFormFields);
         $tp->assign('listing', $listing_structure);
         $tp->assign('errors', $errors);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->assign('listing_access_list', $listing_access_list);
         $tp->assign('comments_total', $comments_total);
         $tp->assign('rate', $rate);
         $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
         SJB_System::setGlobalTemplateVariable('wikiExtraParam', $listingTypeInfo['id']);
         $tp->display('edit_listing.tpl');
     }
 }