";
*/
}
/**
* 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').')';
}
}
/**
* 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)
{
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);
if(substr($sub_course_dir,-1,1)!='/' && !empty($sub_course_dir))
{
$sub_course_dir = $sub_course_dir.'/';
}
if($sub_course_dir == '/')
{
$sub_course_dir='';
}
//Get list from database
if($is_allowed_to_edit)
{
$sql_get_publications_list = "SELECT * " .
"FROM ".$work_table." " .
"WHERE url LIKE '$sub_course_dir%' " .
"AND url NOT LIKE '$sub_course_dir%/%' " .
"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 '$sub_course_dir%/%' AND url LIKE '$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 ORDER BY id";
}
$sql_result = api_sql_query($sql_get_publications_list,__FILE__,__LINE__);
$table_header[] = array(get_lang('Type'),true,'style="width:40px"');
$table_header[] = array(get_lang('Title'),true);
//$table_header[] = array(get_lang('Description'),true);
$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;
$column_show[]=1;
$column_show[]=1;
$column_show[]=1;
$column_show[]=1;
$column_show[]=0;
// 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;
$column_order[]=2;
$column_order[]=3;
$column_order[]=6;
$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);
foreach($dirs_list as $dir)
{
$mydir = $my_sub_dir.$dir;
$action = '';
//display info depending on the permissions
$row = array();
$class = '';
$url = implode("/", array_map("rawurlencode", explode("/", $work->url)));
$row[] = '';
$row[] = ''.$dir.'';
$row[] = '';
$row[] = '';
if( $is_allowed_to_edit)
{
//$action .= '';
$action .= '';
$action .= '';
$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='';
}
$url = implode("/", array_map("rawurlencode", explode("/", $work->url)));
$row[]= build_document_icon_tag('file',$work->url);
$row[]= ''.$work->title.' '.$work->description;
$row[]= display_user_link($user_id,$work->author);// $work->author;
$row[]= date_to_str_ago($work->sent_date).' '.$work->sent_date.'';
if( $is_allowed_to_edit)
{
$action = '';
$action .= '';
$action .= '';
$action .= '';
if($work->accepted == '1')
{
$action .= '';
}
else
{
$action .= '';
}
$row[] = $action;
}
elseif($is_author)
{
$action = '';
$action .= '';
$action .= '';
$row[] = $action;
}
else
{
$row[] = " ";
}
$table_data[] = $row;
}
}
//if( count($table_data) > 0)
//{
$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 = '';
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 = '';
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);
if(!is_dir($base_work_dir.$dir)) {return -1;}
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "DELETE FROM $table WHERE url LIKE 'work/".$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;
}
}
?>