2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 = urlencode($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);
126 * Add additional information, including interest, awards, associations.
127 * @param string CSV format of interests, ie. camping, biking, etc
128 * @param string CSV format of associations, clubs, groups, ie. IEEE
129 * @param string CSV format of awards, honors
130 * @param string expterise, occupation
131 * @param string any extra information
133 function addAdditionalInformation($interests, $associations, $awards, $expertise, $others){
134 global $addslashes, $db;
135 $member_id = $this->id;
136 $interests = $addslashes($interests);
137 $associations = $addslashes($associations);
138 $awards = $addslashes($awards);
139 $expertise = $addslashes($expertise);
140 $others = $addslashes($others);
141 $sql = 'INSERT INTO ' . TABLE_PREFIX . "social_member_additional_information (member_id, interests, associations, awards, expertise, others) VALUES ($member_id, '$interests', '$associations', '$awards', '$expertise', '$others')";
142 mysql_query($sql, $db);
148 * @param int visitor id
150 function addVisitor($visitor_id){
152 $visitor_id = intval($visitor_id);
153 $sql = 'INSERT INTO '.TABLE_PREFIX."social_member_track (`member_id`, `visitor_id`, `timestamp`) VALUES (".$this->getID().", $visitor_id, NOW())";
154 mysql_query($sql, $db);
159 * Update a new job position
160 * @param int The id of this entry
161 * @param string Name of the company, in full.
162 * @param string Tht title of this position
163 * @param int Started date for this position, in the format of yyyymm
164 * @param int Position ended on this date, in the format of yyyymm, or 'NOW'.
165 * 'NOW' means it is still on going.
166 * @param string Description of the position
168 function updatePosition($id, $company, $title, $from, $to, $description){
169 global $addslashes, $db;
171 $company = $addslashes($company);
172 $title = $addslashes($title);
173 $form = $addslashes($form);
174 $to = $addslashes($to);
175 $description = $addslashes($description);
177 $sql = 'UPDATE '.TABLE_PREFIX."social_member_position SET company='$company', title='$title', `from`='$from', `to`='$to', description='$description' WHERE id=$id";
178 mysql_query($sql, $db);
183 * Update a new education
184 * TODO: University names can be generated from another table.
186 * @param int ID of this entry
187 * @param string Name of the University, in full. Might need to pull from another table.
188 * @param int This education begins on this date, yyyymm
189 * @param int This education ends on this date, yyyymm, or can be 'NOW'
190 * @param string The full name of the country this University is in, ie. Canada
191 * @param string The full name of the province this University is in, ie. Ontario
192 * @param string The name of the degree, ie. B.Sc.
193 * @param string The field of study, ie. Computer Science
194 * @param string The description of this education.
196 function updateEducation($id, $university, $from, $to, $country, $province, $degree, $field, $description){
197 global $addslashes, $db;
199 $university = $addslashes($university);
200 $from = $addslashes($from);
201 $to = $addslashes($to);
202 $country = $addslashes($country);
203 $province = $addslashes($province);
204 $degree = $addslashes($degree);
205 $field = $addslashes($field);
206 $description = $addslashes($description);
208 $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";
209 mysql_query($sql, $db);
214 * Updates a new website associated with this member, can be blog, work, portfolio, etc.
215 * @param int ID of this entry
216 * @param string Unique URL of the website
217 * @param string A name for the website.
219 function updateWebsite($id, $url, $site_name){
220 global $addslashes, $db;
222 $url = $addslashes($url);
223 $site_name = $addslashes($site_name);
225 $sql = 'UPDATE '.TABLE_PREFIX."social_member_websites SET url='$url', site_name='$site_name' WHERE id=$id";
226 mysql_query($sql, $db);
231 * Update additional information, including interest, awards, associations.
232 * @param string CSV format of interests, ie. camping, biking, etc
233 * @param string CSV format of associations, clubs, groups, ie. IEEE
234 * @param string CSV format of awards, honors
235 * @param string expterise, occupation
236 * @param string any extra information
238 function updateAdditionalInformation($interests='', $associations='', $awards='', $expertise='', $others=''){
239 global $addslashes, $db;
240 $interests = $addslashes($interests);
241 $associations = $addslashes($associations);
242 $awards = $addslashes($awards);
243 $expertise = $addslashes($expertise);
244 $others = $addslashes($others);
247 //tricky, not all fields get updated at once. Update only the ones that has entries.
249 $sql .= "interests='$interests', ";
251 if ($associations!=''){
252 $sql .= " associations='$associations', ";
255 $sql .= "awards='$awards', ";
258 $sql .= "expertise='$expertise', ";
261 $sql .= "others='$others', ";
264 $sql = substr($sql, 0, -2);
267 $sql2 = 'INSERT INTO '.TABLE_PREFIX."social_member_additional_information SET ".$sql.", member_id=".$_SESSION['member_id'] . " ON DUPLICATE KEY UPDATE ".$sql;
268 mysql_query($sql2, $db);
274 * This method tends to be have a negative impact on system run time.
276 function getDetails(){
278 $sql = 'SELECT core.*, T.interests, T.associations, T.awards, T.expertise, T.others FROM '.
279 '(SELECT * FROM '.TABLE_PREFIX.'members WHERE member_id='.$this->id.') AS core '.
281 TABLE_PREFIX.'social_member_additional_information T ON core.member_id=T.member_id';
282 $result = mysql_query($sql, $db);
284 $row = mysql_fetch_assoc($result);
285 $this->profile = $row;
287 return $this->profile;
294 function getAddress(){
296 $sql = 'SELECT address, postal, city, province, country FROM '.TABLE_PREFIX.'members WHERE member_id='.$this->id;
297 $result = mysql_query($sql, $db);
299 $row = mysql_fetch_assoc($result);
307 * @return the array of job/position
309 function getPosition(){
313 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_position WHERE member_id='.$this->id;
314 $result = mysql_query($sql, $db);
316 while($row = mysql_fetch_assoc($result)){
327 * @return the array of education details
329 function getEducation(){
331 $education = array();
333 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_education WHERE member_id='.$this->id;
334 $result = mysql_query($sql, $db);
336 while($row = mysql_fetch_assoc($result)){
345 * Get websites. can be 1+
346 * @return the array of website details.
348 function getWebsites(){
352 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_member_websites WHERE member_id='.$this->id;
353 $result = mysql_query($sql, $db);
355 while($row = mysql_fetch_assoc($result)){
364 * Get visitor counts within a month, the resultant array contains a daily, weekly, monthly, and a total count.
365 * @return the count of all visitors on this page, within a month.
367 function getVisitors(){
369 $count = array('month'=>0, 'week'=>0, 'day'=>0, 'total'=>0);
371 $month = time() - 60*60*24*30; //month, within 30days.
372 $week = time() - 60*60*24*7; //week, within 7 days.
373 $day = time() - 60*60*24; //day, within 24 hours.
375 $sql = 'SELECT visitor_id, UNIX_TIMESTAMP(timestamp) AS `current_time` FROM '.TABLE_PREFIX.'social_member_track WHERE member_id='.$this->id;
376 $result = mysql_query($sql, $db);
378 while ($row = mysql_fetch_assoc($result)){
379 if($row['current_time'] >= $month && $row['current_time'] <= $week){
381 } elseif ($row['current_time'] > $week && $row['current_time'] <= $day){
383 } elseif ($row['current_time'] > $day){
392 //clean up table randomly, 1%
393 if (rand(1,100) == 1){
394 $sql = 'DELETE FROM '.TABLE_PREFIX."social_member_track WHERE UNIX_TIMESTAMP(`timestamp`) < $month";
395 mysql_query($sql, $db);
404 * @param int position id
406 function deletePosition($id){
409 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_position WHERE id='.$id;
410 $result = mysql_query($sql, $db);
416 * @param int education id
418 function deleteEducation($id){
421 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_education WHERE id='.$id;
422 $result = mysql_query($sql, $db);
428 * @param int websites id
430 function deleteWebsite($id){
433 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_member_websites WHERE id='.$id;
434 $result = mysql_query($sql, $db);
441 function deleteInterests(){
444 $sql = 'UPDATE '.TABLE_PREFIX."social_member_additional_information SET interests='' WHERE member_id=".$this->getID();
445 $result = mysql_query($sql, $db);
450 * Delete associations
452 function deleteAssociations(){
455 $sql = 'UPDATE '.TABLE_PREFIX."social_member_additional_information SET associations='' WHERE member_id=".$this->getID();
456 $result = mysql_query($sql, $db);
463 function deleteAwards(){
466 $sql = 'UPDATE '.TABLE_PREFIX."social_member_additional_information SET awards='' WHERE member_id=".$this->getID();
467 $result = mysql_query($sql, $db);
472 * Get the ID of this member