diff --git a/front/config.form.php b/front/config.form.php new file mode 100644 index 0000000..6ff8550 --- /dev/null +++ b/front/config.form.php @@ -0,0 +1,19 @@ +check($_POST['id'], UPDATE); + + // save + $config->update($_POST); + + + Html::back(); + +} else if (isset($_POST["refresh"])) { + $config->refresh($_POST); // used to refresh process list, task category list + Html::back(); +} + +Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".urlencode('PluginCostsConfig$1')); \ No newline at end of file diff --git a/inc/config.class.php b/inc/config.class.php new file mode 100644 index 0000000..fb297a6 --- /dev/null +++ b/inc/config.class.php @@ -0,0 +1,138 @@ +tableExists(self::getTable())) { + $this->getFromDB(1); + } + } + /** + * Summary of canCreate + * @return boolean + */ + static function canCreate() { + return Session::haveRight('config', UPDATE); + } + + /** + * Summary of canView + * @return boolean + */ + static function canView() { + return Session::haveRight('config', READ); + } + + /** + * Summary of canUpdate + * @return boolean + */ + static function canUpdate() { + return Session::haveRight('config', UPDATE); + } + + /** + * Summary of getTypeName + * @param mixed $nb plural + * @return mixed + */ + static function getTypeName($nb = 0) { + return __("Costs", "costs"); + } + + /** + * Summary of getInstance + * @return PluginProcessmakerConfig + */ + static function getInstance() { + + if (!isset(self::$_instance)) { + self::$_instance = new self(); + if (!self::$_instance->getFromDB(1)) { + self::$_instance->getEmpty(); + } + } + return self::$_instance; + } + + public static function getConfig($update = false) { + static $config = null; + if (is_null($config)) { + $config = new self(); + } + if ($update) { + $config->getFromDB(1); + } + return $config; + } + + /** + * Summary of showConfigForm + * @param mixed $item is the config + * @return boolean + */ + static function showConfigForm() { + global $CFG_GLPI; + + $config = new self(); + $config->getFromDB(1); + + $config->showFormHeader(['colspan' => 4]); + + echo ""; + echo "".__("Add task description on cost", "cost").""; + Dropdown::showYesNo("taskdescription", $config->fields["taskdescription"]); + echo "\n"; + + $config->showFormButtons(['candel'=>false]); + + return false; + } + + function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + global $LANG; + + if ($item->getType()=='Config') { + return __("Costs", "costs"); + } + return ''; + } + + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { + + if ($item->getType()=='Config') { + self::showConfigForm($item); + } + return true; + } + + public static function install(Migration $migration) { + global $DB; + + $table = self::getTable(); + $config = new self(); + + if (!$DB->tableExists($table)) { + $migration->displayMessage("Installing $table"); + //Install + + $query = "CREATE TABLE `$table` ( + `id` int(11) NOT NULL auto_increment, + `taskdescription` tinyint(1) NOT NULL default '0', + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; + + $DB->query($query) or die ($DB->error()); + $config->add([ + 'id' => 1, + 'taskdescription' => 0, + ]); + } + } +} \ No newline at end of file diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 81843de..892e8e8 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -95,6 +95,7 @@ static function generateCosts($item) { 'begin', 'end', 'actiontime', + 'content', ], 'FROM'=>'glpi_tickettasks', 'WHERE'=>[ @@ -110,6 +111,7 @@ static function generateCosts($item) { 'begin', 'end', 'actiontime', + 'content', ], 'FROM'=>'glpi_tickettasks', 'WHERE'=>[ @@ -119,11 +121,16 @@ static function generateCosts($item) { } foreach ($DB->request($query) as $id => $row) { + $config=PluginCostsConfig::getConfig(); + $comment=__('Automatically generated by GLPI').' -> Costs Plugin'; + if ($config->fields['taskdescription']) { + $comment=$row['content']." \n".__('Automatically generated by GLPI').' -> Costs Plugin'; + } $DB->insert( 'glpi_ticketcosts', [ 'tickets_id'=>$ticket_id, 'name'=>$row['id']."_".$row['users_id_tech'], - 'comment'=>__('Automatically generated by GLPI').' -> Costs Plugin', + 'comment'=>$comment, 'begin_date'=>$row['begin'], 'end_date'=>$row['end'], 'actiontime'=>$row['actiontime'], diff --git a/locales/costs.pot b/locales/costs.pot new file mode 100644 index 0000000..31095f6 --- /dev/null +++ b/locales/costs.pot @@ -0,0 +1,27 @@ +# Cost Glpi Plugin. +# Copyright (C) 2020 TICgal +# This file is distributed under the same license as the PACKAGE package. +# TICgal, 2020 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-05-08 14:32+0200\n" +"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: inc/config.class.php:46 inc/config.class.php:102 inc/entity.class.php:46 +#: inc/ticket.class.php:41 +msgid "Costs" +msgstr "" + +#: inc/config.class.php:89 +msgid "Add task description on cost" +msgstr "" diff --git a/locales/en_GB.mo b/locales/en_GB.mo new file mode 100644 index 0000000..a3ba27c Binary files /dev/null and b/locales/en_GB.mo differ diff --git a/locales/en_GB.po b/locales/en_GB.po new file mode 100644 index 0000000..54455df --- /dev/null +++ b/locales/en_GB.po @@ -0,0 +1,28 @@ +# Cost Glpi Plugin. +# Copyright (C) 2020 TICgal +# This file is distributed under the same license as the PACKAGE package. +# TICgal, 2020 +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-05-08 14:32+0200\n" +"PO-Revision-Date: 2020-05-08 14:33+0200\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Last-Translator: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: en_GB\n" + +#: inc/config.class.php:46 inc/config.class.php:102 inc/entity.class.php:46 +#: inc/ticket.class.php:41 +msgid "Costs" +msgstr "Costs" + +#: inc/config.class.php:89 +msgid "Add task description on cost" +msgstr "Add task description on cost" diff --git a/locales/es_ES.mo b/locales/es_ES.mo new file mode 100644 index 0000000..bca14b7 Binary files /dev/null and b/locales/es_ES.mo differ diff --git a/locales/es_ES.po b/locales/es_ES.po new file mode 100644 index 0000000..9e89537 --- /dev/null +++ b/locales/es_ES.po @@ -0,0 +1,28 @@ +# Cost Glpi Plugin. +# Copyright (C) 2020 TICgal +# This file is distributed under the same license as the PACKAGE package. +# TICgal, 2020 +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-05-08 14:32+0200\n" +"PO-Revision-Date: 2020-05-08 14:34+0200\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Last-Translator: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: es_ES\n" + +#: inc/config.class.php:46 inc/config.class.php:102 inc/entity.class.php:46 +#: inc/ticket.class.php:41 +msgid "Costs" +msgstr "Costes" + +#: inc/config.class.php:89 +msgid "Add task description on cost" +msgstr "AƱadir la descripciĆ³n de la tarea en el coste" diff --git a/setup.php b/setup.php index 25ebb4e..b5dfdf6 100755 --- a/setup.php +++ b/setup.php @@ -32,7 +32,7 @@ @link https://tic.gal @since 2018 ---------------------------------------------------------------------- */ -define ('PLUGIN_COSTS_VERSION', '1.1.0'); +define ('PLUGIN_COSTS_VERSION', '1.2.0'); // Minimal GLPI version, inclusive define("PLUGIN_COSTS_MIN_GLPI", "9.3.0"); // Maximum GLPI version, exclusive @@ -94,6 +94,10 @@ function plugin_init_costs() { if (Session::haveRight('entity', UPDATE)) { Plugin::registerClass('PluginCostsEntity', ['addtabon' => 'Entity']); } + if (Session::haveRightsOr("config", [READ, UPDATE])) { + Plugin::registerClass('PluginCostsConfig', ['addtabon' => 'Config']); + $PLUGIN_HOOKS['config_page']['costs'] = 'front/config.form.php'; + } $PLUGIN_HOOKS['csrf_compliant']['costs'] = true; $PLUGIN_HOOKS['pre_item_update']['costs'] = ['Ticket' => ['PluginCostsTicket','generateCosts']]; diff --git a/tools/generate_locales.sh b/tools/generate_locales.sh new file mode 100644 index 0000000..c22223e --- /dev/null +++ b/tools/generate_locales.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +CUR_PATH="`dirname \"$0\"`" + +cd "$CUR_PATH/.." + +xgettext *.php */*.php -o locales/costs.pot -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po -k --keyword=__:1,2t --keyword=_x:1,2,3t --keyword=__s:1,2t --keyword=_sx:1,2,3t --keyword=_n:1,2,3,4t --keyword=_sn:1,2t --keyword=_nx:1,2,3t --copyright-holder "TICgal" + +cd locales + +sed -i "s/SOME DESCRIPTIVE TITLE/Cost Glpi Plugin/" costs.pot +sed -i "s/FIRST AUTHOR , YEAR./TICgal, $(date +%Y)/" costs.pot +sed -i "s/YEAR/$(date +%Y)/" costs.pot + +for a in $(ls *.po); do + msgmerge -U $a costs.pot + msgfmt $a -o "${a%.*}.mo" +done +rm -f *.po~ \ No newline at end of file diff --git a/tools/make_release.sh b/tools/make_release.sh new file mode 100644 index 0000000..434656a --- /dev/null +++ b/tools/make_release.sh @@ -0,0 +1,116 @@ +#!/bin/bash +# +# ------------------------------------------------------------------------- +# make_release.sh +# Based on fusioninventory-for-glpi make_release.sh +# Copyright (C) 2018-2019 by TICgal +# https://github.com/ticgal/costs +# ------------------------------------------------------------------------- +# LICENSE +# This file is part of the costs plugin. +# costs plugin 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 3 of the License, or +# (at your option) any later version. +# costs plugin 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 costs. If not, see . +# -------------------------------------------------------------------------- +# @package costs +# @author TICgal +# @copyright Copyright (c) 2018-2019 TICgal +# @license AGPL License 3.0 or (at your option) any later version +# http://www.gnu.org/licenses/agpl-3.0-standalone.html +# @link https://tic.gal +# @since 2018 +# -------------------------------------------------------------------------- + +PLUGINNAME="costs" + +if [ ! "$#" -eq 2 ] +then + echo "Usage $0 fi_git_dir release" + exit +fi + +read -p "Are translations up to date? [Y/n] " -n 1 -r +echo # (optional) move to a new line +if [[ ! $REPLY =~ ^[Yy]$ ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell +fi + +INIT_DIR=$1 +RELEASE=$2 + +# remove old tmp files +if [ ! -e /tmp/$PLUGINNAME ] +then + echo "Deleting temp directory" + rm -rf /tmp/$PLUGINNAME +fi + +# test plugin_cvs_dir +if [ ! -e $INIT_DIR ] +then + echo "$1 does not exist" + exit +fi + +INIT_PWD=$PWD; + +if [ -e /tmp/$PLUGINNAME ] +then + echo "Delete existing temp directory" + rm -rf /tmp/$PLUGINNAME +fi + +echo "Copy to /tmp directory" +git checkout-index -a -f --prefix=/tmp/$PLUGINNAME/ + +echo "Move to this directory" +cd /tmp/$PLUGINNAME + +echo "Check version" +if grep --quiet $RELEASE setup.php; then + echo "$RELEASE found in setup.php, OK." +else + echo "$RELEASE has not been found in setup.php. Exiting." + exit 1 +fi + +echo "Compile locale files" +./tools/generate_locales.sh + +echo "Delete various scripts and directories" +rm -rf vendor +rm -rf RoboFile.php +rm -rf tools +rm -rf phpunit +rm -rf tests +rm -rf .gitignore +rm -rf .travis.yml +rm -rf .coveralls.yml +rm -rf phpunit.xml.dist +rm -rf composer.json +rm -rf composer.lock +rm -rf .composer.hash +rm -rf ISSUE_TEMPLATE.md +rm -rf PULL_REQUEST_TEMPLATE.md +rm -rf .tx +rm -rf $PLUGINNAME.xml +rm -rf screenshots + +echo "Creating tarball" +cd .. +tar czf "$PLUGINNAME-$RELEASE.tar.tgz" $PLUGINNAME + +cd $INIT_PWD; + +echo "Deleting temp directory" +rm -rf /tmp/$PLUGINNAME + +echo "The Tarball is in the /tmp directory" \ No newline at end of file