Code

Make usage of apostrophes in "Number of listed %s" strings
[gosa.git] / trunk / 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   var $ShowOpsiLocal;
22   var $ShowOpsiNetboot;
24   function divListFai (&$config,$parent)
25   {
26     MultiSelectWindow::MultiSelectWindow($config, "Fai", "fai");
27     
28     $this->parent       = $parent;
29     $this->ui           = get_userinfo();
31     /* Set list strings */
32     $this->SetTitle(  _("List of classes"));
33     $this->SetSummary(_("List of deployment classes and products"));
35     /* Result page will look like a headpage */
36     $this->SetHeadpageMode();
38     $this->EnableAplhabet   (true);
39   
40     /* Disable buttonsm */
41     $this->EnableCloseButton(false);
42     $this->EnableSaveButton (false);
44     /* Dynamic action col, depending on snapshot icons */
45     $action_col_size = 130;
47     /* Toggle all selected / deselected */
48     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
49                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
51     /* set Page header */
52     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
53     $this->AddHeader(array("string" => _("Class name"),  "attach" => "style=''"));
54     $this->AddHeader(array("string" => _("Class types"),         "attach" => "style='width:200px;'"));
55     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
57     $this->AddCheckBox("ShowProfiles"   , sprintf(_("Display objects of type '%s'."),
58           _("Profile"))  ,_("Show profiles")     ,true);
59     $this->AddCheckBox("ShowTemplates"  , sprintf(_("Display objects of type '%s'."),
60           _("Variable")) ,_("Show templates")    ,true);
61     $this->AddCheckBox("ShowScripts"    , sprintf(_("Display objects of type '%s'."),
62           _("Script"))   ,_("Show scripts")      ,true);
63     $this->AddCheckBox("ShowHooks"      , sprintf(_("Display objects of type '%s'."),
64           _("Hook"))     ,_("Show hooks")        ,true);
65     $this->AddCheckBox("ShowVariables"  , sprintf(_("Display objects of type '%s'."),
66           _("Variable")) ,_("Show variables")    ,true);
67     $this->AddCheckBox("ShowPackages"   , sprintf(_("Display objects of type '%s'."),
68           _("Package"))  ,_("Show packages")     ,true);
69     $this->AddCheckBox("ShowPartitions" , sprintf(_("Display objects of type '%s'."),
70           _("Partition")),_("Show partitions")   ,true);
72     /* Add opsi checkboxes if opsi is enabled 
73      */
74     if($this->parent->opsi instanceof opsi && $this->parent->opsi->enabled()){
75       $this->AddCheckBox("ShowOpsiNetboot" , sprintf(_("Display objects of type '%s'."),
76         _("OPSI netboot product")),_("Show netboot products")   ,true);
77       $this->AddCheckBox("ShowOpsiLocal" , sprintf(_("Display objects of type '%s'."),
78         _("OPSI localboot product")),_("Show localboot products")   ,true);
79     }
81     /* Add SubSearch checkbox */
82     //$this->AddCheckBox(SEPERATOR);
83     //$this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
85     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
86     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
87   }
89   function AddUserBoxToFilter($position)
90   {
91     $str = "";
92     if($position  == 2){
94       /* Check if there are post commands available for fai management.
95        * If not, grey out freeze/branch and release remove buttons.
96        */
97       $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
98       $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
100       $smarty = get_smarty();
101       $releases = $this->parent->getBranches();
102       
103       $smarty->assign("allow_create", $c);
104       $smarty->assign("allow_remove", $r);
105       $smarty->assign("fai_release" , $releases[$this->parent->fai_release]);
106       $smarty->assign("fai_base"    , $releases[$this->parent->fai_base]);
107       $smarty->assign("branchimage","plugins/fai/images/branch.png");
108       $smarty->assign("fai_releases", $releases);
109       $plug_id = 0;       
110       if(isset($_GET['plug'])){
111         $plug_id = $_GET['plug'];
112       }
113       $smarty->assign("plug_id",$plug_id);
114       $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
115     }
116     return($str);
117   }
119   function GenHeader()
120   {
121     /* Get all departments within this subtree */
122     $ui= get_userinfo();
123     $first = "";
124     $found = FALSE;
125     $base = $this->config->current['BASE'];
127     /* Add seperator */
128     $add_sep = false;
130     /* Add default header */
131     $listhead = MultiSelectWindow::get_default_header(false);
133     /* Add additional seperator */
134     if($add_sep){
135       $listhead .=" <img class='center' src='images/lists/seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
136     }
138     $s  = ".|"._("Actions")."|\n";
139     $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
140       "&nbsp;"._("Create")."|\n";
142     $acl = $ui->get_permissions($this->parent->acl_base,"fai/faiProfile");
143     if($this->parent->lock_type == "freeze" && !$this->parent->allow_freeze_object_attach){
144       $s.= "...|<input class='center' type='image' src='plugins/fai/images/freeze.png' alt=''>".
145         "&nbsp;"._("Freezed")."|\n";
146     }else{
147       if(preg_match("/c/",$acl)){
148         $s.= "...|<input class='center' type='image' src='plugins/fai/images/fai_new_profile.png' alt=''>".
149           "&nbsp;"._("Profile")."|Create_profile|\n";
150       }
152       /* Append create icons for each fai component */
153       $arr = array(
154           array("plugins/fai/images/fai_new_partitionTable.png" , _("Partition table")  ,
155             "Create_partition" , _("PT") , "faiPartitionTable"),
156           array("plugins/fai/images/fai_new_script.png"         , _("Scripts")          ,
157             "Create_script"    , _("S")  , "faiScript"),
158           array("plugins/fai/images/fai_new_hook.png"           , _("Hooks")            ,
159             "Create_hook"      , _("H")  , "faiHook"),
160           array("plugins/fai/images/fai_new_variable.png"       , _("Variables")        ,
161             "Create_variable"  , _("V")  , "faiVariable"),
162           array("plugins/fai/images/fai_new_template.png"       , _("Templates ")       ,
163             "Create_template"  , _("I")  , "faiTemplate"),
164           array("plugins/fai/images/fai_new_packages.png"       , _("Package list")     ,
165             "Create_package"   , _("PK") , "faiPackage"));
167       foreach($arr as $ar){
168         $acl = $ui->get_permissions($this->parent->acl_base,"fai/".$ar[4]);
169         if(preg_match("/c/",$acl)){
170           $s.= "...|<input class='center' type='image' src='".$ar[0]."' alt=''>".
171             "&nbsp;".$ar[1]."|".$ar[2]."|\n";
172         }
173       }
174     }
176     /* Multiple options */
177     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
178       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
181     /* Add Copy & Paste header */
182     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module,TRUE,FALSE);
184 #   /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */ 
185 #   $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
187     $this->SetDropDownHeaderMenu($s);
188     $this->SetListHeader($listhead);
189   }
191   /* so some basic settings */
192   function execute()
193   {
194     $this->ClearElementsList();
195     $this->GenHeader();
196     $this->AvailableBranches = $this->parent->getBranches();
197   }
199   function setEntries($list)
200   {
201     /********************
202       Variable init
203      ********************/
205     $edit_link = "<a href=\"?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit\">%s</a>";
206     $objects = array(
207         "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png", 
208           "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
209         "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",       
210           "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
211         "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",         
212           "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
213         "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",       
214           "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
215         "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",           
216           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
217         "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",        
218           "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
219         "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",       
220           "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
221         "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",       
222           "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
223         "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",       
224           "NAME"=>_("OPSI localboot product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
227     /* Dynamic action col, depending on snapshot icons */
228     $action_col_size = 130;
230     /********************
231       Attach objects
232      ********************/
234     /* Initialize summary attributes 
235      */
236     $cnts = array();
237     foreach($objects as $key => $data){
238       $cnts[$key] = 0;
239     }
241     /* Walk through entries an build up a printable row for each object 
242      */
243     foreach($list as $key => $value){
245       /* Build up edit icons - depending on read acls for the current type 
246        */
247       $name = "";
248       $name = "";
249       $icon_list = "";
250       $opsi_only = TRUE;
251       $locked = TRUE;
252       foreach($objects as $type => $type_data){
253         if(isset($value[$type])){
254           if(!preg_match("/^freeze/", $value[$type]['FAIstate'])){
255             /* at least one FAI object of this name is not frozen. */
256             $locked = FALSE;
257           }
258           $name = $value[$type]['cn'];
259           $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."' 
260             alt='".$type_data['KZL']."' class='center' name='edit_".$key."_".$type."'>\n";
261           $cnts[$type] ++;
262           if(!in_array($type,array("opsi_local","opsi_netboot"))){
263             $opsi_only = FALSE;
264           }
265         }else{
266           $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
267         }
268       }
270       /* Create checkbox
271        */
272       $checkbox = "&nbsp;";
273       if(!$opsi_only){
274         $checkbox = "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>";
275       }
276   
277       /* Create actions string
278        */
279       $actions = "";
280       if($opsi_only){
281         $actions.= "<input type='image' name='group_edit_".$key."' class='center'
282           src='images/lists/edit.png'>";
283         $actions.= "<img class='center' src='images/empty.png' alt=' '>";
284       }else{
285         $actions.= '<input class="center" src="images/lists/copy.png" alt="Kopieren" name="group_copy_'.$key.'" 
286           title="Diesen Eintrag kopieren" type="image">&nbsp;';
288         $actions.= "<input type='image' name='group_edit_".$key."' class='center'
289           src='images/lists/edit.png'>";
290         if($locked) {
291           $actions.= "<img src='images/lists/locked.png' alt='F' class='center'>";
292         }else{
293           $actions.= "<input type='image' name='group_remove_".$key."' class='center'
294             src='images/lists/trash.png'>";
295         }
296       }
298       /* Create list 
299        */
300       $field1 = array(
301           "string" => $checkbox ,
302           "attach" => "style='width:20px;'");
303       $field2 = array(
304           "string" => sprintf($edit_link,$key,$name),
305           "attach" => "style=''");
306       $field3 = array(
307           "string" => $icon_list ,
308           "attach" => "style='width:200px;'");
309       $field4 = array(
310           "string" => $actions,
311           "attach" => "style='width:".$action_col_size."px;border-right:  0px;text-align:right;'");
313       $this->AddElement(array($field1,$field2,$field3,$field4));
314     }
316      /* Create summary string for list footer */
317      $num_deps=0;
318      if(!$this->SubSearch){
319        $num_deps = count($this->Added_Departments);
320      }
322      $profile_str    = sprintf(_("Number of listed %s"),_("profiles"));
323      $partition_str  = sprintf(_("Number of listed %s"),_("partitions"));
324      $script_str     = sprintf(_("Number of listed %s"),_("scripts"));
325      $hook_str       = sprintf(_("Number of listed %s"),_("hooks"));
326      $variable_str   = sprintf(_("Number of listed %s"),_("variables"));
327      $template_str   = sprintf(_("Number of listed %s"),_("templates"));
328      $package_str    = sprintf(_("Number of listed %s"),_("packages"));   
329      $dep_str        = sprintf(_("Number of listed %s"),_("departments"));
330      $opsi_netboot   = sprintf(_("Number of listed %s"),_("netboot products"));
331      $opsi_local     = sprintf(_("Number of listed %s"),_("localboot products"));
333      $str = "<img class=\"center\" src=\"".$objects['FAIprofile']['IMG']."\"
334        title=\"".$profile_str."\" alt=\"".$profile_str."\">&nbsp;".$cnts['FAIprofile']."&nbsp;&nbsp;&nbsp;&nbsp;";
335      $str.= "<img class=\"center\" src=\"".$objects['FAIpartitionTable']['IMG']."\"
336        title=\"".$partition_str."\" alt=\"".$partition_str."\">&nbsp;".$cnts['FAIpartitionTable']."&nbsp;&nbsp;&nbsp;&nbsp;";
337      $str.= "<img class=\"center\" src=\"".$objects['FAIscript']['IMG']."\"
338        title=\"".$script_str."\" alt=\"".$script_str."\">&nbsp;".$cnts['FAIscript']."&nbsp;&nbsp;&nbsp;&nbsp;";
339      $str.= "<img class=\"center\" src=\"".$objects['FAIhook']['IMG']."\"
340        title=\"".$hook_str."\" alt=\"".$hook_str."\">&nbsp;".$cnts['FAIhook']."&nbsp;&nbsp;&nbsp;&nbsp;";
341      $str.= "<img class=\"center\" src=\"".$objects['FAIvariable']['IMG']."\"
342        title=\"".$variable_str."\" alt=\"".$variable_str."\">&nbsp;".$cnts['FAIvariable']."&nbsp;&nbsp;&nbsp;&nbsp;";
343      $str.= "<img class=\"center\" src=\"".$objects['FAItemplate']['IMG']."\"
344        title=\"".$template_str."\" alt=\"".$template_str."\">&nbsp;".$cnts['FAItemplate']."&nbsp;&nbsp;&nbsp;&nbsp;";
345      $str.= "<img class=\"center\" src=\"".$objects['FAIpackageList']['IMG']."\"
346        title=\"".$package_str."\" alt=\"".$package_str."\">&nbsp;".$cnts['FAIpackageList']."&nbsp;&nbsp;&nbsp;&nbsp;";
347      $str.= "<img class=\"center\" src='images/lists/folder.png'
348        title=\"".$dep_str."\" alt=\"".$dep_str."\">&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
350     if($this->parent->opsi instanceof opsi && $this->parent->opsi->enabled()){
351       $str.= "<img class=\"center\" src=\"".$objects['opsi_netboot']['IMG']."\"
352         title=\"".$opsi_netboot."\" alt=\"".$opsi_netboot."\">&nbsp;".$cnts['opsi_netboot']."&nbsp;&nbsp;&nbsp;&nbsp;";
353       $str.= "<img class=\"center\" src=\"".$objects['opsi_local']['IMG']."\"
354         title=\"".$opsi_local."\" alt=\"".$opsi_local."\">&nbsp;".$cnts['opsi_local']."&nbsp;&nbsp;&nbsp;&nbsp;";
355     }
356     $this->set_List_Bottom_Info($str);
357   }
359   function Save()
360   {
361     MultiSelectWindow::Save();  
362   }
364   function save_object()
365   {
366     /* Save automatic created POSTs like regex, checkboxes */
367     MultiSelectWindow::save_object(); 
368   }
370 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
371 ?>