2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
16 * Members class for Social Networking
17 * TODO: Extend it for the entire ATutor.
21 var $profile; //profile details
24 $this->id = intval($id);
29 * Add a new job position
30 * @param string Name of the company, in full.
31 * @param string Title of this position
32 * @param int Started date for this position, in the format of yyyymm
33 * @param int Position ended on this date, in the format of yyyymm, or 'NOW'.
34 * 'NOW' means it is still on going.
35 * @param string Description of what the position was about
37 function addPosition($company, $title, $from, $to, $description){
38 global $addslashes, $db;
39 $member_id = $this->id;
40 $company = $addslashes($company);
41 $title = $addslashes($title);
42 $from = $addslashes($from);
43 $to = $addslashes($to);
44 $description = $addslashes($description);
46 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_position (member_id, company, title, `from`, `to`, description) VALUES ($member_id, '$company', '$title', '$from', '$to', '$description')";
47 mysql_query($sql, $db);
53 * TODO: University names can be generated from another table.
55 * @param string Name of the University, in full. Might need to pull from another table.
56 * @param int This education begins on this date, yyyymm
57 * @param int This education ends on this date, yyyymm, or can be 'NOW'
58 * @param string The full name of the country this University is in, ie. Canada
59 * @param string The full name of the province this University is in, ie. Ontario
60 * @param string The name of the degree, ie. B.Sc.
61 * @param string The field of study, ie. Computer Science
62 * @param string The description of this education.
64 function addEducation($university, $from, $to, $country,
65 $province, $degree, $field, $description){
66 global $addslashes, $db;
67 $member_id = $this->id;
68 $university = $addslashes($university);
69 $from = $addslashes($from);
70 $to = $addslashes($to);
71 $country = $addslashes($country);
72 $province = $addslashes($province);
73 $degree = $addslashes($degree);
74 $field = $addslashes($field);
75 $description = $addslashes($description);
77 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_education (member_id, university, `from`, `to`, country, province, degree, field, description) VALUES ($member_id, '$university', '$from', '$to', '$country', '$province', '$degree', '$field', '$description')";
78 mysql_query($sql, $db);
83 * Add a new website associated with this member, can be blog, work, portfolio, etc.
84 * @param string Unique URL of the website
85 * @param string A name for the website.
87 function addWebsite($url, $site_name){
88 global $addslashes, $db;
89 $member_id = $this->id;
90 $url = $addslashes($url);
91 $site_name = $addslashes($site_name);
93 $sql = 'INSERT INTO '. TABLE_PREFIX ."social_member_websites (member_id, url, site_name) VALUES ($member_id, '$url', '$site_name')";
94 mysql_query($sql, $db);
99 * Add new interest for this member, in CSV format
100 * @param string interest
102 function addInterests($interests){
103 $this->updateAdditionalInformation($interests);
108 * Add new interest for this member, in CSV format
109 * @param string interest
111 function addAssociations($associations){
112 $this->updateAdditionalInformation('', $associations);
117 * Add new interest for this member, in CSV format
118 * @param string interest
120 function addAwards($awards){
121 $this->updateAdditionalInformation('', '', $awards);
124 * Add a new representation
125 * Special field for LCA to add a represetnative or agent.
127 * @param string The represetnative full name
128 * @param string The title of the representative
129 * @param string The represetnative's phone number
130 * @param string The representativ's email address
131 * @param string The representative's mailing address
133 function addRepresentation($rep_name, $rep_title, $rep_phone, $rep_email, $rep_address){
134 global $addslashes, $db;
135 $member_id = $this->id;
136 $rep_name = $addslashes($rep_name);
137 $rep_title = $addslashes($rep_title);
138 $rep_phone = $addslashes($rep_phone);
139 $rep_email = $addslashes($rep_email);
140 $rep_address = $addslashes($rep_address);
142 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_representation (member_id, rep_name, rep_title, rep_phone, rep_email, rep_address) VALUES ($member_id, '$rep_name', '$rep_title', '$rep_phone', '$rep_email', '$rep_address')";
143 mysql_query($sql, $db);
144 header('Location:edit_profile.php');
149 * Add a new contact person
150 * Special field for LCA to add a contact such as a parent or gaurdian.
152 * @param string The contact full name
153 * @param string The contact's phone number
154 * @param string The contact's email address
155 * @param string The contact's mailing address
158 function addContact($con_name, $con_phone, $con_email, $con_address){
159 global $addslashes, $db;
160 $member_id = $this->id;
161 $con_name = $addslashes($con_name);
162 $con_phone = $addslashes($con_phone);
163 $con_email = $addslashes($con_email);
164 $con_address = $addslashes($con_address);
166 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_contact (member_id, con_name, con_phone, con_email, con_address) VALUES ($member_id, '$con_name', '$con_phone', '$con_email', '$con_address')";
167 mysql_query($sql, $db);
168 header('Location:edit_profile.php');
172 * Add personal characteristics
173 * Special field for LCA to add a contact such as a parent or gaurdian.
175 * @param string person's weight
176 * @param string person's height
177 * @param string person's hair colour
178 * @param string person's eye colour
179 * @param string person's ethnicity
180 * @param string person's languages spoken
181 * @param string person's disbailities
184 function addPersonal($per_weight, $per_height, $per_hair, $per_eyes, $per_ethnicity, $per_languages, $per_disabilities){
185 global $addslashes, $db;
186 $member_id = $this->id;
187 $per_weight = $addslashes($per_weight);
188 $per_height = $addslashes($per_height);
189 $per_hair = $addslashes($per_hair);
190 $per_eyes = $addslashes($per_eyes);
191 $per_ethnicity = $addslashes($per_ethnicity);
192 $per_languages = $addslashes($per_languages);
193 $per_disabilities = $addslashes($per_disabilities);
195 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_personal (member_id, per_weight, per_height, per_hair, per_eyes, per_ethnicity, per_languages, per_disabilities) VALUES ($member_id, '$per_weight', '$per_height', '$per_hair', '$per_eyes','$per_ethnicity','$per_languages','$per_disabilities')";
196 mysql_query($sql, $db);
197 header('Location:edit_profile.php');
204 * Add additional information, including interest, awards, associations.
205 * @param string CSV format of interests, ie. camping, biking, etc
206 * @param string CSV format of associations, clubs, groups, ie. IEEE
207 * @param string CSV format of awards, honors
208 * @param string expterise, occupation
209 * @param string any extra information
211 function addAdditionalInformation($interests, $associations, $awards, $expertise, $others){
212 global $addslashes, $db;
213 $member_id = $this->id;
214 $interests = $addslashes($interests);
215 $associations = $addslashes($associations);
216 $awards = $addslashes($awards);
217 $expertise = $addslashes($expertise);
218 $others = $addslashes($others);
219 $sql = 'INSERT INTO ' . TABLE_PREFIX . "social_member_additional_information (member_id, interests, associations, awards, expertise, others) VALUES ($member_id, '$interests', '$associations', '$awards', '$expertise', '$others')";
220 mysql_query($sql, $db);
226 * @param int visitor id
228 function addVisitor($visitor_id){
230 $visitor_id = intval($visitor_id);
231 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_track (`member_id`, `visitor_id`, `timestamp`) VALUES (".$this->getID().", $visitor_id, NOW())";
232 mysql_query($sql, $db);
237 * Update a new job position
238 * @param int The id of this entry
239 * @param string Name of the company, in full.
240 * @param string Tht title of this position
241 * @param int Started date for this position, in the format of yyyymm
242 * @param int Position ended on this date, in the format of yyyymm, or 'NOW'.
243 * 'NOW' means it is still on going.
244 * @param string Description of the position
246 function updatePosition($id, $company, $title, $from, $to, $description){
247 global $addslashes, $db;
249 $company = $addslashes($company);
250 $title = $addslashes($title);
251 $form = $addslashes($form);
252 $to = $addslashes($to);
253 $description = $addslashes($description);
255 $sql = 'UPDATE '.TABLE_PREFIX."social_member_position SET company='$company', title='$title', `from`='$from', `to`='$to', description='$description' WHERE id=$id";
256 mysql_query($sql, $db);
261 * Update a new education
262 * TODO: University names can be generated from another table.
264 * @param int ID of this entry
265 * @param string Name of the University, in full. Might need to pull from another table.
266 * @param int This education begins on this date, yyyymm
267 * @param int This education ends on this date, yyyymm, or can be 'NOW'
268 * @param string The full name of the country this University is in, ie. Canada
269 * @param string The full name of the province this University is in, ie. Ontario
270 * @param string The name of the degree, ie. B.Sc.
271 * @param string The field of study, ie. Computer Science
272 * @param string The description of this education.
274 function updateEducation($id, $university, $from, $to, $country, $province, $degree, $field, $description){
275 global $addslashes, $db;
277 $university = $addslashes($university);
278 $from = $addslashes($from);
279 $to = $addslashes($to);
280 $country = $addslashes($country);
281 $province = $addslashes($province);
282 $degree = $addslashes($degree);
283 $field = $addslashes($field);
284 $description = $addslashes($description);
286 $sql = 'UPDATE '.TABLE_PREFIX."social_member_education SET university='$university', `from`='$from', `to`='$to', country='$country', province='$province', degree='$degree', field='$field', description='$description' WHERE id=$id";
287 mysql_query($sql, $db);
292 * Updates a new website associated with this member, can be blog, work, portfolio, etc.
293 * @param int ID of this entry
294 * @param string Unique URL of the website
295 * @param string A name for the website.
297 function updateWebsite($id, $url, $site_name){
298 global $addslashes, $db;
300 $url = $addslashes($url);
301 $site_name = $addslashes($site_name);
303 $sql = 'UPDATE '.TABLE_PREFIX."social_member_websites SET url='$url', site_name='$site_name' WHERE id=$id";
304 mysql_query($sql, $db);
309 * Update additional information, including interest, awards, associations.
310 * @param string CSV format of interests, ie. camping, biking, etc
311 * @param string CSV format of associations, clubs, groups, ie. IEEE
312 * @param string CSV format of awards, honors
313 * @param string expterise, occupation
314 * @param string any extra information
316 function updateAdditionalInformation($interests='', $associations='', $awards='', $expertise='', $others=''){
317 global $addslashes, $db;
318 $interests = $addslashes($interests);
319 $associations = $addslashes($associations);
320 $awards = $addslashes($awards);
321 $expertise = $addslashes($expertise);
322 $others = $addslashes($others);
325 //tricky, not all fields get updated at once. Update only the ones that has entries.
327 $sql .= "interests='$interests', ";
329 if ($associations!=''){
330 $sql .= " associations='$associations', ";
333 $sql .= "awards='$awards', ";
336 $sql .= "expertise='$expertise', ";
339 $sql .= "others='$others', ";
342 $sql = substr($sql, 0, -2);
345 $sql2 = 'INSERT INTO '.TABLE_PREFIX."social_member_additional_information SET ".$sql.", member_id=".$_SESSION['member_id'] . " ON DUPLICATE KEY UPDATE ".$sql;
346 mysql_query($sql2, $db);
349 * Edit representation
350 * Special field for LCA to add a represetnative or agent.
352 * @param string The represetnative full name
353 * @param string The title of the representative
354 * @param string The represetnative's phone number
355 * @param string The representativ's email address
356 * @param string The representative's mailing address
358 function updateRepresentation($id, $rep_name, $rep_title, $rep_phone, $rep_email, $rep_address){
359 global $addslashes, $db;
360 $member_id = $this->id;
361 $rep_name = $addslashes($rep_name);
362 $rep_title = $addslashes($rep_title);
363 $rep_phone = $addslashes($rep_phone);
364 $rep_email = $addslashes($rep_email);
365 $rep_address = $addslashes($rep_address);
367 $sql = "UPDATE ".TABLE_PREFIX."social_member_representation SET rep_name='$rep_name', rep_title='$rep_title', rep_phone='$rep_phone', rep_email='$rep_email', rep_address='$rep_address' WHERE id='$id'";
368 mysql_query($sql, $db);
372 * Edit contact person
373 * Special field for LCA to add a contact such as a parent or gaurdian.
375 * @param string The contact full name
376 * @param string The contact's phone number
377 * @param string The contact's email address
378 * @param string The contact's mailing address
381 function updateContact($con_name, $con_phone, $con_email, $con_address){
382 global $addslashes, $db;
383 $member_id = $this->id;
384 $con_name = $addslashes($con_name);
385 $con_phone = $addslashes($con_phone);
386 $con_email = $addslashes($con_email);
387 $con_address = $addslashes($con_address);
389 $sql = "UPDATE ".TABLE_PREFIX."social_member_contact SET con_name='$con_name', con_phone='$con_phone', con_email='$con_email', con_address='con_address' WHERE id='$id'";
390 mysql_query($sql, $db);
394 * Update personal characteristics
395 * Special field for LCA to add a contact such as a parent or gaurdian.
397 * @param string person's weight
398 * @param string person's height
399 * @param string person's hair colour
400 * @param string person's eye colour
401 * @param string person's ethnicity
402 * @param string person's languages spoken
403 * @param string person's disbailities
406 function updatePersonal($per_weight, $per_height, $per_hair, $per_eyes, $per_ethnicity, $per_languages, $per_disabilities){
407 global $addslashes, $db;
408 $member_id = $this->id;
409 $per_weight = $addslashes($per_weight);
410 $per_height = $addslashes($per_height);
411 $per_hair = $addslashes($per_hair);
412 $per_eyes = $addslashes($per_eyes);
413 $per_ethnicity = $addslashes($per_ethnicity);
414 $per_languages = $addslashes($per_languages);
415 $per_disabilities = $addslashes($per_disabilities);
417 $sql = "UPDATE ".TABLE_PREFIX."social_member_personal SET per_weight = '$per_weight', per_height = '$per_height', per_hair = '$per_hair', per_eyes = '$per_eyes', per_ethnicity = '$per_ethnicity', per_languages = '$per_languages', per_disabilities = '$per_disabilities' WHERE member_id = '$member_id'";
418 mysql_query($sql, $db);
419 header('Location:edit_profile.php');
426 * This method tends to be have a negative impact on system run time.
428 function getDetails(){
430 $sql = 'SELECT core.*, T.interests, T.associations, T.awards, T.expertise, T.others FROM '.
431 '(SELECT * FROM '.TABLE_PREFIX.'members WHERE member_id='.$this->id.') AS core '.
433 TABLE_PREFIX.'social_member_additional_information T ON core.member_id=T.member_id';
434 $result = mysql_query($sql, $db);
436 $row = mysql_fetch_assoc($result);
437 $this->profile = $row;
439 return $this->profile;
446 function getAddress(){
448 $sql = 'SELECT address, postal, city, province, country FROM '.TABLE_PREFIX.'members WHERE member_id='.$this->id;
449 $result = mysql_query($sql, $db);
451 $row = mysql_fetch_assoc($result);
459 * @return the array of job/position
461 function getPosition(){
465 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_position WHERE member_id='.$this->id;
466 $result = mysql_query($sql, $db);
468 while($row = mysql_fetch_assoc($result)){
479 * @return the array of education details
481 function getEducation(){
483 $education = array();
485 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_education WHERE member_id='.$this->id;
486 $result = mysql_query($sql, $db);
488 while($row = mysql_fetch_assoc($result)){
497 * Get websites. can be 1+
498 * @return the array of website details.
500 function getWebsites(){
504 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_websites WHERE member_id='.$this->id;
505 $result = mysql_query($sql, $db);
507 while($row = mysql_fetch_assoc($result)){
509 $row['url'] = htmlentities_utf8($row['url']);
520 * Get member's representative info
521 * @return the array of representative's details
523 function getRepresentation(){
525 $representation = array();
527 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_representation WHERE member_id='.$this->id;
528 $result = mysql_query($sql, $db);
530 while($row = mysql_fetch_assoc($result)){
531 $representation[] = $row;
534 return $representation;
537 * Get member's alternate contact info
538 * @return the array of contact's details
540 function getContact(){
544 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_contact WHERE member_id='.$this->id;
545 $result = mysql_query($sql, $db);
547 while($row = mysql_fetch_assoc($result)){
555 * Get member's personal info
556 * @return the array of personal characteristics
558 function getPersonal(){
562 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_personal WHERE member_id='.$this->id;
565 $result = mysql_query($sql, $db);
567 $personal = mysql_fetch_assoc($result);
574 * Get visitor counts within a month, the resultant array contains a daily, weekly, monthly, and a total count.
575 * @return the count of all visitors on this page, within a month.
577 function getVisitors(){
579 $count = array('month'=>0, 'week'=>0, 'day'=>0, 'total'=>0);
581 $month = time() - 60*60*24*30; //month, within 30days.
582 $week = time() - 60*60*24*7; //week, within 7 days.
583 $day = time() - 60*60*24; //day, within 24 hours.
585 $sql = 'SELECT visitor_id, UNIX_TIMESTAMP(timestamp) AS `current_time` FROM '.TABLE_PREFIX.'social_member_track WHERE member_id='.$this->id;
586 $result = mysql_query($sql, $db);
588 while ($row = mysql_fetch_assoc($result)){
589 if($row['current_time'] >= $month && $row['current_time'] <= $week){
591 } elseif ($row['current_time'] > $week && $row['current_time'] <= $day){
593 } elseif ($row['current_time'] > $day){
602 //clean up table randomly, 1%
603 if (rand(1,100) == 1){
604 $sql = 'DELETE FROM '.TABLE_PREFIX."social_member_track WHERE UNIX_TIMESTAMP(`timestamp`) < $month";
605 mysql_query($sql, $db);
614 * @param int position id
616 function deletePosition($id){
619 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_position WHERE id='.$id;
620 $result = mysql_query($sql, $db);
626 * @param int education id
628 function deleteEducation($id){
631 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_education WHERE id='.$id;
632 $result = mysql_query($sql, $db);
638 * @param int websites id
640 function deleteWebsite($id){
643 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_websites WHERE id='.$id;
644 $result = mysql_query($sql, $db);
651 function deleteInterests(){
654 $sql = 'UPDATE '.TABLE_PREFIX."social_member_additional_information SET interests='' WHERE member_id=".$this->getID();
655 $result = mysql_query($sql, $db);
660 * Delete associations
662 function deleteAssociations(){
665 $sql = 'UPDATE '.TABLE_PREFIX."social_member_additional_information SET associations='' WHERE member_id=".$this->getID();
666 $result = mysql_query($sql, $db);
673 function deleteAwards(){
676 $sql = 'UPDATE '.TABLE_PREFIX."social_member_additional_information SET awards='' WHERE member_id=".$this->getID();
677 $result = mysql_query($sql, $db);
681 * Delete representation
683 function deleteRepresentation($member_id){
686 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_representation WHERE member_id='.$this->getID();
687 $result = mysql_query($sql, $db);
693 function deleteContact(){
695 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_contact WHERE member_id='.$this->getID();
696 $result = mysql_query($sql, $db);
700 * Delete personal information
702 function deletePersonal(){
704 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_personal WHERE member_id='.$this->getID();
705 $result = mysql_query($sql, $db);
710 * Get the ID of this member