public function movefile() { $fid = isset($_GET['fid']) ? addslashes($_GET['fid']) : 0; // file id $tid = isset($_GET['tid']) ? addslashes($_GET['tid']) : die('no tid'); //folder id $t = addslashes($_GET['t']); $folder = 0; if ($fid === 0) { //move folder $folder = 1; $dff = new DocumentsPortalFolder(); $dff->getByID($tid); $name = $dff->folder_name; $parent = $dff->folder_parent_id; } else { //move file $df = new DocumentsPortal(); $df->getByID($fid); //pr($df); $name = $df->file_url; } echo Lang::t('Selected Item : '); echo " <b>" . $name . "</b> "; ?> <div id="moveselect_<?php echo $fid; ?> _<?php echo $t; ?> " style="margin: 10px;"> <?php /* * get All folder yang bisa di move in, sama ga boleh, children ga boleh * untuk itu harus find its children */ $pf = new DocumentsPortalFolder(); $arrAll = $pf->getAll("ORDER BY folder_name ASC"); $arrByFID = array(); $arrAnak = array(); /* * init all to add fid supaya tidak membebani database */ foreach ($arrAll as $ffs) { $arrByFID[$ffs->folder_id] = $ffs; } $arrParents = array(); foreach ($arrAll as $ffs) { $parentTID = $ffs->folder_id; while ($parentTID > 0) { $parents = $arrByFID[$parentTID]; $arrParents[$ffs->folder_id][] = $parents->folder_id; $parentTID = $parents->folder_parent_id; } } //urutkan spy benar $arrUrut = array(); foreach ($arrAll as $ffs) { if ($folder && in_array($tid, $arrParents[$ffs->folder_id])) { continue; } if (!$folder && $tid == $ffs->folder_id) { continue; } if ($folder && $parent == $ffs->folder_id) { continue; } //find parents $parentname = ""; if (isset($arrByFID[$ffs->folder_parent_id])) { $parentname = "../" . $arrByFID[$ffs->folder_parent_id]->folder_name; } $parentname = "/"; $rev = array_reverse($arrParents[$ffs->folder_id]); $parArr = array(); foreach ($rev as $par) { $parArr[] = $arrByFID[$par]->folder_name; } $parentname = "/" . implode("/", $parArr) . "/"; $arrUrut[$ffs->folder_id] = $parentname; } asort($arrUrut); ?> <div class="input-group"> <select id="moveselecttag_<?php echo $fid; ?> _<?php echo $tid; ?> _<?php echo $t; ?> " class="form-control"> <?php if ($arrByFID[$tid]->folder_parent_id > 0 || !$folder) { ?> <option value="0">/</option> <?php } ?> <?php foreach ($arrUrut as $folder_id => $fpath) { ?> <option value="<?php echo $folder_id; ?> "> <?php echo $fpath; ?> </option> <?php } ?> </select> <span class="input-group-btn"> <button id="moveselectbutton_<?php echo $fid; ?> _<?php echo $tid; ?> _<?php echo $t; ?> " class="btn btn-default" type="button"><?php echo Lang::t('Move'); ?> </button> </span> </div> </div> <script> $("#moveselectbutton_<?php echo $fid; ?> _<?php echo $tid; ?> _<?php echo $t; ?> ").click(function(){ var slc = $("#moveselecttag_<?php echo $fid; ?> _<?php echo $tid; ?> _<?php echo $t; ?> ").val(); <?php if ($folder) { ?> $.get("<?php echo _SPPATH; ?> DMWeb/moveFolder?t=<?php echo $t; ?> &tid=<?php echo $tid; ?> &to="+slc,function(data){ loadfolder_<?php echo $t; ?> (<?php echo $parent; ?> ); loadfolder_<?php echo $t; ?> (slc); //lwrefresh("UploadDoc"); $('#myModal').modal('hide'); }); <?php } else { ?> $.get("<?php echo _SPPATH; ?> DMWeb/moveFileAction?t=<?php echo $t; ?> &tid=<?php echo $tid; ?> &fid=<?php echo $fid; ?> &to="+slc,function(data){ loadfolder_<?php echo $t; ?> (<?php echo $tid; ?> ); loadfolder_<?php echo $t; ?> (slc); //lwrefresh("UploadDoc"); $('#myModal').modal('hide'); }); <?php } ?> }); </script> <?php }