| 1 | 
        
            1347
         | 
        
            Luisehahne
         | 
        <?php
  | 
      
      
        | 2 | 
        
         | 
        
         | 
        /**
  | 
      
      
        | 3 | 
        
         | 
        
         | 
         *
  | 
      
      
        | 4 | 
        
         | 
        
         | 
         * @category        admin
  | 
      
      
        | 5 | 
        
         | 
        
         | 
         * @package         users
  | 
      
      
        | 6 | 
        
            1710
         | 
        
            Luisehahne
         | 
         * @author          Ryan Djurovich, WebsiteBaker Project
  | 
      
      
        | 7 | 
        
         | 
        
         | 
         * @copyright       2009-2012, WebsiteBaker Org. e.V.
  | 
      
      
        | 8 | 
        
            1347
         | 
        
            Luisehahne
         | 
         * @link			http://www.websitebaker2.org/
  | 
      
      
        | 9 | 
        
         | 
        
         | 
         * @license         http://www.gnu.org/licenses/gpl.html
  | 
      
      
        | 10 | 
        
         | 
        
         | 
         * @platform        WebsiteBaker 2.8.x
  | 
      
      
        | 11 | 
        
            1374
         | 
        
            Luisehahne
         | 
         * @requirements    PHP 5.2.2 and higher
  | 
      
      
        | 12 | 
        
            1347
         | 
        
            Luisehahne
         | 
         * @version         $Id$
  | 
      
      
        | 13 | 
        
         | 
        
         | 
         * @filesource		$HeadURL$
  | 
      
      
        | 14 | 
        
         | 
        
         | 
         * @lastmodified    $Date$
  | 
      
      
        | 15 | 
        
         | 
        
         | 
         *
  | 
      
      
        | 16 | 
        
         | 
        
         | 
         */
  | 
      
      
        | 17 | 
        
         | 
        
         | 
        
  | 
      
      
        | 18 | 
        
         | 
        
         | 
        // Print admin header
  | 
      
      
        | 19 | 
        
         | 
        
         | 
        require('../../config.php');
 | 
      
      
        | 20 | 
        
         | 
        
         | 
        require_once(WB_PATH.'/framework/class.admin.php');
  | 
      
      
        | 21 | 
        
            1457
         | 
        
            Luisehahne
         | 
        // suppress to print the header, so no new FTAN will be set
  | 
      
      
        | 22 | 
        
         | 
        
         | 
        $admin = new admin('Access', 'users_modify', false);
 | 
      
      
        | 23 | 
        
            1347
         | 
        
            Luisehahne
         | 
        
  | 
      
      
        | 24 | 
        
            1425
         | 
        
            Luisehahne
         | 
        // Create a javascript back link
  | 
      
      
        | 25 | 
        
         | 
        
         | 
        $js_back = ADMIN_URL.'/users/index.php';
  | 
      
      
        | 26 | 
        
         | 
        
         | 
        
  | 
      
      
        | 27 | 
        
            1353
         | 
        
            FrankH
         | 
        if( !$admin->checkFTAN() )
  | 
      
      
        | 28 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 29 | 
        
            1457
         | 
        
            Luisehahne
         | 
        	$admin->print_header();
  | 
      
      
        | 30 | 
        
            1425
         | 
        
            Luisehahne
         | 
        	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back);
  | 
      
      
        | 31 | 
        
            1353
         | 
        
            FrankH
         | 
        }
  | 
      
      
        | 32 | 
        
            1457
         | 
        
            Luisehahne
         | 
        // After check print the header
  | 
      
      
        | 33 | 
        
         | 
        
         | 
        $admin->print_header();
  | 
      
      
        | 34 | 
        
            1347
         | 
        
            Luisehahne
         | 
        
  | 
      
      
        | 35 | 
        
         | 
        
         | 
        // Check if user id is a valid number and doesnt equal 1
  | 
      
      
        | 36 | 
        
         | 
        
         | 
        if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
 | 
      
      
        | 37 | 
        
         | 
        
         | 
        	header("Location: index.php");
 | 
      
      
        | 38 | 
        
         | 
        
         | 
        	exit(0);
  | 
      
      
        | 39 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 40 | 
        
            1710
         | 
        
            Luisehahne
         | 
        	$user_id = intval($_POST['user_id']);
  | 
      
      
        | 41 | 
        
            1347
         | 
        
            Luisehahne
         | 
        }
  | 
      
      
        | 42 | 
        
         | 
        
         | 
        
  | 
      
      
        | 43 | 
        
         | 
        
         | 
        // Gather details entered
  | 
      
      
        | 44 | 
        
         | 
        
         | 
        $groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : '';
 | 
      
      
        | 45 | 
        
         | 
        
         | 
        $active = $admin->add_slashes($_POST['active'][0]);
  | 
      
      
        | 46 | 
        
         | 
        
         | 
        $username_fieldname = $admin->get_post_escaped('username_fieldname');
 | 
      
      
        | 47 | 
        
         | 
        
         | 
        $username = strtolower($admin->get_post_escaped($username_fieldname));
  | 
      
      
        | 48 | 
        
         | 
        
         | 
        $password = $admin->get_post('password');
 | 
      
      
        | 49 | 
        
         | 
        
         | 
        $password2 = $admin->get_post('password2');
 | 
      
      
        | 50 | 
        
         | 
        
         | 
        $display_name = $admin->get_post_escaped('display_name');
 | 
      
      
        | 51 | 
        
         | 
        
         | 
        $email = $admin->get_post_escaped('email');
 | 
      
      
        | 52 | 
        
         | 
        
         | 
        $home_folder = $admin->get_post_escaped('home_folder');
 | 
      
      
        | 53 | 
        
         | 
        
         | 
        
  | 
      
      
        | 54 | 
        
         | 
        
         | 
        // Check values
  | 
      
      
        | 55 | 
        
         | 
        
         | 
        if($groups_id == "") {
 | 
      
      
        | 56 | 
        
            1710
         | 
        
            Luisehahne
         | 
        	$admin->print_error($MESSAGE['USERS_NO_GROUP'], $js_back);
  | 
      
      
        | 57 | 
        
            1347
         | 
        
            Luisehahne
         | 
        }
  | 
      
      
        | 58 | 
        
            1710
         | 
        
            Luisehahne
         | 
        if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username))
 | 
      
      
        | 59 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 60 | 
        
         | 
        
         | 
        
  | 
      
      
        | 61 | 
        
         | 
        
         | 
        //	print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
  | 
      
      
        | 62 | 
        
         | 
        
         | 
        //	print_r( $_POST ); print '</pre>';
  | 
      
      
        | 63 | 
        
            1446
         | 
        
            DarkViper
         | 
        	$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
  | 
      
      
        | 64 | 
        
         | 
        
         | 
        	                  $MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
  | 
      
      
        | 65 | 
        
            1347
         | 
        
            Luisehahne
         | 
        }
  | 
      
      
        | 66 | 
        
         | 
        
         | 
        if($password != "") {
 | 
      
      
        | 67 | 
        
         | 
        
         | 
        	if(strlen($password) < 2) {
 | 
      
      
        | 68 | 
        
            1710
         | 
        
            Luisehahne
         | 
        		$admin->print_error($MESSAGE['USERS_PASSWORD_TOO_SHORT'], $js_back);
  | 
      
      
        | 69 | 
        
            1347
         | 
        
            Luisehahne
         | 
        	}
  | 
      
      
        | 70 | 
        
         | 
        
         | 
        	if($password != $password2) {
 | 
      
      
        | 71 | 
        
            1710
         | 
        
            Luisehahne
         | 
        		$admin->print_error($MESSAGE['USERS_PASSWORD_MISMATCH'], $js_back);
  | 
      
      
        | 72 | 
        
            1347
         | 
        
            Luisehahne
         | 
        	}
  | 
      
      
        | 73 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 74 | 
        
         | 
        
         | 
        
  | 
      
      
        | 75 | 
        
         | 
        
         | 
        if($email != "")
  | 
      
      
        | 76 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 77 | 
        
         | 
        
         | 
        	if($admin->validate_email($email) == false)
  | 
      
      
        | 78 | 
        
         | 
        
         | 
            {
 | 
      
      
        | 79 | 
        
            1710
         | 
        
            Luisehahne
         | 
                $admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
  | 
      
      
        | 80 | 
        
            1347
         | 
        
            Luisehahne
         | 
        	}
  | 
      
      
        | 81 | 
        
         | 
        
         | 
        } else { // e-mail must be present
 | 
      
      
        | 82 | 
        
            1710
         | 
        
            Luisehahne
         | 
        	$admin->print_error($MESSAGE['SIGNUP_NO_EMAIL'], $js_back);
  | 
      
      
        | 83 | 
        
            1347
         | 
        
            Luisehahne
         | 
        }
  | 
      
      
        | 84 | 
        
         | 
        
         | 
        
  | 
      
      
        | 85 | 
        
         | 
        
         | 
        // Check if the email already exists
  | 
      
      
        | 86 | 
        
         | 
        
         | 
        $results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."' AND user_id <> '".$user_id."' ");
 | 
      
      
        | 87 | 
        
         | 
        
         | 
        if($results->numRows() > 0)
  | 
      
      
        | 88 | 
        
         | 
        
         | 
        {
 | 
      
      
        | 89 | 
        
            1710
         | 
        
            Luisehahne
         | 
        	if(isset($MESSAGE['USERS_EMAIL_TAKEN']))
  | 
      
      
        | 90 | 
        
            1347
         | 
        
            Luisehahne
         | 
            {
 | 
      
      
        | 91 | 
        
            1710
         | 
        
            Luisehahne
         | 
        		$admin->print_error($MESSAGE['USERS_EMAIL_TAKEN'], $js_back);
  | 
      
      
        | 92 | 
        
            1347
         | 
        
            Luisehahne
         | 
        	} else {
 | 
      
      
        | 93 | 
        
            1710
         | 
        
            Luisehahne
         | 
        		$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'], $js_back);
  | 
      
      
        | 94 | 
        
            1347
         | 
        
            Luisehahne
         | 
        	}
  | 
      
      
        | 95 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 96 | 
        
         | 
        
         | 
        
  | 
      
      
        | 97 | 
        
         | 
        
         | 
        // Prevent from renaming user to "admin"
  | 
      
      
        | 98 | 
        
         | 
        
         | 
        if($username != 'admin') {
 | 
      
      
        | 99 | 
        
         | 
        
         | 
        	$username_code = ", username = '$username'";
  | 
      
      
        | 100 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 101 | 
        
         | 
        
         | 
        	$username_code = '';
  | 
      
      
        | 102 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 103 | 
        
         | 
        
         | 
        
  | 
      
      
        | 104 | 
        
         | 
        
         | 
        // Update the database
  | 
      
      
        | 105 | 
        
         | 
        
         | 
        if($password == "") {
 | 
      
      
        | 106 | 
        
         | 
        
         | 
        	$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email' WHERE user_id = '$user_id'";
  | 
      
      
        | 107 | 
        
         | 
        
         | 
        } else {
 | 
      
      
        | 108 | 
        
         | 
        
         | 
        	// MD5 supplied password
  | 
      
      
        | 109 | 
        
         | 
        
         | 
        	$md5_password = md5($password);
  | 
      
      
        | 110 | 
        
         | 
        
         | 
        	$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email', password = '$md5_password' WHERE user_id = '$user_id'";
  | 
      
      
        | 111 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 112 | 
        
         | 
        
         | 
        $database->query($query);
  | 
      
      
        | 113 | 
        
         | 
        
         | 
        if($database->is_error()) {
 | 
      
      
        | 114 | 
        
            1425
         | 
        
            Luisehahne
         | 
        	$admin->print_error($database->get_error(),$js_back);
  | 
      
      
        | 115 | 
        
            1347
         | 
        
            Luisehahne
         | 
        } else {
 | 
      
      
        | 116 | 
        
            1710
         | 
        
            Luisehahne
         | 
        	$admin->print_success($MESSAGE['USERS_SAVED']);
  | 
      
      
        | 117 | 
        
            1347
         | 
        
            Luisehahne
         | 
        }
  | 
      
      
        | 118 | 
        
         | 
        
         | 
        
  | 
      
      
        | 119 | 
        
         | 
        
         | 
        // Print admin footer
  | 
      
      
        | 120 | 
        
         | 
        
         | 
        $admin->print_footer();
  |