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 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
30 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
31 $tmp2 = array();
32 $tmp3 = array();
34 $tmp2['ParentServer'] = $tmp[1];
35 $tmp2['Url'] = $tmp[0];
36 $tmp2['Release'] = $tmp[2];
38 $tmp3 = split(",",$tmp[3]);
40 foreach($tmp3 as $sec){
41 $tmp2['Sections'][$sec]=$sec;
42 }
43 $this->repositories[$tmp[2]]=$tmp2;
45 }
46 }
48 function execute()
49 {
50 /* Call parent execute */
51 plugin::execute();
53 /* Fill templating stuff */
54 $smarty= get_smarty();
55 $display= "";
57 /* Smarty vars*/
58 $smarty->assign("search_image", get_template_path('images/search.png'));
59 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
60 $smarty->assign("tree_image", get_template_path('images/tree.png'));
61 $smarty->assign("alphabet", generate_alphabet());
62 $smarty->assign("apply", apply_filter());
63 $smarty->assign("regex", $this->regex);
66 /* Do we need to flip is_account state? */
67 if (isset($_POST['modify_state'])){
68 $this->is_account= !$this->is_account;
69 }
71 /* Show tab dialog headers */
72 if ($this->is_account){
73 $display= $this->show_header(_("Remove FAI repository extension."),
74 _("This server has FAI repository features enabled. You can disable them by clicking below."));
75 } else {
76 $display= $this->show_header(_("Add FAI repository extension."),
77 _("This server has FAI repository features disabled. You can enable them by clicking below."));
78 return ($display);
79 }
81 /*
82 ADD / EDIT Repository
83 Dialog Handling
84 */
86 $once = false;
87 foreach($_POST as $name => $value){
88 if((preg_match("/^edit_/",$name))&&(!$once)){
89 if(isset($this->repositories[$value])){
90 $once = true;
91 $obj = $this->repositories[$value];
93 /* to be able to detect if this was renamed */
94 $obj['initialy_was'] = $obj['Release'];
95 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
96 $this->dialog->acl = $this->acl;
97 }
98 }
99 }
101 if(isset($_POST['AddRepository'])){
102 $this->dialog = new servRepositorySetup($this->config,$this->dn);
103 $this->dialog->acl = $this->acl;
104 }
106 if(isset($_POST['repository_setup_save'])){
107 $this->dialog->save_object();
108 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
109 print_red(_("This name is already in use."));
110 }else
112 if(count($this->dialog->check())!=0){
113 foreach($this->dialog->check() as $msg){
114 print_red($msg);
115 }
116 }else{
117 $obj = $this->dialog->save();
118 $this->dialog = NULL;
119 $this->is_dialog= false;
120 $this->repositories[$obj['Release']]=$obj;
121 }
122 }
124 if(isset($_POST['repository_setup_cancel'])){
125 $this->dialog=NULL;
126 $this->is_dialog = false;
127 }
129 if($this->dialog != NULL){
130 $this->dialog->save_object();
131 $this->is_dialog = true;
132 return($this->dialog->execute());
133 }
135 /*
136 Repository setup dialog handling /END
137 */
139 $divlist = new divSelectBox("repositories");
140 $divlist->setHeight(400);
142 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'>";
144 foreach($this->repositories as $name => $reps){
145 $str = " ";
146 foreach($reps['Sections'] as $sec){
147 $str.=$sec." ";
148 }
150 $divlist->AddEntry(array(
151 array("string"=>$name),
152 array("string"=>_("Sections")." :".$str),
153 array("string"=>preg_replace("/%s/",$name,$edit),"attach"=>"style='border-right:0px;'")
154 ));
155 }
157 $smarty -> assign("Repositories",$divlist->DrawList());
159 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
160 return($display);
161 }
163 function remove_from_parent()
164 {
165 /* This cannot be removed... */
166 }
169 /* Save data to object */
170 function save_object()
171 {
172 plugin::save_object();
173 }
176 /* Check supplied data */
177 function check()
178 {
179 $message= array();
180 return ($message);
181 }
184 /* Save to LDAP */
185 function save()
186 {
187 plugin::save();
189 $arr = array();
190 foreach($this->repositories as $servername => $conf){
191 $str = "";
192 foreach($conf['Sections'] as $sec){
193 $str.=$sec.",";
194 }
195 $str=preg_replace("/,$/","",$str);
196 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
197 }
198 $this->attrs['FAIrepository'] = $arr;
200 $ldap= $this->config->get_ldap_link();
201 $ldap->cd ($this->config->current['BASE']);
203 $ldap->cat($this->dn);
205 if($ldap->count()){
206 $ldap->cd($this->dn);
207 $ldap->modify($this->attrs);
208 $this->handle_post_events("modify");
209 }else{
210 $ldap->cd ($this->config->current['BASE']);
211 $ldap->create_missing_trees($this->dn);
212 $ldap->cd($this->dn);
213 $ldap->add($this->attrs);
214 $this->handle_post_events("add");
215 }
216 }
218 }
220 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
221 ?>