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';
85 throw new Exception(
'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);