leave these here or move them elsewhere? // ///////////////////////////////////////////////// */ /** * Builds the form thats enables the user to * select a directory to browse/upload in * * @param array An array containing the folders we want to be able to select * @param string The current folder (path inside of the "document" directory, including the prefix "/") * @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root) * @param boolean Whether to change the renderer (this will add a template to the QuickForm object displaying the form) * @return string html form */ function build_directory_selector($folders,$curdirpath,$group_dir='',$changeRenderer=false) { $folder_titles = array(); if(get_setting('use_document_title') == 'true') { if (is_array($folders)) { $escaped_folders = array(); foreach($folders as $key=>$val){$escaped_folders[$key] = Database::escape_string($val);} $folder_sql = implode("','",$escaped_folders); $doc_table = Database::get_course_table(TABLE_DOCUMENT); $sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')"; $res = api_sql_query($sql,__FILE__,__LINE__); $folder_titles = array(); while($obj = Database::fetch_object($res)) { $folder_titles[$obj->path] = $obj->title; } } } else { if (is_array($folders)){ foreach($folders as $folder) { $folder_titles[$folder] = basename($folder); } } } require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); $form = new FormValidator('selector','POST',api_get_self()); $parent_select = $form->addElement('select', 'curdirpath', get_lang('CurrentDirectory'),'','onchange="javascript:document.selector.submit()"'); if($changeRenderer==true){ $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('{label} : {element} ','curdirpath'); } //group documents cannot be uploaded in the root if(empty($group_dir)) { $parent_select -> addOption(get_lang('HomeDirectory'),'/'); if(is_array($folders)) { foreach ($folders as $folder) { $selected = ($curdirpath==$folder)?' selected="selected"':''; $path_parts = explode('/',$folder); if($folder_titles[$folder]=='shared_folder') { $folder_titles[$folder]=get_lang('SharedFolder'); } elseif(strstr($folder_titles[$folder], 'sf_user_')) { $userinfo=Database::get_user_info_from_id(substr($folder_titles[$folder],8)); $folder_titles[$folder]=$userinfo['lastname'].', '.$userinfo['firstname']; } $label = str_repeat('   ',count($path_parts)-2).' — '.$folder_titles[$folder]; $parent_select -> addOption($label,$folder); if($selected!='') $parent_select->setSelected($folder); } } } else { foreach ($folders as $folder) { $selected = ($curdirpath==$folder)?' selected="selected"':''; $label = $folder_titles[$folder]; if( $folder == $group_dir) { $label = '/ ('.get_lang('HomeDirectory').')'; } else { $path_parts = explode('/',str_replace($group_dir,'',$folder)); $label = str_repeat('   ',count($path_parts)-2).' — '.$label; } $parent_select -> addOption($label,$folder); if($selected!='') $parent_select->setSelected($folder); } } $form=$form->toHtml(); return $form; } /** * Create a html hyperlink depending on if it's a folder or a file * * @param string $www * @param string $title * @param string $path * @param string $filetype (file/folder) * @param int $visibility (1/0) * @param int $show_as_icon - if it is true, only a clickable icon will be shown * @return string url */ function create_document_link($www, $title, $path, $filetype, $size, $visibility, $show_as_icon = false) { global $dbl_click_id; if(isset($_SESSION['_gid'])) { $req_gid = '&gidReq='.$_SESSION['_gid']; } else { $req_gid = ''; } $url_path = urlencode($path); //add class="invisible" on invisible files $visibility_class= ($visibility==0)?' class="invisible"':''; if (!$show_as_icon) { //build download link (icon) $forcedownload_link=($filetype=='folder')?api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&path='.$url_path.$req_gid:api_get_self().'?'.api_get_cidreq().'&action=download&id='.$url_path.$req_gid; //folder download or file download? $forcedownload_icon=($filetype=='folder')?'folder_zip.gif':'filesave.gif'; //prevent multiple clicks on zipped folder download $prevent_multiple_click =($filetype=='folder')?" onclick=\"javascript:if(typeof clic_$dbl_click_id == 'undefined' || clic_$dbl_click_id == false) { clic_$dbl_click_id=true; window.setTimeout('clic_".($dbl_click_id++)."=false;',10000); } else { return false; }\"":''; } $target='_top'; if($filetype=='file') { //check the extension $ext=explode('.',$path); $ext=strtolower($ext[sizeof($ext)-1]); //"htmlfiles" are shown in a frameset if($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png') { $url = "showinframes.php?".api_get_cidreq()."&file=".$url_path.$req_gid; } else { //url-encode for problematic characters (we may not call them dangerous characters...) $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq(); $url=$www.$path; } //files that we want opened in a new window if($ext=='txt') //add here { $target='_blank'; } } else { $url=api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid; } //the little download icon //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'],'',basename($path)); $tooltip_title = explode('?', basename($path)); $tooltip_title = $tooltip_title[0]; if($tooltip_title=='shared_folder') { $tooltip_title_alt=get_lang('SharedFolder'); } elseif(strstr($tooltip_title, 'sf_user_')) { $userinfo=Database::get_user_info_from_id(substr($tooltip_title,8)); $tooltip_title_alt=$userinfo['lastname'].', '.$userinfo['firstname']; } else { $tooltip_title_alt=$tooltip_title; } if (!$show_as_icon) { $force_download_html = ($size==0)?'':''.Display::return_icon($forcedownload_icon, get_lang('Download'),array('height'=>'16', 'width' => '16')).''; return ''.$title.''.$force_download_html; } else { return ''.build_document_icon_tag($filetype, $tooltip_title).''; } } /** * Builds an img html tag for the filetype * * @param string $type (file/folder) * @param string $path * @return string img html tag */ function build_document_icon_tag($type, $path) { $basename = basename($path); if ($type == 'file') { $icon = choose_image($basename); } else { if($basename =='shared_folder') { $icon = 'shared_folder.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpSharedFolder'); } else { $basename = get_lang('SharedFolder'); } } elseif(strstr($basename, 'sf_user_')) { $userinfo=Database::get_user_info_from_id(substr($basename,8)); $image_path = UserManager::get_user_picture_path_by_id(substr($basename,8),'web',false, true); if($image_path['file']=='unknown.jpg') { $icon = $image_path['file']; } else { $icon = '../upload/users/'.substr($basename,8).'/'.$image_path['file']; } $basename = $userinfo['lastname'].', '.$userinfo['firstname']; } else { if(($basename =='audio' || $basename =='flash' || $basename =='images' || $basename =='video') && api_is_allowed_to_edit()==true) { $basename = get_lang('HelpDefaultDirDocuments'); } $icon = 'folder_document.gif'; } } return Display::return_icon($icon, $basename, array('hspace'=>'5', 'align' => 'middle', 'height'=> 22, 'width' => 22)); } /** * Creates the row of edit icons for a file/folder * * @param string $curdirpath current path (cfr open folder) * @param string $type (file/folder) * @param string $path dbase path of file/folder * @param int $visibility (1/0) * @param int $id dbase id of the document * @return string html img tags with hyperlinks */ function build_edit_icons($curdirpath,$type,$path,$visibility,$id,$is_template,$is_read_only=0) { if(isset($_SESSION['_gid'])) { $req_gid = '&gidReq='.$_SESSION['_gid']; } else { $req_gid = ''; } //build URL-parameters for table-sorting $sort_params = array(); if( isset($_GET['column'])) { $sort_params[] = 'column='.$_GET['column']; } if( isset($_GET['page_nr'])) { $sort_params[] = 'page_nr='.$_GET['page_nr']; } if( isset($_GET['per_page'])) { $sort_params[] = 'per_page='.$_GET['per_page']; } if( isset($_GET['direction'])) { $sort_params[] = 'direction='.$_GET['direction']; } $sort_params = implode('&',$sort_params); $visibility_icon = ($visibility==0)?'invisible':'visible'; $visibility_command = ($visibility==0)?'set_visible':'set_invisible'; $curdirpath = urlencode($curdirpath); $modify_icons = ''; if ($is_read_only) { $modify_icons = Display::return_icon('edit_na.gif', get_lang('Modify')); $modify_icons .= ' '.Display::return_icon('delete.gif', get_lang('Delete')); $modify_icons .= ' '.Display::return_icon('deplacer_fichier_na.gif', get_lang('Move')); $modify_icons .= ' '.Display::return_icon($visibility_icon.'_na.gif', get_lang('VisibilityCannotBeChanged')); } else { $modify_icons = ''; if (strcmp($path,'/audio')===0 or strcmp($path,'/flash')===0 or strcmp($path,'/images')===0 or strcmp($path,'/shared_folder')===0 or strcmp($path,'/video')===0) { $modify_icons .= ' '.Display::return_icon('delete_na.gif',get_lang('ThisFolderCannotBeDeleted')); } else { $modify_icons .= ' '; } $modify_icons .= ' '; $modify_icons .= ' '; } if($type == 'file' && pathinfo($path,PATHINFO_EXTENSION)=='html') { if($is_template==0) { $modify_icons .= ' '.get_lang('AddAsTemplate').''; } else{ $modify_icons .= ' '; } } return $modify_icons; } function build_move_to_selector($folders,$curdirpath,$move_file,$group_dir='') { $form = '
'."\n"; $form .= ''."\n"; $form .= '
'; $form .= '
'; $form .= get_lang('MoveTo'); $form .= '
'; $form .= '
'; $form .= ' '."\n"; $form .= '
'; $form .= '
'; $form .= '
'; $form .= '
'; $form .= ' '."\n"; $form .= '
'; $form .= '
'; $form .= ''; $form .= '
'; return $form; } /** * get the path translated with title of docs and folders * @param string the real path * @return the path which should be displayed */ function get_titles_of_path($path) { global $tmp_folders_titles; $nb_slashes = substr_count($path,'/'); $tmp_path = ''; $current_slash_pos = 0; $path_displayed = ''; for($i=0; $i<$nb_slashes; $i++) { // foreach folders of the path, retrieve title. $current_slash_pos = strpos($path,'/',$current_slash_pos+1); $tmp_path = substr($path,strpos($path,'/',0),$current_slash_pos); if(empty($tmp_path)) // if empty, then we are in the final part of the path $tmp_path = $path; if(!empty($tmp_folders_titles[$tmp_path])) // if this path has soon been stored here we don't need a new query { $path_displayed .= $tmp_folders_titles[$tmp_path]; } else { $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE path LIKE BINARY "'.$tmp_path.'"'; $rs = api_sql_query($sql,__FILE__,__LINE__); $tmp_title = '/'.Database::result($rs,0,0); $path_displayed .= $tmp_title; $tmp_folders_titles[$tmp_path] = $tmp_title; } } return $path_displayed; } /** * This function displays the name of the user and makes the link tothe user tool. * * @param $user_id * @param $name * @return a link to the userInfo.php * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function display_user_link_document($user_id, $name) { if ($user_id<>0) { return ''.$name.''; } else { return get_lang('Anonymous'); } } function create_dir_form() { //create the form that asks for the directory name $new_folder_text = '
'; $new_folder_text .= ''; // form title $new_folder_text .= '
'.get_lang('CreateDir').'
'; // folder field $new_folder_text .= '
'; $new_folder_text .= '
*'.get_lang('NewDir').'
'; $new_folder_text .= '
'; $new_folder_text .= '
'; // submit button $new_folder_text .= '
'; $new_folder_text .= '
 
'; $new_folder_text .= '
'; $new_folder_text .= '
'; $new_folder_text .= '
'; $new_folder_text .= '
'; return $new_folder_text; } ?>