Month: July 2013

Html 2 PDF cakephp

1.Download html2pdf
2.Include the files in controller method as below

<?php
$this->autoRender = false;
$this->layout=false;
$id = $this->params[‘pass’][0];
App::import(“Model”,”Order”);
$this->Order=new Order();
$order = $this->Order->find(‘first’, array(‘conditions’=>array(‘Order.id’=>$id)));
$view = new View($this, false);
$view->set(“order”,$order);
$view->viewPath = ‘orders’;
$view_output = $view->render(‘admin_order_pdf’);

App::import(‘Vendor’,’xtcpdf’);
$tcpdf = new XTCPDF();
$textfont = ‘freesans’; // looks better, finer, and more condensed than ‘dejavusans’

$tcpdf->SetAuthor(“Worldwide Stone Order Details”);
$tcpdf->SetAutoPageBreak( false );
$tcpdf->setHeaderFont(array($textfont,”,10));
$tcpdf->xheadercolor = array(150,250,170);
$tcpdf->xheadertext = ”;
$tcpdf->xfootertext = ‘Copyright © %d Worldwide Stone Order Details. All rights reserved.’;
$html_for_pdf=$view_output;
$tcpdf->AddPage();
//$tcpdf->Cell(0,14, $html_for_pdf, 0,1,’L’);

$html_for_pdf=$view_output;
$tcpdf->writeHTMLCell($w=0, $h=0, $x=”, $y=”, $html_for_pdf, $border=0, $ln=1, $fill=0, $reseth=true, $align=”, $autopadding=true);
ob_start();
$tcpdf->Output(‘test.pdf’, ‘D’);
ob_end_flush();
/****************************************************************************/
if (!$id)
{
$this->Session->setFlash(‘Sorry, there was no property ID submitted.’);
$this->redirect(array(‘action’=>’admin_order_list’), null, true);
}
Configure::write(‘debug’,0); // Otherwise we cannot use this method while developing

$id = intval($id);

// $property = $this->__admin_order_view($id); // here the data is pulled from the database and set for the view
$property = $this->Order->find(‘first’,array(‘conditions’=>array(‘Order.id’=>$id)));
// pr($property);

if (empty($property))
{
$this->Session->setFlash(‘Sorry, there is no property with the submitted ID.’);
$this->redirect(array(‘action’=>’admin_order_list’), null, true);
}

$this->layout = ‘pdf’; //this will use the pdf.ctp layout
$this->render();
}

?>
3.The view file to be converted to pdf is

<div><h4><b>Order Details Of <?php echo $order[‘Order’][‘order’];?></b></h4></div>
<h2>Order Information</h2>
<img width=”100″ height=”100″ src=”<?php echo BASE_URL.”img/fancy_images/”.$order[‘Template’][‘image’];?>” />
<p>Order Name :<span><?php echo $order[‘Order’][‘order’];?><br/>
Template Name : <?php echo $order[‘Template’][‘title’];?><br/>
Material  Name : <?php echo $order[‘Material’][‘name’];?><br/>
Material  Id : <?php echo $order[‘Material’][‘material_id’];?>
</p>
<h2>Template Information</h2>
<p>Template Title : <?php if( $order[‘Template’][‘title’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘title’];}?><br/>
Template Price : <?php if( $order[‘Template’][‘price’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘price’];}?><br/>
Template Price : <?php if( $order[‘Template’][‘price’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘price’];}?><br/>
Template Created : <?php if( $order[‘Template’][‘created’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘created’];}?><br/>
Die Id  : <?php if( $order[‘Template’][‘die_id’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘die_id’];}?><br/>
Die Styles : <?php if( $order[‘Template’][‘styles’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘styles’];}?><br/>
Die Styles Codes : <?php if( $order[‘Template’][‘style_codes’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘style_codes’];}?><br/>
Die Styles Complexity : <?php if( $order[‘Template’][‘complexity’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘complexity’];}?><br/>
Die Styles Instances : <?php if( $order[‘Template’][‘instances’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘instances’];}?><br/>
Die Styles Special Die Aplicables :<?php if( $order[‘Template’][‘sd_aplicables’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘sd_aplicables’];}?><br/>
Original width(Single/Double) : <?php if( $order[‘Template’][‘original_width_sds’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘original_width_sds’];}?><br/>
Width in Inches :<?php if( $order[‘Template’][‘width_ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘width_ins’];}?><br/>
Height in Inches  :<?php if( $order[‘Template’][‘height_ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘height_ins’];}?><br/>
Estimated Area in inches  :<?php if( $order[‘Template’][‘estimated_area_ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘estimated_area_ins’];}?><br/>
Estimated Area in cms :  :<?php if( $order[‘Template’][‘estimated_area_cms’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘estimated_area_cms’];}?><br/>
Thickness 4ins :<?php if( $order[‘Template’][‘thickness_4ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘thickness_4ins’];}?><br/>
Thickness 6ins :<?php if( $order[‘Template’][‘thickness_6ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘thickness_6ins’];}?><br/>
Thickness 8ins :<?php if( $order[‘Template’][‘thickness_8ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘thickness_8ins’];}?>
</p>

<h2>Material Information</h2>

<p>Material Name :<span><?php echo $order[‘Material’][‘name’];?><br/>
Material Price :<span><?php echo $order[‘Material’][‘price’];?><br/>
Material Country Of Origin :<?php if( $order[‘Material’][‘country_of_rigin’] ==”){echo “Not Available”;}else {echo $order[‘Material’][‘country_of_rigin’];}?><br/>
Material Stone Type : <?php echo $order[‘Material’][‘stone_type’];?><br/>
Material Color Tone :<?php echo $order[‘Material’][‘color_tone_#’];?><br/>
Material Instance : <?php echo $order[‘Material’][‘instance’];?><br/>
Material Color Code :<?php echo $order[‘Order’][‘order’];?><br/>
</p>

Advertisements

Upload a file cakePHP

In controller this is how it works
Include the component upload in your controller

if(!empty($this->data[‘Supplier’][‘profile_picture’]) && $this->data[‘Supplier’][‘profile_picture’][‘size’]>0)
{
$destination=realpath(‘../../app/webroot/img/supplier’). DS;
$file= $this->data[‘Supplier’][‘profile_picture’];
$img=explode(“.”,$file[‘name’]);
$time=time();
$small=$img[‘0’].”-small.”.$time.$img[‘1’];
$result2 = $this->Upload->upload($file, $destination, $file[‘name’]);

}

And the upload component is

<?php

class UploadComponent extends Component {
/**
* constant for error types
* @var integer
*/
const SUCCESS = 0;

const FILESIZE_EXCEED_SERVER_MAX = 1;

const FILESIZE_EXCEED_FORM_MAX = 2;

const PARTIAL_UPLOAD = 3;

const NO_FILE_UPLOAD = 4;

const NO_DIRECTORY_FOR_UPLOAD = 6;

const SERVER_WRITE_FAIL = 7;

const FILESIZE_EXCEEDS_CODE_MAX = 98;

const FILE_FORMAT_NOT_ALLOWED = 99;

const DESTINATION_NOT_AVAILABLE = 100;

/**
* array of mime types that will be accepted by the UploadComponent
* left empty it will accept any
*/
private $file_types = array();

private $filename = null;

private $destination = null;

private $max_size = null;

private $content_only = false;

private $create_destination = true;

/**
* component constructor – set up local vars based on settings array in controller
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
if (!empty($settings[‘file_types’])) $this->file_types = $settings[‘file_types’];
if (!empty($settings[‘max_size’])) $this->max_size = $settings[‘max_size’];
}

/**
* set the allowed file types for this upload
* values are passed as string arguments to the
* method
* @example allowed_files(‘image/jpg’, ‘image/gif’, ‘image/png’);
* @return UploadComponent
*/
public function allowed_types() {
$types = func_get_args();
$this->file_types = $this->file_types + $types;
return $this;
}

/**
* set a custom name to use for the final uploaded file
* if not set then the original name of the uploaded file is used
* @param string $name
* @return UploadComponent
*/
public function custom_name($name) {
$this->filename = $name;
return $this;
}

/**
* set the destination path for the uploaded file
* @param string $path
* @return UploadComponent
*/
public function destination($path) {
// add trailing slash if there isn’t one
$last_char = substr($path, -1);
if ($last_char !== ‘/’) $path .= ‘/’;

$this->destination = $path;

return $this;
}

/**
* set the max file size for uploads for added validation
* if $this->max_size = 0 (default) then upload size is governed
* by PHP.ini settings and/or form settings.
* @param integer $size – max size of upload in bytes
* @return UploadComponent
*/
public function set_max_size($size) {
$this->max_size = $size;
return $this;
}

/**
* setter for the content_only flag
* if true then the upload is read into buffer
* and returned rather than being written to server
* @param boolean $flag
* @return UploadComponent
*/
public function content_only($flag = true) {
$this->content_only = $flag;
return $this;
}

/**
* setter for the create destination flag.
* can be turned off if an error on missing destination is required
* @param boolean $flag
* @return UploadComponent
*/
public function create_destination($flag = true) {
$this->create_destination = $flag;
return $this;
}

/**
* run the upload.
* the path param is optional and can be set separately
* @param array $form_data – The posted form data for the file element
* @param string $path – Optionally set the destination path here
* @return mixed –
*/
public function upload($form_data, $path = null) {
// silent fail on no image
if ($form_data[‘error’] == self::NO_FILE_UPLOAD) {
throw new Exception ($this->errors(self::NO_FILE_UPLOAD), self::NO_FILE_UPLOAD);
}

// handle optional path passed in
if (!empty($path)) $this->destination($path);

$this->form_data = $form_data;

// check we have a path – only if not returning the content
if ($this->content_only === false) {
if (empty($path) && empty($this->destination)) {
$this->form_data[‘error’] = self::NO_DIRECTORY_FOR_UPLOAD;
}
}

// check file types
if (!empty($this->file_types)) {
if (!in_array($this->form_data[‘type’], $this->file_types)) {
$this->form_data[‘error’] = self::FILE_FORMAT_NOT_ALLOWED;
}
}

// check max size set in code
if ($this->max_size > 0 && $this->form_data[‘size’] > $this->max_size) {
$this->form_data[‘error’] = self::FILE_SIZE_EXCEEDS_CODE_MAX;
}

// check error code
if ($this->form_data[‘error’] !== self::SUCCESS) {
throw new Exception($this->errors($this->form_data[‘error’]), $this->form_data[‘error’]);
}

// if only content required read file and return
if ($this->content_only) {
return file_get_contents($this->form_data[‘tmp_name’]);
}

// parse out class params to make the final destination string
if (empty($this->filename)) {
$destination = $this->destination . $this->form_data[‘name’];
} else {
$destination = $this->destination . $this->filename;
}

// create the destination unless otherwise set
if ($this->create_destination) {
$dir = dirname($destination);
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
} else {
$dir = dirname($destination);
if (!is_dir($dir)) {
throw new Exception($this->errors(self::DESTINATION_NOT_AVAILABLE), self::DESTINATION_NOT_AVAILABLE);
}
}

if (move_uploaded_file($this->form_data[‘tmp_name’], $destination)) {
return $destination;
} else {
throw new Exception($this->errors(self::SERVER_WRITE_FAIL), self::SERVER_WRITE_FAIL);
}

// if we get here without returning something has definitely gone wrong
throw new Exception($this->errors());
}

/**
* parse the response type and return an error string
* @param integer $type
* @return string – error text
*/
private function errors($type = null) {
switch ($type) {
case self::FILESIZE_EXCEED_SERVER_MAX:
return ‘File size exceeds allowed size for server’;
break;
case self::FILESIZE_EXCEED_FORM_MAX:
return ‘File size exceeds allowed size in form’;
break;
case self::PARTIAL_UPLOAD:
return ‘File was partially uploaded. Please check your Internet connection and try again’;
break;
case self::NO_FILE_UPLOAD:
return ‘No file was uploaded.’;
break;
case self::NO_DIRECTORY_FOR_UPLOAD:
return ‘No upload directory found’;
break;
case self::SERVER_WRITE_FAIL:
return ‘Failed to write to the server’;
break;
case self::FILE_FORMAT_NOT_ALLOWED:
return ‘File format of uploaded file is not allowed’;
break;
case self::FILESIZE_EXCEEDS_CODE_MAX:
return ‘File size exceeds maximum allowed size’;
break;
case self::DESTINATION_NOT_AVAILABLE:
return ‘Destination path does not exist’;
break;
default:
return ‘There has been an unexpected error, processing upload failed’;
}
}

}

Validation in cakephp

class User extends AppModel {
var $name = ‘User’;
var $validate = array(
‘firstname’ => array(
‘rule’ => ‘/^[a-zA-Z]{0,}$/i’,
‘message’ => “Enter Firstname (Alphabets Only).”,
‘allowEmpty’=>false
),
‘lastname’ => array(
‘rule’ => ‘/^[a-zA-Z]{0,}$/i’,
‘message’ => “Enter Lastname (Alphabets Only).”,
‘allowEmpty’=>false
),

‘start_date’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Select Date of Hire.”
),
‘primary_phone_number’ => array(
‘rule’ => array(‘phone’, ‘/^\s*[0-9\-\+\s]+$/i’, ‘us’),
‘message’ => “Enter valid phone number.”,
‘allowEmpty’=>true
),
‘s_designation’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter Designation.”
),
‘p_designation’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter Designation.”
),
‘secondary_phone_number’ => array(
‘rule’ => array(‘phone’, ‘/^\s*[0-9\-\+\s]+$/i’, ‘us’),
‘message’ => “Enter valid phone number.”,
‘allowEmpty’=>true
),
‘primary_email’ => array(
‘ruleName2’ => array(
‘rule’ => array(’email’),
‘message’ => “Enter valid email address.”
),

),
‘secondary_email’ => array(
‘ruleName2’ => array(
‘rule’ => array(’email’),
‘message’ => “Enter valid email address.”,
‘allowEmpty’=>true
),

),
‘password’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter your password.”
),
‘password1’ => array(
‘loginRule-1’ => array(
‘rule’    => ‘notEmpty’,
‘message’ => ‘Enter your password.’,
),
‘rule2’ => array(
‘rule’ => array(‘minLength’, 5),
‘message’ => ‘Minimum length of 5 characters.’
),
‘rule3’ => array(
‘rule’ => array(‘maxLength’, 25),
‘message’ => ‘Maximum length of 25 characters.’
)
),

’email’ => array(
‘notEmpty’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter your email.”,
‘last’ => true
),
‘ruleName2’ => array(
‘rule’ => array(’email’),
‘message’ => “Enter valid email address.”
),

),
‘old_password’ => array(
‘ruleName’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter old password.”,
‘last’ => true
),
‘ruleName2’ => array(
‘rule’ => array(‘isOldPasswordExists’),
‘message’ => “Old password doesnot exists.”
)
),
‘confirm_password’ => array(
‘ruleName’ => array(
‘rule’ => ‘notEmpty’,
‘message’ => “Enter confirm password.”
),
‘ruleName2’ => array(
‘rule’ => array(‘matchPasswords’,’password’),
‘message’ => “Passwords do not match.”
)
),
‘dob’ => array(
‘rule’ => array(‘validDOB’),
‘message’ => “Date of birth should not be greater than today’s date.”
)
);

and in controller
$this->Model->save($this->data, array(‘validate’=>false));

Paypal direct payment method

1.firstly you shoud have paypal account to use the payment method
2.Then you need credentials of credit card from the customer so that he can pay
$api_version = ‘98.0’;
$api_endpoint = ‘https://api-3t.sandbox.paypal.com/nvp&#8217;;
$api_username = ”;
$api_password = ”;
$api_signature =”;
// Store request params in an array
$request_params = array
(
‘METHOD’ => ‘DoDirectPayment’,
‘USER’ => $api_username,
‘PWD’ => $api_password,
‘SIGNATURE’ => $api_signature,
‘VERSION’ => $api_version,
‘PAYMENTACTION’ => ‘Sale’,
‘IPADDRESS’ => $_SERVER[‘REMOTE_ADDR’],
‘CREDITCARDTYPE’ => $ctype,
‘ACCT’ => $cnumber,
‘EXPDATE’ => $e,
‘CVV2’ => $cvv,
‘FIRSTNAME’ => $fname,
‘LASTNAME’ => ‘Testerson’,
‘STREET’ => ‘707 W. Bay Drive’,
‘CITY’ => ‘Largo’,
‘STATE’ => ‘FL’,
‘COUNTRYCODE’ => ‘US’,
‘ZIP’ => $zip,
‘AMT’ => $amount,
‘CURRENCYCODE’ => ‘USD’,
‘DESC’ => ‘Testing Payments Pro’
);

// Loop through $request_params array to generate the NVP string.
$nvp_string = ”;
foreach($request_params as $var=>$val)
{
$nvp_string .= ‘&’.$var.’=’.urlencode($val);
}

// Send NVP string to PayPal and store response
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 100);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

$result = curl_exec($curl);

curl_close($curl);

//echo $result.'<br /><br/>’;
parse_str($result, $arr); //this will convert the response url to array
$data[‘result’]=$arr;
$data[‘file’]=”/thankyou”;
//$this->load->view(‘content’,$data);

}

Search results with pagination CakePHP

//add these lines in your view file
<?php
$newUrl = “list”.$urlString;
$urlArray = array(
‘srch_name’ => $search1,
‘srch_type’ => $search2
);

$this->Paginator->options(array(‘url’=>$urlArray));

?>
//create form in the same view file
<?php echo $this->Form->create(‘User’,array(‘action’=>$newUrl,’method’=>’POST’,”class”=>”form”,’name’=>’listForm’));?>
<?php echo $this->Form->input(“name”,array(“class”=>”text2 inputClickBlur”,”label”=>false,”div”=>false,”value”=>$search1,”alt”=>”Type name here”)); ?>
<?php $options=array(‘MNG’=>’Manager’,’SUP’=>’Supplier’,’email’=>’Email’);
echo $this->Form->select(“type”,$options,array(“class”=>”short dropdownClick text3″,”label”=>false,”div”=>false,’empty’=>’—Select—-‘),$search2);?>
<?php echo $this->Form->submit(‘Search’,array(‘title’=>”Search”,’class’=>”normal_btn dblclick”,’div’=>false,’style’=>’margin:1px 5px 0 5px’)); ?>
<?php echo $this->Form->button(“Reset”,array(‘title’=>”Reset”,”type”=>”button”,”class”=>”normal_btn”,’div’=>false,”label”=>false,”onclick”=>”location.href='”.BASE_URL.”admin/users/list'”));?>

//apply sorting if you want to use on fields in same view file

<?php echo $this->Paginator->sort(‘User.firstname’,’Name’);?>
<?php echo $this->Paginator->sort(‘User.email’,’Email’);?>
<?php echo $this->Paginator->sort(‘User.user_type’,’Role’);?>
<?php echo $this->Paginator->sort(‘User.status’,’Status’);?>

//add following code in your controller method of above view
<?php

$criteria = “1”; //All Searching
$this->set(“search1″,”Type name here”);
$this->set(“search2”, “”);
$this->Session->delete(‘SESSION_SEARCH’);

$search2=””;
$search1=””;
$criteria=array(‘User.user_type !=’=>’SADM’);
if(isset($this->data[‘User’]) || !empty($this->params[‘named’]))
{
if((!empty($this->data[‘User’][‘name’]) && $this->data[‘User’][‘name’] != “Type name here”)|| (!empty($this->params[‘named’][‘srch_name’]) && $this->params[‘named’][‘srch_name’]!= ‘Type name here’))
{
if(isset($this->data[‘User’][‘name’] )){
$search1 = trim($this->data[‘User’][‘name’]);
}elseif(isset($this->params[‘named’][‘srch_name’])){
$search1 = trim($this->params[‘named’][‘srch_name’]);
}
$this->set(“search1″,$search1);
$pos = strpos($search1,’@’);
if(!empty($pos))
{
// $criteria .= ” AND User.email='”.$search1.”‘”;
$criteria = array_merge($criteria, array(‘User.email LIKE’=>’%’.$search1.’%’));
}
else
{
$criteria = array_merge($criteria, array(‘User.firstname LIKE’=>’%’.$search1.’%’));
}
}

if(!empty($this->data[‘User’][‘type’]) || !empty($this->params[‘named’][‘srch_type’])){
if(isset($this->data[‘User’][‘type’])){
$search2 = trim($this->data[‘User’][‘type’]);
}elseif(isset($this->params[‘named’][‘srch_type’])){
$search2 = trim($this->params[‘named’][‘srch_type’]);
}
$this->set(“search2″,$search2);
$criteria = array_merge($criteria, array(‘User.user_type LIKE’=>’%’.$search2.’%’));
}
//Done for fixing searching during pagination
$action=””;
if(isset($this->params[‘named’]) && !empty($this->params[‘named’][‘page’])){
$no_of_records=$this->User->find(‘count’,array(‘conditions’=>$criteria));
$no_of_pages=ceil($no_of_records/3);
if($no_of_pages<$this->params[‘named’][‘page’]){
$action=’list/srch_name:’.$search1.’/srch_type:’.$search2;
$this->redirect(array(‘controller’=>’users’,’action’ =>$action));
}
}
}
// echo ‘<pre>’; print_r($this->params);
if(isset($this->params[‘named’])){
$urlString = “/”;
$completeUrl = array();

if(!empty($this->params[‘named’][‘page’]))
$completeUrl[‘page’] = $this->params[‘named’][‘page’];

if(!empty($this->params[‘named’][‘sort’]))
$completeUrl[‘sort’] = $this->params[‘named’][‘sort’];

if(!empty($this->params[‘named’][‘direction’]))
$completeUrl[‘direction’] = $this->params[‘named’][‘direction’];
if(isset($search1))
$completeUrl[‘srch_name’] = $search1;
if(isset($search2))
$completeUrl[‘srch_type’] = $search2;
foreach($completeUrl as $key=>$value){
$urlString.= $key.”:”.$value.”/”;
}
}
// pr($criteria);
// echo $urlString;
$this->set(‘urlString’,$urlString);
if(!empty($setValue)){
if(isset($this->params[‘form’][‘IDs’])){
$saveString = implode(“‘,'”,$this->params[‘form’][‘IDs’]);
}

if($saveString != “”){
$this->User->updateAll($setValue,”User.user_id in (‘”.$saveString.”‘)”);
$this->Session->setFlash($messageStr, ‘layout_success’);
}

}

$this->paginate = array(
‘fields’ => array(
‘User.user_id’,
‘User.firstname’,
‘User.user_type’,
‘User.lastname’,
‘User.status’,
‘User.email’,
),
‘page’=> 1,’limit’ => 3,
‘order’ => array(‘user_id’ => ‘desc’)
);

$data = $this->paginate(‘User’,$criteria);

$this->set(‘total_users’, $data);

//my controller method is admin_list,User model and admin_list.ctp view file

Lens Zoom using JQuery and CSS

Just copy,paste and provide the src of image you want to zoom

<!– Lets make a simple image magnifier –>
<div>

<!– This is the magnifying glass which will contain the original/large version –>
<div></div>

<!– This is the small image –>
<img src=”the image you want to zoom using lens” width=”200″/>

</div>

<style>
/*Some CSS*/
* {margin: 0; padding: 0;}
.magnify {width: 200px; margin: 50px auto; position: relative; cursor: none}

/*Lets create the magnifying glass*/
.large {
width: 175px; height: 175px;
position: absolute;
border-radius: 100%;

/*Multiple box shadows to achieve the glass effect*/
box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.85),
0 0 7px 7px rgba(0, 0, 0, 0.25),
inset 0 0 40px 2px rgba(0, 0, 0, 0.25);

/*hide the glass by default*/
display: none;
}

/*To solve overlap bug at the edges during magnification*/
.small { display: block; }
</style>

//download and attach jquery-1.4.2.js below
<script type=”text/javascript” src=”jquery-1.4.2.js”></script>
<script type=”text/javascript”>

$(‘document’).ready(function(){

var native_width = 0;
var native_height = 0;
$(“.large”).css(“background”,”url(‘” + $(“.small”).attr(“src”) + “‘) no-repeat”);

//Now the mousemove function
$(“.magnify”).mousemove(function(e){
//When the user hovers on the image, the script will first calculate
//the native dimensions if they don’t exist. Only after the native dimensions
//are available, the script will show the zoomed version.
if(!native_width && !native_height)
{
//This will create a new image object with the same image as that in .small
//We cannot directly get the dimensions from .small because of the
//width specified to 200px in the html. To get the actual dimensions we have
//created this image object.
var image_object = new Image();
image_object.src = $(“.small”).attr(“src”);

//This code is wrapped in the .load function which is important.
//width and height of the object would return 0 if accessed before
//the image gets loaded.
native_width = image_object.width;
native_height = image_object.height;
}
else
{
//x/y coordinates of the mouse
//This is the position of .magnify with respect to the document.
var magnify_offset = $(this).offset();
//We will deduct the positions of .magnify from the mouse positions with
//respect to the document to get the mouse positions with respect to the
//container(.magnify)
var mx = e.pageX – magnify_offset.left;
var my = e.pageY – magnify_offset.top;

//Finally the code to fade out the glass if the mouse is outside the container
if(mx < $(this).width() && my < $(this).height() && mx > 0 && my > 0)
{
$(“.large”).fadeIn(100);
}
else
{
$(“.large”).fadeOut(100);
}
if($(“.large”).is(“:visible”))
{
//The background position of .large will be changed according to the position
//of the mouse over the .small image. So we will get the ratio of the pixel
//under the mouse pointer with respect to the image and use that to position the
//large image inside the magnifying glass
var rx = Math.round(mx/$(“.small”).width()*native_width – $(“.large”).width()/2)*-1;
var ry = Math.round(my/$(“.small”).height()*native_height – $(“.large”).height()/2)*-1;
var bgp = rx + “px ” + ry + “px”;

//Time to move the magnifying glass with the mouse
var px = mx – $(“.large”).width()/2;
var py = my – $(“.large”).height()/2;
//Now the glass moves with the mouse
//The logic is to deduct half of the glass’s width and height from the
//mouse coordinates to place it with its center at the mouse coordinates

//If you hover on the image now, you should see the magnifying glass in action
$(“.large”).css({left: px, top: py, backgroundPosition: bgp});
}
}
});
});
</script>

Zoom using css

<ul>
<li><img src=”five.png” width=”150px” height=”100px” alt=”Blackpool pier” /><span><img src=”assets/image-enlarge03.jpg” alt=”Blackpool pier” /><br />Rolling waves off Blackpool North Pier</span></li>
</ul>
<style>
ul.enlarge{
list-style-type:none; /*remove the bullet point*/
margin-left:0;
}
ul.enlarge li{
display:inline-block; /*places the images in a line*/
position: relative;
z-index: 0; /*resets the stack order of the list items – later we’ll increase this*/
margin:10px 40px 0 20px;
}
ul.enlarge img{
background-color:#eae9d4;
padding: 6px;
-webkit-box-shadow: 0 0 6px rgba(132, 132, 132, .75);
-moz-box-shadow: 0 0 6px rgba(132, 132, 132, .75);
box-shadow: 0 0 6px rgba(132, 132, 132, .75);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
ul.enlarge span{
position:absolute;
left: -9999px;
background-color:#eae9d4;
padding: 10px;
font-family: ‘Droid Sans’, sans-serif;
font-size:.9em;
text-align: center;
color: #495a62;
-webkit-box-shadow: 0 0 20px rgba(0,0,0, .75));
-moz-box-shadow: 0 0 20px rgba(0,0,0, .75);
box-shadow: 0 0 20px rgba(0,0,0, .75);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius:8px;
}
ul.enlarge li:hover{
z-index: 50;
cursor:pointer;
}
ul.enlarge span img{
padding:2px;
background:#ccc;
}
ul.enlarge li:hover span{
top: -300px; /*the distance from the bottom of the thumbnail to the top of the popup image*/
left: -20px; /*distance from the left of the thumbnail to the left of the popup image*/
}
ul.enlarge li:hover:nth-child(2) span{
left: -100px;
}
ul.enlarge li:hover:nth-child(3) span{
left: -200px;
}
/**IE Hacks – see http://css3pie.com/ for more info on how to use CS3Pie and to download the latest version**/
ul.enlarge img, ul.enlarge span{
behavior: url(pie/PIE.htc);
}
</style>