function dashboard_plugin_actions() { global $myUser, $_, $conf; switch ($_['action']) { case 'GET_WIDGETS': header('Content-type: application/json'); require_once dirname(__FILE__) . '/Dashboard.class.php'; require_once dirname(__FILE__) . '/Widget.class.php'; $dashManager = new Dashboard(); $dashManager->change(array('default' => '0')); $dashManager->change(array('default' => '1'), array('id' => $_['dashboard'])); $widgetManager = new Widget(); $model = array(); Plugin::callHook("widgets", array(&$model)); $widgets = $widgetManager->loadAll(array('dashboard' => $_['dashboard']), 'cell'); $data = array(); foreach ($widgets as $widget) { $data[] = array('data' => $widget->data, 'column' => $widget->column, 'id' => $widget->id, 'cell' => $widget->cell, 'minified' => $widget->minified, 'model' => $widget->model); } echo json_encode(array('model' => $model, 'data' => $data)); break; case 'ADD_WIDGET': header('Content-type: application/json'); require_once dirname(__FILE__) . '/Widget.class.php'; $response = array(); $widget = new Widget(); $widget->data = json_encode($_POST['data']); $widget->column = $_['column']; $widget->cell = $_['cell']; $widget->model = $_['model']; $widget->dashboard = $_['view']; $widget->save(); $response['id'] = $widget->id; echo json_encode($response); break; case 'MINIMIZE_WIDGET': header('Content-type: application/json'); require_once dirname(__FILE__) . '/Widget.class.php'; $response = array(); $widgetManager = new Widget(); $widgetManager = $widgetManager->getById($_['id']); $widgetManager->minified = 1; $widgetManager->save(); echo json_encode($response); break; case 'MAXIMIZE_WIDGET': header('Content-type: application/json'); require_once dirname(__FILE__) . '/Widget.class.php'; $response = array(); $widgetManager = new Widget(); $widgetManager = $widgetManager->getById($_['id']); $widgetManager->minified = 0; $widgetManager->save(); echo json_encode($response); break; case 'MOVE_WIDGET': header('Content-type: application/json'); require_once dirname(__FILE__) . '/Widget.class.php'; $response = array(); $widgetManager = new Widget(); foreach ($_['sort']['cells'] as $id => $sort) { $widgetManager->change(array('cell' => $sort['cell'], 'column' => $sort['column']), array('id' => $id)); } echo json_encode($response); break; case 'DELETE_WIDGET': header('Content-type: application/json'); require_once dirname(__FILE__) . '/Widget.class.php'; $response = array(); $widgetManager = new Widget(); $widgetManager->delete(array('id' => $_['id'])); echo json_encode($response); break; case 'DASH_ADD_VIEW': global $_, $myUser; require_once dirname(__FILE__) . '/Dashboard.class.php'; $entity = new Dashboard(); $entity->user = $myUser->getId(); $entity->label = $_['viewName']; $entity->default = 0; $entity->save(); header('location: setting.php?section=preference&block=dashboard'); break; case 'DASH_DELETE_VIEW': global $_, $myUser; require_once dirname(__FILE__) . '/Dashboard.class.php'; $entity = new Dashboard(); $entity->delete(array('id' => $_['id'])); header('location: setting.php?section=preference&block=dashboard'); break; } }
$widgetId = $database->escapeString($_POST['widgetName']); $widgetName = "Widget " . $widgetId; $widget->setWidgetId($widgetId); $widget->setName($widgetName); $widget->setMenuId(0); $widget->setPostId(0); if ($widget->create($database)) { echo "true"; } else { echo "false"; } } else { if (isset($_POST['widgetIds'])) { foreach ($_POST['widgetIds'] as $widgetId) { $widget->setWidgetId($widgetId); $widget->delete($database); } echo "true"; } else { if (isset($_POST['widgetId'])) { $widgetId = $database->escapeString($_POST['widgetId']); $type = $database->escapeString($_POST['type']); $array = []; $widget->setWidgetId($widgetId); if ($type == "menu") { $menuOrPostId = $database->escapeString($_POST['menuOrPostId']); $widget->setMenuId($menuOrPostId); $widget->setPostId(0); $widget->update($database); echo "true"; } else {
public static function removeWidget() { $usr = usr::getCurrentUser(1); if (!isset($usr)) { return; } $widgetId = Core::validate(self::getVar('id')); $widget = new Widget(); $result = $widget->findBy(array('UID' => $usr->getId(), 'id' => $widgetId)); if (count($result) <= 0) { return; } $widget->setId($widgetId); $widget->delete(); header('Location: / '); }