f57de5640eb7022b9c7b1d94615fe0a56327a9d1
[acontent.git] / docs / user / user_create_edit.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
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');
17
18 // handle submit
19 if (isset($_POST['cancel'])) {
20         header('Location: index.php');
21         exit;
22 } else if (isset($_POST['submit'])) {
23         require_once(TR_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
24         $usersDAO = new UsersDAO();
25         
26         /* password check: password is verified front end by javascript. here is to handle the errors from javascript */
27         if ($_POST['password_error'] <> "")
28         {
29                 $pwd_errors = explode(",", $_POST['password_error']);
30
31                 foreach ($pwd_errors as $pwd_error)
32                 {
33                         if ($pwd_error == "missing_password")
34                                 $missing_fields[] = _AT('password');
35                         else
36                                 $msg->addError($pwd_error);
37                 }
38         }
39         else
40         {
41                 if (isset($_POST['is_author'])) $is_author = 1;
42                 else $is_author = 0;
43                 
44                 if (!isset($_GET['id']))  // create new user
45                 {
46                         $user_id = $usersDAO->Create($_POST['user_group_id'],
47                               $_POST['login'],
48                                       $_POST['form_password_hidden'],
49                                       $_POST['email'],
50                                       $_POST['first_name'],
51                                       $_POST['last_name'],
52                                   $is_author,
53                                   $_POST['organization'],
54                                   $_POST['phone'],
55                                   $_POST['address'],
56                                   $_POST['city'],
57                                   $_POST['province'],
58                                   $_POST['country'],
59                                   $_POST['postal_code'],
60                                       $_POST['status']);
61                         
62                         if (is_int($user_id) && $user_id > 0)
63                         {
64                                 if (defined('TR_EMAIL_CONFIRMATION') && TR_EMAIL_CONFIRMATION) {
65                                         $msg->addFeedback('REG_THANKS_CONFIRM');
66                 
67                                         $code = substr(md5($_POST['email'] . $now . $user_id), 0, 10);
68                                         
69                                         $confirmation_link = $_base_href . 'confirm.php?id='.$user_id.SEP.'m='.$code;
70                 
71                                         /* send the email confirmation message: */
72                                         require(TR_INCLUDE_PATH . 'classes/phpmailer/transformablemailer.class.php');
73                                         $mail = new TransformableMailer();
74                 
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";
79                 
80                                         $mail->Send();
81                                 } 
82                                 else 
83                                 {
84                                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
85                                         header('Location: index.php');
86                                         exit;
87                                 }
88                         }
89                 }
90                 else  // edit existing user
91                 {
92                         if ($usersDAO->Update($_GET['id'], 
93                                           $_POST['user_group_id'],
94                                   $_POST['login'],
95                                           $_POST['email'],
96                                           $_POST['first_name'],
97                                           $_POST['last_name'],
98                                       $is_author,
99                                       $_POST['organization'],
100                                       $_POST['phone'],
101                                       $_POST['address'],
102                                       $_POST['city'],
103                                       $_POST['province'],
104                                       $_POST['country'],
105                                       $_POST['postal_code'],
106                                           $_POST['status']))
107                         
108                         {
109                                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
110                                 header('Location: index.php');
111                                 exit;
112                         }
113                 }
114         }
115 }
116 // end of handle submit
117
118 // initialize page 
119 $userGroupsDAO = new UserGroupsDAO();
120
121 if (isset($_GET['id'])) // edit existing user
122 {
123         $usersDAO = new UsersDAO();
124         $savant->assign('user_row', $usersDAO->getUserByID($_GET['id']));
125         $savant->assign('show_password', false);
126         
127 }
128 else  // create new user
129 {
130         $savant->assign('show_password', true);
131         
132 }
133 /*****************************/
134 /* template starts down here */
135
136 global $onload;
137 $onload = 'document.form.login.focus();';
138
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'));
144
145 $savant->display('register.tmpl.php');
146
147 ?>