I'm using a custom module called ProductInvestigation and Cases module; when the user adds/deletes a case from the subpanel; I would like to send an email. It has a one to many relationship. The logic I'm thinking of is that if the cases status is new and ProductInvestigation status is InvestigationClosed then it should send out an email. Function createPIEmailwithCases is what I would like to use to send the email. But how do I get the data from the relationship to be send in the email. Is it that function before_add and after_add should be in this function createPIEmailwithCases? This is what I have so far.
function before_add($bean, $event, $arguments)
{
if ($arguments['related_module'] =='Cases')
{
$bean->new_case_c =$arguments['related_id'];
$case_bean = BeanFactory::getBean('Cases', $arguments['related_id']);
/* Get PI Status */
$pi_status=trim($bean->getFieldValue('status_c'));
if ($case_bean->status_c = "New" && $pi_status='Investigation_Closed' )
{
}
}
}
function after_add($bean, $event, $arguments)
{
if ($arguments['related_module'] =='Cases'){
$bean->new_case_c =$arguments['related_id'];
$bean->save();
}
}
*function createPIEmailwithCases(&$email,$action_array,$bean,$xtpl){
/* Get PI Number */
$xtpl->assign('PI_Number', $bean->pinum_c);
/* Get PI Subject */
$xtpl->assign('PI_Subject', $bean->name);
/* Get Product Name */
$xtpl->assign('Product_Name', $bean->product_name_c);
/* Get Product Type */
$xtpl->assign('Product_Type', $bean->type_of_product_c);
/* Get Batch # */
$xtpl->assign('Batch_Number', $bean->batch_c);
/* Get Size(s) */
$xtpl->assign('Size', $bean->size_c);
/* Get Fill Date */
$xtpl->assign('Fill_Date', $bean->filldate_c);
/* Get Batch # */
$xtpl->assign('BestBefore', $bean->bestbefore_c);
/* Get PI Description */
$xtpl->assign('PI_Desc', $bean->description);
/* Get Reviewer Name */
$xtpl->assign('Reviewed_By',$bean->reviewer_c);
$xtpl->assign('Review_Date',$bean->reviewdate_c);
/* Create email message using email template and data above */
$xtpl->parse('block');
$email->Body = from_html($xtpl->text('block'));
return $email;
}
SuiteCRM provides different types of hook and in this case, you can use following relationship hooks.
after_relationship_add
after_relationship_delete
Support URL: https://docs.suitecrm.com/developer/logic-hooks/
I am currently trying to get tcpdf working on my website. I am using xampp as a localhost, but cannot seem to get the config files working correctly. I am almost certain my paths are pointing to the right directory in tcpdf_config.php but when I try and run a script on my email.php page, it is displaying the error shown below. I have tried playing around with pointing to the file/s in a number of ways, but to no avail.
When i navigate to the examples given in the TCPDF folder, they load and work fine, so not sure why i cannot get this page work. Any help much appreciated!
i have tcpdf installed in my xampp directory as follows:
C:/xampp/htdocs/projects/ibill_v3/tcpdf
tcpdf_config.php
<?php
//============================================================+
// File name : tcpdf_config.php
// Begin : 2004-06-11
// Last Update : 2014-12-11
//
// Description : Configuration file for TCPDF.
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info#tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
// Copyright (C) 2004-2014 Nicola Asuni - Tecnick.com LTD
//
// This file is part of TCPDF software library.
//
// TCPDF is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// TCPDF is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
//
// See LICENSE.TXT file for more information.
//============================================================+
/**
* Configuration file for TCPDF.
* #author Nicola Asuni
* #package com.tecnick.tcpdf
* #version 4.9.005
* #since 2004-10-27
*/
// IMPORTANT:
// If you define the constant K_TCPDF_EXTERNAL_CONFIG, all the following settings will be ignored.
// If you use the tcpdf_autoconfig.php, then you can overwrite some values here.
/**
* Installation path (/var/www/tcpdf/).
* By default it is automatically calculated but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_MAIN', 'C:/xampp/htdocs/projects/ibill_v3/tcpdf');
/**
* URL path to tcpdf installation folder (http://localhost/tcpdf/).
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_URL', 'C:/xampp/htdocs/projects/ibill_v3/tcpdf');
/**
* Path for PDF fonts.
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
//define ('K_PATH_FONTS', K_PATH_MAIN.'fonts/');
/**
* Default images directory.
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_IMAGES', 'C:/xampp/htdocs/projects/ibill_v3/tcpdf/fonts');
/**
* Deafult image logo used be the default Header() method.
* Please set here your own logo or an empty string to disable it.
*/
//define ('PDF_HEADER_LOGO', '');
/**
* Header logo image width in user units.
*/
//define ('PDF_HEADER_LOGO_WIDTH', 0);
/**
* Cache directory for temporary files (full path).
*/
//define ('K_PATH_CACHE', '/tmp/');
/**
* Generic name for a blank image.
*/
define ('K_BLANK_IMAGE', '_blank.png');
/**
* Page format.
*/
define ('PDF_PAGE_FORMAT', 'A4');
/**
* Page orientation (P=portrait, L=landscape).
*/
define ('PDF_PAGE_ORIENTATION', 'P');
/**
* Document creator.
*/
define ('PDF_CREATOR', 'TCPDF');
/**
* Document author.
*/
define ('PDF_AUTHOR', 'TCPDF');
/**
* Header title.
*/
define ('PDF_HEADER_TITLE', 'TCPDF Example');
/**
* Header description string.
*/
define ('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org");
/**
* Document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch].
*/
define ('PDF_UNIT', 'mm');
/**
* Header margin.
*/
define ('PDF_MARGIN_HEADER', 5);
/**
* Footer margin.
*/
define ('PDF_MARGIN_FOOTER', 10);
/**
* Top margin.
*/
define ('PDF_MARGIN_TOP', 27);
/**
* Bottom margin.
*/
define ('PDF_MARGIN_BOTTOM', 25);
/**
* Left margin.
*/
define ('PDF_MARGIN_LEFT', 15);
/**
* Right margin.
*/
define ('PDF_MARGIN_RIGHT', 15);
/**
* Default main font name.
*/
define ('PDF_FONT_NAME_MAIN', 'helvetica');
/**
* Default main font size.
*/
define ('PDF_FONT_SIZE_MAIN', 10);
/**
* Default data font name.
*/
define ('PDF_FONT_NAME_DATA', 'helvetica');
/**
* Default data font size.
*/
define ('PDF_FONT_SIZE_DATA', 8);
/**
* Default monospaced font name.
*/
define ('PDF_FONT_MONOSPACED', 'courier');
/**
* Ratio used to adjust the conversion of pixels to user units.
*/
define ('PDF_IMAGE_SCALE_RATIO', 1.25);
/**
* Magnification factor for titles.
*/
define('HEAD_MAGNIFICATION', 1.1);
/**
* Height of cell respect font height.
*/
define('K_CELL_HEIGHT_RATIO', 1.25);
/**
* Title magnification respect main font size.
*/
define('K_TITLE_MAGNIFICATION', 1.3);
/**
* Reduction factor for small font.
*/
define('K_SMALL_RATIO', 2/3);
/**
* Set to true to enable the special procedure used to avoid the overlappind of symbols on Thai language.
*/
define('K_THAI_TOPCHARS', true);
/**
* If true allows to call TCPDF methods using HTML syntax
* IMPORTANT: For security reason, disable this feature if you are printing user HTML content.
*/
define('K_TCPDF_CALLS_IN_HTML', false);
/**
* If true and PHP version is greater than 5, then the Error() method throw new exception instead of terminating the execution.
*/
define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
/**
* Default timezone for datetime functions
*/
define('K_TIMEZONE', 'UTC');
//============================================================+
// END OF FILE
//============================================================+
email.php
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
class ashPDF extends TCPDF {
public function Header() {
$this->setJPEGQuality(90);
$this->Image('logo.png', 62, 36, 72, 0, 'PNG', '/projects/ibill_v3/img/ibill logo.png');
}
public function Footer() {
$this->SetY(-15);
$this->SetFont(PDF_FONT_NAME_MAIN, 'I', 8);
$this->Cell(0, 10, 'php.refulz.com – Web Developer’s Blog', 0, false, 'C');
}
}
$pdf = new ashPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// $pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ash PHP');
$pdf->SetTitle('Fisrt PDF Document using TCPDF');
$pdf->SetSubject('ash PDF Example');
$pdf->SetKeywords('ash, TCPDF, PDF');
// add a page
$pdf->AddPage();
$col = 72; // Column size
$wideCol = 3 * $col; // Description Column
$line = 18; // Line height
// Table header
$pdf->SetFont( '', 'b' );
$pdf->Cell( $col, $line, 'S. No.', 1, 0, 'L' );
$pdf->Cell( $wideCol, $line, 'Task', 1, 0, 'L' );
$pdf->Cell( $col, $line, 'Time', 1, 0, 'R' );
$pdf->Ln(); // Adds Line break
// Table content beings here
$pdf->SetFont( '', '' ); // two parameters accept font-family and style. Passing blank sets default values
$counter = 1; // Setting counter for S. No. column
foreach( $this->taskData['items'] as $item ) {
$pdf->Cell( $col, $line, $counter, 1, 0, 'L' );
$pdf->Cell( $wideCol, $line, $item[0], 1, 0, 'L' );
$pdf->Cell( $col, $line, $item[1], 1, 0, 'R' );
$pdf->Ln();
$counter++;
}
// Output the PDF document.
$pdf->Output( 'Tasksheet.pdf', 'D' );
?>
Error Messages when trying to execute email.php:
Warning: require_once(tcpdf/config/lang/eng.php): failed to open stream: No such file or directory in C:\xampp\htdocs\projects\ibill_v3\html\email.php on line 2
Fatal error: require_once(): Failed opening required 'tcpdf/config/lang/eng.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\projects\ibill_v3\html\email.php on line 2
I am trying to integrate a chart into a website. I tested the gd2 installment by trying to see the examples, which works, see here. Then I went ahead and integrate it in my php file, using this code:
include("grafice/class/pData.class.php");
include("grafice/class/pDraw.class.php");
include("grafice/class/pImage.class.php");
//creaza si populeaza obiectul
$MyData = new pData();
$MyData->addPoints(array(4,VOID,VOID,10,8,3),"Proba 1");
$MyData->addPoints(array(3,10,5,8,5,5),"Proba 2");
$MyData->addPoints(array(2,7,5,1,9,2),"Proba 3");
$MyData->setSerieTicks("Proba 2",4);
$MyData->setSerieWeight("Proba 3",2);
$MyData->setAxisName(0,"Note");
$MyData->addPoints(array("Ian","Feb","Mar","Apr","Mai","Iun"),"Labels");
$MyData->setSerieDescription("Labels","Luni");
$MyData->setAbscissa("Labels");
// creaza obiectul chart
$myPicture = new pImage(700,230,$MyData);
//deseneaza fundalul
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings);
// suprapune un gradient
$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
$myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
// bordura
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
// titlul pozei
$myPicture->setFontProperties(array("FontName"=>"fonts/Silkscreen.ttf","FontSize"=>6));
$myPicture->drawText(10,13,"EXEMPLU",array("R"=>255,"G"=>255,"B"=>255));
// titlul graficului
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawText(250,55,"Media Notelor",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
//deseneaza marimea 1
$myPicture->setGraphArea(60,60,450,190);
$myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>10));
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries);
$myPicture->drawScale($scaleSettings);
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->setFontProperties(array("FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6));
$myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO));
$myPicture->setShadow(FALSE);
//deseneaza marimea 2
$myPicture->setGraphArea(500,60,670,190);
$myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE));
$myPicture->setShadow(TRUE,array("X"=>-1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->drawLineChart();
$myPicture->setShadow(FALSE);
// deseneaza legenda
$myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
//rendereaza poza
$myPicture->autoOutput("img/example.drawLineChart.png");
Unfortunately, this renders the whole page like so: (I am uploading a picture since you need an account to see it)
Did I did something wrong? I used this code in a function.
ALSO, in WAMP examples not work. Any way around that?
I managed to do it, and posting here to help others!
so, I made the function, but I edited the BOLD part
function grafice()
{
/* pChart library inclusions */
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pImage.class.php");
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints(array(10,5,7,8), "Probe 1");
$MyData->setSerieWeight("Probe 1",2);
$MyData->setAxisName(0,"Media Generala");
$MyData->addPoints(array("Ian","Feb","Mar","Apr","Mai","Iun"),"Labels");
$MyData->setSerieDescription("Labels","Luni");
$MyData->setAbscissa("Labels");
$serieSettings = array("R"=>255,"G"=>185,"B"=>11);
$MyData->setPalette("Probe 1",$serieSettings);
/* Create the pChart object */
$myPicture = new pImage(500,230,$MyData);
/* Draw the background */
$Settings = array("R"=>248, "G"=>226, "B"=>174, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings);
/* Overlay with a gradient */
$Settings = array("StartR"=>238, "StartG"=>216, "StartB"=>174, "EndR"=>238, "EndG"=>216, "EndB"=>174, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
$myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,499,229,array("R"=>0,"G"=>0,"B"=>0));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));
$myPicture->drawText(10,13,"Evolutia Mediei Generale",array("R"=>255,"G"=>255,"B"=>255));
/* Write the chart title */
$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawText(250,55,"Media Generala",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
/* Draw the scale and the 1st chart */
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>10));
$scaleSettings = array("DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries);
$myPicture->setGraphArea(60,60,450,190);
$myPicture->drawFilledRectangle(60,60,450,190,array("R"=>0,"G"=>0,"B"=>0,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale($scaleSettings);
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>10,"R"=>0,"G"=>0,"B"=>0));
$myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayR"=>0, "DisplayG"=>0, "DisplayB"=>0, "DisplayOffset"=>10));
$myPicture->setShadow(FALSE);
/* Render the picture (choose the best way) */
/* $myPicture->**( I DELETED ThIS)--> autoOutput <---** ("pictures/example.drawLineChart.png"); and added */
$myPicture->render("pictures/example.drawLineChart.png");
}
Then, when I want to call it, like so :
<?php grafice(); ?>
And then I can do:
<img src="pictures/example.drawLineChart.png" />
Now I just change the picture name with the session id, and so I will have a different graph for everyone ;) Hopefully this will help someone!
I'm having an issue with imagick running on a MAMP installation within a cakephp app.
I have followed the install instructions as indicated here and the install seems to have worked in the sense that the class 'Imagick' exists for me if i test it in a php script (I can see the module is loaded in phpinfo). However any examples that I run utilising the class hang as soon as I echo any content. My view is:
<?php
/* Create a new imagick object */
$im = new Imagick();
/* Create new image. This will be used as fill pattern */
$im->newPseudoImage(50, 50, "gradient:red-black");
/* Create imagickdraw object */
$draw = new ImagickDraw();
/* Start a new pattern called "gradient" */
$draw->pushPattern('gradient', 0, 0, 50, 50);
/* Composite the gradient on the pattern */
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);
/* Close the pattern */
$draw->popPattern();
/* Use the pattern called "gradient" as the fill */
$draw->setFillPatternURL('#gradient');
/* Set font size to 52 */
$draw->setFontSize(52);
/* Annotate some text */
$draw->annotation(20, 50, "Hello World!");
/* Create a new canvas object and a white image */
$canvas = new Imagick();
$canvas->newImage(350, 70, "white");
/* Draw the ImagickDraw on to the canvas */
$canvas->drawImage($draw);
/* 1px black border around the image */
$canvas->borderImage('black', 1, 1);
/* Set the format to PNG */
$canvas->setImageFormat('png');
/* Output the image */
header("Content-Type: image/png");
echo $canvas;
?>
This script will just hang as soon as the echo $canvas is encountered. The script works perfectly in a plain old php file i.e outside of cake but it hangs when visited via my cakephp app action. My action code is:
public function test(){
$this->layout = false;
}
Cake error log is empty.
Okay the issue was with how the header was set in cakephp. Cake didn't allow me to set the page header in the view that way.
I added the following code to the test action:
$this->response->type("image/png");
And it works perfectly now.