PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/profile.php

https://github.com/hovvit/Newsletter
PHP | 446 lines | 396 code | 44 blank | 6 comment | 41 complexity | add142214ee8386f25aaff0cc58ed967 MD5 | raw file
  1. <?php
  2. $user="";
  3. $host="";
  4. $password="";
  5. $dbname="";
  6. $cxn = mysql_connect($host,$user,$password)
  7. or die ("Couldn't connect to server");
  8. $link = mysql_select_db($dbname, $cxn);
  9. // This will run on any page where the shopping cart
  10. // accesses the DB. Prevents SQL injection through any
  11. // POST variable.
  12. foreach ($_POST as $key => $value)
  13. {
  14. $_POST[$key] = mysql_real_escape_string($value);
  15. }
  16. function safe($value)
  17. {
  18. return mysql_real_escape_string($value);
  19. }
  20. // If the save button has been pressed, save the form data.
  21. function saveData($cxn, $userID)
  22. {
  23. /*switch ($_POST['postBirthMonth'])
  24. {
  25. case 'January': { $p4 = 1; } break;
  26. case 'February': { $p4 = 2; } break;
  27. case 'March': { $p4 = 3; } break;
  28. case 'April': { $p4 = 4; } break;
  29. case 'May': { $p4 = 5; } break;
  30. case 'June': { $p4 = 6; } break;
  31. case 'July': { $p4 = 7; } break;
  32. case 'August': { $p4 = 8; } break;
  33. case 'September': { $p4 = 9; } break;
  34. case 'October': { $p4 = 10; } break;
  35. case 'November': { $p4 = 11; } break;
  36. case 'December': { $p4 = 12; } break;
  37. }*/
  38. $p1 = safe($_POST['postName']);
  39. $p2 = safe($_POST['postEmail']);
  40. $p3 = safe($_POST['postContact']);
  41. $p4 = safe($_POST['postBirthMonth']);
  42. $p5 = safe($_POST['postBirthDay']);
  43. $p6 = safe($_POST['postNews']);
  44. $p7 = safe($_POST['postEvent1']);
  45. $p8 = safe($_POST['postEvent2']);
  46. $p9 = safe($_POST['postEvent3']);
  47. $p10 = safe($_POST['postHeadline']);
  48. $p11 = safe($_POST['postStory']);
  49. $p12 = safe($_POST['postBlogName']);
  50. $p13 = safe($_POST['postBlogURL']);
  51. $p14 = safe($_POST['postBlogDescription']);
  52. $p15 = safe($_POST['postMisc1']);
  53. $p16 = safe($_POST['postMisc2']);
  54. //$pOld = safe($_POST['login']);
  55. $query_saveData = "UPDATE userdata SET
  56. nameFull='$p1', emailAddress='$p2', contactInfo='$p3',
  57. birthMonth=$p4, birthDay=$p5, newsMonth='$p6', event1='$p7',
  58. event2='$p8', event3='$p9', newsHeadline='$p10',
  59. newsStory='$p11', blogName='$p12', blogURL='$p13',
  60. blogDescription='$p14', misc1='$p15', misc2='$p16'
  61. WHERE userID='$userID'";
  62. $result_saveData = mysql_query($query_saveData, $cxn)
  63. or die ("Couldn't execute query 1");
  64. }
  65. $userID = 0;
  66. function getExtension($str) {
  67. $i = strrpos($str,".");
  68. if (!$i) { return ""; }
  69. $l = strlen($str) - $i;
  70. $ext = substr($str,$i+1,$l);
  71. return $ext;
  72. }
  73. // check for the login info... if none exists, redirect to home
  74. if (isset ($_POST['login']))
  75. {
  76. $currentUser = safe($_POST['login']);
  77. // get the ID
  78. $query_getID = "SELECT userID FROM userdata WHERE emailAddress='$currentUser'";
  79. $result_getID = mysql_query($query_getID, $cxn)
  80. or die ("Couldn't execute query 1");
  81. // If zero rows, create a new user.
  82. if (mysql_num_rows($result_getID) == 0)
  83. {
  84. $qInsert = "INSERT INTO userdata SET emailAddress='$currentUser'";
  85. $qResult= mysql_query($qInsert, $cxn)
  86. or die ("Couldn't execute query 3");
  87. }
  88. // Now get the ID again...
  89. $query_getID = "SELECT userID FROM userdata WHERE emailAddress='$currentUser'";
  90. $result_getID = mysql_query($query_getID, $cxn)
  91. or die ("Couldn't execute query 1");
  92. $userIDr = mysql_fetch_assoc($result_getID);
  93. $userID = $userIDr['userID'];
  94. }
  95. if (isset ($_POST['userID']))
  96. {
  97. $userID = $_POST['userID'];
  98. }
  99. if ($userID == 0)
  100. {
  101. header('Location: signup.php');
  102. }
  103. // save data if neccessary
  104. $errors = 0;
  105. if (isset($_POST['saveTrue']))
  106. {
  107. saveData($cxn, $userID);
  108. // reset current user (allows you to change your email address)
  109. $currentUser = safe($_POST['postEmail']);
  110. }
  111. //reads the name of the file the user submitted for uploading
  112. //$image=$_FILES['image']['name'];
  113. //if it is not empty
  114. if ( isset($_FILES['image']['name']) && $_FILES['image']['name'] != '')//$image)
  115. {
  116. //get the original name of the file from the clients machine
  117. $filename = stripslashes($_FILES['image']['name']);
  118. //get the extension of the file in a lower case format
  119. $extension = getExtension($filename);
  120. $extension = strtolower($extension);
  121. //if it is not a known extension, we will suppose it is an error and will not upload the file,
  122. //otherwise we will do more tests
  123. if (($extension != "jpg"))
  124. {
  125. //print error message
  126. //echo '<h1>Unknown extension!</h1>';
  127. $errors=1;
  128. }
  129. else
  130. {
  131. //get the size of the image in bytes
  132. //$_FILES['image']['tmp_name'] is the temporary filename of the file
  133. //in which the uploaded file was stored on the server
  134. $size=filesize($_FILES['image']['tmp_name']);
  135. //compare the size with the maxim size we defined and print error if bigger
  136. if ($size > 1000*1024)
  137. {
  138. //echo '<h1>You have exceeded the size limit!</h1>';
  139. $errors=1;
  140. }
  141. //we will give an unique name, for example the time in unix time format
  142. $image_name=$userID.'.'.$extension;
  143. //the new name will be containing the full path where will be stored (images folder)
  144. $newname="userimages/".$image_name;
  145. //we verify if the image has been uploaded, and print error instead
  146. $copied = copy($_FILES['image']['tmp_name'], $newname);
  147. if (!$copied)
  148. {
  149. //echo '<h1>Copy unsuccessfull!</h1>';
  150. $errors=1;
  151. }
  152. }}
  153. // get the info for this user
  154. $query_getData = "SELECT * FROM userdata WHERE userID=$userID";
  155. $result_getData = mysql_query($query_getData, $cxn)
  156. or die ("Couldn't execute query 1");
  157. $userData = mysql_fetch_assoc($result_getData);
  158. $userID = stripslashes($userData['userID']);
  159. $userName = stripslashes($userData['nameFull']);
  160. $userEmail = stripslashes($userData['emailAddress']);
  161. $userContact = stripslashes($userData['contactInfo']);
  162. $userBirthMonth = $userData['birthMonth'];
  163. $userBirthDay = $userData['birthDay'];
  164. $order = array("\\r\\n", "\\n", "\\r", "\\");
  165. $userNews = str_replace($order, '', $userData['newsMonth']);
  166. $userStory = str_replace($order, '', $userData['newsStory']);
  167. //$userNews = $userData['newsMonth'];
  168. $userEvent1 = stripslashes($userData['event1']);
  169. $userEvent2 = stripslashes($userData['event2']);
  170. $userEvent3 = stripslashes($userData['event3']);
  171. $userHeadline = stripslashes($userData['newsHeadline']);
  172. //$userStory = stripslashes($userData['newsStory']);
  173. $userBlogName = stripslashes($userData['blogName']);
  174. $userBlogURL = stripslashes($userData['blogURL']);
  175. $userBlogDescription = stripslashes($userData['blogDescription']);
  176. $userMisc1 = stripslashes($userData['misc1']);
  177. $userImage = stripslashes($userData['misc2']);
  178. echo "
  179. <html>
  180. <title>My Profile</title>
  181. <head></head>
  182. <body bgcolor=#dde6c6>
  183. <style type='text/css'>
  184. table {
  185. font-family:'Helvetica',serif;
  186. font-size: 11;
  187. }
  188. A:link {text-decoration: none; color: #645d41;}
  189. A:visited {text-decoration: none; color: #645d41;}
  190. A:active {text-decoration: none; color: #645d41;}
  191. A:hover {text-decoration: underline; color: #ddd6ba;}
  192. </style>
  193. <form action='profile.php' enctype='multipart/form-data' method='post'>
  194. <table width=100% border=0 bgcolor=#dde6c6>
  195. <tr><td align='center'>
  196. <table width=660px border=0 bgcolor='white'>
  197. <tr>
  198. <td style='background-image: url(evan/images/G.jpg)' align='center'><br /><br />Newsletter - a simple monthly publication to keep friends connected<br /><br /></td>
  199. </tr>
  200. <tr><td align='center'><a href='publications.php'>[Archive]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='signup.php'>[Log out]</a><br /><br /></td></tr>
  201. </table><br />
  202. <table width=660px border=0 bgcolor='white'>
  203. <tr>
  204. <td colspan=3 align='center'><br />
  205. All fields are optional. To unsubscribe from the newsletter, erase your
  206. email address and save the form.";
  207. if (isset($_POST['saveTrue']))
  208. {
  209. //saveData();
  210. echo "<br /><br /><div style='color: red;'><strong>
  211. Your information has been submitted to the newspaper.<br />
  212. You may make further modifications using this page until the publication date.
  213. </strong></div></br />";
  214. if ($errors != 0)
  215. {
  216. echo "<br /><br /><div style='color: red;'><strong>
  217. Error submitting image. You image must be saved with a .jpg<br />
  218. extension and be less than 1 MB in size.
  219. </strong></div></br />";
  220. }
  221. }
  222. echo "
  223. </td>
  224. </tr>
  225. <!--
  226. <tr>
  227. <td colspan=2 align='right'>
  228. <br /><input type='submit' value=' Save '>
  229. </td>
  230. </tr>
  231. -->
  232. <tr>
  233. <td width=500px>&nbsp;</td>
  234. <td>
  235. <br />
  236. <strong>Your information</strong>
  237. <hr width=100%>
  238. Name<br />
  239. <input type='input' name='postName' value='$userName' size=50>
  240. <br />
  241. Email<br />
  242. <input type='input' size=50 name='postEmail' value='$userEmail'>* publications will be sent here
  243. <br />
  244. <!--Other contact information<br />-->
  245. <input type='hidden' name='postContact' value='$userContact' size=50>
  246. <br />
  247. <br />
  248. Birthday&nbsp;&nbsp;
  249. <select name='postBirthMonth'>";
  250. if ($userBirthMonth == 1) { echo "<option value=1 selected='selected'>"; }
  251. else { echo "<option value=1>";}
  252. echo "January</option>";
  253. if ($userBirthMonth == 2) { echo "<option value=2 selected='selected'>"; }
  254. else { echo "<option value=2>";}
  255. echo "February</option>";
  256. if ($userBirthMonth == 3) { echo "<option value=3 selected='selected'>"; }
  257. else { echo "<option value=3>";}
  258. echo "March</option>";
  259. if ($userBirthMonth == 4) { echo "<option value=4 selected='selected'>"; }
  260. else { echo "<option value=4>";}
  261. echo "April</option>";
  262. if ($userBirthMonth == 5) { echo "<option value=5 selected='selected'>"; }
  263. else { echo "<option value=5>";}
  264. echo "May</option>";
  265. if ($userBirthMonth == 6) { echo "<option value=6 selected='selected'>"; }
  266. else { echo "<option value=6>";}
  267. echo "June</option>";
  268. if ($userBirthMonth == 7) { echo "<option value=7 selected='selected'>"; }
  269. else { echo "<option value=7>";}
  270. echo "July</option>";
  271. if ($userBirthMonth == 8) { echo "<option value=8 selected='selected'>"; }
  272. else { echo "<option value=8>";}
  273. echo "August</option>";
  274. if ($userBirthMonth == 9) { echo "<option value=9 selected='selected'>"; }
  275. else { echo "<option value=9>";}
  276. echo "September</option>";
  277. if ($userBirthMonth == 10) { echo "<option value=10 selected='selected'>"; }
  278. else { echo "<option value=10>";}
  279. echo "October</option>";
  280. if ($userBirthMonth == 11) { echo "<option value=11 selected='selected'>"; }
  281. else { echo "<option value=11>";}
  282. echo "November</option>";
  283. if ($userBirthMonth == 12) { echo "<option value=12 selected='selected'>"; }
  284. else { echo "<option value=12>";}
  285. echo "December</option>";
  286. echo "
  287. </select>
  288. <input type='input' name='postBirthDay' value='$userBirthDay' size=3>
  289. <br /><br />
  290. <br />
  291. <strong>Your news</strong>
  292. <hr width=100%>
  293. Monthly update (<200 words please)<br />
  294. <i>Write a short paragraph or two about what you've been up to.</i><br />
  295. <textarea cols=62 rows=10 name='postNews'>$userNews</textarea>
  296. <br /><br />
  297. Announcements & Events<br />
  298. <i>Any announcements / events you are hosting or planning to attend.</i><br />
  299. 1.<input type='input' name='postEvent1' value='$userEvent1' size=78><br />
  300. 2.<input type='input' name='postEvent2' value='$userEvent2' size=78><br />
  301. 3.<input type='input' name='postEvent3' value='$userEvent3' size=78>
  302. <br />
  303. <br /><br />
  304. <strong>Write a featured story</strong><br />
  305. <i>Write a long, blog-style post about anything. Featured stories
  306. will be printed on the first page.</i> <!-- Optionally,
  307. include images. To include images, first upload the image by pressing
  308. the button. Then, at the desired location in the post, enter two pound
  309. symbols followed by the image name followed by two pound symbols. The
  310. image name is case sensitive. test.JPG is not the same as Test.jpg.
  311. <br />Example: ##image.jpg##</i><br /> -->
  312. <hr width=100%>
  313. Headline<br />
  314. <input type='input' size=80 height=5 name='postHeadline' value='$userHeadline'>
  315. <br />
  316. Optional image:
  317. <i>Upload the image by pressing the button. The image will be displayed
  318. at the beginning of your post. Only one image can be uploaded. Images
  319. MUST be saved in a .jpg format and be under 1 mb!
  320. <br /></i>
  321. <input type='file' name='image'>
  322. <input type='hidden' size=40 height=5 name='postMisc2' value='$userImage'>
  323. <br />
  324. Story (no size limit)<br />
  325. <textarea cols=62 rows=14 name='postStory'>$userStory</textarea>
  326. <br />
  327. <br /><br />
  328. <strong>Do you have a personal blog?</strong>
  329. <hr width=100%>
  330. Blog name<br />
  331. <input type='input' size=80 name='postBlogName' value='$userBlogName'>
  332. <br />
  333. Blog URL<br />
  334. <input type='input' size=80 name='postBlogURL' value='$userBlogURL'>
  335. <br />
  336. Blog description (short)<br />
  337. <input type='input' size=80 name='postBlogDescription' value='$userBlogDescription'>
  338. <br />
  339. <br />
  340. <strong>Misc</strong>
  341. <hr width=100%>
  342. Recommended books/music<br />
  343. <input type='input' size=80 name='postMisc1' value='$userMisc1'>
  344. <br />
  345. <br />
  346. </td>
  347. <td width=500px>&nbsp;</td>
  348. </tr>
  349. <tr>
  350. <td colspan=2 align='right'>
  351. <input type='hidden' name='userID' value='$userID'>
  352. <input type='submit' name='saveTrue' value=' Save '><br /><br /><br />
  353. </td>
  354. </tr>
  355. </table>
  356. </td></tr>
  357. </table>
  358. </form>
  359. </body>
  360. </html>";
  361. ?>