0d4453468a2a10005a8013036b32de4067e62b2d
1 <?php
3 class servrepository 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("FAIrepository");
13 var $objectclasses = array("FAIrepositoryServer");
15 /* Search filter */
16 var $regex = "*";
18 /* Configurationdialog for repositories */
19 var $dialog = NULL;
21 /* Repositories */
22 var $repositories = array();
23 var $FAIrepository = array();
25 function servrepository ($config, $dn= NULL)
26 {
27 plugin::plugin ($config, $dn);
29 $this->repositories = array();
30 if(isset($this->attrs['FAIrepository'])){
31 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
32 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
33 $tmp2 = array();
34 $tmp3 = array();
36 if(isset($tmp[1])){
37 $tmp2['ParentServer'] = $tmp[1];
38 if(empty($tmp[1])){
39 $tmp2['ParentServer'] = "none";
40 }
41 }else{
42 $tmp2['ParentServer'] = "none";
43 }
45 if(isset($tmp[0])){
46 $tmp2['Url'] = $tmp[0];
47 }else{
48 $tmp2['Url'] = "";
49 }
51 if(isset($tmp[2])){
52 $tmp2['Release'] = $tmp[2];
53 }else{
54 $tmp2['Release'] = "";
55 }
57 if(isset($tmp[3])){
58 $tmp3 = split(",",$tmp[3]);
59 foreach($tmp3 as $sec){
60 $tmp2['Sections'][$sec]=$sec;
61 }
62 }else{
63 $tmp['Section']=array();
64 }
66 $this->repositories[$tmp[2]]=$tmp2;
67 }
68 }
69 }
71 function execute()
72 {
73 /* Call parent execute */
74 plugin::execute();
76 /* Fill templating stuff */
77 $smarty= get_smarty();
78 $display= "";
80 /* Smarty vars*/
81 $smarty->assign("infoimage", get_template_path('images/info.png'));
82 $smarty->assign("search_image", get_template_path('images/search.png'));
83 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
84 $smarty->assign("tree_image", get_template_path('images/tree.png'));
85 $smarty->assign("alphabet", generate_alphabet());
86 $smarty->assign("apply", apply_filter());
87 $smarty->assign("regex", $this->regex);
90 /* Do we need to flip is_account state? */
91 if (isset($_POST['modify_state'])){
92 $this->is_account= !$this->is_account;
93 }
95 /* Show tab dialog headers */
96 if ($this->is_account){
97 $display= $this->show_header(_("Remove FAI repository extension."),
98 _("This server has FAI repository features enabled. You can disable them by clicking below."));
99 } else {
100 $display= $this->show_header(_("Add FAI repository extension."),
101 _("This server has FAI repository features disabled. You can enable them by clicking below."));
102 return ($display);
103 }
105 /*
106 ADD / EDIT Repository
107 Dialog Handling
108 */
110 $once = false;
111 foreach($_POST as $name => $value){
113 if(preg_match("/AddRepository/",$name)){
114 $once = true;
115 $this->dialog = new servRepositorySetup($this->config,$this->dn);
116 $this->dialog->acl = $this->acl;
117 }
119 if((preg_match("/^delete_/",$name))&&(!$once)){
121 $value = preg_replace("/delete_/","",$name);
122 $value = preg_replace("/_.$/","",$value);
124 if(isset($this->repositories[$value])){
125 $once = true;
126 unset($this->repositories[$value]);
127 }
128 }
130 if((preg_match("/^edit_/",$name))&&(!$once)){
131 $value = preg_replace("/edit_/","",$name);
132 $value = preg_replace("/_.$/","",$value);
133 if(isset($this->repositories[$value])){
134 $once = true;
135 $obj = $this->repositories[$value];
137 /* to be able to detect if this was renamed */
138 $obj['initialy_was'] = $obj['Release'];
139 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
140 $this->dialog->acl = $this->acl;
141 }
142 }
143 }
145 if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
146 $obj = $this->repositories[$_GET['id']];
147 $obj['initialy_was'] = $obj['Release'];
148 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
149 $this->dialog->acl = $this->acl;
150 }
152 /*
153 if(isset($_POST['AddRepository'])){
154 $this->dialog = new servRepositorySetup($this->config,$this->dn);
155 $this->dialog->acl = $this->acl;
156 }
157 */
159 if(isset($_POST['repository_setup_save'])){
160 $this->dialog->save_object();
161 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
162 print_red(_("This name is already in use."));
163 }else
165 if(count($this->dialog->check())!=0){
166 foreach($this->dialog->check() as $msg){
167 print_red($msg);
168 }
169 }else{
170 $obj = $this->dialog->save();
171 $this->dialog = NULL;
172 $this->is_dialog= false;
173 $this->repositories[$obj['Release']]=$obj;
174 }
175 }
177 if(isset($_POST['repository_setup_cancel'])){
178 $this->dialog=NULL;
179 $this->is_dialog = false;
180 }
182 if($this->dialog != NULL){
183 $this->dialog->save_object();
184 $this->is_dialog = true;
185 return($this->dialog->execute());
186 }
188 /*
189 Repository setup dialog handling /END
190 */
192 $divlist = new divList("repositories");
193 $divlist->SetEntriesPerPage(0);
194 $divlist->setHeight(400);
196 $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
197 array("string"=>_("Sections")),
198 array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
199 ) );
201 $link = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
202 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'> ";
203 $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
205 foreach($this->repositories as $name => $reps){
207 $str = " ";
209 if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
212 foreach($reps['Sections'] as $sec){
213 $str.=$sec." ";
214 }
216 $divlist->AddEntry(array(
217 array("string"=>preg_replace("/%s/",$name,$link),"attach"=>"style='width:80px;'"),
218 array("string"=>sprintf($link,$name,_("Sections")." :".$str)),
219 array("string"=>preg_replace("/%s/",$name,$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
220 ));
221 }
222 }
224 $smarty -> assign("Repositories",$divlist->DrawList());
226 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
227 return($display);
228 }
230 function remove_from_parent()
231 {
232 plugin::remove_from_parent();
233 $ldap= $this->config->get_ldap_link();
234 $ldap->cd ($this->config->current['BASE']);
236 $ldap->cat($this->dn);
238 if($ldap->count()){
239 $ldap->cd($this->dn);
240 $this->cleanup();
241 $ldap->modify ($this->attrs);
243 $this->handle_post_events("modify");
244 }
245 }
248 /* Save data to object */
249 function save_object()
250 {
251 plugin::save_object();
252 if(isset($_POST['regex'])){
253 $this->regex = $_POST['regex'];
254 }
255 }
258 /* Check supplied data */
259 function check()
260 {
261 $message= array();
262 return ($message);
263 }
266 /* Save to LDAP */
267 function save()
268 {
269 plugin::save();
271 $arr = array();
272 foreach($this->repositories as $servername => $conf){
273 $str = "";
274 foreach($conf['Sections'] as $sec){
275 $str.=$sec.",";
276 }
277 $str=preg_replace("/,$/","",$str);
279 if($conf['ParentServer']=="none"){
280 $conf['ParentServer'] ="";
281 }
283 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
284 }
285 $this->attrs['FAIrepository'] = $arr;
287 $ldap= $this->config->get_ldap_link();
288 $ldap->cd ($this->config->current['BASE']);
290 $ldap->cat($this->dn);
292 if($ldap->count()){
293 $ldap->cd($this->dn);
294 $this->cleanup();
295 $ldap->modify ($this->attrs);
297 $this->handle_post_events("modify");
298 }else{
299 $ldap->cd ($this->config->current['BASE']);
300 $ldap->create_missing_trees($this->dn);
301 $ldap->cd($this->dn);
302 $ldap->add($this->attrs);
303 $this->handle_post_events("add");
304 }
305 }
307 }
309 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
310 ?>