<?php 
/*===================================================+ 
|| # HoloCMS - Website and Content Management System 
|+===================================================+ 
|| # Copyright © 2008 Meth0d. All rights reserved. 
|| # http://www.meth0d.org 
|+===================================================+ 
|| # HoloCMS is provided "as is" and comes without 
|| # warrenty of any kind. HoloCMS is free software! 
|+===================================================*/ 

require_once('../global.php'); 
if($hkzone !== true){ header("Location: index.php?throwBack=true"); exit; } 
if(!session_is_registered(acp)){ header("Location: index.php?p=login"); exit; } 

$pagename = "Vouchers"; 

if(isset($_POST['voucher'])){ 

    if(!empty($_POST['voucher']) && !empty($_POST['credits'])){ 


            mysql_query("INSERT INTO credit_vouchers (code,type,value) VALUES ('".Filter($_POST['voucher'])."','".$_POST['type']."','".$_POST['credits']."')") or die(mysql_error()); 
            $msg = "Le code à était crée.."; 

            mysql_query("INSERT INTO system_stafflog (action,message,note,userid,targetid,timestamp) VALUES ('Housekeeping','Created voucher ".Filter($_POST['voucher'])." worth ".Filter($_POST['credits'])." credits','vouchers.php','".$my_id."','','".$date_full."')") or die(mysql_error()); 

        } 
    } else { 

        $msg = "S'il vous plaît ne laissez pas de champs vides."; 

    } 


require_once('subheader.php'); 
require_once('header.php'); 
?> 
<table cellpadding='0' cellspacing='8' width='100%' id='tablewrap'> 
<tr> <td width='22%' valign='top' id='leftblock'> 
 <div> 
 <!-- LEFT CONTEXT SENSITIVE MENU --> 
<?php require_once('usermenu.php'); ?> 
 <!-- / LEFT CONTEXT SENSITIVE MENU --> 
 </div> 
 </td> 
 <td width='78%' valign='top' id='rightblock'> 
 <div><!-- RIGHT CONTENT BLOCK --> 
  
<?php if(isset($msg)){ ?><p><strong><?php echo $msg; ?></p></strong><?php } ?> 
  
<form action='index.php?p=vouchers&do=create' method='post' name='theAdminForm' id='theAdminForm'> 
<div class='tableborder'> 
<div class='tableheaderalt'>Crée un Code crédits</div> 

<?php
function randomVoucher($code) {
$characters = "1234567890abdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$key = $characters{rand(0,71)};
for($i=1;$i<$code;$i++)
	{
		$key .= $characters{rand(0,71)};
	}
	return $key;
}

?>

<table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'> 
<tr> 
<td class='tablerow1'  width='40%'  valign='middle'><strong>Code de reduction</strong><div class='graytext'>Le code de bon que l'utilisateur doit saisir pour recevoir les crédits.</div></td> 
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='voucher' value="<?php echo randomVoucher(8); ?>" size='30' class='textinput'></td> 
</tr> 

<tr> 
<td class='tablerow1'  width='40%'  valign='middle'><strong>Type</strong><div class='graytext'> 
 Le type de coupon qui peut être racheté, il ya deux options; crédits ou
     Item, les crédits seront un bon de crédit normale, point sera un meuble
     coupon de remboursement.</div></td> 
<td class='tablerow2'  width='60%'  valign='middle'><select size='1' name='type'> 
<option value='credits'>Credits</option> 
<!--<option value='item'>Item</option> -->
</select></td> 
</tr> 

<tr> 
<td class='tablerow1'  width='40%'  valign='middle'><strong>Montant</strong><div class='graytext'>Le montant des crédits / item un utilisateur recevra en entrant le code de rachat. Pour les achats d'intrants article l'article correct 
    CCT name.</div></td> 
<td class='tablerow2'  width='60%'  valign='middle'><input type='text' name='credits' value="" size='30' class='textinput'></td> 
</tr> 

<tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Crée le Code!' class='realbutton' accesskey='s'></td></tr> 
</form></table></div><br /> 

<?php 
$get_vouchers = mysql_query("SELECT * FROM credit_vouchers") or die(mysql_error()); 
?> 

 <div class='tableborder'> 
 <div class='tableheaderalt'>Bons existants</div> 
 <table cellpadding='4' cellspacing='0' width='100%'> 
 <tr> 
  <td class='tablesubheader' width='60%' align='center'>Code</td> 
  <td class='tablesubheader' width='40%' align='center'>Credits</td> 
 </tr> 
<?php 

while($row = mysql_fetch_assoc($get_vouchers)){ 
    printf(" <tr> 
  <td class='tablerow1' align='center'>%s</td> 
  <td class='tablerow2' align='center'>%s</td> 
</tr>", $row['code'], $row['value']); 
} 
?> 
  
 </table> 
</div> 
     </div><!-- / RIGHT CONTENT BLOCK --> 
     </td></tr> 
</table> 
</div><!-- / OUTERDIV --> 
<div align='center'><br /> 
<?php 
$mtime = explode(' ', microtime()); 
$totaltime = $mtime[0] + $mtime[1] - $starttime; 
printf('Time: %.3f', $totaltime); 
?> 
</div> 