From ba7c4545a1a72e0e12c6ff227d933e4eda84e25d Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 24 Nov 2008 21:35:40 +0100 Subject: [PATCH] [svn r16891] New dates management for work tool (part of FS#3249) --- main/work/work.lib.php | 2414 ++++++++++++++++++++-------------------- main/work/work.php | 909 ++++++--------- 2 files changed, 1556 insertions(+), 1767 deletions(-) diff --git a/main/work/work.lib.php b/main/work/work.lib.php index cc6aa0dcb4..5f351761f0 100644 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -1,1200 +1,1214 @@ -, 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: $ -*/ -/** - * 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('../document/document.inc.php'); -require_once('../inc/lib/fileDisplay.lib.php'); - - -function display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form) -{ - $display_output = '
'; - if(strlen($cur_dir_path) > 0 && $cur_dir_path != '/') - { - $parent_dir = dirname($cur_dir_path); - $display_output .= ''.Display::return_icon('folder_up.gif').' '.get_lang('Up').'  '; - - - } - - if (! $always_show_upload_form ) - { - $display_output .= "  ".Display::return_icon('submit_file.gif', get_lang("UploadADocument"))." ". get_lang("UploadADocument") .'    '; - } - - if (! $always_show_tool_options && api_is_allowed_to_edit(false,true) ) - { - // Create dir - $display_output .= ''.get_lang('CreateDir').' '.get_lang('CreateDir').'   '; - - - if(api_is_allowed_to_edit()) // the coach can't edit options of the tool - // Options - $display_output .= "".Display::return_icon('acces_tool.gif', get_lang("EditToolOptions")).' ' . get_lang("EditToolOptions") . "  "; - } - - 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; - $is_allowed_to_edit = api_is_allowed_to_edit(false,true); - $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - - if (! $is_allowed_to_edit) return; - - echo '
'; - - echo "
\n", - "\n", - "", - ""; - - display_default_visibility_form($uploadvisibledisabled); - - echo '
 ".get_lang("Modify")."
", - get_lang('AllFiles')." : ", - "\"".get_lang('Delete')."\"", - "", - " "; - - $sql_query = "SHOW COLUMNS FROM ".$work_table." LIKE 'accepted'"; - $sql_result = api_sql_query($sql_query,__FILE__,__LINE__); - - if ($sql_result) - { - $columnStatus = mysql_fetch_array($sql_result); - - if ($columnStatus['Default'] == 1) - { - echo "", - "\"".get_lang('Invisible')."\"", - "\n"; - } - else - { - echo "", - "\"".get_lang('Visible')."\"", - "\n"; - } - } - - echo "
'; - - echo '
'.get_lang("ValidateChanges").' :
'; - -/* - echo "
\n"; - - //============================================================================== - // Display directories list - //============================================================================== - - - //$folders = DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit || $group_member_with_upload_rights); - if($cur_dir_path=='/'){$my_cur_dir_path='';}else{$my_cur_dir_path=$cur_dir_path;} - $folders = get_subdirs_list($base_work_dir,1); - echo '
'; - echo(build_work_directory_selector($folders,$cur_dir_path,'')); - echo '
'; - echo '
'; - if ($cur_dir_path!= '/' && $cur_dir_path!=$group_properties['directory']) - { - echo ''. - ''. - get_lang("Up").' '."\n"; -} - echo '' . - ''.get_lang('CreateDir').''. - ''.get_lang('CreateDir').' '."\n"; - 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 -* @version march 2006 -*/ -function display_user_link($user_id, $name='') -{ - global $_otherusers; - - if ($user_id<>0) - { - if ($name=='') - { - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $sql="SELECT * FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'"; - $result=api_sql_query($sql,__FILE__,__LINE__); - $row=mysql_fetch_array($result); - return "".$row['firstname']." ".$row['lastname'].""; - } - else - { - return "".$name.""; - } - } - else - { - return $name.' ('.get_lang('Anonymous').')'; - } -} - -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($d_hour, $d_minute, $d_second, $d_month, $d_day, $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); - list($data[$group.'[year]'],$data[$group.'[month]'],$data[$group.'[day]']) = split('-',$parts[0]); - list($data[$group.'[hour]'],$data[$group.'[minute]']) = split(':',$parts[1]); - return $data; - - } - - 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'; - } - - 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.'year','',array($d_year=>$d_year,$d_year+1=>$d_year+1)); - $group_name[] = FormValidator :: createElement('select',$prefix.'month','',array_combine(range(1,12),array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'))); - $group_name[] = FormValidator :: createElement('select',$prefix.'day','',array_combine(range(1,31),range(1,31))); - $group_name[] = FormValidator :: createElement('select',$prefix.'hour','',array_combine(range(1,24),range(1,24))); - $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 $charset; - // Database table names - $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); - $is_allowed_to_edit = api_is_allowed_to_edit(false,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); - - $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=''; - } - - $session_condition = intval($_SESSION['id_session'])!=0 ?"AND session_id IN (0,".intval($_SESSION['id_session']).")" : ""; - //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. - $session_condition. - "ORDER BY id"; - - $sql_get_publications_num = "SELECT count(*) " . - "FROM ".$work_table." " . - "WHERE url LIKE BINARY '$sub_course_dir%' " .$add_in_where_query. - "AND url NOT LIKE BINARY '$sub_course_dir%/%' " . - $session_condition. - "ORDER BY id"; - - } - else - { - if (!empty($_SESSION['toolgroup'])) - { - $group_query = " WHERE post_group_id = '".$_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 = ''; - $subdirs_query = "WHERE 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." AND session_id IN (0,".intval($_SESSION['id_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. - $session_condition. - "ORDER BY id"; - - } - - $sql_result = api_sql_query($sql_get_publications_list,__FILE__,__LINE__); - $sql_result_num = api_sql_query($sql_get_publications_num,__FILE__,__LINE__); - - $row=Database::fetch_array($sql_result_num); - $count_files=$row[0]; - - $table_header[] = array(get_lang('Type'),true,'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('Date'),true); - - if( $is_allowed_to_edit) - { - $table_header[] = array(get_lang('Modify'),true); - } - - $table_header[] = array('RealDate',false); - - // 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; //date - - if( $is_allowed_to_edit) - { - $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[]=1; //type - $column_order[]=2; // title - - if ($count_files!=0) - { - $column_order[]=3; //authors - } - - $column_order[]=6; // date - - if( $is_allowed_to_edit) - { - $column_order[]=5; - } - - $column_order[]=6; - - $table_data = array(); - $dirs_list = get_subdirs_list($work_dir); - $my_sub_dir = str_replace('work/','',$sub_course_dir); - - // List of all folders - foreach($dirs_list as $dir) - { - if ($my_sub_dir=='') - { - $mydir_temp = '/'.$dir; - } - else - { - $mydir_temp = '/'.$my_sub_dir.$dir; - } - - // select the directory's date - /*$sql_select_directory= "SELECT sent_date FROM ".$work_table." WHERE " . - "url LIKE BINARY '".$mydir_temp."' AND filetype = 'folder'"; - - */ - $session_condition = intval($_SESSION['id_session'])!=0 ?"AND work.session_id IN (0,".intval($_SESSION['id_session']).")" : ""; - $sql_select_directory= "SELECT prop.lastedit_date, id, author, has_properties, view_properties, description, qualification,id FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE " . - "work.url LIKE BINARY '".$mydir_temp."' AND work.filetype = 'folder' AND prop.tool='work' $session_condition"; - $result=api_sql_query($sql_select_directory,__FILE__,__LINE__); - $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 - $folder_session_id = $row['session_id']; - $view_properties=$row['view_properties']; - $is_assignment = $row['has_properties']; - $id2=$row['id']; - - $mydir = $my_sub_dir.$dir; - - if ($is_allowed_to_edit) - { - - $clean_edit_dir=Security :: remove_XSS(Database::escape_string($_GET['edit_dir'])); - - // form edit directory - if(isset($clean_edit_dir) && $clean_edit_dir==$mydir) - { - if(!empty($row['has_properties'])){ - $sql = api_sql_query('SELECT * FROM '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).' WHERE id = '."'".$row['has_properties']."'".' LIMIT 1',__FILE__,__LINE__); - $homework = mysql_fetch_array($sql); - } - - $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?curdirpath='.$my_sub_dir.'&origin='.$origin.'&edit_dir='.$mydir); - //echo $row['view_properties']; - //echo $row['has_properties']; - - $group_name[] = FormValidator :: createElement('text','dir_name'); - $form_folder-> addElement('textarea','description',get_lang('Description'),array('rows'=>5,'cols'=>50)); - $qualification_input[] = FormValidator :: createElement('text','qualification'); - $form_folder -> addGroup($qualification_input,'qualification',get_lang('Qualification'),'size="10"'); - if($row['view_properties']=='1'){ - if($homework['expires_on']!='0000-00-00 00:00:00'){ - $there_is_a_expire_date = true; - $form_folder -> addGroup(create_group_date_select(),'expires',get_lang('Expires_At')); - } - if($homework['ends_on']!='0000-00-00 00:00:00'){ - $there_is_a_end_date = true; - $form_folder -> addGroup(create_group_date_select(),'ends',get_lang('Ends_At')); - } - $form_folder -> addRule (array('expires','ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); - - } - else - { - //$form_folder -> addElement('checkbox', 'enableRandom', null, get_lang('MakeRandom'),'1'); - $form_folder -> addElement('html','
-
 
- -
'); - - $form_folder -> addElement('html',''); - } - - $group_name[] = FormValidator :: createElement('submit','submit_edit_dir',get_lang('Ok')); - $form_folder -> addGroup($group_name,'my_group'); - $form_folder -> addGroupRule('my_group',get_lang('ThisFieldIsRequired'),'required'); - - $defaults = array('my_group[dir_name]'=>$dir,'description'=>$row['description']); - 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'])); - - $form_folder -> setDefaults($defaults); - $display_edit_form=true; - - if($form_folder -> validate()) - { - if($there_is_a_end_date == true || $there_is_a_expire_date == true) - { - if($row['view_properties']=='1') - { - $sql_add_publication = "UPDATE ".Database :: get_course_table(TABLE_STUDENT_PUBLICATION)." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'"; - api_sql_query($sql_add_publication, __FILE__, __LINE__); - $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')."'"; - api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).$expires_query.$ends_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__); - } - else if($row['view_properties']=='0') - { - - if ($_POST['enableRandomExpires']=='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')."'"; - api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).$expires_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__); - $sql_add_publication = "UPDATE ".Database :: get_course_table(TABLE_STUDENT_PUBLICATION)." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'"; - api_sql_query($sql_add_publication, __FILE__, __LINE__); - } - if ($_POST['enableRandomEnds']=='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')."'"; - api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).$ends_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__); - $sql_add_publication = "UPDATE ".Database :: get_course_table(TABLE_STUDENT_PUBLICATION)." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'"; - api_sql_query($sql_add_publication, __FILE__, __LINE__); - } - } - - } - //if($_POST['qualification']['qualification']!='') - api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION).' SET description = '."'".Database::escape_string($_POST['description'])."'".', qualification = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".' WHERE id = '."'".$row['id']."'",__FILE__,__LINE__); - - - - $values = $form_folder -> exportValues(); - $values = $values['my_group']; - update_dir_name($mydir,$values['dir_name']); - $mydir = $my_sub_dir.$values['dir_name']; - $dir = $values['dir_name']; - $display_edit_form=false; - } - } - } - - $action = ''; - $row = array(); - $class = ''; - $row[] = ''.get_lang('Folder').''; //image - $a_count_directory=count_dir($work_dir.'/'.$dir,false); - $cant_files=$a_count_directory[0]; - $cant_dir=$a_count_directory[1]; - - $text_file=get_lang('FilesUpload'); - $text_dir=get_lang('Directories'); - - if ($cant_files==1) - { - $text_file=strtolower(get_lang('FileUpload')); - } - - if ($cant_dir==1) - { - $text_dir=get_lang('directory'); - } - - if ($cant_dir!=0) - { - $dirtext=' ('.$cant_dir.' '.$text_dir.')'; - } - else - { - $dirtext=''; - } - - if($display_edit_form && isset($clean_edit_dir) && $clean_edit_dir==$mydir) - { - $row[] = ''.$form_folder->toHtml(); // form to edit the directory's name - } - else - { - $add_to_name = ''; - if($view_properties==1) $add_to_name = ' / '.get_lang('Assignment').''; - $row[] = ''.$dir.''.$add_to_name.'
'.$cant_files.' '.$text_file.$dirtext; - } - - if ($count_files!=0) - { - $row[] = ""; - } - - if ($direc_date!='' && $direc_date!='0000-00-00 00:00:00') - { - $row[]= date_to_str_ago($direc_date).'
'.$direc_date.''; - } - else - { - $row[]=''; - } - if( $is_allowed_to_edit && !(api_is_course_coach() && $folder_session_id!=$_SESSION['id_session'])) - { - $action .= ''.get_lang('Modify').''; - $action .= ''.get_lang('DirDelete').''; - $row[] = $action; - } - else - { - $row[] = ""; - } - $table_data[] = $row; - } - - while( $work = mysql_fetch_object($sql_result)) - { - //Get the author ID for that document from the item_property table - $is_author = false; - $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=".$work->id; - $author_qry = api_sql_query($author_sql,__FILE__,__LINE__); - - if(Database::num_rows($author_qry)==1) - { - $is_author = true; - } - - //display info depending on the permissions - if( $work->accepted == '1' || $is_allowed_to_edit) - { - $row = array(); - if($work->accepted == '0') - { - $class='class="invisible"'; - } - else - { - $class=''; - } - - if(true || defined('IS_ASSIGNMENT')): - $add_string = ''; - if($work->qualificator_id==0) - $qualification_string = ' / '.get_lang('NotRevised').''; - else - $qualification_string = ' / '.get_lang('Qualification').': '.$work->qualification.''; - - if(defined('ASSIGNMENT_EXPIRES') && (ASSIGNMENT_EXPIRES < convert_date_to_number($work->sent_date))){ - $add_string = ' '.get_lang('Expired').''; - } - endif; - - $url = implode("/", array_map("rawurlencode", explode("/", $work->url))); - $row[]= build_document_icon_tag('file',$work->url); - $row[]= ''.get_lang('Download').''.$work->title.'
'.$work->description; - $row[]= display_user_link($user_id,$work->author).$qualification_string;// $work->author; - $row[]= date_to_str_ago($work->sent_date).$add_string.'
'.$work->sent_date.''; - - if( $is_allowed_to_edit && !(api_is_course_coach() && $work->session_id!=$_SESSION['id_session'])) - { - $action = ''; - $action .= ''.get_lang('Modify').''; - $action .= ''.get_lang('WorkDelete').''; - $action .= ''; - if($work->accepted == '1') - { - $action .= ''.get_lang('Invisible').''; - } - else - { - $action .= ''.get_lang('Visible').''; - } - - $row[] = $action; - } - elseif($is_author) - { - $action = ''; - $action .= ''.get_lang('Modify').''; - $action .= ''.get_lang('WorkDelete').''; - - $row[] = $action; - } - else - { - $row[] = " "; - } - $table_data[] = $row; - } - } - - $sorting_options=array(); - $sorting_options['column']=1; - - $paging_options=array(); - Display::display_sortable_config_table($table_header,$table_data,$sorting_options, $paging_options,NULL,$column_show,$column_order); -} -/** - * Returns a list of subdirectories found in the given directory. - * - * The list return starts from the given base directory. - * If you require the subdirs of /var/www/ (or /var/www), you will get 'abc/', 'def/', but not '/var/www/abc/'... - * @param string Base dir - * @param integer 0 if we only want dirs from this level, 1 if we want to recurse into subdirs - * @return strings_array The list of subdirs in 'abc/' form, -1 on error, and 0 if none found - * @todo Add a session check to see if subdirs_list doesn't exist yet (cached copy) - */ -function get_subdirs_list($basedir='',$recurse=0){ - //echo "Looking for subdirs of $basedir"; - if(empty($basedir) or !is_dir($basedir)){return -1;} - if(substr($basedir,-1,1)!='/'){$basedir = $basedir.'/';} - $dirs_list = array(); - $dh = opendir($basedir); - while($entry = readdir($dh)){ - if(is_dir($basedir.$entry) && $entry!='..' && $entry!='.'){ - $dirs_list[] = $entry; - if($recurse==1){ - foreach(get_subdirs_list($basedir.$entry) as $subdir){ - $dirs_list[] = $entry.'/'.$subdir; - } - } - } - } - closedir($dh); - return $dirs_list; -} -/** - * Builds the form thats enables the user to - * select a directory to browse/upload in - * This function has been copied from the document/document.inc.php library - * - * @param array $folders - * @param string $curdirpath - * @param string $group_dir - * @return string html form - */ -function build_work_directory_selector($folders,$curdirpath,$group_dir='') -{ - $form = '
'."\n"; - $form .= get_lang('CurrentDirectory').' '."\n"; - $form .= ''."\n"; - $form .= '
'; - - return $form; -} -/** - * Builds the form thats enables the user to - * move a document from one directory to another - * This function has been copied from the document/document.inc.php library - * - * @param array $folders - * @param string $curdirpath - * @param string $move_file - * @return string html form - */ -function build_work_move_to_selector($folders,$curdirpath,$move_file,$group_dir='') -{ - $form = '
'."\n"; - $form .= ''."\n"; - $form .= get_lang('MoveTo').' '."\n"; - $form .= ''."\n"; - $form .= '
'; - - return $form; -} -/** - * Checks if the first given directory exists as a subdir of the second given directory - * This function should now be deprecated by Security::check_abs_path() - * @param string Subdir - * @param string Base dir - * @return integer -1 on error, 0 if not subdir, 1 if subdir - */ -function is_subdir_of($subdir,$basedir){ - if(empty($subdir) or empty($basedir)){return -1;} - if(substr($basedir,-1,1)!='/'){$basedir=$basedir.'/';} - if(substr($subdir,0,1)=='/'){$subdir = substr($subdir,1);} - if(is_dir($basedir.$subdir)){ - return 1; - }else{ - return 0; - } -} -/** - * creates a new directory trying to find a directory name - * that doesn't already exist - * (we could use unique_name() here...) - * - * @author Hugues Peeters - * @author Bert Vanderkimpen - * @author Yannick Warnier Adaptation for work tool - * @param string Base work dir (.../work) - * @param string $desiredDirName complete path of the desired name - * @return string actual directory name if it succeeds, - * boolean false otherwise - */ - -function create_unexisting_work_directory($base_work_dir,$desired_dir_name) -{ - $nb = ''; - $base_work_dir = (substr($base_work_dir,-1,1)=='/'?$base_work_dir:$base_work_dir.'/'); - while ( file_exists($base_work_dir.$desired_dir_name.$nb) ) - { - $nb += 1; - } - //echo "creating ".$base_work_dir.$desired_dir_name.$nb."#..."; - $perm = api_get_setting('permissions_for_new_directories'); - $perm = octdec(!empty($perm)?$perm:'0770'); - if ( mkdir($base_work_dir.$desired_dir_name.$nb, $perm)) - { - chmod($base_work_dir.$desired_dir_name.$nb, $perm); - return $desired_dir_name.$nb; - } - else - { - return false; - } -} -/** - * Delete a work-tool directory - * @param string Base "work" directory for this course as /var/www/dokeos/courses/ABCD/work/ - * @param string The directory name as the bit after "work/", without trailing slash - * @return integer -1 on error - */ -function del_dir($base_work_dir,$dir) -{ - if(empty($dir) or $dir=='/'){return -1;}//not authorized - //escape hacks -/* - $dir = str_replace('../','',$dir); - $dir = str_replace('..','',$dir); - $dir = str_replace('./','',$dir); - $dir = str_replace('.','',$dir); -*/ - $check = Security::check_abs_path($base_work_dir.$dir,$base_work_dir); - if (!$check || !is_dir($base_work_dir.$dir)) return -1; - $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $sql = "DELETE FROM $table WHERE url LIKE BINARY 'work/".$dir."/%'"; - if(api_is_course_coach()) - { - $sql .= ' AND session_id='.intval($_SESSION['id_session']); - } - $res = api_sql_query($sql,__FILE__,__LINE__); - - //delete from DB the directories - $sql = "DELETE FROM $table WHERE filetype = 'folder' AND url LIKE BINARY '/".$dir."%'"; - if(api_is_course_coach()) - { - $sql .= ' AND session_id='.intval($_SESSION['id_session']); - } - $res = api_sql_query($sql,__FILE__,__LINE__); - - if(Database::affected_rows()>0) - { - require_once(api_get_path(LIBRARY_PATH).'/fileManage.lib.php'); - my_delete($base_work_dir.$dir); - } -} -/** - * Get the path of a document in the student_publication table (path relative to the course directory) - * @param integer Element ID - * @return string Path (or -1 on error) - */ -function get_work_path($id){ - $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $sql = "SELECT * FROM $table WHERE id=$id"; - $res = api_sql_query($sql); - if(Database::num_rows($res)!=1){ - return -1; - }else{ - $row = Database::fetch_array($res); - return $row['url']; - } -} -/** - * Update the url of a work in the student_publication table - * @param integer ID of the work to update - * @param string Destination directory where the work has been moved (must end with a '/') - * @return -1 on error, sql query result on success - */ -function update_work_url($id,$new_path) -{ - if(empty($id)) return -1; - $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $sql = "SELECT * FROM $table WHERE id=$id"; - $res = api_sql_query($sql); - if(Database::num_rows($res)!=1){ - return -1; - }else{ - $row = Database::fetch_array($res); - $filename = basename($row['url']); - $new_url = $new_path.$filename; - $sql2 = "UPDATE $table SET url = '$new_url' WHERE id=$id"; - $res2 = api_sql_query($sql2); - return $res2; - } -} - -/** - * Update the url of a dir in the student_publication table - * @param string old path - * @param string new path - */ -function update_dir_name($path, $new_name) -{ - global $base_work_dir; - - include_once(api_get_path(LIBRARY_PATH) . "/fileManage.lib.php"); - include_once(api_get_path(LIBRARY_PATH) . "/fileUpload.lib.php"); - - $path_to_dir = dirname($path); - - if($path_to_dir=='.') - { - $path_to_dir = ''; - } - else - { - $path_to_dir .= '/'; - } - - my_rename($base_work_dir.'/'.$path,$new_name); - $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - - //update all the files in the other directories according with the next query - $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "work/'.$path.'/%"'; // like binary (Case Sensitive) - - $rs = api_sql_query($sql, __FILE__, __LINE__); - $work_len=strlen('work/'.$path); - while($work = Database :: fetch_array($rs)) - { - $new_dir=$work['url']; - $name_with_directory=substr($new_dir,$work_len,strlen($new_dir)); - $sql = 'UPDATE '.$table.' SET url="work/'.$path_to_dir.$new_name.$name_with_directory.'" WHERE id= '.$work['id']; - api_sql_query($sql, __FILE__, __LINE__); - } - - //update all the directory's children according with the next query - $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "/'.$path.'%"'; - $rs = api_sql_query($sql, __FILE__, __LINE__); - $work_len=strlen('/'.$path); - while($work = Database :: fetch_array($rs)) - { - $new_dir=$work['url']; - $name_with_directory=substr($new_dir,$work_len,strlen($new_dir)); - $sql = 'UPDATE '.$table.' SET url="/'.$path_to_dir.$new_name.$name_with_directory.'" WHERE id= '.$work['id']; - api_sql_query($sql, __FILE__, __LINE__); - } -} - -/** - * Return an array with all the folder's ids that are in the given path - * @param string Path of the directory - * @return array The list of ids of all the directories in the path - * @author Julio Montoya Dokeos - * @version April 2008 - */ - - function get_parent_directories($my_cur_dir_path) -{ - $list_parents = explode('/', $my_cur_dir_path); - $dir_acum = ''; - global $work_table; - $list_id=array(); - for ($i = 0; $i < count($list_parents) - 1; $i++) - { - $where_sentence = "url LIKE BINARY '" . $dir_acum . "/" . $list_parents[$i]."'"; - $dir_acum .= '/' . $list_parents[$i]; - $sql = "SELECT id FROM ". $work_table . " WHERE ". $where_sentence; - $result = api_sql_query($sql, __FILE__, __LINE__); - $row= Database::fetch_array($result); - $list_id[]=$row['id']; - } - return $list_id; -} - -/** - * Transform an all directory structure (only directories) in an array - * @param string path of the directory - * @return array the directory structure into an array - * @author Julio Montoya Dokeos - * @version April 2008 - */ -function directory_to_array($directory) -{ - $array_items = array(); - if ($handle = opendir($directory)) - { - while (false !== ($file = readdir($handle))) - { - if ($file != "." && $file != "..") - { - if (is_dir($directory. "/" . $file)) - { - $array_items = array_merge($array_items, directory_to_array($directory. "/" . $file)); - $file = $directory . "/" . $file; - $array_items[] = preg_replace("/\/\//si", "/", $file); - } - } - } - closedir($handle); - } - return $array_items; -} - -/** - * Insert into the DB of the course all the directories - * @param string path of the /work directory of the course - * @return -1 on error, sql query result on success - * @author Julio Montoya Dokeos - * @version April 2008 - */ - -function insert_all_directory_in_course_table($base_work_dir) -{ - $dir_to_array =directory_to_array($base_work_dir,true); - $only_dir=array(); - - for($i=0;$i"; - print_r($only_dir); - echo "
";
-	*/
-	for($i=0;$iRead())
-    {    
-    	if (!(($entry == "..") || ($entry == ".")))
-		{		
-        	if (is_dir($path_dir.'/'.$entry))
-        	{       		
-        		$count_dir++;
-          		if ($recurse)
-          		{
-            		$count += count_dir($path_dir . '/' . $entry, $recurse);
-          		}
-          		
-        	}
-			else
-        	{
-        		$count++;
-        	}
-		}
-	}
-	$return_array=array();
-	$return_array[]=$count;
-	$return_array[]=$count_dir;	
-    return $return_array;
-}
-?>
+, 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: $
+*/
+/**
+ * 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 '../document/document.inc.php';
+require_once '../inc/lib/fileDisplay.lib.php';
+
+
+function display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form) 
+{
+	$display_output = "";
+	if(strlen($cur_dir_path) > 0 && $cur_dir_path != '/') {
+		$parent_dir = dirname($cur_dir_path);
+		$display_output .= ''.Display::return_icon('folder_up.gif').' '.get_lang('Up').'  ';
+	}
+	
+	if (! $always_show_upload_form ) {
+		$display_output .= "  ".Display::return_icon('submit_file.gif')." ". get_lang("UploadADocument") .'    ';			
+	}
+	
+	if (! $always_show_tool_options && api_is_allowed_to_edit()) {
+		// Create dir
+		$display_output .=	''.get_lang('CreateDir').' '.get_lang('CreateDir').'   ';
+		// Options
+		$display_output .=	"".Display::return_icon('acces_tool.gif').' ' . get_lang("EditToolOptions") . "  ";							
+	}
+
+	if ($display_output != "") {
+		echo $display_output;
+	}
+}
+
+/**
+* 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;
+	$is_allowed_to_edit = api_is_allowed_to_edit();
+	$work_table 		= Database::get_course_table(TABLE_STUDENT_PUBLICATION);
+
+	if (! $is_allowed_to_edit) {
+		return;
+	}
+	echo '
'; + + echo "
\n", + "\n", + "", + ""; + display_default_visibility_form($uploadvisibledisabled); + echo '
 ".get_lang("Modify")."
", + get_lang('AllFiles')." : ", + "\"".get_lang('Delete')."\"", + "", + " "; + + $sql_query = "SHOW COLUMNS FROM ".$work_table." LIKE 'accepted'"; + $sql_result = api_sql_query($sql_query,__FILE__,__LINE__); + + if ($sql_result) { + $columnStatus = mysql_fetch_array($sql_result); + + if ($columnStatus['Default'] == 1) { + echo "", + "\"".get_lang('Invisible')."\"", + "\n"; + } else { + echo "", + "\"".get_lang('Visible')."\"", + "\n"; + } + } + echo "
'; + echo '
'.get_lang("ValidateChanges").' :
'; + +} + +/** +* 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 +* @version march 2006 +*/ +function display_user_link($user_id, $name='') +{ + global $_otherusers; + + if ($user_id<>0) { + if ($name=='') { + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $sql="SELECT * FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'"; + $result=api_sql_query($sql,__FILE__,__LINE__); + $row=mysql_fetch_array($result); + return "".$row['firstname']." ".$row['lastname'].""; + } else { + return "".$name.""; + } + } else { + return $name.' ('.get_lang('Anonymous').')'; + } +} + +/** +* converts 2008-10-06 12:45:00 to timestamp +*/ +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($d_hour, $d_minute, $d_second, $d_month, $d_day, $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); + list($data[$group.'[year]'],$data[$group.'[month]'],$data[$group.'[day]']) = split('-',$parts[0]); + list($data[$group.'[hour]'],$data[$group.'[minute]']) = split(':',$parts[1]); + 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.'year','',array($d_year=>$d_year,$d_year+1=>$d_year+1)); + $group_name[] = FormValidator :: createElement('select',$prefix.'month','',array_combine(range(1,12),array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'))); + $group_name[] = FormValidator :: createElement('select',$prefix.'day','',array_combine(range(1,31),range(1,31))); + $group_name[] = FormValidator :: createElement('select',$prefix.'hour','',array_combine(range(1,24),range(1,24))); + $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 $charset; + // Database table names + $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); + $is_allowed_to_edit = api_is_allowed_to_edit(); + $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); + + $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=''; + } + + $session_condition = intval($_SESSION['id_session'])!=0 ?"AND session_id IN (0,".intval($_SESSION['id_session']).")" : ""; + //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. + $session_condition. + "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. + $session_condition. + "ORDER BY id"; + + } else { + if (!empty($_SESSION['toolgroup'])) { + $group_query = " WHERE post_group_id = '".$_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 = ''; + $subdirs_query = "WHERE 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." AND session_id IN (0,".intval($_SESSION['id_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. + $session_condition. + "ORDER BY id"; + + } + + $sql_result = api_sql_query($sql_get_publications_list,__FILE__,__LINE__); + $sql_result_num = api_sql_query($sql_get_publications_num,__FILE__,__LINE__); + + $row=Database::fetch_array($sql_result_num); + $count_files=$row[0]; + + $table_header[] = array(get_lang('Type'),true,'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('Date'),true); + + if( $is_allowed_to_edit) { + $table_header[] = array(get_lang('Modify'),true); + } + + $table_header[] = array('RealDate',false); + + // 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; //date + + if( $is_allowed_to_edit) { + $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[]=1; //type + $column_order[]=2; // title + + if ($count_files!=0) { + $column_order[]=3; //authors + } + + $column_order[]=6; // date + + if( $is_allowed_to_edit) { + $column_order[]=5; + } + + $column_order[]=6; + + $table_data = array(); + $dirs_list = get_subdirs_list($work_dir); + + $my_sub_dir = str_replace('work/','',$sub_course_dir); + + // List of all folders + foreach($dirs_list as $dir) { + if ($my_sub_dir=='') { + $mydir_temp = '/'.$dir; + }else { + $mydir_temp = '/'.$my_sub_dir.$dir; + } + + $session_condition = intval($_SESSION['id_session'])!=0 ?"AND work.session_id IN (0,".intval($_SESSION['id_session']).")" : ""; + $sql_select_directory= "SELECT prop.lastedit_date, id, author, has_properties, view_properties, description, qualification,id FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE " . + "work.url LIKE BINARY '".$mydir_temp."' AND work.filetype = 'folder' AND prop.tool='work' $session_condition"; + $result=api_sql_query($sql_select_directory,__FILE__,__LINE__); + $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) { + $clean_edit_dir=Security :: remove_XSS(Database::escape_string($_GET['edit_dir'])); + + // form edit directory + if(isset($clean_edit_dir) && $clean_edit_dir==$mydir) { + if(!empty($row['has_properties'])) { + $sql = api_sql_query('SELECT * FROM '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).' WHERE id = '."'".$row['has_properties']."'".' LIMIT 1',__FILE__,__LINE__); + $homework = mysql_fetch_array($sql); + } + + $form_folder = new FormValidator('edit_dir', 'post', api_get_self().'?curdirpath='.$my_sub_dir.'&origin='.$origin.'&edit_dir='.$mydir); + + $group_name[] = FormValidator :: createElement('text','dir_name'); + //$group_name[] = FormValidator :: createElement('submit','submit_edit_dir',get_lang('Ok')); + + $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]'=>$dir,'description'=>$row['description']); + $form_folder-> addElement('textarea','description',get_lang('Description'),array('rows'=>5,'cols'=>50)); + $qualification_input[] = FormValidator :: createElement('text','qualification'); + + $form_folder -> addGroup($qualification_input,'qualification',get_lang('QualificationNumberOver'),'size="10"'); + + if($row['view_properties']=='1') { + if($homework['expires_on']!='0000-00-00 00:00:00'){ + $there_is_a_expire_date = true; + $form_folder -> addGroup(create_group_date_select(),'expires',get_lang('Expires_At')); + } + if($homework['ends_on']!='0000-00-00 00:00:00') { + $there_is_a_end_date = true; + $form_folder -> addGroup(create_group_date_select(),'ends',get_lang('Ends_At')); + } + $form_folder -> addRule(array('expires','ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); + } + else { + $form_folder -> addElement('html',' '); + + $form_folder -> addElement('html',''); + } + + $form_folder -> addElement('submit','submit_edit_dir',get_lang('Ok')); + + + + + 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'])); + } + $form_folder -> setDefaults($defaults); + $display_edit_form=true; + + if($form_folder -> validate()) { + if($there_is_a_end_date == true || $there_is_a_expire_date == true) { + if($row['view_properties']=='1') { + $sql_add_publication = "UPDATE ".Database :: get_course_table(TABLE_STUDENT_PUBLICATION)." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'"; + api_sql_query($sql_add_publication, __FILE__, __LINE__); + $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')."'"; + api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).$expires_query.$ends_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__); + } else if($row['view_properties']=='0') { + if ($_POST['enableRandomExpires']=='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')."'"; + api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).$expires_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__); + $sql_add_publication = "UPDATE ".Database :: get_course_table(TABLE_STUDENT_PUBLICATION)." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'"; + api_sql_query($sql_add_publication, __FILE__, __LINE__); + } + if ($_POST['enableRandomEnds']=='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')."'"; + api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).$ends_query.' WHERE id = '."'".$row['has_properties']."'",__FILE__,__LINE__); + $sql_add_publication = "UPDATE ".Database :: get_course_table(TABLE_STUDENT_PUBLICATION)." SET has_properties = '".$row['has_properties']. "', view_properties=1 where id ='".$row['id']."'"; + api_sql_query($sql_add_publication, __FILE__, __LINE__); + } + } + + } + //if($_POST['qualification']['qualification']!='') + api_sql_query('UPDATE '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION).' SET description = '."'".Database::escape_string($_POST['description'])."'".', qualification = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".' WHERE id = '."'".$row['id']."'",__FILE__,__LINE__); + //api_sql_query('UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).' SET weight = '."'".Database::escape_string($_POST['qualification']['qualification'])."'".' WHERE course_code = '."'".api_get_course_id()."'".' AND ref_id = '."'".$row['id']."'".'',__FILE__,__LINE__); + + + $values = $form_folder -> exportValues(); + $values = $values['my_group']; + update_dir_name($mydir,$values['dir_name']); + $mydir = $my_sub_dir.$values['dir_name']; + $dir = $values['dir_name']; + $display_edit_form=false; + } + } + } + + $action = ''; + $row = array(); + $class = ''; + $row[] = ''.get_lang('Folder').''; //image + $a_count_directory=count_dir($work_dir.'/'.$dir,false); + $cant_files=$a_count_directory[0]; + $cant_dir=$a_count_directory[1]; + + $text_file=get_lang('FilesUpload'); + $text_dir=get_lang('Directories'); + + if ($cant_files==1) { + $text_file=strtolower(get_lang('FileUpload')); + } + + if ($cant_dir==1) { + $text_dir=get_lang('directory'); + } + + if ($cant_dir!=0) { + $dirtext=' ('.$cant_dir.' '.$text_dir.')'; + } else { + $dirtext=''; + } + + if($display_edit_form && isset($clean_edit_dir) && $clean_edit_dir==$mydir) { + $row[] = ''.$form_folder->toHtml(); // form to edit the directory's name + } else { + $tbl_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); + $add_to_name = ''; + $sql = "SELECT weight FROM ". $tbl_gradebook_link ." WHERE type='3' AND ref_id= '".$id2."'"; + $result=api_sql_query($sql, __FILE__, __LINE__); + $count = Database::num_rows($result); + if($count>0) { + $add_to_name = ' / '.get_lang('Assignment').''; + } else { + $add_to_name = ''; + } + $row[] = ''.$dir.''.$add_to_name.'
'.$cant_files.' '.$text_file.$dirtext; + } + + if ($count_files!=0) { + $row[] = ""; + } + + if ($direc_date!='' && $direc_date!='0000-00-00 00:00:00') { + $row[]= date_to_str_ago($direc_date).'
'.$direc_date.''; + } else { + $row[]=''; + } + + if( $is_allowed_to_edit) { + $action .= ''.get_lang('Modify').''; + $action .= ''.get_lang('DirDelete').''; + $row[] = $action; + } else { + $row[] = ""; + } + $table_data[] = $row; + } + + while( $work = mysql_fetch_object($sql_result)) { + //Get the author ID for that document from the item_property table + $is_author = false; + $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=".$work->id; + $author_qry = api_sql_query($author_sql,__FILE__,__LINE__); + + if(Database::num_rows($author_qry)==1) { + $is_author = true; + } + + //display info depending on the permissions + if( $work->accepted == '1' || $is_allowed_to_edit) { + $row = array(); + if($work->accepted == '0') + { + $class='class="invisible"'; + } else { + $class=''; + } + + + if(defined('IS_ASSIGNMENT')): + $add_string = ''; + + if($work->qualification=='') { + $qualification_string = ' / '.get_lang('NotRevised').''; + } else { + $qualification_string = ' / '.get_lang('Qualification').': '.$work->qualification.''; + } + if(defined('ASSIGNMENT_EXPIRES') && (ASSIGNMENT_EXPIRES < convert_date_to_number($work->sent_date))) { + $add_string = ' '.get_lang('Expired').''; + } + endif; + + $url = implode("/", array_map("rawurlencode", explode("/", $work->url))); + $row[]= build_document_icon_tag('file',$work->url); + $row[]= ''.get_lang('Save').''.$work->title.'
'.$work->description; + $row[]= display_user_link($user_id,$work->author).$qualification_string;// $work->author; + $row[]= date_to_str_ago($work->sent_date).$add_string.'
'.$work->sent_date.''; + + if( $is_allowed_to_edit) { + $action = ''; + $action .= ''.get_lang('Modify').''; + $action .= ''.get_lang('WorkDelete').''; + $action .= ''; + if($work->accepted == '1') { + $action .= ''.get_lang('Invisible').''; + } else { + $action .= ''.get_lang('Visible').''; + } + + $row[] = $action; + } elseif($is_author) { + $action = ''; + $action .= ''.get_lang('Modify').''; + $action .= ''.get_lang('WorkDelete').''; + + $row[] = $action; + } else { + $row[] = " "; + } + $table_data[] = $row; + } + } + + $sorting_options=array(); + $sorting_options['column']=1; + + $paging_options=array(); + Display::display_sortable_config_table($table_header,$table_data,$sorting_options, $paging_options,NULL,$column_show,$column_order); +} + +/** + * Returns a list of subdirectories found in the given directory. + * + * The list return starts from the given base directory. + * If you require the subdirs of /var/www/ (or /var/www), you will get 'abc/', 'def/', but not '/var/www/abc/'... + * @param string Base dir + * @param integer 0 if we only want dirs from this level, 1 if we want to recurse into subdirs + * @return strings_array The list of subdirs in 'abc/' form, -1 on error, and 0 if none found + * @todo Add a session check to see if subdirs_list doesn't exist yet (cached copy) + */ +function get_subdirs_list($basedir='',$recurse=0){ + //echo "Looking for subdirs of $basedir"; + if(empty($basedir) or !is_dir($basedir)) { + return -1; + } + if(substr($basedir,-1,1)!='/') { + $basedir = $basedir.'/'; + } + $dirs_list = array(); + $dh = opendir($basedir); + while($entry = readdir($dh)) { + if(is_dir($basedir.$entry) && $entry!='..' && $entry!='.') { + $dirs_list[] = $entry; + if($recurse==1) { + foreach(get_subdirs_list($basedir.$entry) as $subdir) { + $dirs_list[] = $entry.'/'.$subdir; + } + } + } + } + closedir($dh); + return $dirs_list; +} + +/** + * Builds the form thats enables the user to + * select a directory to browse/upload in + * This function has been copied from the document/document.inc.php library + * + * @param array $folders + * @param string $curdirpath + * @param string $group_dir + * @return string html form + */ +function build_work_directory_selector($folders,$curdirpath,$group_dir='') +{ + $form = '
'."\n"; + $form .= get_lang('CurrentDirectory').' '."\n"; + $form .= ''."\n"; + $form .= '
'; + + return $form; +} +/** + * Builds the form thats enables the user to + * move a document from one directory to another + * This function has been copied from the document/document.inc.php library + * + * @param array $folders + * @param string $curdirpath + * @param string $move_file + * @return string html form + */ +function build_work_move_to_selector($folders,$curdirpath,$move_file,$group_dir='') +{ + $form = '
'."\n"; + $form .= ''."\n"; + $form .= get_lang('MoveTo').' '."\n"; + $form .= ''."\n"; + $form .= '
'; + + return $form; +} + +/** + * Checks if the first given directory exists as a subdir of the second given directory + * This function should now be deprecated by Security::check_abs_path() + * @param string Subdir + * @param string Base dir + * @return integer -1 on error, 0 if not subdir, 1 if subdir + */ +function is_subdir_of($subdir,$basedir) +{ + if(empty($subdir) or empty($basedir)) { + return -1; + } + if(substr($basedir,-1,1)!='/') { + $basedir=$basedir.'/'; + } + if(substr($subdir,0,1)=='/') { + $subdir = substr($subdir,1); + } + if(is_dir($basedir.$subdir)) { + return 1; + } else { + return 0; + } +} + +/** + * creates a new directory trying to find a directory name + * that doesn't already exist + * (we could use unique_name() here...) + * + * @author Hugues Peeters + * @author Bert Vanderkimpen + * @author Yannick Warnier Adaptation for work tool + * @param string Base work dir (.../work) + * @param string $desiredDirName complete path of the desired name + * @return string actual directory name if it succeeds, + * boolean false otherwise + */ +function create_unexisting_work_directory($base_work_dir,$desired_dir_name) +{ + $nb = ''; + $base_work_dir = (substr($base_work_dir,-1,1)=='/'?$base_work_dir:$base_work_dir.'/'); + while ( file_exists($base_work_dir.$desired_dir_name.$nb) ) { + $nb += 1; + } + //echo "creating ".$base_work_dir.$desired_dir_name.$nb."#..."; + $perm = api_get_setting('permissions_for_new_directories'); + $perm = octdec(!empty($perm)?$perm:'0770'); + if ( mkdir($base_work_dir.$desired_dir_name.$nb, $perm)) { + chmod($base_work_dir.$desired_dir_name.$nb, $perm); + return $desired_dir_name.$nb; + } else { + return false; + } +} + +/** + * Delete a work-tool directory + * @param string Base "work" directory for this course as /var/www/dokeos/courses/ABCD/work/ + * @param string The directory name as the bit after "work/", without trailing slash + * @return integer -1 on error + */ +function del_dir($base_work_dir,$dir) +{ + if(empty($dir) or $dir=='/') { + return -1; + } + $check = Security::check_abs_path($base_work_dir.$dir,$base_work_dir); + if (!$check || !is_dir($base_work_dir.$dir)) { + return -1; + } + $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $sql = "DELETE FROM $table WHERE url LIKE BINARY 'work/".$dir."/%'"; + $res = api_sql_query($sql,__FILE__,__LINE__); + + //delete from DB the directories + $sql = "DELETE FROM $table WHERE filetype = 'folder' AND url LIKE BINARY '/".$dir."%'"; + $res = api_sql_query($sql,__FILE__,__LINE__); + + require_once(api_get_path(LIBRARY_PATH).'/fileManage.lib.php'); + my_delete($base_work_dir.$dir); +} + +/** + * Get the path of a document in the student_publication table (path relative to the course directory) + * @param integer Element ID + * @return string Path (or -1 on error) + */ +function get_work_path($id) +{ + $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $sql = "SELECT * FROM $table WHERE id=$id"; + $res = api_sql_query($sql); + if(Database::num_rows($res)!=1) { + return -1; + } else { + $row = Database::fetch_array($res); + return $row['url']; + } +} +/** + * Update the url of a work in the student_publication table + * @param integer ID of the work to update + * @param string Destination directory where the work has been moved (must end with a '/') + * @return -1 on error, sql query result on success + */ +function update_work_url($id,$new_path) +{ + if(empty($id)) return -1; + $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $sql = "SELECT * FROM $table WHERE id=$id"; + $res = api_sql_query($sql); + if(Database::num_rows($res)!=1) { + return -1; + } else { + $row = Database::fetch_array($res); + $filename = basename($row['url']); + $new_url = $new_path.$filename; + $sql2 = "UPDATE $table SET url = '$new_url' WHERE id=$id"; + $res2 = api_sql_query($sql2); + return $res2; + } +} + +/** + * Update the url of a dir in the student_publication table + * @param string old path + * @param string new path + */ +function update_dir_name($path, $new_name) +{ + global $base_work_dir; + + include_once(api_get_path(LIBRARY_PATH) . "/fileManage.lib.php"); + include_once(api_get_path(LIBRARY_PATH) . "/fileUpload.lib.php"); + + $path_to_dir = dirname($path); + + if($path_to_dir=='.') { + $path_to_dir = ''; + }else { + $path_to_dir .= '/'; + } + + my_rename($base_work_dir.'/'.$path,$new_name); + $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + + //update all the files in the other directories according with the next query + $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "work/'.$path.'/%"'; // like binary (Case Sensitive) + + $rs = api_sql_query($sql, __FILE__, __LINE__); + $work_len=strlen('work/'.$path); + + while($work = Database :: fetch_array($rs)) { + $new_dir=$work['url']; + $name_with_directory=substr($new_dir,$work_len,strlen($new_dir)); + $sql = 'UPDATE '.$table.' SET url="work/'.$path_to_dir.$new_name.$name_with_directory.'" WHERE id= '.$work['id']; + api_sql_query($sql, __FILE__, __LINE__); + } + + //update all the directory's children according with the next query + $sql = 'SELECT id, url FROM '.$table.' WHERE url LIKE BINARY "/'.$path.'%"'; + $rs = api_sql_query($sql, __FILE__, __LINE__); + $work_len=strlen('/'.$path); + while($work = Database :: fetch_array($rs)) { + $new_dir=$work['url']; + $name_with_directory=substr($new_dir,$work_len,strlen($new_dir)); + $sql = 'UPDATE '.$table.' SET url="/'.$path_to_dir.$new_name.$name_with_directory.'" WHERE id= '.$work['id']; + api_sql_query($sql, __FILE__, __LINE__); + } +} + +/** + * Return an array with all the folder's ids that are in the given path + * @param string Path of the directory + * @return array The list of ids of all the directories in the path + * @author Julio Montoya Dokeos + * @version April 2008 + */ + + function get_parent_directories($my_cur_dir_path) +{ + $list_parents = explode('/', $my_cur_dir_path); + $dir_acum = ''; + global $work_table; + $list_id=array(); + for ($i = 0; $i < count($list_parents) - 1; $i++) { + $where_sentence = "url LIKE BINARY '" . $dir_acum . "/" . $list_parents[$i]."'"; + $dir_acum .= '/' . $list_parents[$i]; + $sql = "SELECT id FROM ". $work_table . " WHERE ". $where_sentence; + $result = api_sql_query($sql, __FILE__, __LINE__); + $row= Database::fetch_array($result); + $list_id[]=$row['id']; + } + return $list_id; +} + +/** + * Transform an all directory structure (only directories) in an array + * @param string path of the directory + * @return array the directory structure into an array + * @author Julio Montoya Dokeos + * @version April 2008 + */ +function directory_to_array($directory) +{ + $array_items = array(); + if ($handle = opendir($directory)) { + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != "..") { + if (is_dir($directory. "/" . $file)) { + $array_items = array_merge($array_items, directory_to_array($directory. "/" . $file)); + $file = $directory . "/" . $file; + $array_items[] = preg_replace("/\/\//si", "/", $file); + } + } + } + closedir($handle); + } + return $array_items; +} + +/** + * Insert into the DB of the course all the directories + * @param string path of the /work directory of the course + * @return -1 on error, sql query result on success + * @author Julio Montoya Dokeos + * @version April 2008 + */ + +function insert_all_directory_in_course_table($base_work_dir) +{ + $dir_to_array =directory_to_array($base_work_dir,true); + $only_dir=array(); + + for($i=0;$iRead()) { + if (!(($entry == "..") || ($entry == "."))) { + if (is_dir($path_dir.'/'.$entry)) { + $count_dir++; + if ($recurse) { + $count += count_dir($path_dir . '/' . $entry, $recurse); + } + + } else { + $count++; + } + } + } + $return_array=array(); + $return_array[]=$count; + $return_array[]=$count_dir; + return $return_array; +} + +/** +* returns all the javascript that is required for easily +* validation when you create a work +* this goes into the $htmlHeadXtra[] array +*/ +function to_javascript() +{ + return ''; +} \ No newline at end of file diff --git a/main/work/work.php b/main/work/work.php index 650126ff70..2d891aa2b1 100644 --- a/main/work/work.php +++ b/main/work/work.php @@ -1,8 +1,9 @@ -, 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.php 16739 2008-11-13 15:36:40Z pcool $ +* @version $Id: work.php 16891 2008-11-24 20:35:40Z yannoo $ * * @todo refactor more code into functions, use quickforms, coding standards, ... */ @@ -95,170 +96,33 @@ if (isset ($_GET['id_session'])) { $_SESSION['id_session'] = Database::escape_string($_GET['id_session']); } -$htmlHeadXtra[] = ' -'; - - -$htmlHeadXtra[] = ' -'; /* ----------------------------------------------------------- Including necessary files ----------------------------------------------------------- */ -require ('../inc/global.inc.php'); +require_once '../inc/global.inc.php'; +require_once 'work.lib.php'; +require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php'); +require_once (api_get_path(LIBRARY_PATH) . 'debug.lib.inc.php'); +require_once (api_get_path(LIBRARY_PATH) . 'events.lib.inc.php'); +require_once (api_get_path(LIBRARY_PATH) . 'security.lib.php'); +require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); // Section (for the tabs) $this_section = SECTION_COURSES; - -require_once (api_get_path(LIBRARY_PATH) . "course.lib.php"); -require_once (api_get_path(LIBRARY_PATH) . "debug.lib.inc.php"); -require_once (api_get_path(LIBRARY_PATH) . "events.lib.inc.php"); -require_once (api_get_path(LIBRARY_PATH) . "security.lib.php"); -require_once(api_get_path(LIBRARY_PATH) . "formvalidator/FormValidator.class.php"); -require_once ('work.lib.php'); - -function make_select($name,$values,$checked=''){ - $output .= ''; - return $output; -} +$htmlHeadXtra[] = to_javascript(); /* ----------------------------------------------------------- Table definitions ----------------------------------------------------------- */ -$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); -$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); -$iprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); -$student_pub_ass = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); +$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); +$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); +$student_pub_ass = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); +$iprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); /* ----------------------------------------------------------- Constants and variables @@ -302,8 +166,7 @@ if (isset ($_GET['curdirpath']) && $_GET['curdirpath'] != '') { } else { $cur_dir_path = $_GET['curdirpath']; } -} -elseif (isset ($_POST['curdirpath']) && $_POST['curdirpath'] != '') { +} elseif (isset ($_POST['curdirpath']) && $_POST['curdirpath'] != '') { //$cur_dir_path = preg_replace('#[\.]+/#','/',$_POST['curdirpath']); //escape '..' hack attempts //now using common security approach with security lib $in_course = Security :: check_abs_path($base_work_dir . '/' . $_POST['curdirpath'], $base_work_dir); @@ -322,12 +185,9 @@ $cur_dir_path_url = urlencode($cur_dir_path); //prepare a form of path that can easily be added at the end of any url ending with "work/" $my_cur_dir_path = $cur_dir_path; -if ($my_cur_dir_path == '/') - { +if ($my_cur_dir_path == '/') { $my_cur_dir_path = ''; -} -elseif (substr($my_cur_dir_path, -1, 1) != '/') -{ +} elseif (substr($my_cur_dir_path, -1, 1) != '/') { $my_cur_dir_path = $my_cur_dir_path . '/'; } /* @@ -401,8 +261,7 @@ if ($origin != 'learnpath') { $dir_array = explode("/", $cur_dir_path); $array_len = count($dir_array); - if ($array_len > 0) - { + if ($array_len > 0) { $url_dir = 'work.php?&curdirpath=/'; $interbreadcrumb[] = array ( 'url' => $url_dir, @@ -421,25 +280,19 @@ if ($origin != 'learnpath') { // } if ($display_upload_form) { - //$tool_name = get_lang("UploadADocument"); - //$interbreadcrumb[] = array ("url" => "work.php", "name" => get_lang('StudentPublications')); $interbreadcrumb[] = array ( "url" => "work.php", "name" => get_lang('UploadADocument')); } - if ($display_tool_options) { - //$tool_name = get_lang("EditToolOptions"); - //$interbreadcrumb[] = array ("url" => "work.php", "name" => get_lang('StudentPublications')); + if ($display_tool_options) { $interbreadcrumb[] = array ( "url" => "work.php", "name" => get_lang('EditToolOptions')); } //-------------------------------------------------- Display :: display_header(null); -} -else -{ +} else { //we are in the learnpath tool include api_get_path(INCLUDE_PATH) . 'reduced_header.inc.php'; } @@ -456,15 +309,12 @@ $is_allowed_to_edit = api_is_allowed_to_edit(false,true); //has to come after di ============================================================================== */ -if (isset ($_POST['changeProperties'])) -{ +if (isset ($_POST['changeProperties'])) { $query = "UPDATE " . $main_course_table . " SET show_score='" . $uploadvisibledisabled . "' WHERE code='" . $_course['sysCode'] . "'"; api_sql_query($query, __FILE__, __LINE__); $_course['show_score'] = $uploadvisibledisabled; -} -else -{ +} else { $query = "SELECT * FROM " . $main_course_table . " WHERE code=\"" . $_course['sysCode'] . "\""; $result = api_sql_query($query, __FILE__, __LINE__); $row = mysql_fetch_array($result); @@ -479,62 +329,35 @@ Display :: display_introduction_section(TOOL_STUDENTPUBLICATION,'left'); COMMANDS SECTION (reserved for course administrator) ----------------------------------------------------------- */ -if (api_is_allowed_to_edit(false,true)) -{ +if (api_is_allowed_to_edit(false,true)) { /*------------------------------------------- DELETE WORK COMMAND -----------------------------------------*/ - if ($delete) - { - if ($delete == "all") - { + if ($delete) { + if ($delete == "all") { $queryString1 = "SELECT url FROM " . $work_table . ""; $queryString2 = "DELETE FROM " . $work_table . ""; - if(api_is_course_coach()) - { - $queryString1 .= ' WHERE session_id='.intval($_SESSION['id_session']); - $queryString2 .= ' WHERE session_id='.intval($_SESSION['id_session']); - } - } - else - { + + } else { $queryString1 = "SELECT url FROM " . $work_table . " WHERE id = '$delete'"; - $queryString2 = "DELETE FROM " . $work_table . " WHERE id='$delete'"; - if(api_is_course_coach()) - { - $queryString1 .= ' AND session_id='.intval($_SESSION['id_session']); - $queryString2 .= ' AND session_id='.intval($_SESSION['id_session']); - } + $queryString2 = "DELETE FROM " . $work_table . " WHERE id='$delete'"; } $result1 = api_sql_query($queryString1, __FILE__, __LINE__); $result2 = api_sql_query($queryString2, __FILE__, __LINE__); - if ($result1) - { - while ($thisUrl = Database::fetch_array($result1)) { - // check the url really points to a file in the work area - // (some work links can come from groups area...) - //if (substr (dirname($thisUrl['url']), -4) == "work") - if (strstr($thisUrl['url'], "work/$my_cur_dir_path") !== false) - { - @ unlink($currentCourseRepositorySys . $thisUrl['url']); - } - } - } } +} /*------------------------------------------- EDIT COMMAND WORK COMMAND -----------------------------------------*/ - if ($edit) - { + if ($edit) { $sql = "SELECT * FROM " . $work_table . " WHERE id='" . $edit . "'"; $result = api_sql_query($sql, __FILE__, __LINE__); - if ($result) - { + if ($result) { $row = mysql_fetch_array($result); $workTitle = $row['title']; $workAuthor = $row['author']; @@ -548,10 +371,8 @@ if (api_is_allowed_to_edit(false,true)) MAKE INVISIBLE WORK COMMAND -----------------------------------------*/ - if ($make_invisible) - { - if ($make_invisible == "all") - { + if ($make_invisible) { + if ($make_invisible == "all") { $sql = "ALTER TABLE " . $work_table . " CHANGE accepted accepted TINYINT(1) DEFAULT '0'"; @@ -559,23 +380,12 @@ if (api_is_allowed_to_edit(false,true)) $sql = "UPDATE " . $work_table . " SET accepted = 0"; - - if(api_is_course_coach()) - { - $sql .= ' WHERE session_id='.intval($_SESSION['id_session']); - } api_sql_query($sql, __FILE__, __LINE__); - } - else - { + } else { $sql = "UPDATE " . $work_table . " SET accepted = 0 WHERE id = '" . $make_invisible . "'"; - if(api_is_course_coach()) - { - $sql .= ' AND session_id='.intval($_SESSION['id_session']); - } api_sql_query($sql, __FILE__, __LINE__); } @@ -585,144 +395,130 @@ if (api_is_allowed_to_edit(false,true)) MAKE VISIBLE WORK COMMAND -----------------------------------------*/ - if ($make_visible) - { - if ($make_visible == "all") - { + if ($make_visible) { + if ($make_visible == "all") { $sql = "ALTER TABLE " . $work_table . " CHANGE accepted accepted TINYINT(1) DEFAULT '1'"; - api_sql_query($sql, __FILE__, __LINE__); - $sql = "UPDATE " . $work_table . " SET accepted = 1"; - if(api_is_course_coach()) - { - $sql .= ' WHERE session_id='.intval($_SESSION['id_session']); - } - api_sql_query($sql, __FILE__, __LINE__); - } - else - { + } else { $sql = "UPDATE " . $work_table . " SET accepted = 1 WHERE id = '" . $make_visible . "'"; - if(api_is_course_coach()) - { - $sql .= ' AND session_id='.intval($_SESSION['id_session']); - } - api_sql_query($sql, __FILE__, __LINE__); } // update all the parents in the table item propery $list_id=get_parent_directories($my_cur_dir_path); - for ($i = 0; $i < count($list_id); $i++) - { + for ($i = 0; $i < count($list_id); $i++) { api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); } } /*-------------------- * Create dir command - ---------------------*/ - if (!empty ($_REQUEST['create_dir']) && !empty ($_REQUEST['new_dir'])) - { - - function get_date_from_select($prefix){ - return $_POST[$prefix]['Y'].'-'.$_POST[$prefix]['M'].'-'.$_POST[$prefix]['d'].' '.$_POST[$prefix]['H'].':'.$_POST[$prefix]['i'].':00'; - //return $_POST[$prefix.'_year'].'-'.$_POST[$prefix.'_month'].'-'.$_POST[$prefix.'_day'].' '.$_POST[$prefix.'_hour'].':'.$_POST[$prefix.'_minute'].':00'; - } - $fexpire= get_date_from_select('expires_on'); - $fend = get_date_from_select('ends_on'); + ---------------------*/ + if (!empty ($_REQUEST['new_dir'])) { + function get_date_from_select($prefix) { + return $_POST[$prefix.'_year'].'-'.two_digits($_POST[$prefix.'_month']).'-'.two_digits($_POST[$prefix.'_day']).' '.two_digits($_POST[$prefix.'_hour']).':'.two_digits($_POST[$prefix.'_minute']).':00'; + } - - //create the directory - //needed for directory creation - include_once (api_get_path(LIBRARY_PATH) . "fileUpload.lib.php"); - $added_slash = (substr($cur_dir_path, -1, 1) == '/') ? '' : '/'; - $dir_name = $cur_dir_path . $added_slash . replace_dangerous_char($_POST['new_dir']); - $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name); + $fexpire= get_date_from_select('expires'); + $fend = get_date_from_select('ends'); - // we insert here the directory in the table $work_table - $dir_name_sql=''; - if ($created_dir) - { - if ($cur_dir_path=='/') - { - $dir_name_sql = $created_dir; - } - else - { - $dir_name_sql = '/'.$created_dir; - } - - $sql_add_publication = "INSERT INTO " . $work_table . " SET " . - "url = '" . $dir_name_sql . "', - title = '', - description = '".Database::escape_string($_POST['description'])."', - author = '', - active = '0', - accepted = '1', - filetype = 'folder', - post_group_id = '0', - sent_date = NOW(), - qualification = '".(($_POST['qualification_value']!='') ? Database::escape_string($_POST['qualification_value']) : '') ."', - parent_id = '', - qualificator_id = '', - date_of_qualification = '0000-00-00 00:00:00', - session_id = ".intval($_SESSION['id_session']); - - api_sql_query($sql_add_publication, __FILE__, __LINE__); + include_once (api_get_path(LIBRARY_PATH) . "fileUpload.lib.php"); + $added_slash = (substr($cur_dir_path, -1, 1) == '/') ? '' : '/'; + $dir_name = $cur_dir_path . $added_slash . replace_dangerous_char($_POST['new_dir']); + $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name); - // add the directory - $id = mysql_insert_id(); - //Folder created - api_item_property_update($_course, 'work', $id, 'DirectoryCreated', $user_id); - - //----------------inser into student_publication_assignment-------------------// + // we insert here the directory in the table $work_table + $dir_name_sql=''; + if ($created_dir) { + if ($cur_dir_path=='/') { + $dir_name_sql = $created_dir; + } else { + $dir_name_sql = '/'.$created_dir; + } + + $sql_add_publication = "INSERT INTO " . $work_table . " SET " . + "url = '" . $dir_name_sql . "', + title = '', + description = '".Database::escape_string($_POST['description'])."', + author = '', + active = '0', + accepted = '1', + filetype = 'folder', + post_group_id = '0', + sent_date = NOW(), + qualification = '".(($_POST['qualification_value']!='') ? Database::escape_string($_POST['qualification_value']) : '') ."', + parent_id = '', + qualificator_id = '', + date_of_qualification = '0000-00-00 00:00:00', + session_id = ".intval($_SESSION['id_session']); + + api_sql_query($sql_add_publication, __FILE__, __LINE__); + + // add the directory + $id = mysql_insert_id(); + //Folder created + api_item_property_update($_course, 'work', $id, 'DirectoryCreated', $user_id); + Display :: display_normal_message('' . get_lang('DirectoryCreated') . '', false); + //Database :: escape_string($_REQUEST['make_visible']); + //if($_POST['type1']==1) + //$insert_limite + //----------------inser into student_publication_assignment-------------------// //return something like this: 2008-02-45 00:00:00 - if(($_POST['type1'])==1 || ($_POST['type2']==1)) - { - $TSTDPUBASG=Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); - $sql_add_homework = "INSERT INTO ".$TSTDPUBASG." SET " . - "expires_on = '".(($_POST['type1']==1) ? $fexpire : '0000-00-00 00:00:00'). "', - ends_on = '".(($_POST['type2']==1) ? $fend : '0000-00-00 00:00:00')."', - add_to_calendar = '".(int)$_POST['add_to_calendar']."', - enable_qualification = '".(int)$_POST['enable_calification']."', - publication_id = '".$id."'"; - api_sql_query($sql_add_homework, __FILE__, __LINE__); - //api_sql_query($sql_add_publication, __FILE__, __LINE__); - $sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".mysql_insert_id().", view_properties = 1 ".' where id = '.$id; - api_sql_query($sql_add_publication, __FILE__, __LINE__); - } - else - { - $TSTDPUBASG=Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); - $sql_add_homework = "INSERT INTO ".$TSTDPUBASG." SET " . - "expires_on = '0000-00-00 00:00:00', - ends_on = '0000-00-00 00:00:00', - add_to_calendar = '".(int)$_POST['add_to_calendar']."', - enable_qualification = '".(int)$_POST['enable_calification']."', - publication_id = '".$id."'"; - api_sql_query($sql_add_homework, __FILE__, __LINE__); - //api_sql_query($sql_add_publication, __FILE__, __LINE__); - $sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".mysql_insert_id().", view_properties = 0 ".' where id = '.$id; - api_sql_query($sql_add_publication, __FILE__, __LINE__); - } + if($_POST['type1'] || $_POST['type2']) { + + $TSTDPUBASG=Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); + + + $sql_add_homework = "INSERT INTO ".$TSTDPUBASG." SET " . + "expires_on = '".(($_POST['type1']==1) ? get_date_from_select('expires') : '0000-00-00 00:00:00'). "', + ends_on = '".(($_POST['type2']==1) ? get_date_from_select('ends') : '0000-00-00 00:00:00')."', + add_to_calendar = '".(int)$_POST['add_to_calendar']."', + enable_qualification = '".(int)$_POST['enable_calification']."', + publication_id = '".$id."'"; + api_sql_query($sql_add_homework, __FILE__, __LINE__); + //api_sql_query($sql_add_publication, __FILE__, __LINE__); + + $sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".mysql_insert_id().", view_properties = 1 ".' where id = '.$id; + api_sql_query($sql_add_publication, __FILE__, __LINE__); + + } else { + + $TSTDPUBASG=Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); + + + $sql_add_homework = "INSERT INTO ".$TSTDPUBASG." SET " . + "expires_on = '0000-00-00 00:00:00', + ends_on = '0000-00-00 00:00:00', + add_to_calendar = '".(int)$_POST['add_to_calendar']."', + enable_qualification = '".(int)$_POST['enable_calification']."', + publication_id = '".$id."'"; + api_sql_query($sql_add_homework, __FILE__, __LINE__); + //api_sql_query($sql_add_publication, __FILE__, __LINE__); + + $sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".mysql_insert_id().", view_properties = 0 ".' where id = '.$id; + api_sql_query($sql_add_publication, __FILE__, __LINE__); + + } - if($_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 = (empty($_POST['qualification_name'])) ? $_POST['new_dir'] : $_POST['qualification_name']; - add_resource_to_course_gradebook(api_get_course_id(), 3, $id, Database::escape_string($resource_name), 0, $_POST['qualification_value'], Database::escape_string($_POST['description']), "'".date('Y-m-d H:i:s')."'", 1,api_get_session_id()); + if($_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 = (empty($_POST['qualification_name'])) ? $_POST['new_dir'] : $_POST['qualification_name']; + add_resource_to_course_gradebook(api_get_course_id(), 3, $id, Database::escape_string($resource_name),$_POST['weight'], $_POST['qualification_value'], Database::escape_string($_POST['description']),time(), 1,api_get_session_id()); + + } //----------------inser into agenda----------------------// @@ -732,39 +528,34 @@ if (api_is_allowed_to_edit(false,true)) agenda_add_item($course_info,$_POST['new_dir'],$_POST['new_dir'],date('Y-m-d H:i:s'),get_date_from_select('expires')); endif; - //-----------------end feature---------------------------// - - - // update all the parents in the table item propery - $list_id=get_parent_directories($my_cur_dir_path); - - for ($i = 0; $i < count($list_id); $i++) - { - api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); - } - //------------------------------------------------------------------------------- - - Display :: display_normal_message('' . 'DirectoryCreated' . '', false); - //uncomment if you want to enter the created dir - //$curdirpath = $created_dir; - //$curdirpathurl = urlencode($curdirpath); - } - else - { - Display :: display_error_message(get_lang('CannotCreateDir')); - } + //-----------------end features---------------------------// + + // update all the parents in the table item propery + $list_id=get_parent_directories($my_cur_dir_path); + + for ($i = 0; $i < count($list_id); $i++) { + api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); + } + //------------------------------------------------------------------------------- + + + //uncomment if you want to enter the created dir + //$curdirpath = $created_dir; + //$curdirpathurl = urlencode($curdirpath); + } else { + Display :: display_error_message(get_lang('CannotCreateDir')); + } } + /* ------------------- * Delete dir command --------------------*/ - if (!empty ($_REQUEST['delete_dir'])) - { + if (!empty ($_REQUEST['delete_dir'])) { $delete_directory=$_REQUEST['delete_dir']; del_dir($base_work_dir . '/', $delete_directory); Display :: display_normal_message($delete_directory . ' ' . get_lang('DirDeleted')); } - if (!empty ($_REQUEST['delete2'])) - { + if (!empty ($_REQUEST['delete2'])) { $delete_2=$_REQUEST['delete2']; $sql2="DELETE FROM ". Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT)." WHERE publication_id ='".$delete_2."'"; $result2 = api_sql_query($sql2, __FILE__, __LINE__); @@ -772,31 +563,28 @@ if (api_is_allowed_to_edit(false,true)) $sql3="DELETE FROM ".Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK)." WHERE course_code='".$course_code."' AND ref_id='".$delete_2."'"; $result3 = api_sql_query($sql3, __FILE__, __LINE__); } + /* ---------------------- * Move file form request ----------------------- */ - if (!empty ($_REQUEST['move'])) - { + if (!empty ($_REQUEST['move'])) { $folders = get_subdirs_list($base_work_dir, 1); Display :: display_normal_message(build_work_move_to_selector($folders, $cur_dir_path, $_REQUEST['move']), false); } /* ------------------ * Move file command ------------------- */ - if (isset ($_POST['move_to']) && isset ($_POST['move_file'])) - { + if (isset ($_POST['move_to']) && isset ($_POST['move_file'])) { include_once (api_get_path(LIBRARY_PATH) . "/fileManage.lib.php"); $move_to = $_POST['move_to']; if ($move_to == '/' or empty ($move_to)) { $move_to = ''; - } - elseif (substr($move_to, -1, 1) != '/') { + } elseif (substr($move_to, -1, 1) != '/') { $move_to = $move_to . '/'; } //security fix: make sure they can't move files that are not in the document table - if ($path = get_work_path($_POST['move_file'])) - { + if ($path = get_work_path($_POST['move_file'])) { //echo "got path $path"; //Display::display_normal_message('We want to move '.$_POST['move_file'].' to '.$_POST['move_to']); if (move($course_dir . '/' . $path, $base_work_dir . '/' . $move_to)) { @@ -808,51 +596,39 @@ if (api_is_allowed_to_edit(false,true)) // update all the parents in the table item propery $list_id=get_parent_directories($cur_dir_path); - for ($i = 0; $i < count($list_id); $i++) - { + for ($i = 0; $i < count($list_id); $i++) { api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); } Display :: display_normal_message(get_lang('DirMv')); - } - else - { + } else { Display :: display_error_message(get_lang('Impossible')); } - } - else - { + } else { Display :: display_error_message(get_lang('Impossible')); } } -} -/* ------------------------------------------------------------ + +/*----------------------------------------------------------- COMMANDS SECTION (reserved for others - check they're authors each time) ----------------------------------------------------------- */ -else -{ +else { $iprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); $user_id = api_get_user_id(); /*------------------------------------------- DELETE WORK COMMAND -----------------------------------------*/ - if ($delete) - { - if ($delete == "all") - { + if ($delete) { + if ($delete == "all") { /*not authorized to this user */ - } - else - { + } else { //Get the author ID for that document from the item_property table $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . mysql_real_escape_string($delete); $author_qry = api_sql_query($author_sql, __FILE__, __LINE__); - if (Database :: num_rows($author_qry) == 1) - { + if (Database :: num_rows($author_qry) == 1) { //we found the current user is the author $queryString1 = "SELECT url FROM " . $work_table . " WHERE id = '$delete'"; $queryString2 = "DELETE FROM " . $work_table . " WHERE id='$delete'"; @@ -860,15 +636,12 @@ else $result1 = api_sql_query($queryString1, __FILE__, __LINE__); $result2 = api_sql_query($queryString2, __FILE__, __LINE__); - if ($result1) - { + if ($result1) { api_item_property_update($_course, 'work', $delete, 'DocumentDeleted', $user_id); - while ($thisUrl = mysql_fetch_array($result1)) - { + while ($thisUrl = mysql_fetch_array($result1)) { // check the url really points to a file in the work area // (some work links can come from groups area...) - if (substr(dirname($thisUrl['url']), -4) == "work") - { + if (substr(dirname($thisUrl['url']), -4) == "work") { @ unlink($currentCourseRepositorySys . "work/" . $thisWork); } } @@ -880,18 +653,15 @@ else EDIT COMMAND WORK COMMAND -----------------------------------------*/ - if ($edit) - { + if ($edit) { //Get the author ID for that document from the item_property table $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . $edit; $author_qry = api_sql_query($author_sql, __FILE__, __LINE__); - if (Database :: num_rows($author_qry) == 1) - { + if (Database :: num_rows($author_qry) == 1) { //we found the current user is the author $sql = "SELECT * FROM " . $work_table . " WHERE id='" . $edit . "'"; $result = api_sql_query($sql, __FILE__, __LINE__); - if ($result) - { + if ($result) { $row = mysql_fetch_array($result); $workTitle = $row['title']; $workAuthor = $row['author']; @@ -913,10 +683,8 @@ else $error_message = ""; $check = Security :: check_token('post'); //check the token inserted into the form -if ($_POST['submitWork'] && $is_course_member && $check) -{ - if ($_FILES['file']['size']) - { +if ($_POST['submitWork'] && $is_course_member && $check) { + if ($_FILES['file']['size']) { $updir = $currentCourseRepositorySys . 'work/'; //directory path to upload // Try to add an extension to the file if it has'nt one @@ -928,20 +696,14 @@ if ($_POST['submitWork'] && $is_course_member && $check) // Transform any .php file in .phps fo security $new_file_name = php2phps($new_file_name); //filter extension - if (!filter_extension($new_file_name)) - { + if (!filter_extension($new_file_name)) { Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); $succeed = false; - } - else - { - if (!$title) - { + } else { + if (!$title) { $title = $_FILES['file']['name']; } - - if (!$authors) - { + if (!$authors) { $authors = $currentUserFirstName . " " . $currentUserLastName; } @@ -949,12 +711,9 @@ if ($_POST['submitWork'] && $is_course_member && $check) $new_file_name = uniqid('') . $new_file_name; - if (isset ($_SESSION['toolgroup'])) - { + if (isset ($_SESSION['toolgroup'])) { $post_group_id = $_SESSION['toolgroup']; - } - else - { + } else { $post_group_id = '0'; } @@ -966,16 +725,15 @@ if ($_POST['submitWork'] && $is_course_member && $check) $result = api_sql_query("SHOW FIELDS FROM " . $work_table . " LIKE 'sent_date'", __FILE__, __LINE__); - if (!mysql_num_rows($result)) - { + if (!Database::num_rows($result)) { api_sql_query("ALTER TABLE " . $work_table . " ADD sent_date DATETIME NOT NULL"); } $current_date = date('Y-m-d H:i:s'); $parent_id = ''; $sql = api_sql_query('SELECT id FROM '.Database::get_course_table(TABLE_STUDENT_PUBLICATION).' WHERE url = '."'/".Database::escape_string($_GET['curdirpath'])."' AND filetype='folder' LIMIT 1"); - if(mysql_num_rows($sql) > 0 ){ - $dir_row = mysql_fetch_array($sql); + if(Database::num_rows($sql) > 0 ) { + $dir_row = Database::fetch_array($sql); $parent_id = $dir_row['id']; } @@ -987,9 +745,10 @@ if ($_POST['submitWork'] && $is_course_member && $check) active = '" . $active . "', accepted = '" . (!$uploadvisibledisabled) . "', post_group_id = '" . $post_group_id . "', - sent_date = ' ".$current_date ."', - parent_id = '".$parent_id ."' , - session_id=".intval($_SESSION['id_session']); + sent_date = '".$current_date ."', + parent_id = '".$parent_id ."' , + session_id = ".intval($_SESSION['id_session']); + api_sql_query($sql_add_publication, __FILE__, __LINE__); @@ -999,22 +758,18 @@ if ($_POST['submitWork'] && $is_course_member && $check) // update all the parents in the table item propery $list_id=get_parent_directories($my_cur_dir_path); - for ($i = 0; $i < count($list_id); $i++) - { + for ($i = 0; $i < count($list_id); $i++) { api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); } } - } - elseif ($newWorkUrl) - { + } elseif ($newWorkUrl) { /* * SPECIAL CASE ! For a work coming from another area (i.e. groups) */ $url = str_replace('../../' . $_course['path'] . '/', '', $newWorkUrl); - if (!$title) - { + if (!$title) { $title = basename($workUrl); } @@ -1030,7 +785,7 @@ if ($_POST['submitWork'] && $is_course_member && $check) description = '" . $description . "', author = '" . $authors . "', sent_date = NOW(), - session_id=".intval($_SESSION['id_session']); + session_id = ".intval($_SESSION['id_session']); api_sql_query($sql, __FILE__, __LINE__); @@ -1040,8 +795,7 @@ if ($_POST['submitWork'] && $is_course_member && $check) // update all the parents in the table item propery $list_id=get_parent_directories($my_cur_dir_path); - for ($i = 0; $i < count($list_id); $i++) - { + for ($i = 0; $i < count($list_id); $i++) { api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id); } } @@ -1050,8 +804,7 @@ if ($_POST['submitWork'] && $is_course_member && $check) * SPECIAL CASE ! For a work edited */ - else - { + else { //Get the author ID for that document from the item_property table $is_author = false; $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . mysql_real_escape_string($id); @@ -1060,46 +813,44 @@ if ($_POST['submitWork'] && $is_course_member && $check) $is_author = true; } - if ($id && ($is_allowed_to_edit or $is_author)) - { - if (!$title) - { + if ($id && ($is_allowed_to_edit or $is_author)) { + if (!$title) { $title = basename($newWorkUrl); } - - if($is_allowed_to_edit && ($_POST['qualification']!='')){ - $add_to_update = ',qualificator_id ='."'".api_get_user_id()."',"; - $add_to_update .= 'qualification ='."'".Database::escape_string($_POST['qualification'])."',"; - $add_to_update .= 'date_of_qualification ='."'".date('Y-m-d H:i:s')."'"; - } + if($is_allowed_to_edit && ($_POST['qualification']!='')) { + $add_to_update = ',qualificator_id ='."'".api_get_user_id()."',"; + $add_to_update .= 'qualification ='."'".Database::escape_string($_POST['qualification'])."',"; + $add_to_update .= 'date_of_qualification ='."'".date('Y-m-d H:i:s')."'"; + } + $sql = "UPDATE " . $work_table . " SET title = '" . $title . "', description = '" . $description . "', author = '" . $authors . "'".$add_to_update." - WHERE id = '" . $id . "'"; + WHERE id = '$id'"; api_sql_query($sql, __FILE__, __LINE__); - $insertId = $id; + + $t_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); + + //api_sql_query($sql2, __FILE__, __LINE__); + $insertId = $id; api_item_property_update($_course, 'work', $insertId, 'DocumentUpdated', $user_id); $succeed = true; - } - else - { + } else { $error_message = get_lang('TooBig'); } } Security :: clear_token(); //clear the token to prevent re-executing the request with back button } -if ($_POST['submitWork'] && $succeed && !$id) //last value is to check this is not "just" an edit -{ - +if ($_POST['submitWork'] && $succeed && !$id) { + //last value is to check this is not "just" an edit //YW Tis part serve to send a e-mail to the tutors when a new file is sent $send = api_get_course_setting('email_alert_manager_on_new_doc'); - if ($send > 0) - { + if ($send > 0) { // Lets predefine some variables. Be sure to change the from address! $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $table_user = Database :: get_main_table(TABLE_MAIN_USER); @@ -1144,8 +895,7 @@ if ($_POST['submitWork'] && $succeed && !$id) //last value is to check this is n } - if (count($emailto) > 0) - { + if (count($emailto) > 0) { $emailto = implode(',', $emailto); $emailfromaddr = get_setting('emailAdministrator'); $emailfromname = get_setting('siteName'); @@ -1179,7 +929,6 @@ if ($_POST['submitWork'] && $succeed && !$id) //last value is to check this is n Display :: display_normal_message($submit_success_message, false); } -//{ /*======================================= Display links to upload form and tool options ======================================= @@ -1193,10 +942,6 @@ if($is_special > 0): $publication = mysql_fetch_array($sql); $sql = api_sql_query('SELECT * FROM '.Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT).' WHERE publication_id = '.(string)$publication['id'].' LIMIT 1',__FILE__,__LINE__); $homework = mysql_fetch_array($sql); - - if(!empty($publication['description'])){ - Display :: display_normal_message($publication['description']); - } if($homework['expires_on']!='0000-00-00 00:00:00' || $homework['ends_on']!='0000-00-00 00:00:00'): $time_now = convert_date_to_number(date('Y-m-d H:i:s')); @@ -1208,35 +953,35 @@ if($is_special > 0): if($homework['ends_on']!='0000-00-00 00:00:00' && $difference2 < 0) $has_ended = true; define('ASSIGNMENT_EXPIRES',$time_expires); + + if(!empty($publication['description'])){ + Display :: display_normal_message($publication['description']); + } if($has_ended) { - Display :: display_error_message(get_lang('EndDateAlreadyEnded').' '.$homework['ends_on']); + Display :: display_error_message(get_lang('EndDateAlreadyPassed').' '.$homework['ends_on']); display_action_links($cur_dir_path, $always_show_tool_options,true); - }elseif($has_expired) { - Display :: display_warning_message(get_lang('ExpireDateAlreadyExpired').' '.$homework['expires_on']); + } elseif($has_expired) { + Display :: display_warning_message(get_lang('ExpiryDateAlreadyPassed').' '.$homework['expires_on']); display_action_links($cur_dir_path, $always_show_tool_options,$always_show_upload_form); } else { - Display :: display_normal_message(get_lang('ExpireDateToSendWorkIs').' '.$homework['expires_on']); + Display :: display_normal_message(get_lang('ExpiryDateToSendWorkIs').' '.$homework['expires_on']); display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form); } else: display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form); - endif; + endif; else: display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form); endif; - /*======================================= Display form to upload document =======================================*/ -if ($is_course_member) -{ - if (($display_upload_form || $edit)&&!$has_ended) - { +if ($is_course_member) { + if (($display_upload_form || $edit)&&!$has_ended) { $token = Security :: get_token(); //generate token to be used to check validity of request - if ($edit) - { + if ($edit) { //Get the author ID for that document from the item_property table $is_author = false; $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND insert_user_id='$user_id' AND ref=" . $edit; @@ -1249,22 +994,19 @@ if ($is_course_member) require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); require_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php'); - $form = new FormValidator('form', 'POST', api_get_self() . "?curdirpath=" . Security :: remove_XSS(rtrim($cur_dir_path,'/')) . "&origin=$origin", '', 'enctype="multipart/form-data"'); + $form = new FormValidator('form', 'POST', api_get_self() . "?curdirpath=" . rtrim(Security :: remove_XSS($cur_dir_path),'/') . "&origin=$origin", '', 'enctype="multipart/form-data"'); - if (!empty ($error_message)) + if (!empty ($error_message)) { Display :: display_error_message($error_message); - - if ($submitGroupWorkUrl) // For user comming from group space to publish his work - { + } + if ($submitGroupWorkUrl) { + // For user comming from group space to publish his work $realUrl = str_replace($_configuration['root_sys'], $_configuration['root_web'], str_replace("\\", "/", realpath($submitGroupWorkUrl))); $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl); $text_document = & $form->addElement('text', 'document', get_lang("Document")); $defaults["document"] = '' . $realUrl . ''; $text_document->freeze(); - } - - elseif ($edit && ($is_allowed_to_edit or $is_author)) - { + } elseif ($edit && ($is_allowed_to_edit or $is_author)) { $workUrl = $currentCourseRepositoryWeb . $workUrl; $form->addElement('hidden', 'id', $edit); @@ -1274,11 +1016,10 @@ if ($is_course_member) - '; + '; $form->addElement('html', $html); - } - else // else standard upload option - { + } else { + // else standard upload option $form->addElement('file', 'file', get_lang('DownloadFile'), 'size="40" onchange="updateDocumentTitle(this.value)"'); } @@ -1287,37 +1028,34 @@ if ($is_course_member) $titleAuthors = $form->addElement('text', 'authors', get_lang("Authors"), 'style="width: 350px;"'); - if (empty ($authors)) - { + if (empty ($authors)) { $authors = $_user['firstName'] . " " . $_user['lastName']; } $defaults["authors"] = ($edit ? stripslashes($workAuthor) : stripslashes($authors)); - $titleAuthors = $form->addElement('textarea', 'description', get_lang("Description"), 'style="width: 350px; height: 60px;"'); $defaults["description"] = ($edit ? stripslashes($workDescription) : stripslashes($description)); - if($is_allowed_to_edit && $edit )$form->addElement('text', 'qualification', get_lang('Qualification'),'size="10"'); - $defaults['qualification'] = $qualification_number;//($edit ? stripslashes($qualification_number) : stripslashes($qualification_number)); + if($is_allowed_to_edit && $edit ) { + $form->addElement('text', 'qualification', get_lang('Qualification'),'size="10"'); + } + + $defaults['qualification'] = $qualification_number;//($edit ? stripslashes($qualification_number) : stripslashes($qualification_number)); $form->addElement('hidden', 'active', 1); $form->addElement('hidden', 'accepted', 1); $form->addElement('hidden', 'sec_token', $token); // fix the Ok button when we see the tool in the learn path - if ($origin== 'learnpath') - { + if ($origin== 'learnpath') { $form->addElement('html', '
'); $form->addElement('submit', 'submitWork', get_lang('Ok')); $form->addElement('html', '
'); - } - else - { + } else { $form->addElement('submit', 'submitWork', get_lang('Ok')); } - if ($_POST['submitWork'] || $edit) - { + if ($_POST['submitWork'] || $edit) { $form->addElement('submit', 'cancelForm', get_lang('Cancel')); } @@ -1329,59 +1067,100 @@ if ($is_course_member) } + +function make_select($name,$values,$checked='') { + $output .= ''; + return $output; +} + +function make_checkbox($name,$checked='') { + return '' . + ''; + } + +function draw_date_picker($prefix,$default='') { + //$default = 2008-10-01 10:00:00 + if(empty($default)) { + $default = date('Y-m-d H:i:s'); + } + $parts = split(' ',$default); + list($d_year,$d_month,$d_day) = split('-',$parts[0]); + list($d_hour,$d_minute) = split(':',$parts[1]); + + $month_list = array( + 1=>'Enero', + 2=>'Febrero', + 3=>'Marzo', + 4=>'Abril', + 5=>'Mayo', + 6=>'Junio', + 7=>'Julio', + 8=>'Agosto', + 9=>'Septiembre', + 10=>'Octubre', + 11=>'Noviembre', + 12=>'Diciembre' + ); + + $minute = range(10,59); + array_unshift($minute,'00','01','02','03','04','05','06','07','08','09'); + $date_form .= make_select($prefix.'_day', array_combine(range(1,31),range(1,31)), $d_day); + $date_form .= make_select($prefix.'_month', $month_list, $d_month); + $date_form .= make_select($prefix.'_year', array( $d_year=> $d_year, $d_year+1=>$d_year+1), $d_year).'    '; + $date_form .= make_select($prefix.'_hour', array_combine(range(1,24),range(1,24)), $d_hour).' : '; + $date_form .= make_select($prefix.'_minute', $minute, $d_minute); + return $date_form; +} + //show them the form for the directory name - if (isset ($_REQUEST['createdir']) && $is_allowed_to_edit) - { - require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); - $form = new FormValidator('form1', 'POST', api_get_self() . "?curdirpath=" . Security :: remove_XSS($cur_dir_path) . "&origin=$origin"); - $form->addElement('hidden', 'curdirpath', Security :: remove_XSS($cur_dir_path)); - $form->addElement('text', 'new_dir', get_lang('NewDir'), ''); - - $form->addElement('textarea', 'description', get_lang('Description'), 'style="width: 350px; height: 60px;"'); - - $form -> addElement('html',''); - $form -> addElement('html',''); - - $form->addElement('submit', 'create_dir', get_lang('Ok'),'onClick="validate();"'); - - $defaults['expires_on'] = date('Y-m-d 12:00:00'); - $defaults['ends_on'] = date('Y-m-d 12:00:00'); - $form->setDefaults($defaults); - echo '

'; - $form->display(); - /* + if (isset ($_REQUEST['createdir']) && $is_allowed_to_edit) { //create the form that asks for the directory name - $new_folder_text = '

'; + $new_folder_text = '

'; $new_folder_text .= ''; - $new_folder_text .= get_lang('NewDir') . ' '; + $new_folder_text .= ''; + $new_folder_text .= get_lang('NewDir') . ' '; $new_folder_text .= ''; - $new_folder_text .= ''; - $new_folder_text .= '
'; + $new_folder_text .= ''; + //new additional fields inside the "if condition" just to agroup + if(true): + $addtext .= '
'.get_lang('Description').'
'; + $addtext .= '
'; + $addtext .= '
'.get_lang('QualificationOfAssignment').''; + $addtext .= make_checkbox('make_calification').get_lang('MakeQualifiable').'
'; + $addtext .= ''; + $addtext .= ''; + $addtext .= '
'.get_lang('WeightInTheGradebook').''; + $addtext .= '   '; + $addtext .= '
'.get_lang('QualificationNumberOver').''; + $addtext .= '
'; + $addtext .= '

'; + $addtext .= '
'.get_lang('DatesAvailables').''; + $addtext .= '* '.get_lang('ExpiresAt').''; + $addtext .= '   '; + $addtext .= '   '; + $addtext .= '
'; + $addtext .= draw_date_picker('expires').'
'; + $addtext .= make_checkbox('add_to_calendar').get_lang('AddToCalendar').'
'; + $addtext .= '
* '.get_lang('EndsAt').'
'; + $addtext .= '   '; + $addtext .= '
'; + $addtext .= draw_date_picker('ends').'
'; + $addtext .= '
'; + $addtext .= '
'; + $new_folder_text .= $addtext; + endif; + + $new_folder_text .= ''; + + $new_folder_text .= '

'; //show the form echo $new_folder_text; - */ } -} -else -{ +} else { //the user is not registered in this course echo "

" . get_lang("MustBeRegisteredUser") . "

"; } @@ -1391,8 +1170,7 @@ else Display of tool options ============================================================================== */ -if ($display_tool_options) -{ +if ($display_tool_options) { display_tool_options($uploadvisibledisabled, $origin, $base_work_dir, $cur_dir_path, $cur_dir_path_url); } @@ -1401,22 +1179,19 @@ if ($display_tool_options) Display list of student publications ============================================================================== */ -if ($cur_dir_path == '/') -{ +if ($cur_dir_path == '/') { $my_cur_dir_path = ''; -} -else -{ +} else { $my_cur_dir_path = $cur_dir_path; } if (!$display_upload_form && !$display_tool_options) { - if(!$is_allowed_to_edit && $is_special==true){ + if(!$is_allowed_to_edit && $is_special==true) { $add_query = ' AND author = '."'".$_user['firstName'].' '.$_user['lastName']."' "; } - if($is_allowed_to_edit && $is_special==true){ + if($is_allowed_to_edit && $is_special==true) { - switch($_REQUEST['filter']){ + switch($_REQUEST['filter']) { case 1: $add_query = ' AND qualification = '."''"; break; @@ -1438,14 +1213,14 @@ if (!$display_upload_form && !$display_tool_options) { display_student_publications_list($base_work_dir . '/' . $my_cur_dir_path, 'work/' . $my_cur_dir_path, $currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin,$add_query); } + /* ============================================================================== Footer ============================================================================== */ -if ($origin != 'learnpath') -{ + +if ($origin != 'learnpath') { //we are not in the learning path tool Display :: display_footer(); -} -?> \ No newline at end of file +} \ No newline at end of file