/** * 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('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::get_teacher_list_from_course_code_to_string($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(TO_SYS, WEB_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; } }
/** * Export the given HTML to PDF, using a global template * @param string $content the HTML content * * @uses export/table_pdf.tpl */ public function html_to_pdf_with_template($content) { global $_configuration; Display :: display_no_header(); // Assignments Display::$global_template->assign('pdf_content', $content); $organization = api_get_setting('Institution'); $img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png'; // Search for classic logo if (file_exists($img)) { $img = api_get_path(WEB_CODE_PATH).'css/'.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. if (isset($_configuration['pdf_logo_header']) && $_configuration['pdf_logo_header'] ) { $img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/pdf_logo_header.png'; if (file_exists($img)) { $img = api_get_path(WEB_CODE_PATH) . 'css/' . api_get_visual_theme() . '/images/pdf_logo_header.png'; $organization = "<img src='$img'>"; } } Display::$global_template->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_code'] ); } else { $teacher_list = CourseManager::get_teacher_list_from_course_code_to_string( $this->params['course_code'] ); } } else { $user_info = api_get_user_info(); $teacher_list = $user_info['complete_name']; } Display::$global_template->assign('pdf_course', $this->params['course_code']); Display::$global_template->assign('pdf_course_info', $this->params['course_info']); Display::$global_template->assign('pdf_session_info', $this->params['session_info']); Display::$global_template->assign('pdf_date', api_format_date(api_get_local_time(), DATE_TIME_FORMAT_LONG)); Display::$global_template->assign('pdf_teachers', $teacher_list); Display::$global_template->assign('pdf_title', $this->params['pdf_title']); Display::$global_template->assign('add_signatures', $this->params['add_signatures']); // Getting template $tpl = Display::$global_template->get_template('export/table_pdf.tpl'); $html = Display::$global_template->fetch($tpl); $html = api_utf8_encode($html); $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).'/print.css'; $css = file_exists($css_file) ? @file_get_contents($css_file) : ''; self::content_to_pdf($html, $css, $this->params['filename'], $this->params['course_code']); }
/** * @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::get_teacher_list_from_course_code_to_string( $courseCode ); if (!empty($sessionId)) { $sessionInfo = api_get_session_info($sessionId); if (!empty($sessionInfo)) { $header .= ' - ' . $sessionInfo['name']; $header .= '<br />' . $sessionInfo['description']; $teachers = SessionManager::getCoachesByCourseSessionToString( $sessionId, $courseCode ); } } $header .= '<br />'.get_lang('Teachers').': '.$teachers.'<br />'; $header .= '<br />'.get_lang('Date').': '.api_get_local_time().'<br />'; $header .= '<br />'.get_lang('StudentPublication').': '.$workData['title'].'<br />'; $content = null; $expiresOn = null; if (!empty($assignment) && isset($assignment['expires_on'])) { $content .= '<br /><strong>' . get_lang('ExpiryDate') . '</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)) { require_once api_get_path(LIBRARY_PATH).'pdf.lib.php'; $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' => 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; } }