@ -27,6 +27,8 @@
==============================================================================
*/
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
/*
==============================================================================
DISPLAY FUNCTIONS
@ -534,6 +536,21 @@ function to_javascript()
cbList[i].selected = !(cbList[i].selected)
}
}
function plus_attachment() {
if (document.getElementById('options').style.display == 'none') {
document.getElementById('options').style.display = 'block';
document.getElementById('plus').innerHTML=' < img style = \"vertical-align:middle;\" src = \"../img/div_hide.gif\" alt = \"\" / > ".get_lang('AddAnAttachment')."';
} else {
document.getElementById('options').style.display = 'none';
document.getElementById('plus').innerHTML=' < img style = \"vertical-align:middle;\" src = \"../img/div_show.gif\" alt = \"\" / > ".get_lang('AddAnAttachment')."';
}
}
// End -->
< / script > ";
}
@ -744,8 +761,7 @@ function change_visibility_announcement($tool,$id)
STORE_ADVALVAS_ITEM
====================================================*/
function store_advalvas_item($emailTitle,$newContent, $order, $to)
{
function store_advalvas_item($emailTitle,$newContent, $order, $to, $file_comment='') {
global $_course;
global $nameTools;
@ -757,11 +773,15 @@ function store_advalvas_item($emailTitle,$newContent, $order, $to)
$emailTitle = Database::escape_string(Security::remove_XSS($emailTitle));
$newContent = Database::escape_string(Security::remove_XSS($newContent,COURSEMANAGERLOWSECURITY));
$order = intval($order);
// store in the table announcement
$sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order', session_id=".intval($_SESSION['id_session']);
$result = Database::query($sql,__FILE__,__LINE__) or die (mysql_error());
//store the attach file
$last_id= Database::insert_id();
$save_attachment = add_announcement_attachment_file($last_id, $_FILES['user_upload'], $file_comment);
// store in item_property (first the groups, then the users
if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
{
@ -788,9 +808,7 @@ function store_advalvas_item($emailTitle,$newContent, $order, $to)
{
api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", $_user['user_id'], '0');
}
return $last_id;
}
@ -799,19 +817,23 @@ function store_advalvas_group_item($emailTitle,$newContent, $order, $to, $to_use
global $_course;
global $nameTools;
global $_user;
global $tbl_announcement;
global $tbl_item_property;
// database definitions
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$newContent=stripslashes($newContent);
$emailTitle = Database::escape_string(Security::remove_XSS($emailTitle));
$newContent = Database::escape_string(Security::remove_XSS($newContent,COURSEMANAGERLOWSECURITY));
$order = intval($order);
// store in the table announcement
$sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order', session_id=".intval($_SESSION['id_session']);
$result = Database::query($sql,__FILE__,__LINE__) or die (mysql_error());
$last_id= Database::insert_id();
$last_id = Database::insert_id();
// store in item_property (first the groups, then the users
if (!isset($to_users)) // !isset($to): when no user is selected we send it to everyone
{
@ -849,7 +871,7 @@ function store_advalvas_group_item($emailTitle,$newContent, $order, $to, $to_use
* This function stores the announcement Item in the table announcement
* and updates the item_property also
*/
function edit_advalvas_item($id,$emailTitle,$newContent,$to)
function edit_advalvas_item($id,$emailTitle,$newContent,$to, $file_comment='' )
{
global $_course;
@ -862,16 +884,25 @@ function edit_advalvas_item($id,$emailTitle,$newContent,$to)
$newContent=stripslashes($newContent);
$emailTitle = Database::escape_string(Security::remove_XSS($emailTitle));
$newContent = Database::escape_string(Security::remove_XSS($newContent,COURSEMANAGERLOWSECURITY));
$order = intval($order);
// store the modifications in the table announcement
$sql = "UPDATE $tbl_announcement SET content='$newContent', title = '$emailTitle' WHERE id='$id'";
$sql = "UPDATE $tbl_announcement SET content='$newContent', title = '$emailTitle' WHERE id='$id'";
$result = Database::query($sql,__FILE__,__LINE__) or die (mysql_error());
if(empty($last_id)){
$last_id = $id;
$save_attachment = add_announcement_attachment_file($last_id, $_FILES['user_upload'], $file_comment);
}
$last_id = $id;
$edit_attachment = edit_announcement_attachment_file($last_id, $_FILES['user_upload'], $file_comment);
// we remove everything from item_property for this
$sql_delete="DELETE FROM $tbl_item_property WHERE ref='$id' AND tool='announcement'";
$result = Database::query($sql_delete,__FILE__,__LINE__) or die (mysql_error());
// store in item_property (first the groups, then the users
if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
{
@ -991,3 +1022,145 @@ function get_all_annoucement_by_user_course($course_db, $user_id)
return '';
}
}
/*
==============================================================================
ATTACHMENT FUNCTIONS
==============================================================================
*/
/**
* 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 Arthur Portugal
* @version November 2009, dokeos 1.8.6.2
*/
function get_attachment($announcement_id) {
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
$announcement_id=Database::escape_string($announcement_id);
$row=array();
$sql = 'SELECT id,path, filename,comment FROM '. $tbl_announcement_attachment.' WHERE announcement_id = '.(int)$announcement_id.'';
$result=Database::query($sql, __FILE__, __LINE__);
if (Database::num_rows($result)!=0) {
$row=Database::fetch_array($result,ASSOC);
}
return $row;
}
/**
* This function add a attachment file into announcement
* @param string a comment about file
* @param int last id from announcement table
*
*/
function add_announcement_attachment_file($last_id, $file = array(), $file_comment) {
global $_course;
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
// Storing the attachments
if(empty($_FILES['user_upload'])) {
$upload_ok = process_uploaded_file($_FILES['user_upload']);
}
if (!empty($upload_ok)) {
$courseDir = $_course['path'].'/upload/announcements';
$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 '.$tbl_announcement_attachment.'(filename,comment, path,announcement_id,size) '.
"VALUES ( '".$safe_file_name."', '".$file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".$_FILES['user_upload']['size']."' )";
$result=Database::query($sql, __LINE__, __FILE__);
$message.=' / '.get_lang('FileUploadSucces').'< br / > ';
//$last_id_file=Database::insert_id();
//api_item_property_update($_course, 'announcement_attachment', $last_id_file ,'AnnouncementAttachmentAdded', api_get_user_id());
//}
}
}
}
/**
* This function edit a attachment file into announcement
* @param string a comment about file
* @param int Agenda Id
* @param int attachment file Id
*/
function edit_announcement_attachment_file($last_id, $file = array(), $file_comment) {
global $_course;
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
// Storing the attachments
if(!empty($_FILES['user_upload'])) {
$upload_ok = process_uploaded_file($_FILES['user_upload']);
}
if (!empty($upload_ok)) {
$courseDir = $_course['path'].'/upload/announcements';
$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="UPDATE $tbl_announcement_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', announcement_id = '$last_id', size ='".$_FILES['user_upload']['size']."'
WHERE announcement_id = '$last_id'";
$result=Database::query($sql, __FILE__,__LINE__);
$message.=' / '.get_lang('FileUploadSucces').'< br / > ';
//api_item_property_update($_course, 'announcement_attachment', $last_id ,'AnnouncementAttachmentUpdated', api_get_user_id());
//}
}
}
}
/**
* This function delete a attachment file by id
* @param integer attachment file Id
*
*/
function delete_announcement_attachment_file($id) {
global $_course;
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
$id=Database::escape_string($id);
$sql="DELETE FROM $tbl_announcement_attachment WHERE id = $id";
error_log($sql);
$result=Database::query($sql, __FILE__,__LINE__);
// update item_property
//api_item_property_update($_course, 'announcement_attachment', $id,'AnnouncementAttachmentDeleted', api_get_user_id());
}