Source for file announcements.inc.php
Documentation is available at announcements.inc.php
<?php //$Id: announcements.inc.php 15247 2008-05-08 19:07:01Z juliomontoya $
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2008 Dokeos SPRL
Copyright (c) various contributors
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
==============================================================================
==============================================================================
* Include file with functions for the announcements module.
* @package dokeos.announcements
==============================================================================
==============================================================================
==============================================================================
* displays one specific announcement
* @param $announcement_id, the id of the announcement you want to display
* @todo more security checking
global $_user, $dateFormatLong;
$sql_query = " SELECT announcement.*, toolitemproperties.*
FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
WHERE announcement.id = toolitemproperties.ref
AND announcement.id = '$announcement_id'
AND toolitemproperties.tool='announcement'
AND (toolitemproperties.to_user_id='". $_user['user_id']. "' OR toolitemproperties.to_group_id='0')
AND toolitemproperties.visibility='1'
ORDER BY display_order DESC";
$sql_query = " SELECT announcement.*, toolitemproperties.*
FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
WHERE announcement.id = toolitemproperties.ref
AND announcement.id = '$announcement_id'
AND toolitemproperties.tool='announcement'
AND toolitemproperties.to_group_id='0'
AND toolitemproperties.visibility='1'";
$title = $result['title'];
$content = $result['content'];
$last_post_datetime = $result['insert_date'];// post time format datetime de mysql
list ($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
echo "<table height=\"100\" width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" id=\"agenda_list\">\n";
echo "<tr class=\"data\"><td>" . $title . "</td></tr>\n";
echo "<tr class=\"text\"><td>$content</td></tr>\n";
/*======================================
======================================*/
* this function shows the form for sending a message to a specific group or user.
echo "\n<table id=\"recipient_list\" style=\"display: none;\">\n";
// the form containing all the groups and all the users of the course
// the buttons for adding or removing groups/users
echo "\n\t\t<td valign=\"middle\">\n";
echo "\t\t<input type=\"button\" ",
"onClick=\"move(this.form.elements[0],this.form.elements[3])\" ",// 7 & 4 : fonts
"\n\t\t<input type=\"button\"",
"onClick=\"move(this.form.elements[3],this.form.elements[0])\" ",
// the form containing the selected groups and users
/*===========================================
CONSTRUCT_NOT_SELECT_SELECT_FORM
===========================================*/
* this function shows the form for sending a message to a specific group or user.
echo "\t\t<select name=\"not_selected_form[]\" size=5 style=\"width:200px\" multiple>\n";
// adding the groups to the select form
foreach($group_list as $this_group)
if (!in_array("GROUP:". $this_group['id'],$to_already_selected)) // $to_already_selected is the array containing the groups (and users) that are already selected
echo "\t\t<option value=\"GROUP:". $this_group['id']. "\">",
"G: ",$this_group['name']," - " . $this_group['userNb'] . " " . get_lang('Users') .
echo "\t\t<option value=\"\">---------------------------------------------------------</option>\n";
// adding the individual users to the select form
foreach($user_list as $this_user)
if (!in_array("USER:". $this_user["user_id"],$to_already_selected)) // $to_already_selected is the array containing the users (and groups) that are already selected
echo "\t\t<option value=\"USER:",$this_user["user_id"],"\">",
"",$this_user['lastName']," ",$this_user['firstName'],
/*==========================================
CONSTRUCT_SELECTED_SELECT_FORM
==========================================*/
* this function shows the form for sending a message to a specific group or user.
// we separate the $to_already_selected array (containing groups AND users into
$groups_to_already_selected= $groupuser['groups'];
$users_to_already_selected= $groupuser['users'];
// we load all the groups and all the users into a reference array that we use to search the name of the group / user
// we construct the form of the already selected groups / users
echo "\t\t<select name=\"selectedform[]\" size=\"5\" multiple style=\"width:200px\" width=\"200px\">";
foreach($to_already_selected as $groupuser)
list ($type,$id)= explode(":",$groupuser);
echo "\t\t<option value=\"". $groupuser. "\">G: ". $ref_array_groups[$id]['name']. "</option>";
foreach($ref_array_users as $key=> $value){
if($value['user_id']== $id){
echo "\t\t<option value=\"". $groupuser. "\">". $value['lastName']. " ". $value['firstName']. "</option>";
* this function shows the form for sending a message to a specific group or user.
echo "\n<table id=\"recipient_list\" style=\"display: none;\">\n";
echo "\t\t<select name=\"not_selected_form[]\" size=5 style=\"width:200px\" multiple>\n";
foreach($group_users as $user){
echo '<option value="'. $user['user_id']. '">'. $user['lastname']. ' '. $user['firstname']. '</option>';
// the buttons for adding or removing groups/users
echo "\n\t\t<td valign=\"middle\">\n";
echo "\t\t<input type=\"button\" ",
"onClick=\"move(this.form.elements[1],this.form.elements[4])\" ",// 7 & 4 : fonts
"\n\t\t<input type=\"button\"",
"onClick=\"move(this.form.elements[4],this.form.elements[1])\" ",
echo "\t\t<select name=\"selectedform[]\" size=5 style=\"width:200px\" multiple>\n";
==============================================================================
==============================================================================
* this function gets all the users of the course,
* including users from linked courses
//this would return only the users from real courses:
//$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id());
* this function gets all the groups of the course,
* not including linked courses
/*======================================
======================================*/
* This tools loads all the users and all the groups who have received
* a specific item (in this case an announcement item)
global $tbl_item_property;
$sql= "SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'";
$to_group= $row['to_group_id'];
// it was send to one specific user
$to[]= "USER:". $row['to_user_id'];
// it was sent to everyone
$to[]= "GROUP:". $row['to_group_id'];
/*======================================
USER_GROUP_FILTER_JAVASCRIPT
======================================*/
* returns the javascript for setting a filter
* this goes into the $htmlHeadXtra[] array
return "<script language=\"JavaScript\" type=\"text/JavaScript\">
function jumpMenu(targ,selObj,restore)
eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
if (restore) selObj.selectedIndex=0;
/*======================================
========================================*/
* returns all the javascript that is required for easily
* setting the target people/groups
* this goes into the $htmlHeadXtra[] array
return "<script type=\"text/javascript\" language=\"JavaScript\">
<!-- Begin javascript menu swapper
function move(fbox, tbox)
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
for (i = 0; i < tbox.options.length; i++)
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++)
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != \"\")
arrTbox[tLength] = fbox.options[i].text;
arrFbox[fLength] = fbox.options[i].text;
for(c = 0; c < arrFbox.length; c++)
no.value = arrLookup[arrFbox[c]];
for(c = 0; c < arrTbox.length; c++)
no.value = arrLookup[arrTbox[c]];
var f = document.new_calendar_item;
function selectAll(cbList,bSelect,showwarning)
for (var i=0; i<cbList.length; i++)
cbList[i].selected = cbList[i].checked = bSelect
function reverseAll(cbList)
for (var i=0; i<cbList.length; i++)
cbList[i].checked = !(cbList[i].checked)
cbList[i].selected = !(cbList[i].selected)
/*======================================
======================================*/
* constructs the form to display all the groups and users the message has been sent to
* input: $sent_to_array is a 2 dimensional array containing the groups and the users
* the first level is a distinction between groups and users:
* $sent_to_array['groups'] * and $sent_to_array['users']
* $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array
* containing all the id's of the groups (resp. users) who have received this message.
* @author Patrick Cool <patrick.cool@>
// we find all the names of the groups
// we count the number of users and the number of groups
if (isset ($sent_to_array['users']))
$number_users= count($sent_to_array['users']);
if (isset ($sent_to_array['groups']))
$number_groups= count($sent_to_array['groups']);
$total_numbers= $number_users+ $number_groups;
// starting the form if there is more than one user/group
$output= "<select name=\"sent to\">\n";
$output.= "<option>". get_lang("SentTo"). "</option>";
// outputting the name of the groups
foreach ($sent_to_array['groups'] as $group_id)
$output.= "\t<option value=\"\">G: ". $group_names[$group_id]['name']. "</option>\n";
if (isset ($sent_to_array['users']))
foreach ($sent_to_array['users'] as $user_id)
$output.= "\t<option value=\"\">". $user_info['lastName']. " ". $user_info['firstName']. "</option>\n";
else // there is only one user/group
if (isset ($sent_to_array['users']) and is_array($sent_to_array['users']))
echo $user_info['lastName']. " ". $user_info['firstName'];
if (isset ($sent_to_array['groups']) and is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]!== 0)
$group_id= $sent_to_array['groups'][0];
echo $group_names[$group_id]['name'];
if (isset ($sent_to_array['groups']) and is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]== 0)
/*======================================
======================================*/
* This function separates the users from the groups
* users have a value USER:XXX (with XXX the dokeos id
* groups have a value GROUP:YYY (with YYY the group id)
list ($type, $id) = explode(':', $to_item);
$send_to['groups']= $grouplist;
$send_to['users']= $userlist;
/*======================================
======================================*/
* returns all the users and all the groups a specific announcement item
global $tbl_item_property;
$sql= "SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='". $id. "'";
// if to_group_id is null then it is sent to a specific user
// if to_group_id = 0 then it is sent to everybody
$sent_to_group[]= $row['to_group_id'];
// if to_user_id <> 0 then it is sent to a specific user
if ($row['to_user_id'] <> 0)
$sent_to_user[]= $row['to_user_id'];
if (isset ($sent_to_group))
$sent_to['groups']= $sent_to_group;
if (isset ($sent_to_user))
$sent_to['users']= $sent_to_user;
/*===================================================
CHANGE_VISIBILITY($tool,$id)
=================================================*/
* This functions swithes the visibility a course resource
* using the visibility field in 'item_property'
* values: 0 = invisibility for
global $tbl_item_property;
$sql= "SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'";
if ($row['visibility']== '1')
$sql_visibility= "UPDATE $tbl_item_property SET visibility='0' WHERE tool='$tool' AND ref='$id'";
$sql_visibility= "UPDATE $tbl_item_property SET visibility='1' WHERE tool='$tool' AND ref='$id'";
/*====================================================
====================================================*/
global $tbl_announcement;
global $tbl_item_property;
// store in the table announcement
$sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order'";
// 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
// storing the selected groups
foreach ($send_to['groups'] as $group)
// storing the selected users
foreach ($send_to['users'] as $user)
else // the message is sent to everyone, so we set the group to 0
global $tbl_announcement;
global $tbl_item_property;
// store in the table announcement
$sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order'";
// 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
// storing the selected groups
foreach ($send_to['groups'] as $group)
else // the message is sent to everyone, so we set the group to 0
// storing the selected users
foreach ($to_users as $user)
/*==================================================
==================================================*/
* This function stores the announcement Item in the table announcement
* and updates the item_property also
global $tbl_announcement;
global $tbl_item_property;
// store the modifications in the table announcement
$sql = "UPDATE $tbl_announcement SET content='$newContent', title = '$emailTitle' WHERE id='$id'";
// we remove everything from item_property for this
$sql_delete= "DELETE FROM $tbl_item_property WHERE ref='$id' AND tool='announcement'";
// 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
// storing the selected groups
foreach ($send_to['groups'] as $group)
// storing the selected users
foreach ($send_to['users'] as $user)
else // the message is sent to everyone, so we set the group to 0
==============================================================================
==============================================================================
* Sends an announcement by email to a list of users.
* Emails are sent one by one to try to avoid antispam.
foreach ($user_list as $this_user)
/* Header : Bericht van uw lesgever - GES ($course_code) - Morgen geen les! ($mail_title)
Body : John Doe (prenom + nom) <john_doe@hotmail.com> (email)
Morgen geen les! ($mail_title)
Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
$mail_subject = get_lang('professorMessage'). ' - '. $_course['official_code']. ' - '. $mail_title;
$mail_body = '['. $_course['official_code']. '] - ['. $_course['name']. "]\n";
$mail_body .= $_user['firstName']. ' '. $_user['lastName']. ' ';
$mail_body .= '<'. $_user['mail']. ">\n";
$mail_body .= $_course['official_code']. ' '. $_course['name'];
//set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
//here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
if(empty($charset)){$charset= 'ISO-8859-1';}
$encoding = 'Content-Type: text/plain; charset='. $charset;
$newmail = api_mail($this_user['lastname']. ' '. $this_user['firstname'], $this_user['email'], $mail_subject, $mail_body, $_SESSION['_user']['lastName']. ' '. $_SESSION['_user']['firstName'], $_SESSION['_user']['mail'], $encoding);
global $tbl_announcement;
// store the modifications in the table tbl_annoucement
$sql = "UPDATE $tbl_announcement SET email_sent='1' WHERE id='$insert_id'";
|