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
|
|
|
if (!function_exists('increment_visits')) { |
276
|
|
|
/** |
277
|
|
|
* increment visits. |
278
|
|
|
* |
279
|
|
|
* @param $row |
280
|
|
|
* @param string $key is $key_visits_slug |
281
|
|
|
*/ |
282
|
|
|
function increment_visits($row, $key = 'page') |
283
|
|
|
{ |
284
|
|
|
$key .= '_visits_'.$row->slug; |
285
|
|
|
if (!Session::has($key)) { |
286
|
|
|
$row->timestamps = false; |
287
|
|
|
$row->increment('visits'); |
288
|
|
|
Session::put($key, 1); |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
/*---------------------------------- </> --------------------------------*/ |
293
|
|
|
|
294
|
|
|
if (!function_exists('json_not_found_item')) { |
295
|
|
|
/** |
296
|
|
|
* @param $item_or_page |
297
|
|
|
* @param $code |
298
|
|
|
* |
299
|
|
|
* @return JsonResponse |
300
|
|
|
*/ |
301
|
|
|
function json_not_found_item($item_or_page = null, $code = null) |
302
|
|
|
{ |
303
|
|
|
$item_or_page = $item_or_page ?? 'Item'; |
304
|
|
|
$code = $code ?? 404; |
305
|
|
|
$message = $message ?? $code.". This {$item_or_page} Not found."; |
|
|
|
|
306
|
|
|
|
307
|
|
|
return response()->json($message, $code); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
/*---------------------------------- </> --------------------------------*/ |
311
|
|
|
|
312
|
|
|
if (!function_exists('json_not_authorize')) { |
313
|
|
|
/** |
314
|
|
|
* @return JsonResponse |
315
|
|
|
*/ |
316
|
|
|
function json_not_authorize() |
317
|
|
|
{ |
318
|
|
|
return response()->json('not authorize to visit this page', 401); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
/*---------------------------------- </> --------------------------------*/ |
322
|
|
|
|
323
|
|
|
if (!function_exists('has_trash_param')) { |
324
|
|
|
/** |
325
|
|
|
* // This function to check url contains trash or not. |
326
|
|
|
* |
327
|
|
|
* @return string |
328
|
|
|
*/ |
329
|
|
|
function has_trash_param() |
330
|
|
|
{ |
331
|
|
|
$output = ''; |
332
|
|
|
if (strpos($_SERVER['REQUEST_URI'], 'admin/trash')) { |
333
|
|
|
$output = '/trash'; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
return $output; |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
/*---------------------------------- </> --------------------------------*/ |
340
|
|
|
|
341
|
|
|
if (!function_exists('editorInfo')) { |
342
|
|
|
/** |
343
|
|
|
* @param $_page |
344
|
|
|
* |
345
|
|
|
* @return string |
346
|
|
|
*/ |
347
|
|
|
function editorInfo($_page) |
348
|
|
|
{ |
349
|
|
|
$output = ''; |
350
|
|
|
$creator = $_page->createdBy ? $_page->createdBy->name : ' system '; |
351
|
|
|
$editor = $_page->updatedBy ? $_page->updatedBy->name : null; |
352
|
|
|
$created_title = __('created_by', ['name' => $creator]); |
353
|
|
|
$created_title_date = __('addition_date', ['date' => $_page->created_at]); |
354
|
|
|
$modified_title = __('updated_by', ['name' => $editor]); |
355
|
|
|
$modified_title_date = __('edition_date', ['date' => $_page->updated_at]); |
356
|
|
|
|
357
|
|
|
$output .= ''; |
358
|
|
|
$output .= "<p class='user-date-info'><span data-toggle='tooltip' title='{$created_title}'> <i class='fas fa-plus-square'></i> ".hiddenSm($created_title).' </span>'; |
359
|
|
|
$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>'; |
360
|
|
|
if ($editor != null) { |
361
|
|
|
$output .= "<p class='user-date-info'><span data-toggle='tooltip' title='{$modified_title}'> <i class='fas fa-edit'></i> ".hiddenSm($modified_title).' </span>'; |
362
|
|
|
$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>'; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
return $output; |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
/*---------------------------------- </> --------------------------------*/ |
369
|
|
|
|
370
|
|
|
if (!function_exists('trashInfo')) { |
371
|
|
|
/** |
372
|
|
|
* @param $_page |
373
|
|
|
* |
374
|
|
|
* @return string |
375
|
|
|
*/ |
376
|
|
|
function trashInfo($_page) |
377
|
|
|
{ |
378
|
|
|
$output = ''; |
379
|
|
|
$deletedBy = $_page->deletedBy ? $_page->deletedBy->name : ' system '; |
380
|
|
|
$output .= "<p class='user-date-info'>"; |
381
|
|
|
$output .= " <span data-toggle='tooltip' title='تم حذفه بواسطة {$deletedBy}'> <i class='fas fa-trash'></i> ".hiddenSm('تم حذفه بواسطة :'.$deletedBy).' </span>'; |
382
|
|
|
$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>'; |
383
|
|
|
$output .= '</p>'; |
384
|
|
|
|
385
|
|
|
return $output; |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
/*---------------------------------- </> --------------------------------*/ |
389
|
|
|
|
390
|
|
|
if (!function_exists('hiddenSm')) { |
391
|
|
|
/** |
392
|
|
|
* @param $data |
393
|
|
|
* @param $className |
394
|
|
|
* |
395
|
|
|
* @return string |
396
|
|
|
*/ |
397
|
|
|
function hiddenSm($data, $className = null) |
398
|
|
|
{ |
399
|
|
|
$className = $className ?? 'd-none d-md-inline d-lg-inline d-xl-inline'; |
400
|
|
|
|
401
|
|
|
return "<span class='{$className}'>{$data}</span>"; |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
/*---------------------------------- </> --------------------------------*/ |
405
|
|
|
|
406
|
|
|
if (!function_exists('titleLink')) { |
407
|
|
|
/** |
408
|
|
|
* @param $prefix |
409
|
|
|
* @param $row |
410
|
|
|
* @param $can_edit |
411
|
|
|
* @param string $attr |
412
|
|
|
* |
413
|
|
|
* @return string |
414
|
|
|
*/ |
415
|
|
|
function titleLink($prefix, $row, $can_edit, $attr = 'title') |
416
|
|
|
{ |
417
|
|
|
$output = '<p>'; |
418
|
|
|
foreach (langSymbols() as $symbol) { |
|
|
|
|
419
|
|
|
if (isset($row->{langAttr($attr, $symbol)})) { |
420
|
|
|
$_title = $row->{langAttr($attr, $symbol)}; |
421
|
|
|
$str_title = Str::limit($_title, 50); |
422
|
|
|
$output .= "<span data-toggle='tooltip' title='{$_title}' >{$str_title}</span><br/>"; |
423
|
|
|
if ($can_edit) { |
424
|
|
|
$output .= "<a href='/{$prefix}/{$row->id}/edit' data-toggle='tooltip' title='{$_title}' >{$str_title}</a><br/>"; |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
return "{$output}</p>"; |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
/*---------------------------------- </> --------------------------------*/ |
433
|
|
|
|
434
|
|
|
if (!function_exists('slugLink')) { |
435
|
|
|
/** |
436
|
|
|
* @param $row |
437
|
|
|
* @param string $prefix |
438
|
|
|
* @param null $url |
|
|
|
|
439
|
|
|
* |
440
|
|
|
* @return string |
441
|
|
|
*/ |
442
|
|
|
function slugLink($row, $prefix = '', $url = null) |
443
|
|
|
{ |
444
|
|
|
if (!$url) { |
|
|
|
|
445
|
|
|
$url = url($prefix.'/'.$row->slug); |
446
|
|
|
} |
447
|
|
|
// $fullLink=url($row->slug); |
448
|
|
|
// $output = "<a href='$url' target='_blank' data-toggle='tooltip' title='{$fullLink}'>$row->slug</a>"; |
449
|
|
|
return "<a href='{$url}' target='_blank' data-toggle='tooltip' title='زيارة الرابط: {$row->slug}'>{$row->slug}</a>"; |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
/*---------------------------------- </> --------------------------------*/ |
453
|
|
|
|
454
|
|
|
if (!function_exists('actionLinks')) { |
455
|
|
|
/** |
456
|
|
|
* @param $row |
457
|
|
|
* @param $prefix |
458
|
|
|
* @param $user_can_edit |
459
|
|
|
* @param $user_can_delete |
460
|
|
|
* |
461
|
|
|
* @return string |
462
|
|
|
*/ |
463
|
|
|
function actionLinks($row, $prefix, $user_can_edit, $user_can_delete) |
464
|
|
|
{ |
465
|
|
|
// if ($modelName == null) { |
466
|
|
|
// $modelName = str_replace('admin/', '', $prefix); |
467
|
|
|
// } |
468
|
|
|
if (auth()->check()) { |
469
|
|
|
$output = ''; |
470
|
|
|
$trans_edit = __('edit'); |
471
|
|
|
if ($prefix == null and $user_can_edit) { |
472
|
|
|
$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>"; |
473
|
|
|
} else { |
474
|
|
|
if ($user_can_edit) { |
475
|
|
|
$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>"; |
476
|
|
|
} |
477
|
|
|
} |
478
|
|
|
if ($user_can_delete) { |
479
|
|
|
$trans_delete = __('delete'); |
480
|
|
|
$output .= "<button class='btn btn-danger w-100 btn-xs delete' id='{$row->id}'><i class='fas fa-trash'></i> {$trans_delete} </button>"; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
return $output; |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
/*---------------------------------- </> --------------------------------*/ |
488
|
|
|
|
489
|
|
|
if (!function_exists('trashActionLinks')) { |
490
|
|
|
/** |
491
|
|
|
* @param $row |
492
|
|
|
* @param $user_can_restore |
493
|
|
|
* @param $user_can_force_delete |
494
|
|
|
* |
495
|
|
|
* @return string |
496
|
|
|
*/ |
497
|
|
|
function trashActionLinks($row, $user_can_restore, $user_can_force_delete) |
498
|
|
|
{ |
499
|
|
|
$output = ''; |
500
|
|
|
if (auth()->check()) { |
501
|
|
|
if ($user_can_restore) { |
502
|
|
|
$restore = __('restore'); |
503
|
|
|
$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>"; |
504
|
|
|
} |
505
|
|
|
if ($user_can_force_delete) { |
506
|
|
|
$force_delete = __('force_delete'); |
507
|
|
|
$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>"; |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
return $output; |
512
|
|
|
} |
513
|
|
|
} |
514
|
|
|
/*---------------------------------- </> --------------------------------*/ |
515
|
|
|
|
516
|
|
|
if (!function_exists('addTableButton')) { |
517
|
|
|
function addTableButton($modelName, $title = null, $href = null, $name = null, $id = null, $icon = null) |
518
|
|
|
{ |
519
|
|
|
if (!is_can_create($modelName)) { |
520
|
|
|
return ''; |
521
|
|
|
} |
522
|
|
|
if (has_trash_param()) { |
523
|
|
|
return ''; |
524
|
|
|
} |
525
|
|
|
$name = $name ?? 'add'; |
526
|
|
|
$id = $id ?? 'add-btn'; |
527
|
|
|
$icon = $icon ?? 'fa-plus'; |
528
|
|
|
if (!$href) { |
529
|
|
|
$output = "<button class='btn btn-tool {$id}' name='{$name}' id='{$id}'> |
530
|
|
|
<i class='fas fa-fw {$icon} text-success'></i> |
531
|
|
|
{$title} |
532
|
|
|
</button> |
533
|
|
|
|
534
|
|
|
"; |
535
|
|
|
} else { |
536
|
|
|
$output = "<a href='{$href}' class='btn btn-tool {$id}' id='{$id}'> |
537
|
|
|
<i class='fas {$icon} text-success'></i> |
538
|
|
|
{$title} |
539
|
|
|
</a>"; |
540
|
|
|
} |
541
|
|
|
// <button type="button" class="btn btn-tool" data-card-widget="collapse"> |
542
|
|
|
// <i class="fas fa-minus"></i> |
543
|
|
|
// </button> |
544
|
|
|
// <button type="button" class="btn btn-tool" data-card-widget="remove"> |
545
|
|
|
// <i class="fas fa-times"></i> |
546
|
|
|
// </button> |
547
|
|
|
return $output; |
548
|
|
|
} |
549
|
|
|
} |
550
|
|
|
/*---------------------------------- </> --------------------------------*/ |
551
|
|
|
|
552
|
|
|
if (!function_exists('addTrashButton')) { |
553
|
|
|
function addTrashButton($permissionName, $href = null, $params = null) |
554
|
|
|
{ |
555
|
|
|
$request_has_trashed = has_trash_param() ? false : true; |
556
|
|
|
if ($request_has_trashed and !is_can_restore($permissionName) and !is_can_force_delete($permissionName)) { |
557
|
|
|
return ''; |
558
|
|
|
} elseif (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
559
|
|
|
return ''; |
560
|
|
|
} |
561
|
|
|
$defaultHref = $request_has_trashed ? "/admin/trash/{$href}" : "/admin/{$href}"; |
562
|
|
|
$defaultTitle = $request_has_trashed ? __('button.deleted_records') : __('button.active_records'); |
563
|
|
|
$defaultId = $request_has_trashed ? 'trash_data' : 'all_data'; |
564
|
|
|
$defaultIcon = $request_has_trashed ? 'fa-trash-alt' : 'fa-list'; |
565
|
|
|
|
566
|
|
|
$href = url($defaultHref).$params ?? ''; |
567
|
|
|
$title = $title ?? $defaultTitle; |
|
|
|
|
568
|
|
|
$id = $id ?? $defaultId; |
|
|
|
|
569
|
|
|
$icon = $icon ?? $defaultIcon; |
|
|
|
|
570
|
|
|
|
571
|
|
|
return "<a href='{$href}' class='btn btn-sm btn-danger float-right text-capitalize' id='{$id}'> <i class='fas {$icon}'></i> {$title} </a>"; |
572
|
|
|
} |
573
|
|
|
} |
574
|
|
|
/*---------------------------------- </> --------------------------------*/ |
575
|
|
|
|
576
|
|
|
if (!function_exists('activeRecordButton')) { |
577
|
|
|
/** |
578
|
|
|
* @param $permissionName |
579
|
|
|
* @param $href |
580
|
|
|
* @param $params |
581
|
|
|
* @param $className |
582
|
|
|
* |
583
|
|
|
* @return string |
584
|
|
|
*/ |
585
|
|
|
function activeRecordButton($permissionName, $href = null, $params = null, $className = null) |
586
|
|
|
{ |
587
|
|
|
if (request()->has('active') and (request()->get('active') === 'false')) { |
588
|
|
|
$href = url("/admin/{$href}"); |
589
|
|
|
$title = $title ?? __('active_records'); |
|
|
|
|
590
|
|
|
$className = $className ?? 'btn-outline-info'; |
591
|
|
|
$icon = 'fa-fw fa-check-circle'; |
592
|
|
|
} else { |
593
|
|
|
$href = url("/admin/{$href}?active=false"); |
594
|
|
|
$title = $title ?? __('inactive_records'); |
595
|
|
|
$className = $className ?? 'btn-warning'; |
596
|
|
|
$icon = 'fa-fw fa-times-circle'; |
597
|
|
|
} |
598
|
|
|
if (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
599
|
|
|
return ''; |
600
|
|
|
} |
601
|
|
|
if ($params) { |
602
|
|
|
$href .= $params; |
603
|
|
|
} |
604
|
|
|
$id = $id ?? 'all_data'; |
|
|
|
|
605
|
|
|
$icon = $icon ?? 'fa-fw fa-check-circle'; |
606
|
|
|
|
607
|
|
|
return "<div class=''> <a href='{$href}' class='btn {$className} mx-2' id='{$id}'> <i class='fas {$icon}'></i> {$title} </a></div>"; |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
/*---------------------------------- </> --------------------------------*/ |
611
|
|
|
|
612
|
|
|
if (!function_exists('activeButton')) { |
613
|
|
|
function activeButton($item = null) |
614
|
|
|
{ |
615
|
|
|
if ($item) { |
616
|
|
|
$checked = old('active', $item->active) != 1 ? '' : 'checked'; |
617
|
|
|
} else { |
618
|
|
|
$checked = 'checked'; |
619
|
|
|
} |
620
|
|
|
$active = __('active').' <i class="fas fa-check"></i>'; |
|
|
|
|
621
|
|
|
$inactive = __('inactive').' <i class="fas fa-times"> </i>'; |
|
|
|
|
622
|
|
|
|
623
|
|
|
return "<div class='checkbox '> |
624
|
|
|
<!-- edit active button --> |
625
|
|
|
<input type='checkbox' class='text-center align-middle' name='active' id='_active' |
626
|
|
|
data-toggle='toggle' |
627
|
|
|
data-on='{$active}' data-onstyle='success' data-off='{$inactive}' data-offstyle='danger' data-width='125' value='1' {$checked}> |
628
|
|
|
<!-- edit active button --> |
629
|
|
|
</div>"; |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
/*---------------------------------- </> --------------------------------*/ |
633
|
|
|
|
634
|
|
|
if (!function_exists('copyBtn')) { |
635
|
|
|
/** |
636
|
|
|
* @param $shorten_link |
637
|
|
|
* @param $className |
638
|
|
|
* |
639
|
|
|
* @return string |
640
|
|
|
*/ |
641
|
|
|
function copyBtn($shorten_link, $className = null) |
642
|
|
|
{ |
643
|
|
|
$className = $className ?? 'float-right'; |
644
|
|
|
|
645
|
|
|
return " <button class='btn border btn-light btn-clipboard {$className}' data-toggle='tooltip' data-clipboard-text='{$shorten_link}' title='".__('copy')."'> |
|
|
|
|
646
|
|
|
<img src='".asset('img/clippy.svg')." ' width='17px' alt='".__('copy_to_clipboard')."'></button>"; |
|
|
|
|
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
/*---------------------------------- </> --------------------------------*/ |
650
|
|
|
|
651
|
|
|
if (!function_exists('backButton')) { |
652
|
|
|
/** |
653
|
|
|
* @return string |
654
|
|
|
*/ |
655
|
|
|
function backButton() |
656
|
|
|
{ |
657
|
|
|
$url = url()->previous(); |
658
|
|
|
$title = __('back'); |
659
|
|
|
|
660
|
|
|
return "<a href='$url' class=' btn btn-default float-right'> <i class='fas fa-fw fa-chevron-circle-left'></i> $title </a>"; |
661
|
|
|
} |
662
|
|
|
} |
663
|
|
|
/*---------------------------------- </> --------------------------------*/ |
664
|
|
|
|
665
|
|
|
if (!function_exists('ClassName')) { |
666
|
|
|
function ClassName($modelName) |
667
|
|
|
{ |
668
|
|
|
// check name if content \\ dont add App as prefix model |
669
|
|
|
if (strpos($modelName, '\\') === false) { |
670
|
|
|
$modelName = "\App\\{$modelName}"; |
671
|
|
|
} |
672
|
|
|
// if(!(class_exists($modelName))) { |
673
|
|
|
// return "$modelName model Not Found."; |
674
|
|
|
// } |
675
|
|
|
return $modelName; |
676
|
|
|
} |
677
|
|
|
} |
678
|
|
|
/*---------------------------------- </> --------------------------------*/ |
679
|
|
|
|
680
|
|
|
if (!function_exists('viewOrError')) { |
681
|
|
|
function viewOrError($permissionName, $viewName, $type) |
682
|
|
|
{ |
683
|
|
|
if (!is_can_create($permissionName)) { |
684
|
|
|
return view('backend.errors.401'); |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
return view($viewName.$type); |
688
|
|
|
} |
689
|
|
|
} |
690
|
|
|
/*---------------------------------- </> --------------------------------*/ |
691
|
|
|
|
692
|
|
|
if (!function_exists('getActionColumn')) { |
693
|
|
|
function getActionColumn($datatable, $can_edit, $can_delete, $can_restore, $can_force_delete, $trash) |
694
|
|
|
{ |
695
|
|
|
$datatable->addColumn('action', function ($row) use ($can_edit, $can_delete, $can_restore, $can_force_delete, $trash) { |
696
|
|
|
if ($trash) { |
697
|
|
|
return trashActionLinks($row, $can_restore, $can_force_delete); |
698
|
|
|
} else { |
699
|
|
|
return actionLinks($row, $row->adminPrefix, $can_edit, $can_delete); |
700
|
|
|
} |
701
|
|
|
}); |
702
|
|
|
} |
703
|
|
|
} |
704
|
|
|
/*---------------------------------- </> --------------------------------*/ |
705
|
|
|
|
706
|
|
|
if (!function_exists('list_of_error_codes')) { |
707
|
|
|
function list_of_error_codes() |
708
|
|
|
{ |
709
|
|
|
return config('record_errors.codes'); |
710
|
|
|
// return [ |
711
|
|
|
// ['code' => 401, 'icon' => 'fas fa-fas fa-fw fa-exclamation', 'bg-color' => 'bg-warning', 'color' => 'warning'], |
712
|
|
|
// ['code' => 403, 'icon' => 'fas fa-fas fa-fw fa-exclamation-circle', 'bg-color' => 'bg-blue', 'color' => 'blue'], |
713
|
|
|
// ['code' => 404, 'icon' => 'fas fa-fas fa-fw fa-exclamation-triangle', 'bg-color' => 'bg-danger', 'color' => 'danger'], |
714
|
|
|
// ['code' => 419, 'icon' => 'fas fa-fas fa-fw fa-exclamation-circle', 'bg-color' => 'bg-secondary', 'color' => 'secondary'], |
715
|
|
|
// ['code' => 429, 'icon' => 'fas fa-fas fa-fw fa-exclamation-circle', 'bg-color' => 'bg-dark', 'color' => 'dark'], |
716
|
|
|
// ['code' => 500, 'icon' => 'fas fa-fas fa-fw fa-exclamation-triangle', 'bg-color' => 'bg-danger', 'color' => 'danger'], |
717
|
|
|
// ['code' => 503, 'icon' => 'fas fa-fas fa-fw fa-exclamation', 'bg-color' => 'bg-info', 'color' => 'info'], |
718
|
|
|
// ]; |
719
|
|
|
} |
720
|
|
|
} |
721
|
|
|
/*---------------------------------- </> --------------------------------*/ |
722
|
|
|
|
723
|
|
|
if (!function_exists('list_of_menu_error_items')) { |
724
|
|
|
function list_of_menu_error_items() |
725
|
|
|
{ |
726
|
|
|
$items = []; |
727
|
|
|
foreach (list_of_error_codes() as $erra) { |
728
|
|
|
$items[] = [ |
729
|
|
|
'text' => "{$erra['code']} Error Records ", |
730
|
|
|
'url' => "errors-management/records/{$erra['code']}", |
731
|
|
|
'icon_color' => "{$erra['color']}", |
732
|
|
|
'icon' => "{$erra['icon']}", |
733
|
|
|
// 'can' => 'show-error-records' |
734
|
|
|
]; |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
return $items; |
738
|
|
|
} |
739
|
|
|
} |
740
|
|
|
/*---------------------------------- </> --------------------------------*/ |
741
|
|
|
|
742
|
|
|
if (!function_exists('displayVisitsCount')) { |
743
|
|
|
function displayVisitsCount($value) |
744
|
|
|
{ |
745
|
|
|
if ($value > 1000000) { |
746
|
|
|
$number = $value / 1000000; |
747
|
|
|
|
748
|
|
|
return $newVal = number_format($number, 2).'M'; |
|
|
|
|
749
|
|
|
} else { |
750
|
|
|
if ($value > 1000) { |
751
|
|
|
$number = $value / 1000; |
752
|
|
|
|
753
|
|
|
return $newVal = number_format($number, 2).'K'; |
754
|
|
|
} |
755
|
|
|
} |
756
|
|
|
//if you want 2 decimal digits |
757
|
|
|
} |
758
|
|
|
} |
759
|
|
|
/*---------------------------------- </> --------------------------------*/ |
760
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: