Backup
This commit is contained in:
parent
9812519677
commit
25e56bea80
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,10 +7,8 @@
|
|||
<div class="form">
|
||||
<form
|
||||
id="html-form"
|
||||
method="post"
|
||||
enctype="multipart/form-data"
|
||||
target="photos-iframe"
|
||||
on-submit="onFormSubmit">
|
||||
enctype="multipart/form-data">
|
||||
<input type="hidden" name="srv" value="json:image/upload"/>
|
||||
<div class="form-group">
|
||||
<label><t>Id</t></label>
|
||||
<input type="number" name="id" id="photo-id"/>
|
||||
|
@ -20,27 +18,22 @@
|
|||
<input type="text" name="name"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label><t>Schema</t></label>
|
||||
<input type="hidden" name="schema" id="schema-field"/>
|
||||
<label><t>Collection</t></label>
|
||||
<htk-combo id="schema">
|
||||
<db-model property="model">
|
||||
SELECT name, `desc` FROM image_schema ORDER BY `desc`
|
||||
<custom>
|
||||
SELECT name, `desc` FROM image_schema ORDER BY `desc`
|
||||
</custom>
|
||||
</db-model>
|
||||
</htk-combo>
|
||||
<input type="hidden" name="schema" id="schema-field"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label><t>ImageFile</t></label>
|
||||
<input type="file" name="image"/>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" id="photo-size"/>
|
||||
</div>
|
||||
<button class="thin" id="submit">
|
||||
<t>Upload</t>
|
||||
</button>
|
||||
<input id="submit" type="submit" class="thin"/>
|
||||
</form>
|
||||
<iframe
|
||||
id="iframe"
|
||||
name="photos-iframe"
|
||||
on-load="onImageUpload"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
<div class="clear"/>
|
||||
</div>
|
||||
<input id="schema" type="hidden" name="schema"/>
|
||||
<input id="max-size" type="hidden" name="MAX_FILE_SIZE"/>
|
||||
</form>
|
||||
</div>
|
||||
</vn>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Photos": "Fotos"
|
||||
|
||||
,"Schema": "Esquema"
|
||||
,"Collection": "Colección"
|
||||
,"ImageName": "Nom de la imatge"
|
||||
,"Id": "Id"
|
||||
,"ImageFile": "Arxiu d'imatge"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Photos": "Photos"
|
||||
|
||||
,"Schema": "Schema"
|
||||
,"Collection": "Collection"
|
||||
,"ImageName": "Image name"
|
||||
,"Id": "Id"
|
||||
,"ImageFile": "Image file"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Photos": "Fotos"
|
||||
|
||||
,"Schema": "Esquema"
|
||||
,"Collection": "Colección"
|
||||
,"ImageName": "Nombre de la imagen"
|
||||
,"Id": "Id"
|
||||
,"ImageFile": "Archivo de imagen"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Photos": "Photos"
|
||||
|
||||
,"Schema": "Schéma"
|
||||
,"Collection": "Collection"
|
||||
,"ImageName": "Nom de l'image"
|
||||
,"Id": "Id"
|
||||
,"ImageFile": "Fichier image"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Photos": "Photos"
|
||||
|
||||
,"Schema": "Schema"
|
||||
,"Collection": "цуглуулга"
|
||||
,"ImageName": "Image name"
|
||||
,"Id": "Id"
|
||||
,"ImageFile": "Image file"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Photos": "Fotos"
|
||||
|
||||
,"Schema": "Esquema"
|
||||
,"Collection": "Coleção"
|
||||
,"ImageName": "Nome da imagem"
|
||||
,"Id": "Id"
|
||||
,"ImageFile": "Arquivo de imagem"
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
require_once ('vn/web/json-request.php');
|
||||
require_once ('vn/web/rest-request.php');
|
||||
require_once (__DIR__.'/tpv.php');
|
||||
|
||||
/**
|
||||
* Gets transaction confirmation from HTTP POST.
|
||||
**/
|
||||
class ConfirmPost extends Vn\Web\HttpRequest
|
||||
class ConfirmPost extends Vn\Web\RestRequest
|
||||
{
|
||||
function run ()
|
||||
{
|
||||
|
|
|
@ -6,9 +6,9 @@ if (isset ($_POST['key']))
|
|||
{
|
||||
ini_set ('soap.wsdl_cache_enabled', FALSE);
|
||||
|
||||
$requestString = file_get_contents ('soap-request.xml');
|
||||
$requestString = file_get_contents (__DIR__.'/soap-request.xml');
|
||||
|
||||
$client = new SoapClient (stream_resolve_include_path ('vn/tpv/soap.wsdl'));
|
||||
$client = new SoapClient (__DIR__.'/soap.wsdl');
|
||||
$result = $client->__soapCall ('procesaNotificacionSIS', [
|
||||
'XML' => $requestString
|
||||
]);
|
132
vn/web/app.php
132
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -74,7 +74,7 @@ class HtmlService extends Service
|
|||
|
||||
// Loading the requested page
|
||||
|
||||
$basePath = "./html/$page";
|
||||
$basePath = "pages/$page";
|
||||
|
||||
if (file_exists ($basePath))
|
||||
{
|
||||
|
|
|
@ -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');
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Vn\Web;
|
||||
|
||||
require_once (__DIR__.'/rest-app.php');
|
||||
require_once (__DIR__.'/rest-service.php');
|
||||
|
||||
/**
|
||||
* Base class for REST services.
|
||||
|
|
|
@ -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 .
|
||||
|
|
|
@ -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']));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue