edit_document.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <?php // $Id: edit_document.php 22259 2009-07-20 18:56:45Z ivantcholakov $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. Copyright (c) Roan Embrechts
  10. Copyright (c) Rene Haentjens (RH) (update 2004/09/30)
  11. Copyright (c) Bart Mollet, Hogeschool Gent
  12. For a full list of contributors, see "credits.txt".
  13. The full license can be read in "license.txt".
  14. This program is free software; you can redistribute it and/or
  15. modify it under the terms of the GNU General Public License
  16. as published by the Free Software Foundation; either version 2
  17. of the License, or (at your option) any later version.
  18. See the GNU General Public License for more details.
  19. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. * This file allows editing documents.
  25. *
  26. * Based on create_document, this file allows
  27. * - edit name
  28. * - edit comments
  29. * - edit metadata (requires a document table entry)
  30. * - edit html content (only for htm/html files)
  31. *
  32. * For all files
  33. * - show editable name field
  34. * - show editable comments field
  35. * Additionally, for html and text files
  36. * - show RTE
  37. *
  38. * Remember, all files and folders must always have an entry in the
  39. * database, regardless of wether they are visible/invisible, have
  40. * comments or not.
  41. *
  42. * @package dokeos.document
  43. * @todo improve script structure (FormValidator is used to display form, but
  44. * not for validation at the moment)
  45. ==============================================================================
  46. */
  47. // name of the language file that needs to be included
  48. $language_file = 'document';
  49. /*
  50. ------------------------------------------------------------------------------
  51. Included libraries
  52. ------------------------------------------------------------------------------
  53. */
  54. require_once '../inc/global.inc.php';
  55. // Template's javascript
  56. $htmlHeadXtra[] = '
  57. <script type="text/javascript">
  58. function InnerDialogLoaded()
  59. {
  60. /*
  61. var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
  62. return B.ClickFrame();
  63. */
  64. var isIE = (navigator.appVersion.indexOf(\'MSIE\') != -1) ? true : false ;
  65. var EditorFrame = null ;
  66. if ( !isIE )
  67. {
  68. EditorFrame = window.frames[0] ;
  69. }
  70. else
  71. {
  72. // For this dynamic page window.frames[0] enumerates frames in a different order in IE.
  73. // We need a sure method to locate the frame that contains the online editor.
  74. for ( var i = 0, n = window.frames.length ; i < n ; i++ )
  75. {
  76. if ( window.frames[i].location.toString().indexOf(\'InstanceName=texte\') != -1 )
  77. {
  78. EditorFrame = window.frames[i] ;
  79. }
  80. }
  81. }
  82. if ( !EditorFrame )
  83. {
  84. return null ;
  85. }
  86. var B = new EditorFrame.FCKToolbarButton(\'Templates\', EditorFrame.FCKLang.Templates);
  87. return B.ClickFrame();
  88. };
  89. function FCKeditor_OnComplete( editorInstance )
  90. {
  91. 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 \'>";
  92. }
  93. </script>';
  94. $_SESSION['whereami'] = 'document/create';
  95. $this_section=SECTION_COURSES;
  96. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  97. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  98. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  99. require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
  100. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  101. /*
  102. ------------------------------------------------------------------------------
  103. Constants & Variables
  104. ------------------------------------------------------------------------------
  105. */
  106. if (api_is_in_group())
  107. {
  108. $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
  109. }
  110. $file = $_GET['file'];
  111. //echo('file: '.$file.'<br>');
  112. $doc=basename($file);
  113. //echo('doc: '.$doc.'<br>');
  114. $dir=Security::remove_XSS($_GET['curdirpath']);
  115. //echo('dir: '.$dir.'<br>');
  116. $file_name = $doc;
  117. //echo('file_name: '.$file_name.'<br>');
  118. $baseServDir = api_get_path(SYS_COURSE_PATH);
  119. $baseServUrl = $_configuration['url_append']."/";
  120. $courseDir = $_course['path']."/document";
  121. $baseWorkDir = $baseServDir.$courseDir;
  122. $group_document = false;
  123. $doc_tree= explode('/', $file);
  124. $count_dir = count($doc_tree) -2; // "2" because at the begin and end there are 2 "/"
  125. // Level correction for group documents.
  126. if (!empty($group_properties['directory']))
  127. {
  128. $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
  129. }
  130. $relative_url='';
  131. for($i=0;$i<($count_dir);$i++)
  132. {
  133. $relative_url.='../';
  134. }
  135. $html_editor_config = array(
  136. 'ToolbarSet' => (api_is_allowed_to_edit() ? 'Documents' :'DocumentsStudent'),
  137. 'Width' => '100%',
  138. 'Height' => '600',
  139. 'FullPage' => true,
  140. 'InDocument' => true,
  141. 'CreateDocumentDir' => $relative_url,
  142. 'CreateDocumentWebDir' => (empty($group_properties['directory']))
  143. ? api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'
  144. : api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document'.$group_properties['directory'].'/',
  145. 'BaseHref' => api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir
  146. );
  147. $use_document_title = (api_get_setting('use_document_title')=='true') ? true : false;
  148. $noPHP_SELF=true;
  149. /*
  150. ------------------------------------------------------------------------------
  151. Other init code
  152. ------------------------------------------------------------------------------
  153. */
  154. /* please do not modify this dirname formatting */
  155. if(strstr($dir,'..'))
  156. {
  157. $dir='/';
  158. }
  159. if($dir[0] == '.')
  160. {
  161. $dir=substr($dir,1);
  162. }
  163. if($dir[0] != '/')
  164. {
  165. $dir='/'.$dir;
  166. }
  167. if($dir[strlen($dir)-1] != '/')
  168. {
  169. $dir.='/';
  170. }
  171. $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$dir;
  172. if(!is_dir($filepath))
  173. {
  174. $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  175. $dir='/';
  176. }
  177. /**************************************************/
  178. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  179. if(!empty($_SESSION['_gid']))
  180. {
  181. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  182. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace'));
  183. $group_document = true;
  184. $noPHP_SELF=true;
  185. }
  186. $my_cur_dir_path=Security::remove_XSS($_GET['curdirpath']);
  187. $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
  188. $is_allowedToEdit = is_allowed_to_edit() || $_SESSION['group_member_with_upload_rights'];
  189. if(!$is_allowedToEdit)
  190. {
  191. api_not_allowed(true);
  192. }
  193. $user_id = api_get_user_id();
  194. event_access_tool(TOOL_DOCUMENT);
  195. if (!is_allowed_to_edit())
  196. {
  197. if(DocumentManager::check_readonly($_course,$user_id,$file))
  198. {
  199. api_not_allowed();
  200. }
  201. }
  202. /*
  203. ==============================================================================
  204. MAIN TOOL CODE
  205. ==============================================================================
  206. */
  207. /*
  208. ------------------------------------------------------------------------------
  209. General functions
  210. ------------------------------------------------------------------------------
  211. */
  212. /*
  213. ------------------------------------------------------------------------------
  214. Workhorse functions
  215. These do the actual work that is expected from of this tool, other functions
  216. are only there to support these ones.
  217. ------------------------------------------------------------------------------
  218. */
  219. /**
  220. This function changes the name of a certain file.
  221. It needs no global variables, it takes all info from parameters.
  222. It returns nothing.
  223. */
  224. function change_name($baseWorkDir, $sourceFile, $renameTo, $dir, $doc)
  225. {
  226. $file_name_for_change = $baseWorkDir.$dir.$sourceFile;
  227. //api_display_debug_info("call my_rename: params $file_name_for_change, $renameTo");
  228. $renameTo = disable_dangerous_file($renameTo); //avoid renaming to .htaccess file
  229. $renameTo = my_rename($file_name_for_change, stripslashes($renameTo)); //fileManage API
  230. if ($renameTo)
  231. {
  232. if (isset($dir) && $dir != "")
  233. {
  234. $sourceFile = $dir.$sourceFile;
  235. $new_full_file_name = dirname($sourceFile)."/".$renameTo;
  236. }
  237. else
  238. {
  239. $sourceFile = "/".$sourceFile;
  240. $new_full_file_name = "/".$renameTo;
  241. }
  242. update_db_info("update", $sourceFile, $new_full_file_name); //fileManage API
  243. $name_changed = get_lang("ElRen");
  244. $info_message = get_lang('fileModified');
  245. $GLOBALS['file_name'] = $renameTo;
  246. $GLOBALS['doc'] = $renameTo;
  247. return $info_message;
  248. }
  249. else
  250. {
  251. $dialogBox = get_lang('FileExists');
  252. /* return to step 1 */
  253. $rename = $sourceFile;
  254. unset($sourceFile);
  255. }
  256. }
  257. /*
  258. ------------------------------------------------------------------------------
  259. Code to change the comment
  260. ------------------------------------------------------------------------------
  261. Step 2. React on POST data
  262. (Step 1 see below)
  263. */
  264. if (isset($_POST['newComment']))
  265. {
  266. //to try to fix the path if it is wrong
  267. $commentPath = str_replace("//", "/", Database::escape_string(Security::remove_XSS($_POST['commentPath'])));
  268. $newComment = trim(Database::escape_string(Security::remove_XSS($_POST['newComment']))); // remove spaces
  269. $newTitle = trim(Database::escape_string(Security::remove_XSS($_POST['newTitle']))); // remove spaces
  270. // Check if there is already a record for this file in the DB
  271. $result = api_sql_query ("SELECT * FROM $dbTable WHERE path LIKE BINARY '".$commentPath."'",__FILE__,__LINE__);
  272. while($row = Database::fetch_array($result, 'ASSOC'))
  273. {
  274. $attribute['path' ] = $row['path' ];
  275. $attribute['comment' ] = $row['title'];
  276. }
  277. //Determine the correct query to the DB
  278. //new code always keeps document in database
  279. $query = "UPDATE $dbTable
  280. SET comment='".$newComment."', title='".$newTitle."'
  281. WHERE path
  282. LIKE BINARY '".$commentPath."'";
  283. api_sql_query($query,__FILE__,__LINE__);
  284. $oldComment = $newComment;
  285. $oldTitle = $newTitle;
  286. $comments_updated = get_lang('ComMod');
  287. $info_message = get_lang('fileModified');
  288. }
  289. /*
  290. ------------------------------------------------------------------------------
  291. Code to change the name
  292. ------------------------------------------------------------------------------
  293. Step 2. react on POST data - change the name
  294. (Step 1 see below)
  295. */
  296. if (isset($_POST['renameTo']))
  297. {
  298. $info_message = change_name($baseWorkDir, $_GET['sourceFile'], $_POST['renameTo'], $dir, $doc);
  299. //assume name change was successful
  300. }
  301. /*
  302. ------------------------------------------------------------------------------
  303. Code to change the comment
  304. ------------------------------------------------------------------------------
  305. Step 1. Create dialog box.
  306. */
  307. /** TODO check if this code is still used **/
  308. /* Search the old comment */ // RH: metadata: added 'id,'
  309. $result = api_sql_query("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'",__FILE__,__LINE__);
  310. $message = "<i>Debug info</i><br>directory = $dir<br>";
  311. $message .= "document = $file_name<br>";
  312. $message .= "comments file = " . $file . "<br>";
  313. //Display::display_normal_message($message);
  314. while($row = Database::fetch_array($result, 'ASSOC'))
  315. {
  316. $oldComment = $row['comment'];
  317. $oldTitle = $row['title'];
  318. $docId = $row['id']; // RH: metadata
  319. }
  320. /*
  321. ------------------------------------------------------------------------------
  322. WYSIWYG HTML EDITOR - Program Logic
  323. ------------------------------------------------------------------------------
  324. */
  325. if($is_allowedToEdit)
  326. {
  327. if($_POST['formSent']==1)
  328. {
  329. if(isset($_POST['renameTo']))
  330. {
  331. $_POST['filename']=disable_dangerous_file($_POST['renameTo']);
  332. $extension=explode('.',$_POST['filename']);
  333. $extension=$extension[sizeof($extension)-1];
  334. $_POST['filename']=str_replace('.'.$extension,'',$_POST['filename']);
  335. }
  336. $filename=stripslashes($_POST['filename']);
  337. $texte=trim(str_replace(array("\r","\n"),"",stripslashes($_POST['texte'])));
  338. $texte=Security::remove_XSS($texte,COURSEMANAGERLOWSECURITY);
  339. if(!strstr($texte,'/css/frames.css'))
  340. {
  341. $texte=str_replace('</title></head>','</title><link rel="stylesheet" href="../css/frames.css" type="text/css" /></head>',$texte);
  342. }
  343. // RH commented: $filename=replace_dangerous_char($filename,'strict');
  344. // What??
  345. //if($_POST['extension'] != 'htm' && $_POST['extension'] != 'html')
  346. //{
  347. //$extension='html';
  348. //}
  349. //else
  350. //{
  351. $extension = $_POST['extension'];
  352. //}
  353. $file=$dir.$filename.'.'.$extension;
  354. $read_only_flag=$_POST['readonly'];
  355. if (!empty($read_only_flag))
  356. {
  357. $read_only_flag=1;
  358. }
  359. else
  360. {
  361. $read_only_flag=0;
  362. }
  363. $show_edit=$_SESSION['showedit'];
  364. //unset($_SESSION['showedit']);
  365. api_session_unregister('showedit');
  366. if(empty($filename))
  367. {
  368. $msgError=get_lang('NoFileName');
  369. }
  370. else
  371. {
  372. if ($read_only_flag==0)
  373. {
  374. if (!empty($texte))
  375. {
  376. if($fp=@fopen($filepath.$filename.'.'.$extension,'w'))
  377. {
  378. $texte = text_filter($texte);
  379. //if flv player, change absolute paht temporarely to prevent from erasing it in the following lines
  380. $texte = str_replace('flv=h','flv=h|',$texte);
  381. $texte = str_replace('flv=/','flv=/|',$texte);
  382. // change the path of mp3 to absolute
  383. // first regexp deals with ../../../ urls
  384. // Disabled by Ivan Tcholakov.
  385. //$texte = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$texte);
  386. //second regexp deals with audio/ urls
  387. // Disabled by Ivan Tcholakov.
  388. //$texte = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$texte);
  389. fputs($fp,$texte);
  390. fclose($fp);
  391. $perm = api_get_setting('permissions_for_new_directories');
  392. $perm = octdec(!empty($perm)?$perm:'0770');
  393. if(!is_dir($filepath.'css'))
  394. {
  395. mkdir($filepath.'css',$perm);
  396. $doc_id=add_document($_course,$dir.'css','folder',0,'css');
  397. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
  398. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
  399. }
  400. if(!is_file($filepath.'css/frames.css'))
  401. {
  402. $platform_theme= api_get_setting('stylesheets');
  403. if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
  404. copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css',$filepath.'css/frames.css');
  405. $doc_id=add_document($_course,$dir.'css/frames.css','file',filesize($filepath.'css/frames.css'),'frames.css');
  406. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
  407. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
  408. }
  409. }
  410. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  411. $document_id = DocumentManager::get_document_id($_course,$file);
  412. if($document_id)
  413. {
  414. $file_size = filesize($filepath.$filename.'.'.$extension);
  415. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  416. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id']);
  417. //update parent folders
  418. item_property_update_on_folder($_course,$dir,$_user['user_id']);
  419. $dir= substr($dir,0,-1);
  420. header('Location: document.php?curdirpath='.urlencode($dir));
  421. exit ();
  422. }
  423. else
  424. {
  425. //$msgError=get_lang('Impossible');
  426. }
  427. }
  428. else
  429. {
  430. $msgError=get_lang('Impossible');
  431. }
  432. }
  433. else
  434. {
  435. if (is_file($filepath.$filename.'.'.$extension)) {
  436. $file_size = filesize($filepath.$filename.'.'.$extension);
  437. $document_id = DocumentManager::get_document_id($_course,$file);
  438. if ($document_id) {
  439. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  440. }
  441. }
  442. }
  443. }
  444. else
  445. {
  446. if (is_file($filepath.$filename.'.'.$extension)) {
  447. $file_size = filesize($filepath.$filename.'.'.$extension);
  448. $document_id = DocumentManager::get_document_id($_course,$file);
  449. if ($document_id) {
  450. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  451. }
  452. }
  453. if (empty($document_id)) //or if is folder
  454. {
  455. $folder=$_POST['file_path'];
  456. $document_id = DocumentManager::get_document_id($_course,$folder);
  457. if (DocumentManager::is_folder($_course, $document_id))
  458. {
  459. if($document_id)
  460. {
  461. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  462. }
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. //replace relative paths by absolute web paths (e.g. "./" => "http://www.dokeos.com/courses/ABC/document/")
  470. if(file_exists($filepath.$doc))
  471. {
  472. $extension=explode('.',$doc);
  473. $extension=$extension[sizeof($extension)-1];
  474. $filename=str_replace('.'.$extension,'',$doc);
  475. $extension=strtolower($extension);
  476. /*if(!in_array($extension,array('html','htm'))) // that was wrong
  477. {
  478. $extension=$filename=$texte='';
  479. }*/
  480. if(in_array($extension,array('html','htm')))
  481. {
  482. $texte=file($filepath.$doc);
  483. $texte=implode('',$texte);
  484. $path_to_append=api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir;
  485. $texte=str_replace('="./','="'.$path_to_append,$texte);
  486. $texte=str_replace('mp3player.swf?son=.%2F','mp3player.swf?son='.urlencode($path_to_append),$texte);
  487. }
  488. }
  489. /*
  490. ==============================================================================
  491. - display user interface
  492. ==============================================================================
  493. */
  494. // display the header
  495. $nameTools = get_lang("EditDocument") . ': '.$file_name;
  496. Display::display_header($nameTools,"Doc");
  497. // display the tool title
  498. //api_display_tool_title($nameTools);
  499. if(isset($msgError))
  500. {
  501. Display::display_error_message($msgError); //main API
  502. }
  503. if( isset($info_message))
  504. {
  505. Display::display_normal_message($info_message); //main API
  506. }
  507. // readonly
  508. $sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"';
  509. $rs = api_sql_query($sql, __FILE__, __LINE__);
  510. $readonly = Database::result($rs,0,'readonly');
  511. $doc_id = Database::result($rs,0,'id');
  512. // owner
  513. $sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).'
  514. WHERE tool LIKE "document"
  515. AND ref='.intval($doc_id);
  516. $rs = api_sql_query($sql, __FILE__, __LINE__);
  517. $owner_id = Database::result($rs,0,'insert_user_id');
  518. if ($owner_id == $_user['user_id'] || api_is_platform_admin() || api_is_allowed_to_edit() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'] ))
  519. {
  520. $get_cur_path=Security::remove_XSS($_GET['curdirpath']);
  521. $get_file=Security::remove_XSS($_GET['file']);
  522. $action = api_get_self().'?sourceFile='.urlencode($file_name).'&curdirpath='.urlencode($get_cur_path).'&file='.urlencode($get_file).'&doc='.urlencode($doc);
  523. $form = new FormValidator('formEdit','post',$action);
  524. // form title
  525. $form->addElement('header', '', $nameTools);
  526. $renderer = $form->defaultRenderer();
  527. $form->addElement('hidden','filename');
  528. $form->addElement('hidden','extension');
  529. $form->addElement('hidden','file_path');
  530. $form->addElement('hidden','commentPath');
  531. $form->addElement('hidden','showedit');
  532. if($use_document_title)
  533. {
  534. $form->add_textfield('newTitle',get_lang('Title'));
  535. $defaults['newTitle'] = $oldTitle;
  536. }
  537. else
  538. {
  539. $form->addElement('hidden','renameTo');
  540. }
  541. $form->addElement('hidden','formSent');
  542. $defaults['formSent'] = 1;
  543. $read_only_flag=$_POST['readonly'];
  544. $defaults['texte'] = $texte;
  545. //if($extension == 'htm' || $extension == 'html')
  546. // HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved.
  547. if(($extension == 'htm' || $extension == 'html') && stripos($dir, '/HotPotatoes_files') === false)
  548. {
  549. if (empty($readonly) && $readonly==0)
  550. {
  551. $_SESSION['showedit']=1;
  552. $renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'texte');
  553. $form->add_html_editor('texte', '', false, true, $html_editor_config);
  554. }
  555. }
  556. if(!$group_document)
  557. {
  558. $metadata_link = '<a href="../metadata/index.php?eid='.urlencode('Document.'.$docId).'">'.get_lang('AddMetadata').'</a>';
  559. $form->addElement('static',null,get_lang('Metadata'),$metadata_link);
  560. }
  561. $form->addElement('textarea','newComment',get_lang('Comment'),'rows="3" style="width:300px;"');
  562. /*
  563. $renderer = $form->defaultRenderer();
  564. */
  565. if ($owner_id == $_user['user_id'] || api_is_platform_admin())
  566. {
  567. $renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
  568. $checked =&$form->addElement('checkbox','readonly',get_lang('ReadOnly'));
  569. if ($readonly==1)
  570. {
  571. $checked->setChecked(true);
  572. }
  573. }
  574. $form->addElement('style_submit_button','submit',get_lang('SaveDocument'), 'class="save"');
  575. $defaults['filename'] = $filename;
  576. $defaults['extension'] = $extension;
  577. $defaults['file_path'] = Security::remove_XSS($_GET['file']);
  578. $defaults['commentPath'] = $file;
  579. $defaults['renameTo'] = $file_name;
  580. $defaults['newComment'] = $oldComment;
  581. $form->setDefaults($defaults);
  582. // show templates
  583. /*
  584. $form->addElement('html','<div id="frmModel" style="display:block; height:525px; width:240px; position:absolute; top:115px; left:1px;"></div>');
  585. */
  586. $form->display();
  587. //Display::display_error_message(get_lang('ReadOnlyFile')); //main API
  588. }
  589. /*
  590. ==============================================================================
  591. DOKEOS FOOTER
  592. ==============================================================================
  593. */
  594. Display::display_footer();
  595. ?>