<?php
{
public function IsBaseAccess ($in_bitmaskRequested, $isUseCache =
false, $checkForAuthor =
false);
public function IsLessonAccessible ($in_lessonId, $in_bitmaskOperations, $isUseCache =
false);
}
{
'lesson_read' => self::OP_LESSON_READ,
'lesson_create' => self::OP_LESSON_CREATE,
'lesson_write' => self::OP_LESSON_WRITE,
'lesson_remove' => self::OP_LESSON_REMOVE,
'lesson_link_to_parents' => self::OP_LESSON_LINK_TO_PARENTS,
'lesson_unlink_from_parents' => self::OP_LESSON_UNLINK_FROM_PARENTS,
'lesson_link_descendants' => self::OP_LESSON_LINK_DESCENDANTS,
'lesson_unlink_descendants' => self::OP_LESSON_UNLINK_DESCENDANTS,
'lesson_manage_rights' => self::OP_LESSON_MANAGE_RIGHTS
);
private function __construct($in_userId)
{
}
{
if ( ! array_key_exists(
$userId, self::$instanceOfSelf) )
return (self::$instanceOfSelf[
$userId]);
}
{
{
}
else
}
{
$row = $rc->Fetch();
if ( ! isset($row['NAME']) )
{
throw new LearnException ('EA_NOT_EXISTS',
}
$nameUpperCase = mb_strtoupper($row['NAME']);
}
{
$arPossibleRights =
array();
while ($row = $rc->Fetch())
{
$nameUpperCase = mb_strtoupper($row['NAME']);
$arPossibleRights[$row[
'ID']] =
array(
'name' => $row['NAME'],
'sys' => $row['SYS'],
'description' => $row['DESCRIPTION'],
'binding' => $row['BINDING']
);
}
return ($arPossibleRights);
}
{
static $cacheSymbols =
array();
if ( ! (is_int($in_bitmaskOperations) && ($in_bitmaskOperations > 0)) )
{
throw new LearnException ('bitmask must be an integer > 0',
}
$lessonId = (int) $in_lessonId;
$cacheKey = 'k' . $in_lessonId . '|' . $in_bitmaskOperations;
if ( ! ($isUseCache && isset($cacheSymbols[$cacheKey])) )
{
"SELECT TLR.SUBJECT_ID AS SYMBOLS
FROM b_learn_rights TLR
INNER JOIN b_task_operation TTO
ON TTO.TASK_ID = TLR.TASK_ID
INNER JOIN b_operation XTO
ON XTO.ID = TTO.OPERATION_ID
WHERE TLR.LESSON_ID = " . $lessonId . "
AND XTO.MODULE_ID = 'learning'
AND XTO.NAME IN (" . $sqlOperationsNames . ")
UNION
SELECT TLRA.SUBJECT_ID AS SYMBOLS
FROM b_learn_rights_all TLRA
INNER JOIN b_task_operation TTO
ON TTO.TASK_ID = TLRA.TASK_ID
INNER JOIN b_operation XTO
ON XTO.ID = TTO.OPERATION_ID
WHERE XTO.MODULE_ID = 'learning'
AND XTO.NAME IN (" . $sqlOperationsNames . ")
", true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR',
}
while ($row = $rc->Fetch())
$arSymbols[] = $row['SYMBOLS'];
$cacheSymbols[$cacheKey] = $arSymbols;
}
return ($cacheSymbols[$cacheKey]);
}
{
return ($this->
IsBaseAccess ($in_bitmaskRequested, $isUseCache,
true));
}
public function IsBaseAccess ($in_bitmaskRequested, $isUseCache =
false, $checkForAuthor =
false)
{
&& ( $this->userId === ((
int)
$USER->GetID()) )
)
{
return (true);
}
{
return (true);
}
if ( ! (is_int($in_bitmaskRequested) && ($in_bitmaskRequested > 0)) )
{
throw new LearnException ('bitmask must be an integer > 0',
}
$bitmaskRequested = $in_bitmaskRequested;
if ($checkForAuthor)
$arUserAccessSymbols[] = 'CR';
if ( ($bitmaskRequested & $bitmaskBaseAccess) === $bitmaskRequested )
return (true);
else
return (false);
}
{
if ( ! is_array($in_arPermPairs) )
{
throw new LearnException ('',
}
foreach ($in_arPermPairs as $in_subject_id => $in_task_id)
{
$subject_id =
$DB->ForSQL($in_subject_id);
$arPermPairs[$subject_id] = $task_id;
}
if ( ! (self::IsLoggedUserCanAccessModuleSettings()
&& ( ((
int)
$USER->GetID()) === $this->userId) )
)
{
throw new LearnException ('',
}
"DELETE FROM b_learn_rights_all
WHERE 1=1", true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR',
}
foreach ($arPermPairs as $subject_id => $task_id)
{
"INSERT INTO b_learn_rights_all (SUBJECT_ID, TASK_ID)
VALUES ('" . $subject_id . "', " . $task_id . ")", true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR',
}
}
}
{
"SELECT SUBJECT_ID, TASK_ID
FROM b_learn_rights_all
WHERE 1=1");
if ($rc === false)
{
throw new LearnException('EA_SQLERROR',
}
while ($row = $rc->Fetch())
$arPermPairs[$row['SUBJECT_ID']] = (int) $row['TASK_ID'];
return ($arPermPairs);
}
{
"SELECT LESSON_ID, SUBJECT_ID, TASK_ID
FROM b_learn_rights
WHERE LESSON_ID = " . $lessonId . "
");
if ($rc === false)
{
throw new LearnException('EA_SQLERROR',
}
while ($row = $rc->Fetch())
$arPermPairs[$row['SUBJECT_ID']] = (int) $row['TASK_ID'];
return ($arPermPairs);
}
{
if ( ! is_array($in_arPermissions) )
{
throw new LearnException ('',
}
$isUseCacheForRights = false;
$arPermissions =
array();
foreach ($in_arPermissions as $in_lessonId => $arPermPairs)
{
if ( ! is_array($arPermPairs) )
{
throw new LearnException ('',
}
if ( ! $this->
IsLessonAccessible($lesson_id, self::OP_LESSON_MANAGE_RIGHTS, $isUseCacheForRights) )
$isUseCacheForRights = true;
$arPermissions[$lesson_id] =
array();
foreach ($arPermPairs as $in_subject_id => $in_task_id)
{
$subject_id =
$DB->ForSQL($in_subject_id);
$arPermissions[$lesson_id][$subject_id] = $task_id;
}
}
foreach ($arPermissions as $lesson_id => $arPermPairs)
{
$subject_id = $arPerm[0];
$task_id = $arPerm[1];
"DELETE FROM b_learn_rights
WHERE LESSON_ID = $lesson_id", true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR',
}
foreach ($arPermPairs as $subject_id => $task_id)
{
"INSERT INTO b_learn_rights (LESSON_ID, SUBJECT_ID, TASK_ID)
VALUES (" . $lesson_id . ", '" . $subject_id . "', " . $task_id . ")", true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR',
}
}
}
}
public function IsLessonAccessible ($in_lessonId, $in_bitmaskOperations, $isUseCache =
false)
{
static $cacheArIds =
array();
$lessonId = intval($in_lessonId);
$cacheKey = $in_bitmaskOperations."_".$lessonId;
if ($isUseCache && array_key_exists($cacheKey, $cacheArIds))
{
return true;
}
return array_key_exists($cacheKey, $cacheArIds);
}
{
$rc =
$DB->Query($sql,
true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR',
}
while ($row = $rc->Fetch())
$arIds[$in_bitmaskOperations."_".$row['LESSON_ID']] = (int) $row['LESSON_ID'];
return ($arIds);
}
{
if ( ! (is_int($in_bitmaskOperations) && ($in_bitmaskOperations > 0)) )
{
throw new LearnException ('bitmask must be an integer > 0',
}
$prfx =
$DB->ForSQL ($in_prfx);
$userAccessSymbols = 'NULL';
if (
count($arUserAccessSymbols) > 0)
$bitmaskOperationsForAny = $in_bitmaskOperations & ( ~ $bitmaskAvailOperationsForAny );
$bitmaskOperationsForCR = $in_bitmaskOperations & ( ~ $bitmaskAvailOperationsForCR );
$sqlOperationsForAny = false;
$sqlOperationsForCR = false;
if ($bitmaskOperationsForAny !== 0)
if ($bitmaskOperationsForCR !== 0)
if ($sqlOperationsForCR !== false)
$arSqlWhere[] = "(${prfx}TLR.SUBJECT_ID = 'CR' AND ${prfx}TLL.CREATED_BY = $userId AND ${prfx}XTO.NAME IN ($sqlOperationsForCR))";
else
$arSqlWhere[] = "(${prfx}TLL.CREATED_BY = $userId)";
if ($sqlOperationsForAny !== false)
$arSqlWhere[] = "(${prfx}TLR.SUBJECT_ID IN ($userAccessSymbols) AND ${prfx}XTO.NAME IN ($sqlOperationsForAny))";
else
$arSqlWhere[] = "(1=1)";
$sqlWhere = implode("\n OR \n", $arSqlWhere);
$lessonId = intval($lessonId);
if ($lessonId > 0)
{
$sqlWhere = "${prfx}TLL.ID={$lessonId} AND (".$sqlWhere.")";
}
$sql = "SELECT ${prfx}TLL.ID AS LESSON_ID
FROM b_learn_lesson ${prfx}TLL
LEFT OUTER JOIN b_learn_rights ${prfx}TLR
ON ${prfx}TLL.ID = ${prfx}TLR.LESSON_ID
LEFT OUTER JOIN b_task_operation ${prfx}TTO
ON ${prfx}TLR.TASK_ID = ${prfx}TTO.TASK_ID
LEFT OUTER JOIN b_operation ${prfx}XTO
ON ${prfx}TTO.OPERATION_ID = ${prfx}XTO.ID
WHERE
$sqlWhere";
return ($sql);
}
{
if (!is_array($arUserAccessSymbols) ||
count($arUserAccessSymbols) < 1)
{
return 0;
}
if (isset($cache[$userAccessSymbols]))
{
return $cache[$userAccessSymbols];
}
"SELECT XTO.NAME AS OPERATION_NAME
FROM b_learn_rights_all TLRA
INNER JOIN b_task_operation TTO
ON TTO.TASK_ID = TLRA.TASK_ID
INNER JOIN b_operation XTO
ON XTO.ID = TTO.OPERATION_ID
WHERE TLRA.SUBJECT_ID IN ($userAccessSymbols)",
true);
if ($rc === false)
{
throw new LearnException ('EA_SQLERROR: ',
}
$bitmaskOperations = 0;
while ($arData = $rc->Fetch())
{
if ( ! isset(self::$arOperations[$arData['OPERATION_NAME']]) )
{
throw new LearnException ('Unknown operation: ' . $arData['OPERATION_NAME'],
}
$bitmaskOperations = $bitmaskOperations | self::$arOperations[$arData['OPERATION_NAME']];
}
$cache[$userAccessSymbols] = $bitmaskOperations;
return ($bitmaskOperations);
}
{
static $determinedCache =
array();
if ( ! (is_int($in_operations) && ($in_operations > 0)) )
$cacheKey = 'str' . $in_operations;
if ( ! isset ($determinedCache[$cacheKey]) )
{
foreach (self::$arOperations as $operationName => $operationBitFlag)
{
if ($in_operations & $operationBitFlag)
{
$in_operations -= $operationBitFlag;
}
}
if ($in_operations !== 0)
$determinedCache[$cacheKey] = $sql;
}
return ($determinedCache[$cacheKey]);
}
{
if ($isUseCache && isset($cache['str' . $this->userId]))
return ($cache['str' . $this->userId]);
return ($sql);
}
{
$isNeedCAccessUpdate = true;
if ($isUseCache)
{
if (isset($cache['str' . $this->userId]))
return ($cache['str' . $this->userId]);
if ( (static::$CAccessLastUpdated === false)
|| ( (microtime(true) - static::$CAccessLastUpdated) > 3 )
)
{
$isNeedCAccessUpdate = true;
}
else
$isNeedCAccessUpdate = false;
}
else
$isNeedCAccessUpdate = true;
if ($isNeedCAccessUpdate)
{
$oAcc = new CAccess();
$oAcc->UpdateCodes();
if ($isUseCache)
static::$CAccessLastUpdated = microtime(true);
unset ($oAcc);
}
if ($rc === false)
{
throw new LearnException('',
}
while ($arItem = $rc->Fetch())
{
if ( ( (int) $arItem['USER_ID'] ) !== $this->userId )
{
throw new LearnException('',
}
$arData[] = $arItem['ACCESS_CODE'];
}
if ( is_object(
$USER) && ( $this->userId === ((
int)
$USER->GetID()) ) )
$arData[] = 'AU';
return ($arData);
}
{
$arData = array_map (
array(
'CLearnAccess',
'EscapeAndAddLateralQuotes'), $in_arData);
$sql = implode(',', $arData);
return ($sql);
}
{
return (
"'" .
$DB->ForSQL($txt) .
"'");
}
{
return (true);
else
return (false);
}
{
if ( ! preg_match(
"/^[0-9]+$/", (
string)
$var) )
{
throw new LearnException(
'EA_PARAMS: can\'t b strictly casted to integer, but expected: ' .
$var,
}
}
}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static GetUserCodes($USER_ID, $arFilter=[], bool $updateCodes=true)
static GetLangTitle($name, $module="main")
static GetLangDescription($name, $desc, $module="main")
static GetList($arOrder=['MODULE_ID'=> 'asc', 'LETTER'=> 'asc'], $arFilter=[])
static GetInstance($in_userId)
GetLessonPermissions($in_lessonId)
static ListAllPossibleRights()
SQLClauseForAccessibleLessons($in_bitmaskOperations, $isUseCache=false, $lessonId=0, $in_prfx='DEFPRFX')
IsLessonAccessible($in_lessonId, $in_bitmaskOperations, $isUseCache=false)
static StrictlyCastToInteger($var)
IsBaseAccessForCR($in_bitmaskRequested, $isUseCache=false)
static IsLoggedUserCanAccessModuleSettings()
static GetAccessSymbolsHashForSiteUser()
static EscapeAndAddLateralQuotes($txt)
GetAccessCodes($isUseCache=false)
const OP_LESSON_UNLINK_FROM_PARENTS
const OP_LESSON_MANAGE_RIGHTS
GetAccessCodesForSQL($isUseCache=false)
static $CAccessLastUpdated
const OP_LESSON_LINK_DESCENDANTS
GetBitmaskOperationsForAllLessons($arUserAccessSymbols)
const OP_LESSON_UNLINK_DESCENDANTS
GetAccessibleLessonsList($in_bitmaskOperations, $isUseCache=false, $lessonId=0)
SetBasePermissions($in_arPermPairs)
IsBaseAccess($in_bitmaskRequested, $isUseCache=false, $checkForAuthor=false)
static GetNameForTask($taskId)
static Array2CommaSeparatedListForSQL($in_arData)
static GetSymbolsAccessibleToLesson($in_lessonId, $in_bitmaskOperations, $isUseCache=false)
static ParseOperationsForSQL($in_operations)
const OP_LESSON_LINK_TO_PARENTS
SetLessonsPermissions($in_arPermissions)
const EXC_ERR_ALL_ACCESS_DENIED
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
GetLessonPermissions($in_lessonId)
static ListAllPossibleRights()
SQLClauseForAccessibleLessons($in_bitmaskOperations, $isUseCache=false, $lessonId=0, $in_prfx='DEFPRFX')
IsLessonAccessible($in_lessonId, $in_bitmaskOperations, $isUseCache=false)
IsBaseAccessForCR($in_bitmaskRequested, $isUseCache=false)
SetBasePermissions($in_arPermPairs)
GetAccessibleLessonsList($in_bitmaskOperations, $isUseCache=false)
IsBaseAccess($in_bitmaskRequested, $isUseCache=false, $checkForAuthor=false)
static GetNameForTask($taskId)
static GetSymbolsAccessibleToLesson($in_lessonId, $in_bitmaskOperations, $isUseCache=false)
SetLessonsPermissions($in_arPermissions)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"