| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
// Contains UI management functions for the votingapi_actions module.
|
| 5 |
|
| 6 |
function votingapi_actions_admin_page() {
|
| 7 |
$numSets = 25;
|
| 8 |
|
| 9 |
votingapi_rebuild_action_cache();
|
| 10 |
|
| 11 |
drupal_set_title(t('administer voting actions'));
|
| 12 |
|
| 13 |
foreach (_votingapi_load_action_sets_from_db() as $name => $set) {
|
| 14 |
$links = array();
|
| 15 |
$links['votingapi_actions_edit'] = array(
|
| 16 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/gtk-edit.png'),
|
| 17 |
'html' => TRUE,
|
| 18 |
'href' => "admin/voting/actions/edit/$name",
|
| 19 |
'attributes' => array('title' => t('Edit this action set')),
|
| 20 |
);
|
| 21 |
$links['votingapi_actions_export'] = array(
|
| 22 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/document-save.png'),
|
| 23 |
'html' => TRUE,
|
| 24 |
'href' => "admin/voting/actions/export/$name",
|
| 25 |
'attributes' => array('title' => t('Export this action set')),
|
| 26 |
);
|
| 27 |
$links['votingapi_actions_delete'] = array(
|
| 28 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/edit-delete.png'),
|
| 29 |
'html' => TRUE,
|
| 30 |
'href' => "admin/voting/actions/delete/$name",
|
| 31 |
'attributes' => array('title' => t('Delete this action set')),
|
| 32 |
);
|
| 33 |
$items[] = array($name, $set['description'], theme('links', $links));
|
| 34 |
$used[$name] = true;
|
| 35 |
}
|
| 36 |
|
| 37 |
if ($items) {
|
| 38 |
$output = theme('table', array(t('Name'), t('Description'), t('Actions')), $items, array("cellpadding" => "4"), t('User-Defined Action Sets'));
|
| 39 |
$output .= theme('pager', NULL, $numSets);
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
$output .= '<p>' . t('No action sets have currently been defined.') . '</p>';
|
| 43 |
}
|
| 44 |
|
| 45 |
$output .= t('<p>Below are system default action sets; if you clone one of these, or create another set with the same name, it will override the default.</p>');
|
| 46 |
|
| 47 |
$items = array();
|
| 48 |
$default_actions = _votingapi_load_action_sets_from_modules();
|
| 49 |
$set_status = variable_get('votingapi_action_status', array());
|
| 50 |
|
| 51 |
foreach ($default_actions as $name => $set) {
|
| 52 |
if ($used[$name]) {
|
| 53 |
$status = t('Overridden');
|
| 54 |
}
|
| 55 |
else if (isset($set_status[$name])) {
|
| 56 |
if ($set_status[$name]) {
|
| 57 |
$status = 'Enabled';
|
| 58 |
}
|
| 59 |
else {
|
| 60 |
$status = 'Disabled';
|
| 61 |
}
|
| 62 |
}
|
| 63 |
else if ($set['enabled']) {
|
| 64 |
$status = 'Enabled';
|
| 65 |
}
|
| 66 |
else {
|
| 67 |
$status = 'Disabled';
|
| 68 |
}
|
| 69 |
|
| 70 |
if ($status == 'Enabled') {
|
| 71 |
$links = array();
|
| 72 |
$links['votingapi_actions_add'] = array(
|
| 73 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/edit-paste.png'),
|
| 74 |
'html' => TRUE,
|
| 75 |
'href' => "admin/voting/actions/add/$name",
|
| 76 |
'attributes' => array('title' => t('Clone this action set')),
|
| 77 |
);
|
| 78 |
$links['votingapi_actions_export'] = array(
|
| 79 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/document-save.png'),
|
| 80 |
'html' => TRUE,
|
| 81 |
'href' => "admin/voting/actions/export/$name",
|
| 82 |
'attributes' => array('title' => t('Export this action set')),
|
| 83 |
);
|
| 84 |
$links['votingapi_actions_disable'] = array(
|
| 85 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/process-stop.png'),
|
| 86 |
'html' => TRUE,
|
| 87 |
'href' => "admin/voting/actions/disable/$name",
|
| 88 |
'attributes' => array('title' => t('Disable this action set')),
|
| 89 |
);
|
| 90 |
}
|
| 91 |
else if ($status == 'Disabled') {
|
| 92 |
$links = array();
|
| 93 |
$links['votingapi_actions_add'] = array(
|
| 94 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/edit-paste.png'),
|
| 95 |
'html' => TRUE,
|
| 96 |
'href' => "admin/voting/actions/add/$name",
|
| 97 |
'attributes' => array('title' => t('Clone this action set')),
|
| 98 |
);
|
| 99 |
$links['votingapi_actions_export'] = array(
|
| 100 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/document-save.png'),
|
| 101 |
'html' => TRUE,
|
| 102 |
'href' => "admin/voting/actions/export/$name",
|
| 103 |
'attributes' => array('title' => t('Export this action set')),
|
| 104 |
);
|
| 105 |
$links['votingapi_actions_enable'] = array(
|
| 106 |
'title' => theme('image', drupal_get_path('module', 'votingapi_actions') . '/icons/media-playback-start.png'),
|
| 107 |
'html' => TRUE,
|
| 108 |
'href' => "admin/voting/actions/enable/$name",
|
| 109 |
'attributes' => array('title' => t('Enable this action set')),
|
| 110 |
);
|
| 111 |
}
|
| 112 |
else if ($status == 'Overridden') {
|
| 113 |
$links = array();
|
| 114 |
}
|
| 115 |
|
| 116 |
$items[] = array($name, $set['source'], $set['description'], $status, theme('links', $links));
|
| 117 |
}
|
| 118 |
|
| 119 |
if ($items) {
|
| 120 |
$output .= theme('table', array(t('Name'), t('Source'), t('Description'), t('Status'), t('Actions')), $items, array("cellpadding" => "4"), t('Default Action Sets'));
|
| 121 |
}
|
| 122 |
else {
|
| 123 |
$output .= t('<p>No action sets have currently been defined.</p>');
|
| 124 |
}
|
| 125 |
|
| 126 |
return $output;
|
| 127 |
}
|
| 128 |
|
| 129 |
function votingapi_actions_admin_import_page($set_name = NULL) {
|
| 130 |
$form['set'] = array(
|
| 131 |
'#type' => 'textarea',
|
| 132 |
'#title' => t('Import action set'),
|
| 133 |
'#rows' => 20
|
| 134 |
);
|
| 135 |
$form['submit'] = array(
|
| 136 |
'#type' => 'submit',
|
| 137 |
'#value' => t("Submit"),
|
| 138 |
);
|
| 139 |
|
| 140 |
return $form;
|
| 141 |
}
|
| 142 |
|
| 143 |
/*
|
| 144 |
* Handle the submit button on importing an action set.
|
| 145 |
*/
|
| 146 |
function votingapi_actions_admin_import_page_validate($form_id, &$form) {
|
| 147 |
ob_start();
|
| 148 |
eval($form['set']);
|
| 149 |
ob_end_clean();
|
| 150 |
|
| 151 |
if (is_array($sets)) {
|
| 152 |
foreach($sets as $name => $set) {
|
| 153 |
if ($name) {
|
| 154 |
$errors = _votingapi_validate_action_set($name, $set);
|
| 155 |
foreach($errors as $error) {
|
| 156 |
form_set_error('', $error);
|
| 157 |
}
|
| 158 |
}
|
| 159 |
}
|
| 160 |
}
|
| 161 |
}
|
| 162 |
|
| 163 |
/*
|
| 164 |
* Handle the submit button on importing an action set.
|
| 165 |
*/
|
| 166 |
function votingapi_actions_admin_import_page_submit($formid, $form) {
|
| 167 |
ob_start();
|
| 168 |
eval($form['set']);
|
| 169 |
ob_end_clean();
|
| 170 |
|
| 171 |
if (is_array($sets)) {
|
| 172 |
foreach($sets as $name => $set) {
|
| 173 |
if ($name) {
|
| 174 |
$errors = _votingapi_validate_action_set($name, $set);
|
| 175 |
if (count($errors) == 0) {
|
| 176 |
_votingapi_insert_set($name, $set);
|
| 177 |
votingapi_rebuild_action_cache();
|
| 178 |
drupal_goto('admin/voting/actions');
|
| 179 |
}
|
| 180 |
else {
|
| 181 |
foreach ($errors as $error) {
|
| 182 |
drupal_set_message($error);
|
| 183 |
}
|
| 184 |
}
|
| 185 |
}
|
| 186 |
else {
|
| 187 |
drupal_set_message(t('Unable to get an action set out of that.'));
|
| 188 |
return;
|
| 189 |
}
|
| 190 |
}
|
| 191 |
}
|
| 192 |
}
|
| 193 |
|
| 194 |
function votingapi_actions_admin_export_page($set_name) {
|
| 195 |
$code = _votingapi_create_set_code($set_name);
|
| 196 |
$lines = substr_count($code, "\n");
|
| 197 |
$form['code'] = array(
|
| 198 |
'#type' => 'textarea',
|
| 199 |
'#title' => $set['name'],
|
| 200 |
'#default_value' => $code,
|
| 201 |
'#rows' => max($lines, 20)
|
| 202 |
);
|
| 203 |
return $form;
|
| 204 |
}
|
| 205 |
|
| 206 |
function votingapi_actions_admin_delete_page($set_name) {
|
| 207 |
$form['set'] = array('#type' => 'value', '#value' => $set_name);
|
| 208 |
return confirm_form(
|
| 209 |
$form,
|
| 210 |
t('Are you sure you want to delete %title?', array('%title' => $set_name)),
|
| 211 |
$_GET['destination'] ? $_GET['destination'] : 'admin/voting/actions',
|
| 212 |
t('This action cannot be undone.'),
|
| 213 |
t('Delete'), t('Cancel')
|
| 214 |
);
|
| 215 |
}
|
| 216 |
|
| 217 |
/*
|
| 218 |
* Handle the submit button to delete a view.
|
| 219 |
*/
|
| 220 |
function votingapi_actions_admin_delete_page_submit($formid, $form) {
|
| 221 |
$name = $form['set'];
|
| 222 |
$sets = _votingapi_load_action_sets_from_db();
|
| 223 |
if ($sets[$name]) {
|
| 224 |
_votingapi_delete_set($name, $set[$name]);
|
| 225 |
}
|
| 226 |
return 'admin/voting/actions';
|
| 227 |
}
|
| 228 |
|
| 229 |
function votingapi_actions_admin_enable_page($set_name) {
|
| 230 |
_votingapi_set_action_status($set_name, true);
|
| 231 |
drupal_goto('admin/voting/actions');
|
| 232 |
}
|
| 233 |
|
| 234 |
function votingapi_actions_admin_disable_page($set_name) {
|
| 235 |
_votingapi_set_action_status($set_name, false);
|
| 236 |
drupal_goto('admin/voting/actions');
|
| 237 |
}
|
| 238 |
|
| 239 |
function _votingapi_create_set_code($set_name) {
|
| 240 |
$data = cache_get('votingapi_action_sets');
|
| 241 |
$action_sets = unserialize($data->data);
|
| 242 |
$set = $action_sets[$set_name];
|
| 243 |
if ($set) {
|
| 244 |
unset($set['name']);
|
| 245 |
$code = "\n\$sets = array(\n";
|
| 246 |
$code .= "'$set_name' => ";
|
| 247 |
ob_start();
|
| 248 |
var_export($set);
|
| 249 |
$code .= ob_get_clean();
|
| 250 |
ob_end_clean();
|
| 251 |
$code .= "\n);\n";
|
| 252 |
}
|
| 253 |
|
| 254 |
return $code;
|
| 255 |
}
|
| 256 |
|
| 257 |
// This one, this is the biggie.
|
| 258 |
|
| 259 |
function votingapi_actions_admin_edit_page($mode = 'add', $set_name = NULL) {
|
| 260 |
$form = array();
|
| 261 |
$form[] = array(
|
| 262 |
'#type' => 'markup',
|
| 263 |
'#value' => 'Work in progress. Come again soon!'
|
| 264 |
);
|
| 265 |
return $form;
|
| 266 |
}
|