예제 #1
0
 /**
  * Delete subscriptions that have now been made
  * illegal due to permissions change
  *
  * @param string $mode contains group or user
  * @param integer $group group or user id
  * @author Jonathan West <*****@*****.**>
  * @since 1.1.6
  **/
 function check_subscriptions($mode, $group)
 {
     if ($mode == 'user') {
         $query = $this->db->query("SELECT s.subscription_user, s.subscription_item, s.subscription_type, u.user_id, u.user_group, u.user_perms\r\n\t\t\t\t\t\t\t\t\tFROM ({$this->pre}subscriptions s, {$this->pre}users u)\r\n\t\t\t\t\t\t\t\t\tWHERE s.subscription_user = {$group}\r\n\t\t\t\t\t\t\t\t\tAND s.subscription_user = u.user_id\r\n\t\t\t\t\t\t\t\t\t");
         while ($sub = $this->db->nqfetch($query)) {
             $perms = new permissions();
             $perms->db =& $this->db;
             $perms->pre =& $this->pre;
             $perms->get_perms($sub['user_group'], $sub['user_id'], $sub['user_perms']);
             if ($sub['subscription_type'] == 'forum') {
                 if (!$perms->auth('forum_view', $sub['subscription_item'])) {
                     //if user can no longer view forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
                 if (!$perms->auth('forum_subscribe', $sub['subscription_item'])) {
                     //if user can no longer subscribe to a forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
             } else {
                 $check = $this->db->fetch("SELECT topic_forum FROM {$this->pre}topics WHERE topic_id={$sub['subscription_item']}");
                 if (!$perms->auth('forum_view', $check['topic_forum'])) {
                     //if user can no longer view forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
                 if (!$perms->auth('forum_subscribe', $check['topic_forum'])) {
                     //if user can no longer subscribe to a forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
             }
         }
     } else {
         //if a member of the group has subscriptions
         $query = $this->db->query("SELECT s.subscription_user, s.subscription_item, s.subscription_type, u.user_id, u.user_group, g.group_perms\r\n\t\t\t\t\t\t\t\t\tFROM ({$this->pre}subscriptions s, {$this->pre}users u, {$this->pre}groups g)\r\n\t\t\t\t\t\t\t\t\tWHERE g.group_id = {$group}\r\n\t\t\t\t\t\t\t\t\tAND u.user_group = g.group_id\r\n\t\t\t\t\t\t\t\t\tAND s.subscription_user = u.user_id\r\n\t\t\t\t\t\t\t\t\t");
         while ($sub = $this->db->nqfetch($query)) {
             $perms = new permissions();
             $perms->db =& $this->db;
             $perms->pre =& $this->pre;
             $perms->get_perms($sub['user_group'], $sub['user_id'], $sub['group_perms']);
             if ($sub['subscription_type'] == 'forum') {
                 if (!$perms->auth('forum_view', $sub['subscription_item'])) {
                     //if user can no longer view forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
                 if (!$perms->auth('forum_subscribe', $sub['subscription_item'])) {
                     //if user can no longer subscribe to a forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
             } else {
                 $check = $this->db->fetch("SELECT topic_forum FROM {$this->pre}topics WHERE topic_id={$sub['subscription_item']}");
                 if (!$perms->auth('forum_view', $check['topic_forum'])) {
                     //if user can no longer view forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
                 if (!$perms->auth('forum_subscribe', $check['topic_forum'])) {
                     //if user can no longer subscribe to a forum
                     $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * Adds a forum with parameters from $this->post
  *
  * @author Mark Elliot <*****@*****.**>
  * @since Beta 2.1
  * @return string Completion message
  **/
 function AddForum()
 {
     if (trim($this->post['name']) == '') {
         return "The forum name is empty. (Please press back and enter a name)";
     }
     $forums = $this->forum_grab();
     $forums_arr = $this->forum_array($forums, $this->post['parent']);
     $position = $forums_arr ? count($forums_arr) : 0;
     $this->db->query("INSERT INTO {$this->pre}forums\r\n\t\t(forum_tree, forum_parent, forum_name, forum_description, forum_position) VALUES\r\n\t\t('" . $this->CreateTree($forums, $this->post['parent']) . "', '{$this->post['parent']}', '{$this->post['name']}', '{$this->post['description']}', '{$position}')");
     $id = $this->db->insert_id();
     $perms = new permissions();
     $perms->db =& $this->db;
     $perms->pre =& $this->pre;
     while ($perms->get_group()) {
         // Full permissions (note: the banned group is still false)
         if ($this->post['sync'] == -2) {
             $perms->add_z($id, $perms->group != USER_BANNED);
             // Default permissions (only works if there are no forums already created)
         } elseif ($this->post['sync'] == -3) {
             $perms->add_z($id);
             // No permissions
         } elseif ($this->post['sync'] == -1) {
             $perms->add_z($id, false);
             // Copy another forum
         } else {
             $perms->add_z($id, false);
             foreach ($perms->standard as $perm => $false) {
                 if (!isset($perms->globals[$perm])) {
                     $perms->set_xyz($perm, $id, $perms->auth($perm, $this->post['sync']));
                 }
             }
         }
         $perms->update();
     }
     return "Forum added!<br/><br/><a href='{$this->self}'>Continue</a>";
 }
예제 #3
0
 /**
  * Checks Subscriptions to make sure subscribed members can  
  * still view the forum where the topic has been moved too
  *
  * @param $newtopic integer of the selected topic
  * @author Jonathan West <*****@*****.**>
  * @since 1.1.6
  **/
 function update_subscriptions($newtopic)
 {
     $query = $this->db->query("SELECT s.subscription_user, s.subscription_item, s.subscription_type,\r\n\t\t\t\t\t\t\t\t\tu.user_id, u.user_group, u.user_perms,\r\n\t\t\t\t\t\t\t\t\tg.group_id, g.group_perms,\r\n\t\t\t\t\t\t\t\t\tt.topic_forum\r\n\t\t\t\t\t\t\t\t\tFROM ({$this->pre}subscriptions s, {$this->pre}users u, {$this->pre}groups g, {$this->pre}topics t)\r\n\t\t\t\t\t\t\t\t\tWHERE s.subscription_user = u.user_id\r\n\t\t\t\t\t\t\t\t\tAND u.user_group = g.group_id\r\n\t\t\t\t\t\t\t\t\tAND t.topic_id = {$this->get['t']}\r\n\t\t\t\t\t\t\t\t\t");
     while ($sub = $this->db->nqfetch($query)) {
         $perms = new permissions();
         $perms->db =& $this->db;
         $perms->pre =& $this->pre;
         $perms->get_perms($sub['user_group'], $sub['user_id'], $sub['user_perms'] ? $sub['user_perms'] : $sub['group_perms']);
         if (!$perms->auth('forum_view', $sub['topic_forum'])) {
             $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
         } else {
             $this->db->query('UPDATE ' . $this->pre . 'subscriptions SET subscription_item=' . $newtopic . ' WHERE subscription_item=' . $this->get['t'] . " AND subscription_type='topic'");
         }
         if (!$perms->auth('forum_subscribe', $sub['topic_forum'])) {
             $this->db->query("DELETE FROM {$this->pre}subscriptions WHERE subscription_user={$sub['user_id']} AND subscription_item={$sub['subscription_item']}");
         }
     }
 }
예제 #4
0
 function execute()
 {
     $perms_obj = new permissions();
     $perms_obj->db =& $this->db;
     $perms_obj->pre =& $this->pre;
     if (isset($this->get['s']) && $this->get['s'] == 'user') {
         if (!isset($this->get['id'])) {
             header("Location: {$this->self}?a=member&amp;s=perms");
         }
         $this->post['group'] = intval($this->get['id']);
         $mode = 'user';
         $title = 'User Control';
         $link = '&amp;s=user&amp;id=' . $this->post['group'];
         $perms_obj->get_perms(-1, $this->post['group']);
     } else {
         if (!isset($this->post['group'])) {
             return $this->message('User Groups', "\n\t\t\t\t<form action='{$this->self}?a=perms' method='post'><div>\n\t\t\t\t\t{$this->lang->perms_edit_for}\n\t\t\t\t\t<select name='group'>\n\t\t\t\t\t" . $this->select_groups(-1) . "\n\t\t\t\t\t</select>\n\t\t\t\t\t<input type='submit' value='{$this->lang->submit}' /></div>\n\t\t\t\t</form>");
         }
         $this->post['group'] = intval($this->post['group']);
         $mode = 'group';
         $title = $this->lang->perms_title;
         $link = null;
         $perms_obj->get_perms($this->post['group'], -1);
     }
     $this->set_title($title);
     $this->tree($title);
     $forums_only = $this->db->query('SELECT forum_id, forum_name FROM ' . $this->pre . 'forums ORDER BY forum_name');
     $forums_list = array();
     while ($forum = $this->db->nqfetch($forums_only)) {
         $forums_list[] = $forum;
     }
     $perms = array('board_view' => $this->lang->perms_board_view, 'board_view_closed' => $this->lang->perms_board_view_closed, 'do_anything' => $this->lang->perms_do_anything, 'is_admin' => $this->lang->perms_is_admin, 'email_use' => $this->lang->perms_email_use, 'topic_global' => $this->lang->perms_topic_global, 'pm_noflood' => $this->lang->perms_pm_noflood, 'search_noflood' => $this->lang->perms_search_noflood, 'forum_view' => $this->lang->perms_forum_view, 'post_viewip' => $this->lang->perms_post_viewip, 'topic_view' => $this->lang->perms_topic_view, 'poll_create' => $this->lang->perms_poll_create, 'poll_vote' => $this->lang->perms_poll_vote, 'post_create' => $this->lang->perms_post_create, 'topic_create' => $this->lang->perms_topic_create, 'post_noflood' => $this->lang->perms_post_noflood, 'post_delete' => $this->lang->perms_post_delete, 'post_delete_own' => $this->lang->perms_post_delete_own, 'topic_delete' => $this->lang->perms_topic_delete, 'topic_delete_own' => $this->lang->perms_topic_delete_own, 'post_edit' => $this->lang->perms_post_edit, 'post_edit_own' => $this->lang->perms_post_edit_own, 'topic_edit' => $this->lang->perms_topic_edit, 'topic_edit_own' => $this->lang->perms_topic_edit_own, 'topic_lock' => $this->lang->perms_topic_lock, 'topic_lock_own' => $this->lang->perms_topic_lock_own, 'topic_unlock' => $this->lang->perms_topic_unlock, 'topic_unlock_mod' => $this->lang->perms_topic_unlock_mod, 'topic_unlock_own' => $this->lang->perms_topic_unlock_own, 'topic_pin' => $this->lang->perms_topic_pin, 'topic_pin_own' => $this->lang->perms_topic_pin_own, 'topic_split' => $this->lang->perms_topic_split, 'topic_split_own' => $this->lang->perms_topic_split_own, 'topic_unpin' => $this->lang->perms_topic_unpin, 'topic_unpin_own' => $this->lang->perms_topic_unpin_own, 'topic_move' => $this->lang->perms_topic_move, 'topic_move_own' => $this->lang->perms_topic_move_own, 'post_attach' => $this->lang->perms_post_attach, 'post_attach_download' => $this->lang->perms_post_attach_download);
     if (!isset($this->post['submit'])) {
         $count = count($forums_list) + 1;
         if ($mode == 'user') {
             $query = $this->db->fetch("SELECT user_name, user_perms FROM {$this->pre}users WHERE user_id={$this->post['group']}");
             $label = "User '{$query['user_name']}'";
         } else {
             $query = $this->db->fetch("SELECT group_name FROM {$this->pre}groups WHERE group_id={$this->post['group']}");
             $label = "Group '{$query['group_name']}'";
         }
         $out = "\n\t\t\t<script type='text/javascript'>\n\t\t\t<!--\n\t\t\tfunction checkrow(element, check)\n\t\t\t{\n\t\t\t\tvar elements = document.forms['form'].elements;\n\t\t\t\tvar count    = elements.length;\n\n\t\t\t\tfor (var i=0; i<count; i++) {\n\t\t\t\t\tvar current = elements[i];\n\t\t\t\t\tvar temp = current.name.split('[');\n\n\t\t\t\t\tif (!temp[1]) continue;\n\t\t\t\t\ttemp2 = temp[1].split(']');\n\n\t\t\t\t\tif (temp2[0] == element) {\n\t\t\t\t\t\tcurrent.checked = check;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction changeall(element, check)\n\t\t\t{\n\t\t\t\tif (!check) {\n\t\t\t\t\tcheckallbox(element, false);\n\t\t\t\t} else if (areallchecked(element)) {\n\t\t\t\t\tcheckallbox(element, true);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction checkallbox(element, check)\n\t\t\t{\n\t\t\t\tvar elements = document.forms['form'].elements;\n\t\t\t\tvar count    = elements.length;\n\n\t\t\t\tvar allchecked = true;\n\n\t\t\t\tfor (var i=0; i<count; i++) {\n\t\t\t\t\tvar current = elements[i];\n\n\t\t\t\t\tif (current.name == ('perms[' + element + '][-1]')) {\n\t\t\t\t\t\tcurrent.checked = check;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction areallchecked(element)\n\t\t\t{\n\t\t\t\tvar elements = document.forms['form'].elements;\n\t\t\t\tvar count    = elements.length;\n\n\t\t\t\tvar allchecked = true;\n\n\t\t\t\tfor (var i=0; i<count; i++) {\n\t\t\t\t\tvar current = elements[i];\n\n\t\t\t\t\tif (current.name == ('perms[' + element + '][-1]')) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tvar temp = current.name.split('[');\n\n\t\t\t\t\tif (!temp[1]) continue;\n\t\t\t\t\ttemp2 = temp[1].split(']');\n\n\t\t\t\t\tif (temp2[0] == element) {\n\t\t\t\t\t\tif (!current.checked) {\n\t\t\t\t\t\t\tallchecked = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn allchecked;\n\t\t\t}\n\t\t\t//-->\n\t\t\t</script>\n\n\t\t\t<form id='form' action='{$this->self}?a=perms{$link}' method='post'>\n\t\t\t<div align='center'><span style='font-size:14px;'><b>Permissions For {$label}</b></span>";
         if ($mode == 'user') {
             $out .= "<br />{$this->lang->perms_override_user}<br /><br />\n\t\t\t\t<div style='border:1px dashed #ff0000; width:25%; padding:5px'><input type='checkbox' name='usegroup' id='usegroup' style='vertical-align:middle'" . (!$query['user_perms'] ? ' checked' : '') . " /> <label for='usegroup' style='vertical-align:middle'>{$this->lang->perms_only_user}</label></div>";
         }
         $out .= "</div>" . $this->table . "\n\t\t\t<tr>\n\t\t\t\t<td colspan='" . ($count + 1) . "' class='header'>{$label}</td>\n\t\t\t</tr>";
         $out .= $this->show_headers($forums_list);
         $this->iterator_init('tablelight', 'tabledark');
         $i = 0;
         foreach ($perms as $perm => $label) {
             $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='" . $this->iterate() . "'>{$label}</td>\n\t\t\t\t\t<td class='" . $this->lastValue() . "' align='center'>\n\t\t\t\t\t\t<input type='checkbox' name='perms[{$perm}][-1]' id='perms_{$perm}' onclick='checkrow(\"{$perm}\", this.checked)'" . ($perms_obj->auth($perm) ? ' checked=\'checked\'' : '') . " />All\n\t\t\t\t\t</td>";
             if (!isset($perms_obj->globals[$perm])) {
                 foreach ($forums_list as $forum) {
                     if ($perms_obj->auth($perm, $forum['forum_id'])) {
                         $checked = " checked='checked'";
                     } else {
                         $checked = '';
                     }
                     $out .= "\n<td class='" . $this->lastValue() . "' align='center'><input type='checkbox' name='perms[{$perm}][{$forum['forum_id']}]' onclick='changeall(\"{$perm}\", this.checked)'{$checked} /></td>";
                 }
             } elseif ($forums_list) {
                 $out .= "\n<td class='" . $this->lastValue() . "' colspan='{$count}' align='center'>N/A</td>";
             }
             $out .= "\n\t\t\t\t</tr>";
             $i++;
             if ($i % 12 == 0) {
                 $out .= $this->show_headers($forums_list);
             }
         }
         return $out . "\n\t\t\t<tr>\n\t\t\t\t<td colspan='" . ($count + 1) . "' class='footer' align='center'><input type='hidden' name='group' value='{$this->post['group']}' /><input type='submit' name='submit' value='Update Permissions' /></td>\n\t\t\t</tr>" . $this->etable . "</form>";
     } else {
         if ($mode == 'user' && isset($this->post['usegroup'])) {
             $perms_obj->cube = '';
             $perms_obj->update();
             return $this->message($this->lang->perms, $this->lang->perms_user_inherit);
         }
         $perms_obj->reset_cube(false);
         if (!isset($this->post['perms'])) {
             $this->post['perms'] = array();
         }
         foreach ($this->post['perms'] as $name => $data) {
             if (isset($data[-1]) || isset($data['-1']) || count($data) == count($forums_list)) {
                 $perms_obj->set_xy($name, true);
             } else {
                 foreach ($data as $forum => $on) {
                     $perms_obj->set_xyz($name, intval($forum), true);
                 }
             }
         }
         $perms_obj->update();
         return $this->message($this->lang->perms, $this->lang->perms_updated);
     }
 }
예제 #5
0
 /**
  * Creates a category or forum
  *
  * @param string $name Name of the forum
  * @param string $desc Description of the forum
  * @param int $parent Parent id of the forum (0 if a category)
  * @author Geoffrey Dunn <*****@*****.**>
  * @since 1.1.9
  * @return int id of the forum created
  **/
 function create_forum($name, $desc, $parent)
 {
     $parent ? $tree = $parent : ($tree = '');
     $this->db->query("INSERT INTO {$this->pre}forums\n\t\t\t(forum_tree, forum_parent, forum_name, forum_description, forum_position, forum_subcat) VALUES\n\t\t\t('{$tree}', '{$parent}', '{$name}', '{$desc}', '0', '0')");
     $forumId = $this->db->insert_id();
     $perms = new permissions();
     $perms->db =& $this->db;
     $perms->pre =& $this->pre;
     while ($perms->get_group()) {
         if (!$parent) {
             // Default permissions
             $perms->add_z($forumId);
         } else {
             // Copy permissions
             $perms->add_z($forumId, false);
             foreach ($perms->standard as $perm => $false) {
                 if (!isset($perms->globals[$perm])) {
                     $perms->set_xyz($perm, $forumId, $perms->auth($perm, $parent));
                 }
             }
         }
         $perms->update();
     }
     return $forumId;
 }