fixes #1902 ability to set a specific group to notify user registrations

This commit is contained in:
plegall 2023-04-22 17:21:20 +02:00
parent 87926235ca
commit 4b33001c15
10 changed files with 170 additions and 19 deletions

View file

@ -43,7 +43,6 @@ $main_checkboxes = array(
'obligatory_user_mail_address', 'obligatory_user_mail_address',
'rate', 'rate',
'rate_anonymous', 'rate_anonymous',
'email_admin_on_new_user',
'allow_user_customization', 'allow_user_customization',
'log', 'log',
'history_admin', 'history_admin',
@ -199,6 +198,26 @@ if (isset($_POST['submit']))
} }
} }
if (empty($_POST['email_admin_on_new_user']))
{
$_POST['email_admin_on_new_user'] = 'none';
}
elseif ('all' == $_POST['email_admin_on_new_user_filter'])
{
$_POST['email_admin_on_new_user'] = 'all';
}
else
{
if (empty($_POST['email_admin_on_new_user_filter_group']))
{
$_POST['email_admin_on_new_user'] = 'all';
}
else
{
$_POST['email_admin_on_new_user'] = 'group:'.$_POST['email_admin_on_new_user_filter_group'];
}
}
foreach( $main_checkboxes as $checkbox) foreach( $main_checkboxes as $checkbox)
{ {
$_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
@ -372,6 +391,25 @@ switch ($page['section'])
'mail_theme_options' => $mail_themes, 'mail_theme_options' => $mail_themes,
'order_by' => $order_by, 'order_by' => $order_by,
'order_by_options' => $sort_fields, 'order_by_options' => $sort_fields,
'email_admin_on_new_user' => 'none' != $conf['email_admin_on_new_user'],
'email_admin_on_new_user_filter' => in_array($conf['email_admin_on_new_user'], array('none', 'all')) ? 'all' : 'group',
'email_admin_on_new_user_filter_group' => preg_match('/^group:(\d+)$/', $conf['email_admin_on_new_user'], $matches) ? $matches[1] : -1,
)
);
// list of groups
$query = '
SELECT
id,
name
FROM '.GROUPS_TABLE.'
;';
$groups = query2array($query, 'id', 'name');
natcasesort($groups);
$template->assign(
array(
'group_options' => $groups,
) )
); );

View file

@ -2592,6 +2592,17 @@ function delete_groups($group_ids)
return false; return false;
} }
if (preg_match('/^group:(\d+)$/', conf_get_param('email_admin_on_new_user', 'undefined'), $matches))
{
foreach ($group_ids as $group_id)
{
if ($group_id == $matches[1])
{
conf_update_param('email_admin_on_new_user', 'all', true);
}
}
}
$group_id_string = implode(',', $group_ids); $group_id_string = implode(',', $group_ids);
// destruction of the access linked to the group // destruction of the access linked to the group

View file

@ -5,7 +5,8 @@
(function(){ (function(){
var targets = { var targets = {
'input[name="rate"]' : '#rate_anonymous', 'input[name="rate"]' : '#rate_anonymous',
'input[name="allow_user_registration"]' : '#email_admin_on_new_user' 'input[name="allow_user_registration"]' : '#email_admin_on_new_user',
'input[name="email_admin_on_new_user"]' : '#email_admin_on_new_user_filter'
}; };
for (selector in targets) { for (selector in targets) {
@ -67,6 +68,12 @@ jQuery("input[name='mail_theme']").change(function() {
jQuery("input[name='mail_theme']").parents(".themeSelect").removeClass("themeDefault"); jQuery("input[name='mail_theme']").parents(".themeSelect").removeClass("themeDefault");
jQuery(this).parents(".themeSelect").addClass("themeDefault"); jQuery(this).parents(".themeSelect").addClass("themeDefault");
}); });
jQuery("input[name='email_admin_on_new_user_filter']").change(function() {
var val = jQuery("input[name='email_admin_on_new_user_filter']:checked").val();
jQuery('#email_admin_on_new_user_filter_group_options').toggle('group' == val);
});
{/footer_script} {/footer_script}
<form method="post" action="{$F_ACTION}" class="properties"> <form method="post" action="{$F_ACTION}" class="properties">
@ -119,11 +126,13 @@ jQuery("input[name='mail_theme']").change(function() {
{'Allow rating'|translate} {'Allow rating'|translate}
</label> </label>
<label id="rate_anonymous" class="font-checkbox no-bold"> <div id="rate_anonymous" class="sub-setting">
<span class="icon-check"></span> <label class="font-checkbox no-bold">
<input type="checkbox" name="rate_anonymous" {if ($main.rate_anonymous)}checked="checked"{/if}> <span class="icon-check"></span>
{'Rating by guests'|translate} <input type="checkbox" name="rate_anonymous" {if ($main.rate_anonymous)}checked="checked"{/if}>
</label> {'Rating by guests'|translate}
</label>
</div>
</li> </li>
<li> <li>
@ -133,11 +142,38 @@ jQuery("input[name='mail_theme']").change(function() {
{'Allow user registration'|translate} {'Allow user registration'|translate}
</label> </label>
<label id="email_admin_on_new_user" class="font-checkbox no-bold"> <div id="email_admin_on_new_user" class="sub-setting">
<span class="icon-check"></span> <label class="font-checkbox no-bold">
<input type="checkbox" name="email_admin_on_new_user" {if ($main.email_admin_on_new_user)}checked="checked"{/if}> <span class="icon-check"></span>
{'Email admins when a new user registers'|translate} <input type="checkbox" name="email_admin_on_new_user" {if ($main.email_admin_on_new_user)}checked="checked"{/if}>
</label> {'Email admins when a new user registers'|translate}
</label>
<div id="email_admin_on_new_user_filter" class="sub-setting"{if (!$main.email_admin_on_new_user)} style="display:none"{/if}>
<label class="font-checkbox no-bold">
<span class="icon-dot-circled"></span>
<input type="radio" name="email_admin_on_new_user_filter" value="all" {if ($main.email_admin_on_new_user_filter eq 'all')}checked{/if}>
{'All admins'|translate}
</label>
<br>
<label class="font-checkbox no-bold">
<span class="icon-dot-circled"></span>
<input type="radio" name="email_admin_on_new_user_filter" value="group" {if ($main.email_admin_on_new_user_filter eq 'group')}checked{/if}>
{'Only admins in a specific group'|translate}
</label>
<span id="email_admin_on_new_user_filter_group_options"{if ($main.email_admin_on_new_user_filter ne 'group')} style="display:none"{/if}>
{if count($group_options) > 0}
<select name="email_admin_on_new_user_filter_group">
{html_options options=$group_options selected=$main.email_admin_on_new_user_filter_group}
</select>
{else}
{'There is no group in this gallery.'|@translate} <a href="admin.php?page=group_list" class="externalLink">{'Group management'|@translate}</a>
{/if}
</span>
</div>
</div>
</li> </li>
<li> <li>

View file

@ -4525,6 +4525,10 @@ ul.jqtree-tree .jqtree-element {
#ftpPage p {text-align:left;margin:1em;} #ftpPage p {text-align:left;margin:1em;}
#ftpPage fieldset p {margin:0;} #ftpPage fieldset p {margin:0;}
.sub-setting {
margin: 10px 0 10px 20px;
}
/* watermark configuration screen */ /* watermark configuration screen */
#watermarkPositionBox { #watermarkPositionBox {
width:500px; width:500px;

View file

@ -351,7 +351,7 @@ function switch_lang_back()
* @param boolean $send_technical_details - send user IP and browser * @param boolean $send_technical_details - send user IP and browser
* @return boolean * @return boolean
*/ */
function pwg_mail_notification_admins($subject, $content, $send_technical_details=true) function pwg_mail_notification_admins($subject, $content, $send_technical_details=true, $group_id=null)
{ {
if (empty($subject) or empty($content)) if (empty($subject) or empty($content))
{ {
@ -397,7 +397,10 @@ function pwg_mail_notification_admins($subject, $content, $send_technical_detail
array( array(
'filename' => 'notification_admin', 'filename' => 'notification_admin',
'assign' => $tpl_vars, 'assign' => $tpl_vars,
) ),
true, // exclude_current_user
false, // only_webmasters
$group_id
); );
} }
@ -411,7 +414,7 @@ function pwg_mail_notification_admins($subject, $content, $send_technical_detail
* @param array $tpl - as in pwg_mail() * @param array $tpl - as in pwg_mail()
* @return boolean * @return boolean
*/ */
function pwg_mail_admins($args=array(), $tpl=array(), $exclude_current_user=true, $only_webmasters=false) function pwg_mail_admins($args=array(), $tpl=array(), $exclude_current_user=true, $only_webmasters=false, $group_id=null)
{ {
if (empty($args['content']) and empty($tpl)) if (empty($args['content']) and empty($tpl))
{ {
@ -430,14 +433,30 @@ function pwg_mail_admins($args=array(), $tpl=array(), $exclude_current_user=true
// get admins (except ourself) // get admins (except ourself)
$query = ' $query = '
SELECT SELECT
i.user_id,
u.'.$conf['user_fields']['username'].' AS name, u.'.$conf['user_fields']['username'].' AS name,
u.'.$conf['user_fields']['email'].' AS email u.'.$conf['user_fields']['email'].' AS email
FROM '.USERS_TABLE.' AS u FROM '.USERS_TABLE.' AS u
JOIN '.USER_INFOS_TABLE.' AS i JOIN '.USER_INFOS_TABLE.' AS i
ON i.user_id = u.'.$conf['user_fields']['id'].' ON i.user_id = u.'.$conf['user_fields']['id'];
if (!is_null($group_id))
{
$query.= '
JOIN '.USER_GROUP_TABLE.' AS ug
ON ug.user_id = i.user_id';
}
$query.= '
WHERE i.status in (\''.implode("','", $user_statuses).'\') WHERE i.status in (\''.implode("','", $user_statuses).'\')
AND u.'.$conf['user_fields']['email'].' IS NOT NULL'; AND u.'.$conf['user_fields']['email'].' IS NOT NULL';
if (!is_null($group_id))
{
$query.= '
AND group_id = '.intval($group_id);
}
if ($exclude_current_user) if ($exclude_current_user)
{ {
$query.= ' $query.= '

View file

@ -212,7 +212,7 @@ SELECT id
create_user_infos($user_id, $override); create_user_infos($user_id, $override);
if ($notify_admin and $conf['email_admin_on_new_user']) if ($notify_admin and 'none' != $conf['email_admin_on_new_user'])
{ {
include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
$admin_url = get_absolute_root_url().'admin.php?page=user_list&username='.$login; $admin_url = get_absolute_root_url().'admin.php?page=user_list&username='.$login;
@ -224,9 +224,17 @@ SELECT id
get_l10n_args('Admin: %s', $admin_url), get_l10n_args('Admin: %s', $admin_url),
); );
$group_id = null;
if (preg_match('/^group:(\d+)$/', $conf['email_admin_on_new_user'], $matches))
{
$group_id = $matches[1];
}
pwg_mail_notification_admins( pwg_mail_notification_admins(
get_l10n_args('Registration of %s', stripslashes($login) ), get_l10n_args('Registration of %s', stripslashes($login) ),
$keyargs_content $keyargs_content,
true, // $send_technical_details
$group_id
); );
} }

View file

@ -28,7 +28,7 @@ INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_send_mail_as','','S
INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_send_detailed_content','true','Send detailed content for notification by mail'); INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_send_detailed_content','true','Send detailed content for notification by mail');
INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_complementary_mail_content','','Complementary mail content for notification by mail'); INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_complementary_mail_content','','Complementary mail content for notification by mail');
INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_send_recent_post_dates','true','Send recent post by dates for notification by mail'); INSERT INTO piwigo_config (param,value,comment) VALUES ('nbm_send_recent_post_dates','true','Send recent post by dates for notification by mail');
INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_new_user','false','Send an email to theadministrators when a user registers'); INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_new_user','none','Send an email to theadministrators when a user registers');
INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_comment','false','Send an email to the administrators when a valid comment is entered'); INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_comment','false','Send an email to the administrators when a valid comment is entered');
INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_comment_validation','true','Send an email to the administrators when a comment requires validation'); INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_comment_validation','true','Send an email to the administrators when a comment requires validation');
INSERT INTO piwigo_config (param,value,comment) VALUES ('obligatory_user_mail_address','false','Mail address is obligatory for users'); INSERT INTO piwigo_config (param,value,comment) VALUES ('obligatory_user_mail_address','false','Mail address is obligatory for users');

View file

@ -0,0 +1,31 @@
<?php
// +-----------------------------------------------------------------------+
// | This file is part of Piwigo. |
// | |
// | For copyright and license information, please view the COPYING.txt |
// | file that was distributed with this source code. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}
$upgrade_description = 'Add more options to email_admin_on_new_user';
list($old_value) = pwg_db_fetch_row(pwg_query('SELECT value FROM '.PREFIX_TABLE.'config WHERE param = "email_admin_on_new_user"'));
$new_value = 'all';
if ('false' == $old_value)
{
$new_value = 'none';
}
conf_update_param('email_admin_on_new_user', $new_value);
echo
"\n"
. $upgrade_description
."\n"
;
?>

View file

@ -1345,4 +1345,6 @@ $lang['or'] = 'or';
$lang['Locked album'] = 'Locked album'; $lang['Locked album'] = 'Locked album';
$lang['This album is currently locked, visible only to administrators.'] = 'This album is currently locked, visible only to administrators.'; $lang['This album is currently locked, visible only to administrators.'] = 'This album is currently locked, visible only to administrators.';
$lang['Unlock it'] = 'Unlock it'; $lang['Unlock it'] = 'Unlock it';
$lang['All admins'] = 'All admins';
$lang['Only admins in a specific group'] = 'Only admins in a specific group';
// Leave this line empty // Leave this line empty

View file

@ -1345,4 +1345,6 @@ $lang['or'] = 'ou';
$lang['Locked album'] = 'Album verrouillé'; $lang['Locked album'] = 'Album verrouillé';
$lang['This album is currently locked, visible only to administrators.'] = 'Cet album est actuellement verrouillé, visible uniquement par les administrateurs.'; $lang['This album is currently locked, visible only to administrators.'] = 'Cet album est actuellement verrouillé, visible uniquement par les administrateurs.';
$lang['Unlock it'] = 'Le déverrouiller'; $lang['Unlock it'] = 'Le déverrouiller';
$lang['All admins'] = 'Tous les administrateurs';
$lang['Only admins in a specific group'] = 'Uniquement les administrations d\'un groupe spécifique';
// Leave this line empty // Leave this line empty