diff --git a/init.php b/init.php index 3b37ee04..afba5719 100644 --- a/init.php +++ b/init.php @@ -113,10 +113,23 @@ foreach ($result as $value) { $config[$value['setting']] = $value['value']; } -if(empty($config['dashboard_cr'])){ - $config['dashboard_cr'] = "12.7,5.12"; +if(empty($config['dashboard_Admin'])){ + $config['dashboard_Admin'] = "12.7,5.12"; } +if(empty($config['dashboard_Agent'])){ + $config['dashboard_Agent'] = "12.7,5.12"; +} + +if(empty($config['dashboard_Sales'])){ + $config['dashboard_Sales'] = "12.7,5.12"; +} + +if(empty($config['dashboard_Customer'])){ + $config['dashboard_Customer'] = "12.12"; +} + + $_c = $config; if (empty($http_proxy) && !empty($config['http_proxy'])) { $http_proxy = $config['http_proxy']; diff --git a/system/controllers/dashboard.php b/system/controllers/dashboard.php index e2555f68..18f9fb0c 100644 --- a/system/controllers/dashboard.php +++ b/system/controllers/dashboard.php @@ -36,7 +36,12 @@ $current_date = date('Y-m-d'); $ui->assign('start_date', $start_date); $ui->assign('current_date', $current_date); -$widgets = ORM::for_table('tbl_widgets')->selects("enabled", 1)->order_by_asc("orders")->findArray(); +$tipeUser = $admin['user_type']; +if (in_array($tipeUser, ['SuperAdmin', 'Admin'])) { + $tipeUser = 'Admin'; +} + +$widgets = ORM::for_table('tbl_widgets')->where("enabled", 1)->where('user', $tipeUser)->order_by_asc("orders")->findArray(); $count = count($widgets); for ($i = 0; $i < $count; $i++) { try{ diff --git a/system/controllers/widgets.php b/system/controllers/widgets.php index 995758cf..0223e01f 100644 --- a/system/controllers/widgets.php +++ b/system/controllers/widgets.php @@ -5,15 +5,23 @@ * by https://t.me/ibnux **/ _admin(); -$ui->assign('_title', Lang::T('Widgets')); +$ui->assign('_title', Lang::T('Dashboard Widgets')); $ui->assign('_system_menu', 'settings'); $action = alphanumeric($routes['1']); $ui->assign('_admin', $admin); +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + r2(getUrl('dashboard'), 'e', Lang::T('You do not have permission to access this page')); +} +$tipeUser = _req("user"); +if (empty($tipeUser)) { + $tipeUser = 'Admin'; +} +$ui->assign('tipeUser', $tipeUser); $max = ORM::for_table('tbl_widgets')->max('position'); -$max2 = substr_count($config['dashboard_cr'], '.')+substr_count($config['dashboard_cr'], ',')+1; -if($max2>$max){ +$max2 = substr_count($config['dashboard_' . $tipeUser], '.') + substr_count($config['dashboard_' . $tipeUser], ',') + 1; +if ($max2 > $max) { $max = $max2; } $ui->assign('max', $max); @@ -23,6 +31,7 @@ if ($action == 'add') { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $orders = alphanumeric($_POST['orders']); $position = alphanumeric($_POST['position']); + $tipeUser = alphanumeric($_POST['tipeUser']); $enabled = alphanumeric($_POST['enabled']); $title = _post('title'); $widget = _post('widget'); @@ -30,13 +39,14 @@ if ($action == 'add') { $d = ORM::for_table('tbl_widgets')->create(); $d->orders = $orders; $d->position = $position; + $d->user = $tipeUser; $d->enabled = $enabled; $d->title = $title; $d->widget = $widget; $d->content = $content; $d->save(); if ($d->id() > 0) { - r2(getUrl('widgets'), 's', 'Widget Added Successfully'); + r2(getUrl('widgets&user=' . $tipeUser), 's', 'Widget Added Successfully'); } } $files = scandir($WIDGET_PATH); @@ -48,6 +58,7 @@ if ($action == 'add') { } } $widget['position'] = $pos; + $ui->assign('users', ORM::for_table('tbl_widgets')->getEnum("user")); $ui->assign('do', 'add'); $ui->assign('widgets', $widgets); $ui->assign('widget', $widget); @@ -58,6 +69,7 @@ if ($action == 'add') { $id = alphanumeric($_POST['id']); $orders = alphanumeric($_POST['orders']); $position = alphanumeric($_POST['position']); + $tipeUser = alphanumeric($_POST['tipeUser']); $enabled = alphanumeric($_POST['enabled']); $title = _post('title'); $widget = _post('widget'); @@ -66,12 +78,13 @@ if ($action == 'add') { $d = ORM::for_table('tbl_widgets')->find_one($id); $d->orders = $orders; $d->position = $position; + $d->user = $tipeUser; $d->enabled = $enabled; $d->title = $title; $d->widget = $widget; $d->content = $content; $d->save(); - r2(getUrl('widgets'), 's', 'Widget Saved Successfully'); + r2(getUrl('widgets&user=' . $tipeUser), 's', 'Widget Saved Successfully'); } $id = alphanumeric($routes['2']); $widget = ORM::for_table('tbl_widgets')->find_one($id); @@ -83,6 +96,7 @@ if ($action == 'add') { $widgets[str_replace('.php', '', $file)] = $name; } } + $ui->assign('users', ORM::for_table('tbl_widgets')->getEnum("user")); $ui->assign('do', 'edit'); $ui->assign('widgets', $widgets); $ui->assign('widget', $widget); @@ -92,9 +106,9 @@ if ($action == 'add') { $d = ORM::for_table('tbl_widgets')->find_one($id); if ($d) { $d->delete(); - r2(getUrl('widgets'), 's', 'Widget Deleted Successfully'); + r2(getUrl('widgets&user=' . $tipeUser), 's', 'Widget Deleted Successfully'); } - r2(getUrl('widgets'), 'e', 'Widget Not Found'); + r2(getUrl('widgets&user=' . $tipeUser), 'e', 'Widget Not Found'); } else if (!empty($action) && file_exists("system/widget/$action.php") && !empty($routes['2'])) { require_once "system/widget/$action.php"; try { @@ -109,22 +123,22 @@ if ($action == 'add') { $d->orders = $_POST['orders'][$i]; $d->save(); } - r2(getUrl('widgets'), 's', 'Widget order Saved Successfully'); + r2(getUrl('widgets&user=' . $tipeUser), 's', 'Widget order Saved Successfully'); } else { - if(_post("save") == 'struct'){ - $d = ORM::for_table('tbl_appconfig')->where('setting', 'dashboard_cr')->find_one(); + if (_post("save") == 'struct') { + $d = ORM::for_table('tbl_appconfig')->where('setting', 'dashboard_' . $tipeUser)->find_one(); if ($d) { - $d->value = _post('dashboard_cr'); + $d->value = _post('dashboard'); $d->save(); } else { $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'dashboard_cr'; - $d->value = _post('dashboard_cr'); + $d->setting = 'dashboard_' . $tipeUser; + $d->value = _post('dashboard'); $d->save(); } - _alert("Dashboard Structure Saved Successfully", "success", getUrl('widgets')); + _alert("Dashboard Structure Saved Successfully", "success", getUrl('widgets&user=' . $tipeUser)); } - $widgets = ORM::for_table('tbl_widgets')->selects("position", 1)->order_by_asc("orders")->find_many(); + $widgets = ORM::for_table('tbl_widgets')->where("user", $tipeUser)->order_by_asc("orders")->find_many(); $ui->assign('widgets', $widgets); $ui->display('admin/settings/widgets.tpl'); } diff --git a/system/lan/english.json b/system/lan/english.json index c97c3cf5..fe83458e 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -1052,5 +1052,7 @@ "Failed_to_send_the_message__Please_try_again_": "Failed to send the message. Please try again.", "Dashboard_Structure": "Dashboard Structure", "Read_documentation": "Read documentation", - "Structure": "Structure" + "Structure": "Structure", + "Dashboard_Widgets": "Dashboard Widgets", + "User": "User" } \ No newline at end of file diff --git a/ui/ui/admin/settings/widgets.tpl b/ui/ui/admin/settings/widgets.tpl index 724e2e48..477c39c3 100644 --- a/ui/ui/admin/settings/widgets.tpl +++ b/ui/ui/admin/settings/widgets.tpl @@ -1,10 +1,17 @@ {include file="sections/header.tpl"} - - -
- + +
{function showWidget pos=0} -
+
{Lang::T("Area Fields")} {$pos}
@@ -44,7 +51,7 @@
- {Lang::T("Add new widget")} + {Lang::T("Add new widget")}
@@ -80,14 +87,16 @@ {/foreach}
diff --git a/ui/ui/admin/settings/widgets_add_edit.tpl b/ui/ui/admin/settings/widgets_add_edit.tpl index 82484df4..88683740 100644 --- a/ui/ui/admin/settings/widgets_add_edit.tpl +++ b/ui/ui/admin/settings/widgets_add_edit.tpl @@ -49,6 +49,19 @@

 

+
+ +
+ +
+

 

+