document.inc.php 47 KB

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