diff options
author | pb1dft <pb1dft@ampache> | 2006-10-02 21:17:14 +0000 |
---|---|---|
committer | pb1dft <pb1dft@ampache> | 2006-10-02 21:17:14 +0000 |
commit | 6de6f894275ed0f31b9a18f4ff21f983ee22600b (patch) | |
tree | e3d08b06337b12e07ad3f976dc94c414527d5bcc | |
parent | a8a0dc224e1889f70873287caf0b4a00a278303f (diff) | |
download | ampache-6de6f894275ed0f31b9a18f4ff21f983ee22600b.tar.gz ampache-6de6f894275ed0f31b9a18f4ff21f983ee22600b.tar.bz2 ampache-6de6f894275ed0f31b9a18f4ff21f983ee22600b.zip |
Added Some extra Mail Functions
-rw-r--r-- | admin/mail.php | 161 | ||||
-rw-r--r-- | templates/show_mail_users.inc.php | 40 |
2 files changed, 199 insertions, 2 deletions
diff --git a/admin/mail.php b/admin/mail.php index a71669e7..16088fc2 100644 --- a/admin/mail.php +++ b/admin/mail.php @@ -30,6 +30,12 @@ if (!$GLOBALS['user']->has_access(100)) { $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['new_artists'])){$new_artists = scrub_in($_POST['new_artists']);} +if (isset ($_POST['new_albums'])){$new_albums = scrub_in($_POST['new_albums']);} $subject = stripslashes(scrub_in($_POST['subject'])); $message = stripslashes(scrub_in($_POST['message'])); @@ -39,7 +45,7 @@ show_template('header'); switch ($action) { case 'send_mail': if (conf('demo_mode')) { break; } - + $to = "admins"; // do the mail mojo here if ( $to == 'all' ) { $sql = "SELECT * FROM user WHERE email IS NOT NULL"; @@ -63,6 +69,159 @@ switch ($action) { $recipient = rtrim($recipient,","); $from = $user->fullname."<".$user->email.">"; + + if (isset ($cat_stats)){ + + /* Before we display anything make sure that they have a catalog */ + $query = "SELECT * FROM catalog"; + $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; + } + + $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)){ + /* Select out the most popular based on object_count */ + $sql = "SELECT object_id, SUM(count) as count FROM object_count" . + " WHERE object_type = 'album'" . + " GROUP BY object_id" . + " ORDER BY count DESC LIMIT " . conf('popular_threshold'); + $db_result = mysql_query($sql,dbh()); + + while ( $r = @mysql_fetch_object($db_result) ) { + $album = new Album($r->object_id); + $palbums .= $album->name." (". $r->count.")\n"; + } + + $message .= "\n\nMost Popular Albums\n\n"; + $message .= "$palbums"; + + } + + if (isset ($pop_artists)){ + /* Select out the most popular based on object_count */ + $sql = "SELECT object_id, SUM(count) as count FROM object_count" . + " WHERE object_type = 'artist'" . + " GROUP BY object_id" . + " ORDER BY count DESC LIMIT " . conf('popular_threshold'); + $db_result = mysql_query($sql,dbh()); + + while ( $r = @mysql_fetch_object($db_result) ) { + $artist = new Artist($r->object_id); + $partists .= $artist->name." (". $r->count.")\n"; + } + + $message .= "\n\nMost Popular Artists\n\n"; + $message .= "$partists"; + + } + + if (isset ($pop_songs)){ + /* Select out the most popular based on object_count */ + $sql = "SELECT object_id, SUM(count) as count FROM object_count" . + " WHERE object_type = 'song'" . + " GROUP BY object_id" . + " ORDER BY count DESC LIMIT " . conf('popular_threshold'); + $db_result = mysql_query($sql,dbh()); + + while ( $r = @mysql_fetch_object($db_result) ) { + $song = new Song($r->object_id); + $artist = $song->get_artist_name(); + $text = "$artist - $song->title"; + $psongs .= $text." (". $r->count.")\n"; + } + + $message .= "\n\nMost Popular Songs\n\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\nNewest 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\nNewest Album Additions\n\n"; + $message .= "$nalbums"; + } // woohoo!! mail ($from, $subject, $message, diff --git a/templates/show_mail_users.inc.php b/templates/show_mail_users.inc.php index 54f0020b..1315ca86 100644 --- a/templates/show_mail_users.inc.php +++ b/templates/show_mail_users.inc.php @@ -34,10 +34,48 @@ </select> </td> </tr> + <tr> + <td colspan="2"> + <table> + <tr> + <td><?php echo _('Catalog Statistics'); ?>:</td> + <td> + <input type="checkbox" name="cat_stats" value="yes"> + </td> + <td><?php echo _('Most Popular Albums'); ?>:</td> + <td> + <input type="checkbox" name="pop_albums" value="yes"> + </td> + </tr> + + <tr> + <td><?php echo _('Newest Artist Additions'); ?>:</td> + <td> + <input type="checkbox" name="new_artists" value="yes"> + </td> + <td><?php echo _('Most Popular Artists'); ?>:</td> + <td> + <input type="checkbox" name="pop_artists" value="yes"> + </td> + </tr> + + <tr> + <td><?php echo _('Newest Album Additions'); ?>:</td> + <td> + <input type="checkbox" name="new_albums" value="yes"> + </td> + <td><?php echo _('Most Popular Songs'); ?>:</td> + <td> + <input type="checkbox" name="pop_songs" value="yes"> + </td> + </tr> + </table> + </td> + <tr> <tr> <td><?php echo _('Subject'); ?>:</td> - <td> + <td colspan="3"> <input name="subject" value="<?php echo scrub_out($_POST['subject']); ?>" size="50"></input> </td> </tr> |