Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: save.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/admin/users/save.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 *
17
 */
18

    
19
// Print admin header
20
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
21
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
22
// suppress to print the header, so no new FTAN will be set
23
$admin = new admin('Access', 'users_modify', false);
24
$oTrans = Translate::getInstance();
25
$oTrans->enableAddon(ADMIN_DIRECTORY.'\\users');
26

    
27
// Create a javascript back link
28
$js_back = ADMIN_URL.'/users/index.php';
29

    
30
if( !$admin->checkFTAN() )
31
{
32
    $admin->print_header();
33
    $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION).'::');
34
    $sDEBUG=(@DEBUG?$sInfo:'');
35
    $admin->print_error($sDEBUG.$oTrans->MESSAGE_GENERIC_SECURITY_ACCESS, $js_back );
36
}
37

    
38
// After check print the header
39
$admin->print_header();
40
/*
41
$sLanguagesAddonDefaultFile = WB_PATH.'/account/languages/EN.php';
42
if (is_readable($sLanguagesAddonDefaultFile)){include $sLanguagesAddonDefaultFile;}
43
$sLanguagesAddonFile = WB_PATH.'/account/languages/'.LANGUAGE.'.php';
44
if (is_readable($sLanguagesAddonFile)){include $sLanguagesAddonFile;}
45
*/
46
$aInputs = array();
47
$aErrorMessage = array();
48
$aInputs = array_merge( $_POST );
49
// Check if user id is a valid number and doesnt equal 1
50
if(!isset($aInputs['user_id']) OR !is_numeric($aInputs['user_id']) OR $aInputs['user_id'] == 1) {
51
    header("Location: index.php");
52
    exit(0);
53
} else {
54
    $user_id = intval($aInputs['user_id']);
55
}
56
// Gather details entered
57
$groups_id = ( isset($aInputs['groups']) ? implode(",", $aInputs['groups']) : '');
58
$active = intval( is_array($aInputs['active'])  ?($aInputs['active'][0]):$aInputs['active']);
59

    
60
$password = $admin->get_post('password');
61
$password2 = $admin->get_post('password2');
62
$display_name = $admin->StripCodeFromText(($admin->get_post('display_name')));
63
$email = $admin->StripCodeFromText($admin->get_post('email'));
64
$home_folder = $admin->get_post('home_folder');
65
// Check values
66
if($groups_id == "") {
67
    $aErrorMessage[] = ($oTrans->MESSAGE_USERS_NO_GROUP);
68
}
69

    
70
if($password != "") {
71
    if(strlen($password) < 2) {
72
        $aErrorMessage[] = ($oTrans->MESSAGE_USERS_PASSWORD_TOO_SHORT);
73
    }
74
    if($password != $password2) {
75
        $aErrorMessage[] = ($oTrans->MESSAGE_USERS_PASSWORD_MISMATCH);
76
    }
77
}
78
    $md5_password =  md5($password);
79

    
80
if($email != "")
81
{
82
    if($admin->validate_email($email) == false)
83
    {
84
        $aErrorMessage[] = ($oTrans->MESSAGE_USERS_INVALID_EMAIL);
85
    }
86
} else { // e-mail must be present
87
    $aErrorMessage[] = ($oTrans->MESSAGE_SIGNUP_NO_EMAIL);
88
}
89

    
90
// Check if the email already exists
91
$sql  = 'SELECT `user_id` FROM `'.TABLE_PREFIX.'users` '
92
      . 'WHERE `email` = \''.$email.'\' '
93
      .   'AND `user_id` <> '.$user_id;
94
if($database->get_one($sql))
95
{
96
    if(isset($oTrans->MESSAGE_USERS_EMAIL_TAKEN))
97
    {
98
        $aErrorMessage[] = ($oTrans->MESSAGE_USERS_EMAIL_TAKEN);
99
    }
100
}
101
$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` ';
102
$sql .= 'WHERE `user_id` <> '.$user_id.' AND `display_name` LIKE \''.$display_name.'\'';
103
if ($numRow=$database->get_one($sql)) {
104
   $aErrorMessage[] = ( @$oTrans->MESSAGE_USERS_DISPLAYNAME_TAKEN?:$oTrans->MESSAGE_MEDIA_BLANK_NAME.' ('.$oTrans->TEXT_DISPLAY_NAME.')');
105
}
106

    
107
if (!sizeof($aErrorMessage)) {
108
// Update the database
109
$sql  = 'UPDATE `'.TABLE_PREFIX.'users` SET '
110
      . '`groups_id` = \''.$database->escapeString($groups_id).'\', '
111
      . '`active` = '.$database->escapeString($active).', '
112
      . '`display_name` = \''.$database->escapeString($display_name).'\', '
113
      . '`home_folder` = \''.$database->escapeString($home_folder).'\', '
114
      . '`email` = \''.$database->escapeString($email).'\''
115
      . ( ($password == "") ? ' ': ', `password` = \''.$database->escapeString($md5_password).'\' ' )
116
      . 'WHERE `user_id` = '.$database->escapeString($user_id);
117

    
118
    if (!$database->query($sql)) {
119
        if($database->is_error()) {
120
            $aErrorMessage[] = $database->get_error();
121
        }
122
    }
123
}
124
if (sizeof($aErrorMessage)) {
125
    $admin->print_error(implode('<br />', $aErrorMessage), $js_back);
126
} else {
127
    $admin->print_success($oTrans->MESSAGE_USERS_SAVED, $js_back);
128
}
129
// Print admin footer
130
$admin->print_footer();
(4-4/5)