document.inc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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('Documents'), '/');
  48. if (is_array($folders)) {
  49. foreach ($folders as & $folder) {
  50. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  51. $path_parts = explode('/', $folder);
  52. $folder_titles[$folder] = cut($folder_titles[$folder], 80);
  53. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$folder_titles[$folder];
  54. $parent_select -> addOption($label, $folder);
  55. if ($selected != '') {
  56. $parent_select->setSelected($folder);
  57. }
  58. }
  59. }
  60. } else {
  61. foreach ($folders as & $folder) {
  62. $selected = ($curdirpath==$folder) ? ' selected="selected"' : '';
  63. $label = $folder_titles[$folder];
  64. if ($folder == $group_dir) {
  65. $label = get_lang('Documents');
  66. } else {
  67. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  68. $label = cut($label, 80);
  69. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  70. }
  71. $parent_select -> addOption($label, $folder);
  72. if ($selected != '') {
  73. $parent_select->setSelected($folder);
  74. }
  75. }
  76. }
  77. $form = $form->toHtml();
  78. return $form;
  79. }
  80. /**
  81. * Create a html hyperlink depending on if it's a folder or a file
  82. *
  83. * @param string $www
  84. * @param string $title
  85. * @param string $path
  86. * @param string $filetype (file/folder)
  87. * @param int $visibility (1/0)
  88. * @param int $show_as_icon - if it is true, only a clickable icon will be shown
  89. * @return string url
  90. */
  91. function create_document_link($www, $title, $path, $filetype, $size, $visibility, $show_as_icon = false) {
  92. global $dbl_click_id;
  93. if (isset($_SESSION['_gid'])) {
  94. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  95. } else {
  96. $req_gid = '';
  97. }
  98. $url_path = urlencode($path);
  99. // Add class="invisible" on invisible files
  100. $visibility_class = ($visibility == 0) ? ' class="invisible"' : '';
  101. if (!$show_as_icon) {
  102. // Build download link (icon)
  103. $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;
  104. // Folder download or file download?
  105. $forcedownload_icon = ($filetype == 'folder') ? 'folder_zip.gif' : 'filesave.gif';
  106. // Prevent multiple clicks on zipped folder download
  107. $prevent_multiple_click = ($filetype == 'folder') ? " onclick=\"javascript: if(typeof clic_$dbl_click_id == 'undefined' || !clic_$dbl_click_id) { clic_$dbl_click_id=true; window.setTimeout('clic_".($dbl_click_id++)."=false;',10000); } else { return false; }\"":'';
  108. }
  109. $target = '_self';
  110. if ($filetype == 'file') {
  111. // Check the extension
  112. $ext = explode('.', $path);
  113. $ext = strtolower($ext[sizeof($ext) - 1]);
  114. // "htmlfiles" are shown in a frameset
  115. if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'swf' || $ext == 'mp3' || $ext == 'mp4' ||(($ext== 'ogg' || $ext== 'ogx' || $ext== 'oga' || $ext== 'ogv') && api_browser_support('ogg')) ||($ext == 'svg' && api_browser_support('svg'))) {
  116. $url = 'showinframes.php?'.api_get_cidreq().'&amp;file='.$url_path.$req_gid;
  117. } else {
  118. // url-encode for problematic characters (we may not call them dangerous characters...)
  119. $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
  120. $url = $www.$path;
  121. }
  122. // Files that we want opened in a new window
  123. if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here
  124. $target = '_blank';
  125. }
  126. } else {
  127. $url = api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$url_path.$req_gid;
  128. }
  129. // The little download icon
  130. //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'], '', basename($path));
  131. $tooltip_title = explode('?', basename($path));
  132. $tooltip_title = $tooltip_title[0];
  133. $tooltip_title_alt = $tooltip_title;
  134. if ($tooltip_title == 'shared_folder') {
  135. $tooltip_title_alt = get_lang('SharedFolder');
  136. }elseif(strstr($tooltip_title, 'shared_folder_session_')) {
  137. $tooltip_title_alt = get_lang('SharedFolder').' ('.api_get_session_name($current_session_id).')';
  138. }elseif(strstr($tooltip_title, 'sf_user_')) {
  139. $userinfo = Database::get_user_info_from_id(substr($tooltip_title, 8));
  140. $tooltip_title_alt = get_lang('SharedFolder').' ('.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).')';
  141. }
  142. $current_session_id=api_get_session_id();
  143. if (!$show_as_icon) {
  144. if ($filetype == 'folder') {
  145. if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
  146. //filter when I am into shared folder, I can show for donwload only my shared folder
  147. if(is_shared_folder($_GET['curdirpath'],$current_session_id))
  148. {
  149. if (preg_match('/shared_folder\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link))|| preg_match('/shared_folder_session_'.$current_session_id.'\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin())
  150. {
  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. }
  154. elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin())
  155. {
  156. $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>';
  157. }
  158. }
  159. } else {
  160. $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>';
  161. }
  162. //copy files to users myfiles
  163. if(api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0){
  164. $copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&curdirpath='.$_GET['curdirpath'].'&amp;action=copytomyfiles&amp;id='.$url_path.$req_gid :api_get_self().'?'.api_get_cidreq();
  165. if($filetype == 'file')
  166. {
  167. $copy_to_myfiles='<a href="'.$copy_myfiles_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon('briefcase_small.png', get_lang('CopyToMyFiles'), array('height'=>'16', 'width' => '16')).'&nbsp;&nbsp;</a>';
  168. }
  169. }
  170. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html.$copy_to_myfiles;
  171. //end copy files to users myfiles
  172. } else {
  173. if(preg_match('/shared_folder/', urldecode($url)) && preg_match('/shared_folder$/', urldecode($url))==false && preg_match('/shared_folder_session_'.$current_session_id.'$/', urldecode($url))==false){
  174. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $tooltip_title).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
  175. }
  176. else
  177. {
  178. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $tooltip_title).'</a>';
  179. }
  180. }
  181. }
  182. /**
  183. * Builds an img html tag for the filetype
  184. *
  185. * @param string $type (file/folder)
  186. * @param string $path
  187. * @return string img html tag
  188. */
  189. function build_document_icon_tag($type, $path) {
  190. $basename = basename($path);
  191. $current_session_id = api_get_session_id();
  192. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  193. if ($type == 'file') {
  194. $icon = choose_image($basename);
  195. } else {
  196. if ($basename == 'shared_folder') {
  197. $icon = 'shared_folder.gif';
  198. if ($is_allowed_to_edit) {
  199. $basename = get_lang('HelpSharedFolder');
  200. } else {
  201. $basename = get_lang('SharedFolder');
  202. }
  203. }elseif(strstr($basename, 'shared_folder_session_')) {
  204. if ($is_allowed_to_edit) {
  205. $basename = '***('.api_get_session_name($current_session_id).')*** '.get_lang('HelpSharedFolder');
  206. } else {
  207. $basename = get_lang('SharedFolder').' ('.api_get_session_name($current_session_id).')';
  208. }
  209. $icon = 'shared_folder.gif';
  210. }elseif(strstr($basename, 'sf_user_')) {
  211. $userinfo = Database::get_user_info_from_id(substr($basename, 8));
  212. $image_path = UserManager::get_user_picture_path_by_id(substr($basename, 8), 'web', false, true);
  213. if ($image_path['file'] == 'unknown.jpg') {
  214. $icon = $image_path['file'];
  215. } else {
  216. $icon = '../upload/users/'.substr($basename, 8).'/'.$image_path['file'];
  217. }
  218. $basename = get_lang('SharedFolder').' ('.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).')';
  219. } else {
  220. if (($basename =='audio' || $basename =='flash' || $basename =='images' || $basename =='video') && api_is_allowed_to_edit()) {
  221. $basename = get_lang('HelpDefaultDirDocuments');
  222. }
  223. $icon = 'folder_document.gif';
  224. }
  225. }
  226. return Display::return_icon($icon, $basename, array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22));
  227. }
  228. /**
  229. * Creates the row of edit icons for a file/folder
  230. *
  231. * @param string $curdirpath current path (cfr open folder)
  232. * @param string $type (file/folder)
  233. * @param string $path dbase path of file/folder
  234. * @param int $visibility (1/0)
  235. * @param int $id dbase id of the document
  236. * @return string html img tags with hyperlinks
  237. */
  238. function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_template, $is_read_only = 0, $session_id = 0) {
  239. if (isset($_SESSION['_gid'])) {
  240. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  241. } else {
  242. $req_gid = '';
  243. }
  244. // Build URL-parameters for table-sorting
  245. $sort_params = array();
  246. if (isset($_GET['column'])) {
  247. $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
  248. }
  249. if (isset($_GET['page_nr'])) {
  250. $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
  251. }
  252. if (isset($_GET['per_page'])) {
  253. $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
  254. }
  255. if (isset($_GET['direction'])) {
  256. $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
  257. }
  258. $sort_params = implode('&amp;', $sort_params);
  259. $visibility_icon = ($visibility == 0) ? 'invisible' : 'visible';
  260. $visibility_command = ($visibility == 0) ? 'set_visible' : 'set_invisible';
  261. $curdirpath = urlencode($curdirpath);
  262. $is_certificate_mode = DocumentManager::is_certificate_mode($path);
  263. $modify_icons = '';
  264. $cur_ses = api_get_session_id();
  265. $extension = pathinfo($path, PATHINFO_EXTENSION);
  266. // If document is read only *or* we're in a session and the document
  267. // is from a non-session context, hide the edition capabilities
  268. if ($is_read_only /*or ($session_id!=$cur_ses)*/) {
  269. $modify_icons = Display::return_icon('edit_na.gif', get_lang('Modify'));
  270. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.gif', get_lang('Delete'));
  271. $modify_icons .= '&nbsp;'.Display::return_icon('deplacer_fichier_na.gif', get_lang('Move'));
  272. $modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'_na.gif', get_lang('VisibilityCannotBeChanged'));
  273. } else {
  274. if ($is_certificate_mode) {
  275. $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>';
  276. }else {
  277. if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){
  278. $modify_icons = '<a href="edit_drawing.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>';
  279. }else{
  280. $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>';
  281. }
  282. }
  283. if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
  284. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.gif',get_lang('ThisFolderCannotBeDeleted'));
  285. } else {
  286. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  287. $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>';
  288. } else {
  289. if ($is_certificate_mode) {
  290. $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>';
  291. } else {
  292. $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>';
  293. }
  294. }
  295. }
  296. if ($is_certificate_mode) {
  297. $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>';
  298. $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>';
  299. } else {
  300. $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>';
  301. $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>';
  302. }
  303. }
  304. //$extension = pathinfo($path, PATHINFO_EXTENSION);//already load above
  305. if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) {
  306. if ($is_template == 0) {
  307. if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) {
  308. $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>';
  309. }
  310. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course
  311. $visibility_icon_certificate='nocertificate';
  312. if (DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  313. $visibility_icon_certificate='certificate';
  314. $certificate=get_lang('DefaultCertificate');
  315. $preview=get_lang('PreviewCertificate');
  316. $is_preview=true;
  317. } else {
  318. $is_preview=false;
  319. $certificate=get_lang('NoDefaultCertificate');
  320. }
  321. if (isset($_GET['selectcat'])) {
  322. $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>';
  323. if ($is_preview) {
  324. $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="" /></a>';
  325. }
  326. }
  327. }
  328. } else {
  329. $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>';
  330. }
  331. $modify_icons .= '&nbsp;<a href="export_htmldoc2pdf.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'"><img src="../img/file_pdf_small.gif" border="0" title="'.get_lang('Export2PDF').'" alt="" /></a>';
  332. }
  333. return $modify_icons;
  334. }
  335. function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
  336. $form = '<form name="move_to" action="'.api_get_self().'" method="post">'."\n";
  337. $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />'."\n";
  338. $form .= '<div class="row">';
  339. $form .= ' <div class="label">';
  340. $form .= get_lang('MoveTo');
  341. $form .= ' </div>';
  342. $form .= ' <div class="formw">';
  343. $form .= ' <select name="move_to">'."\n";
  344. // Group documents cannot be uploaded in the root
  345. if ($group_dir == '') {
  346. if ($curdirpath != '/') {
  347. $form .= '<option value="/">'.get_lang('Documents').'</option>';
  348. }
  349. if (is_array($folders)) {
  350. foreach ($folders as & $folder) {
  351. // You cannot move a file to:
  352. // 1. current directory
  353. // 2. inside the folder you want to move
  354. // 3. inside a subfolder of the folder you want to move
  355. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  356. $path_displayed = $folder;
  357. // If document title is used, we have to display titles instead of real paths...
  358. if (api_get_setting('use_document_title')) {
  359. $path_displayed = get_titles_of_path($folder);
  360. }
  361. $form .= '<option value="'.$folder.'">'.$path_displayed.'</option>'."\n";
  362. }
  363. }
  364. }
  365. } else {
  366. foreach ($folders as $folder) {
  367. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) { // Cannot copy dir into his own subdir
  368. if (api_get_setting('use_document_title')) {
  369. $path_displayed = get_titles_of_path($folder);
  370. }
  371. $display_folder = substr($path_displayed,strlen($group_dir));
  372. $display_folder = ($display_folder == '') ? get_lang('Documents') : $display_folder;
  373. $form .= '<option value="'.$folder.'">'.$display_folder.'</option>'."\n";
  374. }
  375. }
  376. }
  377. $form .= ' </select>'."\n";
  378. $form .= ' </div>';
  379. $form .= '<div class="row">';
  380. $form .= ' <div class="label"></div>';
  381. $form .= ' <div class="formw">';
  382. $form .= ' <button type="submit" class="next" name="move_file_submit">'.get_lang('MoveElement').'</button>'."\n";
  383. $form .= ' </div>';
  384. $form .= '</div>';
  385. $form .= '</form>';
  386. $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  387. return $form;
  388. }
  389. /**
  390. * Gets the path translated with title of docs and folders
  391. * @param string the real path
  392. * @return the path which should be displayed
  393. */
  394. function get_titles_of_path($path) {
  395. global $tmp_folders_titles;
  396. $nb_slashes = substr_count($path, '/');
  397. $tmp_path = '';
  398. $current_slash_pos = 0;
  399. $path_displayed = '';
  400. for ($i = 0; $i < $nb_slashes; $i++) {
  401. // For each folder of the path, retrieve title.
  402. $current_slash_pos = strpos($path, '/', $current_slash_pos + 1);
  403. $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos);
  404. if (empty($tmp_path)) {
  405. // If empty, then we are in the final part of the path
  406. $tmp_path = $path;
  407. }
  408. if (!empty($tmp_folders_titles[$tmp_path])) {
  409. // If this path has soon been stored here we don't need a new query
  410. $path_displayed .= $tmp_folders_titles[$tmp_path];
  411. } else {
  412. $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE path LIKE BINARY "'.$tmp_path.'"';
  413. $rs = Database::query($sql);
  414. $tmp_title = '/'.Database::result($rs, 0, 0);
  415. $path_displayed .= $tmp_title;
  416. $tmp_folders_titles[$tmp_path] = $tmp_title;
  417. }
  418. }
  419. return $path_displayed;
  420. }
  421. /**
  422. * This function displays the name of the user and makes the link tothe user tool.
  423. *
  424. * @param $user_id
  425. * @param $name
  426. * @return a link to the userInfo.php
  427. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  428. * @version february 2006, dokeos 1.8
  429. */
  430. function display_user_link_document($user_id, $name) {
  431. if ($user_id != 0) {
  432. return '<a href="../user/userInfo.php?uInfo='.$user_id.'">'.$name.'</a>';
  433. } else {
  434. return get_lang('Anonymous');
  435. }
  436. }
  437. /**
  438. * Creates form that asks for the directory name.
  439. * @return string html-output text for the form
  440. */
  441. function create_dir_form() {
  442. $new_folder_text = '<form action="'.api_get_self().'" method="post">';
  443. $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.Security::remove_XSS($_GET['curdirpath']).'" />';
  444. // Form title
  445. $new_folder_text .= '<div class="row"><div class="form_header">'.get_lang('CreateDir').'</div></div>';
  446. // Folder field
  447. $new_folder_text .= '<div class="row">';
  448. $new_folder_text .= '<div class="label"><span class="form_required">*</span>'.get_lang('NewDir').'</div>';
  449. $new_folder_text .= '<div class="formw"><input type="text" name="dirname" /></div>';
  450. $new_folder_text .= '</div>';
  451. // Submit button
  452. $new_folder_text .= '<div class="row">';
  453. $new_folder_text .= '<div class="label">&nbsp;</div>';
  454. $new_folder_text .= '<div class="formw"><button type="submit" class="add" name="create_dir">'.get_lang('CreateFolder').'</button></div>';
  455. $new_folder_text .= '</div>';
  456. $new_folder_text .= '</form>';
  457. $new_folder_text .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  458. return $new_folder_text;
  459. }
  460. /**
  461. * Checks whether the user is in shared folder
  462. * @return return bool Return true when user is into shared folder
  463. */
  464. function is_shared_folder($curdirpath, $current_session_id) {
  465. $clean_curdirpath = Security::remove_XSS($curdirpath);
  466. if($clean_curdirpath== '/shared_folder'){
  467. return true;
  468. }
  469. elseif($clean_curdirpath== '/shared_folder_session_'.$current_session_id){
  470. return true;
  471. }
  472. else{
  473. return false;
  474. }
  475. }
  476. /**
  477. * Checks whether the user is into any user shared folder
  478. * @return return bool Return true when user is in any user shared folder
  479. */
  480. function is_any_user_shared_folder($path, $current_session_id) {
  481. $clean_path = Security::remove_XSS($path);
  482. if(strpos($clean_path,'shared_folder/sf_user_')){
  483. return true;
  484. }
  485. elseif(strpos($clean_path, 'shared_folder_session_'.$current_session_id.'/sf_user_')){
  486. return true;
  487. }
  488. else{
  489. return false;
  490. }
  491. }
  492. /**
  493. * Checks whether the user is into his shared folder
  494. * @return return bool Return true when user is in his user shared folder
  495. */
  496. function is_my_shared_folder($user_id, $path, $current_session_id) {
  497. $clean_path = Security::remove_XSS($path);
  498. if($clean_path == '/shared_folder/sf_user_'.$user_id){
  499. return true;
  500. }
  501. elseif($clean_path == '/shared_folder_session_'.$current_session_id.'/sf_user_'.$user_id){
  502. return true;
  503. }
  504. else{
  505. return false;
  506. }
  507. }
  508. /**
  509. * Check if the file name or folder searched exist
  510. * @return return bool Return true when exist
  511. */
  512. function search_keyword($document_name, $keyword) {
  513. if (api_strripos($document_name, $keyword) !== false){
  514. return true;
  515. } else {
  516. return false;
  517. }
  518. }
  519. ?>