diff --git a/main/work/add_document.php b/main/work/add_document.php index 8560ca8fa9..6a0d74d8ff 100644 --- a/main/work/add_document.php +++ b/main/work/add_document.php @@ -53,13 +53,12 @@ switch ($action) { break; } -Display :: display_header(null); - if (empty($docId)) { - echo Display::page_subheader(get_lang('DocumentsAdded')); + Display :: display_header(null); $documents = getAllDocumentToWork($workId, api_get_course_int_id()); if (!empty($documents)) { + echo Display::page_subheader(get_lang('DocumentsAdded')); echo '
'; foreach ($documents as $doc) { $documentId = $doc['document_id']; @@ -75,11 +74,11 @@ if (empty($docId)) { } $document_tree = DocumentManager::get_document_preview($courseInfo, null, null, 0, false, '/', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId); - echo Display::page_subheader(get_lang('DocumentToAdd')); + echo Display::page_subheader(get_lang('Documents')); echo $document_tree; echo '
'; - } else { + $message = null; $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']); $form = new FormValidator('add_doc', 'post', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId); @@ -89,8 +88,6 @@ if (empty($docId)) { $form->addElement('hidden', 'document_id', $docId); $form->addElement('label', get_lang('File'), $documentInfo['title']); $form->addElement('style_submit_button', 'submit', get_lang('Add')); - $form->display(); - if ($form->validate()) { $values = $form->exportValues(); $workId = $values['id']; @@ -99,14 +96,21 @@ if (empty($docId)) { if (empty($data)) { addDocumentToWork($docId, $workId, api_get_course_int_id()); - Display::display_confirmation_message(get_lang('Added')); + $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId; + header('Location: '.$url); + exit; } else { - Display::display_warning_message(get_lang('DocumentAlreadyAdded')); + $message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning'); } } + + Display :: display_header(null); + echo $message; + $form->display(); } /* + * DB changes needed * CREATE TABLE IF NOT EXISTS c_student_publication_rel_document ( id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, diff --git a/main/work/add_user.php b/main/work/add_user.php index eebca90fdf..30d8610394 100644 --- a/main/work/add_user.php +++ b/main/work/add_user.php @@ -44,7 +44,6 @@ $error_message = null; switch ($action) { case 'add': - $data = getUserToWork($userId, $workId, api_get_course_int_id()); if (empty($data)) { addUserToWork($userId, $workId, api_get_course_int_id()); @@ -52,7 +51,6 @@ switch ($action) { $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?id='.$workId; header('Location: '.$url); exit; - break; case 'delete': if (!empty($workId) && !empty($userId)) { @@ -66,11 +64,10 @@ switch ($action) { Display :: display_header(null); -echo Display::page_subheader(get_lang('UsersAdded')); - $items = getAllUserToWork($workId, api_get_course_int_id()); $usersAdded = array(); if (!empty($items)) { + echo Display::page_subheader(get_lang('UsersAdded')); echo '
'; foreach ($items as $data) { $myUserId = $data['user_id']; diff --git a/main/work/download.php b/main/work/download.php index f1c981c73e..56b88e2201 100644 --- a/main/work/download.php +++ b/main/work/download.php @@ -37,8 +37,8 @@ if (empty($course_info)) { $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION); if (!empty($course_info['real_id'])) { - $sql = 'SELECT * FROM '.$tbl_student_publication.' WHERE c_id = '.$course_info['real_id'].' AND id = "'.$id.'"'; - $result = Database::query($sql); + $sql = 'SELECT * FROM '.$tbl_student_publication.' WHERE c_id = '.$course_info['real_id'].' AND id = "'.$id.'"'; + $result = Database::query($sql); if ($result && Database::num_rows($result)) { $row = Database::fetch_array($result, 'ASSOC'); $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$row['url']; @@ -76,20 +76,24 @@ if (!empty($course_info['real_id'])) { $work_is_visible = ($item_info['visibility'] == 1 && $row['accepted'] == 1); $doc_visible_for_all = ($course_info['show_score'] == 1); - $is_editor = api_is_allowed_to_edit(true,true,true); - $student_is_owner_of_work = ($row['user_id'] == api_get_user_id()); - if ($is_editor - || (!$doc_visible_for_all && $work_is_visible && $student_is_owner_of_work) - || ($doc_visible_for_all && $work_is_visible)) { - $title = str_replace(' ', '_', $row['title']); + $is_editor = api_is_allowed_to_edit(true, true, true); + $student_is_owner_of_work = user_is_author($row['id'], $row['user_id']); + + if ($is_editor + //|| (!$doc_visible_for_all && $work_is_visible && $student_is_owner_of_work) + || ($student_is_owner_of_work) + || ($doc_visible_for_all && $work_is_visible)) { + $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().'/')) { - DocumentManager::file_send_for_download($full_file_name, true, $title); - } - } else { + 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); + } + } else { api_not_allowed(); } - } + } +} else { + api_not_allowed(); } exit; diff --git a/main/work/edit.php b/main/work/edit.php index af2de7447a..f8e52f42a0 100644 --- a/main/work/edit.php +++ b/main/work/edit.php @@ -66,16 +66,18 @@ if (!$is_author) { api_not_allowed(true); } -// Student's can't edit work +// Student's can't edit work only if he can delete his docs. if (!api_is_allowed_to_edit()) { - api_not_allowed(true); + if (api_get_course_setting('student_delete_own_publication') != 1) { + api_not_allowed(true); + } } if (!empty($my_folder_data)) { $homework = get_work_assignment_by_id($my_folder_data['id']); if ($homework['expires_on'] != '0000-00-00 00:00:00' || $homework['ends_on'] != '0000-00-00 00:00:00') { - $time_now = time(); + $time_now = time(); if (!empty($homework['expires_on']) && $homework['expires_on'] != '0000-00-00 00:00:00') { $time_expires = api_strtotime($homework['expires_on'], 'UTC'); @@ -110,13 +112,19 @@ $form_title = get_lang('Edit'); $interbreadcrumb[] = array('url' => '#', 'name' => $form_title); -$form = new FormValidator('form', 'POST', api_get_self()."?".api_get_cidreq()."&id=".$work_id."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&origin=$origin", '', array('enctype' => "multipart/form-data")); +$form = new FormValidator( + 'form', + 'POST', + api_get_self()."?".api_get_cidreq()."&id=".$work_id."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&origin=$origin", + '', + array('enctype' => "multipart/form-data") +); $form->addElement('header', $form_title); $show_progress_bar = false; if ($submitGroupWorkUrl) { - // For user comming from group space to publish his work + // For user coming from group space to publish his work $realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl))); $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl); $text_document = $form->addElement('text', 'document', get_lang('Document')); @@ -129,7 +137,7 @@ if ($submitGroupWorkUrl) { $form->addElement('hidden', 'id', $work_id); $form->addElement('hidden', 'item_id', $item_id); $form->addElement('text', 'title', get_lang('Title'), array('id' => 'file_upload', 'class' => 'span4')); -$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200')); +$form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); $defaults['title'] = $work_item['title']; $defaults["description"] = $work_item['description']; @@ -142,7 +150,7 @@ if ($is_allowed_to_edit && !empty($item_id)) { $row = Database::fetch_array($result); $qualification_over = $row['qualification']; if (!empty($qualification_over) && intval($qualification_over) > 0) { - $form->addElement('text', 'qualification', array(get_lang('Qualification'), null, " / ".$qualification_over), 'size="10"'); + $form->addElement('text', 'qualification', array(get_lang('Qualification'), null, " / ".$qualification_over), 'size="10"'); $form->addElement('hidden', 'qualification_over', $qualification_over); } } @@ -179,27 +187,28 @@ if ($form->validate()) { $work_data = get_work_data_by_id($item_to_edit_id); if (!empty($_POST['title'])) { - $title = isset($_POST['title']) ? $_POST['title'] : $work_data['title']; + $title = isset($_POST['title']) ? $_POST['title'] : $work_data['title']; } $description = isset($_POST['description']) ? $_POST['description'] : $work_data['description']; if ($is_allowed_to_edit && ($_POST['qualification'] !='' )) { - $add_to_update = ', qualificator_id ='."'".api_get_user_id()."',"; + $add_to_update = ', qualificator_id ='."'".api_get_user_id()."', "; $add_to_update .= ' qualification = '."'".Database::escape_string($_POST['qualification'])."',"; - $add_to_update .= ' date_of_qualification ='."'".api_get_utc_datetime()."'"; + $add_to_update .= ' date_of_qualification = '."'".api_get_utc_datetime()."'"; } - if ((int)$_POST['qualification'] > (int)$_POST['qualification_over']) { + if ($_POST['qualification'] > $_POST['qualification_over']) { Display::display_error_message(get_lang('QualificationMustNotBeMoreThanQualificationOver')); } else { $sql = "UPDATE " . $work_table . " - SET title = '" . Database::escape_string($title) . "', - description = '" . Database::escape_string($description) . "' + SET title = '".Database::escape_string($title)."', + description = '".Database::escape_string($description)."' ".$add_to_update." WHERE c_id = $course_id AND id = $item_to_edit_id"; Database::query($sql); } api_item_property_update($_course, 'work', $item_to_edit_id, 'DocumentUpdated', $user_id); + $succeed = true; $error_message .= Display::return_message(get_lang('ItemUpdated'), false); } else { @@ -210,14 +219,13 @@ if ($form->validate()) { } Security::clear_token(); } else { - //Bad token or can't add works + // Bad token or can't add works $error_message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error'); } $script = 'work_list.php'; if ($is_allowed_to_edit) { $script = 'work_list_all.php'; } - header('Location: '.api_get_path(WEB_CODE_PATH).'work/'.$script.'?'.api_get_cidreq().'&id='.$work_id.'&error_message='.$error_message); exit; } diff --git a/main/work/student_work.php b/main/work/student_work.php index b34b815a05..fc2810ba6a 100644 --- a/main/work/student_work.php +++ b/main/work/student_work.php @@ -8,15 +8,11 @@ $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook'); require_once '../inc/global.inc.php'; $current_course_tool = TOOL_STUDENTPUBLICATION; -/* Configuration settings */ - api_protect_course_script(true); -// Including necessary files require_once 'work.lib.php'; $this_section = SECTION_COURSES; -//$workId = isset($_GET['id']) ? intval($_GET['id']) : null; $studentId = isset($_GET['studentId']) ? intval($_GET['studentId']) : null; if (empty($studentId)) { @@ -27,11 +23,14 @@ $tool_name = get_lang('StudentPublications'); $group_id = api_get_group_id(); $userInfo = api_get_user_info($studentId); +$courseInfo = api_get_course_info(); -if (empty($userInfo)) { +if (empty($userInfo) || empty($courseInfo)) { api_not_allowed(true); } +// Only a teachers page. + if (!empty($group_id)) { $group_properties = GroupManager :: get_group_properties($group_id); $show_work = false; @@ -89,11 +88,9 @@ foreach ($workPerUser as $work) { $column++; $table->setCellContents($row, $column, $userResult['sent_date']); $column++; - //$dateQualification = !empty($workExtraData['expires_on']) && $workExtraData['expires_on'] != '0000-00-00 00:00:00' ? api_get_utc_datetime($workExtraData['expires_on']) : '-'; $dateQualification = !empty($workExtraData['expires_on']) && $workExtraData['expires_on'] != '0000-00-00 00:00:00' ? api_get_local_time($workExtraData['expires_on']) : '-'; $table->setCellContents($row, $column, $dateQualification); $column++; - //var_dump($userResult); $score = '-'; if (!empty($scoreWeight)) { $score = strip_tags($userResult['qualification'])."/".$scoreWeight; @@ -104,16 +101,14 @@ foreach ($workPerUser as $work) { // Actions $links = null; - if (empty($userResult['url'])) { - // is a text - $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$userResult['id']; - $links .= Display::url(Display::return_icon('default.png'), $url); - } else { + // is a text + $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$userResult['id']; + $links .= Display::url(Display::return_icon('default.png'), $url); + if (!empty($userResult['url'])) { $url = api_get_path(WEB_CODE_PATH).'work/download.php?'.api_get_cidreq().'&id='.$userResult['id']; - $links .= Display::url(Display::return_icon('save.png'), $url); + $links .= Display::url(Display::return_icon('save.png', get_lang('Download')), $url); } - $url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$userResult['id'].'&id='.$workId.'&parent_id='.$workId; $links .= Display::url(Display::return_icon('edit.png', get_lang('Comment')), $url); diff --git a/main/work/upload.php b/main/work/upload.php index 1ab7a34c5e..669b7fa6e3 100644 --- a/main/work/upload.php +++ b/main/work/upload.php @@ -151,7 +151,7 @@ if ($submitGroupWorkUrl) { $form->addElement('hidden', 'id', $work_id); $form->addElement('hidden', 'contains_file', 0, array('id'=>'contains_file_id')); $form->addElement('text', 'title', get_lang('Title'), array('id' => 'file_upload', 'class' => 'span4')); -$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200')); +$form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); $form->addElement('hidden', 'active', 1); $form->addElement('hidden', 'accepted', 1); @@ -328,7 +328,6 @@ if ($form->validate()) { } $htmlHeadXtra[] = to_javascript_work(); - Display :: display_header(null); if (!empty($work_id)) { diff --git a/main/work/view.php b/main/work/view.php index caa7727fc1..520e9343bb 100644 --- a/main/work/view.php +++ b/main/work/view.php @@ -23,11 +23,17 @@ $course_info = api_get_course_info(); allowOnlySubscribedUser(api_get_user_id(), $work['parent_id'], $course_info['real_id']); if (user_is_author($id) || $course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) { - $url_dir = 'work.php?&id=' . $my_folder_data['id']; - $interbreadcrumb[] = array ('url' => $url_dir,'name' => $my_folder_data['title']); - $interbreadcrumb[] = array ('url' => '#','name' => $work['title']); - - if (($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) || api_is_allowed_to_edit() || ($work['user_id'] == api_get_user_id() && $work['active'] == 1 && $work['accepted'] == 1)) { + if (api_is_allowed_to_edit(null, true)) { + $url_dir = 'work_list_all.php?id='.$my_folder_data['id']; + } else { + $url_dir = 'work_list.php?id='.$my_folder_data['id']; + } + $interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']); + $interbreadcrumb[] = array('url' => '#','name' => $work['title']); + if ( + ($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) || + api_is_allowed_to_edit() || + (user_is_author($id))) { $tpl = new Template(); $tpl->assign('work', $work); $template = $tpl->get_template('work/view.tpl'); @@ -35,6 +41,8 @@ if (user_is_author($id) || $course_info['show_score'] == 0 && $work['active'] == $tpl->assign('content', $content); $tpl->display_one_col_template(); } else { - api_not_allowed(); + api_not_allowed(true); } +} else { + api_not_allowed(true); } diff --git a/main/work/work.lib.php b/main/work/work.lib.php index a194dfe7c6..dc9f5a9996 100644 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -8,7 +8,7 @@ * @author Roan Embrechts, code refactoring and virtual course support * @author Frederic Vauthier, directories management * @author Julio Montoya BeezNest 2011 LOTS of bug fixes - * @todo this lib should be convert in a static class and moved to main/inc/lib + * @todo this lib should be convert in a static class and moved to magein/inc/lib */ /** * Initialization @@ -17,7 +17,11 @@ require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php'; require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; -define('ADD_DOCUMENT_TO_WORK', false); +if (isset($_configuration['add_document_to_work'])) { + define('ADD_DOCUMENT_TO_WORK', $_configuration['add_document_to_work']); +} else { + define('ADD_DOCUMENT_TO_WORK', false); +} /** * Displays action links (for admins, authorized groups members and authorized students) @@ -55,8 +59,6 @@ function display_action_links($id, $cur_dir_path, $action) } } - - if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath' && api_is_allowed_to_session_edit(false, true)) { // Delete all files if (api_get_setting('permanently_remove_deleted_files') == 'true'){ @@ -66,7 +68,6 @@ function display_action_links($id, $cur_dir_path, $action) } } - if ($display_output != '') { echo '
'; echo $display_output; @@ -160,7 +161,6 @@ function display_studentsdelete_form() {
- 0) { $qualification_exists = true; @@ -493,7 +508,6 @@ function display_student_publications_list($id, $my_folder_data, $work_parents, $group_id = api_get_group_id(); - if (is_array($work_parents)) { foreach ($work_parents as $work_parent) { $sql_select_directory = "SELECT @@ -516,7 +530,7 @@ function display_student_publications_list($id, $my_folder_data, $work_parents, } else { $sql_select_directory .= " work.post_group_id = '0' "; } - $sql_select_directory .= " AND ". + $sql_select_directory .= " AND ". " work.c_id = $course_id AND ". " work.id = ".$work_parent->id." AND ". " work.filetype = 'folder' AND ". @@ -595,9 +609,7 @@ function display_student_publications_list($id, $my_folder_data, $work_parents, $weight_input2[] = $form_folder->createElement('text', 'weight'); $form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"'); - $form_folder -> addElement('html', '
'); - $defaults['weight[weight]'] = $link_info['weight']; if (!empty($link_info)) { @@ -620,7 +632,6 @@ function display_student_publications_list($id, $my_folder_data, $work_parents, } else { $homework['expires_on'] = api_get_local_time(); - $expires_date_array = convert_date_to_array(api_get_local_time(), 'expires'); $defaults = array_merge($defaults, $expires_date_array); @@ -847,12 +858,10 @@ function display_student_publications_list($id, $my_folder_data, $work_parents, $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']); - //Work name - //if (api_is_allowed_to_edit()) { - if ($cant_files > 0 ) { - $zip = ''.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL).''; - } - //} + // Work name + if ($cant_files > 0 ) { + $zip = ''.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL).''; + } $link = 'work_list.php'; if (api_is_allowed_to_edit()) { @@ -908,7 +917,7 @@ function display_student_publications_list($id, $my_folder_data, $work_parents, $sorting_options = array(); $sorting_options['column'] = 1; - // Here we change the way how the colums are going to be sorted + // Here we change the way how the columns are going to be sorted // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" @@ -1631,6 +1640,16 @@ function get_count_work($work_id, $onlyMeUserId = null, $notMeUserId = null) return $users_with_work; } +/** + * @param int $start + * @param int $limit + * @param int $column + * @param string $direction + * @param int $work_id + * @param array $where_condition + * @param int $studentId + * @return array + */ function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition, $studentId = null) { $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); @@ -1668,12 +1687,11 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher if ($is_allowed_to_edit) { $extra_conditions .= ' AND work.active IN (0, 1) '; } else { - $extra_conditions .= ' AND work.active IN (1) '; if (isset($course_info['show_score']) && $course_info['show_score'] == 1) { - $extra_conditions .= " AND u.user_id = ".api_get_user_id()." "; + $extra_conditions .= " AND (u.user_id = ".api_get_user_id()." AND work.active IN (0, 1) OR work.active = 1) "; } else { - $extra_conditions .= ''; + $extra_conditions .= ' AND work.active = 1 '; } } @@ -1692,7 +1710,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher } $sql = "SELECT $select - FROM $work_condition $user_condition $course_conditions + FROM $work_condition $user_condition WHERE $extra_conditions $where_condition $condition_session "; $sql .= " ORDER BY $column $direction "; @@ -1702,10 +1720,9 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher $works = array(); while ($work = Database::fetch_array($result, 'ASSOC')) { - //var_dump($work); $item_id = $work['id']; - //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; $can_read = false; @@ -1720,7 +1737,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher $is_author = true; } - if ($course_info['show_score'] == 0 ) { + if ($course_info['show_score'] == 0) { $can_read = true; } @@ -1747,19 +1764,23 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher $add_string = ''; $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC'); + if (!empty($work_assignment['expires_on']) && $work_assignment['expires_on'] != '0000-00-00 00:00:00' && $time_expires && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) { - $add_string = Display::label(get_lang('Expired'),'important'); + $add_string = Display::label(get_lang('Expired'), 'important'); } - if (($can_read && $work['accepted'] == '1') || ($is_author && $work['accepted'] == '1') || $is_allowed_to_edit) { + if ( + ($can_read && $work['accepted'] == '1') || + ($is_author && in_array($work['accepted'], array('1','0'))) || + $is_allowed_to_edit + ) { - //Firstname, lastname, username + // Firstname, lastname, username $work['firstname'] = Display::div($work['firstname'], array('class' => $class)); $work['lastname'] = Display::div($work['lastname'], array('class' => $class)); - //$work['username'] = Display::div($work['username'], array('class' => $class)); if (strlen($work['title']) > 30) { - $short_title = substr($work['title'],0,27).'...'; + $short_title = substr($work['title'], 0, 27).'...'; $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title'])); } else { $work['title'] = Display::div($work['title'], array('class' => $class)); @@ -1774,8 +1795,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher if ($work['contains_file']) { $link_to_download = ''.Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).' '; } else { - //api_get_cidreq() - //$link_to_download = ''.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).' '; + //$link_to_download = ''.Display::return_icon('save_na.png', get_lang('Save'),array(), ICON_SIZE_SMALL).' '; } $send_to = Portfolio::share('work', $work['id'], array('style' => 'white-space:nowrap;')); @@ -1790,6 +1810,9 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher $url = api_get_path(WEB_CODE_PATH).'work/'; $action = ''; if ($is_allowed_to_edit) { + $action .= ''. + Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).' '; + if ($locked) { if ($qualification_exists) { $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'),array(), ICON_SIZE_SMALL); @@ -1805,6 +1828,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).''; } } + if ($work['contains_file']) { if ($locked) { $action .= Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL); @@ -1817,23 +1841,26 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher } else { $action .= ''.Display::return_icon('invisible.png', get_lang('Visible'),array(), ICON_SIZE_SMALL).' '; } + if ($locked) { $action .= Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL); } else { $action .= ''.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).''; } } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) { - if (api_is_allowed_to_session_edit(false, true)) { - //$action .= ''.Display::return_icon('edit.png', get_lang('Modify'),array(), ICON_SIZE_SMALL).''; - $action .= ''. - Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).''; - } else { - $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL); - } + $action .= ''.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).''; + if (api_get_course_setting('student_delete_own_publication') == 1) { + if (api_is_allowed_to_session_edit(false, true)) { + $action .= ''. + Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).''; + } $action .= ' '.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''; + } else { + $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL); } } else { + $action .= ''.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).''; $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL); } @@ -1920,6 +1947,10 @@ function send_email_on_homework_creation($course_id) { } } +/** + * @param string $url + * @return bool + */ function is_work_exist_by_url($url) { $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $url = Database::escape_string($url); @@ -1972,12 +2003,19 @@ function draw_date_picker($prefix, $default = '') { return $date_form; } -function get_date_from_select($prefix) { +function get_date_from_select($prefix) +{ return $_POST[$prefix.'_year'].'-'.two_digits($_POST[$prefix.'_month']).'-'.two_digits($_POST[$prefix.'_day']).' '.two_digits($_POST[$prefix.'_hour']).':'.two_digits($_POST[$prefix.'_minute']).':00'; } -/* Check if a user is the author of the item */ -function user_is_author($item_id, $user_id = null) { +/** + * Check if a user is the author of the item + * @param int $item_id + * @param int $user_id + * @return bool + */ +function user_is_author($item_id, $user_id = null) +{ if (empty($item_id)) { return false; } @@ -1996,6 +2034,7 @@ function user_is_author($item_id, $user_id = null) { $is_author = true; } } + if (!$is_author) { //api_not_allowed(); return false; @@ -2003,7 +2042,6 @@ function user_is_author($item_id, $user_id = null) { return $is_author; } - /** * Get list of users who have not given the task * @param int @@ -2124,7 +2162,11 @@ function display_list_users_without_publication($task_id, $studentId = null) } // Document to work - +/** + * @param int $documentId + * @param int $workId + * @param int $courseId + */ function addDocumentToWork($documentId, $workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); @@ -2136,6 +2178,12 @@ function addDocumentToWork($documentId, $workId, $courseId) Database::insert($table, $params); } +/** + * @param int $documentId + * @param int $workId + * @param int $courseId + * @return array + */ function getDocumentToWork($documentId, $workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); @@ -2145,6 +2193,11 @@ function getDocumentToWork($documentId, $workId, $courseId) return Database::select('*', $table, array('where' => $params)); } +/** + * @param int $workId + * @param int $courseId + * @return array + */ function getAllDocumentToWork($workId, $courseId) { if (ADD_DOCUMENT_TO_WORK == false) { @@ -2157,7 +2210,11 @@ function getAllDocumentToWork($workId, $courseId) return Database::select('*', $table, array('where' => $params)); } - +/** + * @param int $documentId + * @param int $workId + * @param int $courseId + */ function deleteDocumentToWork($documentId, $workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); @@ -2167,9 +2224,11 @@ function deleteDocumentToWork($documentId, $workId, $courseId) Database::delete($table, $params); } -// User to work - - +/** + * @param int $userId + * @param int $workId + * @param int $courseId + */ function addUserToWork($userId, $workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); @@ -2181,6 +2240,12 @@ function addUserToWork($userId, $workId, $courseId) Database::insert($table, $params); } +/** + * @param int $userId + * @param int $workId + * @param int $courseId + * @return array + */ function getUserToWork($userId, $workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); @@ -2190,6 +2255,11 @@ function getUserToWork($userId, $workId, $courseId) return Database::select('*', $table, array('where' => $params)); } +/** + * @param int $workId + * @param int $courseId + * @return array + */ function getAllUserToWork($workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); @@ -2208,7 +2278,11 @@ function userAddedToWork($userId, $workId, $courseId) $result = Database::select('count(*)', $table, array('where' => $params));*/ } - +/** + * @param int $userId + * @param int $workId + * @param int $courseId + */ function deleteUserToWork($userId, $workId, $courseId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); @@ -2218,6 +2292,12 @@ function deleteUserToWork($userId, $workId, $courseId) Database::delete($table, $params); } +/** + * @param int $userId + * @param int $workId + * @param int $courseId + * @return bool + */ function userIsSubscribedToWork($userId, $workId, $courseId) { if (ADD_DOCUMENT_TO_WORK == false) { @@ -2239,6 +2319,12 @@ function userIsSubscribedToWork($userId, $workId, $courseId) return false; } +/** + * @param int $userId + * @param int $workId + * @param int $courseId + * @return bool + */ function allowOnlySubscribedUser($userId, $workId, $courseId) { if (ADD_DOCUMENT_TO_WORK == false) { @@ -2250,9 +2336,13 @@ function allowOnlySubscribedUser($userId, $workId, $courseId) if (userIsSubscribedToWork($userId, $workId, $courseId) == false) { api_not_allowed(true); } - } +/** + * @param int $workId + * @param array $courseInfo + * @return array + */ function getDocumentTemplateFromWork($workId, $courseInfo) { $documents = getAllDocumentToWork($workId, $courseInfo['real_id']); @@ -2270,3 +2360,33 @@ function getDocumentTemplateFromWork($workId, $courseInfo) } return array(); } + +/** + * @param $workId + * @param $courseInfo + */ +function getAllDocumentsFromWorkToString($workId, $courseInfo) +{ + $documents = getAllDocumentToWork($workId, $courseInfo['real_id']); + if (!empty($documents)) { + $docContent = '
'; + echo $docContent; + } +} + +/** + * Returns fckeditor toolbar + * @return array + */ +function getWorkDescriptionToolbar() +{ + return array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '400'); +} diff --git a/main/work/work.php b/main/work/work.php index 3315e6cf2b..59a5a07926 100644 --- a/main/work/work.php +++ b/main/work/work.php @@ -172,7 +172,7 @@ if (!empty($gradebook) && $gradebook == 'view') { } if (!empty($group_id)) { - $group_properties = GroupManager :: get_group_properties($group_id); + $group_properties = GroupManager::get_group_properties($group_id); $show_work = false; if (api_is_allowed_to_edit(false, true)) { @@ -319,8 +319,7 @@ switch ($action) { $form->addElement('text', 'new_dir', get_lang('AssignmentName')); $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required'); - //$form->addElement('html_editor', 'description', get_lang('Description')); - $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200')); + $form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); $form->addElement('advanced_settings', ''.Display::return_icon('div_show.gif',get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')).' '.get_lang('AdvancedParameters').''); @@ -509,17 +508,10 @@ switch ($action) { if ($path = get_work_path($item_id)) { if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) { - //update db + // Update db update_work_url($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']); - api_item_property_update($_course, 'work', $_REQUEST['move_to_id'], 'FolderUpdated', $user_id); - /* - // update all the parents in the table item propery - $list_id = get_parent_directories($move_to_path); - for ($i = 0; $i < count($list_id); $i++) { - api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); - }*/ Display :: display_confirmation_message(get_lang('DirMv')); } else { Display :: display_error_message(get_lang('Impossible')); @@ -549,13 +541,6 @@ switch ($action) { if ($is_allowed_to_edit && $action == 'make_visible') { if (!empty($item_id)) { if (isset($item_id) && $item_id == 'all') { - //never happens - /* - $sql = "ALTER TABLE " . $work_table . " CHANGE accepted accepted TINYINT(1) DEFAULT '1'"; - Database::query($sql); - $sql = "UPDATE " . $work_table . " SET accepted = 1"; - Database::query($sql); - Display::display_confirmation_message(get_lang('AllFilesVisible'));*/ } else { $sql = "UPDATE " . $work_table . " SET accepted = 1 WHERE c_id = $course_id AND id = '" . $item_id . "'"; Database::query($sql); @@ -570,13 +555,6 @@ switch ($action) { /* MAKE INVISIBLE WORK COMMAND */ if (!empty($item_id)) { if (isset($item_id) && $item_id == 'all') { - /* - $sql = "ALTER TABLE " . $work_table . " - CHANGE accepted accepted TINYINT(1) DEFAULT '0'"; - Database::query($sql); - $sql = "UPDATE " . $work_table . " SET accepted = 0"; - Database::query($sql); - Display::display_confirmation_message(get_lang('AllFilesInvisible'));*/ } else { $sql = "UPDATE " . $work_table . " SET accepted = 0 WHERE c_id = $course_id AND id = '" . $item_id . "'"; @@ -741,11 +719,8 @@ switch ($action) { echo $table->toHtml(); echo ''; } else { - - display_student_publications_list($work_id, $my_folder_data, $work_parents, $origin, $add_query, null); } - break; } if ($origin != 'learnpath') { diff --git a/main/work/work_list.php b/main/work/work_list.php index 93c9558ec2..c616929498 100644 --- a/main/work/work_list.php +++ b/main/work/work_list.php @@ -78,26 +78,12 @@ if (!empty($my_folder_data['description'])) { echo '

'.get_lang('Description').':

'.Security::remove_XSS($my_folder_data['description']).'

'; } -$documents = getAllDocumentToWork($workId, $courseInfo['real_id']); -if (!empty($documents)) { - $docContent = '
'; - echo $docContent; -} +echo getAllDocumentsFromWorkToString($workId, $courseInfo); $check_qualification = intval($my_folder_data['qualification']); if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) { $type = 'simple'; - //$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions')); $columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions')); $column_model = array ( array('name'=>'type', 'index'=>'file', 'width'=>'12', 'align'=>'left', 'search' => 'false'), @@ -113,7 +99,6 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) ); } else { $type = 'complex'; - //$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Date'), get_lang('Actions')); $columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'), get_lang('Actions')); $column_model = array ( array('name'=>'type', 'index'=>'file', 'width'=>'12', 'align'=>'left', 'search' => 'false'), @@ -131,10 +116,10 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) $extra_params = array(); -//Autowidth +// Auto width $extra_params['autowidth'] = 'true'; -//height auto +// Height $extra_params['height'] = 'auto'; $extra_params['sortname'] = 'firstname'; diff --git a/main/work/work_list_all.php b/main/work/work_list_all.php index e4f5a4a3bf..aed7325d28 100644 --- a/main/work/work_list_all.php +++ b/main/work/work_list_all.php @@ -73,7 +73,7 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) { echo Display::return_icon('new_document.png', get_lang('AddDocument'), '', ICON_SIZE_MEDIUM).''; echo ''; - echo Display::return_icon('user.png', get_lang('AddUser'), '', ICON_SIZE_MEDIUM).''; + echo Display::return_icon('user.png', get_lang('AddUsers'), '', ICON_SIZE_MEDIUM).''; } $display_output .= ''. @@ -153,6 +153,8 @@ $(function() { api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications')); $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list_others.php?'.api_get_cidreq().'&id='.$workId, 'name' => $my_folder_data['title']); - Display :: display_header(null); echo '
'; @@ -80,46 +76,37 @@ $check_qualification = intval($my_folder_data['qualification']); if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) { $type = 'simple'; - //$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions')); - $columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions')); - $column_model = array ( + $columns = array( + get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions') + ); + $column_model = array( array('name'=>'type', 'index'=>'file', 'width'=>'12', 'align'=>'left', 'search' => 'false'), array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'), array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'), - //array('name'=>'username', 'index'=>'username', 'width'=>'30', 'align'=>'left', 'search' => 'true'), array('name'=>'title', 'index'=>'title', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'wrap_cell' => 'true'), - // array('name'=>'file', 'index'=>'file', 'width'=>'20', 'align'=>'left', 'search' => 'false'), array('name'=>'qualification', 'index'=>'qualification', 'width'=>'20', 'align'=>'left', 'search' => 'true'), - array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'), + array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'), array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30', 'align'=>'left', 'search' => 'true'), array('name'=>'actions', 'index'=>'actions', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'sortable'=>'false') ); } else { $type = 'complex'; - //$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Date'), get_lang('Actions')); - $columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'), get_lang('Actions')); + $columns = array( + get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'), get_lang('Actions') + ); $column_model = array ( array('name'=>'type', 'index'=>'file', 'width'=>'12', 'align'=>'left', 'search' => 'false'), array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'), array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'), - //array('name'=>'username', 'index'=>'username', 'width'=>'30', 'align'=>'left', 'search' => 'true'), array('name'=>'title', 'index'=>'title', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"), - // array('name'=>'file', 'index'=>'file', 'width'=>'20', 'align'=>'left', 'search' => 'false'), - //array('name'=>'qualification', 'index'=>'qualification', 'width'=>'20', 'align'=>'left', 'search' => 'true'), array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'), - //array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30', 'align'=>'left', 'search' => 'true'), array('name'=>'actions', 'index'=>'actions', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'sortable'=>'false') ); } $extra_params = array(); - -//Autowidth $extra_params['autowidth'] = 'true'; - -//height auto $extra_params['height'] = 'auto'; - $extra_params['sortname'] = 'firstname'; $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_user_list_others&work_id='.$workId.'&type='.$type; ?>