@ -25,6 +25,7 @@ function confirmation() {
}
}
< / script > ";
api_block_anonymous_users();
if (!api_is_allowed_to_edit() & & !api_is_student_boss()) {
@ -36,7 +37,130 @@ $action = isset($_GET['action']) && $_GET['action'] ? $_GET['action'] : null;
$filterOfficialCode = isset($_POST['filter']) ? Security::remove_XSS($_POST['filter']) : null;
$filterOfficialCodeGet = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
$url = api_get_self().'?'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
$courseInfo = api_get_course_info();
$filter = api_get_setting('certificate_filter_by_official_code');
$userList = array();
$filterForm = null;
$certificate_list = array();
if ($filter === 'true') {
$options = UserManager::getOfficialCodeGrouped();
$options = array_merge(array('all' => get_lang('All')), $options);
$form = new FormValidator(
'official_code_filter',
'POST',
api_get_self().'?'.api_get_cidreq().'& cat_id='.$cat_id
);
$form->addElement('select', 'filter', get_lang('OfficialCode'), $options);
$form->addButton('submit', get_lang('Submit'));
$filterForm = '< br / > '.$form->returnForm();
if ($form->validate()) {
$officialCode = $form->getSubmitValue('filter');
if ($officialCode == 'all') {
$certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
} else {
$userList = UserManager::getUsersByOfficialCode($officialCode);
if (!empty($userList)) {
$certificate_list = GradebookUtils::get_list_users_certificates(
$cat_id,
$userList
);
}
}
} else {
$certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
}
} else {
$certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
}
$content = '';
$tags = [
'((course_title))',
'((user_first_name))',
'((user_last_name))',
'((author_first_name))',
'((author_last_name))',
'((score))',
'((portal_name))'
];
switch ($action) {
case 'send_notifications':
$currentUserInfo = api_get_user_info();
$originalMessage = isset($_POST['message']) ? $_POST['message'] : '';
if (!empty($originalMessage)) {
foreach ($certificate_list as $index => $value) {
$userInfo = api_get_user_info($value['user_id']);
if (empty($userInfo)) {
continue;
}
$list = GradebookUtils::get_list_gradebook_certificates_by_user_id(
$value['user_id'],
$cat_id
);
$subject = get_lang('NotificationCertificateSubject');
foreach ($list as $valueCertificate) {
$replace = [
$courseInfo['title'],
$userInfo['firstname'],
$userInfo['lastname'],
$currentUserInfo['firstname'],
$currentUserInfo['lastname'],
$valueCertificate['score_certificate'],
api_get_setting('Institution')
];
$message = str_replace($tags, $replace, $originalMessage);
MessageManager::send_message(
$userInfo['id'],
$subject,
$message,
[],
[],
0,
0,
0,
0,
$currentUserInfo['id']
);
$plugin = new AppPlugin();
$smsPlugin = $plugin->getSMSPluginLibrary();
if ($smsPlugin) {
$additionalParameters = array(
'smsType' => SmsPlugin::CERTIFICATE_NOTIFICATION,
'userId' => $userInfo['id'],
'direct_message' => $message
);
$smsPlugin->send($additionalParameters);
}
}
}
Display::addFlash(Display::return_message(get_lang('Sent')));
}
header('Location: '.$url);
exit;
break;
case 'show_notification_form':
$form = new FormValidator('notification', 'post', $url.'&action=send_notifications');
$form->addHeader(get_lang('SendNotification'));
$form->addHtmlEditor('message', get_lang('Message'));
$form->addLabel(
get_lang('Tags'),
Display::return_message(implode('< br / > ', $tags), 'normal', false)
);
$form->addButtonSend(get_lang('Send'));
$form->setDefaults(
['message' => nl2br(get_lang('NotificationCertificateTemplate'))]
);
$content = $form->returnForm();
break;
case 'export_all_certificates':
if (api_is_student_boss()) {
$userGroup = new UserGroup();
@ -70,8 +194,6 @@ switch ($action) {
break;
}
$course_code = api_get_course_id();
$interbreadcrumb[] = array(
'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?',
'name' => get_lang('Gradebook'),
@ -98,6 +220,10 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete') {
$token = Security::get_token();
echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
if (!empty($content)) {
echo $content;
}
//@todo replace all this code with something like get_total_weight()
$cats = Category::load($cat_id, null, null, null, null, null, false);
@ -123,7 +249,7 @@ if (!empty($cats)) {
$total_resource_weight = 0;
if (!empty($datagen)) {
$data_array = $datagen->get_data(
GradebookDataGenerator :: GDG_SORT_NAME ,
0 ,
0,
null,
true
@ -149,45 +275,6 @@ if (!empty($cats)) {
}
}
$filter = api_get_setting('certificate_filter_by_official_code');
$userList = array();
$filterForm = null;
$certificate_list = array();
if ($filter === 'true') {
echo '< br / > ';
$options = UserManager::getOfficialCodeGrouped();
$options = array_merge(array('all' => get_lang('All')), $options);
$form = new FormValidator(
'official_code_filter',
'POST',
api_get_self().'?'.api_get_cidreq().'& cat_id='.$cat_id
);
$form->addElement('select', 'filter', get_lang('OfficialCode'), $options);
$form->addButton('submit', get_lang('Submit'));
$filterForm = '< br / > '.$form->returnForm();
if ($form->validate()) {
$officialCode = $form->getSubmitValue('filter');
if ($officialCode == 'all') {
$certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
} else {
$userList = UserManager::getUsersByOfficialCode($officialCode);
if (!empty($userList)) {
$certificate_list = GradebookUtils::get_list_users_certificates(
$cat_id,
$userList
);
}
}
} else {
$certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
}
} else {
$certificate_list = GradebookUtils::get_list_users_certificates($cat_id);
}
$url = api_get_self().'?'.api_get_cidreq().'&cat_id='.$cat_id.'&filter='.$filterOfficialCode;
echo '< div class = "btn-group" > ';
echo Display::url(
@ -209,7 +296,14 @@ if (count($certificate_list) > 0 && $hideCertificateExport !== 'true') {
$url.'& action=export_all_certificates',
array('class' => 'btn btn-default')
);
echo Display::url(
get_lang('SendCertificateNotifications'),
$url.'& action=show_notification_form',
array('class' => 'btn btn-default')
);
}
echo '< / div > ';
echo $filterForm;
@ -229,19 +323,19 @@ if (count($certificate_list) == 0) {
$value['user_id'],
$cat_id
);
foreach ($list as $value_c ertificate) {
foreach ($list as $valueC ertificate) {
echo '< tr > ';
echo '< td width = "50%" > '.get_lang('Score').' : '.$value_c ertificate['score_certificate'].'< / td > ';
echo '< td width = "30%" > '.get_lang('Date').' : '.api_convert_and_format_date($value_c ertificate['created_at']).'< / td > ';
echo '< td width = "50%" > '.get_lang('Score').' : '.$valueC ertificate['score_certificate'].'< / td > ';
echo '< td width = "30%" > '.get_lang('Date').' : '.api_convert_and_format_date($valueC ertificate['created_at']).'< / td > ';
echo '< td width = "20%" > ';
$url = api_get_path(WEB_PATH).'certificates/index.php?id='.$value_c ertificate['id'];
$url = api_get_path(WEB_PATH).'certificates/index.php?id='.$valueC ertificate['id'];
$certificates = Display::url(
get_lang('Certificate'),
$url,
array('target' => '_blank', 'class' => 'btn btn-default')
);
echo $certificates;
echo '< a onclick = "return confirmation();" href = "gradebook_display_certificate.php?sec_token='.$token.'&'.api_get_cidreq().'&action=delete&cat_id='.$cat_id.'&certificate_id='.$value_c ertificate['id'].'" >
echo '< a onclick = "return confirmation();" href = "gradebook_display_certificate.php?sec_token='.$token.'&'.api_get_cidreq().'&action=delete&cat_id='.$cat_id.'&certificate_id='.$valueC ertificate['id'].'" >
'.Display::return_icon('delete.png', get_lang('Delete')).'
< / a > ';
echo '< / td > < / tr > ';