document.inc.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * EXTRA FUNCTIONS FOR DOCUMENTS TOOL
  5. * @package chamilo.document
  6. */
  7. /**
  8. * Builds the form thats enables the user to
  9. * select a directory to browse/upload in
  10. *
  11. * @param array An array containing the folders we want to be able to select
  12. * @param string The current folder (path inside of the "document" directory, including the prefix "/")
  13. * @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root)
  14. * @param boolean Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form)
  15. * @todo this funcionality is really bad : jmontoya
  16. * @return string html form
  17. */
  18. function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false) {
  19. $doc_table = Database::get_course_table(TABLE_DOCUMENT);
  20. $course_id = api_get_course_int_id();
  21. $folder_titles = array();
  22. if (is_array($folders)) {
  23. $escaped_folders = array();
  24. foreach ($folders as $key => & $val) {
  25. $escaped_folders[$key] = Database::escape_string($val);
  26. }
  27. $folder_sql = implode("','", $escaped_folders);
  28. $sql = "SELECT * FROM $doc_table WHERE filetype = 'folder' AND c_id = $course_id AND path IN ('".$folder_sql."')";
  29. $res = Database::query($sql);
  30. $folder_titles = array();
  31. while ($obj = Database::fetch_object($res)) {
  32. $folder_titles[$obj->path] = $obj->title;
  33. }
  34. }
  35. $form = new FormValidator('selector', 'GET', api_get_self().'?'.api_get_cidreq());
  36. $form->addElement('hidden', 'cidReq', api_get_course_id());
  37. $parent_select = $form->addElement('select', 'id', get_lang('CurrentDirectory'), '', 'onchange="javascript: document.selector.submit();"');
  38. if ($change_renderer) {
  39. $renderer = $form->defaultRenderer();
  40. $renderer->setElementTemplate('<span>{label} : {element}</span> ','curdirpath');
  41. }
  42. // Group documents cannot be uploaded in the root
  43. if (empty($group_dir)) {
  44. $parent_select -> addOption(get_lang('Documents'), '/');
  45. if (is_array($folders)) {
  46. foreach ($folders as $folder_id => & $folder) {
  47. $selected = ($document_id == $folder_id) ? ' selected="selected"' : '';
  48. $path_parts = explode('/', $folder);
  49. $folder_titles[$folder] = cut($folder_titles[$folder], 80);
  50. $counter = count($path_parts) - 2;
  51. if ($counter > 0) {
  52. $label = str_repeat('&nbsp;&nbsp;&nbsp;', $counter).' &mdash; '.$folder_titles[$folder];
  53. } else {
  54. $label = ' &mdash; '.$folder_titles[$folder];
  55. }
  56. $parent_select -> addOption($label, $folder_id);
  57. if ($selected != '') {
  58. $parent_select->setSelected($folder_id);
  59. }
  60. }
  61. }
  62. } else {
  63. if (!empty($folders)) {
  64. foreach ($folders as $folder_id => & $folder) {
  65. $selected = ($document_id == $folder_id) ? ' selected="selected"' : '';
  66. $label = $folder_titles[$folder];
  67. if ($folder == $group_dir) {
  68. $label = get_lang('Documents');
  69. } else {
  70. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  71. $label = cut($label, 80);
  72. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  73. }
  74. $parent_select -> addOption($label, $folder_id);
  75. if ($selected != '') {
  76. $parent_select->setSelected($folder_id);
  77. }
  78. }
  79. }
  80. }
  81. $html = $form->toHtml();
  82. return $html;
  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($document_data, $show_as_icon = false, $counter = null, $visibility) {
  96. global $dbl_click_id;
  97. if (isset($_SESSION['_gid'])) {
  98. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  99. } else {
  100. $req_gid = '';
  101. }
  102. $course_info = api_get_course_info();
  103. $www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
  104. // Get the title or the basename depending on what we're using
  105. if ($document_data['title'] != '') {
  106. $title = $document_data['title'];
  107. } else {
  108. $title = basename($document_data['path']);
  109. }
  110. $filetype = $document_data['filetype'];
  111. $size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
  112. $path = $document_data['path'];
  113. $url_path = urlencode($document_data['path']);
  114. // Add class="invisible" on invisible files
  115. $visibility_class = ($visibility == false) ? ' class="muted"' : '';
  116. if (!$show_as_icon) {
  117. // Build download link (icon)
  118. $forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&id='.$document_data['id'] : api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$document_data['id'];
  119. // Folder download or file download?
  120. $forcedownload_icon = ($filetype == 'folder') ? 'save_pack.png' : 'save.png';
  121. // Prevent multiple clicks on zipped folder download
  122. $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; }\"":'';
  123. }
  124. $target = '_self';
  125. $is_browser_viewable_file = false;
  126. if ($filetype == 'file') {
  127. // Check the extension
  128. $ext = explode('.', $path);
  129. $ext = strtolower($ext[sizeof($ext) - 1]);
  130. // HTML-files an some other types are shown in a frameset by default.
  131. $is_browser_viewable_file = is_browser_viewable($ext);
  132. if ($is_browser_viewable_file) {
  133. //$url = 'showinframes.php?'.api_get_cidreq().'&amp;file='.$url_path.$req_gid;
  134. $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  135. } else {
  136. // url-encode for problematic characters (we may not call them dangerous characters...)
  137. $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
  138. //$new_path = '?id='.$document_data['id'];
  139. $url = $www.$path;
  140. }
  141. //$path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
  142. $path = str_replace('%2F', '/',$url_path); //yox view hack otherwise the image can't be well read
  143. $url = $www.$path;
  144. // Disabled fragment of code, there is a special icon for opening in a new window.
  145. //// Files that we want opened in a new window
  146. //if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here
  147. // $target = '_blank';
  148. //}
  149. } else {
  150. //$url = api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$url_path.$req_gid;
  151. $url = api_get_self().'?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  152. }
  153. // The little download icon
  154. //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'], '', basename($path));
  155. $tooltip_title = explode('?', basename($path));
  156. $tooltip_title = $title;
  157. //Cut long titles
  158. //$title = cut($title, 120);
  159. $tooltip_title_alt = $tooltip_title;
  160. if ($path == '/shared_folder') {
  161. $tooltip_title_alt = get_lang('UserFolders');
  162. } elseif(strstr($path, 'shared_folder_session_')) {
  163. $tooltip_title_alt = get_lang('UserFolders').' ('.api_get_session_name(api_get_session_id()).')';
  164. } elseif(strstr($tooltip_title, 'sf_user_')) {
  165. $userinfo = Database::get_user_info_from_id(substr($tooltip_title, 8));
  166. $tooltip_title_alt = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  167. } elseif($path == '/chat_files') {
  168. $tooltip_title_alt = get_lang('ChatFiles');
  169. } elseif($path == '/learning_path') {
  170. $tooltip_title_alt = get_lang('LearningPaths');
  171. } elseif($path == '/video') {
  172. $tooltip_title_alt = get_lang('Video');
  173. } elseif($path == '/audio') {
  174. $tooltip_title_alt = get_lang('Audio');
  175. } elseif($path == '/flash') {
  176. $tooltip_title_alt = get_lang('Flash');
  177. } elseif($path == '/images') {
  178. $tooltip_title_alt = get_lang('Images');
  179. } elseif($path == '/images/gallery') {
  180. $tooltip_title_alt = get_lang('DefaultCourseImages');
  181. }
  182. $current_session_id = api_get_session_id();
  183. $copy_to_myfiles = $open_in_new_window_link = null;
  184. $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
  185. if (!$show_as_icon) {
  186. if ($filetype == 'folder') {
  187. if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
  188. //filter when I am into shared folder, I can show for donwload only my shared folder
  189. if (is_shared_folder($curdirpath, $current_session_id)) {
  190. 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()) {
  191. $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),ICON_SIZE_SMALL).'</a>';
  192. }
  193. } elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) {
  194. $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),ICON_SIZE_SMALL).'</a>';
  195. }
  196. }
  197. } else {
  198. $force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),ICON_SIZE_SMALL).'</a>';
  199. }
  200. //Copy files to users myfiles
  201. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('users_copy_files') == 'true' && !api_is_anonymous()){
  202. $copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&action=copytomyfiles&id='.$document_data['id'].$req_gid :api_get_self().'?'.api_get_cidreq();
  203. if ($filetype == 'file') {
  204. $copy_to_myfiles = '<a href="'.$copy_myfiles_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon('briefcase.png', get_lang('CopyToMyFiles'), array(),ICON_SIZE_SMALL).'&nbsp;&nbsp;</a>';
  205. }
  206. $send_to = '';
  207. if ($filetype == 'file') {
  208. $send_to = Portfolio::share('document', $document_data['id'], array('style' => 'float:right;'));
  209. }
  210. }
  211. $pdf_icon = '';
  212. $extension = pathinfo($path, PATHINFO_EXTENSION);
  213. if (!api_is_allowed_to_edit() && api_get_setting('students_export2pdf') == 'true' && $filetype == 'file' && in_array($extension, array('html','htm'))) {
  214. $pdf_icon = ' <a style="float:right".'.$prevent_multiple_click.' href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$document_data['id'].'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), ICON_SIZE_SMALL).'</a> ';
  215. }
  216. if ($is_browser_viewable_file) {
  217. $open_in_new_window_link = '<a href="'.$www.str_replace('%2F', '/',$url_path).'?'.api_get_cidreq().'" style="float:right"'.$prevent_multiple_click.' target="_blank">'.Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), array(),ICON_SIZE_SMALL).'&nbsp;&nbsp;</a>';
  218. }
  219. //target="'.$target.'"
  220. if ($filetype == 'file') {
  221. //Sound preview with jplayer
  222. if ( preg_match('/mp3$/i', urldecode($url)) ||
  223. (preg_match('/wav$/i', urldecode($url)) && !preg_match('/_chnano_.wav$/i', urldecode($url))) ||
  224. preg_match('/ogg$/i', urldecode($url))) {
  225. return '<span style="float:left" '.$visibility_class.'>'.$title.'</span>'.$force_download_html.$send_to.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  226. } elseif (
  227. //Show preview sith yoxview
  228. //preg_match('/html$/i', urldecode($url)) ||
  229. //preg_match('/htm$/i', urldecode($url)) ||
  230. preg_match('/swf$/i', urldecode($url)) ||
  231. preg_match('/png$/i', urldecode($url)) ||
  232. preg_match('/gif$/i', urldecode($url)) ||
  233. preg_match('/jpg$/i', urldecode($url)) ||
  234. preg_match('/jpeg$/i', urldecode($url)) ||
  235. preg_match('/bmp$/i', urldecode($url)) ||
  236. preg_match('/svg$/i', urldecode($url)) ||
  237. (preg_match('/wav$/i', urldecode($url)) && preg_match('/_chnano_.wav$/i', urldecode($url)) && api_get_setting('enable_nanogong') == 'true')
  238. ) {
  239. //yox view
  240. //$url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  241. //Simpler version of showinframesmin.php with no headers
  242. $url = 'show_content.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid.'&width=700&height=500';
  243. $class = 'ajax';
  244. if ($visibility == false) {
  245. $class = "ajax invisible";
  246. }
  247. return '<a href="'.$url.'" class="'.$class.'" title="'.$tooltip_title_alt.'" style="float:left">'.$title.'</a>'.$force_download_html.$send_to.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  248. } else {
  249. $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  250. //No plugin just the old and good showinframes.php page
  251. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" style="float:left" '.$visibility_class.' >'.$title.'</a>'.$force_download_html.$send_to.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  252. }
  253. } else {
  254. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html.$send_to.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  255. }
  256. //end copy files to users myfiles
  257. } else {
  258. //Icon column
  259. 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){
  260. if ($filetype == 'file') {
  261. //Sound preview with jplayer
  262. if ( preg_match('/mp3$/i', urldecode($url)) ||
  263. (preg_match('/wav$/i', urldecode($url)) && !preg_match('/_chnano_.wav$/i', urldecode($url))) ||
  264. preg_match('/ogg$/i', urldecode($url))) {
  265. $sound_preview = DocumentManager::generate_media_preview($counter);
  266. return $sound_preview ;
  267. } elseif (
  268. //Show preview sith yoxview
  269. //preg_match('/html$/i', urldecode($url)) ||
  270. //preg_match('/htm$/i', urldecode($url)) ||
  271. preg_match('/swf$/i', urldecode($url)) ||
  272. preg_match('/png$/i', urldecode($url)) ||
  273. preg_match('/gif$/i', urldecode($url)) ||
  274. preg_match('/jpg$/i', urldecode($url)) ||
  275. preg_match('/jpeg$/i', urldecode($url)) ||
  276. preg_match('/bmp$/i', urldecode($url)) ||
  277. preg_match('/svg$/i', urldecode($url)) ||
  278. (preg_match('/wav$/i', urldecode($url)) && preg_match('/_chnano_.wav$/i', urldecode($url))&& api_get_setting('enable_nanogong') == 'true')
  279. ) {
  280. //$url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;//with yoxview
  281. $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;//without yoxview
  282. //return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array()).'</a>';//with yoxview
  283. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array()).'</a>';//without yoxview
  284. } else {
  285. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array()).'</a>';
  286. }
  287. } else {
  288. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array()).'</a>';
  289. }
  290. } else {
  291. if ($filetype == 'file') {
  292. //Sound preview with jplayer
  293. if ( preg_match('/mp3$/i', urldecode($url)) ||
  294. (preg_match('/wav$/i', urldecode($url)) && !preg_match('/_chnano_.wav$/i', urldecode($url))) ||
  295. preg_match('/ogg$/i', urldecode($url))) {
  296. $sound_preview = DocumentManager::generate_media_preview($counter);
  297. return $sound_preview ;
  298. } elseif (
  299. //Show preview sith yoxview
  300. preg_match('/html$/i', urldecode($url)) ||
  301. preg_match('/htm$/i', urldecode($url)) ||
  302. preg_match('/swf$/i', urldecode($url)) ||
  303. preg_match('/png$/i', urldecode($url)) ||
  304. preg_match('/gif$/i', urldecode($url)) ||
  305. preg_match('/jpg$/i', urldecode($url)) ||
  306. preg_match('/jpeg$/i', urldecode($url)) ||
  307. preg_match('/bmp$/i', urldecode($url)) ||
  308. preg_match('/svg$/i', urldecode($url)) ||
  309. (preg_match('/wav$/i', urldecode($url)) && preg_match('/_chnano_.wav$/i', urldecode($url)) && api_get_setting('enable_nanogong') == 'true')
  310. ) {
  311. //$url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;//with yoxview
  312. $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;//without yoxview
  313. //return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';//with yoxview
  314. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';//without yoxview
  315. } else {
  316. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
  317. }
  318. } else {
  319. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
  320. }
  321. }
  322. }
  323. }
  324. /**
  325. * Builds an img html tag for the filetype
  326. *
  327. * @param string $type (file/folder)
  328. * @param string $path
  329. * @return string img html tag
  330. */
  331. function build_document_icon_tag($type, $path) {
  332. $basename = basename($path);
  333. $current_session_id = api_get_session_id();
  334. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  335. if ($type == 'file') {
  336. $icon = choose_image($basename);
  337. if(preg_match('/_chnano_.wav$/i', $basename)) {
  338. $icon="jplayer_play.png";
  339. $basename = 'wav'.' '.'(Nanogong)';
  340. }else{
  341. $basename=substr(strrchr($basename, '.'), 1);
  342. }
  343. } else {
  344. if ($path == '/shared_folder') {
  345. $icon = 'folder_users.gif';
  346. if ($is_allowed_to_edit) {
  347. $basename = get_lang('HelpUsersFolder');
  348. } else {
  349. $basename = get_lang('UserFolders');
  350. }
  351. }elseif(strstr($basename, 'sf_user_')) {
  352. $userinfo = Database::get_user_info_from_id(substr($basename, 8));
  353. $image_path = UserManager::get_user_picture_path_by_id(substr($basename, 8), 'web', false, true);
  354. if ($image_path['file'] == 'unknown.jpg') {
  355. $icon = $image_path['file'];
  356. } else {
  357. $icon = '../upload/users/'.substr($basename, 8).'/'.$image_path['file'];
  358. }
  359. $basename = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);}elseif(strstr($path, 'shared_folder_session_')) {
  360. if ($is_allowed_to_edit) {
  361. $basename = '***('.api_get_session_name($current_session_id).')*** '.get_lang('HelpUsersFolder');
  362. } else {
  363. $basename = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')';
  364. }
  365. $icon = 'folder_users.gif';
  366. } else {
  367. $icon = 'folder_document.gif';
  368. if($path=='/audio'){
  369. $icon = 'folder_audio.gif';
  370. if(api_is_allowed_to_edit()){
  371. $basename=get_lang('HelpDefaultDirDocuments');
  372. }
  373. else{
  374. $basename=get_lang('Audio');
  375. }
  376. }
  377. elseif($path =='/flash'){
  378. $icon = 'folder_flash.gif';
  379. if(api_is_allowed_to_edit()){
  380. $basename=get_lang('HelpDefaultDirDocuments');
  381. }
  382. else{
  383. $basename=get_lang('Flash');
  384. }
  385. }
  386. elseif($path =='/images'){
  387. $icon = 'folder_images.gif';
  388. if(api_is_allowed_to_edit()){
  389. $basename=get_lang('HelpDefaultDirDocuments');
  390. }
  391. else{
  392. $basename=get_lang('Images');
  393. }
  394. }
  395. elseif($path =='/video'){
  396. $icon = 'folder_video.gif';
  397. if(api_is_allowed_to_edit()){
  398. $basename=get_lang('HelpDefaultDirDocuments');
  399. }
  400. else{
  401. $basename=get_lang('Video');
  402. }
  403. }
  404. elseif($path =='/images/gallery'){
  405. $icon = 'folder_gallery.gif';
  406. if(api_is_allowed_to_edit()){
  407. $basename=get_lang('HelpDefaultDirDocuments');
  408. }
  409. else{
  410. $basename=get_lang('Gallery');
  411. }
  412. }
  413. elseif($path =='/chat_files'){
  414. $icon = 'folder_chat.gif';
  415. if(api_is_allowed_to_edit()){
  416. $basename=get_lang('HelpFolderChat');
  417. }
  418. else{
  419. $basename=get_lang('ChatFiles');
  420. }
  421. }
  422. elseif($path == '/learning_path') {
  423. $icon = 'folder_learningpath.gif';
  424. if(api_is_allowed_to_edit()){
  425. $basename= get_lang('HelpFolderLearningPaths');
  426. }
  427. else{
  428. $basename= get_lang('LearningPaths');
  429. }
  430. }
  431. }
  432. }
  433. return Display::return_icon($icon, $basename, array());
  434. }
  435. /**
  436. * Creates the row of edit icons for a file/folder
  437. *
  438. * @param string $curdirpath current path (cfr open folder)
  439. * @param string $type (file/folder)
  440. * @param string $path dbase path of file/folder
  441. * @param int $visibility (1/0)
  442. * @param int $id dbase id of the document
  443. * @return string html img tags with hyperlinks
  444. */
  445. function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0, $visibility) {
  446. if (isset($_SESSION['_gid'])) {
  447. $req_gid = '&gidReq='.$_SESSION['_gid'];
  448. } else {
  449. $req_gid = '';
  450. }
  451. $document_id = $document_data['id'];
  452. $type = $document_data['filetype'];
  453. $is_read_only = $document_data['readonly'];
  454. $path = $document_data['path'];
  455. $parent_id = DocumentManager::get_document_id(api_get_course_info(), dirname($path));
  456. $curdirpath = dirname($document_data['path']);
  457. $is_certificate_mode = DocumentManager::is_certificate_mode($path);
  458. $curdirpath = urlencode($curdirpath);
  459. $extension = pathinfo($path, PATHINFO_EXTENSION);
  460. // Build URL-parameters for table-sorting
  461. $sort_params = array();
  462. if (isset($_GET['column'])) {
  463. $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
  464. }
  465. if (isset($_GET['page_nr'])) {
  466. $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
  467. }
  468. if (isset($_GET['per_page'])) {
  469. $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
  470. }
  471. if (isset($_GET['direction'])) {
  472. $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
  473. }
  474. $sort_params = implode('&amp;', $sort_params);
  475. $visibility_icon = ($visibility == 0) ? 'invisible' : 'visible';
  476. $visibility_command = ($visibility == 0) ? 'set_visible' : 'set_invisible';
  477. $modify_icons = '';
  478. // If document is read only *or* we're in a session and the document
  479. // is from a non-session context, hide the edition capabilities
  480. if ($is_read_only /*or ($session_id!=api_get_session_id())*/) {
  481. if (api_is_course_admin() || api_is_platform_admin()) {
  482. if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
  483. $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  484. } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
  485. $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  486. } else {
  487. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  488. }
  489. } else {
  490. $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'),'',ICON_SIZE_SMALL);
  491. }
  492. $modify_icons .= '&nbsp;'.Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL);
  493. if (api_is_allowed_to_edit() || api_is_platform_admin()) {
  494. $modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),'',ICON_SIZE_SMALL);
  495. }
  496. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'),array(), ICON_SIZE_SMALL);
  497. } else {
  498. if ($is_certificate_mode) {
  499. // gradebook category doesn't seem to be taken into account
  500. //$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'&curdirpath=/certificates&selectcat='.$gradebook_category.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  501. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'&curdirpath=/certificates">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  502. } else {
  503. if (api_get_session_id()) {
  504. if ($document_data['session_id'] == api_get_session_id()) {
  505. if ($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
  506. $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  507. } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
  508. $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  509. } else {
  510. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  511. }
  512. } else {
  513. $modify_icons .= '&nbsp;'.Display::return_icon('edit_na.png', get_lang('Edit'),array(), ICON_SIZE_SMALL).'</a>';
  514. }
  515. } else {
  516. if ($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
  517. $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  518. } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
  519. $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  520. } else {
  521. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'</a>';
  522. }
  523. }
  524. }
  525. if ($is_certificate_mode) {
  526. //$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&amp;move='.$document_id.$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
  527. $modify_icons .= '&nbsp;'.Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
  528. $modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),array(), ICON_SIZE_SMALL).'</a>';
  529. Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),array(), ICON_SIZE_SMALL).'</a>';
  530. } else {
  531. if (api_get_session_id()) {
  532. if ($document_data['session_id'] == api_get_session_id()) {
  533. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'&amp;move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
  534. } else {
  535. $modify_icons .= '&nbsp;'.Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
  536. }
  537. } else {
  538. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'&amp;move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
  539. }
  540. if (api_is_allowed_to_edit() || api_is_platform_admin()) {
  541. if ($visibility_icon=='invisible'){
  542. $tip_visibility=get_lang('Show');
  543. }else{
  544. $tip_visibility=get_lang('Hide');
  545. }
  546. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon($visibility_icon.'.png', $tip_visibility,'',ICON_SIZE_SMALL).'</a>';
  547. }
  548. }
  549. if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
  550. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'),array(), ICON_SIZE_SMALL);
  551. } else {
  552. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  553. //$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).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), ICON_SIZE_SMALL).'</a>';
  554. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'delete_certificate_id='.$id.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), ICON_SIZE_SMALL).'</a>';
  555. } else {
  556. if ($is_certificate_mode) {
  557. //$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).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), ICON_SIZE_SMALL).'</a>';
  558. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), ICON_SIZE_SMALL).'</a>';
  559. } else {
  560. if (api_get_session_id()) {
  561. if ($document_data['session_id'] == api_get_session_id()) {
  562. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), ICON_SIZE_SMALL).'</a>';
  563. } else {
  564. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'),array(), ICON_SIZE_SMALL);
  565. }
  566. } else {
  567. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), ICON_SIZE_SMALL).'</a>';
  568. }
  569. }
  570. }
  571. }
  572. }
  573. if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) {
  574. if ($is_template == 0) {
  575. if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) {
  576. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;add_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon('wizard.png', get_lang('AddAsTemplate'),array(), ICON_SIZE_SMALL).'</a>';
  577. }
  578. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course
  579. $visibility_icon_certificate='nocertificate';
  580. if (DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  581. $visibility_icon_certificate='certificate';
  582. $certificate=get_lang('DefaultCertificate');
  583. $preview=get_lang('PreviewCertificate');
  584. $is_preview=true;
  585. } else {
  586. $is_preview=false;
  587. $certificate=get_lang('NoDefaultCertificate');
  588. }
  589. if (isset($_GET['selectcat'])) {
  590. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;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>';
  591. if ($is_preview) {
  592. $modify_icons .= '&nbsp;<a target="_blank" href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;set_preview='.$id.$req_gid.'&amp;'.$sort_params.'" >'.
  593. Display::return_icon('preview_view.png', $preview,'',ICON_SIZE_SMALL).'</a>';
  594. }
  595. }
  596. }
  597. } else {
  598. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;remove_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.
  599. Display::return_icon('wizard_na.png', get_lang('RemoveAsTemplate'),'',ICON_SIZE_SMALL).'</a>';
  600. }
  601. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$id.'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), ICON_SIZE_SMALL).'</a>';
  602. }
  603. return $modify_icons;
  604. }
  605. function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
  606. $form = new FormValidator('move_to', 'post', api_get_self());
  607. // Form title
  608. $form->addElement('hidden', 'move_file', $move_file);
  609. $options = array();
  610. // Group documents cannot be uploaded in the root
  611. if ($group_dir == '') {
  612. if ($curdirpath != '/') {
  613. $options['/'] = get_lang('Documents');
  614. }
  615. if (is_array($folders)) {
  616. foreach ($folders as & $folder) {
  617. //Hide some folders
  618. if($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css'){
  619. continue;
  620. }
  621. //Admin setting for Hide/Show the folders of all users
  622. if(api_get_setting('show_users_folders') == 'false' && (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))){
  623. continue;
  624. }
  625. //Admin setting for Hide/Show Default folders to all users
  626. if(api_get_setting('show_default_folders') == 'false' && ($folder=='/images' || $folder=='/flash' || $folder=='/audio' || $folder=='/video' || strstr($folder, '/images/gallery') || $folder=='/video/flv')){
  627. continue;
  628. }
  629. //Admin setting for Hide/Show chat history folder
  630. if(api_get_setting('show_chat_folder') == 'false' && $folder=='/chat_files'){
  631. continue;
  632. }
  633. // You cannot move a file to:
  634. // 1. current directory
  635. // 2. inside the folder you want to move
  636. // 3. inside a subfolder of the folder you want to move
  637. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  638. $path_displayed = $folder;
  639. // If document title is used, we have to display titles instead of real paths...
  640. $path_displayed = get_titles_of_path($folder);
  641. if (empty($path_displayed)) {
  642. $path_displayed = get_lang('Untitled');
  643. }
  644. $options[$folder] = $path_displayed;
  645. //$form .= '<option value="'.$folder.'">'.$path_displayed.'</option>';
  646. }
  647. }
  648. }
  649. } else {
  650. foreach ($folders as $folder) {
  651. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) { // Cannot copy dir into his own subdir
  652. $path_displayed = get_titles_of_path($folder);
  653. $display_folder = substr($path_displayed,strlen($group_dir));
  654. $display_folder = ($display_folder == '') ? get_lang('Documents') : $display_folder;
  655. //$form .= '<option value="'.$folder.'">'.$display_folder.'</option>';
  656. $options[$folder] = $display_folder;
  657. }
  658. }
  659. }
  660. $form->addElement('select', 'move_to', get_lang('MoveTo'), $options);
  661. $form->addElement('button', 'move_file_submit', get_lang('MoveElement'));
  662. return $form->return_form();
  663. }
  664. /**
  665. * Gets the path translated with title of docs and folders
  666. * @param string the real path
  667. * @return the path which should be displayed
  668. */
  669. function get_titles_of_path($path) {
  670. global $tmp_folders_titles;
  671. $course_id = api_get_course_int_id();
  672. $nb_slashes = substr_count($path, '/');
  673. $tmp_path = '';
  674. $current_slash_pos = 0;
  675. $path_displayed = '';
  676. for ($i = 0; $i < $nb_slashes; $i++) {
  677. // For each folder of the path, retrieve title.
  678. $current_slash_pos = strpos($path, '/', $current_slash_pos + 1);
  679. $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos);
  680. if (empty($tmp_path)) {
  681. // If empty, then we are in the final part of the path
  682. $tmp_path = $path;
  683. }
  684. if (!empty($tmp_folders_titles[$tmp_path])) {
  685. // If this path has soon been stored here we don't need a new query
  686. $path_displayed .= $tmp_folders_titles[$tmp_path];
  687. } else {
  688. $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).'
  689. WHERE c_id = '.$course_id.' AND path LIKE BINARY "'.$tmp_path.'"';
  690. $rs = Database::query($sql);
  691. $tmp_title = '/'.Database::result($rs, 0, 0);
  692. $path_displayed .= $tmp_title;
  693. $tmp_folders_titles[$tmp_path] = $tmp_title;
  694. }
  695. }
  696. return $path_displayed;
  697. }
  698. /**
  699. * This function displays the name of the user and makes the link tothe user tool.
  700. *
  701. * @param $user_id
  702. * @param $name
  703. * @return a link to the userInfo.php
  704. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  705. * @version february 2006, dokeos 1.8
  706. */
  707. function display_user_link_document($user_id, $name) {
  708. if ($user_id != 0) {
  709. return '<a href="../user/userInfo.php?uInfo='.$user_id.'">'.$name.'</a>';
  710. } else {
  711. return get_lang('Anonymous');
  712. }
  713. }
  714. /**
  715. * Creates form that asks for the directory name.
  716. * @return string html-output text for the form
  717. */
  718. function create_dir_form($current_dir_id) {
  719. global $document_id;
  720. $form = new FormValidator('create_dir_form', 'post', '', '', null, false);
  721. $form->addElement('hidden', 'create_dir', 1);
  722. $form->addElement('hidden', 'dir_id', intval($document_id));
  723. $form->addElement('hidden', 'id', intval($current_dir_id));
  724. $form->addElement('header', '', get_lang('CreateDir'));
  725. $form->addElement('text', 'dirname', get_lang('NewDir'));
  726. $form->addElement('style_submit_button', 'submit', get_lang('CreateFolder'), 'class="add"');
  727. $new_folder_text = $form->return_form();
  728. return $new_folder_text;
  729. }
  730. /**
  731. * Checks whether the user is in shared folder
  732. * @return return bool Return true when user is into shared folder
  733. */
  734. function is_shared_folder($curdirpath, $current_session_id) {
  735. $clean_curdirpath = Security::remove_XSS($curdirpath);
  736. if($clean_curdirpath== '/shared_folder'){
  737. return true;
  738. }
  739. elseif($clean_curdirpath== '/shared_folder_session_'.$current_session_id){
  740. return true;
  741. }
  742. else{
  743. return false;
  744. }
  745. }
  746. /**
  747. * Checks whether the user is into any user shared folder
  748. * @return return bool Return true when user is in any user shared folder
  749. */
  750. function is_any_user_shared_folder($path, $current_session_id) {
  751. $clean_path = Security::remove_XSS($path);
  752. if(strpos($clean_path,'shared_folder/sf_user_')){
  753. return true;
  754. }
  755. elseif(strpos($clean_path, 'shared_folder_session_'.$current_session_id.'/sf_user_')){
  756. return true;
  757. }
  758. else{
  759. return false;
  760. }
  761. }
  762. /**
  763. * Checks whether the user is into his shared folder or into a subfolder
  764. * @return return bool Return true when user is in his user shared folder or into a subforder
  765. */
  766. function is_my_shared_folder($user_id, $path, $current_session_id) {
  767. $clean_path = Security::remove_XSS($path).'/';
  768. $main_user_shared_folder = '/shared_folder\/sf_user_'.$user_id.'\//';//for security does not remove the last slash
  769. $main_user_shared_folder_session='/shared_folder_session_'.$current_session_id.'\/sf_user_'.$user_id.'\//';//for security does not remove the last slash
  770. if (preg_match($main_user_shared_folder, $clean_path)){
  771. return true;
  772. } elseif(preg_match($main_user_shared_folder_session, $clean_path)) {
  773. return true;
  774. } else {
  775. return false;
  776. }
  777. }
  778. /**
  779. * Check if the file name or folder searched exist
  780. * @return return bool Return true when exist
  781. */
  782. function search_keyword($document_name, $keyword) {
  783. if (api_strripos($document_name, $keyword) !== false){
  784. return true;
  785. } else {
  786. return false;
  787. }
  788. }
  789. /**
  790. * Checks whether a document can be previewed by using the browser.
  791. * @param string $file_extension The filename extension of the document (it must be in lower case).
  792. * @return bool Returns TRUE or FALSE.
  793. */
  794. function is_browser_viewable($file_extension) {
  795. static $allowed_extensions = array(
  796. 'htm', 'html', 'xhtml',
  797. 'gif', 'jpg', 'jpeg', 'png', 'tif', 'tiff',
  798. 'pdf', 'svg', 'swf',
  799. 'txt', 'log',
  800. 'mp4', 'ogg', 'ogv', 'ogx', 'mpg', 'mpeg', 'mov', 'avi', 'webm', 'wmv',
  801. 'mp3', 'oga', 'wav', 'au', 'wma', 'mid', 'kar'
  802. );
  803. /*
  804. //TODO: make a admin swich to strict mode
  805. 1. global default $allowed_extensions only: 'htm', 'html', 'xhtml', 'gif', 'jpg', 'jpeg', 'png', 'bmp', 'txt', 'log'
  806. if (in_array($file_extension, $allowed_extensions)) { // Assignment + a logical check.
  807. return true;
  808. }
  809. 2. check native support
  810. 3. check plugins: quicktime, mediaplayer, vlc, acrobat, flash, java
  811. */
  812. if (!($result = in_array($file_extension, $allowed_extensions))) { // Assignment + a logical check.
  813. return false;
  814. }
  815. //check native support (Explorer, Opera, Firefox, Chrome, Safari)
  816. if ($file_extension=="pdf"){
  817. return api_browser_support('pdf');
  818. }
  819. elseif ($file_extension=="mp3"){
  820. return api_browser_support('mp3');
  821. }
  822. elseif ($file_extension=="mp4"){
  823. return api_browser_support('mp4');
  824. }
  825. elseif ($file_extension=="ogg" || $file_extension=="ogx" || $file_extension=="ogv" || $file_extension=="oga"){
  826. return api_browser_support('ogg');
  827. }
  828. elseif ($file_extension=="svg"){
  829. return api_browser_support('svg');
  830. }
  831. elseif ($file_extension=="mpg" || $file_extension=="mpeg"){
  832. return api_browser_support('mpg');
  833. }
  834. elseif ($file_extension=="mov"){
  835. return api_browser_support('mov');
  836. }
  837. elseif ($file_extension=="wav"){
  838. return api_browser_support('wav');
  839. }
  840. elseif ($file_extension=="mid" || $file_extension=="kar"){
  841. return api_browser_support('mid');
  842. }
  843. elseif ($file_extension=="avi"){
  844. return api_browser_support('avi');
  845. }
  846. elseif ($file_extension=="wma"){
  847. return api_browser_support('wma');
  848. }
  849. elseif ($file_extension=="wmv"){
  850. return api_browser_support('wmv');
  851. }
  852. elseif ($file_extension=="tif" || $file_extension=="tiff"){
  853. return api_browser_support('tif');
  854. }
  855. elseif ($file_extension=="mov"){
  856. return api_browser_support('mov');
  857. }
  858. elseif ($file_extension=="au"){
  859. return api_browser_support('au');
  860. }
  861. elseif ($file_extension=="webm"){
  862. return api_browser_support('webm');
  863. }
  864. return $result;
  865. }