diff options
-rw-r--r-- | admin/mail.php | 252 | ||||
-rwxr-xr-x | docs/CHANGELOG | 2 | ||||
-rw-r--r-- | lib/class/ampachemail.class.php | 99 | ||||
-rw-r--r-- | templates/show_login_form.inc.php | 4 | ||||
-rw-r--r-- | templates/show_mail_users.inc.php | 24 | ||||
-rw-r--r-- | templates/sidebar_admin.inc.php | 1 |
6 files changed, 136 insertions, 246 deletions
diff --git a/admin/mail.php b/admin/mail.php index 2d7ce570..4c5a070e 100644 --- a/admin/mail.php +++ b/admin/mail.php @@ -19,257 +19,47 @@ */ -require('../lib/init.php'); +require_once '../lib/init.php'; -if (!$GLOBALS['user']->has_access(100)) { +if (!Access::check('interface','75')) { access_denied(); exit(); } +show_header(); -$action = scrub_in($_POST['action']); -$to = scrub_in($_REQUEST['to']); -if (isset ($_POST['cat_stats'])){$cat_stats = scrub_in($_POST['cat_stats']);} -if (isset ($_POST['pop_albums'])){$pop_albums = scrub_in($_POST['pop_albums']);} -if (isset ($_POST['pop_artists'])){$pop_artists = scrub_in($_POST['pop_artists']);} -if (isset ($_POST['pop_songs'])){$pop_songs = scrub_in($_POST['pop_songs']);} -if (isset ($_POST['threshold'])){$threshold = scrub_in($_POST['threshold']);} else { $threshold = conf($stats_threshold); }; -if (isset ($_POST['new_artists'])){$new_artists = scrub_in($_POST['new_artists']);} -if (isset ($_POST['new_albums'])){$new_albums = scrub_in($_POST['new_albums']);} -if (isset ($_POST['flagged'])){$flagged = scrub_in($_POST['flagged']);} -$subject = stripslashes(scrub_in($_POST['subject'])); -$message = stripslashes(scrub_in($_POST['message'])); - -/* Always show the header */ -show_template('header'); - -switch ($action) { +// Action switch +switch ($_REQUEST['action']) { case 'send_mail': - if (conf('demo_mode')) { break; } - - // do the mail mojo here - if ( $to == 'all' ) { - $sql = "SELECT * FROM user WHERE email IS NOT NULL"; - } - elseif ( $to == 'users' ) { - $sql = "SELECT * FROM user WHERE access='user' OR access='25' AND email IS NOT NULL"; - } - elseif ( $to == 'admins' ) { - $sql = "SELECT * FROM user WHERE access='admin' OR access='100' AND email IS NOT NULL"; - } - elseif ( $to == 'inactive' ) { - if (isset ($_POST['inactive'])){ - $days = $_POST['inactive']; - } else { - $days = "30"; - } - $inactive = time() - ($days * 24 * 60 *60); - $sql = "SELECT * FROM user WHERE last_seen <= '$inactive' AND email IS NOT NULL"; - } + if (Config::get('demo_mode')) { + access_denied(); + exit; + } - - $db_result = mysql_query($sql, dbh()); - - $recipient = ''; + $clients = AmpacheMail::get_users($_REQUEST['to']); - while ( $u = mysql_fetch_object($db_result) ) { - $recipient .= "$u->fullname <$u->email>, "; + foreach ($clients as $client) { + $recipient .= $client['fullname'] ." <" . $client['email'] . ">, "; } // Remove the last , from the recipient $recipient = rtrim($recipient,","); - - $from = $user->fullname."<".$user->email.">"; + + // Set the vars on the object + AmpacheMail::$recipient = $recipient; + AmpacheMail::$from = $GLBOALS['user']->fullname."<".$GLOBALS['user']->email.">"; + AmpacheMail::$subject = scrub_in($_REQUEST['subject']); + AmpacheMail::$message = scrub_in($_REQUEST['message']); + AmpacheMail::send(); - if (isset ($cat_stats)){ - /* Before we display anything make sure that they have a catalog */ - $query = "SELECT * FROM catalog"; - $dbh = dbh(); - $db_results = mysql_query($query, dbh()); - if (!mysql_num_rows($db_results)) { - $items[] = "<span align=\"center\" class=\"error\">" . _("No Catalogs Found!") . "</span><br />"; - $items[] = "<a href=\"" . conf('web_path') . "/admin/catalog.php?action=show_add_catalog\">" ._("Add a Catalog") . "</a>"; - show_info_box(_('Catalog Statistics'),'catalog',$items); - return false; - break; - } - - $query = "SELECT count(*) AS songs, SUM(size) AS size, SUM(time) as time FROM song"; - $db_result = mysql_query($query, $dbh); - $songs = mysql_fetch_assoc($db_result); - - $query = "SELECT count(*) FROM album"; - $db_result = mysql_query($query, $dbh); - $albums = mysql_fetch_row($db_result); - - $query = "SELECT count(*) FROM artist"; - $db_result = mysql_query($query, $dbh); - $artists = mysql_fetch_row($db_result); - - $sql = "SELECT count(*) FROM user"; - $db_result = mysql_query($sql, $dbh); - $users = mysql_fetch_row($db_result); - - $time = time(); - $last_seen_time = $time - 1200; - $sql = "SELECT count(DISTINCT s.username) FROM session AS s " . - "INNER JOIN user AS u ON s.username = u.username " . - "WHERE s.expire > " . $time . " " . - "AND u.last_seen > " . $last_seen_time; - $db_result = mysql_query($sql, $dbh); - $connected_users = mysql_fetch_row($db_result); - - $hours = floor($songs['time']/3600); - $size = $songs['size']/1048576; - - $days = floor($hours/24); - $hours = $hours%24; - - $time_text = "$days "; - $time_text .= ($days == 1) ? _("day") : _("days"); - $time_text .= ", $hours "; - $time_text .= ($hours == 1) ? _("hour") : _("hours"); - - if ( $size > 1024 ) { - $total_size = sprintf("%.2f", ($size/1024)); - $size_unit = "GB"; - } - else { - $total_size = sprintf("%.2f", $size); - $size_unit = "MB"; - } - $stats = _('Total Users')." ".$users[0]."\n"; - $stats .= _('Connected Users')." ".$connected_users[0]."\n"; - $stats .= _('Albums')." ".$albums[0]."\n"; - $stats .= _('Artists')." ".$artists[0]."\n"; - $stats .= _('Songs')." ".$songs['songs']."\n"; - $stats .= _('Catalog Size')." ".$total_size." ".$size_unit."\n"; - $stats .= _('Catalog Time')." ".$time_text."\n"; - - $message .= "\n\nAmpache Catalog Statistics\n\n"; - $message .= "$stats"; - } - - if (isset ($pop_albums)){ - $message .= "\n\nMost Popular Albums\n\n"; - $stats = new Stats(); - $stats = $stats->get_top('10','album',$threshold); - - foreach( $stats as $r){ - $album = new Album($r[object_id]); - $palbums .= $album->name." (". $r[count].")\n"; - } - $message .= "$palbums"; - } - - if (isset ($pop_artists)){ - $message .= "\n\nMost Popular Artists\n\n"; - $stats = new Stats(); - $stats = $stats->get_top('10','artist',$threshold); - - foreach( $stats as $r){ - $artist = new Artist($r[object_id]); - $partists .= $artist->name." (". $r[count].")\n"; - } - $message .= "$partists"; - } - - if (isset ($pop_songs)){ - - $message .= "\n\nMost Popular Songs\n\n"; - $stats = new Stats(); - $stats = $stats->get_top('10','song',$threshold); - - foreach( $stats as $r){ - $song = new Song($r[object_id]); - $artist = $song->get_artist_name(); - $text = "$artist - $song->title"; - $psongs .= $text." (". $r[count].")\n"; - } - $message .= "$psongs"; - } - - if (isset ($new_artists)){ - - $sql = "SELECT DISTINCT artist FROM song ORDER BY addition_time " . - "DESC LIMIT " . conf('popular_threshold'); - $db_result = mysql_query($sql, dbh()); - - while ( $item = mysql_fetch_row($db_result) ) { - $artist = new Artist($item[0]); - $nartists .= $artist->name."\n"; - } - $message .= "\n\nLatest Artist Additions\n\n"; - $message .= "$nartists"; - } - - if (isset ($new_albums)){ - - $sql = "SELECT DISTINCT album FROM song ORDER BY addition_time " . - "DESC LIMIT " . conf('popular_threshold'); - $db_result = mysql_query($sql, dbh()); - - - while ( $item = mysql_fetch_row($db_result) ) { - $album = new Album($item[0]); - $nalbums .= $album->name."\n"; - } - $message .= "\n\nLatest Album Additions\n\n"; - $message .= "$nalbums"; - - } - - if (isset ($flagged)){ - - $flag = new Flag(); - $flagged = $flag->get_flagged(); - $message .= "\n\nFlagged Songs\n\n"; - $message .= "Name\t\t\t\tFlag\t\tFlagged by\tStatus\n"; - foreach ($flagged as $data){ - - $flag = new Flag($data); - $flag->format_name(); - $name = $flag->name; - $user = $flag->user; - $flag = $flag->flag; - if($flag->approved){ $status = "Approved"; } else { $status = "Pending"; } - $message .= "*) $name\t$flag\t\t$user\t\t$status\n"; - } -} - - if (isset ($disabled)){ - - $catalog = new Catalog(); - $songs = $catalog->get_disabled(); - $message .= "\n\nDisabled Songs\n\n"; - - foreach ($songs as $song){ - - $name = "*) ". $song->title ." | ". $song->get_album_name($song->album) ." | ". $song->get_artist_name($song->album) ." | ". $song->file ; - $message .= "$name"; - } -} - - // woohoo!! - mail ($from, $subject, $message, - "From: $from\r\n". - "Bcc: $recipient\r\n"); - /* Confirmation Send */ - $url = conf('web_path') . '/admin/mail.php'; + $url = Config::get('web_path') . '/admin/mail.php'; $title = _('E-mail Sent'); $body = _('Your E-mail was successfully sent.'); show_confirmation($title,$body,$url); break; default: - if ( empty($to) ) { - $to = 'all'; - } - - if ( empty($subject) ) { - $subject = "[" . conf('site_title') . "] "; - } - require (conf('prefix') . '/templates/show_mail_users.inc.php'); + require_once Config::get('prefix') . '/templates/show_mail_users.inc.php'; break; } // end switch diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 7784169a..df233630 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,8 @@ -------------------------------------------------------------------------- v.3.4-Alpha4 + - Fixed Mail functions, some features from old mail are missing for + now. - Fixed Delete Disabled & Sort Files command line scripts - Fixed Find Duplicates Functionality - Added Highest Rated option to Advanced Random diff --git a/lib/class/ampachemail.class.php b/lib/class/ampachemail.class.php new file mode 100644 index 00000000..2a84fdcc --- /dev/null +++ b/lib/class/ampachemail.class.php @@ -0,0 +1,99 @@ +<?php +/* + + Copyright (c) 2001 - 2007 Ampache.org + All rights reserved. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License v2 + 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. + +*/ + +class AmpacheMail { + + // The message, recipient and from + public static $message; + public static $recipient; + public static $from; + public static $subject; + + /** + * Constructor + * This isn't used + */ + private function __construct($name) { + + // Rien a faire + + } // Constructor + + /** + * get_users + * This returns an array of userid's for people who have e-mail addresses + * based on the passed filter + */ + public static function get_users($filter) { + + switch ($fileter) { + default: + case 'all': + $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; + break; + case 'users': + $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; + break; + case 'admins': + $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; + break ; + case 'inactive': + $inactive = time() - (30*86400); + $sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL"; + break; + } // end filter switch + + $db_results = Dba::query($sql); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); + } + + return $results; + + } // get_users + + /** + * add_statistics + * This should be run if we want to add some statistics to this e-mail, appends to self::$message + */ + public static function add_statistics($methods) { + + + + } // add_statistics + + /** + * send + * This actually sends the mail, how amazing + */ + public static function send() { + + mail(self::$from,self::$subject,self::$message,"From: " . self::$from . "\r\nBcc: " . self::$recipient . "\r\n"); + + return true; + + } // send + +} // AmpacheMail class +?> diff --git a/templates/show_login_form.inc.php b/templates/show_login_form.inc.php index 36b38ef0..7f564e9f 100644 --- a/templates/show_login_form.inc.php +++ b/templates/show_login_form.inc.php @@ -35,7 +35,7 @@ $htmllang = str_replace("_","-",Config::get('lang')); <link rel="stylesheet" href="<?php echo Config::get('web_path'); ?>/templates/print.css" type="text/css" media="print" /> <link rel="stylesheet" href="<?php echo Config::get('web_path'); ?>/templates/handheld.css" type="text/css" media="handheld" /> <link rel="stylesheet" href="<?php echo Config::get('web_path'); ?><?php echo Config::get('theme_path'); ?>/templates/default.css" type="text/css" media="screen" /> -<title> <?php echo Config::get('site_title'); ?> </title> +<title> <?php echo scrub_out(Config::get('site_title')); ?> </title> <script type="text/javascript" language="javascript"> function focus(){ document.login.username.focus(); } </script> @@ -51,7 +51,7 @@ function focus(){ document.login.username.focus(); } </h1> </div> <div id="loginbox"> - <h2><?php echo Config::get('site_title'); ?></h2> + <h2><?php echo scrub_out(Config::get('site_title')); ?></h2> <form name="login" method="post" enctype="multipart/form-data" action="<?php echo Config::get('web_path'); ?>/login.php"> <div class="loginfield" id="usernamefield"> diff --git a/templates/show_mail_users.inc.php b/templates/show_mail_users.inc.php index a98128a1..b8fcf5ce 100644 --- a/templates/show_mail_users.inc.php +++ b/templates/show_mail_users.inc.php @@ -1,13 +1,12 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) 2001 - 2007 Ampache.org All rights reserved. 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; either version 2 - of the License, or (at your option) any later version. + as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,20 +21,20 @@ ?> <?php show_box_top(_('Send E-mail to Users')); ?> -<form name="mail" method="post" action="<?php echo conf('web_path'); ?>/admin/mail.php" enctype="multipart/form-data"> +<form name="mail" method="post" action="<?php echo Config::get('web_path'); ?>/admin/mail.php?action=send_mail" enctype="multipart/form-data"> <table> <tr> <td><?php echo _('Mail to'); ?>:</td> <td> <select name="to"> - <option value="all" title="Mail Everyone" <?php if ($to == 'all') { echo "selected=\"selected\""; } ?>>All</option> - <option value="users" title="Mail Users" <?php if ($to == 'user') { echo "selected=\"selected\""; } ?>>Users</option> - <option value="admins" title="Mail Admins" <?php if ($to == 'admin') { echo "selected=\"selected\""; } ?>>Admins</option> - <option value="inactive" title="Mail Inactive Users" <?php if ($to == 'inactive') { echo "selected=\"selected\""; } ?>>Inactive</option> + <option value="all" title="Mail Everyone"><?php echo _('All'); ?></option> + <option value="users" title="Mail Users"><?php echo _('User'); ?></option> + <option value="admins" title="Mail Admins"><?php echo _('Admin'); ?></option> + <option value="inactive" title="Mail Inactive Users"><?php echo _('Inactive Users'); ?> </option> </select> - users that are inactive for more than <input type="text" title="This value is only used when mailing to inactive users" size="3" name="inactive" value="30" /> days</title> </td> </tr> +<!-- <tr> <td colspan="2"> <table> @@ -86,14 +85,14 @@ <tr> <td colspan = "2"><?php echo _('Most Popular Threshold in days'); ?>:</td> <td> - <input type="text" name="threshold" size="3" value="<?php echo conf('popular_threshold'); ?>" /> + <input type="text" name="threshold" size="3" value="<?php echo Config::get('popular_threshold'); ?>" /> </td> </tr> </table> </td> </tr> - +--> <tr> <td><?php echo _('Subject'); ?>:</td> <td colspan="3"> @@ -104,13 +103,12 @@ <tr> <td valign="top"><?php echo _('Message'); ?>:</td> <td> - <textarea class="input" name="message" rows="20" cols="70"><?php echo scrub_out($message); ?></textarea> + <textarea class="input" name="message" rows="10" cols="70"></textarea> </td> </tr> </table> <div class="formValidation"> - <input type="hidden" name="action" value="send_mail" /> <input class="button" type="submit" value="<?php echo _('Send Mail'); ?>" /> </div> </form> diff --git a/templates/sidebar_admin.inc.php b/templates/sidebar_admin.inc.php index bc35e000..af1be577 100644 --- a/templates/sidebar_admin.inc.php +++ b/templates/sidebar_admin.inc.php @@ -21,6 +21,7 @@ <li><h4><?php echo _('Other Tools'); ?></h4> <ul class="sb3" id="sb_admin_ot"> <li id="sb_admin_ot_Duplicates"><a href="<?php echo $web_path; ?>/admin/duplicates.php"><?php echo _('Find Duplicates'); ?></a></li> + <li id="sb_admin_ot_Mail"><a href="<?php echo $web_path; ?>/admin/mail.php"><?php echo _('Mail Users'); ?></a></li> <li id="sb_admin_ot_ClearNowPlaying"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_now_playing"><?php echo _('Clear Now Playing'); ?></a></li> <li id="sb_admin_ot_ClearCatStats"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_stats"><?php echo _('Clear Catalog Stats'); ?></a></li> </ul> |