예제 #1
0
 /**
  * __construct()
  * Constructor for the THINKER_Section Class
  *
  * @author Cory Gehr
  * @access public
  */
 public function __construct()
 {
     // Initialize classInfo with information about the target class
     $this->reflectionClass = new ReflectionClass($this);
     $this->data = array();
     // Override view if necessary
     if (isset($_GET['view'])) {
         $this->view = getPageVar('view', 'str', 'GET', true);
     } else {
         $this->view = DEFAULT_VIEW;
     }
     // Get the session information
     $sessionClass = SESSION_CLASS;
     $this->session = $sessionClass::singleton();
 }
예제 #2
0
파일: Error.php 프로젝트: corygehr/thinker
 /**
  * info()
  * Passes data back for the 'info' subsection
  *
  * @access public
  */
 public function info()
 {
     // Error number
     $no = getPageVar('no', 'int', 'GET');
     $description = 'An unspecified error has occurred.';
     $message = 'Please contact the server administrator.';
     switch ($no) {
         case 404:
             $description = 'The page specified could not be found.';
             $message = 'Please check the URL you attempted to reach and try again.';
             break;
     }
     $this->set('description', $description);
     $this->set('message', $message);
     $this->set('number', $no);
     return true;
 }
예제 #3
0
파일: xml.php 프로젝트: corygehr/thinker
 /**
  * display()
  * Outputs the data
  *
  * @access public
  */
 public function display()
 {
     global $_SECTION;
     // Display the header
     header('Content-type: text/xml');
     // Get data
     $data = $this->section->getData();
     // Get the resultset we should use
     $set = getPageVar('set', 'int', 0);
     if (empty($data)) {
         echo "<{$_SECTION}>\n<error>No data received from the object.</error>\n</{$_SECTION}>";
         exit;
     } else {
         // Return the encoded data
         $xmlObject = new SimpleXMLElement("<?xml version=\"1.0\"?><{$_SECTION}></{$_SECTION}>");
         $this->arrayToXml($data, $xmlObject);
         // Export
         echo $xmlObject->asXML();
     }
 }
예제 #4
0
파일: index.php 프로젝트: corygehr/thinker
}
// Assign section class
$_SECTION_CLASS = CLASS_PREFIX . 'Section_' . $_SECTION;
// Get path to section
$sectionPath = getPath($_SECTION_CLASS);
$sectionFile = $sectionPath . "{$_SECTION}.php";
// Check if the section specified exists
if (file_exists($sectionFile)) {
    require_once $sectionFile;
    // Create instance of section
    $instance = new $_SECTION_CLASS();
    // Load section configuration
    $sectionConfig = parse_ini_file($sectionPath . 'config.ini', true);
    // Check for sub-section
    if (isset($_GET['su'])) {
        $_SUBSECTION = getPageVar('su', 'str', 'GET', true);
    } else {
        // Load subsection from config
        if (isset($sectionConfig['defaults']['default_subsection'])) {
            $_SUBSECTION = $sectionConfig['defaults']['default_subsection'];
        } else {
            trigger_error("Could not determine the subsection to load.", E_USER_ERROR);
        }
    }
    // Attempt to load subsection
    if (method_exists($_SECTION_CLASS, $_SUBSECTION)) {
        // Call method
        $result = $instance->{$_SUBSECTION}();
    } else {
        // Error redirect
        errorRedirect(404);
예제 #5
0
파일: csv.php 프로젝트: corygehr/thinker
 /**
  * display()
  * Outputs the data
  *
  * @author Cory Gehr
  * @access public
  */
 public function display()
 {
     global $_SECTION;
     // Call the constructor in THINKER_View_Common
     // Headers to tell the browser to download a file
     header('Content-type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename="' . $_SECTION . '.csv"');
     header('Pragma: no-cache');
     header('Expires: 0');
     // Get the data
     $tmpData = $this->section->getData();
     // Get the resultset we should use
     $set = getPageVar('set', 'str');
     // Variables to store the data
     $header = null;
     $expdata = "";
     // Get the actual data we'll be working with
     if (isset($tmpData[$set])) {
         $resultData = $tmpData[$set];
         // Get the headers (just grab em from the first item since that should be there)
         $headings = array_keys($resultData[0]);
         $headerTitles = array();
         // Define headers
         foreach ($headings as $heading) {
             // Get rid of ints (see DB.inc for why these are there)
             if (is_string($heading)) {
                 $headerTitles[] = $heading;
                 if ($header) {
                     $header .= ',' . $heading;
                 } else {
                     $header = $heading;
                 }
             }
         }
         // Newline
         $header .= "\n";
         // Add data
         foreach ($resultData as $row) {
             $line = "";
             foreach ($row as $heading => $value) {
                 if ($heading !== 0 && in_array($heading, $headerTitles)) {
                     $value = trim($value);
                     if (!empty($line)) {
                         $line .= ',"' . $value . '"';
                     } else {
                         $line .= '"' . $value . '"';
                     }
                 }
             }
             $expdata .= $line . "\n";
         }
         if ($expdata == "") {
             $expdata = "No Records Found!";
         }
     } else {
         $header = null;
         $expdata = "No Records Found or perhaps this Section does not support CSV Exporting.";
     }
     // Output data
     echo $header .= $expdata;
 }
예제 #6
0
 /**
  * verifyCsrfToken()
  * Verifies that a csrfToken input matches that for the session
  *
  * @access public
  * @param $inputVarName: Name of the CSRF Token Parameter (default: csrfToken)
  * @return True if Valid Token, False if Invalid
  */
 public function verifyCsrfToken($inputVarName = 'csrfToken')
 {
     return getPageVar($inputVarName, 'str', 'REQUEST', true, false) == $_SESSION['CSRF_TOKEN'];
 }
예제 #7
0
 /**
  * filterSelect()
  * Passes data back for the 'filterSelect' subsection
  *
  * @access public
  */
 public function filterSelect()
 {
     // Check for schema information
     $Schema = $this->session->__get('PRIMARY_SCHEMA');
     $Table = $this->session->__get('PRIMARY_TABLE');
     if (!empty($Schema) && !empty($Table)) {
         // Get columns
         $columns = $this->session->__get('PULL_COLUMNS');
         if ($columns) {
             // Process changes
             $phase = getPageVar('phase', 'str', 'GET');
             switch ($phase) {
                 case 'fetchFilterTypes':
                     // Get the name of the column
                     $column = getPageVar('column', 'str', 'GET');
                     if ($column) {
                         // Parse column provided
                         $colParts = explode('-|-', $column);
                         $colPartCount = count($colParts);
                         // Needs to be three or four parts
                         if ($colPartCount === 3 || $colPartCount === 4) {
                             $fkCol = null;
                             if ($colPartCount === 4) {
                                 $fkCol = $colParts[3];
                             }
                             // Get the column data type
                             $id = $this->createColId($colParts[0], $colParts[1], $colParts[2], $fkCol);
                             if (isset($columns[$id])) {
                                 $Column = $columns[$id];
                                 $colType = $Column['COLUMN']->getColumnType();
                                 $filters = array();
                                 switch ($colType) {
                                     case 'bigint':
                                     case 'decimal':
                                     case 'double':
                                     case 'float':
                                     case 'int':
                                     case 'smallint':
                                         $filters = array('EQUALS' => '=', 'GT' => '>', 'GTE' => '>=', 'LT' => '<', 'LTE' => '<=');
                                         break;
                                     case 'date':
                                     case 'datetime':
                                     case 'time':
                                     case 'timestamp':
                                         $filters = array('BEFORE' => 'Before', 'BEFORE_INCL' => 'Before (Inclusive)', 'AFTER' => 'After', 'AFTER_INCL' => 'After (Inclusive)', 'EQUALS' => 'Equals');
                                         break;
                                     case 'tinyint':
                                         $filters = array('FALSE' => 'False', 'TRUE' => 'True');
                                         break;
                                     default:
                                         // Varchar, Char, Enum Typically
                                         $filters = array('CONTAINS' => 'Contains', 'EQUALS' => 'Equals', 'LIKE' => 'Like', 'STARTS_WITH' => 'Starts With', 'ENDS_WITH' => 'Ends With');
                                         break;
                                 }
                                 $this->set('filters', $filters);
                             }
                         }
                     }
                     // This is all we need here
                     return true;
                     break;
                 case 'invalidColumn':
                     pushMessage('An invalid column was specified, please try again.', 'warning');
                     break;
                 case 'missingInfo':
                     pushMessage('A required filter option and/or value were missing, please try again.', 'warning');
                     break;
                 case 'proceed':
                     // Get inputs, as long as they're provided
                     $filters = array();
                     $process = true;
                     $count = 1;
                     while ($process) {
                         $filterAndOrName = "filter-andor_{$count}";
                         $filterColName = "filter-col_{$count}";
                         $filterOptionName = "filter-option_{$count}";
                         $filterValueName = "filter-value_{$count}";
                         $column = getPageVar($filterColName, 'str', 'POST', false);
                         if (!empty($column)) {
                             // Get Column Object
                             if (isset($columns[$column])) {
                                 $FilterCol = $columns[$column];
                                 // Get the option, andor, and values
                                 $option = getPageVar($filterOptionName, 'str', 'POST', false);
                                 $value = getPageVar($filterValueName, 'str', 'POST', false);
                                 $andOr = getPageVar($filterAndOrName, 'str', 'POST', false);
                                 if ($option && ($value || !$value && ($option == 'FALSE' || $option == 'TRUE'))) {
                                     // If no AndOr, then assume AND
                                     if (!$andOr && $count == 1) {
                                         $andOr = 'FIRST';
                                     } else {
                                         $andOr = 'AND';
                                     }
                                     // Store values in array
                                     $filters[] = array('COLUMN' => $FilterCol, 'OPTION' => $option, 'VALUE' => $value, 'ANDOR' => $andOr);
                                     // Continue
                                     $count++;
                                 } else {
                                     // Throw error
                                     redirect('DataPull', 'filterSelect', array('phase' => 'missingInfo'));
                                 }
                             } else {
                                 // Throw error
                                 redirect('DataPull', 'filterSelect', array('phase' => 'invalidColumn'));
                             }
                         } else {
                             // No column value, so we're done
                             $process = false;
                         }
                     }
                     // Store filters in session and redirect
                     $this->session->__set('PULL_FILTERS', $filters);
                     redirect('DataPull', 'dataReview');
                     break;
             }
             $this->set('schemaName', $Schema->getSchemaName());
             $this->set('tableName', $Table->getTableFriendlyName());
             $this->set('columns', $columns);
         } else {
             // We have a schema and table, but no columns. Redirect back to dataSelect
             redirect('DataPull', 'dataSelect', array('phase' => 'noCols'));
         }
     } else {
         // User hasn't started yet. Redirect to start
         redirect('DataPull', 'dsSelect', array('phase' => 'noSchema'));
     }
     return true;
 }