예제 #1
0
 /**
  * Add a  User
  * 
  * $data = array(
  * 'firstname' => '',
  * 'lastname' => '',
  * 'email' => '',
  * 'password' => '',
  * 'code' => '',
  * 'location' => '',
  * 'hub' => '',
  * 'confirm' => false);
  */
 public static function addUser($data)
 {
     /*$data = array(
       'firstname' => '',
       'lastname' => '',
       'email' => '',
       'password' => '',
       'code' => '',
       'location' => '',
       'hub' => '',
       'confirm' => false);*/
     $exists = self::CheckUserEmail($data['email']);
     if (is_object($exists)) {
         self::$error = 'Email already exists';
         return false;
     }
     //Set the password, add some salt
     $salt = md5(date('His'));
     $password = md5($data['password'] . $salt);
     //Stuff it into here, the confirmation email will use it.
     self::$salt = $salt;
     $code = DB::escape(strtoupper($data['code']));
     $firstname = DB::escape(ucwords($data['firstname']));
     $lastname = DB::escape(ucwords($data['lastname']));
     $location = DB::escape(strtoupper($data['location']));
     //Add this stuff in
     if ($data['confirm'] === true) {
         $confirm = 1;
     } else {
         $confirm = 0;
     }
     $sql = "INSERT INTO " . TABLE_PREFIX . "pilots (firstname, lastname, email,\n\t\t\t\t\tcode, location, hub, password, salt, confirmed, joindate, lastip)\n\t\t\t\t  VALUES ('{$firstname}', '{$lastname}', '{$data['email']}', '{$code}',\n\t\t\t\t\t\t\t'{$location}', '{$data['hub']}', '{$password}', '{$salt}', {$confirm}, NOW(), '{$_SERVER['REMOTE_ADDR']}')";
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         if (DB::errno() == 1062) {
             self::$error = 'This email address is already registered';
             return false;
         }
         self::$error = DB::error();
         return false;
     }
     //Grab the new pilotid, we need it to insert those "custom fields"
     $pilotid = DB::$insert_id;
     RanksData::CalculateUpdatePilotRank($pilotid);
     PilotData::GenerateSignature($pilotid);
     /* Add them to the default group */
     $defaultGroup = SettingsData::getSettingValue('DEFAULT_GROUP');
     PilotGroups::addUsertoGroup($pilotid, $defaultGroup);
     // For later
     self::$pilotid = $pilotid;
     //Get customs fields
     $fields = self::GetCustomFields();
     if (!$fields) {
         return true;
     }
     foreach ($fields as $field) {
         $value = Vars::POST($field->fieldname);
         $value = DB::escape($value);
         if ($value != '') {
             $sql = "INSERT INTO " . TABLE_PREFIX . "fieldvalues (fieldid, pilotid, value)\n\t\t\t\t\t\t\tVALUES ({$field->fieldid}, {$pilotid}, '{$value}')";
             DB::query($sql);
         }
     }
     return true;
 }
	<dt><?php 
        echo $field->title;
        ?>
</dt>
	<dd>
	<?php 
        if ($field->type == 'dropdown') {
            echo "<select name=\"{$field->fieldname}\">";
            $values = explode(',', $field->value);
            if (is_array($values)) {
                foreach ($values as $val) {
                    $val = trim($val);
                    echo "<option value=\"{$val}\">{$val}</option>";
                }
            }
            echo '</select>';
        } elseif ($field->type == 'textarea') {
            echo '<textarea name="' . $field->fieldname . '" class="customfield_textarea"></textarea>';
        } else {
            ?>
            <input type="text" name="<?php 
            echo $field->fieldname;
            ?>
" value="<?php 
            echo Vars::POST($field->fieldname);
            ?>
" /></dd>
<?php 
        }
    }
}
	<dt>Hub: *</dt>
	<dd>
		<select name="hub" id="hub">
		<?php 
foreach ($hub_list as $hub) {
    echo '<option value="' . $hub->icao . '">' . $hub->icao . ' - ' . $hub->name . '</option>';
}
?>
		</select>
	</dd>

	<dt>Location: *</dt>
	<dd><select name="location">
		<?php 
foreach ($country_list as $countryCode => $countryName) {
    if (Vars::POST('location') == $countryCode) {
        $sel = 'selected="selected"';
    } else {
        $sel = '';
    }
    echo '<option value="' . $countryCode . '" ' . $sel . '>' . $countryName . '</option>';
}
?>
		</select>
		<?php 
if ($location_error == true) {
    echo '<p class="error">Please enter your location</p>';
}
?>
	</dd>