123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- <?php
- 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
- {
- 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('<span>{label} : {element}</span> ','curdirpath');
- }
-
-
- if($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);
- $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;
- }
- function create_document_link($www,$title,$path,$filetype,$size,$visibility)
- {
- global $dbl_click_id;
- if(isset($_SESSION['_gid']))
- {
- $req_gid = '&gidReq='.$_SESSION['_gid'];
- }
- else
- {
- $req_gid = '';
- }
- $url_path = urlencode($path);
-
- $visibility_class= ($visibility==0)?' class="invisible"':'';
-
- $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;
-
- $forcedownload_icon=($filetype=='folder')?'folder_zip.gif':'filesave.gif';
-
- $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') {
-
- $ext=explode('.',$path);
- $ext=strtolower($ext[sizeof($ext)-1]);
-
- 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
- {
-
- $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
- $url=$www.$path;
- }
-
- if($ext=='txt')
- {
- $target='_blank';
- }
- }
- else
- {
- $url=api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid;
- }
-
- $force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'><img width="16" height="16" src="'.api_get_path(WEB_CODE_PATH).'img/'.$forcedownload_icon.'" alt="" /></a>';
-
- $tooltip_title = str_replace('?cidReq='.$_GET['cidReq'],'',basename($path));
- return '<a href="'.$url.'" title="'.$tooltip_title.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html;
- }
- function build_document_icon_tag($type,$path)
- {
- $icon='folder_document.gif';
- if($type=='file')
- {
- $icon=choose_image(basename($path));
- }
- return '<img src="'.api_get_path(WEB_CODE_PATH).'img/'.$icon.'" border="0" hspace="5" align="middle" alt="" />';
- }
- 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 = '';
- }
-
- $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 = '<img src="../img/edit_na.gif" border="0" title="'.get_lang('Modify').'" alt="" />';
- $modify_icons .= ' <img src="../img/delete_na.gif" border="0" title="'.get_lang('Delete').'" alt="" />';
- $modify_icons .= ' <img src="../img/deplacer_fichier_na.gif" border="0" title="'.get_lang('Move').'" alt="" />';
- $modify_icons .= ' <img src="../img/'.$visibility_icon.'_na.gif" border="0" title="'.get_lang('Visible').'" alt="" />';
- }
- else
- {
- $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&file='.urlencode($path).$req_gid.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="" /></a>';
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&delete='.urlencode($path).$req_gid.'&'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="" /></a>';
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&move='.urlencode($path).$req_gid.'"><img src="../img/deplacer_fichier.gif" border="0" title="'.get_lang('Move').'" alt="" /></a>';
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&'.$visibility_command.'='.$id.$req_gid.'&'.$sort_params.'"><img src="../img/'.$visibility_icon.'.gif" border="0" title="'.get_lang('Visible').'" alt="" /></a>';
- }
-
- if($type == 'file' && pathinfo($path,PATHINFO_EXTENSION)=='html')
- {
- if($is_template==0)
- {
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&add_as_template='.$id.$req_gid.'&'.$sort_params.'"><img src="../img/wizard_small.gif" border="0" title="'.get_lang('AddAsTemplate').'" alt="'.get_lang('AddAsTemplate').'" /></a>';
- }
- else{
- $modify_icons .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&remove_as_template='.$id.$req_gid.'&'.$sort_params.'"><img src="../img/wizard_gray_small.gif" border="0" title="'.get_lang('RemoveAsTemplate').'" alt=""'.get_lang('RemoveAsTemplate').'" /></a>';
- }
- }
- return $modify_icons;
- }
- function build_move_to_selector($folders,$curdirpath,$move_file,$group_dir='')
- {
- $form = '<form name="move_to" action="'.api_get_self().'" method="post">'."\n";
- $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />'."\n";
- $form .= get_lang('MoveTo').' <select name="move_to">'."\n";
-
-
- if($group_dir=='')
- {
- if($curdirpath!='/')
- {
- $form .= '<option value="/">/ ('.get_lang('HomeDirectory').')</option>';
- }
- if(is_array($folders))
- {
- foreach ($folders AS $folder)
- {
-
-
-
-
- if(($curdirpath!=$folder) && ($folder!=$move_file) && (substr($folder,0,strlen($move_file)+1) != $move_file.'/'))
- {
- $path_displayed = $folder;
-
-
- if(api_get_setting('use_document_title'))
- {
- $path_displayed = get_titles_of_path($folder);
- }
- $form .= '<option value="'.$folder.'">'.$path_displayed.'</option>'."\n";
- }
- }
- }
- }
- else
- {
- foreach ($folders AS $folder)
- {
- if(($curdirpath!=$folder) && ($folder!=$move_file) && (substr($folder,0,strlen($move_file)+1) != $move_file.'/'))
- {
- if(api_get_setting('use_document_title'))
- {
- $path_displayed = get_titles_of_path($folder);
- }
-
- $display_folder = substr($path_displayed,strlen($group_dir));
- $display_folder = ($display_folder == '')?'/ ('.get_lang('HomeDirectory').')':$display_folder;
-
- $form .= '<option value="'.$folder.'">'.$display_folder.'</option>'."\n";
- }
- }
- }
- $form .= '</select>'."\n";
- $form .= '<input type="submit" name="move_file_submit" value="'.get_lang('Ok').'" />'."\n";
- $form .= '</form>';
- return $form;
- }
- 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++)
- {
-
- $current_slash_pos = strpos($path,'/',$current_slash_pos+1);
- $tmp_path = substr($path,strpos($path,'/',0),$current_slash_pos);
-
- if(empty($tmp_path))
- $tmp_path = $path;
-
- if(!empty($tmp_folders_titles[$tmp_path]))
- {
- $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;
- }
-
- function display_user_link_document($user_id, $name)
- {
- if ($user_id<>0)
- {
- return '<a href="../user/userInfo.php?uInfo='.$user_id.'">'.$name.'</a>';
- }
- else
- {
- return get_lang('Anonymous');
- }
- }
- ?>
|