| 1 |
<?php
|
| 2 |
// $Id: casetracker_admin.inc,v 1.1 2009/02/10 13:23:01 jmiccolis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Configures the various Case Tracker options; system_settings_form().
|
| 6 |
*/
|
| 7 |
function casetracker_settings() {
|
| 8 |
$form = array();
|
| 9 |
|
| 10 |
$form['casetracker_general'] = array(
|
| 11 |
'#type' => 'fieldset',
|
| 12 |
'#title' => t('General settings'),
|
| 13 |
'#collapsible' => TRUE,
|
| 14 |
'#collapsed' => FALSE,
|
| 15 |
);
|
| 16 |
$form['casetracker_general']['casetracker_default_assign_to'] = array(
|
| 17 |
'#type' => 'textfield',
|
| 18 |
'#title' => t('Default assigned user'),
|
| 19 |
'#autocomplete_path' => 'casetracker_autocomplete',
|
| 20 |
'#required' => TRUE,
|
| 21 |
'#default_value' => variable_get('casetracker_default_assign_to', variable_get('anonymous', t('Anonymous'))),
|
| 22 |
'#description' => t('User to be assigned the case if one is not explicitly defined.'),
|
| 23 |
);
|
| 24 |
|
| 25 |
foreach (array('priority', 'status', 'type') as $state) {
|
| 26 |
$options = casetracker_case_state_load($state);
|
| 27 |
$temp_keys = array_keys($options);
|
| 28 |
$form['casetracker_general']['casetracker_default_case_'. $state] = array(
|
| 29 |
'#type' => 'select',
|
| 30 |
'#options' => $options,
|
| 31 |
'#title' => t('Default case %state', array('%state' => $state)),
|
| 32 |
'#default_value' => variable_get('casetracker_default_case_'. $state, array_shift($temp_keys)),
|
| 33 |
'#description' => t('%state to be assigned the case if one is not explicitly defined.', array('%state' => ucfirst($state))),
|
| 34 |
);
|
| 35 |
};
|
| 36 |
|
| 37 |
$node_types = node_get_types('names');
|
| 38 |
|
| 39 |
$project_types = $node_types; unset($project_types['casetracker_basic_case']);
|
| 40 |
$form['casetracker_general']['casetracker_project_node_types'] = array(
|
| 41 |
'#type' => 'checkboxes',
|
| 42 |
'#title' => t('Project node types'),
|
| 43 |
'#options' => $project_types,
|
| 44 |
'#default_value' => variable_get('casetracker_project_node_types', array('casetracker_basic_project')),
|
| 45 |
'#description' => t('Select the node types that will be considered Case Tracker projects.'),
|
| 46 |
);
|
| 47 |
|
| 48 |
$case_types = $node_types; unset($case_types['casetracker_basic_project']);
|
| 49 |
$form['casetracker_general']['casetracker_case_node_types'] = array(
|
| 50 |
'#type' => 'checkboxes',
|
| 51 |
'#title' => t('Case node types'),
|
| 52 |
'#options' => $case_types,
|
| 53 |
'#default_value' => variable_get('casetracker_case_node_types', array('casetracker_basic_case')),
|
| 54 |
'#description' => t('Select the node types that will be considered Case Tracker cases.'),
|
| 55 |
);
|
| 56 |
|
| 57 |
return system_settings_form($form);
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Displays a form for adding or editing a case state.
|
| 62 |
*/
|
| 63 |
function casetracker_case_state_edit($form_state, $csid = NULL) {
|
| 64 |
$case_state = isset($csid) ? casetracker_case_state_load(NULL, $csid) : NULL;
|
| 65 |
|
| 66 |
$form = array();
|
| 67 |
$form['case_state'] = array(
|
| 68 |
'#type' => 'fieldset',
|
| 69 |
'#title' => t('Case state'),
|
| 70 |
'#collapsible' => TRUE,
|
| 71 |
'#collapsed' => FALSE,
|
| 72 |
);
|
| 73 |
$form['case_state']['name'] = array(
|
| 74 |
'#type' => 'textfield',
|
| 75 |
'#title' => t('State name'),
|
| 76 |
'#required' => TRUE,
|
| 77 |
'#default_value' => isset($case_state) ? $case_state['name'] : NULL,
|
| 78 |
'#description' => t('The name for this case state. Example: "Resolved".'),
|
| 79 |
);
|
| 80 |
$form['case_state']['realm'] = array(
|
| 81 |
'#type' => 'select',
|
| 82 |
'#title' => t('State realm'),
|
| 83 |
'#required' => TRUE,
|
| 84 |
'#default_value' => isset($case_state) ? $case_state['realm'] : NULL,
|
| 85 |
'#description' => t('The realm in which this case state will appear.'),
|
| 86 |
'#options' => array('priority' => t('priority'), 'status' => t('status'), 'type' => t('type')),
|
| 87 |
);
|
| 88 |
$form['case_state']['weight'] = array(
|
| 89 |
'#type' => 'weight',
|
| 90 |
'#title' => t('Weight'),
|
| 91 |
'#default_value' => isset($case_state) ? $case_state['weight'] : 0,
|
| 92 |
'#description' => t('States are ordered first by weight and then by state name.'),
|
| 93 |
);
|
| 94 |
|
| 95 |
if ($case_state) {
|
| 96 |
$form['csid'] = array(
|
| 97 |
'#type' => 'hidden',
|
| 98 |
'#default_value' => $csid,
|
| 99 |
);
|
| 100 |
}
|
| 101 |
$form['submit'] = array(
|
| 102 |
'#type' => 'submit',
|
| 103 |
'#value' => t('Submit'), // this text is an easter egg.
|
| 104 |
);
|
| 105 |
|
| 106 |
return $form;
|
| 107 |
}
|
| 108 |
|
| 109 |
/**
|
| 110 |
* Displays an administrative overview of all case states available.
|
| 111 |
*/
|
| 112 |
function casetracker_case_state_overview() {
|
| 113 |
$rows = array();
|
| 114 |
$headers = array(
|
| 115 |
t('Name'),
|
| 116 |
t('Realm'),
|
| 117 |
array(
|
| 118 |
'data' => t('Operations'),
|
| 119 |
'colspan' => 2)
|
| 120 |
);
|
| 121 |
foreach (array('priority', 'status', 'type') as $realm) {
|
| 122 |
foreach (casetracker_case_state_load($realm) as $csid => $name) {
|
| 123 |
$rows[] = array(
|
| 124 |
t($name),
|
| 125 |
$realm,
|
| 126 |
l(t('edit'), 'admin/settings/casetracker/states/edit/'. $csid),
|
| 127 |
l(t('delete'), 'admin/settings/casetracker/states/delete/'. $csid), );
|
| 128 |
}
|
| 129 |
}
|
| 130 |
|
| 131 |
return theme('table', $headers, $rows);
|
| 132 |
}
|
| 133 |
|
| 134 |
/**
|
| 135 |
* Processes the submitted results of our case state addition or editing.
|
| 136 |
*/
|
| 137 |
function casetracker_case_state_edit_submit($form, &$form_state) {
|
| 138 |
$case_state = array(
|
| 139 |
'name' => $form_state['values']['name'],
|
| 140 |
'realm' => $form_state['values']['realm'],
|
| 141 |
'weight' => $form_state['values']['weight'],
|
| 142 |
);
|
| 143 |
$case_state['csid'] = $form_state['values']['csid']
|
| 144 |
? $form_state['values']['csid'] :
|
| 145 |
NULL; // add or edit, eh?
|
| 146 |
casetracker_case_state_save($case_state);
|
| 147 |
drupal_set_message(
|
| 148 |
t(
|
| 149 |
'The case state %name has been updated.',
|
| 150 |
array('%name' => $form_state['values']['name'])
|
| 151 |
)
|
| 152 |
);
|
| 153 |
$form_state['redirect'] = 'admin/settings/casetracker/states';
|
| 154 |
}
|
| 155 |
|
| 156 |
/**
|
| 157 |
* If the user has asked to delete a case state, we'll double-check.
|
| 158 |
*/
|
| 159 |
function casetracker_case_state_confirm_delete($csid = NULL) {
|
| 160 |
$case_state = casetracker_case_state_load(NULL, $csid);
|
| 161 |
$form['csid'] = array('#type' => 'hidden', '#default_value' => $csid, );
|
| 162 |
$form['name'] = array('#type' => 'hidden', '#default_value' => $case_state['name'], );
|
| 163 |
return confirm_form($form, // NP: 'Eruyt Village' from 'Final Fantasy XII: Original Soundtrack Limited Edition'.
|
| 164 |
t('Are you sure you want to delete the case state %name?', array('%name' => $case_state['name'])),
|
| 165 |
'admin/settings/casetracker/states', t('This action can not be undone.'), t('Delete'), t('Cancel'));
|
| 166 |
}
|
| 167 |
|
| 168 |
/**
|
| 169 |
* Ayup, the user definitely wants to delete this case state.
|
| 170 |
*/
|
| 171 |
function casetracker_case_state_confirm_delete_submit($form, &$form_state) {
|
| 172 |
drupal_set_message(t('Deleted case state %name.', array('%name' => $form_state['values']['name'])));
|
| 173 |
casetracker_case_state_delete($form_state['values']['csid']);
|
| 174 |
return 'admin/settings/casetracker/states';
|
| 175 |
}
|