edit_document.php 22 KB

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