Image_manager.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. include '../auth.php';
  3. if(isset($_GET["bkend"])){
  4. if(isset($_GET["query"])){
  5. if($_GET["query"] == "playlist"){
  6. $intdirs = array_filter(glob("storage/" . "*"), 'is_dir');
  7. $IntDirWInfo = [];
  8. foreach ($intdirs as &$intdir) {
  9. preg_match('/storage\/([^\/]*)/', $intdir, $out_playlist);
  10. $tmp = [];
  11. $tmp["name"] = "Internal - ".hex2bin($out_playlist[1]);
  12. $tmp["dir"] = "../../../Video/".$intdir."/";
  13. $tmp["drive"] = "internal";
  14. $tmp["playlist"] = $out_playlist[1];
  15. array_push($IntDirWInfo,$tmp);
  16. }
  17. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  18. $ExtDirWInfo = []; //TODO: add ext support
  19. }else{
  20. if (file_exists("/media/")){
  21. $extdirs = array_filter(glob("/media/*/Video/*"), 'is_dir');
  22. $ExtDirWInfo = [];
  23. foreach ($extdirs as &$extdir) {
  24. preg_match('/\/media\/([^\/]*)\//', $extdir, $out_storage);
  25. preg_match('/Video\/([^\/]*)/', $extdir, $out_playlist);
  26. $tmp = [];
  27. $tmp["name"] = $out_storage[1]." - ".hex2bin($out_playlist[1]);
  28. $tmp["dir"] = $extdir."/";
  29. $tmp["drive"] = $out_storage[1];
  30. $tmp["playlist"] = $out_playlist[1];
  31. array_push($ExtDirWInfo,$tmp);
  32. }
  33. }
  34. }
  35. $dirs = array_merge($IntDirWInfo,$ExtDirWInfo);
  36. echo json_encode($dirs);
  37. }else if($_GET["query"] == "storage"){
  38. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  39. $extdirs = [];
  40. }else{
  41. $extdirs = array_filter(glob("/media/*"), 'is_dir');
  42. }
  43. $dirs = array_merge($extdirs,["internal"]);
  44. echo json_encode($dirs);
  45. }else if($_GET["query"] == "unsort"){
  46. $intdirs = glob('uploads/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
  47. $IntDirWInfo = [];
  48. foreach ($intdirs as &$intdir) {
  49. $tmp = [];
  50. $tmp["dir"] = "../../../Photo/".$intdir;
  51. $tmp["drive"] = "internal";
  52. array_push($IntDirWInfo,$tmp);
  53. }
  54. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  55. $ExtDirWInfo = []; //TODO: add ext support
  56. }else{
  57. if (file_exists("/media/")){
  58. $extdirs = glob("/media/*/Photo/*.{jpg,jpeg,png,gif}");
  59. $ExtDirWInfo = [];
  60. foreach ($extdirs as &$extdir) {
  61. preg_match('/\/media\/([^\/]*)\//', $extdir, $out_storage);
  62. $tmp = [];
  63. $tmp["dir"] = $extdir;
  64. $tmp["drive"] = $out_storage[1];
  65. array_push($ExtDirWInfo,$tmp);
  66. }
  67. }
  68. }
  69. $dirs = array_merge($IntDirWInfo,$ExtDirWInfo);
  70. echo json_encode($dirs);
  71. }
  72. }
  73. die();
  74. }
  75. ?>
  76. <!DOCTYPE html>
  77. <html>
  78. <head>
  79. <meta charset="UTF-8">
  80. <script src="../script/jquery.min.js"></script>
  81. <link rel="stylesheet" href="../script/tocas/tocas.css">
  82. <script type='text/javascript' src="../script/tocas/tocas.js"></script>
  83. <script type='text/javascript' src="../script/ao_module.js"></script>
  84. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  85. <title>ArOZ Onlineβ</title>
  86. <style>
  87. body{
  88. background:rgba(245,245,245,0.8);
  89. }
  90. @media (max-width: 767px){
  91. .ts.bottom.right.snackbar.active{
  92. width: 100% !important;
  93. bottom: 0px !important;
  94. right: 0px !important;
  95. }
  96. }
  97. </style>
  98. </head>
  99. <body>
  100. <nav class="ts attached borderless small menu">
  101. <a id="rtiBtn" href="index.php" class="item"><i class="angle left icon"></i></a>
  102. <a href="index.php" class="item">ArOZ Photo</a>
  103. <div class="right menu">
  104. <a onclick="ts('#AddstorageModal').modal('show')" class="item"><i class="add outline icon"></i></a>
  105. <a href="../Upload Manager/upload_interface.php?target=Photo&filetype=jpg,jpeg,png,gif" class="item"><i class="upload icon"></i></a>
  106. <a href="Image_manager.php" class="item"><i class="folder open outline icon"></i></a>
  107. </div>
  108. </nav>
  109. <br>
  110. <div class="ts container">
  111. <div class="ts inverted segment">
  112. <p>Batch moving :
  113. <select class="ts basic dropdown" name="batchfolderdropdown">
  114. <option>Select</option>
  115. </select>
  116. <button name="batchfolderbutton" class="ts button"><i class="move icon"></i>Move</button>
  117. <button onclick="ts('#AddstorageModal').modal('show')" class="ts right floated button"><i class="add icon"></i>New folder</button>
  118. </p>
  119. </div>
  120. <div class="ts stackable grid" id="unsortlist">
  121. </div>
  122. </div>
  123. <div class="ts modals dimmer">
  124. <dialog id="AddstorageModal" class="ts fullscreen modal" open>
  125. <div class="header">
  126. Create new storage
  127. </div>
  128. <div class="content">
  129. <div class="ts form">
  130. <div class="field">
  131. <label>Storage</label>
  132. <select name="storagedropdown">
  133. <option>Select</option>
  134. </select>
  135. </div>
  136. <div class="field">
  137. <label>New storage name</label>
  138. <input type="text" id="storagename">
  139. <small></small>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="actions">
  144. <button class="ts deny button">
  145. Cancel
  146. </button>
  147. <button class="ts positive button" onclick="submit()">
  148. Confirm
  149. </button>
  150. </div>
  151. </dialog>
  152. </div>
  153. <br><br><br><br>
  154. <div class="ts bottom right snackbar">
  155. <div class="content"></div>
  156. </div>
  157. <script>
  158. //Bind enter key to the input bar
  159. $("#storagename").on("keydown",function(e){
  160. if (e.keyCode == 13){
  161. submit();
  162. }
  163. });
  164. //first script to run
  165. $.ajax({url: "Image_manager.php?bkend=true&query=unsort", success: function(result){
  166. var resultArr = JSON.parse(result);
  167. var allfile = "";
  168. $.each(resultArr, function( index, value ) {
  169. if(value["drive"] !== "internal"){
  170. var drivename = '<div class="ts horizontal right floated label"><i class="usb icon"></i>' + value["drive"] + '</div>';
  171. }else{
  172. var drivename = '';
  173. }
  174. $("#unsortlist").append('<div class="four wide column" id="' + value["dir"] + '"><div class="ts card" style="height:100%"><div class="image"><img src="AOB' + value["dir"] + '"><div class="header"><div class="sub header">' + ao_module_codec.decodeUmFilename(value["dir"].replace(/^.*[\\\/]/, '')) + drivename + '</div></div></div><div class="content"><p><i class="move icon"></i>Move to <select class="ts basic dropdown" name="folderdropdown" file="' + value["dir"] + '" storage="' + value["drive"] + '"><option>Select</option></select></p><button name="deletefile" file="' + value["dir"] + '" class="ts mini very compact negative button"><i class="delete icon"></i>Delete</button></div></div></div>');
  175. allfile += value["dir"] + ",";
  176. });
  177. $("select[name='batchfolderdropdown']").attr("file",allfile.substr(0,allfile.length -1));
  178. step2();
  179. }});
  180. function step2(){
  181. $.ajax({url: "Image_manager.php?bkend=true&query=playlist", success: function(result){
  182. var resultArr = JSON.parse(result);
  183. $("select[name='folderdropdown']").html("");
  184. $("select[name='folderdropdown']").append(new Option("Select",""));
  185. $("select[name='batchfolderdropdown']").html("");
  186. $("select[name='batchfolderdropdown']").append(new Option("Select",""));
  187. $.each(resultArr, function( index, value ) {
  188. $("select[name='folderdropdown'][storage='" + value["drive"] + "']").append(new Option(value["name"],value["dir"]));
  189. $("select[name='batchfolderdropdown']").append(new Option(value["name"],value["dir"]));
  190. });
  191. step3();
  192. }});
  193. }
  194. function step3(){
  195. $.ajax({url: "Image_manager.php?bkend=true&query=storage", success: function(result){
  196. var resultArr = JSON.parse(result);
  197. $("select[name='storagedropdown']").html("");
  198. $("select[name='storagedropdown']").append(new Option("Select",""));
  199. $.each(resultArr, function( index, value ) {
  200. $("select[name='storagedropdown']").append(new Option(value,value));
  201. });
  202. }});
  203. step4();
  204. }
  205. function step4(){
  206. $( "button[name='batchfolderbutton']" ).click(function() {
  207. if($("select[name='batchfolderdropdown']").val()!==""){
  208. var Arr = $("select[name='batchfolderdropdown']").attr("file").split(",");
  209. var DOM = $("select[name='batchfolderdropdown']");
  210. var length = Arr.length;
  211. var success = 0;
  212. var failed = 0;
  213. $.each(Arr, function( index, value ) {
  214. if(value!== ""){
  215. $(DOM).parent().parent().parent().append('<div class="ts active inverted dimmer"><div class="ts text loader" id="processingtext">Processing...</div></div>');
  216. $.get( "../SystemAOB/functions/file_system/fsexec.php?opr=move&from=" + value + "&target=" + $(DOM).val() + value.replace(/^.*[\\\/]/, ''), function(UUID) {
  217. //Return an UUID, can call fsexec.php?listen={uuid} to see the file moving progress
  218. if(!UUID.includes("ERROR")){
  219. var timer = setInterval(function(){
  220. $.get( '../SystemAOB/functions/file_system/fsexec.php?listen=["' + UUID + '"]', function(data) {
  221. if(data[0][1] == "done"){
  222. success += 1;
  223. if(success == length){
  224. $("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
  225. $(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
  226. }
  227. if((success + failed) == length){
  228. location.reload();
  229. }
  230. msgbox("Moved " + value.replace(/^.*[\\\/]/, ''));
  231. clearInterval(timer);
  232. }else if(data[0][1] == "error"){
  233. failed += 1;
  234. if((success + failed) == length){
  235. location.reload();
  236. }
  237. msgbox("Error moving " + value.replace(/^.*[\\\/]/, ''));
  238. clearInterval(timer);
  239. }
  240. });
  241. }, 3000);
  242. }else{
  243. failed += 1;
  244. if((success + failed) == length){
  245. location.reload();
  246. }
  247. msgbox(UUID);
  248. }
  249. });
  250. }
  251. });
  252. }else{
  253. msgbox("Nothing selected");
  254. }
  255. });
  256. $( "select[name='folderdropdown']" ).change(function() {
  257. if($(this).val()!==""){
  258. var DOM = $(this);
  259. $(DOM).parent().parent().parent().append('<div class="ts active inverted dimmer"><div class="ts text loader">Processing...</div></div>');
  260. $.get( "../SystemAOB/functions/file_system/fsexec.php?opr=move&from=" + $(this).attr("file") + "&target=" + $(this).val() + $(this).attr("file").replace(/^.*[\\\/]/, ''), function(UUID) {
  261. //Return an UUID, can call fsexec.php?listen={uuid} to see the file moving progress
  262. if(!UUID.includes("ERROR")){
  263. var timer = setInterval(function(){
  264. $.get( '../SystemAOB/functions/file_system/fsexec.php?listen=["' + UUID + '"]', function(data) {
  265. if(data[0][1] == "done"){
  266. $(DOM).parent().parent().parent().parent().fadeOut( "slow", function() {
  267. $(DOM).parent().parent().parent().parent().remove();
  268. if($.trim($("#unsortlist").html()) == ""){
  269. $("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
  270. }
  271. });
  272. $(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
  273. msgbox("Success moving " + $(DOM).attr("file").replace(/^.*[\\\/]/, ''));
  274. clearInterval(timer);
  275. }else if(data[0][1] == "error"){
  276. $(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
  277. msgbox("Error moving " + $(DOM).attr("file").replace(/^.*[\\\/]/, ''));
  278. clearInterval(timer);
  279. }
  280. });
  281. }, 3000);
  282. }else{
  283. $(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
  284. msgbox(UUID);
  285. }
  286. });
  287. /*
  288. $.post( "mover.php", { opr: 1, files: $(this).attr("file"), dir: $(this).val() },function( data ) {
  289. if(data == "DONE"){
  290. $(DOM).parent().parent().parent().parent().parent().fadeOut( "slow", function() {
  291. $(DOM).parent().parent().parent().parent().parent().remove();
  292. if($.trim($("#unsortlist").html()) == ""){
  293. $("#unsortlist").html('<div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div>');
  294. }
  295. });
  296. msgbox("Finished.");
  297. }else{
  298. msgbox("Error.");
  299. }
  300. });
  301. */
  302. }else{
  303. msgbox("Nothing selected");
  304. }
  305. });
  306. $( "button[name='deletefile']" ).click(function() {
  307. var DOM = $(this);
  308. $.post( "mover.php", { opr: 3, files: $(this).attr("file")},function( data ) {
  309. if(data == "DONE"){
  310. $(DOM).parent().parent().parent().parent().parent().fadeOut( "slow", function() {
  311. $(DOM).parent().parent().parent().parent().parent().remove();
  312. if($.trim($("#unsortlist").html()) == ""){
  313. $("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
  314. }
  315. });
  316. msgbox("Finished.");
  317. }else{
  318. msgbox("Error.");
  319. }
  320. });
  321. });
  322. $( "details" ).click(function() {
  323. $("details[open='']").not(this).removeAttr('open');
  324. });
  325. $( ".ts.accordion.item" ).hover(function() {
  326. $(".ts.accordion.item").not(this).removeAttr('style');
  327. $(this).attr('style',"background-color:#f7f7f7");
  328. });
  329. if($.trim($("#unsortlist").html()) == ""){
  330. $("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
  331. }
  332. }
  333. /*
  334. var OldArr = [];
  335. var firstInitOldArr = true;
  336. setInterval(function(){
  337. var notmatch = false;
  338. $.ajax({url: "Image_manager.php?bkend=true&query=unsort", success: function(result){
  339. var resultArr = JSON.parse(result);
  340. if(resultArr.length !== OldArr.length){
  341. notmatch = true;
  342. }else{
  343. for (var i = 0; resultArr.length < i; i++) {
  344. if (resultArr[i] !== oldArr[i]){
  345. notmatch = true;
  346. }
  347. }
  348. }
  349. if(firstInitOldArr){
  350. firstInitOldArr = false;
  351. notmatch = false;
  352. }
  353. if(notmatch){
  354. location.reload();
  355. }
  356. OldArr = resultArr;
  357. }
  358. });
  359. }, 3000);
  360. */
  361. function submit(){
  362. if(storage = $("select[name='storagedropdown']").val() !== ""){
  363. var storage = $("select[name='storagedropdown']").val() + "/";
  364. if(storage == "internal/"){
  365. storage = "storage/";
  366. }
  367. $.post( "new_folder.php", { storage: storage, name : $("#storagename").val() },function( data ) {
  368. if(data == "DONE"){
  369. msgbox("Finished.");
  370. location.reload();
  371. }
  372. });
  373. }else{
  374. msgbox("You must select the directory.");
  375. }
  376. }
  377. function msgbox(content,bgcolor,fontcolor){
  378. $(".snackbar").attr("style",'background-color: ' + bgcolor + ';color:' + fontcolor);
  379. ts('.snackbar').snackbar({
  380. content: content,
  381. onAction: () => {
  382. $(".snackbar").removeAttr("style");
  383. }
  384. });
  385. }
  386. </script>
  387. </body>
  388. </html>