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
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
98 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
99 } elseif ($hookname == "groupisactivecheckbox") {
100 //Check if the group is active
101 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
102 $group_id=$params['group'];
103 $group = &group_get_object($group_id);
106 echo ' <input type="CHECKBOX" name="use_mailmanplugin" value="1" ';
107 // CHECKED OR UNCHECKED?
108 if ( $group->usesPlugin ( $this->name ) ) {
114 echo "<strong>Use ".$this->text." Plugin</strong>";
118 } elseif ($hookname == "groupisactivecheckboxpost") {
119 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
120 $group_id=$params['group'];
121 $group = &group_get_object($group_id);
122 $use_mailmanplugin = getStringFromRequest('use_mailmanplugin');
123 if ( $use_mailmanplugin == 1 ) {
124 $group->setPluginUse ( $this->name );
126 $group->setPluginUse ( $this->name, false );
128 } elseif ($hookname == "user_personal_links") {
129 // 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
130 $userid = $params['user_id'];
131 $user = user_get_object($userid);
132 $text = $params['text'];
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/projects_hierarchy/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 elseif ($hookname=='site_admin_option_hook') {
217 echo '<li><a href="'.$this->getPluginPath().'/">Template</a></li>';
223 function getSystemEventClass($params) {
225 switch($params['type']) {
226 case 'MAILMAN_LIST_CREATE' :
228 require_once(dirname(__FILE__).'/events/SystemEvent_MAILMAN_LIST_CREATE.class.php');
230 $params['class'] = 'SystemEvent_MAILMAN_LIST_CREATE';
232 case 'MAILMAN_LIST_DELETE' :
233 require_once(dirname(__FILE__).'/events/SystemEvent_MAILMAN_LIST_DELETE.class.php');
234 $params['class'] = 'SystemEvent_MAILMAN_LIST_DELETE';
250 // c-file-style: "bsd"