|
1
|
|
|
<?php namespace crocodicstudio\crudbooster\controllers; |
|
2
|
|
|
|
|
3
|
|
|
use CRUDBooster; |
|
|
|
|
|
|
4
|
|
|
use Illuminate\Support\Facades\Cache; |
|
5
|
|
|
use Illuminate\Support\Facades\DB; |
|
6
|
|
|
use Illuminate\Support\Facades\Excel; |
|
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\PDF; |
|
|
|
|
|
|
8
|
|
|
use Illuminate\Support\Facades\Request; |
|
9
|
|
|
use Illuminate\Support\Facades\Storage; |
|
10
|
|
|
|
|
11
|
|
|
class SettingsController extends CBController |
|
12
|
|
|
{ |
|
13
|
|
|
public function cbInit() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->module_name = "Settings"; |
|
16
|
|
|
$this->table = 'cms_settings'; |
|
17
|
|
|
$this->primary_key = 'id'; |
|
18
|
|
|
$this->title_field = "name"; |
|
19
|
|
|
$this->index_orderby = ['name' => 'asc']; |
|
|
|
|
|
|
20
|
|
|
$this->button_delete = true; |
|
21
|
|
|
$this->button_show = false; |
|
22
|
|
|
$this->button_cancel = false; |
|
23
|
|
|
$this->button_import = false; |
|
24
|
|
|
$this->button_export = false; |
|
25
|
|
|
|
|
26
|
|
|
$this->col = []; |
|
27
|
|
|
$this->col[] = ["label" => "Nama", "name" => "name", "callback_php" => "ucwords(str_replace('_',' ',%field%))"]; |
|
28
|
|
|
$this->col[] = ["label" => "Setting", "name" => "content"]; |
|
29
|
|
|
|
|
30
|
|
|
$this->form = []; |
|
31
|
|
|
|
|
32
|
|
|
if (Request::get('group_setting')) { |
|
33
|
|
|
$value = Request::get('group_setting'); |
|
34
|
|
|
} else { |
|
35
|
|
|
$value = 'General Setting'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->form[] = ['label' => 'Group', 'name' => 'group_setting', 'value' => $value]; |
|
39
|
|
|
$this->form[] = ['label' => 'Label', 'name' => 'label']; |
|
40
|
|
|
|
|
41
|
|
|
$this->form[] = [ |
|
42
|
|
|
"label" => "Type", |
|
43
|
|
|
"name" => "content_input_type", |
|
44
|
|
|
"type" => "select", |
|
45
|
|
|
"dataenum" => ["text", "number", "email", "textarea", "wysiwyg", "upload_image", "upload_document", "datepicker", "radio", "select"], |
|
46
|
|
|
]; |
|
47
|
|
|
$this->form[] = [ |
|
48
|
|
|
"label" => "Radio / Select Data", |
|
49
|
|
|
"name" => "dataenum", |
|
50
|
|
|
"placeholder" => "Example : abc,def,ghi", |
|
51
|
|
|
"jquery" => " |
|
52
|
|
|
function show_radio_data() { |
|
53
|
|
|
var cit = $('#content_input_type').val(); |
|
54
|
|
|
if(cit == 'radio' || cit == 'select') { |
|
55
|
|
|
$('#form-group-dataenum').show(); |
|
56
|
|
|
}else{ |
|
57
|
|
|
$('#form-group-dataenum').hide(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
$('#content_input_type').change(show_radio_data); |
|
61
|
|
|
show_radio_data(); |
|
62
|
|
|
", |
|
63
|
|
|
]; |
|
64
|
|
|
$this->form[] = ["label" => "Helper Text", "name" => "helper", "type" => "text"]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
function getShow() |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
$this->cbLoader(); |
|
70
|
|
|
|
|
71
|
|
|
if (! CRUDBooster::isSuperadmin()) { |
|
72
|
|
|
CRUDBooster::insertLog(trans("crudbooster.log_try_view", ['name' => 'Setting', 'module' => 'Setting'])); |
|
73
|
|
|
CRUDBooster::redirect(CRUDBooster::adminPath(), trans('crudbooster.denied_access')); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$data['page_title'] = urldecode(Request::get('group')); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
return view('crudbooster::setting', $data); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
function hook_before_edit(&$posdata, $id) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$this->return_url = CRUDBooster::mainpath("show")."?group=".$posdata['group_setting']; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
function getDeleteFileSetting() |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
$id = g('id'); |
|
89
|
|
|
$row = CRUDBooster::first('cms_settings', $id); |
|
90
|
|
|
Cache::forget('setting_'.$row->name); |
|
91
|
|
|
if (Storage::exists($row->content)) { |
|
92
|
|
|
Storage::delete($row->content); |
|
93
|
|
|
} |
|
94
|
|
|
DB::table('cms_settings')->where('id', $id)->update(['content' => null]); |
|
95
|
|
|
CRUDBooster::redirect(Request::server('HTTP_REFERER'), trans('alert_delete_data_success'), 'success'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function postSaveSetting() |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
|
|
101
|
|
|
if (! CRUDBooster::isSuperadmin()) { |
|
102
|
|
|
CRUDBooster::insertLog(trans("crudbooster.log_try_view", ['name' => 'Setting', 'module' => 'Setting'])); |
|
103
|
|
|
CRUDBooster::redirect(CRUDBooster::adminPath(), trans('crudbooster.denied_access')); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$group = Request::get('group_setting'); |
|
107
|
|
|
$setting = DB::table('cms_settings')->where('group_setting', $group)->get(); |
|
108
|
|
|
foreach ($setting as $set) { |
|
109
|
|
|
|
|
110
|
|
|
$name = $set->name; |
|
111
|
|
|
|
|
112
|
|
|
$content = Request::get($set->name); |
|
113
|
|
|
|
|
114
|
|
|
if (Request::hasFile($name)) { |
|
115
|
|
|
|
|
116
|
|
|
if ($set->content_input_type == 'upload_image') { |
|
117
|
|
|
CRUDBooster::valid([$name => 'image|max:10000'], 'view'); |
|
118
|
|
|
} else { |
|
119
|
|
|
CRUDBooster::valid([$name => 'mimes:doc,docx,xls,xlsx,ppt,pptx,pdf,zip,rar|max:20000'], 'view'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$file = Request::file($name); |
|
123
|
|
|
$ext = $file->getClientOriginalExtension(); |
|
124
|
|
|
|
|
125
|
|
|
//Create Directory Monthly |
|
126
|
|
|
$directory = 'uploads/'.date('Y-m'); |
|
127
|
|
|
Storage::makeDirectory($directory); |
|
128
|
|
|
|
|
129
|
|
|
//Move file to storage |
|
130
|
|
|
$filename = md5(str_random(5)).'.'.$ext; |
|
|
|
|
|
|
131
|
|
|
$storeFile = Storage::putFileAs($directory, $file, $filename); |
|
132
|
|
|
if ($storeFile) { |
|
133
|
|
|
$content = $directory.'/'.$filename; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
DB::table('cms_settings')->where('name', $set->name)->update(['content' => $content]); |
|
138
|
|
|
|
|
139
|
|
|
Cache::forget('setting_'.$set->name); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return redirect()->back()->with(['message' => 'Your setting has been saved !', 'message_type' => 'success']); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
function hook_before_add(&$arr) |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
$arr['name'] = str_slug($arr['label'], '_'); |
|
|
|
|
|
|
148
|
|
|
$this->return_url = CRUDBooster::mainpath("show")."?group=".$arr['group_setting']; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
function hook_after_edit($id) |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
$row = DB::table($this->table)->where($this->primary_key, $id)->first(); |
|
154
|
|
|
|
|
155
|
|
|
/* REMOVE CACHE */ |
|
156
|
|
|
Cache::forget('setting_'.$row->name); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths