2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 define('TR_INCLUDE_PATH', '../include/');
14 include_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 include_once(TR_INCLUDE_PATH.'classes/DAO/UsersDAO.class.php');
16 include_once(TR_INCLUDE_PATH.'classes/DAO/UserGroupsDAO.class.php');
19 if (isset($_POST['cancel'])) {
20 header('Location: index.php');
22 } else if (isset($_POST['submit'])) {
23 require_once(TR_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
24 $usersDAO = new UsersDAO();
26 /* password check: password is verified front end by javascript. here is to handle the errors from javascript */
27 if ($_POST['password_error'] <> "")
29 $pwd_errors = explode(",", $_POST['password_error']);
31 foreach ($pwd_errors as $pwd_error)
33 if ($pwd_error == "missing_password")
34 $missing_fields[] = _AT('password');
36 $msg->addError($pwd_error);
41 if (isset($_POST['is_author'])) $is_author = 1;
44 if (!isset($_GET['id'])) // create new user
46 $user_id = $usersDAO->Create($_POST['user_group_id'],
48 $_POST['form_password_hidden'],
53 $_POST['organization'],
59 $_POST['postal_code'],
62 if (is_int($user_id) && $user_id > 0)
64 if (defined('TR_EMAIL_CONFIRMATION') && TR_EMAIL_CONFIRMATION) {
65 $msg->addFeedback('REG_THANKS_CONFIRM');
67 $code = substr(md5($_POST['email'] . $now . $user_id), 0, 10);
69 $confirmation_link = $_base_href . 'confirm.php?id='.$user_id.SEP.'m='.$code;
71 /* send the email confirmation message: */
72 require(TR_INCLUDE_PATH . 'classes/phpmailer/transformablemailer.class.php');
73 $mail = new TransformableMailer();
75 $mail->From = $_config['contact_email'];
76 $mail->AddAddress($_POST['email']);
77 $mail->Subject = SITE_NAME . ' - ' . _AT('email_confirmation_subject');
78 $mail->Body = _AT('email_confirmation_message', SITE_NAME, $confirmation_link)."\n\n";
84 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
85 header('Location: index.php');
90 else // edit existing user
92 if ($usersDAO->Update($_GET['id'],
93 $_POST['user_group_id'],
99 $_POST['organization'],
105 $_POST['postal_code'],
109 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
110 header('Location: index.php');
116 // end of handle submit
119 $userGroupsDAO = new UserGroupsDAO();
121 if (isset($_GET['id'])) // edit existing user
123 $usersDAO = new UsersDAO();
124 $savant->assign('user_row', $usersDAO->getUserByID($_GET['id']));
125 $savant->assign('show_password', false);
128 else // create new user
130 $savant->assign('show_password', true);
133 /*****************************/
134 /* template starts down here */
137 $onload = 'document.form.login.focus();';
139 $savant->assign('show_user_group', true);
140 $savant->assign('show_status', true);
141 $savant->assign('all_user_groups', $userGroupsDAO->getAll());
142 $savant->assign('title', _AT('create_edit_user'));
143 $savant->assign('submit_button_text', _AT('save'));
145 $savant->display('register.tmpl.php');