コード例 #1
0
ファイル: run_import.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     if ($id > 0) {
         $parserFromID = SJB_XmlImport::getSystemParsers($id);
         $parserFromID = $parserFromID ? array_pop($parserFromID) : array();
         if (!empty($parserFromID['product_sid'])) {
             $result = SJB_XmlImport::runImport($id);
             $tp->assign('id', $id);
             $tp->assign('result', $result);
         } else {
             $errors[] = 'Please select a product';
         }
     } else {
         $errors[] = 'Undefined ID parser';
     }
     $tp->assign('errors', $errors);
     $tp->display('run_import.tpl');
 }
コード例 #2
0
ファイル: show_import.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = isset($_GET['action']) ? $_GET['action'] : '';
     $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     if ($id > 0) {
         switch ($action) {
             case 'activate':
                 SJB_XmlImport::activate($id);
                 break;
             case 'deactivate':
                 SJB_XmlImport::deactivate($id);
                 break;
             default:
                 break;
         }
     }
     $systemParsers = SJB_XmlImport::getSystemParsers('', true);
     $tp->assign('systemParsers', $systemParsers);
     $tp->display('show_import_list.tpl');
 }
コード例 #3
0
ファイル: user_fields.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $selected = array();
     $a_selected = array();
     $defaultValue = array();
     $user_group_sid = SJB_Request::getVar('user_group_sid');
     $id = SJB_Request::getVar('id', 0);
     $tree = '';
     $username = '';
     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];
         }
         $xml = $parser_from_id['xml'];
         $xml = SJB_XmlImport::cleanXmlFromImport($xml);
         $username = SJB_XmlImport::encodeSpecialEntities($parser_from_id['username']);
         $defaultValue = $parser_from_id['default_value_user'] != '' ? unserialize($parser_from_id['default_value_user']) : array();
         if ($parser_from_id['maper_user'] != '') {
             $map = unserialize($parser_from_id['maper_user']);
             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);
         }
     } else {
         $xml = SJB_XmlImport::cleanXmlFromImport(base64_decode($_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;
         }
         $user_profile_fields = SJB_UserDetails::getDetails($user_group_sid);
         $i = count($user_profile_fields);
         foreach ($user_profile_fields as $key => $val) {
             if ($val['type'] == 'location') {
                 foreach ($val['fields'] as $fieldInfo) {
                     $userField = new SJB_UserProfileField($fieldInfo);
                     $userField->setSID($fieldInfo['sid']);
                     $user_profile_fields[$i]['id'] = $val['id'] . '_' . $userField->details->properties['id']->value;
                     $user_profile_fields[$i]['caption'] = $userField->details->properties['id']->value;
                     $i++;
                 }
                 unset($user_profile_fields[$key]);
             }
             if ($val['id'] == 'username') {
                 unset($user_profile_fields[$key]);
             }
         }
     } else {
         $errors[] = 'XML syntaxis error.';
     }
     $tp->assign('username', $username);
     $tp->assign('id', $id);
     $tp->assign('selecteduser', $selected);
     $tp->assign('a_selecteduser', $a_selected);
     $tp->assign('xml', htmlspecialchars($xml));
     $tp->assign('errors', $errors);
     $tp->assign('tree', $tree);
     $tp->assign("fields", $user_profile_fields);
     $tp->assign('user_default_value', $defaultValue);
     $tp->display('user_fields.tpl');
 }
コード例 #4
0
ファイル: edit_import.php プロジェクト: Maxlander/shixi
 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');
 }
コード例 #5
0
ファイル: task_scheduler.php プロジェクト: Maxlander/shixi
    private function runTaskScheduler()
    {
        // Deactivate Expired Listings & Send Notifications
        $listingsExpiredID = SJB_ListingManager::getExpiredListingsSID();
        foreach ($listingsExpiredID as $listingExpiredID) {
            SJB_ListingManager::deactivateListingBySID($listingExpiredID, true);
            $listing = SJB_ListingManager::getObjectBySID($listingExpiredID);
            $listingInfo = SJB_ListingManager::createTemplateStructureForListing($listing);
            if (SJB_UserNotificationsManager::isUserNotifiedOnListingExpiration($listing->getUserSID())) {
                SJB_Notifications::sendUserListingExpiredLetter($listingInfo);
            }
            // notify admin
            SJB_AdminNotifications::sendAdminListingExpiredLetter($listingInfo);
        }
        $listingsDeactivatedID = array();
        if (SJB_Settings::getSettingByName('automatically_delete_expired_listings')) {
            $listingsDeactivatedID = SJB_ListingManager::getDeactivatedListingsSID();
            foreach ($listingsDeactivatedID as $listingID) {
                SJB_ListingManager::deleteListingBySID($listingID);
            }
        }
        SJB_ListingManager::unFeaturedListings();
        SJB_ListingManager::unPriorityListings();
        SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_LISTINGS));
        /////////////////////////// Send remind notifications about expiration of LISTINGS
        // 1. get user sids and days count of 'remind listing notification' setting = 1 from user_notifications table
        // 2. foreach user:
        //   - get listings with that expiration remind date
        //   - check every listing sid in DB table of sended. If sended - remove from send list
        //   - send notification with listings to user
        //   - write listings sid in DB table of sended notifications
        $notificationData = SJB_UserNotificationsManager::getUsersAndDaysOnListingExpirationRemind();
        foreach ($notificationData as $elem) {
            $userSID = $elem['user_sid'];
            $days = $elem['days'];
            $listingSIDs = SJB_ListingManager::getListingsIDByDaysLeftToExpired($userSID, $days);
            if (empty($listingSIDs)) {
                continue;
            }
            $listingsInfo = array();
            // check listings remind sended
            foreach ($listingSIDs as $key => $sid) {
                if (SJB_ListingManager::isListingNotificationSended($sid)) {
                    unset($listingSIDs[$key]);
                    continue;
                }
                $info = SJB_ListingManager::getListingInfoBySID($sid);
                $listingsInfo[$sid] = $info;
            }
            if (!empty($listingsInfo)) {
                // now only unsended listings we have in array
                // send listing notification
                foreach ($listingSIDs as $sid) {
                    SJB_Notifications::sendRemindListingExpirationLetter($userSID, $sid, $days);
                }
                // write listing id in DB table of sended notifications
                SJB_ListingManager::saveListingIDAsSendedNotificationsTable($listingSIDs);
            }
        }
        // Send Notifications for Expired Contracts
        $contractsExpiredID = SJB_ContractManager::getExpiredContractsID();
        foreach ($contractsExpiredID as $contractExpiredID) {
            $contractInfo = SJB_ContractManager::getInfo($contractExpiredID);
            $productInfo = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']);
            $userInfo = SJB_UserManager::getUserInfoBySID($contractInfo['user_sid']);
            $serializedExtraInfo = unserialize($contractInfo['serialized_extra_info']);
            if (!empty($serializedExtraInfo['featured_profile']) && !empty($userInfo['featured'])) {
                $contracts = SJB_ContractManager::getAllContractsInfoByUserSID($userInfo['sid']);
                $isFeatured = 0;
                foreach ($contracts as $contract) {
                    if ($contract['id'] != $contractExpiredID) {
                        $serializedExtraInfo = unserialize($contract['serialized_extra_info']);
                        if (!empty($serializedExtraInfo['featured'])) {
                            $isFeatured = 1;
                        }
                    }
                }
                if (!$isFeatured) {
                    SJB_UserManager::removeFromFeaturedBySID($userInfo['sid']);
                }
            }
            if (SJB_UserNotificationsManager::isUserNotifiedOnContractExpiration($contractInfo['user_sid'])) {
                SJB_Notifications::sendUserContractExpiredLetter($userInfo, $contractInfo, $productInfo);
            }
            // notify admin
            SJB_AdminNotifications::sendAdminUserContractExpiredLetter($userInfo['sid'], $contractInfo, $productInfo);
            SJB_ContractManager::deleteContract($contractExpiredID, $contractInfo['user_sid']);
        }
        //////////////////////// Send remind notifications about expiration of contracts
        // 1. get user sids and days count of 'remind subscription notification' setting = 1 from user_notifications table
        // 2. foreach user:
        //   - get contracts with that expiration remind date
        //   - check every contract sid in DB table of sended. If sended - remove from send list
        //   - send notification with contracts to user
        //   - write contract sid in DB table of sended contract notifications
        $notificationData = SJB_UserNotificationsManager::getUsersAndDaysOnSubscriptionExpirationRemind();
        foreach ($notificationData as $elem) {
            $userSID = $elem['user_sid'];
            $days = $elem['days'];
            $contractSIDs = SJB_ContractManager::getContractsIDByDaysLeftToExpired($userSID, $days);
            if (empty($contractSIDs)) {
                continue;
            }
            $contractsInfo = array();
            // check contracts sended
            foreach ($contractSIDs as $key => $sid) {
                if (SJB_ContractManager::isContractNotificationSended($sid)) {
                    unset($contractSIDs[$key]);
                    continue;
                }
                $info = SJB_ContractManager::getInfo($sid);
                $info['extra_info'] = !empty($info['serialized_extra_info']) ? unserialize($info['serialized_extra_info']) : '';
                $contractsInfo[$sid] = $info;
            }
            if (!empty($contractsInfo)) {
                // now only unsended contracts we have in array
                // send contract notification
                foreach ($contractSIDs as $sid) {
                    SJB_Notifications::sendRemindSubscriptionExpirationLetter($userSID, $contractsInfo[$sid], $days);
                }
                // write contract id in DB table of sended contract notifications
                SJB_ContractManager::saveContractIDAsSendedNotificationsTable($contractSIDs);
            }
        }
        // delete applications with no employer and job seeker
        $emptyApplications = SJB_DB::query('SELECT `id` FROM `applications` WHERE `show_js` = 0 AND `show_emp` = 0');
        foreach ($emptyApplications as $application) {
            SJB_Applications::remove($application['id']);
        }
        // NEWS
        $expiredNews = SJB_NewsManager::getExpiredNews();
        foreach ($expiredNews as $article) {
            SJB_NewsManager::deactivateItemBySID($article['sid']);
        }
        // LISTING XML IMPORT
        SJB_XmlImport::runImport();
        // UPDATE PAGES WITH FUNCTION EQUAL BROWSE(e.g. /browse-by-city/)
        SJB_BrowseDBManager::rebuildBrowses();
        //-------------------sitemap generator--------------------//
        SJB_System::executeFunction('miscellaneous', 'sitemap_generator');
        // CLEAR `error_log` TABLE
        $errorLogLifetime = SJB_System::getSettingByName('error_log_lifetime');
        $lifeTime = strtotime("-{$errorLogLifetime} days");
        if ($lifeTime > 0) {
            SJB_DB::query('DELETE FROM `error_log` WHERE `date` < ?t', $lifeTime);
        }
        SJB_Settings::updateSetting('task_scheduler_last_executed_date', $this->currentDate);
        $this->tp->assign('expired_listings_id', $listingsExpiredID);
        $this->tp->assign('deactivated_listings_id', $listingsDeactivatedID);
        $this->tp->assign('expired_contracts_id', $contractsExpiredID);
        $this->tp->assign('notified_saved_searches_id', $this->notifiedSavedSearchesSID);
        $schedulerLog = $this->tp->fetch('task_scheduler_log.tpl');
        SJB_HelperFunctions::writeCronLogFile('task_scheduler.log', $schedulerLog);
        SJB_DB::query('INSERT INTO `task_scheduler_log`
			(`last_executed_date`, `notifieds_sent`, `expired_listings`, `expired_contracts`, `log_text`)
			VALUES ( NOW(), ?n, ?n, ?n, ?s)', count($this->notifiedSavedSearchesSID), count($listingsExpiredID), count($contractsExpiredID), $schedulerLog);
        SJB_System::getModuleManager()->executeFunction('social', 'linkedin');
        SJB_System::getModuleManager()->executeFunction('social', 'facebook');
        SJB_System::getModuleManager()->executeFunction('classifieds', 'linkedin');
        SJB_System::getModuleManager()->executeFunction('classifieds', 'facebook');
        SJB_System::getModuleManager()->executeFunction('classifieds', 'twitter');
        SJB_Event::dispatch('task_scheduler_run');
    }
コード例 #6
0
ファイル: add_import.php プロジェクト: Maxlander/shixi
 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;
     }
 }