Code

Recent changes in win2003sp1 required some fixes (backward compatible).
[gosa.git] / plugins / admin / fai / class_divListFai.inc
1 <?php
3 class divListFai extends MultiSelectWindow
4 {
5   /* Current base */
6   var $selectedBase       = "";
7   var $selectedBranch     = "main";
8   var $AvailableBranches  = array();
9   var $departments        = array();
11   /* Regex */
12   var $Regex              = "*";
13   var $ShowProfiles;
14   var $ShowTemplates;
15   var $ShowScripts;
16   var $ShowHooks;
17   var $ShowVariables;
18   var $ShowPackages;
19   var $ShowPartitions;
21   /* Subsearch checkbox */
22   var $SubSearch;
24   var $parent             ;
25   var $ui                 ;
27   var $SaveAdditionalVars = array("selectedBranch");
29   function divListFai ($config,$parent)
30   {
31     MultiSelectWindow::MultiSelectWindow($config, "Fai", "fai");
32     
33     $this->parent       = $parent;
34     $this->ui           = get_userinfo();
36     /* Set default base */
37     if(!isset($_SESSION['CurrentMainBase'])){
38       $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
39     }
40     $this->selectedBase = $_SESSION['CurrentMainBase'];
42     /* Set list strings */
43     $this->SetTitle(_("List of FAI classes"));
44     $this->SetSummary(_("This table displays all FAI classes in the selected tree."));
46     /* Result page will look like a headpage */
47     $this->SetHeadpageMode();
48     $this->SetInformation(_("This menu allows you to create, delete and edit FAI classes."));
50     $this->EnableAplhabet   (true);
51   
52     /* Disable buttonsm */
53     $this->EnableCloseButton(false);
54     $this->EnableSaveButton (false);
56    /* Dynamic action col, depending on snapshot icons */
57     $action_col_size = 50;
58     if($this->parent->snapshotEnabled()){
59       $action_col_size += 20;
60     }
62     /* set Page header */
63     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
64     $this->AddHeader(array("string" => _("Name of FAI class"),  "attach" => "style=''"));
65     $this->AddHeader(array("string" => _("Class type"),         "attach" => "style='width:200px;'"));
66     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
68     $this->AddCheckBox("ShowProfiles"   , _("Display FAI profile objects")    ,_("Show profiles")     ,true);
69     $this->AddCheckBox("ShowTemplates"  , _("Display FAI template objects")   ,_("Show templates")    ,true);
70     $this->AddCheckBox("ShowScripts"    , _("Display FAI scripts")            ,_("Show scripts")      ,true);
71     $this->AddCheckBox("ShowHooks"      , _("Display FAI hooks")              ,_("Show hooks")        ,true);
72     $this->AddCheckBox("ShowVariables"  , _("Display FAI variables")          ,_("Show variables")    ,true);
73     $this->AddCheckBox("ShowPackages"   , _("Display FAI packages")           ,_("Show packages")     ,true);
74     $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions")         ,_("Show partitions")   ,true);
76     /* Add SubSearch checkbox */
77     //$this->AddCheckBox(SEPERATOR);
78     //$this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
80     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
81     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
82   }
84   function AddUserBoxToFilter($position){
85     $str = "";
86     if($position  == 2){
87       $smarty = get_smarty();
88       $smarty->assign("selectedBranch",$this->selectedBranch);
89       $smarty->assign("branchimage","images/branch.png");
90       $smarty->assign("branches",$this->AvailableBranches);
91       $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
92     }
93     return($str);
94   }
96   function GenHeader()
97   {
98     $ui = get_userinfo();
99     /* Prepare departments,
100        which are shown in the listbox on top of the listbox
101      */
102     $options= "";
103     foreach ($this->config->idepartments as $key => $value){
104       if ($this->selectedBase == $key){
105         $options.= "<option selected='selected' value='$key'>$value</option>";
106       } else {
107         $options.= "<option value='$key'>$value</option>";
108       }
109     }
111         /* Create listhead, it will be shown on top of the divlist.
112      * It provides general navigation and object creation
113      */
114     $listhead =
115       "<div style='background:#F0F0F9;padding:5px;'>&nbsp;".
117       "<input class='center' type='image' src='images/list_root.png' align='middle'
118       title='"._("Go to root department")."' name='dep_root' alt='".      _("Root")."'>&nbsp;".
120       "<input class='center' type='image' src='images/list_up.png' align='middle'
121       title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'>&nbsp;".
123       "<input class='center' type='image' src='images/list_home.png' align='middle'
124       title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'>&nbsp;".
126       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".
127 _("Submit")."'>&nbsp;".
129       "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;";
131     $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
132     if(preg_match("/c/",$acl)){
133       $listhead .=" <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
134         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;";
135     }
137     $listhead .= "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;";
138     $listhead .= $this->get_snapshot_header($this->selectedBase);
141     $arr = array(
142         array("images/fai_new_partitionTable.png" , _("New partition table")  ,"Create_partition" , _("PT") , "faiPartitionTable"),
143         array("images/fai_new_script.png"         , _("New scripts")          ,"Create_script"    , _("S")  , "faiScript"),
144         array("images/fai_new_hook.png"           , _("New hooks")            ,"Create_hook"      , _("H")  , "faiHook"),
145         array("images/fai_new_variable.png"       , _("New variables")        ,"Create_variable"  , _("V")  , "faiVariable"),
146         array("images/fai_new_template.png"       , _("New templates ")       ,"Create_template"  , _("I")  , "faiTemplate"),
147         array("images/fai_new_packages.png"       , _("New package list")     ,"Create_package"   , _("PK") , "faiPackage"));
149     foreach($arr as $ar){
151       $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
152       if(preg_match("/c/",$acl)){
153         $listhead .=" <input class='center' type='image' src='".$ar[0]."' align='middle' title='".$ar[1]."' name='".$ar[2]."' alt='".$ar[3]."'>&nbsp;";
154       }
155     }
156     $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
158       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
159       " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
161       "</div>";
163     $this->SetListHeader($listhead);
164   }
166   /* so some basic settings */
167   function execute()
168   {
169     $this->ClearElementsList();
170     $this->GenHeader();
171     $this->AvailableBranches = $this->parent->getBranches();
172   }
174   function setEntries($list)
175   {
176     /********************
177       Variable init
178      ********************/
180      $objects = array(
181            "FAIpartitionTable"  => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>"Partition table","KZL"=> "PT", "VAR"=>"ShowPartitions"),
182            "FAIpackageList"     => array("IMG"=> "images/fai_packages.png",       "NAME"=>"Package list" ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
183            "FAIscript"          => array("IMG"=> "images/fai_script.png",         "NAME"=>"Scripts" ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
184            "FAIvariable"        => array("IMG"=> "images/fai_variable.png",       "NAME"=>"Variables" ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
185            "FAIhook"            => array("IMG"=> "images/fai_hook.png",           "NAME"=>"Hooks",          "KZL"=> "H",  "VAR"=>"ShowHooks"),
186            "FAIprofile"         => array("IMG"=> "images/fai_profile.png",        "NAME"=>"Profile" ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
187            "FAItemplate"        => array("IMG"=> "images/fai_template.png",       "NAME"=>"Templates" ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"));
189     $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
191     /* Dynamic action col, depending on snapshot icons */
192     $action_col_size = 50;
193     if($this->parent->snapshotEnabled()){
194       $action_col_size += 20;
195     }
197     /********************
198       Attach objects
199      ********************/
201      foreach($list as $key => $value){
202        $info     = "";
203        $img      = "";
204        $type     = $value['type'];
205        $abort    =false;
207        if(isset($objects[$type])){
208          $img   = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
209          $info  = $objects[$type]['NAME'];
210          $var   = $objects[$type]['VAR'];
211        }else{
212          $img   = "<img class='center' src='images/empty.png' alt=''>";
213          $info  = "";
214          $var   = "";
215        }
217        if((isset($value['description']))&&(!empty($value['description']))){
218          $desc= " [".$value['description']."]";
219        }else{
220          $desc= "";
221        }
224        if($value['FAIstate'] == "freeze"){
225          $action=  "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
226          $action.= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
227            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
228        }else{
229          $action= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
230            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
232          if(preg_match("/(c&w)/",$value['acl'])){
233            $action.= $this->GetSnapShotActions($value['dn']);;
234          }
236          if(preg_match("/d/",$value['acl'])){
237            $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
238              name='entry_delete_%KEY%' title='"._("Delete class")."'>";
239          }
240        }
242        $edi = $editlink;
243        $acti = $action;
245        $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
246        $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$value['cn'].$desc,preg_replace('/ /', '&nbsp;', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
247        $field3 = array("string" => $info, "attach" => "style='width:200px;'");
248        $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
249        $this->AddElement(array($field1,$field2,$field3,$field4));
250      }
251   }
253   function Save()
254   {
255     MultiSelectWindow::Save();  
256   }
258   function save_object()
259   {
260     /* Save automatic created POSTs like regex, checkboxes */
261     MultiSelectWindow::save_object(); 
262     $_SESSION['faifilter']['branch'] = $this->selectedBranch; 
263   }
265 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
266 ?>