IncludeModuleLangFile(__FILE__);
class CMedialib
{
private static
$bCache = true,
$cacheTime = 360000,
$cachePath = "medialib/";
public static function Init(){}
public static function GetOperations($collectionId, $menu = false)
{
global $USER;
static $oCollections;
static $arOp;
$userGroups = $USER->GetUserGroupArray();
$key = $collectionId.'|'.implode('-', $userGroups);
if (!is_array($arOp[$key]))
{
if (!is_array($arOp))
$arOp = array();
if (!is_array($oCollections))
{
$res = CMedialib::GetCollectionTree(array('menu' => $menu));
$oCollections = $res['Collections'];
}
$userGroups = $USER->GetUserGroupArray();
$res = CMedialib::GetAccessPermissionsArray($collectionId, $oCollections);
$arOp[$key] = array();
foreach ($res as $group_id => $task_id)
{
if (in_array($group_id, $userGroups))
$arOp[$key] = array_merge($arOp[$key], CTask::GetOperations($task_id, true));
}
}
return $arOp[$key];
}
public static function CanDoOperation($operation, $collectionId=0, $userId = false, $menu = false)
{
if ($GLOBALS["USER"]->IsAdmin())
return true;
$arOp = CMedialib::GetOperations($collectionId, $menu);
return in_array($operation, $arOp);
}
public static function GetAccessPermissionsArray($collectionId = 0, $oCollections = false)
{
static $arAllTasks;
if (is_array($arAllTasks[$collectionId]))
return $arAllTasks[$collectionId];
$col = $oCollections[$collectionId];
$arCols = array();
$resTask = array();
if ($col || $collectionId == 0)
{
$arCols[] = $collectionId;
if (intval($col['PARENT_ID']) > 0)
{
$col_ = $col;
while($col_ && intval($col_['PARENT_ID']) > 0)
{
$arCols[] = $col_['PARENT_ID'];
$col_ = $oCollections[$col_['PARENT_ID']];
}
}
$arCols[] = 0;
$arPerm = CMedialib::_GetAccessPermissions($arCols);
for($i = count($arCols); $i >= 0; $i--)
{
$colId = $arCols[$i];
if (is_array($arPerm[$colId]))
{
for ($j = 0, $n = count($arPerm[$colId]); $j < $n; $j++)
$resTask[$arPerm[$colId][$j]['GROUP_ID']] = $arPerm[$colId][$j]['TASK_ID'];
}
}
}
if (!is_array($arAllTasks))
$arAllTasks = array();
$arAllTasks[$collectionId] = $resTask;
return $resTask;
}
public static function _GetAccessPermissions($arCols = array())
{
global $DB;
$s = '0';
for($i = 0, $l = count($arCols); $i < $l; $i++)
$s .= ",".intval($arCols[$i]);
$strSql = 'SELECT *
FROM b_group_collection_task GCT
WHERE GCT.COLLECTION_ID in ('.$s.')';
$res = $DB->Query($strSql , false, "File: ".__FILE__."
Line: ".__LINE__);
$arResult = array();
while($arRes = $res->Fetch())
{
$colid = $arRes['COLLECTION_ID'];
if (!is_array($arResult[$colid]))
$arResult[$colid] = array();
unset($arRes['COLLECTION_ID']);
$arResult[$colid][] = $arRes;
}
return $arResult;
}
public static function getMaximumFileUploadSize()
{
return min(CUtil::Unformat(ini_get('post_max_size')), CUtil::Unformat(ini_get('upload_max_filesize')));
}
public static function ShowDialogScript($arConfig = array())
{
global $USER;
CUtil::InitJSCore(array('ajax'));
$strWarn = '';
$arConfig['bReadOnly'] = false;
$arConfig['lang'] = LANGUAGE_ID;
$event = '';
if (isset($arConfig['event']))
$event = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['event']);
if ($event == '')
$strWarn .= GetMessage('ML_BAD_EVENT').'. ';
$resultDest = "";
$bDest = is_array($arConfig['arResultDest']);
if ($bDest)
{
if (isset($arConfig['arResultDest']["FUNCTION_NAME"]))
{
$arConfig['arResultDest']["FUNCTION_NAME"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["FUNCTION_NAME"]);
$bDest = $arConfig['arResultDest']["FUNCTION_NAME"] <> '';
$resultDest = "FUNCTION";
}
elseif (isset($arConfig['arResultDest']["FORM_NAME"], $arConfig['arResultDest']["FORM_ELEMENT_NAME"]))
{
$arConfig['arResultDest']["FORM_NAME"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["FORM_NAME"]);
$arConfig['arResultDest']["FORM_ELEMENT_NAME"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["FORM_ELEMENT_NAME"]);
$bDest = $arConfig['arResultDest']["FORM_NAME"] <> '' && $arConfig['arResultDest']["FORM_ELEMENT_NAME"] <> '';
$resultDest = "FORM";
}
elseif (isset($arConfig['arResultDest']["ELEMENT_ID"]))
{
$arConfig['arResultDest']["ELEMENT_ID"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["ELEMENT_ID"]);
$bDest = $arConfig['arResultDest']["ELEMENT_ID"] <> '';
$resultDest = "ID";
}
else
{
$bDest = false;
}
}
if (!$bDest)
$strWarn .= GetMessage('ML_BAD_RETURN').'. ';
if ($strWarn == '')
{
?>