, Ghent University - ability for course admins to specify wether uploaded documents are visible or invisible by default. * @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 magein/inc/lib */ /** * Initialization */ require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; 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) * @param string Current dir * @param integer Whether to show tool options * @param integer Whether to show upload form option * @return void */ function display_action_links($id, $cur_dir_path, $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)) { $display_output .= ''.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).''; } if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath') { // Create dir if (empty($id)) { $display_output .= ''; $display_output .= Display::return_icon('new_work.png', get_lang('CreateAssignment'),'',ICON_SIZE_MEDIUM).''; } if (empty($id)) { // Options $display_output .= ''; $display_output .= Display::return_icon('settings.png', get_lang('EditToolOptions'),'',ICON_SIZE_MEDIUM).''; } } 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'){ $message = get_lang('ConfirmYourChoiceDeleteAllfiles'); } else { $message = get_lang('ConfirmYourChoice'); } } if ($display_output != '') { echo '
'; echo $display_output; echo '
'; } } /** * Displays all options for this tool. * These are * - make all files visible / invisible * - set the default visibility of uploaded files * * @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; } echo '
'; echo ''.get_lang('EditToolOptions').''; display_default_visibility_form($uploadvisibledisabled); display_studentsdelete_form(); echo '
'; echo '
'; } /** * Displays the form where course admins can specify wether uploaded documents * are visible or invisible by default. * * @param $uploadvisibledisabled * @param $origin */ function display_default_visibility_form($uploadvisibledisabled) { ?>
, Ghent University, Belgium */ function display_studentsdelete_form() { // by default api_get_course_setting returns -1 and the code only expects 0 or 1 so anything tha // is different than 1 will be converted into 0 $current_course_setting_value = api_get_course_setting('student_delete_own_publication'); if ($current_course_setting_value != 1) { $current_course_setting_value = 0; } ?>
12345672218 (timestamp) $parts = split(' ', $default); list($d_year, $d_month, $d_day) = split('-', $parts[0]); list($d_hour, $d_minute, $d_second) = split(':', $parts[1]); return mktime((int)$d_hour, (int)$d_minute, (int)$d_second, (int)$d_month, (int)$d_day, (int)$d_year); } /** * converts 1-9 to 01-09 */ function two_digits($number) { $number = (int)$number; return ($number < 10) ? '0'.$number : $number; } /** * converts 2008-10-06 12:45:00 to -> array($data'year'=>2008,$data'month'=>10 etc...) */ function convert_date_to_array($date, $group) { $parts = split(' ', $date); $date_parts = split('-', $parts[0]); $date_parts_tmp = array(); foreach ($date_parts as $item) { $date_parts_tmp[] = intval($item); } $time_parts = split(':', $parts[1]); $time_parts_tmp = array(); foreach ($time_parts as $item) { $time_parts_tmp[] = intval($item); } list($data[$group.'[year]'], $data[$group.'[month]'], $data[$group.'[day]']) = $date_parts_tmp; list($data[$group.'[hour]'], $data[$group.'[minute]']) = $time_parts_tmp; return $data; } /** * get date from a group of date */ function get_date_from_group($group) { return $_POST[$group]['year'].'-'.two_digits($_POST[$group]['month']).'-'.two_digits($_POST[$group]['day']).' '.two_digits($_POST[$group]['hour']).':'.two_digits($_POST[$group]['minute']).':00'; } /** * create a group of select from a date */ function create_group_date_select($prefix = '') { $minute = range(10, 59); $d_year = date('Y'); array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09'); $group_name[] = FormValidator :: createElement('select', $prefix.'day', '', array_combine(range(1, 31), range(1, 31))); $group_name[] = FormValidator :: createElement('select', $prefix.'month', '', array_combine(range(1, 12), api_get_months_long())); $group_name[] = FormValidator :: createElement('select', $prefix.'year', '', array($d_year => $d_year, $d_year + 1 => $d_year + 1)); $group_name[] = FormValidator :: createElement('select', $prefix.'hour', '', array_combine(range(0, 23), range(0, 23))); $group_name[] = FormValidator :: createElement('select', $prefix.'minute', '', $minute); return $group_name; } function get_work_data_by_path($path) { $path = Database::escape_string($path); $course_id = api_get_course_int_id(); $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $sql = "SELECT * FROM ".$work_table." WHERE url = '$path' AND c_id = $course_id "; $result = Database::query($sql); $return = array(); if (Database::num_rows($result)) { $return = Database::fetch_array($result,'ASSOC'); } return $return; } function get_work_data_by_id($id) { $id = intval($id); $course_id = api_get_course_int_id(); $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $sql = "SELECT * FROM $work_table WHERE id = $id AND c_id = $course_id"; $result = Database::query($sql); $return = array(); if (Database::num_rows($result)) { $return = Database::fetch_array($result, 'ASSOC'); } return $return; } /** * @param int $user_id * @param int $work_id * @return int */ function get_work_count_by_student($user_id, $work_id) { $user_id = intval($user_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 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 = intval($return[0]); } return $return; } /** * @param int $id * @return array */ function get_work_assignment_by_id($id) { $id = intval($id); $course_id = api_get_course_int_id(); $table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $sql = "SELECT * FROM $table WHERE c_id = $course_id AND publication_id = $id"; $result = Database::query($sql); $return = array(); if (Database::num_rows($result)) { $return = Database::fetch_array($result,'ASSOC'); } return $return; } /** * @param int $id * @param array $my_folder_data * @param string $add_in_where_query * @return array */ function getWorkList($id, $my_folder_data, $add_in_where_query) { $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $group_id = api_get_group_id(); $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']; $is_allowed_to_edit = api_is_allowed_to_edit(null, true); 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 = ''; //Get list from database if ($is_allowed_to_edit) { $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 "; if (!empty($group_id)) { $sql_get_publications_list .= " AND post_group_id = '".$group_id."' "; } $sql_get_publications_list .= " ORDER BY sent_date DESC"; } 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"; } $work_parents = array(); $sql_result = Database::query($sql_get_publications_list); if (Database::num_rows($sql_result)) { while ($work = Database::fetch_object($sql_result)) { if ($work->parent_id == 0) { $work_parents[] = $work; } } } return $work_parents; } /** * @param int $userId * @return array */ function getWorkPerUser($userId) { $works = getWorkList(null, null, null); $result = array(); if (!empty($works)) { foreach ($works as $workData) { $workId = $workData->id; $result[$workId]['work'] = $workData; $result[$workId]['work']->user_results = get_work_user_list(0, 100, null, null, $workId, null, $userId); } } return $result; } /** * @param int $workId * @param int $course_id * @param int $sessionId * @param int $userId user id to filter * @param array $onlyUserList only parse this user list * @return mixed */ function getUniqueStudentAttempts($workId, $groupId, $course_id, $sessionId, $userId = null, $onlyUserList = array()) { $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $user_table = Database::get_main_table(TABLE_MAIN_USER); $course_id = intval($course_id); $workId = intval($workId); $sessionId = intval($sessionId); $groupId = intval($groupId); $studentCondition = null; if (!empty($onlyUserList)) { $studentCondition = "AND u.user_id IN ('".implode("', '", $onlyUserList)."') "; } else { if (empty($userId)) { return 0; } } $sql_document = "SELECT count(*) FROM ( 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.session_id = $sessionId AND w.parent_id = ".$workId." AND w.post_group_id = ".$groupId." AND w.active IN (0, 1) $studentCondition "; if (!empty($userId)) { $userId = intval($userId); $sql_document .= " AND u.user_id = ".$userId; } $sql_document .= " GROUP BY u.user_id) as t"; $res_document = Database::query($sql_document); $rowCount = Database::fetch_row($res_document); return $rowCount[0]; } /** * Display the list of student publications, taking into account the user status * * @param $origin - typically empty or 'learnpath' */ function display_student_publications_list($id, $my_folder_data, $work_parents, $origin, $add_in_where_query = '', $userList = array()) { global $gradebook; $_course = api_get_course_info(); // Database table names $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); $work_assigment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $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(); $course_info = api_get_course_info(api_get_course_id()); $sort_params = array(); if (isset($_GET['column'])) { $sort_params[] = 'column='.Security::remove_XSS($_GET['column']); } if (isset($_GET['page_nr'])) { $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']); } if (isset($_GET['per_page'])) { $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']); } if (isset($_GET['direction'])) { $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']); } $sort_params = implode('&', $sort_params); $my_params = $sort_params; $origin = Security::remove_XSS($origin); $qualification_exists = false; if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) { $qualification_exists = true; } $edit_dir = isset($_GET['edit_dir']) ? intval($_GET['edit_dir']) : ''; $table_header = array(); $table_has_actions_column = false; $table_header[] = array(get_lang('Type'), false, 'style="width:40px"'); $table_header[] = array(get_lang('Title'), true); if (!empty($id)) { $table_header[] = array(get_lang('FirstName'), true); $table_header[] = array(get_lang('LastName'), true); } $table_header[] = array(get_lang('HandOutDateLimit'), true, 'style="width:200px"'); if ($is_allowed_to_edit) { $table_header[] = array(get_lang('HandedOut'), false); $table_header[] = array(get_lang('Actions'), false, 'style="width:90px"', array('class'=>'td_actions')); $table_has_actions_column = true; if ($qualification_exists) { $table_header[] = array(get_lang('Qualification'), true); } } else { // All users if ($course_info['show_score'] == 0) { $table_header[] = array(get_lang('Others'), false); } } $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) { $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"; $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 $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); // form edit directory 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); } // save original value for later $utc_expiry_time = $homework['expires_on']; if ($is_allowed_to_edit && $locked == false) { if (!empty($edit_dir) && $edit_dir == $id2) { $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; $form_folder -> addElement('advanced_settings', '    '.get_lang('AdvancedParameters').' ' ); $form_folder->addElement('html', '