Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.78 KB | None | 0 0
  1. <?php
  2.  
  3. # Function to connect with the database.
  4. function connect(){
  5.   mysql_connect("localhost","ehab","ehab") or die(mysql_error());
  6.   mysql_select_db("ehab") or die(mysql_error());
  7. }
  8.  
  9. # Function to close the database connection.
  10. function destroy(){
  11.   mysql_close();   
  12. }
  13.  
  14. function update_profile($username){
  15.   connect();
  16.   if(isset($_POST['update'])){
  17.     #Make the changes in the database
  18.    mysql_query("UPDATE users SET email = '".$_POST["email"]."' WHERE email = '$username'") or die(mysql_error());
  19.     mysql_query("UPDATE users SET fname = '".$_POST["fname"]."' WHERE email = '$username'") or die(mysql_error());
  20.     mysql_query("UPDATE users SET lname = '".$_POST["lname"]."' WHERE email = '$username'") or die(mysql_error());
  21.     mysql_query("UPDATE users SET country = '".$_POST["country"]."' WHERE email = '$username'") or die(mysql_error());
  22.     mysql_query("UPDATE users SET city = '".$_POST["city"]."' WHERE email = '$username'") or die(mysql_error());
  23.     #Check if the password needs changing
  24.     if(!empty($_POST['password'])){
  25.       #Check for a minimum length of the password
  26.       if(strlen($_POST['password']) < 6){
  27.         echo '<p><span class="error">Password has not been updated. Must be minimum 6 characters!</span> <a href="editprofile.php">Go back</a></p>';  
  28.       }else{
  29.         #Update the password
  30.         mysql_query("UPDATE users SET password = '".md5($_POST["password"])."' WHERE email = '$username'") or die(mysql_error());
  31.       }
  32.     }
  33.     #Update the session information
  34.     $_SESSION["admin"] = $_POST["email"];
  35.     echo '<p>Profile has been updated!</p>';
  36.   }else{
  37.     #Get all the user information and display it.
  38.     $user = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE email = '$username'"));
  39.     echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
  40.             <table id="hor-zebra" style="width: 80%;">
  41.                 <tbody>
  42.                     <tr class="odd">
  43.                         <td>E-mail</td>
  44.                         <td><input type="text" name="email" value="'.$user['email'].'" /></td>
  45.                     </tr>
  46.                     <tr>
  47.                         <td>Password</td>
  48.                         <td><input type="password" name="password" value="'.$user['password'].'" /> <span style="font-size: 0.8em;">(Leave blank to keep current password)</span></td>
  49.                     </tr>
  50.                     <tr class="odd">
  51.                         <td>First name</td>
  52.                         <td><input type="text" name="fname" value="'.$user['fname'].'" /></td>
  53.                     </tr>
  54.                     <tr>
  55.                         <td>Last name</td>
  56.                         <td><input type="text" name="lname" value="'.$user['lname'].'" /></td>
  57.                     </tr>
  58.                     <tr class="odd">
  59.                         <td>Country</td>
  60.                         <td><input type="text" name="country" value="'.$user['country'].'" /></td>
  61.                     </tr>
  62.                     <tr>
  63.                         <td>City</td>
  64.                         <td><input type="text" name="city" value="'.$user['city'].'" /></td>
  65.                     </tr>
  66.                     <tr>
  67.                         <td><img src="img/reg_arrow.gif"></td>
  68.                         <td><input type="submit" value="Update Profile" name="update" /></td>
  69.                     </tr>
  70.                 </tbody>
  71.             </table>
  72.         </form>';
  73.   }
  74.   destroy();
  75. }
  76.  
  77. function addmodule($go,$error){
  78.     if($go == "Success"){
  79.         echo '<p>Audio file has been successfully uploaded, now it\'s time to  <a href="addcontent.php?mp3='.$error.'">add content</a> or <a href="addproject.php?go=Another&error='.$error.'">add another audio file</a>.';
  80.     }
  81.     if($go == "Another"){
  82.             echo '<p>Please upload another audio file.</p>';
  83.             echo '<form enctype="multipart/form-data" method="post" action="upload.php?error='.$error.'" onsubmit="startUpload();">
  84.                 <p id="f1_upload_process" style="visibility: hidden; text-align: center;">Uploading...<img src="loader.gif" /></p>
  85.                     <p id="f1_upload_form" align="center"><br/>
  86.                         <label><input type="hidden" name="amount" type="text" id="amount" /></label>
  87.                         <label>File: <input name="myfile" type="file" size="30" /></label>
  88.                         <label><input type="submit" name="submitBtn" value="Upload" /></label>
  89.                     </p>
  90.               </form>';
  91.             echo '<div><p>Audio files uploaded so far: <br />';
  92.             print "<ul>";
  93.             $songs = explode("***", $error);
  94.             for($i=0;$i<count($songs);$i++){
  95.                 echo "<li>".$songs[$i]."</li>"; //Hier nog de remove option
  96.             }
  97.             echo '</p></div>';
  98.     }
  99.     if($go == "Error" || empty($go)){
  100.         echo '<p>Please upload an audio file.</p>';
  101.         echo '<form enctype="multipart/form-data" method="post" action="upload.php" onsubmit="startUpload();">
  102.                 <p id="f1_upload_process" style="visibility: hidden; text-align: center;">Uploading...<img src="loader.gif" /></p>
  103.                 <p id="f1_upload_form" align="center"><br/>
  104.                     <label><input type="hidden" name="amount" type="text" id="amount" /></label>
  105.                     <label>File: <input name="myfile" type="file" size="30" /></label>
  106.                     <label><input type="submit" name="submitBtn" value="Upload" /></label>
  107.                 </p>
  108.                 <p><span class="error">'.$error.'</span></p>
  109.               </form>';
  110.     }
  111.    
  112. }
  113.  
  114. function show_add_module_form($mp3){
  115.     if(!$_POST){
  116.         echo '<p>The audio file has been successfully uploaded and will be inserted automaticly within the content. Now you have to add the content.</p>';
  117.         echo '<form action="addcontent.php" method="post">
  118.                 <input type="hidden" value="'.$mp3.'" name="mp3" />
  119.                 <input type="text" value="Name of module?" name="modulename" />
  120.                 <p>
  121.                   <textarea class="ckeditor" cols="80" id="editorcontent" name="editorcontent" rows="10"><p>This is some <strong>sample text</strong>.</textarea>
  122.                 </p>
  123.                 <p>
  124.                   <input type="submit" value="Submit" name="submitcontent"/>
  125.                 </p>
  126.               </form>';
  127.     }else{
  128.         $econtent = $_POST["editorcontent"];
  129.         $songs = explode("***", $_POST["mp3"]);
  130.         $amount = count($songs);
  131.         for($i=0;$i<count($songs);$i++){
  132.             $econtent.= "<p>\n".$songs[$i]."</p>\n";
  133.             //echo $songs[$i]." <br />";
  134.         }
  135.         $modulename = $_POST["modulename"];
  136.         connect();
  137.         mysql_query("INSERT INTO modules VALUES (null,'$modulename','$econtent')");
  138.         echo '<p>Module has been created with success!</p>';
  139.         destroy();
  140.     }
  141. }
  142.  
  143. function footer(){
  144.     //To be added  
  145. }
  146. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement