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