Code

Udpated Tag handling for FAI objects.
[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");
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     /* set Page header */
57     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
58     $this->AddHeader(array("string" => _("Name of FAI class"),  "attach" => "style=''"));
59     $this->AddHeader(array("string" => _("Class type"),         "attach" => "style='width:200px;'"));
60     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:80px;border-right:0px;text-align:right;'"));
62     $this->AddCheckBox("ShowProfiles"   , _("Display FAI profile objects")    ,_("Show profiles")     ,true);
63     $this->AddCheckBox("ShowTemplates"  , _("Display FAI template objects")   ,_("Show templates")    ,true);
64     $this->AddCheckBox("ShowScripts"    , _("Display FAI scripts")            ,_("Show scripts")      ,true);
65     $this->AddCheckBox("ShowHooks"      , _("Display FAI hooks")              ,_("Show hooks")        ,true);
66     $this->AddCheckBox("ShowVariables"  , _("Display FAI variables")          ,_("Show variables")    ,true);
67     $this->AddCheckBox("ShowPackages"   , _("Display FAI packages")           ,_("Show packages")     ,true);
68     $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions")         ,_("Show partitions")   ,true);
70     /* Add SubSearch checkbox */
71     //$this->AddCheckBox(SEPERATOR);
72     //$this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
74     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
75     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
76   }
78   function AddUserBoxToFilter($position)
79   {
80     $str = "";
81     if($position  == 2){
83       /* Check if there are post commands available for fai management.
84        * If not, grey out freeze/branch and release remove buttons.
85        */
86       $r = ("" != search_config($this->config->data,"faiManagement","POSTREMOVE"));
87       $c = ("" != search_config($this->config->data,"faiManagement","POSTCREATE"));
89       $smarty = get_smarty();
90       $smarty->assign("allow_create", $c);
91       $smarty->assign("allow_remove", $r);
92       $smarty->assign("selectedBranch",$this->selectedBranch);
93       $smarty->assign("branchimage","images/branch.png");
94       $smarty->assign("branches",$this->AvailableBranches);
95       $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
96     }
97     return($str);
98   }
100   function GenHeader()
101   {
102     /* Prepare departments,
103        which are shown in the listbox on top of the listbox
104      */
105     $options= "";
106     foreach ($this->config->idepartments as $key => $value){
107       if ($this->selectedBase == $key){
108         $options.= "<option selected='selected' value='$key'>$value</option>";
109       } else {
110         $options.= "<option value='$key'>$value</option>";
111       }
112     }
117     /* Get copy & paste icon */
118     if($this->parent->CopyPasteHandler){
119       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
120     }else{
121       $Copy_Paste ="";
122     }
124     /* Add default header */
125     $listhead = MultiSelectWindow::get_default_header();
126     $listhead.=      " <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
127       title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;".
129       "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
131       " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle'
132       title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'>&nbsp;".
134       " <input class='center' type='image' src='images/fai_new_script.png' align='middle'
135       title='"._("New scripts")."' name='Create_script' alt='"._("S")."'>&nbsp;".
137       " <input class='center' type='image' src='images/fai_new_hook.png' align='middle'
138       title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'>&nbsp;".
140       " <input class='center' type='image' src='images/fai_new_variable.png' align='middle'
141       title='"._("New variables")."' name='Create_variable' alt='"._("V")."'>&nbsp;".
143       " <input class='center' type='image' src='images/fai_new_template.png' align='middle'
144       title='"._("New templates")."' name='Create_template' alt='"._("T")."'>&nbsp;".
146       " <input class='center' type='image' src='images/fai_new_packages.png' align='middle'
147       title='"._("New package list")."' name='Create_package' alt='"._("PK")."'>&nbsp;".
149       $Copy_Paste.
151       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
153       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
154       " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
156       "</div>";
158     $this->SetListHeader($listhead);
159   }
161   /* so some basic settings */
162   function execute()
163   {
164     $this->ClearElementsList();
165     $this->GenHeader();
166   }
168   function setEntries($list)
169   {
170     /********************
171       Variable init
172      ********************/
174      $objects = array(
175            "FAIpartitionTable"  => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
176            "FAIpackageList"     => array("IMG"=> "images/fai_packages.png",       "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
177            "FAIscript"          => array("IMG"=> "images/fai_script.png",         "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
178            "FAIvariable"        => array("IMG"=> "images/fai_variable.png",       "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
179            "FAIhook"            => array("IMG"=> "images/fai_hook.png",           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
180            "FAIprofile"         => array("IMG"=> "images/fai_profile.png",        "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
181            "FAItemplate"        => array("IMG"=> "images/fai_template.png",       "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"));
183     $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
185     /********************
186       Attach objects
187      ********************/
189     $cnts = array();
190     foreach($objects as $key => $data){
191       $cnts[$key] = 0;
192     }
194      foreach($list as $key => $value){
195        $info     = "";
196        $img      = "";
197        $type     = $value['type'];
198        $abort    =false;
200        $cnts[$type] ++;
202        if(isset($objects[$type])){
203          $img   = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
204          $info  = $objects[$type]['NAME'];
205          $var   = $objects[$type]['VAR'];
206        }else{
207          $img   = "<img class='center' src='images/empty.png' alt=''>";
208          $info  = "";
209          $var   = "";
210        }
212        if((isset($value['description']))&&(!empty($value['description']))){
213          $desc= " [".$value['description']."]";
214        }else{
215          $desc= "";
216        }
218        /* Create action icons */
219        $action ="";
220        if($this->parent->CopyPasteHandler){
221          if($value['FAIstate'] != "freeze"){
222            $action .= "<input class='center' type='image'
223              src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
224          }
225          $action.= "<input class='center' type='image'
226            src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
227        }
229        if($value['FAIstate'] == "freeze"){
230          $action .= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
231            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
232          $edi = $editlink;
233          $acti = $action;
234        }else{
235          $action .= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
236            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
237          $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
238            name='entry_delete_%KEY%' title='"._("Delete class")."'>";
239          $acti = $action;
240          $edi = $editlink;
241        }
243        /* Cutted objects should be displayed in light grey */
244        $display = $value['cn'].$desc;
245        if($this->parent->CopyPasteHandler->cutCurrent && $value['dn'] == $this->parent->CopyPasteHandler->objectdn){
246          $display = "<font color='#999999'>".$display."</font>";
247        }
249        $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
250        $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', '&nbsp;', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
251        $field3 = array("string" => $info, "attach" => "style='width:200px;'");
252        $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:80px;border-right:0px;text-align:right;'");
253        $this->AddElement(array($field1,$field2,$field3,$field4));
254      }
256      /* Create summary string for list footer */
257      $num_deps=0;
258      if(!$this->SubSearch){
259        $num_deps = count($this->Added_Departments);
260      }
262      $profile_str    = _("Number of listed profiles");
263      $partition_str  = _("Number of listed partitions");
264      $script_str     = _("Number of listed scripts");
265      $hook_str       = _("Number of listed hooks");
266      $variable_str   = _("Number of listed variables");
267      $template_str   = _("Number of listed templates");
268      $package_str    = _("Number of listed packages");
269      $dep_str        = _("Number of listed departments");
271      $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
272        title='".$profile_str."' alt='".$profile_str."'>&nbsp;".$cnts['FAIprofile']."&nbsp;&nbsp;&nbsp;&nbsp;";
273      $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
274        title='".$partition_str."' alt='".$partition_str."'>&nbsp;".$cnts['FAIpartitionTable']."&nbsp;&nbsp;&nbsp;&nbsp;";
275      $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
276        title='".$script_str."' alt='".$script_str."'>&nbsp;".$cnts['FAIscript']."&nbsp;&nbsp;&nbsp;&nbsp;";
277      $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
278        title='".$hook_str."' alt='".$hook_str."'>&nbsp;".$cnts['FAIhook']."&nbsp;&nbsp;&nbsp;&nbsp;";
279      $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
280        title='".$variable_str."' alt='".$variable_str."'>&nbsp;".$cnts['FAIvariable']."&nbsp;&nbsp;&nbsp;&nbsp;";
281      $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
282        title='".$template_str."' alt='".$template_str."'>&nbsp;".$cnts['FAItemplate']."&nbsp;&nbsp;&nbsp;&nbsp;";
283      $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
284        title='".$package_str."' alt='".$package_str."'>&nbsp;".$cnts['FAIpackageList']."&nbsp;&nbsp;&nbsp;&nbsp;";
285      $str.= "<img class='center' src='images/folder.png'
286        title='".$dep_str."' alt='".$dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
287      $this->set_List_Bottom_Info($str);
288   }
290   function Save()
291   {
292     MultiSelectWindow::Save();  
293   }
295   function save_object()
296   {
297     /* Save automatic created POSTs like regex, checkboxes */
298     MultiSelectWindow::save_object(); 
299     $_SESSION['faifilter']['branch'] = $this->selectedBranch; 
300   }
302 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
303 ?>