示例#1
0
function plugin_mreporting_install()
{
    global $DB;
    //get version
    $plugin = new Plugin();
    $found = $plugin->find("name = 'mreporting'");
    $plugin_mreporting = array_shift($found);
    //init migration
    $migration = new Migration($plugin_mreporting['version']);
    //create profiles table
    $queries = array();
    $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_profiles` (\n      `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\n      `profiles_id` VARCHAR(45) NOT NULL,\n      `reports` CHAR(1),\n      `config` CHAR(1),\n   PRIMARY KEY (`id`)\n   )\n   ENGINE = MyISAM;";
    //create configuration table
    $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_configs` (\n   `id` int(11) NOT NULL auto_increment,\n   `name` varchar(255) collate utf8_unicode_ci default NULL,\n   `classname` varchar(255) collate utf8_unicode_ci default NULL,\n   `is_active` tinyint(1) NOT NULL default '0',\n   `is_notified` tinyint(1) NOT NULL default '1',\n   `show_graph` tinyint(1) NOT NULL default '0',\n   `show_area` tinyint(1) NOT NULL default '0',\n   `spline` tinyint(1) NOT NULL default '0',\n   `show_label` VARCHAR(10) default NULL,\n   `flip_data` tinyint(1) NOT NULL default '0',\n   `unit` VARCHAR(10) default NULL,\n   `default_delay` VARCHAR(10) default NULL,\n   `condition` VARCHAR(255) default NULL,\n   `graphtype` VARCHAR(255) default 'GLPI',\n   PRIMARY KEY  (`id`),\n   KEY `is_active` (`is_active`)\n   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
    $queries[] = "CREATE TABLE  IF NOT EXISTS `glpi_plugin_mreporting_preferences` (\n   `id` int(11) NOT NULL auto_increment,\n   `users_id` int(11) NOT NULL default 0,\n   `template` varchar(255) collate utf8_unicode_ci default NULL,\n   PRIMARY KEY  (`id`),\n   KEY `users_id` (`users_id`)\n   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
    // add display preferences
    $query_display_pref = "SELECT id \n      FROM glpi_displaypreferences\n      WHERE itemtype = 'PluginMreportingConfig'";
    $res_display_pref = $DB->query($query_display_pref);
    if ($DB->numrows($res_display_pref) == 0) {
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','2','2','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','3','3','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','4','4','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','5','5','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','6','6','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','8','8','0');";
    }
    $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` (\n      `id` int(11) NOT NULL auto_increment,\n      `entities_id` int(11) NOT NULL default '0',\n      `is_recursive` tinyint(1) NOT NULL default '0',\n      `name` varchar(255) collate utf8_unicode_ci default NULL,\n      `notepad` longtext collate utf8_unicode_ci,\n      `date_envoie` DATE DEFAULT NULL,\n      `notice`INT(11) NOT NULL DEFAULT 0,\n      `alert` INT(11) NOT NULL DEFAULT 0,\n      `comment` text collate utf8_unicode_ci,\n      `date_mod` datetime default NULL,\n      `is_deleted` tinyint(1) NOT NULL default '0',\n      PRIMARY KEY  (`id`)\n      ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
    foreach ($queries as $query) {
        $DB->query($query);
    }
    // == Update to 2.1 ==
    if (!FieldExists('glpi_plugin_mreporting_configs', 'is_notified')) {
        $migration->addField('glpi_plugin_mreporting_configs', 'is_notified', 'tinyint(1) NOT NULL default "1"', array('after' => 'is_active'));
        $migration->migrationOneTable('glpi_plugin_mreporting_configs');
    }
    require_once "inc/profile.class.php";
    PluginMreportingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . "/mreporting";
    if (!is_dir($rep_files_mreporting)) {
        mkdir($rep_files_mreporting);
    }
    $notifications_folder = GLPI_PLUGIN_DOC_DIR . "/mreporting/notifications";
    if (!is_dir($notifications_folder)) {
        mkdir($notifications_folder);
    }
    require_once "inc/notification.class.php";
    PluginMreportingNotification::install();
    CronTask::Register('PluginMreportingNotification', 'SendNotifications', MONTH_TIMESTAMP);
    require_once "inc/baseclass.class.php";
    require_once "inc/common.class.php";
    require_once "inc/config.class.php";
    $config = new PluginMreportingConfig();
    $config->createFirstConfig();
    return true;
}
示例#2
0
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 mreporting. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
Session::checkRight("config", "w");
$plugin = new Plugin();
if ($plugin->isActivated("mreporting")) {
    //Create first config for graphs
    if (isset($_GET["new"])) {
        Session::checkRight("config", "w");
        $config = new PluginMreportingConfig();
        $config->createFirstConfig();
        Html::back();
    } else {
        Html::header(__("Setup"), '', "plugins", "mreporting", "config");
        PluginMreportingConfig::addFirstconfigLink();
        Search::show("PluginMreportingConfig");
    }
} else {
    Html::header(__("Setup"), '', "config", "plugins");
    echo "<div align='center'>";
    echo "<br><br>";
    echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt=\"warning\">";
    echo "<br><br>";
    echo "<b>Please activate the plugin</b></div>";
}
Html::footer();