<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class report extends MY_Controller{
	function __construct(){
        parent::__construct();
        $this->load->model('category_model', '', TRUE);
        $this->load->model('contact_model', '', TRUE);
        $this->load->model('event_model', '', TRUE);
        $this->load->model('inviteinevent_model', '', TRUE);
        $this->load->model('route_model', '', TRUE);
        // if($this->data['userid']==''){
        //     redirect($this->data['base_url'] . 'home');   
        //     exit;
        // }
        $this->load->library("Pdf");
    }
    function contact(){
        if($this->input->post()){
            $catagory = $this->input->post('catagory');
            $reportview = $this->input->post('reportview');
            ob_clean();
            if($reportview=='View Report'){
                if(!empty($catagory)){
                    $catagory = $this->input->post('catagory');
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                        $cat_details = $this->category_model->single_category_details($catagoryvalue);
                        $contact_details = $this->contact_model->contact_details($catagoryvalue);
                        $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">'.strtoupper($cat_details['name']).'</th>';
                                     $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($contactkey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                        
                                    $html .='</tr>';
                                }
                            }
                        $html .= '</table>';
                        echo $html;
                    }
                }else{
                    $catagory = $this->category_model->allcategory_details();
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                       
                        $contact_details = $this->contact_model->contact_details($catagoryvalue['id']);
                        $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">'.strtoupper($catagoryvalue['name']).'</th>';
                                     $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($contactkey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                        
                                    $html .='</tr>';
                                }
                            }
                        $html .= '</table>';
                        echo $html;
                    }
                }
                exit;
            }
            if($reportview=='Export in PDF'){
                $pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
                $pdf->SetFont('helvetica', '', 8);
                if(!empty($catagory)){
                    $catagory = $this->input->post('catagory');
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                        $pdf->AddPage(); 
                        $cat_details = $this->category_model->single_category_details($catagoryvalue);
                        $contact_details = $this->contact_model->contact_details($catagoryvalue);
                        $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:10px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">'.strtoupper($cat_details['name']).'</th>';
                                     $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:8px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($contactkey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                    $html .='</tr>';
                                }
                            }
                        $html .= '</table>';
                        $pdf->writeHTML($html, true, 0, true, 0);
                    }
                }else{
                    $catagory = $this->category_model->allcategory_details();
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                        $pdf->AddPage(); 
                        $contact_details = $this->contact_model->contact_details($catagoryvalue['id']);
                        $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:10px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">'.strtoupper($catagoryvalue['name']).'</th>';
                                     $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:8px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($contactkey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                    $html .='</tr>';
                                }
                            }
                        $html .= '</table>';
                        $pdf->writeHTML($html, true, 0, true, 0);
                    }
                } 
                $pdf->Output('contact_list.pdf', 'I');  
            }
            if($reportview=='Export in Excel'){
                header("Content-type: application/vnd-ms-excel");
                header("Content-Disposition: attachment; filename=contact_list.xls");
                if(!empty($catagory)){
                    $catagory = $this->input->post('catagory');
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                        $cat_details = $this->category_model->single_category_details($catagoryvalue);
                        $contact_details = $this->contact_model->contact_details($catagoryvalue);
                        $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">'.strtoupper($cat_details['name']).'</th>';
                                     $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($contactkey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                        
                                    $html .='</tr>';
                                }
                            }
                        $html .= '</table>';
                        echo $html;
                    }
                }else{
                    $catagory = $this->category_model->allcategory_details();
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                       
                        $contact_details = $this->contact_model->contact_details($catagoryvalue['id']);
                        $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">'.strtoupper($catagoryvalue['name']).'</th>';
                                     $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($contactkey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                        
                                    $html .='</tr>';
                                }
                            }
                        $html .= '</table>';
                        echo $html;
                    }
                }
                exit;
            }
            // if($reportview=='Sticker View'){
            //     $pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
            //     $pdf->SetTitle('Address Sticker');
            //     $pdf->SetFont('helvetica', '', 11);
            //     if(!empty($catagory)){
            //         $catagory = $this->input->post('catagory');
            //         $cat_details = $this->category_model->single_category_details($catagoryvalue);
            //         foreach ($catagory as $catagorykey => $catagoryvalue) {
            //             $pdf->AddPage(); 
            //             $contact_details = $this->contact_model->contact_details($catagoryvalue);
            //             $html = '<table  cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
            //             if(!empty($contact_details)){
            //                $i=0;
            //                foreach ($contact_details as $contactkey => $contactvalue) {
            //                     if($i==0){
            //                         $html .='<tr width="100%" >'; 
            //                     }
            //                     $html .='<td>';
            //                          $html .='<table align="left" border="1" cellpadding="4" cellspacing="0"><tr width="33.33%"><td height="117px"><b>To,<br>'.strtoupper(nl2br($contactvalue['name'])).' </b><br>'.strtolower(nl2br($contactvalue['address'])).'<br>'.ucwords(ucwords($contactvalue['city'])).'.<br>CONTECT NO : '.$contactvalue['mobile'].'</td>
            //                             </tr></table>';
            //                     $html .='</td>';
                               
            //                     $i++;
            //                     if($i==3){
            //                         $html .='</tr>';
            //                         $i=0;
            //                     }
            //                 }
            //             }
            //             $html .= '</table>';
            //             $pdf->writeHTML($html, true, 0, true, 0);
            //         }
            //     }else{
            //         $catagory = $this->category_model->allcategory_details();
            //         foreach ($catagory as $catagorykey => $catagoryvalue) {
            //             $pdf->AddPage(); 
            //             $contact_details = $this->contact_model->contact_details($catagoryvalue['id']);
            //             $html = '<table cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
            //             if(!empty($contact_details)){
            //                $i=0;
            //                foreach ($contact_details as $contactkey => $contactvalue) {
            //                     if($i==0){
            //                         $html .='<tr width="100%" >'; 
            //                     }
            //                     $html .='<td>';
            //                          $html .='<table align="left" border="1" cellpadding="4" cellspacing="0"><tr width="50%"><td height="117px"><b>To,<br>'.strtoupper(nl2br($contactvalue['name'])).' </b><br>'.strtoupper(nl2br($contactvalue['address'])).'<br>'.ucwords(strtoupper($contactvalue['city'])).'.<br>CONTECT NO : '.strtoupper(nl2br($contactvalue['mobile'])).'</td>
            //                             </tr></table>';
            //                     $html .='</td>';
                               
            //                     $i++;
            //                     if($i==2){
            //                         $html .='</tr>';
            //                         $i=0;
            //                     }
            //                 }
            //             }
            //             $html .= '</table>';
            //             $pdf->writeHTML($html, true, 0, true, 0);
            //         }
            //     } 
            //     ob_end_clean();
            //     $pdf->Output('contact_sticker_view.pdf', 'I');  
            // }
            if($reportview=='Sticker View'){
                $pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
                $pdf->SetTitle('Address Sticker');
                $pdf->SetFont('helvetica', '', 11);
                if(!empty($catagory)){
                    $catagory = $this->input->post('catagory');
                    $cat_details = $this->category_model->single_category_details($catagoryvalue);
                    $cnt=0;
                    $i=1;
                    static $t=0;
                   
                    $html = '<table align="center" cellpadding="0" cellspacing="0" border="1" width="100%" style="font-size:11px;margin-top:30px;">';
                    foreach ($catagory as $catagorykey => $catagoryvalue) {
                        $contact_details = $this->contact_model->contact_details($catagoryvalue);
                        if(!empty($contact_details)){
                            foreach ($contact_details as $contactkey => $contactvalue) {
                                $t++;
                                if($t-1%3==0){              
                                     $html .="<tr>";
                                }  
                                $html .='<td align="center" style="width:6.4cm;height:3.8cm;">';
                                    $html .='<div style="margin-left:0px; margin-top:0px;">';
                                        $html .='<div style="margin-left:5px;font-size:12px;text-align: justify;">';
                                            $html .='<b>To, '.strtoupper(nl2br($contactvalue['name']))."</b>";
                                        $html .='</div>';
                                        $html .='<div style="margin-left:5px;text-align: justify;">';
                                             $html .=ucwords(strtolower(nl2br($contactvalue['address'])));
                                        $html .='</div>';
                                        $html .='<div style="margin-left:5px;text-align: justify;">';
                                             $html .=ucwords(strtolower($contactvalue['city']));
                                        $html .='</div>';
                                        $html .='<div style="margin-left:5px;text-align: justify;">';
                                             $html .='No : '.ucwords($contactvalue['mobile']);
                                        $html .='</div>';
                                    $html .='</div>';
                                $html .='</td>';
                               
                                if($t%3==0 && $t != 0){
                                    $html .= "</tr>";                       
                                }
                                if($t%21==0){
                                    $html .= "<tr> <td style='height:1.6cm;'><br/></td></tr>";
                                }   
                            }
                        }
                    }
                    $html .= '</table>';
                    
                }
                echo $html;exit;
            }
            
        }
        $this->data['category'] = $this->category_model->allcategory_details();
        $this->data['message'] = $this->session->flashdata('message');
        $this->data['breadcrumb']='Category Details';
        $this->data['tpl_name']= "report_contact_details.tpl";
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('template.tpl');  
    }
    function invite(){
        if($this->input->post()){
            $event = $this->input->post('event');
            $reportview = $this->input->post('reportview');
            ob_clean();
            if($reportview=='View Report'){
                if(!empty($event)){
                    $event = $this->input->post('event');
                    $grandtotal='0';
                    $totaladult='0';
                    $totalchild='0';
                    $eventid = implode(',',$event);
                    $vehicle = $this->input->post('vehicle');
                    $roomdate = $this->input->post('roomdate');
                    $route = $this->input->post('route');
                    $data['eventid']=$eventid;
                    $data['vehicle']=$vehicle;
                    $data['roomdate']=$roomdate;
                    $data['route']=$route;
                    $eventwiseview = $this->inviteinevent_model->reportdetailview($data);
                    $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th width="470" colspan="10">';
                                foreach ($event as $eventkey => $eventvalue) {
                                    $e_d = $this->event_model->single_event_details($eventvalue); 
                                    $html .=strtoupper($e_d['name'])."&nbsp;&nbsp;";
                                }
                                $html .='</th>';
                                $r_d = $this->route_model->single_route_details($route); 
                                $rd=strtoupper($r_d['name']);
                                $html .='<th colspan="2">Route : '.$rd.'</th>';
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="55">Sr No.</th>';
                            $html .='<th width="250">Name</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Number</th>';
                            $html .='<th width="70">Category</th>';
                            $html .='<th width="70">Adult</th>';
                            $html .='<th width="70">Child</th>';
                            $html .='<th width="70">Total</th>';
                            $html .='<th width="70">Vehicle</th>';
                            $html .='<th width="70">Room</th>';
                            $html .='<th width="70">Room Date</th>';
                            $html .='<th width="70">Route</th>';
                        $html .='</tr>';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $grandtotal =($grandtotal+intval($eventvalue['total']));
                                $totaladult =($totaladult+intval($eventvalue['adult']));
                                $totalchild =($totalchild+intval($eventvalue['child']));
                                $html .='<tr>';
                                    $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                    $html .='<td width="250" align="left">'.ucwords(strtolower($eventvalue['name']))."<br>".ucwords(strtolower(nl2br($eventvalue['address']))).'</td>';
                                    
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                   $html .='<td width="70" align="left">';
                                    $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                    foreach ($duplicat_details as $dkey => $dvalue) {
                                        $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                    }
                                    $html .='</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                                    $html .='<td  width="70" align="right">'.ucwords(strtolower($eventvalue['vehicle'])).'</td>';
                                    $html .='<td  width="70" align="right">'.ucwords(strtolower($eventvalue['room'])).'</td>';
                                    if($eventvalue['roomdate']!='0000-00-00'){
                                        $html .='<td width="70" align="right"> '.date('d-m-Y',strtotime($eventvalue['roomdate'])).'</td>';
                                    }else{
                                        $html .='<td></td>';
                                    }
                                    $html .='<td  width="70" align="right">'.ucwords(strtolower($eventvalue['route'])).'</td>';
                                $html .='</tr>';
                            }
                        }
                        $html .='<tr>';
                            $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                            $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                            $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                            $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                            $html .='<td  width="70" align="center">';
                                $vehicleby = array_count_values(array_column($eventwiseview, 'vehicle'));
                                                if(!empty($vehicleby)){
                                                    foreach ($vehicleby as $vehiclebykey => $vehiclebyvalue) {
                                                        $html .=ucwords(strtolower($vehiclebykey)). " = ". $vehiclebyvalue."<br>";
                                                    }
                                                }
                             $html .='</td>';
                             $html .='<td  colspan="3" width="70" align="center"></td>'; 
                        $html .='</tr>';
                    $html .= '</table>';
                    echo $html;
                }else{
                    $event = $this->event_model->allevent_details();
                    foreach ($event as $eventkey => $eventvalue) {
                       $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                       $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="8">';
                                        $html .=strtoupper($eventvalue['name'])."";
                                    $html .='</th>';
                                    
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="55">Sr No.</th>';
                                $html .='<th width="250">Name</th>';
                                $html .='<th width="70">Number</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Category</th>';
                                $html .='<th width="70">Adult</th>';
                                $html .='<th width="70">Child</th>';
                                $html .='<th width="70">Total</th>';
                            $html .='</tr>';
                            if(!empty($eventwiseview)){
                                foreach ($eventwiseview as $ekey => $eventvalue) {
                                    $grandtotal =($grandtotal+intval($eventvalue['total']));
                                    $totaladult =($totaladult+intval($eventvalue['adult']));
                                    $totalchild =($totalchild+intval($eventvalue['child']));
                                    $html .='<tr>';
                                        $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                        $html .='<td width="250" align="left">'.ucwords(strtolower($eventvalue['name'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                       $html .='<td width="70" align="left">';
                                        $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                        foreach ($duplicat_details as $dkey => $dvalue) {
                                            $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                        }
                                        $html .='</td>';
                                        $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                        $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                        $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                                    $html .='</tr>';
                                }
                            }
                            $html .='<tr>';
                                $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                                $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                                $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                                $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';

                            $html .='</tr>';
                       $html .= '</table>';
                       echo $html;
                    }
                }
                exit;
            }
            if($reportview=='Export in Excel'){
                header("Content-type: application/vnd-ms-excel");
                header("Content-Disposition: attachment; filename=invite_list.xls");
                if(!empty($event)){
                    $grandtotal='0';
                    $totaladult='0';
                    $totalchild='0';
                    $eventid = implode(',',$event);
                    $vehicle = $this->input->post('vehicle');
                    $roomdate = $this->input->post('roomdate');
                    $route = $this->input->post('route');
                    $data['eventid']=$eventid;
                    $data['vehicle']=$vehicle;
                    $data['roomdate']=$roomdate;
                    $data['route']=$route;
                    $eventwiseview = $this->inviteinevent_model->reportdetailview($data);
                    $html = '<table border="1" cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th colspan="8">';
                                foreach ($event as $eventkey => $eventvalue) {
                                    $e_d = $this->event_model->single_event_details($eventvalue); 
                                    $html .=strtoupper($e_d['name'])."&nbsp;&nbsp;";
                                }
                                $html .='</th>';
                                $r_d = $this->route_model->single_route_details($route); 
                                $rd=strtoupper($r_d['name']);
                                $html .='<th colspan="3">Route : '.$rd.'</th>';
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="30">Sr No.</th>';
                            $html .='<th width="170">Name</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Number</th>';
                            
                            $html .='<th width="120">Category</th>';
                            $html .='<th width="40">Adult</th>';
                            $html .='<th width="40">Child</th>';
                            $html .='<th width="40">Total</th>';
                            $html .='<th width="65">Vehicle</th>';
                            $html .='<th width="70">Room</th>';
                            $html .='<th width="70">Room Date</th>';
                        $html .='</tr>';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $grandtotal =($grandtotal+intval($eventvalue['total']));
                                $totaladult =($totaladult+intval($eventvalue['adult']));
                                $totalchild =($totalchild+intval($eventvalue['child']));
                                $html .='<tr>';
                                    $html .='<td width="30"  align="center">'.($ekey+1).'</td>';
                                    $html .='<td width="170" align="left">'.ucwords(strtolower(nl2br($eventvalue['name'])))."<br>".ucwords(strtolower(nl2br($eventvalue['address']))).'</td>';
                                    
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower(nl2br($eventvalue['mobile']))).'</td>';
                                   $html .='<td width="120" align="left">';
                                    $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                    foreach ($duplicat_details as $dkey => $dvalue) {
                                        $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                    }
                                    $html .='</td>';
                                    $html .='<td  width="40" align="right">'.($eventvalue['adult']).'</td>';
                                    $html .='<td  width="40" align="right">'.($eventvalue['child']).'</td>';
                                    $html .='<td  width="40" align="right">'.($eventvalue['total']).'</td>';
                                    $html .='<td  width="65" align="right">'.ucwords(strtolower($eventvalue['vehicle'])).'</td>';
                                    $html .='<td  width="70" align="right">'.ucwords(strtolower($eventvalue['room'])).'</td>';
                                    if($eventvalue['roomdate']!='0000-00-00'){
                                        $html .='<td width="70" align="right"> '.date('d-m-Y',strtotime($eventvalue['roomdate'])).'</td>';
                                    }else{
                                        $html .='<td></td>';
                                    }
                                $html .='</tr>';
                            }
                        }
                        $html .='<tr style="font-size:14px;font-weight:bold;">';
                            $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                            $html .='<td width="40" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                            $html .='<td width="40" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                            $html .='<td width="40" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                            $html .='<td  width="65" align="center">';
                                $vehicleby = array_count_values(array_column($eventwiseview, 'vehicle'));
                                if(!empty($vehicleby)){
                                    foreach ($vehicleby as $vehiclebykey => $vehiclebyvalue) {
                                        $html .=ucwords(strtolower($vehiclebykey)). " = ". $vehiclebyvalue."<br>";
                                    }
                                }
                             $html .='</td>';
                             $html .='<td width="70" align="center"></td>'; 
                             $html .='<td width="70" align="center"></td>'; 
                        $html .='</tr>';

                    $html .= '</table>';
                    echo $html;
                }else{
                    $event = $this->event_model->allevent_details();
                    foreach ($event as $eventkey => $eventvalue) {
                       $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                       $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="8">';
                                        $html .=strtoupper($eventvalue['name'])."";
                                    $html .='</th>';
                                    
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="55">Sr No.</th>';
                                $html .='<th width="250">Name</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Number</th>';
                                $html .='<th width="70">Category</th>';
                                $html .='<th width="70">Adult</th>';
                                $html .='<th width="70">Child</th>';
                                $html .='<th width="70">Total</th>';
                            $html .='</tr>';
                            if(!empty($eventwiseview)){
                                foreach ($eventwiseview as $ekey => $eventvalue) {
                                    $grandtotal =($grandtotal+intval($eventvalue['total']));
                                    $totaladult =($totaladult+intval($eventvalue['adult']));
                                    $totalchild =($totalchild+intval($eventvalue['child']));
                                    $html .='<tr>';
                                        $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                        
                                        $html .='<td width="250" align="left">'.ucwords(strtolower(nl2br($eventvalue['name'])))."<br>".ucwords(strtolower(nl2br($eventvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                        
                                       $html .='<td width="70" align="left">';
                                        $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                        foreach ($duplicat_details as $dkey => $dvalue) {
                                            $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                        }
                                        $html .='</td>';
                                        $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                        $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                        $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                                    $html .='</tr>';
                                }
                            }
                            $html .='<tr>';
                                $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                                $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                                $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                                $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                            $html .='</tr>';
                       $html .= '</table>';
                       echo $html;
                    }
                }
                exit;
            }
            if($reportview=='Export in PDF'){
                $pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

                $pdf->SetFont('helvetica', '', 10);
                if(!empty($event)){
                    $pdf->AddPage('L', ['format' => PDF_PAGE_FORMAT]);
                    $grandtotal='0';
                    $totaladult='0';
                    $totalchild='0';
                    $eventid = implode(',',$event);
                    $vehicle = $this->input->post('vehicle');
                    $roomdate = $this->input->post('roomdate');
                    $route = $this->input->post('route');
                    $data['eventid']=$eventid;
                    $data['vehicle']=$vehicle;
                    $data['roomdate']=$roomdate;
                    $data['route']=$route;
                    $eventwiseview = $this->inviteinevent_model->reportdetailview($data);
                    $html = '<table border="1" cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th colspan="8">';
                                foreach ($event as $eventkey => $eventvalue) {
                                    $e_d = $this->event_model->single_event_details($eventvalue); 
                                    $html .=strtoupper($e_d['name'])."&nbsp;&nbsp;";
                                }
                                $html .='</th>';
                                $r_d = $this->route_model->single_route_details($route); 
                                $rd=strtoupper($r_d['name']);
                                $html .='<th colspan="5">Route : '.$rd.'</th>';
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="30">Sr No.</th>';
                            $html .='<th width="170">Name</th>';
                            
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Number</th>';
                            $html .='<th width="120">Category</th>';
                            $html .='<th width="40">Adult</th>';
                            $html .='<th width="40">Child</th>';
                            $html .='<th width="40">Total</th>';
                            $html .='<th width="65">Vehicle</th>';
                            $html .='<th width="70">Room</th>';
                            $html .='<th width="70">Room Date</th>';
                        $html .='</tr>';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $grandtotal =($grandtotal+intval($eventvalue['total']));
                                $totaladult =($totaladult+intval($eventvalue['adult']));
                                $totalchild =($totalchild+intval($eventvalue['child']));
                                $html .='<tr>';
                                    $html .='<td width="30"  align="center">'.($ekey+1).'</td>';
                                   
                                     $html .='<td width="170" align="left">'.ucwords(strtolower(nl2br($eventvalue['name'])))."<br>".ucwords(strtolower(nl2br($eventvalue['address']))).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower(nl2br($eventvalue['mobile']))).'</td>';
                                   
                                   $html .='<td width="120" align="left">';
                                    $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                    foreach ($duplicat_details as $dkey => $dvalue) {
                                        $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                    }
                                    $html .='</td>';
                                    $html .='<td  width="40" align="right">'.($eventvalue['adult']).'</td>';
                                    $html .='<td  width="40" align="right">'.($eventvalue['child']).'</td>';
                                    $html .='<td  width="40" align="right">'.($eventvalue['total']).'</td>';
                                    $html .='<td  width="65" align="right">'.ucwords(strtolower($eventvalue['vehicle'])).'</td>';
                                    $html .='<td  width="70" align="right">'.ucwords(strtolower($eventvalue['room'])).'</td>';
                                    if($eventvalue['roomdate']!='0000-00-00'){
                                        $html .='<td width="70" align="right"> '.date('d-m-Y',strtotime($eventvalue['roomdate'])).'</td>';
                                    }else{
                                        $html .='<td></td>';
                                    }
                                $html .='</tr>';
                            }
                        }
                        $html .='<tr style="font-size:14px;font-weight:bold;">';
                            $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                            $html .='<td width="40" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                            $html .='<td width="40" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                            $html .='<td width="40" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                            $html .='<td  width="65" align="center">';
                                $vehicleby = array_count_values(array_column($eventwiseview, 'vehicle'));
                                if(!empty($vehicleby)){
                                    foreach ($vehicleby as $vehiclebykey => $vehiclebyvalue) {
                                        $html .=ucwords(strtolower($vehiclebykey)). " = ". $vehiclebyvalue."<br>";
                                    }
                                }
                             $html .='</td>';
                             $html .='<td  colspan="3" width="70" align="center"></td>'; 
                        $html .='</tr>';

                    $html .= '</table>';
                    $pdf->writeHTML($html, true, 0, true, 0);
                }else{
                    $event = $this->event_model->allevent_details();
                    foreach ($event as $eventkey => $eventvalue) {
                       $pdf->AddPage();
                       $grandtotal='0';
                       $totaladult='0';
                       $totalchild='0'; 
                       $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                       $html = '<table border="1" cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th colspan="8">';
                                        $html .=strtoupper($eventvalue['name'])."&nbsp;&nbsp;";
                                    $html .='</th>';
                                    
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="70">Number</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="100">Category</th>';
                                $html .='<th width="40">Adult</th>';
                                $html .='<th width="40">Child</th>';
                                $html .='<th width="40">Total</th>';
                            $html .='</tr>';
                            if(!empty($eventwiseview)){
                                foreach ($eventwiseview as $ekey => $eventvalue) {
                                    $grandtotal =($grandtotal+intval($eventvalue['total']));
                                    $totaladult =($totaladult+intval($eventvalue['adult']));
                                    $totalchild =($totalchild+intval($eventvalue['child']));
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($ekey+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower(nl2br($eventvalue['name']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower(nl2br($eventvalue['mobile']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                       $html .='<td width="100" align="left">';
                                        $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                        foreach ($duplicat_details as $dkey => $dvalue) {
                                            $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                        }
                                        $html .='</td>';
                                        $html .='<td  width="40" align="right">'.intval($eventvalue['adult']).'</td>';
                                        $html .='<td  width="40" align="right">'.intval($eventvalue['child']).'</td>';
                                        $html .='<td  width="40" align="right">'.intval($eventvalue['total']).'</td>';
                                    $html .='</tr>';
                                }
                            }
                            $html .='<tr style="font-size:14px;font-weight:bold;">';
                                $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                                $html .='<td width="40" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                                $html .='<td width="40" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                                $html .='<td width="40" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                            $html .='</tr>';
                        $html .= '</table>';
                        $pdf->writeHTML($html, true, 0, true, 0);
                    }
                }
                $pdf->Output('contact_list.pdf', 'I');  
            }
            // if($reportview=='Sticker View'){
            //     $pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
            //     $pdf->SetTitle('Address Sticker');
            //     $pdf->SetFont('helvetica', '', 11);
            //     $event = $this->input->post('event');
            //     if(!empty($event)){
            //         $pdf->AddPage(); 
            //         $grandtotal='0';
            //         $totaladult='0';
            //         $totalchild='0';
            //         $eventid = implode(',',$event);
                   
            //         $vehicle = $this->input->post('vehicle');
            //         $roomdate = $this->input->post('roomdate');
            //         $route = $this->input->post('route');
            //         $data['eventid']=$eventid;
            //         $data['vehicle']=$vehicle;
            //         $data['roomdate']=$roomdate;
            //         $data['route']=$route;
            //         $eventwiseview = $this->inviteinevent_model->reportdetailview($data);
            //         $html = '<table cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
            //             if(!empty($eventwiseview)){
            //                 $i=0;
            //                 foreach ($eventwiseview as $ekey => $eventvalue) {
            //                     if($i==0){
            //                         $html .='<tr width="100%" >'; 
            //                     }
            //                     $html .='<td>';
            //                          $html .='<table align="left" border="1" cellpadding="4" cellspacing="0"><tr width="50%"><td height="117px"><b>To,<br>'.strtoupper(nl2br($eventvalue['name'])).' </b><br>'.strtoupper(nl2br($eventvalue['address'])).'<br>'.ucwords(strtoupper($eventvalue['city'])).'.<br>CONTECT NO : '.strtoupper(nl2br($eventvalue['mobile'])).'</td>
            //                             </tr></table>';
            //                     $html .='</td>';
            //                     $i++;
            //                     if($i==2){
            //                         $html .='</tr>';
            //                         $i=0;
            //                     }
            //                 }
            //             }
            //         $html .= '</table>';
            //         $pdf->writeHTML($html, true, 0, true, 0);
            //     }else{
            //         $event = $this->event_model->allevent_details();
            //         $pdf->AddPage();
            //         $html = '<table cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
            //         foreach ($event as $eventkey => $eventvalue) {
            //            $grandtotal='0';
            //            $totaladult='0';
            //            $totalchild='0'; 
            //            $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
            //            if(!empty($eventwiseview)){
            //                 $i=0;
            //                 foreach ($eventwiseview as $ekey => $eventvalue) {
            //                     if($i==0){
            //                         $html .='<tr width="100%" >'; 
            //                     }
            //                     $html .='<td>';
            //                          $html .='<table align="left" border="1" cellpadding="4" cellspacing="0"><tr width="50%"><td height="117px"><b>To,<br>'.strtoupper(nl2br($eventvalue['name'])).' </b><br>'.strtoupper(nl2br($eventvalue['address'])).'<br>'.ucwords(strtoupper($eventvalue['city'])).'.<br>CONTECT NO : '.strtoupper(nl2br($eventvalue['mobile'])).'</td>
            //                             </tr></table>';
            //                     $html .='</td>';
            //                     $i++;
            //                     if($i==2){
            //                         $html .='</tr>';
            //                         $i=0;
            //                     }
            //                 }
            //             }
            //             $pdf->writeHTML($html, true, 0, true, 0);
            //         }
            //         $html = '</table>';
            //         $pdf->writeHTML($html, true, 0, true, 0);
            //     }
            //     ob_end_clean();
            //     $pdf->Output('contact_sticker_view.pdf', 'I');  
            // }
            if($reportview=='Sticker View'){
                $event = $this->input->post('event');
                if(!empty($event)){
                    $grandtotal='0';
                    $totaladult='0';
                    $totalchild='0';
                    $eventid = implode(',',$event);
                    $vehicle = $this->input->post('vehicle');
                    $roomdate = $this->input->post('roomdate');
                    $route = $this->input->post('route');
                    $data['eventid']=$eventid;
                    $data['vehicle']=$vehicle;
                    $data['roomdate']=$roomdate;
                    $data['route']=$route;
                    $eventwiseview = $this->inviteinevent_model->reportdetailview($data);
                    $html = '<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%" style="font-size:11px;margin-top:30px;">';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $contactkey => $eventvalue) 
                            {
                                $t++;
                                if($t-1%3==0){              
                                     $html .="<tr>";
                                }  
                                $html .='<td align="center" style="width:6.4cm;height:3.8cm;">';
                                    $html .='<div style="margin-left:0px; margin-top:0px;">';
                                        $html .='<div style="font-size:12px;text-align: justify;">';
                                            $html .='<b>To, '.strtoupper(nl2br($eventvalue['name']))."</b>";
                                        $html .='</div>';
                                        $html .='<div style="text-align: justify;">';
                                             $html .=ucwords(strtolower(nl2br($eventvalue['address'])));
                                        $html .='</div>';
                                        $html .='<div style="text-align: justify;">';
                                             $html .=ucwords(strtolower($eventvalue['city']));
                                        $html .='</div>';
                                        $html .='<div style="text-align: justify;">';
                                             $html .='No : '.ucwords($eventvalue['mobile']);
                                        $html .='</div>';
                                    $html .='</div>';
                                $html .='</td>';
                               
                                if($t%3==0 && $t != 0){
                                    $html .= "</tr>";                       
                                }
                                if($t%21==0){
                                    $html .= "<tr> <td style='height:1.6cm;'><br/></td></tr>";
                                }   
                            }
                        }
                    $html .= '</table>';
                    echo $html;exit;
                }else{
                    $event = $this->event_model->allevent_details();
                    $pdf->AddPage();
                    $html = '<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%" style="font-size:11px;margin-top:30px;">';
                    foreach ($event as $eventkey => $eventvalue) {
                       $grandtotal='0';
                       $totaladult='0';
                       $totalchild='0'; 
                       $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                       if(!empty($eventwiseview)){
                            $i=0;
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $t++;
                                if($t-1%3==0){              
                                     $html .="<tr>";
                                }  
                                $html .='<td align="center" style="width:6.4cm;height:3.8cm;">';
                                    $html .='<div style="margin-left:0px; margin-top:0px;">';
                                        $html .='<div style="font-size:12px;text-align: justify;">';
                                            $html .='<b>To, '.strtoupper(nl2br($eventvalue['name']))."</b>";
                                        $html .='</div>';
                                        $html .='<div style="text-align: justify;">';
                                             $html .=ucwords(strtolower(nl2br($eventvalue['address'])));
                                        $html .='</div>';
                                        $html .='<div style="text-align: justify;">';
                                             $html .=ucwords(strtolower($eventvalue['city']));
                                        $html .='</div>';
                                        $html .='<div style="text-align: justify;">';
                                             $html .='No : '.ucwords($eventvalue['mobile']);
                                        $html .='</div>';
                                    $html .='</div>';
                                $html .='</td>';
                               
                                if($t%3==0 && $t != 0){
                                    $html .= "</tr>";                       
                                }
                                if($t%21==0){
                                    $html .= "<tr> <td style='height:1.6cm;'><br/></td></tr>";
                                }   
                            }
                        }
                        $pdf->writeHTML($html, true, 0, true, 0);
                    }
                    $html = '</table>';
                    echo $html;exit;
                }
                
                  
            }

        }
        $this->data['route'] = $this->route_model->allroute_details();
        $this->data['event'] = $this->event_model->allevent_details();
        $this->data['message'] = $this->session->flashdata('message');
        $this->data['breadcrumb']='Category Details';
        $this->data['tpl_name']= "report_invite_details.tpl";
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('template.tpl');  
    }
    function contact_report(){
        if($this->input->post()){
            $catagory = $this->input->post('check_all');
            $contact = $this->input->post('contact_id');
            $reportview = $this->input->post('reportview');
            //print_r($contact);exit;
            if(!empty($catagory)){
               $catagory_id =$catagory;
               echo $catagory_id;
            }else{
                $catagory_id = '';
            }
          
            if(!empty($contact)){
                $contact_id =$contact;
            }else{
                $contact_id = '';
            }
            ob_clean();
            if($reportview=='View Report'){
                $contact_details = $this->contact_model->contact_full_details($catagory_id,$contact_id);
                if(!empty($contact_details)){
                    $contact_details = $this->unique_multidim_array($contact_details,'name'); 
                    
                    $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                            $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                    $html .='<th width="470" colspan="5">';
                                    $catname_count = array_count_values(array_column($contact_details, 'catname'));
                                    if(!empty($catname_count)){
                                        foreach ($catname_count as $cckey => $ccvalue) {
                                            $html .= $cckey. "=". $ccvalue."&nbsp;&nbsp;&nbsp;&nbsp;,&nbsp;&nbsp;&nbsp;&nbsp;";
                                        }
                                    }
                                    $html .='</th>';
                                    $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                            $html .='</tr>';
                            $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                                $html .='<th width="30">Sr No.</th>';
                                $html .='<th width="150">Name</th>';
                                $html .='<th width="150">Address</th>';
                                $html .='<th width="70">City</th>';
                                $html .='<th width="70">Contact Number</th>';
                                $html .='<th width="70">Category</th>';
                            $html .='</tr>';
                            if(!empty($contact_details)){
                                $i=0;
                                foreach ($contact_details as $contactkey => $contactvalue) {
                                    $html .='<tr>';
                                        $html .='<td width="30"  align="center">'.($i+1).'</td>';
                                        $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                        $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                        $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                        if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                            $html .='<td width="70"  align="left">';
                                            $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                            foreach ($duplicat_details as $dkey => $dvalue) {
                                                $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                            }
                                            $html .='</td>';
                                          
                                        }else{
                                            $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                        }
                                        
                                    $html .='</tr>';
                                    $i++;
                                }
                            }
                        $html .= '</table>';
                        echo $html;
                    
                }
                exit;
            }
            if($reportview=='Export in PDF'){
                $pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
                $pdf->SetFont('helvetica', '', 8);
                $pdf->AddPage();
                $contact_details = $this->contact_model->contact_full_details($catagory_id,$contact_id);
                if(!empty($contact_details)){
                    $contact_details = $this->unique_multidim_array($contact_details,'name');  
                    $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:10px;font-weight:bold;">';
                                $html .='<th width="470" colspan="5">';
                                $catname_count = array_count_values(array_column($contact_details, 'catname'));
                                if(!empty($catname_count)){
                                    foreach ($catname_count as $cckey => $ccvalue){
                                        $html .= $cckey. "=". $ccvalue."&nbsp;&nbsp;&nbsp;&nbsp;,&nbsp;&nbsp;&nbsp;&nbsp;";
                                    }
                                }
                                $html .='</th>';
                                $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:8px;font-weight:bold;">';
                            $html .='<th width="30">Sr No.</th>';
                            $html .='<th width="150">Name</th>';
                            $html .='<th width="150">Address</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Contact Number</th>';
                            $html .='<th width="70">Category</th>';
                        $html .='</tr>';
                        if(!empty($contact_details)){
                            $i=0;
                            foreach ($contact_details as $contactkey => $contactvalue) {
                                $html .='<tr>';
                                    $html .='<td width="30"  align="center">'.($i+1).'</td>';
                                    $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                    $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                    if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                        $html .='<td width="70"  align="left">';
                                        $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                        foreach ($duplicat_details as $dkey => $dvalue) {
                                            $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                        }
                                        $html .='</td>';
                                      
                                    }else{
                                        $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                    }
                                $html .='</tr>';
                                $i++;
                            }
                        }
                    $html .= '</table>';
                    $pdf->writeHTML($html, true, 0, true, 0);
                }
                $pdf->Output('contact_list.pdf', 'I');  
            }
            if($reportview=='Export in Excel'){
                header("Content-type: application/vnd-ms-excel");
                header("Content-Disposition: attachment; filename=contact_list.xls");
                $contact_details = $this->contact_model->contact_full_details($catagory_id,$contact_id);
                if(!empty($contact_details)){
                    $contact_details = $this->unique_multidim_array($contact_details,'name');  
                    $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th width="470" colspan="5">';
                                $catname_count = array_count_values(array_column($contact_details, 'catname'));
                                if(!empty($catname_count)){
                                    foreach ($catname_count as $cckey => $ccvalue) {
                                        $html .= $cckey. "=". $ccvalue."&nbsp;&nbsp;&nbsp;&nbsp;,&nbsp;&nbsp;&nbsp;&nbsp;";
                                    }
                                }
                                $html .='</th>';
                                $html .='<th width="70"> TOTAL  : '.count($contact_details).'</th>';
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="30">Sr No.</th>';
                            $html .='<th width="150">Name</th>';
                            $html .='<th width="150">Address</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Contact Number</th>';
                            $html .='<th width="70">Category</th>';
                        $html .='</tr>';
                        if(!empty($contact_details)){
                            $i=0;
                            foreach ($contact_details as $contactkey => $contactvalue) {
                                $html .='<tr>';
                                    $html .='<td width="30"  align="center">'.($i+1).'</td>';
                                    $html .='<td width="150" align="left">'.ucwords(strtolower($contactvalue['name'])).'</td>';
                                    $html .='<td width="150"  align="left">'.ucwords(strtolower(nl2br($contactvalue['address']))).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['city'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($contactvalue['mobile'])).'</td>';
                                    if($contactvalue['name']!='' and $contactvalue['categoryid']!=''){
                                        $html .='<td width="70"  align="left">';
                                        $duplicat_details = $this->contact_model->duplicat_details($contactvalue['name'],'',$contactvalue['address']);
                                        foreach ($duplicat_details as $dkey => $dvalue) {
                                            $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                        }
                                        $html .='</td>';
                                      
                                    }else{
                                        $html .='<td width="70"  align="left">'.ucwords(strtoupper($contactvalue['catname'])).'</td>';
                                    }
                                    
                                $html .='</tr>';
                                $i++;
                            }
                        }
                    $html .= '</table>';
                    echo $html;
                }
                
                exit;
            }
            // if($reportview=='Sticker View'){
            //    $pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
            //     $pdf->SetTitle('Address Sticker');
            //     $pdf->SetFont('helvetica', '', 11);
            //     $pdf->AddPage(); 
            //     $contact_details = $this->contact_model->contact_full_details($catagory_id,$contact_id);
            //     if(!empty($contact_details)){
            //         $contact_details = $this->unique_multidim_array($contact_details,'name'); 
            //         $html = '<table  cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
            //         if(!empty($contact_details)){
            //            $i=0;
            //            foreach ($contact_details as $contactkey => $contactvalue) {
            //                 if($i==0){
            //                     $html .='<tr width="100%" >'; 
            //                 }
            //                 $html .='<td>';
            //                      $html .='<table align="left" border="1" cellpadding="4" cellspacing="0"><tr width="50%"><td height="117px"><b>To,<br>'.strtoupper(nl2br($contactvalue['name'])).' </b><br>'.strtoupper(nl2br($contactvalue['address'])).'<br>'.ucwords(strtoupper($contactvalue['city'])).'.<br>CONTECT NO : '.strtoupper(nl2br($contactvalue['mobile'])).'</td>
            //                         </tr></table>';
            //                 $html .='</td>';
                           
            //                 $i++;
            //                 if($i==2){
            //                     $html .='</tr>';
            //                     $i=0;
            //                 }

            //             }
            //         }
            //         $html .= '</table>';
            //         $pdf->writeHTML($html, true, 0, true, 0);
            //     }
            //     ob_end_clean();
            //     $pdf->Output('contact_sticker_view.pdf', 'I');  
            // }
            if($reportview=='Sticker View'){
                $pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
                $pdf->SetTitle('Address Sticker');
                $pdf->SetFont('helvetica', '', 11);
                $pdf->AddPage(); 
                $contact = $this->contact_model->contact_full_details($catagory_id,$contact_id);
                
                $html = '<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%" style="font-size:11px; margin-top:30px;">';
                $cnt=0;
                $i=1;
                static $t=0;
                if(!empty($contact)){
                    foreach ($contact as $contactkey => $contact_details) {
                      $t++;
                      if($t-1%3==0){              
                        $html .="<tr>";
                      }
                        $html .='<td align="center" style="width:6.4cm;height:3.8cm;">';
                            $html .='<div style="margin-left:0px; margin-top:0px;">';
                                $html .='<div style="font-size:12px;text-align: justify;">';
                                    $html .='<b>To, '.strtoupper(nl2br($contact_details['name']))."</b>";
                                $html .='</div>';
                                $html .='<div style="text-align: justify;">';
                                     $html .=ucwords(strtolower(nl2br($contact_details['address'])));
                                $html .='</div>';
                                $html .='<div style="text-align: justify;">';
                                     $html .=ucwords(strtolower($contact_details['city']));
                                $html .='</div>';
                                $html .='<div style="text-align: justify;">';
                                     $html .='No : '.ucwords($contact_details['mobile']);
                                $html .='</div>';
                            $html .='</div>';
                        $html .='</td>';

                        if($t%3==0 && $t != 0){
                            $html .="</tr>";                       
                        }
                        if($t%21==0){
                            $html .="<tr><td style='height:1.6cm;'><br/></td></tr>";
                        }   
                        $i++;

                    }

                }
                $html .='</table>';
                echo $html;exit;
            
            }
        }
    }
    function invite_report(){
        $event = $this->uri->segment(3);
        $reportview = $this->uri->segment(4);
        ob_clean();
        if($reportview=='ViewReport'){ 
            if($event!=''){
                $grandtotal='0';
                $totaladult='0';
                $totalchild='0';
                $eventid = $event;
               
                $eventwiseview = $this->inviteinevent_model->eventwiseview($eventid);
                $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                    $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                            $html .='<th width="470" colspan="8">';
                            $e_d = $this->event_model->single_event_details($event);
                            $html .=strtoupper($e_d['name'])."&nbsp;&nbsp;";
                            $html .='</th>';
                            
                    $html .='</tr>';
                    $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                        $html .='<th width="55">Sr No.</th>';
                        $html .='<th width="250">Name</th>';
                        $html .='<th width="70">Number</th>';
                        $html .='<th width="70">City</th>';
                        $html .='<th width="70">Category</th>';
                        $html .='<th width="70">Adult</th>';
                        $html .='<th width="70">Child</th>';
                        $html .='<th width="70">Total</th>';
                    $html .='</tr>';
                    $eventwiseview = $this->unique_multidim_array($eventwiseview,'address'); 
                    if(!empty($eventwiseview)){
                        foreach ($eventwiseview as $ekey => $eventvalue) {
                            $grandtotal =($grandtotal+intval($eventvalue['total']));
                            $totaladult =($totaladult+intval($eventvalue['adult']));
                            $totalchild =($totalchild+intval($eventvalue['child']));
                            $html .='<tr>';
                                $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                $html .='<td width="250" align="left">'.ucwords(strtolower($eventvalue['name'])).'</td>';
                                $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                               $html .='<td width="70" align="left">';
                                $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                foreach ($duplicat_details as $dkey => $dvalue) {
                                    $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                }
                                $html .='</td>';
                                $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                            $html .='</tr>';
                        }
                    }
                    $html .='<tr>';
                        $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                        $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                        $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                        $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                    $html .='</tr>';
                $html .= '</table>';
                echo $html;
            }else{
                $event = $this->event_model->allevent_details();
                foreach ($event as $eventkey => $eventvalue) {
                   $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                   $eventwiseview = $this->unique_multidim_array($eventwiseview,'address');
                   $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th width="470" colspan="8">';
                                    $html .=strtoupper($eventvalue['name'])."";
                                $html .='</th>';
                                
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="55">Sr No.</th>';
                            $html .='<th width="250">Name</th>';
                            $html .='<th width="70">Number</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Category</th>';
                            $html .='<th width="70">Adult</th>';
                            $html .='<th width="70">Child</th>';
                            $html .='<th width="70">Total</th>';
                        $html .='</tr>';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $grandtotal =($grandtotal+intval($eventvalue['total']));
                                $totaladult =($totaladult+intval($eventvalue['adult']));
                                $totalchild =($totalchild+intval($eventvalue['child']));
                                $html .='<tr>';
                                    $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                    $html .='<td width="250" align="left">'.ucwords(strtolower($eventvalue['name'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                   $html .='<td width="70" align="left">';
                                    $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                    foreach ($duplicat_details as $dkey => $dvalue) {
                                        $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                    }
                                    $html .='</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                                $html .='</tr>';
                            }
                        }
                        $html .='<tr>';
                            $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                            $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                            $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                            $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                        $html .='</tr>';
                   $html .= '</table>';
                   echo $html;
                }
            }
            exit;
        }
        if($reportview=='ExportinExcel'){
            header("Content-type: application/vnd-ms-excel");
            header("Content-Disposition: attachment; filename=invite_list.xls");
            if($event!=''){
                $grandtotal='0';
                $totaladult='0';
                $totalchild='0';
                $eventid = $event;
                $eventwiseview = $this->inviteinevent_model->eventwiseview($eventid);
                $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                    $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                            $html .='<th width="470" colspan="8">';
                            $e_d = $this->event_model->single_event_details($event);
                            $html .=strtoupper($e_d['name'])."&nbsp;&nbsp;";
                            $html .='</th>';
                            
                    $html .='</tr>';
                    $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                        $html .='<th width="55">Sr No.</th>';
                        $html .='<th width="250">Name</th>';
                        $html .='<th width="70">Number</th>';
                        $html .='<th width="70">City</th>';
                        $html .='<th width="70">Category</th>';
                        $html .='<th width="70">Adult</th>';
                        $html .='<th width="70">Child</th>';
                        $html .='<th width="70">Total</th>';
                    $html .='</tr>';
                    $eventwiseview = $this->unique_multidim_array($eventwiseview,'address');
                    if(!empty($eventwiseview)){
                        foreach ($eventwiseview as $ekey => $eventvalue) {
                            $grandtotal =($grandtotal+intval($eventvalue['total']));
                            $totaladult =($totaladult+intval($eventvalue['adult']));
                            $totalchild =($totalchild+intval($eventvalue['child']));
                            $html .='<tr>';
                                $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                $html .='<td width="250" align="left">'.ucwords(strtolower($eventvalue['name'])).'</td>';
                                $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                               $html .='<td width="70" align="left">';
                                $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                foreach ($duplicat_details as $dkey => $dvalue) {
                                    $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                }
                                $html .='</td>';
                                $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                            $html .='</tr>';
                        }
                    }
                    $html .='<tr>';
                        $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                        $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                        $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                        $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                    $html .='</tr>';
                $html .= '</table>';
                echo $html;
            }else{
                $event = $this->event_model->allevent_details();
                foreach ($event as $eventkey => $eventvalue) {
                   $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                   $eventwiseview = $this->unique_multidim_array($eventwiseview,'address');
                   $html = '<table border="1" cellpadding="4" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th width="470" colspan="8">';
                                    $html .=strtoupper($eventvalue['name'])."";
                                $html .='</th>';
                                
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="55">Sr No.</th>';
                            $html .='<th width="250">Name</th>';
                            $html .='<th width="70">Number</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="70">Category</th>';
                            $html .='<th width="70">Adult</th>';
                            $html .='<th width="70">Child</th>';
                            $html .='<th width="70">Total</th>';
                        $html .='</tr>';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $grandtotal =($grandtotal+intval($eventvalue['total']));
                                $totaladult =($totaladult+intval($eventvalue['adult']));
                                $totalchild =($totalchild+intval($eventvalue['child']));
                                $html .='<tr>';
                                    $html .='<td width="55"  align="center">'.($ekey+1).'</td>';
                                    $html .='<td width="250" align="left">'.ucwords(strtolower($eventvalue['name'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['mobile'])).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                   $html .='<td width="70" align="left">';
                                    $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                    foreach ($duplicat_details as $dkey => $dvalue) {
                                        $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                    }
                                    $html .='</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['adult']).'</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['child']).'</td>';
                                    $html .='<td  width="70" align="right">'.intval($eventvalue['total']).'</td>';
                                $html .='</tr>';
                            }
                        }
                        $html .='<tr>';
                            $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                            $html .='<td width="70" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                            $html .='<td width="70" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                            $html .='<td width="70" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                        $html .='</tr>';
                   $html .= '</table>';
                   echo $html;
                }
            }
            exit;
        }
        if($reportview=='ExportinPDF'){
            $pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
            $pdf->SetFont('helvetica', '', 10);
            if($event!=''){
                $pdf->AddPage(); 
                $grandtotal='0';
                $totaladult='0';
                $totalchild='0';
                $eventid = $event;
                $eventwiseview = $this->inviteinevent_model->eventwiseview($eventid);
                $eventwiseview = $this->unique_multidim_array($eventwiseview,'address');
                $html = '<table border="1" cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                    $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                            $html .='<th colspan="8">';
                            $e_d = $this->event_model->single_event_details($event);
                            $html .=strtoupper($e_d['name'])."&nbsp;&nbsp;";
                            $html .='</th>';
                            
                    $html .='</tr>';
                    $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                        $html .='<th width="30">Sr No.</th>';
                        $html .='<th width="150">Name</th>';
                        $html .='<th width="70">Number</th>';
                        $html .='<th width="70">City</th>';
                        $html .='<th width="100">Category</th>';
                        $html .='<th width="40">Adult</th>';
                        $html .='<th width="40">Child</th>';
                        $html .='<th width="40">Total</th>';
                    $html .='</tr>';
                    if(!empty($eventwiseview)){
                        foreach ($eventwiseview as $ekey => $eventvalue) {
                            $grandtotal =($grandtotal+intval($eventvalue['total']));
                            $totaladult =($totaladult+intval($eventvalue['adult']));
                            $totalchild =($totalchild+intval($eventvalue['child']));
                            $html .='<tr>';
                                $html .='<td width="30"  align="center">'.($ekey+1).'</td>';
                                $html .='<td width="150" align="left">'.ucwords(strtolower(nl2br($eventvalue['name']))).'</td>';
                                $html .='<td width="70"  align="left">'.ucwords(strtolower(nl2br($eventvalue['mobile']))).'</td>';
                                $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                               $html .='<td width="100" align="left">';
                                $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                foreach ($duplicat_details as $dkey => $dvalue) {
                                    $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                }
                                $html .='</td>';
                                $html .='<td  width="40" align="right">'.intval($eventvalue['adult']).'</td>';
                                $html .='<td  width="40" align="right">'.intval($eventvalue['child']).'</td>';
                                $html .='<td  width="40" align="right">'.intval($eventvalue['total']).'</td>';
                            $html .='</tr>';
                        }
                    }
                    $html .='<tr style="font-size:14px;font-weight:bold;">';
                        $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                        $html .='<td width="40" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                        $html .='<td width="40" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                        $html .='<td width="40" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                    $html .='</tr>';
                $html .= '</table>';
                $pdf->writeHTML($html, true, 0, true, 0);
            }else{
                $event = $this->event_model->allevent_details();
                foreach ($event as $eventkey => $eventvalue) {
                   $pdf->AddPage();
                   $grandtotal='0';
                   $totaladult='0';
                   $totalchild='0'; 
                   $eventwiseview = $this->inviteinevent_model->eventwiseview($eventvalue['id']);
                   $eventwiseview = $this->unique_multidim_array($eventwiseview,'address');
                   $html = '<table border="1" cellpadding="3" cellspacing="0" align="center" width="100%" style="font-weight:normal;">';
                        $html .='<tr align="center" style="font-size:14px;font-weight:bold;">';
                                $html .='<th colspan="8">';
                                    $html .=strtoupper($eventvalue['name'])."&nbsp;&nbsp;";
                                $html .='</th>';
                                
                        $html .='</tr>';
                        $html .='<tr align="center" style="font-size:12px;font-weight:bold;">';
                            $html .='<th width="30">Sr No.</th>';
                            $html .='<th width="150">Name</th>';
                            $html .='<th width="70">Number</th>';
                            $html .='<th width="70">City</th>';
                            $html .='<th width="100">Category</th>';
                            $html .='<th width="40">Adult</th>';
                            $html .='<th width="40">Child</th>';
                            $html .='<th width="40">Total</th>';
                        $html .='</tr>';
                        if(!empty($eventwiseview)){
                            foreach ($eventwiseview as $ekey => $eventvalue) {
                                $grandtotal =($grandtotal+intval($eventvalue['total']));
                                $totaladult =($totaladult+intval($eventvalue['adult']));
                                $totalchild =($totalchild+intval($eventvalue['child']));
                                $html .='<tr>';
                                    $html .='<td width="30"  align="center">'.($ekey+1).'</td>';
                                    $html .='<td width="150" align="left">'.ucwords(strtolower(nl2br($eventvalue['name']))).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower(nl2br($eventvalue['mobile']))).'</td>';
                                    $html .='<td width="70"  align="left">'.ucwords(strtolower($eventvalue['city'])).'</td>';
                                   $html .='<td width="100" align="left">';
                                    $duplicat_details = $this->contact_model->duplicat_details($eventvalue['name'],'',$eventvalue['address']);
                                    foreach ($duplicat_details as $dkey => $dvalue) {
                                        $html .=ucwords(strtoupper($dvalue['catname'])).'<br>';
                                    }
                                    $html .='</td>';
                                    $html .='<td  width="40" align="right">'.intval($eventvalue['adult']).'</td>';
                                    $html .='<td  width="40" align="right">'.intval($eventvalue['child']).'</td>';
                                    $html .='<td  width="40" align="right">'.intval($eventvalue['total']).'</td>';
                                $html .='</tr>';
                            }
                        }
                        $html .='<tr style="font-size:14px;font-weight:bold;">';
                            $html .='<td colspan="5" align="right" ><h5><b>Total :</b></h5> </td>';
                            $html .='<td width="40" align="right"><h5><b>'.$totaladult.'</b></h5></td>';
                            $html .='<td width="40" align="right"><h5><b>'.$totalchild.'</b></h5></td>';
                            $html .='<td width="40" align="right"><h5><b>'.$grandtotal.'</b></h5></td>';
                        $html .='</tr>';
                    $html .= '</table>';
                    $pdf->writeHTML($html, true, 0, true, 0);
                }
            }
            $pdf->Output('contact_list.pdf', 'I');  
        }
        if($reportview=='StickerView'){
            $pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
            $pdf->SetTitle('Address Sticker');
            $pdf->SetFont('helvetica', '', 11);
            if($event!=''){
                $grandtotal='0';
                $totaladult='0';
                $totalchild='0';
                $eventid = $event;
                $eventwiseview = $this->inviteinevent_model->eventwiseview($eventid);
                $eventwiseview = $this->unique_multidim_array($eventwiseview,'address');
                $cnt=0;
                $i=1;
                static $t=0;
                $html = '<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%" style="font-size:11px; margin-top:30px;">';
                    if(!empty($eventwiseview)){
                        foreach ($eventwiseview as $ekey => $eventvalue) {
                            $t++;
                            if($t-1%3==0){              
                                $html .="<tr>";
                            }
                            $html .='<td align="center" style="width:6.4cm;height:3.8cm;">';
                                $html .='<div style="margin-left:0px; margin-top:0px;">';
                                    $html .='<div style="font-size:12px;text-align: justify;">';
                                        $html .='<b>To, '.strtoupper(nl2br($eventvalue['name']))."</b>";
                                    $html .='</div>';
                                    $html .='<div style="text-align: justify;">';
                                         $html .=ucwords(strtolower(nl2br($eventvalue['address'])));
                                    $html .='</div>';
                                    $html .='<div style="text-align: justify;">';
                                         $html .=ucwords(strtolower($eventvalue['city']));
                                    $html .='</div>';
                                    $html .='<div style="text-align: justify;">';
                                         $html .='No : '.ucwords($eventvalue['mobile']);
                                    $html .='</div>';
                                $html .='</div>';
                            $html .='</td>';

                            if($t%3==0 && $t != 0){
                                $html .="</tr>";                       
                            }
                            if($t%21==0){
                                $html .="<tr><td style='height:1.6cm;'><br/></td></tr>";
                            }
                        }
                    }
                $html .= '</table>';
                
            }
            echo $html;exit;
        }
    }
    function unique_multidim_array($array, $key) { 
        $temp_array = array(); 
        $i = 0; 
        $key_array = array(); 
        
        foreach($array as $val) { 
            if (!in_array($val[$key], $key_array)) { 
                $key_array[$i] = $val[$key]; 
                $temp_array[$i] = $val; 
            } 
            $i++; 
        } 
        return $temp_array; 
    }   
}
