, 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
* @version $Id: work.lib.php 22357 2009-07-24 17:44:17Z juliomontoya $
* @todo this lib should be convert in a static class and moved to main/inc/lib
*/
/**
* Initialization
*/
require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
/**
* 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($cur_dir_path, $always_show_tool_options, $always_show_upload_form) {
global $gradebook;
$display_output = '';
$origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
$curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : empty($curdirpath);
if (strlen($cur_dir_path) > 0 && $cur_dir_path != '/') {
$parent_dir = dirname($cur_dir_path);
$display_output .= ''.Display::return_icon('back.png', get_lang('BackToWorksList'),'','32').'';
} else {
if ($_GET['display_tool_options'] == 'true' OR $_GET['display_upload_form'] == 'true') {
if ($origin != 'learnpath') {
//$display_output .= ''.Display::return_icon('back.png', get_lang('BackToWorksList'),'','32').'';
}
}
}
if (!$always_show_tool_options && api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
if (empty($curdirpath)) {
//$display_output .= ''.Display::return_icon('back.png', get_lang('BackToWorksList'),'','32').'';
}
// Create dir
if ($cur_dir_path == '/') {
$display_output .= ''.Display::return_icon('new_work.png', get_lang('CreateAssignment'),'','32').'';
}
if (empty($curdirpath) || $curdirpath == '.') {
// Options
$display_output .= ''.Display::return_icon('settings.png', get_lang('EditToolOptions'),'','32').'';
}
}
if (!$always_show_upload_form && api_is_allowed_to_session_edit(false, true) && (isset($_GET['curdirpath']) && (!empty($_GET['curdirpath']) && $_GET['curdirpath'] != '.') )) {
$display_output .= ''.Display::return_icon('upload_file.png', get_lang('UploadADocument'),'','32').'';
}
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 (empty($curdirpath) or $curdirpath != '.') {
//$display_output .= ''.Display::return_icon('delete_na.png', get_lang('Delete'),'','32').'';
} else {
/*$display_output .= ''.
Display::return_icon('delete.png', get_lang('Delete'),'','32').'';*/
}
// make all files visible or invisible
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql_query = "SHOW COLUMNS FROM ".$work_table." LIKE 'accepted'";
$sql_result = Database::query($sql_query);
if ($sql_result) {
$columnStatus = Database::fetch_array($sql_result);
/*
if (empty($curdirpath) || $curdirpath == '.') {
if ($columnStatus['Default'] == 1) {
$display_output .= ''.
Display::return_icon('visible.png', get_lang('MakeAllPapersInvisible'),'','32')."\n";
} else {
$display_output .= ''.
Display::return_icon('invisible.png', get_lang('MakeAllPapersVisible'),'','32')."\n";
}
}*/
}
}
if (api_is_allowed_to_edit(null, true)) {
global $publication;
if (empty($curdirpath) or $curdirpath != '.' or $cur_dir_path != '/') {
if (empty($_GET['list']) or Security::remove_XSS($_GET['list']) == 'with') {
$display_output .= ''.
Display::return_icon('exercice_uncheck.png', get_lang('ViewUsersWithoutTask'),'','32')."\n";
} else {
$display_output .= ''.
Display::return_icon('exercice_check.png', get_lang('ViewUsersWithTask'),'','32')."\n";
$_SESSION['token'] = time();
$display_output .= ''.
Display::return_icon('mail_send.png', get_lang('ReminderMessage'),'','32')."";
}
}
}
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
* @param $base_work_dir Base working directory (up to '/work')
* @param $cur_dir_path Current subdirectory of 'work/'
* @param $cur_dir_path_url Current subdirectory of 'work/', url-encoded
*/
function display_tool_options($uploadvisibledisabled, $origin, $base_work_dir, $cur_dir_path, $cur_dir_path_url) {
global $group_properties, $gradebook;
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
if (!$is_allowed_to_edit) {
return;
}
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;
}
?>
/>
/>
, Ghent University
* @version march 2006
*/
function display_user_link_work($user_id, $name = '', $gradebook='') {
global $_otherusers;
$user_id = intval($user_id);
if ($user_id != 0) {
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT user_id, firstname, lastname FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'";
$result = Database::query($sql);
$row = Database::fetch_array($result);
if ($name == '') {
return ''.api_get_person_name($row['firstname'], $row['lastname']).'';
} else {
return ''.$name.'';
}
} else {
return $name.' ('.get_lang('Anonymous').')';
}
}
/**
* converts 2008-10-06 12:45:00 to timestamp
* @deprecated any calls found
*/
function convert_date_to_number($default) {
// 2008-10-12 00:00:00 ---to--> 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;
}
/**
* Display the list of student publications, taking into account the user status
*
* @param $currentCourseRepositoryWeb, the web location of the course folder
* @param $link_target_parameter - should there be a target parameter for the links
* @param $dateFormatLong - date format
* @param $origin - typically empty or 'learnpath'
*/
function display_student_publications_list($work_dir, $sub_course_dir, $currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin, $add_in_where_query = '') {
global $timeNoSecFormat, $dateFormatShort, $gradebook, $_user;
// Database table names
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$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();
$publications_list = array();
$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);
if (substr($sub_course_dir, -1, 1) != '/' && !empty($sub_course_dir)) {
$sub_course_dir = $sub_course_dir.'/';
}
if ($sub_course_dir == '/') {
$sub_course_dir = '';
}
//condition for the session
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
//Get list from database
if ($is_allowed_to_edit) {
$sql_get_publications_list = "SELECT * FROM ".$work_table." " .
"WHERE url LIKE BINARY '$sub_course_dir%' " .
"AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query.$condition_session.
" ORDER BY sent_date DESC";
$sql_get_publications_num = "SELECT count(*) FROM ".$work_table." " .
"WHERE url LIKE BINARY '$sub_course_dir%' " .
"AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query.
$condition_session.
" ORDER BY id";
} else {
if (!empty($_SESSION['toolgroup'])) {
$group_query = " WHERE post_group_id = '".intval($_SESSION['toolgroup'])."' "; // set to select only messages posted by the user's group
$subdirs_query = "AND url NOT LIKE BINARY '$sub_course_dir%/%' AND url LIKE BINARY '$sub_course_dir%'";
} else {
$group_query = " WHERE post_group_id = '0' ";
$subdirs_query = "AND url NOT LIKE '$sub_course_dir%/%' AND url LIKE '$sub_course_dir%'";
}
$sql_get_publications_list = "SELECT * FROM $work_table $group_query $subdirs_query ".$add_in_where_query." $condition_session ORDER BY id";
$sql_get_publications_num = "SELECT count(url) FROM ".$work_table." " .
"WHERE url LIKE BINARY '$sub_course_dir%' AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query.
$condition_session.
" ORDER BY id";
}
//echo $sql_get_publications_list;
$sql_result = Database::query($sql_get_publications_list);
$sql_result_num = Database::query($sql_get_publications_num);
$row = Database::fetch_array($sql_result_num);
$count_files = $row[0];
$table_header[] = array(get_lang('Type'), false, 'style="width:40px"');
$table_header[] = array(get_lang('Title'), true);
if ($count_files != 0) {
$table_header[] = array(get_lang('Authors'), true);
$table_header[] = array(get_lang('Qualification'), true);
}
$table_header[] = array(get_lang('Date'), true, 'style="width:160px"');
if ($origin != 'learnpath') {
$table_header[] = array(get_lang('Actions'), false, 'style="width:90px"');
$table_header[] = array('RealDate', true);
}
// An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
$column_show[] = 1; // type
$column_show[] = 1; // title
if ($count_files != 0) {
$column_show[] = 1; // authors
$column_show[] = 1; // qualification
}
$column_show[] = 1; //date
$column_show[] = 1; // modify
$column_show[] = 0; //real date in correct format
// Here we change the way how the colums are going to be sort
// 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"
$column_order = array();
$i=0;
foreach($table_header as $item) {
$column_order[$i] = $i;
$i++;
}
if ($count_files != 0) {
if ($sub_course_dir == '/work') {
$column_order[2] = 2;
} else {
//$column_order[2] = 5;
}
} else {
//$column_order[1] = 4;
$column_order[2] = 4;
}
$table_data = array();
$dirs_list = get_subdirs_list($work_dir);
$my_sub_dir = str_replace('work/', '', $sub_course_dir);
// @todo Since "works" cant have sub works this foreach is useless when selecting the list of works
// List of all folders
if (is_array($dirs_list)) {
foreach ($dirs_list as $dir) {
if ($my_sub_dir == '') {
$mydir_temp = '/'.$dir;
} else {
$mydir_temp = '/'.$my_sub_dir.$dir;
}
$sql_select_directory = "SELECT prop.lastedit_date, work.id, author, has_properties, view_properties, description, qualification, weight FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE ";
if (!empty($_SESSION['toolgroup'])) {
$sql_select_directory .= " work.post_group_id = '".$_SESSION['toolgroup']."' "; // 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.url LIKE BINARY '".$mydir_temp."' AND work.filetype = 'folder' AND prop.tool='work' $condition_session";
$result = Database::query($sql_select_directory);
$row = Database::fetch_array($result);
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'];
$mydir = $my_sub_dir.$dir;
if ($is_allowed_to_edit) {
isset($_GET['edit_dir']) ? $clean_edit_dir = Security :: remove_XSS($_GET['edit_dir']) : $clean_edit_dir = '';
// form edit directory
if (isset($clean_edit_dir) && $clean_edit_dir == $mydir) {
if (!empty($row['has_properties'])) {
$sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE id = '."'".$row['has_properties']."'".' LIMIT 1');
$homework = Database::fetch_array($sql);
}
$form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?curdirpath='.$my_sub_dir.'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$mydir);
$group_name[] = FormValidator :: createElement('text', 'dir_name');
$form_folder -> addGroup($group_name, 'my_group', get_lang('Title'));
$form_folder -> addGroupRule('my_group', get_lang('ThisFieldIsRequired'), 'required');
$defaults = array('my_group[dir_name]' => html_entity_decode($dir), 'description' => api_html_entity_decode($row['description']));
//$form_folder-> addElement('textarea', 'description', get_lang('Description'), array('rows' => 5, 'cols' => 50));
$form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'work', 'Width' => '100%', 'Height' => '200'));
$qualification_input[] = FormValidator :: createElement('text','qualification');
$form_folder -> addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'), 'size="10"');
if ($row['weight'] > 0) {
$weight_input[] = FormValidator :: createElement('text', 'weight');
$form_folder -> addGroup($weight_input, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
}
$there_is_a_end_date = false;
if ($row['view_properties'] == '1') {
if ($homework['expires_on'] != '0000-00-00 00:00:00') {
$homework['expires_on'] = api_get_local_time($homework['expires_on']);
$there_is_a_expire_date = true;
$form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
}
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;
$form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
}
if ($there_is_a_expire_date && $there_is_a_end_date) {
$form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
}
} else {
$form_folder -> addElement('html', '