public function execute() { $templateProcessor = SJB_System::getTemplateProcessor(); $listingSid = isset($_REQUEST['listing_id']) ? $_REQUEST['listing_id'] : null; $listing = SJB_ListingManager::getObjectBySID($listingSid); if (!is_null($listing) && !$listing->isActive()) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSid); $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array(); if (isset($listingInfo['complete']) && $listingInfo['complete'] == 1 && $listingInfo['checkouted'] == 1) { $subTotalPrice = 0; // проверить истек ли листинг, если истек , прайс прировнять к renewal_price if (SJB_ListingManager::getIfListingHasExpiredBySID($listing->getID()) && isset($productInfo['renewal_price'])) { $subTotalPrice = $productInfo['renewal_price']; } $userSid = $listing->getUserSID(); $productSid = $productInfo['product_sid']; $listingTitle = $listing->getProperty('Title')->getValue(); $listingTypeSid = $listing->getListingTypeSID(); $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid); $newProductName = "Reactivation of \"{$listingTitle}\" {$listingTypeId}"; $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSid, $productSid, $listingSid, $subTotalPrice, $newProductName, 'activateListing'); if ($subTotalPrice <= 0) { if (SJB_ListingManager::activateListingBySID($listing->getSID())) { SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID()); } } else { SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSid); $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/'; SJB_HelperFunctions::redirect($shoppingUrl); } $templateProcessor->assign('listingTypeID', SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid)); } elseif ($listingInfo['checkouted'] == 0) { $productsInfoFromShopppingCart = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($productInfo['product_sid'], $listing->getUserSID()); if (empty($productsInfoFromShopppingCart)) { $productInfoToShopCart = SJB_ProductsManager::getProductInfoBySID($productInfo['product_sid']); $productInfo['number_of_listings'] = 1; $productObj = new SJB_Product($productInfoToShopCart, $productInfoToShopCart['product_type']); $productObj->setNumberOfListings($productInfoToShopCart['number_of_listings']); $productInfoToShopCart['price'] = $productObj->getPrice(); SJB_ShoppingCart::addToShoppingCart($productInfoToShopCart, $listing->getUserSID()); } SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/'); } else { $errors['LISTING_IS_NOT_COMPLETE'] = 1; } } elseif (is_null($listingSid)) { $errors['INVALID_LISTING_ID'] = 1; } elseif (!is_null($listing) && $listing->isActive()) { $errors['LISTING_ALREADY_ACTIVE'] = 1; } else { $errors['WRONG_LISTING_ID_SPECIFIED'] = 1; } $templateProcessor->assign("errors", isset($errors) ? $errors : null); $templateProcessor->display("pay_for_listing.tpl"); }
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); }
public function execute() { if (!function_exists('_filter_data')) { function _filter_data(&$array, $key, $pattern) { if (isset($array[$key])) { if (!preg_match($pattern, $array[$key])) { unset($array[$key]); } } } } _filter_data($_REQUEST, 'sorting_field', "/^[_\\w\\d]+\$/"); _filter_data($_REQUEST, 'sorting_order', "/(^DESC\$)|(^ASC\$)/i"); _filter_data($_REQUEST, 'default_sorting_field', "/^[_\\w\\d]+\$/"); _filter_data($_REQUEST, 'default_sorting_order', "/(^DESC\$)|(^ASC\$)/i"); $tp = SJB_System::getTemplateProcessor(); if (!SJB_UserManager::isUserLoggedIn()) { $errors['NOT_LOGGED_IN'] = true; $tp->assign("ERRORS", $errors); $tp->display("error.tpl"); return; } $this->defineRequestedListingTypeID(); if (!$this->listingTypeID) { $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo()); $tp->display('my_available_listing_types.tpl'); return; } $this->listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID); if (!$this->listingTypeSID) { SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/my-listings/'); return; } $currentUser = SJB_UserManager::getCurrentUser(); $userSID = $currentUser->getSID(); $this->requestCriteria = array('user_sid' => array('equal' => $userSID), 'listing_type_sid' => array('equal' => $this->listingTypeSID)); $acl = SJB_Acl::getInstance(); if ($currentUser->isSubuser()) { $subUserInfo = $currentUser->getSubuserInfo(); if (!$acl->isAllowed('subuser_manage_listings', $subUserInfo['sid'])) { $this->requestCriteria['subuser_sid'] = array('equal' => $subUserInfo['sid']); } } SJB_ListingManager::deletePreviewListingsByUserSID($userSID); $searcher = new SJB_ListingSearcher(); // to save criteria in the session different from search_results $criteriaSaver = new SJB_ListingCriteriaSaver('MyListings'); if (isset($_REQUEST['restore'])) { $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria()); } if (isset($_REQUEST['listings'])) { $listingsSIDs = $_REQUEST['listings']; if (isset($_REQUEST['action_deactivate'])) { $this->executeAction($listingsSIDs, 'deactivate'); } elseif (isset($_REQUEST['action_activate'])) { $redirectToShoppingCard = false; $activatedListings = array(); foreach ($listingsSIDs as $listingSID => $value) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSID); $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array(); if ($listingInfo['active']) { continue; } else { if (SJB_ListingManager::getIfListingHasExpiredBySID($listingSID) && isset($productInfo['renewal_price']) && $productInfo['renewal_price'] > 0) { $redirectToShoppingCard = true; $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']); $newProductName = "Reactivation of \"{$listingInfo['Title']}\" {$listingTypeId}"; $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSID, $productInfo['product_sid'], $listingSID, $productInfo['renewal_price'], $newProductName, 'activateListing'); SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSID); } else { if ($listingInfo['checkouted'] == 0) { $redirectToShoppingCard = true; } else { if (SJB_ListingManager::activateListingBySID($listingSID, false)) { $listing = SJB_ListingManager::getObjectBySID($listingSID); SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID()); $activatedListings[] = $listingSID; } } } } } SJB_BrowseDBManager::addListings($activatedListings); if ($redirectToShoppingCard) { $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/'; SJB_HelperFunctions::redirect($shoppingUrl); } } else { if (isset($_REQUEST['action_delete'])) { $this->executeAction($listingsSIDs, 'delete'); $allowedPostBeforeCheckout = SJB_Settings::getSettingByName('allow_to_post_before_checkout'); foreach ($listingsSIDs as $listingSID => $value) { if ($allowedPostBeforeCheckout == true) { $this->deleteCheckoutedListingFromShopCart($listingSID, $userSID); } } } elseif (isset($_REQUEST['action_sendToApprove'])) { $processListingsIds = array(); foreach ($listingsSIDs as $listingSID => $value) { $processListingsIds[] = $listingSID; } SJB_ListingManager::setListingApprovalStatus($processListingsIds, 'pending'); } } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-listings/{$this->listingTypeID}/"); } $listing = new SJB_Listing(array(), $this->listingTypeSID); $idAliasInfo = $listing->addIDProperty(); $listing->addActivationDateProperty(); $listing->addKeywordsProperty(); $listing->addPicturesProperty(); $listingTypeIdAliasInfo = $listing->addListingTypeIDProperty(); $sortingFields = array(); $innerJoin = array(); $sortingField = SJB_Request::getVar("sorting_field", null); $sortingOrder = SJB_Request::getVar("sorting_order", null); if (isset($sortingField, $sortingOrder)) { $orderInfo = array('sorting_field' => $sortingField, 'sorting_order' => $sortingOrder); } else { $orderInfo = $criteriaSaver->getOrderInfo(); } if ($orderInfo['sorting_field'] == 'applications') { $innerJoin['applications'] = array('count' => 'count(`applications`.id) as appCount', 'join' => 'LEFT JOIN', 'join_field' => 'listing_id', 'join_field2' => 'sid', 'main_table' => 'listings'); $sortingFields['appCount'] = $orderInfo['sorting_order']; $searcher->setGroupByField(array('listings' => 'sid')); } else { if ($orderInfo['sorting_field'] == 'id') { $sortingFields['sid'] = $orderInfo['sorting_order']; } else { if ($orderInfo['sorting_field'] == 'subuser_sid') { $innerJoin['users'] = array('join' => 'LEFT JOIN', 'join_field' => 'sid', 'join_field2' => 'subuser_sid', 'main_table' => 'listings'); $sortingFields['username'] = $orderInfo['sorting_order']; } else { $property = $listing->getProperty($sortingField); if (!empty($property) && $property->isSystem()) { $sortingFields[$orderInfo['sorting_field']] = $orderInfo['sorting_order']; } else { $sortingFields['activation_date'] = 'DESC'; } } } } $this->requestCriteria['sorting_field'] = $orderInfo['sorting_field']; $this->requestCriteria['sorting_order'] = $orderInfo['sorting_order']; $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($_REQUEST, $this->requestCriteria), $listing); $aliases = new SJB_PropertyAliases(); $aliases->addAlias($idAliasInfo); $aliases->addAlias($listingTypeIdAliasInfo); $foundListingsSIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields, $innerJoin); $searchFormBuilder = new SJB_SearchFormBuilder($listing); $searchFormBuilder->registerTags($tp); $searchFormBuilder->setCriteria($criteria); // получим информацию о имеющихся листингах $listingsInfo = array(); $currentUserInfo = SJB_UserManager::getCurrentUserInfo(); $contractInfo['extra_info']['listing_amount'] = 0; if ($acl->isAllowed('post_' . $this->listingTypeID)) { $permissionParam = $acl->getPermissionParams('post_' . $this->listingTypeID); if (empty($permissionParam)) { $contractInfo['extra_info']['listing_amount'] = 'unlimited'; } else { $contractInfo['extra_info']['listing_amount'] = $permissionParam; } } $currentUser = SJB_UserManager::getCurrentUser(); $contractsSIDs = $currentUser->getContractID(); $listingsInfo['listingsNum'] = SJB_ContractManager::getListingsNumberByContractSIDsListingType($contractsSIDs, $this->listingTypeID); $listingsInfo['listingsMax'] = $contractInfo['extra_info']['listing_amount']; if ($listingsInfo['listingsMax'] === 'unlimited') { $listingsInfo['listingsLeft'] = 'unlimited'; } else { $listingsInfo['listingsLeft'] = $listingsInfo['listingsMax'] - $listingsInfo['listingsNum']; $listingsInfo['listingsLeft'] = $listingsInfo['listingsLeft'] < 0 ? 0 : $listingsInfo['listingsLeft']; } $tp->assign('listingTypeID', $this->listingTypeID); $tp->assign('listingTypeName', SJB_ListingTypeManager::getListingTypeNameBySID($this->listingTypeSID)); $tp->assign('listingsInfo', $listingsInfo); $tp->display('my_listings_form.tpl'); $page = SJB_Request::getVar('page', 1); $listingsPerPage = $criteriaSaver->getListingsPerPage(); //save 'listings per page' in the session if (empty($listingsPerPage)) { $listingsPerPage = 10; } $listingsPerPage = SJB_Request::getVar('listings_per_page', $listingsPerPage); $criteriaSaver->setSessionForListingsPerPage($listingsPerPage); $criteriaSaver->setSessionForCurrentPage($page); $criteriaSaver->setSessionForCriteria($_REQUEST); $criteriaSaver->setSessionForOrderInfo($orderInfo); $criteriaSaver->setSessionForObjectSIDs($foundListingsSIDs); // get Applications $appsGroups = SJB_Applications::getAppGroupsByEmployer($currentUserInfo['sid']); $apps = array(); foreach ($appsGroups as $group) { $apps[$group['listing_id']] = $group['count']; } $searchCriteriaStructure = $criteriaSaver->createTemplateStructureForCriteria(); $listingSearchStructure = $criteriaSaver->createTemplateStructureForSearch(); /**************** P A G I N G *****************/ if ($listingSearchStructure['current_page'] > $listingSearchStructure['pages_number']) { $listingSearchStructure['current_page'] = $listingSearchStructure['pages_number']; } if ($listingSearchStructure['current_page'] < 1) { $listingSearchStructure['current_page'] = 1; } $sortedFoundListingsSIDsByPages = array_chunk($foundListingsSIDs, $listingSearchStructure['listings_per_page'], true); /************* S T R U C T U R E **************/ $listingsStructure = array(); $listingStructureMetaData = array(); if (isset($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1])) { foreach ($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1] as $sid) { $listing = SJB_ListingManager::getObjectBySID($sid); $listing->addPicturesProperty(); $listingStructure = SJB_ListingManager::createTemplateStructureForListing($listing); $listingsStructure[$listing->getID()] = $listingStructure; if (isset($listingStructure['METADATA'])) { $listingStructureMetaData = array_merge($listingStructureMetaData, $listingStructure['METADATA']); } } } /*************** D I S P L A Y ****************/ $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $metadata = array(); $metadata['listing'] = $metaDataProvider->getMetaData($listingStructureMetaData); $waitApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($this->listingTypeSID); $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates')); $tp->assign('show_comments', SJB_Settings::getSettingByName('show_comments')); $tp->assign('METADATA', $metadata); $tp->assign('sorting_field', $listingSearchStructure['sorting_field']); $tp->assign('sorting_order', $listingSearchStructure['sorting_order']); $tp->assign('property', $this->getSortableProperties()); $tp->assign('listing_search', $listingSearchStructure); $tp->assign('search_criteria', $searchCriteriaStructure); $tp->assign('listings', $listingsStructure); $tp->assign('waitApprove', $waitApprove); $tp->assign('apps', $apps); $hasSubusersWithListings = false; $subusers = SJB_UserManager::getSubusers($currentUserInfo['sid']); foreach ($subusers as $subuser) { if ($acl->isAllowed('subuser_add_listings', $subuser['sid']) || $acl->isAllowed('subuser_manage_listings', $subuser['sid'])) { $hasSubusersWithListings = true; break; } } $tp->assign('hasSubusersWithListings', $hasSubusersWithListings); $tp->display('my_listings.tpl'); }
public function execute() { $listing_id = SJB_Request::getVar('listing_id', null); $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id); $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_info['listing_type_sid']); if (!is_null($listing_info)) { $filename = SJB_Request::getVar('filename', false); if ($filename) { $file = SJB_UploadFileManager::openFile($filename, $listing_id); $errors['NO_SUCH_FILE'] = true; } if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && !$_REQUEST['Occupations']['tree']) { unset($_REQUEST['Occupations']['tree']); } $listing_info = array_merge($listing_info, $_REQUEST); if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && $_REQUEST['Occupations']['tree']) { $listing_info['Occupations'] = $_REQUEST['Occupations']['tree']; } $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']); $listing->setSID($listing_id); $listing_edit_form = new SJB_Form($listing); $form_is_submitted = SJB_Request::getVar('action'); $errors = array(); if ($form_is_submitted) { $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true)); } if ($form_is_submitted && $listing_edit_form->isDataValid($errors)) { $listingSid = $listing->getID(); SJB_BrowseDBManager::deleteListings($listingSid); SJB_ListingManager::saveListing($listing); SJB_BrowseDBManager::addListings($listingSid); $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_Event::dispatch('listingEdited', $listingSid); if (SJB_Request::isAjax()) { echo '<p class="green">Listing Saved</p>'; exit; } if ($form_is_submitted == 'save_info') { $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']); $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's'; SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/manage-" . strtolower($listingType) . "/?restore=1"); } } $listing->deleteProperty('access_list'); $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id); $comments_total = count($comments); $rate = SJB_Rating::getRatingNumToListing($listing_id); $form_fields = $listing_edit_form->getFormFieldsInfo(); $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing->getListingTypeSID()); $realFormFields = array(); foreach ($pages as $page) { $listingFields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']); foreach ($listingFields as $fieldID => $listingField) { if (isset($form_fields[$fieldID])) { $realFormFields[$fieldID] = $form_fields[$fieldID]; } } } $adminFields = array(); foreach ($form_fields as $fieldName => $field) { if (!isset($realFormFields[$fieldName])) { $adminFields[$fieldName] = $field; } } $realFormFields = array_merge($adminFields, $realFormFields); $tp = SJB_System::getTemplateProcessor(); $listing_edit_form->registerTags($tp); $extraInfo = $listing_info['product_info']; if ($extraInfo) { $extraInfo = unserialize($extraInfo); $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0; $tp->assign("listing_duration", $extraInfo['listing_duration']); $tp->assign("pic_limit", $numberOfPictures); } $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing); if (!isset($listing_structure['access_type'])) { $listing_structure['access_type'] = 'everyone'; } $listing_access_list = SJB_ListingManager::getListingAccessList($listing_id, $listing->getPropertyValue('access_type')); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('form_fields', $realFormFields); $tp->assign('listing', $listing_structure); $tp->assign('errors', $errors); $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo)); $tp->assign('listing_access_list', $listing_access_list); $tp->assign('comments_total', $comments_total); $tp->assign('rate', $rate); $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID())); SJB_System::setGlobalTemplateVariable('wikiExtraParam', $listingTypeInfo['id']); $tp->display('edit_listing.tpl'); } }