bills.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <center>
  2. <table width="690px" cellspacing="0px" cellpadding="0px">
  3. <tr bgcolor="#000000"><td width="250" align="center" valign="center">
  4. <?
  5. //protection!!
  6. $uname = htmlspecialchars($_REQUEST['uname']);
  7. //include ("function_stuff.php");
  8. if($uname!='' && strcmp($uname,'Username')){
  9. /* check via DB if such a user exists */
  10. exec('echo -e "login='.trim($uname).'\nvalues=uid" | ' . UMS_UTILS_PATH . UMS_UTILS['user_info'],$output,$err);
  11. /* if user exists and money are in the right format */
  12. if($err==0 && ereg("^([0-9])+$",trim($_REQUEST['hrn'])) && ereg("^([0-9])+$",trim($_REQUEST['kop']))){
  13. /* get uid by username */
  14. foreach($output as $string){$userid_current = substr(trim($string),4);}
  15. /* convert money to copeks */
  16. $money = $_REQUEST['hrn']*100 + $_REQUEST['kop'];
  17. connect_to_DB();
  18. /* check if such a user exists in mySQL DB */
  19. $query = "SELECT userid FROM users WHERE userid='".$userid_current."'";
  20. $res = mysql_query($query);
  21. /* if not - add user && add money to his account*/
  22. if(mysql_num_rows($res)!=1) {
  23. mysql_query("INSERT INTO users(userid,bill) VALUES('".$userid_current."','".$money."')");
  24. }else{
  25. /* if exists - update his account*/
  26. $res= mysql_query("SELECT bill FROM users WHERE userid='".$userid_current."'");
  27. while($row = mysql_fetch_array($res)) $bill = $row['bill'];
  28. mysql_query("UPDATE users SET bill=".($bill+$money)." WHERE userid='".$userid_current."'");
  29. }
  30. close_connection();
  31. /* show user's acount state */?>
  32. <table>
  33. <tr align="left">
  34. <td>
  35. <font face="helvetica" color="#ffffff" size="4"><? echo $uname ?></font>
  36. <br><font face="helvetica" color="#33CC00" size="4"><? echo echo_price($bill+$money)?></font>
  37. </td>
  38. </tr>
  39. </table>
  40. <?} else { ?><font color="#ffffff" face="helvetica"><?echo "Invalid data";?></font><?}
  41. }?>
  42. </td>
  43. <td align="left">
  44. <form method="POST" action=<?echo $_SERVER['PHP_SELF'];?> >
  45. <input type="hidden" name="userid" value=<?echo $_REQUEST['userid'];?>>
  46. <table cellspacing=0 cellpadding=0>
  47. <tr bgcolor="#000000" height="30px">
  48. <td width="30px"></td>
  49. <td align="left">
  50. <input type="text" size=17 maxlength=17 value="Username" name="uname" style="width:130px; font-family:helvetica; font-size:14"
  51. onclick="if(this.value=='Username') this.value=''" onblur="if(this.value=='') this.value='Username'">
  52. </td>
  53. </tr>
  54. <tr bgcolor="#000000" height="30px">
  55. <td width="30px"><font face="helvetica" color="#ff8000">+</font></td>
  56. <td align="left"><font face="helvetica" color="#ff8000">
  57. <input type="text" size=2 maxlength=2 value="00" name="hrn" style="font-family:helvetica; font-size:14; text-align:right"
  58. onclick="if(this.value=='0' || this.value=='00') this.value=''" onblur="if(this.value=='') this.value='00'"> грн.
  59. <input type="text" size=2 maxlength=2 value="00" name="kop" style="font-family:helvetica; font-size:14; text-align:right"
  60. onclick="if(this.value=='0' || this.value=='00') this.value=''" onblur="if(this.value=='') this.value='00'"> коп.
  61. </font></td>
  62. </tr>
  63. <tr bgcolor="#000000" height="30px">
  64. <td width="30px"></td>
  65. <td align="left"><input type="submit" name="manage_bills_x" style="background-color:#ff8000; width:130px; font-family:helvetica; font-size:14" value='submit'></td>
  66. </tr>
  67. </table>
  68. </form>
  69. </td></tr>