Exemplo n.º 1
0
require_once "config.php";
require DIR_SYSTEM . "/startup.php";
$request = new Request();
Registry::set("request", $request);
Registry::set('document', new Document());
$start = NULL;
$loader = new Loader();
Registry::set('load', $loader);
$language = new Language();
Registry::set('language', $language);
if (ENABLE_SYSLOG == 1) {
    openlog("piler-webui", LOG_PID, LOG_MAIL);
}
/* check if user has authenticated himself. If not, we send him to login */
Registry::set('username', getAuthenticatedUsername());
Registry::set('admin_user', isAdminUser());
Registry::set('auditor_user', isAuditorUser());
Registry::set('readonly_admin', isReadonlyAdmin());
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PREFIX);
Registry::set('DB_DATABASE', DB_DATABASE);
Registry::set('db', $db);
Registry::set('DB_DRIVER', DB_DRIVER);
$sphx = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME, "", "", SPHINX_DATABASE, "");
Registry::set('sphx', $sphx);
if (MEMCACHED_ENABLED) {
    $memcache = new Memcache();
    foreach ($memcached_servers as $m) {
        $memcache->addServer($m[0], $m[1]);
    }
    Registry::set('memcache', $memcache);
Exemplo n.º 2
0
 /**
  * Action for displaying all the information about a product to the user
  *
  * Action for route: /product
  *
  * @param Request $request
  * @param Application $app
  * @return mixed
  */
 public function productAction(Request $request, Application $app)
 {
     //check if username is stored in session
     $username = getAuthenticatedUsername($app);
     $params = $request->query->all();
     $productName = $_GET['product_name'];
     $error = "";
     $connection = open_database_connection();
     if (!$connection) {
         $_SESSION['errorCategory'] = 'Database';
         $_SESSION['errorMessage'] = 'DB connection failed: ' . mysqli_connect_error();
         header('Location: /error');
     }
     $query = "SELECT * FROM `products` WHERE ProductName = '" . $productName . "'";
     $resultSet = mysqli_query($connection, $query);
     if (mysqli_num_rows($resultSet) > 0) {
         $rows = mysqli_fetch_assoc($resultSet);
         $productName = $rows['ProductName'];
         $productImageURL = $rows['ProductImageURL'];
         $productDescription = $rows['ProductDescription'];
         $productCalories = $rows['ProductCalories'];
         $productAllergyInfo = $rows['ProductAllergyInfo'];
         $productPrice = sprintf("%01.2f", $rows['ProductPrice']);
     } else {
         $error = "An internal server error occurred. Please try again later.";
     }
     close_database_connection($connection);
     // build args array
     // -------------
     $argsArray = array('username' => $username, 'title' => $productName, 'productName' => $productName, 'productImageURL' => $productImageURL, 'productDescription' => $productDescription, 'productCalories' => $productCalories, 'productAllergyInfo' => $productAllergyInfo, 'productPrice' => $productPrice, 'errorMessage' => $error);
     // render template
     // --------------
     $templateName = 'product';
     return $app['twig']->render($templateName . '.html.twig', $argsArray);
 }