This topic is locked
[SOLVED]

 So close to an answer...

10/22/2010 3:38:11 PM
PHPRunner General questions
J
joker author

Hey gang,
I am trying to send an email to selected users including another email address entered as user input.
I have the button on my list page as follows:

<SPAN class=buttonborder><INPUT class=button onclick="email=prompt('Please enter SSO of user requesting access.',''); var form = $('#frmAdmin1')[0]; form.a.value='email'; form.submit(); return false;" value="Email selected" type=button></SPAN>


On List Page: Before Process I have:

if(@$_REQUEST["a"]=="email"){
if(@$_REQUEST["selection"]){

$body="";

foreach(@$_REQUEST["selection"] as $keyblock){

$arr=split("&",refine($keyblock));

if(count($arr)<1)

continue;

$keys=array();

$keys["ID"]=urldecode(@$arr[0]);

$where = KeyWhere($keys);

$rs = CustomQuery("select * from data where $where");

$data=db_fetch_array($rs);

}

// if error happened print a message on the web page

if (!$arr["mailed"]){

echo "Error happened:
";

echo "File: " . $arr["errors"][0]["file"] . "
";

echo "Line: " . $arr["errors"][0]["line"] . "
";

echo "Description: " . $arr["errors"][0]["description"] . "
";

}

}

}


And on Before Record Deleted I have:

global $dal;
//delete records

if(@$_POST["a"]=="delete")

return true;
//send emails

if(@$_POST["a"]=="email"){

// send the email

$email=$deleted_values["SSO"]."@mail.com";

$email.= ";".$_POST["a"]."@mail.com";

$subject="SHARED FOLDER ACCESS REQUEST";

$body = "Good Afternoon,"."\r\n";

$body.= "<BR>";

$body.= "You have been identified as the owner of the following folder:"."\r\n";

$body.= "<BR>";

$body.= $deleted_values["Path"]."\r\n";

$body.= "<BR>";

$body.= "In which the person CC'd on this email has requested READ/WRITE ACCESS."."\r\n";

$body.= "<BR>";

$body.= "Please reply simply to this email with either the word APPROVED or REJECTED."."\r\n";

$body.= "<BR>";

$body.= "<BR>";

$body.= "<BR>";

$body.= "Regards and Thanks for your time,"."\r\n";

$body.= "<BR>";

$body.= "Your IT Team"."\r\n";

$from = "test@test.com";

$arr = runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $body, 'from'=>$from));

}

return false;


The popup works but nothing happens, no email. HELP PLEASE!!!
Thanks guys,
Steve

K
karmacomposer 10/22/2010

Is your server or hosting server set up to properly send email. Do you have the email php or cgi scripts in the right place?
Mike

J
joker author 10/22/2010



Is your server or hosting server set up to properly send email. Do you have the email php or cgi scripts in the right place?
Mike


Email works OK when I'm not trying to get the POST variable from the popup. There's a problem somewhere in getting the variable, I just don't know what it is.
UPDATE
It is sending email, just not to the SSO from user input prompt. Grrr!

J
joker author 10/23/2010

For some reason the email being sent is email@mail.com
My code is not passing the variable from the popup, it's using the name of the variable (email).
Can anyone see a problem in my code? All suggestions are welcome.
Thanks guys,
Steve

Sergey Kornilov admin 10/23/2010

Steve,
as far as I can see you save the result of prompt() in Javascript variable email however you don't pass this variable anywhere.
Here is what you need to do.

  1. In HTML code add a new hidden field to the form named 'b'. i.e.

    <input type="hidden" name="b" value="">
  2. In Javascript code assign the value of email to form field b before submitting the form
    <SPAN class=buttonborder><INPUT class=button onclick="email=prompt('Please enter SSO of user requesting access.',''); var form = $('#frmAdmin1')[0]; form.a.value='email'; form.b.value = email; form.submit(); return false;" value="Email selected" type=button></SPAN>


3. In BeforeDelete code use the following:

$email.= ";".$_POST["b"]."@mail.com";
J
joker author 10/25/2010



Steve,
as far as I can see you save the result of prompt() in Javascript variable email however you don't pass this variable anywhere.
Here is what you need to do.

  1. In HTML code add a new hidden field to the form named 'b'. i.e.

    <input type="hidden" name="b" value="">
  2. In Javascript code assign the value of email to form field b before submitting the form
  3. In BeforeDelete code use the following:

$email.= ";".$_POST["b"]."@mail.com";




I followed your directions but now I'm not getting any emails or error messages. In step 1 you say to add a new hidden field to the form, but I don't really have a form, it's just a javascript pop-up box. And also I was wondering if I should remove the code in List Page: Before Process or do I still need that?
Thank you for all of your help

Sergey Kornilov admin 10/25/2010

Your BeforeProcess code is not doing anything at all - you can remove it.
New field needs to be added to the list page form.

J
joker author 10/25/2010



Your BeforeProcess code is not doing anything at all - you can remove it.
New field needs to be added to the list page form.


I have added the new field "b" (<input type="hidden" name="b" value="">) into the list page.
When I add the value.b.form part to the javascript, it refuses to submit. The page submits if I take it out.
Any thoughts?

Sergey Kornilov admin 10/25/2010

'It refuses to submit' is not that descriptive. Post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

J
joker author 11/2/2010

With the help of Jane and team I have figured out the solution. Hope this helps anybody else as well.
The problem was that I needed to email selected rows with their own unique data but also email variables from a user input form. What I ended up doing was this:

  1. Add Button to Main Page**
    I added this code to the main page for my Popup user input form:

<SPAN class=buttonborder><INPUT class=button onclick="var form = $('#frmAdmin1')[0]; form.a.value='email'; return openwin(form);" value="Email selected" type=button></SPAN>




2. Create New View / Modify Add Page

I created a new view called EMAIL and modified the ADD form to include my three user input fields and a submit button:

<TBODY>

<TR>

<TD height=60 width=183>

<DIV align=center>Enter SSO of user requesting access </DIV>

<TD width=201><INPUT maxLength=9 name=requestoremail> </TD>

<TR>

<TD height=60 width=183>

<DIV align=center>Enter ticket number </DIV>

<TD width=201><INPUT name=ticketno> </TD>

<TR>

<TD height=107>

<DIV align=center>Select the type of access

needed.<BR><BR></DIV>

<TD>

<P><INPUT value="Read Only" CHECKED type=radio

name=typeaccess>Read Only Access</P>

<P><INPUT value="Read Write" type=radio

name=typeaccess>Read/Write Access</P></TD></TR></TBODY></TABLE>

<DIV id="buttons_block{$id}" class=blackshade2>

{BEGIN legend}<DIV id="required_block{$id}"><IMG alt=bullet

src="images/icon_required.gif"> - Required field</DIV>{END legend}{$legendBreak} <SPAN

class=buttonborder><INPUT class=button onclick=top.close(); value=Email type=submit name=submit1></SPAN>




3. Add Javascript file

Using Jane's example I modified the following Javascript and included it in a file called "Customfile.js" located in the INCLUDE folder

//define preWin function

var prevWin = null;

function openwin(oForm){

if (prevWin && !prevWin.closed)

prevWin.close();

prevWin = window.open('', 'prevWin', 'left=200,top=200,width=500,height=400,status=0');

oForm.target = 'prevWin';

oForm.action = 'email_add.php';

oForm.submit();

if (prevWin && !prevWin.closed)

prevWin.focus();

return true;

}




4. Include Javascript file

I included the Javascript file by posting this line right before the {BEGIN body} tags:

<script type=text/javascript src="include/customfile.js"></SCRIPT>




5. Create Event to Handle Email

I created a new event on the ADD PAGE: BEFORE PROCESS to handle the email functions after the submit button was hit:

if(isset($_POST['submit1'])){

$rstmp = CustomQuery($_SESSION["sql"]);

while ($datatmp = db_fetch_array($rstmp)){

$email1=$datatmp["SSO"]."@mail.com";

$email2=$_POST["requestoremail"]."@mail.com";

$email="$email1,$email2";

$subject="SHARED FOLDER ACCESS REQUEST - ".$_POST["ticketno"];

$body = "Good Afternoon ".$datatmp["FirstName"].","."\r\n";

$body.= "\r\n";

$body.= "You have been identified as the owner of a group in the following shared folder:"."\r\n";

$body.= "\r\n";

$body.= "Please reply simply to this email with either the word APPROVED or REJECTED."."\r\n";

$body.= "\r\n";

$body.= "\r\n";

$body.= "Thanks for your time,"."\r\n";

$body.= "\r\n";

$body.= "The Administration Team"."\r\n";

$from="adminteam@company.com";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $body, 'from'=>$from));

if(!$ret["mailed"]){

echo $ret["message"]."
";

}

}
$_SESSION["sql"] = "";

echo "<p><a href='javascript:window.close();'>Close window</a></p>";

exit();

}else{

$sql = "select ID,Path,SSO,FirstName,SrvName,GrpName from data where ID in (";

for ($i=0;$i<count($_REQUEST["selection"]);$i++ )

$sql.=$_REQUEST["selection"][$i].",";

$sql = substr($sql,0,-1);

$sql.=")";

$_SESSION["sql"] = $sql;

}



Big thanks go out to Jane and the PHPRunner team for taking the time to answer all my questions!
-Steve