<?php include('header.php');?>
<?php include('sidebar.php');?>
<?php
$maintitle=AL_TEMPLATES;
$page="templates.php";
$table="tbl_templates";
$field_id="templateid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['content_id'];
if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>
<?php
 
if(isset($_REQUEST['submit'])){ 
$required = array("title","description");
$values = $_POST;
unset($values['submit']);
unset($values['mode']);
$userid=array("user_id"=>$user_id);
$values=array_merge($values,$userid);
}
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1><?php echo $maintitle;?></h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> <?php echo AL_DASHBOARD;?></a></li>
        <li class="active"><?php echo $maintitle;?></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
    <?php
	if($mode=="add" || $mode=="edit"){ 
	?>
     <div class="row">
 <!-- Add / Edit / Delete --> 

          <div class="col-sm-12"> 
          <div class="box box-success">
         <div class="box-header">
              <i class="fa fa-building-o"></i>
              <h3 class="box-title"><?php echo $maintitle;?></h3>
              <div class="box-tools pull-right">
                <div class="btn-group">
                <a href="<?php echo $page;?>"><button class="btn btn-danger btn-flat">&nbsp;<?php echo AL_LISTALL;?> <?php echo $maintitle;?></button></a>
                   
                </div>
              </div>
            </div> 
            </div> 
            </div>

 <!-- Add / Edit / Delete --> 
<?php
if($mode=="edit"){
$contentdetails=$helper->select($table,"*",array("user_id"=>$user_id,$field_id=>$_REQUEST['contentid']));
}
?>
      
     <div class="col-md-10">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title"><?php echo $contentdetails[0]['title'];?></h3>
            </div>
            
            <?php
			if($message!=""){
			?>
            <button class="btn btn-block btn-success btn-flat" type="button"><?php echo $message['message'];?></button>
			<?php	
			}
			?>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal" action="print.php" method="post" enctype="multipart/form-data" target="_blank">
            <input type="hidden" name="mode" value="<?php echo $_REQUEST['mode'];?>"/>
              <div class="box-body">
              <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label"><?php echo AL_BRANCHES;?></label>

                  <div class="col-sm-6">
                  <?php
                  $branches= $helper->select("tbl_branches","branchid,title",array());				   
				  ?>
                  <select name="branchid" class="form-control" id="branchid">
                      <option value=""><?php echo AL_SELECTBRANCH;?></option>
                  <?php
				  foreach($branches as $branch){
				  ?>
                  <option <?php if($branch['branchid']==$contentdetails[0]['branchid']){ echo "selected";}?> value="<?php echo $branch['branchid'];?>"><?php echo $branch['title'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                   </div>
                </div>
                   
                 <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label"><?php echo AL_MEMBERS;?> </label>

                  <div class="col-sm-6">
                  <?php
                  $memberdetails= $helper->select("tbl_members","*",array());				   
				  ?>
                  <select name="memberid" class="form-control" id="memberid">
                      <option>Select</option>
                       <?php
			 foreach($memberdetails as $content){
                        ?>
                         <option <?php if($content['memberid']==$contentdetails[0]['memberid']){ echo "selected"; } ?> value="<?php echo $content['memberid'];?>"><?php echo $content['firstname']." ".$content['middlename']." ".$content['lastname'];?></option>
                        <?php
			 }
			 ?>
                      
                  </select>
                   </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label"><?php echo AL_TITLE;?></label>

                  <div class="col-sm-8">
                    <input type="text" name="title" value="<?php echo $contentdetails[0]['title'];?>" class="form-control" id="title" placeholder="Title" >
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputPassword3" class="col-sm-3 control-label"><?php echo AL_DESCRIPTION;?></label>

                  <div class="col-sm-8">
                    <textarea style="height:800px;" class="form-control" id="editor2" name="description" id="description" placeholder="Description"><?php echo $contentdetails[0]['description'];?></textarea>
                  </div>
                </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <button type="reset" class="btn btn-default"><?php echo AL_CANCEL;?></button>
                <input type="submit" name="submit" value="<?php echo AL_EDITSUBMIT;?>" class="btn btn-info pull-left"/>
                 
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
         
        </div>
        </div>
        <?php
	    }
		 
		?>

    </section>
    <!-- /.content -->
  </div>
<?php include('footer.php');  ?>