source: branches/2.2/filemanager/js/common_functions.js @ 3879

Revision 3879, 12.3 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1648 - Correcao( codigo ) e melhoria( laytou/informacao ) no upload de arquivos para o servidor.

Line 
1
2var Xtools      = null;
3
4function load(path,el)
5{
6        currentPath = path;
7        contentFolders = document.getElementById('content_folders');
8        for (i=0; i < contentFolders.childNodes.length; i++)
9                if (contentFolders.childNodes[i].className == "sl")
10                        contentFolders.childNodes[i].className = "l";
11        el.className = "sl";
12        current_folder = currentPath;
13        if(last_folder != current_folder){
14                lastPage = 1;
15                current_page = 1;
16                last_folder = current_folder;
17                offset = 0;
18        }
19        toolbar.control('reload');
20}
21
22function loadXtools()
23{
24        if( Xtools == null )
25                Xtools = new xtools( path_filemanager + "tp/expressowindow/" );
26}
27
28function check(element)
29{
30        element.firstChild.firstChild.checked = true;
31}
32
33function validateFileExtension(fileName)
34{
35        var error_flag = false;
36        var fileExtension = fileName.split(".");
37        fileExtension = fileExtension[(fileExtension.length-1)];
38        for(var i=0; i<denyFileExtensions.length; i++)
39        {
40                if(denyFileExtensions[i] == fileExtension)
41                {
42                        error_flag = true;
43                        break;
44                }
45
46        }
47
48        if ( error_flag == true )
49        {
50                write_error(get_lang('File extension forbidden or invalid file') + '.');
51                return false;
52        }
53        return true;
54}
55
56function get_lang(_key)
57{
58        var key = _key.toLowerCase();
59        if(array_lang[key])
60                var _value = array_lang[key];
61        else
62                var _value = _key+"*";
63
64        if(arguments.length > 1)
65                for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
66                        _value = _value.replace("%"+j,arguments[j]);
67        return _value;
68
69}
70
71
72function newEmptyFile()
73{
74        var name = prompt(get_lang('Enter with the name of new file/directory'), '');
75        var input_text = document.getElementById('newfile_or_dir');
76        if (name != null && name != '' && validateFileExtension(name))
77        {
78                var fileExtension = name.split(".");
79                fileExtension = fileExtension[1];
80                if (typeof(fileExtension) == 'undefined')
81                        input_text.value = name+".html";
82                else
83                        input_text.value = name;
84                address = document.location.toString();
85                address = address.split("&");
86                document.location = address[0]+"&newfile.x=1&newfile_or_dir="+input_text.value;
87
88        }
89}
90
91function newUpload( )
92{
93        if( document.getElementById("dwindownewUpload__parent") == null )
94        {
95                var _newUpload = function(data)
96                {
97                        loadXtools();
98                       
99                        var pArgs = unserialize(data);
100                                pArgs.lang_click_here   = get_lang("Click here");
101                                pArgs.lang_more_files   = get_lang("More files");
102                                pArgs.lang_send_email   = get_lang("Send email");
103                                pArgs.height                    = 210;
104                                pArgs.path_filemanager  = path_filemanager;
105                                pArgs.width                     = 500;
106               
107                        var _html = Xtools.parse( Xtools.xml("upload_files"), "upload.xsl", pArgs );
108                       
109                        draw_window( _html, 490, 350, get_lang("upload files"), "newUpload" );
110               
111                        if( pArgs.emails_to != null )
112                                sendNotification( pArgs.emails_to );
113                }
114               
115                address = document.location.toString();
116                address = address.split("?");
117                var url = address[0]+"?menuaction=filemanager.uifilemanager.showUploadboxes&path="+base64_encode(currentPath);
118                cExecute_( url, _newUpload );
119        }
120}
121
122function newAdvancedUpload()
123{
124        for ( var i = 0 ; i < navigator.plugins.length; i++ )
125        {
126                if ( navigator.plugins[i].name.match('Java') || navigator.plugins[i].name.match('libnpjp2') )
127                {
128                        _winBuild( "dwindownewUpload" , "remove" );
129
130                        loadXtools();
131                       
132                        var pArgs =
133                        {
134                                'iframe_width'          : 515,
135                                'iframe_height'         : 320,
136                                'iframe_src'            : path_filemanager + "inc/uploadApp.php?id="+parseInt(Math.random()*Math.pow(10,15))
137                        };
138                       
139                        var _html = Xtools.parse( Xtools.xml("upload_files_advanced"), "uploadAdvanced.xsl", pArgs);
140                       
141                        draw_window( _html, 530, 345, get_lang("Advanced Upload") );
142                       
143                        return;
144                }
145        }
146       
147        alert( get_lang("You do not have Java installed, plugin not loaded") + "!" );
148}
149
150
151(function( )
152{
153        // TODO: use DES, RSA, PGP, or something strong
154        var sec_key = null;
155        function encode( data )
156        {
157                if (data == null)
158                        return null;
159                ret = "";
160                for ( var i=0;(i < data.length && data.charCodeAt(i) > 31); i++ )
161                {
162                        ret += String.fromCharCode(data.charCodeAt(i) ^ sec_key.charCodeAt(i));
163                }
164                return ret;
165        }
166
167        function crypt( input )
168        {
169                sec_key = input;
170        }
171
172        crypt.prototype.encode = encode;
173        window.crypt = crypt;
174})( );
175
176/*
177 * base64.js - Base64 encoding and decoding functions
178 *
179 * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
180 * Released under the MIT license
181 */
182
183function base64_encode(str) {
184        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
185        var encoded = [];
186        var c = 0;
187        try { var slen = str.length; } catch (e) { write_error(get_lang('you do not have access to %1',currentPath)); return; };
188        while (c < slen) {
189                var b0 = str.charCodeAt(c++);
190                var b1 = str.charCodeAt(c++);
191                var b2 = str.charCodeAt(c++);
192                var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
193                var i0 = (buf & (63 << 18)) >> 18;
194                var i1 = (buf & (63 << 12)) >> 12;
195                var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
196                var i3 = isNaN(b2) ? 64 : (buf & 63);
197                encoded[encoded.length] = chars.charAt(i0);
198                encoded[encoded.length] = chars.charAt(i1);
199                encoded[encoded.length] = chars.charAt(i2);
200                encoded[encoded.length] = chars.charAt(i3);
201        }
202        var retBuff = escape(encoded.join(''));
203        return retBuff.replace(/\+/g,"%2B");
204}
205
206function base64_decode(str) {
207        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
208        var invalid = {
209        strlen: (str.length % 4 != 0),
210        chars:  new RegExp('[^' + chars + ']').test(str),
211        equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
212        };
213        if (invalid.strlen || invalid.chars || invalid.equals)
214                throw new Error('Invalid base64 data');
215        var decoded = [];
216        var c = 0;
217        while (c < str.length) {
218                var i0 = chars.indexOf(str.charAt(c++));
219                var i1 = chars.indexOf(str.charAt(c++));
220                var i2 = chars.indexOf(str.charAt(c++));
221                var i3 = chars.indexOf(str.charAt(c++));
222                var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
223                var b0 = (buf & (255 << 16)) >> 16;
224                var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
225                var b2 = (i3 == 64) ? -1 : (buf & 255);
226                decoded[decoded.length] = String.fromCharCode(b0);
227                if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
228                if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
229        }
230        return decoded.join('');
231}
232
233
234function setRestricted(name)
235{
236        var continue_set = confirm(get_lang('This property will change the visibility of all users that have access to this file, continue?'));
237       
238        if ( continue_set )
239        {
240                cExecute_('./index.php?menuaction=filemanager.vfs_functions.setRestricted&file='
241                                + base64_encode(name)+'&path='+base64_encode(currentPath),handler.restricted);
242        }
243}
244
245function presetComments(el)
246{
247        if (permissions['edit'] == 0){
248                el.blur();
249                write_error(get_lang('You have no permission to access this file'));
250        }
251        oldValue = el.value;
252}
253
254function setComments(el)
255{
256        if ( el.value == oldValue )
257                return;
258       
259        var filename = base64_encode(el.id);
260       
261        cExecute_('./index.php?menuaction=filemanager.vfs_functions.editComment&file='
262                                + filename+'&comment='+base64_encode(el.value), handler.updateComment);
263}
264
265function enterComments(e,el)
266{
267        if ( e.keyCode == KEY_ENTER )
268        {
269                el.blur();
270        }
271}
272
273function EditColumns( args )
274{
275        if( args == 'close' )
276        {
277                _winBuild("window_tools_view","remove");
278        }
279        else if( args == 'save')
280        {
281                var checkBoxes = document.getElementById('menu_col_pref').getElementsByTagName("input");
282
283                for ( var i = 0 ; i < checkBoxes.length; i++)
284                {
285                        if( checkBoxes[i].checked === true )
286                                preferences[checkBoxes[i].value] = '1';
287                        else
288                                preferences[checkBoxes[i].value] = '0';
289                }
290
291                cExecute_('./index.php?menuaction=filemanager.user.save_preferences',function () { toolbar.control('reload'); EditColumns('close'); }, 'preferences='+serialize(preferences));
292        }
293        else
294        {
295                loadXtools();
296               
297                var pTools =
298                {
299                        'checkList'     :       preferences['viewList'],       
300                        'checkIcons':   preferences['viewIcons'],
301                        'check_created'                 : preferences['created'],
302                        'check_createdby_id'    : preferences['createdby_id'],
303                        'check_comment'                 : preferences['comment'],
304                        'check_mime_type'               : preferences['mime_type'],
305                        'check_modified'                : preferences['modified'],
306                        'check_modifiedby_id'   : preferences['modifiedby_id'],
307                        'check_owner'                   : preferences['owner'],
308                        'check_size'                    : preferences['size'],
309                        'check_version'                 : preferences['version'],
310                        'lang_cancel'                   : get_lang('cancel'),
311                        'lang_created_by'               : get_lang('created by'),                       
312                        'lang_created'                  : get_lang('created'),
313                        'lang_comment'                  : get_lang('comment'),
314                        'lang_modified_by'              : get_lang('modified by'),
315                        'lang_modified'                 : get_lang('modified'),
316                        'lang_owner'                    : get_lang('owner'),
317                        'lang_save'                             : get_lang('save'),
318                        'lang_size'                             : get_lang('size'),
319                        'lang_type'                             : get_lang('type'),
320                        'lang_version'                  : get_lang('version'),
321                        'lang_view_as_list'             : get_lang('view as list'),
322                        'lang_view_as_icons'    : get_lang('view as icons'),
323                        'onclickCancel'                 : "EditColumns(\'close\')",
324                        'onclickSave'                   : "EditColumns(\'save\')"
325                }
326               
327                var winTools =
328                {       
329                         id_window              : "window_tools_view",
330                         width                  : 250,
331                         height                 : 290,
332                         top                            : 100,
333                         left                           : 400,
334                         draggable              : true,
335                         visible                        : "display",
336                         resizable              : true,
337                         zindex                 : zIndex++,
338                         title                  : "Expresso FileManager - " + get_lang('View'),
339                         closeAction            : "remove",
340                         content                : Xtools.parse(Xtools.xml("view_config"), "view.xsl", pTools)   
341                };
342       
343                _winBuild( winTools );
344        }
345}
346
347
348function searchFile(){
349        var inputText = document.getElementById('em_message_search');
350        if (inputText.value.length < 4)
351        {
352                alert(get_lang('Your search must have at least 4 characters'));
353                return;
354        }
355        cExecute_('./index.php?menuaction=filemanager.uifilemanager.search&text='+inputText.value,folderList.drawSearch);
356}
357function selectAll(el){
358        checkBoxes = document.getElementsByName('fileman');
359        if (el.checked)
360                for (i=0; i < checkBoxes.length; i++)
361                        checkBoxes[i].checked = true;
362        else
363                for (i=0; i < checkBoxes.length; i++)
364                        checkBoxes[i].checked = false;
365
366}
367
368function borkb(size)
369{
370        var kbyte = 1024;
371        var mbyte = kbyte*1024;
372        var gbyte = mbyte*1024;
373       
374        if (!size)
375        {
376                size = 0;
377        }
378
379        if (size < kbyte)
380        {
381                return size + ' B';
382        }
383        else if (size < mbyte)
384        {
385                return parseInt(size/kbyte) + ' KB';
386        }
387        else if (size < gbyte)
388        {
389                if ( size/mbyte > 100)
390                        return (size/mbyte).toFixed(0) + ' MB';
391                else
392                        return (size/mbyte).toFixed(1) + ' MB';
393        }
394        else
395        {
396                return (size/gbyte).toFixed(1) + ' GB';
397        }
398}
399
400function addNewInput()
401{
402        var newElement = document.createElement('div');
403                newElement.innerHTML  = '<div></div>' +
404                                                                        '<input maxlength="255" name="upload_file[]" type="file" style="margin-right:5px;" />' +
405                                                                        '<input name="upload_comment[]" type="text" style="margin-right:2px;" />' +
406                                                                        '<span style="color:red; cursor:pointer;" onclick="removeInput(this);">'+get_lang('delete')+'</span>';
407       
408        document.getElementById('uploadOption').parentNode.appendChild(newElement);
409}
410
411function removeInput()
412{
413        if( arguments.length > 0 )
414        {
415                var _parent = arguments[0].parentNode;
416               
417                _parent.parentNode.removeChild(_parent);
418        }
419}
420
421function sendNotification()
422{
423        var _div = document.getElementById('sendNotifcation');
424       
425        var _SendNotification = function()
426        {
427                var pArgs =
428                {
429                        'lang_delete'                                           : get_lang('delete'),
430                        'lang_send_notification_email_to'       : get_lang("Send Notification email to:"),
431                        'value_email'                                           : ( ( arguments.length > 0 ) ? arguments[0] : "" )
432                };
433
434                loadXtools();
435               
436                _div.innerHTML += Xtools.parse( Xtools.xml("send_notification"), "send_notification.xsl", pArgs);
437        }
438       
439        if( arguments.length > 0 )
440        {
441                var emailsTo = arguments[0].split(",");
442               
443                _div.innerHTML += "<div style='margin:4 2 2 4px;'>" +
444                                              "<label style='font-weight: bold;'>" + get_lang('The following addresses will be notified') + " : </label>" +
445                                              "</div>";
446                for( var i = 0 ;  i < emailsTo.length ; i++ )
447                {
448                        _SendNotification( emailsTo[i] );
449                        _div.innerHTML += "<div style='margin:1 2 1 4px;'> - " + emailsTo[i] + "</div>";
450                }
451                _div.innerHTML += "<br/>";
452        }
453        else
454                _SendNotification();
455}
456
457function sendFiles()
458{
459        var _formUp                     = document.getElementById('form_up');
460        var _uploadFiles                = document.getElementsByTagName('input');
461        var _flagSend           = true;
462       
463        for( var i = 0 ; i < _uploadFiles.length ; i++ )
464        {
465                if( _uploadFiles[i].name.indexOf("upload_file") > -1 )
466                {
467                        if( _uploadFiles[i].value == "" )
468                        {
469                                removeInput( _uploadFiles[i] );
470                                _flagSend = false;
471                        }
472                }
473        }
474       
475        if( _flagSend )
476                cExecuteForm_( _formUp , handler.upload );
477        else
478                write_msg(get_lang("No file(s) to send") + "!");
479}
Note: See TracBrowser for help on using the repository browser.