Files
webgui/plugins/dynamix/UserEdit.page
2016-06-26 11:53:24 +02:00

149 lines
5.7 KiB
Plaintext

Menu="UserList"
Title="Edit User"
---
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?if (!array_key_exists($name, $users)):?>
<p class="notice">User <?=$name?> has been deleted.</p><br>
<input type="button" value="Done" onClick="done()">
<?return;?>
<?endif;?>
<?
$user = "/boot/config/plugins/dynamix/users/$name.png";
$void = "<img src='/webGui/images/user.png' width='48' height='48' id='image' onclick='$(&quot;#drop&quot;).click()' style='cursor:pointer' title='Click to select PNG file'>";
$icon = "<i class='fa fa-trash top' title='Restore default image' onclick='restore()'></i>";
?>
<style>
<?if ($display['theme'] == 'black'):?>
span#dropbox{border:1px solid #202020;border-radius:5px;background:-webkit-radial-gradient(#303030,#101010);background:linear-gradient(#303030,#101010);padding:28px 12px;line-height:72px;margin-right:16px;}
<?else:?>
span#dropbox{border:1px solid #D0D0D0;border-radius:5px;background:-webkit-radial-gradient(#B0B0B0,#F0F0F0);background:linear-gradient(#B0B0B0,#F0F0F0);padding:28px 12px;line-height:72px;margin-right:16px;}
<?endif;?>
i.top{position:absolute;padding-top:4px;cursor:pointer;}
</style>
<script src="/webGui/javascript/jquery.filedrop.js"></script>
<script>
var path = '/boot/config/plugins/dynamix/users';
var filename = '';
function restore() {
// restore original image and activate APPLY button
$('#dropbox').html("<?=$void?>");
$('input[name="userDesc"]').trigger('change');
filename = 'reset';
}
function upload(remove) {
// save or delete upload when APPLY is pressed
if (remove || filename=='reset') {
$.post("/webGui/include/FileUpload.php",{cmd:'delete',path:path,filename:'<?=$name?>.png'});
} else if (filename) {
$.post("/webGui/include/FileUpload.php",{cmd:'save',path:path,filename:filename,output:'<?=$name?>.png'});
}
}
$(function(){
var dropbox = $('#dropbox');
// attach the drag-n-drop feature to the 'dropbox' element
dropbox.filedrop({
maxfiles:1,
maxfilesize:95, // KB
url:'/webGui/include/FileUpload.php',
beforeEach:function(file) {
if (!file.type.match(/^image\/png/)) {
swal({title:"Warning",text:"Only PNG images are allowed!",type:"warning"});
return false;
}
},
error: function(error, file, i) {
switch (error) {
case 'BrowserNotSupported':
swal({title:"Browser error",text:"Your browser does not support HTML5 file uploads!",type:"error"});
break;
case 'TooManyFiles':
swal({title:"Too many files",text:"Please select one file only!",type:"error"});
break;
case 'FileTooLarge':
swal({title:"File too large",text:"Maximum file upload size is 95 kB (97,280 bytes)",type:"error"});
break;
}
},
uploadStarted:function(i,file,count) {
var image = $('img', $(dropbox));
var reader = new FileReader();
image.width = 48;
image.height = 48;
reader.onload = function(e){image.attr('src',e.target.result);};
reader.readAsDataURL(file);
},
uploadFinished:function(i,file,response) {
if (response == 'OK 200') {
if (!filename || filename=='reset') $(dropbox).append("<?=$icon?>");
$('input[name="userDesc"]').trigger('change');
filename = file.name;
} else {
swal({title:"Upload error",text:response,type:"error"});
}
}
});
// simulate a drop action when manual file selection is done
$('#drop').bind('change', function(e) {
var files = e.target.files;
if ($('#dropbox').triggerHandler({type:'drop',dataTransfer:{files:files}})==false) e.stopImmediatePropagation();
});
});
</script>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onsubmit="upload(<?=$name=="root" ? 'false' : 'this.confirmDelete.checked'?>)">
<input type="hidden" name="userName" value="<?=$name?>">
User name:
: <?=$name?>
Description:
: <input type="text" name="userDesc" maxlength="64" value="<?=$users[$name]['desc'];?>">
Custom image:
: <span id="dropbox">
<?if (file_exists($user)):?>
<img src="<?=autov($user)?>" id="image" width="48" height="48" onclick="$('#drop').click()" style="cursor:pointer" title="Click to select PNG file"><?=$icon?>
<?else:?>
<?=$void?>
<?endif;?>
</span><em>Drag-n-drop a PNG file or click the image at the left.</em><input type="file" id="drop" accept=".png" style="display:none">
> The image will be scaled to 48x48 pixels in size. The maximum image file upload size is 95 kB (97,280 bytes).
<?if ($name=="root"):?>
&nbsp;
<?else:?>
Delete<input type="checkbox" name="confirmDelete" onChange="chkDelete(this.form, this.form.cmdUserEdit)">
<?endif;?>
: <input type="submit" name="cmdUserEdit" value="Apply"><input type="button" value="Done" onclick="done('UserEdit')">
</form>
<br><br>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="userName" value="<?=$name?>">
Password:
: <input type="password" name="userPassword" maxlength="40" onKeyUp="this.form.cmdUserEdit.disabled = (this.form.userPassword.value != this.form.userPasswordConf.value);">
Retype password:
: <input type="password" name="userPasswordConf" maxlength="40" onKeyUp="this.form.cmdUserEdit.disabled = (this.form.userPassword.value != this.form.userPasswordConf.value);">
&nbsp;
: <input type="submit" name="cmdUserEdit" value="Change"><input type="button" value="Done" onclick="done('UserEdit')">
</form>