예제 #1
0
 public function savepro()
 {
     if ($this->post->firstname == '' || $this->post->lastname == '') {
         $this->set('message', 'The first or lastname cannot be blank!');
         $this->render('core_error.tpl');
         return;
     }
     $params = array('firstname' => $this->post->firstname, 'lastname' => $this->post->lastname, 'email' => $this->post->email, 'hub' => $this->post->hub, 'retired' => $this->post->retired, 'totalflights' => $this->post->totalflights, 'totalpay' => floatval($this->post->totalpay), 'transferhours' => $this->post->transferhours);
     PilotData::updateProfile($this->post->pilotid, $params);
     PilotData::SaveFields($this->post->pilotid, $_POST);
     /* Don't calculate a pilot's rank if this is set */
     if (Config::Get('RANKS_AUTOCALCULATE') == false) {
         PilotData::changePilotRank($this->post->pilotid, $this->post->rank);
     } else {
         RanksData::calculateUpdatePilotRank($this->post->pilotid);
     }
     StatsData::UpdateTotalHours();
     $this->set('message', 'Profile updated successfully');
     $this->render('core_success.tpl');
     $this->set('pilots', PilotData::getAllPilots());
     $this->render('/pm/pilot_manager.php');
     if ($this->post->resend_email == 'true') {
         $this->post->id = $this->post->pilotid;
         $this->resendemail(false);
     }
     $pilot = PilotData::getPilotData($this->post->pilotid);
     LogData::addLog(Auth::$userinfo->pilotid, 'Updated profile for ' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' ' . $pilot->firstname . ' ' . $pilot->lastname);
     return;
     break;
 }
예제 #2
0
파일: UserTest.php 프로젝트: rallin/phpVMS
 /**
  * UserTest::testEditUserData()
  * 
  * @return void
  */
 public function testEditUserData()
 {
     $pilot = PilotData::getPilotByEmail('*****@*****.**');
     $this->assertObjectHasAttribute('pilotid', $pilot, 'PilotData::getPilotByEmail');
     # Check a save profile
     $save = PilotData::updateProfile($pilot->pilotid, array('email' => '*****@*****.**', 'location' => 'PK', 'retired' => true));
     $this->assertTrue($save, DB::error());
     # Verify if data was written, and if it differs
     $changeset1 = PilotData::getPilotData($pilot->pilotid);
     $this->assertEquals('PK', $changeset1->location);
     unset($data);
 }
예제 #3
0
 public static function resetpirepcount()
 {
     echo '<h3>Reset PIREP Counts</h3>';
     $all_pilots = PilotData::findPilots(array());
     foreach ($all_pilots as $pilot) {
         $pireps = PIREPData::getReportsByAcceptStatus($pilot->pilotid, PIREP_ACCEPTED);
         $total = count($pireps);
         unset($pireps);
         $code = PilotData::getPilotCode($pilot->code, $pilot->pilotid);
         echo "{$code} - {$pilot->firstname} {$pilot->lastname} - {$total} pireps<br />";
         # Update the pireps table
         PilotData::updateProfile($pilot->pilotid, array('totalpireps' => $total));
     }
     echo 'Completed!';
 }
예제 #4
0
    /**
     * Log the user in
     */
    public static function ProcessLogin($useridoremail, $password)
    {
        # Allow them to login in any manner:
        #  Email: blah@blah.com
        #  Pilot ID: VMA0001, VMA 001, etc
        #  Just ID: 001
        if (is_numeric($useridoremail)) {
            $useridoremail = $useridoremail - intval(Config::Get('PILOTID_OFFSET'));
            $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots
				   WHERE pilotid=' . $useridoremail;
        } else {
            # They're logging in with an email
            if (preg_match('/^.*\\@.*$/i', $useridoremail) > 0) {
                $emailaddress = DB::escape($useridoremail);
                $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots
						WHERE email=\'' . $useridoremail . '\'';
            } elseif (preg_match('/^([A-Za-z]*)(.*)(\\d*)/', $useridoremail, $matches) > 0) {
                $id = trim($matches[2]);
                $id = $id - intval(Config::Get('PILOTID_OFFSET'));
                $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots
						WHERE pilotid=' . $id;
            } else {
                self::$error_message = 'Invalid user ID';
                return false;
            }
        }
        $password = DB::escape($password);
        $userinfo = DB::get_row($sql);
        if (!$userinfo) {
            self::$error_message = 'This user does not exist';
            return false;
        }
        /*  Implement the pilot statuses, see if they are allowed in
            according to their status */
        $pilotStatuses = Config::get('PILOT_STATUS_TYPES');
        foreach ($pilotStatuses as $id => $info) {
            if ($userinfo->retired == $id && $info['canlogin'] == false) {
                self::$error_message = $info['message'];
                return false;
            }
        }
        /*if($userinfo->retired == 1)
          {
          self::$error_message = 'Your account was deactivated, please contact an admin';
          return false;
          }*/
        //ok now check it
        $hash = md5($password . $userinfo->salt);
        if ($hash == $userinfo->password) {
            self::$userinfo = $userinfo;
            #deprecated
            self::$pilot = self::$userinfo;
            self::update_session(self::$session_id, self::$userinfo->pilotid);
            SessionManager::Set('loggedin', 'true');
            SessionManager::Set('userinfo', $userinfo);
            SessionManager::Set('usergroups', PilotGroups::GetUserGroups($userinfo->pilotid));
            PilotData::updateProfile($pilotid, array('lastlogin' => 'NOW()', 'lastip' => $_SERVER['REMOTE_ADDR']));
            return true;
        } else {
            self::$error_message = 'Invalid login, please check your username and password';
            self::LogOut();
            return false;
        }
    }
예제 #5
0
파일: UserTest.php 프로젝트: Galihom/phpVMS
 /**
  * UserTest::testUserStatusChanges()
  * 
  * @return void
  */
 public function testUserStatusChanges()
 {
     $pilot = PilotData::getPilotByEmail('*****@*****.**');
     # Go through all the statuses
     $status_type_list = Config::get('PILOT_STATUS_TYPES');
     foreach ($status_type_list as $id => $status) {
         $save = PilotData::updateProfile($pilot->pilotid, array('retired' => $id));
         $pilotGroups = PilotGroups::getUserGroups($pilot->pilotid);
         # Check if they are in the proper groups:
         foreach ($status['group_add'] as $group) {
             #$this->assertTrue(PilotGroups::checkUserInGroup($pilot->pilotid, $group), "Error adding to \"$group\" for {$status['name']}");
             $found = false;
             foreach ($pilotGroups as $pilot_group) {
                 if ($pilot_group->name === $group) {
                     $found = true;
                     break;
                 }
             }
             $this->assertTrue($found, "Error adding to \"{$group}\" for {$status['name']}");
         }
         foreach ($status['group_remove'] as $group) {
             $this->assertNotTrue(PilotGroups::CheckUserInGroup($pilot->pilotid, $group));
         }
     }
     /* Set the user back to the default status */
     foreach ($status_type_list as $id => $status) {
         if ($status['default'] == false) {
             continue;
         }
         $save = PilotData::updateProfile($pilot->pilotid, array('retired' => $id));
         # Check if they are in the proper groups:
         foreach ($status['group_add'] as $group) {
             $this->assertTrue(PilotGroups::CheckUserInGroup($pilot->pilotid, $group), "Error adding to \"{$group}\" for {$status['name']}");
         }
         foreach ($status['group_remove'] as $group) {
             $this->assertNotTrue(PilotGroups::CheckUserInGroup($pilot->pilotid, $group));
         }
     }
 }
예제 #6
0
 /**
  * SchedulePIREPTest::testPIREPRejected()
  * 
  * @return void
  */
 public function testPIREPRejected()
 {
     $this->resetPilot();
     $sched = $this->findSchedule();
     Config::Set('PIREP_CHECK_DUPLICATE', false);
     Config::Set('EMAIL_SEND_PIREP', false);
     # Update this schedule to only pay per-hour
     SchedulesData::editScheduleFields($sched->id, array('payforflight' => 0));
     $sched = $this->findSchedule();
     $this->assertEquals(0, $sched->payforflight, 'Pay per-flight set to 0');
     $pirep_test = array('pilotid' => $this->samplePilotID, 'code' => $sched->code, 'flightnum' => $sched->flightnum, 'route' => $sched->route, 'depicao' => $sched->depicao, 'arricao' => $sched->arricao, 'aircraft' => $sched->aircraft, 'flighttime' => $sched->flighttime, 'submitdate' => 'NOW()', 'fuelused' => 6000, 'source' => 'unittest', 'comment' => 'Test Flight');
     # Update Pilot Pay to be set to zero
     PilotData::updateProfile($this->samplePilotID, array('totalpay' => 0));
     $pilot_data = PilotData::getPilotData($this->samplePilotID);
     $this->assertEquals($pilot_data->totalpay, 0, 'Reset Pilot Pay to 0');
     # File the flight report
     $pirepid = PIREPData::fileReport($pirep_test);
     $this->assertGreaterThan(0, $pirepid, PIREPData::$lasterror);
     $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $this->assertGreaterThan(0, count($pirepdata), 'No PIREPs returned');
     # Work on one...
     $pirepdata = $pirepdata[0];
     # Verify the little bits of this PIREP....
     $this->assertEquals(PILOT_PAY_HOURLY, $pirepdata->paytype, 'PIREP Pay Type');
     $this->assertEquals($pilot_data->payrate, $pirepdata->pilotpay, 'PIREP Pay Amount');
     # Check the pilot pay
     $pilot_data = PilotData::getPilotData($this->samplePilotID);
     $this->assertEquals(0, $pilot_data->totalpay, 'Check pilot pay after PIREP FILE');
     # Reject the PIREP and then check the pilot pay
     $status = PIREPData::changePIREPStatus($pirepdata->pirepid, PIREP_REJECTED);
     $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $this->assertEquals(PIREP_REJECTED, $pirepdata[0]->accepted, 'changePIREPStatus to ACCEPTED');
     $pirepdata = $pirepdata[0];
     # Check the schedule flown count:
     $post_accept = $this->findSchedule();
     $this->assertEquals($sched->timesflown, $post_accept->timesflown, "Schedule increment count");
     $post_pilot_data = PilotData::getPilotData($this->samplePilotID);
     $this->assertEquals(0, $post_pilot_data->totalpay, 'Check pilot pay after PIREP REJECT');
     $this->assertEquals($pilot_data->totalflights, $post_pilot_data->totalflights, 'Total Flights');
     # Delete the PIREP
     PIREPData::deletePIREP($pirepid);
     # Verify delete
     $data = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $this->assertEmpty($data, 'PIREPDdata::deletePIREP()');
 }
예제 #7
0
 protected function save_profile_post()
 {
     if (!Auth::LoggedIn()) {
         $this->set('message', 'You must be logged in to access this feature!');
         $this->render('core_error.tpl');
         return;
     }
     $userinfo = Auth::$userinfo;
     //TODO: check email validity
     if ($this->post->email == '') {
         return;
     }
     $params = array('code' => Auth::$userinfo->code, 'email' => $this->post->email, 'location' => $this->post->location, 'hub' => Auth::$userinfo->hub, 'bgimage' => $this->post->bgimage, 'retired' => false);
     PilotData::updateProfile($userinfo->pilotid, $params);
     PilotData::SaveFields($userinfo->pilotid, $_POST);
     # Generate a fresh signature
     PilotData::GenerateSignature($userinfo->pilotid);
     PilotData::SaveAvatar($userinfo->code, $userinfo->pilotid);
     $this->set('message', 'Profile saved!');
     $this->render('core_success.tpl');
 }
예제 #8
0
 public static function calculateUpdatePilotRank($pilotid)
 {
     /* Don't calculate a pilot's rank if this is set */
     if (Config::Get('RANKS_AUTOCALCULATE') == false) {
         return;
     }
     $pilotid = intval($pilotid);
     $allranks = self::GetAllRanks();
     $pilot = PilotData::GetPilotData($pilotid);
     $pilothours = $pilot->totalhours;
     if (Config::Get('TRANSFER_HOURS_IN_RANKS') == true) {
         $pilothours += $pilot->transferhours;
     }
     $i = 0;
     foreach ($allranks as $rank) {
         $i++;
         if ($pilothours >= intval($rank->minhours)) {
             $rank_level = $i;
             $last_rank = $rank->rank;
             $last_rankid = $rank->rankid;
         }
     }
     $update = array('rankid' => $last_rankid, 'rank' => $last_rank, 'ranklevel' => $rank_level);
     PilotData::updateProfile($pilot->pilotid, $update);
 }
예제 #9
0
 public function viewpilots()
 {
     /* This function is called for *ANYTHING* in that popup box
        
        Preset all of the template items in this function and
        call them in the subsequent templates
        
        Confusing at first, but easier than loading each tab
        independently via AJAX. Though may be an option later
        on, but can certainly be done by a plugin (Add another
        tab through AJAX). The hook is available for whoever
        wants to use it
        */
     switch ($this->post->action) {
         case 'changepassword':
             $this->ChangePassword();
             return;
             break;
         case 'deletepilot':
             $pilotid = $this->post->pilotid;
             $pilotinfo = PilotData::getPilotData($pilotid);
             PilotData::DeletePilot($pilotid);
             CodonEvent::Dispatch('pilot_deleted', 'PilotAdmin', $pilot);
             $this->set('message', Lang::gs('pilot.deleted'));
             $this->render('core_success.tpl');
             LogData::addLog(Auth::$userinfo->pilotid, 'Deleted pilot ' . PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid) . ' ' . $pilotinfo->firstname . ' ' . $pilotinfo->lastname);
             break;
             /* These are reloaded into the #pilotgroups ID
                so the entire groups list is refreshed
                */
         /* These are reloaded into the #pilotgroups ID
            so the entire groups list is refreshed
            */
         case 'addgroup':
             $this->AddPilotToGroup();
             $this->SetGroupsData($this->post->pilotid);
             $this->render('pilots_groups.tpl');
             return;
             break;
         case 'removegroup':
             $this->RemovePilotGroup();
             $this->SetGroupsData($this->post->pilotid);
             $this->render('pilots_groups.tpl');
             return;
             break;
         case 'saveprofile':
             if ($this->post->firstname == '' || $this->post->lastname == '') {
                 $this->set('message', 'The first or lastname cannot be blank!');
                 $this->render('core_error.tpl');
                 return;
             }
             if (intval($this->post->retired) == 1) {
                 $retired = true;
             } else {
                 $retired = false;
             }
             $params = array('code' => $this->post->code, 'firstname' => $this->post->firstname, 'lastname' => $this->post->lastname, 'email' => $this->post->email, 'location' => $this->post->location, 'hub' => $this->post->hub, 'retired' => $retired, 'totalhours' => $this->post->totalhours, 'totalflights' => $this->post->totalflights, 'totalpay' => floatval($this->post->totalpay), 'payadjust' => floatval($this->post->payadjust), 'transferhours' => $this->post->transferhours, 'comment' => $this->post->comment);
             PilotData::updateProfile($this->post->pilotid, $params);
             PilotData::SaveFields($this->post->pilotid, $_POST);
             /* Don't calculate a pilot's rank if this is set */
             if (Config::Get('RANKS_AUTOCALCULATE') == false) {
                 PilotData::changePilotRank($this->post->pilotid, $this->post->rank);
             } else {
                 RanksData::calculateUpdatePilotRank($this->post->pilotid);
             }
             StatsData::UpdateTotalHours();
             $this->set('message', 'Profile updated successfully');
             $this->render('core_success.tpl');
             $pilot = PilotData::getPilotData($this->post->pilotid);
             LogData::addLog(Auth::$userinfo->pilotid, 'Updated profile for ' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' ' . $pilot->firstname . ' ' . $pilot->lastname);
             return;
             break;
     }
     if ($this->get->action == 'viewoptions') {
         $this->ViewPilotDetails();
         return;
     }
     $this->ShowPilotsList();
 }
예제 #10
0
 public static function calculateUpdatePilotRank($pilotid, $ranks_list = null)
 {
     /* Don't calculate a pilot's rank if this is set */
     if (Config::Get('RANKS_AUTOCALCULATE') == false) {
         return;
     }
     if ($ranks_list === null) {
         $ranks_list = self::getAllRanks();
     }
     $pilotid = intval($pilotid);
     $pilot = PilotData::getPilotData($pilotid);
     $pilothours = $pilot->totalhours;
     if (Config::Get('TRANSFER_HOURS_IN_RANKS') == true) {
         $pilothours += $pilot->transferhours;
     }
     $i = 0;
     foreach ($ranks_list as $rank) {
         $i++;
         if ($pilothours >= intval($rank->minhours)) {
             $rank_level = $i;
             $last_rank = $rank->rank;
             $last_rankid = $rank->rankid;
         }
     }
     $update = array('rankid' => $last_rankid, 'rank' => $last_rank, 'ranklevel' => $rank_level);
     PilotData::updateProfile($pilot->pilotid, $update);
     if ($pilot->rank != $last_rank) {
         $message = Lang::get('activity.pilot.promotion');
         $message = str_replace('$rank', $last_rank, $message);
         # Add it to the activity feed
         ActivityData::addActivity(array('pilotid' => $pilotid, 'type' => ACTIVITY_PROMOTION, 'refid' => $pilotid, 'message' => htmlentities($message)));
     }
 }