aries_

operator controller

Sep 21st, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.10 KB | None | 0 0
  1. <?php
  2.  
  3.     class operator extends CI_Controller {
  4.  
  5.      public function  __construct() {
  6.             parent::__construct();
  7.             if($this->session->userdata('level') != 'Operator' and $this->session->userdata('isLogin') != 1)
  8.         {
  9.             $this->session->set_flashdata('msg', 'Anda harus login terlebih dahulu !!!');
  10.             redirect('log');
  11.         }
  12.            
  13.                //$this->load->model('Train_model');
  14.                $this->load->model('user_model','us');
  15.                $this->load->model('View_training','VT');
  16.                 //$this->load->model('update_model','upd');
  17.    }
  18.     public function index()
  19.     {
  20.         //$this->load->view('welcome_message');
  21.         //$this->load->view('tampilan');
  22.         $isi['isi']='Home';
  23.         $this->load->view('template_ope',$isi);
  24.     }
  25.  
  26.     public function view(){
  27.         $data['View_training'] = $this->VT->selectAll();
  28.         $data['isi']='opp/Data_view';
  29.         $this->load->view('template_ope', $data);
  30.     }
  31.    
  32.     public function update($id){
  33.         $data['View_training'] = $this->VT->plan_by($id);
  34.         $data['Terlaksana']=$this->VT->Get_akses('plan','Terlaksana');
  35.         foreach($data as $key=>$r){
  36.             }
  37.         $data['isi']='opp/Data_update';
  38.         $this->load->view('template_ope', $data);
  39.     }
  40.  
  41.  
  42.     public function upload(){
  43.         $data['View_training'] = $this->VT->selectAll();
  44.         $data['isi']='opp/upload_form';
  45.         $this->load->view('template_ope', $data);
  46.     }
  47.    
  48.     public function user(){
  49.         $data['user']=$this->us->show_user();
  50.         $data['isi']='opp/tampil_user';
  51.         $this->load->view('template_ope',$data);
  52.    
  53.     }
  54.  
  55.     public function Adduser(){
  56.         $data['akses']=$this->us->Get_akses('user','Akses');
  57.         foreach($data as $key=>$r){
  58.             }
  59.         $data['isi']='opp/add_user';
  60.         $this->load->view('template_ope',$data);
  61.     }
  62.  
  63.    
  64.      public function edit($nik){
  65.         $data['akses']=$this->us->Get_akses('user','Akses');
  66.         foreach($data as $key=>$r){
  67.  
  68.         }
  69.         $data['m'] = $this->us->show_user_by($nik);
  70.         $data['isi']='opp/Edit_User';
  71.         $this->load->view('template_ope',$data);
  72.     }
  73.  
  74.         public function report(){
  75.         $data['View_training'] = $this->VT->selectAll();
  76.         $data['isi']='opp/chart_view';
  77.         $this->load->view('template_ope', $data);
  78.     }
  79.    
  80.     public function cari(){
  81.         $cat = $this->input->post('pilih');
  82.  
  83.         if ($cat == 1) {
  84.                 $tgl_awal = $this->input->post('tanggal');
  85.         $tgl_akhir = $this->input->post('tanggal_2');
  86.            
  87.         $data['View_training'] = $this->VT->cari_plan_tgl($tgl_awal,$tgl_akhir);
  88.         $data['isi']='opp/Data_view';
  89.         $this->load->view('template_ope', $data);
  90.             }
  91.             elseif ($cat == 2){
  92.             $kode=$this->input->post('kode ');
  93.             if ($kode == "") {
  94.                 redirect ("view" , "refresh");
  95.             }
  96.             else {
  97.             $data['View_training'] = $this->VT->cari__kode($kode);
  98.             $data['isi']='opp/Data_view';
  99.             $this->load->view('template_ope', $data);
  100.             }
  101.         }
  102.             else {
  103.             redirect ("./view" , "refresh");
  104.             }
  105.     }
  106.        
  107.     public function do_upload() {
  108.         $config['upload_path'] = './temp_upload/';
  109.         $config['allowed_types'] = 'xls';          
  110.         $this->load->library('upload', $config);
  111.                
  112.  
  113.             if ( ! $this->upload->do_upload()) {
  114.             $data = array('error' => $this->upload->display_errors());
  115.             //$this->load->view('Upload', $data);
  116.             }
  117.             else {
  118.             $data = array('error' => false);
  119.             $upload_data = $this->upload->data();
  120.            
  121.                 $this->load->library('excel_reader');
  122.                 $this->load->library('excel');
  123.         $this->excel_reader->setOutputEncoding('CP1251');
  124.            
  125.             //$data = new excel_reader($_FILES['userfile']['tmp_name']);
  126.         $file =  $upload_data['full_path'];
  127.         $this->excel_reader->read($file);
  128.         error_reporting(E_ALL ^ E_NOTICE);
  129.  
  130.             // Sheet 1
  131.             $data = $this->excel_reader->sheets[0] ;
  132.                         $dataexcel = Array();
  133.             for ($i = 1; $i <= $data['numRows']; $i++) {
  134.  
  135.                             if($data['cells'][$i][1] == '') break;
  136.                             $dataexcel[$i-1]['KODE_PLAN'] = $data['cells'][$i][1];
  137.                             $dataexcel[$i-1]['ANGKATAN'] = $data['cells'][$i][2];
  138.                             $dataexcel[$i-1]['TGL_MULAI'] = PHPExcel_Style_NumberFormat::toFormattedString($data['cells'][$i][3],'YYYY-MM-DD');
  139.                             $dataexcel[$i-1]['TGL_AKHIR'] = PHPExcel_Style_NumberFormat::toFormattedString($data['cells'][$i][4],'YYYY-MM-DD');
  140.                             $dataexcel[$i-1]['ANGGARAN'] = $data['cells'][$i][5];
  141.                             $dataexcel[$i-1]['PST_A'] = $data['cells'][$i][6];
  142.                             $dataexcel[$i-1]['TGL_AWAL_REAL'] = $data['cells'][$i][7];
  143.                             $dataexcel[$i-1]['TGL_AKHIR_REAL'] = $data['cells'][$i][8];
  144.                             $dataexcel[$i-1]['ANGGARAN_REAL'] = $data['cells'][$i][9];
  145.                             $dataexcel[$i-1]['PST_REAL'] = $data['cells'][$i][10];
  146.                             $dataexcel[$i-1]['KODE_M'] = $data['cells'][$i][11];
  147.                             $dataexcel[$i-1]['KODE_INST'] = $data['cells'][$i][12];
  148.                             $dataexcel[$i-1]['KODE_UBIS'] = $data['cells'][$i][13];
  149.                             $dataexcel[$i-1]['KODE_LC'] = $data['cells'][$i][14];
  150.                             $dataexcel[$i-1]['Terlaksana'] = $data['cells'][$i][15];
  151.                             $dataexcel[$i-1]['Komen'] = $data['cells'][$i][16];
  152.             }
  153.                        
  154.                        
  155.             delete_files($upload_data['file_path']);
  156.          
  157.             $this->VT->tambahdata($dataexcel);
  158.             $data['View_training'] = $this->VT->getupload();
  159.         }
  160.         redirect('operator/view','refresh');
  161.         //$this->load->view('opp/Data_view', $data);
  162.         //$this->session->set_flashdata('msg', 'Data Berhasil Disimpan !!!');
  163.     }
  164.    
  165.    
  166.     public function del($kode){
  167.         $this->VT->del($kode);
  168.         redirect('operator/view');
  169.     }
  170.    
  171.    
  172.      public function upd_train () {
  173.         $id=$this->input->post('id');
  174.         $TGL_AWAL_REAL = $this->input->post('TGL_AWAL_REAL');
  175.         $TGL_AKHIR_REAL = $this->input->post('TGL_AKHIR_REAL');
  176.         $ANGGARAN_REAL = $this->input->post('ANGGARAN_REAL');
  177.         $PST_REAL = $this->input->post('PST_REAL');
  178.         $Terlaksana = $this->input->post('terlaksana');
  179.         $Komen = $this->input->post('komen');
  180.        
  181.         $this->form_validation->set_rules('TGL_AWAL_REAL', 'Tgl Awal Real', 'required');
  182.         $this->form_validation->set_rules('TGL_AKHIR_REAL', 'Tgl Akhir Real', 'required');
  183.         $this->form_validation->set_rules('ANGGARAN_REAL', 'Anggaran Real', 'required|numeric');
  184.         $this->form_validation->set_rules('PST_REAL', 'Peserta Real', 'required|numeric');
  185.         $this->form_validation->set_rules('komen', 'Komen', 'required');
  186.  
  187.         if ($this->form_validation->run() == FALSE)
  188.     {
  189.         $this->session->set_flashdata('msg', 'Periksa Kembali Semua Data !!!');
  190.          redirect('operator/update','refresh');".";
  191.         }
  192.     else
  193.     {
  194.         $this->VT->update_train($id,$TGL_AWAL_REAL, $TGL_AKHIR_REAL, $ANGGARAN_REAL, $PST_REAL, $Terlaksana, $Komen);
  195.         $this->session->set_flashdata('msg', 'Data Berhasil Disimpan !!!');
  196.         redirect('operator/view','refresh');".";
  197.  
  198.          }
  199.                  }
  200.    
  201.  
  202.     public function delete($id){
  203.         $this->us->delete($id);
  204.         redirect('operator/user');
  205.     }
  206.  
  207.    
  208.     public function tambah_user(){
  209.         $nik=$this->input->post('nik');
  210.         $nama=$this->input->post('nama');
  211.         $almt=$this->input->post('almt');
  212.         $user=$this->input->post('user');
  213.         $pass=$this->input->post('pass');
  214.         $akses=$this->input->post('akses');
  215.  
  216.         $this->form_validation->set_rules('nik', 'Nik', 'required|alpha_dash|min_length[7]|max_length[7]|callback_username_check');
  217.         $this->form_validation->set_rules('nama', 'nama', 'required');
  218.     $this->form_validation->set_rules('almt', 'Alamat', 'required');
  219.         $this->form_validation->set_rules('user', 'Username', 'required');
  220.         $this->form_validation->set_rules('pass', 'Password', 'required');
  221.  if ($this->form_validation->run() == FALSE)
  222.     {
  223.     $this->session->set_flashdata('msg', 'Periksa Kembali Semua Data !!!');
  224.          redirect('operator/Adduser','refresh');".";
  225.         }
  226.     else
  227.     {    
  228.             $data_user=$this->us->lihat_user($nik);
  229.             if ($data_user['NIK']==$nik and $data_user['username']==$user) {
  230.                 $this->session->set_flashdata('msg', 'Duplikat NIK dan Username!!!');
  231.          redirect('operator/Adduser','refresh');".";
  232.             }
  233.             elseif($data_user['NIK']== $nik or $data_user['username']==$user){
  234.                  $this->session->set_flashdata('msg', 'Duplikat NIK atau Username!!!');
  235.          redirect('operator/Adduser','refresh');".";
  236.             }
  237.             else {
  238.          $this->us->tambah( $nik,$nama,$almt,$user,$pass,$akses);
  239.     $this->session->set_flashdata('msg', 'Data Berhasil Disimpan !!!');
  240.      redirect('operator/user','refresh');".";
  241.             }
  242.          }
  243.          }
  244.    
  245.    public function update_user(){
  246.     $nik=$this->input->post('nik');
  247.     $nama=$this->input->post('nama');
  248.     $almt=$this->input->post('almt');
  249.     $user=$this->input->post('user');
  250.     $pass=$this->input->post('pass');
  251.     $akses=$this->input->post('akses');
  252.    
  253.      $this->form_validation->set_rules('nik', 'Nik', 'required|alpha_dash|min_length[7]|max_length[7]|callback_username_check');
  254.       $this->form_validation->set_rules('nama', 'nama', 'required');
  255.     $this->form_validation->set_rules('almt', 'Alamat', 'required');
  256.       $this->form_validation->set_rules('user', 'Username', 'required');
  257.      if ($this->form_validation->run() == FALSE)
  258.     {
  259.     redirect('operator/user','refresh');
  260.     }
  261.     else
  262.     {
  263.         if($pass != "")
  264.         {
  265.     $this->us->update($nik,$nama,$almt,$user,$pass,$akses);
  266.     }else{
  267.     $this->us->update_no_pass($nik,$nama,$almt,$user,$akses);
  268.     }
  269.         $this->session->set_flashdata('msg', 'Data Berhasil Diupdate !!!');
  270.                 redirect('operator/user','refresh');
  271.             }
  272.  
  273. }
  274.  
  275.  public function cetak(){
  276.        $data['plan'] = $this->VT->cetakNow();
  277.        $this->load->view('opp/cetakxls', $data);
  278.            }
  279.  
  280.     }
Advertisement
Add Comment
Please, Sign In to add comment