frmupload.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2003-2010 Frederico Caldeira Knabben
  4. *
  5. * Source modified from part of fckeditor (http://www.fckeditor.net)
  6. * retrieved as GPL v2 or later
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. define('NOTOKENRENEWAL', 1); // Disables token renewal
  22. // Load Dolibarr environment
  23. require '../../../../main.inc.php';
  24. top_httphead();
  25. ?>
  26. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  27. <!--
  28. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  29. * Copyright (C) 2003-2010 Frederico Caldeira Knabben
  30. *
  31. * == BEGIN LICENSE ==
  32. *
  33. * Licensed under the terms of any of the following licenses at your
  34. * choice:
  35. *
  36. * - GNU General Public License Version 2 or later (the "GPL")
  37. * https://www.gnu.org/licenses/gpl.html
  38. *
  39. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  40. * https://www.gnu.org/licenses/lgpl.html
  41. *
  42. * - Mozilla Public License Version 1.1 or later (the "MPL")
  43. * http://www.mozilla.org/MPL/MPL-1.1.html
  44. *
  45. * == END LICENSE ==
  46. *
  47. * Page used to upload new files in the current folder.
  48. -->
  49. <html>
  50. <head>
  51. <title>File Upload</title>
  52. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  53. <?php
  54. print '<!-- Includes CSS for Dolibarr theme -->'."\n";
  55. // Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
  56. $themepath = dol_buildpath($conf->css, 1);
  57. $themesubdir = '';
  58. if (!empty($conf->modules_parts['theme'])) { // This slow down
  59. foreach ($conf->modules_parts['theme'] as $reldir) {
  60. if (file_exists(dol_buildpath($reldir.$conf->css, 0))) {
  61. $themepath = dol_buildpath($reldir.$conf->css, 1);
  62. $themesubdir = $reldir;
  63. break;
  64. }
  65. }
  66. }
  67. //print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
  68. print '<link rel="stylesheet" type="text/css" href="'.$themepath.'">'."\n";
  69. ?>
  70. <link href="browser.css" type="text/css" rel="stylesheet" >
  71. <script type="text/javascript" src="js/common.js"></script>
  72. <script type="text/javascript">
  73. function SetCurrentFolder( resourceType, folderPath )
  74. {
  75. var sUrl = oConnector.ConnectorUrl + 'Command=FileUpload' ;
  76. sUrl += '&Type=' + resourceType ;
  77. sUrl += '&CurrentFolder=' + encodeURIComponent( folderPath );
  78. document.getElementById('frmUpload').action = sUrl ;
  79. }
  80. function OnSubmit()
  81. {
  82. console.log("Click on OnSubmit");
  83. if ( document.getElementById('NewFile').value.length == 0 )
  84. {
  85. alert( 'Please select a file from your computer' );
  86. return false ;
  87. }
  88. // Set the interface elements.
  89. document.getElementById('eUploadMessage').innerHTML = 'Upload a new file in this folder (Upload in progress, please wait...)' ;
  90. document.getElementById('btnUpload').disabled = true ;
  91. return true ;
  92. }
  93. function OnUploadCompleted( errorNumber, data )
  94. {
  95. console.log("errorNumber = "+errorNumber);
  96. // Reset the Upload Worker Frame.
  97. window.parent.frames['frmUploadWorker'].location = 'javascript:void(0)' ;
  98. // Reset the upload form (On IE we must do a little trick to avoid problems).
  99. if ( document.all )
  100. document.getElementById('NewFile').outerHTML = '<input id="NewFile" name="NewFile" style="WIDTH: 100%" type="file">' ;
  101. else
  102. document.getElementById('frmUpload').reset();
  103. // Reset the interface elements.
  104. document.getElementById('eUploadMessage').innerHTML = 'Upload a new file in this folder' ;
  105. document.getElementById('btnUpload').disabled = false ;
  106. switch ( errorNumber )
  107. {
  108. case 0:
  109. window.parent.frames['frmResourcesList'].Refresh();
  110. break;
  111. case 1: // Custom error.
  112. alert( data );
  113. break;
  114. case 201:
  115. window.parent.frames['frmResourcesList'].Refresh();
  116. alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + data + '"' );
  117. break;
  118. case 202:
  119. alert( 'Invalid file (Bad extension)' );
  120. break;
  121. default:
  122. alert( 'Error on file upload. Error number: ' + errorNumber );
  123. break;
  124. }
  125. }
  126. window.onload = function()
  127. {
  128. window.top.IsLoadedUpload = true ;
  129. }
  130. </script>
  131. </head>
  132. <body>
  133. <form id="frmUpload" action="" target="frmUploadWorker" method="post" enctype="multipart/form-data" onsubmit="return OnSubmit();">
  134. <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
  135. <table class="fullHeight" cellspacing="0" cellpadding="0" width="100%" border="0">
  136. <tr>
  137. <td class="nowrap valignmiddle">
  138. <table width="100%" class="inline-block valignmiddle">
  139. <tr>
  140. <td><input id="NewFile" name="NewFile" type="file"></td>
  141. <td class="nowrap">&nbsp;<input id="btnUpload" type="submit" value="Upload" class="flat button"></td>
  142. </tr>
  143. </table>
  144. <!-- Section for upload result message -->
  145. <span id="eUploadMessage"></span><br>
  146. </td>
  147. </tr>
  148. </table>
  149. </form>
  150. </body>
  151. </html>