<?php
include('accesscheck2.php');
require_once('Connections/courier.php');
require_once 'functions/functions.php';
mysql_select_db($database_courier, $courier);

if (!function_exists("GetSQLValueString")) {

 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
  if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
   case "text":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;
   case "long":
   case "int":
   $theValue = ($theValue != "") ? intval($theValue) : "NULL";
   break;
   case "double":
   $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
   break;
   case "date":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;
   case "defined":
   $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
   break;
  }
  return $theValue;
 }

}

// if(empty($id)){
//  $id = $_POST['id'];
// }
$id;
$sql = mysql_query("SELECT * FROM promotion_order WHERE id = $id", $courier) or die(mysql_error());
$patient_row = mysql_fetch_assoc($sql);

// if($action == "edit_purchase_order_pending" || $action == "add_new_purchase_order_pending"){
//  $next_action = "save_purchase_order_pending";
//  $next_action_2 = "edit_purchase_details_pending";
//  $btn_label = "Approve Purchase Order";
// }else{
//  $next_action = "save_purchase_order";
//  $next_action_2 = "edit_purchase_details";
//  $btn_label = "Save Purchase Order";
// }
$next_action = 'save_promo_order';
$btn_label = "Save Promotion1";

//echo $action;
?>


<div class="page-bar">
 <ul class="page-breadcrumb">
  <li>
   <i class="icon-home"></i>
   <a href="index.html">Home</a>
   <i class="fa fa-angle-right"></i>
  </li>
  <li>
   <span>Dashboard</span>
  </li>
 </ul>
 <div class="page-toolbar">
  <div class="btn-group pull-right">
   <button type="button" class="btn btn-fit-height grey-salt dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> Actions
    <i class="fa fa-angle-down"></i>
   </button>
   <ul class="dropdown-menu pull-right" role="menu">
    <li onclick="getstep('edit_purchase_order','<?php echo $id; ?>');">
     <a href="#">
      <i class="icon-refresh" style="display: none;"></i> Refresh
     </a>
    </li>
    <li>
     <a href="#" onclick="delInformtion('delete_purchase_order_promo', '#currentarea', '<?php echo $patient_row['id']; ?>', 'Promo No <?php echo $patient_row['id']; ?> ?', 'You are about to Delete Promo No. <?php echo $patient_row['id']; ?> from the List of Promotional Items.', 'Promo No. <?php echo $patient_row['id']; ?> Deleted Successfully !');"> <i id="trash_<?php echo $id; ?>" class="icon-trash" style="color:red;"></i> <i style="display: none;" id="spin_refresh_<?php echo $id; ?>" class="fa fa-refresh fa-spin fa-fw"></i> Delete Promotion </a>
    </li>
    <li onclick="getstep('list_purchase_orders');">
     <a href="#">
      <i class="fa fa-search" style="display: none;"></i> Search Purchase Orders
     </a>
    </li>
   </ul>
  </div>
 </div>
</div>



<div class="row">
 <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
  <div class="portlet light ">
   <div class="portlet-title">
    <div class="caption">
     <span class="caption-subject bold uppercase font-dark">  Promotion Settings </span>
    </div>
    <div class="actions">
     <a class="btn green" onclick="getstep('<?php echo $next_action; ?>','<?php echo $id; ?>')"> <?php echo $btn_label; ?> <i class="fa fa-check"></i> </a>
    </div>
   </div>
   <div class="portlet-body form">
    <div class="row">
     <form role="form" action="#" class="form-horizontal" id="save_purchase_order">
      <div class="form-body">
       <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
        <div class="col-md-6">
         <div class="row">
          <div class="portlet light ">
           <div class="portlet-title">
            <div class="caption">
             <span class="caption-subject font-dark"> Promotion Information </span>
            </div>
           </div>
           <input type="hidden" name="promo_id" id="promo_id" value="<?php echo $id; ?>">
           <div class="portlet-body form">
           <div class="form-group">
            <label class="col-md-5 control-label"><span class="pull-left">Start Date</span></label>
            <div class="col-md-7">  <input name="start_time" type="text" id="start_time" class="form-control date_time_picker" value="<?php echo $patient_row['start_date']; ?>" readonly> </div>
           </div>

             <div class="form-group">
            <label class="col-md-5 control-label">
                <span class="pull-left">End Date</span></label>
            <div class="col-md-7">  <input name="end_time" type="text" id="end_time" class="form-control date_time_picker" value="<?php echo $patient_row['end_date']; ?>" readonly> </div>
           </div>

               <div class="form-group">
                   <label class="col-md-5 control-label">
                       <span class="pull-left">Branch</span></label>
                   <div class="col-md-7">
                       <select class="form-control date_time_picker" name="promotionbranch" value="<?php echo $patient_row['end_date']; ?>" readonly>
                           <option value="<?php echo $patient_row['branch'] ?>"><?php echo branchName($patient_row['branch'], $courier) ?></option>
                           <?php $getBranch = mysql_query("SELECT * FROM branches");
                                 while ($row = mysql_fetch_assoc($getBranch)){ ?>
                                     <option value="<?php echo $row['id']?>"><?php echo $row['branch_name']?></option>
                                 <?php }
                           ?>
                       </select>
                   </div>
               </div>
            
           </div>
          </div>
         </div>
        </div>

        <div class="col-md-6">
         <div class="row">
          <div class="portlet light ">
           <div class="portlet-title">
            <div class="caption">
             <span class="caption-subject font-dark"> Promotion Description </span>
            </div>
           </div>
           <div class="portlet-body form">
             <div class="form-group">
             <label class="col-md-5 control-label"><span class="pull-left">Promotion Name</span></label>
             <div class="col-md-7"> <input name="promotion_name" type="text" id="promotion_name" class="form-control" value="<?php echo $patient_row['promotion_name']; ?>"> </div>
            </div>
          
           <div class="form-group">
            <label class="col-md-5 control-label"><span class="pull-left">Promotion Description</span></label>
            <div class="col-md-7"> <textarea name="promotion_description" cols="60" rows="3" id="promotion_description" class="form-control"><?php echo $patient_row['promotion_decription'];
            ?></textarea>
            </div>
           </div>
           
          </div>
         </div>
        </div>
       </div>
      </div>
     </div>
    </form>
   </div>
  </div>
 </div>
</div>
</div>

<form name="form" id="" action="">
 <input type="hidden" name="next_action_val" id="next_action_val" value="<?php echo $next_action; ?>">
 <div class="row">
  <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
   <div class="col-md-5">
    <div class="row">
     <div class="portlet light">
      <div class="portlet-title">
       <div class="caption">
        <?php if($action == "add_new_promotion" || $action == "view_promotion_details") {?>
         <input type="text" name="searchtext_query_item_name" onkeyup="MainsearchItemsName('search_items_promo_orders','#view_items_response_wrapper',this.value);" class="form-control input-circle" placeholder="Item Name">
        <input type="hidden" name="purchase_order_id" value="<?php echo $id; ?>">
        <?php }else{ ?>
        <input type="text" name="searchtext_query_item_name" onkeyup="MainsearchItemsName('search_items_purchase_orders','#view_items_response_wrapper',this.value);" class="form-control input-circle" placeholder="Item Name">
        <input type="hidden" name="purchase_order_id" value="<?php echo $id; ?>">
       <?php } ?>
       </div>
       <div class="actions">
        <select name="search_by" id="search_by" class="form-control input-circle">
         <option value="contains">Contains</option>
         <option value="begins">Begins</option>
        </select>
        <input type="hidden" value="<?php echo $next_action_2; ?>" name="action_next">
       </div>
      </div>
      <div class="portlet-body" id="">
       <div style="height: 300px;overflow-y: scroll;overflow-x: hidden;">
        <div class="" id="view_items_response_wrapper"> 
         <?php include 'purchase_order_search_items.php'; ?>
        </div>
       </div>
      </div>
     </div>
    </div>
   </div>

   <div class="col-md-7" id="view_items_response_wrapper_2">
    <?php 
    if ($action == "add_new_promotion" || $action == "view_promotion_details") {
     include 'list_of_added_items_promo.php';
    }else{
    $purchase_id = $patient_row['purchase_order_no'];
    include 'list_of_added_items.php';
    }
 ?>
   </div>
  </div>
 </div>
</form>