403Webshell
Server IP : 127.0.0.1  /  Your IP : 192.168.99.1
Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9
System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64
User : Administrator ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /wamp/www/simbada_2018/application/core/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /wamp/www/simbada_2018/application/core/Core_Laporan.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Core_Laporan extends Userpage_Controller {

  var $path2engine;
  var $path2fr3;
  var $path2cache;
  var $path2output;
  var $attachment;
  var $fr3;
  var $nama_laporan;
  var $xml;
  var $tipe;
  var $area;
  var $group;
  var $unit;
  var $varname;
  var $xml_file;
  var $xml_custom;
  var $xml_temp;
  var $default_param;

  public function __construct()
  {
    parent::__construct();
    $this->load->helper('path');
    $this->path2engine = dirname( realpath(SELF) )."/assets/fr/";
    $this->path2fr3 = $this->path2engine . 'fr3/';
    $this->path2cache = $this->path2engine . 'cache/';
    $this->path2output = $this->path2engine . 'output/';
    $this->attachment = 1; // 0 : show in the browser;  1 : download file
    $this->default_param = array(
      'tahun' => $this->tahun,
      'status' => $this->status,
      'ppkd' => $this->ppkd,
      'roles' => $this->roles,
      'group' => $this->group,
      'skpd_login' => $this->id_skpd,
      'id_kd_lokasi' => $this->id_kd_lokasi,
    );

    // override sesuai nama file yang digunakan
    $this->xml_file = 'simbada.xml';
    $this->xml_custom = 'simbada_custom.xml';
    $this->xml_temp = 'simbada_temp.xml';
  }

  function param($tipe = '', $area = '', $grup = '', $unit = '', $varname = '')
  {
    if ( $tipe == '' || $area == '' || $grup == '' || $unit == '' )
    {
      echo 'Parameter tidak lengkap';
      return FALSE;
    }

    $this->tipe = intval($tipe);
    $this->area = intval($area);
    $this->group = intval($grup);
    $this->unit = intval($unit);
    $this->varname = intval($varname);

    if ($varname !== '')
    {
      $this->reload_param();
    }
    else
    {
      $this->get_parameter();
    }
  }

  protected function read_xml()
  {
    if (! $this->xml = simplexml_load_file($this->path2fr3.$this->xml_temp) )
    {
      echo 'Laporan tidak ditemukan';
      return FALSE;
    }

    $data = $this->xml->TIPE[$this->tipe]->AREA[$this->area]->GROUP[$this->group]->REPORT[$this->unit];
    $this->fr3 = (string) $data->attributes()->file;
    $this->nama_laporan = (string) $data->attributes()->namafile;

    return $data->children();
  }

  protected function get_parameter()
  {
    if (! $report = $this->read_xml() )
    {
      return FALSE;
    }

    $var = array();
    $depend = array();

    // proses untuk default param terlebih dahulu;
    foreach($this->default_param as $key => $val)
    {
      $var[ ':'.$key ] = "'".$val."'";
    }

    $html = '';
    $html .= '<div id="dlg-param" data-tipe="'.$this->tipe.'" data-area="'.$this->area.'" data-group="'.$this->group.'" data-unit="'.$this->unit.'" >';
    for( $i = 0; $i < count($report); $i++)
    {
      $varname = strtolower( (string) $report[$i]->attributes()->varname );
      $caption = (string) $report[$i]->attributes()->caption;
      $default = (string) $report[$i]->attributes()->default;
      $const = (string) $report[$i]->attributes()->value;	  

      if (strtoupper($report[$i]->getName()) == 'DATE')
      {
        // default value
        switch( $default ){
          case 'd' : $default = date('d/m/Y'); break;
          case 'mb' : $default = date('1/m/Y'); break;
          case 'me' : $default = date('t/m/Y'); break;
          case 'tb' :  $tw = floor( (date('n') - 1) / 3) + 1; $default = date('1/'.$tw.'/Y'); break;
          case 'te' : $tw = floor( (date('n') - 1) / 3) + 3; $default = date('t/'.$tw.'/Y'); break;
          case 'yb' : $default = date('1/1/Y'); break;
          case 'ye' : $default = date('t/12/Y'); break;

          default: $default = date('d/m/Y');
        }

        $html .= '<div class="control-row" >';
        $html .= '<label class="control-label" for="'.$varname.'">'.$caption.'</label>';
        $html .= '<input class="report-param datepicker" type="text" id="'.$varname.'" data-tag="'. $i .'" ';
        $html .= 'class="span2 datepicker" value="'.$default.'" />';
        $html .= '</div>';

        $var[ ':'.$varname ]  = "'".prepare_date($default)."'";
      }
      else if (strtoupper($report[$i]->getName()) == 'INPUT')
      {
        $html .= '<div class="control-row" >';
        $html .= '<label class="control-label" for="'.$varname.'">'.$caption.'</label>';
        $html .= '<input class="report-param" type="text" id="'.$varname.'" data-tag="'. $i .'" ';
        $html .= 'class="span2" value="'.$default.'" />';
        $html .= '</div>';

        $var[ ':'.$varname ]  = "'".$default."'";
      }
      else if (strtoupper($report[$i]->getName()) == 'CONST')
      {
        $html .= '<input class="report-param" type="hidden" id="'.$varname.'" data-tag="'. $i .'" value="'.$const.'" />';

        $var[ ':'.$varname ]  = "'".$const."'";
      }
	  
      else if (strtoupper($report[$i]->getName()) == 'SELECT')
      {
        $sql = "".$report[$i]->ITEMSQL->__tostring().""; 
        $key = strtoupper( (string) $report[$i]->ITEMSQL['key'] );
					/* if($key == 'KODE_LOKASI' && $this->session->userdata('id_kd_lokasi') !== 0)
					{	
						$sql .= "where s.id_kode_lokasi = ".$this->session->userdata('id_kd_lokasi')."";
					}
					if($key == 'KODE_LOKASI'){
						$sql .= "order by 1";
					} */
        $display = strtoupper( (string)$report[$i]->ITEMSQL['display'] );
        $selected = '';

        // dependensi
        $dep = $this->get_dependensi( $sql );
        if ( count( $dep ) > 0)
        {
          foreach( $dep as $row )
          {
            $depend[ $row ][] = $varname;
          }
        }

        $html .= '<div class="control-row" >';
        $html .= '<label class="control-label" for="'.$varname.'">'.$caption.'</label>';
        $html .= '<select class="report-param" id="'.$varname.'" data-tag="'. $i .'" style="width:100%" >';

        $result = $this->execute_query($sql, $var);

        foreach( $result as $row )
        {
          $selected = ($row[$key] == $default ? "selected" : "");
          $html .= '<option value="'.$row[$key].'" ' .$selected.' >'.$row[$display].'</option>';
        }
        $html .= '</select></div>';

        $var[ ':'.$varname ]  = "'".$default."'";
        if ($selected == '' && count($result) > 0)
        {
          $var[ ':'.$varname ]  = "'".$result[0][$key]."'";
        }
      }
    }
    $html .= '</div>';

    if (count($depend) > 0)
    {
      $html .= '<script>';
      foreach( $depend as $key => $value)
      {
        $key = str_replace(':', '', $key);
        $html .= '$("#'.$key.'").change(function(){';
        foreach ($value as $val )
        {
          $html .= 'Preview.reload_param("'. $val .'");';
        }
        $html .= '});';
      }
      $html .= '</script>';
    }

    echo $html;
  }

  protected function reload_param()
  {
    if (! $report = $this->read_xml() )
    {
      return FALSE;
    }

    if (! $node = $report[$this->varname] )
    {
      echo 'Parameter tidak ditemukan';
      return FALSE;
    }

    $var = array();
    // proses untuk default param terlebih dahulu;
    foreach($this->default_param as $key => $val)
    {
      $var[ ':'.$key ] = "'".$val."'";
    }

    $option = '';
    // get post variable
    $post = $this->input->post();
    foreach( $post as $key => $value )
    {
      if ($this->validateDate($value, 'd/m/Y'))
        $var[ ':'.$key ] = "'".prepare_date($value)."'";
      else $var[ ':'.$key ] = "'".$value."'";
    }

    $default = (string) $report->attributes()->default;

    $sql = $node->ITEMSQL->__tostring();
    $key = strtoupper( (string) $node->ITEMSQL['key'] );
    $display = strtoupper( (string) $node->ITEMSQL['display'] );

    $result = $this->execute_query($sql, $var);

    foreach( $result as $row )
    {
      $option .= '<option value="'.$row[$key].'"'. ($row[$key] == $default ? " selected" : ""). '>'.$row[$display].'</option>';
    }

    echo $option;
  }

  function validateDate($date, $format = 'Y-m-d H:i:s')
  {
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
  }

  protected function execute_query( $sql, $var)
  {
    $sql = strtr( $sql, $var );

    $result = $this->db->query( $sql );
    if ($result) return $result->result_array();
    else return array();
  }

  protected function get_dependensi( $sql )
  {
    $pattern = "/\:\w*/";
    preg_match_all( $pattern, $sql, $match);
    return $match[0];
  }

  protected function start($param)
  {
    $this->load->helper('file');

    $data = 'ReportName='. $param['fr3'] ."\n";
    $data .= 'OutputType='. $param['format'] ."\n";
    $data .= 'DriverName='.$this->db->dbdriver."\n";
    $data .= 'Connection=DB Express'."\n";
    $data .= 'DBPort='.$this->db->port."\n";
    $data .= 'DBServer='.$this->db->hostname."\n";
    $data .= 'DBName='.$this->db->database."\n";
    $data .= 'DBUser='. $this->db->username."\n";
    $data .= 'DBPassword='. $this->db->password."\n";

    if (isset($param['opt'])) {
      foreach($param['opt'] as $key => $value){
        if (is_array($value)) {
          $value = json_encode($value);
        }
        $data.=$key.'='.$value."\n";
      }
    }

    $in = tempnam($this->path2cache, "in");
    write_file($in, $data);
    $out = basename( $in, '.tmp');
    $outfile = $this->path2output.$out;

    if( PHP_OS == 'WIN32' || PHP_OS == 'WINNT')
    {
      exec($this->path2engine.'RepEngine.exe "'.$in.'" "'.$outfile.'"');
    }
    else
    {
      exec('DISPLAY=:100 wine '.$this->path2engine.'RepEngine.exe "'.$in.'" "'.$outfile.'" 2>'.$this->path2engine.'RepEngine.log');
    }

    $response = (object) NULL;
    if (file_exists($outfile.".ok"))
    {
      $response->isSuccessful = TRUE;
      $response->id = $out;
      $response->nama = rawurlencode($param['nama']);
    }
    else
    {
      $response->isSuccessful = FALSE;
      $response->message = 'Laporan gagal dibuat.';
    }
    echo json_encode($response);
  }

  function proses($tipe = '', $area = '', $grup = '', $unit = '')
  {
    if ( $tipe == '' || $area == '' || $grup == '' || $unit == '' )
    {
      echo 'Parameter tidak lengkap';
      return FALSE;
    }

    $format = $this->input->post('format');
    $this->tipe = intval($tipe);
    $this->area = intval($area);
    $this->group = intval($grup);
    $this->unit = intval($unit);

    if (! $report = $this->read_xml() )
    {
      return FALSE;
    }

    $param['fr3'] = $this->fr3;
    $param['nama'] = $this->nama_laporan;
    $param['format'] = $format ? $format : 'pdf';
    // parameter default
    foreach($this->default_param as $key => $val)
    {
      $param['opt'][$key] = $val;
    }

    $post = $this->input->post();
    if (is_array($post)) {
      foreach( $post as $key => $value )
      {
        $param['opt'][ $key ] = $value;
      }
    }

    $this->start($param);
  }

  public function view($key = '', $reportname = '')
  {
    $this->load->helper('file');

    $ext = "";
    if( PHP_OS == 'WIN32' || PHP_OS == 'WINNT') $ext = ".tmp";

    if (!file_exists($this->path2cache.$key.$ext)) {
      $this->output->set_status_header(500);
      return;
    }

    $config = file($this->path2cache.$key.$ext);
    $filetype = explode('=', $config[1]);
    $filetype = preg_replace("/[\n\r]/","", $filetype[1]);
    $filetype = $filetype == 'rtf' ? 'doc' : $filetype;

    $filename = $key. "." .$filetype;
    $fileerr = $key.".err";

    if (file_exists($this->path2output.$filename)) {
      $outfile = $reportname. "." .$filetype;

      header('Content-Disposition: ' . ($this->attachment == 1 ? 'attachment; ' : '') .'filename="'.$outfile.'"');
      switch ($filetype){
        case 'pdf' :
          header('Content-Type: application/pdf');
          break;
        case 'xls' :
          header('Content-Type: application/xls');
          break;
        case 'xlsx' :
          header('Content-Type: application/xls');
          break;
        case 'doc' :
          header('Content-Type: application/doc');
          break;
        case 'docx' :
          header('Content-Type: application/doc');
          break;
        case 'odt' :
          header('Content-Type: application/odt');
          break;
        case 'ods' :
          header('Content-Type: application/odf');
          break;
      }

      header('Content-Length: '.filesize($this->path2output.$filename));
      header('Cache-Control: no-store');
      readfile($this->path2output.$filename);
    }
    elseif (file_exists($this->path2output.$fileerr)) {
      $this->output->set_status_header(500);
    }
  }

}

Youez - 2016 - github.com/yon3zu
LinuXploit