diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc
index 19c295bd333e61d6ca907b3a3b29afd915780028..775adf0a6c9cdce1ebf0f58df3e2ecf496877269 100644 (file)
class licenseGeneric extends plugin
{
+ // License attributes
+ var $si = NULL;
+ var $data = array();
var $cn = "";
var $orig_cn = "";
- var $description = "";
- var $orig_dn = "";
-
- var $data = array();
- var $orig_data = array();
- var $productIds = array();
- var $softwareIds= array();
- var $licenses = array();
-
- var $availableProductIds = array();
- var $attributes =array("cn","description");
- var $si = NULL;
+ var $description = "";
+ var $partner = "";
+
+ // Date attributes
+ var $conclusionDate = "";
+ var $expirationDate = "";
+ var $notificationDate = "";
+
+ // License model related attribues
+ var $licenseModel = "";
+ var $licenseKey = array();
+ var $orig_licenseModel = "";
+ var $licensePoolId = "";
+ var $boundToHost= array(); // Reserved for Host.
+ var $usedByHost = array(); // Used by Host.
+
+ var $maximumInstallations = 0;
+ var $opsiHosts;
+
+ var $attributes = array(
+ "cn","description","partner","conclusionDate","expirationDate",
+ "notificationDate","licenseModel","licenseKey","maximumInstallations",
+ "licensePoolId", "usedByHost","boundToHost");
- function __construct(&$config,$dn)
+ function __construct(&$config, $dn, $license, $hosts = array())
{
+
$this->config = $config;
- $this->dn = $this->orig_dn = $dn;
-
+ $this->data = $license;
+ $this->dn = $dn;
$this->si = new opsiLicenceHandler($this->config);
+ $this->opsiHosts = $hosts;
- $this->is_account=TRUE;
- if($this->dn == "new"){
+ // Detect account state.
+ if(count($this->data) == 0){
$this->initially_was_account = FALSE;
}else{
$this->initially_was_account = TRUE;
- $this->cn = $this->orig_cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
}
+ $this->is_account = TRUE;
// Extract pool name out of the fake dn.
$this->init();
function init()
{
- // Load local Boot Products
- $res = $this->si->get_local_products();
- if($this->si->is_error()){
- $this->init_successfull = FALSE;
- return(FALSE);
- }
- $this->availableProductIds=array_keys($res);
-
- // Load Pool
- if(!$this->initially_was_account){
- $this->init_successfull = TRUE;
- }else{
-
- $res = $this->si->getPool($this->cn);
- if($this->si->is_error()){
- $this->init_successfull = FALSE;
- return(FALSE);
- }else{
- $this->data = $this->orig_data = $res;
- $this->description = $this->data['description'][0];
-
- // Load software IDs
- $this->softwareIds = array();
- if(isset($this->data['softwareId'])){
- for($i = 0; $i < $this->data['softwareId']['count']; $i++){
- $this->softwareIds[] = $this->data['softwareId'][$i];
- }
- }
+ // Extract license information out of the license object ($this->data)
+ $this->boundToHost = array('0'=>"");
+ $this->usedByHost = array('0'=>"");
+ $this->licenseKey = array('0'=>"");
+ if($this->initially_was_account){
+ foreach($this->attributes as $attr){
+ $this->$attr = $this->data[$attr];
+ }
- // Load product IDs
- $this->productIds = array();
- if(isset($this->data['productId'])){
- for($i = 0; $i < $this->data['productId']['count']; $i++){
- $this->productIds[] = $this->data['productId'][$i];
- }
+ // Fix dates
+ foreach(array("notificationDate","expirationDate","conclusionDate") as $date) {
+ if(!empty($this->$date)){
+ $this->$date = date("d.m.Y",strtotime($this->$date));
}
- $this->init_successfull = TRUE;
- return;
}
}
+
+ $this->orig_cn = $this->cn;
+ $this->orig_licenseModel = $this->licenseModel;
+ $this->init_successfull = TRUE;
+ return;
}
function execute()
{
+ plugin::execute();
// Handle initialization failures.
if(isset($_POST['retry_init'])) $this->init();
if(!$this->init_successfull){
$smarty = get_smarty();
- // Assign ACls
+ // Assign attributes and its ACls
$plInfo = $this->plInfo();
foreach($plInfo['plProvidedAcls'] as $name => $desc){
$smarty->assign("{$name}ACL",$this->getacl($name));
$smarty->assign($attr,$this->$attr);
}
+ // Assign list of available license models
+ $smarty->assign("licenseModels",array(
+ "RETAIL" => _("Retail"),
+ "OEM"=>_("OEM"),
+ "VOLUME" => _("Volume")));
+
+ $smarty->assign("usePrototype", "true");
$smarty->assign("init_successfull", $this->init_successfull);
- $smarty->assign("availableProductIds", array_diff( $this->availableProductIds, $this->productIds));
- $smarty->assign("productIds", $this->productIds);
- $smarty->assign("softwareIds", $this->softwareIds);
- $smarty->assign("licenses", $this->getLicenseList());
$smarty->assign("initially_was_account", $this->initially_was_account);
+ $smarty->assign("hosts", $this->getHosts());
+
+ $ui = get_userinfo();
+ $acl_base = $this->dn;
+ if($acl_base == "new"){
+ $acl_base = $this->config->current['BASE'];
+ }
+ $smarty->assign("licenseACL", $ui->get_permissions($acl_base,"opsi/licensePoolGeneric","licenses"));
+ $smarty->assign("writeable", preg_match("/w/",$ui->get_permissions($acl_base,"opsi/licensePoolGeneric","licenses")));
+ $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
+ $smarty->assign("boundToHost", $this->boundToHost[0]);
+ $smarty->assign("licenseKey", $this->licenseKey[0]);
+
+ // w3c fix, do not show empty options.
+ $tmp = $this->usedByHost;
+ if(isset($tmp[0]) && empty($tmp[0])) unset($tmp[0]);
+ $smarty->assign('usedByHost', $tmp);
+
+ foreach(array("notificationDate","expirationDate","conclusionDate") as $date) {
+ $smarty->assign($date."Writeable", $this->acl_is_writeable($date));
+ }
+
return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
}
- function getLicenseList()
+ function getHosts()
{
- $list = new divSelectBox("test");
- $list->setHeight(100);
+ $ret = array();
+ foreach($this->opsiHosts as $host){
+ $cn = $host['NAME'][0]['VALUE'];
+ $ret[$cn] = $cn;
+ }
+ return($ret);
+ }
-
- return($list->DrawList());
- }
-
/* Save HTML inputs
*/
function save_object()
{
- if(isset($_POST['opsiLicensesPosted'])){
- plugin::save_object();
-
- // Restore license cn, to avoid creating a copy...
- if($this->initially_was_account) $this->cn = $this->orig_cn;
- // We've to add prodcuts here
- if(isset($_POST['availableProduct']) && isset($_POST['addProduct'])){
- $pro = get_post('availableProduct');
- if(isset($this->availableProductIds[$pro]) && !in_array($this->availableProductIds[$pro], $this->productIds)){
- $this->productIds[] =$this->availableProductIds[$pro];
+ if(isset($_POST['opsiLicensesPosted'])){
+ plugin::save_object();
+
+ if(isset($_POST['addLicenseUsage']) && isset($_POST['selectedHostToAdd'])){
+ $host = get_post('selectedHostToAdd');
+ if(!empty($host) &&
+ in_array($host,$this->getHosts()) &&
+ !in_array($host, $this->usedByHost)){
+ $this->usedByHost[] = $host;
}
}
- // We've to remove products here
- if(isset($_POST['productIds']) && isset($_POST['removeProduct'])){
- foreach($_POST['productIds'] as $key){
- if(isset($this->productIds[$key])){
- unset($this->productIds[$key]);
+ if(isset($_POST['removeLicenseUsage']) && isset($_POST['selectedUsedHosts'])){
+ $todel = $_POST['selectedUsedHosts'];
+ foreach($todel as $host){
+ if(isset($this->usedByHost[$host])){
+ unset($this->usedByHost[$host]);
}
}
}
- // We've to add software here
- if(isset($_POST['newSoftwareId']) && isset($_POST['addSoftware'])){
- $soft = trim(get_post('newSoftwareId'));
- if(!empty($soft) && !in_array($soft, $this->softwareIds)){
- $this->softwareIds[] = $soft;
- }
+ // Force licenseKey to be of type array.
+ if(!is_array($this->licenseKey)){
+ $this->licenseKey = array($this->licenseKey);
}
- // We've to remove software Ids here
- if(isset($_POST['softwareIds']) && isset($_POST['removeSoftware'])){
- foreach($_POST['softwareIds'] as $key){
- if(isset($this->softwareIds[$key])){
- unset($this->softwareIds[$key]);
- }
- }
+ // BoundToHost maybe multiple too, later.
+ if(!is_array($this->boundToHost)){
+ $this->boundToHost = array($this->boundToHost);
+ }
+
+ if($this->initially_was_account){
+ $this->cn = $this->orig_cn;
+ $this->licenseModel = $this->orig_licenseModel;
}
}
}
function check()
{
$message = plugin::check();
+
+ // Very simple date input checks
+ if(!empty($this->expirationDate) &&
+ !preg_match("/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/",$this->expirationDate)){
+ $message[] = msgPool::invalid(_("Expiration date"),$this->expirationDate,"","23.02.2009");
+ }
+ if(!empty($this->conclusionDate) &&
+ !preg_match("/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/",$this->conclusionDate)){
+ $message[] = msgPool::invalid(_("Expiration date"),$this->conclusionDate,"","23.02.2009");
+ }
+ if(!empty($this->notificationDate) &&
+ !preg_match("/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/",$this->notificationDate)){
+ $message[] = msgPool::invalid(_("Expiration date"),$this->notificationDate,"","23.02.2009");
+ }
+
+ if(empty($this->cn)){
+ $message[] = msgPool::required(_("Name"));
+ }
+
+ if(empty($this->licenseKey[0])){
+ $message[] = msgPool::required(_("License key"));
+ }
+
return($message);
}
-
/* Removes the object from the opsi database
*/
- function remove_from_parent()
- {
- $this->si->deletePool($this->orig_cn);
- if($this->si->is_error()){
- msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
- }else{
-
- // Trigger remove signal
- $this->handle_post_events("remove");
- }
-
- new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
- }
+ function remove_from_parent() {}
/* Saves object modifications
*/
function save()
{
- plugin::save();
-
- // Send modify/add events
- $mode = "modify";
- if($this->orig_dn == "new"){
- $mode = "add";
+ $data = array();
+ foreach($this->attributes as $target){
+ $data[$target] = $this->$target;
}
-
- $this->si->createPool($this->cn, $this->description,$this->productIds,$this->softwareIds);#
- if($this->si->is_error()){
- msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
- }else{
- $this->handle_post_events($mode);
- }
-
- // Log action
- if($mode == "modify"){
- new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
- }else{
- new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
+
+ // Return opsi like dates.
+ foreach(array("notificationDate","expirationDate","conclusionDate") as $date) {
+ if(!empty($this->$date)){
+ $data[$date] = date("Y-m-d",strtotime($this->$date));
+ }
}
- return 0;
+ return($data);
}
static function plInfo()
"plDescription" => _("License generic"),
"plSelfModify" => FALSE,
"plDepends" => array(),
- "plPriority" => 1,
+ "plPriority" => 8,
"plSection" => array("administration"),
"plCategory" => array("opsi"),
"plProvidedAcls"=> array(
- "cn" => _("Name"),
- "description" => _("Description"))
+ "cn" => _("Name"),
+ "partner" => _("Partner"),
+ "licenseKey" => _("License key"),
+ "licenseModel" => _("License model"),
+ "licensePoolId" => _("License pool id"),
+ "maximumInstallations"=> _("Maximum installations"),
+ "boundToHost" => _("Reserved for host"),
+ "usedByHost" => _("Usage"),
+ "notificationDate" => _("Notification date"),
+ "conclusionDate" => _("Conclusion date"),
+ "expirationDate" => _("Expiration date"),
+ "description" => _("Description"))
));
}
}