Code

Updated image
[gosa.git] / gosa-plugins / fai / admin / fai / class_divListFai.inc
1 <?php
3 class divListFai extends MultiSelectWindow
4 {
5   /* Regex */
6   var $Regex              = "*";
7   var $ShowProfiles;
8   var $ShowTemplates;
9   var $ShowScripts;
10   var $ShowHooks;
11   var $ShowVariables;
12   var $ShowPackages;
13   var $ShowPartitions;
15   /* Subsearch checkbox */
16   var $SubSearch;
18   var $parent             ;
19   var $ui                 ;
21   function divListFai (&$config,$parent)
22   {
23     MultiSelectWindow::MultiSelectWindow($config, "Fai", "fai");
24     
25     $this->parent       = $parent;
26     $this->ui           = get_userinfo();
28     /* Set list strings */
29     $this->SetTitle(  _("List of classes"));
30     $this->SetSummary(_("List of deployment classes and packages"));
32     /* Result page will look like a headpage */
33     $this->SetHeadpageMode();
35     $this->EnableAplhabet   (true);
36   
37     /* Disable buttonsm */
38     $this->EnableCloseButton(false);
39     $this->EnableSaveButton (false);
41     /* Dynamic action col, depending on snapshot icons */
42     $action_col_size = 130;
44     /* Toggle all selected / deselected */
45     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
46                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
48     /* set Page header */
49     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
50     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
51     $this->AddHeader(array("string" => _("Class name"),  "attach" => "style=''"));
52     $this->AddHeader(array("string" => _("Class type"),         "attach" => "style='width:200px;'"));
53     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
55     $this->AddCheckBox("ShowProfiles"   , sprintf(_("Display objects of type '%s'."),_("Profile"))  ,_("Show profiles")     ,true);
56     $this->AddCheckBox("ShowTemplates"  , sprintf(_("Display objects of type '%s'."),_("Variable")) ,_("Show templates")    ,true);
57     $this->AddCheckBox("ShowScripts"    , sprintf(_("Display objects of type '%s'."),_("Script"))   ,_("Show scripts")      ,true);
58     $this->AddCheckBox("ShowHooks"      , sprintf(_("Display objects of type '%s'."),_("Hook"))     ,_("Show hooks")        ,true);
59     $this->AddCheckBox("ShowVariables"  , sprintf(_("Display objects of type '%s'."),_("Variable")) ,_("Show variables")    ,true);
60     $this->AddCheckBox("ShowPackages"   , sprintf(_("Display objects of type '%s'."),_("Package"))  ,_("Show packages")     ,true);
61     $this->AddCheckBox("ShowPartitions" , sprintf(_("Display objects of type '%s'."),_("Partition")),_("Show partitions")   ,true);
63     /* Add SubSearch checkbox */
64     //$this->AddCheckBox(SEPERATOR);
65     //$this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
67     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
68     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
69   }
71   function AddUserBoxToFilter($position)
72   {
73     $str = "";
74     if($position  == 2){
76       /* Check if there are post commands available for fai management.
77        * If not, grey out freeze/branch and release remove buttons.
78        */
79       $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
80       $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
82       $smarty = get_smarty();
83       $releases = $this->parent->getBranches();
84       
85       $smarty->assign("allow_create", $c);
86       $smarty->assign("allow_remove", $r);
87       $smarty->assign("fai_release" , $releases[$this->parent->fai_release]);
88       $smarty->assign("fai_base"    , $releases[$this->parent->fai_base]);
89       $smarty->assign("branchimage","plugins/fai/images/branch.png");
90       $smarty->assign("fai_releases", $releases);
91       $plug_id = 0;       
92       if(isset($_GET['plug'])){
93         $plug_id = $_GET['plug'];
94       }
95       $smarty->assign("plug_id",$plug_id);
96       $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
97     }
98     return($str);
99   }
101   function GenHeader()
102   {
103     /* Get all departments within this subtree */
104     $ui= get_userinfo();
105     $first = "";
106     $found = FALSE;
107     $base = $this->config->current['BASE'];
109     /* Add seperator */
110     $add_sep = false;
112     /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */ 
113     $acl_all = $ui->has_complete_category_acls($this->parent->fai_base,$this->module);
115     /* Add default header */
116     $listhead = MultiSelectWindow::get_default_header(false);
118     /* Add additional seperator */
119     if($add_sep){
120       $listhead .=" <img class='center' src='images/lists/seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
121     }
123     $s  = ".|"._("Actions")."|\n";
124     $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
125       "&nbsp;"._("Create")."|\n";
127     $acl = $ui->get_permissions($this->parent->fai_base,"fai/faiProfile");
128     if($this->parent->lock_type == "freeze" && !$this->parent->allow_freeze_object_attach){
129       $s.= "...|<input class='center' type='image' src='plugins/fai/images/freeze.png' alt=''>".
130         "&nbsp;"._("Freezed")."|\n";
131     }else{
132       if(preg_match("/c/",$acl)){
133         $s.= "...|<input class='center' type='image' src='images/fai_new_profile.png' alt=''>".
134           "&nbsp;"._("Profile")."|Create_profile|\n";
135       }
137       /* Append create icons for each fai component */
138       $arr = array(
139           array("plugins/fai/images/fai_new_partitionTable.png" , _("Partition table")  ,"Create_partition" , _("PT") , "faiPartitionTable"),
140           array("plugins/fai/images/fai_new_script.png"         , _("Scripts")          ,"Create_script"    , _("S")  , "faiScript"),
141           array("plugins/fai/images/fai_new_hook.png"           , _("Hooks")            ,"Create_hook"      , _("H")  , "faiHook"),
142           array("plugins/fai/images/fai_new_variable.png"       , _("Variables")        ,"Create_variable"  , _("V")  , "faiVariable"),
143           array("plugins/fai/images/fai_new_template.png"       , _("Templates ")       ,"Create_template"  , _("I")  , "faiTemplate"),
144           array("plugins/fai/images/fai_new_packages.png"       , _("Package list")     ,"Create_package"   , _("PK") , "faiPackage"));
146       foreach($arr as $ar){
147         $acl = $ui->get_permissions($this->parent->fai_base,"fai/".$ar[4]);
148         if(preg_match("/c/",$acl)){
149           $s.= "...|<input class='center' type='image' src='".$ar[0]."' alt=''>".
150             "&nbsp;".$ar[1]."|".$ar[2]."|\n";
151         }
152       }
153     }
155     /* Multiple options */
156     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
157       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
160     /* Add Copy & Paste header */
161     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module,TRUE,FALSE);
163 #   /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */ 
164 #   $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
166     $this->SetDropDownHeaderMenu($s);
167     $this->SetListHeader($listhead);
168   }
170   /* so some basic settings */
171   function execute()
172   {
173     $this->ClearElementsList();
174     $this->GenHeader();
175     $this->AvailableBranches = $this->parent->getBranches();
176   }
178   function setEntries($list)
179   {
180     /********************
181       Variable init
182      ********************/
184      $objects = array(
185            "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png", "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
186            "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",       "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
187            "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",         "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
188            "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",       "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
189            "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
190            "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",        "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
191            "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",       "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"));
194     /* Dynamic action col, depending on snapshot icons */
195     $action_col_size = 130;
196 #   if($this->parent->snapshotEnabled()){
197 #     $action_col_size += 32;
198 #   }
200     /********************
201       Attach objects
202      ********************/
204     $cnts = array();
205     foreach($objects as $key => $data){
206       $cnts[$key] = 0;
207     }
209      foreach($list as $key => $value){
210        $info     = "";
211        $img      = "";
212        $type     = $value['type'];
213        $abort    =false;
215        $cnts[$type] ++;
217        if(isset($objects[$type])){
218          $img   = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
219          $info  = $objects[$type]['NAME'];
220          $var   = $objects[$type]['VAR'];
221        }else{
222          $img   = "<img class='center' src='images/empty.png' alt=''>";
223          $info  = "";
224          $var   = "";
225        }
227        if((isset($value['description']))&&(!empty($value['description']))){
228          $desc= " [".$value['description']."]";
229        }else{
230          $desc= "";
231        }
233        /* Add copy & cut icons */
234        $ui = get_userinfo();
235        $action ="";
236        $acl_all = $ui->has_complete_category_acls($this->parent->fai_base,$this->module);
238        /* Add copy & cut functionality */
239        $action.= $this->parent->get_copypaste_action($value['dn'],"fai",$value['class'],TRUE,FALSE);
241        if(preg_match("/^freeze/", $value['FAIstate'])){
242          $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_freeze_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
243          $action.=  "<input class='center' type='image' src='images/lists/edit.png'  alt='"._("edit")."'
244            name='entry_freeze_edit_%KEY%' title='"._("Edit class")."'>";
245          $action.=  "<img src='images/lists/locked.png' alt='F' class='center'>";
246        }else{
247          $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
248          $action.= "<input class='center' type='image' src='images/lists/edit.png'  alt='"._("edit")."'
249            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
250          if(preg_match("/d/",$value['acl'])){
251            $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
252              name='entry_delete_%KEY%' title='"._("Delete class")."'>";
253          }
254        }
256 #      $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
258        /* Cutted objects should be displayed in light grey */
259        $display = $value['cn'].$desc;
260        if($this->parent->CopyPasteHandler){
261          foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
262            if($queue_data['dn'] == $value['dn']) {
263              $display = "<font color='#999999'>".$display."</font>";
264              break;
265            }
266          }
267        }
268        $edi = $editlink;
269        $acti = $action;
271        /* Create each field */
272        $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
273            "attach" => "style='width:20px;'");
274        $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
275        $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', '&nbsp;', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
276        $field3 = array("string" => $info, "attach" => "style='width:200px;'");
277        $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
278        $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
279      }
281      /* Create summary string for list footer */
282      $num_deps=0;
283      if(!$this->SubSearch){
284        $num_deps = count($this->Added_Departments);
285      }
287      $profile_str    = sprintf(_("Number of listed '%s'"),_("profiles"));
288      $partition_str  = sprintf(_("Number of listed '%s'"),_("partitions"));
289      $script_str     = sprintf(_("Number of listed '%s'"),_("scripts"));
290      $hook_str       = sprintf(_("Number of listed '%s'"),_("hooks"));
291      $variable_str   = sprintf(_("Number of listed '%s'"),_("variables"));
292      $template_str   = sprintf(_("Number of listed '%s'"),_("templates"));
293      $package_str    = sprintf(_("Number of listed '%s'"),_("packages"));   
294      $dep_str        = sprintf(_("Number of listed '%s'"),_("departments"));
296      $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
297        title='".$profile_str."' alt='".$profile_str."'>&nbsp;".$cnts['FAIprofile']."&nbsp;&nbsp;&nbsp;&nbsp;";
298      $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
299        title='".$partition_str."' alt='".$partition_str."'>&nbsp;".$cnts['FAIpartitionTable']."&nbsp;&nbsp;&nbsp;&nbsp;";
300      $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
301        title='".$script_str."' alt='".$script_str."'>&nbsp;".$cnts['FAIscript']."&nbsp;&nbsp;&nbsp;&nbsp;";
302      $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
303        title='".$hook_str."' alt='".$hook_str."'>&nbsp;".$cnts['FAIhook']."&nbsp;&nbsp;&nbsp;&nbsp;";
304      $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
305        title='".$variable_str."' alt='".$variable_str."'>&nbsp;".$cnts['FAIvariable']."&nbsp;&nbsp;&nbsp;&nbsp;";
306      $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
307        title='".$template_str."' alt='".$template_str."'>&nbsp;".$cnts['FAItemplate']."&nbsp;&nbsp;&nbsp;&nbsp;";
308      $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
309        title='".$package_str."' alt='".$package_str."'>&nbsp;".$cnts['FAIpackageList']."&nbsp;&nbsp;&nbsp;&nbsp;";
310      $str.= "<img class='center' src='images/lists/folder.png'
311        title='".$dep_str."' alt='".$dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
312      $this->set_List_Bottom_Info($str);
313   }
315   function Save()
316   {
317     MultiSelectWindow::Save();  
318   }
320   function save_object()
321   {
322     /* Save automatic created POSTs like regex, checkboxes */
323     MultiSelectWindow::save_object(); 
324   }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>