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();
36 $releases= array();
37 foreach($atr as $release => $sections){
38 $releases[$release]=$release;
39 }
40 if(!empty($this->FAIdebianRelease)){
41 $sections = $atr[$this->FAIdebianRelease] ;
42 }else{
43 $sections = array();
44 }
46 /* Fill templating stuff */
47 if((empty($this->FAIdebianRelease))||(count($this->FAIdebianSection)==0)){
48 $smarty->assign("goon"," disabled ");
49 }else{
50 $smarty->assign("goon"," ");
51 }
53 $smarty->assign("releases" ,$releases);
54 $smarty->assign("release" ,$this->FAIdebianRelease);
55 $smarty->assign("sections",$this->generateSections($sections));
57 $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
58 return($display);
59 }
61 function generateSections($secs)
62 {
63 $str = "";
64 if(is_array($secs)){
65 sort($secs);
66 $secs= array_unique($secs);
67 foreach($secs as $section){
68 if(in_array($section,$this->FAIdebianSection)){
69 $str .= "<input type='checkbox' value='".$section."' name='section_".$section."' checked>".$section."<br>";
70 }else{
71 $str .= "<input 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 }
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 }
150 }
151 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
152 ?>