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$
  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 below for details and a complete list of authors.
  15.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html 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.     * Lists registered notification events
  31.     * @param offset the location to begin listing from
  32.     * @param max_records the maximum number of records returned
  33.     * @param sort_mode the method of sorting used in the listing
  34.     * @param find text used to filter listing
  35.     * @return array of registered notification events
  36.     */
  37.     function list_mail_events($offset$max_records$sort_mode$find)
  38.     {
  39.         if ($find)
  40.         {
  41.             $findesc '%' strtoupper$find '%';
  42.             $mid " where (UPPER(`event`) like ? or UPPER(`email`) like ?)";
  43.             $bindvars=array($findesc,$findesc);
  44.         }
  45.         else
  46.         {
  47.             $mid " ";
  48.             $bindvars=array();
  49.         }
  50.         $query "select * from `".BIT_DB_PREFIX."mail_notifications` $mid order by ".$this->mDb->convertSortmode($sort_mode);
  51.         $query_cant "select count(*) from `".BIT_DB_PREFIX."mail_notifications` $mid";
  52.         $result $this->mDb->query($query,$bindvars,$max_records,$offset);
  53.         $cant $this->mDb->getOne($query_cant,$bindvars);
  54.         $ret array();
  55.         while ($res $result->fetchRow())
  56.         {
  57.             $ret[$res;
  58.         }
  59.         $retval array();
  60.         $retval["data"$ret;
  61.         $retval["cant"$cant;
  62.         return $retval;
  63.     }
  64.     /**
  65.     * Adds an email address for a specified event notification
  66.     * @param event the specified event
  67.     * @param object the specified object
  68.     * @param email the email to remove
  69.     * @return array of the notification record
  70.     */
  71.     function add_mail_event($event$object$email)
  72.     {
  73.         $query "insert into `".BIT_DB_PREFIX."mail_notifications`(`event`,`object`,`email`) values(?,?,?)";
  74.         $result $this->mDb->query($queryarray($event,$object,$email) );
  75.     }
  76.     /**
  77.     * Removes an email address for a specified event notification
  78.     * @param event the specified event
  79.     * @param object the specified object
  80.     * @param email the email to remove
  81.     */
  82.     function remove_mail_event($event$object$email)
  83.     {
  84.         $query "delete from `".BIT_DB_PREFIX."mail_notifications` where `event`=? and `object`=? and `email`=?";
  85.         $result $this->mDb->query($query,array($event,$object,$email));
  86.     }
  87.  
  88.     /**
  89.     * Retrieves the email addresses for a specific event
  90.     * @param event the specified event
  91.     * @param object the specified object
  92.     * @return array of email addresses
  93.     */
  94.     function get_mail_events($event$object)
  95.     {
  96.         $query "select `email` from `".BIT_DB_PREFIX."mail_notifications` where `event`=? and (`object`=? or `object`='*')";
  97.         $result $this->mDb->query($queryarray($event,$object) );
  98.         $ret array();
  99.         while ($res $result->fetchRow())
  100.         {
  101.             $ret[$res["email"];
  102.         }
  103.         return $ret;
  104.     }
  105.  
  106.     /**
  107.     * Post changes to registered email addresses related to a change event
  108.     * @param object number of the content item being updated
  109.     * @param object content_type of the item
  110.     * @param object the package that is being updated
  111.     * @param object the name of the object
  112.     * @param object the name of user making the change
  113.     * @param object any comment added to the change
  114.     * @param object the content of the change
  115.     *
  116.     * @todo Improve the generic handling of the messages
  117.     *  Param information probably needs to be passed as an array, or accessed from Content directly
  118.     */
  119.     function post_content_event($contentid$type$package$name$user$comment$data)
  120.     global $gBitSystem;
  121.             
  122.         $emails $this->get_mail_events($package.'_page_changes'$type $contentid);
  123.  
  124.         foreach ($emails as $email{
  125.             global $gBitSmarty;
  126.             $gBitSmarty->assign('mail_site'$_SERVER["SERVER_NAME"]);
  127.             $gBitSmarty->assign('mail_page'$name );
  128.             $gBitSmarty->assign('mail_date'$gBitSystem->getUTCTime());
  129.             $gBitSmarty->assign('mail_user'$user );
  130.             $gBitSmarty->assign('mail_comment'$comment );
  131.             $gBitSmarty->assign('mail_last_version'1);
  132.             $gBitSmarty->assign('mail_data'$data );
  133.             $gBitSmarty->assign('mail_machine'httpPrefix());
  134.             $gBitSmarty->assign('mail_pagedata'$data );
  135.             $mail_data $gBitSmarty->fetch('bitpackage:'.$package.'/'.$package.'_change_notification.tpl');
  136.  
  137.             @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" );
  138.         }
  139.     }
  140.  
  141.     /**
  142.     * Notifies registered list of eMail recipients of new user registrations
  143.     * @param object name of the new user
  144.     */
  145.     function post_new_user_event$user )
  146.     global $gBitSystem$gBitSmarty;
  147.         $emails $this->get_mail_events('user_registers','*');
  148.         foreach($emails as $email{
  149.             $gBitSmarty->assign('mail_user',$user);
  150.             $gBitSmarty->assign('mail_date',$gBitSystem->getUTCTime());
  151.             $gBitSmarty->assign('mail_site',$_SERVER["SERVER_NAME"]);
  152.             $mail_data $gBitSmarty->fetch('bitpackage:users/new_user_notification.tpl');
  153.  
  154.             mail$emailtra('New user registration'),$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n");
  155.         }
  156.     }
  157.  
  158. }
  159.  
  160. /**
  161.  * @global NotificationLib Notification library
  162.  */
  163. global $notificationlib;
  164. $notificationlib new NotificationLib()
  165. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:14 +0000 by phpDocumentor 1.5.0-lsces