<!DOCTYPE html>
<html lang="en">
   <head>
      <!-- header -->
      <?php 
         helper('form');
         
          $session = session();
         
         $session = \Config\Services::session();
         
         echo view('admin/common_header'); ?>
      <!-- /header -->
      <!-- Bootsrap form validation JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/formValidation.js');?>"></script>
      <script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.js');?>"></script>
      <!-- Theme JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>
      <!-- /theme JS files -->
      <!-- bootsrap switch checkbox JS files -->
      <script src="<?php echo base_url('assets/boots/js/bootstrap-switch.js');?>"></script>
      <!-- notify JS files -->
      <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>
      	<!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/uploaders/fileinput.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/boots/js/fileinput.min.js');?>"></script>
      <style>
         select.form-control{
         width: 300px;
         height: 38px;
         }
      </style>
   </head>
   <body class="navbar-top-md-md">
      <!-- Fixed navbars wrapper -->
      <div class="navbar-fixed-top">
         <!-- Main navbar -->
         <?php echo view('admin/mainnav'); ?>
         <!-- /main navbar -->
         <!-- Second navbar -->
         <?php echo view('admin/secondnav'); ?>
         <!-- /second navbar -->
      </div>
      <!-- /fixed navbars wrapper -->
      <!-- Page header -->
      <div class="page-header">
         <div class="page-header-content">
            <div class="page-title">
               <h4><i id="icon-bck" class="icon-arrow-left52 position-left"></i> <span class="text-semibold"><?php echo 'Rank Settings'; ?></span></h4>
               <ul class="breadcrumb breadcrumb-caret position-right">
                  <?php foreach ($breadcrumbs as $breadcrumb) { if(isset($breadcrumb['href'])){?>
                  <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
                  <?php } else { ?> 
                  <li><?php echo $breadcrumb['text']; ?></li>
                  <?php } } ?>
               </ul>
            </div>
            <?php echo view('admin/'.$module_name.'_header'); ?>
         </div>
      </div>
      <!-- /page header -->
      <!-- Page container -->
      <div class="page-container">
         <!-- Page content -->
         <div class="page-content">
            <!-- Main content -->
            <div class="content-wrapper">
               <!-- Horizontal form -->
               <div class="panel panel-flat">
                  <div class="panel-heading">
                     <h5 class="panel-title"><?php echo 'Rank Settings'; ?></h5>
                     <div class="heading-elements">
                        <ul class="icons-list">
                           <li><a data-action="collapse"></a></li>
                           <li><a data-action="close"></a></li>
                        </ul>
                     </div>
                  </div>
                  <div class="panel-body">
                     <form class="form-horizontal form-account" id="rewardsettings" action="<?php echo site_url($action);?>" method="post" enctype="multipart/form-data">
                        <?php 
                           $validation = \Config\Services::validation();
                           if($validation->listErrors()) { 
                           	$form_err_data = str_replace('<p>', '', $validation->listErrors());
                           	$form_err_data = str_replace('</p>', '', $form_err_data);
                           	$form_err_data = str_replace('.', '', $form_err_data);
                           ?>
                        <script type="text/javascript">
                           (function( $ ) {
                           	$.jGrowl.defaults.closer = false;
                                  var from_daa = '<?php $form_err_data;?>';
                           	$.jGrowl(from_daa, {
                                      header: '<?php echo lang("language_lang.error");?>',
                                      theme: 'bg-danger'
                                  });
                              
                           })(jQuery);
                           
                           
                        </script>
                        <?php
                           }
                           ?>
                        <?php
                           if(isset($reward_info))
                           {
                               ?>
                        <input type="hidden" class="form-control" name="id" id="id" value="<?php echo $reward_info->id;?>"/>
                        <?
                           }
                           ?>
                        <div class="form-group  has-feedback <?php if($validation->getError('rank_name')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Rank Name<span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="rank_name" class="form-control"  value="<?php if(isset($reward_info)){ echo $reward_info->rank_name;}else{ echo  set_value('rank_name');}?>" placeholder="Rank Name">
                              </div>
                              <?php echo $validation->getError('rank_name', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>
                        <div class="form-group  has-feedback <?php if($validation->getError('amount')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Amount<span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="amount" class="form-control"  value="<?php if(isset($reward_info)){ echo $reward_info->amount;}else{ echo  set_value('amount');}?>" placeholder="Amount">
                              </div>
                              <?php echo $validation->getError('amount', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>
                        <div class="form-group  has-feedback <?php if($validation->getError('direct_spon_count')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Direct Sponsor Count<span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="direct_spon_count" class="form-control"  value="<?php if(isset($reward_info)){ echo $reward_info->direct_spon_count;}else{ echo  set_value('direct_spon_count');}?>" placeholder="Direct Sponsor Count">
                              </div>
                              <?php echo $validation->getError('direct_spon_count', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>
                        <?php 
                           $this->db = db_connect();
                           $rank = $this->db->query('select * from rewardsettings')->getResult();
                           
                           
                           
                           ?>
                        <div class="form-group  has-feedback <?php if($validation->getError('sponsor_elg_rank')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Sponsor Eligible Rank<span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <select name="sponsor_elg_rank" id="" class="form-control">
                                    <option value="">Select Rank</option>
                                    <?php 
                                       foreach($rank as $row)
                                       { 
                                       
                                       
                                       if(isset($reward_info)) { 
                                       $select = $reward_info->sponsor_elg_rank;
                                       } else {
                                       $select = '';
                                       }
                                       
                                       
                                       ?>
                                    <option value="<?php echo $row->id;?>"  <?php if($select == $row->id){ echo 'selected'; }   ?>   ><?php echo $row->rank_name;?></option>
                                    <?php  }
                                       ?>
                                 </select>
                              </div>
                              <?php echo $validation->getError('sponsor_elg_rank', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>
                        <div class="form-group  has-feedback <?php if($validation->getError('sponsor_elg_count')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Sponsor Eligible Count <span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="sponsor_elg_count" class="form-control" value="<?php if(isset($reward_info)){ echo $reward_info->sponsor_elg_count;}else{ echo  set_value('sponsor_elg_count');}?>" placeholder="Sponsor Eligible Count">
                              </div>
                              <?php echo $validation->getError('sponsor_elg_count', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>
                        <div class="form-group  has-feedback <?php if($validation->getError('team_reward')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Team Reward ( % )<span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="team_reward" class="form-control" value="<?php if(isset($reward_info)){ echo $reward_info->team_reward;}else{ echo  set_value('team_reward');}?>" placeholder="Team Reward">
                              </div>
                              <?php echo $validation->getError('team_reward', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>

                        <div class="form-group  has-feedback <?php if($validation->getError('gas_reward')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Gas Wallet Reward ( % )<span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="gas_reward" class="form-control" value="<?php if(isset($reward_info)){ echo $reward_info->gas_reward;}else{ echo  set_value('gas_reward');}?>" placeholder="Gas Fee Reward">
                              </div>
                              <?php echo $validation->getError('gas_reward', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>
                        <div class="form-group  has-feedback <?php if($validation->getError('group_sales')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold">Group Sales <span class="text-danger">*</span></label>
                           <div class="col-lg-3">
                              <div style="width:409px;" class="input-group">
                                 <input type="text" name="group_sales" class="form-control" value="<?php if(isset($reward_info)){ echo $reward_info->group_sales;}else{ echo  set_value('group_sales');}?>" placeholder="Group Sales">
                              </div>
                              <?php echo $validation->getError('group_sales', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
                           </div>
                        </div>

                        <div class="form-group has-feedback <?php if($validation->getError('rank_image')) echo "has-error";?>">
								<label class="control-label col-lg-3 text-semibold"> Upload Image <span class="text-danger">*</span></label>
								
								<div class="col-lg-6">
                        <div style="width:409px;" class="input-group">
										<input type="file" name="rank_image" class="file-input-extensions" value="<?php echo set_value('rank_image', isset($reward_info->image) ? "/..".$reward_info->image : '' ); ?>">
									</div>
									<span class="help-block"><?php echo lang('language_lang.site_logo_extension');?></span>
									<?php echo $validation->getError('rank_image', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								</div>
							</div>


                        <?php 
                           if(isset($reward_info)) { 
                           	$status = $reward_info->status;
                           } else {
                           	$status = '';
                           }
                           ?>
                        <!-- Switch single -->
                        <div class="form-group <?php if($validation->getError('status')) echo "has-error";?>">
                           <label class="control-label col-lg-3 text-semibold"><?php echo lang('language_lang.label_cur_status'); ?> </label>
                           <div class="col-lg-6">
                              <div class="checkbox checkbox-switch">
                                 <label>
                                 <input type="checkbox"   <?php if($status){ echo 'checked="checked"'; }   ?>  name="status" data-on-color="success" data-off-color="danger" data-on-text="<?php echo lang('language_lang.On');?>" data-off-text="<?php echo lang('language_lang.Off');?>" class="switchery">
                                 </label>
                              </div>
                              <?php echo $validation->getError('status', '<label class="validation-error-label">', '</label>'); ?>
                           </div>
                        </div>
                        <!-- /switch single -->
                        <div class="text-right col-lg-6">
                           <button style=" padding-right: 14px; margin-right: 205px;" type="submit" class="btn btn-primary"><?php echo lang('language_lang.button_update'); ?> <i class="icon-arrow-right14 position-right"></i></button>
                        </div>
                     </form>
                  </div>
               </div>
               <!-- /horizotal form -->
            </div>
            <!-- /main content -->
         </div>
         <!-- /page content -->
         <!-- Footer -->
         <div class="footer text-muted">
            <?php echo site_footer();?>
         </div>
         <!-- /footer -->
      </div>
      <!-- /page container -->
      <script type="text/javascript">
         jQuery.noConflict();
         (function( $ ) {
         $(function() {
         
         $(document).ready(function() {
         
         
         
         
         
         $.jGrowl.defaults.closer = false;
         
         <?php if($session->getFlashData('error_message')) { ?>
         $.jGrowl("<?php echo $session->getFlashData('error_message');?>", {
         header: '<?php echo lang("language_lang.error");?>',
         theme: 'bg-danger'
         });
         <?php } ?>
         
         <?php if($session->getFlashData('success_message')) { ?>
         $.jGrowl("<?php echo $session->getFlashData('success_message');?>", {
         header: '<?php echo lang("language_lang.success");?>',
         theme: 'bg-success'
         });
         <?php } ?>
         
         
         });
         $('#rewardsettings').formValidation({
         framework: 'bootstrap',
         excluded: [':disabled'],
         icon: {
         // valid: 'glyphicon glyphicon-ok',
         // invalid: 'glyphicon glyphicon-remove',                   
         validating: 'glyphicon glyphicon-refresh'
         },
         fields: {
         rank_name: {
         validators: {
         notEmpty: {
         message: 'Please Enter Rank Name'
         }
         }
         },
         amount: {
         validators: {
         notEmpty: {
         message: 'Please Enter Amount'
         },
         numeric:{
             message: 'Amount is Invalid'
         }
         }
         },
         direct_spon_count: {
         validators: {
         notEmpty: {
         message: 'Please Enter Direct Sponsor Count'
         },
         numeric:{
             message: 'Direct Sponsor Count is Invalid'
         }
         }
         },
         
         sponsor_elg_count: {
         validators: {
         notEmpty: {
         message: 'Please Enter Sponsor Eligible Count'
         },
         numeric:{
         message: 'Sponsor Eligible Count is Invalid'
         }
         }
         },
         team_reward: {
         validators: {
         notEmpty: {
         message: 'Please Enter Team Reward Percentage'
         },
         numeric:{
         message: 'Team Reward Percentage is Invalid'
         }
         }
         },
         gas_reward: {
         validators: {
         notEmpty: {
         message: 'Please Enter Gas fee Reward Percentage'
         },
         numeric:{
         message: 'Gas Fee Reward Percentage is Invalid'
         }
         }
         },
         group_sales: {
         validators: {
         notEmpty: {
         message: 'Please Enter Group Sales'
         },
         numeric:{
          message: 'Group Sale Invalid'
         }
         
         }
         }
         
         
         
         }
         })
         

         $(".file-input-extensions").fileinput({
		    uploadUrl: "http://localhost/file-upload-single/1", // server upload action
		    uploadAsync: false,
		    minFileCount: 1,
		    maxFileCount: 1,
		    overwriteInitial: true,
		    showUpload: false,
		    <?php if(isset($reward_info->image)) { ?>
		    	initialPreview: ["<?php echo base_url('assets/images/rank/'.$reward_info->image);?>"],
		    	initialPreviewAsData: true, // identify if you are sending preview data only and not the raw markup
		    	initialPreviewFileType: 'image', // image is the default and can be overridden in config below
		    <?php } ?>
		    allowedFileExtensions: ["jpg", "gif", "png", "jpeg"],
		    uploadExtraData: {
		        img_key: "1000"
		    }
		});

         $('#icon-bck').on('click',function() {
         				window.history.back();
         			});
         			
         		    $(".switchery").bootstrapSwitch();
         
         });
         })(jQuery);
         
      </script>
   </body>
</html>