52 public $errors = array();
83 public $deliveryreceipt;
97 public function __construct($to, $from, $msg, $deliveryreceipt = 0, $deferred = 0, $priority = 3, $class = 1)
103 if (preg_match(
'/^win/i', PHP_OS)) {
106 if (preg_match(
'/^mac/i', PHP_OS)) {
112 $this->error =
'No SMS Engine defined';
113 throw new Exception(
'No SMS Engine defined');
116 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);
117 dol_syslog(
"CSMSFile::CSMSFile: deferred=".$deferred.
" priority=".$priority.
" class=".$class, LOG_DEBUG);
120 $this->addr_from = $from;
121 $this->addr_to = $to;
122 $this->deferred = $deferred;
123 $this->priority = $priority;
124 $this->
class = $class;
125 $this->deliveryreceipt = $deliveryreceipt;
126 $this->message = $msg;
127 $this->nostop =
false;
138 $errorlevel = error_reporting();
139 error_reporting($errorlevel ^ E_WARNING);
143 dol_syslog(
"CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG);
144 dol_syslog(
"CSMSFile::sendfile message=\n".$this->message);
146 $this->message = stripslashes($this->message);
156 $classmoduleofsender =
getDolGlobalString(
'MAIN_MODULE_'.strtoupper($sendmode).
'_SMS', $sendmode);
157 if ($classmoduleofsender ==
'ovh') {
158 $classmoduleofsender =
'ovhsms@ovh';
161 $tmp = explode(
'@', $classmoduleofsender);
162 $classfile = $tmp[0];
163 $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
164 dol_include_once(
'/'.$module.
'/class/'.strtolower($classfile).
'.class.php');
166 $classname = ucfirst($classfile);
168 dol_syslog(
"CSMSFile::sendfile: try to include class ".$classname);
170 if (class_exists($classname)) {
171 $sms =
new $classname($this->db);
173 $sms->expe = $this->addr_from;
174 $sms->dest = $this->addr_to;
175 $sms->deferred = $this->deferred;
176 $sms->priority = $this->priority;
177 $sms->class = $this->class;
178 $sms->message = $this->message;
179 $sms->nostop = $this->nostop;
180 $sms->deliveryreceipt = $this->deliveryreceipt;
182 $sms->socid = $this->socid;
183 $sms->contact_id = $this->contact_id;
184 $sms->member_id = $this->member_id;
185 $sms->fk_project = $this->fk_project;
187 $res = $sms->SmsSend();
189 $this->error = $sms->error;
190 $this->errors = $sms->errors;
192 dol_syslog(
"CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
198 dol_syslog(
"CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
205 $this->error =
'The SMS manager "'.$classfile.
'" defined into SMS setup MAIN_MODULE_'.strtoupper($sendmode).
'_SMS is not found';
208 dol_print_error(
null,
'Error to get list of senders: '.$e->getMessage());
213 $this->error =
'Bad value for MAIN_SMS_SENDMODE constant';
217 $this->error =
'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
218 dol_syslog(
"CSMSFile::sendfile: ".$this->error, LOG_WARNING);
221 error_reporting($errorlevel);
237 global $conf, $dolibarr_main_data_root;
239 if (@is_writable($dolibarr_main_data_root)) {
240 $outputfile = $dolibarr_main_data_root.
"/dolibarr_sms.log";
241 $fp = fopen($outputfile,
"w");
243 fwrite($fp,
"From: ".$this->addr_from.
"\n");
244 fwrite($fp,
"To: ".$this->addr_to.
"\n");
245 fwrite($fp,
"Priority: ".$this->priority.
"\n");
246 fwrite($fp,
"Class: ".$this->
class.
"\n");
247 fwrite($fp,
"Deferred: ".$this->deferred.
"\n");
248 fwrite($fp,
"DisableStop: ".((
string) (
int) $this->nostop).
"\n");
249 fwrite($fp,
"DeliveryReceipt: ".$this->deliveryreceipt.
"\n");
250 fwrite($fp,
"Message:\n".$this->message);
268 global $dolibarr_main_data_root;
270 if (@is_writable($dolibarr_main_data_root)) {
271 $outputfile = $dolibarr_main_data_root.
"/dolibarr_sms.log";
272 $fp = fopen($outputfile,
"a+");
274 fwrite($fp,
"\nResult of SmsSend = ".$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.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.