public static function saveSession() { $engine = EngineAPI::singleton(); $localvars = localvars::getInstance(); $db = db::get($localvars->get('dbConnectionName')); $sql = "INSERT INTO `session`(username,sessionPages,ipAddr) VALUES(?,?,?)"; $validate = new validate(); $username = session::get('username'); $pages = session::get('loggedPages'); $pages = dbSanitize(implode(',', $pages)); $ip = $_SERVER['REMOTE_ADDR']; $sqlArray = array($username, $pages, $ip); $db->beginTransaction(); try { $sqlResult = $db->query($sql, $sqlArray); if ($sqlResult->error()) { throw new Exception("ERROR SQL" . $sqlResult->errorMsg()); } $db->commit(); } catch (Exception $e) { $db->rollback(); $localvars->set('feedback', $e->getMessage()); errorHandle::errorMsg($e->getMessage()); } }
function displayMessages() { $engine = EngineAPI::singleton(); if (is_empty($engine->errorStack)) { return FALSE; } return '<section><header><h1>Results</h1></header>' . errorHandle::prettyPrint() . '</section>'; }
public static function insert($action, $objectID = 0, $formID = 0, $info = NULL) { $sql = sprintf("INSERT INTO `logs` (`username`,`IP`,`action`,`objectID`,`formID`,`info`,`date`) VALUES('%s','%s','%s','%s','%s','%s','%s')", mfcs::$engine->openDB->escape(users::user('username')), mfcs::$engine->openDB->escape($_SERVER['REMOTE_ADDR']), mfcs::$engine->openDB->escape($action), mfcs::$engine->openDB->escape($objectID), mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($info), time()); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } return TRUE; }
public static function delete($id) { $sql = sprintf("DELETE FROM `permissions` WHERE `formID`='%s'", mfcs::$engine->openDB->escape($id)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } return TRUE; }
public static function validate($type, $data, $extraData = NULL) { if (in_array($type, self::getValidationTypes())) { if (strtolower($type) === 'regexp' && validate::regexp($extraData, $data)) { return TRUE; } else { if (method_exists("validate", $type) && validate::$type($data)) { return TRUE; } } } errorHandle::errorMsg("Entry, " . htmlSanitize($data) . ", is not valid."); return FALSE; }
public function render() { try { $file = $this->path; if (isnull($file)) { throw new Exception('Path is null. We can\'t have a null path, something is crazy.'); } ob_start(); include $file; $renderView = ob_get_contents(); ob_end_clean(); return $renderView; } catch (Exception $e) { errorHandle::errorMsg($e->getMessage()); return false; } }
public static function updateFormNav($groupings) { $groupings = json_decode($groupings, TRUE); if (!is_empty($groupings)) { foreach ($groupings as $I => $grouping) { $positions[$I] = $grouping['position']; } array_multisort($positions, SORT_ASC, $groupings); } $groupings = encodeFields($groupings); $sql = sprintf("UPDATE `forms` SET `navigation`='%s' WHERE `ID`='%s'", mfcs::$engine->openDB->escape($groupings), mfcs::$engine->cleanGet['MYSQL']['id']); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } return TRUE; }
public static function updateDupeTable($formID, $objectID, $data) { // trans begin $result = mfcs::$engine->openDB->transBegin("objects"); if ($result !== TRUE) { errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG); return FALSE; } // wipe the old dupe information $sql = sprintf("DELETE FROM `dupeMatching` WHERE `formID`='%s' AND `objectID`='%s'", mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($objectID)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - removing from duplicate table: " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } //insert data foreach ($data as $name => $raw) { if (!isset(mfcs::$engine->cleanPost['MYSQL'][$name]) || isempty(mfcs::$engine->cleanPost['MYSQL'][$name])) { if (!isempty($raw)) { http::setPost($name, $raw); $postSet = TRUE; } else { continue; } } $sql = sprintf("INSERT INTO `dupeMatching` (`formID`,`objectID`,`field`,`value`) VALUES('%s','%s','%s','%s')", mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($objectID), mfcs::$engine->openDB->escape($name), mfcs::$engine->cleanPost['MYSQL'][$name]); $sqlResult = mfcs::$engine->openDB->query($sql); if (isset($postSet) && $postSet === TRUE) { http::setPost($name, ""); } if (!$sqlResult['result']) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } } // trans commit mfcs::$engine->openDB->transCommit(); mfcs::$engine->openDB->transEnd(); return TRUE; }
public function setupForm($id = null) { try { // call engine $engine = EngineAPI::singleton(); $localvars = localvars::getInstance(); $validate = new validate(); // create customer form $form = formBuilder::createForm('TimeTracker'); $form->linkToDatabase(array('table' => 'timeTracking')); if (!is_empty($_POST) || session::has('POST')) { $processor = formBuilder::createProcessor(); $processor->processPost(); } // form titles $form->insertTitle = ""; $form->editTitle = ""; $form->updateTitle = ""; // if no valid id throw an exception if (!$validate->integer($id) && !isnull($id)) { throw new Exception(__METHOD__ . '() - Not a valid integer, please check the integer and try again.'); } // form information $form->addField(array('name' => 'timeID', 'type' => 'hidden', 'value' => $id, 'primary' => TRUE, 'fieldClass' => 'id', 'showIn' => array(formBuilder::TYPE_INSERT, formBuilder::TYPE_UPDATE))); $form->addField(array('name' => 'projectIdLink', 'type' => 'hidden', 'label' => 'Project ID:', 'required' => TRUE, 'fieldClass' => 'projectID')); $form->addField(array('name' => 'customerIdLink', 'type' => 'hidden', 'label' => 'Customer ID:', 'fieldClass' => 'customerID', 'required' => TRUE)); $form->addField(array('name' => 'startTime', 'type' => 'hidden', 'label' => 'start time:', 'fieldClass' => 'startTime', 'required' => TRUE)); $form->addField(array('name' => 'endTime', 'type' => 'hidden', 'label' => 'end time:', 'fieldClass' => 'endTime', 'required' => TRUE)); $form->addField(array('name' => 'totalHours', 'type' => 'hidden', 'label' => 'total time:', 'required' => TRUE, 'fieldClass' => 'totalHours')); $form->addField(array('name' => "completed", 'label' => "Has this project been completed?", 'showInEditStrip' => TRUE, 'type' => 'boolean', 'duplicates' => TRUE, 'options' => array("YES", "N0"))); $form->addField(array('name' => "descriptionOfWork", 'label' => "Enter a description of the project:", 'type' => 'textarea')); // buttons and submissions $form->addField(array('showIn' => array(formBuilder::TYPE_UPDATE), 'name' => 'update', 'type' => 'submit', 'fieldClass' => 'submit', 'value' => 'Update')); $form->addField(array('showIn' => array(formBuilder::TYPE_UPDATE), 'name' => 'delete', 'type' => 'delete', 'fieldClass' => 'delete hidden', 'value' => 'Delete')); $form->addField(array('showIn' => array(formBuilder::TYPE_INSERT), 'name' => 'insert', 'type' => 'submit', 'fieldClass' => 'submit', 'value' => 'Submit')); return '{form name="TimeTracker" display="form"}'; } catch (Exception $e) { errorHandle::errorMsg($e->getMessage()); } }
public static function insertObjectData($objectID, $data, $formID) { if (!is_array($data)) { return FALSE; } if (mfcs::$engine->openDB->transBegin("objectsData") !== TRUE) { errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG); return FALSE; } // remove old data $sql = sprintf("DELETE FROM `objectsData` WHERE `objectID`='%s'", $objectID); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - " . $sql . " -- " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } // insert new data foreach ($data as $I => $V) { $encoded = 0; if (is_array($V)) { // encode it $V = encodeFields($V); $encoded = 1; } $sql = sprintf("INSERT INTO `objectsData` (formID,objectID,fieldName,value,encoded) VALUES('%s','%s','%s','%s','%s')", mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($objectID), mfcs::$engine->openDB->escape($I), mfcs::$engine->openDB->escape($V), mfcs::$engine->openDB->escape($encoded)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - " . $sql . " -- " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } } mfcs::$engine->openDB->transCommit(); mfcs::$engine->openDB->transEnd(); return TRUE; }
public static function getUsers() { $sql = sprintf("SELECT `ID` FROM `users`"); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } $users = array(); while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { if (($user = self::get($row['ID'])) == FALSE) { return FALSE; } $users[] = $user; } return $users; }
public static function retrieveData($formID, $fieldName = NULL) { $sql = sprintf("SELECT * FROM `objectsData` WHERE `formID`='%s'", mfcs::$engine->openDB->escape($formID)); if (!isnull($fieldName)) { $sql .= "AND `fieldName`='" . mfcs::$engine->openDB->escape($fieldName) . "'"; } $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } $data = array(); while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { if (!isnull($fieldName) && $row['fieldName'] != $fieldName) { continue; } if ($row['encoded'] == "1") { $row['value'] = decodeFields($row['value']); } $data[] = $row; } return $data; }
public static function processObjectFiles($assetsID, $options) { // Disable PHP's max execution time set_time_limit(0); $saveBase = mfcs::config('convertedPath'); $originalsFilepath = self::getSaveDir($assetsID, 'archive'); $originalFiles = scandir($originalsFilepath); // Setup return array $return = array('processed' => array(), 'combine' => array(), 'thumbs' => array(), 'ocr' => array()); // Remove dot files from array foreach ($originalFiles as $I => $filename) { if ($filename[0] == '.') { unset($originalFiles[$I]); } } // Needed to put the files in the right order for processing if (natcasesort($originalFiles) === FALSE) { return FALSE; } try { // If combine files is checked, read this image and add it to the combined object if (isset($options['combine']) && str2bool($options['combine'])) { try { $errors = array(); $createThumb = TRUE; // Create us some temp working space $tmpDir = mfcs::config('mfcstmp') . DIRECTORY_SEPARATOR . uniqid(); mkdir($tmpDir, 0777, TRUE); // Ensure that the HOCR file is created if (!self::createHOCR("{$saveBase}/hocr.cfg")) { return FALSE; } $gsTemp = $tmpDir . DIRECTORY_SEPARATOR . uniqid(); touch($gsTemp); foreach ($originalFiles as $filename) { // Figure some stuff out about the file $originalFile = $originalsFilepath . DIRECTORY_SEPARATOR . $filename; $_filename = pathinfo($originalFile); $filename = $_filename['filename']; $baseFilename = $tmpDir . DIRECTORY_SEPARATOR . $filename; // Create a thumbnail of the first image if ($createThumb === TRUE) { if (($return['combine'][] = self::createThumbnail($originalFile, $filename, $options, $assetsID, TRUE)) === FALSE) { throw new Exception("Failed to create thumbnail: " . $filename); } // Prevent making multiple thumbnails $createThumb = FALSE; } // perform hOCR on the original uploaded file which gets stored in combined as an HTML file $_exec = shell_exec(sprintf('tesseract %s %s -l eng %s 2>&1', escapeshellarg($originalFile), escapeshellarg($baseFilename), escapeshellarg("{$saveBase}/hocr.cfg"))); // If a new-line char is in the output, assume it's an error // Tesseract failed, let's normalize the image and try again if (strpos(trim($_exec), "\n") !== FALSE) { $errors[] = "Unable to process OCR for " . basename($originalFile) . ". Continuing…"; errorHandle::warningMsg("Unable to process OCR for " . basename($originalFile) . ". Continuing…"); // Ensure HTML file exists touch($baseFilename . ".html"); } // Create an OCR'd pdf of the file $_exec = shell_exec(sprintf('hocr2pdf -i %s -s -o %s < %s 2>&1', escapeshellarg($originalFile), escapeshellarg($baseFilename . ".pdf"), escapeshellarg($baseFilename . ".html"))); if (trim($_exec) !== 'Writing unmodified DCT buffer.') { if (strpos($_exec, 'Warning:') !== FALSE) { errorHandle::newError("hocr2pdf Warning: " . $_exec, errorHandle::DEBUG); } else { errorHandle::errorMsg("Failed to Create PDF: " . basename($filename, "jpg") . ".pdf"); throw new Exception("hocr2pdf Error: " . $_exec); } } // Add this pdf to a temp file that will be read in by gs file_put_contents($gsTemp, $baseFilename . ".pdf" . PHP_EOL, FILE_APPEND); // We're done with this file, delete it unlink($baseFilename . ".html"); } // Combine all PDF files in directory $_exec = shell_exec(sprintf('gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=%s @%s 2>&1', self::getSaveDir($assetsID, 'combine') . "combined.pdf", $gsTemp)); if (!is_empty($_exec)) { errorHandle::errorMsg("Failed to combine PDFs into single PDF."); throw new Exception("GhostScript Error: " . $_exec); } $return['combine'][] = array('name' => 'combined.pdf', 'path' => self::getSaveDir($assetsID, 'combine', FALSE), 'size' => filesize(self::getSaveDir($assetsID, 'combine') . 'combined.pdf'), 'type' => 'application/pdf', 'errors' => $errors); // Lastly, we delete our temp working dir (always nice to cleanup after yourself) if (self::cleanupTempDirectory($tmpDir) === FALSE) { errorHandle::errorMsg("Unable to clean up temporary directory: " . $tmpDir); throw new Exception("Unable to clean up temporary directory: " . $tmpDir); } } catch (Exception $e) { // We need to delete our working dir if (isset($tmpDir) && is_dir($tmpDir)) { if (self::cleanupTempDirectory($tmpDir) === FALSE) { errorHandle::errorMsg("Unable to clean up temporary directory (in Exception): " . $tmpDir); } } throw new Exception($e->getMessage(), $e->getCode(), $e); } } // If Combine // This conditional needs updated when different conversion options are added or removed. // If the file has no processing to do, don't do any ... if (!isset($options['convert']) && !isset($options['thumbnail']) && !isset($options['ocr']) && !isset($options['mp3'])) { return $return; } foreach ($originalFiles as $filename) { $originalFile = $originalsFilepath . DIRECTORY_SEPARATOR . $filename; $_filename = pathinfo($originalFile); $filename = $_filename['filename']; // Convert uploaded files into some ofhter size/format/etc if (isset($options['convert']) && str2bool($options['convert'])) { // we create the Imagick object here so that we can pass it to thumbnail creation $image = new Imagick(); $image->readImage($originalFile); // Convert it if (($image = self::convertImage($image, $options, $assetsID, $filename)) === FALSE) { throw new Exception("Failed to create processed image: " . $originalFile); } $filename = $filename . '.' . strtolower($image->getImageFormat()); // Create a thumbnail that includes converted options if (isset($options['thumbnail']) && str2bool($options['thumbnail'])) { if (($return['thumbs'][] = self::createThumbnail($image, $filename, $options, $assetsID)) === FALSE) { throw new Exception("Failed to create thumbnail: " . $filename); } } // Set the return array $return['processed'][] = array('name' => $filename, 'path' => self::getSaveDir($assetsID, 'processed', FALSE), 'size' => filesize(self::getSaveDir($assetsID, 'processed') . $filename), 'type' => self::getMimeType(self::getSaveDir($assetsID, 'processed') . $filename), 'errors' => ''); } else { if (isset($options['thumbnail']) && str2bool($options['thumbnail'])) { if (($return['thumbs'][] = self::createThumbnail($originalFile, $filename, $options, $assetsID)) === FALSE) { throw new Exception("Failed to create thumbnail: " . $filename); } } } // Create an OCR text file if (isset($options['ocr']) && str2bool($options['ocr'])) { if (($return['ocr'][] = self::createOCRTextFile($originalFile, $assetsID, $filename)) === FALSE) { errorHandle::errorMsg("Failed to create OCR text file: " . $filename); throw new Exception("Failed to create OCR file for {$filename}"); } } // Create MP3 if (isset($options['mp3']) && str2bool($options['mp3'])) { $return['mp3'][] = self::createMP3($originalFile); } } // Foreach File } catch (Exception $e) { errorHandle::newError(__METHOD__ . "() - {$e->getMessage()} {$e->getLine()}:{$e->getFile()}", errorHandle::HIGH); } return $return; }
/** * ========================================================= * Checks logic for searching if user email is in the system * this will help to provide a way to make sure that users * are not duplicated in the system. * ========================================================= **/ public static function checkEmail($email) { $engine = EngineAPI::singleton(); $localvars = localvars::getInstance(); $db = db::get($localvars->get('dbConnectionName')); $sql = "SELECT `email` FROM `users` WHERE `email`=? LIMIT=1"; $email = dbSanitize($email); $sqlResult = $db->query($sql, array($email)); try { if ($sqlResult->error()) { throw new Exception("Error Getting Entries"); } if ($sqlResult->rowCount() < 1) { return false; } else { return true; } } catch (Exception $e) { errorHandle::errorMsg($e->getMessage()); } }
public function getCustomerProjectsJSON($customerID) { try { // call engine $engine = EngineAPI::singleton(); $localvars = localvars::getInstance(); $db = db::get($localvars->get('dbConnectionName')); $sql = "SELECT * FROM `projects`"; $validate = new validate(); // test to see if Id is present and valid if (!isnull($customerID) && $validate->integer($customerID)) { $sql .= sprintf('WHERE customerID = %s', $customerID); } // if no valid id throw an exception if (!$validate->integer($customerID) && !isnull($customerID)) { throw new Exception("An invalid ID was given!"); } // get the results of the query $sqlResult = $db->query($sql); // if return no results // else return the data if ($sqlResult->rowCount() < 1) { return "There are no projects in the database."; } else { $data = array(); while ($row = $sqlResult->fetch()) { $data[] = $row; } return json_encode($data); } } catch (Exception $e) { errorHandle::errorMsg($e->getMessage()); } }
public static function generateFormSelectListForFormCreator($metadata = TRUE) { if ($metadata === TRUE) { if (($forms = forms::getMetadataForms()) === FALSE) { errorHandle::errorMsg("Error getting Metadata Forms"); return FALSE; } } else { if ($metadata === FALSE) { if (($forms = forms::getObjectForms()) === FALSE) { errorHandle::errorMsg("Error getting Object Forms"); return FALSE; } } } $formList = '<ul class="pickList">'; foreach ($forms as $form) { if (!mfcsPerms::isViewer($form['ID'])) { continue; } $formList .= sprintf('<li><a href="index.php?id=%s" class="btn">%s</a></li>', htmlSanitize($form['ID']), forms::title($form['ID'])); } $formList .= "<ul>"; return $formList; }
try { if (($builtForm = forms::build($engine->cleanGet['MYSQL']['formID'], $engine->cleanGet['MYSQL']['objectID'], $error)) === FALSE) { throw new Exception("Error building form."); } localvars::add("form", $builtForm); localvars::add("leftnav", navigation::buildProjectNavigation($engine->cleanGet['MYSQL']['formID'])); localvars::add("objectID", $engine->cleanGet['MYSQL']['objectID']); ////////// // Project Tab Stuff $selectedProjects = objects::getProjects($engine->cleanGet['MYSQL']['objectID']); localVars::add("projectOptions", projects::generateProjectChecklist($selectedProjects)); // Project Tab Stuff ////////// } catch (Exception $e) { log::insert("Data Entry: Object: Error", $engine->cleanGet['MYSQL']['objectID'], $engine->cleanGet['MYSQL']['formID'], $e->getMessage()); errorHandle::errorMsg($e->getMessage()); } } localVars::add("results", displayMessages()); // Display warning if form is not part of current project forms::checkFormInCurrentProjects($engine->cleanGet['MYSQL']['formID']); localvars::add("actionHeader", isnull($engine->cleanGet['MYSQL']['objectID']) ? "Add" : "Edit"); localvars::add("parentHeader", isnull($parentObject) ? "" : "<h2>Adding Child to Parent '" . $parentObject['data'][$form['objectTitleField']] . "'</h2>"); $engine->eTemplate("include", "header"); ?> {local var="projectWarning"} <section> <header class="page-header"> <h1>{local var="actionHeader"} Object - {local var="formName"}</h1>
<?php // path to my engineAPI install require_once '/home/timeTracker/phpincludes/engine/engineAPI/4.0/engine.php'; $engine = EngineAPI::singleton(); // Setup Error Rorting errorHandle::errorReporting(errorHandle::E_ALL); // Setup Database Information for Vagrant $databaseOptions = array('username' => 'username', 'password' => 'password', 'dbName' => 'test'); $db = db::create('mysql', $databaseOptions, 'appDB'); // Set localVars and engineVars variables $localvars = localvars::getInstance(); $enginevars = enginevars::getInstance(); if (EngineAPI::VERSION >= "4.0") { $localvars = localvars::getInstance(); $localvarsFunction = array($localvars, 'set'); } else { $localvarsFunction = array("localvars", "add"); } // include base variables recurseInsert("includes/vars.php", "php"); // load a template to use templates::load('timeTemplate');
} if (objects::add("2", $submitArray) !== TRUE) { print "error adding object " . $submitArray['idno']; print "<pre>"; var_dump($submitArray); print "</pre>"; errorHandle::prettyPrint(); exit; } // add the item to the pec project if (objects::addProject(localvars::get("newObjectID"), "1") === FALSE) { print "error -- add Project: \n"; print "<pre>"; var_dump($submitArray); print "</pre>"; errorHandle::prettyPrint(); exit; } mfcs::$engine->cleanPost['MYSQL'] = array(); mfcs::$engine->cleanPost['HTML'] = array(); mfcs::$engine->cleanPost['RAW'] = array(); // make certain we don't have any data cache unset($submitArray); } print "Records: <pre>"; var_dump(count($records)); print "</pre>"; $total = 0; foreach ($metadata as $table => $records) { print "{$table}: <pre>"; var_dump(count($records));
} // Get the MIME Type if (isPHP('5.3')) { $fi = new finfo(FILEINFO_MIME_TYPE); $mimeType = $fi->file($filepath); } else { $fi = new finfo(FILEINFO_MIME); list($mimeType, $mimeEncoding) = explode(';', $fi->file($filepath)); } // Set the correct MIME-Type headers, and output the file's content if (isset($engine->cleanGet['MYSQL']['download']) and str2bool($engine->cleanGet['MYSQL']['download'])) { header(sprintf("Content-Disposition: attachment; filename='%s'", isset($downloadFilename) ? $downloadFilename : basename($filepath))); header("Content-Type: application/octet-stream"); ini_set('memory_limit', -1); die(file_get_contents($filepath)); // die so nothing else will be displayed } else { if ($mimeType == 'application/x-empty') { errorHandle::newError("Failed to locate file to display!", errorHandle::HIGH); header("Content-type: text/plain"); die("Failed to locate requested file!"); // die so nothing else will be displayed } else { files::generateFilePreview($filepath, $mimeType); exit; } } } catch (Exception $e) { errorHandle::newError($e->getMessage(), errorHandle::DEBUG); die($e->getMessage()); }
public function renderDataTable() { try { $engine = EngineAPI::singleton(); $localvars = localvars::getInstance(); $validate = new validate(); $dataRecord = self::getRecords(); $records = ""; foreach ($dataRecord as $data) { $records .= sprintf("<tr>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n <td><a href='customers/edit/%s'><span class='glyphicon glyphicon-edit'></span> </a></td>\n <td><a href='customers/confirmDelete/%s'> <span class='glyphicon glyphicon-trash'></span> </a></td>\n </tr>", $data['companyName'], $data['firstName'], $data['lastName'], $data['email'], $data['phone'], $data['website'], $data['ID'], $data['ID']); } $output = sprintf("<div class='dataTable table-responsive'>\n <table class='table table-striped'>\n <thead>\n <tr class='info'>\n <th> Company Name </th>\n <th> First name </th>\n <th> Last Name </th>\n <th> Email </th>\n <th> Phone Number </th>\n <th> Website </th>\n <th> </th>\n <th> </th>\n </tr>\n </thead>\n <tbody>\n %s\n </tbody>\n </table>\n </div>", $records); return $output; } catch (Exception $e) { errorHandle::errorMsg($e->getMessage()); return $e->getMessage(); } }
require "engineInclude.php"; if (!isCLI()) { recurseInsert("acl.php", "php"); } recurseInsert("dbTableList.php", "php"); $engine->dbConnect("database", "mfcs", TRUE); // Load the mfcs class require_once "includes/index.php"; mfcs::singleton(); // Quick and dirty Checks check // @TODO this needs to be more formalized in a class to easily include other checks as well if (!isCLI()) { $sql_check = sprintf("SELECT `value` FROM `checks` WHERE `name`='uniqueIDCheck'"); $sqlResult_check = mfcs::$engine->openDB->query($sql_check); if (!$sqlResult_check['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); print "<p>Error checking MFCS sanity. Aborting.</p>"; exit; } $row_check = mysql_fetch_array($sqlResult_check['result'], MYSQL_ASSOC); if ($row_check['value'] == "0") { // notify systems via email print "<h1>ERROR!</h1>"; print "<p>MFCS Failed idno sanity check. Please contact systems Immediately.</p>"; print "<p>Please jot down the steps you took getting to this point. Be as specific as possible.</p>"; print "<p>Aborting.</p>"; exit; } } // End Checks $mfcsSearch = new mfcsSearch();
/** * Object cache manager * * This function identifies cache by the class by default. So each class gets 1 cache. If you * need more than 1 cache per class that should be handled internal to the calling class using * the $cachID to distinguish. * * * @param string $action create, update, delete, or get * @param $cacheID * How the calling method/fucntion identifies the cache.<br> * If the calling function or class will be using multiple<br> * caches it should add cache name information to this as well. * @param mixed $value * The value to be stored. (required for everything except "get") * @return bool */ public function cache($action, $cacheID, $value = NULL) { // for security we have to determine the function ID ourselves. // otherwise a malicious module/object author could overwrite the permissions cache $trace = debug_backtrace(); $caller = $trace[1]; $functionID = isset($caller['class']) ? $caller['class'] : $caller['function']; if ($action == "create") { if (isnull($value)) { errorHandle::newError(__METHOD__ . "() - value not provided.", errorHandle::DEBUG); return FALSE; } if (isset($this->cache[$functionID][$cacheID])) { errorHandle::newError(__METHOD__ . "() - cachID found. use update", errorHandle::DEBUG); return FALSE; } $this->cache[$functionID][$cacheID] = $value; } else { if ($action == "update") { if (isnull($value)) { errorHandle::newError(__METHOD__ . "() - value not provided.", errorHandle::DEBUG); return FALSE; } if (!isset($this->cache[$functionID][$cacheID])) { errorHandle::newError(__METHOD__ . "() - cachID not found. use create", errorHandle::DEBUG); return FALSE; } $this->cache[$functionID][$cacheID] = $value; } else { if ($action == "delete") { if (isnull($value)) { errorHandle::newError(__METHOD__ . "() - value not provided.", errorHandle::DEBUG); return FALSE; } if (!isset($this->cache[$functionID][$cacheID])) { errorHandle::newError(__METHOD__ . "() - cachID not found. use create", errorHandle::DEBUG); return FALSE; } unset($this->cache[$functionID][$cacheID]); } else { if ($action == "get") { if (isset($this->cache[$functionID][$cacheID])) { return $this->cache[$functionID][$cacheID]; } return NULL; } else { errorHandle::newError(__METHOD__ . "() - Action '" . $action . "' not allowed.", errorHandle::DEBUG); return FALSE; } } } } return TRUE; }
public static function getForms($projectID, $form = FALSE) { $sql = sprintf("SELECT `formID` FROM `forms_projects` WHERE `projectID`='%s'", mfcs::$engine->openDB->escape($projectID)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } $formIDs = array(); while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { if ($form === TRUE) { if (($formIDs[$row['formID']] = forms::get($row['formID'])) === FALSE) { return FALSE; } } else { $formIDs[] = $row['formID']; } } return $formIDs; }
} catch (Exception $e) { errorHandle::errorMsg($e->getMessage()); } // Get List of existing watermarks $sql = sprintf("SELECT * FROM `watermarks` ORDER BY `name`"); $sqlResult = $engine->openDB->query($sql); if ($sqlResult['result']) { $tmp = NULL; while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { try { $i = new Imagick(); $i->readImageBlob($row['data']); $tmp .= sprintf('<li><a href="?id=%s">%s<br><img src="data:image/%s;base64,%s"></a></li>', htmlSanitize($row['ID']), htmlSanitize($row['name']), strtolower($i->getImageFormat()), base64_encode($row['data'])); } catch (Exception $e) { errorHandle::newError("readImageBlob failed - {$e->getMessage()}", errorHandle::HIGH); errorHandle::errorMsg("Failed to load watermark."); } } localVars::add("existingWatermarks", $tmp); unset($tmp); } // Get List of existing watermarks if (!isnull($ID)) { localVars::add("headerText", "Update Watermark"); localVars::add("submitBtn", '<button type="submit" name="update" class="btn">Update</button><button type="submit" name="delete" class="btn">Delete</button>'); $sql = sprintf("SELECT * FROM `watermarks` WHERE ID='%s' LIMIT 1", $engine->openDB->escape($ID)); $sqlResult = $engine->openDB->query($sql); if ($sqlResult['result']) { $row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC); localVars::add("nameVal", $row['name']); }