2fa8a7cf6fa8551cb0dc13170e21ddde3a4071cd
1 <?php
3 class servRepositorySetup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage FAI repositories";
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("Release","ParentServer","Url");
13 var $objectclasses = array("whatever");
15 /* Attributes */
16 var $Release;
17 var $ParentServer;
18 var $Url;
19 var $Sections=array();
20 var $ParentServers;
22 var $initialy_was=false;
24 function servRepositorySetup ($config, $dn= NULL,$data = false)
25 {
26 plugin::plugin ($config, $dn);
27 if($data != false){
28 $this->Sections= $data['Sections'];
29 $this->Url= $data['Url'];
30 $this->Release= $data['Release'];
31 $this->ParentServer= $data['ParentServer'];
32 if(isset($data['initialy_was'])){
33 $this->initialy_was= $data['initialy_was'];
34 }
35 }
36 }
38 function GetName()
39 {
40 return($this->Release);
41 }
43 function is_new_name()
44 {
45 if(!$this->initialy_was){
46 return(true);
47 }else{
48 if($this->Release != $this->initialy_was){
49 return(true);
50 }
51 }
52 return(false);
53 }
57 function execute()
58 {
59 /* Call parent execute */
60 plugin::execute();
62 /* Fill templating stuff */
63 $smarty= get_smarty();
65 if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
66 $this->Sections[$_POST['SectionName']]=$_POST['SectionName'];
67 }
69 foreach($_POST as $name => $value){
70 if(preg_match("/^delete_/",$name)){
71 if(isset($this->Sections[$value])){
72 unset($this->Sections[$value]);
73 }
74 }
75 }
77 $divlist = new divSelectBox("servRepositorySetup");
78 $divlist->setHeight("120");
80 $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
82 foreach($this->Sections as $sec){
83 $divlist->AddEntry(array(
84 array("string"=>$sec),
85 array("string"=>sprintf($dellink,$sec,$sec),"attach"=>"style='border-right:0px;width:20px;'")
86 ));
87 }
89 $smarty->assign("Sections",$divlist->DrawList());
91 foreach($this->attributes as $attr){
92 $smarty->assign($attr ,$this->$attr);
93 $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
94 }
96 $smarty->assign("ParentServers" ,$this->getParentServers());
97 $smarty->assign("ParentServerKeys",array_flip($this->getParentServers()));
99 return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
100 }
102 /* Save data to object */
103 function save_object()
104 {
105 plugin::save_object();
106 }
109 /* Check supplied data */
110 function check()
111 {
112 $message= array();
114 if(!isset($this->Release)){
115 $message[]=_("Please enter a value for 'release'.");
116 }
118 return ($message);
119 }
122 /* Save to LDAP */
123 function save()
124 {
125 $tmp = array();
126 $tmp['ParentServer'] = $this->ParentServer;
127 $tmp['Url'] = $this->Url;
128 $tmp['Release'] = $this->Release;
129 $tmp['Sections'] = $this->Sections;
130 return($tmp);
131 }
133 function getParentServers()
134 {
136 $ret = array();
138 $ldap = $this->config->get_ldap_link();
140 $ldap->cd($this->config->current['BASE']);
142 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
143 while($attr = $ldap->fetch()){
144 $ret[$attr['cn'][0]]= $attr['cn'][0];
145 }
146 $ret['none']=_("Master");
147 return($ret);
148 }
150 }
152 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
153 ?>