Advertisement
Guest User

adminwebsite

a guest
May 8th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 53.85 KB | None | 0 0
  1. <?php
  2.  
  3. function sqlinjection($data) {
  4.     $filter_sql = mysql_real_escape_string(stripslashes(strip_tags(html_sqlspecialchars($data, ENT_QUOTES))));
  5.     return $filter_sql;
  6. }
  7.  
  8. //
  9.  
  10. if (isset($_POST['submit'])) {
  11.     // bagian ini telah dirubah 5213100034 & 5213100166 dan 5213100177 & 5213100193 menambahkan code ENT_QUOTES
  12.  
  13.     $username = htmlspecialchars(mysql_real_escape_string($_POST['username']), ENT_QUOTES); //changed
  14.  
  15.     $password = htmlspecialchars(mysql_real_escape_string(md5($_POST['password'])), ENT_QUOTES); //changed
  16.     //$pwd=mysql_real_escape_string($_POST['passwd']);
  17.     $sql1 = "SELECT * FROM userapp WHERE name='$username' and password='$password'";
  18.     $result1 = mysql_query($sql1);
  19.     $count1 = mysql_num_rows($result1);
  20.     session_start();
  21.     if ($count1 > 0) {
  22.         setcookie(User, $username);
  23.         header("location: index.php");
  24.     }
  25. }
  26.  
  27. if (!defined('BASEPATH'))
  28.     exit('No direct script access allowed');
  29.  
  30. class Adminwebsite extends CI_Controller {
  31.     /*
  32.       Aplikasi Koperasi Pegawai Negeri Institut Teknologi Sepuluh Nopember (ITS)
  33.       Oleh Rizki Rinaldi
  34.       file : adminwebsite.php untuk aplikasi content management system Koperasi
  35.      */
  36.  
  37.     function __construct() {    // checked by Hatma @ 18 okt
  38.         parent::__construct();
  39.         if (!isset($_SESSION)) {
  40.             session_start();
  41.         }
  42.         $this->load->library(array('pagination', 'session', 'template', 'Excel_reader', 'form_validation'));
  43.         $this->load->model('m_koperasi');
  44.         $this->load->helper(array('form', 'url', 'inflector'));
  45.     }
  46.  
  47.     function index() {  // checked by Hatma @ 18 okt
  48.         $this->cek_session();
  49.         $data = array(
  50.             'total_post' => $this->m_koperasi->GetContent()->num_rows(),
  51.             'total_comment' => $this->m_koperasi->GetComment()->num_rows(),
  52.             'page_view' => $this->m_koperasi->GetContentView()->result_array(),
  53.             'post' => $this->m_koperasi->GetContent("where status = 'publish' order by counter desc")->result_array(),
  54.             'comment' => $this->m_koperasi->GetComment("where komentar.status = 'pending' order by komentar.kode_comment")->result_array(),
  55.             'session' => $this->session->userdata('login'),
  56.             'title' => 'Dasboard admin KUD Sumber Alam'
  57.         );
  58.         $this->template->display('adminwebsite/home', $data);
  59.     }
  60.  
  61.     function login($mess = 1) { // checked by Hatma 17 okt
  62.         $this->load->view('adminwebsite/login', array('message' => $mess, 'title' => 'Login dasboard admin KUD Sumber Alam'));
  63.     }
  64.  
  65.     function proseslogin() {    // checked by Hatma @ 18 okt
  66.         if ($_POST) {
  67.  
  68.             if ($_POST['username'] == "" | $_POST['password'] == "" | $_POST['captcha'] == "" | $_POST["captcha"] != isset($_SESSION["capt"]) | isset($_SESSION["capt"]) == '') {
  69.                 echo "<SCRIPT LANGUAGE='JavaScript'>
  70.                         window.alert('Semua kolom wajib diisi! captcha harus sesuai!')
  71.                         window.location.href='" . base_url() . "index.php/admin';
  72.                         </SCRIPT>";
  73.             } else {
  74.                 $username = strip_tags($_POST['username']); //ini telah diubah oleh 5213100034 & 5213100166  dan 5213100177 & 5213100193 menambahkan code ENT_QUOTES
  75.                 //ini telah diubah oleh 5213100034 & 5213100166  dan 5213100177 & 5213100193 menambahkan code ENT_QUOTES
  76.                 //$password = htmlspecialchars($_POST['password'], ENT_QUOTES); //Prevent from SQL Injection & Ganti (encrypt) Password di tabel Userapp menjadi md5
  77.                 //$username = htmlspecialchars($username);
  78.                 $password = strip_tags($_POST['password']);
  79.                 //$capt = $_POST["captcha"] != $_SESSION["capt"] OR $_SESSION["capt"] == '';
  80.                 $temp = $this->m_koperasi->GetUser("where username = '$username' and password = md5('$password')")->result_array();
  81.                 if ($temp != NULL) {
  82.                     $data = array(
  83.                         'username' => $temp[0]['username'],
  84.                         'pengguna' => $temp[0]['nama_lengkap']//,
  85.                             //'password' => $temp[0]['password'],
  86.                             //'capt' => $temp[0]['capt']
  87.                     );
  88.                     $this->session->set_userdata('login', $data);
  89.                     redirect("adminwebsite");
  90.                 } else {
  91.                     echo "<SCRIPT LANGUAGE='JavaScript'>
  92.                 window.alert('No Anggota atau Password Anda Salah !!')
  93.                 window.location.href='" . base_url() . "index.php/adminwebsite';
  94.                 </SCRIPT>";
  95.                 }
  96.             }
  97.         } else {
  98.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  99.         }
  100.     }
  101.  
  102.     function newcontent() { // checked by Hatma 17 okt
  103.         $this->cek_session();
  104.         $data_sess = $this->session->userdata('login');
  105.         $data = array(
  106.             'session' => $this->session->userdata('login'),
  107.             'username' => $data_sess['pengguna'],
  108.             'kode_content' => '',
  109.             'judul_content' => '',
  110.             'header_post' => '',
  111.             'deskripsi' => '',
  112.             'status' => 'baru',
  113.             'tampilan_status' => '',
  114.             'status_content' => '',
  115.             'label' => $this->m_koperasi->GetLabel()->result_array(),
  116.             'label_post' => array(),
  117.             'tags' => '',
  118.             'isi' => '',
  119.             'title' => 'Dasboard admin KUD Sumber Alam - isi content'
  120.         );
  121.         $this->template->display('adminwebsite/editor_berita', $data);
  122.     }
  123.  
  124.     function editcontent($kode = 0) {// checked by hatma 25 okt
  125.         $this->cek_session();
  126.         $data_sess = $this->session->userdata('login');
  127.         $data_content = $this->m_koperasi->GetContent("where kode_content = '$kode'")->result_array();
  128.         /* label to array */
  129.         $label_post_arr = array();
  130.         foreach ($this->m_koperasi->GetLabelContent("where kode_content = '$kode'")->result_array() as $lab) {
  131.             $label_post_arr[] = $lab['kode_label'];
  132.         }
  133.         /* end label to array */
  134.         $data = array(
  135.             'session' => $this->session->userdata('login'),
  136.             'username' => $data_sess['pengguna'],
  137.             'kode_content' => $data_content[0]['kode_content'],
  138.             'judul_content' => $data_content[0]['judul_content'],
  139.             'header_post' => $data_content[0]['image_header'],
  140.             'deskripsi' => $data_content[0]['deskripsi'],
  141.             'status_content' => $data_content[0]['status'],
  142.             'status' => 'lama',
  143.             'tampilan_status' => $data_content[0]['tampilan_status'],
  144.             'label' => $this->m_koperasi->GetLabel()->result_array(),
  145.             'label_post' => $label_post_arr,
  146.             'tags' => $data_content[0]['tags'],
  147.             'isi' => $data_content[0]['content'],
  148.             'title' => 'Dasboard admin KUD Sumber Alam - edit content'
  149.         );
  150.         $this->template->display('adminwebsite/editor_berita', $data);
  151.     }
  152.  
  153.     function session_preview() {// checked by Hatma 17 okt
  154.         $this->cek_session();
  155.         if ($_POST) {
  156.             $data_sess = $this->session->userdata('login');
  157.             $data = array(
  158.                 'username' => $data_sess['username'],
  159.                 'judul_content' => $_POST['judul_post'],
  160.                 'header_post' => $_POST['header_post'],
  161.                 'penulis' => $data_sess['pengguna'],
  162.                 'tanggal' => date("Y-m-d H:i:s"),
  163.                 'tags' => $_POST['tags'],
  164.                 'isi' => $_POST['isi'],
  165.                 'title' => 'Dasboard admin KUD Sumber Alam'
  166.             );
  167.             /* can't use CI session for save any values :-( */
  168.             /* $this->session->set_userdata('pratinjau',$data);
  169.               print_r($this->session->userdata('pratinjau')); */
  170.             /* session php */
  171.             if (!isset($_SESSION)) {
  172.                 session_start();
  173.             }
  174.             $_SESSION['pratinjau'] = $data;
  175.         } else {
  176.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  177.         }
  178.     }
  179.  
  180.     function pratinjau() {
  181.         $this->cek_session();
  182.         /* preview post */
  183.         /* can't use CI session for save any values :-( */
  184.         /* $sess_pratinjau = $this->session->userdata('pratinjau'); */
  185.         /* session php */
  186.         if (!isset($_SESSION)) {
  187.             session_start();
  188.         }
  189.         $sess_pratinjau = $_SESSION['pratinjau'];
  190.         $data_sess = $this->session->userdata('login');
  191.         $data = array(
  192.             'username' => $data_sess['username'],
  193.             'judul_content' => isset($_POST['judul_post']) ? $_POST['judul_post'] : $sess_pratinjau['judul_content'],
  194.             'header_post' => isset($_POST['header_post']) ? $_POST['header_post'] : $sess_pratinjau['header_post'],
  195.             'penulis' => $data_sess['pengguna'],
  196.             'tanggal' => date("Y-m-d H:i:s"),
  197.             'tags' => isset($_POST['tags']) ? $_POST['tags'] : $sess_pratinjau['tags'],
  198.             'isi' => isset($_POST['isi']) ? $_POST['isi'] : $sess_pratinjau['isi'],
  199.         );
  200.  
  201.         $this->session->set_userdata('pratinjau', $data);
  202.         /* end */
  203.         $sess_pratinjau = $this->session->userdata('pratinjau');
  204.         $data_setting = $this->m_koperasi->GetSetting()->result_array();
  205.         $data = array(
  206.             'recent_post' => $this->m_koperasi->GetContent("where status = 'publish' order by rand() limit 5")->result_array(),
  207.             'content' => $sess_pratinjau,
  208.             'penulis' => $sess_pratinjau["penulis"],
  209.             'deskripsi' => $data_setting[0]['deskripsi_blog'],
  210.             'author' => 'Ahmad Rizal Afani (KUD Sumber Alam)',
  211.             'title' => $data_setting[0]['judul_blog'] . ' - ' . $sess_pratinjau['judul_content'],
  212.             'komentar' => '',
  213.             'fb_fans_page' => $data_setting[0]['facebook_fans_page'],
  214.             'twitter' => $data_setting[0]['twitter'],
  215.             'penulis' => $this->m_koperasi->GetUser("where username = '" . $sess_pratinjau['username'] . "'")->result_array(),
  216.         );
  217.         $this->template->display('adminwebsite/preview', $data);
  218.     }
  219.  
  220.     function savecontent() {    // checked by Hatma @ 18 okt
  221.         $this->cek_session();
  222.         $data_sess = $this->session->userdata('login');
  223.         $this->load->library('upload');
  224.         $nmfile = "file_" . time(); //nama file saya beri nama langsung dan diikuti fungsi time
  225.         $config['upload_path'] = './asset/files/header_content/'; //path folder
  226.         $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp'; //type yang dapat diakses bisa anda sesuaikan
  227.         $config['max_size'] = '2048'; //maksimum besar file 2M
  228.         $config['max_width'] = '1288'; //lebar maksimum 1288 px
  229.         $config['max_height'] = '768'; //tinggi maksimu 768 px
  230.         $config['file_name'] = $nmfile; //nama yang terupload nantinya
  231.         $this->load->library('upload', $config);
  232.         $file = $this->upload->initialize($config);
  233.         //chmod($file, 0777);
  234.         if ($_FILES['filefoto']['name']) {
  235.             if ($this->upload->do_upload('filefoto')) {
  236.                 $gbr = $this->upload->data();
  237.                 //chmod($gbr, 0777);
  238.                 $status_simpan = array('status_simpan' => $this->input->post('status_simpan'),
  239.                     'labels' => $this->input->post('labels'));
  240.                 $data = array(
  241.                     'judul_content' => $this->input->post('judul_post'),
  242.                     'image_header' => $gbr['file_name'],
  243.                     'image_detail' => $gbr['file_type'],
  244.                     'deskripsi' => $this->input->post('deskripsi'),
  245.                     'tanggal' => date("Y-m-d H:i:s"),
  246.                     'penulis' => $data_sess['pengguna'],
  247.                     'content' => $this->input->post('isi'),
  248.                     'tags' => $this->input->post('tags'),
  249.                     //'status' => $this->input->post('status'),
  250.                     //'tampilan_status' => $this->input->post('tampilan_status'),
  251.                     'status' => "publish",
  252.                     'tampilan_status' => "utama",
  253.                     'counter' => 0
  254.                 );
  255.                 if ($status_simpan['status_simpan'] == "baru") {
  256.                     $result = $this->m_koperasi->InsertData('content', $data);
  257.                     if ($result == 1) {
  258.                         $terakhir = $this->m_koperasi->GetContent('order by kode_content desc limit 1')->result_array();
  259.                         /*foreach ($status_simpan['labels'] as $l) {
  260.                             $data = array(
  261.                                 'kode_content' => $terakhir[0]['kode_content'],
  262.                                 'kode_label' => $l
  263.                             );
  264.                             $this->m_koperasi->InsertData('content_label', $data);
  265.                         }*/
  266.                         header('location:' . base_url() . 'index.php/adminwebsite/content/2');
  267.                     } else {
  268.                         header('location:' . base_url() . 'index.php/adminwebsite/content/0');
  269.                     }
  270.                 } else {
  271.                     //$this->m_koperasi->DeleteData('content_label', array('kode_content' => $kode_content));
  272.                     $data = array(
  273.                         'judul_content' => $this->input->post('judul_post'),
  274.                         'image_header' => $gbr['file_name'],
  275.                         'image_detail' => $gbr['file_type'],
  276.                         'deskripsi' => $this->input->post('deskripsi'),
  277.                         'tanggal' => date("Y-m-d H:i:s"),
  278.                         'penulis' => $data_sess['pengguna'],
  279.                         'content' => $this->input->post('isi'),
  280.                         'tags' => $this->input->post('tags'),
  281.                         //'status' => $this->input->post('status'),
  282.                         //'tampilan_status' => $this->input->post('tampilan_status'),
  283.                         'status' => "publish",
  284.                         'tampilan_status' => "utama"
  285.                     );
  286.                     $kode_content = $this->input->post('kode_content') ;
  287.                     $result = $this->m_koperasi->UpdateData('content', $data, array('kode_content' => $kode_content));
  288.                     if ($result == 1) {
  289.                         /*foreach ($labels as $l) {
  290.                             $data = array(
  291.                                 'kode_content' => $kode_content,
  292.                                 'kode_label' => $l
  293.                             );
  294.                             $this->m_koperasi->InsertData('content_label', $data);
  295.                         }*/
  296.                         header('location:' . base_url() . 'index.php/adminwebsite/content/3');
  297.                     } else {
  298.                         header('location:' . base_url() . 'index.php/adminwebsite/content/0');
  299.                     }
  300.                 }
  301.             } else {
  302.                 echo "<SCRIPT LANGUAGE='JavaScript'>
  303.                    window.alert('Upload Gambar Gagal!')
  304.                    window.location.href='" . base_url() . "index.php/admin';
  305.                    </SCRIPT>";
  306.             }
  307.         } else {
  308.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  309.         }
  310.     }
  311.  
  312.     function deletecontent($kode = 0) { // checked by hatma 25 okt
  313.         $this->cek_session();
  314.         $this->m_koperasi->DeleteData('content_label', array('kode_content' => $kode));
  315.         $result = $this->m_koperasi->DeleteData('content', array('kode_content' => $kode));
  316.         if ($result == 1) {
  317.             header('location:' . base_url() . 'index.php/adminwebsite/content/1');
  318.         } else {
  319.             header('location:' . base_url() . 'index.php/adminwebsite/content/0');
  320.         }
  321.     }
  322.  
  323.     function content($mess = -1) {  // checked by hatma 25 okt
  324.         $this->cek_session();
  325.         $data = array(
  326.             'session' => $this->session->userdata('login'),
  327.             'content' => $this->m_koperasi->GetContent('order by kode_content desc')->result_array(),
  328.             'message' => $mess,
  329.             'title' => 'Dasboard admin KUD Sumber Alam - semua content'
  330.         );
  331.         $this->template->display('adminwebsite/berita', $data);
  332.     }
  333.  
  334.     function contentpublish($mess = -1) {
  335.         $this->cek_session();
  336.         $data = array(
  337.             'session' => $this->session->userdata('login'),
  338.             'content' => $this->m_koperasi->GetContent('where status = "publish" order by kode_content desc')->result_array(),
  339.             'message' => $mess,
  340.             'title' => 'Dasboard admin KUD Sumber Alam - semua content diterbitkan'
  341.         );
  342.         $this->template->display('adminwebsite/berita', $data);
  343.     }
  344.  
  345.     function contentdraft($mess = -1) {
  346.         $this->cek_session();
  347.         $data = array(
  348.             'session' => $this->session->userdata('login'),
  349.             'content' => $this->m_koperasi->GetContent('where status = "draft" order by kode_content desc')->result_array(),
  350.             'message' => $mess,
  351.             'title' => 'Dasboard admin KUD Sumber Alam - semua content draft'
  352.         );
  353.         $this->template->display('adminwebsite/berita', $data);
  354.     }
  355.  
  356.     function labels($mess = -1) {
  357.         $this->cek_session();
  358.         $data = array(
  359.             'session' => $this->session->userdata('login'),
  360.             'status' => 'baru',
  361.             'judul_label' => '',
  362.             'kode_label' => '',
  363.             'message' => $mess,
  364.             'label' => $this->m_koperasi->GetLabel("order by kode_label desc")->result_array(),
  365.             'title' => 'Dasboard admin KUD Sumber Alam - semua label'
  366.         );
  367.         $this->template->display('adminwebsite/label_berita', $data);
  368.     }
  369.  
  370.     function editlabel($kode = 0) {
  371.         $this->cek_session();
  372.         $temp = $this->m_koperasi->GetLabel("where kode_label = '$kode'")->result_array();
  373.         $data = array(
  374.             'session' => $this->session->userdata('login'),
  375.             'status' => 'lama',
  376.             'judul_label' => $temp[0]['judul_label'],
  377.             'kode_label' => $temp[0]['kode_label'],
  378.             'message' => "",
  379.             'label' => $this->m_koperasi->GetLabel("where kode_label != '$kode' order by kode_label desc")->result_array(),
  380.             'title' => 'Dasboard admin KUD Sumber Alam - edit label'
  381.         );
  382.         $this->template->display('adminwebsite/label_berita', $data);
  383.     }
  384.  
  385.     function savelabel() {
  386.         $this->cek_session();
  387.         if ($_POST) {
  388.             $status = $_POST['status'];
  389.             $kode_label = $_POST['kode_label'];
  390.             $judul_label = $_POST['judul_label'];
  391.             if ($status == "baru") {
  392.                 $data = array(
  393.                     'kode_label' => $kode_label,
  394.                     'judul_label' => $judul_label
  395.                 );
  396.                 $result = $this->m_koperasi->InsertData('label', $data);
  397.                 if ($result == 1) {
  398.                     header('location:' . base_url() . 'index.php/adminwebsite/labels/2');
  399.                 } else {
  400.                     header('location:' . base_url() . 'index.php/adminwebsite/labels/0');
  401.                 }
  402.             } else {
  403.                 $data = array(
  404.                     'judul_label' => $judul_label
  405.                 );
  406.                 $result = $this->m_koperasi->UpdateData('label', $data, array('kode_label' => $kode_label));
  407.                 if ($result == 1) {
  408.                     header('location:' . base_url() . 'index.php/adminwebsite/labels/3');
  409.                 } else {
  410.                     header('location:' . base_url() . 'index.php/adminwebsite/labels/0');
  411.                 }
  412.             }
  413.         } else {
  414.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  415.         }
  416.     }
  417.  
  418.     function deletelabel($kode = 1) {
  419.         $this->cek_session();
  420.         $result = $this->m_koperasi->DeleteData('label', array('kode_label' => $kode));
  421.         if ($result == 1) {
  422.             header('location:' . base_url() . 'index.php/adminwebsite/labels/1');
  423.         } else {
  424.             header('location:' . base_url() . 'index.php/adminwebsite/labels/0');
  425.         }
  426.     }
  427.  
  428.     function users($mess = -1) {
  429.         $this->cek_session();
  430.         $data = array(
  431.             'session' => $this->session->userdata('login'),
  432.             'message' => $mess,
  433.             'user' => $this->m_koperasi->GetUser()->result_array(),
  434.             'title' => 'Dasboard admin KUD Sumber Alam - semua user'
  435.         );
  436.         $this->template->display('adminwebsite/admin', $data);
  437.     }
  438.  
  439.     function updateusers() {
  440.         $this->cek_session();
  441.         $data_sess = $this->session->userdata('login');
  442.         $data = array(
  443.             'session' => $this->session->userdata('login'),
  444.             'username' => $data_sess['pengguna'],
  445.             'judul_content' => '',
  446.             'header_post' => '',
  447.             'status' => '',
  448.             'label' => $this->m_koperasi->GetLabel()->result_array(),
  449.             'label_post' => array(),
  450.             'title' => 'Dasboard admin KUD Sumber Alam - isi content'
  451.         );
  452.         $this->template->display('adminwebsite/input_user', $data);
  453.     }
  454.  
  455.     function saveuser() {
  456.         $this->cek_session();
  457.         if ($_POST) {
  458.             //ini telah diubah oleh 5213100034 & 5213100166
  459.             $username = mysql_real_escape_string($_POST['username']);
  460.  
  461.             $pengguna = $_POST['pengguna'];
  462.  
  463.             $password = mysql_real_escape_string(md5, $_POST['password']); //ini telah diubah oleh 5213100034 & 5213100166
  464.  
  465.             $facebook = $_POST['facebook'];
  466.             $twitter = $_POST['twitter'];
  467.             $g_plus = $_POST['g_plus'];
  468.  
  469.             $temp = $this->m_koperasi->GetUser("where username = '$username'")->result_array();
  470.             if ($temp == NULL) {
  471.                 $data = array(
  472.                     'username' => $username,
  473.                     'nama_lengkap' => $pengguna,
  474.                     'password' => $password,
  475.                     'facebook' => $facebook,
  476.                     'twitter' => $twitter,
  477.                     'g_plus' => $g_plus
  478.                 );
  479.                 $result = $this->m_koperasi->InsertData('userapp', $data);
  480.                 if ($result == 1) {
  481.                     header('location:' . base_url() . 'index.php/adminwebsite/users/1');
  482.                 } else {
  483.                     header('location:' . base_url() . 'index.php/adminwebsite/users/0');
  484.                 }
  485.             } else {
  486.                 header('location:' . base_url() . 'index.php/adminwebsite/users/3');
  487.             }
  488.         } else {
  489.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  490.         }
  491.     }
  492.  
  493.     function edituser($kodeuser) {
  494.         $this->cek_session();
  495.         $mess = -1;
  496.         $data = array(
  497.             'session' => $this->session->userdata('login'),
  498.             'message' => $mess,
  499.             'datauser' => $this->m_koperasi->GetUser("where kode_user = '$kodeuser'")->result_array(),
  500.             'user' => $this->m_koperasi->GetUser("where kode_user = '$kodeuser'")->result_array(),
  501.             'title' => 'Dasboard admin KUD Sumber Alam - semua user'
  502.         );
  503.  
  504.         $this->template->display('adminwebsite/admin', $data);
  505.     }
  506.  
  507.     function deleteuser($kode = 0) {
  508.         $this->cek_session();
  509.         $result = $this->m_koperasi->DeleteData('userapp', array('kode_user' => $kode));
  510.         if ($result == 1) {
  511.             header('location:' . base_url() . 'index.php/adminwebsite/users/2');
  512.         } else {
  513.             header('location:' . base_url() . 'index.php/adminwebsite/users/0');
  514.         }
  515.     }
  516.  
  517.     function statistikpost() {
  518.         $this->cek_session();
  519.         $data = array(
  520.             'post' => $this->m_koperasi->GetContent("where status = 'publish' order by counter")->result_array(),
  521.             'session' => $this->session->userdata('login'),
  522.             'title' => 'Dasboard admin KUD Sumber Alam - statistik'
  523.         );
  524.         $this->template->display('adminwebsite/statistik_post', $data);
  525.     }
  526.  
  527.     function statistikvisitor() {
  528.         $this->cek_session();
  529.         //page view hari ini, kemarin, bulan ini dan sepanjang waktu
  530.         //visitor OS, browser, lokasi
  531.         $tanggal_wingi = date("d");
  532.         $view_stat = array(
  533.             'day' => $this->m_koperasi->GetVisitor("where SUBSTRING(tanggal,1,10) = '" . date("Y-m-d") . "'")->num_rows(),
  534.             'yesterday' => $this->m_koperasi->GetVisitor("where SUBSTRING(tanggal,1,10) = '" . date("Y-m-d", strtotime("yesterday")) . "'")->num_rows(),
  535.             'mounth' => $this->m_koperasi->GetVisitor("where SUBSTRING(tanggal,1,7) = '" . date("Y-m") . "'")->num_rows(),
  536.             'year' => $this->m_koperasi->GetVisitor("where SUBSTRING(tanggal,1,4) = '" . date("Y") . "'")->num_rows(),
  537.             'sepanjang_waktu' => $this->m_koperasi->GetVisitor()->num_rows(),
  538.         );
  539.         $data = array(
  540.             'session' => $this->session->userdata('login'),
  541.             'post' => $this->m_koperasi->GetContent("where status = 'publish' order by counter desc limit 5")->result_array(),
  542.             'visitor' => $view_stat,
  543.             'title' => 'Dasboard admin KUD Sumber Alam - statistik'
  544.         );
  545.         $this->template->display('adminwebsite/statistik_visitor', $data);
  546.     }
  547.  
  548.     function listcomment($mess = -1) {
  549.         $this->cek_session();
  550.         $data = array(
  551.             'message' => $mess,
  552.             'session' => $this->session->userdata('login'),
  553.             'comment' => $this->m_koperasi->GetComment("order by kode_comment desc")->result_array(),
  554.             'title' => 'Dasboard admin KUD Sumber Alam - komentar'
  555.         );
  556.         $this->template->display('adminwebsite/comment', $data);
  557.     }
  558.  
  559.     function publishingcomment($kode = 0) {
  560.         $this->cek_session();
  561.         $data = array('status' => 'publish');
  562.         $result = $this->m_koperasi->UpdateData('komentar', $data, array('kode_comment' => $kode));
  563.         if ($result == 1) {
  564.             header('location:' . base_url() . 'index.php/adminwebsite/listcomment/1');
  565.         } else {
  566.             header('location:' . base_url() . 'index.php/adminwebsite/listcomment/0');
  567.         }
  568.     }
  569.  
  570.     function deletingcomment($kode = 0) {
  571.         $this->cek_session();
  572.         $result = $this->m_koperasi->DeleteData('komentar', array('kode_comment' => $kode));
  573.         if ($result == 1) {
  574.             header('location:' . base_url() . 'index.php/adminwebsite/listcomment/3');
  575.         } else {
  576.             header('location:' . base_url() . 'index.php/adminwebsite/listcomment/0');
  577.         }
  578.     }
  579.  
  580.     function replycomment($kode = 0) {
  581.         $this->cek_session();
  582.         $data = array(
  583.             'comment' => $this->m_koperasi->GetComment("where content.kode_content = '$kode' order by kode_comment")->result_array(),
  584.             'session' => $this->session->userdata('login'),
  585.             'title' => 'Dasboard admin KUD Sumber Alam - balas komentar'
  586.         );
  587.         $this->template->display('adminwebsite/commentreply', $data);
  588.     }
  589.  
  590.     function myreply() {
  591.         $this->cek_session();
  592.         if ($_POST) {
  593.             $data_sess = $this->session->userdata('login');
  594.             $data = array(
  595.                 'kode_content' => $_POST['kode_content'],
  596.                 'isi' => $_POST['mycomment'],
  597.                 'status' => 'publish',
  598.                 'pengirim' => $data_sess['pengguna'],
  599.                 'website' => 'KUD Sumber Alam',
  600.                 'tanggal' => date("Y-m-d H:i:s")
  601.             );
  602.             $result = $this->m_koperasi->InsertData('komentar', $data);
  603.             if ($result == 1) {
  604.                 header('location:' . base_url() . 'index.php/adminwebsite/listcomment/2');
  605.             } else {
  606.                 header('location:' . base_url() . 'index.php/adminwebsite/listcomment/0');
  607.             }
  608.         } else {
  609.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  610.         }
  611.     }
  612.  
  613.     function settingdasar($mess = -1) {
  614.         $this->cek_session();
  615.         $data = array(
  616.             'session' => $this->session->userdata('login'),
  617.             'message' => $mess,
  618.             'setting' => $this->m_koperasi->GetSetting()->result_array(),
  619.             'title' => 'Dasboard admin KUD Sumber Alam - setting dasar'
  620.         );
  621.         $this->template->display('adminwebsite/setting_dasar', $data);
  622.     }
  623.  
  624.     function savesettingdasar() {
  625.         $this->cek_session();
  626.         if ($_POST) {
  627.             $site_title = $_POST['site_title'];
  628.             $deskripsi = $_POST['deskripsi'];
  629.             $limit_content = $_POST['limit_content'];
  630.             $fb = $_POST['fb'];
  631.             $fb_fans = $_POST['fb_fans'];
  632.             $twitter = $_POST['twitter'];
  633.             $g_plus = $_POST['g_plus'];
  634.             $email = $_POST['email'];
  635.  
  636.             $data = array(
  637.                 'judul_blog' => $site_title,
  638.                 'deskripsi_blog' => $deskripsi,
  639.                 'limit_content' => $limit_content,
  640.                 'facebook' => $fb,
  641.                 'facebook_fans_page' => $fb_fans,
  642.                 'twitter' => $twitter,
  643.                 'g_plus' => $g_plus,
  644.                 'email' => $email
  645.             );
  646.             $result = $this->m_koperasi->UpdateData('setting', $data, array('kode_blog' => '1'));
  647.             if ($result == 1) {
  648.                 header('location:' . base_url() . 'index.php/adminwebsite/settingdasar/1');
  649.             } else {
  650.                 header('location:' . base_url() . 'index.php/adminwebsite/settingdasar/0');
  651.             }
  652.         } else {
  653.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  654.         }
  655.     }
  656.  
  657.     function saveinformation() {
  658.         $this->cek_session();
  659.         if ($_POST) {
  660.             $data = array(
  661.                 'information' => $_POST['information']
  662.             );
  663.             $result = $this->m_koperasi->UpdateData('setting', $data, array('kode_blog' => '1'));
  664.             if ($result == 1) {
  665.                 header('location:' . base_url() . 'index.php/adminwebsite/settingdasar/1');
  666.             } else {
  667.                 header('location:' . base_url() . 'index.php/adminwebsite/settingdasar/0');
  668.             }
  669.         } else {
  670.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  671.         }
  672.     }
  673.  
  674.     function settingprofile($mess = -1) {
  675.         $this->cek_session();
  676.         $data_sess = $this->session->userdata('login');
  677.         $data_user = $this->m_koperasi->GetUser("where username = '" . $data_sess['username'] . "'")->result_array();
  678.         $data = array(
  679.             'session' => $this->session->userdata('login'),
  680.             'kode_user' => $data_user[0]['kode_user'],
  681.             'username' => $data_user[0]['username'],
  682.             'nama_lengkap' => $data_user[0]['nama_lengkap'],
  683.             'fb' => $data_user[0]['facebook'],
  684.             'twitter' => $data_user[0]['twitter'],
  685.             'g_plus' => $data_user[0]['g_plus'],
  686.             'about' => $data_user[0]['about'],
  687.             'message' => $mess,
  688.             'title' => 'Dasboard admin KUD Sumber Alam - setting profile'
  689.         );
  690.         $this->template->display('adminwebsite/setting_profile', $data);
  691.     }
  692.  
  693.     function saveprofile() {
  694.         $this->cek_session();
  695.         if ($_POST) {
  696.             $data_sess = $this->session->userdata('login');
  697.  
  698.             $kode_user = $_POST['kode_user'];
  699.  
  700.             $username = mysql_real_escape_string($_POST['username']); //ini telah diubah oleh 5213100034 & 5213100166
  701.             $nama_lengkap = $_POST['nama_lengkap'];
  702.             $facebook = $_POST['facebook'];
  703.             $g_plus = $_POST['g_plus'];
  704.             $twitter = $_POST['twitter'];
  705.             $about = $_POST['about'];
  706.  
  707.             $password = mysql_real_escape_string(md5, $_POST['password']); //ini telah diubah oleh 5213100034 & 5213100166
  708.  
  709.             if ($password == $data_sess['password']) {
  710.                 $data = array(
  711.                     'username' => $username,
  712.                     'nama_lengkap' => $nama_lengkap,
  713.                     'facebook' => $facebook,
  714.                     'twitter' => $twitter,
  715.                     'g_plus' => $g_plus,
  716.                     'about' => $about
  717.                 );
  718.                 $result = $this->m_koperasi->UpdateData('userapp', $data, array('kode_user' => $kode_user));
  719.                 if ($result == 1) {
  720.                     $new_data_sess = array(
  721.                         'username' => $data_sess['username'],
  722.                         'pengguna' => $nama_lengkap,
  723.                         'password' => $data_sess['password']
  724.                     );
  725.                     $this->session->set_userdata('login', $new_data_sess);
  726.                     header('location:' . base_url() . 'index.php/adminwebsite/settingprofile/1');
  727.                 } else {
  728.                     header('location:' . base_url() . 'index.php/adminwebsite/settingprofile/0');
  729.                 }
  730.             } else {
  731.                 header('location:' . base_url() . 'index.php/adminwebsite/settingprofile/0');
  732.             }
  733.         } else {
  734.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  735.         }
  736.     }
  737.  
  738.     function settingpassword($mess = -1) {
  739.         $this->cek_session();
  740.         $data_sess = $this->session->userdata('login');
  741.         $data = array(
  742.             'session' => $this->session->userdata('login'),
  743.             @'username' => $data_sess['username'],
  744.             'message' => $mess,
  745.             'title' => 'Dasboard admin KUD Sumber Alam - setting password'
  746.         );
  747.         $this->template->display('adminwebsite/setting_password', $data);
  748.     }
  749.  
  750.     function savepassword() {   // checked by hatma 25 okt 2015
  751.         $this->cek_session();
  752.             if ($_POST) {
  753.  
  754.                 if ($_POST['password_lama'] == "" | $_POST['password_baru'] == "" | $_POST['username'] == "" ) {
  755.                     echo "<SCRIPT LANGUAGE='JavaScript'>
  756.                         window.alert('Semua kolom wajib diisi! ')
  757.                         window.location.href='" . base_url() . "index.php/adminwebsite/settingpassword';
  758.                         </SCRIPT>";
  759.                 } else {
  760.  
  761.                     $password_lama = $_POST['password_lama'] ; //. $this->config->item("key_login");
  762.                     $password_baru = $_POST['password_baru'] ; //. $this->config->item("key_login");
  763.                     $id = $_POST['username'];
  764.                     $temp = $this->m_koperasi->GetAdmin("where username = '$id' and password = md5('$password_lama')")->result_array();
  765.                     if ($temp != NULL) {
  766.                         $result = $this->m_koperasi->UbahPassAdmin($id, $password_baru);
  767.                         if ($result == 1) {
  768.                             echo "<SCRIPT LANGUAGE='JavaScript'>
  769.                                                    window.alert('Password Berhasil Di Update !!')
  770.                                                    window.location.href='" . base_url() . "index.php/admin';
  771.                                                    </SCRIPT>";
  772.                         } else
  773.                             echo "<SCRIPT LANGUAGE='JavaScript'>
  774.                                                    window.alert('Password gagal Di Update !!')
  775.                                                    window.location.href='" . base_url() . "index.php/admin';
  776.                                                    </SCRIPT>";
  777.                     } else {
  778.                         echo "<SCRIPT LANGUAGE='JavaScript'>
  779.                                            window.alert('Password Tidak Di Update !! Password lama salah')
  780.                                            window.location.href='" . base_url() . "index.php/adminwebsite/settingpassword';
  781.                                            </SCRIPT>";
  782.                     }
  783.                 }
  784.             } else {
  785.                 redirect("adminwebsite");
  786.             }
  787.        
  788.         /*
  789.         if ($_POST) {
  790.             $data_sess = $this->session->userdata('login');
  791.             $username = $_POST['username'];
  792.             $password_lama = $_POST['password_lama'];
  793.             $password_baru = $_POST['password_baru'];
  794.  
  795.             if ($password_lama == $data_sess['password']) {
  796.                 $data = array('password' => $password_baru);
  797.                 $result = $this->m_koperasi->UpdateData('userapp', $data, array('username' => $username));
  798.                 if ($result == 1) {
  799.                     $new_data_sess = array(
  800.                         'username' => $data_sess['username'],
  801.                         'pengguna' => $data_sess['pengguna'],
  802.                         'password' => $password_baru
  803.                     );
  804.                     $this->session->set_userdata('login', $new_data_sess);
  805.                     header('location:' . base_url() . 'index.php/adminwebsite/settingpassword/1');
  806.                 } else {
  807.                     header('location:' . base_url() . 'index.php/adminwebsite/settingpassword/0');
  808.                 }
  809.             } else {
  810.                 header('location:' . base_url() . 'index.php/adminwebsite/settingpassword/0');
  811.             }
  812.         } else {
  813.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  814.         }
  815.         */
  816.     }
  817.  
  818.     function destroyingsession() {  //checked by hatma @ 18 okt
  819.         $this->session->sess_destroy();
  820.         if (!isset($_SESSION)) {
  821.             session_start();
  822.         }
  823.         //session_destroy();
  824.         header('location:' . base_url() . 'index.php/adminwebsite/login');
  825.     }
  826.  
  827.     function cek_session() {    // checked by Hatma @ 17 okt
  828.         if (!$this->session->userdata('login')) {
  829.             header('location:' . base_url() . 'index.php/adminwebsite/login');
  830.             exit(0);
  831.         }
  832.     }
  833.  
  834.     /* ------KOPERASI -------- */
  835.  
  836.     //INSERT
  837.     function insertuser() { //checked by hatma 19oct
  838.         $this->cek_session();
  839.         $data_sess = $this->session->userdata('login');
  840.         $data = array(
  841.             'session' => $this->session->userdata('login'),
  842.             'username' => $data_sess['pengguna'],
  843.             'id_userkoperasi' => '',
  844.             'nama' => '',
  845.             'nip' => '',
  846.             'no_anggota' => '',
  847.             'unit' => '',
  848.             'tgl_bergabung' => '',
  849.             'status' => 'baru',
  850.             'title' => 'Dasboard admin KUD Sumber Alam - Insert Anggota'
  851.         );
  852.         $this->template->display('adminwebsite/input_anggota1', $data);
  853.     }
  854.  
  855.     function saveanggota() {    // checked by hatma 19 oct
  856.         $this->cek_session();
  857.         if ($_POST) {
  858.             $data_sess = $this->session->userdata('login');
  859.             $nama = $_POST['nama'];
  860.             $nip = $_POST['nip'];
  861.             $no_anggota = $_POST['no_anggota'];
  862.             $no_anggota_lama = $_POST['no_anggota_lama'];
  863.             $password = ($_POST['password']);
  864.             $unit = $_POST['unit'];
  865.             $tgl_bergabung = $_POST['tgl_bergabung'];
  866.             $status_simpan = $_POST['status_simpan'];
  867.             $kode_anggota = $_POST['id_userkoperasi'];
  868.             if ($status_simpan == "baru") {
  869.                 $data = array(
  870.                     'nama' => $nama,
  871.                     'nip' => $nip,
  872.                     'no_anggota' => $no_anggota,
  873.                     //'password' => md5($password),
  874.                     'unit' => $unit,
  875.                     'tgl_bergabung' => $tgl_bergabung
  876.                 );
  877.                 $result = $this->m_koperasi->InsertData('anggota', $data);
  878.                
  879.                 $data2 = array(
  880.                     'no_anggota' => $no_anggota,
  881.                     'password' => md5($password)
  882.                 );
  883.                 $result2 = $this->m_koperasi->InsertData('anggotapassword', $data2);
  884.                
  885.                 if ($result = 1) {
  886.                     header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/2');
  887.                 } else {
  888.                     header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/0');
  889.                 }
  890.             } else {
  891.                 $data = array(
  892.                     'nama' => $nama,
  893.                     'nip' => $nip,
  894.                     'no_anggota' => $no_anggota,
  895.                     //'password' => md5($password),
  896.                     'unit' => $unit,
  897.                     'tgl_bergabung' => $tgl_bergabung
  898.                 );
  899.                 $result = $this->m_koperasi->UpdateData('anggota', $data, array('id_userkoperasi' => $kode_anggota));
  900.                
  901.                 $data2 = array(
  902.                     'no_anggota' => $no_anggota,
  903.                     'password' => md5($password)
  904.                 );
  905.                 $result2 = $this->m_koperasi->UpdateData('anggotapassword', $data2, array('no_anggota' => $no_anggota_lama));
  906.                
  907.                 if ($result == 1) {
  908.                     header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/3');
  909.                 } else {
  910.                     header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/0');
  911.                 }
  912.             }
  913.         } else {
  914.             $this->load->view('adminwebsite/pagenotfound', array('title' => 'page not found'));
  915.         }
  916.     }
  917.  
  918.     function editanggota($kode = 0) {   // checked by hatma 19okt
  919.         $this->cek_session();
  920.         $data_sess = $this->session->userdata('login');
  921.         $data_content = $this->m_koperasi->Getdataanggota("where id_userkoperasi = '$kode'")->result_array();
  922.         /* label to array */
  923.         $data = array(
  924.             'session' => $this->session->userdata('login'),
  925.             'username' => $data_sess['pengguna'],
  926.             'id_userkoperasi' => $data_content[0]['id_userkoperasi'],
  927.             'nama' => $data_content[0]['nama'],
  928.             'nip' => $data_content[0]['nip'],
  929.             'no_anggota' => $data_content[0]['no_anggota'],
  930.             'password' => $data_content[0]['password'],
  931.             'unit' => $data_content[0]['unit'],
  932.             'tgl_bergabung' => $data_content[0]['tgl_bergabung'],
  933.             'status' => 'lama',
  934.             'title' => 'Dasboard admin KUD Sumber Alam - edit content'
  935.         );
  936.         $this->template->display('adminwebsite/input_anggota1', $data);
  937.     }
  938.  
  939.     function tampilprofile($kode = 0) { //checked by hatma 19 okt
  940.         $this->cek_session();
  941.         $data_sess = $this->session->userdata('login');
  942.         $data_content = $this->m_koperasi->Getdataanggota("where id_userkoperasi = '$kode'")->result_array();
  943.         /* label to array */
  944.         $data = array(
  945.             'session' => $this->session->userdata('login'),
  946.             'username' => $data_sess['pengguna'],
  947.             'id_userkoperasi' => $data_content[0]['id_userkoperasi'],
  948.             'nama' => $data_content[0]['nama'],
  949.             'nip' => $data_content[0]['nip'],
  950.             'no_anggota' => $data_content[0]['no_anggota'],
  951.             'password' => $data_content[0]['password'],
  952.             'unit' => $data_content[0]['unit'],
  953.             'tgl_bergabung' => $data_content[0]['tgl_bergabung'],
  954.             'status' => 'lama',
  955.             'title' => 'Dasboard admin KUD Sumber Alam - edit content'
  956.         );
  957.         $this->template->display('adminwebsite/input_anggota1', $data);
  958.     }
  959.  
  960.     function deleteanggota($kode = 0) {
  961.         $this->cek_session();
  962.         $result = $this->m_koperasi->DeleteData('anggota', array('id_userkoperasi' => $kode));
  963.         $this->m_koperasi->hapus_password_userx($kode);
  964.         if ($result == 1) {
  965.             header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/1');
  966.         } else {
  967.             header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/0');
  968.         }
  969.     }
  970.  
  971.     //IMPORT
  972.     function insertusers() {   //checked by hatma 19okt
  973.         $this->cek_session();
  974.         $data_sess = $this->session->userdata('login');
  975.         $data = array(
  976.             'session' => $this->session->userdata('login'),
  977.             'username' => $data_sess['pengguna'],
  978.             'judul_content' => '',
  979.             'header_post' => '',
  980.             'status' => 'baru',
  981.             'label' => $this->m_koperasi->GetLabel()->result_array(),
  982.             'label_post' => array(),
  983.             'title' => 'Dasboard admin KUD Sumber Alam - Import Anggota'
  984.         );
  985.         $this->template->display('adminwebsite/input_anggota', $data);
  986.     }
  987.  
  988.     function do_upload() {  //checked by hatma 19 okt
  989.         $this->cek_session();
  990.         $config['upload_path'] = './asset/files/data_koperasi/';
  991.         $config['allowed_types'] = 'xls';
  992.         $this->load->library('upload', $config);
  993.         if (!$this->upload->do_upload()) {
  994.             $data = array('error' => $this->upload->display_errors());
  995.             $this->session->set_flashdata('msg_excel', 'Insert failed. Please check your file, only .xls file allowed.');
  996.         } else {
  997.  
  998.             $data = array('error' => false);
  999.             $upload_data = $this->upload->data();
  1000.  
  1001.             $this->load->library('excel_reader');
  1002.             $this->excel_reader->setOutputEncoding('CP1251');
  1003.  
  1004.             $file = $upload_data['full_path'];
  1005.             $this->excel_reader->read($file);
  1006.             error_reporting(E_ALL ^ E_NOTICE);
  1007.  
  1008.             // Sheet 1
  1009.             $data = $this->excel_reader->sheets[0];
  1010.             $dataexcel = Array();
  1011.  
  1012.             for ($i = 2; $i <= $data['numRows']; $i++) {
  1013.                 if ($data['cells'][$i][1] == '')
  1014.                     break;
  1015.                 $dataexcel[$i - 1]['nama'] = $data['cells'][$i][1];
  1016.                 $dataexcel[$i - 1]['nip'] = $data['cells'][$i][2];
  1017.                 $dataexcel[$i - 1]['no_anggota'] = $data['cells'][$i][3];
  1018.                 //$dataexcel[$i - 1]['password'] = $data['cells'][$i][4];
  1019.                 $dataexcel[$i - 1]['status_anggota'] = $data['cells'][$i][5];
  1020.                 $dataexcel[$i - 1]['unit'] = $data['cells'][$i][6];
  1021.                 $dataexcel[$i - 1]['tgl_bergabung'] = $data['cells'][$i][7];
  1022.             }
  1023.  
  1024.  
  1025.             //cek data
  1026.             //$check = $this->m_koperasi->search_anggota($dataexcel);
  1027.             /* var_dump($check);
  1028.               exit(); */
  1029.             //if (count($check) > 0) {
  1030.             //    $this->m_koperasi->update_anggota($dataexcel);
  1031.             //    header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/1');
  1032.             //} else {
  1033.                 $this->m_koperasi->truncate_anggota();
  1034.                 $this->m_koperasi->tambah_anggota($dataexcel);
  1035.                 $this->m_koperasi->set_default_password_anggota();
  1036.                 echo "<SCRIPT LANGUAGE='JavaScript'>
  1037.                        window.alert('Upload Anggota Sukses !')
  1038.                        window.location.href='" . base_url() . "index.php/admin';
  1039.                        </SCRIPT>";
  1040.                 //header('location:' . base_url() . 'index.php/adminwebsite/');
  1041.             //}
  1042.         }
  1043.         //  header('location:'.base_url().'index.php/adminwebsite/dataanggota');
  1044.     }
  1045.  
  1046.     function dataanggota($mess = -1) {  // checked by hatma @ 19 oct 2015
  1047.         $this->cek_session();
  1048.         $data_sess = $this->session->userdata('login');
  1049.         $data = array(
  1050.             'session' => $this->session->userdata('login'),
  1051.             'status' => '',
  1052.             'message' => $mess,
  1053.             'data_anggota' => $this->m_koperasi->getdataanggotaall()->result_array(),
  1054.             'label_post' => array(),
  1055.             'title' => 'Dasboard admin KUD Sumber Alam - Daftar Anggota'
  1056.         );
  1057.         $this->template->display('adminwebsite/data_anggota', $data);
  1058.     }
  1059.  
  1060.     function insertsimpanan() { // checked by hatma 19 okt
  1061.         $this->cek_session();
  1062.         $data_sess = $this->session->userdata('login');
  1063.         $data = array(
  1064.             'session' => $this->session->userdata('login'),
  1065.             'username' => $data_sess['pengguna'],
  1066.             'judul_content' => '',
  1067.             'header_post' => '',
  1068.             'status' => '',
  1069.             'label' => $this->m_koperasi->GetLabel()->result_array(),
  1070.             'label_post' => array(),
  1071.             'title' => 'Dasboard admin KUD Sumber Alam - isi content'
  1072.         );
  1073.         $this->template->display('adminwebsite/input_simpanan', $data);
  1074.     }
  1075.  
  1076.     function updatesimpanan() { // checked by hatma 19 okt
  1077.         $this->cek_session();
  1078.         $config['upload_path'] = './asset/files/data_koperasi/';
  1079.         $config['allowed_types'] = 'xls';
  1080.         $this->load->library('upload', $config);
  1081.         if (!$this->upload->do_upload()) {
  1082.             $data = array('error' => $this->upload->display_errors());
  1083.             $this->session->set_flashdata('msg_excel', 'Insert failed. Please check your file, only .xls file allowed.');
  1084.         } else {
  1085.  
  1086.             $data = array('error' => false);
  1087.             $upload_data = $this->upload->data();
  1088.  
  1089.             $this->load->library('excel_reader');
  1090.             $this->excel_reader->setOutputEncoding('CP1251');
  1091.  
  1092.             $file = $upload_data['full_path'];
  1093.             $this->excel_reader->read($file);
  1094.             error_reporting(E_ALL ^ E_NOTICE);
  1095.  
  1096.             // Sheet 1
  1097.             $data = $this->excel_reader->sheets[0];
  1098.             $dataexcel = Array();
  1099.  
  1100.             for ($i = 2; $i <= $data['numRows']; $i++) {
  1101.                 if ($data['cells'][$i][1] == '')
  1102.                     break;
  1103.                 $dataexcel[$i - 1]['no_anggota'] = $data['cells'][$i][1];
  1104.                 $dataexcel[$i - 1]['spn_pokok'] = $data['cells'][$i][2];
  1105.                 $dataexcel[$i - 1]['spn_wajib'] = $data['cells'][$i][3];
  1106.                 $dataexcel[$i - 1]['total'] = $data['cells'][$i][4];
  1107.                 $dataexcel[$i - 1]['tgl_update'] = Date("Y-m-d H:i:s");
  1108.             }
  1109.             //cek data
  1110.             /*
  1111.             $check = $this->m_koperasi->search_simpanan($dataexcel);
  1112.             if (count($check) > 0) {
  1113.                 $this->m_koperasi->update_simpanan($dataexcel);
  1114.                 header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/1');
  1115.             } else {
  1116.                 $this->m_koperasi->tambah_simpanan($dataexcel);
  1117.                 header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/1');
  1118.             }
  1119.              */
  1120.                 $this->m_koperasi->truncate_simpanan();
  1121.                 $this->m_koperasi->tambah_simpanan_baru($dataexcel);
  1122.                 echo "<SCRIPT LANGUAGE='JavaScript'>
  1123.                        window.alert('Upload Simpanan Sukses !')
  1124.                        window.location.href='" . base_url() . "index.php/admin';
  1125.                        </SCRIPT>";
  1126.         }
  1127.         //  header('location:'.base_url().'index.php/adminwebsite/dataanggota');
  1128.     }
  1129.  
  1130.     function insertpinjaman() { // checked by hatma 19 okt
  1131.         $this->cek_session();
  1132.         $data_sess = $this->session->userdata('login');
  1133.         $data = array(
  1134.             'session' => $this->session->userdata('login'),
  1135.             'username' => $data_sess['pengguna'],
  1136.             'judul_content' => '',
  1137.             'header_post' => '',
  1138.             'status' => '',
  1139.             'label' => $this->m_koperasi->GetLabel()->result_array(),
  1140.             'label_post' => array(),
  1141.             'title' => 'Dasboard admin KUD Sumber Alam - isi content'
  1142.         );
  1143.         $this->template->display('adminwebsite/input_pinjaman', $data);
  1144.     }
  1145.  
  1146.     function updatepinjaman() { // checked by hatma 19 okt
  1147.         $this->cek_session();
  1148.         $config['upload_path'] = './asset/files/data_koperasi/';
  1149.         $config['allowed_types'] = 'xls';
  1150.         $this->load->library('upload', $config);
  1151.         if (!$this->upload->do_upload()) {
  1152.             $data = array('error' => $this->upload->display_errors());
  1153.             $this->session->set_flashdata('msg_excel', 'Insert failed. Please check your file, only .xls file allowed.');
  1154.         } else {
  1155.  
  1156.             $data = array('error' => false);
  1157.             $upload_data = $this->upload->data();
  1158.  
  1159.             $this->load->library('excel_reader');
  1160.             $this->excel_reader->setOutputEncoding('CP1251');
  1161.  
  1162.             $file = $upload_data['full_path'];
  1163.             $this->excel_reader->read($file);
  1164.             error_reporting(E_ALL ^ E_NOTICE);
  1165.  
  1166.             // Sheet 1
  1167.             $data = $this->excel_reader->sheets[0];
  1168.             $dataexcel = Array();
  1169.  
  1170.             for ($i = 2; $i <= $data['numRows']; $i++) {
  1171.                 if ($data['cells'][$i][1] == '')
  1172.                     break;
  1173.                 $dataexcel[$i - 1]['no_anggota'] = $data['cells'][$i][1];
  1174.                 $dataexcel[$i - 1]['jumlah_pinjaman'] = $data['cells'][$i][2];
  1175.                 $dataexcel[$i - 1]['masa'] = $data['cells'][$i][3];
  1176.                 $dataexcel[$i - 1]['sekarang'] = $data['cells'][$i][4];
  1177.                 $dataexcel[$i - 1]['sisa'] = $data['cells'][$i][5];
  1178.                 $dataexcel[$i - 1]['angsuran_pokok'] = $data['cells'][$i][6];
  1179.                 $dataexcel[$i - 1]['sisa_angsuran'] = $data['cells'][$i][7];
  1180.                 $dataexcel[$i - 1]['keterangan'] = $data['cells'][$i][8];
  1181.                 $dataexcel[$i - 1]['tgl_update'] = Date("Y-m-d H:i:s");
  1182.             }
  1183.             //cek data
  1184.             /*
  1185.             $check = $this->m_koperasi->search_pinjaman($dataexcel);
  1186.             if (count($check) > 0) {
  1187.                 $this->m_koperasi->update_pinjaman($dataexcel);
  1188.                 header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/1');
  1189.             } else {
  1190.                 $this->m_koperasi->tambah_pinjaman($dataexcel);
  1191.                 header('location:' . base_url() . 'index.php/adminwebsite/dataanggota/1');
  1192.             }
  1193.              */
  1194.                 $this->m_koperasi->truncate_pinjaman();
  1195.                 $this->m_koperasi->tambah_pinjaman_baru($dataexcel);
  1196.                 echo "<SCRIPT LANGUAGE='JavaScript'>
  1197.                        window.alert('Upload Pinjaman Sukses !')
  1198.                        window.location.href='" . base_url() . "index.php/admin';
  1199.                        </SCRIPT>";
  1200.                
  1201.         }
  1202.         //  header('location:'.base_url().'index.php/adminwebsite/dataanggota');
  1203.     }
  1204.  
  1205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement