Skip to content

Commit

Permalink
Release 2.0.0
Browse files Browse the repository at this point in the history
Changed filter mechanism: simplified it. Two kind of filters: type 0 for
ticket content and type 1 for ticket title.
Filters are now complete regex from / to /
Added a web interface to edit filters
tomolimo committed Jun 7, 2016
1 parent ab0f186 commit 24d0f0a
Showing 8 changed files with 623 additions and 127 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,3 +2,12 @@
New home for Ticket Cleaner GLPi plugin

Currently mirrors https://forge.glpi-project.org/projects/ticketcleaner


# Release 2.0.0
Beware that this new release will not keep your existing filters. You'll have to input them again with the new interface that permits to edit them directly into GLPi.
Your former filters will be copied into a backup table that you may edit via your preferred mySQL query editor (table name is `backup_glpi_plugin_ticketcleaner_filters`).
You'll have to combine your former filters to get the new ones that will be entered into the new table, or to create new one from scratch.

This version also brings the possibility to debug your regex using the GLPi debug mode (see wiki).

76 changes: 76 additions & 0 deletions front/filter.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*
* @version $Id$
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2015 Teclib'.
http://glpi-project.org
based on GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2014 by the INDEPNET Development Team.
-------------------------------------------------------------------------
LICENSE
This file is part of GLPI.
GLPI 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.
GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

/** @file
* @brief
*/

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

if (empty($_GET["id"])) {
$_GET["id"] = '';
}

Session::checkLoginUser();

$filter = new PluginTicketcleanerFilter();
if (isset($_POST["add"])) {
$filter->check(-1, CREATE, $_POST);

$newID = $filter->add($_POST);
if ($_SESSION['glpibackcreated']) {
Html::redirect($filter->getFormURL()."?id=".$newID);
} else {
Html::back();
}

} else if (isset($_POST["purge"])) {
$filter->check($_POST["id"], PURGE);
$filter->delete($_POST,1);

$filter->redirectToList();

} else if (isset($_POST["update"])) {

$filter->check($_POST["id"], UPDATE);

$filter->update($_POST);

Html::back();

} else {
Html::header(__('Ticket Cleaner - Filters','ticketcleaner'), $_SERVER['PHP_SELF'] , "config", "PluginTicketcleanerMenu", "ticketcleanerfilter");
$filter->display($_GET);
Html::footer();
}
?>
16 changes: 16 additions & 0 deletions front/filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
include ("../../../inc/includes.php");


Html::header(__('Ticket Cleaner Filters','ticketcleaner'), $_SERVER['PHP_SELF'] , "config", "PluginTicketcleanerMenu", "ticketcleanerfilter");

if (Session::haveRight("config", UPDATE)) {

Search::show('PluginTicketcleanerFilter');

} else {
Html::displayRightError();
}
Html::footer();

?>
223 changes: 108 additions & 115 deletions hook.php

Large diffs are not rendered by default.

343 changes: 343 additions & 0 deletions inc/filter.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,343 @@
<?php

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}

/**
* process short summary.
*
* process description.
*
* @version 1.0
* @author MoronO
*/
class PluginTicketcleanerFilter extends CommonDBTM {

static $rightname = 'entity';


const DESCRIPTION_TYPE = 0;
const TITLE_TYPE = 1;


static function getTypeName($nb=0) {
global $LANG;

if ($nb>1) {
return __('Filters','ticketcleaner');
}
return __('Filter','ticketcleaner');
}

/**
* Summary of getSearchOptions
* @return mixed
*/
function getSearchOptions() {
global $LANG;

$tab = array();

$tab['common'] = __('Filter','ticketcleaner');

$tab[1]['table'] = $this->getTable();
$tab[1]['field'] = 'name';
$tab[1]['name'] = __('Name');
$tab[1]['datatype'] = 'itemlink';
$tab[1]['searchtype'] = 'contains';
$tab[1]['massiveaction'] = false;
$tab[1]['itemlink_type'] = $this->getType();

$tab[8]['table'] = $this->getTable();
$tab[8]['field'] = 'is_active';
$tab[8]['name'] = __('Active');
$tab[8]['massiveaction'] = true;
$tab[8]['datatype'] = 'bool';

$tab[4]['table'] = $this->getTable();
$tab[4]['field'] = 'comment';
$tab[4]['name'] = __('Comments');
$tab[4]['massiveaction'] = true;
$tab[4]['datatype'] = 'text';

$tab[19]['table'] = $this->getTable();
$tab[19]['field'] = 'date_mod';
$tab[19]['name'] = __('Last update');
$tab[19]['datatype'] = 'datetime';
$tab[19]['massiveaction'] = false;

//$tab[802]['table'] = $this->getTable();
//$tab[802]['field'] = 'css_selector_value';
//$tab[802]['name'] = __('Value CSS selector', 'ticketcleaner');
//$tab[802]['massiveaction'] = false;
//$tab[802]['datatype'] = 'dropdown';

$tab[900]['table'] = $this->getTable();
$tab[900]['field'] = 'type';
$tab[900]['name'] = __('Type', 'ticketcleaner');
$tab[900]['massiveaction'] = false;
$tab[900]['searchtype'] = 'equals';
$tab[900]['datatype'] = 'specific';

$tab[901]['table'] = $this->getTable();
$tab[901]['field'] = 'order';
$tab[901]['name'] = __('Order', 'ticketcleaner');
$tab[901]['massiveaction'] = false;
//$tab[901]['searchtype'] = 'equals';

$tab[902]['table'] = $this->getTable();
$tab[902]['field'] = 'regex';
$tab[902]['name'] = __('RegEx', 'ticketcleaner');
$tab[902]['massiveaction'] = false;

$tab[903]['table'] = $this->getTable();
$tab[903]['field'] = 'replacement';
$tab[903]['name'] = __('Replacement', 'ticketcleaner');
$tab[903]['massiveaction'] = false;


return $tab;
}

/**
* @since version 0.84
*
* @param $field
* @param $values
* @param $options array
**/
static function getSpecificValueToDisplay($field, $values, array $options=array()) {

if (!is_array($values)) {
$values = array($field => $values);
}
switch ($field) {


case 'type':
return self::getFilterTypeName($values[$field]);
}
return parent::getSpecificValueToDisplay($field, $values, $options);
}

/**
* @since version 0.84
*
* @param $field
* @param $name (default '')
* @param $values (default '')
* @param $options array
*
* @return string
**/
static function getSpecificValueToSelect($field, $name='', $values='', array $options=array()) {

if (!is_array($values)) {
$values = array($field => $values);
}
$options['display'] = false;
switch ($field) {

case 'type':
$options['value'] = $values[$field];
return self::dropdownType($name, $options);
}
return parent::getSpecificValueToSelect($field, $name, $values, $options);
}



/**
* Dropdown of ticket type
*
* @param $name select name
* @param $options array of options:
* - value : integer / preselected value (default 0)
* - toadd : array / array of specific values to add at the begining
* - on_change : string / value to transmit to "onChange"
* - display : boolean / display or get string (default true)
*
* @return string id of the select
**/
static function dropdownType($name, $options=array()) {

$params['value'] = 0;
$params['toadd'] = array();
$params['on_change'] = '';
$params['display'] = true;

if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}

$items = array();
if (count($params['toadd']) > 0) {
$items = $params['toadd'];
}

$items += self::getFilterTypes();

return Dropdown::showFromArray($name, $items, $params);
}

/**
* Get ticket types
*
* @return array of types
**/
static function getFilterTypes() {

$options[self::DESCRIPTION_TYPE] = self::getFilterTypeName(self::DESCRIPTION_TYPE);
$options[self::TITLE_TYPE] = self::getFilterTypeName(self::TITLE_TYPE);

return $options;
}


/**
* Get ticket type Name
*
* @param $value type ID
**/
static function getFilterTypeName($value) {

switch ($value) {
case self::DESCRIPTION_TYPE :
return __('Description', 'ticketcleaner');

case self::TITLE_TYPE :
return __('Title','ticketcleaner');

default :
// Return $value if not defined
return $value;
}
}

/**
* @since version 0.85
*
* @see CommonGLPI::getTabNameForItem()
**/
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {

if (static::canView()) {
$nb = 0;
switch ($item->getType()) {

case 'PluginTicketcleanerFilter' :
return PluginTicketcleanerFilter::getTypeName(Session::getPluralNumber());
}
}
return '';
}


function defineTabs($options=array()) {

// $ong = array('empty' => $this->getTypeName(1));
$ong = array();
$this->addDefaultFormTab($ong);
//$this->addStandardTab(__CLASS__, $ong, $options);

//$this->addStandardTab('PluginTicketcleanerFilter', $ong, $options);

return $ong;
}

function showForm ($ID, $options=array('candel'=>false)) {
global $DB, $CFG_GLPI, $LANG;

if ($ID > 0) {
$this->check($ID,READ);
}

$canedit = $this->can($ID,UPDATE);
$options['canedit'] = $canedit ;

$this->initForm($ID, $options);


$this->showFormHeader($options);

echo "<tr class='tab_bg_1'>";
echo "<td>".__("Name")."&nbsp;:</td>";
echo "<td><input type='text' size='50' maxlength=250 name='name' value='".htmlentities($this->fields["name"], ENT_QUOTES)."'></td>";
echo "<td rowspan='4' class='middle'>".__("Comments")."&nbsp;:</td>";
echo "<td class='center middle' rowspan='4'><textarea cols='40' rows='4' name='comment' >".htmlentities($this->fields["comment"], ENT_QUOTES)."</textarea></td>";
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td >".__("Active")."&nbsp;:</td>";
echo "<td>" ;
Html::showCheckbox(array('name' => 'is_active',
'checked' => $this->fields['is_active']
));
echo "</td></tr>";

echo "</td></tr>";

echo "<tr class='tab_bg_1'>";
echo "<td >".__('Type', 'ticketcleaner')."&nbsp;:</td>";
//echo "<td><input type='text' size='50' maxlength=200 name='type' value='".$this->fields["type"]."'></td>";
echo "<td>";
$opt = array('value' => $this->fields["type"]);
self::dropdownType('type', $opt);
echo "</td>";
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td >".__('order', 'ticketcleaner')."&nbsp;:</td>";
echo "<td><input type='text' size='10' maxlength=10 name='order' value='".$this->fields["order"]."'></td>";
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td >".__('RegEx', 'ticketcleaner')."&nbsp;:</td>";
echo "<td colspan=3><input type='text' size='150' maxlength=255 name='regex' value='".htmlentities($this->fields["regex"], ENT_QUOTES)."'></td>";
echo "</tr>";

echo "<tr class='tab_bg_1'>";
echo "<td >".__("Replacement", 'ticketcleaner')."&nbsp;:</td>";
echo "<td colspan=3><input type='text' size='150' maxlength=255 name='replacement' value='". htmlentities($this->fields["replacement"], ENT_QUOTES)."'></td>";
echo "</tr>";

if( version_compare(GLPI_VERSION,'9.1','lt') ) {
echo "<tr class='tab_bg_1'>";
echo "<td >".__('Last modification')."&nbsp;:</td><td>";
echo Html::convDateTime($this->fields["date_mod"]);
echo "</td></tr>";
}


echo "<tr><td>&nbsp;";
echo "</td></tr>";

echo "<tr>";
echo "</tr>";

$this->showFormButtons($options );
//$this->addDivForTabs();

}

function prepareInputForAdd($input) {
if(isset( $input['regex'] ) ) {
$input['regex'] = html_entity_decode( $input['regex']) ;
}
return $input ;
}

function prepareInputForUpdate($input) {
if(isset( $input['regex'] ) ) {
$input['regex'] = html_entity_decode( $input['regex']) ;
}

return $input ;
}


}

42 changes: 42 additions & 0 deletions inc/menu.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
class PluginTicketcleanerMenu extends CommonGLPI {
static $rightname = 'entity';

static function getMenuName() {
return __("Ticket Cleaner Filters", "ticketcleaner");
}

static function getMenuContent() {

if (!Session::haveRight('entity', READ)) {
return;
}

$front_page = "/plugins/ticketcleaner/front";
$menu = array();
$menu['title'] = self::getMenuName();
$menu['page'] = "$front_page/filter.php";

$itemtypes = array('PluginTicketcleanerFilter' => 'ticketcleanerfilter');

foreach ($itemtypes as $itemtype => $option) {
$menu['options'][$option]['title'] = $itemtype::getTypeName(Session::getPluralNumber());
switch( $itemtype ) {
case 'PluginTicketcleanerFilter':
$menu['options'][$option]['page'] = $itemtype::getSearchURL(false);
$menu['options'][$option]['links']['search'] = $itemtype::getSearchURL(false);
if ($itemtype::canCreate()) {
$menu['options'][$option]['links']['add'] = $itemtype::getFormURL(false);
}
break ;
default :
$menu['options'][$option]['page'] = PluginTicketcleanerFilter::getSearchURL(false);
break ;
}

}
return $menu;
}


}
16 changes: 10 additions & 6 deletions setup.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

// ----------------------------------------------------------------------
// Original Author of file: Olivier Moron
// Purpose of file: Provides cleaning of Ticket, for title, description
// Purpose of file: Provides cleaning of Ticket, for title, description
// and followups.
// It cleans text for creation and edition (from email or from web interface)
// and it cleans attached pictures to emails
@@ -19,9 +19,9 @@ function plugin_init_ticketcleaner() {
global $PLUGIN_HOOKS;

Plugin::registerClass('PluginTicketCleaner', array('classname' => 'PluginTicketCleaner'));

$PLUGIN_HOOKS['csrf_compliant']['ticketcleaner'] = true;

$PLUGIN_HOOKS['pre_item_add']['ticketcleaner'] = array(
'Ticket' => array('PluginTicketCleaner', 'plugin_pre_item_add_ticketcleaner'),
'TicketFollowup' => array('PluginTicketCleaner', 'plugin_pre_item_add_ticketcleaner_followup')
@@ -30,19 +30,23 @@ function plugin_init_ticketcleaner() {
'Ticket' => array('PluginTicketCleaner', 'plugin_pre_item_update_ticketcleaner'),
'TicketFollowup' => array('PluginTicketCleaner', 'plugin_pre_item_update_ticketcleaner_followup')
);

if (Config::canUpdate()) {
// Display a menu entry
$PLUGIN_HOOKS['menu_toadd']['ticketcleaner'] = array('config' => 'PluginTicketcleanerMenu');
}

}


/**
* Summary of plugin_version_ticketcleaner
* @return name and version of the plugin
* @return name and version of the plugin
*/
function plugin_version_ticketcleaner(){
global $LANG;

return array ('name' => 'Ticket Cleaner',
'version' => '1.2.3',
'version' => '2.0.0',
'author' => 'Olivier Moron',
'homepage' => '',
'minGlpiVersion' => '0.83.8');
25 changes: 19 additions & 6 deletions ticketcleaner.xml
Original file line number Diff line number Diff line change
@@ -10,17 +10,22 @@
<en><![CDATA[Cleaning of Tickets and Followups.]]></en>
</short>
<long>
<fr><![CDATA[Ce plugin sert à 'nettoyer' les Tickets créés par eMail ou par l'interface web ainsi que les Suivis de Tickets. Il permet le filtrage des logos par comparaison de Sha1 calculés sur des fichiers exemples. Il permet le nettoyage des textes des Tickets (et des Suivis) par un méchanisme d'expressions régulières.]]></fr>
<en><![CDATA[This plugin cleans Tickets created via eMails or via web interface (cleans also Ticket Followups). It filters pictures by comparing between new incoming file Sha1 with sample pictures.
It cleans texts of Tickets (and Followups) via a regular expression mechanism.]]></en>
<fr><![CDATA[Ce plugin sert à 'nettoyer' les Tickets créés par eMail ou par l'interface web ainsi que les Suivis de Tickets.
Il permet le filtrage des logos par comparaison de Sha1 calculés sur des fichiers exemples.
Il permet le nettoyage des textes des Tickets (et des Suivis) par un méchanisme d'expressions régulières.
Cette nouvelle version (2.0.0) apporte une simplification des filtres et une nouvelle interface pour la saisie de ceux-ci.]]></fr>
<en><![CDATA[This plugin cleans Tickets created via eMails or via web interface (cleans also Ticket Followups).
It filters pictures by comparing between new incoming file Sha1 with sample pictures.
It cleans texts of Tickets (and Followups) via a regular expression mechanism.
This new release (2.0.0) simplies filter creation, and brings a new interface to input filters.]]></en>
</long>
</description>
<homepage>https://github.com/tomolimo/ticketcleaner</homepage>
<download>https://github.com/tomolimo/ticketcleaner/releases</download>
<issues>https://github.com/tomolimo/ticketcleaner/issues</issues>
<readme>https://forge.glpi-project.org/projects/ticketcleaner/wiki</readme>
<readme>https://github.com/tomolimo/ticketcleaner/wiki</readme>
<authors>
<author>Olivier Moron </author>
<author>Olivier Moron</author>
</authors>
<versions>
<version>
@@ -40,7 +45,15 @@
<compatibility>0.90</compatibility>
</version>
<version>
<num>1.2.3</num>
<num>2.0.0</num>
<compatibility>0.85</compatibility>
</version>
<version>
<num>2.0.0</num>
<compatibility>0.90</compatibility>
</version>
<version>
<num>2.0.0</num>
<compatibility>9.1</compatibility>
</version>

1 comment on commit 24d0f0a

@tomolimo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solves #1

Please sign in to comment.