ThLoser

Untitled

Jul 5th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.36 KB | None | 0 0
  1. <?php
  2. if(!isuseradmin($userID) OR mb_substr(basename($_SERVER['REQUEST_URI']),0,16) != "admincenter2.php") die($_language->module['access_denied']);
  3.  
  4. ?>
  5. <script>
  6. jQuery(function(){
  7.         jQuery('.button').click(function(){
  8.               jQuery('.Rights').hide();
  9.               jQuery('#div'+$(this).attr('target')).show();
  10.         });
  11. });
  12.     </script>
  13.  
  14.  
  15. <h2>Medlemmar</h2>
  16. <?php
  17.     $sql = mysql_query("
  18.     SELECT ".PREFIX."user.username, ".PREFIX."user.registerdate, ".PREFIX."user.userID, ".PREFIX."user_groups.userID, ".PREFIX."user_groups.news, ".PREFIX."user_groups.user, ".PREFIX."user_groups.forum, ".PREFIX."user_groups.moderator, ".PREFIX."user_groups.super
  19.     FROM ".PREFIX."user
  20.     LEFT JOIN ".PREFIX."user_groups
  21.     ON ".PREFIX."user.userID = ".PREFIX."user_groups.userID
  22.     ");
  23.     if (mysql_num_rows($sql) == 0) {
  24.         echo '<div class="alert alert-box alert-error">Finns inga medlemmar.</div>';
  25.     }
  26.     else{
  27.         echo '<form method="post">';
  28.         echo '<table cellspacing="0" cellpadding="0" width="100%" class="table table-striped">';
  29.         echo '<tr><td width="200"><strong>Användarnamn</strong></td><td><strong>Ålder</strong></td><td><strong>Blev medlem</strong></td><td align="right"></td></tr>';
  30.         while ($rad = mysql_fetch_array($sql)) {
  31.             if (isset($_POST['editadmin'])) {
  32.                 if (mysql_result(mysql_query("SELECT COUNT(*) AS ANTAL FROM ".PREFIX."user_groups WHERE userID='".$_POST['userID']."'"),0) > 0) {
  33.             // Following example is part of a response at the following url.
  34.             // http://www.hamsterpaj.net/diskussionsforum/gaa_till_post.php?post_id=4265149
  35.            
  36.             // Items to iterate through (sql-key => post-value)
  37.             $postItems = array(
  38.                     'newsadmin',
  39.                     'forumpolis',
  40.                     'moderator',
  41.                     'memberadmin',
  42.                     'superadmin'
  43.             );
  44.      
  45.             // Check if each individual item is set and assign an integer for state
  46.             // User altered information will be disregarded and changed to either a 0 or 1
  47.             // depending on the key being assigned or not, so no filtering necessary
  48.             foreach ($postItems as $postItem){
  49.                     $_POST[$postItem] = (!isset($_POST[$postItem])) ? 0 : 1;
  50.             }
  51.            
  52.             // Cast userID to an integer only, non-numerical information will return 0
  53.             $_POST['userID'] = (int)$_POST['userID'];
  54.            
  55.             // Construct query
  56.             $sql2 = 'UPDATE user_groups SET news='.$_POST['newsadmin'].', forum='.$_POST['forumpolis'].', moderator='.$_POST['moderator'].', user='.$_POST['memberadmin'].', super='.$_POST['superadmin'].' WHERE userID='.$_POST['userID'];
  57.      
  58.             // Dump variable
  59.             var_dump($sql);
  60.             }
  61.             }
  62.             $res = mysql_query("SELECT birthday, DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW()) - TO_DAYS(birthday)), '%Y') 'age' FROM ".PREFIX."user WHERE userID = '".$rad['userID']."'");
  63.             $cur = mysql_fetch_array($res);
  64.             $birthday = (int)$cur['age']." år ";
  65.             $reg = date('Y/m/d, H:i', $rad['registerdate']);
  66.             $news = ($rad['news'] == "1" && $rad['super'] == 0)  ? 'checked="checked"' : '';
  67.             $memberadmin = ($rad['user'] == "1" && $rad['super'] == 0)  ? 'checked="checked"' : '';
  68.             $moderator = ($rad['moderator'] == "1" && $rad['super'] == 0)  ? 'checked="checked"' : '';
  69.             $polis = ($rad['forum'] == "1" && $rad['super'] == 0)  ? 'checked="checked"' : '';
  70.             $superadmin = ($rad['super'] == "1")  ? 'checked="checked"' : 'none';
  71.             echo '<tr><td width="400"><a href="?p=user&id='.$rad['userID'].'" target="_BLANK">'.$rad['username'].'</a></td><td>'.$birthday.'</td><td>'.$reg.'</td><td align="right"><img src="../img/pencil.png"><img src="../img/user_suit.png" target="'.$rad['userID'].'" title="Rättigheter" class="button" style="cursor:pointer;margin-left: 5px; margin-right: 5px;"><img src="../img/delete.png"></td></tr>';
  72.             echo '<tr class="Rights" id="div'.$rad['userID'].'"><td colspan="4">';
  73.                 echo '<h2>Ändra Rättigheter: '.getUsername($rad['userID']).' </h2>';
  74.                 echo '<table cellspacing="0" cellpadding="0" width="100%">';
  75.                 echo '<tr><td width="350"><strong>Nyhetsadmin</strong> (<small>Nyheter, Artiklar, Guider</small>)</td><td align="right"><input type="checkbox" name="newsadmin" value="1" '.$news.'></td></tr>';
  76.                 echo '<tr><td width="350"><strong>Medlemsadmin</strong> (<small>Medlemmar, Administratörer</small>)</td><td align="right"><input type="checkbox" name="memberadmin" value="1" '.$memberadmin.'></td></tr>';
  77.                 echo '<tr><td width="350"><strong>Moderator</strong> (<small>Trådar, Kategorier, Poliser</small>)</td><td align="right"><input type="checkbox" name="moderator" value="1" '.$moderator.'></td></tr>';
  78.                 echo '<tr><td width="350"><strong>Forumpolis</strong> (<small>Trådar, Kommentarer</small>)</td><td align="right"><input type="checkbox" name="forumpolis" value="1" '.$polis.'></td></tr>';
  79.                 echo '<tr><td width="350"><strong>Super</strong> (<small>Alla rättigheter</small>)</td><td align="right"><input type="checkbox" name="superadmin" value="1" '.$superadmin.'></td></tr>';
  80.                 echo '</table><input type="hidden" name="userID" value="'.$rad['userID'].'">';
  81.                 echo '<input type="submit" name="editadmin" value="Spara" class="btn btn-primary btn-small" style="font-weight:bold; width:100%;">';
  82.            
  83.            
  84.             echo '</td></tr>';
  85.        
  86.         }
  87.         echo '</table></form>';
  88.     }
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment