Exemplo n.º 1
0
/**
 * Function to check if a user is a moderator of a forum
 */
function is_moderator($user, $forum)
{
    global $_USERGROUPS;
    if (is_a($user, 'FAUser')) {
        $user = $user->getInfoArray();
    }
    if (!is_array($user)) {
        trigger_error('Invalid $user call for is_moderator.', E_USER_ERROR);
    }
    if ($user['perms'] >= ADMIN) {
        return TRUE;
    }
    $result = explode('|', trim($forum['moderating_groups'], '|'));
    $moderators = !$result ? force_usergroups($forum['moderating_groups']) : $result;
    $groups = array();
    foreach ($moderators as $g) {
        if (isset($_USERGROUPS[$g])) {
            $groups[] = $g;
        }
    }
    if (isset($user['usergroups'])) {
        $unserialize = explode('|', trim($user['usergroups'], '|'));
        $my_groups = !$unserialize ? force_usergroups($user['usergroups']) : $unserialize;
        /* Do we toggle our moderator's panel? */
        if (is_in_group($my_groups, $groups, $user['perms'])) {
            return TRUE;
        }
    }
    if ($forum['moderating_users'] != '') {
        $users = force_unserialize($forum['moderating_users']);
        if (is_array($users)) {
            foreach ($users as $user_id => $username) {
                if ($user['name'] == $username && $user['id'] == $user_id) {
                    return TRUE;
                }
            }
        }
    }
    return FALSE;
}
Exemplo n.º 2
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS, $_PROFILEFIELDS;
     /* unset any search queries if we are about to go look at this users posts */
     unset($_SESSION['search_queries']);
     if ($request['user']->get('perms') < get_map('member_profile', 'can_view', array())) {
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $request['template']->setFile('content', '../login_form.html');
         $request['template']->setVisibility('no_perms', TRUE);
         return TRUE;
     }
     $member = $request['user_info'];
     $member['num_topics'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND poster_id = " . intval($member['id']) . " AND moved_new_post_id=0 AND is_draft=0 AND queue=0 AND display=1");
     $member['num_replies'] = $member['num_posts'] - $member['num_topics'];
     //$member['num_replies']		= $request['dba']->getValue("SELECT COUNT(*) FROM ". K4POSTS ." WHERE row_type=". REPLY ." AND poster_id = ". intval($member['id']));
     /**
      * Get and set some user/forum statistics
      */
     $num_reg_days = ceil((time() - $member['created']) / 86400);
     $postsperday = ceil($member['num_posts'] / $num_reg_days);
     $member['posts_per_day'] = sprintf($request['template']->getVar('L_POSTSPERDAY'), $postsperday);
     $num_posts = $_DATASTORE['forumstats']['num_topics'] + $_DATASTORE['forumstats']['num_replies'];
     $member['posts_percent'] = $num_posts != 0 && $member['num_posts'] != 0 ? sprintf($request['template']->getVar('L_OFTOTALPOSTS'), round($member['num_posts'] / $num_posts * 100, 3) . '%') : sprintf($request['template']->getVar('L_OFTOTALPOSTS'), '0%');
     $group = get_user_max_group($member, $_USERGROUPS);
     $member['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
     $member['group_nicename'] = $group['nicename'];
     $member['group_avatar'] = $group['avatar'];
     $member['online'] = time() - ini_get('session.gc_maxlifetime') > $member['seen'] ? 'offline' : 'online';
     $result = explode('|', $member['usergroups']);
     $groups = $member['usergroups'] != '' ? !$result ? force_usergroups($member) : $result : array();
     /**
      * Get and set the user groups for this member
      */
     $usergroups = array();
     foreach ($groups as $id) {
         if (isset($_USERGROUPS[$id]) && is_array($_USERGROUPS[$id]) && !empty($_USERGROUPS[$id])) {
             $usergroups[] = $_USERGROUPS[$id];
         }
     }
     $it =& new FAArrayIterator($usergroups);
     $request['template']->setList('member_usergroups', $it);
     foreach ($member as $key => $val) {
         $request['template']->setVar('member_' . $key, $val);
     }
     /**
      * Get the custom user fields for this member
      */
     $fields = array();
     foreach ($_PROFILEFIELDS as $field) {
         if ($field['display_profile'] == 1) {
             if (isset($member[$field['name']])) {
                 //  && $member[$field['name']] != ''
                 switch ($field['inputtype']) {
                     default:
                     case 'text':
                     case 'textarea':
                     case 'select':
                         $field['value'] = $member[$field['name']] != '' ? $member[$field['name']] : $request['template']->getVar('L_NOINFORMATION');
                         break;
                     case 'multiselect':
                     case 'radio':
                     case 'check':
                         $unserialize = @unserialize($member[$field['name']]);
                         $field['value'] = $member[$field['name']] != '' ? implode(", ", !$unserialize ? force_unserialize($member[$field['name']]) : $unserialize) : $request['template']->getVar('L_NOINFORMATION');
                         break;
                 }
                 $field['value'] = preg_replace_callback('~((https?\\:\\/\\/|ftps?\\:\\/\\/)?(?:(?:[\\w\\d\\-_\\+\\.]+\\:)?(?:[\\w\\d\\-_\\+\\.]+)?\\@)?(?:[\\w\\d][\\d_\\-\\w\\.]+\\w){2,}?\\.[\\dA-Za-z]{2,7})([\\:\\/]\\S*)?~', array(&$this, 'handleUrl'), $field['value']);
                 $fields[] = $field;
             }
         }
     }
     if (count($fields) > 0) {
         if ($fields % 2 == 1) {
             $fields[count($fields) - 1]['colspan'] = 2;
         }
         $it =& new FAArrayIterator($fields);
         $request['template']->setList('member_profilefields', $it);
     }
     /**
      * Set the info we need
      */
     $request['template']->setFile('content', 'member_profile.html');
     k4_bread_crumbs($request['template'], $dba, 'L_USERPROFILE');
     return TRUE;
 }
Exemplo n.º 3
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     if (is_a($session['user'], 'Member') && $user['perms'] >= ADMIN) {
         if (!isset($request['id']) || intval($request['id']) == 0) {
             $template->setInfo('content', $template->getVar('L_INVALIDUSERGROUP'), TRUE);
             return TRUE;
         }
         $group = $dba->getRow("SELECT * FROM " . USERGROUPS . " WHERE id = " . intval($request['id']));
         if (!is_array($group) || empty($group)) {
             $template->setInfo('content', $template->getVar('L_INVALIDUSERGROUP'), TRUE);
             return TRUE;
         }
         /* Get all users of this usergroup */
         $users =& $dba->executeQuery("SELECT * FROM " . USERS . " WHERE usergroups LIKE '%;i:" . intval($group['id']) . ";%'");
         while ($users->next()) {
             $user = $users->current();
             $groups = $user['usergroups'] != '' ? iif(!unserialize($user['usergroups']), force_usergroups($user), unserialize($user['usergroups'])) : array();
             /* Are we dealing with an array? */
             if (is_array($groups)) {
                 /* make a new array because if we unset values in the $groups array, it will kill the for() */
                 $new_groups = array();
                 /* Loop through the array */
                 for ($i = 0; $i < count($groups); $i++) {
                     /* This will remove this usergroup, and any ninexistant ones from this user's array */
                     if ($groups[$i] != $group['id'] && $groups[$i] != 0) {
                         $new_groups[] = $groups[$i];
                     }
                 }
                 /* Reset the groups variable */
                 $groups = $new_groups;
             }
             $dba->executeUpdate("UPDATE " . USERS . " SET usergroups = '" . $dba->quote($groups) . "' WHERE id = " . $user['id']);
         }
         /* Remove the usergroup */
         $dba->executeUpdate("DELETE FROM " . USERGROUPS . " WHERE id = " . intval($group['id']));
         if (!@touch(CACHE_FILE, time() - 86460)) {
             @unlink(CACHE_FILE);
         }
         $template->setInfo('content', sprintf($template->getVar('L_REMOVEDUSERGROUP'), $group['name']), FALSE);
         $template->setRedirect('admin.php?act=usergroups', 3);
     } else {
         $template->setError('content', $template->getVar('L_YOUNEEDPERMS'));
     }
     return TRUE;
 }
Exemplo n.º 4
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_USERGROUPS, $_QUERYPARAMS;
     if (!isset($request['id']) || intval($request['id']) == 0) {
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_GROUPDOESNTEXIST'));
     }
     if (!isset($_USERGROUPS[intval($request['id'])])) {
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_GROUPDOESNTEXIST'));
     }
     if (!isset($request['name']) || !$request['name'] || $request['name'] == '') {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_USERDOESNTEXIST'), TRUE);
         return TRUE;
     }
     $group = $_USERGROUPS[intval($request['id'])];
     $member = $dba->getRow("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . USERS . " u LEFT JOIN " . USERINFO . " ui ON u.id=ui.user_id WHERE u.name = '" . $dba->quote($request['name']) . "'");
     if (!$member || !is_array($member) || empty($member)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_USERDOESNTEXIST'), TRUE);
         return TRUE;
     }
     /* Should we set the group moderator? */
     if ($group['mod_name'] == '' || $group['mod_id'] == 0) {
         $admin = $dba->getRow("SELECT * FROM " . USERS . " WHERE perms >= " . intval(ADMIN) . " ORDER BY perms,id ASC LIMIT 1");
         $dba->executeUpdate("UPDATE " . USERGROUPS . " SET mod_name = '" . $dba->quote($admin['name']) . "', mod_id = " . intval($admin['id']) . " WHERE id = " . intval($group['id']));
         if (!@touch(CACHE_FILE, time() - 86460)) {
             @unlink(CACHE_FILE);
         }
         $group['mod_name'] = $admin['name'];
         $group['mod_id'] = $admin['id'];
     }
     if ($group['mod_id'] == $member['id']) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_YOUAREMODERATOR'), TRUE);
         return TRUE;
     }
     $groups = $member['usergroups'] != '' ? iif(!unserialize($member['usergroups']), force_usergroups($member), unserialize($member['usergroups'])) : array();
     $in_group = FALSE;
     foreach ($groups as $id) {
         if (isset($_USERGROUPS[$id]) && $id == $group['id']) {
             $in_group = TRUE;
         }
     }
     if ($in_group) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_BELONGSTOGROUP'), TRUE);
         return TRUE;
     }
     $groups[] = intval($group['id']);
     $extra = NULL;
     if ($user['perms'] < $group['min_perm']) {
         $extra .= ', perms=' . intval($group['min_perm']);
     }
     /* Add this user to the group and change his perms if we need to */
     $dba->executeUpdate("UPDATE " . USERS . " SET usergroups='" . $dba->quote(serialize($groups)) . "' {$extra} WHERE id = " . intval($member['id']));
     $template = BreadCrumbs($template, $template->getVar('L_ADDUSER'));
     $template->setInfo('content', sprintf($template->getVar('L_ADDEDUSERTOGROUP'), $member['name'], $group['name']), FALSE);
     $template->setRedirect('usergroups.php?id=' . intval($group['id']), 3);
     return TRUE;
 }
Exemplo n.º 5
0
 function execute(&$request)
 {
     if ($request['user']->isMember() && $request['user']->get('perms') >= SUPERADMIN) {
         global $_USERGROUPS;
         k4_bread_crumbs($request['template'], $request['dba'], 'L_USERS');
         $request['template']->setVar('users_on', '_on');
         $request['template']->setFile('sidebar_menu', 'menus/users.html');
         if (!isset($_REQUEST['user_id']) || intval($_REQUEST['user_id']) == 0) {
             $action = new K4InformationAction(new K4LanguageElement('L_USERDOESNTEXIST'), 'content', TRUE);
             return $action->execute($request);
         }
         $member = $request['dba']->getRow("SELECT * FROM " . K4USERS . " WHERE id=" . intval($_REQUEST['user_id']) . " LIMIT 1");
         if (!is_array($member) || empty($member)) {
             $action = new K4InformationAction(new K4LanguageElement('L_USERDOESNTEXIST'), 'content', TRUE);
             return $action->execute($request);
         }
         if (!isset($_REQUEST['group_id']) || intval($_REQUEST['group_id']) == 0) {
             $action = new K4InformationAction(new K4LanguageElement('L_GROUPDOESNTEXIST'), 'content', FALSE);
             return $action->execute($request);
         }
         if (!isset($_USERGROUPS[intval($_REQUEST['group_id'])])) {
             $action = new K4InformationAction(new K4LanguageElement('L_GROUPDOESNTEXIST'), 'content', FALSE);
             return $action->execute($request);
         }
         $group = $_USERGROUPS[intval($_REQUEST['group_id'])];
         /* Should we set the group moderator? */
         if ($group['mod_name'] == '' || $group['mod_id'] == 0) {
             $admin = $request['dba']->getRow("SELECT * FROM " . K4USERS . " WHERE perms >= " . intval(ADMIN) . " ORDER BY perms,id ASC LIMIT 1");
             $request['dba']->executeUpdate("UPDATE " . K4USERGROUPS . " SET mod_name = '" . $request['dba']->quote($admin['name']) . "', mod_id = " . intval($admin['id']) . " WHERE id = " . intval($group['id']));
             reset_cache('usergroups');
             $group['mod_name'] = $admin['name'];
             $group['mod_id'] = $admin['id'];
         }
         if ($group['mod_id'] == $member['id']) {
             $action = new K4InformationAction(new K4LanguageElement('L_YOUAREMODERATOR'), 'content', TRUE);
             return $action->execute($request);
         }
         $result = explode('|', trim($member['usergroups'] . '|'));
         $groups = $member['usergroups'] != '' ? iif(!$result, force_usergroups($member), $result) : array();
         $in_group = FALSE;
         foreach ($groups as $id) {
             if (isset($_USERGROUPS[$id]) && $id == $group['id']) {
                 $in_group = TRUE;
             }
         }
         if ($in_group) {
             $action = new K4InformationAction(new K4LanguageElement('L_BELONGSTOGROUP'), 'content', TRUE);
             return $action->execute($request);
         }
         $groups[] = intval($group['id']);
         $extra = NULL;
         if ($member['perms'] < $group['min_perm']) {
             $extra .= ', perms=' . intval($group['min_perm']);
         }
         /* Add this user to the group and change his perms if we need to */
         $request['dba']->executeUpdate("UPDATE " . K4USERS . " SET usergroups='" . $request['dba']->quote('|' . implode('|', $groups) . '|') . "' {$extra} WHERE id = " . intval($member['id']));
         k4_bread_crumbs($request['template'], $request['dba'], 'L_ADDUSER');
         $action = new K4InformationAction(new K4LanguageElement('L_ADDEDUSERTOGROUP', $member['name'], $group['name']), 'content', FALSE, 'admin.php?act=users', 3);
         return $action->execute($request);
     } else {
         no_perms_error($request);
     }
     return TRUE;
 }
Exemplo n.º 6
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_USERGROUPS, $_QUERYPARAMS, $_URL;
     /**
      * Are we looking at the list of user groups?
      */
     if (!isset($request['id']) || intval($request['id']) == 0) {
         $groups = isset($user['usergroups']) && $user['usergroups'] != '' ? iif(!unserialize($user['usergroups']), force_usergroups($user), unserialize($user['usergroups'])) : array();
         $query = "SELECT * FROM " . USERGROUPS . " WHERE display_legend = 1";
         if ($user['perms'] < ADMIN) {
             foreach ($groups as $id) {
                 if (isset($_USERGROUPS[$id])) {
                     $query .= ' OR id = ' . intval($id);
                 }
             }
         } else {
             $query = "SELECT * FROM " . USERGROUPS;
         }
         $groups = $dba->executeQuery($query);
         $template->setList('usergroups', $groups);
         $template = BreadCrumbs($template, $template->getVar('L_USERGROUPS'));
         $template->setFile('content', 'usergroups.html');
         /**
          * Are we looking at a specific user group?
          */
     } else {
         /* Is this user group set? */
         if (!isset($_USERGROUPS[intval($request['id'])])) {
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setInfo('content', $template->getVar('L_GROUPDOESNTEXIST'));
         }
         $group = $_USERGROUPS[intval($request['id'])];
         /**
          * If the group admin has yet to be set, set it to our administrator
          */
         if ($group['mod_name'] == '' || $group['mod_id'] == 0) {
             /* Get our administrator */
             $admin = $dba->getRow("SELECT * FROM " . USERS . " WHERE perms >= " . intval(ADMIN) . " ORDER BY perms,id ASC LIMIT 1");
             $dba->executeUpdate("UPDATE " . USERGROUPS . " SET mod_name = '" . $dba->quote($admin['name']) . "', mod_id = " . intval($admin['id']) . " WHERE id = " . intval($group['id']));
             /* Change the file modification time of our cache file */
             if (!@touch(CACHE_FILE, time() - 86460)) {
                 @unlink(CACHE_FILE);
             }
             /* Add this info to the group array so that we can access it later */
             $group['mod_name'] = $admin['name'];
             $group['mod_id'] = $admin['id'];
         }
         /* Get our admins max user group.. it _should_ be the administrators group */
         $g = get_user_max_group($dba->getRow("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . USERS . " u LEFT JOIN " . USERINFO . " ui ON u.id=ui.user_id WHERE u.id = " . intval($group['mod_id'])), $_USERGROUPS);
         /* Set his group's color */
         $group['mod_color'] = !isset($g['color']) || $g['color'] == '' ? '000000' : $g['color'];
         /* Add this group's info to the database */
         foreach ($group as $key => $val) {
             $template->setVar('group_' . $key, $val);
         }
         /* Create the Pagination */
         $resultsperpage = 10;
         $num_results = $dba->getValue("SELECT COUNT(*) FROM " . USERS . " WHERE usergroups LIKE '%;i:" . intval($group['id']) . ";%' AND id <> " . intval($group['mod_id']));
         $perpage = isset($request['limit']) && ctype_digit($request['limit']) && intval($request['limit']) > 0 ? intval($request['limit']) : $resultsperpage;
         $num_pages = ceil($num_results / $perpage);
         $page = isset($request['page']) && ctype_digit($request['page']) && intval($request['page']) > 0 ? intval($request['page']) : 1;
         $pager =& new TPL_Paginator($_URL, $num_results, $page, $perpage);
         if ($num_results > $perpage) {
             $template->setPager('users_pager', $pager);
         }
         /* Outside valid page range, redirect */
         if (!$pager->hasPage($page) && $num_results > $resultsperpage) {
             $template->setInfo('content', $template->getVar('L_PASTPAGELIMIT'));
             $template->setRedirect('usergroups.php?id=' . $group['id'] . '&limit=' . $perpage . '&page=' . $num_pages, 3);
         }
         /* Get the members for this usergroup */
         $start = ($page - 1) * $perpage;
         /* Get the members of this usergroup */
         $result =& $dba->executeQuery("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . USERS . " u LEFT JOIN " . USERINFO . " ui ON u.id=ui.user_id WHERE u.usergroups LIKE '%;i:" . intval($group['id']) . ";%' AND u.id <> " . intval($group['mod_id']) . " LIMIT " . intval($start) . ", " . intval($perpage));
         $users =& new UsersIterator($result);
         $template->setVar('num_group_members', $num_results);
         if ($user['id'] == $group['mod_id']) {
             $template->show('add_user');
         }
         $template = BreadCrumbs($template, $group['name']);
         $template->setList('users_in_usergroup', $users);
         $template->setFile('content', 'lookup_usergroup.html');
     }
     return TRUE;
 }
 function execute(&$request)
 {
     if ($request['user']->isMember() && $request['user']->get('perms') >= SUPERADMIN) {
         if (!isset($_REQUEST['id']) || intval($_REQUEST['id']) == 0) {
             $action = new K4InformationAction(new K4LanguageElement('L_INVALIDUSERGROUP'), 'content', TRUE);
             return $action->execute($request);
         }
         $group = $request['dba']->getRow("SELECT * FROM " . K4USERGROUPS . " WHERE id = " . intval($_REQUEST['id']));
         if (!is_array($group) || empty($group)) {
             $action = new K4InformationAction(new K4LanguageElement('L_INVALIDUSERGROUP'), 'content', TRUE);
             return $action->execute($request);
         }
         /* Get all users of this usergroup */
         $users = $request['dba']->executeQuery("SELECT * FROM " . K4USERS . " WHERE usergroups LIKE '%;i:" . intval($group['id']) . ";%'");
         while ($users->next()) {
             $user = $users->current();
             $result = explode('|', $request['user']->get('usergroups'));
             $groups = $request['user']->get('usergroups') != '' ? iif(!$result, force_usergroups($user), $result) : array();
             /* Are we dealing with an array? */
             if (is_array($groups)) {
                 /* make a new array because if we unset values in the $groups array, it will kill the for() */
                 $new_groups = array();
                 /* Loop through the array */
                 for ($i = 0; $i < count($groups); $i++) {
                     /* This will remove this usergroup, and any ninexistant ones from this user's array */
                     if ($groups[$i] != $group['id'] && $groups[$i] != 0) {
                         $new_groups[] = $groups[$i];
                     }
                 }
                 /* Reset the groups variable */
                 $groups = $new_groups;
             }
             $request['dba']->executeUpdate("UPDATE " . K4USERS . " SET usergroups = '" . $request['dba']->quote(implode('|', $groups)) . "' WHERE id = " . intval($user['id']));
         }
         /* Remove the usergroup */
         $request['dba']->executeUpdate("DELETE FROM " . K4USERGROUPS . " WHERE id = " . intval($group['id']));
         reset_cache('usergroups');
         k4_bread_crumbs($request['template'], $request['dba'], 'L_USERGROUPS');
         $request['template']->setVar('users_on', '_on');
         $request['template']->setFile('sidebar_menu', 'menus/users.html');
         $action = new K4InformationAction(new K4LanguageElement('L_REMOVEDUSERGROUP', $group['name']), 'content', FALSE, 'admin.php?act=usergroups', 3);
         return $action->execute($request);
     } else {
         no_perms_error($request);
     }
     return TRUE;
 }
 function execute(&$request)
 {
     global $_USERGROUPS, $_QUERYPARAMS;
     if (!isset($_REQUEST['id']) || intval($_REQUEST['id']) == 0) {
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $action = new K4InformationAction(new K4LanguageElement('L_GROUPDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     if (!isset($_USERGROUPS[intval($_REQUEST['id'])])) {
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $action = new K4InformationAction(new K4LanguageElement('L_GROUPDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     if (!isset($_REQUEST['user_id']) || intval($_REQUEST['user_id']) == 0) {
         /* set the breadcrumbs bit */
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $action = new K4InformationAction(new K4LanguageElement('L_USERDOESNTEXIST'), 'content', TRUE);
         return $action->execute($request);
         return TRUE;
     }
     $group = $_USERGROUPS[intval($_REQUEST['id'])];
     $member = $request['dba']->getRow("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE u.id = '" . intval($_REQUEST['user_id']) . "'");
     if (!$member || !is_array($member) || empty($member)) {
         /* set the breadcrumbs bit */
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $action = new K4InformationAction(new K4LanguageElement('L_USERDOESNTEXIST'), 'content', TRUE);
         return $action->execute($request);
     }
     /* Should we set the group moderator? */
     if ($group['mod_name'] == '' || $group['mod_id'] == 0) {
         $admin = $request['dba']->getRow("SELECT * FROM " . K4USERS . " WHERE perms >= " . intval(ADMIN) . " ORDER BY perms,id ASC LIMIT 1");
         $request['dba']->executeUpdate("UPDATE " . K4USERGROUPS . " SET mod_name = '" . $request['dba']->quote($admin['name']) . "', mod_id = " . intval($admin['id']) . " WHERE id = " . intval($group['id']));
         reset_cache('usergroups');
         $group['mod_name'] = $admin['name'];
         $group['mod_id'] = $admin['id'];
     }
     if ($group['mod_id'] == $member['id']) {
         /* set the breadcrumbs bit */
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $action = new K4InformationAction(new K4LanguageElement('L_YOUAREMODERATOR'), 'content', TRUE);
         return $action->execute($request);
     }
     $result = explode('|', trim($member['usergroups'], '|'));
     $groups = $member['usergroups'] != '' ? iif(!$result, force_usergroups($member), $result) : array();
     $groups = array_values($groups);
     $in_group = FALSE;
     $i = 0;
     foreach ($groups as $id) {
         if (isset($_USERGROUPS[$id]) && $id == $group['id']) {
             $in_group = TRUE;
             // remove the person from the user group
             unset($groups[$i]);
         }
         $i++;
     }
     $groups = array_values($groups);
     if (!$in_group) {
         /* set the breadcrumbs bit */
         k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
         $action = new K4InformationAction(new K4LanguageElement('L_NOTBELONGSTOGROUP'), 'content', TRUE);
         return $action->execute($request);
     }
     $newgroup = get_user_max_group(array('usergroups' => '|' . implode('|', $groups) . '|'), $_USERGROUPS);
     $perms = 5;
     if (isset($newgroup['max_perms'])) {
         if ($request['user']->get('perms') > $newgroup['max_perms']) {
             $perms = $newgroup['max_perms'];
         } else {
             if ($request['user']->get('perms') < $newgroup['min_perms']) {
                 $perms = $newgroup['min_perms'];
             }
         }
     }
     /* Add this user to the group and change his perms if we need to */
     $request['dba']->executeUpdate("UPDATE " . K4USERS . " SET usergroups='" . $request['dba']->quote('|' . implode('|', $groups) . '|') . "', perms=" . intval($perms) . " WHERE id = " . intval($member['id']));
     k4_bread_crumbs($request['template'], $request['dba'], 'L_REMOVEUSER');
     $action = new K4InformationAction(new K4LanguageElement('L_REMOVEDUSERFROMGROUP', $member['name'], $group['name']), 'content', FALSE, 'usergroups.php?id=' . intval($group['id']), 3);
     return $action->execute($request);
     return TRUE;
 }
Exemplo n.º 9
0
/**
 * Function to check if a user is a moderator of a forum
 */
function is_moderator($user, $forum)
{
    global $_USERGROUPS;
    if ($user['perms'] >= ADMIN) {
        return TRUE;
    }
    $moderators = !@unserialize($forum['moderating_groups']) ? force_usergroups($forum['moderating_groups']) : unserialize($forum['moderating_groups']);
    /* Make _sure_ that the moderating groups for this forum are set */
    //if(!is_array($moderators) || empty($moderators)) {
    //	if(isset($_USERGROUPS[6]) && $_USERGROUPS[6]['min_perm'] >= ADMIN) {
    //		$moderators		= array(6);
    //	} else {
    //		foreach($_USERGROUPS as $g)
    //			if($g['min_perm'] >= ADMIN)
    //				$moderators	= array($g['id']);
    //	}
    //}
    $groups = array();
    foreach ($moderators as $g) {
        if (isset($_USERGROUPS[$g])) {
            $groups[] = $g;
        }
    }
    if (isset($user['usergroups'])) {
        $my_groups = !@unserialize($user['usergroups']) ? force_usergroups($user['usergroups']) : unserialize($user['usergroups']);
        /* Do we toggle our moderator's panel? */
        if (is_in_group($my_groups, $groups, $user['perms'])) {
            return TRUE;
        }
    }
    return FALSE;
}
Exemplo n.º 10
0
 function execute(&$request)
 {
     global $_USERGROUPS, $_QUERYPARAMS, $_URL;
     /**
      * Are we looking at the list of user groups?
      */
     if (!isset($_REQUEST['id']) || intval($_REQUEST['id']) == 0) {
         $result = explode('|', $request['user']->get('usergroups'));
         $groups = $request['user']->get('usergroups') && $request['user']->get('usergroups') != '' ? iif(!$result, force_usergroups($request['user']->getInfoArray()), $result) : array();
         $query = "SELECT * FROM " . K4USERGROUPS . " WHERE display_legend = 1";
         if ($request['user']->get('perms') < ADMIN) {
             foreach ($groups as $id) {
                 if (isset($_USERGROUPS[$id])) {
                     $query .= ' OR id = ' . intval($id);
                 }
             }
         } else {
             $query = "SELECT * FROM " . K4USERGROUPS;
         }
         $groups = $request['dba']->executeQuery($query);
         $request['template']->setList('usergroups', $groups);
         k4_bread_crumbs($request['template'], $request['dba'], 'L_USERGROUPS');
         $request['template']->setFile('content', 'usergroups.html');
         /**
          * Are we looking at a specific user group?
          */
     } else {
         /* Is this user group set? */
         if (!isset($_USERGROUPS[intval($_REQUEST['id'])])) {
             k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
             $action = new K4InformationAction(new K4LanguageElement('L_GROUPDOESNTEXIST'), 'content', FALSE);
             return $action->execute($request);
         }
         $group = $_USERGROUPS[intval($_REQUEST['id'])];
         /**
          * If the group admin has yet to be set, set it to our administrator
          */
         if ($group['mod_name'] == '' || $group['mod_id'] == 0) {
             /* Get our administrator */
             $admin = $request['dba']->getRow("SELECT * FROM " . K4USERS . " WHERE perms >= " . intval(ADMIN) . " ORDER BY perms,id ASC LIMIT 1");
             $request['dba']->executeUpdate("UPDATE " . K4USERGROUPS . " SET mod_name = '" . $request['dba']->quote($admin['name']) . "', mod_id = " . intval($admin['id']) . " WHERE id = " . intval($group['id']));
             reset_cache('usergroups');
             /* Add this info to the group array so that we can access it later */
             $group['mod_name'] = $admin['name'];
             $group['mod_id'] = $admin['id'];
         }
         /* Get our admins max user group.. it _should_ be the administrators group */
         $g = get_user_max_group($request['dba']->getRow("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE u.id = " . intval($group['mod_id'])), $_USERGROUPS);
         /* Set his group's color */
         $group['mod_color'] = !isset($g['color']) || $g['color'] == '' ? '000000' : $g['color'];
         /* Add this group's info to the database */
         foreach ($group as $key => $val) {
             $request['template']->setVar('group_' . $key, $val);
         }
         /* Create the Pagination */
         $resultsperpage = 10;
         $num_results = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4USERS . " WHERE usergroups LIKE '%|" . intval($group['id']) . "|%' AND id <> " . intval($group['mod_id']));
         $perpage = isset($_REQUEST['limit']) && ctype_digit($_REQUEST['limit']) && intval($_REQUEST['limit']) > 0 ? intval($_REQUEST['limit']) : $resultsperpage;
         $num_pages = ceil($num_results / $perpage);
         $page = isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
         $pager =& new FAPaginator($_URL, $num_results, $page, $perpage);
         if ($num_results > $perpage) {
             $request['template']->setPager('users_pager', $pager);
             /* Create a friendly url for our pager jump */
             $page_jumper = new FAUrl($_URL->__toString());
             $page_jumper->args['limit'] = $perpage;
             $page_jumper->args['page'] = FALSE;
             $page_jumper->anchor = FALSE;
             $request['template']->setVar('pagejumper_url', preg_replace('~&amp;~i', '&', $page_jumper->__toString()));
         }
         /* Outside valid page range, redirect */
         if (!$pager->hasPage($page) && $num_pages > 0) {
             $action = new K4InformationAction(new K4LanguageElement('L_PASTPAGELIMIT'), 'content', FALSE, 'usergroups.php?id=' . $group['id'] . '&limit=' . $perpage . '&page=' . $num_pages, 3);
             return $action->execute($request);
         }
         /* Get the members for this usergroup */
         $start = ($page - 1) * $perpage;
         /* Get the members of this usergroup */
         if ($num_results > 0) {
             $result = $request['dba']->executeQuery("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE u.usergroups LIKE '%|" . intval($group['id']) . "|%' AND u.id <> " . intval($group['mod_id']) . " LIMIT " . intval($start) . ", " . intval($perpage));
             $users =& new UsersIterator($result);
             $request['template']->setList('users_in_usergroup', $users);
         }
         $request['template']->setVar('num_group_members', $num_results);
         if ($request['user']->get('id') == $group['mod_id']) {
             $request['template']->setVisibility('add_user', TRUE);
             $request['template']->setVar('is_mod', 1);
         }
         k4_bread_crumbs($request['template'], $request['dba'], $group['name']);
         $request['template']->setFile('content', 'lookup_usergroup.html');
     }
     return TRUE;
 }
Exemplo n.º 11
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS, $_USERFIELDS;
     /**
      * Error checking on this member
      */
     if (!isset($request['id']) || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_USERDOESNTEXIST'), TRUE);
         return TRUE;
     }
     $member = $dba->getRow("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . USERS . " u LEFT JOIN " . USERINFO . " ui ON u.id = ui.user_id WHERE u.id = " . intval($request['id']));
     if (!$member || !is_array($member) || empty($member)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_USERDOESNTEXIST'), TRUE);
         return TRUE;
     }
     $member['num_topics'] = $dba->getValue("SELECT COUNT(*) FROM " . TOPICS . " WHERE poster_id = " . intval($member['id']));
     $member['num_replies'] = $dba->getValue("SELECT COUNT(*) FROM " . REPLIES . " WHERE poster_id = " . intval($member['id']));
     /**
      * Get and set some user/forum statistics
      */
     $user_created = time() - iif($member['created'] != 0, $member['created'], time());
     $postsperday = $user_created != 0 ? round($member['num_posts'] / ($user_created / 86400), 3) : 0;
     $member['posts_per_day'] = sprintf($template->getVar('L_POSTSPERDAY'), $postsperday);
     $num_posts = $_DATASTORE['forumstats']['num_topics'] + $_DATASTORE['forumstats']['num_replies'];
     $member['posts_percent'] = $num_posts != 0 && $member['num_posts'] != 0 ? sprintf($template->getVar('L_OFTOTALPOSTS'), round($member['num_posts'] / $num_posts * 100, 3) . '%') : sprintf($template->getVar('L_OFTOTALPOSTS'), '0%');
     $group = get_user_max_group($member, $_USERGROUPS);
     $member['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
     $member['online'] = time() - ini_get('session.gc_maxlifetime') > $member['seen'] ? 'offline' : 'online';
     $groups = $member['usergroups'] != '' ? iif(!unserialize($member['usergroups']), force_usergroups($member), unserialize($member['usergroups'])) : array();
     /**
      * Get and set the user groups for this member
      */
     $usergroups = array();
     foreach ($groups as $id) {
         if (isset($_USERGROUPS[$id]) && is_array($_USERGROUPS[$id]) && !empty($_USERGROUPS[$id])) {
             $usergroups[] = $_USERGROUPS[$id];
         }
     }
     $template->setList('member_usergroups', new FAArrayIterator($usergroups));
     foreach ($member as $key => $val) {
         $template->setVar('member_' . $key, $val);
     }
     /**
      * Get the custom user fields for this member
      */
     $fields = array();
     foreach ($_USERFIELDS as $field) {
         if ($field['display_profile'] == 1) {
             if (isset($member[$field['name']]) && $member[$field['name']] != '') {
                 switch ($field['inputtype']) {
                     default:
                     case 'text':
                     case 'textarea':
                     case 'select':
                         $field['value'] = $member[$field['name']];
                         break;
                     case 'multiselect':
                     case 'radio':
                     case 'check':
                         $field['value'] = implode(", ", iif(!unserialize($member[$field['name']]), array(), unserialize($member[$field['name']])));
                         break;
                 }
                 $fields[] = $field;
             }
         }
     }
     if (count($fields) > 0) {
         if ($fields % 2 == 1) {
             $fields[count($fields) - 1]['colspan'] = 2;
         }
         $template->setList('member_profilefields', new FAArrayIterator($fields));
     }
     /**
      * Set the info we need
      */
     $template = BreadCrumbs($template, $template->getVar('L_USERPROFILE'));
     $template->setFile('content', 'member_profile.html');
     return TRUE;
 }