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 static function saveLocation($location) { $location_sid = $location->getSID(); $countryInfo = SJB_CountriesManager::getCountryInfoBySID($location->country_sid); $locationField = $location->name . " " . $location->city . " " . $location->state . " " . $location->state_code; if ($countryInfo) { $locationField .= " " . $countryInfo['country_name'] . " " . $countryInfo['country_code']; } $locationField = explode(' ', $locationField); foreach ($locationField as $key => $field) { $field = trim($field); $len = strlen($field); if ($len < 4) { for ($i = $len; $i < 4; $i++) { $field .= '_'; } $locationField[$key] = $field; } } $locationField = implode(' ', $locationField); if (is_null($location_sid)) { return SJB_DB::query("INSERT INTO `locations` (`name`, `longitude`, `latitude`, `city`, `state`, `state_code`, `country_sid`, `location`) VALUES (?s, ?f, ?f, ?s, ?s, ?s, ?n, ?s)", $location->name, $location->longitude, $location->latitude, $location->city, $location->state, $location->state_code, $location->country_sid, $locationField, false); } return SJB_DB::query("UPDATE `locations` SET `name` = ?s, `longitude` = ?f, `latitude` = ?f, `city` = ?s, `state` = ?s, `state_code` = ?s, `country_sid` = ?n, `location` = ?s WHERE `sid` = ?n", $location->name, $location->longitude, $location->latitude, $location->city, $location->state, $location->state_code, $location->country_sid, $locationField, $location->getSID()); }
public function execute() { $templateProcessor = SJB_System::getTemplateProcessor(); $errors = array(); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $gateway_id = isset($_REQUEST['gateway']) ? $_REQUEST['gateway'] : null; $formSubmitted = SJB_Request::getVar('submit'); $gateway_sid = SJB_PaymentGatewayManager::getSIDByID($gateway_id); if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($action)) { if ($action == 'deactivate') { SJB_PaymentGatewayManager::deactivateByID($gateway_id); } elseif ($action == 'activate') { SJB_PaymentGatewayManager::activateByID($gateway_id); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $gateway = SJB_PaymentGatewayManager::createObjectByID($gateway_id, $_REQUEST); $gateway->dontSaveProperty('id'); $gateway->dontSaveProperty('caption'); $gateway->setSID($gateway_sid); if ($gateway->isValid()) { if (SJB_PaymentGatewayManager::saveGateway($gateway) !== false) { $templateProcessor->assign('gatewaySaved', true); if ($formSubmitted == 'save_gateway') { $siteUrl = SJB_System::getSystemsettings('SITE_URL') . '/system/payment/gateways/?gatewaySaved=1'; SJB_HelperFunctions::redirect($siteUrl); } } else { $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = 1; } } else { $errors = $gateway->getErrors(); } } $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id); $gateway_form = new SJB_Form($gateway); $gateway_form->registerTags($templateProcessor); $gateway_form->makeDisabled('id'); $gateway_form->makeDisabled('caption'); $countryCode = $gateway->getPropertyValue('country'); if (empty($countryCode)) { $countryValue = SJB_CountriesManager::getCountrySIDByCountryCode('US'); $gateway->setPropertyValue('country', $countryValue); } if (empty($gateway)) { $errors['GATEWAY_NOT_FOUND'] = 1; $templateProcessor->assign('errors', $errors); $templateProcessor->display('configure_gateway.tpl'); return; } $gateway_info = SJB_PaymentGatewayManager::getInfoBySID($gateway_sid); $form_fields = $gateway_form->getFormFieldsInfo(); $templateProcessor->assign('gateway', $gateway_info); $templateProcessor->assign('form_fields', $form_fields); $templateProcessor->assign('errors', $errors); $templateProcessor->display('configure_gateway.tpl'); }
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; }
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 function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $form_submitted = SJB_Request::getVar('action'); $page = SJB_Request::getVar('page'); if ($form_submitted) { if (SJB_System::getSystemSettings("isDemo")) { $errors[] = "You don't have permissions for it. This is a Demo version of the software."; } else { if (!empty($_REQUEST['bad_words'])) { $_REQUEST['bad_words'] = trim($_REQUEST['bad_words']); } SJB_Settings::updateSettings($_REQUEST); } if ($form_submitted == 'apply_settings') { $tp->assign("page", $page); } } $i18n = SJB_I18N::getInstance(); $tp->assign("settings", SJB_Settings::getSettings()); $ds = DIRECTORY_SEPARATOR; $path = SJB_BASE_DIR . "system{$ds}cache{$ds}agents_bots.txt"; $disable_bots = file_get_contents($path); $tp->assign("disable_bots", $disable_bots); $tp->assign("timezones", timezone_identifiers_list()); if (!SJB_SubAdmin::getSubAdminSID()) { $tp->assign("subadmins", SJB_SubAdminManager::getAllSubAdminsInfo()); } $tp->assign("errors", $errors); $tp->assign("i18n_domains", $i18n->getDomainsData()); $tp->assign("i18n_languages", $i18n->getActiveLanguagesData()); $tp->assign("countries", SJB_CountriesManager::getAllCountriesCodesAndNames()); $tp->assign('listingEmailTemplates', SJB_EmailTemplateEditor::getEmailTemplatesByGroup(SJB_NotificationGroups::GROUP_ID_LISTING)); $tp->assign('productEmailTemplates', SJB_EmailTemplateEditor::getEmailTemplatesByGroup(SJB_NotificationGroups::GROUP_ID_PRODUCT)); $tp->assign('userEmailTemplates', SJB_EmailTemplateEditor::getEmailTemplatesByGroup(SJB_NotificationGroups::GROUP_ID_USER)); $tp->assign('otherEmailTemplates', SJB_EmailTemplateEditor::getEmailTemplatesByGroup(SJB_NotificationGroups::GROUP_ID_OTHER)); $tp->display("settings.tpl"); }
public static function getUserProfileFieldInfoBySID($user_profile_field_sid) { $field_info = parent::getObjectInfo("user_profile_fields", $user_profile_field_sid); if (in_array($field_info['type'], array('list', 'multilist'))) { if (!empty($field_info['parent_sid'])) { if ($field_info['id'] == 'Country') { $displayAS = !empty($field_info['display_as']) ? $field_info['display_as'] : 'country_name'; $field_info['list_values'] = SJB_CountriesManager::getAllCountriesCodesAndNames(true, $displayAS); } } else { $field_info['list_values'] = SJB_UserProfileFieldDBManager::getListValuesBySID($user_profile_field_sid); } } elseif ($field_info['type'] == 'tree') { $field_info['tree_values'] = SJB_UserProfileFieldTreeManager::getTreeValuesBySID($user_profile_field_sid); $field_info['tree_depth'] = SJB_UserProfileFieldTreeManager::getTreeDepthBySID($user_profile_field_sid); } elseif ($field_info['type'] == 'monetary') { $field_info['currency_values'] = SJB_CurrencyManager::getActiveCurrencyList(); } elseif ($field_info['type'] == 'location') { $field_info['fields'] = SJB_UserProfileFieldManager::getUserProfileFieldsInfoByParentSID($user_profile_field_sid); } return $field_info; }
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() { $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'); } }
private function assignCurrentUserCountry() { $user = SJB_UserManager::getCurrentUser(); if ($user) { $locationValue = $user->getPropertyValue('Location'); $country = SJB_Array::get($locationValue, 'Country'); if ($country) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country); $this->getTemplateProcessor()->assign('curUserCountryInfo', $countryInfo); } } }
/** * @param SJB_Object $object * @return SJB_Object */ public static function fillRegistrationDataWithUser(SJB_Object $object) { if ($oProfile = self::getProfileObject()) { /** @var $oProperty SJB_ObjectProperty */ foreach ($object->getProperties() as $oProperty) { $value = false; switch ($oProperty->getID()) { case 'Country': case 'CurrentCountry': case 'City': case 'CurrentCity': if (!empty($oProfile->location) && !empty($oProfile->location['name'])) { $location = explode(', ', $oProfile->location['name']); if ('Country' == $oProperty->getID() || 'CurrentCountry' == $oProperty->getID()) { $value = count($location) > 2 ? !empty($location[2]) ? $location[2] : '' : (!empty($location[1]) ? $location[1] : ''); } elseif ('City' == $oProperty->getID() || 'CurrentCity' == $oProperty->getID()) { $value = !empty($location[0]) ? $location[0] : ''; } } break; case 'Location': $country = ''; $city = ''; if (!empty($oProfile->location) && !empty($oProfile->location['name'])) { $location = explode(', ', $oProfile->location['name']); $country = count($location) > 2 ? !empty($location[2]) ? $location[2] : '' : (!empty($location[1]) ? $location[1] : ''); $country = $country ? SJB_CountriesManager::getCountrySIDByCountryName($country) : ''; $city = !empty($location[0]) ? $location[0] : ''; } $reqVal = SJB_Request::getVar($oProperty->getID(), false); if (empty($reqVal)) { $location = $object->getChild('Location'); $propertyInfo = $location->getPropertyInfo('Country'); if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) { $location->setPropertyValue('Country', $country); } $propertyInfo = $location->getPropertyInfo('City'); if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) { $location->setPropertyValue('City', $city); } } break; case 'WorkExperience': if (!empty($oProfile->work)) { $aWork = array(); foreach ($oProfile->work as $position) { $work = ''; if (!empty($position['employer'])) { $work .= $position['employer']['name'] . "\r\n"; } if (!empty($position['location'])) { $work .= $position['location']['name'] . "\r\n"; } if (!empty($position['start_date'])) { $work .= $position['start_date'] . "\r\n"; } if (!empty($position['end_date'])) { $work .= $position['end_date'] . "\r\n"; } if (!empty($work)) { $aWork[] = $work; } } $value = implode("\r\n", $aWork); } break; case 'Education': if (!empty($oProfile->education)) { $aEducation = array(); foreach ($oProfile->education as $education) { $sEducation = ''; if (!empty($education['school'])) { $sEducation = $education['school']['name']; } if (!empty($education['year'])) { $sEducation .= '(' . $education['year']['name'] . '):<br/>'; } if (!empty($education['type'])) { $sEducation .= $education['type'] . "\r\n"; } if (!empty($education['concentration'])) { foreach ($education['concentration'] as $concentration) { $sEducation .= '<br/>' . $concentration['name'] . "\r\n"; } } if (!empty($education['classes'])) { foreach ($education['classes'] as $classes) { $sEducation .= '<br/>' . $classes['name'] . ' : ' . $classes['description'] . "\r\n"; } } if (!empty($sEducation)) { array_push($aEducation, $sEducation); } } $value = implode("\r\n", $aEducation); } break; case 'Title': case 'TITLE': $value = 'My Resume'; break; case 'FirstName': if (!empty($oProfile->first_name)) { $value = $oProfile->first_name; } break; case 'LastName': if (!empty($oProfile->last_name)) { $value = $oProfile->last_name; } break; case 'ContactName': if (!empty($oProfile->name)) { $value = $oProfile->name; } break; case 'WebSite': if (!empty($oProfile->website)) { $value = $oProfile->website; } break; case 'CompanyName': if (!empty($oProfile->work) && !empty($oProfile->work[0]['employer']['name'])) { $value = $oProfile->work[0]['employer']['name']; } break; case 'CompanyDescription': if (!empty($oProfile->summary)) { $value = $oProfile->summary; } break; case 'email': if (!empty($oProfile->email) && !SJB_Request::getVar('email', null)) { $value = array('original' => $oProfile->email, 'confirmed' => $oProfile->email); } break; case 'sendmail': $value = false; break; case 'username': case 'password': continue 2; break; default: $propertyCanBeDeleted = !in_array($oProperty->getID(), self::$aUserFields) && !in_array($oProperty->getID(), self::$aListingFields) && !$oProperty->isRequired(); if ($propertyCanBeDeleted) { $object->deleteProperty($oProperty->getID()); continue 2; } break; } if (!empty($value)) { $reqVal = SJB_Request::getVar($oProperty->getID(), false); if (empty($reqVal)) { // if user did not modified his data in form $object->setPropertyValue($oProperty->getID(), $value); } } } } return $object; }
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'); } }
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"); }
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 getDetails() { $common_details = parent::getDetails(); $specific_details = array(array('id' => 'user_name', 'caption' => 'PayPal Pro User name', 'type' => 'string', 'length' => '20', 'is_required' => true, 'is_system' => false), array('id' => 'user_password', 'caption' => 'PayPal Pro User password', 'type' => 'string', 'length' => '20', 'is_required' => true, 'is_system' => false), array('id' => 'user_signature', 'caption' => 'PayPal Pro User signature', 'type' => 'string', 'length' => '50', 'is_required' => true, 'is_system' => false), array('id' => 'use_sandbox', 'caption' => 'PayPal Pro Sandbox <br /> <span class=\'note\'>check to enable PayPal Sandbox</span>', 'type' => 'boolean', 'length' => '20', 'is_required' => false, 'is_system' => false), array('id' => 'https', 'caption' => 'https <br /> <span class=\'note\'>works only if SSL certificate is set up in the system</span>', 'type' => 'boolean', 'length' => '20', 'is_required' => false, 'is_system' => false), array('id' => 'country', 'caption' => 'Country <br /> <span class=\'note\'>The country your PayPal Pro account is registered in</span>', 'type' => 'list', 'list_values' => SJB_CountriesManager::getCountriesCodesAndNamesByCodes(array('US', 'CA', 'UK')), 'is_required' => true, 'is_system' => false)); return array_merge($common_details, $specific_details); }
public function execute() { ini_set('max_execution_time', 0); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $preview = SJB_Request::getVar('preview', false); $importedDataForPreview = array(); $template_processor = SJB_System::getTemplateProcessor(); $errors = null; $start_line = SJB_Request::getVar('start_line', null); $name_column = SJB_Request::getVar('name_column', null); $longitude_column = SJB_Request::getVar('longitude_column', null); $latitude_column = SJB_Request::getVar('latitude_column', null); $city_column = SJB_Request::getVar('city_column', null); $state_column = SJB_Request::getVar('state_column', null); $state_code_column = SJB_Request::getVar('state_code_column', null); $country_sid = SJB_Request::getVar('country_sid', null); $file_format = SJB_Request::getVar('file_format', null); $fields_delimiter = SJB_Request::getVar('fields_delimiter', null); $imported_file_config['start_line'] = $start_line; $imported_file_config['name_column'] = $name_column; $imported_file_config['longitude_column'] = $longitude_column; $imported_file_config['latitude_column'] = $latitude_column; $imported_file_config['city_column'] = $city_column; $imported_file_config['state_column'] = $state_column; $imported_file_config['state_code_column'] = $state_code_column; $imported_file_config['file_format'] = $file_format; $imported_file_config['fields_delimiter'] = $fields_delimiter; $imported_location_count = null; if (isset($_FILES['imported_geo_file']) && !$_FILES['imported_geo_file']['error']) { $fileInfo = $_FILES['imported_geo_file']; $fileFormats = array('csv', 'xls', 'xlsx'); $pathInfo = pathinfo($fileInfo['name']); $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : ''; if (!in_array(strtolower($fileExtension), $fileFormats)) { $errors['File'] = 'WRONG_FORMAT'; } if (empty($_FILES['imported_geo_file']['name'])) { $errors['File'] = 'EMPTY_VALUE'; } if (empty($start_line)) { $errors['Start Line'] = 'EMPTY_VALUE'; } elseif (!is_numeric($start_line) || !is_int($start_line + 0)) { $errors['Start Line'] = 'NOT_INT_VALUE'; } if (empty($name_column)) { $errors['Name Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($name_column) || !is_int($name_column + 0)) { $errors['Name Column'] = 'NOT_INT_VALUE'; } if (empty($longitude_column)) { $errors['Longitude Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($longitude_column) || !is_int($longitude_column + 0)) { $errors['Longitude Column'] = 'NOT_INT_VALUE'; } if (empty($latitude_column)) { $errors['Latitude Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($latitude_column) || !is_int($latitude_column + 0)) { $errors['Latitude Column'] = 'NOT_INT_VALUE'; } if (empty($country_sid)) { $errors['Country'] = 'EMPTY_VALUE'; } if (!SJB_ImportFile::isValidFileExtensionByFormat($file_format, $_FILES['imported_geo_file'])) { $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT'; } if (!SJB_ImportFile::isValidFileCharset($_FILES['imported_geo_file'], $encodingFromCharset)) { $errors['Charset'] = 'CHARSET_INCORRECT'; } if (is_null($errors)) { set_time_limit(0); $file_info = SJB_Array::get($_FILES, 'imported_geo_file'); if (!strcasecmp($file_format, 'excel')) { $import_file = new SJB_ImportFileXLS($file_info); } else { if ($fields_delimiter == 'semicolon') { $fields_delimiter = ';'; } elseif ($fields_delimiter == 'tab') { $fields_delimiter = "\t"; } else { $fields_delimiter = ','; } $import_file = new SJB_ImportFileCSV($file_info, $fields_delimiter); } $import_file->parse($encodingFromCharset); $imported_data = $import_file->getData(); $imported_location_count = 0; $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country_sid); foreach ($imported_data as $key => $importedColumn) { if (empty($importedColumn[$name_column - 1]) || empty($importedColumn[$longitude_column - 1]) || empty($importedColumn[$latitude_column - 1]) || $start_line > $key) { continue; } $name = $importedColumn[$name_column - 1]; $longitude = $importedColumn[$longitude_column - 1]; $latitude = $importedColumn[$latitude_column - 1]; $city = isset($importedColumn[$city_column - 1]) ? $importedColumn[$city_column - 1] : null; $state = isset($importedColumn[$state_column - 1]) ? $importedColumn[$state_column - 1] : null; $state_code = isset($importedColumn[$state_code_column - 1]) ? $importedColumn[$state_code_column - 1] : null; if ($preview) { if (count($importedDataForPreview) >= 10) { break; } $importedDataForPreview[] = array('name' => $name, 'longitude' => $longitude, 'latitude' => $latitude, 'city' => $city, 'state' => $state, 'stateCode' => $state_code, 'country' => $countryInfo['country_name']); } else { $imported_location_count += SJB_LocationManager::addLocation($name, $longitude, $latitude, $city, $state, $state_code, $country_sid, $countryInfo); } } } } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { $errorSid = isset($_FILES['imported_geo_file']['error']) ? $_FILES['imported_geo_file']['error'] : 0; $errors['File'] = SJB_UploadFileManager::getErrorId($errorSid); } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $template_processor->assign("charSets", SJB_HelperFunctions::getCharSets()); $template_processor->assign("importedGeographicData", $importedDataForPreview); $template_processor->assign("countries", $countries); $template_processor->assign("country_sid", $country_sid); $template_processor->assign("errors", $errors); $template_processor->assign("imported_location_count", $imported_location_count); $template_processor->assign("imported_file_config", $imported_file_config); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); if ($preview) { $template_processor->display("import_geographic_data_preview.tpl"); } else { $template_processor->display("import_geographic_data_form.tpl"); } }
public static function getDetails() { return array(array('id' => 'tax_name', 'caption' => 'Tax Name', 'type' => 'unique_string', 'length' => '20', 'table_name' => 'taxes', 'is_required' => true, 'is_system' => true, 'validators' => array('SJB_StringWithoutTagsValidator')), array('id' => 'Country', 'caption' => 'Country', 'type' => 'list', 'list_values' => SJB_CountriesManager::getAllCountriesCodesAndNames(), 'table_name' => 'taxes', 'is_required' => false, 'is_system' => true), array('id' => 'State', 'caption' => 'State', 'type' => 'list', 'table_name' => 'taxes', 'list_values' => array(), 'is_required' => false, 'is_system' => true), array('id' => 'tax_rate', 'caption' => 'Tax Rate', 'type' => 'float', 'table_name' => 'taxes', 'length' => '10', 'is_required' => true, 'is_system' => true, 'minimum' => '0', 'maximum' => '100'), array('id' => 'active', 'caption' => 'Active', 'type' => 'boolean', 'table_name' => 'taxes', 'is_required' => false, 'is_system' => true), array('id' => 'price_includes_tax', 'caption' => 'Price Includes Tax', 'type' => 'boolean', 'table_name' => 'taxes', 'is_required' => false, 'is_system' => true)); }
public static function getListingsFromIndeed($params) { $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($params->listing_type_sid); if ($listingTypeID == 'Job' && $GLOBALS['uri'] == '/search-results-jobs/' || $GLOBALS['uri'] == '/ajax/') { $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : $params->listing_search_structure['current_page']; $publisherID = SJB_Settings::getSettingByName('IndeedPublisherID'); $limit = SJB_Settings::getSettingByName('countIndeedListings'); $ip = $_SERVER['REMOTE_ADDR']; $userAgent = urlencode(SJB_Request::getUserAgent()); $start = $limit * ($page - 1); $stateIndexes = array('AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', 'DC' => 'District of Columbia', 'AS' => 'American Samoa', 'GU' => 'Guam', 'MP' => 'Northern Mariana Islands', 'PR' => 'Puerto Rico', 'UM' => "United's Minor Outlying Islands", 'VI' => 'Virgin Islands'); $countryCodes = array('United States' => 'us', 'Argentina' => 'ar', 'Australia' => 'au', 'Austria' => 'at', 'Bahrain' => 'bh', 'Belgium' => 'be', 'Brazil' => 'br', 'Canada' => 'ca', 'Chile' => 'cl', 'China' => 'cn', 'Colombia' => 'co', 'Czech Republic' => 'cz', 'Denmark' => 'dk', 'Finland' => 'fi', 'France' => 'fr', 'Germany' => 'de', 'Greece' => 'gr', 'Hong Kong' => 'hk', 'Hungary' => 'hu', 'India' => 'in', 'Indonesia' => 'id', 'Ireland' => 'ie', 'Israel' => 'il', 'Italy' => 'it', 'Japan' => 'jp', 'Korea' => 'kr', 'Kuwait' => 'kw', 'Luxembourg' => 'lu', 'Malaysia' => 'my', 'Mexico' => 'mx', 'Netherlands' => 'nl', 'New Zealand' => 'nz', 'Norway' => 'no', 'Oman' => 'om', 'Pakistan' => 'pk', 'Peru' => 'pe', 'Philippines' => 'ph', 'Poland' => 'pl', 'Portugal' => 'pt', 'Qatar' => 'qa', 'Romania' => 'ro', 'Russia' => 'ru', 'Russian Federation' => 'ru', 'Saudi Arabia' => 'sa', 'Singapore' => 'sg', 'South Africa' => 'za', 'Spain' => 'es', 'Sweden' => 'se', 'Switzerland' => 'ch', 'Taiwan' => 'tw', 'Turkey' => 'tr', 'United Arab Emirates' => 'ae', 'United Kingdom' => 'gb', 'Venezuela' => 've'); $countryDomains = array('us' => 'indeed.com', 'ar' => 'ar.indeed.com', 'au' => 'au.indeed.com', 'at' => 'at.indeed.com', 'bh' => 'bh.indeed.com', 'be' => 'be.indeed.com', 'br' => 'indeed.com.br', 'ca' => 'ca.indeed.com', 'cl' => 'indeed.cl', 'cn' => 'cn.indeed.com', 'co' => 'co.indeed.com', 'cz' => 'cz.indeed.com', 'dk' => 'dk.indeed.com', 'fi' => 'indeed.fi', 'fr' => 'indeed.fr', 'de' => 'de.indeed.com', 'gr' => 'gr.indeed.com', 'hk' => 'indeed.hk', 'hu' => 'hu.indeed.com', 'in' => 'indeed.co.in', 'id' => 'id.indeed.com', 'ie' => 'ie.indeed.com', 'il' => 'il.indeed.com', 'it' => 'it.indeed.com', 'jp' => 'jp.indeed.com', 'kr' => 'kr.indeed.com', 'kw' => 'kw.indeed.com', 'lu' => 'indeed.lu', 'my' => 'indeed.com.my', 'mx' => 'indeed.com.mx', 'nl' => 'indeed.nl', 'nz' => 'nz.indeed.com', 'no' => 'no.indeed.com', 'om' => 'om.indeed.com', 'pk' => 'indeed.com.pk', 'pe' => 'indeed.com.pe', 'ph' => 'indeed.com.ph', 'pl' => 'pl.indeed.com', 'pt' => 'indeed.pt', 'qa' => 'qa.indeed.com', 'ro' => 'ro.indeed.com', 'ru' => 'ru.indeed.com', 'sa' => 'sa.indeed.com', 'sg' => 'indeed.com.sg', 'za' => 'indeed.co.za', 'es' => 'indeed.es', 'se' => 'se.indeed.com', 'ch' => 'indeed.ch', 'tw' => 'tw.indeed.com', 'tr' => 'tr.indeed.com', 'ae' => 'indeed.ae', 'gb' => 'indeed.co.uk', 've' => 've.indeed.com'); // SET PARAMS FOR REQUEST $keywords = ''; $criteria = $params->criteria_saver->criteria; $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('JobCategory'); $fieldInfo = SJB_ListingFieldDBManager::getListValuesBySID($fieldSID); $fieldList = array(); foreach ($fieldInfo as $val) { $fieldList[$val['id']] = $val['caption']; } $categoryCriteria = isset($criteria['JobCategory']['multi_like']) ? $criteria['JobCategory']['multi_like'] : ''; if (!empty($categoryCriteria)) { if (!empty($keywords)) { $keywords .= ' or '; } foreach ($categoryCriteria as $category) { if (!empty($category) && !empty($fieldList[$category])) { $keywords .= $fieldList[$category] . ' or '; } } $keywords = substr($keywords, 0, strlen($keywords) - 4); } foreach ($criteria as $fieldName => $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 (isset($criteria['keywords']) && !empty($criteria['keywords'])) { foreach ($criteria['keywords'] as $key => $item) { if (in_array($key, array('exact_phrase', 'any_words', 'all_words'))) { 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); $location = self::getLocation($criteria); if (isset($criteria['Location']['location']['radius']) && !empty($criteria['Location']['location']['radius'])) { if ($criteria['Location']['location']['radius'] == 'any') { $radius = ''; } else { $radius = $criteria['Location']['location']['radius']; } } else { $radius = 0; } $indeedCountry = SJB_Settings::getSettingByName('IndeedCountry'); $country = !empty($criteria['Location_Country']['multi_like'][0]) ? $criteria['Location_Country']['multi_like'][0] : $indeedCountry; $codes = array_values($countryCodes); if (!in_array($country, $codes)) { // ok. Country value - not correct Indeed value. Lets try convert it. if (is_numeric($country)) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country); $country = !empty($countryInfo['country_code']) ? $countryInfo['country_code'] : ''; } } $jobType = SJB_Settings::getSettingByName('IndeedJobType'); $siteType = SJB_Settings::getSettingByName('IndeedSiteType'); $sort = SJB_Settings::getSettingByName('IndeedSort'); $highlight = SJB_Settings::getSettingByName('IndeedHighlightKeywords'); $url = "http://api.indeed.com/ads/apisearch?publisher={$publisherID}&q={$keywords}&l={$location}&sort={$sort}&radius={$radius}&st={$siteType}&jt={$jobType}&start={$start}&limit={$limit}&fromage=&filter=&latlong=1&co={$country}&highlight={$highlight}&chnl=&userip={$ip}&useragent={$userAgent}&v=2"; $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); curl_close($ch); $indeedListings = array(); if ($xml !== false) { $doc = new DOMDocument(); try { $doc->loadXML($xml, LIBXML_NOERROR); $results = $doc->getElementsByTagName('results'); if ($results instanceof DOMNodeList) { $outputCountry = array_flip($countryCodes); $totalResults = $doc->getElementsByTagName('totalresults')->item(0)->nodeValue; $totalPages = ceil((int) $totalResults / $limit); $pageNumber = $doc->getElementsByTagName('pageNumber')->item(0)->nodeValue; $indeedDomain = !empty($indeedCountry) && isset($countryDomains[$indeedCountry]) ? $countryDomains[$indeedCountry] : $countryDomains['us']; if (strpos($indeedDomain, '.') !== 2) { $indeedDomain = 'www.' . $indeedDomain; } foreach ($results as $node) { foreach ($node->getElementsByTagName('result') as $result) { $resultXML = simplexml_import_dom($result); $jobKey = (string) $resultXML->jobkey; $state = (string) $resultXML->state; $country = (string) $resultXML->country; $indeedListings[$jobKey] = array('Title' => (string) $resultXML->jobtitle, 'CompanyName' => (string) $resultXML->company, 'JobDescription' => (string) $resultXML->snippet, 'Location' => array('Country' => empty($country) ? '' : $outputCountry[strtolower($country)], 'State' => empty($state) ? '' : isset($stateIndexes[strtoupper($state)]) ? $stateIndexes[strtoupper($state)] : $state, 'State_Code' => empty($state) ? '' : strtoupper($state), 'City' => (string) $resultXML->city), 'url' => (string) $resultXML->url, 'onmousedown' => ' onMouseDown="' . (string) $resultXML->onmousedown . '" ', 'target' => ' target="_blank" ', 'jobkey' => $jobKey, 'activation_date' => (string) $resultXML->date, 'api' => 'indeed', 'code' => '<span id="indeed_at"><a href="' . SJB_Request::getProtocol() . '://' . $indeedDomain . '/">jobs</a> by <a href="' . SJB_Request::getProtocol() . '://' . $indeedDomain . '/" title="Job Search"><img src="' . SJB_Request::getProtocol() . '://www.indeed.com/p/jobsearch.gif" style="border: 0; vertical-align: middle;" alt="Indeed job search"></a></span>', 'pageNumber' => $pageNumber, 'totalPages' => $totalPages); } } } else { SJB_Logger::error('CANT GET INDEED XML RESULTS'); } } catch (ErrorException $e) { SJB_Logger::error($e->getMessage()); } } else { SJB_Logger::error('NOT VALID RESPONSE FROM INDEED'); } self::$indeedListings = $indeedListings; } return $params; }
/** * @param SJB_Object $object * @return SJB_Object */ public static function fillRegistrationDataWithUser(SJB_Object $object) { if (self::$oSocialPlugin instanceof LinkedinSocialPlugin && ($oProfile = self::getProfileObject())) { /** @var $oProperty SJB_ObjectProperty */ foreach ($object->getProperties() as $oProperty) { $value = ''; switch ($oProperty->getID()) { case 'Country': if (!empty($oProfile->location->country->code)) { $value = SJB_Countries::getCountryNameByISO2((string) $oProfile->location->country->code); } break; case 'Location': $country = ''; $city = ''; $address = ''; if (!empty($oProfile->location->country->code)) { $country = SJB_Countries::getCountryNameByISO2((string) $oProfile->location->country->code); $country = $country ? SJB_CountriesManager::getCountrySIDByCountryName($country) : ''; } if (!empty($oProfile->location->name)) { $city = $oProfile->location->name; } if (!empty($oProfile->{'main-address'})) { $address = $oProfile->{'main-address'}; } $location = $object->getChild('Location'); $propertyInfo = $location->getPropertyInfo('Country'); if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) { $location->setPropertyValue('Country', $country); } $propertyInfo = $location->getPropertyInfo('City'); if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) { $location->setPropertyValue('City', $city); } $propertyInfo = $location->getPropertyInfo('Address'); if ($propertyInfo && (!$propertyInfo['hidden'] || isset($propertyInfo['madeHidden']))) { $location->setPropertyValue('Address', $address); } break; case 'DateOfBirth': if (!empty($oProfile->{'date-of-birth'})) { $year = !empty($oProfile->{'date-of-birth'}->year) ? (string) $oProfile->{'date-of-birth'}->year : '0000'; $month = !empty($oProfile->{'date-of-birth'}->month) ? (string) $oProfile->{'date-of-birth'}->month : '00'; $day = !empty($oProfile->{'date-of-birth'}->day) ? (string) $oProfile->{'date-of-birth'}->day : '00'; $value = SJB_I18N::getInstance()->getDate($day . '-' . $month . '-' . $year); } break; case 'FirstName': if (!empty($oProfile->{'first-name'})) { $value = $oProfile->{'first-name'}; } break; case 'LastName': if (!empty($oProfile->{'last-name'})) { $value = $oProfile->{'last-name'}; } break; case 'ContactName': if (!empty($oProfile->{'last-name'})) { $value = $oProfile->{'first-name'} . ' ' . $oProfile->{'last-name'}; } break; case 'WebSite': // WebSite if (!empty($oProfile->website)) { $value = $oProfile->website; } break; case 'Title': case 'TITLE': if (!empty($oProfile->positions->position->title)) { $value = $oProfile->positions->position->title; } break; case 'CompanyName': if (!empty($oProfile->positions->position->company->name)) { $value = $oProfile->positions->position->company->name; } break; case 'CompanyDescription': if (!empty($oProfile->summary)) { $value = $oProfile->summary; } break; case 'City': if (!empty($oProfile->location->name)) { $value = $oProfile->location->name; } break; case 'PhoneNumber': if (!empty($oProfile->{'phone-numbers'})) { $aPhoneNumbers = array(); foreach (self::$oProfile->{'phone-numbers'}->{'phone-number'} as $phone) { array_push($aPhoneNumbers, $phone->{'phone-number'} . ' (' . $phone->{'phone-type'} . ')'); } $value = implode(', ', $aPhoneNumbers); } break; case 'jsTwitter': if (!empty($oProfile->{'twitter-accounts'})) { $aTwitters = array(); foreach (self::$oProfile->{'twitter-accounts'}->{'twitter-account'} as $twitter) { array_push($aTwitters, $twitter->{'provider-account-name'}); } $value = implode(', ', $aTwitters); } break; case 'Address': if (!empty($oProfile->{'main-address'})) { $value = $oProfile->{'main-address'}; } break; case 'sendmail': $value = false; break; case 'email': if (!empty($oProfile->{'email-address'}) && !SJB_Request::getVar('email', null)) { $value = array('original' => $oProfile->{'email-address'}, 'confirmed' => $oProfile->{'email-address'}); } break; case 'username': case 'password': continue 2; break; default: $propertyCanBeDeleted = !in_array($oProperty->getID(), self::$aUserFields) && !in_array($oProperty->getID(), self::$aListingFields) && !$oProperty->isRequired(); if ($propertyCanBeDeleted) { $object->deleteProperty($oProperty->getID()); } break; } if (!empty($value)) { $reqVal = SJB_Request::getVar($oProperty->getID(), false); if (empty($reqVal)) { // if user did not modified his data in form $object->setPropertyValue($oProperty->getID(), $value); } } } } return $object; }
public static function setComplexFields(&$listing_field_info) { switch ($listing_field_info['type']) { case 'list': case 'multilist': if (!empty($listing_field_info['parent_sid'])) { if ($listing_field_info['id'] == 'Country') { $displayAS = !empty($listing_field_info['display_as']) ? $listing_field_info['display_as'] : 'country_name'; $listing_field_info['list_values'] = SJB_CountriesManager::getAllCountriesCodesAndNames(true, $displayAS); } } else { $listing_field_info['list_values'] = SJB_ListingFieldDBManager::getListValuesBySID($listing_field_info['sid']); } break; case 'tree': $listing_field_info['tree_values'] = SJB_ListingFieldDBManager::getTreeValuesBySID($listing_field_info['sid']); $listing_field_info['tree_depth'] = SJB_ListingFieldDBManager::getTreeDepthBySID($listing_field_info['sid']); break; case 'monetary': $listing_field_info['currency_values'] = SJB_CurrencyManager::getActiveCurrencyList(); break; case 'complex': $listing_field_info['fields'] = SJB_ListingFieldDBManager::getListingFieldsInfoByParentSID($listing_field_info['sid']); $listing_field_info['table_name'] = 'listings'; break; case 'location': $listing_field_info['fields'] = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($listing_field_info['sid']); break; case 'geo': if (isset($listing_field_info['parent_sid'])) { $parentID = SJB_DB::queryValue("SELECT `id` FROM `listing_fields` WHERE `sid` = ?n", $listing_field_info['parent_sid']); $listing_field_info['parentID'] = $parentID; } break; } $listing_field_info['is_classifieds'] = 1; }
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"); } } }
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; }
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); } } } } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $location = new SJB_Location($_REQUEST); $action_name = SJB_Request::getVar('action_name', false); $action = SJB_Request::getVar('action', false); $action = $action_name ? $action_name : $action; $paginator = new SJB_GeographicDataPagination(); $search = ''; $params = array(); $locationAdded = false; switch ($action) { case 'add': if ($location->isDataValid($errors)) { if (SJB_LocationManager::saveLocation($location)) { $location = new SJB_Location(); $locationAdded = true; } else { $errors['Name'] = 'NOT_UNIQUE_VALUE'; } } break; case 'delete': $location_sid = SJB_Request::getVar('location_sid', false); if (!$location_sid) { $locations_sids = SJB_Request::getVar('locations', false); if ($locations_sids) { foreach ($locations_sids as $l_sid => $value) { SJB_LocationManager::deleteLocationBySID($l_sid); } } } else { SJB_LocationManager::deleteLocationBySID($location_sid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/geographic-data/'); break; case 'clear_data': SJB_LocationManager::deleteAllLocations(); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/geographic-data/'); break; case 'search': $searchParams = SJB_Request::getVar('search', false); $search .= 'WHERE 1 '; if (!empty($searchParams['name'])) { $search .= "AND l.`name` LIKE ?s"; $params[] = "%{$searchParams['name']}%"; } if (!empty($searchParams['longitude'])) { $search .= " AND l.`longitude` LIKE ?s"; $params[] = "%{$searchParams['longitude']}%"; } if (!empty($searchParams['latitude'])) { $search .= " AND l.`latitude` LIKE ?s"; $params[] = "%{$searchParams['latitude']}%"; } if (!empty($searchParams['city'])) { $search .= " AND l.`city` LIKE ?s"; $params[] = "%{$searchParams['city']}%"; } if (!empty($searchParams['state'])) { $search .= " AND l.`state` LIKE ?s"; $params[] = "%{$searchParams['state']}%"; } if (!empty($searchParams['state_code'])) { $search .= " AND l.`state_code` LIKE ?s"; $params[] = "%{$searchParams['state_code']}%"; } if (!empty($searchParams['country_sid'])) { $search .= " AND l.`country_sid` = ?n"; $params[] = "{$searchParams['country_sid']}"; } $tp->assign('search', $searchParams); $searchQuery['action'] = 'search'; $searchQuery['search'] = $searchParams; $paginator->setUniqueUrlParam(trim(http_build_query($searchQuery))); break; } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $location_info = $location->getInfo(); $paginator->setItemsCount(SJB_LocationManager::getLocationNumber($search, $params)); $location_collection = SJB_LocationManager::getLocationsInfoWithLimit(($paginator->currentPage - 1) * $paginator->itemsPerPage, $paginator->itemsPerPage, $search, $paginator->sortingField, $paginator->sortingOrder, $params); unset($_REQUEST['zip_codes_per_page']); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); $tp->assign('locationAdded', $locationAdded); $tp->assign('countries', $countries); $tp->assign('query', http_build_query($_REQUEST)); $tp->assign('errors', $errors); $tp->assign('location_info', $location_info); $tp->assign('location_collection', $location_collection); $tp->display('geographic_data.tpl'); }