예제 #1
0
 private static function createFieldForLocation($fieldId, $listingFieldInfo, $listingTypeSid, $parentSid)
 {
     $listingField = new SJB_ListingField($listingFieldInfo, $listingTypeSid);
     $listingField->addParentSID($parentSid);
     $listingField->addProfileFieldAsDv($fieldId);
     self::saveListingField($listingField, array(), true);
 }
예제 #2
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $listingTypeSID = isset($_REQUEST['sid']) ? $_REQUEST['sid'] : null;
     if (!is_null($listingTypeSID)) {
         $form_submitted = SJB_Request::getVar('action', '');
         $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID);
         $approveSettingChanged = $listing_type_info['waitApprove'] != SJB_Request::getVar('waitApprove');
         $listing_type_info = array_merge($listing_type_info, $_REQUEST);
         $listingType = new SJB_ListingType($listing_type_info);
         $listingType->setSID($listingTypeSID);
         $edit_form = new SJB_Form($listingType);
         $listingTypeEmailAlert = $listingType->getPropertyValue('email_alert');
         if (empty($listingTypeEmailAlert)) {
             $listingType->setPropertyValue('email_alert', 0);
         }
         $listingTypeEmailAlertForGuests = $listingType->getPropertyValue('guest_alert_email');
         if (empty($listingTypeEmailAlertForGuests)) {
             $listingType->setPropertyValue('guest_alert_email', 0);
         }
         $errors = array();
         if ($form_submitted && $edit_form->isDataValid($errors)) {
             SJB_Breadcrumbs::updateBreadcrumbsByListingTypeSID($listingTypeSID, $listingType->getPropertyValue('name'));
             SJB_PageManager::updatePagesByListingTypeSID($listingTypeSID, $listingType->getPropertyValue('name'));
             SJB_ListingTypeManager::saveListingType($listingType);
             if ($approveSettingChanged) {
                 SJB_BrowseDBManager::rebuildBrowses();
             }
             if ($form_submitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/listing-types/');
             }
         }
         $template_processor->assign('errors', $errors);
         $template_processor->assign('listing_type_sid', $listingTypeSID);
         $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeSID);
         $listing_fields = array();
         $listing_field_sids = array();
         foreach ($listing_fields_info as $listing_field_info) {
             if ($listing_field_info['type'] == 'logo') {
                 continue;
             }
             $listing_field = new SJB_ListingField($listing_field_info);
             $listing_field->setSID($listing_field_info['sid']);
             $listing_fields[] = $listing_field;
             $listing_field_sids[] = $listing_field_info['sid'];
         }
         $edit_form->registerTags($template_processor);
         $template_processor->assign("listing_type_info", $listing_type_info);
         $template_processor->assign("form_fields", $edit_form->getFormFieldsInfo());
         $template_processor->display("edit_listing_type.tpl");
         $form_collection = new SJB_FormCollection($listing_fields);
         $form_collection->registerTags($template_processor);
         $template_processor->assign("listing_field_sids", $listing_field_sids);
         $template_processor->display("listing_type_fields.tpl");
     }
 }
 public static function getFieldBySID($listing_field_sid)
 {
     $listing_field_info = SJB_ListingFieldDBManager::getListingFieldInfoBySID($listing_field_sid, 'listing_complex_fields');
     if (empty($listing_field_info)) {
         return null;
     } else {
         $listing_field = new SJB_ListingField($listing_field_info);
         $listing_field->setSID($listing_field_sid);
         return $listing_field;
     }
 }
예제 #4
0
 public function execute()
 {
     $listing_type_sid = isset($_REQUEST['listing_type_sid']) ? $_REQUEST['listing_type_sid'] : null;
     if (!is_null($listing_type_sid)) {
         $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_type_sid);
         $pages_list = array();
         if (count($pages) > 1) {
             $pages_list[] = array('id' => 'no', 'caption' => 'Don’t add to a page');
             foreach ($pages as $page) {
                 $pages_list[] = array('id' => $page['sid'], 'caption' => $page['page_name']);
             }
         }
         $listing_field = new SJB_ListingField($_REQUEST, $listing_type_sid, $pages_list);
         /**
          * add infilll instructions field
          */
         //	$listing_field->addInfillInstructions(SJB_Request::getVar('instructions'));
         $add_listing_field_form = new SJB_Form($listing_field);
         $form_is_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'add';
         $errors = null;
         if ($form_is_submitted && $add_listing_field_form->isDataValid($errors)) {
             $page = array();
             if (count($pages) == 1) {
                 $pages = array_pop($pages);
                 $page = array(array('sid' => $pages['sid'], 'listing_type_sid' => $listing_type_sid));
             } else {
                 $posting_page = $listing_field->getProperty('posting_page');
                 $listing_field->deleteProperty('posting_page');
                 if ($posting_page->value != "no") {
                     $page = array(array('sid' => $posting_page->value, 'listing_type_sid' => $listing_type_sid));
                 }
             }
             SJB_ListingFieldManager::saveListingField($listing_field, $page);
             $listing_sid = $listing_field->getSID();
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/attention-listing-type-field/?listing_sid={$listing_sid}");
         } else {
             $template_processor = SJB_System::getTemplateProcessor();
             $template_processor->assign("errors", $errors);
             $template_processor->assign("listing_type_sid", $listing_type_sid);
             $template_processor->assign("listing_type_info", SJB_ListingTypeManager::getListingTypeInfoBySID($listing_type_sid));
             $add_listing_field_form->registerTags($template_processor);
             $template_processor->assign("form_fields", $add_listing_field_form->getFormFieldsInfo());
             $template_processor->display("add_listing_type_field.tpl");
         }
     } else {
         echo 'The system cannot proceed as Listing Type SID is not set';
     }
 }
예제 #5
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     if (isset($_REQUEST['action'], $_REQUEST['field_sid'])) {
         if ($_REQUEST['action'] == 'move_up') {
             SJB_ListingFieldManager::moveUpFieldBySID($_REQUEST['field_sid']);
         } elseif ($_REQUEST['action'] == 'move_down') {
             SJB_ListingFieldManager::moveDownFieldBySID($_REQUEST['field_sid']);
         }
     }
     $listing_fields_info = SJB_ListingFieldManager::getCommonListingFieldsInfo();
     $listing_fields = array();
     $listing_field_sids = array();
     foreach ($listing_fields_info as $listing_field_info) {
         $listing_field = new SJB_ListingField($listing_field_info);
         $listing_field->setSID($listing_field_info['sid']);
         $listing_fields[] = $listing_field;
         $listing_field_sids[] = $listing_field_info['sid'];
     }
     $form_collection = new SJB_FormCollection($listing_fields);
     $form_collection->registerTags($template_processor);
     $template_processor->assign("listing_field_sids", $listing_field_sids);
     $template_processor->display("listing_fields.tpl");
 }
예제 #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'list');
     $fieldSID = SJB_Request::getVar('field_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 'add':
                 $form_is_submitted = SJB_Request::getVar('submit_form', false);
                 $sid = SJB_Request::getVar('sid', false);
                 $request = $_REQUEST;
                 if ($sid) {
                     $listing_field_info = SJB_ListingFieldDBManager::getListingComplexFieldInfoBySID($sid);
                     $request = array_merge($listing_field_info, $request);
                 }
                 $listing_field = new SJB_ListingComplexField($request);
                 if ($sid) {
                     $listing_field->setSID($sid);
                 }
                 $add_listing_field_form = new SJB_Form($listing_field);
                 $add_listing_field_form->registerTags($tp);
                 if ($form_is_submitted && $add_listing_field_form->isDataValid($errors)) {
                     $listing_field->addProperty(array('id' => 'field_sid', 'value' => $fieldSID, 'type' => 'id', 'is_required' => true, 'is_system' => true));
                     SJB_ListingComplexFieldManager::saveListingField($listing_field);
                 }
                 if (SJB_Request::getVar('apply') == 'no' && empty($errors)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-listing-field/edit-fields/?field_sid=" . $fieldSID);
                 }
                 $add_listing_field_form->registerTags($tp);
                 $tp->assign("sid", $listing_field->getSID());
                 $tp->assign("field_type", $listing_field->getFieldType());
                 $tp->assign("form_fields", $this->getFormFieldsInfo($add_listing_field_form));
                 $tp->assign("errors", $errors);
                 $tp->assign("action", $action);
                 $tp->display("edit_complex_field.tpl");
                 break;
             case 'edit':
                 $listing_field_sid = SJB_Request::getVar('sid', 0);
                 $listing_field_info = SJB_ListingFieldDBManager::getListingComplexFieldInfoBySID($listing_field_sid);
                 $listing_field = new SJB_ListingComplexField($listing_field_info);
                 $add_listing_field_form = new SJB_Form($listing_field);
                 $add_listing_field_form->registerTags($tp);
                 $add_listing_field_form->registerTags($tp);
                 $tp->assign("field_type", $listing_field->getFieldType());
                 $tp->assign("sid", $listing_field_sid);
                 $tp->assign("form_fields", $this->getFormFieldsInfo($add_listing_field_form));
                 $tp->assign("errors", $errors);
                 $tp->display("edit_complex_field.tpl");
                 break;
             case 'move_up':
                 $fieldSID = SJB_ListingComplexFieldManager::moveUpFieldBySID($fieldSID);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-fields/?field_sid=" . $fieldSID);
                 break;
             case 'move_down':
                 $fieldSID = SJB_ListingComplexFieldManager::moveDownFieldBySID($fieldSID);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-listing-field/edit-fields/?field_sid=" . $fieldSID);
                 break;
             case 'delete':
                 $listing_field_sid = SJB_Request::getVar('sid', 0);
                 SJB_ListingComplexFieldManager::deleteListingFieldBySID($listing_field_sid);
                 $action = 'list';
                 break;
         }
         if ($action == 'list') {
             $listing_fields_info = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($fieldSID);
             $listing_fields = array();
             $listing_field_sids = array();
             foreach ($listing_fields_info as $listing_field_info) {
                 $listing_field = new SJB_ListingField($listing_field_info);
                 $listing_field->setSID($listing_field_info['sid']);
                 $listing_fields[] = $listing_field;
                 $listing_field_sids[] = $listing_field_info['sid'];
             }
             $form_collection = new SJB_FormCollection($listing_fields);
             $form_collection->registerTags($tp);
             $tp->assign("listing_field_sids", $listing_field_sids);
             $tp->display("listing_complex_fields.tpl");
         }
     }
 }
예제 #7
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");
         }
     }
 }
예제 #8
0
 public function execute()
 {
     $errors = array();
     if (SJB_Request::isAjax()) {
         $response = null;
         if ($logoId = SJB_Request::getVar('logo_id')) {
             SJB_UploadFileManager::deleteUploadedFileByID($logoId, 'logo');
             $parsersId = SJB_Request::getVar('id');
             SJB_DB::query("UPDATE `parsers` SET `xml_logo` = NULL WHERE id = ?n", $parsersId);
         } elseif ($userName = SJB_Request::getVar('parser_user')) {
             $userType = SJB_Request::getVar('user_type');
             $products = SJB_XmlImport::getProducts($userType, $userName, $errors);
             $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors));
             $response = json_encode($response);
         }
         die($response);
     }
     $tp = SJB_System::getTemplateProcessor();
     $original_xml = !empty($_REQUEST['xml']) ? $_REQUEST['xml'] : '';
     $xml = $original_xml;
     $tree = '';
     $listing_fields = array();
     $parsing_name = isset($_REQUEST['parser_name']) ? $_REQUEST['parser_name'] : '';
     $usr_name = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : '';
     $pars_url = isset($_REQUEST['parser_url']) ? $_REQUEST['parser_url'] : '';
     $form_description = isset($_POST['form_description']) ? $_POST['form_description'] : "";
     $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : "";
     $custom_script = SJB_Request::getVar('custom_script', '');
     $custom_script_users = SJB_Request::getVar('custom_script_users', '');
     $add_new_user = isset($_POST['add_new_user']) ? intval($_POST['add_new_user']) : 0;
     $username = SJB_Request::getVar('username', '');
     $external_id = SJB_Request::getVar('external_id', '');
     $defaultValue = array();
     $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings');
     $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     $selected = array();
     $a_selected = array();
     $selectedLogoOption = null;
     $selectedLogoField = null;
     $xml_logo = null;
     $selectedProduct = SJB_Request::getVar('postUnderProduct');
     $save_error = SJB_Request::getVar('save_error');
     if ($save_error) {
         $errors[] = base64_decode($save_error);
     }
     if (!empty($_REQUEST['xml']) || $id > 0) {
         // step 2 OR edit exist
         if ($id > 0) {
             // load exist parser
             $parser_from_id = SJB_XmlImport::getSystemParsers($id);
             if (isset($parser_from_id[0]['name'])) {
                 $parser_from_id = $parser_from_id[0];
             }
             $parsing_name = $parser_from_id['name'];
             $usr_id = $parser_from_id['usr_id'];
             $usr_name = $parser_from_id['usr_name'];
             $form_description = $parser_from_id['description'];
             $pars_url = $parser_from_id['url'];
             $type_id = $parser_from_id['type_id'];
             $custom_script = $parser_from_id['custom_script'];
             $custom_script_users = $parser_from_id['custom_script_users'];
             $add_new_user = $parser_from_id['add_new_user'];
             $importType = $parser_from_id['import_type'];
             $xml = $parser_from_id['xml'];
             $xml_logo = $parser_from_id['xml_logo'];
             $xml = SJB_XmlImport::cleanXmlFromImport($xml);
             $defaultValue = $parser_from_id['default_value'] != '' ? unserialize($parser_from_id['default_value']) : array();
             $username = $parser_from_id['username'];
             $map = unserialize($parser_from_id['maper']);
             $external_id = str_replace('@', '_dog_', $parser_from_id['external_id']);
             $selected_logo_options = unserialize($parser_from_id['logo_options']);
             $selectedLogoOption = $selected_logo_options['option'];
             $selectedLogoField = $selected_logo_options['field'];
             if ($selected_logo_options['option'] == 'upload_logo') {
                 $upload_manager = new SJB_UploadPictureManager();
                 $upload_manager->getUploadedPictureInfo($xml_logo . '_thumb');
                 $logo_link = $upload_manager->getUploadedFileLink($xml_logo . '_thumb');
                 $tp->assign('logo_link', $logo_link);
             }
             foreach ($map as $key => $val) {
                 unset($map[$key]);
                 $key = SJB_XmlImport::encodeSpecialEntities($key);
                 $map[$key] = $val;
             }
             $selected = array_values($map);
             $a_selected = array_keys($map);
             $selectedProduct = $parser_from_id['product_sid'];
         } else {
             $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']);
         }
         $sxml = new simplexml();
         $xml = stripslashes($xml);
         $tree = $sxml->xml_load_file($xml, 'array');
         if (isset($tree['@content'])) {
             $tree = $tree[0];
         }
         if (is_array($tree)) {
             $tree = SJB_XmlImport::convertArray($tree);
             foreach ($tree as $key => $val) {
                 unset($tree[$key]);
                 $key = SJB_XmlImport::encodeSpecialEntities($key);
                 $tree[$key]['val'] = $val;
                 $tree[$key]['key'] = $key;
             }
             $field_types = array(0, $type_id);
             $listing_fields = array();
             $i = 0;
             foreach ($field_types as $type) {
                 $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type);
                 foreach ($listing_fields_info as $listing_field_info) {
                     if ($listing_field_info['type'] == 'location') {
                         foreach ($listing_field_info['fields'] as $fieldInfo) {
                             $listing_field = new SJB_ListingField($fieldInfo);
                             $listing_field->setSID($fieldInfo['sid']);
                             $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value;
                             $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                             $i++;
                         }
                     } else {
                         $listing_field = new SJB_ListingField($listing_field_info);
                         $listing_field->setSID($listing_field_info['sid']);
                         $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value;
                         $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                         $i++;
                     }
                 }
             }
             $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date";
             $i++;
             $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url";
             $i++;
             $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id";
         } else {
             $errors[] = 'XML syntaxis error.';
         }
     } else {
         $errors[] = 'Please input correct xml';
     }
     if (empty($selectedProduct)) {
         $errors[] = 'Please select a product';
     }
     if (!filter_var($pars_url, FILTER_VALIDATE_URL)) {
         $errors[] = 'Please input correct URL';
     }
     $error = SJB_Request::getVar('error', false, 'GET');
     if ($error) {
         $errors[$error] = true;
     }
     $userType = empty($add_new_user) ? 'username' : 'group';
     if ($userType == 'group') {
         $userName = SJB_UserGroupManager::getUserGroupSIDByID($usr_name);
     } else {
         $userName = $usr_name;
     }
     $products = SJB_XmlImport::getProducts($userType, $userName, $errors);
     $tp->assign('id', $id);
     $tp->assign('selected', $selected);
     $tp->assign('a_selected', $a_selected);
     $tp->assign('xml', htmlspecialchars($xml));
     $tp->assign('xml_logo', $xml_logo);
     $tp->assign('xmlToUser', $xml);
     $tp->assign('default_value', $defaultValue);
     $tp->assign('form_name', $parsing_name);
     $tp->assign('form_user', $usr_name);
     $tp->assign('form_user_sid', $usr_id);
     $tp->assign('form_url', $pars_url);
     $tp->assign('form_description', $form_description);
     $tp->assign('custom_script', $custom_script);
     $tp->assign('custom_script_users', $custom_script_users);
     $tp->assign('username', $username);
     $tp->assign('external_id', $external_id);
     $tp->assign('import_type', $importType);
     $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo());
     $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id);
     $tp->assign('add_new_user', $add_new_user);
     $tp->assign('type_id', $type_id);
     $tp->assign('type_name', $type_name);
     $tp->assign('errors', $errors);
     $tp->assign('tree', $tree);
     $tp->assign("fields", $listing_fields);
     $tp->assign('logo_options', $logo_options_array);
     $tp->assign('selectedLogoOption', $selectedLogoOption);
     $tp->assign('selectedLogoField', $selectedLogoField);
     $tp->assign('selectedProduct', $selectedProduct);
     $tp->assign('products', $products);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('add_step_two.tpl');
 }
예제 #9
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_field_sid = SJB_Request::getVar('sid', null);
     if (!is_null($listing_field_sid)) {
         $listingFieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($listing_field_sid);
         $old_listing_field_id = $listingFieldInfo['id'];
         $listingFieldInfo = array_merge($listingFieldInfo, $_REQUEST);
         $listing_field = new SJB_ListingField($listingFieldInfo, $listingFieldInfo['listing_type_sid']);
         $listing_field->setSID($listing_field_sid);
         $formSubmitted = SJB_Request::getVar('action', '');
         if (!in_array($listing_field->field_type, array('video', 'picture', 'file', 'complex'))) {
             $profileField = SJB_Request::getVar('profile_field', false);
             if ($formSubmitted) {
                 if ($profileField) {
                     $listingFieldInfo['default_value'] = '';
                 } else {
                     $listingFieldInfo['profile_field_as_dv'] = '';
                 }
             }
             $default_value = array('id' => 'default_value', 'sid' => isset($listingFieldInfo['sid']) ? $listingFieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['default_value']) ? $listingFieldInfo['default_value'] : '', 'type' => $listing_field->field_type, 'length' => '', 'is_required' => false, 'is_system' => true);
             $additionalParameters = array();
             switch ($listing_field->field_type) {
                 case 'list':
                     if (isset($listingFieldInfo['list_values'])) {
                         $additionalParameters = array('list_values' => $listingFieldInfo['list_values']);
                     }
                     break;
                 case 'multilist':
                     if (isset($listingFieldInfo['list_values'])) {
                         $additionalParameters = array('list_values' => $listingFieldInfo['list_values']);
                     }
                     if (!is_array($default_value['value'])) {
                         if (strpos($default_value['value'], ',')) {
                             $default_value['value'] = explode(',', $default_value['value']);
                         } else {
                             $default_value['value'] = array($default_value['value']);
                         }
                     }
                     break;
                 case 'tree':
                     if (isset($listingFieldInfo['tree_values'])) {
                         $additionalParameters = array('tree_values' => $listingFieldInfo['tree_values']);
                     }
                     break;
                 case 'monetary':
                     if (isset($listingFieldInfo['currency_values'])) {
                         $default_value['currency_values'] = $listingFieldInfo['currency_values'];
                     }
                     break;
             }
             $default_value = array_merge($default_value, $additionalParameters);
             $listing_field->addProperty($default_value);
             $user_groups = SJB_UserGroupManager::getAllUserGroupsInfo();
             $list_values = array();
             foreach ($user_groups as $user_group) {
                 $list_values = array_merge($list_values, SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group['sid']));
             }
             $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', 'list_values' => $list_values, 'length' => '', 'is_required' => false, 'is_system' => true);
             $listing_field->addProperty($profile_field_as_dv);
             if (in_array($listing_field->field_type, array('tree', 'multilist', 'list'))) {
                 $sort_by_alphabet = array('id' => 'sort_by_alphabet', 'caption' => 'Sort Values By Alphabet', 'value' => isset($listingFieldInfo['sort_by_alphabet']) ? $listingFieldInfo['sort_by_alphabet'] : '', 'type' => 'boolean', 'lenght' => '', 'is_required' => false, 'is_system' => true);
                 $listing_field->addProperty($sort_by_alphabet);
             }
             $tp->assign('profileFieldAsDV', !empty($listingFieldInfo['profile_field_as_dv']));
         }
         if (in_array($listing_field->field_type, array('multilist', 'list'))) {
             $listing_field->addDisplayAsProperty($listingFieldInfo['display_as']);
         }
         // infil instructions should be the last element in form
         if (!in_array($listing_field->getFieldType(), array('complex', 'tree', 'location')) && 'ApplicationSettings' != $listing_field->getPropertyValue('id')) {
             if ($formSubmitted) {
                 $listing_field->addInfillInstructions(SJB_Request::getVar('instructions'));
             } else {
                 $listing_field->addInfillInstructions(isset($listingFieldInfo['instructions']) ? $listingFieldInfo['instructions'] : '');
             }
         }
         /**
          * "Display as" options for TREE TYPE
          */
         if ('tree' == $listing_field->getFieldType()) {
             $listing_field->addProperty(SJB_TreeType::getDisplayAsDetail(isset($listingFieldInfo['display_as_select_boxes']) ? $listingFieldInfo['display_as_select_boxes'] : ''));
             $treeLevelsNumber = SJB_ListingFieldTreeManager::getTreeDepthBySID($listing_field_sid);
             $tp->assign('tree_levels_number', $treeLevelsNumber);
             // treee levels captions
             for ($i = 1; $i <= $treeLevelsNumber; $i++) {
                 $levelID = 'level_' . $i;
                 $listing_field->addProperty(array('id' => $levelID, 'caption' => $i . ' Level Name', 'value' => isset($listingFieldInfo[$levelID]) ? $listingFieldInfo[$levelID] : '', 'type' => 'string', 'length' => '250', 'is_required' => false, 'is_system' => true));
             }
         }
         /*
          * end of ""Display as" options for TREE TYPE"
          */
         $edit_form = new SJB_Form($listing_field);
         $edit_form->makeDisabled("type");
         $errors = array();
         if ($formSubmitted && $edit_form->isDataValid($errors)) {
             SJB_ListingFieldManager::saveListingField($listing_field);
             SJB_ListingFieldManager::changeListingPropertyIDs($listingFieldInfo['id'], $old_listing_field_id);
             if ($formSubmitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-listing-type/?sid=" . $listing_field->getListingTypeSID());
             }
         }
         $edit_form->registerTags($tp);
         $tp->assign("form_fields", $edit_form->getFormFieldsInfo());
         $tp->assign("errors", $errors);
         $tp->assign("listing_type_sid", $listing_field->getListingTypeSID());
         $tp->assign("field_type", $listing_field->getFieldType());
         $tp->assign("field_sid", $listing_field->getSID());
         $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_field->getListingTypeSID());
         $tp->assign("listing_type_info", $listing_type_info);
         $tp->assign("listing_field_info", $listingFieldInfo);
         $tp->display("edit_listing_type_field.tpl");
     }
 }
예제 #10
0
 public function execute()
 {
     $listing_field_sid = SJB_Request::getVar('sid', null);
     $tp = SJB_System::getTemplateProcessor();
     if (!is_null($listing_field_sid)) {
         $listing_field_info = SJB_ListingFieldManager::getFieldInfoBySID($listing_field_sid);
         $listing_field_info = array_merge($listing_field_info, $_REQUEST);
         $listing_field = new SJB_ListingField($listing_field_info);
         $listing_field->setSID($listing_field_sid);
         $form_submitted = SJB_Request::getVar('action', '');
         if (!in_array($listing_field->field_type, array('video', 'picture', 'file', 'complex'))) {
             $profile_field = SJB_Request::getVar('profile_field', false);
             if ($form_submitted) {
                 if ($profile_field) {
                     $listing_field_info['default_value'] = '';
                 } else {
                     $listing_field_info['profile_field_as_dv'] = '';
                 }
             }
             $default_value = array();
             if ($listing_field->field_type != 'location') {
                 $default_value = array('id' => 'default_value', 'sid' => isset($listing_field_info['sid']) ? $listing_field_info['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listing_field_info['default_value']) ? $listing_field_info['default_value'] : '', 'type' => $listing_field->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($listing_field_info['add_parameter']) ? $listing_field_info['add_parameter'] : '');
             }
             switch ($listing_field->field_type) {
                 case 'list':
                     if (isset($listing_field_info['list_values'])) {
                         $default_value['list_values'] = $listing_field_info['list_values'];
                     }
                     break;
                 case 'multilist':
                     if (isset($listing_field_info['list_values'])) {
                         $default_value['list_values'] = $listing_field_info['list_values'];
                     }
                     if (!is_array($default_value['value'])) {
                         if (strpos($default_value['value'], ',')) {
                             $default_value['value'] = explode(',', $default_value['value']);
                         } else {
                             $default_value['value'] = array($default_value['value']);
                         }
                     }
                     break;
                 case 'tree':
                     if (isset($listing_field_info['tree_values'])) {
                         $default_value['tree_values'] = $listing_field_info['tree_values'];
                     }
                     if (isset($listing_field_info['display_as_select_boxes'])) {
                         $default_value['display_as_select_boxes'] = $listing_field_info['display_as_select_boxes'];
                     }
                     unset($listing_field_info['choiceLimit']);
                     break;
                 case 'monetary':
                     if (isset($listing_field_info['currency_values'])) {
                         $default_value['currency_values'] = $listing_field_info['currency_values'];
                     }
                     break;
             }
             if ($listing_field->field_type != 'location') {
                 $listing_field->addProperty($default_value);
                 $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => isset($listing_field_info['profile_field_as_dv']) ? $listing_field_info['profile_field_as_dv'] : '', 'type' => 'list', 'list_values' => SJB_UserProfileFieldManager::getAllFieldsInfo(), 'length' => '', 'is_required' => false, 'is_system' => true);
                 $listing_field->addProperty($profile_field_as_dv);
             }
             if (in_array($listing_field->field_type, array('tree', 'multilist', 'list'))) {
                 $sort_by_alphabet = array('id' => 'sort_by_alphabet', 'caption' => 'Sort Values By Alphabet', 'value' => isset($listing_field_info['sort_by_alphabet']) ? $listing_field_info['sort_by_alphabet'] : '', 'type' => 'boolean', 'lenght' => '', 'is_required' => false, 'is_system' => true);
                 $listing_field->addProperty($sort_by_alphabet);
             }
             $tp->assign('profileFieldAsDV', !empty($listing_field_info['profile_field_as_dv']));
         }
         if (in_array($listing_field->field_type, array('multilist', 'list'))) {
             $listing_field->addDisplayAsProperty($listing_field_info['display_as']);
         }
         // infil instructions should be the last element in form
         if (!in_array($listing_field->getFieldType(), array('complex', 'tree', 'location'))) {
             if ($form_submitted) {
                 $listing_field->addInfillInstructions(SJB_Request::getVar('instructions'));
             } else {
                 $listing_field->addInfillInstructions(isset($listing_field_info['instructions']) ? $listing_field_info['instructions'] : '');
             }
         }
         if ('tree' == $listing_field->getFieldType()) {
             $listing_field->addProperty(SJB_TreeType::getDisplayAsDetail(isset($listing_field_info['display_as_select_boxes']) ? $listing_field_info['display_as_select_boxes'] : ''));
             $treeLevelsNumber = SJB_ListingFieldTreeManager::getTreeDepthBySID($listing_field_sid);
             $tp->assign('tree_levels_number', $treeLevelsNumber);
             // treee levels captions
             for ($i = 1; $i <= $treeLevelsNumber; $i++) {
                 $levelID = 'level_' . $i;
                 $listing_field->addProperty(array('id' => $levelID, 'caption' => $i . ' Level Name', 'value' => isset($listing_field_info[$levelID]) ? $listing_field_info[$levelID] : '', 'type' => 'string', 'length' => '250', 'is_required' => false, 'is_system' => true));
             }
         }
         $edit_form = new SJB_Form($listing_field);
         $errors = array();
         if ($form_submitted && $edit_form->isDataValid($errors)) {
             $old_listing_field_id = SJB_Request::getVar('old_listing_field_id', null);
             SJB_ListingFieldManager::saveListingField($listing_field);
             SJB_ListingFieldManager::changeListingPropertyIDs($listing_field_info['id'], $old_listing_field_id);
             if ($form_submitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/listing-fields/');
             }
         }
         $edit_form->registerTags($tp);
         $edit_form->makeDisabled('type');
         if ($listing_field_info['id'] == 'Location' && empty($errors['ID'])) {
             $edit_form->makeDisabled('id');
         }
         $tp->assign('object_sid', $listing_field);
         $tp->assign('form_fields', $edit_form->getFormFieldsInfo());
         $tp->assign('errors', $errors);
         $tp->assign('field_type', $listing_field->getFieldType());
         $tp->assign('listing_field_info', $listing_field_info);
         $tp->assign('field_sid', $listing_field_sid);
         $tp->display('edit_listing_field.tpl');
     }
 }
예제 #11
0
 public function execute()
 {
     $errors = array();
     if (SJB_Request::isAjax()) {
         $response = null;
         $user_type = SJB_Request::getVar('user_type');
         $user_name = SJB_Request::getVar('parser_user');
         $products = SJB_XmlImport::getProducts($user_type, $user_name, $errors);
         $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors));
         die(json_encode($response));
     }
     $tp = SJB_System::getTemplateProcessor();
     $add_level = SJB_Request::getVar('add_level', 1);
     // check for errors
     if ($add_level == '3') {
         $selectUserType = SJB_Request::getVar('selectUserType');
         $addNewUser = 0;
         if ($selectUserType == 'username') {
             $usr_name = isset($_REQUEST['parser_user']) ? SJB_DB::quote($_REQUEST['parser_user']) : '';
             $usr_id = SJB_UserManager::getUserSIDbyUsername($usr_name);
             if (empty($usr_name)) {
                 $errors[] = 'Please enter user name of existing user to the "User Name" field';
                 $usr_name = '';
             } else {
                 $user_sid_exists = SJB_UserManager::getUserSIDbyUsername($usr_name);
                 if (empty($user_sid_exists)) {
                     $errors[] = 'User "' . $usr_name . '" not exists. Please enter user name of existing user to the "User Name" field';
                     $usr_name = '';
                 }
             }
         } elseif ($selectUserType == 'group') {
             $userGroupSid = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : 0;
             $usr_id = $userGroupSid;
             $usr_name = SJB_UserGroupManager::getUserGroupIDBySID($usr_id);
             $addNewUser = 1;
         }
         if ($errors) {
             $add_level = 2;
         }
     }
     $listings_type = SJB_ListingTypeManager::getAllListingTypesInfo();
     $types = array();
     foreach ($listings_type as $one) {
         $types[$one['sid']] = $one['id'];
     }
     $tp->assign('types', $types);
     $selected_logo_options = null;
     switch ($add_level) {
         case '1':
             $template = 'add_step_one.tpl';
             /*
             $types = array();
             foreach ( $listings_type as $one ) {
             					  $types[$one['sid']] = $one['id'];
             }
             $tp->assign('types', $types);
             */
             $tp->display('add_step_one.tpl');
             break;
         case '2':
             $template = 'add_step_two.tpl';
             $original_xml = SJB_Request::getVar('xml');
             $xml = $original_xml;
             $tree = '';
             $listing_fields = array();
             $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings');
             $parsing_name = SJB_Request::getVar('parser_name');
             $usr_name = SJB_Request::getVar('parser_user');
             $pars_url = SJB_Request::getVar('parser_url');
             $form_description = SJB_Request::getVar('form_description', '', 'POST');
             $type_id = SJB_Request::getVar('type_id', '', 'POST');
             $selectedLogoOption = SJB_Request::getVar('logo_options');
             $selectedLogoField = SJB_Request::getVar('import_logo_field');
             $selectedProduct = SJB_Request::getVar('postUnderProduct');
             $id = SJB_Request::getVar('id', 0, 'GET');
             $selected = array();
             $a_selected = array();
             if (!empty($_REQUEST['xml']) || $id > 0) {
                 // step 2 OR edit exist
                 if ($id > 0) {
                     // load exist parser
                     $parser_from_id = SJB_XmlImport::getSystemParsers($id);
                     if (isset($parser_from_id[0]['name'])) {
                         $parser_from_id = $parser_from_id[0];
                     }
                     $parsing_name = $parser_from_id['name'];
                     $usr_id = $parser_from_id['usr_id'];
                     $usr_name = $parser_from_id['usr_name'];
                     $form_description = $parser_from_id['description'];
                     $pars_url = $parser_from_id['url'];
                     $type_id = $parser_from_id['type_id'];
                     $selected_logo_options = unserialize($parser_from_id['logo_options']);
                     $selectedLogoOption = $selected_logo_options['option'];
                     $selectedLogoField = $selected_logo_options['field'];
                     $selectedProduct = $parser_from_id['product_sid'];
                     $xml = $parser_from_id['xml'];
                     $xml = SJB_XmlImport::cleanXmlFromImport($xml);
                     $map = unserialize($parser_from_id['maper']);
                     $selected = array_values($map);
                     $a_selected = array_keys($map);
                 } else {
                     $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']);
                 }
                 $sxml = new simplexml();
                 $tree = $sxml->xml_load_file($xml, 'array');
                 if (isset($tree['@content'])) {
                     $tree = $tree[0];
                 }
                 if (is_array($tree)) {
                     $tree = SJB_XmlImport::convertArray($tree);
                     foreach ($tree as $key => $val) {
                         unset($tree[$key]);
                         // replace '@' and ':'
                         $key = SJB_XmlImport::encodeSpecialEntities($key);
                         $tree[$key]['val'] = $val;
                         $tree[$key]['key'] = $key;
                     }
                     $field_types = array(0, $type_id);
                     $listing_fields = array();
                     $i = 0;
                     foreach ($field_types as $type) {
                         $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type);
                         foreach ($listing_fields_info as $listing_field_info) {
                             if ($listing_field_info['type'] == 'location') {
                                 foreach ($listing_field_info['fields'] as $fieldInfo) {
                                     $listing_field = new SJB_ListingField($fieldInfo);
                                     $listing_field->setSID($fieldInfo['sid']);
                                     $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value;
                                     $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                                     $i++;
                                 }
                             } else {
                                 $listing_field = new SJB_ListingField($listing_field_info);
                                 $listing_field->setSID($listing_field_info['sid']);
                                 $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value;
                                 $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                                 $i++;
                             }
                         }
                     }
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date";
                     $i++;
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url";
                     $i++;
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id";
                 } else {
                     $errors[] = 'XML syntaxis error.';
                     $template = 'add_step_one.tpl';
                 }
             } else {
                 $errors[] = 'Please input correct xml';
                 $template = 'add_step_one.tpl';
             }
             $tp->assign('id', $id);
             $tp->assign('selected', $selected);
             $tp->assign('a_selected', $a_selected);
             $tp->assign('xml', htmlspecialchars($xml));
             $tp->assign('xmlToUser', $xml);
             $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo());
             $tp->assign('form_name', $parsing_name);
             $tp->assign('form_user', $usr_name);
             $tp->assign('form_url', $pars_url);
             $tp->assign('form_description', $form_description);
             $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id);
             $tp->assign('type_id', $type_id);
             $tp->assign('type_name', $type_name);
             $tp->assign('errors', $errors);
             $tp->assign('tree', $tree);
             $tp->assign("fields", $listing_fields);
             $tp->assign('logo_options', $logo_options_array);
             $tp->assign('selectedLogoOption', $selectedLogoOption);
             $tp->assign('selectedLogoField', $selectedLogoField);
             $tp->assign('selectedProduct', $selectedProduct);
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->display($template);
             break;
         case '3':
             $parsing_name = isset($_REQUEST['parser_name']) ? SJB_DB::quote($_REQUEST['parser_name']) : '';
             $pars_url = isset($_POST['parser_url']) ? SJB_DB::quote($_POST['parser_url']) : '';
             $selectedLogoOption = isset($_POST['logo_options']) ? $_POST['logo_options'] : '';
             $selectedLogoField = isset($_POST['import_logo_field']) ? $_POST['import_logo_field'] : '';
             $form_description = isset($_REQUEST['form_description']) ? SJB_DB::quote($_REQUEST['form_description']) : "";
             $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : "";
             $script = isset($_POST['custom_script']) && !empty($_POST['custom_script']) ? SJB_DB::quote($_POST['custom_script']) : "";
             $script_users = SJB_DB::quote(SJB_Request::getVar('custom_script_users', '', SJB_Request::METHOD_POST));
             $defaultValue = SJB_Request::getVar('default_value', false);
             $defaultValueUser = SJB_Request::getVar('user_default_value', false);
             $selectedProduct = SJB_Request::getVar('postUnderProduct');
             $importType = SJB_Request::getVar('import_type', 'increment');
             if ($defaultValue) {
                 foreach ($defaultValue as $key => $val) {
                     $defaultValue[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                 }
             }
             if ($defaultValueUser) {
                 foreach ($defaultValueUser as $key => $val) {
                     $defaultValueUser[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                 }
             }
             $original_xml = !empty($_POST['xml']) ? SJB_DB::quote($_POST['xml']) : '';
             $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
             $addQuery = '';
             $username = SJB_XmlImport::decodeSpecialEntities(SJB_Request::getVar('username', ''));
             $external_id = str_replace('_dog_', '@', SJB_Request::getVar('external_id', ''));
             $site_url = SJB_System::getSystemSettings("SITE_URL");
             if ($addNewUser == 1 && empty($_REQUEST['mapped_user'])) {
                 $error = 'Required user profile fields are not mapped';
                 SJB_HelperFunctions::redirect($site_url . '/edit-import/?id=' . $id . '&save_error=' . base64_encode($error));
             }
             if (!empty($_REQUEST['mapped']) && is_array($_REQUEST['mapped']) && !empty($original_xml) && empty($errors)) {
                 // make map
                 $map1 = array();
                 $map2 = array();
                 $serUserMap = '';
                 foreach ($_REQUEST['mapped'] as $one) {
                     $tmp = explode(':', $one);
                     $map1[] = $tmp[0];
                     $map2[] = $tmp[1];
                 }
                 if ($addNewUser == 1 && !empty($_REQUEST['mapped_user']) && is_array($_REQUEST['mapped_user'])) {
                     // make map
                     $mapUser1 = array();
                     $mapUser2 = array();
                     foreach ($_REQUEST['mapped_user'] as $one) {
                         $tmp = explode(':', $one);
                         $mapUser1[] = str_replace('user_', '', $tmp[0]);
                         $mapUser2[] = $tmp[1];
                     }
                     foreach ($mapUser1 as $key => $val) {
                         $val = SJB_XmlImport::decodeSpecialEntities($val);
                         $mapUser[$val] = $mapUser2[$key];
                     }
                     $serUserMap = serialize($mapUser);
                 }
                 //$map = array_combine($map1, $map2); // PHP5
                 foreach ($map1 as $key => $val) {
                     $val = SJB_XmlImport::decodeSpecialEntities($val);
                     $map[$val] = $map2[$key];
                 }
                 if ($selectedLogoOption && $selectedLogoOption != 'not_logo') {
                     //get real data without any cache
                     if (!SJB_ListingFieldDBManager::getListingFieldInfoByID('ListingLogo')) {
                         $listing_field_info = array('id' => 'ListingLogo', 'type' => 'logo', 'is_system' => false, 'is_required' => false, 'caption' => 'Listing Logo');
                         $listing_field = new SJB_ListingField($listing_field_info, $type_id);
                         $pages = SJB_PostingPagesManager::getFirstPageEachListingType();
                         SJB_ListingFieldManager::saveListingField($listing_field, $pages);
                     }
                     if ($key = array_search('ListingLogo', $map) !== false) {
                         unset($map[$key]);
                     }
                 }
                 if ($defaultValue) {
                     foreach ($defaultValue as $key => $val) {
                         if ($val == '') {
                             unset($defaultValue[$key]);
                         }
                     }
                     $defaultValue = SJB_db::quote(serialize($defaultValue));
                     $addQuery .= ", default_value = '" . $defaultValue . "'";
                 }
                 if ($defaultValueUser) {
                     foreach ($defaultValueUser as $keyuser => $valuser) {
                         if ($valuser == '') {
                             unset($defaultValueUser[$keyuser]);
                         }
                     }
                     $defaultValueUser = SJB_db::quote(serialize($defaultValueUser));
                     $addQuery .= ", default_value_user = '******'";
                 }
                 $queryParsUrl = SJB_DB::quote($pars_url);
                 $queryImportType = SJB_DB::quote($importType);
                 $queryId = intval($id);
                 $query = "SET\n\t\t\t\t\t\t\t`custom_script_users` = ?s,\n\t\t\t\t\t\t\t`custom_script` = ?s,\n\t\t\t\t\t\t\t`type_id` = ?n,\n\t\t\t\t\t\t\t`name` = ?s,\n\t\t\t\t\t\t\t`description` = ?s,\n\t\t\t\t\t\t\t`url` = ?s,\n\t\t\t\t\t\t\t`usr_id` = ?n,\n\t\t\t\t\t\t\t`usr_name` = ?s,\n\t\t\t\t\t\t\t`maper_user` = ?s,\n\t\t\t\t\t\t\t`xml` = ?s,\n\t\t\t\t\t\t\t`add_new_user` = ?n,\n\t\t\t\t\t\t\t`username` = ?s,\n\t\t\t\t\t\t\t`external_id` = ?s,\n\t\t\t\t\t\t\t`product_sid` = ?n,\n\t\t\t\t\t\t\t`import_type` = ?s\n\t\t\t\t\t\t\t{$addQuery}";
                 if ($id > 0) {
                     SJB_DB::query("UPDATE `parsers` {$query} WHERE id = ?n", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType, $queryId);
                 } else {
                     $id = SJB_DB::query("INSERT INTO `parsers` {$query}", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType);
                 }
                 $errorFile = '';
                 $xml_logo = null;
                 switch ($selectedLogoOption) {
                     case 'import_logo':
                         $map[$selectedLogoField] = 'ListingLogo';
                         break;
                     case 'upload_logo':
                         if (!empty($_FILES['upload_logo_file'])) {
                             if ($_FILES['upload_logo_file']['error']) {
                                 $errorFile = SJB_UploadFileManager::getErrorId($_FILES['upload_logo_file']['error']);
                             } else {
                                 $width = SJB_Settings::getSettingByName('listing_picture_width');
                                 $height = SJB_Settings::getSettingByName('listing_picture_height');
                                 $property_info['second_width'] = SJB_Settings::getSettingByName('listing_thumbnail_width');
                                 $property_info['second_height'] = SJB_Settings::getSettingByName('listing_thumbnail_height');
                                 $picture = new SJB_UploadPictureManager();
                                 $picture->setWidth($width);
                                 $picture->setHeight($height);
                                 if ($picture->isValidUploadedPictureFile('upload_logo_file')) {
                                     $xml_logo = "XMLImportLogo_{$id}";
                                     $picture->setUploadedFileID($xml_logo);
                                     $picture->uploadPicture('upload_logo_file', $property_info);
                                 }
                             }
                         }
                         break;
                 }
                 $logo_options = serialize(array('option' => $selectedLogoOption, 'field' => $selectedLogoField));
                 $serMap = serialize($map);
                 if ($xml_logo) {
                     SJB_DB::query("UPDATE `parsers` SET maper = ?s, `xml_logo` = ?s, logo_options = ?s  WHERE id = ?n", $serMap, $xml_logo, $logo_options, $id);
                 } else {
                     SJB_DB::query("UPDATE `parsers` SET maper = ?s, logo_options = ?s  WHERE id = ?n", $serMap, $logo_options, $id);
                 }
                 $form_submitted = SJB_Request::getVar('form_action');
                 if ($form_submitted == 'save_info') {
                     SJB_HelperFunctions::redirect($site_url . '/show-import/');
                 } elseif ($form_submitted == 'apply_info') {
                     $getterParameters = '?id=' . $id;
                     if ($errorFile) {
                         $getterParameters .= '&error=' . $errorFile;
                     }
                     SJB_HelperFunctions::redirect($site_url . '/edit-import/' . $getterParameters);
                 }
             } else {
                 if (empty($errors)) {
                     $errors[] = 'No data to save';
                 }
                 $tp->assign('errors', $errors);
                 $tp->assign('xml', htmlspecialchars($original_xml));
                 $tp->assign('xmlToUser', $original_xml);
                 $tp->assign('form_name', $parsing_name);
                 $tp->assign('form_user', $usr_name);
                 $tp->assign('form_url', $pars_url);
                 $tp->assign('form_description', $form_description);
                 $tp->display('add_step_three.tpl');
             }
             break;
     }
 }