예제 #1
0
파일: admin.php 프로젝트: Maxlander/shixi
 /**
  * logging administrator out of system
  *
  * Function logs administrator out of system
  */
 public static function admin_log_out()
 {
     SJB_Session::unsetValue('username');
     SJB_Session::unsetValue('usertype');
     SJB_Session::unsetValue('adminLoginCounter');
     setcookie("admin_mode", '', time() - 3600, '/');
 }
예제 #2
0
    public function doBackup()
    {
        $settings = SJB_Settings::getSettings();
        if ($settings['autobackup'] && !SJB_System::getSystemSettings('isDemo') && !SJB_System::getIfTrialModeIsOn()) {
            $dirSeparator = DIRECTORY_SEPARATOR;
            $scriptPath = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__);
            $scriptPath = array_shift($scriptPath);
            $path = $scriptPath . 'backup' . $dirSeparator;
            $identifier = time();
            $backupsArr = $this->getAllBackups($path);
            $this->deleteBackupAfterExpired($backupsArr);
            if ($this->isAutobackup()) {
                SessionStorage::destroy('backup_' . $identifier);
                SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                SJB_Session::unsetValue('restore');
                SJB_Session::unsetValue('error');
                $backupDir = $scriptPath . 'backup' . $dirSeparator;
                if (!is_dir($backupDir)) {
                    mkdir($backupDir);
                }
                if (!file_exists($backupDir . '.htaccess')) {
                    $handle = fopen($backupDir . '.htaccess', 'a');
                    $text = '# Apache 2.4
<IfModule mod_authz_core.c>
	<FilesMatch ".*">
		Require all denied
	</FilesMatch>
</IfModule>

# Apache 2.2
<IfModule !mod_authz_core.c>
	<FilesMatch ".*">
		Order Allow,Deny
		Deny from all
	</FilesMatch>
</IfModule>';
                    fwrite($handle, $text);
                    fclose($handle);
                }
                $backupType = SJB_System::getSettingByName('backup_type');
                switch ($backupType) {
                    case 'full':
                        $this->makeFullBackup($identifier, $scriptPath, $dirSeparator);
                        break;
                    case 'database':
                        $this->makeDatabaseBackup($identifier, $dirSeparator, $scriptPath);
                        break;
                    case 'files':
                        $this->makeFilesBackup($identifier, $scriptPath, $dirSeparator);
                        break;
                }
                SJB_Settings::updateSetting('last_autobackup', date("Y-m-d H:i:s"));
            }
        }
    }
예제 #3
0
 /**
  * @param $feedSID
  * @param string $accountId
  * @return array|null
  */
 public function saveAccountInfo($feedSID, $accountId)
 {
     self::$object = new SJB_LinkedIn($this->createCallbackUrl());
     $accessToken = self::$object->_getAccessToken();
     $liveTime = isset($accessToken->_params['oauth_expires_in']) ? $accessToken->_params['oauth_expires_in'] : 60 * 24 * 60 * 60;
     $expirationDate = date('Y-m-d', time() + $liveTime);
     $accessToken = serialize($accessToken);
     if (!empty($accountId)) {
         $result = SJB_DB::query('UPDATE `linkedin_feeds` SET `access_token` = ?s, expiration_date = ?s, `account_id` = ?s WHERE `sid` = ?n OR `access_token` = ?s', $accessToken, $expirationDate, $accountId, $feedSID, $accessToken);
     } else {
         $result = SJB_DB::query('UPDATE `linkedin_feeds` SET `access_token` = ?s, expiration_date = ?s WHERE `sid` = ?n OR `access_token` = ?s', $accessToken, $expirationDate, $feedSID, $accessToken);
     }
     if ($result) {
         self::$object->setAccessToken(null);
         SJB_Session::unsetValue(self::NETWORK_ID);
     }
     return $result;
 }
예제 #4
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $currentUser = SJB_UserManager::getCurrentUser();
     $products = array();
     if (!empty($_SESSION['products'])) {
         $products = $_SESSION['products'];
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         foreach ($products as $product) {
             if (!empty($product['product_info'])) {
                 $productInfo = unserialize($product['product_info']);
                 if ($currentUser->getUserGroupSID() != $productInfo['user_group_sid']) {
                     SJB_Session::unsetValue('products');
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=user_group");
                 } else {
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUser->getSID());
                 }
             }
         }
         SJB_Session::unsetValue('products');
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
     }
     $total_price = 0;
     foreach ($products as $product) {
         $productInfo = unserialize($product['product_info']);
         $product = new SJB_Product($productInfo, $productInfo['product_type']);
         $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
         $product->setNumberOfListings($number_of_listings);
         $productInfo['price'] = $product->getPrice();
         $total_price += $productInfo['price'];
         if ($productInfo['pricing_type'] != 'volume_based' && $productInfo['code_info']) {
             $total_price += $productInfo['code_info']['promoAmount'];
         }
     }
     $tp->assign('products_number', count($products));
     $tp->assign('total_price', $total_price);
     $tp->assign("currency", SJB_CurrencyManager::getDefaultCurrency());
     $tp->display('show_shopping_cart.tpl');
 }
예제 #5
0
 public static function copyFilesAndPicturesFromListing($srcListingSid, $dstListingSid, $tmpListingSid)
 {
     $listing = SJB_ListingManager::getObjectBySID($srcListingSid);
     if ($listing) {
         foreach ($listing->getProperties() as $listingProperty) {
             if ($listingProperty->getType() == 'complex') {
                 self::copyComplexFiles($dstListingSid, $listingProperty);
             } elseif (in_array($listingProperty->getType(), array('file', 'video'))) {
                 self::copyFiles($dstListingSid, $listingProperty);
             }
         }
     }
     if ($tmpListingSid) {
         $gallery = new SJB_ListingGallery();
         $gallery->setListingSID($tmpListingSid);
         $numberOfPictures = $gallery->getPicturesAmount();
         if ($numberOfPictures != 0) {
             $picturesInfo = $gallery->getPicturesInfo();
             $gallery->setListingSID($dstListingSid);
             $gallery->deleteImages();
             foreach ($picturesInfo as $pictureInfo) {
                 $gallery->uploadImage($pictureInfo['picture_url'], $pictureInfo['caption']);
             }
         }
     }
     SJB_Session::unsetValue('tmp_file_storage');
     SJB_ListingDBManager::setListingExpirationDateBySid($dstListingSid);
 }
예제 #6
0
 /**
  * @param $listingSID
  * @param $contractID
  * @param $productSID
  */
 public function addListing($listingSID, $contractID = false, $productSID = false)
 {
     if ($productSID != false) {
         $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         $extraInfo['product_sid'] = (string) $extraInfo['product_sid'];
     } else {
         $contract = new SJB_Contract(array('contract_id' => $contractID));
         $extraInfo = $contract->extra_info;
     }
     $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
     $this->tp->assign("pic_limit", $numberOfPictures);
     $listingTypesInfo = SJB_ListingTypeManager::getAllListingTypesInfo();
     if (!$this->listingTypeID && count($listingTypesInfo) == 1) {
         $listingTypeInfo = array_pop($listingTypesInfo);
         $this->listingTypeID = $listingTypeInfo['id'];
     }
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID);
     $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
     $pageSID = $this->getPageSID($pages, $listingTypeSID);
     $isPageLast = SJB_PostingPagesManager::isLastPageByID($pageSID, $listingTypeSID);
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (($contractID || !empty($this->buttonPressedPostToProceed)) && $this->listingTypeID) {
         $formSubmitted = isset($_REQUEST['action_add']) || isset($_REQUEST['action_add_pictures']) || $isPreviewListingRequested;
         /*
          * social plugin
          * complete listing of data from an array of social data
          * if is allowed
          */
         $aAutoFillData = array('formSubmitted' => &$formSubmitted, 'listingTypeID' => &$this->listingTypeID);
         SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
         /*
          * end of "social plugin"
          */
         $listing = new SJB_Listing($_REQUEST, $listingTypeSID, $pageSID);
         $listing->deleteProperty('featured');
         $listing->deleteProperty('priority');
         $listing->deleteProperty('status');
         $listing->deleteProperty('reject_reason');
         $listing->deleteProperty('ListingLogo');
         $access_type = $listing->getProperty('access_type');
         if ($formSubmitted) {
             if (!empty($access_type)) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
             }
             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contractID, 'is_system' => true));
         }
         $currentUser = SJB_UserManager::getCurrentUser();
         $screeningQuestionnaires = SJB_ScreeningQuestionnaires::getList($currentUser->getSID());
         if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screeningQuestionnaires) {
             $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
             if ($issetQuestionnairyField) {
                 $value = SJB_Request::getVar("screening_questionnaire");
                 $listingInfo = $_REQUEST;
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($currentUser->getSID()), 'is_system' => true));
             }
         } else {
             $listing->deleteProperty('screening_questionnaire');
         }
         /*
          * social plugin
          * "synchronization"
          * if user is not registered using linkedin , delete linkedin sync property
          * also if sync is turned off in admin part
          */
         $aAutoFillData = array('oListing' => &$listing, 'userSID' => $currentUser->getSID(), 'listingTypeID' => $this->listingTypeID, 'listing_info' => $_REQUEST);
         SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
         /*
          * end of social plugin "sync"
          */
         $listingFormAdd = new SJB_Form($listing);
         $listingFormAdd->registerTags($this->tp);
         $fieldErrors = array();
         if ($formSubmitted && ($this->formSubmittedFromPreview || $listingFormAdd->isDataValid($fieldErrors))) {
             if ($isPageLast) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
             }
             $listing->setUserSID($currentUser->getSID());
             $listing->setProductInfo($extraInfo);
             if (empty($access_type->value)) {
                 $listing->setPropertyValue('access_type', 'everyone');
             }
             if ($currentUser->isSubuser()) {
                 $subuserInfo = $currentUser->getSubuserInfo();
                 $listing->addSubuserProperty($subuserInfo['sid']);
             }
             /**
              * >>>>> listing preview @author still
              */
             if (!empty($listingSID)) {
                 $listing->setSID($listingSID);
             }
             /*
              * <<<<< listing preview
              */
             SJB_ListingManager::saveListing($listing);
             if (!empty($this->buttonPressedPostToProceed)) {
                 SJB_ListingManager::unmakeCheckoutedBySID($listing->getSID());
             }
             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
                 $contract->incrementPostingsNumber();
                 SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
             }
             if (SJB_Session::getValue('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');
             }
             // >>> SJB-1197
             // check temporary uploaded storage for listing uploads and assign it to saved listing
             $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);
                 $keywords = $listing->getKeywords();
                 SJB_ListingManager::updateKeywords($keywords, $listing->getSID());
             }
             // <<< SJB-1197
             if ($isPageLast && !$isPreviewListingRequested) {
                 /* delete temp preview listing sid */
                 SJB_Session::unsetValue('preview_listing_sid_for_add');
                 // Start Event
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($extraInfo['featured']) {
                     SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                 }
                 if ($extraInfo['priority']) {
                     SJB_ListingManager::makePriorityBySID($listing->getSID());
                 }
                 if (!empty($this->buttonPressedPostToProceed)) {
                     $this->proceedToCheckout($currentUser->getSID(), $productSID);
                 } else {
                     if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                         SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                     }
                     // notify administrator
                     SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                     if (isset($_REQUEST['action_add_pictures'])) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-pictures/?listing_id=" . $listing->getSID());
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($this->listingTypeID) . '/?listing_id=' . $listing->getSID());
                     }
                 }
             } elseif ($isPageLast && $isPreviewListingRequested) {
                 // for listing preview
                 SJB_Session::setValue('preview_listing_sid_for_add', $listing->getSID());
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($this->listingTypeID) . '-preview/' . $listing->getSID() . '/');
             } else {
                 // listing steps (pages)
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/add-listing/{$this->listingTypeID}/" . SJB_PostingPagesManager::getNextPage($pageSID) . "/" . $listing->getSID());
             }
         } else {
             $listing->deleteProperty('access_list');
             $listing->deleteProperty('contract_id');
             $listingFormAdd = new SJB_Form($listing);
             if ($formSubmitted) {
                 $listingFormAdd->isDataValid($fieldErrors);
             }
             $listingFormAdd->registerTags($this->tp);
             $template = isset($_REQUEST['input_template']) ? $_REQUEST['input_template'] : "input_form.tpl";
             $formFields = $listingFormAdd->getFormFieldsInfo();
             $employersList = SJB_Request::getVar('list_emp_ids', false);
             $employers = array();
             if (is_array($employersList)) {
                 foreach ($employersList as $emp) {
                     $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                     $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                 }
                 sort($employers);
             }
             $this->tp->assign('form_token', SJB_Request::getVar('form_token'));
             $this->tp->assign("account_activated", SJB_Request::getVar('account_activated', ''));
             $this->tp->assign("contract_id", $contractID);
             $this->tp->assign("listing_access_list", $employers);
             $this->tp->assign("listingTypeID", $this->listingTypeID);
             $this->tp->assign('listingTypeStructure', SJB_ListingTypeManager::createTemplateStructure(SJB_ListingTypeManager::getListingTypeInfoBySID($listing->listing_type_sid)));
             $this->tp->assign("field_errors", $fieldErrors);
             $this->tp->assign("form_fields", $formFields);
             $this->tp->assign("pages", $pages);
             $this->tp->assign("pageSID", $pageSID);
             $this->tp->assign("extraInfo", $extraInfo);
             $this->tp->assign("currentPage", SJB_PostingPagesManager::getPageInfoBySID($pageSID));
             $this->tp->assign("isPageLast", $isPageLast);
             $this->tp->assign("nextPage", SJB_PostingPagesManager::getNextPage($pageSID));
             $this->tp->assign("prevPage", SJB_PostingPagesManager::getPrevPage($pageSID));
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $this->tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             /*
              * social plugin
              * only for Resume listing types
              */
             $aAutoFillData = array('tp' => &$this->tp, 'listingTypeID' => &$this->listingTypeID, 'userSID' => $currentUser->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
             /*
              * social plugin
              */
             $this->tp->display($template);
         }
     }
 }
예제 #7
0
 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');
     }
 }
예제 #8
0
 public function execute()
 {
     $formToken = SJB_Request::getVar('form_token');
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('form_token', $formToken);
     $post_max_size_orig = ini_get('post_max_size');
     $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
     // get post_max_size in bytes
     $val = trim($post_max_size_orig);
     $tmp = substr($val, strlen($val) - 1);
     $tmp = strtolower($tmp);
     switch ($tmp) {
         case 'g':
             $val *= 1024;
             break;
         case 'm':
             $val *= 1024;
             break;
         case 'k':
             $val *= 1024;
             break;
     }
     $post_max_size = $val;
     $errors = array();
     if (SJB_Request::getVar('from-preview', false, 'POST') && !SJB_Request::getVar('action_add', false, 'POST')) {
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $previewListingId = SJB_Session::getValue('preview_listing_sid');
         if ($previewListingId && SJB_ListingManager::isListingExists($previewListingId)) {
             $listingId = $previewListingId;
         }
     } else {
         $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int');
     }
     $template = SJB_Request::getVar('edit_template', 'edit_listing.tpl');
     $filename = SJB_Request::getVar('filename', false);
     if ($filename) {
         SJB_UploadFileManager::openFile($filename, $listingId);
         // if file not found - set error here
         $errors['NO_SUCH_FILE'] = true;
     }
     if (empty($_POST) && $server_content_length > $post_max_size) {
         $errors['MAX_FILE_SIZE_EXCEEDED'] = 1;
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $tp->assign('post_max_size', $post_max_size_orig);
     }
     $current_user = SJB_UserManager::getCurrentUser();
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
     // for listing preview
     $formSubmittedFromPreview = false;
     if (empty($listingInfo)) {
         $listingId = SJB_Session::getValue('preview_listing_sid');
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
         if (!empty($listingInfo)) {
             // if on preview page 'POST' button was pressed
             $formSubmittedFromPreview = SJB_Request::getVar('action_add', false, 'POST') && SJB_Request::getVar('from-preview', false, 'POST');
             if ($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;
                     }
                 }
             }
         } else {
             $listingId = null;
             SJB_Session::unsetValue('preview_listing_sid');
         }
     }
     // if preview button was pressed
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (SJB_UserManager::isUserLoggedIn()) {
         if ($listingInfo['user_sid'] != $current_user->getID()) {
             $errors['NOT_OWNER_OF_LISTING'] = $listingId;
         } elseif (!is_null($listingInfo)) {
             $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingInfo['listing_type_sid']);
             $form_is_submitted = SJB_Request::getVar('action', '') == 'save_info' || SJB_Request::getVar('action', '') == 'add' || $isPreviewListingRequested || $formSubmittedFromPreview;
             if (!$form_is_submitted && !SJB_Request::getVar('from-preview', false, 'POST')) {
                 SJB_Session::unsetValue('previewListingId');
                 SJB_Session::unsetValue('preview_listing_sid_or');
             }
             // fill listing from an array of social data if allowed
             $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listingInfo['listing_type_sid']);
             $listingTypeID = $listing_type_info['id'];
             $aAutoFillData = array('formSubmitted' => $form_is_submitted, 'listingTypeID' => $listingTypeID);
             SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
             $listingInfo = array_merge($listingInfo, $_REQUEST);
             $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
             $listing->deleteProperty('ListingLogo');
             $listing->deleteProperty('featured');
             $listing->deleteProperty('priority');
             $listing->deleteProperty('reject_reason');
             $listing->deleteProperty('status');
             $list_emp_ids = SJB_Request::getVar('list_emp_ids');
             $listing->setSID($listingId);
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID());
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $value = SJB_Request::getVar('screening_questionnaire');
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true));
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             //--->CLT-2637
             $properties = $listing->getProperties();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page = array_merge(SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']), $listing_fields_by_page);
             }
             foreach ($properties as $property) {
                 if (!in_array($property->getID(), array_keys($listing_fields_by_page))) {
                     $listing->deleteProperty($property->getID());
                 }
             }
             //--->CLT-2637
             // if user is not registered using linkedin , delete linkedin sync property, also if sync is turned off in admin part
             $aAutoFillData = array('oListing' => &$listing, 'userSID' => $current_user->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo);
             SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
             $listing_edit_form = new SJB_Form($listing);
             $listing_edit_form->registerTags($tp);
             $extraInfo = $listingInfo['product_info'];
             if ($extraInfo) {
                 $extraInfo = unserialize($extraInfo);
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $listingSidForPictures = SJB_Session::getValue('preview_listing_sid_or') ? SJB_Session::getValue('preview_listing_sid_or') : $listingId;
                 $tp->assign('pic_limit', $numberOfPictures);
                 $tp->assign('listingSidForPictures', $listingSidForPictures);
             }
             if ($form_is_submitted) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
             }
             $field_errors = array();
             if ($form_is_submitted && ($formSubmittedFromPreview || $listing_edit_form->isDataValid($field_errors))) {
                 $or_listing_id = SJB_Session::getValue('preview_listing_sid_or');
                 /* preview listing */
                 if ($isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') != $listing->getSID()) {
                     SJB_Session::setValue('preview_listing_sid_or', $listing->getSID());
                     $listing->setSID(null);
                 } elseif (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listing->getSID() && $or_listing_id && $or_listing_id != $listingId) {
                     $listing->setSID($or_listing_id);
                 }
                 if ($isPreviewListingRequested) {
                     $listing->addProperty(array('id' => 'preview', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 } else {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 }
                 if ($isPreviewListingRequested) {
                     $listing->product_info = $extraInfo;
                     if (SJB_Session::getValue('previewListingId')) {
                         $listing->setSID(SJB_Session::getValue('previewListingId'));
                     }
                 } else {
                     SJB_BrowseDBManager::deleteListings($listing->getID());
                 }
                 $listingSidsForCopy = array('filesFrom' => $listingId, 'picturesFrom' => $isPreviewListingRequested && (!$or_listing_id || $or_listing_id === $listingId) ? $listingId : null);
                 SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                 if (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listingId && $or_listing_id && $or_listing_id != $listingId) {
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_ListingManager::deleteListingBySID($listingId);
                 }
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listing->getSID());
                 if ($listingInfo['active']) {
                     SJB_ListingManager::activateListingKeywordsBySID($listing->getSID());
                     SJB_BrowseDBManager::addListings($listing->getID());
                 }
                 // >>> SJB-1197
                 // SET VALUES FROM TEMPORARY SESSION STORAGE
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken);
                 if (is_array($tempFieldsData)) {
                     foreach ($tempFieldsData as $fieldId => $fieldData) {
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldData['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);
                         }
                     }
                     SJB_ListingManager::saveListing($listing);
                     // recreate form object for saved listing
                     // it fix display of complex file fields
                     $listing = SJB_ListingManager::getObjectBySID($listing->getSID());
                     $listing->deleteProperty('featured');
                     $listing->deleteProperty('priority');
                     $listing->deleteProperty('reject_reason');
                     $listing->deleteProperty('status');
                     $listing_edit_form = new SJB_Form($listing);
                     $listing_edit_form->registerTags($tp);
                 }
                 // <<< SJB-1197
                 if ($isPreviewListingRequested) {
                     SJB_Session::setValue('previewListingId', $listing->getSID());
                 }
                 /* preview listing */
                 if ($isPreviewListingRequested) {
                     $listing->setUserSID($current_user->getSID());
                     SJB_Session::setValue('preview_listing_sid', $listing->getSID());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/');
                 } else {
                     /* normal */
                     $listingSid = $listing->getSID();
                     SJB_Event::dispatch('listingEdited', $listingSid);
                     $tp->assign('display_preview', 1);
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-' . strtolower($listingTypeID) . '-details/' . $listing->getSID() . '/');
                 }
             }
             $listing->deleteProperty('access_list');
             $tp->assign('form_is_submitted', $form_is_submitted);
             $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $form_fields = $listing_edit_form->getFormFieldsInfo();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                 foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) {
                     if (!$listing->propertyIsSet($field)) {
                         unset($listing_fields_by_page[$page['page_name']][$field]);
                     }
                 }
             }
             // delete sync fields from posting pages that are not in array $form_fields
             $aAutoFillData = array('listing_fields_by_page' => &$listing_fields_by_page, 'pages' => &$pages, 'form_fields' => $form_fields);
             SJB_Event::dispatch('SocialSynchronizationFieldsOnPostingPages', $aAutoFillData);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             if (!isset($listing_structure['access_type'])) {
                 $listing_structure['access_type'] = 'everyone';
             }
             $listing_access_list = SJB_ListingManager::getListingAccessList($listingId, $listing->getPropertyValue('access_type'));
             $tp->assign('contract_id', $listingInfo['contract_id']);
             $tp->assign('extraInfo', $extraInfo);
             $tp->assign('listing', $listing_structure);
             $tp->assign('pages', $listing_fields_by_page);
             $tp->assign('countPages', count($listing_fields_by_page));
             $tp->assign('field_errors', $field_errors);
             $tp->assign('listing_access_list', $listing_access_list);
             $tp->assign('listingTypeID', $listingTypeID);
             $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
             // only for Resume listing types
             $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $current_user->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
         }
     } else {
         $errors['NOT_LOGGED_IN'] = 1;
     }
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
예제 #9
0
 public static function logout()
 {
     SJB_Session::unsetValue('sn');
     if (self::$oProfile) {
         SJB_HelperFunctions::redirect(self::getFacebookLogoutUrl());
         exit;
     }
 }
예제 #10
0
파일: backup.php 프로젝트: Maxlander/shixi
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $dir_separator = DIRECTORY_SEPARATOR;
     $script_path = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__);
     $script_path = array_shift($script_path);
     $identifier = SJB_Request::getVar('identifier', time());
     $filename = SJB_Request::getVar('filename', false);
     $settings = array();
     if ($filename) {
         SJB_Backup::sendArchiveFile($filename, $script_path . 'backup' . $dir_separator . $filename);
     }
     if (SJB_Request::getVar('action') == "save") {
         $expPeriod = SJB_Request::getVar('backup_expired_period');
         if (!empty($expPeriod) && (!is_numeric($expPeriod) || $expPeriod < 0)) {
             $errors[] = 'EXP_PERIOD_NOT_VALID';
         }
         $ftpValid = $this->isFTPDataValid();
         if (SJB_Request::getVar('autobackup', false) && SJB_Request::getVar('ftp_backup', false) && !$ftpValid) {
             $errors[] = 'FTP_DETAILS_NOT_VALID';
         }
         if (empty($errors)) {
             $backupSettings = $_REQUEST;
             foreach ($backupSettings as $setting => $value) {
                 if (!SJB_Settings::saveSetting($setting, $value)) {
                     $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = "SETTINGS_SAVED_WITH_PROBLEMS";
                 }
             }
             if (empty($errors)) {
                 $tp->assign('successSaveMessage', true);
             }
         } else {
             $settings = $_REQUEST;
         }
     }
     switch ($action) {
         case 'backup':
             if (SJB_System::getSystemSettings('isDemo')) {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             if (SJB_System::getIfTrialModeIsOn() && $_SERVER['REMOTE_ADDR'] != "91.205.51.231") {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             SessionStorage::destroy('backup_' . $identifier);
             SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $backup_type = SJB_Request::getVar('backup_type');
             $backupDir = $script_path . 'backup' . $dir_separator;
             try {
                 $this->prepareBackupDir($backupDir);
             } catch (Exception $e) {
                 SJB_Session::setValue('error', $e->getMessage());
                 exit;
             }
             switch ($backup_type) {
                 case 'full':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $name = 'db.sql';
                     SJB_Backup::dump($name, $script_path, $identifier);
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore', $name);
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'full_backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive($name, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'full')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'database':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $name = 'db.sql';
                     $backupName = 'mysqldump_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '../backup' . $dir_separator;
                     SJB_Backup::dump($name, $script_path, $identifier);
                     if (SJB_Backup::archive(false, $name, $script_path, $export_files_dir_name, $backupName, false, $identifier, 'database')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'files':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore');
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive(false, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'files')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
             }
             break;
         case 'restore':
             if (SJB_System::getSystemSettings('isDemo')) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 exit;
             }
             if (SJB_System::getIfTrialModeIsOn()) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 exit;
             }
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $error = false;
             $restoreDir = $script_path . 'restore' . $dir_separator;
             try {
                 $fileName = $this->moveUploadedFile($restoreDir);
                 $tar = new Archive_Tar($restoreDir . $fileName, 'gz');
                 $tar->_error_class = 'SJB_PEAR_Exception';
                 $tar->extractList('db.sql', $restoreDir);
                 $tar->extract($script_path);
                 if (is_file($restoreDir . 'db.sql')) {
                     SJB_Backup::restore_base_tables($restoreDir . 'db.sql');
                 }
                 SJB_Cache::getInstance()->clean();
             } catch (Exception $ex) {
                 $error = $ex->getMessage();
             }
             SJB_Filesystem::delete($restoreDir);
             if (is_file($script_path . 'install.php')) {
                 SJB_Filesystem::delete($script_path . 'install.php');
             }
             if ($error) {
                 SJB_Session::setValue('error', $error);
             } else {
                 SJB_Session::setValue('restore', 1);
             }
             exit;
             break;
         case 'send_archive':
             $name = SJB_Request::getVar('name', false);
             $archive_file_path = SJB_Path::combine(SJB_BASE_DIR . 'backup' . $dir_separator, $name);
             if ($name) {
                 SJB_Backup::sendArchiveFile($name, $archive_file_path);
             }
             break;
         case 'check':
             $sessionBackup = SessionStorage::read('backup_' . $identifier);
             $sessionBackup = $sessionBackup ? unserialize($sessionBackup) : array();
             $sessionRestore = SJB_Session::getValue('restore');
             $sessionError = SJB_Session::getValue('error');
             if (!empty($sessionBackup['name'])) {
                 $name = $sessionBackup['name'];
                 SessionStorage::destroy('backup_' . $identifier);
                 echo SJB_System::getSystemSettings('SITE_URL') . "/backup/?action=send_archive&name={$name}";
                 exit;
             } elseif (!empty($sessionRestore)) {
                 SJB_Session::unsetValue('restore');
                 echo SJB_System::getSystemSettings('SITE_URL') . '/backup/#restore';
                 exit;
             } elseif (!empty($sessionError)) {
                 echo 'Error';
                 if (SJB_System::getSystemSettings('isDemo')) {
                     echo ': You don\'t have permissions for it. This is a Demo version of the software.';
                 }
                 if (SJB_System::getIfTrialModeIsOn()) {
                     echo ': You don\'t have permissions for it. This is a Trial version of the software.';
                 }
                 exit;
             } elseif (!empty($sessionBackup['last_time'])) {
                 $period = (time() - $sessionBackup['last_time']) / 60;
                 if ($period < 5) {
                     echo 1;
                 } else {
                     SJB_Session::setValue('error', 'The backup generation process was unexpectedly interrupted. Please try again.');
                     echo 'error';
                 }
                 exit;
             } else {
                 echo 1;
             }
             exit;
             break;
         case 'delete_backup':
             $name = SJB_Request::getVar('name', false);
             if ($name) {
                 $backup = $script_path . 'backup' . $dir_separator . $name;
                 if (is_file($backup)) {
                     SJB_Filesystem::delete($backup);
                     SJB_Autobackup::deleteFileFromFtp($name);
                 } else {
                     $errors['FILE_NOT_FOUND'] = 1;
                 }
             }
             $tp->assign('errors', $errors);
             $tp->assign('delBackup', 1);
         case 'created_backups':
             $path = $script_path . 'backup' . $dir_separator;
             if (is_dir($path)) {
                 $di = new DirectoryIterator($path);
                 $backupsArr = array();
                 foreach ($di as $file) {
                     $fileName = $file->getFilename();
                     if (!$file->isDir() && !$file->isLink() && $fileName != '.htaccess') {
                         $cTime = $file->getCTime();
                         $backupsArr[$cTime]['name'] = $fileName;
                         if (preg_match('/mysqldump/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site database only';
                         } elseif (preg_match('/full_backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Full site backup';
                         } elseif (preg_match('/backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site files only';
                         } else {
                             $backupsArr[$cTime]['type'] = 'Unknown';
                         }
                         $pattern = '/(\\w+)_(\\d+)_(\\d+)_(\\d+)__(\\d+)_(\\d+).tar.gz/i';
                         $replacement = '$2-$3-$4 $5:$6';
                         $backupsArr[$cTime]['date'] = preg_replace($pattern, $replacement, $fileName);
                     }
                 }
                 krsort($backupsArr);
                 $tp->assign('created_backups', $backupsArr);
             }
             $tp->display('created_backups.tpl');
             exit;
             break;
         case 'error':
             $sessionError = SJB_Session::getValue('error');
             if (!is_null($sessionError)) {
                 echo '<p class="error">' . $sessionError . '</p>';
                 exit;
             }
             break;
     }
     if (empty($settings)) {
         $settings = SJB_Settings::getSettings();
     }
     $tp->assign('errors', $errors);
     $tp->assign('settings', $settings);
     $tp->assign('identifier', $identifier);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('backup.tpl');
 }
예제 #11
0
 public static function logout()
 {
     if (self::$object && self::$oProfile) {
         // если нужно отозвать token, использовать эту ф-цию
         //			$this->revokeToken();
         // у нас такой цели нет, поэтому просто чистим тоукен
         self::$object->setAccessToken(null);
         SJB_Session::unsetValue('sn');
         SJB_Session::unsetValue(self::NETWORK_ID);
         SJB_Session::unsetValue('oauth');
     }
 }
예제 #12
0
 public static function logout()
 {
     if (isset($_COOKIE['session_key'])) {
         $session_key = $_COOKIE['session_key'];
         SJB_UserManager::removeUserSessionKey($session_key);
         SJB_Authorization::setKeepCookieForUser($session_key, false);
     }
     SJB_Session::unsetValue('userLoginCounter');
     SJB_Session::setValue('current_user', null);
     SJB_Event::dispatch('Logout');
 }
예제 #13
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $networkFeeds = array();
     $template = 'social_media.tpl';
     $formSubmitted = SJB_Request::getVar('submit');
     $action = SJB_Request::getVar('action');
     $subAction = SJB_Request::getVar('sub_action');
     $sid = SJB_Request::getVar('sid');
     $groups = array();
     $accountInfo = null;
     $messages = array();
     $savedSettings = array();
     if (SJB_Request::getVar('error', false)) {
         $errors[] = SJB_Request::getVar('error', false);
     }
     if (SJB_Request::getVar('message', false)) {
         $messages[] = SJB_Request::getVar('message', false);
     }
     $socNetworks = array('facebook' => array('name' => 'Facebook'), 'linkedin' => array('name' => 'Linkedin'), 'twitter' => array('name' => 'Twitter'), 'googleplus' => array('name' => 'Google+'), 'bitly' => array('name' => 'Bitly'));
     $network = SJB_Request::getVar('passed_parameters_via_uri');
     if (empty($network)) {
         $network = SJB_Request::getVar('soc_network');
     }
     switch ($network) {
         case 'facebook':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_FacebookSocial';
             break;
         case 'linkedin':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_LinkedInSocial';
             break;
         case 'twitter':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_TwitterSocial';
             break;
         case 'googleplus':
             $template = 'social_media_settings.tpl';
             $objectName = 'SJB_GooglePlusSocial';
             break;
         default:
             $network = '';
             $action = '';
             $objectName = '';
             break;
     }
     switch ($action) {
         case 'add_feed':
             SJB_Session::unsetValue($network);
             SJB_Session::unsetValue($network . 'Feed');
             $template = 'feed_input_form.tpl';
             $accountID = SJB_Request::getVar('account_id', false);
             $isAuthorized = SJB_Request::getVar('authorized', false);
             if ($accountID) {
                 $tp->assign('accountID', $accountID);
             }
             $feed = new $objectName();
             $addForm = new SJB_Form($feed);
             $addForm->registerTags($tp);
             $searchFormBuilder = new SJB_SearchFormBuilder($feed);
             $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
             $searchFormBuilder->setCriteria($criteria);
             $searchFormBuilder->registerTags($tp);
             $systemFields = $feed->details->systemFields;
             $postingFields = $feed->details->postingFields;
             $listingFields = $feed->details->commonFields;
             $tp->assign('authorized', $isAuthorized);
             $tp->assign('listingFields', $listingFields);
             $tp->assign('postingFields', $postingFields);
             $tp->assign('systemFields', $systemFields);
             $tp->assign('action', $action);
             break;
         case 'save_feed':
             $template = 'feed_input_form.tpl';
             $fieldErrors = array();
             $mediaObject = $objectName . 'Media';
             $networkSocialMedia = new $mediaObject();
             $isAuthorized = SJB_Request::getVar('authorized', false);
             $actionFeed = SJB_Request::getVar('action_feed');
             if ($actionFeed != 'add_feed' && $network != 'twitter') {
                 try {
                     $accountInfo = $networkSocialMedia->getAccountInfo($sid);
                 } catch (Exception $e) {
                     $isAuthorized = false;
                     $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
                 }
             }
             $isGroupsExist = !empty($accountInfo['groups']);
             if (SJB_Request::getVar('process_token', false)) {
                 $_REQUEST = unserialize(SJB_Session::getValue($network . 'Feed'));
                 $_REQUEST['process_token'] = 1;
             }
             $feed = new $objectName($_REQUEST, $isGroupsExist, $isAuthorized);
             if ($isGroupsExist) {
                 $groups = $accountInfo['groups'];
             }
             if ($sid) {
                 $feed->setSID($sid);
                 $tp->assign('feed_sid', $sid);
             }
             $criteriaSaver = new SJB_ListingCriteriaSaver();
             $criteriaSaver->setSessionForCriteria($_REQUEST);
             $requestedData = $criteriaSaver->getCriteria();
             $searchFormBuilder = new SJB_SearchFormBuilder($feed);
             $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
             $searchFormBuilder->setCriteria($criteria);
             $searchFormBuilder->registerTags($tp);
             $properties = $feed->getProperties();
             foreach ($properties as $key => $property) {
                 if (!$property->isSystem()) {
                     $feed->deleteProperty($key);
                 }
             }
             $this->checkToken($tp, $networkSocialMedia, $errors, array(), $network, $sid);
             $addForm = new SJB_Form($feed);
             $addForm->registerTags($tp);
             if ($addForm->isDataValid($fieldErrors)) {
                 if ($network == 'twitter') {
                     try {
                         $accessToken = $networkSocialMedia->getAccessToken($sid, $action, $errors);
                     } catch (Exception $e) {
                         $accessToken = false;
                         $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
                     }
                     if (empty($errors) && $accessToken != false) {
                         $feed->addProperty(array('id' => 'access_token', 'type' => 'text', 'value' => serialize($accessToken), 'is_system' => true));
                     }
                 } else {
                     if ($network == 'facebook' && !empty($accountInfo)) {
                         $feed->addProperty(array('id' => 'access_token', 'type' => 'text', 'value' => serialize($accountInfo['access_token']), 'is_system' => true));
                         $feed->addProperty(array('id' => 'account_name', 'type' => 'text', 'value' => serialize($accountInfo['account_name']), 'is_system' => true));
                     }
                 }
                 if (empty($errors)) {
                     unset($requestedData['groups']);
                     $feed->addProperty(array('id' => 'search_data', 'type' => 'text', 'value' => serialize($requestedData), 'is_system' => true));
                     $feed->saveFeed($feed, $action);
                     if ($formSubmitted == 'save') {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network . '#postJobs');
                     }
                     $tp->assign('feed_sid', $feed->getSID());
                 }
             }
             $systemFields = $feed->details->systemFields;
             $postingFields = $feed->details->postingFields;
             $listingFields = $feed->details->commonFields;
             $changeAccountUrl = "action=authorize&sid={$sid}&sub_action=change_account&soc_network={$network}";
             $tp->assign('field_errors', $fieldErrors);
             $tp->assign('change_url', $changeAccountUrl);
             $tp->assign('listingFields', $listingFields);
             $tp->assign('postingFields', $postingFields);
             $tp->assign('systemFields', $systemFields);
             $tp->assign('action', $actionFeed);
             $tp->assign('authorized', $isAuthorized);
             $tp->assign('allGroups', $groups);
             break;
         case 'grant':
             $mediaObject = $objectName . 'Media';
             $networkSocialMedia = new $mediaObject();
             $error = '';
             try {
                 $accountInfo = $networkSocialMedia->getAccountInfo($sid, $subAction);
             } catch (Exception $e) {
                 $tp->assign('authorized', false);
                 $error = $e->getMessage();
             }
             if (empty($error)) {
                 $networkSocialMedia->updateAccessToken($sid, $accountInfo['account_id'], $accountInfo['account_name']);
                 $logoutUrl = SJB_System::getSystemSettings('SITE_URL') . "/social-media/{$network}?message=ACCOUNT_UPDATED#postJobs";
             } else {
                 $logoutUrl = SJB_System::getSystemSettings('SITE_URL') . "/social-media/{$network}?error={$error}#postJobs";
             }
             // After clicking the 'Grant Permission' button and login to Facebook we are redirected to the feeds list.
             SJB_HelperFunctions::redirect($logoutUrl);
             break;
         case 'edit_feed':
             if (!SJB_Request::getVar('oauth_token', false)) {
                 SJB_Session::unsetValue($network);
             }
             if (!SJB_Request::getVar('process_token', false)) {
                 SJB_Session::unsetValue($network . 'Feed');
             }
             if ($sid) {
                 $changeAccountUrl = "action=authorize&sid={$sid}&sub_action=change_account&soc_network={$network}";
                 $feedInfo = $objectName::getFeedInfoByNetworkIdAndSID($network, $sid);
                 $feedInfo = array_merge($feedInfo, $_REQUEST);
                 $criteriaInfo = $feedInfo['search_data'] ? unserialize($feedInfo['search_data']) : '';
                 $mediaObject = $objectName . 'Media';
                 $networkSocialMedia = new $mediaObject();
                 $isAuthorized = true;
                 if ($network != 'twitter') {
                     try {
                         $accountInfo = $networkSocialMedia->getAccountInfo($sid, $subAction);
                     } catch (Exception $e) {
                         $isAuthorized = false;
                         $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
                     }
                 }
                 $isGroupsExist = !empty($accountInfo['groups']);
                 if ($isGroupsExist) {
                     $groups = $accountInfo['groups'];
                 }
                 if ($accountInfo && $subAction == 'changed') {
                     $feedInfo = array_merge($feedInfo, $accountInfo);
                 }
                 $feed = new $objectName($feedInfo, $isGroupsExist, $isAuthorized);
                 $editForm = new SJB_Form($feed);
                 $editForm->registerTags($tp);
                 $searchFormBuilder = new SJB_SearchFormBuilder($feed);
                 $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($criteriaInfo);
                 $searchFormBuilder->setCriteria($criteria);
                 $searchFormBuilder->registerTags($tp);
                 $systemFields = $feed->details->systemFields;
                 $postingFields = $feed->details->postingFields;
                 $listingFields = $feed->details->commonFields;
                 $this->checkToken($tp, $networkSocialMedia, $errors, $feedInfo, $network, $sid);
                 $tp->assign('listingFields', $listingFields);
                 $tp->assign('postingFields', $postingFields);
                 $tp->assign('systemFields', $systemFields);
                 $tp->assign('feed_sid', $sid);
                 $tp->assign('authorized', $isAuthorized);
                 $tp->assign('allGroups', $groups);
                 $tp->assign('action', $action);
                 $tp->assign('change_url', $changeAccountUrl);
                 $template = 'feed_input_form.tpl';
             }
             break;
         case 'authorize':
             if (!SJB_Request::getVar('oauth_token', false)) {
                 SJB_Session::unsetValue($network);
             }
             $mediaObject = $objectName . 'Media';
             $networkSocialMedia = new $mediaObject();
             try {
                 if ($network == 'twitter') {
                     $accessToken = $networkSocialMedia->getAccessToken($sid, $subAction, $errors);
                     $networkSocialMedia->updateFeedToken($sid, $accessToken);
                     if (SJB_Request::getVar('sub_action', null, 'GET') == 'grant') {
                         if (empty($errors)) {
                             $messages[] = 'Account is successfully updated.';
                         }
                         break;
                     }
                 } else {
                     $accountInfo = $networkSocialMedia->getAccountInfo($sid, $subAction);
                 }
             } catch (Exception $e) {
                 $errors[] = SJB_I18N::getInstance()->gettext('Backend', $e->getMessage());
             }
             $changeAccountUrl = "action=authorize&sub_action=change_account&soc_network={$network}";
             $template = 'feed_input_form.tpl';
             $isAuthorized = isset($accountInfo['account_id']);
             $isGroupsExist = !empty($accountInfo['groups']);
             $feed = new $objectName($accountInfo, $isGroupsExist, $isAuthorized);
             if ($isGroupsExist) {
                 $groups = $accountInfo['groups'];
             }
             $addForm = new SJB_Form($feed);
             $addForm->registerTags($tp);
             $searchFormBuilder = new SJB_SearchFormBuilder($feed);
             $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
             $searchFormBuilder->setCriteria($criteria);
             $searchFormBuilder->registerTags($tp);
             $systemFields = $feed->details->systemFields;
             $postingFields = $feed->details->postingFields;
             $listingFields = $feed->details->commonFields;
             $tp->assign('listingFields', $listingFields);
             $tp->assign('postingFields', $postingFields);
             $tp->assign('systemFields', $systemFields);
             $tp->assign('action', $action);
             $tp->assign('authorized', $isAuthorized);
             $tp->assign('change_url', $changeAccountUrl);
             $tp->assign('allGroups', $groups);
             break;
         case 'delete_feed':
             $sid = SJB_Request::getVar('sid');
             if ($sid) {
                 $feed = new $objectName();
                 $feed->deleteFeed($sid);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network . '#postJobs');
             }
             break;
         case 'status':
             $sid = SJB_Request::getVar('sid');
             $active = SJB_Request::getVar('active');
             $feedInfo = $objectName::getFeedInfoByNetworkIdAndSID($network, $sid);
             if ($feedInfo != null && ($active == '1' || $active == '0')) {
                 $objectName::updateFeedStatus($network . '_feeds', $active, $sid);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network . '#postJobs');
             } else {
                 $errors[] = 'Feed does not exist';
             }
             break;
         case 'save_settings':
             $request = $_REQUEST;
             $error = $this->checkFields($request, $objectName);
             if (!$error) {
                 SJB_Settings::updateSettings($request);
                 if ($formSubmitted == 'save') {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/');
                 } else {
                     if ($formSubmitted == 'apply') {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/social-media/' . $network);
                     }
                 }
             }
             $savedSettings = $request;
             break;
     }
     if ($network) {
         if (empty($savedSettings)) {
             $savedSettings = SJB_Settings::getSettings();
         }
         SJB_Event::dispatch('RedefineSavedSetting', $savedSettings, true);
         if ($network != 'googleplus' && $action != 'edit_feed' && $action != 'add_feed' && $action != 'save_feed') {
             $networkFeeds = SJB_SocialMedia::getFeedsInfoByNetworkID($network);
             $currentDate = date('Y-m-d', time());
             foreach ($networkFeeds as $key => $feed) {
                 if (SJB_SocialMedia::isFeedExpired($feed, $currentDate)) {
                     $networkFeeds[$key]['expired'] = true;
                 }
             }
         }
         $tp->assign('network', $network);
         $tp->assign('savedSettings', $savedSettings);
         $tp->assign('networkFeeds', $networkFeeds);
         $tp->assign('networkName', $socNetworks[$network]['name']);
         if ($network != 'twitter') {
             $networkObject = new $objectName();
             $settings = $networkObject->getConnectSettings();
             $tp->assign('settings', $settings);
         }
     } else {
         $tp->assign('socNetworks', $socNetworks);
     }
     $tp->assign('networkFeeds', $networkFeeds);
     $tp->assign('socNetworks', $socNetworks);
     $tp->assign('errors', $errors);
     $tp->assign('messages', $messages);
     $tp->display($template);
 }
예제 #14
0
 protected static function cleanCurrrentSessionData($network)
 {
     $sessionSN = SJB_Session::getValue('sn');
     if (!empty($sessionSN['authorized']) && $sessionSN['network'] == $network) {
         SJB_Session::unsetValue('sn');
     }
 }
예제 #15
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;
 }
예제 #16
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('input_template', 'input_form.tpl');
     $error = null;
     $listingTypeID = SJB_Request::getVar('listing_type_id', false);
     $passed_parameters_via_uri = SJB_Request::getVar('passed_parameters_via_uri', false);
     $pageID = false;
     if ($passed_parameters_via_uri) {
         $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
         $listingTypeID = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : $listingTypeID;
         $pageID = isset($passed_parameters_via_uri[1]) ? $passed_parameters_via_uri[1] : false;
         $listing_id = isset($passed_parameters_via_uri[2]) ? $passed_parameters_via_uri[2] : false;
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         $post_max_size_orig = ini_get('post_max_size');
         $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
         $fromPreview = SJB_Request::getVar('from-preview', false);
         // 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) {
             $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;
             $tp->assign('post_max_size', $post_max_size_orig);
         }
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
         $currentUser = SJB_UserManager::getCurrentUser();
         $contractID = $listingInfo['contract_id'];
         if ($contractID == 0) {
             $extraInfo = unserialize($listingInfo['product_info']);
             $productSID = $extraInfo['product_sid'];
         } else {
             $contract = new SJB_Contract(array('contract_id' => $contractID));
             $extraInfo = $contract->extra_info;
         }
         if ($listingInfo['user_sid'] != SJB_UserManager::getCurrentUserSID()) {
             $errors['NOT_OWNER_OF_LISTING'] = $listing_id;
         } else {
             $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_type_sid);
             if (!$pageID) {
                 $pageID = $pages[0]['page_id'];
             }
             $pageSID = SJB_PostingPagesManager::getPostingPageSIDByID($pageID, $listing_type_sid);
             $isPageLast = SJB_PostingPagesManager::isLastPageByID($pageSID, $listing_type_sid);
             // preview listing
             $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
             $form_submitted = isset($_REQUEST['action_add']) || isset($_REQUEST['action_add_pictures']) || $isPreviewListingRequested;
             // fill listing from an array of social data if allowed
             $aAutoFillData = array('formSubmitted' => &$form_submitted, 'listingTypeID' => &$listingTypeID);
             SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
             $listingInfo = array_merge($listingInfo, $_REQUEST);
             $listing = new SJB_Listing($listingInfo, $listing_type_sid, $pageSID);
             if ($fromPreview) {
                 if ($form_submitted) {
                     $properties = $listing->getProperties();
                     foreach ($properties as $fieldID => $property) {
                         switch ($property->getType()) {
                             case 'date':
                                 if (!empty($listing_info[$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;
                         }
                     }
                     $listing = new SJB_Listing($listingInfo, $listing_type_sid, $pageSID);
                 }
             }
             $previousComplexFields = $this->processComplexFields($listing, $listingInfo);
             $listing->deleteProperty('featured');
             $listing->deleteProperty('priority');
             $listing->deleteProperty('status');
             $listing->deleteProperty('reject_reason');
             $listing->deleteProperty('ListingLogo');
             $listing->setSID($listing_id);
             $access_type = $listing->getProperty('access_type');
             if ($form_submitted && !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($currentUser->getSID());
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                 if ($issetQuestionnairyField) {
                     $value = SJB_Request::getVar('screening_questionnaire');
                     $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                     $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($currentUser->getSID()), 'is_system' => true));
                 }
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             /* social plugin
              * "synchronization"
              * if user is not registered using linkedin , delete linkedin sync property
              * also deletes it if sync is turned off in admin part
              */
             if ($pages[0]['page_id'] == $pageID) {
                 $aAutoFillData = array('oListing' => &$listing, 'userSID' => $currentUser->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo);
                 SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
             }
             $add_listing_form = new SJB_Form($listing);
             $add_listing_form->registerTags($tp);
             $field_errors = array();
             if ($form_submitted && (SJB_Session::getValue(self::PREVIEW_LISTING_SID) == $listing_id || $add_listing_form->isDataValid($field_errors))) {
                 /* delete temp preview listing sid */
                 SJB_Session::unsetValue(self::PREVIEW_LISTING_SID);
                 if ($isPageLast) {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 }
                 $listing->setUserSID($currentUser->getSID());
                 if (empty($access_type->value)) {
                     $listing->setPropertyValue('access_type', 'everyone');
                 }
                 if (isset($_SESSION['tmp_file_storage'])) {
                     foreach ($_SESSION['tmp_file_storage'] as $k => $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');
                 }
                 // >>> SJB-1197
                 // check temporary uploaded storage for listing uploads and assign it to saved listing
                 $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-1197
                 SJB_ListingManager::saveListing($listing);
                 foreach ($previousComplexFields as $propertyId) {
                     $listing->deleteProperty($propertyId);
                 }
                 if ($isPageLast && !$isPreviewListingRequested) {
                     $listingSID = $listing->getSID();
                     $listing = SJB_ListingManager::getObjectBySID($listingSID);
                     $listing->setSID($listingSID);
                     $keywords = $listing->getKeywords();
                     SJB_ListingManager::updateKeywords($keywords, $listing->getSID());
                     // Start Event
                     $listingSid = $listing->getSID();
                     SJB_Event::dispatch('listingSaved', $listingSid);
                     // is listing featured by default
                     if ($extraInfo['featured']) {
                         SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                     }
                     if ($extraInfo['priority']) {
                         SJB_ListingManager::makePriorityBySID($listing->getSID());
                     }
                     if ($contractID) {
                         if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                             SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                         }
                         // notify administrator
                         SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                         if (isset($_REQUEST['action_add_pictures'])) {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-pictures/?listing_id=" . $listing->getSID());
                         } else {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingTypeID) . '/?listing_id=' . $listing->getSID());
                         }
                     } else {
                         SJB_ListingManager::unmakeCheckoutedBySID($listing->getSID());
                         $this->proceedToCheckout($currentUser->getSID(), $productSID);
                     }
                 } elseif ($isPageLast && $isPreviewListingRequested) {
                     // for listing preview
                     SJB_Session::setValue(self::PREVIEW_LISTING_SID, $listing->getSID());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/');
                 } else {
                     // listing steps (pages)
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/add-listing/{$listingTypeID}/" . SJB_PostingPagesManager::getNextPage($pageSID) . '/' . $listing->getSID());
                 }
             } else {
                 foreach ($previousComplexFields as $propertyId) {
                     $listing->deleteProperty($propertyId);
                 }
                 $listing->deleteProperty('access_list');
                 $listing->deleteProperty('contract_id');
                 $add_listing_form = new SJB_Form($listing);
                 if (SJB_Request::get('action_add') == 'Next') {
                     $add_listing_form->setUseDefaultValues();
                 }
                 if ($form_submitted) {
                     $add_listing_form->isDataValid($field_errors);
                 }
                 $add_listing_form->registerTags($tp);
                 $form_fields = $add_listing_form->getFormFieldsInfo();
                 $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);
                 } else {
                     $access_type = $listing->getPropertyValue('access_type');
                     $employers = SJB_ListingManager::getListingAccessList($listing_id, $access_type);
                 }
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $tp->assign('pic_limit', $numberOfPictures);
                 $tp->assign('listing_sid', $listing_id);
                 $tp->assign('listing_id', $listing_id);
                 $tp->assign('listingSID', $listing->getSID());
                 $tp->assign('listing_access_list', $employers);
                 $tp->assign('listingTypeID', $listingTypeID);
                 $tp->assign('contract_id', $contractID);
                 $tp->assign('field_errors', $field_errors);
                 $tp->assign('form_fields', $form_fields);
                 $tp->assign("extraInfo", $extraInfo);
                 $tp->assign('pages', $pages);
                 $tp->assign('pageSID', $pageSID);
                 $tp->assign('currentPage', SJB_PostingPagesManager::getPageInfoBySID($pageSID));
                 $tp->assign('isPageLast', $isPageLast);
                 $tp->assign('nextPage', SJB_PostingPagesManager::getNextPage($pageSID));
                 $tp->assign('prevPage', SJB_PostingPagesManager::getPrevPage($pageSID));
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
                 // social plugin  only for Resume listing types
                 $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $currentUser->getSID());
                 SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
                 SJB_Session::unsetValue(self::PREVIEW_LISTING_SID);
                 $tp->display($template);
             }
         }
     } else {
         $tp->assign('listingTypeID', $listingTypeID);
         $tp->assign('error', 'NOT_LOGGED_IN');
         $tp->display('add_listing_error.tpl');
     }
 }
예제 #17
0
 private function setSessionValueForRedirectAfterRegister()
 {
     $refererUri = SJB_Request::getVar('HTTP_REFERER', null, 'SERVER');
     if ($refererUri) {
         $refererUri = parse_url($refererUri);
         if (basename($refererUri['path']) != 'registration') {
             if (basename($refererUri['path']) != 'add-listing') {
                 SJB_Session::unsetValue('proceed_to_posting');
                 SJB_Session::unsetValue('productSID');
                 SJB_Session::unsetValue('listing_type_id');
             }
             if (basename($refererUri['path']) != 'shopping-cart') {
                 SJB_Session::unsetValue('fromShoppingCart');
             } else {
                 if (SJB_Request::getVar('fromShoppingCart', false)) {
                     SJB_Session::setValue('fromAnonymousShoppingCart', true);
                 }
             }
         }
     }
 }
예제 #18
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $currentUser = SJB_UserManager::getCurrentUser();
     $action = SJB_Request::getVar('action', false);
     $error = SJB_Request::getVar('error', false);
     $applyPromoCode = SJB_Request::getVar('applyPromoCode', false);
     $action = $applyPromoCode ? 'applyPromoCode' : $action;
     $numberOfListings = SJB_Request::getVar('number_of_listings');
     $productInfo = null;
     $errors = array();
     switch ($action) {
         case 'delete':
             $itemSID = SJB_Request::getVar('item_sid', 0, false, 'int');
             if (SJB_UserManager::isUserLoggedIn()) {
                 if (SJB_Settings::getSettingByName('allow_to_post_before_checkout') == true) {
                     $this->findCheckoutedListingsByProduct($itemSID, $currentUser->getSID());
                 }
                 SJB_ShoppingCart::deleteItemFromCartBySID($itemSID, $currentUser->getSID());
             } else {
                 $products = SJB_Session::getValue('products');
                 if (!empty($products[$itemSID])) {
                     unset($products[$itemSID]);
                     SJB_Session::setValue('products', $products);
                 }
             }
             break;
         case 'checkout':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $products = SJB_Session::getValue('products');
                 $products = $products ? $products : array();
                 $trialProduct = false;
                 foreach ($products as $product) {
                     if (!empty($product['product_info'])) {
                         $productInfo = unserialize($product['product_info']);
                         if ($currentUser->getUserGroupSID() != $productInfo['user_group_sid']) {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=user_group");
                         } elseif (in_array($productInfo['sid'], $currentUser->getTrialProductSIDByUserSID())) {
                             $trialProduct = true;
                         } else {
                             $product = new SJB_Product($productInfo, $productInfo['product_type']);
                             $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                             $product->setNumberOfListings($number_of_listings);
                             $productInfo['price'] = $product->getPrice();
                             SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUser->getSID());
                         }
                     }
                 }
                 SJB_Session::unsetValue('products');
                 if ($trialProduct) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=trial_product");
                 } elseif ($products) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/");
                 }
                 $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
                 if (empty($products)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-account/");
                 }
                 $isRecurring = false;
                 $subTotal = 0;
                 foreach ($products as $key => $product) {
                     $productInfo = unserialize($product['product_info']);
                     if (!empty($productInfo['recurring'])) {
                         $isRecurring = true;
                     }
                     if (!empty($productInfo['pricing_type']) == 'volume_based' && isset($numberOfListings[$productInfo['sid']][$product['sid']])) {
                         $productInfo['number_of_listings'] = $numberOfListings[$productInfo['sid']][$product['sid']];
                         $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                         $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                         $productObj->setNumberOfListings($number_of_listings);
                         $productInfo['price'] = $productObj->getPrice();
                         if (!empty($productInfo['code_info'])) {
                             SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $productInfo['code_info']);
                         }
                         SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                     }
                     $subTotal += $productInfo['price'];
                     $products[$key] = $productInfo;
                     $products[$key]['item_sid'] = $product['sid'];
                     $products[$key]['product_info'] = serialize($productInfo);
                 }
                 $index = 1;
                 $items = array();
                 $codeInfo = array();
                 if ($isRecurring) {
                     $tp->assign('confirmation', 1);
                     $tp->assign('sub_total_price', $subTotal);
                 } else {
                     foreach ($products as $product) {
                         $product_info = unserialize($product['product_info']);
                         SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product, $product['code_info']);
                         $qty = !empty($product_info['number_of_listings']) ? $product_info['number_of_listings'] : null;
                         $items['products'][$index] = $product_info['sid'];
                         if ($qty > 0) {
                             $items['price'][$index] = round($product['price'] / $qty, 2);
                         } else {
                             $items['price'][$index] = round($product['price'], 2);
                         }
                         $items['amount'][$index] = $product['price'];
                         $items['qty'][$index] = $qty;
                         if (isset($product['custom_item'])) {
                             $items['custom_item'][$index] = $product['custom_item'];
                         } else {
                             $items['custom_item'][$index] = "";
                         }
                         if (isset($product['custom_info'])) {
                             $items['custom_info'][$index] = $product['custom_info'];
                         } else {
                             $items['custom_info'][$index]['shoppingCartRecord'] = $product['item_sid'];
                         }
                         if ($product_info['product_type'] == 'banners' && !empty($product_info['banner_info'])) {
                             $items['custom_info'][$index]['banner_info'] = $product_info['banner_info'];
                         }
                         $index++;
                         SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product_info, $codeInfo);
                     }
                     $subUserInfo = $currentUser->getSubuserInfo();
                     $userSID = isset($subUserInfo['sid']) ? $subUserInfo['sid'] : $currentUser->getSID();
                     $invoiceSID = SJB_InvoiceManager::generateInvoice($items, $userSID, $subTotal, SJB_System::getSystemSettings('SITE_URL') . "/create-contract/");
                     SJB_PromotionsManager::addCodeToHistory($codeInfo, $invoiceSID, $userSID);
                     if ($subTotal <= 0) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/create-contract/?invoice_sid=' . $invoiceSID);
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/payment-page/?invoice_sid=" . $invoiceSID);
                     }
                 }
             }
             break;
         case 'applyPromoCode':
             $promotionCode = SJB_Request::getVar('promotion_code', false);
             if ($promotionCode) {
                 if (SJB_UserManager::isUserLoggedIn()) {
                     $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
                 } else {
                     $products = SJB_Session::getValue('products');
                     $products = $products ? $products : array();
                     krsort($products);
                 }
                 $allowShoppingItems = array();
                 $productSIDs = array();
                 foreach ($products as $product) {
                     $productInfo = unserialize($product['product_info']);
                     if (!isset($productInfo['code_info'])) {
                         if (isset($productInfo['custom_info'])) {
                             $allowShoppingItems[] = $product['sid'];
                             $productSIDs[] = $productInfo['custom_info']['productSid'];
                         } else {
                             $allowShoppingItems[] = $product['sid'];
                             $productSIDs[] = $productInfo['sid'];
                         }
                     } else {
                         $appliedPromoCode = $productInfo['code_info'];
                     }
                 }
                 if ($codeInfo = SJB_PromotionsManager::checkCode($promotionCode, $productSIDs)) {
                     $productSIDs = $codeInfo['product_sid'] ? explode(',', $codeInfo['product_sid']) : false;
                     $appliedProducts = array();
                     $codeValid = false;
                     foreach ($products as $key => $product) {
                         $productInfo = unserialize($product['product_info']);
                         if ($productInfo['sid'] != '-1') {
                             $productSid = $productInfo['sid'];
                         } else {
                             $productSid = $productInfo['custom_info']['productSid'];
                         }
                         if ($productSIDs && in_array($productSid, $productSIDs) && $allowShoppingItems && in_array($product['sid'], $allowShoppingItems)) {
                             $currentUsesCount = SJB_PromotionsManager::getUsesCodeBySID($codeInfo['sid']);
                             if ($codeInfo['maximum_uses'] != 0 && $codeInfo['maximum_uses'] > $currentUsesCount || $codeInfo['maximum_uses'] == 0) {
                                 $codeValid = true;
                                 SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $codeInfo);
                                 $appliedProducts[] = $productInfo;
                                 if (SJB_UserManager::isUserLoggedIn()) {
                                     SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                                 } else {
                                     $products[$key]['product_info'] = serialize($productInfo);
                                     SJB_Session::setValue('products', $products);
                                 }
                             }
                         }
                     }
                     if (!$codeValid) {
                         $errors['NOT_VALID'] = 'Invalid promotion code';
                         unset($promotionCode);
                     }
                     $tp->assign('applied_products', $appliedProducts);
                     $tp->assign('code_info', $codeInfo);
                 } else {
                     $errors['NOT_VALID'] = 'Invalid promotion code';
                 }
                 if (isset($promotionCode) && isset($appliedPromoCode)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/');
                 }
             } else {
                 $errors['EMPTY_VALUE'] = 'Promotion code';
             }
             break;
         case 'deletePromoCode':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
             } else {
                 $products = SJB_Session::getValue('products');
                 $products = $products ? $products : array();
                 krsort($products);
             }
             foreach ($products as $key => $product) {
                 $productInfo = unserialize($product['product_info']);
                 SJB_PromotionsManager::removePromoCodeFromProduct($productInfo);
                 if (SJB_UserManager::isUserLoggedIn()) {
                     $numberOfListings = is_array($numberOfListings) ? array_pop($numberOfListings) : false;
                     if (is_array($numberOfListings)) {
                         foreach ($numberOfListings as $listingSid => $listingsCount) {
                             if ($listingSid == $product['sid']) {
                                 $productInfo['number_of_listings'] = $listingsCount;
                             }
                         }
                     }
                     SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                 } else {
                     $products[$key]['product_info'] = serialize($productInfo);
                     SJB_Session::setValue('products', $products);
                 }
             }
             break;
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
         // To display products in shopping cart after user has been registered from shopping cart page
         if (empty($products)) {
             $products = SJB_Session::getValue('products');
             $products = $products ? $products : array();
         }
     } else {
         $products = SJB_Session::getValue('products');
         $products = $products ? $products : array();
         krsort($products);
     }
     $allowShoppingItems = array();
     foreach ($products as $product) {
         $productInfo = unserialize($product['product_info']);
         if (!empty($productInfo['code_info'])) {
             $promotionCode = $productInfo['code_info']['code'];
             $promotionCodeInfo = $productInfo['code_info'];
         } else {
             $allowShoppingItems[] = $product['sid'];
         }
     }
     $promotionCode = isset($promotionCode) ? $promotionCode : '';
     $totalPrice = 0;
     $discountTotalAmount = 0;
     $numberOfListings = SJB_Request::getVar('number_of_listings', false);
     foreach ($products as $key => $product) {
         $productInfo = unserialize($product['product_info']);
         if ($allowShoppingItems && in_array($product['sid'], $allowShoppingItems)) {
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             if (SJB_UserManager::isUserLoggedIn()) {
                 SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
             } else {
                 $products[$key]['product_info'] = serialize($productInfo);
             }
         }
         if ($numberOfListings && array_key_exists('number_of_listings', $productInfo) && array_key_exists($productInfo['sid'], $numberOfListings)) {
             $productInfo['number_of_listings'] = $numberOfListings[$productInfo['sid']][$product['sid']];
         }
         $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
         $productExtraInfo = unserialize($productInfo['serialized_extra_info']);
         if (!empty($productInfo['expiration_period']) && !is_numeric($productInfo['expiration_period'])) {
             $productInfo['primaryPrice'] = $productExtraInfo['price'];
             $productInfo['period'] = ucwords($productInfo['expiration_period']);
         } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
             $volumeBasedPricing = $productInfo['volume_based_pricing'];
             $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
             $productObj->setNumberOfListings($number_of_listings);
             $productInfo['price'] = $productObj->getPrice();
             $productInfo['primaryPrice'] = $productObj->getPrice();
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             $minListings = min($volumeBasedPricing['listings_range_from']);
             $maxListings = max($volumeBasedPricing['listings_range_to']);
             $countListings = array();
             for ($i = $minListings; $i <= $maxListings; $i++) {
                 $countListings[$i]['number_of_listings'] = $i;
                 for ($j = 1; $j <= count($volumeBasedPricing['listings_range_from']); $j++) {
                     if ($i >= $volumeBasedPricing['listings_range_from'][$j] && $i <= $volumeBasedPricing['listings_range_to'][$j]) {
                         $countListings[$i]['price'] = $volumeBasedPricing['price_per_unit'][$j] * $i;
                         $countListings[$i]['primaryPrice'] = $volumeBasedPricing['price_per_unit'][$j] * $i;
                         if (!empty($productInfo['code_info']['type'])) {
                             switch ($productInfo['code_info']['type']) {
                                 case 'percentage':
                                     $countListings[$i]['price'] = round($countListings[$i]['price'] - $countListings[$i]['primaryPrice'] / 100 * $productInfo['code_info']['discount'], 2);
                                     $countListings[$i]['percentPromoAmount'] = round($countListings[$i]['primaryPrice'] - $countListings[$i]['price'], 2);
                                     $countListings[$i]['percentPromoCode'] = $productInfo['code_info']['code'];
                                     break;
                                 case 'fixed':
                                     $countListings[$i]['price'] = round($countListings[$i]['price'] - $productInfo['code_info']['discount'], 2);
                                     break;
                             }
                         }
                     }
                 }
             }
             $productInfo['count_listings'] = $countListings;
         } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
             $productInfo['primaryPrice'] = $productObj->getPrice();
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             unset($productInfo['volume_based_pricing']);
         }
         if (isset($productInfo['code_info'])) {
             if ($productInfo['code_info']['type'] != 'fixed' && isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $discountTotalAmount += (double) $productInfo['count_listings'][$productInfo['number_of_listings']]['percentPromoAmount'];
             } else {
                 $discountTotalAmount += (double) $productInfo['code_info']['promoAmount'];
             }
         }
         if (empty($productInfo['volume_based_pricing'])) {
             $productInfo['primaryPrice'] = $productExtraInfo['price'];
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             $totalPrice += (double) $productInfo['price'];
         }
         $products[$key] = $productInfo;
         $products[$key]['item_sid'] = $product['sid'];
     }
     if ($currentUser) {
         $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($currentUser->getSID(), $totalPrice);
         $tp->assign('tax', $taxInfo);
     }
     $userGroupID = $productInfo ? SJB_UserGroupDBManager::getUserGroupIDBySID($productInfo['user_group_sid']) : false;
     $tp->assign('promotionCodeAlreadyUsed', $promotionCode && empty($errors));
     if (isset($promotionCodeInfo)) {
         $tp->assign('promotionCodeInfo', $promotionCodeInfo);
     }
     $tp->assign('error', $error);
     $tp->assign('errors', $errors);
     $tp->assign('total_price', $totalPrice);
     $tp->assign('discountTotalAmount', $discountTotalAmount);
     $tp->assign('products', $products);
     $tp->assign('userGroupID', $userGroupID);
     $tp->assign('account_activated', SJB_Request::getVar('account_activated', ''));
     $tp->display('shopping_cart.tpl');
 }
예제 #19
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $restore = SJB_Request::getVar('restore', false);
     $action = SJB_Request::getVar('action_name', 'view_log');
     $action = $action == 'search' ? 'view_log' : $action;
     $paginator = new SJB_EmailLogPagination();
     $display_error = SJB_Request::getVar('display_error', false);
     $savedErrors = SJB_Session::getValue(self::EMAIL_ERRORS);
     SJB_Session::unsetValue(self::EMAIL_ERRORS);
     $this->errors = $savedErrors ? $savedErrors : array();
     $message = SJB_Session::getValue(self::EMAIL_LOG_MESSAGE);
     SJB_Session::unsetValue(self::EMAIL_LOG_MESSAGE);
     switch ($action) {
         case 'display_message':
             $sid = SJB_Request::getVar('sid', false);
             $email = SJB_EmailLogManager::getEmailInfoBySID($sid);
             $tp->assign('display_error', $display_error);
             $tp->assign('email', $email);
             $tp->display('display_log_message.tpl');
             return true;
             break;
         case 'resend':
             try {
                 SJB_Settings::saveSetting(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION, SJB_Request::getVar(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION));
                 $this->resendEmails();
                 SJB_Session::setValue(self::EMAIL_LOG_MESSAGE, 'The message(s) were successfully resent.');
             } catch (Exception $e) {
                 array_push($this->errors, $e->getMessage());
             }
             SJB_Session::setValue(self::EMAIL_ERRORS, $this->errors);
             $searchFields = SJB_Request::getVar('searchFields');
             SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/email-log/?sorting_field=' . $paginator->sortingField . '&sorting_order=' . $paginator->sortingOrder . '&items_per_page=' . $paginator->itemsPerPage . $searchFields);
             break;
         case 'view_log':
             $userSID = SJB_Request::getVar('user_sid', false);
             if ($userSID) {
                 $template = 'user_email_log.tpl';
                 $_REQUEST['username']['equal'] = $userSID;
                 $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
                 $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
                 $tp->assign('userGroupInfo', $userGroupInfo);
                 $tp->assign('display_error', $display_error);
                 $tp->assign('user_info', $userInfo);
                 $tp->assign('user_sid', $userSID);
             }
             $email = new SJB_EmailLog($_REQUEST);
             $search_form_builder = new SJB_SearchFormBuilder($email);
             $criteria_saver = new SJB_EmailLogCriteriaSaver();
             if ($restore) {
                 $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
             }
             $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $email);
             if (!$userSID) {
                 $template = 'email_log.tpl';
                 $search_form_builder->setCriteria($criteria);
                 $search_form_builder->registerTags($tp);
                 $tp->display("email_log_search_form.tpl");
             }
             $order_info = array('sorting_field' => $paginator->sortingField, 'sorting_order' => $paginator->sortingOrder);
             $criteria_saver->setSessionForOrderInfo($order_info);
             $criteria_saver->setSessionForCurrentPage($paginator->currentPage);
             $criteria_saver->setSessionForListingsPerPage($paginator->itemsPerPage);
             $searcher = new SJB_EmailLogSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder);
             $found_emails = $searcher->getObjectsSIDsByCriteria($criteria);
             $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
             foreach ($found_emails as $id => $emailSID) {
                 $emailInfo = SJB_EmailLogManager::getEmailInfoBySID($emailSID);
                 $found_emails[$id] = $emailInfo;
                 $found_emails[$id]['user'] = !empty($emailInfo['username']) ? SJB_UserManager::getUserInfoBySID($emailInfo['username']) : array();
                 $found_emails[$id]['admin'] = array();
                 if (!empty($emailInfo['admin'])) {
                     if (is_numeric($emailInfo['admin'])) {
                         $found_emails[$id]['admin'] = SJB_SubAdminManager::getSubAdminInfoBySID($emailInfo['admin']);
                     } else {
                         $found_emails[$id]['admin']['username'] = '******';
                     }
                 }
             }
             $paginator->setItemsCount($searcher->getAffectedRows());
             $searchFields = '';
             foreach ($_REQUEST as $key => $val) {
                 if (is_array($val)) {
                     foreach ($val as $fieldName => $fieldValue) {
                         $searchFields .= "&{$key}[{$fieldName}]={$fieldValue}";
                     }
                 }
             }
             $tp->assign(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION, SJB_Settings::getSettingByName(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION));
             $tp->assign('message', $message);
             $tp->assign('errors', $this->errors);
             $tp->assign("searchFields", $searchFields);
             $tp->assign('paginationInfo', $paginator->getPaginationInfo());
             $tp->assign("found_emails", $found_emails);
             $tp->display($template);
             break;
     }
 }