phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] property/inc/custom forward_mail_as_sms.php


From: Sigurd Nes
Subject: [Phpgroupware-cvs] property/inc/custom forward_mail_as_sms.php
Date: Mon, 26 Feb 2007 13:42:13 +0000

CVSROOT:        /sources/phpgroupware
Module name:    property
Changes by:     Sigurd Nes <sigurdne>   07/02/26 13:42:13

Added files:
        inc/custom     : forward_mail_as_sms.php 

Log message:
        

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/property/inc/custom/forward_mail_as_sms.php?cvsroot=phpgroupware&rev=1.1

Patches:
Index: forward_mail_as_sms.php
===================================================================
RCS file: forward_mail_as_sms.php
diff -N forward_mail_as_sms.php
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ forward_mail_as_sms.php     26 Feb 2007 13:42:13 -0000      1.1
@@ -0,0 +1,185 @@
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage custom
+       * @version $Id: forward_mail_as_sms.php,v 1.1 2007/02/26 13:42:13 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class forward_mail_as_sms
+       {
+               var     $function_name = 'forward_mail_as_sms';
+
+               function forward_mail_as_sms()
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->db                       = 
$this->bocommon->new_db();
+                       $this->db2                      = 
$this->bocommon->new_db();
+
+                       $this->join                     = $this->bocommon->join;
+                       $this->left_join        = $this->bocommon->left_join;
+                       $this->like                     = $this->bocommon->like;
+
+               }
+
+               function pre_run($data='')
+               {
+                       if($data['enabled']==1)
+                       {
+                               $confirm        = True;
+                               $cron           = True;
+                       }
+                       else
+                       {
+                               $confirm        = 
get_var('confirm',array('POST'));
+                               $execute        = 
get_var('execute',array('GET'));
+                       }
+
+
+                       if ($confirm)
+                       {
+                               $this->execute($cron);
+                       }
+                       else
+                       {
+                               $this->confirm($execute=False);
+                               $data['account_id'] = 
$GLOBALS['phpgw']->accounts->name2id($data['user']);
+                               
$GLOBALS['phpgw']->session->appsession('session_data','mail2sms',$data);
+                       }
+               }
+
+               function confirm($execute='')
+               {
+                       $link_data = array
+                       (
+                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
+                               'function'      => $this->function_name,
+                               'execute'       => $execute,
+                       );
+
+                       if(!$execute)
+                       {
+                               $lang_confirm_msg       = 'Vil du virkelig 
utføre denne operasjonen';
+                       }
+
+                       $lang_yes                       = lang('yes');
+
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('confirm_custom'));
+
+                       $msgbox_data = 
$this->bocommon->msgbox_data($this->receipt);
+
+                       $data = array
+                       (
+                               'msgbox_data'                   => 
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                               'done_action'                   => 
$GLOBALS['phpgw']->link('/admin/index.php'),
+                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
+                               'message'                               => 
$this->receipt['message'],
+                               'lang_confirm_msg'              => 
$lang_confirm_msg,
+                               'lang_yes'                              => 
$lang_yes,
+                               'lang_yes_statustext'   => lang('Check for new 
mail - and forward as sms'),
+                               'lang_no_statustext'    => 'tilbake',
+                               'lang_no'                               => 
lang('no'),
+                               'lang_done'                             => 
lang('cancel'),
+                               'lang_done_statustext'  => 'tilbake'
+                       );
+
+                       $appname                = lang('Async service');
+                       $function_msg   = 'Forward email as SMS';
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
+                       $GLOBALS['phpgw']->xslttpl->pp();
+               }
+
+               function execute($cron='')
+               {
+                       $receipt = $this->check_for_new_mail();
+                       $this->cron_log($receipt,$cron);
+
+                       if(!$cron)
+                       {
+                               $this->confirm($execute=False);
+                       }
+               }
+
+               function cron_log($receipt='',$cron='')
+               {
+                       $insert_values= array(
+                               $cron,
+                               date($this->bocommon->datetimeformat),
+                               $this->function_name,
+                               $receipt
+                               );
+
+                       $insert_values  = 
$this->bocommon->validate_db_insert($insert_values);
+
+                       $sql = "INSERT INTO fm_cron_log 
(cron,cron_date,process,message) "
+                                       . "VALUES ($insert_values)";
+                       $this->db->query($sql,__LINE__,__FILE__);
+               }
+
+               function check_for_new_mail()
+               {
+
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','mail2sms');
+//_debug_array($data);
+                       $GLOBALS['phpgw_info']['user']['account_id'] = 
$data['account_id'];
+
+                       $GLOBALS['phpgw']->preferences->account_id = 
$data['account_id'];
+                       $pref = 
$GLOBALS['phpgw']->preferences->read_repository();
+                       
$GLOBALS['phpgw_info']['user']['preferences']['felamimail'] = 
$pref['felamimail'];
+
+//_debug_array($pref);
+
+                       $bofelamimail   = 
CreateObject('felamimail.bofelamimail');
+                       $connectionStatus = $bofelamimail->openConnection();
+                       $headers = $bofelamimail->getHeaders(0, $maxMessages = 
15, $sort = 6);
+
+                       $j = 0;
+                       foreach ($headers['header'] as $header)
+                       {
+                               if($header['seen'] == 0)
+                               {
+                                       $sms[$j]['message'] = 
$header['subject'];
+                                       $bodyParts = 
$bofelamimail->getMessageBody($header['uid']);
+                                       $sms[$j]['message'] = "\n";
+                                       for($i=0; $i<count($bodyParts); $i++ )
+                                       {
+                                               $sms[$j]['message'] = 
$bodyParts[$i]['message'];
+                                       }
+                                       $sms[$j]['message'] = 
substr($sms[$j]['message'],0,160);
+                                       $j++;
+                               }
+                       }
+                       if($connectionStatus == 'True')
+                       {
+                               $bofelamimail->closeConnection();
+                       }
+
+                       $bosms  = CreateObject('sms.bosms',False);
+
+                       if(isset($sms) && is_array($sms))
+                       {
+                               foreach ($sms as $entry)
+                               {
+                                       
$bosms->send_sms(array('p_num_text'=>$data['cellphone'], 'message' 
=>$entry['message']));
+                               }
+                       }
+
+                       $msg = $j . ' messages er sendt';
+                       $this->receipt['message'][]=array('msg'=> $msg);
+                       return $msg;
+
+               }
+       }
+?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]