Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Guestbook extends CI_Controller {
- /**
- * ----------------------------------------------------------------------
- * Method __construct()
- * @return void
- * @access public
- * ----------------------------------------------------------------------
- */
- public function __construct()
- {
- parent::__construct();
- $this->load->model(array('m_gbook'));
- $this->load->helper(array('captcha'));
- date_default_timezone_set('Asia/Jakarta');
- }
- /**
- * ----------------------------------------------------------------------
- * Method index()
- * @return void
- * @access public
- * fungsi untuk menampilkan form input buku tamu
- * ----------------------------------------------------------------------
- */
- public function index()
- {
- $data['setting'] = $this->m_config->find_by_id(1);
- $data['action'] = site_url('guestbook/save/');
- $data['captcha'] = $this->_set_captcha();
- $data['multilevel'] = $this->m_nav->get_data();
- $data['content'] = 'guestbook/form_guestbook';
- $this->load->view('front_end/index', $data);
- }
- /**
- * ----------------------------------------------------------------------
- * Method save()
- * @return void
- * @access public
- * fungsi untuk menyimpan data buku tamu
- * ----------------------------------------------------------------------
- */
- public function save()
- {
- if($this->_set_validation() == TRUE)
- {
- $this->m_gbook->fill_data();
- $this->m_gbook->insert();
- $data['multilevel'] = $this->m_nav->get_data();
- $data['type'] = 'success';
- $data['message'] = 'Pesan sudah tersimpan!';
- $data['setting'] = $this->m_config->find_by_id(1);
- $data['content'] = 'alert/front_alert';
- $this->load->view('front_end/index', $data);
- echo "<meta http-equiv='refresh' content='2; url=".site_url()."/guestbook/'>";
- }
- else
- {
- $this->index();
- }
- }
- /**
- * ----------------------------------------------------------------------
- * Method _set_validation()
- * @return boolean
- * @access public
- * fungsi untuk validasi form inputan
- * ----------------------------------------------------------------------
- */
- private function _set_validation()
- {
- $this->form_validation->set_rules('name', '|', 'trim|required');
- $this->form_validation->set_rules('email', '|', 'trim|required|valid_email');
- $this->form_validation->set_rules('msg', '|', 'trim|required');
- $this->form_validation->set_rules('captcha', '|', 'trim|required|callback_valid_captcha');
- $this->form_validation->set_error_delimiters('<span style="color:maroon; font-weight: normal;">', '</span>');
- return $this->form_validation->run();
- }
- /**
- * ----------------------------------------------------------------------
- * Method read()
- * @return void
- * @access public
- * fungsi untuk menampilkan data dari tabel tbl_guestbook
- * ----------------------------------------------------------------------
- */
- public function read()
- {
- $this->auth->admin_restrict();
- /*
- $this->load->library('pagination');
- $config = array(
- 'base_url' => site_url().'/guestbook/read/',
- 'total_rows' => $this->db->count_all('tbl_guestbook'),
- 'per_page' => 10,
- 'uri_segment' => 3,
- 'first_link' => 'First',
- 'last_link' => 'Last',
- 'next_link' => 'Next',
- 'prev_link' => 'Prev',
- 'full_tag_open' => '<ul>',
- 'full_tag_close' => '</ul>',
- 'num_tag_open' => '<li>',
- 'num_tag_close' => '</li>',
- 'cur_tag_open' => '<li class="active"><a>',
- 'cur_tag_close' => '</a></li>'
- );
- $this->pagination->initialize($config);
- $data['pagination'] = $this->pagination->create_links();
- */
- $data['dashboard'] = 'class = active';
- $data['gbooks'] = $this->m_gbook->find_all();
- $data['content'] = 'guestbook/read';
- $this->load->view('back_end/index', $data);
- }
- /**
- * ----------------------------------------------------------------------
- * Method detail()
- * @return void
- * @access public
- * fungsi untuk menampilkan 1 record dari tabel tbl_guestbook
- * ----------------------------------------------------------------------
- */
- public function detail()
- {
- $this->auth->admin_restrict();
- if($this->uri->segment(3) == FALSE)
- {
- redirect('guestbook/read/');
- }
- else
- {
- $id = $this->uri->segment(3);
- $data['dashboard'] = 'class = active';
- $data['query'] = $this->m_gbook->find_by_id($id);
- $data['content'] = 'guestbook/detail';
- $this->load->view('back_end/index', $data);
- }
- }
- /**
- * ----------------------------------------------------------------------
- * Method Replay()
- * @return void
- * @access public
- * fungsi untuk menampilkan form email reply pada daftar
- * ----------------------------------------------------------------------
- */
- public function reply()
- {
- $this->auth->admin_restrict();
- if($this->uri->segment(3) == FALSE)
- {
- redirect('guestbook/read/');
- }
- else
- {
- $id = $this->uri->segment(3);
- $data['dashboard'] = 'class = active';
- $data['query'] = $this->m_gbook->find_by_id($id);
- $data['content'] = 'guestbook/detail';
- $this->load->view('back_end/index', $data);
- }
- }
- /**
- * ----------------------------------------------------------------------
- * Method delete()
- * @return void
- * @access public
- * fungsi untuk menghapus data
- * ----------------------------------------------------------------------
- */
- public function delete()
- {
- $this->auth->admin_restrict();
- $id = $this->uri->segment(3);
- $this->m_gbook->delete($id);
- $data['dashboard'] = 'class = active';
- $data['type'] = 'alert-success';
- $data['alert_heading'] = 'Sukses';
- $data['message'] = 'Data sudah terhapus!';
- $data['content'] = 'alert/message';
- $this->load->view('back_end/index', $data);
- echo "<meta http-equiv='refresh' content='1; url=".site_url()."/guestbook/read/'>";
- }
- /**
- * ----------------------------------------------------------------------
- * Method multiple_delete()
- * @return void
- * @access public
- * fungsi untuk menghapus data
- * ----------------------------------------------------------------------
- */
- public function multiple_delete()
- {
- $this->auth->admin_restrict();
- if(isset($_POST['id']))
- {
- $id = $_POST['id'];
- $jumlah = count($id);
- for($i = 0; $i<$jumlah; $i++)
- {
- mysql_query("DELETE FROM tbl_guestbook WHERE gb_id='$id[$i]' ");
- }
- $data['dashboard'] = 'class = active';
- $data['type'] = 'alert-success';
- $data['alert_heading'] = 'Sukses';
- $data['message'] = 'Data sudah terhapus!';
- $data['content'] = 'alert/message';
- $this->load->view('back_end/index', $data);
- echo "<meta http-equiv='refresh' content='1; url=".site_url()."/guestbook/read/'>";
- }
- else
- {
- redirect('guestbook/read/');
- }
- }
- private function _set_captcha()
- {
- $vals = array(
- 'img_path' => './assets/captcha/',
- 'img_url' => base_url().'/assets/captcha/',
- 'img_width' => 150,
- 'img_height' => 35,
- 'expiration' => 7200,
- 'word' => random_string('numeric', 4)
- );
- $cap = create_captcha($vals);
- $data = array(
- 'captcha_time' => $cap['time'],
- 'ip_address' => $this->input->ip_address(),
- 'word' => $cap['word']
- );
- $query = $this->db->insert_string('captcha', $data);
- $this->db->query($query);
- return $cap;
- }
- // OK
- public function valid_captcha($str)
- {
- // First, delete old captchas
- $expiration = time()-7200; // Two hour limit
- $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);
- // Then see if a captcha exists:
- $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
- $binds = array($str, $this->input->ip_address(), $expiration);
- $query = $this->db->query($sql, $binds);
- $row = $query->row();
- if ($row->count == 0)
- {
- $this->form_validation->set_message('valid_captcha', 'Captcha tidak valid');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- public function excel()
- {
- error_reporting(E_ALL);
- $this->load->helper('excel');
- $this->config->load('application_info');
- require_once APPPATH.'third_party/PHPExcel'.EXT;
- $query = $this->m_gbook->excel_data();
- $objXLS = new PHPExcel();
- $objSheet = $objXLS->setActiveSheetIndex(0);
- $cell = 2;
- $no = 1;
- $objSheet->setCellValue('A1', 'No.');
- $objSheet->setCellValue('B1', 'Nama');
- $objSheet->setCellValue('C1', 'Email');
- $objSheet->setCellValue('D1', 'Tanggal Kirim');
- $objSheet->setCellValue('E1', 'Komentar');
- $objSheet->setCellValue('F1', 'IP Address');
- foreach($query->result_array() as $data)
- {
- $objSheet->setCellValue('A'.$cell, $no);
- $objSheet->setCellValue('B'.$cell, $data['gb_name']);
- $objSheet->setCellValue('C'.$cell, $data['gb_email']);
- $objSheet->setCellValue('D'.$cell, indo_date($data['gb_date']));
- $objSheet->setCellValue('E'.$cell, strip_tags($data['gb_content']));
- $objSheet->setCellValue('F'.$cell, $data['gb_ip']);
- $cell++;
- $no++;
- }
- $file_name = 'Data Inbox';
- $objXLS->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);
- $objXLS->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);
- $objXLS->getActiveSheet()->getColumnDimension("C")->setAutoSize(true);
- $objXLS->getActiveSheet()->getColumnDimension("D")->setAutoSize(true);
- $objXLS->getActiveSheet()->getColumnDimension("E")->setAutoSize(true);
- $objXLS->getActiveSheet()->getColumnDimension("F")->setAutoSize(true);
- $objXLS->setActiveSheetIndex(0);
- $objXLS->getProperties()->setCreator($this->config->item('creator'))
- ->setLastModifiedBy($this->config->item('creator'))
- ->setTitle($file_name)
- ->setSubject($this->config->item('subject'))
- ->setDescription($file_name)
- ->setKeywords($this->config->item('key_word'))
- ->setCategory('Data Master');
- $objWriter = PHPExcel_IOFactory::createWriter( $objXLS, 'Excel5');
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="'.$file_name.'.xls"');
- header('Cache-Control: max-age=0');
- $objWriter->save('php://output');
- exit();
- }
- public function kirim_emailX()
- {
- $this->load->helper(array('form', 'url'));
- $this->load->library('upload');
- $this->load->library('email');
- //konfigurasi email
- $config = array();
- $config['charset'] = 'utf-8';
- $config['useragent'] = 'Codeigniter'; //bebas sesuai keinginan kamu
- $config['protocol']= "smtp";
- $config['mailtype']= "text";
- $config['smtp_host']= "ssl://smtp.gmail.com";
- $config['smtp_port']= "465";//465
- $config['smtp_timeout']= "5";
- $config['smtp_user']= "psb.bukhari@gmail.com";//isi dengan email kamu
- $config['smtp_pass']= "psbbukhari@8856"; // isi dengan password kamu
- $config['crlf']="\r\n";
- $config['newline']="\r\n";
- $config['wordwrap'] = TRUE;
- //memanggil library email dan set konfigurasi untuk pengiriman email
- $this->email->initialize($config);
- //konfigurasi pengiriman
- $this->email->from($this->input->post('from'));
- $this->email->to($this->input->post('to'));
- $this->email->subject($this->input->post('subject'));
- $this->email->message($this->input->post('isi'));
- //Configure upload.
- $this->upload->initialize(array(
- "upload_path" => "./uploads/",
- "allowed_types" => "*"
- ));
- if($this->email->send())
- {
- //echo "berhasil mengirim email";
- redirect('guestbook/read');
- }else
- {
- //echo "gagal mengirim email";
- echo $this->email->print_debugger();
- }
- }
- //on
- public function send_now()
- {
- $this->load->library('email');
- $this->email->from('no.replay@psb-bukhari.com', 'Panitia Seleksi');
- $this->email->to('liliek.triyono@gmail.com');
- $this->email->cc('');
- $this->email->bcc('');
- $this->email->subject('Sending Email from CodeIgniter with Mandrill');
- $this->email->message('If you forgot how to do this, go ahead and refer to: <a href="http://the-amazing-php.blogspot.com/2015/05/codeigniter-send-email-with-mandrill.html">The Amazing PHP</a>.');
- //$this->email->send();
- if (!$this->email->send()){
- show_error($this->email->print_debugger());
- }else{ echo 'YEAH!!!';}
- }
- //on
- public function send_emailx()
- {
- $to = "liliek.triyono@gmail.com";//need to change
- $subject = "Email subjet here";
- $from_name = "4 Rapid Development";
- $from_email = "no-reply@4rapiddev.com";
- $body = "";
- $body .= "Hi,<br>";
- $body .= "How are you?<br><br>";
- $body .= "<a href='http://4rapiddev.com'>4rapiddev.com</a>";
- $this->load->library('email');
- $config['charset'] = 'utf-8';
- $config['mailtype'] = 'html';
- $config['wordwrap'] = TRUE;
- $config['protocol'] = 'smtp';
- $config['smtp_port'] = '587';//need to change; Mandrill: 587
- $config['smtp_host'] = 'smtp.mandrillapp.com';//need to change; Mandrill: smtp.mandrillapp.com
- $config['smtp_user'] = "psb.bukhari@gmail.com";//need to change
- $config['smtp_pass'] = "eolzZHCxlAr4DdA3MZehyg";//need to change
- $config['smtp_timeout'] = "30";
- $this->email->initialize($config);
- $this->email->from('no-reply@4rapiddev.com', '4 Rapid Development');
- $this->email->to($to);
- $this->email->subject($subject);
- $this->email->message($body);
- //$this->email->send();
- if (!$this->email->send()){
- show_error($this->email->print_debugger());
- }else{ echo 'YEAH!!!';}
- }
- //on
- public function kirim_email()
- {
- $to = $this->input->post('to');//need to change
- $subject = $this->input->post('subject');
- $content = $this->input->post('isi');
- $from_name = "Panitia Seleksi PSB Al Bukhari";
- $from_email = "no-reply@srv-psb.com";
- $this->load->library('email');
- $this->email->from($from_email, $from_name);
- $this->email->to($to);
- $this->email->set_mailtype('html');
- $this->email->subject($subject);
- $this->email->message($content);
- if($this->email->send())
- {
- //echo "berhasil mengirim email";
- redirect('guestbook/read');
- }else
- {
- //echo "gagal mengirim email";
- echo $this->email->print_debugger();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement