CommonDBTM::showFormButtons PHP Method

showFormButtons() public method

Display a 2 columns Footer for Form buttons Close the form is user can edit
public showFormButtons ( $options = [] )
$options array of possible options: - withtemplate : 1 for newtemplate, 2 for newobject from template - colspan for each column (default 2) - candel : set to false to hide "delete" button - canedit : set to false to hide all buttons - addbuttons : array of buttons to add
    function showFormButtons($options = array())
    {
        global $CFG_GLPI;
        // for single object like config
        if (isset($this->fields['id'])) {
            $ID = $this->fields['id'];
        } else {
            $ID = 1;
        }
        $params['colspan'] = 2;
        $params['withtemplate'] = '';
        $params['candel'] = true;
        $params['canedit'] = true;
        $params['addbuttons'] = array();
        $params['formfooter'] = null;
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $params[$key] = $val;
            }
        }
        if ($params['formfooter'] === null) {
            $this->showDates($params);
        }
        if (!$params['canedit'] || !$this->canEdit($ID)) {
            echo "</table></div>";
            // Form Header always open form
            if (!$params['canedit']) {
                Html::closeForm();
            }
            return false;
        }
        echo "<tr class='tab_bg_2'>";
        if ($params['withtemplate'] || $this->isNewID($ID)) {
            echo "<td class='center' colspan='" . $params['colspan'] * 2 . "'>";
            if ($ID <= 0 || $params['withtemplate'] == 2) {
                echo Html::submit(_x('button', 'Add'), array('name' => 'add'));
            } else {
                //TRANS : means update / actualize
                echo Html::submit(_x('button', 'Save'), array('name' => 'update'));
            }
        } else {
            if ($params['candel'] && !$this->can($ID, DELETE) && !$this->can($ID, PURGE)) {
                $params['candel'] = false;
            }
            if ($params['canedit'] && $this->can($ID, UPDATE)) {
                echo "<td class='center' colspan='" . $params['colspan'] * 2 . "'>\n";
                echo Html::submit(_x('button', 'Save'), array('name' => 'update'));
            }
            if ($params['candel']) {
                if ($params['canedit'] && $this->can($ID, UPDATE)) {
                    echo "</td></tr><tr class='tab_bg_2'>\n";
                }
                if ($this->isDeleted()) {
                    if ($this->can($ID, DELETE)) {
                        echo "<td class='right' colspan='" . $params['colspan'] * 2 . "' >\n";
                        echo Html::submit(_x('button', 'Restore'), array('name' => 'restore'));
                    }
                    if ($this->can($ID, PURGE)) {
                        echo "<span class='very_small_space'>";
                        if (in_array($this->getType(), Item_Devices::getConcernedItems())) {
                            Html::showToolTip(__('Check to keep the devices while deleting this item'));
                            echo "&nbsp;";
                            echo "<input type='checkbox' name='keep_devices' value='1'";
                            if (!empty($_SESSION['glpikeep_devices_when_purging_item'])) {
                                echo " checked";
                            }
                            echo ">&nbsp;";
                        }
                        echo Html::submit(_x('button', 'Delete permanently'), array('name' => 'purge'));
                        echo "</span>";
                    }
                } else {
                    echo "<td class='right' colspan='" . $params['colspan'] * 2 . "' >\n";
                    // If maybe dynamic : do not take into account  is_deleted  field
                    if (!$this->maybeDeleted() || $this->useDeletedToLockIfDynamic()) {
                        if ($this->can($ID, PURGE)) {
                            echo Html::submit(_x('button', 'Delete permanently'), array('name' => 'purge', 'confirm' => __('Confirm the final deletion?')));
                        }
                    } else {
                        if (!$this->isDeleted() && $this->can($ID, DELETE)) {
                            echo Html::submit(_x('button', 'Put in dustbin'), array('name' => 'delete'));
                        }
                    }
                }
            }
            if ($this->isField('date_mod')) {
                echo "<input type='hidden' name='_read_date_mod' value='" . $this->getField('date_mod') . "'>";
            }
        }
        if (!$this->isNewID($ID)) {
            echo "<input type='hidden' name='id' value='{$ID}'>";
        }
        echo "</td>";
        echo "</tr>\n";
        if ($params['canedit'] && count($params['addbuttons'])) {
            echo "<tr class='tab_bg_2'>";
            if ($params['colspan'] * 2 - count($params['addbuttons']) > 0) {
                echo "<td colspan='" . ($params['colspan'] * 2 - count($params['addbuttons'])) . "'>&nbsp;" . "</td>";
            }
            foreach ($params['addbuttons'] as $key => $val) {
                echo "<td><input class='submit' type='submit' name='{$key}' value=\"" . Html::entities_deep($val) . "\"></td>";
            }
            echo "</tr>";
        }
        // Close for Form
        echo "</table></div>";
        Html::closeForm();
    }

Usage Example

示例#1
0
 /**
  * @since version 0.90
  *
  * @see CommonDBTM::showFormButtons()
  **/
 function showFormButtons($options = array())
 {
     global $CFG_GLPI;
     if (isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] != "central") {
         return parent::showFormButtons($options);
     }
     // for single object like config
     $ID = 1;
     if (isset($this->fields['id'])) {
         $ID = $this->fields['id'];
     }
     $params['colspan'] = 2;
     $params['candel'] = true;
     $params['canedit'] = true;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     if (!$this->isNewID($ID)) {
         echo "<input type='hidden' name='id' value='{$ID}'>";
     }
     echo "<tr class='tab_bg_2'>";
     echo "<td class='center' colspan='" . $params['colspan'] * 2 . "'>";
     if ($this->isNewID($ID)) {
         echo Ticket::getSplittedSubmitButtonHtml($this->fields['tickets_id'], 'add');
         //         echo "<input type='hidden' name='id' value='$ID'>";
     } else {
         if ($params['candel'] && !$this->can($ID, DELETE) && !$this->can($ID, PURGE)) {
             $params['candel'] = false;
         }
         if ($params['canedit'] && $this->can($ID, UPDATE)) {
             echo Ticket::getSplittedSubmitButtonHtml($this->fields['tickets_id'], 'update');
             echo "</td></tr><tr class='tab_bg_2'>\n";
         }
         if ($params['candel']) {
             echo "<td class='right' colspan='" . $params['colspan'] * 2 . "' >\n";
             if ($this->can($ID, PURGE)) {
                 echo Html::submit(_x('button', 'Delete permanently'), array('name' => 'purge', 'confirm' => __('Confirm the final deletion?')));
             }
         }
         if ($this->isField('date_mod')) {
             echo "<input type='hidden' name='_read_date_mod' value='" . $this->getField('date_mod') . "'>";
         }
     }
     echo "</td></tr></table></div>";
     Html::closeForm();
 }
CommonDBTM