remove old readme
[atutor.git] / docs / mods / _standard / social / basic_profile.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2009                                                                              */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
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 /****************************************************************/
13 // $Id$
14 $_user_location = 'public';
15
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
19 if ($_SESSION['valid_user'] !== true) {
20         require(AT_INCLUDE_PATH.'header.inc.php');
21
22         $info = array('INVALID_USER', $_SESSION['course_id']);
23         $msg->printInfos($info);
24         require(AT_INCLUDE_PATH.'footer.inc.php');
25         exit;
26 }
27
28 if (isset($_POST['cancel'])) {
29         $msg->addFeedback('CANCELLED');
30         Header('Location: profile.php');
31         exit;
32 }
33
34 if (isset($_POST['submit'])) {
35         $missing_fields = array();
36
37         if (!$_POST['first_name']) { 
38                 $missing_fields[] = _AT('first_name');
39         }
40
41         if (!$_POST['last_name']) { 
42                 $missing_fields[] = _AT('last_name');
43         }
44
45         $_POST['first_name'] = str_replace('<', '', $_POST['first_name']);
46         $_POST['second_name'] = str_replace('<', '', $_POST['second_name']);
47         $_POST['last_name'] = str_replace('<', '', $_POST['last_name']);
48
49         // check if first+last is unique
50         if ($_POST['first_name'] && $_POST['last_name']) {
51                 $first_name_sql  = $addslashes($_POST['first_name']);
52                 $last_name_sql   = $addslashes($_POST['last_name']);
53                 $second_name_sql = $addslashes($_POST['second_name']);
54
55                 $sql = "SELECT member_id FROM ".TABLE_PREFIX."members WHERE first_name='$first_name_sql' AND second_name='$second_name_sql' AND last_name='$last_name_sql' AND member_id<>$_SESSION[member_id] LIMIT 1";
56                 $result = mysql_query($sql, $db);
57                 if (mysql_fetch_assoc($result)) {
58                         $msg->addError('FIRST_LAST_NAME_UNIQUE');
59                 }
60         }
61
62         //check date of birth
63         $mo = intval($_POST['month']);
64         $day = intval($_POST['day']);
65         $yr = intval($_POST['year']);
66
67         /* let's us take (one or) two digit years (ex. 78 = 1978, 3 = 2003) */
68         if ($yr < date('y')) { 
69                 $yr += 2000; 
70         } else if ($yr < 1900) { 
71                 $yr += 1900; 
72         } 
73
74         $dob = $yr.'-'.$mo.'-'.$day;
75
76         if ($mo && $day && $yr && !checkdate($mo, $day, $yr)) { 
77                 $msg->addError('DOB_INVALID');
78         } else if (!$mo || !$day || !$yr) {
79                 $dob = '0000-00-00';
80                 $yr = $mo = $day = 0;
81         }
82
83         if (($_POST['gender'] != 'm') && ($_POST['gender'] != 'f')) {
84                 $_POST['gender'] = 'n'; // not specified
85         }
86         
87         
88         if ($missing_fields) {
89                 $missing_fields = implode(', ', $missing_fields);
90                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
91         }
92         $login = strtolower($_POST['login']);
93         if (!$msg->containsErrors()) {                  
94                 if (($_POST['website']) && (!strstr($_POST['website'], '://'))) { $_POST['website'] = 'http://'.$_POST['website']; }
95                 if ($_POST['website'] == 'http://') { $_POST['website'] = ''; }
96
97                 if (isset($_POST['private_email'])) {
98                         $_POST['private_email'] = 1;
99                 } else {
100                         $_POST['private_email'] = 0;
101                 }
102
103                 // insert into the db.
104                 $_POST['website']    = $addslashes($_POST['website']);
105                 $_POST['first_name'] = $addslashes($_POST['first_name']);
106                 $_POST['second_name']= $addslashes($_POST['second_name']);
107                 $_POST['last_name']  = $addslashes($_POST['last_name']);
108                 $_POST['address']    = $addslashes($_POST['address']);
109                 $_POST['postal']     = $addslashes($_POST['postal']);
110                 $_POST['city']       = $addslashes($_POST['city']);
111                 $_POST['province']   = $addslashes($_POST['province']);
112                 $_POST['country']    = $addslashes($_POST['country']);
113                 $_POST['phone']      = $addslashes($_POST['phone']);
114
115                 $sql = "UPDATE ".TABLE_PREFIX."members SET website='$_POST[website]', first_name='$_POST[first_name]', second_name='$_POST[second_name]', last_name='$_POST[last_name]', dob='$dob', gender='$_POST[gender]', address='$_POST[address]', postal='$_POST[postal]', city='$_POST[city]', province='$_POST[province]', country='$_POST[country]', phone='$_POST[phone]', language='$_SESSION[lang]', private_email=$_POST[private_email], creation_date=creation_date, last_login=last_login WHERE member_id=$_SESSION[member_id]";
116
117                 $result = mysql_query($sql,$db);
118                 if (!$result) {
119                         $msg->printErrors('DB_NOT_UPDATED');
120                         exit;
121                 }
122
123                 $msg->addFeedback('PROFILE_UPDATED');
124
125                 header('Location: basic_profile.php');
126                 exit;
127         }
128 }
129
130 $sql    = 'SELECT * FROM '.TABLE_PREFIX.'members WHERE member_id='.$_SESSION['member_id'];
131 $result = mysql_query($sql,$db);
132 $row = mysql_fetch_assoc($result);
133
134 if (!isset($_POST['submit'])) {
135         $_POST = $row;
136         list($_POST['year'],$_POST['month'],$_POST['day']) = explode('-', $row['dob']);
137 }
138
139 /* template starts here */
140 require(AT_INCLUDE_PATH.'header.inc.php');
141
142 $savant->assign('row', $row);
143 $onload = 'document.form.first_name.focus();';
144
145 //$savant->display('registration.tmpl.php');
146 $savant->display('social/basic_profile.tmpl.php');
147 require(AT_INCLUDE_PATH.'footer.inc.php');
148 ?>