$locations_select = new SelectItemtitle("target_location[]", _T('entities list', 'inventory')); $location_list = array(); foreach ($entity['data'] as $location) { $location_list[$location['id']] = $location['Label']; } $locations_select->setElements(array_values($location_list)); $locations_select->setElementsVal(array_keys($location_list)); $pattern_input = new InputTplTitle('patterns[]', _T('regular expression or value', 'inventory') . "\n" . _T('must not contain space character', 'inventory') . "\n"); for ($i = 0; $i < count($rule); $i++) { // Fields//$criteria_select, $fields = array(new SpanElement("<br>"), $locations_select, new SpanElement("<br>"), $selectOperatorType, new SpanElement("<br>"), $operator_select, new SpanElement("<br>"), $pattern_input, new SpanElement("<br>"), new buttonTpl2('removeLine', _T('Remove', 'inventory'), 'removeLine')); $values = array("", locationtoid($entity, $rule[$i]['entitie']), "", $rule[$i]['operand1'], "", $rule[$i]['operator'], "", $rule[$i]['operand2'], ""); $f->add(new TrFormElement(_T('Criterion', 'inventory'), new multifieldTpl($fields)), array("value" => $values, "required" => True)); } // Add line button $addEntityRightBtn = new buttonTpl2('addLine', _T('Add criterion', 'inventory')); $addEntityRightBtn->setClass('btnPrimary'); $f->add(new TrFormElement('', $addEntityRightBtn), array()); $f->add(new HiddenTpl("numRuleadd"), array("value" => $newnumRule, "hide" => True)); $f->pop(); $f->addValidateButton("bconfirm"); $f->display(); ?> <script type="text/javascript"> jQuery(function(){ modelLine = jQuery('.removeLine:first').parents('tr:first').clone(); // Remove line button jQuery('.removeLine').click(function(){
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; }