public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $location = new SJB_Location($_REQUEST); if (SJB_Request::getVar('state', false)) { $location->state_code = SJB_StatesManager::getStateCodeByStateName(SJB_Request::getVar('state', '')); } else { $location->state_code = ''; } $formSubmitted = 'add' == SJB_Request::getVar('action', false); $locationAdded = false; if ($formSubmitted) { if ($location->isDataValid($errors)) { if (SJB_LocationManager::saveLocation($location)) { $location = new SJB_Location(); $locationAdded = true; } else { $errors['Name'] = 'NOT_UNIQUE_VALUE'; } } } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $locationInfo = $location->getInfo(); $tp->assign('locationAdded', $locationAdded); $tp->assign('countries', $countries); $tp->assign('errors', $errors); $tp->assign('location_info', $locationInfo); $tp->display('add_location.tpl'); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $countrySID = SJB_Request::getVar('country_sid', false); $stateSID = SJB_Request::getVar('state_sid', false); $parentID = SJB_Request::getVar('parentID', false); $caption = SJB_Request::getVar('caption', 'State'); $type = SJB_Request::getVar('type', false); $displayAs = SJB_Request::getVar('display_as', 'state_name'); $displayAs = $displayAs == 'state_name' || $displayAs == 'state_code' ? $displayAs : 'state_name'; $result = array(); if ($countrySID) { $result = SJB_StatesManager::getStatesNamesByCountry($countrySID, true, $displayAs); } $tp->assign("caption", $caption); $tp->assign("value", $stateSID); $tp->assign("list_values", $result); $tp->assign("parentID", $parentID); if (!empty($countrySID)) { $tp->assign("enabled", true); } if ($type == 'search') { $tp->assign("id", $parentID . '_State'); $tp->display("../field_types/search/list.tpl"); } else { $tp->assign("id", 'State'); $tp->display("../field_types/input/list.tpl"); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $count_listing = SJB_Request::getVar('count_listing', 10, null, 'int'); $current_user = SJB_UserManager::getCurrentUser(); if (SJB_UserManager::isUserLoggedIn()) { $lastAddedListing = SJB_ListingManager::getLastAddedListingByUserSID($current_user->getSID()); if ($lastAddedListing) { $properties = $current_user->getProperties(); $phrase['title'] = $lastAddedListing->getPropertyValue('Title'); foreach ($properties as $property) { if ($property->getType() == 'location') { $fields = $property->type->child; $childProperties = $fields->getProperties(); foreach ($childProperties as $childProperty) { if (in_array($childProperty->getID(), array('City', 'State', 'Country'))) { $value = $childProperty->getValue(); switch ($childProperty->getType()) { case 'list': if ($childProperty->getID() == 'State') { $displayAS = $childProperty->display_as; $displayAS = $displayAS ? $displayAS : 'state_name'; $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS); } else { $listValues = $childProperty->type->list_values; } foreach ($listValues as $values) { if ($value == $values['id']) { $phrase[strtolower($childProperty->getID())] = $values['caption']; } } break; default: $phrase[strtolower($childProperty->getID())] = $value; break; } } } } } $phrase = array_diff($phrase, array('')); $phrase = implode(" ", $phrase); $listing_type_id = "Job"; $request['action'] = 'search'; $request['listing_type']['equal'] = $listing_type_id; $request['default_listings_per_page'] = $count_listing; $request['default_sorting_field'] = "activation_date"; $request['default_sorting_order'] = "DESC"; $request['keywords']['relevance'] = $phrase; $searchResultsTP = new SJB_SearchResultsTP($request, $listing_type_id, array('field' => 'keywords', 'value' => $phrase)); $tp = $searchResultsTP->getChargedTemplateProcessor(); } $tp->display('suggested_jobs.tpl'); } }
function getData($non_existed_values_flag, $values = array()) { $listFieldsInfo = SJB_ListingFieldManager::getFieldsInfoByType('list'); $multilistFieldsInfo = SJB_ListingFieldManager::getFieldsInfoByType('multilist'); $fieldsInfo = array_merge($listFieldsInfo, $multilistFieldsInfo); foreach ($fieldsInfo as $key => $fieldInfo) { if (empty($fieldInfo['parent_sid'])) { $fieldsInfo[$fieldInfo['id']] = $fieldInfo; } unset($fieldsInfo[$key]); } $result = array(); foreach ($this->properties_names as $key => $property_name) { if (in_array($property_name, array_keys($fieldsInfo)) && isset($values[$key])) { $fieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldsInfo[$property_name]['sid']); if (!empty($fieldInfo['parent_sid']) && $fieldInfo['id'] == 'State') { $fieldInfo['list_values'] = SJB_StatesManager::getStatesNamesByCountry(false, true); } switch ($fieldInfo['type']) { case 'list': foreach ($fieldInfo['list_values'] as $listValues) { if ($listValues['caption'] == $values[$key]) { $result[$property_name] = $listValues['id']; break; } } break; case 'multilist': $multilistValues = explode(',', $values[$key]); $multilistDisplayValues = array(); foreach ($fieldInfo['list_values'] as $listValues) { if (in_array($listValues['caption'], $multilistValues)) { $multilistDisplayValues[] = $listValues['id']; } } $result[$property_name] = implode(',', $multilistDisplayValues); break; } } else { if (strpos($property_name, 'date') && strtotime($values[$key]) == false) { if ($property_name == 'activation_date') { $values[$key] = date('Y-m-d H:i:s'); } else { $values[$key] = ''; } } $result[$property_name] = isset($values[$key]) ? $values[$key] : null; } } $result = $result + $this->_getTreeValues($values, $non_existed_values_flag); return $result; }
protected function _decorateItems($items) { if (!empty($this->field['parent']) && in_array($this->field['field'], array($this->field['parent'] . '_State', $this->field['parent'] . '_Country'))) { $fieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($this->field['sid']); if ($this->field['field'] == $this->field['parent'] . '_State') { $values = SJB_StatesManager::getHashedListItems($fieldInfo['display_as']); } elseif ($this->field['field'] == $this->field['parent'] . '_Country') { $values = SJB_CountriesManager::getHashedListItems($fieldInfo['display_as']); } } else { $listingFieldListItemManager = SJB_ObjectMother::createListingFieldListItemManager(); $values = $listingFieldListItemManager->getHashedListItemsByFieldSID($this->field['sid']); } $values = $this->getSortedValues($values); $listData = array(); foreach ($values as $id => $value) { $listData[$value] = isset($items[$id]) ? $items[$id] : 0; } return $listData; }
/** * @param array $criteria * @param string $settingName * @return string */ protected static function getLocation(array $criteria, $settingName = '') { $location = isset($criteria['Location']['location']['value']) ? $criteria['Location']['location']['value'] : ''; $locationInfo['zipCode'] = isset($criteria['Location_ZipCode']['geo']['location']) ? $criteria['Location_ZipCode']['geo']['location'] : ''; if (isset($criteria['Location_City']['like'])) { $locationInfo['city'] = $criteria['Location_City']['like']; } else { if (isset($criteria['Location_City']['multi_like_and'][0])) { $locationInfo['city'] = $criteria['Location_City']['multi_like_and'][0]; } } if (isset($criteria['Location_State']['multi_like'])) { foreach ($criteria['Location_State']['multi_like'] as $stateSID) { if (!empty($stateSID)) { $stateInfo = SJB_StatesManager::getStateInfoBySID($stateSID); $locationInfo['state'] = !empty($stateInfo['state_code']) ? $stateInfo['state_code'] : ''; } } } $result = ''; if (!empty($location)) { $result = $location; } foreach ($locationInfo as $value) { if (!empty($value) && $value != $location) { if (!empty($result)) { $result .= ",{$value}"; } else { $result = $value; } } } if (!empty($settingName) && empty($result)) { $result = SJB_Settings::getSettingByName($settingName); } if (!empty($result)) { $result = trim($result); $result = urlencode($result); } return empty($result) ? '' : $result; }
public function execute() { $template_processor = SJB_System::getTemplateProcessor(); $location_sid = SJB_Request::getVar('sid', null); $errors = null; $field_errors = null; $location_info = SJB_LocationManager::getLocationInfoBySID($location_sid); if (!is_null($location_info)) { $form_is_submitted = SJB_Request::getVar('action'); $location_info = array_merge($location_info, $_REQUEST); $location = new SJB_Location($location_info); $location->setSID($location_sid); if (SJB_Request::getVar('state', false)) { $location->state_code = SJB_StatesManager::getStateCodeByStateName(SJB_Request::getVar('state', '')); } else { $location->state_code = ''; } if ($form_is_submitted && $location->isDataValid($field_errors)) { if (SJB_LocationManager::saveLocation($location)) { if ($form_is_submitted == 'save_info') { $redirect_url = SJB_System::getSystemSettings('SITE_URL') . '/geographic-data/'; SJB_HelperFunctions::redirect($redirect_url); } } else { $field_errors['Name'] = 'NOT_UNIQUE_VALUE'; } } } elseif (is_null($location_sid)) { $errors['LOCATION_SID_IS_NOT_SPECIFIED'] = 1; } else { $errors['WORNG_LOCATION_SID_IS_SPECIFIED'] = 1; } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $template_processor->assign("location_info", $location_info); $template_processor->assign("countries", $countries); $template_processor->assign("errors", $errors); $template_processor->assign("field_errors", $field_errors); $template_processor->assign("location_sid", $location_sid); $template_processor->display("edit_location.tpl"); }
public static function createTemplateStructureForTax($tax_info) { $tax = new SJB_Taxes($tax_info); foreach ($tax->getProperties() as $property) { if ($property->getType() == 'list') { $value = $property->getValue(); $properties = $property->type->property_info; if ($properties['id'] == 'State') { $properties['list_values'] = SJB_StatesManager::getStatesNamesByCountry($tax->getPropertyValue('Country')); } $listValues = isset($properties['list_values']) ? $properties['list_values'] : array(); $caption = null; foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $caption = $listValue['caption']; break; } } $tax_info[$property->getID()] = isset($caption) ? $caption : ''; } } return $tax_info; }
/** * @param SJB_Listing $listing */ public static function createTemplateStructureForListing($listing, $extraInfo = array()) { $listing_info = parent::getObjectInfo($listing); if (SJB_MemoryCache::has('listingTypeInfo' . $listing->getListingTypeSID())) { $listing_type_info = SJB_MemoryCache::get('listingTypeInfo' . $listing->getListingTypeSID()); } else { $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listing->getListingTypeSID()); SJB_MemoryCache::set('listingTypeInfo' . $listing->getListingTypeSID(), $listing_type_info); } foreach ($listing->getProperties() as $property) { if ($property->isComplex()) { $isPropertyEmpty = true; $properties = $property->type->complex->getProperties(); $properties = is_array($properties) ? $properties : array(); foreach ($properties as $subProperty) { if (!empty($listing_info['user_defined'][$property->getID()][$subProperty->getID()]) && is_array($listing_info['user_defined'][$property->getID()][$subProperty->getID()])) { foreach ($listing_info['user_defined'][$property->getID()][$subProperty->getID()] as $subValue) { if (!empty($subValue)) { $isPropertyEmpty = false; } } } } if ($isPropertyEmpty) { $listing_info['user_defined'][$property->getID()] = ''; } } if ($property->getType() == 'list') { $value = $property->getValue(); $properties = $property->type->property_info; $listValues = isset($properties['list_values']) ? $properties['list_values'] : array(); foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $listing_info['user_defined'][$property->getID()] = $listValue['caption']; } } } elseif ($property->getType() == 'multilist') { $value = $property->getValue(); if (!is_array($property->getValue())) { $value = explode(',', $property->getValue()); } $properties = $property->type->property_info; $listValues = isset($properties['list_values']) ? $properties['list_values'] : array(); $listing_info['user_defined'][$property->getID()] = array(); foreach ($listValues as $listValue) { if (in_array($listValue['id'], $value)) { $listing_info['user_defined'][$property->getID()][$listValue['id']] = $listValue['caption']; } } } elseif ($property->getType() == 'location' && is_array($listing_info['user_defined'][$property->getID()])) { foreach ($property->type->fields as $locationField) { if (array_key_exists($locationField['id'], $listing_info['user_defined'][$property->getID()])) { if ($locationField['id'] == 'State') { $listValues = SJB_StatesManager::getStateNamesBySid($property->value['State'], 'state_name'); } else { $listValues = isset($locationField['list_values']) ? $locationField['list_values'] : array(); } $value = $property->getValue(); $value = isset($value[$locationField['id']]) ? $value[$locationField['id']] : ''; foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $listing_info['user_defined'][$property->getID()][$locationField['id']] = $listValue['caption']; $listing_info['user_defined'][$property->getID()][$locationField['id'] . '_Code'] = $listValue['Code']; $listing_info['user_defined'][$property->getID()][$locationField['id'] . '_Name'] = $listValue['Name']; } } } } } } $cache = SJB_Cache::getInstance(); $cacheId = md5('SJB_UserManager::getObjectBySID' . $listing_info['system']['user_sid']); $user_info = array(); if ($cache->test($cacheId)) { $user_info = $cache->load($cacheId); } else { $user = SJB_UserManager::getObjectBySID($listing_info['system']['user_sid']); $user_info = !empty($user) ? SJB_UserManager::createTemplateStructureForUser($user) : null; $cache->save($user_info, $cacheId, array(SJB_Cache::TAG_USERS)); } $productInfo = SJB_ProductsManager::createTemplateStructureForProduct($listing_info['system']['product_info']); $priceForUpgradeToFeatured = 0; $priceForUpgradeToPriority = 0; if (!empty($listing_info['system']['product_info'])) { $listingProductInfo = unserialize($listing_info['system']['product_info']); $priceForUpgradeToFeatured = SJB_Array::get($listingProductInfo, 'upgrade_to_featured_listing_price', 0); $priceForUpgradeToPriority = SJB_Array::get($listingProductInfo, 'upgrade_to_priority_listing_price', 0); } $structure = array('id' => $listing_info['system']['id'], 'type' => array('id' => $listing_type_info['id'], 'caption' => $listing_type_info['name']), 'user' => $user_info, 'activation_date' => $listing_info['system']['activation_date'], 'expiration_date' => $listing_info['system']['expiration_date'], 'featured' => $listing_info['system']['featured'], 'priority' => $listing_info['system']['priority'], 'views' => $listing_info['system']['views'], 'active' => $listing_info['system']['active'], 'product' => $productInfo, 'contract_id' => $listing_info['system']['contract_id'], 'number_of_pictures' => isset($listing_info['user_defined']['pictures']) ? count($listing_info['user_defined']['pictures']) : 0, 'approveStatus' => $listing_info['system']['status'], 'complete' => $listing_info['system']['complete'], 'external_id' => $listing_info['system']['external_id'], 'priceForUpgradeToFeatured' => $priceForUpgradeToFeatured, 'priceForUpgradeToPriority' => $priceForUpgradeToPriority); if (SJB_Settings::getSettingByName('jobg8Installed') && SJB_PluginManager::isPluginActive('JobG8IntegrationPlugin')) { $structure['jobType'] = JobG8::getJobProperty($listing_info['system']['id'], 'jobType'); } if (array_search('comments', $extraInfo)) { $structure['comments_num'] = SJB_CommentManager::getCommentsNumToListing($listing_info['system']['id']); } if (array_search('ratings', $extraInfo)) { $structure['rating_num'] = SJB_Rating::getRatingNumToListing($listing_info['system']['id']); $structure['rating'] = SJB_Rating::getRatingToListing($listing_info['system']['id']); $structure['rating_array'] = SJB_Rating::getRatingTplToListing($listing_info['system']['id']); } if (!empty($listing_info['system']['subuser_sid'])) { $structure['subuser'] = SJB_UserManager::getUserInfoBySID($listing_info['system']['subuser_sid']); } $structure['METADATA'] = array('activation_date' => array('type' => 'date'), 'expiration_date' => array('type' => 'date'), 'views' => array('type' => 'integer'), 'number_of_pictures' => array('type' => 'integer'), 'approveStatus' => array('type' => 'string'), 'rejectReason' => array('type' => 'string')); $structure = array_merge($structure, $listing_info['user_defined']); $structure['METADATA'] = array_merge($structure['METADATA'], parent::getObjectMetaData($listing)); $listing_user_meta_data = array(); if (isset($user_info['METADATA'])) { $listing_user_meta_data = $user_info['METADATA']; unset($user_info['METADATA']); } $listing_product_meta_data = array(); if (isset($productInfo['METADATA'])) { $listing_product_meta_data = $productInfo['METADATA']; unset($productInfo['METADATA']); } $listing_type_meta_data = array('caption' => array('type' => 'string', 'propertyID' => 'listing_type')); $structure['METADATA'] = array_merge($structure['METADATA'], array('user' => $listing_user_meta_data, 'product' => $listing_product_meta_data, 'type' => $listing_type_meta_data)); return array_merge($structure, $listing_info['user_defined']); }
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'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'list'); $countrySID = SJB_Request::getVar('country_sid', false); $errors = array(); $template = 'states.tpl'; $countries = SJB_CountriesManager::getAllCountries(); $paginator = new SJB_StatesPagination(); switch ($action) { case 'move_state': case 'save_order': $template = 'move_state.tpl'; $itemSIDs = SJB_Request::getVar('item_order', array()); try { SJB_StatesManager::saveItemsOrder($paginator->currentPage, $paginator->itemsPerPage, $itemSIDs); $tp->assign('action', $action); } catch (Exception $e) { $errors['SAVING_ORDER'] = $e->getMessage(); } $states = SJB_StatesManager::getAllStates($countrySID); $tp->assign('states', $states); break; case 'activate': $statesSIDs = array_keys(SJB_Request::getVar('states', array())); foreach ($statesSIDs as $stateSID) { SJB_StatesManager::activateStateBySID($stateSID); } $action = 'list'; break; case 'deactivate': $statesSIDs = array_keys(SJB_Request::getVar('states', array())); foreach ($statesSIDs as $stateSID) { SJB_StatesManager::deactivateStateBySID($stateSID); } $action = 'list'; break; case 'delete': $statesSIDs = array_keys(SJB_Request::getVar('states', array())); foreach ($statesSIDs as $stateSID) { SJB_StatesManager::deleteStateBySID($stateSID); } $action = 'list'; break; case 'add_state': $template = 'add_state.tpl'; $formSubmitted = SJB_Request::getVar('action_add', false); $state = new SJB_State($_REQUEST); $addStateForm = new SJB_Form($state); $addStateForm->registerTags($tp); $addValidParam = array('field' => 'country_sid', 'value' => $countrySID); if ($formSubmitted && $addStateForm->isDataValid($errors, $addValidParam)) { $state->addProperty(array('id' => 'country_sid', 'type' => 'list', 'value' => $countrySID, 'is_required' => true, 'is_system' => true)); SJB_StatesManager::saveState($state); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/states/?country_sid=" . $countrySID); } else { $formFields = $addStateForm->getFormFieldsInfo(); $tp->assign('form_fields', $formFields); } break; case 'edit_state': $template = 'edit_state.tpl'; $stateSID = SJB_Request::getVar('state_id', false); $formSubmitted = SJB_Request::getVar('action_add', false); $stateInfo = SJB_StatesManager::getStateInfoBySID($stateSID); if ($stateInfo) { $stateInfo = array_merge($stateInfo, $_REQUEST); $state = new SJB_State($stateInfo); $addStateForm = new SJB_Form($state); $addStateForm->registerTags($tp); $state->setSID($stateSID); $addValidParam = array('field' => 'country_sid', 'value' => $stateInfo['country_sid']); if ($formSubmitted && $addStateForm->isDataValid($errors, $addValidParam)) { SJB_StatesManager::saveState($state); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/states/?country_sid=" . $stateInfo['country_sid']); } else { $formFields = $addStateForm->getFormFieldsInfo(); $tp->assign('form_fields', $formFields); $tp->assign('state_id', $stateSID); } } else { $tp->assign('action', 'edit'); $errors['WRONG_STATE_ID_SPECIFIED'] = 'WRONG_STATE_ID_SPECIFIED'; $template = 'state_errors.tpl'; } break; case 'import_states': $template = 'import_states.tpl'; $fileInfo = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); if ($fileInfo['error']) { $errors[] = SJB_UploadFileManager::getErrorId($fileInfo['error']); } elseif ($fileInfo) { $fileFormats = array('csv', 'xls', 'xlsx'); $pathInfo = pathinfo($fileInfo['name']); $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : ''; if (!in_array(strtolower($fileExtension), $fileFormats)) { $errors[] = 'Please choose Excel or csv file'; } else { $importFile = new SJB_ImportFileXLS($fileInfo); $importFile->parse(); $importedData = $importFile->getData(); $state = new SJB_State(); $count = 0; foreach ($importedData as $key => $importedColumn) { if ($key == 1) { $data = array_merge(array(array('state_code', 'state_name')), array($importedColumn)); $importedProcessor = new SJB_ImportedStateProcessor($data, $state); } if (!$importedColumn) { continue; } $stateInfo = $importedProcessor->getData($importedColumn); if (!empty($stateInfo['state_code']) && !empty($stateInfo['state_name'])) { $state = new SJB_State($stateInfo); $state->addProperty(array('id' => 'country_sid', 'type' => 'list', 'value' => $countrySID, 'is_required' => true, 'is_system' => true)); $state->setPropertyValue('active', 1); $stateSID = SJB_StatesManager::getStateSIDByStateCode($stateInfo['state_code'], $countrySID); if ($stateSID) { $state->setSID($stateSID); } else { $count++; } SJB_StatesManager::saveState($state); } } $tp->assign('imported_states_count', $count); $template = 'import_states_result.tpl'; } } break; } if ($action == 'list') { $countryCode = SJB_Settings::getSettingByName('default_country_code'); if (!$countrySID) { $countrySID = SJB_CountriesManager::getCountrySIDByCountryCode($countryCode); } if (!$countrySID) { $allCountries = SJB_CountriesManager::getAllCountries(); foreach ($allCountries as $country) { $countrySID = $country['sid']; break; } } $countryInfo = SJB_CountriesManager::getCountryInfoBySID($countrySID); if ($countryInfo && $countryInfo['country_code'] != $countryCode) { SJB_Settings::updateSetting('default_country_code', $countryInfo['country_code']); } $states = SJB_StatesManager::getAllStates($countrySID, ($paginator->currentPage - 1) * $paginator->itemsPerPage, $paginator->itemsPerPage); $paginator->setItemsCount(SJB_StatesManager::countStates($countrySID)); $tp->assign('states', $states); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); } $tp->assign("countries", $countries); $tp->assign("country_sid", $countrySID); $tp->assign("errors", $errors); $tp->display($template); }
public function execute() { ini_set('max_execution_time', 0); $template_processor = SJB_System::getTemplateProcessor(); $errors = array(); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; if (!empty($file_info)) { $extension = $_REQUEST['file_type']; if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) { $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true; } } if (empty($file_info) || $file_info['error'] || !empty($errors)) { if (isset($file_info['error']) && $file_info['error'] > 0) { $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1; } $user_groups = SJB_UserGroupManager::getAllUserGroupsInfo(); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $template_processor->assign('user_groups', $user_groups); $template_processor->assign('errors', $errors); $template_processor->assign('charSets', SJB_HelperFunctions::getCharSets()); $template_processor->display('import_users.tpl'); } else { $csv_delimiter = SJB_Request::getVar('csv_delimiter', null); $user_group_id = SJB_Request::getVar('user_group_id', null); $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id); 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); $user = $this->CreateUser(array(), $user_group_id); $imported_data = $import_file->getData(); $count = 0; $import_file_url = false; $usersID = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_user_processor = new SJB_ImportedUserProcessor($importedColumn, $user); continue; } if (!$importedColumn) { continue; } $userInfo = $imported_user_processor->getData($importedColumn); $extUserID = isset($userInfo['extUserID']) ? $userInfo['extUserID'] : ''; $user = $this->CreateUser(array(), $user_group_id); $user->addExtUserIDProperty(); $doc = new DOMDocument(); foreach ($user->getProperties() as $property) { if ($property->id == 'active') { $property->type->property_info['value'] = $property->value; } elseif ($property->getType() == 'location') { $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode', $property->id . '.Address'); $locationFieldAdded = array(); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $userInfo)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]); } break; default: $value = $userInfo[$locationField]; break; } unset($userInfo[$locationField]); $userInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value; $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField); } } if ($property->id == 'Location') { $locationFields = array('Country', 'State', 'City', 'ZipCode', 'Address'); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $userInfo) && !in_array($locationField, $locationFieldAdded) && !$user->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]); } break; default: $value = $userInfo[$locationField]; break; } $userInfo[$property->id][$locationField] = $value; unset($userInfo[$locationField]); } } } } } $user = $this->CreateUser($userInfo, $user_group_id); $user->addExtUserIDProperty($extUserID); $username = SJB_Array::get($userInfo, 'username'); if (empty($username)) { $errors[] = 'Empty username is not allowed, record ignored.'; } elseif (!is_null(SJB_UserManager::getUserSIDbyUsername($username))) { $errors[] = '\'' . $userInfo['username'] . '\' - this user name already exists, record ignored.'; } else { $originalMd5Password = $user->getPropertyValue('password'); SJB_UserManager::saveUser($user); $this->extraProperties($user, $userInfo, $usersID); if (!empty($originalMd5Password)) { SJB_UserManager::saveUserPassword($user->getSID(), $originalMd5Password); } $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid); if ($isApproveByAdmin) { SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending'); } $count++; } } if ($import_file_url) { SJB_Filesystem::delete(SJB_System::getSystemSettings("IMPORT_FILES_DIRECTORY")); } $template_processor->assign('imported_users_count', $count); $template_processor->assign('errors', $errors); $template_processor->display('import_users_result.tpl'); } }
/** * * @param SJB_User $user */ public static function createTemplateStructureForUser($user) { if (!$user) { return array(); } $structure = $user->getUserInfo(); if (SJB_MemoryCache::has('userGroupInfo' . $user->getUserGroupSID())) { $user_group_info = SJB_MemoryCache::get('userGroupInfo' . $user->getUserGroupSID()); } else { $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user->getUserGroupSID()); SJB_MemoryCache::set('userGroupInfo' . $user->getUserGroupSID(), $user_group_info); } foreach ($user->getProperties() as $property) { $value = $property->getValue(); if ($property->getType() == 'list') { $listValues = isset($property->type->property_info['list_values']) ? $property->type->property_info['list_values'] : array(); foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $structure[$property->getID()] = $listValue['caption']; } } } elseif ($property->getType() == 'location') { foreach ($property->type->fields as $locationField) { if (isset($structure[$property->getID()]) && array_key_exists($locationField['id'], $structure[$property->getID()])) { if ($locationField['id'] == 'State') { $displayAs = !empty($locationField['display_as']) ? $locationField['display_as'] : 'state_name'; $listValues = SJB_StatesManager::getStateNamesBySid($property->value['State'], $displayAs); } else { $listValues = isset($locationField['list_values']) ? $locationField['list_values'] : array(); } foreach ($listValues as $listValue) { if ($listValue['id'] == $value[$locationField['id']]) { $structure[$property->getID()][$locationField['id']] = $listValue['caption']; $structure[$property->getID()][$locationField['id'] . '_Code'] = $listValue['Code']; $structure[$property->getID()][$locationField['id'] . '_Name'] = $listValue['Name']; } } } } } else { $structure[$property->getID()] = $value; } } $structure['id'] = $user->getID(); $structure['isJobg8'] = strpos($structure['username'], 'jobg8_') !== false; $structure['group'] = array('id' => $user_group_info['id'], 'caption' => $user_group_info['name']); $subuserInfo = $user->getSubuserInfo(); if (!empty($subuserInfo)) { $structure['subuser'] = $subuserInfo; } $structure['METADATA'] = array('group' => array('caption' => array('type' => 'string', 'propertyID' => 'caption')), 'registration_date' => array('type' => 'date')); $structure['METADATA'] = array_merge($structure['METADATA'], parent::getObjectMetaData($user)); return $structure; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $listing_type_id = SJB_Request::getVar('listing_type_id', false); $action = SJB_Request::getVar('action', false); $type = SJB_Request::getVar('type', false); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $supportedFormats = array('xlsx', 'xls', 'csv'); $warning = false; $error = ''; if ($action == 'example' && $type) { $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id); $listing_field_manager = new SJB_ListingFieldManager(); $common_details = $listing_field_manager->getCommonListingFieldsInfo(); $extra_details = $listing_field_manager->getListingFieldsInfoByListingType($listing_type_sid); $listing_fields = array_merge($common_details, $extra_details); $directory_to_export = SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY'); $export_properties = array(); $export_data = array(); foreach ($listing_fields as $listing_field) { $export_properties[$listing_field['id']] = $listing_field['id']; $export_data[0][$listing_field['id']] = ''; } SJB_ExportController::createExportDirectoriesForExample(); switch ($type) { case 'exl': SJB_ExportController::makeExportFile($export_data, 'example.xls'); $export_files_dir = SJB_Path::combine($directory_to_export, 'example.xls'); for ($i = 0; $i < ob_get_level(); $i++) { ob_end_clean(); } header('Content-type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename=example.xls'); header('Content-Length: ' . filesize($export_files_dir)); readfile($export_files_dir); break; case 'csv': $export_files_dir = SJB_Path::combine($directory_to_export, 'example.csv'); $fp = fopen($export_files_dir, 'w'); fputcsv($fp, explode(',', implode(',', $export_properties))); fclose($fp); for ($i = 0; $i < ob_get_level(); $i++) { ob_end_clean(); } header('Content-type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename=example.csv'); header('Content-Length: ' . filesize($export_files_dir)); readfile($export_files_dir); break; } SJB_Filesystem::delete($directory_to_export); exit; } if ($productsInfo = $this->canCurrentUserAddListing($error)) { $acl = SJB_Acl::getInstance(); if ($acl->isAllowed('bulk_job_import') == true) { $fileInfo = null; if (isset($_FILES['import_file'])) { $extension = strtolower(substr(strrchr($_FILES['import_file']['name'], '.'), 1)); if (empty($_FILES['import_file']['name']) || !in_array($extension, $supportedFormats)) { $warning = 'Please choose Excel or csv file'; } else { $fileInfo = $_FILES['import_file']; } } $contractID = SJB_Request::getVar('contract_id', false); $current_user = SJB_UserManager::getCurrentUser(); if ($contractID) { $contract = new SJB_Contract(array('contract_id' => $contractID)); } elseif (count($productsInfo) == 1) { $productInfo = array_pop($productsInfo); $contractID = $productInfo['contract_id']; $contract = new SJB_Contract(array('contract_id' => $contractID)); } else { $tp->assign("products_info", $productsInfo); $tp->assign("listing_type_id", $listing_type_id); $tp->display("listing_product_choice.tpl"); } if ($contractID && $listing_type_id) { $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id); if ($fileInfo) { switch ($extension) { case 'xls': case 'xlsx': $import_file = new SJB_ImportFileXLS($fileInfo); break; case 'csv': $import_file = new SJB_ImportFileCSV($fileInfo, ','); break; } $import_file->parse($encodingFromCharset); $bulkPermissionParam = $this->acl->getPermissionParams('post_' . $listing_type_id, $contract->getID(), 'contract'); $imported_data = $import_file->getData(); $countData = 0; foreach ($imported_data as $val) { if ($val) { $countData++; } } if (empty($bulkPermissionParam) || $bulkPermissionParam - $contract->getPostingsNumber() - ($countData - 1) >= 0) { $listing = new SJB_Listing(array(), $listing_type_sid); $count = 0; $listingSIDs = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing); continue; } if (!$importedColumn) { continue; } $count++; $listing_info = $imported_data_processor->getData('ignore', $importedColumn); $doc = new DOMDocument(); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'complex' && !empty($listing_info[$property->id])) { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $doc->loadXML($listing_info[$property->id]); $results = $doc->getElementsByTagName($property->id . 's'); $listing_info[$property->id] = array(); foreach ($results as $complexparent) { $i = 0; foreach ($complexparent->getElementsByTagName($property->id) as $result) { $resultXML = simplexml_import_dom($result); foreach ($childFields as $childField) { if (isset($resultXML->{$childField}['id'])) { $listing_info[$property->id][$childField['id']][$i] = (string) $resultXML->{$childField}['id']; } } $i++; } } } 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, $listing_info)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]); } break; default: $value = $listing_info[$locationField]; break; } $listing_info[$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, $listing_info) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]); } break; default: $value = $listing_info[$locationField]; break; } $listing_info[$property->id][$locationField] = $value; } } } } } $field_info = null; $listing = new SJB_Listing($listing_info, $listing_type_sid); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'tree' && $property->value !== '') { $treeValues = explode(',', $property->value); $treeSIDs = array(); foreach ($treeValues as $treeValue) { $info = SJB_ListingFieldTreeManager::getItemInfoByCaption($property->sid, trim($treeValue)); $treeSIDs[] = $info['sid']; } $listing->setPropertyValue($property->id, implode(',', $treeSIDs)); $listing->details->properties[$property->id]->type->property_info['value'] = implode(',', $treeSIDs); } elseif ($property->getType() == 'monetary') { $currency = SJB_CurrencyManager::getDefaultCurrency(); $listing->details->properties[$property->id]->type->property_info['value']['add_parameter'] = $currency['sid']; } elseif ($property->id == 'ApplicationSettings' && !empty($listing_info['ApplicationSettings'])) { if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listing_info['ApplicationSettings'])) { $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 1); } elseif (preg_match("^(https?:\\/\\/)^iu", $listing_info['ApplicationSettings'])) { $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 2); } else { $listing_info['ApplicationSettings'] = array('value' => '', 'add_parameter' => ''); } $listing->details->properties[$property->id]->type->property_info['value'] = $listing_info['ApplicationSettings']; } elseif ($property->getType() == 'complex' && is_array($property->value)) { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $complexChildValues = $property->value; foreach ($childFields as $childField) { if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) { $field_info = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']); if (isset($listing_info[$property->id][$field_info['id']]) && file_exists($listing_info[$property->id][$field_info['id']])) { SJB_UploadFileManager::fileImport($listing_info, $field_info, $property->id); } } } } // The import of files at import of listings if (in_array($property->getType(), array('file', 'logo', 'picture', 'video')) && $property->value !== '') { $field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id); if (isset($listing_info[$field_info['id']]) && file_exists($listing_info[$field_info['id']])) { SJB_UploadFileManager::fileImport($listing_info, $field_info); } } } $listing->deleteProperty('featured'); $listing->deleteProperty('priority'); $listing->deleteProperty('status'); $listing->deleteProperty('reject_reason'); $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contract->getID(), 'is_system' => true)); $extraInfo = $contract->extra_info; $listing->setProductInfo($extraInfo); $listing->setPropertyValue('access_type', 'everyone'); $listing->setUserSID($current_user->sid); if ($current_user->isSubuser()) { $subuserInfo = $current_user->getSubuserInfo(); $listing->addSubuserProperty($subuserInfo['sid']); } SJB_ListingManager::saveListing($listing); SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']); $contract->incrementPostingsNumber(); SJB_ProductsManager::incrementPostingsNumber($contract->product_sid); if (!empty($extraInfo['featured'])) { SJB_ListingManager::makeFeaturedBySID($listing->getSID()); } if (!empty($extraInfo['priority'])) { SJB_ListingManager::makePriorityBySID($listing->getSID()); } $this->FillGallery($listing, $listing_info); $listingSIDs[] = $listing->getSID(); } SJB_ListingManager::activateListingBySID($listingSIDs); $tp->assign('listingsNum', count($listingSIDs)); $tp->display('job_import_complete.tpl'); } else { $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED'; $tp->assign('listing_type_id', $listing_type_id); $tp->assign('error', $error); $tp->display('job_import.tpl'); } } else { $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $tp->assign('warning', $warning); $tp->assign('contract_id', $contractID); $tp->assign('listing_type_id', $listing_type_id); $tp->display('job_import.tpl'); } } } else { $error = $acl->getPermissionMessage('bulk_job_import'); if (empty($error)) { $error = 'This action is not allowed within your current product'; } $tp->assign('error', $error); $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $tp->assign('listing_type_id', $listing_type_id); $tp->display('job_import.tpl'); } } else { if ($error == 'NO_CONTRACT') { if ($_GET) { $getParam = '?'; foreach ($_GET as $key => $val) { $getParam .= $key . '=' . $val . '&'; } $getParam = substr($getParam, 0, -1); } $page = base64_encode(SJB_System::getURI() . $getParam); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page); } $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $tp->assign('listing_type_id', $listing_type_id); $tp->assign('error', $error); $tp->display('job_import.tpl'); } }
public function execute() { set_time_limit(0); ini_set('memory_limit', -1); $tp = SJB_System::getTemplateProcessor(); $user_groups_info = SJB_UserGroupManager::getAllUserGroupsInfo(); $user_group_info = reset($user_groups_info); $user_group_sid = $user_group_info['sid']; $fields_info = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group_sid); $fields = array(); $tp->assign('test_message', SJB_Request::getVar('test_message', false)); $tp->assign('undeliveredMailingsForTest', SJB_Request::getVar('undeliveredMailingsForTest', false)); foreach ($fields_info as $key => $val) { if ($val['id'] == 'Location') { foreach ($val['fields'] as $field) { if ($field['id'] == 'Country') { $fields['country'] = SJB_CountriesManager::getAllCountriesCodesAndNames(); } elseif ($field['id'] == 'State') { $fields['state'] = SJB_StatesManager::getStatesNamesByCountry(); } } } } $tp->assign('fields', $fields); $errors = array(); $errorId = SJB_Request::getVar('error', null, 'GET'); if ($errorId) { $errors[$errorId] = 1; } if (isset($_REQUEST['submit']) && $_FILES['file_mail']['name'] && $_FILES['file_mail']['error']) { $errorId = SJB_UploadFileManager::getErrorId($_FILES['file_mail']['error']); if ($_REQUEST['submit'] != 'save') { $mailID = SJB_Request::getVar('mail_id', 0); $parameter = $mailID ? '?edit=' . $mailID : ''; SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/' . $parameter . '&error=' . $errorId); } $errors[$errorId] = 1; } else { if (isset($_REQUEST['submit'])) { SJB_DB::query("DELETE FROM uploaded_files WHERE id = 'file_mail'"); $upload_manager = new SJB_UploadFileManager(); $upload_manager->setFileGroup('files'); $upload_manager->setUploadedFileID('file_mail'); $upload_manager->uploadFile('file_mail'); $file_name = ''; if (!isset($_REQUEST['delete_file']) && isset($_REQUEST['old_file']) && !$upload_manager->getUploadedFileName('file_mail')) { $file_name = $_REQUEST['old_file']; } elseif ($upload_manager->getUploadedFileName('file_mail')) { $file_name = "files/files/" . $upload_manager->getUploadedSavedFileName('file_mail'); } $language = SJB_Request::getVar('language', 'any'); $users = SJB_Request::getVar('users', 'any'); $without_cv = SJB_Request::getVar('without_cv', false); $country = SJB_Request::getVar('country', ''); $state = SJB_Request::getVar('state', ''); $city = SJB_Request::getVar('city', ''); $products = SJB_Request::getVar('products', array()); $user_status = SJB_Request::getVar('user_status', ''); $registration_date = SJB_Request::getVar('registration_date', array()); $param = serialize(array('language' => $language, 'users' => $users, 'without_cv' => $without_cv, 'products' => $products, 'country' => $country, 'state' => $state, 'city' => $city, 'status' => $user_status, 'registration' => $registration_date)); $email = ''; $mailSubject = SJB_Request::getVar('subject', ''); $mailText = stripcslashes(SJB_Request::getVar('text', '')); $mailID = SJB_Request::getVar('mail_id', 0); if ($mailID) { SJB_DB::query('UPDATE `mailing` SET `subject` = ?s, `text` = ?s, `email` = ?s, `file` = ?s, `param` = ?s WHERE `id` = ?s', $mailSubject, $mailText, $email, $file_name, $param, $mailID); } else { $query = "INSERT INTO mailing ( email , subject , text , file, param) VALUES ( ?s, ?s, ?s, ?s, ?s)"; SJB_DB::query($query, $email, $mailSubject, $mailText, $file_name, $param); } if ($_REQUEST['submit'] == 'save') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/'); } else { $parameter = $mailID ? '?edit=' . $mailID : ''; SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/' . $parameter); } } } if (SJB_Request::getVar('delete')) { $mailings = SJB_Request::getVar('mailing'); if (is_array($mailings)) { foreach ($mailings as $id => $value) { SJB_DB::query('DELETE FROM `mailing` WHERE `id` = ?n', $id); SJB_DB::query('DELETE FROM `mailing_info` WHERE `mailing_id` = ?n', $id); } } else { $idToDelete = SJB_Request::getInt('delete', 0); SJB_DB::query('DELETE FROM `mailing` WHERE `id` = ?n', $idToDelete); SJB_DB::query('DELETE FROM `mailing_info` WHERE `mailing_id` = ?n', $idToDelete); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/'); } if (isset($_REQUEST['edit'])) { $idToEdit = SJB_Request::getInt('edit', 0); $mail_arr = SJB_DB::query('SELECT * FROM mailing WHERE id = ?n', $idToEdit); $tp->assign("mail_id", $mail_arr[0]['id']); $tp->assign("subject", $mail_arr[0]['subject']); $tp->assign("text", $mail_arr[0]['text']); $tp->assign("file", $mail_arr[0]['file']); $tp->assign("file_url", $mail_arr[0]['file']); $tp->assign("param", unserialize($mail_arr[0]['param'])); } // get products by UserGroup ID if (SJB_Request::isAjax()) { $userGroupID = SJB_Request::getVar('usergr', 0); if ($userGroupID > 0) { $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupID); } else { $products = SJB_ProductsManager::getAllProductsInfo(); } $tp->assign("products", $products); $tp->display("mailing_products.tpl"); exit; } $mail_list = SJB_DB::query('SELECT * FROM mailing'); foreach ($mail_list as $key => $var) { $param = unserialize($mail_list[$key]['param']); $where = ''; $join = ''; $numSentEmails = SJB_DB::queryValue('SELECT count(*) FROM `mailing_info` WHERE `mailing_id` = ?n AND `status`=0', $var['id']); if ($param["language"] != 'any') { $where .= " and language='{$param['language']}'"; } if ($param["users"] != '0') { $where .= ' and u.user_group_sid=' . $param['users']; } if ($param["without_cv"]) { $join = "left join listings l on l.user_sid = u.sid"; $where .= " and l.sid is null"; } // user status if (!empty($param['status'])) { $where .= ' and `u`.`active`=' . (int) $param['status']; } // registration date if (!empty($param['registration']) && is_array($param['registration'])) { $i18n = SJB_I18N::getInstance(); if (!empty($param['registration']['not_less'])) { $where .= ' AND `u`.`registration_date` > \'' . $i18n->getInput('date', $param['registration']['not_less']) . '\''; } if (!empty($param['registration']['not_more'])) { $where .= ' AND `u`.`registration_date` < \'' . $i18n->getInput('date', $param['registration']['not_more']) . '\''; } } // products if (!empty($param['products'])) { $join .= "\n LEFT JOIN contracts ON u.sid = contracts.user_sid\n LEFT JOIN products ON products.sid = contracts.product_sid\n "; $whereProduct = array(); foreach ($param['products'] as $theProduct) { $theProduct = (int) $theProduct; if (!empty($theProduct)) { $whereProduct[] .= "products.sid = '{$theProduct}'"; } else { $whereProduct[] .= 'products.sid IS NULL'; } } if (!empty($whereProduct)) { $where .= ' AND (' . implode(' OR ', $whereProduct) . ')'; } } /// products if (!empty($param['country']) || !empty($param['state'])) { if (!empty($param['country'])) { $where_country = array(); foreach ($param['country'] as $the_country) { if (!empty($the_country)) { $where_country[] .= "`u`.`Location_Country` = '{$the_country}'"; } else { $where_country[] .= "`u`.`Location_Country` IS NULL"; } } if (!empty($where_country)) { $where .= ' AND (' . implode(' OR ', $where_country) . ')'; } } if (!empty($param['state'])) { $where_state = array(); foreach ($param['state'] as $the_state) { if (!empty($the_state)) { $where_state[] .= "`u`.`Location_State` = '{$the_state}'"; } else { $where_state[] .= "`u`.`Location_State` IS NULL"; } } } if (!empty($where_state)) { $where .= ' AND (' . implode(' OR ', $where_state) . ')'; } if (!empty($param['city'])) { $where .= " AND `u`.`Location_City` = '{$param['city']}'"; } } $mail_list[$key]['not_send'] = $numSentEmails; $mail_list[$key]['mail_arr'] = SJB_DB::query("\n SELECT u.sid as sid, u.username, u.user_group_sid, u.language\n FROM users u\n {$join}\n WHERE u.sendmail = 0\n {$where}\n GROUP BY `u`.`sid`"); $mail_list[$key]['count'] = count($mail_list[$key]['mail_arr']); } /* * test sending */ $testMailingID = SJB_Request::getVar('test_send', 0); if ($testMailingID) { if ($this->isTestEmailValid()) { $testSendResult = false; $oMailing = new SJB_Mailing($testMailingID); $mailings = SJB_Request::getVar('mailing'); if (is_array($mailings)) { foreach ($mailings as $id => $value) { $oMailing->setMailingID($id); $oMailing->setMailingList($mail_list); if ($oMailing->testSend()) { $testSendResult = true; } } } else { $oMailing->setMailingList($mail_list); $testSendResult = $oMailing->testSend(); } if ($testSendResult) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/?test_message=1'); } else { $email = urlencode(SJB_Request::getString('email', false)); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/mailing/?undeliveredMailingsForTest={$email}"); } } else { $tp->assign('testEmailNotValid', true); } } // general sending $sendToMailingID = SJB_Request::getVar('sending', 0); $sendResult = false; if ($sendToMailingID) { $oMailing = new SJB_Mailing($sendToMailingID); $mailings = SJB_Request::getVar('mailing'); $undeliveredMailingsInfo = array(); if (is_array($mailings)) { foreach ($mailings as $id => $value) { $oMailing->setMailingID($id); $oMailing->setMailingList($mail_list); $countOfSendMailings = $oMailing->send(); if ($countOfSendMailings != 0) { $sendResult = true; } $undeliveredMailingsInfo = array_merge($oMailing->getUndeliveredMailingsInfo(), $undeliveredMailingsInfo); } } else { $oMailing->setMailingList($mail_list); $countOfSendMailings = $oMailing->send(); if ($countOfSendMailings != 0) { $sendResult = true; } $undeliveredMailingsInfo = $oMailing->getUndeliveredMailingsInfo(); } if ($sendResult) { $tp->assign('send_result', $sendResult); } if (count($undeliveredMailingsInfo)) { $tp->assign("UndeliveredMailings", $oMailing->getUndeliveredMailingsInfo()); } } // send mailing to undelivered $sendToUndeliveredMailingID = SJB_Request::getVar('sendToUndeliveredEmails', 0); if (!empty($sendToUndeliveredMailingID)) { $oMailing = new SJB_Mailing($sendToUndeliveredMailingID); $oMailing->setMailingList($mail_list); $oMailing->sendToUndelivered(); if ($oMailing->getUndeliveredMailingsInfo()) { $tp->assign("UndeliveredMailings", $oMailing->getUndeliveredMailingsInfo()); } } $groups = SJB_DB::query("SELECT * FROM `user_groups`"); $products = SJB_ProductsManager::getAllProductsInfo(); $testEmail = SJB_Settings::getSettingByName('test_email'); $tp->assign('test_email', $testEmail); $tp->assign("products", $products); $tp->assign("groups", $groups); $tp->assign("mail_list", $mail_list); $tp->assign('errors', $errors); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display("mailing.tpl"); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $appsPerPage = SJB_Request::getVar('appsPerPage', 10); $this->currentPage = SJB_Request::getVar('page', 1); $currentUser = SJB_UserManager::getCurrentUser(); $appJobId = SJB_Request::getVar('appJobId', false, null, 'int'); $score = SJB_Request::getVar('score', false); $orderBy = SJB_Request::getVar('orderBy', 'date'); $order = SJB_Request::getVar('order', 'desc'); $displayTemplate = "view.tpl"; $errors = array(); // не бум пускать незарегенных if (SJB_UserManager::isUserLoggedIn() === false) { $tp->assign("ERROR", "NOT_LOGIN"); $tp->display("../miscellaneous/error.tpl"); return; } $filename = SJB_Request::getVar('filename', false); if ($filename) { $appsID = SJB_Request::getVar('appsID', false); if ($appsID) { $file = SJB_UploadFileManager::openApplicationFile($filename, $appsID); if (!$file) { $errors['NO_SUCH_FILE'] = true; } } else { $errors['NO_SUCH_APPS'] = true; } } if (!is_numeric($this->currentPage) || $this->currentPage < 1) { $this->currentPage = 1; } if (!is_numeric($appsPerPage) || $appsPerPage < 1) { $appsPerPage = 10; } if ($order != 'asc' && $order != 'desc') { $order = 'desc'; } if (!empty($score) && $score != 'passed' && $score != 'not_passed') { $score = false; } $tp->assign("orderBy", $orderBy); $tp->assign("order", $order); if (isset($orderBy) && isset($order) && $orderBy != "") { switch ($orderBy) { case "date": $orderInfo = array('sorting_field' => 'date', 'sorting_order' => $order); break; case "title": $orderInfo = array('sorting_field' => 'Title', 'sorting_order' => $order, 'inner_join' => array('table' => 'listings', 'field1' => 'sid', 'field2' => 'listing_id')); break; case "applicant": $orderInfo = false; $sortByUsername = true; break; case "status": $orderInfo = array('sorting_field' => 'status', 'sorting_order' => $order); break; case "score": $orderInfo = array('sorting_field' => 'score', 'sorting_order' => $order); break; case "company": $orderInfo = array('sorting_field' => 'CompanyName', 'sorting_order' => $order, 'inner_join' => array('table' => 'listings', 'field1' => 'sid', 'field2' => 'listing_id'), 'inner_join2' => array('table1' => 'users', 'table2' => 'listings', 'field1' => 'sid', 'field2' => 'user_sid')); break; default: $orderInfo = array('sorting_field' => 'date', 'sorting_order' => $order); } } if ($currentUser->getUserGroupSID() == 41) { // Работадатель switch (SJB_Request::getVar('action', '')) { case "approve": $applications = SJB_Request::getVar('applications', ''); if (!empty($applications)) { if (is_array($applications)) { foreach ($applications as $key => $value) { $this->approveApplication($key); } } else { $this->approveApplication($applications); } } break; case "reject": $applications = SJB_Request::getVar('applications', ''); if (!empty($applications)) { if (is_array($applications)) { foreach ($applications as $key => $value) { $this->rejectApplication($key); } } else { $this->rejectApplication($applications); } } break; case "delete": if (isset($_POST["applications"])) { foreach ($_POST["applications"] as $key => $value) { SJB_Applications::hideEmp($key); } } break; } $whereSubuser = ''; if (!empty($subuser)) { $whereSubuser = '******' . SJB_DB::quote($subuser); } $jobs = SJB_DB::query('select `Title` as `title`, `sid` as `id` from `listings` where `user_sid` = ?n' . $whereSubuser, $currentUser->sid); $listingTitle = null; foreach ($jobs as $job) { if ($job['id'] == $appJobId) { $listingTitle = $job['title']; } } $apps = $this->executeApplicationsForEmployer($appsPerPage, $appJobId, $currentUser, $score, $orderInfo, $listingTitle); if (empty($apps) && $this->currentPage > 1) { $this->currentPage = 1; $apps = $this->executeApplicationsForEmployer($appsPerPage, $appJobId, $currentUser, $score, $orderInfo, $listingTitle); } foreach ($apps as $i => $app) { $apps[$i]["job"] = SJB_ListingManager::getListingInfoBySID($apps[$i]["listing_id"]); if (!empty($apps[$i]["job"]['screening_questionnaire'])) { $screening_questionnaire = SJB_ScreeningQuestionnaires::getInfoBySID($apps[$i]["job"]['screening_questionnaire']); $passing_score = 0; switch ($screening_questionnaire['passing_score']) { case 'acceptable': $passing_score = 1; break; case 'good': $passing_score = 2; break; case 'very_good': $passing_score = 3; break; case 'excellent': $passing_score = 4; break; } if ($apps[$i]['score'] >= $passing_score) { $apps[$i]['passing_score'] = 'Passed'; } else { $apps[$i]['passing_score'] = 'Not passed'; } } if (isset($apps[$i]["resume"]) && !empty($apps[$i]["resume"])) { $apps[$i]["resumeInfo"] = SJB_ListingManager::getListingInfoBySID($apps[$i]["resume"]); } // если это анонимный соискатель - то возьмем имя из пришедшего поля 'username' if ($apps[$i]['jobseeker_id'] == 0) { $apps[$i]["user"]["FirstName"] = $apps[$i]['username']; } else { $apps[$i]["user"] = SJB_UserManager::getUserInfoBySID($apps[$i]["jobseeker_id"]); $apps[$i]['user']['stateInfo'] = SJB_StatesManager::getStateInfoBySID($apps[$i]['user']['Location_State']); if (isset($apps[$i]['user']['stateInfo']['state_code'])) { $apps[$i]['user']['Location']['State_Code'] = $apps[$i]['user']['stateInfo']['state_code']; } } } $tp->assign("appsPerPage", $appsPerPage); $tp->assign("currentPage", $this->currentPage); $tp->assign("pages", $this->pages); $tp->assign("totalPages", $this->totalPages); $tp->assign("appJobs", $jobs); $tp->assign("score", $score); $tp->assign("current_filter", $appJobId); $tp->assign("listing_title", $listingTitle); } else { // Соискатель if (SJB_Request::getVar('action', '', 'POST') == "delete") { foreach (SJB_Request::getVar('applications', array(), 'POST') as $key => $value) { SJB_Applications::hideJS($key); } } $apps = SJB_Applications::getByJobseeker($currentUser->sid, $orderInfo); for ($i = 0; $i < count($apps); ++$i) { $apps[$i]["job"] = SJB_ListingManager::getListingInfoBySID($apps[$i]["listing_id"]); $apps[$i]["company"] = SJB_UserManager::getUserInfoBySID($apps[$i]["job"]["user_sid"]); } $displayTemplate = "view_seeker.tpl"; } if (isset($sortByUsername)) { $sortKeys = array(); $order = $order == "desc" ? SORT_DESC : SORT_ASC; foreach ($apps as $key => $value) { if (!isset($apps[$key]["user"]["FirstName"])) { $apps[$key]["user"]["FirstName"] = ''; } if (!isset($apps[$key]["user"]["LastName"])) { $apps[$key]["user"]["LastName"] = ''; } $sortKeys[$key] = $apps[$key]["user"]["FirstName"] . " " . $apps[$key]["user"]["LastName"]; } array_multisort($sortKeys, $order, SORT_REGULAR, $apps); } if (empty($apps) && empty($errors['NOT_OWNER_OF_APPLICATIONS'])) { $errors['APPLICATIONS_NOT_FOUND'] = true; } $tp->assign("METADATA", SJB_Application::getApplicationMeta()); $tp->assign("applications", $apps); $tp->assign("errors", $errors); $tp->display($displayTemplate); }
/** * @param $db_table_name * @param SJB_Object $object * @param bool $sid * @param array $listingSidsForCopy * @return bool */ public static function saveObject($db_table_name, SJB_Object $object, $sid = false, $listingSidsForCopy = array()) { $object_sid = $object->getSID(); if (is_null($object_sid)) { if ($sid) { if (!SJB_DB::query("INSERT INTO ?w (sid) VALUES({$sid})", $db_table_name)) { return false; } else { $object_sid = $sid; } } elseif (!$sid && !($object_sid = SJB_DB::query("INSERT INTO ?w() VALUES()", $db_table_name))) { return false; } $object->setSID($object_sid); } if (!empty($listingSidsForCopy)) { SJB_ListingManager::copyFilesAndPicturesFromListing($listingSidsForCopy['filesFrom'], $object_sid, $listingSidsForCopy['picturesFrom']); } $object_details = $object->getDetails(); $object_properties = $object_details->getProperties(); $complexFields = array(); foreach ($object_properties as $object_property) { if (!$object_property->saveIntoBD()) { continue; } if ($object_property->isComplex()) { $complexProperties = $object_property->type->complex->getProperties(); $propertyId = $object_property->getID(); $complexFields[$propertyId] = array(); if ($complexProperties) { foreach ($complexProperties as $complexProperty) { $complexProperty->setObjectSID($object_property->object_sid); $fieldValues = $complexProperty->getValue(); if (!empty($fieldValues) && is_array($fieldValues)) { foreach ($fieldValues as $complexEnum => $value) { $complexProperty->setValue($value); $complexProperty->setComplexEnum($complexEnum); $complexProperty->setComplexParent($propertyId); $propertySqlValue = $complexProperty->getSQLValue(); $complexPropertyID = $complexProperty->getID(); $complexParameter = $complexProperty->getAddParameter(); if ($complexParameter == '') { $complexFields[$propertyId][$complexPropertyID][$complexEnum] = $propertySqlValue == 'NULL' ? NULL : $propertySqlValue; } else { $complexFields[$propertyId][$complexPropertyID][$complexEnum] = array('add_parameter' => $complexParameter, 'value' => $propertySqlValue == 'NULL' ? NULL : $propertySqlValue); } } $complexProperty->setValue($fieldValues); } } } } elseif ($object_property->isParent()) { $childProperties = $object_property->type->child->getProperties(); $parentID = $object_property->getID(); $keywords = ''; if ($childProperties) { foreach ($childProperties as $childProperty) { $childProperty->setObjectSID($object_property->object_sid); $property_id = $parentID . "_" . $childProperty->getID(); $property_sql_value = $childProperty->getSQLValue(); if ($childProperty->getID() == 'State') { $displayAS = $childProperty->display_as; $displayAS = $displayAS ? $displayAS : 'state_name'; $childProperty->type->list_values = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS); } $keywords .= $childProperty->getKeywordValue() . ' '; if (empty($property_sql_value) && in_array($childProperty->getType(), array('boolean', 'integer', 'float'))) { $property_sql_value = 0; } SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); } } $origValue = $object_property->getValue(); $object_property->setValue($keywords); $property_id = $object_property->getID(); $property_sql_value = $object_property->getSQLValue(); $object_property->setValue($origValue); SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); } else { $property_id = $object_property->getID(); $property_sql_value = $object_property->getSQLValue(); $property_sql_add_parameter = $object_property->getAddParameter(); if ($object_property->isSystem()) { if (empty($property_sql_value) && in_array($object_property->getType(), array('boolean', 'integer', 'float'))) { $property_sql_value = 0; } SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); if (!empty($property_sql_add_parameter)) { if ($object_property->getType() == 'monetary' && $object->getObjectType() != 'field') { SJB_DB::query("UPDATE `?w` SET `?w` = ?w WHERE sid = ?n", $db_table_name, $property_id . '_parameter', $property_sql_add_parameter, $object_sid); } else { SJB_DB::query("UPDATE `?w` SET `add_parameter` = ?w WHERE sid = ?n", $db_table_name, $property_sql_add_parameter, $object_sid); } } } else { if (SJB_DB::table_exists($db_table_name . "_properties")) { $property_exists = SJB_DB::queryValue("SELECT COUNT(*) FROM ?w WHERE object_sid = ?n AND id = ?s", $db_table_name . "_properties", $object_sid, $property_id); if ($property_exists) { SJB_DB::query("UPDATE ?w SET value = ?s, add_parameter = ?s WHERE object_sid = ?n AND id = ?s", $db_table_name . "_properties", $property_sql_value, $property_sql_add_parameter, $object_sid, $property_id); } else { SJB_DB::query("INSERT INTO ?w(object_sid, id , value, add_parameter) VALUES(?n, ?s, ?s, ?s)", $db_table_name . "_properties", $object_sid, $property_id, $property_sql_value, $property_sql_add_parameter); } } } } } if (!empty($complexFields)) { SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, 'complex', serialize($complexFields), $object_sid); } }
public static function getListingsFromBeyond($params) { $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($params->listing_type_sid); if ($listingTypeID == 'Job' && $GLOBALS['uri'] == '/search-results-jobs/' || $GLOBALS['uri'] == '/ajax/') { $limit = SJB_Settings::getSettingByName('countBeyondListings'); $start = $limit * ($params->listing_search_structure['current_page'] - 1) + 1; if ($limit) { // SET PARAMS FOR REQUEST $criteria = $params->criteria_saver->criteria; $categoryCriteria = isset($criteria['JobCategory']['multi_like']) ? $criteria['JobCategory']['multi_like'] : ''; $category = SJB_Settings::getSettingByName('BeyondIndustryList'); if (!empty($categoryCriteria)) { $categoryFromCriteria = self::getCategory($categoryCriteria); if ($category) { $category = explode('|', $category); $category = array_unique(array_merge($category, $categoryFromCriteria)); } else { $category = $categoryFromCriteria; } $category = implode('|', $category); } $keywords = SJB_Settings::getSettingByName('BeyondKeywords'); foreach ($criteria as $field) { if (is_array($field)) { foreach ($field as $fieldType => $values) { if ($fieldType === 'multi_like_and') { foreach ($values as $val) { if ($keywords != '') { $keywords .= ' AND '; } $keywords .= $val; } } if ($fieldType === 'location') { if (isset($values['value']) && !empty($values['value'])) { if ($keywords != '') { $keywords .= ' AND '; } $keywords .= $values['value']; } } if ($fieldType === 'like') { if ($keywords != '') { $keywords .= ' AND '; } $keywords .= $values; } } } } if (isset($criteria['keywords']) && !empty($criteria['keywords'])) { foreach ($criteria['keywords'] as $key => $item) { if (in_array($key, array('exact_phrase', 'any_words', 'all_words', 'like'))) { if (!empty($keywords)) { $keywords .= ' OR '; } $keywords .= $item; } } } if (substr($keywords, -4) == ' OR ') { $keywords = substr($keywords, 0, strlen($keywords) - 4); } $keywords = trim($keywords); $keywords = urlencode($keywords); $keywords = !empty($keywords) ? "({$keywords})" : ''; $city = ''; if (!empty($criteria['Location_City']['like'])) { $city = urlencode($criteria['Location_City']['like']); } else { if (!empty($criteria['Location_City']['multi_like_and'][0])) { $city = urlencode($criteria['Location_City']['multi_like_and'][0]); } else { if (!empty($criteria['Location']['location']['value'])) { $city = urlencode($criteria['Location']['location']['value']); } } } $state = SJB_Settings::getSettingByName('BeyondState'); if (isset($criteria['Location_State']['multi_like'])) { foreach ($criteria['Location_State']['multi_like'] as $stateSID) { if (!empty($stateSID)) { $stateInfo = SJB_StatesManager::getStateInfoBySID($stateSID); $state = !empty($stateInfo['state_code']) ? $stateInfo['state_code'] : ''; } } } $countryCriteria = isset($criteria['Location_Country']['multi_like'][0]) ? $criteria['Location_Country']['multi_like'][0] : SJB_Settings::getSettingByName('BeyondCountry'); $country = SJB_Settings::getSettingByName('BeyondCountry'); if ($countryCriteria && is_numeric($countryCriteria)) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($countryCriteria); $country = !empty($countryInfo['country_code']) ? $countryInfo['country_code'] : ''; } $employmentTypeCriteria = isset($criteria['EmploymentType']['multi_like']) ? $criteria['EmploymentType']['multi_like'] : ''; $employmentType = SJB_Settings::getSettingByName('BeyonEmploymentType'); if ($employmentTypeCriteria) { $employmentType = self::getEmploymentType($employmentTypeCriteria); } $zipCode = SJB_Settings::getSettingByName('BeyondZipcode'); if (isset($criteria['Location_ZipCode']['geo']['location']) && !empty($criteria['Location_ZipCode']['geo']['location'])) { $zipCode = $criteria['Location_ZipCode']['geo']['location']; } $educationLevel = SJB_Settings::getSettingByName('BeyonEducationLevel'); $experienceLevel = SJB_Settings::getSettingByName('BeyonExperienceLevel'); $affID = SJB_Settings::getSettingByName('BeyondAffiliateID'); $isIPhone = false; if (class_exists('MobilePlugin')) { $isIPhone = MobilePlugin::isPhone(); } if (str_replace('www.', '', $_SERVER['HTTP_HOST']) === SJB_Settings::getValue('mobile_url') || SJB_Settings::getValue('detect_iphone') && $isIPhone) { $mobileAffID = SJB_Settings::getSettingByName('MobileBeyondAffiliateID'); $affID = $mobileAffID ? $mobileAffID : $affID; } $url = "http://www.beyond.com/common/services/job/search/default.asp?aff={$affID}&kw={$keywords}&kt=3&il={$category}&ct={$country}&st={$state}&zc={$zipCode}&el={$educationLevel}&et={$employmentType}&ex={$experienceLevel}&nw=e&pn={$start}&mx={$limit}&fwhere={$city}"; $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL and pass it to the browser $xml = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); $beyondListings = array(); if ($xml !== false) { $doc = new DOMDocument(); $doc->loadXML($xml, LIBXML_NOERROR | LIBXML_NOWARNING); $results = $doc->getElementsByTagName('Item'); if ($results instanceof DOMNodeList) { // if we need just total results number foreach ($results as $node) { $resultXML = simplexml_import_dom($node); $jobKey = (string) $resultXML->SourceInformationID; $location = explode(',', (string) $resultXML->Location); $state = ''; $stateCode = ''; $country = ''; $city = !empty($location[0]) ? $location[0] : ''; if (isset($location[1])) { $location = explode(' ', trim($location[1])); if (!empty($location[0])) { $stateCode = trim($location[0]); $state = self::getState($stateCode); } if (!empty($location[1])) { $country = self::getCountry(trim($location[1])); } } $beyondListings[$jobKey] = array('Title' => (string) $resultXML->Title, 'CompanyName' => (string) $resultXML->CompanyName, 'JobDescription' => (string) $resultXML->ShortDescription, 'JobCategory' => (string) $resultXML->CareerFocus, 'State' => $state, 'Country' => $country, 'City' => $city, 'Location' => array('Country' => $country, 'State' => $state, 'State_Code' => $stateCode, 'City' => $city), 'url' => SJB_System::getSystemSettings('SITE_URL') . '/partnersite/?url=' . base64_encode((string) $resultXML->ApplyURL), 'jobkey' => $jobKey, 'activation_date' => (string) $resultXML->Modified, 'api' => 'beyond', 'code' => '<span id=beyond_at><a href="http://www.beyond.com/">jobs</a> by <a href="http://www.beyond.com/" title="Job Search"><img src="' . SJB_System::getSystemSettings('SITE_URL') . '/system/plugins/beyond_integration_plugin/logo.png" style="border: 0; vertical-align: middle;" alt="Beyond job search"></a></span>'); } } else { SJB_Logger::error('CANT GET BEYOND XML RESULTS'); } } else { SJB_Logger::error('NOT VALID RESPONSE FROM BEYOND'); } self::$beyondListings = $beyondListings; } } return $params; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'list'); $fieldSID = SJB_Request::getVar('field_sid', false); $parentSID = SJB_Request::getVar('sid', false); $errors = null; if ($fieldSID) { $tp->assign('field_sid', $fieldSID); $field_info = SJB_ListingFieldManager::getFieldInfoBySID($fieldSID); $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($field_info['listing_type_sid']); $tp->assign("field_info", $field_info); $tp->assign("type_info", $listing_type_info); $tp->assign("type_sid", isset($listing_type_info['sid']) ? $listing_type_info['sid'] : false); switch ($action) { case 'edit': $form_submitted = SJB_Request::getVar('submit_form', false); $sid = SJB_Request::getVar('sid', 0); $listingFieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoBySID($sid); $listingFieldInfo = array_merge($listingFieldInfo, $_REQUEST); $listingField = new SJB_ListingField($listingFieldInfo); $listingField->deleteProperty('type'); $listingField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($listingFieldInfo['hidden']) ? $listingFieldInfo['hidden'] : '', 'is_system' => true)); $profileField = SJB_Request::getVar('profile_field', false); if ($form_submitted) { if ($profileField) { $listingFieldInfo['default_value'] = ''; $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id']; } else { $listingFieldInfo['profile_field_as_dv'] = ''; } } if (!empty($listingFieldInfo['default_value_setting'])) { if ($listingFieldInfo['default_value_setting'] == 'default_country') { $listingFieldInfo['default_value'] = $listingFieldInfo['default_value_setting']; $listingFieldInfo['profile_field_as_dv'] = ''; } elseif ($listingFieldInfo['default_value_setting'] == 'profile_field') { $listingFieldInfo['default_value'] = ''; $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id']; } } $additionalParameters = array(); if ($listingFieldInfo['id'] == 'Country') { $additionalParameters = array('list_values' => SJB_CountriesManager::getAllCountriesCodesAndNames()); $display_as = array('id' => 'display_as', 'caption' => 'Display Country as', 'type' => 'list', 'value' => isset($listingFieldInfo['display_as']) ? $listingFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'country_name', 'caption' => 'Country Name'), array('id' => 'country_code', 'caption' => 'Country Code')), 'is_system' => true, 'is_required' => true); } elseif ($listingFieldInfo['id'] == 'State') { $defaultCountry = SJB_ListingFieldManager::getDefaultCountryByParentSID($fieldSID); $additionalParameters['list_values'] = array(); if (is_numeric($defaultCountry)) { $additionalParameters['list_values'] = SJB_StatesManager::getStatesNamesByCountry($defaultCountry); } elseif (!empty($defaultCountry)) { $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id']; $tp->assign('disableField', 1); } else { $additionalParameters['comment'] = 'Please select default country first to select default State'; } $display_as = array('id' => 'display_as', 'caption' => 'Display State as', 'type' => 'list', 'value' => isset($listingFieldInfo['display_as']) ? $listingFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'state_name', 'caption' => 'State Name'), array('id' => 'state_code', 'caption' => 'State Code')), 'is_system' => true, 'is_required' => true); } $default_value = array('id' => 'default_value', 'sid' => isset($listingFieldInfo['sid']) ? $listingFieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['default_value']) ? $listingFieldInfo['default_value'] : '', 'type' => $listingField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($listingFieldInfo['add_parameter']) ? $listingFieldInfo['add_parameter'] : ''); $default_value = array_merge($default_value, $additionalParameters); $listingField->addProperty($default_value); $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['profile_field_as_dv']) ? $listingFieldInfo['profile_field_as_dv'] : '', 'type' => 'list', 'length' => '', 'is_required' => false, 'is_system' => true); $listingField->addProperty($profile_field_as_dv); if (isset($display_as)) { $listingField->addProperty($display_as); } if ($form_submitted) { $listingField->addInfillInstructions(SJB_Request::getVar('instructions')); } else { $listingField->addInfillInstructions(isset($listingFieldInfo['instructions']) ? $listingFieldInfo['instructions'] : ''); } $ListingFieldForm = new SJB_Form($listingField); $ListingFieldForm->registerTags($tp); $listingField->setSID($sid); $addValidParam = array('field' => 'parent_sid', 'value' => $parentSID); if ($form_submitted && $ListingFieldForm->isDataValid($errors, $addValidParam)) { SJB_ListingFieldManager::saveListingField($listingField); if ($listingFieldInfo['id'] == 'Country') { $profileFieldAsDv = $listingField->getPropertyValue('profile_field_as_dv'); if ($profileFieldAsDv) { $listingFieldsInfo = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($fieldSID); foreach ($listingFieldsInfo as $fieldInfo) { if ($fieldInfo['id'] == 'State') { $listingField = new SJB_ListingField($fieldInfo); $listingField->setSID($fieldInfo['sid']); $default_value = array('id' => 'default_value', 'sid' => isset($fieldInfo['sid']) ? $fieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => '', 'type' => $listingField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($fieldInfo['add_parameter']) ? $fieldInfo['add_parameter'] : ''); $listingField->addProperty($default_value); $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => 'State', 'type' => 'list', 'length' => '', 'is_required' => false, 'is_system' => true); $listingField->addProperty($profile_field_as_dv); SJB_ListingFieldManager::saveListingField($listingField); } } } } if (SJB_Request::getVar('apply') == 'no' && empty($errors)) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-listing-field/edit-location-fields/?field_sid=" . $fieldSID); } } $ListingFieldForm->makeDisabled('id'); $tp->assign('profileFieldAsDV', !empty($listingFieldInfo['profile_field_as_dv'])); $tp->assign('listingFieldInfo', $listingFieldInfo); $tp->assign("field_type", $listingField->getFieldType()); $tp->assign("sid", $sid); $tp->assign("form_fields", $ListingFieldForm->getFormFieldsInfo()); $tp->assign("errors", $errors); $tp->display("edit_location_field.tpl"); break; case 'move_up': SJB_ListingFieldManager::moveUpFieldBySID($fieldSID); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-location-fields/?field_sid=" . $parentSID); break; case 'move_down': SJB_ListingFieldManager::moveDownFieldBySID($fieldSID); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-location-fields/?field_sid=" . $parentSID); break; } if ($action == 'list') { $listingFieldsInfo = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($fieldSID); $listingFields = array(); $listingFieldSids = array(); foreach ($listingFieldsInfo as $listingFieldInfo) { $listingField = new SJB_ListingField($listingFieldInfo); $listingField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($listingFieldInfo['hidden']) ? $listingFieldInfo['hidden'] : '', 'is_system' => true)); $listingField->setSID($listingFieldInfo['sid']); $listingFields[] = $listingField; $listingFieldSids[] = $listingFieldInfo['sid']; } $form_collection = new SJB_FormCollection($listingFields); $form_collection->registerTags($tp); $tp->assign("listing_field_sids", $listingFieldSids); $tp->display("listing_location_fields.tpl"); } } }
function assignTemplateVariables($params) { global $variables_to_assign; $variables_to_assign = array(); if ($this->objectHasProperty($params['property'])) { $object_property = $this->getObjectProperty($params['property']); $variables_to_assign = $object_property->getPropertyVariablesToAssign(); } if (!empty($params['complexParent'])) { $complexParent = $params['complexParent']; $object = $this->object_properties[$complexParent]->type->complex; $object_properties = $object->getProperties(); if (isset($object_properties[$params['property']])) { $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); } if (isset($params['complexStep']) && !empty($this->object_properties[$complexParent]->value)) { if (is_string($this->object_properties[$complexParent]->value)) { $complexValue = unserialize($this->object_properties[$complexParent]->value); } else { $complexValue = $this->object_properties[$complexParent]->value; } //exception for monetary type if (!isset($variables_to_assign['list_currency'])) { $variables_to_assign['value'] = ''; } if (isset($complexValue[$params['property']]) && isset($complexValue[$params['property']][$params['complexStep']])) { if ($object_properties[$params['property']]->getType() === 'date' && $object_properties[$params['property']]->type->getConvertToDBDate()) { $field = $object_properties[$params['property']]; $field->type->property_info['value'] = $complexValue[$params['property']][$params['complexStep']]; if ($field->isValid() !== true) { $complexValue[$params['property']][$params['complexStep']] = ''; } $variables_to_assign['value'] = SJB_I18N::getInstance()->getInput('date', $complexValue[$params['property']][$params['complexStep']]); } elseif ($object_properties[$params['property']]->getType() == 'monetary') { if (isset($complexValue[$params['property']][$params['complexStep']]['value'])) { $variables_to_assign['value']['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']]['value'], ENT_QUOTES, "UTF-8"); } else { $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8"); } } elseif ($object_properties[$params['property']]->getType() == 'multilist') { $value = $complexValue[$params['property']][$params['complexStep']]; if (!is_array($value) && strpos($value, ',')) { $variables_to_assign['value'] = explode(',', $value); } else { $variables_to_assign['value'] = $value; } } elseif ($object_properties[$params['property']]->getType() !== 'text') { $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8"); } else { $variables_to_assign['value'] = $complexValue[$params['property']][$params['complexStep']]; } } } } if (!empty($params['parent'])) { $parent = $params['parent']; $object = $this->object_properties[$parent]->type->child; $object_properties = $object->getProperties(); if (isset($object_properties[$params['property']])) { $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); } elseif (strpos($params['property'], '.Code')) { $params['property'] = str_replace('.Code', '', $params['property']); if (!isset($object_properties[$params['property']])) { return false; } $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); if ($params['property'] == 'State') { $country = !empty($params['country']) ? $params['country'] : false; $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_code'); } $variables_to_assign['displayAS'] = 'Code'; } else { $params['property'] = str_replace('.Name', '', $params['property']); if (!isset($object_properties[$params['property']])) { return false; } $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); if ($params['property'] == 'State') { $country = !empty($params['country']) ? $params['country'] : false; $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_name'); } $variables_to_assign['displayAS'] = 'Name'; } } if (isset($params['fields'])) { $fields = $params['fields']; $object_property = $this->getObjectProperty($params['property']); $fieldProperties = $object_property->type->child->getProperties(); foreach ($fieldProperties as $key => $property) { if (!array_key_exists($property->getSID(), $fields)) { $object_property->type->child->deleteProperty($key); } } foreach ($fields as $key => $field) { $object_property->type->child->addProperty($field); } $variables_to_assign = $object_property->getPropertyVariablesToAssign(); } if (isset($params['complexStep'])) { $variables_to_assign['complexStep'] = $params['complexStep']; } if (isset($params['parameters'])) { $variables_to_assign = array_merge($variables_to_assign, array('parameters' => $params['parameters'])); } // made for FormBuilders Complex Fields. so admin could define custom html code if (isset($params['customHtml']) && !empty($params['customHtml'])) { $variables_to_assign['customHtml'] = trim($params['customHtml']); } $variables_to_assign = array_merge($variables_to_assign, $this->getVariablesToAssign($params)); $varToAssignValueIsEmpty = $this->isEmptyVariablesToAssignValue($variables_to_assign); if (($this->useDefaultValues || !$this->object->getSID()) && $varToAssignValueIsEmpty && $this->errors === false) { if ($variables_to_assign['default_value'] != '') { if (is_array($variables_to_assign['default_value'])) { $variables_to_assign['default_value']['currency'] = $variables_to_assign['default_value']['add_parameter']; } $variables_to_assign['value'] = $variables_to_assign['default_value']; } else { if ($variables_to_assign['profile_field_as_dv'] != '') { $variables_to_assign['value'] = htmlentities($variables_to_assign['profile_field_as_dv'], ENT_QUOTES, 'UTF-8'); } } } // заглушка для email - когда в value попадает массив из одного элемента [original] if ($variables_to_assign['id'] == 'email') { if (is_array($variables_to_assign['value'])) { $variables_to_assign['value'] = array_pop($variables_to_assign['value']); } } $variables_to_assign['defaultCountry'] = SJB_Settings::getSettingByName('default_country'); if (isset($params['searchWithin'])) { $variables_to_assign['searchWithin'] = $params['searchWithin']; } if (!isset($variables_to_assign['displayAS'])) { $variables_to_assign['displayAS'] = false; } if ($variables_to_assign['id'] == 'default_value' && in_array($this->object->getProperty('default_value')->getType(), array('list', 'multilist'))) { $variables_to_assign['sort_by_alphabet'] = $this->object->getPropertyValue('sort_by_alphabet'); } foreach ($variables_to_assign as $variable_name => $variable_value) { $this->template_processor->assign($variable_name, $variable_value); } return true; }
private static function changeLocationProperties(&$exportProperties, &$exportData) { $locationFieldsInfo = SJB_UserProfileFieldManager::getFieldsInfoByType('location'); foreach ($locationFieldsInfo as $fieldInfo) { if (isset($exportProperties[$fieldInfo['id']])) { unset($exportProperties[$fieldInfo['id']]); $exportLocationProperties[$fieldInfo['id'] . '.Country'] = $fieldInfo['id'] . '.Country'; $exportLocationProperties[$fieldInfo['id'] . '.State'] = $fieldInfo['id'] . '.State'; $exportLocationProperties[$fieldInfo['id'] . '.City'] = $fieldInfo['id'] . '.City'; $exportLocationProperties[$fieldInfo['id'] . '.ZipCode'] = $fieldInfo['id'] . '.ZipCode'; $exportLocationProperties[$fieldInfo['id'] . '.Address'] = $fieldInfo['id'] . '.Address'; ksort($exportLocationProperties); $exportProperties = array_merge($exportProperties, $exportLocationProperties); foreach ($exportData as $userSID => $property) { if (isset($property[$fieldInfo['id']]) && is_array($property[$fieldInfo['id']])) { $propertyLocation = array(); foreach ($property[$fieldInfo['id']] as $locationField => $fieldValue) { if ($locationField == 'Country' && !empty($locationField)) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($fieldValue); $fieldValue = !empty($countryInfo['country_name']) ? $countryInfo['country_name'] : ''; } elseif ($locationField == 'State') { $stateInfo = SJB_StatesManager::getStateInfoBySID($fieldValue); $fieldValue = !empty($stateInfo['state_name']) ? $stateInfo['state_name'] : ''; } $propertyLocation[$fieldInfo['id'] . '.' . $locationField] = $fieldValue; } unset($property[$fieldInfo['id']]); ksort($propertyLocation); $exportData[$userSID] = array_merge($property, $propertyLocation); } } } } }
private function _getRequestdata(array $parameters) { $res = array(); for ($i = 0; $i < $this->getLevel(); $i++) { $value = $this->_getValue($i); $filterItem = $this->schema[$i]; $field = $filterItem['field']; $parent = isset($parameters['parent']) ? $parameters['parent'] : false; $this->type = $filterItem['type']; switch ($filterItem['type']) { case 'tree': $sids = SJB_ListingFieldTreeManager::getChildrenSIDBySID($value); $sids = array_merge($sids, array($value)); $sids = implode(",", $sids); $res[$field]['tree'] = $sids; break; case 'string': case 'integer': $res[$field]['equal'] = $value; case 'list': case 'multilist': if ($parent && in_array($field, array($parent . '_State', $parent . '_Country'))) { $fieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($filterItem['sid']); if ($field == $parent . '_State') { $listValues = SJB_StatesManager::getHashedListItems($fieldInfo['display_as']); } elseif ($field == $parent . '_Country') { $listValues = SJB_CountriesManager::getHashedListItems($fieldInfo['display_as']); } } else { $listingFieldListItemManager = SJB_ObjectMother::createListingFieldListItemManager(); $listValues = $listingFieldListItemManager->getHashedListItemsByFieldSID($filterItem['sid']); } foreach ($listValues as $id => $val) { if (strtolower($val) == strtolower($value)) { $value = $id; } } if ($filterItem['type'] == 'multilist') { $res[$field]['multi_like'][] = $value; } else { $res[$field]['equal'] = $value; } break; } } $res['active']['equal'] = 1; if (!empty($this->listing_type_id)) { $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($this->listing_type_id); if (!$listing_type_sid) { trigger_error("Can't set filter by listing type for unknown type: '" . $this->listing_type_id . "'.", E_USER_WARNING); } $res['listing_type_sid']['equal'] = $listing_type_sid; if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid)) { $res['status']['equal'] = 'approved'; } } return $res; }
public static function getCurrentSearchByCriteria($criteria) { $returnArray = array(); $locationFields = SJB_ListingFieldManager::getFieldsInfoByType('location'); foreach ($criteria as $fieldName => $field) { if (!in_array($fieldName, array('listing_type', 'active', 'username', 'status', 'CompanyName', 'keywords', 'PostedWithin', 'anonymous'))) { $result = array(); $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldName); if (!$fieldInfo) { foreach ($locationFields as $locationField) { $locationSubFields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($locationField['sid']); foreach ($locationSubFields as $locationSubField) { if ($fieldName == $locationField['id'] . "_" . $locationSubField['id']) { $fieldInfo = $locationSubField; $fieldInfo['id'] = $locationField['id'] . "_" . $locationSubField['id']; } } } } foreach ($field as $fieldType => $fieldValue) { switch ($fieldType) { case 'geo': if ($fieldValue['location'] !== '') { $result[$fieldName][$fieldType][$fieldValue['location']] = $fieldValue['location']; } break; case 'location': if (!empty($fieldValue['value'])) { $result[$fieldName][$fieldType][$fieldValue['value']] = $fieldValue['value']; } break; case 'monetary': if (!empty($fieldValue['not_less']) && $fieldValue['not_less'] !== '') { $result[$fieldName][$fieldType][$fieldValue['not_less']] = $fieldValue['not_less']; } if (!empty($fieldValue['not_more']) && $fieldValue['not_more'] !== '') { $result[$fieldName][$fieldType][$fieldValue['not_more']] = $fieldValue['not_more']; } break; case 'multi_like': $listItem = new SJB_ListingFieldListItemManager(); if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { if ($fieldInfo['type'] == 'tree') { $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'"); $name = $name ? $name : ''; $result[$fieldName][$fieldType][$value] = $name; } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') { if (!empty($fieldInfo['parent_sid'])) { if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') { $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']); } else { $listValues = $fieldInfo['list_values']; } foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $result[$fieldName][$fieldType][$value] = $listValue['caption']; break; } } } else { $itemInfo = $listItem->getListItemBySID($value); $caption = $itemInfo ? $itemInfo->getValue() : $value; $result[$fieldName][$fieldType][$value] = $caption; } } else { $result[$fieldName][$fieldType][$value] = $value; } } } } elseif ($fieldValue !== '') { $itemInfo = $listItem->getListItemBySID($fieldValue); $caption = $itemInfo ? $itemInfo->getValue() : $fieldValue; $result[$fieldName][$fieldType][$fieldValue] = $caption; } break; case 'tree': $fieldValue = $fieldValue ? explode(',', $fieldValue) : ""; if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'"); $name = $name ? $name : ''; $result[$fieldName][$fieldType][$value] = $name; } } } break; case 'multi_like_and': if (is_array($fieldValue)) { $listItem = new SJB_ListingFieldListItemManager(); foreach ($fieldValue as $value) { if ($value !== '') { if ($fieldInfo['type'] == 'tree') { $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'"); $name = $name ? $name : ''; $result[$fieldName][$fieldType][$value] = $name; } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') { if (!empty($fieldInfo['parent_sid'])) { if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') { $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']); } else { $listValues = $fieldInfo['list_values']; } foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $result[$fieldName][$fieldType][$value] = $listValue['caption']; break; } } } else { $itemInfo = $listItem->getListItemBySID($value); $caption = $itemInfo ? $itemInfo->getValue() : $value; $result[$fieldName][$fieldType][$value] = $caption; } } else { $result[$fieldName][$fieldType][$value] = $value; } } } } elseif ($fieldValue !== '') { $result[$fieldName][$fieldType][$fieldValue] = $fieldValue; } break; default: if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { $result[$fieldName][$fieldType][$value] = $value; } } } elseif ($fieldValue !== '') { $result[$fieldName][$fieldType][$fieldValue] = $fieldValue; } break; } } if ($result && !empty($fieldInfo)) { $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption']; $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']]; } } elseif ($fieldName == 'CompanyName') { $result = array(); $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'"); if ($userFieldSID) { $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID); foreach ($field as $fieldType => $fieldValue) { switch ($fieldType) { case 'multi_like_and': if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { $result[$fieldName][$fieldType][$value] = $value; } } } elseif ($fieldValue !== '') { $result[$fieldName][$fieldType][$fieldValue] = $fieldValue; } break; } } } if ($result && !empty($fieldInfo)) { $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption']; $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']]; } } elseif ($fieldName == 'keywords') { foreach ($field as $key => $val) { if ($val) { $returnArray['keywords']['field'][$key][$val] = $val; } } if (isset($returnArray['keywords'])) { $returnArray['keywords']['name'] = 'Keywords'; } } } return $returnArray; }
public static function deleteCountryBySID($sid) { SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_FIELDS)); SJB_StatesManager::deleteStatesByCountrySID($sid); return SJB_DB::query("DELETE FROM `countries` WHERE `sid` = ?n", $sid); }