function initTemplates() { global $fmdb; //compare the stored templates with those in the templates directory. Files that exist in the database but not on disk are re-created on disk; files that exist on disk are all stored in the database. $files = $this->getTemplateFiles($this->templatesDir); $dbTemplates = $fmdb->getTemplateList(); //echo '<pre>'.print_r($files, true).'</pre>'; //echo '<pre>'.print_r($dbTemplates, true).'</pre>'; //replace any 'lost' templates (this is primarily to keep template files across an update) foreach ($dbTemplates as $dbFile => $dbTemp) { $dbFile = trim($dbFile); $templateInfo = $fmdb->getTemplate($dbFile, false); if (isset($files[$dbFile])) { // file exists on disk unset($files[$dbFile]); //unset the file; the list of files will be used later to load in new files $filemtime = filemtime($this->templatesDir . '/' . $dbFile); if ($filemtime > $templateInfo['modified']) { //file is a newer version than the one in the db $content = file_get_contents($this->templatesDir . '/' . $dbFile); $template = $this->getTemplateAttributes($dbFile); $title = $template['template_name']; //echo $title." updated<br />"; $fmdb->storeTemplate($dbFile, $title, $content, $filemtime); } } else { // file does not exist on disk //echo $dbFile." recreated<br />"; $templateInfo = $fmdb->getTemplate($dbFile); fm_write_file($this->templatesDir . '/' . $dbFile, $templateInfo['content']); } } foreach ($files as $file) { $filemtime = filemtime($this->templatesDir . '/' . $file); $content = file_get_contents($this->templatesDir . '/' . $file); $title = $template['template_name']; //echo $title." loaded<br />"; $fmdb->storeTemplate($file, $title, $content, $filemtime); } }
function fm_downloadAllFiles() { global $fmdb; global $fm_controls; $tmpDir = fm_getTmpPath(); $formID = sanitize_text_field($_POST['id']); $itemID = sanitize_text_field($_POST['itemid']); $formInfo = $fmdb->getForm($formID); foreach ($formInfo['items'] as $item) { if ($item['unique_name'] == $itemID) { $itemLabel = $item['label']; $fileItem = $item; } } $formData = $fmdb->getFormSubmissionDataRaw($formID, 'timestamp', 'DESC', 0, 0); $files = array(); foreach ($formData as $dataRow) { $fileInfo = unserialize($dataRow[$itemID]); if (sizeof($fileInfo) > 1) { if (!isset($fileInfo['upload_dir'])) { $fname = "(" . $dataRow['timestamp'] . ") " . $fileInfo['filename']; $files[] = $tmpDir . $fname; fm_write_file($tmpDir . $fname, $fileInfo['contents']); } else { $files[] = $fm_controls['file']->parseUploadDir($fileItem['extra']['upload_dir']) . $fileInfo['filename']; } } } if (sizeof($files) > 0) { $zipFileName = $formInfo['title'] . " - " . $itemLabel . ".zip"; $zipFullPath = $tmpDir . sanitize_title($zipFileName); fm_createZIP($files, $zipFullPath); $fp = fopen(fm_getTmpPath() . "download.php", "w"); fwrite($fp, fm_createDownloadFileContents($zipFullPath, $zipFileName)); fclose($fp); echo fm_getTmpURL() . "download.php"; die; } else { die; } die; }
function fm_createCSVFile($formID, $query, $fullpath) { global $fmdb; $csvData = $fmdb->getFormSubmissionDataCSV($formID, $query); return fm_write_file($fullpath, $csvData); }