/[drupal]/contributions/modules/library/library.admin.inc
ViewVC logotype

Contents of /contributions/modules/library/library.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Mon Oct 13 16:43:38 2008 UTC (13 months, 1 week ago) by jastraat
Branch: MAIN
Changes since 1.4: +1 -1 lines
File MIME type: text/x-php
#319676 - Fix form naming mis-match
1 <?php
2 // $Id:
3
4 /**
5 * Menu callback: Edit Library Settings.
6 */
7 function library_admin_settings() {
8 $form = array();
9 $form['library_item_barcodes'] = array(
10 '#type' => 'checkbox',
11 '#title' => t('Use Barcodes/Unique Identifiers for Library Items'),
12 '#default_value' => variable_get('library_item_barcodes', 0),
13 '#return_value' => 1,
14 '#description' => t('This is recommended if you have multiple copies of an item. However, you must have unique identifiers for every instance. If you have multiple copies but do not use barcodes, library management will be against whether any copy is available and will not track any specific copy.'),
15 );
16 $form['library_unique_titles'] = array(
17 '#type' => 'checkbox',
18 '#title' => t('Check that Library Item Titles are Unique (Within a Given Content Type)'),
19 '#default_value' => variable_get('library_unique_titles', 0),
20 '#return_value' => 1,
21 '#description' => t('To display a warning if a title is a duplicate, check this box. This is highly recommended if you are not using barcodes.'),
22 );
23 $form['library_search_block'] = array(
24 '#type' => 'checkbox',
25 '#title' => t('Modify default search block to search library content.'),
26 '#default_value' => variable_get('library_search_block', 0),
27 '#return_value' => 1,
28 );
29 $form['library_status_display'] = array(
30 '#type' => 'checkbox',
31 '#title' => t('Library Status'),
32 '#default_value' => variable_get('library_status_display', 0),
33 '#return_value' => 1,
34 '#description' => t('To display library status on individual library nodes, check this box.'),
35 );
36
37 $form['library_action_display'] = array(
38 '#type' => 'fieldset',
39 '#title' => t('Action Links to Display'),
40 '#description' => t("Select which actions can be taken given a library item's status. If no actions are selected for a given status, no action links will be displayed on items with that status."),
41 );
42
43 $when_available = array();
44 $when_unavailable = array();
45 $when_reference = array();
46 foreach (library_actions() as $aid => $action) {
47 switch ($action['status_change']) {
48 case LIBRARY_ACTION_NO_CHANGE:
49 $when_available[$aid] = $action['name'];
50 $when_unavailable[$aid] = $action['name'];
51 $when_reference[$aid] = $action['name'];
52 break;
53 case LIBRARY_ACTION_TYPE_UNAVAILABLE:
54 $when_available[$aid] = $action['name'];
55 break;
56 case LIBRARY_ACTION_TYPE_AVAILABLE:
57 $when_unavailable[$aid] = $action['name'];
58 break;
59 }
60 }
61 $form['library_action_display']['library_links_display_available'] = array(
62 '#type' => 'checkboxes',
63 '#title' => t('On Available Items'),
64 '#default_value' => variable_get('library_links_display_available', array()),
65 '#options' => $when_available,
66 );
67 $form['library_action_display']['library_links_display_unavailable'] = array(
68 '#type' => 'checkboxes',
69 '#title' => t('On Unavailable Items'),
70 '#default_value' => variable_get('library_links_display_unavailable', array()),
71 '#options' => $when_unavailable,
72 );
73 $form['library_action_display']['library_links_display_reference'] = array(
74 '#type' => 'checkboxes',
75 '#title' => t('On Reference Only Items'),
76 '#default_value' => variable_get('library_links_display_reference', array()),
77 '#options' => $when_reference,
78 );
79
80 $form['library_item_list_display'] = array(
81 '#type' => 'fieldset',
82 '#title' => t('Library Search Results Display'),
83 '#description' => t('The columns chosen below will be added to the node fields that you have selected to display.'),
84 );
85 $form['library_item_list_display']['library_quantity_display'] = array(
86 '#type' => 'checkbox',
87 '#title' => t('Quantity'),
88 '#default_value' => variable_get('library_quantity_display', 0),
89 );
90 $form['library_item_list_display']['library_list_status_display'] = array(
91 '#type' => 'checkbox',
92 '#title' => t('Status'),
93 '#default_value' => variable_get('library_list_status_display', 0),
94 );
95 if (module_exists('taxonomy')) {
96 $vocabularies = array();
97 foreach (taxonomy_get_vocabularies() as $vid => $vocab) {
98 $vocabularies[$vid] = $vocab->name;
99 }
100 $form['library_item_list_display']['library_taxonomy_display'] = array(
101 '#type' => 'checkboxes',
102 '#title' => t('Display Associated Taxonomy Terms in Library View'),
103 '#default_value' => variable_get('library_taxonomy_display', array()),
104 '#options' => $vocabularies,
105 '#description' => t('Select the vocabularies from which you would like to display taxonomy terms. If no vocabularies are selected, terms will not be displayed.'),
106 );
107 }
108 $form['library_text_display'] = array(
109 '#type' => 'fieldset',
110 '#title' => t('Library Text'),
111 '#description' => t('Customize the text display.'),
112 );
113 $form['library_text_display']['library_available_text'] = array(
114 '#type' => 'textfield',
115 '#title' => t('Available Status Text'),
116 '#default_value' => variable_get('library_available_text', 'AVAILABLE'),
117 '#size' => 20,
118 '#maxlength' => 20,
119 '#description' => t("Examples: in, checked in"),
120 );
121 $form['library_text_display']['library_unavailable_noduedates_text'] = array(
122 '#type' => 'textfield',
123 '#title' => t('Unavailable Status Text (Without Due Dates)'),
124 '#default_value' => variable_get('library_unavailable_noduedates_text', 'UNAVAILABLE'),
125 '#size' => 20,
126 '#maxlength' => 20,
127 '#description' => t("Examples: out, checked out"),
128 );
129 $form['library_text_display']['library_reference_only_text'] = array(
130 '#type' => 'textfield',
131 '#title' => t('Reference Only Status Text'),
132 '#default_value' => variable_get('library_reference_only_text', 'REFERENCE ONLY'),
133 '#size' => 20,
134 '#maxlength' => 20,
135 );
136 return system_settings_form($form);
137 }
138
139
140 /**
141 * Menu callback: Edit Library Overdue Settings.
142 */
143 function library_admin_settings_overdue() {
144 $form = array();
145 foreach (library_get_item_types() as $type) {
146 foreach (library_actions() as $aid => $action) {
147 if ($action['status_change'] == LIBRARY_ACTION_TYPE_UNAVAILABLE) {
148 $clean = library_clean_action_name($action['name']);
149 $input_name = 'library_period_for_'. $type .'_'. $clean;
150 $form[$input_name] = array(
151 '#type' => 'fieldset',
152 '#title' => t($type .' '. $action['name'] .' Period'),
153 '#description' => t('The maximum time a patron may %action a %type . Days and hours are combined into one value. Enter a whole number greater than 0 in days or hours if you want to have duedates for this item type with this action.', array('%type' => $type, '%action' => $action['name'])),
154 '#attributes' => array('class' => 'check-out-period-fieldset'),
155 );
156 $input_name_days = 'library_days_for_'. $type .'_'. $clean;
157 $form[$input_name][$input_name_days] = array(
158 '#type' => 'textfield',
159 '#title' => t('Days'),
160 '#default_value' => variable_get(''. $input_name_days, 0),
161 '#size' => 3,
162 '#maxlength' => 3,
163 );
164 $input_name_hours = 'library_hours_for_'. $type .'_'. $clean;
165 $form[$input_name][$input_name_hours] = array(
166 '#type' => 'textfield',
167 '#title' => t('Hours'),
168 '#default_value' => variable_get(''. $input_name_hours, 0),
169 '#size' => 3,
170 '#maxlength' => 3,
171 );
172 }
173 }
174 }
175 $form['library_send_automatic_email'] = array(
176 '#type' => 'checkbox',
177 '#title' => t('Send Automatic Overdue Reminder Emails'),
178 '#default_value' => variable_get('library_send_automatic_email', 0),
179 '#description' => t('If this option is checked and due dates are enabled, Drupal will send a reminder email to each patron with overdue items the day after an item becomes overdue.'),
180 '#return_value' => 1,
181 );
182 // Patron e-mail settings.
183 $form['email'] = array(
184 '#type' => 'fieldset',
185 '#title' => t('Patron Overdue Items Notification e-mail'),
186 '#description' => t('Customize email sent to library patrons with overdue items. Available variables are: !patronname, !site, and !items.'),
187 );
188 $form['email']['library_mail_notify_overdue_subject'] = array(
189 '#type' => 'textfield',
190 '#title' => t('Subject'),
191 '#default_value' => _library_mail_text('notify_overdue_subject'),
192 '#maxlength' => 180,
193 );
194 $form['email']['library_mail_notify_overdue_body'] = array(
195 '#type' => 'textarea',
196 '#title' => t('Body'),
197 '#default_value' => _library_mail_text('notify_overdue_body'),
198 '#rows' => 15,
199 );
200
201 return system_settings_form($form);
202 }
203
204 function library_admin_settings_overdue_validate($form, &$form_state) {
205 foreach (library_get_item_types() as $type) {
206 $duedates_enabled = 0;
207 foreach (library_actions() as $aid => $action) {
208 if ($action['status_change'] == LIBRARY_ACTION_TYPE_UNAVAILABLE) {
209 $clean = library_clean_action_name($action['name']);
210 $input_name_days = 'library_days_for_'. $type .'_'. $clean;
211 $input_name_hours = 'library_hours_for_'. $type .'_'. $clean;
212 if (!is_numeric($form_state['values'][$input_name_days])) {
213 form_set_error($input_name_days, t('Days must be a number.'));
214 }
215 if (!is_numeric($form_state['values'][$input_name_hours])) {
216 form_set_error($input_name_hours, t('Hours must be a number.'));
217 }
218 $day_sec = $form_state['values'][$input_name_days] * 24 * 60 * 60;
219 $hour_sec = $form_state['values'][$input_name_hours] * 60 * 60;
220 $total = $day_sec + $hour_sec;
221 if ($total > 0) {
222 $duedates_enabled = 1;
223 }
224 variable_set('library_period_for_'. $type .'_'. $clean, $total);
225 }
226 }
227 variable_set('library_'. $type .'_due_dates', $duedates_enabled);
228 }
229 }
230
231 /**
232 * Menu callback: Edit Library Action.
233 *
234 * @see library_admin_action_validate()
235 * @see library_admin_action_submit()
236 * @see theme_library_admin_new_action()
237 */
238 function library_admin_action() {
239 $aid = arg(5);
240 if ($aid) {
241 // Display the edit action form.
242 $action = library_get_action($aid);
243 $show_delete = TRUE;
244 if ($action && ($action->status_change > 0)) {
245 $result = db_result(db_query("SELECT COUNT(*) FROM {library_actions} WHERE status_change = '%d' AND aid <> %d", $action->status_change, $action->aid));
246 if ($result) {
247 }
248 else {
249 $show_delete = FALSE;
250 }
251 }
252
253 $form['name'] = array(
254 '#type' => 'textfield',
255 '#title' => t('Action name'),
256 '#default_value' => $action->name,
257 '#size' => 20,
258 '#required' => TRUE,
259 '#maxlength' => 60,
260 '#description' => t('The name for this action.'),
261 );
262 $form['status_change'] = array(
263 '#type' => 'radios',
264 '#title' => t('Status Change'),
265 '#description' => t('How this action changes the status of a library item.'),
266 '#default_value' => isset($action->status_change) ? $action->status_change : 0,
267 '#options' => array(LIBRARY_ACTION_NO_CHANGE => t('No Change'), LIBRARY_ACTION_TYPE_UNAVAILABLE => t('Unavailable'), LIBRARY_ACTION_TYPE_AVAILABLE => t('Available'))
268 );
269 $form['aid'] = array(
270 '#type' => 'value',
271 '#value' => $aid,
272 );
273 $form['submit'] = array(
274 '#type' => 'submit',
275 '#value' => t('Save action'),
276 );
277 if ($show_delete) {
278 $form['delete'] = array(
279 '#type' => 'submit',
280 '#value' => t('Delete action'),
281 );
282 }
283 }
284 else {
285 $form['name'] = array(
286 '#type' => 'textfield',
287 '#size' => 20,
288 '#maxlength' => 60,
289 );
290 $form['status_change'] = array(
291 '#type' => 'radios',
292 '#default_value' => 0,
293 '#options' => array(LIBRARY_ACTION_NO_CHANGE => t('No Change'), LIBRARY_ACTION_TYPE_UNAVAILABLE => t('Unavailable'), LIBRARY_ACTION_TYPE_AVAILABLE => t('Available'))
294 );
295 $form['submit'] = array(
296 '#type' => 'submit',
297 '#value' => t('Add action'),
298 );
299 $form['#submit'][] = 'library_admin_action_submit';
300 $form['#validate'][] = 'library_admin_action_validate';
301 }
302 return $form;
303 }
304
305 /**
306 * Menu callback: Edit Library Action.
307 *
308 * @see library_admin_action()
309 * @see library_admin_action_submit()
310 * @see theme_library_admin_new_action()
311 */
312 function library_admin_action_validate($form, &$form_state) {
313 if ($form_state['values']['name']) {
314 if ($form_state['values']['op'] == t('Save action')) {
315 if (db_result(db_query("SELECT COUNT(*) FROM {library_actions} WHERE name = '%s' AND aid <> %d", $form_state['values']['name'], $form_state['values']['aid']))) {
316 form_set_error('name', t('The action name %name already exists. Please choose another action name.', array('%name' => $form_state['values']['name'])));
317 }
318 }
319 else if ($form_state['values']['op'] == t('Add action')) {
320 if (db_result(db_query("SELECT COUNT(*) FROM {library_actions} WHERE name = '%s'", $form_state['values']['name']))) {
321 form_set_error('name', t('The action name %name already exists. Please choose another action name.', array('%name' => $form_state['values']['name'])));
322 }
323 }
324 }
325 else {
326 form_set_error('name', t('You must specify a valid action name.'));
327 }
328 }
329
330 /**
331 * Menu callback: Edit Library Action.
332 *
333 * @see library_admin_action()
334 * @see library_admin_action_validate()
335 * @see theme_library_admin_new_action()
336 */
337 function library_admin_action_submit($form, &$form_state) {
338 if ($form_state['values']['op'] == t('Save action')) {
339 db_query("UPDATE {library_actions} SET name = '%s', status_change = %d WHERE aid = %d", check_plain($form_state['values']['name']), $form_state['values']['status_change'], $form_state['values']['aid']);
340 drupal_set_message(t('The action has been renamed.'));
341 }
342 else if ($form_state['values']['op'] == t('Delete action')) {
343 db_query('DELETE FROM {library_actions} WHERE aid = %d', $form_state['values']['aid']);
344 db_query('DELETE FROM {library_transactions} WHERE action_aid = %d', $form_state['values']['aid']);
345 $available_display = variable_get('library_links_display_available', array());
346 $unavailable_display = variable_get('library_links_display_unavailable', array());
347 $reference_display = variable_get('library_links_display_reference', array());
348 $key = array_search($form_state['values']['aid'], $available_display);
349 if ($key !== FALSE) {
350 unset($available_display[$key]);
351 variable_set('library_links_display_available', $available_display);
352 }
353 $key2 = array_search($form_state['values']['aid'], $unavailable_display);
354 if ($key2 !== FALSE) {
355 unset($unavailable_display[$key2]);
356 variable_set('library_links_display_unavailable', $unavailable_display);
357 }
358 $key3 = array_search($form_state['values']['aid'], $reference_display);
359 if ($key3 !== FALSE) {
360 unset($reference_display[$key3]);
361 variable_set('library_links_display_reference', $reference_display);
362 }
363 drupal_set_message(t('The action has been deleted.'));
364 }
365 else if ($form_state['values']['op'] == t('Add action')) {
366 db_query("INSERT INTO {library_actions} (name, status_change) VALUES ('%s', %d)", check_plain($form_state['values']['name']), $form_state['values']['status_change']);
367 drupal_set_message(t('The action has been added.'));
368 }
369 $form_state['redirect'] = 'admin/settings/library/actions';
370 return;
371 }
372
373 /**
374 * Retrieve a pipe delimited string of autocomplete suggestions for library items
375 */
376 function library_autocomplete($string) {
377 $matches = array();
378 if (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES) {
379 $result = db_query_range("SELECT l.id, l.barcode, n.title FROM {node} n INNER JOIN {library} l ON n.nid = l.nid WHERE n.status = 1 AND n.type <> 'patron' AND l.barcode <> '' AND LOWER(l.barcode) LIKE LOWER('%s%%')", check_plain($string), 0, 10);
380 while ($item = db_fetch_object($result)) {
381 $matches[$item->barcode .' [title:'. $item->title .'] [id:'. $item->id .']'] = check_plain($item->barcode);
382 }
383 }
384 else {
385 $result = db_query_range("SELECT DISTINCT l.id, n.title FROM {node} n INNER JOIN {library} l ON n.nid = l.nid WHERE n.status = 1 AND n.type <> 'patron' AND LOWER(n.title) LIKE LOWER('%s%%')", check_plain($string), 0, 10);
386 while ($item = db_fetch_object($result)) {
387 $my_key = $item->title .' [id:'. $item->id .']';
388 $matches[$my_key] = check_plain($my_key);
389 }
390 }
391 print drupal_to_js($matches);
392 exit();
393 }
394
395 /*
396 * Send email to patrons with overdue items
397 */
398 function library_notify_overdue() {
399 if (library_duedates_enabled()) {
400 $records = library_get_overdue_items();
401 if (empty($records)) {
402 drupal_set_message(t('No patrons with overdue items at this time.'));
403 }
404 else {
405 $num_emails = 0;
406 foreach ($records as $patron_id => $record) {
407 $params = $record;
408 drupal_mail('library', 'notify_overdue', $params['patron']['patron_email'], language_default(), $params);
409 $num_emails++;
410 }
411 drupal_set_message(t($num_emails .' email(s) sent successfully.'));
412 watchdog('library', '%number overdue email notifications sent successfully.', array('%number' => $num_emails));
413 }
414 }
415 else {
416 drupal_set_message(t('Library due dates are not enabled.'));
417 }
418 drupal_goto('library-items/overdue');
419 }

  ViewVC Help
Powered by ViewVC 1.1.2