/src/class.participant.php

https://github.com/addy689/Sockmonkey · PHP · 283 lines · 130 code · 38 blank · 115 comment · 4 complexity · f48eea548a23f819797ff16d2940fc64 MD5 · raw file

  1. <?php
  2. /**
  3. * Participant class for handling Tathva participant related functions.
  4. * @author Addy Singh <addy689@gmail.com>
  5. * @package content
  6. */
  7. /**
  8. * Includes files for database connectivity.
  9. */
  10. include_once 'database.php';
  11. /**
  12. * Class participant for managing participants.
  13. * @package participant
  14. */
  15. class participant
  16. {
  17. private $pid, $pcnfrm, $pname, $pemail, $pcoll, $pcntct, $pstate, $pgen, $preq, $pcapt, $pnitc;
  18. /**
  19. * The constructor selects the appropriate function based on the number of
  20. * arguments and calls the appropriate protected function.
  21. */
  22. public function __construct(){
  23. $a = func_get_args();
  24. $i = func_num_args();
  25. if($i==1)
  26. call_user_func_array(array($this,'view'),$a);
  27. if($i==9)
  28. call_user_func_array(array($this,'create'),$a);
  29. }
  30. public function __destruct() { }
  31. /**
  32. * Initializes the class properties for a given participant id.
  33. * @param string $pid Participant ID of a participant
  34. */
  35. protected function view($pid){
  36. $sql="SELECT pc_tatid, pc_confirm, pc_name, pc_college, pc_contact, pc_state, pc_gender, pc_accomreqst, pc_accomcaptainid, pc_nitcrollno FROM participant WHERE pc_tatid = '".$pid."'";
  37. $prtcpnt=pg_fetch_assoc(dbquery($sql));
  38. $this->pid=$prtcpnt['pc_tatid'];
  39. $this->pcnfrm=$prtcpnt['pc_confirm'];
  40. $this->pname=$prtcpnt['pc_name'];
  41. $this->pemail=$prtcpnt['pc_email'];
  42. $this->pcoll=$prtcpnt['pc_college'];
  43. $this->pcntct=$prtcpnt['pc_contact'];
  44. $this->pstate=$prtcpnt['pc_state'];
  45. $this->pgen=$prtcpnt['pc_gender'];
  46. $this->preq=$prtcpnt['pc_accomreqst'];
  47. $this->pcapt=$prtcpnt['pc_accomcaptainid'];
  48. $this->pnitc=$prtcpnt['pc_nitcrollno'];
  49. }
  50. /**
  51. * Function to add a new participant. The generated Participant ID is stored in the property pid.
  52. * @param string $pname Full Name of the participant.
  53. * @param string $pemail Email ID of the participant.
  54. * @param string $pcoll College of the participant.
  55. * @param string $pcntct Contact no. of the participant.
  56. * @param string $pstate State the participant belongs to.
  57. * @param character $pgen Gender of the participant.
  58. * @param character $preq Whether accomodation has been requested by the participant.
  59. * @param string $pnitc Roll Number of a participant from NITC.
  60. */
  61. protected function create($pid, $pname, $pemail, $pcoll, $pcntct, $pstate, $pgen, $preq, $pnitc){
  62. $this->pid=pg_escape_string($pid);
  63. $this->pname=pg_escape_string($pname);
  64. $this->pemail=pg_escape_string($pemail);
  65. $this->pcoll=pg_escape_string($pcoll);
  66. $this->pcntct=pg_escape_string($pcntct);
  67. $this->pstate=pg_escape_string($pstate);
  68. $this->pgen=pg_escape_string($pgen);
  69. $this->preq=pg_escape_string($preq);
  70. $this->pnitc=pg_escape_string($pnitc);
  71. $sql="INSERT INTO participant (pc_tatid, pc_name, pc_email, pc_college, pc_contact, pc_state, pc_gender, pc_accomreqst, pc_nitcrollno) VALUES ('" . $this->pid . "','" . $this->pname . "','".$this->pemail . "','" . $this->pcoll . "','" . $this->pcntct . "','" . $this->pstate . "','" . $this->pgen . "','" . $this->preq . "','" . $this->pnitc . "')";
  72. $r=dbquery($sql);
  73. }
  74. public function getTatId(){
  75. return $this->pid;
  76. }
  77. public function getConfirmStatus(){
  78. return $this->pcnfrm;
  79. }
  80. public function getName(){
  81. return $this->pname;
  82. }
  83. public function getEmail(){
  84. return $this->pemail;
  85. }
  86. public function getCollege(){
  87. return $this->pcoll;
  88. }
  89. public function getContact(){
  90. return $this->pcntct;
  91. }
  92. public function getState(){
  93. return $this->pstate;
  94. }
  95. public function getGender(){
  96. return $this->pgen;
  97. }
  98. public function getAccomRequest(){
  99. return $this->preq;
  100. }
  101. public function getAccomCaptain(){
  102. return $this->pcapt;
  103. }
  104. public function getNitcRollNo(){
  105. return $this->pnitc;
  106. }
  107. public static function search($arg){
  108. $arg='%'.$arg.'%';
  109. $sql="SELECT * FROM participant WHERE (pc_tatid ILIKE '".$arg."') OR (pc_name ILIKE '".$arg."') OR (pc_email ILIKE '".$arg."')";
  110. $arr=resource2array(dbquery($sql));
  111. return $arr;
  112. }
  113. /**
  114. * Static function that updates the Participant information.
  115. * @param string $pid Participant ID of a participant.
  116. * @param string $pname Full Name of the participant.
  117. * @param string $pemail Email ID of the participant.
  118. * @param string $pcoll College of the participant.
  119. * @param string $pcntct Contact no. of the participant.
  120. * @param string $pstate State the participant belongs to.
  121. * @param character $preq Whether accomodation has been requested by the participant.
  122. * @param string $pnitc Roll Number of a participant from NITC.
  123. * @return integer (1:update successful | 0:update unsuccessful)
  124. */
  125. public function updateInfo($pname, $pemail, $pcoll, $pcntct, $pstate, $preq, $pnitc){
  126. $pname=pg_escape_string($pname);
  127. $pemail=pg_escape_string($pemail);
  128. $pcoll=pg_escape_string($pcoll);
  129. $pcntct=pg_escape_string($pcntct);
  130. $pstate=pg_escape_string($pstate);
  131. $preq=pg_escape_string($preq);
  132. $pnitc=pg_escape_string($pnitc);
  133. $sql="UPDATE participant SET pc_name='".$pname."', pc_email='".$pemail."', pc_college='".$pcoll."', pc_contact='".$pcntct."', pc_state='".$pstate."', pc_accomreqst='".$preq."', pc_nitcrollno='".$pnitc."' WHERE pc_tatid = '".$this->pid."'";
  134. $r=dbquery($sql);
  135. }
  136. /**
  137. * Static function that updates the Participant Registration information to a given status $st.
  138. * @param string $pid Participant ID of a participant.
  139. * @return integer (1:update successful | 0:update unsuccessful)
  140. */
  141. public function updateStatus($st){
  142. $st=pg_escape_string($st);
  143. $sql="UPDATE participant SET pc_confirm='".$st."' WHERE pc_tatid = '".$this->pid."'";
  144. $r=dbquery($sql);
  145. }
  146. /**
  147. * Static function that updates the current Accomodation captain to a given new Captain.
  148. * @param string $oldcapt Tathva ID of the current Accomodation Captain.
  149. * @param string $newcapt Tathva ID of the new Accomodation Captain.
  150. * @return integer (1: exists | 0: does not exists)
  151. */
  152. public static function updateAccomCaptain($oldcapt, $newcapt){
  153. $oldcapt=pg_escape_string($oldcapt);
  154. $newcapt=pg_escape_string($newcapt);
  155. $sql="UPDATE participant SET pc_accomcaptainid='".$newcapt."' WHERE pc_accomcaptainid='".$oldcapt."'";
  156. $r=dbquery($sql);
  157. if($r)
  158. return 1;
  159. else
  160. return 0;
  161. }
  162. public function getLastId(){
  163. $sql="SELECT COUNT (*) FROM participant";
  164. $x=pg_fetch_row(dbquery($sql));
  165. return $x[0];
  166. }
  167. /**
  168. * Static function that inserts an Accomodation captain for a set of participants whose tathva ID's are contained in array $team[].
  169. * @param string $captid Tathva ID of the Accomodated Team's Captain.
  170. * @return integer (1: exists | 0: does not exists)
  171. */
  172. public static function insertAccomCaptain($team,$captid){
  173. $cnt=count($team);
  174. $i=0;
  175. $sql="BEGIN;";
  176. while($i < $cnt)
  177. {
  178. $sql .="UPDATE participant SET pc_accomcaptainid='$captid' WHERE pc_tatid='{$team[$i]}';";
  179. $i++;
  180. }
  181. $sql .="COMMIT";
  182. $r=dbquery($sql);
  183. if($r)
  184. return 1;
  185. else
  186. return 0;
  187. }
  188. # THE FOLLOWING FUNCTIONS, IF REQUIRED, CAN BE UNCOMMENTED
  189. #
  190. # /**
  191. # * Static function to check if a participant already exists.
  192. # * @param string $pname Given participant name
  193. # * @return integer returns (exists:1 | does not exist:0)
  194. # */
  195. # public static function checkNameExists($pname)
  196. # {
  197. # $sql="SELECT pc_tatid FROM participant WHERE pc_name='".$pname."'";
  198. # $r=pg_fetch_row(dbquery($sql));
  199. # if($r)
  200. # return 1;
  201. # else
  202. # return 0;
  203. # }
  204. # /**
  205. # * Static function to check if an email already exists.
  206. # * @param string $pemail Given email ID
  207. # * @return integer (1: exists | 0: does not exists)
  208. # */
  209. # public static function checkEmailExists($pemail)
  210. # {
  211. # $sql="SELECT pc_tatid FROM participant WHERE pc_email='".$pemail."'";
  212. # $r=pg_fetch_row(dbquery($sql));
  213. # if($r)
  214. # return 1;
  215. # else
  216. # return 0;
  217. # }
  218. # /**
  219. # * Checks if a Paticipant ID already exists in the database.
  220. # * @param string $pid Participant ID of a participant.
  221. # * @return integer (1:exists | 0:does not exist)
  222. # */
  223. # public static function checkTatIdExists($pid)
  224. # {
  225. # $pid=strtoupper($pid);
  226. # $sql="SELECT pc_tatid FROM participant WHERE pc_tatid='".$pid."'";
  227. # $r=pg_fetch_row(dbquery($sql));
  228. # if($r)
  229. # return 1;
  230. # else
  231. # return 0;
  232. # }
  233. #
  234. # public static function checkRollNoExists($pnitc)
  235. # {
  236. # $pnitc=strtoupper($pnitc);
  237. # $sql="SELECT pc_tatid FROM participant WHERE pc_nitcrollno='".$pnitc."'";
  238. # $r=pg_fetch_row(dbquery($sql));
  239. # if($r)
  240. # return 1;
  241. # else
  242. # return 0;
  243. # }
  244. }
  245. ?>