/php/restore_cla.php

https://bitbucket.org/isanneh/campus-pages · PHP · 550 lines · 332 code · 201 blank · 17 comment · 81 complexity · c64c4c001b550126238ae1bc6d57b9ae MD5 · raw file

  1. <?php
  2. //Start session
  3. session_start();
  4. //Include database connection details
  5. require_once('connect.php');
  6. //Array to store validation errors
  7. $errmsg_arr = array();
  8. //Validation error flag
  9. $errflag = false;
  10. //Function to sanitize values received from the form. Prevents SQL injection
  11. function clean($str) {
  12. $str = @trim($str);
  13. if(get_magic_quotes_gpc()) {
  14. $str = stripslashes($str);
  15. }
  16. return mysql_real_escape_string($str);
  17. }
  18. //Sanitize the POST values
  19. $id = clean($_POST['id']);
  20. $version = clean($_POST['version']);
  21. $category = clean($_POST['category']);
  22. //If there are input validations, redirect back to the login form
  23. if($errflag) {
  24. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  25. session_write_close();
  26. header("location: classified.php");
  27. exit();
  28. }
  29. if($category == 'for sale')
  30. {
  31. $qry_current_data="SELECT * FROM for_sale_edits WHERE id='$id'";
  32. $result_current_data=mysql_query($qry_current_data);
  33. if($result_current_data)
  34. {
  35. if(mysql_num_rows($result_current_data) == 0)
  36. {
  37. $row=mysql_fetch_assoc($result_current_data);
  38. //Create query
  39. $qry="UPDATE `for_sale` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$sale_contact_email', `phone`='$sale_phone', `name`='$sale_person', `amount`='$sale_amount', `details`='$sale_details' WHERE id='$id'";
  40. $result=@mysql_query($qry);
  41. if($result)
  42. {
  43. $info = "restored version ";
  44. $info .= $version;
  45. $qry_copy="INSERT INTO for_sale_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `check_email`, `check_phone`, `details`, `status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `check_email`, `check_phone`, `details`, `status`, 'original version' FROM for_sale WHERE id='$id'";
  46. $result_copy=mysql_query($qry_copy);
  47. if(! $result_copy)
  48. {
  49. die("copy query failed!");
  50. }
  51. header("location: events2.php");
  52. exit();
  53. }
  54. else
  55. {
  56. die("query restore update failed");
  57. }
  58. }
  59. }
  60. }
  61. else if($category == 'housing wanted')
  62. {
  63. $qry_current_data="SELECT * FROM housing_wanted_edits WHERE id='$id'";
  64. $result_current_data=mysql_query($qry_current_data);
  65. if($result_current_data)
  66. {
  67. if(mysql_num_rows($result_current_data) == 0)
  68. {
  69. $row=mysql_fetch_assoc($result_current_data);
  70. //Create query
  71. $qry="UPDATE `housing_wanted` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$housing_wanted_contact_email', `phone`='$housing_wanted_phone', `name`='$housing_wanted_person', `amount`='$housing_wanted_amount', `duration`='$housing_wanted_duration', `details`='$housing_wanted_details' WHERE id='$id'";
  72. $result=@mysql_query($qry);
  73. if($result)
  74. {
  75. $info = "restored version ";
  76. $info .= $version;
  77. $qry_copy="INSERT INTO housing_wanted_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `duration`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `duration`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM housing_wanted WHERE id='$id'";
  78. $result_copy=mysql_query($qry_copy);
  79. if(! $result_copy)
  80. {
  81. die("copy query failed!");
  82. }
  83. header("location: events2.php");
  84. exit();
  85. }
  86. else
  87. {
  88. die("query restore update failed");
  89. }
  90. }
  91. }
  92. }
  93. else if($category == 'housing available')
  94. {
  95. $qry_current_data="SELECT * FROM housing_available_edits WHERE id='$id'";
  96. $result_current_data=mysql_query($qry_current_data);
  97. if($result_current_data)
  98. {
  99. if(mysql_num_rows($result_current_data) == 0)
  100. {
  101. $row=mysql_fetch_assoc($result_current_data);
  102. //Create query
  103. $qry="UPDATE `housing_available` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$housing_available_contact_email', `phone`='$housing_available_phone', `name`='$housing_available_person', `amount`='$housing_available_amount', `duration`='$housing_available_duration', `details`='$housing_available_details' WHERE id='$id'";
  104. $result=@mysql_query($qry);
  105. if($result)
  106. {
  107. $info = "restored version ";
  108. $info .= $version;
  109. $qry_copy="INSERT INTO housing_available_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `duration`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `duration`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM housing_available WHERE id='$id'";
  110. $result_copy=mysql_query($qry_copy);
  111. if(! $result_copy)
  112. {
  113. die("copy query failed!");
  114. }
  115. header("location: events2.php");
  116. exit();
  117. }
  118. else
  119. {
  120. die("query restore update failed");
  121. }
  122. }
  123. }
  124. }
  125. else if($category == 'job')
  126. {
  127. $qry_current_data="SELECT * FROM job_edits WHERE id='$id'";
  128. $result_current_data=mysql_query($qry_current_data);
  129. if($result_current_data)
  130. {
  131. if(mysql_num_rows($result_current_data) == 0)
  132. {
  133. $row=mysql_fetch_assoc($result_current_data);
  134. //Create query
  135. $qry="UPDATE `job` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$job_contact_email', `phone`='$job_phone', `name`='$job_person', `website`='$job_website', `details`='$job_details' WHERE id='$id'";
  136. $result=@mysql_query($qry);
  137. if($result)
  138. {
  139. $info = "restored version ";
  140. $info .= $version;
  141. $qry_copy="INSERT INTO job_edits (`id`, `school`, `edited_`school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `website`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_`school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `website`, `check_email`, `check_phone`, `details`, 'original version' FROM job WHERE id='$id'";
  142. $result_copy=mysql_query($qry_copy);
  143. if(! $result_copy)
  144. {
  145. die("copy query failed!");
  146. }
  147. header("location: events2.php");
  148. exit();
  149. }
  150. else
  151. {
  152. die("query restore update failed");
  153. }
  154. }
  155. }
  156. }
  157. else if($category == 'internship')
  158. {
  159. $qry_current_data="SELECT * FROM internship_edits WHERE id='$id'";
  160. $result_current_data=mysql_query($qry_current_data);
  161. if($result_current_data)
  162. {
  163. if(mysql_num_rows($result_current_data) == 0)
  164. {
  165. $row=mysql_fetch_assoc($result_current_data);
  166. //Create query
  167. $qry="UPDATE `internship` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$internship_contact_email', `phone`='$internship_phone', `name`='$internship_person', `website`='$internship_website', `month`='$internship_month', `day`='$internship_day', `year`='$internship_year', `details`='$internship_details' WHERE id='$id'";
  168. $result=@mysql_query($qry);
  169. if($result)
  170. {
  171. $info = "restored version ";
  172. $info .= $version;
  173. $qry_copy="INSERT INTO internship_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `website`, `month`, `day`, `year`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `website`, `month`, `day`, `year`, `check_email`, `check_phone`, `details`, 'original version' FROM internship WHERE id='$id'";
  174. $result_copy=mysql_query($qry_copy);
  175. if(! $result_copy)
  176. {
  177. die("copy query failed!");
  178. }
  179. header("location: events2.php");
  180. exit();
  181. }
  182. else
  183. {
  184. die("query restore update failed");
  185. }
  186. }
  187. }
  188. }
  189. else if($category == 'reu')
  190. {
  191. $qry_current_data="SELECT * FROM reu_edits WHERE id='$id'";
  192. $result_current_data=mysql_query($qry_current_data);
  193. if($result_current_data)
  194. {
  195. if(mysql_num_rows($result_current_data) == 0)
  196. {
  197. $row=mysql_fetch_assoc($result_current_data);
  198. //Create query
  199. $qry="UPDATE `reu` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$reu_contact_email', `phone`='$reu_phone', `name`='$reu_person', `website`='$reu_website', `month`='$reu_month', `day`='$reu_day', `year`='$reu_year', `details`='$reu_details' WHERE id='$id'";
  200. $result=@mysql_query($qry);
  201. if($result)
  202. {
  203. $info = "restored version ";
  204. $info .= $version;
  205. $qry_copy="INSERT INTO reu_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `website`, `month`, `day`, `year`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `website`, `month`, `day`, `year`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM reu WHERE id='$id'";
  206. $result_copy=mysql_query($qry_copy);
  207. if(! $result_copy)
  208. {
  209. die("copy query failed!");
  210. }
  211. header("location: events2.php");
  212. exit();
  213. }
  214. else
  215. {
  216. die("query restore update failed");
  217. }
  218. }
  219. }
  220. }
  221. else if($category == 'services')
  222. {
  223. $qry_current_data="SELECT * FROM services_edits WHERE id='$id'";
  224. $result_current_data=mysql_query($qry_current_data);
  225. if($result_current_data)
  226. {
  227. if(mysql_num_rows($result_current_data) == 0)
  228. {
  229. $row=mysql_fetch_assoc($result_current_data);
  230. //Create query
  231. $qry="UPDATE `services` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$services_contact_email', `phone`='$services_phone', `name`='$services_person', `website`='$services_website', `details`='$services_details' WHERE id='$id'";
  232. $result=@mysql_query($qry);
  233. if($result)
  234. {
  235. $info = "restored version ";
  236. $info .= $version;
  237. $qry_copy="INSERT INTO services_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `website`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `website`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM services WHERE id='$id'";
  238. $result_copy=mysql_query($qry_copy);
  239. if(! $result_copy)
  240. {
  241. die("copy query failed!");
  242. }
  243. header("location: events2.php");
  244. exit();
  245. }
  246. else
  247. {
  248. die("query restore update failed");
  249. }
  250. }
  251. }
  252. }
  253. else if($category == 'tutoring')
  254. {
  255. $qry_current_data="SELECT * FROM tutoring_edits WHERE id='$id'";
  256. $result_current_data=mysql_query($qry_current_data);
  257. if($result_current_data)
  258. {
  259. if(mysql_num_rows($result_current_data) == 0)
  260. {
  261. $row=mysql_fetch_assoc($result_current_data);
  262. //Create query
  263. $qry="UPDATE `tutoring` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$tutoring_contact_email', `phone`='$tutoring_phone', `name`='$tutoring_person', `details`='$tutoring_details' WHERE id='$id'";
  264. $result=@mysql_query($qry);
  265. if($result)
  266. {
  267. $info = "restored version ";
  268. $info .= $version;
  269. $qry_copy="INSERT INTO tutoring_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM tutoring WHERE id='$id'";
  270. $result_copy=mysql_query($qry_copy);
  271. if(! $result_copy)
  272. {
  273. die("copy query failed!");
  274. }
  275. header("location: events2.php");
  276. exit();
  277. }
  278. else
  279. {
  280. die("query restore update failed");
  281. }
  282. }
  283. }
  284. }
  285. else if($category == 'textbooks wanted')
  286. {
  287. $qry_current_data="SELECT * FROM textbooks_wanted_edits WHERE id='$id'";
  288. $result_current_data=mysql_query($qry_current_data);
  289. if($result_current_data)
  290. {
  291. if(mysql_num_rows($result_current_data) == 0)
  292. {
  293. $row=mysql_fetch_assoc($result_current_data);
  294. //Create query
  295. $qry="UPDATE `textbooks_wanted` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$textbooks_wanted_contact_email', `phone`='$textbooks_wanted_phone', `name`='$textbooks_wanted_person', `details`='$textbooks_wanted_details' WHERE id='$id'";
  296. $result=@mysql_query($qry);
  297. if($result)
  298. {
  299. $info = "restored version ";
  300. $info .= $version;
  301. $qry_copy="INSERT INTO textbooks_wanted_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM textbooks_wanted WHERE id='$id'";
  302. $result_copy=mysql_query($qry_copy);
  303. if(! $result_copy)
  304. {
  305. die("copy query failed!");
  306. }
  307. header("location: events2.php");
  308. exit();
  309. }
  310. else
  311. {
  312. die("query restore update failed");
  313. }
  314. }
  315. }
  316. }
  317. else if($category == 'textbooks for sale')
  318. {
  319. $qry_current_data="SELECT * FROM textbooks_for_sale_edits WHERE id='$id'";
  320. $result_current_data=mysql_query($qry_current_data);
  321. if($result_current_data)
  322. {
  323. if(mysql_num_rows($result_current_data) == 0)
  324. {
  325. $row=mysql_fetch_assoc($result_current_data);
  326. //Create query
  327. $qry="UPDATE `textbooks_for_sale` SET `school`='$id', 'ccny', `title`='$title', `category`='$category', `contact_email`='$textbooks_for_sale_contact_email', `phone`='$textbooks_for_sale_phone', `name`='$textbooks_for_sale_person', `details`='$textbooks_for_sale_details' WHERE id='$id'";
  328. $result=@mysql_query($qry);
  329. if($result)
  330. {
  331. $info = "restored version ";
  332. $info .= $version;
  333. $qry_copy="INSERT INTO textbooks_for_sale_edits (`id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `check_email`, `check_phone`, `details`,`status`, `info`) SELECT `id`, `school`, `edited_by`, `title`, `category`, `contact_email`, `phone`, `name`, `amount`, `check_email`, `check_phone`, `details`,`status`, 'original version' FROM textbooks_for_sale WHERE id='$id'";
  334. $result_copy=mysql_query($qry_copy);
  335. if(! $result_copy)
  336. {
  337. die("copy query failed!");
  338. }
  339. header("location: events2.php");
  340. exit();
  341. }
  342. else
  343. {
  344. die("query restore update failed");
  345. }
  346. }
  347. }
  348. }
  349. ?>