<?php 
include 'check.php';
include '../db.inc.php';
include 'check_msg.php';
$ac=$_GET['user'];
$sql="SELECT * FROM users WHERE number='$ac'";
$query=mysqli_query($connectionString,$sql);
$get=mysqli_fetch_array($query,MYSQLI_ASSOC);
if(isset($_POST['submit'])) {
	$firstname=addslashes($_POST['firstname']);
	$lastname=addslashes($_POST['lastname']);
	$dob=addslashes($_POST['dob']);
	$gender=addslashes($_POST['gender']);
	$address=addslashes($_POST['address']);
	$city=addslashes($_POST['city']);
	$state=addslashes($_POST['state']);
	$zip=addslashes($_POST['zip']);
	$country=addslashes($_POST['country']);
	$email=addslashes($_POST['email']);
	$phone=addslashes($_POST['phone']);
	$fax=addslashes($_POST['fax']);
	$occupation=addslashes($_POST['occupation']);
	$type=addslashes($_POST['type']);
	$currency=addslashes($_POST['currency']);
	$error_msg="";
	if(strlen($firstname)==0) {
		$error_msg.="<li>First name is empty</li>";
	}
	if(strlen($lastname)==0) {
		$error_msg.="<li>Last name is empty</li>";
	}
	if(strlen($gender)==0) {
		$error_msg.="<li>You didn't select your gender</li>";
	}
	if(strlen($address)==0) {
		$error_msg.="<li>Address is empty</li>";
	}
	if(strlen($city)==0) {
		$error_msg.="<li>City is empty</li>";
	}
	if(strlen($state)==0) {
		$error_msg.="<li>State is empty</li>";
	}
	if(strlen($zip)==0) {
		$error_msg.="<li>Zip is empty</li>";
	}
	if(strlen($email)==0) {
		$error_msg.="<li>Email is empty</li>";
	}
	elseif (! preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email)) {
		$error_msg.="<li>Email is invalid</li>";
	}
	if(strlen($phone)==0) {
		$error_msg.="<li>Phone is empty</li>";
	}
	if(strlen($occupation)==0) {
		$error_msg.="<li>Occupation is empty</li>";
	}
	if(strlen($type)==0) {
		$error_msg.="<li>You didn't select account type</li>";
	}
	if(strlen($currency)==0) {
		$error_msg.="<li>You didn't select Currency</li>";
	}
	if($error_msg != "") {
		$error_msg="Please correct the following errors".$error_msg;
	}
	else {
		$accnum=rand(1000000000,9999999999);
		$pass=substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),0,10);
		$pin=rand(10000,99999);

		if(!mysqli_query($connectionString,"INSERT INTO `users` (`number` ,`password` ,`pin` ,`firstname` ,`lastname` ,`dob` ,`gender` ,`address` ,`city` ,`state` ,`zip` ,`country` ,`phone` ,`email` ,`occupation` ,`type` ,`currency` ,`lastlogin` ,`status` ,`balance` ,`balance2`)VALUES ('$accnum', '$pass', '$pin', '$firstname', '$lastname', '$dob', '$gender', '$address', '$city', '$state', '$zip', '$country', '$phone', '$email', '$occupation', '$type', '$currency', '0000-00-00 00:00:00', 'Inactive', '0', '0')")) {
		
			echo("Error description: " . mysqli_error($connectionString));exit;
		};
		
		if(is_uploaded_file($_FILES['picture']['tmp_name'])) {
			$tmpName = addslashes(fread(fopen($_FILES['picture']['tmp_name'],"r"),
			filesize($_FILES['picture']['tmp_name'])));
			$type = $_FILES['picture']['type'];
			$size = $_FILES['picture']['size'];
			if(($type != "image/gif") && ($type != "image/jpeg") && ($type != "image/pjpeg")) {
				$error_msg.="<li>Picture must be in gif or jpeg format only</li>";
			}
			elseif($size > 500000){
				$error_msg.="<li>Picture must not be over 500"."kb in size</li>";
			}
	
			else {
				mysqli_query($connectionString,"UPDATE users SET picture='$tmpName' WHERE number='$accnum' LIMIT 1");
			}
		}
	}
	if($error_msg == "") {
?>
		<script>
		alert('Account successfully created \nAccount number is <?php echo $accnum; ?>');
		location.replace('./');
		</script>
<?php
		exit;
	}
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Administrator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="96%" height="421" border="0" cellspacing="5">
  <tr>
    <td width="14%" height="274" valign="top" style="border:#003399 1px solid;"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="21" bgcolor="#004500" class="headers">Navigation</td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="1">
          <tr>
            <td bgcolor="#E8FFF8"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="./">Home</a></strong></font></p></td>
          </tr>
           <tr>
            <td bgcolor="#E8FFF8"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="smssender.php">SMS 
              Sender</a></strong></font></p></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="addact.php">Add Activity </a></strong></font></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="viewact.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>View Activities </strong></font></a></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="messages.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>View Messages (<?php echo $umsg; ?>)</strong></font></a></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="alerts.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>View Alerts</strong></font></a></td>
          </tr>
          
          <tr>
            <td bgcolor="#E8FFF8"><a href="sql.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>SQL</strong></font></a></td>
          </tr>
		  
          <tr>
            <td bgcolor="#E8FFF8"><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="logout.php">Log 
              Out</a></strong></font></td>
          </tr>
        </table>
        <p>&nbsp;</p>
          </td>
      </tr>
    </table>      
      <p>&nbsp;</p>
    </td>
    <td width="86%" valign="top" style="border:#003399 1px solid;"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="21" bgcolor="#004500" class="headers">Create Account </td>
      </tr>
      <tr>
        <td><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
                  <table width="100%" border="0" cellspacing="1">
                    <tr>
                      <td colspan="2" bgcolor="#E8FFF8" class="error_msg"><?php echo $error_msg; ?></td>
                    </tr>
                    <tr>
                      <td width="12%" bgcolor="#E8FFF8">First Name </td>
                      <td width="88%" bgcolor="#E8FFF8"><input name="firstname" type="text" id="firstname" value="<?php echo $_POST['firstname']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">Last Name </td>
                      <td bgcolor="#E8FFF8"><input name="lastname" type="text" id="lastname" value="<?php echo $_POST['lastname']; ?>" /></td>
                    </tr>
					<tr>
                      <td bgcolor="#E8FFF8">Date of Birth </td>
                      <td bgcolor="#E8FFF8"><input name="dob" type="date" id="dob" value="<?php echo $_POST['dob']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">Gender</td>
                      <td bgcolor="#E8FFF8"><input name="gender" type="radio" value="Male" id="radio" <?php if ($_POST['gender'] == "Male"): ?> checked <?php endif; ?> />
                        Male 
                        <input name="gender" type="radio" value="Female" id="radio" <?php if ($_POST['gender'] == "Female"): ?> checked<?php endif; ?> /> 
                      Female </td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">Address</td>
                      <td bgcolor="#E8FFF8"><input name="address" type="text" id="address" value="<?php echo $_POST['address']; ?>" size="50" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">City</td>
                      <td bgcolor="#E8FFF8"><input name="city" type="text" id="city" value="<?php echo $_POST['city']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">State</td>
                      <td bgcolor="#E8FFF8"><input name="state" type="text" id="state" value="<?php echo $_POST['state']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">ZIP</td>
                      <td bgcolor="#E8FFF8"><input name="zip" type="text" id="zip" value="<?php echo $_POST['zip']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">Country</td>
                      <td bgcolor="#E8FFF8"><input name="country" type="text" id="bcountry" value="<?php echo $_POST['country']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">Email</td>
                      <td bgcolor="#E8FFF8"><input name="email" type="text" id="email" value="<?php echo $_POST['email']; ?>" /></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8FFF8">Phone</td>
                      <td bgcolor="#E8FFF8"><input name="phone" type="text" id="phone" value="<?php echo $_POST['phone']; ?>" /></td>
                    </tr>

					<tr>
                      <td bgcolor="#E8FFF8">Occupation</td>
                      <td bgcolor="#E8FFF8"><input name="occupation" type="text" id="occupation" value="<?php echo $_POST['occupation']; ?>" /></td>
                    </tr>
					<tr>
					  <td bgcolor="#E8FFF8">Account Type </td>
					  <td bgcolor="#E8FFF8"><select name="type" id="type">
					    <option value="">--Select--</option>
						<option value="eBusiness" <?php if ($_POST['type'] == "eBusiness"): ?> selected <?php endif; ?>>eBusiness</option>
					    <option value="Current" <?php if ($_POST['type'] == "Current"): ?> selected <?php endif; ?>> Business Current</option>
					    <option value="Savings" <?php if ($_POST['type'] == "Business Savings"): ?> selected <?php endif; ?>> Business Savings</option>
						<option value="Business Plus" <?php if ($_POST['type'] == "Business Plus"): ?> selected <?php endif; ?>>Business Plus</option>
					    </select>					  </td>
				    </tr>
					<tr>
					  <td bgcolor="#E8FFF8">Currency </td>
					  <td bgcolor="#E8FFF8"><select name="currency" id="currency">
					    <option value="">--Select--</option>
						<option value="&pound;" <?php if ($_POST['currency'] == "&pound;"): ?> selected <?php endif; ?>>Pounds Sterling</option>
					    <option value="&#x24;" <?php if ($_POST['currency'] == "&#x24;"): ?> selected <?php endif; ?>>US Dollars</option>
					    <option value="&euro;" <?php if ($_POST['currency'] == "&euro;"): ?> selected <?php endif; ?>>Euro</option>
						<option value="&yen;" <?php if ($_POST['currency'] == "&yen;"): ?> selected <?php endif; ?>>Yen</option>
						<option value="&#8377;" <?php if ($_POST['currency'] == "&#8377;"): ?> selected <?php endif; ?>>Indian Rupee</option>
					    <option value="&#8381;" <?php if ($_POST['currency'] == "&#8381;"): ?> selected <?php endif; ?>>Russian Rubble</option>
						<option value="&#20803;" <?php if ($_POST['currency'] == "&#20803;"): ?> selected <?php endif; ?>>Chinese Yuan</option>
					    </select>					  </td>
				    </tr>
					  <tr>
                      <td bgcolor="#E8FFF8">Picture</td>
                      <td bgcolor="#E8FFF8"><input name="picture" type="file" id="picture"></td>
					  </tr>

					  <tr>
                      <td bgcolor="#E8FFF8">&nbsp;</td>
                      <td bgcolor="#E8FFF8"><input name="submit" type="submit" id="submit" value="Save" />
                        <input name="Reset" type="reset" value="Reset" /></td>
					  </tr>
              </table>
              </form></td>
      </tr>
    </table>      
    </td>
  </tr>
</table>


</body>
</html>
