Code

Updated post handling
[gosa.git] / gosa-core / plugins / admin / ogroups / class_ogroupManagement.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class ogroupManagement extends management
24 {
25     var $plHeadline     = "Object groups";
26     var $plDescription  = "Combine different types of objects to make use of this relationship";
27     var $plIcon  = "plugins/ogroups/images/plugin.png";
29     // Tab definition 
30     protected $tabClass = "ogrouptabs";
31     protected $tabType = "OGROUPTABS";
32     protected $aclCategory = "ogroups";
33     protected $aclPlugin   = "ogroup";
34     protected $objectName   = "object group";
36     function __construct($config,$ui)
37     {
38         $this->config = $config;
39         $this->ui = $ui;
41         $this->storagePoints = array(get_ou("group", "ogroupRDN"));
43         // Build filter
44         if (session::global_is_set(get_class($this)."_filter")){
45             $filter= session::global_get(get_class($this)."_filter");
46         } else {
47             $filter = new filter(get_template_path("ogroup-filter.xml", true));
48             $filter->setObjectStorage($this->storagePoints);
49         }
50         $this->setFilter($filter);
52         // Build headpage
53         $headpage = new listing(get_template_path("ogroup-list.xml", true));
54         $headpage->registerElementFilter("filterProperties", "ogroupManagement::filterProperties");
55         $headpage->setFilter($filter);
57         // Add copy&paste and snapshot handler.
58         if ($this->config->boolValueIsTrue("core", "copyPaste")){
59             $this->cpHandler = new CopyPasteHandler($this->config);
60         }
61         if($this->config->get_cfg_value("core","enableSnapshots") == "true"){
62             $this->snapHandler = new SnapshotHandler($this->config);
63         }
64         parent::__construct($config, $ui, "ogroups", $headpage);
66         $this->registerAction("edit_ogroup","editEntry");
67         $this->registerAction("edit_phonequeue","editEntry");
68         $this->registerAction("edit_workstartup","editEntry");
69         $this->registerAction("edit_termgroup","editEntry");
71         $this->registerAction("sendMessage", "sendMessage");
72         $this->registerAction("saveEventDialog", "saveEventDialog");
73         $this->registerAction("abortEventDialog", "closeDialogs");
74     }
77     // Inject user actions
78     function detectPostActions()
79     {
80         $action = management::detectPostActions();
82         if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEventDialog";
83         if(isset($_POST['abort_event_dialog'])) $action['action'] = "abortEventDialog";
84         return($action);
85     }
88     function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
89     {
90         $str = management::editEntry($action,$target);
91         if(preg_match("/^edit_/",$action)){
92             $tab = preg_replace("/^edit_/","",$action);
93             if(isset($this->tabObject->by_object[$tab])){
94                 $this->tabObject->current = $tab;
95             }else{
96                 trigger_error("Unknown tab: ".$tab);
97             }
98         }
99         if(!empty($str)) return($str);
100     }
103     /*! \brief  Sends a message to a set of users using gosa-si events.
104      */
105     function saveEventDialog()
106     {
107         $this->dialogObject->save_object();
108         $msgs = $this->dialogObject->check();
109         if(count($msgs)){
110             msg_dialog::displayChecks($msgs);
111         }else{
112             $o_queue = new gosaSupportDaemon();
113             $o_queue->append($this->dialogObject);
114             if($o_queue->is_error()){
115                 msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
116             }
117             $this->closeDialogs();
118         }
119     }
122     /*! \brief  Sends a message to a set of users using gosa-si events.
123      */
124     function sendMessage($action="",$target=array(),$all=array())
125     {
127         if(class_available("DaemonEvent_notify")){
129             // Resolv targets  
130             $targets = array();
131             $m_list  = array();
132             $ldap = $this->config->get_ldap_link();
134             // Collect selected ogroups
135             foreach($target as $dn){
136                 $ldap->cat($dn, array('member'));
137                 while ($entry = $ldap->fetch()) {
138                     $m_list[] = $entry;
139                 }
140             }
142             // Collect object group member dns
143             foreach($m_list as $entry){
144                 $members = $entry['member'];
145                 for($i=0;$i<$members['count'];$i++) {
147                     // Fetch member object
148                     $ldap->cat($members[$i], array('uid','cn','objectClass'));
149                     if ($ldap->count() > 0) {
151                         // Determine which type the object has
152                         $attrs = $ldap->fetch();
153                         if (array_search('gosaAccount', $attrs['objectClass'])) {
154                             $uid = $attrs['uid'][0];
155                             $targets['USERS'][] = $uid;
156                         }elseif (array_search('posixGroup', $attrs['objectClass'])) {
157                             $group = $attrs['cn'][0];
158                             $targets['GROUPS'][] = $group;
159                         }
160                     }
161                 }
162             }
164             // We've at least one recipient
165             if(count($targets)){
166                 $events = DaemonEvent::get_event_types(USER_EVENT);
167                 if(isset($events['BY_CLASS']['DaemonEvent_notify'])){
168                     $type = $events['BY_CLASS']['DaemonEvent_notify'];
169                     $this->dialogObject = new $type['CLASS_NAME']($this->config);
170                     $this->dialogObject->add_targets($targets);
171                     $this->dialogObject->set_type(TRIGGERED_EVENT);
172                 }
173             }
175         }
176     }
178     static function filterProperties($row, $gosaGroupObjects)
179     {
181         $conv= array(
182                 "Y" => array("plugins/users/images/select_template.png",_("Templates") , "ogroup"),
183                 "U" => array("plugins/generic/images/head.png"        ,_("User")        , "ogroup"),
184                 "G" => array("plugins/groups/images/select_group.png"       ,_("Group")       , "ogroup"),
185                 "A" => array("plugins/ogroups/images/application.png" ,_("Application") , "ogroup"),
186                 "D" => array("plugins/departments/department.png"     ,_("Department")  , "ogroup"),
187                 "S" => array("plugins/ogroups/images/server.png"      ,_("Server")      , "ogroup"),
188                 "F" => array("plugins/ogroups/images/asterisk.png"    ,_("Phone")       , "phonequeue"),
189                 "W" => array("plugins/ogroups/images/workstation.png" ,_("Workstation") , "workstartup"),
190                 "O" => array("plugins/ogroups/images/winstation.png"  ,_("Windows Install") , "ogroup"),
191                 "T" => array("plugins/ogroups/images/terminal.png"    ,_("Terminal")    , "termgroup"),
192                 "P" => array("plugins/ogroups/images/printer.png"     ,_("Printer")     , "ogroup"));
194         $types = preg_replace("/[^a-z]/i","",$gosaGroupObjects[0]);
195         $result ="";
196         for($i = 0 ; $i < strlen($types); $i++){
197             $type = $types[$i];
198             $result.= image($conv[$type][0], 'listing_edit_'.$conv[$type][2].'_'.$row,$conv[$type][1]);
199         }
200         return($result);
201     }
202
203 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
204 ?>