<?php
// $Id$

require_once( drupal_get_path('module', 'sabreTools') . '/sabreTools.lib.inc');
require_once('sabreQMS.utils.inc');
require_once('class/sabreQMS.class.atachapterlist.inc');
require_once('class/sabreQMS.class.correctiveactionlist.inc');
require_once('class/sabreQMS.class.customerlist.inc');
require_once('class/sabreQMS.class.enginetypes.inc');
require_once('class/sabreQMS.class.joblist.inc');
require_once('class/sabreQMS.class.searchresultstable.inc');
require_once('class/sabreQMS.class.simulatorlist.inc');
require_once('class/sabreQMS.class.technicianlist.inc');
require_once('class/sabreQMS.class.troublecauselist.inc');
require_once('class/sabreQMS.class.qtgteststatus.inc');
require_once('class/sabreQMS.class.userlist.inc');
require_once('class/sabreQMS.class.usergrouplist.inc');
require_once('sabreQMS.users.inc');
require_once('sabreQMS.prevmaint.inc');
require_once('sabreQMS.discrepancy.inc');
require_once('sabreQMS.qtgadmin.inc');
require_once('sabreQMS.vendor.inc');

// ------ globals ------------------

$customer_list;
$chapter_list;
$tech_list;
$simulator_list;
$action_list;


// ------ globals ------------------

// app name for log files
define('QMS_APP', 'sabreQMS');


define('QMS_DISCREPANCY_SEARCH_KEY', 'QMS_discrepancy_search_key');
define('QMS_DISCREPANCY_SEARCH_RESULTS', 'QMS_discrepancy_search_results');
define('QMS_DISCREPANCY_SELECTED', 'QMS_discrepancy_selected');
define('QMS_DISCREPANCY_SEARCH_FORM', 'QMS_discrepancy_search_form');

define('QMS_TROUBLECALL_SEARCH_KEY', 'QMS_trouble_call_search_key');
define('QMS_TROUBLECALL_SEARCH_RESULTS', 'QMS_trouble_call_search_results');
define('QMS_TROUBLECALL_SELECTED', 'QMS_trouble_call_selected');
define('QMS_TROUBLECALL_SEARCH_FORM', 'QMS_trouble_call_search_form');

define('QMS_SHIFTLOG_SEARCH_FORM', 'QMS_shiftlog_search_form');
define('QMS_SHIFTLOG_SEARCH_KEY', 'QMS_shiftlog_search_key');
define('QMS_SHIFTLOG_SEARCH_RESULTS', 'QMS_shiftlog_search_results');
define('QMS_SHIFTLOG_SELECTED', 'QMS_shiftlog_selected');

define('QMS_ENGINEERING_SEARCH_FORM', 'QMS_engineering_search_form');
define('QMS_ENGINEERING_SEARCH_KEY', 'QMS_engineering_search_key');
define('QMS_ENGINEERING_SEARCH_RESULTS', 'QMS_engineering_search_results');
define('QMS_ENGINEERING_SELECTED', 'QMS_engineering_selected');

define('QMS_SIMULATORDOWNTIME_SEARCH_FORM', 'QMS_simulatordown_search_form');
define('QMS_SIMULATORDOWNTIME_SEARCH_KEY', 'QMS_simulatordown_search_key');
define('QMS_SIMULATORDOWNTIME_SEARCH_RESULTS', 'QMS_simulatordown_search_results');

define('QMS_PUNCHCLOCKEVENT_SEARCH_FORM', 'QMS_punchclockevent_search_form');
define('QMS_PUNCHCLOCKEVENT_SEARCH_KEY', 'QMS_punchclockevent_search_key');
define('QMS_PUNCHCLOCKEVENT_SEARCH_RESULTS', 'QMS_punchclockevent_search_results');

define('QMS_JOB_SEARCH_FORM', 'QMS_job_search_form');
define('QMS_JOB_SEARCH_KEY', 'QMS_job_search_key');
define('QMS_JOB_SEARCH_RESULTS', 'QMS_job_search_results');

define('QMS_QTG_SEARCH_KEY', 'QMS_qtg_search_key');
define('QMS_QTG_SEARCH_RESULTS', 'QMS_qtg_search_results');
define('QMS_QTG_SELECTED', 'QMS_qtg_selected');
define('QMS_QTG_SEARCH_FORM', 'QMS_qtg_search_form');

define('QMS_VENDOR_SEARCH_KEY', 'QMS_vendor_search_key');
define('QMS_VENDOR_SEARCH_RESULTS', 'QMS_vendor_search_results');
define('QMS_VENDOR_SELECTED', 'QMS_vendor_selected');
define('QMS_VENDOR_SEARCH_FORM', 'QMS_vendor_search_form');


define('QMS_TECHNICIAN_LIST', 'QMS_technician_list');
//define('QMS_JOB_LIST', 'QMS_job_list');
define('QMS_CUSTOMER_LIST', 'QMS_customer_list');
define('QMS_SIMULATOR_LIST', 'QMS_simulator_list');
define('QMS_ATACHAPTER_LIST', 'QMS_ata_chapter_list');
define('QMS_CORRECTIVE_ACTION_LIST', 'QMS_corrective_action_list');
define('QMS_LOAD_UPDATED_LIST', 'QMS_load_updated_list');
define('QMS_TROUBLE_CAUSE_LIST', 'QMS_trouble_cause_list');

define('QMS_RPT_72HR_ACTIVITY', '72');
define('QMS_RPT_24HR_ACTIVITY', '24');
define('QMS_RPT_OPEN_DISCREPANCY', '1');
define('QMS_RPT_OPEN_MMI', '2');
define('QMS_RPT_DR_SELECTED', '3');

define('QMS_ATACHAPTER_OTHER', 23);
define('QMS_ATACHAPTER_PREFLIGHT', 24);  // loaded at installation
define('QMS_ATACHAPTER_PREVMAINT', 19);  // loaded at installation


// configuration setting
define('QMS_VAR_SIMS_USE_CUSTOMER_PREFIX', 'qms_sims_use_customer_prefix');

define('QMS_DISCREPANCY_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_discrepancy');
define('QMS_DISCREPANCY_DEFAULT_SORT', 'qms_default_sort_order_discrepancy');
define('QMS_TROUBLECALL_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_troublecall');
define('QMS_TROUBLECALL_DEFAULT_SORT', 'qms_default_sort_order_troublecall');

define('QMS_ENGINEERING_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_engineering');
define('QMS_ENGINEERING_DEFAULT_SORT', 'qms_default_sort_order_engineering');
define('QMS_SHIFTLOG_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_shiftlog');
define('QMS_SHIFTLOG_DEFAULT_SORT', 'qms_default_sort_order_shiftlog');
define('QMS_SIMULATORDOWN_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_simulatordown');
define('QMS_SIMULATORDOWN_DEFAULT_SORT', 'qms_default_sort_order_simulatordown');
define('QMS_QTG_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_qtg');
define('QMS_QTG_DEFAULT_SORT', 'qms_default_sort_order_qtg');
define('QMS_VENDOR_DEFAULT_SORT_COLUMN', 'qms_default_sort_column_vendor');
define('QMS_VENDOR_DEFAULT_SORT', 'qms_default_sort_order_vendor');



define('QMS_QTG_STATUS_NOT_RUN', 1);
define('QMS_QTG_STATUS_RAN', 2);
define('QMS_QTG_STATUS_PASSED', 3);
define('QMS_QTG_STATUS_RERUN', 4);
define('QMS_QTG_STATUS_FAIL', 5);


/**
*			@file
**		Sabre Updates QMS module for plugin to Drupal 7.x Framework
*/

function sabreQMS_theme() {
  return array(
    'sabreQMS_javascript' => array(
      'arguments' => array(),
    ),
  );
}


function sabreQMS_init() {
  
  $sabreQMS = drupal_get_path('module', 'sabreQMS');
	drupal_add_css($sabreQMS . '/css/qms-style.css');
  drupal_add_css($sabreQMS . '/css/qms-print.css');

  global $customer_list;
  global $chapter_list;
  global $tech_list;
  global $simulator_list;
  global $action_list;


  global $user;

  $customer_user_id = _user_is_customer($user->uid);

  $customer_list = new CustomerList;
  $chapter_list = new ATAChapterList;
  $tech_list = new TechnicianList;
  $simulator_list = new SimulatorList(array(
                           'customer_id' => $customer_user_id));
  $action_list = new CorrectiveActionList;

}


// VERSION 7
function sabreQMS_permission() {
  return array(
    'access sabreQMS' => array(
      'title' => t('Access QMS'),
      'description' => t('QMS standard access'),
      ),
    'user feedback' => array(
      'title' => t('Provide feedback'),
      'description' => t('Provide user feedback'),
      ),
    'search view reports' => array(
      'title' => t('Search and View Reports'),
      'description' => t('Search and view reports:  Discrepancies, Engineering Logs, Simulator Downtime, Reports, Vendors'),
      ),
    'search view logs' => array(
      'title' => t('Search and View Shift Logs'),
      'description' => t('Search and view Shift Logs'),
      ),
    'view admin lists' => array(
      'title' => t('View Administrative Lists'),
      'description' => t('View:  Chapters, Actions, Customers, Jobs, Load Updated Items, ' .
                        'Preventative Maintenance, Simulators, User Feedback Log. ' .
                        '(not included:  Employees or System Core Administration)'),
      ),
    'create discrepancy' => array(
      'title' => t('Create Discrepancy Reports'),
      'description' => t('Create discrepancy report entries (includes all areas of the DR)'),
      ),
    'edit discrepancy' => array(
      'title' => t('Edit Discrepancy Reports'),
      'description' => t('Edit discrepancy report fields: ' .
                      'Customer, ATA Chapter, Simulator, Date Opened, Discrepancy Text'),
      ),
    'set discrepancy flags' => array(
      'title' => t('Set Discrepancy Report Indicator Fields'),
      'description' => t('Set the indicators for MMI, FAA, or Show Customer'),
      ),
    'close discrepancy' => array(
      'title' => t('Close Discrepancies'),
      'description' => t('Mark discrepancy reports as "closed".  Set the Date Closed and Corrective Action'),
      ),
    'add discrepancy comments' => array(
      'title' => t('Add Discrepancy Comments'),
      'description' => t('Add discrepancy comments to existing discrepancies.'),
      ),
    'edit discrepancy comments' => array(
      'title' => t('Edit Discrepancy Comments'),
      'description' => t('Edit discrepancy comments for existing discrepancies.'),
      ),
    'add discrepancy parts' => array(
      'title' => t('Add Discrepancy Parts'),
      'description' => t('Add discrepancy parts to existing discrepancies.'),
      ),
    'edit discrepancy parts' => array(
      'title' => t('Edit Discrepancy Parts'),
      'description' => t('Edit discrepancy parts for existing discrepancies.'),
      ),
    'add discrepancy files' => array(
      'title' => t('Add Discrepancy Files'),
      'description' => t('Add discrepancy files to existing discrepancies.'),
      ),
    'delete discrepancy files' => array(
      'title' => t('Delete Discrepancy Files'),
      'description' => t('Delete discrepancy files from existing discrepancies.'),
      ),
    'assign technician' => array(
      'title' => t('Assign Technician'),
      'description' => t('Allows technician (re)assignment after the discrepancy has been created.  Otherwise the technician assigned is automatically the user who created the discrepancy report.'),
      ),
    'create trouble call log' => array(
      'title' => t('Create Trouble Call Entries'),
      'description' => t('Create trouble call entries'),
    ),
    'edit trouble call log' => array(
      'title' => t('Edit Trouble Call Entries'),
      'description' => t('Edit trouble call entries'),
    ),
    'add trouble call comments' => array(
      'title' => t('Add Trouble Call Comments'),
      'description' => t('Add trouble call comments to existing trouble calls.'),
      ),
    'edit trouble call comments' => array(
      'title' => t('Edit Trouble Call Comments'),
      'description' => t('Edit trouble call comments for existing trouble call.'),
      ),
    'create shift log' => array(
      'title' => t('Create Shift Log Entries'),
      'description' => t('Create shift log entries'),
      ),
    'create engineering log' => array(
      'title' => t('Create Engineering Log Entries'),
      'description' => t('Create engineering entries'),
      ),
    'create simulator downtime' => array(
      'title' => t('Create Simulator Downtime Entries'),
      'description' => t('Create simulator downtime entries'),
      ),
    'edit qtg event' => array(
      'title' => t('Edit QTG Test Event Statuses'),
      'description' => t('Edit QTG test event statuses'),
      ),
    'create vendor' => array(
      'title' => t('Create Vendor'),
      'description' => t('Create a vendor record'),
      ),
    'edit vendor' => array(
      'title' => t('Edit Vendor'),
      'description' => t('Edit a vendor record'),
      ),
    'punch clock' => array(
      'title' => t('Punch Clock'),
      'description' => t('Access the employee punch clock'),
      ),
    'administer sabreQMS' => array(
      'title' => t('Manage QMS administrative functions'),
      'description' => t('QMS administrative access'),
      ),
  );
}

/**
 * Implements hook_library_alter().
 */
function sabreQMS_library_alter(&$libraries, $module) {

  $jquery_ui_theme = variable_get('jquery_ui_theme', '');

  // don't unset if the css file doesn't exist
  if ( strlen($jquery_ui_theme) > 0 ) {
    unset($libraries['ui']['css']['misc/ui/jquery.ui.theme.css']);
    $libraries['ui']['css'][$jquery_ui_theme] = array();
  }

  // use the 'redmond' css theme for jquery ui rather than the default
  //unset($libraries['ui']['css']['misc/ui/jquery.ui.theme.css']);
  //$libraries['ui']['css']['sites/all/themes/redmond/jquery-ui-1.8.16.custom.css'] = array();
}


/*
 * This function defines the URL to the page created etc.
 * See http://api.drupal.org/api/function/hook_menu/6
 */


function sabreQMS_menu() {

  $items = array();

  //------- QMS Menu Items -----

  $items['discrepancy/add'] = array(
    'title' => t('Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('discrepancy_form'),
    'access arguments' => array('create discrepancy'),
    'description' => 'Create discrepancy report',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -44,
    'file' => 'sabreQMS.discrepancy.inc',
  );

  $items['troublecall/discrepancy/add/%'] = array(
    'title' => t('Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('discrepancy_form', '0', 3), // trouble_call_id
    'access arguments' => array('create discrepancy'),
    'description' => 'Create discrepancy report from trouble call',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.discrepancy.inc',
  );


  $items['discrepancy/edit/%'] = array(
    'title' => t('Edit Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('discrepancy_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'Edit discrepancy report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.discrepancy.inc',
  );

  $items['discrepancy/view/%'] = array(
    'title' => t('Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('view_discrepancy_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'View discrepancy report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.discrepancy.inc',
  );


  $items['discrepancy/delete/%'] = array(
    'title' => t('Delete Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('discrepancy_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete discrepancy report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.discrepancy.inc',
  );

  // discrepancy comments

  $items['discrepancy/comment/get/%'] = array(
    'title' => t('Get Discrepancy Comment'),
    'page callback' => 'get_comment_callback',
    'page arguments' => array('DR', 3),
    'access arguments' => array('edit discrepancy comments'),
    'description' => 'Get discrepancy comment',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );

  $items['discrepancy/comment/update'] = array(
    'title' => t('Add/Update Discrepancy Comment'),
    'page callback' => 'comment_submit_callback',
    'page arguments' => array('DR'),
    'access arguments' => array('add discrepancy comments'),
    'description' => 'Add update discrepancy comment',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );

  $items['discrepancy/comment/delete/%'] = array(
    'title' => t('Delete Discrepancy Comment'),
    'page callback' => 'discrepancy_comment_delete_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete discrepancy comment',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );

  // this is for discrepancies and trouble calls
  $items['theme_comments_table'] = array(
    'title' => t('Redisplay comments table'),
    'page callback' => 'theme_comments_table_callback',
    'access arguments' => array('access sabreQMS'),
    'description' => 'Redisplay table of comments to be added once report is submitted',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );

  // discrepancy parts

  $items['discrepancy/part/get/%'] = array(
    'title' => t('Get Discrepancy Part'),
    'page callback' => 'get_discrepancy_part_callback',
    'page arguments' => array(3),
    'access arguments' => array('edit discrepancy parts'),
    'description' => 'Get discrepancy part',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drparts.inc',
  );

  $items['discrepancy/part/update'] = array(
    'title' => t('Add/Update Discrepancy Part'),
    'page callback' => 'discrepancy_part_submit_callback',
    'access arguments' => array('add discrepancy parts'),
    'description' => 'Add update discrepancy part',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drparts.inc',
  );

  $items['discrepancy/part/delete/%'] = array(
    'title' => t('Delete Discrepancy Part'),
    'page callback' => 'discrepancy_part_delete_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete discrepancy part',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drparts.inc',
  );


  $items['discrepancy/theme_add_parts_table'] = array(
    'title' => t('Redisplay discrepancy parts table'),
    'page callback' => 'theme_add_parts_table_callback',
    'access arguments' => array('create discrepancy'),
    'description' => 'Redisplay table of discrepancy parts to be added once DR is submitted',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drparts.inc',
  );

  $items['discrepancy/file/download/%'] = array(
    'title' => t('Download Discrepancy File'),
    'page callback' => 'discrepancy_file_download',
    'page arguments' => array(3),
    'access callback' => array(True),
    'description' => 'Download file attached to discrepancy',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drfiles.inc',
  );

  $items['discrepancy/file/delete/%'] = array(
    'title' => t('Delete Discrepancy File'),
    'page callback' => 'discrepancy_file_delete_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete file attached to discrepancy',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drfiles.inc',
  );

  $items['discrepancy/file/add/%'] = array(
    'title' => t('Attach Files to Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('file_upload_plupload_form', 'DR', 3),
    'access arguments' => array('add discrepancy files'),
    'description' => 'Add file to discrepancy',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drfiles.inc',
  );

  $items['discrepancy/file/orig/add/%'] = array(
    'title' => t('Attach Files to Discrepancy'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('file_upload_orig_form', 'DR', 4),
    'access arguments' => array('add discrepancy files'),
    'description' => 'Add file to discrepancy',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drfiles.inc',
  );


  $items['discrepancy/file/refresh'] = array(
    'title' => t('Refresh Discrepancy Files Table'),
    'page callback' => 'discrepancy_files_table_refresh_callback',
    //'page arguments' => array(3),
    'access arguments' => array('search view reports'),
    'description' => 'Refresh discrepancy files table',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.drfiles.inc',
  );


  // Discrepancy - Preflight (specialized DR form, new entry only)

  $items['discrepancy/preflight/add'] = array(
    'title' => t('Preflight'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('discrepancy_preflight_form'),
    'access arguments' => array('create discrepancy'),
    'description' => 'Create discrepancy report',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -42,
    'file' => 'sabreQMS.discrepancy.inc',
  );


  //----- DR Utilities ---------


  $items['drno/autocomplete'] = array(
  'page callback' => 'dr_no_autocomplete',
  'access arguments' => array('access sabreQMS'),  // needs to be kept basic as it is a multi-use utility callback
  'type' => MENU_CALLBACK,												 // returns DR report numbers that are valid.
  'file' => 'sabreQMS.discrepancy.inc',
  );

  $items['drno/simulator'] = array(
  'page callback' => 'get_dr_simulator',
  'access arguments' => array('access sabreQMS'),  // needs to be kept basic as it is a multi-use utility callback
  'type' => MENU_CALLBACK,												 // returns DR report numbers that are valid.
  'file' => 'sabreQMS.discrepancy.inc',
  );

  /*  DEPRECATED -- we use a hidden column in the search results table to do this more efficiently
  $items['discrepancy/text/%'] = array(
  'page callback' => 'get_dr_text',
  'page arguments' => array(2),
  'access arguments' => array('access sabreQMS'),  // needs to be kept basic as it is a multi-use utility callback
  'type' => MENU_CALLBACK,												 // returns DR text in floating box for discrepancy search list.
  'file' => 'sabreQMS.discrepancy.inc',
  );
  */




  // Trouble Calls

  $items['troublecall'] = array(
    'title' => t('Trouble Call'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('trouble_call_form'),
    'access arguments' => array('create trouble call log'),
    'description' => 'Create shift log entry',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -39,
    'file' => 'sabreQMS.troublecall.inc',
  );

  $items['troublecall/edit/%'] = array(
    'title' => t('Edit Trouble Call'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('trouble_call_form', 2),
    'access arguments' => array('edit trouble call log'),
    'description' => 'Edit shift log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecall.inc',
  );

  $items['troublecall/view/%'] = array(
    'title' => t('Trouble Call'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('view_trouble_call_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'View shift log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecall.inc',
  );


  $items['troublecall/delete/%'] = array(
    'title' => t('Delete Trouble Call'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('trouble_call_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete shift log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecall.inc',
  );

  // trouble call comments

  $items['troublecall/comment/get/%'] = array(
    'title' => t('Get Trouble Call Comment'),
    'page callback' => 'get_comment_callback',
    'page arguments' => array('TC', 3),
    'access arguments' => array('edit trouble call comments'),
    'description' => 'Get trouble call comment',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );

  $items['troublecall/comment/update'] = array(
    'title' => t('Add/Update Trouble Call Comment'),
    'page callback' => 'comment_submit_callback',
    'page arguments' => array('TC'),
    'access arguments' => array('add trouble call comments'),
    'description' => 'Add update trouble call comment',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );

  $items['troublecall/comment/delete/%'] = array(
    'title' => t('Delete Trouble Call Comment'),
    'page callback' => 'trouble_call_comment_delete_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete trouble call comment',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.comments.inc',
  );






  // Shift Log

  $items['shiftlog'] = array(
    'title' => t('Shift Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('shift_log_form'),
    'access arguments' => array('create shift log'),
    'description' => 'Create shift log entry',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -38,
    'file' => 'sabreQMS.shiftlog.inc',
  );

  $items['shiftlog/edit/%'] = array(
    'title' => t('Edit Shift Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('shift_log_form', 2),
    'access arguments' => array('create shift log'),
    'description' => 'Edit shift log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlog.inc',
  );

  $items['shiftlog/view/%'] = array(
    'title' => t('Shift Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('view_shift_log_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'View shift log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlog.inc',
  );


  $items['shiftlog/delete/%'] = array(
    'title' => t('Delete Shift Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('shift_log_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete shift log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlog.inc',
  );


  $items['shiftlog/file/download/%'] = array(
    'title' => t('Download Shift Log File'),
    'page callback' => 'shift_log_file_download',
    'page arguments' => array(3),
    'access callback' => array(True),
    'description' => 'Download file attached to shift log',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlogfiles.inc',
  );

  $items['shiftlog/file/delete/%'] = array(
    'title' => t('Delete Shift Log File'),
    'page callback' => 'shift_log_file_delete_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete file attached to shift log',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlogfiles.inc',
  );

  $items['shiftlog/file/add/%'] = array(
    'title' => t('Attach Files to Shift Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('file_upload_plupload_form', 'SL', 3),
    'access arguments' => array('create shift log'),
    'description' => 'Add file to shift log',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlogfiles.inc',
  );

  $items['shiftlog/file/orig/add/%'] = array(
    'title' => t('Attach Files to Shift Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('file_upload_orig_form', 'SL', 4),
    'access arguments' => array('create shift log'),
    'description' => 'Add file to shift log',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.shiftlogfiles.inc',
  );



  // Engineering Log

  $items['engineering'] = array(
    'title' => t('Engineering Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('engineering_form'),
    'access arguments' => array('create engineering log'),
    'description' => 'Create engineering log entry',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -36,
    'file' => 'sabreQMS.engineering.inc',
  );

  $items['engineering/edit/%'] = array(
    'title' => t('Edit Engineering Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('engineering_form', 2),
    'access arguments' => array('create engineering log'),
    'description' => 'Edit engineering log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engineering.inc',
  );

  $items['engineering/view/%'] = array(
    'title' => t('Engineering Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('view_engineering_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'View engineering log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engineering.inc',
  );

  $items['engineering/delete/%'] = array(
    'title' => t('Delete Engineering Log'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('engineering_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete engineering log entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engineering.inc',
  );

  // Simulator Downtime

  $items['simulator_downtime'] = array(
    'title' => t('Simulator Downtime'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('simulator_downtime_form'),
    'access arguments' => array('create simulator downtime'),
    'description' => 'Create engineering log entry',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -34,
    'file' => 'sabreQMS.simulatordown.inc',
  );

  $items['simulator_downtime/edit/%'] = array(
    'title' => t('Edit Simulator Downtime'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('simulator_downtime_form', 2),
    'access arguments' => array('create simulator downtime'),
    'description' => 'Edit simulator downtime entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatordown.inc',
  );

  $items['simulator_downtime/view/%'] = array(
    'title' => t('Simulator Downtime'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('view_simulator_downtime_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'View simulator downtime entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatordown.inc',
  );


  $items['simulator_downtime/delete/%'] = array(
    'title' => t('Delete Simulator Downtime'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('simulator_downtime_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete simulator downtime entry',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatordown.inc',
  );



  // QTG Tests - View, Edit, Deleteqtg_event_form

  $items['qtg/event/edit/%'] = array(
    'title' => t('Edit QTG Test Event'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_event_form', 3, True),
      // handle edit perm in the form function
    'access arguments' => array('search view reports'),
    'description' => 'Edit QTG Test Event',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/event/view/%'] = array(
    'title' => t('View QTG Test Event'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_event_form', 3, False),
    'access arguments' => array('search view reports'),
    'description' => 'View QTG Test Event',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/event/delete/%'] = array(
    'title' => t('Delete QTG Test Event'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_event_delete_confirm', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete QTG Test Event',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/test/status/edit/%/%'] = array(
    'title' => t('Edit QTG Test Status'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_status_form', 4, 5, '', True),
            // qtg_event_id, qtg_test_id, qtg_test_status_history_id, bEdit
    'access arguments' => array('edit qtg event'),
    'description' => 'Edit QTG Test Status',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/test/status/view/%/%'] = array(
    'title' => t('View QTG Test Status'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_status_form', 4, 5, False),
                        // qtg_event_id, qtg_test_id, bEdit
    'access arguments' => array('search view reports'),
    'description' => 'Edit QTG Test Status',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/test/status/run/%/%'] = array(
    'title' => t('Run QTG Test'),
    'page callback' => 'qtg_run_test_callback',
    'page arguments' => array(4, 5), // qtg_event_id, qtg_test_id
    'access arguments' => array('edit qtg event'),
    'description' => 'Run QTG Test',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/test/history/edit/%'] = array(
    'title' => t('Edit QTG Test Status History'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_status_form', '', '', 4, True),
              // qtg_event_id, qtg_test_id, qtg_test_status_history_id, bEdit
    'access arguments' => array('edit qtg event'),
    'description' => 'Edit QTG Test Status History',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );

  $items['qtg/test/history/delete/%'] = array(
    'title' => t('Delete QTG Test Status History'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_status_delete_confirm', 4),
                      //qtg_test_status_history_id
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete QTG Test Status History',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtg.inc',
  );


  // Vendor

  $items['vendor'] = array(
    'title' => t('Vendor'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('vendor_form'),
    'access arguments' => array('create vendor'),
    'description' => 'Create vendor record',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -32,
    'file' => 'sabreQMS.vendor.inc',
  );

  $items['vendor/edit/%'] = array(
    'title' => t('Edit Vendor'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('vendor_form', 2),
    'access arguments' => array('edit vendor'),
    'description' => 'Edit vendor record',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.vendor.inc',
  );

  $items['vendor/view/%'] = array(
    'title' => t('Vendor'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('view_vendor_form', 2),
    'access arguments' => array('search view reports'),
    'description' => 'View vendor',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.vendor.inc',
  );


  $items['vendor/delete/%'] = array(
    'title' => t('Delete Vendor'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('vendor_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete vendor',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.vendor.inc',
  );

  $items['reports/vendors/selected'] = array(
    'title' => t('Vendors Report'),
    'page callback' => 'vendors_selected_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display a report of vendors selected from search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  // Punch Clock

  $items['punchclock'] = array(
    'title' => t('Punch Clock'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('punch_clock_form'),
    'access arguments' => array('punch clock'),
    'description' => 'Punch clock for punching in/punching out of Sabre Updates projects',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -30,
    'file' => 'sabreQMS.punchclock.inc',
  );

  $items['punchclock/punch'] = array(
    'title' => t('Punch Clock'),
    'page callback' => 'punch_clock_event_callback',
    //'page arguments' => array(2),
    'access arguments' => array('punch clock'),
    'description' => 'Clock In/Clock Out punch clock event',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclock.inc',
  );

  $items['punchclockevent/add'] = array(
    'title' => t('Add Punch Clock Event'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('punch_clock_admin_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add punch clock event by Administrator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );

  $items['punchclockevent/edit/%'] = array(
    'title' => t('Edit Punch Clock Event'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('punch_clock_admin_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit punch clock event by Administrator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );

  $items['punchclockevent/delete/%'] = array(
    'title' => t('Delete Punch Clock Event'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('punch_clock_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete punch clock event by Administrator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );



  // Punch Clock Event Search  -- Shows up in QMS Settings Menu ONLY

  $items['qmssettings/punchclockevents'] = array(
    'title' => t('Punch Clock Events'),
    'page callback' => 'search_punch_clock_events',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Search employee punch clock events',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );

  $items['punchclockevents/search'] = array(
    'title' => t('Punch Clock Events'),
    'page callback' => 'punch_clock_event_search_form_callback',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Display punch clock events search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );

  $items['punchclockevents/pager'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'punch_clock_event_pager_callback',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Display another punch clock events search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );

  $items['punchclockevents/clear'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'punch_clock_event_clear_results_callback',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Clears the cache for the punch clock event search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.punchclockadmin.inc',
  );



  // User Feedback

  $items['feedback/add'] = array(
    'title' => t('User Feedback'),
    'page callback' => 'user_feedback',
    //'page arguments' => array('user_feedback'),  // don't use drupal_get_form here.  We're caching this page, causes an error
    'access arguments' => array('user feedback'),
    'description' => 'Provide feedback',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-menu',
    'weight' => -30,
    'file' => 'sabreQMS.userfeedback.inc',
  );



  //------- QMS Search Menu Items -----

  $items['search/discrepancy'] = array(
    'title' => t('Discrepancies'),
    'page callback' => 'search_discrepancies',
    'access arguments' => array('search view reports'),
    'description' => 'Search discrepancy reports',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -40,
    'file' => 'sabreQMS.searchdiscrepancies.inc',
  );

  $items['search/discrepancy/search'] = array(
    'title' => t('Discrepancies'),
    'page callback' => 'discrepancy_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display Discrepancy search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchdiscrepancies.inc',
  );

  $items['search/discrepancy/pager'] = array(
    'title' => t('Discrepancies'),
    'page callback' => 'discrepancy_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another Discrepancy search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchdiscrepancies.inc',
  );

  $items['search/discrepancy/clear'] = array(
    'title' => t('Discrepancies'),
    'page callback' => 'discrepancy_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the discrepancy search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchdiscrepancies.inc',
  );

  $items['search/discrepancy/selection'] = array(
    'title' => t('Discrepancies'),
    'page callback' => 'result_list_selection_callback',
    'page arguments' => array(QMS_DISCREPANCY_SELECTED),  // selected cache name prefix
    'access arguments' => array('search view reports'),
    'description' => 'Tracks the selections made from the discrepancy search list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.utils.inc',
  );

  // ------------ Trouble Calls ------------

  $items['search/troublecalls'] = array(
    'title' => t('Trouble Calls'),
    'page callback' => 'search_trouble_calls',
    'access arguments' => array('search view reports'),
    'description' => 'Search trouble call reports',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -39,
    'file' => 'sabreQMS.searchtroublecalls.inc',
  );

  $items['search/troublecalls/search'] = array(
    'title' => t('Trouble Calls'),
    'page callback' => 'trouble_call_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display trouble call search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchtroublecalls.inc',
  );

  $items['search/troublecalls/pager'] = array(
    'title' => t('Trouble Calls'),
    'page callback' => 'trouble_call_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another trouble call search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchtroublecalls.inc',
  );

  $items['search/troublecalls/clear'] = array(
    'title' => t('Trouble Calls'),
    'page callback' => 'trouble_call_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the discrepancy search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchtroublecalls.inc',
  );

  $items['search/troublecalls/selection'] = array(
    'title' => t('Trouble Calls'),
    'page callback' => 'result_list_selection_callback',
    'page arguments' => array(QMS_TROUBLECALL_SELECTED),  // selected cache name prefix
    'access arguments' => array('search view reports'),
    'description' => 'Tracks the selections made from the trouble calls search list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.utils.inc',
  );



  // Shift Log Search

  $items['search/shiftlog'] = array(
    'title' => t('Shift Logs'),
    'page callback' => 'search_shift_logs',
    'access arguments' => array('search view logs'),
    //'access callback' => 'search_shiftlog_access_callback',
    'description' => 'Search shift logs',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -38,
    'file' => 'sabreQMS.searchshiftlogs.inc',
  );

  $items['search/shiftlog/search'] = array(
    'title' => t('Shift Logs'),
    'page callback' => 'shift_log_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display shift log search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchshiftlogs.inc',
  );

  $items['search/shiftlog/pager'] = array(
    'title' => t('Shift Logs'),
    'page callback' => 'shift_log_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another shift log search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchshiftlogs.inc',
  );

  $items['search/shiftlog/clear'] = array(
    'title' => t('Shift Logs'),
    'page callback' => 'shift_log_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the shift log search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchshiftlogs.inc',
  );

  $items['search/shiftlog/selection'] = array(
    'title' => t('Shift Logs'),
    'page callback' => 'result_list_selection_callback',
    'page arguments' => array(QMS_SHIFTLOG_SELECTED),  // record type for specifying cache
    'access arguments' => array('search view reports'),
    'description' => 'Tracks the selections made from the shift log search list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.utils.inc',
  );



  // Engineering Log Search

  $items['search/engineering'] = array(
    'title' => t('Engineering Logs'),
    'page callback' => 'search_engineering_logs',
    'access arguments' => array('search view reports'),
    'description' => 'Search engineering logs',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -36,
    'file' => 'sabreQMS.searchengineering.inc',
  );

  $items['search/engineering/search'] = array(
    'title' => t('Engineering Logs'),
    'page callback' => 'engineering_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display engineering log search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchengineering.inc',
  );

  $items['search/engineering/pager'] = array(
    'title' => t('Engineering Logs'),
    'page callback' => 'engineering_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another engineering log search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchengineering.inc',
  );

  $items['search/engineering/clear'] = array(
    'title' => t('Engineering Logs'),
    'page callback' => 'engineering_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the engineering log search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchengineering.inc',
  );

  $items['search/engineering/selection'] = array(
    'title' => t('Engineering Logs'),
    'page callback' => 'result_list_selection_callback',
    'page arguments' => array(QMS_ENGINEERING_SELECTED),  // selected cache name prefix
    'access arguments' => array('search view reports'),
    'description' => 'Tracks the selections made from the engineering search list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.utils.inc',
  );


  // Simulator Downtime Search

  $items['search/simulator_downtime'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'search_simulator_downtime',
    'access arguments' => array('search view reports'),
    'description' => 'Search simulator downtime',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -34,
    'file' => 'sabreQMS.searchsimulatordown.inc',
  );

  $items['search/simulator_downtime/search'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'simulator_downtime_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display simulator downtime search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchsimulatordown.inc',
  );

  $items['search/simulator_downtime/pager'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'simulator_downtime_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another simulator downtime search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchsimulatordown.inc',
  );

  $items['search/simulator_downtime/clear'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'simulator_downtime_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the simulator downtime search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchsimulatordown.inc',
  );



  $items['search/qtg'] = array(
    'title' => t('QTG Tests'),
    'page callback' => 'search_qtg',
    'access arguments' => array('search view reports'),
    'description' => 'Search QTG Test Events',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -30,
    'file' => 'sabreQMS.searchqtg.inc',
  );

  $items['search/qtg/search'] = array(
    'title' => t('QTG Tests'),
    'page callback' => 'qtg_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display QTG Tests search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchqtg.inc',
  );

  $items['search/qtg/pager'] = array(
    'title' => t('QTG Tests'),
    'page callback' => 'qtg_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another QTG Tests search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchqtg.inc',
  );

  $items['search/qtg/clear'] = array(
    'title' => t('QTG Tests'),
    'page callback' => 'qtg_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the QTG Tests search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchqtg.inc',
  );

  $items['search/qtg/selection'] = array(
    'title' => t('QTG Tests'),
    'page callback' => 'result_list_selection_callback',
    'page arguments' => array(QMS_QTG_SELECTED),  // selected cache name prefix
    'access arguments' => array('search view reports'),
    'description' => 'Tracks the selections made from the QTG Test search list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.utils.inc',
  );

  /* ------------- search / vendors ----------------- */
  $items['search/vendors'] = array(
    'title' => t('Vendors'),
    'page callback' => 'search_vendors',
    'access arguments' => array('search view reports'),
    'description' => 'Search Vendors',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -28,
    'file' => 'sabreQMS.searchvendors.inc',
  );

  $items['search/vendors/search'] = array(
    'title' => t('Vendors'),
    'page callback' => 'vendor_search_form_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display Vendor search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchvendors.inc',
  );

  $items['search/vendors/pager'] = array(
    'title' => t('Vendors'),
    'page callback' => 'vendor_pager_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Display another Vendor search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchvendors.inc',
  );

  $items['search/vendors/clear'] = array(
    'title' => t('Vendors'),
    'page callback' => 'vendor_clear_results_callback',
    'access arguments' => array('search view reports'),
    'description' => 'Clears the cache for the Vendor search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.searchvendors.inc',
  );

  $items['search/vendors/selection'] = array(
    'title' => t('Vendors'),
    'page callback' => 'result_list_selection_callback',
    'page arguments' => array(QMS_VENDOR_SELECTED),  // selected cache name prefix
    'access arguments' => array('search view reports'),
    'description' => 'Tracks the selections made from the Vendor search list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.utils.inc',
  );

  $items['vendor/customer/add'] = array(
    'title' => t('Add User to Group'),
    'page callback' => 'vendor_add_customer_callback',
    //'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Link customer with vendor',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.vendor.inc',
  );

  $items['vendor/customer/remove'] = array(
    'title' => t('Remove User from Group'),
    'page callback' => 'vendor_remove_customer_callback',
    //'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Unlink customer from vendor',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.vendor.inc',
  );

  $items['vendor/customer/refresh'] = array(
    'title' => t('Refresh Customers Table'),
    'page callback' => 'vendor_customer_table_refresh_callback',
    //'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Refresh vendor customers table',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.vendor.inc',
  );


  //---------- Search Menu Items ----------------

  $items['search'] = array(
    'title' => t('QMS Search'),
    'page callback' => 'display_search_menu_list',
    'access arguments' => array('search view reports'),
    'description' => 'View list of available searches',
    'type' => MENU_CALLBACK,
    //'menu_name' => 'qms-search-menu',
    //'weight' => -32,
    //'file' => 'sabreQMS.reports.inc',
  );

  $items['reports'] = array(
    'title' => t('Reports'),
    'page callback' => 'display_reports_menu',
    'access arguments' => array('search view reports'),
    'description' => 'View list of available reports',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-search-menu',
    'weight' => -10,
    'file' => 'sabreQMS.reports.inc',
  );




  //------- QMS Admin Menu Items -----

  $items['qmssettings'] = array(
    'title' => t('QMS Settings'),
    'page callback' => 'display_qms_settings_menu',
    'access arguments' => array('view admin lists'),
    'description' => 'Displays menu of administrative lists for the QMS',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-admin-menu',
    'weight' => -40,
  );



  $items['qmssettings/atachapters'] = array(
    'title' => t('ATA Chapters'),
    'page callback' => 'atachapters_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display ATA Chapters',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.atachapters.inc',
  );

  $items['atachapter/add'] = array(
    'title' => t('Add ATA Chapter'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('atachapter_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add ATA Chapter',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.atachapters.inc',
  );

  $items['atachapter/edit/%'] = array(
    'title' => t('Edit ATA Chapter'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('atachapter_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit ATA Chapter',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.atachapters.inc',
  );

  $items['atachapter/delete/%'] = array(
    'title' => t('Delete ATA Chapter'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('atachapter_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete AtA Chapter',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.atachapters.inc',
  );

  $items['qmssettings/corrective_actions'] = array(
    'title' => t('Corrective Actions'),
    'page callback' => 'corrective_actions_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display corrective actions',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.correctiveactions.inc',
  );

  $items['corrective_action/add'] = array(
    'title' => t('Add Corrective Action'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('corrective_action_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add corrective action',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.correctiveactions.inc',
  );

  $items['corrective_action/edit/%'] = array(
    'title' => t('Edit Corrective Action'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('corrective_action_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit corrective action',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.correctiveactions.inc',
  );

  $items['corrective_action/delete/%'] = array(
    'title' => t('Delete Corrective Action'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('corrective_action_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete corrective action',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.correctiveactions.inc',
  );



  $items['qmssettings/customers'] = array(
    'title' => t('Customers'),
    'page callback' => 'customers_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display customers',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.customers.inc',
  );

  $items['customer/add'] = array(
    'title' => t('Add Customer'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('customer_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Administer customers',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.customers.inc',
  );

  $items['customer/edit/%'] = array(
    'title' => t('Edit Customer'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('customer_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Administer customers',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.customers.inc',
  );

  $items['customer/delete/%'] = array(
    'title' => t('Delete Customer'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('customer_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Administer customers',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.customers.inc',
  );


  $items['qmssettings/jobs'] = array(
    'title' => t('Jobs'),
    //'page callback' => 'job_list_display',
    'page callback' => 'search_jobs',
    'page arguments' => array(False),
    'access arguments' => array('view admin lists'),
    'description' => 'Search jobs',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['qmssettings/jobs/search'] = array(
    'title' => t('Jobs Search'),
    'page callback' => 'jobs_search_form_callback',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Display jobs search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['qmssettings/jobs/clear'] = array(
    'title' => t('Simulator Downtime Logs'),
    'page callback' => 'jobs_clear_results_callback',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Clears the cache for the search results page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['qmssettings/jobs/pager'] = array(
    'title' => t('Jobs'),
    'page callback' => 'jobs_pager_callback',
    'page arguments' => array(True),
    'access arguments' => array('view admin lists'),
    'description' => 'Display jobs page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['job/add'] = array(
    'title' => t('Add Job'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('job_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add job',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['job/edit/%'] = array(
    'title' => t('Edit Job'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('job_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit job',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['job/delete/%'] = array(
    'title' => t('Delete Job'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('job_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete job',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.jobs.inc',
  );

  $items['qmssettings/engloadupdated'] = array(
    'title' => t('Load Updated'),
    'page callback' => 'eng_load_updated_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display engineering load updated list',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engloadupdated.inc',
  );

  $items['engloadupdate/add'] = array(
    'title' => t('Add Load Updated Item'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('eng_load_updated_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Administer engineering load updated item',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engloadupdated.inc',
  );

  $items['engloadupdate/edit/%'] = array(
    'title' => t('Edit Load Updated Item'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('eng_load_updated_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Administer engineering load updated item',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engloadupdated.inc',
  );

  $items['engloadupdate/delete/%'] = array(
    'title' => t('Delete Load Updated Item'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('eng_load_updated_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Administer engineering load updated item',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.engloadupdated.inc',
  );




  $items['qmssettings/prevmaintlist'] = array(
    'title' => t('Preventative Maintenance'),
    'page callback' => 'prev_maint_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display simulator preventative maintenance schedules',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.prevmaint.inc',
  );

  $items['qmssettings/prevmaintlist/%'] = array(
    'title' => t('Preventative Maintenance'),
    'page callback' => 'prev_maint_display',
    'page arguments' => array(2),
    'access arguments' => array('view admin lists'),
    'description' => 'Display simulator preventative maintenance schedules',
    'type' => MENU_CALLBACK,
    'menu_name' => 'qms-admin-menu',
    'file' => 'sabreQMS.prevmaint.inc',
  );

  $items['qmssettings/prevmaintlist/callback/%'] = array(
    'title' => t('Preventative Maintenance'),
    'page callback' => 'prev_maint_callback',
    'page arguments' => array(3),
    'access arguments' => array('view admin lists'),
    'description' => 'Refresh simulator preventative maintenance schedules',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.prevmaint.inc',
  );

  $items['prevmaint/add/%'] = array(
    'title' => t('Add Preventative Maintenance Item'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('prev_maint_form', 2, ''),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add Preventative Maintenance Item',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.prevmaint.inc',
  );

  $items['prevmaint/edit/%/%'] = array(
    'title' => t('Edit Preventative Maintenance Item'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('prev_maint_form', '', 3),			//'simulator_id / prev_maint_id'
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit Preventative Maintenance Item',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.prevmaint.inc',
  );

  $items['prevmaint/delete/%/%'] = array(
    'title' => t('Delete Preventative Maintenance Item'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('prev_maint_delete_confirm', 3),  //'simulator_id / prev_maint_id'
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete Preventative Maintenance Item',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.prevmaint.inc',
  );

  // QMS config settings

  $items['qmssettings/qmsconfig'] = array(
    'title' => t('QMS Configuration Settings'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qms_config_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QMS Configuration Settings',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qmsconfig.inc',
  );


  // QTG Plans
  $items['qmssettings/qtg'] = array(
    'title' => t('QTG Test Plans'),
    'page callback' => 'qtg_test_plan_display',
    //'page arguments' => array('qtg_group_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QTG Test Plans',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  // QTG Tests
  $items['qmssettings/qtg'] = array(
    'title' => t('QTG Test Settings'),
    'page callback' => 'qtg_test_plan_display',
    //'page arguments' => array('qtg_group_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QTG Plans',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  // QTG Page Tabs
  $items['qmssettings/qtg/plans'] = array(
    'title' => t('Test Plans'),
    'page callback' => 'qtg_test_plan_display',
    'page arguments' => array(
      'vars' => array(
        'title' => t('QTG Test Settings'),
      ),
    ),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QTG Test Settings',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
    'file' => 'sabreQMS.qtgadmin.inc',
  );

  $items['qmssettings/qtg/engines'] = array(
    'title' => t('Engines'),
    'page callback' => 'qtg_engine_display',
    'page arguments' => array(
      'vars' => array(
        'title' => t('QTG Test Settings'),
      ),
    ),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QTG Test Settings',
    'type' => MENU_LOCAL_TASK,
    'weight' => 4,
    'file' => 'sabreQMS.qtgadmin.inc',
  );

  $items['qmssettings/qtg/tests'] = array(
    'title' => t('Tests'),
    'page callback' => 'qtg_test_display',
    'page arguments' => array(
      'vars' => array(
        'title' => t('QTG Test Settings'),
      ),
    ),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QTG Test Settings',
    'type' => MENU_LOCAL_TASK,
    'weight' => 8,
    'file' => 'sabreQMS.qtgadmin.inc',
  );

  $items['qmssettings/qtg/schedules'] = array(
    'title' => t('Test Schedules'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'qtg_schedules_form',
      'vars' => array(
        'title' => t('QTG Test Settings'),
      ),
    ),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'QTG Test Settings',
    'type' => MENU_LOCAL_TASK,
    'weight' => 12,
    'file' => 'sabreQMS.qtgadmin.inc',
  );



  // QTG Test Plans -- Add/Edit/Delete
  $items['qtg/plan/add'] = array(
    'title' => t('Add QTG Test Plan'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_plan_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add QTG Test Plan',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  
  $items['qtg/plan/edit/%'] = array(
    'title' => t('Edit QTG Test Plan'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_plan_form', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit QTG Test Plan',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  
  $items['qtg/plan/delete/%'] = array(
    'title' => t('Delete QTG Test Plan'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_plan_delete_confirm', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete QTG Test Plan',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );

  // QTG Engines -- Add/Edit/Delete
  $items['qtg/engine/add'] = array(
    'title' => t('Add QTG Engine'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_engine_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add QTG Engine',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  $items['qtg/engine/edit/%'] = array(
    'title' => t('Edit QTG Engine'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_engine_form', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit QTG Engine',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  $items['qtg/engine/delete/%'] = array(
    'title' => t('Delete QTG Engine'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_engine_delete_confirm', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete QTG Engine',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );

  // QTG Tests -- Add/Edit/Delete
  $items['qtg/test/add'] = array(
    'title' => t('Add QTG Test'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add QTG Test',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  $items['qtg/test/edit/%'] = array(
    'title' => t('Edit QTG Test'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_form', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit QTG Test',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );
  $items['qtg/test/delete/%'] = array(
    'title' => t('Delete QTG Test'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('qtg_test_delete_confirm', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete QTG Test',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.qtgadmin.inc',
  );



  // QTG Test Schedules - Edit
//  $items['qtg/test/schedule/%/%'] = array(
//	  'title' => t('Edit QTG Test Schedule'),
//	  'page callback' => 'drupal_get_form',
//		'page arguments' => array('qtg_test_schedule_form', 3, 4), // test plan id, test id
//	  'access arguments' => array('administer sabreQMS'),
//	  'description' => 'Edit QTG Test Plan',
//	  'type' => MENU_CALLBACK,
//		'file' => 'sabreQMS.qtgadmin.inc',
//	);



  // Simulators

  $items['qmssettings/simulators'] = array(
    'title' => t('Simulators'),
    'page callback' => 'simulators_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display simulators',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/add'] = array(
    'title' => t('Add Simulator'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('simulator_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add simulator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/edit/%'] = array(
    'title' => t('Edit Simulator'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('simulator_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit simulator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/delete/%'] = array(
    'title' => t('Delete Simulator'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('simulator_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete simulator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/notify/addupdate'] = array(
    'title' => t('Add or Update Simulator Notification'),
    'page callback' => 'simulator_add_update_notification_callback',
    //'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add or Update simulator notification',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/notify/remove/%'] = array(
    'title' => t('Remove Simulator Notification'),
    'page callback' => 'simulator_remove_notification_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Remove simulator notification',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/notify/refresh'] = array(
    'title' => t('Refresh Simulator Notification Table'),
    'page callback' => 'simulator_notification_table_refresh_callback',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Refresh simulator notification table',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  $items['simulator/notify/%'] = array(
    'title' => t('Get Simulator Notification'),
    'page callback' => 'get_simulator_notification_callback',
    'page arguments' => array(2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Get simulator notification record',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulators.inc',
  );

  /*----------- Simulator Files -----------------*/

  $items['simulator/file/download/%'] = array(
    'title' => t('Download Simulator File'),
    'page callback' => 'simulator_file_download',
    'page arguments' => array(3),
    'access callback' => array(True),
    'description' => 'Download file attached to simulator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatorfiles.inc',
  );

  $items['simulator/file/delete/%'] = array(
    'title' => t('Delete Simulator File'),
    'page callback' => 'simulator_file_delete_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete file attached to simulator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatorfiles.inc',
  );

  $items['simulator/file/add/%'] = array(
    'title' => t('Attach Files to Simulator'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('file_upload_plupload_form', 'SI', 3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add file to shift log',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatorfiles.inc',
  );

  $items['simulator/file/orig/add/%'] = array(
    'title' => t('Attach Files to Simulator'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('file_upload_orig_form', 'SI', 4),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add file to simulator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.simulatorfiles.inc',
  );

  // Trouble Causes

  $items['qmssettings/trouble_causes'] = array(
    'title' => t('Trouble Causes'),
    'page callback' => 'trouble_causes_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display ATA Chapters',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecauses.inc',
  );

  $items['trouble_cause/add'] = array(
    'title' => t('Add Trouble Cause'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('trouble_cause_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add Trouble Cause',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecauses.inc',
  );

  $items['trouble_cause/edit/%'] = array(
    'title' => t('Edit Trouble Cause'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('trouble_cause_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit Trouble Cause',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecauses.inc',
  );

  $items['trouble_cause/delete/%'] = array(
    'title' => t('Delete Trouble Cause'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('trouble_cause_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete Trouble Cause',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.troublecauses.inc',
  );




  // User Groups

  $items['qmssettings/usergroups'] = array(
    'title' => t('User Groups'),
    'page callback' => 'user_groups_display',
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Display user groups for email notifications',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );

  $items['usergroup/add'] = array(
    'title' => t('Add User Group'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_group_form'),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add User Group for simulator activity email notifications',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );

  $items['usergroup/edit/%'] = array(
    'title' => t('Edit User Group'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_group_form', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Edit user group for simulator activity email notifications',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );

  $items['usergroup/delete/%'] = array(
    'title' => t('Delete User Group'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_group_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete user group',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );

  $items['usergroup/user/add'] = array(
    'title' => t('Add User to Group'),
    'page callback' => 'user_group_add_user_callback',
    //'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Add user to group',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );

  $items['usergroup/user/remove/%'] = array(
    'title' => t('Remove User from Group'),
    'page callback' => 'user_group_remove_user_callback',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Remove user from group',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );

  $items['usergroup/user/refresh'] = array(
    'title' => t('Refresh Users Table'),
    'page callback' => 'user_group_user_table_refresh_callback',
    //'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Refresh users table',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.usergroups.inc',
  );




  // User Feedback

  $items['feedback'] = array(
    'title' => t('User Feedback Log'),
    'page callback' => 'user_feedback_display',
    'access arguments' => array('view admin lists'),
    'description' => 'Display user feedback log',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'qms-settings-menu',
    'weight' => 0,
    //'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.userfeedback.inc',
  );

  $items['feedback/pager'] = array(
    'title' => t('User Feedback Log'),
    'page callback' => 'user_feedback_display',
    'page arguments' => array(True),
    'access arguments' => array('view admin lists'),
    'description' => 'Display user feedback log page',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.userfeedback.inc',
  );

  $items['feedback/send/%'] = array(
    'title' => t('User Feedback Log'),
    'page callback' => 'email_feedback_to_admin',
    'page arguments' => array(2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Resend the selected user feedback to the currently logged in administrator',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.userfeedback.inc',
  );

  $items['feedback/delete/%'] = array(
    'title' => t('Delete Feedback'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_feedback_delete_confirm', 2),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Delete user feedback',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.userfeedback.inc',
  );

  // ------------ Reports -----------------------

  $items['reports/alerts'] = array(
    'title' => t('QMS Alerts'),
    'page callback' => 'QMS_alerts',
    //'page arguments' => array(),
    'access arguments' => array('search view reports'),
    'description' => 'QMS Alerts',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/discrepancy_early_warning'] = array(
    'title' => t('Discrepancy Early Warning'),
    'page callback' => 'discrepancy_early_warning_report',
    'page arguments' => array(
      'vars' => array(
        'pager' => False,
        'filter' => False,
      ),
    ),
    'access arguments' => array('search view reports'),
    'description' => 'Discrepancy Early Warning of DRs in need of being closed.',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/discrepancy_early_warning/filter'] = array(
    'title' => t('Discrepancy Early Warning'),
    'page callback' => 'discrepancy_early_warning_report',
    'page arguments' => array(
      'vars' => array(
        'pager' => False,
        'filter' => True,
      ),
    ),
    'access arguments' => array('search view reports'),
    'description' => 'Discrepancy Early Warning of DRs in need of being closed, get page.',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/discrepancy_early_warning/pager'] = array(
    'title' => t('Discrepancy Early Warning'),
    'page callback' => 'discrepancy_early_warning_report',
    'page arguments' => array(
      'vars' => array(
        'pager' => True,
        'filter' => False,
      ),
    ),
    'access arguments' => array('search view reports'),
    'description' => 'Discrepancy Early Warning of DRs in need of being closed, get page.',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/qtgexpiring'] = array(
    'title' => t('QTG Expiring'),
    'page callback' => 'qtg_expiring_report',
    'page arguments' => array(
      'vars' => array(
        'pager' => False,
        'filter' => False,
      ),
    ),
    'access arguments' => array('search view reports'),
    'description' => 'QTG tests expiring.',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/qtgexpiring/pager'] = array(
    'title' => t('QTG Expiring'),
    'page callback' => 'qtg_expiring_report',
    'page arguments' => array(
      'vars' => array(
        'pager' => True,
        'filter' => False,
      ),
    ),
    'access arguments' => array('search view reports'),
    'description' => 'QTG tests expiring.',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/qtgexpiring/filter'] = array(
    'title' => t('QTG Expiring'),
    'page callback' => 'qtg_expiring_report',
    'page arguments' => array(
      'vars' => array(
        'pager' => False,
        'filter' => True,
      ),
    ),
    'access arguments' => array('search view reports'),
    'description' => 'QTG tests expiring.',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/time_worked'] = array(
    'title' => t('Time Worked Report'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('time_worked_report_form'),
    'access arguments' => array('search view reports'),
    'description' => 'Display options to display Job Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/timesheet/export/%'] = array(
    'title' => t('Timesheet Export'),
    'page callback' => 'timesheet_export',
    'page arguments' => array(3),
    'access arguments' => array('administer sabreQMS'),
    'description' => 'Export timesheet data into a format compatible with QuickBooks',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/get_jobs'] = array(
    'title' => t('Time Worked Report'),
    'page callback' => 'get_employee_jobs',
    'access arguments' => array('search view reports'),
    'description' => 'Callback to retrieve jobs for a specific employee',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/time_worked_report'] = array(
    'title' => t('Time Worked Report'),
    'page callback' => 'get_time_worked_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display options to display Job Time Worked Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/activity24'] = array(
    'title' => t('24 Hour Activity Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_24HR_ACTIVITY, '0'),
    'access arguments' => array('search view reports'),
    'description' => 'Display 24 Hour Activity Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/activity24/%'] = array(
    'title' => t('24 Hour Activity Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_24HR_ACTIVITY, 2),
    'access arguments' => array('search view reports'),
    'description' => 'Display 24 Hour Activity Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/activity24/%/%'] = array(
    'title' => t('24 Hour Activity Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_24HR_ACTIVITY, 2, 3),
    'access arguments' => array('search view reports'),
    'description' => 'Display 24 Hour Activity Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/activity72'] = array(
    'title' => t('72 Hour Activity Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_72HR_ACTIVITY, '0'),
    'access arguments' => array('search view reports'),
    'description' => 'Display 72 Hour Activity Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/activity72/%'] = array(
    'title' => t('72 Hour Activity Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_72HR_ACTIVITY, 2),
    'access arguments' => array('search view reports'),
    'description' => 'Display 72 Hour Activity Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/activity72/%/%'] = array(
    'title' => t('72 Hour Activity Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_72HR_ACTIVITY, 2, 3),
    'access arguments' => array('search view reports'),
    'description' => 'Display 72 Hour Activity Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/open_discrepancies'] = array(
    'title' => t('Open Discrepancies Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_OPEN_DISCREPANCY, '0'),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Open Discrepancy Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/open_discrepancies/%'] = array(
    'title' => t('Open Discrepancies Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_OPEN_DISCREPANCY, 2),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Open Discrepancy Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/open_discrepancies/%/%'] = array(
    'title' => t('Open Discrepancies Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_OPEN_DISCREPANCY, 2, 3),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Open Discrepancy Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/open_mmi'] = array(
    'title' => t('Open MMI Discrepancies Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_OPEN_MMI, '0'),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Open MMI Discrepancies Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/open_mmi/%'] = array(
    'title' => t('Open MMI Discrepancies Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_OPEN_MMI, 2),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Open MMI Discrepancies Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/open_mmi/%/%'] = array(
    'title' => t('Open MMI Discrepancies Report'),
    'page callback' => 'discrepancies_report',
    'page arguments' => array(QMS_RPT_OPEN_MMI, 2, 3),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Open MMI Discrepancies Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/simulator_downtime'] = array(
    'title' => t('Simulator Downtime/Uptime Report'),
    'page callback' => 'simulator_downtime_report',
    'page arguments' => array('0', ''),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Simulator Downtime/Uptime Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );
  /*
  $items['reports/simulator_downtime/%/%'] = array(
    'title' => t('Simulator Downtime/Uptime Report'),
    'page callback' => 'simulator_downtime_report',
    'page arguments' => array(2, 3, '1'),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Simulator Downtime/Uptime Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );
  */

  $items['reports/simulator_downtime/%/%'] = array(
    'title' => t('Simulator Downtime/Uptime Report'),
    'page callback' => 'simulator_downtime_report',
    'page arguments' => array(2, 3),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Simulator Downtime/Uptime Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/simulator_reliability'] = array(
    'title' => t('Simulator Reliability Report'),
    'page callback' => 'simulator_reliability_report',
    'page arguments' => array('0', '0'),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Simulator Reliability Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/simulator_reliability/%/%/%/%'] = array(
    'title' => t('Simulator Reliability Report'),
    'page callback' => 'simulator_reliability_report',
    'page arguments' => array(2, 3, 4, 5),
    'access arguments' => array('search view reports'),
    'description' => 'Display the Simulator Reliability Report',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/discrepancies/selected'] = array(
    'title' => t('Discrepancy Log Report'),
    'page callback' => 'discrepancies_selected_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display a report of discrepancies selected from search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/troublecalls/selected'] = array(
    'title' => t('Trouble Call Log Report'),
    'page callback' => 'trouble_calls_selected_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display a report of trouble calls selected from search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/shiftlog/selected'] = array(
    'title' => t('Shift Log Report'),
    'page callback' => 'shiftlog_selected_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display a report of engineering log entries selected from search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );


  $items['reports/engineering/selected'] = array(
    'title' => t('Engineering Log Report'),
    'page callback' => 'engineering_selected_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display a report of engineering log entries selected from search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['reports/qtg/selected'] = array(
    'title' => t('QTG Test Event Report'),
    'page callback' => 'qtg_selected_report',
    'access arguments' => array('search view reports'),
    'description' => 'Display a report of QTG events selected from search results',
    'type' => MENU_CALLBACK,
    'file' => 'sabreQMS.reports.inc',
  );

  $items['home/employee'] = array(
    'title' => t('Welcome'),
    'page callback' => 'display_home_page_employee',
    'access arguments' => array('search view reports'),
    'description' => 'Sabre Updates employee home page',
    'type' => MENU_CALLBACK,
    //'file' => 'sabreQMS.reports.inc',
  );
  /*
  $items['log_managed_file'] = array(
    'title' => t('Log Managed File'),
    'page callback' => 'log_managed_file',
    'access arguments' => array('access sabreQMS'),
    'description' => '',
    'type' => MENU_CALLBACK,
  );
  */


  return $items;
}

/*
 * ----------- CUSTOM MENUS --------------
 *
 */


/*
 * display_home_page_employee()
 *
 */
function display_home_page_employee() {

  if ( user_access('search view reports') == FALSE ) {
    drupal_set_message( t('Unauthorized:  Permission is required'), 'status');
    return;
  }

  $content =
    '<p>This is the Quality Management System.  ' .
    'Some useful links are listed below:</p>' .
    '<dl class="admin-list">';

  if ( user_access('punch clock') || user_access('create shift log') ) {
    $content .=  '<dt><strong>Utility</strong></dt>';

    if ( user_access('punch clock') ) {
      $content .= '<dd><a href="' . url('punchclock') . '">Punch Clock</a></dd>';
    }
    if ( user_access('create shift log') ) {
      $content .=
        '<dd><a href="' . url('shiftlog') .
              '">Shift Log - New Entry</a><br /><br /></dd>';
    }
  }

  $content .=
    '<dt><strong>Reports</strong></dt>' .
    '<dd><a href="' . url('reports/discrepancy_early_warning') . '">Discrepancy Early Warning</a></dd>' .
     '<dd><a href="' . url('reports/activity24') . '">24 Hour Activity Report</a></dd>' .
    '<dd><a href="' . url('reports/activity72') . '">72 Hour Activity Report</a></dd>' .
    '<dd><a href="' . url('reports/open_discrepancies') . '">Open Discrepancies</a></dd>' .
    '<dd><a href="' . url('reports/open_mmi') . '">Open MMI Discrepancies</a></dd>' .
    '<dd><a href="' . url('reports/qtgexpiring') . '">QTG Tests Expiring Report</a></dd>' .
    '<dd><a href="' . url('reports/simulator_downtime') . '">Simulator Downtime/Uptime</a></dd>' .
    '<dd><a href="' . url('reports/simulator_reliability') . '">Simulator Reliability</a></dd>' .
    '<dd><a href="' . url('reports/time_worked') . '">Time Worked Report</a></dd>' .
    '</dl>';

  return $content;
}


/*
 * display_qms_settings_menu()
 *
 */
function display_qms_settings_menu() {

  if ( user_access('view admin lists') == FALSE ) {
    drupal_set_message( t('Unauthorized:  Permission is required'), 'status');
    return;
  }

  global $user;
  $is_customer = _user_is_customer($user->uid);

  $admin = user_access('administer sabreQMS');

  //------ build QMS Settings Menu ---------

  $content = '<dl class="admin-list">';

  if ( !$is_customer ) {

    $content .=
      '<dt><a href="' . url('qmssettings/atachapters') . '">ATA Chapters</a></dt>' .
      '<dd>Administer ATA Chapters</dd>';

    $content .=
      '<dt><a href="' . url('qmssettings/corrective_actions') . '">Corrective Actions</a></dt>' .
      '<dd>Administer Corrective Actions</dd>';

    $content .=
      '<dt><a href="' . url('qmssettings/customers') . '">Customers</a></dt>' .
      '<dd>Administer Customers</dd>';
  }


  if ( !$is_customer ) {
    $content .=
      '<dt><a href="' . url('qmssettings/jobs') . '">Jobs</a></dt>' .
      '<dd>Administer Jobs</dd>';
  }

  if ( !$is_customer ) {
    $content .=
      '<dt><a href="' . url('qmssettings/engloadupdated') . '">Load Updated Items</a></dt>' .
      '<dd>Administer Engineering Load Updated items</dd>';

    $content .=
      '<dt><a href="' . url('qmssettings/prevmaintlist') . '">Preventative Maintenance</a></dt>' .
      '<dd>Administer Preventative Maintenance profiles</dd>';
  }

  // this is for admins only
  if ( $admin ) {
    $content .=
      '<dt><a href="' . url('qmssettings/punchclockevents') . '">Punch Clock Events</a></dt>' .
      '<dd>Administer employee punch clock events</dd>';

    $content .=
      '<dt><a href="' . url('qmssettings/qmsconfig') . '">QMS Configuration</a></dt>' .
      '<dd>Administer QMS system features</dd>';


    $content .=
      '<dt><a href="' . url('qmssettings/qtg') . '">QTG Tests</a></dt>' .
      '<dd>Administer QTG Tests</dd>';


  }

  $content .=
    '<dt><a href="' . url('qmssettings/simulators') . '">Simulators</a></dt>' .
    '<dd>Administer Simulators</dd>';


  // this is for admins only
  if ( $admin ) {
    $content .=
      '<dt><a href="' . url('qmssettings/trouble_causes') . '">Trouble Causes</a></dt>' .
      '<dd>Administer Trouble Causes</dd>';

    $content .=
      '<dt><a href="' . url('admin/people') . '">User Accounts</a></dt>' .
      '<dd>Administer User Accounts</dd>';

    $content .=
      '<dt><a href="' . url('qmssettings/usergroups') . '">User Groups</a></dt>' .
      '<dd>Administer User Email Notification Groups</dd>';

  }

  if ( !$is_customer ) {
    $content .=
      '<dt><a href="' . url('feedback') . '">User Feedback Log</a></dt>' .
      '<dd>Review User Feedback Log</dd>';
  }

  $content .= '</dl>';

  return $content;
}

/*
 * display_qms_settings_menu()
 *
 */
function display_search_menu_list() {

  if ( user_access('view admin lists') == FALSE ) {
    drupal_set_message( t('Unauthorized:  Permission is required'), 'status');
    return;
  }

  $content =
    '<dl class="admin-list">'.
    '<dt><a href="' . url('search/discrepancies') . '">Discrepancy Logs</a></dt>' .
    '<dd>Search Discrepancy Logs</dd>' .
    '<dt><a href="' . url('search/troublecalls') . '">Trouble Call Logs</a></dt>' .
    '<dd>Search Trouble Call Logs</dd>' .
    '<dt><a href="' . url('search/shiftlogs') . '">Shift Logs</a></dt>' .
    '<dd>Search Shift Logs</dd>' .
    '<dt><a href="' . url('search/engineering') . '">Engineering Logs</a></dt>' .
    '<dd>Search Engineering Logs</dd>' .
    '<dt><a href="' . url('search/simulator_downtime') . '">Simulator Downtime Logs</a></dt>' .
    '<dd>Search Simulator Downtime Logs</dd>' .
    '<dt><a href="' . url('search/qtg') . '">QTG Reports</a></dt>' .
    '<dd>Search QTG Reports</dd>' .
    '<dt><a href="' . url('search/vendors') . '">Vendors</a></dt>' .
    '<dd>Search Vendors</dd>' .
    '</dl>';

  return $content;
}


//---------------- BLOCKS ---------------------------------
// generic blocks now being handled by sabreTools


/*
 * sabreQMS_block_list_alter()
 *
 * implements hook_block_list_alter()
 * Drupal won't allow you to delete system blocks or add new ones directly through the database ( it disregards direct db updates)
 * From here we can override the existing blocks before rendering
 *
 *	Unfortunately, this is the only way to manage block displays.
 * Direct DB edits fail as the system core will supercede anything you attempt to update
 */

function sabreQMS_block_list_alter(&$blocks) {

  /*
  foreach ($blocks as $bid => $block) {

    //  ---------- SABRE TOOLS handles this part
    // adjust the menu blocks
    if ($block->module == 'system') {

      // hide the navigation menu block
      if ( $block->delta == 'navigation') {
        $blocks[$bid]->region = -1;
      }
      // hide the default footer block "Powered By Drupal"
      else if ( $block->delta == 'powered-by') {
        $blocks[$bid]->region = -1;
      }
    }

  }
  */

  // now add on our sabreQMS menu blocks
  $block = block_load('menu', 'qms-menu');
  $blocks[$block->bid] = $block;
  $blocks[$block->bid]->region = 'sidebar_first';
  $blocks[$block->bid]->weight = -9;
  unset($block);

  $block = block_load('menu', 'qms-search-menu');
  $blocks[$block->bid] = $block;
  $blocks[$block->bid]->region = 'sidebar_first';
  $blocks[$block->bid]->weight = -8;
  unset($block);

  $block = block_load('menu', 'qms-admin-menu');
  $blocks[$block->bid] = $block;
  $blocks[$block->bid]->region = 'sidebar_first';
  $blocks[$block->bid]->weight = -7;
}

/*
 * sabreQMS_block_info()
 *
 * implements hook_block_info()
 */
/*
function sabreQMS_block_info() {
  $blocks['user_account_bar'] = array(
    'info' => t('User Account Bar'),
    'status' => True,
    'region' => 'header',
    'weight' => -10,
    'cache' => DRUPAL_NO_CACHE,
  );
  $blocks['no_javascript'] = array(
    'info' => t('SCRIPTS DISABLED!'),
    'title' => t('SCRIPTS DISABLED!'),
    'status' => True,
    'region' => 'sidebar_first',
    'weight' => -10,
    //'cache' => DRUPAL_CACHE,
  );
  return $blocks;
}
*/

/*
 * sabreQMS_block_view()
 *
 * implements hook_block_view()
 */
/*
function sabreQMS_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'user_account_bar':
    case 'no_javascript':
    //case 'qms-menu':
    //case 'qms-search-menu':
    //case 'qms-admin-menu':
      $block['content'] = sabreQMS_block_contents($delta);
      break;
  }
  return $block;
}
*/


/*
 * sabreQMS_block_contents()
 *
 * implements hook_block_contents()
 */

//don't allow block caching in admin > config > performance
// will sometimes display last user
/*
function sabreQMS_block_contents($which_block) {
  $block = array();

  switch ($which_block) {
    case 'user_account_bar':
      global $user;
      if ( isset($user) && isset($user->uid) && isset($user->name) ) {
        $block = array(
          '#markup' => l( "Hello, " . $user->name, 'user') . "&nbsp;&nbsp;|&nbsp;&nbsp;" . l( "Log out", 'user/logout'),
        );
      }
      break;
    case 'no_javascript':
      $block = array(
          '#markup' => '<p>SORRY.  Javascript has not been detected.  This may due to browser settings or  anti-virus software with script blocking.</p> <p>QMS requires javascript in order to function properly.  Please enable javascript and try to access QMS again or contact the site administrator for help.</p>',
        );
      break;
  }
  return $block;
}
*/


/*
 *  adjust display of block for scheduler (when it's connecting to QMS)
 *
 */
//function sabreQMS_block_view_alter(&$data, $block) {
//  $debug = 1;
//  if ( $block->delta == 'no_javascript') {
//    $block->region = 'sidebar_second';
//  }
//
//}





/*
 *    confirm_form FIX
 *
 *    sabreQMS_form_alter()
 *
 *    convert all confirm_form 'Cancel' links to buttons and
 *    redirects the link href on button submit
 *    forces submit button style to bold for all forms
 *
 */

function sabreQMS_form_alter(&$form, &$form_state, &$form_id) {
  // Converting all links to form buttons
  if (isset($form['#theme']) && ($form['#theme'] == 'confirm_form')) {
    $cancel_href = $form['actions']['cancel']['#href'];
    $cancel_title = $form['actions']['cancel']['#title'];
    if (!is_null($cancel_href)) {
//-+ REPLACED:
      $form['actions']['cancel']['#href'] = '';
//-+ Hide the old cancel link
      // Add our own button
      $form['actions']['cancel'] = array(
        '#type' => 'button',
        '#value' => $cancel_title,
        '#attributes' => array('onclick' => 'window.location="' . url($cancel_href) . '"; return false;'),
      );
      // needs to be set before confirm_form is called or wrong path triggered
      //$_GET['destination'] = $cancel_href;
    }

  }

  // this applies to ALL form submit buttons in QMS
  //$form['actions']['submit']['#attributes']['class'][] = 'qms-btn-submit';
  if ( isset($form['actions']['submit'])) {
    $form['actions']['submit']['#attributes']['style'] = 'font-weight:bolder;';
  }

  return $form;
}




/*
 * 	search_shiftlog_access_callback()
 *
 *   component to work with 'access callback' property of hook_menu()
 */
/*
function search_shiftlog_access_callback() {
  // don't display shift log search if user is a customer
  //global $user;
  //return ( (_user_is_customer($user->uid) > 0) ? False : user_access('search view reports') );
  return ( user_access('search view reports') );

}
*/

/*
 *	log_managed_file()
*/
/*
function log_managed_file() {

  global $user;
  global $base_path;

  $temp_file->uid = $user->uid;
  $temp_file->filename = $_POST['filename'];
  $filepath = "../../../" . QMS_TEMP_DIR . $temp_file->filename;
  //$temp_file->filemime = mime_content_type($filepath);
  $temp_file->filesize = filesize($filepath);
  $temp_file->uri = "temporary://" . $temp_file->filename;
  $temp_file->status = 0;
  $temp_file->timestamp = time();

  if ( $temp_file->filesize > 0 ) {
    file_save($temp_file);
  }

  return drupal_json_output(array(
                            'fid' => $temp_file->fid,
                            ));
}
*/

/*  ------------------------------------------------------------------------------------------------
 *	sabreQMS_cron()
 *
 *	implements hook_cron()
 *  Process preventative maintenance tasks
 */

function sabreQMS_cron() {

  //$last_run = variable_get('sabreQMS_cron_last_run', REQUEST_TIME);
  $cron_run_interval = variable_get('cron_safe_threshold', 3600);	// default to an hour interval

  // determine look ahead interval
  $threshold_time = REQUEST_TIME + $cron_run_interval;

  //------------- PREVENTATIVE MAINTENANCE -------------------
  _create_prev_maint_discrepancies($threshold_time);

  //------------- QTG TEST EVENTS ----------------------------
  _create_qtg_test_events($threshold_time);


  variable_set('sabreQMS_cron_last_run', REQUEST_TIME);
}

//--------------------------- PREVENTATIVE MAINT --------------------------------
/*
 *    _create_prev_maint_discrepancies()
 *
 *  $threshold_time passed in from sabreQMS_cron
 */

function _create_prev_maint_discrepancies($threshold_time) {
  try {

    // select every PM task that comes before the next cron run
    $query = db_select('qms_prev_maint', 'p')
             ->condition('next_pm_datetime', $threshold_time, '<');

    $f = $query->fields('p', array( 'prev_maint_id',
                                    'simulator_id',
                                    'pm_text',
                                    'next_pm_datetime',
                                    'frequency',
                                    'repeat_count',
                                    'repeats_on',
                                    'preflight',
                                  ));
    $result = $query->execute();
    
    $row_count = (int)$result->rowCount();
    watchdog('sabreQMS', "Prev Maint Events Found: $row_count", array(), WATCHDOG_DEBUG);

    if ( $row_count > 0 ) {

      foreach ($result as $row) {

        // create a new DR for each PM task that is due
        $discrepancy = new stdClass();
        $baseno = _st_generate_report_base_no('DR');

        $discrepancy->dr_no = _st_generate_report_no('DR', $baseno);
        $discrepancy->tech_user_id = 0; //unassigned
        $discrepancy->simulator_id = $row->simulator_id;
        $discrepancy->discrepancy = $row->pm_text;
        $discrepancy->date_opened = $row->next_pm_datetime;
        $discrepancy->is_pm = 1;
        
        $discrepancy->preflight = $row->preflight;
        
        // sending the preflight email now
        $discrepancy->preflight_email_sent = 1;

        $discrepancy->ata_chapter_id = (($row->preflight) ?
                QMS_ATACHAPTER_PREFLIGHT : QMS_ATACHAPTER_PREVMAINT);
        $discrepancy->created_date = REQUEST_TIME;
        $discrepancy->updated_date = REQUEST_TIME;

        drupal_write_record('qms_discrepancy_log', $discrepancy);  // add the DR

        // send out email notices for new DRs
        _discrepancy_add_update_post_processing($discrepancy->discrepancy_id);

        //update the record for the next pm task datetime

        $pm_item = new stdClass();
        $pm_item->prev_maint_id = $row->prev_maint_id;
        $pm_item->next_pm_datetime = 
             _calc_next_pm_schedule_date($row->frequency, 
                                         $row->repeat_count, 
                                         $row->repeats_on,
                                         (int)$row->next_pm_datetime);
                                        // date('Y-m-d H:i:s', $row->next_pm_datetime));
                                         
        drupal_write_record('qms_prev_maint', $pm_item, 'prev_maint_id');	  // update the PM
        
        watchdog('sabreQMS', "PrevMaint: \n" . var_export((array)$pm_item, True),
                             array(), WATCHDOG_DEBUG);
                             //"\nDiscrepancy: \n" . var_export($discrepancy, True),
                             
        
        
          
        unset($discrepancy);
        unset($pm_item);
      }
    }
  }
  catch (Exception $e) {
    watchdog('sabreQMS', '_create_prev_maint_discrepancies()' . $e->getMessage(),
              array(), WATCHDOG_ERROR);
  }
}

//--------------------------- QTG TEST EVENTS --------------------------------
/*
 *  _create_qtg_test_events()
 *
 *  $threshold_time passed in from sabreQMS_cron
 */
function _create_qtg_test_events($threshold_time) {
  try {

    // select every PM task that comes before the next cron run
    $query = db_select('qms_qtg_groups', 'g');
    $query->innerJoin('qms_qtg_test_plans', 'p', 'p.qtg_test_plan_id = g.qtg_test_plan_id');
    $query->condition('g.next_event', $threshold_time, '<');
    $query->condition('p.active', 1);

    $query->fields('g', array('qtg_group_id',
                              'qtg_test_plan_id',
                              'group_name',
                              'next_event',
                            ));
    $result = $query->execute();

    if ( $result->rowCount() ) {

      $qtg_test_groups = $result->fetchAll();

      foreach ($qtg_test_groups as $group) {

        $test_list = _get_qtg_groups_tests($group->qtg_group_id);

        if ( count($test_list) ) {
          // don't create a QTG Event if there are no tests to include

          // create a new Test Event for each Test Group that is due
          $event = new stdClass();
          $baseno = _st_generate_report_base_no('QTG');

          $event->qtg_no = _st_generate_report_no('QTG', $baseno);
          $event->qtg_test_plan_id = $group->qtg_test_plan_id;
          $event->qtg_group_id = $group->qtg_group_id;

          $event->created_date = REQUEST_TIME;
          //$discrepancy->updated_date = REQUEST_TIME;

          drupal_write_record('qms_qtg_events', $event);  // add the QTG Event

          if ( $event->qtg_event_id ) {
            // event created successfully, store the tests items with it

            foreach($test_list as $t) {
              $event_test = new stdClass();
              $event_test->qtg_event_id = $event->qtg_event_id;
              $event_test->qtg_test_id = $t->qtg_test_id;
              $event_test->current_status = QMS_QTG_STATUS_NOT_RUN;

              // add the QTG Event Tests
              drupal_write_record('qms_qtg_event_tests', $event_test);

              $status_history = new stdClass();
              $status_history->qtg_event_id = $event->qtg_event_id;
              $status_history->qtg_test_id = $t->qtg_test_id;
              $status_history->test_status = QMS_QTG_STATUS_NOT_RUN;
              $status_history->note_text = '';
              $status_history->created_date = REQUEST_TIME;
              //$status_history->updated_by_user = 1;

              // add the first test status entry
              drupal_write_record('qms_qtg_test_status_history', $status_history);
            }


            // update the record for the next event
            //$curr_event = _st_format_date($group->next_event, 'custom', 'Y-m-d H:i:s');
            //$group->next_event = strtotime($curr_event . ' + 1 year');
            
            $group->next_event = _st_modify_timestamp($group->next_event, '+1 year');
            drupal_write_record('qms_qtg_groups', $group, 'qtg_group_id');
          }
        }

      }
    }
  }
  catch (Exception $e) {
    watchdog('sabreQMS', '_create_qtg_test_events()' . $e->getMessage(),
              array(), WATCHDOG_ERROR);
  }
}
