Code

Added host and product dialogs
[gosa.git] / gosa-plugins / opsi / admin / opsiLicenses / class_licenseByProduct.inc
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_opsiLicenses.inc 13520 2009-03-09 14:54:13Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
24 class licenseByProduct extends plugin 
25 {
27   var $cn = "";
28   var $licenseUses = array();
29   var $init_successfull = FALSE;
32   function __construct(&$config,$dn)
33   {
34     $this->config = $config;
35     $this->dn = $this->orig_dn = $dn;
36     $this->si = new opsiLicenceHandler($this->config);
38     $this->is_account=TRUE;
39     if($this->dn == "new"){
40       $this->initially_was_account = FALSE;
41     }else{
42       $this->initially_was_account = TRUE;
43       $this->cn = $this->orig_cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
44     }
46     // Extract pool name out of the fake dn.
47     $this->init();
48   }
50   
51   function init()
52   {
53     $this->licenseUses = array();
54     if(!$this->initially_was_account){
55       $this->init_successfull = TRUE;
56     }else{
58       $res = $this->si->getLicenseUsage("", $this->cn);
59       if($this->si->is_error()){
60         $this->init_successfull = FALSE;
61         return;
62       }
64       $this->licenseUses = $res;
65       $this->init_successfull = TRUE;
66     }
67   }
70   function execute()
71   {
72     // Handle initialization failures.
73     if(isset($_POST['retry_init'])) $this->init();
74     if(!$this->init_successfull){
75       $smarty = get_smarty();
76       $smarty->assign("init_successfull", $this->init_successfull);
77       return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
78     }
79     
80     // Create usage list
81     $list = new divSelectBox("licenseUsage");
82     foreach($this->licenseUses as $license){
84       $f1 = array("string" => $license['hostId'][0]);
85       $f2 = array("string" => $license['licenseKey'][0]);
86       $f3 = array("string" => $license['licensePoolId'][0]);
87       $f4 = array("string" => $license['softwareLicenseId'][0],
88                   "attach" => "style='border-right:0px;'");
89       $list->addEntry(array($f1,$f2,$f3,$f4));
90     } 
92     $smarty = get_smarty();
94     // Assign ACls 
95     $plInfo = $this->plInfo();
96     foreach($plInfo['plProvidedAcls'] as $name => $desc){
97       $smarty->assign("{$name}ACL",$this->getacl($name));
98     }
99     foreach($this->attributes as $attr){
100       $smarty->assign($attr,$this->$attr);
101     }
103     $smarty->assign("licenseUses", $list->DrawList());
104     $smarty->assign("init_successfull", $this->init_successfull);
105     $smarty->assign("initially_was_account", $this->initially_was_account);
106     return($smarty->fetch(get_template_path('licenseUsage.tpl',TRUE,dirname(__FILE__))));
107   }
109  
110   /* Save HTML inputs
111    */
112   function save_object()
113   {
114     if(isset($_POST['opsiLicenseUsagePosted'])){
115       plugin::save_object();  
116     }
117   }  
120   /* Check user input and return a list of 'invalid input' messages.
121    */
122   function check()
123   {
124     $message = plugin::check();
125     return($message);
126   }
127   
129   /* Saves object modifications
130    */  
131   function save()
132   {
133     plugin::save();
135     // Send modify/add events
136     $mode = "modify";
137     if($this->orig_dn == "new"){
138       $mode = "add";
139     }
141     $this->si->createPool($this->cn, $this->description,$this->productIds,$this->softwareIds);#
142     if($this->si->is_error()){
143       msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
144     }else{
145       $this->handle_post_events($mode);
146     }
148     // Log action
149     if($mode == "modify"){
150       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
151     }else{
152       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
153     }
155     return 0;
156   }
158  
159   function remove_from_parent(){ return; }
161  
162   static function plInfo()
163   {
164     return (array(
165           "plShortName"   => _("Usage"),
166           "plDescription" => _("License usage"),
167           "plSelfModify"  => FALSE,
168           "plDepends"     => array(),
169           "plPriority"    => 1,
170           "plSection"     => array("administration"),
171           "plCategory"    => array("opsi"),
172           "plProvidedAcls"=> array(
173             "cn"                => _("Name"),
174             "description" => _("Description"))
175           ));
176   }
180 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
181 ?>