Code

d693716909f8e14afd77bcfa54be22e506fb66b7
[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     /* Toggle all selected / deselected */
63     $chk = "<input type='checkbox' id='select_all' name='select_all'
64                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
66     /* set Page header */
67     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
68     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
69     $this->AddHeader(array("string" => _("Name of FAI class"),  "attach" => "style=''"));
70     $this->AddHeader(array("string" => _("Class type"),         "attach" => "style='width:200px;'"));
71     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
73     $this->AddCheckBox("ShowProfiles"   , _("Display FAI profile objects")    ,_("Show profiles")     ,true);
74     $this->AddCheckBox("ShowTemplates"  , _("Display FAI template objects")   ,_("Show templates")    ,true);
75     $this->AddCheckBox("ShowScripts"    , _("Display FAI scripts")            ,_("Show scripts")      ,true);
76     $this->AddCheckBox("ShowHooks"      , _("Display FAI hooks")              ,_("Show hooks")        ,true);
77     $this->AddCheckBox("ShowVariables"  , _("Display FAI variables")          ,_("Show variables")    ,true);
78     $this->AddCheckBox("ShowPackages"   , _("Display FAI packages")           ,_("Show packages")     ,true);
79     $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions")         ,_("Show partitions")   ,true);
81     /* Add SubSearch checkbox */
82     //$this->AddCheckBox(SEPERATOR);
83     //$this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), 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 = ("" != search_config($this->config->data,"faiManagement","POSTREMOVE"));
98       $c = ("" != search_config($this->config->data,"faiManagement","POSTCREATE"));
100       $smarty = get_smarty();
101       $smarty->assign("allow_create", $c);
102       $smarty->assign("allow_remove", $r);
103       $smarty->assign("selectedBranch",$this->selectedBranch);
104       $smarty->assign("branchimage","images/branch.png");
105       $smarty->assign("branches",$this->AvailableBranches);
106       $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
107     }
108     return($str);
109   }
111   function GenHeader()
112   {
113     /* Prepare departments,
114        which are shown in the listbox on top of the listbox
115      */
116     $options= "";
118     /* Get all departments within this subtree */
119     $ui= get_userinfo();
120     $first = "";
121     $found = FALSE;
122     $base = $this->config->current['BASE'];
124     /* Add base */
125     $tmp = array();
126     $tmp[] = array("dn"=>$this->config->current['BASE']);
127     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
128                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
130     $deps = array();
131     foreach($tmp as $tm){
132       $deps[$tm['dn']] = $tm['dn'];
133     }
135     /* Load possible departments */
136     $ui= get_userinfo();
137     $tdeps= $ui->get_module_departments("fai");
138     $ids = $this->config->idepartments;
139     $first = "";
140     $found = FALSE;
141     foreach($ids as $dep => $name){
142       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
144         /* Keep first base dn in mind, we could need this
145          *  info if no valid base was found
146          */
147         if(empty($first)) {
148           $first = $dep['dn'];
149         }
151         $value = $ids[$dep];
152         if ($this->selectedBase == $dep){
153           $found = TRUE;
154           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
155         } else {
156           $options.= "<option value='".$dep."'>$value</option>";
157         }
158       }
159     }
161     /* The currently used base is not visible with your acl setup.
162      * Set base to first useable base.
163      */
164     if(!$found){
165       $this->selectedBase = $first;
166     }
168     /* Add seperator */
169     $add_sep = false;
171     /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */ 
172     $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
174     /* Add default header */
175     $listhead = MultiSelectWindow::get_default_header();
177     $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
178     if(preg_match("/c/",$acl)){
179       $listhead .=" <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
180         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;";
181       $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
182     }
184     /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */ 
185     if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
186       $listhead .= $this->get_snapshot_header($this->selectedBase);
187     }
189     /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
190     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
191       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
192     }
194     /* Append create icons for each fai component */
195     $arr = array(
196         array("images/fai_new_partitionTable.png" , _("New partition table")  ,"Create_partition" , _("PT") , "faiPartitionTable"),
197         array("images/fai_new_script.png"         , _("New scripts")          ,"Create_script"    , _("S")  , "faiScript"),
198         array("images/fai_new_hook.png"           , _("New hooks")            ,"Create_hook"      , _("H")  , "faiHook"),
199         array("images/fai_new_variable.png"       , _("New variables")        ,"Create_variable"  , _("V")  , "faiVariable"),
200         array("images/fai_new_template.png"       , _("New templates ")       ,"Create_template"  , _("I")  , "faiTemplate"),
201         array("images/fai_new_packages.png"       , _("New package list")     ,"Create_package"   , _("PK") , "faiPackage"));
203     foreach($arr as $ar){
204       $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
205       if(preg_match("/c/",$acl)){
206         $add_sep = true;
207         $listhead .=" <input class='center' type='image' src='".$ar[0]."' align='middle' title='".$ar[1]."' name='".$ar[2]."' alt='".$ar[3]."'>&nbsp;";
208       }
209     }
211     /* Add additional seperator */
212     if($add_sep){
213       $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
214     }
215   
216     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
217                   " <input class='center' type='image' src='images/list_submit.png' align='middle' 
218                   title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
220     /* Multiple options */
221     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
222         title='"._("Remove selected fai objects")."' alt='"._("Remove fai objects")."' name='remove_multiple_fai_objects'>&nbsp;";
224     /* Add multiple copy & cut icons */
225     if(is_object($this->parent->CopyPasteHandler)){
226       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
227         title='"._("Copy selected objects")."' alt='"._("Copy fai objects")."' name='multiple_copy_fai'>&nbsp;";
228       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
229         title='"._("cut selected objects")."' alt='"._("Cut fai objects")."' name='multiple_cut_fai'>&nbsp;";
230       $listhead .= "</div>";
231     }
233     $listhead .="</div>";;
236     $this->SetListHeader($listhead);
237   }
239   /* so some basic settings */
240   function execute()
241   {
242     $this->ClearElementsList();
243     $this->GenHeader();
244     $this->AvailableBranches = $this->parent->getBranches();
245   }
247   function setEntries($list)
248   {
249     /********************
250       Variable init
251      ********************/
253      $objects = array(
254            "FAIpartitionTable"  => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>"Partition table","KZL"=> "PT", "VAR"=>"ShowPartitions"),
255            "FAIpackageList"     => array("IMG"=> "images/fai_packages.png",       "NAME"=>"Package list" ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
256            "FAIscript"          => array("IMG"=> "images/fai_script.png",         "NAME"=>"Scripts" ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
257            "FAIvariable"        => array("IMG"=> "images/fai_variable.png",       "NAME"=>"Variables" ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
258            "FAIhook"            => array("IMG"=> "images/fai_hook.png",           "NAME"=>"Hooks",          "KZL"=> "H",  "VAR"=>"ShowHooks"),
259            "FAIprofile"         => array("IMG"=> "images/fai_profile.png",        "NAME"=>"Profile" ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
260            "FAItemplate"        => array("IMG"=> "images/fai_template.png",       "NAME"=>"Templates" ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"));
262     $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
264     /* Dynamic action col, depending on snapshot icons */
265     $action_col_size = 50;
266     if($this->parent->snapshotEnabled()){
267       $action_col_size += 20;
268     }
270     /********************
271       Attach objects
272      ********************/
274     $cnts = array();
275     foreach($objects as $key => $data){
276       $cnts[$key] = 0;
277     }
279      foreach($list as $key => $value){
280        $info     = "";
281        $img      = "";
282        $type     = $value['type'];
283        $abort    =false;
285        $cnts[$type] ++;
287        if(isset($objects[$type])){
288          $img   = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
289          $info  = $objects[$type]['NAME'];
290          $var   = $objects[$type]['VAR'];
291        }else{
292          $img   = "<img class='center' src='images/empty.png' alt=''>";
293          $info  = "";
294          $var   = "";
295        }
297        if((isset($value['description']))&&(!empty($value['description']))){
298          $desc= " [".$value['description']."]";
299        }else{
300          $desc= "";
301        }
304        if($value['FAIstate'] == "freeze"){
305          $action=  "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
306          $action.= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
307            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
308        }else{
309          $action= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
310            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
312          if(preg_match("/(c&w)/",$value['acl'])){
313            $action.= $this->GetSnapShotActions($value['dn']);;
314          }
316          if(preg_match("/d/",$value['acl'])){
317            $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
318              name='entry_delete_%KEY%' title='"._("Delete class")."'>";
319          }
320        }
322        $edi = $editlink;
323        $acti = $action;
325        /* Cutted objects should be displayed in light grey */
326        $display = $value['cn'].$desc;
327        if($this->parent->CopyPasteHandler){
328          foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
329            if($queue_data['dn'] == $value['dn']) {
330              $display = "<font color='#999999'>".$display."</font>";
331              break;
332            }
333          }
334        }
336        /* Create each field */
337        $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
338            "attach" => "style='width:20px;'");
339        $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
340        $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', '&nbsp;', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
341        $field3 = array("string" => $info, "attach" => "style='width:200px;'");
342        $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
343        $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
344      }
346      /* Create summary string for list footer */
347      $num_deps=0;
348      if(!$this->SubSearch){
349        $num_deps = count($this->Added_Departments);
350      }
352      /* Profile */
353      $str = $cnts['FAIprofile']." ";
354      $cnts['FAIprofile']        != 1  ? $str.=_("Profiles").", "    : $str .= _("Profile").", ";
356      /* Scripts */
357      $str.= $cnts['FAIpartitionTable']." ";
358      $cnts['FAIpartitionTable'] != 1  ? $str.=_("Partitions").", "  : $str .= _("Partition").", ";
360      /* Scripts */
361      $str.= $cnts['FAIscript']." ";
362      $cnts['FAIscript']         != 1  ? $str.=_("Scripts").", "     : $str .= _("Script").", ";
364      /* Hooks */
365      $str.= $cnts['FAIhook']." ";
366      $cnts['FAIhook']           != 1  ? $str.=_("Hooks").", "       : $str .= _("Hook").", ";
368      /* Variables */
369      $str.= $cnts['FAIvariable']." ";
370      $cnts['FAIvariable']       != 1  ? $str.=_("Variables").", "   : $str .= _("Variable").", ";
372      /* Templates */
373      $str.= $cnts['FAItemplate']." ";
374      $cnts['FAItemplate']       != 1  ? $str.=_("Templates").", "   : $str .= _("Template").", ";
376      /* Packages */
377      $str.= $cnts['FAIpackageList']." ";
378      $cnts['FAIpackageList']    != 1  ? $str.=_("Package lists").", ": $str .= _("Package list").", ";
380      $str.= $num_deps." ";
381      $num_deps       != 1  ? $str.=_("Departments")    : $str .= _("Department");
382      $this->set_List_Bottom_Info($str);
384   }
386   function Save()
387   {
388     MultiSelectWindow::Save();  
389   }
391   function save_object()
392   {
393     /* Save automatic created POSTs like regex, checkboxes */
394     MultiSelectWindow::save_object(); 
395     $_SESSION['faifilter']['branch'] = $this->selectedBranch; 
396   }
398 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
399 ?>