Archive for December, 2005

XAJAX & Smarty

Saturday, December 31st, 2005

Okay so I have been messing around with all this ajax stuff recently. Now being a big fan of SMARTY I was reluctant to go and write my own templating system, and intergrating javascript into some of the existing smarty templates I had was a bit of a pain in the ass. But I really wanted to give this AJAX stuff a go.

After trying various different ajax scripts and implementatons, I settled on XAjax to work with PHP. The main reason was that they seemed to be the easiest to intergrate with Smarty.

So down to the nuts and bolts of it.

require_once(INCLUDESDIR. '/3rdparty/Xajax/xajax.inc.php');
$xajax = new xajax();
// Send our xajax requests to a certain server
$xajax->setRequestURI("form-processor.php");
$xajax->registerFunction("validate-field");
$xajax->processRequests();
$smarty->assign('xajax_javascript', $xajax->getJavascript());
$smarty->display('web/common/header.tpl');

So lets go this bit by bit just so that we are clear.

  • The first line simply includes or Xajax script
  • Begin a new instance of Xajax
  • The next line tells Xajax where to send the data. By default it will use POST and send the data back to the same calling script. However in this example, I am sending the data to another script whihc does all the processing for me and returns the results as an Xajax response.
  • Finally the register functions tells Xajax which function to call based upon what you write and decide it is allowed to call.
  • The process request statement must be called otherwise you won’t get anything back from your scripts
  • Xajax makes it very easy for you, all you do is as normal is assign a smarty var, the Xajax javascript and call it in your template as you would normally call anything else.
  • No an important bit here. If like me you are sending your requests to a separate script, you must include the Xajax library, you must have xajax registered the functions and you must call xajax->processRequests();

    A function, for those that don’t know can be anything you want to do. The validate one looks like this;


    public function validate-field($arg1) {
    $objResponse = new xajaxResponse();
    if(!$arg1, !$arg2) {
    return false;
    }
    $objResponse->addClear("messages","innerHTML");
    $objResponse->addAssign('messages', 'innerHTML', "Form was validated");
    return $objResponse->getXML();
    }

    You must return the $objResponse->getXML(), otherwise, how is XAJAX supposed to know what to do?

    So on my form, I have a on blur event that simply valiades the filed after the user moves away from the field

    This simple gets the value of the field and passes it to xajax whihc then calls my function. Simple right.

    Now I have actually got it to send messages like processing data, and then display an error message, perhaps I will put up an example of those when I get a chance.

    BTW this is a very very simplifed example of how quick it is to add XAJAX into your scripts. However please note that it can be quite complex to do this, and you should sit and plan your application correctly and its data flow. Also remember don’t use AJAX just because its cool to do so, use it because there is actually a need to use it.

    Smarty & Google Maps

    Tuesday, December 27th, 2005

    Well it looks like Monte is at it again. Another great product from the SMARTY guy. This handy little API makes it a piece of piss to intergrate Google maps into you web app. Of course it also supports SMARTY too.

    I have not played with it yet, but I will over the next few days as soon as I return to a dedicated link, instead of this vodafone 3G card which may I add is still over priced, not as good as it should be, and still not working correctly under Linux.

    Anyhow, must dash, have turkey to digest….. :)

    Installing Qmail With Vpopmail on RedHat Enterprise Server 4 with help from Qmailrocks.org

    Monday, December 19th, 2005

    Okay, so today I decided to install qmail + vpopmail + mysql + courier on a RHES 4 machine. Well normally I have used the excellent source rpms from Qmail Toaster, but I was having lots of problems with them today and considering time was tight I would go ahead and use the sources.

    Now I have known about Qmail Rocks for a long time now, but never really gotten around to testing the docs agains RHES 4, so today I thought would be my luck day.

    Now I had actually setup the server with a partition for vpopmail of about 10GB for the amount of users that will be located on it. It also keeps my filesystem nice and tidy, yet standard enough for any other sysadmin to come along and figure out what is going on.

    All went fine throughtout the install. In fact it was the easiest install I have ever done. All I did was copy and paste into my putty session the commands in bolded text. I then opened a browser, pointed it at the server and its vqadmin cgi and added a domain.

    All was going well until I opened up the Qmailadmin page. When I typed in my postmaster password for the domain I kept getting an Invalid User error.

    Okay so I looked at mysql and she was running sweetly, and the tables had all the correct info in them after vqadmin added the domain. There was nothing helpful in any of the log files, so I resorted to using the vpopmail command line tools to find out the problem.

    When I ran vdominfo, I got all the info I expected, however when I ran vuserinfo postmaster@somedomain.com I kept getting the following error.

    vmysql: can’t read settings from /home/vpopmail/etc/vpopmail.mysql

    Strange I thought, one binary could read the files, the other could not. Anyhow, I googled, a bit but never cam across the right answer, which then began to freak me out. Its not often that I can’t find the answer with google. So I took a break for a wee while.

    I cam back a few hours later, lit a smoke and said that this was not going to beat me. So I googled and gooogled and then yahooed and even dare I say it MSN’d it (yes I was going to extra low depths to solve the problem). Now I could have mailed the excellent and relavant maillists, but from the searching the one thing I did cop onto was that problems of this nature were common and so common in fact that anyone with a clue would not ask about them. So me not wanting to look like an idiot decided against that.

    Finally I began to get somewhere. I twigged it was a permissions error early on, it was sorta obvious anyhow. But one mail I read (sorry can’t find it now) described a similar problem but with a different binary in the vpopmail toolkit and with a similar partition structure as mine. It was to do with suid permissions on the partition. Lo and behold when I looked at the fstab I had nosuid in the defintion for /home/vpopmail.

    I quickly fixked that, and sensing I was close cd’d to the vpopmail bin dir to try my vuserinfo again.

    ./vuserinfo postmaster@somedomain.com
    vmysql: can’t read settings from /home/vpopmail/etc/vpopmail.mysql

    Bollix I thought. I lit yet another smoke and cruised over to Inter 7 again. The answer has to be here. Its the home of vpopmail. Surely some n00bie posted with the same error as me, got flamed, but then got a right answer and I can save face by not having to be the n00bie to post to the list……… well after searching though the mail list with the horrible htdig search engine, I was begining to think that I was going to be the n00bie.

    The I said I would reread the inter 7 docs again and make sure, what Qmail rocks was trying to do and what inter7 advised you to do was right.

    Well straight off, I spotted the error. The Install Doc advises a uid and a gid of 89, F*&@ I said, I remember this….. I had the same problem a year or so ago. The vpopmail and vchkpwd binarys should have the same uid and gid to work correctly. So I removed the users and groups Qmail Rocks had installed (7500 and 7509 for some reason??) and proceeded to do a rebuild. 6 min later I was ready to try again.

    BINGO BABY! It worked! Well I thought to myself, sometimes the most experienced people make mistakes. But I suppose the moral of this is, if you learn something once, don’t forget it. :)

    Anyhow, am posting this to show what an idiot I can be at times, you won’t always get the answer from google, you more than likley if you are not lazy have the answer but mostly, so I don’t forget again… Oh yeah and hopefull this will get indexed to hell by the search engines :)

    *Shamed*

    ILUG Website

    Saturday, December 3rd, 2005

    Well another thread has begun on the mail list about the state of the current ILUG website. I have tonnes I can say and tonnes I could do for this website IMHO and together with others I think a combinatin of our ideas could make for an exciting and informative website for a newbiee all the way through to an enterprise.

    However there are a couple of things I will say now. Don’t bother with the technology. We know it exists so thats not such a big problem. We need to formulate a strategy for the web site first. Then come up with permanaent content links, like about, community and then the more fluid dynamic site content. Apoint specialist teams to look after certain areas. For eample those interested in business and linux look after that section with a a chief and sub editor whom can remove content or alter as necessary. How they run themselves is not important, the main thing is that the overall team has one or two points of contact should things go wrong.

    Media watch. Watch whats happening in the media and put a linux spin on it if applicable.

    Make the thing easy to naviagte but hell design it beautifully so that it looks good, but also allows the end user to find what they are looking for quickly and easily. Use CSS to its fullest to provide standards complicance with elegant fall back for older browsers.

    ohh I could go on and on, but in realtiy I am putting my hand up and saying, I want to help, what do you want me to do. If I need to lead I will I don’t care about the politics of it all, just KISS is all and it will rock!