PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/concrete/tools/files/import.php

https://github.com/rii-J/concrete5-de
PHP | 281 lines | 233 code | 42 blank | 6 comment | 13 complexity | 12b54ef7ee4fdc441aa4cd3aca3eacd0 MD5 | raw file
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. $u = new User();
  4. $ch = Loader::helper('concrete/file');
  5. $h = Loader::helper('concrete/interface');
  6. $form = Loader::helper('form');
  7. $fp = FilePermissions::getGlobal();
  8. if (!$fp->canAddFiles()) {
  9. die(t("Unable to add files."));
  10. }
  11. $types = $fp->getAllowedFileExtensions();
  12. $searchInstance = $_REQUEST['searchInstance'];
  13. $ocID = $_REQUEST['ocID'];
  14. $types = $ch->serializeUploadFileExtensions($types);
  15. $valt = Loader::helper('validation/token');
  16. ?>
  17. <ul class="ccm-dialog-tabs" id="ccm-file-import-tabs">
  18. <li class="ccm-nav-active"><a href="javascript:void(0)" id="ccm-file-upload-multiple"><?php echo t('Upload Multiple')?></a></li>
  19. <li><a href="javascript:void(0)" id="ccm-file-add-incoming"><?php echo t('Add Incoming')?></a></li>
  20. <li><a href="javascript:void(0)" id="ccm-file-add-remote"><?php echo t('Add Remote Files')?></a></li>
  21. </ul>
  22. <script type="text/javascript" src="<?php echo ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.js"></script>
  23. <script type="text/javascript" src="<?php echo ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.handlers.js"></script>
  24. <script type="text/javascript" src="<?php echo ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.fileprogress.js"></script>
  25. <script type="text/javascript" src="<?php echo ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.queue.js"></script>
  26. <script type="text/javascript">
  27. var ccm_fiActiveTab = "ccm-file-upload-multiple";
  28. $("#ccm-file-import-tabs a").click(function() {
  29. $("li.ccm-nav-active").removeClass('ccm-nav-active');
  30. $("#" + ccm_fiActiveTab + "-tab").hide();
  31. ccm_fiActiveTab = $(this).attr('id');
  32. $(this).parent().addClass("ccm-nav-active");
  33. $("#" + ccm_fiActiveTab + "-tab").show();
  34. });
  35. </script>
  36. <div id="ccm-file-upload-multiple-tab">
  37. <h1><?php echo t('Upload Multiple Files')?></h1>
  38. <?php
  39. $umf = ini_get('upload_max_filesize');
  40. $umf = str_ireplace(array('M', 'K', 'G'), array(' MB', 'KB', ' GB'), $umf);
  41. ?>
  42. <script type="text/javascript">
  43. var swfu;
  44. $(function() {
  45. $("#ccm-file-manager-multiple-remote").submit(function() {
  46. $(this).attr('target', ccm_alProcessorTarget);
  47. });
  48. $("#ccm-file-manager-multiple-incoming").submit(function() {
  49. $(this).attr('target', ccm_alProcessorTarget);
  50. });
  51. swfu = new SWFUpload({
  52. flash_url : "<?php echo ASSETS_URL_FLASH?>/swfupload/swfupload.swf",
  53. upload_url : "<?php echo REL_DIR_FILES_TOOLS_REQUIRED?>/files/importers/multiple",
  54. post_params: {'ccm-session' : "<?php echo session_id(); ?>",'searchInstance': '<?php echo $searchInstance?>', 'ocID' : '<?php echo $ocID?>', 'ccm_token' : '<?php echo $valt->generate("upload")?>'},
  55. file_size_limit : "<?php echo $umf?>",
  56. file_types : "<?php echo $types?>",
  57. button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
  58. file_types_description : "<?php echo t('All Files') ?>",
  59. file_upload_limit : 100,
  60. button_cursor: SWFUpload.CURSOR.HAND,
  61. file_queue_limit : 0,
  62. custom_settings : {
  63. progressTarget : "ccm-file-upload-multiple-list",
  64. cancelButtonId : "ccm-file-upload-multiple-btnCancel"
  65. },
  66. debug: false,
  67. // Button settings
  68. button_image_url: "<?php echo ASSETS_URL_IMAGES?>/icons/add_file_swfupload.png", // Relative to the Flash file
  69. button_width: "80",
  70. button_text: '<span class="uploadButtonText"><?php echo t('Add Files')?><\/span>',
  71. button_height: "16",
  72. button_text_left_padding: 18,
  73. button_text_style: ".uploadButtonText {background-color: #eee; font-family: Helvetica Neue, Helvetica, Arial}",
  74. button_placeholder_id: "ccm-file-upload-multiple-spanButtonPlaceHolder",
  75. // The event handler functions are defined in handlers.js
  76. // wrapped function with apply are so c5 can do anything special it needs to
  77. // some functions needed to be overridden completly
  78. file_queued_handler : function (file) {
  79. fileQueued.apply(this,[file]);
  80. },
  81. file_queue_error_handler : fileQueueError,
  82. file_dialog_complete_handler : function(numFilesSelected, numFilesQueued){
  83. try {
  84. if (numFilesSelected > 0) {
  85. document.getElementById(this.customSettings.cancelButtonId).disabled = false;
  86. }
  87. //this.startUpload();
  88. } catch (ex) {
  89. this.debug(ex);
  90. }
  91. },
  92. upload_start_handler : uploadStart,
  93. upload_progress_handler : function(file, bytesLoaded, bytesTotal){
  94. try {
  95. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  96. var progress = new FileProgress(file, this.customSettings.progressTarget);
  97. progress.setProgress(percent);
  98. progress.setStatus("<?php echo t('Uploading...')?> ("+percent+"%)");
  99. } catch (ex) {
  100. this.debug(ex);
  101. }
  102. },
  103. upload_error_handler : uploadError,
  104. upload_success_handler : function(file, serverData){
  105. try {
  106. eval('serverData = '+serverData);
  107. var progress = new FileProgress(file, this.customSettings.progressTarget);
  108. if (serverData['error'] == true) {
  109. progress.setError(serverData['message']);
  110. } else {
  111. progress.setComplete();
  112. }
  113. progress.toggleCancel(false);
  114. if(serverData['id']){
  115. if(!this.highlight){this.highlight = [];}
  116. this.highlight.push(serverData['id']);
  117. if(ccm_uploadedFiles && serverData['id']!='undefined') ccm_uploadedFiles.push(serverData['id']);
  118. }
  119. } catch (ex) {
  120. this.debug(ex);
  121. }
  122. },
  123. upload_complete_handler : uploadComplete,
  124. queue_complete_handler : function(file){
  125. // queueComplete() from swfupload.handlers.js
  126. if (ccm_uploadedFiles.length > 0) {
  127. queueComplete();
  128. ccm_filesUploadedDialog('<?php echo $searchInstance?>');
  129. }
  130. }
  131. });
  132. });
  133. </script>
  134. <style type="text/css">
  135. </style>
  136. <form id="form1" action="<?php echo DISPATCHER_FILENAME?>" method="post" enctype="multipart/form-data">
  137. <table border="0" width="100%" cellspacing="0" cellpadding="0" id="ccm-file-upload-multiple-list">
  138. <tr>
  139. <th colspan="2"><div style="width: 80px; float: right"><span id="ccm-file-upload-multiple-spanButtonPlaceHolder"></span></div><?php echo t('Upload Queue');?></th>
  140. </tr>
  141. </table>
  142. <div class="ccm-spacer">&nbsp;</div><br/>
  143. <!--
  144. <div>
  145. <div id="ccm-file-upload-multiple-results-wrapper">
  146. <div style="width: 100px; float: right; text-align: right"></div>
  147. <div id="ccm-file-upload-multiple-results">0 <?php echo t('Files Uploaded');?></div>
  148. <div class="ccm-spacer">&nbsp;</div>
  149. </div>
  150. </div>
  151. <br style="clear:left;"/> //-->
  152. <div>
  153. <?php
  154. print $h->button_js(t('Start Uploads'), 'swfu.startUpload()');
  155. print $h->button_js(t('Cancel All Uploads'), 'swfu.cancelQueue()', 'left', null,array('id'=>'ccm-file-upload-multiple-btnCancel', 'disabled' => 1));
  156. ?>
  157. </div>
  158. </form>
  159. <div class="ccm-spacer">&nbsp;</div>
  160. <br/>
  161. <div class="ccm-note">
  162. <strong><?php echo t('Upload Max File Size: %s', ini_get('upload_max_filesize'))?></strong><br/>
  163. <strong><?php echo t('Post Max Size: %s', ini_get('post_max_size'))?></strong><br/>
  164. </div>
  165. </div>
  166. <?php
  167. $valt = Loader::helper('validation/token');
  168. $fh = Loader::helper('validation/file');
  169. Loader::library('file/types');
  170. $incoming_contents = $ch->getIncomingDirectoryContents();
  171. ?>
  172. <div id="ccm-file-add-incoming-tab" style="display: none">
  173. <h1><?php echo t('Add from Incoming Directory')?></h1>
  174. <?php if(!empty($incoming_contents)) { ?>
  175. <form id="ccm-file-manager-multiple-incoming" method="post" action="<?php echo REL_DIR_FILES_TOOLS_REQUIRED?>/files/importers/incoming">
  176. <input type="hidden" name="searchInstance" value="<?php echo $searchInstance?>" />
  177. <input type="hidden" name="ocID" value="<?php echo $ocID?>" />
  178. <table id="incoming_file_table" width="100%" cellpadding="0" cellspacing="0">
  179. <tr>
  180. <td width="10%" valign="middle" class="center theader"><input type="checkbox" id="check_all_imports" name="check_all_imports" onclick="ccm_alSelectMultipleIncomingFiles(this);" value="" /></td>
  181. <td width="20%" valign="middle" class="center theader"></td>
  182. <td width="45%" valign="middle" class="theader"><?php echo t('Filename')?></td>
  183. <td width="25%" valign="middle" class="center theader"><?php echo t('Size')?></td>
  184. </tr>
  185. </table>
  186. <div id="incoming_files" class="incoming_file_importer">
  187. <table id="incoming_file_table" width="100%">
  188. <?php foreach($incoming_contents as $filenum=>$file_array) {
  189. $ft = FileTypeList::getType($file_array['name']);
  190. ?>
  191. <tr>
  192. <td width="10%" valign="middle" class="center">
  193. <?php if($fh->extension($file_array['name'])) { ?>
  194. <input type="checkbox" name="send_file<?php echo $filenum?>" class="ccm-file-select-incoming" value="<?php echo $file_array['name']?>" />
  195. <?php } ?>
  196. </td>
  197. <td width="20%" valign="middle" class="center"><?php echo $ft->getThumbnail(1)?></td>
  198. <td width="45%" valign="middle"><?php echo $file_array['name']?></td>
  199. <td width="25%" valign="middle" class="center"><?php echo $file_array['size']?><?php echo t('Kb')?></div>
  200. </tr>
  201. <?php } ?>
  202. <tr>
  203. <td style="text-align: center"><input type="checkbox" name="removeFilesAfterPost" value="1" /></td>
  204. <td colspan="2">
  205. <?php echo t('Remove files from incoming/ directory.')?></td>
  206. <td>
  207. <?php
  208. print $form->submit('submit', t('Add Files'));
  209. ?>
  210. </td>
  211. </tr>
  212. </table>
  213. <div class="clear"></div>
  214. </div>
  215. <?php echo $valt->output('import_incoming');?>
  216. <div style="clear: both">&nbsp;</div>
  217. </form>
  218. <?php } else { ?>
  219. <?php echo t('No files found in %s', DIR_FILES_INCOMING)?>
  220. <?php } ?>
  221. </div>
  222. <div id="ccm-file-add-remote-tab" style="display: none">
  223. <h1><?php echo t('Add From Remote URL')?></h1>
  224. <form method="POST" id="ccm-file-manager-multiple-remote" action="<?php echo REL_DIR_FILES_TOOLS_REQUIRED?>/files/importers/remote">
  225. <input type="hidden" name="searchInstance" value="<?php echo $searchInstance?>" />
  226. <input type="hidden" name="ocID" value="<?php echo $ocID?>" />
  227. <h3><?php echo t('Enter URL to valid file(s)')?></h3>
  228. <?php echo $valt->output('import_remote');?>
  229. <?php echo $form->text('url_upload_1', array('style' => 'width:90%'))?><br/>
  230. <?php echo $form->text('url_upload_2', array('style' => 'width:90%'))?><br/>
  231. <?php echo $form->text('url_upload_3', array('style' => 'width:90%'))?><br/>
  232. <?php echo $form->text('url_upload_4', array('style' => 'width:90%'))?><br/>
  233. <?php echo $form->text('url_upload_5', array('style' => 'width:90%'))?><br/>
  234. <br/>
  235. <?php
  236. print $form->submit('submit', t('Add Files'));
  237. ?>
  238. </form>
  239. </div>