|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Author: Zahir Hayrullah |
|
5
|
|
|
* create date : 10/04/2020 07:00 AM |
|
6
|
|
|
* Last Modified Date: 10/04/2020 07:00 AM. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Illuminate\Contracts\Auth\Authenticatable; |
|
10
|
|
|
use Illuminate\Contracts\View\Factory; |
|
11
|
|
|
use Illuminate\Http\JsonResponse; |
|
12
|
|
|
use Illuminate\Support\Facades\Session; |
|
13
|
|
|
use Illuminate\Support\Str; |
|
14
|
|
|
use Illuminate\View\View; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
if (!function_exists('get_auth_user')) { |
|
17
|
|
|
/** |
|
18
|
|
|
* @param $user |
|
19
|
|
|
* |
|
20
|
|
|
* @return Authenticatable|null |
|
21
|
|
|
*/ |
|
22
|
|
|
function get_auth_user($user = null) |
|
23
|
|
|
{ |
|
24
|
|
|
$key = $user ? "auth_user_{$user->id}" : 'auth_user'; |
|
25
|
|
|
if (!Session::has($key)) { |
|
26
|
|
|
// 1-session again |
|
27
|
|
|
$user = $user ?? auth()->user(); |
|
28
|
|
|
Session::put($key, $user); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return session($key); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
35
|
|
|
|
|
36
|
|
|
if (!function_exists('user_avatar')) { |
|
37
|
|
|
/** |
|
38
|
|
|
* @param $user |
|
39
|
|
|
* |
|
40
|
|
|
* @return mixed |
|
41
|
|
|
*/ |
|
42
|
|
|
function user_avatar($user = null) |
|
43
|
|
|
{ |
|
44
|
|
|
return optional(get_auth_user($user))->avatar; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
48
|
|
|
|
|
49
|
|
|
if (!function_exists('user_roles')) { |
|
50
|
|
|
/** |
|
51
|
|
|
* @param $user |
|
52
|
|
|
* |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
function user_roles($user = null) |
|
56
|
|
|
{ |
|
57
|
|
|
return optional(get_auth_user($user))->roles; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
61
|
|
|
|
|
62
|
|
|
if (!function_exists('getArrayValidationErrors')) { |
|
63
|
|
|
/** |
|
64
|
|
|
* @param $validation |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
function getArrayValidationErrors($validation) |
|
69
|
|
|
{ |
|
70
|
|
|
$error_array = []; |
|
71
|
|
|
if ($validation) { |
|
72
|
|
|
foreach ($validation->messages()->getMessages() as $field_name => $messages) { |
|
73
|
|
|
$error_array[] = $messages; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $error_array; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
81
|
|
|
|
|
82
|
|
|
if (!function_exists('jsonOutput')) { |
|
83
|
|
|
/** |
|
84
|
|
|
* @param $error_array |
|
85
|
|
|
* @param $success_output |
|
86
|
|
|
* |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
function jsonOutput($error_array, $success_output = null) |
|
90
|
|
|
{ |
|
91
|
|
|
return [ |
|
92
|
|
|
'error' => $error_array, |
|
93
|
|
|
'success' => $success_output, |
|
94
|
|
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
98
|
|
|
|
|
99
|
|
|
if (!function_exists('callAPI')) { |
|
100
|
|
|
/** |
|
101
|
|
|
* @param $method |
|
102
|
|
|
* @param $url |
|
103
|
|
|
* @param $data |
|
104
|
|
|
* |
|
105
|
|
|
* @return bool|string |
|
106
|
|
|
*/ |
|
107
|
|
|
function callAPI($method, $url, $data = null) |
|
108
|
|
|
{ |
|
109
|
|
|
// $data must be json when method is post |
|
110
|
|
|
$curl = curl_init(); |
|
111
|
|
|
if (!$curl) { |
|
|
|
|
|
|
112
|
|
|
return false; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
switch ($method) { |
|
116
|
|
|
case 'POST': |
|
117
|
|
|
curl_setopt($curl, CURLOPT_POST, 1); |
|
118
|
|
|
break; |
|
119
|
|
|
case 'PUT': |
|
120
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
121
|
|
|
break; |
|
122
|
|
|
} |
|
123
|
|
|
if ($data) { |
|
124
|
|
|
curl_setopt($curl, CURLOPT_POST, $data); |
|
125
|
|
|
$url = sprintf('%s?%s', $url, http_build_query($data)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$headers = get_api_headers(); |
|
129
|
|
|
// OPTIONS: |
|
130
|
|
|
|
|
131
|
|
|
curl_setopt($curl, CURLOPT_URL, $url); |
|
132
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
|
133
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
134
|
|
|
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
|
135
|
|
|
|
|
136
|
|
|
// EXECUTE: |
|
137
|
|
|
$result = curl_exec($curl); |
|
138
|
|
|
// if (!$result) { |
|
139
|
|
|
// die('Connection Failure'); |
|
140
|
|
|
// } |
|
141
|
|
|
curl_close($curl); |
|
142
|
|
|
|
|
143
|
|
|
return $result; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
147
|
|
|
|
|
148
|
|
|
if (!function_exists('get_api_headers')) { |
|
149
|
|
|
function get_api_headers($headers = []) |
|
150
|
|
|
{ |
|
151
|
|
|
$headers[] = 'Content-Type: application/json'; |
|
152
|
|
|
if (array_key_exists('HTTP_HOST', $_SERVER)) { |
|
153
|
|
|
$headers[] = 'ORIGIN: '.$_SERVER['HTTP_HOST']; |
|
154
|
|
|
} |
|
155
|
|
|
if (array_key_exists('HTTP_REFERER', $_SERVER)) { |
|
156
|
|
|
$headers[] = 'REFERER: '.$_SERVER['HTTP_REFERER']; |
|
157
|
|
|
} |
|
158
|
|
|
if (array_key_exists('HTTP_ORIGIN', $_SERVER)) { |
|
159
|
|
|
$headers[] = 'ORIGIN: '.$_SERVER['HTTP_ORIGIN']; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $headers; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
166
|
|
|
|
|
167
|
|
|
if (!function_exists('delete_record')) { |
|
168
|
|
|
/** |
|
169
|
|
|
* @param $item |
|
170
|
|
|
* @param $permissionName |
|
171
|
|
|
* |
|
172
|
|
|
* @return JsonResponse |
|
173
|
|
|
*/ |
|
174
|
|
|
function delete_record($item, $permissionName) |
|
175
|
|
|
{ |
|
176
|
|
|
if (!is_can_delete($permissionName)) { |
|
177
|
|
|
return response()->json("You don't have authorize to delete this item.", 401); |
|
178
|
|
|
} |
|
179
|
|
|
// $item = ClassName($modelName)::find($id); |
|
180
|
|
|
if ($item) { |
|
181
|
|
|
$item->delete(); |
|
182
|
|
|
|
|
183
|
|
|
return response()->json('The item has been "deleted" successfully', 200); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
return response()->json('The item not found', 404); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
190
|
|
|
|
|
191
|
|
|
if (!function_exists('restore_record')) { |
|
192
|
|
|
/** |
|
193
|
|
|
* @param $item |
|
194
|
|
|
* @param $permissionName |
|
195
|
|
|
* |
|
196
|
|
|
* @return JsonResponse |
|
197
|
|
|
*/ |
|
198
|
|
|
function restore_record($item, $permissionName) |
|
199
|
|
|
{ |
|
200
|
|
|
if (!is_can_restore($permissionName)) { |
|
201
|
|
|
return response()->json("You don't have authorize to restore this item.", 401); |
|
202
|
|
|
} |
|
203
|
|
|
// $item = ClassName($modelName)::withTrashed()->find($id); |
|
204
|
|
|
if ($item) { |
|
205
|
|
|
$item->restore(); |
|
206
|
|
|
|
|
207
|
|
|
return response()->json('The item has been "restored" successfully', 200); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
return response()->json('The item not found', 404); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
214
|
|
|
|
|
215
|
|
|
if (!function_exists('force_delete_record')) { |
|
216
|
|
|
/** |
|
217
|
|
|
* @param $item |
|
218
|
|
|
* @param $permissionName |
|
219
|
|
|
* |
|
220
|
|
|
* @return JsonResponse |
|
221
|
|
|
*/ |
|
222
|
|
|
function force_delete_record($item, $permissionName) |
|
223
|
|
|
{ |
|
224
|
|
|
if (!is_can_force_delete($permissionName)) { |
|
225
|
|
|
return response()->json("You don't have authorize to destroy this item.", 401); |
|
226
|
|
|
} |
|
227
|
|
|
// $item = ClassName($modelName)::withTrashed()->find($id); |
|
228
|
|
|
if ($item) { |
|
229
|
|
|
$item->forceDelete(); |
|
230
|
|
|
|
|
231
|
|
|
return response()->json('The item has been "destroyed" successfully', 200); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
return response()->json('The item not found', 404); |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
238
|
|
|
|
|
239
|
|
|
if (!function_exists('show_record')) { |
|
240
|
|
|
/** |
|
241
|
|
|
* @param $request |
|
242
|
|
|
* @param $modelName |
|
243
|
|
|
* @param $id |
|
244
|
|
|
* @param $permissionName |
|
245
|
|
|
* @param $with |
|
246
|
|
|
* |
|
247
|
|
|
* @return Factory|JsonResponse|View|void |
|
248
|
|
|
*/ |
|
249
|
|
|
function show_record($request, $modelName, $id, $permissionName = null, $with = null) |
|
250
|
|
|
{ |
|
251
|
|
|
if (!$request->ajax()) { |
|
252
|
|
|
// if Request not Ajax |
|
253
|
|
|
if (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
|
254
|
|
|
return view('backend.errors.401'); |
|
255
|
|
|
} |
|
256
|
|
|
abort(404); |
|
257
|
|
|
} |
|
258
|
|
|
if (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
|
259
|
|
|
return json_not_authorize(); |
|
260
|
|
|
} |
|
261
|
|
|
if (!is_numeric($id)) { |
|
262
|
|
|
return json_not_found_item('Page'); |
|
263
|
|
|
} |
|
264
|
|
|
$ClassName = get_class_name($modelName); |
|
265
|
|
|
$item = $ClassName::with($with)->find($id); |
|
266
|
|
|
if (!$item) { |
|
267
|
|
|
return json_not_found_item(); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
return response()->json($item, 200); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
} |
|
274
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
275
|
|
|
|
|
276
|
|
|
if (!function_exists('increment_visits')) { |
|
277
|
|
|
/** |
|
278
|
|
|
* increment visits. |
|
279
|
|
|
* |
|
280
|
|
|
* @param $row |
|
281
|
|
|
* @param string $key is $key_visits_slug |
|
282
|
|
|
*/ |
|
283
|
|
|
function increment_visits($row, $key = 'page') |
|
284
|
|
|
{ |
|
285
|
|
|
$key .= '_visits_'.$row->slug; |
|
286
|
|
|
if (!Session::has($key)) { |
|
287
|
|
|
$row->timestamps = false; |
|
288
|
|
|
$row->increment('visits'); |
|
289
|
|
|
Session::put($key, 1); |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
294
|
|
|
|
|
295
|
|
|
if (!function_exists('json_not_found_item')) { |
|
296
|
|
|
/** |
|
297
|
|
|
* @param $item_or_page |
|
298
|
|
|
* @param $code |
|
299
|
|
|
* |
|
300
|
|
|
* @return JsonResponse |
|
301
|
|
|
*/ |
|
302
|
|
|
function json_not_found_item($item_or_page = null, $code = null) |
|
303
|
|
|
{ |
|
304
|
|
|
$item_or_page = $item_or_page ?? 'Item'; |
|
305
|
|
|
$code = $code ?? 404; |
|
306
|
|
|
$message = $message ?? $code.". This {$item_or_page} Not found."; |
|
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
return response()->json($message, $code); |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
312
|
|
|
|
|
313
|
|
|
if (!function_exists('json_not_authorize')) { |
|
314
|
|
|
/** |
|
315
|
|
|
* @return JsonResponse |
|
316
|
|
|
*/ |
|
317
|
|
|
function json_not_authorize() |
|
318
|
|
|
{ |
|
319
|
|
|
return response()->json('not authorize to visit this page', 401); |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
323
|
|
|
|
|
324
|
|
|
if (!function_exists('has_trash_param')) { |
|
325
|
|
|
/** |
|
326
|
|
|
* // This function to check url contains trash or not. |
|
327
|
|
|
* |
|
328
|
|
|
* @return string |
|
329
|
|
|
*/ |
|
330
|
|
|
function has_trash_param() |
|
331
|
|
|
{ |
|
332
|
|
|
$output = ''; |
|
333
|
|
|
if (strpos($_SERVER['REQUEST_URI'], 'admin/trash')) { |
|
334
|
|
|
$output = '/trash'; |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
return $output; |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
341
|
|
|
|
|
342
|
|
|
if (!function_exists('editorInfo')) { |
|
343
|
|
|
/** |
|
344
|
|
|
* @param $_page |
|
345
|
|
|
* |
|
346
|
|
|
* @return string |
|
347
|
|
|
*/ |
|
348
|
|
|
function editorInfo($_page) |
|
349
|
|
|
{ |
|
350
|
|
|
$output = ''; |
|
351
|
|
|
$creator = $_page->createdBy ? $_page->createdBy->name : ' system '; |
|
352
|
|
|
$editor = $_page->updatedBy ? $_page->updatedBy->name : null; |
|
353
|
|
|
$created_title = __('created_by', ['name' => $creator]); |
|
354
|
|
|
$created_title_date = __('addition_date', ['date' => $_page->created_at]); |
|
355
|
|
|
$modified_title = __('updated_by', ['name' => $editor]); |
|
356
|
|
|
$modified_title_date = __('edition_date', ['date' => $_page->updated_at]); |
|
357
|
|
|
|
|
358
|
|
|
$output .= ''; |
|
359
|
|
|
$output .= "<p class='user-date-info'><span data-toggle='tooltip' title='{$created_title}'> <i class='fas fa-plus-square'></i> ".hiddenSm($created_title).' </span>'; |
|
360
|
|
|
$output .= " - <span data-toggle='tooltip' title='{$created_title_date}'> <i class='fas fa-calendar-plus'></i> ".hiddenSm(optional($_page->created_at)->format('Y-m-d')).' </span></p>'; |
|
361
|
|
|
if ($editor != null) { |
|
362
|
|
|
$output .= "<p class='user-date-info'><span data-toggle='tooltip' title='{$modified_title}'> <i class='fas fa-edit'></i> ".hiddenSm($modified_title).' </span>'; |
|
363
|
|
|
$output .= " - <span data-toggle='tooltip' title='{$modified_title_date}'> <i class='fas fa-calendar'></i> ".hiddenSm(optional($_page->updated_at)->format('Y-m-d')).' </span></p>'; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
return $output; |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
370
|
|
|
|
|
371
|
|
|
if (!function_exists('trashInfo')) { |
|
372
|
|
|
/** |
|
373
|
|
|
* @param $_page |
|
374
|
|
|
* |
|
375
|
|
|
* @return string |
|
376
|
|
|
*/ |
|
377
|
|
|
function trashInfo($_page) |
|
378
|
|
|
{ |
|
379
|
|
|
$output = ''; |
|
380
|
|
|
$deletedBy = $_page->deletedBy ? $_page->deletedBy->name : ' system '; |
|
381
|
|
|
$output .= "<p class='user-date-info'>"; |
|
382
|
|
|
$output .= " <span data-toggle='tooltip' title='تم حذفه بواسطة {$deletedBy}'> <i class='fas fa-trash'></i> ".hiddenSm('تم حذفه بواسطة :'.$deletedBy).' </span>'; |
|
383
|
|
|
$output .= " - <span data-toggle='tooltip' title='تاريخ الحذف {$_page->deleted_at}'> <i class='fas fa-calendar-times'></i> ".hiddenSm('بتاريخ :'.optional($_page->deleted_at)->format('Y-m-d')).' </span>'; |
|
384
|
|
|
$output .= '</p>'; |
|
385
|
|
|
|
|
386
|
|
|
return $output; |
|
387
|
|
|
} |
|
388
|
|
|
} |
|
389
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
390
|
|
|
|
|
391
|
|
|
if (!function_exists('hiddenSm')) { |
|
392
|
|
|
/** |
|
393
|
|
|
* @param $data |
|
394
|
|
|
* @param $className |
|
395
|
|
|
* |
|
396
|
|
|
* @return string |
|
397
|
|
|
*/ |
|
398
|
|
|
function hiddenSm($data, $className = null) |
|
399
|
|
|
{ |
|
400
|
|
|
$className = $className ?? 'd-none d-md-inline d-lg-inline d-xl-inline'; |
|
401
|
|
|
|
|
402
|
|
|
return "<span class='{$className}'>{$data}</span>"; |
|
403
|
|
|
} |
|
404
|
|
|
} |
|
405
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
406
|
|
|
|
|
407
|
|
|
if (!function_exists('titleLink')) { |
|
408
|
|
|
/** |
|
409
|
|
|
* @param $prefix |
|
410
|
|
|
* @param $row |
|
411
|
|
|
* @param $can_edit |
|
412
|
|
|
* @param string $attr |
|
413
|
|
|
* |
|
414
|
|
|
* @return string |
|
415
|
|
|
*/ |
|
416
|
|
|
function titleLink($prefix, $row, $can_edit, $attr = 'title') |
|
417
|
|
|
{ |
|
418
|
|
|
$output = '<p>'; |
|
419
|
|
|
foreach (langSymbols() as $symbol) { |
|
|
|
|
|
|
420
|
|
|
if (isset($row->{langAttr($attr, $symbol)})) { |
|
421
|
|
|
$_title = $row->{langAttr($attr, $symbol)}; |
|
422
|
|
|
$str_title = Str::limit($_title, 50); |
|
423
|
|
|
$output .= "<span data-toggle='tooltip' title='{$_title}' >{$str_title}</span><br/>"; |
|
424
|
|
|
if ($can_edit) { |
|
425
|
|
|
$output .= "<a href='/{$prefix}/{$row->id}/edit' data-toggle='tooltip' title='{$_title}' >{$str_title}</a><br/>"; |
|
426
|
|
|
} |
|
427
|
|
|
} |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
return "{$output}</p>"; |
|
431
|
|
|
} |
|
432
|
|
|
} |
|
433
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
434
|
|
|
|
|
435
|
|
|
if (!function_exists('slugLink')) { |
|
436
|
|
|
/** |
|
437
|
|
|
* @param $row |
|
438
|
|
|
* @param string $prefix |
|
439
|
|
|
* @param null $url |
|
|
|
|
|
|
440
|
|
|
* |
|
441
|
|
|
* @return string |
|
442
|
|
|
*/ |
|
443
|
|
|
function slugLink($row, $prefix = '', $url = null) |
|
444
|
|
|
{ |
|
445
|
|
|
if (!$url) { |
|
|
|
|
|
|
446
|
|
|
$url = url($prefix.'/'.$row->slug); |
|
447
|
|
|
} |
|
448
|
|
|
// $fullLink=url($row->slug); |
|
449
|
|
|
// $output = "<a href='$url' target='_blank' data-toggle='tooltip' title='{$fullLink}'>$row->slug</a>"; |
|
450
|
|
|
return "<a href='{$url}' target='_blank' data-toggle='tooltip' title='زيارة الرابط: {$row->slug}'>{$row->slug}</a>"; |
|
451
|
|
|
} |
|
452
|
|
|
} |
|
453
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
454
|
|
|
|
|
455
|
|
|
if (!function_exists('actionLinks')) { |
|
456
|
|
|
/** |
|
457
|
|
|
* @param $row |
|
458
|
|
|
* @param $prefix |
|
459
|
|
|
* @param $user_can_edit |
|
460
|
|
|
* @param $user_can_delete |
|
461
|
|
|
* |
|
462
|
|
|
* @return string |
|
463
|
|
|
*/ |
|
464
|
|
|
function actionLinks($row, $prefix, $user_can_edit, $user_can_delete) |
|
465
|
|
|
{ |
|
466
|
|
|
// if ($modelName == null) { |
|
467
|
|
|
// $modelName = str_replace('admin/', '', $prefix); |
|
468
|
|
|
// } |
|
469
|
|
|
if (auth()->check()) { |
|
470
|
|
|
$output = ''; |
|
471
|
|
|
$trans_edit = __('edit'); |
|
472
|
|
|
if ($prefix == null and $user_can_edit) { |
|
473
|
|
|
$output = "<a href='javascript:void(0)' class='btn btn-primary w-100 btn-xs edit' id='{$row->id}'><i class='fas fa-pencil-alt'></i> {$trans_edit} </a>"; |
|
474
|
|
|
} else { |
|
475
|
|
|
if ($user_can_edit) { |
|
476
|
|
|
$output = "<a href='/{$prefix}/{$row->id}/edit' class='btn btn-primary w-100 btn-xs edit' id='{$row->id}'><i class='fas fa-pencil-alt'></i> {$trans_edit} </a>"; |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
if ($user_can_delete) { |
|
480
|
|
|
$trans_delete = __('delete'); |
|
481
|
|
|
$output .= "<button class='btn btn-danger w-100 btn-xs delete' id='{$row->id}'><i class='fas fa-trash'></i> {$trans_delete} </button>"; |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
return $output; |
|
485
|
|
|
} |
|
486
|
|
|
} |
|
487
|
|
|
} |
|
488
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
489
|
|
|
|
|
490
|
|
|
if (!function_exists('trashActionLinks')) { |
|
491
|
|
|
/** |
|
492
|
|
|
* @param $row |
|
493
|
|
|
* @param $user_can_restore |
|
494
|
|
|
* @param $user_can_force_delete |
|
495
|
|
|
* |
|
496
|
|
|
* @return string |
|
497
|
|
|
*/ |
|
498
|
|
|
function trashActionLinks($row, $user_can_restore, $user_can_force_delete) |
|
499
|
|
|
{ |
|
500
|
|
|
$output = ''; |
|
501
|
|
|
if (auth()->check()) { |
|
502
|
|
|
if ($user_can_restore) { |
|
503
|
|
|
$restore = __('restore'); |
|
504
|
|
|
$output = "<a href='javascript:void(0)' class='btn btn-info w-100 btn-xs btn-restore' id='{$row->id}'><i class='fas fa-trash-restore'></i> {$restore} </a>"; |
|
505
|
|
|
} |
|
506
|
|
|
if ($user_can_force_delete) { |
|
507
|
|
|
$force_delete = __('force_delete'); |
|
508
|
|
|
$output .= "<button class='btn bg-dark w-100 btn-xs btn-force-delete' id='{$row->id}'><i class='fas fa-fire-alt'></i> {$force_delete} </button>"; |
|
509
|
|
|
} |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
return $output; |
|
513
|
|
|
} |
|
514
|
|
|
} |
|
515
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
516
|
|
|
|
|
517
|
|
|
if (!function_exists('addTableButton')) { |
|
518
|
|
|
function addTableButton($modelName, $title = null, $href = null, $name = null, $id = null, $icon = null) |
|
519
|
|
|
{ |
|
520
|
|
|
if (!is_can_create($modelName)) { |
|
521
|
|
|
return ''; |
|
522
|
|
|
} |
|
523
|
|
|
if (has_trash_param()) { |
|
524
|
|
|
return ''; |
|
525
|
|
|
} |
|
526
|
|
|
$name = $name ?? 'add'; |
|
527
|
|
|
$id = $id ?? 'add-btn'; |
|
528
|
|
|
$icon = $icon ?? 'fa-plus'; |
|
529
|
|
|
if (!$href) { |
|
530
|
|
|
$output = "<button class='btn btn-tool {$id}' name='{$name}' id='{$id}'> |
|
531
|
|
|
<i class='fas fa-fw {$icon} text-success'></i> |
|
532
|
|
|
{$title} |
|
533
|
|
|
</button> |
|
534
|
|
|
|
|
535
|
|
|
"; |
|
536
|
|
|
} else { |
|
537
|
|
|
$output = "<a href='{$href}' class='btn btn-tool {$id}' id='{$id}'> |
|
538
|
|
|
<i class='fas {$icon} text-success'></i> |
|
539
|
|
|
{$title} |
|
540
|
|
|
</a>"; |
|
541
|
|
|
} |
|
542
|
|
|
// <button type="button" class="btn btn-tool" data-card-widget="collapse"> |
|
543
|
|
|
// <i class="fas fa-minus"></i> |
|
544
|
|
|
// </button> |
|
545
|
|
|
// <button type="button" class="btn btn-tool" data-card-widget="remove"> |
|
546
|
|
|
// <i class="fas fa-times"></i> |
|
547
|
|
|
// </button> |
|
548
|
|
|
return $output; |
|
549
|
|
|
} |
|
550
|
|
|
} |
|
551
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
552
|
|
|
|
|
553
|
|
|
if (!function_exists('addTrashButton')) { |
|
554
|
|
|
function addTrashButton($permissionName, $href = null, $params = null) |
|
555
|
|
|
{ |
|
556
|
|
|
$request_has_trashed = has_trash_param() ? false : true; |
|
557
|
|
|
if ($request_has_trashed and !is_can_restore($permissionName) and !is_can_force_delete($permissionName)) { |
|
558
|
|
|
return ''; |
|
559
|
|
|
} elseif (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
|
560
|
|
|
return ''; |
|
561
|
|
|
} |
|
562
|
|
|
$defaultHref = $request_has_trashed ? "/admin/trash/{$href}" : "/admin/{$href}"; |
|
563
|
|
|
$defaultTitle = $request_has_trashed ? __('button.deleted_records') : __('button.active_records'); |
|
564
|
|
|
$defaultId = $request_has_trashed ? 'trash_data' : 'all_data'; |
|
565
|
|
|
$defaultIcon = $request_has_trashed ? 'fa-trash-alt' : 'fa-list'; |
|
566
|
|
|
|
|
567
|
|
|
$href = url($defaultHref).$params ?? ''; |
|
568
|
|
|
$title = $title ?? $defaultTitle; |
|
|
|
|
|
|
569
|
|
|
$id = $id ?? $defaultId; |
|
|
|
|
|
|
570
|
|
|
$icon = $icon ?? $defaultIcon; |
|
|
|
|
|
|
571
|
|
|
|
|
572
|
|
|
return "<a href='{$href}' class='btn btn-sm btn-danger float-right text-capitalize' id='{$id}'> <i class='fas {$icon}'></i> {$title} </a>"; |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
} |
|
576
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
577
|
|
|
|
|
578
|
|
|
if (!function_exists('activeRecordButton')) { |
|
579
|
|
|
/** |
|
580
|
|
|
* @param $permissionName |
|
581
|
|
|
* @param $href |
|
582
|
|
|
* @param $params |
|
583
|
|
|
* @param $className |
|
584
|
|
|
* |
|
585
|
|
|
* @return string |
|
586
|
|
|
*/ |
|
587
|
|
|
function activeRecordButton($permissionName, $href = null, $params = null, $className = null) |
|
588
|
|
|
{ |
|
589
|
|
|
if (request()->has('active') and (request()->get('active') === 'false')) { |
|
590
|
|
|
$href = url("/admin/{$href}"); |
|
591
|
|
|
$title = $title ?? __('active_records'); |
|
|
|
|
|
|
592
|
|
|
$className = $className ?? 'btn-outline-info'; |
|
593
|
|
|
$icon = 'fa-fw fa-check-circle'; |
|
594
|
|
|
} else { |
|
595
|
|
|
$href = url("/admin/{$href}?active=false"); |
|
596
|
|
|
$title = $title ?? __('inactive_records'); |
|
597
|
|
|
$className = $className ?? 'btn-warning'; |
|
598
|
|
|
$icon = 'fa-fw fa-times-circle'; |
|
599
|
|
|
} |
|
600
|
|
|
if (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
|
601
|
|
|
return ''; |
|
602
|
|
|
} |
|
603
|
|
|
if ($params) { |
|
604
|
|
|
$href .= $params; |
|
605
|
|
|
} |
|
606
|
|
|
$id = $id ?? 'all_data'; |
|
|
|
|
|
|
607
|
|
|
$icon = $icon ?? 'fa-fw fa-check-circle'; |
|
608
|
|
|
|
|
609
|
|
|
return "<div class=''> <a href='{$href}' class='btn {$className} mx-2' id='{$id}'> <i class='fas {$icon}'></i> {$title} </a></div>"; |
|
610
|
|
|
} |
|
611
|
|
|
} |
|
612
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
613
|
|
|
|
|
614
|
|
|
if (!function_exists('activeButton')) { |
|
615
|
|
|
function activeButton($item = null) |
|
616
|
|
|
{ |
|
617
|
|
|
if ($item) { |
|
618
|
|
|
$checked = old('active', $item->active) != 1 ? '' : 'checked'; |
|
619
|
|
|
} else { |
|
620
|
|
|
$checked = 'checked'; |
|
621
|
|
|
} |
|
622
|
|
|
$active = __('active').' <i class="fas fa-check"></i>'; |
|
|
|
|
|
|
623
|
|
|
$inactive = __('inactive').' <i class="fas fa-times"> </i>'; |
|
|
|
|
|
|
624
|
|
|
|
|
625
|
|
|
return "<div class='checkbox '> |
|
626
|
|
|
<!-- edit active button --> |
|
627
|
|
|
<input type='checkbox' class='text-center align-middle' name='active' id='_active' |
|
628
|
|
|
data-toggle='toggle' |
|
629
|
|
|
data-on='{$active}' data-onstyle='success' data-off='{$inactive}' data-offstyle='danger' data-width='125' value='1' {$checked}> |
|
630
|
|
|
<!-- edit active button --> |
|
631
|
|
|
</div>"; |
|
632
|
|
|
} |
|
633
|
|
|
} |
|
634
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
635
|
|
|
|
|
636
|
|
|
if (!function_exists('copyBtn')) { |
|
637
|
|
|
/** |
|
638
|
|
|
* @param $shorten_link |
|
639
|
|
|
* @param $className |
|
640
|
|
|
* |
|
641
|
|
|
* @return string |
|
642
|
|
|
*/ |
|
643
|
|
|
function copyBtn($shorten_link, $className = null) |
|
644
|
|
|
{ |
|
645
|
|
|
$className = $className ?? 'float-right'; |
|
646
|
|
|
|
|
647
|
|
|
return " <button class='btn border btn-light btn-clipboard {$className}' data-toggle='tooltip' data-clipboard-text='{$shorten_link}' title='".__('copy')."'> |
|
|
|
|
|
|
648
|
|
|
<img src='".asset('img/clippy.svg')." ' width='17px' alt='".__('copy_to_clipboard')."'></button>"; |
|
|
|
|
|
|
649
|
|
|
} |
|
650
|
|
|
} |
|
651
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
652
|
|
|
|
|
653
|
|
|
if (!function_exists('backButton')) { |
|
654
|
|
|
/** |
|
655
|
|
|
* @return string |
|
656
|
|
|
*/ |
|
657
|
|
|
function backButton() |
|
658
|
|
|
{ |
|
659
|
|
|
$url = url()->previous(); |
|
660
|
|
|
$title = __('back'); |
|
661
|
|
|
|
|
662
|
|
|
return "<a href='$url' class=' btn btn-default float-right'> <i class='fas fa-fw fa-chevron-circle-left'></i> $title </a>"; |
|
663
|
|
|
} |
|
664
|
|
|
} |
|
665
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
666
|
|
|
|
|
667
|
|
|
if (!function_exists('ClassName')) { |
|
668
|
|
|
function ClassName($modelName) |
|
669
|
|
|
{ |
|
670
|
|
|
// check name if content \\ dont add App as prefix model |
|
671
|
|
|
if (strpos($modelName, '\\') === false) { |
|
672
|
|
|
$modelName = "\App\\{$modelName}"; |
|
673
|
|
|
} |
|
674
|
|
|
// if(!(class_exists($modelName))) { |
|
675
|
|
|
// return "$modelName model Not Found."; |
|
676
|
|
|
// } |
|
677
|
|
|
return $modelName; |
|
678
|
|
|
} |
|
679
|
|
|
} |
|
680
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
681
|
|
|
|
|
682
|
|
|
if (!function_exists('viewOrError')) { |
|
683
|
|
|
function viewOrError($permissionName, $viewName, $type) |
|
684
|
|
|
{ |
|
685
|
|
|
if (!is_can_create($permissionName)) { |
|
686
|
|
|
return view('backend.errors.401'); |
|
687
|
|
|
} |
|
688
|
|
|
|
|
689
|
|
|
return view($viewName.$type); |
|
690
|
|
|
} |
|
691
|
|
|
} |
|
692
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
693
|
|
|
|
|
694
|
|
|
if (!function_exists('getActionColumn')) { |
|
695
|
|
|
function getActionColumn($datatable, $can_edit, $can_delete, $can_restore, $can_force_delete, $trash) |
|
696
|
|
|
{ |
|
697
|
|
|
$datatable->addColumn('action', function ($row) use ($can_edit, $can_delete, $can_restore, $can_force_delete, $trash) { |
|
698
|
|
|
if ($trash) { |
|
699
|
|
|
return trashActionLinks($row, $can_restore, $can_force_delete); |
|
700
|
|
|
} else { |
|
701
|
|
|
return actionLinks($row, $row->adminPrefix, $can_edit, $can_delete); |
|
702
|
|
|
} |
|
703
|
|
|
}); |
|
704
|
|
|
} |
|
705
|
|
|
} |
|
706
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
707
|
|
|
|
|
708
|
|
|
if (!function_exists('list_of_error_codes')) { |
|
709
|
|
|
function list_of_error_codes() |
|
710
|
|
|
{ |
|
711
|
|
|
return config('record_errors.codes'); |
|
712
|
|
|
// return [ |
|
713
|
|
|
// ['code' => 401, 'icon' => 'fas fa-fas fa-fw fa-exclamation', 'bg-color' => 'bg-warning', 'color' => 'warning'], |
|
714
|
|
|
// ['code' => 403, 'icon' => 'fas fa-fas fa-fw fa-exclamation-circle', 'bg-color' => 'bg-blue', 'color' => 'blue'], |
|
715
|
|
|
// ['code' => 404, 'icon' => 'fas fa-fas fa-fw fa-exclamation-triangle', 'bg-color' => 'bg-danger', 'color' => 'danger'], |
|
716
|
|
|
// ['code' => 419, 'icon' => 'fas fa-fas fa-fw fa-exclamation-circle', 'bg-color' => 'bg-secondary', 'color' => 'secondary'], |
|
717
|
|
|
// ['code' => 429, 'icon' => 'fas fa-fas fa-fw fa-exclamation-circle', 'bg-color' => 'bg-dark', 'color' => 'dark'], |
|
718
|
|
|
// ['code' => 500, 'icon' => 'fas fa-fas fa-fw fa-exclamation-triangle', 'bg-color' => 'bg-danger', 'color' => 'danger'], |
|
719
|
|
|
// ['code' => 503, 'icon' => 'fas fa-fas fa-fw fa-exclamation', 'bg-color' => 'bg-info', 'color' => 'info'], |
|
720
|
|
|
// ]; |
|
721
|
|
|
} |
|
722
|
|
|
} |
|
723
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
724
|
|
|
|
|
725
|
|
|
if (!function_exists('list_of_menu_error_items')) { |
|
726
|
|
|
function list_of_menu_error_items() |
|
727
|
|
|
{ |
|
728
|
|
|
$items = []; |
|
729
|
|
|
foreach (list_of_error_codes() as $erra) { |
|
730
|
|
|
$items[] = [ |
|
731
|
|
|
'text' => "{$erra['code']} Error Records ", |
|
732
|
|
|
'url' => "errors-management/records/{$erra['code']}", |
|
733
|
|
|
'icon_color' => "{$erra['color']}", |
|
734
|
|
|
'icon' => "{$erra['icon']}", |
|
735
|
|
|
// 'can' => 'show-error-records' |
|
736
|
|
|
]; |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
return $items; |
|
740
|
|
|
} |
|
741
|
|
|
} |
|
742
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
743
|
|
|
|
|
744
|
|
|
if (!function_exists('displayVisitsCount')) { |
|
745
|
|
|
function displayVisitsCount($value) |
|
746
|
|
|
{ |
|
747
|
|
|
if ($value > 1000000) { |
|
748
|
|
|
$number = $value / 1000000; |
|
749
|
|
|
|
|
750
|
|
|
return $newVal = number_format($number, 2).'M'; |
|
|
|
|
|
|
751
|
|
|
} else { |
|
752
|
|
|
if ($value > 1000) { |
|
753
|
|
|
$number = $value / 1000; |
|
754
|
|
|
|
|
755
|
|
|
return $newVal = number_format($number, 2).'K'; |
|
756
|
|
|
} |
|
757
|
|
|
} |
|
758
|
|
|
//if you want 2 decimal digits |
|
759
|
|
|
} |
|
760
|
|
|
} |
|
761
|
|
|
/*---------------------------------- </> --------------------------------*/ |
|
762
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: