6 * This file is part of FusionForge.
8 * FusionForge 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.
13 * FusionForge 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.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Portions Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
23 * Portions Copyright 2010 (c) Mélanie Le Bail
26 require_once 'plugins_utils.php';
27 require_once 'common/system_event/SystemEvent.class.php';
28 require_once 'common/event/Event.class.php';
29 require_once 'MailmanList.class.php';
30 require_once 'MailmanListFactory.class.php';
31 require_once 'MailmanListDao.class.php';
32 require_once 'common/dao/CodendiDataAccess.class.php';
34 require_once 'mailman/include/events/SystemEvent_MAILMAN_LIST_CREATE.class.php';
35 require_once 'mailman/include/events/SystemEvent_MAILMAN_LIST_DELETE.class.php';
38 class mailmanPlugin extends Plugin {
39 public function __construct($id=0) {
41 //$this->setScope(Plugin::SCOPE_PROJECT);
42 $this->name = "mailman" ;
43 $this->text = "Mailman" ; // To show in the tabs, use...
44 $this->_addHook("user_personal_links");//to make a link to the user�s personal part of the plugin
45 $this->_addHook("usermenu") ;
46 $this->_addHook("groupmenu"); // To put into the project tabs
47 $this->_addHook("groupisactivecheckbox") ; // The "use ..." checkbox in editgroupinfo
48 $this->_addHook("groupisactivecheckboxpost") ; //
49 $this->_addHook("userisactivecheckbox") ; // The "use ..." checkbox in user account
50 $this->_addHook("userisactivecheckboxpost") ; //
51 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
52 $this->_addHook("monitored_element"); // to show monitored items in my page
53 $this->_addHook("group_delete"); // to delete mailing list associated when deleting a group
54 $this->_addHook("group_approve"); // to create mailing list 'Commit' when creating a group
55 $this->_addHook('site_admin_option_hook');
56 $this->_addHook(Event::GET_SYSTEM_EVENT_CLASS,'getSystemEventClass', false);//to make SystemEvent manager knows about mailman plugin
61 echo '<h1>Mailman</h1>';
62 echo $this->getPluginInfo()->getpropVal('answer');
65 function getPluginInfo() {
66 if (!is_a($this->pluginInfo, 'MailmanPluginInfo')) {
67 require_once 'MailmanPluginInfo.class.php';
68 $this->pluginInfo = new MailmanPluginInfo($this);
70 return $this->pluginInfo;
73 function CallHook ($hookname, &$params) {
74 global $use_mailmanplugin,$G_SESSION,$HTML,$gfcommon,$gfwww,$gfplugins;
75 if ($hookname == "usermenu") {
76 $text = $this->text; // this is what shows in the tab
77 if ($G_SESSION->usesPlugin("mailman")) {
78 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
79 echo ' | ' . $HTML->PrintSubMenu (array ($text),
80 array ('/plugins/mailman/index.php' . $param ));
82 } elseif ($hookname == "groupmenu") {
83 $group_id=$params['group'];
84 $project = &group_get_object($group_id);
85 if (!$project || !is_object($project)) {
88 if ($project->isError()) {
91 if (!$project->isProject()) {
94 if ( $project->usesPlugin ( $this->name ) ) {
95 $params['TITLES'][]=$this->text;
96 $params['DIRS'][]='/plugins/mailman/index.php?group_id=' . $group_id . "&pluginname=" . $this->name; // we indicate the part we�re calling is the project one
97 $params['ADMIN'][]='';
99 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
100 } elseif ($hookname == "groupisactivecheckbox") {
101 //Check if the group is active
102 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
103 $group_id=$params['group'];
104 $group = &group_get_object($group_id);
107 echo ' <input type="CHECKBOX" name="use_mailmanplugin" value="1" ';
108 // CHECKED OR UNCHECKED?
109 if ( $group->usesPlugin ( $this->name ) ) {
115 echo "<strong>Use ".$this->text." Plugin</strong>";
119 } elseif ($hookname == "groupisactivecheckboxpost") {
120 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
121 $group_id=$params['group'];
122 $group = &group_get_object($group_id);
123 $use_mailmanplugin = getStringFromRequest('use_mailmanplugin');
124 if ( $use_mailmanplugin == 1 ) {
125 $group->setPluginUse ( $this->name );
127 $group->setPluginUse ( $this->name, false );
129 } elseif ($hookname == "user_personal_links") {
130 // this displays the link in the user's profile page to it's personal mailman (if you want other sto access it, youll have to change the permissions in the index.php
131 $userid = $params['user_id'];
132 $user = user_get_object($userid);
133 //check if the user has the plugin activated
134 if ($user->usesPlugin($this->name)) {
136 echo util_make_link ("/plugins/mailman/index.php?id=$userid&type=user&pluginname=".$this->name,
137 _('View Personal mailman')
141 } elseif ($hookname == "project_admin_plugins") {
142 // this displays the link in the project admin options page to it's mailman administration
143 $group_id = $params['group_id'];
144 $group = &group_get_object($group_id);
145 if ( $group->usesPlugin ( $this->name ) ) {
146 echo '<p>'.util_make_link ("/plugins/".$this->name."/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
147 _('View the mailman Administration')).'</p>';
150 elseif ($hookname == "monitored_element") {
151 $current_user=UserManager::instance()->getCurrentUser();
153 $order_name_arr=array();
154 $order_name_arr[]=_('Remove');
155 $order_name_arr[]=_('Monitored Lists');
156 echo $HTML->listTableTop($order_name_arr);
157 $dao = new MailmanListDao(CodendiDataAccess::instance());
158 $result = $dao->listsMonitoredByUser($current_user->getEmail());
159 for ($i=0; $i<$result->rowCount(); $i++) {
160 $listResult = $result->getRow();
161 $list = new MailmanList($listResult['group_id'],$listResult['group_list_id']);
162 if ($list->isError()) {
163 $this->setError($list->getErrorMessage());
168 if (count($lists) < 1) {
169 echo '<tr><td colspan="2"><strong>'._('You are not monitoring any lists.').'</strong></td></tr>';
171 echo '<tr><td colspan="2"><strong>'.util_make_link ('/plugins/mailman',_('My Monitored Lists')).'</strong></td></tr>';
172 foreach ($lists as $l) {
173 $group = $l->getGroup();
174 if ($group->getID() != $last_group) {
175 echo ' <tr '. $HTML->boxGetAltRowStyle(1) .'><td colspan="2">'.util_make_link ('/plugins/mailman/index.php?group_id='.$group->getID(),$group->getPublicName()).'</td></tr>';
178 <tr '.$HTML->boxGetAltRowStyle(0).'><td class="align-center"><a href="/plugins/mailman/index.php?group_id='.$group->getID().
179 '&action=unsubscribe&id='.$l->getID().'">' .
180 '<img src="'.$HTML->imgroot.'/ic/trash.png" height="16" width="16" '.'border="0" alt="" /></a>' .
181 '</td><td width="99%"><a href="/plugins/mailman/index.php?group_id='.$group->getID().'&action=options&id='.$l->getID().'">'.
182 $l->getName().'"</a></td></tr>';
183 $last_group= $group->getID();
186 echo $HTML->listTableBottom();
189 elseif ($hookname == "group_delete") {
190 $group_id = $params['group_id'];
191 $group = &group_get_object($group_id);
192 $mlf = new MailmanListFactory($group);
193 $ml_arr =& $mlf->getMailmanLists();
194 for ($i=0; $i<count($ml_arr); $i++) {
195 if (!is_object($ml_arr[$i])) {
196 printf (_("Not Object: MailmanList: %d"),$i);
199 if (!$ml_arr[$i]->deleteList(1,1)) {
200 $this->setError(_('Could not properly delete the mailing list'));
202 //echo 'MailmanListFactory'.db_error();
205 elseif ($hookname == "group_approve") {
206 $idadmin_group =$params[0];
207 $group_id=$params[1];
208 $group = &group_get_object($group_id);
209 $mlist = new MailmanList($group);
210 if (!$mlist->create('commits','Commits',1,$idadmin_group)) {
211 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
216 // TODO : WTF ? : I think this should probably be gotten rid of -- OlivierBerger
217 elseif ($hookname=='site_admin_option_hook') {
218 echo '<li><a href="'.$this->getPluginPath().'/">Template [' . _('Mailman plugin') . ']</a></li>';
224 function getSystemEventClass($params) {
226 switch($params['type']) {
227 case 'MAILMAN_LIST_CREATE' :
229 require_once(dirname(__FILE__).'/events/SystemEvent_MAILMAN_LIST_CREATE.class.php');
231 $params['class'] = 'SystemEvent_MAILMAN_LIST_CREATE';
233 case 'MAILMAN_LIST_DELETE' :
234 require_once(dirname(__FILE__).'/events/SystemEvent_MAILMAN_LIST_DELETE.class.php');
235 $params['class'] = 'SystemEvent_MAILMAN_LIST_DELETE';
251 // c-file-style: "bsd"