b3330346b43bc76c8d0e4bf050d999836aebfdd2
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 $releases= array();
36 foreach($atr as $release => $sections){
37 $releases[$release]=$release;
38 }
39 if(!empty($this->FAIdebianRelease)){
40 $sections = $atr[$this->FAIdebianRelease] ;
41 }else{
42 $sections = array();
43 }
45 /* Fill templating stuff */
46 if((empty($this->FAIdebianRelease))||(count($this->FAIdebianSection)==0)){
47 $smarty->assign("goon"," disabled ");
48 }else{
49 $smarty->assign("goon"," ");
50 }
52 $smarty->assign("releases" ,$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 foreach($secs as $section){
67 if(in_array($section,$this->FAIdebianSection)){
68 $str .= "<input type='checkbox' value='".$section."' name='section_".$section."' checked>".$section."<br>";
69 }else{
70 $str .= "<input type='checkbox' value='".$section."' name='section_".$section."'>".$section."<br>";
71 }
72 $str .="<input type='hidden' name='wasOnPage_".$section."'>";
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['YesItIsPostedPackages'])){
109 if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
110 $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
111 }
113 foreach($_POST as $name => $value){
114 if(preg_match("/wasOnPage_/",$name)){
115 $nm = preg_replace("/wasOnPage_/","",$name);
116 if(isset($_POST['section_'.$nm])){
117 $this->FAIdebianSection[$nm] = $nm;
118 }else{
119 if(isset($this->FAIdebianSection[$nm])){
120 unset($this->FAIdebianSection[$nm]);
121 }
122 }
123 }
124 }
125 }
126 /* Remove all section that are not available at the currently selected server */
127 $atr = $this->getServerInfos();
128 foreach($this->FAIdebianSection as $section){
129 if(!in_array($section,$atr[$this->FAIdebianRelease])){
130 unset($this->FAIdebianSection[$section]);
131 }
132 }
134 }
136 /* Check supplied data */
137 function check()
138 {
139 /* Call common method to give check the hook */
140 $message= plugin::check();
142 return ($message);
143 }
145 function save()
146 {
147 return(array("FAIdebianRelease"=>$this->FAIdebianRelease,"FAIdebianSection"=>$this->FAIdebianSection));
148 }
149 }
150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
151 ?>