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("release" ,$this->FAIdebianRelease);
53 $smarty->assign("sections",$this->generateSections($sections));
55 $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
56 return($display);
57 }
59 function generateSections($secs)
60 {
61 $str = "";
62 if(is_array($secs)){
63 sort($secs);
64 $secs= array_unique($secs);
65 foreach($secs as $section){
66 if(in_array($section,$this->FAIdebianSection)){
67 $str .= "<input type='checkbox' value='".$section."' name='section_".$section."' checked>".$section."<br>";
68 }else{
69 $str .= "<input type='checkbox' value='".$section."' name='section_".$section."'>".$section."<br>";
70 }
71 $str .="<input type='hidden' name='wasOnPage_".$section."'>";
72 }
73 }
74 return($str);
75 }
77 function getServerInfos()
78 {
79 $ret = array();
80 $ldap = $this->config->get_ldap_link();
81 $ldap->cd($this->config->current['BASE']);
82 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
83 while($attrs = $ldap->fetch()){
84 if(isset($attrs['FAIrepository'])){
85 for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
86 $obj = $attrs['FAIrepository'][$i];
87 $tmp = split("\|",$obj);
88 if(count($tmp)==4){
89 foreach(split(",",$tmp[3]) as $sec){
90 if(!empty($sec)){
91 $ret[$tmp[2]][] = $sec;
92 }
93 }
94 }
95 }
96 }
97 }
98 return($ret);
99 }
102 /* Save data to object */
103 function save_object()
104 {
105 /* Post handling for Section, Release Setup */
106 if(isset($_POST['YesItIsPostedPackages'])){
108 if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
109 $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
110 }
112 foreach($_POST as $name => $value){
113 if(preg_match("/wasOnPage_/",$name)){
114 $nm = preg_replace("/wasOnPage_/","",$name);
115 if(isset($_POST['section_'.$nm])){
116 $this->FAIdebianSection[$nm] = $nm;
117 }else{
118 if(isset($this->FAIdebianSection[$nm])){
119 unset($this->FAIdebianSection[$nm]);
120 }
121 }
122 }
123 }
124 }
125 /* Remove all section that are not available at the currently selected server */
126 $atr = $this->getServerInfos();
127 foreach($this->FAIdebianSection as $section){
128 if(!in_array($section,$atr[$this->FAIdebianRelease])){
129 unset($this->FAIdebianSection[$section]);
130 }
131 }
133 }
135 /* Check supplied data */
136 function check()
137 {
138 /* Call common method to give check the hook */
139 $message= plugin::check();
141 return ($message);
142 }
144 function save()
145 {
146 return(array("FAIdebianRelease"=>$this->FAIdebianRelease,"FAIdebianSection"=>$this->FAIdebianSection));
147 }
148 }
149 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
150 ?>