diff --git a/main/work/work.lib.php b/main/work/work.lib.php
index b9fdaf5a65..77537185e5 100755
--- a/main/work/work.lib.php
+++ b/main/work/work.lib.php
@@ -888,6 +888,7 @@ function build_work_directory_selector($folders, $curdirpath, $group_dir = '') {
*/
function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
//gets file title
+
$move_file = intval($move_file);
$tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT title FROM $tbl_work WHERE id ='".$move_file."'";
@@ -908,29 +909,29 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d
//group documents cannot be uploaded in the root
if ($group_dir == '') {
if ($curdirpath != '/') {
- $form .= '';
+ $form .= '';
}
if (is_array($folders)) {
- foreach ($folders as $folder) {
+ foreach ($folders as $fid => $folder) {
//you cannot move a file to:
//1. current directory
//2. inside the folder you want to move
//3. inside a subfolder of the folder you want to move
if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
- $form .= ''."\n";
+ $form .= ''."\n";
}
}
}
} else {
if ($curdirpath != '/') {
- $form .= '';
+ $form .= '';
}
- foreach ($folders as $folder) {
+ foreach ($folders as $fid => $folder) {
if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
//cannot copy dir into his own subdir
$display_folder = substr($folder, strlen($group_dir));
$display_folder = ($display_folder == '') ? '/ ('.get_lang('Root').')' : $display_folder;
- $form .= ''."\n";
+ $form .= ''."\n";
}
}
}
@@ -1054,7 +1055,7 @@ function get_work_path($id) {
* @param string Destination directory where the work has been moved (must end with a '/')
* @return -1 on error, sql query result on success
*/
-function update_work_url($id, $new_path) {
+function update_work_url($id, $new_path, $parent_id) {
if (empty($id)) return -1;
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT * FROM $table WHERE id=$id";
@@ -1064,8 +1065,8 @@ function update_work_url($id, $new_path) {
} else {
$row = Database::fetch_array($res);
$filename = basename($row['url']);
- $new_url = $new_path.$filename;
- $sql2 = "UPDATE $table SET url = '$new_url' WHERE id=$id";
+ $new_url = $new_path .$filename;
+ $sql2 = "UPDATE $table SET url = '$new_url', parent_id = '$parent_id' WHERE id=$id";
$res2 = Database::query($sql2);
return $res2;
}
@@ -1429,9 +1430,10 @@ function get_list_users_without_publication($task_id) {
$session_id = api_get_session_id();
if (!empty($session_id)){
- $sql = "SELECT C.id_user as id FROM $work_table AS S, $session_course_rel_user AS C, $iprop_table AS I WHERE C.id_user=I.insert_user_id and S.id=I.ref and S.parent_id='$task_id' and course_code='".api_get_course_id()."' and S.session_id='".$session_id."'";
+ $sql = "SELECT user_id as id FROM $work_table WHERE parent_id='$task_id' and session_id='".$session_id."'";
+
} else {
- $sql = "SELECT C.user_id as id FROM $work_table AS S, $table_course_user AS C, $iprop_table AS I WHERE C.user_id=I.insert_user_id and S.id=I.ref and C.status=5 and S.parent_id='$task_id' and course_code='".api_get_course_id()."'";
+ $sql = "SELECT user_id as id FROM $work_table WHERE parent_id='$task_id'";
}
$result = Database::query($sql);
$users_with_tasks = array();
@@ -1444,6 +1446,7 @@ function get_list_users_without_publication($task_id) {
} else {
$sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u WHERE cu.status!=1 and cu.course_code='".api_get_course_id()."' AND u.user_id=cu.user_id";
}
+
$result_users = Database::query($sql_users);
$users_without_tasks = array();
while ($row_users = Database::fetch_row($result_users)) {
diff --git a/main/work/work.php b/main/work/work.php
index f669449763..d552654114 100755
--- a/main/work/work.php
+++ b/main/work/work.php
@@ -561,7 +561,7 @@ if (!empty($_REQUEST['new_dir'])) {
session_id = ".intval($id_session);
Database::query($sql_add_publication);
-
+
// add the directory
$id = Database::insert_id();
//Folder created
@@ -674,10 +674,13 @@ if (!empty($_REQUEST['delete2'])) {
if (!empty ($_REQUEST['move'])) {
$folders = array();
- $sql = "SELECT url FROM $work_table WHERE url LIKE '/%' AND post_group_id = '".(empty($_SESSION['toolgroup'])?0:intval($_SESSION['toolgroup']))."'";
+ $session_id = api_get_session_id();
+ $session_id == 0 ? $withsession = " AND session_id = 0 " : $withsession = " AND session_id='".$session_id."'";
+
+ $sql = "SELECT id, url FROM $work_table WHERE url LIKE '/%' AND post_group_id = '".(empty($_SESSION['toolgroup'])?0:intval($_SESSION['toolgroup']))."'".$withsession;
$res = Database::query($sql);
while($folder = Database::fetch_array($res)) {
- $folders[] = substr($folder['url'], 1, strlen($folder['url']) - 1);
+ $folders[$folder['id']] = substr($folder['url'], 1, strlen($folder['url']) - 1);
}
echo build_work_move_to_selector($folders, $cur_dir_path, $_REQUEST['move']);
}
@@ -687,21 +690,28 @@ if (!empty ($_REQUEST['move'])) {
if (isset ($_POST['move_to']) && isset ($_POST['move_file'])) {
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
$move_to = $_POST['move_to'];
- if ($move_to == '/' or empty ($move_to)) {
- $move_to = '';
- } elseif (substr($move_to, -1, 1) != '/') {
- $move_to = $move_to . '/';
- }
+ $move_to_path = get_work_path($move_to);
+
+// var_dump($move_to_path);
+
+ if ($move_to_path==-1) {
+ $move_to_path = '/';
+ } elseif (substr($move_to_path, -1, 1) != '/') {
+ $move_to_path = $move_to_path .'/';
+ }
//security fix: make sure they can't move files that are not in the document table
- if ($path = get_work_path($_POST['move_file'])) {
+ $move_file_id = intval($_POST['move_file']);
+ if ($path = get_work_path($move_file_id)) {
//Display::display_normal_message('We want to move '.$_POST['move_file'].' to '.$_POST['move_to']);
- if (move($course_dir . '/' . $path, $base_work_dir . '/' . $move_to)) {
+ //var_dump($base_work_dir . $move_to_path);
+ if (move($course_dir . '/' . $path, $base_work_dir . $move_to_path)) {
//update db
- update_work_url($_POST['move_file'], 'work/' . $move_to);
+
+ update_work_url($move_file_id, 'work' . $move_to_path, $move_to);
//set the current path
- $cur_dir_path = $move_to;
- $cur_dir_path_url = urlencode($move_to);
+ $cur_dir_path = $move_to_path;
+ $cur_dir_path_url = urlencode($move_to_path);
// update all the parents in the table item propery
$list_id = get_parent_directories($cur_dir_path);
@@ -875,6 +885,8 @@ if ($ctok == $_POST['sec_token']) { //check the token inserted into the form
$current_date = date('Y-m-d H:i:s');
$parent_id = '';
$active = '';
+ $user_id = api_get_user_id();
+
$sql = Database::query('SELECT id FROM '.Database::get_course_table(TABLE_STUDENT_PUBLICATION).' WHERE url = '."'/".Database::escape_string($_GET['curdirpath'])."' AND filetype='folder' LIMIT 1");
if (Database::num_rows($sql) > 0) {
$dir_row = Database::fetch_array($sql);
@@ -890,7 +902,8 @@ if ($ctok == $_POST['sec_token']) { //check the token inserted into the form
post_group_id = '" . $post_group_id . "',
sent_date = '".$current_date ."',
parent_id = '".$parent_id ."' ,
- session_id = ".intval($id_session);
+ session_id = '".intval($id_session)."' ,
+ user_id = '".$user_id."'";
Database::query($sql_add_publication);
@@ -935,7 +948,8 @@ if ($ctok == $_POST['sec_token']) { //check the token inserted into the form
author = '" . Database::escape_string($authors) . "',
post_group_id = '".$post_group_id."',
sent_date = '".$current_date."',
- session_id = ".intval($id_session);
+ session_id = '".intval($id_session)."',
+ user_id = '".$user_id."'";
Database::query($sql);