Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Aiheen aloitti: cleoni - helmikuu 20, 2008, 08:03:11 AP

Otsikko: e-mail notification to all
Kirjoitti: cleoni - helmikuu 20, 2008, 08:03:11 AP
Hi all,
we have an installation of SMF that is being used as a work tool for a closed group of 20-30 people.

They use it to keep in touch and share documents, as an alternative of a mailing list.

it would be interesting to have either:

- an option "notify all users about all forums and topics" so that every user gets an e-mail notification upon any post in any forum (possibly including calendar). The notification - as currently - should be sent only once, then the system should stop e-mail to that user until she comes and visits the forum"

- since users have got already the possibility to subscribe to individual topics and forums, an utility with which the admin subscribes all users to all forums quickly would be a good help.
the individual users cound un-subscribe from forums if they want to, but at least the subscribe-all task could be done easily without the need to do it manually one by one

Best,

Otsikko: Re: e-mail notification to all
Kirjoitti: cleoni - helmikuu 20, 2008, 09:02:00 AP
I did it by myself!

I wrote an utility that lets you subscribe all users (or a subset) to all forums (or a subset).

Just create a

utility

subfolder under your SMF forum,
create a file in it, say,

subscribeall.php

then copy+paste this code in it:


<?php
require '../Settings.php';
$db_con = mysql_connect($db_server,$db_user,$db_passwd);


if (isset($_POST['go']) && $_POST['go']) {

   $users = array();
   $boards = array();

   foreach (array_keys($_REQUEST) as $k) {
      if (substr($k,0,10) == 'subscribe_') {
         array_push($users,substr($k,10));
      }
   }

   foreach (array_keys($_REQUEST) as $k) {
      if (substr($k,0,6) == 'board_') {
         array_push($boards,substr($k,6));
      }
   }

   subscribe($users,$boards);
} else {

   $sql = "SELECT * FROM smf_members WHERE 1 ORDER BY memberName";
   $rs = mysql_db_query($db_name,$sql,$db_con);

   echo '<html><head></head>';
   echo '<body>';
   echo '<h1>Batch subscribe users</h1>';
   echo '<form method="post">';

   if ($rs && mysql_num_rows($rs) > 0) {
      while ($rec = mysql_fetch_assoc($rs)) {
            $sel = '';
            if ($rec['cate_id'] == $default) $sel = 'SELECTED ';
            echo '<input type="checkbox" value="1" name="subscribe_'.$rec['ID_MEMBER'].'" checked>'.$rec['memberName']."<br /></option>\n";
      }
      mysql_free_result($rs);
   }
   echo '<h2>To boards:</h2>';
   // Get boards
   $sql = "SELECT * FROM smf_boards ORDER BY name";
   $rs = mysql_db_query($db_name,$sql,$db_con);
   if ($rs && mysql_num_rows($rs) > 0) {
      while ($rec = mysql_fetch_assoc($rs)) {
            echo '<input type="checkbox" value="1" name="board_'.$rec['ID_BOARD'].'" checked>'.$rec['name']."<br /></option>\n";
      }
      mysql_free_result($rs);
   }


   echo '<input type="submit" name="go" value="Go!">';
   echo '</form>';
   echo '</body></html>';
}

function subscribe($users,$boards) {
   global $db_con,$db_name;

   foreach ($users as $u) {
         echo "<br>Subscribing user #$u...<br>";

         $sql = "DELETE FROM smf_log_notify WHERE ID_TOPIC=0 AND ID_MEMBER = $u";
         mysql_db_query($db_name,$sql,$db_con);
         if ($errno = mysql_errno()) {
            echo "$sql<br/>";
            $rs =  $errno . ": " . mysql_error(). "<br/>\n";
            echo "result: $rs";
         }

         echo "to board #<br>";
         foreach ($boards as $b) {
            echo "$b ";
            $sql = "INSERT INTO smf_log_notify (ID_MEMBER,ID_TOPIC,ID_BOARD) VALUES ($u,0,$b)";
            mysql_db_query($db_name,$sql,$db_con);
            if ($errno = mysql_errno()) {
               echo "$sql<br/>";
               $rs =  $errno . ": " . mysql_error(). "<br/>\n";
               echo "result: $rs";
            }
         }
   }

}

?>


then opening:

http://yourserver.com/forum/utility/subscribeall.php

will let you select and do the job!

Otsikko: Re: e-mail notification to all
Kirjoitti: Cozzman - helmikuu 28, 2008, 01:25:58 IP
thank you SOOO much this is GREAT.

Now if i can only figure out how to globally change the users Notification options from the worthless defaults (or change the defaults themselves as they are terrible)
Otsikko: Re: e-mail notification to all
Kirjoitti: cleoni - helmikuu 28, 2008, 03:31:37 IP
I'm happy to read that's been useful to others :-)

Cheers!