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 GForge; 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';
36 class mailmanPlugin extends Plugin {
37 public function __construct($id=0) {
39 //$this->setScope(Plugin::SCOPE_PROJECT);
40 $this->name = "mailman" ;
41 $this->text = "Mailman" ; // To show in the tabs, use...
42 $this->_addHook("user_personal_links");//to make a link to the user�s personal part of the plugin
43 $this->_addHook("usermenu") ;
44 $this->_addHook("groupmenu"); // To put into the project tabs
45 $this->_addHook("groupisactivecheckbox") ; // The "use ..." checkbox in editgroupinfo
46 $this->_addHook("groupisactivecheckboxpost") ; //
47 $this->_addHook("userisactivecheckbox") ; // The "use ..." checkbox in user account
48 $this->_addHook("userisactivecheckboxpost") ; //
49 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
50 $this->_addHook("monitored_element"); // to show monitored items in my page
51 $this->_addHook("group_delete"); // to delete mailing list associated when deleting a group
52 $this->_addHook("group_approve"); // to create mailing list 'Commit' when creating a group
53 $this->_addHook('site_admin_option_hook');
54 $this->_addHook(Event::GET_SYSTEM_EVENT_CLASS,'getSystemEventClass', false);//to make SystemEvent manager knows about mailman plugin
59 echo '<h1>Mailman</h1>';
60 echo $this->getPluginInfo()->getpropVal('answer');
63 function getPluginInfo() {
64 if (!is_a($this->pluginInfo, 'MailmanPluginInfo')) {
65 require_once('MailmanPluginInfo.class.php');
66 $this->pluginInfo =& new MailmanPluginInfo($this);
68 return $this->pluginInfo;
71 function CallHook ($hookname, $params) {
72 global $use_mailmanplugin,$G_SESSION,$HTML,$gfcommon,$gfwww,$gfplugins;
73 if ($hookname == "usermenu") {
74 $text = $this->text; // this is what shows in the tab
75 if ($G_SESSION->usesPlugin("mailman")) {
76 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we�re calling is the user one
77 echo ' | ' . $HTML->PrintSubMenu (array ($text),
78 array ('/plugins/mailman/index.php' . $param ));
80 } elseif ($hookname == "groupmenu") {
81 $group_id=$params['group'];
82 $project = &group_get_object($group_id);
83 if (!$project || !is_object($project)) {
86 if ($project->isError()) {
89 if (!$project->isProject()) {
92 if ( $project->usesPlugin ( $this->name ) ) {
93 $params['TITLES'][]=$this->text;
94 $params['DIRS'][]='/plugins/mailman/index.php?group_id=' . $group_id . "&pluginname=" . $this->name; // we indicate the part we�re calling is the project one
96 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
97 } elseif ($hookname == "groupisactivecheckbox") {
98 //Check if the group is active
99 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
100 $group_id=$params['group'];
101 $group = &group_get_object($group_id);
104 echo ' <input type="CHECKBOX" name="use_mailmanplugin" value="1" ';
105 // CHECKED OR UNCHECKED?
106 if ( $group->usesPlugin ( $this->name ) ) {
112 echo "<strong>Use ".$this->text." Plugin</strong>";
116 } elseif ($hookname == "groupisactivecheckboxpost") {
117 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
118 $group_id=$params['group'];
119 $group = &group_get_object($group_id);
120 $use_mailmanplugin = getStringFromRequest('use_mailmanplugin');
121 if ( $use_mailmanplugin == 1 ) {
122 $group->setPluginUse ( $this->name );
124 $group->setPluginUse ( $this->name, false );
126 } elseif ($hookname == "userisactivecheckbox") {
127 //check if user is active
128 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
129 $user = $params['user'];
132 echo ' <input type="CHECKBOX" name="use_mailmanplugin" value="1" ';
133 // CHECKED OR UNCHECKED?
134 if ( $user->usesPlugin ( $this->name ) ) {
137 echo "> Use ".$this->text." Plugin";
140 } elseif ($hookname == "userisactivecheckboxpost") {
141 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
142 $user = $params['user'];
143 $use_mailmanplugin = getStringFromRequest('use_mailmanplugin');
144 if ( $use_mailmanplugin == 1 ) {
145 $user->setPluginUse ( $this->name );
147 $user->setPluginUse ( $this->name, false );
151 echo ' <input type="CHECKBOX" name="use_mailmanplugin" value="1" ';
152 // CHECKED OR UNCHECKED?
153 if ( $user->usesPlugin ( $this->name ) ) {
156 echo "> Use ".$this->text." Plugin";
159 } elseif ($hookname == "user_personal_links") {
160 // 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
161 $userid = $params['user_id'];
162 $user = user_get_object($userid);
163 $text = $params['text'];
164 //check if the user has the plugin activated
165 if ($user->usesPlugin($this->name)) {
167 echo util_make_link ("/plugins/mailman/index.php?id=$userid&type=user&pluginname=".$this->name,
168 _('View Personal mailman')
172 } elseif ($hookname == "project_admin_plugins") {
173 // this displays the link in the project admin options page to it�s mailman administration
174 $group_id = $params['group_id'];
175 $group = &group_get_object($group_id);
176 if ( $group->usesPlugin ( $this->name ) ) {
177 echo util_make_link ("/plugins/projects_hierarchy/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
178 _('View the mailman Administration')) ;
182 elseif ($hookname == "monitored_element") {
183 $current_user=UserManager::instance()->getCurrentUser();
185 $order_name_arr=array();
186 $order_name_arr[]=_('Remove');
187 $order_name_arr[]=_('Monitored Lists');
188 echo $HTML->listTableTop($order_name_arr);
189 $dao = & new MailmanListDao(CodendiDataAccess::instance());
190 $result = $dao->listsMonitoredByUser($current_user->getEmail());
191 for ($i=0; $i<$result->rowCount(); $i++) {
192 $listResult = $result->getRow();
193 $list =& new MailmanList($listResult['group_id'],$listResult['group_list_id']);
194 if ($list->isError()) {
195 $this->setError($list->getErrorMessage());
200 if (count($lists) < 1) {
201 echo '<tr><td colspan="2"><strong>'._('You are not monitoring any lists.').'</strong></td></tr>';
203 echo '<tr><td colspan="2"><strong>'.util_make_link ('/plugins/mailman',_('My Monitored Lists')).'</strong></td></tr>';
204 foreach ($lists as $l) {
205 $group = $l->getGroup();
206 if ($group->getID() != $last_group) {
207 echo ' <tr '. $HTML->boxGetAltRowStyle(1) .'><td colspan="2">'.util_make_link ('/plugins/mailman/index.php?group_id='.$group->getID(),$group->getPublicName()).'</td></tr>';
210 <tr '.$HTML->boxGetAltRowStyle(0).'><td class="align-center"><a href="/plugins/mailman/index.php?group_id='.$group->getID().
211 '&action=unsubscribe&id='.$l->getID().'">' .
212 '<img src="'.$HTML->imgroot.'/ic/trash.png" height="16" width="16" '.'border="0" alt="" /></a>' .
213 '</td><td width="99%"><a href="/plugins/mailman/index.php?group_id='.$group->getID().'&action=options&id='.$l->getID().'">'.
214 $l->getName().'"</a></td></tr>';
215 $last_group= $group->getID();
218 echo $HTML->listTableBottom();
221 elseif ($hookname == "group_delete") {
222 $group_id = $params['group_id'];
223 $group = &group_get_object($group_id);
224 $mlf = new MailmanListFactory($group);
225 $ml_arr =& $mlf->getMailmanLists();
226 for ($i=0; $i<count($ml_arr); $i++) {
227 if (!is_object($ml_arr[$i])) {
228 printf (_("Not Object: MailmanList: %d"),$i);
231 if (!$ml_arr[$i]->deleteList(1,1)) {
232 $this->setError(_('Could not properly delete the mailing list'));
234 //echo 'MailmanListFactory'.db_error();
237 elseif ($hookname == "group_approve") {
238 $idadmin_group =$params[0];
239 $group_id=$params[1];
240 $group = &group_get_object($group_id);
241 $mlist = new MailmanList($group);
242 if (!$mlist->create('commits','Commits',1,$idadmin_group)) {
243 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
248 elseif ($hookname=='site_admin_option_hook') {
249 echo '<li><a href="'.$this->getPluginPath().'/">Template</a></li>';
255 function getSystemEventClass($params) {
257 switch($params['type']) {
258 case 'MAILMAN_LIST_CREATE' :
260 require_once(dirname(__FILE__).'/events/SystemEvent_MAILMAN_LIST_CREATE.class.php');
262 $params['class'] = 'SystemEvent_MAILMAN_LIST_CREATE';
264 case 'MAILMAN_LIST_DELETE' :
265 require_once(dirname(__FILE__).'/events/SystemEvent_MAILMAN_LIST_DELETE.class.php');
266 $params['class'] = 'SystemEvent_MAILMAN_LIST_DELETE';
282 // c-file-style: "bsd"