document.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /* EXTRA FUNCTIONS FOR DOCUMENTS TOOL */
  4. /**
  5. * Builds the form thats enables the user to
  6. * select a directory to browse/upload in
  7. *
  8. * @param array An array containing the folders we want to be able to select
  9. * @param string The current folder (path inside of the "document" directory, including the prefix "/")
  10. * @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root)
  11. * @param boolean Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form)
  12. * @return string html form
  13. */
  14. function build_directory_selector($folders, $curdirpath, $group_dir = '', $change_renderer = false) {
  15. $folder_titles = array();
  16. if (api_get_setting('use_document_title') == 'true') {
  17. if (is_array($folders)) {
  18. $escaped_folders = array();
  19. foreach ($folders as $key => & $val) {
  20. $escaped_folders[$key] = Database::escape_string($val);
  21. }
  22. $folder_sql = implode("','", $escaped_folders);
  23. $doc_table = Database::get_course_table(TABLE_DOCUMENT);
  24. $sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')";
  25. $res = Database::query($sql);
  26. $folder_titles = array();
  27. while ($obj = Database::fetch_object($res)) {
  28. $folder_titles[$obj->path] = $obj->title;
  29. }
  30. }
  31. } else {
  32. if (is_array($folders)) {
  33. foreach ($folders as & $folder) {
  34. $folder_titles[$folder] = basename($folder);
  35. }
  36. }
  37. }
  38. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  39. $form = new FormValidator('selector', 'POST', api_get_self());
  40. $parent_select = $form->addElement('select', 'curdirpath', get_lang('CurrentDirectory'), '', 'onchange="javascript: document.selector.submit();"');
  41. if ($change_renderer) {
  42. $renderer = $form->defaultRenderer();
  43. $renderer->setElementTemplate('<span>{label} : {element}</span> ','curdirpath');
  44. }
  45. // Group documents cannot be uploaded in the root
  46. if (empty($group_dir)) {
  47. $parent_select -> addOption(get_lang('HomeDirectory'), '/');
  48. if (is_array($folders)) {
  49. foreach ($folders as & $folder) {
  50. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  51. $path_parts = explode('/', $folder);
  52. if ($folder_titles[$folder] == 'shared_folder') {
  53. $folder_titles[$folder] = get_lang('SharedFolder');
  54. } elseif (strstr($folder_titles[$folder], 'sf_user_')) {
  55. $userinfo = Database::get_user_info_from_id(substr($folder_titles[$folder], 8));
  56. $folder_titles[$folder] = api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  57. }
  58. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$folder_titles[$folder];
  59. $parent_select -> addOption($label, $folder);
  60. if ($selected != '') {
  61. $parent_select->setSelected($folder);
  62. }
  63. }
  64. }
  65. } else {
  66. foreach ($folders as & $folder) {
  67. $selected = ($curdirpath==$folder) ? ' selected="selected"' : '';
  68. $label = $folder_titles[$folder];
  69. if ($folder == $group_dir) {
  70. $label = '/ ('.get_lang('HomeDirectory').')';
  71. } else {
  72. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  73. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  74. }
  75. $parent_select -> addOption($label, $folder);
  76. if ($selected != '') {
  77. $parent_select->setSelected($folder);
  78. }
  79. }
  80. }
  81. $form = $form->toHtml();
  82. return $form;
  83. }
  84. /**
  85. * Create a html hyperlink depending on if it's a folder or a file
  86. *
  87. * @param string $www
  88. * @param string $title
  89. * @param string $path
  90. * @param string $filetype (file/folder)
  91. * @param int $visibility (1/0)
  92. * @param int $show_as_icon - if it is true, only a clickable icon will be shown
  93. * @return string url
  94. */
  95. function create_document_link($www, $title, $path, $filetype, $size, $visibility, $show_as_icon = false) {
  96. global $dbl_click_id;
  97. if (isset($_SESSION['_gid'])) {
  98. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  99. } else {
  100. $req_gid = '';
  101. }
  102. $url_path = urlencode($path);
  103. // Add class="invisible" on invisible files
  104. $visibility_class = ($visibility == 0) ? ' class="invisible"' : '';
  105. if (!$show_as_icon) {
  106. // Build download link (icon)
  107. $forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&amp;path='.$url_path.$req_gid : api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$url_path.$req_gid;
  108. // Folder download or file download?
  109. $forcedownload_icon = ($filetype == 'folder') ? 'folder_zip.gif' : 'filesave.gif';
  110. // Prevent multiple clicks on zipped folder download
  111. $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; }\"":'';
  112. }
  113. $target = '_self';
  114. if ($filetype == 'file') {
  115. // Check the extension
  116. $ext = explode('.', $path);
  117. $ext = strtolower($ext[sizeof($ext) - 1]);
  118. // "htmlfiles" are shown in a frameset
  119. if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png') {
  120. $url = 'showinframes.php?'.api_get_cidreq().'&amp;file='.$url_path.$req_gid;
  121. } else {
  122. // url-encode for problematic characters (we may not call them dangerous characters...)
  123. $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
  124. $url = $www.$path;
  125. }
  126. // Files that we want opened in a new window
  127. if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here
  128. $target = '_blank';
  129. }
  130. } else {
  131. $url = api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$url_path.$req_gid;
  132. }
  133. // The little download icon
  134. //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'], '', basename($path));
  135. $tooltip_title = explode('?', basename($path));
  136. $tooltip_title = $tooltip_title[0];
  137. if ($tooltip_title == 'shared_folder') {
  138. $tooltip_title_alt = get_lang('SharedFolder');
  139. } elseif(strstr($tooltip_title, 'sf_user_')) {
  140. $userinfo = Database::get_user_info_from_id(substr($tooltip_title, 8));
  141. $tooltip_title_alt = api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  142. } else {
  143. $tooltip_title_alt = $tooltip_title;
  144. }
  145. if (!$show_as_icon) {
  146. if ($filetype == 'folder') {
  147. if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
  148. $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).'</a>';
  149. }
  150. } else {
  151. $force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array('height'=>'16', 'width' => '16')).'</a>';
  152. }
  153. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html;
  154. } else {
  155. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $tooltip_title).'</a>';
  156. }
  157. }
  158. /**
  159. * Builds an img html tag for the filetype
  160. *
  161. * @param string $type (file/folder)
  162. * @param string $path
  163. * @return string img html tag
  164. */
  165. function build_document_icon_tag($type, $path) {
  166. $basename = basename($path);
  167. $current_session_id = api_get_session_id();
  168. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  169. if ($type == 'file') {
  170. $icon = choose_image($basename);
  171. } else {
  172. if ($basename == 'shared_folder') {
  173. $icon = 'shared_folder.gif';
  174. if ($is_allowed_to_edit) {
  175. $basename = get_lang('HelpSharedFolder');
  176. } else {
  177. $basename = get_lang('SharedFolder');
  178. }
  179. } elseif(strstr($basename, 'sf_user_')) {
  180. $userinfo = Database::get_user_info_from_id(substr($basename, 8));
  181. $image_path = UserManager::get_user_picture_path_by_id(substr($basename, 8), 'web', false, true);
  182. if ($image_path['file'] == 'unknown.jpg') {
  183. $icon = $image_path['file'];
  184. } else {
  185. $icon = '../upload/users/'.substr($basename, 8).'/'.$image_path['file'];
  186. }
  187. $basename = api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  188. } else {
  189. if (($basename =='audio' || $basename =='flash' || $basename =='images' || $basename =='video') && api_is_allowed_to_edit()) {
  190. $basename = get_lang('HelpDefaultDirDocuments');
  191. }
  192. $icon = 'folder_document.gif';
  193. }
  194. }
  195. return Display::return_icon($icon, $basename, array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22));
  196. }
  197. /**
  198. * Creates the row of edit icons for a file/folder
  199. *
  200. * @param string $curdirpath current path (cfr open folder)
  201. * @param string $type (file/folder)
  202. * @param string $path dbase path of file/folder
  203. * @param int $visibility (1/0)
  204. * @param int $id dbase id of the document
  205. * @return string html img tags with hyperlinks
  206. */
  207. function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_template, $is_read_only = 0, $session_id = 0) {
  208. if (isset($_SESSION['_gid'])) {
  209. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  210. } else {
  211. $req_gid = '';
  212. }
  213. // Build URL-parameters for table-sorting
  214. $sort_params = array();
  215. if (isset($_GET['column'])) {
  216. $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
  217. }
  218. if (isset($_GET['page_nr'])) {
  219. $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
  220. }
  221. if (isset($_GET['per_page'])) {
  222. $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
  223. }
  224. if (isset($_GET['direction'])) {
  225. $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
  226. }
  227. $sort_params = implode('&amp;', $sort_params);
  228. $visibility_icon = ($visibility == 0) ? 'invisible' : 'visible';
  229. $visibility_command = ($visibility == 0) ? 'set_visible' : 'set_invisible';
  230. $curdirpath = urlencode($curdirpath);
  231. $is_certificate_mode = DocumentManager::is_certificate_mode($path);
  232. $modify_icons = '';
  233. $cur_ses = api_get_session_id();
  234. // If document is read only *or* we're in a session and the document
  235. // is from a non-session context, hide the edition capabilities
  236. if ($is_read_only /*or ($session_id!=$cur_ses)*/) {
  237. $modify_icons = Display::return_icon('edit_na.gif', get_lang('Modify'));
  238. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.gif', get_lang('Delete'));
  239. $modify_icons .= '&nbsp;'.Display::return_icon('deplacer_fichier_na.gif', get_lang('Move'));
  240. $modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'_na.gif', get_lang('VisibilityCannotBeChanged'));
  241. } else {
  242. if ($is_certificate_mode) {
  243. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'&selectcat='.$gradebook_category.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="" /></a>';
  244. } else {
  245. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="" /></a>';
  246. }
  247. 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) {
  248. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.gif',get_lang('ThisFolderCannotBeDeleted'));
  249. } else {
  250. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  251. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'delete_certificate_id='.$id.'&selectcat='.$gradebook_category.' " onclick="return confirmation(\''.basename($path).'\');"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="" /></a>';
  252. } else {
  253. if ($is_certificate_mode) {
  254. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'&selectcat='.$gradebook_category.'" onclick="return confirmation(\''.basename($path).'\');"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="" /></a>';
  255. } else {
  256. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="" /></a>';
  257. }
  258. }
  259. }
  260. if ($is_certificate_mode) {
  261. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;move='.urlencode($path).$req_gid.'&selectcat='.$gradebook_category.'"><img src="../img/deplacer_fichier.gif" border="0" title="'.get_lang('Move').'" alt="" /></a>';
  262. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'&selectcat='.$gradebook_category.'"><img src="../img/'.$visibility_icon.'.gif" border="0" title="'.get_lang('Visible').'" alt="" /></a>';
  263. } else {
  264. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;move='.urlencode($path).$req_gid.'"><img src="../img/deplacer_fichier.gif" border="0" title="'.get_lang('Move').'" alt="" /></a>';
  265. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/'.$visibility_icon.'.gif" border="0" title="'.get_lang('Visible').'" alt="" /></a>';
  266. }
  267. }
  268. if ($type == 'file' && pathinfo($path, PATHINFO_EXTENSION) == 'html') {
  269. if ($is_template == 0) {
  270. if ((isset($_GET['curdirpath']) && $_GET['curdirpath']<>'/certificates') || !isset($_GET['curdirpath'])) {
  271. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;add_as_template='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/wizard_small.gif" border="0" title="'.get_lang('AddAsTemplate').'" alt="'.get_lang('AddAsTemplate').'" /></a>';
  272. }
  273. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course
  274. $visibility_icon_certificate='nocertificate';
  275. if (DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  276. $visibility_icon_certificate='certificate';
  277. $certificate=get_lang('DefaultCertificate');
  278. $preview=get_lang('PreviewCertificate');
  279. $is_preview=true;
  280. } else {
  281. $is_preview=false;
  282. $certificate=get_lang('NoDefaultCertificate');
  283. }
  284. if (isset($_GET['selectcat'])) {
  285. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;selectcat='.Security::remove_XSS($_GET['selectcat']).'&amp;set_certificate='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/'.$visibility_icon_certificate.'.png" border="0" title="'.$certificate.'" alt="" /></a>';
  286. if ($is_preview) {
  287. $modify_icons .= '&nbsp;<a target="_blank" href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;set_preview='.$id.$req_gid.'&amp;'.$sort_params.'" ><img src="../img/search.gif" border="0" title="'.$preview.'" alt="" width="16" height="16"/></a>';
  288. }
  289. }
  290. }
  291. } else {
  292. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;remove_as_template='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/wizard_gray_small.gif" border="0" title="'.get_lang('RemoveAsTemplate').'" alt=""'.get_lang('RemoveAsTemplate').'" /></a>';
  293. }
  294. }
  295. return $modify_icons;
  296. }
  297. function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
  298. $form = '<form name="move_to" action="'.api_get_self().'" method="post">'."\n";
  299. $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />'."\n";
  300. $form .= '<div class="row">';
  301. $form .= ' <div class="label">';
  302. $form .= get_lang('MoveTo');
  303. $form .= ' </div>';
  304. $form .= ' <div class="formw">';
  305. $form .= ' <select name="move_to">'."\n";
  306. // Group documents cannot be uploaded in the root
  307. if ($group_dir == '') {
  308. if ($curdirpath != '/') {
  309. $form .= '<option value="/">/ ('.get_lang('HomeDirectory').')</option>';
  310. }
  311. if (is_array($folders)) {
  312. foreach ($folders as & $folder) {
  313. // You cannot move a file to:
  314. // 1. current directory
  315. // 2. inside the folder you want to move
  316. // 3. inside a subfolder of the folder you want to move
  317. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  318. $path_displayed = $folder;
  319. // If document title is used, we have to display titles instead of real paths...
  320. if (api_get_setting('use_document_title')) {
  321. $path_displayed = get_titles_of_path($folder);
  322. }
  323. $form .= '<option value="'.$folder.'">'.$path_displayed.'</option>'."\n";
  324. }
  325. }
  326. }
  327. } else {
  328. foreach ($folders as $folder) {
  329. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) { // Cannot copy dir into his own subdir
  330. if (api_get_setting('use_document_title')) {
  331. $path_displayed = get_titles_of_path($folder);
  332. }
  333. $display_folder = substr($path_displayed,strlen($group_dir));
  334. $display_folder = ($display_folder == '') ? '/ ('.get_lang('HomeDirectory').')' : $display_folder;
  335. $form .= '<option value="'.$folder.'">'.$display_folder.'</option>'."\n";
  336. }
  337. }
  338. }
  339. $form .= ' </select>'."\n";
  340. $form .= ' </div>';
  341. $form .= '<div class="row">';
  342. $form .= ' <div class="label"></div>';
  343. $form .= ' <div class="formw">';
  344. $form .= ' <button type="submit" class="next" name="move_file_submit">'.get_lang('MoveElement').'</button>'."\n";
  345. $form .= ' </div>';
  346. $form .= '</div>';
  347. $form .= '</form>';
  348. $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  349. return $form;
  350. }
  351. /**
  352. * Gets the path translated with title of docs and folders
  353. * @param string the real path
  354. * @return the path which should be displayed
  355. */
  356. function get_titles_of_path($path) {
  357. global $tmp_folders_titles;
  358. $nb_slashes = substr_count($path, '/');
  359. $tmp_path = '';
  360. $current_slash_pos = 0;
  361. $path_displayed = '';
  362. for ($i = 0; $i < $nb_slashes; $i++) {
  363. // For each folder of the path, retrieve title.
  364. $current_slash_pos = strpos($path, '/', $current_slash_pos + 1);
  365. $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos);
  366. if (empty($tmp_path)) {
  367. // If empty, then we are in the final part of the path
  368. $tmp_path = $path;
  369. }
  370. if (!empty($tmp_folders_titles[$tmp_path])) {
  371. // If this path has soon been stored here we don't need a new query
  372. $path_displayed .= $tmp_folders_titles[$tmp_path];
  373. } else {
  374. $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE path LIKE BINARY "'.$tmp_path.'"';
  375. $rs = Database::query($sql);
  376. $tmp_title = '/'.Database::result($rs, 0, 0);
  377. $path_displayed .= $tmp_title;
  378. $tmp_folders_titles[$tmp_path] = $tmp_title;
  379. }
  380. }
  381. return $path_displayed;
  382. }
  383. /**
  384. * This function displays the name of the user and makes the link tothe user tool.
  385. *
  386. * @param $user_id
  387. * @param $name
  388. * @return a link to the userInfo.php
  389. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  390. * @version february 2006, dokeos 1.8
  391. */
  392. function display_user_link_document($user_id, $name) {
  393. if ($user_id != 0) {
  394. return '<a href="../user/userInfo.php?uInfo='.$user_id.'">'.$name.'</a>';
  395. } else {
  396. return get_lang('Anonymous');
  397. }
  398. }
  399. /**
  400. * Creates form that asks for the directory name.
  401. * @return string html-output text for the form
  402. */
  403. function create_dir_form() {
  404. $new_folder_text = '<form action="'.api_get_self().'" method="post">';
  405. $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.Security::remove_XSS($_GET['curdirpath']).'" />';
  406. // Form title
  407. $new_folder_text .= '<div class="row"><div class="form_header">'.get_lang('CreateDir').'</div></div>';
  408. // Folder field
  409. $new_folder_text .= '<div class="row">';
  410. $new_folder_text .= '<div class="label"><span class="form_required">*</span>'.get_lang('NewDir').'</div>';
  411. $new_folder_text .= '<div class="formw"><input type="text" name="dirname" /></div>';
  412. $new_folder_text .= '</div>';
  413. // Submit button
  414. $new_folder_text .= '<div class="row">';
  415. $new_folder_text .= '<div class="label">&nbsp;</div>';
  416. $new_folder_text .= '<div class="formw"><button type="submit" class="add" name="create_dir">'.get_lang('CreateFolder').'</button></div>';
  417. $new_folder_text .= '</div>';
  418. $new_folder_text .= '</form>';
  419. $new_folder_text .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  420. return $new_folder_text;
  421. }
  422. /**
  423. * Checks whether the user is in his/her shared folder
  424. * @return return bool Return true when user is in his shared folder
  425. */
  426. function is_my_shared_folder($user_id, $path) {
  427. return Security::remove_XSS($path) == '/shared_folder/sf_user_'.$user_id;
  428. }