| Conditions | 40 |
| Paths | > 20000 |
| Total Lines | 219 |
| Code Lines | 130 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 137 | public function show_form($morecss = 'titlefield', $showform = 1) |
||
| 138 | { |
||
| 139 | // phpcs:enable |
||
| 140 | global $conf, $langs, $form; |
||
| 141 | |||
| 142 | if (!is_object($form)) { |
||
| 143 | $form = new Form($this->db); |
||
| 144 | } |
||
| 145 | |||
| 146 | // Load translation files required by the page |
||
| 147 | $langs->loadLangs(array('other', 'mails', 'sms')); |
||
| 148 | |||
| 149 | $soc = new Societe($this->db); |
||
|
|
|||
| 150 | if (!empty($this->withtosocid) && $this->withtosocid > 0) { |
||
| 151 | $soc->fetch($this->withtosocid); |
||
| 152 | } |
||
| 153 | |||
| 154 | print "\n<!-- Begin form SMS -->\n"; |
||
| 155 | |||
| 156 | print ' |
||
| 157 | <script nonce="' . getNonce() . '" type="text/javascript"> |
||
| 158 | function limitChars(textarea, limit, infodiv) |
||
| 159 | { |
||
| 160 | var text = textarea.value; |
||
| 161 | var textlength = text.length; |
||
| 162 | var info = document.getElementById(infodiv); |
||
| 163 | |||
| 164 | info.innerHTML = (limit - textlength); |
||
| 165 | return true; |
||
| 166 | } |
||
| 167 | </script>'; |
||
| 168 | |||
| 169 | if ($showform) { |
||
| 170 | print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"" . $this->param["returnurl"] . "\">\n"; |
||
| 171 | } |
||
| 172 | |||
| 173 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
| 174 | foreach ($this->param as $key => $value) { |
||
| 175 | print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n"; |
||
| 176 | } |
||
| 177 | print "<table class=\"border centpercent\">\n"; |
||
| 178 | |||
| 179 | // Substitution array |
||
| 180 | if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this. |
||
| 181 | print "<tr><td colspan=\"2\">"; |
||
| 182 | $help = ""; |
||
| 183 | foreach ($this->substit as $key => $val) { |
||
| 184 | $help .= $key . ' -> ' . $langs->trans($val) . '<br>'; |
||
| 185 | } |
||
| 186 | print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help); |
||
| 187 | print "</td></tr>\n"; |
||
| 188 | } |
||
| 189 | |||
| 190 | // From |
||
| 191 | if ($this->withfrom) { |
||
| 192 | if ($this->withfromreadonly) { |
||
| 193 | print '<tr><td class="titlefield ' . $morecss . '">' . $langs->trans("SmsFrom"); |
||
| 194 | print '<input type="hidden" name="fromsms" value="' . $this->fromsms . '">'; |
||
| 195 | print "</td><td>"; |
||
| 196 | if ($this->fromtype == 'user') { |
||
| 197 | $langs->load("users"); |
||
| 198 | $fuser = new User($this->db); |
||
| 199 | $fuser->fetch($this->fromid); |
||
| 200 | print $fuser->getNomUrl(1); |
||
| 201 | print ' '; |
||
| 202 | } |
||
| 203 | if ($this->fromsms) { |
||
| 204 | print $this->fromsms; |
||
| 205 | } else { |
||
| 206 | if ($this->fromtype) { |
||
| 207 | $langs->load("errors"); |
||
| 208 | print '<span class="warning"> <' . $langs->trans("ErrorNoPhoneDefinedForThisUser") . '> </span>'; |
||
| 209 | } |
||
| 210 | } |
||
| 211 | print "</td></tr>\n"; |
||
| 212 | print "</td></tr>\n"; |
||
| 213 | } else { |
||
| 214 | print '<tr><td class="' . $morecss . '">' . $langs->trans("SmsFrom") . "</td><td>"; |
||
| 215 | if (getDolGlobalString('MAIN_SMS_SENDMODE')) { |
||
| 216 | $sendmode = getDolGlobalString('MAIN_SMS_SENDMODE'); // $conf->global->MAIN_SMS_SENDMODE looks like a value 'module' |
||
| 217 | $classmoduleofsender = getDolGlobalString('MAIN_MODULE_' . strtoupper($sendmode) . '_SMS', $sendmode); // $conf->global->MAIN_MODULE_XXX_SMS looks like a value 'class@module' |
||
| 218 | if ($classmoduleofsender == 'ovh') { |
||
| 219 | $classmoduleofsender = 'ovhsms@ovh'; // For backward compatibility |
||
| 220 | } |
||
| 221 | |||
| 222 | $tmp = explode('@', $classmoduleofsender); |
||
| 223 | $classfile = $tmp[0]; |
||
| 224 | $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]); |
||
| 225 | dol_include_once('/' . $module . '/class/' . $classfile . '.class.php'); |
||
| 226 | try { |
||
| 227 | $classname = ucfirst($classfile); |
||
| 228 | if (class_exists($classname)) { |
||
| 229 | $sms = new $classname($this->db); |
||
| 230 | $resultsender = $sms->SmsSenderList(); |
||
| 231 | } else { |
||
| 232 | $sms = new stdClass(); |
||
| 233 | $sms->error = 'The SMS manager "' . $classfile . '" defined into SMS setup MAIN_MODULE_' . strtoupper($sendmode) . '_SMS is not found'; |
||
| 234 | } |
||
| 235 | } catch (Exception $e) { |
||
| 236 | dol_print_error(null, 'Error to get list of senders: ' . $e->getMessage()); |
||
| 237 | exit; |
||
| 238 | } |
||
| 239 | } else { |
||
| 240 | dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING); |
||
| 241 | $resultsender = array(); |
||
| 242 | $resultsender[0]->number = $this->fromsms; |
||
| 243 | } |
||
| 244 | |||
| 245 | if (is_array($resultsender) && count($resultsender) > 0) { |
||
| 246 | print '<select name="fromsms" id="fromsms" class="flat">'; |
||
| 247 | foreach ($resultsender as $obj) { |
||
| 248 | print '<option value="' . $obj->number . '">' . $obj->number . '</option>'; |
||
| 249 | } |
||
| 250 | print '</select>'; |
||
| 251 | } else { |
||
| 252 | print '<span class="error wordbreak">' . $langs->trans("SmsNoPossibleSenderFound"); |
||
| 253 | if (is_object($sms) && !empty($sms->error)) { |
||
| 254 | print ' ' . $sms->error; |
||
| 255 | } |
||
| 256 | print '</span>'; |
||
| 257 | } |
||
| 258 | print '</td>'; |
||
| 259 | print "</tr>\n"; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | |||
| 263 | // To (target) |
||
| 264 | if ($this->withto || is_array($this->withto)) { |
||
| 265 | print '<tr><td>'; |
||
| 266 | //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"); |
||
| 267 | $moretext = ''; |
||
| 268 | print $form->textwithpicto($langs->trans("SmsTo"), $moretext); |
||
| 269 | print '</td><td>'; |
||
| 270 | if ($this->withtoreadonly) { |
||
| 271 | print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : ""; |
||
| 272 | } else { |
||
| 273 | print '<input class="width150" id="sendto" name="sendto" value="' . dol_escape_htmltag(!is_array($this->withto) && $this->withto != '1' ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "+") . '">'; |
||
| 274 | if (!empty($this->withtosocid) && $this->withtosocid > 0) { |
||
| 275 | $liste = array(); |
||
| 276 | foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value) { |
||
| 277 | $liste[$key] = $value; |
||
| 278 | } |
||
| 279 | print " " . $langs->trans("or") . " "; |
||
| 280 | //var_dump($_REQUEST);exit; |
||
| 281 | print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1); |
||
| 282 | } |
||
| 283 | print '<span class="opacitymedium hideonsmartphone"> ' . $langs->trans("SmsInfoNumero") . '</span>'; |
||
| 284 | } |
||
| 285 | print "</td></tr>\n"; |
||
| 286 | } |
||
| 287 | |||
| 288 | // Message |
||
| 289 | if ($this->withbody) { |
||
| 290 | $defaultmessage = ''; |
||
| 291 | if ($this->param["models"] == 'body') { |
||
| 292 | $defaultmessage = $this->withbody; |
||
| 293 | } |
||
| 294 | $defaultmessage = make_substitutions($defaultmessage, $this->substit); |
||
| 295 | if (GETPOSTISSET("message")) { |
||
| 296 | $defaultmessage = GETPOST("message", 'restricthtml'); |
||
| 297 | } |
||
| 298 | $defaultmessage = str_replace('\n', "\n", $defaultmessage); |
||
| 299 | |||
| 300 | print "<tr>"; |
||
| 301 | print '<td class="tdtop">' . $langs->trans("SmsText") . "</td>"; |
||
| 302 | print "<td>"; |
||
| 303 | if ($this->withbodyreadonly) { |
||
| 304 | print nl2br($defaultmessage); |
||
| 305 | print '<input type="hidden" name="message" value="' . dol_escape_htmltag($defaultmessage) . '">'; |
||
| 306 | } else { |
||
| 307 | print '<textarea class="quatrevingtpercent" name="message" id="message" rows="' . ROWS_4 . '" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">' . $defaultmessage . '</textarea>'; |
||
| 308 | print '<div id="charlimitinfo" class="opacitymedium">' . $langs->trans("SmsInfoCharRemain") . ': <span id="charlimitinfospan">' . (160 - dol_strlen($defaultmessage)) . '</span></div></td>'; |
||
| 309 | } |
||
| 310 | print "</td></tr>\n"; |
||
| 311 | } |
||
| 312 | |||
| 313 | print ' |
||
| 314 | <tr> |
||
| 315 | <td>' . $langs->trans("DelayBeforeSending") . ':</td> |
||
| 316 | <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr> |
||
| 317 | |||
| 318 | <tr><td>' . $langs->trans("Priority") . ' :</td><td> |
||
| 319 | <select name="priority" id="priority" class="flat"> |
||
| 320 | <option value="0">high</option> |
||
| 321 | <option value="1">medium</option> |
||
| 322 | <option value="2" selected>low</option> |
||
| 323 | <option value="3">veryLow</option> |
||
| 324 | </select></td></tr> |
||
| 325 | |||
| 326 | <tr><td>' . $langs->trans("Type") . ' :</td><td> |
||
| 327 | <select name="class" id="class" class="flat"> |
||
| 328 | <option value="0">Flash</option> |
||
| 329 | <option value="1" selected>Standard</option> |
||
| 330 | <option value="2">SIM</option> |
||
| 331 | <option value="3">ToolKit</option> |
||
| 332 | </select></td></tr> |
||
| 333 | |||
| 334 | <tr><td>' . $langs->trans("DisableStopIfSupported") . ' :</td><td> |
||
| 335 | <select name="disablestop" id="disablestop" class="flat"> |
||
| 336 | <option value="0" selected>No</option> |
||
| 337 | <option value="1" selected>Yes</option> |
||
| 338 | </select></td></tr>'; |
||
| 339 | |||
| 340 | print "</table>\n"; |
||
| 341 | |||
| 342 | |||
| 343 | if ($showform) { |
||
| 344 | print '<div class="center">'; |
||
| 345 | print '<input type="submit" class="button" name="sendmail" value="' . dol_escape_htmltag($langs->trans("SendSms")) . '">'; |
||
| 346 | if ($this->withcancel) { |
||
| 347 | print ' '; |
||
| 348 | print '<input class="button button-cancel" type="submit" name="cancel" value="' . dol_escape_htmltag($langs->trans("Cancel")) . '">'; |
||
| 349 | } |
||
| 350 | print '</div>'; |
||
| 351 | |||
| 352 | print "</form>\n"; |
||
| 353 | } |
||
| 354 | |||
| 355 | print "<!-- End form SMS -->\n"; |
||
| 356 | } |
||
| 358 |