<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
global $configverssion_id; global $configapp_version; global $userID; global $server; global $LANG; $resellerID = getReseller();
//=== List page stuffs =============
$pag = $pag1 = $pag2 = $pag3 = $page = 1; $setLimit = 20;
if(isset($_GET["page"])) $page = (int)$_GET["page"];
$pageLimit = ($page * $setLimit) - $setLimit; 
if(isset($_GET["pag"])) $pag = (int)$_GET["pag"];
$pageLimit2 = ($pag * $setLimit) - $setLimit; 
if(isset($_GET["pag1"])) $pag1 = (int)$_GET["pag1"];
$pageLimit3 = ($pag1 * $setLimit) - $setLimit; 
if(isset($_GET["pag2"])) $pag2 = (int)$_GET["pag2"];
$pageLimit4 = ($pag2 * $setLimit) - $setLimit; 
if(isset($_GET["pag3"])) $pag3 = (int)$_GET["pag3"];
$pageLimit5 = ($pag3 * $setLimit) - $setLimit; 

$pageurl=$_SERVER['REQUEST_URI']."?";
if(count($_GET)) { $pageurl = $_SERVER['REQUEST_URI'].'&'; }
$trans = array("s=d_o" => "", "s=d_n" => "", "s=r_h" => "", "s=r_l" => "", "s=s_r" => "", "s=s_u" => "", "s=s_q" => "", "s=s_c" => "", "s=s_f" => "", "s=s_p" => "");
$pageurl = strtr($pageurl,$trans);
$pageurl = str_replace('&&','&',$pageurl);
//====End ==============
define('TITLE','Currencies');

if(userRole()> 1) {
	header('location: index.php');	
}

$today = date('Y-m-d'); $time = strtotime($today.'-1 months'); $lastMonth = date("Y-m", $time); $time = strtotime($today.'-1 years'); $lastYear = date("Y", $time);
?>
<?php

 if(isset($_REQUEST['dw'])) {
	$tdelete = mysqli_real_escape_string($server,$_REQUEST['dw']);
	mysqli_query($server,"DELETE FROM `currencies` WHERE id = '$tdelete' AND system = 0") or die(mysqli_error($server));
	$_SESSION['message'] = $LANG['The item(s) has been deleted from the list'];
	header('location: currency?err=0');
 }
?>
 
<div class="row no-m-t no-m-b">
	<div class="col s12 m12 l12">
            <div class="card white lighten-5">
                <div class="card-content">  
                	<div class="row no-m-t no-m-b">
                    
                     <div class="col s12 m6 l7">
                          <h5><?=$LANG['Currencies']?></h5> 
                     <?php
                    $query="SELECT * FROM currencies ORDER BY id DESC limit $pageLimit2,$setLimit";
					$result = mysqli_query($server,$query) or die(mysqli_error($server));
					$x = mysqli_num_rows($result);
                    if($x < 1) {
                    ?><table>	   
                      <div class="col s12 m12 l12">
                            <div class="card blue lighten-5">
                                <div class="card-content">
                                     <h3 class="center-align"><i class="fa fa-exclamation-circle"></i></h3>
                                     <h5 class="center-align"><?=$LANG['You have not created any currencies yet']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="date"><?=$LANG['Title']?></th>
                                <th data-field="status"><?=$LANG['Code']?></th>
                                <th data-field="rate"><?=$LANG['Rate']?> (<?=userCurrencyCode($userID)?>)</th>
                                <th data-field="act"></th>
                             </tr>
                          </thead>
                          <tbody>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						?>
                             <tr>
                                 <td><?=$rows['title']?> </td>
                                 <td><?=$rows['code']?></td>
                                 <td><?=$rows['rate']?></td>
                                 <td>
                                 <a class="hoverable blue-text" onclick="eddiCurr(<?=$rows['id']?>,'<?=$rows['title']?>','<?=$rows['code']?>','<?=$rows['rate']?>','<?=$rows['symbul']?>');" href="#"><?=$LANG['Edit']?></a>&nbsp; &nbsp;
                                 <?php if($rows['system']<1) { ?>
                                 <a class="hoverable red-text" onclick="return confirm('<?=$LANG['delete_confirm']?>');" href="currency?dw=<?=$rows['id']?>"><?=$LANG['Delete']?></a><?php } ?>
                                 </td>
                             </tr>
                       <?php } ?>   
                          </tbody>
                      </table>
                      <?php } ?>
                       <div class="col s12 m12 l12" style="margin-top: 5px;">
                          <?php displayPaginationN($setLimit,$page,$query,'i','');  ?>
                      </div>
                      <br><br>
                     </div>
                
                     <div class="col s12 m6 l5 yellow lighten-5" style="border:1px solid black">
                          <form action="" method="post" id="credit-form" onSubmit="return false;">
                          	<h5 id="titc"><?=$LANG['Add Currency']?></h5> 

                           <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="title" type="text" required class="validate" >
                                       <label class="active" for="title"><?=$LANG['Title']?></label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="code" type="text" required class="validate" >
                                       <label class="active" for="code"><?=$LANG['Currency Code']?></label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="symbul" type="text" required class="validate">
                                       <label class="active" for="symbul"><?=$LANG['Symbol']?> </label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="rate" type="text" required class="validate" >
                                       <label class="active" for="rate"><?=$LANG['Exchange Rate']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                           <div class="card-action">
                           		<input type="hidden" value="0" id="currency_id">
                                <button id="curren-button" class="btn green darken-4" type="submit"><?=$LANG['Save Currency']?> </button>
                                <span id="curren-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                                <button id="rtes-button" class="btn red darken-4" type="reset"><?=$LANG['Cancel']?> </button>
                           </div>
                        </form>
                     </div>
                     
				</div>                
            </div>  
         </div>     
	</div>
</div>