litefm.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  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. if(!$("form#upload input#uploadsubmit").hasClass('disabled')){
  798. var i = 0;
  799. $.each(arr, function(index, input) {
  800. if(typeof input.value.name !== 'undefined')
  801. {
  802. i++;
  803. }
  804. });
  805. if( i > max_file_uploads )
  806. {
  807. alert("The upload exceeds the max_file_uploads directive in php.ini ("+max_file_uploads+" files).");
  808. return false;
  809. }
  810. if( i == 0)
  811. {
  812. return false;
  813. }
  814. }else{
  815. return false;
  816. }
  817. },
  818. /* reset before submitting */
  819. beforeSend: function() {
  820. progress.show();
  821. percent.html('0%');
  822. percent2.html('0%');
  823. $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').addClass('disabled').prop('disabled', true);
  824. },
  825. /* progress bar call back*/
  826. uploadProgress: function(event, position, total, percentComplete) {
  827. var pVel = percentComplete + '%';
  828. bar.val(percentComplete);
  829. percent.html(pVel);
  830. },
  831. error: function(jqXHR, textStatus, errorThrown){
  832. $(".uploadLiteFMStatus").html(textStatus + " " + errorThrown);
  833. $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').prop('disabled', false);
  834. },
  835. /* success call back */
  836. success: function(data) {
  837. if(typeof data.count !== 'undefined')
  838. {
  839. var files_qty = data.count,
  840. files_info = data.files,
  841. percent_file = [],
  842. file_complete = [],
  843. percent_total = 0,
  844. pVel = "",
  845. rond_total = 0;
  846. var refresh = setInterval(function(){
  847. $.each(files_info, function(index, file){
  848. if(typeof file_complete[index] !== 'undefined' && file_complete[index] == true)
  849. {
  850. return true;
  851. }
  852. $.ajax({
  853. type: "POST",
  854. url: 'home.php?m=litefm&home_id='+home_id+'&type=cleared&pid='+file['pid']+'&size='+file['size']+'&filename='+file['filename']+"&data_type=json",
  855. dataType:'json',
  856. async: false,
  857. success: function(data){
  858. percent_file[index] = data.pct / parseInt(files_qty);
  859. file_complete[index] = data.complete;
  860. }
  861. });
  862. });
  863. percent_total = 0;
  864. $.each(percent_file, function(index, percent){
  865. percent_total += percent;
  866. });
  867. rond_total = parseInt(percent_total);
  868. pVel = rond_total + '%';
  869. bar2.val(rond_total);
  870. percent2.html(pVel);
  871. var stop_refresh = true;
  872. $.each(file_complete, function(index, complete){
  873. if(complete == false)
  874. {
  875. stop_refresh = false;
  876. return false;
  877. }
  878. });
  879. if(stop_refresh == true)
  880. {
  881. $("form#upload input#files, form#upload input#uploadsubmit").removeClass('disabled').prop('disabled', false);
  882. clearInterval(refresh);
  883. }
  884. }, 2000);
  885. }
  886. else
  887. {
  888. if(typeof data.error.post_max_size !== 'undefined')
  889. {
  890. alert(data.error.post_max_size);
  891. }
  892. if(typeof data.error.error_message !== 'undefined')
  893. {
  894. var error_messages = "";
  895. $.each(data.error.error_message, function(index, message){
  896. error_messages += message+"\n\n";
  897. });
  898. alert(error_messages);
  899. }
  900. }
  901. }
  902. });
  903. });
  904. // secure file
  905. $(".chattrButton").each(function(){
  906. $(this).click(function(){
  907. if(checkSession() == false) { return; }
  908. var addpost = {};
  909. addpost.secure_file = '',
  910. addpost.set_attr = $(this).attr('data-set_attr'),
  911. addpost.file_name = $(this).attr('data-file_name');
  912. addpost.item = $(this).attr('data-item');
  913. $('#dialog').html(ask_change_attr.replace("%file_name%",addpost.file_name));
  914. $('#dialog').dialog({
  915. autoOpen: true,
  916. width: 450,
  917. modal: true,
  918. buttons: [{ text: yes, click: function(){
  919. $.ajax({
  920. type: "POST",
  921. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  922. data: addpost,
  923. complete: function(){
  924. window.location.href = window.location.href.replace('&back','');
  925. }
  926. });
  927. $( this ).dialog( "close" );
  928. }
  929. },{ text: no, click: function(){
  930. $( this ).dialog( "close" );
  931. }
  932. }],
  933. close: function() {
  934. $( this ).dialog( "close" );
  935. }
  936. });
  937. });
  938. });
  939. // send_by_email
  940. $("#send_by_email.operations-button").click(function(){
  941. if(checkSession() == false) { return; }
  942. var addpost = {};
  943. addpost.items = [];
  944. addpost.send_by_email = '';
  945. var value = '';
  946. var items = '';
  947. $('input[class="item"]:checked').each(function(){
  948. item = $(this).attr('data-item');
  949. value = $(this).attr('value');
  950. addpost.items.push(item);
  951. items += "<br>"+value;
  952. });
  953. if(items != '')
  954. {
  955. if(user_email == "")
  956. {
  957. user_email = "destination@email";
  958. }
  959. $('#dialog').html(ask_send_by_email+":"+items+"<br>"+
  960. "<label for='archive_name'>"+archive_name+"</label><br>\n"+
  961. "<input name='archive_name' id='archive_name' type=text value='archive' style='width:100%;'><br>\n"+
  962. "<label for='archive_type'>"+archive_type+"</label><br>\n"+
  963. "<select name='archive_type' id='archive_type' style='width:100%;'>\n"+
  964. "<option value='zip'>zip</option>\n"+
  965. "<option value='tbz'>tbz</option>\n"+
  966. "<option value='tgz'>tgz</option>\n"+
  967. "<option value='tar'>tar</option>\n"+
  968. "<option value='bz2'>bz2 ("+compresses_files_separately+")</option>\n"+
  969. "</select><br>"+
  970. "<label for='subject'>"+subject+"</label><br>\n"+
  971. "<input name='subject' id='subject' type=text value='Files attached' style='width:100%;'><br>\n"+
  972. "<label for='message'>"+message+"</label><br>\n"+
  973. "<textarea name='message' id='message' style='width:100%;'>There are the files you requested from OGP</textarea><br>\n"+
  974. "<label for='dest_email'>"+dest_email+"</label><br>\n"+
  975. "<input name='dest_email' id='dest_email' type=text value='"+user_email+"' style='width:100%;'><br>\n");
  976. $('#dialog').dialog({
  977. autoOpen: true,
  978. width: 450,
  979. modal: true,
  980. buttons: [{ text: yes, click: function(){
  981. addpost.archive_name = $('#archive_name').val();
  982. addpost.archive_type = $('#archive_type').val();
  983. addpost.subject = $('#subject').val();
  984. addpost.message = $('#message').val();
  985. addpost.dest_email = $('#dest_email').val();
  986. $.ajax({
  987. type: "POST",
  988. url: "home.php?m=litefm&home_id="+home_id+"&type=cleared",
  989. data: addpost,
  990. success: function(data){
  991. data = $.trim(data);
  992. if(data != '')
  993. {
  994. alert(data);
  995. }
  996. },
  997. complete: function(){
  998. window.location.href = window.location.href.replace('&back','');
  999. }
  1000. });
  1001. $( this ).dialog( "close" );
  1002. }
  1003. },{ text: no, click: function(){
  1004. $( this ).dialog( "close" );
  1005. }
  1006. }],
  1007. close: function() {
  1008. $( this ).dialog( "close" );
  1009. }
  1010. });
  1011. }
  1012. else
  1013. {
  1014. alert(select_at_least_one_item);
  1015. }
  1016. });
  1017. });