332 lines
9.5 KiB
PHP
332 lines
9.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
date_default_timezone_set('Asia/Kolkata');
|
|
class Policy extends CI_Controller {
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('Policy_model');
|
|
$this->load->model('Company_model');
|
|
$this->load->model('Category_model');
|
|
}
|
|
function list_policy()
|
|
{
|
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
|
$data['pol']=$this->Policy_model->list_policies();
|
|
$this->load->view('admin/policy/list',$data);
|
|
}
|
|
function add_policy()
|
|
{
|
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
|
if($this->input->post('add'))
|
|
{
|
|
$policyname=$this->input->post('policyname');
|
|
$Company=$this->input->post('Company');
|
|
$Category=$this->input->post('Category');
|
|
$p_amount=$this->input->post('p_amount');
|
|
$pa_period=$this->input->post('pa_period');
|
|
$p_period=$this->input->post('p_period');
|
|
$pp_period=$this->input->post('pp_period');
|
|
$guarantee=$this->input->post('guarantee');
|
|
$g_period=$this->input->post('g_period');
|
|
$Intro=$this->input->post('Intro');
|
|
$topplan=$this->input->post('topplan');
|
|
$claimsettleper=$this->input->post('claimsettleper');
|
|
$lifecover=$this->input->post('lifecover');
|
|
$am_type=$this->input->post('am_type');
|
|
$Compare=$this->input->post('Compare');
|
|
$cmp_detail=$this->input->post('cmp_detail');
|
|
$maxager=$this->input->post('maxager');
|
|
|
|
//multi
|
|
$benefits=$this->input->post('benefits');
|
|
$Specialization=$this->input->post('Specialization');
|
|
$array_benefits = implode(",", $benefits);
|
|
$ben =array();
|
|
foreach($benefits as $key=>$val)
|
|
{
|
|
$ben[]=$benefits[$key];
|
|
}
|
|
$ben_res= implode(', ', $ben);
|
|
|
|
$spec =array();
|
|
foreach($Specialization as $key1=>$val1)
|
|
{
|
|
$spec[]=$Specialization[$key1];
|
|
}
|
|
$spec_res= implode(', ', $spec);
|
|
//make directory
|
|
|
|
if (!is_dir('uploads/policy')) {
|
|
mkdir('./uploads/policy', 0777, TRUE);
|
|
|
|
}
|
|
|
|
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
|
|
$path = 'uploads/policy/'; // upload directory
|
|
|
|
if($_FILES['Image'])
|
|
{
|
|
|
|
$img = $_FILES['Image']['name'];
|
|
$tmp = $_FILES['Image']['tmp_name'];
|
|
// get uploaded file's extension
|
|
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
|
|
// can upload same image using rand function
|
|
$final_image = "Image".rand(1000,1000000).$img;
|
|
// check's valid format
|
|
if(in_array($ext, $valid_extensions))
|
|
{
|
|
$path = $path.strtolower($final_image);
|
|
|
|
if(move_uploaded_file($tmp,$path))
|
|
{} } }
|
|
$table="policies";
|
|
$rvalue=array(
|
|
'name'=>$policyname,
|
|
'category'=>$Category,
|
|
'company'=>$Company,
|
|
'amount'=>$p_amount,
|
|
'amount_period'=>$pa_period,
|
|
'image'=>$path,
|
|
'intro'=>$Intro,
|
|
'max_cover_age'=>$maxager,
|
|
'benefits'=>$ben_res,
|
|
'life_cover'=>$lifecover." ".$am_type,
|
|
'claimed_settlement'=>$claimsettleper,
|
|
'is_this_top_plan'=>$topplan,
|
|
'specializations'=>$spec_res,
|
|
'guarantee'=>$guarantee." ".$g_period,
|
|
'policy_period'=>$p_period." ".$pp_period,
|
|
'cdate'=>date('Y-m-d H:i:s'),
|
|
'status'=>1);
|
|
$result=$this->commonsql_model->insert_table($table,$rvalue);
|
|
$polid=$this->db->insert_id();
|
|
|
|
foreach($Compare as $ck=>$cv){
|
|
$table="policy_compare_details";
|
|
$rvalue=array(
|
|
'policy'=>$polid,
|
|
'category'=>$Category,
|
|
'compare'=>$Compare[$ck],
|
|
'comparedetail'=>$cmp_detail[$ck],
|
|
'cdate'=>date('Y-m-d H:i:s'),
|
|
'status'=>1);
|
|
if($cmp_detail[$ck]!=""){
|
|
$result=$this->commonsql_model->insert_table($table,$rvalue);
|
|
}
|
|
}
|
|
if($result)
|
|
{
|
|
$this->session->set_userdata('suc','successfully added');
|
|
redirect('admin/policies');
|
|
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_userdata('err','Please try again');
|
|
redirect('admin/policies');
|
|
}
|
|
|
|
}
|
|
|
|
$data['cmp']=$this->Company_model->list_cmp();
|
|
$data['cat']=$this->Category_model->list_cat();
|
|
|
|
$this->load->view('admin/policy/add',$data);
|
|
}
|
|
function get_compare_master()
|
|
{
|
|
$cid=$_POST['val'];
|
|
$com=$this->Policy_model->get_compare_master($cid);
|
|
foreach($com->result() as $c){
|
|
$comid=$c->id;
|
|
$compare_name=$c->compare_name;?>
|
|
<option value="<?=$comid;?>"><?=$compare_name;?></option>
|
|
<?php }
|
|
}
|
|
function view_policy($id)
|
|
{
|
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
|
$data['pol']=$this->Policy_model->list_policies($id);
|
|
$data['cmp_det']=$this->Policy_model->get_polict_compare_details($id);
|
|
$this->load->view('admin/policy/view',$data);
|
|
}
|
|
function edit_policy($id)
|
|
{
|
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
|
if($this->input->post('edit'))
|
|
{
|
|
$policyname=$this->input->post('policyname');
|
|
$Company=$this->input->post('Company');
|
|
$Category=$this->input->post('Category');
|
|
$p_amount=$this->input->post('p_amount');
|
|
$pa_period=$this->input->post('pa_period');
|
|
$p_period=$this->input->post('p_period');
|
|
$pp_period=$this->input->post('pp_period');
|
|
$guarantee=$this->input->post('guarantee');
|
|
$g_period=$this->input->post('g_period');
|
|
$Intro=$this->input->post('Intro');
|
|
$Image=$this->input->post('Image');
|
|
$oldimage=$this->input->post('oldimage');
|
|
$topplan=$this->input->post('topplan');
|
|
$claimsettleper=$this->input->post('claimsettleper');
|
|
$lifecover=$this->input->post('lifecover');
|
|
$am_type=$this->input->post('am_type');
|
|
$Compare=$this->input->post('Compare');
|
|
$cmp_detail=$this->input->post('cmp_detail');
|
|
$maxager=$this->input->post('maxager');
|
|
$hiddenprimary=$this->input->post('hiddenprimary');
|
|
//multi
|
|
$benefits=$this->input->post('benefits');
|
|
$Specialization=$this->input->post('Specialization');
|
|
$array_benefits = implode(",", $benefits);
|
|
$ben =array();
|
|
foreach($benefits as $key=>$val)
|
|
{
|
|
$ben[]=$benefits[$key];
|
|
}
|
|
$ben_res= implode(', ', $ben);
|
|
|
|
$spec =array();
|
|
foreach($Specialization as $key1=>$val1)
|
|
{
|
|
$spec[]=$Specialization[$key1];
|
|
}
|
|
$spec_res= implode(', ', $spec);
|
|
|
|
if($Image=="") {
|
|
$simage=$oldimage;
|
|
}
|
|
if (!is_dir('uploads/policy')) {
|
|
mkdir('./uploads/policy', 0777, TRUE);
|
|
|
|
}
|
|
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
|
|
$path = 'uploads/policy/'; // upload directory
|
|
|
|
if($_FILES['Image']['tmp_name'])
|
|
{
|
|
$img = $_FILES['Image']['name'];
|
|
$tmp = $_FILES['Image']['tmp_name'];
|
|
// get uploaded file's extension
|
|
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
|
|
// can upload same image using rand function
|
|
$final_image = "Image".rand(1000,1000000).$img;
|
|
// check's valid format
|
|
if(in_array($ext, $valid_extensions))
|
|
{
|
|
$simage = $path.strtolower($final_image);
|
|
if(move_uploaded_file($tmp,$simage))
|
|
{}} }
|
|
$table="policies";
|
|
$where=array("id"=>$id);
|
|
$rvalue=array(
|
|
'name'=>$policyname,
|
|
'category'=>$Category,
|
|
'company'=>$Company,
|
|
'amount'=>$p_amount,
|
|
'amount_period'=>$pa_period,
|
|
'image'=>$simage,
|
|
'intro'=>$Intro,
|
|
'benefits'=>$ben_res,
|
|
'max_cover_age'=>$maxager,
|
|
'life_cover'=>$lifecover." ".$am_type,
|
|
'claimed_settlement'=>$claimsettleper,
|
|
'is_this_top_plan'=>$topplan,
|
|
'specializations'=>$spec_res,
|
|
'guarantee'=>$guarantee." ".$g_period,
|
|
'policy_period'=>$p_period." ".$pp_period,
|
|
'udate'=>date('Y-m-d H:i:s'),
|
|
'status'=>1);
|
|
$result=$this->commonsql_model->updateTable($table,$where,$rvalue);
|
|
|
|
|
|
foreach($Compare as $ck=>$cv){
|
|
/* comparision edit */
|
|
$exist_tag=$this->Policy_model->get_polict_compare_details($id);
|
|
|
|
if($exist_tag->num_rows()>0)
|
|
{
|
|
$oldcompare=array();
|
|
|
|
foreach($exist_tag->result() as $list)
|
|
{
|
|
$oldcompare[]=$list->id ;
|
|
|
|
}
|
|
}
|
|
//different1
|
|
$diff=array_diff($oldcompare,$hiddenprimary);
|
|
if($diff>0){
|
|
foreach($diff as $value){
|
|
$where=array('id'=>$value);
|
|
$tablename="policy_compare_details";
|
|
$values=array('status'=>0);
|
|
if($hiddenprimary[$ck]!=""){
|
|
$product=$this->commonsql_model->updateTable($tablename,$where,$values);
|
|
}
|
|
}
|
|
}
|
|
$table="policy_compare_details";
|
|
$rvalue=array(
|
|
'policy'=>$id,
|
|
'category'=>$Category,
|
|
'compare'=>$Compare[$ck],
|
|
'comparedetail'=>$cmp_detail[$ck],
|
|
'cdate'=>date('Y-m-d H:i:s'),
|
|
'status'=>1);
|
|
if($hiddenprimary[$ck]==""){
|
|
if($cmp_detail[$ck]!=""){
|
|
$result=$this->commonsql_model->insert_table($table,$rvalue);
|
|
}
|
|
}
|
|
if($hiddenprimary[$ck]!="")
|
|
{
|
|
$where=array("id"=>$hiddenprimary[$ck]);
|
|
$result=$this->commonsql_model->updateTable($table,$where,$rvalue);
|
|
}
|
|
|
|
}
|
|
if($result)
|
|
{
|
|
$this->session->set_userdata('suc','successfully updated');
|
|
redirect('admin/policies');
|
|
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_userdata('err','Please try again');
|
|
redirect('admin/policies');
|
|
}
|
|
|
|
|
|
}
|
|
$data['pol']=$this->Policy_model->list_policies($id);
|
|
$data['cmp_det']=$this->Policy_model->get_polict_compare_details($id);
|
|
$data['cmp']=$this->Company_model->list_cmp();
|
|
$data['cat']=$this->Category_model->list_cat();
|
|
$this->load->view('admin/policy/edit',$data);
|
|
}
|
|
function delete_policy($id)
|
|
{
|
|
$table="policies";
|
|
$where=array("id"=>$id);
|
|
$rvalue=array(
|
|
'status'=>0);
|
|
$result=$this->commonsql_model->updateTable($table,$where,$rvalue);
|
|
if($result)
|
|
{
|
|
$this->session->set_userdata('suc','successfully deleted');
|
|
redirect('admin/policies');
|
|
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_userdata('err','Please try again');
|
|
redirect('admin/policies');
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|