edit_document.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. $current_session_id = api_get_session_id();
  124. $doc_tree= explode('/', $file);
  125. $count_dir = count($doc_tree) -2; // "2" because at the begin and end there are 2 "/"
  126. // Level correction for group documents.
  127. if (!empty($group_properties['directory']))
  128. {
  129. $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
  130. }
  131. $relative_url='';
  132. for($i=0;$i<($count_dir);$i++)
  133. {
  134. $relative_url.='../';
  135. }
  136. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  137. $html_editor_config = array(
  138. 'ToolbarSet' => ($is_allowed_to_edit ? 'Documents' :'DocumentsStudent'),
  139. 'Width' => '100%',
  140. 'Height' => '600',
  141. 'FullPage' => true,
  142. 'InDocument' => true,
  143. 'CreateDocumentDir' => $relative_url,
  144. 'CreateDocumentWebDir' => (empty($group_properties['directory']))
  145. ? api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'
  146. : api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document'.$group_properties['directory'].'/',
  147. 'BaseHref' => api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir
  148. );
  149. $use_document_title = (api_get_setting('use_document_title')=='true') ? true : false;
  150. $noPHP_SELF=true;
  151. /*
  152. ------------------------------------------------------------------------------
  153. Other init code
  154. ------------------------------------------------------------------------------
  155. */
  156. /* please do not modify this dirname formatting */
  157. if(strstr($dir,'..'))
  158. {
  159. $dir='/';
  160. }
  161. if($dir[0] == '.')
  162. {
  163. $dir=substr($dir,1);
  164. }
  165. if($dir[0] != '/')
  166. {
  167. $dir='/'.$dir;
  168. }
  169. if($dir[strlen($dir)-1] != '/')
  170. {
  171. $dir.='/';
  172. }
  173. $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$dir;
  174. if(!is_dir($filepath))
  175. {
  176. $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  177. $dir='/';
  178. }
  179. /**************************************************/
  180. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  181. if(!empty($_SESSION['_gid']))
  182. {
  183. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  184. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace'));
  185. $group_document = true;
  186. $noPHP_SELF=true;
  187. }
  188. $my_cur_dir_path=Security::remove_XSS($_GET['curdirpath']);
  189. $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
  190. $is_allowedToEdit = is_allowed_to_edit() || $_SESSION['group_member_with_upload_rights'];
  191. if(!$is_allowedToEdit)
  192. {
  193. api_not_allowed(true);
  194. }
  195. $user_id = api_get_user_id();
  196. event_access_tool(TOOL_DOCUMENT);
  197. if (!is_allowed_to_edit())
  198. {
  199. if(DocumentManager::check_readonly($_course,$user_id,$file))
  200. {
  201. api_not_allowed();
  202. }
  203. }
  204. /*
  205. ==============================================================================
  206. MAIN TOOL CODE
  207. ==============================================================================
  208. */
  209. /*
  210. ------------------------------------------------------------------------------
  211. General functions
  212. ------------------------------------------------------------------------------
  213. */
  214. /*
  215. ------------------------------------------------------------------------------
  216. Workhorse functions
  217. These do the actual work that is expected from of this tool, other functions
  218. are only there to support these ones.
  219. ------------------------------------------------------------------------------
  220. */
  221. /**
  222. This function changes the name of a certain file.
  223. It needs no global variables, it takes all info from parameters.
  224. It returns nothing.
  225. */
  226. function change_name($baseWorkDir, $sourceFile, $renameTo, $dir, $doc)
  227. {
  228. $file_name_for_change = $baseWorkDir.$dir.$sourceFile;
  229. //api_display_debug_info("call my_rename: params $file_name_for_change, $renameTo");
  230. $renameTo = disable_dangerous_file($renameTo); //avoid renaming to .htaccess file
  231. $renameTo = my_rename($file_name_for_change, stripslashes($renameTo)); //fileManage API
  232. if ($renameTo)
  233. {
  234. if (isset($dir) && $dir != "")
  235. {
  236. $sourceFile = $dir.$sourceFile;
  237. $new_full_file_name = dirname($sourceFile)."/".$renameTo;
  238. }
  239. else
  240. {
  241. $sourceFile = "/".$sourceFile;
  242. $new_full_file_name = "/".$renameTo;
  243. }
  244. update_db_info("update", $sourceFile, $new_full_file_name); //fileManage API
  245. $name_changed = get_lang("ElRen");
  246. $info_message = get_lang('fileModified');
  247. $GLOBALS['file_name'] = $renameTo;
  248. $GLOBALS['doc'] = $renameTo;
  249. return $info_message;
  250. }
  251. else
  252. {
  253. $dialogBox = get_lang('FileExists');
  254. /* return to step 1 */
  255. $rename = $sourceFile;
  256. unset($sourceFile);
  257. }
  258. }
  259. /*
  260. ------------------------------------------------------------------------------
  261. Code to change the comment
  262. ------------------------------------------------------------------------------
  263. Step 2. React on POST data
  264. (Step 1 see below)
  265. */
  266. if (isset($_POST['newComment']))
  267. {
  268. //to try to fix the path if it is wrong
  269. $commentPath = str_replace("//", "/", Database::escape_string(Security::remove_XSS($_POST['commentPath'])));
  270. $newComment = trim(Database::escape_string(Security::remove_XSS($_POST['newComment']))); // remove spaces
  271. $newTitle = trim(Database::escape_string(Security::remove_XSS($_POST['newTitle']))); // remove spaces
  272. // Check if there is already a record for this file in the DB
  273. $result = Database::query ("SELECT * FROM $dbTable WHERE path LIKE BINARY '".$commentPath."'",__FILE__,__LINE__);
  274. while($row = Database::fetch_array($result, 'ASSOC'))
  275. {
  276. $attribute['path' ] = $row['path' ];
  277. $attribute['comment' ] = $row['title'];
  278. }
  279. //Determine the correct query to the DB
  280. //new code always keeps document in database
  281. $query = "UPDATE $dbTable
  282. SET comment='".$newComment."', title='".$newTitle."'
  283. WHERE path
  284. LIKE BINARY '".$commentPath."'";
  285. Database::query($query,__FILE__,__LINE__);
  286. $oldComment = $newComment;
  287. $oldTitle = $newTitle;
  288. $comments_updated = get_lang('ComMod');
  289. $info_message = get_lang('fileModified');
  290. }
  291. /*
  292. ------------------------------------------------------------------------------
  293. Code to change the name
  294. ------------------------------------------------------------------------------
  295. Step 2. react on POST data - change the name
  296. (Step 1 see below)
  297. */
  298. if (isset($_POST['renameTo']))
  299. {
  300. $info_message = change_name($baseWorkDir, $_GET['sourceFile'], $_POST['renameTo'], $dir, $doc);
  301. //assume name change was successful
  302. }
  303. /*
  304. ------------------------------------------------------------------------------
  305. Code to change the comment
  306. ------------------------------------------------------------------------------
  307. Step 1. Create dialog box.
  308. */
  309. /** TODO check if this code is still used **/
  310. /* Search the old comment */ // RH: metadata: added 'id,'
  311. $result = Database::query("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'",__FILE__,__LINE__);
  312. $message = "<i>Debug info</i><br>directory = $dir<br>";
  313. $message .= "document = $file_name<br>";
  314. $message .= "comments file = " . $file . "<br>";
  315. //Display::display_normal_message($message);
  316. while($row = Database::fetch_array($result, 'ASSOC'))
  317. {
  318. $oldComment = $row['comment'];
  319. $oldTitle = $row['title'];
  320. $docId = $row['id']; // RH: metadata
  321. }
  322. /*
  323. ------------------------------------------------------------------------------
  324. WYSIWYG HTML EDITOR - Program Logic
  325. ------------------------------------------------------------------------------
  326. */
  327. if($is_allowedToEdit)
  328. {
  329. if($_POST['formSent']==1)
  330. {
  331. if(isset($_POST['renameTo']))
  332. {
  333. $_POST['filename']=disable_dangerous_file($_POST['renameTo']);
  334. $extension=explode('.',$_POST['filename']);
  335. $extension=$extension[sizeof($extension)-1];
  336. $_POST['filename']=str_replace('.'.$extension,'',$_POST['filename']);
  337. }
  338. $filename=stripslashes($_POST['filename']);
  339. $texte=trim(str_replace(array("\r","\n"),"",stripslashes($_POST['texte'])));
  340. $texte=Security::remove_XSS($texte,COURSEMANAGERLOWSECURITY);
  341. if(!strstr($texte,'/css/frames.css'))
  342. {
  343. $texte=str_replace('</title></head>','</title><link rel="stylesheet" href="../css/frames.css" type="text/css" /></head>',$texte);
  344. }
  345. // RH commented: $filename=replace_dangerous_char($filename,'strict');
  346. // What??
  347. //if($_POST['extension'] != 'htm' && $_POST['extension'] != 'html')
  348. //{
  349. //$extension='html';
  350. //}
  351. //else
  352. //{
  353. $extension = $_POST['extension'];
  354. //}
  355. $file=$dir.$filename.'.'.$extension;
  356. $read_only_flag=$_POST['readonly'];
  357. if (!empty($read_only_flag))
  358. {
  359. $read_only_flag=1;
  360. }
  361. else
  362. {
  363. $read_only_flag=0;
  364. }
  365. $show_edit=$_SESSION['showedit'];
  366. //unset($_SESSION['showedit']);
  367. api_session_unregister('showedit');
  368. if(empty($filename))
  369. {
  370. $msgError=get_lang('NoFileName');
  371. }
  372. else
  373. {
  374. if ($read_only_flag==0)
  375. {
  376. if (!empty($texte))
  377. {
  378. if($fp=@fopen($filepath.$filename.'.'.$extension,'w'))
  379. {
  380. $texte = text_filter($texte);
  381. //if flv player, change absolute paht temporarely to prevent from erasing it in the following lines
  382. $texte = str_replace('flv=h','flv=h|',$texte);
  383. $texte = str_replace('flv=/','flv=/|',$texte);
  384. // change the path of mp3 to absolute
  385. // first regexp deals with ../../../ urls
  386. // Disabled by Ivan Tcholakov.
  387. //$texte = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$texte);
  388. //second regexp deals with audio/ urls
  389. // Disabled by Ivan Tcholakov.
  390. //$texte = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$texte);
  391. fputs($fp,$texte);
  392. fclose($fp);
  393. $perm = api_get_setting('permissions_for_new_directories');
  394. $perm = octdec(!empty($perm)?$perm:'0770');
  395. if(!is_dir($filepath.'css'))
  396. {
  397. mkdir($filepath.'css',$perm);
  398. $doc_id=add_document($_course,$dir.'css','folder',0,'css');
  399. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'],null,null,null,null,$current_session_id);
  400. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'],null,null,null,null,$current_session_id);
  401. }
  402. if(!is_file($filepath.'css/frames.css'))
  403. {
  404. $platform_theme= api_get_setting('stylesheets');
  405. if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
  406. copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css',$filepath.'css/frames.css');
  407. $doc_id=add_document($_course,$dir.'css/frames.css','file',filesize($filepath.'css/frames.css'),'frames.css');
  408. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'],null,null,null,null,$current_session_id);
  409. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'],null,null,null,null,$current_session_id);
  410. }
  411. }
  412. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  413. $document_id = DocumentManager::get_document_id($_course,$file);
  414. if($document_id)
  415. {
  416. $file_size = filesize($filepath.$filename.'.'.$extension);
  417. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  418. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'],null,null,null,null,$current_session_id);
  419. //update parent folders
  420. item_property_update_on_folder($_course,$dir,$_user['user_id']);
  421. $dir= substr($dir,0,-1);
  422. header('Location: document.php?curdirpath='.urlencode($dir));
  423. exit ();
  424. }
  425. else
  426. {
  427. //$msgError=get_lang('Impossible');
  428. }
  429. }
  430. else
  431. {
  432. $msgError=get_lang('Impossible');
  433. }
  434. }
  435. else
  436. {
  437. if (is_file($filepath.$filename.'.'.$extension)) {
  438. $file_size = filesize($filepath.$filename.'.'.$extension);
  439. $document_id = DocumentManager::get_document_id($_course,$file);
  440. if ($document_id) {
  441. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  442. }
  443. }
  444. }
  445. }
  446. else
  447. {
  448. if (is_file($filepath.$filename.'.'.$extension)) {
  449. $file_size = filesize($filepath.$filename.'.'.$extension);
  450. $document_id = DocumentManager::get_document_id($_course,$file);
  451. if ($document_id) {
  452. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  453. }
  454. }
  455. if (empty($document_id)) //or if is folder
  456. {
  457. $folder=$_POST['file_path'];
  458. $document_id = DocumentManager::get_document_id($_course,$folder);
  459. if (DocumentManager::is_folder($_course, $document_id))
  460. {
  461. if($document_id)
  462. {
  463. update_existing_document($_course, $document_id,$file_size,$read_only_flag);
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. }
  471. //replace relative paths by absolute web paths (e.g. "./" => "http://www.dokeos.com/courses/ABC/document/")
  472. if(file_exists($filepath.$doc))
  473. {
  474. $extension=explode('.',$doc);
  475. $extension=$extension[sizeof($extension)-1];
  476. $filename=str_replace('.'.$extension,'',$doc);
  477. $extension=strtolower($extension);
  478. /*if(!in_array($extension,array('html','htm'))) // that was wrong
  479. {
  480. $extension=$filename=$texte='';
  481. }*/
  482. if(in_array($extension,array('html','htm')))
  483. {
  484. $texte=file($filepath.$doc);
  485. $texte=implode('',$texte);
  486. $path_to_append=api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir;
  487. $texte=str_replace('="./','="'.$path_to_append,$texte);
  488. $texte=str_replace('mp3player.swf?son=.%2F','mp3player.swf?son='.urlencode($path_to_append),$texte);
  489. }
  490. }
  491. /*
  492. ==============================================================================
  493. - display user interface
  494. ==============================================================================
  495. */
  496. // display the header
  497. $nameTools = get_lang("EditDocument") . ': '.$file_name;
  498. Display::display_header($nameTools,"Doc");
  499. // display the tool title
  500. //api_display_tool_title($nameTools);
  501. if(isset($msgError))
  502. {
  503. Display::display_error_message($msgError); //main API
  504. }
  505. if( isset($info_message))
  506. {
  507. Display::display_normal_message($info_message); //main API
  508. }
  509. // readonly
  510. $sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"';
  511. $rs = Database::query($sql, __FILE__, __LINE__);
  512. $readonly = Database::result($rs,0,'readonly');
  513. $doc_id = Database::result($rs,0,'id');
  514. // owner
  515. $sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).'
  516. WHERE tool LIKE "document"
  517. AND ref='.intval($doc_id);
  518. $rs = Database::query($sql, __FILE__, __LINE__);
  519. $owner_id = Database::result($rs,0,'insert_user_id');
  520. if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'] ))
  521. {
  522. $get_cur_path=Security::remove_XSS($_GET['curdirpath']);
  523. $get_file=Security::remove_XSS($_GET['file']);
  524. $action = api_get_self().'?sourceFile='.urlencode($file_name).'&curdirpath='.urlencode($get_cur_path).'&file='.urlencode($get_file).'&doc='.urlencode($doc);
  525. $form = new FormValidator('formEdit','post',$action);
  526. // form title
  527. $form->addElement('header', '', $nameTools);
  528. $renderer = $form->defaultRenderer();
  529. $form->addElement('hidden','filename');
  530. $form->addElement('hidden','extension');
  531. $form->addElement('hidden','file_path');
  532. $form->addElement('hidden','commentPath');
  533. $form->addElement('hidden','showedit');
  534. if($use_document_title)
  535. {
  536. $form->add_textfield('newTitle',get_lang('Title'));
  537. $defaults['newTitle'] = $oldTitle;
  538. }
  539. else
  540. {
  541. $form->addElement('hidden','renameTo');
  542. }
  543. $form->addElement('hidden','formSent');
  544. $defaults['formSent'] = 1;
  545. $read_only_flag=$_POST['readonly'];
  546. $defaults['texte'] = $texte;
  547. //if($extension == 'htm' || $extension == 'html')
  548. // HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved.
  549. if(($extension == 'htm' || $extension == 'html') && stripos($dir, '/HotPotatoes_files') === false)
  550. {
  551. if (empty($readonly) && $readonly==0)
  552. {
  553. $_SESSION['showedit']=1;
  554. $renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'texte');
  555. $form->add_html_editor('texte', '', false, true, $html_editor_config);
  556. }
  557. }
  558. if(!$group_document)
  559. {
  560. $metadata_link = '<a href="../metadata/index.php?eid='.urlencode('Document.'.$docId).'">'.get_lang('AddMetadata').'</a>';
  561. $form->addElement('static',null,get_lang('Metadata'),$metadata_link);
  562. }
  563. $form->addElement('textarea','newComment',get_lang('Comment'),'rows="3" style="width:300px;"');
  564. /*
  565. $renderer = $form->defaultRenderer();
  566. */
  567. if ($owner_id == $_user['user_id'] || api_is_platform_admin())
  568. {
  569. $renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
  570. $checked =&$form->addElement('checkbox','readonly',get_lang('ReadOnly'));
  571. if ($readonly==1)
  572. {
  573. $checked->setChecked(true);
  574. }
  575. }
  576. $form->addElement('style_submit_button','submit',get_lang('SaveDocument'), 'class="save"');
  577. $defaults['filename'] = $filename;
  578. $defaults['extension'] = $extension;
  579. $defaults['file_path'] = Security::remove_XSS($_GET['file']);
  580. $defaults['commentPath'] = $file;
  581. $defaults['renameTo'] = $file_name;
  582. $defaults['newComment'] = $oldComment;
  583. $form->setDefaults($defaults);
  584. // show templates
  585. /*
  586. $form->addElement('html','<div id="frmModel" style="display:block; height:525px; width:240px; position:absolute; top:115px; left:1px;"></div>');
  587. */
  588. $form->display();
  589. //Display::display_error_message(get_lang('ReadOnlyFile')); //main API
  590. }
  591. /*
  592. ==============================================================================
  593. DOKEOS FOOTER
  594. ==============================================================================
  595. */
  596. Display::display_footer();
  597. ?>