From 43135c127ec2c433fc11aa589b4f5e2e692d9fd3 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 30 Apr 2008 05:19:57 +0200 Subject: [PATCH] [svn r15182] Now working the readonly option when editing a Document. (see FS#2452 - 10) --- main/document/edit_document.php | 215 +++++++++++++++++++------------- main/inc/lib/fileUpload.lib.php | 7 +- 2 files changed, 133 insertions(+), 89 deletions(-) diff --git a/main/document/edit_document.php b/main/document/edit_document.php index fd8750ad89..904b1054e2 100644 --- a/main/document/edit_document.php +++ b/main/document/edit_document.php @@ -1,4 +1,4 @@ -addElement('hidden','filename'); - $form->addElement('hidden','extension'); + $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')); @@ -537,9 +568,29 @@ if (api_is_allowed_to_edit() || GroupManager :: is_user_in_group($_user['user_id $form->addElement('hidden','formSent'); $defaults['formSent'] = 1; $form->addElement('submit','submit',get_lang('Ok')); - $form->add_html_editor('texte','',false,true); + + //echo $read_only_flag=$_POST['readonly']; $defaults['texte'] = $texte; + + if (!empty($readonly) && $readonly==1) + { + $file_web_path=api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'; + $filepath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/'; + $filename_noedit=$file_web_path.$file_name; + $_SESSION['showedit']=0; + if (file_exists($filepath.$file_name)) + { + $form->addelement('html','
'); + } + } + else + { + $_SESSION['showedit']=1; + $form->add_html_editor('texte','',false,true); + } + } + if(!$group_document) { $metadata_link = ''.get_lang('AddMetadata').''; @@ -548,19 +599,11 @@ if (api_is_allowed_to_edit() || GroupManager :: is_user_in_group($_user['user_id $form->addElement('textarea','newComment',get_lang('Comment'),'rows="3" style="width:300px;"'); - /* if($owner_id != $_user['user_id']) - { - $form->addElement('hidden','readonly'); - } - else - { - */ - $renderer = $form->defaultRenderer(); + $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('
{element}{label}
', 'readonly'); $form->addElement('checkbox','readonly',get_lang('ReadOnly')); - //} - $defaults['readonly']=$readonly; + $defaults['readonly']=$readonly; $form->addElement('submit','submit',get_lang('Ok')); $defaults['filename'] = $filename; diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index c1f91d4dd8..501c6e2879 100644 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -1218,12 +1218,13 @@ function get_document_id() moved to document.lib.php * @param array $_course * @param int $document_id * @param int $filesize + * @param int $readonly * @return boolean true /false */ -function update_existing_document($_course,$document_id,$filesize) -{ +function update_existing_document($_course,$document_id,$filesize,$readonly=0) +{ $document_table = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']); - $sql="UPDATE $document_table SET `size`='$filesize' WHERE id='$document_id'"; + $sql="UPDATE $document_table SET size = '$filesize' , readonly = '$readonly' WHERE id='$document_id'"; if(api_sql_query($sql,__FILE__,__LINE__)) { return true;