Results 1 to 9 of 9

Thread: [SOLVED] Sending ZmAppt startDate via actionUrl param & to a PHP script

  1. #1
    emoulton is offline Junior Member
    Join Date
    Aug 2007
    Location
    California
    Posts
    8
    Rep Power
    8

    Default [SOLVED] Sending ZmAppt startDate via actionUrl param & to a PHP script

    I'm having a bit of trouble getting the startDate of an appointment sent to a PHP script that I'm writing. The subject, location, and notes for the appointment seem to be getting to the script just fine, but the date does not. Is it some other data type other than integer? (The Zimlet Whitepaper says that it's an integer). I'm pretty sure something is being sent, or the php script would send back an empty string rather than "undefined." (See code samples, and the output I'm getting below).

    Thanks for any help that anyone might provide. I'm really diggin' Zimbra, by the way; it's a really nice system. Thanks for making an open source version.

    I'm running the 4.5.7_GA_1319.UBUNTU6 UBUNTU6 FOSS edition release running under Ubuntu server 6.06.

    Here's the bit of the Zimlet's XML definition I'm having trouble with:
    Code:
    <dragSource type="ZmAppt">
            <canvas type="dialog" title="Server Response" width="200"/>
    	<actionUrl target="http://externalserver/myscript.php">
    		<param name="apptSubject">${obj.subject}</param>
    		<param name="apptLocation">${obj.location}</param>
    		<param name="apptNotes">${obj.notes}</param>
    		<param name="apptStartDate">${obj.startDate}</param>
    	</actionUrl>
    </dragSource>
    Here's the PHP script I was testing with:
    PHP Code:
    $subject   $_REQUEST['apptSubject'];
    $location  $_REQUEST['apptLocation'];
    $notes     $_REQUEST['apptNotes'];
    $startdate $_REQUEST['apptStartDate'];

    echo 
    "Subject: ".$subject."<br />";
    echo 
    "Location: ".$location."<br />";
    echo 
    "Notes: ".$notes."<br />";
    echo 
    "Start Date: ".$startdate."<br />"
    When I drop an appointment into my Zimlet I get this output in the Server Response dialog I setup:

    Subject: Test Subject
    Location: Test Location
    Notes: Some notes about stuff
    Start Date: undefined

  2. #2
    JoshuaPrismon is offline Zimlet Guru & Moderator
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    Default

    Quote Originally Posted by emoulton View Post
    I'm having a bit of trouble getting the startDate of an appointment sent to a PHP script that I'm writing. The subject, location, and notes for the appointment seem to be getting to the script just fine, but the date does not. Is it some other data type other than integer? (The Zimlet Whitepaper says that it's an integer). I'm pretty sure something is being sent, or the php script would send back an empty string rather than "undefined." (See code samples, and the output I'm getting below).

    Thanks for any help that anyone might provide. I'm really diggin' Zimbra, by the way; it's a really nice system. Thanks for making an open source version.

    I'm running the 4.5.7_GA_1319.UBUNTU6 UBUNTU6 FOSS edition release running under Ubuntu server 6.06.

    Here's the bit of the Zimlet's XML definition I'm having trouble with:
    Code:
    <dragSource type="ZmAppt">
            <canvas type="dialog" title="Server Response" width="200"/>
    	<actionUrl target="http://externalserver/myscript.php">
    		<param name="apptSubject">${obj.subject}</param>
    		<param name="apptLocation">${obj.location}</param>
    		<param name="apptNotes">${obj.notes}</param>
    		<param name="apptStartDate">${obj.startDate}</param>
    	</actionUrl>
    </dragSource>
    Here's the PHP script I was testing with:
    PHP Code:
    $subject   $_REQUEST['apptSubject'];
    $location  $_REQUEST['apptLocation'];
    $notes     $_REQUEST['apptNotes'];
    $startdate $_REQUEST['apptStartDate'];

    echo 
    "Subject: ".$subject."<br />";
    echo 
    "Location: ".$location."<br />";
    echo 
    "Notes: ".$notes."<br />";
    echo 
    "Start Date: ".$startdate."<br />"
    When I drop an appointment into my Zimlet I get this output in the Server Response dialog I setup:

    Subject: Test Subject
    Location: Test Location
    Notes: Some notes about stuff
    Start Date: undefined
    You might try using Firefox and Firebug, setting a breakpoint in ZmZimletContext._zmObjectTransformers and see if you can see what is going on there. I just looked at the code, andit seemed correct.

  3. #3
    emoulton is offline Junior Member
    Join Date
    Aug 2007
    Location
    California
    Posts
    8
    Rep Power
    8

    Default

    Thanks for the response.

    I've never used Firebug before, but I installed it and took a look around. Just to clarify: I'm assuming that ZmZimletContext._zmObjectTransformers is a function somewhere in the Zimbra code, and you're suggesting that I use firebug to break the execution of this function to see what it's doing; see if it's passing back bad data to the Zimlet I wrote, right?

  4. #4
    emoulton is offline Junior Member
    Join Date
    Aug 2007
    Location
    California
    Posts
    8
    Rep Power
    8

    Default Still A Bit Confused...

    Sorry that I've not followed up until now; I haven't had a chance to work on this until today. Here is what I've (not) found out so far:

    In firebug I can't seem to find where ZmZimletContext._zmObjectTransformers is defined. I'm not sure if it's a function, object, or what, but I searched all the script files loaded up by firebug, and found only a few references to it. I put breakpoints on all of them, but only the if statement below was executed when I dragged and dropped my appointment onto my Zimlet.

    I set a breakpoint in the file ZimbraMail_all.js.zgz in an if statement:
    Code:
    if(ZmZimletContext._zmObjectTransformers[type]){
    return ZmZimletContext._zmObjectTransformers[type](obj);
    }else{
    return obj;
    }
    The line numbers start with 1378 (at the if statement), and I set a breakpoint at the if statement, and the two return statements. When I drag and drop the appointment the if statement is evaluated as true, and the line return ZmZimletContext._zmObjectTransformers[type](obj); is run.

    I'm pretty lost here, any more ideas?

    Thanks!
    Last edited by emoulton; 10-31-2007 at 11:16 AM.

  5. #5
    JoshuaPrismon is offline Zimlet Guru & Moderator
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    Default

    Quote Originally Posted by emoulton View Post
    Sorry that I've not followed up until now; I haven't had a chance to work on this until today. Here is what I've (not) found out so far:

    In firebug I can't seem to find where ZmZimletContext._zmObjectTransformers is defined. I'm not sure if it's a function, object, or what, but I searched all the script files loaded up by firebug, and found only a few references to it. I put breakpoints on all of them, but only the if statement below was executed when I dragged and dropped my appointment onto my Zimlet.

    I set a breakpoint in the file ZimbraMail_all.js.zgz in an if statement:
    Code:
    if(ZmZimletContext._zmObjectTransformers[type]){
    return ZmZimletContext._zmObjectTransformers[type](obj);
    }else{
    return obj;
    }
    The line numbers start with 1378 (at the if statement), and I set a breakpoint at the if statement, and the two return statements. When I drag and drop the appointment the if statement is evaluated as true, and the line return ZmZimletContext._zmObjectTransformers[type](obj); is run.

    I'm pretty lost here, any more ideas?

    Thanks!
    _zmObjectTransformers is a array of procedures that take the type of object, and run it against it. If you look a above where the array is set, you will see procedures that are defined for every object type that can be dragged to a zimlet.

  6. #6
    emoulton is offline Junior Member
    Join Date
    Aug 2007
    Location
    California
    Posts
    8
    Rep Power
    8

    Default

    From what I can see in firebug it looks like the start date of the appointment is being converted correctly. The object that's passed back has a parameter set called startDate with what looks like a start date in it. It looks like the _zmObjectTransformers stuff is working, but the data isn't being sent to the php script. Firebug tells me that Zimbra is sending apptStartDate=undefined. Any more ideas on where in the Zimbra code I should look next? What part of the code is handling the XML actionUrl tags that send the data?

    Oh yes, I've just upgraded to version 4.5.10 to see if it would make a difference, and it hasn't.

    I'm going to try and figure out how to handle things in JavaScript, and see if that works any differently, but it might take me a while to get around to doing so. I'll post whatever I find out about it here.

    Thanks for all your help so far JoshuaPrismon, I really appreciate it.

  7. #7
    emoulton is offline Junior Member
    Join Date
    Aug 2007
    Location
    California
    Posts
    8
    Rep Power
    8

    Default JavaScript problems...

    I used the Google Translator Zimlet as a base for writing the following code:

    XML definition file:
    Code:
    <zimlet name="email_reminder" version="0.21" description="Email Reminder">
    	<include>email_reminder.js</include>
    	<handlerObject>Email_Reminder</handlerObject>
    	<zimletPanelItem label="Email Reminder">
    		<toolTipText>
    			Drag and Drop An Appointment, or Double-click to configure.
    		</toolTipText>
    		<dragSource type="ZmAppt" />
    	</zimletPanelItem>
    	<userProperties>
    		<property type="string" name="emailaddr" label="Send To" />
    		<property type="string" name="emailuser" label="User" />
    		<property type="password" name="emailpass" label="Password" />
    	</userProperties>
    </zimlet>
    And the JavaScript file:
    Code:
    function Email_Reminder() {}
    
    Email_Reminder.prototype = new ZmZimletBase();
    Email_Reminder.prototype.constructor = Email_Reminder;
    
    Email_Reminder.URL = "http://my.test.server/test/emailr.php";
    
    Email_Reminder.prototype.doDrop = function (zmObject)
    {
    	this._zmObject = zmObject;
    	if (!this._statusDialog) { this._initialize(); }
    
    	this._contentDIV.innerHTML = this._zmObject.startDate;
    	this._contentDIV.style.visibility = "visible";
    
    	this._makeRequest();
    }
    
    Email_Reminder.prototype._initialize = function ()
    {
    	this._parentView = new DwtComposite(this.getShell());
    	this._parentView.setSize("440", "175");
    	
    	this._contentDIV = document.createElement("DIV");
    	this._contentDIV.style.height = "140px";
    	this._contentDIV.style.width = "435px";
    	this._contentDIV.style.backgroundColor = "#FFFFFF";
    	this._contentDIV.style.padding = "3px";
    	this._contentDIV.style.position = "absolute";
    	this._contentDIV.style.overflow = "auto";
    	this._parentView.getHtmlElement().appendChild(this._contentDIV);
    
    	this._statusDialog = this._createDialog({title:"Status", view:this._parentView});
    }
    
    Email_Reminder.prototype._makeRequest = function ()
    {
    	var params = [];
    	var i = 0;
    	
    	params[i++] = "apptStartDate=";
    	params[i++] = AjxStringUtil.urlEncode(this._zmObject.startDate);
    	
    	var header = { "User-Agent": navigator.userAgent , "Content-Type": "application/x-www-form-urlencoded" , "Referer": "http://my.test.server/test/emailr.php" };
    	var url = ZmZimletBase.PROXY + AjxStringUtil.urlEncode(Email_Reminder.URL);
    
    	AjxRpc.invoke(params.join("") , url , header , new AjxCallback(this , this._resultCallback));
    }
    
    Email_Reminder.prototype._populateStatus = function (respObj)
    {
    	var result = respObj.success ? respObj.text : null;
    	var divIdx = result ? result.indexOf("<div id=result_box") : null;
    	var div = divIdx ? Dwt.parseHtmlFragment(result.substring(divIdx)) : null;	
    
    	this._contentDIV.innerHTML = div ? div.innerHTML : "An error happened.";
    }
    
    
    Email_Reminder.prototype._resultCallback = function (obj)
    {
    	this._populateStatus(obj);
    	if (!this._statusDialog.isPoppedUp()) { this._statusDialog.popup(); }
    }
    The php code is the same as my first post in this thread, except I've commented out all the lines but the ones that deal with the start date of the appointment.

    I get a 403 error from the Zimbra server when I try to drag an appointment to this zimlet. The error text is: "Access to the specified resource () has been forbidden." The dialog pops up, but I get the "An error happened." message that's in the _populateStatus function. The URL that firebug is getting the 403 from is:
    Code:
    https://my.zimbra.server:444/service/proxy?target=http://my.test.server/test/emailr.php
    I'll keep playing around with it to see if I can't figure out what's going on. Currently I have a very limited idea of what the JavaScript code is doing, and I'm not much of a JavaScript programmer to begin with.

    Any suggestions would be more than welcome. Thanks!

  8. #8
    JoshuaPrismon is offline Zimlet Guru & Moderator
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    Default

    Quote Originally Posted by emoulton View Post
    I used the Google Translator Zimlet as a base for writing the following code:

    XML definition file:
    Code:
    <zimlet name="email_reminder" version="0.21" description="Email Reminder">
    	<include>email_reminder.js</include>
    	<handlerObject>Email_Reminder</handlerObject>
    	<zimletPanelItem label="Email Reminder">
    		<toolTipText>
    			Drag and Drop An Appointment, or Double-click to configure.
    		</toolTipText>
    		<dragSource type="ZmAppt" />
    	</zimletPanelItem>
    	<userProperties>
    		<property type="string" name="emailaddr" label="Send To" />
    		<property type="string" name="emailuser" label="User" />
    		<property type="password" name="emailpass" label="Password" />
    	</userProperties>
    </zimlet>
    And the JavaScript file:
    Code:
    function Email_Reminder() {}
    
    Email_Reminder.prototype = new ZmZimletBase();
    Email_Reminder.prototype.constructor = Email_Reminder;
    
    Email_Reminder.URL = "http://my.test.server/test/emailr.php";
    
    Email_Reminder.prototype.doDrop = function (zmObject)
    {
    	this._zmObject = zmObject;
    	if (!this._statusDialog) { this._initialize(); }
    
    	this._contentDIV.innerHTML = this._zmObject.startDate;
    	this._contentDIV.style.visibility = "visible";
    
    	this._makeRequest();
    }
    
    Email_Reminder.prototype._initialize = function ()
    {
    	this._parentView = new DwtComposite(this.getShell());
    	this._parentView.setSize("440", "175");
    	
    	this._contentDIV = document.createElement("DIV");
    	this._contentDIV.style.height = "140px";
    	this._contentDIV.style.width = "435px";
    	this._contentDIV.style.backgroundColor = "#FFFFFF";
    	this._contentDIV.style.padding = "3px";
    	this._contentDIV.style.position = "absolute";
    	this._contentDIV.style.overflow = "auto";
    	this._parentView.getHtmlElement().appendChild(this._contentDIV);
    
    	this._statusDialog = this._createDialog({title:"Status", view:this._parentView});
    }
    
    Email_Reminder.prototype._makeRequest = function ()
    {
    	var params = [];
    	var i = 0;
    	
    	params[i++] = "apptStartDate=";
    	params[i++] = AjxStringUtil.urlEncode(this._zmObject.startDate);
    	
    	var header = { "User-Agent": navigator.userAgent , "Content-Type": "application/x-www-form-urlencoded" , "Referer": "http://my.test.server/test/emailr.php" };
    	var url = ZmZimletBase.PROXY + AjxStringUtil.urlEncode(Email_Reminder.URL);
    
    	AjxRpc.invoke(params.join("") , url , header , new AjxCallback(this , this._resultCallback));
    }
    
    Email_Reminder.prototype._populateStatus = function (respObj)
    {
    	var result = respObj.success ? respObj.text : null;
    	var divIdx = result ? result.indexOf("<div id=result_box") : null;
    	var div = divIdx ? Dwt.parseHtmlFragment(result.substring(divIdx)) : null;	
    
    	this._contentDIV.innerHTML = div ? div.innerHTML : "An error happened.";
    }
    
    
    Email_Reminder.prototype._resultCallback = function (obj)
    {
    	this._populateStatus(obj);
    	if (!this._statusDialog.isPoppedUp()) { this._statusDialog.popup(); }
    }
    The php code is the same as my first post in this thread, except I've commented out all the lines but the ones that deal with the start date of the appointment.

    I get a 403 error from the Zimbra server when I try to drag an appointment to this zimlet. The error text is: "Access to the specified resource () has been forbidden." The dialog pops up, but I get the "An error happened." message that's in the _populateStatus function. The URL that firebug is getting the 403 from is:
    Code:
    https://my.zimbra.server:444/service/proxy?target=http://my.test.server/test/emailr.php
    I'll keep playing around with it to see if I can't figure out what's going on. Currently I have a very limited idea of what the JavaScript code is doing, and I'm not much of a JavaScript programmer to begin with.

    Any suggestions would be more than welcome. Thanks!
    It sounds like you have a proxy/permissions issue in your config template.

  9. #9
    emoulton is offline Junior Member
    Join Date
    Aug 2007
    Location
    California
    Posts
    8
    Rep Power
    8

    Default

    I had no idea that I needed a config template. Figuring that one out would have taken me quite a while. Thank you VERY much.

    I've finally gotten the startDate string to be sent from, and passed back to the zimlet via the php script. At first I got another "undefined", but then I changed the code that was parsing the response object, and it started working.

    Here's the change I made in the JavaScript file:
    Code:
    Email_Reminder.prototype._populateStatus = function (respObj)
    {
    /*    //Commented out this stuff which was taken verbatim, (almost),
           //from the google translator zimlet.
    	var result = respObj.success ? respObj.text : null;
    	var divIdx = result ? result.indexOf("<div id=result_box") : null;
    	var div = divIdx ? Dwt.parseHtmlFragment(result.substring(divIdx)) : null;	
    
    	this._contentDIV.innerHTML = div ? div.innerHTML : "An error happened.";
     */
    
            //Added this in it's stead.
    	this._contentDIV.innerHTML = respObj.text;
    }
    Here's the config template file that I added in case anyone is interested:
    Code:
    <zimletConfig name="email_reminder" version="0.23">
      <global>
        <property name="allowedDomains">my.test.server</property>
      </global>
    </zimletConfig>
    Thanks again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 07-19-2007, 02:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •