How to save draft contect when you add

Standard

http://sisyphus-js.herokuapp.com/

 

https://syeilendrapramuditya.wordpress.com/2015/07/13/html-form-autosave-with-sisyphus-js-how-to-use-it/

 

<!DOCTYPE html>
<html>
<head>
"text/javascript" src="sisyphus.min.js">
$( function() {
$( "#form2" ).sisyphus(); //Autosave form2 only,
// or you can persist all forms data at one command
// $( "form" ).sisyphus();
} );
</head>
<body>
Form 1
<form action="" id="form1" name="form1" method="post">
Name:<br />
<input type="text" name="name" value="" /><br />
E-mail:<br />
<input type="text" name="mail" value="" /><br />
Comment:<br />
<input type="text" name="comment" value="" size="50" />
<br /><br />
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
<br>
Form 2
<form action="" id="form2" name="form2" method="post">
Name:<br />
<input type="text" name="name" value="" /><br />
E-mail:<br />
<input type="text" name="mail" value="" /><br />
Comment:<br />
<input type="text" name="comment" value="" size="50" />
<br /><br />
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
</body>
</html>
Advertisements

API IN CODEIGNITOR

Standard

api.php controller

 

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);class Api extends CI_Controller {function __construct() { parent::__construct();
date_default_timezone_set(‘Australia/canberra’);  $militime =round(microtime(true) * 1000); $datetime =date(‘Y-m-d h:i:s’); define(‘militime’, $militime); define(‘datetime’, $datetime); }
public function login(){ $email = $this->input->post(’email’); $name = $this->input->post(‘name’); $image = $this->input->post(‘image’); $contact_no = $this->input->post(‘contact_no’); $device_token = $this->input->post(‘device_token’); $device_id = $this->input->post(‘device_id’); $device_type = $this->input->post(‘device_type’);    $type = $this->input->post(‘social_login_type’);
if($device_type == ‘iOS’ && strlen($device_id) === strlen($device_token))    {         $device_token = ”;    }
$version_code = $this->input->post(‘version_code’);
$auth_key = $this->rand_string(40);
$final_output = array();
if(!empty($email))    {       $get_version = $this->common_model->common_getRow(‘app_version’,array(‘version_id’=>1));         if(($version_code < $get_version->android_min_version && $device_type == ‘android’) || ($version_code < $get_version->ios_min_version && $device_type == ‘iOS’))     {     if($device_type == ‘android’)     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to Google Play to download the latest version’;      }     else     {     $msg = ‘This version of ATMC is became to obsolete. Please go to App Store to download the latest version’;     }
$final_output[‘status’] = ‘1001’; $final_output[‘message’] = $msg; header(“content-type: application/json”);     echo json_encode($final_output);exit;     }     else     {  $check_email = $this->common_model->common_getRow(‘students’,array(’email’=>$email)); if(!empty($check_email)) {     $update_value = $this->common_model->updateData(‘students’,array(‘update_at’=>militime,’token’=>$auth_key,’device_id’=>$device_id,’device_token’=>$device_token,’device_type’=>$device_type,’image’=>$image,’name’=>$name,’social_login_type’=>$type,’contact_no’=>$contact_no,),array(’email’=>$email));
$student_id = $check_email->student_id;
$query = $this->db->query(“UPDATE `students` SET `device_token` = ” WHERE `device_id` = ‘$device_id’ AND `student_id` != ‘$student_id'”);

$data_array = array(     ‘student_id’=>$check_email->student_id,                   ‘name’=>$name,                   ’email’=>$check_email->email,             ‘contact_no’=>$contact_no,                   ‘image’=>$image,                   ‘social_login_type’=>$type,                   ‘token’=>$auth_key,                               );
$final_output[‘status’] = ‘success’; $final_output[‘message’] = ‘You have logged-in successfully.’; $final_output[‘data’] = $data_array;     }     else {           $insert_array = array(                   ‘name’=>$name,                   ’email’=>$email,                   ‘contact_no’=>$contact_no,                   ‘image’=>$image,                   ‘device_id’=>$device_id,                   ‘device_token’=>$device_token,                   ‘device_type’=>$device_type,                   ‘token’=>$auth_key,                   ‘social_login_type’=>$type,                   ‘create_at’=>militime,                   ‘update_at’=>militime,           );
$insertId = $this->common_model->common_insert(‘students’, $insert_array);
if($insertId)     {     $dataa_array  = array(     ‘student_id’=>$insertId,                   ‘name’=>$name,                   ’email’=>$email,             ‘contact_no’=>$contact_no,                   ‘image’=>$image,                   ‘social_login_type’=>$type,                   ‘token’=>$auth_key             );

$query = $this->db->query(“UPDATE `students` SET `device_token` = ” WHERE `device_id` = ‘$device_id’ AND `student_id` != ‘$insertId'”);

$final_output[‘status’] = ‘success’; $final_output[‘message’] = ‘You have logged-in successfully.’; $final_output[‘data’] = $dataa_array; }else {  $final_output[‘status’] = ‘failed’;       $final_output[‘message’] = ‘Something went wrong! please try again.’;       unset($final_output[‘data’]); }     } }    }else { $final_output[‘status’] = ‘failed’; $final_output[‘message’] = ‘Required parameter not found’; unset($final_output[‘data’]); }  header(“content-type: application/json”);    echo json_encode($final_output);}

 

public function message_list_search_more(){ $headers = apache_request_headers(); if($headers[‘Secret-Key’] !=”)  {  $check_key = $this->checktoken($headers[‘Secret-Key’]);
if($check_key[‘status’] == ‘true’)     {         $device_type = $this->input->post(‘device_type’);              $version_code = $this->input->post(‘version_code’);
$get_version = $this->common_model->common_getRow(‘app_version’,array(‘version_id’=>1));
if(($version_code < $get_version->android_min_version && $device_type == ‘android’) || ($version_code < $get_version->ios_min_version && $device_type == ‘iOS’))        {     if($device_type == ‘android’)     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to Google Play to download the latest version;’;      }     else     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to App Store to download the latest version;’;     }
$final_output[‘status’] = ‘1001’; $final_output[‘message’] = $msg; header(“content-type: application/json”);     echo json_encode($final_output);exit;     }    else    {
//$create_at = $this->input->post(‘create_at’); $searchVal = $this->input->post(‘searchVal’);        $student_id = $check_key[‘data’]->student_id;
$final_output = array();
if($searchVal==0) { $searchVal= ”; }else { $searchVal= “WHERE title like’%$searchVal%'”; }
$query = $this->db->query(‘SELECT * FROM message_details ‘.$searchVal.’ ORDER BY message_id DESC LIMIT 10′); $messagelist = $query->result();
if(!empty($messagelist)) {
$message_arr = array();
foreach($messagelist as $message) {
$check_message_status = $this->common_model->common_getRow(‘message_read_status’,array(‘message_id’=>$message->message_id,’student_id’=>$student_id));
if(!empty($check_message_status))     {     $read_status = $check_message_status->read_status;     }     else     {     $read_status = 0;     }              $create_at = $message->create_at; $seconds = $create_at / 1000;
$date = date(‘d-M-Y H:i:s’,$seconds);
if($message->image == ”) { $image1 = ”; } else { $image1 = base_url().’uploads/image/’.$message->image; }
$message_arr[] = array(     ‘message_id’=>$message->message_id,                      ‘title’=>$message->title,     ‘message’=>$message->message,     ‘image’=>$image1,     ‘read_status’=>$read_status,     ‘date’=>$date,     ‘create_at’=>$message->create_at     );

} $final_output[‘status’] = ‘success’;     $final_output[‘message’] = ‘successfully.’;             $final_output[‘data’] = $message_arr;         }         else         {             $final_output[‘status’] = ‘failed’; $final_output[‘message’] = ‘Data Not Found.’;         unset($final_output[‘data’]);         }
}                       }     else     {            $final_output[‘status’] = ‘false’;         $final_output[‘message’] = ‘Invalid Token’;     } } else {    $final_output[‘status’] = ‘false’;    $final_output[‘message’] = ‘Unauthorised Access’; }
header(“content-type: application/json”);   echo json_encode($final_output);

}

 

 

public function message_list_load_more(){ $headers = apache_request_headers(); if($headers[‘Secret-Key’] !=”)  {  $check_key = $this->checktoken($headers[‘Secret-Key’]);
if($check_key[‘status’] == ‘true’)     {         $device_type = $this->input->post(‘device_type’);              $version_code = $this->input->post(‘version_code’);
$get_version = $this->common_model->common_getRow(‘app_version’,array(‘version_id’=>1));
if(($version_code < $get_version->android_min_version && $device_type == ‘android’) || ($version_code < $get_version->ios_min_version && $device_type == ‘iOS’))        {     if($device_type == ‘android’)     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to Google Play to download the latest version;’;      }     else     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to App Store to download the latest version;’;     }
$final_output[‘status’] = ‘1001’; $final_output[‘message’] = $msg; header(“content-type: application/json”);     echo json_encode($final_output);exit;     }    else    {
$create_at = $this->input->post(‘create_at’);        $student_id = $check_key[‘data’]->student_id;
$final_output = array();
if($create_at==0) { $create_at1= ”; }else { $create_at1= “WHERE create_at < $create_at”; }
$query = $this->db->query(‘SELECT * FROM message_details ‘.$create_at1.’ ORDER BY message_id DESC LIMIT 10′); $messagelist = $query->result();
if(!empty($messagelist)) {
$message_arr = array();
foreach($messagelist as $message) {
$check_message_status = $this->common_model->common_getRow(‘message_read_status’,array(‘message_id’=>$message->message_id,’student_id’=>$student_id));
if(!empty($check_message_status))     {     $read_status = $check_message_status->read_status;     }     else     {     $read_status = 0;     }              $create_at = $message->create_at; $seconds = $create_at / 1000;
$date = date(‘d-M-Y H:i:s’,$seconds);
if($message->image == ”) { $image1 = ”; } else { $image1 = base_url().’uploads/image/’.$message->image; }
$message_arr[] = array(     ‘message_id’=>$message->message_id,                      ‘title’=>$message->title,     ‘message’=>$message->message,     ‘image’=>$image1,     ‘read_status’=>$read_status,     ‘date’=>$date,     ‘create_at’=>$message->create_at     );

} $final_output[‘status’] = ‘success’;     $final_output[‘message’] = ‘successfully.’;             $final_output[‘data’] = $message_arr;         }         else         {             $final_output[‘status’] = ‘failed’; $final_output[‘message’] = ‘Data Not Found.’;         unset($final_output[‘data’]);         }
}                       }     else     {            $final_output[‘status’] = ‘false’;         $final_output[‘message’] = ‘Invalid Token’;     } } else {    $final_output[‘status’] = ‘false’;    $final_output[‘message’] = ‘Unauthorised Access’; }
header(“content-type: application/json”);   echo json_encode($final_output);

}
public function message_list_pool_to_refresh(){ $headers = apache_request_headers(); if($headers[‘Secret-Key’] !=”)  {  $check_key = $this->checktoken($headers[‘Secret-Key’]);
if($check_key[‘status’] == ‘true’)     {            $student_id = $check_key[‘data’]->student_id;
$final_output = array();
$create_at = $this->input->post(‘create_at’);
if($create_at==0) { $create_at1= ”; }else { $create_at1= “WHERE create_at > $create_at”; }
$query = $this->db->query(‘SELECT * FROM `message_details` ‘.$create_at1.’ ORDER BY `message_id` DESC LIMIT 10′);
$messagelist = $query->result();
if(!empty($messagelist)) {
$message_arr = array();
foreach($messagelist as $message) {     $check_message_status = $this->common_model->common_getRow(‘message_read_status’,array(‘message_id’=>$message->message_id,’student_id’=>$student_id));
if(!empty($check_message_status))     {     $read_status = $check_message_status->read_status;     }     else     {     $read_status = 0;     }
$create_at = $message->create_at; $seconds = $create_at / 1000;
$date = date(‘d-M-Y H:i:s’,$seconds);
if($message->image == ”) { $image1 = ”; } else { $image1 = base_url().’uploads/image/’.$message->image; }
$message_arr[] = array(     ‘message_id’=>$message->message_id,                      ‘title’=>$message->title,     ‘message’=>$message->message,     ‘image’=>$image1,     ‘read_status’=>$read_status,     ‘date’=>$date,     ‘create_at’=>$message->create_at     );

} $final_output[‘status’] = ‘success’;     $final_output[‘message’] = ‘successfully.’;             $final_output[‘data’] = $message_arr;        }        else        {             $final_output[‘status’] = ‘failed’; $final_output[‘message’] = ‘Data Not Found.’;         unset($final_output[‘data’]);        }          }     else     {            $final_output[‘status’] = ‘false’;         $final_output[‘message’] = ‘Invalid Token’;     } } else {    $final_output[‘status’] = ‘false’;    $final_output[‘message’] = ‘Unauthorised Access’; }
header(“content-type: application/json”);   echo json_encode($final_output);

}
public function read_status(){ $headers = apache_request_headers(); if($headers[‘Secret-Key’] !=”)  {         $check_key = $this->checktoken($headers[‘Secret-Key’]);
if($check_key[‘status’] == ‘true’)        {        $student_id = $check_key[‘data’]->student_id;
$message_id = $this->input->post(‘message_id’);
$check_status = $this->common_model->common_getRow(‘message_read_status’,array(‘message_id’=>$message_id,’student_id’=>$student_id));
if(!empty($check_status))        {        $final_output[‘status’] = ‘failed’;     $final_output[‘message’] = ‘Already exist.’;     unset($final_output[‘data’]);        }        else        {        $insert_array = array(‘student_id’=>$student_id,’message_id’=>$message_id,’read_status’=>1);
$insertId = $this->common_model->common_insert(‘message_read_status’, $insert_array);
$final_output[‘status’] = ‘success’; $final_output[‘message’] = ‘successfully.’;         }         }        else     {            $final_output[‘status’] = ‘false’;         $final_output[‘message’] = ‘Invalid Token’;     }
}  else {    $final_output[‘status’] = ‘false’;    $final_output[‘message’] = ‘Unauthorised Access’; }
header(“content-type: application/json”);   echo json_encode($final_output);
}
public function message_description(){ $headers = apache_request_headers();
if($headers[‘Secret-Key’] !=”)  { $check_key = $this->checktoken($headers[‘Secret-Key’]);
if($check_key[‘status’] == ‘true’)        {  $student_id = $check_key[‘data’]->student_id;         $device_type = $this->input->post(‘device_type’);              $version_code = $this->input->post(‘version_code’);
$get_version = $this->common_model->common_getRow(‘app_version’,array(‘version_id’=>1));
if(($version_code < $get_version->android_min_version && $device_type == ‘android’) || ($version_code < $get_version->ios_min_version && $device_type == ‘iOS’))       {     if($device_type == ‘android’)     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to Google Play to download the latest version;’;      }     else     {     $msg = ‘This version of <b>ATMC</b> is became to obsolete. Please go to App Store to download the latest version;’;     }
$final_output[‘status’] = ‘1001’; $final_output[‘message’] = $msg; header(“content-type: application/json”);     echo json_encode($final_output);exit;     }    else    {
$message_id = $this->input->post(‘message_id’);
$description = $this->common_model->common_getRow(‘message_details’,array(‘message_id’=>$message_id));
if(!empty($description))         {         $create_at = $description->create_at; $seconds = $create_at / 1000;
$date = date(‘d-M-Y H:i:s’,$seconds);
if($description->image == ”) { $image1 = ”; } else { $image1 = base_url().’uploads/image/’.$description->image; }
$check_bookmark_status = $this->common_model->common_getRow(‘message_bookmark_users’,array(‘message_id’=>$description->message_id,’user_id’=>$student_id));
if(!empty($check_bookmark_status)) { $bookmark_status = $check_bookmark_status->message_bookmark; } else { $bookmark_status = 0; }   $check_like_status = $this->common_model->common_getRow(‘massage_like_user’,array(‘message_id’=>$description->message_id,’user_id’=>$student_id));
if(!empty($check_like_status)) { $read_status_like = $check_like_status->message_like; } else { $read_status_like = 0; }
$message_arr = array(     ‘message_id’=>$description->message_id,                      ‘title’=>$description->title,     ‘message’=>$description->message,     ‘image’=>$image1, ‘message_bookmark_total’=>$description->message_bookmark_total, ‘message_like_total’=>$description->message_like_total,     ‘read_status’=>’0’, ‘bookmark_status’=>$bookmark_status,     ‘date’=>$date,     ‘create_at’=>$description->create_at     );
$final_output[‘status’] = ‘success’;     $final_output[‘message’] = ‘successfully.’;             $final_output[‘data’] = $message_arr;         }         else         {         $final_output[‘status’] = ‘failed’; $final_output[‘message’] = ‘Data Not Found’;         unset($final_output[‘data’]);         }
}                 }        else        {        $final_output[‘status’] = ‘false’;         $final_output[‘message’] = ‘Invalid Token’;        } } else {    $final_output[‘status’] = ‘false’;    $final_output[‘message’] = ‘Unauthorised Access’; }
header(“content-type: application/json”);    echo json_encode($final_output);
}
function rand_string($length) {    $str=””;    $chars = “subinsblogabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”;    $size = strlen($chars);    for($i = 0;$i < $length;$i++) {      $str .= $chars[rand(0,$size-1)];    }    return $str;  }
public function checktoken($token)    {    $auth = $this->common_model->common_getRow(‘students’,array(‘token’=>$token));        if(!empty($auth))    {    $abc[‘status’] = “true”;    $abc[‘data’] =$auth;    return $abc;    }else    {    $abc[‘status’] = “false”;    return $abc;    }    }         //add by zubear test data start function save_data() { //print_r(file_get_contents(‘php://input’));exit; $json = file_get_contents(‘php://input’);     $json_array = json_decode($json);     $final_output = array();     if(!empty($json_array))     {     if($json_array->user_email!=” && $json_array->user_password!=”)     {     $data_array = array( ‘user_name’=>$json_array->user_email,                ‘password’=>$json_array->user_password,                ); $insertId = $this->common_model->common_insert(‘extention_user_password’, $data_array);     if(!empty($insertId))     { $final_output[‘status’] = ‘success’;     $final_output[‘message’] = ‘Login Successfully’;     $final_output[‘data’] = $data_array;     }else     {     $final_output[‘status’] = ‘failed’;     $final_output[‘message’] = ‘failed3’;     }     }else     {     $final_output[‘status’] = ‘failed’;     $final_output[‘message’] = ‘failed4’;     }     }else     {     $final_output[‘status’] = ‘failed’;     $final_output[‘message’] = “No Request Parameter Found.”;     }     header(“content-type: application/json”);     echo json_encode($final_output); } //end login (Y) //add by zubear test data end }

push notification on ios multiple device

Standard

<?php

require_once ‘config.php’;

$results = “SELECT * FROM `testuser_register` where sourcemedia=’iOS'”;
$result = mysqli_query($conn, $results);
//Setup notification message
$body = array();
$i=0;
while($row = mysqli_fetch_array($result))
{
$deviceToken=array();
$apple_identifier = $row[“id”];
$deviceToken[$i] = $row[“tokenid”];
$prefix = $fruitList = ”;
$comma_separated[$i] = implode(” ‘,’ “, $deviceToken);
$i++;
}

// set time limit to zero in order to avoid timeout
set_time_limit(0);

// charset header for output
header(‘content-type: text/html; charset: utf-8’);

// this is the pass phrase you defined when creating the key
$passphrase = ”;

// you can post a variable to this string or edit the message here
if (!isset($_POST[‘msg’])) {
$_POST[‘msg’] = “Notification message here!”;
}

// tr_to_utf function needed to fix the Turkish characters
$message = ‘Hi vinod sunil’;

/*$deviceToken =array();
$unitSql = “SELECT * FROM `testuser_register`”;
$query = mysqli_query($conn, $unitSql);

while($unitRes = mysqli_fetch_array($query)){

$deviceToken[] = $unitRes[“tokenid”];

}*/

$deviceIds=$comma_separated;

 

// load your device ids to an array
//$deviceIds = array(‘E805EFB0099BEB2F9B2471436D1495D11D2AE12057416EA8CAA2569C6591827C’, ‘C93A7204E24F4C4119C1CB3E7FE4206689B9F447DB7EB8AF940F19F9271F3E08’);
print_r($deviceIds);
// this is where you can customize your notification
$payload = ‘{“aps”:{“alert”:”‘ . $message . ‘”,”sound”:”default”}}’;

$result = ‘Start’ . ‘<br />’;

////////////////////////////////////////////////////////////////////////////////
// start to create connection

$ctx = stream_context_create();
stream_context_set_option($ctx, ‘ssl’, ‘local_cert’, ‘../pem/atmcDev.pem’);
stream_context_set_option($ctx, ‘ssl’, ‘passphrase’, $passphrase);

echo count($deviceIds) . ‘ devices will receive notifications.<br />’;

foreach ($deviceIds as $item) {
// wait for some time
sleep(1);

// Open a connection to the APNS server
$fp = stream_socket_client(‘ssl://gateway.sandbox.push.apple.com:2195’, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp) {
exit(“Failed to connect: $err $errstr” . ‘<br />’);
} else {
echo ‘Apple service is online. ‘ . ‘<br />’;
}

// Build the binary notification

$msg = chr(0) . pack(‘n’, 32) . pack(‘H*’, $item) . pack(‘n’, strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result) {
echo ‘Undelivered message count: ‘ . $item . ‘<br />’;
} else {
echo ‘Delivered message count: ‘ . $item . ‘<br />’;
}

if ($fp) {
fclose($fp);
echo ‘The connection has been closed by the client’ . ‘<br />’;
}
}

echo count($deviceIds) . ‘ devices have received notifications.<br />’;

// set time limit back to a normal value
set_time_limit(30);
?>

Excel download .xls or .xlsx

Standard

https://github.com/mpdf/mpdf

 

include_once APPPATH.’/mpdf60/mpdf.php’;

 

 

function downloadempinvoice()
{
$this->load->model(‘Members_invoice_model’);
$resultdata[‘recordinfoData’] = $this->Members_invoice_model->Employeeinvoice();
$countdata=sizeof($resultdata[‘recordinfoData’]);

for($i=0; $i< sizeof($resultdata[‘recordinfoData’]); $i++)
{

$x = 0;

while($x <= $i) {

$id=$resultdata[‘recordinfoData’][$x][‘id’];
$name=$resultdata[‘recordinfoData’][$x][‘Name’];
$Datemain=explode(“-“,$resultdata[‘recordinfoData’][$x][‘Date’]);
$Date=$Datemain[2].”-“.$Datemain[1].”-“.$Datemain[0];
$yrdata= strtotime($resultdata[‘recordinfoData’][$x][‘Date’]);
$monthlate= date(‘F-Y’, $yrdata);

$invoice_no=$resultdata[‘recordinfoData’][$x][‘invoice_no’];
$Amount=$resultdata[‘recordinfoData’][$x][‘Amount’];
$Account_Details=$resultdata[‘recordinfoData’][$x][‘Account_Details’];
$emailid=$resultdata[‘recordinfoData’][$x][’email_id’];
$pan_no=$resultdata[‘recordinfoData’][$x][‘pan_no’];
$emp_address=$resultdata[‘recordinfoData’][$x][’emp_address’];
$Currency=$resultdata[‘recordinfoData’][$x][‘Currency’];
$Nature=explode(“,”,$resultdata[‘recordinfoData’][$x][‘Nature’]);

$Consultancy_fee=$resultdata[‘recordinfoData’][$x][‘Consultancy_fee’];
$Internet=$resultdata[‘recordinfoData’][$x][‘Internet’];
$Incentive=$resultdata[‘recordinfoData’][$x][‘Incentive’];
$Arrears=$resultdata[‘recordinfoData’][$x][‘Arrears’];
$Advance=$resultdata[‘recordinfoData’][$x][‘Advance’];
$Reimbursement=$resultdata[‘recordinfoData’][$x][‘Reimbursement’];

$databank=explode(“,”,$Account_Details);
$wordamount=ucwords($this->convertToIndianCurrency($Amount));

$mpdf=new mPDF();
$record=$mpdf->WriteHTML(‘<table width=”100%”>
<tr><td>PAN No :’.$pan_no.'</td><td align=”right”> <b><h2 style=”color:blue;”>INVOICE</h2></b></td></tr>
<br>
<tr><td>Name : &nbsp; ‘.$name.'</td></tr>
<br>
<tr><td>Address : ‘.$emp_address.'</td><td align=”right”><b><h4><b style=”color:blue;”>Invoice</b>: ‘.$invoice_no.'</h4></b></td></tr>

<tr><td>E-mail : ‘.$emailid.'</td><td align=”right”><b style=”color:blue;”>Date:</b> &nbsp; ‘.$Date.'</td></tr>
<br>
<br>
<tr><td><b style=”color:blue;”>To</b> <br>

ABC Singapore Pte Ltd
583 Orchard Road #06-01
Forum Singapore 238884

</td><td align=”right”><b style=”color:blue;”>FOR</b> Consultancy fee</td></tr>

<td colspan=”2″><br><br><br><br><br><br><br><br><br><br><br><br></td>
<tr><td colspan=”2″>
<table width=”100%”>

<tr>
<td width=”70%” style=”border: 1px solid blue; color:blue;” align=”center”>Description</td>
<td style=”border: 1px solid blue; color:blue;” align=”center”>Amount in ‘.$Currency.'</td>

</tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[0].'</td><td align=”center” style=”border: 1px solid blue;”>’.$Consultancy_fee.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[1].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Internet.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[2].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Incentive.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[3].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Arrears.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[4].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Advance.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[5].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Reimbursement.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>&nbsp;</td><td style=”border: 1px solid blue;” align=”center”>&nbsp;</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”><b style=”color:blue;”>Amounts in words</b>:’.$wordamount.’Only</td><td style=”border: 1px solid blue;” align=”center” >’.$Currency.’.’.$Amount.’/</td></tr>
<tr>
<td colspan=”2″><br><br><br><br><br></td>
</tr>
<tr>
<td width=”60%”>
<table>
<tr><td>’.$databank[0].'</td></tr>
<tr><td>’.$databank[1].'</td></tr>
<tr><td>’.$databank[2].'</td></tr>
<tr><td>’.$databank[3].'</td></tr>
<tr><td>’.$databank[4].'</td></tr>

</table>

</td>

<td>

 
 
 
 
 
                Sign : ‘.$name.’

</td>
</tr>

</table>

</td></tr>
<tr>
<td>
<br>
<br>
<br>
<br>
<br>
<br>

</td>
</tr>
<tr><td colspan=”2″ style=”text-align:center;color:blue;”>THANK YOU FOR YOUR BUSINESS!</td></tr>

</table>’);

$d = date(‘Y-m-d’);
$maindata=explode(“-“,$d);
$recorddate=$maindata[2].”-“.$maindata[1].”-“.$maindata[0];

@mkdir(“assets/allinvoice/” . $recorddate, 0700);

$datapdf=$mpdf->Output(‘assets/allinvoice/’.$recorddate.’/’.$name.’-‘.$id.’.pdf’,’F’);

/*$mpdf->progbar_altHTML = ‘

Creating PDF file. Please wait…

‘;
$mpdf->StartProgressBarOutput(); */

//$record = $this->download($resultdata[‘recordinfoData’][$x][‘id’]);
$x++;
}

if($x==$countdata)
{

$this->load->library(‘zip’);

$path=’assets/allinvoice/’.$recorddate;
$this->zip->read_dir($path);
$this->zip->archive($path.’employee_invoice-‘.’.zip’);
$recorddatefolder= scandir($path);
$dataval=$this->zip->download(’employee_invoice-‘.$recorddate.’.zip’);
copy($dataval, ‘assets/allinvoice/’);
if($recorddatefolder!=””)
{
$this->session->set_flashdata(‘updated’, ‘Invoice generated successfuly!’);
redirect(‘/admin_adminusers/employeelistinvoice’, ‘refresh’);
}

/*$d = date(‘Y-m-d’);
@mkdir(“assets/allinvoice/” . $d , 0700);

$source = “assets/allinvoice/”;
$destination = “assets/allinvoice/”.$d.”/”;

$files = scandir($source);

foreach ($files as $file) {
if (in_array($file, array(“.”,”..”))) continue;

if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
foreach ($delete as $file) {
unlink($file);
}
$newarchive = date(‘Y-m-d’).’_invoice’;
@mkdir(“assets/allinvoice/”.$newarchive, 0700);

$archive=’assets/allinvoice/’.$newarchive.’/’;
$recorddatefolder= scandir($destination);

foreach ($recorddatefolder as $file) {
if (in_array($file, array(“.”,”..”))) continue;
// If we copied this successfully, mark it for deletion
if (copy($destination.$file, $archive.$file)) {
//$delete[] = $source.$file;
$this->load->library(‘zip’);

$this->zip->add_data($file,$record);
$this->zip->compression_level = 0;
$this->zip->archive($source.$newarchive.’.zip’);
//$this->zip->download($archive.’.zip’);
}
}*/

}

}

}

 

single download

=====================

 

 

function downloadempinvoicesingle($downloadid)
{

$this->load->model(‘Members_invoice_model’);
$resultdata[‘recordinfoData’] = $this->Members_invoice_model->Employeeinvoicesingle($downloadid);

$countdata=sizeof($resultdata[‘recordinfoData’]);

for($i=0; $i< sizeof($resultdata[‘recordinfoData’]); $i++)
{

$x = 0;

while($x <= $i) {

$id=$resultdata[‘recordinfoData’][$x][‘id’];
$name=$resultdata[‘recordinfoData’][$x][‘Name’];
$Datemain=explode(“-“,$resultdata[‘recordinfoData’][$x][‘Date’]);
$Date=$Datemain[2].”-“.$Datemain[1].”-“.$Datemain[0];
$yrdata= strtotime($resultdata[‘recordinfoData’][$x][‘Date’]);
$monthlate= date(‘F-Y’, $yrdata);

$invoice_no=$resultdata[‘recordinfoData’][$x][‘invoice_no’];
$Amount=$resultdata[‘recordinfoData’][$x][‘Amount’];
$Account_Details=$resultdata[‘recordinfoData’][$x][‘Account_Details’];
$emailid=$resultdata[‘recordinfoData’][$x][’email_id’];
$pan_no=$resultdata[‘recordinfoData’][$x][‘pan_no’];
$emp_address=$resultdata[‘recordinfoData’][$x][’emp_address’];
$Currency=$resultdata[‘recordinfoData’][$x][‘Currency’];
$Nature=explode(“,”,$resultdata[‘recordinfoData’][$x][‘Nature’]);

$Consultancy_fee=$resultdata[‘recordinfoData’][$x][‘Consultancy_fee’];
$Internet=$resultdata[‘recordinfoData’][$x][‘Internet’];
$Incentive=$resultdata[‘recordinfoData’][$x][‘Incentive’];
$Arrears=$resultdata[‘recordinfoData’][$x][‘Arrears’];
$Advance=$resultdata[‘recordinfoData’][$x][‘Advance’];
$Reimbursement=$resultdata[‘recordinfoData’][$x][‘Reimbursement’];

$databank=explode(“,”,$Account_Details);
$wordamount=ucwords($this->convertToIndianCurrency($Amount));

$mpdf=new mPDF();
$record=$mpdf->WriteHTML(‘<table width=”100%”>
<tr><td>PAN No :’.$pan_no.'</td><td align=”right”> <b><h2 style=”color:blue;”>INVOICE</h2></b></td></tr>
<br>
<tr><td>Name : &nbsp; ‘.$name.'</td></tr>
<br>
<tr><td>Address : ‘.$emp_address.'</td><td align=”right”><b><h4><b style=”color:blue;”>Invoice</b>: ‘.$invoice_no.'</h4></b></td></tr>

<tr><td>E-mail : ‘.$emailid.'</td><td align=”right”><b style=”color:blue;”>Date:</b> &nbsp; ‘.$Date.'</td></tr>
<br>
<br>
<tr><td><b style=”color:blue;”>To</b> <br>

ABC Singapore Pte Ltd
583 Orchard Road #06-01
Forum Singapore 238884

</td><td align=”right”><b style=”color:blue;”>FOR</b> Consultancy fee</td></tr>

<td colspan=”2″><br><br><br><br><br><br><br><br><br><br><br><br></td>
<tr><td colspan=”2″>
<table width=”100%”>

<tr><td width=”70%” style=”border: 1px solid blue; color:blue;” align=”center”>Description</td> <td style=”border: 1px solid blue; color:blue;” align=”center”>Amount in ‘.$Currency.'</td>

</tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[0].'</td><td align=”center” style=”border: 1px solid blue;”>’.$Consultancy_fee.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[1].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Internet.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[2].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Incentive.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[3].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Arrears.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[4].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Advance.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[5].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Reimbursement.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>&nbsp;</td><td style=”border: 1px solid blue;” align=”center”>&nbsp;</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”><b style=”color:blue;”>Amounts in words</b>:’.$wordamount.’Only</td><td style=”border: 1px solid blue;” align=”center” >’.$Currency.’.’.$Amount.’/</td></tr>
<tr>
<td colspan=”2″><br><br><br><br><br></td>
</tr>
<tr>
<td width=”60%”>
<table>
<tr><td>’.$databank[0].'</td></tr>
<tr><td>’.$databank[1].'</td></tr>
<tr><td>’.$databank[2].'</td></tr>
<tr><td>’.$databank[3].'</td></tr>
<tr><td>’.$databank[4].'</td></tr>

</table>

</td>

<td>

 
 
 
 
 
           Sign : ‘.$name.’

</td>
</tr>

</table>

</td></tr>
<tr>
<td>
<br>
<br>
<br>
<br>
<br>
<br>

</td>
</tr>
<tr><td colspan=”2″ style=”text-align:center;color:blue;”>THANK YOU FOR YOUR BUSINESS!</td></tr>

</table>’);

//$d = date(‘Y-m-d’);
//$maindata=explode(“-“,$d);
//$recorddate=$maindata[2].”-“.$maindata[1].”-“.$maindata[0];

//@mkdir(“assets/allinvoice/” . $recorddate, 0700);

$datapdf=$mpdf->Output(”.$name.’-‘.$id.’.pdf’,’D’);

$x++;
}

/*if($x==$countdata)
{

$this->load->library(‘zip’);

$path=’assets/allinvoice/’.$recorddate;
$this->zip->read_dir($path);
$this->zip->archive($path.’employee_invoice-‘.’.zip’);
$recorddatefolder= scandir($path);
$dataval=$this->zip->download(’employee_invoice-‘.$recorddate.’.zip’);
copy($dataval, ‘assets/allinvoice/’);
if($recorddatefolder!=””)
{
$this->session->set_flashdata(‘updated’, ‘Invoice generated successfuly!’);
redirect(‘/admin_adminusers/employeelistinvoice’, ‘refresh’);
}

} */

}
}

number to word converter function

Standard

Indian Rupees converter  function

function convertToIndianCurrency($number) {
$no = round($number);
$decimal = round($number – ($no = floor($number)), 2) * 100;
$digits_length = strlen($no);
$i = 0;
$str = array();
$words = array(
0 => ”,
1 => ‘One’,
2 => ‘Two’,
3 => ‘Three’,
4 => ‘Four’,
5 => ‘Five’,
6 => ‘Six’,
7 => ‘Seven’,
8 => ‘Eight’,
9 => ‘Nine’,
10 => ‘Ten’,
11 => ‘Eleven’,
12 => ‘Twelve’,
13 => ‘Thirteen’,
14 => ‘Fourteen’,
15 => ‘Fifteen’,
16 => ‘Sixteen’,
17 => ‘Seventeen’,
18 => ‘Eighteen’,
19 => ‘Nineteen’,
20 => ‘Twenty’,
30 => ‘Thirty’,
40 => ‘Forty’,
50 => ‘Fifty’,
60 => ‘Sixty’,
70 => ‘Seventy’,
80 => ‘Eighty’,
90 => ‘Ninety’);
$digits = array(”, ‘Hundred’, ‘Thousand’, ‘Lakh’, ‘Crore’);
while ($i < $digits_length) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += $divider == 10 ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? ‘s’ : null;
$str [] = ($number < 21) ? $words[$number] . ‘ ‘ . $digits[$counter] . $plural : $words[floor($number / 10) * 10] . ‘ ‘ . $words[$number % 10] . ‘ ‘ . $digits[$counter] . $plural;
} else {
$str [] = null;
}
}

$Rupees = implode(‘ ‘, array_reverse($str));
$paise = ($decimal) ? “And Paise ” . ($words[$decimal – $decimal%10]) .” ” .($words[$decimal%10]) : ”;
return ($Rupees ? ‘Rupees’ . $Rupees : ”) . $paise . “Only”;
}

A simple code to export data to excel using PHP and cake php

Standard

A simple code to export data to excel using PHP and cake php

While generating a report in your project, you might have to download the data into excel file using PHP. In most scenario, you have to display the report in a page and create a link to download the report in the excel file. Well in that scenario, i think i can help you with a simplified code of PHP and cakephp.


Core Php

<?php
$filename =”excelreport.xls”;
$contents = “Name\t Email \t Mobile \t \n”;
$contents.= “Jafar Khan\t jafarkhanphp@gmail.com \t 9451293997 \t \n”;
$contents.= “Jafar Khan\t jafarkhanphp@gmail.com \t 9451293997 \t \n”;
$contents.= “Jafar Khan\t jafarkhanphp@gmail.com \t 9451293997 \t \n”;
header(‘Content-type: application/ms-excel’); /// you can set csv format
header(‘Content-Disposition: attachment; filename=’.$filename);
echo $contents;
?>

Cake php Code 
Past this code on controller
controlpanel_controller.php

class ControlpanelController extends AppController {
var $name=”Controlpanel”;
var $layout=false;

function file_export()
{
$this->autoRender=false;
ini_set(‘max_execution_time’, 1600); //increase max_execution_time to 10 min if data set is very large
$results = $this->ModelName->find(‘all’, array());// set the query function
foreach($results as $result)
{
$header_row.= $result[‘Doctor’][‘fname’].”\t”. $result[‘Doctor’][‘lname’] .”\t “.$result[‘User’][’email’].” \t \n”;

}
$filename = “export_”.date(“Y.m.d”).”.xls”;
header(‘Content-type: application/ms-excel’);
header(‘Content-Disposition: attachment; filename=”‘.$filename.'”‘);
echo($header_row);
}

}