dolibarr  7.0.0-beta
frmresourceslist.php
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  * retreived 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 <http://www.gnu.org/licenses/>.
20  */
21 
22 define('NOTOKENRENEWAL',1); // Disables token renewal
23 
24 require '../../../../main.inc.php';
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  * http://www.gnu.org/licenses/gpl.html
38  *
39  * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
40  * http://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  * This page shows all resources available in a folder in the File Browser.
48 -->
49 <html>
50 <head>
51  <title>Resources</title>
52  <link href="browser.css" type="text/css" rel="stylesheet">
53  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
54  <script type="text/javascript" src="js/common.js"></script>
55  <script type="text/javascript">
56 
57 var oListManager = new Object();
58 
59 oListManager.Clear = function()
60 {
61  document.body.innerHTML = '' ;
62 }
63 
64 function ProtectPath(path)
65 {
66  path = path.replace( /\\/g, '\\\\');
67  path = path.replace( /'/g, '\\\'');
68  return path ;
69 }
70 
71 oListManager.GetFolderRowHtml = function( folderName, folderPath )
72 {
73  // Build the link to view the folder.
74  var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath(folderPath) + '\');return false;">' ;
75 
76  return '<tr>' +
77  '<td width="16">' +
78  sLink +
79  '<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>' +
80  '<\/td><td class="nowrap" colspan="2">&nbsp;' +
81  sLink +
82  folderName +
83  '<\/a>' +
84  '<\/td><\/tr>' ;
85 }
86 
87 // Note: fileUrl must be already "URL encoded"
88 oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
89 {
90  // Build the link to view the folder.
91  var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;">' ;
92 
93  // Get the file icon.
94  var sIcon = oIcons.GetIcon( fileName );
95 
96  return '<tr>' +
97  '<td width="16">' +
98  sLink +
99  '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +
100  '<\/td><td>&nbsp;' +
101  sLink +
102  fileName +
103  '<\/a>' +
104  '<\/td><td align="right" class="nowrap">&nbsp;' +
105  fileSize +
106  ' KB' +
107  '<\/td><\/tr>' ;
108 }
109 
110 function OpenFolder( folderPath )
111 {
112  // Load the resources list for this folder.
113  window.parent.frames['frmFolders'].LoadFolders( folderPath );
114 }
115 
116 function GetUrlParam( paramName )
117 {
118  var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' );
119  var oMatch = oRegex.exec( window.top.location.search );
120 
121  if ( oMatch && oMatch.length > 1 )
122  return decodeURIComponent( oMatch[1] );
123  else
124  return '' ;
125 }
126 
127 // Note fileUrl must be already "URL encoded"
128 function OpenFile( fileUrl )
129 {
130  funcNum = GetUrlParam('CKEditorFuncNum');
131  //window.top.opener.CKEDITOR.tools.callFunction(funcNum, encodeURI( fileUrl ).replace( '#', '%23' ));
132  window.top.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl.replace( '#', '%23' ));
133 
135  window.top.close();
136  window.top.opener.focus();
137 }
138 
139 function LoadResources( resourceType, folderPath )
140 {
141  oListManager.Clear();
142  oConnector.ResourceType = resourceType ;
143  oConnector.CurrentFolder = folderPath ;
144  oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack );
145 }
146 
147 function Refresh()
148 {
149  LoadResources( oConnector.ResourceType, oConnector.CurrentFolder );
150 }
151 
152 function GetFoldersAndFilesCallBack( fckXml )
153 {
154  if ( oConnector.CheckError( fckXml ) != 0 )
155  return ;
156 
157  // Get the current folder path.
158  var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' );
159  if ( oFolderNode == null )
160  {
161  alert( 'The server didn\'t reply with a proper XML data. Please check your configuration.' );
162  return ;
163  }
164  var sCurrentFolderPath = oFolderNode.attributes.getNamedItem('path').value ;
165  var sCurrentFolderUrl = oFolderNode.attributes.getNamedItem('url').value ;
166 
167 // var dTimer = new Date();
168 
169  var oHtml = new StringBuilder( '<table id="tableFiles" cellspacing="1" cellpadding="0" width="100%" border="0">' );
170 
171  // Add the Folders.
172  var oNodes ;
173  oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' );
174  for ( var i = 0 ; i < oNodes.length ; i++ )
175  {
176  var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
177  oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) );
178  }
179 
180  // Add the Files.
181  oNodes = fckXml.SelectNodes( 'Connector/Files/File' );
182  for ( var j = 0 ; j < oNodes.length ; j++ )
183  {
184  var oNode = oNodes[j] ;
185  var sFileName = oNode.attributes.getNamedItem('name').value ;
186  var sFileSize = oNode.attributes.getNamedItem('size').value ;
187 
188  // Get the optional "url" attribute. If not available, build the url.
189  var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url');
190  var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : encodeURI( sCurrentFolderUrl + sFileName ).replace( /#/g, '%23' );
191 
192  oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) );
193  }
194 
195  oHtml.Append( '<\/table>' );
196 
197  document.body.innerHTML = oHtml.ToString();
198 
199 // window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;
200 
201 }
202 
203 window.onload = function()
204 {
205  window.top.IsLoadedResourcesList = true ;
206 }
207  </script>
208 </head>
209 <body class="FileArea">
210 </body>
211 </html>
type
Definition: viewcat.php:283