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

Language PHP Lines 338
MD5 Hash 5d0beb5c3ae96f37b6afda4a54dce485 Estimated Cost $7,205 (why?)
Repository https://github.com/asterix14/dolibarr.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?PHP
/* Copyright (C) 2005-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
 * Copyright (C) 2010      Juanjo Menent        <jmenent@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
 *       \file       htdocs/core/class/html.formmail.class.php
 *       \ingroup    core
 *       \brief      Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire
 */
require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php");


/**     \class      FormSms
 *      \brief      Classe permettant la generation du formulaire d'envoi de Sms
 *      \remarks    Utilisation: $formsms = new FormSms($db)
 *      \remarks                 $formsms->proprietes=1 ou chaine ou tableau de valeurs
 *      \remarks                 $formsms->show_form() affiche le formulaire
 */
class FormSms
{
    var $db;

    var $fromname;
    var $fromsms;
    var $replytoname;
    var $replytomail;
    var $toname;
    var $tomail;

    var $withsubstit;			// Show substitution array
    var $withfrom;
    var $withto;
    var $withtopic;
    var $withbody;

    var $withfromreadonly;
    var $withreplytoreadonly;
    var $withtoreadonly;
    var $withtopicreadonly;
    var $withcancel;

    var $substit=array();
    var $param=array();

    var $error;


    /**
     *	Constructor
     *
     *  @param		DoliDB		$DB      Database handler
     */
    function FormSms($DB)
    {
        $this->db = $DB;

        $this->withfrom=1;
        $this->withto=1;
        $this->withtopic=1;
        $this->withbody=1;

        $this->withfromreadonly=1;
        $this->withreplytoreadonly=1;
        $this->withtoreadonly=0;
        $this->withtopicreadonly=0;
        $this->withbodyreadonly=0;

        return 1;
    }

    /**
     *	Show the form to input an sms
     *
     *	@param	string	$width	Width of form
     *	@return	void
     */
    function show_form($width='180px')
    {
        global $conf, $langs, $user;

        $langs->load("other");
        $langs->load("mails");
        $langs->load("sms");

        $form=new Form($this->db);
        $soc=new Societe($this->db);
        if (!empty($this->withtosocid) && $this->withtosocid > 0)
        {
            $soc->fetch($this->withtosocid);
        }

        print "\n<!-- Begin form SMS -->\n";

        print '
<script language="javascript">
function limitChars(textarea, limit, infodiv)
{
    var text = textarea.value;
    var textlength = text.length;
    var info = document.getElementById(infodiv);

    info.innerHTML = (limit - textlength);
    return true;
}
</script>';

        print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
        foreach ($this->param as $key=>$value)
        {
            print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
        }
        print "<table class=\"border\" width=\"100%\">\n";

        // Substitution array
        if ($this->withsubstit)
        {
            print "<tr><td colspan=\"2\">";
            $help="";
            foreach($this->substit as $key => $val)
            {
                $help.=$key.' -> '.$langs->trans($val).'<br>';
            }
            print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help);
            print "</td></tr>\n";
        }

        // From
        if ($this->withfrom)
        {
            if ($this->withfromreadonly)
            {
                print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
                print "<tr><td width=\"".$width."\">".$langs->trans("SmsFrom")."</td><td>";
                if ($this->fromtype == 'user')
                {
                    $langs->load("users");
                    $fuser=new User($this->db);
                    $fuser->fetch($this->fromid);
                    print $fuser->getNomUrl(1);
                    print ' &nbsp; ';
                }
                if ($this->fromsms)
                {
                    print $this->fromsms;
                }
                else
                {
                    if ($this->fromtype)
                    {
                        $langs->load("errors");
                        print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
                    }
                }
                print "</td></tr>\n";
                print "</td></tr>\n";
            }
            else
            {
                print "<tr><td width=\"".$width."\">".$langs->trans("SmsFrom")."</td><td>";
                //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')        // For backward compatibility        @deprecated
                {
                    dol_include_once('/ovh/class/ovhsms.class.php');
                    try
                    {
                        $sms = new OvhSms($this->db);
                        if (empty($conf->global->OVHSMS_ACCOUNT))
                        {
                            $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
                        }
                        else
                        {
                            $resultsender = $sms->SmsSenderList();
                        }
                    }
                    catch(Exception $e)
                    {
                        dol_print_error('','Error to get list of senders: '.$e->getMessage());
                    }
                }
                else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
                {
                    $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
                    $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
                    dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
                    try
                    {
                        $classname=ucfirst($classfile);
                        $sms = new $classname($this->db);
                        $resultsender = $sms->SmsSenderList();
                    }
                    catch(Exception $e)
                    {
                        dol_print_error('','Error to get list of senders: '.$e->getMessage());
                        exit;
                    }
                }
                else
                {
                    dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
                    $resultsender[0]->number=$this->fromsms;
                }

                if (is_array($resultsender) && count($resultsender) > 0)
                {
                    print '<select name="fromsms" id="valid" class="flat">';
                    foreach($resultsender as $obj)
                    {
                        print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
                    }
                    print '</select>';
                }
                else
                {
                    print '<span class="error">'.$langs->trans("SmsNoPossibleRecipientFound");
                    if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
                    print '</span>';
                }
                print '</td>';
                print "</tr>\n";
            }
        }

        // To
        if ($this->withto || is_array($this->withto))
        {
            print '<tr><td width="180">';
            //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
            $moretext='';
            print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
            print '</td><td>';
            if ($this->withtoreadonly)
            {
                print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
            }
            else
            {
                print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto):"+")."\">";
                if (! empty($this->withtosocid) && $this->withtosocid > 0)
                {
                    $liste=array();
                    foreach ($soc->thirdparty_and_contact_phone_array() as $key=>$value)
                    {
                        $liste[$key]=$value;
                    }
                    print " ".$langs->trans("or")." ";
                    //var_dump($_REQUEST);exit;
                    print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
                }
                print ' '.$langs->trans("SmsInfoNumero");
            }
            print "</td></tr>\n";
        }

        // Message
        if ($this->withbody)
        {
            $defaultmessage='';
            if ($this->param["models"]=='body')
            {
                $defaultmessage=$this->withbody;
            }
            $defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs);
            if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
            $defaultmessage=str_replace('\n',"\n",$defaultmessage);

            print "<tr>";
            print "<td width=\"180\" valign=\"top\">".$langs->trans("SmsText")."</td>";
            print "<td>";
            if ($this->withbodyreadonly)
            {
                print nl2br($defaultmessage);
                print '<input type="hidden" name="message" value="'.$defaultmessage.'">';
            }
            else
            {
                print '<textarea cols="40" name="message" id="message" rows="4" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
                print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
            }
            print "</td></tr>\n";
        }

        print '
           <tr>
            <td>'.$langs->trans("DelayBeforeSending").':</td>
            <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>

           <tr><td>'.$langs->trans("Priority").' :</td><td>
           <select name="priority" id="valid" class="flat">
           <option value="0">0</option>
           <option value="1">1</option>
           <option value="2">2</option>
           <option value="3" selected="selected">3</option>
           </select></td></tr>

           <tr><td>'.$langs->trans("Type").' :</td><td>
           <select name="class" id="valid" class="flat">
           <option value="0">Flash</option>
           <option value="1" selected="selected">Standard</option>
           <option value="2">SIM</option>
           <option value="3">ToolKit</option>
           </select></td></tr>';

        print "</table>\n";

        print '<center>';
        print "<input class=\"button\" type=\"submit\" name=\"sendmail\" value=\"".$langs->trans("SendSms")."\"";
        print ">";
        if ($this->withcancel)
        {
            print " &nbsp; &nbsp; ";
            print "<input class=\"button\" type=\"submit\" name=\"cancel\" value=\"".$langs->trans("Cancel")."\">";
        }
        print "</center>\n";

        print "</form>\n";
        print "<!-- End form SMS -->\n";
    }

}

?>
Back to Top