Ignore:
Timestamp:
Jul 7, 2011, 1:27:50 PM (13 years ago)
Author:
J.Commelin
Message:

Refactored code and added comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Copyrights/admin.php

    r11635 r11656  
    3232check_status(ACCESS_ADMINISTRATOR);
    3333
    34 // Default is to create, if changed to 1, show edit page
     34// Default is to create a copyright, if changed to 1, show the edit page
    3535$edit = 0;
    3636
     
    4444// Do managing of copyrights
    4545if (isset($_GET['tab'])) {
     46  // Create a new copyright
    4647  if ($_GET['tab'] == 'create') {
     48    // Fetch the values from the form
    4749    $name = pwg_db_real_escape_string($_REQUEST['name']);
    4850    $url = pwg_db_real_escape_string($_REQUEST['url']);
    4951    $descr = pwg_db_real_escape_string($_REQUEST['descr']);
    5052    $visible = (isset($_REQUEST['visible']) ? 1 : 0);
     53
     54    // Check whether a copyright with such a name exists
     55    // Therefore count the number of copyrights with that name
    5156    $query = sprintf(
    5257      'SELECT COUNT(*)
     
    5661      COPYRIGHTS_ADMIN, $name);
    5762    list($counter) = pwg_db_fetch_row(pwg_query($query));
    58     if ($counter != 0) {
     63
     64    if ($counter != 0) { // The copyright exists already
    5965      array_push($page['errors'], l10n('This copyright already exists'));
    60     } else {
     66    } else { // The copyright did not yet exist
     67      // Compose a query to insert the copyright
    6168      $query = sprintf(
    6269        'INSERT INTO %s
     
    6572        ;',
    6673        COPYRIGHTS_ADMIN, $name, $url, $descr, $visible);
    67       pwg_query($query);
     74      pwg_query($query); // Execute the query
    6875    }
    6976  }
    7077
     78  // Edit an existing copyright
    7179  if ($_GET['tab'] == 'edit') {
    72     $edit = 1;
    73     $CRid = $_REQUEST['id'];
     80    $edit = 1; // Show the edit page
     81    $CRid = $_REQUEST['id']; // Fetch the id of the copyright to be edited
     82
     83    // Fetch the current attributes to the copyright
    7484    $query = sprintf(
    7585      'SELECT *
     
    8090    $result = pwg_query($query);
    8191    $row = pwg_db_fetch_assoc($result);
     92
     93    // Save the attributes in convenient variables
    8294    $CRname = $row['name'];
    8395    $CRurl = $row['url'];
     
    8698  }
    8799
     100  // Update an existing copyright
    88101  if ($_GET['tab'] == 'update') {
     102    // Fetch the values from the edit form
    89103    $id = pwg_db_real_escape_string($_REQUEST['id']);
    90104    $name = pwg_db_real_escape_string($_REQUEST['name']);
     
    92106    $descr= pwg_db_real_escape_string($_REQUEST['descr']);
    93107    $visible = (isset($_REQUEST['visible']) ? 1 : 0);
     108
     109    // Compose a query to update the copyright
    94110    $query = sprintf(
    95111      'UPDATE %s
     
    98114      ;',
    99115      COPYRIGHTS_ADMIN, $name, $url, $descr, $visible, $id);
    100     pwg_query($query);
     116    pwg_query($query); // Execute the query
    101117  }
    102  
     118
     119  // Delete an existing copyright
    103120  if ($_GET['tab'] == 'delete') {
    104     $id = $_REQUEST['id'];
     121    $id = $_REQUEST['id']; // Fetch the id of the copyright to be deleted
     122
     123    // Compose a query to delete the copyright
    105124    $query = sprintf(
    106125      'DELETE FROM %s
     
    108127      ;',
    109128      COPYRIGHTS_ADMIN, $id);
    110     pwg_query($query);
     129    pwg_query($query); // Execute the query
    111130  }
    112131}
    113132
    114 // Create page template
     133/* Assign variables to the template */
    115134global $template;
    116135
     136// Add the admin.tpl template
    117137$template->set_filenames(
    118138  array(
     
    121141);
    122142
     143// Select the existing copyrights
    123144$query = sprintf(
    124145  'SELECT *
     
    128149$result = pwg_query($query);
    129150
     151// Append the copyrights to the Smarty array
    130152while ($row = pwg_db_fetch_assoc($result)) {
    131153  $template->append(
     
    141163}
    142164
     165// Assign the path for URL forming
    143166$template->assign(
    144167  'COPYRIGHTS_PATH',
     
    146169);
    147170
     171// Assign all the variables we constructed above
    148172$template->assign('edit', $edit);
    149173$template->assign('CRid', $CRid);
     
    153177$template->assign('CRvisible', $CRvisible);
    154178
     179// Get it up and running
    155180$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    156181
Note: See TracChangeset for help on using the changeset viewer.