Esempio n. 1
0
 public static function getPropertyByParentID($parentID, $fieldID, $listing_type_sid = 0)
 {
     $parentSID = SJB_ListingFieldManager::getListingFieldSIDByID($parentID);
     $fields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($parentSID);
     $fieldSID = null;
     foreach ($fields as $field) {
         if ($field['id'] == $fieldID) {
             $fieldSID = $field['sid'];
         }
     }
     if ($fieldSID) {
         $property_info = SJB_ListingFieldDBManager::getListingFieldInfoBySID($fieldSID);
         $property_info['id'] = $parentID . "_" . $property_info['id'];
         $fieldID = $property_info['id'];
         return new SJB_ObjectProperty($property_info);
     }
     return null;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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");
         }
     }
 }
Esempio n. 4
0
 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;
 }