<?php 

Class Admin_m extends CI_Model {
    
	public function checkEmail($email){
		$this->db->select();
		$this->db->from('members');
		$this->db->where('emailAddress',$email);
		$query=$this->db->get();
		return $query->num_rows();
		}  
               
        public function createProfile($compName,$compAddress,$compEmail,$compPhone,$contact,$compPassword,$date){
            $data=array('mycomp_address'=>$compAddress,'mycomp_name'=>$compName,'mycomp_email'=>$compEmail,'mycomp_phone'=>$compPhone,'mycomp_password'=>$compPassword,'mycomp_contact'=>$contact,'reg_date'=>$date,'status'=>'1');
            return $this->db->insert('company',$data);
            
        }
        
        // returns all branches
        public function branches(){
            return $this->db->get('branch')->result_array();
        }
        
        //returns all divisions
        public function divisions(){
            return $this->db->get('divisions')->result_array();
            
        }
        public function getAllContribution($id){
            $this->db->where('profileID',$id);
            $this->db->where('transStatus','Paid');
            return $this->db->get('agm2016_transaction')->result_array();
        }
        
        //inserts agm2016_transaction
        public function insertTransact($profileId,$transName,$transNo,$transAmount,$transStatus,$transDate,$transYear,$paymentMode,$feeItemId){
         $data=array('profileID'=>$profileId,'transName'=>$transName,'transNo'=>$transNo,'transAmount'=>$transAmount,'transStatus'=>$transStatus,'transDate'=>$transDate,'transYear'=>$transYear,'paymentMode'=>$paymentMode,'feeAdminmID'=>$feeItemId);
         $this->db->insert('agm2016_transaction',$data);
         return $this->db->insert_id();
        }
        //Authenticate a returning applicant
        public function authenticate($username,$password){
            $this->db->select();
            $this->db->from('conferenceadmin');
            $this->db->where('username',$username);
            $this->db->where('password',$password);
            $this->db->where('status',1);
            return $this->db->get()->result_array();
            
                
        }
        public function checkMyLogin($username,$password){
            $this->db->where('username',$username);
            $this->db->where('password',$password);
            $this->db->where('status',1);
            $query=$this->db->get('conferenceadmin');
            return $query->num_rows();
        }
        
        public function duePrevious($regNo){
            $this->db->where('reg_no',$regNo);
            $query=$this->db->get('payitem_amount');
            $row=$query->row_array();
            return $row['prev_out'];
        }
        public function dueAnnual($regNo){
            $this->db->where('reg_no',$regNo);
            $query=$this->db->get('payitem_amount');
            $row=$query->row_array();
            return $row['annualsub'];
        }
        
        //selects all from a table
        public function getAll($table){
            return $this->db->get($table)->result_array();
        }
        //returns application status
        public function applicationStatus($coopNo){
            $this->db->where('coopNo',$coopNo);
            return $this->db->get('mortgageApplication')->result_array();
        }
        //inserts fellow
        public function insertApply($title, $surname, $firstname, $othernames,$gender,$nat,$dob,$place, $home, $email, $phone,$maiden,$identity,$identityNo,$idIssue,$idExpiry,$employment,$employer,$employerEmail,$employerPhone,$employerAddress,$nok,$nokAddress,$nokPhone,$dependent,$agree,$category,$passport,$year,$date,$category,$contType){
            $data=array('title'=>$title,'lastname'=>$surname,'firstname'=>$firstname, 'othernames'=>$othernames, 'gender'=>$gender,'nationalityID'=>$nat, 'birthPlace'=>$place,'birthDate'=>$dob,'identityID'=>$identity,'identityNumber'=>$identityNo,'identityDateIssued'=>$idIssue,'identityDateExpired'=>$idExpiry,'maidenName'=>$maiden,'emailAddress'=>$email,'phoneNumber'=>$phone,'homeAddress'=>$home,'dependantNumber'=>$dependent,'nextofKinName'=>$nok,'nextofKinAddress'=>$nokAddress,'nextofKinPhone'=>$nokPhone,'photograph'=>$passport,'agreement'=>$agree,'yearJoined'=>$year,'dateRegister'=>$date,'category'=>$category,'contType'=>$contType);
            $this->db->insert('profile',$data);
            return $this->db->insert_id(); 
            
        }
        //inserts mortgage application
        public function insertMortgageApply($coopNo,$date){
            $data=array('coopNo'=>$coopNo,'dateApplied'=>$date,'status'=>'0');
            return $this->db->insert('mortgageApplication',$data);
        }
        public function getCriteria($category,$contType){
            $this->db->where('cat',$category);
            $this->db->where('contType',$contType);
            return $this->db->get('mortgageCriteria')->result_array();
        }
        public function update($id, $title, $surname, $othernames,$password){
            $data=array('title'=>$title,'surname'=>$surname,'othernames'=>$othernames,'password'=>$password);
            $this->db->where('id',$id);
            return $this->db->update('conferenceadmin',$data);      
            
        }

public function exportExcel(){
	    $this->db->select('agm2016_conference.confID,agm2016_conference.confName,agm2016_conference.memberNo,agm2016_category.cat_name, agm2016_conference.confAuthNum,agm2016_conference.confEmail,agm2016_conference.confPhone,agm2016_transaction.transAmount,agm2016_conference.bank,agm2016_conference.confRegDate');
            $this->db->join('agm2016_transaction', 'agm2016_conference.confAuthNum = agm2016_transaction.transRef'); 
            $this->db->join('agm2016_category', 'agm2016_conference.confCatID =agm2016_category.cat_id '); 
            $this->db->where('agm2016_transaction.transStatus','PAID');
            
            $query = $this->db->get('agm2016_conference');
            if ($query->num_rows() > 0) {
                $row = $query->result_array();
                return $row;
            } else{
                return false;
            }

}
        public function transactions($limit=0, $offset=0, $order_by='confName', $direction='DESC'){
            // $query=$this->db->query("SELECT distinct * FROM agm2016_conference a,agm2016_transaction b,agm2016_category c WHERE a.confAuthNum=b.transRef AND a.confCatID=c.cat_id AND b.transType='999' AND b.transStatus='PAID' LIMIT 0,10");
            
			$this->db->select('agm2016_conference.*, agm2016_transaction.*,agm2016_category.*');
            $this->db->join('agm2016_transaction', 'agm2016_conference.confAuthNum = agm2016_transaction.transRef'); 
            $this->db->join('agm2016_category', 'agm2016_conference.confCatID =agm2016_category.cat_id '); 
            $this->db->where('agm2016_transaction.transStatus','PAID');
            $this->db->order_by($order_by, 'ASC');
            
            if($limit>0)
                {
                    $this->db->limit($limit, $offset);
                }
			$query = $this->db->get('agm2016_conference');
            if ($query->num_rows() > 0) {
                $row = $query->result_array();
                return $row;
            } else{
                return false;
            }
        }
		public function count_transactions(){
            $this->db->select('agm2016_conference.*, agm2016_transaction.*,agm2016_category.*');
            $this->db->join('agm2016_transaction', 'agm2016_conference.confAuthNum = agm2016_transaction.transRef'); 
            $this->db->join('agm2016_category', 'agm2016_conference.confCatID =agm2016_category.cat_id '); 
            $this->db->where('agm2016_transaction.transStatus','PAID');
			return $this->db->count_all('agm2016_conference');
		}
        public function allTransactions(){
            $query=$this->db->query("SELECT * FROM agm2016_conference a,agm2016_transaction b,agm2016_category c WHERE a.confAuthNum=b.transRef AND a.confCatID=c.cat_id AND b.transType='999' AND b.transStatus='PAID'");
            return $query->result_array();
        }
        public function officers($id){
            $query=$this->db->query("SELECT * FROM conferenceadmin a,confroles b WHERE a.roles_id=b.confroleID AND a.id !='$id'");
            return $query->result_array();
        }
        public function insertOfficer($title,$surname,$othernames,$username,$password,$role){
            $data=array('title'=>$title,'surname'=>$surname,'othernames'=>$othernames,'username'=>$username,'password'=>$password,'roles_id'=>$role);
            return $this->db->insert('conferenceadmin',$data);
        }
        public function updateOfficer($title,$surname,$othernames,$username,$password,$role,$id){
            $data=array('title'=>$title,'surname'=>$surname,'othernames'=>$othernames,'username'=>$username,'password'=>$password,'roles_id'=>$role);
            $this->db->where('id',$id);
            return $this->db->update('conferenceadmin',$data);
        }
        public function editOfficer($id){
            $this->db->where('id',$id);
            return $this->db->get('conferenceadmin')->result_array();
        }
        public function dues($reg_no){
            $this->db->where('reg_no',$reg_no);
            return $this->db->get('payitem_amount')->result_array();
        }
        public function updatePassport($id,$name){
            $data=array('photograph'=>$name);
            $this->db->where('profileID',$id);
            return $this->db->update('members',$data);
        }
        
        public function checkPayment($transNo){
            $query=$this->db->query("SELECT * FROM agm2016_conference a,agm2016_transaction b WHERE a.confAuthNum=b.transRef AND b.transType='999' AND transStatus='PAID'");
            return $query->num_rows();
        }
   
    public function getMemberDetails($niqsNo){
        $this->db->where('memberNo',$niqsNo);
        return $this->db->get('members')->result_array();
    }
public function getCategoryDetails($catId){
        $this->db->where('cat_id',$catId);
        return $this->db->get('agm2016_category')->result_array();
    }

    public function insertDetails($category, $niqsNo, $names, $phone, $email, $company, 
         $authNum,$date, $grade, $bank, $paymode, $form_no){
        $year=date('Y');
       /* $data=array('confCatID'=>$category,'memberNo'=>$niqsNo,'confName'=>$names,'confPhone'=>$phone,'confEmail'=>$email,
			'confCompany'=>$company,'confLocation'=>$postal,'confAuthNum'=>$authNum,'confYear'=>$year); */
		##############################################
		## my code starts here 
		#############################################

		$data=array('confCatID'=>$category,'memberNo'=>$niqsNo,'confName'=>$names,'confPhone'=>$phone,
            'confEmail'=>$email,'confCompany'=>$company,'confAuthNum'=>$authNum,'confRegDate'=>$date,'confYear'=>$year,
			 'bank' =>$bank, 'paymentMode' => $paymode, 'teller_no' => $form_no);
		##############################################
		## my code ends here 
		#############################################
        $this->db->insert('agm2016_conference',$data);
        return $this->db->insert_id();
    }

   public function insertCPD($memberno){
$confId = 1; $unit = 18;
$data = array('confID' => $confId, 'memberNo' => $memberno, 'unit' => $unit);
$this->db->insert('confparticipant', $data);
}

    public function insertTrans($date,$appType,$amount,$status,$insert,$transID){
       $data=array('transDate'=>$date,'transType'=>$appType,'transAmount'=>$amount,'transStatus'=>$status,'transAppID'=>$insert,'transRef'=>$transID);
       return $this->db->insert('agm2016_transaction',$data);
   }
	public function paymentDetails($transNo = false, $name = false){

$sql = "";
if ($transNo != false){
 $sql = "SELECT * FROM agm2016_conference a,agm2016_transaction b,agm2016_category c WHERE a.confAuthNum=b.transRef AND a.confCatID=c.cat_id AND b.transType='999' AND transStatus='PAID' AND b.transRef='$transNo'";
} elseif ($name != false){
 $sql = "SELECT * FROM agm2016_conference a, agm2016_transaction b,agm2016_category c WHERE a.confAuthNum=b.transRef AND a.confCatID=c.cat_id AND b.transType='999' AND transStatus='PAID' AND a.confName LIKE '%$name%'";
}
            $query=$this->db->query($sql);
            return $query->result_array();
        }
        public function updateAttendee($confID,$name,$email,$phone,$amount,$transRef){
            $data=array('confName'=>$name,'confEmail'=>$email,'confPhone'=>$phone);
            $this->db->where('confID',$confID);
            $this->db->update('agm2016_conference',$data);
$data2 = array('transAmount' =>$amount);
$this->db->where('transRef',$transRef);
return $this->db->update('agm2016_transaction',$data2);
        }
        
        public function checkMaterialCollection($confID){
            $query=$this->db->query("SELECT * FROM confmatcollection a,conferencematerial b WHERE a.confmaterialID=b.confMaterialID AND a.confID='$confID'");
            return $query->result_array();
        }
        public function checkMaterial2($confID){
            $query=$this->db->query("SELECT * FROM conferencematerial WHERE confMaterialID NOT IN (SELECT confMaterialID FROM confmatcollection WHERE confID='$confID')");
            return $query->result_array();
        }
        
        public function insertMaterial($confID,$values){
            $data=array('confMaterialID'=>$values,'confID'=>$confID);
            return $this->db->insert('confmatcollection',$data);
        }


        public function insertEmployment($insert_id,$employment,$employer,$employerPhone,$employerAddress,$employerEmail){
            $data=array('profileID'=>$insert_id,'employmentTypeID'=>$employment,'employerName'=>$employer,'employerAddress'=>$employerAddress,'employerPhoneNumber'=>$employerPhone,'employerEmailAddress'=>$employerEmail);
            $this->db->insert('employmentdetails',$data);
            
        }
        public function updateEmployment($insert_id,$employment,$employer,$employerPhone,$employerAddress,$employerEmail){
            $data=array('employmentTypeID'=>$employment,'employerName'=>$employer,'employerAddress'=>$employerAddress,'employerPhoneNumber'=>$employerPhone,'employerEmailAddress'=>$employerEmail);
            $this->db->where('profileID',$insert_id);
            return $this->db->update('employmentdetailsMembers',$data);
            
        }
        
        
        //updates fellow
         public function updateApply($surname,$othernames,$home,$email,$phone,$dob,$nat,$grade,$sec,$sec_cert,$grad_year_sec,$deg1,$deg1_cert,$grad_year_deg1,$deg2,$deg2_cert,$grad_year_deg2,$id){
            $data=array('surname'=>$surname,'othernames'=>$othernames,'contact_addr'=>$home,'email'=>$email,'mobilephone'=>$phone,'dob'=>$dob,'nationality'=>$nat,'grade'=>$grade,'sec_school'=>$sec,'grad_year_sec'=>$grad_year_sec,'cert_sec'=>$sec_cert,'degree1'=>$deg1,'grad_year_deg1'=>$grad_year_deg1,'cert_deg1'=>$deg1_cert,'degree2'=>$deg2,'grad_year_deg2'=>$grad_year_deg2,'cert_deg2'=>$deg2_cert);
            $this->db->where('id',$id);
            return $this->db->update('applicants',$data);
            
            
        }
        
        //checks if a details is alreay inserted
        public function checkInsert($table,$value,$field){
            $this->db->where($field,$value);
            $query=$this->db->get("$table");
            return $query->num_rows();
        }
        
        //inserts into fellow_agm table
        public function fellowAgm($stud_id,$agm,$agmVenue1,$agmVenue2,$agmVenue3,$agmVenue4,$agmVenue5,$agmDate1,$agmDate2,$agmDate3,$agmDate4,$agmDate5){
            $data=array('stud_id'=>$stud_id,'agm'=>$agm,'agmVenue1'=>$agmVenue1,'agmVenue2'=>$agmVenue2,'agmVenue3'=>$agmVenue3,'agmVenue4'=>$agmVenue4,'agmVenue5'=>$agmVenue5,'agmDate1'=>$agmDate1,'agmDate2'=>$agmDate2,'agmDate3'=>$agmDate3,'agmDate4'=>$agmDate4,'agmDate5'=>$agmDate5);
            return $this->db->insert('fellow_agm',$data);
        }
        //updates fellow_agm
        public function updateFellowAgm($stud_id,$agm,$agmVenue1,$agmVenue2,$agmVenue3,$agmVenue4,$agmVenue5,$agmDate1,$agmDate2,$agmDate3,$agmDate4,$agmDate5){
            $data=array('agm'=>$agm,'agmVenue1'=>$agmVenue1,'agmVenue2'=>$agmVenue2,'agmVenue3'=>$agmVenue3,'agmVenue4'=>$agmVenue4,'agmVenue5'=>$agmVenue5,'agmDate1'=>$agmDate1,'agmDate2'=>$agmDate2,'agmDate3'=>$agmDate3,'agmDate4'=>$agmDate4,'agmDate5'=>$agmDate5);
            $this->db->where('stud_id',$stud_id);
            return $this->db->update('fellow_agm',$data);
        }
        
        //inserts into fellow_bm
        public function fellowBm($stud_id,$bm,$bmVenue1,$bmVenue2,$bmVenue3,$bmVenue4,$bmVenue5,$bmDate1,$bmDate2,$bmDate3,$bmDate4,$bmDate5){
            $data=array('stud_id'=>$stud_id,'bm'=>$bm,'bmVenue1'=>$bmVenue1,'bmVenue2'=>$bmVenue2,'bmVenue3'=>$bmVenue3,'bmVenue4'=>$bmVenue4,'bmVenue5'=>$bmVenue5,'bmDate1'=>$bmDate1,'bmDate2'=>$bmDate2,'bmDate3'=>$bmDate3,'bmDate4'=>$bmDate4,'bmDate5'=>$bmDate5);
            return $this->db->insert('fellow_bm',$data);                    
        }
        //updates fellow_bm
        public function updateFellowBm($stud_id,$bm,$bmVenue1,$bmVenue2,$bmVenue3,$bmVenue4,$bmVenue5,$bmDate1,$bmDate2,$bmDate3,$bmDate4,$bmDate5){
            $data=array('bm'=>$bm,'bmVenue1'=>$bmVenue1,'bmVenue2'=>$bmVenue2,'bmVenue3'=>$bmVenue3,'bmVenue4'=>$bmVenue4,'bmVenue5'=>$bmVenue5,'bmDate1'=>$bmDate1,'bmDate2'=>$bmDate2,'bmDate3'=>$bmDate3,'bmDate4'=>$bmDate4,'bmDate5'=>$bmDate5);
            $this->db->where('stud_id',$stud_id);
            return $this->db->update('fellow_bm',$data);                    
        }
        
        //inserts fellow_contribution
        public function fellowContribution($stud_id,$inventions,$modifications,$design,$specialTech,$author){
            $data=array('stud_id'=>$stud_id,'inventions'=>$inventions,'modifications'=>$modifications,'design'=>$design,'specialTech'=>$specialTech,'author'=>$author);
            return $this->db->insert('fellow_contribution',$data);
        }
        //updates fellow_contribution
        public function updateFellowContribution($stud_id,$inventions,$modifications,$design,$specialTech,$author){
        $data=array('inventions'=>$inventions,'modifications'=>$modifications,'design'=>$design,'specialTech'=>$specialTech,'author'=>$author);
        $this->db->where('stud_id',$stud_id);
        return $this->db->update('fellow_contribution',$data);
        }
        
        //inserts fellow_divisionMeeting
        public function fellow_divisionMeeting($stud_id,$dm,$dmVenue1,$dmVenue2,$dmVenue3,$dmVenue4,$dmVenue5,$dmDate1,$dmDate2,$dmDate3,$dmDate4,$dmDate5){
        $data=array('stud_id'=>$stud_id,'dm'=>$dm,'dmVenue1'=>$dmVenue1,'dmVenue2'=>$dmVenue2,'dmVenue3'=>$dmVenue3,'dmVenue4'=>$dmVenue4,'dmVenue5'=>$dmVenue5,'dmDate1'=>$dmDate1,'dmDate2'=>$dmDate2,'dmDate3'=>$dmDate3,'dmDate4'=>$dmDate4,'dmDate5'=>$dmDate5);
        return $this->db->insert('fellow_divisionMeeting',$data);
            
        }
        //updates fellow_divisionMeeting
        public function updateFellowDivisionMeeting($stud_id,$dm,$dmVenue1,$dmVenue2,$dmVenue3,$dmVenue4,$dmVenue5,$dmDate1,$dmDate2,$dmDate3,$dmDate4,$dmDate5){
        $data=array('dm'=>$dm,'dmVenue1'=>$dmVenue1,'dmVenue2'=>$dmVenue2,'dmVenue3'=>$dmVenue3,'dmVenue4'=>$dmVenue4,'dmVenue5'=>$dmVenue5,'dmDate1'=>$dmDate1,'dmDate2'=>$dmDate2,'dmDate3'=>$dmDate3,'dmDate4'=>$dmDate4,'dmDate5'=>$dmDate5);
        $this->db->where('stud_id',$stud_id);
        return $this->db->update('fellow_divisionMeeting',$data);
        }
        
        //inserts fellow_public_position
        public function fellow_public_position($stud_id,$position,$position1,$position2,$position3,$period1,$period2,$period3){
        $data=array('stud_id'=>$stud_id,'position'=>$position,'position1'=>$position1,'position2'=>$position2,'position3'=>$position3,'period1'=>$period1,'period2'=>$period2,'period3'=>$period3);
        return $this->db->insert('fellow_public_position',$data);
                    
        }
        
        //updates fellow_public_position
        public function updateFellowPublicPosition($stud_id,$position,$position1,$position2,$position3,$period1,$period2,$period3){
        $data=array('position'=>$position,'position1'=>$position1,'position2'=>$position2,'position3'=>$position3,'period1'=>$period1,'period2'=>$period2,'period3'=>$period3);
        $this->db->where('stud_id',$stud_id);
        return $this->db->update('fellow_public_position',$data);
                    
        }
        //inserts fellow_other_details
        public function fellow_other_details($stud_id,$electionDate,$years,$bo,$boDetails,$do,$doDetails,$nseRep,$nseRepDetails,$nseEOffice,$nseEOfficePos,$nseEOfficePeriod,$nseCouncil,$nseCouncilDetails){
            $data=array('stud_id'=>$stud_id,'electionDate'=>$electionDate,'years'=>$years,'bo'=>$bo,'boDetails'=>$boDetails,'do'=>$do,'doDetails'=>$doDetails,'nseRep'=>$nseRep,'nseRepDetails'=>$nseRepDetails,'nseEOffice'=>$nseEOffice,'nseEOfficePos'=>$nseEOfficePos,'nseEOfficePeriod'=>$nseEOfficePeriod,'nseCouncil'=>$nseCouncil,'nseCouncilDetails'=>$nseCouncilDetails);
            return $this->db->insert('fellow_other_details',$data);
        }
        
        
        //updates fellow_other_details
        public function updateFellowOtherDetails($stud_id,$electionDate,$years,$bo,$boDetails,$do,$doDetails,$nseRep,$nseRepDetails,$nseEOffice,$nseEOfficePos,$nseEOfficePeriod,$nseCouncil,$nseCouncilDetails){
            $data=array('electionDate'=>$electionDate,'years'=>$years,'bo'=>$bo,'boDetails'=>$boDetails,'do'=>$do,'doDetails'=>$doDetails,'nseRep'=>$nseRep,'nseRepDetails'=>$nseRepDetails,'nseEOffice'=>$nseEOffice,'nseEOfficePos'=>$nseEOfficePos,'nseEOfficePeriod'=>$nseEOfficePeriod,'nseCouncil'=>$nseCouncil,'nseCouncilDetails'=>$nseCouncilDetails);
            $this->db->where('stud_id',$stud_id);
            return $this->db->update('fellow_other_details',$data);
        }
        
        //inserts into fellow_division_meeting
        public function fellow_division_meeting($stud_id,$dm,$dmVenue1,$dmVenue2,$dmVenue3,$dmVenue4,$dmVenue5,$dmDate1,$dmDate2,$dmDate3,$dmDate4,$dmdate5){
            $data=array('stud_id'=>$stud_id,'dm'=>$dm,'dmVenue1'=>$dmVenue1,'dmVenue2'=>$dmVenue2,'dmVenue3'=>$dmVenue3,'dmVenue4'=>$dmVenue4,'dmVenue5'=>$dmVenue5,'dmDate1'=>$dmDate1,'dmDate2'=>$dmDate2,'dmDate3'=>$dmDate3,'dmDate4'=>$dmDate4,'dmDate5'=>$dmdate5);
            return $this->db->insert('fellow_division_meeting',$data);
        }
        
        //updates fellow_division_meeting
        /*public function updateFellowDivisionMeeting($stud_id,$dm,$dmVenue1,$dmVenue2,$dmVenue3,$dmVenue4,$dmVenue5,$dmDate1,$dmDate2,$dmDate3,$dmDate4,$dmdate5){
            $data=array('dm'=>$dm,'dmVenue1'=>$dmVenue1,'dmVenue2'=>$dmVenue2,'dmVenue3'=>$dmVenue3,'dmVenue4'=>$dmVenue4,'dmVenue5'=>$dmVenue5,'dmDate1'=>$dmDate1,'dmDate2'=>$dmDate2,'dmDate3'=>$dmDate3,'dmDate4'=>$dmDate4,'dmDate5'=>$dmdate5);
            $this->db->where('stud_id',$stud_id);
            return $this->db->update('fellow_division_meeting',$data);
        }*/
        
        //inserts into fellow_tech_meeting
        public function fellow_techMeeting($stud_id,$tm,$techVenue1,$techVenue2,$techVenue3,$techVenue4,$techVenue5,$techDate1,$techDate2,$techDate3,$techDate4,$techDate5){
            $data=array('stud_id'=>$stud_id,'tm'=>$tm,'techVenue1'=>$techVenue1,'techVenue2'=>$techVenue2,'techVenue3'=>$techVenue3,'techVenue4'=>$techVenue4,'techVenue5'=>$techVenue5,'techDate1'=>$techDate1,'techDate2'=>$techDate2,'techDate3'=>$techDate3,'techDate4'=>$techDate4,'techDate5'=>$techDate5);
            return $this->db->insert('fellow_techMeeting',$data);
            
        }
        
        //updates fellow_techMeeting(
        public function updateFellowTechMeeting($stud_id,$tm,$techVenue1,$techVenue2,$techVenue3,$techVenue4,$techVenue5,$techDate1,$techDate2,$techDate3,$techDate4,$techDate5){
            $data=array('tm'=>$tm,'techVenue1'=>$techVenue1,'techVenue2'=>$techVenue2,'techVenue3'=>$techVenue3,'techVenue4'=>$techVenue4,'techVenue5'=>$techVenue5,'techDate1'=>$techDate1,'techDate2'=>$techDate2,'techDate3'=>$techDate3,'techDate4'=>$techDate4,'techDate5'=>$techDate5);
            $this->db->where('stud_id',$stud_id);
            return $this->db->update('fellow_techMeeting',$data);
            
        }
        
        //inserts fellowTechPaper
        public function fellow_techPaper($stud_id,$techPaper,$title1,$title2,$title3,$title4,$techPaperDate1,$techPaperDate2,$techPaperDate3,$techPaperDate4){
            $data=array('stud_id'=>$stud_id,'techPaper'=>$techPaper,'title1'=>$title1,'title2'=>$title2,'title3'=>$title3,'title4'=>$title4,'techPaperDate1'=>$techPaperDate1,'techPaperDate2'=>$techPaperDate2,'techPaperDate3'=>$techPaperDate3,'techPaperDate4'=>$techPaperDate4);
            return $this->db->insert('fellow_techPaper',$data);
            
        }
        
        //updates fellow_techPaper
        public function updateFellowTechPaper($stud_id,$techPaper,$title1,$title2,$title3,$title4,$techPaperDate1,$techPaperDate2,$techPaperDate3,$techPaperDate4){
            $data=array('techPaper'=>$techPaper,'title1'=>$title1,'title2'=>$title2,'title3'=>$title3,'title4'=>$title4,'techPaperDate1'=>$techPaperDate1,'techPaperDate2'=>$techPaperDate2,'techPaperDate3'=>$techPaperDate3,'techPaperDate4'=>$techPaperDate4);
            $this->db->where('stud_id',$stud_id);
            return $this->db->update('fellow_techPaper',$data);
            
        }
        public function getMany($table,$value,$field){
            $this->db->where($field,$value);
            return $this->db->get($table)->result_array();
        }
        //returns fees
        public function fees($type){
            $query=$this->db->query("SELECT * FROM apply_fee_item WHERE (grade='$type' OR grade='0')");
            return $query->result_array();
            //$this->db->where('grade',$type);
            //$this->db->or_where('grade','0');
            //return $this->db->get('apply_fee_item')->result_array();
        }
        
      
        
        //check if a transaction has been inserted once
        public function checkTrans($authNum){
            $this->db->where('agm2016_transaction.transRef',$authNum);
            $query=$this->db->get('apply_reg_pay');
            return $query->num_rows();
        }
        //returns the name of the company
        public function getName($id){
            $this->db->where('id',$id);
            $query=$this->db->get('company');
            $row=$query->row_array();
            return $row['mycomp_name'];
        }
        //updates profile
        public function updateProfile($compName, $compAddress, $compEmail, $compPhone, $contact, $compPassword,$compId){
           $data=array('mycomp_address'=>$compAddress,'mycomp_name'=>$compName,'mycomp_email'=>$compEmail,'mycomp_phone'=>$compPhone,'mycomp_password'=>$compPassword,'mycomp_contact'=>$contact);
           $this->db->where('id',$compId); 
           return $this->db->update('company',$data); 
            
        }
        public function reportSearch($id,$from,$to){
            $query=$this->db->query("SELECT * FROM company_agm2016_transaction a,agm2016_transaction b WHERE a.agm2016_transactionid=b.trans_no AND b.date_pay BETWEEN $from and $to GROUP BY a.nseregno");
            /*$this->db->select();
            $this->db->from('company_agm2016_transaction a');
            $this->db->join('agm2016_transaction b','a.agm2016_transactionid=b.trans_no');
            $this->db->where('a.company_id',$id);
            $this->db->group_by('a.nseregno');
            $this->db->between($from,$to);
            $query=$this->db->get();*/
            return $query->result_array();
        }
        
        public function report($id){
            $this->db->select();
            $this->db->from('company_transaction a');
            $this->db->join('transaction b','a.transactionid=b.trans_no');
            $this->db->where('a.company_id',$id);
            $this->db->group_by('a.nseregno');
            $query=$this->db->get();
            return $query->result_array();
        }
        
        //counts for check out
        public function checkoutCount($transid,$compId){
        $query=$this->db->query("SELECT * FROM payitem c,nsemem b,company_transaction a WHERE a.nseregno=b.nseregno AND a.item_id=c.id AND transactionid='$transid' AND company_id='$compId'");
            return $query->num_rows();
            
        }
        
        //returns items for checking out
         public function checkOut($start,$limit,$transid,$compId){
            $query=$this->db->query("SELECT * FROM payitem c,nsemem b,company_transaction a WHERE a.nseregno=b.nseregno AND a.item_id=c.id AND transactionid='$transid' AND company_id='$compId' LIMIT $start,$limit");
            return $query->result_array();
            
            
            
        }
        
        public function resetPassword($email,$password){
            $data=array('mycomp_password'=>$password);
            $this->db->where('mycomp_email',$email);
            return $this->db->update('company',$data);
        }
        //Checks if a member has been added to the shopping cart before
        
        public function checkMembersExistCart($nseregno,$transid){
            $this->db->where('nseregno',$nseregno);
            $this->db->where('transactionid',$transid);
            $query=$this->db->get('company_transaction');
            return $query->num_rows();
        }
        //checks login details
        public function checkLogin($email,$password){
            $this->db->where('mycomp_email',$email);
            $this->db->where('mycomp_password',$password);
            $this->db->where('status',1);
            return $this->db->get('company')->result_array();
        }
        
        public function membersProfile($nseregno){
            //$query=$this->db->query("SELECT * FROM nsemem a,payitem_amount b,company_agm2016_transaction c WHERE a.nseregno=b.nseregno AND a.nseregno=c.nseregno AND c.agm2016_transactionid='$transId' AND a.nseregno NOT IN (c.nseregno)");
            $this->db->select();
            $this->db->from('nsemem a');
            $this->db->join('payitem_amount b','a.nseregno=b.nseregno');
            $this->db->where('a.nseregno',$nseregno);
            
            return $this->db->get()->result_array();
            //return $query->result_array();
            
        }
        
        public function getItemName($items){
            /*$this->db->where('id',$items);
            $query=$this->db->get('payitem')->result_array();
            $row=$query->row_array();
            return $row['name'];*/
            $query=$this->db->query("SELECT name FROM payitem WHERE id='$items'");
            $row=$query->row_array();
            return $row['name'];
            
            
                    
        }
        
        public function itemAmount($nseregno,$item_name){
            $query=$this->db->query("SELECT $item_name FROM payitem_amount WHERE nseregno='$nseregno'");
            $row=$query->row_array();
            return $row[$item_name];
            
            
        }
        
        public function dispTotalAmount($transid,$compId){
            $query=$this->db->query("SELECT SUM(amount) as amount FROM company_transaction WHERE transactionid='$transid' AND company_id='$compId'");
            $row=$query->row_array();
            return $row['amount'];
        }
        public function transSummary($transid,$compId){
            $query=$this->db->query("SELECT SUM(a.amount) as amount,b.nseregno FROM company_transaction a,nsemem b WHERE a.nseregno=b.nseregno AND transactionid='$transid' AND company_id='$compId' GROUP BY b.nseregno LIMIT 0, 5");
            return $query->result_array();
        }
        
        public function insertItem($nseregno,$items,$id,$item_amount,$transid,$date){
            $data=array('agm2016_transactionid'=>$transid,'nseregno'=>$nseregno,'item_id'=>$items,'amount'=>$item_amount,'company_id'=>$id,'date'=>$date);
            return $this->db->insert('company_agm2016_transaction',$data);
        }
        
        public function retrieveTransDetails($transId){
            $query=$this->db->query("SELECT SUM(`amount`) as amount,nseregno,agm2016_transactionid,item_id FROM company_agm2016_transaction WHERE agm2016_transactionid='$transId' GROUP BY nseregno");
            return $query->result_array();
        }
        
        public function retrieveTransDetailsAgain($transId,$date){
            $this->db->where('agm2016_transactionid',$transId);
            $this->db->where('date',$date);
            return $this->db->get('company_agm2016_transaction')->result_array();
        }
        
        //returns Item Names
        public function itemNames($id){
            $this->db->where('id',$id);
            $query=$this->db->get('payitem');
            $row=$query->row_array();
            return $row['name'];
        }
        
        public function updateTransDetails($name,$amount,$nseregno,$transId){
            $data=array($name=>$amount);
            $this->db->where('nseregno',$nseregno);
            $this->db->where('trans_no',$transId);
            return $this->db->update('agm2016_transaction',$data);
        }
        //returns current year
        /*public function getCurrentYear(){
            $query=$this->db->get('current_year');
            $row=$this->query->row_array();
            return $row['currentyear'];
        }*/
        
        //inserts into agm2016_transaction table
        public function insertagm2016_transaction($nseregno,$date,$total,$status,$trxn,$year){
            $data=array('nseregno'=>$nseregno,'date_pay'=>$date,'amount_paid'=>$total,'trans_no'=>$trxn,'pay_status'=>$status,'year'=>$year);
            return $this->db->insert('agm2016_transaction',$data);
        }
        public function cartSummary($transid,$compId){
            $query=$this->db->query("SELECT * FROM payitem c,nsemem b,company_agm2016_transaction a WHERE a.nseregno=b.nseregno AND a.item_id=c.id AND agm2016_transactionid='$transid' AND company_id='$compId'");
            return $query->result_array();
        }
        
        //this checks if the agm2016_transaction has been captured earlier
        public function checkagm2016_transaction($transId){
            $this->db->where('trans_no',$transId);
            $query=$this->db->get('agm2016_transaction');
            return $query->num_rows();
        }
        
        //returns agm2016_transaction amount
        public function checkAmount($transId){
            $query=$this->db->query("SELECT SUM(amount_paid) as amount FROM agm2016_transaction WHERE trans_no='$transId'" );
            $row=$query->row_array();
            return $row['amount'];
        }
        
        public function viewDetails($transid,$compId,$regno){
            $query=$this->db->query("SELECT * FROM payitem c,nsemem b,company_agm2016_transaction a WHERE a.nseregno=b.nseregno AND a.item_id=c.id AND agm2016_transactionid='$transid' AND a.company_id='$compId' AND a.nseregno='$regno' ");
            return $query->result_array();
        }
        
        public function emptyCart($transId){
            $this->db->where('agm2016_transactionid',$transId);
            return $this->db->delete('company_agm2016_transaction');
        }
        
        //deletes an item from the cart
        public function deleteItem($id){
            $this->db->where('id',$id);
            return $this->db->delete('company_agm2016_transaction');
        }
        
        //returns profile
        public function profile($id){
            $this->db->where('id',$id);
            return $this->db->get('conferenceadmin')->result_array();
        }
        
        
        //returns any particular
        public function getAny($table,$value,$field,$output){
            $this->db->where($field,$value);
            $query=$this->db->get($table);
            $row=$query->row_array();
            return $row["$output"];
        }
       public function insertTrans22($regNo,$date,$transID,$status,$amount,$reference_id){
           $data=array('regNo'=>$regNo,'date'=>$date,'agm2016_transactionid'=>$transID,'status'=>$status,'amount'=>$amount,'reference_id'=>$reference_id);
      $this->db->insert('transaction',$data);
           }
    
}