0
1
Fork 0

Merge with master

This commit is contained in:
Juan Ferrer Toribio 2017-05-09 15:33:02 +02:00
commit 45f5cc3deb
45 changed files with 535 additions and 232 deletions

View File

@ -2,20 +2,5 @@
Hedera.Items = new Class Hedera.Items = new Class
({ ({
Extends: Hedera.Form Extends: Hedera.Form
,activate: function ()
{
this.$('lot').assign ({
warehouse: 7,
realm: null
});
}
,onShowClick: function ()
{
var lot = this.$('lot');
lot.assign ({rate: this.$('rate').value});
this.gui.openReport ('items-report', lot.params);
}
}); });

View File

@ -0,0 +1,4 @@
{
"Items": "Artícles",
"Enter a search term": "Introdueix un terme de cerca"
}

9
forms/admin/items/locale/en.json Normal file → Executable file
View File

@ -1,9 +1,4 @@
{ {
"Item list": "Item list" "Items": "Items",
"Enter a search term": "Enter a search term"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Show": "Show"
} }

9
forms/admin/items/locale/es.json Normal file → Executable file
View File

@ -1,9 +1,4 @@
{ {
"Item list": "Listado de artículos" "Items": "Artículos",
"Enter a search term": "Introduce un término de búsqueda"
,"Store": "Almacén"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Show": "Mostrar"
} }

View File

@ -0,0 +1,4 @@
{
"Items": "Articles",
"Enter a search term": "Entrez un terme de recherche"
}

9
forms/admin/items/locale/mn.json Normal file → Executable file
View File

@ -1,9 +1,4 @@
{ {
"Item list": "Item list" "Items": "Items",
"Enter a search term": "Enter a search term"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Show": "Show"
} }

View File

@ -1,9 +1,4 @@
{ {
"Item list": "Lista de Ítens" "Items": "Artigos",
"Enter a search term": "Digite um termo de pesquisa"
,"Store": "Armazém"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Show": "Mostrar"
} }

View File

@ -0,0 +1,23 @@
/* Row */
.items .list-row > .photo
{
margin-right: 1em;
float: left;
border-radius: 50%;
height: 3.2em;
width: 3.2em;
}
.items .list-row > p
{
margin: .1em 0;
margin-left: 5em;
}
/* Topbar */
.action-bar .htk-search-entry
{
margin: .8em .6em;
}

View File

@ -1,42 +1,47 @@
<vn> <vn>
<vn-lot id="lot"/>
<h1 id="title"> <h1 id="title">
<t>Item list</t> <t>Items</t>
</h1> </h1>
<div id="actions" class="action-bar"> <div id="actions">
<htk-bar-button <htk-search-entry
icon="show" param="filter"/>
tip="_Show"
on-click="onShowClick"/>
</div> </div>
<div id="main" class="items"> <div id="main" class="items">
<div class="card form"> <div class="card list">
<div> <htk-repeater form-id="iter" empty-message="_Enter a search term">
<label><t>Store</t></label> <db-model property="model" batch="hash">
<htk-combo lot="lot" name="warehouse"> SELECT Id_Article, Article, Medida, Categoria, Foto
<db-model property="model"> FROM vn2008.Articles
SELECT id, name FROM vn2008.warehouse WHERE Article LIKE CONCAT('%', #filter, '%')
WHERE reserve ORDER BY name OR Id_Article = #filter
ORDER BY Article LIMIT 50
</db-model> </db-model>
</htk-combo> <custom>
</div> <div class="list-row">
<div> <htk-image
<label><t>Realm</t></label> form="iter"
<htk-combo lot="lot" name="realm" not-null="false"> column="Foto"
<db-model property="model"> class="photo"
SELECT id, reino FROM vn2008.reinos directory="catalog"
WHERE display != FALSE ORDER BY reino subdir="200x200"
</db-model> full-dir="900x900"
</htk-combo> editable="true"
</div> conn="conn"/>
<div> <p class="concept">
<label><t>Rate</t></label> <htk-text form="iter" column="Article"/>
<select id="rate"> <htk-text form="iter" column="Medida"/>
<option>3</option> <htk-text form="iter" column="Categoria"/>
<option>2</option> </p>
<option>1</option> <p>
</select> <htk-text form="iter" column="Id_Article"/>
</p>
<p>
<htk-text form="iter" column="Foto"/>
</p>
<div class="clear"/>
</div> </div>
</custom>
</htk-repeater>
</div> </div>
</div> </div>
</vn> </vn>

View File

@ -1,12 +1,13 @@
{ {
"Photos": "Fotos" "Images": "Imatges"
,"Collection": "Colección" ,"Collection": "Col·lecció"
,"ImageName": "Nom de la imatge" ,"Click or drop files here": "Prem o deixa anar els arxius aquí"
,"Id": "Id"
,"ImageFile": "Arxiu d'imatge"
,"Upload": "Enviar" ,"Clear all": "Netejar tot"
,"Upload files": "Pujar arxius"
,"ImageUploaded": "Imatge pujada correctament" ,"Upload finished successfully": "Imatges pujades correctament"
,"Some errors happened on upload": "Van ocórrer errors en pujar alguna de les imatges"
,"There are no files to upload": "No s'ha seleccionat arxius per pujar"
} }

View File

@ -1,12 +1,13 @@
{ {
"Photos": "Photos" "Images": "Images"
,"Collection": "Collection" ,"Collection": "Collection"
,"ImageName": "Image name" ,"Click or drop files here": "Click or drop files here"
,"Id": "Id"
,"ImageFile": "Image file"
,"Upload": "Upload" ,"Clear all": "Clear all"
,"Upload files": "Upload files"
,"ImageUploaded": "Image uploaded successfully" ,"Upload finished successfully": "Upload finished successfully"
,"Some errors happened on upload": "Some errors happened on upload"
,"There are no files to upload": "There are no files to upload"
} }

View File

@ -1,12 +1,13 @@
{ {
"Photos": "Fotos" "Images": "Imágenes"
,"Collection": "Colección" ,"Collection": "Colección"
,"ImageName": "Nombre de la imagen" ,"Click or drop files here": "Pulsa o suelta los archivos aquí"
,"Id": "Id"
,"ImageFile": "Archivo de imagen"
,"Upload": "Enviar" ,"Clear all": "Limpiar todo"
,"Upload files": "Subir archivos"
,"ImageUploaded": "Imagen subida correctamente" ,"Upload finished successfully": "Imágenes subidas correctamente"
,"Some errors happened on upload": "Ocurrieron errores al subir alguna de las imágenes"
,"There are no files to upload": "No se han seleccionado archivos para subir"
} }

View File

@ -1,12 +1,13 @@
{ {
"Photos": "Photos" "Images": "Images"
,"Collection": "Collection" ,"Collection": "Collection"
,"ImageName": "Nom de l'image" ,"Click or drop files here": "Cliquez ici ou déposer des fichiers"
,"Id": "Id"
,"ImageFile": "Fichier image"
,"Upload": "Télécharger" ,"Clear all": "Tout effacer"
,"Upload files": "Upload Files"
,"ImageUploaded": "téléchargement correct" ,"Upload finished successfully": "Les images téléchargées correctement"
,"Some errors happened on upload": "Des erreurs sont survenues lors du téléchargement des images"
,"There are no files to upload": "Aucun fichier sélectionné pour télécharger"
} }

View File

@ -1,12 +1,13 @@
{ {
"Photos": "Photos" "Images": "Images"
,"Collection": "цуглуулга" ,"Collection": "Collection"
,"ImageName": "Image name" ,"Click or drop files here": "Click or drop files here"
,"Id": "Id"
,"ImageFile": "Image file"
,"Upload": "Upload" ,"Clear all": "Clear all"
,"Upload files": "Upload files"
,"ImageUploaded": "Image uploaded successfully" ,"Upload finished successfully": "Upload finished successfully"
,"Some errors happened on upload": "Some errors happened on upload"
,"There are no files to upload": "There are no files to upload"
} }

View File

@ -1,12 +1,13 @@
{ {
"Photos": "Fotos" "Images": "Imagens"
,"Collection": "Coleção" ,"Collection": "Coleção"
,"ImageName": "Nome da imagem" ,"Click or drop files here": "Clique ou soltar arquivos aqui"
,"Id": "Id"
,"ImageFile": "Arquivo de imagem"
,"Upload": "Enviar" ,"Clear all": "Clear All"
,"Upload files": "Fazer upload de arquivos"
,"ImageUploaded": "Imagem subida correctamente" ,"Upload finished successfully": "Upload concluído com sucesso"
,"Some errors happened on upload": "Ocurrieron erros ao subir alguma das imagens"
,"There are no files to upload": "Não há arquivos selecionados para upload"
} }

View File

@ -2,36 +2,203 @@
Hedera.Photos = new Class Hedera.Photos = new Class
({ ({
Extends: Hedera.Form Extends: Hedera.Form
,filesData: []
,uploadCount: 0
,errors: false
,activate: function () ,activate: function ()
{ {
this.$('schema').value = 'catalog'; this.$('schema').value = 'catalog';
this.$('photo-id').focus ();
var self = this;
this.$('html-form').onsubmit = function ()
{ self._onSubmit (); return false; };
} }
,_onSubmit: function () ,addFiles: function (files)
{ {
this.$('schema-field').value = this.$('schema').value; if (!files)
this.$('submit').disabled = true; return;
this.conn.sendFormMultipart (this.$('html-form'), for (var i = 0; i < files.length; i++)
this._onResponse.bind (this)); this.addFile (files[i]);
} }
,_onResponse: function (json, error) ,addFile: function (file)
{ {
this.$('submit').disabled = false; var doc = document;
var div = doc.createElement ('div');
if (error) var button = new Htk.Button ({
throw error; tip: 'Remove',
icon: 'delete'
});
button.on ('click', this.onFileRemove, this);
div.appendChild (button.node);
this.$('photo-id').value = ''; var thumb = doc.createElement ('img');
this.$('photo-id').focus (); thumb.file = file;
Htk.Toast.showMessage (_('ImageAdded')); thumb.className = 'thumb';
div.appendChild (thumb);
var reader = new FileReader ();
reader.onload = function (e) { thumb.src = e.target.result; };
reader.readAsDataURL(file);
var name = doc.createElement ('input');
name.type = 'text';
name.value = getFileName (file.name);
div.appendChild (name);
var status = doc.createElement ('span');
status.className = 'status';
div.appendChild (status);
var fileData = {
div: div,
file: file,
name: name,
status: status,
sent: false,
loading : false
};
this.filesData.push (fileData);
button.value = fileData;
this.$('file-list').appendChild (div);
}
,onUploadClick: function ()
{
var filesData = this.filesData;
var formData = new FormData();
var count = 0;
for (var i = 0; i < filesData.length; i++)
{
var fileData = filesData[i];
if (!(fileData.sent || fileData.loading))
{
formData.append ('image', fileData.file);
formData.append ('name', fileData.name.value);
formData.append ('schema', this.$('schema').value);
formData.append ('srv', 'json:image/upload');
this.conn.sendFormData (formData,
this.onFileUpload.bind (this, fileData));
fileData.loading = true;
this.uploadCount++;
count++;
}
}
if (count === 0)
Htk.Toast.showWarning (_('There are no files to upload'));
}
,onFileUpload: function (fileData, data, error)
{
fileData.loading = false;
if (data)
{
var iconName = 'ok';
var title = _('ImageAdded');
fileData.sent = true;
fileData.name.disabled = true;
}
else
{
var iconName = 'error';
var title = error.message;
this.errors = true;
}
var status = fileData.status;
Vn.Node.removeChilds (status);
var icon = new Htk.Icon ({icon: iconName});
status.appendChild (icon.node);
status.title = title;
this.uploadCount--;
if (this.uploadCount === 0)
{
if (!this.errors)
Htk.Toast.showMessage (_('Upload finished successfully'));
else
Htk.Toast.showError (_('Some errors happened on upload'));
this.errors = false;
}
}
,onFileRemove: function (button)
{
var fileData = button.value;
this.$('file-list').removeChild (fileData.div);
for (var i = 0; i < this.filesData.length; i++)
if (this.filesData[i] === fileData)
{
this.filesData.splice (i, 1);
break;
}
}
,onClearClick: function ()
{
this.filesData = [];
Vn.Node.removeChilds (this.$('file-list'));
}
,onDropzoneClick: function ()
{
this.$('file').click ();
}
,onFileChange: function ()
{
this.addFiles (this.$('file').files);
}
,onDragEnter: function (event)
{
Vn.Node.addClass (this.$('dropzone'), 'dragover');
}
,onDragLeave: function (event)
{
Vn.Node.removeClass (this.$('dropzone'), 'dragover');
}
,onDragOver: function (event)
{
event.preventDefault ();
}
,onDragEnd: function (event)
{
Vn.Node.removeClass (this.$('dropzone'), 'dragover');
event.dataTransfer.clearData ();
}
,onDrop: function (event)
{
event.preventDefault ();
this.addFiles (event.dataTransfer.files);
} }
}); });
function getFileName (path)
{
var barIndex = path.lastIndexOf ('/');
if (barIndex === -1)
barIndex = path.lastIndexOf ('\\');
if (barIndex === -1)
barIndex = 0;
var dotIndex = path.lastIndexOf ('.');
if (dotIndex === -1)
dotIndex = 0;
return path.substr (barIndex, dotIndex);
}

View File

@ -1,17 +1,63 @@
.photos iframe /* Dropzone */
.photos .dropzone
{
background-color: white;
border-style: dashed;
border-radius: .4em;
border-color: #2196F3;
padding: 2em 1em;
text-align: center;
color: #666;
cursor: pointer;
}
.photos .dropzone.dragover
{
color: #CCC;
border-style: solid;
}
.photos input[type=file]
{ {
display: none; display: none;
} }
/* Footer */ /* File list */
.photos input[type=submit] .photos .file-list
{ {
display: block; margin-top: 1em;
margin-top: 1.5em; }
margin-left: auto; .photos .file-list > div
margin-right: auto; {
font-size: 1.2em; height: 2.5em;
}
.photos .file-list .thumb
{
max-height: 2em;
max-width: 2em;
vertical-align: middle;
margin: 0 1em;
}
.photos .file-list input
{
max-width: 10em;
}
.photos .file-list .status
{
margin-left: .5em;
cursor: pointer;
} }
/* Footer */
.photos .footer
{
margin-top: 1.5em;
text-align: center;
}
.photos .footer > button
{
font-size: 1.2em;
margin-left: 1em;
}

View File

@ -1,33 +1,41 @@
<vn> <vn>
<h1 id="title"> <h1 id="title">
<t>Photos</t> <t>Images</t>
</h1> </h1>
<div id="main" class="photos"> <div id="main" class="photos">
<form <div class="box">
id="html-form" <div class="form-group">
enctype="multipart/form-data">
<div class="card form">
<input type="hidden" name="srv" value="json:image/upload"/>
<div>
<label><t>Id</t></label>
<input type="number" name="id" id="photo-id"/>
</div>
<div>
<label><t>ImageName</t></label>
<input type="text" name="name"/>
</div>
<div>
<label><t>Collection</t></label> <label><t>Collection</t></label>
<htk-combo id="schema"> <htk-combo id="schema">
<db-model property="model"> <db-model property="model">
SELECT name, `desc` FROM image_schema ORDER BY `desc` SELECT name, `desc` FROM image_schema ORDER BY `desc`
</db-model> </db-model>
</htk-combo> </htk-combo>
<input type="hidden" name="schema" id="schema-field"/>
</div> </div>
<div> <div id="dropzone" class="dropzone"
<label><t>ImageFile</t></label> on-dragenter="onDragEnter"
<input type="file" name="image"/> on-dragleave="onDragLeave"
on-mouseout="onDragLeave"
on-dragover="onDragOver"
on-drop="onDrop"
on-dragend="onDragEnd"
on-click="onDropzoneClick">
<t>Click or drop files here</t>
</div>
<input
id="file"
type="file"
multiple="true"
name="image"
on-change="onFileChange"/>
<div id="file-list" class="file-list"/>
<div class="footer">
<button class="thin" on-click="onClearClick">
<t>Clear all</t>
</button>
<button class="thin" on-click="onUploadClick">
<t>Upload files</t>
</button>
</div> </div>
<input id="submit" type="submit" class="thin"/> <input id="submit" type="submit" class="thin"/>
</div> </div>

View File

@ -0,0 +1,23 @@
Hedera.ItemsForm = new Class
({
Extends: Hedera.Form
,activate: function ()
{
this.$('warehouse').value = 7;
this.$('realm').value = null;
}
,onPreviewClick: function ()
{
var batch = new Sql.Batch ();
batch.addValues ({
'warehouse': this.$('warehouse').value
,'realm': this.$('realm').value
,'rate': this.$('rate').value
});
this.gui.openReport ('items-report', batch);
}
});

View File

@ -0,0 +1,9 @@
{
"Item list": "Item list"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Preview": "Preview"
}

View File

@ -0,0 +1,9 @@
{
"Item list": "Listado de artículos"
,"Store": "Almacén"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Preview": "Mostrar"
}

View File

@ -0,0 +1,9 @@
{
"Item list": "Item list"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Preview": "Preview"
}

View File

@ -0,0 +1,9 @@
{
"Item list": "Lista de Ítens"
,"Store": "Armazém"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Preview": "Mostrar"
}

42
forms/reports/items-form/ui.xml Executable file
View File

@ -0,0 +1,42 @@
<vn>
<vn-lot id="lot"/>
<h1 id="title">
<t>Item list</t>
</h1>
<div id="actions" class="action-bar">
<htk-bar-button
icon="show"
tip="_Show"
on-click="onShowClick"/>
</div>
<div id="main" class="items">
<div class="card form">
<div>
<label><t>Store</t></label>
<htk-combo lot="lot" name="warehouse">
<db-model property="model">
SELECT id, name FROM vn2008.warehouse
WHERE reserve ORDER BY name
</db-model>
</htk-combo>
</div>
<div>
<label><t>Realm</t></label>
<htk-combo lot="lot" name="realm" not-null="false">
<db-model property="model">
SELECT id, reino FROM vn2008.reinos
WHERE display != FALSE ORDER BY reino
</db-model>
</htk-combo>
</div>
<div>
<label><t>Rate</t></label>
<select id="rate">
<option>3</option>
<option>2</option>
<option>1</option>
</select>
</div>
</div>
</div>
</vn>

View File

View File

@ -191,7 +191,7 @@ module.exports = new Class
,loadMenu: function () ,loadMenu: function ()
{ {
var sql = 'CALL form_list ()'; var sql = 'CALL formList ()';
this._conn.execQuery (sql, this._onMenuLoad.bind (this)); this._conn.execQuery (sql, this._onMenuLoad.bind (this));
} }

View File

@ -50,6 +50,7 @@
,"Visits": "Visites" ,"Visits": "Visites"
,"News": "Noticies" ,"News": "Noticies"
,"Photos": "Fotos" ,"Photos": "Fotos"
,"Items": "Artícles"
,"Reports": "Informes" ,"Reports": "Informes"
,"Shelves": "Estanterías" ,"Shelves": "Estanterías"
,"Items list": "Llistat articles" ,"Items list": "Llistat articles"

View File

@ -50,6 +50,7 @@
,"Visits": "Visits" ,"Visits": "Visits"
,"News": "News" ,"News": "News"
,"Photos": "Photos" ,"Photos": "Photos"
,"Items": "Items"
,"Reports": "Reports" ,"Reports": "Reports"
,"Shelves": "Shelves" ,"Shelves": "Shelves"
,"Items list": "Items list" ,"Items list": "Items list"

View File

@ -50,6 +50,7 @@
,"Visits": "Visitas" ,"Visits": "Visitas"
,"News": "Noticias" ,"News": "Noticias"
,"Photos": "Fotos" ,"Photos": "Fotos"
,"Items": "Artículos"
,"Reports": "Informes" ,"Reports": "Informes"
,"Shelves": "Estanterías" ,"Shelves": "Estanterías"
,"Items list": "Listado artículos" ,"Items list": "Listado artículos"

View File

@ -50,6 +50,7 @@
,"Visits": "Visites" ,"Visits": "Visites"
,"News": "Nouvelles" ,"News": "Nouvelles"
,"Photos": "Photos" ,"Photos": "Photos"
,"Items": "Articles"
,"Reports": "Rapport" ,"Reports": "Rapport"
,"Shelves": "Etagères" ,"Shelves": "Etagères"
,"Items list": "Liste des articles" ,"Items list": "Liste des articles"

View File

@ -50,6 +50,7 @@
,"Visits": "уулзалт" ,"Visits": "уулзалт"
,"News": "мэдээ" ,"News": "мэдээ"
,"Photos": "Фото зураг" ,"Photos": "Фото зураг"
,"Items": "зүйл"
,"Reports": "мэдээ" ,"Reports": "мэдээ"
,"Shelves": "тавиур" ,"Shelves": "тавиур"
,"Items list": "зүйлс жагсаалт" ,"Items list": "зүйлс жагсаалт"

View File

@ -50,6 +50,7 @@
,"Visits": "Visitas" ,"Visits": "Visitas"
,"News": "Noticias" ,"News": "Noticias"
,"Photos": "Fotos" ,"Photos": "Fotos"
,"Items": "Artigos"
,"Reports": "Relatórios" ,"Reports": "Relatórios"
,"Shelves": "Estantes" ,"Shelves": "Estantes"
,"Items list": "Lista de Itens" ,"Items list": "Lista de Itens"

View File

@ -193,6 +193,20 @@ module.exports = new Class
this._addRequest (); this._addRequest ();
} }
,sendFormData: function (formData, callback)
{
if (this.token)
formData.append ('token', this.token);
var request = new XMLHttpRequest ();
request.open ('post', '', true);
request.onreadystatechange =
this._onStateChange.bind (this, request, callback);
request.send (formData);
this._addRequest ();
}
/* /*
* Called when REST response is received. * Called when REST response is received.
*/ */

View File

@ -20,7 +20,7 @@ class Sync extends Vn\Lib\Method
function run () function run ()
{ {
$db = $this->getSysConn () $db = $this->getSysConn ();
set_time_limit (0); set_time_limit (0);
$this->$trashSubdir = date ('YmdHis'); $this->$trashSubdir = date ('YmdHis');

View File

@ -65,7 +65,6 @@ class Thumb extends Vn\Web\RestRequest
// Creates the thumb. // Creates the thumb.
$util = new Util ($this->app); $util = new Util ($this->app);
$baseDir = "{$util->dataDir}/$schema"; $baseDir = "{$util->dataDir}/$schema";
$srcFile = "$baseDir/full/$file"; $srcFile = "$baseDir/full/$file";

View File

@ -10,77 +10,31 @@ use Vn\Lib\UserException;
*/ */
class Upload extends Vn\Web\JsonRequest class Upload extends Vn\Web\JsonRequest
{ {
const PARAMS = [
'name',
'schema'
];
function run ($db) function run ($db)
{ {
$util = new Util ($this->app); $util = new Util ($this->app);
// Checks schema.
$regexp = '/[^a-z0-9_]/';
if (empty ($_REQUEST['schema']) || preg_match ($regexp, $_REQUEST['schema']) !== 0)
throw new UserException (s('Bad schema name'));
$schema = $_REQUEST['schema']; $schema = $_REQUEST['schema'];
$name = $_REQUEST['name'];
// Checks schema
$info = $util->loadInfo ($schema); $info = $util->loadInfo ($schema);
if (!$info) if (!$info)
throw new UserException (s('Schema not exists')); throw new UserException (s('Schema not exists'));
// Checks file name and identifier. // Checks file name
$query = sprintf ( if (preg_match ('/[^a-z0-9_]/', $_REQUEST['name']) !== 0)
'SHOW INDEX FROM `%1$s`.`%2$s` WHERE Key_name = \'PRIMARY\''
,$info['schema']
,$info['table']
);
$pk = $db->getRow ($query);
if (!empty ($_REQUEST['id']) && empty ($_REQUEST['name']))
{
$query = sprintf (
'SELECT `%3$s` FROM `%1$s`.`%2$s` WHERE `%4$s` = #id'
,$info['schema']
,$info['table']
,$info['column']
,$pk['Column_name']
);
$_REQUEST['name'] = $db->getValue ($query,
['id' => $_REQUEST['id']]);
}
if (empty ($_REQUEST['name']) || preg_match ($regexp, $_REQUEST['name']) !== 0)
throw new UserException (s('Bad file name')); throw new UserException (s('Bad file name'));
// Checks permissions. // Checks for file errors
if (!empty ($_REQUEST['id']))
{
$filterColumn = $pk['Column_name'];
$filterValue = $_REQUEST['id'];
}
else
{
$filterColumn = $info['column'];
$filterValue = $_REQUEST['name'];
}
$query = sprintf (
'UPDATE `%1$s`.`%2$s` SET `%3$s` = #name WHERE `%4$s` = #filter LIMIT 1'
,$info['schema']
,$info['table']
,$info['column']
,$filterColumn
);
$params = [
'name' => $_REQUEST['name'],
'filter' => $filterValue
];
if (!$db->query ($query, $params))
throw new UserException (s('Permission denied'));
// Checks for file errors.
if (empty ($_FILES['image']['name'])) if (empty ($_FILES['image']['name']))
throw new UserException (s('File not choosed')); throw new UserException (s('File not choosed'));
@ -123,14 +77,15 @@ class Upload extends Vn\Web\JsonRequest
if ($_FILES['image']['size'] > $maxSize * 1048576) if ($_FILES['image']['size'] > $maxSize * 1048576)
throw new UserException (sprintf (s('File size error'), $maxSize)); throw new UserException (sprintf (s('File size error'), $maxSize));
// Resizes and saves the image. // Resizes and saves the image
$fileName = "{$_REQUEST['name']}.png"; $tmpName = $_FILES['image']['tmp_name'];
$fileName = "{$name}.png";
$schemaPath = "{$util->dataDir}/$schema"; $schemaPath = "{$util->dataDir}/$schema";
$fullFile = "$schemaPath/full/$fileName"; $fullFile = "$schemaPath/full/$fileName";
$symbolicSrc = "../full/$fileName"; $symbolicSrc = "../full/$fileName";
$image = Image::create ($_FILES['image']['tmp_name']); $image = Image::create ($tmpName);
Image::resizeSave ($image, $fullFile, $info['max_height'], $info['max_width']); Image::resizeSave ($image, $fullFile, $info['max_height'], $info['max_width']);
foreach ($info['sizes'] as $size => $i) foreach ($info['sizes'] as $size => $i)
@ -140,7 +95,7 @@ class Upload extends Vn\Web\JsonRequest
} }
imagedestroy ($image); imagedestroy ($image);
unlink ($_FILES['image']['tmp_name']); unlink ($tmpName);
return TRUE; return TRUE;
} }
} }