Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

pull/2458/head
jmontoyaa 8 years ago
commit 61df9eacb7
  1. 2
      plugin/test2pdf/install.php
  2. 1
      plugin/test2pdf/lang/english.php
  3. 551
      plugin/test2pdf/src/download-pdf.php
  4. 1
      plugin/test2pdf/src/index.test2pdf.php
  5. 219
      plugin/test2pdf/src/test2pdf.lib.php
  6. 22
      plugin/test2pdf/src/test2pdf_plugin.class.php
  7. 32
      plugin/test2pdf/src/view-pdf.php
  8. 10
      plugin/test2pdf/start.php

@ -10,6 +10,6 @@
*/ */
require_once dirname(__FILE__) . '/config.php'; require_once dirname(__FILE__) . '/config.php';
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
die ('You must have admin permissions to install plugins'); die('You must have admin permissions to install plugins');
} }
Test2pdfPlugin::create()->install(); Test2pdfPlugin::create()->install();

@ -13,4 +13,3 @@ $strings['PluginDisabledFromAdminPanel'] = "The plugin has been disabled from th
$strings['AnswersColumn'] = "Answers: "; $strings['AnswersColumn'] = "Answers: ";
$strings['Statement']= "Statement"; $strings['Statement']= "Statement";
$strings['PageX']= "Page %s"; $strings['PageX']= "Page %s";

@ -13,8 +13,8 @@ require_once 'test2pdf_plugin.class.php';
$test2pdfPlugin = Test2pdfPlugin::create(); $test2pdfPlugin = Test2pdfPlugin::create();
$enable = $test2pdfPlugin->get('enable_plugin'); $enable = $test2pdfPlugin->get('enable_plugin');
if($enable != "true"){ if ($enable != "true") {
header('Location: ../../../index.php'); header('Location: ../../../index.php');
} }
require('../class/fpdf.php'); require('../class/fpdf.php');
@ -26,214 +26,216 @@ $id_quiz = (int) $_GET['id_quiz'];
class PDF extends FPDF class PDF extends FPDF
{ {
function Header() public function Header()
{ {
global $title_course; global $title_course;
global $title_quiz; global $title_quiz;
$logo = '../resources/img/logo.png'; $logo = '../resources/img/logo.png';
$this->Image($logo,10,0); $this->Image($logo, 10, 0);
// Title // Title
$this->SetFont('Courier','I',14); $this->SetFont('Courier', 'I', 14);
$this->Cell(0,5,$title_course,0,1,'R'); $this->Cell(0, 5, $title_course, 0, 1, 'R');
$this->SetFont('Helvetica','I',14); $this->SetFont('Helvetica', 'I', 14);
$this->Cell(0,5,$title_quiz,0,1,'R'); $this->Cell(0, 5, $title_quiz, 0, 1, 'R');
// Line break // Line break
$this->SetLineWidth(0.5); $this->SetLineWidth(0.5);
$this->SetDrawColor(60,120,255); $this->SetDrawColor(60, 120, 255);
$this->Line(10, 24, 200, 24); $this->Line(10, 24, 200, 24);
$this->SetLineWidth(0.4); $this->SetLineWidth(0.4);
$this->SetDrawColor(200); $this->SetDrawColor(200);
$this->Line(11, 24.5, 199, 24.5); $this->Line(11, 24.5, 199, 24.5);
$this->Ln(10); $this->Ln(10);
} }
function Footer() public function Footer()
{ {
global $test2pdfPlugin; global $test2pdfPlugin;
// Position at 1.5 cm from bottom // Position at 1.5 cm from bottom
$this->SetY(-15); $this->SetY(-15);
$y = $this->GetY(); $y = $this->GetY();
// Line break // Line break
$this->SetLineWidth(0.5); $this->SetLineWidth(0.5);
$this->SetDrawColor(60,120,255); $this->SetDrawColor(60, 120, 255);
$this->Line(10, $y, 200, $y); $this->Line(10, $y, 200, $y);
$this->SetLineWidth(0.4); $this->SetLineWidth(0.4);
$this->SetDrawColor(200); $this->SetDrawColor(200);
$this->Line(11, $y+0.5, 199, $y+0.5); $this->Line(11, $y+0.5, 199, $y+0.5);
// Arial italic 8 // Arial italic 8
$this->SetFont('Arial','I',8); $this->SetFont('Arial', 'I', 8);
// Text color in gray // Text color in gray
$this->SetTextColor(128); $this->SetTextColor(128);
// Page number // Page number
$this->Cell(0,10,utf8_decode(sprintf($test2pdfPlugin->get_lang('PageX'), $this->PageNo())),0,0,'C'); $this->Cell(0, 10, utf8_decode(sprintf($test2pdfPlugin->get_lang('PageX'), $this->PageNo())), 0, 0, 'C');
$this->Cell(0,10,date('Y'),0,0,'R'); $this->Cell(0, 10, date('Y'), 0, 0, 'R');
} }
var $B; public $B;
var $I; public $I;
var $U; public $U;
var $HREF; public $HREF;
var $fontList; public $fontList;
var $issetfont; public $issetfont;
var $issetcolor; public $issetcolor;
function PDF($orientation='P', $unit='mm', $format='A4') public function PDF($orientation='P', $unit='mm', $format='A4')
{ {
//Call parent constructor //Call parent constructor
$this->__construct($orientation,$unit,$format); $this->__construct($orientation, $unit, $format);
//Initialization //Initialization
$this->B=0; $this->B=0;
$this->I=0; $this->I=0;
$this->U=0; $this->U=0;
$this->HREF=''; $this->HREF='';
$this->fontlist=array('arial', 'times', 'courier', 'helvetica', 'symbol'); $this->fontlist=['arial', 'times', 'courier', 'helvetica', 'symbol'];
$this->issetfont=false; $this->issetfont=false;
$this->issetcolor=false; $this->issetcolor=false;
} }
function WriteHTML($html) public function WriteHTML($html)
{ {
//HTML parser //HTML parser
$html=strip_tags($html,"<b><u><i><a><img><p><br><strong><em><font><tr><blockquote><style>"); //supprime tous les tags sauf ceux reconnus $html=strip_tags($html, "<b><u><i><a><img><p><br><strong><em><font><tr><blockquote><style>"); //supprime tous les tags sauf ceux reconnus
$html=str_replace("\n",' ',$html); //remplace retour à la ligne par un espace $html=str_replace("\n", ' ', $html); //remplace retour à la ligne par un espace
$a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE); //éclate la chaîne avec les balises $a=preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE); //éclate la chaîne avec les balises
foreach($a as $i=>$e) foreach ($a as $i=>$e) {
{ if ($i%2==0) {
if($i%2==0) //Text
{ if ($this->HREF) {
//Text $this->PutLink($this->HREF, $e);
if($this->HREF) } else {
$this->PutLink($this->HREF,$e); $this->Write(5, stripslashes(txtentities($e)));
else }
$this->Write(5,stripslashes(txtentities($e))); } else {
} //Tag
else if ($e[0]=='/') {
{ $this->CloseTag(strtoupper(substr($e, 1)));
//Tag } else {
if($e[0]=='/') //Extract attributes
$this->CloseTag(strtoupper(substr($e,1))); $a2=explode(' ', $e);
else $tag=strtoupper(array_shift($a2));
{ $attr=[];
//Extract attributes foreach ($a2 as $v) {
$a2=explode(' ',$e); if (preg_match('/([^=]*)=["\']?([^"\']*)/', $v, $a3)) {
$tag=strtoupper(array_shift($a2)); $attr[strtoupper($a3[1])]=$a3[2];
$attr=array(); }
foreach($a2 as $v) }
{ $this->OpenTag($tag, $attr);
if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3)) }
$attr[strtoupper($a3[1])]=$a3[2]; }
} }
$this->OpenTag($tag,$attr); }
}
}
}
}
function OpenTag($tag, $attr) public function OpenTag($tag, $attr)
{ {
//Opening tag //Opening tag
switch($tag){ switch ($tag) {
case 'STRONG': case 'STRONG':
$this->SetStyle('B',true); $this->SetStyle('B', true);
break; break;
case 'EM': case 'EM':
$this->SetStyle('I',true); $this->SetStyle('I', true);
break; break;
case 'B': case 'B':
case 'I': case 'I':
case 'U': case 'U':
$this->SetStyle($tag,true); $this->SetStyle($tag, true);
break; break;
case 'A': case 'A':
$this->HREF=$attr['HREF']; $this->HREF=$attr['HREF'];
break; break;
case 'IMG': case 'IMG':
if(isset($attr['SRC']) && (isset($attr['WIDTH']) || isset($attr['HEIGHT']))) { if (isset($attr['SRC']) && (isset($attr['WIDTH']) || isset($attr['HEIGHT']))) {
if(!isset($attr['WIDTH'])) if (!isset($attr['WIDTH'])) {
$attr['WIDTH'] = 0; $attr['WIDTH'] = 0;
if(!isset($attr['HEIGHT'])) }
$attr['HEIGHT'] = 0; if (!isset($attr['HEIGHT'])) {
$this->Image($attr['SRC'], $this->GetX(), $this->GetY(), px2mm($attr['WIDTH']), px2mm($attr['HEIGHT'])); $attr['HEIGHT'] = 0;
} }
break; $this->Image($attr['SRC'], $this->GetX(), $this->GetY(), px2mm($attr['WIDTH']), px2mm($attr['HEIGHT']));
case 'TR': }
case 'BLOCKQUOTE': break;
case 'BR': case 'TR':
$this->Ln(5); case 'BLOCKQUOTE':
break; case 'BR':
case 'P': $this->Ln(5);
$this->Ln(10); break;
break; case 'P':
case 'FONT': $this->Ln(10);
if (isset($attr['COLOR']) && $attr['COLOR']!='') { break;
$coul=hex2dec($attr['COLOR']); case 'FONT':
$this->SetTextColor($coul['R'],$coul['V'],$coul['B']); if (isset($attr['COLOR']) && $attr['COLOR']!='') {
$this->issetcolor=true; $coul=hex2dec($attr['COLOR']);
} $this->SetTextColor($coul['R'], $coul['V'], $coul['B']);
if (isset($attr['FACE']) && in_array(strtolower($attr['FACE']), $this->fontlist)) { $this->issetcolor=true;
$this->SetFont(strtolower($attr['FACE'])); }
$this->issetfont=true; if (isset($attr['FACE']) && in_array(strtolower($attr['FACE']), $this->fontlist)) {
} $this->SetFont(strtolower($attr['FACE']));
break; $this->issetfont=true;
} }
} break;
}
}
function CloseTag($tag) public function CloseTag($tag)
{ {
//Closing tag //Closing tag
if($tag=='STRONG') if ($tag=='STRONG') {
$tag='B'; $tag='B';
if($tag=='EM') }
$tag='I'; if ($tag=='EM') {
if($tag=='B' || $tag=='I' || $tag=='U') $tag='I';
$this->SetStyle($tag,false); }
if($tag=='A') if ($tag=='B' || $tag=='I' || $tag=='U') {
$this->HREF=''; $this->SetStyle($tag, false);
if($tag=='FONT'){ }
if ($this->issetcolor==true) { if ($tag=='A') {
$this->SetTextColor(0); $this->HREF='';
} }
if ($this->issetfont) { if ($tag=='FONT') {
$this->SetFont('arial'); if ($this->issetcolor==true) {
$this->issetfont=false; $this->SetTextColor(0);
} }
} if ($this->issetfont) {
} $this->SetFont('arial');
$this->issetfont=false;
}
}
}
function SetStyle($tag, $enable) public function SetStyle($tag, $enable)
{ {
//Modify style and select corresponding font //Modify style and select corresponding font
$this->$tag+=($enable ? 1 : -1); $this->$tag+=($enable ? 1 : -1);
$style=''; $style='';
foreach(array('B','I','U') as $s) foreach (['B','I','U'] as $s) {
{ if ($this->$s>0) {
if($this->$s>0) $style.=$s;
$style.=$s; }
} }
$this->SetFont('',$style); $this->SetFont('', $style);
} }
function PutLink($URL, $txt) public function PutLink($URL, $txt)
{ {
//Put a hyperlink //Put a hyperlink
$this->SetTextColor(0,0,255); $this->SetTextColor(0, 0, 255);
$this->SetStyle('U',true); $this->SetStyle('U', true);
$this->Write(5,$txt,$URL); $this->Write(5, $txt, $URL);
$this->SetStyle('U',false); $this->SetStyle('U', false);
$this->SetTextColor(0); $this->SetTextColor(0);
} }
} }
//Obtener nombre del curso y nombre del ejercicio //Obtener nombre del curso y nombre del ejercicio
//$info_course = CourseManager::get_course_information_by_id($course_id); //$info_course = CourseManager::get_course_information_by_id($course_id);
$info_course = api_get_course_info_by_id($course_id); $info_course = api_get_course_info_by_id($course_id);
$info_quiz = getInfoQuiz($course_id,$id_quiz); $info_quiz = getInfoQuiz($course_id, $id_quiz);
$title_course = utf8_decode(removeHtml($info_course['title'])); $title_course = utf8_decode(removeHtml($info_course['title']));
$title_quiz = utf8_decode(removeHtml($info_quiz['title'])); $title_quiz = utf8_decode(removeHtml($info_quiz['title']));
@ -246,96 +248,95 @@ $array_question_id = getQuestions($course_id, $id_quiz);
// Go through all questions and get the answers // Go through all questions and get the answers
if ($_GET['type'] == 'question' || $_GET['type'] == 'all') { if ($_GET['type'] == 'question' || $_GET['type'] == 'all') {
$j = 1; $j = 1;
foreach ($array_question_id as $key => $value) { foreach ($array_question_id as $key => $value) {
$InfoQuestion = getInfoQuestion($course_id, $value); $InfoQuestion = getInfoQuestion($course_id, $value);
if ($pdf->GetY() > 240) { if ($pdf->GetY() > 240) {
$pdf->AddPage(); $pdf->AddPage();
} }
$pdf->SetFont('Arial','',12); $pdf->SetFont('Arial', '', 12);
$pdf->SetTextColor(64); $pdf->SetTextColor(64);
if (trim($InfoQuestion['description'])!='') { if (trim($InfoQuestion['description'])!='') {
$j = 0; $j = 0;
$pdf->WriteHTML(utf8_decode(removeQuotes($InfoQuestion['description']))); $pdf->WriteHTML(utf8_decode(removeQuotes($InfoQuestion['description'])));
$pdf->Ln(); $pdf->Ln();
} else {
$pdf->MultiCell(0, 7, ($key+$j).' - '.utf8_decode($InfoQuestion['question']), 0, 'L', false);
}
/*
} else { if($InfoQuestion['question'] == "Enunciado"){
$pdf->MultiCell(0,7,($key+$j).' - '.utf8_decode($InfoQuestion['question']),0,'L',false); $j = 0;
} $pdf->MultiCell(0,7,utf8_decode($InfoQuestion['question']),0,'L',false);
/* if(trim($InfoQuestion['description'])!=''){
$pdf->WriteHTML(utf8_decode(quitar_acentos($InfoQuestion['description'])));
if($InfoQuestion['question'] == "Enunciado"){ $pdf->Ln();
$j = 0; }
$pdf->MultiCell(0,7,utf8_decode($InfoQuestion['question']),0,'L',false); }else{
if(trim($InfoQuestion['description'])!=''){ $pdf->MultiCell(0,7,($key+$j).' - '.utf8_decode($InfoQuestion['question']),0,'L',false);
$pdf->WriteHTML(utf8_decode(quitar_acentos($InfoQuestion['description']))); }*/
$pdf->Ln(); $InfoAnswer = getAnswers($course_id, $value);
} foreach ($InfoAnswer as $key2 => $value2) {
}else{ $pdf->SetFont('Arial', 'I', 10);
$pdf->MultiCell(0,7,($key+$j).' - '.utf8_decode($InfoQuestion['question']),0,'L',false); $pdf->SetTextColor(96);
}*/ $pdf->Cell(1, 7, '', 0, 0);
$InfoAnswer = getAnswers($course_id, $value); $pdf->Rect($pdf->GetX()+2, $pdf->GetY(), 4, 4);
foreach ($InfoAnswer as $key2 => $value2) { $pdf->Cell(7, 7, '', 0, 0);
$pdf->SetFont('Arial','I',10); $pdf->MultiCell(0, 5, $letters[$key2].' - '.utf8_decode(removeHtml($value2['answer'])), 0, 'L', false);
$pdf->SetTextColor(96); $pdf->Ln(1);
$pdf->Cell(1,7,'',0,0); }
$pdf->Rect($pdf->GetX()+2,$pdf->GetY(),4,4); $pdf->Ln(4);
$pdf->Cell(7,7,'',0,0); }
$pdf->MultiCell(0,5,$letters[$key2].' - '.utf8_decode(removeHtml($value2['answer'])),0,'L',false);
$pdf->Ln(1);
}
$pdf->Ln(4);
}
} }
$j=1; $j=1;
if ($_GET['type'] == 'answer' || $_GET['type'] == 'all') { if ($_GET['type'] == 'answer' || $_GET['type'] == 'all') {
$array_resp = array(); $array_resp = [];
foreach ($array_question_id as $key => $value) { foreach ($array_question_id as $key => $value) {
$InfoQuestion = getInfoQuestion($course_id,$value); $InfoQuestion = getInfoQuestion($course_id, $value);
if ($InfoQuestion['question'] == $test2pdfPlugin->get_lang('Statement')) { if ($InfoQuestion['question'] == $test2pdfPlugin->get_lang('Statement')) {
$j = 0; $j = 0;
} else { } else {
$respuestas = ''; $respuestas = '';
$InfoQuestion = getInfoQuestion($course_id,$value); $InfoQuestion = getInfoQuestion($course_id, $value);
if ($InfoQuestion['type']==2 || $InfoQuestion['type']==9 || $InfoQuestion['type']==11 || $InfoQuestion['type']==12 || $InfoQuestion['type']==14) { if ($InfoQuestion['type']==2 || $InfoQuestion['type']==9 || $InfoQuestion['type']==11 || $InfoQuestion['type']==12 || $InfoQuestion['type']==14) {
$InfoAnswer = getAnswers($course_id,$value); $InfoAnswer = getAnswers($course_id, $value);
$respuestas .= ' '.($key+$j).' -'; $respuestas .= ' '.($key+$j).' -';
foreach ($InfoAnswer as $key2 => $value2) { foreach ($InfoAnswer as $key2 => $value2) {
if ($value2['correct'] == 1) { if ($value2['correct'] == 1) {
$respuestas .= ' '.$letters[$key2].','; $respuestas .= ' '.$letters[$key2].',';
} }
} }
$i = strrpos($respuestas,','); $i = strrpos($respuestas, ',');
$respuestas = substr($respuestas,0,$i); $respuestas = substr($respuestas, 0, $i);
$respuestas .= ' '; $respuestas .= ' ';
$array_resp[] = $respuestas; $array_resp[] = $respuestas;
} else { } else {
$InfoAnswer = getAnswers($course_id,$value); $InfoAnswer = getAnswers($course_id, $value);
foreach ($InfoAnswer as $key2 => $value2) { foreach ($InfoAnswer as $key2 => $value2) {
if ($value2['correct'] == 1) { if ($value2['correct'] == 1) {
$respuestas .= ' '.($key+$j).' - '.$letters[$key2].' '; $respuestas .= ' '.($key+$j).' - '.$letters[$key2].' ';
break; break;
} }
} }
$array_resp[] = $respuestas; $array_resp[] = $respuestas;
} }
} }
} }
$pdf->SetFont('Arial','',12); $pdf->SetFont('Arial', '', 12);
$pdf->SetTextColor(64); $pdf->SetTextColor(64);
$pdf->Cell(0, 7, utf8_decode($test2pdfPlugin->get_lang('AnswersColumn')), 0, 1, 'L', false); $pdf->Cell(0, 7, utf8_decode($test2pdfPlugin->get_lang('AnswersColumn')), 0, 1, 'L', false);
$pdf->SetFont('Arial', 'I', 10); $pdf->SetFont('Arial', 'I', 10);
$pdf->SetTextColor(64, 64, 255); $pdf->SetTextColor(64, 64, 255);
$i = 1; $i = 1;
foreach ($array_resp as $resp) { foreach ($array_resp as $resp) {
$pdf->Cell(50, 6, $resp, 0); $pdf->Cell(50, 6, $resp, 0);
if($i%4 == 0){ if ($i%4 == 0) {
$pdf->Ln(); $pdf->Ln();
} }
$i++; $i++;
} }
} }
$pdf->Output(); $pdf->Output();

@ -4,4 +4,3 @@
* Index of the Test to pdf plugin courses list * Index of the Test to pdf plugin courses list
* @package chamilo.plugin.test2pdf * @package chamilo.plugin.test2pdf
*/ */

@ -11,7 +11,7 @@ require_once '../../../main/inc/global.inc.php';
require_once '../config.php'; require_once '../config.php';
require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php'; require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php';
$letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); $letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
/** /**
* List exercises * List exercises
@ -25,7 +25,7 @@ function showExerciseCourse($course_id, $session_id = 0)
$course_id = (int) $course_id; $course_id = (int) $course_id;
$session_id = (int) $session_id; $session_id = (int) $session_id;
$tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST); $tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
$tableLpItem = Database::get_course_table(TABLE_LP_ITEM); $tableLpItem = Database::get_course_table(TABLE_LP_ITEM);
$sql = "SELECT a.* $sql = "SELECT a.*
FROM $tableQuiz a FROM $tableQuiz a
LEFT JOIN $tableLpItem b LEFT JOIN $tableLpItem b
@ -35,10 +35,10 @@ function showExerciseCourse($course_id, $session_id = 0)
AND (a.active = 1 OR (item_type = 'quiz' AND b.c_id = $course_id)) AND (a.active = 1 OR (item_type = 'quiz' AND b.c_id = $course_id))
ORDER BY a.title ASC;"; ORDER BY a.title ASC;";
$res = Database::query($sql); $res = Database::query($sql);
if (!$res) { if (!$res) {
die("Error Database $tableQuiz"); die("Error Database $tableQuiz");
} }
$aux = array(); $aux = [];
while ($row = Database::fetch_assoc($res)) { while ($row = Database::fetch_assoc($res)) {
$aux[] = $row; $aux[] = $row;
} }
@ -54,12 +54,12 @@ function getInfoQuiz($c_id, $id)
{ {
$c_id = (int) $c_id; $c_id = (int) $c_id;
$id = (int) $id; $id = (int) $id;
$tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST); $tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "SELECT * FROM $tableQuiz WHERE c_id = $c_id AND iid = $id"; $sql = "SELECT * FROM $tableQuiz WHERE c_id = $c_id AND iid = $id";
$res = Database::query($sql); $res = Database::query($sql);
if (!$res) { if (!$res) {
die("Error Database $tableQuiz"); die("Error Database $tableQuiz");
} }
$row = Database::fetch_assoc($res); $row = Database::fetch_assoc($res);
return $row; return $row;
} }
@ -73,23 +73,23 @@ function getQuestions($c_id, $quizId)
{ {
$c_id = (int) $c_id; $c_id = (int) $c_id;
$quizId = (int) $quizId; $quizId = (int) $quizId;
$tableQuizQuestion = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $tableQuizQuestion = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION); $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT a.question_id AS question_id $sql = "SELECT a.question_id AS question_id
FROM $tableQuizQuestion a FROM $tableQuizQuestion a
INNER JOIN $tableQuestion b ON a.question_id = b.iid INNER JOIN $tableQuestion b ON a.question_id = b.iid
WHERE a.c_id = $c_id AND b.c_id = a.c_id AND a.exercice_id = $quizId WHERE a.c_id = $c_id AND b.c_id = a.c_id AND a.exercice_id = $quizId
AND (b.type IN (1, 2, 9, 10, 11, 12, 14)) AND (b.type IN (1, 2, 9, 10, 11, 12, 14))
ORDER BY question_order ASC;"; ORDER BY question_order ASC;";
$res = Database::query($sql); $res = Database::query($sql);
if (!$res) { if (!$res) {
die("Error Database $tableQuizQuestion"); die("Error Database $tableQuizQuestion");
} }
$aux = array(); $aux = [];
while ($row = Database::fetch_assoc($res)) { while ($row = Database::fetch_assoc($res)) {
$aux[] = $row['question_id']; $aux[] = $row['question_id'];
} }
return $aux; return $aux;
} }
/** /**
@ -101,15 +101,15 @@ function getInfoQuestion($c_id, $id)
{ {
$c_id = (int) $c_id; $c_id = (int) $c_id;
$id = (int) $id; $id = (int) $id;
$tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION); $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT * FROM $tableQuestion $sql = "SELECT * FROM $tableQuestion
WHERE c_id = $c_id WHERE c_id = $c_id
AND iid = $id AND iid = $id
AND (type IN (1, 2, 9, 10, 11, 12, 14))"; AND (type IN (1, 2, 9, 10, 11, 12, 14))";
$res = Database::query($sql); $res = Database::query($sql);
if (!$res) { if (!$res) {
die("Error Database $tableQuestion"); die("Error Database $tableQuestion");
} }
$row = Database::fetch_assoc($res); $row = Database::fetch_assoc($res);
return $row; return $row;
} }
@ -123,19 +123,19 @@ function getAnswers($c_id, $id)
{ {
$c_id = (int) $c_id; $c_id = (int) $c_id;
$id = (int) $id; $id = (int) $id;
$tableQuizAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER); $tableQuizAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql = "SELECT * FROM $tableQuizAnswer $sql = "SELECT * FROM $tableQuizAnswer
WHERE c_id = $c_id AND question_id = $id WHERE c_id = $c_id AND question_id = $id
ORDER BY position ASC;"; ORDER BY position ASC;";
$res = Database::query($sql); $res = Database::query($sql);
if (!$res) { if (!$res) {
die("Error Database $tableQuizAnswer"); die("Error Database $tableQuizAnswer");
} }
$aux = array(); $aux = [];
while ($row = Database::fetch_assoc($res)) { while ($row = Database::fetch_assoc($res)) {
$aux[] = $row; $aux[] = $row;
} }
return $aux; return $aux;
} }
/** /**
@ -145,49 +145,49 @@ function getAnswers($c_id, $id)
*/ */
function removeHtml($string) function removeHtml($string)
{ {
$txt=str_replace("<html>","",$string); $txt=str_replace("<html>", "", $string);
$txt=str_replace("<head>","",$txt); $txt=str_replace("<head>", "", $txt);
$txt=str_replace("<title>","",$txt); $txt=str_replace("<title>", "", $txt);
$txt=str_replace("</title>","",$txt); $txt=str_replace("</title>", "", $txt);
$txt=str_replace("</head>","",$txt); $txt=str_replace("</head>", "", $txt);
$txt=str_replace("<body>","",$txt); $txt=str_replace("<body>", "", $txt);
$txt=str_replace("</body>","",$txt); $txt=str_replace("</body>", "", $txt);
$txt=str_replace("</html>","",$txt); $txt=str_replace("</html>", "", $txt);
$txt=strip_tags($txt); $txt=strip_tags($txt);
$txt=str_replace(chr(13).chr(10),"",$txt); $txt=str_replace(chr(13).chr(10), "", $txt);
/* /*
$txt=str_replace("&nbsp;"," ",$txt); $txt=str_replace("&nbsp;"," ",$txt);
$txt=str_replace("&Aacute;","Á",$txt); $txt=str_replace("&Aacute;","Á",$txt);
$txt=str_replace("&aacute;","á",$txt); $txt=str_replace("&aacute;","á",$txt);
$txt=str_replace("&Eacute;","É",$txt); $txt=str_replace("&Eacute;","É",$txt);
$txt=str_replace("&eacute;","é",$txt); $txt=str_replace("&eacute;","é",$txt);
$txt=str_replace("&Iacute;","Í",$txt); $txt=str_replace("&Iacute;","Í",$txt);
$txt=str_replace("&iacute;","í",$txt); $txt=str_replace("&iacute;","í",$txt);
$txt=str_replace("&Oacute;","Ó",$txt); $txt=str_replace("&Oacute;","Ó",$txt);
$txt=str_replace("&oacute;","ó",$txt); $txt=str_replace("&oacute;","ó",$txt);
$txt=str_replace("&Uacute;","Ú",$txt); $txt=str_replace("&Uacute;","Ú",$txt);
$txt=str_replace("&uacute;","ú",$txt); $txt=str_replace("&uacute;","ú",$txt);
$txt=str_replace("&Ntilde;","Ñ",$txt); $txt=str_replace("&Ntilde;","Ñ",$txt);
$txt=str_replace("&ntilde;","ñ",$txt); $txt=str_replace("&ntilde;","ñ",$txt);
$txt=str_replace("&agrave;","à",$txt); $txt=str_replace("&agrave;","à",$txt);
$txt=str_replace("&Agrave;","À",$txt); $txt=str_replace("&Agrave;","À",$txt);
$txt=str_replace("&iexcl;","¡",$txt); $txt=str_replace("&iexcl;","¡",$txt);
$txt=str_replace("&middot;","·",$txt); $txt=str_replace("&middot;","·",$txt);
$txt=str_replace("&Ccedil;","Ç",$txt); $txt=str_replace("&Ccedil;","Ç",$txt);
$txt=str_replace("&ccedil;","ç",$txt); $txt=str_replace("&ccedil;","ç",$txt);
$txt=str_replace("&quot;",'"',$txt); $txt=str_replace("&quot;",'"',$txt);
$txt=str_replace("&ordf;",'ª',$txt); $txt=str_replace("&ordf;",'ª',$txt);
$txt=str_replace("&ordm;",'º',$txt); $txt=str_replace("&ordm;",'º',$txt);
$txt=str_replace("&amp;",'&',$txt); $txt=str_replace("&amp;",'&',$txt);
$txt=str_replace("&bull;",'•',$txt); $txt=str_replace("&bull;",'•',$txt);
$txt=str_replace("&iquest;",'¿',$txt); $txt=str_replace("&iquest;",'¿',$txt);
$txt=str_replace("&euro;",'EUR',$txt); $txt=str_replace("&euro;",'EUR',$txt);
$txt=str_replace("&uuml;",'ü',$txt); $txt=str_replace("&uuml;",'ü',$txt);
$txt=str_replace("&Uuml;",'Ü',$txt); $txt=str_replace("&Uuml;",'Ü',$txt);
$txt=str_replace("&uml;",'¨',$txt);*/ $txt=str_replace("&uml;",'¨',$txt);*/
return $txt; return $txt;
} }
/** /**
@ -197,37 +197,37 @@ function removeHtml($string)
*/ */
function removeQuotes($string) function removeQuotes($string)
{ {
//$txt=strip_tags($cadena); //$txt=strip_tags($cadena);
$txt=str_replace("&nbsp;"," ",$string); $txt=str_replace("&nbsp;", " ", $string);
$txt=str_replace("&Aacute;","Á",$txt); $txt=str_replace("&Aacute;", "Á", $txt);
$txt=str_replace("&aacute;","á",$txt); $txt=str_replace("&aacute;", "á", $txt);
$txt=str_replace("&Eacute;","É",$txt); $txt=str_replace("&Eacute;", "É", $txt);
$txt=str_replace("&eacute;","é",$txt); $txt=str_replace("&eacute;", "é", $txt);
$txt=str_replace("&Iacute;","Í",$txt); $txt=str_replace("&Iacute;", "Í", $txt);
$txt=str_replace("&iacute;","í",$txt); $txt=str_replace("&iacute;", "í", $txt);
$txt=str_replace("&Oacute;","Ó",$txt); $txt=str_replace("&Oacute;", "Ó", $txt);
$txt=str_replace("&oacute;","ó",$txt); $txt=str_replace("&oacute;", "ó", $txt);
$txt=str_replace("&Uacute;","Ú",$txt); $txt=str_replace("&Uacute;", "Ú", $txt);
$txt=str_replace("&uacute;","ú",$txt); $txt=str_replace("&uacute;", "ú", $txt);
$txt=str_replace("&Ntilde;","Ñ",$txt); $txt=str_replace("&Ntilde;", "Ñ", $txt);
$txt=str_replace("&ntilde;","ñ",$txt); $txt=str_replace("&ntilde;", "ñ", $txt);
$txt=str_replace("&quot;",'"',$txt); $txt=str_replace("&quot;", '"', $txt);
$txt=str_replace("&ordf;",'ª',$txt); $txt=str_replace("&ordf;", 'ª', $txt);
$txt=str_replace("&ordm;",'º',$txt); $txt=str_replace("&ordm;", 'º', $txt);
$txt=str_replace("&amp;",'&',$txt); $txt=str_replace("&amp;", '&', $txt);
$txt=str_replace("&bull;",'•',$txt); $txt=str_replace("&bull;", '•', $txt);
$txt=str_replace("&iquest; &",'¿',$txt); $txt=str_replace("&iquest; &", '¿', $txt);
$txt=str_replace("&agrave;","à",$txt); $txt=str_replace("&agrave;", "à", $txt);
$txt=str_replace("&Agrave;","À",$txt); $txt=str_replace("&Agrave;", "À", $txt);
$txt=str_replace("&iexcl;","¡",$txt); $txt=str_replace("&iexcl;", "¡", $txt);
$txt=str_replace("&middot;","·",$txt); $txt=str_replace("&middot;", "·", $txt);
$txt=str_replace("&Ccedil;","Ç",$txt); $txt=str_replace("&Ccedil;", "Ç", $txt);
$txt=str_replace("&ccedil;","ç",$txt); $txt=str_replace("&ccedil;", "ç", $txt);
$txt=str_replace("&euro;",'EUR',$txt); $txt=str_replace("&euro;", 'EUR', $txt);
$txt=str_replace("&uuml;",'ü',$txt); $txt=str_replace("&uuml;", 'ü', $txt);
$txt=str_replace("&Uuml;",'Ü',$txt); $txt=str_replace("&Uuml;", 'Ü', $txt);
$txt=str_replace("uml;",'¨',$txt); $txt=str_replace("uml;", '¨', $txt);
return $txt; return $txt;
} }
/** /**
@ -243,7 +243,7 @@ function hex2dec($color = '#000000')
$vert = hexdec($V); $vert = hexdec($V);
$B = substr($color, 5, 2); $B = substr($color, 5, 2);
$bleu = hexdec($B); $bleu = hexdec($B);
$tbl_couleur = array(); $tbl_couleur = [];
$tbl_couleur['R'] = $rouge; $tbl_couleur['R'] = $rouge;
$tbl_couleur['V'] = $vert; $tbl_couleur['V'] = $vert;
$tbl_couleur['B'] = $bleu; $tbl_couleur['B'] = $bleu;
@ -271,4 +271,3 @@ function txtentities($html)
$trans = array_flip($trans); $trans = array_flip($trans);
return strtr($html, $trans); return strtr($html, $trans);
} }

@ -15,12 +15,12 @@
*/ */
class Test2pdfPlugin extends Plugin class Test2pdfPlugin extends Plugin
{ {
public $isCoursePlugin = true; public $isCoursePlugin = true;
/** /**
* *
* @return StaticPlugin * @return StaticPlugin
*/ */
static function create() public static function create()
{ {
static $result = null; static $result = null;
return $result ? $result : $result = new self(); return $result ? $result : $result = new self();
@ -31,18 +31,18 @@ class Test2pdfPlugin extends Plugin
parent::__construct( parent::__construct(
'1.0', '1.0',
'Jose Angel Ruiz - NoSoloRed (original author)', 'Jose Angel Ruiz - NoSoloRed (original author)',
array( [
'enable_plugin' => 'boolean' 'enable_plugin' => 'boolean'
) ]
); );
} }
/** /**
* This method creates the tables required to this plugin * This method creates the tables required to this plugin
*/ */
function install() public function install()
{ {
//Installing course settings //Installing course settings
$this->install_course_fields_in_all_courses(); $this->install_course_fields_in_all_courses();
require_once api_get_path(SYS_PLUGIN_PATH) . 'test2pdf/database.php'; require_once api_get_path(SYS_PLUGIN_PATH) . 'test2pdf/database.php';
} }
@ -50,14 +50,14 @@ class Test2pdfPlugin extends Plugin
/** /**
* This method drops the plugin tables * This method drops the plugin tables
*/ */
function uninstall() public function uninstall()
{ {
//Deleting course settings //Deleting course settings
$this->uninstall_course_fields_in_all_courses($this->course_settings); $this->uninstall_course_fields_in_all_courses($this->course_settings);
$tablesToBeDeleted = array( $tablesToBeDeleted = [
TABLE_TEST2PDF TABLE_TEST2PDF
); ];
foreach ($tablesToBeDeleted as $tableToBeDeleted) { foreach ($tablesToBeDeleted as $tableToBeDeleted) {
$table = Database::get_main_table($tableToBeDeleted); $table = Database::get_main_table($tableToBeDeleted);
$sql = "DROP TABLE IF EXISTS $tableToBeDeleted"; $sql = "DROP TABLE IF EXISTS $tableToBeDeleted";

@ -16,23 +16,23 @@ $plugin = Test2pdfPlugin::create();
$t2p_plugin = $plugin->get('enable_plugin'); $t2p_plugin = $plugin->get('enable_plugin');
if ($t2p_plugin === 'true') { if ($t2p_plugin === 'true') {
$templateName = $plugin->get_lang('ViewExercises'); $templateName = $plugin->get_lang('ViewExercises');
$tpl = new Template($templateName); $tpl = new Template($templateName);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
// Leer Datos y Mostrar tabla // Leer Datos y Mostrar tabla
$iconInfo = api_get_path(WEB_PLUGIN_PATH) . 'test2pdf/resources/img/24/info.png'; $iconInfo = api_get_path(WEB_PLUGIN_PATH) . 'test2pdf/resources/img/24/info.png';
$iconDownload = api_get_path(WEB_PLUGIN_PATH) . 'test2pdf/resources/img/32/download.png'; $iconDownload = api_get_path(WEB_PLUGIN_PATH) . 'test2pdf/resources/img/32/download.png';
$info_exercise = showExerciseCourse($course_id); $info_exercise = showExerciseCourse($course_id);
$tpl->assign('infoExercise', $info_exercise); $tpl->assign('infoExercise', $info_exercise);
$tpl->assign('course_id', $course_id); $tpl->assign('course_id', $course_id);
$tpl->assign('iconInfo',$iconInfo); $tpl->assign('iconInfo', $iconInfo);
$tpl->assign('iconDownload',$iconDownload); $tpl->assign('iconDownload', $iconDownload);
$listing_tpl = 'test2pdf/view/view-pdf.tpl'; $listing_tpl = 'test2pdf/view/view-pdf.tpl';
$content = $tpl->fetch($listing_tpl); $content = $tpl->fetch($listing_tpl);
$tpl->assign('content', $content); $tpl->assign('content', $content);
$tpl->display_one_col_template(); $tpl->display_one_col_template();
} else { } else {
header('Location: ../../../index.php'); header('Location: ../../../index.php');
} }

@ -19,9 +19,9 @@ $plugin = Test2pdfPlugin::create();
$t2p_plugin = $plugin->get('enable_plugin'); $t2p_plugin = $plugin->get('enable_plugin');
if ($t2p_plugin == "true") { if ($t2p_plugin == "true") {
$url = 'src/view-pdf.php?'.api_get_cidreq(); $url = 'src/view-pdf.php?'.api_get_cidreq();
header('Location: ' . $url); header('Location: ' . $url);
exit; exit;
}else{ } else {
echo get_lang('PluginDisabledFromAdminPanel'); echo get_lang('PluginDisabledFromAdminPanel');
} }
Loading…
Cancel
Save