Exemple #1
0
<?php

// Starts session before header is sent
session_start();
require_once '../../../init/initLog.inc.php';
$currentDay = DateTool::getTimeString(DateTool::FORMAT_MYSQL_DATE);
define('TAIL_LOG_FILE', LOG_DIR . '/' . $currentDay . '-web.log');
$grep = RequestTool::getParameter('grep', RequestTool::PARAM_TYPE_FREE, false);
$logFile = file_exists(TAIL_LOG_FILE) ? file(TAIL_LOG_FILE) : array();
$starterLine = SessionTool::getInstance()->getParameter('startLine', false, 0);
$lineCount = count($logFile);
for ($index = $starterLine; $index < $lineCount; ++$index) {
    // Filter lines per grep
    if ($grep && !StringTool::strpos($logFile[$index], $grep)) {
        continue;
    }
    $truncate = true;
    switch (StringTool::substr($logFile[$index], 0, 7)) {
        case "":
            $color = '#5F5';
            // Green
            break;
        case "":
            $color = '#FF5';
            // Yellow
            break;
        case "":
            $color = '#F55';
            // Red
            break;
        case "":
 /**
  * Property writing accessor
  * @param string $propertyName The property name
  * @param string $value The property value
  */
 public function setProperty($propertyName, $value)
 {
     // Non-null value
     if ($value !== NULL) {
         // Numeric value
         if (StringTool::isInt($value)) {
             $value = StringTool::toInt($value, false);
         } else {
             if (StringTool::isFloat($value, FALSE)) {
                 $value = StringTool::toFloat($value, false);
             } else {
                 if (StringTool::endsWith($propertyName, 'date')) {
                     // Date has a 10 length (YYYY-mm-dd)
                     if (StringTool::strlen($value) == 10) {
                         $value = DateTool::stringToTimestamp($value, DateTool::FORMAT_MYSQL_DATE);
                     } else {
                         $value = DateTool::stringToTimestamp($value);
                     }
                 }
             }
         }
         // Day property type
     }
     // Removes table name at the beginning of field name, not for id fields nor xxx_has_xxx tables
     $tableName = DatabaseFactory::getElementTableName($this->getElementClass());
     if (!StringTool::contains($tableName, ElementFactory::TABLE_JOIN_SEPARATOR)) {
         $tablePrefix = $tableName . '_';
         $tableIdField = $tablePrefix . 'id';
         if (StringTool::startsWith($propertyName, $tablePrefix) && (!StringTool::endsWith($propertyName, '_id') || $propertyName == $tableIdField)) {
             $propertyName = StringTool::truncateFirstChars($propertyName, StringTool::strlen($tablePrefix));
         }
     }
     // Updates original property list
     if (!ArrayTool::array_key_exists($propertyName, $this->propertyList)) {
         // It's the first time this property gets a value, it will be updated (set a null value to original property list)
         $this->originalPropertyList[$propertyName] = NULL;
     } else {
         if (ArrayTool::array_key_exists($propertyName, $this->originalPropertyList)) {
             // Attribute value had already changed (originalPropertyList already has a value for this property)
             // If value has been reset to original value, removes the update of the property
             if ($value == $this->originalPropertyList[$propertyName]) {
                 unset($this->originalPropertyList[$propertyName]);
             }
         } else {
             if ($value !== $this->propertyList[$propertyName]) {
                 // If value has changed, updates original value
                 $this->originalPropertyList[$propertyName] = $this->propertyList[$propertyName];
             }
         }
     }
     // Sets property new value
     $this->propertyList[$propertyName] = $value;
 }
Exemple #3
0
if ($structureId !== null || !$player->current_quizz) {
    try {
        $structureId = RequestTool::getParameter('structureId', RequestTool::PARAM_TYPE_UNSIGNED_INT);
        $structure = OsteoFactory::getElement('Structure', $structureId);
    } catch (Exception $e) {
        // Incorrect parameter or invalid structure: do nothing
        RequestTool::redirect('/');
    }
    $isCraft = RequestTool::getParameter('craft', RequestTool::PARAM_TYPE_BOOLEAN, false, false);
    $questionList = OsteoFactory::getElementList('Question', ($isCraft ? 'question_is_in_craft_quizz=1 AND ' : '') . 'structure_id=' . $structureId, 'RAND() LIMIT ' . $structure->question_number);
    $quizz = array('structureId' => $structureId, 'questionList' => array());
    foreach ($questionList as $question) {
        $quizz['questionList'][] = array('questionId' => $question->id, 'answer' => null);
    }
    $quizz['isCraft'] = $isCraft;
    $quizz['startDate'] = DateTool::getTimestamp();
    $player->current_quizz = json_encode($quizz);
    $player->update();
    $currentQuestionIndex = 0;
    $currentQuestion = reset($questionList);
} else {
    if ($player->current_quizz) {
        $quizz = json_decode($player->current_quizz, true);
        foreach ($quizz['questionList'] as $questionNumber => $quizzQuestion) {
            if ($quizzQuestion['answer'] === null) {
                $currentQuestion = OsteoFactory::getElement('Question', $quizzQuestion['questionId']);
                $currentQuestionIndex = $questionNumber;
                break;
            }
        }
        // No questionwith no answer: test is over
Exemple #4
0
 function include_js_alaxos($inline = false)
 {
     /*
      * The alaxos.js file contains code that need jquery declared as $j
      */
     $this->include_js_jquery($inline);
     $this->include_js_jquery_no_conflict($inline);
     /*
      * The alaxos.js file contains code that need a date_format global variable
      */
     $this->scriptBlock('var date_format = "' . strtolower(DateTool::get_date_format()) . '";', array('inline' => $inline));
     $this->scriptBlock('var application_root = "' . $this->url('/') . '";', array('inline' => $inline));
     $this->script('/alaxos/js/alaxos/alaxos.js', array('inline' => $inline));
 }
 private function get_day_header_values()
 {
     DateTool::set_current_locale($this->locale);
     $format = '';
     switch ($this->display_mode) {
         case self::DISPLAY_MODE_MONTH:
             $format = $this->month_day_header_format;
             break;
         case self::DISPLAY_MODE_DAY:
         case self::DISPLAY_MODE_DAY_HOUR:
             $format = $this->day_day_header_format;
             break;
         case self::DISPLAY_MODE_WEEK:
         case self::DISPLAY_MODE_WEEK_HOUR:
             $format = $this->week_day_header_format;
             break;
     }
     if ($this->display_day_names || $this->display_mode == self::DISPLAY_MODE_WEEK || $this->display_mode == self::DISPLAY_MODE_WEEK_HOUR || $this->display_mode == self::DISPLAY_MODE_MONTH || $this->display_mode == self::DISPLAY_MODE_DAY || $this->display_mode == self::DISPLAY_MODE_DAY_HOUR) {
         $day_names = array();
         $date_cursor = $this->first_date_to_show;
         if ($this->display_mode == self::DISPLAY_MODE_DAY || $this->display_mode == self::DISPLAY_MODE_DAY_HOUR) {
             $day_names[1] = strftime($format, strtotime($date_cursor));
             $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
         } else {
             for ($i = 1; $i <= 7; $i++) {
                 $day_names[$i] = strftime($format, strtotime($date_cursor));
                 $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
             }
         }
     }
     return $day_names;
 }
 private function get_sql_date($date_value)
 {
     return DateTool::date_to_sql($date_value);
 }
 /**
  * Traces a log message
  * @param string $message The message
  * @param int $logLevel The log level
  * @color string $color The color of the message in the log
  */
 private function log($message, $logLevel = LOG_MIN_LEVEL, $color = NULL)
 {
     // Tests log level
     if (!IS_FILE_LOG_ENABLED || !$this->logFile) {
         return;
     }
     if ($this->detailedMode || $logLevel >= LOG_MIN_LEVEL && (!$this->silentMode || $logLevel >= LogTool::WARNING_LEVEL)) {
         $logHeaderList = array();
         // Sets headers
         // Log type
         if ($logLevel >= LogTool::ERROR_LEVEL) {
             $logHeaderList[LogTool::TYPE_FIELD] = 'ERROR';
         } else {
             if ($logLevel >= LogTool::WARNING_LEVEL) {
                 $logHeaderList[LogTool::TYPE_FIELD] = 'WARNING';
             } else {
                 if ($logLevel >= LogTool::NOTICE_LEVEL) {
                     $logHeaderList[LogTool::TYPE_FIELD] = 'NOTICE';
                 } else {
                     $logHeaderList[LogTool::TYPE_FIELD] = 'DEBUG';
                 }
             }
         }
         // Remote ip
         if (ArrayTool::array_key_exists('REMOTE_ADDR', $_SERVER)) {
             $logHeaderList[LogTool::REMOTE_IP_FIELD] = $_SERVER['REMOTE_ADDR'];
         } else {
             $logHeaderList[LogTool::REMOTE_IP_FIELD] = '';
         }
         // Current uri/script
         $logHeaderList[LogTool::URI_FIELD] = basename($_SERVER['PHP_SELF']);
         // Current time
         $logHeaderList[LogTool::DATE_FIELD] = DateTool::getTimeString(DateTool::FORMAT_TIME);
         // host
         $logHeaderList[LogTool::HOST_FIELD] = php_uname('n');
         // computes header
         $logHeader = '[' . $logHeaderList[LogTool::DATE_FIELD] . '] ' . $logHeaderList[LogTool::TYPE_FIELD] . ' [' . ($logHeaderList[LogTool::REMOTE_IP_FIELD] ? $logHeaderList[LogTool::REMOTE_IP_FIELD] . ' > ' : '') . $logHeaderList[LogTool::HOST_FIELD] . '] ' . $logHeaderList[LogTool::URI_FIELD];
         // computes log line
         $logLine = $color . $logHeader . ': ' . str_replace(PHP_EOL, PHP_EOL . $logHeader . ': ', $message) . PHP_EOL;
         // Opens new log file if date has changed
         if (DateTool::getTimeString(DateTool::FORMAT_MYSQL_DATE) != $this->currentLogDate) {
             $this->closeLogFile();
             $this->openLogFile();
         }
         // Finally write the line in log file
         fwrite($this->logFile, $logLine);
     }
 }
 /**
  * Gets property value in correct format for request
  * @param string $propertyName The name of the property to detect field type
  * @param string $propertyValue The property value
  * @return string the value in correct format for the request
  */
 private static function getFormattedPropertyValue($elementClass, $propertyName, $propertyValue)
 {
     // NULL value
     if ($propertyValue === null) {
         $formattedValue = 'NULL';
     } else {
         $formattedValue = '\'';
         if (StringTool::isInt($propertyValue)) {
             // Datetime / date property type
             if (StringTool::endsWith($propertyName, 'date')) {
                 $formattedValue .= DateTool::timestampToString($propertyValue);
             } else {
                 $formattedValue .= StringTool::toInt($propertyValue, FALSE);
             }
         } else {
             if (StringTool::isFloat($propertyValue, FALSE)) {
                 $formattedValue .= StringTool::toFloat($propertyValue, FALSE);
             } else {
                 $formattedValue .= $elementClass::getDatabaseConnection()->realEscapeString($propertyValue);
             }
         }
         $formattedValue .= '\'';
     }
     return $formattedValue;
 }
Exemple #9
0
 /**
  * Return the CSS class name needed by the frequency-decoder.com datepicker used to recognize the date format.
  * The date format is determined by the current locale (that can be set by the DateTool :: set_current_locale()).
  *
  * @param $class_name
  */
 function get_datepicker_css_class($class_name = 'inputDate')
 {
     $locale = DateTool::get_current_locale();
     $locale = strtolower($locale);
     switch ($locale) {
         case 'fr_ch':
         case 'fr_ch.utf-8':
         case 'fr_fr':
             return $class_name . ' format-d-m-y divider-dot';
         case 'en_en':
         case 'en_us':
         case 'en_en.utf-8':
         case 'en_us.utf-8':
             return $class_name . ' format-y-m-d divider-dash';
         default:
             return 'H:i:s';
     }
 }
Exemple #10
0
require_once '../init/init.inc.php';
//$smarty->assign('javascript', array('manageQuestion'));
//$smarty->assign('css', array('manageElement'));
$smarty->assign('page', 'index');
if (AuthenticationTool::getInstance()->isPlayerConnected()) {
    OsteoFactory::getElementList('Component');
    $structureList = OsteoFactory::getElementList('Structure', null, 'structure_category_order, structure_order ASC', 'structure LJ player_has_structure, structure_category IJ structure');
    $smarty->assign('structureList', Osteo::elementListToArray($structureList, Structure::FORMAT_PLAYER_STRUCTURE_LIST));
    $componentList = OsteoFactory::getElementList('Component');
    $smarty->assign('componentList', Osteo::elementListToArray($componentList, Component::FORMAT_PLAYER_COMPONENT_LIST));
}
$scoreDataList = Structure::getDatabaseConnection()->selectRequest('SELECT player_name, SUM(is_crafted) AS crafted, SUM(best_score) AS score, SUM(best_time) AS time FROM player INNER JOIN player_has_structure ON player.player_id = player_has_structure.player_id GROUP BY player.player_id ORDER BY crafted DESC, score DESC, time ASC LIMIT 10');
$scoreList = array();
foreach ($scoreDataList as $scoreData) {
    if (!$scoreData['time']) {
        $formattedTime = '-';
    } else {
        $formattedTime = DateTool::timestampToString($scoreData['time'], DateTool::FORMAT_MINUTES);
        if (StringTool::startsWith($formattedTime, '00m')) {
            $formattedTime = StringTool::truncateFirstChars($formattedTime, 4);
        }
        if (StringTool::startsWith($formattedTime, '0')) {
            $formattedTime = StringTool::truncateFirstChars($formattedTime, 1);
        }
    }
    $scoreList[] = array('player_name' => $scoreData['player_name'], 'crafted' => $scoreData['crafted'], 'score' => $scoreData['score'], 'time' => $formattedTime);
}
$smarty->assign('scoreList', $scoreList);
$smarty->display('layout.tpl');
require_once 'init/end.inc.php';
Exemple #11
0
<?php

/*
 * Load all files in alaxos/libs folder
 *
 * Note: The path to the lib folder is relative to the current file
 *       If you copy this code into your APP bootstrap.php file, adapt the folder path
 *       Alternatively, you can call the Alaxos plugin bootstrap.php file from within your APP bootstrap.php file like this:
 *
 *       require_once(ROOT . DS . 'plugins' . DS . 'alaxos' . DS . 'config' . DS . 'bootstrap.php');
 *       or
 *       require_once(APP . DS . 'plugins' . DS . 'alaxos' . DS . 'config' . DS . 'bootstrap.php');
 */
$f = new Folder(dirname(__FILE__) . DS . '..' . DS . 'libs');
$files = $f->read();
foreach ($files[1] as $file) {
    if ($file != 'additional_translations.php') {
        require_once $f->path . $file;
    }
}
/*
 * Some functions of the Alaxos plugin need to have a locale set. By default, a locale is set below to make them work.
 *
 * But this is up to you to use the DateTool :: set_current_locale() function in your application to modify this default locale.
 *
 * Don't modify it below, but do it for instance in the beforeFilter() function of your AppController.
 * This will prevent to forget to modify it again whenever you make an Alaxos plugin update.
 */
DateTool::set_current_locale('en');
 /**
  * Converts a timestamp to a time string
  * @param int $timestamp The timestamp (default is NULL for now)
  * @param string $format The string format
  * @return string The time string
  */
 public static function timestampToString($timestamp, $format = DateTool::FORMAT_MYSQL_DATETIME)
 {
     if (!StringTool::isInt($timestamp)) {
         throw new Exception('Unable to convert timestamp to time string : "' . $timestamp . '" is not an integer');
     }
     return DateTool::getTimeString($format, $timestamp);
 }
 private function get_calendar_cells_with_hours($calendar_data)
 {
     $dates = $calendar_data['dates'];
     //debug($calendar_data);
     $date_keys = array_keys($dates);
     //debug($date_keys);
     $cells = array(array('cell_options' => array('class' => 'dayname')));
     $days_names = $this->get_day_names_cells($calendar_data);
     $cells = array_merge($cells, $days_names);
     $hours = DateTool::get_time_array($calendar_data['hour_start'], $calendar_data['hour_end'], $calendar_data['hour_interval']);
     /*
      * Hour cell content
      */
     $hour_string = '';
     $total_height = 0;
     $css_class = 'hour_zone';
     foreach ($hours as $index => $hour) {
         if ($index == count($hours) - 1) {
             $css_class = 'last_hour_zone';
         }
         $hour_string .= '<div class="' . $css_class . '" style="height:' . $this->time_display_height . 'px;">' . $hour . '</div>';
         $total_height += $this->time_display_height;
     }
     $hour_display_height = $this->time_display_height / $calendar_data['hour_interval'];
     $cell_content = array();
     $cell_content['content'] = $hour_string;
     $cell_content['cell_options'] = array('class' => 'hour_column');
     $cells[] = $cell_content;
     //debug(count($date_keys));
     for ($i = 0; $i < count($date_keys); $i++) {
         $cell_content = array();
         $current_date = $date_keys[$i];
         $calendar_start_datetime = '';
         $calendar_end_datetime = '';
         $event_start_date = '';
         $event_end_date = '';
         //	        debug($dates);
         //	        debug($date_keys[$i]);
         if (isset($dates[$date_keys[$i]]['events'])) {
             $cell_content['content'] = '';
             foreach ($dates[$date_keys[$i]]['events'] as $event) {
                 $event_start_date = new Datetime($event['model'][$event['options']['model_name']][$event['options']['start_field']]);
                 $event_end_date = new Datetime($event['model'][$event['options']['model_name']][$event['options']['end_field']]);
                 $calendar_start_datetime = new Datetime($current_date . ' ' . DateTool::get_time_from_hour($calendar_data['hour_start']));
                 $calendar_end_datetime = new Datetime($current_date . ' ' . DateTool::get_time_from_hour($calendar_data['hour_end']));
                 if ($event_start_date <= $calendar_start_datetime && $event_end_date > $calendar_start_datetime || $event_start_date < $calendar_end_datetime && $event_end_date >= $calendar_end_datetime || $event_start_date >= $calendar_start_datetime && $event_end_date <= $calendar_end_datetime) {
                     /*
                      * Event must be displayed
                      */
                     $top_margin = 2;
                     $id = $event['model'][$event['options']['model_name']][$event['options']['id_field']];
                     $controller = $event['options']['link_controller'];
                     $action = $event['options']['link_action'];
                     $event_start_timestamp = strtotime($event['model'][$event['options']['model_name']][$event['options']['start_field']]);
                     $event_end_timestamp = strtotime($event['model'][$event['options']['model_name']][$event['options']['end_field']]);
                     $calendar_start_timestamp = strtotime($current_date . ' ' . $calendar_data['hour_start'] . ':00:00');
                     $calendar_end_timestamp = strtotime($current_date . ' ' . $calendar_data['hour_end'] . ':00:00');
                     //debug($event_start_timestamp);
                     //debug($event_end_timestamp);
                     //debug($calendar_start_timestamp);
                     //debug($calendar_end_timestamp);
                     if ($event_start_date > $calendar_start_datetime) {
                         /*
                          * Calculate top-margin if event doesn't start at the top of the calendar
                          */
                         $hour_difference = ($event_start_timestamp - $calendar_start_timestamp) / 3600;
                         $border_height_compensation = $hour_difference / $calendar_data['hour_interval'];
                         $top_margin = $hour_difference * $hour_display_height + 0.75 * $border_height_compensation;
                     }
                     /*
                      * Check if event has to start at the top of the calendar
                      */
                     $display_start_before = false;
                     if ($event_start_timestamp < $calendar_start_timestamp) {
                         $event_start_timestamp = $calendar_start_timestamp;
                         $event_start_date = $calendar_start_datetime;
                         $display_start_before = true;
                     }
                     /*
                      * Check if event has to end at the bottom of the calendar
                      */
                     $display_end_after = false;
                     if ($event_end_timestamp > $calendar_end_timestamp) {
                         $event_end_timestamp = $calendar_end_timestamp;
                         $event_end_date = $calendar_end_datetime;
                         $display_end_after = true;
                     }
                     /*
                      * Event height
                      */
                     $hour_difference = ($event_end_timestamp - $event_start_timestamp) / 3600;
                     $border_height_compensation = $hour_difference / $calendar_data['hour_interval'];
                     $event_height = $hour_difference * $hour_display_height + 0.75 * $border_height_compensation;
                     /*
                      * Infos to display for the event
                      */
                     $event_title = $event['model'][$event['options']['model_name']][$event['options']['title_field']];
                     if ($display_start_before) {
                         $display_start_time = '...';
                     } else {
                         $display_start_time = $event_start_date->format('H:i');
                     }
                     if ($display_end_after) {
                         $display_end_time = '...';
                     } else {
                         $display_end_time = $event_end_date->format('H:i');
                     }
                     $event_html = '<div id="event_' . $id . '" class="' . $event['options']['css_class'] . ' event_hour" style="margin-top:' . $top_margin . 'px;height:' . $event_height . 'px"><div class="event_display_time">' . $display_start_time . '</div><div style="height:' . ($event_height - 30) . 'px;">' . $event_title . '</div><div class="event_display_time">' . $display_end_time . '</div></div>';
                     $event_html = $this->AlaxosHtml->link($event_html, array('controller' => $controller, 'action' => $action, $id), array('escape' => false));
                     //debug($event_height);
                     if ($event_height < 80) {
                         /*
                          * If the event display is not high enough, better to make the event nowrap
                          * to have place in width to put the title
                          */
                         $cell_content['content'] .= '<td nowrap="nowrap">' . $event_html . '</td>';
                     } else {
                         $cell_content['content'] .= '<td>' . $event_html . '</td>';
                     }
                 }
             }
         }
         //debug($current_date);
         $cell_content['cell_options'] = array('class' => $dates[$current_date]['cell_options']['class']);
         if (isset($cell_content['content'])) {
             $cell_content['content'] = '<table class="event_aligner" border="0" cellspacing="0" cellpadding="1"><tr>' . $cell_content['content'] . '</tr></table>';
         }
         $cells[] = $cell_content;
     }
     return $cells;
 }
Exemple #14
0
 /**
  *
  * @param string $start_datetime
  * @param string $end_datetime
  * @param string $datetime_to_check
  * @return bool Indicates wether the time to check is between the two given times
  */
 public static function datetime_is_in_interval($start_datetime, $end_datetime, $datetime_to_check = null, $locale = 'sql')
 {
     if (!isset($datetime_to_check)) {
         $datetime_to_check = DateTool::get_current_datetime($locale);
     }
     $start_datetime = DateTool::get_complete_datetime($start_datetime);
     $end_datetime = DateTool::get_complete_datetime($end_datetime);
     $datetime_to_check = DateTool::get_complete_datetime($datetime_to_check);
     $comparison1 = DateTool::compare_dates($start_datetime, $datetime_to_check, $locale);
     $comparison2 = DateTool::compare_dates($datetime_to_check, $end_datetime, $locale);
     if (($comparison1 == '<' || $comparison1 == '=') && $comparison2 == '<') {
         return true;
     } else {
         return false;
     }
 }
Exemple #15
0
            }
        }
    }
}
if (!$quizz['isCraft']) {
    $questionDataList = array();
    foreach ($quizz['questionList'] as $questionData) {
        $question = OsteoFactory::getElement('Question', $questionData['questionId']);
        $questionDataList[] = $question->toArray(Question::FORMAT_RESULT, $questionData['answer']);
    }
    $smarty->assign('questionList', $questionDataList);
}
$smarty->assign('isCraft', $quizz['isCraft']);
$smarty->assign('isSuccess', $isSuccess);
$smarty->assign('previousBestScore', $previousBestScore);
$smarty->assign('previousBestTime', $previousBestTime);
$smarty->assign('isBestScore', $isBestScore);
$smarty->assign('isBestTime', $isBestTime);
$smarty->assign('correctAnswerNumber', $correctAnswerNumber);
$formattedTime = DateTool::timestampToString($time, DateTool::FORMAT_MINUTES);
if (StringTool::startsWith($formattedTime, '00m')) {
    $formattedTime = StringTool::truncateFirstChars($formattedTime, 4);
}
if (StringTool::startsWith($formattedTime, '0')) {
    $formattedTime = StringTool::truncateFirstChars($formattedTime, 1);
}
$smarty->assign('totalTime', $formattedTime);
$smarty->assign('totalQuestionNumber', count($quizz['questionList']));
$smarty->assign('page', 'score');
$smarty->display('layout.tpl');
require_once 'init/end.inc.php';