/Controller/controller.action.php

https://github.com/mayurr/ND · PHP · 795 lines · 668 code · 66 blank · 61 comment · 171 complexity · 589818ac5a063a4b70a2a3bf274d6b59 MD5 · raw file

  1. <?php
  2. session_start();
  3. include_once ("../Model/class.give.php");
  4. include_once ("../Model/class.get.php");
  5. include_once ("../Model/class.object.php");
  6. include_once ("../Model/class.applicant.php");
  7. include_once ("../Model/class.user.php");
  8. include_once ("../Model/class.action.php");
  9. include_once ("../Model/class.mail.php");
  10. $columnArray = array();
  11. switch ($_POST['action']) {
  12. /*
  13. * Switch Case to insert a new Give
  14. */
  15. case "Give":
  16. $give = new Give();
  17. $object = new Object();
  18. /*
  19. * get the last id and generate new give id
  20. */
  21. $lastId = $give->getLastGiveId();
  22. if ($lastId != null) {
  23. $newGiveId = $give->getNewId($lastId);
  24. }
  25. else {
  26. $newGiveId = "give00001";
  27. }
  28. /*
  29. * get the last id and generate new object id
  30. */
  31. $lastId = $object->getLastObjectId();
  32. if ($lastId != null) {
  33. $newObjectId = $object->getNewId($lastId);
  34. }
  35. else {
  36. $newObjectId = "obj00001";
  37. }
  38. /*
  39. * set the values to be inserted to give table and insert
  40. */
  41. $give->setGiveId($newGiveId);
  42. $give->setUserId($_SESSION['user1']['userId']);
  43. $give->setObjectId($newObjectId);
  44. $give->setStartDate($_POST['startDate']);
  45. $give->setEndDate($_POST['endDate']);
  46. $give->setComments($_POST['comments']);
  47. $give->setStatus("Active");
  48. $give->setLocation($_POST['location']);
  49. $result = $give->insertGive();
  50. /*
  51. * set the values to be inserted to object table and insert
  52. */
  53. $object->setObjectId($newObjectId);
  54. $object->setName($_POST['name']);
  55. $object->setDescription($_POST['description']);
  56. $object->setImage($_POST['image']);
  57. $object->setType($_POST['type']);
  58. $object->setCounter(1);
  59. $result2 = $object->insertObject();
  60. $newGive = array("giveId"=>$newGiveId,"userId"=>$_SESSION['user1']['userId'],"objectId"=>$newObjectId,"objectName"=>$_POST['name'],"objectDescription"=>$_POST['description'],"objectImage"=>$_POST['image'],"objectType"=>$_POST['type'],"startDate"=>$_POST['startDate'],"endDate"=>$_POST['endDate'],"comments"=>$_POST['comments'],"status"=>"Active","location"=>$_POST['location'],"firstName"=>$_SESSION['user1']['firstName'],"lastName"=>$_SESSION['user1']['lastName'],"userImage"=>$_SESSION['user1']['image']);
  61. if($_SESSION['gives'][0]['giveId'] == "empty") {
  62. $_SESSION['gives'] = array();
  63. }
  64. if($_SESSION['userGives'][0]['giveId'] == "empty") {
  65. $_SESSION['userGives'] = array();
  66. }
  67. array_unshift($_SESSION['gives'],$newGive);
  68. array_unshift($_SESSION['userGives'],$newGive);
  69. echo $newGiveId."::".$_SESSION['user1']['userId']."::".$newObjectId;
  70. break;
  71. /*
  72. * Switch Case to insert a new Get
  73. */
  74. case "Get":
  75. $get = new Get();
  76. $object = new Object();
  77. /*
  78. * get the last id and generate new give id
  79. */
  80. $lastId = $get->getLastGetId();
  81. if ($lastId != null) {
  82. $newGetId = $get->getNewId($lastId);
  83. }
  84. else {
  85. $newGetId = "get00001";
  86. }
  87. /*
  88. * get the last id and generate new object id
  89. */
  90. $lastId = $object->getLastObjectId();
  91. if ($lastId != null) {
  92. $newObjectId = $object->getNewId($lastId);
  93. }
  94. else {
  95. $newObjectId = "obj00001";
  96. }
  97. /*
  98. * set the values to be inserted to give table and insert
  99. */
  100. $get->setGetId($newGetId);
  101. $get->setUserId($_SESSION['user1']['userId']);
  102. $get->setObjectId($newObjectId);
  103. $get->setStartDate($_POST['startDate']);
  104. $get->setEndDate($_POST['endDate']);
  105. $get->setComments($_POST['comments']);
  106. $get->setStatus("Active");
  107. $get->setLocation($_POST['location']);
  108. $result1 = $get->insertGet();
  109. /*
  110. * set the values to be inserted to object table and insert
  111. */
  112. $object->setObjectId($newObjectId);
  113. $object->setName($_POST['name']);
  114. $object->setDescription($_POST['description']);
  115. $object->setImage($_POST['image']);
  116. $object->setType($_POST['type']);
  117. $object->setCounter(1);
  118. $result2 = $object->insertObject();
  119. $newGet = array("getId"=>$newGetId,"userId"=>$_SESSION['user1']['userId'],"objectId"=>$newObjectId,"objectName"=>$_POST['name'],"objectDescription"=>$_POST['description'],"objectImage"=>$_POST['image'],"objectType"=>$_POST['type'],"startDate"=>$_POST['startDate'],"endDate"=>$_POST['endDate'],"comments"=>$_POST['comments'],"status"=>"Active","location"=>$_POST['location'],"firstName"=>$_SESSION['user1']['firstName'],"lastName"=>$_SESSION['user1']['lastName'],"userImage"=>$_SESSION['user1']['image']);
  120. if($_SESSION['gets'][0]['getId'] == "empty") {
  121. $_SESSION['gets'] = array();
  122. }
  123. if($_SESSION['userGets'][0]['getId'] == "empty") {
  124. $_SESSION['userGets'] = array();
  125. }
  126. array_unshift($_SESSION['gets'],$newGet);
  127. array_unshift($_SESSION['userGets'],$newGet);
  128. echo $newGetId."::".$_SESSION['user1']['userId']."::".$newObjectId;
  129. break;
  130. /*
  131. * Switch Case to show all gives on Give Page
  132. */
  133. case "GetAllGives":
  134. $noUserGivesFlag = 0;
  135. $_SESSION['gives'] = array();
  136. $_SESSION['userGives'] = array();
  137. $action = new Action();
  138. $result = $action->getAllGives();
  139. if (sizeof($result) != 0) {
  140. $count = 0;
  141. for($i=0;$i<sizeof($result);$i++) {
  142. $_SESSION['gives'][$i]['giveId'] = $result[$i]['give_id'];
  143. $_SESSION['gives'][$i]['userId'] = $result[$i]['user_id'];
  144. $_SESSION['gives'][$i]['objectId'] = $result[$i]['object_id'];
  145. $_SESSION['gives'][$i]['objectName'] = $result[$i]['name'];
  146. $_SESSION['gives'][$i]['objectDescription'] = $result[$i]['description'];
  147. $_SESSION['gives'][$i]['objectImage'] = $result[$i]['object_image'];
  148. $_SESSION['gives'][$i]['objectType'] = $result[$i]['type'];
  149. $_SESSION['gives'][$i]['startDate'] = $result[$i]['start_date'];
  150. $_SESSION['gives'][$i]['endDate'] = $result[$i]['end_date'];
  151. $_SESSION['gives'][$i]['comments'] = $result[$i]['comments'];
  152. $_SESSION['gives'][$i]['status'] = $result[$i]['status'];
  153. $_SESSION['gives'][$i]['location'] = $result[$i]['location'];
  154. $_SESSION['gives'][$i]['firstName'] = $result[$i]['first_name'];
  155. $_SESSION['gives'][$i]['lastName'] = $result[$i]['last_name'];
  156. $_SESSION['gives'][$i]['userImage'] = $result[$i]['user_image'];
  157. $_SESSION['gives'][$i]['timestamp'] = $result[$i]['timestamp'];
  158. if ($result[$i]['user_id'] == $_SESSION['user1']['userId']) {
  159. $_SESSION['userGives'][$count]['giveId'] = $result[$i]['give_id'];
  160. $_SESSION['userGives'][$count]['userId'] = $result[$i]['user_id'];
  161. $_SESSION['userGives'][$count]['objectId'] = $result[$i]['object_id'];
  162. $_SESSION['userGives'][$count]['objectName'] = $result[$i]['name'];
  163. $_SESSION['userGives'][$count]['objectDescription'] = $result[$i]['description'];
  164. $_SESSION['userGives'][$count]['objectImage'] = $result[$i]['object_image'];
  165. $_SESSION['userGives'][$count]['objectType'] = $result[$i]['type'];
  166. $_SESSION['userGives'][$count]['startDate'] = $result[$i]['start_date'];
  167. $_SESSION['userGives'][$count]['endDate'] = $result[$i]['end_date'];
  168. $_SESSION['userGives'][$count]['comments'] = $result[$i]['comments'];
  169. $_SESSION['userGives'][$count]['status'] = $result[$i]['status'];
  170. $_SESSION['userGives'][$count]['location'] = $result[$i]['location'];
  171. $_SESSION['userGives'][$count]['firstName'] = $result[$i]['first_name'];
  172. $_SESSION['userGives'][$count]['lastName'] = $result[$i]['last_name'];
  173. $_SESSION['userGives'][$count]['userImage'] = $result[$i]['user_image'];
  174. $_SESSION['userGives'][$count]['timestamp'] = $result[$i]['timestamp'];
  175. $count += 1;
  176. $noUserGivesFlag = 1;
  177. }
  178. }
  179. if ($noUserGivesFlag == 0) {
  180. $_SESSION['userGives'][0]['giveId'] = "empty";
  181. }
  182. }
  183. else {
  184. $_SESSION['gives'][0]['giveId'] = "empty";
  185. $_SESSION['userGives'][0]['giveId'] = "empty";
  186. }
  187. break;
  188. case "GetAllGets":
  189. $noUserGetsflag = 0;
  190. $_SESSION['gets'] = array();
  191. $_SESSION['userGets'] = array();
  192. $action = new Action();
  193. $result = $action->getAllGets();
  194. if (sizeof($result) != 0) {
  195. $count = 0;
  196. for($i=0;$i<sizeof($result);$i++) {
  197. $_SESSION['gets'][$i]['getId'] = $result[$i]['get_id'];
  198. $_SESSION['gets'][$i]['userId'] = $result[$i]['user_id'];
  199. $_SESSION['gets'][$i]['objectId'] = $result[$i]['object_id'];
  200. $_SESSION['gets'][$i]['objectName'] = $result[$i]['name'];
  201. $_SESSION['gets'][$i]['objectDescription'] = $result[$i]['description'];
  202. $_SESSION['gets'][$i]['objectImage'] = $result[$i]['object_image'];
  203. $_SESSION['gets'][$i]['objectType'] = $result[$i]['type'];
  204. $_SESSION['gets'][$i]['startDate'] = $result[$i]['start_date'];
  205. $_SESSION['gets'][$i]['endDate'] = $result[$i]['end_date'];
  206. $_SESSION['gets'][$i]['comments'] = $result[$i]['comments'];
  207. $_SESSION['gets'][$i]['status'] = $result[$i]['status'];
  208. $_SESSION['gets'][$i]['location'] = $result[$i]['location'];
  209. $_SESSION['gets'][$i]['firstName'] = $result[$i]['first_name'];
  210. $_SESSION['gets'][$i]['lastName'] = $result[$i]['last_name'];
  211. $_SESSION['gets'][$i]['userImage'] = $result[$i]['user_image'];
  212. $_SESSION['gets'][$i]['timestamp'] = $result[$i]['timestamp'];
  213. if ($result[$i]['user_id'] == $_SESSION['user1']['userId']) {
  214. $_SESSION['userGets'][$count]['getId'] = $result[$i]['get_id'];
  215. $_SESSION['userGets'][$count]['userId'] = $result[$i]['user_id'];
  216. $_SESSION['userGets'][$count]['objectId'] = $result[$i]['object_id'];
  217. $_SESSION['userGets'][$count]['objectName'] = $result[$i]['name'];
  218. $_SESSION['userGets'][$count]['objectDescription'] = $result[$i]['description'];
  219. $_SESSION['userGets'][$count]['objectImage'] = $result[$i]['object_image'];
  220. $_SESSION['userGets'][$count]['objectType'] = $result[$i]['type'];
  221. $_SESSION['userGets'][$count]['startDate'] = $result[$i]['start_date'];
  222. $_SESSION['userGets'][$count]['endDate'] = $result[$i]['end_date'];
  223. $_SESSION['userGets'][$count]['comments'] = $result[$i]['comments'];
  224. $_SESSION['userGets'][$count]['status'] = $result[$i]['status'];
  225. $_SESSION['userGets'][$count]['location'] = $result[$i]['location'];
  226. $_SESSION['userGets'][$count]['firstName'] = $result[$i]['first_name'];
  227. $_SESSION['userGets'][$count]['lastName'] = $result[$i]['last_name'];
  228. $_SESSION['userGets'][$count]['userImage'] = $result[$i]['user_image'];
  229. $_SESSION['userGets'][$count]['timestamp'] = $result[$i]['timestamp'];
  230. $count += 1;
  231. $noUserGetsflag = 1;
  232. }
  233. }
  234. if($noUserGetsflag == 0) {
  235. $_SESSION['userGets'][0]['getId'] = "empty";
  236. }
  237. }
  238. else {
  239. $_SESSION['gets'][0]['getId'] = "empty";
  240. $_SESSION['userGets'][0]['getId'] = "empty";
  241. }
  242. break;
  243. /*
  244. * Switch Case to add new applicant to Applicants Table
  245. */
  246. case "AddApplicant":
  247. $applicant = new Applicant();
  248. /*
  249. * get the last id and generate new applicant id
  250. */
  251. $lastId = $applicant->getLastApplicantId();
  252. if ($lastId != null) {
  253. $newApplicantId = $applicant->getNewId($lastId);
  254. }
  255. else {
  256. $newApplicantId = "applicant00001";
  257. }
  258. /*
  259. * set the values to be inserted to give table and insert
  260. */
  261. $applicant->setApplicantId($newApplicantId);
  262. $applicant->setGivegetId($_POST['givegetId']);
  263. $applicant->setUserId($_SESSION['user1']['userId']);
  264. $applicant->setComments($_POST['comments']);
  265. $applicant->setStatus("Pending");
  266. $result1 = $applicant->insertApplicant();
  267. $newApplicant = array("applicantId"=>$newApplicantId,"givegetId"=>$_POST['givegetId'],"userId"=>$_SESSION['user1']['userId'],"comments"=>$_POST['comments'],"status"=>"Pending","firstName"=>$_SESSION['user1']['firstName'],"lastName"=>$_SESSION['user1']['lastName'],"image"=>$_SESSION['user1']['image']);
  268. array_unshift($_SESSION['applicants'],$newApplicant);
  269. break;
  270. /*
  271. * Switch Case to show all applicants for specific Give or Get
  272. */
  273. case "GetAllApplicants":
  274. $_SESSION['applicants'] = array();
  275. $applicant = new Applicant();
  276. $result = $applicant->getAllApplicants();
  277. if (sizeof($result) != 0) {
  278. for($i=0;$i<sizeof($result);$i++) {
  279. $_SESSION['applicants'][$i]['applicantId'] = $result[$i]['applicant_id'];
  280. $_SESSION['applicants'][$i]['givegetId'] = $result[$i]['giveget_id'];
  281. $_SESSION['applicants'][$i]['userId'] = $result[$i]['user_id'];
  282. $_SESSION['applicants'][$i]['comments'] = $result[$i]['comments'];
  283. $_SESSION['applicants'][$i]['status'] = $result[$i]['status'];
  284. $_SESSION['applicants'][$i]['firstName'] = $result[$i]['first_name'];
  285. $_SESSION['applicants'][$i]['lastName'] = $result[$i]['last_name'];
  286. $_SESSION['applicants'][$i]['image'] = $result[$i]['image'];
  287. $_SESSION['applicants'][$i]['timestamp'] = $result[$i]['timestamp'];
  288. }
  289. }
  290. else {
  291. $_SESSION['applicants'][0]['applicantId'] = "empty";
  292. }
  293. break;
  294. case "ShowApplicants":
  295. $count = 0;
  296. $flag = 0;
  297. $json = "{\"result\": [";
  298. if (sizeof($_SESSION['applicants']) != 0) {
  299. for($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  300. if($_SESSION['applicants'][$i]['givegetId'] == $_POST['givegetId']) {
  301. if($count > 0) {
  302. $json .= ",";
  303. }
  304. $json .= "{\"applicantId\":\"".$_SESSION['applicants'][$i]['applicantId']."\",";
  305. $json .= "\"givegetId\" :\"".$_SESSION['applicants'][$i]['givegetId']."\",";
  306. $json .= "\"userId\" :\"".$_SESSION['applicants'][$i]['userId']."\",";
  307. $json .= "\"comments\" :\"".$_SESSION['applicants'][$i]['comments']."\",";
  308. $json .= "\"status\" :\"".$_SESSION['applicants'][$i]['status']."\",";
  309. $json .= "\"firstName\" :\"".$_SESSION['applicants'][$i]['firstName']."\",";
  310. $json .= "\"lastName\" :\"".$_SESSION['applicants'][$i]['lastName']."\",";
  311. $json .= "\"userImage\" :\"".$_SESSION['applicants'][$i]['image']."\"}";
  312. $count += 1;
  313. $flag = 1;
  314. }
  315. }
  316. if($flag == 0) {
  317. $json .= "{\"empty\":\"empty\"}";
  318. }
  319. }
  320. else {
  321. $json .= "{\"empty\":\"empty\"}";
  322. }
  323. $json .= "]";
  324. str_replace("},]", "}]", $json);
  325. $count = 0;
  326. $flag = 0;
  327. $json1 = "\"result1\": [";
  328. if(strpos($_POST['givegetId'], "give") !== false) {
  329. if (sizeof($_SESSION['gives']) != 0) {
  330. for($i=0;$i<sizeof($_SESSION['gives']);$i++) {
  331. if($_SESSION['gives'][$i]['giveId'] == $_POST['givegetId']) {
  332. if($count > 0) {
  333. $json1 .= ",";
  334. }
  335. $json1 .= "{\"objectType\":\"".$_SESSION['gives'][$i]['objectType']."\",";
  336. $json1 .= "\"objectName\" :\"".$_SESSION['gives'][$i]['objectName']."\",";
  337. $json1 .= "\"objectImage\" :\"".$_SESSION['gives'][$i]['objectImage']."\",";
  338. $json1 .= "\"objectDescription\" :\"".$_SESSION['gives'][$i]['objectDescription']."\",";
  339. $json1 .= "\"comments\" :\"".$_SESSION['gives'][$i]['comments']."\",";
  340. $json1 .= "\"location\" :\"".$_SESSION['gives'][$i]['location']."\",";
  341. $json1 .= "\"startDate\" :\"".$_SESSION['gives'][$i]['startDate']."\",";
  342. $json1 .= "\"endDate\" :\"".$_SESSION['gives'][$i]['endDate']."\"}";
  343. $count += 1;
  344. $flag = 1;
  345. break;
  346. }
  347. }
  348. if($flag == 0) {
  349. $json1 .= "{\"empty\":\"empty\"}";
  350. }
  351. }
  352. else {
  353. $json1 .= "{\"empty\":\"empty\"}";
  354. }
  355. }
  356. else {
  357. if (sizeof($_SESSION['gets']) != 0) {
  358. for($i=0;$i<sizeof($_SESSION['gets']);$i++) {
  359. if($_SESSION['gets'][$i]['getId'] == $_POST['givegetId']) {
  360. if($count > 0) {
  361. $json1 .= ",";
  362. }
  363. $json1 .= "{\"objectType\":\"".$_SESSION['gets'][$i]['objectType']."\",";
  364. $json1 .= "\"objectName\" :\"".$_SESSION['gets'][$i]['objectName']."\",";
  365. $json1 .= "\"objectImage\" :\"".$_SESSION['gets'][$i]['objectImage']."\",";
  366. $json1 .= "\"objectDescription\" :\"".$_SESSION['gets'][$i]['objectDescription']."\",";
  367. $json1 .= "\"comments\" :\"".$_SESSION['gets'][$i]['comments']."\",";
  368. $json1 .= "\"location\" :\"".$_SESSION['gets'][$i]['location']."\",";
  369. $json1 .= "\"startDate\" :\"".$_SESSION['gets'][$i]['startDate']."\",";
  370. $json1 .= "\"endDate\" :\"".$_SESSION['gets'][$i]['endDate']."\"}";
  371. $count += 1;
  372. $flag = 1;
  373. break;
  374. }
  375. }
  376. if($flag == 0) {
  377. $json1 .= "{\"empty\":\"empty\"}";
  378. }
  379. }
  380. else {
  381. $json1 .= "{\"empty\":\"empty\"}";
  382. }
  383. }
  384. $json1 .= "]}";
  385. str_replace("},]}", "}]}", $json1);
  386. echo $json.",".$json1;
  387. break;
  388. case "ChooseUser":
  389. $applicant = new Applicant();
  390. $applicant->setApplicantId($_POST['applicantId']);
  391. $applicant->setStatus("Chosen");
  392. $result = $applicant->updateApplicant();
  393. for($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  394. if($_SESSION['applicants'][$i]['applicantId'] == $_POST['applicantId']) {
  395. $_SESSION['applicants'][$i]['status'] = "Chosen";
  396. break;
  397. }
  398. }
  399. if ($_POST['type'] == "give") {
  400. $give = new Give();
  401. $give->setGiveId($_POST['givegetId']);
  402. $give->setStatus("Chosen");
  403. $result = $give->updateGive();
  404. for($i=0;$i<sizeof($_SESSION['gives']);$i++) {
  405. if($_SESSION['gives'][$i]['giveId'] == $_POST['givegetId']) {
  406. $_SESSION['gives'][$i]['status'] = "Chosen";
  407. break;
  408. }
  409. }
  410. for($i=0;$i<sizeof($_SESSION['userGives']);$i++) {
  411. if($_SESSION['userGives'][$i]['giveId'] == $_POST['givegetId']) {
  412. $_SESSION['userGives'][$i]['status'] = "Chosen";
  413. $objectName = $_SESSION['userGives'][$i]['objectName'];
  414. $objectImage = $_SESSION['userGives'][$i]['objectImage'];
  415. $objectType = $_SESSION['userGives'][$i]['objectType'];
  416. break;
  417. }
  418. }
  419. }
  420. else {
  421. $get = new Get();
  422. $get->setGetId($_POST['givegetId']);
  423. $get->setStatus("Chosen");
  424. $result = $get->updateGet();
  425. for($i=0;$i<sizeof($_SESSION['gets']);$i++) {
  426. if($_SESSION['gets'][$i]['getId'] == $_POST['givegetId']) {
  427. $_SESSION['gets'][$i]['status'] = "Chosen";
  428. break;
  429. }
  430. }
  431. for($i=0;$i<sizeof($_SESSION['userGets']);$i++) {
  432. if($_SESSION['userGets'][$i]['getId'] == $_POST['givegetId']) {
  433. $_SESSION['userGets'][$i]['status'] = "Chosen";
  434. $objectName = $_SESSION['userGets'][$i]['objectName'];
  435. $objectImage = $_SESSION['userGets'][$i]['objectImage'];
  436. $objectType = $_SESSION['userGets'][$i]['objectType'];
  437. break;
  438. }
  439. }
  440. }
  441. if($_POST['type'] == "give") {
  442. for($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  443. if ($_SESSION['applicants'][$i]['applicantId'] == $_POST['applicantId']) {
  444. $getterId = $_SESSION['applicants'][$i]['userId'];
  445. break;
  446. }
  447. }
  448. $flag1 = 0;
  449. $flag2 = 0;
  450. for($i=0;$i<sizeof($_SESSION['users']);$i++) {
  451. if ($_SESSION['users'][$i]['userId'] == $getterId) {
  452. $getterName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  453. $getterEmail = $_SESSION['users'][$i]['email'];
  454. $flag1 = 1;
  455. }
  456. if ($_SESSION['users'][$i]['userId'] == $_POST['giverId']) {
  457. $giverName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  458. $giverEmail = $_SESSION['users'][$i]['email'];
  459. $flag2 = 1;
  460. }
  461. if ($flag1 == 1 && $flag2 == 1) {
  462. break;
  463. }
  464. }
  465. }
  466. if($_POST['type'] == "get") {
  467. for($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  468. if ($_SESSION['applicants'][$i]['applicantId'] == $_POST['applicantId']) {
  469. $giverId= $_SESSION['applicants'][$i]['userId'];
  470. break;
  471. }
  472. }
  473. $flag1 = 0;
  474. $flag2 = 0;
  475. for($i=0;$i<sizeof($_SESSION['users']);$i++) {
  476. if ($_SESSION['users'][$i]['userId'] == $_POST['getterId']) {
  477. $getterName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  478. $getterEmail = $_SESSION['users'][$i]['email'];
  479. $flag1 = 1;
  480. }
  481. if ($_SESSION['users'][$i]['userId'] == $giverId) {
  482. $giverName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  483. $giverEmail = $_SESSION['users'][$i]['email'];
  484. $flag2 = 1;
  485. }
  486. if ($flag1 == 1 && $flag2 == 1) {
  487. break;
  488. }
  489. }
  490. }
  491. if($_POST['type'] == "give") {
  492. $message = "<html><head></head><body>";
  493. $message .= "<p>Hi ".$getterName."</p><br/>";
  494. $message .= "<p>I have chosen to gift you:</p><br/>";
  495. $message .= "<img src='http://nayadaur.org/images/".$objectType.".png' width=50 height=50 /><br/>";
  496. $message .= "<img src='http://nayadaur.org/uploads/".$objectImage."' width=50 height=50 /><p> ".$objectName."</p><br/>";
  497. $message .= "<p>How do we do this!?</p><br />";
  498. $message .= "<p>Thank You!</p><br/>";
  499. $message .= "<p>".$giverName."</p><br/>";
  500. $message .= "</body></html>";
  501. $mail = new Mail();
  502. $mail->setFrom($giverEmail);
  503. $mail->setSubject("Hi!");
  504. $mail->setMessage($message);
  505. $mail->setTo($getterEmail);
  506. }
  507. else {
  508. $message = "<html><head></head><body>";
  509. $message .= "<p>Hi ".$giverName."</p><br/>";
  510. $message .= "<p>I have chosen to be gifted by you:</p><br/>";
  511. $message .= "<img src='http://nayadaur.org/images/".$objectType.".png' width=50 height=50 /><p> ".$objectType."</p><br/>";
  512. $message .= "<img src='http://nayadaur.org/uploads/".$objectImage."' width=50 height=50 /><p> ".$objectName."</p><br/>";
  513. $message .= "<p>How do we do this!?</p><br />";
  514. $message .= "<p>Thank You!</p><br/>";
  515. $message .= "<p>".$getterName."</p><br/>";
  516. $message .= "</body></html>";
  517. $mail->setFrom($getterEmail);
  518. $mail->setSubject("Hi!");
  519. $mail->setMessage($message);
  520. $mail->setTo($giverEmail);
  521. }
  522. $mail->sendMail();
  523. break;
  524. case "ConfirmReceipt":
  525. $applicant = new Applicant();
  526. $give = new Give();
  527. $get = new Get();
  528. /*
  529. * Delete entry/entries from applicant table and update status in Session Array
  530. */
  531. $applicant->setGivegetId($_POST['givegetId']);
  532. $applicant->deleteApplicant();
  533. for ($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  534. if($_SESSION['applicants'][$i]['applicantId'] == $_POST['applicantId']){
  535. $_SESSION['applicants'][$i]['status'] = "Complete";
  536. break;
  537. }
  538. }
  539. /*
  540. * Delete entry from give/get table and update status in Session Array
  541. */
  542. if($_POST['tableName'] == "give") {
  543. $give->setGiveId($_POST['givegetId']);
  544. $result = $give->deleteGive();
  545. for ($i=0;$i<sizeof($_SESSION['gives']);$i++) {
  546. if($_SESSION['gives'][$i]['giveId'] == $_POST['givegetId']){
  547. $_SESSION['gives'][$i]['status'] = "Complete";
  548. $objectImage = $_SESSION['gives'][$i]['objectImage'];
  549. $objectName = $_SESSION['gives'][$i]['objectName'];
  550. break;
  551. }
  552. }
  553. }
  554. else{
  555. $get->setGetId($_POST['givegetId']);
  556. $result = $get->deleteGet();
  557. for ($i=0;$i<sizeof($_SESSION['gets']);$i++) {
  558. if($_SESSION['gets'][$i]['getId'] == $_POST['givegetId']){
  559. $_SESSION['gets'][$i]['status'] = "Complete";
  560. $objectImage = $_SESSION['gets'][$i]['objectImage'];
  561. $objectName = $_SESSION['gets'][$i]['objectName'];
  562. break;
  563. }
  564. }
  565. }
  566. $mail = new Mail();
  567. $flagGetter = 0;
  568. $flagGiver = 0;
  569. for ($i=0;$i<sizeof($_SESSION['users']);$i++) {
  570. if($_SESSION['users'][$i]['userId'] == $_POST['getterId']) {
  571. $getterEmail = $_SESSION['users'][$i]['email'];
  572. $getterName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  573. $flagGetter = 1;
  574. }
  575. if($_SESSION['users'][$i]['userId'] == $_POST['giverId']) {
  576. $giverEmail = $_SESSION['users'][$i]['email'];
  577. $giverName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  578. $flagGiver = 1;
  579. }
  580. if($flagGetter == 1 && $flagGiver == 1) {
  581. break;
  582. }
  583. }
  584. if($_POST['type']) {
  585. $mail->setSubject(strtoupper($_POST['type'])." Complete!");
  586. }
  587. $mail->setFrom("admin@nayadaur.org");
  588. $message = "<html><head></head><body>";
  589. $message .= "<p>Hi ".$getterName."</p><br/>";
  590. $message .= "<p>Congratulations!</p><br/>";
  591. $message .= "<p>You have just been Gifted:</p><br/>";
  592. $message .= "<img src='http://nayadaur.org/uploads/".$objectImage."' width=50 height=50 /><p> ".$objectName."</p><br/>";
  593. $message .= "<p>by ".$giverName." - ".$giverEmail."</p><br/>";
  594. $message .= "<p>This has been added to your Story and your position in the neighbourhood has been updated.</p><br/><br/>";
  595. $message .= "<p>Thank You!</p><br/>";
  596. $message .= "<p>contact@nayadaur.org for any questions or comments.</p>";
  597. $message .= "</body></html>";
  598. $mail->setMessage($message);
  599. $mail->setTo($getterEmail);
  600. $mail->sendMail();
  601. $message = "<html><head></head><body>";
  602. $message .= "<p>Hi ".$giverName."</p><br/>";
  603. $message .= "<p>Congratulations!</p><br/>";
  604. $message .= "<p>You have just Gifted:</p><br/>";
  605. $message .= "<img src='http://nayadaur.org/uploads/".$objectImage."' width=50 height=50 /><p> ".$objectName."</p><br/>";
  606. $message .= "<p>to ".$getterName." - ".$getterEmail."</p><br/>";
  607. $message .= "<p>This has been added to your Story and your position in the neighbourhood has been updated.</p><br/><br/>";
  608. $message .= "<p>Thank You!</p><br/>";
  609. $message .= "<p>contact@nayadaur.org for any questions or comments.</p>";
  610. $message .= "</body></html>";
  611. $mail->setMessage($message);
  612. $mail->setTo($giverEmail);
  613. $mail->sendMail();
  614. break;
  615. case "ConfirmNonReceipt":
  616. $applicant = new Applicant();
  617. $give = new Give();
  618. $get = new Get();
  619. /*
  620. * Delete entry/entries from applicant table and update status in Session Array
  621. */
  622. $applicant->setGivegetId($_POST['givegetId']);
  623. $applicant->deleteApplicant();
  624. for ($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  625. if($_SESSION['applicants'][$i]['applicantId'] == $_POST['applicantId']){
  626. $_SESSION['applicants'][$i]['status'] = "Failure";
  627. break;
  628. }
  629. }
  630. /*
  631. * Delete entry from give table and update status in Session Array
  632. */
  633. if($_POST['tableName'] == "give") {
  634. $give->setGiveId($_POST['givegetId']);
  635. $result = $give->deleteGive();
  636. for ($i=0;$i<sizeof($_SESSION['gives']);$i++) {
  637. if($_SESSION['gives'][$i]['giveId'] == $_POST['givegetId']){
  638. $_SESSION['gives'][$i]['status'] = "Failure";
  639. $objectImage = $_SESSION['gives'][$i]['objectImage'];
  640. $objectName = $_SESSION['gives'][$i]['objectName'];
  641. break;
  642. }
  643. }
  644. }
  645. /*
  646. * Delete entry from get table and update status in Session Array
  647. */
  648. else{
  649. $get->setGetId($_POST['givegetId']);
  650. $result = $get->deleteGet();
  651. for ($i=0;$i<sizeof($_SESSION['gets']);$i++) {
  652. if($_SESSION['gets'][$i]['getId'] == $_POST['givegetId']){
  653. $_SESSION['gets'][$i]['status'] = "Failure";
  654. $objectImage = $_SESSION['gets'][$i]['objectImage'];
  655. $objectName = $_SESSION['gets'][$i]['objectName'];
  656. break;
  657. }
  658. }
  659. }
  660. $mail = new Mail();
  661. $flagGetter = 0;
  662. $flagGiver = 0;
  663. for ($i=0;$i<sizeof($_SESSION['users']);$i++) {
  664. if($_SESSION['users'][$i]['userId'] == $_POST['getterId']) {
  665. $getterEmail = $_SESSION['users'][$i]['email'];
  666. $getterName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  667. $flagGetter = 1;
  668. }
  669. if($_SESSION['users'][$i]['userId'] == $_POST['giverId']) {
  670. $giverEmail = $_SESSION['users'][$i]['email'];
  671. $giverName = $_SESSION['users'][$i]['firstName']." ".$_SESSION['users'][$i]['lastName'];
  672. $flagGiver = 1;
  673. }
  674. if($flagGetter == 1 && $flagGiver == 1) {
  675. break;
  676. }
  677. }
  678. if($_POST['type']) {
  679. $mail->setSubject(strtoupper($_POST['type'])." Failure!");
  680. }
  681. $mail->setFrom("admin@nayadaur.org");
  682. $message = "<html><head></head><body>";
  683. $message .= "<p>Hi ".$getterName."</p><br/>";
  684. $message .= "<p>Your gift:</p><br/>";
  685. $message .= "<img src='http://nayadaur.org/uploads/".$objectImage."' width=50 height=50 /><p> ".$objectName."</p><br/>";
  686. $message .= "<p>by ".$giverName." has been Cancelled</p><br/>";
  687. $message .= "<p>This has been added to your Story and your position in the neighbourhood has been updated.</p><br/><br/>";
  688. $message .= "<p>Thank You!</p><br/>";
  689. $message .= "<p>contact@nayadaur.org for any questions or comments.</p>";
  690. $message .= "</body></html>";
  691. $mail->setMessage($message);
  692. $mail->setTo($getterEmail);
  693. $mail->sendMail();
  694. $message = "<html><head></head><body>";
  695. $message .= "<p>Hi ".$giverName."</p><br/>";
  696. $message .= "<p>Your gift:</p><br/>";
  697. $message .= "<img src='http://nayadaur.org/uploads/".$objectImage."' width=50 height=50 /><p> ".$objectName."</p><br/>";
  698. $message .= "<p>to ".$giverName." has been Cancelled</p><br/>";
  699. $message .= "<p>This has been added to your Story and your position in the neighbourhood has been updated.</p><br/><br/>";
  700. $message .= "<p>Thank You!</p><br/>";
  701. $message .= "<p>contact@nayadaur.org for any questions or comments.</p>";
  702. $message .= "</body></html>";
  703. $mail->setMessage($message);
  704. $mail->setTo($giverEmail);
  705. $mail->sendMail();
  706. break;
  707. case "WithdrawApplication":
  708. $applicant = new Applicant();
  709. $applicant->setApplicantId($_POST['applicantId']);
  710. $applicant->setStatus("Withdrawn");
  711. $result = $applicant->updateApplicant();
  712. for($i=0;$i<sizeof($_SESSION['applicants']);$i++) {
  713. if($_SESSION['applicants'][$i]['applicantId'] == $_POST['applicantId']) {
  714. $_SESSION['applicants'][$i]['status'] = "Withdrawn";
  715. break;
  716. }
  717. }
  718. break;
  719. case "SendFeedback":
  720. $email = $_SESSION['user1']['email'];
  721. $feedback=$_POST["feedback"];
  722. $to = "admin@nayadaur.org,contact@simplybetter.in";
  723. $subject = "Feedback";
  724. //$message = "Hello! This is a simple email message.";
  725. $headers = "From:" . $email;
  726. mail($to,$subject,$feedback,$headers);
  727. break;
  728. }
  729. ?>