PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/mybookbag/contact.php

https://bitbucket.org/s2223902/mybookbag
PHP | 178 lines | 176 code | 2 blank | 0 comment | 1 complexity | 30441cd7078a4cf438d0f790b9a94640 MD5 | raw file
  1. <?php
  2. session_start();
  3. include('db_connection.php');
  4. include('functions.php');
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  10. <link href="css/toolbar.css" rel="stylesheet" type="text/css" />
  11. <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  12. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  13. <link rel="stylesheet" href="css/formstyles.css" type="text/css" />
  14. <script type="text/javascript" src="js/Placeholders.js"></script>
  15. <script type="text/javascript">
  16. Placeholders.init({
  17. live: true,
  18. hideOnFocus: true});
  19. </script>
  20. <title><?php echo $_SESSION['username'];?>'s Admin Contact</title>
  21. </head>
  22. <body>
  23. <div id="carbonForm2">
  24. <div id="logo2">
  25. <img src="img/logo.png" />
  26. <p>Welcome <b><?php echo $_SESSION['username'];?></b></p>
  27. </div>
  28. <ul id="nav">
  29. <li><a href="page.php">Home</a></li>
  30. <li><a href="mybooks.php">MyBookBag</a>
  31. <ul>
  32. <li><a href="mybooks.php">My Books</a></li>
  33. <li><a href="myebooks.php">My eBooks</a></li>
  34. <li><a href="myjournals.php">My journals</a></li>
  35. <li><a href="adddoc.php">Add Books</a></li>
  36. </ul>
  37. </li>
  38. <li><a href="friends.php">My Friends</a>
  39. <ul>
  40. <li><a href="friends.php">My Friends</a></li>
  41. <li><a href="messages.php">Messages (<?php echo checkMessages();?>)</a></li>
  42. <li><a href="addfriend.php">Add friends</a></li>
  43. <li><a href="requests.php">Friend Requests</a></li>
  44. </ul>
  45. </li>
  46. <li><a href="settings.php">Settings</a>
  47. <ul>
  48. <li><a href="passreset.php">Change Password</a></li>
  49. </ul>
  50. </li>
  51. <li class="current"><a href="contact.php">Contact</a></li>
  52. <li><a href="logout.php">Log Out</a></li>
  53. </ul>
  54. <div class="fieldContainer">
  55. <?php
  56. //We check if the user is logged
  57. if(isset($_SESSION['username']))
  58. {
  59. $form = true;
  60. $otitle = '';
  61. $omessage = '';
  62. if(isset($_POST['title'], $_POST['message']))
  63. {
  64. $otitle = $_POST['title'];
  65. $omessage = $_POST['message'];
  66. //We remove slashes depending on the configuration
  67. if(get_magic_quotes_gpc())
  68. {
  69. $otitle = stripslashes($otitle);
  70. $omessage = stripslashes($omessage);
  71. }
  72. //We check if all the fields are filled
  73. if($_POST['title']!='' and $_POST['message']!='')
  74. {
  75. //We protect the variables
  76. $title = mysql_real_escape_string($otitle);
  77. $message = mysql_real_escape_string(nl2br(htmlentities($omessage, ENT_QUOTES, 'UTF-8')));
  78. //We check if Admin exists
  79. $query = mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="Admin"') or die ("fetch".mysql_error());
  80. $dn1 = mysql_fetch_array($query) or die("fetch".mysql_error());
  81. if($dn1['recip']==1)
  82. {
  83. //We check if the Admin is not the actual user
  84. if($dn1['recipid']!=$_SESSION['id'])
  85. {
  86. $id = $dn1['npm']+1;
  87. //We send the message
  88. if(mysql_query('insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "1", "'.$title.'", "'.$_SESSION['id'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")')or die ("insertdata".mysql_error()))
  89. {
  90. ?>
  91. <div class="message">The message has successfully been sent.<br />
  92. <a href="messages.php">List of my Personal messages</a></div>
  93. <?php
  94. $form = false;
  95. }
  96. else
  97. {
  98. //Otherwise, we say that an error occured
  99. $error = 'An error occurred while sending the message';
  100. }
  101. }
  102. else
  103. {
  104. //Otherwise, we say the user cannot send a message to himself
  105. $error = 'You cannot send a message to yourself.';
  106. }
  107. }
  108. else
  109. {
  110. //Otherwise, we say the recipient does not exists
  111. $error = 'The recipient does not exist.';
  112. }
  113. }
  114. else
  115. {
  116. //Otherwise, we say a field is empty
  117. $error = 'A field is empty. Please fill of the fields.';
  118. }
  119. }
  120. elseif(isset($_GET['recip']))
  121. {
  122. //We get the username for the recipient if available
  123. $orecip = $_GET['recip'];
  124. }
  125. if($form)
  126. {
  127. //We display a message if necessary
  128. if(isset($error))
  129. {
  130. echo '<div class="message">'.$error.'</div>';
  131. }
  132. //We display the form
  133. ?>
  134. <div class="content">
  135. <h1>New Personal Message</h1>
  136. <form action="contact.php" method="post">
  137. Please fill the following form to send a message to the Admin<br />
  138. <div class="formRow">
  139. <div class="field">
  140. <input type="text" value="<?php echo htmlentities($otitle, ENT_QUOTES, 'UTF-8'); ?>" id="title" name="title" placeholder="Title" /><br />
  141. </div>
  142. </div>
  143. <div class="formRow">
  144. <div class="field">
  145. <textarea cols="40" rows="5" id="message" name="message" placeholder="Message"><?php echo htmlentities($omessage, ENT_QUOTES, 'UTF-8'); ?></textarea><br />
  146. </div>
  147. </div>
  148. <div class="formRow">
  149. <div class="field">
  150. <br/><input type="submit" id="submit" value="Send" />
  151. </div>
  152. </div>
  153. </form>
  154. </div>
  155. </div>
  156. </div>
  157. <?php
  158. }
  159. }
  160. else
  161. {
  162. echo '<div class="message">You must be logged to access this page.</div>';
  163. }
  164. ?>
  165. </body>
  166. </html>