- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
function SetFileAccessPermission($path, $arPermissions, $bOverWrite=true)
	{
		CMain::InitPathVars($site, $path);
		$DOC_ROOT = CSite::GetSiteDocRoot($site);
		if(strlen($path) <= 0)
			$path="/";
		if(($p = bxstrrpos($path, "/"))!==false)
		{
			$path_file = substr($path, $p+1);
			$path_dir = substr($path, 0, $p);
		}
		else
			return false;
		if($path_file=="" && $path_dir=="")
			$path_file = "/";
		$PERM = Array();
		if(file_exists($DOC_ROOT.$path_dir."/.access.php"))
			@include($DOC_ROOT.$path_dir."/.access.php");
		
		$FILE_PERM = $PERM[$path_file];
		if(!is_array($FILE_PERM))
			$FILE_PERM=Array();
		if(!$bOverWrite && count($FILE_PERM)>0)
			return true;
		$bDiff = false;
		$str="<?\n";
		foreach($arPermissions as $group=>$perm)
		{
			if(strlen($perm) > 0)
				$str.="\$PERM[\"".$path_file."\"][\"".$group."\"]=\"".str_replace("\"", "\\\"", $perm)."\";\n";
			if(!$bDiff && $FILE_PERM[$group]!=$perm)
				$bDiff=true;
		}
		foreach($PERM as $file=>$arPerm)
		{
			if(strval($file) !==$path_file)
				foreach($arPerm as $group=>$perm)
					$str.="\$PERM[\"".$file."\"][\"".$group."\"]=\"".str_replace("\"", "\\\"", $perm)."\";\n";
		}
		if(!$bDiff)
		{
			foreach($FILE_PERM as $group=>$perm)
				if($arPermissions[$group]!=$perm)
				{
					$bDiff==true;
					break;
				}
		}
		$str.="?".">";
		
		$this->SaveFileContent($DOC_ROOT.$path_dir."/.access.php", $str);
		$GLOBALS["CACHE_MANAGER"]->CleanDir("menu");
		unset($this->FILE_PERMISSION_CACHE[$site."|".$path_dir."/.access.php"]);
		
		if($bDiff)
		{
			$db_events = GetModuleEvents("main", "OnChangePermissions");
			while($arEvent = $db_events->Fetch())
				ExecuteModuleEvent($arEvent, Array($site, $path), $arPermissions);
		}
		return true;
	}