<?php defined('_JEXEC') or die('Restricted access'); 
/**
* @copyright	Copyright (C) 2008-2009 CMSJunkie. All rights reserved.
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
use Joomla\CMS\HTML\HTMLHelper;

?>
<div id="jbd-container" class="jbd-container jbd-edit-container">
    <form action="<?php echo JRoute::_('index.php?option=com_jbusinessdirectory&view=updates');?>" method="post" name="adminForm" id="adminForm">
    	<input type="hidden" name="task" value="" />
    	<input type="hidden" name="controller" value="" />
    	<input type="hidden" name="boxchecked" value="1" />
    	
    	<?php echo JHTML::_( 'form.token' ); ?> 
    
    	<fieldset class="boxed">
    		 <h3><?php echo JText::_('LNG_UPDATES',true); ?></h3>
    		 <div class="row">
    		 	<div class="col-md-6">
          		 	<div class="form-group">
                        <label for="name"><?php echo JText::_('LNG_ORDER_ID')?> </label>
                        <input type="text" name="orderId" id="orderId" value="<?php echo isset($this->appSettings->order_id)?$this->appSettings->order_id:""?>">
                        <?php echo JText::_('LNG_ORDER_NOTICE')?>
                    </div>
          		 	<div class="form-group">
                        <label for="name"><?php echo JText::_('LNG_ORDER_EMAIL')?> </label>
                        <input type="text" name="orderEmail" id="orderEmail" value="<?php echo isset($this->appSettings->order_email)?$this->appSettings->order_email:""?>">
                        <?php echo JText::_('LNG_ORDER_EMAIL_NOTICE')?>
                    </div>
                    <div class="form-group">
                    	<?php echo JText::_('LNG_CURRENT_VERSION').' : <b><span class="text-success">'.$this->currentVersion."</span></b>" ?>
                    	<div id="orderData">
			  				<?php echo $this->expirationDate;?>
			  			</div>
                    </div>
    		 	</div>
    		 	<div class="col-md-4 offset-2">
					<div style="border:1px solid #ccc;width:300px;padding:10px;background:#fff"><span class="badge badge-warning rounded-circle"><i class="la la-exclamation"></i></span> <?php echo JText::_('LNG_UPDATE_NOTICE',true)?></div>	 		
    		 	</div>
    		 </div>
    	</fieldset>			
    	
    	<fieldset class="adminform">
        	<legend><?php echo JText::_('LNG_AVAILABLE_UPDATES',true)?></legend>
        	<?php if (is_array($this->items) && count($this->items)) : ?>
        		<table class="jtable" id="itemList">
        			<thead class="jtable-head">
        				<tr class="jtable-head-row">
							<th class="jtable-head-row-data">
								<div class="d-flex justify-content-center align-items-center">
									<div class="jradio">
										<input id="jradio-2" type="checkbox" title="<?php echo JText::_('JGLOBAL_CHECK_ALL');?>" onclick="Joomla.checkAll(this)" />
										<label for="jradio-2"></label>
									</div>
								</div>
							</th>
        					<th class="jtable-head-row-data">
        						<?php echo JText::_('COM_INSTALLER_HEADING_NAME'); ?>
        					</th>
        					<th class="jtable-head-row-data">
        						<?php echo JText::_('COM_INSTALLER_HEADING_INSTALLTYPE'); ?>
        					</th>
        					<th class="jtable-head-row-data">
        						<?php echo JText::_('COM_INSTALLER_HEADING_TYPE'); ?>
        					</th>
							<th class="jtable-head-row-data">
								<?php echo JText::_('COM_INSTALLER_CURRENT_VERSION'); ?>
							</th>
							<th class="jtable-head-row-data">
								<?php echo JText::_('COM_INSTALLER_NEW_VERSION'); ?>
							</th>
							<th class="jtable-head-row-data">        				
        						<?php echo JText::_('COM_INSTALLER_HEADING_FOLDER'); ?>
        					</th>
        					<th class="jtable-head-row-data">
        						<?php echo JText::_('COM_INSTALLER_HEADING_CLIENT'); ?>
        					</th>
        					<th class="jtable-head-row-data" width="25%">
        						<?php echo JText::_('COM_INSTALLER_HEADING_DETAILS_URL'); ?>
        					</th>
        				</tr>
        			</thead>
        			<tbody>
        			<?php
        				jimport( 'joomla.application.componenet.helper' );
        				$module = JComponentHelper::getComponent('com_jbusinessdirectory');
        			//var_dump($this->items);
        			foreach ($this->items as $i => $item) :
        				if($module->id!=$item->extension_id)
        					continue;
        				
        				$client = $item->client_id ? JText::_('JADMINISTRATOR') : JText::_('JSITE');
        			?>
        				<tr class="jtable-body-row" data-draggable-group="3">
        					<td class="jtable-body-row-data px-3">
								<?php echo HTMLHelper::_('jbdgrid.id', $i, $item->update_id); ?>
        					</td>
        					<td  class="jtable-body-row-data px-3">
        						<span class="editlinktip hasTooltip">
        						<?php echo $this->escape($item->name); ?>
        						</span>
        					</td>
        					<td class="jtable-body-row-data px-3">
        						<?php echo $item->extension_id ? JText::_('COM_INSTALLER_MSG_UPDATE_UPDATE') : JText::_('COM_INSTALLER_NEW_INSTALL') ?>
        					</td>
        					<td class="jtable-body-row-data px-3">
        						<?php echo JText::_('COM_INSTALLER_TYPE_' . $item->type) ?>
        					</td>
        					<td class="jtable-body-row-data px-3">
								<span class="badge bg-warning text-dark"><?php echo $item->current_version; ?></span>
							</td>
							<td class="jtable-body-row-data px-3">
								<span class="badge bg-success"><?php echo $item->version; ?></span>
							</td>
        					<td  class="jtable-body-row-data px-3">
        						<?php echo @$item->folder != '' ? $item->folder : JText::_('COM_INSTALLER_TYPE_NONAPPLICABLE'); ?>
        					</td>
        					<td  class="jtable-body-row-data px-3">
        						<?php echo $client; ?>
        					</td>
        					<td class="jtable-body-row-data px-3">
								<?php echo $item->detailsurl ?>
        						<?php if (isset($item->infourl)) : ?>
        							<br />
        							<a href="<?php echo $item->infourl; ?>" target="_blank">
        							<?php echo $this->escape($item->infourl); ?>
        							</a>
        						<?php endif; ?>
        					</td>
        				</tr>
        			<?php endforeach; ?>
        			</tbody>
        		</table>
        		<?php else : ?>
        			<div class="alert alert-info">
        				<a class="close" data-dismiss="alert" href="javascript:void(0)">&times;</a>
        				<?php echo JText::_('COM_INSTALLER_MSG_UPDATE_NOUPDATES'); ?>
        			</div>
        		<?php endif; ?>
    	</fieldset>		
    </form>
</div>