Completed
Branch develop (e3d3d3)
by
unknown
23:59
created

FormOther::showColor()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 21
nc 10
nop 2
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
1
<?php
2
/* Copyright (c) 2002-2007 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2004-2012 Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2004      Benoit Mortier       <[email protected]>
5
 * Copyright (C) 2004      Sebastien Di Cintio  <[email protected]>
6
 * Copyright (C) 2004      Eric Seigne          <[email protected]>
7
 * Copyright (C) 2005-2012 Regis Houssin        <[email protected]>
8
 * Copyright (C) 2006      Andre Cianfarani     <[email protected]>
9
 * Copyright (C) 2006      Marc Barilley/Ocebo  <[email protected]>
10
 * Copyright (C) 2007      Franky Van Liedekerke <[email protected]>
11
 * Copyright (C) 2007      Patrick Raguin 		<[email protected]>
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 3 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
 */
26
27
/**
28
 *	\file       htdocs/core/class/html.formother.class.php
29
 *  \ingroup    core
30
 *	\brief      Fichier de la classe des fonctions predefinie de composants html autre
31
 */
32
33
34
/**
35
 *	Classe permettant la generation de composants html autre
36
 *	Only common components are here.
37
 */
38
class FormOther
39
{
40
    private $db;
41
    public $error;
42
43
44
    /**
45
     *	Constructor
46
     *
47
     *	@param	DoliDB		$db      Database handler
48
     */
49
    function __construct($db)
50
    {
51
        $this->db = $db;
52
53
        return 1;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
54
    }
55
56
57
    /**
58
     *    Return HTML select list of export models
59
     *
60
     *    @param    string	$selected          Id modele pre-selectionne
61
     *    @param    string	$htmlname          Nom de la zone select
62
     *    @param    string	$type              Type des modeles recherches
63
     *    @param    int		$useempty          Affiche valeur vide dans liste
64
     *    @return	void
65
     */
66
    function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
67
    {
68
        $sql = "SELECT rowid, label";
69
        $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
70
        $sql.= " WHERE type = '".$type."'";
71
        $sql.= " ORDER BY rowid";
72
        $result = $this->db->query($sql);
73
        if ($result)
74
        {
75
            print '<select class="flat minwidth200" name="'.$htmlname.'">';
76
            if ($useempty)
77
            {
78
                print '<option value="-1">&nbsp;</option>';
79
            }
80
81
            $num = $this->db->num_rows($result);
82
            $i = 0;
83
            while ($i < $num)
84
            {
85
                $obj = $this->db->fetch_object($result);
86
                if ($selected == $obj->rowid)
87
                {
88
                    print '<option value="'.$obj->rowid.'" selected>';
89
                }
90
                else
91
                {
92
                    print '<option value="'.$obj->rowid.'">';
93
                }
94
                print $obj->label;
95
                print '</option>';
96
                $i++;
97
            }
98
            print "</select>";
99
        }
100
        else {
101
            dol_print_error($this->db);
102
        }
103
    }
104
105
106
    /**
107
     *    Return list of export models
108
     *
109
     *    @param    string	$selected          Id modele pre-selectionne
110
     *    @param    string	$htmlname          Nom de la zone select
111
     *    @param    string	$type              Type des modeles recherches
112
     *    @param    int		$useempty          Affiche valeur vide dans liste
113
     *    @return	void
114
     */
115
    function select_import_model($selected='',$htmlname='importmodelid',$type='',$useempty=0)
116
    {
117
        $sql = "SELECT rowid, label";
118
        $sql.= " FROM ".MAIN_DB_PREFIX."import_model";
119
        $sql.= " WHERE type = '".$type."'";
120
        $sql.= " ORDER BY rowid";
121
        $result = $this->db->query($sql);
122
        if ($result)
123
        {
124
            print '<select class="flat" name="'.$htmlname.'">';
125
            if ($useempty)
126
            {
127
                print '<option value="-1">&nbsp;</option>';
128
            }
129
130
            $num = $this->db->num_rows($result);
131
            $i = 0;
132
            while ($i < $num)
133
            {
134
                $obj = $this->db->fetch_object($result);
135
                if ($selected == $obj->rowid)
136
                {
137
                    print '<option value="'.$obj->rowid.'" selected>';
138
                }
139
                else
140
                {
141
                    print '<option value="'.$obj->rowid.'">';
142
                }
143
                print $obj->label;
144
                print '</option>';
145
                $i++;
146
            }
147
            print "</select>";
148
        }
149
        else {
150
            dol_print_error($this->db);
151
        }
152
    }
153
154
155
    /**
156
     *    Return list of ecotaxes with label
157
     *
158
     *    @param	string	$selected   Preselected ecotaxes
159
     *    @param    string	$htmlname	Name of combo list
160
     *    @return	integer
161
     */
162
    function select_ecotaxes($selected='',$htmlname='ecotaxe_id')
163
    {
164
        global $langs;
165
166
        $sql = "SELECT e.rowid, e.code, e.libelle, e.price, e.organization,";
167
        $sql.= " c.label as country";
168
        $sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
169
        $sql.= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
170
        $sql.= " ORDER BY country, e.organization ASC, e.code ASC";
171
172
    	dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
173
        $resql=$this->db->query($sql);
174
        if ($resql)
175
        {
176
            print '<select class="flat" name="'.$htmlname.'">';
177
            $num = $this->db->num_rows($resql);
178
            $i = 0;
179
            print '<option value="-1">&nbsp;</option>'."\n";
180
            if ($num)
181
            {
182
                while ($i < $num)
183
                {
184
                    $obj = $this->db->fetch_object($resql);
185
                    if ($selected && $selected == $obj->rowid)
186
                    {
187
                        print '<option value="'.$obj->rowid.'" selected>';
188
                    }
189
                    else
190
                    {
191
                        print '<option value="'.$obj->rowid.'">';
192
                        //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
193
                    }
194
                    $selectOptionValue = $obj->code.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
195
                    print $selectOptionValue;
196
                    print '</option>';
197
                    $i++;
198
                }
199
            }
200
            print '</select>';
201
            return 0;
202
        }
203
        else
204
        {
205
            dol_print_error($this->db);
206
            return 1;
207
        }
208
    }
209
210
211
    /**
212
     *    Return list of revenue stamp for country
213
     *
214
     *    @param	string	$selected   	Value of preselected revenue stamp
215
     *    @param    string	$htmlname   	Name of combo list
216
     *    @param    string	$country_code   Country Code
217
     *    @return	string					HTML select list
218
     */
219
    function select_revenue_stamp($selected='',$htmlname='revenuestamp',$country_code='')
220
    {
221
    	global $langs;
222
223
    	$out='';
224
225
    	$sql = "SELECT r.taux";
226
    	$sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
227
    	$sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
228
    	$sql.= " AND c.code = '".$country_code."'";
229
230
    	dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
231
    	$resql=$this->db->query($sql);
232
    	if ($resql)
233
    	{
234
    		$out.='<select class="flat" name="'.$htmlname.'">';
235
    		$num = $this->db->num_rows($resql);
236
    		$i = 0;
237
    		$out.='<option value="0">&nbsp;</option>'."\n";
238
    		if ($num)
239
    		{
240
    			while ($i < $num)
241
    			{
242
    				$obj = $this->db->fetch_object($resql);
243
    				if (($selected && $selected == $obj->taux) || $num == 1)
244
    				{
245
    					$out.='<option value="'.$obj->taux.'" selected>';
246
    				}
247
    				else
248
    				{
249
    					$out.='<option value="'.$obj->taux.'">';
250
    					//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
251
    				}
252
    				$out.=$obj->taux;
253
    				$out.='</option>';
254
    				$i++;
255
    			}
256
    		}
257
    		$out.='</select>';
258
    		return $out;
259
    	}
260
    	else
261
    	{
262
    		dol_print_error($this->db);
263
    		return '';
264
    	}
265
    }
266
267
268
    /**
269
     *    Return a HTML select list to select a percent
270
     *
271
     *    @param	integer	$selected      	pourcentage pre-selectionne
272
     *    @param    string	$htmlname      	nom de la liste deroulante
273
     *    @param	int		$disabled		Disabled or not
274
     *    @param    int		$increment     	increment value
275
     *    @param    int		$start         	start value
276
     *    @param    int		$end           	end value
277
     *    @return   string					HTML select string
278
     */
279
    function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100)
280
    {
281
        $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>';
282
283
        for ($i = $start ; $i <= $end ; $i += $increment)
284
        {
285
            if ($selected == $i)
286
            {
287
                $return.= '<option value="'.$i.'" selected>';
288
            }
289
            else
290
            {
291
                $return.= '<option value="'.$i.'">';
292
            }
293
            $return.= $i.' % ';
294
            $return.= '</option>';
295
        }
296
297
        $return.= '</select>';
298
299
        return $return;
300
    }
301
302
    /**
303
     * Return select list for categories (to use in form search selectors)
304
     *
305
     * @param	int		$type			Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated.
306
     * @param   integer	$selected     	Preselected value
307
     * @param   string	$htmlname      	Name of combo list
308
     * @param	int		$nocateg		Show also an entry "Not categorized"
309
     * @param   int     $showempty      Add also an empty line
310
     * @return string		        	Html combo list code
311
     * @see	select_all_categories
312
     */
313
    function select_categories($type,$selected=0,$htmlname='search_categ',$nocateg=0,$showempty=1)
314
    {
315
        global $conf, $langs;
316
        require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
317
318
        // For backward compatibility
319
        if (is_numeric($type))
320
        {
321
            dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
322
        }
323
        
324
        // Load list of "categories"
325
        $static_categs = new Categorie($this->db);
326
        $tab_categs = $static_categs->get_full_arbo($type);
327
328
        $moreforfilter = '';
329
        $nodatarole = '';
330
        // Enhance with select2
331
        if ($conf->use_javascript_ajax)
332
        {
333
            include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
334
            $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
335
            $moreforfilter.=$comboenhancement;
336
            $nodatarole=($comboenhancement?' data-role="none"':'');
337
        }
338
339
        // Print a select with each of them
340
        $moreforfilter.='<select class="flat minwidth100" id="select_categ_'.$htmlname.'" name="'.$htmlname.'"'.$nodatarole.'>';
341
        if ($showempty) $moreforfilter.='<option value="0">&nbsp;</option>';	// Should use -1 to say nothing
342
343
        if (is_array($tab_categs))
344
        {
345
            foreach ($tab_categs as $categ)
346
            {
347
                $moreforfilter.='<option value="'.$categ['id'].'"';
348
                if ($categ['id'] == $selected) $moreforfilter.=' selected';
349
                $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
350
            }
351
        }
352
        if ($nocateg)
353
        {
354
        	$langs->load("categories");
355
        	$moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>';
356
        }
357
        $moreforfilter.='</select>';
358
359
        return $moreforfilter;
360
    }
361
362
363
    /**
364
     *  Return select list for categories (to use in form search selectors)
365
     *
366
     *  @param	string	$selected     	Preselected value
367
     *  @param  string	$htmlname      	Name of combo list (example: 'search_sale')
368
     *  @param  User	$user           Object user
369
     *  @param	int		$showstatus		0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
370
     *  @param	int		$showempty		1=show also an empty value
371
     *  @param	string	$morecss		More CSS
372
     *  @return string					Html combo list code
373
     */
374
    function select_salesrepresentatives($selected,$htmlname,$user,$showstatus=0,$showempty=1,$morecss='')
375
    {
376
        global $conf,$langs;
377
        $langs->load('users');
378
379
        $out = '';
380
        $nodatarole = '';
381
        // Enhance with select2
382
        if ($conf->use_javascript_ajax)
383
        {
384
            include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
385
386
            $comboenhancement = ajax_combobox($htmlname);
387
            if ($comboenhancement)
388
            {
389
            	$out.=$comboenhancement;
390
            	$nodatarole=($comboenhancement?' data-role="none"':'');
391
            }
392
        }
393
        // Select each sales and print them in a select input
394
        $out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$nodatarole.'>';
395
        if ($showempty) $out.='<option value="0">&nbsp;</option>';
396
397
        // Get list of users allowed to be viewed
398
        $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
399
        $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
400
        $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
401
        if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
402
        if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
403
        // Add existing sales representatives of thirdparty of external user
404
        if (empty($user->rights->user->user->lire) && $user->societe_id)
405
        {
406
            $sql_usr.=" UNION ";
407
            $sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login";
408
            $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
409
            $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
410
            $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
411
        }
412
	$sql_usr.= " ORDER BY u.statut DESC, lastname ASC";
413
        //print $sql_usr;exit;
414
415
        $resql_usr = $this->db->query($sql_usr);
416
        if ($resql_usr)
417
        {
418
            while ($obj_usr = $this->db->fetch_object($resql_usr))
419
            {
420
421
                $out.='<option value="'.$obj_usr->rowid.'"';
422
423
                if ($obj_usr->rowid == $selected) $out.=' selected';
424
425
                $out.='>';
426
                $out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname);
427
                // Complete name with more info
428
                $moreinfo=0;
429
                if (! empty($conf->global->MAIN_SHOW_LOGIN))
430
                {
431
                    $out.=($moreinfo?' - ':' (').$obj_usr->login;
432
                    $moreinfo++;
433
                }
434
                if ($showstatus >= 0)
435
                {
436
					if ($obj_usr->statut == 1 && $showstatus == 1)
437
					{
438
						$out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
439
	                	$moreinfo++;
440
					}
441
					if ($obj_usr->statut == 0)
442
					{
443
						$out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
444
                		$moreinfo++;
445
					}
446
				}
447
				$out.=($moreinfo?')':'');
448
                $out.='</option>';
449
            }
450
            $this->db->free($resql_usr);
451
        }
452
        else
453
        {
454
            dol_print_error($this->db);
455
        }
456
        $out.='</select>';
457
458
        return $out;
459
    }
460
461
    /**
462
     *	Return list of project and tasks
463
     *
464
     *	@param  int		$selectedtask   		Pre-selected task
465
     *  @param  int		$projectid				Project id
466
     * 	@param  string	$htmlname    			Name of html select
467
     * 	@param	int		$modeproject			1 to restrict on projects owned by user
468
     * 	@param	int		$modetask				1 to restrict on tasks associated to user
469
     * 	@param	int		$mode					0=Return list of tasks and their projects, 1=Return projects and tasks if exists
470
     *  @param  int		$useempty       		0=Allow empty values
471
     *  @param	int		$disablechildoftaskid	1=Disable task that are child of the provided task id
472
     *  @return	void
473
     */
474
    function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0)
475
    {
476
        global $user, $langs;
477
478
        require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
479
480
        //print $modeproject.'-'.$modetask;
481
        $task=new Task($this->db);
482
        $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode);
483
        if ($tasksarray)
484
        {
485
            print '<select class="flat" name="'.$htmlname.'">';
486
            if ($useempty) print '<option value="0">&nbsp;</option>';
487
            $j=0;
488
            $level=0;
489
            $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
490
            print '</select>';
491
        }
492
        else
493
        {
494
            print '<div class="warning">'.$langs->trans("NoProject").'</div>';
495
        }
496
    }
497
498
    /**
499
     * Write lines of a project (all lines of a project if parent = 0)
500
     *
501
     * @param 	int		$inc					Cursor counter
502
     * @param 	int		$parent					Id of parent task we want to see
503
     * @param 	array	$lines					Array of task lines
504
     * @param 	int		$level					Level
505
     * @param 	int		$selectedtask			Id selected task
506
     * @param 	int		$selectedproject		Id selected project
507
     * @param	int		$disablechildoftaskid	1=Disable task that are child of the provided task id
508
     * @return	void
509
     */
510
    private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0, $disablechildoftaskid=0)
511
    {
512
        global $langs, $user, $conf;
513
514
        $lastprojectid=0;
515
516
        $numlines=count($lines);
517
        for ($i = 0 ; $i < $numlines ; $i++)
518
        {
519
        	if ($lines[$i]->fk_parent == $parent)
520
            {
521
                $var = !$var;
0 ignored issues
show
Bug introduced by
The variable $var does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
522
523
				//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id);		// $lines[$i]->id may be empty if project has no lines
524
525
                // Break on a new project
526
                if ($parent == 0)	// We are on a task at first level
527
                {
528
                    if ($lines[$i]->fk_project != $lastprojectid)	// Break found on project
529
                    {
530
                        if ($i > 0) print '<option value="0" disabled>----------</option>';
531
                        print '<option value="'.$lines[$i]->fk_project.'_0"';
532
                        if ($selectedproject == $lines[$i]->fk_project) print ' selected';
533
                        print '>';	// Project -> Task
534
                        print $langs->trans("Project").' '.$lines[$i]->projectref;
535
                        if (empty($lines[$i]->public))
536
                        {
537
                            print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
538
                        }
539
                        else
540
                        {
541
                            print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
542
                        }
543
                        //print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
544
                        print "</option>\n";
545
546
                        $lastprojectid=$lines[$i]->fk_project;
547
                        $inc++;
548
                    }
549
                }
550
551
                $newdisablechildoftaskid=$disablechildoftaskid;
552
553
                // Print task
554
                if (isset($lines[$i]->id))		// We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
555
                {
556
                	// Check if we must disable entry
557
                	$disabled=0;
558
                	if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
559
                	{
560
               			$disabled++;
561
               			if ($lines[$i]->fk_parent == $disablechildoftaskid) $newdisablechildoftaskid=$lines[$i]->id;	// If task is child of a disabled parent, we will propagate id to disable next child too
562
                	}
563
564
                    print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
565
                    if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
566
                    if ($disabled) print ' disabled';
567
                    print '>';
568
                    print $langs->trans("Project").' '.$lines[$i]->projectref;
569
                    if (empty($lines[$i]->public))
570
                    {
571
                        print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
572
                    }
573
                    else
574
                    {
575
                        print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
576
                    }
577
                    if ($lines[$i]->id) print ' > ';
578
                    for ($k = 0 ; $k < $level ; $k++)
579
                    {
580
                        print "&nbsp;&nbsp;&nbsp;";
581
                    }
582
                    print $lines[$i]->ref.' '.$lines[$i]->label."</option>\n";
583
                    $inc++;
584
                }
585
586
                $level++;
587
                if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
588
                $level--;
589
            }
590
        }
591
    }
592
593
594
    /**
595
     *		Output a HTML thumb of color or a text if not defined.
596
     *
597
     *		@param	string		$color				String with hex (FFFFFF) or comma RGB ('255,255,255')
598
     *		@param	string		$textifnotdefined	Text to show if color not defined
599
     * 		@return	string							HTML code for color thumb
600
     *		@see selectColor
601
     */
602
    static function showColor($color, $textifnotdefined='')
603
    {
604
    	$textcolor='FFF';
605
    	if ($color)
606
    	{
607
    	    $tmp=explode(',', $color);
608
    	    if (count($tmp) > 1)   // This is a comma RGB ('255','255','255')
609
    	    {
610
    	        $r = $tmp[0];
611
    	        $g = $tmp[1];
612
    	        $b = $tmp[2];
613
    	    }
614
    	    else
615
    	    {
616
    	        $hexr=$color[0].$color[1];
617
    	        $hexg=$color[2].$color[3];
618
    	        $hexb=$color[4].$color[5];
619
            	$r = hexdec($hexr);
620
            	$g = hexdec($hexg);
621
            	$b = hexdec($hexb);
622
    	    }
623
        	$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;    // HSL algorithm
624
            if ($bright > 0.6) $textcolor='000';     	   
625
    	}
626
    	
627
    	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
628
    	$color = colorArrayToHex(colorStringToArray($color,array()),'');
629
    	
630
		if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
631
		else print $textifnotdefined;
632
    }
633
634
    /**
635
     *		Output a HTML code to select a color
636
     *
637
     *		@param	string		$set_color		Pre-selected color
638
     *		@param	string		$prefix			Name of HTML field
639
     *		@param	string		$form_name		Deprecated. Not used.
640
     * 		@param	int			$showcolorbox	1=Show color code and color box, 0=Show only color code
641
     * 		@param 	array		$arrayofcolors	Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
642
     * 		@return	void
643
     * 		@deprecated Use instead selectColor
644
     *      @see selectColor()
645
     */
646
    function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='')
647
    {
648
    	print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
649
    }
650
651
    /**
652
     *		Output a HTML code to select a color. Field will return an hexa color like '334455'.
653
     *
654
     *		@param	string		$set_color		Pre-selected color
655
     *		@param	string		$prefix			Name of HTML field
656
     *		@param	string		$form_name		Deprecated. Not used.
657
     * 		@param	int			$showcolorbox	1=Show color code and color box, 0=Show only color code
658
     * 		@param 	array		$arrayofcolors	Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
659
     * 		@param	string		$morecss		Add css style into input field
660
     * 		@return	string
661
     *		@see showColor
662
     */
663
    static function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='')
664
    {
665
	    // Deprecation warning
666
	    if ($form_name) {
667
		    dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING);
668
	    }
669
670
        global $langs,$conf;
671
672
        $out='';
673
674
        if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
675
        {
676
            $langs->load("other");
677
            if (empty($conf->dol_use_jmobile))
678
            {
679
	            $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
680
	            $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
681
	            $out.= '<script type="text/javascript">
682
	             jQuery(document).ready(function(){
683
	                $(\'#colorpicker'.$prefix.'\').jPicker( {
684
	                window: {
685
	                  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
686
	                  effects:
687
	                    {
688
	                    type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
689
	                    speed:
690
	                    {
691
	                      show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
692
	                      hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
693
	                    }
694
	                    },
695
	                  position:
696
	                    {
697
	                    x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
698
	                    y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
699
	                    },
700
	                },
701
	                images: {
702
	                    clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
703
	                    picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
704
	          		},
705
	                localization: // alter these to change the text presented by the picker (e.g. different language)
706
	                  {
707
	                    text:
708
	                    {
709
	                      title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
710
	                      newColor: \''.dol_escape_js($langs->trans("New")).'\',
711
	                      currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
712
	                      ok: \''.dol_escape_js($langs->trans("Save")).'\',
713
	                      cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
714
	                    }
715
	                  }
716
			        } ); });
717
	             </script>';
718
            }
719
            $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />';
720
        }
721
        else  // In most cases, this is not used. We used instead function with no specific list of colors
722
        {
723
            if (empty($conf->dol_use_jmobile))
724
            {
725
	        	$out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
726
	            $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
727
	            $out.= '<script type="text/javascript">
728
	             jQuery(document).ready(function(){
729
	                 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
730
	                     size: 14,
731
	                     label: \'\',
732
	                     hide: true
733
	                 });
734
	             });
735
	             </script>';
736
            }
737
            $out.= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss?' '.$morecss:'').'" name="'.$prefix.'">';
738
            //print '<option value="-1">&nbsp;</option>';
739
            foreach ($arrayofcolors as $val)
740
            {
741
                $out.= '<option value="'.$val.'"';
742
                if ($set_color == $val) $out.= ' selected';
743
                $out.= '>'.$val.'</option>';
744
            }
745
            $out.= '</select>';
746
        }
747
748
        return $out;
749
    }
750
751
    /**
752
     *	Creation d'un icone de couleur
753
     *
754
     *	@param	string	$color		Couleur de l'image
755
     *	@param	string	$module 	Nom du module
756
     *	@param	string	$name		Nom de l'image
757
     *	@param	int		$x 			Largeur de l'image en pixels
758
     *	@param	int		$y      	Hauteur de l'image en pixels
759
     *	@return	void
760
     */
761
    function CreateColorIcon($color,$module,$name,$x='12',$y='12')
762
    {
763
        global $conf;
764
765
        $file = $conf->$module->dir_temp.'/'.$name.'.png';
766
767
        // On cree le repertoire contenant les icones
768
        if (! file_exists($conf->$module->dir_temp))
769
        {
770
            dol_mkdir($conf->$module->dir_temp);
771
        }
772
773
        // On cree l'image en vraies couleurs
774
        $image = imagecreatetruecolor($x,$y);
775
776
        $color = substr($color,1,6);
777
778
        $rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
779
        $vert  = hexdec(substr($color,2,2)); //conversion du canal vert
780
        $bleu  = hexdec(substr($color,4,2)); //conversion du canal bleu
781
782
        $couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
783
        //print $rouge.$vert.$bleu;
784
        imagefill($image,0,0,$couleur); //on remplit l'image
785
        // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
786
        ImagePng($image,$file); //renvoie une image sous format png
787
        ImageDestroy($image);
788
    }
789
790
    /**
791
     *    	Return HTML combo list of week
792
     *
793
     *    	@param	string		$selected          Preselected value
794
     *    	@param  string		$htmlname          Nom de la zone select
795
     *    	@param  int			$useempty          Affiche valeur vide dans liste
796
     *    	@return	string
797
     */
798
    function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
799
    {
800
        global $langs;
801
802
        $week = array(	0=>$langs->trans("Day0"),
803
        1=>$langs->trans("Day1"),
804
        2=>$langs->trans("Day2"),
805
        3=>$langs->trans("Day3"),
806
        4=>$langs->trans("Day4"),
807
        5=>$langs->trans("Day5"),
808
        6=>$langs->trans("Day6"));
809
810
        $select_week = '<select class="flat" name="'.$htmlname.'">';
811
        if ($useempty)
812
        {
813
            $select_week .= '<option value="-1">&nbsp;</option>';
814
        }
815
        foreach ($week as $key => $val)
816
        {
817
            if ($selected == $key)
818
            {
819
                $select_week .= '<option value="'.$key.'" selected>';
820
            }
821
            else
822
            {
823
                $select_week .= '<option value="'.$key.'">';
824
            }
825
            $select_week .= $val;
826
            $select_week .= '</option>';
827
        }
828
        $select_week .= '</select>';
829
        return $select_week;
830
    }
831
832
    /**
833
     *      Return HTML combo list of month
834
     *
835
     *      @param  string      $selected          Preselected value
836
     *      @param  string      $htmlname          Name of HTML select object
837
     *      @param  int         $useempty          Show empty in list
838
     *      @param  int         $longlabel         Show long label
839
     *      @return string
840
     */
841
    function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0)
842
    {
843
        global $langs;
844
845
        require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
846
847
        if ($longlabel) $montharray = monthArray($langs, 0);	// Get array
848
        else $montharray = monthArray($langs, 1);
849
850
        $select_month = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
851
        if ($useempty)
852
        {
853
            $select_month .= '<option value="0">&nbsp;</option>';
854
        }
855
        foreach ($montharray as $key => $val)
856
        {
857
            if ($selected == $key)
858
            {
859
                $select_month .= '<option value="'.$key.'" selected>';
860
            }
861
            else
862
            {
863
                $select_month .= '<option value="'.$key.'">';
864
            }
865
            $select_month .= $val;
866
            $select_month .= '</option>';
867
        }
868
        $select_month .= '</select>';
869
        return $select_month;
870
    }
871
872
    /**
873
     *	Return HTML combo list of years
874
     *
875
     *  @param  string		$selected       Preselected value (''=current year, -1=none, year otherwise)
876
     *  @param  string		$htmlname       Name of HTML select object
877
     *  @param  int			$useempty       Affiche valeur vide dans liste
878
     *  @param  int			$min_year       Offset of minimum year into list (by default current year -10)
879
     *  @param  int		    $max_year		Offset of maximum year into list (by default current year + 5)
880
     *  @param	int			$offset			Offset
881
     *  @param	int			$invert			Invert
882
     *  @param	string		$option			Option
883
     *  @return	string
884
     */
885
    function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
886
    {
887
        print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option);
888
    }
889
890
    /**
891
     *	Return HTML combo list of years
892
     *
893
     *  @param  string	$selected       Preselected value (''=current year, -1=none, year otherwise)
894
     *  @param  string	$htmlname       Name of HTML select object
895
     *  @param  int	    $useempty       Affiche valeur vide dans liste
896
     *  @param  int	    $min_year		Offset of minimum year into list (by default current year -10)
897
     *  @param  int	    $max_year       Offset of maximum year into list (by default current year + 5)
898
     *  @param	int		$offset			Offset
899
     *  @param	int		$invert			Invert
900
     *  @param	string	$option			Option
901
     *  @return	string
902
     */
903
    function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
904
    {
905
        $out='';
906
907
        $currentyear = date("Y")+$offset;
908
        $max_year = $currentyear+$max_year;
909
        $min_year = $currentyear-$min_year;
910
        if(empty($selected) && empty($useempty)) $selected = $currentyear;
911
912
        $out.= '<select class="flat" placeholder="aa" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
913
        if($useempty)
914
        {
915
        	$selected_html='';
916
            if ($selected == '') $selected_html = ' selected';
917
            $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
918
        }
919
        if (! $invert)
920
        {
921
            for ($y = $max_year; $y >= $min_year; $y--)
922
            {
923
                $selected_html='';
924
                if ($selected > 0 && $y == $selected) $selected_html = ' selected';
925
                $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
926
            }
927
        }
928
        else
929
        {
930
            for ($y = $min_year; $y <= $max_year; $y++)
931
            {
932
                $selected_html='';
933
                if ($selected > 0 && $y == $selected) $selected_html = ' selected';
934
                $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
935
            }
936
        }
937
        $out.= "</select>\n";
938
939
        return $out;
940
    }
941
942
    /**
943
     * Show form to select address
944
     *
945
     * @param	int		$page        	Page
946
     * @param  	string	$selected    	Id condition pre-selectionne
947
     * @param	int		$socid			Id of third party
948
     * @param  	string	$htmlname    	Nom du formulaire select
949
     * @param	string	$origin        	Origine de l'appel pour pouvoir creer un retour
950
     * @param  	int		$originid      	Id de l'origine
951
     * @return	void
952
     */
953
    function form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='')
954
    {
955
        global $langs,$conf;
956
        global $form;
957
958
        if ($htmlname != "none")
959
        {
960
            print '<form method="post" action="'.$page.'">';
961
            print '<input type="hidden" name="action" value="setaddress">';
962
            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
963
            $form->select_address($selected, $socid, $htmlname, 1);
964
            print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
965
            $langs->load("companies");
966
            print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
967
            print '</form>';
968
        }
969
        else
970
        {
971
            if ($selected)
972
            {
973
                require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php';
974
                $address=new Address($this->db);
975
                $result=$address->fetch_address($selected);
976
                print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
977
            }
978
            else
979
            {
980
                print "&nbsp;";
981
            }
982
        }
983
    }
984
985
986
987
    /**
988
     * 	Get array with HTML tabs with boxes of a particular area including personalized choices of user.
989
     *  Class 'Form' must be known.
990
     *
991
     * 	@param	   User         $user		 Object User
992
     * 	@param	   String       $areacode    Code of area for pages (0=value for Home page)
993
     * 	@return    array                     array('selectboxlist'=>, 'boxactivated'=>, 'boxlista'=>, 'boxlistb'=>)
994
     */
995
    static function getBoxesArea($user,$areacode)
996
    {
997
        global $conf,$langs,$db;
998
999
        include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1000
1001
        $confuserzone='MAIN_BOXES_'.$areacode;
1002
1003
        // $boxactivated will be array of boxes enabled into global setup
1004
        // $boxidactivatedforuser will be array of boxes choosed by user
1005
        
1006
        $selectboxlist='';
1007
        $boxactivated=InfoBox::listBoxes($db,'activated',$areacode,(empty($user->conf->$confuserzone)?null:$user));	// Search boxes of common+user (or common only if user has no specific setup)
1008
        
1009
        $boxidactivatedforuser=array();
1010
        foreach($boxactivated as $box)
1011
        {
1012
        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id;	// We keep only boxes to show for user
1013
        }
1014
        
1015
        // Define selectboxlist
1016
        $arrayboxtoactivatelabel=array();
1017
        if (! empty($user->conf->$confuserzone))
1018
        {
1019
        	$boxorder='';
1020
        	$langs->load("boxes");	// Load label of boxes
1021
        	foreach($boxactivated as $box)
1022
        	{
1023
        		if (! empty($boxidactivatedforuser[$box->id])) continue;	// Already visible for user
1024
        		$label=$langs->transnoentitiesnoconv($box->boxlabel);
1025
        		if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1026
        		//$label = '<span class="fa fa-home fa-fw" aria-hidden="true"></span>'.$label;    KO with select2. No html rendering.
1027
        		$arrayboxtoactivatelabel[$box->id]=$label;			// We keep only boxes not shown for user, to show into combo list
1028
        	}
1029
            foreach($boxidactivatedforuser as $boxid)
1030
        	{
1031
       			if (empty($boxorder)) $boxorder.='A:';
1032
  				$boxorder.=$boxid.',';
1033
        	}
1034
1035
        	//var_dump($boxidactivatedforuser);
1036
1037
        	// Class Form must have been already loaded
1038
			$selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1039
			$selectboxlist.='<input type="hidden" name="addbox" value="addbox">';
1040
			$selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">';
1041
			$selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1042
			$selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1043
			$selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1044
            if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1045
            $selectboxlist.='</form>';
1046
            $selectboxlist.=ajax_combobox("boxcombo");
1047
        }
1048
1049
        // Javascript code for dynamic actions
1050
        if (! empty($conf->use_javascript_ajax))
1051
        {
1052
	        $selectboxlist.='<script type="text/javascript" language="javascript">
1053
1054
	        // To update list of activated boxes
1055
	        function updateBoxOrder(closing) {
1056
	        	var left_list = cleanSerialize(jQuery("#left").sortable("serialize"));
1057
	        	var right_list = cleanSerialize(jQuery("#right").sortable("serialize"));
1058
	        	var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1059
	        	if (boxorder==\'A:A-B:B\' && closing == 1)	// There is no more boxes on screen, and we are after a delete of a box so we must hide title
1060
	        	{
1061
	        		jQuery.ajax({
1062
	        			url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=0&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1063
	        			async: false
1064
	        		});
1065
	        		// We force reload to be sure to get all boxes into list
1066
	        		window.location.search=\'mainmenu='.GETPOST("mainmenu").'&leftmenu='.GETPOST('leftmenu').'&action=delbox\';
1067
	        	}
1068
	        	else
1069
	        	{
1070
	        		jQuery.ajax({
1071
	        			url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1072
	        			async: true
1073
	        		});
1074
	        	}
1075
	        }
1076
1077
	        jQuery(document).ready(function() {
1078
	        	jQuery("#boxcombo").change(function() {
1079
	        	var boxid=jQuery("#boxcombo").val();
1080
	        		if (boxid > 0) {
1081
	            		var left_list = cleanSerialize(jQuery("#left").sortable("serialize"));
1082
	            		var right_list = cleanSerialize(jQuery("#right").sortable("serialize"));
1083
	            		var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1084
	    				jQuery.ajax({
1085
	    					url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\',
1086
	    			        async: false
1087
	    		        });
1088
	        			window.location.search=\'mainmenu='.GETPOST("mainmenu").'&leftmenu='.GETPOST('leftmenu').'&action=addbox&boxid=\'+boxid;
1089
	                }
1090
	        	});';
1091
	        	if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1092
	        	$selectboxlist.='
1093
1094
	        	jQuery("#left, #right").sortable({
1095
		        	/* placeholder: \'ui-state-highlight\', */
1096
	    	    	handle: \'.boxhandle\',
1097
	    	    	revert: \'invalid\',
1098
	       			items: \'.box\',
1099
	        		containment: \'.fiche\',
1100
	        		connectWith: \'.connectedSortable\',
1101
	        		stop: function(event, ui) {
1102
	        			updateBoxOrder(1);  /* 1 to avoid message after a move */
1103
	        		}
1104
	    		});
1105
1106
	        	jQuery(".boxclose").click(function() {
1107
	        		var self = this;	// because JQuery can modify this
1108
	        		var boxid=self.id.substring(8);
1109
	        		var label=jQuery(\'#boxlabelentry\'+boxid).val();
1110
	        		jQuery(\'#boxto_\'+boxid).remove();
1111
	        		if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid));
1112
	        		updateBoxOrder(1);  /* 1 to avoid message after a remove */
1113
	        	});
1114
1115
        	});'."\n";
1116
1117
	        $selectboxlist.='</script>'."\n";
1118
        }
1119
1120
        // Define boxlista and boxlistb
1121
        $nbboxactivated=count($boxidactivatedforuser);
1122
1123
        if ($nbboxactivated)
1124
        {
1125
        	$langs->load("boxes");
1126
			$langs->load("projects");
1127
1128
        	$emptybox=new ModeleBoxes($db);
1129
1130
            $boxlista.="\n<!-- Box left container -->\n";
0 ignored issues
show
Bug introduced by
The variable $boxlista does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1131
            $boxlista.='<div id="left" class="connectedSortable">'."\n";
1132
1133
            // Define $box_max_lines
1134
            $box_max_lines=5;
1135
            if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1136
1137
            $ii=0;
1138
            foreach ($boxactivated as $key => $box)
1139
            {
1140
            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1141
				if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='A'.sprintf("%02d",($ii+1));	// When box_order was not yet set to Axx or Bxx and is still 0
1142
            	if (preg_match('/^A/i',$box->box_order)) // column A
1143
                {
1144
                    $ii++;
1145
                    //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1146
                    //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1147
                    // Show box
1148
                    $box->loadBox($box_max_lines);
1149
                    $boxlista.= $box->outputBox();
1150
                }
1151
            }
1152
1153
            if (empty($conf->browser->phone))
1154
            {
1155
            	$emptybox->box_id='A';
1156
            	$emptybox->info_box_head=array();
1157
            	$emptybox->info_box_contents=array();
1158
            	$boxlista.= $emptybox->outputBox(array(),array());
1159
            }
1160
            $boxlista.= "</div>\n";
1161
            $boxlista.= "<!-- End box left container -->\n";
1162
1163
            $boxlistb.= "\n<!-- Box right container -->\n";
0 ignored issues
show
Bug introduced by
The variable $boxlistb does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1164
            $boxlistb.= '<div id="right" class="connectedSortable">'."\n";
1165
1166
            $ii=0;
1167
            foreach ($boxactivated as $key => $box)
1168
            {
1169
            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1170
            	if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='B'.sprintf("%02d",($ii+1));	// When box_order was not yet set to Axx or Bxx and is still 0
1171
            	if (preg_match('/^B/i',$box->box_order)) // colonne B
1172
                {
1173
                    $ii++;
1174
                    //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1175
                    //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1176
                    // Show box
1177
                    $box->loadBox($box_max_lines);
1178
                    $boxlistb.= $box->outputBox();
1179
                }
1180
            }
1181
1182
            if (empty($conf->browser->phone))
1183
            {
1184
            	$emptybox->box_id='B';
1185
            	$emptybox->info_box_head=array();
1186
            	$emptybox->info_box_contents=array();
1187
            	$boxlistb.= $emptybox->outputBox(array(),array());
1188
            }
1189
            $boxlistb.= "</div>\n";
1190
            $boxlistb.= "<!-- End box right container -->\n";
1191
1192
        }
1193
1194
        return array('selectboxlist'=>count($boxactivated)?$selectboxlist:'', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1195
    }
1196
1197
1198
    /**
1199
     *  Return a HTML select list of bank accounts
1200
     *
1201
     *  @param  string	$htmlname          	Name of select zone
1202
     *  @param	string	$dictionarytable	Dictionary table
1203
     *  @param	string	$keyfield			Field for key
1204
     *  @param	string	$labelfield			Label field
1205
     *  @param	string	$selected			Selected value
1206
     *  @param  int		$useempty          	1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
1207
     *  @param  string  $moreattrib         More attributes on HTML select tag
1208
     * 	@return	void
1209
     */
1210
    function select_dictionary($htmlname,$dictionarytable,$keyfield='code',$labelfield='label',$selected='',$useempty=0,$moreattrib='')
1211
    {
1212
        global $langs, $conf;
1213
1214
        $langs->load("admin");
1215
1216
        $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1217
        $sql.= " FROM ".MAIN_DB_PREFIX.$dictionarytable;
1218
        $sql.= " ORDER BY ".$labelfield;
1219
1220
        dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1221
        $result = $this->db->query($sql);
1222
        if ($result)
1223
        {
1224
            $num = $this->db->num_rows($result);
1225
            $i = 0;
1226
            if ($num)
1227
            {
1228
                print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
1229
                if ($useempty == 1 || ($useempty == 2 && $num > 1))
1230
                {
1231
                    print '<option value="-1">&nbsp;</option>';
1232
                }
1233
1234
                while ($i < $num)
1235
                {
1236
                    $obj = $this->db->fetch_object($result);
1237
                    if ($selected == $obj->rowid || $selected == $obj->$keyfield)
1238
                    {
1239
                        print '<option value="'.$obj->$keyfield.'" selected>';
1240
                    }
1241
                    else
1242
                    {
1243
                        print '<option value="'.$obj->$keyfield.'">';
1244
                    }
1245
                    print $obj->$labelfield;
1246
                    print '</option>';
1247
                    $i++;
1248
                }
1249
                print "</select>";
1250
            }
1251
            else
1252
			{
1253
                print $langs->trans("DictionaryEmpty");
1254
            }
1255
        }
1256
        else {
1257
            dol_print_error($this->db);
1258
        }
1259
    }
1260
1261
}
1262
1263