Well I have been try out what you were doing, and getting not so far... so I tried something else as well... as a test I put the script that I was working on in the UDT which dose work in the sense that it mails and saves that PDF... then attached it to the Event Handler OnUpdateUser.... So the way I figured it with the test code that works (it has the data that will be passed static in the UDT) I should just run through the action as the event pops off.... right?? so I think I'm doing something not right in the UDT, like I shouldn't just copy a working php script over??? Any help here would be great... once this works then I make the bend of what you did with what I need, where i just print the ChangeSettings form to pdf and save/mail it ... at least that’s the thought...
Code: Select all
require("../Core_files/PDFgenerator/tcpdf_php4/class.phpmailer.php");
require_once('../Core_files/PDFgenerator/tcpdf_php4/config/lang/eng.php');
require_once('../Core_files/PDFgenerator/tcpdf_php4/tcpdf.php');
function splitData(array $a_Data)
{
// We need to track levels so use a static variable.
static $i_Level = 0;
// We are in a new level.
++$i_Level;
// This levels results start life as an empty array.
$a_Results = array();
// Iterate the supplied data to this level.
foreach($a_Data as $s_Entry)
{
// Different levels have different formatting.
switch($i_Level)
{
// Level 1 is {name:value} (even if value is an array).
case 1 :
$s_Entry = substr($s_Entry, 1, -1);
$i_SplitPos = strpos($s_Entry, ':');
$s_Key = substr($s_Entry, 0, $i_SplitPos);
$s_Value = substr($s_Entry, 1 + $i_SplitPos);
break;
// Level 2 is where value is {name|value},{name|value},{name|value},{name|value}
case 2 :
$a_Results[] = splitData(explode(',', $s_Entry));
break;
// Level 3 is name|value
case 3:
list($s_Key, $s_Value) = explode('|', $s_Entry);
break;
}
// If the value starts with a { it needs further refinement so call this function recursively.
if (isset($s_Value) && (strlen($s_Value) > 0) && ('{' === $s_Value{0}))
{
$a_Results[$s_Key] = splitData(preg_split('`(?:}),(?:{)`', substr($s_Value, 1, -1)));
}
else
{
// Level 2 is not data generating.
if (2 !== $i_Level)
{
// Store the results.
$a_Results[$s_Key] = $s_Value;
}
}
}
// We have finished with this level.
--$i_Level;
// Return the results for this level.
return $a_Results;
}
function dataToPDF($PDF, array $a_Data, array $a_Keys = array())
{
// We need to track levels so use a static variable.
static $i_Level = 0;
// We are in a new level.
++$i_Level;
// Iterate the supplied data array.
foreach($a_Data as $s_Key => $m_Values)
{
// If the data is an array then call this function recursively.
if (is_array($m_Values))
{
// Store the current key at the current level.
$a_Keys[$i_Level] = $s_Key;
// Call this function recursively with the PDF object we received,
// the array of values and the accumulated keys.
dataToPDF($PDF, $m_Values, $a_Keys);
}
else
{
// Remove any accumulated keys for this level
unset($a_Keys[$i_Level]);
// Generate a parameter array containing any supplied keys,
// the current key and the current value.
$a_Params = $a_Keys;
$a_Params[] = $s_Key;
$a_Params[] = $m_Values;
// Call the PDF object to add a MultiRow with the array of parameters.
call_user_func_array(array($PDF, 'MultiRow'), $a_Params);
}
}
// We have finished with this level.
--$i_Level;
}
// Prepare the data.
// This would normally come in from your flash.
$_POST["dataArray"] = '{name:value},{Applacation Date:Mon Jun 23 17:36:26 GMT-0700 2008},{emps_grd:{row|0,employer|asdfasdf,address|asdfasdf,phone|asdf,supervisor|asdf,contact|false,wage|,duties|,from|Mon Jun 2 00:00:00 GMT-0700 2008,to|,reason|},{row|1,employer|new Employee,address|asdfasdf,phone|,supervisor|asdfadf,contact|false,wage|asdfasdf,duties|,from|Tue Jun 3 00:00:00 GMT-0700 2008,to|Thu Jun 19 00:00:00 GMT-0700 2008,reason|}},{jobs_picks:{Job_Pick`0|CNA - MEDICAL UNIT},{Job_Pick`1|Unit Secretary / CNA Mental Health Center},{Job_Pick`2|CREDIT COUNSELOR},{Job_Pick`3|UNIT SECRETARY - ICU/PCU},{Job_Pick`4|CNA - SURGICAL UNIT},{Job_Pick`5|CNA - SURGICAL UNIT}},{name_title:Mr},{urstate:Choose},{primphonetype:Choose},{altphonetype:Choose},{emerg_contype:Choose},{days:3rd},{evenings:1st},{nights:2nd},{high_school_from:Mon Jun 9 00:00:00 GMT-0700 2008},{high_school_to:Tue Jun 17 00:00:00 GMT-0700 2008},{high_school_when:undefined},{prev_emplofrom:undefined},{prev_emploto:undefined},{skill_medterm_date:undefined},{college_from:undefined},{college_to:undefined},{college_when:undefined},{college2_from:Tue Jun 10 00:00:00 GMT-0700 2008},{college2_to:Tue Jun 17 00:00:00 GMT-0700 2008},{college2_when:Thu Jun 19 00:00:00 GMT-0700 2008},{college3_from:undefined},{college3_to:undefined},{college3_when:undefined},{college4_from:undefined},{college4_to:undefined},{college4_when:undefined},{current_ed_completdate:undefined},{license_xdate:undefined},{license2_xdate:undefined},{em_data_rec_brith:undefined},{lastname:Dude},{firstname:Man},{middlename:Hit},{suffix:sr},{ssn:5946565632},{street:},{city:},{zip:},{primphone:},{altphone:},{email:},{emerg_con:},{emerg_connumber:},{learnabout_job_othertxt:},{relative_name:},{relative_rela:},{undefined:undefined},{undefined:undefined},{undefined:undefined},{undefined:undefined},{high_school_name:},{high_school_loca:},{college_name:},{college_loca:},{college2_name:},{college2_loca:},{college3_name:},{college3_loca:},{college4_name:},{college4_loca:},{college_major:},{college2_major:},{college3_major:},{college4_major:},{current_ed_name:},{current_ed_loca:},{current_ed_study:},{license_type:},{license_number:},{license_state:},{license2_type:},{license2_number:},{license2_state:},{skill_typn_wpm:},{skill_medterm_school:},{skill_monitors_type:},{leg_othername_1:},{leg_othername_2:},{leg_othername_3:},{leg_othername_4:},{leg_able_work_note:},{leg_convic_note:},{undefined:undefined},{undefined:undefined},{em_data_rec_notes:},{digitalsign:},{full_time:yes},{part_time:Yes},{temp:},{on_call:Yes},{avaiable_mon:},{avaiable_tus:},{avaiable_wed:Yes},{avaiable_thru:Yes},{avaiable_fri:},{avaiable_sat:},{avaiable_sun:Yes},{ssnoptout:},{learnabout_job_ad:},{learnabout_job_friend:},{learnabout_job_other:},{skill_typn:},{skill_dataentry:},{skill_medterm:},{skill_medtrans:Yes},{skill_accounting:Yes},{skill_insure_bill:Yes},{skill_credit_collect:Yes},{skill_switchborad:},{skill_cashier:},{skill_10key:Yes},{skill_invoicing:},{skill_reception:Yes},{skill_floorcare_man:},{skill_floorcare_mac:},{skill_dishman:},{skill_dishindus:},{skill_linen:},{skill_sterilizer:},{skill_autoclave:},{skill_sewing:},{skill_maintengen:},{skill_maintencraft:},{skill_maintencraft_el:Yes},{skill_maintencraft_pl:Yes},{skill_maintencraft_co:Yes},{skill_maintencraft_pt:Yes},{skill_steriletechique:},{skill_vitalsigns:},{skill_charting:},{skill_pre_opprep:},{skill_isolation:},{skill_cateterization:},{skill_coronarycare:},{skill_intensive:},{skill_monitors:},{skill_orthopedic:},{skill_pediatic:},{skill_obstertrics:},{skill_medical:},{skill_surgical:},{skill_geriatric:},{skill_oncology:},{skill_family_homecare:},{em_data_rec_w:},{em_data_rec_b:},{em_data_rec_h:},{em_data_rec_a:},{em_data_rec_a_i:},{em_data_rec_v:},{em_data_rec_d:},{em_data_rec_di:},{appstate_cb:},{drugtest:},{digital_agree:},{Em_HIS_Con_Y:Yes},{rotate_shifts_N:No},{weekends_Y:Yes},{relativeemplo_N:},{high_school_did_atend_N:No},{college_did_atend_Y:Yes},{college2_did_atend_Y:Yes},{college3_did_atend_N:},{college4_did_atend_N:},{current_ed_N:},{licensed_N:},{app4license_N:},{leg_othername_N:},{leg_able_work_N:},{leg_visa_N:},{em_data_rec_sex_M:},{leg_convic_N:},{_18_N:},{prev_emplo_N:}';
// Convert the long string into an array.
preg_match_all( '`({[^{},]*?:{.*?}}|{[^{},]*?:.*?})`sim', $_POST['dataArray'], $a_Matches);
// Convert the simple array into a nested array.
$a_Data = splitData($a_Matches[1]);
// Remove any log file.
@unlink('./debug.log');
// DEBUG : Uncomment the next line to create a debug log file.
file_put_contents('./debug.log', var_export($a_Data, True) . PHP_EOL, FILE_APPEND);
// extend TCPF with custom functions
class MYPDF extends TCPDF {
function MultiRow($left, $right) {
//MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0)
$a_Params = func_get_args();
// DEBUG : Uncomment the next line to create a debug log file.
//file_put_contents('./debug.log', implode(' | ', $a_Params) . PHP_EOL, FILE_APPEND);
$page_start = $this->getPage();
$y_start = $this->GetY();
// write the left cell
$this->MultiCell(40, 0, $left, 1, 'R', 0, 2, 0 ,0, true, 0);
$page_end_1 = $this->getPage();
$y_end_1 = $this->GetY();
$this->setPage($page_start);
// write the right cell
$this->MultiCell(0, 0, $right, 1, 'J', 0, 1, $this->GetX() ,$y_start, true, 0);
$page_end_2 = $this->getPage();
$y_end_2 = $this->GetY();
// set the new row position by case
if (max($page_end_1,$page_end_2) == $page_start) {
$ynew = max($y_end_1, $y_end_2);
} elseif ($page_end_1 == $page_end_2) {
$ynew = max($y_end_1, $y_end_2);
} elseif ($page_end_1 > $page_end_2) {
$ynew = $y_end_1;
} else {
$ynew = $y_end_2;
}
$this->setPage(max($page_end_1,$page_end_2));
$this->SetXY($this->GetX(),$ynew);
$htmlcontent = $a_Params;
$this->writeHTML($htmlcontent, true, 0, true, 0);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
$pdf->SetProtection(array('print'));
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor("Nicola Asuni");
$pdf->SetTitle("TCPDF Example 011");
$pdf->SetSubject("TCPDF Tutorial");
$pdf->SetKeywords("TCPDF, PDF, example, test, guide");
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
//initialize document
$pdf->AliasNbPages();
// add a page
$pdf->AddPage();
// ---------------------------------------------------------
// set font
$pdf->SetFont("vera", "", 12);
//Column titles
$header=array('something','Capital');
dataToPDF($pdf, $a_Data);
//dataToPDF($htmlcontent, $a_Data);
// set font
$pdf->SetFont("dejavusans", "", 9);
// create some HTML content
//$htmlcontent = $a_Data;
// output the HTML content
//$pdf->writeHTML($htmlcontent, true, 0, true, 0);
// reset pointer to the last page
$pdf->lastPage();
////////////////////////////////
/////////EMAIL AREA
//////////////////////////////
// create your pdf file. maybe give it a unique filename.
$filename = "example_011.pdf";
// use for Upload folder >>>>>>>>>>>>>>>>>
$pdf->Output("/home/content/*/html/Core/uploads/apps/" . $filename,"F");
$pdf->Output($filename, "F");
$mail = new PHPMailer();
$mail->MsgHTML($body);
$mail->AddAddress("dbjeremy@cableone.net", "John Doe");
$mail->From = "*@sjrmc.org";
$mail->FromName = 'SJRMC Personnel Department';
$mail->Subject = 'Employment Application CC';
$mail->Body = 'Thank you for submiting your application. REPLACE TEXT';
if(!$mail->AddAttachment("example_011.pdf")) {
echo "There was a problem attaching the pdf.";
echo $mailer->ErrorInfo;
}
$dataResponse_1 = "passed";
if(!$mail->Send()) {
print("&response=error");
} else {
print("&response=passed");
}