/**
  * @param Category $catobj
  * @param $showtree
  * @param $selectcat
  * @param $is_course_admin
  * @param $is_platform_admin
  * @param $simple_search_form
  * @param bool $show_add_qualification
  * @param bool $show_add_link
  */
 public function display_header_gradebook_per_gradebook($catobj, $showtree, $selectcat, $is_course_admin, $is_platform_admin, $simple_search_form, $show_add_qualification = true, $show_add_link = true)
 {
     // Student
     $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
     $objcat = new Category();
     $course_id = Database::get_course_by_category($selectcat);
     $message_resource = $objcat->show_message_resource_delete($course_id);
     if (!$is_course_admin && $status != 1 && $selectcat != 0) {
         $user_id = api_get_user_id();
         $user = get_user_info_from_id($user_id);
         $catcourse = Category::load($catobj->get_id());
         $scoredisplay = ScoreDisplay::instance();
         $scorecourse = $catcourse[0]->calc_score($user_id);
         // generating the total score for a course
         $allevals = $catcourse[0]->get_evaluations($user_id, true);
         $alllinks = $catcourse[0]->get_links($user_id, true);
         $evals_links = array_merge($allevals, $alllinks);
         $item_value = 0;
         $item_total = 0;
         for ($count = 0; $count < count($evals_links); $count++) {
             $item = $evals_links[$count];
             $score = $item->calc_score($user_id);
             $my_score_denom = $score[1] == 0 ? 1 : $score[1];
             $item_value += $score[0] / $my_score_denom * $item->get_weight();
             $item_total += $item->get_weight();
         }
         $item_value = number_format($item_value, 2, '.', ' ');
         $total_score = array($item_value, $item_total);
         $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
         $cattotal = Category::load(0);
         $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
         $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable');
         $scoreinfo = get_lang('StatsStudent') . ' :<b> ' . api_get_person_name($user['firstname'], $user['lastname']) . '</b><br />';
         if (!$catobj->get_id() == '0' && !isset($_GET['studentoverview']) && !isset($_GET['search'])) {
             $scoreinfo .= '<h2>' . get_lang('Total') . ' : ' . $scorecourse_display . '</h2>';
         }
         Display::display_normal_message($scoreinfo, false);
     }
     // show navigation tree and buttons?
     $header = '<div class="actions"><table border=0>';
     if ($showtree == '1' || isset($_GET['studentoverview'])) {
         $header .= '<tr>';
         if (!$selectcat == '0') {
             $header .= '<td style=" "><a href="' . api_get_self() . '?selectcat=' . $catobj->get_parent_id() . '">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('RootCat'), '', ICON_SIZE_MEDIUM) . '</a></td>';
         }
         $header .= '<td style=" ">' . get_lang('CurrentCategory') . '</td>' . '<td style=" "><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
         $cats = Category::load();
         $tree = $cats[0]->get_tree();
         unset($cats);
         foreach ($tree as $cat) {
             for ($i = 0; $i < $cat[2]; $i++) {
                 $line .= '&mdash;';
             }
             $line = isset($line) ? $line : '';
             if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
                 $header .= '<option selected value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
             } else {
                 $header .= '<option value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
             }
             $line = '';
         }
         $header .= '</select></form></td>';
         if (!empty($simple_search_form) && $message_resource === false) {
             $header .= '<td style="vertical-align: top;">' . $simple_search_form->toHtml() . '</td>';
         } else {
             $header .= '<td></td>';
         }
         if ($is_course_admin && $message_resource === false && $_GET['selectcat'] != 0) {
             /* $header .= '<td style="vertical-align: top;"><a href="gradebook_flatview.php?'.api_get_cidreq().'&selectcat=' . $catobj->get_id() . '"><img src="../img/view_list.gif" alt="' . get_lang('FlatView') . '" /> ' . get_lang('FlatView') . '</a>';
                if ($is_course_admin && $message_resource===false) {
                $header .= '<td style="vertical-align: top;"><a href="gradebook_scoring_system.php?'.api_get_cidreq().'&selectcat=' . $catobj->get_id() .'"><img src="../img/acces_tool.gif" alt="' . get_lang('ScoreEdit') . '" /> ' . get_lang('ScoreEdit') . '</a>';
                } */
         } elseif (!isset($_GET['studentoverview'])) {
             if ($message_resource === false) {
                 //$header .= '<td style="vertical-align: top;"><a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&selectcat=' . $catobj->get_id() . '"><img src="../img/view_list.gif" alt="' . get_lang('FlatView') . '" /> ' . get_lang('FlatView') . '</a>';
             }
         } else {
             $header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?' . api_get_cidreq() . '&studentoverview=&exportpdf=&selectcat=' . $catobj->get_id() . '" target="_blank"><img src="../img/icons/32/pdf.png" alt="' . get_lang('ExportPDF') . '" /> ' . get_lang('ExportPDF') . '</a>';
         }
         $header .= '</td></tr>';
     }
     $header .= '</table></div>';
     // for course admin & platform admin add item buttons are added to the header
     $header .= '<div class="actions">';
     $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
     $user_id = api_get_user_id();
     $course_code = $my_category['course_code'];
     $status_user = api_get_status_of_user_in_course($user_id, $course_code);
     //$header .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat=0"><img src="../img/folder_new.gif" alt="' . get_lang('AddGradebook') . '" /></a></td>';
     if (api_is_allowed_to_edit(null, true)) {
         if ($selectcat == '0') {
             if ($show_add_qualification === true) {
             }
             if ($show_add_link) {
                 //$header .= '<td><a href="gradebook_add_eval.php?'.api_get_cidreq().'"><img src="../img/filenew.gif" alt="' . get_lang('NewEvaluation') . '" /> ' . get_lang('NewEvaluation') . '</a>';
             }
         } else {
             if ($show_add_qualification === true && $message_resource === false) {
                 //$header .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat=' . $catobj->get_id() . '" ><img src="../img/folder_new.gif" alt="' . get_lang('NewSubCategory') . '" align="absmiddle" /> ' . get_lang('NewSubCategory') . '</a></td>';
             }
             $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
             $my_api_cidreq = api_get_cidreq();
             if ($my_api_cidreq == '') {
                 $my_api_cidreq = 'cidReq=' . $my_category['course_code'];
             }
             if ($show_add_link && !$message_resource) {
                 //$header .= '<td><a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '" >'.Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'),'',ICON_SIZE_MEDIUM).'</a>';
                 $cats = Category::load($selectcat);
                 if ($cats[0]->get_course_code() != null && !$message_resource) {
                     //$header .= '<td><a href="gradebook_add_link.php?'.api_get_cidreq().'&selectcat=' . $catobj->get_id() . '"><img src="../img/link.gif" alt="' . get_lang('MakeLink') . '" align="absmiddle" /> ' . get_lang('MakeLink') . '</a>';
                     //$header .= '<td><a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'),'',ICON_SIZE_MEDIUM).'</a>';
                 } else {
                     //	$header .= '<td><a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'),'',ICON_SIZE_MEDIUM).'</a>';
                 }
             }
             if (!$message_resource) {
                 $myname = $catobj->shows_all_information_an_category($catobj->get_id());
                 $my_course_id = api_get_course_id();
                 $my_file = substr($_SESSION['gradebook_dest'], 0, 5);
                 $header .= '<td style="vertical-align: top;"><a href="gradebook_flatview.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' . Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . '</a>';
                 $header .= '<td style="vertical-align: top;"><a href="gradebook_display_certificate.php?' . $my_api_cidreq . '&amp;cat_id=' . (int) $_GET['selectcat'] . '">' . Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'), '', ICON_SIZE_MEDIUM) . '</a>';
                 $visibility_icon = $catobj->is_visible() == 0 ? 'invisible' : 'visible';
                 $visibility_command = $catobj->is_visible() == 0 ? 'set_visible' : 'set_invisible';
                 //Right icons
                 $modify_icons = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . '&cidReq=' . $catobj->get_course_code() . '&id_session=' . $catobj->get_session_id() . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM) . '</a>';
                 //$modify_icons .= '<a href="../document/document.php?curdirpath=/certificates&'.$my_api_cidreq.'&origin=gradebook&selectcat=' . $catobj->get_id() . '">'.
                 //Display::return_icon('certificate.png', get_lang('AttachCertificate'),'',ICON_SIZE_MEDIUM).'</a>';
                 //hide or delete are not options available
                 //$modify_icons .= '&nbsp;<a  href="' . api_get_self() . '?visiblecat=' . $catobj->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'',ICON_SIZE_MEDIUM).'</a>';
                 if ($catobj->get_name() != api_get_course_id()) {
                     $modify_icons .= '&nbsp;<a  href="' . api_get_self() . '?deletecat=' . $catobj->get_id() . '&amp;selectcat=0&amp;cidReq=' . $catobj->get_course_code() . '" onclick="return confirmation();">' . Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_MEDIUM) . '</a>';
                 }
                 $header .= Display::div($modify_icons, array('class' => 'right'));
             }
         }
     } elseif (isset($_GET['search'])) {
         $header .= '<b>' . get_lang('SearchResults') . ' :</b>';
     }
     $header .= '</div>';
     echo $header;
 }
 /**
  * Builds the course or platform admin icons to edit a category
  * @param Category $cat category
  * @param Category $selectcat id of selected category
  */
 public static function build_edit_icons_cat($cat, $selectcat)
 {
     $show_message = $cat->show_message_resource_delete($cat->get_course_code());
     $grade_model_id = $selectcat->get_grade_model_id();
     $selectcat = $selectcat->get_id();
     $modify_icons = null;
     if ($show_message === false) {
         $visibility_icon = $cat->is_visible() == 0 ? 'invisible' : 'visible';
         $visibility_command = $cat->is_visible() == 0 ? 'set_visible' : 'set_invisible';
         $modify_icons .= '<a class="view_children" data-cat-id="' . $cat->get_id() . '" href="javascript:void(0);">' . Display::return_icon('view_more_stats.gif', get_lang('Show'), '', ICON_SIZE_SMALL) . '</a>';
         if (!api_is_allowed_to_edit(null, true)) {
             $modify_icons .= Display::url(Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_SMALL), 'personal_stats.php?' . http_build_query(['selectcat' => $cat->get_id()]) . '&' . api_get_cidreq(), ['class' => 'ajax', 'data-title' => get_lang('FlatView')]);
         }
         if (api_is_allowed_to_edit(null, true)) {
             // Locking button
             if (api_get_setting('gradebook_locking_enabled') == 'true') {
                 if ($cat->is_locked()) {
                     if (api_is_platform_admin()) {
                         $modify_icons .= '&nbsp;<a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToUnlockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=unlock">' . Display::return_icon('lock.png', get_lang('UnLockEvaluation'), '', ICON_SIZE_SMALL) . '</a>';
                     } else {
                         $modify_icons .= '&nbsp;<a href="#">' . Display::return_icon('lock_na.png', get_lang('GradebookLockedAlert'), '', ICON_SIZE_SMALL) . '</a>';
                     }
                     $modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>';
                 } else {
                     $modify_icons .= '&nbsp;<a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToLockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=lock">' . Display::return_icon('unlock.png', get_lang('LockEvaluation'), '', ICON_SIZE_SMALL) . '</a>';
                     $modify_icons .= '&nbsp;<a href="#" >' . Display::return_icon('pdf_na.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>';
                 }
             }
             if (empty($grade_model_id) || $grade_model_id == -1) {
                 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() . '&id_session=' . $cat->get_session_id() . '">' . Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
                 }
             }
             $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' . $cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session=' . $cat->get_session_id() . '">' . Display::return_icon('percentage.png', get_lang('EditAllWeights'), '', ICON_SIZE_SMALL) . '</a>';
             $modify_icons .= '<a href="gradebook_flatview.php?selectcat=' . $cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session=' . $cat->get_session_id() . '">' . Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_SMALL) . '</a>';
             $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblecat=' . $cat->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&cidReq=' . $cat->get_course_code() . '&id_session=' . $cat->get_session_id() . '">' . Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
             //no move ability for root categories
             if ($cat->is_movable()) {
                 /* $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?movecat=' . $cat->get_id() . '&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$cat->get_course_code().'">
                    <img src="../img/icons/22/move.png" border="0" title="' . get_lang('Move') . '" alt="" /></a>'; */
             } else {
                 //$modify_icons .= '&nbsp;<img src="../img/deplacer_fichier_na.gif" border="0" title="' . get_lang('Move') . '" alt="" />';
             }
             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 .= '&nbsp;<a href="' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '&cidReq=' . $cat->get_course_code() . '&id_session=' . $cat->get_session_id() . '" onclick="return confirmation();">' . Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL) . '</a>';
             }
         }
         return $modify_icons;
     }
 }