kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file notification_lib.php

Documentation is available at notification_lib.php

  1. <?php
  2. /**
  3.  * eMail Notification Library
  4.  *
  5.  * @package kernel
  6.  * @version $Header: /cvsroot/bitweaver/_bit_kernel/notification_lib.php,v 1.9 2007/01/06 09:46:16 squareing Exp $
  7.  * @author awcolley
  8.  *
  9.  *  created 2003/06/03
  10.  *
  11.  *  Copyright (c) 2004 bitweaver.org
  12.  *  Copyright (c) 2003 tikwiki.org
  13.  *  Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  14.  *  All Rights Reserved. See copyright.txt for details and a complete list of authors.
  15.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
  16.  */
  17.  
  18. /**
  19.  * A library use to store email addresses registered for specific notification events.
  20.  *
  21.  * Currently used in articles, trackers, users register and wiki.
  22.  *
  23.  * @package kernel
  24.  * @todo does not need to inherit BitBase class. Should hold a BitDb connection as a
  25.  *  global variable.
  26.  */
  27. class NotificationLib extends BitBase
  28. {
  29.     /**
  30.     * Notifies via email triggered events.
  31.     */
  32.     function NotificationLib()
  33.     {
  34.         BitBase::BitBase();
  35.     }
  36.     /**
  37.     * Lists registered notification events
  38.     * @param offset the location to begin listing from
  39.     * @param max_records the maximum number of records returned
  40.     * @param sort_mode the method of sorting used in the listing
  41.     * @param find text used to filter listing
  42.     * @return array of registered notification events
  43.     */
  44.     function list_mail_events($offset$max_records$sort_mode$find)
  45.     {
  46.         if ($find)
  47.         {
  48.             $findesc '%' strtoupper$find '%';
  49.             $mid " where (UPPER(`event`) like ? or UPPER(`email`) like ?)";
  50.             $bindvars=array($findesc,$findesc);
  51.         }
  52.         else
  53.         {
  54.             $mid " ";
  55.             $bindvars=array();
  56.         }
  57.         $query "select * from `".BIT_DB_PREFIX."mail_notifications$mid order by ".$this->mDb->convertSortmode($sort_mode);
  58.         $query_cant "select count(*) from `".BIT_DB_PREFIX."mail_notifications$mid";
  59.         $result $this->mDb->query($query,$bindvars,$max_records,$offset);
  60.         $cant $this->mDb->getOne($query_cant,$bindvars);
  61.         $ret array();
  62.         while ($res $result->fetchRow())
  63.         {
  64.             $ret[$res;
  65.         }
  66.         $retval array();
  67.         $retval["data"$ret;
  68.         $retval["cant"$cant;
  69.         return $retval;
  70.     }
  71.     /**
  72.     * Adds an email address for a specified event notification
  73.     * @param event the specified event
  74.     * @param object the specified object
  75.     * @param email the email to remove
  76.     * @return array of the notification record
  77.     */
  78.     function add_mail_event($event$object$email)
  79.     {
  80.         $query "insert into `".BIT_DB_PREFIX."mail_notifications`(`event`,`object`,`email`) values(?,?,?)";
  81.         $result $this->mDb->query($queryarray($event,$object,$email) );
  82.     }
  83.     /**
  84.     * Removes an email address for a specified event notification
  85.     * @param event the specified event
  86.     * @param object the specified object
  87.     * @param email the email to remove
  88.     */
  89.     function remove_mail_event($event$object$email)
  90.     {
  91.         $query "delete from `".BIT_DB_PREFIX."mail_notifications` where `event`=? and `object`=? and `email`=?";
  92.         $result $this->mDb->query($query,array($event,$object,$email));
  93.     }
  94.  
  95.     /**
  96.     * Retrieves the email addresses for a specific event
  97.     * @param event the specified event
  98.     * @param object the specified object
  99.     * @return array of email addresses
  100.     */
  101.     function get_mail_events($event$object)
  102.     {
  103.         $query "select `email` from `".BIT_DB_PREFIX."mail_notifications` where `event`=? and (`object`=? or `object`='*')";
  104.         $result $this->mDb->query($queryarray($event,$object) );
  105.         $ret array();
  106.         while ($res $result->fetchRow())
  107.         {
  108.             $ret[$res["email"];
  109.         }
  110.         return $ret;
  111.     }
  112.  
  113.     /**
  114.     * Post changes to registered email addresses related to a change event
  115.     * @param object number of the content item being updated
  116.     * @param object content_type of the item
  117.     * @param object the package that is being updated
  118.     * @param object the name of the object
  119.     * @param object the name of user making the change
  120.     * @param object any comment added to the change
  121.     * @param object the content of the change
  122.     *
  123.     * @todo Improve the generic handling of the messages
  124.     *  Param information probably needs to be passed as an array, or accessed from Content directly
  125.     */
  126.     function post_content_event($contentid$type$package$name$user$comment$data)
  127.     global $gBitSystem;
  128.             
  129.         $emails $this->get_mail_events($package.'_page_changes'$type $contentid);
  130.  
  131.         foreach ($emails as $email{
  132.             global $gBitSmarty;
  133.             $gBitSmarty->assign('mail_site'$_SERVER["SERVER_NAME"]);
  134.             $gBitSmarty->assign('mail_page'$name );
  135.             $gBitSmarty->assign('mail_date'$gBitSystem->getUTCTime());
  136.             $gBitSmarty->assign('mail_user'$user );
  137.             $gBitSmarty->assign('mail_comment'$comment );
  138.             $gBitSmarty->assign('mail_last_version'1);
  139.             $gBitSmarty->assign('mail_data'$data );
  140.             $gBitSmarty->assign('mail_machine'httpPrefix());
  141.             $gBitSmarty->assign('mail_pagedata'$data );
  142.             $mail_data $gBitSmarty->fetch('bitpackage:'.$package.'/'.$package.'_change_notification.tpl');
  143.  
  144.             @mail($email$package tra(' page')' ' $name ' ' tra('changed')$mail_data"From: ".$gBitSystem->getConfig'site_sender_email' )."\r\nContent-type: text/plain;charset=utf-8\r\n" );
  145.         }
  146.     }
  147.  
  148.     /**
  149.     * Notifies registered list of eMail recipients of new user registrations
  150.     * @param object name of the new user
  151.     */
  152.     function post_new_user_event$user )
  153.     global $gBitSystem$gBitSmarty;
  154.         $emails $this->get_mail_events('user_registers','*');
  155.         foreach($emails as $email{
  156.             $gBitSmarty->assign('mail_user',$user);
  157.             $gBitSmarty->assign('mail_date',$gBitSystem->getUTCTime());
  158.             $gBitSmarty->assign('mail_site',$_SERVER["SERVER_NAME"]);
  159.             $mail_data $gBitSmarty->fetch('bitpackage:users/new_user_notification.tpl');
  160.  
  161.             mail$emailtra('New user registration'),$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n");
  162.         }
  163.     }
  164.  
  165. }
  166.  
  167. /**
  168.  * @global NotificationLib Notification library
  169.  */
  170. global $notificationlib;
  171. $notificationlib new NotificationLib()
  172. ?>

Documentation generated on Thu, 15 Feb 2007 20:46:19 +0000 by phpDocumentor 1.3.0