/**
  * Display the HTML-Footer
  */
 public function displayFooter()
 {
     if (!Request::isAjax()) {
         include 'tpl/tpl.Frontend.footer.php';
     }
     Error::getInstance()->footer_sent = true;
 }
Esempio n. 2
0
 /**
  * Get training object
  * @param int $index optional
  * @return \TrainingObject
  */
 public final function object($index = 0)
 {
     if ($index > 0) {
         Error::getInstance()->addDebug('ParserAbstractSingle has only one training, asked for index = ' . $index);
     }
     return $this->TrainingObject;
 }
Esempio n. 3
0
 /**
  * Can the strategy handle the data?
  * 
  * To test this, we try to fetch a gtopo30-value.
  * This costs only 0.1 credit per call.
  * 
  * We assume that Geonames will find elevation data for all points.
  * 
  * @see http://www.geonames.org/export/webservice-exception.html
  */
 public function canHandleData()
 {
     $url = 'http://api.geonames.org/gtopo30JSON?lat=47.01&lng=10.2&username='******'gtopo30'])) {
         return true;
     }
     if (isset($response['status']) && isset($response['status']['value'])) {
         switch ((int) $response['status']['value']) {
             case 10:
                 \Error::getInstance()->addWarning('Geonames user account is not valid.');
                 break;
             case 18:
                 \Error::getInstance()->addDebug('Geonames-request failed: daily limit of credits exceeded');
                 break;
             case 19:
                 \Error::getInstance()->addDebug('Geonames-request failed: hourly limit of credits exceeded');
                 break;
             case 20:
                 \Error::getInstance()->addDebug('Geonames-request failed: weekly limit of credits exceeded');
                 break;
             default:
                 if (isset($response['status']['message'])) {
                     \Error::getInstance()->addDebug('Geonames response: ' . $response['status']['message']);
                 }
         }
     }
     return false;
 }
 /**
  * Get training object
  * @param int $index optional index
  * @return TrainingObject
  */
 public final function object($index = 0)
 {
     if (!isset($this->TrainingObjects[$index])) {
         Error::getInstance()->addDebug('Parser has only ' . $this->numberOfTrainings() . ' trainings, but asked for index = ' . $index);
         return end($this->TrainingObjects);
     }
     return $this->TrainingObjects[$index];
 }
 /**
  * Constructor
  */
 function __construct($url = null)
 {
     $this->url = "";
     $this->module = null;
     $this->action = null;
     $this->args = array();
     $this->error = Error::getInstance();
     $this->addGetParameters();
     $this->addPostParameters();
     $this->parseUrl($url);
 }
 /**
  * Initialize this plugin
  * @see PluginPanel::initPlugin()
  */
 protected function initPlugin()
 {
     $this->fileNameStart = SessionAccountHandler::getId() . '-runalyze-backup';
     if (isset($_GET['json'])) {
         if (move_uploaded_file($_FILES['qqfile']['tmp_name'], realpath(dirname(__FILE__)) . '/import/' . $_FILES['qqfile']['name'])) {
             Error::getInstance()->footer_sent = true;
             echo '{"success":true}';
         } else {
             echo '{"error":"Moving file did not work. Set chmod 777 for ' . realpath(dirname(__FILE__)) . '/import/"}';
         }
         exit;
     }
 }
Esempio n. 7
0
 /**
  * Send an email via smtp
  * @param string $to
  * @param string $subject
  * @param string $message
  * @return boolean 
  */
 public static function sendMail($to, $subject, $message)
 {
     $sender = MAIL_SENDER == '' ? '*****@*****.**' : MAIL_SENDER;
     try {
         $message = Swift_Message::newInstance()->setSubject($subject)->setBody($message, 'text/html')->setFrom(array($sender => MAIL_NAME))->setTo($to);
         $transport = Swift_SmtpTransport::newInstance(SMTP_HOST, SMTP_PORT, SMTP_SECURITY)->setUsername(SMTP_USERNAME)->setPassword(SMTP_PASSWORD);
         $mailer = Swift_Mailer::newInstance($transport);
         return $mailer->send($message);
     } catch (Exception $e) {
         Error::getInstance()->addError('Mail could not be sent: ' . $e->getMessage());
         return false;
     }
 }
Esempio n. 8
0
 /**
  * Function to display the HTML-Footer
  */
 public function displayFooter()
 {
     if (!Request::isAjax()) {
         if (self::$IS_IFRAME) {
             include 'tpl/tpl.FrontendSharedIframe.footer.php';
         }
         include 'tpl/tpl.Frontend.footer.php';
     }
     if (RUNALYZE_DEBUG && Error::getInstance()->hasErrors()) {
         Error::getInstance()->display();
     }
     Error::getInstance()->footer_sent = true;
 }
Esempio n. 9
0
 /**
  * Get clothes as string
  * @return string
  */
 public function asString()
 {
     $usedClothes = array();
     $clothes = ClothesFactory::AllClothes();
     foreach ($this->ids as $id) {
         $id = (int) trim($id);
         if (isset($clothes[$id])) {
             $usedClothes[] = $clothes[$id]['name'];
         } else {
             Error::getInstance()->addWarning('Asked for unknown clothes-ID: "' . $id . '"');
         }
     }
     return implode(', ', $usedClothes);
 }
Esempio n. 10
0
 /**
  * Can the strategy handle the data?
  * 
  * We assume that DataScienceToolkit will find elevation data for all points.
  * 
  * @see http://www.datasciencetoolkit.org/developerdocs#coordinates2statistics
  */
 public function canHandleData()
 {
     $url = 'http://www.datasciencetoolkit.org/coordinates2statistics/49.4%2c7.7?statistics=elevation';
     $response = json_decode(\Filesystem::getExternUrlContent($url), true);
     if (is_null($response)) {
         return false;
     }
     if (is_array($response) && isset($response[0]['statistics'])) {
         return true;
     }
     if (isset($response['error'])) {
         \Error::getInstance()->addDebug('DataScienceToolkit response: ' . $response['error']);
     }
     return false;
 }
Esempio n. 11
0
 /**
  * Can the strategy handle the data?
  * 
  * We assume that GoogleMaps will find elevation data for all points.
  * 
  * @see https://developers.google.com/maps/documentation/elevation/?hl=de&csw=1
  */
 public function canHandleData()
 {
     $url = 'http://maps.googleapis.com/maps/api/elevation/json?locations=49.4,7.7&sensor=false';
     $response = json_decode(\Filesystem::getExternUrlContent($url), true);
     if (is_null($response)) {
         return false;
     }
     if (is_array($response) && isset($response['results'])) {
         return true;
     }
     if (isset($response['status'])) {
         \Error::getInstance()->addDebug('GoogleMaps response: ' . $response['status']);
     }
     return false;
 }
Esempio n. 12
0
 /**
  * Load file
  */
 protected function loadFile()
 {
     if (!file_exists($this->schemeFile)) {
         Error::getInstance()->addError('Cannot find database scheme: ' . $this->schemeFile);
         return;
     } else {
         include $this->schemeFile;
         if (!isset($TABLENAME) || !isset($FIELDS) || !isset($FIELDSETS)) {
             Error::getInstance()->addError('$TABLENAME, $FIELDS and $FIELDSETS must be defined in scheme file: ' . $this->schemeFile);
         } else {
             $this->tableName = PREFIX . $TABLENAME;
             $this->fields = array_merge($this->fields, $FIELDS);
             $this->fieldsets = array_merge($this->fieldsets, $FIELDSETS);
             $this->hiddenKeys = array_merge($this->hiddenKeys, $HIDDEN_KEYS);
         }
     }
 }
Esempio n. 13
0
 public static function display($date, $format = self::SHORT_FORMAT, $language = null, $useOrdinalSuffix = true, $timeZone = null)
 {
     $returnValue = '';
     $currentLocale = setlocale(LC_TIME, 0);
     $currentTimeZone = 'America/Montreal';
     $defaultLanguage = 'fr';
     $timeZones = DateTimeZone::listIdentifiers();
     $dateTimeZone = new DateTimeZone(in_array($timeZone, $timeZones) ? $timeZone : $currentTimeZone);
     $currentDateTimeZone = new DateTimeZone($currentTimeZone);
     try {
         if (!is_null($language)) {
             $language = $defaultLanguage;
         }
         /*if (!is_null($language)) {
               $locales = array(
                   'fr_CA' => array('fr_CA.UTF-8', 'fr_CA.utf8', 'fra'),
                   'en_CA' => array('en_CA.UTF-8', 'en_CA.utf8'),
               );
               if (isset($locales[$language])) {
                   setlocale(LC_TIME,  $locales[$language]);
               } else {
                   $language = $defaultLanguage;
               }
           } else {
               $language = strstr($currentLocale, '.', true); // Take only characters before dot
           }*/
         if (!empty($date)) {
             $dateTime = new DateTime(is_numeric($date) ? "@{$date}" : $date);
             if (!is_null($timeZone)) {
                 // if timezone is not null, display date with the good one.
                 $dateTime->setTimestamp($dateTime->getTimestamp() + $dateTimeZone->getOffset($dateTime));
             }
             $ordinalSuffix = $useOrdinalSuffix ? $dateTime->format('S') : '';
             $returnValue = strftime(self::getFormat($language, $format, $ordinalSuffix), $dateTime->getTimestamp());
         }
     } catch (Exception $e) {
         Error::getInstance()->log('[' . date('Y-m-d H:i:s') . ' ] - SimpleDate::display() - ' . $e->getMessage() . "\n");
         $returnValue = $date;
     }
     setlocale(LC_TIME, $currentLocale);
     return $returnValue;
 }
Esempio n. 14
0
 public function __construct($url = "")
 {
     if (!defined('COOLPOST')) {
         die("ERROR HACK");
         exit;
     }
     $this->siteClose();
     if (!empty($_GET["url"])) {
         $url = $_GET["url"];
     }
     $url = rtrim($url, '/');
     $url = explode('/', $url);
     $file = ENGINE_DIR . '/controllers/' . $url[0] . '.class.php';
     if (file_exists($file)) {
         if (!$this->controllerAllowed($url[0])) {
             $controller = Error::getInstance();
         } else {
             $controller = new $url[0]();
         }
     } else {
         if (empty($url[0])) {
             $controller = new Index();
         } else {
             $controller = Error::getInstance();
         }
     }
     if (!empty($url[1]) && isset($url[1])) {
         if (!$this->methodAllowed($controller, $url[1])) {
             $controller = Error::getInstance();
         } else {
             if (!empty($url[2])) {
                 $controller->{$url}[1]($url[2]);
             } else {
                 $controller->{$url}[1]();
             }
         }
     } else {
         $controller->defaultPage();
     }
 }
 /**
  * Get training objects
  * @param int $index optional index
  * @return array array of TrainingObject
  */
 public final function object($index = 0)
 {
     if (is_null($this->Parser)) {
         Error::getInstance()->addError('Parser of Importer is empty. Returned default TrainingObject.');
         return new TrainingObject(DataObject::$DEFAULT_ID);
     }
     return $this->Parser->object($index);
 }
Esempio n. 16
0
	<div class="panel clear">
		<div class="panel-heading"><h1><?php 
_e('Debug console');
?>
</h1></div>
		<div class="panel-content"><?php 
echo Error::getInstance()->display();
?>
</div>
	</div>
Esempio n. 17
0
 function __construct()
 {
     self::$_errors = Error::getInstance();
 }
Esempio n. 18
0
 /**
  * Install this plugin
  * @return bool
  */
 public final function install()
 {
     if ($this->id() != PluginInstaller::ID) {
         Error::getInstance()->addError('Plugin can not be installed, id is set wrong.');
         return false;
     }
     $this->id = DB::getInstance()->insert('plugin', array('key', 'type', 'active', 'order'), array($this->key(), $this->typeString(), '1', '99'));
     return true;
 }
Esempio n. 19
0
 /**
  * End benchmark
  * 
  * This will produce a debug message with execution time.
  */
 public static function end()
 {
     if (!is_null(self::$StartTime)) {
         Error::getInstance()->addDebug('Benchmark time: ' . (microtime(true) - self::$StartTime));
     }
 }
Esempio n. 20
0
 /**
  * Set some special configuration values
  * @param int $accountId
  */
 private static function setSpecialConfigValuesFor($accountId)
 {
     if (is_null($accountId) || $accountId < 0) {
         Error::getInstance()->addError('AccountID for special config-values not set.');
         return;
     }
     $DB = DB::getInstance();
     $columns = array('category', 'key', 'value', 'accountid');
     $DB->exec('UPDATE `' . PREFIX . 'type` SET `sportid`="' . self::$SPECIAL_KEYS['RUNNING_SPORT_ID'] . '" WHERE `accountid`="' . $accountId . '"');
     $DB->insert('conf', $columns, array('general', 'MAINSPORT', self::$SPECIAL_KEYS['MAIN_SPORT_ID'], $accountId));
     $DB->insert('conf', $columns, array('general', 'RUNNINGSPORT', self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], $accountId));
     $DB->insert('conf', $columns, array('general', 'TYPE_ID_RACE', self::$SPECIAL_KEYS['TYPE_ID_RACE'], $accountId));
     //Connect equipment type and sport
     $DB->insert('equipment_sport', array('sportid', 'equipment_typeid'), array(self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], self::$SPECIAL_KEYS['EQUIPMENT_SHOES_ID']));
     $DB->insert('equipment_sport', array('sportid', 'equipment_typeid'), array(self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID']));
     // Add standard clothes equipment
     $eqColumns = array('name', 'notes', 'typeid', 'accountid');
     $DB->insert('equipment', $eqColumns, array(__('long sleeve'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('T-shirt'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('singlet'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('jacket'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('long pants'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('shorts'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('gloves'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
     $DB->insert('equipment', $eqColumns, array(__('hat'), '', self::$SPECIAL_KEYS['EQUIPMENT_CLOTHES_ID'], $accountId));
 }
Esempio n. 21
0
/**
 * Own function to handle the errors using class::Error.
 * @param $type      type of error (E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE)
 * @param $message   error message
 * @param $file      filename
 * @param $line      line number
 * @return bool      returning true to not execute PHP internal error handler
 */
function error_handler($type, $message, $file, $line)
{
    switch ($type) {
        case E_ERROR:
            $type = 'ERROR';
            break;
        case E_WARNING:
            $type = 'WARNING';
            break;
        case E_NOTICE:
            $type = 'NOTICE';
            break;
        default:
            $type = 'Unknown error type';
            break;
    }
    Error::getInstance()->add($type, $message, $file, $line);
    return true;
}
Esempio n. 22
0
 protected function _setError($key, $value)
 {
     if (!self::$_errors) {
         self::$_errors = Error::getInstance();
     }
     self::$_errors->setError($key, $value);
 }
Esempio n. 23
0
 /**
  * Init pointer to DB/Error-object
  */
 protected function initInternalObjects()
 {
     $this->DB = DB::getInstance();
     $this->Error = Error::getInstance();
     $this->Dataset = new Dataset();
 }
Esempio n. 24
0
 /**
  * Get timestamp of first training
  * @return int   Timestamp
  */
 private static function calculateStartTime()
 {
     $data = DB::getInstance()->query('SELECT MIN(`time`) as `time` FROM `' . PREFIX . 'training` WHERE accountid = ' . SessionAccountHandler::getId())->fetch();
     if (isset($data['time']) && $data['time'] == 0) {
         $data = DB::getInstance()->query('SELECT MIN(`time`) as `time` FROM `' . PREFIX . 'training` WHERE `time` != 0 AND accountid = ' . SessionAccountHandler::getId())->fetch();
         Error::getInstance()->addWarning('Du hast ein Training ohne Zeitstempel, also mit dem Datum 01.01.1970.');
     }
     if ($data === false || $data['time'] == null) {
         return 0;
     }
     return $data['time'];
 }
Esempio n. 25
0
 /**
  * Write a file
  * @param string $fileName relative to FRONTEND_PATH
  * @param string $fileContent 
  */
 public static function writeFile($fileName, $fileContent)
 {
     $file = fopen(FRONTEND_PATH . $fileName, "w");
     if ($file !== false) {
         fwrite($file, $fileContent);
         fclose($file);
     } else {
         Error::getInstance()->addError('Die Datei "' . $fileName . '" konnte zum Schreiben nicht erstellt/ge&ouml;ffnet werden.');
     }
 }
Esempio n. 26
0
 /**
  * Set some special configuration values
  * @param int $accountId
  */
 private static function setSpecialConfigValuesFor($accountId)
 {
     if (is_null($accountId) || $accountId < 0) {
         Error::getInstance()->addError('AccountID for special config-values not set.');
         return;
     }
     $DB = DB::getInstance();
     $whereAdd = 'AND `accountid`=' . (int) $accountId;
     $columns = array('category', 'key', 'value', 'accountid');
     $DB->exec('UPDATE `' . PREFIX . 'type` SET `sportid`="' . self::$SPECIAL_KEYS['RUNNING_SPORT_ID'] . '" WHERE `accountid`="' . $accountId . '"');
     $DB->insert('conf', $columns, array('general', 'MAINSPORT', self::$SPECIAL_KEYS['MAIN_SPORT_ID'], $accountId));
     $DB->insert('conf', $columns, array('general', 'RUNNINGSPORT', self::$SPECIAL_KEYS['RUNNING_SPORT_ID'], $accountId));
     $DB->insert('conf', $columns, array('general', 'TYPE_ID_RACE', self::$SPECIAL_KEYS['TYPE_ID_RACE'], $accountId));
 }
Esempio n. 27
0
 /**
  * Check for JSON-return
  * @return boolean
  */
 private function returnJSON()
 {
     $Uploader = new ImporterUpload();
     if ($Uploader->thereWasAFile()) {
         echo $Uploader->getResponse();
         Error::getInstance()->debug_displayed = true;
         return true;
     }
     return false;
 }
Esempio n. 28
0
 /**
  * Display the HTML-Footer
  */
 public function displayFooter()
 {
     if (RUNALYZE_DEBUG && Error::getInstance()->hasErrors()) {
         Error::getInstance()->display();
     }
     if (!Request::isAjax() && !isset($_GET['hideHtmlHeader'])) {
         include 'tpl/tpl.Frontend.footer.php';
     }
     Error::getInstance()->footer_sent = true;
 }
Esempio n. 29
0
 /**
  * Update database
  */
 protected function updateDatabase()
 {
     $columns = array_keys($this->data);
     $values = array_values($this->data);
     DB::getInstance()->update($this->tableName(), $this->id, $columns, $values);
     if (self::$DEBUG_QUERIES) {
         Error::getInstance()->addDebug('Updated #' . $this->id . ' ' . $this->tableName() . ': ' . print_r($this->data, true));
     }
 }
Esempio n. 30
0
 /**
  * Parse one trackpoint
  * @param SimpleXMLElement $TP
  */
 protected function parseTrackpoint(&$TP)
 {
     if ($this->distancesAreEmpty) {
         $TP->addChild('DistanceMeters', 1000 * $this->distanceToTrackpoint($TP));
     }
     //else if ((float)$TP->DistanceMeters < $this->gps['km'])
     //	$TP->DistanceMeters = 1000*$this->distanceToTrackpoint($TP);
     $ThisBreakInMeter = (double) $TP->DistanceMeters - $this->lastDistance;
     $ThisBreakInSeconds = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - end($this->gps['time_in_s']) - $this->PauseInSeconds;
     if (Configuration::ActivityForm()->detectPauses()) {
         $NoMove = $this->lastDistance == (double) $TP->DistanceMeters && !$this->isWithoutDistance;
         $TooSlow = !$this->lastPointWasEmpty && $ThisBreakInMeter > 0 && $ThisBreakInSeconds / $ThisBreakInMeter > 6;
     } else {
         $NoMove = $TooSlow = false;
     }
     if (empty($TP->DistanceMeters) && !$this->isWithoutDistance || $NoMove || $TooSlow) {
         $Ignored = false;
         if (count($TP->children()) == 1 || $NoMove || $TooSlow) {
             if ($NoMove && $ThisBreakInSeconds <= self::$IGNORE_NO_MOVE_UNTIL) {
                 $Ignored = true;
             } else {
                 $this->PauseInSeconds += $ThisBreakInSeconds;
                 $this->wasPause = true;
                 $this->pauseDuration += $ThisBreakInSeconds;
             }
             if (self::$DEBUG_SPLITS) {
                 Error::getInstance()->addDebug('PAUSE at ' . (string) $TP->Time . ' of ' . $ThisBreakInSeconds . ', empty point: ' . ($NoMove ? 'no move' . ($Ignored ? ' ignored' : '') : 'empty trackpoint') . ($TooSlow ? ' (too slow, ' . $ThisBreakInMeter . 'm in ' . $ThisBreakInSeconds . 's)' : ''));
             }
         }
         if (!$Ignored) {
             return;
         }
     }
     if (empty($TP->DistanceMeters) && !empty($this->gps['km'])) {
         $TP->DistanceMeters = end($this->gps['km']) * 1000;
     }
     if ($this->TrainingObject->getTimestamp() == 0) {
         $this->TrainingObject->setTimestamp(strtotime((string) $TP->Time));
     }
     if ($this->lastPointWasEmpty) {
         $OldPauseInSeconds = $this->PauseInSeconds;
         $this->PauseInSeconds = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - end($this->gps['time_in_s']);
         $this->pauseDuration += $this->PauseInSeconds - $OldPauseInSeconds;
         $this->wasPause = true;
         if (self::$DEBUG_SPLITS) {
             Error::getInstance()->addDebug('PAUSE at ' . (string) $TP->Time . ' of ' . ($this->PauseInSeconds - $OldPauseInSeconds) . ', last point was empty');
         }
     }
     if ($this->wasPause) {
         $this->TrainingObject->Pauses()->add(new \Runalyze\Model\Trackdata\Pause(end($this->gps['time_in_s']), $this->pauseDuration, end($this->gps['heartrate']), !empty($TP->HeartRateBpm) ? round($TP->HeartRateBpm->Value) : 0));
         $this->wasPause = false;
         $this->pauseDuration = 0;
     }
     $this->lastPointWasEmpty = false;
     $this->lastPoint = (int) $TP->DistanceMeters;
     $this->lastDistance = (double) $TP->DistanceMeters;
     $this->gps['time_in_s'][] = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - $this->PauseInSeconds;
     $this->gps['km'][] = round((double) $TP->DistanceMeters / 1000, ParserAbstract::DISTANCE_PRECISION);
     $this->gps['altitude'][] = (int) $TP->AltitudeMeters;
     $this->gps['heartrate'][] = !empty($TP->HeartRateBpm) ? round($TP->HeartRateBpm->Value) : 0;
     if (!empty($TP->Position)) {
         $this->gps['latitude'][] = (double) $TP->Position->LatitudeDegrees;
         $this->gps['longitude'][] = (double) $TP->Position->LongitudeDegrees;
     } elseif (!empty($this->gps['latitude'])) {
         $this->gps['latitude'][] = end($this->gps['latitude']);
         $this->gps['longitude'][] = end($this->gps['longitude']);
     } else {
         $this->gps['latitude'][] = 0;
         $this->gps['longitude'][] = 0;
     }
     $this->parseExtensionValues($TP);
 }