@ -27,7 +27,7 @@ require_once 'gradebook_functions_users.inc.php';
* @param int Session ID (optional or 0 if not defined)
* @return boolean True on success, false on failure
*/
function add_resource_to_course_gradebook($course_code, $resource_type, $resource_id, $resource_name='', $weight=0, $max=0, $resource_description='', $date=null, $visible=0, $session_id = 0) {
function add_resource_to_course_gradebook($category_id, $c ourse_code, $resource_type, $resource_id, $resource_name='', $weight=0, $max=0, $resource_description='', $visible=0, $session_id = 0) {
/* See defines in lib/be/linkfactory.class.php
define('LINK_EXERCISE',1);
define('LINK_DROPBOX',2);
@ -35,51 +35,17 @@ function add_resource_to_course_gradebook($course_code, $resource_type, $resourc
define('LINK_LEARNPATH',4);
define('LINK_FORUM_THREAD',5),
define('LINK_WORK',6);
*/
$category = 0;
*/
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
$link = LinkFactory :: create($resource_type);
$link->set_user_id(api_get_user_id());
$link->set_course_code($course_code);
// TODO find the corresponding category (the first one for this course, ordered by ID)
$t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = "SELECT * FROM $t WHERE course_code = '".Database::escape_string($course_code)."' ";
if (!empty($session_id)) {
$sql .= " AND session_id = ".(int)$session_id;
} else {
$sql .= " AND (session_id IS NULL OR session_id = 0) ";
}
$sql .= " ORDER BY id";
$res = Database::query($sql);
if (Database::num_rows($res)< 1 ) {
//there is no unique category for this course+session combination,
$cat = new Category();
if (!empty($session_id)) {
$my_session_id=api_get_session_id();
$s_name = api_get_session_name($my_session_id);
$cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
$cat->set_session_id($session_id);
} else {
$cat->set_name($course_code);
}
$cat->set_course_code($course_code);
$cat->set_description(null);
$cat->set_user_id(api_get_user_id());
$cat->set_parent_id(0);
$cat->set_weight(100);
$cat->set_visible(0);
$can_edit = api_is_allowed_to_edit(true, true);
if ($can_edit) {
$cat->add();
}
$category = $cat->get_id();
unset ($cat);
} else {
$row = Database::fetch_array($res);
$category = $row['id'];
}
$link->set_category_id($category);
if (empty($category_id)) {
return false;
}
$link->set_category_id($category_id);
if ($link->needs_name_and_description()) {
$link->set_name($resource_name);
} else {
@ -215,7 +181,7 @@ function build_edit_icons_cat($cat, $selectcat) {
if (api_is_platform_admin()) {
$modify_icons .= ' < a onclick = "javascrip:lock_confirmation()" href = "' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=unlock" > '.Display::return_icon('unlock.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'< / a > ';
} else {
$modify_icons .= ' < a href = "#" > '.Display::return_icon('unlock_na.png', get_lang('ResourceLockedByGradebook '),'',ICON_SIZE_SMALL).'< / a > ';
$modify_icons .= ' < a href = "#" > '.Display::return_icon('unlock_na.png', get_lang('GradebookLockedAlert '),'',ICON_SIZE_SMALL).'< / a > ';
}
} else {
$modify_icons .= ' < a onclick = "javascrip:lock_confirmation()" href = "' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=lock" > '.Display::return_icon('lock.png', get_lang('Lock'),'',ICON_SIZE_SMALL).'< / a > ';
@ -226,7 +192,11 @@ function build_edit_icons_cat($cat, $selectcat) {
$modify_icons .= ' < a href = "gradebook_flat_view.php?export_pdf=category&selectcat=' . $cat->get_id() . '" > '.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).'< / a > ';
if (empty($grade_model_id) || $grade_model_id == -1) {
$modify_icons .= '< a href = "gradebook_edit_cat.php?editcat='.$cat->get_id().'&cidReq='.$cat->get_course_code().'" > '.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'< / a > ';
if ($cat->is_locked() & & !api_is_platform_admin()) {
$modify_icons .= Display::return_icon('edit_na.png', get_lang('Modify'),'',ICON_SIZE_SMALL);
} else {
$modify_icons .= '< a href = "gradebook_edit_cat.php?editcat='.$cat->get_id().'&cidReq='.$cat->get_course_code().'" > '.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'< / a > ';
}
}
$modify_icons .= ' < a href = "' . api_get_self() . '?visiblecat=' . $cat->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . ' " > '.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'',ICON_SIZE_SMALL).'< / a > ';
@ -243,9 +213,12 @@ function build_edit_icons_cat($cat, $selectcat) {
/*$modify_icons .= ' < a href = "gradebook_edit_all.php?id_session='.api_get_session_id().'&cidReq='.$cat->get_course_code().'&selectcat=' . $cat->get_id() . '" > '.
Display::return_icon('percentage.png', get_lang('EditAllWeights'),'',ICON_SIZE_SMALL).' < / a > '; */
}
$modify_icons .= ' < a href = "' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '&cidReq='.$cat->get_course_code().'" onclick = "return confirmation();" > '.Display::return_icon('delete.png', get_lang('DeleteAll'),'',ICON_SIZE_SMALL).'< / a > ';
if ($cat->is_locked() & & !api_is_platform_admin()) {
$modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'),'',ICON_SIZE_SMALL);
} else {
$modify_icons .= ' < a href = "' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '&cidReq='.$cat->get_course_code().'" onclick = "return confirmation();" > '.Display::return_icon('delete.png', get_lang('DeleteAll'),'',ICON_SIZE_SMALL).'< / a > ';
}
}
return $modify_icons;
}
}
@ -256,7 +229,7 @@ function build_edit_icons_cat($cat, $selectcat) {
*/
function build_edit_icons_eval($eval, $selectcat) {
$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
$locked_status = $eval->get _locked();
$is_locked = $eval->is _locked();
$eval->get_course_code();
$cat=new Category();
$message_eval=$cat->show_message_resource_delete($eval->get_course_code());
@ -264,14 +237,17 @@ function build_edit_icons_eval($eval, $selectcat) {
if ($message_eval===false & & api_is_allowed_to_edit(null, true)) {
$visibility_icon= ($eval->is_visible() == 0) ? 'invisible' : 'visible';
$visibility_command= ($eval->is_visible() == 0) ? 'set_visible' : 'set_invisible';
$modify_icons= '< a href = "gradebook_edit_eval.php?editeval=' . $eval->get_id() . ' &cidReq='.$eval->get_course_code().'" >
'.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'< / a > ';
if ($is_locked & & !api_is_platform_admin()) {
$modify_icons= Display::return_icon('edit_na.png', get_lang('Modify'),'',ICON_SIZE_SMALL);
} else {
$modify_icons= '< a href = "gradebook_edit_eval.php?editeval=' . $eval->get_id() . ' &cidReq='.$eval->get_course_code().'" > '.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'< / a > ';
}
//$modify_icons .= ' < a href = "' . api_get_self() . '?moveeval=' . $eval->get_id() . '&selectcat=' . $selectcat . '" > < img src = "../img/deplacer_fichier.gif" border = "0" title = "' . get_lang('Move') . '" alt = "" / > < / a > ';
$modify_icons .= ' < a href = "' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . ' " > '.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'',ICON_SIZE_SMALL).'< / a > ';
if (api_is_allowed_to_edit(null, true)){
$modify_icons .= ' < a href = "gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq='.$eval->get_course_code().'" > '.Display::return_icon('history.png', get_lang('GradebookQualifyLog'),'',ICON_SIZE_SMALL).'< / a > ';
}
/*
if ($locked_status == 0){
$modify_icons .= " < a href = \"javascript:if ( confirm ( ' " . addslashes ( get_lang ( ' AreYouSureToLockedTheEvaluation ' ) ) . " ' ) ) { location . href = '".api_get_self().' ? lockedeval = ' . $eval->get_id() . ' & amp ; selectcat = ' . $selectcat . ' & amp ; cidReq = '.$eval->get_course_code()."' ; } \ " > ".Display::return_icon('unlock.png',get_lang('LockEvaluation'), array(), ICON_SIZE_SMALL)."< / a > ";
@ -281,8 +257,12 @@ function build_edit_icons_eval($eval, $selectcat) {
} else {
$modify_icons .= ' < img src = "../img/locked_na.png" border = "0" title = "' . get_lang('TheEvaluationIsLocked') . '" alt = "" / > ';
}
}*/
$modify_icons .= ' < a href = "' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq='.$eval->get_course_code().'" onclick = "return confirmation();" > '.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'< / a > ';
}*/
if ($is_locked & & !api_is_platform_admin()) {
$modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
} else {
$modify_icons .= ' < a href = "' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq='.$eval->get_course_code().'" onclick = "return confirmation();" > '.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'< / a > ';
}
return $modify_icons;
}
}
@ -291,15 +271,20 @@ function build_edit_icons_eval($eval, $selectcat) {
* @param object $linkobject
* @param int $selectcat id of selected category
*/
function build_edit_icons_link($link, $selectcat) {
$link->get_course_code();
function build_edit_icons_link($link, $selectcat) {
$cat = new Category();
$message_link = $cat->show_message_resource_delete($link->get_course_code());
$message_link = $cat->show_message_resource_delete($link->get_course_code());
$is_locked = $link->is_locked();
if ($message_link===false) {
$visibility_icon= ($link->is_visible() == 0) ? 'invisible' : 'visible';
$visibility_command= ($link->is_visible() == 0) ? 'set_visible' : 'set_invisible';
$modify_icons= '< a href = "gradebook_edit_link.php?editlink='.$link->get_id().'&cidReq='.$link->get_course_code().'" > '.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'< / a > ';
if ($is_locked & & !api_is_platform_admin()) {
$modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'),'',ICON_SIZE_SMALL);
} else {
$modify_icons = '< a href = "gradebook_edit_link.php?editlink='.$link->get_id().'&cidReq='.$link->get_course_code().'" > '.Display::return_icon('edit.png', get_lang('Modify'),'',ICON_SIZE_SMALL).'< / a > ';
}
//$modify_icons .= ' < a href = "' . api_get_self() . '?movelink=' . $link->get_id() . '&selectcat=' . $selectcat . '" > < img src = "../img/deplacer_fichier.gif" border = "0" title = "' . get_lang('Move') . '" alt = "" / > < / a > ';
$modify_icons .= ' < a href = "' . api_get_self() . '?visiblelink=' . $link->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . ' " > '.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'',ICON_SIZE_SMALL).'< / a > ';
@ -311,9 +296,13 @@ function build_edit_icons_link($link, $selectcat) {
$show_delete = false;
}
if ($show_delete) {
$modify_icons .= ' < a href = "' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &cidReq='.$link->get_course_code().'" onclick = "return confirmation();" > '.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'< / a > ';
if ($is_locked & & !api_is_platform_admin()) {
$modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
} else {
$modify_icons .= ' < a href = "' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &cidReq='.$link->get_course_code().'" onclick = "return confirmation();" > '.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'< / a > ';
}
} else {
$modify_icons .= ' .'.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
$modify_icons .= ' '.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
}
return $modify_icons;
}
@ -335,7 +324,7 @@ function is_resource_in_course_gradebook($course_code, $resource_type, $resource
// TODO find the corresponding category (the first one for this course, ordered by ID)
$t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "SELECT * FROM $t WHERE course_code = '".Database::escape_string($course_code)."' ";
/* $sql = "SELECT * FROM $t WHERE course_code = '".Database::escape_string($course_code)."' ";
if (!empty($session_id)) {
$sql .= " AND session_id = ".(int)$session_id;
} else {
@ -346,15 +335,17 @@ function is_resource_in_course_gradebook($course_code, $resource_type, $resource
if (Database::num_rows($res)< 1 ) {
return false;
}
$row = Database::fetch_array($res);
$category = $row['id'];
$sql = "SELECT id FROM $l l WHERE l.category_id = $category AND type = ".(int) $resource_type." and ref_id = ".(int) $resource_id;
$row = Database::fetch_array($res,'ASSOC');
$category = $row['id'];*/
$course_code = Database::escape_string($course_code);
$sql = "SELECT * FROM $l l WHERE course_code = '$course_code' AND type = ".(int) $resource_type." and ref_id = ".(int) $resource_id;
$res = Database::query($sql);
if (Database::num_rows($res)< 1 ) {
return false;
}
$row = Database::fetch_array($res);
return $row['id'] ;
$row = Database::fetch_array($res, 'ASSOC' );
return $row;
}
/**
@ -363,11 +354,10 @@ function is_resource_in_course_gradebook($course_code, $resource_type, $resource
* @return bool false on error, true on success
*/
function get_resource_from_course_gradebook($link_id) {
if ( empty($link_id) ) { return false; }
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
if ( empty($link_id) ) { return false; }
// TODO find the corresponding category (the first one for this course, ordered by ID)
$l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "SELECT * FROM $l WHERE id = ".(int)$link_id;
$sql = "SELECT * FROM $l WHERE id = ".(int)$link_id;
$res = Database::query($sql);
$row = array();
if (Database::num_rows($res) > 0) {
@ -624,6 +614,81 @@ function get_user_certificate_content($user_id, $course_code, $is_preview = fals
return array('content' => $new_content_html, 'variables'=>$content_html['variables']);
}
function create_default_course_gradebook() {
if (api_is_allowed_to_edit(true, true)) {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = "SELECT * FROM $t WHERE course_code = '".Database::escape_string($course_code)."' ";
if (!empty($session_id)) {
$sql .= " AND session_id = ".(int)$session_id;
} else {
$sql .= " AND (session_id IS NULL OR session_id = 0) ";
}
$sql .= " ORDER BY id";
$res = Database::query($sql);
if (Database::num_rows($res)< 1 ) {
//there is no unique category for this course+session combination,
$cat = new Category();
if (!empty($session_id)) {
$my_session_id=api_get_session_id();
$s_name = api_get_session_name($my_session_id);
$cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
$cat->set_session_id($session_id);
} else {
$cat->set_name($course_code);
}
$cat->set_course_code($course_code);
$cat->set_description(null);
$cat->set_user_id(api_get_user_id());
$cat->set_parent_id(0);
$cat->set_weight(100);
$cat->set_visible(0);
$cat->add();
$category_id = $cat->get_id();
unset ($cat);
} else {
$row = Database::fetch_array($res);
$category_id = $row['id'];
}
}
return $category_id;
}
function load_gradebook_select_in_tool($form) {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
create_default_course_gradebook();
//Cat list
$all_categories = Category :: load(null, null, $course_code, null, null, $session_id, false);
$select_gradebook = $form->addElement('select', 'category_id', get_lang('SelectGradebook'));
if (!empty($all_categories)) {
foreach ($all_categories as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
$grade_model_id = $my_cat->get_grade_model_id();
if (empty($grade_model_id)) {
if ($my_cat->get_parent_id() == 0) {
//$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
}
} else {
$select_gradebook->addoption(get_lang('Select'), 0);
}
/*if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
} */
}
}
}
}
function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array()) {
// Beginning of PDF report creation