Example #1
0
 public static function installRights($first = false)
 {
     $missing_rights = array();
     $installed_rights = ProfileRight::getAllPossibleRights();
     $right_names = array();
     // Add common plugin's rights
     $right_names[] = self::getProfileNameForItemtype('PluginGenericobjectType');
     // Add types' rights
     $types = PluginGenericobjectType::getTypes(true);
     foreach ($types as $_ => $type) {
         $itemtype = $type['itemtype'];
         $right_names[] = self::getProfileNameForItemtype($itemtype);
     }
     // Check for already defined rights
     foreach ($right_names as $right_name) {
         _log($right_name, isset($installed_rights[$right_name]));
         if (!isset($installed_rights[$right_name])) {
             $missing_rights[] = $right_name;
         }
     }
     //Install missing rights in profile and update the object
     if (count($missing_rights) > 0) {
         ProfileRight::addProfileRights($missing_rights);
         self::changeProfile();
     }
 }
function plugin_post_init_genericobject()
{
    global $GO_FIELDS;
    //Toolbox::logDebug($GO_FIELDS);
    Plugin::registerClass('PluginGenericobjectProfile', array('addtabon' => array('Profile', 'PluginGenericobjectType')));
    foreach (PluginGenericobjectType::getTypes() as $id => $objecttype) {
        $itemtype = $objecttype['itemtype'];
        if (class_exists($itemtype)) {
            $itemtype::registerType();
        }
    }
}
Example #3
0
 You should have received a copy of the GNU General Public License
 along with Genericobject. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 @package   genericobject
 @author    the genericobject plugin team
 @copyright Copyright (c) 2010-2011 Order plugin team
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/genericobject
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
 
include ("../../../inc/includes.php");

if (isset($_GET['itemtype'])) {
   $itemtype = $_GET['itemtype'];
   $types = PluginGenericobjectType::getTypes();
//   $type = new PluginGenericobjectType();
//   $type->getFromDBByType($_GET['itemtype']);
//   Html::redirect(Toolbox::getItemTypeFormURL('PluginGenericobjectType').'?id='.$type->getID());

   Session::checkRight(PluginGenericobjectProfile::getProfileNameForItemtype($itemtype), READ);
   Html::header(__("Type of objects", "genericobject"), $_SERVER['PHP_SELF'], "assets",
                $_GET['itemtype']);
   Search::Show($_GET['itemtype']);

}

Html::footer();
Example #4
0
function plugin_genericobject_MassiveActions($type)
{
    $types = PluginGenericobjectType::getTypes();
    if (isset($types[$type])) {
        $objecttype = PluginGenericobjectType::getInstance($type);
        if ($objecttype->isTransferable()) {
            return array('plugin_genericobject_transfer' => __("Transfer"));
        } else {
            return array();
        }
    } else {
        return array();
    }
}
 You should have received a copy of the GNU General Public License
 along with Genericobject. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 @package   genericobject
 @author    the genericobject plugin team
 @copyright Copyright (c) 2010-2011 Order plugin team
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/genericobject
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
include "../../../inc/includes.php";
$itemtype = null;
if (isset($_REQUEST['itemtype'])) {
    $types = array_keys(PluginGenericobjectType::getTypes());
    $requested_type = $_REQUEST['itemtype'];
    $error = array();
    if (!in_array($requested_type, $types)) {
        $error[] = __('The requested type has not been defined yet!');
        if (!PluginGenericobjectType::canCreate()) {
            $error[] = __('Please ask your administrator to create this type of object');
        }
    } else {
        if (!class_exists($requested_type)) {
            $error[] = __('The generated files for the requested type of object are missing!');
            $error[] = __('You might need to regenerate the files under ' . GENERICOBJECT_DOC_DIR . '.');
        }
    }
    if (count($error) > 0) {
        Html::header(__('Type not found!'));
Example #6
0
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE `{$table}` (\n                           `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n                           `entities_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           `itemtype` varchar(255) collate utf8_unicode_ci default NULL,\n                           `is_active` tinyint(1) NOT NULL default '0',\n                           `name` varchar(255) collate utf8_unicode_ci default NULL,\n                           `comment` text NULL,\n                           `date_mod` datetime DEFAULT NULL,\n                           `date_creation` datetime DEFAULT NULL,\n                           `use_global_search` tinyint(1) NOT NULL default '0',\n                           `use_unicity` tinyint(1) NOT NULL default '0',\n                           `use_history` tinyint(1) NOT NULL default '0',\n                           `use_infocoms` tinyint(1) NOT NULL default '0',\n                           `use_contracts` tinyint(1) NOT NULL default '0',\n                           `use_documents` tinyint(1) NOT NULL default '0',\n                           `use_tickets` tinyint(1) NOT NULL default '0',\n                           `use_links` tinyint(1) NOT NULL default '0',\n                           `use_loans` tinyint(1) NOT NULL default '0',\n                           `use_network_ports` tinyint(1) NOT NULL default '0',\n                           `use_direct_connections` tinyint(1) NOT NULL default '0',\n                           `use_plugin_datainjection` tinyint(1) NOT NULL default '0',\n                           `use_plugin_pdf` tinyint(1) NOT NULL default '0',\n                           `use_plugin_order` tinyint(1) NOT NULL default '0',\n                           `use_plugin_uninstall` tinyint(1) NOT NULL default '0',\n                           `use_plugin_geninventorynumber` tinyint(1) NOT NULL default '0',\n                           `use_menu_entry` tinyint(1) NOT NULL default '0',\n                           `use_projects` tinyint(1) NOT NULL default '0',\n                           `linked_itemtypes` text NULL,\n                           `plugin_genericobject_typefamilies_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           PRIMARY KEY ( `id` )\n                           ) ENGINE = MYISAM COMMENT = 'Object types definition table' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
     }
     $migration->addField($table, "use_network_ports", "bool");
     $migration->addField($table, "use_direct_connections", "bool");
     $migration->addField($table, "use_plugin_geninventorynumber", "bool");
     $migration->addField($table, "use_contracts", "bool");
     $migration->addField($table, "use_menu_entry", "bool");
     $migration->addField($table, "use_global_search", "bool");
     $migration->addField($table, "use_projects", "bool");
     $migration->addField($table, "use_notepad", "bool");
     $migration->addField($table, "comment", "text");
     if (!$migration->addField($table, "date_mod", "datetime")) {
         $migration->changeField($table, "date_mod", "date_mod", "datetime");
     }
     $migration->addField($table, "date_creation", "datetime");
     $migration->addField($table, "linked_itemtypes", "text");
     $migration->addField($table, "plugin_genericobject_typefamilies_id", "integer");
     $migration->addField($table, "use_plugin_simcard", "bool");
     $migration->migrationOneTable($table);
     // Migrate notepad data
     $allGenericObjectTypes = PluginGenericobjectType::getTypes(true);
     $notepad = new Notepad();
     foreach ($allGenericObjectTypes as $genericObjectType => $genericObjectData) {
         $genericObjectTypeInstance = new $genericObjectType();
         if (FieldExists($genericObjectTypeInstance->getTable(), "notepad")) {
             $query = "INSERT INTO `" . $notepad->getTable() . "`\n                  (`items_id`,\n                  `itemtype`,\n                  `date`,\n                  `date_mod`,\n                  `content`\n               )\n               SELECT\n                  `id` as `items_id`,\n                  '" . $genericObjectType . "' as `itemtype`,\n                  now() as `date`,\n                  now() as `date_mod`,\n                  `notepad` as `content`\n               FROM `" . $genericObjectTypeInstance->getTable() . "`\n               WHERE notepad IS NOT NULL\n               AND notepad <> ''";
             $DB->query($query) or die($DB->error());
         }
         $query = "UPDATE`" . $notepad->getTable() . "`";
         $migration->dropField($genericObjectTypeInstance->getTable(), "notepad");
         $migration->migrationOneTable($genericObjectTypeInstance->getTable());
     }
     //Displayprefs
     $prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8, 14 => 10, 15 => 11);
     foreach ($prefs as $num => $rank) {
         if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='" . __CLASS__ . "' AND `num`='{$num}'\n                                       AND `users_id`='0'")) {
             $preference = new DisplayPreference();
             $tmp['itemtype'] = __CLASS__;
             $tmp['num'] = $num;
             $tmp['rank'] = $rank;
             $tmp['users_id'] = 0;
             $preference->add($tmp);
         }
     }
     //If files are missing, recreate them!
     self::checkClassAndFilesForItemType();
 }
Example #7
0
   /**
    * Generate items to display in GLPI menus
    *
    */
   static function getMenuContent() {
      $menu = array();
      $types = PluginGenericobjectType::getTypes();
      unset($_SESSION['glpimenu']);
      foreach($types as $type) {
         $itemtype = $type['itemtype'];
         $item = new $itemtype();
         $itemtype_rightname = PluginGenericobjectProfile::getProfileNameForItemtype($itemtype);
         if (
            class_exists($itemtype)
            and Session::haveRight($itemtype_rightname, READ)
         ) {

            $links = array();
            if ($item->canUseTemplate()) {
               $links['template'] = "/front/setup.templates.php?itemtype=$itemtype&amp;add=0";
               $links['add'] = "/front/setup.templates.php?itemtype=$itemtype&amp;add=1";
            } else {
               $links['add'] = self::getFormUrl(false).'?itemtype='.$itemtype;
            }
            $menu[strtolower($itemtype)]= array(
               'title' => (
                  "<span class='genericobject_menu_wrapper'>"
                  . self::getMenuIcon($type['itemtype'])
                  . "<span class='genericobject_menu_text'>"
                  .     $type['itemtype']::getMenuName()
                  . "</span>"
                  .
                  "</span>"
               ),
               'page' => self::getSearchUrl(false).'?itemtype='.$itemtype,
               'links' => $links
            );
            _log("Menu Content for ", $itemtype, "\n", $menu[strtolower($itemtype)]);
         }
      }
      $menu['is_multi_entries']= true;
      return $menu;
   }
Example #8
0
 static function getMenuContent()
 {
     $types = PluginGenericobjectType::getTypes();
     foreach ($types as $type) {
         $itemtype = $type['itemtype'];
         $item = new $itemtype();
         $itemtype_rightname = PluginGenericobjectProfile::getProfileNameForItemtype($itemtype);
         if (class_exists($itemtype) && Session::haveRight($itemtype_rightname, READ)) {
             $links = array();
             $links['search'] = $itemtype::getSearchUrl(false);
             if ($item->canUseTemplate()) {
                 $links['template'] = "/front/setup.templates.php?itemtype={$itemtype}&amp;add=0";
                 if (Session::haveRight($itemtype_rightname, CREATE)) {
                     $links['add'] = "/front/setup.templates.php?itemtype={$itemtype}&amp;add=1";
                 }
             } else {
                 if (Session::haveRight($itemtype_rightname, CREATE)) {
                     $links['add'] = $itemtype::getFormUrl(false);
                 }
             }
             // $menu[strtolower($itemtype)] = array('title' => $type['itemtype']::getMenuName(),
             //                                      'page'  => $itemtype::getSearchUrl(false));
             if ($type['plugin_genericobject_typefamilies_id'] > 0 && (!isset($_GET['itemtype']) || !preg_match("/itemtype=" . $_GET['itemtype'] . "/", $_GET['itemtype']))) {
                 $family_id = $type['plugin_genericobject_typefamilies_id'];
                 $name = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id, 0, false);
                 $str_name = strtolower($name);
                 $menu[$str_name]['title'] = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id);
                 $menu[$str_name]['page'] = '/plugins/genericobject/front/familylist.php?id=' . $family_id;
                 $menu[$str_name]['options'][strtolower($itemtype)] = array('title' => $type['itemtype']::getMenuName(), 'page' => $itemtype::getSearchUrl(false), 'links' => $links);
             } else {
                 $menu[strtolower($itemtype)] = array('title' => $type['itemtype']::getMenuName(), 'page' => $itemtype::getSearchUrl(false), 'links' => $links);
             }
         }
     }
     $menu['is_multi_entries'] = true;
     return $menu;
 }
Example #9
0
function plugin_post_init_genericobject()
{
    foreach (PluginGenericobjectType::getTypes() as $id => $objecttype) {
        $itemtype = $objecttype['itemtype'];
        $itemtype::registerType();
    }
}
Example #10
0
 /**
  * Create rights for the profile if it doesn't exists
  * @param profileID the profile ID
  * @return nothing
  */
 public static function createAccess($profiles_id, $first = false)
 {
     $profile = new self();
     foreach (PluginGenericobjectType::getTypes(true) as $tmp => $value) {
         if (!self::profileExists($profiles_id, $value["itemtype"])) {
             $input["itemtype"] = $value["itemtype"];
             $input["right"] = $first ? 'w' : '';
             $input["open_ticket"] = $first ? 1 : 0;
             $input["profiles_id"] = $profiles_id;
             $profile->add($input);
         }
     }
 }