function plugin_init_reports()
{
    global $PLUGIN_HOOKS, $DB, $LANG;
    $PLUGIN_HOOKS['csrf_compliant']['reports'] = true;
    $plugin = new plugin();
    //Define only for bookmarks
    Plugin::registerClass('PluginReportsReport');
    Plugin::registerClass('PluginReportsStat');
    Plugin::registerClass('PluginReportsProfile', array('addtabon' => array('Profile')));
    if (Session::haveRight("config", UPDATE)) {
        $PLUGIN_HOOKS['config_page']['reports'] = 'front/config.form.php';
    }
    $PLUGIN_HOOKS['menu_entry']['reports'] = false;
    $PLUGIN_HOOKS['item_clone']['reports'] = array('Profile' => array('PluginReportsProfile', 'cloneProfile'));
    $rightreport = array();
    $rightstats = array();
    foreach (searchReport() as $report => $plug) {
        $field = 'plugin_reports_' . $report;
        if ($plug != 'reports') {
            $field = 'plugin_reports_' . $plug . "_" . $report;
        }
        if (Session::haveRight($field, READ)) {
            $tmp = $LANG["plugin_{$plug}"][$report];
            //If the report's name contains 'stat' then display it in the statistics page
            //(instead of Report page)
            if (isStat($report)) {
                if (!isset($PLUGIN_HOOKS['stats'][$plug])) {
                    $PLUGIN_HOOKS['stats'][$plug] = array();
                }
                $PLUGIN_HOOKS['stats'][$plug]["report/{$report}/{$report}.php"] = $tmp;
            } else {
                if (!isset($PLUGIN_HOOKS['reports'][$plug])) {
                    $PLUGIN_HOOKS['reports'][$plug] = array();
                }
                $PLUGIN_HOOKS['reports'][$plug]["report/{$report}/{$report}.php"] = $tmp;
            }
        }
    }
}
 /**
  * @param $report
  **/
 static function showForReport($report)
 {
     global $DB;
     /* call from front/config.form.php
      * $report = "bar" (from reports) or "foo_bar" (other plugins)
      */
     if (empty($report) || !Session::haveRight('profile', READ)) {
         return false;
     }
     $current = self::getAllProfilesRights(array("name = 'plugin_reports_{$report}'"));
     $canedit = Session::haveRight('profile', UPDATE);
     if ($canedit) {
         echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>\n";
     }
     echo "<table class='tab_cadre'>\n";
     echo "<tr><th colspan='2'>" . __('Profils rights', 'reports') . "</th></tr>\n";
     $query = "SELECT `id`, `name`\n                FROM `glpi_profiles`\n                ORDER BY `name`";
     foreach ($DB->request($query) as $data) {
         echo "<tr class='tab_bg_1'><td>" . $data['name'] . "&nbsp: </td><td>";
         $profrights = ProfileRight::getProfileRights($data['id'], array('statistic', 'reports'));
         $canstat = isset($profrights['statistic']) && $profrights['statistic'];
         $canreport = isset($profrights['reports']) && $profrights['reports'];
         if (isStat($report) && $canstat || !isStat($report) && $canreport) {
             Profile::dropdownNoneReadWrite($data['id'], isset($current[$data['id']]) ? $current[$data['id']] : 0, 1, 1, 0);
         } else {
             // Can't access because missing right from GLPI core
             // Profile::dropdownNoneReadWrite($mod,'',1,0,0);
             echo "<input type='hidden' name='" . $data['id'] . "' value='NULL'>" . __('No access') . " *";
         }
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_4'><td colspan='2'>* ";
     if (isStat($report)) {
         _e('No right on Assistance / Statistics', 'reports');
     } else {
         _e('No right on Tools / Reports', 'reports');
     }
     echo "</tr>";
     if ($canedit) {
         echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
         echo "<input type='hidden' name='report' value='{$report}'>";
         echo "<input type='submit' name='update' value='" . _sx('button', 'Update') . "' " . "class='submit'>";
         echo "</td></tr>\n";
         echo "</table>\n";
         Html::closeForm();
     } else {
         echo "</table>\n";
     }
 }
Exemplo n.º 3
0
 /**
  * @param $report
  **/
 static function showForReport($report)
 {
     global $DB;
     if (empty($report) || !Session::haveRight('profile', 'r')) {
         return false;
     }
     $current = self::getAllRights(array('report' => $report), true);
     $canedit = Session::haveRight('profile', 'w');
     if ($canedit) {
         echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>\n";
     }
     echo "<table class='tab_cadre'>\n";
     echo "<tr><th colspan='2'>" . __('Profils rights', 'reports') . "</th></tr>\n";
     $query = "SELECT `id`, `name`, `statistic`, `reports`\n                FROM `glpi_profiles`\n                ORDER BY `name`";
     foreach ($DB->request($query) as $data) {
         echo "<tr class='tab_bg_1'><td>" . $data['name'] . "&nbsp: </td><td>";
         if (isStat($report) && $data['statistic'] == 1 || !isStat($report) && $data['reports'] == 'r') {
             Profile::dropdownNoneReadWrite($data['id'], isset($current[$data['id']]) ? 'r' : '', 1, 1, 0);
         } else {
             // Can't access because missing right from GLPI core
             // Profile::dropdownNoneReadWrite($mod,'',1,0,0);
             echo "<input type='hidden' name='" . $data['id'] . "' value='NULL'>" . __('No access') . " *";
         }
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_4'><td colspan='2'>* ";
     if (isStat($report)) {
         _e('No right on Assistance / Statistics', 'reports');
     } else {
         _e('No right on Tools / Reports', 'reports');
     }
     echo "</tr>";
     if ($canedit) {
         echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
         echo "<input type='hidden' name='report' value='{$report}'>";
         echo "<input type='submit' name='update' value='" . _sx('button', 'Update') . "' " . "class='submit'>&nbsp;&nbsp;&nbsp;";
         echo "<input type='submit' name='delete' value='" . _sx('button', 'Delete permanently') . "'\n                class='submit'>";
         echo "</td></tr>\n";
         echo "</table>\n";
         Html::closeForm();
     } else {
         echo "</table>\n";
     }
 }
Exemplo n.º 4
0
echo __('Rights management by report', 'reports') . "</th></tr>\n";
echo "<tr class='tab_bg_1'><td>" . __('Report', 'Reports', 1) . "&nbsp; ";
$query = "SELECT `id`, `name`\n          FROM `glpi_profiles`\n          ORDER BY `name`";
$result = $DB->query($query);
echo "<select name='report'>";
$plugname = array();
$rap = array();
foreach ($tab as $key => $plug) {
    $mod = $plug == 'reports' ? $key : $plug . '_' . $key;
    if (!isset($plugname[$plug])) {
        // Retrieve the plugin name
        $function = "plugin_version_{$plug}";
        $tmp = $function();
        $plugname[$plug] = $tmp['name'];
    }
    $section = isStat($mod) ? sprintf(__('%1$s - %2$s'), __('Assistance'), __('Statistics')) : sprintf(__('%1$s - %2$s'), __('Tools'), __('Report', 'Reports', 2));
    $rap[$plug][$section][$mod] = $LANG["plugin_{$plug}"][$key];
}
$tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
foreach ($rap as $plug => $tmp1) {
    echo '<optgroup label="' . sprintf(__('%1$s - %2$s'), __('Plugins'), $plugname[$plug]) . '">';
    foreach ($tmp1 as $section => $tmp2) {
        echo '<optgroup label="' . $tab . "&raquo;&nbsp;" . $section . '">';
        foreach ($tmp2 as $mod => $name) {
            echo "<option value='{$mod}' " . ($report == "{$mod}" ? "selected" : "") . ">{$tab}{$tab}{$name}</option>\n";
        }
        echo "</optgroup>\n";
    }
    echo "</optgroup>\n";
}
echo "</select>";
Exemplo n.º 5
0
 /**
  * Display a common search criterias form
  * @param target the form's target
  * @param params the search criterias
  */
 function displayCriteriasForm()
 {
     global $HEADER_LOADED;
     //Get criteria's values
     $this->manageCriteriasValues();
     //Display Html::header is output is HTML
     if (isset($_POST["display_type"]) && $_POST["display_type"] != Search::HTML_OUTPUT) {
         return;
     }
     if (!$HEADER_LOADED) {
         $title = $this->title;
         if ($this->subname) {
             $title = sprintf(__('%1$s - %2$s'), $title, $this->subname);
         }
         if (isStat($this->name)) {
             Html::header($title, $_SERVER['PHP_SELF'], "maintain", "stat");
             Stat::title();
         } else {
             Html::header($title, $_SERVER['PHP_SELF'], "utils", "report");
             Report::title();
         }
     }
     plugin_reports_checkRight($this->plug, $this->name, "r");
     //Display form only if there're criterias
     if (!empty($this->criterias)) {
         echo "<div class='center'>";
         echo "<form method='post' name='form' action='" . $_SERVER['PHP_SELF'] . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='6'>" . __('Search criteria', 'reports');
         //If form is validated, then display the bookmark button
         if ($this->criteriasValidated()) {
             //Add parameters to uri to be saved as bookmarks
             $_SERVER["REQUEST_URI"] = $this->buildBookmarkUrl();
             Bookmark::showSaveButton(Bookmark::URI, isStat($this->name) ? 'PluginReportsStat' : 'PluginReportsReport');
         }
         echo "</th></tr>\n";
         //Display each criteria's html selection item
         foreach ($this->criterias as $criteria) {
             $criteria->displayCriteria();
         }
         $this->closeColumn();
         echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
         echo "<input type='submit' name='find' value='" . _sx('button', 'Search') . "' class='submit'>";
         echo "</td></tr>";
         echo "</table></div>";
         Html::closeForm();
     }
 }