| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      
 
     | 
  
  
    | 
      3
     | 
    
      // $Id: users.php 1213 2009-12-12 15:23:53Z MaGnaL $
 
     | 
  
  
    | 
      4
     | 
    
      
 
     | 
  
  
    | 
      5
     | 
    
      /*
 
     | 
  
  
    | 
      6
     | 
    
      
 
     | 
  
  
    | 
      7
     | 
    
       Website Baker Project <http://www.websitebaker.org/>
 
     | 
  
  
    | 
      8
     | 
    
       Copyright (C) 2004-2009, Ryan Djurovich
 
     | 
  
  
    | 
      9
     | 
    
      
 
     | 
  
  
    | 
      10
     | 
    
       Website Baker is free software; you can redistribute it and/or modify
 
     | 
  
  
    | 
      11
     | 
    
       it under the terms of the GNU General Public License as published by
 
     | 
  
  
    | 
      12
     | 
    
       the Free Software Foundation; either version 2 of the License, or
 
     | 
  
  
    | 
      13
     | 
    
       (at your option) any later version.
 
     | 
  
  
    | 
      14
     | 
    
      
 
     | 
  
  
    | 
      15
     | 
    
       Website Baker is distributed in the hope that it will be useful,
 
     | 
  
  
    | 
      16
     | 
    
       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
     | 
  
  
    | 
      17
     | 
    
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
     | 
  
  
    | 
      18
     | 
    
       GNU General Public License for more details.
 
     | 
  
  
    | 
      19
     | 
    
      
 
     | 
  
  
    | 
      20
     | 
    
       You should have received a copy of the GNU General Public License
 
     | 
  
  
    | 
      21
     | 
    
       along with Website Baker; if not, write to the Free Software
 
     | 
  
  
    | 
      22
     | 
    
       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
     | 
  
  
    | 
      23
     | 
    
      
 
     | 
  
  
    | 
      24
     | 
    
      */
 
     | 
  
  
    | 
      25
     | 
    
      
 
     | 
  
  
    | 
      26
     | 
    
      // Include config file and admin class file
 
     | 
  
  
    | 
      27
     | 
    
      require('../../config.php');
     | 
  
  
    | 
      28
     | 
    
      require_once(WB_PATH.'/framework/class.admin.php');
 
     | 
  
  
    | 
      29
     | 
    
      
 
     | 
  
  
    | 
      30
     | 
    
      // Create new database object
 
     | 
  
  
    | 
      31
     | 
    
      $database = new database();
 
     | 
  
  
    | 
      32
     | 
    
      
 
     | 
  
  
    | 
      33
     | 
    
      if(!isset($_POST['action']) OR ($_POST['action'] != "modify" AND $_POST['action'] != "delete")) {
     | 
  
  
    | 
      34
     | 
    
      	header("Location: index.php");
     | 
  
  
    | 
      35
     | 
    
      	exit(0);
 
     | 
  
  
    | 
      36
     | 
    
      }
 
     | 
  
  
    | 
      37
     | 
    
      
 
     | 
  
  
    | 
      38
     | 
    
      // Set parameter 'action' as alternative to javascript mechanism
 
     | 
  
  
    | 
      39
     | 
    
      if(isset($_POST['modify']))
 
     | 
  
  
    | 
      40
     | 
    
      	$_POST['action'] = "modify";
 
     | 
  
  
    | 
      41
     | 
    
      if(isset($_POST['delete']))
 
     | 
  
  
    | 
      42
     | 
    
      	$_POST['action'] = "delete";
 
     | 
  
  
    | 
      43
     | 
    
      
 
     | 
  
  
    | 
      44
     | 
    
      // Check if user id is a valid number and doesnt equal 1
 
     | 
  
  
    | 
      45
     | 
    
      if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
     | 
  
  
    | 
      46
     | 
    
      	header("Location: index.php");
     | 
  
  
    | 
      47
     | 
    
      	exit(0);
 
     | 
  
  
    | 
      48
     | 
    
      }
 
     | 
  
  
    | 
      49
     | 
    
      
 
     | 
  
  
    | 
      50
     | 
    
      if($_POST['action'] == 'modify') {
     | 
  
  
    | 
      51
     | 
    
      	// Print header
 
     | 
  
  
    | 
      52
     | 
    
      	$admin = new admin('Access', 'users_modify');
     | 
  
  
    | 
      53
     | 
    
      	// Get existing values
 
     | 
  
  
    | 
      54
     | 
    
      	$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."'");
     | 
  
  
    | 
      55
     | 
    
      	$user = $results->fetchRow();
 
     | 
  
  
    | 
      56
     | 
    
      	
 
     | 
  
  
    | 
      57
     | 
    
      	// Setup template object
 
     | 
  
  
    | 
      58
     | 
    
      	$template = new Template(THEME_PATH.'/templates');
 
     | 
  
  
    | 
      59
     | 
    
      	$template->set_file('page', 'users_form.htt');
     | 
  
  
    | 
      60
     | 
    
      	$template->set_block('page', 'main_block', 'main');
     | 
  
  
    | 
      61
     | 
    
      	$template->set_var(	array(
 
     | 
  
  
    | 
      62
     | 
    
      										'ACTION_URL' => ADMIN_URL.'/users/save.php',
 
     | 
  
  
    | 
      63
     | 
    
      										'SUBMIT_TITLE' => $TEXT['SAVE'],
 
     | 
  
  
    | 
      64
     | 
    
      										'USER_ID' => $user['user_id'],
 
     | 
  
  
    | 
      65
     | 
    
      										'USERNAME' => $user['username'],
 
     | 
  
  
    | 
      66
     | 
    
      										'DISPLAY_NAME' => $user['display_name'],
 
     | 
  
  
    | 
      67
     | 
    
      										'EMAIL' => $user['email'],
 
     | 
  
  
    | 
      68
     | 
    
      										'ADMIN_URL' => ADMIN_URL,
 
     | 
  
  
    | 
      69
     | 
    
      										'WB_URL' => WB_URL,
 
     | 
  
  
    | 
      70
     | 
    
      										'WB_PATH' => WB_PATH,
 
     | 
  
  
    | 
      71
     | 
    
      										'THEME_URL' => THEME_URL
 
     | 
  
  
    | 
      72
     | 
    
      										)
 
     | 
  
  
    | 
      73
     | 
    
      								);
 
     | 
  
  
    | 
      74
     | 
    
      	if($user['active'] == 1) {
     | 
  
  
    | 
      75
     | 
    
      		$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
     | 
  
  
    | 
      76
     | 
    
      	} else {
     | 
  
  
    | 
      77
     | 
    
      		$template->set_var('DISABLED_CHECKED', ' checked="checked"');
     | 
  
  
    | 
      78
     | 
    
      	}
 
     | 
  
  
    | 
      79
     | 
    
      	// Add groups to list
 
     | 
  
  
    | 
      80
     | 
    
      	$template->set_block('main_block', 'group_list_block', 'group_list');
     | 
  
  
    | 
      81
     | 
    
      	$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
     | 
  
  
    | 
      82
     | 
    
      	if($results->numRows() > 0) {
     | 
  
  
    | 
      83
     | 
    
      		$template->set_var('ID', '');
     | 
  
  
    | 
      84
     | 
    
      		$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
     | 
  
  
    | 
      85
     | 
    
      		$template->set_var('SELECTED', '');
     | 
  
  
    | 
      86
     | 
    
      		$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      87
     | 
    
      		while($group = $results->fetchRow()) {
     | 
  
  
    | 
      88
     | 
    
      			$template->set_var('ID', $group['group_id']);
     | 
  
  
    | 
      89
     | 
    
      			$template->set_var('NAME', $group['name']);
     | 
  
  
    | 
      90
     | 
    
      			if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
     | 
  
  
    | 
      91
     | 
    
      				$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      92
     | 
    
      			} else {
     | 
  
  
    | 
      93
     | 
    
      				$template->set_var('SELECTED', '');
     | 
  
  
    | 
      94
     | 
    
      			}
 
     | 
  
  
    | 
      95
     | 
    
      			$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      96
     | 
    
      		}
 
     | 
  
  
    | 
      97
     | 
    
      	}
 
     | 
  
  
    | 
      98
     | 
    
      	// Only allow the user to add a user to the Administrators group if they belong to it
 
     | 
  
  
    | 
      99
     | 
    
      	if(in_array(1, $admin->get_groups_id())) {
     | 
  
  
    | 
      100
     | 
    
      		$template->set_var('ID', '1');
     | 
  
  
    | 
      101
     | 
    
      		$users_groups = $admin->get_groups_name();
 
     | 
  
  
    | 
      102
     | 
    
      		$template->set_var('NAME', $users_groups[1]);
     | 
  
  
    | 
      103
     | 
    
      		
 
     | 
  
  
    | 
      104
     | 
    
      		$in_group = FALSE;
 
     | 
  
  
    | 
      105
     | 
    
      		foreach($admin->get_groups_id() as $cur_gid){
     | 
  
  
    | 
      106
     | 
    
      		    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
     | 
  
  
    | 
      107
     | 
    
      		        $in_group = TRUE;
 
     | 
  
  
    | 
      108
     | 
    
      		    }
 
     | 
  
  
    | 
      109
     | 
    
      		}
 
     | 
  
  
    | 
      110
     | 
    
      
 
     | 
  
  
    | 
      111
     | 
    
      		if($in_group) {
     | 
  
  
    | 
      112
     | 
    
      			$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      113
     | 
    
      		} else {
     | 
  
  
    | 
      114
     | 
    
      			$template->set_var('SELECTED', '');
     | 
  
  
    | 
      115
     | 
    
      		}
 
     | 
  
  
    | 
      116
     | 
    
      		$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      117
     | 
    
      	} else {
     | 
  
  
    | 
      118
     | 
    
      		if($results->numRows() == 0) {
     | 
  
  
    | 
      119
     | 
    
      			$template->set_var('ID', '');
     | 
  
  
    | 
      120
     | 
    
      			$template->set_var('NAME', $TEXT['NONE_FOUND']);
     | 
  
  
    | 
      121
     | 
    
      			$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      122
     | 
    
      			$template->parse('group_list', 'group_list_block', true);
     | 
  
  
    | 
      123
     | 
    
      		}
 
     | 
  
  
    | 
      124
     | 
    
      	}
 
     | 
  
  
    | 
      125
     | 
    
      	
 
     | 
  
  
    | 
      126
     | 
    
      	// Generate username field name
 
     | 
  
  
    | 
      127
     | 
    
      	$username_fieldname = 'username_';
 
     | 
  
  
    | 
      128
     | 
    
      	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
 
     | 
  
  
    | 
      129
     | 
    
      	srand((double)microtime()*1000000);
 
     | 
  
  
    | 
      130
     | 
    
      	$i = 0;
 
     | 
  
  
    | 
      131
     | 
    
      	while ($i <= 7) {
     | 
  
  
    | 
      132
     | 
    
      		$num = rand() % 33;
 
     | 
  
  
    | 
      133
     | 
    
      		$tmp = substr($salt, $num, 1);
 
     | 
  
  
    | 
      134
     | 
    
      		$username_fieldname = $username_fieldname . $tmp;
 
     | 
  
  
    | 
      135
     | 
    
      		$i++;
 
     | 
  
  
    | 
      136
     | 
    
      	}
 
     | 
  
  
    | 
      137
     | 
    
      	
 
     | 
  
  
    | 
      138
     | 
    
      	// Work-out if home folder should be shown
 
     | 
  
  
    | 
      139
     | 
    
      	if(!HOME_FOLDERS) {
     | 
  
  
    | 
      140
     | 
    
      		$template->set_var('DISPLAY_HOME_FOLDERS', 'none');
     | 
  
  
    | 
      141
     | 
    
      	}
 
     | 
  
  
    | 
      142
     | 
    
      	
 
     | 
  
  
    | 
      143
     | 
    
      	// Include the WB functions file
 
     | 
  
  
    | 
      144
     | 
    
      	require_once(WB_PATH.'/framework/functions.php');
 
     | 
  
  
    | 
      145
     | 
    
      	
 
     | 
  
  
    | 
      146
     | 
    
      	// Add media folders to home folder list
 
     | 
  
  
    | 
      147
     | 
    
      	$template->set_block('main_block', 'folder_list_block', 'folder_list');
     | 
  
  
    | 
      148
     | 
    
      	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
     | 
  
  
    | 
      149
     | 
    
      		$template->set_var('NAME', str_replace(WB_PATH, '', $name));
     | 
  
  
    | 
      150
     | 
    
      		$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
     | 
  
  
    | 
      151
     | 
    
      		if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
     | 
  
  
    | 
      152
     | 
    
      			$template->set_var('SELECTED', ' selected="selected"');
     | 
  
  
    | 
      153
     | 
    
      		} else {
     | 
  
  
    | 
      154
     | 
    
      			$template->set_var('SELECTED', ' ');
     | 
  
  
    | 
      155
     | 
    
      		}
 
     | 
  
  
    | 
      156
     | 
    
      		$template->parse('folder_list', 'folder_list_block', true);
     | 
  
  
    | 
      157
     | 
    
      	}
 
     | 
  
  
    | 
      158
     | 
    
      	
 
     | 
  
  
    | 
      159
     | 
    
      	// Insert language text and messages
 
     | 
  
  
    | 
      160
     | 
    
      	$template->set_var(array(
 
     | 
  
  
    | 
      161
     | 
    
      									'TEXT_RESET' => $TEXT['RESET'],
 
     | 
  
  
    | 
      162
     | 
    
      									'TEXT_ACTIVE' => $TEXT['ACTIVE'],
 
     | 
  
  
    | 
      163
     | 
    
      									'TEXT_DISABLED' => $TEXT['DISABLED'],
 
     | 
  
  
    | 
      164
     | 
    
      									'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
 
     | 
  
  
    | 
      165
     | 
    
      									'TEXT_USERNAME' => $TEXT['USERNAME'],
 
     | 
  
  
    | 
      166
     | 
    
      									'TEXT_PASSWORD' => $TEXT['PASSWORD'],
 
     | 
  
  
    | 
      167
     | 
    
      									'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
 
     | 
  
  
    | 
      168
     | 
    
      									'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
 
     | 
  
  
    | 
      169
     | 
    
      									'TEXT_EMAIL' => $TEXT['EMAIL'],
 
     | 
  
  
    | 
      170
     | 
    
      									'TEXT_GROUP' => $TEXT['GROUP'],
 
     | 
  
  
    | 
      171
     | 
    
      									'TEXT_NONE' => $TEXT['NONE'],
 
     | 
  
  
    | 
      172
     | 
    
      									'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
 
     | 
  
  
    | 
      173
     | 
    
      									'USERNAME_FIELDNAME' => $username_fieldname,
 
     | 
  
  
    | 
      174
     | 
    
      									'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
 
     | 
  
  
    | 
      175
     | 
    
      									'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
 
     | 
  
  
    | 
      176
     | 
    
      									)
 
     | 
  
  
    | 
      177
     | 
    
      							);
 
     | 
  
  
    | 
      178
     | 
    
      	
 
     | 
  
  
    | 
      179
     | 
    
      	// Parse template object
 
     | 
  
  
    | 
      180
     | 
    
      	$template->parse('main', 'main_block', false);
     | 
  
  
    | 
      181
     | 
    
      	$template->pparse('output', 'page');
     | 
  
  
    | 
      182
     | 
    
      } elseif($_POST['action'] == 'delete') {
     | 
  
  
    | 
      183
     | 
    
      	// Print header
 
     | 
  
  
    | 
      184
     | 
    
      	$admin = new admin('Access', 'users_delete');
     | 
  
  
    | 
      185
     | 
    
      	// Delete the user
 
     | 
  
  
    | 
      186
     | 
    
      	$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
     | 
  
  
    | 
      187
     | 
    
      	if($database->is_error()) {
     | 
  
  
    | 
      188
     | 
    
      		$admin->print_error($database->get_error());
 
     | 
  
  
    | 
      189
     | 
    
      	} else {
     | 
  
  
    | 
      190
     | 
    
      		$admin->print_success($MESSAGE['USERS']['DELETED']);
 
     | 
  
  
    | 
      191
     | 
    
      	}
 
     | 
  
  
    | 
      192
     | 
    
      }
 
     | 
  
  
    | 
      193
     | 
    
      
 
     | 
  
  
    | 
      194
     | 
    
      // Print admin footer
 
     | 
  
  
    | 
      195
     | 
    
      $admin->print_footer();
 
     | 
  
  
    | 
      196
     | 
    
      
 
     | 
  
  
    | 
      197
     | 
    
      ?>
 
     |