@ -24,7 +24,8 @@ require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.
* @param integer Whether to show upload form option
* @return void
*/
function display_action_links($id, $cur_dir_path, $show_tool_options, $display_upload_link, $action) {
function display_action_links($id, $cur_dir_path, $show_tool_options, $display_upload_link, $action)
{
global $gradebook;
$id = $my_back_id = intval($id);
@ -32,39 +33,39 @@ function display_action_links($id, $cur_dir_path, $show_tool_options, $display_u
$my_back_id = 0;
}
$display_output = '';
$origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
$display_output = '';
$origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
if (!empty($id)) {
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&id='.$my_back_id.'" > '.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
if (!empty($id)) {
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&id='.$my_back_id.'" > '.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
if ($show_tool_options & & api_is_allowed_to_edit(null, true) & & $origin != 'learnpath') {
// Create dir
if (empty($id)) {
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&action=create_dir&origin='.$origin.'&gradebook='.$gradebook.'" > ';
$display_output .= Display::return_icon('new_work.png', get_lang('CreateAssignment'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
if (empty($id)) {
// Options
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&action=settings&origin='.$origin.'&gradebook='.$gradebook.'" > ';
$display_output .= Display::return_icon('settings.png', get_lang('EditToolOptions'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
}
if ($show_tool_options & & api_is_allowed_to_edit(null, true) & & $origin != 'learnpath') {
// Create dir
if (empty($id)) {
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&action=create_dir&origin='.$origin.'&gradebook='.$gradebook.'" > ';
$display_output .= Display::return_icon('new_work.png', get_lang('CreateAssignment'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
if (empty($id)) {
// Options
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&action=settings&origin='.$origin.'&gradebook='.$gradebook.'" > ';
$display_output .= Display::return_icon('settings.png', get_lang('EditToolOptions'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
}
if ($display_upload_link & & api_is_allowed_to_session_edit(false, true) & & !empty($id)) {
$display_output .= '< a href = "'.api_get_self().'?'.api_get_cidreq().'&id='.$id.'&action=upload_form&origin='.$origin.'&gradebook='.$gradebook.'" > ';
$display_output .= Display::return_icon('upload_file.png', get_lang('UploadADocument'),'',ICON_SIZE_MEDIUM).'< / a > ';
}
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 (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 (api_is_allowed_to_edit(null, true)) {
global $token;
@ -309,30 +310,122 @@ function get_work_assignment_by_id($id) {
return $return;
}
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);
$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 ".
" 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;
}
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;
}
function getUniqueStudentAttempts($workId, $course_id, $userId = null)
{
$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);
$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.parent_id = ".$workId." AND w.active IN (0, 1)
";
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 $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($id, $link_target_parameter, $dateFormatLong, $origin, $add_in_where_query = '') {
global $timeNoSecFormat, $dateFormatShort, $gradebook, $_course;
function display_student_publications_list($id, $my_folder_data, $work_parents, $origin, $add_in_where_query = '', $countUsers = null)
{
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);
$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();
$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());
$sort_params = array();
@ -354,62 +447,13 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$origin = Security::remove_XSS($origin);
// Getting the work data
$my_folder_data = get_work_data_by_id($id);
// $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';
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 = '';
//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 ".
" 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;
}
}
}
}
$edit_dir = isset($_GET['edit_dir']) ? $_GET['edit_dir'] : '';
@ -421,19 +465,24 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
if (!empty($id)) {
$table_header[] = array(get_lang('FirstName'), true);
$table_header[] = array(get_lang('LastName'), true);
if ($qualification_exists) {
$table_header[] = array(get_lang('Qualification'), true);
}
}
$table_header[] = array(get_lang('Date'), true, 'style="width:200px"');
//$table_header[] = array(get_lang('Date'), true, 'style="width:200px"');
$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;
}
// the following column name seems both undefined and unused
//$table_header[] = array('RealDate', true);
} else {
//$table_header[] = array(get_lang('HandedOutDate'), false);
}
if ($qualification_exists) {
$table_header[] = array(get_lang('Qualification'), true);
}
$table_data = array();
@ -443,9 +492,20 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
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 ";
$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
@ -464,6 +524,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
// 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'];
@ -472,15 +533,16 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$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);
}
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->addElement('hidden', 'work_id', $id2);
@ -492,11 +554,13 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$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', '< a href = "javascript://" onclick = "javascript: return plus();" >
< span id = "plus" > < img style = "vertical-align:middle;" src = "../img/div_show.gif" alt = "" / >
'.get_lang('AdvancedParameters').'
< / span >
< / a > ');
$form_folder -> addElement('advanced_settings',
'< a href = "javascript://" onclick = "javascript: return plus();" >
< span id = "plus" > < img style = "vertical-align:middle;" src = "../img/div_show.gif" alt = "" / >
'.get_lang('AdvancedParameters').'
< / span >
< / a > '
);
$form_folder->addElement('html', '< div id = "options" style = "display: none;" > ');
if (empty($default)) {
@ -734,12 +798,13 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$action = '';
$row = array();
$class = '';
$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)";
$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 {
$user_filter = "user_id = ".api_get_user_id()." AND ";
if ($course_info['show_score'] == 0) {
@ -762,6 +827,8 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$count_document = Database::fetch_row($res_document);
$cant_files = $count_document[0];
$cant_files_per_user = getUniqueStudentAttempts($work_data['id'], $course_id);
$text_file = get_lang('FilesUpload');
if ($cant_files == 1) {
@ -803,20 +870,35 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$work_title.'< / a > '.$add_to_name.'< br / > '.$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).'< br / > < span class = "dropbox_date" > '.api_format_date($direc_date_local).'< / span > ';
// $row[] = date_to_str_ago($direc_date_local).'< br / > < span class = "dropbox_date" > '.api_format_date($direc_date_local).'< / span > ';
} else {
$direc_date_local = '0000-00-00 00:00:00';
$row[] = '';
// $row[] = '';
}
/*if (!empty($homework)) {
$row[] = !empty($homework['expires_on']) & & $homework['expires_on'] != '0000-00-00 00:00:00' ? api_get_utc_datetime($homework['expires_on']): '-';
} else {
$row[] = '-';
}*/
if (!empty($homework)) {
$row[] = !empty($homework['ends_on']) & & $homework['ends_on'] != '0000-00-00 00:00:00' ? api_get_utc_datetime($homework['ends_on']): '-';
} else {
$row[] = '-';
}
if ($origin != 'learnpath') {
if ($is_allowed_to_edit) {
$row[] = $cant_files_per_user.'/'.$countUsers;
if (api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION)) {
$action .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL);
$action .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL);
@ -824,13 +906,12 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$action .= '< a href = "'.api_get_self().'?cidReq='.api_get_course_id().'&origin='.$origin.'&gradebook='.$gradebook.'&edit_dir='.$id2.'" > '.Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL).'< / a > ';
$action .= ' < a href = "'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&delete_dir='.$id2.'" onclick = "javascript:if(!confirm('." ' " . addslashes ( api_htmlentities ( get_lang ( ' ConfirmYourChoice ' ) , ENT_QUOTES ) ) . " ' " . ' ) ) return false ; " title = "'.get_lang('DirDelete').'" > '.Display::return_icon('delete.png',get_lang('DirDelete'),'',ICON_SIZE_SMALL).'< / a > ';
}
$row[] = $action;
} else {
$row[] = '';
}
}
$row[] = $direc_date_local;
// $row[] = $direc_date_local;
$row[] = $work_data['title'];
$table_data[] = $row;
}
@ -872,7 +953,8 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
if ($table_has_actions_column) {
$column_show[] = 1; // modify
}
$column_show[] = 0; //real date in correct format
$column_show[] = 1; //real date in correct format
$column_show[] = 0; //real date in correct format
$paging_options = array();
if (isset($_GET['curdirpath'])) {
@ -887,6 +969,7 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
$my_params['origin'] = $origin;
Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order);
}
/**
* Returns a list of subdirectories found in the given directory.
*
@ -1543,7 +1626,8 @@ function get_count_work($work_id) {
return $users_with_work;
}
function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition) {
function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition, $studentId = null)
{
$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);
@ -1590,7 +1674,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
$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,
$select = 'DISTINCT u.user_id, 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) ";
@ -1598,10 +1682,15 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
$work_assignment = get_work_assignment_by_id($work_id);
if (!empty($studentId)) {
$where_condition.= " AND u.user_id = ".intval($studentId);
}
$sql = "SELECT $select
FROM $work_condition $user_condition $course_conditions
WHERE $extra_conditions $where_condition $condition_session ";
$sql .= " ORDER BY $column $direction ";
$sql .= " LIMIT $start, $limit";
@ -1916,7 +2005,8 @@ function user_is_author($item_id, $user_id = null) {
* @author cvargas
* @author Julio Montoya < gugli100 @ gmail . com > Fixing query
*/
function get_list_users_without_publication($task_id) {
function get_list_users_without_publication($task_id, $studentId = null)
{
$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);
@ -1933,6 +2023,7 @@ function get_list_users_without_publication($task_id) {
} else {
$sql = "SELECT user_id as id FROM $work_table WHERE c_id = $course_id AND parent_id='$task_id' and session_id='".$session_id."'";
}
$result = Database::query($sql);
$users_with_tasks = array();
while($row = Database::fetch_array($result)) {
@ -1947,6 +2038,10 @@ function get_list_users_without_publication($task_id) {
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."'";
}
if (!empty($studentId)) {
$sql_users.= "AND u.user_id = ".intval($studentId);
}
$group_id = api_get_group_id();
$new_group_user_list = array();
@ -1986,7 +2081,7 @@ function get_list_users_without_publication($task_id) {
* @author cvargas carlos.vargas@beeznest.com cfasanando, christian.fasanado@beeznest.com
* @author Julio Montoya < gugli100 @ gmail . com > Fixes
*/
function display_list_users_without_publication($task_id) {
function display_list_users_without_publication($task_id, $studentId = null ) {
global $origin;
$table_header[] = array(get_lang('LastName'), true);
$table_header[] = array(get_lang('FirstName'), true);