Example #1
0
/**
 * Returns whether a user can manage contacts.
 * If groups are checked, one true permission makes the function return true.
 *
 * @param User $user
 * @param boolean $include_groups states whether groups should be checked for permissions
 * @return boolean
 */
function can_manage_contacts(User $user, $include_groups = true)
{
    if ($user->isGuest()) {
        return false;
    }
    if ($user->getCanManageContacts()) {
        return true;
    }
    if ($include_groups) {
        $user_ids = $user->getId();
        $group_ids = GroupUsers::getGroupsCSVsByUser($user_ids);
        if ($group_ids != '') {
            $gr = Groups::findOne(array('conditions' => array('id in (' . $group_ids . ') AND can_manage_contacts = true ')));
            return $gr instanceof Group;
        }
    }
    return false;
}