edit_document.php 23 KB

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