html.formsms.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/class/html.formsms.class.php
  20. * \ingroup core
  21. * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire
  22. */
  23. require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
  24. /**
  25. * Classe permettant la generation du formulaire d'envoi de Sms
  26. * Usage: $formsms = new FormSms($db)
  27. * $formsms->proprietes=1 ou chaine ou tableau de valeurs
  28. * $formsms->show_form() affiche le formulaire
  29. */
  30. class FormSms
  31. {
  32. var $db;
  33. var $fromname;
  34. var $fromsms;
  35. var $replytoname;
  36. var $replytomail;
  37. var $toname;
  38. var $tomail;
  39. var $withsubstit; // Show substitution array
  40. var $withfrom;
  41. var $withto;
  42. var $withtopic;
  43. var $withbody;
  44. var $withfromreadonly;
  45. var $withreplytoreadonly;
  46. var $withtoreadonly;
  47. var $withtopicreadonly;
  48. var $withcancel;
  49. var $substit=array();
  50. var $param=array();
  51. var $error;
  52. /**
  53. * Constructor
  54. *
  55. * @param DoliDB $db Database handler
  56. */
  57. function __construct($db)
  58. {
  59. $this->db = $db;
  60. $this->withfrom=1;
  61. $this->withto=1;
  62. $this->withtopic=1;
  63. $this->withbody=1;
  64. $this->withfromreadonly=1;
  65. $this->withreplytoreadonly=1;
  66. $this->withtoreadonly=0;
  67. $this->withtopicreadonly=0;
  68. $this->withbodyreadonly=0;
  69. return 1;
  70. }
  71. /**
  72. * Show the form to input an sms.
  73. *
  74. * @param string $morecss Class on first column td
  75. * @param int $showform Show form tags and submit button (recommanded is to use with value 0)
  76. * @return void
  77. */
  78. function show_form($morecss='titlefield', $showform=1)
  79. {
  80. global $conf, $langs, $user, $form;
  81. if (! is_object($form)) $form=new Form($this->db);
  82. $langs->load("other");
  83. $langs->load("mails");
  84. $langs->load("sms");
  85. $soc=new Societe($this->db);
  86. if (!empty($this->withtosocid) && $this->withtosocid > 0)
  87. {
  88. $soc->fetch($this->withtosocid);
  89. }
  90. print "\n<!-- Begin form SMS -->\n";
  91. print '
  92. <script language="javascript">
  93. function limitChars(textarea, limit, infodiv)
  94. {
  95. var text = textarea.value;
  96. var textlength = text.length;
  97. var info = document.getElementById(infodiv);
  98. info.innerHTML = (limit - textlength);
  99. return true;
  100. }
  101. </script>';
  102. if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
  103. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  104. foreach ($this->param as $key=>$value)
  105. {
  106. print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
  107. }
  108. print "<table class=\"border centpercent\">\n";
  109. // Substitution array
  110. if ($this->withsubstit)
  111. {
  112. print "<tr><td colspan=\"2\">";
  113. $help="";
  114. foreach($this->substit as $key => $val)
  115. {
  116. $help.=$key.' -> '.$langs->trans($val).'<br>';
  117. }
  118. print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help);
  119. print "</td></tr>\n";
  120. }
  121. // From
  122. if ($this->withfrom)
  123. {
  124. if ($this->withfromreadonly)
  125. {
  126. print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom");
  127. print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
  128. print "</td><td>";
  129. if ($this->fromtype == 'user')
  130. {
  131. $langs->load("users");
  132. $fuser=new User($this->db);
  133. $fuser->fetch($this->fromid);
  134. print $fuser->getNomUrl(1);
  135. print ' &nbsp; ';
  136. }
  137. if ($this->fromsms)
  138. {
  139. print $this->fromsms;
  140. }
  141. else
  142. {
  143. if ($this->fromtype)
  144. {
  145. $langs->load("errors");
  146. print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
  147. }
  148. }
  149. print "</td></tr>\n";
  150. print "</td></tr>\n";
  151. }
  152. else
  153. {
  154. print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
  155. //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
  156. if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated
  157. {
  158. dol_include_once('/ovh/class/ovhsms.class.php');
  159. try
  160. {
  161. $sms = new OvhSms($this->db);
  162. if (empty($conf->global->OVHSMS_ACCOUNT))
  163. {
  164. $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
  165. }
  166. else
  167. {
  168. $resultsender = $sms->SmsSenderList();
  169. }
  170. }
  171. catch(Exception $e)
  172. {
  173. dol_print_error('','Error to get list of senders: '.$e->getMessage());
  174. }
  175. }
  176. else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
  177. {
  178. $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
  179. $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
  180. dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
  181. try
  182. {
  183. $classname=ucfirst($classfile);
  184. $sms = new $classname($this->db);
  185. $resultsender = $sms->SmsSenderList();
  186. }
  187. catch(Exception $e)
  188. {
  189. dol_print_error('','Error to get list of senders: '.$e->getMessage());
  190. exit;
  191. }
  192. }
  193. else
  194. {
  195. dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
  196. $resultsender=array();
  197. $resultsender[0]->number=$this->fromsms;
  198. }
  199. if (is_array($resultsender) && count($resultsender) > 0)
  200. {
  201. print '<select name="fromsms" id="valid" class="flat">';
  202. foreach($resultsender as $obj)
  203. {
  204. print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
  205. }
  206. print '</select>';
  207. }
  208. else
  209. {
  210. print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
  211. if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
  212. print '</span>';
  213. }
  214. print '</td>';
  215. print "</tr>\n";
  216. }
  217. }
  218. // To (target)
  219. if ($this->withto || is_array($this->withto))
  220. {
  221. print '<tr><td width="180">';
  222. //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
  223. $moretext='';
  224. print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
  225. print '</td><td>';
  226. if ($this->withtoreadonly)
  227. {
  228. print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
  229. }
  230. else
  231. {
  232. print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">";
  233. if (! empty($this->withtosocid) && $this->withtosocid > 0)
  234. {
  235. $liste=array();
  236. foreach ($soc->thirdparty_and_contact_phone_array() as $key=>$value)
  237. {
  238. $liste[$key]=$value;
  239. }
  240. print " ".$langs->trans("or")." ";
  241. //var_dump($_REQUEST);exit;
  242. print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
  243. }
  244. print ' '.$langs->trans("SmsInfoNumero");
  245. }
  246. print "</td></tr>\n";
  247. }
  248. // Message
  249. if ($this->withbody)
  250. {
  251. $defaultmessage='';
  252. if ($this->param["models"]=='body')
  253. {
  254. $defaultmessage=$this->withbody;
  255. }
  256. $defaultmessage=make_substitutions($defaultmessage,$this->substit);
  257. if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
  258. $defaultmessage=str_replace('\n',"\n",$defaultmessage);
  259. print "<tr>";
  260. print "<td width=\"180\" valign=\"top\">".$langs->trans("SmsText")."</td>";
  261. print "<td>";
  262. if ($this->withbodyreadonly)
  263. {
  264. print nl2br($defaultmessage);
  265. print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
  266. }
  267. else
  268. {
  269. print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
  270. print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
  271. }
  272. print "</td></tr>\n";
  273. }
  274. print '
  275. <tr>
  276. <td>'.$langs->trans("DelayBeforeSending").':</td>
  277. <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
  278. <tr><td>'.$langs->trans("Priority").' :</td><td>
  279. <select name="priority" id="valid" class="flat">
  280. <option value="0">high</option>
  281. <option value="1">medium</option>
  282. <option value="2" selected>low</option>
  283. <option value="3">veryLow</option>
  284. </select></td></tr>
  285. <tr><td>'.$langs->trans("Type").' :</td><td>
  286. <select name="class" id="valid" class="flat">
  287. <option value="0">Flash</option>
  288. <option value="1" selected>Standard</option>
  289. <option value="2">SIM</option>
  290. <option value="3">ToolKit</option>
  291. </select></td></tr>';
  292. print "</table>\n";
  293. if ($showform)
  294. {
  295. print '<div class="center">';
  296. print '<input class="button" type="submit" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
  297. if ($this->withcancel)
  298. {
  299. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  300. print '<input class="button" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  301. }
  302. print '</div>';
  303. print "</form>\n";
  304. }
  305. print "<!-- End form SMS -->\n";
  306. }
  307. }