comment_vote_settings
- Versions
- 4.6
comment_vote_settings($mid = 0)
Menu callback; displays page for assigning names to vote values.
Code
modules/comment.module, line 1135
<?php
function comment_vote_settings($mid = 0) {
$op = $_POST['op'];
$edit = $_POST['edit'];
if ($op == t('Save vote')) {
db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit['vote'], $edit['weight'], $mid);
$mid = 0; // zero it out so we return to the overview.
drupal_set_message(t('The vote has been saved.'));
}
else if ($op == t('Delete vote')) {
db_query('DELETE FROM {moderation_votes} WHERE mid = %d', $mid);
db_query('DELETE FROM {moderation_roles} WHERE mid = %d', $mid);
$mid = 0; // zero it out so we return to the overview.
drupal_set_message(t('The vote has been deleted.'));
}
else if ($op == t('Add new vote')) {
db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit['vote'], $edit['weight']);
$mid = 0; // zero it out so we return to the overview.
drupal_set_message(t('The vote has been added.'));
}
$output .= '<h3>'. t('Moderation votes overview') .'</h3>';
// load up and show any vote types previously defined.
$header = array(t('Votes'), t('Weight'), t('Operations'));
$result = db_query('SELECT mid, vote, weight FROM {moderation_votes} ORDER BY weight');
while ($vote = db_fetch_object($result)) {
$rows[] = array($vote->vote, array('data' => $vote->weight), array('data' => l(t('edit'), "admin/comment/configure/votes/$vote->mid")));
}
if (!$rows) {
$rows[] = array(array('data' => t('No vote types have been defined.'), 'colspan' => '3'));
}
$output .= theme('table', $header, $rows);
if ($mid) { // if we're not saving, deleting, or adding, we must be editing, so prefill the form fields.
$vote = db_fetch_object(db_query('SELECT vote, weight FROM {moderation_votes} WHERE mid = %d', $mid));
}
$output .= '<br /><h3>'. (isset($mid) ? t('Edit moderation option') : t('Add new moderation option')) .'</h3>';
$form .= form_textfield(t('Vote'), 'vote', $vote->vote, 32, 64, t('The name of this vote. Example: "off topic", "excellent", "sucky".'));
$form .= form_textfield(t('Weight'), 'weight', $vote->weight, 32, 64, t('Used to order votes in the comment control box; heavier sink.'));
if ($mid) {
$form .= form_submit(t('Save vote'));
$form .= form_submit(t('Delete vote'));
}
else {
$form .= form_submit(t('Add new vote'));
}
print theme('page', $output . form($form));
}
?>Login or register to post comments 