Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 708 lines (638 sloc) 28.817 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
<?php
/**
* SOPAC is The Social OPAC: a Drupal module that serves as a wholly integrated web OPAC for the Drupal CMS
* This file contains the Drupal include functions for all the SOPAC admin pieces and configuration options
* This file is called via hook_menu
*
* @package SOPAC
* @version 2.1
* @author John Blyberg
*/


/**
* Sets up administrative options for SOPAC and returns a systems settings form
*
* @return string Settings form HTML
*/
function sopac_admin() {
  $form = array();
  $current_ils = variable_get('sopac_ils', FALSE);

  if (!$current_ils) {
    $form['starter_instruction'] = array(
      '#type' => 'markup',
      '#value' => 'Please select your ILS, then submit this form to continue setup.',
    );
  }

  $form['sopac_general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['sopac_general']['sopac_ils'] = array(
    '#type' => 'select',
    '#title' => t('Your ILS name'),
    '#default_value' => variable_get('sopac_ils', 'iii'),
    '#options' => array('iii' => 'iii', 'koha' => 'koha', 'sirsi' => 'sirsi'),
    '#required' => TRUE,
  );

  // Start admin with only choice of ILS.
  if (!$current_ils) {
    $form['sopac_general']['#collapsed'] = FALSE;
    // This will call sopac_admin_submit() to clear menu cache
    $form = system_settings_form($form);
    $form['#submit'][] = 'sopac_admin_submit';
    return $form;
  }

  $form['sopac_general']['sopac_lib_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your Institution\'s name'),
    '#default_value' => variable_get('sopac_lib_name', 'Anytown Public Library'),
    '#size' => 32,
    '#maxlength' => 254,
    '#description' => t("The name of your library or institution."),
    '#required' => TRUE,
  );

  $locum_path = trim(variable_get('sopac_locum_path', '/usr/local/include/locum'));
  if ($locum_path[0] != '/') {
    $locum_path = '/' . $locum_path;
  }
  if (substr($locum_path, -1) != '/') {
    $locum_path .= '/';
  }
  if (!file_exists($locum_path . 'locum-client.php')) {
    $locum_error = '<br /><span style="color: red;">NOTE: ' . $locum_path . 'locum-client.php does not seem to exist!</span>' ;
  }
  $form['sopac_general']['sopac_locum_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to the Locum Client Library'),
    '#default_value' => variable_get('sopac_locum_path', '/usr/local/include/locum'),
    '#size' => 32,
    '#maxlength' => 128,
    '#description' => t("The path to where you have installed Locum." . $locum_error),
    '#required' => TRUE,
  );

  $insurge_path = trim(variable_get('sopac_insurge_path', '/usr/local/include/insurge'));
  if ($insurge_path[0] != '/') {
    $insurge_path = '/' . $insurge_path;
  }
  if (substr($insurge_path, -1) != '/') {
    $insurge_path .= '/';
  }
  if (!file_exists($insurge_path . 'insurge-client.php')) {
    $insurge_error = '<br /><span style="color: red;">NOTE: ' . $insurge_path . 'insurge-client.php does not seem to exist!</span>' ;
  }
  $form['sopac_general']['sopac_insurge_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to the Insurge Client Library'),
    '#default_value' => variable_get('sopac_insurge_path', '/usr/local/include/insurge'),
    '#size' => 32,
    '#maxlength' => 128,
    '#description' => t("The path to where you have installed Insurge." . $insurge_error),
    '#required' => TRUE,
  );

  $form['sopac_general']['sopac_url_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('SOPAC URL prefix'),
    '#default_value' => variable_get('sopac_url_prefix', 'cat/seek'),
    '#size' => 24,
    '#maxlength' => 72,
    '#description' => t("This is the URL prefix you wish SOPAC to use within the site, for example, to use www.yoursite.com/cat/seek as the base URL for SOPAC, enter 'cat/seek' without the leading or trailing slash. If you change this, you will likely need to clear your site cache in your ") . l(t('performance settings'), 'admin/settings/performance'),
    '#required' => TRUE,
  );

  $form['sopac_general']['sopac_results_per_page'] = array(
    '#type' => 'textfield',
    '#title' => t('Max # of results per page'),
    '#default_value' => variable_get('sopac_results_per_page', 20),
    '#size' => 10,
    '#maxlength' => 4,
    '#description' => t("This is the maxumum number of results that will be displayed per page in the catalog hit-list."),
    '#required' => TRUE,
  );

  $form['sopac_general']['sopac_search_form_cfg'] = array(
    '#type' => 'select',
    '#title' => t('Default Search Form Display'),
    '#default_value' => variable_get('sopac_search_form_cfg', 'both'),
    '#description' => t("This option allows you to configure how you want the search form to be displayed from within the SOPAC context. You can Display Just the basic search box, or the basic search box and the advanced search form drop-down option."),
    '#options' => array('basic' => t('Display just the basic form'), 'both' => t('Display both basic and advanced forms'))
  );

  $form['sopac_general']['sopac_multi_branch_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Multi-Branch Support'),
    '#default_value' => variable_get('sopac_multi_branch_enable', 0),
    '#description' => t('Select this option if you plan to operate SOPAC in a multi-branch environment.'),
  );

  // the next two settings to support giving users ability to select a home branch
  $description = t('Check this box if your library has multiple branches, and you would like each user to be able to select a home branch.');
  $description .= t('<br />NOTE: this feature requires that branches are set up in the locum config.');
  $description .= t('<br />NOTE: the user option will be set up during the first cron job after checking this box.');

  $form['sopac_general']['sopac_home_branch_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow Users to Select a Home Branch'),
    '#default_value' => variable_get('sopac_home_branch_enable', 0),
    '#description' => $description,
  );

  $form['sopac_general']['sopac_ssl_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable SSL for Account Management'),
    '#default_value' => variable_get('sopac_ssl_enable', 0),
    '#description' => t("Selecting this option will cause SOPAC to redirect browsers to an encrypted page if the user is accesing their personal information. You will need to have SSL enabled on your web server. This is HIGHLY RECCOMENDED. If you enable this option, you must put the following setting in your Apache vhost configuration for this site's <VirtualHost *:443> section: SetEnv HTTPS TRUE"),
  );

  $form['sopac_general']['sopac_ssl_port'] = array(
    '#type' => 'textfield',
    '#title' => t('SSL Connection Port'),
    '#default_value' => variable_get('sopac_ssl_port', 443),
    '#size' => 6,
    '#maxlength' => 4,
    '#description' => t("This is the port that your Apache SSL process is listening on."),
    '#required' => TRUE,
  );

  $form['sopac_general']['sopac_catalog_disabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable Catalog'),
    '#default_value' => variable_get('sopac_catalog_disabled', 0),
    '#description' => t("Selecting this option will disable Requests and the My Account information provided by the catalog. Searches and Social functions will still work."),
  );

  $form['sopac_general']['sopac_catalog_disabled_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Catalog Disabled Message'),
    '#default_value' => variable_get('sopac_catalog_disabled_message', 'Catalog access is currently disabled'),
    '#description' => t("This is the message displayed on the My Account page and as a tool tip on Request buttons when catalog is disabled"),
    '#required' => TRUE,
  );

  $form['sopac_fines'] = array(
    '#type' => 'fieldset',
    '#title' => t('Fines Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['sopac_fines']['sopac_fines_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Fines Management'),
    '#default_value' => variable_get('sopac_fines_enable', 1),
    '#description' => t("Check this box to allow users to access their fines through SOPAC."),
  );

  $form['sopac_fines']['sopac_payments_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Payments Management'),
    '#default_value' => variable_get('sopac_payments_enable', 1),
    '#description' => t("Check this box to allow users to pay their fines through SOPAC."),
  );

  $form['sopac_fines']['sopac_fines_warning_amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Fine Warning Amount'),
    '#default_value' => variable_get('sopac_fines_warning_amount', ''),
    '#size' => 60,
    '#maxlength' => 128,
    '#description' => t("Warning will appear on the My Account page if fines are equal to or greater than this amount"),
  );

  $form['sopac_social_features'] = array(
    '#type' => 'fieldset',
    '#title' => t('Social Feature Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // This really isn't implemented yet and is here are a reminder
  $form['sopac_social_features']['sopac_social_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable the Social Catalog Components'),
    '#default_value' => variable_get('sopac_social_enable', 1),
    '#description' => t("Check this box if you would like to enable community-driven reviews, ratings, comments, and tagging in the catalog."),
  );

  $form['sopac_social_features']['sopac_random_tags'] = array(
    '#type' => 'checkbox',
    '#title' => t('Random Tags'),
    '#default_value' => variable_get('sopac_random_tags', 1),
    '#description' => t("Check this box if you would like to display tags in random order."),
  );

  $form['sopac_social_features']['sopac_tag_limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Tag Limit'),
    '#default_value' => variable_get('sopac_tag_limit', 100),
    '#size' => 6,
    '#maxlength' => 5,
    '#description' => t("This is the maximum number of tags to display in the tag cloud."),
  );

  $form['sopac_social_features']['sopac_tag_sort'] = array(
    '#type' => 'select',
    '#title' => t('Tag Cloud Sorting'),
    '#default_value' => variable_get('sopac_tag_sort', 'ORDER BY count DESC'),
    '#description' => t("How to sort tags in tag cloud if Random Tags is not checked."),
    '#options' => array(
      'ORDER BY count ASC' => t('By count, ascending'),
      'ORDER BY count DESC' => t('By count, descending'),
      'ORDER BY tag ASC' => t('Alphabeticaly, ascending'),
      'ORDER BY tag DESC' => t('Alphabeticaly, descending'),
    ),
  );

  $form['sopac_social_features']['sopac_lists_staff_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Lists Staff Roles'),
    '#default_value' => variable_get('sopac_lists_staff_roles', array()),
    '#options' => user_roles(TRUE),
    '#description' => "Select which roles will be marked as STAFF on public list display",
  );

  $form['sopac_account'] = array(
    '#type' => 'fieldset',
    '#title' => t('Account Page Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['sopac_account']['sopac_summary_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable the Account Summary on the Account page'),
    '#default_value' => variable_get('sopac_summary_enable', 1),
    '#description' => t("Check this box if you would like to enable the Account Summary on the Account page. You probably want this."),
  );

  $form['sopac_account']['sopac_pname_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display Patron Name in the Account Summary'),
    '#default_value' => variable_get('sopac_pname_enable', 1),
    '#description' => t("Check this box if you would like to have patron names appear in the Account Summary."),
  );

  $form['sopac_account']['sopac_lcard_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display Library Card Number in the Account Summary'),
    '#default_value' => variable_get('sopac_lcard_enable', 1),
    '#description' => t("Check this box if you would like to have library card numbers appear in the Account Summary."),
  );

  $form['sopac_account']['sopac_numco_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display # of checkouts in the Account Summary'),
    '#default_value' => variable_get('sopac_numco_enable', 1),
    '#description' => t("Check this box if you would like # of checkouts appear in the Account Summary."),
  );

  $form['sopac_account']['sopac_checkout_history_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display checkout history in the user area'),
    '#default_value' => variable_get('sopac_checkout_history_enable', 0),
    '#description' => t("Check this box if you would like checkout history to appear in the user area."),
  );

  $form['sopac_account']['sopac_checkout_history_wipe'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete checkout history from ILS after harvest'),
    '#default_value' => variable_get('sopac_checkout_history_wipe', 1),
    '#description' => t("Check this box if you would like to purge checkout history from the ILS after it's imported into SOPAC."),
  );

  $form['sopac_account']['sopac_checkout_history_cache_time'] = array(
    '#type' => 'textfield',
    '#title' => t('Checkout history cache time'),
    '#default_value' => variable_get('sopac_checkout_history_cache_time', 60),
    '#description' => t("How many minutes should SOPAC wait before checking the ILS for checkout history again?"),
    '#size' => 6,
    '#maxlength' => 5,
  );

  $form['sopac_account']['sopac_hold_freezes_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable freezing holds'),
    '#default_value' => variable_get('sopac_hold_freezes_enable', 1),
    '#description' => t("Check this box if you would like users to be able to freeze holds."),
  );
  if (variable_get('sopac_fines_enable', 1)) {
    $form['sopac_account']['sopac_fines_display'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display Fine Amounts in the Account Summary'),
      '#default_value' => variable_get('sopac_fines_display', 1),
      '#description' => t("Check this box if you would like fine amounts to appear in the Account Summary."),
    );
  }

  $form['sopac_account']['sopac_cardexp_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display Library Card Expiration Date in the Account Summary'),
    '#default_value' => variable_get('sopac_cardexp_enable', 1),
    '#description' => t("Check this box if you would like to have library card expiration dates appear in the Account Summary."),
  );

  $form['sopac_account']['sopac_tel_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display telephone # in the Account Summary'),
    '#default_value' => variable_get('sopac_tel_enable', 1),
    '#description' => t("Check this box if you would like the patron telephone # to appear in the Account Summary."),
  );

  $form['sopac_account']['sopac_email_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display Email Address in the Account Summary'),
    '#default_value' => variable_get('sopac_email_enable', 1),
    '#description' => t("Check this box if you would like the patron email address to appear in the Account Summary."),
  );

  $form['sopac_account']['sopac_invalid_cardnum'] = array(
    '#type' => 'textarea',
    '#title' => t('Invalid Library Card Message'),
    '#default_value' => variable_get('sopac_invalid_cardnum', 'It appears that your card number is invalid. If you feel that this is in error, please contact us.'),
    '#description' => t("This is the message that is displayed to users if they have entered an invalid library card number. HTML is OK."),
    '#required' => TRUE,
  );

  $form['sopac_cardnum_verify'] = array(
    '#type' => 'fieldset',
    '#title' => t('Card Number Verification Requirements'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['sopac_cardnum_verify']['sopac_require_cfg'] = array(
    '#type' => 'select',
    '#title' => t('Require Patrons to Meet All or One of the Requirements'),
    '#default_value' => variable_get('sopac_require_cfg', 'one'),
    '#description' => t("This option allows you to tell SOPAC if you would like to require users to fulfill all of the following enabled requirements, or just one. For example, if this is set to just 'One', users would have to enter one correct value instead of all corect values in order to have their library card verified."),
    '#options' => array('one' => t('Just One'), 'all' => t('All Requirements'))
  );

  $form['sopac_cardnum_verify']['sopac_require_name'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require Patron name for Verification'),
    '#default_value' => variable_get('sopac_require_name', 1),
    '#description' => t("Check this box if you would like to require the patron to type in their name in order to verify their library card number."),
  );

  $form['sopac_cardnum_verify']['sopac_require_tel'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require Telephone Number for Verification'),
    '#default_value' => variable_get('sopac_require_tel', 1),
    '#description' => t("Check this box if you would like to require the patron to type in their telephone number in order to verify their library card number."),
  );

  $form['sopac_cardnum_verify']['sopac_require_streetname'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Address Street Name for Verification'),
    '#default_value' => variable_get('sopac_require_streetname', 1),
    '#description' => t("Check this box if you would like to use the street name of the patron's address to verify their library card number."),
  );

  $form['sopac_cardnum_verify']['sopac_uv_cardnum'] = array(
    '#type' => 'textarea',
    '#title' => t('Unvalidated Library Card Message'),
    '#default_value' => variable_get('sopac_uv_cardnum', 'The card number you have provided has not yet been verified by you. In order to make sure that you are the rightful owner of this library card number, we need to ask you some simple questions.'),
    '#description' => t("This is the message that is displayed to users on their account page if they have not yet verified their library card number. HTML is OK."),
    '#required' => TRUE,
  );

  if ($current_ils == 'sirsi') {
    $form['core']['sopac_changeable_pickup_location'] = array(
      '#type' => 'hidden',
      '#value' => TRUE,
    );

    $form['core']['sopac_suspend_holds'] = array(
      '#type' => 'hidden',
      '#value' => TRUE,
    );
  }
  else {
    $form['core']['sopac_changeable_pickup_location'] = array(
      '#type' => 'hidden',
      '#value' => FALSE,
    );

    $form['core']['sopac_suspend_holds'] = array(
      '#type' => 'hidden',
      '#value' => FALSE,
    );
  }

  // This will call sopac_admin_submit() to clear menu cache
  $form = system_settings_form($form);
  $form['#submit'][] = 'sopac_admin_submit';

  // Return the SOPAC configuration form
  return $form;

}

// Part of supporting user home branch in multibranch situation
function sopac_setup_user_home_selector() {
  if (!variable_get('sopac_home_branch_enable', 0) || variable_get('sopac_home_selector_options', FALSE)) {
    return FALSE;
  }
  $locum = sopac_get_locum();
  $branches = $locum->locum_config['branches'];
  if (!(is_array($branches) && count($branches))) {
    return FALSE;
  }
  $options = array_values($branches);
  $options = join("\n\r", $options);
  $description = t('Choose a branch as your home. This will be the default pickup location when you place holds.');
  $result = db_query("
INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page)
VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')",
    'Home Branch', 'profile_pref_home_branch', $description, 'Preferences', 'selection', 1, 0, 1, 1, 0, $options, ''
  );
  if ($result) {
    variable_set('sopac_home_selector_options', TRUE);
    return TRUE;
  }
  return FALSE;
}

// Rebuild menu cache
function sopac_admin_submit($form, &$form_state) {
  menu_rebuild();
}

function sopac_admin_moderate_form($form_state, $type = 'reviews', $offset = 0) {
  include_once('sopac_catalog.php');
  $insurge = sopac_get_insurge();
  $locum = sopac_get_locum();
  $limit = 100; // per page

  if ($form_state['storage']['confirm_ids']) {
    // CONFIRM FORM
    $confirm_ids = $form_state['storage']['confirm_ids'];
    $form['confirm_message'] = array(
      '#prefix' => '<h2>Are you sure you want to delete these ' . $type . '?</h2><ul>',
      '#suffix' => '</ul>',
      '#tree' => TRUE,
    );

    if ($type == 'reviews') {
      $reviews = $insurge->get_reviews(NULL, NULL, $confirm_ids, $limit);
      $form['reviews'] = array(
        '#type' => 'value',
        '#value' => $reviews['reviews'],
      );
      foreach ($reviews['reviews'] as $review) {
        $form['confirm_message'][] = array(
          '#value' => '<li>'. check_plain($review['rev_title']) . "</li>\n",
        );
      }
    }
    else if ($type == 'tags') {
      $tags = array();
      foreach ($confirm_ids as $tag_id) {
        $tag = $insurge->get_tag($tag_id);
        $tags[] = $tag;
        $form['confirm_message'][] = array(
          '#value' => '<li>'. check_plain($tag['tag']) . "</li>\n",
        );
      }
      $form['tags'] = array(
        '#type' => 'value',
        '#value' => $tags,
      );
    }

    $form['operation'] = array(
      '#type' => 'hidden',
      '#value' => 'delete',
    );
    $form['#submit'][] = 'sopac_admin_moderate_delete_confirm_submit';
    return confirm_form($form,
                        t('Are you sure you want to delete these ' . $type . '?'),
                        'admin/settings/sopac/moderate/' . $type, t('This action cannot be undone.'),
                        t('Delete all'), t('Cancel'));
  }
  else {
    // REVIEW FORM
    if ($type == 'reviews') {
      $reviews = $insurge->get_reviews(NULL, NULL, NULL, $limit, intval($offset));

      $checkboxes = array();
      $form = array();
      foreach ($reviews['reviews'] as $review) {
        $bib = $locum->get_bib_item($review['bnum'], TRUE);

        // Hover text for the bib
        $hover = $bib['title'] . "\n" .
                 $bib['callnum'] . "\n" .
                 $bib['pub_info'] . "\n" .
                 $bib['descr'];

        $checkboxes[$review['rev_id']] = '';
        $account = user_load(array('uid' => $review['uid']));
        $form[$review['rev_id']] = array(
          'user' => array('#value' => l($account->name, 'user/' . $account->uid)),
          'bnum' => array('#value' => l($bib['title'], 'catalog/record/' . $review['bnum'], array('attributes' => array('title' => $hover)))),
          'title' => array('#value' => $review['rev_title']),
          'body' => array('#value' => $review['rev_body']),
          'created' => array('#value' => date("F j, Y, g:i a", $review['rev_create_date'])),
          'update' => array('#value' => date("F j, Y, g:i a", $review['rev_last_update'])),
        );
      }
      $form['checkboxes'] = array(
        '#type' => 'checkboxes',
        '#options' => $checkboxes,
      );
      $form['operation'] = array(
        '#type' => 'hidden',
        '#value' => 'delete',
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Delete Selected Reviews'),
      );
      $form['next'] = array(
        '#value' => '<p>' . l('NEXT PAGE', 'admin/settings/sopac/moderate/' . $type . '/' . ($offset + $limit)) . '</p>',
      );
      $form['#theme'] = 'sopac_admin_moderate_reviews';
    }
    else if ($type == 'tags') {
      $tags = $insurge->get_tags(1, $limit, $offset);
      $checkboxes = array();
      $form = array();
      foreach ($tags as $tag) {
        $bib = $locum->get_bib_item($tag['bnum'], TRUE);

        // Hover text for the bib
        $hover = $bib['title'] . "\n" .
                 $bib['callnum'] . "\n" .
                 $bib['pub_info'] . "\n" .
                 $bib['descr'];

        $checkboxes[$tag['tid']] = '';
        $account = user_load(array('uid' => $tag['uid']));
        $form[$tag['tid']] = array(
          'user' => array('#value' => l($account->name, 'user/' . $account->uid)),
          'bnum' => array('#value' => l($bib['title'], 'catalog/record/' . $tag['bnum'], array('attributes' => array('title' => $hover)))),
          'tag' => array('#value' => $tag['tag']),
          'created' => array('#value' => $tag['tag_date']),
          'public' => array('#value' => $tag['public'] ? 'Public' : 'Private'),
        );
      }
      $form['checkboxes'] = array(
        '#type' => 'checkboxes',
        '#options' => $checkboxes,
      );
      $form['operation'] = array(
        '#type' => 'hidden',
        '#value' => 'delete',
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Delete Selected Tags'),
      );
      $form['next'] = array(
        '#value' => '<p>' . l('NEXT PAGE', 'admin/settings/sopac/moderate/' . $type . '/' . ($offset + $limit)) . '</p>',
      );
      $form['#theme'] = 'sopac_admin_moderate_tags';
    }
    return $form;
  }
}

function sopac_admin_moderate_form_submit($form, &$form_state) {
  foreach($form_state['values']['checkboxes'] as $confirm_id) {
    if ($confirm_id) {
      $form_state['storage']['confirm_ids'][] = $confirm_id;
    }
  }
  $form_state['rebuild'] = TRUE;
}

function sopac_admin_moderate_delete_confirm_submit($form, &$form_state) {
  $insurge = sopac_get_insurge();
  if ($reviews = $form_state['values']['reviews']) {
    foreach ($reviews as $review) {
      if (module_exists('summergame')) {
        if ($player = summergame_player_load(array('uid' => $review['uid']))) {
          // Delete the points from the player record if found
          db_query("DELETE FROM sg_ledger WHERE pid = %d AND type = 'Wrote Review' " .
                   "AND metadata LIKE '%%bnum:%d%%'",
                   $player['pid'], $review['bnum']);
          if (db_affected_rows()) {
            $player_link = l($points . ' Summer Game score card', 'summergame/player/' . $player['pid']);
            drupal_set_message("Removed points for this review from player's $player_link");
          }
        }
      }
      $insurge->delete_review($review['uid'], $review['rev_id']);
    }
    drupal_goto('admin/settings/sopac/moderate/reviews');
  }
  else if ($tags = $form_state['values']['tags']) {
    if (module_exists('summergame')) {
      foreach($tags as $tag) {
        if ($player = summergame_player_load(array('uid' => $tag['uid']))) {
          // Delete the points from the player record if found
          db_query("DELETE FROM sg_ledger WHERE pid = %d AND type = 'Tagged an Item' " .
                   "AND metadata LIKE '%%bnum:%d%%'",
                   $player['pid'], $tag['bnum']);
          if (db_affected_rows()) {
            $player_link = l($points . ' Summer Game score card', 'summergame/player/' . $player['pid']);
            drupal_set_message("Removed points for this tag from player's $player_link");
          }
        }
        $insurge->delete_user_tag($tag['uid'], $tag['tag'], $tag['bnum']);
      }
    }
    drupal_goto('admin/settings/sopac/moderate/tags');
  }
}

function theme_sopac_admin_moderate_reviews($form) {
  $rows = array();
  foreach (element_children($form['checkboxes']) as $rev_id) {
    $rows[] = array(
      drupal_render($form['checkboxes'][$rev_id]),
      drupal_render($form[$rev_id]['user']),
      drupal_render($form[$rev_id]['bnum']),
      drupal_render($form[$rev_id]['title']),
      drupal_render($form[$rev_id]['body']),
      drupal_render($form[$rev_id]['created']),
      drupal_render($form[$rev_id]['update']),
    );
  }
  $header = array(
    'Select',
    'User',
    'Bib #',
    'Title',
    'Body',
    'Created',
    'Updated',
  );
  return theme('table', $header, $rows) . drupal_render($form);
}

function theme_sopac_admin_moderate_tags($form) {
  $rows = array();
  foreach (element_children($form['checkboxes']) as $tid) {
    $rows[] = array(
      drupal_render($form['checkboxes'][$tid]),
      drupal_render($form[$tid]['user']),
      drupal_render($form[$tid]['bnum']),
      drupal_render($form[$tid]['tag']),
      drupal_render($form[$tid]['created']),
      drupal_render($form[$tid]['public']),
    );
  }
  $header = array(
    'Select',
    'User',
    'Bib #',
    'Tag',
    'Created',
    'Public',
  );
  return theme('table', $header, $rows) . drupal_render($form);
}
Something went wrong with that request. Please try again.