Code

Added support for general check hooks
[gosa.git] / plugins / admin / fai / class_faiPackageNew.inc
1 <?php
3 class faiPackageNew extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary        = "Manage server basic objects";
7   var $cli_description    = "Some longer text\nfor help";
8   var $cli_parameters     = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account     = TRUE;
12   var $attributes         = array();
13   var $objectclasses      = array();
14  
15   var $sections           = array(); // All sections
16   var $releases           = array(); // Releases 
18   var $FAIdebianRelease   = "";           // The selected release
19   var $FAIdebianSection   = array();      // selected section
21   var $obj;
23   function faiPackageNew ($config, $dn= NULL)
24   {
25     plugin::plugin ($config, $dn);
26   }
28   function execute()
29   {
30           /* Call parent execute */
31           plugin::execute();
32     $display = "";
33     $smarty = get_smarty(); 
34     $atr = $this->getServerInfos(); 
35     foreach($atr as $release => $sections){
36       $releases[$release]=$release;
37     }
38     if(!empty($this->FAIdebianRelease)){
39       $sections = $atr[$this->FAIdebianRelease] ;
40     }else{
41       $sections = array();
42     }
44     /* Fill templating stuff */
45     if((empty($this->FAIdebianRelease))||(count($this->FAIdebianSection)==0)){
46       $smarty->assign("goon"," disabled ");
47     }else{
48       $smarty->assign("goon"," ");
49     }
51     $smarty->assign("releases"    ,$releases);
52     $smarty->assign("releaseKeys" ,array_flip($releases));
53     $smarty->assign("release" ,$this->FAIdebianRelease);
54     $smarty->assign("sections",$this->generateSections($sections));
56     $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
57     return($display);
58   }
60   function generateSections($secs)
61   {
62     $str = "";
63     if(is_array($secs)){
64       sort($secs);
65       $secs= array_unique($secs);
66       $rel  = " onClick='document.mainform.submit();' ";
67       foreach($secs as $section){
68         if(in_array($section,$this->FAIdebianSection)){
69           $str .= "<input ".$rel." type='checkbox' value='".$section."' name='section_".$section."' checked>".$section."<br>";
70         }else{
71           $str .= "<input ".$rel." type='checkbox' value='".$section."' name='section_".$section."'>".$section."<br>";
72         }
73         $str .="<input type='hidden' name='wasOnPage_".$section."'>";
74       }
75     }
76     return($str); 
77   }
79   function getServerInfos()
80   {
81     $ret = array();
82     $ldap = $this->config->get_ldap_link();
83     $ldap->cd($this->config->current['BASE']);
84     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
85     while($attrs = $ldap->fetch()){
86       if(isset($attrs['FAIrepository'])){
87         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
88           $obj = $attrs['FAIrepository'][$i];
89           $tmp = split("\|",$obj);
90           if(count($tmp)==4){
91             foreach(split(",",$tmp[3]) as $sec){
92               if(!empty($sec)){
93                 $ret[$tmp[2]][] =  $sec;
94               }
95             }
96           }
97         } 
98       }
99     }
100     return($ret);
101   }
104   /* Save data to object */
105   function save_object()
106   {
107     /* Post handling for Section, Release  Setup */
108     if(isset($_POST['YesItIsPostedPackages'])){
110       if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
111         $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
112       }
113         
114       foreach($_POST as $name => $value){
115         if(preg_match("/wasOnPage_/",$name)){
116           $nm = preg_replace("/wasOnPage_/","",$name);
117           if(isset($_POST['section_'.$nm])){
118             $this->FAIdebianSection[$nm] = $nm; 
119           }else{
120             if(isset($this->FAIdebianSection[$nm])){
121               unset($this->FAIdebianSection[$nm]);
122             }
123           }
124         }
125       }
126     }
127     /* Remove all section that are not available at the currently selected server */ 
128     $atr = $this->getServerInfos();
129     foreach($this->FAIdebianSection as $section){
130       if(!in_array($section,$atr[$this->FAIdebianRelease])){
131         unset($this->FAIdebianSection[$section]);
132       }
133     }
135   }
137   /* Check supplied data */
138   function check()
139   {
140     /* Call common method to give check the hook */
141     $message= plugin::check();
143     return ($message);
144   }
146   function save()
147   {
148     return(array("FAIdebianRelease"=>$this->FAIdebianRelease,"FAIdebianSection"=>$this->FAIdebianSection));
149   }
151 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
152 ?>