Example #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;
 }
Example #2
0
 /**
  * Reject the report, and then send them the comment
  * that was entered into the report
  */
 protected function reject_pirep_post()
 {
     $pirepid = $this->post->pirepid;
     $comment = $this->post->comment;
     if ($pirepid == '' || $comment == '') {
         return;
     }
     PIREPData::ChangePIREPStatus($pirepid, PIREP_REJECTED);
     // 2 is rejected
     $pirep_details = PIREPData::GetReportDetails($pirepid);
     // If it was previously accepted, subtract the flight data
     if (intval($pirep_details->accepted) == PIREP_ACCEPTED) {
         PilotData::UpdateFlightData($pirep_details->pilotid, -1 * floatval($pirep->flighttime), -1);
     }
     //PilotData::UpdatePilotStats($pirep_details->pilotid);
     RanksData::CalculateUpdatePilotRank($pirep_details->pilotid);
     PilotData::resetPilotPay($pirep_details->pilotid);
     StatsData::UpdateTotalHours();
     // Send comment for rejection
     if ($comment != '') {
         $commenter = Auth::$userinfo->pilotid;
         // The person logged in commented
         PIREPData::AddComment($pirepid, $commenter, $comment);
         // Send them an email
         $this->set('firstname', $pirep_details->firstname);
         $this->set('lastname', $pirep_details->lastname);
         $this->set('pirepid', $pirepid);
         $message = Template::GetTemplate('email_commentadded.tpl', true);
         Util::SendEmail($pirep_details->email, 'Comment Added', $message);
     }
     LogData::addLog(Auth::$userinfo->pilotid, 'Rejected PIREP #' . $pirepid);
     # Call the event
     CodonEvent::Dispatch('pirep_rejected', 'PIREPAdmin', $pirep_details);
 }
Example #3
0
 public function approveall()
 {
     echo '<h3>Approve All</h3>';
     $allpireps = PIREPData::findPIREPS(array('p.accepted' => PIREP_PENDING));
     $total = count($allpireps);
     $count = 0;
     foreach ($allpireps as $pirep_details) {
         if ($pirep_details->aircraft == '') {
             continue;
         }
         # Update pilot stats
         SchedulesData::IncrementFlownCount($pirep_details->code, $pirep_details->flightnum);
         PIREPData::ChangePIREPStatus($pirep_details->pirepid, PIREP_ACCEPTED);
         // 1 is accepted
         //PilotData::UpdateFlightData($pirep_details->pilotid, $pirep_details->flighttime, 1);
         PilotData::UpdatePilotStats($pirep_details->pilotid);
         PilotData::UpdatePilotPay($pirep_details->pilotid, $pirep_details->flighttime);
         RanksData::CalculateUpdatePilotRank($pirep_details->pilotid);
         RanksData::CalculatePilotRanks();
         PilotData::GenerateSignature($pirep_details->pilotid);
         StatsData::UpdateTotalHours();
         $count++;
     }
     $skipped = $total - $count;
     echo "{$count} of {$total} were approved ({$skipped} has errors)";
 }