Skip to content

Commit

Permalink
Adding icon file upload in user group
Browse files Browse the repository at this point in the history
  • Loading branch information
aswzen committed May 28, 2019
1 parent eb684f0 commit 1bb2ea5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
28 changes: 26 additions & 2 deletions application/controllers/usergroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@ function go_insert_user_group()

$_USERGROUP = $this->loadModel('UserGroupModel');

$name = 'icon-developer';
if(isset($_POST['record']['icon'][0])){
$content = $_POST['record']['icon'][0]['content'];
$name = $_POST['record']['icon'][0]['name'];
$name = str_replace(' ', '_', $name);
$class = str_replace('.', '_', $name);
file_put_contents(ROOT_STATIC_DIR.'/css/icons/'.$name, base64_decode($content));

$css = "\n.icon-".$class."{background:url('icons/".$name."') no-repeat center center;}";
$myfile = file_put_contents(ROOT_STATIC_DIR.'/css/icon.css', $css.PHP_EOL , FILE_APPEND | LOCK_EX);
}

$array = array(
"id" => null,
"groupcode" => $_POST['record']['groupcode'],
"usergroup" => $_POST['record']['usergroup'],
"badge" => $_POST['record']['badge'],
"icon" => $_POST['record']['icon']
"icon" => 'icon-'.$class
);

$_USERGROUP->addUserGroup($array);
Expand All @@ -84,12 +96,24 @@ function go_edit_user_group()

$_USERGROUP = $this->loadModel('UserGroupModel');

$name = 'icon-developer';
if(isset($_POST['record']['icon'][0])){
$content = $_POST['record']['icon'][0]['content'];
$name = $_POST['record']['icon'][0]['name'];
$name = str_replace(' ', '_', $name);
$class = str_replace('.', '_', $name);
file_put_contents(ROOT_STATIC_DIR.'/css/icons/'.$name, base64_decode($content));

$css = "\n.icon-".$class."{background:url('icons/".$name."') no-repeat center center;}";
$myfile = file_put_contents(ROOT_STATIC_DIR.'/css/icon.css', $css.PHP_EOL , FILE_APPEND | LOCK_EX);
}

$array = array(
"id" => $_POST['record']['id'],
"groupcode" => $_POST['record']['groupcode'],
"usergroup" => $_POST['record']['usergroup'],
"badge" => $_POST['record']['badge'],
"icon" => $_POST['record']['icon']
"icon" => 'icon-'.$class
);

$_USERGROUP->saveUserGroup($array);
Expand Down
45 changes: 31 additions & 14 deletions application/views/user_group_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?php } ?>

<?php include('footer.php'); ?>

<script type="text/javascript" src="<?php echo STATIC_DIR; ?>js/jquery.ajaxfileupload.js"></script>
<script type="text/javascript">

$(function () {
Expand Down Expand Up @@ -111,19 +111,28 @@ function addUserGroup(){
options : {},
required : true,
html : {
attr : 'style="font-size:14px;width:120px"',
attr : 'style="font-size:14px;width:120px"',
caption : 'Badge'
}
},
{
name : 'icon',
type : 'text',
options : {},
type : 'file',
options : {
max : 1,
onAdd: (event) => {
var name = event.file.name;
if(name.endsWith(".jpg") || name.endsWith(".bmp") || name.endsWith(".png") || name.endsWith(".gif") ){} else {
alert('File type should be jpg,bmp,png or gif');
event.preventDefault()
}
}
},
required : true,
html : {
attr : 'style="font-size:14px;width:130px"',
caption : 'Icon Class Name'
}
attr : 'style="font-size:14px;width:250px"',
caption : 'Icon'
},
},
],
record: {
Expand Down Expand Up @@ -220,15 +229,23 @@ function editUserGroup(id){
caption : 'Badge'
}
},
{
{
name : 'icon',
type : 'text',
options : {},
required : true,
type : 'file',
options : {
max : 1,
onAdd: (event) => {
var name = event.file.name;
if(name.endsWith(".jpg") || name.endsWith(".bmp") || name.endsWith(".png") || name.endsWith(".gif") ){} else {
alert('File type should be jpg,bmp,png or gif');
event.preventDefault()
}
}
},
html : {
attr : 'style="font-size:14px;width:130px"',
caption : 'Icon Class Name'
}
attr : 'style="font-size:14px;width:250px"',
caption : 'Icon: (leave it<br> blank to ignore)<br>'
},
},
],
actions: {
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Defines
define('ROOT_DIR', realpath(dirname(__FILE__)) .'/');
define('APP_DIR', ROOT_DIR .'application/');
define('ROOT_STATIC_DIR',ROOT_DIR .'static/');

// FOR INSTALLER
$_CF_FILE = APP_DIR .'config/config.php';
Expand Down
2 changes: 1 addition & 1 deletion static/js/w2ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10806,7 +10806,7 @@ var w2confirm = function (msg, title, callBack) {
case 'file':
defaults = {
selected : [],
placeholder : w2utils.lang('Attach files by dragging and dropping or Click to Select'),
placeholder : w2utils.lang('Click to select'),
max : 0,
maxSize : 0, // max size of all files, 0 - unlim
maxFileSize : 0, // max size of a single file, 0 -unlim
Expand Down

0 comments on commit 1bb2ea5

Please sign in to comment.