diff --git a/backend/TE/AppDB.php b/backend/TE/AppDB.php index 27ec2fb3c2a0193b6a9eb56f8f5723f4e282e0d4..a5818d5113fd26de57bc361a2befb0636fcb9fa9 100644 --- a/backend/TE/AppDB.php +++ b/backend/TE/AppDB.php @@ -638,7 +638,7 @@ class AppDB_TE extends AppDB } // Folders - public function getFolders( $countExercises = false, $showPersonal = false, $folderID = NULL ) + public function getFolders( $countExercises = false, $showPersonal = false, $folderID = NULL, $subFolders = NULL, $notFolder = NULL ) { $select = 'folder.id, folder.name'; $from = 'folder'; @@ -664,18 +664,29 @@ class AppDB_TE extends AppDB if( Application::get('subfolders') ) { - if( $where == '' ) - $where = 'WHERE'; - else - $where .= ' and'; - - - if( $folderID != NULL ) - $where .= " folder.childof =". $folderID; - else - $where .= " folder.childof IS NULL"; + if( $subFolders == NULL ) + { + if( $where == '' ) + $where = 'WHERE'; + else + $where .= ' and'; + + + if( $folderID != NULL ) + $where .= " folder.childof =". $folderID; + else + $where .= " folder.childof IS NULL"; + } } + if( $notFolder != NULL ) + { + if( $where == '' ) + $where = "WHERE folder.id != " . ( int ) $notFolder; + else + $where .= " AND folder.id != " . ( int ) $notFolder; + } + $res = $this->query( "SELECT " . $select . " FROM " . $from . " " . $where . " " . $group . " ORDER BY folder.name ASC;" ); if( ! $_SESSION[ 'user' ][ 'isadmin' ] ) @@ -853,6 +864,13 @@ class AppDB_TE extends AppDB $this->commitTransaction(); return $id; } + public function moveFolder( $id, $tofolder ) + { + $this->checkAdmin(); + $this->beginTransaction(); + $this->query( "UPDATE folder SET childof=" . ( int ) $tofolder . " WHERE id=" . ( int ) $id . ";" ); + $this->commitTransaction(); + } public function setFolderACL( $id, $acl ) { $this->checkAdmin(); diff --git a/js/backend.js b/js/backend.js index 7fb5cf5e1e1de2523385d4d0737f5d9bb524d7d8..ea9d0eb7f61c0441ab7d5f9001f6170bd90524c9 100644 --- a/js/backend.js +++ b/js/backend.js @@ -684,6 +684,7 @@ function Pianos4Backend(params) ['Rename', onEditFolder, params.icons.exercise], '--', ['Create new folder', onCreateNewFolder, params.icons.folder[0]], + ['Move folder', onMoveFolder, params.icons.management], ['Delete folder', onDeleteFolder, params.icons._delete] @@ -802,7 +803,134 @@ function Pianos4Backend(params) Pianos4Backend.showFormDialog(dlgopts); } + + var onMoveFolder = function( item ) + { + var pushmodification = function( id, tofolder ) + { + $.ajax( { + url: '?action=rpc&method=moveFolder', + data: { + id: id, + tofolder: tofolder + }, + type: "POST", + dataType: 'json', + success: function( data ) + { + if( ! data.error ) + { + toastr.success( "Folder moved" ); + location.reload(); + + } else { + toastr.error( data.message, "Server side error" ); + } + }, + error: function( data ) + { + toastr.error( "Network error" ); + } + } ); + } + + var movefolderui = $( '
' ) + .css( 'padding-top', '20px' ); + + $( '
' ) + .text( "Move folder to:" ) + .append( + $( '
' ) + .css( 'height', '100%' ) + .css( 'width', '100%' ) + .css( 'margin-top', '2em' ) + .append( $( '