skala
Juan Carlos Raña 16 years ago
commit b9a84344ad
  1. 77
      main/admin/calendar.lib.php
  2. 9
      main/admin/calendar.php
  3. 8
      main/announcements/announcements.inc.php
  4. 34
      main/announcements/announcements.php
  5. 1
      main/calendar/agenda.inc.php
  6. 2
      main/exercice/exercice_submit.php
  7. 2
      main/inc/lib/add_course.lib.inc.php
  8. 13
      main/inc/lib/mail.lib.inc.php
  9. 540
      tests/main/admin/calendar.lib.test.php
  10. 20
      tests/main/inc/lib/course.lib.test.php

@ -480,6 +480,7 @@ function store_new_agenda_item()
} }
} }
return $last_id;*/ return $last_id;*/
return $last_id;
} }
/** /**
@ -609,31 +610,24 @@ function save_edit_agenda_item($id,$title,$content,$start_date,$end_date)
* by the course administrator * by the course administrator
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param integer the id of the agenda item wa are deleting * @param integer the id of the agenda item wa are deleting
* @return bool true if it's success or false otherwise
*/ */
function delete_agenda_item($id) function delete_agenda_item($id)
{ {
global $_course; global $_course;
$id=Database::escape_string($id);
if (is_allowed_to_edit() && !api_is_anonymous())
{
if (!empty($_GET['id']) && isset($_GET['action']) && $_GET['action']=="delete")
{
$t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$id=(int)addslashes($_GET['id']); $id = intval($id);
$sql = "SELECT * FROM $t_agenda WHERE id = $id"; $sql = "SELECT * FROM $t_agenda WHERE id = '$id'";
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql,__FILE__,__LINE__);
if(Database::num_rows($res) > 0) if(Database::num_rows($res) > 0)
{ {
$sql = "DELETE FROM ".$t_agenda." WHERE id='$id'"; $sql = "DELETE FROM ".$t_agenda." WHERE id='$id'";
$result = Database::query($sql,__FILE__,__LINE__) or die (Database::error()); $result = Database::query($sql,__FILE__,__LINE__) or die (Database::error());
}
api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,'delete',api_get_user_id()); api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,'delete',api_get_user_id());
$id=null; return true;
echo '<br />';
Display::display_normal_message(get_lang("AgendaDeleteSuccess"));
}
} }
return false;
} }
/** /**
* Makes an agenda item visible or invisible for a student * Makes an agenda item visible or invisible for a student
@ -1057,9 +1051,9 @@ function display_one_agenda_item($agenda_id)
// the message has been sent to // the message has been sent to
echo "\t\t<td class=\"".$stylenotbold."\">".get_lang("SentTo").": ".get_lang('AllUsersOfThePlatform'); echo "\t\t<td class=\"".$stylenotbold."\">".get_lang("SentTo").": ".get_lang('AllUsersOfThePlatform');
$sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]); //$sent_to = sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
$sent_to_form=sent_to_form($sent_to); //sent_to_form=sent_to_form($sent_to);
echo $sent_to_form; //echo $sent_to_form;
echo "</td>\n\t</tr>\n"; echo "</td>\n\t</tr>\n";
/*-------------------------------------------------- /*--------------------------------------------------
@ -1097,6 +1091,7 @@ function display_one_agenda_item($agenda_id)
/*-------------------------------------------------- /*--------------------------------------------------
DISPLAY: the added resources DISPLAY: the added resources
--------------------------------------------------*/ --------------------------------------------------*/
/*
if (check_added_resources("Agenda", $myrow["id"])) if (check_added_resources("Agenda", $myrow["id"]))
{ {
echo "<tr><td colspan='2'>"; echo "<tr><td colspan='2'>";
@ -1108,7 +1103,7 @@ function display_one_agenda_item($agenda_id)
display_added_resources("Agenda", $myrow["id"], $addedresource_style); display_added_resources("Agenda", $myrow["id"], $addedresource_style);
echo "</td></tr>"; echo "</td></tr>";
} }
*/
/*-------------------------------------------------- /*--------------------------------------------------
DISPLAY: edit delete button (course admin only) DISPLAY: edit delete button (course admin only)
--------------------------------------------------*/ --------------------------------------------------*/
@ -1146,6 +1141,7 @@ function display_one_agenda_item($agenda_id)
"</table>"; "</table>";
} }
/** /**
* (This function is probably deprecated for this module)
* Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
* agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
* we have to retrieve the information that is in the database and use this information in the forms. * we have to retrieve the information that is in the database and use this information in the forms.
@ -1155,7 +1151,8 @@ function display_one_agenda_item($agenda_id)
*/ */
function show_group_filter_form() function show_group_filter_form()
{ {
$group_list=get_course_groups(); /** @todo this select missing to implement */
//$group_list=get_course_groups();
echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">"; echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
echo "<option value=\"agenda.php?group=none\">show all groups</option>"; echo "<option value=\"agenda.php?group=none\">show all groups</option>";
@ -1165,16 +1162,19 @@ echo "<option value=\"agenda.php?group=none\">show all groups</option>";
echo "<option value=\"agenda.php?group=".$this_group['id']."\" "; echo "<option value=\"agenda.php?group=".$this_group['id']."\" ";
echo ($this_group['id']==$_SESSION['group'])? " selected":"" ; echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
echo ">".$this_group['name']."</option>"; echo ">".$this_group['name']."</option>";
}*/ }
*/
echo "</select>"; echo "</select>";
} }
function show_user_filter_form() function show_user_filter_form()
{ {
$user_list=get_course_users();
//echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">"; /** @todo this select missing to implement */
//echo "<option value=\"agenda.php?user=none\">show all users</option>";
//$user_list=get_course_users();
echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
echo "<option value=\"agenda.php?user=none\">show all users</option>";
/*foreach($user_list as $this_user) /*foreach($user_list as $this_user)
{ {
// echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>"; // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
@ -1187,12 +1187,13 @@ echo "</select>";
function show_user_group_filter_form() function show_user_group_filter_form()
{ {
/** @todo this select missing to implement */
echo "\n<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">"; echo "\n<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
echo "\n\t<option value=\"agenda.php?user=none\">".get_lang("ShowAll")."</option>"; echo "\n\t<option value=\"agenda.php?user=none\">".get_lang("ShowAll")."</option>";
// Groups // Groups
echo "\n\t<optgroup label=\"".get_lang("Groups")."\">"; echo "\n\t<optgroup label=\"".get_lang("Groups")."\">";
$group_list=get_course_groups(); //$group_list=get_course_groups();
/* foreach($group_list as $this_group) /* foreach($group_list as $this_group)
{ {
// echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>"; // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
@ -1204,7 +1205,7 @@ function show_user_group_filter_form()
// Users // Users
echo "\n\t<optgroup label=\"".get_lang("Users")."\">"; echo "\n\t<optgroup label=\"".get_lang("Users")."\">";
$user_list=get_course_users(); //$user_list=get_course_users();
/* foreach($user_list as $this_user) /* foreach($user_list as $this_user)
{ {
// echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>"; // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
@ -1617,7 +1618,7 @@ function get_agendaitems($month, $year)
$items = array (); $items = array ();
//databases of the courses //databases of the courses
$TABLEAGENDA = Database :: get_course_table(TABLE_MAIN_SYSTEM_CALENDAR); $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
//$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
//$group_memberships = GroupManager :: get_group_ids(Database::get_current_course_database(), $_user['user_id']); //$group_memberships = GroupManager :: get_group_ids(Database::get_current_course_database(), $_user['user_id']);
@ -2170,7 +2171,7 @@ function get_repeated_events_day_view($course_info,$start=0,$end=0,$params)
//$db_end = date('Y-m-d H:i:s',$end); //$db_end = date('Y-m-d H:i:s',$end);
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
//$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
$sql = "SELECT c.id, c.title, c.content, " . $sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
@ -2298,10 +2299,10 @@ function get_repeated_events_week_view($course_info,$start=0,$end=0,$params)
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
//$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); //$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
//$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); //$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
$sql = "SELECT c.id, c.title, c.content " . $sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end " .
" FROM ". $t_cal ." " FROM ". $t_cal ."
WHERE c.start_date <= '$db_start' " AS c WHERE c.start_date <= '$db_start' "
.(!empty($params['conditions'])?$params['conditions']:'') .(!empty($params['conditions'])?$params['conditions']:'')
.(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'') .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
.(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:''); .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
@ -2422,8 +2423,8 @@ function get_repeated_events_month_view($course_info,$start=0,$end=0,$params)
//$db_end = date('Y-m-d H:i:s',$end); //$db_end = date('Y-m-d H:i:s',$end);
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
//$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
//$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
$sql = "SELECT c.id, c.title, c.content, " . $sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
" cr.cal_type, cr.cal_end " . " cr.cal_type, cr.cal_end " .
@ -2593,8 +2594,8 @@ function get_repeated_events_list_view($course_info,$start=0,$end=0,$params)
//$db_end = date('Y-m-d H:i:s',$end); //$db_end = date('Y-m-d H:i:s',$end);
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
//$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
//$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
$sql = "SELECT c.id, c.title, c.content, " . $sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
" cr.cal_type, cr.cal_end " . " cr.cal_type, cr.cal_end " .
@ -2883,7 +2884,9 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
// store in last_tooledit (first the groups, then the users // store in last_tooledit (first the groups, then the users
$done = false; $done = false;
if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) // !is_null($to): when no user is selected we send it to everyone
//(This part of this code is not been used)
/* if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) // !is_null($to): when no user is selected we send it to everyone
{ {
$send_to=separate_users_groups($to); $send_to=separate_users_groups($to);
// storing the selected groups // storing the selected groups
@ -2913,7 +2916,7 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
// storing the resources // storing the resources
if (!empty($_SESSION['source_type']) && !empty($last_id)) { if (!empty($_SESSION['source_type']) && !empty($last_id)) {
//store_resources($_SESSION['source_type'],$last_id); //store_resources($_SESSION['source_type'],$last_id);
} }*/
return $last_id; return $last_id;
} }
/** /**
@ -2960,7 +2963,9 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
} }
return $data; return $data;
} }
/**
* This function is not been used or deprecated
*/
function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest) function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest)
{/* {/*
$t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);

@ -320,7 +320,14 @@ if (api_is_allowed_to_edit(false,true))
$id=(int)$_GET['id']; $id=(int)$_GET['id'];
if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
{ // a coach can only delete an element belonging to his session { // a coach can only delete an element belonging to his session
delete_agenda_item($id); if (is_allowed_to_edit() && !api_is_anonymous()) {
if (!empty($id)) {
$res_del = delete_agenda_item($id);
if ($res_del) {
Display::display_normal_message(get_lang("AgendaDeleteSuccess"));
}
}
}
} }
if (api_get_setting('display_upcoming_events') == 'true') { if (api_get_setting('display_upcoming_events') == 'true') {
display_upcoming_events(); display_upcoming_events();

@ -792,8 +792,8 @@ function store_advalvas_item($emailTitle, $newContent, $order, $to, $file_commen
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
// filter data // filter data
$emailTitle = Database::escape_string(Security::remove_XSS($emailTitle)); $emailTitle = Database::escape_string($emailTitle);
$newContent = Database::escape_string(Security::remove_XSS($newContent,COURSEMANAGERLOWSECURITY)); $newContent = Database::escape_string($newContent);
$order = intval($order); $order = intval($order);
// store in the table announcement // store in the table announcement
@ -848,8 +848,8 @@ function store_advalvas_group_item($emailTitle,$newContent, $order, $to, $to_use
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$newContent=stripslashes($newContent); $newContent=stripslashes($newContent);
$emailTitle = Database::escape_string(Security::remove_XSS($emailTitle)); $emailTitle = Database::escape_string($emailTitle);
$newContent = Database::escape_string(Security::remove_XSS($newContent,COURSEMANAGERLOWSECURITY)); $newContent = Database::escape_string($newContent);
$order = intval($order); $order = intval($order);
// store in the table announcement // store in the table announcement

@ -135,8 +135,8 @@ require_once($lib.'fileUpload.lib.php');
----------------------------------------------------------- -----------------------------------------------------------
*/ */
$safe_emailTitle = Security::remove_XSS($_POST['emailTitle']); $safe_emailTitle = $_POST['emailTitle'];
$safe_newContent = Security::remove_XSS($_POST['newContent']); $safe_newContent = $_POST['newContent'];
if (!empty($_POST['To'])) if (!empty($_POST['To']))
{ {
@ -668,12 +668,9 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
if ($sqlmail != '') { if ($sqlmail != '') {
$result = Database::query($sqlmail,__FILE__,__LINE__); $result = Database::query($sqlmail,__FILE__,__LINE__);
/*================================================================================= /*=================================================================================
send email one by one to avoid antispam send email one by one to avoid antispam
=================================================================================*/ =================================================================================*/
$db_name = Database::get_course_table(TABLE_MAIN_SURVEY); $db_name = Database::get_course_table(TABLE_MAIN_SURVEY);
while ($myrow = Database::fetch_array($result)) { while ($myrow = Database::fetch_array($result)) {
/* Header : Bericht van uw lesgever - GES ($_cid) /* Header : Bericht van uw lesgever - GES ($_cid)
@ -695,11 +692,8 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
$newContentfive=str_replace("#db_name#",$db_name,$newContentfour); $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
$newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive); $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
$message=stripslashes($newContentsix); $message=stripslashes($newContentsix);
$sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS); $sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS);
$email = $_SESSION['_user']['mail']; $email = $_SESSION['_user']['mail'];
$headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15"; $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
//@mail($myrow["email"],stripslashes($emailTitle),$message,$headers); //@mail($myrow["email"],stripslashes($emailTitle),$message,$headers);
api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email); api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
@ -719,15 +713,25 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
//set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first) //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) //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
//$to_email_address =$_POST['emailsAdd']; $recipient_name = api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS);
//$mail_body;
$headers = array();
if (empty($charset)) { $charset='ISO-8859-1';}
$headers['Content-Type'] = 'text/html';
$headers['charset'] = $charset;
$mailid = $myrow["email"]; $mailid = $myrow["email"];
$newmail = api_mail_html(api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS), $myrow["email"], stripslashes($emailSubject), $mail_body, api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS), $_SESSION['_user']['mail'],$headers); $sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS);
$sender_email = $_SESSION['_user']['mail'];
$data_file = array();
if (!empty($_FILES['user_upload'])) {
$courseDir = $_course['path'].'/upload/announcements/';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$sql = 'SELECT path, filename FROM '.$tbl_announcement_attachment.'
WHERE id = "'.$insert_id.'"';
$result = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($result);
$data_file = array('path' => $sys_course_path.$courseDir.$row['path'],
'filename' => $row['filename']);
}
api_mail_html($recipient_name, $mailid, stripslashes($emailSubject), $mail_body, $sender_name, $sender_email, null, $data_file);
} }
$sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'"; $sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";

@ -3741,6 +3741,7 @@ function get_repeated_events_day_view($course_info,$start=0,$end=0,$params)
return $events; return $events;
} }
/** /**
* (This function is not been use in the code)
* Get repeated events of a course between two dates (timespan of a week). * Get repeated events of a course between two dates (timespan of a week).
* Returns an array containing the events * Returns an array containing the events
* @param string Course info array (as returned by api_get_course_info()) * @param string Course info array (as returned by api_get_course_info())

@ -249,7 +249,7 @@ if (!isset($_SESSION['expired_time'])) {
} }
if ($exercise_row['expired_time'] != 0) { if ($exercise_row['expired_time'] != 0) { //Sends the exercice form when the expired time is finished
$htmlHeadXtra[] = "<script type=\"text/javascript\"> $htmlHeadXtra[] = "<script type=\"text/javascript\">
$(document).ready(function(){ $(document).ready(function(){
$('#text-content').epiclock({ $('#text-content').epiclock({

@ -1948,7 +1948,7 @@ function lang2db($string)
* Fills the course database with some required content and example content. * Fills the course database with some required content and example content.
* @version 1.2 * @version 1.2
*/ */
function fill_Db_course($courseDbName, $courseRepository, $language,$default_document_array) function fill_Db_course($courseDbName, $courseRepository, $language,$default_document_array = array())
{ {
global $_configuration, $clarolineRepositoryWeb, $_user; global $_configuration, $clarolineRepositoryWeb, $_user;

@ -109,11 +109,12 @@ function api_mail($recipient_name, $recipient_email, $subject, $message, $sender
* @param string email body * @param string email body
* @param string sender name * @param string sender name
* @param string sender e-mail * @param string sender e-mail
* @param array data file (path and filename)
* @param array extra headers in form $headers = array($name => $value) to allow parsing * @param array extra headers in form $headers = array($name => $value) to allow parsing
* @return returns true if mail was sent * @return returns true if mail was sent
* @see class.phpmailer.php * @see class.phpmailer.php
*/ */
function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name="", $sender_email="", $extra_headers=null) { function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = "", $sender_email = "", $extra_headers = null, $data_file = array()) {
global $regexp; global $regexp;
global $platform_email; global $platform_email;
@ -155,7 +156,6 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
//$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; //Disposition-Notification //$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; //Disposition-Notification
} }
if ($sender_name!="") if ($sender_name!="")
{ {
$mail->FromName = $sender_name; $mail->FromName = $sender_name;
@ -165,8 +165,15 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
$mail->FromName = $platform_email['SMTP_FROM_NAME']; $mail->FromName = $platform_email['SMTP_FROM_NAME'];
} }
$mail->Subject = $subject; $mail->Subject = $subject;
$mail->AltBody = strip_tags(str_replace('<br />',"\n",$message));
$mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
$mail->Body = '<html><head></head><body>'.$message.'</body></html>'; $mail->Body = '<html><head></head><body>'.$message.'</body></html>';
// attachment ...
if (!empty($data_file)) {
$mail->AddAttachment($data_file['path'], $data_file['filename']);
}
// only valid address // only valid address
if(is_array($recipient_email)) if(is_array($recipient_email))
{ {

@ -3,6 +3,7 @@
require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php"); require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php'); require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
require_once(api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php'); require_once(api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
Mock::generate('Database'); Mock::generate('Database');
Mock::generate('Display'); Mock::generate('Display');
class TestCalendar extends UnitTestCase { class TestCalendar extends UnitTestCase {
@ -12,6 +13,14 @@ class TestCalendar extends UnitTestCase {
} }
public function setUp(){
$this->tcourse = new CourseManager();
}
public function tearDown(){
$this->tcourse = null;
}
public function testDisplayMinimonthcalendar(){ public function testDisplayMinimonthcalendar(){
ob_start(); ob_start();
global $DaysShort; global $DaysShort;
@ -55,11 +64,14 @@ class TestCalendar extends UnitTestCase {
public function testStoreNewAgendaItem(){ public function testStoreNewAgendaItem(){
global $_user; global $_user;
$res = store_new_agenda_item(); $res_store = store_new_agenda_item();
$this->assertFalse($res); $this->assertTrue(is_numeric($res_store));
$this->assertTrue(is_null($res));
$this->assertNull($res); //delete the new agenda item in the database
//var_dump($res); if (is_numeric($res_store)) {
$res_delete = delete_agenda_item($res_store);
$this->assertTrue(is_numeric($res_store));
}
} }
public function testDisplayCourseadminLinks(){ public function testDisplayCourseadminLinks(){
@ -80,24 +92,11 @@ class TestCalendar extends UnitTestCase {
} }
public function testGetAgendaItem(){ public function testGetAgendaItem(){
$realgrouplist= new MockDatabase(); $id=4;
$id=1;
$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$sql= "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."'";
$sql_result = Database::query($sql,__FILE__,__LINE__);
$result= Database::fetch_array($result);
$real_list[] = $result;
$res = get_agenda_item($id); $res = get_agenda_item($id);
if(is_array($real_list)) if(is_array($res)) {
$this->assertTrue(is_array($real_list));
else{
$this->assertTrue(is_null($real_list));
$this->assertTrue($real_list === true || $real_list === false);
}
$realgrouplist->expectOnce($real_list);
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
//var_dump($real_list); }
//var_dump($res);
} }
public function testStoreEditedAgendaItem(){ public function testStoreEditedAgendaItem(){
@ -132,111 +131,69 @@ class TestCalendar extends UnitTestCase {
//var_dump($res); //var_dump($res);
//var_dump($TABLEAGENDA); //var_dump($TABLEAGENDA);
} }
/**
public function testDeleteAgendaItem(){ * Makes an agenda item visible or invisible for a student
$realagenda= new MockDatabase(); * @param integer id the id of the agenda item we are changing the visibility of
$realagenda1 = new MockDisplay(); */
global $_course;
$id=Database::escape_string($id);
$res = delete_agenda_item($id);
$sql = "SELECT * FROM $t_agenda WHERE id = $id";
$sql_result = Database::query($sql,__FILE__,__LINE__);
$result = Database::fetch_array($sql_result);
$real_agenda[] = $result;
$res= delete_agenda_item($id);
$realagenda->expectOnce($real_agenda);
$this->assertTrue($real_agenda);
$this->assertTrue(is_null($res));
$this->assertTrue(is_array($real_agenda));
//var_dump($res);
//var_dump($real_agenda);
}
public function testShowhideAgendaItem(){ public function testShowhideAgendaItem(){
ob_start(); ob_start();
$instans = new MockDisplay();
$id=1; $id=1;
global $nameTools; global $nameTools;
$res = showhide_agenda_item($id); $res = showhide_agenda_item($id);
//Show the message when the visibility was changed
$real_show = Display::display_normal_message(get_lang("VisibilityChanged")); $real_show = Display::display_normal_message(get_lang("VisibilityChanged"));
$instans_real[] = $real_show;
$instans->expectOnce($instans_real);
ob_end_clean(); ob_end_clean();
$this->assertTrue(is_object($instans)); if(!empty($res)){
$this->assertTrue(is_array($instans_real)); $this->assertTrue($res);
//var_dump($instans); $this->assertTrue($real_show);
} else {
$this->assertNull($res);
}
//var_dump($res); //var_dump($res);
//var_dump($instans_real);
} }
/** /**
* Para poder ejecutar la funcion display_agenda_items(), es * Displays all the agenda items
* necesario comentar el die de la linea 718, porque sino, no se
* podria realizar la prueba.
*/ */
public function testDisplayAgendaItems(){ public function testDisplayAgendaItems(){
ob_start(); ob_start();
$realdisplay = new MockDatabase(); $_SESSION['is_courseAdmin'] = 1;
$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
global $select_month, $select_year;
global $DaysShort, $DaysLong, $MonthsLong;
global $is_courseAdmin;
global $dateFormatLong, $timeNoSecFormat,$charset, $_user, $_course;
$sql = "SELECT * FROM ".$TABLEAGENDA.' ORDER BY start_date '.$_SESSION['sort'];
$result=Database::query($sql,__FILE__,__LINE__);
$real_display[] = $result;
$res = display_agenda_items(); $res = display_agenda_items();
ob_end_clean(); ob_end_clean();
$realdisplay->expectOnce($real_display);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertTrue(is_array($real_display));
$realdisplay->expectOnce($real_display);
//var_dump($res);
//var_dump($real_display);
//var_dump($realdisplay);
} }
/** /**
* Para poder ejecutar esta prueba es necesario comentar el * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
* die de la linea 984.
*/ */
public function testDisplayOneAgendaItem(){ public function testDisplayOneAgendaItem(){
ob_start(); ob_start();
$realdisplayone = new MockDatabase(); $agenda_id=1;
$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $res = display_one_agenda_item($agenda_id);
global $TABLE_ITEM_PROPERTY;
global $select_month, $select_year;
global $DaysShort, $DaysLong, $MonthsLong;
global $is_courseAdmin;
global $dateFormatLong, $timeNoSecFormat, $charset;
global $_user;
$agenda_id=2;
$agenda_id=Database::escape_string($agenda_id);
$sql = "SELECT * FROM ".$TABLEAGENDA;
$sql_result=Database::query($sql,__FILE__,__LINE__);
$myrow=Database::fetch_array($sql_result);
$real_display_one[]= $$myrow;
//$res = display_one_agenda_item($agenda_id);
ob_end_clean(); ob_end_clean();
$realdisplayone->expectOnce($real_display_one); $this->assertTrue(is_null($res));
$this->assertTrue(is_array($real_display_one));
//var_dump($res);
//var_dump($realdisplayone);
//var_dump($real_display_one);
} }
/*public function testShowGroupFilterForm(){ /**
$group_list=get_course_groups(); * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
* agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
* we have to retrieve the information that is in the database and use this information in the forms.
*/
public function testShowGroupFilterForm(){
ob_start();
$res = show_group_filter_form(); $res = show_group_filter_form();
$this->assertTrue($res); ob_end_clean();
//var_dump($res); $this->assertTrue(is_null($res));
} }
public function testShowUserFilterForm(){ public function testShowUserFilterForm(){
ob_start();
$res = show_user_filter_form(); $res = show_user_filter_form();
$this->assertTrue($res); ob_end_clean();
//var_dump($res); $this->assertTrue(is_null($res));
} }
*/
public function testShowAddForm(){ public function testShowAddForm(){
ob_start(); ob_start();
global $MonthsLong; global $MonthsLong;
@ -248,52 +205,23 @@ class TestCalendar extends UnitTestCase {
} }
public function testGetAgendaitems(){ public function testGetAgendaitems(){
$realgetagenda = new MockDatabase(); global $_user;
$$TABLEAGENDA = Database :: get_course_table(TABLE_MAIN_SYSTEM_CALENDAR); global $_configuration;
$month=06; $month='12';
$year=2010; $year='2009';
global $MonthsLong;
$month=Database::escape_string($month);
$year=Database::escape_string($year);
$sqlquery = "SELECT
DISTINCT *
FROM ".$TABLEAGENDA."
WHERE
MONTH(start_date)='".$month."'
AND YEAR(start_date)='".$year."'
GROUP BY id
ORDER BY start_date ";
$sql_result = Database::query($sqlquery, __FILE__, __LINE__);
$result = Database::fetch_array($sql_result);
$real_get_agenda[] = $result;
$res = get_agendaitems($month, $year); $res = get_agendaitems($month, $year);
if(is_array($res)) {
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
$realgetagenda->expectOnce($real_get_agenda); }
$this->assertTrue(is_array($real_get_agenda));
//var_dump($res);
//var_dump($real_get_agenda);
//var_dump($realgetagenda);
} }
public function testDisplayUpcomingEvents(){ public function testDisplayUpcomingEvents(){
ob_start(); ob_start();
$realdisplay = new MockDatabase();
$TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$sqlquery = "SELECT
DISTINCT *
FROM ".$TABLEAGENDA."
ORDER BY start_date ";
$result = Database::query($sqlquery, __FILE__, __LINE__);
$resultado = Database::fetch_array($result,'ASSOC');
$real_display[] = $resultado;
$res = display_upcoming_events(); $res = display_upcoming_events();
$realdisplay->expectOnce($real_display);
ob_end_clean(); ob_end_clean();
$this->assertTrue(is_array($real_display)); $this->assertNull($res);
$this->assertTrue(is_null($res));
//var_dump($real_display);
//var_dump($realdisplay);
//var_dump($res);
} }
public function testCalculateStartEndOfWeek(){ public function testCalculateStartEndOfWeek(){
@ -333,196 +261,84 @@ class TestCalendar extends UnitTestCase {
} }
public function testGetDayAgendaitems() { public function testGetDayAgendaitems() {
$realgetday = new MockDatabase(); $courses_dbs=array();
$TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $month='12';
global $_user; $year='2009';
global $_configuration; $day='1';
global $setting_agenda_link;
$courses_dbs='';
$month=11;
$year=2009;
$day='';
$sqlquery = "SELECT DISTINCT *
FROM ".$TABLEAGENDA."
WHERE
DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
GROUP BY agenda.id
ORDER BY start_date ";
$result = Database::query($sqlquery, __FILE__, __LINE__);
$item = Database::fetch_array($result);
$real_get_day[] = $item;
$res = get_day_agendaitems($courses_dbs, $month, $year, $day); $res = get_day_agendaitems($courses_dbs, $month, $year, $day);
$realgetday->expectOnce($real_get_day);
$this->assertTrue(is_array($real_get_day));
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
//var_dump($res); //var_dump($res);
//var_dump($real_get_day);
//var_dump($$realgetday);
} }
public function testGetWeekAgendaitems() { public function testGetWeekAgendaitems() {
$realgetweek = new MockDatabase(); $courses_dbs=array();
$TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $year='2009';
global $_user; $month='12';
global $_configuration; $res = get_week_agendaitems($courses_dbs, $month, $year);
global $setting_agenda_link;$month='';
$courses_dbs='';
$year='';
$week = '';
$sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA." ORDER BY start_date";
$result = Database::query($sqlquery, __FILE__, __LINE__);
$item = Database::fetch_array($result);
$real_get_week[]= $item;
$res = get_week_agendaitems($courses_dbs, $month, $year, $week);
$realgetweek->expectOnce($real_get_week);
$this->assertTrue(is_array($real_get_week));
$this->assertTrue($realgetweek);
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
//var_dump($res);
//var_dump($real_get_week);
//var_dump($realgetweek);
} }
public function testGetRepeatedEventsDayView(){ public function testGetRepeatedEventsDayView(){
$realgetrepeat = new MockDatabase();
$course_info=''; global $_configuration;
require_once api_get_path(SYS_PATH).'tests/main/inc/lib/add_course.lib.inc.test.php';
// create a course
$course_datos = array(
'wanted_code'=> 'COD21',
'title'=>'metodologia de calculo diferencial',
'tutor_name'=>'R. J. Wolfagan',
'category_code'=>'2121',
'course_language'=>'english',
'course_admin_id'=>'1211',
'db_prefix'=> $_configuration['db_prefix'].'COD21',
'db_prefix'=> $_configuration['db_prefix'].'COD21',
'firstExpirationDelay'=>'112'
);
$res = create_course($course_datos['wanted_code'], $course_datos['title'],
$course_datos['tutor_name'], $course_datos['category_code'],
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
if ($res) {
$start = 0; $start = 0;
$end = 0; $end = 0;
$params=''; $params='';
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); $course_code = 'COD21';
$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); $course_info = api_get_course_info($course_code);
$sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
" cr.cal_type, cr.cal_end " .
" FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
" WHERE cr.cal_end >= $start " .
" AND cr.cal_id = c.id " .
" AND item_property.ref = c.id ".
" AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
" AND c.start_date <= '$db_start' "
.(!empty($params['conditions'])?$params['conditions']:'')
.(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
.(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
$res = Database::query($sql,__FILE__,__LINE__);
$row = Database::fetch_array($res);
$real_get_repeat[] = $row;
$resul = get_repeated_events_day_view($course_info,$start,$end,$params); $resul = get_repeated_events_day_view($course_info,$start,$end,$params);
$realgetrepeat->expectOnce($real_get_repeat);
$this->assertTrue(is_array($real_get_repeat));
$this->assertTrue(is_array($resul)); $this->assertTrue(is_array($resul));
//var_dump($resul);
//var_dump($realgetrepeat); }
//var_dump($real_get_repeat);
} }
public function testget_repeated_events_week_view(){ public function testGetRepeatedEventsWeekView(){
$realgetrepeated = new MockDatabase(); $course_info = 'COD21';
$course_info=''; $resul = get_repeated_events_week_view($course_info, 0, 0, '');
$start=0;
$end=0;
$params='';
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$sql = "SELECT c.id, c.title, c.content " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
" FROM". $t_cal ."
WHERE c.start_date <= '$db_start' "
.(!empty($params['conditions'])?$params['conditions']:'')
.(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
.(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
$res = Database::query($sql,__FILE__,__LINE__);
$row = Database::fetch_array($res);
$real_get_repeated[] = $row;
$resul = get_repeated_events_week_view($course_info,$start,$end,$params);
$realgetrepeated->expectOnce($real_get_repeated);
$this->assertTrue(is_array($resul)); $this->assertTrue(is_array($resul));
$this->assertTrue($real_get_repeated);
//var_dump($resul);
//var_dump($real_get_repeated);
//var_dump($realgetrepeated);
} }
public function testGetRepeatedEventsMonthView(){ public function testGetRepeatedEventsMonthView(){
$realgetrepeated= new MockDatabase(); $course_code='COD21';
$course_info=''; $course_info = api_get_course_info($course_code);
$start=''; $resul= get_repeated_events_month_view($course_info,0,0,'');
$end='';
$params='';
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
" cr.cal_type, cr.cal_end " .
" FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
" WHERE cr.cal_end >= $start " .
" AND cr.cal_id = c.id " .
" AND item_property.ref = c.id ".
" AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
" AND c.start_date <= '$db_start' "
.(!empty($params['conditions'])?$params['conditions']:'')
.(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
.(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
$res = Database::query($sql,__FILE__,__LINE__);
$row = Database::fetch_array($res);
$real_get_repeated[] = $row;
$resul= get_repeated_events_month_view($course_info,$start,$end,$params);
$realgetrepeated->expectOnce($real_get_repeated);
$this->assertTrue(is_array($resul)); $this->assertTrue(is_array($resul));
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false || $res === true);
$this->assertTrue($real_get_repeated);
//var_dump($resul); //var_dump($resul);
//var_dump($real_get_repeated);
//var_dump($realgetrepeated);
} }
public function testGetRepeatedEventsListView(){ public function testGetRepeatedEventsListView(){
$realgetrepeatedevents = new MockDatabase(); $course_code='COD21';
$course_info=''; $course_info = api_get_course_info($course_code);
$start=0; $resul = get_repeated_events_list_view($course_info,0,0,'');
$end=0;
$params='';
$t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
$sql = "SELECT c.id, c.title, c.content, " .
" UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
" cr.cal_type, cr.cal_end " .
" FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
" WHERE cr.cal_end >= $start " .
" AND cr.cal_id = c.id " .
" AND item_property.ref = c.id ".
" AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
" AND c.start_date <= '$db_start' "
.(!empty($params['conditions'])?$params['conditions']:'')
.(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
.(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
$res = Database::query($sql,__FILE__,__LINE__);
$row = Database::fetch_array($res);
$real_get_repeated_events[] = $row;
$resul = get_repeated_events_list_view($course_info,$start,$end,$params);
$realgetrepeatedevents->expectOnce($real_get_repeated_events);
$this->assertTrue(is_array($real_get_repeated_events));
$this->assertTrue(is_array($resul)); $this->assertTrue(is_array($resul));
$realgetrepeatedevents->expectCallCount($real_get_repeated_events);
//var_dump($resul); //var_dump($resul);
//var_dump($real_get_repeated_events);
//var_dump($realgetrepeatedevents);
} }
public function testIsRepeatedEvent() { public function testIsRepeatedEvent() {
$realrepetead = new MockDatabase(); //This is deprecated or not used
$id=1;
$course=null;
$sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
$res = Database::query($sql,__FILE__,__LINE__);
$result = Database::num_rows($res)>0;
$real_repetead[] = $result;
$resu = is_repeated_event($id,$course);
$realrepetead->expectOnce($real_repetead);
$this->assertTrue(is_bool($resu));
$this->assertTrue($resu === true || $resu === false);
$this->assertTrue($real_repetead);
$this->assertTrue($realrepetead);
//var_dump($resu);
//var_dump($real_repetead);
//var_dump($realrepetead);
} }
public function testAddWeek(){ public function testAddWeek(){
@ -548,103 +364,51 @@ class TestCalendar extends UnitTestCase {
$this->assertTrue(is_numeric($res)); $this->assertTrue(is_numeric($res));
//var_dump($res); //var_dump($res);
} }
/** /**
* para poder realizar esta prueba, se tuvo que comentar el "die" ubicado en la * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
* linea 2877 para que la prueba pudiera ejecutarse de manera exitosa. * @param array Course info
* @param string Event title
* @param string Event content/description
* @param string Start date
* @param string End date
* @param array List of groups to which this event is added
* @param int Parent id (optional)
* @return int The new item's DB ID
*/ */
public function testAgendaAddItem(){ public function testAgendaAddItem(){
$realagenda = new MockDatabase();
global $_course; global $_course;
$course_info='null'; $course_code='COD21';
$course_info = api_get_course_info($course_code);
$title='test'; $title='test';
$content='test function'; $content='test function';
$db_start_date='07/11/2009'; $db_start_date='07/11/2009';
$db_end_date='07/20/2009'; $db_end_date='07/20/2009';
$to=array(); $res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to=array(), $parent_id=null);
$parent_id=null; $this->assertTrue(is_numeric($res));
$t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$title = Database::escape_string($title);
$content = Database::escape_string($content);
$start_date = Database::escape_string($db_start_date);
$end_date = Database::escape_string($db_end_date);
$sql = "SELECT * FROM $t_agenda WHERE title='$title' AND content = '$content' AND start_date = '$start_date'
AND end_date = '$end_date' ".(!empty($parent_id)? "AND parent_event_id = '$parent_id'":"");
$result = Database::query($sql,__FILE__,__LINE__);
$sql1 = "INSERT INTO ".$t_agenda."(title,content, start_date, end_date)VALUES
('".$title."','".$content."', '".$start_date."','".$end_date."')";
$result1 = Database::query($sql1,__FILE__,__LINE__);
$real_agenda[]= $result;
$real_agenda1[]= $result1;
//$res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to, $parent_id);
$realagenda->expectOnce($real_agenda);
$realagenda->expectOnce($real_agenda1);
//$this->assertTrue(is_numeric($res));
$this->assertTrue(is_array($real_agenda));
$this->assertTrue(is_array($real_agenda1));
//var_dump($res); //var_dump($res);
//var_dump($real_agenda);
//var_dump($real_agenda1);
} }
/**
* Adds a repetitive item to the database
* @param array Course info
* @param int The original event's id
* @param string Type of repetition
* @param int Timestamp of end of repetition (repeating until that date)
* @param array Original event's destination
* @return boolean False if error, True otherwise
*/
public function testGetCalendarItems(){ public function testGetCalendarItems(){
$realgetcalendar = new MockDatabase(); global $_course;
global $_user, $_course; $month='12';
global $is_allowed_to_edit;
$month='march';
$year='2009'; $year='2009';
$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$sql="SELECT
DISTINCT *
FROM ".$TABLEAGENDA." agenda
WHERE MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
GROUP BY id ".
"ORDER BY start_date ";
$result=Database::query($sql,__FILE__,__LINE__);
$row=Database::fetch_array($result);
$res = get_calendar_items($month, $year); $res = get_calendar_items($month, $year);
$real_get_calendar[]= $row;
$realgetcalendar->expectOnce($real_get_calendar);
$realgetcalendar->expectCallCount($real_get_calendar);
$this->assertTrue(is_bool($row));
$this->assertTrue(is_array($real_get_calendar));
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
//var_dump($real_get_calendar);
//var_dump($row);
//var_dump($res); //var_dump($res);
} }
public function testAgendaAddRepeatItem(){ public function testAgendaAddRepeatItem(){
$realagenda = new MockDatabase(); //this function is not used or deprecated
$course_info='course of test';
$orig_id=001;
$type='daily';
$end=10;
$orig_dest='monday';
$t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
$sql = "SELECT title, content, start_date as sd, end_date as ed FROM $t_agenda WHERE id = $orig_id";
$res = Database::query($sql,__FILE__,__LINE__);
$row = Database::fetch_array($res);
$sql1 = "INSERT INTO $t_agenda_r (cal_id, cal_type, cal_end)" .
" VALUES ($orig_id,'$type',$end)";
$res1 = Database::query($sql1,__FILE__,__LINE__);
$resu= agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest);
$real_agenda[] = $row;
$realagenda->expectOnce($real_agenda);
$realagenda->expectCallCount($real_agenda);
$realagenda->expectOnce($t_agenda);
$realagenda->expectOnce($res1);
if(is_bool($resu)){
$this->assertTrue(is_bool($resu));
$this->assertTrue($resu === true || $resu===false);
}else
$this->assertTrue(is_null($resu));
$this->assertTrue(is_array($real_agenda));
$this->assertTrue($row);
//var_dump($resu);
//var_dump($res);
//var_dump($res1);
//var_dump($real_agenda);
} }
public function testAgendaImportIcal(){ public function testAgendaImportIcal(){
@ -660,32 +424,16 @@ class TestCalendar extends UnitTestCase {
}else{ }else{
$this->assertTrue($res); $this->assertTrue($res);
} }
} }
public function testDeleteAgendaItem(){
global $_course;
$course_code='COD21';
$id=1;
$res = delete_agenda_item($id);
$res = $this->tcourse->delete_course($course_code);
$this->assertTrue(is_null($res));
//var_dump($res);
}
} }
?> ?>

@ -329,7 +329,7 @@ class TestCourse extends UnitTestCase{
public function testGetGroupListOfCourse(){ public function testGetGroupListOfCourse(){
$grouplist = new MockDatabase(); $grouplist = new MockDatabase();
$course_code = 'TEST'; $course_code = 'COD12';
$course_info = Database :: get_course_info($course_code); $course_info = Database :: get_course_info($course_code);
$database_name = $course_info['db_name']; $database_name = $course_info['db_name'];
$session_id=1; $session_id=1;
@ -344,7 +344,7 @@ class TestCourse extends UnitTestCase{
public function testAttemptCreateVirtualCourse(){ public function testAttemptCreateVirtualCourse(){
$createvirtual = new MockDisplay(); $createvirtual = new MockDisplay();
$real_course_code = 'TEST'; $real_course_code = 'COD12';
$course_title = 'test'; $course_title = 'test';
$wanted_course_code = '01'; $wanted_course_code = '01';
$course_language= 'english'; $course_language= 'english';
@ -364,7 +364,7 @@ class TestCourse extends UnitTestCase{
$user_id = api_get_user_id(); $user_id = api_get_user_id();
$real_course_code = 'TEST'; $real_course_code = 'TEST';
$course_title = 'test'; $course_title = 'test';
$wanted_course_code = '01'; $wanted_course_code = 'COD12';
$course_language= 'english'; $course_language= 'english';
$course_category= 'lang'; $course_category= 'lang';
$course_sys_code = ''; $course_sys_code = '';
@ -389,12 +389,16 @@ class TestCourse extends UnitTestCase{
//var_dump($createvirtualcourse); //var_dump($createvirtualcourse);
} }
public function testDeleteCourse(){ public function testDeleteCourse($course_code = ''){
global $_configuration; global $_configuration;
$code = '01'; $code = 'COD12';
if (!empty($course_code)) {
$code = $course_code;
}
$res = $this->tcourse->delete_course($code); $res = $this->tcourse->delete_course($code);
$this->assertTrue($this->tcourse->delete_course()===null); $this->assertTrue($this->tcourse->delete_course()===null);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
} }
public function testCreateDatabaseDump(){ public function testCreateDatabaseDump(){
@ -408,7 +412,7 @@ class TestCourse extends UnitTestCase{
public function testUserCourseSort(){ public function testUserCourseSort(){
$user_id ='01'; $user_id ='01';
$course_code='0001'; $course_code='COD12';
$res = $this->tcourse->UserCourseSort($user_id,$course_code); $res = $this->tcourse->UserCourseSort($user_id,$course_code);
$this->assertTrue($res); $this->assertTrue($res);
$this->assertTrue(is_numeric($res)); $this->assertTrue(is_numeric($res));
@ -433,7 +437,7 @@ class TestCourse extends UnitTestCase{
public function testEmailToTutor() { public function testEmailToTutor() {
$user_id= ''; $user_id= '';
$course_code= 'test'; $course_code= 'COD12';
$res=CourseManager::email_to_tutor($course_code,$user_id); $res=CourseManager::email_to_tutor($course_code,$user_id);
$this->assertTrue(is_string($course_code)); $this->assertTrue(is_string($course_code));
//var_dump($res); //var_dump($res);
@ -488,7 +492,7 @@ class TestCourse extends UnitTestCase{
} }
public function testUpdateCourseExtraFieldValue(){ public function testUpdateCourseExtraFieldValue(){
$course_code = '0001'; $course_code = 'COD12';
$fname = ''; $fname = '';
$fvalue= ''; $fvalue= '';
$res = $this->tcourse->update_course_extra_field_value($course_code,$fname,$fvalue=''); $res = $this->tcourse->update_course_extra_field_value($course_code,$fname,$fvalue='');

Loading…
Cancel
Save