Code

Removed duplicated addslashes
[gosa.git] / plugins / admin / groups / class_divListGroup.inc
1 <?php
3 class divListGroup extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
12   var $UserRegex          = "*";
14   /* CheckBoxes, to change default values modify $this->AddCheckBox */
15   var $ShowPrimaryGroups;
16   var $ShowSambaGroups;  
17   var $ShowApplicationGroups; 
18   var $ShowMailGroups;
19   var $ShowFunctionalGroups;
21   /* Subsearch checkbox */
22   var $SubSearch              = false;
24   var $parent             ;
25   var $ui                 ;
27   function divListGroup ($config,$parent)
28   {
29     MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
30     
31     $this->parent       = $parent;
32     $this->ui           = get_userinfo();
34     /* Set list strings */
35     $this->SetTitle(_("List of groups"));
36     $this->SetSummary(_("List of groups"));
37     $this->EnableAplhabet   (true);
39     /* Result page will look like a headpage */
40     $this->SetHeadpageMode();
41     $this->SetInformation(_("This menu allows you to add, edit and remove selected groups. You may want to use the range selector on top of the group listbox, when working with a large number of groups."));
42   
43     /* Disable buttonsm */
44     $this->EnableCloseButton(false);
45     $this->EnableSaveButton (false);
47     /* Dynamic action col, depending on snapshot icons */
48     $action_col_size = 70;
49     if($this->parent->snapshotEnabled()){
50       $action_col_size += 38;
51     }
53     /* set Page header */
54     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
55     $this->AddHeader(array("string"=>_("Groupname / Department")));
56     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
57     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
59     /*                  Text        ,Value    ,Name         ,Is selected */
60     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"),          _("Show primary groups"),      true);
61     $this->AddCheckBox("ShowSambaGroups",       _("Select to see groups that have samba groups mappings"),          _("Show samba groups"),      true);
62     $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"),        _("Show application groups"),true);
63     $this->AddCheckBox("ShowMailGroups",        _("Select to see groups that have mail settings"),                  _("Show mail groups"),       true);
64     $this->AddCheckBox("ShowFunctionalGroups",  _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
65     $this->AddCheckBox(SEPERATOR);
67     /* Add SubSearch checkbox */    
68     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
70     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
71     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
72     $this->AddRegex   ("UserRegex", _("User name of which groups are shown"),         "*" , false, "images/search_user.png");
73   }
76   function GenHeader()
77   {
78     /* Prepare departments,
79        which are shown in the listbox on top of the listbox
80      */
81     $options= "";
84     
85     /* Get all departments within this subtree */
86     $base = $this->config->current['BASE'];
87     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
88                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
90     /* Load possible departments */
91     $ui= get_userinfo();
92     $tdeps= $ui->get_module_departments("groups");
94     $ids = $this->config->idepartments;
96     foreach($deps as $dep){
97       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
99         $value = $ids[$dep['dn']];
100         if ($this->selectedBase == $dep['dn']){
101           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
102         } else {
103           $options.= "<option value='".$dep['dn']."'>$value</option>";
104         }
105       }
106     }
108     $acls  = $ui->get_permissions($this->selectedBase,"groups/group");
110     /* Get copy & paste icon */
111     if(preg_match("/w/",$acls) &&  $this->parent->CopyPasteHandler){
112       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
113     }else{
114       $Copy_Paste ="";
115     }
117     // Managment
118     $listhead = "
119       <div style='background:#F0F0F9;padding:5px;'>".
120       " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
121       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
122       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
123       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
124       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;";
126     if(preg_match("/c/",$acls) && preg_match("/w/",$acls)){
127       $listhead .= $this->get_snapshot_header($this->selectedBase);
128     }else{
129       $listhead .= "<img class='center' src='images/restore_grey.png' alt=''>&nbsp;";
130     }
132     if(preg_match("/c/",$acls)) {
133       $listhead.=" <input type='image' class='center' src='images/list_new_group.png' 
134         title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;";
135     }
137     $listhead.=      $Copy_Paste.
138       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
139       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
140       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
141       "'>&nbsp;".
142       "</div>";
144     $this->SetListHeader($listhead);
145   }
147   function execute()
148   {
149     $this->ClearElementsList();
150     $this->GenHeader();
151   }
153   function setEntries($groups)
154   {
155     // Defining Links
156     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
158     // image Buttons
159     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
160     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
162     /* Dynamic action col, depending on snapshot icons */
163     $action_col_size = 70;
164     if($this->parent->snapshotEnabled()){
165       $action_col_size += 38;
166     }
168     /* Assign extension images */
169     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
170                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
171     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
172                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
173     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
174                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
175     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
176                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
177     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
178                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
179     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
180                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
182     // Space
183     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
185     // User and Template  Images
186     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
188     $ui = get_userinfo();
190     // Test Every Entry and generate divlist Array
191     foreach($groups as $key => $val){
192     
193       /* Create action icons - copy & paste icons */
194       $actions= "";
195       if(($this->parent->CopyPasteHandler) && preg_match("/w/",$ui->get_category_permissions($val['dn'],"group"))){
196         $actions.= "<input class='center' type='image'
197           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
198         $actions.= "<input class='center' type='image'
199           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
200       }
202       $actions.= "<input class='center' type='image'
203         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
205       if(preg_match("/w/",$ui->get_permissions($val['dn'],"groups/group"))){
206         $actions.= $this->GetSnapShotActions($val['dn']);
207       }
209       if(preg_match("/d/",$ui->get_permissions($val['dn'],"groups/group"))){
210         $actions.= "<input class='center' type='image'
211           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
212       }
215       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
217       if(isset($val['objectClass'])){
218         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
219         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
220         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
221         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
222         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
223         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
224       }
226       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
228       if(!isset($val['description'][0])){
229         $desc = "";
230       }else{
231         $desc = " - [ ".$val['description'][0]." ]";
232       }
234       /* FAIrelease tag from groupApplications */
235       if(isset($val['FAIrelease'][0])){
236         $desc .= " (".$val['FAIrelease'][0].")";
237       }
239       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
240       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
241       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
242       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
244       $this->AddElement(array($field1,$field2,$field3,$field4));
245     }
246   }
248   function Save()
249   {
250     MultiSelectWindow :: Save();  
251   }
253   function save_object()
254   {
255     /* Save automatic created POSTs like regex, checkboxes */
256     MultiSelectWindow::save_object();   
257   }
259 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
260 ?>