Example #1
0
 public static function buildFilesPreview($objectID, $fieldName = NULL)
 {
     if (objects::validID(TRUE, $objectID) === FALSE) {
         return FALSE;
     }
     if (($object = objects::get($objectID, TRUE)) === FALSE) {
         return FALSE;
     }
     $output = '';
     if (isset($fieldName)) {
         $field = forms::getField($object['formID'], $fieldName);
         $fields = array($field);
     } else {
         $fields = forms::getFields($object['formID']);
     }
     $fileLIs = array();
     foreach ($fields as $field) {
         if ($field['type'] != 'file') {
             continue;
         }
         // If there's nothing uploaded for the field, no need to continue
         if (empty($object['data'][$field['name']])) {
             continue;
         }
         // Figure out some needed vars for later
         $fileDataArray = $object['data'][$field['name']];
         $assetsID = $fileDataArray['uuid'];
         $fileLIs = array();
         uasort($fileDataArray['files']['archive'], function ($a, $b) {
             return strnatcasecmp($a['name'], $b['name']);
         });
         foreach ($fileDataArray['files']['archive'] as $fileID => $file) {
             $_filename = pathinfo($file['name']);
             $filename = $_filename['filename'];
             $links = array();
             $links['Original'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'archive');
             if (str2bool($field['convert'])) {
                 $links['Converted'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'processed');
             }
             if (str2bool($field['thumbnail'])) {
                 $links['Thumbnail'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'thumbs');
             }
             if (str2bool($field['ocr'])) {
                 $links['OCR'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'ocr');
             }
             if (str2bool($field['combine'])) {
                 $links['Combined PDF'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], 'combinedPDF');
                 $links['Combined Thumbnail'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], 'combinedThumb');
             }
             $previewLinks = array();
             $downloadLinks = array();
             foreach ($links as $linkLabel => $linkURL) {
                 $previewLinks[] = sprintf('<li><a tabindex="-1" href="javascript:;" onclick="previewFile(this,\'%s\')">%s</a></li>', $linkURL, $linkLabel);
                 $downloadLinks[] = sprintf('<li><a tabindex="-1" href="%s&download=1">%s</a></li>', $linkURL, $linkLabel);
             }
             // Build the preview dropdown HTML
             $previewDropdown = '<div class="btn-group">';
             $previewDropdown .= '	<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">';
             $previewDropdown .= '		Preview <span class="caret"></span>';
             $previewDropdown .= '	</a>';
             $previewDropdown .= sprintf('<ul class="dropdown-menu">%s</ul>', implode('', $previewLinks));
             $previewDropdown .= '</div>';
             // Build the download dropbox HTML
             $downloadDropdown = '<div class="btn-group">';
             $downloadDropdown .= '	<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">';
             $downloadDropdown .= '		Download <span class="caret"></span>';
             $downloadDropdown .= '	</a>';
             $downloadDropdown .= sprintf('<ul class="dropdown-menu">%s</ul>', implode('', $downloadLinks));
             $downloadDropdown .= '</div>';
             $fileLIs[] = sprintf('<li><div class="filename">%s</div><!-- TODO <button class="btn">Field Details</button> -->%s%s</li>', $file['name'], $previewDropdown, $downloadDropdown);
         }
         $output .= sprintf('<div class="filePreviewField"><header>%s</header><ul class="filePreviews">%s</ul></div>', $field['label'], implode('', $fileLIs));
     }
     // Include the filePreview Modal, and the CSS and JavaScript links
     $output .= '<div id="filePreviewModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3></h3></div><div class="modal-body"><iframe class="filePreview"></iframe></div><div class="modal-footer"><a class="btn previewDownloadLink">Download File</a><a class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Close</a></div></div>';
     $output .= sprintf('<link href="%sincludes/css/filePreview.css" rel="stylesheet">', localvars::get('siteRoot'));
     $output .= sprintf('<script src="%sincludes/js/filePreview.js"></script>', localvars::get('siteRoot'));
     return $output;
 }
Example #2
0
if (isset($engine->cleanGet['MYSQL']['ajax'])) {
    $result = array();
    if (isset($engine->cleanPost['MYSQL']['action'])) {
        switch ($engine->cleanPost['MYSQL']['action']) {
            case 'updateUserProjects':
                $result = users::updateUserProjects();
                break;
            default:
                break;
        }
    } else {
        if (isset($engine->cleanGet['MYSQL']['action'])) {
            switch ($engine->cleanGet['MYSQL']['action']) {
                case 'selectChoices':
                    $field = forms::getField($engine->cleanGet["MYSQL"]['formID'], $engine->cleanGet["MYSQL"]['fieldName']);
                    $fieldChoices = forms::getFieldChoices($field);
                    $result = forms::drawFieldChoices($field, $fieldChoices);
                    die($result);
                    break;
                case 'searchFormFields':
                    die(mfcsSearch::formFieldOptions($engine->cleanGet["MYSQL"]['formID']));
                    break;
                case 'paginationPerPage':
                    $result = users::setField('pagination', $engine->cleanGet["MYSQL"]['perPage']);
                    die(json_encode($result ? "TRUE" : "FALSE"));
                    break;
                case 'paginationJumpToIDNO':
                    $objects = objects::getAllObjectsForForm($engine->cleanGet['MYSQL']['formID'], "idno");
                    for ($I = 0; $I < count($objects); $I++) {
                        if (strtolower($objects[$I]['idno']) == strtolower($engine->cleanGet['MYSQL']['idno'])) {
Example #3
0
$engine->obCallback = FALSE;
try {
    // Check for simple (stupid developer errors)
    if (!isset($engine->cleanGet['MYSQL']['objectID'])) {
        throw new Exception('No Object ID provided!');
    }
    if (!isset($engine->cleanGet['MYSQL']['field'])) {
        throw new Exception('No field provided!');
    }
    if (!isset($engine->cleanGet['MYSQL']['type'])) {
        throw new Exception('No file type provided!');
    }
    // Get some vars
    $object = objects::get($engine->cleanGet['MYSQL']['objectID']);
    $fieldName = $engine->cleanGet['MYSQL']['field'];
    $field = forms::getField($object['formID'], $engine->cleanGet['MYSQL']['field']);
    $fileType = trim($engine->cleanGet['MYSQL']['type']);
    $fileArray = $object['data'][$fieldName];
    $fileUUID = $fileArray['uuid'];
    // print "<pre>";
    // var_dump($fileArray);
    // print "</pre>";
    if (FALSE === strpos($fileType, 'combined')) {
        // Non-combined file
        $fileID = $engine->cleanGet['MYSQL']['fileID'];
        $file = $fileArray['files'][$fileType][$fileID];
        $filepath = files::getSaveDir($fileUUID, $fileType) . DIRECTORY_SEPARATOR . $file['name'];
    } else {
        // Combined file
        if ($fileType == 'combinedPDF') {
            // Show the combined PDF