From 50ecb678c16a8e22f8b668631c97e52be780a350 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 5 Jan 2010 09:05:05 +0000 Subject: [PATCH] Updated opsiLicenses git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15036 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../opsiLicenses/class_divListLicenses.inc | 196 --------- .../opsiLicenses/class_filterOpsiLicense.inc | 45 ++ .../admin/opsiLicenses/class_opsiLicenses.inc | 396 +++--------------- gosa-plugins/opsi/admin/opsiLicenses/main.inc | 37 +- .../admin/opsiLicenses/opsiLicense-filter.tpl | 33 ++ .../admin/opsiLicenses/opsiLicense-filter.xml | 40 ++ .../admin/opsiLicenses/opsiLicense-list.tpl | 31 ++ .../admin/opsiLicenses/opsiLicense-list.xml | 143 +++++++ 8 files changed, 361 insertions(+), 560 deletions(-) delete mode 100644 gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc create mode 100644 gosa-plugins/opsi/admin/opsiLicenses/class_filterOpsiLicense.inc create mode 100644 gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.tpl create mode 100644 gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.xml create mode 100644 gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.tpl create mode 100644 gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.xml diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc deleted file mode 100644 index b2b2864ab..000000000 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc +++ /dev/null @@ -1,196 +0,0 @@ -parent = $parent; - $this->ui = get_userinfo(); - - // Dynamic action col, depending on snapshot icons - $action_col_size = 90; - if($this->parent->snapshotEnabled()){ - $action_col_size += 38; - } - - // Set list strings - $this->SetTitle(_("List of license pools")); - $this->SetSummary(_("List of license pools")); - $this->EnableAplhabet(true); - - // Result page will look like a headpage - $this->SetHeadpageMode(); - - // Disable buttonsm - $this->EnableCloseButton(false); - $this->EnableSaveButton (false); - - // Add checkbox: Toggle all selected / deselected - $chk = ""; - - // Set Page col headers - $this->AddHeader(array("string" => $chk,"attach"=>"style='width:20px;'")); - $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); - $this->AddHeader(array("string" => _("License pools"), "attach" => "style=''")); - $this->AddHeader(array("string" => _("Actions"), - "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'")); - - // Add regex user input field - $this->AddRegex ("Regex", _("Regular expression for matching license pools"), "*" , true); - } - - - function GenHeader() - { - /* Get all departments within this subtree */ - $ui= get_userinfo(); - $first = ""; - $found = FALSE; - $base = $this->config->current['BASE']; - $options = $this->create_department_list($this->module); - - /* Get copy & paste icon */ - $acls = $ui->get_permissions($this->selectedBase,"opsi/licenseGeneric"); - $acl_all= $ui->has_complete_category_acls($this->selectedBase,"opsi"); - - /* Add default header */ - $listhead = MultiSelectWindow::get_default_header(false); - - /* Create Layers menu */ - $s = ".|"._("Actions")."|\n"; - - /* Append create options */ - if(preg_match("/c/",$acls)) { - $s .= "..|". - " "._("Create")."|\n"; - $s.= "...|". - " "._("License")."|license_new|\n"; - } - - /* Multiple options */ - $s.= "..|---|\n"; - - if(preg_match("/d/",$acls)) { - $s.= "..|". - " "._("Remove")."|"."remove_multiple_licenses|\n"; - } - - $this->SetDropDownHeaderMenu($s); - $this->SetListHeader($listhead); - } - - - function execute() - { - $this->ClearElementsList(); - $this->GenHeader(); - } - - function setEntries($list) - { - // Defining Links - $editlink = "%s"; - - // Dynamic action col, depending on snapshot icons - $action_col_size = 90; - if($this->parent->snapshotEnabled()){ - $action_col_size += 38; - } - - $ui = get_userinfo(); - - // Assigning licenses - foreach($list as $key => $val){ - - // Get object permissions - $acl = $ui->get_permissions($val['dn'],"opsi/licenseGeneric"); - $acl_all= $ui->has_complete_category_acls($val['dn'],"opsi"); - - // Create edit and remove icon buttons - $actions = ""; - if(preg_match("/d/",$acl)){ - $actions.= ""; - }else{ - $actions.= " "; - } - - - // Append license descriptio, if available - $title = "title='".preg_replace('/ /', ' ', LDAP::fix($val['dn']))."'"; - if(!isset($val['description'][0])){ - $desc = ""; - }else{ - $desc = " - [ ".$val['description'][0]." ]"; - } - $display = $val['cn'][0].$desc; - - // Append the entry to the divlist - $field0 = array("string" => "" , - "attach" => "style='width:20px;'"); - $field1 = array("string" => ""._("License")."", - "attach" => "style='text-align:center;width: 20px;'"); - $field2 = array("string" => sprintf($editlink,$key,$display), - "attach" => "style='' ".$title); - $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), - "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); - - $this->AddElement(array($field0,$field1,$field2,$field4)); - } - - // Create the list summary - $num_deps=0; - if(!$this->SubSearch){ - $num_deps = count($this->Added_Departments); - } - $num_objs = count($list); - $num_obj_str = _("Number of listed license pools"); - $str = "".$num_obj_str." ".$num_objs."    "; - $this->set_List_Bottom_Info($str); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_filterOpsiLicense.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_filterOpsiLicense.inc new file mode 100644 index 000000000..2a45bb0eb --- /dev/null +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_filterOpsiLicense.inc @@ -0,0 +1,45 @@ +listPools(); + $result = array(); + if($si->is_error() || !is_array($res)){ + $this->init_successfull = FALSE; + msg_dialog::display(_("Error"),msgPool::siError($si->get_error()),ERROR_DIALOG); + return; + }else{ + + // Reset the list of licenses + foreach($res as $item){ + + // Fake an ldap entry, this enables ACL checks. + $entry['dn'] = "opsi:cn=".$item['cn'][0].",".$config->current['BASE']; + foreach($item as $name => $value){ + $entry[] = $name; + $entry[$name] = $value; + } + $entry['count'] = count($item); + $result[] = $entry; + } + } + return(filterACL::unifyResult($result)); + } + + static function unifyResult($result) + { + $res=array(); + foreach($result as $entry){ + if(!isset($res[$entry['dn']])){ + $res[$entry['dn']]=$entry; + } + } + return(array_values($res)); + } +} + +?> diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc index 27466eb68..76e279151 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc @@ -1,351 +1,67 @@ config= &$config; - $this->ui= get_userinfo(); - - // Initialize the corresponding list class. - $this->DivListLicenses = new divListLicense($this->config,$this); - } - - - function execute() + var $plHeadline = "Opsi Licenses"; + var $plDescription = "License management"; + var $plIcon = "plugins/opsi/images/plugin.png"; + + // Tab definition + protected $tabClass = "licenseTabs"; + protected $tabType = "OPSILICENSETABS"; + protected $aclCategory = "opsi"; + protected $aclPlugin = "licenseGeneric"; + protected $objectName = "license"; + + function __construct($config,$ui) { - // Call parent execute - plugin::execute(); - - // Variables to restore after 'entry locked' warning was displayed - session::set('LOCK_VARS_TO_USE',array('/^license_/','/^act/', - '/^id/','/^menu_action/','/^item/')); - - $smarty = get_smarty(); - - /*************** - * Handle _POST/_GET variables - ***************/ + $this->config = $config; + $this->ui = $ui; - // Get entry related posts - $s_action = ""; - $s_entry = ""; - foreach($_POST as $name => $value){ - if(preg_match("/^license_edit_/",$name)){ - $s_action = "edit"; - $s_entry = preg_replace("/^license_edit_([0-9]*)_.*$/","\\1",$name); - break; - } - if(preg_match("/^license_del_/",$name)){ - $s_action = "remove"; - $s_entry = preg_replace("/^license_del_([0-9]*)_.*$/","\\1",$name); - break; - } - } - - if(isset($_GET['act']) && $_GET['act'] == "edit_entry" && isset($_GET['id'])){ - $id = $_GET['id']; - if(isset($this->licenses[$id])){ - $s_action = "edit"; - $s_entry = $id; - } - } + $this->storagePoints = array(); - // Get menu related posts - if(isset($_POST['menu_action'])) { - if($_POST['menu_action'] == "remove_multiple_licenses"){ - $s_action = "remove_multiple"; - } - if($_POST['menu_action'] == "license_new"){ - $s_action = "new"; - } - } - - - - /*************** - * Remove handling - ***************/ - - if($s_action == "remove_multiple" || $s_action == "remove"){ - - if($s_action == "remove_multiple"){ - $ids = $this->list_get_selected_items(); - }else{ - $ids = array($s_entry); - } - - if(count($ids)){ - $this->dns = array(); - $disallowed = array(); - foreach($ids as $id){ - $dn = $this->licenses[$id]['dn']; - $acl = $this->ui->get_permissions($dn, "opsi/licenseGeneric"); - if(preg_match("/d/",$acl)){ - $this->dns[$id] = $dn; - }else{ - $disallowed[] = $dn; - } - } - - if(count($disallowed)){ - msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG); - } - - if(count($this->dns)){ - - $dns_names = array(); - foreach($this->dns as $dn){ - $dns_names[] = LDAP::fix($dn); - } - - $smarty->assign("info", msgPool::deleteInfo($dns_names,_("License"))); - $smarty->assign("multiple", true); - return($smarty->fetch(get_template_path('remove.tpl', TRUE))); - } - } - } - - - /* Remove lock */ - if(isset($_POST['delete_multiple_licenses_cancel'])){ - - /* Remove lock file after successfull deletion */ - $this->remove_lock(); - $this->dns = array(); + // Build filter +# if (session::global_is_set(get_class($this)."_filter")){ +# $filter= session::global_get(get_class($this)."_filter"); +# } else { + $filter = new filter(get_template_path("opsiLicense-filter.xml", true)); + $filter->setObjectStorage($this->storagePoints); +# } + $this->setFilter($filter); + + // Build headpage + $headpage = new listing(get_template_path("opsiLicense-list.xml", true)); + $headpage->setFilter($filter); + + // Add copy&paste and snapshot handler. + if ($this->config->boolValueIsTrue("main", "copyPaste")){ + $this->cpHandler = new CopyPasteHandler($this->config); } - - - /* Confirmation for deletion has been passed. Users should be deleted. */ - if (isset($_POST['delete_multiple_licenses_confirm'])){ - - /* Remove user by user and check acls before removeing them */ - foreach($this->dns as $key => $dn){ - - $acl = $this->ui->get_permissions($dn, "opsi/licenseGeneric"); - if (preg_match('/d/', $acl)){ - $this->dialog = new licenseTabs($this->config, $this->config->data['TABS']['OPSILICENSETABS'],$dn, "opsi"); - $this->dialog->set_acl_base($this->config->current['BASE']); - $this->dialog->delete(); - $this->dialog= NULL; - } else { - - /* Normally this shouldn't be reached, send some extra - logs to notify the administrator */ - msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG); - new log("security","opsi/".get_class($this),$dn,array(),"Tried to trick deletion."); - } - } - - /* Remove lock file after successfull deletion */ - $this->remove_lock(); - $this->dns = array(); - } - - - /*************** - * New handling - ***************/ - - if($s_action == "new" && !$this->dialog instanceOf tabs){ - $this->dn = "new"; - $this->dialog = new licenseTabs($this->config, $this->config->data['TABS']['OPSILICENSETABS'],$this->dn, "opsi"); - $this->dialog->set_acl_base($this->config->current['BASE']); + if($this->config->get_cfg_value("enableSnapshots") == "true"){ + $this->snapHandler = new SnapshotHandler($this->config); } - - /*************** - * Edit handling - ***************/ - - if($s_action == "edit" && !$this->dialog instanceOf tabs){ - if(!isset($this->licenses[$s_entry])){ - trigger_error("Unknown entry!"); - }else{ - - $entry = $this->licenses[$s_entry]; - $this->dn = $entry['dn']; - - /* Open the dialog */ - $this->dialog = new licenseTabs($this->config, $this->config->data['TABS']['OPSILICENSETABS'], - $entry['dn'], "opsi"); - $this->dialog->set_acl_base($this->config->current['BASE']); - set_object_info($this->dn); - } - } - - - /*************** - * Dialog handling - ***************/ - - if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && $this->dialog instanceOf tabs){ - $this->dialog->save_object(); - $msgs = $this->dialog->check(); - if(count($msgs)){ - msg_dialog::displayChecks($msgs); - }else{ - $this->dialog->save(); - if (!isset($_POST['edit_apply'])){ - $this->remove_lock(); - $this->dialog= NULL; - set_object_info(); - }else{ - $this->dialog->re_init(); - } - } - } - - if (isset($_POST['edit_cancel']) && $this->dialog instanceOf tabs){ - $this->remove_lock(); - $this->dialog= NULL; - set_object_info(); - } - - if($this->dialog instanceOf tabs){ - $display= $this->dialog->execute(); - - $dialog_opened = ($this->dialog->by_object[$this->dialog->current]->dialog instanceOf plugin); - - if(!$dialog_opened){ - if($this->dialog->read_only == TRUE){ - $display.= "

- -

"; - }else{ - - $display.= "

\n"; - $display.= "\n"; - $display.= " \n"; - if ($this->dn != "new"){ - $display.= "\n"; - $display.= " \n"; - } - $display.= "\n"; - $display.= "

"; - } - } - return ($display); - } - - - /*************** - * List handling - ***************/ - - // Display dialog with group list - $this->DivListLicenses->parent = $this; - $this->DivListLicenses->execute(); - $this->reload (); - $this->DivListLicenses->setEntries($this->licenses); - return($this->DivListLicenses->Draw()); + parent::__construct($config, $ui, "licenses", $headpage); } - - - // Refreshes the list of known license objects. - function reload() - { - - // Get current ldap base and filter settings. - $base = $this->DivListLicenses->selectedBase; - $Regex = $this->DivListLicenses->Regex; - - $si = new opsiLicenceHandler($this->config); - $this->licenses = array(); - $res = $si->listPools(); - if($si->is_error() || !is_array($res)){ - $this->init_successfull = FALSE; - msg_dialog::display(_("Error"),msgPool::siError($si->get_error()),ERROR_DIALOG); - return; - }else{ - - // Reset the list of licenses - foreach($res as $item){ - - // Fake an ldap entry, this enables ACL checks. - $item['dn'] = "opsi:cn=".$item['cn'][0].",".$this->config->current['BASE']; - $this->licenses[] = $item; - } - } - } - - - /* \brief Returns a list of selected entry ids. - * E.g. remove multiple entries. - * @return Array A list of entry IDs - */ - function list_get_selected_items() - { - $ids = array(); - foreach($_POST as $name => $value){ - if(preg_match("/^item_selected_[0-9]*$/",$name)){ - $id = preg_replace("/^item_selected_/","",$name); - $ids[$id] = $id; - } - } - return($ids); - } - - - function remove_lock() - { - if (isset($this->dialog->dn)){ - del_lock ($this->dialog->dn); - }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){ - del_lock($this->dn); - } - if(isset($this->dns) && is_array($this->dns) && count($this->dns)){ - del_lock($this->dns); - } - } - - - function save_object() - { - $this->DivListLicenses->save_object(); - } -} - +} // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/opsi/admin/opsiLicenses/main.inc b/gosa-plugins/opsi/admin/opsiLicenses/main.inc index 865e23b2c..292ebc980 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/main.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/main.inc @@ -3,7 +3,7 @@ * This code is part of GOsa (http://www.gosa-project.org) * Copyright (C) 2003-2008 GONICUS GmbH * - * ID: $$Id: main.inc 13288 2008-12-12 14:54:13Z hickert $$ + * ID: $$Id: main.inc 14752 2009-11-05 10:00:17Z hickert $$ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,46 +20,35 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -// Remove locks created by this plugin +/* Remove locks created by this plugin +*/ if ($remove_lock){ if(session::is_set('opsiLicenses')){ - $macl = session::get('opsiLicenses'); - $macl->remove_lock(); + $macl = session::get('opsiLicenses'); + $macl->remove_lock(); } } /* Remove this plugin from session */ if ( $cleanup ){ - $macl = session::get('opsiLicenses'); - $macl->remove_lock(); session::un_set('opsiLicenses'); }else{ - /* Create object object on demand */ + /* Create opsiLicenses object on demand */ if (!session::is_set('opsiLicenses')){ - session::set('opsiLicenses',new opsiLicenses($config)); + $opsiLicenses= new opsiLicenses ($config, $ui); + session::set('opsiLicenses',$opsiLicenses); } $opsiLicenses = session::get('opsiLicenses'); + $display= $opsiLicenses->execute(); - /* Execute formular */ - $opsiLicenses->save_object(); - $output= $opsiLicenses->execute (); - - /* Page header*/ - if (get_object_info() != ""){ - $display= print_header(get_template_path('plugins/opsi/images/plugin.png'), - _("Software licenses"), - "\"\" ". - LDAP::fix(get_object_info())); - } else { - $display= print_header(get_template_path('plugins/opsi/images/plugin.png'), _("Software licenses")); + /* Reset requested? */ + if (isset($_GET['reset']) && $_GET['reset'] == 1){ + session::un_set ('opsiLicenses'); } - $display.= $output; - - /* Store changes in session */ + /* Show and save dialog */ session::set('opsiLicenses',$opsiLicenses); } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.tpl b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.tpl new file mode 100644 index 000000000..ba7af5cde --- /dev/null +++ b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.tpl @@ -0,0 +1,33 @@ +
+

+ [F]{t}Filter{/t} +

+
+ +
+ +
+ + {$SCOPE} + + + + + + +
+ + + {$NAME} +
+ + + + + +
+ {$APPLY} +
+
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.xml b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.xml new file mode 100644 index 000000000..af1ba4e5f --- /dev/null +++ b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-filter.xml @@ -0,0 +1,40 @@ + + + + + roles + + true + + + + + OpsiLicense + (&(objectClass=organizationalRole)$NAME) + dn + objectClass + cn + description + + auto + + + + textfield + NAME + 20 + 60 + + + (cn=*$*) + false + + LDAP + (&(objectClass=organizationalRole)(cn=*$NAME*)) + cn + 0.5 + 3 + + + + diff --git a/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.tpl b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.tpl new file mode 100644 index 000000000..b233c5874 --- /dev/null +++ b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.tpl @@ -0,0 +1,31 @@ + + + + + + + +
+
+

 {$HEADLINE} {$SIZELIMIT}

+
+ +
+
+ + +
{$ROOT} {$BACK} {$HOME} {$RELOAD} {$SEPARATOR} {t}Base{/t} {$BASE}  {$SEPARATOR}  {$ACTIONS}
+
+
+ +
+
+ + + + {$LIST} +
+ {$FILTER} +
+ + diff --git a/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.xml b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.xml new file mode 100644 index 000000000..17aab5031 --- /dev/null +++ b/gosa-plugins/opsi/admin/opsiLicenses/opsiLicense-list.xml @@ -0,0 +1,143 @@ + + + + + true + false + true + true + + roles + + 1 + + + + organizationalRole + roles + role + plugins/rolemanagement/images/role.png + + + + + + |20px;c||250px|170px;r| + + + %{filter:objectType(dn,objectClass)} + + + + %{filter:departmentLink(row,dn,description)} + 2 + + + + %{filter:objectType(dn,objectClass)} + + + + + cn + string + %{filter:link(row,dn,"%s",cn)} + true + + + + + description + string + %{filter:link(row,dn,"%s",description)} + true + + + + + %{filter:actions(dn,row,objectClass)} + + +
+ + + + + sub + images/lists/new.png + + + + new + entry + plugins/rolemanagement/images/new.png + + + + + + separator + + + + edit + entry + images/lists/edit.png + + + + + remove + entry + images/lists/trash.png + + + + + exporter + + + + separator + + + + copypaste + + + + snapshot + + + + + + + + cp + copypaste + + + + edit + entry + images/lists/edit.png + + + + + snapshot + snapshot + + + + remove + entry + images/lists/trash.png + roles/role[d] + + + + + +
-- 2.30.2