Setting a users vacation message through the api

natterjacks

Verified User
Joined
Apr 26, 2006
Messages
17
I've been busy working on this today and figured that others may benefit from what I've done.
I've written some php using l0rdphi1's php class (nice one btw!!) to log in an email user and allow them to set their own vacation message.
It's still a work in progress and needs the modification / delete sections added, but you'll get the jist.

I hope this helps!!

The HTML Logon Form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Verify Users Email Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><center><br><br>
<form action="login.php" method="post">
<table width="70%" border="0">
<tr>
<td width="21%">Full Email Address:</td>
<td width="54%"><input name="email" type="text" size="64" maxlength="64"></td>
<td width="25%">(e.g. [email protected]) </td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="passwd"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Login"></td>
<td> </td>
</tr>
</table>
</form>
</center>
</body>
</html>
 
The login.php:

<?php

session_start();

// Setting variables for this script only
$email = $_POST["email"];
$passwd = $_POST["passwd"];

// Beginning API call
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://domain.com',2222);
$sock->set_login('username','password');

$sock->set_method('POST');

// Authenticate User
$sock->query('/CMD_API_EMAIL_AUTH',

array(

'email' => $email,
'passwd' => $passwd,

));

$result = $sock->fetch_parsed_body();

if ($result["error"] == 1) {
echo "<br><br><center>";
echo "Invalid Email Address or Password<br><br>";
echo "Click <a href=\"login.html\">here </a>to return to the login screen<br></center>";
die();

} else {

// Setting Session wide variables for further scripts
$_SESSION['email'] = $_POST['email'];

$domain = "@niandj.com";
$_SESSION['user'] = str_replace($domain, "", $_SESSION['email']);

}

// Checking to see if a Vacation message already exists
$sock = new HTTPSocket;

$sock->connect('ssl://domain.com',2222);
$sock->set_login('username','password');

$sock->set_method('POST');


$sock->query('/CMD_API_EMAIL_VACATION_MODIFY',

array(

'domain' => 'domain.com',
'user' => $_SESSION['user'],
));

$result = $sock->fetch_parsed_body();

// If the vacation text is returned as null then we prompt the user to create a new message using the form displayed
if ($result["text"] == "") {

echo "<center><br><br>You do not have a Vacation Message, please enter your new message below<br><br><br></center>";

// Otherwise they are prompted to modify their existing message
} else {

echo "<center><br><br>Click <a href=\"modifyedit.php\">here</a> to modify your existing Vacation Message</center>";
die();

}

?>

<html>
<HEAD>
<title>Vacation Entry</title>
</HEAD>
<body>
<br><br>
<table class=list cellpadding=3 cellspacing=1>
<form name=info action="submitvacation.php" method="post">
<tr><td class=list>Email Account: </td><td><?PHP print_r($email); ?></td></tr>
<tr><td class=list>Vacation Message:</td><td class=list align=center><textarea rows=15 cols=60 name=text></textarea></td></tr>
<tr><td class=list>Vacation Start: </td><td class=list>
<select class=selectclass name=starttime>
<option value="morning">Morning</option >
<option value="afternoon">Afternoon</option >
<option value="evening">Evening</option >
</select >
of
<select class=selectclass name=startmonth>
<option selected value="01">Jan</option >
<option value="02">Feb</option >
<option value="03">Mar</option >
<option value="04">Apr</option >
<option value="05">May</option >
<option value="06">Jun</option >
<option value="07">Jul</option >
<option value="08">Aug</option >
<option value="09">Sep</option >
<option value="10">Oct</option >
<option value="11">Nov</option >
<option value="12">Dec</option >
</select >
<select class=selectclass name=startday>
<option selected value="01">01</option >
<option value="02">02</option >
<option value="03">03</option >
<option value="04">04</option >
<option value="05">05</option >
<option value="06">06</option >
<option value="07">07</option >
<option value="08">08</option >
<option value="09">09</option >
<option value="10">10</option >
<option value="11">11</option >
<option value="12">12</option >
<option value="13">13</option >
<option value="14">14</option >
<option value="15">15</option >
<option value="16">16</option >
<option value="17">17</option >
<option value="18">18</option >
<option value="19">19</option >
<option value="20">20</option >
<option value="21">21</option >
<option value="22">22</option >
<option value="23">23</option >
<option value="24">24</option >
<option value="25">25</option >
<option value="26">26</option >
<option value="27">27</option >
<option value="28">28</option >
<option value="29">29</option >
<option value="30">30</option >
<option value="31">31</option >
</select >
<select class=selectclass name=startyear>
<option value="2002">2002</option >
<option value="2003">2003</option >
<option value="2004">2004</option >
<option value="2005">2005</option >
<option selected value="2006">2006</option >
<option value="2007">2007</option >
<option value="2008">2008</option >
<option value="2009">2009</option >
<option value="2010">2010</option >
<option value="2011">2011</option >
<option value="2012">2012</option >
<option value="2013">2013</option >
<option value="2014">2014</option >
<option value="2015">2015</option >
<option value="2016">2016</option >
<option value="2017">2017</option >
<option value="2018">2018</option >
<option value="2019">2019</option >
<option value="2020">2020</option >
<option value="2021">2021</option >
<option value="2022">2022</option >
<option value="2023">2023</option >
<option value="2024">2024</option >
<option value="2025">2025</option >
<option value="2026">2026</option >
<option value="2027">2027</option >
<option value="2028">2028</option >
<option value="2029">2029</option >
</select >
</td></tr>
<tr><td class=list>Vacation End:</td><td class=list>
<select class=selectclass name=endtime>
<option value="morning">Morning</option >
<option selected value="afternoon">Afternoon</option >
<option value="evening">Evening</option >
</select >
of
<select class=selectclass name=endmonth>
<option selected value="01">Jan</option >
<option value="02">Feb</option >
<option value="03">Mar</option >
<option value="04">Apr</option >
<option value="05">May</option >
<option value="06">Jun</option >
<option value="07">Jul</option >
<option value="08">Aug</option >
<option value="09">Sep</option >
<option value="10">Oct</option >
<option value="11">Nov</option >
<option value="12">Dec</option >
</select >
<select class=selectclass name=endday>
<option selected value="01">01</option >
<option value="02">02</option >
<option value="03">03</option >
<option value="04">04</option >
<option value="05">05</option >
<option value="06">06</option >
<option value="07">07</option >
<option value="08">08</option >
<option value="09">09</option >
<option value="10">10</option >
<option value="11">11</option >
<option value="12">12</option >
<option value="13">13</option >
<option value="14">14</option >
<option value="15">15</option >
<option value="16">16</option >
<option value="17">17</option >
<option value="18">18</option >
<option value="19">19</option >
<option value="20">20</option >
<option value="21">21</option >
<option value="22">22</option >
<option value="23">23</option >
<option value="24">24</option >
<option value="25">25</option >
<option value="26">26</option >
<option value="27">27</option >
<option value="28">28</option >
<option value="29">29</option >
<option value="30">30</option >
<option value="31">31</option >
</select >
<select class=selectclass name=endyear>
<option value="2002">2002</option >
<option value="2003">2003</option >
<option value="2004">2004</option >
<option value="2005">2005</option >
<option selected value="2006">2006</option >
<option value="2007">2007</option >
<option value="2008">2008</option >
<option value="2009">2009</option >
<option value="2010">2010</option >
<option value="2011">2011</option >
<option value="2012">2012</option >
<option value="2013">2013</option >
<option value="2014">2014</option >
<option value="2015">2015</option >
<option value="2016">2016</option >
<option value="2017">2017</option >
<option value="2018">2018</option >
<option value="2019">2019</option >
<option value="2020">2020</option >
<option value="2021">2021</option >
<option value="2022">2022</option >
<option value="2023">2023</option >
<option value="2024">2024</option >
<option value="2025">2025</option >
<option value="2026">2026</option >
<option value="2027">2027</option >
<option value="2028">2028</option >
<option value="2029">2029</option >
</select ></td></tr>

<tr><td class=listtitle colspan=3 align=right>

<input type=submit name=create value="Create">
</td></tr>
</form>
</table>
</body>
</html>
 
and the submitvacation.php:

<?php

session_start();

if ($result["error"] == 1) {
die("You are not authorized, please login first");

} else {

// Setting Session Wide Variables
$_SESSION['text'] = stripslashes($_POST['text']);
$_SESSION['starttime'] = $_POST['starttime'];
$_SESSION['startmonth'] = $_POST['startmonth'];
$_SESSION['startday'] = $_POST['startday'];
$_SESSION['startyear'] = $_POST['startyear'];
$_SESSION['endtime'] = $_POST['endtime'];
$_SESSION['endmonth'] = $_POST['endmonth'];
$_SESSION['endday'] = $_POST['endday'];
$_SESSION['endyear'] = $_POST['endyear'];

// Calling the DA API
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://domain.com',2222);
$sock->set_login('username','password');

$sock->set_method('POST');

$sock->query('/CMD_API_EMAIL_VACATION',

array(

'domain' => 'domain.com',
'action' => 'create',
'user' => $_SESSION['user'],
'text' => $_SESSION['text'],
'starttime' => $_SESSION['starttime'],
'startmonth' => $_SESSION['startmonth'],
'startday' => $_SESSION['startday'],
'startyear' => $_SESSION['startyear'],
'endtime' => $_SESSION['endtime'],
'endmonth' => $_SESSION['endmonth'],
'endday' => $_SESSION['endday'],
'endyear' => $_SESSION['endyear'],
'create' => 'Create'
));

$result = $sock->fetch_parsed_body();

if ($result["details"] == "A message for that user already exists") {

echo "Submit Failed for: ";
print_r($_SESSION['user']);
echo "<br>";
echo "email: ";
print_r($email);
echo "<br>";
echo "Vacation Message: ";
print_r($text);
echo "<br><br>";
echo "A message for that user already exists";
echo "<br><br>";
echo "Click <a href=\"modifyoverwrite.php\">here</a> to overwrite your old message or click <a href=\"modifyedit.php\">here</a> to edit your old message.";


} else {

print_r($result);

}

}

?>
 
I'm new to php, but this code is working :)

Please let me know if I'm going about it totally wrong!

Cheers!!
 
Hi natterjacks,

Any chance of seing the modify*.php files too? Thanks!
 
Hi,

Since then I've changed the code quite a bit to tidy things up. The text is all in Dutch now, which probably won't help you much.

Give me a couple of days and I'll run through the files, translate it back to english and put it all in a zip file.

Cheers,

Nathan
 
Any chance you're still willing to share the work you've done? I tried working with the information you shared, but haven't ever hacked on php code before and haven't been able to get things working yet.
 
mine is not working. when we submit, it says the vacation message was entered and when we click the link to go back and look at the message, it is not there and the system can't find it.
We log into DA and it is not in there either.

Any suggestions?
 
Have you checked that all your files are owner.group apache.apache? And have you edited vacation.php to include the domain for which you are trying to set things up?
 
no. instructions did not indicate owner/group had to be changed.

I do not have the access to change the owner/group anyway.
If I am not able to change the owner/group, will I not be able to run this on my client site? This has to be installed on the client site...
 
Last edited:
Back
Top