Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions ajax/dropdownExport.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php //
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
Expand Down Expand Up @@ -59,29 +59,21 @@
"onClick='return false;' value='"._sx('button', 'Post')."' />";
Html::Closeform();
echo "<script type='text/javascript'>
Ext.get('export_svg_link').on('click', function () {
$('#export_svg_link').on('click', function () {
var svg_content = vis{$randname}.scene[0].canvas.innerHTML;
var form = document.getElementById('export_svg_form');
form.svg_content.value = svg_content;
form.submit();

//set new crsf token for svg export
Ext.Ajax.request({
url: '../ajax/get_new_crsf_token.php',
success: function(response, opts) {
var token = response.responseText;
Ext.select('#export_svg_form input[name=_glpi_csrf_token]')
.set({'value': token});
}
});

//set new crsf token for main form
Ext.Ajax.request({
$.ajax({
url: '../ajax/get_new_crsf_token.php',
type: 'POST',
dataType: 'html',
success: function(response, opts) {
var token = response.responseText;
Ext.select('#mreporting_date_selector input[name=_glpi_csrf_token]')
.set({'value': token});
var token = response;
$('#mreporting_date_selector input[name=_glpi_csrf_token]').val(token);
$('#export_svg_form input[name=_glpi_csrf_token]').val(token);
}
});

Expand All @@ -93,15 +85,16 @@
_sx('button', 'Post')."\" class='submit'>";

echo "<script type='text/javascript'>
Ext.get('export_submit').on('click', function () {
$('#export_submit').on('click', function () {
//get new crsf
Ext.Ajax.request({
$.ajax({
url: '../ajax/get_new_crsf_token.php',
type: 'POST',
dataType: 'html',
success: function(response, opts) {
var token = response.responseText;
Ext.select('#export_form input[name=_glpi_csrf_token]')
.set({'value': token});

var token = response;
$('#export_form input[name=_glpi_csrf_token]').val(token);
$('#mreporting_date_selector input[name=_glpi_csrf_token]').val(token);
}
});
});
Expand Down
59 changes: 59 additions & 0 deletions front/download.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
Mreporting plugin for GLPI
Copyright (C) 2003-2011 by the mreporting Development Team.

https://forge.indepnet.net/projects/mreporting
-------------------------------------------------------------------------

LICENSE

This file is part of mreporting.

mreporting is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

mreporting is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with mreporting. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

$USEDBREPLICATE = 1;
$DBCONNECTION_REQUIRED = 0; // Not really a big SQL request

include ("../../../inc/includes.php");

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

if (isset($_GET['id'])){
$notificationTarget = new PluginMreportingNotificationTargetNotification();
$file = $notificationTarget->getFileDir()."/".$notificationTarget->getFileName($_GET['id']);

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}

exit;

2 changes: 1 addition & 1 deletion front/export_svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
header("Content-disposition: attachment; filename=export.svg");
header("Content-type: image/svg+xml");

echo $_REQUEST['svg_content'];
echo stripslashes(htmlspecialchars_decode($_REQUEST['svg_content']));

26 changes: 18 additions & 8 deletions front/profile.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,28 @@

} else if (isset($_REQUEST['giveReadAccessForAllReport'])){
foreach($res as $report) {
$profil->getFromDBByQuery("WHERE profiles_id = ".$_REQUEST['profile_id'].
" AND reports = ".$report['id']);
$profil->fields['right'] = READ;
$profil->update($profil->fields);
if ($profil->getFromDBByQuery(" WHERE profiles_id = ".$_REQUEST['profile_id'].
" AND reports = ".$report['id'])) {
$profil->fields['right'] = READ;
$profil->update($profil->fields);
} else {
$profil->add(array('profiles_id' => $_REQUEST['profile_id'],
'reports' => $report['id'],
'right' => READ));
}
}

} else if (isset($_REQUEST['giveNoneAccessForAllReport'])){
foreach($res as $report) {
$profil->getFromDBByQuery("WHERE profiles_id = ".$_REQUEST['profile_id'].
" AND reports = ".$report['id']);
$profil->fields['right'] = 'NULL';
$profil->update($profil->fields);
if ($profil->getFromDBByQuery(" WHERE profiles_id = ".$_REQUEST['profile_id'].
" AND reports = ".$report['id'])) {
$profil->fields['right'] = 'NULL';
$profil->update($profil->fields);
} else {
$profil->add(array('profiles_id' => $_REQUEST['profile_id'],
'reports' => $report['id'],
'right' => 'NULL'));
}
}

} else if (isset($_REQUEST['giveNoneAccessForAllProfile'])){
Expand Down
24 changes: 16 additions & 8 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,16 @@ function plugin_mreporting_install() {
$migration->migrationOneTable('glpi_plugin_mreporting_configs');

// == Update to 2.3 ==
$right = array();
if (!fieldExists('glpi_plugin_mreporting_profiles', 'right')
&& fieldExists('glpi_plugin_mreporting_profiles', 'reports')) {
//save all profile with right READ
$right = PluginMreportingProfile::getRight();

//truncate profile table
// truncate profile table
$query = "TRUNCATE TABLE `glpi_plugin_mreporting_profiles`";
$DB->query($query);

//migration of field
$migration->addField('glpi_plugin_mreporting_profiles', 'right', 'char');
$migration->addField('glpi_plugin_mreporting_profiles', 'right', 'integer');
$migration->changeField('glpi_plugin_mreporting_profiles', 'reports',
'reports','integer');
$migration->changeField('glpi_plugin_mreporting_profiles', 'profiles_id',
Expand All @@ -156,7 +155,7 @@ function plugin_mreporting_install() {
}

// == UPDATE to 0.84+1.0 ==
$query = "UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ".READ." WHERE pr.right = 'r'";
$query = "UPDATE `glpi_plugin_mreporting_profiles` SET `right` = '".READ."' WHERE `right` = 'r'";
$DB->query($query);
if (!isIndex('glpi_plugin_mreporting_profiles', 'profiles_id_reports')) {
$query = "ALTER IGNORE TABLE glpi_plugin_mreporting_profiles
Expand All @@ -179,15 +178,22 @@ function plugin_mreporting_install() {

$migration->addField("glpi_plugin_mreporting_preferences", "selectors", "text");
$migration->migrationOneTable('glpi_plugin_mreporting_preferences');

// == Init available reports
require_once "inc/baseclass.class.php";
require_once "inc/common.class.php";
require_once "inc/config.class.php";
$config = new PluginMreportingConfig();
$config->createFirstConfig();
if (!countElementsInTable("glpi_plugin_mreporting_configs")) {
$config->createFirstConfig();
}

if (!empty($right)) {
PluginMreportingProfile::addRightToProfiles($right);
$query = "UPDATE `glpi_plugin_mreporting_profiles` SET `right` = '".READ."'";
$DB->query($query);
}

PluginMreportingProfile::addRightToProfiles($right);
return true;
}

Expand Down Expand Up @@ -220,6 +226,8 @@ function plugin_mreporting_uninstall() {

require_once "inc/notification.class.php";
PluginMreportingNotification::uninstall();

CronTask::Unregister('MreportingNotification');

return true;
}
Expand Down
12 changes: 7 additions & 5 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,15 @@ function showExportForm($opt) {
echo "</div>";

echo "<script type='text/javascript'>
Ext.get('export_submit').on('click', function () {
$('#export_submit').on('click', function () {
//get new crsf
Ext.Ajax.request({
$.ajax({
url: '../ajax/get_new_crsf_token.php',
type: 'POST',
dataType: 'html',
success: function(response, opts) {
var token = response.responseText;
Ext.select('#exportform input[name=_glpi_csrf_token]').set({'value': token});
var token = response;
$('#exportform input[name=_glpi_csrf_token]').val(token);
document.getElementById('exportform').submit();
}
});
Expand Down Expand Up @@ -1633,7 +1635,7 @@ static function showSelector($date1, $date2, $randname) {
}
$_SERVER['REQUEST_URI'] .= "&date1".$randname."=".$date1;
$_SERVER['REQUEST_URI'] .= "&date2".$randname."=".$date2;
Bookmark::showSaveButton(Bookmark::URI);
Bookmark::showSaveButton(Bookmark::URI, self::getType());

//If there's no selector for the report, there's no need for a reset button !
if ($has_selector) {
Expand Down
10 changes: 10 additions & 0 deletions inc/download.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class PluginMreportingDownload extends CommonDBTM {

public function __construct() {
$this->forceTable("glpi_plugin_mreporting_configs");
parent::__construct();
}

}
2 changes: 1 addition & 1 deletion inc/graphpng.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function showImage($contents, $export="png") {
$show_inline = false;
$rand=mt_rand();
$filename = "mreporting_img_$rand.png";
$filedir = GLPI_ROOT."/files/_plugins/mreporting/$filename";
$filedir = GLPI_PLUGIN_DOC_DIR."/mreporting/$filename";
file_put_contents($filedir, $contents);

echo "<img src='".$CFG_GLPI['root_doc'].
Expand Down
2 changes: 1 addition & 1 deletion inc/helpdeskplus.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public function reportHgbarRespectedSlasByTopCategory($config = array()) {
AND t.is_deleted = '0'";
if ($category) {
$query .= " AND c.id = " . $category;
} else {
} elseif (!empty($categories)) {
$query .= " AND c.id IN (" . implode(',', $categories) . ")";
}
$query .= " GROUP BY respected_sla, c.id
Expand Down
14 changes: 8 additions & 6 deletions inc/notification.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ static function install() {
));

// Création de la notification
$notification = new Notification();
$notification_id = $notification->add(array(
$notification = new Notification();
if ($notification_id = $notification->add(array(
'name' => __("Notification for \"More Reporting\"", 'mreporting'),
'comment' => "",
'entities_id' => 0,
Expand All @@ -57,12 +57,14 @@ static function install() {
'itemtype' => 'PluginMreportingNotification',
'notificationtemplates_id' => $template_id,
'event' => 'sendReporting',
'mode' => 'mail',
));
'mode' => 'mail'))) {

$DB->query('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id)
VALUES (1, 1, '.$notification_id.');');
}
}

$DB->query('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id)
VALUES (1, 1, ' . $notification_id . ');');


return array('success' => true);
}
Expand Down
19 changes: 13 additions & 6 deletions inc/notificationtargetnotification.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,27 @@ function getTags() {
function getDatasForTemplate($event, $options = array()) {
global $CFG_GLPI;

$user_name = mt_rand().'_';
$user_name = mt_rand();

$file_name = $this->_buildPDF($user_name);
$path = GLPI_PLUGIN_DOC_DIR."/mreporting/notifications/$file_name";

$this->additionalData['attachment']['path'] = $path;
$this->additionalData['attachment']['name'] = $file_name;

$link = $CFG_GLPI['url_base']."/index.php?redirect=plugin_mreporting_$file_name";
$link = $CFG_GLPI['url_base']."/index.php?redirect=PluginMreportingDownload_$user_name";

$this->datas['##lang.mreporting.file_url##'] = __('Link');
$this->datas['##mreporting.file_url##'] = $link;
}


public function getFileName($user_name){
return 'glpi_report_'.$user_name."_".date('d-m-Y').'.pdf';
}

public function getFileDir(){
return GLPI_PLUGIN_DOC_DIR.'/mreporting/notifications';
}

/**
* Generate a PDF file with mreporting reports to be send in the notifications
Expand All @@ -50,8 +57,8 @@ function getDatasForTemplate($event, $options = array()) {
private function _buildPDF($user_name = '') {
global $CFG_GLPI, $DB, $LANG;

$dir = GLPI_PLUGIN_DOC_DIR.'/mreporting/notifications';
$file_name = 'glpi_report_'.$user_name.date('d-m-Y').'.pdf';
$dir = $this->getFileDir();
$file_name = $this->getFileName($user_name);

if(!is_dir($dir)) return false;

Expand Down Expand Up @@ -106,7 +113,7 @@ private function _buildPDF($user_name = '') {
continue;
}
$image_base64 = $matches[1][2];
if (strpos($image_base64, 'data:image/png;base64,') === false) {
if (strpos($image_base64, 'data:image/png;base64,') === false && isset($matches[1][3])) {
$image_base64 = $matches[1][3];
}
if (strpos($image_base64, 'data:image/png;base64,') === false) {
Expand Down
Loading