Dropdown::showPrivatePublicSwitch PHP Method

showPrivatePublicSwitch() static public method

Private / Public switch for items which may be assign to a user and/or an entity
static public showPrivatePublicSwitch ( $is_private, $entity, $is_recursive )
$is_private default is private ?
$entity working entity ID
$is_recursive is the item recursive ?
    static function showPrivatePublicSwitch($is_private, $entity, $is_recursive)
    {
        global $CFG_GLPI;
        $rand = mt_rand();
        echo "<script type='text/javascript' >\n";
        echo "function setPrivate{$rand}() {\n";
        $params = array('is_private' => 1, 'is_recursive' => $is_recursive, 'entities_id' => $entity, 'rand' => $rand);
        Ajax::updateItemJsCode('private_switch' . $rand, $CFG_GLPI["root_doc"] . "/ajax/private_public.php", $params);
        echo "};";
        echo "function setPublic{$rand}() {\n";
        $params = array('is_private' => 0, 'is_recursive' => $is_recursive, 'entities_id' => $entity, 'rand' => $rand);
        Ajax::updateItemJsCode('private_switch' . $rand, $CFG_GLPI["root_doc"] . "/ajax/private_public.php", $params);
        echo "};";
        echo "</script>";
        echo "<span id='private_switch{$rand}'>";
        $_POST['rand'] = $rand;
        $_POST['is_private'] = $is_private;
        $_POST['is_recursive'] = $is_recursive;
        $_POST['entities_id'] = $entity;
        include GLPI_ROOT . "/ajax/private_public.php";
        echo "</span>\n";
        return $rand;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Print the bookmark form
  *
  * @param $ID        integer ID of the item
  * @param $options   array
  *     - target for the Form
  *     - type bookmark type when adding a new bookmark
  *     - url when adding a new bookmark
  *     - itemtype when adding a new bookmark
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $ID = $this->fields['id'];
     // Only an edit form : always check w right
     if ($ID > 0) {
         $this->check($ID, UPDATE);
     } else {
         $this->check(-1, CREATE);
     }
     echo '<br>';
     echo "<form method='post' name='form_save_query' action='" . $_SERVER['PHP_SELF'] . "'>";
     echo "<div class='center'>";
     if (isset($options['itemtype'])) {
         echo "<input type='hidden' name='itemtype' value='" . $options['itemtype'] . "'>";
     }
     if (isset($options['type']) && $options['type'] != 0) {
         echo "<input type='hidden' name='type' value='" . $options['type'] . "'>";
     }
     if (isset($options['url'])) {
         echo "<input type='hidden' name='url' value='" . rawurlencode($options['url']) . "'>";
     }
     echo "<table class='tab_cadre' width='" . self::WIDTH . "px'>";
     echo "<tr><th>&nbsp;</th><th>";
     if ($ID > 0) {
         //TRANS: %1$s is the Itemtype name and $2$d the ID of the item
         printf(__('%1$s - ID %2$d'), $this->getTypeName(1), $ID);
     } else {
         _e('New item');
     }
     echo "</th></tr>";
     echo "<tr><td class='tab_bg_1'>" . __('Name') . "</td>";
     echo "<td class='tab_bg_1'>";
     Html::autocompletionTextField($this, "name", array('user' => $this->fields["users_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Type') . "</td>";
     echo "<td>";
     if (static::canCreate()) {
         Dropdown::showPrivatePublicSwitch($this->fields["is_private"], $this->fields["entities_id"], $this->fields["is_recursive"]);
     } else {
         if ($this->fields["is_private"]) {
             _e('Private');
         } else {
             _e('Public');
         }
     }
     echo "</td></tr>";
     if ($ID <= 0) {
         // add
         echo "<tr>";
         echo "<td class='tab_bg_2 top' colspan='2'>";
         echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "'>";
         echo "<div class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</div></td></tr>";
     } else {
         echo "<tr>";
         echo "<td class='tab_bg_2 top' colspan='2'>";
         echo "<input type='hidden' name='id' value='{$ID}'>";
         echo "<input type='submit' name='update' value=\"" . __s('Save') . "\" class='submit'>";
         echo "</td></tr><tr><td class='tab_bg_2 right' colspan='2'>";
         echo "<input type='submit' name='purge' value=\"" . _sx('button', 'Delete permanently') . "\"\n                class='submit'>";
         echo "</td></tr>";
     }
     echo "</table></div>";
     Html::closeForm();
 }
All Usage Examples Of Dropdown::showPrivatePublicSwitch