/**
 * Display fields for massive actions
 *
 * @param array $options Massive Actions options
 * @return bool Success
 */
function plugin_customfields_MassiveActionsFieldsDisplay($options = array())
{
    global $DB;
    $type = $options['itemtype'];
    $table = $options['options']['table'];
    $field = $options['options']['field'];
    $linkfield = $options['options']['linkfield'];
    // Get configuration of the custom field
    $query = "SELECT *\n             FROM `glpi_plugin_customfields_fields`\n             WHERE `itemtype` = '{$type}'\n                   AND `system_name` = '{$field}'";
    $result = $DB->query($query);
    if ($data = $DB->fetch_assoc($result)) {
        switch ($data['data_type']) {
            case 'dropdown':
                $dropdown_obj = new PluginCustomfieldsDropdown();
                $tmp = $dropdown_obj->find("system_name = '" . $data['system_name'] . "'");
                $dropdown = array_shift($tmp);
                Dropdown::show('PluginCustomfieldsDropdownsItem', array('condition' => $dropdown['id'] . " = plugin_customfields_dropdowns_id", 'name' => $data['system_name'], 'entity' => $_SESSION['glpiactive_entity']));
                break;
            case 'yesno':
                dropdown::showYesNo($field, 0);
                break;
            case 'date':
                Html::showDateFormItem($field, '', true, true);
                break;
            case 'money':
                echo '<input type="text" size="16" value="' . Html::formatNumber(0, true) . '" name="' . $field . '"/>';
                break;
            default:
                $item = new $type();
                Html::autocompletionTextField($item, $field);
                break;
        }
        return true;
    }
    return false;
}
 // Label of dropdown
 echo '<td><input name="name[' . $ID . ']" value="' . htmlspecialchars($data['name']) . '" size="20"></td>';
 // Internal name
 echo '<td>' . $data['system_name'] . '</td>';
 echo '<td class="center">';
 if ($data['num_links'] == 0 && $haveright) {
     // Show "delete" link, when ACL is right and no usages
     echo '<input name="delete[' . $ID . ']" class="submit" type="submit" value=\'' . _sx('button', 'Delete permanently') . '\'>';
 } else {
     // Show usages
     echo sprintf(_n('Used by %1$s device', 'Used by %1$s devices', $data['num_links'], 'customfields'), $data['num_links']);
 }
 echo '</td>';
 // show Search/Add-Link to manage dropdown fields
 echo '<td>';
 $item = new PluginCustomfieldsDropdown();
 $table = $item->getTable();
 $rand = mt_rand();
 $name = Dropdown::EMPTY_VALUE;
 $comment = "";
 $tmpname = Dropdown::getDropdownName($table, '', 1);
 if ($tmpname["name"] != "&nbsp;") {
     $name = $tmpname["name"];
     $comment = $tmpname["comment"];
 }
 // Manage items
 $options_tooltip['link'] = $CFG_GLPI["root_doc"] . '/plugins/customfields/front/dropdownsitem.php';
 $options_tooltip['linktarget'] = '_blank';
 Html::showToolTip($comment, $options_tooltip);
 // Add item
 $itemFormUrl = $CFG_GLPI["root_doc"] . '/plugins/customfields/front/dropdownsitem.form.php' . "?popup=1&amp;rand=" . $rand . "&amp;plugin_customfields_dropdowns_id=" . $ID;
Example #3
0
 /**
  * Show form for item (used by overriding virtual classes)
  *
  * @param $id ID of customfield
  * @param array $options Addtional options
  * @return bool Success
  */
 function showForm($id, $options = array())
 {
     global $LANG, $CFG_GLPI, $DB;
     // ACL check
     if (!Session::haveRight("profile", "r")) {
         //return false;
     }
     switch ($this->associatedItemType()) {
         case "Computer":
         case "Contract":
         case "Document":
         case "User":
         case "Group":
         case "Monitor":
         case "Software":
         case "Peripheral":
         case "Printer":
         case "CartridgeItem":
         case "ConsumableItem":
         case "Phone":
         case "Budget":
             $canedit = Session::haveRight(strtolower($this->associatedItemType()), "w");
             $canread = Session::haveRight(strtolower($this->associatedItemType()), "r");
             break;
             // The "networkequipment" right doesn't exist in Session/Rigths variable. It's actually "networking".
         // The "networkequipment" right doesn't exist in Session/Rigths variable. It's actually "networking".
         case "NetworkEquipment":
             $canedit = Session::haveRight("networking", "w");
             $canread = Session::haveRight("networking", "r");
             break;
         case "ComputerDisk":
         case "DeviceProcessor":
         case "DeviceMemory":
         case "DeviceMotherboard":
         case "DeviceNetworkCard":
         case "DeviceHardDrive":
         case "DeviceDrive":
         case "DeviceControl":
         case "DeviceGraphicCard":
         case "DeviceSoundCard":
         case "DeviceCase":
         case "DevicePowerSupply":
         case "DevicePci":
             $canedit = Session::haveRight("device", "w");
             $canread = Session::haveRight("device", "r");
             break;
         case "Supplier":
         case "Contact":
             $canedit = Session::haveRight("contact_enterprise", "w");
             $canread = Session::haveRight("contact_enterprise", "r");
             break;
         case "SoftwareVersion":
         case "SoftwareLicense":
             $canedit = Session::haveRight("software", "w");
             $canread = Session::haveRight("software", "r");
             break;
         case "Ticket":
             $canedit = Session::haveRight("update_ticket", "1");
             $canread = true;
             break;
     }
     if ($canread != true) {
         return false;
     }
     // Set target
     $target = $CFG_GLPI["root_doc"] . "/plugins/customfields/front/field.form.php";
     if (isset($options['target'])) {
         $target = $options['target'];
     }
     $itemType = $this->getType();
     $associatedItemType = $this->associatedItemType();
     $table = $itemType::getTable();
     $sql = "SELECT *\r\n\t  \t\t    FROM `{$table}`\r\n\t          WHERE `id` = {$id}";
     $result = $DB->query($sql);
     $associatedItemCustomValues = $DB->fetch_assoc($result);
     $DB->free_result($result);
     //Added
     $associatedTable = $associatedItemType::getTable();
     $entity = 0;
     if (!in_array($associatedItemType, array('ComputerDisk', 'NetworkPort', 'Entity', 'SoftwareVersion', 'SoftwareLicense'))) {
         $query = "SELECT entities_id\r\n                   FROM {$associatedTable} WHERE id= '{$id}'";
         $result = $DB->query($query);
         if ($result != false) {
             $number = $DB->numrows($result);
             if ($number == 1) {
                 $data = $DB->fetch_array($result);
                 $entity = $data['entities_id'];
             }
         }
     }
     $field_uses = false;
     // End of added code
     // Select customfield configuration
     $sql = "SELECT `label`, `system_name`, `data_type`, `default_value`,\r\n                     `entities`\r\n\t  \t\t    FROM `glpi_plugin_customfields_fields`\r\n\t    \t\t WHERE `deleted` = '0' AND `itemtype` = '{$associatedItemType}' \r\n\t\t\t    ORDER BY `sort_order` ASC, `label` ASC";
     $result = $DB->query($sql);
     $currentSectionName = '';
     echo "<form action='" . $target . "' method='post'>";
     echo "<table class='tab_cadre_fixe'>";
     while ($data = $DB->fetch_assoc($result)) {
         if ($data['entities'] != '*') {
             $entities = explode(',', $data['entities']);
             // don't process the field if it shouldn't be shown for this entity
             if (!in_array($entity, $entities)) {
                 continue;
             }
         }
         switch ($data['data_type']) {
             case 'sectionhead':
                 // Display section header
                 $currentSectionName = $data['label'];
                 echo "<tr><th colspan='2' class='center b'>" . $currentSectionName;
                 echo "</th></tr>";
                 break;
             default:
                 $field_uses = true;
                 // Label
                 if ($currentSectionName == '') {
                     $currentSectionName = "&nbsp;";
                     echo "<tr><th colspan='2' class='center b'>" . $currentSectionName;
                     echo "</th></tr>";
                 }
                 $fieldName = $data['system_name'];
                 echo "<tr><td>" . $data['label'] . "</td><td>";
                 // Check readonly and restricted
                 $readonly = false;
                 if (array_key_exists('restricted', $data) && $data['restricted']) {
                     $checkfield = $data['itemtype'] . '_' . $data['system_name'];
                     $prof = new pluginCustomfieldsProfile();
                     if (!$prof->fieldHaveRight($checkfield, 'r')) {
                         // User has no access right. Skip the field.
                         continue;
                     }
                     if (!$prof->fieldHaveRight($checkfield, 'w')) {
                         // User has read, but not write right. Set the field to
                         // readonly
                         $readonly = true;
                     }
                 }
                 // The current value comes from the data table
                 if ($data['data_type'] != 'sectionhead') {
                     $value = $associatedItemCustomValues[$fieldName];
                 }
                 // Display input widgets based on the data type
                 switch ($data['data_type']) {
                     case 'general':
                         # Single line input
                         if (!$readonly) {
                             echo '<input type="text" size="20" value="' . $value . '" name="' . $fieldName . '"/>';
                         } else {
                             plugin_customfields_showValue($value);
                         }
                         break;
                     case 'dropdown':
                         # Dropdown
                         if (!$readonly) {
                             $dropdown_obj = new PluginCustomfieldsDropdown();
                             $tmp = $dropdown_obj->find("system_name = '" . $data['system_name'] . "'");
                             $dropdown = array_shift($tmp);
                             Dropdown::show('PluginCustomfieldsDropdownsItem', array('condition' => $dropdown['id'] . " = plugin_customfields_dropdowns_id", 'name' => $fieldName, 'value' => $value, 'entity' => $_SESSION['glpiactive_entity']));
                         }
                         break;
                     case 'date':
                         # Date input
                         $editcalendar = !$readonly;
                         Html::showDateFormItem($fieldName, $value, true, $editcalendar);
                         break;
                     case 'money':
                         # Money input
                         if (!$readonly) {
                             echo '<input type="text" size="16" value="' . Html::formatNumber($value, true) . '" name="' . $fieldName . '"/>';
                         } else {
                             plugin_customfields_showValue(Html::formatNumber($value, true));
                         }
                         break;
                     case 'yesno':
                         # Checkbox
                         if (!$readonly) {
                             Dropdown::showYesNo($fieldName, $value);
                         } else {
                             plugin_customfields_showValue(Dropdown::getYesNo($fieldName, $value));
                         }
                         break;
                     case 'notes':
                         # Multiline input
                         if (!$readonly) {
                             echo '<textarea name="' . $fieldName . '" rows="4" cols="35">' . $value . '</textarea>';
                         } else {
                             plugin_customfields_showValue($value, 'height:6em;width:23em;');
                         }
                         break;
                     case 'number':
                         # Number
                         if (!$readonly) {
                             echo '<input type="text" size="10" value="' . $value . '" name="' . $fieldName . '"/>';
                         } else {
                             plugin_customfields_showValue($value);
                         }
                         break;
                 }
                 echo "</td></tr>";
         }
     }
     $DB->free_result($result);
     if ($field_uses) {
         if ($canedit) {
             echo "<tr class='tab_bg_1'>";
             echo "<td class='center' colspan='2'>";
             echo "<input type='hidden' name='id' value='{$id}'>";
             echo "<input type='hidden' name='customfielditemtype'\r\n               value='{$itemType}'>";
             echo "<input type='submit' name='update_customfield' value='" . _sx('button', 'Save') . "' class='submit'>";
             echo "</td></tr>";
         }
     } else {
         echo $LANG['plugin_customfields']['No_Fields'];
     }
     echo "</table>";
     Html::closeForm();
 }