Rework announcement see BT#10949

1.9.x
jmontoya 10 years ago
parent 6dd2462eb8
commit f150613d64
  1. 530
      main/announcements/announcements.inc.php
  2. 1517
      main/announcements/announcements.php
  3. 4
      main/forum/forumfunction.inc.php
  4. 37
      main/inc/ajax/announcement.ajax.php
  5. 34
      main/inc/ajax/model.ajax.php
  6. 176
      main/inc/lib/course.lib.php
  7. 102
      main/inc/lib/display.lib.php
  8. 26
      main/inc/lib/formvalidator/FormValidator.class.php
  9. 23
      main/inc/lib/main_api.lib.php
  10. 12
      main/inc/lib/pear/HTML/QuickForm.php

@ -204,12 +204,13 @@ class AnnouncementManager
}
$sql_result = Database::query($sql_query);
$html = null;
if (Database::num_rows($sql_result) > 0) {
$result = Database::fetch_array($sql_result, 'ASSOC');
$title = $result['title'];
$content = $result['content'];
echo "<table height=\"100\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" class=\"data_table\">";
echo "<tr><td><h2>" . $title . "</h2></td></tr>";
$html .= "<table height=\"100\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" class=\"data_table\">";
$html .= "<tr><td><h2>" . $title . "</h2></td></tr>";
if ($allowToEdit) {
$modify_icons = "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=modify&id=" . $announcement_id . "\">" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>";
@ -230,14 +231,13 @@ class AnnouncementManager
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) .
"</a>";
}
echo "<tr><th style='text-align:right'>$modify_icons</th></tr>";
$html .= "<tr><th style='text-align:right'>$modify_icons</th></tr>";
}
$content = self::parse_content($result['to_user_id'], $content, api_get_course_id(), api_get_session_id());
echo "<tr><td>$content</td></tr>";
echo "<tr><td class=\"announcements_datum\">" . get_lang('LastUpdateDate') . " : " . api_convert_and_format_date($result['insert_date'], DATE_TIME_FORMAT_LONG) . "</td></tr>";
$html .= "<tr><td>$content</td></tr>";
$html .= "<tr><td class=\"announcements_datum\">" . get_lang('LastUpdateDate') . " : " . api_convert_and_format_date($result['insert_date'], DATE_TIME_FORMAT_LONG) . "</td></tr>";
// User or group icon
$sent_to_icon = '';
@ -246,24 +246,26 @@ class AnnouncementManager
}
$sent_to = self::sent_to('announcement', $announcement_id);
$sent_to_form = self::sent_to_form($sent_to);
echo Display::tag('td', get_lang('SentTo') . ' : ' . $sent_to_form, array('class' => 'announcements_datum'));
$html .= Display::tag('td', get_lang('SentTo') . ' : ' . $sent_to_form, array('class' => 'announcements_datum'));
$attachment_list = self::get_attachment($announcement_id);
if (count($attachment_list) > 0) {
echo "<tr><td>";
$html .= "<tr><td>";
$realname = $attachment_list['path'];
$user_filename = $attachment_list['filename'];
$full_file_name = 'download.php?'.api_get_cidreq().'&file=' . $realname;
echo '<br/>';
echo Display::return_icon('attachment.gif', get_lang('Attachment'));
echo '<a href="' . $full_file_name . ' "> ' . $user_filename . ' </a>';
echo ' - <span class="forum_attach_comment" >' . $attachment_list['comment'] . '</span>';
$html .= '<br/>';
$html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
$html .= '<a href="' . $full_file_name . ' "> ' . $user_filename . ' </a>';
$html .= ' - <span class="forum_attach_comment" >' . $attachment_list['comment'] . '</span>';
if (api_is_allowed_to_edit(false, true)) {
echo Display::url(Display::return_icon('delete.png', get_lang('Delete'), '', 16), api_get_self() . "?" . api_get_cidreq() . "&action=delete_attachment&id_attach=" . $attachment_list['id'] . "&sec_token=" . $stok);
$html .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), '', 16), api_get_self() . "?" . api_get_cidreq() . "&action=delete_attachment&id_attach=" . $attachment_list['id'] . "&sec_token=" . $stok);
}
echo '</td></tr>';
$html .= '</td></tr>';
}
echo "</table>";
$html .= "</table>";
return $html;
} else {
return false;
}
@ -1217,4 +1219,502 @@ class AnnouncementManager
$email = AnnouncementEmail::create(null, $id);
$email->send($sendToUsersInSession);
}
/**
* @param $stok
* @param $announcement_number
* @param bool $getCount
* @param null $start
* @param null $limit
* @param string $sidx
* @param string $sord
* @param string $titleToSearch
* @param int $userIdToSearch
*
* @return array
*/
public static function getAnnouncements(
$stok,
$announcement_number,
$getCount = false,
$start = null,
$limit = null,
$sidx = '',
$sord = '',
$titleToSearch = '',
$userIdToSearch = 0
) {
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$user_id = api_get_user_id();
$group_id = api_get_group_id();
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id, true, true, 'announcement.session_id');
$course_id = api_get_course_int_id();
$_course = api_get_course_info();
$group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id());
$allowUserEditSetting = api_get_course_setting('allow_user_edit_announcement');
$select = ' DISTINCT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date';
if ($getCount) {
$select = ' COUNT(announcement.id) count';
}
$searchCondition = '';
if (!empty($titleToSearch)) {
$titleToSearch = Database::escape_string($titleToSearch);
$searchCondition .= " AND (title LIKE '%$titleToSearch%')";
}
if (!empty($userIdToSearch)) {
$userIdToSearch = intval($userIdToSearch);
$searchCondition .= " AND (ip.insert_user_id = $userIdToSearch)";
}
if (api_is_allowed_to_edit(false, true) ||
($allowUserEditSetting && !api_is_anonymous())
) {
// A.1. you are a course admin with a USER filter
// => see only the messages of this specific user + the messages of the group (s)he is member of.
//if (!empty($user_id)) {
if (0) {
if (is_array($group_memberships) && count($group_memberships) > 0 ) {
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref AND
ip.tool = 'announcement' AND
(
ip.to_user_id = $user_id OR
ip.to_group_id IS NULL OR
ip.to_group_id IN (0, ".implode(", ", $group_memberships).")
) AND
ip.visibility IN ('1', '0')
$condition_session
$searchCondition
ORDER BY display_order DESC";
} else {
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref AND
ip.tool ='announcement' AND
(ip.to_user_id = $user_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND
ip.visibility IN ('1', '0')
$condition_session
$searchCondition
ORDER BY display_order DESC";
}
} elseif ($group_id != 0) {
// A.2. you are a course admin with a GROUP filter
// => see only the messages of this specific group
$sql = "SELECT $select
FROM $tbl_announcement announcement INNER JOIN $tbl_item_property ip
ON (announcement.id = ip.ref AND ip.tool='announcement')
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
ip.visibility<>'2' AND
(ip.to_group_id = $group_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL)
$condition_session
$searchCondition
ORDER BY display_order DESC";
//GROUP BY ip.ref
} else {
// A.3 you are a course admin without any group or user filter
// A.3.a you are a course admin without user or group filter but WITH studentview
// => see all the messages of all the users and groups without editing possibilities
if (isset($isStudentView) && $isStudentView == "true") {
$sql = "SELECT $select
FROM $tbl_announcement announcement INNER JOIN $tbl_item_property ip
ON (announcement.id = ip.ref AND ip.tool='announcement')
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
ip.tool='announcement' AND
ip.visibility='1'
$condition_session
$searchCondition
ORDER BY display_order DESC";
//GROUP BY ip.ref
} else {
// A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
// => see all the messages of all the users and groups with editing possibilities
$sql = "SELECT $select
FROM $tbl_announcement announcement INNER JOIN $tbl_item_property ip
ON (announcement.id = ip.ref AND ip.tool='announcement')
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
(ip.visibility='0' or ip.visibility='1')
$condition_session
$searchCondition
ORDER BY display_order DESC";
//GROUP BY ip.ref
}
}
} else {
// STUDENT
if (is_array($group_memberships) && count($group_memberships) > 0) {
if ($allowUserEditSetting && !api_is_anonymous()) {
if ($group_id == 0) {
// No group
$cond_user_id = " AND (
ip.lastedit_user_id = '".$user_id."' OR (
ip.to_user_id='".$user_id."' OR
(ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))
)
) ";
} else {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$user_id."' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.")
)";
}
} else {
if ($group_id == 0) {
$cond_user_id = " AND (
ip.to_user_id = $user_id AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))
) ";
} else {
$cond_user_id = " AND (
ip.to_user_id = $user_id AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id."))
)";
}
}
$sql = "SELECT $select
FROM $tbl_announcement announcement,
$tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref
AND ip.tool='announcement'
$cond_user_id
$condition_session
$searchCondition
AND ip.visibility='1'
ORDER BY display_order DESC";
} else {
if ($user_id) {
if ($allowUserEditSetting && !api_is_anonymous()) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".api_get_user_id()."' OR
(ip.to_user_id='".$user_id."' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL))
) ";
} else {
$cond_user_id = " AND (ip.to_user_id='".$user_id."' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) ";
}
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref AND
ip.tool='announcement'
$cond_user_id
$condition_session
$searchCondition
AND ip.visibility='1'
AND announcement.session_id IN(0, ".$session_id.")
ORDER BY display_order DESC";
} else {
if (($allowUserEditSetting && !api_is_anonymous())) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$user_id."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL
)";
} else {
$cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL ";
}
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref AND
ip.tool='announcement'
$cond_user_id
$condition_session
$searchCondition
AND
ip.visibility='1' AND
announcement.session_id IN ( 0,".api_get_session_id().")";
}
}
}
if (!is_null($start) && !is_null($limit)) {
$start = intval($start);
$limit = intval($limit);
$sql .= " LIMIT $start, $limit";
}
$result = Database::query($sql);
if ($getCount) {
$result = Database::fetch_array($result, 'ASSOC');
return $result['count'];
}
$iterator = 1;
$bottomAnnouncement = $announcement_number;
$origin = null;
$displayed = [];
$results = [];
$actionUrl = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq();
while ($myrow = Database::fetch_array($result, 'ASSOC')) {
if (!in_array($myrow['id'], $displayed)) {
$sent_to_icon = '';
// the email icon
if ($myrow['email_sent'] == '1') {
$sent_to_icon = ' '.Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'));
}
$title = $myrow['title'].$sent_to_icon;
$item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id);
$myrow['visibility'] = $item_visibility;
// show attachment list
$attachment_list = AnnouncementManager::get_attachment($myrow['id']);
$attachment_icon = '';
if (count($attachment_list)>0) {
$attachment_icon = ' '.Display::return_icon('attachment.gif',get_lang('Attachment'));
}
/* TITLE */
$user_info = api_get_user_info($myrow['insert_user_id']);
$username = sprintf(get_lang("LoginX"), $user_info['username']);
$username_span = Display::tag('span', api_get_person_name($user_info['firstName'], $user_info['lastName']), array('title'=>$username));
$title = Display::url($title.$attachment_icon, $actionUrl.'&action=view&id='.$myrow['id']);
//$html .= Display::tag('td', $username_span, array('class' => 'announcements-list-line-by-user'));
//$html .= Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), array('class' => 'announcements-list-line-datetime'));
$modify_icons = '';
// we can edit if : we are the teacher OR the element belongs to
// the session we are coaching OR the option to allow users to edit is on
if (api_is_allowed_to_edit(false, true) ||
(api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']))
|| (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
) {
$modify_icons = "<a href=\"".$actionUrl."&action=modify&id=".$myrow['id']."\">".
Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL)."</a>";
if ($myrow['visibility']==1) {
$image_visibility="visible";
$alt_visibility=get_lang('Hide');
} else {
$image_visibility="invisible";
$alt_visibility=get_lang('Visible');
}
$modify_icons .= "<a href=\"".$actionUrl."&origin=".$origin."&action=showhide&id=".$myrow['id']."&sec_token=".$stok."\">".
Display::return_icon($image_visibility.'.png', $alt_visibility,'',ICON_SIZE_SMALL)."</a>";
// DISPLAY MOVE UP COMMAND only if it is not the top announcement
if ($iterator != 1) {
$modify_icons .= "<a href=\"".$actionUrl."&action=move&up=".$myrow["id"]."&sec_token=".$stok."\">".
Display::return_icon('up.gif', get_lang('Up'))."</a>";
} else {
$modify_icons .= Display::return_icon('up_na.gif', get_lang('Up'));
}
if ($iterator < $bottomAnnouncement) {
$modify_icons .= "<a href=\"".$actionUrl."&action=move&down=".$myrow["id"]."&sec_token=".$stok."\">".
Display::return_icon('down.gif', get_lang('Down'))."</a>";
} else {
$modify_icons .= Display::return_icon('down_na.gif', get_lang('Down'));
}
if (api_is_allowed_to_edit(false,true)) {
$modify_icons .= "<a href=\"".$actionUrl."&action=delete&id=".$myrow['id']."&sec_token=".$stok."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,api_get_system_encoding()))."')) return false;\">".
Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).
"</a>";
}
$iterator ++;
} else {
$modify_icons = Display::url(
Display::return_icon('default.png'),
$actionUrl.'&action=view&id='.$myrow['id']
);
}
$announcement = [
'id' => $myrow["id"],
'title' => $title,
'username' => $username_span,
'insert_date' => api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG),
'actions' => $modify_icons
];
$results[] = $announcement;
}
$displayed[] = $myrow['id'];
}
return $results;
}
/**
* @return int
*/
public static function getNumberAnnouncements()
{
// Maximum title messages to display
$maximum = '12';
// Database Table Definitions
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$session_id = api_get_session_id();
$_course = api_get_course_info();
$course_id = $_course['real_id'];
$userId = api_get_user_id();
$condition_session = api_get_session_condition($session_id, true, true, 'announcement.session_id');
if (api_is_allowed_to_edit(false,true)) {
// check teacher status
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
if (api_get_group_id() == 0) {
$group_condition = "";
} else {
$group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0 OR ip.to_group_id IS NULL)";
}
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref AND
ip.tool = 'announcement' AND
ip.visibility <> '2'
$group_condition
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0,$maximum";
}
} else {
// students only get to see the visible announcements
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
$group_memberships = GroupManager::get_group_ids($_course['real_id'], $userId);
if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
if (api_get_group_id() == 0) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$userId."' OR (
ip.to_user_id='".$userId."' OR
ip.to_group_id IN (0, ".implode(", ", $group_memberships).") OR
ip.to_group_id IS NULL
)
)
";
} else {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$userId."'OR
ip.to_group_id IN (0, ".api_get_group_id().") OR
ip.to_group_id IS NULL
)";
}
} else {
if (api_get_group_id() == 0) {
$cond_user_id = " AND (
ip.to_user_id='".$userId."' OR
ip.to_group_id IN (0, ".implode(", ", $group_memberships).") OR
ip.to_group_id IS NULL
) ";
} else {
$cond_user_id = " AND (
ip.to_user_id='".$userId."' OR
ip.to_group_id IN (0, ".api_get_group_id().") OR
ip.to_group_id IS NULL
) ";
}
}
// the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
if (is_array($group_memberships) && count($group_memberships)>0) {
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref AND
ip.tool='announcement'
AND ip.visibility='1'
$cond_user_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";
} else {
// the user is not member of any group
// this is an identified user => show the general announcements AND his personal announcements
if ($userId) {
if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$userId."' OR
( ip.to_user_id='".$userId."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL)
) ";
} else {
$cond_user_id = " AND ( ip.to_user_id='".$userId."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL) ";
}
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility='1'
$cond_user_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";
} else {
if (api_get_course_setting('allow_user_edit_announcement')) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL
) ";
} else {
$cond_user_id = " AND ip.to_group_id='0' ";
}
// the user is not identiefied => show only the general announcements
$sql="SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
ip.c_id = $course_id AND
announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility='1'
AND ip.to_group_id='0'
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";
}
}
}
}
$result = Database::query($sql);
return Database::num_rows($result);
}
}

File diff suppressed because it is too large Load Diff

@ -3539,7 +3539,9 @@ function move_thread_form()
$htmlcontent .= ' </div>
</div>';
$form->addElement('html', $htmlcontent);
$form->addElement('html', $htmlcontent);
// The OK button
$form->addElement('style_submit_button', 'SubmitForum', get_lang('MoveThread'), 'class="save"');

@ -0,0 +1,37 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls
*/
require_once '../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$isAllowedToEdit = api_is_allowed_to_edit();
$courseInfo = api_get_course_info();
switch ($action) {
case 'delete_item':
if ($isAllowedToEdit) {
if (empty($_REQUEST['id'])) {
return false;
}
if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
return false;
}
$list = explode(',', $_REQUEST['id']);
foreach ($list as $itemId) {
if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $itemId)) {
AnnouncementManager::delete_announcement($courseInfo, $itemId);
}
}
}
break;
default:
echo '';
break;
}
exit;

@ -48,7 +48,8 @@ if (!in_array(
'get_usergroups_teacher',
'get_user_course_report_resumed',
'get_user_course_report',
'get_sessions_tracking'
'get_sessions_tracking',
'get_course_announcements'
)
) && !isset($_REQUEST['from_course_session'])) {
api_protect_admin_script(true);
@ -143,6 +144,9 @@ if (!$sidx) {
//@todo rework this
switch ($action) {
case 'get_course_announcements':
$count = AnnouncementManager::getAnnouncements(null, null, true);
break;
case 'get_user_course_report':
case 'get_user_course_report_resumed':
if (!(api_is_platform_admin(false, true))) {
@ -562,6 +566,31 @@ switch ($action) {
$item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
}
}
break;
case 'get_course_announcements':
$columns = array(
'title',
'username',
'insert_date',
'actions'
);
$titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
$userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
$result = AnnouncementManager::getAnnouncements(
null,
null,
false,
$start,
$limit,
$sidx,
$sord,
$titleToSearch,
$userIdToSearch
);
break;
case 'get_work_teacher':
$columns = array(
@ -1328,7 +1357,8 @@ $allowed_actions = array(
//'get_course_exercise_medias',
'get_user_course_report',
'get_user_course_report_resumed',
'get_exercise_grade'
'get_exercise_grade',
'get_course_announcements'
);
//5. Creating an obj to return a json

@ -5523,4 +5523,180 @@ class CourseManager
$row = Database::fetch_array($result);
return $row['count'];
}
/**
* @param FormValidator $form
* @param array $to_already_selected
*
* @return HTML_QuickForm_element
*/
public static function addUserGroupMultiSelect(&$form, $to_already_selected)
{
$user_list = self::getCourseUsers();
$group_list = self::getCourseGroups();
$array = self::buildSelectOptions($group_list, $user_list, $to_already_selected);
$result = array();
foreach ($array as $content) {
$result[$content['value']] = $content['content'];
}
$element = $form->addElement(
'advmultiselect',
'users',
get_lang('Users'),
$result,
array('select_all_checkbox' => true, 'style' => 'width: 280px;')
);
$element->setElementTemplate('
{javascript}
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
<td valign="top">{unselected}</td>
<td align="center">{add}<br /><br />{remove}</td>
<td valign="top">{selected}</td>
</tr>
</table>
');
$element->setButtonAttributes('add', array('class' => 'btn arrowr'));
$element->setButtonAttributes('remove', array('class' => 'btn arrowl'));
return $element;
}
/**
* Shows the form for sending a message to a specific group or user.
* @param FormValidator $form
* @param int $group_id
* @param array $to
*/
public static function addGroupMultiSelect($form, $group_id, $to = array())
{
$group_users = GroupManager::get_subscribed_users($group_id);
$array = self::buildSelectOptions(null, $group_users, $to);
$result = array();
foreach ($array as $content) {
$result[$content['value']] = $content['content'];
}
$element = $form->addElement('advmultiselect', 'users', get_lang('Users'), $result);
$element->setElementTemplate('
{javascript}
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
<td valign="top">{unselected}</td>
<td align="center">{add}<br /><br />{remove}</td>
<td valign="top">{selected}</td>
</tr>
</table>
');
$element->setButtonAttributes('add', array('class' => 'btn arrowr'));
$element->setButtonAttributes('remove', array('class' => 'btn arrowl'));
}
/**
* this function gets all the users of the course,
* including users from linked courses
*/
public static function getCourseUsers()
{
//this would return only the users from real courses:
$session_id = api_get_session_id();
if ($session_id != 0) {
$user_list = self::get_real_and_linked_user_list(api_get_course_id(), true, $session_id);
} else {
$user_list = self::get_real_and_linked_user_list(api_get_course_id(), false, 0);
}
return $user_list;
}
/**
* this function gets all the groups of the course,
* not including linked courses
*/
public static function getCourseGroups()
{
$session_id = api_get_session_id();
if ($session_id != 0) {
$new_group_list = self::get_group_list_of_course(api_get_course_id(), $session_id, 1);
} else {
$new_group_list = self::get_group_list_of_course(api_get_course_id(), 0, 1);
}
return $new_group_list;
}
/**
* this function shows the form for sending a message to a specific group or user.
* @param array $group_list
* @param array $user_list
* @param array $to_already_selected
* @return array
*/
public static function buildSelectOptions(
$group_list = array(),
$user_list = array(),
$to_already_selected = array()
) {
if (empty($to_already_selected)) {
$to_already_selected = array();
}
$result = array();
// adding the groups to the select form
if ($group_list) {
foreach ($group_list as $this_group) {
if (is_array($to_already_selected)) {
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
$user_label = ($this_group['userNb'] > 0) ? get_lang('Users') : get_lang('LowerCaseUser');
$user_disabled = ($this_group['userNb'] > 0) ? "" : "disabled=disabled";
$result[] = array(
'disabled' => $user_disabled,
'value' => "GROUP:" . $this_group['id'],
'content' => "G: " . $this_group['name'] . " - " . $this_group['userNb'] . " " . $user_label
);
}
}
}
}
// adding the individual users to the select form
if ($user_list) {
foreach ($user_list as $user) {
if (is_array($to_already_selected)) {
if (!in_array(
"USER:" . $user['user_id'],
$to_already_selected
)
) { // $to_already_selected is the array containing the users (and groups) that are already selected
$result[] = array(
'value' => "USER:" . $user['user_id'],
'content' => api_get_person_name($user['firstname'], $user['lastname'])
);
}
}
}
}
return $result;
}
}

@ -2129,4 +2129,106 @@ class Display
{
Session::erase('flash_messages');
}
/**
* @param string $content
* @param string $title
* @param string $footer
* @param string $style primary|success|info|warning|danger
* @param string $extra
*
* @return string
*/
public static function panel($content, $title = '', $footer = '', $style = '', $extra = '')
{
$title = !empty($title) ? '<div class="panel-heading"><h3 class="panel-title">'.$title.'</h3>'.$extra.'</div>' : '';
$footer = !empty($footer) ? '<div class="panel-footer ">'.$footer.'</div>' : '';
$styles = ['primary','success','info','warning','danger'];
$style = !in_array($style, $styles) ? 'default' : $style;
return '
<div class="panel panel-'.$style.'">
'.$title.'
'.self::contentPanel($content).'
'.$footer.'
</div>'
;
}
/**
* @param string $content
* @return string
*/
public static function contentPanel($content)
{
return '<div class="panel-body">
'.$content.'
</div>';
}
/**
* Get the button HTML with an Awesome Font icon
* @param string $text The button content
* @param string $url The url to button
* @param string $icon The Awesome Font class for icon
* @param string $type Optional. The button Bootstrap class. Default 'default' class
* @param array $attributes The additional attributes
* @return string The button HTML
*/
public static function toolbarButton(
$text,
$url,
$icon = 'check',
$type = 'default',
array $attributes = [],
$includeText = true
) {
$buttonClass = "btn btn-$type";
$icon = self::tag('i', null, ['class' => "fa fa-$icon fa-fw", 'aria-hidden' => 'true']);
$attributes['class'] = isset($attributes['class']) ? "$buttonClass {$attributes['class']}" : $buttonClass;
if (!$includeText) {
$text = '<span class="sr-only">' . $text . '</span>';
}
return self::url("$icon $text", $url, $attributes);
}
/**
* @param int $id
* @param array $content
* @param int $col
* @param bool|true $right
* @return string
*/
public static function toolbarAction($id, $content = array(), $col = 2, $right = true)
{
$columns = 12/$col;
$html = '';
$html .= '<div id="' . $id . '" class="actions">';
$html .= '<div class="row-fluid">';
if ($col > 4) {
$html = '<div class="alert alert-warning" role="alert">Action toolbar design does not work when exceeding four columns - check Display::toolbarAction()</div>';
} else {
for ( $i = 0; $i < $col; $i++ ) {
$html .= '<div class="span' . $columns . '">';
if ( $col == 2 && $i == 1 ) {
if ($right === true) {
$html .= '<div class="pull-right">';
$html .= (isset($content[$i]) ? $content[$i] : '');
$html .= '</div>';
} else {
$html .= $content[$i];
}
} else {
$html .= $content[$i];
}
$html .= '</div>';
}
}
$html .= '</div>';
$html .= '</div>';
return $html;
}
}

@ -567,6 +567,11 @@ EOT;
echo $this->return_form();
}
public function returnForm()
{
return $this->return_form();
}
/**
* Returns the HTML code of the form.
* If an element in the form didn't validate, an error message is showed
@ -634,6 +639,27 @@ EOT;
}
return $return_value;
}
/**
* @param string $snippet
*/
public function addHtml($snippet)
{
$this->addElement('html', $snippet);
}
/**
* @param string $name
* @param string $label
* @param string $text
* @param array $attributes
*
* @return HTML_QuickForm_checkbox
*/
public function addCheckBox($name, $label, $text = '', $attributes = array())
{
return $this->addElement('checkbox', $name, $label, $text, $attributes);
}
}
/**

@ -7565,3 +7565,26 @@ function api_protect_limit_for_session_admin()
api_not_allowed(true);
}
}
/**
* @param string $tool Possible values:
* GroupManager::GROUP_TOOL_*
*
*/
function api_protect_course_group($tool, $showHeader = true)
{
$userId = api_get_user_id();
$groupId = api_get_group_id();
if (!empty($groupId)) {
$allow = GroupManager::user_has_access(
$userId,
$groupId,
$tool
);
if (!$allow) {
api_not_allowed($showHeader);
}
}
}

@ -2034,6 +2034,18 @@ class HTML_QuickForm extends HTML_Common
// return the textual error message corresponding to the code
return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[QUICKFORM_ERROR];
}
/**
* @param HTML_QuickForm_element $element
*/
public function setRequired(HTML_QuickForm_element $element)
{
$this->addRule(
$element->getName(),
get_lang('ThisFieldIsRequired'),
'required'
);
}
}
/**

Loading…
Cancel
Save