<?php
class Lookup extends MY_Controller
{
   public function __construct() {
      parent::__construct();
      $this->db_smartone = $this->load->database("onedev", true);
   }

   function dropdown($sp) {
      $sql = "call $sp";
      $qry = $this->db_smartone->query($sql);
      if (! $qry) {
         echo json_encode(array());
      }
      $rows = $qry->result_array();
      if (count($rows) == 0 ) {
         echo json_encode(array());
      }
      echo json_encode($rows);
   }

   function ac($sp) {
      $prm = $this->sys_input;
      $search = $prm['search'];
      $sql = "call $sp(?)";
      if (isset($prm['dep'])) {
         $sql = "call $sp(?,?)";
         $value = $prm['value'];
         $qry = $this->db_smartone->query($sql,array($search,$value));
      } else {
         $qry = $this->db_smartone->query($sql,array($search));
      }
      if (! $qry) {
         echo json_encode(array());
      }
      $rows = $qry->result_array();
      if (count($rows) == 0 ) {
         echo json_encode(array());
         exit;
      }
      echo json_encode($rows);
   }
}
