PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/class/html.formsms.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 337 lines | 261 code | 31 blank | 45 comment | 29 complexity | dec3e6186662771ce596f0c6515c60e8 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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.formmail.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 $width Width of form
  75. * @return void
  76. */
  77. function show_form($width='180px')
  78. {
  79. global $conf, $langs, $user;
  80. $langs->load("other");
  81. $langs->load("mails");
  82. $langs->load("sms");
  83. $form=new Form($this->db);
  84. $soc=new Societe($this->db);
  85. if (!empty($this->withtosocid) && $this->withtosocid > 0)
  86. {
  87. $soc->fetch($this->withtosocid);
  88. }
  89. print "\n<!-- Begin form SMS -->\n";
  90. print '
  91. <script language="javascript">
  92. function limitChars(textarea, limit, infodiv)
  93. {
  94. var text = textarea.value;
  95. var textlength = text.length;
  96. var info = document.getElementById(infodiv);
  97. info.innerHTML = (limit - textlength);
  98. return true;
  99. }
  100. </script>';
  101. print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
  102. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  103. foreach ($this->param as $key=>$value)
  104. {
  105. print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
  106. }
  107. print "<table class=\"border\" width=\"100%\">\n";
  108. // Substitution array
  109. if ($this->withsubstit)
  110. {
  111. print "<tr><td colspan=\"2\">";
  112. $help="";
  113. foreach($this->substit as $key => $val)
  114. {
  115. $help.=$key.' -> '.$langs->trans($val).'<br>';
  116. }
  117. print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help);
  118. print "</td></tr>\n";
  119. }
  120. // From
  121. if ($this->withfrom)
  122. {
  123. if ($this->withfromreadonly)
  124. {
  125. print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
  126. print "<tr><td width=\"".$width."\">".$langs->trans("SmsFrom")."</td><td>";
  127. if ($this->fromtype == 'user')
  128. {
  129. $langs->load("users");
  130. $fuser=new User($this->db);
  131. $fuser->fetch($this->fromid);
  132. print $fuser->getNomUrl(1);
  133. print ' &nbsp; ';
  134. }
  135. if ($this->fromsms)
  136. {
  137. print $this->fromsms;
  138. }
  139. else
  140. {
  141. if ($this->fromtype)
  142. {
  143. $langs->load("errors");
  144. print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
  145. }
  146. }
  147. print "</td></tr>\n";
  148. print "</td></tr>\n";
  149. }
  150. else
  151. {
  152. print "<tr><td width=\"".$width."\">".$langs->trans("SmsFrom")."</td><td>";
  153. //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
  154. if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated
  155. {
  156. dol_include_once('/ovh/class/ovhsms.class.php');
  157. try
  158. {
  159. $sms = new OvhSms($this->db);
  160. if (empty($conf->global->OVHSMS_ACCOUNT))
  161. {
  162. $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
  163. }
  164. else
  165. {
  166. $resultsender = $sms->SmsSenderList();
  167. }
  168. }
  169. catch(Exception $e)
  170. {
  171. dol_print_error('','Error to get list of senders: '.$e->getMessage());
  172. }
  173. }
  174. else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
  175. {
  176. $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
  177. $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
  178. dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
  179. try
  180. {
  181. $classname=ucfirst($classfile);
  182. $sms = new $classname($this->db);
  183. $resultsender = $sms->SmsSenderList();
  184. }
  185. catch(Exception $e)
  186. {
  187. dol_print_error('','Error to get list of senders: '.$e->getMessage());
  188. exit;
  189. }
  190. }
  191. else
  192. {
  193. dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
  194. $resultsender[0]->number=$this->fromsms;
  195. }
  196. if (is_array($resultsender) && count($resultsender) > 0)
  197. {
  198. print '<select name="fromsms" id="valid" class="flat">';
  199. foreach($resultsender as $obj)
  200. {
  201. print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
  202. }
  203. print '</select>';
  204. }
  205. else
  206. {
  207. print '<span class="error">'.$langs->trans("SmsNoPossibleRecipientFound");
  208. if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
  209. print '</span>';
  210. }
  211. print '</td>';
  212. print "</tr>\n";
  213. }
  214. }
  215. // To
  216. if ($this->withto || is_array($this->withto))
  217. {
  218. print '<tr><td width="180">';
  219. //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
  220. $moretext='';
  221. print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
  222. print '</td><td>';
  223. if ($this->withtoreadonly)
  224. {
  225. print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
  226. }
  227. else
  228. {
  229. print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto):"+")."\">";
  230. if (! empty($this->withtosocid) && $this->withtosocid > 0)
  231. {
  232. $liste=array();
  233. foreach ($soc->thirdparty_and_contact_phone_array() as $key=>$value)
  234. {
  235. $liste[$key]=$value;
  236. }
  237. print " ".$langs->trans("or")." ";
  238. //var_dump($_REQUEST);exit;
  239. print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
  240. }
  241. print ' '.$langs->trans("SmsInfoNumero");
  242. }
  243. print "</td></tr>\n";
  244. }
  245. // Message
  246. if ($this->withbody)
  247. {
  248. $defaultmessage='';
  249. if ($this->param["models"]=='body')
  250. {
  251. $defaultmessage=$this->withbody;
  252. }
  253. $defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs);
  254. if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
  255. $defaultmessage=str_replace('\n',"\n",$defaultmessage);
  256. print "<tr>";
  257. print "<td width=\"180\" valign=\"top\">".$langs->trans("SmsText")."</td>";
  258. print "<td>";
  259. if ($this->withbodyreadonly)
  260. {
  261. print nl2br($defaultmessage);
  262. print '<input type="hidden" name="message" value="'.$defaultmessage.'">';
  263. }
  264. else
  265. {
  266. print '<textarea cols="40" name="message" id="message" rows="4" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
  267. print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
  268. }
  269. print "</td></tr>\n";
  270. }
  271. print '
  272. <tr>
  273. <td>'.$langs->trans("DelayBeforeSending").':</td>
  274. <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
  275. <tr><td>'.$langs->trans("Priority").' :</td><td>
  276. <select name="priority" id="valid" class="flat">
  277. <option value="0">0</option>
  278. <option value="1">1</option>
  279. <option value="2">2</option>
  280. <option value="3" selected="selected">3</option>
  281. </select></td></tr>
  282. <tr><td>'.$langs->trans("Type").' :</td><td>
  283. <select name="class" id="valid" class="flat">
  284. <option value="0">Flash</option>
  285. <option value="1" selected="selected">Standard</option>
  286. <option value="2">SIM</option>
  287. <option value="3">ToolKit</option>
  288. </select></td></tr>';
  289. print "</table>\n";
  290. print '<center>';
  291. print "<input class=\"button\" type=\"submit\" name=\"sendmail\" value=\"".$langs->trans("SendSms")."\"";
  292. print ">";
  293. if ($this->withcancel)
  294. {
  295. print " &nbsp; &nbsp; ";
  296. print "<input class=\"button\" type=\"submit\" name=\"cancel\" value=\"".$langs->trans("Cancel")."\">";
  297. }
  298. print "</center>\n";
  299. print "</form>\n";
  300. print "<!-- End form SMS -->\n";
  301. }
  302. }
  303. ?>