Here’s how the form Looks :
<form action=“<?php echo url(‘/Profile’);?>” method=“post” class=“form-horizontal form-bordered”>
<div class=“form-group”>
<label class=“col-xs-3 control-label” for=“material-text2”>First Name</label>
<div class=“col-xs-9”>
<input class=“form-control” type=“text” id=“material-text2” name=“material-text2” placeholder=“<?php echo $pilot->firstname;?>” /disabled>
</div>
</div>
<div class=“form-group”>
<label class=“col-xs-3 control-label” for=“material-text2”>Last Name</label>
<div class=“col-xs-9”>
<input class=“form-control” type=“text” id=“material-text2” name=“material-text2” placeholder=“<?php echo $pilot->lastname;?>” /disabled>
<span class=“text-muted”><small>You cannot change your Name. If you need to change name, open a <a href=“<?php echo SITE_URL?>/index.php/helpdesk”>support ticket</a>.</small></span>
</div>
</div>
<div class=“form-group”>
<label class=“col-xs-3 control-label” for=“material-text2”>Hub</label>
<div class=“col-xs-9”>
<input class=“form-control” type=“text” id=“material-text2” name=“material-text2” placeholder=“<?php echo $pilot->hub;?>” /disabled>
<span class=“text-muted”><small>To change your Operating Hub, you need to open a ticket at <a href=“<?php echo SITE_URL?>/index.php/hubtransfer”>Hub Transfer </a>system.</small></span>
</div>
</div>
<div class=“form-group”>
<label class=“col-xs-3 control-label” for=“email”>Email</label>
<div class=“col-xs-9”>
<input class=“form-control” type=“text” id=“email” name=“email” value=“<?php echo $pilot->email;?>” placeholder="[email protected]">
<span class=“text-muted”><small>All e-mails regarding Flight operations and Human resources will be sent to this email ID.</small></span>
</div>
</div>
<div class=“form-group”>
<label class=“col-xs-3 control-label” for=“livestream”>Live Stream ID</label>
<div class=“col-xs-9”>
<input type=“livestream” name=“livestream” class=“form-control” value=“<?php echo $pilot->livestream;?>” placeholder=“Twitch”>
<span class=“text-muted”><small>Enter your Twitch User ID, *NOT* the URL</small></span>
</div>
</div>
<div class=“form-group”>
<label class=“col-xs-3 control-label” for=“location”>Country</label>
<div class=“col-xs-9”>
<select class=“form-control select-chosen” id=“location” name=“location” style=“width: 100%;” data-placeholder=“Choose one..”>
<?php
foreach($countries as $countryCode=>$countryName)
{
if($pilot->location == $countryCode)
$sel = ‘selected=“selected”’;
else
$sel = ‘’;
echo ‘<option value="’.$countryCode.‘" ‘.$sel.’>’.$countryName.‘</option>’;
}
?>
</select>
</div>
</div>
<div class=“form-group form-actions”>
<div class=“col-xs-9 col-xs-offset-3”>
<input type=“hidden” name=“action” value=“saveprofile” />
<input class=“btn btn-sm btn-primary” type=“submit” name=“submit” value=“Save Changes” />
</div>
</div>
</form>
Here’s how the Module Looks :
P.s Since my site is on maintenance now, i’ve made it to work only for the Admins.
<?php
class Profile extends CodonModule
{
/**
* Profile::index()
*
* @return
*/
public function index()
{
//remove after migration
if(PilotGroups::group_has_perm(Auth::$usergroups, ACCESS_ADMIN))
{
if(!Auth::LoggedIn()) {
$this->render(‘login_form.php’); //
return;
}
else
{
$this->render(‘profile_main.php’); //
}
}
if(!Auth::LoggedIn()) {
$this->render(‘Maintenance/index.php’); // login_form.php
return;
}
/*
* This is from /profile/editprofile
*/
if(isset($this->post->action)) {
if($this->post->action == ‘saveprofile’) {
$this->save_profile_post();
}
/* this comes from /profile/changepassword
*/
if($this->post->action == ‘changepassword’) {
$this->change_password_post();
}
}
$pilot = PilotData::getPilotData(Auth::$pilot->pilotid);
if(Config::Get(‘TRANSFER_HOURS_IN_RANKS’) == true) {
$totalhours = $pilot->totalhours + $pilot->transferhours;
} else {
$totalhours = $pilot->totalhours;
}
$this->set(‘pilotcode’, PilotData::getPilotCode($pilot->code, $pilot->pilotid));
$this->set(‘report’, PIREPData::getLastReports($pilot->pilotid));
$this->set(‘nextrank’, RanksData::getNextRank($totalhours));
$this->set(‘allawards’, AwardsData::getPilotAwards($pilot->pilotid));
$this->set(‘userinfo’, $pilot);
$this->set(‘pilot’, $pilot);
$this->set(‘pilot_hours’, $totalhours);
$this->render(‘Maintenance/index.php’); // profile_main.php
// CodonEvent::Dispatch(‘profile_viewed’, ‘Profile’);
}
public function viewbids() {
if ($this->post->action == ‘deletebid’) {
$ret = SchedulesData::RemoveBid($this->post->id);
$params = array();
if ($ret == true) {
$params[‘status’] = ‘ok’;
} else {
$params[‘status’] = ‘There was an error’;
$params[‘message’] = DB::error();
}
echo json_encode($params);
return;
}
$this->set(‘allbids’, SchedulesData::getAllBids());
$this->render(‘pilots_viewallbids.php’);
}
/**
* This is the public profile for the pilot
*/
/**
* Profile::view()
*
* @param string $pilotid
* @return
*/
public function view($pilotid=‘’)
{
#replacement for OFC charts - Google Charts API - simpilot
$this->set(‘chart_url’, ChartsData::build_pireptable(PilotData::parsePilotID($pilotid), 30));
#end
$pilotid = PilotData::parsePilotID($pilotid);
$pilot = PilotData::getPilotData($pilotid);
$this->title = 'Profile of ‘.$pilot->firstname.’ '.$pilot->lastname;
$this->set(‘userinfo’, $pilot);
$this->set(‘pilot’, $pilot);
$this->set(‘allfields’, PilotData::getFieldData($pilotid, false));
$pirep_list = PIREPData::getAllReportsForPilot($pilotid);
$this->set(‘pireps’, $pirep_list);
$this->set(‘pirep_list’, $pirep_list);
$this->set(‘pilotcode’, PilotData::getPilotCode($pilot->code, $pilot->pilotid));
$this->set(‘allawards’, AwardsData::getPilotAwards($pilot->pilotid));
$this->render(‘pilot_public_profile.php’);
}
/**
* Profile::stats()
*
* @return
*/
public function stats()
{
if(!Auth::LoggedIn()) {
$this->set(‘message’, ‘Oops, You must be logged in to access this feature!’);
$this->render(‘core_error.php’);
return;
}
$this->set(‘pilot’, Auth::$pilot);
$this->render(‘profile_stats.php’);
}
/**
* Profile::badge()
*
* @return
*/
public function badge()
{
$this->set(‘badge_url’, fileurl(SIGNATURE_PATH.‘/’.PilotData::GetPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid).‘.png’));
$this->set(‘pilotcode’, PilotData::getPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid));
$this->render(‘profile_badge.php’);
}
/**
* Profile::editprofile()
*
* @return
*/
public function editprofile()
{
if(!Auth::LoggedIn()) {
$this->set(‘message’, ‘You must be logged in to access this feature!’);
$this->render(‘core_error.php’);
return;
}
$this->set(‘userinfo’, Auth::$pilot);
$this->set(‘pilot’, Auth::$pilot);
$this->set(‘customfields’, PilotData::getFieldData(Auth::$pilotid, true));
$this->set(‘bgimages’, PilotData::getBackgroundImages());
$this->set(‘countries’, Countries::getAllCountries());
$this->set(‘pilotcode’, PilotData::getPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid));
$this->render(‘profile_edit.php’);
}
/**
* Profile::changepassword()
*
* @return
*/
public function changepassword()
{
if(!Auth::LoggedIn()) {
$this->set(‘message’, ‘You must be logged in to access this feature!’);
$this->render(‘core_error.php’);
return;
}
$this->render(‘profile_changepassword.php’);
}
/**
* Profile::save_profile_post()
*
* @return
*/
protected function save_profile_post()
{
$pilot = Auth::$pilot;
//TODO: check email validity
if($this->post->email == ‘’) {
$this->set(‘message’, ‘The email address cannot be blank.’);
$this->render(‘core_error.php’);
return;
}
$fields = RegistrationData::getCustomFields();
if(count($fields) > 0) {
foreach ($fields as $field) {
$value = Vars::POST($field->fieldname);
$value1 = DB::escape($value);
if ($field->required == 1 && $value1 == ‘’) {
$this->set(‘message’, ‘’.$field->title.’ cannot be blank!');
$this->render(‘core_error.php’);
return;
}
}
}
$params = array(
‘code’ => $pilot->code,
‘email’ => $this->post->email,
‘location’ => $this->post->location,
‘avatar’ => $this->post->avatar,
‘hub’ => $pilot->hub,
‘bgimage’ => $this->post->bgimage,
‘retired’ => false
);
PilotData::updateProfile($pilot->pilotid, $params);
PilotData::SaveFields($pilot->pilotid, $_POST);
# Generate a fresh signature
PilotData::GenerateSignature($pilot->pilotid);
PilotData::SaveAvatar($pilot->code, $pilot->pilotid, $_FILES);
$this->set(‘message’, ‘Profile Saved!’);
$this->render(‘core_success.php’);
}
/**
* Profile::change_password_post()
*
* @return
*/
protected function change_password_post()
{
if(!Auth::LoggedIn()) {
$this->set(‘message’, ‘You must be logged in to access this feature!’);
$this->render(‘core_error.php’);
return;
}
// Verify
if($this->post->oldpassword == ‘’) {
$this->set(‘message’, ‘You must enter your current password’);
$this->render(‘core_error.php’);
return;
}
if($this->post->password1 != $this->post->password2) {
$this->set(‘message’, ‘Your passwords do not match’);
$this->render(‘core_error.php’);
return;
}
// Change
$hash = md5($this->post->oldpassword . Auth::$pilot->salt);
if($hash == Auth::$pilot->password) {
RegistrationData::ChangePassword(Auth::$pilotid, $_POST[‘password1’]);
$this->set(‘message’, ‘Your password has been reset’);
} else {
$this->set(‘message’, ‘You entered an invalid password’);
}
$this->render(‘core_success.php’);
}
}