/**
 * Display the title of a course in course catalog
 * @param $course
 */
function return_title($course)
{
    $html = '';
    $linkCourse = api_get_course_url($course['code']);
    $title = cut($course['title'], 70);
    $ajax_url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=add_course_vote';
    $teachers = CourseManager::getTeacherListFromCourseToString($course['real_id']);
    $rating = Display::return_rating_system('star_' . $course['real_id'], $ajax_url . '&course_id=' . $course['real_id'], $course['point_info']);
    $html .= '<h4 class="title"><a href="' . $linkCourse . '">' . cut($title, 60) . '</a></h4>';
    $html .= '<div class="teachers">' . $teachers . '</div>';
    $html .= '<div class="ranking">' . $rating . '</div>';
    return $html;
}
 /**
  * Return tab of params to display a course title in the My Courses tab
  * Check visibility, right, and notification icons, and load_dirs option
  * @param $courseId
  * @param bool $loadDirs
  * @return array
  */
 public static function getCourseParamsForDisplay($courseId, $loadDirs = false)
 {
     $user_id = api_get_user_id();
     // Table definitions
     $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE);
     $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $TABLE_ACCESS_URL_REL_COURSE = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
     $current_url_id = api_get_current_access_url_id();
     // Get course list auto-register
     $special_course_list = self::get_special_course_list();
     $without_special_courses = '';
     if (!empty($special_course_list)) {
         $without_special_courses = ' AND course.code NOT IN ("' . implode('","', $special_course_list) . '")';
     }
     //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
     $sql = "SELECT course.id, course.title, course.code, course.subscribe subscr, course.unsubscribe unsubscr, course_rel_user.status status,\n                course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat\n                FROM\n                {$TABLECOURS} course,\n                {$TABLECOURSUSER}  course_rel_user, " . $TABLE_ACCESS_URL_REL_COURSE . " url\n                WHERE\n                    course.id=" . intval($courseId) . " AND\n                    course.id = course_rel_user.c_id AND\n                    url.c_id = course.id AND\n                    course_rel_user.user_id = " . intval($user_id) . "\n                    {$without_special_courses}\n                ";
     // If multiple URL access mode is enabled, only fetch courses
     // corresponding to the current URL.
     if (api_get_multiple_access_url() && $current_url_id != -1) {
         $sql .= " AND url.course_code=course.code AND access_url_id=" . intval($current_url_id);
     }
     // Use user's classification for courses (if any).
     $sql .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
     $result = Database::query($sql);
     // Browse through all courses. We can only have one course because
     // of the  course.id=".intval($courseId) in sql query
     $course = Database::fetch_array($result);
     $course_info = api_get_course_info_by_id($courseId);
     if (empty($course_info)) {
         return '';
     }
     //$course['id_session'] = null;
     $course_info['id_session'] = null;
     $course_info['status'] = $course['status'];
     // For each course, get if there is any notification icon to show
     // (something that would have changed since the user's last visit).
     $show_notification = Display::show_notification($course_info);
     // New code displaying the user's status in respect to this course.
     $status_icon = Display::return_icon('blackboard.png', $course_info['title'], array(), ICON_SIZE_LARGE);
     $params = array();
     $params['right_actions'] = '';
     if (api_is_platform_admin()) {
         if ($loadDirs) {
             $params['right_actions'] .= '<a id="document_preview_' . $course_info['real_id'] . '_0" class="document_preview" href="javascript:void(0);">' . Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>';
             $params['right_actions'] .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>';
             $params['right_actions'] .= Display::div('', array('id' => 'document_result_' . $course_info['real_id'] . '_0', 'class' => 'document_preview_container'));
         } else {
             $params['right_actions'] .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>';
         }
         if ($course_info['status'] == COURSEMANAGER) {
             //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;'));
         }
     } else {
         if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
             if ($loadDirs) {
                 $params['right_actions'] .= '<a id="document_preview_' . $course_info['real_id'] . '_0" class="document_preview" href="javascript:void(0);">' . Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>';
                 $params['right_actions'] .= Display::div('', array('id' => 'document_result_' . $course_info['real_id'] . '_0', 'class' => 'document_preview_container'));
             } else {
                 if ($course_info['status'] == COURSEMANAGER) {
                     $params['right_actions'] .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>';
                 }
             }
         }
     }
     $course_title_url = '';
     if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) {
         $course_title_url = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/?id_session=0';
         $course_title = Display::url($course_info['title'], $course_title_url);
     } else {
         $course_title = $course_info['title'] . " " . Display::tag('span', get_lang('CourseClosed'), array('class' => 'item_closed'));
     }
     // Start displaying the course block itself
     if (api_get_setting('course.display_coursecode_in_courselist') == 'true') {
         $course_title .= ' (' . $course_info['visual_code'] . ') ';
     }
     $teachers = '';
     if (api_get_setting('course.display_teacher_in_courselist') == 'true') {
         $teachers = CourseManager::getTeacherListFromCourseToString($course['real_id'], self::USER_SEPARATOR, true);
     }
     $params['link'] = $course_title_url;
     $params['icon'] = $status_icon;
     $params['title'] = $course_title;
     $params['teachers'] = $teachers;
     if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
         $params['notifications'] = $show_notification;
     }
     return $params;
 }
Exemple #3
0
// Create a search-box.
$form_search = new FormValidator('search_simple', 'GET', api_get_path(WEB_CODE_PATH) . 'tracking/courseLog.php?' . api_get_cidreq(), '', array(), FormValidator::LAYOUT_INLINE);
$form_search->addElement('hidden', 'from', Security::remove_XSS($from));
$form_search->addElement('hidden', 'session_id', $sessionId);
$form_search->addElement('hidden', 'id_session', $sessionId);
$form_search->addElement('text', 'user_keyword');
$form_search->addButtonSearch(get_lang('SearchUsers'));
echo Display::toolbarAction('toolbar-courselog', array(0 => $actionsLeft, 1 => $form_search->returnForm(), 2 => $actionsRight), 3);
$course_name = get_lang('Course') . ' ' . $courseInfo['name'];
if ($session_id) {
    $titleSession = Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL) . ' ' . api_get_session_name($session_id);
    $titleCourse = Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL) . ' ' . $course_name;
} else {
    $titleSession = Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL) . ' ' . $courseInfo['name'];
}
$teacherList = CourseManager::getTeacherListFromCourseToString($courseInfo['real_id'], ',', false, true);
$coaches = null;
if (!empty($session_id)) {
    $coaches = CourseManager::get_coachs_from_course_to_string($session_id, $courseInfo['real_id'], ',', false, true);
}
$html = '';
if (!empty($teacherList)) {
    $html .= Display::page_subheader2(get_lang('Teachers'));
    $html .= $teacherList;
}
if (!empty($coaches)) {
    $html .= Display::page_subheader2(get_lang('Coaches'));
    $html .= $coaches;
}
$sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
if (!empty($sessionList)) {
 /**
  * Display list of courses in a category.
  * (for anonymous users)
  *
  * @version 1.1
  * @author Patrick Cool <*****@*****.**>, Ghent University - refactoring and code cleaning
  * @author Julio Montoya <*****@*****.**>, Beeznest template modifs
  */
 function return_courses_in_categories()
 {
     $result = '';
     $stok = Security::get_token();
     // Initialization.
     $user_identified = api_get_user_id() > 0 && !api_is_anonymous();
     $web_course_path = api_get_path(WEB_COURSE_PATH);
     $category = Database::escape_string($_GET['category']);
     $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
     // Database table definitions.
     $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
     $main_category_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
     // Get list of courses in category $category.
     $sql_get_course_list = "SELECT * FROM {$main_course_table} cours\n                                    WHERE category_code = '" . Database::escape_string($_GET['category']) . "'\n                                    ORDER BY title, UPPER(visual_code)";
     // Showing only the courses of the current access_url_id.
     if (api_is_multiple_url_enabled()) {
         $url_access_id = api_get_current_access_url_id();
         if ($url_access_id != -1) {
             $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
             $sql_get_course_list = "SELECT * FROM {$main_course_table} as course\n                        INNER JOIN {$tbl_url_rel_course} as url_rel_course\n                        ON (url_rel_course.c_id = course.id)\n                        WHERE\n                            access_url_id = {$url_access_id} AND\n                            category_code = '" . Database::escape_string($_GET['category']) . "'\n                        ORDER BY title, UPPER(visual_code)";
         }
     }
     // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
     $sql_result_courses = Database::query($sql_get_course_list);
     while ($course_result = Database::fetch_array($sql_result_courses)) {
         $course_list[] = $course_result;
     }
     // $setting_show_also_closed_courses
     if ($user_identified) {
         if ($setting_show_also_closed_courses) {
             $platform_visible_courses = '';
         } else {
             $platform_visible_courses = "  AND (t3.visibility='" . COURSE_VISIBILITY_OPEN_WORLD . "' OR t3.visibility='" . COURSE_VISIBILITY_OPEN_PLATFORM . "' )";
         }
     } else {
         if ($setting_show_also_closed_courses) {
             $platform_visible_courses = '';
         } else {
             $platform_visible_courses = "  AND (t3.visibility='" . COURSE_VISIBILITY_OPEN_WORLD . "' )";
         }
     }
     $sqlGetSubCatList = "\n                    SELECT  t1.name,\n                            t1.code,\n                            t1.parent_id,\n                            t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse\n                    FROM {$main_category_table} t1\n                    LEFT JOIN {$main_category_table} t2 ON t1.code=t2.parent_id\n                    LEFT JOIN {$main_course_table} t3 ON (t3.category_code = t1.code {$platform_visible_courses})\n                    WHERE t1.parent_id " . (empty($category) ? "IS NULL" : "='{$category}'") . "\n                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
     // Showing only the category of courses of the current access_url_id
     if (api_is_multiple_url_enabled()) {
         $courseCategoryCondition = null;
         if (CourseCategoryManager::isMultipleUrlSupport()) {
             $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
             $courseCategoryCondition = " INNER JOIN {$table} a ON (t1.id = a.course_category_id)";
         }
         $url_access_id = api_get_current_access_url_id();
         if ($url_access_id != -1) {
             $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
             $sqlGetSubCatList = "\n                    SELECT t1.name,\n                            t1.code,\n                            t1.parent_id,\n                            t1.children_count,\n                            COUNT(DISTINCT t3.code) AS nbCourse\n                    FROM {$main_category_table} t1\n                    {$courseCategoryCondition}\n                    LEFT JOIN {$main_category_table} t2 ON t1.code = t2.parent_id\n                    LEFT JOIN {$main_course_table} t3 ON (t3.category_code = t1.code {$platform_visible_courses})\n                    INNER JOIN {$tbl_url_rel_course} as url_rel_course\n                    ON (url_rel_course.c_id = t3.id)\n                    WHERE\n                        url_rel_course.access_url_id = {$url_access_id} AND\n                        t1.parent_id " . (empty($category) ? "IS NULL" : "='{$category}'") . "\n                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count\n                    ORDER BY t1.tree_pos, t1.name";
         }
     }
     $resCats = Database::query($sqlGetSubCatList);
     $thereIsSubCat = false;
     if (Database::num_rows($resCats) > 0) {
         $htmlListCat = Display::page_header(get_lang('CatList'));
         $htmlListCat .= '<ul>';
         $htmlTitre = '';
         while ($catLine = Database::fetch_array($resCats)) {
             $category_has_open_courses = self::category_has_open_courses($catLine['code']);
             if ($category_has_open_courses) {
                 // The category contains courses accessible to anonymous visitors.
                 $htmlListCat .= '<li>';
                 $htmlListCat .= '<a href="' . api_get_self() . '?category=' . $catLine['code'] . '">' . $catLine['name'] . '</a>';
                 if (api_get_setting('show_number_of_courses') == 'true') {
                     $htmlListCat .= ' (' . $catLine['nbCourse'] . ' ' . get_lang('Courses') . ')';
                 }
                 $htmlListCat .= "</li>";
                 $thereIsSubCat = true;
             } elseif ($catLine['children_count'] > 0) {
                 // The category has children, subcategories.
                 $htmlListCat .= '<li>';
                 $htmlListCat .= '<a href="' . api_get_self() . '?category=' . $catLine['code'] . '">' . $catLine['name'] . '</a>';
                 $htmlListCat .= "</li>";
                 $thereIsSubCat = true;
             } elseif (api_get_setting('show_empty_course_categories') == 'true') {
                 /* End changed code to eliminate the (0 courses) after empty categories. */
                 $htmlListCat .= '<li>';
                 $htmlListCat .= $catLine['name'];
                 $htmlListCat .= "</li>";
                 $thereIsSubCat = true;
             }
             // Else don't set thereIsSubCat to true to avoid printing things if not requested.
             // TODO: deprecate this useless feature - this includes removing system variable
             if (empty($htmlTitre)) {
                 $htmlTitre = '<p>';
                 if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
                     $htmlTitre .= '<a href="' . api_get_self() . '">&lt;&lt; ' . get_lang('BackToHomePage') . '</a>';
                 }
                 $htmlTitre .= "</p>";
             }
         }
         $htmlListCat .= "</ul>";
     }
     $result .= $htmlTitre;
     if ($thereIsSubCat) {
         $result .= $htmlListCat;
     }
     while ($categoryName = Database::fetch_array($resCats)) {
         $result .= '<h3>' . $categoryName['name'] . "</h3>\n";
     }
     $numrows = Database::num_rows($sql_result_courses);
     $courses_list_string = '';
     $courses_shown = 0;
     if ($numrows > 0) {
         $courses_list_string .= Display::page_header(get_lang('CourseList'));
         $courses_list_string .= "<ul>";
         if (api_get_user_id()) {
             $courses_of_user = self::get_courses_of_user(api_get_user_id());
         }
         foreach ($course_list as $course) {
             // $setting_show_also_closed_courses
             if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
                 continue;
             }
             if (!$setting_show_also_closed_courses) {
                 // If we do not show the closed courses
                 // we only show the courses that are open to the world (to everybody)
                 // and the courses that are open to the platform (if the current user is a registered user.
                 if ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM || $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD) {
                     $courses_shown++;
                     $courses_list_string .= "<li>";
                     $courses_list_string .= '<a href="' . $web_course_path . $course['directory'] . '/">' . $course['title'] . '</a><br />';
                     $course_details = array();
                     if (api_get_setting('course.display_coursecode_in_courselist') == 'true') {
                         $course_details[] = $course['visual_code'];
                     }
                     if (api_get_setting('course.display_teacher_in_courselist') == 'true') {
                         $course_details[] = CourseManager::getTeacherListFromCourseToString($course['real_id']);
                     }
                     if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('language.platform_language')) {
                         $course_details[] = $course['course_language'];
                     }
                     $courses_list_string .= implode(' - ', $course_details);
                     $courses_list_string .= "</li>";
                 }
             } else {
                 // We DO show the closed courses.
                 // The course is accessible if (link to the course homepage):
                 // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
                 // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
                 // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
                 // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
                 // 5. the user is the platform admin api_is_platform_admin().
                 $courses_shown++;
                 $courses_list_string .= "<li>";
                 if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM || $user_identified && array_key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED || $courses_of_user[$course['code']]['status'] == '1' || api_is_platform_admin()) {
                     $courses_list_string .= '<a href="' . $web_course_path . $course['directory'] . '/">';
                 }
                 $courses_list_string .= $course['title'];
                 if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM || $user_identified && array_key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED || $courses_of_user[$course['code']]['status'] == '1' || api_is_platform_admin()) {
                     $courses_list_string .= '</a><br />';
                 }
                 $course_details = array();
                 if (api_get_setting('course.display_coursecode_in_courselist') == 'true') {
                     $course_details[] = $course['visual_code'];
                 }
                 //                        if (api_get_setting('course.display_coursecode_in_courselist') == 'true' && api_get_setting('course.display_teacher_in_courselist') == 'true') {
                 //                        $courses_list_string .= ' - ';
                 //                }
                 if (api_get_setting('course.display_teacher_in_courselist') == 'true') {
                     if (!empty($course['tutor_name'])) {
                         $course_details[] = $course['tutor_name'];
                     }
                 }
                 if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('language.platform_language')) {
                     $course_details[] = $course['course_language'];
                 }
                 $courses_list_string .= implode(' - ', $course_details);
                 // We display a subscription link if:
                 // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
                 // 2.
                 if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
                     if ($course['subscribe'] == '1') {
                         $courses_list_string .= '&nbsp;<a class="btn btn-primary" href="main/auth/courses.php?action=subscribe_course&sec_token=' . $stok . '&subscribe_course=' . $course['code'] . '&category_code=' . Security::remove_XSS($_GET['category']) . '">' . get_lang('Subscribe') . '</a><br />';
                     } else {
                         $courses_list_string .= '<br />' . get_lang('SubscribingNotAllowed');
                     }
                 }
                 $courses_list_string .= "</li>";
             }
             //end else
         }
         // end foreach
         $courses_list_string .= "</ul>";
     }
     if ($courses_shown > 0) {
         // Only display the list of courses and categories if there was more than
         // 0 courses visible to the world (we're in the anonymous list here).
         $result .= $courses_list_string;
     }
     if ($category != '') {
         $result .= '<p><a href="' . api_get_self() . '"> ' . Display::return_icon('back.png', get_lang('BackToHomePage')) . get_lang('BackToHomePage') . '</a></p>';
     }
     return $result;
 }
Exemple #5
0
 /**
  * Export the given HTML to PDF, using a global template
  *
  * @uses export/table_pdf.tpl
  * @param $content
  * @param bool|false $saveToFile
  * @param bool|false $returnHtml
  *
  * @return string
  */
 public function html_to_pdf_with_template($content, $saveToFile = false, $returnHtml = false)
 {
     if (empty($this->template)) {
         $tpl = new Template('', false, false, false);
     } else {
         $tpl = $this->template;
     }
     // Assignments
     // Assignments
     $tpl->assign('pdf_content', $content);
     $organization = api_get_setting('platform.institution');
     $img = api_get_path(SYS_CSS_PATH) . 'themes/' . api_get_visual_theme() . '/images/header-logo.png';
     // Search for classic logo
     if (file_exists($img)) {
         $img = api_get_path(WEB_CSS_PATH) . 'themes/' . api_get_visual_theme() . '/images/header-logo.png';
         $organization = "<img src='{$img}'>";
     } else {
         // Just use the platform title.
         if (!empty($organization)) {
             $organization = '<h2 align="left">' . $organization . '</h2>';
         }
     }
     // Use custom logo image.
     $pdfLogo = api_get_setting('pdf_logo_header');
     if ($pdfLogo === 'true') {
         $visualTheme = api_get_visual_theme();
         $img = api_get_path(SYS_CSS_PATH) . 'themes/' . $visualTheme . '/images/pdf_logo_header.png';
         if (file_exists($img)) {
             $img = api_get_path(WEB_CSS_PATH) . 'themes/' . $visualTheme . '/images/pdf_logo_header.png';
             $organization = "<img src='{$img}'>";
         }
     }
     $tpl->assign('organization', $organization);
     //Showing only the current teacher/admin instead the all teacher list name see BT#4080
     if (isset($this->params['show_real_course_teachers']) && $this->params['show_real_course_teachers']) {
         if (isset($this->params['session_info']) && !empty($this->params['session_info'])) {
             $teacher_list = SessionManager::getCoachesByCourseSessionToString($this->params['session_info']['id'], $this->params['course_info']['real_id']);
         } else {
             $teacher_list = CourseManager::getTeacherListFromCourseToString($this->params['course_code']);
         }
     } else {
         $user_info = api_get_user_info();
         if ($this->params['show_teacher_as_myself']) {
             $teacher_list = $user_info['complete_name'];
         }
     }
     $tpl->assign('pdf_course', $this->params['course_code']);
     $tpl->assign('pdf_course_info', $this->params['course_info']);
     $tpl->assign('pdf_session_info', $this->params['session_info']);
     $tpl->assign('pdf_date', $this->params['pdf_date']);
     $tpl->assign('pdf_teachers', $teacher_list);
     $tpl->assign('pdf_title', $this->params['pdf_title']);
     $tpl->assign('pdf_student_info', $this->params['student_info']);
     $tpl->assign('show_grade_generated_date', $this->params['show_grade_generated_date']);
     $tpl->assign('add_signatures', $this->params['add_signatures']);
     // Getting template
     $tableTemplate = $tpl->get_template('export/table_pdf.tpl');
     $html = $tpl->fetch($tableTemplate);
     $html = api_utf8_encode($html);
     $css_file = api_get_path(SYS_CSS_PATH) . '/print.css';
     $css = file_exists($css_file) ? @file_get_contents($css_file) : '';
     $html = self::content_to_pdf($html, $css, $this->params['filename'], $this->params['course_code'], 'D', $saveToFile, null, $returnHtml);
     if ($returnHtml) {
         return $html;
     }
 }
Exemple #6
0
/**
 * @param int $workId
 * @param array $courseInfo
 * @param int $sessionId
 * @param string $format
 * @return bool
 */
function exportAllStudentWorkFromPublication($workId, $courseInfo, $sessionId, $format = 'pdf')
{
    if (empty($courseInfo)) {
        return false;
    }
    $workData = get_work_data_by_id($workId);
    if (empty($workData)) {
        return false;
    }
    $assignment = get_work_assignment_by_id($workId);
    $courseCode = $courseInfo['code'];
    $header = get_lang('Course') . ': ' . $courseInfo['title'];
    $teachers = CourseManager::getTeacherListFromCourseToString($courseInfo['real_id']);
    if (!empty($sessionId)) {
        $sessionInfo = api_get_session_info($sessionId);
        if (!empty($sessionInfo)) {
            $header .= ' - ' . $sessionInfo['name'];
            $header .= '<br />' . $sessionInfo['description'];
            $teachers = SessionManager::getCoachesByCourseSessionToString($sessionId, $courseInfo['real_id']);
        }
    }
    $header .= '<br />' . get_lang('Teachers') . ': ' . $teachers . '<br />';
    $header .= '<br />' . get_lang('Date') . ': ' . api_get_local_time() . '<br />';
    $header .= '<br />' . get_lang('WorkName') . ': ' . $workData['title'] . '<br />';
    $content = null;
    $expiresOn = null;
    if (!empty($assignment) && isset($assignment['expires_on'])) {
        $content .= '<br /><strong>' . get_lang('ExpirationDate') . '</strong>: ' . api_get_local_time($assignment['expires_on']);
        $expiresOn = api_get_local_time($assignment['expires_on']);
    }
    if (!empty($workData['description'])) {
        $content .= '<br /><strong>' . get_lang('Description') . '</strong>: ' . $workData['description'];
    }
    $workList = get_work_user_list(null, null, null, null, $workId);
    switch ($format) {
        case 'pdf':
            if (!empty($workList)) {
                $table = new HTML_Table(array('class' => 'data_table'));
                $headers = array(get_lang('Name'), get_lang('User'), get_lang('HandOutDateLimit'), get_lang('SentDate'), get_lang('FileName'), get_lang('Score'), get_lang('Feedback'));
                $column = 0;
                foreach ($headers as $header) {
                    $table->setHeaderContents(0, $column, $header);
                    $column++;
                }
                $row = 1;
                //$pdf->set_custom_header($header);
                foreach ($workList as $work) {
                    $content .= '<hr />';
                    // getWorkComments need c_id
                    $work['c_id'] = $courseInfo['real_id'];
                    //$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />';
                    $score = null;
                    if (!empty($work['qualification_only'])) {
                        $score = $work['qualification_only'];
                    }
                    //$content .= get_lang('Description').': '.$work['description'].'<br />';
                    $comments = getWorkComments($work);
                    $feedback = null;
                    if (!empty($comments)) {
                        $content .= '<h4>' . get_lang('Feedback') . ': </h4>';
                        foreach ($comments as $comment) {
                            $feedback .= get_lang('User') . ': ' . api_get_person_name($comment['firstname'], $comment['lastname']) . '<br />';
                            $feedback .= $comment['comment'] . '<br />';
                        }
                    }
                    $table->setCellContents($row, 0, strip_tags($workData['title']));
                    $table->setCellContents($row, 1, api_get_person_name(strip_tags($work['firstname']), strip_tags($work['lastname'])));
                    $table->setCellContents($row, 2, $expiresOn);
                    $table->setCellContents($row, 3, api_get_local_time($work['sent_date_from_db']));
                    $table->setCellContents($row, 4, strip_tags($work['title']));
                    $table->setCellContents($row, 5, $score);
                    $table->setCellContents($row, 6, $feedback);
                    $row++;
                }
                $content = $table->toHtml();
                if (!empty($content)) {
                    $params = array('filename' => $workData['title'] . '_' . api_get_local_time(), 'pdf_title' => api_replace_dangerous_char($workData['title']), 'course_code' => $courseInfo['code'], 'add_signatures' => false);
                    $pdf = new PDF('A4', null, $params);
                    $pdf->html_to_pdf_with_template($content);
                }
                exit;
            }
            break;
    }
}