create_document.php 25 KB

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