function processFilePicker($label, $questionNum, $required, $fileName, $pkId, $containerUrl, $canModify) { global $log, $site_prefix, $getContainerUrl; //Start of refactor work $submitFileButtonId = "submit-all-" . $questionNum; $removeFileButtonId = "remove-all-" . $questionNum; $glyphiconRemoveId = $pkId . "_remove"; $formDropzoneId = "file_dropzone" . $questionNum; $fullFileId = "fullImage" . $questionNum; $uploadSuccessId = "upload-success-" . $questionNum; $uploadButtonLabel = "Upload File"; $removeButtonLabel = "Remove File"; $primaryKeyId = "pkid-" . $questionNum; //Added question number hidden field to work with the image/file downloader for display $hiddenQuestNumId = $pkId . "_" . $questionNum; $replacementDivId = $pkId . "_replace"; $getContainerDataMethod = "getContainerData" . $questionNum; $rewriteImageDivMethod = "rewriteImageDiv" . $questionNum; $fileTypeID = $pkId . "_" . $questionNum . "_fileType"; $fileTypeIcon = ""; //support file delete from FileMaker functionality $deleteSuccessId = "remove-success-" . $questionNum; $removeMethodName = "removeFile" . $questionNum; if (isset($containerUrl) && !empty($containerUrl)) { $extension = getFileMakerContainerFileExtension($containerUrl); $fileTypeIcon = getFileIcon($extension); } if ((!isset($fileName) || empty($fileName)) && (isset($containerUrl) && !empty($containerUrl))) { $fileName = getLightBoxCaption($containerUrl); } ?> <br> <div class="row"> <div class="col-xs-12 col-lg-12"> <h6><b> <?php echo $questionNum . ". " . $label; ?> <?php if ($required) { ?> <i class="text-danger"> *(REQUIRED)</i> <?php } ?> </b> </h6> </div> </div> <div class="tdc-container-fluid"><!-- wrap the file dropzone and display area with the TDC container equalize width between file and image --> <div class="row"> <input type="hidden" id="<?php echo $primaryKeyId; ?> " name="<?php echo $primaryKeyId; ?> " value="<?php echo $pkId; ?> "> <input type="hidden" id="<?php echo $hiddenQuestNumId; ?> " name="<?php echo $hiddenQuestNumId; ?> " value="<?php echo $questionNum; ?> "> <input type="hidden" id="<?php echo $fileTypeID; ?> " name="<?php echo $fileTypeID; ?> " value="file"> <?php if ($canModify) { ?> <?php if (!empty($containerUrl)) { ?> <!-- container has data so display image in Lightbox--> <div id="<?php echo $replacementDivId; ?> " name="<?php echo $replacementDivId; ?> "><!-- start of image replacement div --> <div class="col-xs-6 col-md-6"><!-- move this outside of if() test to line 190 --> <span class="glyphicon glyphicon-remove pull-right remove-cross" title="Remove File From Server" data-toggle="tooltip" id="<?php echo $glyphiconRemoveId; ?> " onclick="<?php echo $removeMethodName; ?> ('<?php echo $primaryKeyId; ?> ');" style="margin-right: 10px;"> </span> <div class="image_container"> <a href="<?php echo $containerUrl; ?> " alt="Full File"> <img class="img-responsive preview-image" src="<?php echo $fileTypeIcon; ?> " align="left" id="<?php echo $fullFileId; ?> "> <!-- <p class="text-center" style="padding-left: 20px;"><?php echo urldecode($fileName); ?> </p> --> </a> </div> <div class="row text-left text-success tdc-display-none" id="<?php echo $deleteSuccessId; ?> "> <strong>File Successfully Deleted From FileMaker</strong><br> </div> </div><!-- end of first 6 column div --> <div class="col-xs-6 col-md-6 tdc-cell-spacing"> <div class="row"> <div id="<?php echo $formDropzoneId; ?> " class="decoration dropzone"></div> </div> <div class="row pull-right upload-btn-position"> <button type="button" id="<?php echo $submitFileButtonId; ?> " class="btn btn-primary upload-btn"><?php echo $uploadButtonLabel; ?> </button> <button type="button" id="<?php echo $removeFileButtonId; ?> " class="btn btn-danger upload-btn"><?php echo $removeButtonLabel; ?> </button> </div> <div class="row text-right text-success tdc-display-none" id="<?php echo $uploadSuccessId; ?> "> <strong>Image Successfully Uploaded</strong><br> <i class="text-info"><strong>The preview of the image is not immediate available.</strong></i> </div> </div><!-- end of second 6 column div --> </div><!-- end of replacement div --> <?php } else { if (empty($containerUrl) && !empty($fileName)) { ?> <!-- container is empty but the filename field exists --> <div id="<?php echo $replacementDivId; ?> " name="<?php echo $replacementDivId; ?> "><!-- start of image replacement div --> <div class="col-xs-6 col-md-6 empty_image_container"><!-- move this outside of if() test to line 190 --> <p class="text-center">Import still processing file <?php echo $fileName; ?> .</p> <p class="text-center"> Reload page when complete.</p> </div> <div class="col-xs-6 col-md-6"> <div class="row"> <div id="<?php echo $formDropzoneId; ?> " class="decoration dropzone"></div> </div> <div class="row pull-right upload-btn-position"> <button type="button" id="<?php echo $submitFileButtonId; ?> " class="btn btn-primary upload-btn"><?php echo $uploadButtonLabel; ?> </button> <button type="button" id="<?php echo $removeFileButtonId; ?> " class="btn btn-danger upload-btn"><?php echo $removeButtonLabel; ?> </button> </div> <div class="row text-right text-success tdc-display-none" id="<?php echo $uploadSuccessId; ?> "> <strong>Image Successfully Uploaded</strong><br> <i class="text-info"><strong>The preview of the image is not immediate available.</strong></i> </div> </div> </div><!-- end of replacement div --> <?php } else { ?> <!-- No container data or filename just display Dropzone box --> <div id="<?php echo $replacementDivId; ?> " name="<?php echo $replacementDivId; ?> "><!-- start of image replacement div --> <div class="col-xs-12 col-md-12"> <div class="row"> <div id="<?php echo $formDropzoneId; ?> " class="decoration dropzone"></div> </div> <div class="row pull-right upload-btn-position"> <button type="button" id="<?php echo $submitFileButtonId; ?> " class="btn btn-primary upload-btn"><?php echo $uploadButtonLabel; ?> </button> <button type="button" id="<?php echo $removeFileButtonId; ?> " class="btn btn-danger upload-btn"><?php echo $removeButtonLabel; ?> </button> </div> <div class="row text-right text-success tdc-display-none" id="<?php echo $uploadSuccessId; ?> "> <strong>Image Successfully Uploaded</strong><br> <i class="text-info"><strong>The preview of the image is not immediate available.</strong></i> </div> </div> </div><!-- end of replacement div --> <?php } } ?> <?php } else { ?> <!-- The user cannot remove or add the file downloaded from FileMaker or else just show empty bordered DIV --> <?php if ($containerUrl) { ?> <div class="col-xs-12 col-md-12 image_container"> <a href="<?php echo $containerUrl; ?> " alt="Full File"> <img class="img-responsive preview-image" src="<?php echo $fileTypeIcon; ?> " align="left" id="<?php echo $fullFileId; ?> "> <p class="text-center" style="padding-left: 20px;"><?php echo urldecode($fileName); ?> </p> </a> </div> <?php } else { ?> <div class="col-xs-12 col-md-12 image_container"></div> <?php } ?> <?php } ?> </div> </div><!-- end of tdc-container-fluid div --> <script> $(document).ready(function () { $('<?php echo '#' . $submitFileButtonId; ?> ').hide(); $('<?php echo '#' . $removeFileButtonId; ?> ').hide(); $('<?php echo '#' . $uploadSuccessId; ?> ').hide(); $('<?php echo '#' . $deleteSuccessId; ?> ').hide(); }); function <?php echo $removeMethodName; ?> (elmId){ var pkid = document.getElementById(elmId).value; console.log("PK: " + pkid); $.ajax({ data: 'pkId=' + pkid, url: 'processing/removeFileFM.php', method: 'POST', success: function(msg){ console.log(msg); }, error: function(msg){ console.log("Error: " + msg); } }); var fileSelected = document.getElementById('<?php echo $fullFileId; ?> '); fileSelected.parentNode.removeChild(fileSelected); $('<?php echo '#' . $deleteSuccessId; ?> ').fadeIn(100).delay(5000).fadeOut(500); } Dropzone.options.<?php echo getCamelCase($formDropzoneId); ?> = { //URL to submit the for //TODO make this more dynamic Remove all hardcoded path elements in this page url: '../uploaders/imageUploader.php', //Prevent dropzone from uploading files immediately autoProcessQueue: false, //Dropzone accepts the file types to upload acceptedFiles: ".pdf, .docx, .doc, .txt, .xls, .xlsx", init: function(){ var submitButton = document.querySelector('<?php echo '#' . $submitFileButtonId; ?> '); var myDropzone = this; //closure submitButton.addEventListener("click", function(){ console.log("Event listener fired"); myDropzone.processQueue(); //Tell Dropzone to process all queued files }); this.on("sending", function(file, xhr, data) { console.log("Adding Meta record PKID to Post array"); data.append("pkId", document.getElementById('<?php echo $primaryKeyId; ?> ').value); }); //if an error is found with mime type of file hide the submit button this.on("error", function(file, response){ console.log("Error has occurred"); $('<?php echo '#' . $submitFileButtonId; ?> ').hide(); }); this.on("success", function(file, response){ console.log("Successful upload"); $('<?php echo '#' . $submitFileButtonId; ?> ').hide(); $('<?php echo '#' . $removeFileButtonId; ?> ').hide(); $('<?php echo '#' . $uploadSuccessId; ?> ').fadeIn(100).delay(5000).fadeOut(500); //Now we need to get the flag to run get the 'Just' uploaded image/file URL var runContainerUrl = <?php echo $getContainerUrl ? 'true' : 'false'; ?> ; var jsonData = JSON.parse(response); if(jsonData && jsonData.container_status){ if(jsonData.container_status != '' && jsonData.container_status == 'empty'){ console.log("We have container status of empty so now get the container URL"); <?php echo $getContainerDataMethod; ?> (document.getElementById('<?php echo $primaryKeyId; ?> ').value, myDropzone); } } }); //When a file is dropped inside Dropzone show box show button controls //TODO would like to use the success return to ensure that the button will only show when mine // type matches what we expect this.on("addedfile", function(file){ var ext = file.name.split('.').pop(); console.log("File Extension for added file: " + ext); if(ext == 'pdf'){ $(file.previewElement).find(".dz-image img").attr("src", "../images/PDF-icon_128px_red.png"); }else if(ext.indexOf('doc') != -1) { //this test was doc or docx $(file.previewElement).find(".dz-image img").attr("src", "../images/Office-Word-icon_128px_blue.png"); }else if(ext.indexOf('xls') != -1) { //this test was xls or xslx console.log("Show excel icon"); $(file.previewElement).find(".dz-image img").attr("src", "../images/excel-icon-128px.png"); }else if(ext == 'txt'){ $(file.previewElement).find(".dz-image img").attr("src", "../images/text-icon_128px.png"); } $('<?php echo '#' . $removeFileButtonId; ?> ').show(); $('<?php echo '#' . $submitFileButtonId; ?> ').show(); }); //removes files previous loaded in the Dropzone upload box //Also hides upload and reset buttons document.querySelector("button#<?php echo $removeFileButtonId; ?> ").addEventListener("click", function(){ myDropzone.removeAllFiles(); $('<?php echo '#' . $submitFileButtonId; ?> ').hide(); $('<?php echo '#' . $removeFileButtonId; ?> ').hide(); }); } } /** * Method to recursively call a PHP file and get the container URL for a given META PK * @param pkId string value of the PK for a given meta record * Note: TODO: can this be a generic method to replace a DIV encapsulating a image or file */ function <?php echo $getContainerDataMethod; ?> (pkId, myDropzone){ var getFileTimer = setTimeout(function() { console.log("getContainerData called with PKID: " + pkId); $.ajax({ url: "../uploaders/urlReloader.php", //get the file name of PHP processor to get container URL data: {"pk":pkId}, type: "POST", success: function(response){ console.log("getContainerDataMethod Success " + response); var jsonData = JSON.parse(response); if(jsonData.container_status == "empty"){ console.log("Conatiner is empty so call method again"); <?php echo $getContainerDataMethod; ?> (pkId, myDropzone); //now run this method ever 5 seconds as a thread to release browser }else{ if(jsonData.container_url) { <?php echo $rewriteImageDivMethod; ?> (pkId, document.getElementById('<?php echo $hiddenQuestNumId; ?> ').value, jsonData.container_url,jsonData.filename, myDropzone, document.getElementById('<?php echo $fileTypeID; ?> ').value); clearTimeout(getFileTimer); return false; }else{ console.log("Strange condition - container status not empty without a URL in JSON array"); } } }, error: function(response){ console.log("Error: " + response); jsonErrorData = JSON.parse(response); if(jsonErrorData.status == "error"){ console.log("Error occurred kill get URL process"); clearTimeout(getFileTimer); return false; } } }); }, 5000); //This setup to run ever 5 seconds and this needs to be adjusted to more like 1 or 2 minute cycles } /** * Rewrite the Div srounding the Image or file and replace it with the URL from the FM container * @param pk Primary meta file record id/key UUID * @param questNum the meta question number associated with item * @param url the container URL * @param filename the filename of the object file/image uploaded */ function <?php echo $rewriteImageDivMethod; ?> (pk, questNum, url, filename, dzHandle, filetype){ console.log("rewriteImageDiv PK: " + pk + " Question Number: " + questNum + " URL: " + url); //Call the php file with POST format and query string attributes $('<?php echo '#' . $replacementDivId; ?> ').load('../uploaders/loadFileImageDiv.php', {'pk':pk, 'url':url, 'questNum':questNum, 'filename':filename,'filetype':filetype}, function(){ console.log("Load complete now hide buttons"); $('<?php echo '#' . $submitFileButtonId; ?> ').hide(); $('<?php echo '#' . $removeFileButtonId; ?> ').hide(); }); dzHandle.removeAllFiles(); } </script> <?php }
function getFormClassName($tableName, $appNamespace) { return $appNamespace . 'Form_Edit' . getCamelCase($tableName); }
if ($column['PK'] && count($primkeys) === 1) { $daofinders .= ' /**' . PHP_EOL . ' /* Primary Key Finder' . PHP_EOL . ' /* @return object' . PHP_EOL . ' */' . PHP_EOL . ' public function findBy' . getCamelCase($columnname) . '($' . $columnname . ')' . PHP_EOL . ' {' . PHP_EOL . ' $sql="SELECT * FROM ' . $tablename . ' WHERE ' . $columnname . '=\'$' . $columnname . '\' LIMIT 1";' . PHP_EOL . ' return $this->getSelfObject($sql);' . PHP_EOL . ' }' . PHP_EOL . PHP_EOL; } else { $daofinders .= ' /**' . PHP_EOL . ' /* Column ' . $columnname . ' Finder' . PHP_EOL . ' /* @return object[]' . PHP_EOL . ' */' . PHP_EOL . ' public function findBy' . getCamelCase($columnname) . '($' . $columnname . ')' . PHP_EOL . ' {' . PHP_EOL . ' $sql="SELECT * FROM ' . $tablename . ' WHERE ' . $columnname . '=\'$' . $columnname . '\'";' . PHP_EOL . ' return $this->getSelfObjects($sql);' . PHP_EOL . ' }' . PHP_EOL . PHP_EOL; } } } if (count($primkeys) > 1) { $name = implode('And', array_map('ucfirst', $primkeys)); $vars = implode(',', array_map(function ($x) { return '$' . $x; }, $primkeys)); $where = implode(' AND ', array_map(function ($x) { return $x . "='\$" . $x . "'"; }, $primkeys)); $daofinders .= ' /**' . PHP_EOL . ' /* Composite Primary Key Finder' . PHP_EOL . ' /* @return object' . PHP_EOL . ' */' . PHP_EOL . ' public function findBy' . getCamelCase($name) . '(' . $vars . ')' . PHP_EOL . ' {' . PHP_EOL . ' $sql="SELECT * FROM ' . $tablename . ' WHERE ' . $where . ' LIMIT 1";' . PHP_EOL . ' return $this->getSelfObject($sql);' . PHP_EOL . ' }' . PHP_EOL . PHP_EOL; } // $daocontent .= "abstract class {$class}DAO extends EntityBase" . PHP_EOL . '{' . PHP_EOL . $daovars . PHP_EOL . ' /**' . PHP_EOL . ' /* Constructor' . PHP_EOL . ' /* @var mixed $id' . PHP_EOL . ' */' . PHP_EOL . ' public function __construct($id=0)' . PHP_EOL . ' {' . PHP_EOL . ' parent::__construct();' . PHP_EOL . " \$this->table='{$tablename}';" . PHP_EOL . " \$this->primkeys=array('" . implode("','", $primkeys) . "');" . PHP_EOL . " \$this->fields=array('" . implode("','", $fields) . "');" . PHP_EOL . ' $this->sql="SELECT * FROM {$this->table}";' . PHP_EOL . ' if($id) $this->read($id);' . PHP_EOL . ' }' . PHP_EOL . PHP_EOL; $daocontent .= $daorefs; $daocontent .= $daofinders; $daocontent .= ' // ==========!!!DO NOT PUT YOUR OWN CODE (BUSINESS LOGIC) HERE!!!==========' . PHP_EOL . ' // EXTEND THIS DAO CLASS WITH YOUR ONW CLASS CONTAINING YOUR BUSINESS LOGIC' . PHP_EOL . ' // BECAUSE THIS CLASS WILL BE !!RECREATED--OVERWRITTEN!! ON NEXT PHPDAO RUN' . PHP_EOL . '}' . PHP_EOL . PHP_EOL; $daofile = fopen($daofilename, 'w'); fwrite($daofile, $daocontent); fclose($daofile); // MODELS //////////////////////////////////////////////////////////////////// $filename = "../models/{$class}.php"; if (!file_exists($filename)) { $file = fopen($filename, 'w'); $content = '<?php' . PHP_EOL . PHP_EOL . "require_once 'DAO/{$class}.dao.php';" . PHP_EOL . PHP_EOL . '/**' . PHP_EOL . '/* Class ' . $class . PHP_EOL . ' */' . PHP_EOL . 'class ' . $class . ' extends ' . $class . 'DAO' . PHP_EOL . '{' . PHP_EOL . ' // PUT YOUR BUSINESS LOGIC HERE' . PHP_EOL . '}' . PHP_EOL . PHP_EOL . PHP_EOL; fwrite($file, $content);