create_document.php 23 KB

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