function plugin_init_genericobject()
{
    global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS, $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $LOADED_PLUGINS;
    include_once GLPI_ROOT . '/plugins/genericobject/inc/profile.class.php';
    PluginGenericobjectProfile::reloadProfileRights();
    $GO_READONLY_FIELDS = array("is_helpdesk_visible", "comment");
    $GO_BLACKLIST_FIELDS = array("itemtype", "table", "is_deleted", "id", "entities_id", "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name", "is_helpdesk_visible", "comment");
    $GO_LINKED_TYPES = array('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor', 'Printer', 'NetworkEquipment');
    $PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true;
    $GENERICOBJECT_PDF_TYPES = array();
    $plugin = new Plugin();
    if ($plugin->isInstalled("genericobject") && $plugin->isActivated("genericobject")) {
        plugin_genericobject_includeCommonFields();
        $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1;
        // add css styles
        $PLUGIN_HOOKS['add_css']['genericobject'] = array("css/styles.css");
        // Display a menu entry ?
        $PLUGIN_HOOKS['menu_toadd']['genericobject'] = array('config' => 'PluginGenericobjectType', 'assets' => 'PluginGenericobjectObject');
        // Ensure GLPI does correctly load menu entries for each activated objects
        // TODO: it could be better to check existence of those entries before unsetting the glpimenu
        // session in order to trigger rebuild.
        unset($_SESSION['glpimenu']);
        // Config page
        /*if (Session::haveRight('config', READ)) {
             $PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php';
             $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['add']
                = Toolbox::getItemTypeFormURL('PluginGenericobjectType', false);
             $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['search']
                = Toolbox::getItemTypeSearchURL('PluginGenericobjectType', false);
          }*/
        $PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true;
        $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1;
        $PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject';
        $PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject";
    }
}
示例#2
0
function plugin_genericobject_install() {
   global $DB;

   //check directories rights
   if (!check_directories()) {
      return false;
   }

   $migration = new Migration('2.4.0');

   foreach (
      array(
         'PluginGenericobjectField',
         'PluginGenericobjectCommonDropdown',
         'PluginGenericobjectCommonTreeDropdown',
         'PluginGenericobjectProfile',
         'PluginGenericobjectType',
         'PluginGenericobjectTypeFamily'
      ) as $itemtype
   ) {
      if ($plug=isPluginItemType($itemtype)) {
         $plugname = strtolower($plug['plugin']);
         $dir      = GLPI_ROOT . "/plugins/$plugname/inc/";
         $item     = strtolower($plug['class']);
         if (file_exists("$dir$item.class.php")) {
            include_once ("$dir$item.class.php");
            if ( method_exists($itemtype, 'install') ) {
               $itemtype::install($migration);
            }
         }
      }
   }

   if (!is_dir(GENERICOBJECT_CLASS_PATH)) {
      @ mkdir(GENERICOBJECT_CLASS_PATH, 0777, true)
         or die("Can't create folder " . GENERICOBJECT_CLASS_PATH);
   }

   //Init plugin & types
   plugin_init_genericobject();

   //Init profiles
   PluginGenericobjectProfile::reloadProfileRights();
   return true;
}
示例#3
0
   /**
    * Create an object, it's table, files and rights
    *
    * @since 2.1.5
    * @param name object short name
    * @param itemtype object class name
    * @param options create options :
    *    - add_table : add the object table (default is no)
    *    - create_default_profile : add default right (default is no) for current user profile
    *    - add_injection_file : add file to integrate itemtype into the datainjection plugin
    *    - add_language_file : create a default language for the itemtype
    * @return none
    */
   static function addNewObject($name, $itemtype, $options = array()) {
      $params['add_table']              = false;
      $params['create_default_profile'] = false;
      $params['add_injection_file']     = false;
      $params['add_language_file']      = true;
      foreach ($options as $key => $value) {
         $params[$key] = $value;
      }

      if ($params['add_table']) {
         self::addTable($itemtype);
      }

      //Write object class on the filesystem
      self::addClassFile($name, $itemtype);

     //Write the form on the filesystem
      self::addFormFile($name, $itemtype);
      self::addSearchFile($name, $itemtype);

      //Add language file
      self::addLocales($name, $itemtype);

      //Add file needed by datainjectin plugin
      if ($params['add_injection_file']) {
         self::addDatainjectionFile($name);
      }
      PluginGenericobjectProfile::installRights();
      if ($params['create_default_profile']) {
         //Create rights for this new object
         PluginGenericobjectProfile::createAccess($_SESSION["glpiactiveprofile"]["id"], $itemtype,true);
         //Reload profiles
         PluginGenericobjectProfile::reloadProfileRights();
      }
   }
示例#4
0
function plugin_init_genericobject() {
   global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS,
          $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $LOADED_PLUGINS;


   include_once(GLPI_ROOT.'/plugins/genericobject/inc/profile.class.php');

   PluginGenericobjectProfile::reloadProfileRights();
   $GO_READONLY_FIELDS  = array ("is_helpdesk_visible", "comment");

   $GO_BLACKLIST_FIELDS = array ("itemtype", "table", "is_deleted", "id", "entities_id",
                                 "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name",
                                 "is_helpdesk_visible", "comment");

   $GO_LINKED_TYPES     = array ('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor',
                                  'Printer', 'NetworkEquipment');

   $PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true;
   $GENERICOBJECT_PDF_TYPES                         = array ();
   $plugin                                          = new Plugin();

   if ($plugin->isInstalled("genericobject") && $plugin->isActivated("genericobject")) {

      plugin_genericobject_includeCommonFields();
      $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1;

      // add css styles
      $PLUGIN_HOOKS['add_css']['genericobject'] = array(
         "css/styles.css"
      );

      // Display a menu entry ?
      $PLUGIN_HOOKS['menu_toadd']['genericobject'] = array(
         'config' => 'PluginGenericobjectType',
         'assets' => 'PluginGenericobjectObject'
      );

      // Ensure GLPI does correctly load menu entries for each activated objects
      // TODO: it could be better to check existence of those entries before unsetting the glpimenu
      // session in order to trigger rebuild.
      unset($_SESSION['glpimenu']);

      //Do not display icon if not using the genericobject plugin
//      if (isset($_GET['id']) &&  $_GET['id'] != ''
//         && strpos($_SERVER['REQUEST_URI'],
//                     Toolbox::getItemTypeFormURL("PluginGenericobjectType")) !== false) {
//         $url  = '/plugins/genericobject/index.php';
//         $type = new PluginGenericobjectType();
//         $type->getFromDB($_GET['id']);
//         if ($type->fields['is_active']) {
//            $url.= '?itemtypes_id='.$_GET['id'];
//            $image = "<img src='".$CFG_GLPI["root_doc"]."/pics/stats_item.png' title=\"".
//                      __("Go to objects list", "genericobject").
//                        "\" alt=\"".__("Go to objects list", "genericobject")."\">";
//            $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links'][$image]
//               = $url;
//         }
//      }
      $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['add']
         = Toolbox::getItemTypeFormURL('PluginGenericobjectType', false);
      $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['search']
         = Toolbox::getItemTypeSearchURL('PluginGenericobjectType', false);

      // Config page
      if (Session::haveRight('config', READ)) {
         $PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php';
      }

      $PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true;
      $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1;

      $PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject';
      $PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject";

   }
}