Project

General

Profile

1 2 Manuela
<?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$
14
 * @filesource      $HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18
19
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
20
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
21
22
$admin = new admin('Access', 'users');
23
24
$iUserStatus = 1;
25
$iUserStatus = ( ( $admin->get_get('status')==1 ) ? 0 : $iUserStatus );
26
unset($_GET);
27
28
$oTrans = Translate::getInstance();
29
$oTrans->enableAddon(ADMIN_DIRECTORY.'\\users');
30
/**
31
32
 * print '<pre  class="mod-pre rounded">function <span>'.__FUNCTION__.'( '.''.' );</span>  filename: <span>'.basename(__FILE__).'</span>  line: '.__LINE__.' -> <br />';
33
 * print_r( $oTrans ); print '</pre>'; flush (); //  ob_flush();;sleep(10); die();
34
 */
35
// Setup template object, parse vars to it, then parse it
36
// Create new template object
37
$template = new Template(dirname($admin->correct_theme_source('users.htt')));
38
// $template->debug = true;
39
40
$template->set_file('page', 'users.htt');
41
$template->set_block('page', 'main_block', 'main');
42
$template->set_block("main_block", "manage_groups_block", "groups");
43
$template->set_var('ADMIN_URL', ADMIN_URL);
44
$template->set_var('FTAN', $admin->getFTAN());
45
$template->set_var('USER_STATUS', $iUserStatus );
46
47
$UserStatusActive = 'url('.THEME_URL.'/images/user.png)';
48
$UserStatusInactive = 'url('.THEME_URL.'/images/user_red.png)';
49
50
$sUserTitle = ($iUserStatus == 0) ? $oTrans->MENU_USERS.' '.strtolower($oTrans->TEXT_ACTIVE) : $oTrans->MENU_USERS.' '.strtolower($oTrans->TEXT_DEACTIVED) ;
51
52
$template->set_var('TEXT_USERS', $sUserTitle.' '.$oTrans->TEXT_SHOW );
53
$template->set_var('STATUS_ICON', ( ($iUserStatus==0) ? $UserStatusActive : $UserStatusInactive) );
54
55
// Get existing value from database
56
$sql  = 'SELECT `user_id`, `username`, `display_name`, `active` FROM `'.TABLE_PREFIX.'users` ' ;
57
$sql .= 'WHERE user_id != 1 ';
58
$sql .=   'AND active = '.$iUserStatus.' ';
59
$sql .= 'ORDER BY `display_name`,`username`';
60
61
$results = $database->query($sql);
62
if($database->is_error()) {
63
    $admin->print_error($database->get_error(), 'index.php');
64
}
65
66
$sUserList  = $oTrans->TEXT_LIST_OPTIONS.' ';
67
$sUserList .= ($iUserStatus == 1) ? $oTrans->MENU_USERS.' '.strtolower($oTrans->TEXT_ACTIVE) : $oTrans->MENU_USERS.' '.strtolower($oTrans->TEXT_DEACTIVED) ;
68
// Insert values into the modify/remove menu
69
$template->set_block('main_block', 'list_block', 'list');
70
if($results->numRows() > 0) {
71
    // Insert first value to say please select
72
    $template->set_var('VALUE', '');
73
    $template->set_var('NAME', $sUserList);
74
    $template->set_var('STATUS', 'class="user-active"' );
75
    $template->parse('list', 'list_block', true);
76
    // Loop through users
77
    while($user = $results->fetchRow()) {
78
        $template->set_var('VALUE',$admin->getIDKEY($user['user_id']));
79
        $template->set_var('STATUS', ($user['active']==false ? 'class="user-inactive"' : 'class="user-active"') );
80
        $template->set_var('NAME', $user['display_name'].' ('.$user['username'].')');
81
        $template->parse('list', 'list_block', true);
82
    }
83
} else {
84
    // Insert single value to say no users were found
85
    $template->set_var('NAME', $oTrans->TEXT_NONE_FOUND);
86
    $template->parse('list', 'list_block', true);
87
}
88
89
// Insert permissions values
90
if($admin->get_permission('users_add') != true) {
91
    $template->set_var('DISPLAY_ADD', 'hide');
92
}
93
if($admin->get_permission('users_modify') != true) {
94
    $template->set_var('DISPLAY_MODIFY', 'hide');
95
}
96
if($admin->get_permission('users_delete') != true) {
97
    $template->set_var('DISPLAY_DELETE', 'hide');
98
}
99
$HeaderTitle  = (($iUserStatus == 1) ? $oTrans->HEADING_MODIFY_ACTIVE_USER.' ' : $oTrans->HEADING_MODIFY_DELETE_USER.' ');
100
$HeaderTitle .= (($iUserStatus == 1) ? strtolower($oTrans->TEXT_ACTIVE) : strtolower($oTrans->TEXT_DEACTIVED));
101
// Insert language headings
102
$template->set_var(array(
103
        'HEADING_MODIFY_DELETE_USER' => $HeaderTitle,
104
        'HEADING_ADD_USER' => $oTrans->HEADING_ADD_USER
105
        )
106
);
107
// insert urls
108
$template->set_var(array(
109
        'ADMIN_URL' => ADMIN_URL,
110
        'WB_URL' => WB_URL,
111
        'THEME_URL' => THEME_URL
112
        )
113
);
114
// Insert language text and messages
115
$template->set_var(array(
116
        'TEXT_MODIFY' => $oTrans->TEXT_MODIFY,
117
        'TEXT_DELETE' => (($iUserStatus == 1) ? $oTrans->TEXT_DEACTIVE:$oTrans->TEXT_DELETE),
118
        'TEXT_MANAGE_GROUPS' => ( $admin->get_permission('groups') == true ) ? $oTrans->TEXT_MANAGE_GROUPS : "**",
119
        'CONFIRM_DELETE' => (($iUserStatus == 1) ? $oTrans->TEXT_ARE_YOU_SURE : $oTrans->MESSAGE_USERS_CONFIRM_DELETE)
120
        )
121
);
122
if ( $admin->get_permission('groups') == true ) $template->parse("groups", "manage_groups_block", true);
123
// Parse template object
124
$template->parse('main', 'main_block', false);
125
$template->pparse('output', 'page');
126
127
// Setup template object, parse vars to it, then parse it
128
// Create new template object
129
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')), 'remove');
130
// $template->debug = true;
131
$template->set_file('page', 'users_form.htt');
132
$template->set_block('page', 'main_block', 'main');
133
$template->set_block('main_block', 'user_display_block', 'user_display');
134
135
$template->set_var('DISPLAY_EXTRA', 'display:none;');
136
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
137
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
138
$template->set_var('SUBMIT_TITLE', $oTrans->TEXT_ADD);
139
$template->set_var('FTAN', $admin->getFTAN());
140
// {READONLY}
141
$template->set_var('READONLY', '' );
142
143
// insert urls
144
$template->set_var(array(
145
        'ADMIN_URL' => ADMIN_URL,
146
        'WB_URL' => WB_URL,
147
        'THEME_URL' => THEME_URL
148
        )
149
);
150
$template->set_var('USERNAME', '');
151
152
// Add groups to list
153
$template->set_block('main_block', 'group_list_block', 'group_list');
154
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
155
if($results->numRows() > 0) {
156
    $template->set_var('ID', '');
157
    $template->set_var('NAME', $oTrans->TEXT_PLEASE_SELECT.'...');
158
    $template->set_var('SELECTED', ' selected="selected"');
159
    $template->parse('group_list', 'group_list_block', true);
160
    while($group = $results->fetchRow()) {
161
        $template->set_var('ID', $group['group_id']);
162
        $template->set_var('NAME', $group['name']);
163
        $template->set_var('SELECTED', '');
164
        $template->parse('group_list', 'group_list_block', true);
165
    }
166
}
167
// Only allow the user to add a user to the Administrators group if they belong to it
168
if(in_array(1, $admin->get_groups_id())) {
169
    $users_groups = $admin->get_groups_name();
170
    $template->set_var('ID', '1');
171
    $template->set_var('NAME', $users_groups[1]);
172
    $template->set_var('SELECTED', '');
173
    $template->parse('group_list', 'group_list_block', true);
174
} else {
175
    if($results->numRows() == 0) {
176
        $template->set_var('ID', '');
177
        $template->set_var('NAME', $oTrans->TEXT_NONE_FOUND);
178
        $template->parse('group_list', 'group_list_block', true);
179
    }
180
}
181
182
// Insert permissions values
183
184
if($admin->get_permission('users_add') != true) {
185
    $template->set_var('DISPLAY_ADD', 'hide');
186
}
187
188
// Generate username field name
189
$username_fieldname = 'username_';
190
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
191
srand((double)microtime()*1000000);
192
$i = 0;
193
while ($i <= 7) {
194
    $num = rand() % 33;
195
    $tmp = substr($salt, $num, 1);
196
    $username_fieldname = $username_fieldname . $tmp;
197
    $i++;
198
}
199
200
// Work-out if home folder should be shown
201
if(!HOME_FOLDERS) {
202
    $template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
203
}
204
205
// Include the WB functions file
206
require_once(WB_PATH.'/framework/functions.php');
207
208
// Add media folders to home folder list
209
$template->set_block('main_block', 'folder_list_block', 'folder_list');
210
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
211
    $template->set_var('NAME', str_replace(WB_PATH, '', $name));
212
    $template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
213
    $template->set_var('SELECTED', ' ');
214
    $template->parse('folder_list', 'folder_list_block', true);
215
}
216
217
// Insert language text and messages
218
$template->set_var(array(
219
            'TEXT_CANCEL' => $oTrans->TEXT_CANCEL,
220
            'TEXT_RESET' => $oTrans->TEXT_RESET,
221
            'TEXT_ACTIVE' => $oTrans->TEXT_ACTIVE,
222
            'TEXT_DISABLED' => $oTrans->TEXT_DISABLED,
223
            'TEXT_PLEASE_SELECT' => $oTrans->TEXT_PLEASE_SELECT,
224
            'TEXT_USERNAME' => $oTrans->TEXT_USERNAME,
225
            'TEXT_PASSWORD' => $oTrans->TEXT_PASSWORD,
226
            'TEXT_RETYPE_PASSWORD' => $oTrans->TEXT_RETYPE_PASSWORD,
227
            'TEXT_DISPLAY_NAME' => $oTrans->TEXT_DISPLAY_NAME,
228
            'TEXT_EMAIL' => $oTrans->TEXT_EMAIL,
229
            'TEXT_GROUP' => $oTrans->TEXT_GROUP,
230
            'TEXT_NONE' => $oTrans->TEXT_NONE,
231
            'TEXT_HOME_FOLDER' => $oTrans->TEXT_HOME_FOLDER,
232
            'USERNAME_FIELDNAME' => $username_fieldname,
233
            'CHANGING_PASSWORD' => $oTrans->MESSAGE_USERS_CHANGING_PASSWORD,
234
            'CANCEL_LINK' => ADMIN_URL.'/access/index.php',
235
            )
236
    );
237
$template->set_block( 'user_display_block', '');
238
239
// Parse template for add user form
240
$template->parse('main', 'main_block', false);
241
$template->pparse('output', 'page');
242
243
$admin->print_footer();