PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/concreteOLD/tools/files/import.php

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