litefm.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. function GetURLParameter(sParam)
  2. {
  3. var sPageURL = window.location.search.substring(1);
  4. var sURLVariables = sPageURL.split('&');
  5. for (var i = 0; i < sURLVariables.length; i++)
  6. {
  7. var sParameterName = sURLVariables[i].split('=');
  8. if (sParameterName[0] == sParam)
  9. {
  10. return sParameterName[1];
  11. }
  12. }
  13. }
  14. function checkSession() {
  15. var ret = true;
  16. var request = new XMLHttpRequest();
  17. request.open('GET', 'modules/litefm/SessionCheck.php', false);
  18. request.onload = function(e) {
  19. var session = JSON.parse(this.responseText);
  20. if(!session.valid) {
  21. alert("Your session has expired.");
  22. window.location = "index.php";
  23. ret = false;
  24. }
  25. }
  26. request.send(null);
  27. return ret;
  28. }
  29. function detectIE() {
  30. var ua = window.navigator.userAgent;
  31. var msie = ua.indexOf('MSIE ');
  32. var trident = ua.indexOf('Trident/');
  33. if (msie > 0) {
  34. // IE 10 or older => return version number
  35. return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
  36. }
  37. if (trident > 0) {
  38. // IE 11 (or newer) => return version number
  39. var rv = ua.indexOf('rv:');
  40. return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
  41. }
  42. // other browser
  43. return false;
  44. }
  45. var ie = detectIE();
  46. if (!Date.now) {
  47. Date.now = function() { return new Date().getTime(); }
  48. }
  49. function indexedDBOk() {
  50. return "indexedDB" in window;
  51. }
  52. function downloadFile(home_id, file_id, file_size, file_name)
  53. {
  54. if(checkSession() == false) { return; }
  55. var fileNode = document.getElementById('fileid'+file_id);
  56. var aLink = document.getElementById('jsDwl'+file_id);
  57. if (aLink.getAttribute('disabled') == 'disabled') {
  58. return;
  59. }
  60. aLink.setAttribute('disabled','disabled');
  61. var did = Date.now();
  62. var bytesDownloaded = 0;
  63. var progressbar = document.createElement('DIV');
  64. var progress = document.createElement('DIV');
  65. var percentage = document.createElement("SPAN");
  66. progressbar.setAttribute('id','progress_'+file_id);
  67. progressbar.setAttribute('style', 'background:white;'+
  68. 'height:4px;'+
  69. 'width:400px;'+
  70. 'border:1px solid black;'+
  71. 'position:absolute;'+
  72. 'z-index:2;');
  73. percentage.setAttribute('id','percentage_'+file_id);
  74. progressbar.appendChild(progress);
  75. fileNode.appendChild(progressbar);
  76. fileNode.appendChild(percentage);
  77. progressbar = document.getElementById('progress_'+file_id);
  78. progress = progressbar.firstChild;
  79. percentage = document.getElementById('percentage_'+file_id);
  80. var key = 1;
  81. var db;
  82. var memoryStore;
  83. function failure() {
  84. progressbar.parentNode.removeChild(progressbar);
  85. percentage.parentNode.removeChild(percentage);
  86. window.onbeforeunload = false;
  87. window.onunload = false;
  88. }
  89. function init() {
  90. if(ie)
  91. {
  92. if(ie >= 10)
  93. {
  94. memoryStore = [];
  95. getFilePart();
  96. }
  97. else
  98. {
  99. failure();
  100. alert('Your browser does not support this function.');
  101. return;
  102. }
  103. }
  104. else
  105. {
  106. if( !indexedDBOk() )
  107. {
  108. failure();
  109. alert('Your browser does not support this function.');
  110. return;
  111. }
  112. var openRequest = indexedDB.open(did,1);
  113. openRequest.onupgradeneeded = function(e) {
  114. var thisDB = e.target.result;
  115. if(!thisDB.objectStoreNames.contains("dl_parts")) {
  116. thisDB.createObjectStore("dl_parts");
  117. }
  118. }
  119. openRequest.onsuccess = function(e) {
  120. db = e.target.result;
  121. getFilePart();
  122. }
  123. openRequest.onerror = function(e) {
  124. failure();
  125. cleanUp();
  126. alert(e.target.error.name);
  127. return;
  128. }
  129. }
  130. }
  131. function addBuffer(arraybuffer, key) {
  132. if(ie)
  133. {
  134. // Store the blob in memory
  135. memoryStore.push(new Blob([arraybuffer]));
  136. }
  137. else
  138. {
  139. // Store the blob in indexedDB
  140. var transaction = db.transaction(["dl_parts"],"readwrite");
  141. var store = transaction.objectStore("dl_parts");
  142. var request = store.add(new Blob([arraybuffer]), key);
  143. request.onerror = function(e) {
  144. failure();
  145. cleanUp();
  146. alert(e.target.error.name);
  147. return;
  148. }
  149. }
  150. }
  151. function getAllParts() {
  152. if(ie)
  153. {
  154. navigator.msSaveOrOpenBlob(new Blob(memoryStore), file_name);
  155. }
  156. else
  157. {
  158. var trans = db.transaction(["dl_parts"],"readonly");
  159. var store = trans.objectStore("dl_parts");
  160. var parts = [];
  161. trans.oncomplete = function(evt) {
  162. try
  163. {
  164. var fileUrl = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
  165. var a = document.createElement('a');
  166. a.href = fileUrl;
  167. a.target = '_blank';
  168. a.download = file_name || fileUrl;
  169. var evt=new MouseEvent('click', {'view':window,'bubbles':true,'cancelable':true});
  170. a.dispatchEvent(evt);
  171. // Otherwise Firefox fails starting the download.
  172. setTimeout(function() { window.URL.revokeObjectURL(a.href); }, 1);
  173. parts = [];
  174. }
  175. catch(e)
  176. {
  177. console.log(e);
  178. }
  179. };
  180. var cursorRequest = store.openCursor();
  181. cursorRequest.onerror = function(error) {
  182. failure();
  183. cleanUp();
  184. alert(error);
  185. return;
  186. };
  187. cursorRequest.onsuccess = function(evt) {
  188. var cursor = evt.target.result;
  189. if (cursor) {
  190. parts.push(cursor.value);
  191. cursor.continue();
  192. }
  193. };
  194. }
  195. }
  196. function cleanUp() {
  197. if(ie)
  198. {
  199. memoryStore = [];
  200. }
  201. else
  202. {
  203. db.close();
  204. indexedDB.deleteDatabase(did);
  205. }
  206. var xhr = new XMLHttpRequest();
  207. xhr.open('POST', "home.php?m=litefm&home_id="+home_id+"&p=get&remove_did="+did+"&type=cleared", false);
  208. xhr.send(null);
  209. window.onunload = false;
  210. }
  211. function getFilePart()
  212. {
  213. var xhr = new XMLHttpRequest();
  214. 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);
  215. xhr.responseType = 'arraybuffer';
  216. xhr.onload = function(e) {
  217. if(this.response.byteLength != 0)
  218. {
  219. var lapTime = Date.now() - did; // milliseconds from download start
  220. // Uncompress and calculate the statistics.
  221. var compressed = new Uint8Array(this.response);
  222. var inflate = new Zlib.Inflate(compressed);
  223. var plain = inflate.decompress();
  224. bytesDownloaded += plain.byteLength;
  225. var multiplier = 1000 / lapTime;
  226. var MBs = (bytesDownloaded / 1000000) * multiplier;
  227. var value = bytesDownloaded * 100 / file_size;
  228. progress.setAttribute('style', 'background:blue;'+
  229. 'height:4px;'+
  230. 'width:'+value+'%;');
  231. percentage.innerHTML = "&nbsp;"+(Math.round(value * 100) / 100)+"%&nbsp;-&nbsp;"+MBs.toFixed(2)+"MB/s";
  232. addBuffer(plain, key++);
  233. // Get the next part
  234. getFilePart();
  235. }
  236. else
  237. {
  238. getAllParts();
  239. // Otherwise Firefox fails starting the download.
  240. setTimeout(function() { cleanUp(); }, 60000);
  241. // element.remove(); fails on IE
  242. progressbar.parentNode.removeChild(progressbar);
  243. percentage.parentNode.removeChild(percentage);
  244. aLink.removeAttribute('disabled');
  245. window.onbeforeunload = false;
  246. }
  247. };
  248. xhr.send(null);
  249. }
  250. window.onbeforeunload = function(){
  251. return 'A file download is in progress';
  252. };
  253. window.onunload = function(){
  254. cleanUp();
  255. }
  256. init();
  257. }
  258. $(document).ready(function(){
  259. /* translation & info */
  260. var select_at_least_one_item = $('#dialog').attr('data-select_at_least_one_item'),
  261. ask_delete = $('#dialog').attr('data-ask_delete'),
  262. ask_rename = $('#dialog').attr('data-ask_rename'),
  263. ask_move = $('#dialog').attr('data-ask_move'),
  264. ask_copy = $('#dialog').attr('data-ask_copy'),
  265. ask_compress = $('#dialog').attr('data-ask_compress'),
  266. ask_uncompress = $('#dialog').attr('data-ask_uncompress'),
  267. archive_name = $('#dialog').attr('data-archive_name'),
  268. archive_type = $('#dialog').attr('data-archive_type'),
  269. file_name = $('#dialog').attr('data-file_name'),
  270. folder_name = $('#dialog').attr('data-folder_name'),
  271. compresses_files_separately = $('#dialog').attr('data-compresses_files_separately'),
  272. to = $('#dialog').attr('data-to'),
  273. yes = $('#dialog').attr('data-yes'),
  274. no = $('#dialog').attr('data-no'),
  275. max_file_uploads = $('#dialog').attr('data-max_file_uploads'),
  276. upload_to_web = $('#dialog').attr('data-upload_to_web'),
  277. transfer_to_server = $('#dialog').attr('data-transfer_to_server'),
  278. upload = $('#dialog').attr('data-upload'),
  279. ask_change_attr = $('#dialog').attr('data-ask_change_attr'),
  280. ask_send_by_email = $('#dialog').attr('data-ask_send_by_email'),
  281. subject = $('#dialog').attr('data-subject'),
  282. message = $('#dialog').attr('data-message'),
  283. dest_email = $('#dialog').attr('data-dest_email'),
  284. user_email = $('#dialog').attr('data-user_email');
  285. // Home id
  286. var home_id = GetURLParameter('home_id');
  287. // Browse folder (when using "move/uncompress")
  288. $('.folder').each(function(){
  289. $(this).click(function(){
  290. if(checkSession() == false) { return; }
  291. var addpost = {};
  292. addpost[ 'm' ] = 'user_games';
  293. addpost[ 'p' ] = 'browser';
  294. addpost[ 'home_id' ] = $('.levelup').attr('data-home-id');
  295. addpost[ 'item' ] = $(this).attr('data-item');
  296. addpost[ 'type' ] = 'cleared';
  297. $.ajax({
  298. type: "GET",
  299. url: "home.php",
  300. data: addpost,
  301. success: function(data){
  302. data = data.replace("user_games.js","litefm.js");
  303. $( "#browser" ).html(data);
  304. }
  305. });
  306. });
  307. });
  308. // Back to previous folder (when using "move/uncompress")
  309. $('.levelup').click(function(){
  310. if(checkSession() == false) { return; }
  311. var addpost = {};
  312. addpost[ 'm' ] = 'user_games';
  313. addpost[ 'p' ] = 'browser';
  314. addpost[ 'home_id' ] = $(this).attr('data-home-id');
  315. addpost[ 'back' ] = 'back';
  316. addpost[ 'type' ] = 'cleared';
  317. $.ajax({
  318. type: "GET",
  319. url: "home.php",
  320. data: addpost,
  321. success: function(data){
  322. data = data.replace("user_games.js","litefm.js");
  323. $( "#browser" ).html(data);
  324. }
  325. });
  326. });
  327. // Create new folder (when using "move/uncompress")
  328. $('#addfolder').click(function(){
  329. if(checkSession() == false) { return; }
  330. var addpost = {};
  331. addpost[ 'm' ] = 'user_games';
  332. addpost[ 'p' ] = 'browser';
  333. addpost[ 'home_id' ] = home_id;
  334. addpost[ 'create_folder' ] = 'create_folder';
  335. addpost[ 'folder_name' ] = $('input[name=dirname]').val();
  336. addpost[ 'type' ] = 'cleared';
  337. $.ajax({
  338. type: "GET",
  339. url: "home.php",
  340. data: addpost,
  341. success: function(data){
  342. data = data.replace("user_games.js","litefm.js");
  343. $( "#browser" ).html(data);
  344. }
  345. });
  346. });
  347. // Switch checkboxes
  348. $("#switch_check").click(function(){
  349. var checkBoxes = $('input[class="item"]');
  350. checkBoxes.prop("checked", !checkBoxes.prop("checked"));
  351. });
  352. // Remove
  353. $("#remove.operations-button").click(function(){
  354. if(checkSession() == false) { return; }
  355. var addpost = {};
  356. addpost.items = [];
  357. addpost.remove = '';
  358. var item = '';
  359. var value = '';
  360. var items = '';
  361. $('input[class="item"]:checked').each(function(){
  362. item = $(this).attr('data-item');
  363. value = $(this).attr('value');
  364. addpost.items.push(item);
  365. items += "<br>"+value;
  366. });
  367. if(items != '')
  368. {
  369. $('#dialog').html(ask_delete.replace("%s", ":"+items));
  370. $('#dialog').dialog({
  371. autoOpen: true,
  372. width: 450,
  373. modal: true,
  374. buttons: [{ text: yes, click: function(){
  375. $.ajax({
  376. type: "POST",
  377. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  378. data: addpost,
  379. complete: function(){
  380. window.location.href = window.location.href.replace('&back','');
  381. }
  382. });
  383. $( this ).dialog( "close" );
  384. }
  385. },{ text: no, click: function(){
  386. $( this ).dialog( "close" );
  387. }
  388. }],
  389. close: function() {
  390. $( this ).dialog( "close" );
  391. }
  392. });
  393. }
  394. else
  395. {
  396. alert(select_at_least_one_item);
  397. }
  398. });
  399. // Rename
  400. $("#rename.operations-button").click(function(){
  401. if(checkSession() == false) { return; }
  402. var addpost = {};
  403. addpost.items = [];
  404. addpost.values = [];
  405. addpost.rename = '';
  406. var value = '';
  407. var items = '';
  408. $('input[class="item"]:checked').each(function(){
  409. item = $(this).attr('data-item');
  410. value = $(this).attr('value').replace('"', "&quot;");
  411. addpost.items.push(item);
  412. items += "<br><input class='rename' type=text style='width:100%;' name='"+item+"' value=\""+value+"\">";
  413. });
  414. if(items != '')
  415. {
  416. $('#dialog').html(ask_rename+":"+items);
  417. $('#dialog').dialog({
  418. autoOpen: true,
  419. width: 450,
  420. modal: true,
  421. buttons: [{ text: yes, click: function(){
  422. $('input[class="rename"]').each(function(){
  423. value = $(this).val();
  424. addpost.values.push(value);
  425. });
  426. $.ajax({
  427. type: "POST",
  428. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  429. data: addpost,
  430. complete: function(){
  431. window.location.href = window.location.href.replace('&back','');
  432. }
  433. });
  434. $( this ).dialog( "close" );
  435. }
  436. },{ text: no, click: function(){
  437. $( this ).dialog( "close" );
  438. }
  439. }],
  440. close: function() {
  441. $( this ).dialog( "close" );
  442. }
  443. });
  444. }
  445. else
  446. {
  447. alert(select_at_least_one_item);
  448. }
  449. });
  450. // Move
  451. $("#move.operations-button").click(function(){
  452. if(checkSession() == false) { return; }
  453. var addpost = {};
  454. addpost.items = [];
  455. addpost.values = [];
  456. addpost.move = '';
  457. var value = '';
  458. var items = '';
  459. $('input[class="item"]:checked').each(function(){
  460. item = $(this).attr('data-item');
  461. value = $(this).attr('value');
  462. addpost.items.push(item);
  463. items += "<br>"+value;
  464. });
  465. if(items != '')
  466. {
  467. var addpostb = {};
  468. addpostb[ 'm' ] = 'user_games';
  469. addpostb[ 'p' ] = 'browser';
  470. addpostb[ 'home_id' ] = home_id;
  471. addpostb[ 'folder' ] = $('#dialog').attr('data-folder');
  472. addpostb[ 'type' ] = 'cleared';
  473. $.ajax({
  474. type: "GET",
  475. url: "home.php",
  476. data: addpostb,
  477. async: false,
  478. success: function(data){
  479. data = data.replace("user_games.js","litefm.js");
  480. $('#dialog').html(ask_move+":"+items+"<br>"+to+":<br><div id='browser' >"+data+"</div>");
  481. }
  482. });
  483. $('#dialog').dialog({
  484. autoOpen: true,
  485. width: 450,
  486. modal: true,
  487. buttons: [{ text: yes, click: function(){
  488. addpost.selected_path = $('#selected_path').text();
  489. $.ajax({
  490. type: "POST",
  491. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  492. data: addpost,
  493. complete: function(){
  494. window.location.href = window.location.href.replace('&back','');
  495. }
  496. });
  497. $( this ).dialog( "close" );
  498. }
  499. },{ text: no, click: function(){
  500. $( this ).dialog( "close" );
  501. }
  502. }],
  503. close: function() {
  504. $( this ).dialog( "close" );
  505. }
  506. });
  507. }
  508. else
  509. {
  510. alert(select_at_least_one_item);
  511. }
  512. });
  513. // Copy
  514. $("#copy.operations-button").click(function(){
  515. if(checkSession() == false) { return; }
  516. var addpost = {};
  517. addpost.items = [];
  518. addpost.values = [];
  519. addpost.copy = '';
  520. var value = '';
  521. var items = '';
  522. $('input[class="item"]:checked').each(function(){
  523. item = $(this).attr('data-item');
  524. value = $(this).attr('value');
  525. addpost.items.push(item);
  526. items += "<br>"+value;
  527. });
  528. if(items != '')
  529. {
  530. var addpostb = {};
  531. addpostb[ 'm' ] = 'user_games';
  532. addpostb[ 'p' ] = 'browser';
  533. addpostb[ 'home_id' ] = home_id;
  534. addpostb[ 'folder' ] = $('#dialog').attr('data-folder');
  535. addpostb[ 'type' ] = 'cleared';
  536. $.ajax({
  537. type: "GET",
  538. url: "home.php",
  539. data: addpostb,
  540. async: false,
  541. success: function(data){
  542. data = data.replace("user_games.js","litefm.js");
  543. $('#dialog').html(ask_copy+":"+items+"<br>"+to+":<br><div id='browser' >"+data+"</div>");
  544. }
  545. });
  546. $('#dialog').dialog({
  547. autoOpen: true,
  548. width: 450,
  549. modal: true,
  550. buttons: [{ text: yes, click: function(){
  551. addpost.selected_path = $('#selected_path').text();
  552. $.ajax({
  553. type: "POST",
  554. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  555. data: addpost,
  556. complete: function(){
  557. window.location.href = window.location.href.replace('&back','');
  558. }
  559. });
  560. }
  561. },{ text: no, click: function(){
  562. $( this ).dialog( "close" );
  563. }
  564. }],
  565. close: function() {
  566. $( this ).dialog( "close" );
  567. }
  568. });
  569. }
  570. else
  571. {
  572. alert(select_at_least_one_item);
  573. }
  574. });
  575. // Compress
  576. $("#compress.operations-button").click(function(){
  577. if(checkSession() == false) { return; }
  578. var addpost = {};
  579. addpost.items = [];
  580. addpost.compress = '';
  581. var value = '';
  582. var items = '';
  583. $('input[class="item"]:checked').each(function(){
  584. item = $(this).attr('data-item');
  585. value = $(this).attr('value');
  586. addpost.items.push(item);
  587. items += "<br>"+value;
  588. });
  589. if(items != '')
  590. {
  591. $('#dialog').html(ask_compress+":"+items+"<br>"+
  592. "<label for='archive_name'>"+archive_name+"</label>\n"+
  593. "<input name='archive_name' id='archive_name' type=text value='archive' ><br>\n"+
  594. "<label for='archive_type'>"+archive_type+"</label>\n"+
  595. "<select name='archive_type' id='archive_type' >\n"+
  596. "<option value='zip'>zip</option>\n"+
  597. "<option value='tbz'>tbz</option>\n"+
  598. "<option value='tgz'>tgz</option>\n"+
  599. "<option value='tar'>tar</option>\n"+
  600. "<option value='bz2'>bz2 ("+compresses_files_separately+")</option>\n"+
  601. "</select>");
  602. $('#dialog').dialog({
  603. autoOpen: true,
  604. width: 450,
  605. modal: true,
  606. buttons: [{ text: yes, click: function(){
  607. addpost.archive_name = $('#archive_name').val();
  608. addpost.archive_type = $('#archive_type').val();
  609. $.ajax({
  610. type: "POST",
  611. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  612. data: addpost,
  613. complete: function(){
  614. window.location.href = window.location.href.replace('&back','');
  615. }
  616. });
  617. $( this ).dialog( "close" );
  618. }
  619. },{ text: no, click: function(){
  620. $( this ).dialog( "close" );
  621. }
  622. }],
  623. close: function() {
  624. $( this ).dialog( "close" );
  625. }
  626. });
  627. }
  628. else
  629. {
  630. alert(select_at_least_one_item);
  631. }
  632. });
  633. // Uncompress
  634. $("#uncompress.operations-button").click(function(){
  635. if(checkSession() == false) { return; }
  636. var addpost = {};
  637. addpost.items = [];
  638. addpost.values = [];
  639. addpost.uncompress = '';
  640. var value = '';
  641. var items = '';
  642. var ext = '';
  643. $('input[class="item"]:checked').each(function(){
  644. item = $(this).attr('data-item');
  645. value = $(this).attr('value');
  646. ext = value.split('.').pop();
  647. if(ext.match(/^(tar|tgz|gz|Z|zip|bz2|tbz|lzma|xz|txz)$/i) != null)
  648. {
  649. addpost.items.push(item);
  650. items += "<br>"+value;
  651. }
  652. });
  653. if(items != '')
  654. {
  655. var addpostb = {};
  656. addpostb[ 'm' ] = 'user_games';
  657. addpostb[ 'p' ] = 'browser';
  658. addpostb[ 'home_id' ] = home_id;
  659. addpostb[ 'folder' ] = $('#dialog').attr('data-folder');
  660. addpostb[ 'type' ] = 'cleared';
  661. $.ajax({
  662. type: "GET",
  663. url: "home.php",
  664. data: addpostb,
  665. async: false,
  666. success: function(data){
  667. data = data.replace("user_games.js","litefm.js");
  668. $('#dialog').html(ask_uncompress+":"+items+"<br>"+to+":<br><div id='browser' >"+data+"</div>");
  669. }
  670. });
  671. $('#dialog').dialog({
  672. autoOpen: true,
  673. width: 450,
  674. modal: true,
  675. buttons: [{ text: yes, click: function(){
  676. addpost.selected_path = $('#selected_path').text();
  677. $.ajax({
  678. type: "POST",
  679. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  680. data: addpost,
  681. complete: function(){
  682. window.location.href = window.location.href.replace('&back','');
  683. }
  684. });
  685. }
  686. },{ text: no, click: function(){
  687. $( this ).dialog( "close" );
  688. }
  689. }],
  690. close: function() {
  691. $( this ).dialog( "close" );
  692. }
  693. });
  694. }
  695. else
  696. {
  697. alert(select_at_least_one_item);
  698. }
  699. });
  700. // Create File
  701. $("#create_file.operations-button").click(function(){
  702. if(checkSession() == false) { return; }
  703. var addpost = {};
  704. addpost.create_file = '';
  705. $('#dialog').html("<label for='file_name'>"+file_name+"</label>\n"+
  706. "<input id='file_name' type=text style='width:100%;' name='file_name' >");
  707. $('#dialog').dialog({
  708. autoOpen: true,
  709. width: 450,
  710. modal: true,
  711. buttons: [{ text: yes, click: function(){
  712. addpost.file_name = $('input[id="file_name"]').val();
  713. $.ajax({
  714. type: "POST",
  715. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  716. data: addpost,
  717. complete: function(){
  718. window.location.href = window.location.href.replace('&back','');
  719. }
  720. });
  721. $( this ).dialog( "close" );
  722. }
  723. },{ text: no, click: function(){
  724. $( this ).dialog( "close" );
  725. }
  726. }],
  727. close: function() {
  728. $( this ).dialog( "close" );
  729. }
  730. });
  731. });
  732. // Create Folder
  733. $("#create_folder.operations-button").click(function(){
  734. if(checkSession() == false) { return; }
  735. var addpost = {};
  736. addpost.create_folder = '';
  737. $('#dialog').html("<label for='folder_name'>"+folder_name+"</label>\n"+
  738. "<input id='folder_name' type=text style='width:100%;' name='folder_name' >");
  739. $('#dialog').dialog({
  740. autoOpen: true,
  741. width: 450,
  742. modal: true,
  743. buttons: [{ text: yes, click: function(){
  744. addpost.folder_name = $('input[id="folder_name"]').val();
  745. $.ajax({
  746. type: "POST",
  747. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  748. data: addpost,
  749. complete: function(){
  750. window.location.href = window.location.href.replace('&back','');
  751. }
  752. });
  753. $( this ).dialog( "close" );
  754. }
  755. },{ text: no, click: function(){
  756. $( this ).dialog( "close" );
  757. }
  758. }],
  759. close: function() {
  760. $( this ).dialog( "close" );
  761. }
  762. });
  763. });
  764. // upload
  765. $("#upload.operations-button").click(function(){
  766. if(checkSession() == false) { return; }
  767. $('#dialog').html('<div class="uploadLiteFMStatus status"></div>\
  768. <form id="upload" action="home.php?m=litefm&home_id='+home_id+'&type=cleared&data_type=json" method="post" enctype="multipart/form-data">\
  769. <input type="file" name="files[]" multiple="multiple" id="files">\
  770. <input type="submit" name="upload" id="uploadsubmit" value="'+upload+'" >\
  771. </form>\
  772. <div class="progress">\
  773. '+upload_to_web+':<br><progress class="bar" max="100" style="width:100%;" ></progress><div class="percent"></div >\
  774. '+transfer_to_server+':<br><progress class="bar2" max="100" style="width:100%;" ></progress><div class="percent2"></div >\
  775. </div>');
  776. /* variables */
  777. var progress = $('.progress');
  778. var percent = $('.percent');
  779. var bar = $('.bar');
  780. var percent2 = $('.percent2');
  781. var bar2 = $('.bar2');
  782. progress.hide();
  783. $('#dialog').dialog({
  784. autoOpen: true,
  785. width: 350,
  786. modal: true,
  787. close: function() {
  788. $( this ).dialog( "close" );
  789. window.location.href = window.location.href.replace('&back','');
  790. }
  791. });
  792. /* submit form with ajax request using jQuery.form plugin */
  793. $('form#upload').ajaxForm({
  794. /* set data type json */
  795. dataType:'json',
  796. beforeSubmit : function(arr, $form, options){
  797. $(".uploadLiteFMStatus").html("");
  798. if(!$("form#upload input#uploadsubmit").hasClass('disabled')){
  799. var i = 0;
  800. $.each(arr, function(index, input) {
  801. if(typeof input.value.name !== 'undefined')
  802. {
  803. i++;
  804. }
  805. });
  806. if( i > max_file_uploads )
  807. {
  808. alert("The upload exceeds the max_file_uploads directive in php.ini ("+max_file_uploads+" files).");
  809. return false;
  810. }
  811. if( i == 0)
  812. {
  813. return false;
  814. }
  815. }else{
  816. return false;
  817. }
  818. },
  819. /* reset before submitting */
  820. beforeSend: function() {
  821. progress.show();
  822. percent.html('0%');
  823. percent2.html('0%');
  824. $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').addClass('disabled').prop('disabled', true);
  825. },
  826. /* progress bar call back*/
  827. uploadProgress: function(event, position, total, percentComplete) {
  828. var pVel = percentComplete + '%';
  829. bar.val(percentComplete);
  830. percent.html(pVel);
  831. },
  832. error: function(jqXHR, textStatus, errorThrown){
  833. $(".uploadLiteFMStatus").html(textStatus + " " + errorThrown);
  834. $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').prop('disabled', false);
  835. },
  836. /* success call back */
  837. success: function(data) {
  838. if(typeof data.count !== 'undefined')
  839. {
  840. var files_qty = data.count,
  841. files_info = data.files,
  842. percent_file = [],
  843. file_complete = [],
  844. percent_total = 0,
  845. pVel = "",
  846. rond_total = 0;
  847. var refresh = setInterval(function(){
  848. $.each(files_info, function(index, file){
  849. if(typeof file_complete[index] !== 'undefined' && file_complete[index] == true)
  850. {
  851. return true;
  852. }
  853. $.ajax({
  854. type: "POST",
  855. url: 'home.php?m=litefm&home_id='+home_id+'&type=cleared&pid='+file['pid']+'&size='+file['size']+'&filename='+file['filename']+"&data_type=json",
  856. dataType:'json',
  857. async: false,
  858. success: function(data){
  859. percent_file[index] = data.pct / parseInt(files_qty);
  860. file_complete[index] = data.complete;
  861. }
  862. });
  863. });
  864. percent_total = 0;
  865. $.each(percent_file, function(index, percent){
  866. percent_total += percent;
  867. });
  868. rond_total = parseInt(percent_total);
  869. pVel = rond_total + '%';
  870. bar2.val(rond_total);
  871. percent2.html(pVel);
  872. var stop_refresh = true;
  873. $.each(file_complete, function(index, complete){
  874. if(complete == false)
  875. {
  876. stop_refresh = false;
  877. return false;
  878. }
  879. });
  880. if(stop_refresh == true)
  881. {
  882. $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').prop('disabled', false);
  883. clearInterval(refresh);
  884. }
  885. }, 2000);
  886. }
  887. else
  888. {
  889. if(typeof data.error.post_max_size !== 'undefined')
  890. {
  891. alert(data.error.post_max_size);
  892. }
  893. if(typeof data.error.error_message !== 'undefined')
  894. {
  895. var error_messages = "";
  896. $.each(data.error.error_message, function(index, message){
  897. error_messages += message+"\n\n";
  898. });
  899. alert(error_messages);
  900. }
  901. }
  902. }
  903. });
  904. });
  905. // secure file
  906. $(".chattrButton").each(function(){
  907. $(this).click(function(){
  908. if(checkSession() == false) { return; }
  909. var addpost = {};
  910. addpost.secure_file = '',
  911. addpost.set_attr = $(this).attr('data-set_attr'),
  912. addpost.file_name = $(this).attr('data-file_name');
  913. addpost.item = $(this).attr('data-item');
  914. $('#dialog').html(ask_change_attr.replace("%file_name%",addpost.file_name));
  915. $('#dialog').dialog({
  916. autoOpen: true,
  917. width: 450,
  918. modal: true,
  919. buttons: [{ text: yes, click: function(){
  920. $.ajax({
  921. type: "POST",
  922. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  923. data: addpost,
  924. complete: function(){
  925. window.location.href = window.location.href.replace('&back','');
  926. }
  927. });
  928. $( this ).dialog( "close" );
  929. }
  930. },{ text: no, click: function(){
  931. $( this ).dialog( "close" );
  932. }
  933. }],
  934. close: function() {
  935. $( this ).dialog( "close" );
  936. }
  937. });
  938. });
  939. });
  940. // send_by_email
  941. $("#send_by_email.operations-button").click(function(){
  942. if(checkSession() == false) { return; }
  943. var addpost = {};
  944. addpost.items = [];
  945. addpost.send_by_email = '';
  946. var value = '';
  947. var items = '';
  948. $('input[class="item"]:checked').each(function(){
  949. item = $(this).attr('data-item');
  950. value = $(this).attr('value');
  951. addpost.items.push(item);
  952. items += "<br>"+value;
  953. });
  954. if(items != '')
  955. {
  956. if(user_email == "")
  957. {
  958. user_email = "destination@email";
  959. }
  960. $('#dialog').html(ask_send_by_email+":"+items+"<br>"+
  961. "<label for='archive_name'>"+archive_name+"</label><br>\n"+
  962. "<input name='archive_name' id='archive_name' type=text value='archive' style='width:100%;'><br>\n"+
  963. "<label for='archive_type'>"+archive_type+"</label><br>\n"+
  964. "<select name='archive_type' id='archive_type' style='width:100%;'>\n"+
  965. "<option value='zip'>zip</option>\n"+
  966. "<option value='tbz'>tbz</option>\n"+
  967. "<option value='tgz'>tgz</option>\n"+
  968. "<option value='tar'>tar</option>\n"+
  969. "<option value='bz2'>bz2 ("+compresses_files_separately+")</option>\n"+
  970. "</select><br>"+
  971. "<label for='subject'>"+subject+"</label><br>\n"+
  972. "<input name='subject' id='subject' type=text value='Files attached' style='width:100%;'><br>\n"+
  973. "<label for='message'>"+message+"</label><br>\n"+
  974. "<textarea name='message' id='message' style='width:100%;'>There are the files you requested from OGP</textarea><br>\n"+
  975. "<label for='dest_email'>"+dest_email+"</label><br>\n"+
  976. "<input name='dest_email' id='dest_email' type=text value='"+user_email+"' style='width:100%;'><br>\n");
  977. $('#dialog').dialog({
  978. autoOpen: true,
  979. width: 450,
  980. modal: true,
  981. buttons: [{ text: yes, click: function(){
  982. addpost.archive_name = $('#archive_name').val();
  983. addpost.archive_type = $('#archive_type').val();
  984. addpost.subject = $('#subject').val();
  985. addpost.message = $('#message').val();
  986. addpost.dest_email = $('#dest_email').val();
  987. $.ajax({
  988. type: "POST",
  989. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  990. data: addpost,
  991. success: function(data){
  992. data = $.trim(data);
  993. if(data != '')
  994. {
  995. alert(data);
  996. }
  997. },
  998. complete: function(){
  999. window.location.href = window.location.href.replace('&back','');
  1000. }
  1001. });
  1002. $( this ).dialog( "close" );
  1003. }
  1004. },{ text: no, click: function(){
  1005. $( this ).dialog( "close" );
  1006. }
  1007. }],
  1008. close: function() {
  1009. $( this ).dialog( "close" );
  1010. }
  1011. });
  1012. }
  1013. else
  1014. {
  1015. alert(select_at_least_one_item);
  1016. }
  1017. });
  1018. });