2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
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 /************************************************************************/
13 // $Id: profile.php 7208 2008-01-09 16:07:24Z greg $
15 $_user_location = 'public';
17 define('AT_INCLUDE_PATH', '../../include/');
18 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
20 if ($_SESSION['valid_user'] !== true) {
21 require(AT_INCLUDE_PATH.'header.inc.php');
23 $info = array('INVALID_USER', $_SESSION['course_id']);
24 $msg->printInfos($info);
26 require(AT_INCLUDE_PATH.'footer.inc.php');
30 if (isset($_POST['cancel'])) {
31 $msg->addFeedback('CANCELLED');
32 Header('Location: profile.php');
36 if (isset($_POST['submit'])) {
37 $missing_fields = array();
39 if (!$_POST['first_name']) {
40 $missing_fields[] = _AT('first_name');
43 if (!$_POST['last_name']) {
44 $missing_fields[] = _AT('last_name');
47 $_POST['first_name'] = str_replace('<', '', $_POST['first_name']);
48 $_POST['second_name'] = str_replace('<', '', $_POST['second_name']);
49 $_POST['last_name'] = str_replace('<', '', $_POST['last_name']);
51 // check if first+last is unique
52 if ($_POST['first_name'] && $_POST['last_name']) {
53 $first_name_sql = $addslashes($_POST['first_name']);
54 $last_name_sql = $addslashes($_POST['last_name']);
55 $second_name_sql = $addslashes($_POST['second_name']);
57 $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";
58 $result = mysql_query($sql, $db);
59 if (mysql_fetch_assoc($result)) {
60 $msg->addError('FIRST_LAST_NAME_UNIQUE');
65 $mo = intval($_POST['month']);
66 $day = intval($_POST['day']);
67 $yr = intval($_POST['year']);
69 /* let's us take (one or) two digit years (ex. 78 = 1978, 3 = 2003) */
70 if ($yr < date('y')) {
72 } else if ($yr < 1900) {
76 $dob = $yr.'-'.$mo.'-'.$day;
78 if ($mo && $day && $yr && !checkdate($mo, $day, $yr)) {
79 $msg->addError('DOB_INVALID');
80 } else if (!$mo || !$day || !$yr) {
85 if (($_POST['gender'] != 'm') && ($_POST['gender'] != 'f')) {
86 $_POST['gender'] = 'n'; // not specified
90 if ($missing_fields) {
91 $missing_fields = implode(', ', $missing_fields);
92 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
94 $login = strtolower($_POST['login']);
95 if (!$msg->containsErrors()) {
96 if (($_POST['website']) && (!ereg('://',$_POST['website']))) { $_POST['website'] = 'http://'.$_POST['website']; }
97 if ($_POST['website'] == 'http://') { $_POST['website'] = ''; }
99 if (isset($_POST['private_email'])) {
100 $_POST['private_email'] = 1;
102 $_POST['private_email'] = 0;
105 // insert into the db.
106 $_POST['website'] = $addslashes($_POST['website']);
107 $_POST['first_name'] = $addslashes($_POST['first_name']);
108 $_POST['second_name']= $addslashes($_POST['second_name']);
109 $_POST['last_name'] = $addslashes($_POST['last_name']);
110 $_POST['address'] = $addslashes($_POST['address']);
111 $_POST['postal'] = $addslashes($_POST['postal']);
112 $_POST['city'] = $addslashes($_POST['city']);
113 $_POST['province'] = $addslashes($_POST['province']);
114 $_POST['country'] = $addslashes($_POST['country']);
115 $_POST['phone'] = $addslashes($_POST['phone']);
117 $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]";
119 $result = mysql_query($sql,$db);
121 $msg->printErrors('DB_NOT_UPDATED');
125 $msg->addFeedback('PROFILE_UPDATED');
127 header('Location: basic_profile.php');
132 $sql = 'SELECT * FROM '.TABLE_PREFIX.'members WHERE member_id='.$_SESSION['member_id'];
133 $result = mysql_query($sql,$db);
134 $row = mysql_fetch_assoc($result);
136 if (!isset($_POST['submit'])) {
138 list($_POST['year'],$_POST['month'],$_POST['day']) = explode('-', $row['dob']);
141 /* template starts here */
142 require(AT_INCLUDE_PATH.'header.inc.php');
143 include('lib/profile_menu.inc.php');
144 $savant->assign('row', $row);
145 $onload = 'document.form.first_name.focus();';
147 //$savant->display('registration.tmpl.php');
148 $savant->display('html/basic_profile.tmpl.php');
149 require(AT_INCLUDE_PATH.'footer.inc.php');?>