aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2006-02-20 23:47:01 +0000
committerrub <rub@piwigo.org>2006-02-20 23:47:01 +0000
commit2afff7c2266c55970e666bda1b02964dd97d8f71 (patch)
tree7a523caf088a7697a9dd3fe3c954da915cdfa84b
parent16034a592a32d9a6a0af0ed04c27ad4cf28cd844 (diff)
Step 3: Integration of new admin menu with the associated file (No interface, Only Message)
git-svn-id: http://piwigo.org/svn/trunk@1049 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin.php1
-rw-r--r--admin/mailtousers.php286
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php15
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php15
-rw-r--r--template/yoga/admin.tpl1
5 files changed, 318 insertions, 0 deletions
diff --git a/admin.php b/admin.php
index 2752fb0d9..4e73e2f0f 100644
--- a/admin.php
+++ b/admin.php
@@ -70,6 +70,7 @@ $template->assign_vars(
'U_FAQ'=> $link_start.'help',
'U_SITES'=> $link_start.'remote_site',
'U_MAINTENANCE'=> $link_start.'maintenance',
+ 'U_MAILTOUSERS'=> $link_start.'mailtousers',
'U_CONFIG_GENERAL'=> $conf_link.'general',
'U_CONFIG_COMMENTS'=> $conf_link.'comments',
'U_CONFIG_DISPLAY'=> $conf_link.'default',
diff --git a/admin/mailtousers.php b/admin/mailtousers.php
new file mode 100644
index 000000000..b1d402580
--- /dev/null
+++ b/admin/mailtousers.php
@@ -0,0 +1,286 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
+// | Copyright (C) 2006 Ruben ARNAUD - team@phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
+// | last modifier : $Author: plg $
+// | revision : $Revision: 870 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+// +-----------------------------------------------------------------------+
+// | include
+// +-----------------------------------------------------------------------+
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+ die ("Hacking attempt!");
+}
+include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
+include_once(PHPWG_ROOT_PATH.'include/functions_notification.inc.php');
+include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
+
+// +-----------------------------------------------------------------------+
+// | functions
+// +-----------------------------------------------------------------------+
+/*
+ * Search an available check_key
+ *
+ * It's a copy of function find_available_feed_id
+ *
+ * @return string feed identifier
+ */
+function find_available_check_key()
+{
+ while (true)
+ {
+ $key = generate_key(128);
+ $query = '
+select
+ count(*)
+from
+ '.USER_MAIL_NOTIFICATION_TABLE.'
+where
+ check_key = \''.$key.'\';';
+
+ list($count) = mysql_fetch_row(pwg_query($query));
+ if ($count == 0)
+ {
+ return $key;
+ }
+ }
+}
+
+/*
+ * Updating News users
+ */
+function update_data_user_mail_notification()
+{
+/* $query = '
+insert into '.USER_MAIL_NOTIFICATION_TABLE.'
+ (user_id, enabled)
+ (select id, \'false\' from '.USERS_TABLE.'
+ where mail_address is not null and id not in (select user_id from '.USER_MAIL_NOTIFICATION_TABLE.'))
+;';
+ pwg_query($query);*/
+
+ global $conf, $page;
+
+ $query = '
+select
+ id user_id, username, mail_address
+from
+ '.USERS_TABLE.'
+where
+ mail_address is not null and
+ id not in (select user_id from '.USER_MAIL_NOTIFICATION_TABLE.')
+order by
+ id;';
+
+ $result = pwg_query($query);
+
+ if (mysql_num_rows($result) > 0)
+ {
+ $inserts = array();
+
+ while ($row = mysql_fetch_array($result))
+ {
+ array_push($inserts, array('user_id' => $row['user_id'],
+ 'check_key' => find_available_check_key(),
+ 'enabled' => ($conf['default_value_user_mail_notification_enabled'] == true ? 'true' : 'false')));
+ array_push($page['infos'], sprintf(l10n('nbm_User %s [%s] added.'), $row['username'], $row['mail_address']));
+ }
+
+ mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
+ }
+}
+
+/*
+ * Updating News users
+ */
+function send_all_user_mail_notification()
+{
+ global $conf, $conf_mail, $page, $user, $lang_info, $lang;
+ list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+
+ $query = '
+select
+ N.user_id, U.username, U.mail_address, N.last_send
+from
+ '.USER_MAIL_NOTIFICATION_TABLE.' as N,
+ '.USERS_TABLE.' as U
+where
+ N.user_id = U.id and
+ N.enabled = \'true\' and
+ U.mail_address is not null
+order by
+ user_id;';
+
+ $result = pwg_query($query);
+
+ if (mysql_num_rows($result) > 0)
+ {
+ $error_on_mail_count = 0;
+ $sended_mail_count = 0;
+ $datas = array();
+ // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
+ $sav_mailtousers_user = $user;
+ $sav_mailtousers_lang_info = $lang_info;
+ $sav_mailtousers_lang = $lang;
+ // Save message info and error in the original language
+ $msg_info = l10n('nbm_Mail sended to %s [%s].');
+ $msg_error = l10n('nbm_Error when sending email to %s [%s].');
+ // Last Language
+ $last_mailtousers_language = $user['language'];
+
+ while ($row = mysql_fetch_array($result))
+ {
+ $user = array();
+ $user['id'] = $row['user_id'];
+ $user = array_merge($user, getuserdata($user['id'], true));
+
+ if ($last_mailtousers_language != $user['language'])
+ {
+ $last_mailtousers_language = $user['language'];
+
+ // Re-Init language arrays
+ $lang_info = array();
+ $lang = array();
+
+ // language files
+ include(get_language_filepath('common.lang.php'));
+ // No test admin because script is checked admin (user selected no)
+ // Translations are in admin file too
+ include(get_language_filepath('admin.lang.php'));
+ }
+
+ $message = '';
+ $news = news($row['last_send'], $dbnow);
+ if (count($news) > 0)
+ {
+ $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_New elements added');
+ $message .= sprintf(l10n('nbm_Hello %s'), $row['username']).",\n\n";
+
+ if (!is_null($row['last_send']))
+ $message .= sprintf(l10n('nbm_New elements were added between %s and %s:'), $row['last_send'], $dbnow);
+ else
+ $message .= sprintf(l10n('nbm_New elements were added on %s:'), $dbnow);
+ $message .= "\n";
+
+ foreach ($news as $line)
+ {
+ $message .= ' o '.$line."\n";
+ }
+
+ $message .= "\n".sprintf(l10n('nbm_Go to %s %s.'), $conf['gallery_title'], $conf['gallery_url'])."\n\n";
+ $message .= "\n".sprintf(l10n('nbm_To unsubscribe send a message to %s.'), $conf_mail['email_webmaster'])."\n\n";
+
+ if (pwg_mail(format_email($row['username'], $row['mail_address']), '', $subject, $message))
+ {
+ $sended_mail_count += 1;
+ array_push($page['infos'], sprintf($msg_info, $row['username'], $row['mail_address']));
+ $data = array('user_id' => $row['user_id'],
+ 'last_send' => $dbnow);
+ array_push($datas, $data);
+ }
+ else
+ {
+ $error_on_mail_count += 1;
+ array_push($page['errors'], sprintf($msg_error, $row['username'], $row['mail_address']));
+ }
+ }
+ }
+
+ // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
+ $user = $sav_mailtousers_user;
+ $lang_info = $sav_mailtousers_lang_info;
+ $lang = $sav_mailtousers_lang;
+
+ mass_updates(
+ USER_MAIL_NOTIFICATION_TABLE,
+ array(
+ 'primary' => array('user_id'),
+ 'update' => array('last_send')
+ ),
+ $datas
+ );
+
+ if ($error_on_mail_count != 0)
+ {
+ array_push($page['errors'], sprintf(l10n('nbm_%d mails were not sended.'), $error_on_mail_count));
+ }
+ else
+ {
+ if ($sended_mail_count == 0)
+ array_push($page['infos'], l10n('nbm_No mail to send.'));
+ else
+ array_push($page['infos'], sprintf(l10n('nbm_%d mails were sended.'), $sended_mail_count));
+ }
+ }
+ else
+ {
+ array_push($page['errors'], l10n('nbm_No user to send notifications by mail.'));
+ }
+}
+
+// +-----------------------------------------------------------------------+
+// | Main
+// +-----------------------------------------------------------------------+
+update_data_user_mail_notification();
+send_all_user_mail_notification();
+
+
+// +-----------------------------------------------------------------------+
+// | template initialization |
+// +-----------------------------------------------------------------------+
+
+$title = l10n('nbm_Send mail to users');
+
+// +-----------------------------------------------------------------------+
+// | infos & errors display |
+// +-----------------------------------------------------------------------+
+
+/*echo '<pre>';
+
+if (count($page['errors']) != 0)
+{
+ echo "\n\nErrors:\n";
+ foreach ($page['errors'] as $error)
+ {
+ echo $error."\n";
+ }
+}
+
+if (count($page['infos']) != 0)
+{
+ echo "\n\nInformations:\n";
+ foreach ($page['infos'] as $info)
+ {
+ echo $info."\n";
+ }
+}
+
+echo '</pre>';
+*/
+?> \ No newline at end of file
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index 8bd3e510c..c7b0db36a 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -375,4 +375,19 @@ $lang['users'] = 'Users';
$lang['visitors'] = 'Visitors';
$lang['w_day'] = 'Day';
$lang['waiting'] = 'Waiting';
+$lang['nbm_item_notification'] = 'Notification';
+$lang['nbm_User %s [%s] added.'] = 'User %s [%s] added.';
+$lang['nbm_New elements added'] = 'New elements added';
+$lang['nbm_Hello %s'] = 'Hello %s';
+$lang['nbm_New elements were added between %s and %s:'] = 'New elements were added between %s and %s:';
+$lang['nbm_New elements were added on %s:'] = 'New elements were added on %s:';
+$lang['nbm_Go to %s %s.'] = 'Go to %s %s.';
+$lang['nbm_To unsubscribe send a message to %s.'] = 'To unsubscribe send a message to %s.';
+$lang['nbm_Mail sended to %s [%s].'] = 'Mail sended to %s [%s].';
+$lang['nbm_Error when sending email to %s [%s].'] = 'Error when sending email to %s [%s].';
+$lang['nbm_%d mails were not sended.'] = '%d mails were not sended.';
+$lang['nbm_No mail to send.'] = 'No mail to send.';
+$lang['nbm_%d mails were sended.'] = '%d mails were sended.';
+$lang['nbm_No user to send notifications by mail.'] = 'No user to send notifications by mail.';
+$lang['nbm_Send mail to users'] = 'Send mail to users';
?> \ No newline at end of file
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index 446704fe9..060a39219 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -374,4 +374,19 @@ $lang['users'] = 'Utilisateurs';
$lang['visitors'] = 'Visiteurs';
$lang['w_day'] = 'Jour';
$lang['waiting'] = 'En attente';
+$lang['nbm_item_notification'] = 'Notification';
+$lang['nbm_User %s [%s] added.'] = 'Utilisateur %s [%s] ajouté.';
+$lang['nbm_New elements added'] = 'Nouveaux éléments ajoutés';
+$lang['nbm_Hello %s'] = 'Bonjour %s';
+$lang['nbm_New elements were added between %s and %s:'] = 'Des nouveaux éléments ont été ajoutés entre le %s et le %s:';
+$lang['nbm_New elements were added on %s:'] = 'Des nouveaux éléments ont été ajoutés le %s:';
+$lang['nbm_Go to %s %s.'] = 'Allez sur %s %s.';
+$lang['nbm_To unsubscribe send a message to %s.'] = 'Pour vous désinscrire, envoyer un mail à %s.';
+$lang['nbm_Mail sended to %s [%s].'] = 'Mail envoyé à %s [%s].';
+$lang['nbm_Error when sending email to %s [%s].'] = 'Erreur lors de l\'envoi du mail à %s [%s].';
+$lang['nbm_%d mails were not sended.'] = '%s mails n\'ont pas été envoyés.';
+$lang['nbm_No mail to send.'] = 'Pas de mail à envoyer.';
+$lang['nbm_%d mails were sended.'] = '%s mails ont été envoyés.';
+$lang['nbm_No user to send notifications by mail.'] = 'Pas d\'utilisateur pour envoyer des notifications par mails.';
+$lang['nbm_Send mail to users'] = 'Envoi de mail aux utilisateurs';
?> \ No newline at end of file
diff --git a/template/yoga/admin.tpl b/template/yoga/admin.tpl
index 9c37ae52c..33f1e6eba 100644
--- a/template/yoga/admin.tpl
+++ b/template/yoga/admin.tpl
@@ -19,6 +19,7 @@
<li><a href="{U_HISTORY}">{lang:history}</a></li>
<li><a href="{U_CAT_UPDATE}">{lang:update}</a></li>
<li><a href="{U_MAINTENANCE}">{lang:Maintenance}</a></li>
+ <li><a href="{U_MAILTOUSERS}">{lang:nbm_item_notification}</a></li>
</ul>
</dd>