add a readme file to the top level AContent directory
[acontent.git] / register.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 require(TR_INCLUDE_PATH.'vitals.inc.php');
15 include(TR_INCLUDE_PATH."securimage/securimage.php");
16
17 if (isset($_POST['cancel'])) {
18         header('Location: index.php');
19         exit;
20 } else if (isset($_POST['submit'])) {
21         require_once(TR_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
22         $usersDAO = new UsersDAO();
23         
24         /* password check: password is verified front end by javascript. here is to handle the errors from javascript */
25         if ($_POST['password_error'] <> "")
26         {
27                 $pwd_errors = explode(",", $_POST['password_error']);
28
29                 foreach ($pwd_errors as $pwd_error)
30                 {
31                         if ($pwd_error == "missing_password")
32                                 $missing_fields[] = _AT('password');
33                         else
34                                 $msg->addError($pwd_error);
35                 }
36         }
37         //CAPTCHA
38         if ($_config['use_captcha']==TR_STATUS_ENABLED){
39                 $img = new Securimage();
40                 $valid = $img->check($_POST['secret']);
41                 if (!$valid)
42                         $msg->addError('SECRET_ERROR');
43         }
44
45         if (!$msg->containsErrors())
46         {
47                 if (isset($_POST['is_author'])) $is_author = 1;
48                 else $is_author = 0;
49                 
50                 $user_id = $usersDAO->Create(TR_USER_GROUP_USER,
51                       $_POST['login'],
52                               $_POST['form_password_hidden'],
53                               $_POST['email'],
54                               $_POST['first_name'],
55                               $_POST['last_name'],
56                               $is_author,
57                               $_POST['organization'],
58                               $_POST['phone'],
59                               $_POST['address'],
60                               $_POST['city'],
61                               $_POST['province'],
62                               $_POST['country'],
63                               $_POST['postal_code'],
64                               TR_STATUS_ENABLED);
65                 
66                 if (is_int($user_id) && $user_id > 0)
67                 {
68                         if (defined('TR_EMAIL_CONFIRMATION') && TR_EMAIL_CONFIRMATION) {
69                                 $msg->addFeedback('REG_THANKS_CONFIRM');
70         
71                                 $code = substr(md5($_POST['email'] . $now . $user_id), 0, 10);
72                                 
73                                 $confirmation_link = $_base_href . 'confirm.php?id='.$user_id.SEP.'m='.$code;
74         
75                                 /* send the email confirmation message: */
76                                 require(TR_INCLUDE_PATH . 'classes/phpmailer/transformablemailer.class.php');
77                                 $mail = new TransformableMailer();
78         
79                                 $mail->From     = $_config['contact_email'];
80                                 $mail->AddAddress($_POST['email']);
81                                 $mail->Subject = SITE_NAME . ' - ' . _AT('email_confirmation_subject');
82                                 $mail->Body    = _AT('email_confirmation_message', SITE_NAME, $confirmation_link)."\n\n";
83         
84                                 $mail->Send();
85                         } 
86                         else 
87                         {
88                                 // auto login
89                                 $usersDAO->setLastLogin($user_id);
90                                 $_SESSION['user_id'] = $user_id;
91                                 
92                                 // show web service ID in success message
93                                 $row = $usersDAO->getUserByID($user_id);
94                                 $msg->addFeedback(array('REGISTER_SUCCESS', $row['web_service_id']));
95                                 header('Location: index.php');
96                                 exit;
97                         }
98                 }
99         }
100 }
101
102 /*****************************/
103 /* template starts down here */
104
105 global $onload;
106 $onload = 'document.form.login.focus();';
107
108 $savant->assign('title', _AT('registration'));
109 $savant->assign('submit_button_text', _AT('register'));
110 $savant->assign('show_user_group', false);
111 $savant->assign('show_status', false);
112 $savant->assign('show_password', true);
113 if ($_config['use_captcha'] == TR_STATUS_ENABLED) $savant->assign('use_captcha', true);
114
115 $savant->display('register.tmpl.php');
116
117 ?>