public static function isUserAccessThisPage() { $pageID = SJB_PageManager::getPageParentURI(SJB_Navigator::getURI(), SJB_System::getSystemSettings('SYSTEM_ACCESS_TYPE'), false); $access = true; $currentUser = SJB_UserManager::getCurrentUser(); if (!is_null($currentUser)) { $access = false; $queryParam = ''; $listingId = SJB_Request::getVar("listing_id", false); $passedParametersViaUri = SJB_Request::getVar("passed_parameters_via_uri", false); if (!$listingId && $passedParametersViaUri) { $passedParametersViaUri = SJB_UrlParamProvider::getParams(); $listingId = isset($passedParametersViaUri[0]) ? $passedParametersViaUri[0] : ''; } if ($listingId) { $queryParam = " AND `param` = '" . SJB_DB::quote($listingId) . "' "; } $pageHasBeenVisited = SJB_DB::query("SELECT `param` FROM `page_view` WHERE `id_user` = ?s AND `id_pages` = ?s {$queryParam}", $currentUser->getSID(), $pageID); if (!empty($queryParam) && $pageHasBeenVisited || strpos($pageID, 'print') !== false) { $access = true; } else { $contractsId = $currentUser->getContractID(); $pageAccess = SJB_ContractManager::getPageAccessByUserContracts($contractsId, $pageID); $numberOfPagesViewed = SJB_ContractManager::getNumbeOfPagesViewed($currentUser->getSID(), $contractsId, $pageID); if (isset($pageAccess[$pageID]) && $pageAccess[$pageID]['count_views'] != '') { if ($numberOfPagesViewed < $pageAccess[$pageID]['count_views']) { $access = true; } if ($access === true) { $listingTypeSID = null; if (is_numeric($listingId)) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); if ($listingInfo) { $listingTypeSID = $listingInfo['listing_type_sid']; } } $availableContractId = ''; foreach ($contractsId as $contractId) { $pageAccessByContract = SJB_ContractManager::getPageAccessByUserContracts(array($contractId), $pageID); $viewsLeft = SJB_ContractManager::getNumbeOfPagesViewed($currentUser->getSID(), array($contractId), false, $listingTypeSID); if (!empty($pageAccessByContract[$pageID]['count_views']) && $pageAccessByContract[$pageID]['count_views'] > $viewsLeft) { $availableContractId = $contractId; } } if (!empty($availableContractId)) { SJB_DB::query("INSERT INTO page_view (`id_user` ,`id_pages`, `param`, `contract_id`, `listing_type_sid`) VALUES ( ?n, ?s, ?s, ?n, ?n)", $currentUser->getSID(), $pageID, $listingId, $availableContractId, $listingTypeSID); } else { $access = false; } } } else { $access = true; } } } return $access; }