public function emails()
 {
     $this->set('title', 'Pilot Manager');
     $email = $this->post->email;
     $send = $this->post->send;
     Template::Set('send', $send);
     if ($send == "warning") {
         $pilotinfo = PManagerData::getpilotbyemail($email);
         $pilot = $pilotinfo->pilotid;
         Template::Set('pilot', PManagerData::getpilotbyemail($email));
         Template::Set('subject', 'Account termination Warning!!');
         Template::Set('email', $email);
         $subject = "Account termination Warning!!";
         $message = Template::Get('/pm/email_warning.php', true);
         Template::Set('message', $message);
         Util::SendEmail($email, $subject, $message);
         PManagerData::warningsent($pilot, $message);
         $this->show('/pm/email_confirm.php');
     }
     if ($send == "welcome") {
         $pilotinfo = PManagerData::getpilotbyemail($email);
         $pilot = $pilotinfo->pilotid;
         Template::Set('pilot', PManagerData::getpilotbyemail($email));
         Template::Set('subject', 'Welcome!!');
         Template::Set('email', $email);
         $subject = "Welcome!!";
         $message = Template::Get('/pm/email_welcome.php', true);
         Template::Set('message', $message);
         Util::SendEmail($email, $subject, $message);
         PManagerData::welcomesent($pilot, $message);
         $this->show('/pm/email_confirm.php');
     }
     if ($send == "blank") {
         $this->set('title', 'Pilot Manager');
         $this->set('email', $email);
         $this->show('/pm/blank_email.php');
     }
 }
Example #2
0
 /**
  * Function used to get a template
  *
  * Similar to Template::Draw() but will return the output as a string rather than echoing it.
  *
  * @param string $name The name of the template
  * @param array $_PARAMS Multiple parameters to give to the template
  *
  * @return string Will return the finalized template as string. Empty string is returned incase an error occured. (check the log file)
  */
 static function Get($name, $_PARAMS = array())
 {
     if (!isset(self::$templates[$name]) && is_file(TEMPLATE_DIR . $name . '.html')) {
         // Check if this template exists and is not cached
         self::$templates[$name] = file_get_contents(TEMPLATE_DIR . $name . '.html');
     } else {
         if (!isset(self::$templates[$name]) && is_file(INTERNAL_TEMPLATE_DIR . $name . '.html')) {
             self::$templates[$name] = file_get_contents(INTERNAL_TEMPLATE_DIR . $name . '.html');
         } else {
             if (!isset(self::$templates[$name])) {
                 Lightwork::Log('Tried to draw missing template: ' . $name, Lightwork::LOG_DEBUG);
                 // ...and log this so we can fix it.
                 return '';
             }
         }
     }
     $template = self::$templates[$name];
     // Grab the template
     $template = preg_replace_callback(LWC::REGEX_IFCLAUSE, function ($matches) use($name, $_PARAMS) {
         $matches['name'] = $matches[1];
         // Define name of parameter so we can find it more easily
         if ($matches[2] != '') {
             $matches['condition'] = $matches[2];
             // Condition (is or is not)
             $matches['value'] = $matches[3];
             // Value for the condition check
             if ($matches['value'] == 'empty') {
                 // Special case: replace keyword 'empty' with an empty string
                 $matches['value'] = '';
             } else {
                 if ($matches['value'] == 'null') {
                     // Special case: replace string null with actual null
                     $matches['value'] = null;
                 }
             }
         }
         $matches['if_template'] = $matches[4];
         // Template to use incase condition is true
         if (isset($matches[5])) {
             $matches['else_template'] = $matches[5];
         }
         // Optional template if condition is false
         if (array_key_exists($matches['name'], $_PARAMS)) {
             if (isset($matches['condition'])) {
                 if ($matches['condition'] == 'is' && $_PARAMS[$matches['name']] == $matches['value']) {
                     // Check if our parameter matches the value...
                     return $matches['if_template'];
                 } else {
                     if ($matches['condition'] == 'not' && $_PARAMS[$matches['name']] != $matches['value']) {
                         // ...or our parameter does not match the value
                         return $matches['if_template'];
                     }
                 }
             } else {
                 if ($_PARAMS[$matches['name']]) {
                     // Check if our parameter is true
                     return $matches['if_template'];
                 }
                 // Output the if_template
             }
             if (isset($matches['else_template'])) {
                 // None of the conditions above were true, check if we can use the else template
                 return $matches['else_template'];
             } else {
                 // There is no else template, return empty instead
                 return '';
             }
         } else {
             Lightwork::Log('Tried to use missing parameter ' . $matches['name'] . ' on template ' . $name, Lightwork::LOG_DEBUG);
             // Log all missing parameters so they can be fixed
             return '';
         }
         if (array_key_exists($matches[1], $_PARAMS)) {
             if ($matches[2] != '' && $matches[3] != '') {
                 if ($matches[2] == 'is' && $_PARAMS[$matches[1]] == $matches[3]) {
                     return $matches[4];
                 } else {
                     if (isset($matches[4])) {
                         return $matches[4];
                     } else {
                         return '';
                     }
                 }
             } else {
                 if ($_PARAMS[$matches[1]]) {
                     return $matches[3];
                 } else {
                     if (isset($matches[4])) {
                         return $matches[4];
                     } else {
                         return '';
                     }
                 }
             }
         } else {
             Lightwork::Log('Tried to use missing parameter ' . $matches[1] . ' on template ' . $name, Lightwork::LOG_DEBUG);
             return '';
         }
     }, $template);
     $template = preg_replace_callback(LWC::REGEX_INCLUDER, function ($matches) use($name, $_PARAMS) {
         return Template::Get($matches[1], $_PARAMS);
     }, $template);
     $template = preg_replace_callback(LWC::REGEX_KEY_FINDER_OPTIONS, function ($matches) use($name, $_PARAMS) {
         if (mb_strlen($matches[1]) > 0) {
             $options = str_split($matches[1]);
         } else {
             $options = ['p'];
         }
         $parameter = $matches[2];
         foreach ($options as $option) {
             switch ($option) {
                 case 'p':
                     if (array_key_exists($parameter, $_PARAMS)) {
                         $parameter = $_PARAMS[$parameter];
                     } else {
                         $parameter = '';
                         Lightwork::Log('Tried to use missing parameter ' . $matches[2] . ' on template ' . $name, Lightwork::LOG_DEBUG);
                     }
                     break;
                 case 't':
                     $parameter = t($parameter);
                     break;
                 case 'e':
                     $parameter = escape($parameter);
                     break;
                 default:
                     Lightwork::Log('Tried to use unknown template option: ' . $option);
                     break;
             }
         }
         return $parameter;
     }, $template);
     return $template;
 }
Example #3
0
 public function get($name)
 {
     return Template::Get($name, true);
 }
Example #4
0
 /**
  * Find and set any pilots as retired
  *
  * @return mixed This is the return value description
  *
  */
 public static function findRetiredPilots()
 {
     $days = Config::Get('PILOT_INACTIVE_TIME');
     if ($days == '') {
         $days = 90;
     }
     $sql = "SELECT * FROM " . TABLE_PREFIX . "pilots\n\t\t\t\tWHERE DATE_SUB(CURDATE(), INTERVAL  {$days} DAY) > `lastlogin`  \n\t\t\t\t\tAND `totalflights` = 0 AND `lastlogin` != 0\n\t\t\t\t\tAND `retired` = 0";
     $results = DB::get_results($sql);
     $sql = "SELECT * FROM " . TABLE_PREFIX . "pilots\n\t\t\t\tWHERE DATE_SUB(CURDATE(), INTERVAL  {$days} DAY) > `lastpirep` \n\t\t\t\t\tAND `totalflights` > 0 AND `lastpirep` != 0\n\t\t\t\t\tAND `retired` = 0";
     $results2 = DB::get_results($sql);
     // messy but two queries, merge them both
     if (!is_array($results) && !is_array($results2)) {
         return false;
     } else {
         if (is_array($results) && is_array($results2)) {
             $results = array_merge($results, $results2);
         }
         if (!is_array($results) && is_array($results2)) {
             $results = $results2;
         }
     }
     if (!$results) {
         return false;
     }
     # Find the retired status
     $statuses = Config::get('PILOT_STATUS_TYPES');
     foreach ($statuses as $retired_id => $status) {
         if ($status['autoretire'] == true) {
             break;
         }
     }
     foreach ($results as $row) {
         // Set them retired
         self::updateProfile($row->pilotid, array('retired' => $retired_id));
         Template::Set('pilot', $row);
         $pilot_retired_template = Template::Get('email_pilot_retired.tpl', true, true, true);
         Util::SendEmail($row->email, Lang::get('email.pilot.retired.subject'), $pilot_retired_template);
     }
 }
Example #5
0
# Load the main skin
$settings_file = SKINS_PATH . DS . CURRENT_SKIN . '.php';
if (file_exists($settings_file)) {
    include $settings_file;
}
$BaseTemplate->template_path = SKINS_PATH;
Template::Set('MODULE_NAV_INC', $NAVBAR);
Template::Set('MODULE_HEAD_INC', $HTMLHead);
ob_start();
MainController::RunAllActions();
$page_content = ob_get_clean();
$BaseTemplate->Set('title', MainController::$page_title . ' - ' . SITE_NAME);
$BaseTemplate->Set('page_title', MainController::$page_title . ' - ' . SITE_NAME);
if (file_exists(SKINS_PATH . '/layout.tpl')) {
    $BaseTemplate->Set('page_htmlhead', Template::Get('core_htmlhead.tpl', true));
    $BaseTemplate->Set('page_htmlreq', Template::Get('core_htmlreq.tpl', true));
    $BaseTemplate->Set('page_content', $page_content);
    $BaseTemplate->ShowTemplate('layout.tpl');
} else {
    # It's a template sammich!
    $BaseTemplate->ShowTemplate('header.tpl');
    echo $page_content;
    $BaseTemplate->ShowTemplate('footer.tpl');
}
# Force connection close
DB::close();
if (Config::Get('XDEBUG_BENCHMARK')) {
    $run_time = xdebug_time_index();
    $memory_end = xdebug_memory_usage();
    echo 'TOTAL MEMORY: ' . ($memory_end - $memory_start) . '<br />';
    echo 'PEAK: ' . xdebug_peak_memory_usage() . '<br />';
Example #6
0
    /**
     * Get all of the details for a PIREP, including lat/long of the airports
     */
    public static function getReportDetails($pirepid)
    {
        $sql = 'SELECT p.*, s.*, s.id AS scheduleid, p.route, p.route_details,
					u.pilotid, u.firstname, u.lastname, u.email, u.rank,
					dep.name as depname, dep.lat AS deplat, dep.lng AS deplng,
					arr.name as arrname, arr.lat AS arrlat, arr.lng AS arrlng,
				    p.code, p.flightnum, p.depicao, p.arricao,  p.price AS price,
				    a.id as aircraftid, a.name as aircraft, a.registration, p.flighttime,
				    p.distance, 
                    UNIX_TIMESTAMP(p.submitdate) as submitdate, 
                    UNIX_TIMESTAMP(p.modifieddate) as modifieddate,
                    p.accepted, p.log
				FROM ' . TABLE_PREFIX . 'pilots u, ' . TABLE_PREFIX . 'pireps p
					LEFT JOIN ' . TABLE_PREFIX . 'airports AS dep ON dep.icao = p.depicao
					LEFT JOIN ' . TABLE_PREFIX . 'airports AS arr ON arr.icao = p.arricao
					LEFT JOIN ' . TABLE_PREFIX . 'aircraft a ON a.id = p.aircraft
					LEFT JOIN ' . TABLE_PREFIX . 'schedules s ON s.code = p.code AND s.flightnum = p.flightnum
				WHERE p.pilotid=u.pilotid AND p.pirepid=' . $pirepid;
        $row = DB::get_row($sql);
        $row->rawdata = unserialize($row->rawdata);
        /* Do any specific replacements here */
        if ($row) {
            /* If it's FSFlightKeeper, process the `rawdata` column, which contains
               array()'d copied of extra data that was sent by the ACARS. Run that
               through some templates which we've got. This can probably be generic-ized
               but it's fine now for FSFK. This can probably move through an outside 
               function, but seems OK to stay in getReportDetails() for now, since this
               is semi-intensive code here (the most expensive is populating the templates,
               and I wouldn't want to run it for EVERY PIREP which is called by the system.
               */
            if ($row->source == 'fsfk') {
                /* Do data stuff in the logs */
                $data = $row->rawdata;
                /* Process flight data */
                if (isset($data['FLIGHTDATA'])) {
                    Template::Set('data', $data['FLIGHTDATA']);
                    $flightdata = Template::Get('fsfk_log_flightdata.tpl', true, true, true);
                    $row->log .= $flightdata;
                    unset($flightdata);
                }
                /* Process the flightplan */
                if (isset($data['FLIGHTPLAN'])) {
                    $value = trim($data['FLIGHTPLAN']);
                    $lines = explode("\n", $value);
                    Template::Set('lines', $lines);
                    $flightplan = Template::Get('fsfk_log_flightplan.tpl', true, true, true);
                    $row->log .= $flightplan;
                    unset($flightplan);
                }
                /* Process flight critique data */
                if (isset($data['FLIGHTCRITIQUE'])) {
                    $value = $data['FLIGHTCRITIQUE'];
                    $value = trim($value);
                    preg_match_all("/(.*) \\| (.*)\n/", $value, $matches);
                    # Get these from a template
                    Template::Set('matches', $matches);
                    $critique = Template::Get('fsfk_log_flightcritique.tpl', true, true, true);
                    $row->log .= $critique;
                    unset($critique);
                }
                /* Process the flight images, last */
                if (isset($data['FLIGHTMAPS'])) {
                    Template::Set('images', $data['FLIGHTMAPS']);
                    $flightimages = Template::Get('fsfk_log_flightimages.tpl', true, true, true);
                    $row->log .= $flightimages;
                    unset($flightimages);
                }
            }
            /* End "if FSFK" */
            if ($row->route_details != '') {
                $row->route_details = unserialize($row->route_details);
            } else {
                $row->route_details = NavData::parseRoute($row);
            }
        }
        /* End "if $row" */
        return $row;
    }
Example #7
0
 /**
  * Registration::ProcessRegistration()
  *
  * @return
  */
 protected function ProcessRegistration()
 {
     // Yes, there was an error
     if (!$this->VerifyData()) {
         $this->ShowForm();
         return;
     }
     $data = array('firstname' => $this->post->firstname, 'lastname' => $this->post->lastname, 'email' => $this->post->email, 'password' => $this->post->password1, 'code' => $this->post->code, 'location' => $this->post->location, 'hub' => $this->post->hub, 'confirm' => false);
     if (CodonEvent::Dispatch('registration_precomplete', 'Registration', $_POST) == false) {
         return false;
     }
     $ret = RegistrationData::CheckUserEmail($data['email']);
     if ($ret) {
         $this->set('error', Lang::gs('email.inuse'));
         $this->render('registration_error.tpl');
         return false;
     }
     $val = RegistrationData::AddUser($data);
     if ($val == false) {
         $this->set('error', RegistrationData::$error);
         $this->render('registration_error.tpl');
         return;
     } else {
         $pilotid = RegistrationData::$pilotid;
         /* Automatically confirm them if that option is set */
         if (Config::Get('PILOT_AUTO_CONFIRM') == true) {
             PilotData::AcceptPilot($pilotid);
             RanksData::CalculatePilotRanks();
             $pilot = PilotData::getPilotData($pilotid);
             $this->set('pilot', $pilot);
             $this->render('registration_autoconfirm.tpl');
         } else {
             /* Otherwise, wait until an admin confirms the registration */
             RegistrationData::SendEmailConfirm($email, $firstname, $lastname);
             $this->render('registration_sentconfirmation.tpl');
         }
     }
     CodonEvent::Dispatch('registration_complete', 'Registration', $_POST);
     // Registration email/show user is waiting for confirmation
     $sub = 'A user has registered';
     $message = "The user {$data['firstname']} {$data['lastname']} ({$data['email']}) has registered, and is awaiting confirmation.";
     $email = Config::Get('EMAIL_NEW_REGISTRATION');
     if (empty($email)) {
         $email = ADMIN_EMAIL;
     }
     Util::SendEmail($email, $sub, $message);
     // Send email to user
     $this->set('firstname', $data['firstname']);
     $this->set('lastname', $data['lastname']);
     $this->set('userinfo', $data);
     $message = Template::Get('email_registered.tpl', true);
     Util::SendEmail($data['email'], 'Registration at ' . SITE_NAME, $message);
     $rss = new RSSFeed('Latest Pilot Registrations', SITE_URL, 'The latest pilot registrations');
     $pilot_list = PilotData::GetLatestPilots();
     foreach ($pilot_list as $pilot) {
         $rss->AddItem('Pilot ' . PilotData::GetPilotCode($pilot->code, $pilot->pilotid) . ' (' . $pilot->firstname . ' ' . $pilot->lastname . ')', SITE_URL . '/admin/index.php?admin=pendingpilots', '', '');
     }
     $rss->BuildFeed(LIB_PATH . '/rss/latestpilots.rss');
 }
Example #8
0
 protected function RejectPilot()
 {
     $pilot = PilotData::GetPilotData($this->post->id);
     # Send pilot notification
     $subject = Lang::gs('email.register.rejected.subject');
     $this->set('pilot', $pilot);
     $message = Template::Get('email_registrationdenied.tpl', true, true, true);
     Util::SendEmail($pilot->email, $subject, $message);
     # Reject in the end, since it's delted
     PilotData::RejectPilot($this->post->id);
     CodonEvent::Dispatch('pilot_rejected', 'PilotAdmin', $pilot);
     LogData::addLog(Auth::$userinfo->pilotid, 'Approved ' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' - ' . $pilot->firstname . ' ' . $pilot->lastname);
 }
Example #9
0
 /**
  * PilotAdmin::RejectPilot()
  * 
  * @return
  */
 protected function RejectPilot()
 {
     $this->checkPermission(MODERATE_REGISTRATIONS);
     $pilot = PilotData::GetPilotData($this->post->id);
     # Send pilot notification
     $subject = Lang::gs('email.register.rejected.subject');
     $this->set('pilot', $pilot);
     $oldPath = Template::setTemplatePath(TEMPLATES_PATH);
     $oldSkinPath = Template::setSkinPath(ACTIVE_SKIN_PATH);
     $message = Template::Get('email_registrationdenied.php', true, true, true);
     Template::setTemplatePath($oldPath);
     Template::setSkinPath($oldSkinPath);
     Util::SendEmail($pilot->email, $subject, $message);
     # Reject in the end, since it's delted
     PilotData::RejectPilot($this->post->id);
     CodonEvent::Dispatch('pilot_rejected', 'PilotAdmin', $pilot);
     LogData::addLog(Auth::$userinfo->pilotid, 'Approved ' . PilotData::getPilotCode($pilot->code, $pilot->pilotid) . ' - ' . $pilot->firstname . ' ' . $pilot->lastname);
 }