chriscripps
Posts: 30
|
| Posted: 07/06/2008, 5:34 PM |
|
Hi,
I am working on setting up a page where an editable grid has a button to send the contents of the editable grid to an email recipient. In one script, I duplicated the SQL query used to make the grid and when the button was clicked, the query was made and the results set into the email body and mailed. That seems to work.
I was reading in the forums and came up with a post from Peterr where you declare global $main_block and then echo $main_block ( or put it in an email) in the before output event for the page. I have that working on my page, but since the page is for someone to see and approve prior to emailing, I would like them to push an email button prior to the email being generated. With the before output event, the email is sent and while it is not pretty, it works to show the grid (if I get this working, maybe I will ask about formatting). If I use the OnClick event on the button, it sends only the text portions I put into the email, but $main_block seems to be null. the code I have on the event is this:
global $main_block;
global $Tpl;
global $BlockToParse;
$main_block=$Tpl->getvar($BlockToParse);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host="yourhostname";
$mail->smtpAuth = "true";
$mail->UserName = "YYYYYYYY";
$mail->Password = "XXXXXX";
$mail->From = "email@email.com";
$mail->FromName = "Chris Cripps";
$mail->addaddress("email@email.com");
$mail->Subject = "this is a test";
$mail->Body = $main_block."TT ";
$mail->AltBody = "this is the plain text version";
$mail->WordWrap = 75;
if (!$mail->send())
{
echo 'message not sent';
echo 'mailer error: '.$mail->ErrorInfo;
global $Redirect;
$Redirect= "Sorry.php";
}
else {
$mail->ClearAddresses();
$mail->ClearAttachments();
}
I am having trouble figuring out $main_block. Is it truly set to null upon the output? Is there another way to declare it/get it back? If there is a way to declare it and get it working, is there a way to get style elements to be sent with absolute addresses instead of relative addresses so they look like they do on the webpage in an email?
Thanks,
Chris
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/06/2008, 6:09 PM |
|
Chris
Take a look at how the convert to PDF function in the before output event works.
You could basically build your e-mail function the same way. In other worlds, when convert = something e-mail the $main_block.
I would create it in a custom code event for the before output event. This way you can preview your page then when you click on e-mail, it just calls the page with the url parameter set.
I think that would be the easiest way.
Have fun.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/06/2008, 6:11 PM |
|
Incidentally get rid of this...
$main_block=$Tpl->getvar($BlockToParse);
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/07/2008, 8:04 AM |
|
Hey Chris
I just thought of another way you might do this that should be a little easier that the cloning of the PDF code I suggested earlier.
Try creating a before output event as custom code. In the befeore output custom code put this in there.
global $main_block;
global $mail_block;
$mail_block = $main_block;
Now when your page is displayed $mail_block will be an exact HTML duplicate of the page you have displayed.
As in all cases using $main_block you might have to do some manipulation since $main_block is actually the HTML that CCS displays in the browser for that page. So your $mail_block will also include the HTML for the e-mail button I assume you will have on that page or any other links you have on the page for the pages function. You will need to remove that code from $mail_block unless you want the buttons sent also. You can do that by putting some <div id="xxx"> the Template HTML thet has the buttons etc.</div> and write some code to remove all the code between that div id from the $mail_block string.
After you have done that. your page will display for your user to approve and $mail_block will contain the html for your e-mail body.
Now your on-click event for sending the email would have in it
global $mail_block;
$mail->Body = $mail_block."TT ";
Let me know if this works for you.
Have fun.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/07/2008, 8:20 AM |
|
Another thought.
One thing you might have to consider is that this being server side stuff. When the page is displayed the last suggestion might not work since bothe $main_block and $mail_block are gone by the time the page is displayed. The PDF clone solution will definitely work since that is processed at the server side.
If you do it the second way, as I think about it more, you might have to do all the string manipulation in the before output event and place in into a hidden text field on your form that you can grab as the e-mail body.
As you can tell this issue has intriged me and I am sending you ideas in a sort of stream of unconciousness.
I reviewing all my seemingly disjointed thoughts there are 2 ways to do this.
1. Clone the Convert to PDF code into a custom code for the before output event that would do the modification of the HTML. (You must move $main_block into another string to remove the buttons etc. in the HTML and send that string in your e-mail or your page might not display properly) This custom code then would send the e-mail if the convert paramter is set which would be set by youe e-mail button on the page. (you can name convert to anything that is just the name CCS give it for the PDF convert code).
2.In the same custom code before output event, take $main_Block and move it to anothe string, remove the buttons etc. as in method 1. Then put it into a hidden control on your form. This is tricky because in the before output event your controls (ie $Container->xx) are not defined as global. You will have to add that global declaration for that component in the custom code. Now your on-click event will be able to access and send the content of that hidden field in your e-mail.
Again, let me know if that helps or even works.
Take Care
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
chriscripps
Posts: 30
|
| Posted: 07/07/2008, 3:45 PM |
|
Hi John,
Thanks for all the help so far. It does help my understanding of what is working when and where things get dumped. I have tried the second set of suggestions, and I cannot get it to work, and I think the trouble is with this:
"This is tricky because in the before output event your controls (ie $Container->xx) are not defined as global. You will have to add that global declaration for that component in the custom code."
global $main_block;
global $resultsgrid;
global $mail_block;
$mail_block = $main_block;
$resultsgrid->Hidden1->SetValue($main_block);
I put this code in the before output event, but the hidden block has nothing. I put this code in the custom code on the OnClick event for my button:
global $mail_block;
global $resultsgrid;
$body = $resultsgrid->Hidden1->GetValue();
I changed the hidden block to a text area. I see it as blank. I can put a straight text in there in some later events (Before Show), but cannot seem to get anything in there in the Before Output event.
Where should I be doing the global declaration?
Thanks,
Chris
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/07/2008, 5:08 PM |
|
Chris
The trick is really knowing what object to make global. This can be difficult to figure out. you have to look at the ccs generated code to find out what the object really is. One way is to look an any event your form is using like a before show or something.
You will find the control name specifired as global. instead of using $container-> use that value $somestring->fieldname->
The value you see defined in that code is the one you would make global in your before output code.
I actually think the modified PDF convert method is the easiest but I think it can work either way.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
|