create_document.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows creating new html documents with an online WYSIWYG html editor.
  5. *
  6. * @package chamilo.document
  7. */
  8. /* INIT SECTION */
  9. // Name of the language file that needs to be included
  10. $language_file = array('document', 'gradebook');
  11. require_once '../inc/global.inc.php';
  12. $_SESSION['whereami'] = 'document/create';
  13. $this_section = SECTION_COURSES;
  14. $htmlHeadXtra[] = '<script type="text/javascript">
  15. function InnerDialogLoaded() {
  16. /*
  17. var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
  18. return B.ClickFrame();
  19. */
  20. var isIE = (navigator.appVersion.indexOf(\'MSIE\') != -1) ? true : false ;
  21. var EditorFrame = null ;
  22. if ( !isIE ) {
  23. EditorFrame = window.frames[0] ;
  24. } else {
  25. // For this dynamic page window.frames[0] enumerates frames in a different order in IE.
  26. // We need a sure method to locate the frame that contains the online editor.
  27. for ( var i = 0, n = window.frames.length ; i < n ; i++ ) {
  28. if ( window.frames[i].location.toString().indexOf(\'InstanceName=content\') != -1 ) {
  29. EditorFrame = window.frames[i] ;
  30. }
  31. }
  32. }
  33. if ( !EditorFrame ) {
  34. return null ;
  35. }
  36. var B = new EditorFrame.FCKToolbarButton(\'Templates\', EditorFrame.FCKLang.Templates);
  37. return B.ClickFrame();
  38. };
  39. var temp=false;
  40. var temp2=false;
  41. var use_document_title='.api_get_setting('use_document_title').';
  42. var load_default_template = '. ((isset($_POST['submit']) || empty($_SERVER['QUERY_STRING'])) ? 'false' : 'true' ) .';
  43. function launch_templates() {
  44. //document.getElementById(\'frmModel\').style.display="block";
  45. //document.getElementById(\'content___Frame\').width=\'70%\';
  46. //window.frames[0].FCKToolbarItems.GetItem("Template").Click;
  47. }
  48. function FCKeditor_OnComplete( editorInstance ) {
  49. editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;
  50. 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 \'>";
  51. }
  52. function check_for_title() {
  53. if (temp) {
  54. // This functions shows that you can interact directly with the editor area
  55. // DOM. In this way you have the freedom to do anything you want with it.
  56. // Get the editor instance that we want to interact with.
  57. var oEditor = FCKeditorAPI.GetInstance(\'content\') ;
  58. // Get the Editor Area DOM (Document object).
  59. var oDOM = oEditor.EditorDocument ;
  60. var iLength ;
  61. var contentText ;
  62. var contentTextArray;
  63. var bestandsnaamNieuw = "";
  64. var bestandsnaamOud = "";
  65. // The are two diffent ways to get the text (without HTML markups).
  66. // It is browser specific.
  67. if( document.all ) // If Internet Explorer.
  68. {
  69. contentText = oDOM.body.innerText ;
  70. }
  71. else // If Gecko.
  72. {
  73. var r = oDOM.createRange() ;
  74. r.selectNodeContents( oDOM.body ) ;
  75. contentText = r.toString() ;
  76. }
  77. var index=contentText.indexOf("/*<![CDATA");
  78. contentText=contentText.substr(0,index);
  79. // Compose title if there is none
  80. contentTextArray = contentText.split(\' \') ;
  81. var x=0;
  82. for(x=0; (x<5 && x<contentTextArray.length); x++)
  83. {
  84. if(x < 4)
  85. {
  86. bestandsnaamNieuw += contentTextArray[x] + \' \';
  87. }
  88. else
  89. {
  90. bestandsnaamNieuw += contentTextArray[x];
  91. }
  92. }
  93. // comment see FS#3335
  94. // if(document.getElementById(\'title_edited\').value == "false")
  95. // {
  96. // document.getElementById(\'filename\').value = bestandsnaamNieuw;
  97. // if(use_document_title){
  98. // document.getElementById(\'title\').value = bestandsnaamNieuw;
  99. // }
  100. // }
  101. }
  102. temp=true;
  103. }
  104. function trim(s) {
  105. while(s.substring(0,1) == \' \') {
  106. s = s.substring(1,s.length);
  107. }
  108. while(s.substring(s.length-1,s.length) == \' \') {
  109. s = s.substring(0,s.length-1);
  110. }
  111. return s;
  112. }
  113. function check_if_still_empty() {
  114. if(trim(document.getElementById(\'filename\').value) != "") {
  115. document.getElementById(\'title_edited\').value = "true";
  116. }
  117. }
  118. function setFocus() {
  119. $("#document_title").focus();
  120. }
  121. $(window).load(function () {
  122. setFocus();
  123. });
  124. </script>';
  125. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  126. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  127. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
  128. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  129. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  130. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  131. if (isset($_REQUEST['certificate'])) {
  132. $nameTools = get_lang('CreateCertificate');
  133. } else {
  134. $nameTools = get_lang('CreateDocument');
  135. }
  136. $nameTools = get_lang('CreateDocument');
  137. /* Constants and variables */
  138. $document_data = DocumentManager::get_document_data_by_id($_REQUEST['id'], api_get_course_id());
  139. if (empty($document_data)) {
  140. if (api_is_in_group()) {
  141. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  142. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  143. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  144. $dir = $document_data['path'];
  145. $folder_id = $document_data['id'];
  146. } else {
  147. $dir = '/';
  148. $folder_id = 0;
  149. }
  150. } else {
  151. $folder_id = $document_data['id'];
  152. $dir = $document_data['path'];
  153. }
  154. /* MAIN CODE */
  155. // Please, do not modify this dirname formatting
  156. if (strstr($dir, '..')) {
  157. $dir = '/';
  158. }
  159. if ($dir[0] == '.') {
  160. $dir = substr($dir, 1);
  161. }
  162. if ($dir[0] != '/') {
  163. $dir = '/'.$dir;
  164. }
  165. if ($dir[strlen($dir) - 1] != '/') {
  166. $dir .= '/';
  167. }
  168. // Configuration for the FCKEDITOR
  169. $doc_tree = explode('/', $dir);
  170. $count_dir = count($doc_tree) -2; // "2" because at the begin and end there are 2 "/"
  171. if (api_is_in_group()) {
  172. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  173. // Level correction for group documents.
  174. if (!empty($group_properties['directory'])) {
  175. $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
  176. }
  177. }
  178. $relative_url = '';
  179. for ($i = 0; $i < ($count_dir); $i++) {
  180. $relative_url .= '../';
  181. }
  182. // We do this in order to avoid the condition in html_editor.php ==> if ($this -> fck_editor->Config['CreateDocumentWebDir']=='' || $this -> fck_editor->Config['CreateDocumentDir']== '')
  183. if ($relative_url== '') {
  184. $relative_url = '/';
  185. }
  186. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  187. $html_editor_config = array(
  188. 'ToolbarSet' => ($is_allowed_to_edit ? 'Documents' :'DocumentsStudent'),
  189. 'Width' => '100%',
  190. 'Height' => '600',
  191. 'FullPage' => true,
  192. 'InDocument' => true,
  193. 'CreateDocumentDir' => $relative_url,
  194. 'CreateDocumentWebDir' => (empty($group_properties['directory']))
  195. ? api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'
  196. : api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/',
  197. 'BaseHref' => api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir
  198. );
  199. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  200. if (!is_dir($filepath)) {
  201. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  202. $dir = '/';
  203. }
  204. //I'm in the certification module?
  205. $is_certificate_mode = false;
  206. $is_certificate_array = explode('/',$dir);
  207. array_shift($is_certificate_array);
  208. if ($is_certificate_array[0]=='certificates') {
  209. $is_certificate_mode = true;
  210. }
  211. $to_group_id = 0;
  212. if (!$is_certificate_mode) {
  213. if (api_is_in_group()) {
  214. $req_gid = '&amp;gidReq='.api_get_group_id();
  215. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".api_get_group_id(), "name" => get_lang('GroupSpace'));
  216. $noPHP_SELF = true;
  217. $to_group_id = api_get_group_id();
  218. $path = explode('/', $dir);
  219. if ('/'.$path[1] != $group_properties['directory']) {
  220. api_not_allowed(true);
  221. }
  222. }
  223. $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents'));
  224. } else {
  225. $interbreadcrumb[]= array ( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  226. }
  227. if (!$is_allowed_in_course) {
  228. api_not_allowed(true);
  229. }
  230. if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] || is_my_shared_folder($_user['user_id'], Security::remove_XSS($dir),api_get_session_id()))) {
  231. api_not_allowed(true);
  232. }
  233. /* Header */
  234. event_access_tool(TOOL_DOCUMENT);
  235. $display_dir = $dir;
  236. if (isset ($group_properties)) {
  237. $display_dir = explode('/', $dir);
  238. unset ($display_dir[0]);
  239. unset ($display_dir[1]);
  240. $display_dir = implode('/', $display_dir);
  241. }
  242. // Create a new form
  243. $form = new FormValidator('create_document','post',api_get_self().'?dir='.Security::remove_XSS(urlencode($dir)).'&selectcat='.Security::remove_XSS($_GET['selectcat']));
  244. // form title
  245. $form->addElement('header', '', $nameTools);
  246. if (isset($_REQUEST['certificate'])) {//added condition for certicate in gradebook
  247. $form->addElement('hidden','certificate','true',array('id'=>'certificate'));
  248. if (isset($_GET['selectcat']))
  249. $form->addElement('hidden','selectcat',intval($_GET['selectcat']));
  250. }
  251. $renderer = & $form->defaultRenderer();
  252. // Hidden element with current directory
  253. $form->addElement('hidden', 'id');
  254. $default['id'] = $folder_id;
  255. // Filename
  256. $form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"');
  257. /**
  258. * Check if a document width the choosen filename allready exists
  259. */
  260. function document_exists($filename) {
  261. global $filepath;
  262. $filename = addslashes(trim($filename));
  263. $filename = Security::remove_XSS($filename);
  264. $filename = replace_dangerous_char($filename);
  265. $filename = disable_dangerous_file($filename);
  266. return !file_exists($filepath.$filename.'.html');
  267. }
  268. // Change the default renderer for the filename-field to display the dir and extension
  269. /*
  270. $renderer = & $form->defaultRenderer();
  271. */
  272. //$filename_template = str_replace('{element}', "<tt>$display_dir</tt> {element} <tt>.html</tt>", $renderer->_elementTemplate);
  273. $filename_template = str_replace('{element}', '{element}', $renderer->_elementTemplate); // TODO: What is the point of this statement?
  274. $renderer->setElementTemplate($filename_template, 'filename');
  275. // Initialize group array
  276. $group = array();
  277. // If allowed, add element for document title
  278. if (api_get_setting('use_document_title') == 'true') {
  279. //$group[]= $form->add_textfield('title', get_lang('Title'),true,'class="input_titles" id="title"');
  280. // replace the add_textfield with this
  281. $group[]=$form->createElement('text','title',get_lang('Title'),'class="input_titles" id="document_title"');
  282. //$form->applyFilter('title','trim');
  283. //$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  284. // Added by Ivan Tcholakov, 10-OCT-2009.
  285. $form->addElement('hidden', 'filename', '', array('id' => 'filename'));
  286. //
  287. } else {
  288. //$form->add_textfield('filename', get_lang('FileName'),true,'class="input_titles" id="filename" onblur="javascript: check_if_still_empty();"');
  289. // replace the add_textfield with this
  290. $group[]=$form->createElement('text', 'filename', get_lang('FileName'), 'class="input_titles" id="document_title" onblur="javascript: check_if_still_empty();"');
  291. //$form->applyFilter('filename','trim');
  292. //$form->addRule('filename', get_lang('ThisFieldIsRequired'), 'required');
  293. //$form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists');
  294. // Added by Ivan Tcholakov, 10-OCT-2009.
  295. $form->addElement('hidden', 'title', '', array('id' => 'title'));
  296. //
  297. }
  298. /*
  299. // Selected the file where are save the news documents
  300. build_directory_selector($folders, $path, $group_properties['directory']);
  301. $subjects = $folders;
  302. $form->addElement('select', get_lang('CurrentDirectory'), '', $folders);
  303. */
  304. // Show read-only box only in groups
  305. if (!empty($_SESSION['_gid'])) {
  306. //$renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
  307. $group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
  308. }
  309. // Add group to the form
  310. if ($is_certificate_mode)
  311. $form->addGroup($group, 'filename_group', get_lang('CertificateName') ,'&nbsp;&nbsp;&nbsp;', false);
  312. else
  313. $form->addGroup($group, 'filename_group', api_get_setting('use_document_title') == 'true' ? get_lang('Title') : get_lang('FileName') ,'&nbsp;&nbsp;&nbsp;', false);
  314. $form->addRule('filename_group', get_lang('ThisFieldIsRequired'), 'required');
  315. if (api_get_setting('use_document_title') == 'true') {
  316. $form->addGroupRule('filename_group', array(
  317. 'title' => array(
  318. array(get_lang('ThisFieldIsRequired'), 'required'),
  319. array(get_lang('FileExists'),'callback', 'document_exists')
  320. )
  321. ));
  322. } else {
  323. $form->addGroupRule('filename_group', array(
  324. 'filename' => array(
  325. array(get_lang('ThisFieldIsRequired'), 'required'),
  326. array(get_lang('FileExists'),'callback', 'document_exists')
  327. )
  328. ));
  329. }
  330. $current_session_id = api_get_session_id();
  331. //$form->addElement('style_submit_button', 'submit', get_lang('SaveDocument'), 'class="save"');
  332. // HTML-editor
  333. $renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'content');
  334. $form->add_html_editor('content','', false, false, $html_editor_config);
  335. // Comment-field
  336. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  337. // If we are not in the certificates creation, display a folder chooser for the
  338. // new document created
  339. if (!$is_certificate_mode && !is_my_shared_folder($_user['user_id'], $dir, $current_session_id)) {
  340. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  341. //$parent_select -> addOption(get_lang('HomeDirectory'), '/');
  342. $parent_select = $form->addElement('select', 'curdirpath', get_lang('DestinationDirectory'));
  343. // Following two conditions copied from document.inc.php::build_directory_selector()
  344. $folder_titles = array();
  345. if (api_get_setting('use_document_title') == 'true') {
  346. if (is_array($folders)) {
  347. $escaped_folders = array();
  348. foreach ($folders as $key => & $val) {
  349. //Hide some folders
  350. if ($val=='/HotPotatoes_files' || $val=='/certificates' || basename($val)=='css'){
  351. continue;
  352. }
  353. //Admin setting for Hide/Show the folders of all users
  354. if (api_get_setting('show_users_folders') == 'false' && (strstr($val, '/shared_folder') || strstr($val, 'shared_folder_session_'))){
  355. continue;
  356. }
  357. //Admin setting for Hide/Show Default folders to all users
  358. if (api_get_setting('show_default_folders') == 'false' && ($val=='/images' || $val=='/flash' || $val=='/audio' || $val=='/video' || strstr($val, '/images/gallery') || $val=='/video/flv')){
  359. continue;
  360. }
  361. //Admin setting for Hide/Show chat history folder
  362. if (api_get_setting('show_chat_folder') == 'false' && $val=='/chat_files'){
  363. continue;
  364. }
  365. $escaped_folders[$key] = Database::escape_string($val);
  366. }
  367. $folder_sql = implode("','", $escaped_folders);
  368. $doc_table = Database::get_course_table(TABLE_DOCUMENT);
  369. $sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')";
  370. $res = Database::query($sql);
  371. $folder_titles = array();
  372. while ($obj = Database::fetch_object($res)) {
  373. $folder_titles[$obj->path] = $obj->title;
  374. }
  375. }
  376. } else {
  377. if (is_array($folders)) {
  378. foreach ($folders as & $folder) {
  379. $folder_titles[$folder] = basename($folder);
  380. }
  381. }
  382. }
  383. if (empty($group_dir)) {
  384. $parent_select -> addOption(get_lang('HomeDirectory'), '/');
  385. if (is_array($folders)) {
  386. foreach ($folders as & $folder) {
  387. //Hide some folders
  388. if ($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css'){
  389. continue;
  390. }
  391. //Admin setting for Hide/Show the folders of all users
  392. if (api_get_setting('show_users_folders') == 'false' && (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))){
  393. continue;
  394. }
  395. //Admin setting for Hide/Show Default folders to all users
  396. if (api_get_setting('show_default_folders') == 'false' && ($folder=='/images' || $folder=='/flash' || $folder=='/audio' || $folder=='/video' || strstr($folder, '/images/gallery') || $folder=='/video/flv')){
  397. continue;
  398. }
  399. //Admin setting for Hide/Show chat history folder
  400. if (api_get_setting('show_chat_folder') == 'false' && $folder=='/chat_files'){
  401. continue;
  402. }
  403. $selected = (substr($dir,0,-1) == $folder) ? ' selected="selected"' : '';
  404. $path_parts = explode('/', $folder);
  405. $folder_titles[$folder] = cut($folder_titles[$folder], 80);
  406. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$folder_titles[$folder];
  407. $parent_select -> addOption($label, $folder);
  408. if ($selected != '') {
  409. $parent_select->setSelected($folder);
  410. }
  411. }
  412. }
  413. } else {
  414. foreach ($folders as & $folder) {
  415. $selected = (substr($dir,0,-1)==$folder) ? ' selected="selected"' : '';
  416. $label = $folder_titles[$folder];
  417. if ($folder == $group_dir) {
  418. $label = '/ ('.get_lang('HomeDirectory').')';
  419. } else {
  420. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  421. $label = cut($label, 80);
  422. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  423. }
  424. $parent_select -> addOption($label, $folder);
  425. if ($selected != '') {
  426. $parent_select->setSelected($folder);
  427. }
  428. }
  429. }
  430. }
  431. //$form->addElement('textarea', 'comment', get_lang('Comment'), array ('rows' => 5, 'cols' => 50));
  432. if ($is_certificate_mode)
  433. $form->addElement('style_submit_button', 'submit', get_lang('CreateCertificate'), 'class="save"');
  434. else
  435. $form->addElement('style_submit_button', 'submit', get_lang('langCreateDoc'), 'class="save"');
  436. $form->setDefaults($default);
  437. // HTML
  438. /*
  439. $form->addElement('html','<div id="frmModel" style="display:block; height:525px; width:240px; position:absolute; top:115px; left:1px;"></div>');
  440. */
  441. // If form validates -> save the new document
  442. if ($form->validate()) {
  443. $values = $form->exportValues();
  444. $readonly = isset($values['readonly']) ? 1 : 0;
  445. $values['title'] = addslashes(trim($values['title']));
  446. $values['title'] = Security::remove_XSS($values['title']);
  447. $values['title'] = replace_dangerous_char($values['title']);
  448. $values['title'] = disable_dangerous_file($values['title']);
  449. $values['filename'] = addslashes(trim($values['filename']));
  450. $values['filename'] = Security::remove_XSS($values['filename']);
  451. $values['filename'] = replace_dangerous_char($values['filename']);
  452. $values['filename'] = disable_dangerous_file($values['filename']);
  453. //die($values['curdirpath']);
  454. if (!empty($values['curdirpath'])) {
  455. $dir = $values['curdirpath'];
  456. }
  457. if ($dir[strlen($dir) - 1] != '/') {
  458. $dir .= '/';
  459. }
  460. if (api_get_setting('use_document_title') != 'true') {
  461. $values['title'] = $values['filename'];
  462. } else {
  463. $values['filename'] = $values['title'];
  464. }
  465. $filename = $values['filename'];
  466. $title = $values['title'];
  467. $extension = 'html';
  468. $content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
  469. if (strpos($content, '/css/frames.css') === false) {
  470. $content = str_replace('</head>', '<style> body{margin:10px;}</style> <link rel="stylesheet" href="./css/frames.css" type="text/css" /></head>', $content);
  471. }
  472. if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
  473. $content = text_filter($content);
  474. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].'/courses/', $content);
  475. // change the path of mp3 to absolute
  476. // first regexp deals with ../../../ urls
  477. // Disabled by Ivan Tcholakov.
  478. //$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  479. //second regexp deals with audio/ urls
  480. // Disabled by Ivan Tcholakov.
  481. //$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  482. fputs($fp, $content);
  483. fclose($fp);
  484. chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
  485. if (!is_dir($filepath.'css')) {
  486. mkdir($filepath.'css', api_get_permissions_for_new_directories());
  487. $doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
  488. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id);
  489. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
  490. }
  491. if (!is_file($filepath.'css/frames.css')) {
  492. // Make a copy of the current css for the new document
  493. copy(api_get_path(SYS_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css', $filepath.'css/frames.css');
  494. $doc_id = add_document($_course, $dir.'css/frames.css', 'file', filesize($filepath.'css/frames.css'), 'frames.css');
  495. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], null, null, null, null, $current_session_id);
  496. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
  497. }
  498. $file_size = filesize($filepath.$filename.'.'.$extension);
  499. $save_file_path = $dir.$filename.'.'.$extension;
  500. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename, null, $readonly);
  501. if ($document_id) {
  502. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id, null, null, null, $current_session_id);
  503. // Update parent folders
  504. item_property_update_on_folder($_course, $dir, $_user['user_id']);
  505. $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
  506. $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
  507. if ($new_comment || $new_title) {
  508. $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  509. $ct = '';
  510. if ($new_comment)
  511. $ct .= ", comment='$new_comment'";
  512. if ($new_title)
  513. $ct .= ", title='$new_title'";
  514. Database::query("UPDATE $TABLE_DOCUMENT SET".substr($ct, 1)." WHERE id = '$document_id'");
  515. }
  516. $dir= substr($dir,0,-1);
  517. $selectcat = '';
  518. if (isset($_REQUEST['selectcat']))
  519. $selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']);
  520. header('Location: document.php?id='.$folder_id.$selectcat);
  521. exit ();
  522. } else {
  523. Display :: display_header($nameTools, 'Doc');
  524. Display :: display_error_message(get_lang('Impossible'));
  525. Display :: display_footer();
  526. }
  527. } else {
  528. Display :: display_header($nameTools, 'Doc');
  529. //api_display_tool_title($nameTools);
  530. Display :: display_error_message(get_lang('Impossible'));
  531. Display :: display_footer();
  532. }
  533. } else {
  534. // Interbreadcrumb for the current directory root path
  535. // Copied from document.php
  536. $dir_array = explode('/', $dir);
  537. $array_len = count($dir_array);
  538. /*
  539. TODO:check and delete this code
  540. if (!$is_certificate_mode) {
  541. if ($array_len > 1) {
  542. if (empty($_SESSION['_gid'])) {
  543. $url_dir = 'document.php?&curdirpath=/';
  544. $interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory'));
  545. }
  546. }
  547. }
  548. */
  549. $dir_acum = '';
  550. for ($i = 0; $i < $array_len; $i++) {
  551. $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
  552. //Max char 80
  553. $url_to_who = cut($dir_array[$i],80);
  554. if ($is_certificate_mode) {
  555. $interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who);
  556. } else {
  557. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
  558. }
  559. $dir_acum .= $dir_array[$i].'/';
  560. }
  561. Display :: display_header($nameTools, "Doc");
  562. //api_display_tool_title($nameTools);
  563. // actions
  564. if (isset($_REQUEST['certificate'])) {
  565. $all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate(api_get_user_id());
  566. $str_info='';
  567. foreach ($all_information_by_create_certificate[0] as $info_value) {
  568. $str_info.=$info_value.'<br/>';
  569. }
  570. $create_certificate=get_lang('CreateCertificateWithTags');
  571. Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info,false);
  572. }
  573. echo '<div class="actions">';
  574. // link back to the documents overview
  575. if ($is_certificate_mode)
  576. echo '<a href="document.php?curdirpath='.Security::remove_XSS($dir).'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'','32').'</a>';
  577. else
  578. echo '<a href="document.php?curdirpath='.Security::remove_XSS($dir).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview'),'','32').'</a>';
  579. echo '</div>';
  580. $form->display();
  581. Display :: display_footer();
  582. }