示例#1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $listingTypeID = SJB_Request::getVar('listing_type_id', '');
     if (SJB_UserManager::isUserLoggedIn()) {
         if (!SJB_Acl::getInstance()->isAllowed('save_' . trim($listingTypeID))) {
             $errors[] = 'DENIED_VIEW_SAVED_LISTING';
         }
         if (!$errors) {
             $userSid = SJB_UserManager::getCurrentUserSID();
             if (SJB_Request::getVar('action', '') == 'delete') {
                 $listing_id = SJB_Request::getVar('listing_id', null);
                 if (!is_null($listing_id)) {
                     foreach ($listing_id as $key => $value) {
                         SJB_SavedListings::deleteListingFromDBBySID($key, $userSid);
                     }
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . SJB_Navigator::getURI());
                 }
             }
             $saved_listings_id = SJB_SavedListings::getSavedListingsFromDB($userSid);
             $listings_structure = array();
             $listing_structure_meta_data = array();
             foreach ($saved_listings_id as $saved_listing) {
                 $saved_listing_id = $saved_listing['listing_sid'];
                 $listing = SJB_ListingManager::getObjectBySID($saved_listing_id);
                 if (is_null($listing)) {
                     continue;
                 }
                 $listing->addPicturesProperty();
                 $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
                 $listings_structure[$listing->getID()] = $listing_structure;
                 $listings_structure[$listing->getID()]['saved_listing'] = $saved_listing;
                 if (isset($listing_structure['METADATA'])) {
                     $listing_structure_meta_data = array_merge($listing_structure_meta_data, $listing_structure['METADATA']);
                 }
             }
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign("METADATA", array("listing" => $metaDataProvider->getMetaData($listing_structure_meta_data)));
             $tp->assign("listings", $listings_structure);
             $tp->assign("listing_type_id", $listingTypeID);
             $tp->display("saved_listings.tpl");
         } else {
             $tp->assign("errors", $errors);
             $tp->display("save_search_failed.tpl");
         }
     } else {
         $url = base64_encode(SJB_System::getSystemSettings("SITE_URL") . "/system/classifieds" . SJB_System::getURI());
         switch ($listingTypeID) {
             case 'job':
                 $url = base64_encode(SJB_System::getSystemSettings("SITE_URL") . "/saved-jobs/");
                 break;
             case 'resume':
                 $url = base64_encode(SJB_System::getSystemSettings("SITE_URL") . "/saved-resumes/");
                 break;
         }
         $tp->assign("return_url", $url);
         $tp->display("../users/login.tpl");
     }
 }
示例#2
0
 public static function canRate($listing_sid, $title = false)
 {
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_info = SJB_UserManager::getCurrentUserInfo();
         $user_id = $user_info['sid'];
     } else {
         if ($title) {
             self::$title = 3;
         }
         //'Please sign in to vote ';
         return false;
     }
     $result = SJB_DB::query("SELECT vote FROM `rating` WHERE `user_id` = {$user_id} AND listing_id = ?n ", $listing_sid);
     if (count($result) == 0) {
         if ($title) {
             self::$title = 1;
         }
         //'Please, Vote!';
         return true;
     }
     if ($title) {
         self::$title = 2;
     }
     //"You've already voted";
     return false;
 }
示例#3
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_id = SJB_UserManager::getCurrentUserSID();
         $errors = array();
         $id = SJB_Request::getInt('id', 0, 'GET');
         $action = SJB_Request::getVar('action', '', 'GET');
         if ($id > 0) {
             // read message
             if (SJB_PrivateMessage::isMyMessage($id)) {
                 if ($action == 'delete') {
                     SJB_PrivateMessage::delete(array($id));
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/private-messages/inbox/');
                 }
                 $message = SJB_PrivateMessage::readMessage($id);
                 SJB_Authorization::updateCurrentUserSession();
                 $current_user_info = SJB_UserManager::createTemplateStructureForCurrentUser();
                 $current_user_info['logged_in'] = true;
                 $current_user_info['new_messages'] = SJB_PrivateMessage::getCountUnreadMessages($current_user_info['id']);
                 SJB_System::setCurrentUserInfo($current_user_info);
                 $tp->assign('message', $message);
                 $tp->assign('include', 'message_detail.tpl');
             } else {
                 $errors['NOT_EXISTS_MESSAGE'] = 1;
             }
         }
         $tp->assign('errors', $errors);
         $tp->assign('unread', SJB_PrivateMessage::getCountUnreadMessages($user_id));
         $tp->display('main.tpl');
     } else {
         $tp->assign('return_url', base64_encode(SJB_Navigator::getURIThis()));
         $tp->display('../users/login.tpl');
     }
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_id = SJB_UserManager::getCurrentUserSID();
         if (SJB_Request::getVar('pm_action', '', SJB_Request::METHOD_POST) == 'delete') {
             $checked = SJB_Request::getVar('pm_check', array(), SJB_Request::METHOD_POST);
             SJB_PrivateMessage::delete($checked);
         }
         $page = intval(SJB_Request::getVar('page', 1, SJB_Request::METHOD_GET));
         $messagesPerPage = SJB_Request::getInt('messagesPerPage', 10);
         $total = SJB_PrivateMessage::getTotalOutbox($user_id);
         $totalPages = ceil($total / $messagesPerPage);
         if ($totalPages == 0) {
             $totalPages = 1;
         }
         if (empty($page) || $page <= 0) {
             $page = 1;
         }
         if ($totalPages < $page) {
             SJB_HelperFunctions::redirect("?page={$totalPages}");
         }
         $list = SJB_PrivateMessage::getListOutbox($user_id, $page, $messagesPerPage);
         $tp->assign('message_list', $list);
         $tp->assign('messagesPerPage', $messagesPerPage);
         $tp->assign('page', $page);
         $tp->assign('totalPages', $totalPages);
         $tp->assign('include', 'list_outbox.tpl');
         $tp->assign('unread', SJB_PrivateMessage::getCountUnreadMessages($user_id));
     }
     $tp->display('main.tpl');
 }
 public function execute()
 {
     $count_listing = SJB_Request::getVar('count_listing', 10);
     $listings_structure = array();
     $listing_structure_meta_data = array();
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_sid = SJB_UserManager::getCurrentUserSID();
         $viewed_listings = SJB_UserManager::getRecentlyViewedListingsByUserSid($user_sid, $count_listing);
         if (count($viewed_listings)) {
             foreach ($viewed_listings as $viewed_listing) {
                 $listing = SJB_ListingManager::getObjectBySID($viewed_listing['listing_sid']);
                 if (empty($listing)) {
                     continue;
                 }
                 $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
                 $listings_structure[] = $listing_structure;
                 if (isset($listing_structure['METADATA'])) {
                     $listing_structure_meta_data = array_merge($listing_structure_meta_data, $listing_structure['METADATA']);
                 }
             }
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign("METADATA", array("listing" => $metaDataProvider->getMetaData($listing_structure_meta_data)));
             $tp->assign("listings", $listings_structure);
         }
         $tp->display('recently_viewed_listings.tpl');
     }
 }
示例#6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $count_listing = SJB_Request::getVar('count_listing', 10, null, 'int');
     $current_user = SJB_UserManager::getCurrentUser();
     if (SJB_UserManager::isUserLoggedIn()) {
         $lastAddedListing = SJB_ListingManager::getLastAddedListingByUserSID($current_user->getSID());
         if ($lastAddedListing) {
             $properties = $current_user->getProperties();
             $phrase['title'] = $lastAddedListing->getPropertyValue('Title');
             foreach ($properties as $property) {
                 if ($property->getType() == 'location') {
                     $fields = $property->type->child;
                     $childProperties = $fields->getProperties();
                     foreach ($childProperties as $childProperty) {
                         if (in_array($childProperty->getID(), array('City', 'State', 'Country'))) {
                             $value = $childProperty->getValue();
                             switch ($childProperty->getType()) {
                                 case 'list':
                                     if ($childProperty->getID() == 'State') {
                                         $displayAS = $childProperty->display_as;
                                         $displayAS = $displayAS ? $displayAS : 'state_name';
                                         $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $displayAS);
                                     } else {
                                         $listValues = $childProperty->type->list_values;
                                     }
                                     foreach ($listValues as $values) {
                                         if ($value == $values['id']) {
                                             $phrase[strtolower($childProperty->getID())] = $values['caption'];
                                         }
                                     }
                                     break;
                                 default:
                                     $phrase[strtolower($childProperty->getID())] = $value;
                                     break;
                             }
                         }
                     }
                 }
             }
             $phrase = array_diff($phrase, array(''));
             $phrase = implode(" ", $phrase);
             $listing_type_id = "Job";
             $request['action'] = 'search';
             $request['listing_type']['equal'] = $listing_type_id;
             $request['default_listings_per_page'] = $count_listing;
             $request['default_sorting_field'] = "activation_date";
             $request['default_sorting_order'] = "DESC";
             $request['keywords']['relevance'] = $phrase;
             $searchResultsTP = new SJB_SearchResultsTP($request, $listing_type_id, array('field' => 'keywords', 'value' => $phrase));
             $tp = $searchResultsTP->getChargedTemplateProcessor();
         }
         $tp->display('suggested_jobs.tpl');
     }
 }
示例#7
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_id = SJB_UserManager::getCurrentUserSID();
         $unread = SJB_PrivateMessage::getCountUnreadMessages($user_id);
         $tp->assign('unread', $unread);
         $tp->assign('include', '');
     }
     $tp->display('main.tpl');
 }
示例#8
0
文件: ajax.php 项目: Maxlander/shixi
 private function jsRate()
 {
     if (!SJB_UserManager::isUserLoggedIn()) {
         exit;
     }
     $listing_sid = SJB_Request::getInt('listing', 0, SJB_Request::METHOD_POST);
     $rate = SJB_Request::getInt('rate', 0, SJB_Request::METHOD_POST);
     $new_rating = SJB_Rating::setRaiting($rate, $listing_sid, SJB_UserManager::getCurrentUserSID());
     if (isset($new_rating['rating'])) {
         echo $new_rating['rating'];
     }
 }
示例#9
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int');
     $listingType = SJB_Request::getVar('listing_type', null);
     if (!$listingType) {
         if ($listingId) {
             $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
             $listingType = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
         } else {
             $listingType = 'job';
         }
     }
     $displayForm = SJB_Request::getVar('displayForm', false);
     $error = null;
     if (!SJB_Acl::getInstance()->isAllowed('save_' . trim($listingType))) {
         $error = 'DENIED_SAVE_LISTING';
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         if (!$error) {
             if (!is_null($listingId)) {
                 if (SJB_UserManager::isUserLoggedIn()) {
                     SJB_SavedListings::saveListingOnDB($listingId, SJB_UserManager::getCurrentUserSID());
                     SJB_Statistics::addStatistics('saveListing', SJB_ListingTypeManager::getListingTypeSIDByID($listingType), $listingId);
                 } else {
                     SJB_SavedListings::saveListingInCookie($listingId);
                 }
                 $template_processor->assign('saved_listing', SJB_SavedListings::getSavedListingsByUserAndListingSid(SJB_UserManager::getCurrentUserSID(), $listingId));
             } else {
                 $error = 'LISTING_ID_NOT_SPECIFIED';
             }
         }
         $params = SJB_Request::getVar('params', false);
         $searchId = SJB_Request::getVar('searchId', false);
         $page = SJB_Request::getVar('page', false);
         $template_processor->assign("params", $params);
         $template_processor->assign("searchId", $searchId);
         $template_processor->assign("page", $page);
         $template_processor->assign("listing_type", $listingType);
         $template_processor->assign("listing_sid", $listingId);
         $template_processor->assign("from_login", SJB_Request::getVar("from_login", false));
         $template_processor->assign("error", $error);
         $template_processor->assign("displayForm", $displayForm);
         $template_processor->assign("view", SJB_Request::getVar('view'));
         $template_processor->display("save_listing.tpl");
     } else {
         $template_processor->assign("return_url", base64_encode(SJB_Navigator::getURIThis() . "&from_login=1"));
         $template_processor->assign("ajaxRelocate", true);
         $template_processor->display("../users/login.tpl");
     }
 }
示例#10
0
文件: error.php 项目: Maxlander/shixi
 public function execute()
 {
     $pageConfig = SJB_Request::getInstance()->page_config;
     $tp = SJB_System::getTemplateProcessor();
     if (isset($this->params['ERROR'])) {
         $tp->assign('ERROR', $this->params['ERROR']);
     } else {
         if (SJB_UserManager::isUserLoggedIn()) {
             $tp->assign('ERROR', 'ACCESS_DENIED');
         } else {
             $tp->assign('ERROR', 'NOT_LOGIN');
         }
     }
     $tp->assign('page_function', $pageConfig->function);
     $tp->display('../miscellaneous/error.tpl');
 }
 public function execute()
 {
     $current_user_info = array('logged_in' => false);
     if (SJB_UserManager::isUserLoggedIn()) {
         SJB_Authorization::updateCurrentUserSession();
         $current_user_info = SJB_UserManager::createTemplateStructureForCurrentUser();
         $current_user_info['logged_in'] = true;
         $current_user_info['new_messages'] = SJB_PrivateMessage::getCountUnreadMessages($current_user_info['id']);
     } else {
         // social plugin
         $userGroups = SJB_UserGroupManager::getAllUserGroupsInfo();
         SJB_System::setCurrentUserGroupsInfo($userGroups);
         SJB_Event::dispatch('Login_Plugin');
     }
     SJB_System::setCurrentUserInfo($current_user_info);
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $userSID = SJB_UserManager::getCurrentUserSID();
         $action = SJB_Request::getVar('pm_action', null);
         if ($action) {
             $checked = SJB_Request::getVar('pm_check', array(), 'POST');
             switch ($action) {
                 case 'delete':
                     SJB_PrivateMessage::deleteContact($userSID, $checked);
                     break;
                 case 'save_contact':
                     $error = '';
                     $contactSID = SJB_Request::getInt('user_id', 0);
                     SJB_PrivateMessage::saveContact($userSID, $contactSID, $error);
                     $tp->assign('error', $error);
                     $tp->display('contact_save.tpl');
                     return true;
                     break;
                 default:
                     break;
             }
         }
         $page = SJB_Request::getInt('page', 1, 'GET');
         $contactsPerPage = SJB_Request::getInt('contactsPerPage', 10);
         SJB_PrivateMessage::deleteNonexistentContacts($userSID);
         $total = SJB_PrivateMessage::getTotalContacts($userSID);
         $totalPages = ceil($total / $contactsPerPage);
         if ($totalPages == 0) {
             $totalPages = 1;
         }
         if (empty($page) || $page <= 0) {
             $page = 1;
         }
         if ($totalPages < $page) {
             SJB_HelperFunctions::redirect("?page={$totalPages}");
         }
         $tp->assign('message_list', SJB_PrivateMessage::getContacts($userSID, $page, $contactsPerPage));
         $tp->assign('contactsPerPage', $contactsPerPage);
         $tp->assign('page', $page);
         $tp->assign('totalPages', $totalPages);
         $tp->assign('include', 'contacts.tpl');
         $tp->assign('unread', SJB_PrivateMessage::getCountUnreadMessages($userSID));
     }
     $tp->display('main.tpl');
 }
示例#13
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $user_menu_template = 'user_menu.tpl';
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_info = SJB_Authorization::getCurrentUserInfo();
         if (!empty($user_info)) {
             $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
             if (!empty($user_group_info['user_menu_template']) && $tp->templateExists($user_group_info['user_menu_template'])) {
                 $user_menu_template = $user_group_info['user_menu_template'];
             }
             $tp->assign("user_group_info", $user_group_info);
             $tp->assign('listingTypesInfo', SJB_ListingTypeManager::getAllListingTypesInfo());
         }
     }
     $tp->assign("account_activated", SJB_Request::getVar('account_activated', ''));
     $tp->display($user_menu_template);
 }
示例#14
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_id = SJB_UserManager::getCurrentUserSID();
         $action = SJB_Request::getVar('pm_action', SJB_Request::METHOD_POST, false);
         if ($action) {
             $checked = SJB_Request::getVar('pm_check', SJB_Request::METHOD_POST, array());
             switch ($action) {
                 case 'mark':
                     SJB_PrivateMessage::markAsRead($checked);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/private-messages/inbox/');
                     break;
                 case 'delete':
                     SJB_PrivateMessage::delete($checked);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/private-messages/inbox/');
                     break;
                 default:
                     break;
             }
         }
         $page = SJB_Request::getInt('page', 1, 'GET');
         $messagesPerPage = SJB_Request::getInt('messagesPerPage', 10);
         $total = SJB_PrivateMessage::getTotalInbox($user_id);
         $totalPages = ceil($total / $messagesPerPage);
         if ($totalPages == 0) {
             $totalPages = 1;
         }
         if (empty($page) || $page <= 0) {
             $page = 1;
         }
         if ($totalPages < $page) {
             SJB_HelperFunctions::redirect("?page={$totalPages}");
         }
         $tp->assign('message_list', SJB_PrivateMessage::getListInbox($user_id, $page, $messagesPerPage));
         $tp->assign('include', 'list_inbox.tpl');
         $tp->assign('messagesPerPage', $messagesPerPage);
         $tp->assign('page', $page);
         $tp->assign('totalPages', $totalPages);
         $tp->assign('unread', SJB_PrivateMessage::getCountUnreadMessages($user_id));
     }
     $tp->display('main.tpl');
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = null;
     if (SJB_UserManager::isUserLoggedIn()) {
         $userSID = SJB_UserManager::getCurrentUserSID();
         $contactSID = 0;
         $errors = array();
         if (isset($_REQUEST['passed_parameters_via_uri'])) {
             $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
             $contactSID = SJB_Array::get($passed_parameters_via_uri, 0);
         }
         if (!$contactSID) {
             $errors['UNDEFINED_CONTACT_ID'] = 1;
         } else {
             $contactInfo = SJB_PrivateMessage::getContactInfo($userSID, $contactSID);
             if (!$contactInfo) {
                 $errors['WRONG_CONTACT_ID_SPECIFIED'] = 1;
             } else {
                 $action = SJB_Request::getVar('action');
                 switch ($action) {
                     case 'save':
                         $note = SJB_Request::getVar('note');
                         $result = SJB_PrivateMessage::saveContactNote($userSID, $contactSID, $note);
                         if ($result) {
                             $tp->assign('noteSaved', true);
                         }
                         break;
                     default:
                         break;
                 }
             }
             $tp->assign('contactInfo', $contactInfo);
         }
         $tp->assign('errors', $errors);
     }
     if ($action) {
         $tp->assign('action', $action);
         $tp->display('notes.tpl');
     } else {
         $tp->display('contact.tpl');
     }
 }
示例#16
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');
 }
示例#17
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn() === false) {
         $tp->assign('ERROR', 'NOT_LOGIN');
         $tp->display('../miscellaneous/error.tpl');
         return;
     }
     $appsSID = 0;
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
         $appsSID = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null;
     }
     if (SJB_Applications::isUserOwnerApps(SJB_UserManager::getCurrentUserSID(), $appsSID)) {
         $apps_info = SJB_Applications::getBySID($appsSID);
         if (!empty($apps_info['questionnaire'])) {
             $questions = unserialize($apps_info['questionnaire']);
             $tp->assign('questions', $questions);
         }
         $tp->assign('apps_info', $apps_info);
         $tp->display('view_questionaire.tpl');
     }
 }
示例#18
0
文件: index.php 项目: Maxlander/shixi
<?php

require_once 'phpbb_bridge_plugin.php';
$userSession = PhpBBBridgePlugin::getUserSessionBySessionId(SJB_Session::getSessionId());
if (!empty($userSession)) {
    if (SJB_UserManager::isUserLoggedIn()) {
        if ($userSession['user_sid'] !== SJB_UserManager::getCurrentUserSID()) {
            if (!$userSession['user_sid']) {
                SJB_Authorization::logout();
            } else {
                SJB_Session::setValue('current_user', PhpBBBridgePlugin::sessionDecode($userSession['data']));
            }
        }
    } else {
        SJB_Session::setValue('current_user', PhpBBBridgePlugin::sessionDecode($userSession['data']));
    }
}
SJB_Event::handle('Login', array('PhpBBBridgePlugin', 'login'));
SJB_Event::handle('Logout', array('PhpBBBridgePlugin', 'logout'));
示例#19
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $info = '';
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_id = SJB_UserManager::getCurrentUserSID();
         $to = SJB_Request::getVar('to');
         // POST and check for errors form_to form_subject form_message
         if (isset($_POST['form_to'])) {
             $to_user_name = SJB_Request::getVar('form_to', null, 'POST');
             $to_user_info = null;
             // trying to get user info by user id
             if (intval($to_user_name)) {
                 $to_user_info = SJB_UserManager::getUserInfoBySID($to_user_name);
             }
             /*
              * в функции compose private message функцию отправки
              * сообщения по имени пользователя оставить рабочей
              */
             if (is_null($to_user_info)) {
                 $to_user_info = SJB_UserManager::getUserInfoByUserName($to_user_name);
             }
             // trying to get user info by user id
             if (intval($to_user_name)) {
                 $to_user_info = SJB_UserManager::getUserInfoBySID($to_user_name);
             }
             /*
              * в функции compose private message функцию отправки
              * сообщения по имени пользователя оставить рабочей
              */
             if (is_null($to_user_info)) {
                 $to_user_info = SJB_UserManager::getUserInfoByUserName($to_user_name);
             }
             $to_user = isset($to_user_info['sid']) ? $to_user_info['sid'] : 0;
             $subject = isset($_POST['form_subject']) ? strip_tags($_POST['form_subject']) : '';
             $message = isset($_POST['form_message']) ? SJB_PrivateMessage::cleanText($_POST['form_message']) : '';
             $save = isset($_POST['form_save']) ? true : false;
             if ($to_user == 0) {
                 $errors['form_to'] = 'You specified wrong username';
             }
             if (empty($subject)) {
                 $errors['form_subject'] = 'Please, enter message subject';
             }
             if (empty($message)) {
                 $errors['form_message'] = 'Please, enter message';
             }
             if (count($errors) == 0) {
                 $anonym = SJB_Request::getVar('anonym');
                 SJB_PrivateMessage::sendMessage($user_id, $to_user, $subject, $message, $save, false, false, $anonym);
                 $info = 'The message was sent successfully';
                 $to = '';
                 // save to contacts
                 if (!$anonym) {
                     SJB_PrivateMessage::saveContact($user_id, $to_user);
                     SJB_PrivateMessage::saveContact($to_user, $user_id);
                 }
             } else {
                 $tp->assign("form_to", htmlentities($to_user_name, ENT_QUOTES, "UTF-8"));
                 $tp->assign("form_subject", htmlentities($subject, ENT_QUOTES, "UTF-8"));
                 $tp->assign("form_message", $message);
                 $tp->assign("form_save", $save);
                 $tp->assign("errors", $errors);
             }
         }
         $display_to = '';
         // get display name for "Message to" field
         SJB_UserManager::getComposeDisplayName($to, $display_to);
         $tp->assign('info', $info);
         $tp->assign('to', $to);
         $tp->assign('anonym', SJB_Request::getVar('anonym'));
         $tp->assign('display_to', $display_to);
         $tp->assign('include', 'new_message.tpl');
         $tp->assign('unread', SJB_PrivateMessage::getCountUnreadMessages($user_id));
         $tp->display('main.tpl');
     } else {
         $tp->assign('return_url', base64_encode(SJB_Navigator::getURIThis()));
         $tp->assign('ajaxRelocate', true);
         $tp->display('../users/login.tpl');
     }
 }
示例#20
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $current_user = SJB_UserManager::getCurrentUser();
     $action = SJB_Request::getVar('action', 'productList');
     $productSID = SJB_Request::getVar('product_sid', 0, 'default', 'int');
     $template = 'products.tpl';
     $availableProducts = array();
     $errors = array();
     switch ($action) {
         case 'productList':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $postingProductsOnly = SJB_Request::getVar('postingProductsOnly', false);
                 $availableProducts = SJB_ProductsManager::getProductsByUserGroupSID($current_user->getUserGroupSID(), $current_user->getSID());
                 $trialProduncts = $current_user->getTrialProductSIDByUserSID();
                 foreach ($availableProducts as $key => $availableProduct) {
                     if (in_array($availableProduct['sid'], $trialProduncts) || $postingProductsOnly && $availableProduct['product_type'] != "post_listings" && $availableProduct['product_type'] != "mixed_product") {
                         unset($availableProducts[$key]);
                     }
                 }
                 if ($postingProductsOnly) {
                     $tp->assign('postingProductsOnly', $postingProductsOnly);
                 }
             } elseif ($userGroupID = SJB_Request::getVar('userGroupID', false)) {
                 $userGroupSID = SJB_UserGroupManager::getUserGroupSIDByID($userGroupID);
                 $availableProducts = SJB_ProductsManager::getProductsByUserGroupSID($userGroupSID, 0);
             } else {
                 $availableProducts = SJB_ProductsManager::getAllActiveProducts();
             }
             foreach ($availableProducts as $key => $availableProductInfo) {
                 if (SJB_ProductsManager::isProductTrialAndAlreadyInCart($availableProductInfo, $current_user)) {
                     unset($availableProducts[$key]);
                     continue;
                 }
                 $availableProduct = new SJB_Product($availableProductInfo, $availableProductInfo['product_type']);
                 $availableProduct->setNumberOfListings(1);
                 $availableProducts[$key]['price'] = $availableProduct->getPrice();
                 if (isset($availableProducts[$key]['listing_type_sid'])) {
                     $availableProducts[$key]['listing_type_id'] = SJB_ListingTypeDBManager::getListingTypeIDBySID($availableProducts[$key]['listing_type_sid']);
                 }
             }
             SJB_Event::dispatch('RedefineTemplateName', $template, true);
             SJB_Event::dispatch('RedefineProductsDisplayInfo', $availableProducts, true);
             $tp->assign("account_activated", SJB_Request::getVar('account_activated', ''));
             $tp->assign("availableProducts", $availableProducts);
             break;
         case 'view_product_detail':
             $template = 'view_product_detail.tpl';
             if (!SJB_UserManager::isUserLoggedIn() || $current_user->mayChooseProduct($productSID, $errors)) {
                 $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
                 if (in_array($productInfo['product_type'], array('post_listings', 'mixed_product'))) {
                     $productInfo['listingTypeID'] = SJB_ListingTypeManager::getListingTypeIDBySID($productInfo['listing_type_sid']);
                 }
                 $event = SJB_Request::getVar('event', false);
                 if ($event) {
                     if ($productInfo) {
                         switch ($productInfo['product_type']) {
                             case 'banners':
                                 $params = $_REQUEST;
                                 if (empty($params['title'])) {
                                     $errors[] = "Banner Title is empty.";
                                 }
                                 if (empty($params['link'])) {
                                     $errors[] = "Banner link mismatched!";
                                 }
                                 if (empty($_FILES['image']['name'])) {
                                     $errors[] = "No file attached!";
                                 } elseif ($_FILES['image']['error']) {
                                     switch ($_FILES['image']['error']) {
                                         case '1':
                                             $errors[] = 'UPLOAD_ERR_INI_SIZE';
                                             break;
                                         case '2':
                                             $errors[] = 'UPLOAD_ERR_FORM_SIZE';
                                             break;
                                         case '3':
                                             $errors[] = 'UPLOAD_ERR_PARTIAL';
                                             break;
                                         case '4':
                                             $errors[] = 'UPLOAD_ERR_NO_FILE';
                                             break;
                                         default:
                                             $errors[] = 'NOT_UPLOAD_FILE';
                                             break;
                                     }
                                 } else {
                                     $imageInfo = @getimagesize($_FILES['image']['tmp_name']);
                                     if (!$imageInfo || $imageInfo['2'] < 1 && $imageInfo['2'] > 3) {
                                         $errors[] = 'Image format is not supported';
                                     } elseif (!empty($productInfo['width']) && $imageInfo[0] != $productInfo['width']) {
                                         $errors[] = "Your banner dimensions exceed the required size. Please upload an appropriate banner.";
                                     } elseif (!empty($productInfo['height']) && $imageInfo[1] != $productInfo['height']) {
                                         $errors[] = "Your banner dimensions exceed the required size. Please upload an appropriate banner.";
                                     }
                                 }
                                 if ($errors) {
                                     break;
                                 }
                                 //add banner
                                 $title = $params['title'];
                                 $link = $params['link'];
                                 $expr = preg_match("/(http:\\/\\/)/", $link, $matches);
                                 if ($expr != true) {
                                     $link = "http://" . $link;
                                 }
                                 $filesDir = SJB_System::getSystemSettings('FILES_DIR');
                                 $ext = preg_match("|\\.(\\w{3})\\b|u", $_FILES['image']['name'], $arr);
                                 $fileName = preg_replace("|\\.(\\w{3})\\b|u", "", $_FILES['image']['name']);
                                 $hashName = md5(time() * $_FILES['image']['size']) . "_" . $fileName;
                                 $bannerFilePath = $filesDir . "banners/" . $hashName . "." . $arr[1];
                                 $copy = move_uploaded_file($_FILES['image']['tmp_name'], $bannerFilePath);
                                 if (!$copy) {
                                     $errors[] = 'Cannot copy file from TMP dir to Banners Dir';
                                     break;
                                 }
                                 if ($_FILES['image']['type'] != 'application/x-shockwave-flash') {
                                     $bannerInfo = getimagesize($bannerFilePath);
                                     if ($productInfo['width'] != '' && $productInfo['height'] != '') {
                                         $sx = $productInfo['width'];
                                         $sy = $productInfo['height'];
                                     } else {
                                         $sx = $bannerInfo[0];
                                         $sy = $bannerInfo[1];
                                     }
                                     $type = $bannerInfo['mime'];
                                 } else {
                                     if ($productInfo['width'] == '' || $productInfo['height'] == '') {
                                         $errors[] = 'Your banner dimensions exceed the required size. Please upload an appropriate banner.';
                                         break;
                                     }
                                     $sx = $productInfo['width'];
                                     $sy = $productInfo['height'];
                                     $type = $_FILES['image']['type'];
                                 }
                                 $active = 0;
                                 $group = $productInfo['banner_group_sid'];
                                 $params['bannerFilePath'] = "/" . str_replace("../", "/", str_replace(SJB_BASE_DIR, '', $bannerFilePath));
                                 $params['openBannerIn'] = '';
                                 $params['bannerType'] = 'file';
                                 $params['code'] = '';
                                 $params['title'] = $title;
                                 $params['link'] = $link;
                                 $params['type'] = $type;
                                 $params['sx'] = $sx;
                                 $params['sy'] = $sy;
                                 $params['banner_group_sid'] = $group;
                                 $productInfo['banner_info'] = $params;
                                 break;
                         }
                         if (!$errors) {
                             $numberOfListings = SJB_Request::getVar('number_of_listings');
                             $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
                             if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based' && $numberOfListings) {
                                 $productInfo['number_of_listings'] = $numberOfListings;
                                 $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 (SJB_UserManager::isUserLoggedIn()) {
                                 SJB_ShoppingCart::addToShoppingCart($productInfo, $current_user->getSID());
                             } else {
                                 if (isset($_SESSION['products'])) {
                                     foreach ($_SESSION['products'] as $addedProduct) {
                                         $addedProductInfo = unserialize($addedProduct['product_info']);
                                         if ($addedProductInfo['user_group_sid'] != $productInfo['user_group_sid']) {
                                             $errors[] = 'You are trying to add products of different User Groups in your Shopping Cart. You сan add only products belonging to one User Group. If you want to add this product in the Shopping Cart please go back to the Shopping Cart and remove products of other User Groups.';
                                             break;
                                         }
                                     }
                                 }
                                 if (!$errors) {
                                     $id = time();
                                     $_SESSION['products'][$id]['product_info'] = serialize($productInfo);
                                     $_SESSION['products'][$id]['sid'] = $id;
                                     $_SESSION['products'][$id]['user_sid'] = 0;
                                 }
                             }
                             if (!$errors) {
                                 SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
                             }
                         }
                     }
                 }
                 if (!empty($productInfo['expiration_period']) && !is_numeric($productInfo['expiration_period'])) {
                     $productInfo['period'] = ucwords($productInfo['expiration_period']);
                 } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based' && !empty($productInfo['volume_based_pricing'])) {
                     $volumeBasedPricing = $productInfo['volume_based_pricing'];
                     $price = array();
                     $firstPrice = 0;
                     if (!empty($volumeBasedPricing['listings_range_from'])) {
                         for ($i = 1; $i <= count($volumeBasedPricing['listings_range_from']); $i++) {
                             if ($volumeBasedPricing['listings_range_from'][$i] == $volumeBasedPricing['listings_range_to'][$i]) {
                                 $price[$i]['range']['from'] = $volumeBasedPricing['listings_range_from'][$i];
                             } else {
                                 $price[$i]['range']['from'] = $volumeBasedPricing['listings_range_from'][$i];
                                 $price[$i]['range']['to'] = $volumeBasedPricing['listings_range_to'][$i];
                             }
                             $price[$i]['price'] = $volumeBasedPricing['price_per_unit'][$i];
                             if ($i > 1 && $firstPrice > $volumeBasedPricing['price_per_unit'][$i]) {
                                 $price[$i]['savings'] = round(100 - 100 / $firstPrice * $volumeBasedPricing['price_per_unit'][$i]);
                             } else {
                                 $firstPrice = $volumeBasedPricing['price_per_unit'][$i];
                             }
                         }
                     }
                     $productInfo['volume_based_pricing'] = $price;
                     $minListings = min($volumeBasedPricing['listings_range_from']);
                     $maxListings = max($volumeBasedPricing['listings_range_to']);
                     $countListings = array();
                     for ($i = $minListings; $i <= $maxListings; $i++) {
                         $countListings[] = $i;
                     }
                     $productInfo['count_listings'] = $countListings;
                 } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                     $productInfo['fixed_period'] = 1;
                 }
                 if ($productInfo['product_type'] == 'banners') {
                     $params = $_REQUEST;
                     $bannersObj = new SJB_Banners();
                     $banner_fields = $bannersObj->getBannersMeta();
                     foreach ($banner_fields as $key => $banner_field) {
                         $banner_fields[$banner_field['id']] = $banner_field;
                         if (!empty($params[$banner_field['id']])) {
                             $banner_fields[$banner_field['id']]['value'] = $params[$banner_field['id']];
                         }
                         unset($banner_fields[$key]);
                     }
                     if (!empty($params['errors'])) {
                         $tp->assign("errors", $params['errors']);
                     }
                     $tp->assign("banner_fields", $banner_fields);
                 }
                 $userGroupID = SJB_UserGroupDBManager::getUserGroupIDBySID($productInfo['user_group_sid']);
                 $tp->assign('productInfo', $productInfo);
                 $tp->assign('userGroupID', $userGroupID);
                 $tp->assign('productSID', $productSID);
                 $tp->assign('mayChooseProduct', true);
             }
             $tp->assign('errors', $errors);
             break;
     }
     $tp->display($template);
 }
示例#21
0
 /**
  * @param int $currentUserID
  * @param int $productSID
  * @return bool|int|mixed
  */
 public function proceedToCheckout($currentUserID, $productSID)
 {
     $errors = array();
     $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
     if (SJB_UserManager::isUserLoggedIn()) {
         $numberOfListings = SJB_ListingDBManager::getNumberOfCheckoutedListingsByProductSID($productSID, $currentUserID);
         $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         $shoppingCartProducts = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($productSID, $currentUserID);
         if (!empty($shoppingCartProducts)) {
             if ($productInfo['product_type'] == 'mixed_product' || isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                 if ($numberOfListings / (count($shoppingCartProducts) * $productInfo['number_of_listings']) > 1) {
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
                 }
             }
             if (isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 if ($numberOfListings / (count($shoppingCartProducts) * end($productInfo['volume_based_pricing']['listings_range_to'])) > 1) {
                     $productInfo['number_of_listings'] = 1;
                     $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                     $productObj->setNumberOfListings($productInfo['number_of_listings']);
                     $productInfo['price'] = $productObj->getPrice();
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
                 } else {
                     foreach ($shoppingCartProducts as $shoppingCartProduct) {
                         $unserializedProductInfoFromShopCart = unserialize($shoppingCartProduct['product_info']);
                         if ($unserializedProductInfoFromShopCart['number_of_listings'] < end($unserializedProductInfoFromShopCart['volume_based_pricing']['listings_range_to'])) {
                             $unserializedProductInfoFromShopCart['number_of_listings'] += 1;
                             SJB_ShoppingCart::updateItemBySID($shoppingCartProduct['sid'], $unserializedProductInfoFromShopCart);
                             break;
                         }
                     }
                 }
             }
         } else {
             if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based') {
                 $productInfo['number_of_listings'] = 1;
                 $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                 $productObj->setNumberOfListings($productInfo['number_of_listings']);
                 $productInfo['price'] = $productObj->getPrice();
             }
             SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
         }
     } else {
         $products = SJB_Session::getValue('products');
         if (isset($products)) {
             foreach ($products as $addedProduct) {
                 $addedProductInfo = unserialize($addedProduct['product_info']);
                 if ($addedProductInfo['user_group_sid'] != $productInfo['user_group_sid']) {
                     $errors[] = 'You are trying to add products of different User Groups in your Shopping Cart. You сan add only products belonging to one User Group. If you want to add this product in the Shopping Cart please go back to the Shopping Cart and remove products of other User Groups.';
                     break;
                 }
             }
         }
         if (!$errors) {
             $id = time();
             $products[$id]['product_info'] = serialize($productInfo);
             $products[$id]['sid'] = $id;
             $products[$id]['user_sid'] = 0;
             SJB_Session::setValue('products', $products);
         }
     }
     if (!$errors) {
         SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
     }
 }
示例#22
0
 public function isAccessible()
 {
     return SJB_UserManager::isUserLoggedIn();
 }
示例#23
0
 public static function canCurrentUserAddListing(&$error, $listingTypeId = false)
 {
     $acl = SJB_Acl::getInstance();
     if (SJB_UserManager::isUserLoggedIn()) {
         $current_user = SJB_UserManager::getCurrentUser();
         if ($current_user->hasContract()) {
             $contracts_id = $current_user->getContractID();
             $contractsSIDs = $contracts_id ? implode(',', $contracts_id) : 0;
             $resultContractInfo = SJB_DB::query("SELECT `id`, `product_sid`, `expired_date`, `number_of_postings` FROM `contracts` WHERE `id` in ({$contractsSIDs}) ORDER BY `expired_date` DESC");
             $PlanAcces = count($resultContractInfo) > 0 ? true : false;
             if ($PlanAcces && $acl->isAllowed('post_' . $listingTypeId)) {
                 $productsInfo = array();
                 $is_contract = false;
                 foreach ($resultContractInfo as $contractInfo) {
                     if ($acl->isAllowed('post_' . $listingTypeId, $contractInfo['id'], 'contract')) {
                         $permissionParam = $acl->getPermissionParams('post_' . $listingTypeId, $contractInfo['id'], 'contract');
                         if (empty($permissionParam) || $acl->getPermissionParams('post_' . $listingTypeId, $contractInfo['id'], 'contract') > $contractInfo['number_of_postings']) {
                             $product = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']);
                             $productsInfo[$contractInfo['id']]['product_name'] = $product['name'];
                             $productsInfo[$contractInfo['id']]['expired_date'] = $contractInfo['expired_date'];
                             $productsInfo[$contractInfo['id']]['contract_id'] = $contractInfo['id'];
                         }
                     }
                     $is_contract = true;
                 }
                 if ($is_contract && count($productsInfo) > 0) {
                     return $productsInfo;
                 } else {
                     $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED';
                 }
             } else {
                 $error = 'DO_NOT_MATCH_POST_THIS_TYPE_LISTING';
             }
         } else {
             $error = 'NO_CONTRACT';
         }
     } else {
         $error = 'NOT_LOGGED_IN';
     }
     return false;
 }
示例#24
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);
 }
示例#25
0
 function getListingCollectionStructure($sorted_found_listings_sids_for_current_page)
 {
     $listings_structure = array();
     $currentUserSID = SJB_UserManager::getCurrentUserSID();
     $isUserLoggedIn = SJB_UserManager::isUserLoggedIn();
     foreach ($sorted_found_listings_sids_for_current_page as $sid) {
         $listing = SJB_ListingManager::getObjectBySID($sid);
         $listing->addPicturesProperty();
         $listings_structure[$listing->getID()] = SJB_ListingManager::createTemplateStructureForListing($listing);
         $listings_structure[$listing->getID()] = SJB_ListingManager::newValueFromSearchCriteria($listings_structure[$listing->getID()], $this->criteria_saver->criteria);
         if ($isUserLoggedIn) {
             $listings_structure[$listing->getID()]['saved_listing'] = SJB_SavedListings::getSavedListingsByUserAndListingSid($currentUserSID, $listing->getID());
         }
     }
     return $listings_structure;
 }
示例#26
0
 public function execute()
 {
     $errors = array();
     $field_errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $loggedIn = SJB_UserManager::isUserLoggedIn();
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $controller = new SJB_SendListingInfoController($_REQUEST);
     $isDataSubmitted = false;
     $jobInfo = SJB_ListingManager::getListingInfoBySID($controller->getListingID());
     if ($controller->isListingSpecified()) {
         if ($controller->isDataSubmitted()) {
             if (SJB_Captcha::getInstance($tp, $_REQUEST)->isValid($errors)) {
                 // получим уникальный id для файла в uploaded_files
                 $file_id_current = 'application_' . md5(microtime());
                 $upload_manager = new SJB_UploadFileManager();
                 $upload_manager->setFileGroup('files');
                 $upload_manager->setUploadedFileID($file_id_current);
                 $file_name = $upload_manager->uploadFile('file_tmp');
                 $id_file = $upload_manager->fileId;
                 $post = $controller->getData();
                 $listingId = 0;
                 $post['submitted_data']['questionnaire'] = '';
                 if (isset($post['submitted_data']['id_resume'])) {
                     $listingId = $post['submitted_data']['id_resume'];
                 }
                 $mimeType = isset($_FILES['file_tmp']['type']) ? $_FILES['file_tmp']['type'] : '';
                 if (isset($_FILES['file_tmp']['size']) && $file_name != '' && $_FILES['file_tmp']['size'] == 0) {
                     $errors['FILE_IS_EMPTY'] = 'The uploaded file should not be blank';
                 }
                 if (!empty($_FILES['file_tmp']['name'])) {
                     $fileFormats = explode(',', SJB_System::getSettingByName('file_valid_types'));
                     $fileInfo = pathinfo($_FILES['file_tmp']['name']);
                     if (!isset($fileInfo['extension']) || !in_array(strtolower($fileInfo['extension']), $fileFormats)) {
                         $errors['NOT_SUPPORTED_FILE_FORMAT'] = strtolower($fileInfo['extension']) . ' ' . SJB_I18N::getInstance()->gettext(null, 'is not in an acceptable file format');
                     }
                 }
                 if ($file_name == '' && $listingId == 0) {
                     $canAppplyWithoutResume = false;
                     SJB_Event::dispatch('CanApplyWithoutResume', $canAppplyWithoutResume);
                     if (!$canAppplyWithoutResume) {
                         $errors['APPLY_INPUT_ERROR'] = 'Please select file or resume';
                     }
                 } else {
                     if (SJB_Applications::isApplied($post['submitted_data']['listing_id'], $current_user_sid) && !is_null($current_user_sid)) {
                         $errors['APPLY_APPLIED_ERROR'] = 'You already applied';
                     }
                 }
                 $res = false;
                 $listing_info = '';
                 $notRegisterUserData = $_POST;
                 $score = 0;
                 // для зарегестрированного пользователя получим поля email и name
                 // для незарегестрированных - поля name и email приходят с формы
                 if ($loggedIn === true) {
                     $userData = SJB_UserManager::getCurrentUserInfo();
                     $post['submitted_data']['username'] = isset($userData['username']) ? $userData['username'] : '';
                     $post['submitted_data']['LastName'] = isset($userData['LastName']) ? $userData['LastName'] : '';
                     $post['submitted_data']['FirstName'] = isset($userData['FirstName']) ? $userData['FirstName'] : '';
                     $post['submitted_data']['name'] = $post['submitted_data']['FirstName'] . ' ' . $post['submitted_data']['LastName'];
                     $post['submitted_data']['email'] = $userData['email'];
                 }
                 if (!empty($jobInfo['screening_questionnaire'])) {
                     $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
                     $add_form = new SJB_Form($questions);
                     $add_form->registerTags($tp);
                     $add_form->isDataValid($field_errors);
                     $tp->assign('field_errors', $field_errors);
                     if (!$field_errors) {
                         $result = array();
                         $properties = $questions->getProperties();
                         $countAnswers = 0;
                         foreach ($properties as $key => $val) {
                             if ($val->type->property_info['type'] == 'boolean') {
                                 switch ($val->value) {
                                     case 0:
                                         $val->value = 'No';
                                         break;
                                     case 1:
                                         $val->value = 'Yes';
                                         break;
                                 }
                             }
                             $result[$val->caption] = $val->value;
                             if (isset($val->type->property_info['list_values'])) {
                                 foreach ($val->type->property_info['list_values'] as $list_values) {
                                     if (is_array($val->value)) {
                                         foreach ($val->value as $value) {
                                             if ($value == $list_values['id'] && $list_values['score'] != 'no') {
                                                 $score += $list_values['score'];
                                                 $countAnswers++;
                                             }
                                         }
                                     } else {
                                         if ($val->value == $list_values['id'] && $list_values['score'] != 'no') {
                                             $score += $list_values['score'];
                                             $countAnswers++;
                                         }
                                     }
                                 }
                             }
                         }
                         if ($countAnswers === 0) {
                             $score = 0.0;
                         } else {
                             $score = round($score / $countAnswers, 2);
                         }
                         $post['submitted_data']['questionnaire'] = serialize($result);
                     }
                 }
                 if (count($errors) == 0 && count($field_errors) == 0) {
                     $res = SJB_Applications::create($post['submitted_data']['listing_id'], $current_user_sid, isset($post['submitted_data']['id_resume']) ? $post['submitted_data']['id_resume'] : '', $post['submitted_data']['comments'], $file_name, $mimeType, $id_file, isset($post['submitted_data']['anonymous']) ? $post['submitted_data']['anonymous'] : '0', $notRegisterUserData, $post['submitted_data']['questionnaire'], $score);
                     if ($res) {
                         SJB_Statistics::addStatistics('apply', $post['submitted_data']['listing_id'], $res);
                     }
                     if (isset($post['submitted_data']['id_resume']) && $post['submitted_data']['id_resume'] != 0) {
                         $listing_info = SJB_ListingManager::getListingInfoBySID($post['submitted_data']['id_resume']);
                         $emp_sid = SJB_ListingManager::getUserSIDByListingSID($post['submitted_data']['listing_id']);
                         $accessible = SJB_ListingManager::isListingAccessableByUser($post['submitted_data']['id_resume'], $emp_sid);
                         if (!$accessible) {
                             SJB_ListingManager::setListingAccessibleToUser($post['submitted_data']['id_resume'], $emp_sid);
                         }
                     }
                     if (!empty($file_name)) {
                         $file_name = 'files/files/' . $file_name;
                     }
                     SJB_Notifications::sendApplyNow($post, $file_name, $listing_info, $current_user_sid, $notRegisterUserData, $score);
                     if (!empty($jobInfo['screening_questionnaire'])) {
                         $questionnaire = SJB_ScreeningQuestionnaires::getInfoBySID($jobInfo['screening_questionnaire']);
                         if ($questionnaire) {
                             $passing_score = 0;
                             switch ($questionnaire['passing_score']) {
                                 case 'acceptable':
                                     $passing_score = 1;
                                     break;
                                 case 'good':
                                     $passing_score = 2;
                                     break;
                                 case 'very_good':
                                     $passing_score = 3;
                                     break;
                                 case 'excellent':
                                     $passing_score = 4;
                                     break;
                             }
                         }
                         if ($score >= $passing_score && $questionnaire['send_auto_reply_more'] == 1) {
                             if (!empty($questionnaire['email_text_more'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_more'], $notRegisterUserData);
                             }
                         } elseif ($score < $passing_score && $questionnaire['send_auto_reply_less'] == 1) {
                             if (!empty($questionnaire['email_text_less'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_less'], $notRegisterUserData);
                             }
                         }
                     }
                 }
                 if ($res === false) {
                     $errors['APPLY_ERROR'] = 'Cannot apply';
                 }
                 $isDataSubmitted = true;
             }
         }
         if (!empty($jobInfo['screening_questionnaire'])) {
             $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
             $add_form = new SJB_Form($questions);
             $add_form->registerTags($tp);
             $form_fields = $add_form->getFormFieldsInfo();
             $tp->assign('form_fields', $form_fields);
             $tp->assign('questionsObject', $questions);
         }
         if ($loggedIn) {
             $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID('Resume');
             $wait_approve = SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid);
             $approve_status = '';
             if ($wait_approve) {
                 $approve_status = "AND `l`.`status` = 'approved'";
             }
             $result = SJB_DB::query("SELECT `l`.`sid` , `l`.`Title` FROM `listings` as `l`\n\t\t\t\tLEFT JOIN `listing_types` as `lt` ON (`lt`.`sid` = `l`.`listing_type_sid`)\n\t\t\t\tWHERE `lt`.`id` = 'Resume' {$approve_status} AND `l`.`user_sid` = {$current_user_sid} AND `l`.`active`");
             $resume = array();
             foreach ($result as $val) {
                 $resume[$val['sid']] = $val['Title'];
             }
             $tp->assign('resume', $resume);
         }
         $tp->assign('listing', $jobInfo);
     } else {
         $errors['UNDEFINED_LISTING_ID'] = true;
     }
     $tp->assign('request', $_REQUEST);
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $controller->getListingID());
     $tp->assign('is_data_submitted', $isDataSubmitted);
     $tp->display('apply_now.tpl');
 }
示例#27
0
 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()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $user_id = SJB_UserManager::getCurrentUserSID();
         $errors = array();
         $info = '';
         $to = SJB_Request::getVar('to', '', 'GET');
         // POST and check for errors form_to form_subject form_message
         if (isset($_POST['act'])) {
             $to_user_name = SJB_Request::getVar('form_to', '', 'POST');
             $to_user_info = null;
             if (intval($to_user_name)) {
                 $to_user_info = SJB_UserManager::getUserInfoBySID($to_user_name);
             }
             // в функции compose private message функцию отправки
             // сообщения по имени пользователя оставить рабочей
             if (is_null($to_user_info)) {
                 $to_user_info = SJB_UserManager::getUserInfoByUserName($to_user_name);
             }
             $cc = SJB_Request::getVar('cc', false);
             if ($cc !== false) {
                 if (intval($cc)) {
                     $cc_info = SJB_UserManager::getUserInfoBySID($cc);
                 }
                 // в функции compose private message функцию отправки
                 // сообщения по имени пользователя оставить рабочей
                 if (is_null($cc_info)) {
                     $cc_info = SJB_UserManager::getUserInfoByUserName($cc);
                 }
                 if (!empty($cc_info)) {
                     $cc = $cc_info['sid'];
                 }
             }
             $to_user = isset($to_user_info['sid']) ? $to_user_info['sid'] : 0;
             $subject = isset($_POST['form_subject']) ? strip_tags($_POST['form_subject']) : '';
             $message = isset($_POST['form_message']) ? SJB_PrivateMessage::cleanText($_POST['form_message']) : '';
             $save = isset($_POST['form_save']) ? $_POST['form_save'] == 1 ? true : false : false;
             if ($to_user == 0) {
                 $errors['form_to'] = 'Please enter correct username';
             }
             if (empty($subject)) {
                 $errors['form_subject'] = 'Please, enter message subject';
             }
             if (empty($message)) {
                 $errors['form_message'] = 'Please, enter message';
             }
             if (count($errors) == 0) {
                 $anonym = SJB_Request::getVar('anonym');
                 SJB_PrivateMessage::sendMessage($user_id, $to_user, $subject, $message, $save, false, $cc, $anonym);
                 // save to contacts
                 if (!$anonym) {
                     SJB_PrivateMessage::saveContact($user_id, $to_user);
                     SJB_PrivateMessage::saveContact($to_user, $user_id);
                 }
                 echo '<p class="message">' . SJB_I18N::getInstance()->gettext(null, 'The message was sent successfully') . '</p>';
                 exit;
             }
         }
         $display_to = '';
         // get display name for 'Message to' field
         SJB_UserManager::getComposeDisplayName($to, $display_to);
         $tp->assign('errors', $errors);
         $tp->assign('info', $info);
         $tp->assign('to', $to);
         $tp->assign('display_to', $display_to);
         $tp->assign('anonym', SJB_Request::getVar('anonym'));
         $tp->assign('cc', SJB_Request::getVar('cc', ''));
         $tp->assign('unread', SJB_PrivateMessage::getCountUnreadMessages($user_id));
         $tp->display('new_message_ajax.tpl');
     } else {
         $tp->assign('return_url', base64_encode(SJB_Navigator::getURIThis()));
         $tp->assign('ajaxRelocate', true);
         $tp->display('../users/login.tpl');
     }
 }
示例#29
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');
 }
示例#30
0
 public function execute()
 {
     /***************************************************
      * Integration of JobSource Jobg8 script
      *
      * This script integrate P4P of JobG8
      ***************************************************/
     /*
     For example in SJB there is a user "emp", с user_id = 8, emal = emp@emp.com, username = EMPjob
     Are we correct to assume that the encryption parameters will be as follows:
     
     ADHOC is ON:
     ?cid=810388&a=ADHOC&email=emp@emp.com&adv=EMPjob
     
     ADHOC is OFF:
     ?cid=810388&a=8&email=emp@emp.com&adv=EMPjob
     */
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $currentUser = SJB_UserManager::getCurrentUserInfo();
         $currentUsername = $currentUser['username'];
         $userEmail = $currentUser['email'];
         $username = $currentUser['CompanyName'];
         if (empty($username)) {
             $username = $currentUser['username'];
         }
         // our jobg8 Job Board ID
         $jobboardID = SJB_Settings::getSettingByName('jobg8_jobboard_id_p4p');
         $jobg8_p4p_url = SJB_Settings::getSettingByName('jobg8_p4p_url');
         $cid = SJB_Settings::getSettingByName('jobg8_cid');
         $markup = '';
         $mode = '';
         // check current user for individual markup value
         $result = SJB_DB::query("SELECT * FROM `users_markup` WHERE `user_sid` = ?n", $currentUser['sid']);
         if (!empty($result)) {
             $markup = $result[0]['markup'];
         }
         // check individual adhoc mode
         if ($currentUser['jobg8_adhoc'] == 1) {
             $adhoc_mode = true;
         } else {
             $adhoc_mode = false;
         }
         // look jobg8 p4p-integration doc (parameter 'a')
         if ($adhoc_mode) {
             $mode = 'ADHOC';
         } else {
             $mode = $currentUser['sid'];
         }
         //////////////////////////////////
         // set region field for P4P
         // check tax countries and states list
         //////////////////////////////////
         $taxRegions = array('Canada' => array("Alberta" => "AB", "British Columbia" => "BC", "Manitoba" => "MB", "New Brunswick" => "NB", "Newfoundland and Labrador" => "NL", "Nova Scotia" => "NS", "Northwest Territories" => "NT", "Nunavut" => "NU", "Ontario" => "ON", "Prince Edward Island" => "PE", "Quebec" => "QC", "Saskatchewan" => "SK", "Yukon" => "YT"), 'Germany' => 'DEU', 'Spain' => 'ESP', 'Ireland' => 'IRL');
         // check country
         $taxRegionCode = '';
         $userCountry = $currentUser['Country'];
         $userState = $currentUser['State'];
         if (!empty($userCountry) && !empty($userState) && array_key_exists($userCountry, $taxRegions)) {
             if (isset($taxRegions[$userCountry]) && is_string($taxRegions[$userCountry])) {
                 $taxRegionCode = $taxRegions[$userCountry];
             } elseif (isset($taxRegions[$userCountry]) && is_array($taxRegions[$userCountry]) && array_key_exists($userState, $taxRegions[$userCountry])) {
                 // check region
                 $taxRegionCode = $taxRegions[$userCountry][$userState];
             }
         }
         if ($markup == '' || !is_numeric($markup)) {
             if ($mode == 'ADHOC') {
                 $message = "?cid={$cid}&a={$mode}&email={$userEmail}&adv={$username}&region={$taxRegionCode}";
             } else {
                 $message = "?cid={$cid}&a={$mode}&region={$taxRegionCode}";
             }
         } else {
             if ($mode == 'ADHOC') {
                 $message = "?cid={$cid}&a={$mode}&email={$userEmail}&adv={$username}&m={$markup}&region={$taxRegionCode}";
             } else {
                 $message = "?cid={$cid}&a={$mode}&m={$markup}&region={$taxRegionCode}";
             }
         }
         // use RSA library for crypt
         $sshKey = JobG8IntegrationPlugin::getRsaKey();
         $keyArray = explode(' ', $sshKey, 3);
         $keyLength = $keyArray[0];
         $exponent = $keyArray[1];
         $modulus = $keyArray[2];
         // Encrypt the message
         $encryptedData = rsa_encrypt($message, $exponent, $modulus, $keyLength);
         // Base64 encode the encrypted data
         $output = urlencode(base64_encode($encryptedData));
         $tp->assign('jobg8_p4p_url', $jobg8_p4p_url);
         $tp->assign('jobboardID', $jobboardID);
         $tp->assign('encoded_data', $output);
         $tp->display('jobg8_p4p.tpl');
     } else {
         $tp->assign("return_url", base64_encode(SJB_Navigator::getURIThis()));
         //$tp->assign("ajaxRelocate", true);
         $tp->display("../users/login.tpl");
     }
 }