[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/sitemgr/inc/ -> class.notification_bo.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare SiteMgr - Web Content Management                              *
   4      * http://www.egroupware.org                                                *
   5      * --------------------------------------------                             *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.notification_bo.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14      class notification_bo
  15      {
  16       
  17          var $so;
  18  
  19  		function notification_bo()
  20          {
  21              $this->so =& CreateObject("sitemgr.notification_so");
  22          }
  23  
  24  		function create_notification($email,$all_langs)
  25          {
  26              return $this->so->create_notification($email,$all_langs);
  27          }
  28  
  29  		function delete_notifications($email)
  30          {
  31              $this->so->delete_notifications($email);
  32          }
  33  
  34  		function get_notifications($site_id,$lang)
  35          {
  36              return $this->so->get_notifications($site_id,$lang);
  37          }
  38  
  39  		function translate($data,$transl=False,$lang='') {
  40              if (!$transl) {
  41                  $transl=CreateObject('phpgwapi.translation',array('sitemgr',$lang));
  42              }
  43              $msg='';
  44              foreach($data as $val) {
  45                  if (is_array($val)) {
  46                      if ($val['translate'])
  47                          $msg.=$transl->translate($val['text']);
  48                      else
  49                          $msg.=implode('',$val);
  50                  }
  51                  else $msg.=$val;
  52              }
  53              return $msg;
  54          }
  55          
  56  		function prepare_url($extravars = '')
  57          {
  58              // Change http://xyz/index.php?page_name=page1 to
  59              // http://xyz/page1/ if the htaccess stuff is enabled
  60              if (!is_array($extravars))
  61              {
  62                  parse_str($extravars,$extravarsnew);
  63                  $extravars = $extravarsnew;
  64              }
  65  
  66              if ($extravars['page_name'] != '' && $GLOBALS['sitemgr_info']['htaccess_rewrite'])
  67              {
  68                  $url = '/'.$extravars['page_name'];
  69                  unset($extravars['page_name']);
  70              }
  71  
  72              // In certain instances (wouldn't it be better to fix these instances? MT)
  73              // a url may look like this: 'http://xyz//hi.php' or
  74              // like this: '//index.php?blahblahblah' -- so the code below will remove
  75              // the inappropriate double slashes and leave appropriate ones
  76              $url = $GLOBALS['Common_BO']->sites->current_site['site_url'] . $url;
  77              if (!strpos($url,"://")) {
  78                  $url="http://".$GLOBALS['egw_info']['server']['hostname'].$url;
  79              }
  80  
  81              $url = substr(ereg_replace('([^:])//','\1/','s'.$url),1);
  82  
  83              // build the extravars string from a array
  84              $vars = array();
  85              foreach($extravars as $key => $value)
  86              {
  87                  $vars[] = urlencode($key).'='.urlencode($value);
  88              }
  89              return $url . (count($vars) ? '?'.implode('&',$vars) : '');
  90          }
  91          
  92  		function prepare_message($site_id,$lang,$def_lang,$url,$data)
  93          {
  94              $msg = $this->so->get_message($site_id,$lang,$def_lang);
  95  
  96  //echo __FILE__.__LINE__."<PRE>";
  97  //print_r($msg);
  98  //print_r($GLOBALS['egw']->translation);
  99  //echo "</PRE>";
 100  
 101              if (!$msg) { // the message template is not in the database; use the default message.
 102                  if ($lang==$GLOBALS['lang']) {
 103                      $msg['message']=lang('The website has changed. Too see the change, follow this URL: $URL.');
 104                      $msg['subject']=lang('Automatically generated notification');
 105                  }
 106                  else {
 107                      $transl=CreateObject('phpgwapi.translation',array('sitemgr',$lang));
 108                      $msg['message']=$transl->translate('The website has changed. Too see the change, follow this URL: $URL .');
 109                      $msg['subject']=$transl->translate('Automatically generated notification');
 110                      if (is_array($data))
 111                          $data=$this->translate($data,$transl);
 112                  }
 113              }
 114              
 115              if (is_array($data))
 116                  $data=$this->translate($data,False,$lang);
 117                  
 118              $url=$this->prepare_url($url);
 119              
 120              return str_replace(array('$URL','$DATA','$SITE'),array($url,$data,
 121                  $GLOBALS['Common_BO']->sites->current_site['site_name_'.$lang]),$msg);
 122          }
 123          
 124  		function shall_send($cat_id,$state) 
 125          {
 126              //only send a message if the anonymous user may read the category and
 127              //if the version is either published or preunpublished.
 128              
 129              if (is_array($state)){
 130                  $Shall=False;
 131                  foreach($state as $versionid => $s)
 132                  {
 133                      $Shall = $Shall || 
 134                          ($s==SITEMGR_STATE_PUBLISH || $s==SITEMGR_STATE_PREUNPUBLISH);
 135                  }
 136  //        if (!$Shall) {
 137  //          echo __FILE__.__LINE__."\None of the states is visible. \nCat:|$cat_id|, Sta:|";print_r($state);echo "|<BR>";
 138  //        }
 139                  return $Shall;
 140              }
 141              else if ($state<0) {
 142                  $cat_so=CreateObject("sitemgr.Categories_SO");
 143                  if (!$cat_so->isactive($cat_id,array(SITEMGR_STATE_PUBLISH,SITEMGR_STATE_PREUNPUBLISH))) {
 144  //          echo __FILE__.__LINE__."\nCategory invisible. \nCat:|$cat_id|, Sta:|$state|<BR>";
 145   
 146                      return False;
 147                  }
 148              }
 149              else if ($state!=SITEMGR_STATE_PUBLISH && $state!=SITEMGR_STATE_PREUNPUBLISH) {
 150  //         echo __FILE__.__LINE__."\nChange invisible. \nCat:|$cat_id|, Sta:|$state|<BR>";
 151              
 152                   return False;
 153              }
 154              
 155              return $this->so->get_permissions($cat_id) & EGW_ACL_READ;
 156          }
 157  
 158  		function notify_users($site_id,$cat_id,$state,$lang,$def_lang,$url,$data="N/A") 
 159          {
 160              if (!$this->shall_send($cat_id,$state)) {
 161  //        echo __FILE__.__LINE__."\nMessages not sent due to permission errors. \nCat:|$cat_id|, Sta:|$state|<BR>";
 162                  return;
 163              }
 164                  
 165              $addresses=$this->get_notifications($site_id,$lang);
 166  
 167              if (count($addresses)) {
 168                  $msg=$this->prepare_message($site_id,$lang,$def_lang,$url,$data);
 169  
 170                  $smtp=CreateObject("phpgwapi.send");
 171                  $smtp->Subject=$msg['subject'];
 172                  $smtp->Body=$msg['message'];
 173                  $smtp->WordWrap=$msg['WordWrap'];
 174                  
 175                  foreach($addresses as $value) {
 176                      $smtp->AddAddress($value);
 177  //echo __FILE__.__LINE__."<PRE>\n";        
 178  //print_r($smtp->Subject);
 179  //echo "\n========\n";
 180  //print_r($smtp->Body);
 181  //echo "\n</PRE>";
 182                      if (!$smtp->Send()) {
 183  //echo __FILE__.__LINE__.$value.": $smtp->ErrorInfo <BR/>";             
 184                      }
 185                      $smtp->ClearAddresses();
 186                  }
 187              }
 188          }
 189      }
 190  


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7