plugins/admin/UserRanks.php
author Dan
Mon, 11 Aug 2008 22:31:04 -0400
changeset 685 17ebe24cdf85
parent 633 4f81e21b5590
child 801 eb8b23f11744
permissions -rw-r--r--
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
685
17ebe24cdf85 Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
parents: 633
diff changeset
     5
 * Version 1.1.5 (Caoineag alpha 5)
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
     6
 * Copyright (C) 2006-2008 Dan Fuhry
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
     7
 *
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
     8
 * 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
     9
 * 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
    10
 *
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    11
 * 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
    12
 * 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
    13
 */
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    14
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    15
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
    16
{
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    17
  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
    18
  global $lang;
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    19
  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
    20
  {
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    21
    $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
    22
    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
    23
    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
    24
    return;
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    25
  }
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
    26
  
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
parents: 555
diff changeset
    27
  // 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
parents: 555
diff changeset
    28
  $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
parents: 555
diff changeset
    29
      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
parents: 555
diff changeset
    30
      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
parents: 555
diff changeset
    31
      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
parents: 555
diff changeset
    32
      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
parents: 555
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
parents: 555
diff changeset
    34
  
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
parents: 555
diff changeset
    35
  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
parents: 555
diff changeset
    36
  {
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    37
    // ajax call, try to decode json request
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    38
    header('Content-type: application/json');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    39
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    40
    if ( !isset($_POST['r']) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    41
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    42
      echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    43
          'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    44
          'error' => 'Missing JSON request payload'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    45
        ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    46
      return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    47
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    48
    try
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    49
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    50
      $request = enano_json_decode($_POST['r']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    51
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    52
    catch ( Exception $e )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    53
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    54
      echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    55
          'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    56
          'error' => 'Invalid JSON request payload'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    57
        ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    58
      return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    59
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    60
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    61
    if ( !isset($request['mode']) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    62
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    63
      echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    64
          'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    65
          'error' => 'JSON request payload does not contain required parameter "mode"'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    66
        ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    67
      return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    68
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    69
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    70
    // we've got it
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    71
    switch ( $request['mode'] )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    72
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    73
      case 'get_rank':
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    74
        // easy enough, get a rank from the DB
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    75
        $rank_id = intval(@$request['rank_id']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    76
        if ( empty($rank_id) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    77
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    78
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    79
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    80
              'error' => 'Missing rank ID'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    81
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    82
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    83
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    84
        // query and fetch
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    85
        $q = $db->sql_query('SELECT rank_id, rank_title, rank_style FROM ' . table_prefix . "ranks WHERE rank_id = $rank_id;");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    86
        if ( !$q || $db->numrows() < 1 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    87
          $db->die_json();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    88
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    89
        $row = $db->fetchrow();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    90
        $db->free_result();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    91
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    92
        // why does mysql do this?
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    93
        $row['rank_id'] = intval($row['rank_id']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    94
        echo enano_json_encode($row);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    95
        break;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    96
      case 'save_rank':
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    97
        // easy enough, get a rank from the DB
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    98
        $rank_id = intval(@$request['rank_id']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    99
        // note - an empty rank_style field is permitted
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   100
        if ( empty($rank_id) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   101
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   102
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   103
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   104
              'error' => 'Missing rank ID'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   105
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   106
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   107
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   108
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   109
        if ( empty($request['rank_title']) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   110
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   111
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   112
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   113
              'error' => $lang->get('acpur_err_missing_rank_title')
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   114
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   115
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   116
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   117
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   118
        // perform update
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   119
        $rank_title = $db->escape($request['rank_title']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   120
        $rank_style = $db->escape(@$request['rank_style']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   121
        $q = $db->sql_query('UPDATE ' . table_prefix . "ranks SET rank_title = '$rank_title', rank_style = '$rank_style' WHERE rank_id = $rank_id;");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   122
        
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
parents: 628
diff changeset
   123
        // 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
parents: 628
diff changeset
   124
        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
parents: 628
diff changeset
   125
        
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   126
        echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   127
            'mode' => 'success'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   128
          ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   129
        break;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   130
      case 'create_rank':
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   131
        if ( empty($request['rank_title']) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   132
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   133
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   134
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   135
              'error' => $lang->get('acpur_err_missing_rank_title')
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   136
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   137
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   138
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   139
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   140
        $rank_title = $db->escape($request['rank_title']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   141
        $rank_style = $db->escape(@$request['rank_style']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   142
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   143
        // perform insert
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   144
        $q = $db->sql_query('INSERT INTO ' . table_prefix . "ranks ( rank_title, rank_style ) VALUES\n"
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   145
                          . "  ( '$rank_title', '$rank_style' );");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   146
        if ( !$q )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   147
          $db->die_json();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   148
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   149
        $rank_id = $db->insert_id();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   150
        if ( !$rank_id )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   151
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   152
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   153
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   154
              'error' => 'Refetch of rank ID failed'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   155
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   156
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   157
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   158
        
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
parents: 628
diff changeset
   159
        // 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
parents: 628
diff changeset
   160
        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
parents: 628
diff changeset
   161
        
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   162
        echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   163
            'mode' => 'success',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   164
            'rank_id' => $rank_id
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   165
          ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   166
        break;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   167
      case 'delete_rank':
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   168
        // nuke a rank
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   169
        $rank_id = intval(@$request['rank_id']);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   170
        if ( empty($rank_id) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   171
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   172
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   173
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   174
              'error' => 'Missing rank ID'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   175
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   176
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   177
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   178
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   179
        // is this rank protected (e.g. a system rank)?
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   180
        if ( in_array($rank_id, $protected_ranks) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   181
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   182
          echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   183
              'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   184
              'error' => $lang->get('acpur_err_cant_delete_system_rank')
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   185
            ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   186
          return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   187
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   188
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   189
        // unset any user and groups that might be using it
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   190
        $q = $db->sql_query('UPDATE ' . table_prefix . "users SET user_rank = NULL WHERE user_rank = $rank_id;");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   191
        if ( !$q )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   192
          $db->die_json();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   193
        $q = $db->sql_query('UPDATE ' . table_prefix . "groups SET group_rank = NULL WHERE group_rank = $rank_id;");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   194
        if ( !$q )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   195
          $db->die_json();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   196
        
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   197
        // now remove the rank itself
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   198
        $q = $db->sql_query('DELETE FROM ' . table_prefix . "ranks WHERE rank_id = $rank_id;");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   199
        if ( !$q )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   200
          $db->_die();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   201
        
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
parents: 628
diff changeset
   202
        // 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
parents: 628
diff changeset
   203
        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
parents: 628
diff changeset
   204
        
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   205
        echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   206
            'mode' => 'success'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   207
          ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   208
        break;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   209
      default:
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   210
        echo enano_json_encode(array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   211
          'mode' => 'error',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   212
          'error' => 'Unknown requested operation'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   213
        ));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   214
      return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   215
    }
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
parents: 555
diff changeset
   216
    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
parents: 555
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
parents: 555
diff changeset
   218
  
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
parents: 555
diff changeset
   219
  // 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
parents: 555
diff changeset
   220
  // 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
parents: 555
diff changeset
   221
  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
parents: 555
diff changeset
   222
  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
parents: 555
diff changeset
   223
  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
parents: 555
diff changeset
   224
  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
parents: 555
diff changeset
   225
  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
parents: 555
diff changeset
   226
  
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
parents: 555
diff changeset
   227
  // 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
parents: 555
diff changeset
   228
  $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
parents: 555
diff changeset
   229
  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
parents: 555
diff changeset
   230
    $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
parents: 555
diff changeset
   231
  
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
parents: 555
diff changeset
   232
  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
parents: 555
diff changeset
   233
  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
parents: 555
diff changeset
   234
  {
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
parents: 555
diff changeset
   235
    // 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
parents: 555
diff changeset
   236
    // 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
parents: 555
diff changeset
   237
    // 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
parents: 555
diff changeset
   238
    // 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
parents: 555
diff changeset
   239
    $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
parents: 555
diff changeset
   240
    // FIXME: make sure htmlspecialchars() is escaping quotes and backslashes
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   241
    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
parents: 555
diff changeset
   242
  }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   243
  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
parents: 555
diff changeset
   244
  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
parents: 555
diff changeset
   245
  
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
parents: 555
diff changeset
   246
  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
parents: 555
diff changeset
   247
  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
parents: 555
diff changeset
   248
  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
parents: 555
diff changeset
   249
  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
   250
}
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
   251
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
diff changeset
   252
?>