diff --git a/MySqlClass.php b/MySqlClass.php index fa1fd18..6df9784 100644 --- a/MySqlClass.php +++ b/MySqlClass.php @@ -5,85 +5,82 @@ class MysqlClass private $nomehost = "localhost"; private $nomeuser = "root"; private $password = "root"; - - /* - private $nomehost = "sql.gruppolapastamadre.it"; - private $nomeuser = "w18092_ricuser"; - private $password = "RTvg0o6IESoqQyx8CCJn"; - */ - private $mydb = "w18092_ricettario"; - // controllo sulle connessioni attive - private $attiva = false; - private $connessione = null; - - // funzione per la connessione a MySQL - public function connetti() - { - if(!$this->attiva) - { - $this->connessione = mysql_connect($this->nomehost,$this->nomeuser,$this->password); - if ($this->connessione == FALSE) - die(mysql_error()); - mysql_select_db($this->mydb, $this->connessione) or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php"); - $this->attiva = true; - } - else{ - return true; - } - - } - - public function executeQuery($queryStr) - { - $this->connetti(); - - if (!$res = mysql_query($queryStr, $this->connessione)) die(mysql_error()); - return true; - return false; - } - - public function insertRecord($queryStr) - { - $this->connetti(); - - if (!$res = mysql_query($queryStr, $this->connessione)) die(mysql_error()); - return mysql_insert_id(); - } - - public function queryToObject($queryStr) - { - $this->connetti(); - - $sth = mysql_query($queryStr, $this->connessione) or die(mysql_error()); - - $rows = array(); - while($r = mysql_fetch_assoc($sth)) { - array_push($rows,array_map('utf8_encode', $r)); - } - mysql_free_result($sth); - return $rows; - } - - // funzione per la chiusura della connessione - public function disconnetti() - { - if($this->attiva) - { - if(mysql_close($this->connessione)) - { - $this->attiva = false; - return true; - } - else - { - return false; - } - } - } - - public function __destruct() - { - $this->disconnetti(); - } - } + private $mydb = "w18092_ricettario"; + /* + private $nomehost = "sql.gruppolapastamadre.it"; + private $nomeuser = "w18092_ricuser"; + private $password = "RTvg0o6IESoqQyx8CCJn"; + private $mydb = "w18092_ricettario"; + */ + // controllo sulle connessioni attive + private $attiva = false; + private $connessione = null; + + // funzione per la connessione a MySQL + public function connetti() { + if (!$this->attiva) { + $this->connessione = mysqli_connect($this->nomehost, $this->nomeuser, $this->password); + if ($this->connessione == FALSE) + die(mysqli_error()); + mysqli_select_db($this->connessione, $this->mydb) or die("Errore nella selezione del database. Verificare i parametri nel file config.inc.php"); + $this->attiva = true; + } + else { + return true; + } + } + + public function executeQuery($queryStr) { + $this->connetti(); + + if (!$res = mysqli_query($this->connessione, $queryStr)) + die(mysqli_error()); + return true; + } + + public function insertRecord($queryStr) { + $this->connetti(); + + if (!$res = mysqli_query($this->connessione, $queryStr)) + die(mysqli_error()); + return mysqli_insert_id($this->connessione); + } + + public function queryToObject($queryStr, $encode = true) { + $this->connetti(); + + $sth = mysqli_query($this->connessione, $queryStr) or die(mysqli_error()); + + if($encode){ + $rows = array(); + while ($r = mysqli_fetch_assoc($sth)) { + array_push($rows, array_map('utf8_encode', $r)); + } + mysqli_free_result($sth); + return $rows; + } + else + { + return mysqli_fetch_array($sth); + } + } + + // funzione per la chiusura della connessione + public function disconnetti() { + if ($this->attiva) { + if (mysqli_close($this->connessione)) { + $this->attiva = false; + return true; + } else { + return false; + } + } + } + + public function __destruct() { + $this->disconnetti(); + } + +} + ?> \ No newline at end of file diff --git a/Slim/Environment.php b/Slim/Environment.php index a15e1e4..3459783 100644 --- a/Slim/Environment.php +++ b/Slim/Environment.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -140,7 +140,10 @@ class Environment implements \ArrayAccess, \IteratorAggregate $env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes // Virtual path - $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path + $env['PATH_INFO'] = $requestUri; + if (substr($requestUri, 0, strlen($physicalPath)) == $physicalPath) { + $env['PATH_INFO'] = substr($requestUri, strlen($physicalPath)); // <-- Remove physical path + } $env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string $env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash @@ -151,7 +154,8 @@ class Environment implements \ArrayAccess, \IteratorAggregate $env['SERVER_NAME'] = $_SERVER['SERVER_NAME']; //Number of server port that is running the script - $env['SERVER_PORT'] = $_SERVER['SERVER_PORT']; + //Fixes: https://github.com/slimphp/Slim/issues/962 + $env['SERVER_PORT'] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80; //HTTP request headers (retains HTTP_ prefix to match $_SERVER) $headers = \Slim\Http\Headers::extract($_SERVER); @@ -191,9 +195,9 @@ class Environment implements \ArrayAccess, \IteratorAggregate { if (isset($this->properties[$offset])) { return $this->properties[$offset]; - } else { - return null; } + + return null; } /** diff --git a/Slim/Exception/Pass.php b/Slim/Exception/Pass.php index 99d95c2..30a3a1d 100644 --- a/Slim/Exception/Pass.php +++ b/Slim/Exception/Pass.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Exception/Stop.php b/Slim/Exception/Stop.php index a251851..28aba78 100644 --- a/Slim/Exception/Stop.php +++ b/Slim/Exception/Stop.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Helper/Set.php b/Slim/Helper/Set.php index 9538b69..bf6e895 100644 --- a/Slim/Helper/Set.php +++ b/Slim/Helper/Set.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -160,7 +160,7 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate public function __unset($key) { - return $this->remove($key); + $this->remove($key); } /** @@ -215,8 +215,8 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate /** * Ensure a value or object will remain globally unique - * @param string $key The value or object name - * @param Closure The closure that defines the object + * @param string $key The value or object name + * @param \Closure $value The closure that defines the object * @return mixed */ public function singleton($key, $value) @@ -234,8 +234,8 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate /** * Protect closure from being directly invoked - * @param Closure $callable A closure to keep from being invoked and evaluated - * @return Closure + * @param \Closure $callable A closure to keep from being invoked and evaluated + * @return \Closure */ public function protect(\Closure $callable) { diff --git a/Slim/Http/Cookies.php b/Slim/Http/Cookies.php index cf13801..3b2e11e 100644 --- a/Slim/Http/Cookies.php +++ b/Slim/Http/Cookies.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Http/Headers.php b/Slim/Http/Headers.php index 1704b80..c5e08f2 100644 --- a/Slim/Http/Headers.php +++ b/Slim/Http/Headers.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index 735484b..2cd88b4 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -169,9 +169,9 @@ class Request return true; } elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') { return true; - } else { - return false; } + + return false; } /** diff --git a/Slim/Http/Response.php b/Slim/Http/Response.php index c55d647..48c76d8 100644 --- a/Slim/Http/Response.php +++ b/Slim/Http/Response.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -85,6 +85,7 @@ class Response implements \ArrayAccess, \Countable, \IteratorAggregate 204 => '204 No Content', 205 => '205 Reset Content', 206 => '206 Partial Content', + 226 => '226 IM Used', //Redirection 3xx 300 => '300 Multiple Choices', 301 => '301 Moved Permanently', @@ -116,13 +117,20 @@ class Response implements \ArrayAccess, \Countable, \IteratorAggregate 418 => '418 I\'m a teapot', 422 => '422 Unprocessable Entity', 423 => '423 Locked', + 426 => '426 Upgrade Required', + 428 => '428 Precondition Required', + 429 => '429 Too Many Requests', + 431 => '431 Request Header Fields Too Large', //Server Error 5xx 500 => '500 Internal Server Error', 501 => '501 Not Implemented', 502 => '502 Bad Gateway', 503 => '503 Service Unavailable', 504 => '504 Gateway Timeout', - 505 => '505 HTTP Version Not Supported' + 505 => '505 HTTP Version Not Supported', + 506 => '506 Variant Also Negotiates', + 510 => '510 Not Extended', + 511 => '511 Network Authentication Required' ); /** diff --git a/Slim/Http/Util.php b/Slim/Http/Util.php index dafedb3..00cac0e 100644 --- a/Slim/Http/Util.php +++ b/Slim/Http/Util.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -60,9 +60,9 @@ class Util $strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes; if ($strip) { return self::stripSlashes($rawData); - } else { - return $rawData; } + + return $rawData; } /** diff --git a/Slim/Log.php b/Slim/Log.php index d872e87..13cb825 100644 --- a/Slim/Log.php +++ b/Slim/Log.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -306,7 +306,12 @@ class Log if (!isset(self::$levels[$level])) { throw new \InvalidArgumentException('Invalid log level supplied to function'); } else if ($this->enabled && $this->writer && $level <= $this->level) { - $message = (string)$object; + if (is_array($object) || (is_object($object) && !method_exists($object, "__toString"))) { + $message = print_r($object, true); + } else { + $message = (string) $object; + } + if (count($context) > 0) { if (isset($context['exception']) && $context['exception'] instanceof \Exception) { $message .= ' - ' . $context['exception']; diff --git a/Slim/LogWriter.php b/Slim/LogWriter.php index 5e44e2f..afa3ae9 100644 --- a/Slim/LogWriter.php +++ b/Slim/LogWriter.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Middleware.php b/Slim/Middleware.php index be23100..79fbb1e 100644 --- a/Slim/Middleware.php +++ b/Slim/Middleware.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Middleware/ContentTypes.php b/Slim/Middleware/ContentTypes.php index 08049db..fcc2242 100644 --- a/Slim/Middleware/ContentTypes.php +++ b/Slim/Middleware/ContentTypes.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -116,7 +116,7 @@ class ContentTypes extends \Slim\Middleware { if (function_exists('json_decode')) { $result = json_decode($input, true); - if ($result) { + if(json_last_error() === JSON_ERROR_NONE) { return $result; } } diff --git a/Slim/Middleware/Flash.php b/Slim/Middleware/Flash.php index 96f685e..593082f 100644 --- a/Slim/Middleware/Flash.php +++ b/Slim/Middleware/Flash.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Middleware/MethodOverride.php b/Slim/Middleware/MethodOverride.php index 7fa3bb0..1298767 100644 --- a/Slim/Middleware/MethodOverride.php +++ b/Slim/Middleware/MethodOverride.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE diff --git a/Slim/Middleware/PrettyExceptions.php b/Slim/Middleware/PrettyExceptions.php index 8a56442..aafda0f 100644 --- a/Slim/Middleware/PrettyExceptions.php +++ b/Slim/Middleware/PrettyExceptions.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -89,7 +89,7 @@ class PrettyExceptions extends \Slim\Middleware $message = $exception->getMessage(); $file = $exception->getFile(); $line = $exception->getLine(); - $trace = str_replace(array('#', '\n'), array('
#', '
'), $exception->getTraceAsString()); + $trace = str_replace(array('#', "\n"), array('
#', '
'), $exception->getTraceAsString()); $html = sprintf('

%s

', $title); $html .= '

The application could not run because of the following error:

'; $html .= '

Details

'; diff --git a/Slim/Middleware/SessionCookie.php b/Slim/Middleware/SessionCookie.php index a467475..939c977 100644 --- a/Slim/Middleware/SessionCookie.php +++ b/Slim/Middleware/SessionCookie.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -119,15 +119,10 @@ class SessionCookie extends \Slim\Middleware if (session_id() === '') { session_start(); } - $value = $this->app->getCookie($this->settings['name']); - if ($value) { - try { - $_SESSION = unserialize($value); - } catch (\Exception $e) { - $this->app->getLog()->error('Error unserializing session cookie value! ' . $e->getMessage()); - } + $value = json_decode($value, true); + $_SESSION = is_array($value) ? $value : array(); } else { $_SESSION = array(); } @@ -138,7 +133,7 @@ class SessionCookie extends \Slim\Middleware */ protected function saveSession() { - $value = serialize($_SESSION); + $value = json_encode($_SESSION); if (strlen($value) > 4096) { $this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.'); diff --git a/Slim/Route.php b/Slim/Route.php index 99b47a1..2127e62 100644 --- a/Slim/Route.php +++ b/Slim/Route.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -288,6 +288,9 @@ class Route public function appendHttpMethods() { $args = func_get_args(); + if(count($args) && is_array($args[0])){ + $args = $args[0]; + } $this->methods = array_merge($this->methods, $args); } @@ -298,6 +301,9 @@ class Route public function via() { $args = func_get_args(); + if(count($args) && is_array($args[0])){ + $args = $args[0]; + } $this->methods = array_merge($this->methods, $args); return $this; diff --git a/Slim/Router.php b/Slim/Router.php index b0e7a60..87e06ed 100644 --- a/Slim/Router.php +++ b/Slim/Router.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -232,9 +232,9 @@ class Router $this->getNamedRoutes(); if ($this->hasNamedRoute($name)) { return $this->namedRoutes[(string) $name]; - } else { - return null; } + + return null; } /** diff --git a/Slim/Slim.php b/Slim/Slim.php index cb8ef66..4a83595 100644 --- a/Slim/Slim.php +++ b/Slim/Slim.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -54,7 +54,7 @@ class Slim /** * @const string */ - const VERSION = '2.4.2'; + const VERSION = '2.6.1'; /** * @var \Slim\Helper\Set @@ -231,22 +231,22 @@ class Slim public function __get($name) { - return $this->container[$name]; + return $this->container->get($name); } public function __set($name, $value) { - $this->container[$name] = $value; + $this->container->set($name, $value); } public function __isset($name) { - return isset($this->container[$name]); + return $this->container->has($name); } public function __unset($name) { - unset($this->container[$name]); + $this->container->remove($name); } /** @@ -906,7 +906,12 @@ class Slim } } - return $value; + /* + * transform $value to @return doc requirement. + * \Slim\Http\Util::decodeSecureCookie - is able + * to return false and we have to cast it to null. + */ + return $value === false ? null : $value; } /** @@ -1100,6 +1105,18 @@ class Slim $this->halt($status); } + /** + * RedirectTo + * + * Redirects to a specific named route + * + * @param string $route The route name + * @param array $params Associative array of URL parameters and replacement values + */ + public function redirectTo($route, $params = array(), $status = 302){ + $this->redirect($this->urlFor($route, $params), $status); + } + /******************************************************************************** * Flash Messages *******************************************************************************/ @@ -1138,6 +1155,16 @@ class Slim } } + /** + * Get all flash messages + */ + public function flashData() + { + if (isset($this->environment['slim.flash'])) { + return $this->environment['slim.flash']->getMessages(); + } + } + /******************************************************************************** * Hooks *******************************************************************************/ @@ -1160,10 +1187,10 @@ class Slim /** * Invoke hook - * @param string $name The hook name - * @param mixed $hookArg (Optional) Argument for hooked functions + * @param string $name The hook name + * @param mixed ... (Optional) Argument(s) for hooked functions, can specify multiple arguments */ - public function applyHook($name, $hookArg = null) + public function applyHook($name) { if (!isset($this->hooks[$name])) { $this->hooks[$name] = array(array()); @@ -1173,10 +1200,14 @@ class Slim if (count($this->hooks[$name]) > 1) { ksort($this->hooks[$name]); } + + $args = func_get_args(); + array_shift($args); + foreach ($this->hooks[$name] as $priority) { if (!empty($priority)) { foreach ($priority as $callable) { - call_user_func($callable, $hookArg); + call_user_func_array($callable, $args); } } } @@ -1344,6 +1375,7 @@ class Slim throw $e; } else { try { + $this->response()->write(ob_get_clean()); $this->error($e); } catch (\Slim\Exception\Stop $e) { // Do nothing diff --git a/Slim/View.php b/Slim/View.php index 1a3973b..4059c80 100644 --- a/Slim/View.php +++ b/Slim/View.php @@ -6,7 +6,7 @@ * @copyright 2011 Josh Lockhart * @link http://www.slimframework.com * @license http://www.slimframework.com/license - * @version 2.4.2 + * @version 2.6.1 * @package Slim * * MIT LICENSE @@ -108,7 +108,7 @@ class View * @param string $key * @param mixed $value */ - public function keep($key, Closure $value) + public function keep($key, \Closure $value) { $this->data->keep($key, $value); } @@ -152,9 +152,9 @@ class View { if (!is_null($key)) { return isset($this->data[$key]) ? $this->data[$key] : null; - } else { - return $this->data->all(); } + + return $this->data->all(); } /** diff --git a/config.inc.php b/config.inc.php index 0251c1a..0aabd58 100644 --- a/config.inc.php +++ b/config.inc.php @@ -2,6 +2,7 @@ $allowedHost = array( "localhost", + "denisnotebook", "app.gruppolapastamadre.it", "dev.gruppolapastamadre.it", "management.gruppolapastamadre.it" diff --git a/management.php b/management.php index 1707fbc..9a55781 100644 --- a/management.php +++ b/management.php @@ -161,6 +161,42 @@ $app->get('/ricetta/:itemID/photos', function ($itemID) use ($app) { " INNER JOIN profilo ON profilo.ProfiloID = immagini.from_profile_id". " WHERE id_ricette = " . $itemID; + $mysqlconnetion = new MysqlClass; + //$mysqlconnetion->connetti(); + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + returnJson($app, $callbackFn, $retObj); +}); + +$app->get('/statistics/gender', function () use ($app) { + $callbackFn = $app->request()->get('callback'); + + $query = "SELECT 'Gender' as Type, IF(Gender='', 'Sconosciuto', Gender) as Serie, COUNT(gender) as CountSerie from profilo GROUP BY gender"; + + $mysqlconnetion = new MysqlClass; + //$mysqlconnetion->connetti(); + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + returnJson($app, $callbackFn, $retObj); +}); + +$app->get('/statistics/typeAccess', function () use ($app) { + $callbackFn = $app->request()->get('callback'); + + $query = "SELECT 'TipoAccesso' as Type, TipoAccesso as Serie, COUNT(TipoAccesso) as CountSerie from profilo GROUP BY TipoAccesso"; + + $mysqlconnetion = new MysqlClass; + //$mysqlconnetion->connetti(); + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + returnJson($app, $callbackFn, $retObj); +}); + +$app->get('/statistics/themesUsage', function () use ($app) { + $callbackFn = $app->request()->get('callback'); + + $query = "SELECT 'TemaUI' as Type, TemaUI as Serie, COUNT(TemaUI) as CountSerie from profilo GROUP BY TemaUI"; + $mysqlconnetion = new MysqlClass; //$mysqlconnetion->connetti(); $retObj = $mysqlconnetion->queryToObject($query); diff --git a/profile.php b/profile.php index bb05134..c910413 100644 --- a/profile.php +++ b/profile.php @@ -81,7 +81,7 @@ $app->get('/profile/:keyStore/ricette', function ($keyStore) use ($app) { $app->get('/profile/:keyStore', function ($keyStore) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; - $query = "select ProfiloID, TipoAccesso, RisultatiRicerca, TemaUI, Name, Gender, 0 as NumRicette, BloccoNoteUpdated from profilo" . + $query = "SELECT ProfiloID,TipoAccesso,RisultatiRicerca,TemaUI,Name,Gender,0 AS NumRicette,BloccoNoteUpdated,Email,bSpacciatore,bPrivacy,Cap,Comune,Provincia,TipoPM, Latitudine, Longitudine from profilo" . " where ProfiloID = '" . $keyStore . "'"; $retObj = $mysqlconnetion->queryToObject($query); @@ -100,11 +100,38 @@ $app->get('/profile/:keyStore', function ($keyStore) use ($app) { returnJson($app, $callbackFn, $retObj); }); +$app->get('/profile/province(/:iniz)', function ($iniz = "") use ($app) { + $callbackFn = $app->request()->get('callback'); + $mysqlconnetion = new MysqlClass; + $where= ""; + if($iniz!="") + $where = "WHERE Provincia like '" . $iniz . "%' "; + $query = "select DISTINCT Provincia from comuni " . $where . "ORDER BY Provincia"; + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + + returnJson($app, $callbackFn, $retObj); +}); + +$app->get('/profile/comuni/:prov(/:iniz)', function ($prov ,$iniz = "") use ($app) { + $callbackFn = $app->request()->get('callback'); + $mysqlconnetion = new MysqlClass; + $where= ""; + if($iniz!="") + $where = "AND Comune like '" . $iniz . "%' "; + $query = "select Comune, CAP from comuni where Provincia = '" . $prov . "' " . $where . "ORDER BY Comune"; + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + + returnJson($app, $callbackFn, $retObj); +}); + + $app->post('/profile', function () use ($app) { $callbackFn = $app->request()->get('callback'); $json_data_body = json_decode($app->request()->post('dataPair')); $mysqlconnetion = new MysqlClass; - $query = "insert into profilo(ProfiloID, Name, Email, Gender, TipoAccesso, RisultatiRicerca, TemaUI, UltimoAccesso, CreatoIl) values ('" . $json_data_body->keyStore . "', '" . str_replace("'", "''",$json_data_body->name) . "', '" . $json_data_body->email . "', '" . $json_data_body->gender . "', '" . $json_data_body->type . "', '" . $json_data_body->risRic . "', '" . $json_data_body->tema . "', NOW(), NOW())"; + $query = "insert into profilo(ProfiloID, Name, Email, Gender, TipoAccesso, RisultatiRicerca, TemaUI, UltimoAccesso, CreatoIl) values ('" . $json_data_body->keyStore . "', '" . str_replace("'", "''", htmlentities($json_data_body->name, null, "UTF-8")) . "', '" . $json_data_body->email . "', '" . $json_data_body->gender . "', '" . $json_data_body->type . "', '" . $json_data_body->risRic . "', '" . $json_data_body->tema . "', NOW(), NOW())"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti();