Fixing course copy with works now using ids

skala
Julio Montoya 14 years ago
parent be6e40095b
commit 0623bcfabc
  1. 132
      main/coursecopy/classes/CourseRestorer.class.php
  2. 2
      main/css/base.css
  3. 26
      main/work/download.php
  4. 47
      main/work/downloadfolder.inc.php
  5. 400
      main/work/work.lib.php
  6. 9
      main/work/work.php

@ -174,7 +174,7 @@ class CourseRestorer
if( Database::num_rows($res) == 0) { if( Database::num_rows($res) == 0) {
// The to_group_id and to_user_id are set to default values as users/groups possibly not exist in the target course // The to_group_id and to_user_id are set to default values as users/groups possibly not exist in the target course
$sql = "INSERT INTO $table SET $sql = "INSERT INTO $table SET
c_id = = '".$this->destination_course_id."', c_id = '".$this->destination_course_id."',
tool = '".self::DBUTF8escapestring($property['tool'])."', tool = '".self::DBUTF8escapestring($property['tool'])."',
insert_user_id = '".self::DBUTF8escapestring($property['insert_user_id'])."', insert_user_id = '".self::DBUTF8escapestring($property['insert_user_id'])."',
insert_date = '".self::DBUTF8escapestring($property['insert_date'])."', insert_date = '".self::DBUTF8escapestring($property['insert_date'])."',
@ -233,10 +233,8 @@ class CourseRestorer
$params['category_code'] = $course_info['categoryCode']; $params['category_code'] = $course_info['categoryCode'];
$params['subscribe'] = $course_info['subscribe_allowed']; $params['subscribe'] = $course_info['subscribe_allowed'];
$params['unsubscribe'] = $course_info['unubscribe_allowed']; $params['unsubscribe'] = $course_info['unubscribe_allowed'];
CourseManager::update_attributes($origin_course_info['real_id'], $params);
CourseManager::update_attributes($origin_course_info['real_id'], $params);
} }
/** /**
@ -275,7 +273,7 @@ class CourseRestorer
$new = substr($document->path, 8); $new = substr($document->path, 8);
if (!is_dir($path.'document'.$new)) { if (!is_dir($path.'document'.$new)) {
var_dump($path.'document'.$new); //var_dump($path.'document'.$new);
$created_dir = create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0 ,$path.'document', $new, $title, $visibility); $created_dir = create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0 ,$path.'document', $new, $title, $visibility);
} }
} elseif ($document->file_type == DOCUMENT) { } elseif ($document->file_type == DOCUMENT) {
@ -511,7 +509,14 @@ class CourseRestorer
} }
} }
$sql = "INSERT INTO ".$table." SET c_id = ".$this->destination_course_id.", path = '/".substr($document->path, 9)."', comment = '".self::DBUTF8escapestring($document->comment)."', title = '".self::DBUTF8escapestring($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."', session_id = '$my_session_id'"; $sql = "INSERT INTO ".$table." SET
c_id = ".$this->destination_course_id.",
path = '/".substr($document->path, 9)."',
comment = '".self::DBUTF8escapestring($document->comment)."',
title = '".self::DBUTF8escapestring($document->title)."' ,
filetype='".$document->file_type."',
size= '".$document->size."',
session_id = '$my_session_id'";
Database::query($sql); Database::query($sql);
$document_id = Database::insert_id(); $document_id = Database::insert_id();
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
@ -691,8 +696,7 @@ class CourseRestorer
} }
} }
} }
$sql = "INSERT INTO ".$forum_cat_table. $sql = "INSERT INTO ".$forum_cat_table." SET
" SET
c_id = ".$this->destination_course_id." , c_id = ".$this->destination_course_id." ,
cat_title = '".self::DBUTF8escapestring($title). cat_title = '".self::DBUTF8escapestring($title).
"', cat_comment = '".self::DBUTF8escapestring($forum_cat->description). "', cat_comment = '".self::DBUTF8escapestring($forum_cat->description).
@ -797,7 +801,14 @@ class CourseRestorer
$condition_session = " , session_id = '$session_id' "; $condition_session = " , session_id = '$session_id' ";
} }
$sql = "INSERT INTO ".$link_table." SET c_id = ".$this->destination_course_id." , url = '".self::DBUTF8escapestring($link->url)."', title = '".self::DBUTF8escapestring($link->title)."', description = '".self::DBUTF8escapestring($link->description)."', category_id='".$cat_id."', on_homepage = '".$link->on_homepage."', display_order='".($max_order+1)."' $condition_session"; $sql = "INSERT INTO ".$link_table." SET
c_id = ".$this->destination_course_id." ,
url = '".self::DBUTF8escapestring($link->url)."',
title = '".self::DBUTF8escapestring($link->title)."',
description = '".self::DBUTF8escapestring($link->description)."',
category_id='".$cat_id."',
on_homepage = '".$link->on_homepage."',
display_order='".($max_order+1)."' $condition_session";
Database::query($sql); Database::query($sql);
$this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id();
@ -862,7 +873,12 @@ class CourseRestorer
// check resources inside html from fckeditor tool and copy correct urls into recipient course // check resources inside html from fckeditor tool and copy correct urls into recipient course
$event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course($event->content, $this->course->code, $this->course->destination_path); $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course($event->content, $this->course->code, $this->course->destination_path);
$sql = "INSERT INTO ".$table." SET c_id = ".$this->destination_course_id." , title = '".self::DBUTF8escapestring($event->title)."', content = '".self::DBUTF8escapestring($event->content)."', start_date = '".$event->start_date."', end_date = '".$event->end_date."'"; $sql = "INSERT INTO ".$table." SET
c_id = ".$this->destination_course_id." ,
title = '".self::DBUTF8escapestring($event->title)."',
content = '".self::DBUTF8escapestring($event->content)."',
start_date = '".$event->start_date."',
end_date = '".$event->end_date."'";
Database::query($sql); Database::query($sql);
$new_event_id = Database::insert_id(); $new_event_id = Database::insert_id();
$this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
@ -1615,74 +1631,70 @@ class CourseRestorer
* @todo I fixed this crappy function jmontoya * @todo I fixed this crappy function jmontoya
*/ */
function restore_student_publication() { function restore_student_publication() {
$work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$my_tbl_db_spa_origin = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT, $this->course->db_name);
$my_tbl_db_spa_destination = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$my_tbl_db_origin = Database :: get_course_table(TABLE_STUDENT_PUBLICATION, $this->course->db_name);
$my_tbl_db_destination = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$my_tbl_db_item_property_origin = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->db_name);
$my_tbl_db_item_property_destination = Database :: get_course_table(TABLE_ITEM_PROPERTY);
//query in student publication //query in student publication
/* $query_sql_fin_sp='INSERT IGNORE INTO '.$my_tbl_db_destination.' (c_id, id,url,title,description,author,active,accepted,post_group_id,sent_date,' . /* $query_sql_fin_sp='INSERT IGNORE INTO '.$my_tbl_db_destination.' (c_id, id,url,title,description,author,active,accepted,post_group_id,sent_date,' .
'filetype,has_properties,view_properties,qualification,date_of_qualification,' . 'filetype,has_properties,view_properties,qualification,date_of_qualification,' .
'parent_id,qualificator_id,session_id) '; 'parent_id,qualificator_id,session_id) ';
*/ */
$sql ='SELECT c_id, id,url,title,description,author,active,accepted,post_group_id,' . $sql = 'SELECT c_id, id, url, title,description,author,active,accepted,post_group_id, sent_date,filetype,has_properties,view_properties,qualification,date_of_qualification,qualificator_id,session_id
'sent_date,filetype,has_properties,view_properties,qualification,date_of_qualification,' . FROM '.$work_table.'
'parent_id,qualificator_id,session_id FROM '.$work_table.' WHERE c_id = '.$this->course_origin_id.' AND filetype="folder" '; WHERE c_id = '.$this->course_origin_id.' AND filetype="folder" AND active IN (0, 1) ';
$result = Database::query($sql); $result = Database::query($sql);
$folders = Database::store_result($result, 'ASSOC'); $folders = Database::store_result($result, 'ASSOC');
foreach($folders as $folder) {
foreach ($folders as $folder) {
$old_id = $folder['id'];
unset($folder['id']);
$folder['c_id'] = $this->destination_course_id; $folder['c_id'] = $this->destination_course_id;
Database::insert($work_table, $folder); $folder['parent_id'] = 0;
$new_id = Database::insert($work_table, $folder);
if ($new_id) {
//query in item property
$sql = 'SELECT tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type, lastedit_user_id,to_group_id,to_user_id,visibility,start_visible, end_visible
FROM '.$item_property_table.' ip INNER JOIN '.$work_table.' sp ON ip.ref=sp.id
WHERE sp.c_id = '.$this->course_origin_id.' AND
ip.c_id = '.$this->course_origin_id.' AND
tool="work" AND sp.id = '.$old_id.'';
$result = Database::query($sql);
$sub_folders = Database::store_result($result, 'ASSOC');
foreach ($sub_folders as $sub_folder) {
$sub_folder['c_id'] = $this->destination_course_id;
$sub_folder['ref'] = $new_id;
$new_item_id = Database::insert($item_property_table, $sub_folder);
}
$sql = 'SELECT sa.id, sa.expires_on,sa.ends_on,sa.add_to_calendar, sa.enable_qualification, sa.publication_id
FROM '.$work_assignment_table.' sa INNER JOIN '.$work_table.' sp ON sa.publication_id=sp.id
WHERE sp.c_id = '.$this->course_origin_id.' AND
sa.c_id = '.$this->course_origin_id.' AND
filetype="folder" AND sp.id = '.$old_id.'';
$result = Database::query($sql);
$assing_list = Database::store_result($result, 'ASSOC');
foreach($assing_list as $assign) {
$assign['c_id'] = $this->destination_course_id;
$assign['id'] = $new_id;
Database::insert($work_assignment_table, $assign);
}
}
} }
$destination='../../courses/'.$this->course->destination_path.'/work/'; $destination='../../courses/'.$this->course->destination_path.'/work/';
$origin='../../courses/'.$this->course->info['path'].'/work/'; $origin='../../courses/'.$this->course->info['path'].'/work/';
self::allow_create_all_directory($origin,$destination,false); self::allow_create_all_directory($origin,$destination,false);
//query in item property
/*$query_sql_fin_ip='INSERT IGNORE INTO '.$my_tbl_db_item_property_destination.'' .
'(tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,' .
'to_user_id,visibility,start_visible,end_visible) ';*/
$query_sql_ini_ip='SELECT tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,' .
'lastedit_user_id,to_group_id,to_user_id,visibility,start_visible,
end_visible FROM '.$item_property_table.' ip INNER JOIN '.$work_table.' sp' .
' ON ip.ref=sp.id WHERE c_id = '.$this->course_origin_id.' AND tool="work" ';
$result = Database::query($sql);
$folders = Database::store_result($result, 'ASSOC');
foreach($folders as $folder) {
$folder['c_id'] = $this->destination_course_id;
Database::insert($item_property_table, $folder);
}
/*$query_sql_fin_sa='INSERT IGNORE INTO '.$my_tbl_db_spa_destination.'' .
'(id,expires_on,ends_on,add_to_calendar,enable_qualification,publication_id) ';*/
$sql = 'SELECT sa.id,sa.expires_on,sa.ends_on,sa.add_to_calendar,sa.enable_qualification,sa.publication_id FROM '.$work_assignment_table.' sa INNER JOIN '.$work_table.' sp
ON sa.publication_id=sp.id WHERE c_id = '.$this->course_origin_id.' AND filetype="folder" ';
$result = Database::query($sql);
$folders = Database::store_result($result, 'ASSOC');
foreach($folders as $folder) {
$folder['c_id'] = $this->destination_course_id;
Database::insert($work_assignment_table, $folder);
}
} }

@ -2959,7 +2959,7 @@ input.maininput:focus {
float: left; float: left;
height: auto; height: auto;
margin: 10px 8px 15px 15px; margin: 10px 8px 15px 15px;
padding: 20px; padding: 18px;
} }
/* Makes the course elements more readable */ /* Makes the course elements more readable */

@ -25,12 +25,7 @@ header('Pragma: no-cache');
//protection //protection
api_protect_course_script(true); api_protect_course_script(true);
$doc_url = $_GET['file']; $id = $_GET['id'];
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
$course_info = api_get_course_info(); $course_info = api_get_course_info();
@ -38,24 +33,23 @@ if (empty($course_info)) {
api_not_allowed(true); api_not_allowed(true);
} }
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$doc_url;
$tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
// launch event $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
event_download($doc_url);
if (!empty($_course['real_id'])) { if (!empty($course_info['real_id'])) {
$doc_url = Database::escape_string($doc_url); $sql = 'SELECT * FROM '.$tbl_student_publication.' WHERE c_id = '.$course_info['real_id'].' AND id = "'.$id.'"';
$sql = 'SELECT * FROM '.$tbl_student_publication.' WHERE c_id = '.$_course['real_id'].' AND url LIKE BINARY "'.$doc_url.'"';
$result = Database::query($sql); $result = Database::query($sql);
if ($result && Database::num_rows($result)) { if ($result && Database::num_rows($result)) {
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
$item_info = api_get_item_property_info(api_get_course_int_id(), 'work', $row['id']); $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$row['url'];
$item_info = api_get_item_property_info(api_get_course_int_id(), 'work', $row['id']);
if (empty($item_info)) { if (empty($item_info)) {
exit; exit;
} }
if ($item_info['visibility'] == 1 && $row['accepted'] == 1 && ($row['user_id'] == api_get_user_id() || api_is_allowed_to_edit())) { if ($item_info['visibility'] == 1 && $row['accepted'] == 1 && ($row['user_id'] == api_get_user_id() || api_is_allowed_to_edit())) {
$title = str_replace(' ', '_', $row['title']); $title = str_replace(' ', '_', $row['title']);
event_download($title);
if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')) { if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')) {
DocumentManager::file_send_for_download($full_file_name, true, $title); DocumentManager::file_send_for_download($full_file_name, true, $title);
} }

@ -7,7 +7,12 @@
* @package chamilo.work * @package chamilo.work
*/ */
$path = $_GET['path']; $work_id = $_GET['id'];
$work_data = get_work_data_by_id($work_id);
if (empty($work_data)) {
exit;
}
//prevent some stuff //prevent some stuff
if (empty($path)) { if (empty($path)) {
@ -38,17 +43,16 @@ $prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$files = array(); $files = array();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
//set the path that will be used in the query
if ($path == '/') {
$querypath = ''; // to prevent ...path LIKE '//%'... in query
} else {
$querypath = $path;
}
//search for all files that are not deleted => visibility != 2 //search for all files that are not deleted => visibility != 2
$querypath = Database::escape_string($querypath);
$sql = "SELECT url, title FROM $tbl_student_publication AS work, $prop_table AS props $sql = "SELECT url, title FROM $tbl_student_publication AS work, $prop_table AS props
WHERE props.c_id = $course_id AND work.c_id = $course_id AND props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'2'"; WHERE props.c_id = $course_id AND
work.c_id = $course_id AND
props.tool='work' AND
work.id=props.ref AND
work.parent_id = $work_id AND
work.filetype='file' AND props.visibility<>'2'";
$query = Database::query($sql); $query = Database::query($sql);
//add tem to the zip file //add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query)) { while ($not_deleted_file = Database::fetch_assoc($query)) {
@ -59,16 +63,14 @@ if (api_is_allowed_to_edit()) {
} }
} else { } else {
//for other users, we need to create a zipfile with only visible files and folders //for other users, we need to create a zipfile with only visible files and folders
if ($path == '/') {
$querypath = ''; // to prevent ...path LIKE '//%'... in query
} else {
$querypath = $path;
}
$querypath = Database::escape_string($querypath);
$sql = "SELECT url, title FROM $tbl_student_publication AS work, $prop_table AS props $sql = "SELECT url, title FROM $tbl_student_publication AS work, $prop_table AS props
WHERE props.c_id = $course_id AND work.c_id = $course_id AND props.tool='work' AND work.accepted = 1 AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND WHERE props.c_id = $course_id AND work.c_id = $course_id AND
props.visibility = '1' AND props.insert_user_id='".api_get_user_id()."' "; props.tool='work' AND
work.accepted = 1 AND
work.id=props.ref AND
work.parent_id = $work_id AND
work.filetype='file' AND
props.visibility = '1' AND props.insert_user_id='".api_get_user_id()."' ";
$query = Database::query($sql); $query = Database::query($sql);
//add tem to the zip file //add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query)) { while ($not_deleted_file = Database::fetch_assoc($query)) {
@ -81,13 +83,12 @@ if (api_is_allowed_to_edit()) {
}//end for other users }//end for other users
//logging //logging
event_download(basename($path).'.zip (folder)'); event_download(basename($work_data['title']).'.zip (folder)');
//start download of created file //start download of created file
$name = basename($path).'.zip'; $name = basename($work_data['title']).'.zip';
if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) { if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) {
DocumentManager::file_send_for_download($temp_zip_file, true, $name); DocumentManager::file_send_for_download($temp_zip_file, true, $name);
@unlink($temp_zip_file); @unlink($temp_zip_file);
exit; exit;

@ -318,8 +318,7 @@ function get_work_assignment_by_id($id) {
*/ */
function display_student_publications_list($id, $link_target_parameter, $dateFormatLong, $origin, $add_in_where_query = '') { function display_student_publications_list($id, $link_target_parameter, $dateFormatLong, $origin, $add_in_where_query = '') {
global $timeNoSecFormat, $dateFormatShort, $gradebook, $_course;
global $timeNoSecFormat, $dateFormatShort, $gradebook, $_user, $_course;
// Database table names // Database table names
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -352,86 +351,84 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$my_params = $sort_params; $my_params = $sort_params;
$origin = Security::remove_XSS($origin); $origin = Security::remove_XSS($origin);
// Getting the work data // Getting the work data
$my_folder_data = get_work_data_by_id($id); $my_folder_data = get_work_data_by_id($id);
$work_in_gradebook_link_id = is_resource_in_course_gradebook(api_get_course_id(), 3 , $id, api_get_session_id()); if (empty($my_folder_data)) {
if ($work_in_gradebook_link_id) { $work_in_gradebook_link_id = is_resource_in_course_gradebook(api_get_course_id(), 3 , $id, api_get_session_id());
if ($is_allowed_to_edit) if ($work_in_gradebook_link_id) {
if (intval($my_folder_data['qualification']) == 0) { if ($is_allowed_to_edit)
Display::display_warning_message(get_lang('MaxWeightNeedToBeProvided')); if (intval($my_folder_data['qualification']) == 0) {
} Display::display_warning_message(get_lang('MaxWeightNeedToBeProvided'));
} }
}
$qualification_exists = false; $qualification_exists = false;
if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) { if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) {
$qualification_exists = true; $qualification_exists = true;
} }
$work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work'; $work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work';
$sub_course_dir = '';
if (!empty($my_folder_data)) {
if (!empty($my_folder_data)) { $work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work'.$my_folder_data['url'];
$work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work'.$my_folder_data['url']; }
$sub_course_dir = 'work' .$my_folder_data['url'];
} $contains_file_query = '';
if (substr($sub_course_dir, -1, 1) != '/' && !empty($sub_course_dir)) {
$sub_course_dir = $sub_course_dir.'/'; //Get list from database
} if ($is_allowed_to_edit) {
if ($sub_course_dir == '/') { $active_condition = ' active IN (0, 1)';
$sub_course_dir = ''; $sql_get_publications_list = "SELECT * FROM $work_table
} WHERE c_id = $course_id $add_in_where_query $condition_session AND $active_condition AND
( parent_id = 0)
$contains_file_query = ''; $contains_file_query
$parent_id = isset($my_folder_data['id']) ? $my_folder_data['id'] : 0; ORDER BY sent_date DESC";
} else {
if (!empty($sub_course_dir)) { if (!empty($_SESSION['toolgroup'])) {
$contains_file_query = " OR (contains_file = 0 AND parent_id = $parent_id ) "; $group_query = " WHERE c_id = $course_id AND post_group_id = '".intval($_SESSION['toolgroup'])."' "; // set to select only messages posted by the user's group
} $subdirs_query = "AND parent_id = 0";
} else {
//Get list from database $group_query = " WHERE c_id = $course_id AND post_group_id = '0' ";
if ($is_allowed_to_edit) { $subdirs_query = "AND parent_id = 0";
$active_condition = ' active IN (0, 1)'; }
$sql_get_publications_list = "SELECT * FROM $work_table //@todo how we can active or not an assignment?
WHERE c_id = $course_id $add_in_where_query $condition_session AND $active_condition AND $active_condition = ' AND active IN (1,0)';
( contains_file = 1 AND parent_id = $parent_id) $sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session ORDER BY title";
$contains_file_query }
ORDER BY sent_date DESC";
$work_parents = array();
$sql_get_publications_num = "SELECT count(*) FROM ".$work_table." $sql_result = Database::query($sql_get_publications_list);
WHERE c_id = $course_id $add_in_where_query $condition_session AND $active_condition AND if (Database::num_rows($sql_result)) {
( contains_file = 1 AND parent_id = $parent_id ) while ($work = Database::fetch_object($sql_result)) {
$contains_file_query if ($work->parent_id == 0) {
ORDER BY sent_date DESC"; $work_parents[] = $work;
} else { }
if (!empty($_SESSION['toolgroup'])) { }
$group_query = " WHERE c_id = $course_id AND post_group_id = '".intval($_SESSION['toolgroup'])."' "; // set to select only messages posted by the user's group }
$subdirs_query = "AND parent_id = $parent_id"; } else {
} else { $parent_id = isset($my_folder_data['id']) ? $my_folder_data['id'] : 0;
$group_query = " WHERE c_id = $course_id AND post_group_id = '0' "; if (!empty($_SESSION['toolgroup'])) {
$subdirs_query = "AND parent_id = $parent_id"; $group_query = " WHERE c_id = $course_id AND post_group_id = '".intval($_SESSION['toolgroup'])."' "; // set to select only messages posted by the user's group
} $subdirs_query = "AND parent_id = $parent_id ";
} else {
$active_condition = ' AND active IN (1)'; $group_query = " WHERE c_id = $course_id AND post_group_id = '0' ";
$subdirs_query = "AND parent_id = $parent_id";
$sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session ORDER BY id"; }
$sql_get_publications_num = "SELECT count(url) FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session $subdirs_query .= " AND user_id = ".api_get_user_id()." ";
ORDER BY id"; $active_condition = ' AND active IN (1)';
}
$sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session ORDER BY title";
//echo $sql_get_publications_list; $sql_result = Database::query($sql_get_publications_list);
//echo $sql_get_publications_num; }
$sql_result = Database::query($sql_get_publications_list);
$sql_result_num = Database::query($sql_get_publications_num);
$edit_dir = isset($_GET['edit_dir']) ? $_GET['edit_dir'] : '';
$row = Database::fetch_array($sql_result_num);
$count_files = $row[0];
$table_header = array(); $table_header = array();
$table_has_actions_column = false; $table_has_actions_column = false;
$table_header[] = array(get_lang('Type'), false, 'style="width:40px"'); $table_header[] = array(get_lang('Type'), false, 'style="width:40px"');
$table_header[] = array(get_lang('Title'), true); $table_header[] = array(get_lang('Title'), true);
if ($count_files != 0) { if (!empty($id)) {
$table_header[] = array(get_lang('FirstName'), true); $table_header[] = array(get_lang('FirstName'), true);
$table_header[] = array(get_lang('LastName'), true); $table_header[] = array(get_lang('LastName'), true);
if ($qualification_exists) { if ($qualification_exists) {
@ -449,26 +446,12 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
//$table_header[] = array('RealDate', true); //$table_header[] = array('RealDate', true);
$table_data = array(); $table_data = array();
$dirs_list = get_subdirs_list($work_dir);
$my_sub_dir = str_replace('work/', '', $sub_course_dir);
$course_info = CourseManager::get_course_information(api_get_course_id());
$edit_dir = isset($_GET['edit_dir']) ? $_GET['edit_dir'] : '';
// @todo Since "works" cant have sub works this foreach is useless when selecting the list of works
// List of all folders // List of all folders
if (is_array($dirs_list)) {
foreach ($dirs_list as $dir) { if (is_array($work_parents)) {
if ($my_sub_dir == '') { foreach ($work_parents as $work_parent) {
$mydir_temp = '/'.$dir;
} else {
$mydir_temp = '/'.$my_sub_dir.$dir;
}
$sql_select_directory = "SELECT title, prop.insert_date, prop.lastedit_date, work.id, author, has_properties, view_properties, description, qualification, weight, allow_text_assignment $sql_select_directory = "SELECT title, prop.insert_date, prop.lastedit_date, work.id, author, has_properties, view_properties, description, qualification, weight, allow_text_assignment
FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id)
WHERE active IN (0, 1) AND "; WHERE active IN (0, 1) AND ";
@ -477,12 +460,14 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$sql_select_directory .= " work.post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group $sql_select_directory .= " work.post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group
} else { } else {
$sql_select_directory .= " work.post_group_id = '0' "; $sql_select_directory .= " work.post_group_id = '0' ";
} }
$sql_select_directory .= " AND prop.c_id = $course_id AND
$sql_select_directory .= " AND prop.c_id = $course_id AND work.c_id = $course_id AND work.url LIKE BINARY '".$mydir_temp."' AND work.filetype = 'folder' AND prop.tool='work' $condition_session"; work.c_id = $course_id AND
work.id = ".$work_parent->id." AND
work.filetype = 'folder' AND
prop.tool='work' $condition_session";
$result = Database::query($sql_select_directory); $result = Database::query($sql_select_directory);
$row = Database::fetch_array($result); $row = Database::fetch_array($result, 'ASSOC');
if (!$row) { if (!$row) {
// the folder belongs to another session // the folder belongs to another session
@ -492,23 +477,21 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$author = $row['author']; //directory's author $author = $row['author']; //directory's author
$view_properties = $row['view_properties']; $view_properties = $row['view_properties'];
$is_assignment = $row['has_properties']; $is_assignment = $row['has_properties'];
$id2 = $row['id']; $id2 = $row['id']; //work id
$mydir = $my_sub_dir.$dir;
if ($is_allowed_to_edit) { if ($is_allowed_to_edit) {
// form edit directory // form edit directory
if (isset($edit_dir) && $edit_dir == $mydir) { if (!empty($edit_dir) && $edit_dir == $id2) {
if (!empty($row['has_properties'])) { if (!empty($row['has_properties'])) {
$sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE c_id = '.$course_id.' AND id = "'.$row['has_properties'].'" LIMIT 1'); $sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE c_id = '.$course_id.' AND id = "'.$row['has_properties'].'" LIMIT 1');
$homework = Database::fetch_array($sql); $homework = Database::fetch_array($sql);
} }
$form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2);
$form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?curdirpath='.$my_sub_dir.'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$mydir);
$group_name[] = FormValidator :: createElement('text', 'dir_name'); $group_name[] = FormValidator :: createElement('text', 'dir_name');
$form_folder -> addGroup($group_name, 'my_group', get_lang('Title')); $form_folder -> addGroup($group_name, 'my_group', get_lang('Title'));
$form_folder->addElement('hidden', 'work_id', $row['id']); $form_folder->addElement('hidden', 'work_id', $id2);
$form_folder -> addGroupRule('my_group', get_lang('ThisFieldIsRequired'), 'required'); $form_folder -> addGroupRule('my_group', get_lang('ThisFieldIsRequired'), 'required');
$defaults = array('my_group[dir_name]' => Security::remove_XSS($row['title']), 'description' => Security::remove_XSS($row['description'])); $defaults = array('my_group[dir_name]' => Security::remove_XSS($row['title']), 'description' => Security::remove_XSS($row['description']));
@ -606,10 +589,8 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
} }
$form_folder -> addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments')); $form_folder -> addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
$form_folder -> addElement('html', '</div>');
$form_folder -> addElement('html', '</div>');
$form_folder -> addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"'); $form_folder -> addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"');
if ($there_is_a_end_date) { if ($there_is_a_end_date) {
@ -703,8 +684,8 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
add_resource_to_course_gradebook(api_get_course_id(), 3, $row['id'], $resource_name, (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], $_POST['description'] , time(), 1, api_get_session_id()); add_resource_to_course_gradebook(api_get_course_id(), 3, $row['id'], $resource_name, (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], $_POST['description'] , time(), 1, api_get_session_id());
} }
update_dir_name($work_data['id'], $mydir, $dir_name, $values['dir_name']); update_dir_name($work_data, $dir_name, $values['dir_name']);
$mydir = $my_sub_dir.$dir_name;
$dir = $dir_name; $dir = $dir_name;
$display_edit_form = false; $display_edit_form = false;
@ -738,7 +719,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
} }
} }
$work_data = get_work_data_by_path('/'.$dir); $work_data = get_work_data_by_id($work_parent->id);
$action = ''; $action = '';
$row = array(); $row = array();
@ -755,16 +736,16 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$sql_document = "SELECT count(*) FROM $work_table WHERE c_id = $course_id AND parent_id = ".$work_data['id']." AND active IN (0, 1) "; $sql_document = "SELECT count(*) FROM $work_table WHERE c_id = $course_id AND parent_id = ".$work_data['id']." AND active IN (0, 1) ";
} else { } else {
$sql_document = "SELECT count(*) FROM $work_table s, $iprop_table p $sql_document = "SELECT count(*) FROM $work_table s, $iprop_table p
WHERE s.c_id = $course_id AND WHERE s.c_id = $course_id AND
p.c_id = $course_id AND p.c_id = $course_id AND
s.id = p.ref AND s.id = p.ref AND
p.tool='work' AND p.tool='work' AND
s.accepted='1' AND s.accepted='1' AND
user_id = ".api_get_user_id()." AND user_id = ".api_get_user_id()." AND
parent_id = ".$work_data['id']." AND parent_id = ".$work_data['id']." AND
active = 1 AND active = 1 AND
url LIKE 'work/".$dir."/%'"; parent_id = ".$work_parent->id."";
} }
//count documents //count documents
@ -780,11 +761,11 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$icon = Display::return_icon('work.png', get_lang('Assignment'), array(), 22); $icon = Display::return_icon('work.png', get_lang('Assignment'), array(), 22);
if (!empty($display_edit_form) && isset($edit_dir) && $edit_dir == $mydir) { if (!empty($display_edit_form) && !empty($edit_dir) && $edit_dir == $id2) {
$row[] = $icon; $row[] = $icon;
$row[] = '<span class="invisible" style="display:none">'.$dir.'</span>'.$form_folder->toHtml(); // form to edit the directory's name $row[] = '<span class="invisible" style="display:none">'.$dir.'</span>'.$form_folder->toHtml(); // form to edit the directory's name
} else { } else {
$row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&curdirpath='.$mydir.'">'.$icon.'</a>'; $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'">'.$icon.'</a>';
$add_to_name = ''; $add_to_name = '';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
@ -800,29 +781,17 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$add_to_name = ''; $add_to_name = '';
} }
$work_id_exists = get_work_id($mydir); //true or false
$work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']); $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']);
//Work name //Work name
if (api_is_allowed_to_edit()) {
if (!empty($work_id_exists)) { $zip = '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&gradebook='.$gradebook.'&action=downloadfolder&id='.$work_data['id'].'">
'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), 22).'</a>';
if (api_is_allowed_to_edit()) { }
$zip = '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&gradebook='.$gradebook.'&action=downloadfolder&path=/'.$mydir.'"> $url = $zip.'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&id='.$work_data['id'].'"'.$class.'>'.
'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), 22).'</a>'; $work_title.'</a>'.
} $add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
$row[] = $url;
$url = $zip.'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&id='.$work_data['id'].'"'.$class.'>'.
$work_title.'</a>'.
$add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
$row[] = $url;
} else {
$url = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&id='.$work_data['id'].'"'.$class.'>'.$work_title.'</a>'.
$add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
$row[] = $url;
}
} }
if ($count_files != 0) { if ($count_files != 0) {
$row[] = ''; $row[] = '';
@ -838,30 +807,28 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
if ($is_allowed_to_edit) { if ($is_allowed_to_edit) {
$action .= '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&curdirpath='.$my_sub_dir.'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$mydir.'">'.Display::return_icon('edit.png', get_lang('Modify'), array(), 22).'</a>'; $action .= '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2.'">'.Display::return_icon('edit.png', get_lang('Modify'), array(), 22).'</a>';
$action .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&delete_dir='.$mydir.'&delete2='.$id2.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('DirDelete').'" >'.Display::return_icon('delete.png',get_lang('DirDelete'),'',22).'</a>'; $action .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&delete_dir='.$id2.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('DirDelete').'" >'.Display::return_icon('delete.png',get_lang('DirDelete'),'',22).'</a>';
$row[] = $action; $row[] = $action;
} else { } else {
$row[] = ''; $row[] = '';
} }
} }
$row[] = $direc_date_local; $row[] = $direc_date_local;
$row[] = $work_data['title'];
$table_data[] = $row; $table_data[] = $row;
} }
} }
//Redefining $my_sub_dir
if (substr($my_sub_dir,strlen($my_sub_dir)-1, strlen($my_sub_dir)) == '/') {
$my_sub_dir = substr($my_sub_dir, 0,strlen($my_sub_dir)-1);
}
$my_assignment = get_work_assignment_by_id($id); $my_assignment = get_work_assignment_by_id($id);
if (Database::num_rows($sql_result) > 0) { if (Database::num_rows($sql_result) > 0) {
while ($work = Database::fetch_object($sql_result)) { while ($work = Database::fetch_object($sql_result)) {
//Get the author ID for that document from the item_property table //Get the author ID for that document from the item_property table
$is_author = false; $is_author = false;
$item_property_data = api_get_item_property_info(api_get_course_int_id(), 'work', $work->id, api_get_session_id()); $item_property_data = api_get_item_property_info(api_get_course_int_id(), 'work', $work->id, api_get_session_id());
if (!$is_allowed_to_edit && $item_property_data['insert_user_id'] == api_get_user_id()) { if (!$is_allowed_to_edit && $item_property_data['insert_user_id'] == api_get_user_id()) {
$is_author = true; $is_author = true;
} }
@ -869,7 +836,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
//display info depending on the permissions //display info depending on the permissions
if ($is_author && $work->accepted == '1' || $is_allowed_to_edit) { if ($is_author && $work->accepted == '1' || $is_allowed_to_edit) {
$row = array(); $row = array();
if ($work->accepted == '0') { if ($work->accepted == '0') {
$class = 'class="invisible"'; $class = 'class="invisible"';
@ -892,12 +859,9 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$add_string = ' <b style="color:red">'.get_lang('Expired').'</b>'; $add_string = ' <b style="color:red">'.get_lang('Expired').'</b>';
} }
} }
$row[] = '<a href="download.php?id='.$work->id.'">'.build_document_icon_tag('file', substr(basename($work->url), 13)).'</a>';
$url = implode('/', array_map('rawurlencode', explode('/', $work->url)));
$row[] = '<a href="download.php?file='.$url.'">'.build_document_icon_tag('file', substr(basename($work->url), 13)).'</a>';
if ($work->contains_file) { if ($work->contains_file) {
$row[] = '<a href="download.php?file='.$url.'"'.$class.'>'.Display::return_icon('save.png', get_lang('Save'),array('style' => 'float:right;'), 22).' '.$work->title.'</a><br />'.$work->description; $row[] = '<a href="download.php?id='.$work->id.'"'.$class.'>'.Display::return_icon('save.png', get_lang('Save'),array('style' => 'float:right;'), 22).' '.$work->title.'</a><br />'.$work->description;
} else { } else {
$row[] = '<a href="view.php?id='.$work->id.'"'.$class.'>'.$work->title.'</a><br />'.$work->description; $row[] = '<a href="view.php?id='.$work->id.'"'.$class.'>'.$work->title.'</a><br />'.$work->description;
} }
@ -918,14 +882,14 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
Display::return_icon('rate_work.png', get_lang('CorrectAndRate'),array(), 22).'</a>'; Display::return_icon('rate_work.png', get_lang('CorrectAndRate'),array(), 22).'</a>';
} }
if ($work->contains_file) { if ($work->contains_file) {
$action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;action=move&item_id='.$work->id.'" title="'.get_lang('Move').'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>'; $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&origin='.$origin.'&gradebook='.$gradebook.'&amp;action=move&item_id='.$work->id.'" title="'.get_lang('Move').'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
} }
if ($work->accepted == '1') { if ($work->accepted == '1') {
$action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;action=make_invisible&item_id='.$work->id.'&amp;'.$sort_params.'" title="'.get_lang('Invisible').'" >'.Display::return_icon('visible.png', get_lang('Invisible'),array(), 22).'</a>'; $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&origin='.$origin.'&gradebook='.$gradebook.'&amp;action=make_invisible&item_id='.$work->id.'&amp;'.$sort_params.'" title="'.get_lang('Invisible').'" >'.Display::return_icon('visible.png', get_lang('Invisible'),array(), 22).'</a>';
} else { } else {
$action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;action=make_visible&item_id='.$work->id.'&amp;'.$sort_params.'" title="'.get_lang('Visible').'" >'.Display::return_icon('invisible.png', get_lang('Visible'),array(), 22).'</a> '; $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&origin='.$origin.'&gradebook='.$gradebook.'&amp;action=make_visible&item_id='.$work->id.'&amp;'.$sort_params.'" title="'.get_lang('Visible').'" >'.Display::return_icon('invisible.png', get_lang('Visible'),array(), 22).'</a> ';
} }
$action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('WorkDelete').'" >'.Display::return_icon('delete.png', get_lang('WorkDelete'),'',22).'</a>'; $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&origin='.$origin.'&gradebook='.$gradebook.'&amp;delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('WorkDelete').'" >'.Display::return_icon('delete.png', get_lang('WorkDelete'),'',22).'</a>';
$row[] = $action; $row[] = $action;
// the user that is not course admin can only edit/delete own document // the user that is not course admin can only edit/delete own document
@ -935,15 +899,16 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$table_has_actions_column = true; $table_has_actions_column = true;
} }
$action = ''; $action = '';
$action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&curdirpath='.urlencode($my_sub_dir).'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;action=mark_work&item_id='.$work->id.'" title="'.get_lang('Modify').'" >'.Display::return_icon('edit.png', get_lang('Modify'),array(), 22).'</a>'; $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;action=mark_work&item_id='.$work->id.'" title="'.get_lang('Modify').'" >'.Display::return_icon('edit.png', get_lang('Modify'),array(), 22).'</a>';
if (api_get_course_setting('student_delete_own_publication') == 1) { if (api_get_course_setting('student_delete_own_publication') == 1) {
$action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&curdirpath='.urlencode($my_sub_dir).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('WorkDelete').'" >'.Display::return_icon('delete.png',get_lang('WorkDelete'),'',22).'</a>'; $action .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$my_folder_data['id'].'&origin='.$origin.'&gradebook='.$gradebook.'&delete='.$work->id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('WorkDelete').'" >'.Display::return_icon('delete.png',get_lang('WorkDelete'),'',22).'</a>';
} }
$row[] = $action; $row[] = $action;
} else { } else {
$row[] = ' '; $row[] = ' ';
} }
$row[] = $work_sent_date_local; $row[] = $work_sent_date_local;
$table_data[] = $row; $table_data[] = $row;
} }
} }
@ -962,27 +927,25 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$column_order[$i] = $i; $column_order[$i] = $i;
$i++; $i++;
} }
if (empty($my_folder_data)) {
if ($count_files != 0) { $column_order[1] = 5;
$column_order[2] = 2;
} else { } else {
$column_order[2] = 4; $column_order[2] = 2;
} }
// An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
$column_show = array(); $column_show = array();
$column_show[] = 1; // type $column_show[] = 1; // type 0
$column_show[] = 1; // title $column_show[] = 1; // title 1
if ($count_files != 0) { if (!empty($my_folder_data)) {
$column_show[] = 1; // firstname $column_show[] = 1; // 2
$column_show[] = 1; // lastname $column_show[] = 1; // 3
if ($qualification_exists) { if ($qualification_exists) {
$column_show[] = 1; // qualification $column_show[] = 1; // 4
} }
} }
$column_show[] = 1; //date $column_show[] = 1; //date
if ($table_has_actions_column) { if ($table_has_actions_column) {
$column_show[] = 1; // modify $column_show[] = 1; // modify
@ -997,13 +960,16 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$my_params = array ('id' => isset($_GET['id']) ? $_GET['id'] : null); $my_params = array ('id' => isset($_GET['id']) ? $_GET['id'] : null);
if (isset($_GET['edit_dir'])) { if (isset($_GET['edit_dir'])) {
$my_params = array ('edit_dir' => Security::remove_XSS($_GET['edit_dir'])); $my_params = array ('edit_dir' => intval($_GET['edit_dir']));
} }
$my_params['origin'] = $origin; $my_params['origin'] = $origin;
Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order); Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order);
} }
function get_work_list() {
}
/** /**
* Returns a list of subdirectories found in the given directory. * Returns a list of subdirectories found in the given directory.
* *
@ -1205,38 +1171,44 @@ function create_unexisting_work_directory($base_work_dir, $desired_dir_name) {
* @param string The directory name as the bit after "work/", without trailing slash * @param string The directory name as the bit after "work/", without trailing slash
* @return integer -1 on error * @return integer -1 on error
*/ */
function del_dir($base_work_dir, $dir, $id) { function del_dir($id) {
$id = intval($id); global $_course;
if (empty($dir) or $dir == '/') { $id = intval($id);
return -1; $work_data = get_work_data_by_id($id);
}
$check = Security::check_abs_path($base_work_dir.$dir, $base_work_dir); if (empty($work_data)) {
if (!$check || !is_dir($base_work_dir.$dir)) { return false;
return -1; }
}
$base_work_dir = api_get_path(SYS_COURSE_PATH) .$_course['path'].'/work';
$work_data_url = $base_work_dir.$work_data['url'];
$check = Security::check_abs_path($work_data_url.'/', $base_work_dir.'/');
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
//Deleting the folder
$url_path = get_work_path($id); if (!empty($work_data['url'])) {
if (!empty($url_path) && $url_path != -1) {
//Deleting all contents inside the folder //Deleting all contents inside the folder
//@todo replace to parent_id //@todo replace to parent_id
$sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND url LIKE BINARY 'work/".$dir."/%'"; $sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND filetype = 'folder' AND id = $id";
$res = Database::query($sql);
$sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND filetype = 'folder' AND id = $id";
$res = Database::query($sql); $res = Database::query($sql);
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; $sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND parent_id = $id";
$new_dir = $dir.'_DELETED_'.$id; $res = Database::query($sql);
if (api_get_setting('permanently_remove_deleted_files') == 'true'){
my_delete($base_work_dir.$dir); if ($check) {
} else { require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
if (file_exists($base_work_dir.$dir)) { $new_dir = $work_data_url.'_DELETED_'.$id;
rename($base_work_dir.$dir, $base_work_dir.$new_dir); if (api_get_setting('permanently_remove_deleted_files') == 'true'){
} my_delete($work_data_url);
} } else {
if (file_exists($work_data_url)) {
rename($work_data_url, $new_dir);
}
}
}
} }
} }
@ -1286,9 +1258,15 @@ function update_work_url($id, $new_path, $parent_id) {
* @param string old path * @param string old path
* @param string new path * @param string new path
*/ */
function update_dir_name($work_id, $path, $new_name, $title) { function update_dir_name($work_data, $new_name, $title) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$work_id = intval($work_id); $work_id = intval($work_data['id']);
$path = $work_data['url'];
if ($work_data['title'] == $title) {
return true;
}
$title = Database::escape_string($title); $title = Database::escape_string($title);
if (!empty($new_name)) { if (!empty($new_name)) {
@ -1303,7 +1281,6 @@ function update_dir_name($work_id, $path, $new_name, $title) {
$new_name = Security::remove_XSS($new_name); $new_name = Security::remove_XSS($new_name);
$new_name = replace_dangerous_char($new_name); $new_name = replace_dangerous_char($new_name);
$new_name = disable_dangerous_file($new_name); $new_name = disable_dangerous_file($new_name);
my_rename($base_work_dir.'/'.$path, $new_name); my_rename($base_work_dir.'/'.$path, $new_name);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
@ -1816,9 +1793,6 @@ function is_work_exist_by_url($url) {
} }
} }
function make_select($name, $values, $checked = '') { function make_select($name, $values, $checked = '') {
$output = '<select name="'.$name.'" id="'.$name.'">'; $output = '<select name="'.$name.'" id="'.$name.'">';
foreach($values as $key => $value) { foreach($values as $key => $value) {

@ -1107,14 +1107,11 @@ switch ($action) {
/* Delete dir command */ /* Delete dir command */
if (!empty($_REQUEST['delete_dir'])) { if (!empty($_REQUEST['delete_dir'])) {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed(); api_not_allowed();
} }
$delete_directory = $_REQUEST['delete_dir']; del_dir($_REQUEST['delete_dir']);
$id = $_REQUEST['delete2'];
del_dir($base_work_dir . '/', $delete_directory, $id);
Display :: display_confirmation_message(get_lang('DirDeleted') . ': '.$delete_directory); Display :: display_confirmation_message(get_lang('DirDeleted') . ': '.$delete_directory);
} }

Loading…
Cancel
Save