[svn r17061] Added file attachments to events (see FS#193)

skala
Cristian Fasanando 17 years ago
parent 8cd14fddd7
commit f89474820e
  1. 130
      main/calendar/agenda.inc.php
  2. 16
      main/calendar/agenda.php
  3. 96
      main/calendar/download.php
  4. 15
      main/inc/lib/add_course.lib.inc.php
  5. 3
      main/inc/lib/database.lib.php
  6. 12
      main/install/update-files-1.8.5-1.8.6.inc.php

@ -1,4 +1,4 @@
<?php //$Id: agenda.inc.php 16978 2008-11-27 11:04:12Z pcool $
<?php //$Id: agenda.inc.php 17061 2008-12-03 21:43:06Z cfasanando $
/*
==============================================================================
@ -1717,7 +1717,23 @@ function display_agenda_items()
echo $td_colspan;
echo $content;
echo '</td></tr>';
// attachment list
$attachment_list=get_attachment($myrow['id']);
if (!empty($attachment_list)) {
$realname=$attachment_list['path'];
$user_filename=$attachment_list['filename'];
$full_file_name = 'download.php?file='.$realname;
echo Display::return_icon('attachment.gif',get_lang('Attachment'));
echo '<a href="'.$full_file_name.'';
echo ' "> '.$user_filename.' </a>';
echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span><br />';
}
echo '</td></tr>';
/*--------------------------------------------------
display: the added resources
@ -1740,7 +1756,6 @@ function display_agenda_items()
$event_list.=$myrow['id'].',';
$counter++;
/*--------------------------------------------------
display: jump-to-top icon
--------------------------------------------------*/
@ -1768,6 +1783,25 @@ function display_agenda_items()
"</table>";
}
/**
* Show a list with all the attachments according to the post's id
* @param the post's id
* @return array with the post info
* @author Christian Fasanando
* @version November 2008, dokeos 1.8.6
*/
function get_attachment($agenda_id) {
$agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
$row=array();
$sql = 'SELECT path, filename,comment FROM '. $agenda_table_attachment.' WHERE agenda_id = '.(int)$agenda_id.'';
$result=api_sql_query($sql, __FILE__, __LINE__);
if (Database::num_rows($result)!=0) {
$row=Database::fetch_array($result);
}
return $row;
}
/**
* Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
@ -1996,7 +2030,6 @@ function show_add_form($id = '')
}
else
{
// we are coming from the resource linker so there might already have been some information in the form.
// When we clicked on the button to add resources we stored every form information into a session and now we
// are doing the opposite thing: getting the information out of the session and putting it into variables to
@ -2018,8 +2051,7 @@ function show_add_form($id = '')
$to=$form_elements['to'];
$repeat = $form_elements['repeat'];
}
// switching the send to all/send to groups/send to users
if ($_POST['To'])
{
@ -2041,7 +2073,6 @@ function show_add_form($id = '')
$repeat = !empty($_POST['repeat'])?true:false;
}
// if the id is set then we are editing an agenda item
if (is_int($id))
{
@ -2067,7 +2098,6 @@ function show_add_form($id = '')
// we start a completely new item, we do not come from the resource linker
if ($_GET['originalresource']!=="no" and $_GET['action']=="add")
{
$_SESSION["formelements"]=null;
unset_session_resources();
}
@ -2105,7 +2135,6 @@ function show_add_form($id = '')
}
else
{
?>
<tr class="subtitle">
<td valign="top" colspan="3">
@ -2121,7 +2150,7 @@ function show_add_form($id = '')
}
echo '<a href="#" onclick="if(document.getElementById(\'recipient_list\').style.display==\'none\') document.getElementById(\'recipient_list\').style.display=\'block\'; else document.getElementById(\'recipient_list\').style.display=\'none\';">'.get_lang('ModifyRecipientList').'</a>';
show_to_form($to);
if (isset($_GET['id']) && $to!='everyone'){
if (isset($_GET['id']) && $to!='everyone') {
echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
}
?>
@ -2404,20 +2433,20 @@ function show_add_form($id = '')
//for images
$oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Images&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['ImageUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Images&ServerPath=$upload_path" ;
$oFCKeditor->Config['ImageUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Images&ServerPath=$upload_path" ;
//for flash
$oFCKeditor->Config['FlashBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['FlashUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Flash&ServerPath=$upload_path" ;
$oFCKeditor->Config['MediaBrowserURL'] = $oFCKeditor->Config['FlashBrowserURL'];
$oFCKeditor->Config['FlashUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Flash&ServerPath=$upload_path" ;
$oFCKeditor->Config['MediaBrowserURL'] = $oFCKeditor->Config['FlashBrowserURL'];
//for MP3
$oFCKeditor->Config['MP3BrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=MP3&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['MP3UploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=MP3&ServerPath=$upload_path" ;
$oFCKeditor->Config['MP3BrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=MP3&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['MP3UploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=MP3&ServerPath=$upload_path" ;
//for Videos
$oFCKeditor->Config['VideoBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Video&Connector=connectors/php/connector.php&ServerPath=$upload_path";
$oFCKeditor->Config['VideoUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video&ServerPath=$upload_path" ;
$oFCKeditor->Config['VideoUploadURL'] = $oFCKeditor->BasePath . "editor/filemanager/upload/php/upload.php?Type=Video&ServerPath=$upload_path" ;
//link
$oFCKeditor->Config['LinkBrowserURL'] = $oFCKeditor->BasePath . "editor/filemanager/browser/default/browser.html?Type=Images&Connector=connectors/php/connector.php&ServerPath=$upload_path";
@ -2450,8 +2479,20 @@ function show_add_form($id = '')
echo "\t\t</td>\n\t</tr>\n";
/* END ADDED BY UGENT, Patrick Cool, march 2004 */
if(empty($id)) //only show repeat fields when adding the first time
{
{
?>
<tr><td colspan="2"><br /><b><?php echo get_lang('AddAnAttachment') ?><br /><br /></td></tr>
<tr>
<td colspan="2">
<label for="file_name"><?php echo ucwords(get_lang('FileName'))?></label>
<input type="file" name="user_upload"/>
</td>
</tr><tr>
<td colspan="2">
<label for="comment"><?php echo get_lang('FileComment')?></label><br />
<textarea name="file_comment" rows ="4" cols = "34" ></textarea>
</td>
</tr>
<tr>
<td><label for="repeat"><?php echo get_lang('RepeatedEvent');?></label><input type="checkbox" name="repeat" <?php echo ($repeat?'checked="checked"':'');?>/></td>
<td colspan="2" />
@ -3830,11 +3871,12 @@ function add_year($timestamp,$num=1)
* @param int Parent id (optional)
* @return int The new item's DB ID
*/
function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date,$group_id,$id_user,$to=array(), $parent_id=null)
function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date,$group_id,$id_user,$to=array(), $parent_id=null,$file_comment)
{
global $_course;
$user_id = api_get_user_id();
$t_agenda = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']);
$agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
// some filtering of the input data
$title = Database::escape_string($title); // no html allowed in the title
$content = Database::escape_string($content);
@ -3849,6 +3891,46 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
$result = api_sql_query($sql,__FILE__,__LINE__) or die (Database::error());
$last_id=Database::insert_id();
// Storing the attachments
if(!empty($_FILES['user_upload']['name'])) {
$upload_ok = process_uploaded_file($_FILES['user_upload']);
}
if ($upload_ok) {
$courseDir = $_course['path'].'/upload/calendar';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path.$courseDir;
// Try to add an extension to the file if it hasn't one
$new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
// user's file name
$file_name =$_FILES['user_upload']['name'];
if (!filter_extension($new_file_name)) {
Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
} else {
$new_file_name = uniqid('');
$new_path=$updir.'/'.$new_file_name;
$result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
$safe_file_comment= Database::escape_string($file_comment);
$safe_file_name = Database::escape_string($file_name);
$safe_new_file_name = Database::escape_string($new_file_name);
// Storing the attachments if any
if ($result) {
$sql='INSERT INTO '.$agenda_table_attachment.'(filename,comment, path,agenda_id,size) '.
"VALUES ( '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".$_FILES['user_upload']['size']."' )";
$result=api_sql_query($sql, __LINE__, __FILE__);
$message.=' / '.get_lang('FileUploadSucces').'<br />';
$last_id_file=Database::insert_id();
api_item_property_update($_course, 'calendar_event_attachment', $last_id_file ,'AgendaAttachmentAdded', api_get_user_id());
}
}
}
// store in last_tooledit (first the groups, then the users
$done = false;
@ -3894,7 +3976,7 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
* @param int User ID
* @return boolean False if error, True otherwise
*/
function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest,$id_group=null,$id_user=null)
function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest,$id_group=null,$id_user=null,$file_comment)
{
$t_agenda = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']);
$t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
@ -3950,20 +4032,20 @@ function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest,$id_
case 'daily':
for($i = $orig_start + 86400; ($i <= $end); $i += 86400)
{
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i+$diff), $id_group, $id_user, $orig_dest, $orig_id);
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i+$diff), $id_group, $id_user, $orig_dest, $orig_id,$file_comment);
}
break;
case 'weekly':
for($i = $orig_start + 604800; ($i <= $end); $i += 604800)
{
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i+$diff), $id_group, $id_user, $orig_dest, $orig_id);
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i+$diff), $id_group, $id_user, $orig_dest, $orig_id,$file_comment);
}
break;
case 'monthlyByDate':
$next_start = add_month($orig_start);
while($next_start <= $end)
{
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start+$diff), $id_group, $id_user, $orig_dest, $orig_id);
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start+$diff), $id_group, $id_user, $orig_dest, $orig_id,$file_comment);
$next_start = add_month($next_start);
}
break;
@ -3977,7 +4059,7 @@ function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest,$id_
$next_start = add_year($orig_start);
while($next_start <= $end)
{
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start+$diff), $id_group, $id_user,$orig_dest, $orig_id);
$res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start+$diff), $id_group, $id_user,$orig_dest, $orig_id,$file_comment);
$next_start = add_year($next_start);
}
break;

@ -1,4 +1,4 @@
<?php //$Id: agenda.php 16785 2008-11-18 21:32:39Z yannoo $
<?php //$Id: agenda.php 17061 2008-12-03 21:43:06Z cfasanando $
/*
==============================================================================
Dokeos - elearning and course management software
@ -59,6 +59,8 @@ api_protect_course_script();
*/
$_SESSION['source_type'] = 'Agenda';
include('../resourcelinker/resourcelinker.inc.php');
require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
if (!empty($addresources)) // When the "Add Resource" button is clicked we store all the form data into a session
{
$form_elements= array ('day'=>$_POST['fday'], 'month'=>$_POST['fmonth'], 'year'=>$_POST['fyear'], 'hour'=>$_POST['fhour'], 'minutes'=>$_POST['fminute'],
@ -183,7 +185,7 @@ if (empty($_GET['origin']) or $_GET['origin'] != 'learnpath')
else
{
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
}
}
/* ==============================================================================
TRACKING
@ -293,7 +295,6 @@ $fck_attribute['ToolbarSet'] = 'Middle';
$fck_attribute['Config']['CreateDocumentDir'] = api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/';
$fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/';
if(isset($_SESSION['_course']) && $_SESSION['_course']['path']!='')
{
$upload_path = api_get_path(REL_COURSE_PATH).$_SESSION['_course']['path'].'/document/';
@ -302,11 +303,6 @@ else
{
$upload_path = api_get_path(REL_PATH).'main/default_course_document/';
}
// THE RIGHT PART
echo "<td valign=\"top\">";
@ -327,14 +323,14 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
$course_info = api_get_course_info();
$event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
$event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
$id = agenda_add_item($course_info,$_POST['title'],$_POST['content'],$event_start,$event_stop,$_REQUEST['group'],$_REQUEST['user'],$_POST['selectedform']);
$id = agenda_add_item($course_info,$_POST['title'],$_POST['content'],$event_start,$event_stop,$_REQUEST['group'],$_REQUEST['user'],$_POST['selectedform'],false,$_POST['file_comment']);
if(!empty($_POST['repeat']))
{
$end_y = intval($_POST['repeat_end_year']);
$end_m = intval($_POST['repeat_end_month']);
$end_d = intval($_POST['repeat_end_day']);
$end = mktime(23, 59, 59, $end_m, $end_d, $end_y);
$res = agenda_add_repeat_item($course_info,$id,$_POST['repeat_type'],$end,null,$_REQUEST['group'],$_REQUEST['user']);
$res = agenda_add_repeat_item($course_info,$id,$_POST['repeat_type'],$end,null,$_REQUEST['group'],$_REQUEST['user'],$_POST['file_comment']);
}
display_agenda_items();
}

@ -0,0 +1,96 @@
<?php // $Id: $
/*
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2008 Dokeos SPRL
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
info@dokeos.com
==============================================================================
*/
/**
==============================================================================
* This file is responsible for passing requested documents to the browser.
* Html files are parsed to fix a few problems with URLs,
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*
* @package dokeos.document
==============================================================================
*/
/*
==============================================================================
MAIN CODE
==============================================================================
*/
session_cache_limiter('public');
include('../inc/global.inc.php');
$this_section=SECTION_COURSES;
include(api_get_path(LIBRARY_PATH).'document.lib.php');
include 'agenda.inc.php';
// IMPORTANT to avoid caching of documents
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Cache-Control: public');
header('Pragma: no-cache');
//protection
api_protect_course_script(true);
$doc_url = $_GET['file'];
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
if (! isset($_course))
{
api_not_allowed(true);
}
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/calendar/'.$doc_url;
//if the rewrite rule asks for a directory, we redirect to the document explorer
if (is_dir($full_file_name))
{
//remove last slash if present
//$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
//mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (Ren<EFBFBD>)
while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
//create the path
$document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
//redirect
header('Location: '.$document_explorer);
}
$tbl_agenda_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
// launch event
event_download($doc_url);
$sql='SELECT filename FROM '.$tbl_agenda_attachment.'
WHERE path LIKE BINARY "'.$doc_url.'"';
$result= api_sql_query($sql, __FILE__, __LINE__);
$row= Database::fetch_array($result);
DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
exit;
?>

@ -236,6 +236,8 @@ function prepare_course_repository($courseRepository, $courseId)
mkdir(api_get_path(SYS_COURSE_PATH).$courseRepository . "/upload/blog", $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseRepository . "/upload/learning_path", $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseRepository . "/upload/learning_path/images", $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseRepository . "/upload/calendar", $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseRepository . "/upload/calendar/images", $perm);
mkdir(api_get_path(SYS_COURSE_PATH).$courseRepository . "/work", $perm);
//create .htaccess in dropbox
@ -298,6 +300,7 @@ function update_Db_course($courseDbName)
$TABLETOOLAGENDA = $courseDbName . 'calendar_event';
$TABLETOOLAGENDAREPEAT = $courseDbName . 'calendar_event_repeat';
$TABLETOOLAGENDAREPEATNOT = $courseDbName . 'calendar_event_repeat_not';
$TABLETOOLAGENDAATTACHMENT = $courseDbName . 'calendar_event_attachment';
// Announcements
$TABLETOOLANNOUNCEMENTS = $courseDbName . 'announcement';
@ -762,6 +765,18 @@ function update_Db_course($courseDbName)
)";
api_sql_query($sql,__FILE__,__LINE__);
// Agenda Attachment
$sql = "CREATE TABLE `".$TABLETOOLAGENDAATTACHMENT."` (
id int NOT NULL auto_increment,
path varchar(255) NOT NULL,
comment text,
size int NOT NULL default 0,
agenda_id int NOT NULL,
filename varchar(255) NOT NULL,
PRIMARY KEY (id)
)";
api_sql_query($sql, __FILE__, __LINE__);
/*
-----------------------------------------------------------
Document tool

@ -1,4 +1,4 @@
<?php // $Id: database.lib.php 16919 2008-11-25 23:31:07Z iflorespaz $
<?php // $Id: database.lib.php 17061 2008-12-03 21:43:06Z cfasanando $
/* See license terms in /dokeos_license.txt */
/**
==============================================================================
@ -79,6 +79,7 @@ define('TABLE_SCORM_SCO_DATA', 'scorm_sco_data');
define('TABLE_AGENDA', 'calendar_event');
define('TABLE_AGENDA_REPEAT', 'calendar_event_repeat');
define('TABLE_AGENDA_REPEAT_NOT', 'calendar_event_repeat_not');
define('TABLE_AGENDA_ATTACHMENT','calendar_event_attachment');
define('TABLE_ANNOUNCEMENT', 'announcement');
define('TABLE_CHAT_CONNECTED', 'chat_connected'); // @todo: probably no longer in use !!!
define('TABLE_COURSE_DESCRIPTION', 'course_description');

@ -106,7 +106,17 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
//upload > learning_path > images
if(!is_dir($currentCourseRepositorySys."upload/learning_path/images")){
mkdir($currentCourseRepositorySys."upload/learning_path/images",$perm);
}
}
//upload > calendar
if(!is_dir($currentCourseRepositorySys."upload/calendar")){
mkdir($currentCourseRepositorySys."upload/calendar",$perm);
}
//upload > calendar > images
if(!is_dir($currentCourseRepositorySys."upload/calendar/images")){
mkdir($currentCourseRepositorySys."upload/calendar/images",$perm);
}
}
}
else

Loading…
Cancel
Save