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-11-02 14:06:27

DoctorDeath
Member
Registered: 2017-05-03
Posts: 11

add an item to the GLPI menu?

hi friends
I'm learning to write my plugin
I can't add an item to the GLPI menu in any way, tell me what's wrong with dal?

setup.php

<?php


define('PLUGIN_ZAKAZ_VERSION', '1.0');

// Minimal GLPI version, inclusive
define("PLUGIN_ZAKAZ_MIN_GLPI_VERSION", "10.0.0");
// Maximum GLPI version, exclusive
define("PLUGIN_ZAKAZ_MAX_GLPI_VERSION", "10.0.99");

if (!defined("PLUGIN_ZAKAZ_DIR")) {
    define("PLUGIN_ZAKAZ_DIR", GLPI_ROOT . "/plugins/zakz");
}

/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_zakaz()
{
    global $PLUGIN_HOOKS, $CFG_GLPI, $ORDER_TYPES;
   $PLUGIN_HOOKS['csrf_compliant']['zakaz'] = true;

   /* Init current profile */
   $PLUGIN_HOOKS['change_profile']['zakaz'] = ['PluginOrderProfile', 'initProfile'];
   
    Plugin::registerClass('PluginZakaz');
    Plugin::registerClass('PluginZakazProfile');
    Plugin::registerClass('PluginZakazMenu', array('addtabon' => array('Management')));
   
    $PLUGIN_HOOKS['csrf_compliant']['zakaz'] = true;
    $PLUGIN_HOOKS['change_profile']['zakaz'] = [PluginZakazProfile::class, 'initProfile'];

    $PLUGIN_HOOKS['menu_toadd']['zakaz'] = ['Management'  => 'PluginZakazMenu'];
    $PLUGIN_HOOKS['config_page']['PluginZakaz'] = 'front/index.php';
    $PLUGIN_HOOKS['menu']['PluginZakaz']= true;
        
    
}


/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_zakaz()
{
     $author = "<a href='https://radio-portal.su'>Радиолюбительский портал'</a>";
   $author.= ", <a href='mailto:doc@radio-portal.su'>Doc</a>";
    return [
        'name'           => 'Заказ оборудования',
        'version'        => PLUGIN_ZAKAZ_VERSION,
        'author'         => $author,
        'license'        => 'GPLv2+',
        'homepage'       => 'https://radio-portal.su',
        'requirements'   => [
            'glpi' => [
                'min' => PLUGIN_ZAKAZ_MIN_GLPI_VERSION,
                'max' => PLUGIN_ZAKAZ_MAX_GLPI_VERSION,
            ]
        ]
    ];
}

/**
* Check pre-requisites before install
* OPTIONNAL, but recommanded
*
* @return boolean
*/
function plugin_zakaz_check_prerequisites()
{
    return true;
}

/**
* Check configuration process
*
* @param boolean $verbose Whether to display message on failure. Defaults to false
*
* @return boolean
*/
function plugin_zakaz_check_config($verbose = false)
{
    if (true) { // Your configuration check
        return true;
    }

    if ($verbose) {
        echo __('Installed / not configured', 'zakaz');
    }
    return false;
}

hook.php
<?php


/**
* Plugin install process
*
* @return boolean
*/
function plugin_zakaz_install()
{
            global $DB;
        $migrate = new Migration(100);
        if (!$DB->tableExists('glpi_plugin_zakaz_pord')) {
        $query =  "CREATE TABLE `glpi_plugin_zakaz_pord` (
  `slu` int(255) NOT NULL,
  `date_slu` date DEFAULT NULL,
  `iniciator` varchar(62) DEFAULT NULL,
  `inc` int(255) DEFAULT NULL,
  `fio` varchar(232) DEFAULT NULL,
  `company` int(11) DEFAULT NULL,
  `equipment` varchar(10000) DEFAULT NULL,
  `date_poluch` date DEFAULT NULL,
  `status` int(1) DEFAULT 1,
  `comments` text DEFAULT NULL,
   PRIMARY KEY (`slu`));";
     $DB->queryOrDie($query, $DB->error());
        }
        $migrate->executeMigration();
   
    return true;
}

/**
* Plugin uninstall process
*
* @return boolean
*/
function plugin_zakaz_uninstall()
{
            global $DB;

        $tables = [
            'pord'
        ];

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

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

Offline

Board footer

Powered by FluxBB