| 
      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: users.php 1529 2011-11-25 05:03:32Z Luisehahne $
 
     | 
  
  
    | 
      13
     | 
    
       * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/users.php $
 
     | 
  
  
    | 
      14
     | 
    
       * @lastmodified    $Date: 2011-11-25 06:03:32 +0100 (Fri, 25 Nov 2011) $
 
     | 
  
  
    | 
      15
     | 
    
       *
 
     | 
  
  
    | 
      16
     | 
    
      */
 
     | 
  
  
    | 
      17
     | 
    
      
 
     | 
  
  
    | 
      18
     | 
    
       // Include config file and admin class file
 
     | 
  
  
    | 
      19
     | 
    
      require('../../config.php');
     | 
  
  
    | 
      20
     | 
    
      require_once(WB_PATH.'/framework/class.admin.php');
 
     | 
  
  
    | 
      21
     | 
    
      
 
     | 
  
  
    | 
      22
     | 
    
      $action = 'cancel';
 
     | 
  
  
    | 
      23
     | 
    
      // Set parameter 'action' as alternative to javascript mechanism
 
     | 
  
  
    | 
      24
     | 
    
      $action = (isset($_POST['modify']) ? 'modify' : $action );
 
     | 
  
  
    | 
      25
     | 
    
      $action = (isset($_POST['delete']) ? 'delete' : $action );
 
     | 
  
  
    | 
      26
     | 
    
      
 
     | 
  
  
    | 
      27
     | 
    
      switch ($action):
 
     | 
  
  
    | 
      28
     | 
    
      	case 'modify' :
 
     | 
  
  
    | 
      29
     | 
    
      			// Print header
 
     | 
  
  
    | 
      30
     | 
    
      			$admin = new admin('Access', 'users_modify');
     | 
  
  
    | 
      31
     | 
    
      			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
     | 
  
  
    | 
      32
     | 
    
      			// Check if user id is a valid number and doesnt equal 1
 
     | 
  
  
    | 
      33
     | 
    
      			if($user_id == 0){
     | 
  
  
    | 
      34
     | 
    
      			$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
 
     | 
  
  
    | 
      35
     | 
    
                  }
 
     | 
  
  
    | 
      36
     | 
    
      			if( ($user_id < 2 ) )
 
     | 
  
  
    | 
      37
     | 
    
      			{
     | 
  
  
    | 
      38
     | 
    
      				// if($admin_header) { $admin->print_header(); }
     | 
  
  
    | 
      39
     | 
    
      				$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
 
     | 
  
  
    | 
      40
     | 
    
      			}
 
     | 
  
  
    | 
      41
     | 
    
      			// Get existing values
 
     | 
  
  
    | 
      42
     | 
    
      			$results = $database->query("SELECT * FROM `".TABLE_PREFIX."users` WHERE `user_id` = '".$user_id."'");
     | 
  
  
    | 
      43
     | 
    
      			$user = $results->fetchRow();
 
     | 
  
  
    | 
      44
     | 
    
      
 
     | 
  
  
    | 
      45
     | 
    
      			// Setup template object, parse vars to it, then parse it
 
     | 
  
  
    | 
      46
     | 
    
      			$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('users_form.htt'));
     | 
  
  
    | 
      47
     | 
    
      			// Create new template object
 
     | 
  
  
    | 
      48
     | 
    
      			$template = new Template($ThemePath);
 
     | 
  
  
    | 
      49
     | 
    
      			// $template->debug = true;
 
     | 
  
  
    | 
      50
     | 
    
      			$template->set_file('page', 'users_form.htt');
     | 
  
  
    | 
      51
     | 
    
      			$template->set_block('page', 'main_block', 'main');
     | 
  
  
    | 
      52
     | 
    
      			$template->set_var(	array(
 
     | 
  
  
    | 
      53
     | 
    
      								'ACTION_URL' => ADMIN_URL.'/users/save.php',
 
     | 
  
  
    | 
      54
     | 
    
      								'SUBMIT_TITLE' => $TEXT['SAVE'],
 
     | 
  
  
    | 
      55
     | 
    
      								'USER_ID' => $user['user_id'],
 
     | 
  
  
    | 
      56
     | 
    
      								'USERNAME' => $user['username'],
 
     | 
  
  
    | 
      57
     | 
    
      								'DISPLAY_NAME' => $user['display_name'],
 
     | 
  
  
    | 
      58
     | 
    
      								'EMAIL' => $user['email'],
 
     | 
  
  
    | 
      59
     | 
    
      								'ADMIN_URL' => ADMIN_URL,
 
     | 
  
  
    | 
      60
     | 
    
      								'WB_URL' => WB_URL,
 
     | 
  
  
    | 
      61
     | 
    
      								'THEME_URL' => THEME_URL
 
     | 
  
  
    | 
      62
     | 
    
      								)
 
     | 
  
  
    | 
      63
     | 
    
      						);
 
     | 
  
  
    | 
      64
     | 
    
      
 
     | 
  
  
    | 
      65
     | 
    
      			$template->set_var('FTAN', $admin->getFTAN());
     | 
  
  
    | 
      66
     | 
    
      			if($user['active'] == 1) {
     | 
  
  
    | 
      67
     | 
    
      				$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
     | 
  
  
    | 
      68
     | 
    
      			} else {
     | 
  
  
    | 
      69
     | 
    
      				$template->set_var('DISABLED_CHECKED', ' checked="checked"');
     | 
  
  
    | 
      70
     | 
    
      			}
 
     | 
  
  
    | 
      71
     | 
    
      			// Add groups to list
 
     | 
  
  
    | 
      72
     | 
    
      			$template->set_block('main_block', 'group_list_block', 'group_list');
     | 
  
  
    | 
      73
     | 
    
      			$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
     | 
  
  
    | 
      74
     | 
    
      			if($results->numRows() > 0) {
     | 
  
  
    | 
      75
     | 
    
      				$template->set_var('ID', '');
     | 
  
  
    | 
      76
     | 
    
      				$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
     | 
  
  
    | 
      77
     | 
    
      				$template->set_var('SELECTED', '');
     | 
  
  
    | 
      78
     | 
    
      				$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      79
     | 
    
      				while($group = $results->fetchRow()) {
     | 
  
  
    | 
      80
     | 
    
      					$template->set_var('ID', $group['group_id']);
     | 
  
  
    | 
      81
     | 
    
      					$template->set_var('NAME', $group['name']);
     | 
  
  
    | 
      82
     | 
    
      					if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
     | 
  
  
    | 
      83
     | 
    
      						$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      84
     | 
    
      					} else {
     | 
  
  
    | 
      85
     | 
    
      						$template->set_var('SELECTED', '');
     | 
  
  
    | 
      86
     | 
    
      					}
 
     | 
  
  
    | 
      87
     | 
    
      					$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      88
     | 
    
      				}
 
     | 
  
  
    | 
      89
     | 
    
      			}
 
     | 
  
  
    | 
      90
     | 
    
      
 
     | 
  
  
    | 
      91
     | 
    
      			// Only allow the user to add a user to the Administrators group if they belong to it
 
     | 
  
  
    | 
      92
     | 
    
      			if(in_array(1, $admin->get_groups_id()))
 
     | 
  
  
    | 
      93
     | 
    
      		    {
     | 
  
  
    | 
      94
     | 
    
      				$template->set_var('ID', '1');
     | 
  
  
    | 
      95
     | 
    
      				$users_groups = $admin->get_groups_name();
 
     | 
  
  
    | 
      96
     | 
    
      				$template->set_var('NAME', $users_groups[1]);
     | 
  
  
    | 
      97
     | 
    
      
 
     | 
  
  
    | 
      98
     | 
    
      				$in_group = FALSE;
 
     | 
  
  
    | 
      99
     | 
    
      				foreach($admin->get_groups_id() as $cur_gid){
     | 
  
  
    | 
      100
     | 
    
      				    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
     | 
  
  
    | 
      101
     | 
    
      				        $in_group = TRUE;
 
     | 
  
  
    | 
      102
     | 
    
      				    }
 
     | 
  
  
    | 
      103
     | 
    
      				}
 
     | 
  
  
    | 
      104
     | 
    
      
 
     | 
  
  
    | 
      105
     | 
    
      				if($in_group) {
     | 
  
  
    | 
      106
     | 
    
      					$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      107
     | 
    
      				} else {
     | 
  
  
    | 
      108
     | 
    
      					$template->set_var('SELECTED', '');
     | 
  
  
    | 
      109
     | 
    
      				}
 
     | 
  
  
    | 
      110
     | 
    
      				$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      111
     | 
    
      			} else {
     | 
  
  
    | 
      112
     | 
    
      				if($results->numRows() == 0) {
     | 
  
  
    | 
      113
     | 
    
      					$template->set_var('ID', '');
     | 
  
  
    | 
      114
     | 
    
      					$template->set_var('NAME', $TEXT['NONE_FOUND']);
     | 
  
  
    | 
      115
     | 
    
      					$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      116
     | 
    
      					$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      117
     | 
    
      				}
 
     | 
  
  
    | 
      118
     | 
    
      			}
 
     | 
  
  
    | 
      119
     | 
    
      
 
     | 
  
  
    | 
      120
     | 
    
      			// Generate username field name
 
     | 
  
  
    | 
      121
     | 
    
      			$username_fieldname = 'username_';
 
     | 
  
  
    | 
      122
     | 
    
      			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
 
     | 
  
  
    | 
      123
     | 
    
      			srand((double)microtime()*1000000);
 
     | 
  
  
    | 
      124
     | 
    
      			$i = 0;
 
     | 
  
  
    | 
      125
     | 
    
      			while ($i <= 7) {
     | 
  
  
    | 
      126
     | 
    
      				$num = rand() % 33;
 
     | 
  
  
    | 
      127
     | 
    
      				$tmp = substr($salt, $num, 1);
 
     | 
  
  
    | 
      128
     | 
    
      				$username_fieldname = $username_fieldname . $tmp;
 
     | 
  
  
    | 
      129
     | 
    
      				$i++;
 
     | 
  
  
    | 
      130
     | 
    
      			}
 
     | 
  
  
    | 
      131
     | 
    
      
 
     | 
  
  
    | 
      132
     | 
    
      			// Work-out if home folder should be shown
 
     | 
  
  
    | 
      133
     | 
    
      			if(!HOME_FOLDERS) {
     | 
  
  
    | 
      134
     | 
    
      				$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
     | 
  
  
    | 
      135
     | 
    
      			}
 
     | 
  
  
    | 
      136
     | 
    
      
 
     | 
  
  
    | 
      137
     | 
    
      			// Include the WB functions file
 
     | 
  
  
    | 
      138
     | 
    
      			require_once(WB_PATH.'/framework/functions.php');
 
     | 
  
  
    | 
      139
     | 
    
      
 
     | 
  
  
    | 
      140
     | 
    
      			// Add media folders to home folder list
 
     | 
  
  
    | 
      141
     | 
    
      			$template->set_block('main_block', 'folder_list_block', 'folder_list');
     | 
  
  
    | 
      142
     | 
    
      			foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
 
     | 
  
  
    | 
      143
     | 
    
      		    {
     | 
  
  
    | 
      144
     | 
    
      				$template->set_var('NAME', str_replace(WB_PATH, '', $name));
     | 
  
  
    | 
      145
     | 
    
      				$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
     | 
  
  
    | 
      146
     | 
    
      				if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
     | 
  
  
    | 
      147
     | 
    
      					$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      148
     | 
    
      				} else {
     | 
  
  
    | 
      149
     | 
    
      					$template->set_var('SELECTED', ' ');
     | 
  
  
    | 
      150
     | 
    
      				}
 
     | 
  
  
    | 
      151
     | 
    
      				$template->parse('folder_list', 'folder_list_block', true);
     | 
  
  
    | 
      152
     | 
    
      			}
 
     | 
  
  
    | 
      153
     | 
    
      
 
     | 
  
  
    | 
      154
     | 
    
      			// Insert language text and messages
 
     | 
  
  
    | 
      155
     | 
    
      			$template->set_var(array(
 
     | 
  
  
    | 
      156
     | 
    
      								'TEXT_RESET' => $TEXT['RESET'],
 
     | 
  
  
    | 
      157
     | 
    
      								'TEXT_CANCEL' => $TEXT['CANCEL'],
 
     | 
  
  
    | 
      158
     | 
    
      								'TEXT_ACTIVE' => $TEXT['ACTIVE'],
 
     | 
  
  
    | 
      159
     | 
    
      								'TEXT_DISABLED' => $TEXT['DISABLED'],
 
     | 
  
  
    | 
      160
     | 
    
      								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
 
     | 
  
  
    | 
      161
     | 
    
      								'TEXT_USERNAME' => $TEXT['USERNAME'],
 
     | 
  
  
    | 
      162
     | 
    
      								'TEXT_PASSWORD' => $TEXT['PASSWORD'],
 
     | 
  
  
    | 
      163
     | 
    
      								'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
 
     | 
  
  
    | 
      164
     | 
    
      								'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
 
     | 
  
  
    | 
      165
     | 
    
      								'TEXT_EMAIL' => $TEXT['EMAIL'],
 
     | 
  
  
    | 
      166
     | 
    
      								'TEXT_GROUP' => $TEXT['GROUP'],
 
     | 
  
  
    | 
      167
     | 
    
      								'TEXT_NONE' => $TEXT['NONE'],
 
     | 
  
  
    | 
      168
     | 
    
      								'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
 
     | 
  
  
    | 
      169
     | 
    
      								'USERNAME_FIELDNAME' => $username_fieldname,
 
     | 
  
  
    | 
      170
     | 
    
      								'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
 
     | 
  
  
    | 
      171
     | 
    
      								'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
 
     | 
  
  
    | 
      172
     | 
    
      								)
 
     | 
  
  
    | 
      173
     | 
    
      						);
 
     | 
  
  
    | 
      174
     | 
    
      
 
     | 
  
  
    | 
      175
     | 
    
      			// Parse template object
 
     | 
  
  
    | 
      176
     | 
    
      			$template->parse('main', 'main_block', false);
     | 
  
  
    | 
      177
     | 
    
      			$template->pparse('output', 'page');
     | 
  
  
    | 
      178
     | 
    
      			// Print admin footer
 
     | 
  
  
    | 
      179
     | 
    
      			$admin->print_footer();
 
     | 
  
  
    | 
      180
     | 
    
      			break;
 
     | 
  
  
    | 
      181
     | 
    
      		case 'delete' :
 
     | 
  
  
    | 
      182
     | 
    
      			// Print header
 
     | 
  
  
    | 
      183
     | 
    
      			$admin = new admin('Access', 'users_delete');
     | 
  
  
    | 
      184
     | 
    
      			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
     | 
  
  
    | 
      185
     | 
    
      			// Check if user id is a valid number and doesnt equal 1
 
     | 
  
  
    | 
      186
     | 
    
      			if($user_id == 0){
     | 
  
  
    | 
      187
     | 
    
      			$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
 
     | 
  
  
    | 
      188
     | 
    
                  }
 
     | 
  
  
    | 
      189
     | 
    
      			if( ($user_id < 2 ) )
 
     | 
  
  
    | 
      190
     | 
    
      			{
     | 
  
  
    | 
      191
     | 
    
      				// if($admin_header) { $admin->print_header(); }
     | 
  
  
    | 
      192
     | 
    
      				$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
 
     | 
  
  
    | 
      193
     | 
    
      			}
 
     | 
  
  
    | 
      194
     | 
    
      			$sql  = 'SELECT `active` FROM `'.TABLE_PREFIX.'users` ';
 
     | 
  
  
    | 
      195
     | 
    
                  $sql .= 'WHERE `user_id` = '.$user_id.'';
 
     | 
  
  
    | 
      196
     | 
    
                  if( ($iDeleteUser = $database->get_one($sql)) == 1 ) {
     | 
  
  
    | 
      197
     | 
    
      				// Delete the user
 
     | 
  
  
    | 
      198
     | 
    
      				$database->query("UPDATE `".TABLE_PREFIX."users` SET `active` = 0 WHERE `user_id` = '".$user_id."' ");
     | 
  
  
    | 
      199
     | 
    
                  } else {
     | 
  
  
    | 
      200
     | 
    
      				$database->query("DELETE FROM `".TABLE_PREFIX."users` WHERE `user_id` = ".$user_id);
     | 
  
  
    | 
      201
     | 
    
                  }
 
     | 
  
  
    | 
      202
     | 
    
      
 
     | 
  
  
    | 
      203
     | 
    
      			if($database->is_error()) {
     | 
  
  
    | 
      204
     | 
    
      				$admin->print_error($database->get_error());
 
     | 
  
  
    | 
      205
     | 
    
      			} else {
     | 
  
  
    | 
      206
     | 
    
      				$admin->print_success($MESSAGE['USERS_DELETED']);
 
     | 
  
  
    | 
      207
     | 
    
      			}
 
     | 
  
  
    | 
      208
     | 
    
      			// Print admin footer
 
     | 
  
  
    | 
      209
     | 
    
      			$admin->print_footer();
 
     | 
  
  
    | 
      210
     | 
    
      			break;
 
     | 
  
  
    | 
      211
     | 
    
      	default:
 
     | 
  
  
    | 
      212
     | 
    
      			break;
 
     | 
  
  
    | 
      213
     | 
    
      endswitch;
 
     |