60aea4affc4de21ac220217f7108bd6d8316a869
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();
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 }
74 }
75 return($str);
76 }
78 function getServerInfos()
79 {
80 $ret = array();
81 $ldap = $this->config->get_ldap_link();
82 $ldap->cd($this->config->current['BASE']);
83 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
84 while($attrs = $ldap->fetch()){
85 if(isset($attrs['FAIrepository'])){
86 for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
87 $obj = $attrs['FAIrepository'][$i];
88 $tmp = split("\|",$obj);
89 if(count($tmp)==4){
90 foreach(split(",",$tmp[3]) as $sec){
91 if(!empty($sec)){
92 $ret[$tmp[2]][] = $sec;
93 }
94 }
95 }
96 }
97 }
98 }
99 return($ret);
100 }
103 /* Save data to object */
104 function save_object()
105 {
106 /* Post handling for Section, Release Setup */
107 if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
108 $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
109 }
111 /* Get Sections */
112 foreach($_POST as $name => $value){
113 if(preg_match("/^section_/",$name)){
114 $this->FAIdebianSection[$value] = $value;
115 }
116 }
118 /* Remove all section that are not available at the currently selected server */
119 $atr = $this->getServerInfos();
120 foreach($this->FAIdebianSection as $section){
121 if(!in_array($section,$atr[$this->FAIdebianRelease])){
122 unset($this->FAIdebianSection[$section]);
123 }
124 }
126 }
128 /* Check supplied data */
129 function check()
130 {
131 $message= array();
132 return ($message);
133 }
135 function save()
136 {
137 return(array("FAIdebianRelease"=>$this->FAIdebianRelease,"FAIdebianSection"=>$this->FAIdebianSection));
138 }
139 }
140 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
141 ?>