<?php require_once './utility/texteditor_utility.php';?>
<?php
$req = $_POST['List'];
if(empty($req)){
		$req ="Add";
}
$ctrl_name = BASE_URL."/homebanners";
$page_name = BASE_URL."/homebanners/".$req;
$num = $cnt;

$SectionArr=array();
$SubsectionArr=array();
$PagesArr=array();
if($TotalSectionids){
	foreach($TotalSectionids as $TotalSectionid)
	{
			//print_r($TotalSectionid);
			
			$SectionIds = $TotalSectionid->section_ids;
			
			$SectionArr = explode(",",$SectionIds);
			
			$SubsectionIds = $TotalSectionid->subsection_ids;
			
			$SubsectionArr = explode(",",$SubsectionIds);
			
			$PagesIds = $TotalSectionid->pages_ids;
			
			$PagesArr = explode(",",$PagesIds);
			
	}
}

?>
<style>
		.black_overlay{
			display: none;
			position:fixed;
			top: 0%;
			left: 0%;
			width: 100%;
			height: 100%;
			background-color: black;
			z-index:1001;
			-moz-opacity: 0.7;
			opacity:.70;
			filter: alpha(opacity=70);
		}
		.white_content {
			display: none;
			position:fixed;
			top: 30%;
			left: 32%;
			width: 470px;
			height: 600px;
			z-index:1002;
			overflow: auto;
		}
</style>
<h1 class="page-header"><?php echo $_REQUEST["List"]?> Home Banner</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-8 alert alert-danger" style="clear:right">
                    <?php echo $error_msg;?>
                 </div>             
                </td>
             </tr>   
			 
         <?php } ?> 
		 	<tr>
                <td align="center">  
                  <div style="clear:right" align="right">
                   <button value="AddRecord" type="button" name="AddButton" class="btn btn-primary" onclick="location.href='<?php echo BASE_URL?>/homebanners/index'">Back to Home Banners</button>
                 </div>             
                </td>
             </tr>   
        <tr>
        	<td align="center">       
             <div class="col-lg-12">
             <div class="well">
                  <form name="frm" id="frm" method="post" class="bs-example form-horizontal" enctype="multipart/form-data">
                  <input type="hidden" name="act" id="act" value="" />
				  <input type="hidden" name="List" value="<?php echo $_REQUEST['List']?>">
					<input type="hidden" name="homebanner_id" id="homebanner_id" value="<?php echo $userDetails->id?>" />
                    <fieldset>                  
                      <div class="form-group">
                          <label class="col-lg-2 control-label" for="name">Title</label>
                        <div class="col-lg-8">
                          <input name="title" type="text" class="validate[required] form-control" id="title" value="<?php echo $userDetails->title?>" />
                        </div>
                      </div>
                      <div class="form-group">
                          <label class="col-lg-2 control-label" for="name">Image</label>
                        <div class="col-lg-8" align="left">
                          <input type="file" name="simage" id="simage" /> (only <?php echo VALID_EXT_HOMEBANNERS." files allowed";?> width=1920px and height=128px) 
                        </div>
                      </div>
                      <div class="form-group">
                          <label class="col-lg-3 control-label" for="page_content"></label>
                        <div class="col-lg-6">
                          <?php 
					  if(!empty($userDetails->simage)){
								 ?>
							 	<table align="center" border="0" cellpadding="3" cellspacing="3" width="100%">
                               	   <tr>	
                                   		<td width="133"><?php if(!empty($userDetails->simage)){?> <img src="<?php echo "../". UPLOADDIR_HOMEBANNERS."/".$userDetails->simage?>?<?php echo date("YmdHis")?>" width="100" height="100" alt="<?php echo SEO_IMAGE_ALT; ?>" title="<?php echo SEO_IMAGE_TITLE; ?>"> <?php }?><input type="hidden" name="homebanner_image_old" value="<?php echo $userDetails->simage?>">
										</td>
                                   	   
                                   </tr>
                               </table>
                             <?php } ?>
                        </div>
                      </div>
					 
                      <div class="form-group">
                          <label class="col-lg-2 control-label" for="designer_email">Status</label>
                        <div class="col-lg-8" align="left">
                          <select name="status" id="status" class="form-control" style="width:100px; text-align:left">
												  	<option value="1" <?php if($userDetails->status==1){echo "selected";}?>>Active</option>
													<option value="0" <?php if($userDetails->status==0){echo "selected";}?>>Inactive</option>
												  </select>
                        </div>
                      </div>
                      
                      <div class="form-group">
                          <label class="col-lg-2 control-label" for="designer_email">Is Common Banner?</label>
                        <div class="col-lg-8" align="left">
                          <select name="is_common" id="is_common" class="form-control" style="width:100px; text-align:left">
                            <option value="1" <?php if($userDetails->is_common==1){echo "selected";}?>>Yes</option>
                            <option value="0" <?php if($userDetails->is_common==0){echo "selected";}?>>No</option>
                          </select>
                        </div>
                      </div>
                      
                      <div class="form-group">

                          <label class="col-lg-2 control-label" for="designer_email">Assign Banner to</label>

                        <div class="col-lg-8" align="left">
                        
                        	<table align="center" border="0" cellpadding="5" cellspacing="5" width="100%">     
                            <tr>
                               	<td><input type="checkbox" name="secCheckBox[]" value="-1" <?php if(in_array(-1,$SectionArr)) { echo "Checked"; }?>>&nbsp;Home</td>
                               </tr>                     
                             <?php 
							  for($i=0;$i<count($SectionTree);$i++){ ?>
                               <tr>
                               	<td><input type="checkbox" name="secCheckBox[]" value="<?php echo $SectionTree[$i]["SectionId"]?>" <?php if(in_array($SectionTree[$i]["SectionId"],$SectionArr)) { echo "Checked"; }?> >&nbsp;<?php echo $SectionTree[$i]["SectionName"]?></td>
                               </tr>
                               <?php
							   	if($SectionTree[$i]["subSectionCnt"] > 0){ ?>
                                <tr>
                                	<td class="subSectionCont" style="padding-left:20px;">
                                     <table align="center" border="0" cellpadding="5" cellspacing="5" width="100%">  
                                     	<?php for($j=0;$j<count($SectionTree[$i]["SubSections"]);$j++){ ?>
                                        	 <tr>
                                           		 <td><input type="checkbox" name="subSecCheckBox[]" value="<?php echo $SectionTree[$i]["SubSections"][$j]["SubSectionId"]?>"
												  <?php if(in_array($SectionTree[$i]["SubSections"][$j]["SubSectionId"],$SubsectionArr)) { echo "Checked"; }?>>&nbsp;<?php echo $SectionTree[$i]["SubSections"][$j]["subSectionName"]?></td>
                                          	 </tr>
                                             <?php if($SectionTree[$i]["SubSections"][$j]["pagesCnt"] > 0){ ?>
                                              <tr>
			                                	<td class="PagesCont" style="padding-left:20px;">
                                                	<table align="center" border="0" cellpadding="5" cellspacing="5" width="100%">  
                                                    	<?php for($k=0;$k<count($SectionTree[$i]["SubSections"][$j]["Pages"]);$k++){ ?>
                                                        <tr>
                                                             <td><input type="checkbox" name="pagesCheckBox[]" value="<?php echo $SectionTree[$i]["SubSections"][$j]["Pages"][$k]["PageId"]?>"  <?php if(in_array($SectionTree[$i]["SubSections"][$j]["Pages"][$k]["PageId"],$PagesArr)) { echo "Checked"; }?>>&nbsp;<?php echo $SectionTree[$i]["SubSections"][$j]["Pages"][$k]["pageName"]?></td>
                                                         </tr>
                                                        <?php }?>
                                                    </table>
                                                </td>
                                              </tr>  
											 <?php }?>
                                        <?php } ?>
                                     </table>
                                    </td>
                                </tr>
								<?php }
                               ?>
							  <?php }
							 ?>
                            </table>

                        </div>

                      </div>
                      
                  
                      <div class="form-group">
                        <div class="col-lg-8 col-lg-offset-1">                    
                          <button class="btn btn-primary" name="Submit" type="submit" value="Submit">Submit</button>&nbsp; <button class="btn btn-primary" name="Cancel" type="button" value="Cancel" onclick="location.href='<?php echo BASE_URL?>/homebanners/index'">Cancel</button>
                        </div>
                      </div>
                    </fieldset>
                  </form>
            </div>
          </div>
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">

$(document).ready(function() {

    $('#frm').bootstrapValidator({

        message: 'This value is not valid',

        fields: {

            title: {

                message: 'The Title is not valid',

                validators: {

                    notEmpty: {

                        message: 'The Title is required and can\'t be empty'

                    }

                }

            },<?php if($req == "Add") {?>simage: {

                message: 'The Image is not valid',

                validators: {

                    notEmpty: {

                        message: 'The Image is required and can\'t be empty'

                    }

                }

            }<?php } ?>

        }

    });

});


</script>

