Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @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: add.php 1868 2013-02-19 21:07:19Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/add.php $
14
 * @lastmodified    $Date: 2013-02-19 22:07:19 +0100 (Tue, 19 Feb 2013) $
15
 *
16
 */
17

    
18
/* -------------------------------------------------------- */
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

    
26
	function add_user($admin, &$aActionRequest)
27
	{
28
		global $MESSAGE,$TEXT, $HEADING;
29
		$database = WbDatabase::getInstance();
30
        $bRetVal = false;
31
        $iMinPassLength = 6;
32

    
33
        if( !$admin->checkFTAN() )
34
        {
35
//        	$admin->print_header();
36
        	msgQueue::add($MESSAGE['GENERIC_SECURITY_ACCESS']);
37
            return $bRetVal;
38
        }
39

    
40
        // 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

    
52
        $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

    
63
        // 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

    
73
        if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
74
        	msgQueue::add( $MESSAGE['USERS_NAME_INVALID_CHARS']);
75
        }
76

    
77
		$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

    
86
    	if(strlen($password) < $iMinPassLength ) {
87
    		msgQueue::add($MESSAGE['USERS_PASSWORD_TOO_SHORT']);
88
    	}
89

    
90
		$pattern = '/[^'.$admin->password_chars.']/';
91
		if (preg_match($pattern, $password)) {
92
			msgQueue::add($MESSAGE['PREFERENCES_INVALID_CHARS']);
93
    	}
94

    
95
    	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

    
145
            if(defined('HOME_FOLDERS') && HOME_FOLDERS) {
146
                // Include the WB functions file
147
                if(!function_exists('media_filename')) { require(WB_PATH.'/framework/functions.php'); }
148

    
149
                // Remove bad characters
150
                $sHomeFolder = WB_PATH.MEDIA_DIRECTORY.'/home/'.( media_filename($username) );
151
                if ( sizeof(createFolderProtectFile( $sHomeFolder )) )
152
                {
153
                	msgQueue::add($MESSAGE['MEDIA_DIR_NOT_MADE'].' ('.basename($sHomeFolder).') ' );
154
                }
155
            }
156
            // Inser the user into the database
157
			$sql  = 'INSERT INTO `'.TABLE_PREFIX.'users` SET '.
158
                    '`group_id`     = '.intval($group_id).', '.
159
                    '`groups_id`    = \''.$database->escapeString($groups_id).'\', '.
160
                    '`active`       = '.intval($active).', '.
161
                    '`username`     = \''.$database->escapeString($username).'\', '.
162
                    '`password`     = \''.md5($password).'\', '.
163
                    '`confirm_code` = \''.$database->escapeString($confirm_code).'\', '.
164
                    '`confirm_timeout` = '.intval($confirm_timeout).', '.
165
                    '`remember_key` = \''.$database->escapeString($remember_key).'\', '.
166
                    '`last_reset`   = '.intval($last_reset).', '.
167
                    '`display_name` = \''.$database->escapeString($display_name).'\', '.
168
                    '`email`        = \''.$database->escapeString($email).'\', '.
169
                    '`timezone`     = '.intval($timezone).', '.
170
                    '`date_format`  = \''.$database->escapeString($date_format).'\', '.
171
                    '`time_format`  = \''.$database->escapeString($time_format).'\', '.
172
                    '`language`     = \''.$database->escapeString($language).'\', '.
173
                    '`home_folder`  = \''.$database->escapeString($home_folder).'\', '.
174
                    '`login_when`   = '.intval($login_when).', '.
175
                    '`login_ip`     = \''.$database->escapeString($login_ip).'\' '.
176
                    '';
177
            if($database->query($sql)) {
178
            	msgQueue::add($MESSAGE['USERS_ADDED'], true);
179
		        $bRetVal = true;
180
            }
181
            if($database->is_error()) {
182
                msgQueue::add( implode('<br />',explode(';',$database->get_error())) );
183
            }
184
        } else {
185
        	msgQueue::add($HEADING['ADD_USER'].' '.$MESSAGE['GENERIC_NOT_COMPARE']);
186

    
187
		}
188
		return $bRetVal;
189
   }
(1-1/7)