create_document.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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. // Name of the language file that needs to be included
  9. $language_file = array('document', 'gradebook');
  10. require_once '../inc/global.inc.php';
  11. $_SESSION['whereami'] = 'document/create';
  12. $this_section = SECTION_COURSES;
  13. $htmlHeadXtra[] = '
  14. <script>
  15. var hide_bar = function() {
  16. $("#template_col").hide();
  17. $("#doc_form").removeClass("span9");
  18. $("#doc_form").addClass("span11");
  19. $("#hide_bar_template").css({"background-image" : \'url("../img/hide2.png")\'})
  20. }
  21. $(document).ready(function() {
  22. if ($(window).width() <= 785 ) {
  23. hide_bar();
  24. }
  25. $("#hide_bar_template").toggle(
  26. function() {
  27. hide_bar();
  28. },
  29. function() {
  30. $("#template_col").show();
  31. $("#doc_form").removeClass("span11");
  32. $("#doc_form").addClass("span9");
  33. $(this).css("background-image", \'url("../img/hide0.png")\');
  34. }
  35. );
  36. });
  37. function InnerDialogLoaded() {
  38. var isIE = (navigator.appVersion.indexOf(\'MSIE\') != -1) ? true : false ;
  39. var EditorFrame = null ;
  40. if ( !isIE ) {
  41. EditorFrame = window.frames[0] ;
  42. } else {
  43. // For this dynamic page window.frames[0] enumerates frames in a different order in IE.
  44. // We need a sure method to locate the frame that contains the online editor.
  45. for ( var i = 0, n = window.frames.length ; i < n ; i++ ) {
  46. if ( window.frames[i].location.toString().indexOf(\'InstanceName=content\') != -1 ) {
  47. EditorFrame = window.frames[i] ;
  48. }
  49. }
  50. }
  51. if ( !EditorFrame ) {
  52. return null ;
  53. }
  54. var B = new EditorFrame.FCKToolbarButton(\'Templates\', EditorFrame.FCKLang.Templates);
  55. return B.ClickFrame();
  56. };
  57. var temp=false;
  58. var temp2=false;
  59. var load_default_template = '. ((isset($_POST['submit']) || empty($_SERVER['QUERY_STRING'])) ? 'false' : 'true' ) .';
  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 different ways to get the text (without HTML markups).
  78. // It is browser specific.
  79. // If Internet Explorer.
  80. if( document.all ) {
  81. contentText = oDOM.body.innerText ;
  82. } else {
  83. // If Gecko.
  84. var r = oDOM.createRange() ;
  85. r.selectNodeContents( oDOM.body ) ;
  86. contentText = r.toString() ;
  87. }
  88. var index=contentText.indexOf("/*<![CDATA");
  89. contentText=contentText.substr(0,index);
  90. // Compose title if there is none
  91. contentTextArray = contentText.split(\' \') ;
  92. var x=0;
  93. for(x=0; (x<5 && x<contentTextArray.length); x++) {
  94. if(x < 4) {
  95. bestandsnaamNieuw += contentTextArray[x] + \' \';
  96. } else {
  97. bestandsnaamNieuw += contentTextArray[x];
  98. }
  99. }
  100. }
  101. temp=true;
  102. }
  103. function trim(s) {
  104. while(s.substring(0,1) == \' \') {
  105. s = s.substring(1,s.length);
  106. }
  107. while(s.substring(s.length-1,s.length) == \' \') {
  108. s = s.substring(0,s.length-1);
  109. }
  110. return s;
  111. }
  112. function setFocus() {
  113. $("#document_title").focus();
  114. }
  115. $(window).load(function () {
  116. setFocus();
  117. });
  118. </script>';
  119. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  120. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
  121. //I'm in the certification module?
  122. $is_certificate_mode = false;
  123. if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
  124. $is_certificate_mode = true;
  125. }
  126. if ($is_certificate_mode) {
  127. $nameTools = get_lang('CreateCertificate');
  128. } else {
  129. $nameTools = get_lang('CreateDocument');
  130. }
  131. /* Constants and variables */
  132. $doc_table = Database::get_course_table(TABLE_DOCUMENT);
  133. $course_id = api_get_course_int_id();
  134. $courseCode = api_get_course_id();
  135. $sessionId = api_get_session_id();
  136. $userId = api_get_user_id();
  137. $_course = api_get_course_info();
  138. $groupId = api_get_group_id();
  139. $document_data = DocumentManager::get_document_data_by_id(
  140. $_REQUEST['id'],
  141. $courseCode,
  142. true,
  143. 0
  144. );
  145. if (!empty($sessionId) && empty($document_data)) {
  146. $document_data = DocumentManager::get_document_data_by_id(
  147. $_REQUEST['id'],
  148. $courseCode,
  149. true,
  150. $sessionId
  151. );
  152. }
  153. if (empty($document_data)) {
  154. if (api_is_in_group()) {
  155. $group_properties = GroupManager::get_group_properties($groupId);
  156. $document_id = DocumentManager::get_document_id($_course, $group_properties['directory']);
  157. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  158. $dir = $document_data['path'];
  159. $folder_id = $document_data['id'];
  160. } else {
  161. $dir = '/';
  162. $folder_id = 0;
  163. }
  164. } else {
  165. $folder_id = $document_data['id'];
  166. $dir = $document_data['path'];
  167. }
  168. /* MAIN CODE */
  169. // Please, do not modify this dirname formatting
  170. if (strstr($dir, '..')) {
  171. $dir = '/';
  172. }
  173. if ($dir[0] == '.') {
  174. $dir = substr($dir, 1);
  175. }
  176. if ($dir[0] != '/') {
  177. $dir = '/'.$dir;
  178. }
  179. if ($dir[strlen($dir) - 1] != '/') {
  180. $dir .= '/';
  181. }
  182. if ($is_certificate_mode) {
  183. $document_id = DocumentManager::get_document_id(api_get_course_info(), '/certificates');
  184. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
  185. $folder_id = $document_data['id'];
  186. $dir = '/certificates/';
  187. }
  188. // Configuration for the FCKEDITOR
  189. $doc_tree = explode('/', $dir);
  190. $count_dir = count($doc_tree) -2; // "2" because at the begin and end there are 2 "/"
  191. if (api_is_in_group()) {
  192. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  193. // Level correction for group documents.
  194. if (!empty($group_properties['directory'])) {
  195. $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
  196. }
  197. }
  198. $relative_url = '';
  199. for ($i = 0; $i < ($count_dir); $i++) {
  200. $relative_url .= '../';
  201. }
  202. /* We do this in order to avoid the condition in html_editor.php ==> if
  203. ($this -> fck_editor->Config['CreateDocumentWebDir']=='' || $this -> fck_editor->Config['CreateDocumentDir']== '')*
  204. */
  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. if ($is_certificate_mode) {
  222. $html_editor_config['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/';
  223. $html_editor_config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/';
  224. $html_editor_config['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir;
  225. }
  226. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  227. if (!is_dir($filepath)) {
  228. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  229. $dir = '/';
  230. }
  231. $to_group_id = 0;
  232. if (!$is_certificate_mode) {
  233. $req_gid = null;
  234. if (api_is_in_group()) {
  235. $req_gid = '&amp;gidReq='.api_get_group_id();
  236. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".api_get_group_id(), "name" => get_lang('GroupSpace'));
  237. $noPHP_SELF = true;
  238. $to_group_id = api_get_group_id();
  239. $path = explode('/', $dir);
  240. if ('/'.$path[1] != $group_properties['directory']) {
  241. api_not_allowed(true);
  242. }
  243. }
  244. $interbreadcrumb[] = array("url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents'));
  245. } else {
  246. $interbreadcrumb[]= array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  247. }
  248. if (!$is_allowed_in_course) {
  249. api_not_allowed(true);
  250. }
  251. if (!($is_allowed_to_edit ||
  252. $_SESSION['group_member_with_upload_rights'] ||
  253. is_my_shared_folder($userId, $dir, api_get_session_id()))
  254. ) {
  255. api_not_allowed(true);
  256. }
  257. /* Header */
  258. event_access_tool(TOOL_DOCUMENT);
  259. $display_dir = $dir;
  260. if (isset($group_properties)) {
  261. $display_dir = explode('/', $dir);
  262. unset($display_dir[0]);
  263. unset($display_dir[1]);
  264. $display_dir = implode('/', $display_dir);
  265. }
  266. $select_cat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : null;
  267. $curDirPath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
  268. // Create a new form
  269. $form = new FormValidator(
  270. 'create_document',
  271. 'post',
  272. api_get_self().'?'.api_get_cidreq().'&dir='.Security::remove_XSS(urlencode($dir)).'&selectcat='.$select_cat,
  273. null,
  274. array('class' =>'form-vertical')
  275. );
  276. // form title
  277. $form->addElement('header', $nameTools);
  278. if ($is_certificate_mode) {//added condition for certicate in gradebook
  279. $form->addElement('hidden','certificate','true',array('id'=>'certificate'));
  280. if (isset($_GET['selectcat'])) {
  281. $form->addElement('hidden','selectcat', $select_cat);
  282. }
  283. }
  284. // Hidden element with current directory
  285. $form->addElement('hidden', 'id');
  286. $defaults = array();
  287. $defaults['id'] = $folder_id;
  288. // Filename
  289. $form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"');
  290. /**
  291. * Check if a document width the chosen filename already exists
  292. */
  293. function document_exists($filename) {
  294. global $dir;
  295. // Clean up the name, only ASCII characters should stay. (and strict)
  296. $cleanName = replace_dangerous_char($filename, 'strict');
  297. // No "dangerous" files
  298. $cleanName = disable_dangerous_file($cleanName);
  299. return !DocumentManager::documentExists(
  300. $dir.$cleanName.'.html',
  301. api_get_course_info(),
  302. api_get_session_id(),
  303. api_get_group_id()
  304. );
  305. /*$filename = addslashes(trim($filename));
  306. $filename = Security::remove_XSS($filename);
  307. $filename = replace_dangerous_char($filename);
  308. $filename = disable_dangerous_file($filename);
  309. return !file_exists($filepath.$filename.'.html');*/
  310. }
  311. // Add group to the form
  312. if ($is_certificate_mode) {
  313. $form->addElement('text', 'title', get_lang('CertificateName'), 'class="span4" id="document_title"');
  314. } else {
  315. $form->addElement('text', 'title', get_lang('Title'), 'class="span4" id="document_title"');
  316. }
  317. // Show read-only box only in groups
  318. if (!empty($_SESSION['_gid'])) {
  319. $group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
  320. }
  321. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  322. $form->addRule('title', get_lang('FileExists'), 'callback', 'document_exists');
  323. $current_session_id = api_get_session_id();
  324. $form->add_html_editor('content','', false, false, $html_editor_config);
  325. // Comment-field
  326. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  327. // If we are not in the certificates creation, display a folder chooser for the
  328. // new document created
  329. if (!$is_certificate_mode && !is_my_shared_folder($userId, $dir, $current_session_id)) {
  330. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
  331. $parent_select = $form->addElement('select', 'curdirpath', array(null, get_lang('DestinationDirectory')));
  332. // Following two conditions copied from document.inc.php::build_directory_selector()
  333. $folder_titles = array();
  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. $sql = "SELECT * FROM $doc_table WHERE c_id = $course_id AND filetype='folder' AND path IN ('".$folder_sql."')";
  357. $res = Database::query($sql);
  358. $folder_titles = array();
  359. while ($obj = Database::fetch_object($res)) {
  360. $folder_titles[$obj->path] = $obj->title;
  361. }
  362. }
  363. if (empty($group_dir)) {
  364. $parent_select -> addOption(get_lang('HomeDirectory'), '/');
  365. if (is_array($folders)) {
  366. foreach ($folders as & $folder) {
  367. //Hide some folders
  368. if ($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css'){
  369. continue;
  370. }
  371. //Admin setting for Hide/Show the folders of all users
  372. if (api_get_setting('show_users_folders') == 'false' && (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))){
  373. continue;
  374. }
  375. //Admin setting for Hide/Show Default folders to all users
  376. if (api_get_setting('show_default_folders') == 'false' && ($folder=='/images' || $folder=='/flash' || $folder=='/audio' || $folder=='/video' || strstr($folder, '/images/gallery') || $folder=='/video/flv')){
  377. continue;
  378. }
  379. //Admin setting for Hide/Show chat history folder
  380. if (api_get_setting('show_chat_folder') == 'false' && $folder=='/chat_files'){
  381. continue;
  382. }
  383. $selected = (substr($dir,0,-1) == $folder) ? ' selected="selected"' : '';
  384. $path_parts = explode('/', $folder);
  385. $folder_titles[$folder] = cut($folder_titles[$folder], 80);
  386. $space_counter =count($path_parts) - 2;
  387. if ($space_counter > 0) {
  388. $label = str_repeat('&nbsp;&nbsp;&nbsp;', $space_counter).' &mdash; '.$folder_titles[$folder];
  389. } else {
  390. $label = ' &mdash; '.$folder_titles[$folder];
  391. }
  392. $parent_select -> addOption($label, $folder);
  393. if ($selected != '') {
  394. $parent_select->setSelected($folder);
  395. }
  396. }
  397. }
  398. } else {
  399. foreach ($folders as & $folder) {
  400. $selected = (substr($dir,0,-1)==$folder) ? ' selected="selected"' : '';
  401. $label = $folder_titles[$folder];
  402. if ($folder == $group_dir) {
  403. $label = '/ ('.get_lang('HomeDirectory').')';
  404. } else {
  405. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  406. $label = cut($label, 80);
  407. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  408. }
  409. $parent_select -> addOption($label, $folder);
  410. if ($selected != '') {
  411. $parent_select->setSelected($folder);
  412. }
  413. }
  414. }
  415. }
  416. if ($is_certificate_mode)
  417. $form->addElement('style_submit_button', 'submit', get_lang('CreateCertificate'), 'class="save"');
  418. else
  419. $form->addElement('style_submit_button', 'submit', get_lang('CreateDoc'), 'class="save"');
  420. $form->setDefaults($defaults);
  421. // If form validates -> save the new document
  422. if ($form->validate()) {
  423. $values = $form->exportValues();
  424. $readonly = isset($values['readonly']) ? 1 : 0;
  425. $values['title'] = trim($values['title']);
  426. if ($dir[strlen($dir) - 1] != '/') {
  427. $dir .= '/';
  428. }
  429. // Setting the filename
  430. $filename = $values['title'];
  431. $filename = addslashes(trim($filename));
  432. $filename = Security::remove_XSS($filename);
  433. $filename = replace_dangerous_char($filename);
  434. $filename = disable_dangerous_file($filename);
  435. $filename .= DocumentManager::getDocumentSuffix(
  436. $_course,
  437. api_get_session_id(),
  438. api_get_group_id()
  439. );
  440. // Setting the title
  441. $title = $values['title'];
  442. // Setting the extension
  443. $extension = 'html';
  444. $content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
  445. if (strpos($content, '/css/frames.css') == false) {
  446. $content = str_replace('</head>', '<link rel="stylesheet" href="./css/frames.css" type="text/css" /><style> body{margin:50px;}</style></head>', $content);
  447. }
  448. // Don't create file with the same name.
  449. if (file_exists($filepath.$filename.'.'.$extension)) {
  450. Display:: display_header($nameTools, 'Doc');
  451. Display:: display_error_message(get_lang('FileExists').' '.$title, false);
  452. Display:: display_footer();
  453. exit;
  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', $userId, null, null, null, null, $current_session_id);
  471. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, 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', $userId, null, null, null, null, $current_session_id);
  478. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, 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(
  483. $_course,
  484. $save_file_path,
  485. 'file',
  486. $file_size,
  487. $title,
  488. null,
  489. $readonly
  490. );
  491. if ($document_id) {
  492. api_item_property_update(
  493. $_course,
  494. TOOL_DOCUMENT,
  495. $document_id,
  496. 'DocumentAdded',
  497. $userId,
  498. $to_group_id,
  499. null,
  500. null,
  501. null,
  502. $current_session_id
  503. );
  504. // Update parent folders
  505. item_property_update_on_folder($_course, $dir, $userId);
  506. $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
  507. $new_comment = Database::escape_string($new_comment);
  508. $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
  509. $new_title = htmlspecialchars($new_title);
  510. $new_title = Database::escape_string($new_title);
  511. if ($new_comment || $new_title) {
  512. $ct = '';
  513. if ($new_comment)
  514. $ct .= ", comment='$new_comment'";
  515. if ($new_title)
  516. $ct .= ", title='$new_title'";
  517. Database::query("UPDATE $doc_table SET".substr($ct, 1)." WHERE c_id = $course_id AND 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. $certificate_condition = '';
  524. if ($is_certificate_mode) {
  525. $df = DocumentManager::get_default_certificate_id($_course['code']);
  526. if (!isset($df)) {
  527. DocumentManager::attach_gradebook_certificate ($_course['code'],$document_id);
  528. }
  529. $certificate_condition = '&certificate=true&curdirpath=/certificates';
  530. }
  531. header('Location: document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition);
  532. exit();
  533. } else {
  534. Display :: display_header($nameTools, 'Doc');
  535. Display :: display_error_message(get_lang('Impossible'));
  536. Display :: display_footer();
  537. }
  538. } else {
  539. Display :: display_header($nameTools, 'Doc');
  540. Display :: display_error_message(get_lang('Impossible'));
  541. Display :: display_footer();
  542. }
  543. } else {
  544. // Interbreadcrumb for the current directory root path
  545. // Copied from document.php
  546. $dir_array = explode('/', $dir);
  547. $array_len = count($dir_array);
  548. // Interbreadcrumb for the current directory root path
  549. if (empty($document_data['parents'])) {
  550. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  551. } else {
  552. foreach($document_data['parents'] as $document_sub_data) {
  553. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  554. }
  555. }
  556. Display :: display_header($nameTools, "Doc");
  557. // actions
  558. echo '<div class="actions">';
  559. // link back to the documents overview
  560. if ($is_certificate_mode)
  561. echo '<a href="document.php?certificate=true&id='.$folder_id.'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.
  562. Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  563. else
  564. echo '<a href="document.php?curdirpath='.Security::remove_XSS($dir).'">'.
  565. Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  566. echo '</div>';
  567. if ($is_certificate_mode) {
  568. $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_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. // HTML-editor
  577. echo '<div class="row-fluid" style="overflow:hidden">
  578. <div id="template_col" class="span2" style="width:162px">
  579. <div id="frmModel" style="overflow: visible;"></div>
  580. </div>
  581. <div id="hide_bar_template"></div>
  582. <div id="doc_form" class="span9">
  583. '.$form->return_form().'
  584. </div>
  585. </div>';
  586. Display :: display_footer();
  587. }