PDA

View Full Version : adding [[plan]]



kwansan
04-17-2006, 02:00 PM
Hi,

First off, this is an excellent who is script. Superbly written with nice clean codes and it is easily integrated. Seems everything was well thought out. =)

I am using this script on my hosting site and I can easily allow users to search for domain names and than pass the variable to my order form along with the choosen plan.

What I am trying to do now is allow users to select a plan first and pass this variable to the whois search form. However, I am having some difficulty, since the templates (search, available, etc etc) are contained within the config/template.php ... If I include any additional <? php $_REQEST[plan] or what if statements ?> it gives me the infamous T whitespace error.

Is it easier to make something like [[domain]] and [[ext]] for [[plan]] and if so what files need to be changed.

Or is it easier to write <?php scripts ?> straight into the templates and if so how would I let whois script know that it is php without using <? ?> in other words I am trying to figure out what compiler is used. I know it is not smarty since {} I did not see any curlys.

anyhow, if any one has any suggestions or know how I can include an additional variable that will compile with the double square brackets.

Thanks ! =)

Patrick
04-17-2006, 11:09 PM
There are a couple of options here that you might not have even thought of that may be available (and easiest) to implement.

First of all, what billing software or billing method are you using? Are you passing the client onto another script then once they select a domain?

If you are, then you might want to consider using sessions (again, this would depend on your billing script, etc). Then you could just start the session on your website (session_start () (http://www.php.net/session_start)) and use $_SESSION['plan'] = whatever; for session the plan's id prior to passing it onto the whois script, and then pick it up later (by referring to $_SESSION['plan'] prior to or on your billing page... remember to session_start() before attempting to access and before any output).

If that is a possibility, use that.

Now... onto the other answers:

The script doesn't use smarty templates (personal preference on my part in writing the script) and the template engine is a basic one that was scripted specifically for the whois script. I considered adding the ability to allow executed PHP code within templates via
tags but I decided against it since it could potentially open up security holes that are just unnecessary for the ability it offers and as a whole the nature of the script.

That said, you still have a couple of options. One of them is manually editing the config/template.php file. For example, the default main page is:
[php] $this->TEMPLATES['main'] = "[[header]]
[[searchbar]]
[[footer]]";

You could replace that with:

$this->TEMPLATES['main'] = "[[header]]
[[searchbar]]"
. $_REQUEST['plan']
. "[[footer]]";


You would have to do that manually by editing the file of course. The advantage of doing it this way would be that you wouldn't break any part of the script with the possible exception of the edit templates page (currently the edit templates page ALWAYS writes all the templates regardless of whether they have been changed... I will likely change this in the next version to only update the templates if they need to be updated). The reason I say possible exception is that more-than-likely your templates page will still work fine, with the exception of editing whichever template(s) has the $_REQUEST code in it (I would suggest backing up template.php before trying it out for the first time to be safe).

So far, the methods above are much better than the method below. First of all because they will almost certainly not break any updating to the script (so the updater script of the admin panel will still work) and secondly because they do not edit any code that might be changed in the future (the modifications will still be in place after updating).

The final method is the one that I do not recommend, and that is adding another variable to the template engine such as [[plan]]. I don't recommend this because the changes will not stick after you next update (you will have to do them all over again), while in the previous examples your changes will likely be fine through any future updates:
Again, I DO NOT recommend this method.

Open up classes/display.php and scroll down to the "function parsePage()" function line (around line 208 as of version 2.22).

Find:

$search = array (
"/\[\[header\]\]/",
"/\[\[footer\]\]/",
"/\[\[copyright\]\]/"
);

$replace = array (
$this->CORE->TEMPLATES['header'],
($this->CORE->CONFIG->SCRIPT['copyright'] && !$this->copyright ? $copyright : "") . $this->CORE->TEMPLATES['footer'],
$copyright
);

And change that accordingly, such as:

$search = array (
"/\[\[header\]\]/",
"/\[\[footer\]\]/",
"/\[\[copyright\]\]/",
"/\[\[plan\]\]/"
);

$replace = array (
$this->CORE->TEMPLATES['header'],
($this->CORE->CONFIG->SCRIPT['copyright'] && !$this->copyright ? $copyright : "") . $this->CORE->TEMPLATES['footer'],
$copyright,
$_REQUEST['plan']
);

So there are three methods. I recommend trying the first one, if possible (and it isn't possible to use sessions in many setups). I recommend trying the second one (editing template.php) if the first doesn't work and I DO NOT recommend trying the third one.

Best of luck.

kwansan
04-18-2006, 09:50 PM
Hi Patiek,

You are a genius it works like a charm! I used the solution you advised me not to use. =)

I decided to use the one to build search/replace variable in the display.php since I needed to write additional elseif statements. I have made my notations around the additional code and saved the snippet separately. So, if and when the script is updated I will know where to copy and paste this snippet. I agree I do not like digging around config files. But, it was not too bad. That is the beauty of your whois script. There really is no reason to go poking around any of your config files. Most integration/customizing can be done straight from the admin panel.

Thank you so much for providing an easy to use admin panel.

With your help, now when a plan is selected with "i need a new domain", the plan is passed to the domain search bar page. After a new domain is searched, it prints the available results with the plan they originally selected as a dropdown with a submit button that will pass it to my order form.

Here they can change the plan before continuing to the order form.

I did run into one small problem. Originally I had it as radio buttons but, when they change the plan and conduct another domain name search, it did not reflect the new changed plan. I did not know how to have this done (since I am limited with javascript). I tried a few onclick methods with no luck.

So I changed it to dropdowns, it looks less apparent. No biggie. =). Dropdowns take up less space anyway.

Just wanted to personally thank you again for such a wonderful script and for your personal assistance. This is definately a "must have" script.