<?php

Class Site extends CI_Model {

    public function getContent($id) {
        $this->db->where('page_ref_id', $id);
        return $this->db->get('web_pages_content')->result_array();
        //$row=$query->row_array();
        //return $row['page_ref_content'];
    }

    public function getNews() {
        $this->db->order_by('news_id', 'DESC');
        return $this->db->get('news_content')->result_array();
    }

    public function Standing($limit, $start) {
        /* $this->db->select();
          $this->db->from('nsemem a');
          $this->db->join('payitem_amount b','a.nseregno=b.nseregno');
          //$this->db->limit(0,50);
          return $this->db->get()->result_array(); */
        $query = $this->db->query("SELECT * FROM nsemem a,payitem_amount b WHERE a.nseregno=b.nseregno ORDER BY a.idd LIMIT $start,$limit");
        return $query->result_array();
    }
public function getAll($table) {
        return $this->db->get($table)->result_array();
    }
    
    public function getMemberDetails($niqsNo){
        $this->db->where('memberNo',$niqsNo);
        return $this->db->get('members')->result_array();
    }
    
    public function insertDetails($category,$niqsNo,$names,$phone,$email,$company,$authNum){
        $year=date('Y');
        $data=array('confCatID'=>$category,'memberNo'=>$niqsNo,'confName'=>$names,'confPhone'=>$phone,'confEmail'=>$email,'confCompany'=>$company,'confAuthNum'=>$authNum,'confYear'=>$year);
        $this->db->insert('event_conference',$data);
        return $this->db->insert_id();
    }
    
    public function getApplication($transID){
        $query=$this->db->query("SELECT * FROM event_conference a,event_transaction b WHERE a.confAuthNum=b.transRef AND b.transRef='$transID'");
        return $query->result_array();
    }
    
    
    public function applicationType(){
        return $this->db->get('applicationtype')->result_array();
    }
    public function newsDetails($id) {
        $this->db->where('news_id', $id);
        return $this->db->get('news_content')->result_array();
    }

    public function eventDetails($id) {
        $this->db->where('id', $id);
        return $this->db->get('events')->result_array();
    }

    public function members($limit, $start) {
        $this->db->limit($limit, $start);
        return $this->db->get('members')->result_array();
    }

    public function countMembers() {
        $this->db->select();
        $this->db->from('nsemem a');
        $this->db->join('payitem_amount b', 'a.nseregno=b.nseregno');
        return $this->db->get()->num_rows();
    }

    public function searchFin($surname) {
        $query = $this->db->query("SELECT * FROM nsemem a,payitem_amount b WHERE a.nseregno=b.nseregno AND a.lastname LIKE '%$surname%'");
        return $query->result_array();
    }

    public function searchFin2($regNo) {
        $query = $this->db->query("SELECT * FROM nsemem a,payitem_amount b WHERE a.nseregno=b.nseregno AND a.nseregno='$regNo'");
        return $query->result_array();
    }

    public function getEvents() {
        return $this->db->get('events')->result_array();
    }

    public function checkLogin($surname, $regNo) {
        $this->db->where('lastname', $surname);
        $this->db->where('nseregno', $regNo);
        return $this->db->get('nsemem')->num_rows();
    }

    public function profile($surname, $regNo) {
        $this->db->where('lastname', $surname);
        $this->db->where('nseregno', $regNo);
        //$this->db->limit(1);
        return $this->db->get('nsemem')->result_array();
    }

    public function fullProfile($idd) {
        $this->db->where('idd', $idd);
        return $this->db->get('nsemem')->result_array();
    }

    public function financial($nseregno) {
        //$query=$this->db->query("SELECT * FROM payitem a,payitem")
        $this->db->where('nseregno', $nseregno);
        return $this->db->get('payitem_amount')->result_array();
    }

    //deletes member from temp transaction
    public function deleteTempTrans($nseregno) {
        $this->db->where('nseregno', $nseregno);
        $this->db->delete('temptrans');
    }

    public function insertItem($nseregno, $items, $item_amount, $name, $date) {
        $data = array('nseregno' => $nseregno, 'items' => $items, 'amount' => $item_amount, 'name' => $name, 'date' => $date);
        return $this->db->insert('temptrans', $data);
    }

    public function getTempTrans($nseregno) {
        $this->db->where('nseregno', $nseregno);
        return $this->db->get('temptrans')->result_array();
    }
    public function getTempTrans2($nseregno,$date) {
        $this->db->where('nseregno', $nseregno);
        $this->db->where('date',$date);
        return $this->db->get('temptrans')->result_array();
    }
    public function updateTrans($transID,$responseCode,$responseDescription,$amount,$paymentRef,$transactionDate,$status){
       $this->db->where('transRef',$transID);
       $data=array('transRespCode'=>$responseCode,'transRespDesc'=>$responseDescription,'transRespAmount'=>$amount,'transRespPayRef'=>$paymentRef,'transRespTransDate'=>$transactionDate,'transStatus'=>$status);
   return $this->db->update('transaction',$data);
    }
    public function getTransaction($transRef){
        $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.transRef='$transRef'");
        return $query->result_array();
    }
    public function amountItem($name,$nseregno){
        //$query=$this->db->query("SELECT $name FROM payitem_amount WHERE nseregno='$nseregno'");
        $this->db->select($name);
        $this->db->from('payitem_amount');
        $this->db->where('nseregno',$nseregno);
        $query=$this->db->get();
        $row=$query->row_array();
        return $row[$name];
    }

    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 retrieveTransDetails($transID){
        $query=$this->db->query("SELECT * FROM nsemem a,transaction b WHERE a.nseregno=b.nseregno AND b.trans_no='$transID'");
        return $query->result_array();
    }

    public function loadPayItem() {
        return $this->db->get('payitem')->result_array();
    }
    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('event_transaction',$data);
   }
    public function getItemName($items) {

        $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];
    }

}
