コード例 #1
0
ファイル: publicFunc.php プロジェクト: pulse-project/pulse
function _inventory_baseEdit($FH, $mode)
{
    $username = $FH->getArrayOrPostValue("uid");
    $d = new DivForModule(_T("Entity right", "inventory"), "#DDF");
    $entities = getLocationAll(['min' => 0, 'filters' => array()]);
    $default_user_locations = array("1");
    $f = new Table();
    $d->push($f);
    if ($mode == 'edit') {
        $user_locations = getLocationsForUser($username);
        if (!count($user_locations)) {
            $user_locations = $default_user_locations;
        }
    } else {
        $user_locations = $default_user_locations;
    }
    $entities_select = new SelectItem("entitie[]");
    $entity_val = array();
    $entity_list = array();
    foreach ($entities['data'] as $entity) {
        $entity_list[$entity['id']] = $entity['Labelval'];
        $entity_val[$entity['id']] = $entity['id'];
    }
    $entities_select->setElements($entity_list);
    $entities_select->setElementsVal($entity_val);
    $entity_valT = array();
    foreach ($user_locations as $attr) {
        $fields = array($entities_select, new inventorybuttonTpl2('removeLine', _T('Remove', 'inventory'), 'removeLine', _T('Remove entity for user', 'inventory') . " : [" . $username . "]"));
        $values = array(strval($attr), '');
        $f->add(new TrFormElement(_T('Entity right', 'inventory'), new multifieldTpl($fields)), array("value" => $values, "required" => True));
    }
    // Add line button
    $addEntityRightBtn = new inventorybuttonTpl2('addLine', _T('Add entity right', 'inventory'), '', _T('Add entity right for user', 'inventory') . " : [" . $username . "]");
    $addEntityRightBtn->setClass('btnPrimary');
    $f->add(new TrFormElement('', $addEntityRightBtn), array());
    print <<<EOF
        <script type="text/javascript">
        jQuery(function(){
            modelLine = jQuery('.removeLine:first').parents('tr:first').clone();
            // Remove line button
            jQuery('.removeLine').click(function(){
                if (jQuery('.removeLine').length > 1)
                    jQuery(this).parents('tr:first').remove();
                else
                jQuery('#entitie option[value="1"]').prop('selected', true);
            });
            // Add line button
            jQuery('#addLine').click(function(){
                var newline = modelLine.clone().insertBefore(jQuery(this).parents('tr:first'));
                newline.find('.removeLine').click(function(){
                    if (jQuery('.removeLine').length > 1)
                        jQuery(this).parents('tr:first').remove();
                });
            });
        });
        </script>
EOF;
    return $d;
}
コード例 #2
0
ファイル: publicFunc.php プロジェクト: pulse-project/pulse
function _glpi_baseEdit($FH, $mode)
{
    $username = $FH->getArrayOrPostValue("uid");
    // Default profile is SuperAdmin on root entity
    // with recursive rights
    $default_user_locations = array(array('entity_id' => 1, 'is_dynamic' => 0, 'is_recursive' => 1, 'profile' => 4));
    if ($mode == 'edit') {
        $user_locations = getLocationsForUser($username);
        // If not user profile, switching to default
        if (!count($user_locations)) {
            $user_locations = $default_user_locations;
        }
    } else {
        // Default profile is SuperAdmin on root entity
        // with recursive rights
        $user_locations = $default_user_locations;
    }
    $d = new DivForModule(_T("Entity attributes", "glpi"), "#DDF");
    $f = new Table();
    $d->push($f);
    // =================================
    // Entity select
    // =================================
    $entities_select = new SelectItem("entities[]");
    $entities = getUserLocations();
    $entity_list = array();
    foreach ($entities as $entity) {
        $id = str_replace('UUID', '', $entity['uuid']);
        $entity_list[$id] = $entity['name'];
    }
    $entities_select->setElements(array_values($entity_list));
    $entities_select->setElementsVal(array_keys($entity_list));
    // =================================
    // Profiles select
    // =================================
    $profiles_select = new SelectItem("profiles[]");
    $profiles = getAllUserProfiles();
    $profiles_select->setElements(array_values($profiles));
    $profiles_select->setElementsVal(array_keys($profiles));
    // =================================
    // Recursive select
    // =================================
    $recursive_select = new SelectItem("is_recursive[]");
    $recursive_select->setElements(array('Recursive', 'Not recursive'));
    $recursive_select->setElementsVal(array('1', '0'));
    // =================================
    // Recursive select
    // =================================
    $dynamic_select = new SelectItem("is_dynamic[]");
    $dynamic_select->setElements(array('Dynamic', 'Not dynamic'));
    $dynamic_select->setElementsVal(array('1', '0'));
    foreach ($user_locations as $attr) {
        // Fields
        $fields = array($entities_select, $profiles_select, $recursive_select, $dynamic_select, new buttonTpl2('removeLine', _T('Remove', 'glpi'), 'removeLine'));
        $values = array($attr['entity_id'], $attr['profile'], $attr['is_recursive'], $attr['is_dynamic'], '');
        $f->add(new TrFormElement(_T('Entity right', 'glpi'), new multifieldTpl($fields)), array("value" => $values, "required" => True));
    }
    // Add line button
    $addEntityRightBtn = new buttonTpl2('addLine', _T('Add entity right', 'backuppc'));
    $addEntityRightBtn->setClass('btnPrimary');
    $f->add(new TrFormElement('', $addEntityRightBtn), array());
    print <<<EOF
<script type="text/javascript">
jQuery(function(){
    
    modelLine = jQuery('.removeLine:first').parents('tr:first').clone();
        
     // Remove line button
     jQuery('.removeLine').click(function(){
         if (jQuery('.removeLine').length > 1)
             jQuery(this).parents('tr:first').remove();
     });
     
     
     // Add line button
     jQuery('#addLine').click(function(){
        var newline = modelLine.clone().insertBefore(jQuery(this).parents('tr:first'));
         newline.find('input[type=text]').val('');
         newline.find('textarea').val('');

         newline.find('.removeLine').click(function(){
            if (jQuery('.removeLine').length > 1)
                jQuery(this).parents('tr:first').remove();
        });
     });
    
});
window.toto=1;
</script>
EOF;
    return $f;
}