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