Exemplo n.º 1
0
function plugin_fields_checkFiles()
{
    $plugin = new Plugin();
    if (isset($_SESSION['glpiactiveentities']) && $plugin->isInstalled('fields') && $plugin->isActivated('fields')) {
        Plugin::registerClass('PluginFieldsContainer');
        Plugin::registerClass('PluginFieldsDropdown');
        Plugin::registerClass('PluginFieldsField');
        if (TableExists("glpi_plugin_fields_containers")) {
            $container_obj = new PluginFieldsContainer();
            $containers = $container_obj->find();
            foreach ($containers as $container) {
                $classname = "PluginFields" . ucfirst($container['itemtype'] . preg_replace('/s$/', '', $container['name']));
                if (!class_exists($classname)) {
                    PluginFieldsContainer::generateTemplate($container);
                }
            }
        }
        if (TableExists("glpi_plugin_fields_fields")) {
            $fields_obj = new PluginFieldsField();
            $fields = $fields_obj->find("`type` = 'dropdown'");
            foreach ($fields as $field) {
                PluginFieldsDropdown::create($field);
            }
        }
    }
}
Exemplo n.º 2
0
 static function addNewProfile(Profile $profile)
 {
     $containers = new PluginFieldsContainer();
     $found_containers = $containers->find();
     $fields_profile = new self();
     foreach ($found_containers as $container) {
         $fields_profile->add(array('profiles_id' => $profile->fields['id'], 'plugin_fields_containers_id' => $container['id']));
     }
     return true;
 }
Exemplo n.º 3
0
/**
 * Load Fields classes in datainjection.
 * Called by Setup.php:44 if Datainjection is installed and active
**/
function plugin_datainjection_populate_fields()
{
    global $INJECTABLE_TYPES;
    $container = new PluginFieldsContainer('is_active = 1');
    $found = $container->find();
    foreach ($found as $id => $values) {
        $classname = "PluginFields" . ucfirst($values['itemtype'] . preg_replace('/s$/', '', $values['name'])) . 'Injection';
        $INJECTABLE_TYPES[$classname] = 'fields';
        $INJECTABLE_TYPES[$classname . 'Injection'] = 'fields';
    }
}
Exemplo n.º 4
0
 static function findContainer($itemtype, $items_id, $type = 'tab', $subtype = '')
 {
     if ($type === 'tab' || $type === 'dom') {
         $sql_type = "`type` = '{$type}'";
     } else {
         $sql_type = "1=1";
     }
     $entity = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : 0;
     $sql_entity = getEntitiesRestrictRequest("AND", "", "", $entity, true, true);
     $sql_subtype = '';
     if ($subtype != '') {
         if ($subtype == $itemtype . '$main') {
             $sql_subtype = " AND type = 'dom' ";
         } else {
             $sql_subtype = " AND type != 'dom' AND subtype = '{$subtype}' ";
         }
     }
     $container = new PluginFieldsContainer();
     $found_c = $container->find($sql_type . " AND `itemtype` = '{$itemtype}' AND is_active = 1 " . $sql_entity . $sql_subtype);
     if (empty($found_c)) {
         return false;
     }
     if ($type == "dom") {
         $tmp = array_shift($found_c);
         $id = $tmp['id'];
     } else {
         $id = array_keys($found_c);
         if (count($id) == 1) {
             $id = array_shift($id);
         }
     }
     //profiles restriction
     if (isset($_SESSION['glpiactiveprofile']['id'])) {
         $profile = new PluginFieldsProfile();
         if (is_array($id)) {
             $condition = "`plugin_fields_containers_id` IN (" . implode(", ", $id) . ")";
         } else {
             $condition = "`plugin_fields_containers_id` = '{$id}'";
         }
         $found = $profile->find("`profiles_id` = '" . $_SESSION['glpiactiveprofile']['id'] . "'\n                                 AND {$condition}");
         $first_found = array_shift($found);
         if ($first_found['right'] == NULL) {
             return false;
         }
     }
     return $id;
 }
Exemplo n.º 5
0
 static function findContainer($itemtype, $type = 'tab', $subtype = '')
 {
     $sql_type = "`type` = '{$type}'";
     $entity = isset($_SESSION['glpiactiveentities']) ? $_SESSION['glpiactiveentities'] : 0;
     $sql_entity = getEntitiesRestrictRequest("AND", "", "", $entity, true, true);
     $sql_subtype = '';
     if ($subtype != '') {
         if ($subtype == $itemtype . '$main') {
             $sql_subtype = " AND type = 'dom' ";
         } else {
             $sql_subtype = " AND type != 'dom' AND subtype = '{$subtype}' ";
         }
     }
     $container = new PluginFieldsContainer();
     $itemtypes = $container->find($sql_type . " AND is_active = 1 " . $sql_entity . $sql_subtype);
     $id = 0;
     if (count($itemtypes) < 1) {
         return false;
     }
     foreach ($itemtypes as $data) {
         $dataitemtypes = json_decode($data['itemtypes']);
         $item = new $itemtype();
         if (in_array($item->getType(), $dataitemtypes) != FALSE) {
             $id = $data['id'];
         }
     }
     //profiles restriction
     if (isset($_SESSION['glpiactiveprofile']['id'])) {
         $profile = new PluginFieldsProfile();
         if (isset($id)) {
             if (is_array($id)) {
                 $condition = "`plugin_fields_containers_id` IN (" . implode(", ", $id) . ")";
             } else {
                 $condition = "`plugin_fields_containers_id` = '{$id}'";
             }
             $found = $profile->find("`profiles_id` = '" . $_SESSION['glpiactiveprofile']['id'] . "'\n                                 AND {$condition}");
             $first_found = array_shift($found);
             if ($first_found['right'] == NULL) {
                 return false;
             }
         }
     }
     return $id;
 }