comment_matrix_settings

Versions
4.6
comment_matrix_settings()

Menu callback; presents the moderation vote matrix.

Code

modules/comment.module, line 1056

<?php
function comment_matrix_settings() {

  if ($edit = $_POST['edit']) {
    db_query('DELETE FROM {moderation_roles} ');
    foreach ($edit as $role_id => $votes) {
      foreach ($votes as $mid => $value) {
        $sql = "('$mid', '$role_id', '". ($value ? $value : 0) ."')";
        db_query('INSERT INTO {moderation_roles} (mid, rid, value) VALUES '. $sql);
      }
    }
    drupal_set_message(t('The vote values have been saved.'));
  }

  $output .= '<h3>'. t('Moderation vote/value matrix') .'</h3>';

  $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'");
  $role_names = array();
  while ($role = db_fetch_object($result)) {
    $role_names[$role->rid] = $role->name;
  }

  $result = db_query('SELECT rid, mid, value FROM {moderation_roles} ');
  while ($role = db_fetch_object($result)) {
    $mod_roles[$role->rid][$role->mid] = $role->value;
  }

  $header = array_merge(array(t('Votes')), array_values($role_names));

  $result = db_query('SELECT mid, vote FROM {moderation_votes} ORDER BY weight');
  while ($vote = db_fetch_object($result)) {
    $row = array($vote->vote);
    foreach (array_keys($role_names) as $rid) {
      $row[] = array('data' => form_textfield(NULL, "$rid][$vote->mid", $mod_roles[$rid][$vote->mid], 4, 3));
    }
    $rows[] = $row;
  }
  if (!$rows) {
    $rows[] = array(array('data' => t('No votes have been defined.'), 'colspan' => '5'));
  }

  $output .= theme('table', $header, $rows);
  if ($rows) { $output .= '<br />'. form_submit(t('Submit votes')); }

  print theme('page', form($output));
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.