[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_admin/ -> userclass2.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_admin/userclass2.php,v $
  14  |     $Revision: 1.22 $
  15  |     $Date: 2006/12/24 13:27:24 $
  16  |     $Author: mrpete $
  17  +----------------------------------------------------------------------------+
  18  */
  19  require_once ("../class2.php");
  20  if (!getperms("4")) {
  21      header("location:".e_BASE."index.php");
  22       exit;
  23  }
  24  $e_sub_cat = 'userclass';
  25  require_once ("auth.php");
  26  require_once(e_HANDLER."userclass_class.php");
  27  $uclass = new e_userclass;
  28  
  29  function check_allowed($class_id)
  30  {
  31      global $sql;
  32      if (!$sql->db_Select('userclass_classes', '*', "userclass_id = {$class_id}"))
  33      {
  34          header("location:".SITEURL);
  35          exit;
  36      }
  37      $row = $sql->db_Fetch();
  38      if (!getperms('0') && !check_class($row['userclass_editclass']))
  39      {
  40          header("location:".SITEURL);
  41          exit;
  42      }
  43  }
  44  
  45  if (strstr(e_QUERY, 'clear'))
  46  {
  47      $tmp = explode('.', e_QUERY);
  48      $class_id = $tmp[1];
  49      check_allowed($class_id);
  50      if ($sql->db_Select('user', 'user_id, user_class', "user_class = '{$class_id}' OR user_class REGEXP('^{$class_id},') OR user_class REGEXP(',{$class_id},') OR user_class REGEXP(',{$class_id}$')"))
  51      {
  52          while ($row = $sql->db_Fetch())
  53          {
  54              $uidList[$row['user_id']] = $row['user_class'];
  55          }
  56          $uclass->class_remove($class_id, $uidList);
  57          $message = UCSLAN_1;
  58      }
  59  }
  60  elseif(e_QUERY)
  61  {
  62      $tmp2 = explode('-', e_QUERY);
  63      $class_id = $tmp2[0];
  64      check_allowed($class_id);
  65      $message = UCSLAN_2;
  66  
  67      if ($sql->db_Select('user', 'user_id, user_class', "user_class = '{$class_id}' OR user_class REGEXP('^{$class_id},') OR user_class REGEXP(',{$class_id},') OR user_class REGEXP(',{$class_id}$')"))
  68      {
  69          while ($row = $sql->db_Fetch())
  70          {
  71              $uidList[$row['user_id']] = $row['user_class'];
  72          }
  73          $uclass->class_remove($class_id, $uidList);
  74      }
  75      unset($uidList);
  76      if ($sql->db_Select('user', 'user_id, user_class', "user_id IN({$tmp2[1]})"))
  77      {
  78          while ($row = $sql->db_Fetch())
  79          {
  80              $uidList[$row['user_id']] = $row['user_class'];
  81          }
  82          $uclass->class_add($class_id, $uidList);
  83      }
  84  }
  85  
  86  if (isset($_POST['delete']))
  87  {
  88      $class_id = $_POST['existing'];
  89      check_allowed($class_id);
  90      if ($_POST['confirm']) {
  91          $sql->db_Delete('userclass_classes', "userclass_id='".$_POST['existing']."' ");
  92          if ($sql->db_Select('user', 'user_id, user_class', "user_class = '{$class_id}' OR user_class REGEXP('^{$class_id},') OR user_class REGEXP(',{$class_id},') OR user_class REGEXP(',{$class_id}$')"))
  93          {
  94              while ($row = $sql->db_Fetch())
  95              {
  96                  $uidList[$row['user_id']] = $row['user_class'];
  97              }
  98              $uclass->class_remove($class_id, $uidList);
  99          }
 100          if (isset($pref['frontpage'][$class_id]))
 101          {
 102              unset($pref['frontpage'][$class_id]);
 103              save_prefs();
 104          }
 105          $message = UCSLAN_3;
 106      }
 107      else
 108      {
 109          $message = UCSLAN_4;
 110      }
 111  }
 112  
 113  if(isset($_POST['edit']))
 114  {
 115      check_allowed($_POST['existing']);
 116      $sql->db_Select('userclass_classes', '*', "userclass_id='".$_POST['existing']."' ");
 117      $row = $sql->db_Fetch();
 118      extract($row);
 119  }
 120  
 121  if (isset($_POST['updateclass']))
 122  {
 123      check_allowed($_POST['userclass_id']);
 124      $_POST['userclass_name'] = $tp->toDB($_POST['userclass_name']);
 125      $_POST['userclass_description'] = $tp->toDB($_POST['userclass_description']);
 126      $sql->db_Update('userclass_classes', "userclass_editclass={$_POST['userclass_editclass']}, userclass_name='".$_POST['userclass_name']."', userclass_description='".$_POST['userclass_description']."' WHERE userclass_id='".$_POST['userclass_id']."' ");
 127      $message = UCSLAN_5;
 128  }
 129  
 130  if (isset($_POST['createclass']))
 131  {
 132      if($_POST['userclass_name'])
 133      {
 134          $_POST['userclass_name'] = $tp->toDB($_POST['userclass_name']);
 135          $_POST['userclass_description'] = $tp->toDB($_POST['userclass_description']);
 136  
 137          if (getperms("0") || check_class($_POST['userclass_editclass']) && $_POST['userclass_editclass']) {
 138              $editclass = $_POST['userclass_editclass'];
 139              $i = 1;
 140              while ($sql->db_Select('userclass_classes', '*', "userclass_id='".$i."' ") && $i < 255)
 141              {
 142                  $i++;
 143              }
 144              if ($i < 255)
 145              {
 146                  $sql->db_Insert("userclass_classes", $i.", '".strip_tags($_POST['userclass_name'])."', '".$_POST['userclass_description']."',{$editclass} ");
 147              }
 148              if (!isset($pref['frontpage'][$i]))
 149              {
 150                  $pref['frontpage'][$i] = $pref['frontpage'][e_UC_GUEST];
 151                  save_prefs();
 152              }
 153              $message = UCSLAN_6;
 154          }
 155          else
 156          {
 157              header("location:".SITEURL);
 158              exit;
 159          }
 160      }
 161  }
 162  
 163  if (isset($message))
 164  {
 165      $ns->tablerender("", "<div style='text-align:center'><b>".$message."</b></div>");
 166  }
 167  
 168  $class_total = $sql->db_Select("userclass_classes", "*", "ORDER BY userclass_name", "nowhere");
 169  
 170  $text = "<div style='text-align:center'>
 171      <form method='post' action='".e_SELF."' id='classForm'>
 172      <table class='fborder' style='".ADMIN_WIDTH."'>
 173      <tr>
 174      <td class='fcaption' style='text-align:center' colspan='2'>";
 175  
 176  if ($class_total == "0")
 177  {
 178      $text .= UCSLAN_7;
 179  }
 180  else
 181  {
 182      $text .= "<span class='defaulttext'>".UCSLAN_8.":</span>
 183          <select name='existing' class='tbox'>";
 184      while ($row = $sql->db_Fetch())
 185      {
 186          if (check_class($row['userclass_editclass']) || getperms("0"))
 187          {
 188              $text .= "<option value='{$row['userclass_id']}'>{$row['userclass_name']}</option>";
 189          }
 190      }
 191      $text .= "</select>
 192          <input class='button' type='submit' name='edit' value='".LAN_EDIT."' />
 193          <input class='button' type='submit' name='delete' value='".LAN_DELETE."' />
 194          <input type='checkbox' name='confirm' value='1' /><span class='smalltext'> ".UCSLAN_11."</span>
 195          </td>
 196          </tr>";
 197  }
 198  
 199  $text .= "
 200      <tr>
 201      <td class='forumheader3' style='width:30%'>".UCSLAN_12."</td>
 202      <td class='forumheader3' style='width:70%'>
 203      <input class='tbox' type='text' size='30' maxlength='25' name='userclass_name' value='$userclass_name' /></td>
 204      </tr>
 205      <tr>
 206      <td class='forumheader3'>".UCSLAN_13."</td>
 207      <td class='forumheader3' style='width:70%'><input class='tbox' type='text' size='60' maxlength='85' name='userclass_description' value='$userclass_description' /></td>
 208      </tr>
 209      ";
 210  
 211      if(!isset($userclass_editclass))
 212      {
 213          $userclass_editclass = e_UC_ADMIN;
 214      }
 215  
 216  $text .= "
 217      <tr>
 218      <td class='forumheader3'>".UCSLAN_24."</td>
 219      <td class='forumheader3'>".r_userclass("userclass_editclass", $userclass_editclass, "off", "main,admin,classes,matchclass,public,nobody")."</td>
 220      </tr>
 221      ";
 222  
 223  $text .= "
 224      <tr><td colspan='2' style='text-align:center' class='forumheader'>";
 225  
 226  if(isset($_POST['edit']))
 227  {
 228      $text .= "<input class='button' type='submit' name='updateclass' value='".UCSLAN_14."' />
 229          <input type='hidden' name='userclass_id' value='$userclass_id' />";
 230  }
 231  else
 232  {
 233      $text .= "<input class='button' type='submit' name='createclass' value='".UCSLAN_15."' />";
 234  }
 235  
 236  $text .= "</td></tr></table>";
 237  
 238  if(isset($_POST['edit']))
 239  {
 240      $sql->db_Select("user", "user_id, user_name, user_class, user_login", "ORDER BY user_name", "no-where");
 241      $c = 0;
 242      $d = 0;
 243      while ($row = $sql->db_Fetch())
 244      {
 245          extract($row);
 246          if (check_class($userclass_id, $user_class))
 247          {
 248              $in_userid[$c] = $user_id;
 249              $in_username[$c] = $user_name;
 250              $in_userlogin[$c] = $user_login ? "(".$user_login.")" : "";
 251              $c++;
 252          }
 253          else
 254          {
 255              $out_userid[$d] = $user_id;
 256              $out_username[$d] = $user_name;
 257              $out_userlogin[$d] = $user_login ? "(".$user_login.")" : "";
 258              $d++;
 259          }
 260      }
 261  
 262      $text .= "<br /><table class='fborder' style='".ADMIN_WIDTH."'>
 263          <tr>
 264          <td class='fcaption' style='text-align:center;width:30%'>".UCSLAN_16."</td></tr>
 265          <tr>
 266          <td class='forumheader3' style='width:70%; text-align:center'>
 267  
 268          <table style='width:90%'>
 269          <tr>
 270          <td style='width:45%; vertical-align:top'>
 271          ".UCSLAN_22."<br />
 272          <select class='tbox' id='assignclass1' name='assignclass1' size='10' style='width:220px' multiple='multiple' onchange='moveOver();'>";
 273  
 274      for ($a = 0; $a <= ($d-1); $a++)
 275      {
 276          $text .= "<option value=".$out_userid[$a].">".$out_username[$a]." ".$out_userlogin[$a]."</option>";
 277      }
 278  
 279      $text .= "</select>
 280          </td>
 281          <td style='width:45%; vertical-align:top'>
 282          ".UCSLAN_23."<br />
 283          <select class='tbox' id='assignclass2' name='assignclass2' size='10' style='width:220px' multiple='multiple'>";
 284      for($a = 0; $a <= ($c-1); $a++)
 285      {
 286          $text .= "<option value=".$in_userid[$a].">".$in_username[$a]." ".$in_userlogin[$a]."</option>";
 287      }
 288      $text .= "</select><br /><br />
 289          <input class='button' type='button' value='".UCSLAN_17."' onclick='removeMe();' />
 290          <input class='button' type='button' value='".UCSLAN_18."' onclick='clearMe($userclass_id);' />
 291          <input type='hidden' name='class_id' value='$userclass_id' />
 292  
 293          </td></tr></table>
 294          </td></tr>
 295          <tr><td colspan='2' style='text-align:center' class='forumheader'>
 296          <input class='button' type='button' value='".UCSLAN_19." ".$userclass_name." ".UCSLAN_20."' onclick='saveMe($userclass_id);' />
 297          </td>
 298          </tr>
 299          </table>";
 300  
 301  }
 302  
 303  $text .= "</form>
 304      </div>";
 305  
 306  //
 307  // Show a table of all userclasses and who can manage them
 308  //
 309  // lazy get list again
 310  $class_total = $sql->db_Select("userclass_classes", "*", "ORDER BY userclass_name", "nowhere");
 311  
 312  $text .= "<br /><div style='text-align:center'>
 313      <table class='fborder' style='".ADMIN_WIDTH."'>
 314      <tr>
 315      <td class='fcaption'>".UCSLAN_12."</td>
 316      <td class='fcaption'>".UCSLAN_24."</td>
 317      <td class='fcaption'>".UCSLAN_13."</td>
 318      </tr>\n";
 319      
 320  if ($class_total == "0")
 321  {
 322      $text .= "<tr><td colspan='3'>".UCSLAN_7."</td></tr>";
 323  }
 324  else
 325  {
 326      while ($row = $sql->db_Fetch())
 327      {
 328          $rEditClass = $row['userclass_editclass'];
 329          if (check_class($rEditClass) || getperms("0"))
 330          {
 331              if(!isset($rEditClass))
 332              {
 333                  $rEditClass = e_UC_ADMIN;
 334              }
 335  
 336              $text .= "<tr>
 337              <td class='forumheader3'>{$row['userclass_name']}</td>
 338              <td class='forumheader3'>".r_userclass_name($rEditClass)."</td>
 339              <td class='forumheader3'>{$row['userclass_description']}</td>\n";
 340          }
 341      }
 342  }
 343  $text .="</table>";
 344  
 345  $ns->tablerender(UCSLAN_21, $text);
 346  
 347  require_once ("footer.php");
 348  function headerjs()
 349  {
 350  
 351      $script_js = "<script type=\"text/javascript\">
 352          //<![CDATA[
 353          // Adapted from original:  Kathi O'Shea (Kathi.O'Shea@internet.com)
 354  		function moveOver() {
 355          var boxLength = document.getElementById('assignclass2').length;
 356          var selectedItem = document.getElementById('assignclass1').selectedIndex;
 357          var selectedText = document.getElementById('assignclass1').options[selectedItem].text;
 358          var selectedValue = document.getElementById('assignclass1').options[selectedItem].value;
 359          var i;
 360          var isNew = true;
 361          if (boxLength != 0) {
 362          for (i = 0; i < boxLength; i++) {
 363          thisitem = document.getElementById('assignclass2').options[i].text;
 364          if (thisitem == selectedText) {
 365          isNew = false;
 366          break;
 367          }
 368          }
 369          }
 370          if (isNew) {
 371          newoption = new Option(selectedText, selectedValue, false, false);
 372          document.getElementById('assignclass2').options[boxLength] = newoption;
 373          document.getElementById('assignclass1').options[selectedItem].text = '';
 374          }
 375          document.getElementById('assignclass1').selectedIndex=-1;
 376          }
 377  
 378  
 379  		function removeMe() {
 380          var boxLength = document.getElementById('assignclass2').length;
 381          var boxLength2 = document.getElementById('assignclass1').length;
 382          arrSelected = new Array();
 383          var count = 0;
 384          for (i = 0; i < boxLength; i++) {
 385          if (document.getElementById('assignclass2').options[i].selected) {
 386          arrSelected[count] = document.getElementById('assignclass2').options[i].value;
 387          var valname = document.getElementById('assignclass2').options[i].text;
 388          for (j = 0; j < boxLength2; j++) {
 389          if (document.getElementById('assignclass1').options[j].value == arrSelected[count]){
 390          document.getElementById('assignclass1').options[j].text = valname;
 391          }
 392          }
 393  
 394          // document.getElementById('assignclass1').options[i].text = valname;
 395          }
 396          count++;
 397          }
 398          var x;
 399          for (i = 0; i < boxLength; i++) {
 400          for (x = 0; x < arrSelected.length; x++) {
 401          if (document.getElementById('assignclass2').options[i].value == arrSelected[x]) {
 402          document.getElementById('assignclass2').options[i] = null;
 403          }
 404          }
 405          boxLength = document.getElementById('assignclass2').length;
 406          }
 407          }
 408  
 409  		function clearMe(clid) {
 410          location.href = document.location + \"?clear.\" + clid;
 411          }
 412  
 413  		function saveMe(clid) {
 414          var strValues = \"\";
 415          var boxLength = document.getElementById('assignclass2').length;
 416          var count = 0;
 417          if (boxLength != 0) {
 418          for (i = 0; i < boxLength; i++) {
 419          if (count == 0) {
 420          strValues = document.getElementById('assignclass2').options[i].value;
 421          } else {
 422          strValues = strValues + \",\" + document.getElementById('assignclass2').options[i].value;
 423          }
 424          count++;
 425          }
 426          }
 427          if (strValues.length == 0) {
 428          //alert(\"You have not made any selections\");
 429          }
 430          else {
 431          location.href = document.location + \"?\" + clid + \"-\" + strValues;
 432          }
 433          }
 434          //]]>
 435          </script>\n";
 436      return $script_js;
 437  }
 438  
 439  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7