<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Brcustomerend extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model('Brcustomermodel', 'customer_model');
		$this->load->model('Brshopmodel', 'shop_model');
		$this->load->model('BrservicesuserModel', 'servicesuser_model');

	}

	public function get($id = Null) {
		$partnerlist = $this->frontenduser_model->getBannerAll();
		echo '1';
		print_r($partnerlist);
	}

	public function add() {

		// $request= new Request();
		// $admin=$request->getBody();

		// 'inputadminname':$('#inputadminname').val(),
		//     'inputloginname':$('#inputloginname').val(),
		//     'inputPassword'
		// $name=$this->input->post('name');

		//add security trim input-todo
		//hash password for security
		$inputcode = $this->input->post('code');
		$display_name = $this->input->post('display_name');
		// $chi_name=$this->input->post('chi_name');
		// $eng_firstname=$this->input->post('eng_firstname');
		// $eng_lastname=$this->input->post('eng_lastname');
		$gender = $this->input->post('gender');
		$dob = $this->input->post('dob');
		$mobile = $this->input->post('mobile');
		$district_id = $this->input->post('district_id');
		$area_id = $this->input->post('area_id');
		$zone = $this->input->post('zone');
		$address = $this->input->post('address');
		$join_date = $this->input->post('join_date');
		$shop_id = $this->input->post('shop_id');
		$skin_improve = $this->input->post('skin_improve');
		$body_improve = $this->input->post('body_improve');
		$face_improve = $this->input->post('face_improve');
		$referrer1 = $this->input->post('referrer1');
		$referred_mobile = $this->input->post('referred_mobile');
		$remark = $this->input->post('remark');
		$need_purchase_service = $this->input->post('need_purchase_service');
		$service_id = $this->input->post('service_id');
		$purchased_date = $this->input->post('purchased_date');
		$purchased_qty = $this->input->post('purchased_qty');
		$available_qty = $this->input->post('available_qty');
		$remark2 = $this->input->post('remark2');
		$promotion_code = $this->input->post('promotion_code');
		$first_registered_tenant_no = $this->input->post('first_registered_tenant_no');
		$concurrent_registered_tenant_no = $this->input->post('concurrent_registered_tenant_no');
		$level = $this->input->post('level');
		$isTemp = $this->input->post('isTemp');
		$channelSelectID = $this->input->post('channelSelectID');
		$prefer_pic = $this->input->post('prefer_pic');
		$bodyoptionother_text = $this->input->post('bodyoptionother_text');
		$faceoptionother_text = $this->input->post('faceoptionother_text');

		//2020-09-08 added portable field
		$id_number = "";
		if ($this->input->post('id_number') != false) {
			$id_number = $this->input->post('id_number');
		}
		$career_name = "";
		if ($this->input->post('career_name') != false) {
			$career_name = $this->input->post('career_name');
		}
		$age = "";
		if ($this->input->post('age') != false) {
			$age = $this->input->post('age');
		}
		$body_height = "";
		if ($this->input->post('body_height') != false) {
			$body_height = $this->input->post('body_height');
		}
		$body_weight = "";
		if ($this->input->post('body_weight') != false) {
			$body_weight = $this->input->post('body_weight');
		}
		$married_status = "";
		if ($this->input->post('married_status') != false) {
			$married_status = $this->input->post('married_status');
		}
		$child_num = "";
		if ($this->input->post('child_num') != false) {
			$child_num = $this->input->post('child_num');
		}
		$disease = "";
		if ($this->input->post('disease') != false) {
			$disease = $this->input->post('disease');
		}
		$diseaseother = "";
		if ($this->input->post('diseaseother') != false) {
			$diseaseother = $this->input->post('diseaseother');
		}
		$sensitivity = "";
		if ($this->input->post('sensitivity') != false) {
			$sensitivity = $this->input->post('sensitivity');
		}
		$surgery = "";
		if ($this->input->post('surgery') != false) {
			$surgery = $this->input->post('surgery');
		}
		$medicine = "";
		if ($this->input->post('medicine') != false) {
			$medicine = $this->input->post('medicine');
		}
		$allergy = "";
		if ($this->input->post('allergy') != false) {
			$allergy = $this->input->post('allergy');
		}
		$lifestyle = "";
		if ($this->input->post('lifestyle') != false) {
			$lifestyle = $this->input->post('lifestyle');
		}
		$habbit = "";
		if ($this->input->post('habbit') != false) {
			$habbit = $this->input->post('habbit');
		}
		$lighttheraphist = "";
		if ($this->input->post('lighttheraphist') != false) {
			$lighttheraphist = $this->input->post('lighttheraphist');
		}
		$otherlighttherapist = "";
		if ($this->input->post('otherlighttherapist') != false) {
			$otherlighttherapist = $this->input->post('otherlighttherapist');
		}
		$botoxtherapist = "";
		if ($this->input->post('botoxtherapist') != false) {
			$botoxtherapist = $this->input->post('botoxtherapist');
		}
		$transtherapist = "";
		if ($this->input->post('transtherapist') != false) {
			$transtherapist = $this->input->post('transtherapist');
		}
		$feeding = "";
		if ($this->input->post('feeding') != false) {
			$feeding = $this->input->post('feeding');
		}
		$beautytreat = "";
		if ($this->input->post('beautytreat') != false) {
			$beautytreat = $this->input->post('beautytreat');
		}
		$paymentmethod = "";
		if ($this->input->post('paymentmethod') != false) {
			$paymentmethod = $this->input->post('paymentmethod');
		}
		$otherpayment = "";
		if ($this->input->post('otherpayment') != false) {
			$otherpayment = $this->input->post('otherpayment');
		}
		$referrer1 = "";
		if ($this->input->post('referrer1') != false) {
			$referrer1 = $this->input->post('referrer1');
		}
		$sensitivity_option = "";
		if ($this->input->post('sensitivity_option') != false) {
			$sensitivity_option = $this->input->post('sensitivity_option');
		}
		$surgery_option = "";
		if ($this->input->post('surgery_option') != false) {
			$surgery_option = $this->input->post('surgery_option');
		}
		$medicine_option = "";
		if ($this->input->post('medicine_option') != false) {
			$medicine_option = $this->input->post('medicine_option');
		}
		$allergy_option = "";
		if ($this->input->post('allergy_option') != false) {
			$allergy_option = $this->input->post('allergy_option');
		}

		//end　2020-09-08 added portable field

		//service data
		$need_purchase_service = $this->input->post('need_purchase_service');
		$service_id = $this->input->post('service_id');
		$purchased_date = $this->input->post('purchased_date');
		$purchased_price = $this->input->post('purchased_price');
		$purchased_qty = $this->input->post('purchased_qty');
		$available_qty = $this->input->post('available_qty');
		//end service data

		$data = array(
			'code' => $inputcode,
			'display_name' => $display_name,
			// 'chi_name'=>$chi_name,
			// 'eng_firstname'=>$eng_firstname,
			// 'inputadminname'=>$inputadminname,
			// 'eng_lastname'=>$eng_lastname,
			'gender' => $gender,
			'dob' => $dob,
			'mobile' => $mobile,
			'district_id' => $district_id,
			'area_id' => $area_id,
			'zone' => $zone,
			'address' => $address,
			'join_date' => $join_date,
			'shop_id' => $shop_id,
			'skin_improve' => $skin_improve,
			'body_improve' => $body_improve,
			'face_improve' => $face_improve,
			'referred_mobile' => $referred_mobile,
			'remark' => $remark,
			'need_purchase_service' => $need_purchase_service,
			'service_id' => $service_id,
			'purchased_date' => $purchased_date,
			'purchased_qty' => $purchased_qty,
			'available_qty' => $available_qty,
			'remark2' => $remark2,
			'promotion_code' => $promotion_code,
			'first_registered_tenant_no' => $first_registered_tenant_no,
			'concurrent_registered_tenant_no' => $concurrent_registered_tenant_no,
			'level' => $level,
			'isTemp' => $isTemp,
			'channelSelectID' => $channelSelectID,
			'prefer_pic' => $prefer_pic,
			'bodyoptionother_text' => $bodyoptionother_text,
			'faceoptionother_text' => $faceoptionother_text,

			//added portable field 2020-0908
			'referrer1' => $referrer1,
			'id_number' => $id_number,
			'career_name' => $career_name,
			'age' => $age,
			'body_height' => $body_height,
			'body_weight' => $body_weight,
			'married_status' => $married_status,
			'child_num' => $child_num,
			'disease' => $disease,
			'diseaseother' => $diseaseother,
			'sensitivity_option' => $sensitivity_option,
			'sensitivity' => $sensitivity,
			'surgery_option' => $surgery_option,
			'surgery' => $surgery,
			'medicine_option' => $medicine_option,
			'medicine' => $medicine,
			'allergy_option' => $allergy_option,
			'allergy' => $allergy,
			'lifestyle' => $lifestyle,
			'habbit' => $habbit,
			'lighttheraphist' => $lighttheraphist,
			'otherlighttherapist' => $otherlighttherapist,
			'botoxtherapist' => $botoxtherapist,
			'transtherapist' => $transtherapist,
			'feeding' => $feeding,
			'beautytreat' => $beautytreat,
			'paymentmethod' => $paymentmethod,
			'otherpayment' => $otherpayment,

			//end added portable field 2020-0908

		);

		// $code="";
		// if($this->frontenduser_model->admin_exists($inputadminname)==false){
		//     $code="FAILURE";
		//     $msg="已有管理員姓名".$inputadminname;
		// }
		// else
		// if($this->customer_model->customercode_exists(strtolower($code))==false){
		//     $entercode=$code;
		//     $code="FAILURE";
		//     $msg="已有客戶編號".$entercode;
		// }

		$headcode = $this->shop_model->getShopcodeHead($first_registered_tenant_no);

		if ($this->customer_model->customermobile_exists($mobile) == false) {
			// $entercode=$code;
			$code = "FAILURE";
			$msg = "新增失敗。已有客戶電話號碼" . $mobile;
		} elseif (!empty($inputcode) && strpos($inputcode, $headcode) !== 0) {
			$code = "FAILURE";
			$msg = "新增失敗。客戶編號的前綴應為 " . $headcode . "。";
		} elseif (!empty($inputcode) && $inputcode == $headcode . "0000") {
			$code = "FAILURE";
			$msg = "新增失敗。請填寫客戶編號.現在客戶編號是" . $headcode . "0000" . "。";
		} elseif ($this->customer_model->customercode_exists($inputcode) == false) {
			$code = "FAILURE";
			$msg = "新增失敗。已有客戶編號" . $inputcode;
		} else {
			$result = $this->customer_model->insertCustomer($data);
			if ($need_purchase_service == 1) {
				//add service data to service user table

				//get last inserted id
				$lastId = $this->customer_model->getCustomerByPhone($mobile);
				// $insert_id = $this->db->insert_id();

				//end get last inserted id

				// $purchatedateformat = DateTime::createFromFormat('Y-m-d', $purchased_date);
				$purchasetimeStamp = "";
				date_default_timezone_set('Asia/Hong_Kong');
				if (!empty($purchased_date)) {

					$purchatedateformat = new DateTime($purchased_date);
					// echo $date->getTimestamp();
					if ($purchatedateformat === false) {

					} else {
						$purchasetimeStamp = $purchatedateformat->getTimestamp();
					}
				}
				$data2 = array(
					'user_id' => $lastId,
					'service_id' => $service_id,
					// 'purchased_date'=>$purchased_date,
					'purchased_date' => $purchasetimeStamp,
					'purchased_price' => $purchased_price,
					'purchased_qty' => $purchased_qty,
					'available_qty' => $available_qty,
					'remark2' => $remark2,
				);

				$result2 = $this->servicesuser_model->insertServicesUser($data2);
				//end add service data to service user table
			} //if($need_purchase_service==1){

			if ($result == false) {
				$code = "FAILURE";
				$msg = "記錄不能加入";
			} else {
				$code = "SUCCESS";
				$msg = "記錄成功加入";
				//for add user it will add a secret key to database

				//end

			}
		}

		header('Content-Type: application/json');
		// $code="SUCCESS";
		// $code="FAILURE";
		// $msg="已有相關記錄";
		// $myArray = ['id'=>12, 'name'=>'Topi'];
		$myArray = ['recordstatus' => $code, 'msg' => $msg];
		echo json_encode($myArray);
		// echo "posted";

	}
	public function update() {

		$id = $this->input->post('id');
		$inputcode = $this->input->post('code');
		$display_name = $this->input->post('display_name');
		// $chi_name=$this->input->post('chi_name');
		// $eng_firstname=$this->input->post('eng_firstname');
		// $eng_lastname=$this->input->post('eng_lastname');
		$gender = $this->input->post('gender');
		$dob = $this->input->post('dob');
		$mobile = $this->input->post('mobile');
		$district_id = $this->input->post('district_id');
		$area_id = $this->input->post('area_id');
		$zone = $this->input->post('zone');
		$address = $this->input->post('address');
		$join_date = $this->input->post('join_date');
		$shop_id = $this->input->post('shop_id');
		$skin_improve = $this->input->post('skin_improve');
		$referred_mobile = $this->input->post('referred_mobile');
		$remark = $this->input->post('remark');
		$oridistrict_id = $this->input->post('oridistrict_id');
		$oriarea_id = $this->input->post('oriarea_id');
		$orizone = $this->input->post('orizone');
		$first_registered_tenant_no = $this->input->post('first_registered_tenant_no');
		$concurrent_registered_tenant_no = $this->input->post('concurrent_registered_tenant_no');
		$level = $this->input->post('level');
		$isTemp = $this->input->post('isTemp');
		$channelSelectID = $this->input->post('channelSelectID');
		$prefer_pic = $this->input->post('prefer_pic');
		$body_improve = $this->input->post('body_improve');
		$bodyoptionother_text = $this->input->post('bodyoptionother_text');
		$face_improve = $this->input->post('face_improve');
		$faceoptionother_text = $this->input->post('faceoptionother_text');

		// $need_purchase_service=$this->input->post('need_purchase_service');
		// $service_id=$this->input->post('service_id');
		// $purchased_date=$this->input->post('purchased_date');
		// $purchased_qty=$this->input->post('purchased_qty');
		// $available_qty=$this->input->post('available_qty');
		// $remark2=$this->input->post('remark2');

		//2020-09-08 added portable field
		$comefrompage = "";
		// $comefrompage=$this->input->post('comefrompage');
		if ($this->input->post('comefrompage') != false) {
			$comefrompage = $this->input->post('comefrompage');
		}
		$id_number = "";
		if ($this->input->post('id_number') != false) {
			$id_number = $this->input->post('id_number');
		}
		$career_name = "";
		if ($this->input->post('career_name') != false) {
			$career_name = $this->input->post('career_name');
		}
		$age = "";
		if ($this->input->post('age') != false) {
			$age = $this->input->post('age');
		}
		$body_height = "";
		if ($this->input->post('body_height') != false) {
			$body_height = $this->input->post('body_height');
		}
		$body_weight = "";
		if ($this->input->post('body_weight') != false) {
			$body_weight = $this->input->post('body_weight');
		}
		$married_status = "";
		if ($this->input->post('married_status') != false) {
			$married_status = $this->input->post('married_status');
		}
		$child_num = "";
		if ($this->input->post('child_num') != false) {
			$child_num = $this->input->post('child_num');
		}
		$disease = "";
		if ($this->input->post('disease') != false) {
			$disease = $this->input->post('disease');
		}
		$diseaseother = "";
		if ($this->input->post('diseaseother') != false) {
			$diseaseother = $this->input->post('diseaseother');
		}
		$sensitivity = "";
		if ($this->input->post('sensitivity') != false) {
			$sensitivity = $this->input->post('sensitivity');
		}
		$surgery = "";
		if ($this->input->post('surgery') != false) {
			$surgery = $this->input->post('surgery');
		}
		$medicine = "";
		if ($this->input->post('medicine') != false) {
			$medicine = $this->input->post('medicine');
		}
		$allergy = "";
		if ($this->input->post('allergy') != false) {
			$allergy = $this->input->post('allergy');
		}
		$lifestyle = "";
		if ($this->input->post('lifestyle') != false) {
			$lifestyle = $this->input->post('lifestyle');
		}
		$habbit = "";
		if ($this->input->post('habbit') != false) {
			$habbit = $this->input->post('habbit');
		}
		$lighttheraphist = "";
		if ($this->input->post('lighttheraphist') != false) {
			$lighttheraphist = $this->input->post('lighttheraphist');
		}
		$otherlighttherapist = "";
		if ($this->input->post('otherlighttherapist') != false) {
			$otherlighttherapist = $this->input->post('otherlighttherapist');
		}
		$botoxtherapist = "";
		if ($this->input->post('botoxtherapist') != false) {
			$botoxtherapist = $this->input->post('botoxtherapist');
		}
		$transtherapist = "";
		if ($this->input->post('transtherapist') != false) {
			$transtherapist = $this->input->post('transtherapist');
		}
		$feeding = "";
		if ($this->input->post('feeding') != false) {
			$feeding = $this->input->post('feeding');
		}
		$beautytreat = "";
		if ($this->input->post('beautytreat') != false) {
			$beautytreat = $this->input->post('beautytreat');
		}
		$paymentmethod = "";
		if ($this->input->post('paymentmethod') != false) {
			$paymentmethod = $this->input->post('paymentmethod');
		}
		$otherpayment = "";
		if ($this->input->post('otherpayment') != false) {
			$otherpayment = $this->input->post('otherpayment');
		}
		$referrer1 = "";
		if ($this->input->post('referrer1') != false) {
			$referrer1 = $this->input->post('referrer1');
		}
		$sensitivity_option = "";
		if ($this->input->post('sensitivity_option') != false) {
			$sensitivity_option = $this->input->post('sensitivity_option');
		}
		$surgery_option = "";
		if ($this->input->post('surgery_option') != false) {
			$surgery_option = $this->input->post('surgery_option');
		}
		$medicine_option = "";
		if ($this->input->post('medicine_option') != false) {
			$medicine_option = $this->input->post('medicine_option');
		}
		$allergy_option = "";
		if ($this->input->post('allergy_option') != false) {
			$allergy_option = $this->input->post('allergy_option');
		}

		//end　2020-09-08 added portable field

		if (!empty($district_id)) {
			$inputDistrict_id = $district_id;
		} else {
			$inputDistrict_id = $oridistrict_id;
		}
		if (!empty($area_id)) {
			$inputArea_id = $area_id;
		} else {
			$inputArea_id = $oriarea_id;
		}
		if (!empty($zone)) {
			$inputZone = $zone;
		} else {
			$inputZone = $orizone;
		}

		$data = array(
			'id' => $id,
			'code' => $inputcode,
			'display_name' => $display_name,
			// 'chi_name'=>$chi_name,
			// 'eng_firstname'=>$eng_firstname,
			// 'inputadminname'=>$inputadminname,
			// 'eng_lastname'=>$eng_lastname,
			'gender' => $gender,
			'dob' => $dob,
			'mobile' => $mobile,
			'district_id' => $inputDistrict_id,
			'area_id' => $inputArea_id,
			'zone' => $inputZone,
			'address' => $address,
			'join_date' => $join_date,
			'shop_id' => $shop_id,
			'skin_improve' => $skin_improve,
			'referred_mobile' => $referred_mobile,
			'remark' => $remark,
			'oridistrict_id' => $oridistrict_id,
			'oriarea_id' => $oriarea_id,
			'orizone' => $orizone,
			'first_registered_tenant_no' => $first_registered_tenant_no,
			'concurrent_registered_tenant_no' => $concurrent_registered_tenant_no,
			'level' => $level,
			'isTemp' => $isTemp,
			'channelSelectID' => $channelSelectID,
			'prefer_pic' => $prefer_pic,
			'body_improve' => $body_improve,
			'bodyoptionother_text' => $bodyoptionother_text,
			'face_improve' => $face_improve,
			'faceoptionother_text' => $faceoptionother_text,
			// 'need_purchase_service'=>$need_purchase_service,
			// 'service_id'=>$service_id,
			// 'purchased_date'=>$purchased_date,
			// 'purchased_qty'=>$purchased_qty,
			// 'available_qty'=>$available_qty,
			// 'remark2'=>$remark2,

			//added portable field 2020-0908
			'referrer1' => $referrer1,
			'comefrompage' => $comefrompage,
			'id_number' => $id_number,
			'career_name' => $career_name,
			'age' => $age,
			'body_height' => $body_height,
			'body_weight' => $body_weight,
			'married_status' => $married_status,
			'child_num' => $child_num,
			'disease' => $disease,
			'diseaseother' => $diseaseother,
			'sensitivity_option' => $sensitivity_option,
			'sensitivity' => $sensitivity,
			'surgery_option' => $surgery_option,
			'surgery' => $surgery,
			'medicine_option' => $medicine_option,
			'medicine' => $medicine,
			'allergy_option' => $allergy_option,
			'allergy' => $allergy,
			'lifestyle' => $lifestyle,
			'habbit' => $habbit,
			'lighttheraphist' => $lighttheraphist,
			'otherlighttherapist' => $otherlighttherapist,
			'botoxtherapist' => $botoxtherapist,
			'transtherapist' => $transtherapist,
			'feeding' => $feeding,
			'beautytreat' => $beautytreat,
			'paymentmethod' => $paymentmethod,
			'otherpayment' => $otherpayment,

			//end added portable field 2020-0908

		);

		// $code="";
		// if($this->frontenduser_model->admin_exists($inputadminname)==false){
		//     $code="FAILURE";
		//     $msg="已有管理員姓名".$inputadminname;
		// }
		// else
		// if($this->customer_model->customercode_existsbyid($code,$id)==false){
		//     $entercode=$code;
		//     $code="FAILURE";
		//     $msg="已有客戶編號".$entercode;
		// }
		$headcode = $this->shop_model->getShopcodeHead($first_registered_tenant_no);

		if ($this->customer_model->customermobile_existsbyid($mobile, $id) == false) {
			// $entercode=$code;
			$code = "FAILURE";
			$msg = "更改失敗。已有客戶電話號碼" . $mobile;
		} elseif (!empty($inputcode) && strpos($inputcode, $headcode) !== 0) {
			$code = "FAILURE";
			$msg = "更改失敗。客戶編號的前綴應為 " . $headcode . "。";
		} elseif (!empty($inputcode) && $inputcode == $headcode . "0000") {
			$code = "FAILURE";
			$msg = "更改失敗。請填寫客戶編號.現在客戶編號是" . $headcode . "0000" . "。";
		} elseif (!empty($inputcode) && $this->customer_model->customercode_existsbyid($inputcode, $id) == false) {
			$code = "FAILURE";
			$msg = "新增失敗。已有客戶編號" . $inputcode;
		} else {
			$result = $this->customer_model->updateCustomer($data);
			if ($result == false) {
				$code = "FAILURE";
				$msg = "記錄不能更改";
			} else {
				$code = "SUCCESS";
				$msg = "記錄成功更改";
				//for add user it will add a secret key to database

				//end

			}
		}

		header('Content-Type: application/json');
		// $code="SUCCESS";
		// $code="FAILURE";
		// $msg="已有相關記錄";
		// $myArray = ['id'=>12, 'name'=>'Topi'];
		$myArray = ['recordstatus' => $code, 'msg' => $msg];
		echo json_encode($myArray);
		// echo "posted";
	}

	public function status() {
		$action = $this->input->post('action');
		$personid = $this->input->post('personid');
		if ($action == "add") {

			//insert first level id
			$data = array(

				'id' => $personid,
				'status' => 1,
				// 'level1id'=>$level1id,
				// // 'inputadminname'=>$inputadminname,
				// 'level2id'=>$level2id,
				// 'level3id'=>$level3id,
				// 'level4id'=>$level4id
			);

			$result = $this->customer_model->updateStatus($data);
		}
		if ($action == "remove") {
			$data = array(

				'id' => $personid,
				'status' => 0,
			);

			$result = $this->customer_model->updateStatus($data);
		} //if($action=="remove"){

		if ($result == false) {
			$code = "FAILURE";
			$msg = "記錄不能更改";
		} else {
			$code = "SUCCESS";
			$msg = "記錄成功更改";
		}

		header('Content-Type: application/json');
		// $code="SUCCESS";
		// $code="FAILURE";
		// $msg="已有相關記錄";
		// $myArray = ['id'=>12, 'name'=>'Topi'];
		$myArray = ['recordstatus' => $code, 'msg' => $msg];
		echo json_encode($myArray);
		// echo "posted";

	}
	public function getPreferPic() {
		$cust_id = $this->input->post('cust_id');
		$data = $this->customer_model->getPreferPic($cust_id);
		header('Content-Type: application/json');
		echo json_encode($data);

	} //public function getPreferPic(){
	public function edit() {

		// $request= new Request();
		// $admin=$request->getBody();

		// 'inputadminname':$('#inputadminname').val(),
		//     'inputloginname':$('#inputloginname').val(),
		//     'inputPassword'
		// $name=$this->input->post('name');

		//add security trim input-todo
		//hash password for security
		$inputcompanynameedit = $this->input->post('inputcompanynameedit');
		$inputfullnameedit = $this->input->post('inputfullnameedit');
		$inputteledit = $this->input->post('inputteledit');
		// $inputadminname=$this->input->post('inputadminnameedit');
		$inputloginname = $this->input->post('inputloginnameedit');
		$inputPassword = $this->input->post('inputPasswordedit');
		$id = $this->input->post('inputadminid');

		$data = array(

			'inputcompanynameedit' => $inputcompanynameedit,
			'inputfullnameedit' => $inputfullnameedit,
			'inputteledit' => $inputteledit,
			// 'inputadminname'=>$inputadminname,
			'inputloginname' => $inputloginname,
			'inputPassword' => $inputPassword,
			'id' => $id,
		);

		$code = "";
		// if($this->frontenduser_model->admin_existsbyid($inputadminname,$id)==false){
		//     $code="FAILURE";
		//     $msg="已有管理員姓名".$inputadminname;
		// }
		// else
		if ($this->frontenduser_model->login_existsbyid(strtolower($inputloginname), $id) == false) {
			$code = "FAILURE";
			$msg = "已有登入名稱" . $inputloginname;
		} else {
			$result = $this->frontenduser_model->updateAdmin($data);
			if ($result == false) {
				$code = "FAILURE";
				$msg = "記錄不能更改";
			} else {
				$code = "SUCCESS";
				$msg = "記錄成功更改";
			}

		}

		header('Content-Type: application/json');
		// $code="SUCCESS";
		// $code="FAILURE";
		// $msg="已有相關記錄";
		// $myArray = ['id'=>12, 'name'=>'Topi'];
		$myArray = ['recordstatus' => $code, 'msg' => $msg];
		echo json_encode($myArray);
		// echo "posted";

	}

	public function delete() {
		$inputdeletecheckboxvalue = $this->input->post('inputdeletecheckboxvalue');
		$result = true;
		foreach ($inputdeletecheckboxvalue as $key => $values) {
			if ($this->frontenduser_model->deleteAdmin($values) == false) {
				$result = false;
			}

		} //foreach ($inputdeletecheckboxvalue as $key => $values){

		if ($result == true) {
			$code = "SUCCESS";
			$msg = "相關記錄成功删徐";
		} else {
			$code = "FAILURE";
			$msg = "相關記錄不能删徐";
		}

		// $msg=$inputdeletecheckboxvalue;
		header('Content-Type: application/json');
		$myArray = ['recordstatus' => $code, 'msg' => $msg];
		echo json_encode($myArray);
	}
	public function getadmindata() {
		$id = $this->input->post('user_id');
		$data = $this->frontenduser_model->getAdmindateByid($id);
		header('Content-Type: application/json');
		echo json_encode($data);
	}
	public function checkrefererid() {
		//test referer
		$customer_id = $this->input->get('id', TRUE);
		// echo $product_id;
		$data = $this->customer_model->getCustomer($customer_id);
		if (!empty($data->referred_mobile)) {
			echo $data->referred_mobile;
			$refererdata = $this->customer_model->getReferrerByCodeOrPhone($data->referred_mobile);
			if (!empty($refererdata->id)) {
				echo $refererdata->id;
			}
		}
	}

} //class Admins {
