/**
  * Returns request parameter value
  * @param string $paramName The parameter name
  * @param string $type The parameter type (RequestTool::PARAM_TYPE_INT, RequestTool::PARAM_TYPE_STRING, etc)
  * @param boolean $isMandatory Specifies if the parameter is mandatory (raises an exception if not set)
  * @param string $defaultValue The default value returned if parameter is not set and not mandatory
  * @param string $method The method used to pass parameters in the request (GET or POST)
  * @return string The parameter value
  */
 public static function &getParameter($paramName, $type, $isMandatory = true, $defaultValue = NULL, $method = RequestTool::METHOD_GET)
 {
     // If method is not specified, try both
     if ($method === RequestTool::METHOD_POST_OR_GET) {
         try {
             // Tries POST method, considers param as mandatory.
             return RequestTool::getParameter($paramName, $type, TRUE, $defaultValue, RequestTool::METHOD_POST);
         } catch (Exception $e) {
             // If nothing is found with POST method, as it is mandatory, an exception as raised. Try to find it with GET method.
             return RequestTool::getParameter($paramName, $type, $isMandatory, $defaultValue, RequestTool::METHOD_GET);
         }
     }
     // Get parameter list
     $paramList = RequestTool::getParameterList($method);
     // Checks if parameter is set
     if (ArrayTool::array_key_exists($paramName, $paramList)) {
         if ($type == RequestTool::PARAM_TYPE_ARRAY) {
             $paramValue = $paramList[$paramName];
         } else {
             if (StringTool::strlen($paramList[$paramName]) > 0) {
                 $paramValue = $paramList[$paramName];
             }
         }
     }
     // Parameter is not set
     if (!isset($paramValue)) {
         // Parameter is mandatory, raising exception
         if ($isMandatory) {
             throw new ParameterException('"' . $paramName . '" request ' . $method . ' parameter is mandatory and not set');
         }
         // else returns default value
         return $defaultValue;
     }
     // if magic quotes activated by server configuration, stripslashes
     if (get_magic_quotes_gpc()) {
         $paramValue = stripslashes($paramValue);
     }
     // Checks if parameter value format is correct
     RequestTool::checkParameterValue($paramValue, $type);
     return $paramValue;
 }
Example #2
0
                    break;
                }
            }
            break;
        case 4:
            $isAnswerCorrect = false;
            $answerValue = RequestTool::getParameter('answer', RequestTool::PARAM_TYPE_FREE, false, false, RequestTool::METHOD_POST);
            $answerData = explode('/', $answerValue);
            if (count($answerData) === 2) {
                foreach ($answerList as $answer) {
                    $distance = sqrt(($answer->x - $answerData[0]) * ($answer->x - $answerData[0]) + ($answer->y - $answerData[1]) * ($answer->y - $answerData[1]));
                    if ($distance <= $answer->text + 5) {
                        $isAnswerCorrect = true;
                        break;
                    }
                }
            }
            break;
    }
    $quizz['questionList'][$currentQuestionIndex]['answer'] = $isAnswerCorrect;
    $player->current_quizz = json_encode($quizz);
    $player->update();
    RequestTool::redirect('/play.php');
}
$smarty->assign('currentQuestionNumber', $currentQuestionIndex + 1);
$smarty->assign('totalQuestionNumber', count($quizz['questionList']));
$smarty->assign('percentCompleted', floor($currentQuestionIndex / count($quizz['questionList']) * 100));
$smarty->assign('question', $currentQuestion->toArray(Question::FORMAT_GAME));
$smarty->assign('page', 'game');
$smarty->display('layout.tpl');
require_once 'init/end.inc.php';
Example #3
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 "":
<?php

// Starts session before header is sent
@session_start();
error_reporting(E_ALL);
ini_set('display_errors', 'On');
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . __DIR__ . '/..' . PATH_SEPARATOR . __DIR__ . '/../framework/php' . PATH_SEPARATOR . __DIR__ . '/../lib/php' . PATH_SEPARATOR . PATH_SEPARATOR . __DIR__ . '/../lib/smarty');
if ($_SERVER['HTTP_HOST'] === 'www.craftanat.fr') {
    require_once 'globals/globals_livedemo.php';
} else {
    require_once 'globals/globals.php';
}
// init Smarty
require_once 'smarty.inc.php';
// Gets class_loader
require_once 'class_loader.inc.php';
// Gets error handler
require_once 'error_handler.inc.php';
// starts transaction
DatabaseFactory::startTransaction();
$authenticationInstance = AuthenticationTool::getInstance();
$isPlayerConnected = $authenticationInstance->isPlayerConnected();
if (!$isPlayerConnected) {
    RequestTool::redirect('/');
}
$adminUser = $authenticationInstance->getConnectedPlayer();
if (!$adminUser->is_admin) {
    RequestTool::redirect('/');
}
$smarty->assign('adminUser', $adminUser);
        }
        if (isset($_FILES['image'])) {
            $imageFile = $_FILES['image'];
            $availableExtensionList = array('jpg', 'jpeg', 'gif', 'png');
            $uploadedFileExtension = strtolower(substr(strrchr($imageFile['name'], '.'), 1));
            if (in_array($uploadedFileExtension, $availableExtensionList)) {
                $destinationFile = 'questions/question_' . $question->id . '.' . $uploadedFileExtension;
                $isUploaded = move_uploaded_file($imageFile['tmp_name'], IMAGE_PATH_FROM_ROOT . $destinationFile);
                if ($isUploaded) {
                    $question->image = IMAGE_PATH . $destinationFile;
                    $question->update();
                }
            }
        }
        if (empty($errorList)) {
            RequestTool::redirect('/admin/questionList.php');
        }
    }
} else {
    if ($questionId !== null) {
        $question = OsteoFactory::getElement('Question', $questionId);
    }
}
if (isset($question)) {
    $smarty->assign('question', $question->toArray(Osteo::FORMAT_ADMIN));
}
$questionCategoryList = OsteoFactory::getElementList('QuestionCategory');
$strucutreList = OsteoFactory::getElementList('Structure');
$smarty->assign('isEditMode', $questionId !== null);
$smarty->assign('submitText', $questionId !== null ? 'Mettre à jour' : 'Ajouter');
$smarty->assign('errorList', $errorList);
<?php

require_once '../../init/initAdmin.inc.php';
OsteoFactory::getElementList('QuestionCategory');
$structureList = OsteoFactory::getElementList('Structure');
$structureId = RequestTool::getParameter('structureId', RequestTool::PARAM_TYPE_UNSIGNED_INT, false, null);
$questionList = OsteoFactory::getElementList('Question', $structureId !== null ? 'structure_id=' . $structureId : null);
//$smarty->assign('javascript', array('manageQuestion'));
//$smarty->assign('css', array('manageElement'));
$smarty->assign('structureList', Osteo::elementListToArray($structureList, Osteo::FORMAT_ADMIN));
$smarty->assign('questionList', Osteo::elementListToArray($questionList, Osteo::FORMAT_ADMIN));
$smarty->assign('currentUrl', RequestTool::getCurrentURL(false));
$smarty->assign('page', 'admin/questionList');
$smarty->display('admin/layout.tpl');
require_once 'init/end.inc.php';
            $structureRequiredStructure->add();
        }
        if (isset($_FILES['image'])) {
            $imageFile = $_FILES['image'];
            $availableExtensionList = array('jpg', 'jpeg', 'gif', 'png');
            $uploadedFileExtension = strtolower(substr(strrchr($imageFile['name'], '.'), 1));
            if (in_array($uploadedFileExtension, $availableExtensionList)) {
                $destinationFile = 'structures/structure_' . $structure->id . '.' . $uploadedFileExtension;
                $isUploaded = move_uploaded_file($imageFile['tmp_name'], IMAGE_PATH_FROM_ROOT . $destinationFile);
                if ($isUploaded) {
                    $structure->image = IMAGE_PATH . $destinationFile;
                    $structure->update();
                }
            }
            if (empty($errorList)) {
                RequestTool::redirect('/admin/structureList.php');
            }
        }
    }
} else {
    if ($structureId !== null) {
        $structure = OsteoFactory::getElement('Structure', $structureId);
    }
}
if (isset($structure)) {
    $smarty->assign('structure', $structure->toArray(Osteo::FORMAT_ADMIN));
}
$structureCategoryList = OsteoFactory::getElementList('StructureCategory');
$structureList = OsteoFactory::getElementList('Structure');
$smarty->assign('isEditMode', $structureId !== null);
$smarty->assign('submitText', $structureId !== null ? 'Mettre à jour' : 'Ajouter');
<?php

// Starts session before header is sent
session_start();
header('Content-type:application/json');
require_once 'globals/globals.php';
// Gets class_loader
require_once 'class_loader.inc.php';
// Gets error handler
require_once 'error_handler.inc.php';
$language = 'fr';
$t = TranslationTool::getInstance($language);
SystemTool::$context = SystemTool::CONTEXT_AJAX;
// starts transaction
DatabaseFactory::startTransaction();
$authenticationInstance = AuthenticationTool::getInstance();
if (!$authenticationInstance->isPlayerConnected()) {
    throw new PlayerNotConnectedException();
}
if (!RequestTool::isAjaxRequest()) {
    throw new Exception();
}