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 $_GET['id'] = intval($_GET['id']);
20 if (isset($_POST['cancel'])) {
21 header('Location: index.php');
23 } else if (isset($_POST['submit'])) {
24 require_once(TR_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
25 $usersDAO = new UsersDAO();
27 /* password check: password is verified front end by javascript. here is to handle the errors from javascript */
28 if ($_POST['password_error'] <> "")
30 $pwd_errors = explode(",", $_POST['password_error']);
32 foreach ($pwd_errors as $pwd_error)
34 if ($pwd_error == "missing_password")
35 $missing_fields[] = _AT('password');
37 $msg->addError($pwd_error);
42 if (isset($_POST['is_author'])) $is_author = 1;
45 if (!isset($_GET['id'])) // create new user
47 $user_id = $usersDAO->Create($_POST['user_group_id'],
49 $_POST['form_password_hidden'],
54 $_POST['organization'],
60 $_POST['postal_code'],
63 if (is_int($user_id) && $user_id > 0)
65 if (defined('TR_EMAIL_CONFIRMATION') && TR_EMAIL_CONFIRMATION) {
66 $msg->addFeedback('REG_THANKS_CONFIRM');
68 $code = substr(md5($_POST['email'] . $now . $user_id), 0, 10);
70 $confirmation_link = $_base_href . 'confirm.php?id='.$user_id.SEP.'m='.$code;
72 /* send the email confirmation message: */
73 require(TR_INCLUDE_PATH . 'classes/phpmailer/transformablemailer.class.php');
74 $mail = new TransformableMailer();
76 $mail->From = $_config['contact_email'];
77 $mail->AddAddress($_POST['email']);
78 $mail->Subject = SITE_NAME . ' - ' . _AT('email_confirmation_subject');
79 $mail->Body = _AT('email_confirmation_message', SITE_NAME, $confirmation_link)."\n\n";
85 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
86 header('Location: index.php');
91 else // edit existing user
93 if ($usersDAO->Update($_GET['id'],
94 $_POST['user_group_id'],
100 $_POST['organization'],
106 $_POST['postal_code'],
110 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
111 header('Location: index.php');
117 // end of handle submit
120 $userGroupsDAO = new UserGroupsDAO();
122 if (isset($_GET['id'])) // edit existing user
124 $usersDAO = new UsersDAO();
125 $savant->assign('user_row', $usersDAO->getUserByID($_GET['id']));
126 $savant->assign('show_password', false);
129 else // create new user
131 $savant->assign('show_password', true);
134 /*****************************/
135 /* template starts down here */
138 $onload = 'document.form.login.focus();';
140 $savant->assign('show_user_group', true);
141 $savant->assign('show_status', true);
142 $savant->assign('all_user_groups', $userGroupsDAO->getAll());
143 $savant->assign('title', _AT('create_edit_user'));
144 $savant->assign('submit_button_text', _AT('save'));
146 $savant->display('register.tmpl.php');