Add pagination in course announcement + add multiple delete see BT#10949

1.10.x
jmontoya 9 years ago
parent 93cae24e1d
commit c1f149e927
  1. 180
      main/announcements/announcements.php
  2. 37
      main/inc/ajax/announcement.ajax.php
  3. 88
      main/inc/ajax/model.ajax.php
  4. 163
      main/inc/lib/AnnouncementManager.php
  5. 1
      main/work/work.lib.php

@ -37,10 +37,10 @@ $display_form = false;
$display_title_list = true;
// Maximum title messages to display
$maximum = '12';
$maximum = '12';
// Length of the titles
$length = '36';
$length = '36';
// Database Table Definitions
$tbl_courses = Database::get_main_table(TABLE_MAIN_COURSE);
@ -69,16 +69,15 @@ $content = null;
switch ($action) {
case 'move':
/* Move announcement up/down */
if (isset($_GET['sec_token']) && $ctok == $_GET['sec_token']) {
if (!empty($_GET['down'])) {
$thisAnnouncementId = intval($_GET['down']);
$sortDirection = "DESC";
}
if (!empty($_GET['up'])) {
$thisAnnouncementId = intval($_GET['up']);
$sortDirection = "ASC";
}
if (!empty($_GET['down'])) {
$thisAnnouncementId = intval($_GET['down']);
$sortDirection = "DESC";
}
if (!empty($_GET['up'])) {
$thisAnnouncementId = intval($_GET['up']);
$sortDirection = "ASC";
}
if (!empty($sortDirection)) {
@ -130,7 +129,101 @@ switch ($action) {
$content = AnnouncementManager::display_announcement($announcement_id);
break;
case 'list':
$content = AnnouncementManager::getAnnouncements($stok, $announcement_number);
$htmlHeadXtra[] = api_get_jqgrid_js();
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_announcements&'.api_get_cidreq();
$deleteUrl = api_get_path(WEB_AJAX_PATH).'announcement.ajax.php?a=delete_item&'.api_get_cidreq();
$columns = array(get_lang('Title'), get_lang('By'), get_lang('LastUpdateDate'), get_lang('Actions'));
// Column config
$columnModel = array(
array(
'name' => 'title',
'index' => 'title',
'width' => '300',
'align' => 'left',
'sortable' => 'false',
),
array(
'name' => 'username',
'index' => 'username',
'width' => '100',
'align' => 'left',
'sortable' => 'false',
),
array(
'name' => 'insert_date',
'index' => 'insert_date',
'width' => '200',
'align' => 'left',
'sortable' => 'false',
),
array(
'name' => 'actions',
'index' => 'actions',
'width' => '150',
'align' => 'left',
//'formatter' => 'action_formatter',
'sortable' => 'false',
),
);
// Autowidth
$extra_params['autowidth'] = 'true';
// height auto
$extra_params['height'] = 'auto';
$editOptions = '';
if (api_is_allowed_to_edit()) {
$extra_params['multiselect'] = true;
$editOptions = '
$("#announcements").jqGrid(
"navGrid",
"#announcements_pager",
{ edit: false, add: false, del: true },
{ height:280, reloadAfterSubmit:false }, // edit options
{ height:280, reloadAfterSubmit:false }, // add options
{ reloadAfterSubmit:false, url: "'.$deleteUrl.'" }, // del options
{ width:500 } // search options
);
';
}
$content = '<script>
$(function() {'.
Display::grid_js('announcements', $url, $columns, $columnModel, $extra_params, array(), '', true).$editOptions.'
});
</script>';
$count = AnnouncementManager::getAnnouncements($stok, $announcement_number, true);
if (empty($count)) {
$html = '';
if ((api_is_allowed_to_edit(false, true) ||
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) &&
(empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')
) {
$html .= '<div id="no-data-view">';
$html .= '<h3>' . get_lang('Announcements') . '</h3>';
$html .= Display::return_icon('valves.png', '', array(), 64);
$html .= '<div class="controls">';
$html .= Display::url(
get_lang('AddAnnouncement'),
api_get_self() . "?" . api_get_cidreq() . "&action=add",
array('class' => 'btn btn-primary')
);
$html .= '</div>';
$html .= '</div>';
} else {
$html = Display::return_message(get_lang('NoAnnouncements'), 'warning');
}
$content = $html;
} else {
$content .= Display::grid_html('announcements');
}
break;
case 'delete':
/* Delete announcement */
@ -140,11 +233,10 @@ switch ($action) {
}
if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
// tooledit : visibility = 2 : only visible for platform administrator
if ($ctok == $_GET['sec_token']) {
AnnouncementManager::delete_announcement($_course, $id);
Display::addFlash(Display::return_message(get_lang('AnnouncementDeleted')));
}
AnnouncementManager::delete_announcement($_course, $id);
Display::addFlash(Display::return_message(get_lang('AnnouncementDeleted')));
}
header('Location: '.$homeUrl);
exit;
@ -159,17 +251,17 @@ switch ($action) {
break;
case 'delete_attachment':
$id = $_GET['id_attach'];
if ($ctok == $_GET['sec_token']) {
if (api_is_allowed_to_edit()) {
AnnouncementManager::delete_announcement_attachment_file($id);
}
if (api_is_allowed_to_edit()) {
AnnouncementManager::delete_announcement_attachment_file($id);
}
header('Location: '.$homeUrl);
exit;
break;
case 'showhide':
if (!isset($_GET['isStudentView']) || $_GET['isStudentView'] != 'false') {
if (isset($_GET['id']) AND $_GET['id']) {
if (isset($_GET['id']) && $_GET['id']) {
if (api_get_session_id() != 0 &&
api_is_allowed_to_session_edit(false, true) == false) {
api_not_allowed();
@ -178,15 +270,15 @@ switch ($action) {
if (!api_is_course_coach() ||
api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])
) {
if ($ctok == $_GET['sec_token']) {
AnnouncementManager::change_visibility_announcement(
$_course,
$_GET['id']
);
Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
header('Location: '.$homeUrl);
exit;
}
AnnouncementManager::change_visibility_announcement(
$_course,
$_GET['id']
);
Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
header('Location: '.$homeUrl);
exit;
}
}
}
@ -320,11 +412,11 @@ switch ($action) {
$form->addElement('hidden', 'id');
$htmlTags = "<b>".get_lang('Tags')."</b></br></br>";
$tags = AnnouncementManager::get_tags();
foreach ($tags as $tag) {
$htmlTags .= "<b>".$tag."</b></br>";
}
$form->addHtml("<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-8'><div class='alert alert-info'>".$htmlTags."</div></div></div>");
$form->addHtmlEditor(
'content',
@ -443,13 +535,19 @@ if (!empty($_GET['remind_inactive'])) {
if (!empty($group_id)) {
$group_properties = GroupManager :: get_group_properties($group_id);
$interbreadcrumb[] = array("url" => "../group/group.php?".api_get_cidreq(), "name" => get_lang('Groups'));
$interbreadcrumb[] = array("url"=>"../group/group_space.php?".api_get_cidreq(), "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
$interbreadcrumb[] = array(
"url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
"name" => get_lang('Groups'),
);
$interbreadcrumb[] = array(
"url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
"name" => get_lang('GroupSpace').' '.$group_properties['name'],
);
}
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
//we are not in the learning path
Display::display_header($nameTools,get_lang('Announcements'));
Display::display_header($nameTools, get_lang('Announcements'));
}
// Tool introduction
@ -459,24 +557,24 @@ if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
// Actions
$show_actions = false;
if ((api_is_allowed_to_edit(false,true) ||
if ((api_is_allowed_to_edit(false, true) ||
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) &&
(empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')
) {
echo '<div class="actions">';
if (in_array($action, array('add', 'modify','view'))) {
echo "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".$origin."'>".
Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM)."</a>";
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM)."</a>";
} else {
echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&origin=".$origin."'>".
Display::return_icon('new_announce.png',get_lang('AddAnnouncement'),'',ICON_SIZE_MEDIUM)."</a>";
Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), '', ICON_SIZE_MEDIUM)."</a>";
}
$show_actions = true;
} else {
if (in_array($action, array('view'))) {
echo '<div class="actions">';
echo "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".$origin."'>".
Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM)."</a>";
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM)."</a>";
echo '</div>';
}
}
@ -495,8 +593,6 @@ if (api_is_allowed_to_edit() && $announcement_number > 1) {
if ($show_actions)
echo '</div>';
Display::showFlash();
echo $content;
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {

@ -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;

@ -46,7 +46,8 @@ if (!in_array(
'get_user_course_report_resumed',
'get_user_course_report',
'get_sessions_tracking',
'get_sessions'
'get_sessions',
'get_course_announcements'
)
) && !isset($_REQUEST['from_course_session'])) {
api_protect_admin_script(true);
@ -329,6 +330,9 @@ switch ($action) {
$skill = new Skill();
$count = $skill->get_user_list_skill_ranking_count();
break;
case 'get_course_announcements':
$count = AnnouncementManager::getAnnouncements(null, null, true);
break;
case 'get_work_teacher':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
@ -754,6 +758,17 @@ 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'
);
$result = AnnouncementManager::getAnnouncements(null, null, false, $start, $limit, $sidx, $sord);
break;
case 'get_work_teacher':
$columns = array(
@ -1084,11 +1099,15 @@ switch ($action) {
}
$columns[] = 'total';
$result = SessionManager::get_session_lp_progress($sessionId, $courseId, $date_from, $date_to,
$result = SessionManager::get_session_lp_progress(
$sessionId,
$courseId,
$date_from,
$date_to,
array(
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
'limit' => "$start , $limit",
)
);
break;
@ -1116,16 +1135,20 @@ switch ($action) {
$questions = SurveyManager::get_questions($surveyId, $courseId);
foreach ($questions as $question_id => $question)
{
foreach ($questions as $question_id => $question) {
$columns[] = $question_id;
}
$result = SessionManager::get_survey_overview($sessionId, $courseId, $surveyId, $date_from, $date_to,
$result = SessionManager::get_survey_overview(
$sessionId,
$courseId,
$surveyId,
$date_from,
$date_to,
array(
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
'limit' => "$start , $limit",
)
);
break;
@ -1144,25 +1167,25 @@ switch ($action) {
'wikis',
'surveys',
//exercises
'lessons_total' ,
'lessons_done' ,
'lessons_left' ,
'lessons_total',
'lessons_done',
'lessons_left',
'lessons_progress',
//exercises
'exercises_total' ,
'exercises_done' ,
'exercises_left' ,
'exercises_progress' ,
'exercises_total',
'exercises_done',
'exercises_left',
'exercises_progress',
//forums
'forums_total' ,
'forums_done' ,
'forums_left' ,
'forums_progress' ,
'forums_total',
'forums_done',
'forums_left',
'forums_progress',
//assignments
'assignments_total' ,
'assignments_done' ,
'assignments_left' ,
'assignments_progress' ,
'assignments_total',
'assignments_done',
'assignments_left',
'assignments_progress',
//Wiki
'wiki_total',
'wiki_revisions',
@ -1170,11 +1193,11 @@ switch ($action) {
'wiki_unread',
'wiki_progress',
//surveys
'surveys_total' ,
'surveys_done' ,
'surveys_left' ,
'surveys_progress' ,
);
'surveys_total',
'surveys_done',
'surveys_left',
'surveys_progress',
);
$sessionId = 0;
if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
$sessionId = intval($_GET['session_id']);
@ -1354,7 +1377,7 @@ switch ($action) {
if (!in_array($sidx, $columns)) {
$sidx = 'name';
}
$result = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
$result = Database::select('*', "$obj->table ", array('order' => "$sidx $sord", 'LIMIT' => "$start , $limit"));
$new_result = array();
foreach ($result as $item) {
$new_result[] = $item;
@ -1439,7 +1462,7 @@ switch ($action) {
$quizIds = array();
if (!empty($exercises)) {
foreach($exercises as $exercise) {
foreach ($exercises as $exercise) {
$quizIds[] = $exercise['id'];
}
}
@ -1449,7 +1472,7 @@ switch ($action) {
$usersId = array_keys($listUserSess);
$users = UserManager::get_user_list_by_ids($usersId, null, "lastname, firstname", "$start , $limit");
$users = UserManager::get_user_list_by_ids($usersId, null, "lastname, firstname", "$start , $limit");
$exeResults = $objExercise->getExerciseAndResult($_GET['course_id'], $_GET['session_id'], $quizIds);
$arrGrade = array();
@ -1539,9 +1562,7 @@ switch ($action) {
}
$role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
$group['status'] = $role;
$group['actions'] = Display::url($icon, $url);
$new_result[] = $group;
}
@ -1589,7 +1610,8 @@ $allowed_actions = array(
'get_user_course_report',
'get_user_course_report_resumed',
'get_exercise_grade',
'get_group_reporting'
'get_group_reporting',
'get_course_announcements'
);
//5. Creating an obj to return a json

@ -1383,8 +1383,14 @@ class AnnouncementManager
/**
* @param $stok
* @param $announcement_number
* @param bool $getCount
* @param null $start
* @param null $limit
* @param string $sidx
* @param string $sord
* @return array
*/
public static function getAnnouncements($stok, $announcement_number)
public static function getAnnouncements($stok, $announcement_number, $getCount = false, $start = null, $limit = null, $sidx = '', $sord = '')
{
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -1399,6 +1405,11 @@ class AnnouncementManager
$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.iid) count';
}
if (api_is_allowed_to_edit(false, true) ||
($allowUserEditSetting && !api_is_anonymous())
) {
@ -1408,7 +1419,7 @@ class AnnouncementManager
//if (!empty($user_id)) {
if (0) {
if (is_array($group_memberships) && count($group_memberships) > 0 ) {
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
@ -1424,7 +1435,7 @@ class AnnouncementManager
$condition_session
ORDER BY display_order DESC";
} else {
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
@ -1439,57 +1450,55 @@ class AnnouncementManager
} 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 announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
FROM $tbl_announcement announcement, $tbl_item_property ip
$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
announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility<>'2'
AND (ip.to_group_id = $group_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL)
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
GROUP BY ip.ref
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) and $isStudentView=="true") {
$sql="SELECT
announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
FROM $tbl_announcement announcement, $tbl_item_property ip
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
announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility='1'
ip.tool='announcement' AND
ip.visibility='1'
$condition_session
GROUP BY ip.ref
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 announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
FROM $tbl_announcement announcement, $tbl_item_property ip
$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
announcement.id = ip.ref
AND ip.tool='announcement'
AND (ip.visibility='0' or ip.visibility='1')
ip.c_id = $course_id AND
(ip.visibility='0' or ip.visibility='1')
$condition_session
GROUP BY ip.ref
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 (api_get_group_id() == 0) {
// No group
$cond_user_id = " AND (
@ -1504,7 +1513,6 @@ class AnnouncementManager
)";
}
} else {
if (api_get_group_id() == 0) {
$cond_user_id = " AND (
ip.to_user_id=$user_id OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))
@ -1516,12 +1524,7 @@ class AnnouncementManager
}
}
$sql = "SELECT
announcement.*,
ip.visibility,
ip.to_group_id,
ip.insert_user_id,
ip.insert_date
$sql = "SELECT $select
FROM $tbl_announcement announcement,
$tbl_item_property ip
WHERE
@ -1544,7 +1547,7 @@ class AnnouncementManager
$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 announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
@ -1566,7 +1569,7 @@ class AnnouncementManager
$cond_user_id = " AND 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, ip.insert_date
$sql = "SELECT $select
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE
announcement.c_id = $course_id AND
@ -1580,49 +1583,31 @@ class AnnouncementManager
}
}
}
if (!is_null($start) && !is_null($limit)) {
$start = intval($start);
$limit = intval($limit);
$sql .= " LIMIT $start, $limit";
}
$result = Database::query($sql);
$num_rows = Database::num_rows($result);
$html = null;
if ($getCount) {
$result = Database::fetch_array($result, 'ASSOC');
if ($num_rows == 0) {
if ((api_is_allowed_to_edit(false, true) OR
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) and
(empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
) {
$html .= '<div id="no-data-view">';
$html .= '<h3>' . get_lang('Announcements') . '</h3>';
$html .= Display::return_icon('valves.png', '', array(), 64);
$html .= '<div class="controls">';
$html .= Display::url(
get_lang('AddAnnouncement'),
api_get_self() . "?" . api_get_cidreq() . "&action=add",
array('class' => 'btn btn-primary')
);
$html .= '</div>';
$html .= '</div>';
} else {
$html = Display::return_message(get_lang('NoAnnouncements'), 'warning');
}
return $html;
return $result['count'];
}
$iterator = 1;
$bottomAnnouncement = $announcement_number;
$origin = null;
$html .= '<table width="100%" class="data_table announcements-list">';
$ths = Display::tag('th', get_lang('Title'));
$ths .= Display::tag('th', get_lang('By') );
$ths .= Display::tag('th', get_lang('LastUpdateDate') );
if (api_is_allowed_to_edit(false,true) OR (api_is_course_coach() &&
/*if (api_is_allowed_to_edit(false,true) OR (api_is_course_coach() &&
api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']))
OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
$ths .= Display::tag('th', get_lang('Modify'));
}
}*/
$html .= Display::tag('tr', $ths);
$displayed = array();
$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 = '';
@ -1642,8 +1627,6 @@ class AnnouncementManager
$style = '';
}
$html .= '<tr class="announcements-list-line">';
// show attachment list
$attachment_list = AnnouncementManager::get_attachment($myrow['id']);
@ -1656,20 +1639,18 @@ class AnnouncementManager
$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, api_get_self().'?'.api_get_cidreq().'&action=view&id='.$myrow['id']);
$html .= Display::tag('td', Security::remove_XSS($title), array('class' => 'announcements-list-line-title '.$style));
$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'));
$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) OR
if (api_is_allowed_to_edit(false, true) ||
(api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']))
OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
|| (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
) {
$modify_icons = "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">".
$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";
@ -1678,37 +1659,49 @@ class AnnouncementManager
$image_visibility="invisible";
$alt_visibility=get_lang('Visible');
}
$modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$origin."&action=showhide&id=".$myrow['id']."&sec_token=".$stok."\">".
$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=\"".api_get_self()."?".api_get_cidreq()."&action=move&up=".$myrow["id"]."&sec_token=".$stok."\">".
$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=\"".api_get_self()."?".api_get_cidreq()."&action=move&down=".$myrow["id"]."&sec_token=".$stok."\">".
$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=\"".api_get_self()."?".api_get_cidreq()."&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;\">".
$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 ++;
$html .= Display::tag('td', $modify_icons, array('class' => 'announcements-list-line-actions'));
} else {
$modify_icons = Display::url(
Display::return_icon('default.png'),
$actionUrl.'&action=view&id='.$myrow['id']
);
}
$html .= "</tr>";
$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'];
}
$html .= "</table>";
return $html;
return $results;
}
/**

@ -1503,6 +1503,7 @@ function getWorkListTeacher(
if ($getCount) {
$row = Database::fetch_array($result);
return $row['count'];
}
$url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq();

Loading…
Cancel
Save