Selaa lähdekoodia

[svn r14776] add the readonly feature for documents (FS#2127)

Eric Marguin 17 vuotta sitten
vanhempi
commit
eac1383e7e

+ 6 - 2
main/document/create_document.php

@@ -1,5 +1,5 @@
 <?php
-// $Id: create_document.php 14177 2008-01-23 15:50:31Z elixir_inter $
+// $Id: create_document.php 14776 2008-04-08 06:55:16Z elixir_inter $
 /*
 ==============================================================================
 	Dokeos - elearning and course management software
@@ -271,6 +271,9 @@ else
 	$form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists');
 }
 
+$renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
+$form->addElement('checkbox','readonly',get_lang('ReadOnly'));
+
 $form->addElement('submit', 'submit', get_lang('Ok'));
 
 // HTML-editor
@@ -284,6 +287,7 @@ $form->setDefaults($default);
 if ($form->validate())
 {
 	$values = $form->exportValues();
+	$readonly = isset($values['readonly']) ? 1 : 0;
 	if (api_get_setting('use_document_title') != 'true')
 	{
 		$values['title'] = $values['filename'];
@@ -348,7 +352,7 @@ if ($form->validate())
 		$file_size = filesize($filepath.$filename.'.'.$extension);
 		$save_file_path = $dir.$filename.'.'.$extension;
 
-		$document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename);
+		$document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename,null,$readonly);
 		if ($document_id)
 		{
 			api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id);

+ 6 - 2
main/document/document.php

@@ -1,4 +1,4 @@
-<?php // $Id: document.php 14697 2008-03-26 16:05:34Z juliomontoya $
+<?php // $Id: document.php 14776 2008-04-08 06:55:16Z elixir_inter $
 
 /*
 ==============================================================================
@@ -646,7 +646,11 @@ if($docs_and_folders)
 		//admins get an edit column
 		if ($is_allowed_to_edit || $group_member_with_upload_rights)
 		{
-			$edit_icons = build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key, $id['is_template']);
+			// if readonly, check if it the owner of the file ?
+			if (!$id['readonly'] || $id['insert_user_id'] == $_user['user_id'] || api_is_platform_admin())
+				$edit_icons = build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key, $id['is_template']);
+			else
+				$row[] = '';
 			$row[] = $edit_icons;
 		}
 		$row[]=$last_edit_date;

+ 27 - 2
main/document/edit_document.php

@@ -1,4 +1,4 @@
-<?php // $Id: edit_document.php 14316 2008-02-19 15:38:24Z yannoo $
+<?php // $Id: edit_document.php 14776 2008-04-08 06:55:16Z elixir_inter $
 /*
 ==============================================================================
 	Dokeos - elearning and course management software
@@ -301,7 +301,7 @@ if (isset($_POST['renameTo']))
 */
 
 
-
+/** TODO check if this code is still used **/
 /* Search the old comment */  // RH: metadata: added 'id,'
 $result = mysql_query ("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'");
 
@@ -508,6 +508,31 @@ else
 {
 	$form->addElement('hidden','renameTo');
 }
+
+// readonly
+$sql = 'SELECT id, readonly FROM '.$dbTable.'
+		WHERE path LIKE BINARY "'.$dir.$doc.'"';
+$rs = api_sql_query($sql, __FILE__, __LINE__);
+$readonly = mysql_result($rs,0,'readonly');
+$doc_id = mysql_result($rs,0,'id');
+// owner
+$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 = mysql_result($rs,0,'insert_user_id');
+if($owner_id != $_user['user_id'])
+{
+	$form->addElement('hidden','readonly');
+}
+else
+{
+	$renderer = $form->defaultRenderer();
+	$renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
+	$form->addElement('checkbox','readonly',get_lang('ReadOnly'));
+}
+$defaults['readonly']=$readonly;
+
 if($extension == "htm" || $extension == "html")
 {
 	$form->addElement('hidden','formSent');

+ 1 - 0
main/inc/lib/add_course.lib.inc.php

@@ -661,6 +661,7 @@ function update_Db_course($courseDbName)
 			title varchar(255) default NULL,
 			filetype set('file','folder') NOT NULL default 'file',
 			size int NOT NULL default 0,
+			readonly TINYINT UNSIGNED NOT NULL,
 			PRIMARY KEY (`id`)
 		)";
 	api_sql_query($sql, __FILE__, __LINE__);

+ 3 - 3
main/inc/lib/fileUpload.lib.php

@@ -1176,12 +1176,12 @@ function filter_extension(&$filename)
  * @param string $title
  * @return id if inserted document
  */
-function add_document($_course,$path,$filetype,$filesize,$title,$comment=NULL)
+function add_document($_course,$path,$filetype,$filesize,$title,$comment=NULL, $readonly=0)
 {
 	$table_document = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']);
 	$sql="INSERT INTO $table_document
-	(`path`,`filetype`,`size`,`title`, `comment`)
-	VALUES ('$path','$filetype','$filesize','$title', '$comment')";
+	(`path`,`filetype`,`size`,`title`, `comment`, readonly)
+	VALUES ('$path','$filetype','$filesize','$title', '$comment',$readonly)";
 	if(api_sql_query($sql,__FILE__,__LINE__))
 	{
 		//display_message("Added to database (id ".mysql_insert_id().")!");

+ 2 - 1
main/install/migrate-db-1.8.4-1.8.5-pre.sql

@@ -109,4 +109,5 @@ INSERT INTO course_setting(variable,value,category) VALUES ('allow_learning_path
 ALTER TABLE forum_post ADD INDEX idx_forum_post_thread_id (thread_id);
 ALTER TABLE forum_post ADD INDEX idx_forum_post_visible (visible);
 ALTER TABLE forum_thread ADD INDEX idx_forum_thread_forum_id (forum_id);
-ALTER TABLE student_publication ADD COLUMN filetype SET('file','folder')  NOT NULL DEFAULT 'file' AFTER sent_date;
+ALTER TABLE student_publication ADD COLUMN filetype SET('file','folder')  NOT NULL DEFAULT 'file' AFTER sent_date;
+ALTER TABLE document ADD readonly TINYINT UNSIGNED NOT NULL ;