Monday, March 30, 2009

Progress bar using PHP

Upload progress bar



An extension to track progress of a file uploads. It is only known to work on Apache and at least PHP 5.2 is needed.

To Install

In windows it’s quite easy just copy and paste the uploadprogress.dll extension and enables the extension in the php configuration file and that’s it.

However in linux or unix, installation is different you need to either install it from the site http://pecl.php.net/package/uploadprogress via a pear or pecl in the server or download the stable release from the site and then install.

What to configure in php.ini

[uploadprogress]

extension=uploadprogress.dll

uploadprogress.file.contents_template = "c:\temp\upl_%s.txt" uploadprogress.file.filename_template = "c:\temp\upl_%s.txt"

uploadprogress.file.upload_identifier="UPLOAD_IDENTIFIER"

uploadprogress.update_interval=500

uploadprogress.delete_finished=1

(please set the path as per linux where it says c:\temp\upl_%s.txt)

after adding this lines in php.ini create a folder temp in a location set in the above php.ini

That’s all … and start running the progressbar

The progress bar is tested in firefox and IE and is working fine.

Friday, March 20, 2009

Integrating Paypal Shopping cart

The PayPal Shopping Cart – Add to Cart

With the PayPal Shopping Cart, you can let buyers select multiple items on your website and Pay for them with a single payment. Buyers click Add to Cart buttons to add items to their Virtual PayPal Shopping Carts, and they click View Cart buttons to review the items in their Carts before they check out and make their payments.

Sample HTML Code for a Basic Add to Cart Button. The sample HTML code below illustrates a basic Add to Cart button with these features:
An item named “QA Testing”.
An item price of $990.95 USD.
􀁺 PayPal calculates tax and shipping based on rates that you set up in your PayPal account.
􀁺 The buyer’s PayPal Shopping Cart opens in a separate browser window or tab.

form target=paypal action=https://www.paypal.com/cgi-bin/webscr method=post

Identify your business so that you can collect the payments.
input type=hidden name=business value=abc@abc.com

Specify a PayPal Shopping Cart Add to Cart button.
input type=hidden name=cmd value=_cart
input type=hidden name=add value=1

Specify details about the item that buyers will purchase.
input type=hidden name=item_name Value=QA and Software Testing
input type=hidden name=amount value=990.95
input type=hidden name=currency_code value=USD

Continue shopping on the current webpage of the merchant site.
The below value is replaced when buyers click Add to Cart
input type=hidden name=shopping_url value=http://www.globalworldtech.com/services.html
input type=hidden name=shipping value=4
input type=hidden name=handling_cart value=24

Display the payment button.
input type=image name=submit border=0 src=https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif
alt=PayPal - The safer, easier way to pay online
img alt="" border=0 width="1" height="1" src=https://www.paypal.com/en_US/i/scr/pixel.gif

form

Variables required to tell PayPal the type of form it is are:

1) cmd
The cmd variable is always required in a FORM. Its value determines which Website Payments Standard checkout experience you are using to obtain payment.

Allowed Values for cmd Variable
Value of cmd Description
a) _xclick The button that the person clicked was a Buy Now button
b) _donations The button that the person clicked was a Donate button
c) _xclick- subscriptions the button that the person clicked was a Subscribe button.
d) _cart For shopping cart purchases; these additional variables specify the Kind of shopping cart button or command:
􀁺 add – Add to Cart buttons this must be set to 1
􀁺 display – View Cart buttons other alternative to add
􀁺 upload – The Cart Upload command tells it’s a third party cart must be set to1.

2) shopping_url
Use the shopping_url variable to let PayPal control which page buyers return to when they click the Continue Shopping button.

3) handling_cart

Single handling fee to be charged cart-wide. If handling_cart is used in multiple Add to Cart buttons, the handling_cart value of the first item is used.

4) amount
Required Price of the item or the total price of all items in the shopping
Cart.

5) business
Required Your PayPal ID or an email address associated with your PayPal
account. Email addresses must be confirmed

6) item_name
Required Name of the item or a name for the entire Shopping Cart

7) currency_code
The currency of the payment. The default is USD.

8) shipping
The cost of shipping the item. This use of the shipping variable is valid only for Buy Now and Add to Cart buttons.

There are few other additional html variables like tax, tax_rate ,undefined_quantity,weight,weight_unit also can defined if required you can check the url
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables for all html variables.

Sunday, March 1, 2009

Abstract Class
An abstract class is a class with or without data members that provides some functionality and leaves the remaining functionality for its child class to implement. The child class must provide the functionality not provided by the abstract class or else the child class also becomes abstract.
Objects of an abstract and interface class cannot be created i.e. only objects of concrete class can be created.
To define a class as Abstract, the keyword abstract is to be used e.g. abstract class ClassName { }
Eg :
abstract class Furniture {
private $height, width, length;

public function setData($h, $w, $l) {
$this->height = $h;
$this->width = $w;
$this->length = $l;
}

//this function is declared as abstract and hence the function
//body will have to be provided in the child class
public abstract function getPrice();

}


class BookShelf extends Furniture {

private $price;

public setData($h, $w, $l, $p) {
parent::setData($h, $w, $l);
$this->price = $p;
}


//this is the function body of the parent abstract method
public function getPrice() {
return $this->price;
}
}
In the above example, the method getPrice() in class Furniture has been declared as Abstract. This means that its the responsibility of the child class to provide the functionality of getPrice(). The BookShelf class is a child of the Furniture class and hence provides the function body for getPrice().
Private methods cannot be abstract
If a method is defined as abstract then it cannot be declared as private (it can only be public or protected). This is because a private method cannot be inherited.

Interface Class
Interface is a class with no data members and contains only member functions and they lack its implementation. Any class that inherits from an interface must implement the missing member function body.
Interfaces is also an abstract class because abstract class always require an implementation.
In PHP 5, interfaces may declare only methods. An interface cannot declare any variables. To extend from an Interface, keyword implements is used. PHP5 supports class extending more than one interface.
Eg:
interface employee
{
function setdata($empname,$empage);
function outputData();
}

class Payment implements employee
{
function setdata($empname,$empage)
{
//Functionality
}

function outputData()
{
echo "Inside Payment Class";
}
}

$a = new Payment();
$a->outputData();