Dokeos PHP Cross Reference Learning Management Systems

Source: /main/document/create_document.php - 542 lines - 25362 bytes - Summary - Text - Print

Description: This file allows creating new html documents with an online WYSIWYG html editor.

   1  <?php
   2  
   3  /* For licensing terms, see /dokeos_license.txt */
   4  
   5  /**
   6  ==============================================================================
   7  *    This file allows creating new html documents with an online WYSIWYG html
   8  *    editor.
   9  *    @package dokeos.document
  10  ==============================================================================
  11  */
  12  
  13  // name of the language file that needs to be included
  14  $language_file = array('document','gradebook');
  15  
  16  // setting the help
  17  $help_content = 'createdocument';
  18  
  19  // include the global Dokeos file
  20  require_once  '../inc/global.inc.php';
  21  
  22  // include additional libraries
  23  require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  24  require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  25  require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  26  require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  27  require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  28  
  29  // section (for the tabs)
  30  $this_section = SECTION_COURSES;
  31  
  32  // Access restrictions
  33  api_protect_course_script(true);
  34  
  35  define('DOKEOS_DOCUMENT', true);
  36  
  37  $_SESSION['whereami'] = 'document/create';
  38  // Add additional javascript, css
  39  $htmlHeadXtra[] = '<script type="text/javascript">
  40    $(document).ready(function(){
  41      $(".row").attr("style","padding:0px;");
  42    });
  43  </script> ';
  44  
  45  if (isset($_REQUEST['certificate'])) {
  46      $nameTools = get_lang('CreateCertificate');    
  47  } else {
  48      $nameTools = get_lang('CreateDocument');    
  49  }
  50  
  51  $fck_attribute['Width'] = '100%';
  52  $fck_attribute['Height'] = '600';
  53  
  54  $fck_attribute['Config']['FullPage'] = true;
  55  if(!api_is_allowed_to_edit()){
  56      $fck_attribute['Config']['UserStatus'] = 'student';
  57      $fck_attribute['ToolbarSet'] = 'Documents_Student';
  58  } else {
  59      $fck_attribute['ToolbarSet'] = 'Documents';
  60  }
  61  
  62  /*
  63  -----------------------------------------------------------
  64      Constants and variables
  65  -----------------------------------------------------------
  66  */
  67  $dir = isset($_GET['dir']) ? Security::remove_XSS($_GET['dir']) : Security::remove_XSS($_POST['dir']); // please do not modify this dirname formatting
  68  
  69  /*
  70  ==============================================================================
  71          MAIN CODE
  72  ==============================================================================
  73  */
  74  
  75  if (api_is_in_group()) {
  76      $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
  77  }
  78  
  79  if (strstr($dir, '..')) {
  80      $dir = '/';
  81  }
  82  
  83  if ($dir[0] == '.') {
  84      $dir = substr($dir, 1);
  85  }
  86  
  87  if ($dir[0] != '/') {
  88      $dir = '/'.$dir;
  89  }
  90  
  91  if ($dir[strlen($dir) - 1] != '/') {
  92      $dir .= '/';
  93  }
  94  
  95  // Configuration for the FCKEDITOR
  96  $doc_tree= explode('/', $dir);
  97  $count_dir = count($doc_tree) -2; // "2" because at the begin and end there are 2 "/"
  98  // Level correction for group documents.
  99  if (!empty($group_properties['directory'])) {
 100      $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
 101  }
 102  $relative_url='';
 103  
 104  for($i=0;$i<($count_dir);$i++) {
 105      $relative_url.='../';    
 106  }
 107  
 108  // we do this in order to avoid the condition in html_editor.php ==> if ($this -> fck_editor->Config['CreateDocumentWebDir']=='' || $this -> fck_editor->Config['CreateDocumentDir']== '')
 109  if ($relative_url== '') {
 110      $relative_url = '/';
 111  }
 112  
 113  $html_editor_config = array(
 114      'ToolbarSet' => (api_is_allowed_to_edit() ? 'Documents' :'DocumentsStudent'),
 115      'Width' => '100%',
 116      'Height' => '650',
 117      'FullPage' => true,
 118      'InDocument' => true,
 119      'CreateDocumentDir' => $relative_url,
 120      'CreateDocumentWebDir' => (empty($group_properties['directory']))
 121          ? api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'
 122          : api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document'.$group_properties['directory'].'/',
 123      'BaseHref' => api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir
 124  );
 125  
 126  $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
 127  if (!is_dir($filepath)) {
 128      $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
 129      $dir = '/';
 130  }
 131  
 132  // create css folder if it doesn't exist
 133  $perm = api_get_setting('permissions_for_new_directories');
 134  $perm = octdec(!empty($perm)?$perm:'0770');
 135  $css_folder = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/css'; 
 136  if (!is_dir($css_folder)) {
 137          mkdir($css_folder);
 138          chmod($css_folder, $perm);
 139          $doc_id = add_document($_course, '/css', 'folder', 0, 'css');
 140          api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
 141          api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
 142  }
 143  
 144  //I'm in the certification module?  
 145  $is_certificate_mode = false;
 146  $is_certificate_array = explode('/',$_GET['dir']);
 147  array_shift($is_certificate_array);
 148  if ($is_certificate_array[0]=='certificates') {
 149      $is_certificate_mode = true;
 150  }
 151  /**************************************************/
 152  $to_group_id = 0;
 153  if (!$is_certificate_mode) {
 154      if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
 155          $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
 156          $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace'));
 157          $noPHP_SELF = true;
 158          $to_group_id = $_SESSION['_gid'];
 159          $group = GroupManager :: get_group_properties($to_group_id);
 160          $path = explode('/', $dir);
 161          if ('/'.$path[1] != $group['directory']) {
 162              api_not_allowed(true);
 163          }    
 164      }
 165      $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".Security::remove_XSS($_GET['dir']).$req_gid, "name" => get_lang('Documents'));
 166  } else {
 167      $interbreadcrumb[]= array (    'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));    
 168  }
 169  
 170  if (!$is_allowed_in_course)
 171      api_not_allowed(true);
 172  
 173  $is_allowedToEdit = api_is_allowed_to_edit();
 174  if (!($is_allowedToEdit || $_SESSION['group_member_with_upload_rights'])) {
 175      api_not_allowed(true);
 176  }
 177  
 178  // tracking
 179  event_access_tool(TOOL_DOCUMENT);
 180  
 181  $display_dir = $dir;
 182  if (isset ($group)) {
 183      $display_dir = explode('/', $dir);
 184      unset ($display_dir[0]);
 185      unset ($display_dir[1]);
 186      $display_dir = implode('/', $display_dir);
 187  }
 188  
 189  // Create a new form
 190  $form = new FormValidator('create_document','post',api_get_self().'?'.api_get_cidreq().'&dir='.Security::remove_XSS($_GET['dir']).'&selectcat='.Security::remove_XSS($_GET['selectcat']));
 191  
 192  // form title
 193  //$form->addElement('header', '', $nameTools);
 194  if (isset($_REQUEST['certificate'])) {//added condition for certicate in gradebook
 195      $form->addElement('hidden','certificate','true',array('id'=>'certificate'));
 196      if (isset($_GET['selectcat']))
 197          $form->addElement('hidden','selectcat',intval($_GET['selectcat']));    
 198      
 199  }
 200  $renderer = & $form->defaultRenderer();
 201  
 202  // Hidden element with current directory
 203  $form->addElement('hidden', 'dir');
 204  $default['dir'] = $dir;
 205  // Filename
 206  
 207  $form->addElement('hidden','title_edited','false','id="title_edited"');
 208  if (isset($_GET['tplid'])) {
 209    $form->addElement('hidden','is_template','1');
 210  } else {
 211    $form->addElement('hidden','is_template','0');
 212  }
 213  
 214  
 215  /**
 216   * Check if a document width the choosen filename allready exists
 217   */
 218  function document_exists($filename) {
 219      global $filepath;
 220      $filename = replace_dangerous_char($filename);
 221      return !file_exists($filepath.$filename.'.html');
 222  }
 223  
 224  // Change the default renderer for the filename-field to display the dir and extension
 225  /*
 226  $renderer = & $form->defaultRenderer();
 227  */
 228  //$filename_template = str_replace('{element}', "<tt>$display_dir</tt> {element} <tt>.html</tt>", $renderer->_elementTemplate);
 229  $filename_template = str_replace('{element}', "{element}", $renderer->_elementTemplate);
 230  $renderer->setElementTemplate($filename_template, 'filename');
 231  
 232  // initialize group array
 233  $group = array();
 234  // If allowed, add element for document title
 235  if (api_get_setting('use_document_title') == 'true') {    
 236      //$group[]= $form->add_textfield('title', get_lang('Title'),true,'class="input_titles" id="title"');
 237      // replace the     add_textfield with this    
 238      $form->addElement('text','title',get_lang('Title'),'class="focus" id="title" style="width:300px;"');
 239      //$form->applyFilter('title','trim');        
 240      //$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');        
 241      $form->addRule('title', get_lang('FileExists'), 'callback', 'document_exists');
 242  } else {        
 243      //$form->add_textfield('filename', get_lang('FileName'),true,'class="input_titles" id="filename"  onblur="check_if_still_empty()"');
 244      // replace the     add_textfield with this 
 245      $form->addElement('text','filename',get_lang('FileName'),'class="input_titles" id="filename" onblur="check_if_still_empty()"');
 246      //$form->applyFilter('filename','trim');    
 247      //$form->addRule('filename', get_lang('ThisFieldIsRequired'), 'required');                
 248      $form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists');
 249  }
 250  
 251  // This fix display problem of the button on I.E
 252  $margin_top = "margin-top:-28px;";
 253  if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {
 254     $margin_top = "";
 255  }
 256  if ($is_certificate_mode)
 257      $form->addElement('style_submit_button', 'submit', get_lang('CreateCertificate'), 'class="save" style="'.$margin_top.' margin-bottom:10px;"');
 258  else 
 259      $form->addElement('style_submit_button', 'submit', get_lang('Validate'), 'class="save" style="'.$margin_top.' margin-bottom:10px"');
 260  
 261  /* Show read-only box only in groups */
 262  if(!empty($_SESSION['_gid'])) {
 263      //$renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
 264      $group[]= $form->createElement('checkbox','readonly','',get_lang('ReadOnly'));
 265  }
 266  /*
 267  // add group to the form
 268  if ($is_certificate_mode)
 269      $form->addGroup($group, 'filename_group', get_lang('CertificateName') ,'&nbsp;&nbsp;&nbsp;', false);
 270  else
 271      $form->addGroup($group, 'filename_group', get_lang('FileName') ,'&nbsp;&nbsp;&nbsp;', false);
 272      
 273  $form->addRule('filename_group', get_lang('ThisFieldIsRequired'), 'required');
 274  
 275  if (api_get_setting('use_document_title') == 'true') {            
 276      $form->addGroupRule('filename_group', array(
 277        'title' => array(
 278          array(get_lang('ThisFieldIsRequired'), 'required'),       
 279          array(get_lang('FileExists'),'callback', 'document_exists')
 280          )
 281      ));
 282  } else {
 283      $form->addGroupRule('filename_group', array(
 284        'filename' => array(               
 285          array(get_lang('ThisFieldIsRequired'), 'required'),
 286          array(get_lang('FileExists'),'callback', 'document_exists')
 287          )
 288      ));        
 289  }*/
 290  
 291  //$form->addElement('style_submit_button', 'submit', get_lang('SaveDocument'), 'class="save"');
 292  
 293  // HTML-editor
 294  //$renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'content');
 295  //$form->addElement('html','<div style="display:block; height:525px; width:240px; position:absolute; top:50px; left:50px;"><table width="100%" cellpadding="3" cellspacing="3" border="1"><tr><td><a href="document.php?curdirpath='.Security::remove_XSS($_GET['dir']).'">'.Display::return_icon('go_previous_32.png',get_lang('Back'),array('style'=>'vertical-align:middle;')).'&nbsp;&nbsp;'.get_lang('Back').'</a></td></tr><tr><td align="center"><a href="javascript:callTplGallery()"><div class="actions" ><img src="'.api_get_path(WEB_IMG_PATH).'tools_wizard.png"></div></a></td></tr><tr><td align="center"><h4>Templates Gallery</h4></td></tr></table></div>');
 296  //$renderer->setElementTemplate('<div class="row"><div class="label" style="overflow: visible;"><table width="100%" cellpadding="3" cellspacing="3"><tr><td align="center"><a href="document.php?curdirpath='.Security::remove_XSS($_GET['dir']).'">'.Display::return_icon('go_previous_32.png',get_lang('Back'),array('style'=>'vertical-align:middle;')).'&nbsp;&nbsp;'.get_lang('Back').'</a></td></tr><tr><td align="center"><a href="javascript:callTplGallery()"><div class="actions" ><img src="'.api_get_path(WEB_IMG_PATH).'tools_wizard.png"></div></a></td></tr><tr><td align="center"><h4>Templates Gallery</h4></td></tr></table></div><div class="formw">{element}</div></div>', 'content');
 297  $renderer->setElementTemplate('<div class="row"><div style="width:100%;float:right;">{element}</div></div>', 'content');
 298  $form->add_html_editor('content','', false, false, $html_editor_config);
 299  // Comment-field
 300  //$form->addElement('textarea', 'comment', get_lang('Comment'), array ('rows' => 5, 'cols' => 50));
 301  if(isset($_REQUEST['tplid'])) {
 302      $table_sys_template = Database::get_main_table('system_template');
 303      $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);    
 304      $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
 305      $user_id = api_get_user_id();
 306          
 307      // setting some paths
 308      $img_dir = api_get_path(REL_CODE_PATH).'img/';
 309      $default_course_dir = api_get_path(REL_CODE_PATH).'default_course_document/';
 310  
 311          // update templates.css in course
 312      $css_name = api_get_setting('stylesheets');                
 313          if (file_exists(api_get_path(SYS_PATH).'main/css/'.$css_name.'/templates.css')) {
 314              $template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH).'img/', file_get_contents(api_get_path(SYS_PATH).'main/css/'.$css_name.'/templates.css'));
 315              $template_content = str_replace('images/', api_get_path(REL_CODE_PATH).'css/'.$css_name.'/images/', $template_content);            
 316              file_put_contents($css_folder.'/templates.css', $template_content);
 317          }    
 318              
 319          if (!isset($_REQUEST['tmpltype'])) {
 320          if ($_REQUEST['tplid'] <> 0) {
 321              $query = 'SELECT content,title FROM '.$table_sys_template.' WHERE id='.Database::escape_string(Security::remove_XSS($_REQUEST['tplid']));
 322              $result = api_sql_query($query,__FILE__,__LINE__);
 323              while($obj = Database::fetch_object($result)) {
 324                              $valcontent = $obj->content;
 325                              $title = $obj->title;
 326              }
 327                                                 
 328                          // add css inside document content
 329                          $template_css = '';
 330                          if (strpos($valcontent, '/css/templates.css') === false) {
 331                              $template_css = '<link rel="stylesheet" href="'.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/css/templates.css" type="text/css" />';
 332                          }
 333                          
 334              $valcontent =  str_replace('{CSS}',$template_css, $valcontent);     
 335                          
 336                          // add js inside document content
 337                          $js = '';                        
 338                          if (strpos($valcontent, '/javascript/jquery.highlight.js') === false) { 
 339                              $js .='<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
 340                              $js .='<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'jwplayer/jwplayer.js" language="javascript"></script>'.PHP_EOL;
 341                              if (api_get_setting('show_glossary_in_documents') != 'none') {                                                                
 342                                  if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
 343                                      $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
 344                                  } else {
 345                                      $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"></script>';
 346                                      $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
 347                                  }
 348                              }                                                
 349                          } 
 350                          $valcontent = str_replace('</head>',$js.'</head>',$valcontent);
 351              $valcontent =  str_replace('{IMG_DIR}',$img_dir, $valcontent);
 352              $valcontent =  str_replace('{REL_PATH}', api_get_path(REL_PATH), $valcontent);
 353              $valcontent =  str_replace('{COURSE_DIR}',$default_course_dir, $valcontent);
 354              $default['content'] = $valcontent;
 355                          $default['title'] = get_lang($title);
 356          }
 357      } else {
 358              $sql = "SELECT template.id, template.title, template.description, template.image, template.ref_doc, document.path 
 359              FROM ".$table_template." template, ".$table_document." document 
 360              WHERE user_id='".Database::escape_string($user_id)."'
 361              AND course_code='".Database::escape_string(api_get_course_id())."'
 362              AND document.id = template.ref_doc"; 
 363              $result_template = api_sql_query($sql,__FILE__,__LINE__);
 364              while ($row = Database::fetch_array($result_template)) {
 365                              $valcontent = file_get_contents(api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$row['path']);
 366                              $title = $row['title'];
 367              }
 368              $default['content'] = $valcontent;
 369                          $default['title'] = $title;
 370      }    
 371  }
 372  if(!empty($_REQUEST['filename'])) {
 373          $default['title'] = Security::remove_XSS($_REQUEST['filename']);
 374  }
 375  $form->setDefaults($default);
 376  
 377  // If form validates -> save the new document
 378  if ($form->validate()) {
 379      $values = $form->exportValues();
 380      $readonly = isset($values['readonly']) ? 1 : 0;
 381      if (api_get_setting('use_document_title') != 'true') {
 382      $normal_name = $values['filename'];
 383          $clean_val = addslashes(trim($normal_name));
 384      } else {
 385      $normal_name = $values['title'];
 386          $clean_val = addslashes(trim($values['title']));
 387      }
 388      $clean_val=Security::remove_XSS($clean_val);
 389      $original_name = Security::remove_XSS($normal_name);
 390      $clean_val=replace_dangerous_char(stripslashes($clean_val));
 391      $clean_val=disable_dangerous_file($clean_val);
 392      $clean_val=replace_accents($clean_val);    
 393  
 394      if (api_get_setting('use_document_title') != 'true') {
 395              $values['filename']=$clean_val;
 396              $values['title'] = str_replace('/','-',$values['filename']);
 397              $filename = replace_accents($values['filename']);
 398              $title = $values['filename'];
 399      } else    {
 400              $values['title']=$clean_val;
 401              $values['filename'] = str_replace('/','-',$values['title']);
 402              $filename = replace_accents($values['title']);
 403              $title = $values['title'];
 404      }
 405  
 406      $texte = stripslashes($values['content']);
 407      $texte = Security::remove_XSS($texte,COURSEMANAGERLOWSECURITY);
 408      if(empty($title)) {
 409              $filename = 'Noname_'.rand(1,100);
 410      }
 411      $extension = 'html';
 412      $js = '';
 413      // add js path if it doesn't exist
 414      if (strpos($texte, 'javascript/jquery.highlight.js') === false) {            
 415          $js .='<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
 416          $js .='<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'jwplayer/jwplayer.js" language="javascript"></script>'.PHP_EOL;
 417          if (api_get_setting('show_glossary_in_documents') != 'none' && isset($_POST['is_template']) && $_POST['is_template'] == 0) {                
 418              if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
 419                  $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
 420              } else {
 421                  $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"></script>';
 422                  $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
 423              }
 424          }
 425      }
 426  
 427      $template_css = '';
 428      // add template css path if it doesn't exist
 429      if (strpos($texte, '/css/templates.css') === false) {
 430          $template_css = '<link rel="stylesheet" href="'.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/css/templates.css" type="text/css" />';            
 431      }
 432  
 433      $texte = str_replace('</head>', $template_css.$js.'</head>', $texte);
 434          
 435      if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
 436          $texte = text_filter($texte);        
 437          $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $texte);         
 438          fputs($fp, $content);
 439          fclose($fp);
 440          $files_perm = api_get_setting('permissions_for_new_files');
 441          $files_perm = octdec(!empty($files_perm)?$files_perm:'0770');
 442          chmod($filepath.$filename.'.'.$extension,$files_perm);
 443          $perm = api_get_setting('permissions_for_new_directories');
 444          $perm = octdec(!empty($perm)?$perm:'0770');
 445          if (!is_dir($filepath.'css')) {
 446              mkdir($filepath.'css');
 447              chmod($filepath.'css', $perm);
 448              $doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
 449              api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
 450              api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
 451          }
 452  
 453          if (!is_file($filepath.'css/templates.css')) {
 454              //make a copy of the current css for the new document
 455              copy(api_get_path(SYS_CODE_PATH).'css/'.api_get_setting('stylesheets').'/templates.css', $filepath.'css/templates.css');
 456              $doc_id = add_document($_course, $dir.'css/templates.css', 'file', filesize($filepath.'css/templates.css'), 'templates.css');
 457              api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
 458              api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
 459          }
 460  
 461          $file_size = filesize($filepath.$filename.'.'.$extension);
 462          $save_file_path = $dir.$filename.'.'.$extension;
 463  
 464          $document_id = add_document($_course, $save_file_path, 'file', $file_size, $original_name,null,$readonly);
 465          if ($document_id) {
 466              api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
 467              //update parent folders
 468              item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
 469              $new_comment = isset ($_POST['comment']) ? trim($_POST['comment']) : '';
 470              $new_title = isset ($_POST['title']) ? trim($_POST['title']) : '';
 471              if ($new_comment || $new_title) {
 472                  $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
 473                  $ct = '';
 474                  if ($new_comment)
 475                      $ct .= ", comment='$new_comment'";
 476                  if ($new_title)
 477                      $ct .= ", title='$new_title'";
 478                  api_sql_query("UPDATE $TABLE_DOCUMENT SET".substr($ct, 1)." WHERE id = '$document_id'", __FILE__, __LINE__);
 479              }
 480              $dir= substr($dir,0,-1);
 481              $selectcat = '';
 482              // Get last 3 characters
 483              $ext = substr(strrchr($save_file_path,'.'),1);
 484              $ext = strtolower($ext);
 485              if (isset($_REQUEST['selectcat']))
 486                  $selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']);
 487              if(api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
 488                 DocumentManager::search_engine_save($document_id, $new_title, $content, $save_file_path);
 489              }
 490              $allowed_file_types = array('htm','html','gif','jpg','jpeg','png','bmp');
 491              if (in_array($ext, $allowed_file_types)) {
 492                 echo "<script>window.location.href='showinframes.php?".api_get_cidReq()."&file=".$save_file_path."&curdirpath=".$dir."';</script>";
 493              } else {
 494                             echo "<script>window.location.href='document.php?".api_get_cidReq()."&curdirpath='".$dir.";</script>";
 495              }
 496              exit ();
 497          } else {
 498              Display :: display_tool_header($nameTools, "Doc");
 499              Display :: display_error_message(get_lang('Impossible'));
 500              Display :: display_footer();        
 501          }
 502      } else {
 503          Display :: display_tool_header($nameTools, "Doc");
 504          //api_display_tool_title($nameTools);
 505          Display :: display_error_message(get_lang('Impossible'));
 506          Display :: display_footer();
 507      }
 508  } else {
 509      // Display the header
 510      Display :: display_tool_header($nameTools, "Doc");
 511      if (isset($_REQUEST['certificate'])) {
 512          $all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate();
 513          $str_info='';
 514          foreach ($all_information_by_create_certificate[0] as $info_value) {
 515              $str_info.=$info_value.'<br/>';
 516          }
 517          $create_certificate=get_lang('CreateCertificateWithTags');
 518          echo '<div class="section_white"><div class="sectioncontent_white_bg">'.$create_certificate.': <br />'.$str_info.'</div></div>';
 519      }
 520      // actions
 521      echo '<div class="actions">' . PHP_EOL;
 522      echo '<a href="document.php?'.api_get_cidreq().'&curdirpath='.Security::remove_XSS($_GET['dir']).'&amp;selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('pixel.gif', get_lang('Documents'), array('class' => 'toolactionplaceholdericon toolactionback')).' '.get_lang('Documents').'</a>' . PHP_EOL;
 523      echo '<a href="template_gallery.php?'.api_get_cidreq().'&doc=N&dir='.Security::remove_XSS($_GET['dir']).'&amp;selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('pixel.gif', get_lang('Templates'), array('class' => 'toolactionplaceholdericon toolactiontemplates')).' '.get_lang('Templates').'</a>' . PHP_EOL;
 524      echo '</div>' . PHP_EOL;
 525  
 526      // start the content div
 527      echo '<div id="content">';
 528  
 529      // display the form
 530      $form->display();
 531  
 532      // close the content div
 533      echo '</div>';
 534  
 535       // bottom actions bar
 536      echo '<div class="actions">';
 537      echo '</div>';
 538  
 539      // display the footer
 540      Display::display_footer();
 541  }
 542  ?>

title

Description

title

Description

title

Description

title

title

Body