Exemplo n.º 1
0
 /**
  *  Hook to admin graphic reports
  *  Used in www/tracker/admin/index.php
  * 
  * @param params:hook parameters
  */
 function tracker_graphic_report_admin($params)
 {
     $request = HTTPRequest::instance();
     if ($request->valid(new Valid_WhiteList('func', array('reportgraphic'))) && $request->valid(new Valid_UInt('atid'))) {
         $func = $request->get('func');
         $atid = $request->get('atid');
         if ($func == 'reportgraphic') {
             require_once 'html-generators/GraphicEngineHtml.class.php';
             require_once 'data-access/GraphOnTrackers_Report.class.php';
             if (!user_isloggedin()) {
                 exit_not_logged_in();
                 return;
             }
             $user_id = UserManager::instance()->getCurrentUser()->getId();
             $geh = new graphicEngineHtml($atid, $user_id, $this->getThemePath());
             if ($request->exist('create_report_graphic') && $request->get('rep_name')) {
                 if ($GLOBALS['ath']->userIsAdmin() && $request->valid(new Valid_WhiteList('rep_scope', array('P', 'I')))) {
                     $rep_scope = $request->get('rep_scope');
                 } else {
                     $rep_scope = 'I';
                 }
                 if ($report = GraphOnTrackers_Report::create($atid, $user_id, $request->get('rep_name'), $request->get('rep_desc'), $rep_scope)) {
                     $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'new_created_report'));
                     $GLOBALS['Response']->redirect('/tracker/admin/?func=reportgraphic&group_id=' . $report->getGroupId() . '&atid=' . $report->getAtid() . '&report_graphic_id=' . $report->getId());
                 }
             } else {
                 $report_graphic_id = $request->getValidated('report_graphic_id', 'uint', 0);
                 $gr = new GraphOnTrackers_Report($report_graphic_id);
                 if ($gr->getScope() != 'P' || $GLOBALS['ath']->userIsAdmin()) {
                     if ($request->exist('update_report')) {
                         if ($request->valid(new Valid_String('rep_name')) && $request->valid(new Valid_String('rep_desc')) && $request->valid(new Valid_WhiteList('rep_scope', array('I', 'P')))) {
                             $rep_name = $request->get('rep_name');
                             $rep_desc = $request->get('rep_desc');
                             $rep_scope = $request->get('rep_scope');
                             if ($rep_name != $gr->getName() || $rep_desc != $gr->getDescription() || $rep_scope != $gr->getScope()) {
                                 $gr->setName($rep_name);
                                 $gr->setDescription($rep_desc);
                                 $gr->setScope($rep_scope);
                                 $gr->setUserId(UserManager::instance()->getCurrentUser()->getId());
                                 if ($gr->update()) {
                                     $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'updated_report'));
                                 } else {
                                     $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'not_updated_report') . ': ' . $gr->getErrorMessage());
                                 }
                             }
                         }
                     } else {
                         if (is_array($request->get('delete_chart'))) {
                             $chart_id_to_delete = (int) key($request->get('delete_chart'));
                             $gr->deleteChart($chart_id_to_delete);
                             $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'updated_report'));
                             $GLOBALS['Response']->redirect('/tracker/admin/?func=reportgraphic&group_id=' . $gr->getGroupId() . '&atid=' . $gr->getAtid() . '&report_graphic_id=' . $gr->getId());
                         } else {
                             if ($request->exist('update_chart') && is_array($request->get('chart'))) {
                                 $row = $request->get('chart');
                                 if (isset($row['id'])) {
                                     $chart_to_edit = $gr->getChart($row['id']);
                                     if ($chart_to_edit->update($row)) {
                                         $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'updated_report'));
                                     }
                                 }
                             } else {
                                 if ($request->exist('edit_chart')) {
                                     $chart_to_edit = $gr->getChart((int) $request->get('edit_chart'));
                                 } else {
                                     if ($request->exist('add_chart')) {
                                         if ($chart = $gr->createChart($request->get('add_chart'))) {
                                             $GLOBALS['Response']->redirect('/tracker/admin/?func=reportgraphic&group_id=' . $gr->getGroupId() . '&atid=' . $gr->getAtid() . '&report_graphic_id=' . $gr->getId() . '&edit_chart=' . (int) $chart->getId());
                                         }
                                     } else {
                                         if ($request->exist('delete_report_graphic')) {
                                             $gr->delete();
                                             $report_graphic_id = null;
                                             $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'report_deleted'));
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $GLOBALS['ath']->adminHeader(array('title' => $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'report_mgmt'), 'help' => 'TrackerAdministration.html#GraphTrackerReportSetting'));
             if ($request->exist('new_report_graphic')) {
                 $geh->createReportForm();
             } else {
                 if ($report_graphic_id) {
                     if (isset($chart_to_edit)) {
                         $geh->showChartForm($chart_to_edit);
                     } else {
                         $geh->showReportForm($report_graphic_id);
                     }
                 } else {
                     // Front page
                     $reports = $geh->grf->getReportsAvailable($atid, user_getid());
                     $geh->showAvailableReports($reports);
                 }
             }
             $GLOBALS['ath']->footer(null);
             exit;
         }
     }
 }