/**
  * Copy the reports from the tracker $from_id to the tracker $to_id
  * The copied reports must have scope == 'P'
  */
 public function copyReports($from_id, $to_id)
 {
     $user_id = UserManager::instance()->getCurrentUser()->getId();
     $dao = new GraphOnTrackers_ReportDao(CodendiDataAccess::instance());
     foreach ($dao->searchByTrackerIdAndScope($from_id, 'P') as $row) {
         //retrieve the report
         $report = new GraphOnTrackers_Report($row['report_graphic_id']);
         //Create a new one
         $copied_report = GraphOnTrackers_Report::create($to_id, $user_id, $report->getName(), $report->getDescription(), $report->getScope());
         //Copy the charts
         $this->copyCharts($report, $copied_report);
     }
 }
 /**
  *  Display detail report form
  *
  *  @return void
  */
 function showReportForm($report_graphic_id)
 {
     $hp =& Codendi_HTMLPurifier::instance();
     $group = $GLOBALS['ath']->getGroup();
     $group_id = $group->getID();
     $atid = $GLOBALS['ath']->getID();
     $gr = new GraphOnTrackers_Report($report_graphic_id);
     echo '<H2>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'tracker') . ' \'<A href="/tracker/admin/?group_id=' . $group_id . '&atid=' . $atid . '">' . $hp->purify($GLOBALS['ath']->getName()) . '</A>\' -  ' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'modify_report') . ' \'' . $hp->purify($gr->name) . '\' ';
     echo help_button('TrackerAdministration.html#GraphTrackerReportSetting') . '</H2>';
     echo '<p><a href="/tracker/admin/?func=reportgraphic&amp;group_id=' . (int) $group_id . '&amp;atid=' . (int) $atid . '">&laquo; ' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'return_reports') . '</a></p>';
     echo '<FORM NAME="show_rep_graphic" ACTION="/tracker/admin/" METHOD="POST">
           <INPUT TYPE="HIDDEN" NAME="func" VALUE="reportgraphic">
           <INPUT TYPE="HIDDEN" NAME="update_report_graphic" VALUE="y">
           <INPUT TYPE="HIDDEN" NAME="atid" VALUE="' . $hp->purify($atid) . '">
           <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="' . $hp->purify($group_id) . '">
           <INPUT TYPE="HIDDEN" NAME="report_graphic_id" VALUE="' . $hp->purify($gr->getId()) . '">
           <INPUT TYPE="HIDDEN" NAME="post_changes_graphic" VALUE="y">
           <table><tr valign="top"><td>
           <B>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'name') . ': </B>
           </td><td>
           <INPUT TYPE="TEXT" NAME="rep_name" VALUE="' . $hp->purify($gr->getName()) . '" SIZE="20" MAXLENGTH="20">
           &nbsp;&nbsp;&nbsp;&nbsp;
           <B>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'scope') . ': </B>';
     if ($GLOBALS['ath']->userIsAdmin()) {
         echo '<SELECT NAME="rep_scope">
               <OPTION VALUE="I"' . ($gr->getScope() == 'I' ? 'SELECTED' : '') . '>' . $GLOBALS['Language']->getText('global', 'Personal') . '</OPTION>
               <OPTION VALUE="P"' . ($gr->getScope() == 'P' ? 'SELECTED' : '') . '>' . $GLOBALS['Language']->getText('global', 'Project') . '</OPTION>
               </SELECT>';
     } else {
         echo $gr->getScope() == 'P' ? $GLOBALS['Language']->getText('global', 'Project') : $GLOBALS['Language']->getText('global', 'Personal');
     }
     echo '</td><td rowspan="2"  valign="middle"><input type="submit" name="update_report" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" /></td></tr>
           <tr valign="top"><td><B>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'desc') . ':</B></td><td>
           <INPUT TYPE="TEXT" NAME="rep_desc" VALUE="' . $hp->purify($gr->getDescription()) . '" class="textfield_medium" />
           </td></tr></table>';
     echo '<hr /><p><strong>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'add_chart') . '</strong> ';
     $url = '/tracker/admin/?func=reportgraphic&amp;group_id=' . (int) $group_id . '&amp;atid=' . (int) $atid . '&amp;report_graphic_id=' . (int) $gr->getId();
     $url_add = $url . '&amp;add_chart=';
     foreach ($gr->getChartFactories() as $factory) {
         echo '<a href="' . $url_add . $factory['chart_type'] . '"  style="border:1px solid #ccc; margin:10px; padding:5px 10px; vertical-align:middle">';
         echo '<img style="vertical-align:middle; " src="' . $factory['icon'] . '" /> ';
         echo '<label style="margin-left:4px;">' . $factory['title'] . '</label>';
         echo '</a>';
     }
     echo '</p>';
     foreach ($gr->getCharts() as $chart) {
         echo '<div style="float:left; padding:10px; text-align:right;">';
         echo '<a title="' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'tooltip_edit') . '" href="' . $url . '&amp;edit_chart=' . $chart->getId() . '"><img src="' . util_get_dir_image_theme() . 'ic/edit.png" alt="edit" /></a>';
         echo '<input title="' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'tooltip_del') . '" type="image" src="' . util_get_dir_image_theme() . 'ic/cross.png" onclick="return confirm(' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'confirm_del') . ');" name="delete_chart[' . $chart->getId() . ']" />';
         $chart->display();
         echo '</div>';
     }
     echo '<div style="clear:both;"></div>';
     '</FORM>';
 }
Example #3
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;
         }
     }
 }
    /**
     *  Display detail report form
     *
     *  @return void
     */
    function showReportForm($report_graphic_id)
    {
        $hp =& Codendi_HTMLPurifier::instance();
        $group = $GLOBALS['ath']->getGroup();
        $group_id = $group->getID();
        $atid = $GLOBALS['ath']->getID();
        $gr = new GraphOnTrackers_Report($report_graphic_id);
        echo '<H2>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'tracker') . ' \'<A href="/tracker/admin/?group_id=' . $group_id . '&atid=' . $atid . '">' . $hp->purify($GLOBALS['ath']->getName()) . '</A>\' -  ' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'modify_report') . ' \'' . $hp->purify($gr->name) . '\' ';
        echo help_button('tracker-v3.html#tracker-graphical-report-setting') . '</H2>';
        echo '<p><a href="/tracker/admin/?func=reportgraphic&amp;group_id=' . (int) $group_id . '&amp;atid=' . (int) $atid . '">&laquo; ' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'return_reports') . '</a></p>';
        echo '<form name="show_rep_graphic" action="/tracker/admin/" method="post" class="form-inline">
              <input type="hidden" name="func" value="reportgraphic">
              <input type="hidden" name="update_report_graphic" value="y">
              <input type="hidden" name="atid" value="' . $hp->purify($atid) . '">
              <input type="hidden" name="group_id" value="' . $hp->purify($group_id) . '">
              <input type="hidden" name="report_graphic_id" value="' . $hp->purify($gr->getId()) . '">
              <input type="hidden" name="post_changes_graphic" value="y">

              <label>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'name') . ': </label>
              <input type="text" name="rep_name" value="' . $hp->purify($gr->getName()) . '" maxlength="20" class="input-small">

              <label>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'desc') . ':</label>
              <input type="text" name="rep_desc" value="' . $hp->purify($gr->getDescription()) . '" class="input-xlarge" />

              <label>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'scope') . ': </label>';
        if ($GLOBALS['ath']->userIsAdmin()) {
            echo '<select name="rep_scope">
                  <option value="i"' . ($gr->getScope() == 'I' ? 'selected="selected"' : '') . '>' . $GLOBALS['Language']->getText('global', 'Personal') . '</option>
                  <option value="p"' . ($gr->getScope() == 'P' ? 'selected="selected"' : '') . '>' . $GLOBALS['Language']->getText('global', 'Project') . '</option>
                  </select>';
        } else {
            echo $gr->getScope() == 'P' ? $GLOBALS['Language']->getText('global', 'Project') : $GLOBALS['Language']->getText('global', 'Personal');
        }
        echo '<input type="submit" name="update_report" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" class="btn"/>';
        echo '<hr /><p><strong>' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'add_chart') . '</strong> ';
        $url = '/tracker/admin/?func=reportgraphic&amp;group_id=' . (int) $group_id . '&amp;atid=' . (int) $atid . '&amp;report_graphic_id=' . (int) $gr->getId();
        $url_add = $url . '&amp;add_chart=';
        foreach ($gr->getChartFactories() as $factory) {
            $js = 'location.href=\'' . $url_add . $factory['chart_type'] . '\'';
            $on_click = 'onClick="' . $js . ';"';
            echo '<button type="button" class="btn graphontrackers_add_btn" ' . $on_click . ' style="background-image: url(\'' . $factory['icon'] . '\');">' . $factory['title'] . '</button> ';
        }
        echo '</p>';
        foreach ($gr->getCharts() as $chart) {
            echo '<div style="float:left; padding:10px; text-align:right;">';
            echo '<a title="' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'tooltip_edit') . '" href="' . $url . '&amp;edit_chart=' . $chart->getId() . '"><img src="' . util_get_dir_image_theme() . 'ic/edit.png" alt="edit" /></a>';
            echo '<input title="' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'tooltip_del') . '" type="image" src="' . util_get_dir_image_theme() . 'ic/cross.png" onclick="return confirm(' . $GLOBALS['Language']->getText('plugin_graphontrackers_include_report', 'confirm_del') . ');" name="delete_chart[' . $chart->getId() . ']" />';
            $chart->display();
            echo '</div>';
        }
        echo '<div style="clear:both;"></div>
        </form>';
    }