Image_manager.php 15 KB

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