<?php	
	$ctrl_name = BASE_URL."/admin";
	$page_name = BASE_URL."/admin/changesettings";		
	
?>
<h1 class="page-header">Site Configuration</h1>  
<div class="bs-example table-responsive">
<table align="center" width="100%" border="0">   
 		<?php if(!empty($error_msg)) {?>     
            <tr>
                <td align="center">  
                  <div class="col-lg-6 alert alert-danger" style="clear:right">
                    <?php echo $error_msg;?>
                 </div>             
                </td>
             </tr>   
         <?php } ?>  	
    	<tr>
        	<td align="center">                  
		<div class="bs-example">
              <ul style="margin-bottom: 15px;" class="nav nav-tabs">
             	 	<?php 				
				   	for($i=0;$i<count($tabArr);$i++) {
					   if(!empty($option_cat_val)){
						   if($option_cat_val == ($i+1)){ $activeIn = "active"; }
						   else{ $activeIn = "";  }						   
					   }else{
						   if($i == 0){ $activeIn = "active"; }
						   else { $activeIn = ""; }
					   } 					   
					?>		   
                <li class="<?php echo $activeIn; ?>"><a data-toggle="tab" href="#<?php echo $tabArr[$i]?>"><?php echo $tabValArr[$i]?></a></li>
                <?php } ?>                
              </ul>
              <div class="tab-content" id="myTabContent">
               	<?php 				
				   	for($i=0;$i<count($tabArr);$i++) {
					   if(!empty($option_cat_val)){
						   if($option_cat_val == ($i+1)){ $activeIn = "active in"; }
						   else{ $activeIn = "";  }						   
					   }else{
						   if($i == 0){ $activeIn = "active in"; }
						   else { $activeIn = ""; }
					   }
				 ?>
                
                <div id="<?php echo $tabArr[$i]?>" class="tab-pane fade <?php echo $activeIn; ?>">
                      <table align="center" width="100%" border="0">  
                        <tr>
                            <td>		
                            		<div class="col-lg-10">
							             <div class="well">
                                    	                       
										<?php if($site_messages[$i]!=''){ ?>
                                        <form name="<?php echo $tabArr[$i]?>Frm" id="<?php echo $tabArr[$i]?>Frm" action="<?php echo $page_name?>" method="post" class="bs-example form-horizontal">                                  
                                        <input type="hidden" name="option_cat" id="option_cat" value="<?php echo ($i+1); ?>">   
                                         	<fieldset>
                                           		  <?php  
													if($site_messages[$i]!=''){
														foreach ($site_messages[$i] as $settings) {
													?>
                                            	   <div class="form-group">
                                                  	  <input type="hidden" name="id[]" value="<?php echo $settings->id;?>" />
                                                      <label class="col-lg-2 control-label" for="fname"><?php echo $settings->option_title;?></label>
                                                    <div class="col-lg-10">
                                                     <?php if(!$settings->option_type){ ?>
													  <textarea name="txt_<?php echo $settings->id;?>" id="txt_<?php echo $settings->id;?>" rows="2" class="form-control"><?php echo $settings->option_value;?></textarea>
													  <?php }else{ 
													  $r1_check = $settings->option_value ? "checked" : "";
													  $r2_check = !$settings->option_value ? "checked" : "";
													  ?>
                                                      <div class="radio">
                                                        <label>
                                                          <input type="radio" checked="" name="r_<?php echo $settings->id;?>" id="r1_<?php echo $settings->id;?>" value="1" <?php echo $r1_check;?>>
                                                          Active
                                                        </label>
                                                      </div>
                                                      <div class="radio">
                                                        <label>
                                                          <input type="radio" name="r_<?php echo $settings->id;?>" id="r2_<?php echo $settings->id;?>" value="0" <?php echo $r2_check;?>>
                                                          Inactive
                                                        </label>
                                                      </div>
													  <?php }  ?>                                                     
                                                    </div>
                                                    
                                                  </div>
                                                  <?php } ?>                                                   
                                                  <div class="form-group">
                                                    <div class="col-lg-10 col-lg-offset-5">                    
                                                      <button class="btn btn-primary" name="Submit" type="submit" value="Submit">Update Messages</button>
                                                    </div>
                                                  </div>
                                                  <?php }else{ ?>
												  <div class="col-lg-6 alert alert-danger" style="float:none">Clients Messages Not Found</div>
												  <?php
												  }?>
                                            </fieldset>
                                   		
                                        </form>
                                  		 <?php }else{
                                      	?>
                                      	 <div class="col-lg-6 alert alert-danger" style="float:none">Messages Not Found</div>
										  <?php
                                         }?>
                                        
                                     	</div>
                                	</div>  
                            </td>
                        </tr>
                      </table>
                </div>
                
                <?php } ?>               
              </div>
   </div>
   	</td>
   </tr>
</table>    
</div>
<script language="javascript">
$(document).ready(function() {
<?php 
for($i=0;$i<count($tabArr);$i++) { 
if($site_messages[$i]!=''){
?>
    $('#<?php echo $tabArr[$i]?>Frm').bootstrapValidator({
        fields: {
			<?php 
				$pad="";
				foreach ($site_messages[$i] as $settings) {
					 if(!$settings->option_type){ 
			?><?php echo $pad;?>
					txt_<?php echo $settings->id;?>: {
						message: 'The field value is not valid',
						validators: {
							notEmpty: {
								message: 'The field is required and can\'t be empty'
							}
						}
					}
				 <?php $pad=",";
				 		} ?>				
			<?php } ?>	
        }
    });
<?php
	}
 } ?>
 });
</script>