Project

General

Profile

1 1475 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6 1529 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7 1475 Luisehahne
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
 */
17
18 1815 Luisehahne
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(!defined('WB_URL')) {
21
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
22
	throw new IllegalFileException();
23
}
24
/* -------------------------------------------------------- */
25 1475 Luisehahne
26 1815 Luisehahne
	function add_user($admin, &$aActionRequest)
27
	{
28
		global $MESSAGE,$TEXT, $HEADING;
29
		$database = WbDatabase::getInstance();
30
        $bRetVal = false;
31
        $iMinPassLength = 6;
32 1475 Luisehahne
33 1815 Luisehahne
        if( !$admin->checkFTAN() )
34
        {
35
//        	$admin->print_header();
36
        	msgQueue::add($MESSAGE['GENERIC_SECURITY_ACCESS']);
37
            return $bRetVal;
38
        }
39 1475 Luisehahne
40 1815 Luisehahne
        // Get details entered
41
        $groups_id = (isset($aActionRequest['groups'])) ? implode(",", $admin->add_slashes($aActionRequest['groups'])) : '';
42
        $groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
43
        $active = intval(strip_tags($admin->StripCodeFromText($aActionRequest['active'][0])));
44
        $username_fieldname = strip_tags($admin->StripCodeFromText($aActionRequest['username_fieldname']));
45
        $username = strtolower(strip_tags($admin->StripCodeFromText($aActionRequest[$username_fieldname])));
46
        $password = strip_tags($admin->StripCodeFromText($aActionRequest['password']));
47
        $password2 = strip_tags($admin->StripCodeFromText($aActionRequest['password2']));
48
        $display_name = strip_tags($admin->StripCodeFromText($aActionRequest['display_name']));
49
        $email = strip_tags($admin->StripCodeFromText($aActionRequest['email']));
50
        $home_folder = strip_tags($admin->StripCodeFromText($aActionRequest['home_folder']));
51 1475 Luisehahne
52 1815 Luisehahne
        $language = DEFAULT_LANGUAGE;
53
        $timezone = -72000;
54
        $date_format = DEFAULT_DATE_FORMAT;
55
        $time_format = DEFAULT_TIME_FORMAT;
56
        $confirm_code = '';
57
        $confirm_timeout = 0;
58
        $remember_key = '';
59
        $login_ip = '';
60
        $last_reset = 0;
61
        $login_when = 0;
62 1475 Luisehahne
63 1815 Luisehahne
        // Check values
64
        // Check values
65
        if($groups_id == "") {
66
        	msgQueue::add($MESSAGE['USERS_NO_GROUP']);
67
        } else {
68
            $aGroups_id = explode(',', $groups_id);
69
            //if user is in administrator-group, get this group else just get the first one
70
            if($admin->is_group_match($groups_id,'1')) { $group_id = 1; } else { $group_id = intval($aGroups_id[0]); }
71
        }
72 1475 Luisehahne
73 1815 Luisehahne
        if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
74
        	msgQueue::add( $MESSAGE['USERS_NAME_INVALID_CHARS']);
75
        }
76 1475 Luisehahne
77 1815 Luisehahne
		$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
78
                'WHERE `username` LIKE \''.$username.'\' ';
79
        // Check if username already exists
80
        if( ($iFoundUser = $database->get_one($sql)) != null ) {
81
            if($iFoundUser) {
82
            	msgQueue::add($MESSAGE['USERS_USERNAME_TAKEN']);
83
            }
84
        }
85 1475 Luisehahne
86 1815 Luisehahne
    	if(strlen($password) < $iMinPassLength ) {
87
    		msgQueue::add($MESSAGE['USERS_PASSWORD_TOO_SHORT']);
88
    	}
89 1475 Luisehahne
90 1815 Luisehahne
		$pattern = '/[^'.$admin->password_chars.']/';
91
		if (preg_match($pattern, $password)) {
92
			msgQueue::add($MESSAGE['PREFERENCES_INVALID_CHARS']);
93
    	}
94 1475 Luisehahne
95 1815 Luisehahne
    	if(($password != $password2) ) {
96
    		msgQueue::add($MESSAGE['USERS_PASSWORD_MISMATCH']);
97
    	}
98
99
//
100
// check that display_name is unique in whoole system (prevents from User-faking)
101
    	$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` ';
102
    	$sql .= 'WHERE `user_id` <> '.(int)$admin->get_user_id().' AND `display_name` LIKE "'.$display_name.'"';
103
    	if( ($iFoundUser = intval($database->get_one($sql))) > 0 ){
104
    	   msgQueue::add($MESSAGE['USERS_USERNAME_TAKEN'].' ('.$TEXT['DISPLAY_NAME'].')');
105
        } else {
106
            if($display_name == '') {
107
        	   msgQueue::add($MESSAGE['GENERIC_FILL_IN_ALL'].' ('.$TEXT['DISPLAY_NAME'].')');
108
            }
109
       }
110
111
        if(findStringInFileList($display_name, dirname(__FILE__).'/disallowedNames')) {
112
            msgQueue::add( $TEXT['ERROR'].' '.$TEXT['DISPLAY_NAME'].' ('.$display_name.')' );
113
        }
114
115
        if($email != "")
116
        {
117
        	if($admin->validate_email($email) == false)
118
            {
119
                msgQueue::add($MESSAGE['USERS_INVALID_EMAIL'].' ('.$email.')');
120
        	}
121
        } else { // e-mail must be present
122
        	msgQueue::add($MESSAGE['SIGNUP_NO_EMAIL']);
123
        }
124
125
		$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
126
                'WHERE `email` LIKE \''.$email.'\' ';
127
128
        // Check if the email already exists
129
        if( ($iFoundUser = $database->get_one($sql)) != null ) {
130
            if($iFoundUser) {
131
            	if(isset($MESSAGE['USERS_EMAIL_TAKEN']))
132
                {
133
            		msgQueue::add($MESSAGE['USERS_EMAIL_TAKEN'].' ('.$email.')');
134
            	} else {
135
            		msgQueue::add($MESSAGE['USERS_INVALID_EMAIL'].' ('.$email.')');
136
            	}
137
            }
138
        }
139
140
		if( ($msg = msgQueue::getError()) == '')
141
		{
142
            //if user is in administrator-group, get this group else just get the first one
143
            if($admin->is_group_match($groups_id,'1')) { $group_id = 1; $groups_id = '1'; }
144 1818 Luisehahne
145
            // Include the WB functions file
146
            if(!function_exists('media_filename')) { require(WB_PATH.'/framework/functions.php'); }
147
148
            // Remove bad characters
149
            $sHomeFolder = WB_PATH.MEDIA_DIRECTORY.'/home/'.( media_filename($username) );
150
            if ( sizeof(createFolderProtectFile( $sHomeFolder )) )
151
            {
152
            	msgQueue::add($MESSAGE['MEDIA_DIR_NOT_MADE'].' ('.basename($sHomeFolder).') ' );
153
            }
154 1815 Luisehahne
            // Inser the user into the database
155
			$sql  = 'INSERT INTO `'.TABLE_PREFIX.'users` SET '.
156
                    '`group_id`     = '.intval($group_id).', '.
157
                    '`groups_id`    = \''.mysql_real_escape_string($groups_id).'\', '.
158
                    '`active`       = '.intval($active).', '.
159
                    '`username`     = \''.mysql_real_escape_string($username).'\', '.
160
                    '`password`     = \''.md5($password).'\', '.
161
                    '`confirm_code` = \''.mysql_real_escape_string($confirm_code).'\', '.
162
                    '`confirm_timeout` = '.intval($confirm_timeout).', '.
163
                    '`remember_key` = \''.mysql_real_escape_string($remember_key).'\', '.
164
                    '`last_reset`   = '.intval($last_reset).', '.
165
                    '`display_name` = \''.mysql_real_escape_string($display_name).'\', '.
166
                    '`email`        = \''.mysql_real_escape_string($email).'\', '.
167
                    '`timezone`     = '.intval($timezone).', '.
168
                    '`date_format`  = \''.mysql_real_escape_string($date_format).'\', '.
169
                    '`time_format`  = \''.mysql_real_escape_string($time_format).'\', '.
170
                    '`language`     = \''.mysql_real_escape_string($language).'\', '.
171
                    '`home_folder`  = \''.mysql_real_escape_string($home_folder).'\', '.
172
                    '`login_when`   = '.intval($login_when).', '.
173
                    '`login_ip`     = \''.mysql_real_escape_string($login_ip).'\' '.
174
                    '';
175
            if($database->query($sql)) {
176
            	msgQueue::add($MESSAGE['USERS_ADDED'], true);
177
            }
178
            if($database->is_error()) {
179
                msgQueue::add( implode('<br />',explode(';',$database->get_error())) );
180
            }
181
        } else {
182
        	msgQueue::add($HEADING['ADD_USER'].' '.$MESSAGE['GENERIC_NOT_COMPARE']);
183
184
       }
185
    }
186
//