Skip to content

Commit 96f3aae

Browse files
committed
Allowing export glosary items to PDF see BT#4686
1 parent a8bf404 commit 96f3aae

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

main/glossary/index.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ function sorter($item1, $item2) {
8282
$filename = 'glossary_course_'.api_get_course_id();
8383
Export::export_table_csv_utf8($list, $filename);
8484
}
85+
if (isset($_GET['action']) && $_GET['action'] == 'export_to_pdf') {
86+
GlossaryManager::export_to_pdf();
87+
}
8588

8689
Display::display_header($tool_name);
8790

@@ -218,7 +221,7 @@ function sorter($item1, $item2) {
218221
$data = Import::csv_reader($_FILES['file']['tmp_name']);
219222
$good = 0;
220223
$bad = 0;
221-
foreach($data as $item) {
224+
foreach ($data as $item) {
222225
if (GlossaryManager::save_glossary(array('glossary_title' => $item['term'], 'glossary_comment' => $item['definition']), false))
223226
$good++;
224227
else
@@ -230,9 +233,9 @@ function sorter($item1, $item2) {
230233
if ($bad)
231234
Display::display_error_message (get_lang ("TermsNotImported") . ':' . $bad);
232235

233-
GlossaryManager::display_glossary();
236+
GlossaryManager::display_glossary();
234237
}
235-
break;
238+
break;
236239
default:
237240
GlossaryManager::display_glossary();
238241
break;

main/inc/lib/glossary.lib.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ function glossary_exists($term,$not_id='') {
209209
return false;
210210
}
211211
}
212+
212213
/**
213214
* Get one specific glossary term data
214215
*
@@ -217,7 +218,7 @@ function glossary_exists($term,$not_id='') {
217218
*
218219
* @author Patrick Cool <[email protected]>, Ghent University, Belgium
219220
*/
220-
function get_glossary_information($glossary_id) {
221+
static function get_glossary_information($glossary_id) {
221222
// Database table definition
222223
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
223224
$t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@@ -280,14 +281,15 @@ function delete_glossary($glossary_id, $message = true) {
280281
* @author Patrick Cool <[email protected]>, Ghent University, Belgium
281282
* @version januari 2009, dokeos 1.8.6
282283
*/
283-
function display_glossary($view = 'table') {
284+
static function display_glossary($view = 'table') {
284285
// This function should always be called with the corresponding
285286
// parameter for view type. Meanwhile, use this cheap trick.
286287
if (empty($_SESSION['glossary_view'])) {
287288
$_SESSION['glossary_view'] = $view;
288289
}
289290
// action links
290-
echo '<div class="actions" style="margin-bottom:10px">';
291+
echo '<div class="actions">';
292+
291293
if (api_is_allowed_to_edit(null,true)) {
292294
echo '<a href="index.php?'.api_get_cidreq().'&action=addglossary&msg=add">'.Display::return_icon('new_glossary_term.png',get_lang('TermAddNew'),'','32').'</a>';
293295
}
@@ -296,6 +298,9 @@ function display_glossary($view = 'table') {
296298
if (api_is_allowed_to_edit(null,true)) {
297299
echo '<a href="index.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png',get_lang('ImportGlossary'),'','32').'</a>';
298300
}
301+
302+
echo '<a href="index.php?'.api_get_cidreq().'&action=export_to_pdf">'.Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>';
303+
299304
if ((isset($_SESSION['glossary_view']) && $_SESSION['glossary_view'] == 'table') or (!isset($_SESSION['glossary_view']))){
300305
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=list">'.Display::return_icon('view_detailed.png',get_lang('ListView'),'','32').'</a>';
301306
} else {
@@ -344,7 +349,7 @@ function display_glossary_list() {
344349
* @author Patrick Cool <[email protected]>, Ghent University, Belgium
345350
* @version januari 2009, dokeos 1.8.6
346351
*/
347-
function get_number_glossary_terms($session_id=0) {
352+
static function get_number_glossary_terms($session_id=0) {
348353
// Database table definition
349354
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
350355
$course_id = api_get_course_int_id();
@@ -371,7 +376,7 @@ function get_number_glossary_terms($session_id=0) {
371376
* @author Julio Montoya fixing this function, adding intvals
372377
* @version januari 2009, dokeos 1.8.6
373378
*/
374-
function get_glossary_data($from, $number_of_items, $column, $direction) {
379+
static function get_glossary_data($from, $number_of_items, $column, $direction) {
375380
global $_user;
376381
// Database table definition
377382
$t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
@@ -445,7 +450,7 @@ function get_glossary_data($from, $number_of_items, $column, $direction) {
445450
* @author Patrick Cool <[email protected]>, Ghent University, Belgium
446451
* @version januari 2009, dokeos 1.8.6
447452
*/
448-
function actions_filter($glossary_id, $url_params, $row) {
453+
static function actions_filter($glossary_id, $url_params, $row) {
449454
$glossary_id = $row[2];
450455
$return = '<a href="'.api_get_self().'?action=edit_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
451456
$glossary_data = GlossaryManager::get_glossary_information($glossary_id);
@@ -471,7 +476,7 @@ function actions_filter($glossary_id, $url_params, $row) {
471476
* @author Patrick Cool <[email protected]>, Ghent University, Belgium
472477
* @version januari 2009, dokeos 1.8.6
473478
*/
474-
function javascript_glossary() {
479+
static function javascript_glossary() {
475480
return "<script type=\"text/javascript\">
476481
function confirmation (name) {
477482
if (confirm(\" ". get_lang("TermConfirmDelete") ." \"+ name + \" ?\"))
@@ -547,4 +552,26 @@ function move_glossary($direction, $glossary_id, $message = true) {
547552
if ($message)
548553
Display::display_confirmation_message(get_lang('TermMoved'));
549554
}
555+
556+
static function export_to_pdf() {
557+
$data = GlossaryManager::get_glossary_data(0, GlossaryManager::get_number_glossary_terms(api_get_session_id()), 0, 'ASC');
558+
$html = '<html><body>';
559+
$html .= '<h2>'.get_lang('Glossary').'</h2><hr><br><br>';
560+
foreach ($data as $item) {
561+
$term = $item[0];
562+
$description = $item[1];
563+
$html .= '<h4>'.$term.'</h4><p>'.$description.'<p><hr>';
564+
}
565+
$html .= '</body></html>';
566+
$course_code = api_get_course_id();
567+
$pdf = new PDF();
568+
//$pdf->set_custom_header($title);
569+
/*$css_file = api_get_path(SYS_CODE_PATH).'css/print.css';
570+
if (file_exists($css_file)) {
571+
$css = @file_get_contents($css_file);
572+
} else {
573+
$css = '';
574+
}*/
575+
$pdf->content_to_pdf($html, $css, get_lang('Glossary').'_'.$course_code, $course_code);
576+
}
550577
}

main/inc/lib/pdf.lib.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public function html_to_pdf($html_file_array, $pdf_name = '', $course_code = nul
199199

200200
/**
201201
* Converts an html string to PDF
202-
* @param string valid html
202+
* @param string valid html
203+
* @param string CSS content of a CSS file
203204
* @param string pdf name
204205
* @param string course code (if you are using html that are located in the document tool you must provide this)
205206
* @return string Web path

0 commit comments

Comments
 (0)