<?php 
/*
	Freeway eCommerce
	http://www.openfreeway.org
	Copyright (c) 2007 ZacWare

	Released under the GNU General Public License 
*/	
// Check to ensure this file is included in osConcert!
defined('_FEXEC') or die();
?>
<div>
<h3><?php echo HEADING_TITLE; ?></h3>



<?php
  if ($messageStack->size('borlisting') > 0) {
?>
      <div><?php echo $messageStack->output('borlisting'); ?></div>
<?php
  }
  //start edit section
  if (isset($_GET['edit']) && is_numeric($_GET['edit'])){
?>
  
   <h4><?php echo BOR_EDIT_TITLE. $_GET['edit']; ?></h4>
      
	  <table width="100%" cellspacing="1" cellpadding="2" class="infoBox" style="display:true">
          <tr class="">
            <td>
            <table width="100%" cellpadding="2">
<?php

// now load order info

	  $bor_query = tep_db_query("select * from " . TABLE_ORDERS . " 
									where bor_datetime > 0
									AND orders_id = '".$_GET['edit']."'
									AND orders_status = '".MODULE_PAYMENT_BOR_ORDER_STATUS_ID."'
									LIMIT 1");
		if (tep_db_num_rows($bor_query) == 0 ) { 
			echo "<tr><td>";
			echo BOR_NIL;
			echo "</td><tr></table></td></tr></table></div>";
		}else{
//create header row
     ?>
     <tr>
     	<td><?php echo BOR_ORDER; ?></td>
        <td><?php echo BOR_ORDER_PIN; ?></td>
        <td><?php echo BOR_EXPIRY; ?></td>
        <td><?php echo BOR_TICKETS; ?></td>
     </tr>
     
     <?php	

    
 	while ($bor_results = tep_db_fetch_array($bor_query)) {

?>
            <tr>
                
                <td valign="top">
                    <?php echo $bor_results['orders_id'].' - <b>'.$bor_results['billing_name'].'</b><br>'.$bor_results['billing_company']; ?>
                </td>
                <td valign="top">
               		 <?php echo $bor_results['bor_random_id']; ?>
                </td>
                <td valign="top">
    <?php echo $bor_results['bor_datetime']; ?>

    <td>
    <?php echo $bor_results['bor_datetime']; ?>

		<?php
		if ((float)$bor_results['bor_expiry'] > (float)MODULE_PAYMENT_BOR_TIME) {
			echo '<br><span class="text-danger fw-bold">' . TEXT_EXTENDED . '</span>';
		}
		?>
	</td>

    <form action="bor_listings.php" method="post" style="margin-top:10px;">
        <input type="hidden" name="action" value="extend_bor">
        <input type="hidden" name="orders_id" value="<?php echo (int)$_GET['edit']; ?>">

        <div style="font-size:12px; margin-bottom:4px;">
    <?php echo TEXT_EXTEND_EXPIRY; ?>
	</div>

	<button type="submit" name="extend_days" value="1" class="btn btn-sm btn-outline-primary"><?php echo TEXT_EXTEND_1_DAY; ?></button>
	<button type="submit" name="extend_days" value="2" class="btn btn-sm btn-outline-primary"><?php echo TEXT_EXTEND_2_DAYS; ?></button>
	<button type="submit" name="extend_days" value="4" class="btn btn-sm btn-outline-primary"><?php echo TEXT_EXTEND_4_DAYS; ?></button>
	<button type="submit" name="extend_days" value="7" class="btn btn-sm btn-outline-primary"><?php echo TEXT_EXTEND_7_DAYS; ?></button>
	<button type="submit" name="extend_days" value="14" class="btn btn-sm btn-outline-danger"><?php echo TEXT_EXTEND_14_DAYS; ?></button>
    </form>
</td>
                <td>
                </td>
                    
          </tr>
          <tr>
             <td colspan="3" valign="top"  >
             <?php //order comments here
			 				$comments = "ORDER COMMENTS:<br>";
							$sql3 = "
								SELECT 
									comments 
								FROM
									orders_status_history
								WHERE
									orders_id = '".$_GET['edit']."'
							    AND
								    TRIM(comments) <> ''
								ORDER BY
									orders_status_history_id ASC";
									
								$comments_query = tep_db_query($sql3); 
								
								;
								
		                        $comments_count = tep_db_num_rows($comments_query);
		                       if ($comments_count > 0 ){
       
	                                while($comments_result = tep_db_fetch_array($comments_query)){
									
										$comments .= $comments_result['comments'];
										$comments .=  '<br>';
										
										
									
									   }
									}else{
									  $comments = 'TEXT_NO ORDER COMMENTS';
									}
									
									echo $comments;
					?>
             
             
             </td>
             <td valign="top">
                 <?php    //////////////////////// tickets //////////////
		 $bor_tickets_query = tep_db_query("select * from " . TABLE_ORDERS_PRODUCTS . " 
									where orders_id = '".$_GET['edit']."'");
		if (tep_db_num_rows($bor_tickets_query) == 0 ) { 
		
				echo BOR_NIL_TICKETS;
			}else{?>
                     <script type="text/javascript">
						<!--
						function confirmation() {
							var answer = confirm("<?php echo BOR_CONFIRM_RESERVATIONS; ?>")
							if (answer){
								return true
							}
							else{
								return false
							}
						}
						//-->
						</script>

            <form action="checkout_process_reservation.php" method="post" id = "bor" name = "bor" onsubmit = "return confirmation();">
            <input type="hidden" name = "orders_id" value = "<?php echo $_GET['edit'];?>" />
            <table>
            	<tr>
                	<td></td>
                    <td align="center"><?php echo BOR_CONFIRM; ?></td><td> </td>
                    <td align="center"><?php echo BOR_RESTOCK; ?></td>
                </tr>
              <?php 	while ($bor_ticket_results = tep_db_fetch_array($bor_tickets_query)) {?>
                  <tr>
                  	<td valign="top"><?php echo $bor_ticket_results ['categories_name']
				              .' '
					          .$bor_ticket_results ['products_name']
							  .'<br><span style ="font-size: 10px">'
							  .$bor_ticket_results ['concert_date']
							  .' '
							  .$bor_ticket_results ['concert_time']
							  .'</span>';
						?>
				    </td>
                    <td valign="top" align="center">
                     <input type="checkbox" id = "chk1<?php echo $bor_ticket_results['orders_products_id'];?>" name="confirm_list[]" checked = "checked" 
                      	value="<?php echo $bor_ticket_results['orders_products_id'];?>"
                        onclick="javascript:document.getElementById('chk2<?php echo $bor_ticket_results['orders_products_id'];?>').checked =!document.getElementById('chk1<?php echo $bor_ticket_results['orders_products_id'];?>').checked;"
                        >
					</td><td> </td>
                    <td valign="top" align="center">
                      <input type="checkbox" id = "chk2<?php echo $bor_ticket_results['orders_products_id'];?>" name="restock_list[]" 
                        value="<?php echo $bor_ticket_results['orders_products_id'];?>"
                        onclick="javascript:document.getElementById('chk1<?php echo $bor_ticket_results['orders_products_id'];?>').checked =! document.getElementById('chk2<?php echo $bor_ticket_results['orders_products_id'];?>').checked;">
					</td>
                  </tr>			 
			<?php } ?>
               </table>

<input  type="submit" class="btn btn-primary" value="<?php echo TEXT_SUBMIT; ?>" />
</form>
            <?php }	 ?>

                    </td>
                  </tr>


<?php
  }
?>
            </table>
           </td>
          
          
          </tr>
        </table>

 </div>
  
<?php  
  }
  }else{
  
  //end edit section
?>
      <h4><?php echo BOR_TITLE; ?></h4>
      
	  <table width="100%" cellspacing="1" cellpadding="2" class="infoBox" style="display:true">
          <tr class="">
            <td>
            <table width="100%" cellpadding="2">
<?php

// now load current orders
		if(BOR_AGENT_ONLY=='true'){
			$agent_only="AND customers_id = '" . $FSESSION->get("customer_id") . "'";
		}else{
			$agent_only="";
		}
		

	  $bor_query = tep_db_query("select * from " . TABLE_ORDERS . " 
									where bor_datetime > 0
									AND orders_status = '".MODULE_PAYMENT_BOR_ORDER_STATUS_ID."' $agent_only");
		if (tep_db_num_rows($bor_query) == 0 ) { 
		
			echo "<tr><td>";
			echo BOR_NIL;
			echo "</td><tr></table></div>";
		}else{
//create header row
     ?>
     <tr>
     	<td><?php echo BOR_ORDER; ?></td>
        <td><?php echo BOR_ORDER_PIN; ?></td>
        <td><?php echo BOR_EXPIRY; ?></td>
        <td><?php echo BOR_SELECT; ?></td>
     </tr>
     
     <?php	}




 	while ($bor_results = tep_db_fetch_array($bor_query)) {

?>
              <tr>
                
                <td>
                    <?php echo $bor_results['orders_id'].' - <b>'.$bor_results['billing_name'].'</b>'; ?>
                </td>
                <td>
               		 <?php echo $bor_results['bor_random_id']; ?>
                </td>
                <td>
					<td>
					<?php echo $bor_results['bor_datetime']; ?>

					<?php
					if ((float)$bor_results['bor_expiry'] > (float)MODULE_PAYMENT_BOR_TIME) {
						echo '<br><span class="text-danger fw-bold">' . TEXT_EXTENDED . '</span>';
					}
					?>
				</td>
                    <td >
					   <?php echo '<a href="' . tep_href_link('bor_listings.php', 'edit=' . $bor_results['orders_id'], 'SSL') . '">' .   tep_template_image_button_basic('', SMALL_IMAGE_BUTTON_EDIT) . '</a>';
                            
                        ?>
                    </td>
                  </tr>


<?php
  }
?>
            </table></td>
          </tr>
        </table>
		

 </div>
 
 <?php // end main table display
 }
 ?>
 <br> <br>
<div class="cart-page__empty-actions d-flex justify-content-end gap-2">
          <?php
          echo '<a href="' . tep_href_link(FILENAME_FEATURED_CATEGORIES) . '">' . tep_template_image_button_basic('', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>';
          echo '&nbsp;&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_template_image_button_basic('', IMAGE_BUTTON_CONTINUE) . '</a>';
          ?>
        </div>