$sql = "SELECT `Parent_Template_ID` FROM `Template` WHERE `Template_ID` = {$current_template_id}"; $current_template_id = (int) $db->get_var($sql); if ($current_template_id) { $id_tree[] = $current_template_id; } } while ($current_template_id != 0); } else { $id_tree = array($dragged_id); } $new_file_path = '/' . implode('/', array_reverse($id_tree)); $new_file_path = $db->escape($new_file_path); $sql = "UPDATE `Template` SET `Parent_Template_ID` = {$new_parent_id} WHERE `Template_ID` = {$dragged_id}"; $db->query($sql); nc_update_template_file_path_recursively($dragged_id); $template_folder = rtrim(nc_Core::get_object()->TEMPLATE_FOLDER, '\\/'); nc_move_directory($template_folder . $old_file_path, $template_folder . $new_file_path); } //change priorities $priority = 0; if ($position == 'inside') { $sql = "UPDATE `Template` SET `Priority` = {$priority} WHERE `Template_ID` = {$dragged_id}"; $db->query($sql); $priority++; } $sql = "SELECT `Template_ID` FROM `Template` " . "WHERE `Template_ID` <> {$dragged_id} " . "AND `Parent_Template_ID` = {$new_parent_id} " . "ORDER BY `Priority`, `Template_ID`"; foreach ((array) $db->get_col($sql) as $template_id) { $sql = "UPDATE `Template` SET `Priority` = {$priority} WHERE `Template_ID` = {$template_id}"; $db->query($sql); $priority++; if ($position == 'below' && $target_id == $template_id) { $sql = "UPDATE `Template` SET `Priority` = {$priority} WHERE `Template_ID` = {$dragged_id}";
function nc_move_directory($source, $destination) { $dir = opendir($source); if ($dir) { @mkdir($destination); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($source . '/' . $file)) { nc_move_directory($source . '/' . $file, $destination . '/' . $file); } else { if (copy($source . '/' . $file, $destination . '/' . $file)) { @unlink($source . '/' . $file); } } } } closedir($dir); @rmdir($source); } }