public function execute() { $tp = SJB_System::getTemplateProcessor(); $countrySID = SJB_Request::getVar('country_sid', false); $stateSID = SJB_Request::getVar('state_sid', false); $parentID = SJB_Request::getVar('parentID', false); $caption = SJB_Request::getVar('caption', 'State'); $type = SJB_Request::getVar('type', false); $displayAs = SJB_Request::getVar('display_as', 'state_name'); $displayAs = $displayAs == 'state_name' || $displayAs == 'state_code' ? $displayAs : 'state_name'; $result = array(); if ($countrySID) { $result = SJB_StatesManager::getStatesNamesByCountry($countrySID, true, $displayAs); } $tp->assign("caption", $caption); $tp->assign("value", $stateSID); $tp->assign("list_values", $result); $tp->assign("parentID", $parentID); if (!empty($countrySID)) { $tp->assign("enabled", true); } if ($type == 'search') { $tp->assign("id", $parentID . '_State'); $tp->display("../field_types/search/list.tpl"); } else { $tp->assign("id", 'State'); $tp->display("../field_types/input/list.tpl"); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $count_listing = SJB_Request::getVar('count_listing', 10, null, 'int'); $current_user = SJB_UserManager::getCurrentUser(); if (SJB_UserManager::isUserLoggedIn()) { $lastAddedListing = SJB_ListingManager::getLastAddedListingByUserSID($current_user->getSID()); if ($lastAddedListing) { $properties = $current_user->getProperties(); $phrase['title'] = $lastAddedListing->getPropertyValue('Title'); foreach ($properties as $property) { if ($property->getType() == 'location') { $fields = $property->type->child; $childProperties = $fields->getProperties(); foreach ($childProperties as $childProperty) { if (in_array($childProperty->getID(), array('City', 'State', 'Country'))) { $value = $childProperty->getValue(); switch ($childProperty->getType()) { case 'list': if ($childProperty->getID() == 'State') { $displayAS = $childProperty->display_as; $displayAS = $displayAS ? $displayAS : 'state_name'; $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS); } else { $listValues = $childProperty->type->list_values; } foreach ($listValues as $values) { if ($value == $values['id']) { $phrase[strtolower($childProperty->getID())] = $values['caption']; } } break; default: $phrase[strtolower($childProperty->getID())] = $value; break; } } } } } $phrase = array_diff($phrase, array('')); $phrase = implode(" ", $phrase); $listing_type_id = "Job"; $request['action'] = 'search'; $request['listing_type']['equal'] = $listing_type_id; $request['default_listings_per_page'] = $count_listing; $request['default_sorting_field'] = "activation_date"; $request['default_sorting_order'] = "DESC"; $request['keywords']['relevance'] = $phrase; $searchResultsTP = new SJB_SearchResultsTP($request, $listing_type_id, array('field' => 'keywords', 'value' => $phrase)); $tp = $searchResultsTP->getChargedTemplateProcessor(); } $tp->display('suggested_jobs.tpl'); } }
function getData($non_existed_values_flag, $values = array()) { $listFieldsInfo = SJB_ListingFieldManager::getFieldsInfoByType('list'); $multilistFieldsInfo = SJB_ListingFieldManager::getFieldsInfoByType('multilist'); $fieldsInfo = array_merge($listFieldsInfo, $multilistFieldsInfo); foreach ($fieldsInfo as $key => $fieldInfo) { if (empty($fieldInfo['parent_sid'])) { $fieldsInfo[$fieldInfo['id']] = $fieldInfo; } unset($fieldsInfo[$key]); } $result = array(); foreach ($this->properties_names as $key => $property_name) { if (in_array($property_name, array_keys($fieldsInfo)) && isset($values[$key])) { $fieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldsInfo[$property_name]['sid']); if (!empty($fieldInfo['parent_sid']) && $fieldInfo['id'] == 'State') { $fieldInfo['list_values'] = SJB_StatesManager::getStatesNamesByCountry(false, true); } switch ($fieldInfo['type']) { case 'list': foreach ($fieldInfo['list_values'] as $listValues) { if ($listValues['caption'] == $values[$key]) { $result[$property_name] = $listValues['id']; break; } } break; case 'multilist': $multilistValues = explode(',', $values[$key]); $multilistDisplayValues = array(); foreach ($fieldInfo['list_values'] as $listValues) { if (in_array($listValues['caption'], $multilistValues)) { $multilistDisplayValues[] = $listValues['id']; } } $result[$property_name] = implode(',', $multilistDisplayValues); break; } } else { if (strpos($property_name, 'date') && strtotime($values[$key]) == false) { if ($property_name == 'activation_date') { $values[$key] = date('Y-m-d H:i:s'); } else { $values[$key] = ''; } } $result[$property_name] = isset($values[$key]) ? $values[$key] : null; } } $result = $result + $this->_getTreeValues($values, $non_existed_values_flag); return $result; }
public static function createTemplateStructureForTax($tax_info) { $tax = new SJB_Taxes($tax_info); foreach ($tax->getProperties() as $property) { if ($property->getType() == 'list') { $value = $property->getValue(); $properties = $property->type->property_info; if ($properties['id'] == 'State') { $properties['list_values'] = SJB_StatesManager::getStatesNamesByCountry($tax->getPropertyValue('Country')); } $listValues = isset($properties['list_values']) ? $properties['list_values'] : array(); $caption = null; foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $caption = $listValue['caption']; break; } } $tax_info[$property->getID()] = isset($caption) ? $caption : ''; } } return $tax_info; }
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"); }
/** * @param $db_table_name * @param SJB_Object $object * @param bool $sid * @param array $listingSidsForCopy * @return bool */ public static function saveObject($db_table_name, SJB_Object $object, $sid = false, $listingSidsForCopy = array()) { $object_sid = $object->getSID(); if (is_null($object_sid)) { if ($sid) { if (!SJB_DB::query("INSERT INTO ?w (sid) VALUES({$sid})", $db_table_name)) { return false; } else { $object_sid = $sid; } } elseif (!$sid && !($object_sid = SJB_DB::query("INSERT INTO ?w() VALUES()", $db_table_name))) { return false; } $object->setSID($object_sid); } if (!empty($listingSidsForCopy)) { SJB_ListingManager::copyFilesAndPicturesFromListing($listingSidsForCopy['filesFrom'], $object_sid, $listingSidsForCopy['picturesFrom']); } $object_details = $object->getDetails(); $object_properties = $object_details->getProperties(); $complexFields = array(); foreach ($object_properties as $object_property) { if (!$object_property->saveIntoBD()) { continue; } if ($object_property->isComplex()) { $complexProperties = $object_property->type->complex->getProperties(); $propertyId = $object_property->getID(); $complexFields[$propertyId] = array(); if ($complexProperties) { foreach ($complexProperties as $complexProperty) { $complexProperty->setObjectSID($object_property->object_sid); $fieldValues = $complexProperty->getValue(); if (!empty($fieldValues) && is_array($fieldValues)) { foreach ($fieldValues as $complexEnum => $value) { $complexProperty->setValue($value); $complexProperty->setComplexEnum($complexEnum); $complexProperty->setComplexParent($propertyId); $propertySqlValue = $complexProperty->getSQLValue(); $complexPropertyID = $complexProperty->getID(); $complexParameter = $complexProperty->getAddParameter(); if ($complexParameter == '') { $complexFields[$propertyId][$complexPropertyID][$complexEnum] = $propertySqlValue == 'NULL' ? NULL : $propertySqlValue; } else { $complexFields[$propertyId][$complexPropertyID][$complexEnum] = array('add_parameter' => $complexParameter, 'value' => $propertySqlValue == 'NULL' ? NULL : $propertySqlValue); } } $complexProperty->setValue($fieldValues); } } } } elseif ($object_property->isParent()) { $childProperties = $object_property->type->child->getProperties(); $parentID = $object_property->getID(); $keywords = ''; if ($childProperties) { foreach ($childProperties as $childProperty) { $childProperty->setObjectSID($object_property->object_sid); $property_id = $parentID . "_" . $childProperty->getID(); $property_sql_value = $childProperty->getSQLValue(); if ($childProperty->getID() == 'State') { $displayAS = $childProperty->display_as; $displayAS = $displayAS ? $displayAS : 'state_name'; $childProperty->type->list_values = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS); } $keywords .= $childProperty->getKeywordValue() . ' '; if (empty($property_sql_value) && in_array($childProperty->getType(), array('boolean', 'integer', 'float'))) { $property_sql_value = 0; } SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); } } $origValue = $object_property->getValue(); $object_property->setValue($keywords); $property_id = $object_property->getID(); $property_sql_value = $object_property->getSQLValue(); $object_property->setValue($origValue); SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); } else { $property_id = $object_property->getID(); $property_sql_value = $object_property->getSQLValue(); $property_sql_add_parameter = $object_property->getAddParameter(); if ($object_property->isSystem()) { if (empty($property_sql_value) && in_array($object_property->getType(), array('boolean', 'integer', 'float'))) { $property_sql_value = 0; } SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, $property_id, $property_sql_value, $object_sid); if (!empty($property_sql_add_parameter)) { if ($object_property->getType() == 'monetary' && $object->getObjectType() != 'field') { SJB_DB::query("UPDATE `?w` SET `?w` = ?w WHERE sid = ?n", $db_table_name, $property_id . '_parameter', $property_sql_add_parameter, $object_sid); } else { SJB_DB::query("UPDATE `?w` SET `add_parameter` = ?w WHERE sid = ?n", $db_table_name, $property_sql_add_parameter, $object_sid); } } } else { if (SJB_DB::table_exists($db_table_name . "_properties")) { $property_exists = SJB_DB::queryValue("SELECT COUNT(*) FROM ?w WHERE object_sid = ?n AND id = ?s", $db_table_name . "_properties", $object_sid, $property_id); if ($property_exists) { SJB_DB::query("UPDATE ?w SET value = ?s, add_parameter = ?s WHERE object_sid = ?n AND id = ?s", $db_table_name . "_properties", $property_sql_value, $property_sql_add_parameter, $object_sid, $property_id); } else { SJB_DB::query("INSERT INTO ?w(object_sid, id , value, add_parameter) VALUES(?n, ?s, ?s, ?s)", $db_table_name . "_properties", $object_sid, $property_id, $property_sql_value, $property_sql_add_parameter); } } } } } if (!empty($complexFields)) { SJB_DB::query("UPDATE `?w` SET `?w` = ?s WHERE sid = ?n", $db_table_name, 'complex', serialize($complexFields), $object_sid); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'list'); $fieldSID = SJB_Request::getVar('field_sid', false); $parentSID = SJB_Request::getVar('sid', false); $errors = null; if ($fieldSID) { $tp->assign('field_sid', $fieldSID); $field_info = SJB_ListingFieldManager::getFieldInfoBySID($fieldSID); $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($field_info['listing_type_sid']); $tp->assign("field_info", $field_info); $tp->assign("type_info", $listing_type_info); $tp->assign("type_sid", isset($listing_type_info['sid']) ? $listing_type_info['sid'] : false); switch ($action) { case 'edit': $form_submitted = SJB_Request::getVar('submit_form', false); $sid = SJB_Request::getVar('sid', 0); $listingFieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoBySID($sid); $listingFieldInfo = array_merge($listingFieldInfo, $_REQUEST); $listingField = new SJB_ListingField($listingFieldInfo); $listingField->deleteProperty('type'); $listingField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($listingFieldInfo['hidden']) ? $listingFieldInfo['hidden'] : '', 'is_system' => true)); $profileField = SJB_Request::getVar('profile_field', false); if ($form_submitted) { if ($profileField) { $listingFieldInfo['default_value'] = ''; $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id']; } else { $listingFieldInfo['profile_field_as_dv'] = ''; } } if (!empty($listingFieldInfo['default_value_setting'])) { if ($listingFieldInfo['default_value_setting'] == 'default_country') { $listingFieldInfo['default_value'] = $listingFieldInfo['default_value_setting']; $listingFieldInfo['profile_field_as_dv'] = ''; } elseif ($listingFieldInfo['default_value_setting'] == 'profile_field') { $listingFieldInfo['default_value'] = ''; $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id']; } } $additionalParameters = array(); if ($listingFieldInfo['id'] == 'Country') { $additionalParameters = array('list_values' => SJB_CountriesManager::getAllCountriesCodesAndNames()); $display_as = array('id' => 'display_as', 'caption' => 'Display Country as', 'type' => 'list', 'value' => isset($listingFieldInfo['display_as']) ? $listingFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'country_name', 'caption' => 'Country Name'), array('id' => 'country_code', 'caption' => 'Country Code')), 'is_system' => true, 'is_required' => true); } elseif ($listingFieldInfo['id'] == 'State') { $defaultCountry = SJB_ListingFieldManager::getDefaultCountryByParentSID($fieldSID); $additionalParameters['list_values'] = array(); if (is_numeric($defaultCountry)) { $additionalParameters['list_values'] = SJB_StatesManager::getStatesNamesByCountry($defaultCountry); } elseif (!empty($defaultCountry)) { $listingFieldInfo['profile_field_as_dv'] = $listingFieldInfo['id']; $tp->assign('disableField', 1); } else { $additionalParameters['comment'] = 'Please select default country first to select default State'; } $display_as = array('id' => 'display_as', 'caption' => 'Display State as', 'type' => 'list', 'value' => isset($listingFieldInfo['display_as']) ? $listingFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'state_name', 'caption' => 'State Name'), array('id' => 'state_code', 'caption' => 'State Code')), 'is_system' => true, 'is_required' => true); } $default_value = array('id' => 'default_value', 'sid' => isset($listingFieldInfo['sid']) ? $listingFieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['default_value']) ? $listingFieldInfo['default_value'] : '', 'type' => $listingField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($listingFieldInfo['add_parameter']) ? $listingFieldInfo['add_parameter'] : ''); $default_value = array_merge($default_value, $additionalParameters); $listingField->addProperty($default_value); $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['profile_field_as_dv']) ? $listingFieldInfo['profile_field_as_dv'] : '', 'type' => 'list', 'length' => '', 'is_required' => false, 'is_system' => true); $listingField->addProperty($profile_field_as_dv); if (isset($display_as)) { $listingField->addProperty($display_as); } if ($form_submitted) { $listingField->addInfillInstructions(SJB_Request::getVar('instructions')); } else { $listingField->addInfillInstructions(isset($listingFieldInfo['instructions']) ? $listingFieldInfo['instructions'] : ''); } $ListingFieldForm = new SJB_Form($listingField); $ListingFieldForm->registerTags($tp); $listingField->setSID($sid); $addValidParam = array('field' => 'parent_sid', 'value' => $parentSID); if ($form_submitted && $ListingFieldForm->isDataValid($errors, $addValidParam)) { SJB_ListingFieldManager::saveListingField($listingField); if ($listingFieldInfo['id'] == 'Country') { $profileFieldAsDv = $listingField->getPropertyValue('profile_field_as_dv'); if ($profileFieldAsDv) { $listingFieldsInfo = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($fieldSID); foreach ($listingFieldsInfo as $fieldInfo) { if ($fieldInfo['id'] == 'State') { $listingField = new SJB_ListingField($fieldInfo); $listingField->setSID($fieldInfo['sid']); $default_value = array('id' => 'default_value', 'sid' => isset($fieldInfo['sid']) ? $fieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => '', 'type' => $listingField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($fieldInfo['add_parameter']) ? $fieldInfo['add_parameter'] : ''); $listingField->addProperty($default_value); $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => 'State', 'type' => 'list', 'length' => '', 'is_required' => false, 'is_system' => true); $listingField->addProperty($profile_field_as_dv); SJB_ListingFieldManager::saveListingField($listingField); } } } } if (SJB_Request::getVar('apply') == 'no' && empty($errors)) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-listing-field/edit-location-fields/?field_sid=" . $fieldSID); } } $ListingFieldForm->makeDisabled('id'); $tp->assign('profileFieldAsDV', !empty($listingFieldInfo['profile_field_as_dv'])); $tp->assign('listingFieldInfo', $listingFieldInfo); $tp->assign("field_type", $listingField->getFieldType()); $tp->assign("sid", $sid); $tp->assign("form_fields", $ListingFieldForm->getFormFieldsInfo()); $tp->assign("errors", $errors); $tp->display("edit_location_field.tpl"); break; case 'move_up': SJB_ListingFieldManager::moveUpFieldBySID($fieldSID); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-location-fields/?field_sid=" . $parentSID); break; case 'move_down': SJB_ListingFieldManager::moveDownFieldBySID($fieldSID); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-location-fields/?field_sid=" . $parentSID); break; } if ($action == 'list') { $listingFieldsInfo = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($fieldSID); $listingFields = array(); $listingFieldSids = array(); foreach ($listingFieldsInfo as $listingFieldInfo) { $listingField = new SJB_ListingField($listingFieldInfo); $listingField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($listingFieldInfo['hidden']) ? $listingFieldInfo['hidden'] : '', 'is_system' => true)); $listingField->setSID($listingFieldInfo['sid']); $listingFields[] = $listingField; $listingFieldSids[] = $listingFieldInfo['sid']; } $form_collection = new SJB_FormCollection($listingFields); $form_collection->registerTags($tp); $tp->assign("listing_field_sids", $listingFieldSids); $tp->display("listing_location_fields.tpl"); } } }
function assignTemplateVariables($params) { global $variables_to_assign; $variables_to_assign = array(); if ($this->objectHasProperty($params['property'])) { $object_property = $this->getObjectProperty($params['property']); $variables_to_assign = $object_property->getPropertyVariablesToAssign(); } if (!empty($params['complexParent'])) { $complexParent = $params['complexParent']; $object = $this->object_properties[$complexParent]->type->complex; $object_properties = $object->getProperties(); if (isset($object_properties[$params['property']])) { $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); } if (isset($params['complexStep']) && !empty($this->object_properties[$complexParent]->value)) { if (is_string($this->object_properties[$complexParent]->value)) { $complexValue = unserialize($this->object_properties[$complexParent]->value); } else { $complexValue = $this->object_properties[$complexParent]->value; } //exception for monetary type if (!isset($variables_to_assign['list_currency'])) { $variables_to_assign['value'] = ''; } if (isset($complexValue[$params['property']]) && isset($complexValue[$params['property']][$params['complexStep']])) { if ($object_properties[$params['property']]->getType() === 'date' && $object_properties[$params['property']]->type->getConvertToDBDate()) { $field = $object_properties[$params['property']]; $field->type->property_info['value'] = $complexValue[$params['property']][$params['complexStep']]; if ($field->isValid() !== true) { $complexValue[$params['property']][$params['complexStep']] = ''; } $variables_to_assign['value'] = SJB_I18N::getInstance()->getInput('date', $complexValue[$params['property']][$params['complexStep']]); } elseif ($object_properties[$params['property']]->getType() == 'monetary') { if (isset($complexValue[$params['property']][$params['complexStep']]['value'])) { $variables_to_assign['value']['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']]['value'], ENT_QUOTES, "UTF-8"); } else { $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8"); } } elseif ($object_properties[$params['property']]->getType() == 'multilist') { $value = $complexValue[$params['property']][$params['complexStep']]; if (!is_array($value) && strpos($value, ',')) { $variables_to_assign['value'] = explode(',', $value); } else { $variables_to_assign['value'] = $value; } } elseif ($object_properties[$params['property']]->getType() !== 'text') { $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8"); } else { $variables_to_assign['value'] = $complexValue[$params['property']][$params['complexStep']]; } } } } if (!empty($params['parent'])) { $parent = $params['parent']; $object = $this->object_properties[$parent]->type->child; $object_properties = $object->getProperties(); if (isset($object_properties[$params['property']])) { $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); } elseif (strpos($params['property'], '.Code')) { $params['property'] = str_replace('.Code', '', $params['property']); if (!isset($object_properties[$params['property']])) { return false; } $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); if ($params['property'] == 'State') { $country = !empty($params['country']) ? $params['country'] : false; $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_code'); } $variables_to_assign['displayAS'] = 'Code'; } else { $params['property'] = str_replace('.Name', '', $params['property']); if (!isset($object_properties[$params['property']])) { return false; } $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign(); if ($params['property'] == 'State') { $country = !empty($params['country']) ? $params['country'] : false; $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_name'); } $variables_to_assign['displayAS'] = 'Name'; } } if (isset($params['fields'])) { $fields = $params['fields']; $object_property = $this->getObjectProperty($params['property']); $fieldProperties = $object_property->type->child->getProperties(); foreach ($fieldProperties as $key => $property) { if (!array_key_exists($property->getSID(), $fields)) { $object_property->type->child->deleteProperty($key); } } foreach ($fields as $key => $field) { $object_property->type->child->addProperty($field); } $variables_to_assign = $object_property->getPropertyVariablesToAssign(); } if (isset($params['complexStep'])) { $variables_to_assign['complexStep'] = $params['complexStep']; } if (isset($params['parameters'])) { $variables_to_assign = array_merge($variables_to_assign, array('parameters' => $params['parameters'])); } // made for FormBuilders Complex Fields. so admin could define custom html code if (isset($params['customHtml']) && !empty($params['customHtml'])) { $variables_to_assign['customHtml'] = trim($params['customHtml']); } $variables_to_assign = array_merge($variables_to_assign, $this->getVariablesToAssign($params)); $varToAssignValueIsEmpty = $this->isEmptyVariablesToAssignValue($variables_to_assign); if (($this->useDefaultValues || !$this->object->getSID()) && $varToAssignValueIsEmpty && $this->errors === false) { if ($variables_to_assign['default_value'] != '') { if (is_array($variables_to_assign['default_value'])) { $variables_to_assign['default_value']['currency'] = $variables_to_assign['default_value']['add_parameter']; } $variables_to_assign['value'] = $variables_to_assign['default_value']; } else { if ($variables_to_assign['profile_field_as_dv'] != '') { $variables_to_assign['value'] = htmlentities($variables_to_assign['profile_field_as_dv'], ENT_QUOTES, 'UTF-8'); } } } // заглушка для email - когда в value попадает массив из одного элемента [original] if ($variables_to_assign['id'] == 'email') { if (is_array($variables_to_assign['value'])) { $variables_to_assign['value'] = array_pop($variables_to_assign['value']); } } $variables_to_assign['defaultCountry'] = SJB_Settings::getSettingByName('default_country'); if (isset($params['searchWithin'])) { $variables_to_assign['searchWithin'] = $params['searchWithin']; } if (!isset($variables_to_assign['displayAS'])) { $variables_to_assign['displayAS'] = false; } if ($variables_to_assign['id'] == 'default_value' && in_array($this->object->getProperty('default_value')->getType(), array('list', 'multilist'))) { $variables_to_assign['sort_by_alphabet'] = $this->object->getPropertyValue('sort_by_alphabet'); } foreach ($variables_to_assign as $variable_name => $variable_value) { $this->template_processor->assign($variable_name, $variable_value); } return true; }
public static function getCurrentSearchByCriteria($criteria) { $returnArray = array(); $locationFields = SJB_ListingFieldManager::getFieldsInfoByType('location'); foreach ($criteria as $fieldName => $field) { if (!in_array($fieldName, array('listing_type', 'active', 'username', 'status', 'CompanyName', 'keywords', 'PostedWithin', 'anonymous'))) { $result = array(); $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldName); if (!$fieldInfo) { foreach ($locationFields as $locationField) { $locationSubFields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($locationField['sid']); foreach ($locationSubFields as $locationSubField) { if ($fieldName == $locationField['id'] . "_" . $locationSubField['id']) { $fieldInfo = $locationSubField; $fieldInfo['id'] = $locationField['id'] . "_" . $locationSubField['id']; } } } } foreach ($field as $fieldType => $fieldValue) { switch ($fieldType) { case 'geo': if ($fieldValue['location'] !== '') { $result[$fieldName][$fieldType][$fieldValue['location']] = $fieldValue['location']; } break; case 'location': if (!empty($fieldValue['value'])) { $result[$fieldName][$fieldType][$fieldValue['value']] = $fieldValue['value']; } break; case 'monetary': if (!empty($fieldValue['not_less']) && $fieldValue['not_less'] !== '') { $result[$fieldName][$fieldType][$fieldValue['not_less']] = $fieldValue['not_less']; } if (!empty($fieldValue['not_more']) && $fieldValue['not_more'] !== '') { $result[$fieldName][$fieldType][$fieldValue['not_more']] = $fieldValue['not_more']; } break; case 'multi_like': $listItem = new SJB_ListingFieldListItemManager(); if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { if ($fieldInfo['type'] == 'tree') { $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'"); $name = $name ? $name : ''; $result[$fieldName][$fieldType][$value] = $name; } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') { if (!empty($fieldInfo['parent_sid'])) { if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') { $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']); } else { $listValues = $fieldInfo['list_values']; } foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $result[$fieldName][$fieldType][$value] = $listValue['caption']; break; } } } else { $itemInfo = $listItem->getListItemBySID($value); $caption = $itemInfo ? $itemInfo->getValue() : $value; $result[$fieldName][$fieldType][$value] = $caption; } } else { $result[$fieldName][$fieldType][$value] = $value; } } } } elseif ($fieldValue !== '') { $itemInfo = $listItem->getListItemBySID($fieldValue); $caption = $itemInfo ? $itemInfo->getValue() : $fieldValue; $result[$fieldName][$fieldType][$fieldValue] = $caption; } break; case 'tree': $fieldValue = $fieldValue ? explode(',', $fieldValue) : ""; if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'"); $name = $name ? $name : ''; $result[$fieldName][$fieldType][$value] = $name; } } } break; case 'multi_like_and': if (is_array($fieldValue)) { $listItem = new SJB_ListingFieldListItemManager(); foreach ($fieldValue as $value) { if ($value !== '') { if ($fieldInfo['type'] == 'tree') { $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'"); $name = $name ? $name : ''; $result[$fieldName][$fieldType][$value] = $name; } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') { if (!empty($fieldInfo['parent_sid'])) { if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') { $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']); } else { $listValues = $fieldInfo['list_values']; } foreach ($listValues as $listValue) { if ($listValue['id'] == $value) { $result[$fieldName][$fieldType][$value] = $listValue['caption']; break; } } } else { $itemInfo = $listItem->getListItemBySID($value); $caption = $itemInfo ? $itemInfo->getValue() : $value; $result[$fieldName][$fieldType][$value] = $caption; } } else { $result[$fieldName][$fieldType][$value] = $value; } } } } elseif ($fieldValue !== '') { $result[$fieldName][$fieldType][$fieldValue] = $fieldValue; } break; default: if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { $result[$fieldName][$fieldType][$value] = $value; } } } elseif ($fieldValue !== '') { $result[$fieldName][$fieldType][$fieldValue] = $fieldValue; } break; } } if ($result && !empty($fieldInfo)) { $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption']; $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']]; } } elseif ($fieldName == 'CompanyName') { $result = array(); $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'"); if ($userFieldSID) { $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID); foreach ($field as $fieldType => $fieldValue) { switch ($fieldType) { case 'multi_like_and': if (is_array($fieldValue)) { foreach ($fieldValue as $value) { if ($value !== '') { $result[$fieldName][$fieldType][$value] = $value; } } } elseif ($fieldValue !== '') { $result[$fieldName][$fieldType][$fieldValue] = $fieldValue; } break; } } } if ($result && !empty($fieldInfo)) { $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption']; $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']]; } } elseif ($fieldName == 'keywords') { foreach ($field as $key => $val) { if ($val) { $returnArray['keywords']['field'][$key][$val] = $val; } } if (isset($returnArray['keywords'])) { $returnArray['keywords']['name'] = 'Keywords'; } } } return $returnArray; }