diff --git a/forms/admin/photos/photos.js b/forms/admin/photos/photos.js
index 0f2b7da4..a391a31d 100644
--- a/forms/admin/photos/photos.js
+++ b/forms/admin/photos/photos.js
@@ -6,38 +6,37 @@ Vn.Photos = new Class
,activate: function ()
{
this.$('schema').value = 'catalog';
- this.$('photo-size').value = 10 /* MB */ * 1048576;
this.$('photo-id').focus ();
- this.$('html-form').action =
- '//'+ Vn.Config['image_host'] +'/rest.php?action=image';
+
+ var self = this;
+ this.$('html-form').onsubmit = function ()
+ { self.onSubmit (); return false; };
}
-
- ,onFormSubmit: function ()
+
+ ,onSubmit: function ()
{
this.$('schema-field').value = this.$('schema').value;
this.$('submit').disabled = true;
this.gui.loaderPush ();
- }
- ,onImageUpload: function ()
- {
+ var request = new Vn.JsonRequest ();
+ request.sendFormMultipart (this.$('html-form'),
+ this.onResponse.bind (this));
+ }
+
+ ,onResponse: function (request, json, error)
+ {
this.gui.loaderPop ();
this.$('submit').disabled = false;
- try {
- var responseText = this.$('iframe').contentDocument.body.textContent;
- var response = eval ('('+ responseText +')');
-
- if (response.data)
- {
- this.$('photo-id').value = '';
- this.$('photo-id').focus ();
- Htk.Toast.showMessage (_('ImageUploaded'));
- }
- else
- Htk.Toast.showError (response.error.message +' ('+ response.error.code +')');
+ if (json)
+ {
+ this.$('photo-id').value = '';
+ this.$('photo-id').focus ();
+ Htk.Toast.showMessage (_('ImageAdded'));
}
- catch (e) {}
+ else
+ Htk.Toast.showError (error.message);
}
});
diff --git a/forms/admin/photos/style.css b/forms/admin/photos/style.css
index c25d6923..59dedb12 100644
--- a/forms/admin/photos/style.css
+++ b/forms/admin/photos/style.css
@@ -20,11 +20,12 @@
/* Footer */
-.photos button
+.photos input[type=submit]
{
display: block;
margin: 0 auto;
padding: 0.6em;
margin-top: 1.5em;
+ font-size: 1.2em;
}
diff --git a/forms/admin/photos/ui.xml b/forms/admin/photos/ui.xml
index 1b074152..23d9d94c 100755
--- a/forms/admin/photos/ui.xml
+++ b/forms/admin/photos/ui.xml
@@ -7,10 +7,8 @@
diff --git a/forms/ecomerce/invoices/invoices.js b/forms/ecomerce/invoices/invoices.js
index 959821e6..78c07a2c 100644
--- a/forms/ecomerce/invoices/invoices.js
+++ b/forms/ecomerce/invoices/invoices.js
@@ -8,7 +8,12 @@ Vn.Invoices = new Class
if (!invoiceId)
return;
- var url = 'rest.php?method=dms/invoice&invoice='+ invoiceId;
+ var params = {
+ 'srv': 'rest:dms/invoice',
+ 'invoice': invoiceId
+ };
+
+ var url = '?'+ Vn.Url.makeUri (params);
window.open (url, '_blank');
}
});
diff --git a/js/htk/field/select.js b/js/htk/field/select.js
index 95c27738..6b79a86a 100644
--- a/js/htk/field/select.js
+++ b/js/htk/field/select.js
@@ -113,6 +113,7 @@ Htk.Select = new Class
,initialize: function (props)
{
var button = this.createElement ('button');
+ button.type = 'button';
button.className = 'htk-select input';
button.addEventListener ('mousedown', this._onButtonMouseDown.bind (this));
diff --git a/js/htk/image-editor.xml b/js/htk/image-editor.xml
index 37161386..01aca00e 100644
--- a/js/htk/image-editor.xml
+++ b/js/htk/image-editor.xml
@@ -18,7 +18,6 @@
-
diff --git a/js/vn/json-request.js b/js/vn/json-request.js
index f0967eda..856f522d 100644
--- a/js/vn/json-request.js
+++ b/js/vn/json-request.js
@@ -21,8 +21,11 @@ Vn.JsonRequest = new Class
,send: function (params, callback)
{
+ if (!params)
+ params = {};
+
params['srv'] = 'json:'+ this._methodName;
- this.sendWithUrl (params, callback, 'post', url);
+ this.sendWithUrl (params, callback, 'post', '.');
}
,sendForm: function (form, callback)
@@ -34,16 +37,13 @@ Vn.JsonRequest = new Class
if (elements[i].name)
params[elements[i].name] = elements[i].value;
- this.sendWithUrl (params, callback, form.method, form.action);
+ this.sendWithUrl (params, callback, 'post', form.action);
}
,sendFormMultipart: function (form, callback)
{
- var formData = new FormData (form);
- formData.append ('service', 'Json');
-
var request = new XMLHttpRequest ();
- request.open (form.method, form.action, true);
+ request.open ('post', form.action, true);
request.onreadystatechange =
this._onStateChange.bind (this, request, callback);
request.send (new FormData (form));
@@ -57,7 +57,32 @@ Vn.JsonRequest = new Class
var data = null;
var error = null;
- try {
+ try {
+ if (request.status == 0)
+ {
+ var ex = new Vn.JsonException ();
+ ex.message = _('The server does not respond');
+ throw ex;
+ }
+
+ var contentType = null;
+
+ try {
+ contentType = request
+ .getResponseHeader ('Content-Type')
+ .split (';')[0]
+ .trim ();
+ }
+ catch (e) {}
+
+ if (contentType != 'application/json')
+ {
+ var ex = new Vn.JsonException ();
+ ex.message = request.statusText;
+ ex.code = request.status;
+ throw ex;
+ }
+
var json = JSON.parse (request.responseText);
var jsData = json.data;
var jsWarns = json.warnings;
diff --git a/locale/ca/forms/admin/photos.json b/locale/ca/forms/admin/photos.json
index b7ac94c9..33d37b50 100755
--- a/locale/ca/forms/admin/photos.json
+++ b/locale/ca/forms/admin/photos.json
@@ -1,7 +1,7 @@
{
"Photos": "Fotos"
- ,"Schema": "Esquema"
+ ,"Collection": "Colección"
,"ImageName": "Nom de la imatge"
,"Id": "Id"
,"ImageFile": "Arxiu d'imatge"
diff --git a/locale/en/forms/admin/photos.json b/locale/en/forms/admin/photos.json
index 39489077..402722b4 100755
--- a/locale/en/forms/admin/photos.json
+++ b/locale/en/forms/admin/photos.json
@@ -1,7 +1,7 @@
{
"Photos": "Photos"
- ,"Schema": "Schema"
+ ,"Collection": "Collection"
,"ImageName": "Image name"
,"Id": "Id"
,"ImageFile": "Image file"
diff --git a/locale/es/forms/admin/photos.json b/locale/es/forms/admin/photos.json
index fa200179..65031e5f 100755
--- a/locale/es/forms/admin/photos.json
+++ b/locale/es/forms/admin/photos.json
@@ -1,7 +1,7 @@
{
"Photos": "Fotos"
- ,"Schema": "Esquema"
+ ,"Collection": "Colección"
,"ImageName": "Nombre de la imagen"
,"Id": "Id"
,"ImageFile": "Archivo de imagen"
diff --git a/locale/fr/forms/admin/photos.json b/locale/fr/forms/admin/photos.json
index cf3a0511..b6be33d7 100755
--- a/locale/fr/forms/admin/photos.json
+++ b/locale/fr/forms/admin/photos.json
@@ -1,7 +1,7 @@
{
"Photos": "Photos"
- ,"Schema": "Schéma"
+ ,"Collection": "Collection"
,"ImageName": "Nom de l'image"
,"Id": "Id"
,"ImageFile": "Fichier image"
diff --git a/locale/mn/forms/admin/photos.json b/locale/mn/forms/admin/photos.json
index 39489077..f40f409e 100755
--- a/locale/mn/forms/admin/photos.json
+++ b/locale/mn/forms/admin/photos.json
@@ -1,7 +1,7 @@
{
"Photos": "Photos"
- ,"Schema": "Schema"
+ ,"Collection": "цуглуулга"
,"ImageName": "Image name"
,"Id": "Id"
,"ImageFile": "Image file"
diff --git a/locale/pt/forms/admin/photos.json b/locale/pt/forms/admin/photos.json
index 8d0e1eb7..28ad4bb6 100644
--- a/locale/pt/forms/admin/photos.json
+++ b/locale/pt/forms/admin/photos.json
@@ -1,7 +1,7 @@
{
"Photos": "Fotos"
- ,"Schema": "Esquema"
+ ,"Collection": "Coleção"
,"ImageName": "Nome da imagem"
,"Id": "Id"
,"ImageFile": "Arquivo de imagem"
diff --git a/rest/tpv/confirm-post.php b/rest/tpv/confirm-post.php
index 050ff9c6..7665f6a4 100644
--- a/rest/tpv/confirm-post.php
+++ b/rest/tpv/confirm-post.php
@@ -1,12 +1,12 @@
__soapCall ('procesaNotificacionSIS', [
'XML' => $requestString
]);
diff --git a/vn/web/app.php b/vn/web/app.php
index 1fb29480..965f4385 100644
--- a/vn/web/app.php
+++ b/vn/web/app.php
@@ -12,6 +12,7 @@ require_once ('vn/lib/app.php');
**/
class App extends \Vn\Lib\App
{
+ protected $conn = NULL;
private $allowedServices =
[
'html',
@@ -65,6 +66,137 @@ class App extends \Vn\Lib\App
else
return parent::getConfigFile ();
}
+
+ /**
+ * Tries to retrieve user credentials from many sources such as POST,
+ * SESSION or COOKIES. If $_POST['remember'] is defined the user credentials
+ * are saved on the client brownser for future logins, cookies names are
+ * 'vn_user' for the user name and 'vn_pass' for user password, the
+ * password is encoded using base64_encode() function and should be decoded
+ * using base64_decode().
+ *
+ * return Db\Conn The database connection
+ **/
+ function login ()
+ {
+ if ($this->conn)
+ return $this->conn;
+
+ $user = NULL;
+ $password = NULL;
+ $rememberUser = TRUE;
+ $rememberPass = FALSE;
+ $credentialsChanged = TRUE;
+ $wasLoged = isset ($_SESSION['user']);
+
+ if (isset ($_POST['guest']))
+ {
+ $sysConn = $this->getSysConn ();
+ $row = $sysConn->getRow (
+ 'SELECT guest_user, guest_pass FROM config');
+
+ if ($row)
+ {
+ $user = $row['guest_user'];
+ $password = base64_decode ($row['guest_pass']);
+ $rememberUser = FALSE;
+ }
+ }
+ elseif (isset ($_POST['user']) && isset ($_POST['password']))
+ {
+ $user = $_POST['user'];
+ $password = $_POST['password'];
+
+ if (isset ($_POST['remember']) && $_POST['remember'])
+ $rememberPass = TRUE;
+ }
+ elseif (isset ($_SESSION['user']))
+ {
+ $user = $_SESSION['user'];
+ $password = $_SESSION['password'];
+ $credentialsChanged = FALSE;
+ }
+ elseif (isset ($_COOKIE['vn_user']) && isset ($_COOKIE['vn_pass']))
+ {
+ $user = $_COOKIE['vn_user'];
+ $password = base64_decode ($_COOKIE['vn_pass']);
+ $rememberPass = TRUE;
+ }
+
+ if (!isset ($user))
+ throw new SessionExpiredException ();
+
+ try {
+ $db = $this->createConnection ($user, $password);
+ $db->query ('CALL user_session_start (#)', [session_id ()]);
+ $this->conn = $db;
+
+ if ($rememberUser)
+ {
+ $cookieLife = time () + 7 * 86400; // 7 Days
+ setcookie ('vn_user', $user, $cookieLife);
+
+ if ($rememberPass)
+ setcookie ('vn_pass',
+ base64_encode ($password), $cookieLife);
+ }
+
+ $_SESSION['user'] = $user;
+ $_SESSION['password'] = $password;
+ }
+ catch (\Exception $e)
+ {
+ $this->conn = NULL;
+ throw new BadLoginException ();
+ }
+
+ // Registering the user access
+
+ if (!$wasLoged)
+ unset ($_SESSION['visitUser']);
+
+ if (isset ($_SESSION['access'])
+ && !isset ($_SESSION['visitUser']))
+ {
+ $sysConn = $this->getSysConn ();
+ $_SESSION['visitUser'] = $sysConn->getValue (
+ 'CALL visit_user_new (#, #, #)',
+ [
+ $_SESSION['access']
+ ,nullIf ($_SESSION, 'visitUser')
+ ,session_id ()
+ ]
+ );
+
+ if (!isset ($_SESSION['visitUnknown']))
+ $_SESSION['visitUnknown'] = $_SESSION['visitUser'];
+ }
+
+ return $db;
+ }
+
+ /**
+ * Logouts the current user. Cleans the last saved used credentials.
+ **/
+ function logout ()
+ {
+ $_SESSION['visitUser'] = nullIf ($_SESSION, 'visitUnknown');
+
+ setcookie ('vn_pass', '', -1);
+ unset ($_COOKIE['vn_pass']);
+ unset ($_SESSION['user']);
+ unset ($_SESSION['password']);
+
+ if ($this->conn)
+ {
+ $this->conn->query (
+ 'DELETE FROM user_session_view '
+ .'WHERE connection_id = CONNECTION_ID()'
+ );
+ $this->conn->close ();
+ $this->conn = NULL;
+ }
+ }
}
?>
diff --git a/vn/web/html-service.php b/vn/web/html-service.php
index 44c97972..516724c0 100644
--- a/vn/web/html-service.php
+++ b/vn/web/html-service.php
@@ -74,7 +74,7 @@ class HtmlService extends Service
// Loading the requested page
- $basePath = "./html/$page";
+ $basePath = "pages/$page";
if (file_exists ($basePath))
{
diff --git a/vn/web/json-request.php b/vn/web/json-request.php
index be9a945b..3ecf4bce 100644
--- a/vn/web/json-request.php
+++ b/vn/web/json-request.php
@@ -2,7 +2,7 @@
namespace Vn\Web;
-require_once (__DIR__.'/json-app.php');
+require_once (__DIR__.'/json-service.php');
require_once (__DIR__.'/rest-request.php');
/**
diff --git a/vn/web/rest-request.php b/vn/web/rest-request.php
index 397efddc..c679b44e 100644
--- a/vn/web/rest-request.php
+++ b/vn/web/rest-request.php
@@ -2,7 +2,7 @@
namespace Vn\Web;
-require_once (__DIR__.'/rest-app.php');
+require_once (__DIR__.'/rest-service.php');
/**
* Base class for REST services.
diff --git a/vn/web/rest-service.php b/vn/web/rest-service.php
index fff9c33f..f768564e 100644
--- a/vn/web/rest-service.php
+++ b/vn/web/rest-service.php
@@ -25,135 +25,6 @@ class RestService extends Service
$method->run ();
}
- /**
- * Tries to retrieve user credentials from many sources such as POST,
- * SESSION or COOKIES. If $_POST['remember'] is defined the user credentials
- * are saved on the client brownser for future logins, cookies names are
- * 'vn_user' for the user name and 'vn_pass' for user password, the
- * password is encoded using base64_encode() function and should be decoded
- * using base64_decode().
- **/
- function login ()
- {
- if ($this->conn)
- return $this->conn;
-
- $user = NULL;
- $password = NULL;
- $rememberUser = TRUE;
- $rememberPass = FALSE;
- $credentialsChanged = TRUE;
- $wasLoged = isset ($_SESSION['user']);
-
- if (isset ($_POST['guest']))
- {
- $sysConn = $this->app->getSysConn ();
- $row = $sysConn->getRow (
- 'SELECT guest_user, guest_pass FROM config');
-
- if ($row)
- {
- $user = $row['guest_user'];
- $password = base64_decode ($row['guest_pass']);
- $rememberUser = FALSE;
- }
- }
- elseif (isset ($_POST['user']) && isset ($_POST['password']))
- {
- $user = $_POST['user'];
- $password = $_POST['password'];
-
- if (isset ($_POST['remember']) && $_POST['remember'])
- $rememberPass = TRUE;
- }
- elseif (isset ($_SESSION['user']))
- {
- $user = $_SESSION['user'];
- $password = $_SESSION['password'];
- $credentialsChanged = FALSE;
- }
- elseif (isset ($_COOKIE['vn_user']) && isset ($_COOKIE['vn_pass']))
- {
- $user = $_COOKIE['vn_user'];
- $password = base64_decode ($_COOKIE['vn_pass']);
- $rememberPass = TRUE;
- }
-
- if (!isset ($user))
- throw new SessionExpiredException ();
-
- try {
- $db = $this->app->createConnection ($user, $password);
- $db->query ('CALL user_session_start (#)', [session_id ()]);
- $this->conn = $db;
-
- if ($rememberUser)
- {
- $cookieLife = time () + 7 * 86400; // 7 Days
- setcookie ('vn_user', $user, $cookieLife);
-
- if ($rememberPass)
- setcookie ('vn_pass',
- base64_encode ($password), $cookieLife);
- }
-
- $_SESSION['user'] = $user;
- $_SESSION['password'] = $password;
- }
- catch (\Exception $e)
- {
- $this->conn = NULL;
- throw new BadLoginException ();
- }
-
- // Registering the user access
-
- if (!$wasLoged)
- unset ($_SESSION['visitUser']);
-
- if (isset ($_SESSION['access'])
- && !isset ($_SESSION['visitUser']))
- {
- $sysConn = $this->getSysConn ();
- $_SESSION['visitUser'] = $sysConn->getValue (
- 'CALL visit_user_new (#, #, #)',
- [
- $_SESSION['access']
- ,nullIf ($_SESSION, 'visitUser')
- ,session_id ()
- ]
- );
-
- if (!isset ($_SESSION['visitUnknown']))
- $_SESSION['visitUnknown'] = $_SESSION['visitUser'];
- }
-
- return $db;
- }
-
- /**
- * Cleans the last saved used credentials.
- **/
- function logout ()
- {
- $_SESSION['visitUser'] = nullIf ($_SESSION, 'visitUnknown');
-
- setcookie ('vn_pass', '', -1);
- unset ($_COOKIE['vn_pass']);
- unset ($_SESSION['user']);
- unset ($_SESSION['password']);
-
- if ($this->conn)
- {
- $this->conn->query (
- 'DELETE FROM user_session_view '
- .'WHERE connection_id = CONNECTION_ID()'
- );
- $this->conn->close ();
- $this->conn = NULL;
- }
- }
-
/**
* Deinitializes the Application. When init method is called, this
* function is called automatically at the end of the script .
diff --git a/vn/web/service.php b/vn/web/service.php
index f90036df..b785c9e8 100755
--- a/vn/web/service.php
+++ b/vn/web/service.php
@@ -29,7 +29,6 @@ class OutdatedVersionException extends Lib\UserException {}
abstract class Service
{
protected $app;
- protected $conn = NULL;
function __construct ($app)
{
@@ -132,7 +131,7 @@ abstract class Service
function getVersion ()
{
return (int) strftime ('%G%m%d%H%M%S',
- filectime (__FILE__ /* $_SERVER['SCRIPT_FILENAME'] */));
+ filectime ($_SERVER['SCRIPT_FILENAME']));
}
}