51 public $errors = array();
72 public $deliveryreceipt;
86 public function __construct($to, $from, $msg, $deliveryreceipt = 0, $deferred = 0, $priority = 3, $class = 1)
92 if (preg_match(
'/^win/i', PHP_OS)) {
95 if (preg_match(
'/^mac/i', PHP_OS)) {
101 $this->error =
'No SMS Engine defined';
102 throw new Exception(
'No SMS Engine defined');
105 dol_syslog(
"CSMSFile::CSMSFile: MAIN_SMS_SENDMODE=".
getDolGlobalString(
'MAIN_SMS_SENDMODE').
" charset=".$conf->file->character_set_client.
" from=".$from.
", to=".$to.
", msg length=".strlen($msg), LOG_DEBUG);
106 dol_syslog(
"CSMSFile::CSMSFile: deferred=".$deferred.
" priority=".$priority.
" class=".$class, LOG_DEBUG);
109 $this->addr_from = $from;
110 $this->addr_to = $to;
111 $this->deferred = $deferred;
112 $this->priority = $priority;
113 $this->
class = $class;
114 $this->deliveryreceipt = $deliveryreceipt;
115 $this->message = $msg;
116 $this->nostop =
false;
129 $errorlevel = error_reporting();
130 error_reporting($errorlevel ^ E_WARNING);
134 dol_syslog(
"CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG);
135 dol_syslog(
"CSMSFile::sendfile message=\n".$this->message);
137 $this->message = stripslashes($this->message);
147 $classmoduleofsender =
getDolGlobalString(
'MAIN_MODULE_'.strtoupper($sendmode).
'_SMS', $sendmode);
148 if ($classmoduleofsender ==
'ovh') {
149 $classmoduleofsender =
'ovhsms@ovh';
152 $tmp = explode(
'@', $classmoduleofsender);
153 $classfile = $tmp[0];
154 $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
155 dol_include_once(
'/'.$module.
'/class/'.strtolower($classfile).
'.class.php');
157 $classname = ucfirst($classfile);
158 if (class_exists($classname)) {
159 $sms =
new $classname($this->db);
160 $sms->expe = $this->addr_from;
161 $sms->dest = $this->addr_to;
162 $sms->deferred = $this->deferred;
163 $sms->priority = $this->priority;
164 $sms->class = $this->class;
165 $sms->message = $this->message;
166 $sms->nostop = $this->nostop;
167 $sms->deliveryreceipt = $this->deliveryreceipt;
169 $sms->socid = $this->socid;
170 $sms->contact_id = $this->contact_id;
171 $sms->member_id = $this->member_id;
172 $sms->fk_project = $this->fk_project;
174 $res = $sms->SmsSend();
176 $this->error = $sms->error;
177 $this->errors = $sms->errors;
179 dol_syslog(
"CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
181 dol_syslog(
"CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
189 $sms->error =
'The SMS manager "'.$classfile.
'" defined into SMS setup MAIN_MODULE_'.strtoupper($sendmode).
'_SMS is not found';
192 dol_print_error(
'',
'Error to get list of senders: '.$e->getMessage());
198 return 'Bad value for MAIN_SMS_SENDMODE constant';
201 $this->error =
'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
202 dol_syslog(
"CSMSFile::sendfile: ".$this->error, LOG_WARNING);
205 error_reporting($errorlevel);
221 global $conf, $dolibarr_main_data_root;
223 if (@is_writeable($dolibarr_main_data_root)) {
224 $outputfile = $dolibarr_main_data_root.
"/dolibarr_sms.log";
225 $fp = fopen($outputfile,
"w");
227 fputs($fp,
"From: ".$this->addr_from.
"\n");
228 fputs($fp,
"To: ".$this->addr_to.
"\n");
229 fputs($fp,
"Priority: ".$this->priority.
"\n");
230 fputs($fp,
"Class: ".$this->
class.
"\n");
231 fputs($fp,
"Deferred: ".$this->deferred.
"\n");
232 fputs($fp,
"DisableStop: ".$this->nostop.
"\n");
233 fputs($fp,
"DeliveryReceipt: ".$this->deliveryreceipt.
"\n");
234 fputs($fp,
"Message:\n".$this->message);
252 global $conf, $dolibarr_main_data_root;
254 if (@is_writeable($dolibarr_main_data_root)) {
255 $outputfile = $dolibarr_main_data_root.
"/dolibarr_sms.log";
256 $fp = fopen($outputfile,
"a+");
258 fputs($fp,
"\nResult id=".$result);
Class to send SMS Usage: $smsfile = new CSMSFile($subject,$sendto,$replyto,$message,...
dump_sms_result($result)
Write content of a SendSms result into a dump file (mode = all) Used for debugging.
sendfile()
Send sms that was prepared by constructor.
dump_sms()
Write content of a SendSms request into a dump file (mode = all) Used for debugging.
__construct($to, $from, $msg, $deliveryreceipt=0, $deferred=0, $priority=3, $class=1)
CSMSFile.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolChmod($filepath, $newmask='')
Change mod of a file.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.