create_document.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. //I'm in the certification module?
  134. $is_certificate_mode = false;
  135. if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
  136. $is_certificate_mode = true;
  137. }
  138. if ($is_certificate_mode) {
  139. $nameTools = get_lang('CreateCertificate');
  140. } else {
  141. $nameTools = get_lang('CreateDocument');
  142. }
  143. /* Constants and variables */
  144. $document_data = DocumentManager::get_document_data_by_id($_REQUEST['id'], api_get_course_id(), true);
  145. if (empty($document_data)) {
  146. if (api_is_in_group()) {
  147. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  148. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  149. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  150. $dir = $document_data['path'];
  151. $folder_id = $document_data['id'];
  152. } else {
  153. $dir = '/';
  154. $folder_id = 0;
  155. }
  156. } else {
  157. $folder_id = $document_data['id'];
  158. $dir = $document_data['path'];
  159. }
  160. /* MAIN CODE */
  161. // Please, do not modify this dirname formatting
  162. if (strstr($dir, '..')) {
  163. $dir = '/';
  164. }
  165. if ($dir[0] == '.') {
  166. $dir = substr($dir, 1);
  167. }
  168. if ($dir[0] != '/') {
  169. $dir = '/'.$dir;
  170. }
  171. if ($dir[strlen($dir) - 1] != '/') {
  172. $dir .= '/';
  173. }
  174. if ($is_certificate_mode) {
  175. $document_id = DocumentManager::get_document_id(api_get_course_info(), '/certificates');
  176. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
  177. $folder_id = $document_data['id'];
  178. $dir = '/certificates/';
  179. }
  180. // Configuration for the FCKEDITOR
  181. $doc_tree = explode('/', $dir);
  182. $count_dir = count($doc_tree) -2; // "2" because at the begin and end there are 2 "/"
  183. if (api_is_in_group()) {
  184. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  185. // Level correction for group documents.
  186. if (!empty($group_properties['directory'])) {
  187. $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
  188. }
  189. }
  190. $relative_url = '';
  191. for ($i = 0; $i < ($count_dir); $i++) {
  192. $relative_url .= '../';
  193. }
  194. // We do this in order to avoid the condition in html_editor.php ==> if ($this -> fck_editor->Config['CreateDocumentWebDir']=='' || $this -> fck_editor->Config['CreateDocumentDir']== '')
  195. if ($relative_url== '') {
  196. $relative_url = '/';
  197. }
  198. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  199. $html_editor_config = array(
  200. 'ToolbarSet' => ($is_allowed_to_edit ? 'Documents' :'DocumentsStudent'),
  201. 'Width' => '100%',
  202. 'Height' => '500',
  203. 'FullPage' => true,
  204. 'InDocument' => true,
  205. 'CreateDocumentDir' => $relative_url,
  206. 'CreateDocumentWebDir' => (empty($group_properties['directory']))
  207. ? api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'
  208. : api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/',
  209. 'BaseHref' => api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir
  210. );
  211. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  212. if (!is_dir($filepath)) {
  213. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  214. $dir = '/';
  215. }
  216. $to_group_id = 0;
  217. if (!$is_certificate_mode) {
  218. if (api_is_in_group()) {
  219. $req_gid = '&amp;gidReq='.api_get_group_id();
  220. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".api_get_group_id(), "name" => get_lang('GroupSpace'));
  221. $noPHP_SELF = true;
  222. $to_group_id = api_get_group_id();
  223. $path = explode('/', $dir);
  224. if ('/'.$path[1] != $group_properties['directory']) {
  225. api_not_allowed(true);
  226. }
  227. }
  228. $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents'));
  229. } else {
  230. $interbreadcrumb[]= array ( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  231. }
  232. if (!$is_allowed_in_course) {
  233. api_not_allowed(true);
  234. }
  235. 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()))) {
  236. api_not_allowed(true);
  237. }
  238. /* Header */
  239. event_access_tool(TOOL_DOCUMENT);
  240. $display_dir = $dir;
  241. if (isset ($group_properties)) {
  242. $display_dir = explode('/', $dir);
  243. unset ($display_dir[0]);
  244. unset ($display_dir[1]);
  245. $display_dir = implode('/', $display_dir);
  246. }
  247. // Create a new form
  248. $form = new FormValidator('create_document','post',api_get_self().'?dir='.Security::remove_XSS(urlencode($dir)).'&selectcat='.Security::remove_XSS($_GET['selectcat']));
  249. // form title
  250. $form->addElement('header', '', $nameTools);
  251. if ($is_certificate_mode) {//added condition for certicate in gradebook
  252. $form->addElement('hidden','certificate','true',array('id'=>'certificate'));
  253. if (isset($_GET['selectcat']))
  254. $form->addElement('hidden','selectcat', intval($_GET['selectcat']));
  255. }
  256. $renderer = & $form->defaultRenderer();
  257. // Hidden element with current directory
  258. $form->addElement('hidden', 'id');
  259. $default['id'] = $folder_id;
  260. // Filename
  261. $form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"');
  262. /**
  263. * Check if a document width the choosen filename allready exists
  264. */
  265. function document_exists($filename) {
  266. global $filepath;
  267. $filename = addslashes(trim($filename));
  268. $filename = Security::remove_XSS($filename);
  269. $filename = replace_dangerous_char($filename);
  270. $filename = disable_dangerous_file($filename);
  271. return !file_exists($filepath.$filename.'.html');
  272. }
  273. // Change the default renderer for the filename-field to display the dir and extension
  274. /*
  275. $renderer = & $form->defaultRenderer();
  276. */
  277. //$filename_template = str_replace('{element}', "<tt>$display_dir</tt> {element} <tt>.html</tt>", $renderer->_elementTemplate);
  278. $filename_template = str_replace('{element}', '{element}', $renderer->_elementTemplate); // TODO: What is the point of this statement?
  279. $renderer->setElementTemplate($filename_template, 'filename');
  280. // Initialize group array
  281. $group = array();
  282. // If allowed, add element for document title
  283. if (api_get_setting('use_document_title') == 'true') {
  284. $group[]=$form->createElement('text','title',get_lang('Title'),'class="input_titles" id="document_title"');
  285. // Added by Ivan Tcholakov, 10-OCT-2009.
  286. $form->addElement('hidden', 'filename', '', array('id' => 'filename'));
  287. //
  288. } else {
  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. // Added by Ivan Tcholakov, 10-OCT-2009.
  292. $form->addElement('hidden', 'title', '', array('id' => 'title'));
  293. }
  294. // Show read-only box only in groups
  295. if (!empty($_SESSION['_gid'])) {
  296. $group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
  297. }
  298. // Add group to the form
  299. if ($is_certificate_mode)
  300. $form->addGroup($group, 'filename_group', get_lang('CertificateName') ,'&nbsp;&nbsp;&nbsp;', false);
  301. else
  302. $form->addGroup($group, 'filename_group', api_get_setting('use_document_title') == 'true' ? get_lang('Title') : get_lang('FileName') ,'&nbsp;&nbsp;&nbsp;', false);
  303. $form->addRule('filename_group', get_lang('ThisFieldIsRequired'), 'required');
  304. if (api_get_setting('use_document_title') == 'true') {
  305. $form->addGroupRule('filename_group', array(
  306. 'title' => array(
  307. array(get_lang('ThisFieldIsRequired'), 'required'),
  308. array(get_lang('FileExists'),'callback', 'document_exists')
  309. )
  310. ));
  311. } else {
  312. $form->addGroupRule('filename_group', array(
  313. 'filename' => array(
  314. array(get_lang('ThisFieldIsRequired'), 'required'),
  315. array(get_lang('FileExists'),'callback', 'document_exists')
  316. )
  317. ));
  318. }
  319. $current_session_id = api_get_session_id();
  320. // HTML-editor
  321. $renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'content');
  322. $form->add_html_editor('content','', false, false, $html_editor_config);
  323. // Comment-field
  324. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  325. // If we are not in the certificates creation, display a folder chooser for the
  326. // new document created
  327. if (!$is_certificate_mode && !is_my_shared_folder($_user['user_id'], $dir, $current_session_id)) {
  328. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  329. //$parent_select -> addOption(get_lang('HomeDirectory'), '/');
  330. $parent_select = $form->addElement('select', 'curdirpath', get_lang('DestinationDirectory'));
  331. // Following two conditions copied from document.inc.php::build_directory_selector()
  332. $folder_titles = array();
  333. if (api_get_setting('use_document_title') == 'true') {
  334. if (is_array($folders)) {
  335. $escaped_folders = array();
  336. foreach ($folders as $key => & $val) {
  337. //Hide some folders
  338. if ($val=='/HotPotatoes_files' || $val=='/certificates' || basename($val)=='css'){
  339. continue;
  340. }
  341. //Admin setting for Hide/Show the folders of all users
  342. if (api_get_setting('show_users_folders') == 'false' && (strstr($val, '/shared_folder') || strstr($val, 'shared_folder_session_'))){
  343. continue;
  344. }
  345. //Admin setting for Hide/Show Default folders to all users
  346. if (api_get_setting('show_default_folders') == 'false' && ($val=='/images' || $val=='/flash' || $val=='/audio' || $val=='/video' || strstr($val, '/images/gallery') || $val=='/video/flv')){
  347. continue;
  348. }
  349. //Admin setting for Hide/Show chat history folder
  350. if (api_get_setting('show_chat_folder') == 'false' && $val=='/chat_files'){
  351. continue;
  352. }
  353. $escaped_folders[$key] = Database::escape_string($val);
  354. }
  355. $folder_sql = implode("','", $escaped_folders);
  356. $doc_table = Database::get_course_table(TABLE_DOCUMENT);
  357. $sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')";
  358. $res = Database::query($sql);
  359. $folder_titles = array();
  360. while ($obj = Database::fetch_object($res)) {
  361. $folder_titles[$obj->path] = $obj->title;
  362. }
  363. }
  364. } else {
  365. if (is_array($folders)) {
  366. foreach ($folders as & $folder) {
  367. $folder_titles[$folder] = basename($folder);
  368. }
  369. }
  370. }
  371. if (empty($group_dir)) {
  372. $parent_select -> addOption(get_lang('HomeDirectory'), '/');
  373. if (is_array($folders)) {
  374. foreach ($folders as & $folder) {
  375. //Hide some folders
  376. if ($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css'){
  377. continue;
  378. }
  379. //Admin setting for Hide/Show the folders of all users
  380. if (api_get_setting('show_users_folders') == 'false' && (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))){
  381. continue;
  382. }
  383. //Admin setting for Hide/Show Default folders to all users
  384. if (api_get_setting('show_default_folders') == 'false' && ($folder=='/images' || $folder=='/flash' || $folder=='/audio' || $folder=='/video' || strstr($folder, '/images/gallery') || $folder=='/video/flv')){
  385. continue;
  386. }
  387. //Admin setting for Hide/Show chat history folder
  388. if (api_get_setting('show_chat_folder') == 'false' && $folder=='/chat_files'){
  389. continue;
  390. }
  391. $selected = (substr($dir,0,-1) == $folder) ? ' selected="selected"' : '';
  392. $path_parts = explode('/', $folder);
  393. $folder_titles[$folder] = cut($folder_titles[$folder], 80);
  394. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$folder_titles[$folder];
  395. $parent_select -> addOption($label, $folder);
  396. if ($selected != '') {
  397. $parent_select->setSelected($folder);
  398. }
  399. }
  400. }
  401. } else {
  402. foreach ($folders as & $folder) {
  403. $selected = (substr($dir,0,-1)==$folder) ? ' selected="selected"' : '';
  404. $label = $folder_titles[$folder];
  405. if ($folder == $group_dir) {
  406. $label = '/ ('.get_lang('HomeDirectory').')';
  407. } else {
  408. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  409. $label = cut($label, 80);
  410. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  411. }
  412. $parent_select -> addOption($label, $folder);
  413. if ($selected != '') {
  414. $parent_select->setSelected($folder);
  415. }
  416. }
  417. }
  418. }
  419. //$form->addElement('textarea', 'comment', get_lang('Comment'), array ('rows' => 5, 'cols' => 50));
  420. if ($is_certificate_mode)
  421. $form->addElement('style_submit_button', 'submit', get_lang('CreateCertificate'), 'class="save"');
  422. else
  423. $form->addElement('style_submit_button', 'submit', get_lang('langCreateDoc'), 'class="save"');
  424. $form->setDefaults($default);
  425. // If form validates -> save the new document
  426. if ($form->validate()) {
  427. $values = $form->exportValues();
  428. $readonly = isset($values['readonly']) ? 1 : 0;
  429. $values['title'] = trim($values['title']);
  430. if (!empty($values['curdirpath'])) {
  431. $dir = $values['curdirpath'];
  432. }
  433. if ($dir[strlen($dir) - 1] != '/') {
  434. $dir .= '/';
  435. }
  436. if (api_get_setting('use_document_title') != 'true') {
  437. $values['title'] = $values['filename'];
  438. } else {
  439. $values['filename'] = $values['title'];
  440. }
  441. $values['filename'] = addslashes(trim($values['filename']));
  442. $values['filename'] = Security::remove_XSS($values['filename']);
  443. $values['filename'] = replace_dangerous_char($values['filename']);
  444. $values['filename'] = disable_dangerous_file($values['filename']);
  445. $filename = $values['filename'];
  446. $title = $values['title'];
  447. $extension = 'html';
  448. $content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
  449. if (strpos($content, '/css/frames.css') === false) {
  450. $content = str_replace('</head>', '<style> body{margin:10px;}</style> <link rel="stylesheet" href="./css/frames.css" type="text/css" /></head>', $content);
  451. }
  452. if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
  453. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].'/courses/', $content);
  454. // change the path of mp3 to absolute
  455. // first regexp deals with ../../../ urls
  456. // Disabled by Ivan Tcholakov.
  457. //$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  458. //second regexp deals with audio/ urls
  459. // Disabled by Ivan Tcholakov.
  460. //$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  461. fputs($fp, $content);
  462. fclose($fp);
  463. chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
  464. if (!is_dir($filepath.'css')) {
  465. mkdir($filepath.'css', api_get_permissions_for_new_directories());
  466. $doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
  467. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id);
  468. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
  469. }
  470. if (!is_file($filepath.'css/frames.css')) {
  471. // Make a copy of the current css for the new document
  472. copy(api_get_path(SYS_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css', $filepath.'css/frames.css');
  473. $doc_id = add_document($_course, $dir.'css/frames.css', 'file', filesize($filepath.'css/frames.css'), 'frames.css');
  474. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], null, null, null, null, $current_session_id);
  475. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
  476. }
  477. $file_size = filesize($filepath.$filename.'.'.$extension);
  478. $save_file_path = $dir.$filename.'.'.$extension;
  479. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $title, null, $readonly);
  480. if ($document_id) {
  481. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id, null, null, null, $current_session_id);
  482. // Update parent folders
  483. item_property_update_on_folder($_course, $dir, $_user['user_id']);
  484. $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
  485. $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
  486. if ($new_comment || $new_title) {
  487. $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  488. $ct = '';
  489. if ($new_comment)
  490. $ct .= ", comment='$new_comment'";
  491. if ($new_title)
  492. $ct .= ", title='$new_title'";
  493. Database::query("UPDATE $TABLE_DOCUMENT SET".substr($ct, 1)." WHERE id = '$document_id'");
  494. }
  495. $dir= substr($dir,0,-1);
  496. $selectcat = '';
  497. if (isset($_REQUEST['selectcat']))
  498. $selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']);
  499. $certificate_condition = '';
  500. if ($is_certificate_mode) {
  501. $certificate_condition = '&certificate=true';
  502. }
  503. header('Location: document.php?id='.$folder_id.$selectcat.$certificate_condition);
  504. exit ();
  505. } else {
  506. Display :: display_header($nameTools, 'Doc');
  507. Display :: display_error_message(get_lang('Impossible'));
  508. Display :: display_footer();
  509. }
  510. } else {
  511. Display :: display_header($nameTools, 'Doc');
  512. Display :: display_error_message(get_lang('Impossible'));
  513. Display :: display_footer();
  514. }
  515. } else {
  516. // Interbreadcrumb for the current directory root path
  517. // Copied from document.php
  518. $dir_array = explode('/', $dir);
  519. $array_len = count($dir_array);
  520. /*
  521. TODO:check and delete this code
  522. if (!$is_certificate_mode) {
  523. if ($array_len > 1) {
  524. if (empty($_SESSION['_gid'])) {
  525. $url_dir = 'document.php?&curdirpath=/';
  526. $interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory'));
  527. }
  528. }
  529. }
  530. */
  531. // Interbreadcrumb for the current directory root path
  532. if (empty($document_data['parents'])) {
  533. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  534. } else {
  535. foreach($document_data['parents'] as $document_sub_data) {
  536. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  537. }
  538. }
  539. Display :: display_header($nameTools, "Doc");
  540. //api_display_tool_title($nameTools);
  541. // actions
  542. echo '<div class="actions">';
  543. // link back to the documents overview
  544. if ($is_certificate_mode)
  545. echo '<a href="document.php?certificate=true&id='.$folder_id.'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'','32').'</a>';
  546. else
  547. 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>';
  548. echo '</div>';
  549. if ($is_certificate_mode) {
  550. $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id());
  551. $str_info = '';
  552. foreach ($all_information_by_create_certificate[0] as $info_value) {
  553. $str_info.=$info_value.'<br/>';
  554. }
  555. $create_certificate = get_lang('CreateCertificateWithTags');
  556. Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info,false);
  557. }
  558. $form->display();
  559. Display :: display_footer();
  560. }