function checkPermission($userPerm,$servicePerm)
{
if( !$userPerm || !$servicePerm ) return false;
if(!preg_match("/^[0-9]+$/",(string) $userPerm) || !preg_match("/^[0-9]+$/",(string) $servicePerm)) return false;
if( $userPerm==$servicePerm ) return true;
$i=0;
$tempPerm=0;
do {
$tempPerm= pow(2, $i++); // permission 값 임시 저장 1,2,4,8,16
$sumPerm += $tempPerm; // permission 합계 1,3,7,25
if( $sumPerm <= $userPerm ) $arrayPerm[$tempPerm] = true; // permission 검증값
else break;
} while (true);
return @$arrayPerm[$servicePerm];
}
function makePlusPermission($arrayPerm=array(),$perm=0)
{
if( $arrayPerm ) {
$add=@array_shift($arrayPerm);
if(!preg_match("/^[0-9]+$/",(string)$add)) $add=0;
$perm+=$add;
return makePlusPermission($arrayPerm,$perm);
}
$retVal = ((int)$arrayPerm+(int)$perm);//PHP_INT_MAX
return ($retVal < 0 ? 0 : $retVal);
}
function makeRejectPermission($rejectPerm=array(), $perm=0)
{
if( $rejectPerm ) {
$minus=@array_shift($rejectPerm);
if(!preg_match("/^[0-9]+$/",(string)$minus)) $minus=0;
$perm-=$minus;
echo '$perm = '.$perm. ',$minus = ' .$minus. '<br/>';
return makeRejectPermission($rejectPerm,$perm);
}
$retVal = ((int)$rejectPerm+(int)$perm);//PHP_INT_MAX
return ($retVal < 0 ? 0 : $retVal);
}
// 퍼미션 변수
$writePost = 1;
$readPost = 2;
$deletePost = 4;
$addUser = 8;
$deleteUser = 16;
$perm["access"] = 1;
$perm["list"] = 2;
$perm["list_more"] = 4;
$perm["read"] = 8;
$perm["read_more"] = 16;
$perm["delete"] = 32;
$perm["delete_more"] = 64;
$perm["modify"] = 128;
$perm["modify_more"] = 256;
$perm["upload"] = 512;
$perm["upload_more"] = 1024;
$perm["down"] = 2048;
$perm["down_more"] = 4096;
$perm["write"] = 8192;
$perm["write_more"] = 16384;
$perm["find"] = 32768;
$perm["find_more"] = 65536;
// 131072,262144,524288,1048576,2097152,4194304,8388608
//조직도.권한 <1,2,4,8,16,32,64,128,256,512>
//org_chart_user_access,org_chart_group_acces
// 그룹 퍼미션 갱신
$administrator = makePlusPermission( array( $writePost, $readPost, $deletePost, $addUser, $deleteUser ) );
$administrator_modify = makeRejectPermission( array( $deleteUser ),$administrator );
$moderator = makePlusPermission( array( $readPost, $deletePost, $deleteUser ) );
$writer = makePlusPermission( array( $writePost , $readPost ) );
$guest = makePlusPermission( array( $readPost ) );
if( checkPermission($administrator, $deleteUser) ) {
echo '<br/>';
echo("Login administrator - Access organization Listen Function". '<br>');
}
if( checkPermission($administrators, $deleteUser) ) {
echo '<br/>';
echo("Login administrator - Access organization Listen Function". '<br>');
}else {
echo '<br/>';
echo("Login administrator - Error Access organization Listen Function". '<br>');
}
echo '$administrator = ' . $administrator. '<br>' ;
echo '$administrator_modify = ' . $administrator_modify ;
//printing
$perm = 15,
$minus = 16
Login administrator - Access organization Listen Function
Login administrator - Error Access organization Listen Function
$administrator = 31
$administrator_modify = 15
// Good luck, lock.......