21aa551ace56f4b17612120b5093686235d93f9e
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);
28 $this->repositories = array();
29 if(isset($this->attrs['FAIrepository'])){
30 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
31 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
32 $tmp2 = array();
33 $tmp3 = array();
35 $tmp2['ParentServer'] = $tmp[1];
36 if(empty($tmp[1])){
37 $tmp2['ParentServer'] = "none";
38 }
39 $tmp2['Url'] = $tmp[0];
40 $tmp2['Release'] = $tmp[2];
42 $tmp3 = split(",",$tmp[3]);
44 foreach($tmp3 as $sec){
45 $tmp2['Sections'][$sec]=$sec;
46 }
47 $this->repositories[$tmp[2]]=$tmp2;
48 }
49 }
50 }
52 function execute()
53 {
54 /* Call parent execute */
55 plugin::execute();
57 /* Fill templating stuff */
58 $smarty= get_smarty();
59 $display= "";
61 /* Smarty vars*/
62 $smarty->assign("search_image", get_template_path('images/search.png'));
63 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
64 $smarty->assign("tree_image", get_template_path('images/tree.png'));
65 $smarty->assign("alphabet", generate_alphabet());
66 $smarty->assign("apply", apply_filter());
67 $smarty->assign("regex", $this->regex);
70 /* Do we need to flip is_account state? */
71 if (isset($_POST['modify_state'])){
72 $this->is_account= !$this->is_account;
73 }
75 /* Show tab dialog headers */
76 if ($this->is_account){
77 $display= $this->show_header(_("Remove FAI repository extension."),
78 _("This server has FAI repository features enabled. You can disable them by clicking below."));
79 } else {
80 $display= $this->show_header(_("Add FAI repository extension."),
81 _("This server has FAI repository features disabled. You can enable them by clicking below."));
82 return ($display);
83 }
85 /*
86 ADD / EDIT Repository
87 Dialog Handling
88 */
90 $once = false;
91 foreach($_POST as $name => $value){
92 if((preg_match("/^delete_/",$name))&&(!$once)){
93 if(isset($this->repositories[$value])){
94 $once = true;
95 unset($this->repositories[$value]);
96 }
97 }
99 if((preg_match("/^edit_/",$name))&&(!$once)){
100 if(isset($this->repositories[$value])){
101 $once = true;
102 $obj = $this->repositories[$value];
104 /* to be able to detect if this was renamed */
105 $obj['initialy_was'] = $obj['Release'];
106 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
107 $this->dialog->acl = $this->acl;
108 }
109 }
110 }
112 if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
113 $obj = $this->repositories[$_GET['id']];
114 $obj['initialy_was'] = $obj['Release'];
115 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
116 $this->dialog->acl = $this->acl;
117 }
119 if(isset($_POST['AddRepository'])){
120 $this->dialog = new servRepositorySetup($this->config,$this->dn);
121 $this->dialog->acl = $this->acl;
122 }
124 if(isset($_POST['repository_setup_save'])){
125 $this->dialog->save_object();
126 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
127 print_red(_("This name is already in use."));
128 }else
130 if(count($this->dialog->check())!=0){
131 foreach($this->dialog->check() as $msg){
132 print_red($msg);
133 }
134 }else{
135 $obj = $this->dialog->save();
136 $this->dialog = NULL;
137 $this->is_dialog= false;
138 $this->repositories[$obj['Release']]=$obj;
139 }
140 }
142 if(isset($_POST['repository_setup_cancel'])){
143 $this->dialog=NULL;
144 $this->is_dialog = false;
145 }
147 if($this->dialog != NULL){
148 $this->dialog->save_object();
149 $this->is_dialog = true;
150 return($this->dialog->execute());
151 }
153 /*
154 Repository setup dialog handling /END
155 */
157 $divlist = new divSelectBox("repositories");
158 $divlist->setHeight(400);
159 $link = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
160 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'> ";
161 $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
163 foreach($this->repositories as $name => $reps){
164 $str = " ";
165 foreach($reps['Sections'] as $sec){
166 $str.=$sec." ";
167 }
169 $divlist->AddEntry(array(
170 array("string"=>preg_replace("/%s/",$name,$link)),
171 array("string"=>sprintf($link,$name,_("Sections")." :".$str)),
172 array("string"=>preg_replace("/%s/",$name,$edit.$delete),"attach"=>"style='border-right:0px;'")
173 ));
174 }
176 $smarty -> assign("Repositories",$divlist->DrawList());
178 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
179 return($display);
180 }
182 function remove_from_parent()
183 {
184 plugin::remove_from_parent();
185 $ldap= $this->config->get_ldap_link();
186 $ldap->cd ($this->config->current['BASE']);
188 $ldap->cat($this->dn);
190 if($ldap->count()){
191 $ldap->cd($this->dn);
192 $ldap->modify($this->attrs);
193 $this->handle_post_events("modify");
194 }else{
195 $ldap->cd ($this->config->current['BASE']);
196 $ldap->create_missing_trees($this->dn);
197 $ldap->cd($this->dn);
198 $ldap->add($this->attrs);
199 $this->handle_post_events("add");
200 }
201 }
204 /* Save data to object */
205 function save_object()
206 {
207 plugin::save_object();
208 }
211 /* Check supplied data */
212 function check()
213 {
214 $message= array();
215 return ($message);
216 }
219 /* Save to LDAP */
220 function save()
221 {
222 plugin::save();
224 $arr = array();
225 foreach($this->repositories as $servername => $conf){
226 $str = "";
227 foreach($conf['Sections'] as $sec){
228 $str.=$sec.",";
229 }
230 $str=preg_replace("/,$/","",$str);
232 if($conf['ParentServer']=="none"){
233 $conf['ParentServer'] ="";
234 }
236 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
237 }
238 $this->attrs['FAIrepository'] = $arr;
240 $ldap= $this->config->get_ldap_link();
241 $ldap->cd ($this->config->current['BASE']);
243 $ldap->cat($this->dn);
245 if($ldap->count()){
246 $ldap->cd($this->dn);
247 $ldap->modify($this->attrs);
248 $this->handle_post_events("modify");
249 }else{
250 $ldap->cd ($this->config->current['BASE']);
251 $ldap->create_missing_trees($this->dn);
252 $ldap->cd($this->dn);
253 $ldap->add($this->attrs);
254 $this->handle_post_events("add");
255 }
256 }
258 }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>