<style type="text/css">
    #txtcontent{
        height: 400px;
    }
</style>
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="#"><?php echo $this->lang->line("SETTINGS"); ?></a>
            </li>
            <li class="active"><?php echo $this->lang->line("RESOURCES"); ?></li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->
    <!-- Page Header -->
    <div class="page-header position-relative">
        <div class="header-title">
            <h1>
                <?php echo $this->lang->line("RESOURCES"); ?>
            </h1>
        </div>
        <!--Header Buttons-->
        <div class="header-buttons">
            <a class="sidebar-toggler" href="#">
                <i class="fa fa-arrows-h"></i>
            </a>
            <a class="refresh" id="refresh-toggler" href="">
                <i class="glyphicon glyphicon-refresh"></i>
            </a>
            <a class="fullscreen" id="fullscreen-toggler" href="#">
                <i class="glyphicon glyphicon-fullscreen"></i>
            </a>
        </div>
        <!--Header Buttons End-->
    </div>
    <!-- /Page Header -->
    <!-- Page Body -->
    <!-- End Page Body -->
    <div class="page-body">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="row">
                    <div class="col-xs-12 col-md-12">
                        <div class="widget">
                            <div class="widget-body">

                                <div class = "row center">
                                    <div class="col-lg-12 col-sm-12 col-xs-12">
                                        <div class="widget center">
<div>
    <div id="horizontal-form">
        <form class="form-horizontal" role="form" method="POST" action="<?php echo site_url('settings/resources/add')?>">
            <input type="hidden" name="id" value="<?php echo !empty($editdata)?$editdata[0]->ID:''?>">
            
            
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label no-padding-right"><?php echo $this->lang->line("NAME"); ?></label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="name" id="name" placeholder="<?php echo $this->lang->line("NAME"); ?>" value="<?php echo!empty($editdata)?$editdata[0]->NAME:'' ?>">
                </div>
            </div>
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label no-padding-right"><?php echo $this->lang->line("RESOURCETYPE"); ?></label>
                <div class="col-sm-10">
                    <select class="form-control" name="restype" id="restype" onchange="togglefield(this.value)">
                         <option value="0" <?php if($editdata && $editdata[0]->RESTYPE==0) echo "selected"; ?>><?php echo $this->lang->line("TEXT"); ?></option>
                         <option value="1" <?php if($editdata && $editdata[0]->RESTYPE==1) echo "selected"; ?>><?php echo $this->lang->line("IMAGE"); ?></option>
                     </select>
                </div>
            </div>
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label no-padding-right"><?php echo $this->lang->line("CONTENT"); ?></label>
                <div class="col-sm-10">
                    
                    
<input type="file" name="content" id="filecontent" class="form-control" <?php if(($editdata && $editdata[0]->RESTYPE==0) || !$editdata) echo 'style="display:none;"'; ?> />

<img src="<?php if($editdata && $editdata[0]->RESTYPE==1) echo !empty($editdata)? "data:image/jpeg;base64,".base64_encode($editdata[0]->CONTENT):'' ?>" id="displaylogoimg" width="150" <?php if($editdata && $editdata[0]->RESTYPE==0) echo 'style="display:none;"'; ?> />

<textarea class="form-control" name="content" id="txtcontent" placeholder="<?php echo $this->lang->line("CONTENT"); ?>" <?php if($editdata && $editdata[0]->RESTYPE==1) echo 'style="display:none;"'; ?>><?php echo !empty($editdata)?htmlentities($editdata[0]->CONTENT):'' ?></textarea>

                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-success">
                    <span class="fa fa-check"></span>
                    <?php echo $this->lang->line("SAVE"); ?></button>
                    <a id="close" href="<?php echo site_url('settings/resources')?>" class="btn btn-danger">
                        <span class="fa fa-close"></span>
                        <?php echo $this->lang->line("CLOSE"); ?>
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
                                        </div>
                                    </div> 
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Page Content -->
<script type="text/javascript">
    function togglefield(restype){
        if(restype=='0'){
            $("#filecontent").hide();
            $("#displaylogoimg").hide();
            $("#txtcontent").show();
        }else if(restype=='1'){
            $("#filecontent").show();
            $("#displaylogoimg").show();
            $("#txtcontent").hide();
        }
    }
    
    function readURL(input,imgid) {
        if (input.files && input.files[0]) {
          var reader = new FileReader();
          reader.onload = function(e) {
            $("#txtcontent").html(e.target.result);
            $('#'+imgid).attr('src', e.target.result);
          }
          reader.readAsDataURL(input.files[0]);
        }
    }    
    $("#filecontent").change(function() {
        readURL(this,'displaylogoimg');
    });
</script>