3 * Mailing Lists Facility
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2003-2004 (c) Guillaume Smet - Open Wide
7 * Copyright 2010 (c) Franck Villaume - Capgemini
8 * Copyright (C) 2011-2012 Alain Peyrat - Alcatel-Lucent
9 * Copyright 2012-2014,2016, Franck Villaume - TrivialDev
10 * http://fusionforge.org/
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 require_once '../../env.inc.php';
29 require_once $gfcommon.'include/pre.php';
30 require_once $gfwww.'mail/admin/../mail_utils.php';
32 require_once $gfcommon.'mail/MailingList.class.php';
33 require_once $gfcommon.'mail/MailingListFactory.class.php';
37 $group_id = getIntFromRequest('group_id');
40 $group = group_get_object($group_id);
41 if (!$group || !is_object($group) || $group->isError()) {
45 session_require_perm ('project_admin', $group->getID()) ;
48 // Post Changes to database
50 if (getStringFromRequest('post_changes') == 'y') {
54 if (getStringFromRequest('add_list') == 'y') {
56 if (check_email_available($group, $group->getUnixName() . '-' . getStringFromPost('list_name'), $error_msg)) {
57 $mailingList = new MailingList($group);
59 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
60 exit_form_double_submit('mail');
62 if(!$mailingList || !is_object($mailingList)) {
63 form_release_key(getStringFromRequest("form_key"));
64 exit_error(_('Error getting the list'),'mail');
65 } elseif($mailingList->isError()) {
66 form_release_key(getStringFromRequest("form_key"));
67 exit_error($mailingList->getErrorMessage(),'mail');
70 if(!$mailingList->create(
71 getStringFromPost('list_name'),
72 getStringFromPost('description'),
73 getIntFromPost('is_public', 1)
75 form_release_key(getStringFromRequest("form_key"));
76 exit_error($mailingList->getErrorMessage(),'mail');
78 $feedback .= _('List Added');
82 form_release_key(getStringFromRequest("form_key"));
87 } elseif (getStringFromPost('change_status') == 'y') {
88 $mailingList = new MailingList($group, getIntFromGet('group_list_id'));
90 if(!$mailingList || !is_object($mailingList)) {
91 exit_error(_('Error getting the list'),'mail');
92 } elseif($mailingList->isError()) {
93 exit_error($mailingList->getErrorMessage(),'mail');
96 if(!$mailingList->update(
97 unInputSpecialChars(getStringFromPost('description')),
98 getIntFromPost('is_public', MAIL__MAILING_LIST_IS_PUBLIC),
99 MAIL__MAILING_LIST_IS_UPDATED
101 exit_error($mailingList->getErrorMessage(),'mail');
103 $feedback .= _('List updated');
109 // Reset admin password
111 if (getIntFromRequest('reset_pw') == 1) {
112 $mailingList = new MailingList($group, getIntFromGet('group_list_id'));
114 if(!$mailingList || !is_object($mailingList)) {
115 exit_error(_('Error getting the list'),'mail');
116 } elseif($mailingList->isError()) {
117 exit_error($mailingList->getErrorMessage(),'mail');
120 if($mailingList->getStatus() == MAIL__MAILING_LIST_IS_CONFIGURED) {
121 if(!$mailingList->update(
122 $mailingList->getDescription(),
123 $mailingList->isPublic(),
124 MAIL__MAILING_LIST_PW_RESET_REQUESTED
126 exit_error($mailingList->getErrorMessage(),'mail');
128 $feedback .= _('Password reset requested');
136 if(getIntFromGet('add_list')) {
137 mail_header(array('title' => _('Add a Mailing List')));
139 printf(_('Lists are named in this manner:<br /><strong>projectname-listname@%s</strong>'), forge_get_config('lists_host'));
142 $mlFactory = new MailingListFactory($group);
143 if (!$mlFactory || !is_object($mlFactory) || $mlFactory->isError()) {
144 exit_error($mlFactory->getErrorMessage(),'mail');
147 $mlArray = $mlFactory->getMailingLists();
149 if ($mlFactory->isError()) {
150 echo $HTML->error_msg(_('Error').' '._('Unable to get the lists').' '.$mlFactory->getErrorMessage());
155 $tableHeaders = array(
156 _('Existing mailing lists')
161 $mlCount = count($mlArray);
163 echo $HTML->listTableTop($tableHeaders);
164 for ($j = 0; $j < $mlCount; $j++) {
165 $currentList =& $mlArray[$j];
166 if ($currentList->isError()) {
168 echo $currentList->getErrorMessage();
171 echo '<tr><td>'.$currentList->getName().'</td></tr>';
174 echo $HTML->listTableBottom();
179 echo $HTML->openForm(array('method' => 'post', 'action' => getStringFromServer('PHP_SELF').'?group_id='.$group_id)); ?>
180 <input type="hidden" name="post_changes" value="y" />
181 <input type="hidden" name="add_list" value="y" />
182 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
183 <p><strong><?php echo _('Mailing List Name').utils_requiredField()._(':'); ?></strong><br />
184 <strong><?php echo $group->getUnixName(); ?>-<input type="text" name="list_name" value="" size="10" maxlength="12" required="required" pattern="[a-zA-Z0-9]{4,}" />@<?php echo forge_get_config('lists_host'); ?></strong></p>
186 <strong><?php echo _('Is Public?'); ?></strong><br />
187 <input type="radio" id="public_yes" name="is_public" value="<?php echo MAIL__MAILING_LIST_IS_PUBLIC; ?>" checked="checked" />
188 <label for="public_yes">
189 <?php echo _('Yes'); ?>
192 <input type="radio" id="public_no" name="is_public" value="<?php echo MAIL__MAILING_LIST_IS_PRIVATE; ?>" />
193 <label for="public_no">
194 <?php echo _('No'); ?>
198 <strong><?php echo _('Description')._(':'); ?></strong><br />
199 <input type="text" name="description" value="" size="40" maxlength="80" /></p>
201 <input type="submit" name="submit" value="<?php echo _('Add This List'); ?>" /></p>
203 echo $HTML->closeForm();
207 // Form to modify list
209 } elseif(getIntFromGet('change_status') && getIntFromGet('group_list_id')) {
210 $mailingList = new MailingList($group, getIntFromGet('group_list_id'));
212 if(!$mailingList || !is_object($mailingList)) {
213 exit_error(_('Error getting the list'), 'mail');
214 } elseif($mailingList->isError()) {
215 exit_error($mailingList->getErrorMessage(), 'mail');
219 'title' => sprintf(_('Update Mailing List %s'), $mailingList->getName())));
221 <h3><?php echo $mailingList->getName(); ?></h3>
222 <?php echo $HTML->openForm(array('method' => 'post', 'action' => getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_list_id='.$mailingList->getID())); ?>
223 <input type="hidden" name="post_changes" value="y" />
224 <input type="hidden" name="change_status" value="y" />
226 <strong><?php echo _('Is Public?'); ?></strong><br />
227 <input type="radio" name="is_public" value="<?php echo MAIL__MAILING_LIST_IS_PUBLIC; ?>"<?php echo ($mailingList->isPublic() == MAIL__MAILING_LIST_IS_PUBLIC ? ' checked="checked"' : ''); ?> /> <?php echo _('Yes'); ?><br />
228 <input type="radio" name="is_public" value="<?php echo MAIL__MAILING_LIST_IS_PRIVATE; ?>"<?php echo ($mailingList->isPublic() == MAIL__MAILING_LIST_IS_PRIVATE ? ' checked="checked"' : ''); ?> /> <?php echo _('No'); ?>
231 <strong><?php echo _('Description')._(':'); ?></strong><br />
232 <input type="text" name="description" value="<?php echo inputSpecialChars($mailingList->getDescription()); ?>" size="40" maxlength="80" /></p>
234 <input type="submit" name="submit" value="<?php echo _('Update'); ?>" /></p>
236 echo $HTML->closeForm();
237 echo util_make_link('/mail/admin/deletelist.php?group_id='.$group_id.'&group_list_id='.$mailingList->getID(), '['._('Permanently Delete List').']');
243 $mlFactory = new MailingListFactory($group);
244 if (!$mlFactory || !is_object($mlFactory) || $mlFactory->isError()) {
245 exit_error($mlFactory->getErrorMessage(),'mail');
249 'title' => _('Mailing Lists Admin'))
252 $mlArray = $mlFactory->getMailingLists();
254 if ($mlFactory->isError()) {
255 echo $HTML->error_msg(_('Error').' '.sprintf(_('Unable to get the list %s'), $group->getPublicName()));
256 echo $HTML->error_msg($mlFactory->getErrorMessage());
260 echo '<p>'.sprintf(_('You can administrate lists from here. Please note that private lists can still be viewed by members of your project, but are not listed on %s.'), forge_get_config ('forge_name')).'</p>';
262 echo util_make_link(getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&add_list=1', _('Add Mailing List'));
264 $mlCount = count($mlArray);
266 $tableHeaders = array(
272 echo $HTML->listTableTop($tableHeaders);
273 for ($i = 0; $i < $mlCount; $i++) {
274 $currentList =& $mlArray[$i];
275 if ($currentList->isError()) {
276 echo '<tr><td colspan="4">';
277 echo $currentList->getErrorMessage();
281 '<strong>'.$currentList->getName().'</strong><br />'.
282 htmlspecialchars($currentList->getDescription()).'</td>';
283 echo '<td class="align-center">';
284 if ($currentList->getStatus() != MAIL__MAILING_LIST_PW_RESET_REQUESTED) {
285 echo util_make_link(getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_list_id='.$currentList->getID().'&change_status=1', _('Update'));
288 echo '<td class="align-center">';
289 if($currentList->getStatus() == MAIL__MAILING_LIST_IS_REQUESTED) {
290 echo _('Not activated yet');
292 echo util_make_link($currentList->getExternalAdminUrl(), _('Administration'), false, true);
295 echo '<td class="align-center">';
296 if($currentList->getStatus() == MAIL__MAILING_LIST_IS_CONFIGURED) {
297 echo util_make_link(getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_list_id='.$currentList->getID().'&reset_pw=1', _('Reset admin password'));
304 echo $HTML->listTableBottom();