| 1 |
<?php |
<?php |
| 2 |
// $Id: feature.module,v 1.26 2007/01/08 00:05:31 killes Exp $ |
// $Id: feature.module,v 1.27 2007/12/05 20:48:08 kbahey Exp $ |
| 3 |
|
|
| 4 |
define('FEATURE_CATEGORY_LIST', 'feature_category_list'); |
define('FEATURE_CATEGORY_LIST', 'feature_category_list'); |
| 5 |
|
|
| 27 |
return array("maintain feature list"); |
return array("maintain feature list"); |
| 28 |
} |
} |
| 29 |
|
|
| 30 |
function feature_menu($may_cache) { |
function feature_menu() { |
| 31 |
$items = array(); |
$items = array(); |
| 32 |
$access = user_access("maintain feature list"); |
$access = user_access("maintain feature list"); |
| 33 |
|
|
| 34 |
if ($may_cache) { |
$items['admin/feature'] = array( |
| 35 |
$items[] = array( |
'title' => t('Features'), |
| 36 |
'path' => 'admin/feature', |
'page callback' => 'feature_admin_list', |
| 37 |
'title' => t('Features'), |
'access' => $access, |
| 38 |
'callback' => 'feature_admin_list', |
'file' => 'feature.module', |
| 39 |
'access' => $access, |
); |
| 40 |
); |
$items['admin/feature/list'] = array( |
| 41 |
$items[] = array( |
'title' => t('List'), |
| 42 |
'path' => 'admin/feature/list', |
'page callback' => 'feature_admin_list', |
| 43 |
'title' => t('List'), |
'access' => $access, |
| 44 |
'callback' => 'feature_admin_list', |
'file' => 'feature.module', |
| 45 |
'access' => $access, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 46 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'weight' => -10, |
| 47 |
'weight' => -10, |
); |
| 48 |
); |
$items['admin/feature/add'] = array( |
| 49 |
$items[] = array( |
'title' => t('Add feature'), |
| 50 |
'path' => 'admin/feature/add', |
'page callback' => 'drupal_get_form', |
| 51 |
'title' => t('Add feature'), |
'page arguments' => array('feature_admin'), |
| 52 |
'callback' => 'drupal_get_form', |
'access' => $access, |
| 53 |
'callback arguments' => array('feature_admin'), |
'file' => 'feature.module', |
| 54 |
'access' => $access, |
'type' => MENU_LOCAL_TASK, |
| 55 |
'type' => MENU_LOCAL_TASK, |
); |
| 56 |
); |
$items['admin/feature/edit'] = array( |
| 57 |
$items[] = array( |
'title' => t('Edit feature'), |
| 58 |
'path' => 'admin/feature/edit', |
'page callback' => 'drupal_get_form', |
| 59 |
'title' => t('Edit feature'), |
'page arguments' => array('feature_admin'), |
| 60 |
'callback' => 'drupal_get_form', |
'access' => $access, |
| 61 |
'callback arguments' => array('feature_admin'), |
'file' => 'feature.module', |
| 62 |
'access' => $access, |
'type' => MENU_CALLBACK, |
| 63 |
'type' => MENU_CALLBACK, |
); |
| 64 |
); |
$items['admin/feature/delete'] = array( |
| 65 |
$items[] = array( |
'title' => t('Delete feature'), |
| 66 |
'path' => 'admin/feature/delete', |
'page callback' => 'feature_admin_delete', |
| 67 |
'title' => t('Delete feature'), |
'access' => $access, |
| 68 |
'callback' => 'feature_admin_delete', |
'file' => 'feature.module', |
| 69 |
'access' => $access, |
'type' => MENU_CALLBACK, |
| 70 |
'type' => MENU_CALLBACK, |
); |
| 71 |
); |
$items['admin/feature/settings'] = array( |
| 72 |
$items[] = array( |
'title' => t('Settings'), |
| 73 |
'path' => 'admin/feature/settings', |
'page callback' => 'drupal_get_form', |
| 74 |
'title' => t('Settings'), |
'page arguments' => array('feature_settings'), |
| 75 |
'callback' => 'drupal_get_form', |
'access' => $access, |
| 76 |
'callback arguments' => array('feature_settings'), |
'file' => 'feature.module', |
| 77 |
'access' => $access, |
'type' => MENU_LOCAL_TASK, |
| 78 |
'type' => MENU_LOCAL_TASK, |
); |
| 79 |
); |
$items['features'] = array( |
| 80 |
$items[] = array( |
'title' => t('Features'), |
| 81 |
'path' => 'features', |
'page callback' => 'feature_listing', |
| 82 |
'title' => t('Features'), |
'access' => user_access('access content'), |
| 83 |
'callback' => 'feature_listing', |
'file' => 'feature.module', |
| 84 |
'access' => user_access('access content'), |
'type' => MENU_CALLBACK, |
| 85 |
'type' => MENU_CALLBACK, |
); |
|
); |
|
|
} |
|
| 86 |
return $items; |
return $items; |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
function feature_get($fid) { |
function feature_get($fid) { |
| 90 |
return db_fetch_object(db_query("SELECT * FROM {feature} WHERE fid = %d", $fid)); |
if ($fid) { |
| 91 |
|
$feature = db_fetch_object(db_query("SELECT * FROM {feature} WHERE fid = %d", $fid)); |
| 92 |
|
} |
| 93 |
|
else { |
| 94 |
|
$feature->name = ''; |
| 95 |
|
$feature->category = ''; |
| 96 |
|
$feature->description = ''; |
| 97 |
|
$feature->details = ''; |
| 98 |
|
$feature->image = ''; |
| 99 |
|
$feature->fid = 0; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
return $feature; |
| 103 |
} |
} |
| 104 |
|
|
| 105 |
function feature_settings() { |
function feature_settings() { |
| 123 |
$op = arg(2); |
$op = arg(2); |
| 124 |
$fid = (int)arg(3); |
$fid = (int)arg(3); |
| 125 |
|
|
| 126 |
if ($fid) { |
$feature = feature_get($fid); |
|
$feature = feature_get($fid); |
|
|
} |
|
|
else { |
|
|
$feature = array(); |
|
|
} |
|
| 127 |
|
|
| 128 |
$form['name'] = array( |
$form['name'] = array( |
| 129 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
function feature_admin_validate($form_id, $form_values) { |
function feature_admin_validate($form_id, $form_values) { |
| 187 |
if (empty($form_values['name'])) { |
if (empty($form_values['values']['name'])) { |
| 188 |
form_set_error('name', t('You have to specify a valid name.')); |
form_set_error('name', t('You have to specify a valid name.')); |
| 189 |
} |
} |
| 190 |
|
|
| 191 |
if (empty($form_values['description'])) { |
if (empty($form_values['values']['description'])) { |
| 192 |
form_set_error('description', t('You have to specify a valid description.')); |
form_set_error('description', t('You have to specify a valid description.')); |
| 193 |
} |
} |
| 194 |
} |
} |
| 195 |
|
|
| 196 |
function feature_admin_submit($form_id, $form_values = NULL) { |
function feature_admin_submit($form_id, $form_values = NULL) { |
| 197 |
if ($form_values['fid'] && $form_values['name']) { |
$values = $form_values['values']; |
| 198 |
db_query("UPDATE {feature} SET name = '%s', category = '%d', description = '%s', details = '%s', image = '%s' WHERE fid = %d", $form_values['name'], $form_values['category'], $form_values['description'], $form_values['details'], $form_values['image'], $form_values['fid']); |
if (isset($values['fid']) && isset($values['name'])) { |
| 199 |
|
db_query("UPDATE {feature} SET name = '%s', category = '%d', description = '%s', details = '%s', image = '%s' WHERE fid = %d", $values['name'], $values['category'], $values['description'], $values['details'], $values['image'], $values['fid']); |
| 200 |
} |
} |
| 201 |
else { |
else { |
| 202 |
db_query("INSERT INTO {feature} (name, category, description, details, image) VALUES ('%s', '%s', '%s', '%s', '%s')", $form_values["name"], $form_values["category"], $form_values["description"], $form_values["details"], $form_values["image"]); |
db_query("INSERT INTO {feature} (name, category, description, details, image) VALUES ('%s', '%s', '%s', '%s', '%s')", $values["name"], $values["category"], $values["description"], $values["details"], $values["image"]); |
| 203 |
} |
} |
| 204 |
|
|
| 205 |
drupal_set_message(t('The feature has been saved.')); |
drupal_set_message(t('The feature has been saved.')); |
| 209 |
function feature_admin_delete() { |
function feature_admin_delete() { |
| 210 |
$fid = (int)arg(3); |
$fid = (int)arg(3); |
| 211 |
if (feature_get($fid)) { |
if (feature_get($fid)) { |
| 212 |
return drupal_get_form('feature_admin_delete_confirm', $fid); |
return drupal_get_form('feature_admin_delete_confirm'); |
| 213 |
} |
} |
| 214 |
else { |
else { |
| 215 |
drupal_set_message(t('You requested to delete an invalid feature.')); |
drupal_set_message(t('You requested to delete an invalid feature.')); |
| 217 |
} |
} |
| 218 |
} |
} |
| 219 |
|
|
| 220 |
function feature_admin_delete_confirm($fid) { |
function feature_admin_delete_confirm() { |
| 221 |
|
$fid = (int)arg(3); |
| 222 |
$feature = feature_get($fid); |
$feature = feature_get($fid); |
| 223 |
$form['fid'] = array('#type' => 'value', '#value' => $fid); |
$form['fid'] = array( |
| 224 |
|
'#type' => 'value', |
| 225 |
|
'#value' => $fid, |
| 226 |
|
); |
| 227 |
return confirm_form( |
return confirm_form( |
| 228 |
$form, |
$form, |
| 229 |
t('Are you sure you want to delete feature %name?', array('%name' => $feature->name)), |
t('Are you sure you want to delete feature @name?', array('@name' => $feature->name)), |
| 230 |
'admin/feature', |
'admin/feature', |
| 231 |
t('This action cannot be undone.'), |
t('This action cannot be undone.'), |
| 232 |
t('Delete'), |
t('Delete'), |
| 234 |
} |
} |
| 235 |
|
|
| 236 |
function feature_admin_delete_confirm_submit($form_id, $form_values) { |
function feature_admin_delete_confirm_submit($form_id, $form_values) { |
| 237 |
db_query("DELETE FROM {feature} WHERE fid = %d", $form_values['fid']); |
db_query("DELETE FROM {feature} WHERE fid = %d", $form_values['values']['fid']); |
| 238 |
drupal_set_message(t('The feature has been deleted.')); |
drupal_set_message(t('The feature has been deleted.')); |
| 239 |
return 'admin/feature'; |
return 'admin/feature'; |
| 240 |
} |
} |
| 245 |
$result = db_query("SELECT * FROM {feature} ORDER BY name"); |
$result = db_query("SELECT * FROM {feature} ORDER BY name"); |
| 246 |
|
|
| 247 |
$header = array(t('Name'), t('Description'), t('Category'), t('Details'), t('Image'), array('data' => t('Operations'), 'colspan' => 2)); |
$header = array(t('Name'), t('Description'), t('Category'), t('Details'), t('Image'), array('data' => t('Operations'), 'colspan' => 2)); |
| 248 |
|
$rows = array(); |
| 249 |
|
|
| 250 |
while ($feature = db_fetch_object($result)) { |
while ($feature = db_fetch_object($result)) { |
| 251 |
$rows[] = array(check_plain($feature->name), |
$rows[] = array(check_plain($feature->name), |
| 252 |
check_plain($feature->description), |
check_plain($feature->description), |