function perform()
 {
     // don't lose the db!
     $db = $_REQUEST['db'];
     if (isset($_POST['all'])) {
         $location_id = $_POST['all'];
     } else {
         $location_id = $_POST['visible'];
     }
     $short_name = $_POST['library'];
     $lib_f = new LibraryFinder($db);
     $library = $lib_f->getLibraryByName($short_name);
     $library_id = $library['library_id'];
     $lf = new LocationFinder($db);
     $location_name = $lf->getLocation($location_id);
     if (isset($_POST['add'])) {
         $add = $lf->addBridgeItem($location_id, $library_id, $location_name);
     } elseif (isset($_POST['remove'])) {
         $remove = $lf->removeBridgeItem($location_id, $library_id);
     } elseif (isset($_POST['up'])) {
         $location_id = $_POST['visible'];
         $up = $lf->moveBridgeItemUp($location_id, $library_id);
     } elseif (isset($_POST['down'])) {
         $location_id = $_POST['visible'];
         $down = $lf->moveBridgeItemDown($location_id, $library_id);
     }
     $loa = new LibraryAdminFormAction();
     $result = $loa->perform();
     $_REQUEST['library_id'] = $library['library_id'];
     $_REQUEST['library'] = $library['short_name'];
     $_REQUEST['full_name'] = $library['full_name'];
     $_REQUEST['parent_table'] = 'locations';
     $_REQUEST['locationList'] = $lf->findByLibraryID($library['library_id']);
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Library Admin', 'content' => 'content/admin/libraryEditForm.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     // where are we?
     $uf = new UserFinder($db);
     $user = $uf->findById($_SESSION['userId']);
     $result['user'] = $user;
     $af = new AdminFinder($db);
     $adminTableList = $af->getAdminTables();
     $result['adminTables'] = $adminTableList;
     $lf = new LibraryFinder($db);
     $table = 'libraries';
     $result['everything'] = $lf->getAllLibraries();
     if (isset($_POST['library_id'])) {
         $libraryID = $_POST['library_id'];
         $library = $lf->getLibraryName($libraryID);
     } else {
         $library = $user['library_short_name'];
         $libraryID = $user['library_id'];
     }
     $af = new AdminFinder($db);
     $parent_table_data = $af->getAdminTableRow($table);
     $result['parent_table_data'] = $parent_table_data;
     return $result;
 }
 function perform()
 {
     // don't lose the db!
     $db = $_REQUEST['db'];
     // decipher finder function (add or edit)
     //echo($_POST['option_pk']);
     if (isset($_POST['save']) && $_POST['option_pk'] == 0) {
         $function = 'addOption';
     } elseif (isset($_POST['save']) && $_POST['option_pk'] != '') {
         $function = 'editOption';
     }
     // OptionAddAction
     $finder = $_POST['parent_finder'];
     $table = $_POST['parent_table'];
     $option_pk = $_POST['option_pk'];
     $option = $_POST['option'];
     $parent_pk = $_POST['parent_pk'];
     $description = $_POST['description'];
     $examples = $_POST['examples'];
     $finder = new $finder($db);
     $option = $finder->{$function}($option_pk, $option, $parent_pk, $description, $examples);
     $short_name = $_POST['library'];
     $lib_f = new LibraryFinder($db);
     $library = $lib_f->getLibraryByName($short_name);
     header('Location: optionAdminForm.do?table=' . $table);
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Add Date Criteria', 'content' => 'content/reportFormDate.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     // where are we?
     $userFinder = new UserFinder($db);
     $user = $userFinder->findById($_SESSION['userId']);
     $library = $user['library_short_name'];
     $libraryID = $user['library_id'];
     $result['library_id'] = $libraryID;
     $result['library'] = $library;
     $result['user'] = $user;
     $report_id = grwd('report_id');
     $result['report_id'] = $report_id;
     // get all the info on the reports
     $reportFinder = new ReportFinder($db);
     $reportCount = $reportFinder->getReportCount();
     $result['reportCount'] = $reportCount;
     // get the information for the chosen report by requiring Reports.php and all the reports
     $report_class_handle = new Report();
     $report_class_get = $report_class_handle->get();
     // declare the report class by using it's ID
     $report_info = new $report_id();
     $result['reportList'] = $report_info->info();
     $libraryFinder = new LibraryFinder($db);
     $result['libraryList'] = $libraryFinder->getAllLibraries();
     $locationFinder = new LocationFinder($db);
     $result['locationList'] = $locationFinder->getAllLocations();
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Library Admin	', 'content' => 'content/admin/libraryAdmin.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     // where are we?
     $uf = new UserFinder($db);
     $user = $uf->findById($_SESSION['userId']);
     $result['user'] = $user;
     $lf = new LibraryFinder($db);
     $libraryList = $lf->getAllLibraries();
     $result['libraryList'] = $libraryList;
     if (isset($_POST['library_id'])) {
         $libraryID = $_POST['library_id'];
         $library = $lf->getLibraryName($libraryID);
     } else {
         $library = $user['library_short_name'];
         $libraryID = $user['library_id'];
     }
     $result['library_id'] = $libraryID;
     $result['library'] = $library;
     $locationFinder = new LocationFinder($db);
     $result['locationList'] = $locationFinder->findByLibraryID($libraryID);
     $result['distinctLocationList'] = $locationFinder->getDistinctLocations();
     $af = new AdminFinder($db);
     $adminTableList = $af->getAdminTables();
     $result['adminTables'] = $adminTableList;
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Advanced Search', 'content' => 'content/advancedSearchForm.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     //var_dump($_REQUEST);
     // where are we?
     $userFinder = new UserFinder($db);
     $user = $userFinder->findById($_SESSION['userId']);
     $library = $user['library_short_name'];
     $libraryId = $user['library_id'];
     $result['library_id'] = $libraryId;
     $result['library'] = $library;
     $result['user'] = $user;
     // The library that got searched for last time, probably...
     $selLibId = grwd('search_library_id', $libraryId);
     $result['search_library_id'] = $selLibId;
     $libraryFinder = new LibraryFinder($db);
     $libraryList = $libraryFinder->getAllLibraries();
     array_unshift($libraryList, array('library_id' => $libraryId, 'short_name' => $user['library_short_name'], 'full_name' => $user['library_full_name']), array('library_id' => '0', 'short_name' => 'All Libraries', 'full_name' => 'All Libraries'), array('library_id' => '', 'short_name' => '----------------------------', 'full_name' => '----------------------------'));
     $result['libraryList'] = $libraryList;
     $locationFinder = new LocationFinder($db);
     $result['locationList'] = $locationFinder->getAllLocations();
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Option Admin	', 'content' => 'content/admin/optionAdminForm.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     // where are we?
     $uf = new UserFinder($db);
     $user = $uf->findById($_SESSION['userId']);
     $result['user'] = $user;
     $af = new AdminFinder($db);
     $adminTableList = $af->getAdminTables();
     $result['adminTables'] = $adminTableList;
     if (isset($_GET['table'])) {
         $table = $_GET['table'];
     }
     //echo($table);
     $result['everything'] = $af->getTableFields($table);
     //var_dump($result['everything']);
     $lf = new LibraryFinder($db);
     $libraryList = $lf->getAllLibraries();
     $result['libraryList'] = $libraryList;
     if (isset($_GET['library_id'])) {
         $libraryID = $_GET['library_id'];
         $library = $lf->getLibraryName($libraryID);
     } else {
         $library = $user['library_short_name'];
         $libraryID = $user['library_id'];
     }
     if (isset($table)) {
         $parent_table = $table;
     } else {
         $parent_table = 'locations';
     }
     $af = new AdminFinder($db);
     $parent_table_data = $af->getAdminTableRow($parent_table);
     $result['library_id'] = $libraryID;
     $result['library'] = $library;
     $parentFinder = new $parent_table_data['parent_finder']($db);
     $result['bridgeTableList'] = $parentFinder->findByLibraryID($libraryID);
     $result['parentTableList'] = $parentFinder->getDistinctList();
     $result['parent_table_data'] = $parent_table_data;
     return $result;
 }
 function perform()
 {
     // don't lose the db!
     $db = $_REQUEST['db'];
     // PatronTypeAddAction
     $patron_type = $_POST['new_option'];
     $parent_pk = $_POST['parent_pk'];
     $description = $_POST['description'];
     $examples = $_POST['examples'];
     $ptf = new PatronTypeFinder($db);
     $new_option = $ptf->addPatronType($patron_type, $parent_pk, $description, $examples);
     $short_name = $_POST['library'];
     $lib_f = new LibraryFinder($db);
     $library = $lib_f->getLibraryByName($short_name);
     $laa = new LibraryAdminAction();
     $result = $laa->perform();
     $result['library_id'] = $library['library_id'];
     $result['library'] = $library['short_name'];
     $result['full_name'] = $library['full_name'];
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : User Admin', 'content' => 'content/admin/userAdminForm.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     // where are we?
     $uf = new UserFinder($db);
     $user = $uf->findById($_SESSION['userId']);
     $result['user'] = $user;
     // Find the list of users, and flag one as selected
     // If one isn't found, use "new" as the requester id
     $userList = $uf->findUsers();
     $result['userList'] = $userList;
     $result['selId'] = grwd('selUserId', -1);
     $result['selUser'] = $uf->findById($result['selId']);
     if (!is_numeric($result['selId'])) {
         $result['selUser']['user_id'] = 'new';
     }
     // Find libraries, and which library is selected
     $lf = new LibraryFinder($db);
     $result['libraryList'] = $lf->getAllLibraries();
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Search Results', 'content' => 'content/questionSearchResults.php');
     // The number of questions and page offset we want
     $count = grwd('count', 50);
     $page = grwd('page', 1);
     $result['count'] = $count;
     $result['page'] = $page;
     // don't lose the db!
     $db = $_REQUEST['db'];
     $userFinder = new UserFinder($db);
     $user = $userFinder->findById($_SESSION['userId']);
     $result['user'] = $user;
     // Generate a base URL for this search -- can't have page or count data
     // cos we're going to build pagination links from this
     $criteriaArray = $_GET;
     unset($criteriaArray['page']);
     unset($criteriaArray['count']);
     $advancedSearchString = implode_assoc('=', '&', $criteriaArray, true, true);
     $result['criteria_array'] =& $criteriaArray;
     $baseUrl = 'advancedSearch.do?' . $advancedSearchString;
     $result['advanced_search_string'] = $advancedSearchString;
     // gather request data
     $date1 = grwd('date1');
     $date2 = grwd('date2');
     $library_id_post = grwd('library_id') + 0;
     $location_id_post = grwd('location_id') + 0;
     $initials = grwd('initials');
     $searchString = grwd('searchString');
     $result['searchWords'] = $searchString;
     $questionFinder = new QuestionFinder($db);
     $startDate = array('database_field' => 'questions.question_date', 'relation' => '>=', 'value' => $date1, 'type' => 'DATE');
     $endDate = array('database_field' => 'questions.question_date', 'relation' => '<=', 'value' => $date2, 'type' => 'DATE');
     $library_id = array('database_field' => 'questions.library_id', 'relation' => '=', 'value' => $library_id_post, 'type' => 'INT');
     $location_id = array('database_field' => 'questions.location_id', 'relation' => '=', 'value' => $location_id_post, 'type' => 'INT');
     $initials = array('database_field' => 'questions.initials', 'relation' => 'LIKE', 'value' => $initials, 'type' => 'TEXT');
     $searchCriteria = array('database_field' => array('question', 'answer'), 'relation' => 'fulltext', 'value' => $searchString, 'type' => 'FULLTEXT');
     // pull together all of the search criteria
     $criteria = array('start_date' => $startDate, 'end_date' => $endDate, 'library_id' => $library_id, 'location_id' => $location_id, 'initials' => $initials, 'search_criteria' => $searchCriteria);
     $sql = "";
     $param = array();
     foreach ($criteria as $value) {
         if (!$value["value"]) {
             continue;
         }
         if (count($param) != 0) {
             $sql .= ' AND ';
         }
         if ($value["type"] == "FULLTEXT") {
             // Track if this is the first fulltext in group
             $orNeeded = false;
             $sql .= ' ( ';
             foreach ($value["database_field"] as $field) {
                 if ($orNeeded) {
                     $sql .= " OR ";
                 }
                 $sql .= 'MATCH(' . $field . ") AGAINST(? IN BOOLEAN MODE)";
                 $param[] = mySqlFulltextString($value["value"]);
                 $orNeeded = true;
             }
             $sql .= ' ) ';
         } else {
             if ($value['type'] == "DATE") {
                 // Make dates sane; the only part of this that's special
                 $sDate = makeDateSane($value['value']);
                 $sDate = date('Y-m-d', strtotime($sDate));
                 $sql .= $value["database_field"] . ' ' . $value["relation"] . ' ? ';
                 $param[] = $sDate;
             } else {
                 $sql .= $value["database_field"] . ' ' . $value["relation"] . ' ? ';
                 $param[] = $value["value"];
             }
         }
     }
     $questionFinder = new QuestionFinder($db);
     $qList =& $questionFinder->getPagedList($count, $page, $sql, $param);
     $result['questionList'] =& $qList['list'];
     $result['list_meta'] = $qList['meta'];
     $libraryFinder = new LibraryFinder($db);
     $searchLibName = $libraryFinder->getLibraryName($library_id_post);
     if ($library_id_post == 0) {
         $searchLibName = "All Libraries";
     }
     if (isset($location_id_post)) {
         $locationFinder = new LocationFinder($db);
         $searchLocName = $locationFinder->getLocation($location_id_post);
     }
     $result['origin'] = $baseUrl . "&amp;page={$page}&amp;count={$count}";
     $result['base_url'] = $baseUrl;
     $result['date1'] = $date1;
     $result['date2'] = $date2;
     $result['library_id'] = $library_id;
     $result['library_name'] = $searchLibName;
     $result['search_library_id'] = $library_id_post;
     $result['location_id'] = $location_id;
     $result['location_name'] = $searchLocName;
     $result['criteria'] = $criteria;
     // $result['sql'] = $sql;
     return $result;
 }
 function perform()
 {
     // set display requirements
     $result = array('renderer' => 'template_renderer.inc', 'pageTitle' => SITE_NAME . ' : Finished Report', 'content' => 'content/reportReturn.php');
     // don't lose the db!
     $db = $_REQUEST['db'];
     // where are we?
     $userFinder = new UserFinder($db);
     $user = $userFinder->findById($_SESSION['userId']);
     $result['user'] = $user;
     // gather posted data
     $date1 = trim(grwd('date1'));
     $date2 = trim(grwd('date2'));
     if ($date1 == '') {
         $date1 = '1/1/1990';
     }
     if ($date2 == '') {
         $date2 = 'now';
     }
     $report_id = grwd('report_id');
     $library_id_post = grwd('library_id') + 0;
     $location_id_post = grwd('location_id') + 0;
     // function to sanity check dates
     $date1 = makeDateSane($date1);
     $date1 = date('Y-m-d G:i:s', strtotime($date1));
     $date2 = makeDateSane($date2);
     $date2 = date('Y-m-d G:i:s', strtotime($date2));
     $startDate = array('database_field' => 'questions.question_date', 'relation' => '>=', 'value' => $date1, 'type' => 'DATE');
     $endDate = array('database_field' => 'questions.question_date', 'relation' => '<=', 'value' => $date2, 'type' => 'DATE');
     $library_id = array('database_field' => 'questions.library_id', 'relation' => '=', 'value' => $library_id_post, 'type' => 'INT');
     $location_id = array('database_field' => 'questions.location_id', 'relation' => '=', 'value' => $location_id_post, 'type' => 'INT');
     // pull together all of the search criteria
     $criteria = array('start_date' => $startDate, 'end_date' => $endDate, 'library_id' => $library_id, 'location_id' => $location_id);
     $sql = " WHERE questions.delete_hide = 0 ";
     $i = 0;
     $param = array();
     foreach ($criteria as $value) {
         if (!$value["value"]) {
             continue;
         }
         $sql .= 'AND' . ' ' . $value["database_field"] . ' ' . $value["relation"] . ' ? ';
         $param[$i] = $value["value"];
         $i++;
     }
     // get the relevant data from the Report class
     $reportFinder = new ReportFinder($db);
     $reportCount = $reportFinder->getReportCount();
     $reportQuestionCount = $reportFinder->getReportQuestionCount($sql, $param);
     // call the specific class of the report
     $report_class_handle = new Report();
     $report_class_get = $report_class_handle->get();
     $report_info = new $report_id();
     // declare the report class by using it's ID
     $result['reportList'] = $report_info->info();
     // start preparing the report for processing
     $reportPerform = new $_REQUEST["report_id"]($db);
     $reportResults = $reportPerform->perform($sql, $param);
     $libraryFinder = new LibraryFinder($db);
     $reportLibName = $libraryFinder->getLibraryName($library_id_post);
     if (isset($location_id_post)) {
         $locationFinder = new LocationFinder($db);
         $reportLocName = $locationFinder->getLocation($location_id_post);
     }
     // prepare $results
     // since a CSV report is handled differently with the headers, configure the report here
     if ($report_id == "DataCSVReport" || isset($_REQUEST["csv_export"])) {
         $result['renderer'] = 'template_csv.inc';
         $result['content'] = 'content/outputCSV.php';
     }
     $result['report_id'] = $report_id;
     $result['date1'] = $date1;
     $result['date2'] = $date2;
     $result['library_id'] = $library_id;
     $result['library_id_post'] = $library_id_post;
     $result['library_name'] = $reportLibName;
     $result['location_id'] = $location_id;
     $result['location_id_post'] = $location_id_post;
     $result['location_name'] = $reportLocName;
     $result['reportCount'] = $reportCount;
     $result['reportQuestionCount'] = $reportQuestionCount;
     $result['reportResults'] = $reportResults;
     $result['criteria'] = $criteria;
     $result['sql'] = $sql;
     return $result;
 }