jsAjaxDropdown() static public méthode

Create Ajax dropdown to clean JS
static public jsAjaxDropdown ( $name, $field_id, $url, $params = [] ) : String
$name
$field_id string id of the dom element
$url string URL to get datas
$params array of parameters must contains : - 'value' : default value selected - 'valuename' : default name of selected value
Résultat String
ocsinventoryng is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
// Make a select box
if (isset($_POST["itemtype"])) {
    $table = getTableForItemType($_POST["itemtype"]);
    $rand = mt_rand();
    if (isset($_POST["rand"])) {
        $rand = $_POST["rand"];
    }
    echo "<input type='hidden' name='tolink_itemtype[" . $_POST["id"] . "]' value='" . $_POST["itemtype"] . "'>";
    echo "<br>";
    $field_id = Html::cleanId("dropdown_" . $_POST['myname'] . $rand);
    $p = array('itemtype' => $_POST["itemtype"], 'table' => $table, 'myname' => $_POST["myname"], 'rand' => $_POST["rand"]);
    if (isset($_POST["used"]) && !empty($_POST["used"])) {
        if (isset($_POST["used"][$_POST["itemtype"]])) {
            $p["used"] = $_POST["used"][$_POST["itemtype"]];
        }
    }
    echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/ajax/getDropdownFindItem.php", $p);
}
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
// Make a select box
if (isset($_POST["itemtype"]) && CommonITILObject::isPossibleToAssignType($_POST["itemtype"])) {
    $table = getTableForItemType($_POST["itemtype"]);
    $rand = mt_rand();
    // Message for post-only
    if (!isset($_POST["admin"]) || $_POST["admin"] == 0) {
        echo "<br>" . __('Enter the first letters (user, item name, serial or asset number)');
    }
    echo "<br>";
    $field_id = Html::cleanId("dropdown_" . $_POST['myname'] . $rand);
    $p = array('itemtype' => $_POST["itemtype"], 'entity_restrict' => $_POST['entity_restrict'], 'table' => $table, 'myname' => $_POST["myname"]);
    if (isset($_POST["used"]) && !empty($_POST["used"])) {
        if (isset($_POST["used"][$_POST["itemtype"]])) {
            $p["used"] = $_POST["used"][$_POST["itemtype"]];
        }
    }
    echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownFindNum.php", $p);
    // Auto update summary of active or just solved tickets
    $params = array('items_id' => '__VALUE__', 'itemtype' => $_POST['itemtype']);
    Ajax::updateItemOnSelectEvent($field_id, "item_ticket_selection_information", $CFG_GLPI["root_doc"] . "/ajax/ticketiteminformation.php", $params);
}
Exemple #3
0
 /**
  * Print out an HTML "<select>" for a dropdown with preselected value
  *
  * @param $myname             the name of the HTML select
  * @param $value              the preselected value we want (default 0)
  * @param $locations_id       default location ID for search (default -1)
  * @param $display_comment    display the comment near the dropdown (default 1)
  * @param $entity_restrict    Restrict to a defined entity(default -1)
  * @param $devtype            (default '')
  *
  * @return nothing (display the select box)
  **/
 static function dropdownNetpoint($myname, $value = 0, $locations_id = -1, $display_comment = 1, $entity_restrict = -1, $devtype = '')
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $name = Dropdown::EMPTY_VALUE;
     $comment = "";
     if (empty($value)) {
         $value = 0;
     }
     if ($value > 0) {
         $tmpname = Dropdown::getDropdownName("glpi_netpoints", $value, 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
         }
     }
     $field_id = Html::cleanId("dropdown_" . $myname . $rand);
     $param = array('value' => $value, 'valuename' => $name, 'entity_restrict' => $entity_restrict, 'devtype' => $devtype, 'locations_id' => $locations_id);
     echo Html::jsAjaxDropdown($myname, $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownNetpoint.php", $param);
     // Display comment
     if ($display_comment) {
         $comment_id = Html::cleanId("comment_" . $myname . $rand);
         Html::showToolTip($comment, array('contentid' => $comment_id));
         $item = new self();
         if ($item->canCreate()) {
             echo "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;' " . "onClick=\"" . Html::jsGetElementbyID('netpoint' . $rand) . ".dialog('open');\">";
             Ajax::createIframeModalWindow('netpoint' . $rand, $item->getFormURL());
         }
         $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_netpoints");
         echo Ajax::updateItemOnSelectEvent($field_id, $comment_id, $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
     }
     return $rand;
 }
Exemple #4
0
 /**
  * Make a select box with all glpi users where select key = name
  *
  * @param $options array of possible options:
  *    - name           : string / name of the select (default is users_id)
  *    - value
  *    - right          : string / limit user who have specific right :
  *                           id -> only current user (default case);
  *                           interface -> central ;
  *                           all -> all users ;
  *                           specific right like Ticket::READALL, CREATE.... (is array passed one of all passed right is needed)
  *    - comments       : boolean / is the comments displayed near the dropdown (default true)
  *    - entity         : integer or array / restrict to a defined entity or array of entities
  *                        (default -1 : no restriction)
  *    - entity_sons    : boolean / if entity restrict specified auto select its sons
  *                        only available if entity is a single value not an array(default false)
  *    - all            : Nobody or All display for none selected
  *                           all=0 (default) -> Nobody
  *                           all=1 -> All
  *                           all=-1-> nothing
  *    - rand           : integer / already computed rand value
  *    - toupdate       : array / Update a specific item on select change on dropdown
  *                        (need value_fieldname, to_update, url
  *                        (see Ajax::updateItemOnSelectEvent for information)
  *                        and may have moreparams)
  *    - used           : array / Already used items ID: not to display in dropdown (default empty)
  *    - ldap_import
  *    - on_change      : string / value to transmit to "onChange"
  *    - display        : boolean / display or get string (default true)
  *    - width          : specific width needed (default 80%)
  *    - specific_tags  : array of HTML5 tags to add the the field
  *    - url            : url of the ajax php code which should return the json data to show in
  *                        the dropdown (default /ajax/getDropdownUsers.php)
  *
  * @return rand value if displayed / string if not
  **/
 static function dropdown($options = array())
 {
     global $DB, $CFG_GLPI;
     // Default values
     $p['name'] = 'users_id';
     $p['value'] = '';
     $p['right'] = 'id';
     $p['all'] = 0;
     $p['on_change'] = '';
     $p['comments'] = 1;
     $p['width'] = '80%';
     $p['entity'] = -1;
     $p['entity_sons'] = false;
     $p['used'] = array();
     $p['ldap_import'] = false;
     $p['toupdate'] = '';
     $p['rand'] = mt_rand();
     $p['display'] = true;
     $p['_user_index'] = 0;
     $p['specific_tags'] = array();
     $p['url'] = $CFG_GLPI['root_doc'] . "/ajax/getDropdownUsers.php";
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     // check default value (in case of multiple observers)
     if (is_array($p['value'])) {
         $p['value'] = $p['value'][$p['_user_index']];
     }
     // Check default value for dropdown : need to be a numeric
     if (strlen($p['value']) == 0 || !is_numeric($p['value'])) {
         $p['value'] = 0;
     }
     $output = '';
     if (!($p['entity'] < 0) && $p['entity_sons']) {
         if (is_array($p['entity'])) {
             $output .= "entity_sons options is not available with array of entity";
         } else {
             $p['entity'] = getSonsOf('glpi_entities', $p['entity']);
         }
     }
     // Make a select box with all glpi users
     $user = getUserName($p['value'], 2);
     $view_users = self::canView();
     if (!empty($p['value']) && $p['value'] > 0) {
         $default = $user["name"];
     } else {
         if ($p['all']) {
             $default = __('All');
         } else {
             $default = Dropdown::EMPTY_VALUE;
         }
     }
     $field_id = Html::cleanId("dropdown_" . $p['name'] . $p['rand']);
     $param = array('value' => $p['value'], 'valuename' => $default, 'width' => $p['width'], 'all' => $p['all'], 'right' => $p['right'], 'on_change' => $p['on_change'], 'used' => $p['used'], 'entity_restrict' => $p['entity'], 'specific_tags' => $p['specific_tags']);
     $output = Html::jsAjaxDropdown($p['name'], $field_id, $p['url'], $param);
     // Display comment
     if ($p['comments']) {
         $comment_id = Html::cleanId("comment_" . $p['name'] . $p['rand']);
         $link_id = Html::cleanId("comment_link_" . $p["name"] . $p['rand']);
         if (!$view_users) {
             $user["link"] = '';
         } else {
             if (empty($user["link"])) {
                 $user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php";
             }
         }
         $output .= "&nbsp;" . Html::showToolTip($user["comment"], array('contentid' => $comment_id, 'display' => false, 'link' => $user["link"], 'linkid' => $link_id));
         $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_users");
         if ($view_users) {
             $paramscomment['withlink'] = $link_id;
         }
         $output .= Ajax::updateItemOnSelectEvent($field_id, $comment_id, $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
     }
     $output .= Ajax::commonDropdownUpdateItem($p, false);
     if (Session::haveRight('user', self::IMPORTEXTAUTHUSERS) && $p['ldap_import'] && Entity::isEntityDirectoryConfigured($_SESSION['glpiactive_entity'])) {
         $output .= "<img alt='' title=\"" . __s('Import a user') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                      onClick=\"" . Html::jsGetElementbyID('userimport' . $p['rand']) . ".dialog('open');\">";
         $output .= Ajax::createIframeModalWindow('userimport' . $p['rand'], $CFG_GLPI["root_doc"] . "/front/ldap.import.php?entity=" . $_SESSION['glpiactive_entity'], array('title' => __('Import a user'), 'display' => false));
     }
     if ($p['display']) {
         echo $output;
         return $p['rand'];
     }
     return $output;
 }
Exemple #5
0
Session::checkCentralAccess();
// Make a select box
if ($_POST["idtable"] && class_exists($_POST["idtable"])) {
    $table = getTableForItemType($_POST["idtable"]);
    // Link to user for search only > normal users
    $link = "getDropdownValue.php";
    if ($_POST["idtable"] == 'User') {
        $link = "getDropdownUsers.php";
    }
    $rand = mt_rand();
    $field_id = Html::cleanId("dropdown_" . $_POST["name"] . $rand);
    $p = array('value' => 0, 'valuename' => Dropdown::EMPTY_VALUE, 'itemtype' => $_POST["idtable"], 'display_emptychoice' => true, 'displaywith' => array('otherserial', 'serial'));
    if (isset($_POST['value'])) {
        $p['value'] = $_POST['value'];
    }
    if (isset($_POST['entity_restrict'])) {
        $p['entity_restrict'] = $_POST['entity_restrict'];
    }
    if (isset($_POST['condition'])) {
        $p['condition'] = $_POST['condition'];
    }
    echo Html::jsAjaxDropdown($_POST["name"], $field_id, $CFG_GLPI['root_doc'] . "/ajax/" . $link, $p);
    if (!empty($_POST['showItemSpecificity'])) {
        $params = array('items_id' => '__VALUE__', 'itemtype' => $_POST["idtable"]);
        if (isset($_POST['entity_restrict'])) {
            $params['entity_restrict'] = $_POST['entity_restrict'];
        }
        Ajax::updateItemOnSelectEvent($field_id, "showItemSpecificity_" . $_POST["name"] . "{$rand}", $_POST['showItemSpecificity'], $params);
        echo "<br><span id='showItemSpecificity_" . $_POST["name"] . "{$rand}'>&nbsp;</span>\n";
    }
}
Exemple #6
0
 /**
  * Dropdown numbers
  *
  * @since version 0.84
  *
  * @param $myname          select name
  * @param $options   array of additionnal options :
  *     - value              default value (default 0)
  *     - rand               random value
  *     - min                min value (default 0)
  *     - max                max value (default 100)
  *     - step               step used (default 1)
  *     - toadd     array    of values to add at the beginning
  *     - unit      string   unit to used
  *     - display   boolean  if false get string
  *     - width              specific width needed (default 80%)
  *     - on_change string / value to transmit to "onChange"
  *     - used      array / Already used items ID: not to display in dropdown (default empty)
  **/
 static function showNumber($myname, $options = array())
 {
     global $CFG_GLPI;
     $p['value'] = 0;
     $p['rand'] = mt_rand();
     $p['min'] = 0;
     $p['max'] = 100;
     $p['step'] = 1;
     $p['toadd'] = array();
     $p['unit'] = '';
     $p['display'] = true;
     $p['width'] = '';
     $p['on_change'] = '';
     $p['used'] = array();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     if ($p['value'] < $p['min'] && !isset($p['toadd'][$p['value']])) {
         $p['value'] = $p['min'];
     }
     $field_id = Html::cleanId("dropdown_" . $myname . $p['rand']);
     if (!isset($p['toadd'][$p['value']])) {
         $valuename = self::getValueWithUnit($p['value'], $p['unit']);
     } else {
         $valuename = $p['toadd'][$p['value']];
     }
     $param = array('value' => $p['value'], 'valuename' => $valuename, 'width' => $p['width'], 'on_change' => $p['on_change'], 'used' => $p['used'], 'unit' => $p['unit'], 'min' => $p['min'], 'max' => $p['max'], 'step' => $p['step'], 'toadd' => $p['toadd']);
     $out = Html::jsAjaxDropdown($myname, $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownNumber.php", $param);
     if ($p['display']) {
         echo $out;
         return $p['rand'];
     }
     return $out;
 }
Exemple #7
0
 /**
  * Make a select box for connections
  *
  * @param $itemtype               type to connect
  * @param $fromtype               from where the connection is
  * @param $myname                 select name
  * @param $entity_restrict        Restrict to a defined entity (default = -1)
  * @param $onlyglobal             display only global devices (used for templates) (default 0)
  * @param $used             array Already used items ID: not to display in dropdown
  *
  * @return nothing (print out an HTML select box)
  */
 static function dropdownConnect($itemtype, $fromtype, $myname, $entity_restrict = -1, $onlyglobal = 0, $used = array())
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $field_id = Html::cleanId("dropdown_" . $myname . $rand);
     $param = array('entity_restrict' => $entity_restrict, 'fromtype' => $fromtype, 'itemtype' => $itemtype, 'onlyglobal' => $onlyglobal, 'used' => $used);
     echo Html::jsAjaxDropdown($myname, $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownConnect.php", $param);
     return $rand;
 }
(at your option) any later version.

Racks is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Racks. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Plugin::load('racks', true);
if (isset($_POST["modeltable"]) && !empty($_POST["modeltable"])) {
    $rand = mt_rand();
    $itemtype = substr($_POST['modeltable'], 0, -5);
    $modelfield = getForeignKeyFieldForTable(getTableForItemType($_POST['modeltable']));
    $table = getTableForItemType($itemtype);
    $params = array('searchText' => '__VALUE__', 'modeltable' => $_POST["modeltable"], 'modelfield' => $modelfield, 'itemtype' => $itemtype, 'rand' => $rand, 'width' => '500', 'myname' => $_POST["myname"]);
    if (isset($_POST['value'])) {
        $params['value'] = $_POST['value'];
        $params['valuename'] = "-----";
    }
    if (isset($_POST['entity_restrict'])) {
        $params['entity_restrict'] = $_POST['entity_restrict'];
    }
    $field_id = Html::cleanId($_POST['myname'] . $rand);
    echo Html::jsAjaxDropdown($_POST["myname"], $field_id, $CFG_GLPI['root_doc'] . "/plugins/racks/ajax/dropdownValue.php", $params);
}
        $objeto = new $itemtype();
        $table = $objeto->getTable();
    }
    //$use_ajax=$CFG_GLPI['use_ajax'];
    //echo $CFG_GLPI['use_ajax'];
    $tabletype = PluginRelationRelation::getNombreClaseRelacionada($_POST['type_relations']);
    /*
    switch ($tabletype){
    	case "Group" :
    		$use_ajax=0;
    		break;
    	case "User" :
    		$use_ajax=0;
    		break;			
    	default:
    		$use_ajax=$CFG_GLPI['use_ajax'];
    		break;
    }	
    */
    //echo $tabletype."-".$use_ajax;
    //$params = array();
    $params = array('searchText' => '__VALUE__', 'type_relations' => $_POST['type_relations'], 'entity_restrict' => $_POST['entity_restrict'], 'itemtype' => $_POST['itemtype'], 'rand' => $_POST['rand'], 'myname' => $_POST['myname']);
    //'used'=>$_POST['used']
    //print_r($params);
    //Session::addMessageAfterRedirect($_POST , false, ERROR);
    $field_id = Html::cleanId("show_" . $_POST['myname'] . $rand);
    //$field_id = "show_".$_POST['myname'].$rand;
    //$default='<select name="'.$_POST['myname'].'"><option value="0">------</option></select>';
    //Ajax::dropdown($use_ajax,'/plugins/relation/ajax/dropdownValue.php',$params,$default,$rand);
    echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/plugins/relation/ajax/dropdownValue.php", $params);
}