News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1203449007:v:use_geshi-1:v:type-php

Started by SleePy, Feb 19, 2008, 07:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

// Check their permissions, gets kinda messy.
function CanDo($permission, $id_mem = false)
{
   global $user_info, $tSettings;

   // Simplify this call.
   $todo_groups = $tSettings['moderation'][$permission];

   // Can they moderate themselves?
   if(($id_mem && $id_mem == $user_info['id'] && ($tSettings['moderate_own'][0] == 0 || in_array($user_info['groups'], $tSettings['moderate_own']))) || $todo_groups[0] == 0 || $user_info['is_admin'])
      return true;

   // Load the SMF settings and loop it into a nicer array.
   $smf_groups = array();
   foreach($todo_groups as $grp)
   {
      if(isset($tSettings['groups'][$grp]))
         $smf_groups[] = $tSettings['groups'][$grp];
   }

   // Do they have any of the same groups?
   if(array_intersect($smf_groups, $user_info['groups']))
   {
      // Loop through the SMF groups.
      foreach($smf_groups as $smf_group)
      {
         // set this into the array quickly.
         $tgroup = $tSettings['groups'][$smf_group];

         // Loop through our todo groups.
         foreach($todo_groups as $thegroup)
         {
            // If we got something lets continue.
            if($thegroup == $tgroup)
            {
               // Loop through the permissions.
               foreach($tSettings['moderation'][$permission] as $tperm)
               {
                  // I told you this would get messy.
                  if($tperm == $tgroup)
                     return true;
               }
            }
         }
      }
   }
   return false;
}
No siggy! :D