summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7dae67e)
raw | patch | inline | side by side (parent: 7dae67e)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 13:33:33 +0000 (13:33 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 13:33:33 +0000 (13:33 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14314 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc
index eacafcd1407ae5d91c5316334302d4a92209e41f..7473f68fffa648163a89c07c0413817dd4203123 100644 (file)
*/
-class licenseGeneric extends plugin {
+class licenseGeneric extends plugin
+{
- // The variables this plugin takes care of.
- var $cn = "";
- var $description ="";
- var $telephoneNumber = "";
- var $facsimileTelephoneNumber = "";
+ var $orig_dn = "";
+ var $data = array();
+ var $orig_data = array();
- // The objects base
- var $base = "";
-
- // Keep track if possible ng aming modifications
- var $orig_dn = "";
- var $orig_cn = "";
- var $orig_base = "";
-
- // The object classes written by this plugin
- var $objectclasses = array("top","organizationalLicense");
-
- // The list of occupants ([dn])
- var $licenseOccupant = array();
-
- // The licenseOccupant cache, dn=>attrs
- var $licenseOccCache = array();
-
- // A list of attributes managed by this plugin
- var $attributes = array("cn","description",
- "telephoneNumber","facsimileTelephoneNumber","licenseOccupant");
-
+ var $productIds = array();
+ var $softwareIds= array();
- /* Initialize the class
- */
- function __construct($config,$dn){
- plugin::plugin($config,$dn);
- $this->is_account = TRUE;
-
- // Initialize list of occupants
- $this->licenseOccupant = array();
- if(isset($this->attrs['licenseOccupant'])){
- for($i=0;$i<$this->attrs['licenseOccupant']['count']; $i++){
- $this->licenseOccupant[] = $this->attrs['licenseOccupant'][$i];
- }
- }
- // Detect the objects base
- if ($this->dn == "new"){
- $this->base = session::get('CurrentMainBase');
- } else {
- $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("licenseRDN"), '/i')."/","",$this->dn);
- }
+ var $attributes =array("cn","description");
- // Keep track of naming attribute modifications
- $this->orig_base = $this->base;
- $this->orig_dn = $dn;
- $this->orig_cn = $this->cn;
+ function __construct(&$config,$dn)
+ {
+ $this->config = $config;
+ $this->dn = $this->orig_dn = $dn;
- // Reload the occupant cache.
- $this->reload();
+ // Extract pool name out of the fake dn.
+ $this->cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
+ $this->init();
}
-
- /* Keep occupant cache up to date.
- * Else, we may have entries we can't display.
- */
- function reload()
- {
- // Entries can't be added twice.
- $attrs = array("description", "objectClass", "uid","cn");
- $this->licenseOccupant = array_unique($this->licenseOccupant);
- $this->licenseOccupant = array_values($this->licenseOccupant);
- $ldap = $this->config->get_ldap_link();
- foreach($this->licenseOccupant as $dn){
- if(!isset($this->licenseOccCache[$dn])){
- if($ldap->dn_exists($dn)){
- $ldap->cat($dn, $attrs);
+ function init()
+ {
+ $si = new opsiLicenceHandler($this->config);
+ $res = $si->getPool($this->cn);
+ if($si->is_error()){
+ $this->init_successfull = FALSE;
+ return(FALSE);
+ }else{
+ $this->data = $this->orig_data = $res;
+ $this->description = $this->data['description'][0];
- $tmp = $ldap->fetch();
- if(!isset($tmp['cn'])){
-
- // Extract the namingAttribute out of the dn.
- $cn = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$tmp['dn']);
- if(isset($tmp['uid'])){
- $cn = $tmp['uid'][0];
- }
- if(isset($tmp['description'])){
- $cn.= " [".$tmp['description'][0]."]";
- }
- $tmp['cn'][0] = $cn;
- }
+ // Load software IDs
+ if(isset($this->data['softwareId'])){
+ for($i = 0; $i < $this->data['softwareId']['count']; $i++){
+ $this->softwareIds[] = $this->data['softwareId'][$i];
+ }
+ }
- $this->licenseOccCache[$dn] = $tmp;
+ // Load product IDs
+ if(isset($this->data['productId'])){
+ for($i = 0; $i < $this->data['productId']['count']; $i++){
+ $this->productIds[] = $this->data['productId'][$i];
}
}
+ $this->init_successfull = TRUE;
+ return;
}
-
}
-
- function getOccupants(){
- return($this->licenseOccupant);
- }
- /* Generate HTML output of this plugin.
- */
function execute()
{
- // Get list of possible ldap bases, will be selectable in the ui.
- $tmp = $this->allowedBasesToMoveTo();
-
-
- /***************
- * Dialog handling
- ***************/
-
- if(isset($_POST['edit_membership']) && !$this->dialog instanceOf plugin){
- $this->dialog = new occupantSelect($this->config,$this->dn,$this);
- }
- if(isset($_POST['delete_membership']) && !$this->dialog instanceOf plugin){
- if(isset($_POST['members'])){
- foreach($_POST['members'] as $id){
- if(isset($this->licenseOccupant[$id])){
- unset($this->licenseOccupant[$id]);
- }
- }
- $this->reload();
- }
+ // Handle initialization failures.
+ if(isset($_POST['retry_init'])) $this->init();
+ if(!$this->init_successfull){
+ $smarty = get_smarty();
+ $smarty->assign("init_successfull", $this->init_successfull);
+ return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
}
- if(isset($_POST['add_object_cancel']) && $this->dialog instanceOf plugin){
- $this->dialog = NULL;
- }
- if(isset($_POST['add_object_finish']) && $this->dialog instanceOf plugin){
- $ret = $this->dialog->save();
- foreach($ret as $key => $entry){
- $this->licenseOccupant[] = $entry['dn'];
- $this->licenseOccCache[$entry['dn']] = $entry['attrs'];
- }
- $this->reload();
- $this->dialog = NULL;
- }
+ $smarty = get_smarty();
- if($this->dialog instanceOf plugin){
- $this->dialog->save_object();
- return($this->dialog->execute());
+ // Assign ACls
+ $plInfo = $this->plInfo();
+ foreach($plInfo['plProvidedAcls'] as $name => $desc){
+ $smarty->assign("{$name}ACL",$this->getacl($name));
}
-
-
- /***************
- * Template handling
- ***************/
-
- // Get smarty instance and assign required variables.
- $smarty = get_smarty();
- $smarty->assign("bases", $tmp);
- $smarty->assign("base_select",$this->base);
- $smarty->assign("members",$this->convert_list());
foreach($this->attributes as $attr){
$smarty->assign($attr,$this->$attr);
}
- // Assign current permissions for each attribute.
- $tmp = $this->plInfo();
- foreach($tmp['plProvidedAcls'] as $attr => $desc){
- $smarty->assign($attr."ACL",$this->getacl($attr));
- }
+ $smarty->assign("init_successfull", $this->init_successfull);
return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
}
function check()
{
$message = plugin::check();
-
- // Set the new acl base
- if($this->dn == "new") {
- $this->set_acl_base($this->base);
- }
-
- // Check if we are allowed to create/move this user
- if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
- $message[]= msgPool::permCreate();
- }elseif($this->orig_dn != "new" &&
- !$this->acl_is_moveable($this->base) &&
- ($this->orig_base != $this->base || $this->orig_cn != $this->cn )){
- $message[]= msgPool::permMove();
- }
-
- /* must: cn */
- if ($this->cn == ""){
- $message[]= msgPool::required(_("Name"));
- }
-
- // Check if this name is uniq for licenses.
- $ldap= $this->config->get_ldap_link();
- $ldap->cd($this->config->current['BASE']);
- $ldap->search("(&(objectClass=organizationalLicense)(cn=$this->cn))", array("cn"));
- $ldap->fetch();
- if ($ldap->count() != 0 && ( $this->dn == 'new' || $this->cn != $this->orig_cn)){
- $message[]= msgPool::duplicated(_("Name"));
- }
-
return($message);
}
- /* Returns list of occupants as <html><option> statements.
- */
- function convert_list()
- {
- $temp= "";
- $icon = " style=\"background-image:url('plugins/generic/images/head.png');\" ";
- foreach ($this->licenseOccupant as $key => $dn){
- if(isset($this->licenseOccCache[$dn])){
- $entry = $this->licenseOccCache[$dn];
- $name = $entry['cn']['0'];
- if(isset($entry['description'][0])){
- $name .= " [".$entry['description'][0]."]";
- }
- }else{
- $name = _("Unknown")." ".$dn;
- }
- $temp.= "<option {$icon} title='{$dn}' value='$key' class='select'>{$name}</option>\n";
- }
- return ($temp);
- }
-
/* Removes the object from the ldap database
*/
function remove_from_parent()
{
- plugin::remove_from_parent();
-
- // Remove this object.
- $ldap= $this->config->get_ldap_link();
- $ldap->rmdir($this->dn);
- if (!$ldap->success()){
- msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
- }
-
// Log action.
new log("remove","licenses/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
/* Saves object modifications
*/
- function save(){
+ function save()
+ {
plugin::save();
- /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
- new entries. So do a check first... */
- $ldap = $this->config->get_ldap_link();
- $ldap->cat ($this->dn, array('dn'));
- if ($ldap->fetch()){
- $mode= "modify";
- } else {
- $mode= "add";
- $ldap->cd($this->config->current['BASE']);
- $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
- }
- @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save via $mode");
- // Finally write data with selected 'mode'
- $this->cleanup();
- $ldap->cd ($this->dn);
- $ldap->$mode ($this->attrs);
- if (!$ldap->success()){
- msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(),
- $this->dn, LDAP_MOD, get_class()));
- return (1);
+ // Send modify/add events
+ $mode = "modify";
+ if($this->orig_dn == "new"){
+ $mode = "add";
}
- // Send modify/add events
$this->handle_post_events($mode);
- // Update ACL dependencies too
- if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
- $tmp = new acl($this->config,$this->parent,$this->dn);
- $tmp->update_acl_membership($this->orig_dn,$this->dn);
- }
-
// Log action
if($mode == "modify"){
new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
return 0;
}
-
-
- /* This avoids that users move themselves out of their rights.
- */
- function allowedBasesToMoveTo()
- {
- $bases = $this->get_allowed_bases();
- return($bases);
- }
-
-
+
+
/* Save HTML inputs
*/
function save_object()
{
plugin::save_object();
- if(isset($_POST['base'])){
- $this->base = get_post('base');
- }
}
-
- function PrepareForCopyPaste($source)
- {
- plugin::PrepareForCopyPaste($source);
-
- /* Load member objects */
- $this->licenseOccupant = array();
- if (isset($source['licenseOccupant'])){
- foreach ($source['licenseOccupant'] as $key => $value){
- if ("$key" != "count"){
- $value= @LDAP::convert($value);
- $this->licenseOccupant["$value"]= "$value";
- }
- }
- }
- $this->reload();
- }
-
-
- function getCopyDialog()
- {
- $smarty = get_smarty();
- $smarty->assign("cn", $this->cn);
- $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
- $ret = array();
- $ret['string'] = $str;
- $ret['status'] = "";
- return($ret);
- }
-
- function saveCopyDialog()
- {
- if(isset($_POST['cn'])){
- $this->cn = $_POST['cn'];
- }
- }
-
static function plInfo()
{
"plDepends" => array(),
"plPriority" => 1,
"plSection" => array("administration"),
- "plCategory" => array("licenses" => array("description" => _("Licenses"),
- "objectClass" => "organizationalLicense")),
+ "plCategory" => array("opsi"),
"plProvidedAcls"=> array(
"cn" => _("Name"),
- "description" => _("Description"),
- "base" => _("Base"),
- "telephoneNumber" => _("Telefon number"),
- "facsimileTelephoneNumber" => _("Fax number"),
- "licenseOccupant" => _("Occupants"))
+ "description" => _("Description"))
));
}
}
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc
index bad066d425179c631b7bb0aeddc1337243b464be..6a3ea5bc993daeefb3b423065c7895d8c1a43f47 100644 (file)
$data= array();
$data['licensePoolId'] = htmlentities($licensePoolId);
$res = $this->send_data("gosa_opsi_getLicensePool_hash",$this->target,$data,TRUE);
-
- print_a($res);
if(isset($res['XML'][0]['ANSWER_OPSI_GETLICENSEPOOL_HASH'])){
$item = array();
- foreach(array("LICENSEPOOLID" => "licensePoolId",
+ foreach(array("LICENSEPOOLID" => "cn",
"DESCRIPTION" => "description",
- "WINDOWSSOFTWAREIDS" => "windowsSoftwareIds",
- "PRODUCTIDS" => "productIds") as $source => $target){
+ "WINDOWSSOFTWAREIDS" => "softwareId",
+ "PRODUCTIDS" => "productId") as $source => $target){
if(isset($res['XML'][0][$source])){
+
+ $item[$target] = array('count' => 0);
foreach($res['XML'][0][$source] as $data){
- $item[$target][] = $res['XML'][0][$source][0]['VALUE'];
+ $item[$target][] = $data['VALUE'];
}
+ $item[$target]['count'] = count($item[$target]) -1 ;
}
}
return($item);
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/generic.tpl b/gosa-plugins/opsi/admin/opsiLicenses/generic.tpl
+++ /dev/null
@@ -1,85 +0,0 @@
-<table style='width:100%;'>
- <tr>
- <td style='width:50%; vertical-align:top; border-right:1px solid #A0A0A0; padding-right:10px;'>
-
- <h2><img src='plugins/licensemanagement/images/license.png' alt='' class='center'>
- {t}Generic{/t}
- </h2>
-
- <table style='width:100%;'>
- <tr>
- <td>{t}Name{/t}{$must}</td>
- <td>
- {render acl=$cnACL}
- <input type='text' value='{$cn}' name='cn'>
- {/render}
- </td>
- </tr>
- <tr>
- <td>{t}Description{/t}</td>
- <td>
- {render acl=$descriptionACL}
- <input type='text' value='{$description}' name='description'>
- {/render}
- </td>
- </tr>
- <tr>
- <td>
- <div style="height:10px;"></div>
- <label for="base">{t}Base{/t}</label>
- </td>
- <td>
- <div style="height:10px;"></div>
- {render acl=$baseACL}
- <select id="base" size="1" name="base" title="{t}Choose subtree to place user in{/t}">
- {html_options options=$bases selected=$base_select}
- </select>
- {/render}
- {render acl=$baseACL disable_picture='images/lists/folder_grey.png'}
- <input type="image" name="chooseBase" src="images/lists/folder.png" class="center"
- title="{t}Select a base{/t}">
- {/render}
- </td>
- </tr>
- <tr>
- <td colspan="2"><p class="seperator"> </p><br></td>
- </tr>
- <tr>
- <td>{t}Phone number{/t}</td>
- <td>
- {render acl=$telephoneNumberACL}
- <input type='text' value='{$telephoneNumber}' name='telephoneNumber'>
- {/render}
- </td>
- </tr>
- <tr>
- <td>{t}Fax number{/t}</td>
- <td>
- {render acl=$facsimileTelephoneNumberACL}
- <input type='text' value='{$facsimileTelephoneNumber}' name='facsimileTelephoneNumber'>
- {/render}
- </td>
- </tr>
- </table>
-
- </td>
- <td style=' vertical-align:top; padding-left:10px;'>
- <h2><img src='plugins/licensemanagement/images/occupant.png' alt='' class='center'>
- {t}Occupants{/t}
- </h2>
-
-{render acl=$licenseOccupantACL}
- <select style="width:100%; height:450px;" id="members" name="members[]" size="15" multiple>
- {$members}
- </select>
-{/render}
- <br>
-{render acl=$licenseOccupantACL}
- <input type=submit value="{msgPool type=addButton}" name="edit_membership">
-{/render}
-{render acl=$licenseOccupantACL}
- <input type=submit value="{msgPool type=delButton}" name="delete_membership">
-{/render}
- </td>
- </tr>
-</table>