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; }
static function prepareHtmlFields($fields, $items_id, $canedit = true, $show_table = true, $massiveaction = false) { if (empty($fields)) { return false; } //get object associated with this fields $tmp = $fields; $first_field = array_shift($tmp); $container_obj = new PluginFieldsContainer(); $container_obj->getFromDB($first_field['plugin_fields_containers_id']); $items_itemtype = ucfirst($container_obj->fields['itemtype']); $classname = "PluginFields" . $items_itemtype . preg_replace('/s$/', '', $container_obj->fields['name']); $obj = new $classname(); //find row for this object with the items_id $found_values = $obj->find("plugin_fields_containers_id = " . $first_field['plugin_fields_containers_id'] . " AND items_id = " . $items_id); $found_v = array_shift($found_values); // find profiles (to check if current profile can edit fields) $fprofile = new PluginFieldsProfile(); $found_p = $fprofile->find("`profiles_id` = '" . $_SESSION['glpiactiveprofile']['id'] . "'\n AND `plugin_fields_containers_id` = '" . $first_field['plugin_fields_containers_id'] . "'"); $first_found_p = array_shift($found_p); // test status for "CommonITILObject" objects if (is_subclass_of($items_itemtype, "CommonITILObject")) { $items_obj = new $items_itemtype(); $items_obj->getFromDB($items_id); if (in_array($items_obj->fields['status'], $items_obj->getClosedStatusArray()) || in_array($items_obj->fields['status'], $items_obj->getSolvedStatusArray()) || $first_found_p['right'] != CREATE) { $canedit = false; } } //show all fields $html = ""; $odd = 0; foreach ($fields as $field) { if ($field['type'] === 'header') { $html .= "<tr class='tab_bg_2'>"; $html .= "<th colspan='4'>" . $field['label'] . "</td>"; $html .= "</tr>"; $odd = 0; } else { //get value $value = ""; if (is_array($found_v)) { if ($field['type'] == "dropdown") { $value = $found_v["plugin_fields_" . $field['name'] . "dropdowns_id"]; } else { $value = $found_v[$field['name']]; } } if (isset($_SESSION['plugin']['fields']['values_sent'])) { if ($field['type'] == "dropdown") { $value = $_SESSION['plugin']['fields']['values_sent']["plugin_fields_" . $field['name'] . "dropdowns_id"]; } else { $value = $_SESSION['plugin']['fields']['values_sent'][$field['name']]; } } //get default value if (empty($value) && !empty($field['default_value'])) { $value = $field['default_value']; } //show field if ($show_table) { if ($odd % 2 == 0) { $html .= "<tr class='tab_bg_2'>"; } $required = $field['mandatory'] == 1 ? "<span class='red'>*</span>" : ''; if ($container_obj->fields['itemtype'] == 'Ticket' && $container_obj->fields['type'] == 'dom' && strpos($_SERVER['HTTP_REFERER'], ".injector.php") === false && strpos($_SERVER['HTTP_REFERER'], ".public.php") === false) { $html .= "<th width='13%'>" . $field['label'] . " : {$required}</th>"; } else { $html .= "<td>" . $field['label'] . " : {$required}</td>"; } $html .= "<td>"; } $readonly = $field['is_readonly']; switch ($field['type']) { case 'number': case 'text': $value = Html::cleanInputText($value); if ($canedit && !$readonly) { $html .= "<input type='text' name='" . $field['name'] . "' value=\"{$value}\" />"; } else { $html .= $value; } break; case 'textarea': if ($massiveaction) { continue; } if ($canedit && !$readonly) { $html .= "<textarea cols='45' rows='4' name='" . $field['name'] . "'>" . "{$value}</textarea>"; } else { $html .= nl2br($value); } break; case 'dropdown': if ($canedit && !$readonly) { //find entity on current object $obj = new $container_obj->fields['itemtype'](); $obj->getFromDB($items_id); ob_start(); if (strpos($field['name'], "dropdowns_id") !== false) { $dropdown_itemtype = getItemTypeForTable(getTableNameForForeignKeyField($field['name'])); } else { $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']); } Dropdown::show($dropdown_itemtype, array('value' => $value, 'entity' => $obj->getEntityID())); $html .= ob_get_contents(); ob_end_clean(); } else { $dropdown_table = "glpi_plugin_fields_" . $field['name'] . "dropdowns"; $html .= Dropdown::getDropdownName($dropdown_table, $value); } break; case 'yesno': //in massive action, we must skip display for yesno (possible bug in framework) //otherwise double display of field if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); Dropdown::showYesNo($field['name'], $value); $html .= ob_get_contents(); ob_end_clean(); } else { $html .= Dropdown::getYesNo($value); } break; case 'date': if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); Html::showDateFormItem($field['name'], $value); $html .= ob_get_contents(); ob_end_clean(); } else { $html .= Html::convDate($value); } break; case 'datetime': if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); Html::showDateTimeFormItem($field['name'], $value); $html .= ob_get_contents(); ob_end_clean(); } else { $html .= Html::convDateTime($value); } case 'dropdownuser': if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); User::dropdown(array('name' => $field['name'], 'value' => $value, 'entity' => -1, 'right' => 'all', 'condition' => 'is_active=1 && is_deleted=0')); $html .= ob_get_contents(); ob_end_clean(); } else { $showuserlink = 0; if (Session::haveRight('user', 'r')) { $showuserlink = 1; } $html .= getUserName($value, $showuserlink); } } if ($show_table) { $html .= "</td>"; if ($odd % 2 == 1) { $html .= "</tr>"; } $odd++; } } } if ($show_table && $odd % 2 == 1) { $html .= "</tr>"; } unset($_SESSION['plugin']['fields']['values_sent']); return $html; }
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; }