<?php include('header.php');?>
<?php include('sidebar.php');?>
 
<?php
$clientid=$_REQUEST['clientid'];
$maintitle=Projects;
$page="projects.php";
$table="tbl_projects";
$field_id="projectid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['contentid'];
if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>
<?php
 
if(isset($_REQUEST['submit'])=="submit"){ 
$dataexist=array();
//$required = array("issuedate","expiredate","memberid");
$values = $_POST;
unset($values['submit']);
unset($values['mode']);

$userid=array("user_id"=>$user_id);
$values=array_merge($values,$userid);
$images=$helper->multiple_image_upload($_FILES['frm_filename_images'],"gallery");

if($_REQUEST['mode']=="add"){
$message=$helper->insert($table,$values,$required,$dataexist);
        foreach($images as $image){
                   $helper->insert_multiple_images($image,$message['id'],"tbl_gallery_images","galleryid");
           } 
}
if($_REQUEST['mode']=="edit"){
$message=$helper->update($table, $values,array($field_id=>$_REQUEST['contentid']),$required);
 foreach($images as $image){
	   $helper->insert_multiple_images($image,$_REQUEST['contentid'],"tbl_gallery_images","galleryid");
   }
}
}
?>

<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>
<?php
if($mode=="edit"){
$contentdetails=$helper->select($table,"*",array($field_id=>$_REQUEST['contentid']));

         
}
?>
 <!-- Add / Edit / Delete --> 


     <div class="col-md-10">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title"> <?php echo AL_ADD;?> <?php echo $maintitle;?></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="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="mode" value="<?php echo $_REQUEST['mode'];?>"/>
              <div class="box-body">
              
                </div>
             <div class="form-group">
                     
                  <label for="inputEmail3" class="col-sm-3 control-label">Client Name</label>

                  <div class="col-sm-8">
                  <?php
                  $clients= $helper->select("tbl_client","clientid,companyname",array());				   
				  ?>
                  <select name="clientid" class="form-control" id="clientid">
                  <?php
				  foreach($clients as $client){
				  ?>
                  <option <?php if($client['clientid']==$contentdetails[0]['clientid']){ echo "selected";}?> value="<?php echo $client['clientid'];?>"><?php echo $client['companyname'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                   </div>
                </div>
                <div class="form-group">
                   
                  <label for="inputEmail3" class="col-sm-3 control-label">Service</label>

                  <div class="col-sm-8">
                  <?php
                  $services= $helper->select("tbl_services","serviceid,title",array());				   
				  ?>
                  <select name="service" class="form-control" id="branchid">
                  <?php
				  foreach($services as $service){
				  ?>
                  <option <?php if($service['serviceid']==$contentdetails[0]['serviceid']){ echo "selected";}?> value="<?php echo $service['serviceid'];?>"><?php echo $service['title'];?></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" required name="title" value="<?php echo $contentdetails[0]['title'];?>" class="form-control" id="title" placeholder="Title" >
                  </div>
                </div>
                 <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Maintenance Packages</label>

                  <div class="col-sm-8">
                    <input type="radio" name="package" value="Daily"/> Daily &nbsp;
                    <input type="radio" name="package" value="Weekly"/> Weekly&nbsp;
                    <input type="radio" name="package" value="Monthly"/> Monthly&nbsp;
                    <input type="radio" name="package" value="Quarterly"/> Quarterly&nbsp;
                    <input type="radio" name="package" value="Half Yearly"/> Half Yearly&nbsp;
                    <input type="radio" name="package" value="Yearly"/> Yearly
                  </div>
                </div>
                <?php /*?><div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Custom Url</label>

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

                  <div class="col-sm-8">
                    <textarea class="form-control" name="description" id="description" placeholder="Description"><?php echo $contentdetails[0]['description'];?></textarea>
                  </div>
                </div>
               <div class="form-group">
                <label for="inputEmail3" class="col-sm-3 control-label">Start Date</label>
				<div class="col-sm-6">
                <div class="input-group date">
                  <div class="input-group-addon">
                    <i class="fa fa-calendar"></i>
                  </div>
                  <input name="startdate" type="text" value="<?php echo $contentdetails[0]['startdate'];?>" class="form-control pull-right" id="datepicker">
                </div>
                </div>
                <!-- /.input group -->
              </div>
                
                <div class="form-group">
                <label for="inputEmail3" class="col-sm-3 control-label">End Date</label>
				<div class="col-sm-6">
                <div class="input-group date">
                  <div class="input-group-addon">
                    <i class="fa fa-calendar"></i>
                  </div>
                  <input name="enddate" type="text" value="<?php echo $contentdetails[0]['enddate'];?>" class="form-control pull-right" id="datepicker2">
                </div>
                </div>
                <!-- /.input group -->
              </div>
           
            <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Upload Contract</label>
                  <div class="col-sm-8">
                    <input type="file" class="" name="frm_filename">
                  </div>
                </div>
             <?php
            if($contentdetails[0]['image']!=""){
             ?>
            
                <div class="form-group">
                    <div class="col-sm-4"></div>
                  <div class="col-sm-8">
                      <a target="_self" href="<?php echo $site_url;?>images/contract/download.php?file=<?php echo $contentdetails[0]['image'];?>"><button class="btn btn-danger btn-flat">&nbsp;Download Contract</button></a>
                  </div>
                </div>
            <?php
            }
            ?>
              </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_SUBMIT;?>" class="btn btn-info pull-right"/>
             
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
         
        </div>
        </div>
        <?php
	    }
            else {
		?>
        <?php
		if($mode=="delete"){
			 $message=$helper->delete($table, array($field_id=>$_REQUEST['contentid']));
		}
		?>
          <?php
		if($mode=="approve"){
			$helper->update($table, array("status"=>1),array($field_id=>$_REQUEST['contentid']), array());
		}
		?>
         <?php
		if($mode=="pending"){
			$helper->update($table, array("status"=>2),array($field_id=>$_REQUEST['contentid']), array());
		}
		?>
        <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <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" data-toggle="tooltip" title="Add <?php echo $maintitle;?>">
                <div class="btn-group">
                <a href="<?php echo $page;?>?mode=add&branchid=<?php echo $branchid;?>"><button class="btn btn-danger btn-flat"><i class="glyphicon  glyphicon-plus"></i>&nbsp;<?php echo AL_ADDNEW;?> <?php echo $maintitle;?></button></a>
                   
                </div>
              </div>
            </div>
            <?php
			$listtypes=$helper->selectlimit($table,"*",array(),$start,$limit);			 
			?>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
            <?php
			if($message!=""){
			?>
            <button class="btn btn-block btn-danger btn-flat" type="button"><?php echo $message['message'];?></button>
			<?php	
			}
			?>
              <table class="table table-hover">
                <tr>
                  <th><?php echo AL_SERIALNO;?></th>
                  <th>Project Title</th>
                  <th>Branch Name</th>
                   <th>Start Date</th>
                   <th>End Date</th>
                  <th><?php echo AL_STATUS;?></th>
                  <th><?php echo AL_ACTION;?></th>
                  <th>Work Status</th>
                </tr>
                <?php
				$i=($start*$limit)+1;
				foreach($listtypes as $type){
				?>
                 <?php
				  if($_REQUEST['start']>0){
					  $limitpage=$_REQUEST['start'];
				  }
				  else {
					  $limitpage=1;
				  }
				 
                    
				  ?>
                <tr>
                  <td><?php echo $i;?></td>
                  <td><?php echo $type['title'];?></td>
                  <?php
                  $branch= $helper->select("tbl_branch","*",array("branchid"=>$type['branchid'])); 
		   ?>
                  <?php
                  $client= $helper->select("tbl_client","companyname",array("clientid"=>$clientid)); 
		         ?>
                   
                  <td><?php echo $branch[0]['branchname'];?></td>
                   <?php
                  $membername= $helper->select("tbl_members","firstname,middlename,lastname",array("memberid"=>$type['memberid']));
		   ?>
                  
                  <td><?php echo $type['startdate'];?></td>
                   <td><?php echo $type['enddate'];?></td>
                  <td>	
                    <?php
                     $currentdate=date('Y-m-d');
                    if($currentdate > $type['enddate']) 
                     {
                      echo '<span class="label label-danger">Expired</span>';
                      } else {
                       echo '<span class="label label-primary">Active</span>';   
                      }                    
                    ?>
                  </td>
                  <td>
                  <a href="<?php echo $site_url;?><?php echo $page;?>?userid=<?php echo $_REQUEST['userid'];?>&mode=edit&clientid=<?php echo $REQUEST['clientid'];?>&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>"><span class="label label-primary"><i class="fa fa-edit"></i> <?php echo AL_EDIT;?></span></a>
                  <?php
				  if($valexist==0 && $valexist==0){
				  ?>
                   <a href="<?php echo $site_url;?><?php echo $page;?>?mode=delete&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>&branchid=<?php echo $type['branchid'];?>" onclick="return getConfirmation()"><span class="label label-danger"><i class="fa fa-times"></i> <?php echo AL_DELETE;?></span></a>
                   <?php
				  }
				  ?>
                
                   </td>
                   <td>
                       <a class="fancybox fancybox.iframe"  href="<?php echo $site_url;?>schedule.php?projectid=<?php echo $type['projectid'];?>"><span class="label label-success">Schedule</span></a>
                   </td>
                </tr>
                 
                <?php
				$i=$i+1;
				}
				?>
                
                
              </table>
              <?php
			   $counter_list= $helper->countofdata($table,array(),$limit,array("status"=>"ASC"));
			  include('pagination/pagination.php');
			  ?>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
             
      </div>
      <?php
		   
                    
                }
		?>

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