You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2022-05-26 12:16:16

phil-de
Member
Registered: 2022-05-26
Posts: 1

Self-programmed plugin is not displayed as a tab

Hello everyone!

I tried to program a plugin based on the documentation.
I can install the plugin so far, the table is also created. But the plugin does not appear as a "tab" under assets.
Can anyone tell me what I'm doing wrong?

Thank you!

setup.php

<?php
    //Variablen Definition mit Plugin Informationen
    const PLUGIN_NAME = "Debitoren Plugin";
    const VERSION_NUMBER = "1.0";
    const AUTHOR = "Phil";
    const LICENSE = "GNU";
    const HOMEPAGE = "www.domain.de";
    const MINGLPIVERSION = "10.0.0";

    //Initialisierungsfunktion
    function plugin_init_debitoren()
    {
        global $PLUGIN_HOOKS;
        $Plugin = new Plugin();
        $PLUGIN_HOOKS['csrf_compliant']['debitoren'] = true;

        Plugin::registerClass('debitoren');
    }

    //Plugin Meta Daten festlegen
    function plugin_version_debitoren()
    {
        return array(
            "name"              =>  PLUGIN_NAME,
            "version"           =>  VERSION_NUMBER,
            "author"            =>  AUTHOR,
            "license"           =>  LICENSE,
            "homepage"          =>  HOMEPAGE,
            "minGlpiVersion"    =>  MINGLPIVERSION,
        );
    }

    //Überprüfung ob Server Anforderungen erfüllt sind
    function plugin_debitoren_check_prerequisites()
    {
        if(version_compare(GLPI_VERSION, MINGLPIVERSION, 'eq') || version_compare(GLPI_VERSION, MINGLPIVERSION, 'gt'))
        {
            return true;
        } else
        {
            echo "Das Plugin benötigt die Version " . MINGLPIVERSION . "! Installiert: " . GLPI_VERSION;
            return false;
        }
    }

    function plugin_debitoren_check_config()
    {
        return true;
    }

hook.php

<?php
    function plugin_debitoren_install()
    {
        global $DB;

        $migrate = new Migration(100);

        //Check if Database Table exists
        if (!$DB->tableExists('glpi_plugin_debitoren_customer'))
        {
            $query = "CREATE TABLE glpi_plugin_customer_customer (
                id int(6) NOT NULL AUTO_INCREMENT,
                salutation varchar(255) NOT NULL,
                firstname varchar(255) NOT NULL,
                lastname varchar(255) NOT NULL,
                street varchar(255) NOT NULL,
                city varchar(255) NOT NULL,
                plz varchar(255) NOT NULL,
                country varchar(255) NOT NULL,
                primary key (id));";
            $DB->queryOrDie($query, $DB->error());
        }

        $migrate->executeMigration();
        return true;
    }

    function plugin_debitoren_uninstall()
    {
        global $DB;

        $tables = [
            'customer'
        ];

        foreach ($tables as $table) {
            $tablename = 'glpi_plugin_debitoren_' . $table;

            if ($DB->tableExists($tablename)) {
                $DB->queryOrDie(
                    "DROP TABLE `$tablename`",
                    $DB->error()
                );
            }
        }
        return true;
    }

inc/debitoren.class.php

<?php
class PluginDebitorenAddNewDebitor extends CommonDBTM
{
    public function showForm($ID, $options = [])
    {
        global $CFG_GLPI;

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

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

        $params = $options;
        // Standardgemäß werden nicht alle Elemente angezeigt. Hier werden diese angezeigt oder zurückgegeben
        $params['display'] = false;

        $out = '<tr>';
        $out .= '<th>' . __('Debitoren hinzufügen', 'debitoren') . '</th>';

        $objectName = autoName(
            $this->fields["name"],
            "name",
            (isset($options['withtemplate']) && $options['withtemplate'] == 2),
            $this->getType(),
            $this->fields["entities_id"]
        );
        $out .= '<td>';
        $out .= Html::automcompletionTextField(
            $this,
            'name',
            [
                'value' => $objectName,
                'display' => false
            ]
        );
        $out .= '</td>';
        $out .= $this->showFormButtons($params);

        if ($options['display'])
        {
            echo $out;
        }
        else
        {
            return $out;
        }
    }
}

front/addnewdebitor.form.php

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

// Überprüfe ob das Plugin installiert und aktiviert ist
$plugin = new Plugin();
if (!$plugin->isInstalled('debitoren') || !$plugin->isActivated('debitoren')) {
   Html::displayNotFoundError();
}

$object = new PluginDebitorenAddNewDebitor();

if (isset($_POST['add']))
{
    // Überprüfe Create Rechte
    $object->check(-1, CREATE, $_POST);
    // Erstelle Objekt
    $newid = $object->add($_POST);
    // Navigiere zum neuen Objekt
    Html::redirect("{CFG_GLPI['root_doc']}/plugins/debitoren/front/debitor.form.php?id={$newid}");
} else if (isset($_POST['update']))
{
    // Überprüfe die Update Berechtigung
    $object->check($_POST['id'], UPDATE);
    // Aktualisiere Objekt
    $object->update($_POST);
    // Navigiere zum Objekt
    Html::back();
}
else if (isset($_POST['delete']))
{
    // Überprüfe die Delete Berechtigung
    $object->check($_POST['id'], DELETE);
    // Entferne Objekt
    $object->delete($_POST);
    // Navigiere zurück zur Übersicht
    $object->redirectToList();
}
else if (isset($_POST['purge']))
{
    // Überprüfe Purge Berechtigung
    $object->check($_POST['id'], PURGE);
    // Lösche Objekt
    $object->delete($_POST, 1);
    // Navigiere zur Objektübersicht
    Html::redirect("{$CFG_GLPI['root_doc']}/plugins/debitoren/front/debitor.php");
} else
{
    // Standard Display
    $withtemplate = (isset($_GET['withtemplate']) ? $_GET['withtemplate'] : 0);
    $object->display(
        [
          'id' => $_GET['id'],
          'withtemplate' => $withtemplate
        ]
    );
}

front/addnewdebitor.php

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

// Überprüfe ob das Plugin aktiviert ist
$plugin = new Plugin();
if (!$plugin->isInstalled('debitoren') || !$plugin->isActivated('debitoren')) {
   Html::displayNotFoundError();
}

// Überprüfe die Zugriffsrechte
if (PluginDebitorenAddNewDebitor::canView())
{
    //Berechtigung vorhanden, zeige Liste an

    //Füge Seitenüberschrift hinzu
    Html::header(
        __('Debitoren', 'debitoren'),
        $_SERVER['PHP_SELF'],
        'assets',
        'PluginDebitorenAddNewDebitor',
        'addnewdebitor'
    );

    Search::show('PluginDebitorenAddNewDebitor');

    Html::footer();
} else
{
    //Keine Berechtigung, zeige Fehlermeldung
    Html::displayRightError();
}

Offline

#2 2022-05-30 11:52:15

Kaya84
Member
Registered: 2019-06-13
Posts: 217

Re: Self-programmed plugin is not displayed as a tab

Inside the plugin_init function,
you need to add where to show it with    
$PLUGIN_HOOKS["menu_toadd"]
or with Plugin::registerClass ('pluginnamee'),                            array('addtabon' => 'Profile'));

Offline

Board footer

Powered by FluxBB