12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- class Helper{
- const METRES_TO_FEET=3.2808399;
- const KILOMETRES_TO_MILES=0.621371192;
-
- public static function TableMaker($data,$buttonText="Submit",$action="",$method="post") {
- ob_start();
- echo '<form action="',$action,'" method="',$method,'"><table>';
- foreach ($data as $datum){
- if (!isset($datum['value']))
- $datum['value']="";
- if (!isset($datum['type']))
- $datum['type']="text";
-
- $html="";
- switch ($datum['type']) {
- case "select":
- $html="<select id=\"$datum[name]\" name=\"$datum[name]\">";
- foreach ($datum['options'] as $value=>$option){
- $html.="<option value=\"$value\"";
- if ($value==$datum['value'])
- $html.="selected=\"selected\"";
- $html.=">$option</option>";
- }
- $html.="</select>";
- break;
- case "checkbox":
- $checked="";
- if ($datum['checked'])
- $checked='checked="checked"';
- $html="<input type=\"checkbox\" id=\"$datum[name]\" name=\"$datum[name]\" $checked />";
- break;
- default:
- $html="<input id=\"$datum[name]\" name=\"$datum[name]\" type=\"$datum[type]\" value=\"$datum[value]\" />";
- break;
- }
- if ($datum['type']=="hidden"){
- echo $html;
- continue;
- }
-
- echo '<tr><td><label for="',$datum['name'],'">',$datum['display'],': </label></td>',
- '<td>',$html,'</td></tr>';
- }
- echo '<tr><td></td><td><input name="submit_form" type="submit" value="',$buttonText,'" /></td></tr>',
- '</table></form>';
- return ob_get_clean();
- }
-
- public static function IsValidEmail($email){
- if( !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$email))
- return false;
- return true;
- list($userName, $mailDomain)=explode("@", $email);
- if (checkdnsrr($mailDomain,"MX"))
- return true;
- else
- return false;
- }
-
- public static function DeleteCookie($cookie){
- unset($_COOKIE[$cookie]);
- setcookie($cookie,null,-1,'/');
- }
-
- public static function GetMaxUploadString(){
- $maxUpload=(int)ini_get('upload_max_filesize');
- $maxPost=(int)ini_get('post_max_size');
- $memoryLimit=(int)ini_get('memory_limit');
- $size=min($maxUpload, $maxPost, $memoryLimit);
- return $size.'MB';
- }
- }
|