Helper.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. class Helper{
  3. const METRES_TO_FEET=3.2808399;
  4. const KILOMETRES_TO_MILES=0.621371192;
  5. public static function TableMaker($data,$buttonText="Submit",$action="",$method="post") {
  6. ob_start();
  7. echo '<form action="',$action,'" method="',$method,'"><table>';
  8. foreach ($data as $datum){
  9. if (!isset($datum['value']))
  10. $datum['value']="";
  11. if (!isset($datum['type']))
  12. $datum['type']="text";
  13. $html="";
  14. switch ($datum['type']) {
  15. case "select":
  16. $html="<select id=\"$datum[name]\" name=\"$datum[name]\">";
  17. foreach ($datum['options'] as $value=>$option){
  18. $html.="<option value=\"$value\"";
  19. if ($value==$datum['value'])
  20. $html.="selected=\"selected\"";
  21. $html.=">$option</option>";
  22. }
  23. $html.="</select>";
  24. break;
  25. case "checkbox":
  26. $checked="";
  27. if ($datum['checked'])
  28. $checked='checked="checked"';
  29. $html="<input type=\"checkbox\" id=\"$datum[name]\" name=\"$datum[name]\" $checked />";
  30. break;
  31. default:
  32. $html="<input id=\"$datum[name]\" name=\"$datum[name]\" type=\"$datum[type]\" value=\"$datum[value]\" />";
  33. break;
  34. }
  35. if ($datum['type']=="hidden"){
  36. echo $html;
  37. continue;
  38. }
  39. echo '<tr><td><label for="',$datum['name'],'">',$datum['display'],': </label></td>',
  40. '<td>',$html,'</td></tr>';
  41. }
  42. echo '<tr><td></td><td><input name="submit_form" type="submit" value="',$buttonText,'" /></td></tr>',
  43. '</table></form>';
  44. return ob_get_clean();
  45. }
  46. public static function IsValidEmail($email){
  47. if( !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$email))
  48. return false;
  49. return true;
  50. list($userName, $mailDomain)=explode("@", $email);
  51. if (checkdnsrr($mailDomain,"MX"))
  52. return true;
  53. else
  54. return false;
  55. }
  56. public static function DeleteCookie($cookie){
  57. unset($_COOKIE[$cookie]);
  58. setcookie($cookie,null,-1,'/');
  59. }
  60. public static function GetMaxUploadString(){
  61. $maxUpload=(int)ini_get('upload_max_filesize');
  62. $maxPost=(int)ini_get('post_max_size');
  63. $memoryLimit=(int)ini_get('memory_limit');
  64. $size=min($maxUpload, $maxPost, $memoryLimit);
  65. return $size.'MB';
  66. }
  67. }