edit_document.php 22 KB

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