} } } } else { $skip_next = false; } } } else { // In this case the user has used the drag and drop functionnality $array_of_weights = explode(",", $drag_order); $graphs_in_dashboard = array(); foreach ($array_of_weights as $new_weight) { $expl = explode(":", $new_weight); $current_graph = new Graph($expl[0]); if (!isset($dashboard_id)) { $dashboard_id = $current_graph->getDashboardId(); } else { // Check if all the graphs are in the same dashboard if ($dashboard_id != $current_graph->getDashboardId()) { $error = true; break; } } $current_graph->setWeight($expl[1]); $graphs_in_dashboard[] = $current_graph; } } if (!$error) { foreach ($graphs_in_dashboard as $graph_to_store) { $graph_to_store->store(); }
<?php include dirname(__FILE__) . '/inc/init.php'; fAuthorization::requireLoggedIn(); fRequest::overrideAction(); $action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete', 'view')); $dashboard_id = fRequest::get('dashboard_id'); $graph_id = fRequest::get('graph_id'); $manage_url = $_SERVER['SCRIPT_NAME']; // --------------------------------- // if ('edit' == $action) { try { $graph = new Graph($graph_id); $dashboard = new Dashboard($graph->getDashboardId()); $lines = Line::findAll($graph_id); if (fRequest::isPost()) { $graph->populate(); fRequest::validateCSRFToken(fRequest::get('token')); $graph->store(); fMessaging::create('affected', fURL::get(), $graph->getName()); fMessaging::create('success', fURL::getWithQueryString(), 'The Graph ' . $graph->getName() . ' was successfully updated'); //fURL::redirect($manage_url); } } catch (fNotFoundException $e) { fMessaging::create('error', $manage_url, 'The Graph requested, ' . fHTML::encode($graph_id) . ', could not be found'); fURL::redirect($manage_url); } catch (fExpectedException $e) { fMessaging::create('error', fURL::get(), $e->getMessage()); } include VIEW_PATH . '/add_edit_graph.php'; // --------------------------------- //
$graph->populate(); fRequest::validateCSRFToken(fRequest::get('token')); $graph->store(); fMessaging::create('affected', $manage_url, $graph->getName()); fMessaging::create('success', $manage_url, 'The Graph ' . $graph->getName() . ' was successfully created'); fURL::redirect(Graph::makeUrl('edit', $graph)); } catch (fExpectedException $e) { fMessaging::create('error', fURL::get(), $e->getMessage()); } } include VIEW_PATH . '/add_edit_graph.php'; } elseif ('delete' == $action) { $class_name = 'Graph'; try { $obj = new Graph($graph_id); $dashboard = new Dashboard($obj->getDashboardId()); $delete_text = 'Are you sure you want to delete the graph : <strong>' . $obj->getName() . '</strong>?'; if (fRequest::isPost()) { fRequest::validateCSRFToken(fRequest::get('token')); $obj->delete(); $lines = Line::findAll($graph_id); foreach ($lines as $line) { $line->delete(); } fMessaging::create('success', Dashboard::makeUrl('edit', $dashboard), 'The graph for ' . $dashboard->getName() . ' was successfully deleted'); fURL::redirect(Dashboard::makeUrl('edit', $dashboard)); } } catch (fNotFoundException $e) { fMessaging::create('error', Dashboard::makeUrl('edit', $dashboard), 'The line requested could not be found'); fURL::redirect(Dashboard::makeUrl('edit', $dashboard)); } catch (fExpectedException $e) {
public static function cloneGraph($graph_id, $dashboard_id = NULL) { $graph_to_clone = new Graph($graph_id); if (empty($dashboard_id)) { $dashboard_id = $graph_to_clone->getDashboardId(); } $graph = new Graph(); $clone_name = 'Clone of ' . $graph_to_clone->getName(); // If it's too long, we truncate if (strlen($clone_name) > 255) { $clone_name = substr($clone_name, 0, 255); } $graph->setName($clone_name); $graph->setArea($graph_to_clone->getArea()); $graph->setVtitle($graph_to_clone->getVtitle()); $graph->setDescription($graph_to_clone->getDescription()); $graph->setDashboardId($dashboard_id); $graph->setWeight($graph_to_clone->getWeight()); $graph->setTimeValue($graph_to_clone->getTimeValue()); $graph->setUnit($graph_to_clone->getUnit()); $graph->setCustomOpts($graph_to_clone->getCustomOpts()); $graph->setStartsAtMidnight($graph_to_clone->getStartsAtMidnight()); $graph->store(); // Clone of the lines $lines = Line::findAll($graph_id); foreach ($lines as $line_to_clone) { Line::cloneLine($line_to_clone->getLineId(), TRUE, $graph->getGraphId()); } }