Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.64 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  *Edit profile Page
  5.  */
  6.  
  7. session_start();
  8. $con = mysqli_connect("localhost","root","","WebsiteDB");
  9.  
  10. if (mysqli_connect_errno())
  11.  
  12. {
  13.  
  14.     echo "MySQLi Connection was not established: " . mysqli_connect_error();
  15.  
  16. }
  17.  
  18. ?>
  19.  
  20. <!DOCTYPE HTML>
  21. <head>
  22.    <script type="text/javascript" src="./../js/jquery-3.2.1.min.js"></script>
  23.     <script type = "text/javascript" src="./../plugin/tinymce/tinymce.min.js"></script>
  24.  
  25. </head>
  26. <div id="Edit-Profile">
  27.     <form method="POST" action="./editprofile.php">
  28. <?php
  29.  
  30.     $name = $_GET["username"];
  31.     $yourroleid = $_SESSION['rid'];
  32.     $yourownuid =  $_SESSION['uid'];
  33.     $sqlq = "Select UserNameID, userName, Role, IP_ADD , Notes, Welcome_Note, RoleName FROM UserName INNER JOIN Role ON UserName.Role=Role.RoleID WHERE UsernameID = $name";
  34.  
  35.     $runq = mysqli_query($con,$sqlq);
  36.     $resultrow = mysqli_fetch_row($runq);
  37.     $usnid = $resultrow[0];
  38.     $usn = $resultrow[1];
  39.     $currentroleid = $resultrow[2];
  40.     $ipadd= $resultrow[3];
  41.     $notes = $resultrow[4];
  42.     $Welcomenote = $resultrow[5];
  43.     $rank = $resultrow[6];
  44.     $checkifexist = mysqli_num_rows($runq);
  45.     /**
  46.      Obtaining Roles
  47.      */
  48.     //Connect to our MySQL database using the PDO extension.
  49.     $pdo = new PDO('mysql:host=localhost;dbname=WebsiteDB', 'root', '');
  50.     $obtainallroles = "Select * FROM Role";
  51.     //Prepare the select statement.
  52.     $stmt = $pdo->prepare($obtainallroles);
  53.  
  54.     //Execute the statement.
  55.     $stmt->execute();
  56.  
  57.     //Retrieve the rows using fetchAll.
  58.     $allroles = $stmt->fetchAll();
  59.  
  60.     if ($checkifexist == 0)
  61.     {
  62.         header("Location: ./editprofile.php?username=". $yourownuid); //checks if user exist, if not, redirect to your own page
  63.         die();
  64.     }
  65.  
  66. ?>
  67.  
  68.  
  69.     <?php if ($yourroleid == 1) : ?> <!-- If SysOP -->
  70.     <p>Username: <?php echo $usn;?></p>
  71.     <p>IP Address: <?php echo $ipadd;?></p>
  72.     <p>Country:</p>
  73.     <!-- Modified an online script to loop through , ensures that the dropdown shows your current rank! -->
  74.     <p>Rank:
  75.         <select name="Rank"><?php foreach($allroles as $rn): ?>
  76.                     <?php if ($currentroleid != $rn['RoleID']) : ?>
  77.                     <option value="<?= $rn['RoleID']; ?>"><?= $rn['RoleName']; ?></option>
  78.                     <?php else:?>
  79.                     <option selected="selected" value="<?= $rn['RoleID']; ?>"><?= $rn['RoleName']; ?></option>
  80.                     <?php endif; ?>
  81.                     <?php endforeach; ?>
  82.         </select> </p>
  83.     <p>Password: <input type = "password" class="input" placeholder="Enter your new Password here" name="pw1"></br>
  84.             <input type = "password" class="input" placeholder="Enter it again" name="pw2"></br>
  85.             <input type="checkbox"></p>
  86.     <p>Profile Note: </p>
  87.         <script type = "text/javascript">
  88.             tinymce.init({
  89.                 selector: 'textarea',
  90.                 branding: false,
  91.                 // change this value according to your HTML
  92.                 height : 300,
  93.                 width:700,
  94.             });</script>
  95.  
  96.         <textarea id = "test"><?php echo $notes; ?></textarea>
  97.     <p>Welcome Page:
  98.  
  99.         <textarea id = "test"><?php echo $Welcomenote; ?></textarea>
  100.     </p>
  101.     <div id="EditButton">
  102.         <button type="submit" name="btnEdit" id="Edit1" value="Edit">Edit</button>
  103.     </div>
  104.    
  105.     <?php elseif ($yourroleid == 2): ?> <!-- else if Administrator -->
  106.         <?php if ($currentroleid == 1 OR $currentroleid == $yourroleid) : ?>
  107.          <!--If Userpage is an admin or SysOP - Only SysOPs can edit other SysOPs and Admins, Admins can only edit classes below them! Admins will not be able to view notes for other Admins or SysOP-->
  108.         <p>Username: <?php echo $usn;?></p>
  109.         <p>IP Address: <?php echo $ipadd;?></p>
  110.         <p>Country:</p>
  111.         <!-- Modified an online script to loop through , ensures that the dropdown shows your current rank! -->
  112.         <p>Rank: <?php echo $rank; ?></p>
  113.         <p>Welcome Page: <?php echo $Welcomenote; ?></p>
  114.         <div id="EditButton">
  115.             <button type="submit" name="btnEdit" id="Edit1" value="Edit">Edit</button>
  116.         </div>
  117.             <?php else: ?>
  118.             <p>Username: <?php echo $usn;?></p>
  119.             <p>IP Address: <?php echo $ipadd;?></p>
  120.             <p>Country:</p>
  121.             <!-- Modified an online script to loop through , ensures that the dropdown shows your current rank! -->
  122.             <p>Rank:
  123.                 <select name="Rank"><?php foreach($allroles as $rn): ?>
  124.                         <?php if ($currentroleid != $rn['RoleID']) : ?>
  125.                             <option value="<?= $rn['RoleID']; ?>"><?= $rn['RoleName']; ?></option>
  126.                         <?php else:?>
  127.                             <option selected="selected" value="<?= $rn['RoleID']; ?>"><?= $rn['RoleName']; ?></option>
  128.                         <?php endif; ?>
  129.                     <?php endforeach; ?>
  130.                 </select> </p>
  131.             <p>Profile Note: <?php echo $notes; ?></p>
  132.             <p>Welcome Page: <?php echo $Welcomenote; ?></p>
  133.         <div id="EditButton">
  134.             <button type="submit" name="btnEdit" id="Edit1" value="Edit">Edit</button>
  135.         </div>
  136.  
  137.         <?php endif; ?>
  138.     <?php elseif ($name == $yourownuid): ?> <!-- else if you are logged in as your own user and browsing your own page -->
  139.         print "self";
  140.     <?php else: ?>
  141.     <?php endif;  ?>
  142.         <?php
  143.         if (isset($_POST['btnEdit']))
  144.         {
  145.             echo "good job";
  146.         }
  147.         else
  148.         {
  149.             echo "bad";
  150.         }
  151.         ?>
  152.  
  153. </form>
  154. </div>
  155.  
  156.  
  157. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement