| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053 |
- function GetURLParameter(sParam)
- {
- var sPageURL = window.location.search.substring(1);
- var sURLVariables = sPageURL.split('&');
- for (var i = 0; i < sURLVariables.length; i++)
- {
- var sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] == sParam)
- {
- return sParameterName[1];
- }
- }
- }
- function checkSession() {
- var ret = true;
- var request = new XMLHttpRequest();
- request.open('GET', 'modules/litefm/SessionCheck.php', false);
- request.onload = function(e) {
- var session = JSON.parse(this.responseText);
- if(!session.valid) {
- alert("Your session has expired.");
- window.location = "index.php";
- ret = false;
- }
- }
- request.send(null);
- return ret;
- }
- function detectIE() {
- var ua = window.navigator.userAgent;
- var msie = ua.indexOf('MSIE ');
- var trident = ua.indexOf('Trident/');
- if (msie > 0) {
- // IE 10 or older => return version number
- return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
- }
- if (trident > 0) {
- // IE 11 (or newer) => return version number
- var rv = ua.indexOf('rv:');
- return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
- }
- // other browser
- return false;
- }
- var ie = detectIE();
- if (!Date.now) {
- Date.now = function() { return new Date().getTime(); }
- }
- function indexedDBOk() {
- return "indexedDB" in window;
- }
- function downloadFile(home_id, file_id, file_size, file_name)
- {
- if(checkSession() == false) { return; }
- var fileNode = document.getElementById('fileid'+file_id);
- var aLink = document.getElementById('jsDwl'+file_id);
- if (aLink.getAttribute('disabled') == 'disabled') {
- return;
- }
- aLink.setAttribute('disabled','disabled');
- var did = Date.now();
- var bytesDownloaded = 0;
- var progressbar = document.createElement('DIV');
- var progress = document.createElement('DIV');
- var percentage = document.createElement("SPAN");
- progressbar.setAttribute('id','progress_'+file_id);
- progressbar.setAttribute('style', 'background:white;'+
- 'height:4px;'+
- 'width:400px;'+
- 'border:1px solid black;'+
- 'position:absolute;'+
- 'z-index:2;');
- percentage.setAttribute('id','percentage_'+file_id);
- progressbar.appendChild(progress);
- fileNode.appendChild(progressbar);
- fileNode.appendChild(percentage);
- progressbar = document.getElementById('progress_'+file_id);
- progress = progressbar.firstChild;
- percentage = document.getElementById('percentage_'+file_id);
- var key = 1;
- var db;
- var memoryStore;
-
- function failure() {
- progressbar.parentNode.removeChild(progressbar);
- percentage.parentNode.removeChild(percentage);
- window.onbeforeunload = false;
- window.onunload = false;
- }
-
- function init() {
- if(ie)
- {
- if(ie >= 10)
- {
- memoryStore = [];
- getFilePart();
- }
- else
- {
- failure();
- alert('Your browser does not support this function.');
- return;
- }
- }
- else
- {
- if( !indexedDBOk() )
- {
- failure();
- alert('Your browser does not support this function.');
- return;
- }
-
- var openRequest = indexedDB.open(did,1);
-
- openRequest.onupgradeneeded = function(e) {
- var thisDB = e.target.result;
-
- if(!thisDB.objectStoreNames.contains("dl_parts")) {
- thisDB.createObjectStore("dl_parts");
- }
- }
-
- openRequest.onsuccess = function(e) {
- db = e.target.result;
- getFilePart();
- }
-
- openRequest.onerror = function(e) {
- failure();
- cleanUp();
- alert(e.target.error.name);
- return;
- }
- }
- }
- function addBuffer(arraybuffer, key) {
- if(ie)
- {
- // Store the blob in memory
- memoryStore.push(new Blob([arraybuffer]));
- }
- else
- {
- // Store the blob in indexedDB
- var transaction = db.transaction(["dl_parts"],"readwrite");
- var store = transaction.objectStore("dl_parts");
- var request = store.add(new Blob([arraybuffer]), key);
- request.onerror = function(e) {
- failure();
- cleanUp();
- alert(e.target.error.name);
- return;
- }
- }
- }
- function getAllParts() {
- if(ie)
- {
- navigator.msSaveOrOpenBlob(new Blob(memoryStore), file_name);
- }
- else
- {
- var trans = db.transaction(["dl_parts"],"readonly");
- var store = trans.objectStore("dl_parts");
- var parts = [];
- trans.oncomplete = function(evt) {
- try
- {
- var fileUrl = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
- var a = document.createElement('a');
- a.href = fileUrl;
- a.target = '_blank';
- a.download = file_name || fileUrl;
- var evt=new MouseEvent('click', {'view':window,'bubbles':true,'cancelable':true});
- a.dispatchEvent(evt);
- // Otherwise Firefox fails starting the download.
- setTimeout(function() { window.URL.revokeObjectURL(a.href); }, 1);
- parts = [];
- }
- catch(e)
- {
- console.log(e);
- }
- };
-
- var cursorRequest = store.openCursor();
-
- cursorRequest.onerror = function(error) {
- failure();
- cleanUp();
- alert(error);
- return;
- };
-
- cursorRequest.onsuccess = function(evt) {
- var cursor = evt.target.result;
- if (cursor) {
- parts.push(cursor.value);
- cursor.continue();
- }
- };
- }
- }
-
- function cleanUp() {
- if(ie)
- {
- memoryStore = [];
- }
- else
- {
- db.close();
- indexedDB.deleteDatabase(did);
- }
- var xhr = new XMLHttpRequest();
- xhr.open('POST', "home.php?m=litefm&home_id="+home_id+"&p=get&remove_did="+did+"&type=cleared", false);
- xhr.send(null);
- window.onunload = false;
- }
-
- function getFilePart()
- {
- var xhr = new XMLHttpRequest();
- xhr.open('POST', "home.php?m=litefm&home_id="+home_id+"&item="+file_id+"&name="+file_name+"&p=get&type=cleared&size="+file_size+"&did="+did, true);
- xhr.responseType = 'arraybuffer';
- xhr.onload = function(e) {
- if(this.response.byteLength != 0)
- {
- var lapTime = Date.now() - did; // milliseconds from download start
- // Uncompress and calculate the statistics.
- var compressed = new Uint8Array(this.response);
- var inflate = new Zlib.Inflate(compressed);
- var plain = inflate.decompress();
- bytesDownloaded += plain.byteLength;
- var multiplier = 1000 / lapTime;
- var MBs = (bytesDownloaded / 1000000) * multiplier;
- var value = bytesDownloaded * 100 / file_size;
- progress.setAttribute('style', 'background:blue;'+
- 'height:4px;'+
- 'width:'+value+'%;');
- percentage.innerHTML = " "+(Math.round(value * 100) / 100)+"% - "+MBs.toFixed(2)+"MB/s";
- addBuffer(plain, key++);
- // Get the next part
- getFilePart();
- }
- else
- {
- getAllParts();
- // Otherwise Firefox fails starting the download.
- setTimeout(function() { cleanUp(); }, 60000);
- // element.remove(); fails on IE
- progressbar.parentNode.removeChild(progressbar);
- percentage.parentNode.removeChild(percentage);
- aLink.removeAttribute('disabled');
- window.onbeforeunload = false;
- }
- };
- xhr.send(null);
- }
-
- window.onbeforeunload = function(){
- return 'A file download is in progress';
- };
-
- window.onunload = function(){
- cleanUp();
- }
-
- init();
- }
- $(document).ready(function(){
- /* translation & info */
- var select_at_least_one_item = $('#dialog').attr('data-select_at_least_one_item'),
- ask_delete = $('#dialog').attr('data-ask_delete'),
- ask_rename = $('#dialog').attr('data-ask_rename'),
- ask_move = $('#dialog').attr('data-ask_move'),
- ask_copy = $('#dialog').attr('data-ask_copy'),
- ask_compress = $('#dialog').attr('data-ask_compress'),
- ask_uncompress = $('#dialog').attr('data-ask_uncompress'),
- archive_name = $('#dialog').attr('data-archive_name'),
- archive_type = $('#dialog').attr('data-archive_type'),
- file_name = $('#dialog').attr('data-file_name'),
- folder_name = $('#dialog').attr('data-folder_name'),
- compresses_files_separately = $('#dialog').attr('data-compresses_files_separately'),
- to = $('#dialog').attr('data-to'),
- yes = $('#dialog').attr('data-yes'),
- no = $('#dialog').attr('data-no'),
- max_file_uploads = $('#dialog').attr('data-max_file_uploads'),
- upload_to_web = $('#dialog').attr('data-upload_to_web'),
- transfer_to_server = $('#dialog').attr('data-transfer_to_server'),
- upload = $('#dialog').attr('data-upload'),
- ask_change_attr = $('#dialog').attr('data-ask_change_attr'),
- ask_send_by_email = $('#dialog').attr('data-ask_send_by_email'),
- subject = $('#dialog').attr('data-subject'),
- message = $('#dialog').attr('data-message'),
- dest_email = $('#dialog').attr('data-dest_email'),
- user_email = $('#dialog').attr('data-user_email');
- // Home id
- var home_id = GetURLParameter('home_id');
- // Browse folder (when using "move/uncompress")
- $('.folder').each(function(){
- $(this).click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost[ 'm' ] = 'user_games';
- addpost[ 'p' ] = 'browser';
- addpost[ 'home_id' ] = $('.levelup').attr('data-home-id');
- addpost[ 'item' ] = $(this).attr('data-item');
- addpost[ 'type' ] = 'cleared';
- $.ajax({
- type: "GET",
- url: "home.php",
- data: addpost,
- success: function(data){
- data = data.replace("user_games.js","litefm.js");
- $( "#browser" ).html(data);
- }
- });
- });
- });
- // Back to previous folder (when using "move/uncompress")
- $('.levelup').click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost[ 'm' ] = 'user_games';
- addpost[ 'p' ] = 'browser';
- addpost[ 'home_id' ] = $(this).attr('data-home-id');
- addpost[ 'back' ] = 'back';
- addpost[ 'type' ] = 'cleared';
- $.ajax({
- type: "GET",
- url: "home.php",
- data: addpost,
- success: function(data){
- data = data.replace("user_games.js","litefm.js");
- $( "#browser" ).html(data);
- }
- });
- });
- // Create new folder (when using "move/uncompress")
- $('#addfolder').click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost[ 'm' ] = 'user_games';
- addpost[ 'p' ] = 'browser';
- addpost[ 'home_id' ] = home_id;
- addpost[ 'create_folder' ] = 'create_folder';
- addpost[ 'folder_name' ] = $('input[name=dirname]').val();
- addpost[ 'type' ] = 'cleared';
- $.ajax({
- type: "GET",
- url: "home.php",
- data: addpost,
- success: function(data){
- data = data.replace("user_games.js","litefm.js");
- $( "#browser" ).html(data);
- }
- });
- });
- // Switch checkboxes
- $("#switch_check").click(function(){
- var checkBoxes = $('input[class="item"]');
- checkBoxes.prop("checked", !checkBoxes.prop("checked"));
- });
- // Remove
- $("#remove.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.remove = '';
- var item = '';
- var value = '';
- var items = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value');
- addpost.items.push(item);
- items += "<br>"+value;
- });
- if(items != '')
- {
- $('#dialog').html(ask_delete.replace("%s", ":"+items));
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- // Rename
- $("#rename.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.values = [];
- addpost.rename = '';
- var value = '';
- var items = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value').replace('"', """);
- addpost.items.push(item);
- items += "<br><input class='rename' type=text style='width:100%;' name='"+item+"' value=\""+value+"\">";
- });
- if(items != '')
- {
- $('#dialog').html(ask_rename+":"+items);
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- $('input[class="rename"]').each(function(){
- value = $(this).val();
- addpost.values.push(value);
- });
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- // Move
- $("#move.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.values = [];
- addpost.move = '';
- var value = '';
- var items = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value');
- addpost.items.push(item);
- items += "<br>"+value;
- });
- if(items != '')
- {
- var addpostb = {};
- addpostb[ 'm' ] = 'user_games';
- addpostb[ 'p' ] = 'browser';
- addpostb[ 'home_id' ] = home_id;
- addpostb[ 'folder' ] = $('#dialog').attr('data-folder');
- addpostb[ 'type' ] = 'cleared';
- $.ajax({
- type: "GET",
- url: "home.php",
- data: addpostb,
- async: false,
- success: function(data){
- data = data.replace("user_games.js","litefm.js");
- $('#dialog').html(ask_move+":"+items+"<br>"+to+":<br><div id='browser' >"+data+"</div>");
- }
- });
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.selected_path = $('#selected_path').text();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- // Copy
- $("#copy.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.values = [];
- addpost.copy = '';
- var value = '';
- var items = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value');
- addpost.items.push(item);
- items += "<br>"+value;
- });
- if(items != '')
- {
- var addpostb = {};
- addpostb[ 'm' ] = 'user_games';
- addpostb[ 'p' ] = 'browser';
- addpostb[ 'home_id' ] = home_id;
- addpostb[ 'folder' ] = $('#dialog').attr('data-folder');
- addpostb[ 'type' ] = 'cleared';
- $.ajax({
- type: "GET",
- url: "home.php",
- data: addpostb,
- async: false,
- success: function(data){
- data = data.replace("user_games.js","litefm.js");
- $('#dialog').html(ask_copy+":"+items+"<br>"+to+":<br><div id='browser' >"+data+"</div>");
- }
- });
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.selected_path = $('#selected_path').text();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- // Compress
- $("#compress.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.compress = '';
- var value = '';
- var items = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value');
- addpost.items.push(item);
- items += "<br>"+value;
- });
- if(items != '')
- {
- $('#dialog').html(ask_compress+":"+items+"<br>"+
- "<label for='archive_name'>"+archive_name+"</label>\n"+
- "<input name='archive_name' id='archive_name' type=text value='archive' ><br>\n"+
- "<label for='archive_type'>"+archive_type+"</label>\n"+
- "<select name='archive_type' id='archive_type' >\n"+
- "<option value='zip'>zip</option>\n"+
- "<option value='tbz'>tbz</option>\n"+
- "<option value='tgz'>tgz</option>\n"+
- "<option value='tar'>tar</option>\n"+
- "<option value='bz2'>bz2 ("+compresses_files_separately+")</option>\n"+
- "</select>");
-
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.archive_name = $('#archive_name').val();
- addpost.archive_type = $('#archive_type').val();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- // Uncompress
- $("#uncompress.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.values = [];
- addpost.uncompress = '';
- var value = '';
- var items = '';
- var ext = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value');
- ext = value.split('.').pop();
- if(ext.match(/^(tar|tgz|gz|Z|zip|bz2|tbz|lzma|xz|txz)$/i) != null)
- {
- addpost.items.push(item);
- items += "<br>"+value;
- }
- });
- if(items != '')
- {
- var addpostb = {};
- addpostb[ 'm' ] = 'user_games';
- addpostb[ 'p' ] = 'browser';
- addpostb[ 'home_id' ] = home_id;
- addpostb[ 'folder' ] = $('#dialog').attr('data-folder');
- addpostb[ 'type' ] = 'cleared';
- $.ajax({
- type: "GET",
- url: "home.php",
- data: addpostb,
- async: false,
- success: function(data){
- data = data.replace("user_games.js","litefm.js");
- $('#dialog').html(ask_uncompress+":"+items+"<br>"+to+":<br><div id='browser' >"+data+"</div>");
- }
- });
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.selected_path = $('#selected_path').text();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- // Create File
- $("#create_file.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.create_file = '';
- $('#dialog').html("<label for='file_name'>"+file_name+"</label>\n"+
- "<input id='file_name' type=text style='width:100%;' name='file_name' >");
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.file_name = $('input[id="file_name"]').val();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- });
- // Create Folder
- $("#create_folder.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.create_folder = '';
- $('#dialog').html("<label for='folder_name'>"+folder_name+"</label>\n"+
- "<input id='folder_name' type=text style='width:100%;' name='folder_name' >");
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.folder_name = $('input[id="folder_name"]').val();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- });
- // upload
- $("#upload.operations-button").click(function(){
- if(checkSession() == false) { return; }
- $('#dialog').html('<div class="uploadLiteFMStatus status"></div>\
- <form id="upload" action="home.php?m=litefm&home_id='+home_id+'&type=cleared&data_type=json" method="post" enctype="multipart/form-data">\
- <input type="file" name="files[]" multiple="multiple" id="files">\
- <input type="submit" name="upload" id="uploadsubmit" value="'+upload+'" >\
- </form>\
- <div class="progress">\
- '+upload_to_web+':<br><progress class="bar" max="100" style="width:100%;" ></progress><div class="percent"></div >\
- '+transfer_to_server+':<br><progress class="bar2" max="100" style="width:100%;" ></progress><div class="percent2"></div >\
- </div>');
- /* variables */
- var progress = $('.progress');
- var percent = $('.percent');
- var bar = $('.bar');
- var percent2 = $('.percent2');
- var bar2 = $('.bar2');
- progress.hide();
- $('#dialog').dialog({
- autoOpen: true,
- width: 350,
- modal: true,
- close: function() {
- $( this ).dialog( "close" );
- window.location.href = window.location.href.replace('&back','');
- }
- });
- /* submit form with ajax request using jQuery.form plugin */
- $('form#upload').ajaxForm({
- /* set data type json */
- dataType:'json',
- beforeSubmit : function(arr, $form, options){
- if(!$("form#upload input#uploadsubmit").hasClass('disabled')){
- var i = 0;
- $.each(arr, function(index, input) {
- if(typeof input.value.name !== 'undefined')
- {
- i++;
- }
- });
- if( i > max_file_uploads )
- {
- alert("The upload exceeds the max_file_uploads directive in php.ini ("+max_file_uploads+" files).");
- return false;
- }
- if( i == 0)
- {
- return false;
- }
- }else{
- return false;
- }
- },
- /* reset before submitting */
- beforeSend: function() {
- progress.show();
- percent.html('0%');
- percent2.html('0%');
- $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').addClass('disabled').prop('disabled', true);
- },
- /* progress bar call back*/
- uploadProgress: function(event, position, total, percentComplete) {
- var pVel = percentComplete + '%';
- bar.val(percentComplete);
- percent.html(pVel);
- },
- error: function(jqXHR, textStatus, errorThrown){
- $(".uploadLiteFMStatus").html(textStatus + " " + errorThrown);
- $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').prop('disabled', false);
- },
- /* success call back */
- success: function(data) {
- if(typeof data.count !== 'undefined')
- {
- var files_qty = data.count,
- files_info = data.files,
- percent_file = [],
- file_complete = [],
- percent_total = 0,
- pVel = "",
- rond_total = 0;
- var refresh = setInterval(function(){
- $.each(files_info, function(index, file){
- if(typeof file_complete[index] !== 'undefined' && file_complete[index] == true)
- {
- return true;
- }
- $.ajax({
- type: "POST",
- url: 'home.php?m=litefm&home_id='+home_id+'&type=cleared&pid='+file['pid']+'&size='+file['size']+'&filename='+file['filename']+"&data_type=json",
- dataType:'json',
- async: false,
- success: function(data){
- percent_file[index] = data.pct / parseInt(files_qty);
- file_complete[index] = data.complete;
- }
- });
- });
-
- percent_total = 0;
- $.each(percent_file, function(index, percent){
- percent_total += percent;
- });
-
- rond_total = parseInt(percent_total);
- pVel = rond_total + '%';
- bar2.val(rond_total);
- percent2.html(pVel);
-
- var stop_refresh = true;
- $.each(file_complete, function(index, complete){
- if(complete == false)
- {
- stop_refresh = false;
- return false;
- }
- });
-
- if(stop_refresh == true)
- {
- $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').prop('disabled', false);
- clearInterval(refresh);
- }
- }, 2000);
- }
- else
- {
- if(typeof data.error.post_max_size !== 'undefined')
- {
- alert(data.error.post_max_size);
- }
- if(typeof data.error.error_message !== 'undefined')
- {
- var error_messages = "";
- $.each(data.error.error_message, function(index, message){
- error_messages += message+"\n\n";
- });
- alert(error_messages);
- }
- }
- }
- });
- });
- // secure file
- $(".chattrButton").each(function(){
- $(this).click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.secure_file = '',
- addpost.set_attr = $(this).attr('data-set_attr'),
- addpost.file_name = $(this).attr('data-file_name');
- addpost.item = $(this).attr('data-item');
- $('#dialog').html(ask_change_attr.replace("%file_name%",addpost.file_name));
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- });
- });
- // send_by_email
- $("#send_by_email.operations-button").click(function(){
- if(checkSession() == false) { return; }
- var addpost = {};
- addpost.items = [];
- addpost.send_by_email = '';
- var value = '';
- var items = '';
- $('input[class="item"]:checked').each(function(){
- item = $(this).attr('data-item');
- value = $(this).attr('value');
- addpost.items.push(item);
- items += "<br>"+value;
- });
- if(items != '')
- {
- if(user_email == "")
- {
- user_email = "destination@email";
- }
- $('#dialog').html(ask_send_by_email+":"+items+"<br>"+
- "<label for='archive_name'>"+archive_name+"</label><br>\n"+
- "<input name='archive_name' id='archive_name' type=text value='archive' style='width:100%;'><br>\n"+
- "<label for='archive_type'>"+archive_type+"</label><br>\n"+
- "<select name='archive_type' id='archive_type' style='width:100%;'>\n"+
- "<option value='zip'>zip</option>\n"+
- "<option value='tbz'>tbz</option>\n"+
- "<option value='tgz'>tgz</option>\n"+
- "<option value='tar'>tar</option>\n"+
- "<option value='bz2'>bz2 ("+compresses_files_separately+")</option>\n"+
- "</select><br>"+
- "<label for='subject'>"+subject+"</label><br>\n"+
- "<input name='subject' id='subject' type=text value='Files attached' style='width:100%;'><br>\n"+
- "<label for='message'>"+message+"</label><br>\n"+
- "<textarea name='message' id='message' style='width:100%;'>There are the files you requested from OGP</textarea><br>\n"+
- "<label for='dest_email'>"+dest_email+"</label><br>\n"+
- "<input name='dest_email' id='dest_email' type=text value='"+user_email+"' style='width:100%;'><br>\n");
-
- $('#dialog').dialog({
- autoOpen: true,
- width: 450,
- modal: true,
- buttons: [{ text: yes, click: function(){
- addpost.archive_name = $('#archive_name').val();
- addpost.archive_type = $('#archive_type').val();
- addpost.subject = $('#subject').val();
- addpost.message = $('#message').val();
- addpost.dest_email = $('#dest_email').val();
- $.ajax({
- type: "POST",
- url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
- data: addpost,
- success: function(data){
- data = $.trim(data);
- if(data != '')
- {
- alert(data);
- }
- },
- complete: function(){
- window.location.href = window.location.href.replace('&back','');
- }
- });
- $( this ).dialog( "close" );
- }
- },{ text: no, click: function(){
- $( this ).dialog( "close" );
- }
- }],
- close: function() {
- $( this ).dialog( "close" );
- }
- });
- }
- else
- {
- alert(select_at_least_one_item);
- }
- });
- });
|