document.inc.php 48 KB

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