litefm.js 29 KB

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