555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 1
<?php
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 2
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 3
/*
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
diff
changeset
+ − 5
* Copyright (C) 2006-2009 Dan Fuhry
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 6
*
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 7
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 8
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 9
*
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 10
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 11
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 12
*/
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 13
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 14
function page_Admin_UserRanks()
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 15
{
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 16
global $db, $session, $paths, $template, $plugins; // Common objects
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 17
global $lang;
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 18
if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 19
{
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 20
$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 21
echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 22
echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 23
return;
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 24
}
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 25
563
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 26
// This should be a constant somewhere
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 27
$protected_ranks = array(
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 28
RANK_ID_MEMBER,
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 29
RANK_ID_MOD,
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 30
RANK_ID_ADMIN,
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 31
RANK_ID_GUEST
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 32
);
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 33
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 34
if ( $paths->getParam(0) == 'action.json' )
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 35
{
628
+ − 36
// ajax call, try to decode json request
+ − 37
header('Content-type: application/json');
+ − 38
+ − 39
if ( !isset($_POST['r']) )
+ − 40
{
+ − 41
echo enano_json_encode(array(
+ − 42
'mode' => 'error',
+ − 43
'error' => 'Missing JSON request payload'
+ − 44
));
+ − 45
return true;
+ − 46
}
+ − 47
try
+ − 48
{
+ − 49
$request = enano_json_decode($_POST['r']);
+ − 50
}
+ − 51
catch ( Exception $e )
+ − 52
{
+ − 53
echo enano_json_encode(array(
+ − 54
'mode' => 'error',
+ − 55
'error' => 'Invalid JSON request payload'
+ − 56
));
+ − 57
return true;
+ − 58
}
+ − 59
+ − 60
if ( !isset($request['mode']) )
+ − 61
{
+ − 62
echo enano_json_encode(array(
+ − 63
'mode' => 'error',
+ − 64
'error' => 'JSON request payload does not contain required parameter "mode"'
+ − 65
));
+ − 66
return true;
+ − 67
}
+ − 68
+ − 69
// we've got it
+ − 70
switch ( $request['mode'] )
+ − 71
{
+ − 72
case 'get_rank':
+ − 73
// easy enough, get a rank from the DB
+ − 74
$rank_id = intval(@$request['rank_id']);
+ − 75
if ( empty($rank_id) )
+ − 76
{
+ − 77
echo enano_json_encode(array(
+ − 78
'mode' => 'error',
+ − 79
'error' => 'Missing rank ID'
+ − 80
));
+ − 81
return true;
+ − 82
}
+ − 83
// query and fetch
+ − 84
$q = $db->sql_query('SELECT rank_id, rank_title, rank_style FROM ' . table_prefix . "ranks WHERE rank_id = $rank_id;");
+ − 85
if ( !$q || $db->numrows() < 1 )
+ − 86
$db->die_json();
+ − 87
+ − 88
$row = $db->fetchrow();
+ − 89
$db->free_result();
+ − 90
+ − 91
// why does mysql do this?
+ − 92
$row['rank_id'] = intval($row['rank_id']);
+ − 93
echo enano_json_encode($row);
+ − 94
break;
+ − 95
case 'save_rank':
+ − 96
// easy enough, get a rank from the DB
+ − 97
$rank_id = intval(@$request['rank_id']);
+ − 98
// note - an empty rank_style field is permitted
+ − 99
if ( empty($rank_id) )
+ − 100
{
+ − 101
echo enano_json_encode(array(
+ − 102
'mode' => 'error',
+ − 103
'error' => 'Missing rank ID'
+ − 104
));
+ − 105
return true;
+ − 106
}
+ − 107
+ − 108
if ( empty($request['rank_title']) )
+ − 109
{
+ − 110
echo enano_json_encode(array(
+ − 111
'mode' => 'error',
+ − 112
'error' => $lang->get('acpur_err_missing_rank_title')
+ − 113
));
+ − 114
return true;
+ − 115
}
+ − 116
+ − 117
// perform update
+ − 118
$rank_title = $db->escape($request['rank_title']);
+ − 119
$rank_style = $db->escape(@$request['rank_style']);
+ − 120
$q = $db->sql_query('UPDATE ' . table_prefix . "ranks SET rank_title = '$rank_title', rank_style = '$rank_style' WHERE rank_id = $rank_id;");
+ − 121
633
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 122
// regenerate the ranks cache
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 123
generate_cache_userranks();
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 124
628
+ − 125
echo enano_json_encode(array(
+ − 126
'mode' => 'success'
+ − 127
));
+ − 128
break;
+ − 129
case 'create_rank':
+ − 130
if ( empty($request['rank_title']) )
+ − 131
{
+ − 132
echo enano_json_encode(array(
+ − 133
'mode' => 'error',
+ − 134
'error' => $lang->get('acpur_err_missing_rank_title')
+ − 135
));
+ − 136
return true;
+ − 137
}
+ − 138
+ − 139
$rank_title = $db->escape($request['rank_title']);
+ − 140
$rank_style = $db->escape(@$request['rank_style']);
+ − 141
+ − 142
// perform insert
+ − 143
$q = $db->sql_query('INSERT INTO ' . table_prefix . "ranks ( rank_title, rank_style ) VALUES\n"
+ − 144
. " ( '$rank_title', '$rank_style' );");
+ − 145
if ( !$q )
+ − 146
$db->die_json();
+ − 147
+ − 148
$rank_id = $db->insert_id();
+ − 149
if ( !$rank_id )
+ − 150
{
+ − 151
echo enano_json_encode(array(
+ − 152
'mode' => 'error',
+ − 153
'error' => 'Refetch of rank ID failed'
+ − 154
));
+ − 155
return true;
+ − 156
}
+ − 157
633
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 158
// regenerate the ranks cache
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 159
generate_cache_userranks();
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 160
628
+ − 161
echo enano_json_encode(array(
+ − 162
'mode' => 'success',
+ − 163
'rank_id' => $rank_id
+ − 164
));
+ − 165
break;
+ − 166
case 'delete_rank':
+ − 167
// nuke a rank
+ − 168
$rank_id = intval(@$request['rank_id']);
+ − 169
if ( empty($rank_id) )
+ − 170
{
+ − 171
echo enano_json_encode(array(
+ − 172
'mode' => 'error',
+ − 173
'error' => 'Missing rank ID'
+ − 174
));
+ − 175
return true;
+ − 176
}
+ − 177
+ − 178
// is this rank protected (e.g. a system rank)?
+ − 179
if ( in_array($rank_id, $protected_ranks) )
+ − 180
{
+ − 181
echo enano_json_encode(array(
+ − 182
'mode' => 'error',
+ − 183
'error' => $lang->get('acpur_err_cant_delete_system_rank')
+ − 184
));
+ − 185
return true;
+ − 186
}
+ − 187
+ − 188
// unset any user and groups that might be using it
+ − 189
$q = $db->sql_query('UPDATE ' . table_prefix . "users SET user_rank = NULL WHERE user_rank = $rank_id;");
+ − 190
if ( !$q )
+ − 191
$db->die_json();
+ − 192
$q = $db->sql_query('UPDATE ' . table_prefix . "groups SET group_rank = NULL WHERE group_rank = $rank_id;");
+ − 193
if ( !$q )
+ − 194
$db->die_json();
+ − 195
+ − 196
// now remove the rank itself
+ − 197
$q = $db->sql_query('DELETE FROM ' . table_prefix . "ranks WHERE rank_id = $rank_id;");
+ − 198
if ( !$q )
+ − 199
$db->_die();
+ − 200
633
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 201
// regenerate the ranks cache
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 202
generate_cache_userranks();
4f81e21b5590
Made the rank editor actually refresh the ranks cache upon creating/editing/deleting a rank. It's 5 in the morning, I'm going to bed, release is first thing after breakfast and coffee.
Dan
diff
changeset
+ − 203
628
+ − 204
echo enano_json_encode(array(
+ − 205
'mode' => 'success'
+ − 206
));
+ − 207
break;
+ − 208
default:
+ − 209
echo enano_json_encode(array(
+ − 210
'mode' => 'error',
+ − 211
'error' => 'Unknown requested operation'
+ − 212
));
+ − 213
return true;
+ − 214
}
563
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 215
return true;
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 216
}
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 217
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 218
// draw initial interface
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 219
// yes, four paragraphs of introduction. Suck it up.
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 220
echo '<h3>' . $lang->get('acpur_heading_main') . '</h3>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 221
echo '<p>' . $lang->get('acpur_intro_para1') . '</p>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 222
echo '<p>' . $lang->get('acpur_intro_para2') . '</p>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 223
echo '<p>' . $lang->get('acpur_intro_para3') . '</p>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 224
echo '<p>' . $lang->get('acpur_intro_para4') . '</p>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 225
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 226
// fetch ranks
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 227
$q = $db->sql_query('SELECT rank_id, rank_title, rank_style FROM ' . table_prefix . "ranks ORDER BY rank_title ASC;");
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 228
if ( !$q )
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 229
$db->_die();
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 230
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 231
echo '<div class="rankadmin-left" id="admin_ranks_container_left">';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 232
while ( $row = $db->fetchrow() )
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 233
{
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 234
// format rank according to what its users look like
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 235
// rank titles can be stored as language strings, so have the language manager fetch this
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 236
// normally it refetches (which takes time) if a string isn't found, but it won't try to fetch
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 237
// a string that isn't in the category_stringid format
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 238
$rank_title = $lang->get($row['rank_title']);
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 239
// FIXME: make sure htmlspecialchars() is escaping quotes and backslashes
628
+ − 240
echo '<a href="#rank_edit:' . $row['rank_id'] . '" onclick="ajaxInitRankEdit(' . $row['rank_id'] . '); return false;" class="rankadmin-editlink" style="' . htmlspecialchars($row['rank_style']) . '" id="rankadmin_editlink_' . $row['rank_id'] . '">' . htmlspecialchars($rank_title) . '</a> ';
563
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 241
}
628
+ − 242
echo '<a href="#rank_create" onclick="ajaxInitRankCreate(); return false;" class="rankadmin-editlink rankadmin-createlink" id="rankadmin_createlink">' . $lang->get('acpur_btn_create_init') . '</a> ';
563
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 243
echo '</div>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 244
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 245
echo '<div class="rankadmin-right" id="admin_ranks_container_right">';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 246
echo $lang->get('acpur_msg_select_rank');
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 247
echo '</div>';
0103428e2179
First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
diff
changeset
+ − 248
echo '<span class="menuclear"></span>';
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 249
}
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 250
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff
changeset
+ − 251
?>