Assalamualaikum dan salam sejahtera..
Berikut adalah contoh carian rekod bagi pengguna sistem menggunakan CodeIgnitor...
View
<div class="row-fluid">
<div class="span10 offset1">
<?php echo tbs_horizontal_form_open('', array('id'=>'user_search'));?>
<?php echo tbs_horizontal_input(array( //validation using jquery -> assets/validation/register.js
'name'=>'usr_id',
'id'=>'usr_id',
'value'=>set_value('usr_id', $userregistration['usr_id']),
'class'=>'',
'maxlength'=>'15',
), array(
'label'=>'User Id',
), false);?>
<?php echo tbs_horizontal_input(array(
'name'=>'usr_fullname',
'id'=>'usr_fullname',
'value'=> set_value('usr_fullname', $userregistration['usr_fullname']),
'class'=>'input-xlarge',
), array(
'label'=>'User Name',
), false); ?>
<?php echo tbs_horizontal_dropdown('usr_cdstate', $state,
$data['usr_cdstate'], array(
'id'=>'usr_cdstate',
'class'=>'input-xlarge',
), array(
'label'=>'State',
), false)?>
<?php echo tbs_horizontal_dropdown('cd_agencytype', $agency,
$data['cd_agencytype'], array(
'id'=>'cd_agencytype',
'class'=>'input-xlarge',
), array(
'label'=>'Agency Type',
), false)?>
<div class="control-group">
<label for="cd_facilitytype" class="control-label">Type of Facilities </label>
<div class="controls">
<span id="ajaxfacility">
<!-- Please select Agency Type first -->
<select class="input-xlarge" id="cd_facilitytype" name="cd_facilitytype">
<option value="">-- Please Select Agency Type First --</option>
<?php
//echo '<pre>'.print_r($facilitytype).'</pre>';
//foreach ($facilitytype as $key => $value) {
// echo '<option value="'.$key.'">'.$value.'</option>';
//}
?>
</select>
</span>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group">
<label for="usr_facilitycode" class="control-label">Name of Facilities</label>
<div class="controls">
<span id="ajaxfacilityName">
<!-- Please select Agency Type first -->
<select class="input-xlarge" id="usr_facilitycode" name="usr_facilitycode">
<option value="">-- Please Select State First --</option>
<?php
//echo '<pre>'.print_r($facilitytype).'</pre>';
//foreach ($facilitytype as $key => $value) {
// echo '<option value="'.$key.'">'.$value.'</option>';
//}
?>
</select>
</span>
<span class="help-inline"></span>
</div>
</div>
<?php echo tbs_horizontal_dropdown('usr_active',$status,
$data['usr_active'], array(
'id'=>'usr_active',
'class'=>'input-medium',
), array(
'label'=>'User Active',
), false); ?>
<?php echo form_close();?>
</div>
</div>
</br>
<div align="center">
<button type="button" class="btn btn-orange search"><i class="icon icon-search icon-white"></i> Search</button>
<a class="btn btn-orange" href="<?php echo site_url('admin/add')?>">
<i class="icon-question-sign icon-white"></i> New User
</a>
</div>
<div class="line"></div>
<div id="listUser"></div>
<div id="callback"></div>
<script src='<?php echo base_url('assets/validation/admin.js')?>'></script>
<script>
window.listUser = function(param){
AjaxCall(base_url+'index.php/admin/listJson',param, 'listUser', 'id', '', '');
};
$(document).ready(function(){
$('button.search').live('click', function() {
var $var = "";
$('#user_search').find(':input[type=text]').each(function(key, val){ //find all input in form and put in array
if(val.value != '') { $var += val.name+"="+val.value+"&"; }
});
$('#user_search').find('select').each(function(key, val){ //find all input in form and put in array
if(val.value != '') { $var += val.name+"="+val.value+"&"; }
});
if($var != '') {
AjaxCall(base_url+'index.php/admin/listJson', $var, '', '', 'listUser("'+$var+'")', '');
}
return false;
});
$('#usr_cdstate').live('change', function() {
AjaxCall(base_url+'index.php/admin/facilityName', 'id='+$(this).val(), '', '', '', 'ajaxfacilityName');
});
$('#cd_agencytype').live('change', function() {
var fcode = $('#cd_agencytype').val();
var id = $(this).val();
AjaxCall(base_url+'index.php/admin/facilityType', 'id='+$(this).val(), '', '', '', 'ajaxfacility');
});
$('#cd_facilitytype').live('change', function() {
var state = $('#usr_cdstate').val();
var fcode = $('#cd_agencytype').val();
var id = $(this).val();
AjaxCall(base_url+'index.php/admin/facilityNameType/','state='+state+'&fcode='+fcode+'&id='+id,'', '', '','ajaxfacilityName');
});
});
</script>
Models
<!-- Models : modal tbl_tr_userregistration_model.php -->
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Tbl_tr_userregistration_model extends CI_Model
{
private $tableName;
private $pk;
private $usr_counting;
private $created_date;
private $updated_date;
function __construct() {
parent::__construct();
$this->tableName = "tr_userregistration";
$this->pk = "usr_regnumber";
$this->fk = "usr_id";
$this->usr_counting = "usr_counting";
$this->created_date = "dtcreated";
$this->updated_date = "dtupdated";
}
public function ajaxFacilityType($id) {
$this->db->select('*');
$this->db->where('cd_agencytype',$id);
return $this->db->get('lt_facilitytype')->result_array();
}
public function ajaxFacilityName($id) {
$this->db->select('*');
$this->db->where('State',$id);
return $this->db->get('lt_facilities')->result_array();
}
public function ajaxFacilityNameType($state, $fcode, $id) {
if($state!= '' && $fcode!= '' && $id!= '') {
$this->db->select('*');
$this->db->where('State',$state);
$this->db->where('cd_agencytype',$fcode);
$this->db->where('PFacilityCode',$id);
return $this->db->get('lt_facilities')->result_array();
} else if ($state== '' && $fcode!= '' && $id!= '') {
$this->db->select('*');
$this->db->where('cd_agencytype',$fcode);
$this->db->where('PFacilityCode',$id);
return $this->db->get('lt_facilities')->result_array();
}
}
public function ajaxfacilityType_add($id) {
$this->db->select('*');
$this->db->where('cd_agencytype',$id);
return $this->db->get('lt_facilitytype')->result_array();
}
public function ajaxfacilityName_add($state, $fcode, $id) {
$this->db->select('*');
$this->db->where('State',$state);
$this->db->where('cd_agencytype',$fcode);
$this->db->where('PFacilityCode',$id);
return $this->db->get('lt_facilities')->result_array();
}
public function searchCases($where='', $like_where='')
{
$this->db->select('tr_userregistration.usr_id, tr_userregistration.usr_icno, tr_userregistration.usr_regnumber, tr_userregistration.usr_facilitycode, tr_userregistration.usr_icno, tr_userregistration.usr_fullname, tr_userregistration.usr_active, lt_state.desc_state, lt_facilities.FullName');
$this->db->join('lt_facilities', 'lt_facilities.facilitycode = tr_userregistration.usr_facilitycode', 'left');
$this->db->join('lt_facilitytype', 'lt_facilitytype.cd_facilitytype = tr_userregistration.cd_facilitytype', 'left');
$this->db->join('lt_state', 'lt_state.cd_state = tr_userregistration.usr_cdstate', 'left');
if($where != ''){
$this->db->where($where);
}
if($like_where!= ''){
$this->db->like($like_where);
}
if($where != ''){
$this->db->where($where);
}
$this->db->group_by('usr_icno');
return $this->db->get($this->tableName)->result_array();
}
}
?>
Controller
<?php
class Admin extends MY_Controller {
public function __construct() {
parent::__construct();
// load model
// put your model Class
$this->_ci =& get_instance();
$this->load->model("Tbl_tr_userregistration_model");
$this->load->model("Chimss_model");
$this->load->helper('html');
}
function facilityType() {
$id = $this->input->post('id');
$data = $this->Tbl_tr_userregistration_model->ajaxFacilityType($id);
echo '<select class="input-xlarge" id="cd_facilitytype" name="cd_facilitytype">';
echo '<option value="">-- Please Select --</option>';
foreach ($data as $index => $value) {
//echo '<pre>'.print_r($value).'</pre>';
echo '<option value="'.$value['cd_facilitytype'].'">'.$value['decs_facilitytype'].'</option>';
}
echo '</select>';
}
function facilityName() {
$id = $this->input->post('id');
$data = $this->Tbl_tr_userregistration_model->ajaxFacilityName($id);
echo '<select class="input-xlarge" id="usr_facilitycode" name="usr_facilitycode">';
echo '<option value="">-- Please Select --</option>';
foreach ($data as $index => $value) {
echo '<option value="'.$value['facilitycode'].'">'.$value['FullName'].'</option>';
}
echo '</select>';
}
function facilityNameType() {
$state = $this->input->post('state');
$fcode = $this->input->post('fcode');
$id = $this->input->post('id');
$data = $this->Tbl_tr_userregistration_model->ajaxFacilityNameType($state, $fcode, $id);
echo '<select class="input-xlarge" id="usr_facilitycode" name="usr_facilitycode">';
echo '<option value="">-- Please Select --</option>';
foreach ($data as $index => $value) {
echo '<option value="'.$value['facilitycode'].'">'.$value['FullName'].'</option>';
}
echo '</select>';
}
function facilityType_add() {
$id = $this->input->post('id');
$data = $this->Tbl_tr_userregistration_model->ajaxfacilityType_add($id);
echo '<select class="input-xlarge" id="cd_facilitytype" name="cd_facilitytype">';
echo '<option value="">-- Please Select --</option>';
foreach ($data as $index => $value) {
// echo '<pre>'.print_r($value).'</pre>';
echo '<option value="'.$value['cd_facilitytype'].'">'.$value['decs_facilitytype'].'</option>';
}
echo '</select>';
}
function facilityName_add() {
$state = $this->input->post('state');
$fcode = $this->input->post('fcode');
$id = $this->input->post('id');
$data = $this->Tbl_tr_userregistration_model->ajaxfacilityName_add($state, $fcode, $id);
// echo $data;
echo '<select class="input-xlarge" id="usr_facilitycode" name="usr_facilitycode">';
echo '<option value="">-- Please Select --</option>';
foreach ($data as $index => $value) {
//echo '<pre>'.print_r($value).'</pre>';
echo '<option value="'.$value['facilitycode'].'">'.$value['FullName'].'</option>';
}
echo '</select>';
}
//LISTING CASE STATUS
function listing(){
$data = $this->Chimss_model->get_info('tr_userregistration', array('usr_regnumber'=>$id));
//echo '<pre>'.print_r($data).'</pre>';
$data['userregistration']['usr_regnumber'] = $this->input->post('usr_regnumber');
$data['userregistration']['usr_fullname'] = $this->input->post('usr_fullname');
$data['title'] = "List of CHIMSS's User";
$data['state'] = $this->Chimss_model->get_select_list('lt_state', array('key'=>'cd_state', 'val'=>'desc_state', 'orderby'=>'cd_state'),1);
$data['agency'] = $this->Chimss_model->get_select_list('lt_agencytype', array('key'=>'cd_agencytype', 'val'=>'decs_agenctype', 'orderby'=>'cd_agencytype'), 1);
$data['facilitytype'] = $this->Chimss_model->get_select_list('lt_facilitytype', array('key'=>'cd_facilitytype', 'val'=>'decs_facilitytype', 'orderby'=>'cd_facilitytype'), 1, array('active_status'=>'Y'));
$data['namefacility'] = $this->Chimss_model->get_select_list('lt_facilities', array('key'=>'facilitycode', 'val'=>'FullName', 'orderby'=>'facilitycode'), 1);
$data['status'] = array(''=>'-- Please Select --', 'Y'=>'Yes', 'N'=>'No');
$this->form_validation->set_rules('usr_regnumber','User Registratiom');
$this->_render_page($data);
}
function listJson(){
if($this->input->post('usr_id') != '') {
$data['search']['tr_userregistration.usr_id'] = $this->input->post('usr_id');
}
if($this->input->post('usr_fullname') != '') {
$data['like_search']['tr_userregistration.usr_fullname'] = $this->input->post('usr_fullname');
}
if($this->input->post('usr_cdstate') != '') {
$data['search']['tr_userregistration.usr_cdstate'] = $this->input->post('usr_cdstate');
}
if($this->input->post('cd_agencytype') != '') {
$data['search']['tr_userregistration.cd_agencytype'] = $this->input->post('cd_agencytype');
}
if($this->input->post('usr_facilitycode') != '') {
$data['search']['tr_userregistration.usr_facilitycode'] = $this->input->post('usr_facilitycode');
}
if($this->input->post('usr_active') != '') {
$data['search']['tr_userregistration.usr_active'] = $this->input->post('usr_active');
}
$users = $this->Tbl_tr_userregistration_model->searchCases($data['search'], $data['like_search']);
//set template
$this->table->set_template(array(
'table_open'=>'<table class="table table-condensed table-bordered table-striped table-hover dynamic">',
));
//set table heading
$this->table->set_heading(array(
array('data'=>'User Id'),
array('data'=>'User Name', 'width'=>'300px'),
array('data'=>'IC.No/Passport'),
array('data'=>'Facilities Name'),
array('data'=>'State'),
'Action'
));
//set table data
$bil = 1;
foreach ($users as $key => $val) {
$button = "<a href='view/".$val['usr_regnumber']."' class='btn btn-mini' id='view' title='View User Information' attr='".$val['usr_regnumber']."'><i class='icon icon-zoom-in'></i></a>";
$button .= nbs(1)."<a href='update/".$val['usr_regnumber']."' class='btn btn-mini' id='update' title='Edit User Information' attr='".$val['usr_regnumber']."'><i class='icon icon-edit'></i></a>";
$button .= nbs(1)."<a href='javascript:void(0);' class='btn btn-mini' title='Delete User Information' id='delete' attr='".$val['usr_regnumber']."'><i class='icon icon-trash'></i></a>";
$this->table->add_row(array(
array('data'=>$val['usr_id'], 'class'=>'text-left'),
strtoupper($val['usr_fullname']),
$val['usr_icno'],
strtoupper($val['FullName']),
strtoupper($val['desc_state']),
$button,
));
$bil++;
}
//generate table
echo $this->table->generate();
$sDom = '"sDom": "<\'row-fluid\'<\'span4\'l><\'span8\'f>r>t<\'row-fluid\'<\'span8\'i><\'span4\'p>>", "sPaginationType": "bootstrap", "oLanguage": {"sLengthMenu": "_MENU_ records per page"}, "aoColumnDefs": [{"aTargets": [ 0 ], "bSortable": false },{"aTargets": [ -1 ], "bSortable": false },{ "aTargets": [ \'_all\' ], "bSortable": true }]';
//load class dynamic di Controller, tidak boleh load pada View sbb nanti nak Search, Paging dan Sorting
echo "<script>$(document).ready(function() { $('.dynamic').dataTable({".$sDom."}); });</script>";
}
}
?>
----------------------------------------------------------
Disediakan Oleh : Saipul Bahari bin Hasan
Sumber : Sistem CHIMSS
0 comments:
Post a Comment