diff --git a/core/dashboard/app_languages.php b/core/dashboard/app_languages.php index e19e467b83..2a5b26d79a 100644 --- a/core/dashboard/app_languages.php +++ b/core/dashboard/app_languages.php @@ -2234,4 +2234,54 @@ $text['label-system_status']['zh-cn'] = "系统状况"; $text['label-system_status']['ja-jp'] = "システムステータス"; $text['label-system_status']['ko-kr'] = "시스템 상태"; +$text['button-assign']['en-us'] = "Assign"; +$text['button-assign']['en-gb'] = "Assign"; +$text['button-assign']['ar-eg'] = "تعيين"; +$text['button-assign']['de-at'] = "Zuweisen"; +$text['button-assign']['de-ch'] = "Zuweisen"; +$text['button-assign']['de-de'] = "Zuweisen"; +$text['button-assign']['el-gr'] = "Ανάθεση"; +$text['button-assign']['es-cl'] = "Asignar"; +$text['button-assign']['es-mx'] = "Asignar"; +$text['button-assign']['fr-ca'] = "Attribuer"; +$text['button-assign']['fr-fr'] = "Attribuer"; +$text['button-assign']['he-il'] = "הקצה"; +$text['button-assign']['it-it'] = "Assegna"; +$text['button-assign']['nl-nl'] = "Toewijzen"; +$text['button-assign']['pl-pl'] = "Przypisz"; +$text['button-assign']['pt-br'] = "Atribuir"; +$text['button-assign']['pt-pt'] = "Atribuir"; +$text['button-assign']['ro-ro'] = "Atribuie"; +$text['button-assign']['ru-ru'] = "Назначить"; +$text['button-assign']['sv-se'] = "Tilldela"; +$text['button-assign']['uk-ua'] = "Призначити"; +$text['button-assign']['zh-cn'] = "分配"; +$text['button-assign']['ja-jp'] = "割り当てる"; +$text['button-assign']['ko-kr'] = "할당하다"; + +$text['button-unassign']['en-us'] = "Unassign"; +$text['button-unassign']['en-gb'] = "Unassign"; +$text['button-unassign']['ar-eg'] = "إلغاء التعيين"; +$text['button-unassign']['de-at'] = "Entfernen"; +$text['button-unassign']['de-ch'] = "Entfernen"; +$text['button-unassign']['de-de'] = "Entfernen"; +$text['button-unassign']['el-gr'] = "Αφαίρεση"; +$text['button-unassign']['es-cl'] = "Desasignar"; +$text['button-unassign']['es-mx'] = "Desasignar"; +$text['button-unassign']['fr-ca'] = "Désattribuer"; +$text['button-unassign']['fr-fr'] = "Désattribuer"; +$text['button-unassign']['he-il'] = "בטל הקצאה"; +$text['button-unassign']['it-it'] = "Disassegna"; +$text['button-unassign']['nl-nl'] = "Verwijderen"; +$text['button-unassign']['pl-pl'] = "Cofnij przypisanie"; +$text['button-unassign']['pt-br'] = "Desatribuir"; +$text['button-unassign']['pt-pt'] = "Desatribuir"; +$text['button-unassign']['ro-ro'] = "Dezafectare"; +$text['button-unassign']['ru-ru'] = "Убрать назначение"; +$text['button-unassign']['sv-se'] = "Avdela"; +$text['button-unassign']['uk-ua'] = "Скасувати призначення"; +$text['button-unassign']['zh-cn'] = "取消分配"; +$text['button-unassign']['ja-jp'] = "割り当て解除"; +$text['button-unassign']['ko-kr'] = "할당 해제"; + ?> diff --git a/core/dashboard/dashboard_widget_edit.php b/core/dashboard/dashboard_widget_edit.php index 74c917fd74..3f5b2f2d71 100644 --- a/core/dashboard/dashboard_widget_edit.php +++ b/core/dashboard/dashboard_widget_edit.php @@ -209,7 +209,7 @@ //redirect the user if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) { - header('Location: dashboard_edit.php?id='.$dashboard_uuid); + header('Location: dashboard_edit.php?id='.urlencode($dashboard_uuid)); exit; } } diff --git a/core/dashboard/dashboard_widget_list.php b/core/dashboard/dashboard_widget_list.php index 685a6e1229..1bff2d9e88 100644 --- a/core/dashboard/dashboard_widget_list.php +++ b/core/dashboard/dashboard_widget_list.php @@ -43,22 +43,34 @@ $action = $_POST['action']; $dashboard_uuid = $_POST['dashboard_uuid']; $dashboard_widgets = $_POST['dashboard_widgets']; + $group_uuid = $_POST['group_uuid']; } //process the http post data by action if (!empty($action) && !empty($dashboard_widgets)) { - switch ($action) { case 'toggle': if (permission_exists('dashboard_widget_edit')) { $obj = new dashboard; - $obj->toggle_items($dashboard_widgets); + $obj->toggle_widgets($dashboard_widgets); } break; case 'delete': if (permission_exists('dashboard_widget_delete')) { $obj = new dashboard; - $obj->delete_items($dashboard_widgets); + $obj->delete_widgets($dashboard_widgets); + } + break; + case 'group_widgets_add': + if (permission_exists('dashboard_widget_edit')) { + $obj = new dashboard; + $obj->assign_widgets($dashboard_widgets, $dashboard_uuid, $group_uuid); + } + break; + case 'group_widgets_delete': + if (permission_exists('dashboard_widget_delete')) { + $obj = new dashboard; + $obj->unassign_widgets($dashboard_widgets, $dashboard_uuid, $group_uuid); } break; } @@ -107,17 +119,17 @@ $sql .= limit_offset($rows_per_page ?? null, $offset ?? null); $database = new database; $parameters['dashboard_uuid'] = $dashboard_uuid; - $widget_data = $database->select($sql, $parameters ?? null, 'all'); + $result = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); //get the list of widget uuids $widget_uuid_list = []; - foreach ($widget_data as $row) { + foreach ($result as $row) { $widget_uuid_list[] = $row['dashboard_widget_uuid']; } $widgets = []; - foreach ($widget_data as $row) { + foreach ($result as $row) { //skip child widgets unless the parent doesn't exist if (!empty($row['dashboard_widget_parent_uuid']) && in_array($row['dashboard_widget_parent_uuid'], $widget_uuid_list)) { continue; @@ -128,7 +140,7 @@ //add child widgets under parent widgets if ($row['widget_path'] == 'dashboard/parent') { - foreach ($widget_data as $child) { + foreach ($result as $child) { if ($child['dashboard_widget_parent_uuid'] == $row['dashboard_widget_uuid']) { $widgets[] = $child; } @@ -136,14 +148,42 @@ } } + //get the group list + $sql = "select group_uuid, group_name from v_groups "; + $database = new database; + $groups = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + //create token $object = new token; $token = $object->create('/core/dashboard/dashboard_widget_list.php'); //show the content + echo "
\n"; + echo "\n"; + echo "\n"; + echo "
\n"; echo "
".$text['title-widgets']."
".number_format($num_rows)."
\n"; echo "
\n"; + echo " \n"; + + if (permission_exists('dashboard_widget_add') && !empty($widgets)) { + echo button::create(['type'=>'button','label'=>$text['button-assign'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_group_widgets_add','class' => 'btn btn-default revealed','collapse'=>'hide-xs','style'=>'display: none;','onclick'=>"list_action_set('group_widgets_add'); list_form_submit('form_list');"]); + } + if (permission_exists('dashboard_widget_delete') && !empty($widgets)) { + echo button::create(['type'=>'button','label'=>$text['button-unassign'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'name'=>'btn_group_widgets_delete','class' => 'btn btn-default revealed','style'=>'display: none; margin-right: 35px;','collapse'=>'hide-xs','onclick'=>"modal_open('modal-delete-groups','btn_group_widgets_delete');"]); + } + if (permission_exists('dashboard_widget_delete') && !empty($widgets)) { + echo modal::create(['id'=>'modal-delete-groups','type'=>'unassign', 'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_group_widgets_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('group_widgets_delete'); list_form_submit('form_list');"])]); + } echo button::create(['type'=>'button','id'=>'action_bar_sub_button_back','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'collapse'=>'hide-xs','style'=>'margin-right: 15px; display: none;','link'=>'dashboard.php']); if (permission_exists('dashboard_widget_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','name'=>'btn_add','link'=>'dashboard_widget_edit.php?id='.escape($dashboard_uuid).'&widget_uuid='.escape($widget_uuid)]); @@ -157,7 +197,6 @@ if (!empty($paging_controls_mini)) { echo "".$paging_controls_mini."\n"; } - echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; @@ -169,10 +208,6 @@ echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); } - echo "
\n"; - echo "\n"; - echo "\n"; - echo "
\n"; echo "\n"; echo "\n"; diff --git a/core/dashboard/index.php b/core/dashboard/index.php index 26abc0b51f..f7fb2b8f15 100644 --- a/core/dashboard/index.php +++ b/core/dashboard/index.php @@ -196,7 +196,7 @@ //redirect the browser message::add($text['message-update']); - header("Location: /core/dashboard/".(!empty($_GET['name']) ? "?name=".$_GET['name'] : null)); + header("Location: /core/dashboard/".(!empty($_GET['name']) ? "?name=".urlencode($_GET['name']) : null)); return; } } diff --git a/core/dashboard/resources/classes/dashboard.php b/core/dashboard/resources/classes/dashboard.php index 805d0d4117..b64d79a216 100644 --- a/core/dashboard/resources/classes/dashboard.php +++ b/core/dashboard/resources/classes/dashboard.php @@ -270,7 +270,7 @@ } } - public function delete_items($records) { + public function delete_widgets($records) { //assign the variables $this->name = 'dashboard_widget'; $this->table = 'dashboard_widgets'; @@ -321,7 +321,7 @@ } } - public function toggle_items($records) { + public function toggle_widgets($records) { //assign the variables $this->name = 'dashboard_widget'; $this->table = 'dashboard_widgets'; @@ -390,4 +390,176 @@ } } + public function assign_widgets($records, $dashboard_uuid, $group_uuid) { + //assign the variables + $this->name = 'dashboard_widget'; + $this->table = 'dashboard_widgets'; + + if (permission_exists($this->name.'_add')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->location); + exit; + } + + //assign multiple records + if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) { + + //define the group_name and group_uuid + if (!empty($records) && @sizeof($records) != 0) { + $sql = "select group_name, group_uuid from v_groups "; + $sql .= "where group_uuid = :group_uuid "; + $parameters['group_uuid'] = $group_uuid; + $database = new database; + $group = $database->select($sql, $parameters, 'row'); + } + + //build the delete array + $x = 0; + foreach ($records as $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) { + //build array + $uuids[] = "'".$record['dashboard_widget_uuid']."'"; + //assign dashboard widget groups + $array[$this->name.'_groups'][$x][$this->name.'_group_uuid'] = uuid(); + $array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid; + $array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid']; + $array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid']; + //increment + $x++; + } + } + + unset($records); + + //exlude exist rows + if (!empty($array) && @sizeof($array) != 0) { + $sql = "select dashboard_uuid, ".$this->name."_uuid, "; + $sql .= "group_uuid from v_".$this->name."_groups "; + $database = new database; + $dashboard_widget_groups = $database->select($sql, null, 'all'); + $array[$this->name.'_groups'] = array_filter($array[$this->name.'_groups'], function($ar) use ($dashboard_widget_groups) { + foreach ($dashboard_widget_groups as $existing_array_item) { + if ($ar['dashboard_uuid'] == $existing_array_item['dashboard_uuid'] && $ar[$this->name.'_uuid'] == $existing_array_item[$this->name.'_uuid'] && $ar['group_uuid'] == $existing_array_item['group_uuid']) { + return false; + } + } + return true; + }); + unset($dashboard_widget_groups); + } + + //add the checked rows from group + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { + //execute save + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + //set message + message::add($text['message-add']); + } + } + } + } + + public function unassign_widgets($records, $dashboard_uuid, $group_uuid) { + //assign the variables + $this->name = 'dashboard_widget'; + $this->table = 'dashboard_widgets'; + + if (permission_exists($this->name.'_add')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->location); + exit; + } + + //assign multiple records + if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) { + + //define the group_name and group_uuid + if (!empty($records) && @sizeof($records) != 0) { + $sql = "select group_name, group_uuid from v_groups "; + $sql .= "where group_uuid = :group_uuid "; + $parameters['group_uuid'] = $group_uuid; + $database = new database; + $group = $database->select($sql, $parameters, 'row'); + } + + //build the delete array + $x = 0; + foreach ($records as $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) { + //build array + $uuids[] = "'".$record['dashboard_widget_uuid']."'"; + //assign dashboard widget groups + $array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid; + $array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid']; + $array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid']; + //increment + $x++; + } + } + + unset($records); + + //include child dashboard widgets and their dasboard_uuid too + if (!empty($uuids) && @sizeof($uuids) != 0) { + $sql = "select dashboard_uuid, ".$this->name."_uuid from v_".$this->table." "; + $sql .= "where ".$this->name."_parent_uuid in (".implode(', ', $uuids).") "; + $database = new database; + $rows = $database->select($sql, null, 'all'); + if (!empty($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + //assign dashboard widget groups + $array[$this->name.'_groups'][$x]['dashboard_uuid'] = $row['dashboard_uuid']; + $array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $row['dashboard_widget_uuid']; + $array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid']; + //increment + $x++; + } + } + } + + unset($uuids); + + //add the checked rows from group + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { + //grant temporary permissions + $p = new permissions; + $p->add('dashboard_widget_group_delete', 'temp'); + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //revoke temporary permissions + $p->delete('dashboard_widget_group_delete', 'temp'); + + //set message + message::add($text['message-delete']); + } + } + } + } + }