diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 3df01582f4..8a11130857 100644 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -26,16 +26,16 @@ require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc. */ function display_action_links($id, $cur_dir_path, $show_tool_options, $display_upload_link, $action) { global $gradebook; - + $id = $my_back_id = intval($id); if ($action == 'list') { $my_back_id = 0; } - + $display_output = ''; - $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : ''; - - if (!empty($id)) { + $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : ''; + + if (!empty($id)) { $display_output .= ''.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).''; } @@ -68,7 +68,7 @@ function display_action_links($id, $cur_dir_path, $show_tool_options, $display_u if (api_is_allowed_to_edit(null, true)) { global $token; - + if (!empty($id)) { if (empty($_GET['list']) or Security::remove_XSS($_GET['list']) == 'with') { $display_output .= ''. @@ -106,12 +106,12 @@ function display_action_links($id, $cur_dir_path, $show_tool_options, $display_u * * @param $uploadvisibledisabled * @param $origin - + */ function display_tool_options($uploadvisibledisabled, $origin) { global $gradebook; $is_allowed_to_edit = api_is_allowed_to_edit(null, true); - + if (!$is_allowed_to_edit) { return; } @@ -178,10 +178,10 @@ function display_studentsdelete_form() { + @@ -283,14 +283,14 @@ function get_work_count_by_student($user_id, $work_id) { $work_id = intval($work_id); $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); - + $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $sql = "SELECT COUNT(*) as count FROM $work_table + $sql = "SELECT COUNT(*) as count FROM $work_table WHERE c_id = $course_id AND parent_id = $work_id AND user_id = $user_id AND active = 1 AND session_id = $session_id "; $result = Database::query($sql); $return = 0; if (Database::num_rows($result)) { - $return = Database::fetch_row($result,'ASSOC'); + $return = Database::fetch_row($result,'ASSOC'); $return = intval($return[0]); } return $return; @@ -324,17 +324,17 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $user_table = Database::get_main_table(TABLE_MAIN_USER); $work_assigment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); - + $is_allowed_to_edit = api_is_allowed_to_edit(null, true); - - $user_id = api_get_user_id(); + + $user_id = api_get_user_id(); $session_id = api_get_session_id(); - $condition_session = api_get_session_condition($session_id); + $condition_session = api_get_session_condition($session_id); $course_id = api_get_course_int_id(); $group_id = api_get_group_id(); - + $course_info = api_get_course_info(api_get_course_id()); - + $sort_params = array(); if (isset($_GET['column'])) { @@ -353,66 +353,66 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $my_params = $sort_params; $origin = Security::remove_XSS($origin); - // Getting the work data - $my_folder_data = get_work_data_by_id($id); - + // Getting the work data + $my_folder_data = get_work_data_by_id($id); + $qualification_exists = false; if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) { $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'; if (!empty($my_folder_data)) { $work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work'.$my_folder_data['url']; } - + if (empty($my_folder_data)) { $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $id, api_get_session_id()); $work_in_gradebook_link_id = $link_info['id']; - + if ($work_in_gradebook_link_id) { if ($is_allowed_to_edit) if (intval($my_folder_data['qualification']) == 0) { Display::display_warning_message(get_lang('MaxWeightNeedToBeProvided')); } - } - $contains_file_query = ''; - + } + $contains_file_query = ''; + //Get list from database if ($is_allowed_to_edit) { - $active_condition = ' active IN (0, 1)'; + $active_condition = ' active IN (0, 1)'; $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 ". " ORDER BY sent_date DESC"; - } else { + } else { if (!empty($group_id)) { $group_query = " WHERE c_id = $course_id AND post_group_id = '".$group_id."' "; // set to select only messages posted by the user's group $subdirs_query = "AND parent_id = 0"; } else { $group_query = " WHERE c_id = $course_id AND post_group_id = '0' "; $subdirs_query = "AND parent_id = 0"; - } - //@todo how we can active or not an assignment? - $active_condition = ' AND active IN (1,0)'; - $sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session ORDER BY title"; + } + //@todo how we can active or not an assignment? + $active_condition = ' AND active IN (1,0)'; + $sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query $add_in_where_query $active_condition $condition_session ORDER BY title"; } - - $work_parents = array(); - + + $work_parents = array(); + $sql_result = Database::query($sql_get_publications_list); - if (Database::num_rows($sql_result)) { + if (Database::num_rows($sql_result)) { while ($work = Database::fetch_object($sql_result)) { if ($work->parent_id == 0) { $work_parents[] = $work; } } - } - } - - $edit_dir = isset($_GET['edit_dir']) ? $_GET['edit_dir'] : ''; - + } + } + + $edit_dir = isset($_GET['edit_dir']) ? $_GET['edit_dir'] : ''; + $table_header = array(); $table_has_actions_column = false; $table_header[] = array(get_lang('Type'), false, 'style="width:40px"'); @@ -425,7 +425,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $table_header[] = array(get_lang('Qualification'), true); } } - + $table_header[] = array(get_lang('Date'), true, 'style="width:200px"'); if ($is_allowed_to_edit) { @@ -438,83 +438,83 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $table_data = array(); // List of all folders if no id was provided - + $group_id = api_get_group_id(); - - if (is_array($work_parents)) { - foreach ($work_parents as $work_parent) { + + if (is_array($work_parents)) { + foreach ($work_parents as $work_parent) { $sql_select_directory = "SELECT title, url, 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 AND prop.c_id = $course_id ) ". " WHERE active IN (0, 1) AND "; - + if (!empty($group_id)) { $sql_select_directory .= " work.post_group_id = '".$group_id."' "; // set to select only messages posted by the user's group } else { $sql_select_directory .= " work.post_group_id = '0' "; - } + } $sql_select_directory .= " AND ". " work.c_id = $course_id AND ". " work.id = ".$work_parent->id." AND ". " work.filetype = 'folder' AND ". - " prop.tool='work' $condition_session"; + " prop.tool='work' $condition_session"; $result = Database::query($sql_select_directory); $row = Database::fetch_array($result, 'ASSOC'); - + if (!$row) { // the folder belongs to another session continue; } - $direc_date = $row['lastedit_date']; //directory's date - $author = $row['author']; //directory's author + $direc_date = $row['lastedit_date']; //directory's date + $author = $row['author']; //directory's author $view_properties = $row['view_properties']; $is_assignment = $row['has_properties']; $id2 = $row['id']; //work id $locked = api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION); - + if ($is_allowed_to_edit && $locked == false) { // form edit directory - + if (!empty($edit_dir) && $edit_dir == $id2) { - + if (!empty($row['has_properties'])) { $sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE c_id = '.$course_id.' AND id = "'.$row['has_properties'].'" LIMIT 1'); $homework = Database::fetch_array($sql); } - $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2); - $form_folder->addElement('text', 'dir_name', get_lang('Title')); + $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2); + $form_folder->addElement('text', 'dir_name', get_lang('Title')); $form_folder->addElement('hidden', 'work_id', $id2); $form_folder -> addRule('dir_name', get_lang('ThisFieldIsRequired'), 'required'); - + $my_title = !empty($row['title']) ? $row['title'] : basename($row['url']); - + $defaults = array('dir_name' => Security::remove_XSS($my_title), 'description' => Security::remove_XSS($row['description'])); $form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'work', 'Width' => '80%', 'Height' => '200')); - $there_is_a_end_date = false; + $there_is_a_end_date = false; $form_folder -> addElement('advanced_settings', '    '.get_lang('AdvancedParameters').' '); $form_folder->addElement('html', ''); + } + if ($homework['ends_on'] != '0000-00-00 00:00:00') { $homework['ends_on'] = api_get_local_time($homework['ends_on']); $there_is_a_end_date = true; - + $defaults['enableEndDate'] = true; - + $form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"'); $form_folder -> addElement('html', '
'); $form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt')); $form_folder -> addElement('html', '
'); $form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); - + } else { $homework['ends_on'] = api_get_local_time(); - + $expires_date_array = convert_date_to_array(api_get_local_time(), 'ends'); $defaults = array_merge($defaults, $expires_date_array); - + $there_is_a_end_date = false; - + $form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"'); $form_folder -> addElement('html', ''); $form_folder -> addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"'); - + if ($there_is_a_end_date) { $end_date_array = convert_date_to_array($homework['ends_on'], 'ends'); $defaults = array_merge($defaults, $end_date_array); } - + if ($there_is_a_expire_date) { $expires_date_array = convert_date_to_array($homework['expires_on'], 'expires'); - $defaults = array_merge($defaults, $expires_date_array); + $defaults = array_merge($defaults, $expires_date_array); } - + if (!empty($row['qualification'])) { $defaults = array_merge($defaults, array('qualification[qualification]' => $row['qualification'])); - } - + } + $defaults['allow_text_assignment'] = $row['allow_text_assignment']; $form_folder -> setDefaults($defaults); $display_edit_form = true; if ($form_folder->validate()) { - + if ($_POST['enableExpiryDate'] == '1') { $there_is_a_expire_date = true; } else { @@ -627,18 +627,18 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $there_is_a_end_date = true; } else { $there_is_a_end_date = false; - } - + } + $values = $form_folder->exportValues(); $work_id = $values['work_id']; - + $dir_name = replace_dangerous_char($values['dir_name']); $dir_name = disable_dangerous_file($dir_name); $edit_check = false; - - $work_data = get_work_data_by_id($work_id); - + + $work_data = get_work_data_by_id($work_id); + if (!empty($work_data)) { $edit_check = true; } else { @@ -646,43 +646,43 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor } if ($edit_check) { - $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); - + $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); + $expires_query = ' SET expires_on = '."'".($there_is_a_expire_date ? api_get_utc_datetime(get_date_from_group('expires')) : '0000-00-00 00:00:00')."'"; Database::query('UPDATE '.$work_assigment.$expires_query.' WHERE c_id = '.$course_id.' AND id = '."'".$row['has_properties']."'"); $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 WHERE c_id = $course_id AND id ='".$row['id']."'"; - Database::query($sql_add_publication); - + Database::query($sql_add_publication); + $ends_query = ' SET ends_on = '."'".($there_is_a_end_date ? api_get_utc_datetime(get_date_from_group('ends')) : '0000-00-00 00:00:00')."'"; Database::query('UPDATE '.$work_assigment.$ends_query.' WHERE c_id = '.$course_id.' AND id = '."'".$row['has_properties']."'"); $sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 WHERE c_id = $course_id AND id ='".$row['id']."'"; Database::query($sql_add_publication); - + $qualification_value = isset($_POST['qualification']['qualification']) && !empty($_POST['qualification']['qualification']) ? intval($_POST['qualification']['qualification']) : 0; $enable_qualification = !empty($qualification_value) ? 1 : 0; $sql_add_publication = "UPDATE ".$work_assigment." SET enable_qualification = '".$enable_qualification. "' WHERE c_id = $course_id AND publication_id ='".$row['id']."'"; - Database::query($sql_add_publication); - - $sql = 'UPDATE '.$work_table.' SET + Database::query($sql_add_publication); + + $sql = 'UPDATE '.$work_table.' SET allow_text_assignment = '."'".intval($_POST['allow_text_assignment'])."'".' , - title = '."'".Database::escape_string($_POST['dir_name'])."'".', - description = '."'".Database::escape_string($_POST['description'])."'".', + title = '."'".Database::escape_string($_POST['dir_name'])."'".', + description = '."'".Database::escape_string($_POST['description'])."'".', qualification = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".', - weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".' - WHERE c_id = '.$course_id.' AND id = '.$row['id']; + weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".' + WHERE c_id = '.$course_id.' AND id = '.$row['id']; Database::query($sql); - + require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php'; - + $link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], api_get_session_id()); $link_id = null; if (!empty($link_info)) { $link_id = $link_info['id']; } - + if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1 && !empty($_POST['category_id'])) { if (empty($link_id)) { add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], $_POST['dir_name'], (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], $_POST['description'], 1, api_get_session_id(), $link_id); @@ -690,12 +690,12 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor update_resource_from_course_gradebook($link_id, api_get_course_id(), $_POST['weight']['weight']); } } else { - //Delete everything of the gradebook - remove_resource_from_course_gradebook($link_id); + //Delete everything of the gradebook + remove_resource_from_course_gradebook($link_id); } update_dir_name($work_data, $dir_name, $values['dir_name']); - + $dir = $dir_name; $display_edit_form = false; @@ -704,7 +704,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $res = Database::query($sql); $calendar_id = Database::fetch_row($res); $dir_name = sprintf(get_lang('HandingOverOfTaskX'), $dir_name); - + $end_date = $row['insert_date']; if ($_POST['enableExpiryDate'] == '1') { @@ -728,16 +728,16 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor } } } - + $work_data = get_work_data_by_id($work_parent->id); - + $action = ''; $row = array(); $class = ''; - $cant_files = 0; + $cant_files = 0; $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); - + if (api_is_allowed_to_edit()) { $sql_document = "SELECT count(*) FROM $work_table w INNER JOIN $user_table u ON w.user_id = u.user_id WHERE w.c_id = $course_id AND w.parent_id = ".$work_data['id']." AND w.active IN (0, 1)"; } else { @@ -746,18 +746,18 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $user_filter = null; } $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 - s.id = p.ref AND - p.tool='work' AND - s.accepted='1' AND + s.id = p.ref AND + p.tool='work' AND + s.accepted='1' AND $user_filter - parent_id = ".$work_data['id']." AND + parent_id = ".$work_data['id']." AND active = 1 AND parent_id = ".$work_parent->id.""; } - - //count documents + + //count documents $res_document = Database::query($sql_document); $count_document = Database::fetch_row($res_document); $cant_files = $count_document[0]; @@ -769,7 +769,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor } $icon = Display::return_icon('work.png', get_lang('Assignment'), array(), ICON_SIZE_SMALL); - + if (!empty($display_edit_form) && !empty($edit_dir) && $edit_dir == $id2) { $row[] = $icon; $row[] = ''.$form_folder->toHtml(); // form to edit the directory's name @@ -790,23 +790,23 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor } else { $add_to_name = ''; } - + $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']); - - //Work name - //if (api_is_allowed_to_edit()) { + + //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).''; } - //} + //} $url = $zip.''. - $work_title.' '.$add_to_name.'
'.$cant_files.' '.$text_file.$dirtext; - $row[] = $url; + $work_title.' '.$add_to_name.'
'.$cant_files.' '.$text_file.$dirtext; + $row[] = $url; } if ($count_files != 0) { $row[] = ''; } - + if ($direc_date != '' && $direc_date != '0000-00-00 00:00:00') { $direc_date_local = api_get_local_time($direc_date); $row[] = date_to_str_ago($direc_date_local).'
'.api_format_date($direc_date_local).''; @@ -824,7 +824,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $action .= ''.Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL).''; $action .= ' '.Display::return_icon('delete.png',get_lang('DirDelete'),'',ICON_SIZE_SMALL).''; } - + $row[] = $action; } else { $row[] = ''; @@ -835,7 +835,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $table_data[] = $row; } } - + $sorting_options = array(); $sorting_options['column'] = 1; @@ -849,7 +849,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor $column_order[$i] = $i; $i++; } - if (empty($my_folder_data)) { + if (empty($my_folder_data)) { $column_order[1] = 5; } else { $column_order[2] = 2; @@ -858,7 +858,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor // 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[] = 1; // type 0 + $column_show[] = 1; // type 0 $column_show[] = 1; // title 1 if (!empty($my_folder_data)) { @@ -878,13 +878,13 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor if (isset($_GET['curdirpath'])) { $my_params = array ('curdirpath' => Security::remove_XSS($_GET['curdirpath'])); } - + $my_params = array ('id' => isset($_GET['id']) ? $_GET['id'] : null); if (isset($_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); } /** @@ -973,7 +973,7 @@ function build_work_directory_selector($folders, $curdirpath, $group_dir = '') { * @return string html form */ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') { - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); $move_file = intval($move_file); $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $sql = "SELECT title FROM $tbl_work WHERE c_id = $course_id AND id ='".$move_file."'"; @@ -1025,7 +1025,7 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d $form .= ''; $form .= ' '; - $form .= '
+ $form .= '
@@ -1088,33 +1088,33 @@ function create_unexisting_work_directory($base_work_dir, $desired_dir_name) { * @return integer -1 on error */ function del_dir($id) { - global $_course; + global $_course; $id = intval($id); $work_data = get_work_data_by_id($id); - + if (empty($work_data)) { return false; - } - - $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.'/'); - - + } + + $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); $course_id = api_get_course_int_id(); if (!empty($work_data['url'])) { - + //Deleting all contents inside the folder - //@todo replace to parent_id - $sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND filetype = 'folder' AND id = $id"; + //@todo replace to parent_id + $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 parent_id = $id"; $res = Database::query($sql); - if ($check) { + if ($check) { require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; $new_dir = $work_data_url.'_DELETED_'.$id; if (api_get_setting('permanently_remove_deleted_files') == 'true'){ @@ -1157,7 +1157,7 @@ function update_work_url($id, $new_path, $parent_id) { $course_id = api_get_course_int_id(); $id = intval($id); $parent_id = intval($parent_id); - + $sql = "SELECT * FROM $table WHERE c_id = $course_id AND id = $id"; $res = Database::query($sql); if (Database::num_rows($res) != 1) { @@ -1177,18 +1177,18 @@ function update_work_url($id, $new_path, $parent_id) { * @param string old path * @param string new path */ -function update_dir_name($work_data, $new_name, $title) { +function update_dir_name($work_data, $new_name, $title) { $course_id = api_get_course_int_id(); $work_id = intval($work_data['id']); $path = $work_data['url']; - + if ($work_data['title'] == $title) { return true; - } + } $title = Database::escape_string($title); - + if (!empty($new_name)) { - global $base_work_dir; + global $base_work_dir; $new_name = Security::remove_XSS($new_name); $new_name = replace_dangerous_char($new_name); @@ -1204,12 +1204,12 @@ function update_dir_name($work_data, $new_name, $title) { while ($work = Database :: fetch_array($rs)) { $new_dir = $work['url']; - $name_with_directory = substr($new_dir, $work_len, strlen($new_dir)); + $name_with_directory = substr($new_dir, $work_len, strlen($new_dir)); $name = Database::escape_string('work/'.$new_name.'/'.$name_with_directory); - $sql = 'UPDATE '.$table.' SET url= "'.$name.'" WHERE c_id = '.$course_id.' AND id= '.$work['id']; + $sql = 'UPDATE '.$table.' SET url= "'.$name.'" WHERE c_id = '.$course_id.' AND id= '.$work['id']; Database::query($sql); } - + $sql = "UPDATE $table SET url= '/".$new_name."' , title = '".$title."' WHERE c_id = $course_id AND id = $work_id"; Database::query($sql); } @@ -1232,7 +1232,7 @@ function get_parent_directories($id) { $list_id = array(); if (Database::num_rows($result)) { while ($row = Database::fetch_array($result)) { - $list_id[] = $row['id']; + $list_id[] = $row['id']; } } return $list_id; @@ -1279,12 +1279,12 @@ function insert_all_directory_in_course_table($base_work_dir) { } $course_id = api_get_course_int_id(); $group_id = api_get_group_id(); - + for($i = 0; $i < count($only_dir); $i++) { global $work_table; $sql_insert_all= "INSERT INTO " . $work_table . " SET - c_id = '$course_id', - url = '" . $only_dir[$i] . "', + c_id = '$course_id', + url = '" . $only_dir[$i] . "', title = '', description = '', author = '', @@ -1333,9 +1333,9 @@ function count_dir($path_dir, $recurse) { * validation when you create a work * this goes into the $htmlHeadXtra[] array */ -function to_javascript_work() { +function to_javascript_work() { $origin = isset($_REQUEST['origin']) && !empty($_REQUEST['origin']) ? api_get_tools_lists($_REQUEST['origin']) : ''; - + $js = ''; + '; return $js; } @@ -1476,12 +1476,12 @@ function get_work_id($path) { $TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY); $course_id = api_get_course_int_id(); if (api_is_allowed_to_edit()) { - $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work, $TBL_PROP_TABLE AS props + $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work, $TBL_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/".$path."%' AND work.filetype='file' AND props.visibility<>'2'"; } else { - $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props + $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_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/".$path."%' AND work.filetype='file' AND props.visibility<>'2' AND props.lastedit_user_id='".api_get_user_id()."'"; - } + } $result = Database::query($sql); $num_rows = Database::num_rows($result); @@ -1493,37 +1493,37 @@ function get_work_id($path) { } function get_count_work($work_id) { - $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); - $user_table = Database::get_main_table(TABLE_MAIN_USER); - - $is_allowed_to_edit = api_is_allowed_to_edit(null, true); - + $user_table = Database::get_main_table(TABLE_MAIN_USER); + + $is_allowed_to_edit = api_is_allowed_to_edit(null, true); + $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); - + $course_id = api_get_course_int_id(); $group_id = api_get_group_id(); $course_info = api_get_course_info(api_get_course_id()); $work_id = intval($work_id); - + if (!empty($group_id)) { - $extra_conditions = " work.post_group_id = '".intval($group_id)."' "; // set to select only messages posted by the user's group + $extra_conditions = " work.post_group_id = '".intval($group_id)."' "; // set to select only messages posted by the user's group } else { - $extra_conditions = " work.post_group_id = '0' "; + $extra_conditions = " work.post_group_id = '0' "; } if ($is_allowed_to_edit) { $extra_conditions .= ' AND work.active IN (0, 1) '; } else { - $extra_conditions .= ' AND work.active = 1 AND accepted = 1'; - if (isset($course_info['show_score']) && $course_info['show_score'] == 1) { + $extra_conditions .= ' AND work.active = 1 AND accepted = 1'; + if (isset($course_info['show_score']) && $course_info['show_score'] == 1) { $extra_conditions .= " AND work.user_id = ".api_get_user_id()." "; } else { $extra_conditions .= ''; } - } - + } + $extra_conditions .= " AND parent_id = ".$work_id." "; $sql = "SELECT count(*) as count ". @@ -1534,110 +1534,116 @@ function get_count_work($work_id) { " INNER JOIN $user_table u ON (work.user_id = u.user_id) ". " WHERE $extra_conditions $where_condition $condition_session "; $result = Database::query($sql); - - $users_with_work = 0; + + $users_with_work = 0; if (Database::num_rows($result)) { - $result = Database::fetch_array($result); + $result = Database::fetch_array($result); $users_with_work = $result['count']; } - return $users_with_work; + return $users_with_work; } function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition) { - $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); - $user_table = Database::get_main_table(TABLE_MAIN_USER); - + $user_table = Database::get_main_table(TABLE_MAIN_USER); + $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $group_id = api_get_group_id(); $course_info = api_get_course_info(api_get_course_id()); - - $work_id = intval($work_id); + + $work_id = intval($work_id); $column = empty($column) ? : Database::escape_string($column); $start = intval($start); $limit = intval($limit); if (!in_array($direction, array('asc','desc'))) { - $direction = 'desc'; + $direction = 'desc'; } - - $work_data = get_work_data_by_id($work_id); - $is_allowed_to_edit = api_is_allowed_to_edit(null, true); + + $work_data = get_work_data_by_id($work_id); + $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $condition_session = api_get_session_condition($session_id); - + $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION); if (!empty($work_data)) { - + if (!empty($group_id)) { - $extra_conditions = " work.post_group_id = '".intval($group_id)."' "; // set to select only messages posted by the user's group + $extra_conditions = " work.post_group_id = '".intval($group_id)."' "; // set to select only messages posted by the user's group } else { - $extra_conditions = " work.post_group_id = '0' "; + $extra_conditions = " work.post_group_id = '0' "; } 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 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()." "; } else { $extra_conditions .= ''; } } - - $extra_conditions .= " AND parent_id = ".$work_id." "; - - $select = 'DISTINCT work.id as id, title as title, description, url, sent_date, contains_file, has_properties, view_properties, + + $extra_conditions .= " AND parent_id = ".$work_id." "; + + $select = 'DISTINCT work.id as id, title as title, description, url, sent_date, contains_file, has_properties, view_properties, qualification, weight, allow_text_assignment, u.firstname, u.lastname, u.username, parent_id, accepted, qualificator_id'; - + $user_condition = "INNER JOIN $user_table u ON (work.user_id = u.user_id) "; $work_condition = "$iprop_table prop INNER JOIN $work_table work ON (prop.ref = work.id AND prop.c_id = $course_id AND work.c_id = $course_id ) "; - + $work_assignment = get_work_assignment_by_id($work_id); - + $sql = "SELECT $select - FROM $work_condition $user_condition $course_conditions + FROM $work_condition $user_condition $course_conditions WHERE $extra_conditions $where_condition $condition_session "; - + $sql .= " ORDER BY $column $direction "; $sql .= " LIMIT $start, $limit"; - + $result = Database::query($sql); $works = array(); - + while ($work = Database::fetch_array($result, 'ASSOC')) { //var_dump($work); - $item_id = $work['id']; - + $item_id = $work['id']; + //Get the author ID for that document from the item_property table $is_author = false; $can_read = false; - - $item_property_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_id, api_get_session_id()); - - if (!$is_allowed_to_edit && $item_property_data['insert_user_id'] == api_get_user_id()) { + + $owner_id = $work['user_id']; + + /* Because a bug found when saving items using the api_item_property_update() + the field $item_property_data['insert_user_id'] is not reliable. */ + + // $item_property_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_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 && $owner_id == api_get_user_id()) { $is_author = true; - } + } + if ($course_info['show_score'] == 0 ) { $can_read = true; } - + if ($work['accepted'] == '0') { $class = 'invisible'; } else { $class = ''; - } - + } + $qualification_exists = false; if (!empty($work_data['qualification']) && intval($work_data['qualification']) > 0) { $qualification_exists = true; } - + $qualification_string = ''; - + if ($qualification_exists) { if ($work['qualification'] == '') { $qualification_string = Display::label('-'); @@ -1645,52 +1651,52 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher $qualification_string = Display::label($work['qualification'], 'info'); } } - - $add_string = ''; + + $add_string = ''; $time_expires = api_strtotime($work['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'); } - + if (($can_read && $work['accepted'] == '1') || ($is_author && $work['accepted'] == '1') || $is_allowed_to_edit) { - + //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).'...'; $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title'])); } else { $work['title'] = Display::div($work['title'], array('class' => $class)); } - - + + //Type - $work['type'] = build_document_icon_tag('file', $work['file']); + $work['type'] = build_document_icon_tag('file', $work['file']); //File name $link_to_download = null; - + if ($work['contains_file']) { $link_to_download = ''.Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).' '; } else { $link_to_download = ''.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).' '; } - + $send_to = Portfolio::share('work', $work['id'], array('style' => 'white-space:nowrap;')); - + $work['qualification'] = $qualification_string; //Date - $work_date = api_convert_and_format_date($work['sent_date']); - $work['sent_date'] = date_to_str_ago(api_get_local_time($work['sent_date'])).' '.$add_string.'
'.$work_date; + $work_date = api_convert_and_format_date($work['sent_date']); + $work['sent_date'] = date_to_str_ago(api_get_local_time($work['sent_date'])).' '.$add_string.'
'.$work_date; //Actions - $url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&id='.$work_id.'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']); - $action = ''; + $url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&id='.$work_id.'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']); + $action = ''; if ($is_allowed_to_edit) { if ($locked) { if ($qualification_exists) { @@ -1723,8 +1729,8 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher $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)) { + } + } 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).''; } else { @@ -1738,17 +1744,17 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher } //Status - if (empty($work['qualificator_id'])) { + if (empty($work['qualificator_id'])) { $qualificator_id = Display::label(get_lang('NotRevised'), 'warning'); } else { $qualificator_id = Display::label(get_lang('Revised'), 'success'); - } + } $work['qualificator_id'] = $qualificator_id; $work['actions'] = $send_to.$link_to_download.$action; $works[] = $work; - } + } } - return $works; + return $works; } } @@ -1767,24 +1773,24 @@ function send_reminder_users_without_publication($task_data) { $task_title = !empty($task_data['title']) ? $task_data['title'] : basename($task_data['url']); $subject = '[' . api_get_setting('siteName') . '] '; - + // The body can be as long as you wish, and any combination of text and variables - + $content = get_lang('ReminderToSubmitPendingTask')."\n".get_lang('CourseName').' : '.$_course['name']."\n"; $content .= get_lang('WorkName').' : '.$task_title."\n"; $list_users = get_list_users_without_publication($task_id); - - $mails_sent_to = array(); + + $mails_sent_to = array(); foreach ($list_users as $user) { - $name_user = api_get_person_name($user[1], $user[0], null, PERSON_NAME_EMAIL_ADDRESS); - $dear_line = get_lang('Dear')." ".api_get_person_name($user[1], $user[0]) .", \n\n"; - $body = $dear_line.$content; - - api_mail($name_user, $user[3], $subject, $body, $sender_name, $email_admin); - $mails_sent_to[] = $name_user; - } - return $mails_sent_to; + $name_user = api_get_person_name($user[1], $user[0], null, PERSON_NAME_EMAIL_ADDRESS); + $dear_line = get_lang('Dear')." ".api_get_person_name($user[1], $user[0]) .", \n\n"; + $body = $dear_line.$content; + + api_mail($name_user, $user[3], $subject, $body, $sender_name, $email_admin); + $mails_sent_to[] = $name_user; + } + return $mails_sent_to; } /** @@ -1795,7 +1801,7 @@ function send_reminder_users_without_publication($task_data) { * @author Guillaume Viguier * @author Julio Montoya Adding session support - 2011 */ -function send_email_on_homework_creation($course_id) { +function send_email_on_homework_creation($course_id) { // Get the students of the course $session_id = api_get_session_id(); if (empty($session_id)) { @@ -1883,11 +1889,11 @@ function user_is_author($item_id, $user_id = null) { if (empty($user_id)) { $user_id = api_get_user_id(); } - - $is_author = false; - $item_to_edit_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_id, api_get_session_id()); + + $is_author = false; + $item_to_edit_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_id, api_get_session_id()); $is_allowed_to_edit = api_is_allowed_to_edit(); - + if ($is_allowed_to_edit) { $is_author = true; } else { @@ -1911,14 +1917,14 @@ function user_is_author($item_id, $user_id = null) { * @author Julio Montoya Fixing query */ function get_list_users_without_publication($task_id) { - $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_user = Database::get_main_table(TABLE_MAIN_USER); $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); //condition for the session $session_id = api_get_session_id(); - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); $task_id = intval($task_id); @@ -1934,39 +1940,39 @@ function get_list_users_without_publication($task_id) { } if ($session_id == 0){ - $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u + $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u WHERE u.status!=1 and cu.course_code='".api_get_course_id()."' AND u.user_id=cu.user_id"; } else { - $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u + $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u WHERE u.status!=1 and cu.course_code='".api_get_course_id()."' AND u.user_id=cu.id_user and cu.id_session='".$session_id."'"; } - + $group_id = api_get_group_id(); - + $new_group_user_list = array(); - + if ($group_id) { - $group_user_list = GroupManager::get_subscribed_users($group_id); + $group_user_list = GroupManager::get_subscribed_users($group_id); if (!empty($group_user_list)) { foreach($group_user_list as $group_user) { $new_group_user_list[] = $group_user['user_id']; } } } - + $result_users = Database::query($sql_users); $users_without_tasks = array(); while ($row_users = Database::fetch_row($result_users)) { - + if (in_array($row_users[0], $users_with_tasks)) continue; - if ($group_id && !in_array($row_users[0], $new_group_user_list)) { + if ($group_id && !in_array($row_users[0], $new_group_user_list)) { continue; } //$user_id = array_shift($row_users); $row_users[0] = $row_users[1]; $row_users[1] = $row_users[2]; $row_users[2] = Display::encrypted_mailto_link($row_users[3]); - + $users_without_tasks[] = $row_users; } return $users_without_tasks; @@ -1987,7 +1993,7 @@ function display_list_users_without_publication($task_id) { $table_header[] = array(get_lang('Email'), true); // table_data $table_data = get_list_users_without_publication($task_id); - + $sorting_options = array(); $sorting_options['column'] = 1; $paging_options = array();