/** * @param string $network * @param int $listingSID * @return bool */ private static function isNetworkAllowed($network, $listingSID) { $allowed = false; if (SJB_Settings::getSettingByName("enable_job_sharing_for_users_{$network}")) { $permission = SJB_ListingDBManager::getPermissionByListingSid('post_jobs_on_social_networks', $listingSID); if ($permission == 'deny') { $allowed = false; } else { if ($permission == 'allow' || SJB_Acl::getInstance()->isAllowed('post_jobs_on_social_networks')) { $allowed = true; } } } return $allowed; }
/** * @param $itemSID * @param $userSID */ public function findCheckoutedListingsByProduct($itemSID, $userSID) { $shopCartProduct = SJB_DB::query("SELECT `product_info` FROM `shopping_cart` WHERE `sid` = ?n", $itemSID); if (!empty($shopCartProduct)) { $productInfo = unserialize($shopCartProduct[0]['product_info']); $countCheckoutedListings = SJB_ListingDBManager::getNumberOfCheckoutedListingsByProductSID($productInfo['sid'], $userSID); if ($countCheckoutedListings != 0) { $serializedProductSIDForShopCart = '"sid";s:' . strlen($productInfo['sid']) . ':"' . $productInfo['sid'] . '";'; $countOfOtherShopCartProducts = SJB_DB::queryValue("SELECT COUNT(`sid`) FROM `shopping_cart` WHERE `sid` != ?n AND `user_sid` = ?n AND `product_info` REGEXP '({$serializedProductSIDForShopCart})' ORDER BY `sid` ASC", $itemSID, $userSID); if ($productInfo['product_type'] == 'mixed_product' || isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') { $limitCheckoutedListingsToDelete = $countCheckoutedListings - $countOfOtherShopCartProducts * $productInfo['number_of_listings']; if ($limitCheckoutedListingsToDelete > 0) { $this->deleteCheckoutedListingsByProduct($userSID, $productInfo['sid'], $limitCheckoutedListingsToDelete); } } if (isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') { $maxAvailableListings = end($productInfo['volume_based_pricing']['listings_range_to']); $shopCartProductsToUpdate = SJB_DB::query("SELECT `sid`,`product_info` FROM `shopping_cart` WHERE `sid` != ?n AND `user_sid` = ?n AND `product_info` REGEXP '({$serializedProductSIDForShopCart})' ORDER BY `sid` ASC", $itemSID, $userSID); $limitCheckoutedListingsToDelete = $countCheckoutedListings - $countOfOtherShopCartProducts * $maxAvailableListings; if ($limitCheckoutedListingsToDelete >= 0) { foreach ($shopCartProductsToUpdate as $shopCartProductToUpdate) { $shopCartProductInfo = unserialize($shopCartProductToUpdate['product_info']); $shopCartProductInfo['number_of_listings'] = $maxAvailableListings; SJB_ShoppingCart::updateItemBySID($shopCartProductToUpdate['sid'], $shopCartProductInfo); } if ($limitCheckoutedListingsToDelete > 0) { $this->deleteCheckoutedListingsByProduct($userSID, $productInfo['sid'], $limitCheckoutedListingsToDelete); } } else { foreach ($shopCartProductsToUpdate as $shopCartProductToUpdate) { $shopCartProductInfo = unserialize($shopCartProductToUpdate['product_info']); if ($limitCheckoutedListingsToDelete > end($shopCartProductInfo['volume_based_pricing']['listings_range_to'])) { $limitCheckoutedListingsToDelete -= end($shopCartProductInfo['volume_based_pricing']['listings_range_to']); $shopCartProductInfo['number_of_listings'] = $maxAvailableListings; } else { $shopCartProductInfo['number_of_listings'] = $limitCheckoutedListingsToDelete; } SJB_ShoppingCart::updateItemBySID($shopCartProductToUpdate['sid'], $shopCartProductInfo); } } } } } }
public static function deactivateListingKeywordsBySID($listingSID) { return SJB_ListingDBManager::deactivateListingKeywordsBySID($listingSID); }
public function execute() { ini_set('max_execution_time', 0); $tp = SJB_System::getTemplateProcessor(); $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $listingTypeID = SJB_Request::getVar('listing_type_id', null); $productSID = SJB_Request::getVar('product_sid', 0); $errors = array(); if ($listingTypeID && $productSID) { $acl = SJB_Acl::getInstance(); $resource = 'post_' . strtolower($listingTypeID); if (!$acl->isAllowed($resource, $productSID, 'product')) { $errors[] = 'You cannot import listings of this type under the selected product'; } } if (!empty($file_info)) { $extension = SJB_Request::getVar('file_type'); if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) { $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true; } } if (empty($file_info) || $file_info['error'] || $errors) { if (isset($file_info['error']) && $file_info['error'] > 0) { $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1; } $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo(); $products = SJB_ProductsManager::getProductsByProductType('post_listings'); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('listing_types', $listing_types); $tp->assign('products', $products); $tp->assign('errors', $errors); $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $tp->display('import_listings.tpl'); } else { $i18n = SJB_I18N::getInstance(); $csv_delimiter = SJB_Request::getVar('csv_delimiter', null); $activeStatus = SJB_Request::getVar('active', 0); $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d')); $activationDate = $i18n->getInput('date', $activationDate); $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null); $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID); if (empty($productInfo['listing_duration'])) { $expirationDate = ''; } else { $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days'); $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp)); } $extension = $_REQUEST['file_type']; if ($extension == 'xls') { $import_file = new SJB_ImportFileXLS($file_info); } elseif ($extension == 'csv') { $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter); } $import_file->parse($encodingFromCharset); $listing = $this->CreateListing(array(), $listingTypeID); $imported_data = $import_file->getData(); $isFileImported = true; $count = 0; $addedListingsSids = array(); $nonExistentUsers = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing); continue; } if (!$importedColumn) { continue; } $count++; $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn); $doc = new DOMDocument(); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $doc->loadXML($listingInfo[$property->id]); $results = $doc->getElementsByTagName($property->id . 's'); $listingInfo[$property->id] = array(); foreach ($results as $complexparent) { $i = 1; foreach ($complexparent->getElementsByTagName($property->id) as $result) { $resultXML = simplexml_import_dom($result); foreach ($childFields as $childField) { if (isset($resultXML->{$childField}['id'])) { $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']); } } $i++; } } } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) { $value = $listingInfo[$property->id]; $listingInfo[$property->id] = array(); $listingInfo[$property->id]['value'] = $value; $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency(); $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code']; $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode); $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : ''; if (isset($listingInfo[$property->id . "Currency"])) { unset($listingInfo[$property->id . "Currency"]); } } elseif ($property->getType() == 'location') { $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode'); $locationFieldAdded = array(); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $listingInfo)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]); } break; default: $value = $listingInfo[$locationField]; break; } $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value; $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField); } } if ($property->id == 'Location') { $locationFields = array('Country', 'State', 'City', 'ZipCode'); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]); } break; default: $value = $listingInfo[$locationField]; break; } $listingInfo[$property->id][$locationField] = $value; } } } } } $listing = $this->CreateListing($listingInfo, $listingTypeID); $pictures = array(); if (isset($listingInfo['pictures'])) { $listing->addPicturesProperty(); $explodedPictures = explode(';', $listingInfo['pictures']); foreach ($explodedPictures as $picture) { if (!empty($picture)) { $pictures[] = $picture; } } $listing->setPropertyValue('pictures', count($pictures)); } $listing->addActiveProperty($activeStatus); $listing->addActivationDateProperty($activationDate); $listing->addExpirationDateProperty($expirationDate); SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid); $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID)); $listing->setPropertyValue('access_type', 'everyone'); $listing->setPropertyValue('status', 'approved'); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'tree' && $property->value !== '') { try { $treeImportHelper = new SJB_FieldTreeImportHelper($property->value); $treeValues = $treeImportHelper->parseAndGetValues(); $listing->setPropertyValue($property->id, $treeValues); $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues; } catch (Exception $e) { $listing->setPropertyValue($property->id, ''); $listing->details->properties[$property->id]->type->property_info['value'] = ''; SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage()); } } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) { if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) { $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1); } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) { $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2); } else { $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => ''); } //put empty if not valid email or url $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings']; } elseif ($property->getType() == 'complex') { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $complexChildValues = $property->value; foreach ($childFields as $childField) { if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) { $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']); if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) { $isFileImported = false; } } if ($property->type->complex->details->properties[$childField['id']]->value == null) { $property->type->complex->details->properties[$childField['id']]->value = array(1 => ''); $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => ''); } } } // The import of files at import of listings if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id); if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) { $isFileImported = false; } } } if ($non_existed_values_flag == 'add') { $this->UpdateListValues($listing); } if ($listing->getUserSID()) { SJB_ListingManager::saveListing($listing); $listingSid = $listing->getSID(); SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid); SJB_ListingManager::activateListingBySID($listingSid, false); if (!$this->fillGallery($listingSid, $pictures)) { $isFileImported = false; } $addedListingsSids[] = $listingSid; } else { $nonExistentUsers[] = $listingInfo['username']; $count--; } } SJB_BrowseDBManager::addListings($addedListingsSids); SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids)); if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) { SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY')); } $tp->assign('imported_listings_count', $count); $tp->assign('nonExistentUsers', $nonExistentUsers); $tp->display('import_listings_result.tpl'); } }
public static function deleteUserById($id) { $user = SJB_UserManager::getObjectBySID($id); if (empty($user)) { SJB_UserDBManager::deleteEmptyUsers(); return true; } SJB_Event::dispatch('onBeforeUserDelete', $user); $listings = SJB_ListingDBManager::getListingsSIDByUserSID($id); SJB_ListingManager::deleteListingBySID($listings); $subusers = self::getSubusers($id); foreach ($subusers as $subuser) { self::deleteUserById($subuser['sid']); } // delete user logo file $pictProp = $user->getProperty('Logo'); if ($pictProp) { SJB_UploadFileManager::deleteUploadedFileByID($pictProp->value); } $videoProp = $user->getProperty('video'); if ($videoProp) { SJB_UploadFileManager::deleteUploadedFileByID($videoProp->value); } // delete social info $socialReference = SJB_SocialPlugin::getProfileSocialID($user->getSID()); if ($socialReference) { SJB_SocialPlugin::deleteProfileSocialInfoByReference($socialReference); } $result = SJB_UserDBManager::deleteUserById($id) && SJB_ContractManager::deleteAllContractsByUserSID($id) && SJB_Rating::deleteRatingByUserSID($id); SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_USERS)); return $result && SJB_SavedSearches::deleteUserSearchesFromDB($id); }
/** * @param $listingSID * @param $userSID */ public function deleteCheckoutedListingFromShopCart($listingSID, $userSID) { $listingInfoCheckout = SJB_DB::query("SELECT `sid`,`product_info` FROM `listings` WHERE `sid` = ?n AND `checkouted` = 0 AND `complete` = 1", $listingSID); $listingProductInfo = unserialize($listingInfoCheckout[0]['product_info']); $shopCartProducts = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($listingProductInfo['product_sid'], $userSID); if ($listingProductInfo['pricing_type'] == 'fixed') { $countCheckoutedListings = SJB_ListingDBManager::getNumberOfCheckoutedListingsByProductSID($listingProductInfo['product_sid'], $userSID); if (count($shopCartProducts) * $listingProductInfo['number_of_listings'] - ($countCheckoutedListings - 1) >= $listingProductInfo['number_of_listings']) { SJB_ShoppingCart::deleteItemFromCartBySID($shopCartProducts[0]['sid'], $userSID); } } if (isset($listingProductInfo['pricing_type']) && $listingProductInfo['pricing_type'] == 'volume_based') { $shopCartSIDMinNumberOfListings = ''; $minNumberOfListings = ''; foreach ($shopCartProducts as $shopCartProduct) { $shopCartProductInfo = unserialize($shopCartProduct['product_info']); if (empty($minNumberOfListings) || $minNumberOfListings > $shopCartProductInfo['number_of_listings']) { $minNumberOfListings = $shopCartProductInfo['number_of_listings']; $shopCartSIDMinNumberOfListings = $shopCartProduct['sid']; } } if ($minNumberOfListings == 1) { SJB_ShoppingCart::deleteItemFromCartBySID($shopCartSIDMinNumberOfListings, $userSID); } else { $shopCartProductInfo['number_of_listings'] = $minNumberOfListings - 1; SJB_ShoppingCart::updateItemBySID($shopCartSIDMinNumberOfListings, $shopCartProductInfo); } } }
/** * @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/'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $template = SJB_Request::getVar('display_template'); $page = 1; $searchId = strip_tags(SJB_Request::getVar('searchId', time())); if (!empty($_REQUEST["page"])) { $page = intval($_REQUEST["page"]); } $items_per_page = SJB_Request::getVar('companies_per_page', false); $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($_REQUEST["listing_type_id"]); $alphabets = SJB_AlphabetManager::getAlphabetsForDisplay(); $abArr = array(); foreach ($alphabets as $alphabet) { $abArr[] = explode(' ', $alphabet['value']); } $action = SJB_Request::getVar('action', 'search_form'); if (SJB_Request::getVar('first_char')) { $action = 'search'; $_REQUEST['CompanyName']['first_char_like'] = SJB_Request::getVar('first_char'); } elseif (!isset($_REQUEST['CompanyName']) || $_REQUEST['CompanyName']['like'] == '') { $_REQUEST['CompanyName']['not_empty'] = true; } $userGroupSid = SJB_UserGroupManager::getUserGroupSIDByID('Employer'); $userGroupFields = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($userGroupSid); foreach ($userGroupFields as $key => $userGroupField) { if ($userGroupField['type'] == 'location') { $userGroupFields[$key]['fields'] = array(); $userGroupFields[$key]['fields'][$userGroupField['sid']] = $userGroupField; } } $user = new SJB_User(array(), $userGroupSid); $_REQUEST['active']['equal'] = 1; $search_form_builder = new SJB_SearchFormBuilder($user); $criteria_saver = new SJB_UserCriteriaSaver($searchId); $criteria_saver->setSessionForOrderInfo($_REQUEST); if (isset($_REQUEST['searchId'])) { $action = 'search'; $criteria = $criteria_saver->getCriteria(); if (!empty($_REQUEST['sorting_field'])) { unset($criteria['sorting_field']); } else { $orderInfo = $criteria_saver->getOrderInfo(); if (!empty($orderInfo['sorting_order'])) { $criteria['sorting_order'] = $orderInfo['sorting_order']; } } $_REQUEST = array_merge($_REQUEST, $criteria); if (!$items_per_page) { $items_per_page = $criteria_saver->listings_per_page; } } $items_per_page = $items_per_page ? $items_per_page : 10; $criteria = $search_form_builder->extractCriteriaFromRequestData(array_merge($_REQUEST, array('username' => array('not_equal' => 'jobg8'))), $user); if ($items_per_page) { $criteria_saver->setSessionForListingsPerPage($items_per_page); } $search_form_builder->setCriteria($criteria); $search_form_builder->registerTags($tp); $form_fields = $search_form_builder->getFormFieldsInfo(); $tp->assign('form_fields', $form_fields); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields))); $tp->assign('userGroupFields', $userGroupFields); $tp->assign('action', $action); $tp->assign('alphabets', $abArr); if ($action == 'search') { $sorting_field = SJB_Request::getVar('sorting_field', false); $sorting_order = SJB_Request::getVar('sorting_order', false); if (isset($_REQUEST['searchId']) && !$sorting_field) { $order_info = $criteria_saver->order_info; if ($order_info) { $sorting_field = $order_info['sorting_field']; $sorting_order = $order_info['sorting_order']; } } if (!$sorting_field) { $sorting_field = 'CompanyName'; $sorting_order = 'ASC'; } $inner_join = array(); if ($sorting_field == 'number_of_jobs') { if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid) == 1) { $count = "sum( if( `listings`.`status` = 'approved', `listings`.`active`, 0 ) )"; } else { $count = "sum(`listings`.`active`)"; } $inner_join = array('listings' => array('sort_field' => $count, 'noPresix' => true, 'join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'LEFT JOIN', 'groupBy' => '`users`.`sid`')); } elseif ($sorting_field == 'Location_State') { $inner_join = array('states' => array('sort_field' => 'state_name', 'noPresix' => true, 'join_field' => 'sid', 'join_field2' => 'Location_State', 'join' => 'LEFT JOIN')); } $searcher = new SJB_UserSearcher(false, $sorting_field, $sorting_order, $inner_join, array('limit' => ($page - 1) * $items_per_page, 'num_rows' => $items_per_page)); $found_users = array(); $found_users_sids = array(); $found_users_by_criteria = $searcher->getObjectsByCriteria($criteria, null, array(), true); $foundObjectSIDs = $searcher->getFoundObjectSIDs(); // display search form $tp->display($template); $criteria_saver->setSession($_REQUEST, $foundObjectSIDs); if (count($foundObjectSIDs) > 0) { $listingType = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_type_sid); $countListings = SJB_ListingDBManager::getActiveAndApproveJobsNumberForUsers($foundObjectSIDs, $listingType); } foreach ($found_users_by_criteria as $id => $user) { $listingsNumber = isset($countListings[$id]) ? $countListings[$id] : 0; $user->addProperty(array('id' => 'countListings', 'type' => 'string', 'value' => $listingsNumber)); if ($user->getProperty('CompanyName')) { $found_users_sids[$user->getSID()] = $user->getSID(); $found_users[$id] = $user; } } $usersCount = $searcher->getAffectedRows(); $form_collection = new SJB_FormCollection($found_users); $form_collection->registerTags($tp); $pages = array(); for ($i = $page - 3; $i < $page + 3; $i++) { if ($i > 0) { $pages[] = $i; } if ($i * $items_per_page > $usersCount) { break; } } $totalPages = ceil($usersCount / $items_per_page); if (empty($totalPages)) { $totalPages = 1; } if (array_search(1, $pages) === false) { array_unshift($pages, 1); } if (array_search($totalPages, $pages) === false) { array_push($pages, $totalPages); } $tp->assign("sorting_order", $sorting_order); $tp->assign("sorting_field", $sorting_field); $tp->assign("found_users_sids", $found_users_sids); $tp->assign("companies_per_page", $items_per_page); $tp->assign("searchId", $searchId); $tp->assign("usersCount", $usersCount); $tp->assign("current_page", $page); $tp->assign("pages_number", $totalPages); $tp->display('search_result_company.tpl'); } else { // display search form $tp->display($template); } }
private function redirectToListingByKeywords() { $arrayKeywords = SJB_Request::getVar('keywords'); if (empty($arrayKeywords)) { return; } $keywords = array_pop($arrayKeywords); if (empty($keywords)) { return; } $id_listing = intval($keywords); if ($id_listing == 0) { return; } $listing_info = SJB_ListingDBManager::getListingInfoBySID($id_listing); if (empty($listing_info)) { return; } $type = SJB_ListingTypeDBManager::getListingTypeInfoBySID($listing_info['listing_type_sid']); $listing_type = $type['id']; $arrayType = SJB_Request::getVar('listing_type'); if (empty($arrayType)) { return; } $expected_type = array_pop($arrayType); if ($expected_type != $listing_type) { return; } $id = $listing_info['sid']; $name_listing = SJB_HelperFunctions::slugify($listing_info['Title']); $type = strtolower($listing_type); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/display-{$type}/{$id}/{$name_listing}.html"); }
/** * Save listing keyword * * @param string $keyword * @param int $listing_sid * @param bool $active */ public static function saveListingKeyword($keyword, $listing_sid, $active = false) { if (!empty($keyword) && !SJB_ListingDBManager::isKeywordExistsByListingSID($listing_sid, $keyword)) { SJB_DB::query('INSERT INTO `listings_keywords` (`keywords`, `listing_sid`, `active`) VALUES (?s, ?n, ?n)', $keyword, $listing_sid, $active); } }
/** * Returns quick statistics for employer: current live jobs, jobs posted this month, * job views this month, applications received this month * @param $userSID * @return array */ public static function getEmployerQuickStatistics($userSID) { $where = ' AND `s`.`date` >= FROM_DAYS(TO_DAYS(CURDATE()) - DAYOFMONTH(CURDATE()) + 1)'; $subQuery = "SELECT `l`.`sid` FROM `listings` `l` WHERE `l`.`user_sid` = ?n\n\t\t\t\t\t UNION ALL\n\t\t\t\t\t SELECT `st`.`object_sid` FROM `statistics` `st` WHERE `st`.`user_sid` = ?n AND `st`.`event` = 'deleteListing'"; $quickStats = SJB_DB::query("\n\t\t\tSELECT IFNULL(SUM(`quickStats`.`countPostedListings`),0) AS `countPostedListings`,\n\t\t\tIFNULL(SUM(`quickStats`.`countViewedListings`),0) AS `countViewedListings`, IFNULL(SUM(`quickStats`.`countApplications`),0) AS `countApplications`\n\t\t\tFROM (\n\t\t\t\tSELECT SUM(`s`.`count`) AS `countPostedListings`, 0 AS `countViewedListings`, 0 AS `countApplications`\n\t\t\t\tFROM `statistics` `s`\n\t\t\t\tWHERE `s`.`user_sid` = ?n AND `s`.`event` = 'addListing' AND `s`.`type`= 6 {$where} GROUP BY `s`.`user_sid`\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT 0 AS `countPostedListings`, SUM(`s`.`count`) AS `countViewedListings`, 0 AS `countApplications`\n\t\t\t\tFROM `statistics` `s`\n\t\t\t\tWHERE `s`.`event` = 'viewListing' AND `s`.`type`= 6 {$where} AND `s`.`object_sid` IN ( {$subQuery})\n\t\t\t\tGROUP BY `s`.`user_sid`\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT 0 AS `countPostedListings`, 0 AS `countViewedListings`, SUM(`s`.`count`) AS `countApplications`\n\t\t\t\tFROM `statistics` `s`\n\t\t\t\tWHERE `s`.`event` = 'apply' {$where} AND `s`.`type` IN ({$subQuery})\n\t\t\t\tGROUP BY `s`.`user_sid`\n\t\t\t) AS quickStats", $userSID, $userSID, $userSID, $userSID, $userSID); $quickStats = array_pop($quickStats); $quickStats['countActiveListings'] = SJB_ListingDBManager::getActiveAndApproveListingsNumberByUserSID($userSID); return $quickStats; }