, Ghent University - ability for course admins to specify wether uploaded documents are visible or invisible by default. * @author Roan Embrechts, code refactoring and virtual course support * @author Frederic Vauthier, directories management * @version $Id: work.lib.php 18636 2009-02-23 18:44:54Z yannoo $ */ /** * 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) { echo '
'.get_lang('CreateDir').'   ';
// Options
$display_output .= "".Display::return_icon('acces_tool.gif', get_lang("EditToolOptions")).' ' . get_lang("EditToolOptions") . "  ";
}
if (! $always_show_upload_form ) {
$display_output .= "  ".Display::return_icon('submit_file.gif', get_lang("UploadADocument"))." ". get_lang("UploadADocument") .'    ';
}
if ($display_output != "")
{
echo $display_output;
}
echo '
'; //image
//$a_count_directory=count_dir($work_dir.'/'.$dir,false);
$cant_files=0;
$cant_dir = 0;
if(api_is_allowed_to_edit()) {
$sql_document = "SELECT count(*) FROM $work_table WHERE url NOT LIKE '".$sub_course_dir.$dir."/%/%' AND url LIKE '".$sub_course_dir.$dir."/%'";
} else {
// gets admin_course
$table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT course_user.user_id FROM $table_user user, $table_course_user course_user
WHERE course_user.user_id=user.user_id AND course_user.course_code='".api_get_course_id()."' AND course_user.status='1'";
$res = api_sql_query($sql,__FILE__,__LINE__);
$admin_course = '';
while($row_admin = Database::fetch_row($res)) {
$admin_course .='\''.$row_admin[0].'\',';
}
$sql_document = "SELECT count(*) FROM $work_table s, $iprop_table p WHERE s.id = p.ref AND p.tool='work' AND lastedit_user_id IN(".$admin_course.'\''.api_get_user_id().'\''.") AND s.accepted='1' AND url NOT LIKE '".$sub_course_dir.$dir."/%/%' AND url LIKE '".$sub_course_dir.$dir."/%'";
}
//count documents
$res_document = api_sql_query($sql_document,__FILE__,__LINE__);
$count_document = Database::fetch_row($res_document);
$cant_files = $count_document[0];
//count directories
$sql_directory = "SELECT count(*) FROM $work_table s WHERE url NOT LIKE '/".$mydir."/%/%' AND url LIKE '/".$mydir."/%'";
$res_directory = api_sql_query($sql_directory,__FILE__,__LINE__);
$count_directory = Database::fetch_row($res_directory);
$cant_dir = $count_directory[0];
$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 (!empty($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 = '';
}
$show_as_icon = get_work_id($mydir); //true or false
if ($show_as_icon) {
$row[] = '
';
$action .= '
';
$row[] = $action;
} else {
$row[] = "";
}
$table_data[] = $row;
}
while( $work = Database::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 ref=".$work->id;
$author_qry = api_sql_query($author_sql,__FILE__,__LINE__);
$row2=Database::fetch_array($author_qry);
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='';
}
$qualification_string = '';
$add_string = '';
if(defined('IS_ASSIGNMENT')):
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)));
//$full_file_name = 'download.php?file='.$realname;
$row[]= build_document_icon_tag('file',$work->url);
$row[]= '
'.$work->title.'
';
$action .= '
';
$action .= '
';
if($work->accepted == '1') {
$action .= '
';
} else {
$action .= '
';
}
$row[] = $action;
} elseif($is_author) {
$action = '';
$action .= '
';
$action .= '
';
$row[] = $action;
} else {
$row[] = " ";
}
$table_data[] = $row;
}
}
$sorting_options=array();
$sorting_options['column']=1;
$paging_options=array();
if (isset($_GET['curdirpath'])) {
$my_params = array ('curdirpath' => Security::remove_XSS($_GET['curdirpath']));
}
if (isset($_GET['edit_dir'])) {
$my_params = array ('edit_dir' => Security::remove_XSS($_GET['edit_dir']));
}
Display::display_sortable_config_table($table_header,$table_data,$sorting_options, $paging_options,$my_params,$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)) {
$entry = replace_accents($entry);
$entry = disable_dangerous_file($entry);
$entry = replace_dangerous_char($entry);
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='')
{
//gets file title
$tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT title FROM $tbl_work WHERE id ='".(int)$move_file."'";
$result = api_sql_query($sql,__FILE__,__LINE__);
$title = Database::fetch_row($result);
$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