NEW FEATURE: use gravatars as icons for players
[e-DoKo.git] / include / functions.php
index d99f9c8732f5757aa14cfcc8ee5caba56104b790..63216eb3d44bbcf91374961ef7da24d337c01a0c 100644 (file)
@@ -58,36 +58,56 @@ function mymail($uid,$subject,$message)
 {
   global $EmailName;
 
-  /* check if user wants email right away or if we should save it in
-   * the database for later delivery
-   */
-  if(0)
+  /* do we send the email right away or save it in the database? */
+  $send_now = 1;
+
+  /* add standard header and footer */
+  $subject = "$EmailName".$subject;
+
+  /* standard goodbye */
+  $footer  = "\nHave a nice day\n".
+    "   your E-Doko service department\n\n".
+    "-- \n".
+    "You can change your mail delivery mode in the preference menu.\n".
+    'web: http://doko.nubati.net   '.
+    'help: http://wiki.nubati.net/EmailDoko   '.
+    'bugs: http://wiki.nubati.net/EmailDokoIssues';
+
+  if(is_array($uid))
     {
-      /* send to database (not yet implemented)*/
+      /* send email to more than one person */
+
+      $header  = "Hello all\n\n";
+
+      foreach($uid as $user)
+       {
+         $all[] = DB_get_email('userid',$user);
+       }
+      $To = implode(",",$all);
     }
   else
     {
-      /* send email right away */
-
-      /* add standard header and footer */
-      $subject = "$EmailName".$subject;
-
       /* standard greeting */
       $name    = DB_get_name('userid',$uid);
       $header  = "Hello $name\n\n";
 
-      /* and standard goodbye */
-      $footer  = "\nHave a nice day\n".
-       "   your E-Doko service department\n\n".
-       "-- \n".
-       "You can change your mail delivery mode in the preference menu.\n".
-       'web: http://doko.nubati.net   '.
-       'help: http://wiki.nubati.net/EmailDoko   '.
-       'bugs: http://wiki.nubati.net/EmailDokoIssues';
-
       $To = DB_get_email('userid',$uid);
 
-      sendmail($To,$subject,$header.$message.$footer);
+      /* check if user wants email right away or if we should save it in
+       * the database for later delivery
+       */
+
+      $PREF = DB_get_PREF($uid);
+      if( $PREF['digest'] != 'digest-off' )
+       $send_now = 0;
+    }
+
+  if($send_now)
+    sendmail($To,$subject,$header.$message.$footer);
+  else
+    {
+      /* store email in database */
+      DB_digest_insert_email($To,$message);
     }
 }
 
@@ -783,7 +803,8 @@ function display_table ()
                     "        Hand.point_call, ".
                     "        User.last_login, ".
                     "        Hand.hash,       ".
-                    "        User.timezone    ".
+                    "        User.timezone,    ".
+                    "        User.email       ".
                     "FROM Hand ".
                     "LEFT JOIN User ON User.id=Hand.user_id ".
                     "WHERE Hand.game_id='".$gameid."' ".
@@ -801,10 +822,14 @@ function display_table ()
       $call      = $r[5];
       $hash      = $r[7];
       $timezone  = $r[8];
+      $email     = $r[9];      
+      $wins      = DB_get_number_of_tricks($gameid,$pos);
       date_default_timezone_set($defaulttimezone);
       $lastlogin = strtotime($r[6]);
       date_default_timezone_set($timezone);
       $timenow   = strtotime(date("Y-m-d H:i:s"));
+      $gravatar = "$name<br /><img class=\"gravatar\" title=\"$name\" src=\"http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?d=identicon\" />";
+
 
       echo "  <div class=\"table".($pos-1)."\">\n";
 
@@ -817,10 +842,10 @@ function display_table ()
          $comment = $vacation[2];
 
              $title = "begin: $start  end: $stop $comment";
-             echo "   <span class=\"vacation\" title=\"$title\">$name (on vacation until $stop)</span> \n";
+             echo "   <span class=\"vacation\" title=\"$title\">$gravatar (on vacation until $stop)</span> \n";
        }
       else
-       echo "   $name \n";
+       echo "   $gravatar \n";
       if($debug)
        echo"</a>\n";
 
@@ -924,6 +949,22 @@ function display_table ()
                             "last login: ".date("Y-m-d H:i:s",$lastlogin)."\">".
                             "<img src=\"pics/button/time-info.png\" class=\"tinybutton\" alt=\"time info\" />".
                             "</span>\n";
+
+      /* show how many tricks the person made */
+      switch($wins)
+       {
+       case 0:
+         echo "#tricks 0"; break;
+       case 1:
+         echo "#tricks 1"; break;
+       case 2:
+       case 3:
+       case 4:
+         echo "#tricks few"; break;
+       default:
+         echo "#tricks many"; break;
+       }
+
       echo "   </div>\n";
 
     }
@@ -942,7 +983,7 @@ function display_user_menu($id)
                     " LEFT JOIN Game On Hand.game_id=Game.id".
                     " WHERE Hand.user_id='$id'".
                     " AND ( Game.player='$id' OR ISNULL(Game.player) )".
-                    " AND Game.status<>'gameover'".
+                    " AND ( Game.status='pre' OR Game.status='play' )".
                     " ORDER BY Game.session" );
 
   $i=0;