edit_document.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows editing documents.
  5. *
  6. * Based on create_document, this file allows
  7. * - edit name
  8. * - edit comments
  9. * - edit metadata (requires a document table entry)
  10. * - edit html content (only for htm/html files)
  11. *
  12. * For all files
  13. * - show editable name field
  14. * - show editable comments field
  15. * Additionally, for html and text files
  16. * - show RTE
  17. *
  18. * Remember, all files and folders must always have an entry in the
  19. * database, regardless of wether they are visible/invisible, have
  20. * comments or not.
  21. *
  22. * @package chamilo.document
  23. * @todo improve script structure (FormValidator is used to display form, but
  24. * not for validation at the moment)
  25. */
  26. // Name of the language file that needs to be included
  27. $language_file = 'document';
  28. /* Included libraries */
  29. require_once '../inc/global.inc.php';
  30. // Template's javascript
  31. $htmlHeadXtra[] = '
  32. <script type="text/javascript">
  33. function InnerDialogLoaded()
  34. {
  35. /*
  36. var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
  37. return B.ClickFrame();
  38. */
  39. var isIE = (navigator.appVersion.indexOf(\'MSIE\') != -1) ? true : false ;
  40. var EditorFrame = null ;
  41. if ( !isIE )
  42. {
  43. EditorFrame = window.frames[0] ;
  44. }
  45. else
  46. {
  47. // For this dynamic page window.frames[0] enumerates frames in a different order in IE.
  48. // We need a sure method to locate the frame that contains the online editor.
  49. for ( var i = 0, n = window.frames.length ; i < n ; i++ )
  50. {
  51. if ( window.frames[i].location.toString().indexOf(\'InstanceName=content\') != -1 )
  52. {
  53. EditorFrame = window.frames[i] ;
  54. }
  55. }
  56. }
  57. if ( !EditorFrame )
  58. {
  59. return null ;
  60. }
  61. var B = new EditorFrame.FCKToolbarButton(\'Templates\', EditorFrame.FCKLang.Templates);
  62. return B.ClickFrame();
  63. };
  64. function FCKeditor_OnComplete( editorInstance )
  65. {
  66. document.getElementById(\'frmModel\').innerHTML = "<iframe style=\'height: 525px; width: 180px;\' scrolling=\'no\' frameborder=\'0\' src=\''.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/fckdialogframe.html \'>";
  67. }
  68. </script>';
  69. $_SESSION['whereami'] = 'document/create';
  70. $this_section = SECTION_COURSES;
  71. $lib_path = api_get_path(LIBRARY_PATH);
  72. require_once $lib_path.'fileManage.lib.php';
  73. require_once $lib_path.'fileUpload.lib.php';
  74. require_once $lib_path.'document.lib.php';
  75. require_once $lib_path.'groupmanager.lib.php';
  76. require_once $lib_path.'formvalidator/FormValidator.class.php';
  77. /* Constants & Variables */
  78. if (api_is_in_group()) {
  79. $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
  80. }
  81. $file = $_GET['file'];
  82. //echo('file: '.$file.'<br />');
  83. $doc = basename($file);
  84. //echo('doc: '.$doc.'<br />');
  85. $dir = Security::remove_XSS($_GET['curdirpath']);
  86. //I'm in the certification module?
  87. $is_certificate_mode = DocumentManager::is_certificate_mode($dir);
  88. //echo('dir: '.$dir.'<br />');
  89. $file_name = $doc;
  90. //echo('file_name: '.$file_name.'<br />');
  91. $baseServDir = api_get_path(SYS_COURSE_PATH);
  92. $baseServUrl = $_configuration['url_append'].'/';
  93. $courseDir = $_course['path'].'/document';
  94. $baseWorkDir = $baseServDir.$courseDir;
  95. $group_document = false;
  96. $current_session_id = api_get_session_id();
  97. $doc_tree = explode('/', $file);
  98. $count_dir = count($doc_tree) - 2; // "2" because at the begin and end there are 2 "/"
  99. // Level correction for group documents.
  100. if (!empty($group_properties['directory'])) {
  101. $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
  102. }
  103. $relative_url = '';
  104. for ($i = 0; $i < ($count_dir); $i++) {
  105. $relative_url .= '../';
  106. }
  107. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  108. $html_editor_config = array(
  109. 'ToolbarSet' => ($is_allowed_to_edit ? 'Documents' :'DocumentsStudent'),
  110. 'Width' => '100%',
  111. 'Height' => '600',
  112. 'FullPage' => true,
  113. 'InDocument' => true,
  114. 'CreateDocumentDir' => $relative_url,
  115. 'CreateDocumentWebDir' => (empty($group_properties['directory']))
  116. ? api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'
  117. : api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document'.$group_properties['directory'].'/',
  118. 'BaseHref' => api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir
  119. );
  120. $use_document_title = api_get_setting('use_document_title') == 'true';
  121. $noPHP_SELF = true;
  122. /* Other initialization code */
  123. /* Please, do not modify this dirname formatting */
  124. if (strstr($dir, '..')) {
  125. $dir = '/';
  126. }
  127. if ($dir[0] == '.') {
  128. $dir = substr($dir, 1);
  129. }
  130. if ($dir[0] != '/') {
  131. $dir = '/'.$dir;
  132. }
  133. if ($dir[strlen($dir) - 1] != '/') {
  134. $dir .= '/';
  135. }
  136. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$dir;
  137. if (!is_dir($filepath)) {
  138. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  139. $dir = '/';
  140. }
  141. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  142. if (!empty($_SESSION['_gid'])) {
  143. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  144. $interbreadcrumb[] = array ('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace'));
  145. $group_document = true;
  146. $noPHP_SELF = true;
  147. }
  148. $my_cur_dir_path = Security::remove_XSS($_GET['curdirpath']);
  149. if (!$is_certificate_mode)
  150. $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
  151. else
  152. $interbreadcrumb[]= array ( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  153. $is_allowedToEdit = is_allowed_to_edit() || $_SESSION['group_member_with_upload_rights'];
  154. if (!$is_allowedToEdit) {
  155. api_not_allowed(true);
  156. }
  157. $user_id = api_get_user_id();
  158. event_access_tool(TOOL_DOCUMENT);
  159. if (!is_allowed_to_edit()) {
  160. if (DocumentManager::check_readonly($_course, $user_id, $file)) {
  161. api_not_allowed();
  162. }
  163. }
  164. /* MAIN TOOL CODE */
  165. /* General functions */
  166. /*
  167. Workhorse functions
  168. These do the actual work that is expected from of this tool, other functions
  169. are only there to support these ones.
  170. */
  171. /**
  172. This function changes the name of a certain file.
  173. It needs no global variables, it takes all info from parameters.
  174. It returns nothing.
  175. */
  176. function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) {
  177. $file_name_for_change = $base_work_dir.$dir.$source_file;
  178. //api_display_debug_info("call my_rename: params $file_name_for_change, $rename_to");
  179. $rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file
  180. $rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API
  181. if ($rename_to) {
  182. if (isset($dir) && $dir != '') {
  183. $source_file = $dir.$source_file;
  184. $new_full_file_name = dirname($source_file).'/'.$rename_to;
  185. } else {
  186. $source_file = '/'.$source_file;
  187. $new_full_file_name = '/'.$rename_to;
  188. }
  189. update_db_info('update', $source_file, $new_full_file_name); // fileManage API
  190. $name_changed = get_lang('ElRen');
  191. $info_message = get_lang('fileModified');
  192. $GLOBALS['file_name'] = $rename_to;
  193. $GLOBALS['doc'] = $rename_to;
  194. return $info_message;
  195. } else {
  196. $dialogBox = get_lang('FileExists'); // TODO: This variable is not used.
  197. /* Return to step 1 */
  198. $rename = $source_file;
  199. unset($source_file);
  200. }
  201. }
  202. /* Code to change the comment
  203. Step 2. React on POST data
  204. (Step 1 see below) */
  205. if (isset($_POST['newComment'])) {
  206. // Fixing the path if it is wrong
  207. $commentPath = str_replace('//', '/', Database::escape_string(Security::remove_XSS($_POST['commentPath'])));
  208. $newComment = trim(Database::escape_string(Security::remove_XSS($_POST['newComment']))); // Remove spaces
  209. $newTitle = trim(Database::escape_string(Security::remove_XSS($_POST['newTitle']))); // Remove spaces
  210. // Check whether there is already a database record for this file
  211. $result = Database::query ("SELECT * FROM $dbTable WHERE path LIKE BINARY '".$commentPath."'");
  212. while ($row = Database::fetch_array($result, 'ASSOC')) {
  213. $attribute['path' ] = $row['path' ];
  214. $attribute['comment' ] = $row['title'];
  215. }
  216. // Determine the correct query to the DB,
  217. // new code always keeps document in database
  218. $query = "UPDATE $dbTable
  219. SET comment='".$newComment."', title='".$newTitle."'
  220. WHERE path
  221. LIKE BINARY '".$commentPath."'";
  222. Database::query($query);
  223. $oldComment = $newComment;
  224. $oldTitle = $newTitle;
  225. $comments_updated = get_lang('ComMod');
  226. $info_message = get_lang('fileModified');
  227. }
  228. /* Code to change the name
  229. Step 2. react on POST data - change the name
  230. (Step 1 see below) */
  231. if (isset($_POST['renameTo'])) {
  232. $info_message = change_name($baseWorkDir, $_GET['sourceFile'], $_POST['renameTo'], $dir, $doc);
  233. //assume name change was successful
  234. }
  235. /* Code to change the comment
  236. Step 1. Create dialog box. */
  237. /** TODO: Check whether this code is still used **/
  238. /* Search the old comment */ // RH: metadata: added 'id,'
  239. $result = Database::query("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'");
  240. /*
  241. // Debug info - enable on temporary needs only.
  242. $message = '<i>Debug info</i><br />directory = '.$dir.'<br />';
  243. $message .= 'document = '.$file_name.'<br />';
  244. $message .= 'comments file = '.$file.'<br />';
  245. Display::display_normal_message($message);
  246. */
  247. while ($row = Database::fetch_array($result, 'ASSOC')) {
  248. $oldComment = $row['comment'];
  249. $oldTitle = $row['title'];
  250. $docId = $row['id']; // RH: metadata
  251. }
  252. /* WYSIWYG HTML EDITOR - Program Logic */
  253. if ($is_allowedToEdit) {
  254. if ($_POST['formSent'] == 1) {
  255. if (isset($_POST['renameTo'])) {
  256. $_POST['filename'] = disable_dangerous_file($_POST['renameTo']);
  257. $extension = explode('.', $_POST['filename']);
  258. $extension = $extension[sizeof($extension) - 1];
  259. $_POST['filename'] = str_replace('.'.$extension, '', $_POST['filename']);
  260. }
  261. $filename = stripslashes($_POST['filename']);
  262. $content = trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content'])));
  263. $content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY);
  264. if (!strstr($content, '/css/frames.css')) {
  265. $content=str_replace('</title></head>', '</title><link rel="stylesheet" href="../css/frames.css" type="text/css" /></head>', $content);
  266. }
  267. if (!ctype_alnum($_POST['extension'])) {
  268. header('Location: document.php?msg=WeirdExtensionDeniedInPost');
  269. exit ();
  270. }
  271. $extension = $_POST['extension'];
  272. $file = $dir.$filename.'.'.$extension;
  273. $read_only_flag = $_POST['readonly'];
  274. $read_only_flag = empty($read_only_flag) ? 0 : 1;
  275. $show_edit = $_SESSION['showedit'];
  276. //unset($_SESSION['showedit']);
  277. api_session_unregister('showedit');
  278. if (empty($filename)) {
  279. $msgError = get_lang('NoFileName');
  280. } else {
  281. if ($read_only_flag == 0) {
  282. if (!empty($content)) {
  283. if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
  284. $content = text_filter($content);
  285. // For flv player, change absolute paht temporarely to prevent from erasing it in the following lines
  286. $content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content);
  287. // Change the path of mp3 to absolute
  288. // The first regexp deals with ../../../ urls
  289. // Disabled by Ivan Tcholakov.
  290. //$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  291. // The second regexp deals with audio/ urls
  292. // Disabled by Ivan Tcholakov.
  293. //$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  294. fputs($fp, $content);
  295. fclose($fp);
  296. if (!is_dir($filepath.'css')) {
  297. mkdir($filepath.'css', api_get_permissions_for_new_directories());
  298. $doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
  299. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id);
  300. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
  301. }
  302. if (!is_file($filepath.'css/frames.css')) {
  303. $platform_theme = api_get_setting('stylesheets');
  304. if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
  305. copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css', $filepath.'css/frames.css');
  306. $doc_id = add_document($_course, $dir.'css/frames.css', 'file', filesize($filepath.'css/frames.css'), 'frames.css');
  307. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], null, null, null, null, $current_session_id);
  308. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
  309. }
  310. }
  311. // "WHAT'S NEW" notification: update table item_property
  312. $document_id = DocumentManager::get_document_id($_course, $file);
  313. if ($document_id) {
  314. $file_size = filesize($filepath.$filename.'.'.$extension);
  315. update_existing_document($_course, $document_id, $file_size, $read_only_flag);
  316. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], null, null, null, null, $current_session_id);
  317. // Update parent folders
  318. item_property_update_on_folder($_course, $dir,$_user['user_id']);
  319. $dir = substr($dir, 0, -1);
  320. header('Location: document.php?curdirpath='.urlencode($dir));
  321. exit ();
  322. } else {
  323. //$msgError = get_lang('Impossible');
  324. }
  325. } else {
  326. $msgError = get_lang('Impossible');
  327. }
  328. } else {
  329. if (is_file($filepath.$filename.'.'.$extension)) {
  330. $file_size = filesize($filepath.$filename.'.'.$extension);
  331. $document_id = DocumentManager::get_document_id($_course, $file);
  332. if ($document_id) {
  333. update_existing_document($_course, $document_id, $file_size, $read_only_flag);
  334. }
  335. }
  336. }
  337. } else {
  338. if (is_file($filepath.$filename.'.'.$extension)) {
  339. $file_size = filesize($filepath.$filename.'.'.$extension);
  340. $document_id = DocumentManager::get_document_id($_course, $file);
  341. if ($document_id) {
  342. update_existing_document($_course, $document_id, $file_size, $read_only_flag);
  343. }
  344. }
  345. if (empty($document_id)) { // or if is a folder
  346. $folder = $_POST['file_path'];
  347. $document_id = DocumentManager::get_document_id($_course, $folder);
  348. if (DocumentManager::is_folder($_course, $document_id)) {
  349. if ($document_id) {
  350. update_existing_document($_course, $document_id, $file_size, $read_only_flag);
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. }
  358. // Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/')
  359. if (file_exists($filepath.$doc)) {
  360. $extension = explode('.', $doc);
  361. $extension = $extension[sizeof($extension) - 1];
  362. $filename = str_replace('.'.$extension, '', $doc);
  363. $extension = strtolower($extension);
  364. if (in_array($extension, array('html', 'htm'))) {
  365. $content = file($filepath.$doc);
  366. $content = implode('', $content);
  367. $path_to_append = api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir;
  368. $content = str_replace('="./', '="'.$path_to_append, $content);
  369. $content = str_replace('mp3player.swf?son=.%2F', 'mp3player.swf?son='.urlencode($path_to_append), $content);
  370. }
  371. }
  372. /* Display user interface */
  373. // Display the header
  374. $nameTools = get_lang('EditDocument') . ': '.$file_name;
  375. Display::display_header($nameTools, 'Doc');
  376. // Display the tool title
  377. //api_display_tool_title($nameTools);
  378. if (isset($msgError)) {
  379. Display::display_error_message($msgError);
  380. }
  381. if (isset($info_message)) {
  382. Display::display_confirmation_message($info_message);
  383. if (isset($_POST['origin'])) {
  384. $slide_id = $_POST['origin_opt'];
  385. nav_to_slideshow($slide_id);
  386. }
  387. }
  388. // Readonly
  389. $sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"';
  390. $rs = Database::query($sql);
  391. $readonly = Database::result($rs, 0, 'readonly');
  392. $doc_id = Database::result($rs, 0, 'id');
  393. // Owner
  394. $sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).'
  395. WHERE tool LIKE "document"
  396. AND ref='.intval($doc_id);
  397. $rs = Database::query($sql);
  398. $owner_id = Database::result($rs, 0, 'insert_user_id');
  399. if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'] )) {
  400. $get_cur_path = Security::remove_XSS($_GET['curdirpath']);
  401. $get_file = Security::remove_XSS($_GET['file']);
  402. $action = api_get_self().'?sourceFile='.urlencode($file_name).'&curdirpath='.urlencode($get_cur_path).'&file='.urlencode($get_file).'&doc='.urlencode($doc);
  403. $form = new FormValidator('formEdit', 'post', $action);
  404. // Form title
  405. $form->addElement('header', '', $nameTools);
  406. $renderer = $form->defaultRenderer();
  407. $form->addElement('hidden', 'filename');
  408. $form->addElement('hidden', 'extension');
  409. $form->addElement('hidden', 'file_path');
  410. $form->addElement('hidden', 'commentPath');
  411. $form->addElement('hidden', 'showedit');
  412. $form->addElement('hidden', 'origin');
  413. $form->addElement('hidden', 'origin_opt');
  414. if ($use_document_title) {
  415. $form->add_textfield('newTitle', get_lang('Title'));
  416. $defaults['newTitle'] = $oldTitle;
  417. } else {
  418. $form->addElement('hidden', 'renameTo');
  419. }
  420. $form->addElement('hidden', 'formSent');
  421. $defaults['formSent'] = 1;
  422. $read_only_flag = $_POST['readonly'];
  423. // Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor.
  424. // This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573
  425. $defaults['content'] = str_replace('<!--[', '<!-- [', $content);
  426. //if ($extension == 'htm' || $extension == 'html')
  427. // HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved.
  428. if (($extension == 'htm' || $extension == 'html') && stripos($dir, '/HotPotatoes_files') === false) {
  429. if (empty($readonly) && $readonly == 0) {
  430. $_SESSION['showedit'] = 1;
  431. $renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'content');
  432. $form->add_html_editor('content', '', false, true, $html_editor_config);
  433. }
  434. }
  435. if (!$group_document) {
  436. $metadata_link = '<a href="../metadata/index.php?eid='.urlencode('Document.'.$docId).'">'.get_lang('AddMetadata').'</a>';
  437. $form->addElement('static', null, get_lang('Metadata'), $metadata_link);
  438. }
  439. $form->addElement('textarea', 'newComment', get_lang('Comment'), 'rows="3" style="width:300px;"');
  440. /*
  441. $renderer = $form->defaultRenderer();
  442. */
  443. if ($owner_id == $_user['user_id'] || api_is_platform_admin()) {
  444. $renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
  445. $checked =& $form->addElement('checkbox', 'readonly', get_lang('ReadOnly'));
  446. if ($readonly == 1) {
  447. $checked->setChecked(true);
  448. }
  449. }
  450. if ($is_certificate_mode)
  451. $form->addElement('style_submit_button', 'submit', get_lang('SaveCertificate'), 'class="save"');
  452. else
  453. $form->addElement('style_submit_button','submit',get_lang('SaveDocument'), 'class="save"');
  454. $defaults['filename'] = $filename;
  455. $defaults['extension'] = $extension;
  456. $defaults['file_path'] = Security::remove_XSS($_GET['file']);
  457. $defaults['commentPath'] = $file;
  458. $defaults['renameTo'] = $file_name;
  459. $defaults['newComment'] = $oldComment;
  460. $defaults['origin'] = Security::remove_XSS($_GET['origin']);
  461. $defaults['origin_opt'] = Security::remove_XSS($_GET['origin_opt']);
  462. $form->setDefaults($defaults);
  463. // Show templates
  464. /*
  465. $form->addElement('html', '<div id="frmModel" style="display:block; height:525px; width:240px; position:absolute; top:115px; left:1px;"></div>');
  466. */
  467. if (isset($_REQUEST['curdirpath']) && $_GET['curdirpath']=='/certificates') {
  468. $all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate();
  469. $str_info='';
  470. foreach ($all_information_by_create_certificate[0] as $info_value) {
  471. $str_info.=$info_value.'<br/>';
  472. }
  473. $create_certificate=get_lang('CreateCertificateWithTags');
  474. Display::display_normal_message($create_certificate.': <br /><br />'.$str_info,false);
  475. }
  476. if ($is_certificate_mode) {
  477. echo '<div class="actions">';
  478. echo '<a href="document.php?curdirpath='.Security::remove_XSS($_GET['curdirpath']).'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview')).get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview').'</a>';
  479. echo '</div>';
  480. } else {
  481. $origin=Security::remove_XSS($_GET['origin']);
  482. if ($origin=='slideshow') {
  483. $slide_id=$_GET['origin_opt'];
  484. nav_to_slideshow($slide_id);
  485. }
  486. }
  487. $form->display();
  488. //Display::display_error_message(get_lang('ReadOnlyFile'));
  489. }
  490. // For better navigation when a slide is been commented
  491. function nav_to_slideshow($slide_id) {
  492. $path = Security::remove_XSS($_GET['curdirpath']);
  493. $pathurl = urlencode($path);
  494. echo '<div class="actions">';
  495. echo '<a href="document.php?action=exit_slideshow&curdirpath='.$pathurl.'">'.Display::return_icon('back.png').get_lang('BackTo').' '.get_lang('DocumentsOverview').'</a>&nbsp;';
  496. //echo '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('ViewSlideshow')).get_lang('BackTo').' '.get_lang('ViewSlideshow').'</a>';
  497. echo '</div>';
  498. }
  499. Display::display_footer();