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()); } }
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 static function loadProjects() { $engine = EngineAPI::singleton(); $currentProjects = array(); $sql = sprintf("SELECT projects.ID,projectName FROM `projects` LEFT JOIN users_projects ON users_projects.projectID=projects.ID WHERE users_projects.userID=%s", $engine->openDB->escape(self::user('ID'))); $sqlResult = $engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError("Failed to load user's projects ({$sqlResult['error']})", errorHandle::HIGH); errorHandle::errorMsg("Failed to load your current projects."); return FALSE; } else { while ($row = mysql_fetch_assoc($sqlResult['result'])) { $currentProjects[$row['ID']] = $row['projectName']; } } return $currentProjects; }
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 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()); } }
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>
public static function submit($formID, $objectID = NULL, $importing = FALSE) { $engine = mfcs::$engine; $backgroundProcessing = array(); if (isnull($objectID)) { $newObject = TRUE; } else { $newObject = FALSE; } // Get the current Form if (($form = self::get($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - retrieving form by formID", errorHandle::DEBUG); return FALSE; } // the form is an object form, make sure that it has an ID field defined. // @TODO this check can probably be removed, its being checked in object class if ($form['metadata'] == "0") { $idnoInfo = self::getFormIDInfo($formID); if ($idnoInfo === FALSE) { errorHandle::newError(__METHOD__ . "() - no IDNO field for object form.", errorHandle::DEBUG); return FALSE; } } $fields = $form['fields']; if (usort($fields, 'sortFieldsByPosition') !== TRUE) { errorHandle::newError(__METHOD__ . "() - usort", errorHandle::DEBUG); if (!$importing) { errorHandle::errorMsg("Error retrieving form."); } return FALSE; } $values = array(); // go through all the fields, get their values foreach ($fields as $field) { $value = isset($engine->cleanPost['RAW'][$field['name']]) ? $engine->cleanPost['RAW'][$field['name']] : ""; $validationTests = self::validateSubmission($formID, $field, $value, $objectID); if (isnull($validationTests) || $validationTests === FALSE) { continue; } if (strtolower($field['readonly']) == "true") { // need to pull the data that loaded with the form if ($newObject === FALSE) { // grab it from the database $oldObject = objects::get($objectID); $values[$field['name']] = $oldObject['data'][$field['name']]; } else { // If the form has a variable in the value we apply the variable, otherwise, field value. // we need to check for disabled on insert form if (!isset($field['disabledInsert']) || isset($field['disabledInsert']) && $field['disabledInsert'] == "false") { $values[$field['name']] = self::hasFieldVariables($field['value']) ? self::applyFieldVariables($value) : $field['value']; } // grab the default value from the form. // $values[$field['name']] = $field['value']; } } else { if (strtolower($field['type']) == "file" && isset($engine->cleanPost['MYSQL'][$field['name']])) { // Process uploaded files $uploadID = $engine->cleanPost['MYSQL'][$field['name']]; // Process the uploads and put them into their archival locations if (($tmpArray = files::processObjectUploads($objectID, $uploadID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - Archival Location", errorHandle::DEBUG); return FALSE; } if ($tmpArray !== TRUE) { // didn't generate a proper uuid for the items, rollback if (!isset($tmpArray['uuid'])) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - No UUID", errorHandle::DEBUG); return FALSE; } // ads this field to the files object // we can't do inserts yet because we don't have the objectID on // new objects files::addProcessingField($field['name']); // Should the files be processed now or later? if (isset($field['bgProcessing']) && str2bool($field['bgProcessing']) === TRUE) { $backgroundProcessing[$field['name']] = TRUE; } else { $backgroundProcessing[$field['name']] = FALSE; } $values[$field['name']] = $tmpArray; } else { // if we don't have files, and this is an update, we need to pull the files information from the // version that is already in the system. $oldObject = objects::get($objectID); if ($newObject === FALSE && objects::hasFiles($objectID, $field['name']) === TRUE) { $values[$field['name']] = $oldObject['data'][$field['name']]; } } } else { $values[$field['name']] = $value; } } } if (isset($engine->errorStack['error']) && count($engine->errorStack['error']) > 0) { // errorHandle::newError(__METHOD__."() - Error stack not empty.", errorHandle::DEBUG); return FALSE; } // start transactions $result = $engine->openDB->transBegin("objects"); if ($result !== TRUE) { if (!$importing) { errorHandle::errorMsg("Database transactions could not begin."); } errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG); return FALSE; } if ($newObject === TRUE) { if (objects::create($formID, $values, $form['metadata'], isset($engine->cleanPost['MYSQL']['parentID']) ? $engine->cleanPost['MYSQL']['parentID'] : "0") === FALSE) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); if (!$importing) { errorHandle::errorMsg("Error inserting new object."); } errorHandle::newError(__METHOD__ . "() - Error inserting new object.", errorHandle::DEBUG); return FALSE; } // Grab the objectID of the new object $objectID = localvars::get("newObjectID"); } else { if (objects::update($objectID, $formID, $values, $form['metadata'], isset($engine->cleanPost['MYSQL']['parentID']) ? $engine->cleanPost['MYSQL']['parentID'] : "0") === FALSE) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); if (!$importing) { errorHandle::errorMsg("Error updating."); } errorHandle::newError(__METHOD__ . "() - Error updating.", errorHandle::DEBUG); return FALSE; } } // Now that we have a valid objectID, we insert into the processing table if (files::insertIntoProcessingTable($objectID) === FALSE) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - Processing Table", errorHandle::DEBUG); return FALSE; } // end transactions $engine->openDB->transCommit(); $engine->openDB->transEnd(); if (!is_empty($backgroundProcessing)) { foreach ($backgroundProcessing as $fieldName => $V) { if ($V === FALSE) { // No background processing. do it now. files::process($objectID, $fieldName); } } } if ($newObject === TRUE) { if (!$importing) { errorHandle::successMsg("Object created successfully."); } } else { if (!$importing) { errorHandle::successMsg("Object updated successfully."); } } return TRUE; }
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; }
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(); } }
public static function buildObject($row, $ignoreCache = FALSE, $metadata = TRUE) { if (!is_array($row)) { return FALSE; } if (!$ignoreCache) { $mfcs = mfcs::singleton(); $cachID = "getObject:" . $row['ID']; $cache = $mfcs->cache("get", $cachID); if (!isnull($cache)) { return $cache; } } // @TODO sanity checking // we might want to do a little more sanity cheecking here. // does $data['data'] exist? // does it have the proper structure? // etc ... if ($metadata !== FALSE) { // **** Original way of getting data if (($row['data'] = decodeFields($row['data'])) === FALSE) { errorHandle::errorMsg("Error retrieving object."); return FALSE; } // **** objectsData table method for getting data // if (($row['data'] = self::retrieveObjectData($row['ID'])) === FALSE) { // errorHandle::errorMsg("Error retrieving object."); // return FALSE; // } // **** objectsData, single query // $object = $row[0]; // $data = array(); // foreach ($row as $fragment) { // $data[$fragment['fieldName']] = ($fragment['encoded'] == "1")?decodeFields($fragment['value']):$fragment['value']; // } // $object['data'] = $data; // unset($object['fieldName']); // unset($object['value']); // $row = $object; } if (!$ignoreCache) { $cache = $mfcs->cache("create", $cachID, $row); if ($cache === FALSE) { errorHandle::newError(__METHOD__ . "() - unable to cache object", errorHandle::DEBUG); } } return $row; }
} 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']); }