12 $parameters= array(
"a" => array(
"operation" =>
"",
"filename" =>
""));
13 $string= array(
"filter" => FILTER_SANITIZE_STRING);
14 HCU_ImportVars($parameters,
"a", array(
"operation" => $string,
"filename" => $string));
15 extract($parameters[
"a"]);
17 $self=
"$menu_link?ft=$ft";
28 $dataURL=
"$menu_link?ft=$ft";
32 $showSQL= $SYSENV[
"devmode"];
36 $uploadPath=
"$home_path/public_html/pdf/";
44 "HomeBanking" => array(
45 "HomeBanking" => array(
46 "Estatement Inserts" =>
"insert.pdf",
47 "Privacy Policy" =>
"privacy.pdf",
48 "Fee Schedule" =>
"fees.pdf" 51 "publicHTML" => array(
52 "Newsletters" => array(
53 "Regular Newsletter" =>
"newsletter.pdf",
54 "Quarterly Newsletter" =>
"quarterlynews.pdf",
55 "Youth Newsletter" =>
"kidsnews.pdf",
56 "Prime Newsletter" =>
"primenews.pdf",
57 "Senior Newsletter" =>
"seniornews.pdf",
58 "Teen Newsletter" =>
"teennews.pdf",
59 "Middle School Newsletter" =>
"middleschoolnews.pdf" 61 "Miscellaneous (For information about linking documents, contact HomeCU.)" => array(
62 "Loan Rates" =>
"lrates.pdf",
63 "Savings Rates" =>
"srates.pdf",
64 "Sales (Repo) List" =>
"forsale.pdf",
65 "General Information" =>
"info.pdf",
66 "Annual Report" =>
"annualreport.pdf",
67 "Financial Statement" =>
"financials.pdf",
68 "Skip-A-Payment Form" =>
"skip-pay.pdf",
69 "Scholarship Application" =>
"scholarship.pdf",
70 "Funds Availability" =>
"funds.pdf",
71 "Holiday Schedule" =>
"holidays.pdf" 77 $operation= trim($operation);
84 $returnArray= uploadFile($uploadPath, $filename, $allowedFiles, $maxSize);
87 $returnArray= removeFile($uploadPath, $filename, $allowedFiles);
89 case "readHomeBanking":
90 $files= HCU_array_key_exists(
"HomeBanking", $allowedFiles) ? $allowedFiles[
"HomeBanking"] : array();
91 $returnArray= getFileList($dbh, $Cu, $files, $uploadPath,
"regular");
93 case "readPublicHTML":
94 $files= HCU_array_key_exists(
"publicHTML", $allowedFiles) ? $allowedFiles[
"publicHTML"] : array();
95 $returnArray= getFileList($dbh, $Cu, $files, $uploadPath,
"grouped");
98 printFilePreview($uploadPath, $filename, $allowedFiles);
102 $returnArray= array(
"error" => array(
"Operation not specified: '$operation'"),
"record" => array(),
"sql" => array());
107 header(
'Content-type: application/json');
108 print HCU_JsonEncode($returnArray);
117 <script type=
"text/javascript">
121 getShowWaitFunctions();
134 function openConfirmFileRemoval(tr)
136 var confirmFileRemoval= $(
"#confirmFileRemoval").data(
"kendoDialog");
137 if (confirmFileRemoval ==
null)
139 confirmFileRemoval= $(
"<div id='confirmFileRemoval'></div>").appendTo(
"body").kendoDialog({
140 title:
"Confirm File Removal",
142 {text:
"No", action:
function() {
144 var tr= $(
"#confirmFileRemoval").data(
"tr");
145 var ddl= $(tr).closest(
".k-grid").find(
".k-grid-toolbar [data-role='dropdownlist']").data(
"kendoDropDownList");
148 $(
"[name='actionSelection']:checked").prop(
"checked",
false);
150 {text:
"Yes", primary:
true, action:
function() {
151 var tr= $(
"#confirmFileRemoval").data(
"tr");
154 var ddl= $(tr).closest(
".k-grid").find(
".k-grid-toolbar [data-role='dropdownlist']").data(
"kendoDropDownList");
158 $(tr).closest(
".k-grid").data(
"kendoGrid").removeRow($(tr));
163 if (window.activeWindows !=
null)
164 window.activeWindows.push(
this);
167 if (window.activeWindows !=
null)
168 window.activeWindows.pop();
170 }).data(
"kendoDialog");
173 var grid= $(tr).closest(
".k-grid").data(
"kendoGrid");
174 var dataItem= grid.dataItem(tr);
175 confirmFileRemoval.content(
"<p>This file \"" + dataItem.filename +
"\" will be deleted.</p><p>Are you sure you want to do this?</p>").open();
176 $(
"#confirmFileRemoval").data(
"tr", tr);
187 function openUploadDialog(tr)
189 var uploadDialog= $(
"#uploadDialog").data(
"kendoDialog");
190 var
template= kendo.template($(
"#uploadTemplate").html());
191 if (uploadDialog ==
null)
193 uploadDialog= $(
"<div id='uploadDialog'></div>").appendTo(
"body").kendoDialog({
194 title:
"Upload File",
195 content: $(
"#uploadTemplate").html(),
197 {text:
"Cancel", action:
function() {
198 $(
"#uploader").data(
"kendoUpload").clearAllFiles();
201 var tr= $(
"#uploadDialog").data(
"tr");
202 var ddl= $(tr).closest(
".k-grid").find(
".k-grid-toolbar [data-role='dropdownlist']").data(
"kendoDropDownList");
205 $(
"[name='actionSelection']:checked").prop(
"checked",
false);
207 {text:
"Upload", primary:
true, action:
function() {
208 $(
"#uploader").data(
"kendoUpload").upload(); <?php
214 if (window.activeWindows !=
null)
215 window.activeWindows.push(
this);
218 $.homecuValidator.setup({formValidate:
'pdfuploadDiv', formStatusField:
'statusDiv'});
219 if (window.activeWindows !=
null)
220 window.activeWindows.pop();
222 }).data(
"kendoDialog");
224 var uploader= $(
"#uploader").kendoUpload({
226 saveUrl:
"<?php echo $self; ?>&operation=uploadFile",
227 withCredentials:
true,
235 var response= e.XMLHttpRequest.responseText;
237 if (response.indexOf(
"PDFUploadFirstErrorLi") != -1)
239 $(
"#formValidateMainDiv").show();
240 $(
"#formValidateMainDiv").html(
"<p>The following errors were detected:</p><ul>" + response +
"</ul>");
244 openAuthFailedDialog(response);
248 var tr= $(
"#uploadDialog").data(
"tr");
249 var ddl= $(tr).closest(
".k-grid").find(
".k-grid-toolbar [data-role='dropdownlist']").data(
"kendoDropDownList");
252 this.clearAllFiles();
257 if (e.response.code == 0)
259 var tr= $(
"#uploadDialog").data(
"tr");
260 var grid= $(tr).closest(
".k-grid").data(
"kendoGrid");
261 grid.dataSource.read();
262 this.clearAllFiles();
263 $(
"#uploadDialog").data(
"kendoDialog").close();
267 $.homecuValidator.displayMessage(e.response.error, $.homecuValidator.settings.statusError );
273 select:
function(e) <?php
276 var tr= $(
"#uploadDialog").data(
"tr");
280 if ($(tr).length == 0)
281 throw "Please select a file.";
283 var file= e.files[0];
284 if (file.extension.toLowerCase() !=
".pdf")
285 throw "File needs to be a PDF.";
287 if (file.size > <?php echo $maxSize; ?>)
288 throw "File exceeds the max size.";
295 if (error.length !=
"")
297 $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError );
305 var tr= $(
"#uploadDialog").data(
"tr");
309 if ($(tr).length == 0)
310 throw "Please select a file.";
312 var file= e.files[0];
313 if (file.extension.toLowerCase() !=
".pdf")
314 throw "File needs to be a PDF.";
316 if (file.size > <?php echo $maxSize; ?>)
317 throw "File exceeds the max size.";
324 if (error.length !=
"")
326 $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError );
333 var grid= $(tr).closest(
".k-grid").data(
"kendoGrid");
334 var dataItem= grid.dataItem($(tr));
335 e.data= {filename: dataItem.filename};
340 select:
"Select File" 342 }).data(
"kendoUpload");
344 $(
"#uploadBtn").click(
function() { $(
"#uploader").click();
return false; });
345 $(
"#uploadFileBtn").click(
function() { $(
".k-upload-selected").click();
return false; });
348 var grid= $(tr).closest(
".k-grid").data(
"kendoGrid");
349 var dataItem= grid.dataItem(tr);
351 $(
"#uploadDialog").find(
".filename").text(dataItem.filename);
352 if (dataItem.modified ==
null)
353 $(
"#uploadDialog").find(
".modified").hide();
356 $(
"#uploadDialog").find(
".modified").show();
357 $(
"#uploadDialog").find(
".size").text(dataItem.size);
360 $(
"#uploadDialog").data(
"tr", tr);
361 $.homecuValidator.setup({formValidate:
'uploadDialog', formStatusField:
'uploadStatusDiv'});
372 function openAuthFailedDialog(response)
374 var authFailedDialog= $(
"#authFailedDialog").data(
"kendoWindow");
375 if (authFailedDialog !=
null)
377 authFailedDialog.destroy();
378 $(
"#authFailedDialog").empty();
381 authFailedDialog= $(
"#authFailedDialog").kendoWindow({
382 content: {
template: response.replace(/[#]/g,
"\\#")},
390 }).data(
"kendoWindow");
392 authFailedDialog.open().center();
403 function openFileWindow(filename)
405 var fileWindow= $(
"#fileWindow").data(
"kendoWindow");
406 if (fileWindow ==
null)
408 var fileWindow= $(
"<div id='fileWindow'></div>").appendTo(
"body").kendoWindow({
411 if (window.activeWindows !=
null)
412 window.activeWindows.push(
this);
415 if (window.activeWindows !=
null)
416 window.activeWindows.pop();
421 }).data(
"kendoWindow");
423 $(
"#fileWindow").on(
"click",
".closeBtn",
function() {
424 $(
"#fileWindow").data(
"kendoWindow").close();
428 var
template= kendo.template(
'<div class="hcu-template"><embed height="100%" width="100%" id="viewIframe" src="<?php echo $self; ?>&operation=previewFile&filename=#: filename #"' 429 +
'type="application/pdf"><div class="hcu-edit-buttons k-state-default"><a class="closeBtn k-button k-primary" href="\\#"><i class="fa fa-check"></i>Close</a></div></div>');
430 fileWindow.content(
template({operation:
"viewFile", filename: filename})).open().center();
441 $.homecuValidator.setup({formValidate:
'pdfuploadDiv', formStatusField:
'statusDiv'});
442 var gridDefinition= {
446 destroy: { url:
"<?php echo $self; ?>&operation=removeFile", dataType:
"json", type:
"POST" },
447 parameterMap:
function(data, type) {
453 return {filename: data.filename};
461 kendoId: {type:
"number"},
462 filename: {type:
"string"},
463 modified: {type:
"string"},
464 size: {type:
"string"},
465 type: {type:
"string"}
473 $.homecuValidator.displayMessage(e.errors, $.homecuValidator.settings.statusError );
475 requestEnd:
function(e) {
479 var selected= $(
"[name='actionSelection']:checked");
480 if ($(selected).length > 0)
482 var ddl= $(selected).closest(
".k-grid").find(
".k-grid-toolbar [data-role='dropdownlist']").data(
"kendoDropDownList");
487 if (e.type ==
"destroy" &&
this.options.serverGrouping)
496 {field:
"filename", title:
"Name"},
497 {field:
"modified", title:
"Modified"},
498 {field:
"size", title:
"Size"}
504 remove:
function(e) {
505 this.dataSource.add({id: e.model.id, kendoId: e.model.kendoId, filename: e.model.filename, type: e.model.type, modified:
null, size:
null});
506 this.dataSource.sync();
511 var
template= $(
"#rowTemplate").html();
512 var hbTemplate=
template.replace(
"#####",
"");
513 var phTemplate=
template.replace(
"#####",
"<td></td>"); <?php
514 gridDefinition.dataSource.transport.read= {url:
"<?php echo $self; ?>&operation=readHomeBanking", dataType:
"json", type:
"POST"};
515 gridDefinition.toolbar=
"<div id='actionHomeBankingDDL'></div>";
516 gridDefinition.rowTemplate= hbTemplate;
517 var homeBankingGrid= $(
"#homeBankingGrid").kendoGrid(gridDefinition).data(
"kendoGrid");
518 gridDefinition.dataSource.transport.read= {url:
"<?php echo $self; ?>&operation=readPublicHTML", dataType:
"json", type:
"POST"};
519 gridDefinition.toolbar=
"<div id='actionPublicHTMLDDL'></div>";
520 gridDefinition.rowTemplate= phTemplate;
521 gridDefinition.columns.push({field:
"type", hidden:
true, groupHeaderTemplate:
"#: value #"})
522 gridDefinition.dataSource.group= {field:
"type"};
523 gridDefinition.dataSource.serverSorting=
true;
524 gridDefinition.dataSource.serverGrouping=
true;
525 gridDefinition.remove= undefined;
526 var publicHTMLGrid= $(
"#publicHTMLGrid").kendoGrid(gridDefinition).data(
"kendoGrid");
529 dataSource: [{text:
"Action ...", value: 1}, {text:
"Upload", value: 2}, {text:
"Delete", value: 3}],
531 dataTextField:
"text",
532 dataValueField:
"value",
533 change:
function(e) {
535 var tr= $(this.wrapper).closest(
".k-grid").find(
"tr:has([name='actionSelection']:checked)");
540 openUploadDialog(tr);
543 openConfirmFileRemoval(tr);
551 var actionHomeBankingDDL= $(
"#actionHomeBankingDDL").kendoDropDownList(ddlDefinition).data(
"kendoDropDownList");
552 var actionPublicHTMLDDL= $(
"#actionPublicHTMLDDL").kendoDropDownList(ddlDefinition).data(
"kendoDropDownList");
555 $(
"#homeBankingGrid,#publicHTMLGrid").on(
"click",
"[name='actionSelection']",
function() {
556 var tr= $(
this).closest(
"tr");
557 var grid= $(tr).closest(
".k-grid").attr(
"id");
558 if (grid ==
"homeBankingGrid")
560 var ddl= $(
"#actionHomeBankingDDL").data(
"kendoDropDownList");
561 var otherDDL= $(
"#actionPublicHTMLDDL").data(
"kendoDropDownList");
565 var otherDDL= $(
"#actionHomeBankingDDL").data(
"kendoDropDownList");
566 var ddl= $(
"#actionPublicHTMLDDL").data(
"kendoDropDownList");
568 grid= $(
"#"+grid).data(
"kendoGrid");
569 var dataItem= grid.dataItem($(tr));
570 var filter= dataItem.modified ==
null ? {field:
"value",
operator:
"neq", value: 3} : []; <?php
572 ddl.dataSource.filter(filter);
576 otherDDL.enable(
false);
579 $(
"#homeBankingGrid,#publicHTMLGrid").on(
"click",
".pdfPreview",
function() {
580 var tr= $(
this).closest(
"tr");
581 var grid= $(tr).closest(
".k-grid").data(
"kendoGrid");
582 var dataItem= grid.dataItem($(tr));
583 openFileWindow(dataItem.filename);
587 $(document).ready(
function() {
591 <?php printDeleteTemplate(); ?>
592 <script
id=
"rowTemplate" type=
"text/x-kendo-template">
593 # var fileExists= modified != null; # 594 <tr data-uid=
"#= uid #">
596 <td><input type=
"radio" name=
"actionSelection"></td>
597 <td>#
if (fileExists) { # <i
class=
"fa fa-search pdfPreview showClickable"></i> # }
else { # # } #</td>
598 <td #
if (!fileExists) { # colspan=
"3" # } #>#: filename #</td>
599 # if (fileExists) { # 600 <td>#= modified #</td>
605 <script
id=
"uploadTemplate" type=
"text/x-kendo-template">
606 <div
id=
"uploadStatusDiv"></div>
607 <div
class=
"container-fluid">
608 <div
class=
"row hcuSpacer vsgSecondary">Upload a file
for <span
class=
"filename"></span>.</div>
609 <div
class=
"modified" style=
"display:none;"><div
class=
"row hcuSpacer vsgSecondary">Upload will overwrite another file with a size of <span
class=
"size"></span>.</div></div>
610 <div
class=
"row hcuSpacer"><input type=
"file" name=
"files" id=
"uploader" accept=
"application/pdf" /></div>
615 list-style-position: inside;
618 #uploadDialog .k-clear-selected, #uploadDialog .k-upload-selected, #uploadDialog .k-upload-status { 623 <div
id=
"pdfuploadDiv" class=
"container-fluid pdfuploadDiv">
624 <div
id=
"statusDiv"></div>
625 <div
class=
"hcuSpacer hcu-no-padding">
626 <div
class=
"well well-sm col-xs-12">
627 <div
class=
"container-fluid">
628 <div
class=
"row hcuSpacer h3">PDF File Upload</div>
629 <div
class=
"row hcuSpacer">
632 <li>Only one file of each type is allowed. Prior copies will be overwritten.</li>
633 <li>File must be a valid <font color='red'>PDF document.</font></li>
634 <li>File must be no larger than <font color='red'>10MB</font> in size.</li>
636 Contact HomeCU to
set up additional upload links in the lists below. Supported uploadable files include:
638 <li>Newsletters - General, Quarterly, Seniors, Teens, Kids, Middle School</li>
639 <li>Statement Inserts</li>
640 <li>Fee Schedule, Savings Rates, Loan Rates, Sales (Repo) Listing</li>
641 <li>Privacy Policy</li>
642 <li>Annual Report</li>
643 <li>Financial Statement</li>
644 <li>General Information</li>
645 <li>Skip-A-Payment Form</li>
646 <li>Scholarship Application</li>
647 <li>Funds Availability</li>
648 <li>Holiday Schedule</li>
654 <div
class=
"hcuSpacer hcu-no-padding">
655 <div
class=
"container-fluid">
656 <div
class=
"row hcuSpacer h4">Digital
Banking Uploads</div>
657 <div
class=
"row hcuSpacer"><div
id=
"homeBankingGrid"></div></div>
660 <div
class=
"hcuSpacer hcu-no-padding">
661 <div
class=
"container-fluid">
662 <div
class=
"row hcuSpacer h4">Public HTML Uploads</div>
663 <div
class=
"row hcuSpacer"><div
id=
"publicHTMLGrid"></div></div>
690 function getFileList($dbh, $Cu, $files, $uploadPath, $mode)
699 if (!is_writable($uploadPath))
700 throw new exception(
"PDF Directory is not set up correctly. Please contact HomeCU for assistance.");
701 foreach($files as $typeName => $typeFiles)
703 foreach($typeFiles as $fileName => $filePath)
705 $fullPath=
"${uploadPath}${filePath}";
709 if (is_readable($fullPath))
712 $modified= DateTime::createFromFormat(
"U", filemtime($fullPath));
714 $tz=
new DateTimeZone(GetCreditUnionTimezone($dbh, $Cu));
715 $modified->setTimezone($tz);
716 $modified= $modified->format(
"m/d/Y H:i:s");
718 $size= filesize($fullPath);
721 else if ($size < $mbMin)
722 $size= round($size/$kbMin, 2) .
" KB";
724 $size= round($size/$mbMin, 2) .
" MB";
727 $row= array(
"kendoId" => ++$index,
"filename" => $fileName,
"type" => $typeName,
"modified" => $modified,
"size" => $size);
728 if ($mode ==
"grouped")
730 if (!HCU_array_key_exists($typeName, $fileList))
731 $fileList[$typeName]= array(
"field" =>
"type",
"value" => $typeName,
"items" => array(),
"hasSubgroups" =>
false,
"aggregates" => array());
732 $fileList[$typeName][
"items"][]= $row;
739 if ($mode ==
"grouped")
740 $fileList= array_values($fileList);
742 return array(
"data" => $fileList);
746 return array(
"error" => $e->getMessage(),
"code" => $e->getCode());
763 function uploadFile($uploadPath, $filename, $allowedFiles, $maxSize)
768 "1" =>
"1: The file you tried to upload is just too big. The allowable limit is 10MB.",
769 "2" =>
"2: The file you tried to upload is just too big. The allowable limit is 10MB.",
770 "3" =>
"3: The file was only partially uploaded",
771 "4" =>
"4: no file was uploaded");
774 if (!isset($filename) || trim($filename) ==
"")
775 throw new exception(
"Please select a file to upload.", 1);
776 if (!is_writable($uploadPath))
777 throw new exception(
"PDF Directory is not set up correctly. Please contact HomeCU for assistance.", 2);
778 foreach($allowedFiles as $gridType => $files)
780 foreach($files as $typeName => $typeFiles)
782 foreach($typeFiles as $fileName => $filePath)
784 if (trim($fileName) == trim($filename))
786 $thisFilePath = $filePath;
790 if (isset($thisFilePath))
795 if (!isset($thisFilePath))
796 throw new exception(
"File isn't valid.", 3);
798 $file = $_FILES[
'files'];
800 if ($file[
"size"] > $maxSize)
801 throw new exception(
"File exceeds the max size.", 4);
802 if ($file[
"error"] != 0)
804 $errorInt= $file[
"error"];
805 throw new exception(HCU_array_key_exists($errorInt, $fileErrors) ? $fileErrors[$errorInt] :
"$errorInt: Unknown error.", 5);
808 $filetmp = $file[
'tmp_name'];
809 $filemime = explode(
";", trim(`file -bi $filetmp`));
810 if (strtolower($filemime[0]) !=
"application/pdf")
811 throw new exception(
"Wrong file type ( $filemime[0] ). File must be PDF document.", 6);
812 if (!@move_uploaded_file($filetmp,
"${uploadPath}${thisFilePath}"))
815 throw new exception(
"Couldn't post the file where it belongs. Better call HomeCU.", 7);
818 @chmod(
"${uploadPath}${thisFilePath}", 0644);
819 return array(
"code" => 0);
823 return array(
"error" => $e->getMessage(),
"code" => $e->getCode());
840 function removeFile($uploadPath, $filename, $allowedFiles)
845 if (!isset($filename) || trim($filename) ==
"")
846 throw new exception(
"Please select a file to remove.", 3);
847 if (!is_writable($uploadPath))
848 throw new exception(
"PDF Directory is not set up correctly. Please contact HomeCU for assistance.", 1);
849 foreach($allowedFiles as $gridType => $files)
851 foreach($files as $typeName => $typeFiles)
853 foreach($typeFiles as $fileName => $filePath)
855 if (trim($fileName) == trim($filename))
857 $thisFilePath= $filePath;
861 if (isset($thisFilePath))
867 if (isset($thisFilePath))
869 $fullPath=
"${uploadPath}${thisFilePath}";
870 if (@file_exists($fullPath) && !@unlink($fullPath))
871 throw new exception(
"File could not be deleted. Better call HomeCU.", 2);
874 return array(
"data" => isset($thisFilePath) ?
"path found" :
"path NOT found");
878 return array(
"error" => $e->getMessage(),
"code" => $e->getCode());
890 function printFilePreview($uploadPath, $filename, $allowedFiles)
895 if (!isset($filename) || trim($filename) ==
"")
896 throw new exception(
"Please select a file to remove.", 3);
897 if (!is_writable($uploadPath))
898 throw new exception(
"PDF Directory is not set up correctly. Please contact HomeCU for assistance.", 1);
899 foreach($allowedFiles as $gridType => $files)
901 foreach($files as $typeName => $typeFiles)
903 foreach($typeFiles as $fileName => $filePath)
905 if (trim($fileName) == trim($filename))
907 $thisFilePath= $filePath;
911 if (isset($thisFilePath))
916 if (!isset($thisFilePath))
917 throw new exception(
"File doesn't exist.", 4);
919 $fullPath=
"${uploadPath}${thisFilePath}";
920 if (!@is_readable($fullPath))
921 throw new exception(
"File doesn't exist.", 2);
923 $pdffile = fopen($fullPath,
"r");
924 $sArray=fstat($pdffile);
925 $size=$sArray[
"size"];
926 header(
"Content-Type: application/pdf");
927 header(
"Content-length: $size");
933 header(
'Content-type: application/json');
934 print HCU_JsonEncode( array(
"error" => $e->getMessage(),
"code" => $e->getCode()));