| 831 | 
           florian | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           ////////////////////////////////////////////////////////////////////////////////
  | 
        
        
            | 
            | 
           4 | 
           //                                                                            //
  | 
        
        
            | 
            | 
           5 | 
           //   Copyright (C) 2006  Phorum Development Team                              //
  | 
        
        
            | 
            | 
           6 | 
           //   http://www.phorum.org                                                    //
  | 
        
        
            | 
            | 
           7 | 
           //                                                                            //
  | 
        
        
            | 
            | 
           8 | 
           //   This program is free software. You can redistribute it and/or modify     //
  | 
        
        
            | 
            | 
           9 | 
           //   it under the terms of either the current Phorum License (viewable at     //
  | 
        
        
            | 
            | 
           10 | 
           //   phorum.org) or the Phorum License that was distributed with this file    //
  | 
        
        
            | 
            | 
           11 | 
           //                                                                            //
  | 
        
        
            | 
            | 
           12 | 
           //   This program is distributed in the hope that it will be useful,          //
  | 
        
        
            | 
            | 
           13 | 
           //   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
  | 
        
        
            | 
            | 
           14 | 
           //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
  | 
        
        
            | 
            | 
           15 | 
           //                                                                            //
  | 
        
        
            | 
            | 
           16 | 
           //   You should have received a copy of the Phorum License                    //
  | 
        
        
            | 
            | 
           17 | 
           //   along with this program.                                                 //
  | 
        
        
            | 
            | 
           18 | 
           ////////////////////////////////////////////////////////////////////////////////
  | 
        
        
            | 
            | 
           19 | 
              | 
        
        
            | 
            | 
           20 | 
               if(!defined("PHORUM_ADMIN")) return;
  | 
        
        
            | 
            | 
           21 | 
              | 
        
        
            | 
            | 
           22 | 
               $error="";
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
               if(count($_POST)){
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
                   if( isset($_POST['action']) && $_POST['action'] == "deleteGroups") {
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
                     $count=0;
  | 
        
        
            | 
            | 
           29 | 
                     foreach($_POST['deleteIds'] as $id => $deluid) {
  | 
        
        
            | 
            | 
           30 | 
                         phorum_db_delete_group($deluid);
  | 
        
        
            | 
            | 
           31 | 
                         $count++;
  | 
        
        
            | 
            | 
           32 | 
                     }
  | 
        
        
            | 
            | 
           33 | 
                     echo "$count Group(s) deleted.<br />";
  | 
        
        
            | 
            | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
                   }
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
                   switch ($_POST["section"]) {
  | 
        
        
            | 
            | 
           38 | 
              | 
        
        
            | 
            | 
           39 | 
                       case "add":
  | 
        
        
            | 
            | 
           40 | 
                           $group_id=0;
  | 
        
        
            | 
            | 
           41 | 
                           $_POST["group_name"]=trim($_POST["group_name"]);
  | 
        
        
            | 
            | 
           42 | 
                           if(!empty($_POST["group_name"])){
  | 
        
        
            | 
            | 
           43 | 
                               $group_id=phorum_db_add_group($_POST["group_name"]);
  | 
        
        
            | 
            | 
           44 | 
                           }
  | 
        
        
            | 
            | 
           45 | 
                           if(!$group_id){
  | 
        
        
            | 
            | 
           46 | 
                               echo "Error adding group<br />";
  | 
        
        
            | 
            | 
           47 | 
                           } else {
  | 
        
        
            | 
            | 
           48 | 
                               echo "Group added<br />";
  | 
        
        
            | 
            | 
           49 | 
                           }
  | 
        
        
            | 
            | 
           50 | 
                           break;
  | 
        
        
            | 
            | 
           51 | 
              | 
        
        
            | 
            | 
           52 | 
                       case "edit":
  | 
        
        
            | 
            | 
           53 | 
                           $group = array("group_id" => $_POST["group_id"], "name" => $_POST["name"], "open" => $_POST["open"]);
  | 
        
        
            | 
            | 
           54 | 
              | 
        
        
            | 
            | 
           55 | 
                           if(phorum_db_save_group($group)){
  | 
        
        
            | 
            | 
           56 | 
                               echo "Group Saved";
  | 
        
        
            | 
            | 
           57 | 
                           } else {
  | 
        
        
            | 
            | 
           58 | 
                               echo "Error Saving Group Name";
  | 
        
        
            | 
            | 
           59 | 
                           }
  | 
        
        
            | 
            | 
           60 | 
                           break;
  | 
        
        
            | 
            | 
           61 | 
              | 
        
        
            | 
            | 
           62 | 
                       case "forums":
  | 
        
        
            | 
            | 
           63 | 
                           $group=$_POST;
  | 
        
        
            | 
            | 
           64 | 
                           if($_POST["new_forum"]){
  | 
        
        
            | 
            | 
           65 | 
                               if(!is_array($_POST["new_permissions"])){
  | 
        
        
            | 
            | 
           66 | 
                                   $permission=0;
  | 
        
        
            | 
            | 
           67 | 
                               } else {
  | 
        
        
            | 
            | 
           68 | 
                                   $permission = 0;
  | 
        
        
            | 
            | 
           69 | 
                                   foreach($_POST["new_permissions"] as $perm=>$check){
  | 
        
        
            | 
            | 
           70 | 
                                      $permission = $permission | $perm;
  | 
        
        
            | 
            | 
           71 | 
                                   }
  | 
        
        
            | 
            | 
           72 | 
                               }
  | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
                               $group["permissions"][$_POST["new_forum"]]=$permission;
  | 
        
        
            | 
            | 
           75 | 
                           }
  | 
        
        
            | 
            | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
                           if(isset($_POST["delforum"])){
  | 
        
        
            | 
            | 
           78 | 
                               foreach($_POST["delforum"] as $fid=>$val){
  | 
        
        
            | 
            | 
           79 | 
                                   unset($group["permissions"][$fid]);
  | 
        
        
            | 
            | 
           80 | 
                                   unset($_POST["forums"][$fid]);
  | 
        
        
            | 
            | 
           81 | 
                               }
  | 
        
        
            | 
            | 
           82 | 
                           }
  | 
        
        
            | 
            | 
           83 | 
              | 
        
        
            | 
            | 
           84 | 
              | 
        
        
            | 
            | 
           85 | 
                           if(isset($_POST["forums"])){
  | 
        
        
            | 
            | 
           86 | 
                               foreach($_POST["forums"] as $forum_id){
  | 
        
        
            | 
            | 
           87 | 
                                   $permission=0;
  | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
                                   if(isset($group["permissions"][$forum_id])){
  | 
        
        
            | 
            | 
           90 | 
                                       foreach($group["permissions"][$forum_id] as $perm=>$check){
  | 
        
        
            | 
            | 
           91 | 
                                           $permission = $permission | $perm;
  | 
        
        
            | 
            | 
           92 | 
                                       }
  | 
        
        
            | 
            | 
           93 | 
                                   }
  | 
        
        
            | 
            | 
           94 | 
              | 
        
        
            | 
            | 
           95 | 
                                   $group["permissions"][$forum_id]=$permission;
  | 
        
        
            | 
            | 
           96 | 
                               }
  | 
        
        
            | 
            | 
           97 | 
                           }
  | 
        
        
            | 
            | 
           98 | 
              | 
        
        
            | 
            | 
           99 | 
                           unset($group["forums"]);
  | 
        
        
            | 
            | 
           100 | 
                           unset($group["delforum"]);
  | 
        
        
            | 
            | 
           101 | 
                           unset($group["new_forum"]);
  | 
        
        
            | 
            | 
           102 | 
                           unset($group["new_permissions"]);
  | 
        
        
            | 
            | 
           103 | 
              | 
        
        
            | 
            | 
           104 | 
                           if(phorum_db_save_group($group)){
  | 
        
        
            | 
            | 
           105 | 
                           	// clearing user-cache if needed
  | 
        
        
            | 
            | 
           106 | 
                           	if(isset($PHORUM['cache_users']) && $PHORUM['cache_users']) {
  | 
        
        
            | 
            | 
           107 | 
           	                	$group_members=phorum_db_get_group_members($_POST["group_id"]);
  | 
        
        
            | 
            | 
           108 | 
              | 
        
        
            | 
            | 
           109 | 
           	                	if(count($group_members)) {
  | 
        
        
            | 
            | 
           110 | 
           	                		foreach($group_members as $user_id => $user_status) {
  | 
        
        
            | 
            | 
           111 | 
           	                			phorum_cache_remove('user',$user_id);
  | 
        
        
            | 
            | 
           112 | 
           	                		}
  | 
        
        
            | 
            | 
           113 | 
           	                	}
  | 
        
        
            | 
            | 
           114 | 
              | 
        
        
            | 
            | 
           115 | 
                           	}
  | 
        
        
            | 
            | 
           116 | 
              | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
                               echo "Group Forum Permissions Saved";
  | 
        
        
            | 
            | 
           119 | 
                           } else {
  | 
        
        
            | 
            | 
           120 | 
                               echo "Error Saving Group Forum Permissions";
  | 
        
        
            | 
            | 
           121 | 
                           }
  | 
        
        
            | 
            | 
           122 | 
              | 
        
        
            | 
            | 
           123 | 
              | 
        
        
            | 
            | 
           124 | 
                           break;
  | 
        
        
            | 
            | 
           125 | 
              | 
        
        
            | 
            | 
           126 | 
                   }
  | 
        
        
            | 
            | 
           127 | 
              | 
        
        
            | 
            | 
           128 | 
               }
  | 
        
        
            | 
            | 
           129 | 
              | 
        
        
            | 
            | 
           130 | 
               if($error){
  | 
        
        
            | 
            | 
           131 | 
                   phorum_admin_error($error);
  | 
        
        
            | 
            | 
           132 | 
               }
  | 
        
        
            | 
            | 
           133 | 
              | 
        
        
            | 
            | 
           134 | 
               include_once "./include/admin/PhorumInputForm.php";
  | 
        
        
            | 
            | 
           135 | 
               $groups=phorum_db_get_groups();
  | 
        
        
            | 
            | 
           136 | 
              | 
        
        
            | 
            | 
           137 | 
               $forums=phorum_db_get_forums();
  | 
        
        
            | 
            | 
           138 | 
              | 
        
        
            | 
            | 
           139 | 
               if(isset($_GET["edit"])){
  | 
        
        
            | 
            | 
           140 | 
              | 
        
        
            | 
            | 
           141 | 
                   $group=$groups[$_GET["group_id"]];
  | 
        
        
            | 
            | 
           142 | 
              | 
        
        
            | 
            | 
           143 | 
                   $frm =& new PhorumInputForm ("", "post");
  | 
        
        
            | 
            | 
           144 | 
              | 
        
        
            | 
            | 
           145 | 
                   $frm->addbreak("Edit Group");
  | 
        
        
            | 
            | 
           146 | 
              | 
        
        
            | 
            | 
           147 | 
                   $frm->hidden("module", "groups");
  | 
        
        
            | 
            | 
           148 | 
              | 
        
        
            | 
            | 
           149 | 
                   $frm->hidden("section", "edit");
  | 
        
        
            | 
            | 
           150 | 
              | 
        
        
            | 
            | 
           151 | 
                   $frm->hidden("group_id", $_GET["group_id"]);
  | 
        
        
            | 
            | 
           152 | 
              | 
        
        
            | 
            | 
           153 | 
                   $open_options = array(PHORUM_GROUP_CLOSED => "No",
  | 
        
        
            | 
            | 
           154 | 
                                   PHORUM_GROUP_OPEN => "Yes",
  | 
        
        
            | 
            | 
           155 | 
                                   PHORUM_GROUP_REQUIRE_APPROVAL => "Yes (require Group Moderator approval)");
  | 
        
        
            | 
            | 
           156 | 
                   $frm->addrow("Name:", $frm->text_box("name", $group["name"], 50));
  | 
        
        
            | 
            | 
           157 | 
                   $frm->addrow("Allow Membership Requests:", $frm->select_tag("open", $open_options, $group["open"], ""));
  | 
        
        
            | 
            | 
           158 | 
                   $frm->show();
  | 
        
        
            | 
            | 
           159 | 
              | 
        
        
            | 
            | 
           160 | 
                   echo "<br /><hr class=\"PhorumAdminHR\" /><br />";
  | 
        
        
            | 
            | 
           161 | 
              | 
        
        
            | 
            | 
           162 | 
              | 
        
        
            | 
            | 
           163 | 
                   $frm =& new PhorumInputForm ("", "post", "Update");
  | 
        
        
            | 
            | 
           164 | 
              | 
        
        
            | 
            | 
           165 | 
                   $frm->hidden("module", "groups");
  | 
        
        
            | 
            | 
           166 | 
              | 
        
        
            | 
            | 
           167 | 
                   $frm->hidden("section", "forums");
  | 
        
        
            | 
            | 
           168 | 
              | 
        
        
            | 
            | 
           169 | 
                   $frm->hidden("group_id", $_GET["group_id"]);
  | 
        
        
            | 
            | 
           170 | 
              | 
        
        
            | 
            | 
           171 | 
                   $row=$frm->addbreak("Edit Forum Permissions");
  | 
        
        
            | 
            | 
           172 | 
              | 
        
        
            | 
            | 
           173 | 
                   $frm->addhelp($row, "Forum Permissions", "Permissions given to groups overwrite any permissions granted by the forum properties.  Also, if a user is granted permissions directly to a forum in the user admin, any group permissions he has for that forum will be ignored.  If the user is a member of two or more groups that have permissions in the same forum, the permissions will be combined. (eg. If group A allows read and reply and group B allows create and moderate, the user will receive all four permissions.)");
  | 
        
        
            | 
            | 
           174 | 
              | 
        
        
            | 
            | 
           175 | 
                   $forums=phorum_db_get_forums();
  | 
        
        
            | 
            | 
           176 | 
              | 
        
        
            | 
            | 
           177 | 
                   $perm_frm = $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_READ."]", 1, "Read")."  ".
  | 
        
        
            | 
            | 
           178 | 
                               $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_REPLY."]", 1, "Reply")."  ".
  | 
        
        
            | 
            | 
           179 | 
                               $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_NEW_TOPIC."]", 1, "Create New Topics")."  ".
  | 
        
        
            | 
            | 
           180 | 
                               $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_EDIT."]", 1, "Edit Their Posts")."<br />".
  | 
        
        
            | 
            | 
           181 | 
                               $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_ATTACH."]", 1, "Attach Files")."<br />".
  | 
        
        
            | 
            | 
           182 | 
                               $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_MODERATE_MESSAGES."]", 1, "Moderate Messages")."  ".
  | 
        
        
            | 
            | 
           183 | 
                               $frm->checkbox("new_permissions[".PHORUM_USER_ALLOW_MODERATE_USERS."]", 1, "Moderate Users")."  ";
  | 
        
        
            | 
            | 
           184 | 
              | 
        
        
            | 
            | 
           185 | 
              | 
        
        
            | 
            | 
           186 | 
                   $arr[]="Add A Forum...";
  | 
        
        
            | 
            | 
           187 | 
                   foreach($forums as $forum_id=>$forum){
  | 
        
        
            | 
            | 
           188 | 
                       if(empty($group["permissions"][$forum_id]) && $forum['folder_flag'] == 0)
  | 
        
        
            | 
            | 
           189 | 
                           $arr[$forum_id]=$forum["name"];
  | 
        
        
            | 
            | 
           190 | 
                   }
  | 
        
        
            | 
            | 
           191 | 
              | 
        
        
            | 
            | 
           192 | 
                   if(count($arr)>1)
  | 
        
        
            | 
            | 
           193 | 
                       $frm->addrow($frm->select_tag("new_forum", $arr), $perm_frm);
  | 
        
        
            | 
            | 
           194 | 
              | 
        
        
            | 
            | 
           195 | 
              | 
        
        
            | 
            | 
           196 | 
                   ksort($group["permissions"]);
  | 
        
        
            | 
            | 
           197 | 
                   if(is_array($group["permissions"])){
  | 
        
        
            | 
            | 
           198 | 
                       foreach($group["permissions"] as $forum_id=>$perms){
  | 
        
        
            | 
            | 
           199 | 
                           $perm_frm = $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_READ."]", 1, "Read", $perms & PHORUM_USER_ALLOW_READ)."  ".
  | 
        
        
            | 
            | 
           200 | 
                                       $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_REPLY."]", 1, "Reply", $perms & PHORUM_USER_ALLOW_REPLY)."  ".
  | 
        
        
            | 
            | 
           201 | 
                                       $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_NEW_TOPIC."]", 1, "Create New Topics", $perms & PHORUM_USER_ALLOW_NEW_TOPIC)."  ".
  | 
        
        
            | 
            | 
           202 | 
                                       $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_EDIT."]", 1, "Edit Their Posts", $perms & PHORUM_USER_ALLOW_EDIT)."<br />".
  | 
        
        
            | 
            | 
           203 | 
                                       $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_ATTACH."]", 1, "Attach Files", $perms & PHORUM_USER_ALLOW_ATTACH)."<br />".
  | 
        
        
            | 
            | 
           204 | 
                                       $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_MODERATE_MESSAGES."]", 1, "Moderate Messages", $perms & PHORUM_USER_ALLOW_MODERATE_MESSAGES)."  ".
  | 
        
        
            | 
            | 
           205 | 
                                       $frm->checkbox("permissions[$forum_id][".PHORUM_USER_ALLOW_MODERATE_USERS."]", 1, "Moderate Users", $perms & PHORUM_USER_ALLOW_MODERATE_USERS)."  ".
  | 
        
        
            | 
            | 
           206 | 
              | 
        
        
            | 
            | 
           207 | 
                           $frm->hidden("forums[$forum_id]", $forum_id);
  | 
        
        
            | 
            | 
           208 | 
              | 
        
        
            | 
            | 
           209 | 
                           $row=$frm->addrow($forums[$forum_id]["name"]."<br />".$frm->checkbox("delforum[$forum_id]", 1, "Delete"), $perm_frm);
  | 
        
        
            | 
            | 
           210 | 
              | 
        
        
            | 
            | 
           211 | 
                       }
  | 
        
        
            | 
            | 
           212 | 
                   }
  | 
        
        
            | 
            | 
           213 | 
              | 
        
        
            | 
            | 
           214 | 
                   $frm->show();
  | 
        
        
            | 
            | 
           215 | 
              | 
        
        
            | 
            | 
           216 | 
               }
  | 
        
        
            | 
            | 
           217 | 
              | 
        
        
            | 
            | 
           218 | 
               if(empty($_REQUEST["edit"])){
  | 
        
        
            | 
            | 
           219 | 
              | 
        
        
            | 
            | 
           220 | 
                   $frm =& new PhorumInputForm ("", "post");
  | 
        
        
            | 
            | 
           221 | 
              | 
        
        
            | 
            | 
           222 | 
                   $frm->addbreak("Phorum Group Admin");
  | 
        
        
            | 
            | 
           223 | 
              | 
        
        
            | 
            | 
           224 | 
                   $frm->hidden("module", "groups");
  | 
        
        
            | 
            | 
           225 | 
              | 
        
        
            | 
            | 
           226 | 
                   $frm->hidden("section", "add");
  | 
        
        
            | 
            | 
           227 | 
              | 
        
        
            | 
            | 
           228 | 
                   $frm->addrow("Add A Group:", $frm->text_box("group_name", "", 50));
  | 
        
        
            | 
            | 
           229 | 
              | 
        
        
            | 
            | 
           230 | 
                   $frm->show();
  | 
        
        
            | 
            | 
           231 | 
              | 
        
        
            | 
            | 
           232 | 
                   echo "<hr class=\"PhorumAdminHR\" />";
  | 
        
        
            | 
            | 
           233 | 
                   echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
  | 
        
        
            | 
            | 
           234 | 
                   echo "<input type=\"hidden\" name=\"module\" value=\"groups\">\n";
  | 
        
        
            | 
            | 
           235 | 
                   echo "<input type=\"hidden\" name=\"action\" value=\"deleteGroups\">\n";
  | 
        
        
            | 
            | 
           236 | 
                   echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"PhorumAdminTable\" width=\"100%\">\n";
  | 
        
        
            | 
            | 
           237 | 
                   echo "<tr>\n";
  | 
        
        
            | 
            | 
           238 | 
                   echo "    <td class=\"PhorumAdminTableHead\">Group</td>\n";
  | 
        
        
            | 
            | 
           239 | 
                   echo "    <td class=\"PhorumAdminTableHead\">Delete</td>\n";
  | 
        
        
            | 
            | 
           240 | 
                   echo "</tr>\n";
  | 
        
        
            | 
            | 
           241 | 
              | 
        
        
            | 
            | 
           242 | 
                   foreach($groups as $group){
  | 
        
        
            | 
            | 
           243 | 
                       echo "<tr>\n";
  | 
        
        
            | 
            | 
           244 | 
                       echo "    <td class=\"PhorumAdminTableRow\"><a href=\"$_SERVER[PHP_SELF]?module=groups&edit=1&group_id={$group['group_id']}\">".htmlspecialchars($group['name'])."</a></td>\n";
  | 
        
        
            | 
            | 
           245 | 
                       echo "    <td class=\"PhorumAdminTableRow\">Delete? <input type=\"checkbox\" name=\"deleteIds[]\" value=\"{$group['group_id']}\"></td>\n";
  | 
        
        
            | 
            | 
           246 | 
                       echo "</tr>\n";
  | 
        
        
            | 
            | 
           247 | 
                   }
  | 
        
        
            | 
            | 
           248 | 
                   echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Delete Selected\"></td></tr>";
  | 
        
        
            | 
            | 
           249 | 
                   echo "</table></form>\n";
  | 
        
        
            | 
            | 
           250 | 
              | 
        
        
            | 
            | 
           251 | 
               }
  |