mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Dashboard Edit: Add widget group assign/unassign feature (#7489)
* Dashboard Edit: Add widget group assign/unassign feature * Update dashboard.php * Update app_languages.php * Update index.php * Update dashboard_widget_edit.php * Update dashboard_widget_list.php * Update dashboard.php
This commit is contained in:
@@ -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'] = "할당 해제";
|
||||
|
||||
?>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 "<form id='form_list' method='post' action='dashboard_widget_list.php'>\n";
|
||||
echo "<input type='hidden' id='action' name='action' value=''>\n";
|
||||
echo "<input type='hidden' name='dashboard_uuid' value='".escape($dashboard_uuid)."'>\n";
|
||||
|
||||
echo "<div class='action_bar' id='action_bar_sub'>\n";
|
||||
echo " <div class='heading'><b>".$text['title-widgets']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
|
||||
echo " <div class='actions'>\n";
|
||||
echo " <select class='formfld revealed' id='group_uuid' name='group_uuid' style='display: none;'>\n";
|
||||
echo " <option value=''>Select Group</option>\n";
|
||||
if (!empty($groups)) {
|
||||
foreach ($groups as $row) {
|
||||
echo " <option value='".urlencode($row["group_uuid"])."'>".escape($row['group_name'])." ".escape($row['group_description'])."</option>\n";
|
||||
}
|
||||
}
|
||||
echo " </select>\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 "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
|
||||
}
|
||||
echo " </form>\n";
|
||||
echo " </div>\n";
|
||||
echo " <div style='clear: both;'></div>\n";
|
||||
echo "</div>\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 "<form id='form_list' method='post' action='dashboard_widget_list.php?'>\n";
|
||||
echo "<input type='hidden' id='action' name='action' value=''>\n";
|
||||
echo "<input type='hidden' name='dashboard_uuid' value='".escape($dashboard_uuid)."'>\n";
|
||||
|
||||
echo "<div class='card'>\n";
|
||||
echo "<table class='list'>\n";
|
||||
echo "<tr class='list-header'>\n";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user