Пример #1
0
 public function execute()
 {
     $this->tp = SJB_System::getTemplateProcessor();
     $error = null;
     $post_max_size_orig = ini_get("post_max_size");
     $session_maxlifetime = ini_get("session.gc_maxlifetime");
     $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
     $this->listingTypeID = SJB_Request::getVar('listing_type_id', false);
     /**
      * >>>>> for listing preview @author still
      */
     $this->formSubmittedFromPreview = SJB_Request::getVar('action_add', false, 'POST') && SJB_Request::getVar('from-preview', false, 'POST');
     $editTempListing = SJB_Request::getVar('edit_temp_listing', false, 'POST');
     if ($this->formSubmittedFromPreview || $editTempListing) {
         $listingSID = SJB_Session::getValue('preview_listing_sid_for_add');
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSID);
         if (empty($this->listingTypeID) && !empty($listingInfo)) {
             // if on preview page "POST" button was pressed
             if ($this->formSubmittedFromPreview) {
                 $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
                 $properties = $listing->getProperties();
                 foreach ($properties as $fieldID => $property) {
                     switch ($property->getType()) {
                         case 'date':
                             if (!empty($listingInfo[$fieldID])) {
                                 $listingInfo[$fieldID] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID]);
                             }
                             break;
                         case 'complex':
                             $complex = $property->type->complex;
                             $complexProperties = $complex->getProperties();
                             foreach ($complexProperties as $complexfieldID => $complexProperty) {
                                 if ($complexProperty->getType() == 'date') {
                                     $values = $complexProperty->getValue();
                                     foreach ($values as $index => $value) {
                                         if (!empty($listingInfo[$fieldID][$complexfieldID][$index])) {
                                             $listingInfo[$fieldID][$complexfieldID][$index] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID][$complexfieldID][$index]);
                                         }
                                     }
                                 }
                             }
                             break;
                     }
                 }
             }
             if ($editTempListing || $this->formSubmittedFromPreview) {
                 $current_user = SJB_UserManager::getCurrentUser();
                 $this->listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
                 // check wether user is owner of the temp listing
                 if ($listingInfo['user_sid'] != $current_user->getID()) {
                     $error['NOT_OWNER_OF_LISTING'] = $listingSID;
                 }
                 // set listing info and listing type id
                 $_REQUEST = array_merge($_REQUEST, $listingInfo);
                 $_REQUEST['listing_type_id'] = $this->listingTypeID;
             }
         }
         if (empty($listingInfo)) {
             $listingSID = null;
             SJB_Session::unsetValue('preview_listing_sid_for_add');
         }
     } else {
         $listingSID = null;
         SJB_Session::unsetValue('preview_listing_sid_for_add');
     }
     /*
      * <<<<< for listing preview
      */
     // get post_max_size in bytes
     $val = trim($post_max_size_orig);
     $tmp = substr($val, strlen($val) - 1);
     $tmp = strtolower($tmp);
     /*
      * if ini value is K - then multiply to 1024
      * if ini value is M - then multiply twice: in case 'm', and case 'k'
      * if ini value is G - then multiply tree times: in 'g', 'm', 'k'
      *
      * out value - in bytes!
      */
     switch ($tmp) {
         case 'g':
             $val *= 1024;
         case 'm':
             $val *= 1024;
         case 'k':
             $val *= 1024;
     }
     $post_max_size = $val;
     $filename = SJB_Request::getVar('filename', false);
     if ($filename) {
         $listing_id = SJB_Request::getVar('listing_id', '', 'default', 'int');
         $file = SJB_UploadFileManager::openFile($filename, $listing_id);
         $errors['NO_SUCH_FILE'] = true;
     }
     if (empty($_POST) && $server_content_length > $post_max_size) {
         $errors['MAX_FILE_SIZE_EXCEEDED'] = 1;
         $listing_id = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $this->tp->assign('post_max_size', $post_max_size_orig);
     }
     $tmpListingIDFromRequest = SJB_Request::getVar('listing_id', false, 'default', 'int');
     if (!empty($tmpListingIDFromRequest)) {
         $tmpListingSID = $tmpListingIDFromRequest;
     } elseif (!$tmpListingIDFromRequest) {
         $tmpListingSID = time();
     }
     $this->buttonPressedPostToProceed = SJB_Request::getVar('proceed_to_posting');
     if (SJB_UserManager::isUserLoggedIn()) {
         SJB_Session::unsetValue('proceed_to_posting');
         SJB_Session::unsetValue('productSID');
         SJB_Session::unsetValue('listing_type_id');
         if (!is_null($this->buttonPressedPostToProceed)) {
             $productSID = SJB_Request::getVar('productSID', false, 'default', 'int');
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             $userInfo = SJB_UserManager::getCurrentUserInfo();
             if ($userInfo['user_group_sid'] == $productInfo['user_group_sid']) {
                 $this->tp->assign('productSID', $productSID);
                 $this->tp->assign('proceed_to_posting', $productSID);
                 $this->tp->assign("listing_id", $tmpListingSID);
                 $this->addListing($listingSID, 0, $productSID);
             } else {
                 $this->displayErrorTpl('DO_NOT_MATCH_POST_THIS_TYPE_LISTING');
             }
         } else {
             if ($productsInfo = SJB_ListingManager::canCurrentUserAddListing($error, $this->listingTypeID)) {
                 if ($contractID = SJB_Request::getVar('contract_id', false, 'POST')) {
                     $this->tp->assign("listing_id", $tmpListingSID);
                     $this->addListing($listingSID, $contractID, false);
                 } elseif (count($productsInfo) == 1) {
                     $productInfo = array_pop($productsInfo);
                     $contractID = $productInfo['contract_id'];
                     $this->tp->assign("listing_id", $tmpListingSID);
                     $this->addListing($listingSID, $contractID, false);
                 } else {
                     $this->tp->assign('listing_id', $tmpListingSID);
                     $this->tp->assign('products_info', $productsInfo);
                     $this->tp->assign('listingTypeID', $this->listingTypeID);
                     $this->tp->display('listing_product_choice.tpl');
                 }
             } else {
                 if ($error == 'NO_CONTRACT') {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/products/?postingProductsOnly=1&page=');
                 }
                 $this->displayErrorTpl($error);
             }
         }
     } else {
         if ($this->buttonPressedPostToProceed != false) {
             SJB_Session::setValue('proceed_to_posting', true);
             SJB_Session::setValue('productSID', SJB_Request::getVar('productSID', '', 'default', 'int'));
             SJB_Session::setValue('listing_type_id', $this->listingTypeID);
         }
         $this->displayErrorTpl('NOT_LOGGED_IN');
     }
 }
Пример #2
0
 public static function getRedirectUrlByPageID($pageId)
 {
     $error = '';
     if (!is_null(SJB_Session::getValue('fromAnonymousShoppingCart'))) {
         SJB_Session::unsetValue('fromAnonymousShoppingCart');
         return SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/?';
     }
     $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/my-account/?';
     if (empty($pageId)) {
         return $redirectUrl;
     }
     if ($pageId == 'posting_page') {
         $user = SJB_UserManager::getCurrentUser();
         $userGroupId = SJB_UserGroupManager::getUserGroupIDBySID($user->getUserGroupSID());
         $listingTypeSid = SJB_ListingTypeManager::getListingTypeByUserSID($user->getSID());
         $listingTypeId = !empty($listingTypeSid) ? SJB_ListingTypeManager::getListingTypeIDBySID(array_pop($listingTypeSid)) : '';
         if ($user->hasContract() && SJB_ListingManager::canCurrentUserAddListing($error, $listingTypeId)) {
             $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/add-listing/?listing_type_id=' . $listingTypeId . "&";
         } elseif ($user->hasContract()) {
             $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/my-account/?';
         } else {
             $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/' . mb_strtolower($userGroupId) . '-products/?postingProductsOnly=1&';
         }
     }
     return $redirectUrl;
 }