3336616a0dbeead0e99491261948a00f9f929c59
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 ="";
21 var $initialy_was=false;
23 function servRepositorySetup ($config, $dn= NULL,$data = false)
24 {
25 plugin::plugin ($config, $dn);
26 if($data != false){
27 foreach(array("Sections","Release","Url","ParentServer","initialy_was") as $atr){
28 if(isset($data[$atr])){
29 $this->$atr = $data[$atr];
30 }
31 }
32 }
33 }
35 function GetName()
36 {
37 return($this->Release);
38 }
40 function is_new_name()
41 {
42 if(!$this->initialy_was){
43 return(true);
44 }else{
45 if($this->Release != $this->initialy_was){
46 return(true);
47 }
48 }
49 return(false);
50 }
54 function execute()
55 {
56 /* Call parent execute */
57 plugin::execute();
59 /* Fill templating stuff */
60 $smarty= get_smarty();
62 if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
63 $this->Sections[$_POST['SectionName']]=$_POST['SectionName'];
64 }
66 foreach($_POST as $name => $value){
67 if(preg_match("/^delete_/",$name)){
68 if(isset($this->Sections[$value])){
69 unset($this->Sections[$value]);
70 }
71 }
72 }
74 $divlist = new divSelectBox("servRepositorySetup");
75 $divlist->setHeight("120");
77 $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
79 foreach($this->Sections as $sec){
80 $divlist->AddEntry(array(
81 array("string"=>$sec),
82 array("string"=>sprintf($dellink,$sec,$sec),"attach"=>"style='border-right:0px;width:20px;'")
83 ));
84 }
86 $smarty->assign("Sections",$divlist->DrawList());
88 foreach($this->attributes as $attr){
89 $smarty->assign($attr ,$this->$attr);
90 $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
91 }
93 $smarty->assign("ParentServers" ,$this->getParentServers());
94 $smarty->assign("ParentServerKeys",array_flip($this->getParentServers()));
96 return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
97 }
99 /* Save data to object */
100 function save_object()
101 {
102 plugin::save_object();
103 }
106 /* Check supplied data */
107 function check()
108 {
109 $message= array();
111 if(empty($this->Release)){
112 $message[]=_("Please enter a value for 'release'.");
113 }
115 if(empty($this->Url)){
116 $message[] = _("Please specify a valid value for 'url'.");
117 }
119 return ($message);
120 }
123 /* Save to LDAP */
124 function save()
125 {
126 $tmp = array();
127 $tmp['ParentServer'] = $this->ParentServer;
128 $tmp['Url'] = $this->Url;
129 $tmp['Release'] = $this->Release;
130 $tmp['Sections'] = $this->Sections;
131 return($tmp);
132 }
134 function getParentServers()
135 {
136 $ret = array();
137 $ldap = $this->config->get_ldap_link();
138 $ldap->cd($this->config->current['BASE']);
139 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
140 while($attr = $ldap->fetch()){
141 $ret[$attr['cn'][0]]= $attr['cn'][0];
142 }
143 $ret['none']=_("Master");
144 return($ret);
145 }
147 }
149 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
150 ?>