69 public function __construct($to, $from, $msg, $deliveryreceipt = 0, $deferred = 0, $priority = 3, $class = 1)
75 if (preg_match(
'/^win/i', PHP_OS)) {
78 if (preg_match(
'/^mac/i', PHP_OS)) {
83 if (empty($conf->global->MAIN_SMS_SENDMODE)) {
84 $this->error =
'No SMS Engine defined';
88 dol_syslog(
"CSMSFile::CSMSFile: MAIN_SMS_SENDMODE=".$conf->global->MAIN_SMS_SENDMODE.
" charset=".$conf->file->character_set_client.
" from=".$from.
", to=".$to.
", msg length=".strlen($msg), LOG_DEBUG);
89 dol_syslog(
"CSMSFile::CSMSFile: deferred=".$deferred.
" priority=".$priority.
" class=".$class, LOG_DEBUG);
92 $this->addr_from = $from;
94 $this->deferred = $deferred;
95 $this->priority = $priority;
96 $this->
class = $class;
97 $this->message = $msg;
98 $this->nostop =
false;
111 $errorlevel = error_reporting();
112 error_reporting($errorlevel ^ E_WARNING);
116 dol_syslog(
"CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG);
117 dol_syslog(
"CSMSFile::sendfile message=\n".$this->message);
119 $this->message = stripslashes($this->message);
121 if (!empty($conf->global->MAIN_SMS_DEBUG)) {
125 if (empty($conf->global->MAIN_DISABLE_ALL_SMS)) {
127 if ($conf->global->MAIN_SMS_SENDMODE ==
'ovh') {
129 $sms =
new OvhSms($this->
db);
130 $sms->expe = $this->addr_from;
131 $sms->dest = $this->addr_to;
132 $sms->message = $this->message;
133 $sms->deferred = $this->deferred;
134 $sms->priority = $this->priority;
135 $sms->class = $this->class;
136 $sms->nostop = $this->nostop;
138 $sms->socid = $this->socid;
139 $sms->contact_id = $this->contact_id;
140 $sms->member_id = $this->member_id;
141 $sms->project = $this->fk_project;
143 $res = $sms->SmsSend();
146 $this->error = $sms->error;
147 dol_syslog(
"CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
149 dol_syslog(
"CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
151 if (!empty($conf->global->MAIN_SMS_DEBUG)) {
155 } elseif (!empty($conf->global->MAIN_SMS_SENDMODE)) {
156 $tmp = explode(
'@', $conf->global->MAIN_SMS_SENDMODE);
157 $classfile = $tmp[0];
158 $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
161 $classname = ucfirst($classfile);
162 $sms =
new $classname($this->
db);
163 $sms->expe = $this->addr_from;
164 $sms->dest = $this->addr_to;
165 $sms->deferred = $this->deferred;
166 $sms->priority = $this->priority;
167 $sms->class = $this->class;
168 $sms->message = $this->message;
169 $sms->nostop = $this->nostop;
171 $sms->socid = $this->socid;
172 $sms->contact_id = $this->contact_id;
173 $sms->member_id = $this->member_id;
174 $sms->fk_project = $this->fk_project;
176 $res = $sms->SmsSend();
178 $this->error = $sms->error;
179 $this->errors = $sms->errors;
181 dol_syslog(
"CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
183 dol_syslog(
"CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
185 if (!empty($conf->global->MAIN_SMS_DEBUG)) {
190 dol_print_error(
'',
'Error to get list of senders: '.$e->getMessage());
196 return 'Bad value for MAIN_SMS_SENDMODE constant';
199 $this->error =
'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
200 dol_syslog(
"CSMSFile::sendfile: ".$this->error, LOG_WARNING);
203 error_reporting($errorlevel);
219 global $conf, $dolibarr_main_data_root;
221 if (@is_writeable($dolibarr_main_data_root)) {
222 $outputfile = $dolibarr_main_data_root.
"/dolibarr_sms.log";
223 $fp = fopen($outputfile,
"w");
225 fputs($fp,
"From: ".$this->addr_from.
"\n");
226 fputs($fp,
"To: ".$this->addr_to.
"\n");
227 fputs($fp,
"Priority: ".$this->priority.
"\n");
228 fputs($fp,
"Class: ".$this->
class.
"\n");
229 fputs($fp,
"Deferred: ".$this->deferred.
"\n");
230 fputs($fp,
"DisableStop: ".$this->nostop.
"\n");
231 fputs($fp,
"Message:\n".$this->message);
234 if (!empty($conf->global->MAIN_UMASK)) {
235 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
251 global $conf, $dolibarr_main_data_root;
253 if (@is_writeable($dolibarr_main_data_root)) {
254 $outputfile = $dolibarr_main_data_root.
"/dolibarr_sms.log";
255 $fp = fopen($outputfile,
"a+");
257 fputs($fp,
"\nResult id=".$result);
260 if (!empty($conf->global->MAIN_UMASK)) {
261 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
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...
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.