123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- <?php
- $language_file = 'document';
- require_once '../inc/global.inc.php';
- $htmlHeadXtra[] = '
- <script type="text/javascript">
- function InnerDialogLoaded()
- {
- /*
- var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
- return B.ClickFrame();
- */
- var isIE = (navigator.appVersion.indexOf(\'MSIE\') != -1) ? true : false ;
- var EditorFrame = null ;
- if ( !isIE )
- {
- EditorFrame = window.frames[0] ;
- }
- else
- {
- // For this dynamic page window.frames[0] enumerates frames in a different order in IE.
- // We need a sure method to locate the frame that contains the online editor.
- for ( var i = 0, n = window.frames.length ; i < n ; i++ )
- {
- if ( window.frames[i].location.toString().indexOf(\'InstanceName=texte\') != -1 )
- {
- EditorFrame = window.frames[i] ;
- }
- }
- }
- if ( !EditorFrame )
- {
- return null ;
- }
- var B = new EditorFrame.FCKToolbarButton(\'Templates\', EditorFrame.FCKLang.Templates);
- return B.ClickFrame();
- };
-
- function FCKeditor_OnComplete( editorInstance )
- {
- 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 \'>";
- }
-
- </script>';
- $_SESSION['whereami'] = 'document/create';
- $this_section=SECTION_COURSES;
- require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
- require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- require_once api_get_path(LIBRARY_PATH).'document.lib.php';
- require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
- require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
- if (api_is_in_group())
- {
- $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
- }
- $file = $_GET['file'];
- $doc=basename($file);
- $dir=Security::remove_XSS($_GET['curdirpath']);
- $file_name = $doc;
- $baseServDir = api_get_path(SYS_COURSE_PATH);
- $baseServUrl = $_configuration['url_append']."/";
- $courseDir = $_course['path']."/document";
- $baseWorkDir = $baseServDir.$courseDir;
- $group_document = false;
- $doc_tree= explode('/', $file);
- $count_dir = count($doc_tree) -2;
- if (!empty($group_properties['directory']))
- {
- $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
- }
- $relative_url='';
- for($i=0;$i<($count_dir);$i++)
- {
- $relative_url.='../';
- }
- $html_editor_config = array(
- 'ToolbarSet' => (api_is_allowed_to_edit() ? 'Documents' :'Documents_Student'),
- 'Width' => '100%',
- 'Height' => '600',
- 'FullPage' => true,
- 'InDocument' => true,
- 'CreateDocumentDir' => $relative_url,
- 'CreateDocumentWebDir' => (empty($group_properties['directory']))
- ? api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'
- : api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document'.$group_properties['directory'].'/',
- 'BaseHref' => api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir
- );
- $use_document_title = (get_setting('use_document_title')=='true')?true:false;
- $noPHP_SELF=true;
- if(strstr($dir,'..'))
- {
- $dir='/';
- }
- if($dir[0] == '.')
- {
- $dir=substr($dir,1);
- }
- if($dir[0] != '/')
- {
- $dir='/'.$dir;
- }
- if($dir[strlen($dir)-1] != '/')
- {
- $dir.='/';
- }
- $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$dir;
- if(!is_dir($filepath))
- {
- $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
- $dir='/';
- }
- $dbTable = Database::get_course_table(TABLE_DOCUMENT);
- if(!empty($_SESSION['_gid']))
- {
- $req_gid = '&gidReq='.$_SESSION['_gid'];
- $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace'));
- $group_document = true;
- $noPHP_SELF=true;
- }
- $my_cur_dir_path=Security::remove_XSS($_GET['curdirpath']);
- $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
- $is_allowedToEdit = is_allowed_to_edit() || $_SESSION['group_member_with_upload_rights'];
- if(!$is_allowedToEdit)
- {
- api_not_allowed(true);
- }
- $user_id = api_get_user_id();
- event_access_tool(TOOL_DOCUMENT);
- if (!is_allowed_to_edit())
- {
- if(DocumentManager::check_readonly($_course,$user_id,$file))
- {
- api_not_allowed();
- }
- }
- function change_name($baseWorkDir, $sourceFile, $renameTo, $dir, $doc)
- {
- $file_name_for_change = $baseWorkDir.$dir.$sourceFile;
-
- $renameTo = disable_dangerous_file($renameTo);
- $renameTo = my_rename($file_name_for_change, stripslashes($renameTo));
-
- if ($renameTo)
- {
- if (isset($dir) && $dir != "")
- {
- $sourceFile = $dir.$sourceFile;
- $new_full_file_name = dirname($sourceFile)."/".$renameTo;
- }
- else
- {
- $sourceFile = "/".$sourceFile;
- $new_full_file_name = "/".$renameTo;
- }
- update_db_info("update", $sourceFile, $new_full_file_name);
- $name_changed = get_lang("ElRen");
- $info_message = get_lang('fileModified');
- $GLOBALS['file_name'] = $renameTo;
- $GLOBALS['doc'] = $renameTo;
- return $info_message;
- }
- else
- {
- $dialogBox = get_lang('FileExists');
-
- $rename = $sourceFile;
- unset($sourceFile);
- }
- }
- if (isset($_POST['newComment']))
- {
-
- $commentPath = str_replace("//", "/", Database::escape_string(Security::remove_XSS($_POST['commentPath'])));
- $newComment = trim(Database::escape_string(Security::remove_XSS($_POST['newComment'])));
- $newTitle = trim(Database::escape_string(Security::remove_XSS($_POST['newTitle'])));
-
- $result = api_sql_query ("SELECT * FROM $dbTable WHERE path LIKE BINARY '".$commentPath."'",__FILE__,__LINE__);
- while($row = Database::fetch_array($result, 'ASSOC'))
- {
- $attribute['path' ] = $row['path' ];
- $attribute['comment' ] = $row['title'];
- }
-
-
- $query = "UPDATE $dbTable
- SET comment='".$newComment."', title='".$newTitle."'
- WHERE path
- LIKE BINARY '".$commentPath."'";
- api_sql_query($query,__FILE__,__LINE__);
- $oldComment = $newComment;
- $oldTitle = $newTitle;
- $comments_updated = get_lang('ComMod');
- $info_message = get_lang('fileModified');
- }
- if (isset($_POST['renameTo']))
- {
- $info_message = change_name($baseWorkDir, $_GET['sourceFile'], $_POST['renameTo'], $dir, $doc);
-
- }
-
- $result = api_sql_query("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'",__FILE__,__LINE__);
- $message = "<i>Debug info</i><br>directory = $dir<br>";
- $message .= "document = $file_name<br>";
- $message .= "comments file = " . $file . "<br>";
- while($row = Database::fetch_array($result, 'ASSOC'))
- {
- $oldComment = $row['comment'];
- $oldTitle = $row['title'];
- $docId = $row['id'];
- }
- if($is_allowedToEdit)
- {
- if($_POST['formSent']==1)
- {
- if(isset($_POST['renameTo']))
- {
- $_POST['filename']=disable_dangerous_file($_POST['renameTo']);
- $extension=explode('.',$_POST['filename']);
- $extension=$extension[sizeof($extension)-1];
- $_POST['filename']=str_replace('.'.$extension,'',$_POST['filename']);
- }
-
- $filename=stripslashes($_POST['filename']);
- $texte=trim(str_replace(array("\r","\n"),"",stripslashes($_POST['texte'])));
- $texte=Security::remove_XSS($texte,COURSEMANAGERLOWSECURITY);
- if(!strstr($texte,'/css/frames.css'))
- {
- $texte=str_replace('</title></head>','</title><link rel="stylesheet" href="../css/frames.css" type="text/css" /></head>',$texte);
- }
-
-
-
-
-
-
-
-
- $extension = $_POST['extension'];
-
-
- $file=$dir.$filename.'.'.$extension;
- $read_only_flag=$_POST['readonly'];
- if (!empty($read_only_flag))
- {
- $read_only_flag=1;
- }
- else
- {
- $read_only_flag=0;
- }
-
- $show_edit=$_SESSION['showedit'];
-
- api_session_unregister('showedit');
-
-
- if(empty($filename))
- {
- $msgError=get_lang('NoFileName');
- }
- else
- {
- if ($read_only_flag==0)
- {
- if (!empty($texte))
- {
- if($fp=@fopen($filepath.$filename.'.'.$extension,'w'))
- {
- $texte = text_filter($texte);
-
- $texte = str_replace('flv=h','flv=h|',$texte);
- $texte = str_replace('flv=/','flv=/|',$texte);
-
-
-
-
-
-
-
-
-
-
- fputs($fp,$texte);
- fclose($fp);
- $perm = api_get_setting('permissions_for_new_directories');
- $perm = octdec(!empty($perm)?$perm:'0770');
- if(!is_dir($filepath.'css'))
- {
- mkdir($filepath.'css',$perm);
- $doc_id=add_document($_course,$dir.'css','folder',0,'css');
- api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
- api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
- }
-
- if(!is_file($filepath.'css/frames.css'))
- {
- $platform_theme= api_get_setting('stylesheets');
- if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
- copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css',$filepath.'css/frames.css');
- $doc_id=add_document($_course,$dir.'css/frames.css','file',filesize($filepath.'css/frames.css'),'frames.css');
- api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
- api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
- }
- }
-
-
- $document_id = DocumentManager::get_document_id($_course,$file);
- if($document_id)
- {
- $file_size = filesize($filepath.$filename.'.'.$extension);
- update_existing_document($_course, $document_id,$file_size,$read_only_flag);
- api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id']);
-
- item_property_update_on_folder($_course,$dir,$_user['user_id']);
- $dir= substr($dir,0,-1);
- header('Location: document.php?curdirpath='.urlencode($dir));
- exit ();
- }
- else
- {
-
- }
- }
- else
- {
- $msgError=get_lang('Impossible');
- }
- }
- else
- {
- if (is_file($filepath.$filename.'.'.$extension)) {
- $file_size = filesize($filepath.$filename.'.'.$extension);
- $document_id = DocumentManager::get_document_id($_course,$file);
- if ($document_id) {
- update_existing_document($_course, $document_id,$file_size,$read_only_flag);
- }
- }
- }
- }
- else
- {
-
- if (is_file($filepath.$filename.'.'.$extension)) {
- $file_size = filesize($filepath.$filename.'.'.$extension);
- $document_id = DocumentManager::get_document_id($_course,$file);
-
- if ($document_id) {
- update_existing_document($_course, $document_id,$file_size,$read_only_flag);
- }
- }
-
- if (empty($document_id))
- {
- $folder=$_POST['file_path'];
- $document_id = DocumentManager::get_document_id($_course,$folder);
-
- if (DocumentManager::is_folder($_course, $document_id))
- {
- if($document_id)
- {
- update_existing_document($_course, $document_id,$file_size,$read_only_flag);
- }
- }
- }
-
-
- }
- }
- }
- }
- if(file_exists($filepath.$doc))
- {
- $extension=explode('.',$doc);
- $extension=$extension[sizeof($extension)-1];
- $filename=str_replace('.'.$extension,'',$doc);
- $extension=strtolower($extension);
-
-
-
- if(in_array($extension,array('html','htm')))
- {
- $texte=file($filepath.$doc);
- $texte=implode('',$texte);
- $path_to_append=api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$dir;
- $texte=str_replace('="./','="'.$path_to_append,$texte);
- $texte=str_replace('mp3player.swf?son=.%2F','mp3player.swf?son='.urlencode($path_to_append),$texte);
- }
- }
- $nameTools = get_lang("EditDocument") . ': '.$file_name;
- Display::display_header($nameTools,"Doc");
- if(isset($msgError))
- {
- Display::display_error_message($msgError);
- }
- if( isset($info_message))
- {
- Display::display_normal_message($info_message);
- }
- $sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"';
- $rs = api_sql_query($sql, __FILE__, __LINE__);
- $readonly = Database::result($rs,0,'readonly');
- $doc_id = Database::result($rs,0,'id');
-
- $sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).'
- WHERE tool LIKE "document"
- AND ref='.intval($doc_id);
- $rs = api_sql_query($sql, __FILE__, __LINE__);
- $owner_id = Database::result($rs,0,'insert_user_id');
- if ($owner_id == $_user['user_id'] || api_is_platform_admin() || api_is_allowed_to_edit() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'] ))
- {
- $get_cur_path=Security::remove_XSS($_GET['curdirpath']);
- $get_file=Security::remove_XSS($_GET['file']);
- $action = api_get_self().'?sourceFile='.urlencode($file_name).'&curdirpath='.urlencode($get_cur_path).'&file='.urlencode($get_file).'&doc='.urlencode($doc);
- $form = new FormValidator('formEdit','post',$action);
-
- $form->addElement('header', '', $nameTools);
-
- $renderer = $form->defaultRenderer();
- $form->addElement('hidden','filename');
- $form->addElement('hidden','extension');
- $form->addElement('hidden','file_path');
- $form->addElement('hidden','commentPath');
- $form->addElement('hidden','showedit');
-
- if($use_document_title)
- {
- $form->add_textfield('newTitle',get_lang('Title'));
- $defaults['newTitle'] = $oldTitle;
- }
- else
- {
- $form->addElement('hidden','renameTo');
- }
- $form->addElement('hidden','formSent');
- $defaults['formSent'] = 1;
-
- $read_only_flag=$_POST['readonly'];
-
- $defaults['texte'] = $texte;
-
-
-
- if(($extension == 'htm' || $extension == 'html') && stripos($dir, '/HotPotatoes_files') === false)
- {
- if (empty($readonly) && $readonly==0)
- {
- $_SESSION['showedit']=1;
- $renderer->setElementTemplate('<div class="row"><div class="label" id="frmModel" style="overflow: visible;"></div><div class="formw">{element}</div></div>', 'texte');
- $form->add_html_editor('texte', '', false, true, $html_editor_config);
- }
- }
-
- if(!$group_document)
- {
- $metadata_link = '<a href="../metadata/index.php?eid='.urlencode('Document.'.$docId).'">'.get_lang('AddMetadata').'</a>';
- $form->addElement('static',null,get_lang('Metadata'),$metadata_link);
- }
-
- $form->addElement('textarea','newComment',get_lang('Comment'),'rows="3" style="width:300px;"');
-
- if ($owner_id == $_user['user_id'] || api_is_platform_admin())
- {
- $renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
- $checked =&$form->addElement('checkbox','readonly',get_lang('ReadOnly'));
- if ($readonly==1)
- {
- $checked->setChecked(true);
- }
- }
- $form->addElement('style_submit_button','submit',get_lang('SaveDocument'), 'class="save"');
-
- $defaults['filename'] = $filename;
- $defaults['extension'] = $extension;
- $defaults['file_path'] = Security::remove_XSS($_GET['file']);
- $defaults['commentPath'] = $file;
- $defaults['renameTo'] = $file_name;
- $defaults['newComment'] = $oldComment;
-
- $form->setDefaults($defaults);
-
-
- $form->display();
-
- }
- Display::display_footer();
- ?>
|