diff --git a/application/libraries/admin/quexmlpdf.php b/application/libraries/admin/quexmlpdf.php index d59efd3..4832ccf 100644 --- a/application/libraries/admin/quexmlpdf.php +++ b/application/libraries/admin/quexmlpdf.php @@ -60,7 +60,7 @@ class quexmlpdf extends pdf { * @var int Defaults to 15. * @since 2010-09-02 */ - protected $cornerBorder = 13; + protected $cornerBorder = 14; /** * The length in MM of a corner line @@ -223,6 +223,12 @@ class quexmlpdf extends pdf { */ protected $skipColumnWidth = 20; + /** + * The default style for the text of the questionnaire + * + * @var string Defaults to "". + * @since 2010-09-16 + */ protected $style; /** @@ -235,7 +241,7 @@ class quexmlpdf extends pdf { * @var string Defaults to 10.5. * @since 2011-12-20 */ - protected $singleResponseHorizontalHeight = 10.5; + protected $singleResponseHorizontalHeight = 11; /** * Height of the are of each single response (includes guiding lines) @@ -302,6 +308,14 @@ class quexmlpdf extends pdf { protected $singleResponseHorizontalMax = 10; /** + * Allow single choice horizontal arrays to be split over multiple pages/columns + * + * @var array Defaults to false. + * @since 2012-08-10 + */ + protected $allowSplittingSingleChoiceHorizontal = true; + + /** * The height of an arrow * * @var array Defaults to 3. @@ -334,6 +348,14 @@ class quexmlpdf extends pdf { protected $textResponseHeight = 8; /** + * The height of a pre-filled response barcode + * + * @var bool Defaults to 6. + * @since 2012-06-22 + */ + protected $barcodeResponseHeight = 6; + + /** * The maximum number of text responses per line * * @var mixed Defaults to 24. @@ -400,8 +422,10 @@ class quexmlpdf extends pdf { * * @var mixed Defaults to 145. * @since 2010-09-20 + * @deprecated + * @see drawLongText() for the new calculation of long text box width */ - protected $longTextResponseWidth = 145; + //protected $longTextResponseWidth = 145; /** * Default number of characters to store in a long text field @@ -411,6 +435,21 @@ class quexmlpdf extends pdf { */ protected $longTextStorageWidth = 1024; + /** + * The number of columns to display the sections/questions in on each page + * + * @var int Defaults to 1. + * @since 2012-05-30 + */ + protected $columns = 1; + + /** + * The width of the border between columns + * + * @var int Defaults to 1. + * @since 2012-05-31 + */ + protected $columnBorder = 1; /** * The layout of the form for importing in to queXF @@ -469,6 +508,14 @@ class quexmlpdf extends pdf { protected $boxCP = 0; /** + * Column counter pointer (current column) + * + * @var mixed Defaults to 0. + * @since 2012-05-30 + */ + protected $columnCP = 0; + + /** * Background colour of a question * * @var bool Defaults to array(220,220,220). @@ -542,6 +589,14 @@ class quexmlpdf extends pdf { protected $vasLineWidth = 0.5; /** + * The width of a line for the default value + * + * @var double Defaults to 0.5. + * @since 2012-06-14 + */ + protected $defaultValueLineWidth = 0.5; + + /** * Height of the VAS ending lines in mm * * @var mixed Defaults to 4. @@ -767,6 +822,83 @@ class quexmlpdf extends pdf { /** + * Get the response label font sizes (normal and small) + * + * @return array containing the normal font size as the first element and small as second + * @author Adam Zammit + * @since 2013-04-10 + */ + public function getResponseLabelFontSize() + { + return array($this->responseLabelFontSize,$this->responseLabelFontSizeSmall); + } + + /** + * Set the response label font sizes + * + * @param array $sizes normal font size first then small + * + * @author Adam Zammit + * @since 2013-04-10 + */ + public function setResponseLabelFontSize($sizes) + { + $this->responseLabelFontSize = intval($sizes[0]); + $this->responseLabelFontSizeSmall = intval($sizes[1]); + } + + /** + * Get the response text font size + * + * @return int The response text font size + * @author Adam Zammit + * @since 2013-04-10 + */ + public function getResponseTextFontSize() + { + return $this->responseTextFontSize; + } + + /** + * Set the response text font size + * + * @param int $size + * + * @author Adam Zammit + * @since 2013-04-10 + */ + public function setResponseTextFontSize($size) + { + $this->responseTextFontSize = intval($size); + } + + /** + * Get the style without any HTML/etc formatting + * + * @return string The style without HTML or tabs + * @author Adam Zammit + * @since 2013-04-10 + */ + public function getStyle() + { + return strip_tags(str_replace("\t","",$this->style)); + } + + /** + * Set the CSS styling of some questionnaire elements + * + * @param string $style The CSS styling of some questionnire elements + * + * @return none + * @author Adam Zammit + * @since 2013-04-10 + */ + public function setStyle($style) + { + $this->style = ""; + } + + /** * Export the layout as an XML file * * @return string The XML layout in queXF Banding XML format @@ -904,6 +1036,9 @@ class quexmlpdf extends pdf { //set text colour $this->SetTextColor($this->textColour); + + //set column pointer + $this->columnCP = -1; } /** @@ -960,6 +1095,21 @@ class quexmlpdf extends pdf { } /** + * The X coordinate of the start of the column + * + * @return int The X coordinate of the start of the current column + * @author Adam Zammit + * @since 2012-05-30 + */ + public function getColumnX() + { + $border = 0; + if ($this->columnCP > 0) + $border = $this->columnBorder; + return $this->getMainPageX() + ($this->columnCP * ($this->getColumnWidth() + $border)) + $border; + } + + /** * The width of the writeable page * * @return int The width of the writeable page @@ -972,6 +1122,21 @@ class quexmlpdf extends pdf { } /** + * The width of the writable column + * + * @return int The width of the current column + * @author Adam Zammit + * @since 2012-05-30 + */ + public function getColumnWidth() + { + $border = 0; + if ($this->columnCP > 0) + $border = $this->columnBorder; + return ((1 / $this->columns) * $this->getMainPageWidth()) - $border; + } + + /** * Draw a horizontal response box with possible eye guides and arrows * * @param int $x The x position of the box area (top left) @@ -980,9 +1145,10 @@ class quexmlpdf extends pdf { * @param bool $downarrow Draw a down arrow? * @param bool $rightarrow Draw an arrow to the right? * @param bool $smallwidth Whether or not to use the small width + * @param bool $filled Whether or not to have the box pre-filled * */ - protected function drawHorizontalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $smallwidth = false) + protected function drawHorizontalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $smallwidth = false, $filled =false) { $this->SetDrawColor($this->lineColour[0]); $this->SetLineWidth($this->singleResponseBoxBorder); @@ -1015,6 +1181,15 @@ class quexmlpdf extends pdf { $this->SetLineStyle(array('dash' => '0')); $this->Rect($x + $linelength,$y,$this->singleResponseBoxWidth,$this->singleResponseBoxHeight,'DF',array(),$this->backgroundColourEmpty); + + if ($filled) + { + //draw a cross + $this->SetLineWidth($this->defaultValueLineWidth); + $this->Line($x + $linelength, $y, $x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); + $this->Line($x + $linelength + $this->singleResponseBoxWidth, $y, $x + $linelength, $y + $this->singleResponseBoxHeight); + } + $this->setBackground('question'); return array($x + $linelength,$y,$x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); //return the posistion for banding } @@ -1027,9 +1202,10 @@ class quexmlpdf extends pdf { * @param string $position What position the box is in for the eye guides * @param bool $downarrow Draw a down arrow? * @param bool $rightarrow Draw an arrow to the right? + * @param bool $filled Whether or not to have the box pre-filled * */ - protected function drawVerticalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false) + protected function drawVerticalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $filled = false) { $this->SetDrawColor($this->lineColour[0]); $this->SetLineWidth($this->singleResponseBoxBorder); @@ -1072,7 +1248,7 @@ class quexmlpdf extends pdf { $this->setDefaultFont($this->skipToTextFontSize,'B'); - $this->MultiCell($this->skipColumnWidth,$this->singleResponseBoxHeight,$text,0,'L',false,0,($this->getPageWidth() - $this->getMainPageX() - $this->skipColumnWidth),$y,true,0,false,true,$this->singleResponseBoxHeight,'M',true); + $this->MultiCell($this->skipColumnWidth,$this->singleResponseBoxHeight,$text,0,'L',false,0,(($this->getColumnWidth() + $this->getColumnX()) - $this->skipColumnWidth),$y,true,0,false,true,$this->singleResponseBoxHeight,'M',true); //Reset to non bold as causing problems with TCPDF HTML CSS conversion $this->setDefaultFont($this->skipToTextFontSize,''); @@ -1082,6 +1258,15 @@ class quexmlpdf extends pdf { } $this->Rect($x,$y,$this->singleResponseBoxWidth,$this->singleResponseBoxHeight,'DF',array(),$this->backgroundColourEmpty); + + if ($filled) + { + //draw a cross + $this->SetLineWidth($this->defaultValueLineWidth); + $this->Line($x, $y, $x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); + $this->Line($x + $this->singleResponseBoxWidth, $y, $x, $y + $this->singleResponseBoxHeight); + } + $this->setBackground('question'); return array($x,$y,$x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); //return the posistion for banding } @@ -1237,6 +1422,10 @@ class quexmlpdf extends pdf { $sqtmp['text'] .= $ttmp; } $sqtmp['varname'] = $sq['varName']; + + if (isset($sq['defaultValue'])) + $sqtmp['defaultvalue'] = $sq['defaultValue']; + $rstmp['subquestions'][] = $sqtmp; } @@ -1244,6 +1433,10 @@ class quexmlpdf extends pdf { { $rtmp = array(); $rstmp['varname'] = $r['varName']; + + if (isset($r['defaultValue'])) + $rstmp['defaultvalue'] = $r['defaultValue']; + if (isset($r->fixed)) { $rtmp['type'] = 'fixed'; @@ -1268,6 +1461,10 @@ class quexmlpdf extends pdf { $oarr = array(); $oarr['width'] = current($c->contingentQuestion->length); $oarr['text'] = current($c->contingentQuestion->text); + + if (isset($c->contingentQuestion['defaultValue'])) + $oarr['defaultvalue'] = $c->contingentQuestion['defaultValue']; + $oarr['varname'] = $c->contingentQuestion['varName']; $cat['other'] = $oarr; } @@ -1282,6 +1479,10 @@ class quexmlpdf extends pdf { $rtmp['type'] = 'longtext'; else if ($format == 'number' || $format == 'numeric' || $format == 'integer') $rtmp['type'] = 'number'; + else if ($format == 'i25') + $rtmp['type'] = 'i25'; + else if ($format == 'codabar') + $rtmp['type'] = 'codabar'; else $rtmp['type'] = 'text'; $rtmp['width'] = current($r->free->length); @@ -1324,7 +1525,7 @@ class quexmlpdf extends pdf { { $this->init(); $this->questionnaireId = intval($questionnaire['id']); - $this->newPage(); + $this->newPage(true); //first page //Draw questionnaireInfo before if exists if (isset($questionnaire['infobefore'])) @@ -1406,7 +1607,7 @@ class quexmlpdf extends pdf { //fill to the end of the last page - $this->fillPageBackground(); + $this->fillLastPageBackground(); } @@ -1420,9 +1621,9 @@ class quexmlpdf extends pdf { protected function drawInfo($info) { $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $this->questionnaireInfoMargin, $this->getMainPageX(), $this->GetY() - $this->questionBorderBottom, "
",0,1,true,true); - $html = "
getMainPageWidth() . "mm\" class=\"questionnaireInfo\">{$info}
"; - $this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->questionnaireInfoMargin, $this->getColumnX(), $this->GetY() - $this->questionBorderBottom, "
",0,1,true,true); + $html = "
getColumnWidth() . "mm\" class=\"questionnaireInfo\">{$info}
"; + $this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); } /** @@ -1454,8 +1655,8 @@ class quexmlpdf extends pdf { $this->SetY($this->GetY() + $this->helpBeforeBorderTop,false); //new line $this->setBackground('question'); - $html = "
getMainPageWidth() . "mm\" class=\"questionHelpBefore\">{$question['helptextbefore']}
"; - $this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $html = "
getColumnWidth() . "mm\" class=\"questionHelpBefore\">{$question['helptextbefore']}
"; + $this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); //Leave a border at the bottom of the Help Before text if ($this->helpBeforeBorderBottom > 0) //question border @@ -1463,7 +1664,6 @@ class quexmlpdf extends pdf { } //Question header - if (isset($question['text'])) $question['text'] = FlattenText($question['text']); $this->drawQuestionHead($question['title'], $question['text'],$help,$specifier); $text = ""; @@ -1505,7 +1705,12 @@ class quexmlpdf extends pdf { case 'vas': $this->drawMatrixVas($subquestions,$text,$response['labelleft'],$response['labelright']); break; - + case 'i25': + $this->drawMatrixBarcode($subquestions, 'I25'); + break; + case 'codabar': + $this->drawMatrixBarcode($subquestions, 'CODABAR'); + break; } } else @@ -1513,6 +1718,10 @@ class quexmlpdf extends pdf { $response = $r['response']; $type = $response['type']; + $defaultvalue = false; + if (isset($r['defaultvalue'])) + $defaultvalue = $r['defaultvalue']; + if (isset($response['text']) && !empty($response['text'])) $rtext = $text . $this->subQuestionTextSeparator . $response['text']; else @@ -1524,28 +1733,34 @@ class quexmlpdf extends pdf { { case 'fixed': if (isset($response['rotate'])) - $this->drawSingleChoiceHorizontal($response['categories'],array(array('text' => '', 'varname' => $varname)),$rtext); + $this->drawSingleChoiceHorizontal($response['categories'],array(array('text' => '', 'varname' => $varname, 'defaultvalue' => $defaultvalue)),$rtext); else - $this->drawSingleChoiceVertical($response['categories'],array(array('text' => '', 'varname' => $varname)),$rtext); + $this->drawSingleChoiceVertical($response['categories'],array(array('text' => '', 'varname' => $varname, 'defaultvalue' => $defaultvalue)),$rtext); break; case 'longtext': $this->addBoxGroup(6,$varname,$rtext); - $this->drawLongText($response['width']); + $this->drawLongText($response['width'],$defaultvalue); break; case 'number': $bgtype = 4; case 'currency': case 'text': $this->addBoxGroup($bgtype,$varname,$rtext,$response['width']); - $this->drawText($response['text'],$response['width']); + $this->drawText($response['text'],$response['width'],$defaultvalue); //Insert a gap here - $this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); + $this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); $this->SetY($this->GetY() + $this->subQuestionLineSpacing,false); break; case 'vas': $this->addBoxGroup(1,$varname,$rtext,strlen($this->vasIncrements)); $this->drawVas("",$response['labelleft'],$response['labelright']); break; + case 'i25': + $this->drawMatrixBarcode(array(array('text' => $rtext, 'varname' => $varname, 'defaultvalue' => $defaultvalue)),'I25'); + break; + case 'codabar': + $this->drawMatrixBarcode(array(array('text' => $rtext, 'varname' => $varname, 'defaultvalue' => $defaultvalue)),'CODABAR'); + break; } } @@ -1555,8 +1770,8 @@ class quexmlpdf extends pdf { if (isset($question['helptextafter'])) { $this->setBackground('question'); - $html = "
getMainPageWidth() . "mm\" class=\"questionHelpAfter\">{$question['helptextafter']}
"; - $this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $html = "
getColumnWidth() . "mm\" class=\"questionHelpAfter\">{$question['helptextafter']}
"; + $this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); } @@ -1590,16 +1805,62 @@ class quexmlpdf extends pdf { else $this->addBoxGroup($bgtype,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text'],$width); + $defaultvalue = false; + if (isset($s['defaultvalue'])) + $defaultvalue = $s['defaultvalue']; + $this->drawText($s['text'],$width,$defaultvalue); - $this->drawText($s['text'],$width); + $currentY = $this->GetY(); + + //Insert a gap here + $this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); + $this->SetY($currentY + $this->subQuestionLineSpacing,false); + } + } + + + /** + * Draw a barcode as a "question" + * + * @param string $subquestions + * @param mixed $type + * + * @author Adam Zammit + * @since 2012-06-22 + */ + protected function drawMatrixBarcode($subquestions, $type) + { + $c = count($subquestions); + + for ($i = 0; $i < $c; $i++) + { + $s = $subquestions[$i]; + + $this->addBoxGroup(5,$s['varname'],$s['text'],strlen($s['defaultvalue'])); + + $x = $this->getColumnX(); + $y = $this->GetY(); + + $html = "
"; + $this->setBackground('question'); + $this->writeHTMLCell($this->getColumnWidth(), $this->barcodeResponseHeight, $this->getColumnX(), $this->GetY() , $this->style . $html,0,1,true,false); + + //draw the barcode + $barcodeStyle = array('align' => 'R', 'border' => false, 'padding' => '0', 'bgcolor' => $this->backgroundColourQuestion, 'text' => false, 'stretch' => false); + $this->write1DBarcode($s['defaultvalue'], $type, $x, $y, $this->getColumnWidth() - $this->skipColumnWidth,$this->barcodeResponseHeight,'', $barcodeStyle, 'B'); + + //pointer should now be at the bottom right - but make the box the width of the whole column for better reading + $this->addBox($x,$y,$this->GetX(),$this->getColumnWidth() + $this->getColumnX()); $currentY = $this->GetY(); //Insert a gap here - $this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); + $this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); $this->SetY($currentY + $this->subQuestionLineSpacing,false); + } + } /** @@ -1637,7 +1898,7 @@ class quexmlpdf extends pdf { $currentY = $this->GetY(); //Insert a gap here - $this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); + $this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); $this->SetY($currentY + $this->subQuestionLineSpacing,false); $heading = false; @@ -1651,26 +1912,35 @@ class quexmlpdf extends pdf { * Draw a large empty box for writing in text * * @param mixed $width The "width" of the box. This relates to the number of "lines" high + * @param bool|string $defaultvalue The default text to print in the box (if any) * * @author Adam Zammit * @since 2010-09-02 */ - protected function drawLongText($width) + protected function drawLongText($width,$defaultvalue = false) { + //Calculate long text box width as the width of the available column minus the skip column and question title area + $rwidth = $this->getColumnWidth() - $this->skipColumnWidth - $this->questionTitleWidth; + $currentY = $this->GetY(); $height = $width * $this->longTextResponseHeightMultiplier; $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $height, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $height, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); $this->SetY($currentY,false); $this->setBackground('empty'); $border = array('LTRB' => array('width' => $this->textResponseBorder, 'dash' => 0)); //Align to skip column on right - $this->SetX(($this->getPageWidth() - $this->getMainPageX() - $this->skipColumnWidth - $this->longTextResponseWidth),false); + $this->SetX((($this->getColumnWidth() + $this->getColumnX()) - $this->skipColumnWidth - $rwidth),false); //Add to pay layout - $this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $this->longTextResponseWidth, $this->GetY() + $height); + $this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $rwidth, $this->GetY() + $height); $this->SetDrawColor($this->lineColour[0]); - $this->Cell($this->longTextResponseWidth,$height,'',$border,0,'',true,'',0,false,'T','C'); + + $text = ""; + if ($defaultvalue !== false) + $text = $defaultvalue; + + $this->Cell($rwidth,$height,$text,$border,0,'',true,'',0,false,'T','T'); $currentY = $currentY + $height; $this->SetY($currentY,false); } @@ -1689,7 +1959,7 @@ class quexmlpdf extends pdf { */ protected function drawVas($text, $labelleft,$labelright,$heading = true) { - $textwidth = $this->getMainPageWidth() - $this->skipColumnWidth - ($this->vasLength + ($this->vasLineWidth * 2.0)) - 2; + $textwidth = $this->getColumnWidth() - $this->skipColumnWidth - ($this->vasLength + ($this->vasLineWidth * 2.0)) - 2; $this->setBackground('question'); if ($heading) @@ -1703,7 +1973,7 @@ class quexmlpdf extends pdf { $html = "
$labelleft$labelright
"; - $this->writeHTMLCell($this->getMainPageWidth(), 0, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,false); + $this->writeHTMLCell($this->getColumnWidth(), 0, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,false); } $currentY = $this->GetY(); @@ -1714,28 +1984,28 @@ class quexmlpdf extends pdf { $textwidth += 2; - $this->writeHTMLCell($this->getMainPageWidth(), $this->vasAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,false); + $this->writeHTMLCell($this->getColumnWidth(), $this->vasAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,false); $ncurrentY = $this->GetY(); $this->SetY($currentY,false); - $this->SetX($textwidth + $this->getMainPageX(),false); + $this->SetX($textwidth + $this->getColumnX(),false); $this->SetLineWidth($this->vasLineWidth); $this->SetDrawColor($this->lineColour[0]); //Draw the VAS left vert line $ly = (($this->vasAreaHeight - $this->vasHeight) / 2.0) + $currentY; - $lx = $textwidth + $this->getMainPageX(); + $lx = $textwidth + $this->getColumnX(); $this->Line($lx,$ly,$lx,$ly + $this->vasHeight); //Right vert line - $lx = $textwidth + $this->getMainPageX() + $this->vasLength + $this->vasLineWidth; + $lx = $textwidth + $this->getColumnX() + $this->vasLength + $this->vasLineWidth; $this->Line($lx,$ly,$lx,$ly + $this->vasHeight); //Line itself $ly = ($this->vasAreaHeight / 2.0) + $currentY; - $lx = $textwidth + $this->getMainPageX() + ($this->vasLineWidth / 2.0); + $lx = $textwidth + $this->getColumnX() + ($this->vasLineWidth / 2.0); $this->Line($lx,$ly,$lx + $this->vasLength,$ly); //Add to layout system @@ -1756,14 +2026,15 @@ class quexmlpdf extends pdf { * * @param string $text The text label if any (can be HTML) * @param int $width The number of boxes to draw + * @param bool|string $defaultvalue The default text to include or false if none */ - protected function drawText($text,$width) + protected function drawText($text,$width,$defaultvalue = false) { $this->SetDrawColor($this->lineColour[0]); //calculate text responses per line - $textResponsesPerLine = round(($this->getMainPageWidth() - $this->skipColumnWidth - $this->textResponseMarginX) / ($this->textResponseWidth + $this->textResponseBorder)); - $labelTextResponsesSameLine = round(($this->getMainPageWidth() - $this->skipColumnWidth - $this->labelTextResponsesSameLineMarginX) / ($this->textResponseWidth + $this->textResponseBorder)); + $textResponsesPerLine = round(($this->getColumnWidth() - $this->skipColumnWidth - $this->textResponseMarginX) / ($this->textResponseWidth + $this->textResponseBorder)); + $labelTextResponsesSameLine = round(($this->getColumnWidth() - $this->skipColumnWidth - $this->labelTextResponsesSameLineMarginX) / ($this->textResponseWidth + $this->textResponseBorder)); //draw boxes - can draw up to $textResponsesPerLine for each line $lines = ceil($width / $textResponsesPerLine); @@ -1772,35 +2043,38 @@ class quexmlpdf extends pdf { if ($width > $labelTextResponsesSameLine && !empty($text)) { $this->setBackground('question'); - $html = "
questionTitleWidth}mm\">getMainPageWidth() - $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"responseAboveText\">$text
"; - $this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $html = "
questionTitleWidth}mm\">getColumnWidth() - $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"responseAboveText\">$text
"; + $this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); } $currentY = $this->GetY(); + $startstring = 0; + for ($i = 0; $i < $lines; $i++) { if ($lines == 1) $cells = $width; //one line only else if (($i + 1 == $lines)) $cells = ($width - ($textResponsesPerLine * $i)); //last line else $cells = $textResponsesPerLine; //middle line + //add another box group if moving on to another line if ($i >= 1) $this->addBoxGroupCopyPrevious(); - $textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - (($this->textResponseWidth + $this->textResponseBorder ) * $cells); + $textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - (($this->textResponseWidth + $this->textResponseBorder ) * $cells); //print "textwidth: $textwidth cells: $cells mainpagex: " . $this->getMainPageX() . "
"; //First draw a background of height $this->responseLabelHeight $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $this->textResponseHeight, $this->getMainPageX(), $this->GetY() , $this->style . $html,0,1,true,false); + $this->writeHTMLCell($this->getColumnWidth(), $this->textResponseHeight, $this->getColumnX(), $this->GetY() , $this->style . $html,0,1,true,false); if ($lines == 1 && $cells <= $labelTextResponsesSameLine && !empty($text)) { $this->setDefaultFont($this->responseTextFontSize); - $this->MultiCell($textwidth,$this->textResponseHeight,$text,0,'R',false,1,$this->getMainPageX(),$currentY,true,0,false,true,$this->textResponseHeight,'M',true); + $this->MultiCell($textwidth,$this->textResponseHeight,$text,0,'R',false,1,$this->getColumnX(),$currentY,true,0,false,true,$this->textResponseHeight,'M',true); //$html = "
$text
"; @@ -1810,9 +2084,15 @@ class quexmlpdf extends pdf { $ncurrentY = $this->GetY(); $this->SetY($currentY,false); - $this->SetX($textwidth + $this->getMainPageX() + 2,false); //set the X position to the first cell + $this->SetX($textwidth + $this->getColumnX() + 2,false); //set the X position to the first cell + + $string = false; + if ($defaultvalue !== false) + $string = substr($defaultvalue,$startstring,$cells); + + $this->drawCells($cells,$string); - $this->drawCells($cells); + $startstring += $cells; $currentY = $ncurrentY; @@ -1822,9 +2102,9 @@ class quexmlpdf extends pdf { if (!(($i + 1) == $lines) && $this->textResponseLineSpacing > 0) //if there should be a gap between text responses and not the last { - $this->SetX($this->getMainPageX(),false); + $this->SetX($this->getColumnX(),false); $this->setBackground('question'); - $this->Cell($this->getMainPageWidth(),$this->textResponseLineSpacing,'','',0,'',true,'',0,false,'T','C'); + $this->Cell($this->getColumnWidth(),$this->textResponseLineSpacing,'','',0,'',true,'',0,false,'T','C'); $currentY += $this->textResponseLineSpacing; $this->SetY($currentY,false); //new line } @@ -1837,11 +2117,12 @@ class quexmlpdf extends pdf { * Draw X number of cells at the current X Y position * * @param int $cells The number of text cells to draw + * @param string $string A string to draw if set * * @author Adam Zammit * @since 2010-09-08 */ - protected function drawCells($cells) + protected function drawCells($cells, $string) { $this->setBackground('empty'); $this->SetDrawColor($this->lineColour[0]); @@ -1870,8 +2151,12 @@ class quexmlpdf extends pdf { //Add the box to the layout scheme $this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $this->textResponseWidth,$this->GetY() + $this->textResponseHeight); + $text = ''; + if (isset($string[$j])) + $text = $string[$j]; + //Draw the box - $this->Cell($this->textResponseWidth,$this->textResponseHeight,'',$border,0,'',true,'',0,false,'T','C'); + $this->Cell($this->textResponseWidth,$this->textResponseHeight,$text,$border,0,'',true,'',0,false,'T','C'); } @@ -1897,7 +2182,7 @@ class quexmlpdf extends pdf { $rwidth = ($width * ($this->textResponseWidth + $this->textResponseBorder + $this->textResponseLineSpacing)); - $textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - ($rwidth * $total); + $textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total); $html = ""; foreach ($subquestions as $r) @@ -1905,18 +2190,18 @@ class quexmlpdf extends pdf { $html .= ""; } $html .= "
{$r['text']}
"; - $this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); $currentY = $this->GetY(); $html = "
"; - $this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); $ncurrentY = $this->GetY(); $this->SetY($currentY,false); //Set X position - $this->SetX($this->getMainPageX() + $textwidth,false); + $this->SetX($this->getColumnX() + $textwidth,false); foreach ($subquestions as $s) @@ -1927,10 +2212,12 @@ class quexmlpdf extends pdf { else $this->addBoxGroup($bgtype,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']); - + $string = false; + if (isset($s['defaultvalue'])) + $string = substr($defaultvalue,0,$width); //Draw the cells - $this->drawCells($width); + $this->drawCells($width,$string); //Move X for a gap $this->SetX($this->GetX() + $this->textResponseLineSpacing,false); @@ -1941,17 +2228,16 @@ class quexmlpdf extends pdf { $this->SetY($ncurrentY,false); } + /** - * Draw a horizontal table of respones including "eye guides" + * Draw the head of a single choice horizontal table of responses * * @param array $categories The response categories - * @param array $subquestions The subquestions if any - * @param string|bool $parenttext The question text of the parent or false if not specified * * @author Adam Zammit - * @since 2010-09-08 + * @since 2012-06-05 */ - protected function drawSingleChoiceHorizontal($categories, $subquestions = array(array('text' => '')),$parenttext = false) + protected function drawSingleChoiceHorizontalHead($categories) { $total = count($categories); $currentY = $this->GetY(); @@ -1961,22 +2247,22 @@ class quexmlpdf extends pdf { else $rwidth = $this->singleResponseVerticalAreaWidth; - $textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - ($rwidth * $total); + $textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total); //First draw a background of height $this->responseLabelHeight $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $this->responseLabelHeight, $this->getMainPageX(), $currentY , $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->responseLabelHeight, $this->getColumnX(), $currentY , $this->style . $html,0,1,true,true); $this->setDefaultFont($this->responseLabelFontSize); $count = 0; - //Draw a Cell for each rwidth from $textwidth + $this->getMainPageX(),currentY + //Draw a Cell for each rwidth from $textwidth + $this->getColumnX(),currentY foreach ($categories as $r) { $y = $currentY; - $x = ($textwidth + $this->getMainPageX() + ($rwidth * $count)); + $x = ($textwidth + $this->getColumnX() + ($rwidth * $count)); // Going to break the line because of long word if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength) @@ -1990,13 +2276,62 @@ class quexmlpdf extends pdf { $count++; } + } + + /** + * Draw a horizontal table of respones including "eye guides" + * + * @param array $categories The response categories + * @param array $subquestions The subquestions if any + * @param string|bool $parenttext The question text of the parent or false if not specified + * + * @author Adam Zammit + * @since 2010-09-08 + */ + protected function drawSingleChoiceHorizontal($categories, $subquestions = array(array('text' => '')),$parenttext = false) + { + $total = count($categories); + $currentY = $this->GetY(); + + if ($total > $this->singleResponseHorizontalMax) //change if too many cats + $rwidth = $this->singleResponseVerticalAreaWidthSmall; + else + $rwidth = $this->singleResponseVerticalAreaWidth; + + $textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total); + + //draw the header + $this->drawSingleChoiceHorizontalHead($categories); + $currentY += $this->responseLabelHeight; - //reset font size + if ($this->allowSplittingSingleChoiceHorizontal) $this->startTransaction(); //start a transaction + for ($i = 0; $i < count($subquestions); $i++) + { + $s = $subquestions[$i]; + + if ($this->allowSplittingSingleChoiceHorizontal && $this->pageBreakOccured) + { + $this->pageBreakOccured = false; + $this->rollBackTransaction(true); + $this->SetAutoPageBreak(false); //Temporarily set so we don't trigger a page break + $this->fillPageBackground(); + $this->newPage(); + $this->drawSingleChoiceHorizontalHead($categories); + //reset currentY + $currentY = $this->GetY() + $this->responseLabelHeight; - foreach ($subquestions as $s) + $i = $i - 2; //go back and draw subquestions on the new page + } + else { + if ($this->allowSplittingSingleChoiceHorizontal) + { + $this->commitTransaction(); + $this->startTransaction(); //start a transaction to allow for splitting over pages if necessary + } + //Add box group to current layout if ($parenttext == false) $this->addBoxGroup(1,$s['varname'],$s['text']); @@ -2009,13 +2344,10 @@ class quexmlpdf extends pdf { //Draw background $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseHorizontalHeight, $this->getMainPageX(), $currentY, $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseHorizontalHeight, $this->getColumnX(), $currentY, $this->style . $html,0,1,true,true); $this->setDefaultFont($this->responseTextFontSize); - $this->MultiCell($textwidth,$this->singleResponseHorizontalHeight,$s['text'],0,'R',false,0,$this->getMainPageX(),$currentY,true,0,false,true,$this->singleResponseHorizontalHeight,'M',true); - - - + $this->MultiCell($textwidth,$this->singleResponseHorizontalHeight,$s['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$this->singleResponseHorizontalHeight,'M',true); //Draw the categories horizontally @@ -2027,7 +2359,11 @@ class quexmlpdf extends pdf { else if ($rnum < $total) $num = 'middle'; else if ($rnum == $total) $num = 'last'; - $position = $this->drawHorizontalResponseBox(($this->getMainPageX() + $textwidth + (($rnum - 1) * $rwidth)),$currentY, $num,false,false,($total > $this->singleResponseHorizontalMax)); + $bfilled = false; + if (isset($s['defaultvalue']) && $s['defaultvalue'] !== false && $s['defaultvalue'] == $r['value']) + $bfilled = true; + + $position = $this->drawHorizontalResponseBox(($this->getColumnX() + $textwidth + (($rnum - 1) * $rwidth)),$currentY, $num,false,false,($total > $this->singleResponseHorizontalMax),$bfilled); //Add box to the current layout $this->addBox($position[0],$position[1],$position[2],$position[3],$r['value'],$r['text']); @@ -2043,7 +2379,7 @@ class quexmlpdf extends pdf { $this->SetY($currentY,false); } - + } } /** @@ -2063,7 +2399,7 @@ class quexmlpdf extends pdf { $rwidth = $this->singleResponseVerticalAreaWidth; - $textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - ($rwidth * $total); + $textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total); if (count($categories) > 1) { @@ -2073,16 +2409,16 @@ class quexmlpdf extends pdf { //First draw a background of height $this->responseLabelHeight $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $this->responseLabelHeight, $this->getMainPageX(), $currentY , $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->responseLabelHeight, $this->getColumnX(), $currentY , $this->style . $html,0,1,true,true); $this->setDefaultFont($this->responseLabelFontSize); - //Draw a Cell for each rwidth from $textwidth + $this->getMainPageX(),currentY + //Draw a Cell for each rwidth from $textwidth + $this->getColumnX(),currentY foreach ($subquestions as $r) { $y = $currentY; - $x = ($textwidth + $this->getMainPageX() + ($rwidth * $count)); + $x = ($textwidth + $this->getColumnX() + ($rwidth * $count)); // Going to break the line because of long word if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength) @@ -2122,7 +2458,7 @@ class quexmlpdf extends pdf { else $this->addBoxGroup(1,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']); - $x = $this->getMainPageX() + $textwidth + ($rwidth * $snum) + ((($rwidth - $this->singleResponseBoxWidth) / 2.0 )); + $x = $this->getColumnX() + $textwidth + ($rwidth * $snum) + ((($rwidth - $this->singleResponseBoxWidth) / 2.0 )); $other = false; @@ -2140,10 +2476,10 @@ class quexmlpdf extends pdf { //Draw background $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); $this->setDefaultFont($this->responseTextFontSize); - $this->MultiCell($textwidth,$this->singleResponseAreaHeight,$r['text'],0,'R',false,0,$this->getMainPageX(),$currentY,true,0,false,true,$this->singleResponseAreaHeight,'M',true); + $this->MultiCell($textwidth,$this->singleResponseAreaHeight,$r['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$this->singleResponseAreaHeight,'M',true); } @@ -2153,8 +2489,12 @@ class quexmlpdf extends pdf { if (isset($r['skipto'])) $skipto = $r['skipto']; if (isset($r['other']) && $rnum == $total) $other = $r['other']; //only set for last in set + $bfilled = false; + if (isset($s['defaultvalue']) && $s['defaultvalue'] !== false && $s['defaultvalue'] == $r['value']) + $bfilled = true; + //Draw the box over the top - $position = $this->drawVerticalResponseBox($x,$currentY, $num, $other, $skipto); + $position = $this->drawVerticalResponseBox($x,$currentY, $num, $other, $skipto, $bfilled); //Add box to the current layout $this->addBox($position[0],$position[1],$position[2],$position[3],$r['value'],$r['text']); @@ -2181,9 +2521,14 @@ class quexmlpdf extends pdf { { //Display the "other" variable $this->addBoxGroup(3,$other['varname'],$other['text'],$other['width']); - $this->drawText($other['text'],$other['width']); + + $defaultvalue = false; + if (isset($other['defaultvalue']) && $other['defaultvalue'] !== false) + $defaultvalue = $other['defaultvalue']; + + $this->drawText($other['text'],$other['width'],$defaultvalue); //Insert a gap here - $this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); + $this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion); $this->SetY($this->GetY() + $this->subQuestionLineSpacing,false); } @@ -2210,21 +2555,22 @@ class quexmlpdf extends pdf { if (isset($this->skipToRegistry[$title])) $class = "questionTitleSkipTo"; - $html = ""; + $html = "
questionTitleWidth . "mm\">$titlegetMainPageWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$text
"; if ($specifier !== false) { - $html .= ""; + $html .= ""; } $html .= "
questionTitleWidth . "mm\">$titlegetColumnWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$text
questionTitleWidth . "mm\"> getMainPageWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$specifier
questionTitleWidth . "mm\"> getColumnWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$specifier
"; - $this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + + $this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); if ($help != false) { - $html = "
getMainPageWidth() - $this->skipColumnWidth) . "mm\" class=\"questionHelp\">$help
"; - $this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true); + $html = "
getColumnWidth() - $this->skipColumnWidth) . "mm\" class=\"questionHelp\">$help
"; + $this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true); } } @@ -2251,7 +2597,7 @@ class quexmlpdf extends pdf { $html .= "
$info
"; $this->setBackground('section'); - $this->writeHTMLCell($this->getPageWidth() - (($this->cornerBorder *2) + ($this->cornerWidth * 2)),$this->sectionHeight,$this->getMainPageX(),$this->getY(),$this->style . $html,array('B' => array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->backgroundColourEmpty)),1,true,true,''); + $this->writeHTMLCell($this->getColumnWidth(),$this->sectionHeight,$this->getColumnX(),$this->getY(),$this->style . $html,array('B' => array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->backgroundColourEmpty)),1,true,true,''); $this->setBackground('empty'); } @@ -2267,19 +2613,33 @@ class quexmlpdf extends pdf { } /** - * Draw the background from the current Y position to the bottom of the page + * Make sure to fill the remaining columns on the last page * - * @param bool $last Optional, defaults to false. If this is the last page + * @author Adam Zammit + * @since 2012-05-31 + */ + protected function fillLastPageBackground() + { + while ($this->columnCP < $this->columns) + { + $this->fillPageBackground(); + $this->SetXY($this->getColumnX(),($this->cornerBorder + $this->cornerWidth)); + $this->columnCP++; + } + } + + /** + * Draw the background from the current Y position to the bottom of the page * * @author Adam Zammit * @since 2010-09-15 */ - protected function fillPageBackground($last = false) + protected function fillPageBackground() { $height = $this->getPageHeight() - $this->cornerBorder - $this->GetY() + $this->questionBorderBottom; $html = "
"; $this->setBackground('question'); - $this->writeHTMLCell($this->getMainPageWidth(), $height, $this->getMainPageX(), $this->GetY() - $this->questionBorderBottom, $this->style . $html,0,1,true,true); + $this->writeHTMLCell($this->getColumnWidth(), $height, $this->getColumnX(), $this->GetY() - $this->questionBorderBottom, $this->style . $html,0,1,true,true); } /** @@ -2288,7 +2648,11 @@ class quexmlpdf extends pdf { * Draw the barcode and page corners * */ - protected function newPage() + protected function newPage($init = false) + { + $this->columnCP++; //increment the column pointer + + if ($init || ($this->columnCP >= $this->columns)) // if it is time for a new page { $this->AddPage(); @@ -2350,9 +2714,16 @@ class quexmlpdf extends pdf { $this->layoutCP = $barcodeValue; $this->SetXY($cb + $this->cornerWidth, $cb + $this->cornerWidth); - $this->SetAutoPageBreak(true,$this->getMainPageX()); $this->setBackground('empty'); + + $this->columnCP = 0; //reset column pointer + } + else // move to a new column + { + $this->SetXY($this->getColumnX(),($this->cornerBorder + $this->cornerWidth)); + } + $this->SetAutoPageBreak(true,$this->getMainPageX()); } /** diff --git a/application/views/admin/export/quexmlpdf_view.php b/application/views/admin/export/quexmlpdf_view.php index 75dc052..e74304d 100644 --- a/application/views/admin/export/quexmlpdf_view.php +++ b/application/views/admin/export/quexmlpdf_view.php @@ -11,5 +11,5 @@ span.sectionTitle {font-size:18pt; font-weight:bold;} span.sectionDescription {font-size:14pt; font-weight:bold;} div.sectionInfo {font-style:normal; font-size:10pt; text-align:left; font-weight:normal;} - td.questionnaireInfo {font-size:16pt; text-align:center; font-weight:bold;} + td.questionnaireInfo {font-size:14pt; text-align:center; font-weight:bold;}