public static function notifyOnUserDeactivated($username) { $userSID = SJB_UserManager::getUserSIDbyUsername($username); if (SJB_UserNotificationsManager::isUserNotifiedOnProfileDeactivation($userSID)) { $user = SJB_UserManager::getObjectBySID($userSID); $userGroupSID = $user->getUserGroupSID(); $emailTplSID = SJB_UserGroupManager::getEmailTemplateSIDByUserGroupAndField($userGroupSID, 'notify_user_on_deactivation'); $user = SJB_UserManager::createTemplateStructureForUser($user); $data = array('user' => $user); $email = SJB_EmailTemplateEditor::getEmail($user['email'], $emailTplSID, $data); return $email->send('User Deactivated'); } return null; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $listingTypeID = SJB_Request::getVar('listing_type_id', null); $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID); $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID); $productSID = SJB_Request::getVar('product_sid', false); $editUser = SJB_Request::getVar('edit_user', false); $action = SJB_Request::getVar('action', false); $username = SJB_Request::getVar('username', false); $errors = array(); if ($username && ($userSID = SJB_UserManager::getUserSIDbyUsername($username))) { $userInfo = SJB_UserManager::getUserInfoBySID($userSID); $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']); if (!$productSID) { $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupInfo['sid']); foreach ($products as $key => $product) { if (empty($product['listing_type_sid']) || $product['listing_type_sid'] != $listingTypeSID) { unset($products[$key]); } } if ($action == 'productVerify') { $errors['PRODUCT_NOT_SELECTED'] = 1; } $tp->assign('errors', $errors); $tp->assign('username', $username); $tp->assign('products', $products); $tp->assign('edit_user', $editUser); $tp->assign('userSID', $userSID); $tp->assign('userGroupInfo', $userGroupInfo); $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo)); $tp->display('select_product.tpl'); } else { $form_submitted = SJB_Request::getVar('action', '') == 'add'; $tmp_listing_id_from_request = SJB_Request::getVar('listing_id', false, 'default', 'int'); if (!empty($tmp_listing_id_from_request)) { $tmp_listing_sid = $tmp_listing_id_from_request; } elseif (!$tmp_listing_id_from_request) { $tmp_listing_sid = time(); } $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID); $extraInfo = is_null($productInfo['serialized_extra_info']) ? null : unserialize($productInfo['serialized_extra_info']); if (!empty($extraInfo)) { $extraInfo['product_sid'] = $productSID; } $_REQUEST['featured'] = !empty($_REQUEST['featured']) ? $_REQUEST['featured'] : $productInfo['featured']; $_REQUEST['priority'] = !empty($_REQUEST['priority']) ? $_REQUEST['priority'] : $productInfo['priority']; $listing = new SJB_Listing($_REQUEST, $listingTypeSID); $properties = $listing->getPropertyList(); foreach ($properties as $property) { $propertyInfo = $listing->getPropertyInfo($property); $propertyInfo['user_sid'] = $userSID; if ($propertyInfo['type'] == 'location') { $child = $listing->getChild($property); $childProperties = $child->getPropertyList(); foreach ($childProperties as $childProperty) { $childPropertyInfo = $child->getPropertyInfo($childProperty); $childPropertyInfo['user_sid'] = $userSID; $child->setPropertyInfo($childProperty, $childPropertyInfo); } } $listing->setPropertyInfo($property, $propertyInfo); } $listing->deleteProperty('status'); $listing->deleteProperty('reject_reason'); $access_type = $listing->getProperty('access_type'); if ($form_submitted) { if (!empty($access_type)) { $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true)); } } $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($userSID); if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) { $issetQuestionnairyField = $listing->getProperty('screening_questionnaire'); if ($issetQuestionnairyField) { $value = SJB_Request::getVar("screening_questionnaire"); $listing_info = $_REQUEST; $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : ''; $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($userSID), 'is_system' => true)); } } else { $listing->deleteProperty('screening_questionnaire'); } if ($listing->getProperty('captcha')) { $listing->deleteProperty('captcha'); } $add_listing_form = new SJB_Form($listing); $add_listing_form->registerTags($tp); $field_errors = array(); if ($form_submitted && $add_listing_form->isDataValid($field_errors)) { $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true)); $listing->setUserSID($userSID); $listing->setProductInfo($extraInfo); if (empty($access_type->value)) { $listing->setPropertyValue('access_type', 'everyone'); } SJB_ListingManager::saveListing($listing); SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $_REQUEST['featured'], $_REQUEST['priority'], $userSID); if (isset($_SESSION['tmp_file_storage'])) { foreach ($_SESSION['tmp_file_storage'] as $v) { SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']); SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']); } SJB_Session::unsetValue('tmp_file_storage'); } $formToken = SJB_Request::getVar('form_token'); $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage'); $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken); if (!empty($uploadedFields)) { foreach ($uploadedFields as $fieldId => $fieldValue) { // get field of listing $isComplex = false; if (strpos($fieldId, ':') !== false) { $isComplex = true; } $tmpUploadedFileId = $fieldValue['file_id']; // rename it to real listing field value $newFileId = $fieldId . "_" . $listing->getSID(); SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId); if ($isComplex) { list($parentField, $subField, $complexStep) = explode(':', $fieldId); $parentProp = $listing->getProperty($parentField); $parentValue = $parentProp->getValue(); // look for complex property with current $fieldID and set it to new value of property if (!empty($parentValue)) { foreach ($parentValue as $id => $value) { if ($id == $subField) { $parentValue[$id][$complexStep] = $newFileId; } } $listing->setPropertyValue($parentField, $parentValue); } } else { $listing->setPropertyValue($fieldId, $newFileId); } // unset value from session temporary storage $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}"); } //and remove token key from temporary storage $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}"); SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage); SJB_ListingManager::saveListing($listing); } SJB_ListingManager::activateListingBySID($listing->getSID()); SJB_ProductsManager::incrementPostingsNumber($productSID); $listingSid = $listing->getSID(); SJB_Event::dispatch('listingSaved', $listingSid); if ($editUser) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user/?user_sid=" . $userSID); } else { if ($listingTypeID == 'resume' || $listingTypeID == 'job') { $link = "manage-" . strtolower($listingTypeID) . "s"; } else { $link = "manage-" . strtolower($listingTypeID) . "-listings"; } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/{$link}/?action=search&listing_type_sid=" . $listingTypeSID); } } else { $listing->deleteProperty('access_list'); $listing->deleteProperty('contract_id'); $add_listing_form = new SJB_Form($listing); if ($form_submitted) { $add_listing_form->isDataValid($field_errors); } $add_listing_form->registerTags($tp); $form_fields = $add_listing_form->getFormFieldsInfo(); $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID); $formFieldsSorted = array(); $formFieldsSorted['featured'] = $form_fields['featured']; $formFieldsSorted['priority'] = $form_fields['priority']; foreach ($pages as $page) { $listing_fields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']); foreach (array_keys($listing_fields) as $field) { if ($listing->propertyIsSet($field)) { $formFieldsSorted[$field] = $form_fields[$field]; } } } $form_fields = $formFieldsSorted; //SJB_HelperFunctions::d($form_fields); $employers_list = SJB_Request::getVar('list_emp_ids', false); $employers = array(); if (is_array($employers_list)) { foreach ($employers_list as $emp) { $currEmp = SJB_UserManager::getUserInfoBySID($emp); $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']); } sort($employers); } $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0; $tp->assign("pic_limit", $numberOfPictures); $tp->assign("listing_id", $tmp_listing_sid); $tp->assign("listing_access_list", $employers); $tp->assign("errors", $field_errors); $tp->assign("form_fields", $form_fields); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields))); } $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('edit_user', $editUser); $tp->assign('productInfo', $productInfo); $tp->assign('username', $username); $tp->assign('product_sid', $productSID); $tp->assign('userSID', $userSID); $tp->assign('userGroupInfo', $userGroupInfo); $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo)); $tp->display('input_form.tpl'); } } else { if ($username && !$userSID) { $errors['USER_NOT_FOUND'] = 1; } elseif ($action == 'userVerify') { $errors['USER_NOT_SELECTED'] = 1; } $tp->assign('errors', $errors); $tp->assign('username', $username); $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo)); $tp->display('select_user.tpl'); } }
public function execute() { ini_set('max_execution_time', 0); $template_processor = SJB_System::getTemplateProcessor(); $errors = array(); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; if (!empty($file_info)) { $extension = $_REQUEST['file_type']; if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) { $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true; } } if (empty($file_info) || $file_info['error'] || !empty($errors)) { if (isset($file_info['error']) && $file_info['error'] > 0) { $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1; } $user_groups = SJB_UserGroupManager::getAllUserGroupsInfo(); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $template_processor->assign('user_groups', $user_groups); $template_processor->assign('errors', $errors); $template_processor->assign('charSets', SJB_HelperFunctions::getCharSets()); $template_processor->display('import_users.tpl'); } else { $csv_delimiter = SJB_Request::getVar('csv_delimiter', null); $user_group_id = SJB_Request::getVar('user_group_id', null); $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id); if ($extension == 'xls') { $import_file = new SJB_ImportFileXLS($file_info); } elseif ($extension == 'csv') { $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter); } $import_file->parse($encodingFromCharset); $user = $this->CreateUser(array(), $user_group_id); $imported_data = $import_file->getData(); $count = 0; $import_file_url = false; $usersID = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_user_processor = new SJB_ImportedUserProcessor($importedColumn, $user); continue; } if (!$importedColumn) { continue; } $userInfo = $imported_user_processor->getData($importedColumn); $extUserID = isset($userInfo['extUserID']) ? $userInfo['extUserID'] : ''; $user = $this->CreateUser(array(), $user_group_id); $user->addExtUserIDProperty(); $doc = new DOMDocument(); foreach ($user->getProperties() as $property) { if ($property->id == 'active') { $property->type->property_info['value'] = $property->value; } elseif ($property->getType() == 'location') { $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode', $property->id . '.Address'); $locationFieldAdded = array(); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $userInfo)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]); } break; default: $value = $userInfo[$locationField]; break; } unset($userInfo[$locationField]); $userInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value; $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField); } } if ($property->id == 'Location') { $locationFields = array('Country', 'State', 'City', 'ZipCode', 'Address'); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $userInfo) && !in_array($locationField, $locationFieldAdded) && !$user->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]); } break; default: $value = $userInfo[$locationField]; break; } $userInfo[$property->id][$locationField] = $value; unset($userInfo[$locationField]); } } } } } $user = $this->CreateUser($userInfo, $user_group_id); $user->addExtUserIDProperty($extUserID); $username = SJB_Array::get($userInfo, 'username'); if (empty($username)) { $errors[] = 'Empty username is not allowed, record ignored.'; } elseif (!is_null(SJB_UserManager::getUserSIDbyUsername($username))) { $errors[] = '\'' . $userInfo['username'] . '\' - this user name already exists, record ignored.'; } else { $originalMd5Password = $user->getPropertyValue('password'); SJB_UserManager::saveUser($user); $this->extraProperties($user, $userInfo, $usersID); if (!empty($originalMd5Password)) { SJB_UserManager::saveUserPassword($user->getSID(), $originalMd5Password); } $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid); if ($isApproveByAdmin) { SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending'); } $count++; } } if ($import_file_url) { SJB_Filesystem::delete(SJB_System::getSystemSettings("IMPORT_FILES_DIRECTORY")); } $template_processor->assign('imported_users_count', $count); $template_processor->assign('errors', $errors); $template_processor->display('import_users_result.tpl'); } }
function _getChargedTemplateProcessor(&$listings_structure) { $tp = SJB_System::getTemplateProcessor(); $searchCriteria = $this->criteria_saver->getCriteria(); $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($this->listing_type_sid); if (!empty($listing_type_info['show_brief_or_detailed'])) { $is_show_brief_or_detailed = $listing_type_info['show_brief_or_detailed']; $show_brief_or_detailed = $this->criteria_saver->getBriefOrDetailedSearch(); $tp->assign("is_show_brief_or_detailed", $is_show_brief_or_detailed); $tp->assign("show_brief_or_detailed", $show_brief_or_detailed); } $keywordsHighlight = ''; if (isset($searchCriteria['keywords']) && SJB_System::getSettingByName('use_highlight_for_keywords')) { foreach ($searchCriteria['keywords'] as $type => $keywords) { $keywordsTrim = trim($keywords); if (!empty($keywordsTrim)) { switch ($type) { case 'like': case 'exact_phrase': $keywordsHighlight = json_encode($keywords); break; case 'all_words': case 'any_words': $keywordsHighlight = json_encode(explode(' ', $keywords)); break; case 'boolean': $keywordsHighlight = json_encode(SJB_BooleanEvaluator::parse($keywords, true)); break; } } } } $view = !empty($this->requested_data['view']) ? $this->requested_data['view'] : 'list'; $tp->assign("keywordsHighlight", $keywordsHighlight); $tp->assign("sorting_field", $this->listing_search_structure['sorting_field']); $tp->assign("sorting_order", $this->listing_search_structure['sorting_order']); $tp->assign("listing_search", $this->listing_search_structure); $tp->assign("listings", $listings_structure); $tp->assign("searchId", $this->searchId); $tp->assign("view_on_map", SJB_System::getSettingByName('view_on_map')); $tp->assign("view", $view); $listing = new SJB_Listing(array(), $this->listing_type_sid); $user = new SJB_User(array()); $listing_structure_meta_data = SJB_ListingManager::createMetadataForListing($listing, $user); if (isset($searchCriteria['username']['equal'])) { $userSID = SJB_UserManager::getUserSIDbyUsername($searchCriteria['username']['equal']); $user = SJB_UserManager::getObjectBySID($userSID); $userInfo = !empty($user) ? SJB_UserManager::createTemplateStructureForUser($user) : null; $tp->assign("userInfo", $userInfo); } if (isset($searchCriteria['listing_type']['equal']) && SJB_System::getSettingByName('turn_on_refine_search_' . $searchCriteria['listing_type']['equal']) && $this->useRefine) { $tp->assign("refineSearch", true); } $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $metadata = array("listing" => $metaDataProvider->getMetaData($listing_structure_meta_data)); $tp->assign("METADATA", $metadata); return $tp; }
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; } }