Skip to content

Commit

Permalink
Added base objects for config pages
Browse files Browse the repository at this point in the history
  • Loading branch information
DonutsNL committed Jun 21, 2023
1 parent 1a7b847 commit 479b0a7
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 1 deletion.
51 changes: 51 additions & 0 deletions front/Config.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

include ("../../../inc/includes.php");
use GlpiPlugin\Ticketfilter\Config;

// Check if plugin is activated...
$plugin = new Plugin();
if (!$plugin->isInstalled('ticketfilter') || !$plugin->isActivated('ticketfilter')) {
Html::displayNotFoundError();
}

$Config = new Config();

if (isset($_POST['add'])) {
//Check CREATE ACL
$Config->check(-1, CREATE, $_POST);
//Do object creation
$newid = $Config->add($_POST);
//Redirect to newly created object form
Html::redirect("{$CFG_GLPI['root_doc']}/plugins/front/myobject.form.php?id=$newid");
} else if (isset($_POST['update'])) {
//Check UPDATE ACL
$Config->check($_POST['id'], UPDATE);
//Do object update
$Config->update($_POST);
//Redirect to object form
Html::back();
} else if (isset($_POST['delete'])) {
//Check DELETE ACL
$Config->check($_POST['id'], DELETE);
//Put object in dustbin
$Config->delete($_POST);
//Redirect to objects list
$Config->redirectToList();
} else if (isset($_POST['purge'])) {
//Check PURGE ACL
$Config->check($_POST['id'], PURGE);
//Do object purge
$Config->delete($_POST, 1);
//Redirect to objects list
Html::redirect("{$CFG_GLPI['root_doc']}/plugins/front/myobject.php");
} else {
//per default, display object
$withtemplate = (isset($_GET['withtemplate']) ? $_GET['withtemplate'] : 0);
$Config->display(
[
'id' => $_GET['id'],
'withtemplate' => $withtemplate
]
);
}
34 changes: 34 additions & 0 deletions front/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
include ("../../../inc/includes.php");
use GlpiPlugin\Ticketfilter\Config;
use Plugin;

// Check if plugin is activated...
$plugin = new Plugin();
if (!$plugin->isInstalled('ticketfilter') || !$plugin->isActivated('ticketfilter')) {
Html::displayNotFoundError();
}

//check for ACLs
/*if (Config::canView()) { */
//View is granted: display the list.

//Add page header
Html::header(
__('Ticket Filter', 'ticketfilter'),
$_SERVER['PHP_SELF'],
'assets',
Config::class,
'ticketfilter'
);

Search::show(Config::class);

Html::footer();

/*
} else {
//View is not granted.
Html::displayRightError();
}
*/
97 changes: 97 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* ------------------------------------------------------------------------
* Chris Gralike Ticket Filter
* Copyright (C) 2023 by Chris Gralike
* ------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Ticket Filter project.
*
* Ticket Filter plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Ticket Filter 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ticket filter. If not, see <http://www.gnu.org/licenses/>.
*
* ------------------------------------------------------------------------
*
* @package TicketFilter
* @version 1.0.0
* @author Chris Gralike
* @copyright Copyright (c) 2023 by Chris Gralike
* @license MIT
* @see https://github.com/DonutsNL/ticketfilter/readme.md
* @link https://github.com/DonutsNL/ticketfilter
* @since 1.0.0
* @todo !Keep it stupid simple!
* -Create a fancy configuration page
* -Config [Followup Match string] [AutoSolve Match String] [Supress followups] [regEx101 testlink/comment]
* -Option to automatically merge duplicate oldest/latest ticket if more then 1 ticket is found with matchstring.
* -Option to automatically link with closed ticket(s) on match closed (how to deal with multiple closed tickets?)
* -Default GLPI behaviour is to load Plugin trazilion times with each dashboard graph, maybe create singleton pattern/caching?
* ------------------------------------------------------------------------
**/

namespace GlpiPlugin\Ticketfilter;

use CommonDropdown;
use Html;

class Config extends CommonDropdown {

public function showForm($ID, array $options = []) {
global $CFG_GLPI;

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

if (!isset($options['display'])) {
//display per default
$options['display'] = true;
}

$params = $options;
//do not display called elements per default; they'll be displayed or returned here
$params['display'] = false;

$out = '<tr>';
$out .= '<th>' . __('My label', 'Ticket Filter') . '</th>';

$objectName = autoName(
$this->fields["name"],
"name",
(isset($options['withtemplate']) && $options['withtemplate']==2),
$this->getType(),
$this->fields["entities_id"]
);

$out .= '<td>';
$out .= Html::autocompletionTextField(
$this,
'name',
[
'value' => $objectName,
'display' => false
]
);
$out .= '</td>';

$out .= $this->showFormButtons($params);

if ($options['display'] == true) {
echo $out;
} else {
return $out;
}
}
}
3 changes: 2 additions & 1 deletion src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class Filter {
*
* @param Ticket $item Hooked Ticket object passed by refference.
* @return void
* @since 1.0.0
* @since 1.0.0
* @see setup.php hook
*/
public static function PreItemAdd(Ticket $item) : void
{
Expand Down

0 comments on commit 479b0a7

Please sign in to comment.