This topic is locked

button to call a php file outside PHPRunner

12/22/2008 9:00:43 AM
PHPRunner General questions
S
shoppy author

Hi all,
I want to have a button to open a php file outside PHPRunner.
Can anybody tell me how t do that?
thanks a million
John

J
Jane 12/22/2008

Hi,
to add button use custom event (Insert PHP code snippet option on the Visual Editor tab).

You can point your button to any page you want.

S
shoppy author 12/22/2008

Hi Jane (and Sergey),
This is what I want.

Every morning a script sends 'reminders' to an emailadress that forwards the emails to different people.
I now want a button on the _kandidaten_list.php page that sends the 'reminders' to the person that is the loged in USER (after he clickes it).
This is the script I use to send the reminders:
[codebox]<?php
$server = 'XXXX';

$gebruiker = 'xxxx';

$wachtwoord = 'xxxx';

$database = 'xxx';
//$ontvangerEmail = 'adkompleet@synoptico.nl';

$ontvangerEmail = $_SESSION["Email"];
if (mysql_connect($server,$gebruiker,$wachtwoord)) {

if (mysql_select_db($database)) {

$query = "SELECT Kandidaatnummer, Kandidaatvoornaam, Kandidaatvoortgang, KandidaatVakgebied, Reminder FROM `_kandidaten` WHERE Reminder <= NOW()";

$result = mysql_query ($query);
if ($result && mysql_num_rows($result) > 0){

// De class invoegen in het huidige bestand

require ('mail.class.php');
while($row = mysql_fetch_assoc($result)) {

// Een email object aanmaken.

// Door het object te koppelen aan een variabele (in dit geval $email) kun je er iets mee doen.

$email = new email ('mailform.php');
// De SMTP server opgeven

$email->setMailServer ('localhost');
// $email->setSubject ('Reminder: ' . $row['Kandidaatnummer'] . ' - Vakgebied: ' . $row['KandidaatVakgebied']);

$email->setSubject (' ' . $row['Kandidaatnummer'] . ' - ' . $row['KandidaatVakgebied']. ' - '. $row['Kandidaatvoornaam']);
// Het lastige deel: de dynamische content definieren

// Als je 'mailform.php' er bij pakt en je verstuurt even een mail naar jezelf zal het denk ik duidelijk zijn

// Je kunt hier uiteraard zo nog een paar regels bij zetten. Dat gaat gewoon goed!

$email->dynamicContent ('[[Reminder]]', $row['Reminder']);

$email->dynamicContent ('[[KandidaatVakgebied]]', $row['KandidaatVakgebied']);

$email->dynamicContent ('[[Kandidaatvoornaam]]', $row['Kandidaatvoornaam']);

$email->dynamicContent ('[[Kandidaatvoortgang]]', nl2br($row['Kandidaatvoortgang']));

// Als laatst versturen we de email. Het eerste adres is van de afzender, het tweede de ontvanger.

// Een check lijkt mij hier ook wel op zijn plaats!

if ($email->sendMail ('reminder@synoptico.nl', $ontvangerEmail)) {

echo "Verstuurd ";

} else {

echo "Fout ";

}

}

}else{

echo '<p>Sorry, ik heb geen kandidaten gevonden!</p>';

}

}else{

echo '<p>Sorry, ik kon geen verbinding maken met de databasetabel!</p>';

}

}else{

echo '<p>Sorry, ik kon geen verbinding maken met de databaseserver!</p>';

}

?>[/codebox]
there are two scripts that are being called: mail.class.php and mailform.php
This script works but I realy want to implant it in a button so it only sends the reminders to the current User.
mail.class.php

[codebox]<?php
class email {
function email ($mailForm = NULL) {

if (strlen ($mailForm) > 0) {

if (file_exists ($mailForm)) {

$this->mailForm = $mailForm;

$this->check['mailForm'] = true;

} else {

$this->check['mailForm'] = false;

die ("Het email formulier bestaat niet.");

}

} else {

$this->check['mailForm'] = false;

die ("Er is geen locatie voor het email formulier opgegeven.");

}

}
function setMailServer ($mailServer = NULL) {

if (strlen ($mailServer) > 0) {

if (ini_set ('SMTP', $mailServer)) {

$this->check['mailServer'] = true;

} else {

$this->check['mailServer'] = false;

die ("Mailserver kan niet ingesteld worden.");

}

} else {

$this->check['mailServer'] = false;

die ("Geen mailserver adres opgegeven.");

}

}
function setSubject ($subject = NULL) {

if (strlen ($subject) > 0) {

$this->subject = $subject;

if ($this->subject == $subject) {

$this->check['subject'] = true;

} else {

$this->check['subject'] = false;

die ("Er is een fout opgetreden! (" . FUNCTION . ")");

}

} else {

$this->check['subject'] = false;

die ("Er is geen onderwerp voor de email opgegeven.");

}

}
function dynamicContent ($search = NULL, $replace = NULL) {

if (strlen ($search) > 0 && strlen ($replace) > 0) {

$this->dynamicContent[] = array ('search'=>$search, 'replace'=>$replace);

$this->check['dynamicContent'] = true;

} else {

$this->check['dynamicContent'] = false;

die ("Dynamische content is niet gedefinieerd.");

}

}
function sendMail ($frommail = NULL, $tomail = NULL) {

if (strlen ($frommail) > 0 && strlen ($tomail) > 0) {

if ($this->check['mailForm'] && $this->check['subject']) {

$html = implode('', file($this->mailForm));

if (isset ($this->dynamicContent) && $this->check['dynamicContent']) {

foreach ($this->dynamicContent as $content) {

$html = str_replace ($content['search'], $content['replace'], $html);

}

}

if ( @mail($tomail, $this->subject, "$html" , "FROM:$frommail\r\nContent-type: text/html; charset=iso-8859-1\r\nReply-To:$frommail")) {

return true;

} else {

return false;

}

} else {

die ("Er is een fout opgetreden. (" . FUNCTION . ")");

}

} else {

return false;

}

}

}
?>[/codebox]
mailform.php

[codebox]<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td>Beste Collega,</td>

</tr>

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td>Er staat nog een reminder open voor [[Reminder]] </td>

</tr>

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td>[[KandidaatVakgebied]] - [[Kandidaatvoornaam]]</td>

</tr>

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td>[[Kandidaatvoortgang]]</td>

</tr>

</table>

[/codebox]
I hope you can helpme.
John

J
Jane 12/23/2008

Hi,
just point your button to your script and pass username of logged user in the URL.

S
shoppy author 12/23/2008

Hi,

just point your button to your script and pass username of logged user in the URL.


The url = http://myownwebsite/name/sendreminders.ph
Can you give me an example of the proper code for this type of button and what to place in the url?
John

J
Jane 12/23/2008

Hi,
here is just a sample:

echo "<input type=button class=button value=\"Button 1\" onclick=\"window.location.href='sendreminders.php?username=".$_SESSION["UserID"]."';\">";

S
shoppy author 12/23/2008

Hi,

here is just a sample:


Sorry Jane,
The script dos not find the proper emailadres from UserID

What do I need to change in the script so that it finds it?
I thought $ontvangerEmail = $_SESSION["Email"]; would do the trick but it doesn't.
John