Rewriting Auto-response Page, need assistance.

sirbrent

Well-Known Member
Sep 30, 2008
98
1
58
Hello,
I am rewriting the cpanel auto-responder page which is available to webmail user when logging-in.

Essentially I am looking for a way to get auto-responder status, if its on or off for the logged-in email account. I want to be able to determine this so I can set conditional text on the page. For example if the condition returns true then i would display text "Auto-responder is currently on for this account".

I cannot seem to find a way to do this, although i note several ways to get auto-responder data using the api.

Eg.
Code:
<cpanel Email="getarsbody(FORM{'email'})">
But nothing to simply get the status of auto-responders.

Any help would be appreciated.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Hello,
I am rewriting the cpanel auto-responder page which is available to webmail user when logging-in.

Essentially I am looking for a way to get auto-responder status, if its on or off for the logged-in email account. I want to be able to determine this so I can set conditional text on the page. For example if the condition returns true then i would display text "Auto-responder is currently on for this account".

I cannot seem to find a way to do this, although i note several ways to get auto-responder data using the api.

Eg.
Code:
<cpanel Email="getarsbody(FORM{'email'})">
But nothing to simply get the status of auto-responders.

Any help would be appreciated.
You could do something like:

HTML:
<cpanelfeature autoresponders>
Autoresponders are enabled for this account.
</cpanelfeature>
Please be sure to modify these pages on your own copy of a theme. Editing the X3 theme files, even for webmail, directly will likely result in your modifications being lost.
 

sirbrent

Well-Known Member
Sep 30, 2008
98
1
58
Thanks for your response. However I do not believe cpanelfeature is what I need. That will "test" if the feature is enabled on the account through the feature list, but that is not what i am looking for. I am looking for a way to test if there is an auto-responder active on the currently logged-in mail users account. So if someone does not have the auto-responder on they would see text like "The auto-responder is off and you are receiving mail as usual." and if its on see a message such as:

Code:
Your auto-responder is currently ON. Click here to turn off.

Your response:
<cpanel Email="getarsbody(FORM{'email'})">
I hope this clears up what I am trying to do :)
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Thanks for your response. However I do not believe cpanelfeature is what I need. That will "test" if the feature is enabled on the account through the feature list, but that is not what i am looking for. I am looking for a way to test if there is an auto-responder active on the currently logged-in mail users account. So if someone does not have the auto-responder on they would see text like "The auto-responder is off and you are receiving mail as usual." and if its on see a message such as:

Code:
Your auto-responder is currently ON. Click here to turn off.

Your response:
<cpanel Email="getarsbody(FORM{'email'})">
I hope this clears up what I am trying to do :)
Ah. Well, here's a slight abuse of API2 syntax but it works for me in the webmail interface:

HTML:
<?cp Email::listautoresponders(The auto-responder is enabled)  || 'The auto-responder is off and you are receiving mail as usual' ?>
The quotes are needed for the text/HTML after the ||.
 

sirbrent

Well-Known Member
Sep 30, 2008
98
1
58
Still Open: Rewriting Auto-response Page, need assistance.

It is heading in the right direction :)

Might I ask for your expertise in abusing the API one more time???

What I am trying to output if the user has auto-responder enabled is this:

Code:
The auto-responder is currently enabled.
<a href="dodelautoresconfirm.html?email=%&redirectdomain=$FORM{'domain'}" onclick="delautoresconfirm('%');return false;">Turn off</a>
<br /><br />
Your response:
<br /><br />
<cpanel Email="getarsbody(FORM{'email'})">
<br /><br />
That looks a little messy, but hopefully you get the main idea -- <cpanel Email="getarsbody(FORM{'email'})"> would be replaced with the body of the set autoresponder.

So I imagine it would look something like this, I know this looks REALLY messy. I don't know how the syntax should look exactly, but the functionality should be roughly correct?

Code:
<cpanelif $appname==webmail>
<br />

<?cp Email::listautoresponders(The auto-responder is currently enabled. [a href="dodelautoresconfirm.html?email=%&redirectdomain=$FORM{'domain'}" onclick="delautoresconfirm\{leftparenthesis}'%'\{rightparenthesis};return false;"]Turn off[/a][br /][br /]Your response:[br /][br /]<cpanel Email="getarsbody(FORM{'email'})"])>[br /][br /]  || 'The auto-responder is off and you are receiving mail as usual' ?>

</cpanelif>
Thanks again for your help.
 
Last edited:

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
It is heading in the right direction :)

Might I ask for your expertise in abusing the API one more time???

What I am trying to output if the user has auto-responder enabled is this:

Code:
The auto-responder is currently enabled.
<a href="dodelautoresconfirm.html?email=%&redirectdomain=$FORM{'domain'}" onclick="delautoresconfirm('%');return false;">Turn off</a>
<br /><br />
Your response:
<br /><br />
<cpanel Email="getarsbody(FORM{'email'})">
<br /><br />
That looks a little messy, but hopefully you get the main idea -- <cpanel Email="getarsbody(FORM{'email'})"> would be replaced with the body of the set autoresponder.

So I imagine it would look something like this, I know this looks REALLY messy. I don't know how the syntax should look exactly, but the functionality should be roughly correct?

Code:
<cpanelif $appname==webmail>
<br />

<?cp Email::listautoresponders(The auto-responder is currently enabled. [a href="dodelautoresconfirm.html?email=%&redirectdomain=$FORM{'domain'}" onclick="delautoresconfirm\{leftparenthesis}'%'\{rightparenthesis};return false;"]Turn off[/a][br /][br /]Your response:[br /][br /]<cpanel Email="getarsbody(FORM{'email'})"])>[br /][br /]  || 'The auto-responder is off and you are receiving mail as usual' ?>

</cpanelif>
Thanks again for your help.
Embedding one API call within another makes a mess of things. Note that <cpanel Email="getarsbody(FORM{'email'})"])> returns an empty string when there is no auto-responder. So you can have your one API call, then that API call immediately after it.

I recommend you brush up on API2 syntax so you understand how to use % in API2. I did a presentation on API2 syntax at the 2007 cPanel Conference. I recommend looking at these slides beginning at slide 23 to understand API2 syntax:

http://twiki.cpanel.net/twiki/pub/A...urces/TrainingSlides07/Customizing_cPanel.pdf
 

sirbrent

Well-Known Member
Sep 30, 2008
98
1
58
Thanks so much. With your help, the resources and a little creativity I managed to accomplish exactly what I was hoping. x3 is a great interface but is starting to show its age, and in places it rough around the edges.

I changed the autoresponder feature (for webmail users) to be much simpler to use. Now a webmail user can do everything from autores.html, and is presented with a single form for setting a responder, and a simple on and off button. I will likely spice it up with some ajax, but for now it is working the way I envisioned.

If you are interested, here is a snippet of my code:

Code:
<cpanelif $appname==webmail>
<br />

<?cp Email::listautoresponders($LANG{'HCBAutoResStatOnMsg'} [br /] [br /]
[form method="POST" id="turnoffAR" name="turnoffAR" action="dodelautoresconfirm.html?email=$authuser&redirectdomain=$FORM{'domain'}"]
[input type="submit" class="input-button" value="$LANG{'HCBAutoResOffBtn'}"]
[/form]) domain=$FORM{'domain'} || '$LANG{'HCBAutoResStatOffMsg'}' ?>
<br /><br /><br />

<script type="text/javascript">

var waitpanel;

function register_validators() {
    register_validator('nomatch','empty',[document.mainform.from],'<cpanel langprint="ValidatorAutoresFrom">');
    register_validator('nomatch','empty',[document.mainform.subject],'<cpanel langprint="ValidatorAutoresSubject">');
   register_validator('nomatch','empty',[document.mainform.arbody],'<cpanel langprint="ValidatorAutoresBody">');
 
    realtime_validate_init('mainform');
}
function kill_utfmsg() {
    if (!FORM['autoload']) { checkcharset(); }
    document.getElementById('utfmsg').style.display='none';
}
YAHOO.util.Event.addListener(window, "load", kill_utfmsg, false);
YAHOO.util.Event.addListener(window, "load", register_validators, false);
function checkcharset() {
    var current_encoding = '<cpanel getcharset="">';
    var charEl = document.getElementById('charset');
    var req_encoding = charEl.options[charEl.selectedIndex].value;

    if (current_encoding == req_encoding) {
        return;
    }

    /* 

        to dream :)

    var prevCharSet = document.characterSet;
    eval('document.characterSet = req_encoding;');
    eval('document.inputEncoding = req_encoding;');
    if (document.characterSet != prevCharSet) {
        return;
    } */


    FORM['__cpanel__temp__charset__'] = req_encoding;
    FORM['autoload'] = 1;
    var QueryString = [];
    for(var i in FORM) {
        QueryString.push(i + '=' + FORM[i]);
    }
    
    show_loading("<cpanel langprint="CharEncodingSwitch">");
    window.location.href = 'addars.html?' + QueryString.join('&');
}

function show_loading(action,body) {

    if (!waitpanel) {    waitpanel =
           new YAHOO.widget.Panel("waitpanel",
                                           { width:"252px",
                                             fixedcenter:true,
                                             close:false,
                                             draggable:false,
                                             modal:true,
                                             visible:false
                                          }
                                      );
    }
  waitpanel.setHeader(action);
  var loadingimg = '<img src="img/yui/rel_interstitial_loading.gif" />';
    if (body) {
        waitpanel.setBody(body + '<br />' + loadingimg);
    }  else {
        waitpanel.setBody(loadingimg);
    }
  waitpanel.render(document.body);
  waitpanel.show();
}


var FORM = {};
parseForm();    

function parseForm() {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            FORM[key] = val;
        }
    }
}

</script>



<fieldset style="width: 550px;">
<legend><strong><?cp Email::listautoresponders($LANG{'HCBAutoResModifyFormTitle'}) || '$LANG{'HCBAutoResNewFormTitle'}' ?></strong></legend>
<form style="margin: 0px; padding: 0px;" method="POST" onSubmit="return do_validate(this.id);" id="mainform" name="mainform" action="doaddars.html">
<input type="hidden" id="charset" name="charset" value="utf-8">
<input type="hidden" id="email2" name="email2" value="<cpanel print="$authuser">">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="5" style="margin-top: 10px; margin-bottom: 10px;">
  <tr>
    <td width="60"><cpanel langprint="HCBAutoResFrom"></td>
    <td width="386"><input type="text" size="30" id="from" name="from" value="<cpanel Email="getarsfrom(FORM{'email'})">">
      <em>(eg. John Smith)</em></td>
  </tr>
  <tr>
    <td><cpanel langprint="HCBAutoResSubject"></td>
    <td><input type="text" size="55" id="subject" name="subject" value="<cpanel Email="getarssubject(FORM{'email'})">"></td>
  </tr>
  <tr>
    <td><cpanel langprint="HCBAutoResMessage"></td>
    <td></td>
  </tr>
  <tr>
    <td colspan="2">
    <textarea id="arbody" name="arbody" cols="75" rows="8" style="width: 100%; overflow: auto;"><cpanel Email="getarsbody(FORM{'email'})"></textarea>
    </td>
  </tr>
  <tr>
    <td colspan="2"><input type="checkbox" name="html" value="1" <cpanel Email="getarshtml(FORM{'email'})"> > <cpanel langprint="HCBAutoResHTML"></td>
  </tr>
  <tr>
    <td colspan="2" style="text-align: center;"><input type="submit" class="input-button" value="<?cp Email::listautoresponders($LANG{'Modify'}) || '$LANG{'ARCreate'}' ?>"></td>
  </tr>
</table>
</form>
</fieldset>
</cpanelif>
...and the Language Strings (english utf-8):

Code:
HCBAutoResHeadSingular=Autoresponder Configuration
HCBAutoResDescWebmail=The autoresponder will provide automatic replies to your incoming mail. They are often used to provide a response in your absence, e.g., when you are on vacation or out of the office.
HCBAutoResStatOnMsg=The autoresponse feature is currently <strong>ON</strong> for this mailbox.
HCBAutoResStatOffMsg=The autoresponse feature is currently <strong>OFF</strong> for this mailbox.<br />To enable this feature set an autoresponse below.
HCBAutoResOffBtn=Turn OFF
HCBAutoResNewFormTitle=Create an Autoresponse
HCBAutoResModifyFormTitle=Modify Current Autoresponse
HCBAutoResFrom=From:
HCBAutoResSubject=Subject:
HCBAutoResMessage=Message:
HCBAutoResHTML=HTML Message