, 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 $
*/
/**
* 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
*/
require_once dirname(__FILE__).'/../document/document.inc.php';
require_once dirname(__FILE__).'/../inc/lib/fileDisplay.lib.php';
function display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form)
{
global $gradebook;
global $charset;
$display_output = "";
$origin = isset($_GET['origin'])?Security::remove_XSS($_GET['origin']):'';
$curdirpath = isset($_GET['curdirpath'])?Security::remove_XSS($_GET['curdirpath']):empty($curdirpath);
///why is that here?
//$origin = api_get_tools_lists($origin);
echo '
';
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')).' '.get_lang('BackToWorksList').'';
}
else
{
if ($_GET['display_tool_options'] == 'true' OR $_GET['display_upload_form'] == 'true' )
{
if ($origin!='learnpath') {
echo '
'.Display::return_icon('back.png',get_lang('BackToWorksList')).' '.get_lang('BackToWorksList').'';
}
}
}
if (! $always_show_tool_options && api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
// Create dir
if ($cur_dir_path=='/')
{
$display_output .= '
'.Display::return_icon('works_new.gif', get_lang('CreateAssignment')).' '.get_lang('CreateAssignment').' ';
}
// Options
$display_output .= "
".Display::return_icon('acces_tool.gif', get_lang("EditToolOptions")).' ' . get_lang("EditToolOptions") . "";
}
if (! $always_show_upload_form && api_is_allowed_to_session_edit(false,true)) {
$display_output .= "
".Display::return_icon('submit_file.gif', get_lang("UploadADocument"))." ". get_lang("UploadADocument") .'';
}
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.gif', get_lang('Delete')).get_lang('DeleteAllFiles').'';
} else {
$display_output .= "
".
Display::return_icon('delete.gif', get_lang('Delete')).' '.get_lang('DeleteAllFiles')."";
}
// 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 ($columnStatus['Default'] == 1) {
$display_output .= "
".
Display::return_icon('visible.gif', get_lang('MakeAllPapersInvisible')).' '.get_lang('MakeAllPapersInvisible').
"\n";
} else {
$display_output .= "
".
Display::return_icon('invisible.gif', get_lang('MakeAllPapersVisible')).' '.get_lang('MakeAllPapersVisible').
"\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('un_check.gif', get_lang('ViewUsersWithoutTask')).' '.get_lang('ViewUsersWithoutTask').
"\n";
} else {
$display_output .= "
".
Display::return_icon('check.gif', get_lang('ViewUsersWithTask')).' '.get_lang('ViewUsersWithTask').
"\n";
$_SESSION['token'] = time();
$display_output .= "
".
Display::return_icon('messagebox_warning.gif', get_lang('ReminderMessage')).' '.get_lang('ReminderMessage').
"\n";
}
}
}
if ($display_output != "") {
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 $charset, $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 '');
if(empty($default)) {
$default = date('Y-m-d 12:00:00');
}
$parts = split(' ',$default);
list($d_year,$d_month,$d_day) = split('-',$parts[0]);
list($d_hour,$d_minute) = split(':',$parts[1]);
if ((int)$row['weight'] == 0) {
$form_folder -> addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'),'onclick="javascript:if(this.checked==true){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
$form_folder -> addElement('html','
');
$weight_input2[] = FormValidator :: createElement('text','weight');
$form_folder -> addGroup($weight_input2,'weight',get_lang('WeightInTheGradebook'),'size="10"');
$form_folder -> addElement('html','
');
}
if($homework['expires_on']='0000-00-00 00:00:00') {
$homework['expires_on']=date("Y-m-d H:i:s");
$there_is_a_expire_date = true;
$form_folder -> addElement('checkbox', 'enableExpiryDate',null,get_lang('EnableExpiryDate'),'onclick="javascript:if(this.checked==true){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
$form_folder -> addElement('html','
');
$form_folder -> addGroup(create_group_date_select(),'expires',get_lang('ExpiresAt'));
$form_folder -> addElement('html','
');
}
if($homework['ends_on']='0000-00-00 00:00:00') {
$homework['ends_on']=date("Y-m-d H:i:s");
$there_is_a_end_date = true;
$form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'),'onclick="javascript:if(this.checked==true){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');
$form_folder -> addElement('html','
');
}
$form_folder -> addElement('style_submit_button','submit',get_lang('ModifyDirectory'),'class="save"');
if($there_is_a_end_date == true) {
$defaults = array_merge($defaults,convert_date_to_array($homework['ends_on'],'ends'));
}
if($there_is_a_expire_date == true) {
$defaults = array_merge($defaults,convert_date_to_array($homework['expires_on'],'expires'));
}
if(!empty($row['qualification'])) {
$defaults = array_merge($defaults,array('qualification[qualification]'=>$row['qualification']));
}
if(!empty($row['weight'])) {
$defaults = array_merge($defaults,array('weight[weight]'=>$row['weight']));
}
$form_folder -> setDefaults($defaults);
$display_edit_form=true;
if($form_folder -> validate()) {
$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
if($there_is_a_end_date == true || $there_is_a_expire_date == true) {
if($row['view_properties']=='1') {
$sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
Database::query($sql_add_publication);
$expires_query= ' SET expires_on = '."'".(($there_is_a_expire_date == true)?get_date_from_group('expires'):'0000-00-00 00:00:00')."'".',';
$ends_query = ' ends_on = '."'".(($there_is_a_end_date == true) ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
Database::query('UPDATE '.$work_assigment.$expires_query.$ends_query.' WHERE id = '."'".$row['has_properties']."'");
} else if($row['view_properties']=='0') {
if ($_POST['enableExpiryDate']=='1') {
$expires_query= ' SET expires_on = '."'".(($there_is_a_expire_date == true)?get_date_from_group('expires'):'0000-00-00 00:00:00')."'";
//$ends_query = ' ends_on = '."'".(($there_is_a_end_date == true) ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
Database::query('UPDATE '.$work_assigment.$expires_query.' WHERE id = '."'".$row['has_properties']."'");
$sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
Database::query($sql_add_publication);
}
if ($_POST['enableEndDate']=='1') {
//$expires_query= ' SET expires_on = '."'".(($there_is_a_expire_date == true)?get_date_from_group('expires'):'0000-00-00 00:00:00')."'".',';
$ends_query = ' SET ends_on = '."'".(($there_is_a_end_date == true) ? get_date_from_group('ends') : '0000-00-00 00:00:00')."'";
Database::query('UPDATE '.$work_assigment.$ends_query.' WHERE id = '."'".$row['has_properties']."'");
$sql_add_publication = "UPDATE ".$work_table." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'";
Database::query($sql_add_publication);
}
}
}
//if($_POST['qualification']['qualification']!='')
Database::query('UPDATE '.$work_table.' SET description = '."'".Database::escape_string(Security::remove_XSS($_POST['description']))."'".', qualification = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".',weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".' WHERE id = '."'".$row['id']."'");
Database::query('UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).' SET weight = '."'".Database::escape_string($_POST['weight']['weight'])."'".' WHERE course_code = '."'".api_get_course_id()."'".' AND ref_id = '."'".$row['id']."'".'');
//we are changing the current work and we want add them into gradebook
if(isset($_POST['make_calification']) && $_POST['make_calification']==1) {
require_once('../gradebook/lib/be/gradebookitem.class.php');
require_once('../gradebook/lib/be/evaluation.class.php');
require_once('../gradebook/lib/be/abstractlink.class.php');
require_once('../gradebook/lib/gradebook_functions.inc.php');
$resource_name = Security::remove_XSS($_POST['dir_name']);
add_resource_to_course_gradebook(api_get_course_id(), 3, $row['id'], Database::escape_string($resource_name),(float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], Database::escape_string($_POST['description']),time(), 1,api_get_session_id());
}
Display::display_confirmation_message(get_lang('FolderEdited'));
$values = $form_folder -> exportValues();
$values = $values['my_group'];
$dir_name = replace_dangerous_char($values['dir_name']);
$dir_name = disable_dangerous_file($dir_name);
update_dir_name($mydir,$dir_name);
$mydir = $my_sub_dir.$dir_name;
$dir = $dir_name;
$display_edit_form=false;
// gets calendar_id from student_publication_assigment
$sql = "SELECT add_to_calendar FROM $work_assigment WHERE publication_id ='".$row['id']."'";
$res = Database::query($sql);
$calendar_id = Database::fetch_row($res);
// update from agenda if it exists
if (!empty($calendar_id[0])) {
$sql = "UPDATE ".$TABLEAGENDA."
SET title='".$dir_name."',
content = '".$dir_name."',
end_date='".get_date_from_group('ends')."'
WHERE id='".$calendar_id[0]."'";
Database::query($sql);
}
}
}
}
$action = '';
$row = array();
$class = '';
$row[] = '