Example #1
0
    function insert()
    {
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $idu = $session_data['id'];
            $idtbl = $this->input->post('tabel');
            $tabel = $this->mweb->getmanage_by_id($idtbl);
            switch ($idtbl) {
                case '1':
                    $exclude = array('user', 'log');
                    break;
                case '6':
                    $exclude = array('acc');
                    break;
                case '7':
                    $exclude = array('acc');
                    break;
                case '15':
                    $exclude = array('idreq', 'idimg', 'desc');
                    break;
                case '17':
                    $exclude = array('id');
                    break;
                default:
                    $exclude = array('');
                    break;
            }
            $stmt_list = create_statement($tabel, $exclude);
            $query = explode(',', $stmt_list);
            $data = array();
            $kolom = array();
            $ttempb = array();
            $liskol = $this->db->list_fields($tabel);
            $fkolm = array_shift(array_slice($liskol, 0, 1));
            $lid = $this->mweb->get_akhir($fkolm, $tabel);
            $gettempb = $this->mweb->get_tempbrg($lid, $idtbl);
            foreach ($query as $row) {
                $kolom[] = $row;
                switch ($row) {
                    case 'id':
                        $idnee = $this->input->post($row);
                        $idnee = $lid;
                        $data[] = $idnee;
                        break;
                    case 'time':
                        $data[] = date('d-m-Y h:i:s');
                        break;
                    case 'iduser':
                        $data[] = $session_data['id'];
                        break;
                    case 'Kenaikan_Harga':
                        $hbru = $this->input->post('Harga_Baru');
                        $hlma = $this->input->post('Harga_Lama');
                        if (!empty($hbru) && !empty($hlma) && $hbru > $hlma) {
                            $data[] = intval($hbru - $hlma);
                        } else {
                            $data[] = 0;
                        }
                        break;
                    case 'Description':
                        $set = $this->input->post('set');
                        $nmprod = $this->input->post('namaprod');
                        if (!empty($set) && !empty($nmprod)) {
                            $kdbl = $this->mweb->get_akhir('kdbarang', 'barang');
                            $this->db->set('a.status', 'success');
                            $this->db->set('b.kdbarang', $kdbl);
                            $this->db->where('a.idreq', $set);
                            $this->db->where('a.idreq = b.idreq');
                            $this->db->update('antrian as a, request as b');
                            $imm = $nmprod . '+';
                            $imm .= $this->input->post($row);
                            $data[] = $imm;
                        } else {
                            $data[] = $this->input->post($row);
                        }
                        break;
                    case 'kdbarang':
                        if ($tabel === 'postprod') {
                            $data[] = $this->input->post($row);
                        } else {
                            $data[] = implode('|', $gettempb);
                        }
                        break;
                    default:
                        $data[] = $this->input->post($row);
                        break;
                }
            }
            $setdata = array_combine($kolom, $data);
            $idlastt = $this->mweb->settable($tabel, $setdata);
            $isi = implode(',', $data);
            //-----------------------------------------
            $file = 'log.txt';
            $pathfile = APPPATH . 'views/' . $file;
            $tulislog = $session_data['id'] . ',' . date('Y-m-d h:i:s') . ',' . $tabel . ',' . $isi . "\n";
            if (file_exists($pathfile)) {
                $current = file_get_contents($pathfile);
                // Append a new person to the file
                $current .= $tulislog;
                $current .= "\r\n";
                // Write the contents back to the file
                file_put_contents($pathfile, $current);
            } else {
                $handle = fopen($pathfile, 'w') or die('Cannot open file:  ' . $pathfile);
                //implicitly creates file
                fwrite($handle, $tulislog);
            }
            if ($idlastt) {
                switch ($idtbl) {
                    case '1':
                        $this->db->where('idcus', $idlastt);
                        $this->db->update('cus', array('iduser' => $session_data['id']));
                        break;
                    case '3':
                        $sett = $this->input->post('set');
                        $kdbl = $this->mweb->get_akhir('kdbarang', 'barang');
                        if (getusereq($sett)) {
                            $idpeng = getusereq($sett);
                            $notifh = array('from' => $idu, 'iduser' => $idpeng, 'msg' => 'request barang dengan kode <strong>' . $sett . '</strong> success dengan harga jual Rp.<strong>' . gethrgbrg($idlastt) . '</strong>', 'time' => date('d-m-Y h:i:s'));
                            $settnotif = $this->mweb->settable('notif', $notifh);
                            if (!$settnotif) {
                                ?>
							<script type="text/javascript">alert('maaf terjadi kesalahan pada system :(');</script>
						<?php 
                                redirect('login', 'refresh');
                            }
                        }
                        break;
                    case '5':
                        $qqlast = $this->mweb->get_last_id($idlastt, $tabel);
                        foreach ($qqlast as $record) {
                            $pass = $record['password'];
                        }
                        $passbaru = sha1($pass);
                        $this->mweb->updatepass($idlastt, $passbaru);
                        break;
                    case '15':
                        $config['upload_path'] = FCPATH . 'uploads/';
                        $config['allowed_types'] = 'gif|jpg|png';
                        //load the upload library
                        $this->upload->initialize($config);
                        $this->upload->set_allowed_types('*');
                        $data['upload_data'] = '';
                        //if not successful, set the error message
                        if (!$this->upload->do_upload('userfile')) {
                            redirect(site_url('gudang/profile?tab=3&e=1'), 'refresh');
                        } else {
                            //else, set the success message
                            //$idlastt=$this->mweb->last_id_ins('idreq','request');
                            $data = array('msg' => "Upload success!");
                            $dataimg = $this->upload->data();
                            $postkdb = $this->input->post('kdbarang');
                            $desck = $this->input->post('namaprod');
                            if (empty($postkdb)) {
                                $descc = $desck;
                            } else {
                                $descc = $this->input->post('kdbarang');
                            }
                            $dtimg = array('idimg' => '', 'src' => $dataimg['full_path'], 'desc' => $descc);
                            $set = $this->mweb->setimage($dtimg);
                            $setupd = array('idimg' => $set, 'desc' => $desck);
                            $this->db->where('idreq', $idlastt);
                            $this->db->update('request', $setupd);
                            $setantri = array('idreq' => $idlastt, 'time' => date('d-m-Y h:i:s'));
                            $idant = $this->mweb->settable('antrian', $setantri);
                            if ($idant) {
                                if (!is_mimin()) {
                                    $notifmin = array('from' => $idu, 'iduser' => getid_min(), 'msg' => 'ada permintaan barang dengan kode <strong><a href="' . site_url('gudang/slug/17/4/21/a?id=' . $idlastt . '&tbl=15') . '">' . $idlastt . '</a></strong>', 'aksi' => 'request', 'time' => date('d-m-Y h:i:s'));
                                    $this->mweb->settable('notif', $notifmin);
                                }
                            }
                        }
                        break;
                    case '6':
                        if (!is_admin()) {
                            $msginv = array('from' => $idu, 'iduser' => getid_own(), 'aksi' => 'invoice', 'time' => date('d-m-Y h:i:s'), 'msg' => 'invoice kode <a href="' . site_url('gudang/slug/5/4/6/a?id=' . $idlastt . '&tbl=6') . '"><strong>' . $idlastt . '</strong></a>');
                            $this->mweb->settable('notif', $msginv);
                        }
                        break;
                    case '7':
                        if (!is_admin()) {
                            $msginv = array('from' => $idu, 'iduser' => getid_own(), 'aksi' => 'quotation', 'time' => date('d-m-Y h:i:s'), 'msg' => 'quotation kode <a href="' . site_url('gudang/slug/5/4/7/a?id=' . $idlastt . '&tbl=7') . '"><strong>' . $idlastt . '</strong></a>');
                            $this->mweb->settable('notif', $msginv);
                        }
                        break;
                    case '16':
                        $purc = $this->mweb->gettable_byid($fkolm, $idlastt, $tabel);
                        if (count($purc) > 0) {
                            foreach ($purc as $vpurc) {
                                $lb = rtrim($vpurc['linkbeli']);
                                $hb = rtrim($vpurc['hrg_beli']);
                            }
                            if (empty($lb) && empty($hb) || $hb === '0') {
                                $this->db->where('id', $idlastt);
                                $this->db->update('purchase', array('status' => 'p'));
                            } else {
                                if (strlen($lb) > 0 && empty($hb) || $hb === '0') {
                                    $this->db->where('id', $idlastt);
                                    $this->db->update('purchase', array('status' => 'w'));
                                } else {
                                    $this->db->where('id', $idlastt);
                                    $this->db->update('purchase', array('status' => 'wp'));
                                }
                            }
                        } else {
                            redirect('gudang?ep=' . $idlastt, 'refresh');
                        }
                        break;
                }
                redirect('gudang', 'refresh');
            } else {
                redirect('gudang?e=i', 'refresh');
            }
        } else {
            //If no session, redirect to login page
            redirect('login', 'refresh');
        }
    }
Example #2
0
        }
        ?>
   </td>
      <td><a href="<?php 
        echo current_url() . '/a?id=' . $valreq['idreq'] . '&tbl=16';
        ?>
"><?php 
        echo $valreq['idreq'];
        ?>
</a></td>
    <td><?php 
        echo $valreq['time'];
        ?>
</td>
    <td><?php 
        echo empty($valreq['kdbarang']) || is_null($valreq['kdbarang']) || strlen($valreq['kdbarang']) === 0 ? 0 : gethrgbrg($valreq['kdbarang']);
        ?>
</td>
    <td><?php 
        echo $valreq['namaprod'];
        ?>
</td>
    <td><?php 
        echo $valreq['Model'];
        ?>
</td>
    <td><?php 
        echo $valreq['desc'];
        ?>
</td>
    <td><a href="<?php