<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  
  <head>
    <title>
      Admin &gt; File Manager | <?php echo html_escape($this->system->set[ 'site_name']) . PHP_EOL; ?>
    </title>
    <?php include_once(VIEWPATH. 'includes/head.php'); ?>
    <style>
    .list-inline.folder>li {
        padding-right: 2px;
        padding-left: 2px
    }
    .panel-body code {
        background-color: transparent;
        border-radius: 0;
    }
    </style>
    <?php if ($this->uri->segment(5) == 'application' && $this->uri->segment(6) == 'views' && $set['edit']):?>
    <script src="<?php echo base_url('assets/js/jquery-linedtextarea.js');?>"></script>
	<link href="<?php echo base_url('assets/css/jquery-linedtextarea.css');?>" type="text/css" rel="stylesheet" />
    <?php endif;?>
  </head>
  
  <body>
    <?php include_once(VIEWPATH. 'admin/_navbar.php'); ?>
    <div class="container">
      <ul class="breadcrumb">
        <li><a href="<?php echo site_url();?>"><i class="fa fa-home"></i></a></li>
        <li><a href="<?php echo site_url('admin');?>">Admin Panel</a></li>
        <li><a href="<?php echo site_url('admin/modules/file-manager/browse/'.dirname($path));?>">File Manager</a></li>
        <li class="active"><span><?php echo $file_name;?></span></li>
      </ul>
      <div class="row">
        <div class="col-sm-3">
          <?php
          $params = array(array(
            'title' => basename($path) != '.' ? basename($path) : '/',
            'icon' => 'fa fa-folder-o',
            'links' => array(),
          ));
          $params[0]['links'][] = array('Parent Directory',site_url('admin/modules/file-manager/browse/'.dirname($path)),'fa fa-reply', false);
          foreach ($results['folders'] as $dir) {
            $params[0]['links'][] = array($dir['name'], site_url('admin/modules/file-manager/browse/'.$path.$dir['name']),'fa fa-folder-o', false);
          }
          foreach ($results['files'] as $file) {
            $params[0]['links'][] = array($file['name'], site_url('admin/modules/file-manager/edit/'.$path.$file['name']),'fa fa-file', $file['name'] === $file_name ? true : false);
          }
          echo sidebar_menu($params);
          ?>
        </div>
        <div class="col-sm-9">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3>
                <i class="fa fa-file"></i> <?php echo $file_name;?>
              </h3>
            </div>
            <?php if ($this->uri->segment(5) == 'application' && $this->uri->segment(6) == 'views' && $set['edit']):?>
            <div class="panel-body">
              <?php echo form_open();?>
                <div class="alert alert-warning">
                  <i class="fa fa-exclamation-triangle"></i> Berhati - hatilah jika mengedit file, syntax harus diperhatikan agar tidak terjadi error!
                </div>
                <div class="form-group">
                  <textarea name="source" id="source" rows="25" style="width: 100%;"><?php echo set_value('source', $content);?></textarea>
                </div>
                <div>
                  <button type="submit" class="btn btn-primary">Simpan</button>
                </div>
              <?php echo form_close();?>
            </div>
            <?php else:?>
            <div class="panel-body" style="overflow-x:scroll">
              <?php
              $code = highlight_code($content);
              
              if (!$code)
                $code = highlight_string($content);
              
              echo $code;
              ?>
            </div>
            <?php endif;?>
            <div class="panel-footer" style="overflow: hidden;"><i>File: <?php echo $path.$file_name;?></i></div>
          </div>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <?php if ($this->uri->segment(5) == 'application' && $this->uri->segment(6) == 'views' && $set['edit']):?>
    <script>
    $(function() {
      $("#source").linedtextarea({selectedLine: <?php echo $error_line;?>});
    });
    </script>
    <?php endif;?>
  </body>

</html>