PageRenderTime 145ms CodeModel.GetById 60ms app.highlight 13ms RepoModel.GetById 67ms app.codeStats 0ms

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

https://github.com/asterix14/dolibarr
PHP | 337 lines | 261 code | 31 blank | 45 comment | 29 complexity | 5d0beb5c3ae96f37b6afda4a54dce485 MD5 | raw file
  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 2 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/**
 20 *       \file       htdocs/core/class/html.formmail.class.php
 21 *       \ingroup    core
 22 *       \brief      Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire
 23 */
 24require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php");
 25
 26
 27/**     \class      FormSms
 28 *      \brief      Classe permettant la generation du formulaire d'envoi de Sms
 29 *      \remarks    Utilisation: $formsms = new FormSms($db)
 30 *      \remarks                 $formsms->proprietes=1 ou chaine ou tableau de valeurs
 31 *      \remarks                 $formsms->show_form() affiche le formulaire
 32 */
 33class FormSms
 34{
 35    var $db;
 36
 37    var $fromname;
 38    var $fromsms;
 39    var $replytoname;
 40    var $replytomail;
 41    var $toname;
 42    var $tomail;
 43
 44    var $withsubstit;			// Show substitution array
 45    var $withfrom;
 46    var $withto;
 47    var $withtopic;
 48    var $withbody;
 49
 50    var $withfromreadonly;
 51    var $withreplytoreadonly;
 52    var $withtoreadonly;
 53    var $withtopicreadonly;
 54    var $withcancel;
 55
 56    var $substit=array();
 57    var $param=array();
 58
 59    var $error;
 60
 61
 62    /**
 63     *	Constructor
 64     *
 65     *  @param		DoliDB		$DB      Database handler
 66     */
 67    function FormSms($DB)
 68    {
 69        $this->db = $DB;
 70
 71        $this->withfrom=1;
 72        $this->withto=1;
 73        $this->withtopic=1;
 74        $this->withbody=1;
 75
 76        $this->withfromreadonly=1;
 77        $this->withreplytoreadonly=1;
 78        $this->withtoreadonly=0;
 79        $this->withtopicreadonly=0;
 80        $this->withbodyreadonly=0;
 81
 82        return 1;
 83    }
 84
 85    /**
 86     *	Show the form to input an sms
 87     *
 88     *	@param	string	$width	Width of form
 89     *	@return	void
 90     */
 91    function show_form($width='180px')
 92    {
 93        global $conf, $langs, $user;
 94
 95        $langs->load("other");
 96        $langs->load("mails");
 97        $langs->load("sms");
 98
 99        $form=new Form($this->db);
100        $soc=new Societe($this->db);
101        if (!empty($this->withtosocid) && $this->withtosocid > 0)
102        {
103            $soc->fetch($this->withtosocid);
104        }
105
106        print "\n<!-- Begin form SMS -->\n";
107
108        print '
109<script language="javascript">
110function limitChars(textarea, limit, infodiv)
111{
112    var text = textarea.value;
113    var textlength = text.length;
114    var info = document.getElementById(infodiv);
115
116    info.innerHTML = (limit - textlength);
117    return true;
118}
119</script>';
120
121        print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
122        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
123        foreach ($this->param as $key=>$value)
124        {
125            print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
126        }
127        print "<table class=\"border\" width=\"100%\">\n";
128
129        // Substitution array
130        if ($this->withsubstit)
131        {
132            print "<tr><td colspan=\"2\">";
133            $help="";
134            foreach($this->substit as $key => $val)
135            {
136                $help.=$key.' -> '.$langs->trans($val).'<br>';
137            }
138            print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help);
139            print "</td></tr>\n";
140        }
141
142        // From
143        if ($this->withfrom)
144        {
145            if ($this->withfromreadonly)
146            {
147                print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
148                print "<tr><td width=\"".$width."\">".$langs->trans("SmsFrom")."</td><td>";
149                if ($this->fromtype == 'user')
150                {
151                    $langs->load("users");
152                    $fuser=new User($this->db);
153                    $fuser->fetch($this->fromid);
154                    print $fuser->getNomUrl(1);
155                    print ' &nbsp; ';
156                }
157                if ($this->fromsms)
158                {
159                    print $this->fromsms;
160                }
161                else
162                {
163                    if ($this->fromtype)
164                    {
165                        $langs->load("errors");
166                        print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
167                    }
168                }
169                print "</td></tr>\n";
170                print "</td></tr>\n";
171            }
172            else
173            {
174                print "<tr><td width=\"".$width."\">".$langs->trans("SmsFrom")."</td><td>";
175                //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
176                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')        // For backward compatibility        @deprecated
177                {
178                    dol_include_once('/ovh/class/ovhsms.class.php');
179                    try
180                    {
181                        $sms = new OvhSms($this->db);
182                        if (empty($conf->global->OVHSMS_ACCOUNT))
183                        {
184                            $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
185                        }
186                        else
187                        {
188                            $resultsender = $sms->SmsSenderList();
189                        }
190                    }
191                    catch(Exception $e)
192                    {
193                        dol_print_error('','Error to get list of senders: '.$e->getMessage());
194                    }
195                }
196                else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
197                {
198                    $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
199                    $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
200                    dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
201                    try
202                    {
203                        $classname=ucfirst($classfile);
204                        $sms = new $classname($this->db);
205                        $resultsender = $sms->SmsSenderList();
206                    }
207                    catch(Exception $e)
208                    {
209                        dol_print_error('','Error to get list of senders: '.$e->getMessage());
210                        exit;
211                    }
212                }
213                else
214                {
215                    dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
216                    $resultsender[0]->number=$this->fromsms;
217                }
218
219                if (is_array($resultsender) && count($resultsender) > 0)
220                {
221                    print '<select name="fromsms" id="valid" class="flat">';
222                    foreach($resultsender as $obj)
223                    {
224                        print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
225                    }
226                    print '</select>';
227                }
228                else
229                {
230                    print '<span class="error">'.$langs->trans("SmsNoPossibleRecipientFound");
231                    if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
232                    print '</span>';
233                }
234                print '</td>';
235                print "</tr>\n";
236            }
237        }
238
239        // To
240        if ($this->withto || is_array($this->withto))
241        {
242            print '<tr><td width="180">';
243            //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
244            $moretext='';
245            print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
246            print '</td><td>';
247            if ($this->withtoreadonly)
248            {
249                print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
250            }
251            else
252            {
253                print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto):"+")."\">";
254                if (! empty($this->withtosocid) && $this->withtosocid > 0)
255                {
256                    $liste=array();
257                    foreach ($soc->thirdparty_and_contact_phone_array() as $key=>$value)
258                    {
259                        $liste[$key]=$value;
260                    }
261                    print " ".$langs->trans("or")." ";
262                    //var_dump($_REQUEST);exit;
263                    print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
264                }
265                print ' '.$langs->trans("SmsInfoNumero");
266            }
267            print "</td></tr>\n";
268        }
269
270        // Message
271        if ($this->withbody)
272        {
273            $defaultmessage='';
274            if ($this->param["models"]=='body')
275            {
276                $defaultmessage=$this->withbody;
277            }
278            $defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs);
279            if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
280            $defaultmessage=str_replace('\n',"\n",$defaultmessage);
281
282            print "<tr>";
283            print "<td width=\"180\" valign=\"top\">".$langs->trans("SmsText")."</td>";
284            print "<td>";
285            if ($this->withbodyreadonly)
286            {
287                print nl2br($defaultmessage);
288                print '<input type="hidden" name="message" value="'.$defaultmessage.'">';
289            }
290            else
291            {
292                print '<textarea cols="40" name="message" id="message" rows="4" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
293                print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
294            }
295            print "</td></tr>\n";
296        }
297
298        print '
299           <tr>
300            <td>'.$langs->trans("DelayBeforeSending").':</td>
301            <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
302
303           <tr><td>'.$langs->trans("Priority").' :</td><td>
304           <select name="priority" id="valid" class="flat">
305           <option value="0">0</option>
306           <option value="1">1</option>
307           <option value="2">2</option>
308           <option value="3" selected="selected">3</option>
309           </select></td></tr>
310
311           <tr><td>'.$langs->trans("Type").' :</td><td>
312           <select name="class" id="valid" class="flat">
313           <option value="0">Flash</option>
314           <option value="1" selected="selected">Standard</option>
315           <option value="2">SIM</option>
316           <option value="3">ToolKit</option>
317           </select></td></tr>';
318
319        print "</table>\n";
320
321        print '<center>';
322        print "<input class=\"button\" type=\"submit\" name=\"sendmail\" value=\"".$langs->trans("SendSms")."\"";
323        print ">";
324        if ($this->withcancel)
325        {
326            print " &nbsp; &nbsp; ";
327            print "<input class=\"button\" type=\"submit\" name=\"cancel\" value=\"".$langs->trans("Cancel")."\">";
328        }
329        print "</center>\n";
330
331        print "</form>\n";
332        print "<!-- End form SMS -->\n";
333    }
334
335}
336
337?>