Prevent cells from overlapping when the content is wider than the cell - fpdf

I have this.
for($i=0; $i < $longArreglo; $i++) {
$this->Cell($w[0],6, $final_array[$i][0],'LR',0,'L', $fill);
$this->Cell($w[1],6, $final_array[$i][2],'LR',0,'C', $fill);
$this->Cell($w[2],6, $final_array[$i][3],'LR',0,'L', $fill);
$this->Cell($w[3],6, $final_array[$i][5],'LR',0,'C', $fill);
$this->Cell($w[4],6, $final_array[$i][6],'LR',0,'C', $fill);
$this->Cell($w[5],6, $final_array[$i][12],'LR',0,'C', $fill);
$this->Cell($w[6],6, $final_array[$i][13],'LR',0,'C', $fill);
$this->Cell($w[7],6, $final_array[$i][14],'LR',0,'C', $fill);
$this->Cell($w[8],6, $final_array[$i][15],'LR',0,'C', $fill);
$this->Cell($w[9],6, $final_array[$i][16],'LR',0,'C', $fill);
$this->Cell($w[10],6, $final_array[$i][17],'LR',0,'C', $fill);
$this->Cell($w[11],6, $final_array[$i][18],'LR',0,'C', $fill);
$this->Cell($w[12],6, $final_array[$i][19],'LR',0,'C', $fill);
$this->Cell($w[13],6, $final_array[$i][20],'LR',0,'C', $fill);
$this->Ln();
}
And here: $this->Cell($w[2],6, $final_array[$i][3],'LR',0,'L', $fill); is a person name, the width of cell is 15 and if the name is most large than cell, it does this:
I need the cells to not coalesce.

This post might be old but I couldn't find any other solution on the internet. I've modified Hugo's post and I hope that this will be helpful to someone one day. I've created a new method in the fpdf class for this for ease of use.
function pdfText($cellWidth, $text, $pdf){
$textWidth = $pdf->getstringwidth($text);
while($textWidth > $cellWidth -1){
$text = substr($text,0,-1);
$textWidth = $pdf->getstringwidth($text);
}
return $text;
}
require_once('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint esse quia repellat cupiditate excepturi exercitationem asperiores eligendi iusto. Blanditiis sequi suscipit assumenda quibusdam aliquid quas eligendi soluta ab fugit ad.';
$pdf->setFont('Arial', '', 10);
$cellWidth = 180;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,6,$text,1,1,'L',0);
$pdf->setFont('Arial', '', 12);
$cellWidth = 160;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,7,$text,1,1,'L',0);
$pdf->setFont('Arial', '', 14);
$cellWidth = 140;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,8,$text,1,1,'L',0);
$pdf->setFont('Arial', '', 16);
$cellWidth = 120;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,9,$text,1,1,'L',0);
$pdf->Output('I');

so, the example should be:
// width - width of cell
// text to be put into cell
// pdf - pdf object of fpdf
// fill - how to fill cell?
function putField($width,$text,$pdf,$fill){
$textwidth = $pdf->getstringwidth($text);
while($textwidth>$width){ // loop until textwidth is shorter than cell width
$text=substr($text,0,-1); // strip last char
$textwidth = $pdf->getstringwidth($text); // read text width again
}
$pdf->Cell($width,6, $text,'LR',0,'L', $fill); // put the cell
}
for($i=0; $i < $longArreglo; $i++) {
putField($w[0],$final_array[$i][0],$this,$fill);
}

Related

page has Too many redirects from mail.php file?

I hope someone can help me. I have a page with a form and then the information
is emailed to me. the code below seems to be redirecting to the same page over and over again. It used to work for years now its not always working.
any help appreciated. Thanks Steve
<?php
//****************************************
//edit here
$senderName = 'WEB';
$senderEmail = 'site#example.com';
$targetEmail = 'contact#sellmydiabeticteststrips.com';
$messageSubject = 'Message from web-site';
$redirectToReferer = true;
$redirectURL = 'contact.html';
//****************************************
// mail content
$ufname = $_POST['ufname'];
$uaddress = $_POST['uaddress'];
$uemail = $_POST['uemail'];
$utel = $_POST['utel'];
$ucity = $_POST['ucity'];
$ustate = $_POST['ustate'];
$uzip = $_POST['uzip'];
$ubrand = $_POST['ubrand'];
$unumber = $_POST['unumber'];
$ucheck = $_POST['ucheck'];
$agree = $_POST['agree'];
// collect interests data
$interestsString = '';
for($i = 0; $i < count($interests); $i++) {
$interestsString .= $interests[$i].($i < count($interests) - 1 ? ', ' : '');
}
// prepare message text
$messageText = 'First Name: '.$ufname."\n".
'Address: '.$uaddress."\n".
'Email: '.$uemail."\n".
'Telephone: '.$utel."\n".
'City: '.$ucity."\n".
'State: '.$ustate."\n".
'Zip: '.$uzip."\n".
'Brand of test strips: '.$ubrand."\n".
'Number of boxes: '.$unumber."\n".
'Check: '.$ucheck."\n".
'Terms and Conditions: '.$agree."\n";
if($interestsString) {
$messageText .= 'Kinderen wonen bij mij: '.$interestsString."\n";
}
// send email
$senderName = "=?UTF-8?B?" . base64_encode($senderName) . "?=";
$messageSubject = "=?UTF-8?B?" . base64_encode($messageSubject) . "?=";
$messageHeaders = "From: " . $senderName . " <" . $senderEmail . ">\r\n"
. "MIME-Version: 1.0" . "\r\n"
. "Content-type: text/plain; charset=UTF-8" . "\r\n";
if (preg_match('/^[_.0-9a-z-]+#([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$targetEmail,$matches))
mail($targetEmail, $messageSubject, $messageText, $messageHeaders);
// redirect
if($redirectToReferer) {
header("Location: ".#$_SERVER['HTTP_REFERER'].'#sent');
} else {
header("Location: ".$redirectURL);
}
?>

Get loop text values from mform

Mmform has a 'count' textfield. When user has filled with value 3, mform should create 'Unit part' by looping the textfields
(forename, designation and filemanager). Upon mform submission, I need to display Unit part filled by the user.
Could you let me know suggestions.
<?php
require('config.php');
require_once($CFG->libdir.'/formslib.php');
class active_form extends moodleform {
function definition() {
$mform = $this->_form;
$fileoptions = $this->_customdata['fileoptions'];
$count = $mform->addElement('text', 'count', get_string('count', 'form'), array('name' => 'count[]');
$count = $mform->setType('count', PARAM_INT);
for ($i=1; $i<=$count; $i++) {
// Unit
$mform->addElement('text', 'forename', get_string('forename', 'form'), array('name'=>'forename[]'));
$mform->setType('forename', PARAM_RAW);
$mform->addElement('text', 'designation', get_string('designation', 'form'), array('name'=>'designation[]'));
$mform->setType('designation', PARAM_RAW);
$mform->addElement('filemanager', 'attachment', get_string('attachment', 'form'), null, $fileoptions);
$mform->setType('attachment', PARAM_RAW);
}
$this->add_action_buttons();
}
function validation($data, $files) {
$errors = parent::validation($data, $files);
return $errors;
}
}
$mform = new active_form(null, $customdata);
if ($mform->is_submitted()) {
$data = $mform->get_data();
for ($i=1; $i <= $data->count; $i++) {
$forename = $data->forename;
$designation = $data->designation;
$attachment = $data->attachment;
echo 'forename' . $forename. '<br>';
echo 'designation' . $designation. '<br>';
echo 'attachment' . $attachment. '<br>';
}
}
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();
?>
ex: User has filled with
count: 3
forename = SVs Group
designation = Assistant Engineer
attachment = 676208496
forename = Prime Group
designation = Staff Member
attachment = 646759033
forename = Ecos Group
designation = Staff Member
attachment = 107025147
Output:
count:3
forename: SVs Group
designation: Assistant Engineer
attachment: 676208496
forename: Prime Group
designation: Staff Member
attachment: 646759033
forename: Ecos Group
designation: Staff Member
attachment: 107025147

Moodle email confirmation

When a new user register, moodle send confirmation email to user, from the language file lang/en/moodle.php with a string "emailconfirmation" by a moodle function:
function send_confirmation_email($user) {
global $CFG;
$site = get_site();
$supportuser = generate_email_supportuser();
$data = new stdClass();
$data->firstname = fullname($user);
$data->sitename = format_string($site->fullname);
$data->admin = generate_email_signoff();
$subject = get_string('emailconfirmationsubject', '', format_string($site->fullname));
$username = urlencode($user->username);
$username = str_replace('.', '%2E', $username); // prevent problems with trailing dots
$data->link = $CFG->wwwroot .'/login/confirm.php?data='. $user->secret .'/'. $username;
$message = get_string('emailconfirmation', '', $data);
$messagehtml = text_to_html(get_string('emailconfirmation', '', $data), false, false, true);
return email_to_user($user, $subject, $message, $messagehtml);
}
Moodle redirects to index.php after confirmation. How do I redirect $data->link to a custom page after confirmation:
if (send_confirmation_email($user)) {
if (AUTH_CONFIRM_OK = true) {
$urltogo = new moodle_url($CFG->wwwroot . "/coursestat/view.php", array('id' => $statid));
redirect($urltogo);
}
}
else
print_error('auth_noemail','auth_email');
Just use $data->link assuming its a string?
if (send_confirmation_email($user)) {
// Assuming $data->link is a string?
$urltogo = new moodle_url($data->link);
redirect($urltogo);
}
This line
if (AUTH_CONFIRM_OK = true) {
Doesn't make sense, AUTH_CONFIRM_OK is a constant. Also = is an assignment. I'm guessing you meant something like this:
if ($somevariable == AUTH_CONFIRM_OK) {

Zend Framework 1.12 barcode does not echo into next pages on pdf file

Barcode does not print into next pages on pdf file. Let me explain. If I want to print 60 barcodes and 15 barcodes on each page. It is printing 15 barcodes, rest of barcodes and pages showing blank. Here is my code
public function generatebarcodeAction(){
$this->_helper->layout()->disableLayout();
$pdf = new Zend_Pdf();
$hidden =$_POST['hidden']; // i want to barcode of this field.
// barcode should be print quantity from to quantity to
$quantityfrom =$_POST['quantity_from'];
$quantityto =$_POST['quantity_to'];
$rendererOptions = array(
'topOffset' => 50,
'leftOffset' => 50
);
Zend_Barcode::setBarcodeFont(dirname(ROOT_PATH) . '/inventory/library/Zend/Barcode/Object/fonts/open-sans/OpenSans-Semibold.ttf');
$numberOfPages = $quantityto/15;
$equipmentCount = $quantityto;
for($i = 1; $i <= $numberOfPages; $i++)
{
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 20);
$pdf->pages[] = $page;
}
foreach($pdf->pages as $id => $page)
{
if($equipmentCount > 15)
{
$barcodesOnThisPage = 15;
$equipmentCount = $equipmentCount - 15;
}
else
{
$barcodesOnThisPage = $equipmentCount;
}
for($i=$quantityfrom;$i<=$quantityto;$i++){
$barcodeOptions = array('text' => $hidden.$i);
$rendererOptions = array('topOffset' => 50*$i);
$pdfWithBarcode = Zend_Barcode::factory('code39', 'pdf',
$barcodeOptions, $rendererOptions)->setResource($pdf)->draw();
$pdfWithBarcode->save('testBarcode.pdf');
}
$quantityfrom = $i;
}
}
In this code you are create 4 blank pages and then draw all barcodes in page number 1. you cant see 45 barcodes because their margin is bigger than page height!!
you may want to add barcodes to $pages not to $pdf.
be care you should use for instead of foreach to rewrite $page

Missing image in Typo3 $this->contentObj in 6.0.3

in TYPO3 6.0.2 I got an Extbase/Fluid-Extension. The function in the Controller looks like this:
$this->contentObj = $this->configurationManager->getContentObject();
$data = $this->contentObj->data;
print_r($data);
This will return a tt_content - object including image => /path/to/image. Everything fine.
[bodytext] => Lorem ipsum dolor
[image] => ../../fileadmin/user_upload/images/businessman.jpg
Today changing source to TYPO3 6.0.3 everything the same but the image is just a "1".
[bodytext] => Lorem ipsum dolor
[image] => 1
What can I do? Thanks!
i found this to get files without sql query
public function myAction(){
// get data of the content object
$data = $this->contentObj = $this->configurationManager->getContentObject()->data;
// Neu ab Typo3 6.0.3 -> Bild in tt_content-Object wird nicht mehr mit zurueckgeliefert, daher:
$fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
$fileObjects = $fileRepository->findByRelation('tt_content', 'image', $data['uid']);
$files = array();
foreach ($fileObjects as $key => $value) {
$files[$key]['reference'] = $value->getReferenceProperties();
$files[$key]['original'] = $value->getOriginalFile()->getProperties();
}
#t3lib_utility_Debug::debug($files);
#die('Ende');
// Files in Fluid ausgeben
$this->view->assign('files', $files);
// Daten in Fluid ausgeben
$this->view->assign('data', $data);
}
fluid
<f:for each="{files}" as="file">
<li>
<img src="fileadmin{file.original.identifier}" alt="" />
<p class="flex-caption"><f:format.nl2br>{file.reference.description}</f:format.nl2br></p>
</li>
</f:for>
the bug appears to be a result of the security update where the typical jumpURL system has changed (SQL Injection). I filed a bug here: http://forge.typo3.org/issues/46090
Since TYPO3 6 the method "function getContentObject($name)" was located in
*typo3\sysext\cms\tslib\class.tslib_content.php*.
Content of this file:
/*
* #deprecated since 6.0, the classname tslib_cObj and this file is obsolete
* and will be removed with 6.2. The class was renamed and is now located at:
* typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
*/
require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('frontend') . 'Classes/ContentObject/ContentObjectRenderer.php';
But I don't see any differences between the old an the new file containing my problem.
I didn't find out how to get the file reference for the tt_content-entry "native", so I wrote a SQL-query:
public function bla() {
// get data of the content object
$this->contentObj = $this->configurationManager->getContentObject();
$data = $this->contentObj->data;
// Neu ab Typo3 6.0.3 -> Bild in tt_content-Object wird nicht mehr mit zurueckgeliefert, daher:
// https://forge.typo3.org/issues/46090
// http://stackoverflow.com/questions/15250351/missing-image-in-typo3-this-contentobj-in-6-0-3
$res = $GLOBALS['TYPO3_DB']->sql_query(
'select sys_file.identifier from sys_file_reference left join sys_file on sys_file_reference.uid_local = sys_file.uid where sys_file_reference.uid_foreign='.$data['uid'].' and sys_file_reference.deleted=0'
);
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$data['image'] = $row['identifier'];
}
#print_r($data);
// assign the data to the fluid template
$this->view->assign('data', $data);
}