Passed
Push — master ( 853f8f...c34860 )
by Alxarafe
25:12
created
dolibarr/htdocs/core/class/html.formprojet.class.php 3 patches
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -29,660 +29,660 @@
 block discarded – undo
29 29
  */
30 30
 class FormProjets
31 31
 {
32
-	/**
32
+    /**
33 33
      * @var DoliDB Database handler.
34 34
      */
35 35
     public $db;
36 36
 
37
-	/**
38
-	 * @var string Error code (or message)
39
-	 */
40
-	public $error='';
37
+    /**
38
+     * @var string Error code (or message)
39
+     */
40
+    public $error='';
41 41
 
42 42
 
43
-	/**
44
-	 *	Constructor
45
-	 *
46
-	 *  @param		DoliDB		$db      Database handler
47
-	 */
48
-	function __construct($db)
49
-	{
50
-		$this->db = $db;
51
-	}
43
+    /**
44
+     *	Constructor
45
+     *
46
+     *  @param		DoliDB		$db      Database handler
47
+     */
48
+    function __construct($db)
49
+    {
50
+        $this->db = $db;
51
+    }
52 52
 
53 53
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
54
-	/**
55
-	 *	Output a combo list with projects qualified for a third party / user
56
-	 *
57
-	 *	@param	int		$socid      	Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
58
-	 *	@param  string	$selected   	Id project preselected ('' or id of project)
59
-	 *	@param  string	$htmlname   	Name of HTML field
60
-	 *	@param	int		$maxlength		Maximum length of label
61
-	 *	@param	int		$option_only	Return only html options lines without the select tag
62
-	 *	@param	int		$show_empty		Add an empty line
63
-	 *  @param	int		$discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
64
-	 *  @param	int		$forcefocus		Force focus on field (works with javascript only)
65
-	 *  @param	int		$disabled		Disabled
66
-	 *  @param  int     $mode           0 for HTML mode and 1 for JSON mode
67
-	 *  @param  string  $filterkey      Key to filter
68
-	 *  @param  int     $nooutput       No print output. Return it only.
69
-	 *  @param  int     $forceaddid     Force to add project id in list, event if not qualified
70
-	 *  @param  string  $morecss        More css
71
-	 *	@param  int     $htmlid         Html id to use instead of htmlname
72
-	 *	@return string           		Return html content
73
-	 */
74
-	function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='')
75
-	{
54
+    /**
55
+     *	Output a combo list with projects qualified for a third party / user
56
+     *
57
+     *	@param	int		$socid      	Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
58
+     *	@param  string	$selected   	Id project preselected ('' or id of project)
59
+     *	@param  string	$htmlname   	Name of HTML field
60
+     *	@param	int		$maxlength		Maximum length of label
61
+     *	@param	int		$option_only	Return only html options lines without the select tag
62
+     *	@param	int		$show_empty		Add an empty line
63
+     *  @param	int		$discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
64
+     *  @param	int		$forcefocus		Force focus on field (works with javascript only)
65
+     *  @param	int		$disabled		Disabled
66
+     *  @param  int     $mode           0 for HTML mode and 1 for JSON mode
67
+     *  @param  string  $filterkey      Key to filter
68
+     *  @param  int     $nooutput       No print output. Return it only.
69
+     *  @param  int     $forceaddid     Force to add project id in list, event if not qualified
70
+     *  @param  string  $morecss        More css
71
+     *	@param  int     $htmlid         Html id to use instead of htmlname
72
+     *	@return string           		Return html content
73
+     */
74
+    function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='')
75
+    {
76 76
         // phpcs:enable
77
-		global $langs,$conf,$form;
78
-
79
-		$out='';
80
-
81
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
82
-		{
83
-			$placeholder='';
84
-
85
-			if ($selected && empty($selected_input_value))
86
-			{
87
-				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88
-				$project = new Project($this->db);
89
-				$project->fetch($selected);
90
-				$selected_input_value=$project->ref;
91
-			}
92
-			$urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
93
-			$out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
77
+        global $langs,$conf,$form;
78
+
79
+        $out='';
80
+
81
+        if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
82
+        {
83
+            $placeholder='';
84
+
85
+            if ($selected && empty($selected_input_value))
86
+            {
87
+                require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88
+                $project = new Project($this->db);
89
+                $project->fetch($selected);
90
+                $selected_input_value=$project->ref;
91
+            }
92
+            $urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
93
+            $out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
94 94
 //				'update' => array(
95 95
 //					'projectid' => 'id'
96 96
 //				)
97
-			));
98
-
99
-			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
100
-		}
101
-		else
102
-		{
103
-			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
104
-		}
105
-		if ($discard_closed)
106
-		{
107
-			if (class_exists('Form'))
108
-			{
109
-				if (empty($form)) $form=new Form($this->db);
110
-				$out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
111
-			}
112
-		}
113
-
114
-		if (empty($nooutput))
115
-		{
116
-		    print $out;
117
-		    return '';
118
-		}
119
-		else return $out;
120
-	}
97
+            ));
98
+
99
+            $out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
100
+        }
101
+        else
102
+        {
103
+            $out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
104
+        }
105
+        if ($discard_closed)
106
+        {
107
+            if (class_exists('Form'))
108
+            {
109
+                if (empty($form)) $form=new Form($this->db);
110
+                $out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
111
+            }
112
+        }
113
+
114
+        if (empty($nooutput))
115
+        {
116
+            print $out;
117
+            return '';
118
+        }
119
+        else return $out;
120
+    }
121 121
 
122 122
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
123
-	/**
124
-	 * Returns an array with projects qualified for a third party
125
-	 *
126
-	 * @param  int     $socid      	       Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
127
-	 * @param  int     $selected   	       Id project preselected
128
-	 * @param  string  $htmlname   	       Nom de la zone html
129
-	 * @param  int     $maxlength          Maximum length of label
130
-	 * @param  int     $option_only	       Return only html options lines without the select tag
131
-	 * @param  int     $show_empty		   Add an empty line
132
-	 * @param  int     $discard_closed     Discard closed projects (0=Keep,1=hide completely,2=Disable)
123
+    /**
124
+     * Returns an array with projects qualified for a third party
125
+     *
126
+     * @param  int     $socid      	       Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
127
+     * @param  int     $selected   	       Id project preselected
128
+     * @param  string  $htmlname   	       Nom de la zone html
129
+     * @param  int     $maxlength          Maximum length of label
130
+     * @param  int     $option_only	       Return only html options lines without the select tag
131
+     * @param  int     $show_empty		   Add an empty line
132
+     * @param  int     $discard_closed     Discard closed projects (0=Keep,1=hide completely,2=Disable)
133 133
      * @param  int     $forcefocus		   Force focus on field (works with javascript only)
134 134
      * @param  int     $disabled           Disabled
135
-	 * @param  int     $mode               0 for HTML mode and 1 for array return (to be used by json_encode for example)
136
-	 * @param  string  $filterkey          Key to filter
137
-	 * @param  int     $nooutput           No print output. Return it only.
138
-	 * @param  int     $forceaddid         Force to add project id in list, event if not qualified
139
-	 * @param  int     $htmlid             Html id to use instead of htmlname
140
-	 * @param  string  $morecss            More CSS
141
-	 * @return int         			       Nb of project if OK, <0 if KO
142
-	 */
143
-	function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0, $htmlid='', $morecss='maxwidth500')
144
-	{
135
+     * @param  int     $mode               0 for HTML mode and 1 for array return (to be used by json_encode for example)
136
+     * @param  string  $filterkey          Key to filter
137
+     * @param  int     $nooutput           No print output. Return it only.
138
+     * @param  int     $forceaddid         Force to add project id in list, event if not qualified
139
+     * @param  int     $htmlid             Html id to use instead of htmlname
140
+     * @param  string  $morecss            More CSS
141
+     * @return int         			       Nb of project if OK, <0 if KO
142
+     */
143
+    function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0, $htmlid='', $morecss='maxwidth500')
144
+    {
145 145
         // phpcs:enable
146
-		global $user,$conf,$langs;
147
-
148
-		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
149
-
150
-		if (empty($htmlid)) $htmlid = $htmlname;
151
-
152
-		$out='';
153
-		$outarray=array();
154
-
155
-		$hideunselectables = false;
156
-		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
157
-
158
-		$projectsListId = false;
159
-		if (empty($user->rights->projet->all->lire))
160
-		{
161
-			$projectstatic=new Project($this->db);
162
-			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
163
-		}
164
-
165
-		// Search all projects
166
-		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
167
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
168
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
169
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
170
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
171
-		if ($socid > 0)
172
-		{
173
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
174
-		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
175
-		    {
176
-		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
177
-		    }
178
-		}
179
-		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
180
-		$sql.= " ORDER BY p.ref ASC";
181
-
182
-		$resql=$this->db->query($sql);
183
-		if ($resql)
184
-		{
185
-			// Use select2 selector
186
-			if (! empty($conf->use_javascript_ajax))
187
-			{
188
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
189
-	           	$comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
190
-            	$out.=$comboenhancement;
191
-            	$morecss.=' minwidth100';
192
-			}
193
-
194
-			if (empty($option_only)) {
195
-				$out.= '<select class="flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlid.'" name="'.$htmlname.'">';
196
-			}
197
-			if (!empty($show_empty)) {
198
-				$out.= '<option value="0">&nbsp;</option>';
199
-			}
200
-			$num = $this->db->num_rows($resql);
201
-			$i = 0;
202
-			if ($num)
203
-			{
204
-				while ($i < $num)
205
-				{
206
-					$obj = $this->db->fetch_object($resql);
207
-					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
208
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
209
-					{
210
-						// Do nothing
211
-					}
212
-					else
213
-					{
214
-						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) // We discard closed except if selected
215
-						{
216
-							$i++;
217
-							continue;
218
-						}
219
-
220
-						$labeltoshow=dol_trunc($obj->ref,18);
221
-						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
222
-						//else $labeltoshow.=' ('.$langs->trans("Private").')';
223
-						$labeltoshow.=', '.dol_trunc($obj->title, $maxlength);
224
-						if ($obj->name)
225
-						{
226
-						    $labeltoshow.=' - '.$obj->name;
227
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
228
-						}
229
-
230
-						$disabled=0;
231
-						if ($obj->fk_statut == 0)
232
-						{
233
-							$disabled=1;
234
-							$labeltoshow.=' - '.$langs->trans("Draft");
235
-						}
236
-						else if ($obj->fk_statut == 2)
237
-						{
238
-							if ($discard_closed == 2) $disabled=1;
239
-							$labeltoshow.=' - '.$langs->trans("Closed");
240
-						}
241
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
242
-						{
243
-							$disabled=1;
244
-							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
245
-						}
246
-
247
-						if (!empty($selected) && $selected == $obj->rowid)
248
-						{
249
-							$out.= '<option value="'.$obj->rowid.'" selected';
250
-							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
251
-							$out.= '>'.$labeltoshow.'</option>';
252
-						}
253
-						else
254
-						{
255
-							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
256
-							{
257
-								$resultat='';
258
-							}
259
-							else
260
-							{
261
-								$resultat='<option value="'.$obj->rowid.'"';
262
-								if ($disabled) $resultat.=' disabled';
263
-								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
264
-								//else $labeltoshow.=' ('.$langs->trans("Private").')';
265
-								$resultat.='>';
266
-								$resultat.=$labeltoshow;
267
-								$resultat.='</option>';
268
-							}
269
-							$out.= $resultat;
270
-
271
-							$outarray[] = array(
272
-								'key' => (int) $obj->rowid,
273
-								'value' => $obj->ref,
274
-								'ref' => $obj->ref,
275
-								'label' => $labeltoshow,
276
-								'disabled' => (bool) $disabled
277
-							);
278
-						}
279
-					}
280
-					$i++;
281
-				}
282
-			}
283
-
284
-			$this->db->free($resql);
285
-
286
-			if (!$mode) {
287
-				if (empty($option_only)) $out.= '</select>';
288
-				if (empty($nooutput))
289
-				{
290
-				    print $out;
291
-				    return '';
292
-				}
293
-				else return $out;
294
-			} else {
295
-				return $outarray;
296
-			}
297
-		}
298
-		else
299
-		{
300
-			dol_print_error($this->db);
301
-			return -1;
302
-		}
303
-	}
304
-
305
-	/**
306
-	 *	Output a combo list with tasks qualified for a third party
307
-	 *
308
-	 *	@param	int		$socid      	Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
309
-	 *	@param  int		$selected   	Id task preselected
310
-	 *	@param  string	$htmlname   	Name of HTML select
311
-	 *	@param	int		$maxlength		Maximum length of label
312
-	 *	@param	int		$option_only	Return only html options lines without the select tag
313
-	 *	@param	string	$show_empty		Add an empty line ('1' or string to show for empty line)
314
-	 *  @param	int		$discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
146
+        global $user,$conf,$langs;
147
+
148
+        require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
149
+
150
+        if (empty($htmlid)) $htmlid = $htmlname;
151
+
152
+        $out='';
153
+        $outarray=array();
154
+
155
+        $hideunselectables = false;
156
+        if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
157
+
158
+        $projectsListId = false;
159
+        if (empty($user->rights->projet->all->lire))
160
+        {
161
+            $projectstatic=new Project($this->db);
162
+            $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
163
+        }
164
+
165
+        // Search all projects
166
+        $sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
167
+        $sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
168
+        $sql.= " WHERE p.entity IN (".getEntity('project').")";
169
+        if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
170
+        if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
171
+        if ($socid > 0)
172
+        {
173
+            if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
174
+            else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
175
+            {
176
+                $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
177
+            }
178
+        }
179
+        if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
180
+        $sql.= " ORDER BY p.ref ASC";
181
+
182
+        $resql=$this->db->query($sql);
183
+        if ($resql)
184
+        {
185
+            // Use select2 selector
186
+            if (! empty($conf->use_javascript_ajax))
187
+            {
188
+                include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
189
+                    $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
190
+                $out.=$comboenhancement;
191
+                $morecss.=' minwidth100';
192
+            }
193
+
194
+            if (empty($option_only)) {
195
+                $out.= '<select class="flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlid.'" name="'.$htmlname.'">';
196
+            }
197
+            if (!empty($show_empty)) {
198
+                $out.= '<option value="0">&nbsp;</option>';
199
+            }
200
+            $num = $this->db->num_rows($resql);
201
+            $i = 0;
202
+            if ($num)
203
+            {
204
+                while ($i < $num)
205
+                {
206
+                    $obj = $this->db->fetch_object($resql);
207
+                    // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
208
+                    if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
209
+                    {
210
+                        // Do nothing
211
+                    }
212
+                    else
213
+                    {
214
+                        if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) // We discard closed except if selected
215
+                        {
216
+                            $i++;
217
+                            continue;
218
+                        }
219
+
220
+                        $labeltoshow=dol_trunc($obj->ref,18);
221
+                        //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
222
+                        //else $labeltoshow.=' ('.$langs->trans("Private").')';
223
+                        $labeltoshow.=', '.dol_trunc($obj->title, $maxlength);
224
+                        if ($obj->name)
225
+                        {
226
+                            $labeltoshow.=' - '.$obj->name;
227
+                            if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
228
+                        }
229
+
230
+                        $disabled=0;
231
+                        if ($obj->fk_statut == 0)
232
+                        {
233
+                            $disabled=1;
234
+                            $labeltoshow.=' - '.$langs->trans("Draft");
235
+                        }
236
+                        else if ($obj->fk_statut == 2)
237
+                        {
238
+                            if ($discard_closed == 2) $disabled=1;
239
+                            $labeltoshow.=' - '.$langs->trans("Closed");
240
+                        }
241
+                        else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
242
+                        {
243
+                            $disabled=1;
244
+                            $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
245
+                        }
246
+
247
+                        if (!empty($selected) && $selected == $obj->rowid)
248
+                        {
249
+                            $out.= '<option value="'.$obj->rowid.'" selected';
250
+                            //if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
251
+                            $out.= '>'.$labeltoshow.'</option>';
252
+                        }
253
+                        else
254
+                        {
255
+                            if ($hideunselectables && $disabled && ($selected != $obj->rowid))
256
+                            {
257
+                                $resultat='';
258
+                            }
259
+                            else
260
+                            {
261
+                                $resultat='<option value="'.$obj->rowid.'"';
262
+                                if ($disabled) $resultat.=' disabled';
263
+                                //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
264
+                                //else $labeltoshow.=' ('.$langs->trans("Private").')';
265
+                                $resultat.='>';
266
+                                $resultat.=$labeltoshow;
267
+                                $resultat.='</option>';
268
+                            }
269
+                            $out.= $resultat;
270
+
271
+                            $outarray[] = array(
272
+                                'key' => (int) $obj->rowid,
273
+                                'value' => $obj->ref,
274
+                                'ref' => $obj->ref,
275
+                                'label' => $labeltoshow,
276
+                                'disabled' => (bool) $disabled
277
+                            );
278
+                        }
279
+                    }
280
+                    $i++;
281
+                }
282
+            }
283
+
284
+            $this->db->free($resql);
285
+
286
+            if (!$mode) {
287
+                if (empty($option_only)) $out.= '</select>';
288
+                if (empty($nooutput))
289
+                {
290
+                    print $out;
291
+                    return '';
292
+                }
293
+                else return $out;
294
+            } else {
295
+                return $outarray;
296
+            }
297
+        }
298
+        else
299
+        {
300
+            dol_print_error($this->db);
301
+            return -1;
302
+        }
303
+    }
304
+
305
+    /**
306
+     *	Output a combo list with tasks qualified for a third party
307
+     *
308
+     *	@param	int		$socid      	Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
309
+     *	@param  int		$selected   	Id task preselected
310
+     *	@param  string	$htmlname   	Name of HTML select
311
+     *	@param	int		$maxlength		Maximum length of label
312
+     *	@param	int		$option_only	Return only html options lines without the select tag
313
+     *	@param	string	$show_empty		Add an empty line ('1' or string to show for empty line)
314
+     *  @param	int		$discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
315 315
      *  @param	int		$forcefocus		Force focus on field (works with javascript only)
316 316
      *  @param	int		$disabled		Disabled
317
-	 *  @param	string	$morecss        More css added to the select component
318
-	 *  @param	string	$projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids.
319
-	 *  @param	string	$showproject	'all' = Show project info, ''=Hide project info
320
-	 *  @param	User	$usertofilter	User object to use for filtering
321
-	 *	@return int         			Nbr of project if OK, <0 if KO
322
-	 */
323
-	function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showproject='all', $usertofilter=null)
324
-	{
325
-		global $user,$conf,$langs;
326
-
327
-		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
328
-
329
-		if (is_null($usertofilter))
330
-		{
331
-			$usertofilter = $user;
332
-		}
333
-
334
-		$out='';
335
-
336
-		$hideunselectables = false;
337
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
338
-
339
-		if (empty($projectsListId))
340
-		{
341
-			if (empty($usertofilter->rights->projet->all->lire))
342
-			{
343
-				$projectstatic=new Project($this->db);
344
-				$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter,0,1);
345
-			}
346
-		}
347
-
348
-		// Search all projects
349
-		$sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public,';
350
-		$sql.= ' s.nom as name';
351
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
352
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
353
-		$sql.= ' '.MAIN_DB_PREFIX.'projet_task as t';
354
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
355
-		$sql.= " AND t.fk_projet = p.rowid";
356
-		if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")";
357
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
359
-		$sql.= " ORDER BY p.ref, t.ref ASC";
360
-
361
-		$resql=$this->db->query($sql);
362
-		if ($resql)
363
-		{
364
-			// Use select2 selector
365
-			if (! empty($conf->use_javascript_ajax))
366
-			{
367
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
368
-	           	$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
369
-            	$out.=$comboenhancement;
370
-            	$morecss='minwidth200 maxwidth500';
371
-			}
372
-
373
-			if (empty($option_only)) {
374
-				$out.= '<select class="valignmiddle flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.$htmlname.'">';
375
-			}
376
-			if (! empty($show_empty)) {
377
-				$out.= '<option value="0" class="optiongrey">';
378
-				if (! is_numeric($show_empty)) $out.=$show_empty;
379
-				else $out.='&nbsp;';
380
-				$out.= '</option>';
381
-			}
382
-			$num = $this->db->num_rows($resql);
383
-			$i = 0;
384
-			if ($num)
385
-			{
386
-				while ($i < $num)
387
-				{
388
-					$obj = $this->db->fetch_object($resql);
389
-					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
390
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire))
391
-					{
392
-						// Do nothing
393
-					}
394
-					else
395
-					{
396
-						if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED)
397
-						{
398
-							$i++;
399
-							continue;
400
-						}
401
-
402
-						$labeltoshow = '';
403
-
404
-						if ($showproject == 'all')
405
-						{
406
-							$labeltoshow.=dol_trunc($obj->ref,18);     // Project ref
407
-							//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
408
-							//else $labeltoshow.=' ('.$langs->trans("Private").')';
409
-							$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
410
-
411
-							if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
412
-
413
-							$disabled=0;
414
-							if ($obj->fk_statut == Project::STATUS_DRAFT)
415
-							{
416
-								$disabled=1;
417
-								$labeltoshow.=' - '.$langs->trans("Draft");
418
-							}
419
-							else if ($obj->fk_statut == Project::STATUS_CLOSED)
420
-							{
421
-								if ($discard_closed == 2) $disabled=1;
422
-								$labeltoshow.=' - '.$langs->trans("Closed");
423
-							}
424
-							else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
425
-							{
426
-								$disabled=1;
427
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
428
-							}
429
-							$labeltoshow.=' - ';
430
-						}
431
-
432
-						// Label for task
433
-						$labeltoshow.=$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength);
434
-
435
-						if (!empty($selected) && $selected == $obj->rowid)
436
-						{
437
-							$out.= '<option value="'.$obj->rowid.'" selected';
438
-							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
439
-							$out.= '>'.$labeltoshow.'</option>';
440
-						}
441
-						else
442
-						{
443
-							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
444
-							{
445
-								$resultat='';
446
-							}
447
-							else
448
-							{
449
-								$resultat='<option value="'.$obj->rowid.'"';
450
-								if ($disabled) $resultat.=' disabled';
451
-								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
452
-								//else $labeltoshow.=' ('.$langs->trans("Private").')';
453
-								$resultat.='>';
454
-								$resultat.=$labeltoshow;
455
-								$resultat.='</option>';
456
-							}
457
-							$out.= $resultat;
458
-						}
459
-					}
460
-					$i++;
461
-				}
462
-			}
463
-			if (empty($option_only)) {
464
-				$out.= '</select>';
465
-			}
466
-
467
-			print $out;
468
-
469
-			$this->db->free($resql);
470
-			return $num;
471
-		}
472
-		else
473
-		{
474
-			dol_print_error($this->db);
475
-			return -1;
476
-		}
477
-	}
317
+     *  @param	string	$morecss        More css added to the select component
318
+     *  @param	string	$projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids.
319
+     *  @param	string	$showproject	'all' = Show project info, ''=Hide project info
320
+     *  @param	User	$usertofilter	User object to use for filtering
321
+     *	@return int         			Nbr of project if OK, <0 if KO
322
+     */
323
+    function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showproject='all', $usertofilter=null)
324
+    {
325
+        global $user,$conf,$langs;
326
+
327
+        require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
328
+
329
+        if (is_null($usertofilter))
330
+        {
331
+            $usertofilter = $user;
332
+        }
333
+
334
+        $out='';
335
+
336
+        $hideunselectables = false;
337
+        if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
338
+
339
+        if (empty($projectsListId))
340
+        {
341
+            if (empty($usertofilter->rights->projet->all->lire))
342
+            {
343
+                $projectstatic=new Project($this->db);
344
+                $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter,0,1);
345
+            }
346
+        }
347
+
348
+        // Search all projects
349
+        $sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public,';
350
+        $sql.= ' s.nom as name';
351
+        $sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
352
+        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
353
+        $sql.= ' '.MAIN_DB_PREFIX.'projet_task as t';
354
+        $sql.= " WHERE p.entity IN (".getEntity('project').")";
355
+        $sql.= " AND t.fk_projet = p.rowid";
356
+        if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")";
357
+        if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
+        if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
359
+        $sql.= " ORDER BY p.ref, t.ref ASC";
360
+
361
+        $resql=$this->db->query($sql);
362
+        if ($resql)
363
+        {
364
+            // Use select2 selector
365
+            if (! empty($conf->use_javascript_ajax))
366
+            {
367
+                include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
368
+                    $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
369
+                $out.=$comboenhancement;
370
+                $morecss='minwidth200 maxwidth500';
371
+            }
372
+
373
+            if (empty($option_only)) {
374
+                $out.= '<select class="valignmiddle flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.$htmlname.'">';
375
+            }
376
+            if (! empty($show_empty)) {
377
+                $out.= '<option value="0" class="optiongrey">';
378
+                if (! is_numeric($show_empty)) $out.=$show_empty;
379
+                else $out.='&nbsp;';
380
+                $out.= '</option>';
381
+            }
382
+            $num = $this->db->num_rows($resql);
383
+            $i = 0;
384
+            if ($num)
385
+            {
386
+                while ($i < $num)
387
+                {
388
+                    $obj = $this->db->fetch_object($resql);
389
+                    // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
390
+                    if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire))
391
+                    {
392
+                        // Do nothing
393
+                    }
394
+                    else
395
+                    {
396
+                        if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED)
397
+                        {
398
+                            $i++;
399
+                            continue;
400
+                        }
401
+
402
+                        $labeltoshow = '';
403
+
404
+                        if ($showproject == 'all')
405
+                        {
406
+                            $labeltoshow.=dol_trunc($obj->ref,18);     // Project ref
407
+                            //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
408
+                            //else $labeltoshow.=' ('.$langs->trans("Private").')';
409
+                            $labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
410
+
411
+                            if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
412
+
413
+                            $disabled=0;
414
+                            if ($obj->fk_statut == Project::STATUS_DRAFT)
415
+                            {
416
+                                $disabled=1;
417
+                                $labeltoshow.=' - '.$langs->trans("Draft");
418
+                            }
419
+                            else if ($obj->fk_statut == Project::STATUS_CLOSED)
420
+                            {
421
+                                if ($discard_closed == 2) $disabled=1;
422
+                                $labeltoshow.=' - '.$langs->trans("Closed");
423
+                            }
424
+                            else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
425
+                            {
426
+                                $disabled=1;
427
+                                $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
428
+                            }
429
+                            $labeltoshow.=' - ';
430
+                        }
431
+
432
+                        // Label for task
433
+                        $labeltoshow.=$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength);
434
+
435
+                        if (!empty($selected) && $selected == $obj->rowid)
436
+                        {
437
+                            $out.= '<option value="'.$obj->rowid.'" selected';
438
+                            //if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
439
+                            $out.= '>'.$labeltoshow.'</option>';
440
+                        }
441
+                        else
442
+                        {
443
+                            if ($hideunselectables && $disabled && ($selected != $obj->rowid))
444
+                            {
445
+                                $resultat='';
446
+                            }
447
+                            else
448
+                            {
449
+                                $resultat='<option value="'.$obj->rowid.'"';
450
+                                if ($disabled) $resultat.=' disabled';
451
+                                //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
452
+                                //else $labeltoshow.=' ('.$langs->trans("Private").')';
453
+                                $resultat.='>';
454
+                                $resultat.=$labeltoshow;
455
+                                $resultat.='</option>';
456
+                            }
457
+                            $out.= $resultat;
458
+                        }
459
+                    }
460
+                    $i++;
461
+                }
462
+            }
463
+            if (empty($option_only)) {
464
+                $out.= '</select>';
465
+            }
466
+
467
+            print $out;
468
+
469
+            $this->db->free($resql);
470
+            return $num;
471
+        }
472
+        else
473
+        {
474
+            dol_print_error($this->db);
475
+            return -1;
476
+        }
477
+    }
478 478
 
479 479
 
480 480
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
481
-	/**
482
-	 *    Build a HTML select list of element of same thirdparty to suggest to link them to project
483
-	 *
484
-	 *    @param	string		$table_element		Table of the element to update
485
-	 *    @param	string		$socid				If of thirdparty to use as filter or 'id1,id2,...'
486
-	 *    @param	string		$morecss			More CSS
487
-	 *    @param    int         $limitonstatus      Add filters to limit length of list to opened status (for example to avoid ERR_RESPONSE_HEADERS_TOO_BIG on project/element.php page). TODO To implement
488
-	 *    @param	string		$projectkey			Equivalent key  to fk_projet for actual table_element
489
-	 *    @return	int|string						The HTML select list of element or '' if nothing or -1 if KO
490
-	 */
491
-	function select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2,$projectkey="fk_projet")
492
-	{
481
+    /**
482
+     *    Build a HTML select list of element of same thirdparty to suggest to link them to project
483
+     *
484
+     *    @param	string		$table_element		Table of the element to update
485
+     *    @param	string		$socid				If of thirdparty to use as filter or 'id1,id2,...'
486
+     *    @param	string		$morecss			More CSS
487
+     *    @param    int         $limitonstatus      Add filters to limit length of list to opened status (for example to avoid ERR_RESPONSE_HEADERS_TOO_BIG on project/element.php page). TODO To implement
488
+     *    @param	string		$projectkey			Equivalent key  to fk_projet for actual table_element
489
+     *    @return	int|string						The HTML select list of element or '' if nothing or -1 if KO
490
+     */
491
+    function select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2,$projectkey="fk_projet")
492
+    {
493 493
         // phpcs:enable
494
-		global $conf, $langs;
495
-
496
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
497
-
498
-		$linkedtothirdparty=false;
499
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) $linkedtothirdparty=true;
500
-
501
-		$sqlfilter='';
502
-
503
-		//print $table_element;
504
-		switch ($table_element)
505
-		{
506
-			case "loan":
507
-				$sql = "SELECT t.rowid, t.label as ref";
508
-				break;
509
-			case "facture":
510
-				$sql = "SELECT t.rowid, t.ref as ref";
511
-				break;
512
-			case "facture_fourn":
513
-				$sql = "SELECT t.rowid, t.ref, t.ref_supplier";
514
-				break;
515
-			case "commande_fourn":
516
-			case "commande_fournisseur":
517
-			    $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
518
-				break;
519
-			case "facture_rec":
520
-				$sql = "SELECT t.rowid, t.titre as ref";
521
-				break;
522
-			case "actioncomm":
523
-				$sql = "SELECT t.id as rowid, t.label as ref";
524
-				$projectkey="fk_project";
525
-				break;
526
-			case "expensereport":
527
-				return '';
528
-			case "expensereport_det":
529
-				/*$sql = "SELECT rowid, '' as ref";	// table is llx_expensereport_det
494
+        global $conf, $langs;
495
+
496
+        if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
497
+
498
+        $linkedtothirdparty=false;
499
+        if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) $linkedtothirdparty=true;
500
+
501
+        $sqlfilter='';
502
+
503
+        //print $table_element;
504
+        switch ($table_element)
505
+        {
506
+            case "loan":
507
+                $sql = "SELECT t.rowid, t.label as ref";
508
+                break;
509
+            case "facture":
510
+                $sql = "SELECT t.rowid, t.ref as ref";
511
+                break;
512
+            case "facture_fourn":
513
+                $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
514
+                break;
515
+            case "commande_fourn":
516
+            case "commande_fournisseur":
517
+                $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
518
+                break;
519
+            case "facture_rec":
520
+                $sql = "SELECT t.rowid, t.titre as ref";
521
+                break;
522
+            case "actioncomm":
523
+                $sql = "SELECT t.id as rowid, t.label as ref";
524
+                $projectkey="fk_project";
525
+                break;
526
+            case "expensereport":
527
+                return '';
528
+            case "expensereport_det":
529
+                /*$sql = "SELECT rowid, '' as ref";	// table is llx_expensereport_det
530 530
 				$projectkey="fk_projet";
531 531
 				break;*/
532
-				return '';
533
-			case "commande":
534
-		    case "contrat":
535
-			case "fichinter":
536
-			    $sql = "SELECT t.rowid, t.ref";
537
-			    break;
538
-			case 'stock_mouvement':
539
-				$sql = 'SELECT t.rowid, t.label as ref';
540
-				$projectkey='fk_origin';
541
-				break;
542
-			case "payment_salary":
543
-				$sql = "SELECT t.rowid, t.num_payment as ref";	// TODO In a future fill and use real ref field
544
-				break;
545
-			case "payment_various":
546
-				$sql = "SELECT t.rowid, t.num_payment as ref";
547
-				break;
548
-			case "chargesociales":
549
-			default:
550
-				$sql = "SELECT t.rowid, t.ref";
551
-				break;
552
-		}
553
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
554
-		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
556
-		$sql.= " WHERE ".$projectkey." is null";
557
-		if (! empty($socid) && $linkedtothirdparty)
558
-		{
559
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
560
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
561
-		}
562
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
563
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
564
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
565
-		$sql.= " ORDER BY ref DESC";
566
-
567
-		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
568
-		$resql=$this->db->query($sql);
569
-		if ($resql)
570
-		{
571
-			$num = $this->db->num_rows($resql);
572
-			$i = 0;
573
-			if ($num > 0)
574
-			{
575
-				$sellist = '<select class="flat elementselect css'.$table_element.($morecss?' '.$morecss:'').'" name="elementselect">';
576
-				$sellist .='<option value="-1"></option>';
577
-				while ($i < $num)
578
-				{
579
-					$obj = $this->db->fetch_object($resql);
580
-					$ref=$obj->ref?$obj->ref:$obj->rowid;
581
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
582
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
583
-					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
584
-					$i++;
585
-				}
586
-				$sellist .='</select>';
587
-			}
588
-			/*else
532
+                return '';
533
+            case "commande":
534
+            case "contrat":
535
+            case "fichinter":
536
+                $sql = "SELECT t.rowid, t.ref";
537
+                break;
538
+            case 'stock_mouvement':
539
+                $sql = 'SELECT t.rowid, t.label as ref';
540
+                $projectkey='fk_origin';
541
+                break;
542
+            case "payment_salary":
543
+                $sql = "SELECT t.rowid, t.num_payment as ref";	// TODO In a future fill and use real ref field
544
+                break;
545
+            case "payment_various":
546
+                $sql = "SELECT t.rowid, t.num_payment as ref";
547
+                break;
548
+            case "chargesociales":
549
+            default:
550
+                $sql = "SELECT t.rowid, t.ref";
551
+                break;
552
+        }
553
+        if ($linkedtothirdparty) $sql.=", s.nom as name";
554
+        $sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
+        if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
556
+        $sql.= " WHERE ".$projectkey." is null";
557
+        if (! empty($socid) && $linkedtothirdparty)
558
+        {
559
+            if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
560
+            else $sql.= " AND t.fk_soc IN (".$socid.")";
561
+        }
562
+        if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
563
+        if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
564
+        if ($sqlfilter) $sql.= " AND ".$sqlfilter;
565
+        $sql.= " ORDER BY ref DESC";
566
+
567
+        dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
568
+        $resql=$this->db->query($sql);
569
+        if ($resql)
570
+        {
571
+            $num = $this->db->num_rows($resql);
572
+            $i = 0;
573
+            if ($num > 0)
574
+            {
575
+                $sellist = '<select class="flat elementselect css'.$table_element.($morecss?' '.$morecss:'').'" name="elementselect">';
576
+                $sellist .='<option value="-1"></option>';
577
+                while ($i < $num)
578
+                {
579
+                    $obj = $this->db->fetch_object($resql);
580
+                    $ref=$obj->ref?$obj->ref:$obj->rowid;
581
+                    if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
582
+                    if (! empty($obj->name)) $ref.=' - '.$obj->name;
583
+                    $sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
584
+                    $i++;
585
+                }
586
+                $sellist .='</select>';
587
+            }
588
+            /*else
589 589
 			{
590 590
 				$sellist = '<select class="flat" name="elementselect">';
591 591
 				$sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
592 592
 				$sellist.= '</select>';
593 593
 			}*/
594
-			$this->db->free($resql);
595
-
596
-			return $sellist;
597
-		}
598
-		else
599
-		{
600
-			dol_print_error($this->db);
601
-			$this->error=$this->db->lasterror();
602
-			$this->errors[]=$this->db->lasterror();
603
-			dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
604
-			return -1;
605
-		}
606
-	}
607
-
608
-
609
-	/**
610
-	 *    Build a HTML select list of element of same thirdparty to suggest to link them to project
611
-	 *
612
-	 *    @param   string      $htmlname           HTML name
613
-	 *    @param   string      $preselected        Preselected (int or 'all' or 'none')
614
-	 *    @param   int         $showempty          Add an empty line
615
-	 *    @param   int         $useshortlabel      Use short label
616
-	 *    @param   int         $showallnone        Add choice "All" and "None"
617
-	 *    @param   int         $showpercent        Show default probability for status
618
-	 *    @param   string      $morecss            Add more css
619
-	 *    @return  int|string                      The HTML select list of element or '' if nothing or -1 if KO
620
-	 */
621
-	function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='')
622
-	{
623
-		global $conf, $langs;
624
-
625
-		$sql = "SELECT rowid, code, label, percent";
626
-		$sql.= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
627
-		$sql.= " WHERE active = 1";
628
-		$sql.= " ORDER BY position";
629
-
630
-		$resql=$this->db->query($sql);
631
-		if ($resql)
632
-		{
633
-			$num = $this->db->num_rows($resql);
634
-			$i = 0;
635
-			if ($num > 0)
636
-			{
637
-				$sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
638
-				if ($showempty) {
594
+            $this->db->free($resql);
595
+
596
+            return $sellist;
597
+        }
598
+        else
599
+        {
600
+            dol_print_error($this->db);
601
+            $this->error=$this->db->lasterror();
602
+            $this->errors[]=$this->db->lasterror();
603
+            dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
604
+            return -1;
605
+        }
606
+    }
607
+
608
+
609
+    /**
610
+     *    Build a HTML select list of element of same thirdparty to suggest to link them to project
611
+     *
612
+     *    @param   string      $htmlname           HTML name
613
+     *    @param   string      $preselected        Preselected (int or 'all' or 'none')
614
+     *    @param   int         $showempty          Add an empty line
615
+     *    @param   int         $useshortlabel      Use short label
616
+     *    @param   int         $showallnone        Add choice "All" and "None"
617
+     *    @param   int         $showpercent        Show default probability for status
618
+     *    @param   string      $morecss            Add more css
619
+     *    @return  int|string                      The HTML select list of element or '' if nothing or -1 if KO
620
+     */
621
+    function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='')
622
+    {
623
+        global $conf, $langs;
624
+
625
+        $sql = "SELECT rowid, code, label, percent";
626
+        $sql.= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
627
+        $sql.= " WHERE active = 1";
628
+        $sql.= " ORDER BY position";
629
+
630
+        $resql=$this->db->query($sql);
631
+        if ($resql)
632
+        {
633
+            $num = $this->db->num_rows($resql);
634
+            $i = 0;
635
+            if ($num > 0)
636
+            {
637
+                $sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
638
+                if ($showempty) {
639 639
                     // Without &nbsp, strange move of screen when switching value
640 640
                     $sellist.= '<option value="-1">&nbsp;</option>';
641 641
                 }
642
-				if ($showallnone) {
642
+                if ($showallnone) {
643 643
                     $sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>-- '.$langs->trans("OnlyOpportunitiesShort").' --</option>';
644
-				    $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>-- '.$langs->trans("OpenedOpportunitiesShort").' --</option>';
645
-				    $sellist.= '<option value="notopenedopp"'.($preselected == 'notopenedopp'?' selected="selected"':'').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").' --</option>';
646
-				    $sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>-- '.$langs->trans("NotAnOpportunityShort").' --</option>';
644
+                    $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>-- '.$langs->trans("OpenedOpportunitiesShort").' --</option>';
645
+                    $sellist.= '<option value="notopenedopp"'.($preselected == 'notopenedopp'?' selected="selected"':'').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").' --</option>';
646
+                    $sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>-- '.$langs->trans("NotAnOpportunityShort").' --</option>';
647
+                }
648
+                while ($i < $num)
649
+                {
650
+                    $obj = $this->db->fetch_object($resql);
651
+
652
+                    $sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
653
+                    if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
654
+                    $sellist .= '>';
655
+                    if ($useshortlabel)
656
+                    {
657
+                        $finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
658
+                    }
659
+                    else
660
+                    {
661
+                        $finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
662
+                        if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
663
+                    }
664
+                    $sellist .= $finallabel;
665
+                    $sellist .='</option>';
666
+                    $i++;
647 667
                 }
648
-				while ($i < $num)
649
-				{
650
-					$obj = $this->db->fetch_object($resql);
651
-
652
-					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
653
-					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
654
-					$sellist .= '>';
655
-					if ($useshortlabel)
656
-					{
657
-						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
658
-					}
659
-					else
660
-					{
661
-						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
662
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
663
-					}
664
-					$sellist .= $finallabel;
665
-					$sellist .='</option>';
666
-					$i++;
667
-				}
668
-				$sellist .='</select>';
669
-			}
670
-			/*else
668
+                $sellist .='</select>';
669
+            }
670
+            /*else
671 671
 			{
672 672
 				$sellist = '<select class="flat" name="elementselect">';
673 673
 				$sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
674 674
 				$sellist.= '</select>';
675 675
 			}*/
676
-			$this->db->free($resql);
677
-
678
-			return $sellist;
679
-		}
680
-		else
681
-		{
682
-			$this->error=$this->db->lasterror();
683
-			$this->errors[]=$this->db->lasterror();
684
-			dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
685
-			return -1;
686
-		}
687
-	}
676
+            $this->db->free($resql);
677
+
678
+            return $sellist;
679
+        }
680
+        else
681
+        {
682
+            $this->error=$this->db->lasterror();
683
+            $this->errors[]=$this->db->lasterror();
684
+            dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
685
+            return -1;
686
+        }
687
+    }
688 688
 }
Please login to merge, or discard this patch.
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @var string Error code (or message)
39 39
 	 */
40
-	public $error='';
40
+	public $error = '';
41 41
 
42 42
 
43 43
 	/**
@@ -71,43 +71,43 @@  discard block
 block discarded – undo
71 71
 	 *	@param  int     $htmlid         Html id to use instead of htmlname
72 72
 	 *	@return string           		Return html content
73 73
 	 */
74
-	function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='')
74
+	function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $morecss = '', $htmlid = '')
75 75
 	{
76 76
         // phpcs:enable
77
-		global $langs,$conf,$form;
77
+		global $langs, $conf, $form;
78 78
 
79
-		$out='';
79
+		$out = '';
80 80
 
81
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
81
+		if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
82 82
 		{
83
-			$placeholder='';
83
+			$placeholder = '';
84 84
 
85 85
 			if ($selected && empty($selected_input_value))
86 86
 			{
87 87
 				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88 88
 				$project = new Project($this->db);
89 89
 				$project->fetch($selected);
90
-				$selected_input_value=$project->ref;
90
+				$selected_input_value = $project->ref;
91 91
 			}
92
-			$urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
93
-			$out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
92
+			$urloption = 'socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
93
+			$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
94 94
 //				'update' => array(
95 95
 //					'projectid' => 'id'
96 96
 //				)
97 97
 			));
98 98
 
99
-			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
99
+			$out .= '<input type="text" class="minwidth200'.($morecss ? ' '.$morecss : '').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
100 100
 		}
101 101
 		else
102 102
 		{
103
-			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
103
+			$out .= $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
104 104
 		}
105 105
 		if ($discard_closed)
106 106
 		{
107 107
 			if (class_exists('Form'))
108 108
 			{
109
-				if (empty($form)) $form=new Form($this->db);
110
-				$out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
109
+				if (empty($form)) $form = new Form($this->db);
110
+				$out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
111 111
 			}
112 112
 		}
113 113
 
@@ -140,62 +140,62 @@  discard block
 block discarded – undo
140 140
 	 * @param  string  $morecss            More CSS
141 141
 	 * @return int         			       Nb of project if OK, <0 if KO
142 142
 	 */
143
-	function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0, $htmlid='', $morecss='maxwidth500')
143
+	function select_projects_list($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $htmlid = '', $morecss = 'maxwidth500')
144 144
 	{
145 145
         // phpcs:enable
146
-		global $user,$conf,$langs;
146
+		global $user, $conf, $langs;
147 147
 
148 148
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
149 149
 
150 150
 		if (empty($htmlid)) $htmlid = $htmlname;
151 151
 
152
-		$out='';
153
-		$outarray=array();
152
+		$out = '';
153
+		$outarray = array();
154 154
 
155 155
 		$hideunselectables = false;
156
-		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
156
+		if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
157 157
 
158 158
 		$projectsListId = false;
159 159
 		if (empty($user->rights->projet->all->lire))
160 160
 		{
161
-			$projectstatic=new Project($this->db);
162
-			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
161
+			$projectstatic = new Project($this->db);
162
+			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
163 163
 		}
164 164
 
165 165
 		// Search all projects
166 166
 		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
167
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
168
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
169
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
170
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
167
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
168
+		$sql .= " WHERE p.entity IN (".getEntity('project').")";
169
+		if ($projectsListId !== false) $sql .= " AND p.rowid IN (".$projectsListId.")";
170
+		if ($socid == 0) $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
171 171
 		if ($socid > 0)
172 172
 		{
173
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
173
+		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql .= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
174 174
 		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
175 175
 		    {
176
-		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
176
+		        $sql .= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
177 177
 		    }
178 178
 		}
179 179
 		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
180
-		$sql.= " ORDER BY p.ref ASC";
180
+		$sql .= " ORDER BY p.ref ASC";
181 181
 
182
-		$resql=$this->db->query($sql);
182
+		$resql = $this->db->query($sql);
183 183
 		if ($resql)
184 184
 		{
185 185
 			// Use select2 selector
186
-			if (! empty($conf->use_javascript_ajax))
186
+			if (!empty($conf->use_javascript_ajax))
187 187
 			{
188
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
188
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
189 189
 	           	$comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
190
-            	$out.=$comboenhancement;
191
-            	$morecss.=' minwidth100';
190
+            	$out .= $comboenhancement;
191
+            	$morecss .= ' minwidth100';
192 192
 			}
193 193
 
194 194
 			if (empty($option_only)) {
195
-				$out.= '<select class="flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlid.'" name="'.$htmlname.'">';
195
+				$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlid.'" name="'.$htmlname.'">';
196 196
 			}
197 197
 			if (!empty($show_empty)) {
198
-				$out.= '<option value="0">&nbsp;</option>';
198
+				$out .= '<option value="0">&nbsp;</option>';
199 199
 			}
200 200
 			$num = $this->db->num_rows($resql);
201 201
 			$i = 0;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 				{
206 206
 					$obj = $this->db->fetch_object($resql);
207 207
 					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
208
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
208
+					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
209 209
 					{
210 210
 						// Do nothing
211 211
 					}
@@ -217,56 +217,56 @@  discard block
 block discarded – undo
217 217
 							continue;
218 218
 						}
219 219
 
220
-						$labeltoshow=dol_trunc($obj->ref,18);
220
+						$labeltoshow = dol_trunc($obj->ref, 18);
221 221
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
222 222
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
223
-						$labeltoshow.=', '.dol_trunc($obj->title, $maxlength);
223
+						$labeltoshow .= ', '.dol_trunc($obj->title, $maxlength);
224 224
 						if ($obj->name)
225 225
 						{
226
-						    $labeltoshow.=' - '.$obj->name;
227
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
226
+						    $labeltoshow .= ' - '.$obj->name;
227
+						    if ($obj->name_alias) $labeltoshow .= ' ('.$obj->name_alias.')';
228 228
 						}
229 229
 
230
-						$disabled=0;
230
+						$disabled = 0;
231 231
 						if ($obj->fk_statut == 0)
232 232
 						{
233
-							$disabled=1;
234
-							$labeltoshow.=' - '.$langs->trans("Draft");
233
+							$disabled = 1;
234
+							$labeltoshow .= ' - '.$langs->trans("Draft");
235 235
 						}
236 236
 						else if ($obj->fk_statut == 2)
237 237
 						{
238
-							if ($discard_closed == 2) $disabled=1;
239
-							$labeltoshow.=' - '.$langs->trans("Closed");
238
+							if ($discard_closed == 2) $disabled = 1;
239
+							$labeltoshow .= ' - '.$langs->trans("Closed");
240 240
 						}
241
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
241
+						else if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
242 242
 						{
243
-							$disabled=1;
244
-							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
243
+							$disabled = 1;
244
+							$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
245 245
 						}
246 246
 
247 247
 						if (!empty($selected) && $selected == $obj->rowid)
248 248
 						{
249
-							$out.= '<option value="'.$obj->rowid.'" selected';
249
+							$out .= '<option value="'.$obj->rowid.'" selected';
250 250
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
251
-							$out.= '>'.$labeltoshow.'</option>';
251
+							$out .= '>'.$labeltoshow.'</option>';
252 252
 						}
253 253
 						else
254 254
 						{
255 255
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
256 256
 							{
257
-								$resultat='';
257
+								$resultat = '';
258 258
 							}
259 259
 							else
260 260
 							{
261
-								$resultat='<option value="'.$obj->rowid.'"';
262
-								if ($disabled) $resultat.=' disabled';
261
+								$resultat = '<option value="'.$obj->rowid.'"';
262
+								if ($disabled) $resultat .= ' disabled';
263 263
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
264 264
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
265
-								$resultat.='>';
266
-								$resultat.=$labeltoshow;
267
-								$resultat.='</option>';
265
+								$resultat .= '>';
266
+								$resultat .= $labeltoshow;
267
+								$resultat .= '</option>';
268 268
 							}
269
-							$out.= $resultat;
269
+							$out .= $resultat;
270 270
 
271 271
 							$outarray[] = array(
272 272
 								'key' => (int) $obj->rowid,
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 			$this->db->free($resql);
285 285
 
286 286
 			if (!$mode) {
287
-				if (empty($option_only)) $out.= '</select>';
287
+				if (empty($option_only)) $out .= '</select>';
288 288
 				if (empty($nooutput))
289 289
 				{
290 290
 				    print $out;
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 	 *  @param	User	$usertofilter	User object to use for filtering
321 321
 	 *	@return int         			Nbr of project if OK, <0 if KO
322 322
 	 */
323
-	function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showproject='all', $usertofilter=null)
323
+	function selectTasks($socid = -1, $selected = '', $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null)
324 324
 	{
325
-		global $user,$conf,$langs;
325
+		global $user, $conf, $langs;
326 326
 
327 327
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
328 328
 
@@ -331,53 +331,53 @@  discard block
 block discarded – undo
331 331
 			$usertofilter = $user;
332 332
 		}
333 333
 
334
-		$out='';
334
+		$out = '';
335 335
 
336 336
 		$hideunselectables = false;
337
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
337
+		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
338 338
 
339 339
 		if (empty($projectsListId))
340 340
 		{
341 341
 			if (empty($usertofilter->rights->projet->all->lire))
342 342
 			{
343
-				$projectstatic=new Project($this->db);
344
-				$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter,0,1);
343
+				$projectstatic = new Project($this->db);
344
+				$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
345 345
 			}
346 346
 		}
347 347
 
348 348
 		// Search all projects
349 349
 		$sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public,';
350
-		$sql.= ' s.nom as name';
351
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
352
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
353
-		$sql.= ' '.MAIN_DB_PREFIX.'projet_task as t';
354
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
355
-		$sql.= " AND t.fk_projet = p.rowid";
356
-		if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")";
357
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
359
-		$sql.= " ORDER BY p.ref, t.ref ASC";
360
-
361
-		$resql=$this->db->query($sql);
350
+		$sql .= ' s.nom as name';
351
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
352
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
353
+		$sql .= ' '.MAIN_DB_PREFIX.'projet_task as t';
354
+		$sql .= " WHERE p.entity IN (".getEntity('project').")";
355
+		$sql .= " AND t.fk_projet = p.rowid";
356
+		if ($projectsListId) $sql .= " AND p.rowid IN (".$projectsListId.")";
357
+		if ($socid == 0) $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
+		if ($socid > 0)  $sql .= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
359
+		$sql .= " ORDER BY p.ref, t.ref ASC";
360
+
361
+		$resql = $this->db->query($sql);
362 362
 		if ($resql)
363 363
 		{
364 364
 			// Use select2 selector
365
-			if (! empty($conf->use_javascript_ajax))
365
+			if (!empty($conf->use_javascript_ajax))
366 366
 			{
367
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
367
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
368 368
 	           	$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
369
-            	$out.=$comboenhancement;
370
-            	$morecss='minwidth200 maxwidth500';
369
+            	$out .= $comboenhancement;
370
+            	$morecss = 'minwidth200 maxwidth500';
371 371
 			}
372 372
 
373 373
 			if (empty($option_only)) {
374
-				$out.= '<select class="valignmiddle flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.$htmlname.'">';
374
+				$out .= '<select class="valignmiddle flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlname.'" name="'.$htmlname.'">';
375 375
 			}
376
-			if (! empty($show_empty)) {
377
-				$out.= '<option value="0" class="optiongrey">';
378
-				if (! is_numeric($show_empty)) $out.=$show_empty;
379
-				else $out.='&nbsp;';
380
-				$out.= '</option>';
376
+			if (!empty($show_empty)) {
377
+				$out .= '<option value="0" class="optiongrey">';
378
+				if (!is_numeric($show_empty)) $out .= $show_empty;
379
+				else $out .= '&nbsp;';
380
+				$out .= '</option>';
381 381
 			}
382 382
 			$num = $this->db->num_rows($resql);
383 383
 			$i = 0;
@@ -403,65 +403,65 @@  discard block
 block discarded – undo
403 403
 
404 404
 						if ($showproject == 'all')
405 405
 						{
406
-							$labeltoshow.=dol_trunc($obj->ref,18);     // Project ref
406
+							$labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
407 407
 							//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
408 408
 							//else $labeltoshow.=' ('.$langs->trans("Private").')';
409
-							$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
409
+							$labeltoshow .= ' '.dol_trunc($obj->title, $maxlength);
410 410
 
411
-							if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
411
+							if ($obj->name) $labeltoshow .= ' ('.$obj->name.')';
412 412
 
413
-							$disabled=0;
413
+							$disabled = 0;
414 414
 							if ($obj->fk_statut == Project::STATUS_DRAFT)
415 415
 							{
416
-								$disabled=1;
417
-								$labeltoshow.=' - '.$langs->trans("Draft");
416
+								$disabled = 1;
417
+								$labeltoshow .= ' - '.$langs->trans("Draft");
418 418
 							}
419 419
 							else if ($obj->fk_statut == Project::STATUS_CLOSED)
420 420
 							{
421
-								if ($discard_closed == 2) $disabled=1;
422
-								$labeltoshow.=' - '.$langs->trans("Closed");
421
+								if ($discard_closed == 2) $disabled = 1;
422
+								$labeltoshow .= ' - '.$langs->trans("Closed");
423 423
 							}
424
-							else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
424
+							else if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
425 425
 							{
426
-								$disabled=1;
427
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
426
+								$disabled = 1;
427
+								$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
428 428
 							}
429
-							$labeltoshow.=' - ';
429
+							$labeltoshow .= ' - ';
430 430
 						}
431 431
 
432 432
 						// Label for task
433
-						$labeltoshow.=$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength);
433
+						$labeltoshow .= $obj->tref.' '.dol_trunc($obj->tlabel, $maxlength);
434 434
 
435 435
 						if (!empty($selected) && $selected == $obj->rowid)
436 436
 						{
437
-							$out.= '<option value="'.$obj->rowid.'" selected';
437
+							$out .= '<option value="'.$obj->rowid.'" selected';
438 438
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
439
-							$out.= '>'.$labeltoshow.'</option>';
439
+							$out .= '>'.$labeltoshow.'</option>';
440 440
 						}
441 441
 						else
442 442
 						{
443 443
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
444 444
 							{
445
-								$resultat='';
445
+								$resultat = '';
446 446
 							}
447 447
 							else
448 448
 							{
449
-								$resultat='<option value="'.$obj->rowid.'"';
450
-								if ($disabled) $resultat.=' disabled';
449
+								$resultat = '<option value="'.$obj->rowid.'"';
450
+								if ($disabled) $resultat .= ' disabled';
451 451
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
452 452
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
453
-								$resultat.='>';
454
-								$resultat.=$labeltoshow;
455
-								$resultat.='</option>';
453
+								$resultat .= '>';
454
+								$resultat .= $labeltoshow;
455
+								$resultat .= '</option>';
456 456
 							}
457
-							$out.= $resultat;
457
+							$out .= $resultat;
458 458
 						}
459 459
 					}
460 460
 					$i++;
461 461
 				}
462 462
 			}
463 463
 			if (empty($option_only)) {
464
-				$out.= '</select>';
464
+				$out .= '</select>';
465 465
 			}
466 466
 
467 467
 			print $out;
@@ -488,17 +488,17 @@  discard block
 block discarded – undo
488 488
 	 *    @param	string		$projectkey			Equivalent key  to fk_projet for actual table_element
489 489
 	 *    @return	int|string						The HTML select list of element or '' if nothing or -1 if KO
490 490
 	 */
491
-	function select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2,$projectkey="fk_projet")
491
+	function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet")
492 492
 	{
493 493
         // phpcs:enable
494 494
 		global $conf, $langs;
495 495
 
496
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
496
+		if ($table_element == 'projet_task') return ''; // Special cas of element we never link to a project (already always done)
497 497
 
498
-		$linkedtothirdparty=false;
499
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) $linkedtothirdparty=true;
498
+		$linkedtothirdparty = false;
499
+		if (!in_array($table_element, array('don', 'expensereport_det', 'expensereport', 'loan', 'stock_mouvement', 'payment_salary', 'payment_various', 'chargesociales'))) $linkedtothirdparty = true;
500 500
 
501
-		$sqlfilter='';
501
+		$sqlfilter = '';
502 502
 
503 503
 		//print $table_element;
504 504
 		switch ($table_element)
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 				break;
522 522
 			case "actioncomm":
523 523
 				$sql = "SELECT t.id as rowid, t.label as ref";
524
-				$projectkey="fk_project";
524
+				$projectkey = "fk_project";
525 525
 				break;
526 526
 			case "expensereport":
527 527
 				return '';
@@ -537,10 +537,10 @@  discard block
 block discarded – undo
537 537
 			    break;
538 538
 			case 'stock_mouvement':
539 539
 				$sql = 'SELECT t.rowid, t.label as ref';
540
-				$projectkey='fk_origin';
540
+				$projectkey = 'fk_origin';
541 541
 				break;
542 542
 			case "payment_salary":
543
-				$sql = "SELECT t.rowid, t.num_payment as ref";	// TODO In a future fill and use real ref field
543
+				$sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
544 544
 				break;
545 545
 			case "payment_various":
546 546
 				$sql = "SELECT t.rowid, t.num_payment as ref";
@@ -550,40 +550,40 @@  discard block
 block discarded – undo
550 550
 				$sql = "SELECT t.rowid, t.ref";
551 551
 				break;
552 552
 		}
553
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
554
-		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
556
-		$sql.= " WHERE ".$projectkey." is null";
557
-		if (! empty($socid) && $linkedtothirdparty)
553
+		if ($linkedtothirdparty) $sql .= ", s.nom as name";
554
+		$sql .= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
+		if ($linkedtothirdparty) $sql .= ", ".MAIN_DB_PREFIX."societe as s";
556
+		$sql .= " WHERE ".$projectkey." is null";
557
+		if (!empty($socid) && $linkedtothirdparty)
558 558
 		{
559
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
560
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
559
+		    if (is_numeric($socid)) $sql .= " AND t.fk_soc=".$socid;
560
+		    else $sql .= " AND t.fk_soc IN (".$socid.")";
561 561
 		}
562
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
563
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
564
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
565
-		$sql.= " ORDER BY ref DESC";
562
+		if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) $sql .= ' AND t.entity IN ('.getEntity('project').')';
563
+		if ($linkedtothirdparty) $sql .= " AND s.rowid = t.fk_soc";
564
+		if ($sqlfilter) $sql .= " AND ".$sqlfilter;
565
+		$sql .= " ORDER BY ref DESC";
566 566
 
567 567
 		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
568
-		$resql=$this->db->query($sql);
568
+		$resql = $this->db->query($sql);
569 569
 		if ($resql)
570 570
 		{
571 571
 			$num = $this->db->num_rows($resql);
572 572
 			$i = 0;
573 573
 			if ($num > 0)
574 574
 			{
575
-				$sellist = '<select class="flat elementselect css'.$table_element.($morecss?' '.$morecss:'').'" name="elementselect">';
576
-				$sellist .='<option value="-1"></option>';
575
+				$sellist = '<select class="flat elementselect css'.$table_element.($morecss ? ' '.$morecss : '').'" name="elementselect">';
576
+				$sellist .= '<option value="-1"></option>';
577 577
 				while ($i < $num)
578 578
 				{
579 579
 					$obj = $this->db->fetch_object($resql);
580
-					$ref=$obj->ref?$obj->ref:$obj->rowid;
581
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
582
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
583
-					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
580
+					$ref = $obj->ref ? $obj->ref : $obj->rowid;
581
+					if (!empty($obj->ref_supplier)) $ref .= ' ('.$obj->ref_supplier.')';
582
+					if (!empty($obj->name)) $ref .= ' - '.$obj->name;
583
+					$sellist .= '<option value="'.$obj->rowid.'">'.$ref.'</option>';
584 584
 					$i++;
585 585
 				}
586
-				$sellist .='</select>';
586
+				$sellist .= '</select>';
587 587
 			}
588 588
 			/*else
589 589
 			{
@@ -598,9 +598,9 @@  discard block
 block discarded – undo
598 598
 		else
599 599
 		{
600 600
 			dol_print_error($this->db);
601
-			$this->error=$this->db->lasterror();
602
-			$this->errors[]=$this->db->lasterror();
603
-			dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
601
+			$this->error = $this->db->lasterror();
602
+			$this->errors[] = $this->db->lasterror();
603
+			dol_syslog(get_class($this)."::select_element ".$this->error, LOG_ERR);
604 604
 			return -1;
605 605
 		}
606 606
 	}
@@ -618,38 +618,38 @@  discard block
 block discarded – undo
618 618
 	 *    @param   string      $morecss            Add more css
619 619
 	 *    @return  int|string                      The HTML select list of element or '' if nothing or -1 if KO
620 620
 	 */
621
-	function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='')
621
+	function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '')
622 622
 	{
623 623
 		global $conf, $langs;
624 624
 
625 625
 		$sql = "SELECT rowid, code, label, percent";
626
-		$sql.= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
627
-		$sql.= " WHERE active = 1";
628
-		$sql.= " ORDER BY position";
626
+		$sql .= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
627
+		$sql .= " WHERE active = 1";
628
+		$sql .= " ORDER BY position";
629 629
 
630
-		$resql=$this->db->query($sql);
630
+		$resql = $this->db->query($sql);
631 631
 		if ($resql)
632 632
 		{
633 633
 			$num = $this->db->num_rows($resql);
634 634
 			$i = 0;
635 635
 			if ($num > 0)
636 636
 			{
637
-				$sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
637
+				$sellist = '<select class="flat oppstatus'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
638 638
 				if ($showempty) {
639 639
                     // Without &nbsp, strange move of screen when switching value
640
-                    $sellist.= '<option value="-1">&nbsp;</option>';
640
+                    $sellist .= '<option value="-1">&nbsp;</option>';
641 641
                 }
642 642
 				if ($showallnone) {
643
-                    $sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>-- '.$langs->trans("OnlyOpportunitiesShort").' --</option>';
644
-				    $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>-- '.$langs->trans("OpenedOpportunitiesShort").' --</option>';
645
-				    $sellist.= '<option value="notopenedopp"'.($preselected == 'notopenedopp'?' selected="selected"':'').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").' --</option>';
646
-				    $sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>-- '.$langs->trans("NotAnOpportunityShort").' --</option>';
643
+                    $sellist .= '<option value="all"'.($preselected == 'all' ? ' selected="selected"' : '').'>-- '.$langs->trans("OnlyOpportunitiesShort").' --</option>';
644
+				    $sellist .= '<option value="openedopp"'.($preselected == 'openedopp' ? ' selected="selected"' : '').'>-- '.$langs->trans("OpenedOpportunitiesShort").' --</option>';
645
+				    $sellist .= '<option value="notopenedopp"'.($preselected == 'notopenedopp' ? ' selected="selected"' : '').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").' --</option>';
646
+				    $sellist .= '<option value="none"'.($preselected == 'none' ? ' selected="selected"' : '').'>-- '.$langs->trans("NotAnOpportunityShort").' --</option>';
647 647
                 }
648 648
 				while ($i < $num)
649 649
 				{
650 650
 					$obj = $this->db->fetch_object($resql);
651 651
 
652
-					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
652
+					$sellist .= '<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
653 653
 					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
654 654
 					$sellist .= '>';
655 655
 					if ($useshortlabel)
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 					else
660 660
 					{
661 661
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
662
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
662
+						if ($showpercent) $finallabel .= ' ('.$obj->percent.'%)';
663 663
 					}
664 664
 					$sellist .= $finallabel;
665
-					$sellist .='</option>';
665
+					$sellist .= '</option>';
666 666
 					$i++;
667 667
 				}
668
-				$sellist .='</select>';
668
+				$sellist .= '</select>';
669 669
 			}
670 670
 			/*else
671 671
 			{
@@ -679,9 +679,9 @@  discard block
 block discarded – undo
679 679
 		}
680 680
 		else
681 681
 		{
682
-			$this->error=$this->db->lasterror();
683
-			$this->errors[]=$this->db->lasterror();
684
-			dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
682
+			$this->error = $this->db->lasterror();
683
+			$this->errors[] = $this->db->lasterror();
684
+			dol_syslog(get_class($this)."::selectOpportunityStatus ".$this->error, LOG_ERR);
685 685
 			return -1;
686 686
 		}
687 687
 	}
Please login to merge, or discard this patch.
Braces   +123 added lines, -69 removed lines patch added patch discarded remove patch
@@ -97,8 +97,7 @@  discard block
 block discarded – undo
97 97
 			));
98 98
 
99 99
 			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
100
-		}
101
-		else
100
+		} else
102 101
 		{
103 102
 			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
104 103
 		}
@@ -106,7 +105,9 @@  discard block
 block discarded – undo
106 105
 		{
107 106
 			if (class_exists('Form'))
108 107
 			{
109
-				if (empty($form)) $form=new Form($this->db);
108
+				if (empty($form)) {
109
+				    $form=new Form($this->db);
110
+				}
110 111
 				$out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
111 112
 			}
112 113
 		}
@@ -115,8 +116,9 @@  discard block
 block discarded – undo
115 116
 		{
116 117
 		    print $out;
117 118
 		    return '';
119
+		} else {
120
+		    return $out;
118 121
 		}
119
-		else return $out;
120 122
 	}
121 123
 
122 124
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -147,13 +149,17 @@  discard block
 block discarded – undo
147 149
 
148 150
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
149 151
 
150
-		if (empty($htmlid)) $htmlid = $htmlname;
152
+		if (empty($htmlid)) {
153
+		    $htmlid = $htmlname;
154
+		}
151 155
 
152 156
 		$out='';
153 157
 		$outarray=array();
154 158
 
155 159
 		$hideunselectables = false;
156
-		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
160
+		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) {
161
+		    $hideunselectables = true;
162
+		}
157 163
 
158 164
 		$projectsListId = false;
159 165
 		if (empty($user->rights->projet->all->lire))
@@ -166,17 +172,26 @@  discard block
 block discarded – undo
166 172
 		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
167 173
 		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
168 174
 		$sql.= " WHERE p.entity IN (".getEntity('project').")";
169
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
170
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
175
+		if ($projectsListId !== false) {
176
+		    $sql.= " AND p.rowid IN (".$projectsListId.")";
177
+		}
178
+		if ($socid == 0) {
179
+		    $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
180
+		}
171 181
 		if ($socid > 0)
172 182
 		{
173
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
174
-		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
183
+		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
184
+		        $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
185
+		    } else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') {
186
+		        // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
175 187
 		    {
176 188
 		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
177 189
 		    }
190
+		    }
191
+		}
192
+		if (!empty($filterkey)) {
193
+		    $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
178 194
 		}
179
-		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
180 195
 		$sql.= " ORDER BY p.ref ASC";
181 196
 
182 197
 		$resql=$this->db->query($sql);
@@ -208,12 +223,13 @@  discard block
 block discarded – undo
208 223
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
209 224
 					{
210 225
 						// Do nothing
211
-					}
212
-					else
226
+					} else
213 227
 					{
214
-						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) // We discard closed except if selected
228
+						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) {
229
+						    // We discard closed except if selected
215 230
 						{
216 231
 							$i++;
232
+						}
217 233
 							continue;
218 234
 						}
219 235
 
@@ -224,7 +240,9 @@  discard block
 block discarded – undo
224 240
 						if ($obj->name)
225 241
 						{
226 242
 						    $labeltoshow.=' - '.$obj->name;
227
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
243
+						    if ($obj->name_alias) {
244
+						        $labeltoshow.=' ('.$obj->name_alias.')';
245
+						    }
228 246
 						}
229 247
 
230 248
 						$disabled=0;
@@ -232,13 +250,13 @@  discard block
 block discarded – undo
232 250
 						{
233 251
 							$disabled=1;
234 252
 							$labeltoshow.=' - '.$langs->trans("Draft");
235
-						}
236
-						else if ($obj->fk_statut == 2)
253
+						} else if ($obj->fk_statut == 2)
237 254
 						{
238
-							if ($discard_closed == 2) $disabled=1;
255
+							if ($discard_closed == 2) {
256
+							    $disabled=1;
257
+							}
239 258
 							$labeltoshow.=' - '.$langs->trans("Closed");
240
-						}
241
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
259
+						} else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
242 260
 						{
243 261
 							$disabled=1;
244 262
 							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
@@ -249,17 +267,17 @@  discard block
 block discarded – undo
249 267
 							$out.= '<option value="'.$obj->rowid.'" selected';
250 268
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
251 269
 							$out.= '>'.$labeltoshow.'</option>';
252
-						}
253
-						else
270
+						} else
254 271
 						{
255 272
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
256 273
 							{
257 274
 								$resultat='';
258
-							}
259
-							else
275
+							} else
260 276
 							{
261 277
 								$resultat='<option value="'.$obj->rowid.'"';
262
-								if ($disabled) $resultat.=' disabled';
278
+								if ($disabled) {
279
+								    $resultat.=' disabled';
280
+								}
263 281
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
264 282
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
265 283
 								$resultat.='>';
@@ -284,18 +302,20 @@  discard block
 block discarded – undo
284 302
 			$this->db->free($resql);
285 303
 
286 304
 			if (!$mode) {
287
-				if (empty($option_only)) $out.= '</select>';
305
+				if (empty($option_only)) {
306
+				    $out.= '</select>';
307
+				}
288 308
 				if (empty($nooutput))
289 309
 				{
290 310
 				    print $out;
291 311
 				    return '';
312
+				} else {
313
+				    return $out;
292 314
 				}
293
-				else return $out;
294 315
 			} else {
295 316
 				return $outarray;
296 317
 			}
297
-		}
298
-		else
318
+		} else
299 319
 		{
300 320
 			dol_print_error($this->db);
301 321
 			return -1;
@@ -334,7 +354,9 @@  discard block
 block discarded – undo
334 354
 		$out='';
335 355
 
336 356
 		$hideunselectables = false;
337
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
357
+		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
358
+		    $hideunselectables = true;
359
+		}
338 360
 
339 361
 		if (empty($projectsListId))
340 362
 		{
@@ -353,9 +375,15 @@  discard block
 block discarded – undo
353 375
 		$sql.= ' '.MAIN_DB_PREFIX.'projet_task as t';
354 376
 		$sql.= " WHERE p.entity IN (".getEntity('project').")";
355 377
 		$sql.= " AND t.fk_projet = p.rowid";
356
-		if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")";
357
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
378
+		if ($projectsListId) {
379
+		    $sql.= " AND p.rowid IN (".$projectsListId.")";
380
+		}
381
+		if ($socid == 0) {
382
+		    $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
383
+		}
384
+		if ($socid > 0) {
385
+		    $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
386
+		}
359 387
 		$sql.= " ORDER BY p.ref, t.ref ASC";
360 388
 
361 389
 		$resql=$this->db->query($sql);
@@ -375,8 +403,11 @@  discard block
 block discarded – undo
375 403
 			}
376 404
 			if (! empty($show_empty)) {
377 405
 				$out.= '<option value="0" class="optiongrey">';
378
-				if (! is_numeric($show_empty)) $out.=$show_empty;
379
-				else $out.='&nbsp;';
406
+				if (! is_numeric($show_empty)) {
407
+				    $out.=$show_empty;
408
+				} else {
409
+				    $out.='&nbsp;';
410
+				}
380 411
 				$out.= '</option>';
381 412
 			}
382 413
 			$num = $this->db->num_rows($resql);
@@ -390,8 +421,7 @@  discard block
 block discarded – undo
390 421
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire))
391 422
 					{
392 423
 						// Do nothing
393
-					}
394
-					else
424
+					} else
395 425
 					{
396 426
 						if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED)
397 427
 						{
@@ -408,20 +438,22 @@  discard block
 block discarded – undo
408 438
 							//else $labeltoshow.=' ('.$langs->trans("Private").')';
409 439
 							$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
410 440
 
411
-							if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
441
+							if ($obj->name) {
442
+							    $labeltoshow.=' ('.$obj->name.')';
443
+							}
412 444
 
413 445
 							$disabled=0;
414 446
 							if ($obj->fk_statut == Project::STATUS_DRAFT)
415 447
 							{
416 448
 								$disabled=1;
417 449
 								$labeltoshow.=' - '.$langs->trans("Draft");
418
-							}
419
-							else if ($obj->fk_statut == Project::STATUS_CLOSED)
450
+							} else if ($obj->fk_statut == Project::STATUS_CLOSED)
420 451
 							{
421
-								if ($discard_closed == 2) $disabled=1;
452
+								if ($discard_closed == 2) {
453
+								    $disabled=1;
454
+								}
422 455
 								$labeltoshow.=' - '.$langs->trans("Closed");
423
-							}
424
-							else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
456
+							} else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
425 457
 							{
426 458
 								$disabled=1;
427 459
 								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
@@ -437,17 +469,17 @@  discard block
 block discarded – undo
437 469
 							$out.= '<option value="'.$obj->rowid.'" selected';
438 470
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
439 471
 							$out.= '>'.$labeltoshow.'</option>';
440
-						}
441
-						else
472
+						} else
442 473
 						{
443 474
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
444 475
 							{
445 476
 								$resultat='';
446
-							}
447
-							else
477
+							} else
448 478
 							{
449 479
 								$resultat='<option value="'.$obj->rowid.'"';
450
-								if ($disabled) $resultat.=' disabled';
480
+								if ($disabled) {
481
+								    $resultat.=' disabled';
482
+								}
451 483
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
452 484
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
453 485
 								$resultat.='>';
@@ -468,8 +500,7 @@  discard block
 block discarded – undo
468 500
 
469 501
 			$this->db->free($resql);
470 502
 			return $num;
471
-		}
472
-		else
503
+		} else
473 504
 		{
474 505
 			dol_print_error($this->db);
475 506
 			return -1;
@@ -493,10 +524,15 @@  discard block
 block discarded – undo
493 524
         // phpcs:enable
494 525
 		global $conf, $langs;
495 526
 
496
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
527
+		if ($table_element == 'projet_task') {
528
+		    return '';
529
+		}
530
+		// Special cas of element we never link to a project (already always done)
497 531
 
498 532
 		$linkedtothirdparty=false;
499
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) $linkedtothirdparty=true;
533
+		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) {
534
+		    $linkedtothirdparty=true;
535
+		}
500 536
 
501 537
 		$sqlfilter='';
502 538
 
@@ -550,18 +586,31 @@  discard block
 block discarded – undo
550 586
 				$sql = "SELECT t.rowid, t.ref";
551 587
 				break;
552 588
 		}
553
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
589
+		if ($linkedtothirdparty) {
590
+		    $sql.=", s.nom as name";
591
+		}
554 592
 		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
593
+		if ($linkedtothirdparty) {
594
+		    $sql.=", ".MAIN_DB_PREFIX."societe as s";
595
+		}
556 596
 		$sql.= " WHERE ".$projectkey." is null";
557 597
 		if (! empty($socid) && $linkedtothirdparty)
558 598
 		{
559
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
560
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
599
+		    if (is_numeric($socid)) {
600
+		        $sql.= " AND t.fk_soc=".$socid;
601
+		    } else {
602
+		        $sql.= " AND t.fk_soc IN (".$socid.")";
603
+		    }
604
+		}
605
+		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) {
606
+		    $sql.= ' AND t.entity IN ('.getEntity('project').')';
607
+		}
608
+		if ($linkedtothirdparty) {
609
+		    $sql.=" AND s.rowid = t.fk_soc";
610
+		}
611
+		if ($sqlfilter) {
612
+		    $sql.= " AND ".$sqlfilter;
561 613
 		}
562
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
563
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
564
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
565 614
 		$sql.= " ORDER BY ref DESC";
566 615
 
567 616
 		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
@@ -578,8 +627,12 @@  discard block
 block discarded – undo
578 627
 				{
579 628
 					$obj = $this->db->fetch_object($resql);
580 629
 					$ref=$obj->ref?$obj->ref:$obj->rowid;
581
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
582
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
630
+					if (! empty($obj->ref_supplier)) {
631
+					    $ref.=' ('.$obj->ref_supplier.')';
632
+					}
633
+					if (! empty($obj->name)) {
634
+					    $ref.=' - '.$obj->name;
635
+					}
583 636
 					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
584 637
 					$i++;
585 638
 				}
@@ -594,8 +647,7 @@  discard block
 block discarded – undo
594 647
 			$this->db->free($resql);
595 648
 
596 649
 			return $sellist;
597
-		}
598
-		else
650
+		} else
599 651
 		{
600 652
 			dol_print_error($this->db);
601 653
 			$this->error=$this->db->lasterror();
@@ -650,16 +702,19 @@  discard block
 block discarded – undo
650 702
 					$obj = $this->db->fetch_object($resql);
651 703
 
652 704
 					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
653
-					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
705
+					if ($obj->rowid == $preselected) {
706
+					    $sellist .= ' selected="selected"';
707
+					}
654 708
 					$sellist .= '>';
655 709
 					if ($useshortlabel)
656 710
 					{
657 711
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
658
-					}
659
-					else
712
+					} else
660 713
 					{
661 714
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
662
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
715
+						if ($showpercent) {
716
+						    $finallabel.= ' ('.$obj->percent.'%)';
717
+						}
663 718
 					}
664 719
 					$sellist .= $finallabel;
665 720
 					$sellist .='</option>';
@@ -676,8 +731,7 @@  discard block
 block discarded – undo
676 731
 			$this->db->free($resql);
677 732
 
678 733
 			return $sellist;
679
-		}
680
-		else
734
+		} else
681 735
 		{
682 736
 			$this->error=$this->db->lasterror();
683 737
 			$this->errors[]=$this->db->lasterror();
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formother.class.php 3 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
     private $db;
41 41
 
42 42
     /**
43
-	 * @var string Error code (or message)
44
-	 */
45
-	public $error;
43
+     * @var string Error code (or message)
44
+     */
45
+    public $error;
46 46
 
47 47
 
48 48
     /**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         $sql = "SELECT rowid, label";
74 74
         $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
75 75
         $sql.= " WHERE type = '".$type."'";
76
-		if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user;
76
+        if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user;
77 77
         $sql.= " ORDER BY rowid";
78 78
         $result = $this->db->query($sql);
79 79
         if ($result)
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         $sql.= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
180 180
         $sql.= " ORDER BY country, e.organization ASC, e.code ASC";
181 181
 
182
-    	dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
182
+        dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
183 183
         $resql=$this->db->query($sql);
184 184
         if ($resql)
185 185
         {
@@ -230,50 +230,50 @@  discard block
 block discarded – undo
230 230
     function select_revenue_stamp($selected='', $htmlname='revenuestamp', $country_code='')
231 231
     {
232 232
         // phpcs:enable
233
-    	global $langs;
234
-
235
-    	$out='';
236
-
237
-    	$sql = "SELECT r.taux, r.revenuestamp_type";
238
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
239
-    	$sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
240
-    	$sql.= " AND c.code = '".$country_code."'";
241
-
242
-    	dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
243
-    	$resql=$this->db->query($sql);
244
-    	if ($resql)
245
-    	{
246
-    		$out.='<select class="flat" name="'.$htmlname.'">';
247
-    		$num = $this->db->num_rows($resql);
248
-    		$i = 0;
249
-    		$out.='<option value="0">&nbsp;</option>'."\n";
250
-    		if ($num)
251
-    		{
252
-    			while ($i < $num)
253
-    			{
254
-    				$obj = $this->db->fetch_object($resql);
255
-    				if (($selected && $selected == $obj->taux) || $num == 1)
256
-    				{
257
-    					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
258
-    				}
259
-    				else
260
-    				{
261
-    					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
262
-    					//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
263
-    				}
264
-    				$out.=$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
265
-    				$out.='</option>';
266
-    				$i++;
267
-    			}
268
-    		}
269
-    		$out.='</select>';
270
-    		return $out;
271
-    	}
272
-    	else
273
-    	{
274
-    		dol_print_error($this->db);
275
-    		return '';
276
-    	}
233
+        global $langs;
234
+
235
+        $out='';
236
+
237
+        $sql = "SELECT r.taux, r.revenuestamp_type";
238
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
239
+        $sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
240
+        $sql.= " AND c.code = '".$country_code."'";
241
+
242
+        dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
243
+        $resql=$this->db->query($sql);
244
+        if ($resql)
245
+        {
246
+            $out.='<select class="flat" name="'.$htmlname.'">';
247
+            $num = $this->db->num_rows($resql);
248
+            $i = 0;
249
+            $out.='<option value="0">&nbsp;</option>'."\n";
250
+            if ($num)
251
+            {
252
+                while ($i < $num)
253
+                {
254
+                    $obj = $this->db->fetch_object($resql);
255
+                    if (($selected && $selected == $obj->taux) || $num == 1)
256
+                    {
257
+                        $out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
258
+                    }
259
+                    else
260
+                    {
261
+                        $out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
262
+                        //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
263
+                    }
264
+                    $out.=$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
265
+                    $out.='</option>';
266
+                    $i++;
267
+                }
268
+            }
269
+            $out.='</select>';
270
+            return $out;
271
+        }
272
+        else
273
+        {
274
+            dol_print_error($this->db);
275
+            return '';
276
+        }
277 277
     }
278 278
 
279 279
 
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
         }
369 369
         if ($nocateg)
370 370
         {
371
-        	$langs->load("categories");
372
-        	$moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>';
371
+            $langs->load("categories");
372
+            $moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>';
373 373
         }
374 374
         $moreforfilter.='</select>';
375 375
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
             $comboenhancement = ajax_combobox($htmlname);
405 405
             if ($comboenhancement)
406 406
             {
407
-            	$out.=$comboenhancement;
407
+                $out.=$comboenhancement;
408 408
             }
409 409
         }
410 410
         // Select each sales and print them in a select input
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
             $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
427 427
             $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
428 428
         }
429
-	    $sql_usr.= " ORDER BY statut DESC, lastname ASC";  // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
429
+        $sql_usr.= " ORDER BY statut DESC, lastname ASC";  // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
430 430
         //print $sql_usr;exit;
431 431
 
432 432
         $resql_usr = $this->db->query($sql_usr);
@@ -450,18 +450,18 @@  discard block
 block discarded – undo
450 450
                 }
451 451
                 if ($showstatus >= 0)
452 452
                 {
453
-					if ($obj_usr->statut == 1 && $showstatus == 1)
454
-					{
455
-						$out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
456
-	                	$moreinfo++;
457
-					}
458
-					if ($obj_usr->statut == 0)
459
-					{
460
-						$out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
461
-                		$moreinfo++;
462
-					}
463
-				}
464
-				$out.=($moreinfo?')':'');
453
+                    if ($obj_usr->statut == 1 && $showstatus == 1)
454
+                    {
455
+                        $out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
456
+                        $moreinfo++;
457
+                    }
458
+                    if ($obj_usr->statut == 0)
459
+                    {
460
+                        $out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
461
+                        $moreinfo++;
462
+                    }
463
+                }
464
+                $out.=($moreinfo?')':'');
465 465
                 $out.='</option>';
466 466
             }
467 467
             $this->db->free($resql_usr);
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
      * 	@param	int		$mode					0=Return list of tasks and their projects, 1=Return projects and tasks if exists
487 487
      *  @param  int		$useempty       		0=Allow empty values
488 488
      *  @param	int		$disablechildoftaskid	1=Disable task that are child of the provided task id
489
-	 *  @param	string	$filteronprojstatus		Filter on project status ('-1'=no filter, '0,1'=Draft+Validated status)
489
+     *  @param	string	$filteronprojstatus		Filter on project status ('-1'=no filter, '0,1'=Draft+Validated status)
490 490
      *  @param	string	$morecss				More css
491 491
      *  @return	void
492 492
      */
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
         $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode, '', $filteronprojstatus);
502 502
         if ($tasksarray)
503 503
         {
504
-        	print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
504
+            print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
505 505
             if ($useempty) print '<option value="0">&nbsp;</option>';
506 506
             $j=0;
507 507
             $level=0;
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
         $numlines=count($lines);
538 538
         for ($i = 0 ; $i < $numlines ; $i++)
539 539
         {
540
-        	if ($lines[$i]->fk_parent == $parent)
540
+            if ($lines[$i]->fk_parent == $parent)
541 541
             {
542 542
                 $var = !$var;
543 543
 
544
-				//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id);		// $lines[$i]->id may be empty if project has no lines
544
+                //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id);		// $lines[$i]->id may be empty if project has no lines
545 545
 
546 546
                 // Break on a new project
547 547
                 if ($parent == 0)	// We are on a task at first level
@@ -574,13 +574,13 @@  discard block
 block discarded – undo
574 574
                 // Print task
575 575
                 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
576 576
                 {
577
-                	// Check if we must disable entry
578
-                	$disabled=0;
579
-                	if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
580
-                	{
581
-               			$disabled++;
582
-               			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
583
-                	}
577
+                    // Check if we must disable entry
578
+                    $disabled=0;
579
+                    if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
580
+                    {
581
+                            $disabled++;
582
+                            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
583
+                    }
584 584
 
585 585
                     print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
586 586
                     if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
@@ -623,14 +623,14 @@  discard block
 block discarded – undo
623 623
      */
624 624
     static function showColor($color, $textifnotdefined='')
625 625
     {
626
-    	$textcolor='FFF';
627
-    	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
628
-    	if(colorIsLight($color)) $textcolor='000';
626
+        $textcolor='FFF';
627
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
628
+        if(colorIsLight($color)) $textcolor='000';
629 629
 
630
-    	$color = colorArrayToHex(colorStringToArray($color,array()),'');
630
+        $color = colorArrayToHex(colorStringToArray($color,array()),'');
631 631
 
632
-		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.'">';
633
-		else print $textifnotdefined;
632
+        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.'">';
633
+        else print $textifnotdefined;
634 634
     }
635 635
 
636 636
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
     function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='')
650 650
     {
651 651
         // phpcs:enable
652
-    	print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
652
+        print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
653 653
     }
654 654
 
655 655
     /**
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
      */
667 667
     static function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='')
668 668
     {
669
-	    // Deprecation warning
670
-	    if ($form_name) {
671
-		    dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING);
672
-	    }
669
+        // Deprecation warning
670
+        if ($form_name) {
671
+            dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING);
672
+        }
673 673
 
674 674
         global $langs,$conf;
675 675
 
@@ -680,9 +680,9 @@  discard block
 block discarded – undo
680 680
             $langs->load("other");
681 681
             if (empty($conf->dol_use_jmobile))
682 682
             {
683
-	            $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
684
-	            $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
685
-	            $out.= '<script type="text/javascript">
683
+                $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
684
+                $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
685
+                $out.= '<script type="text/javascript">
686 686
 	             jQuery(document).ready(function(){
687 687
 	                $(\'#colorpicker'.$prefix.'\').jPicker( {
688 688
 	                window: {
@@ -726,9 +726,9 @@  discard block
 block discarded – undo
726 726
         {
727 727
             if (empty($conf->dol_use_jmobile))
728 728
             {
729
-	        	$out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
730
-	            $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
731
-	            $out.= '<script type="text/javascript">
729
+                $out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
730
+                $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
731
+                $out.= '<script type="text/javascript">
732 732
 	             jQuery(document).ready(function(){
733 733
 	                 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
734 734
 	                     size: 14,
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
         $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
930 930
         if($useempty)
931 931
         {
932
-        	$selected_html='';
932
+            $selected_html='';
933 933
             if ($selected == '') $selected_html = ' selected';
934 934
             $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
935 935
         }
@@ -1028,55 +1028,55 @@  discard block
 block discarded – undo
1028 1028
         $boxidactivatedforuser=array();
1029 1029
         foreach($boxactivated as $box)
1030 1030
         {
1031
-        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id;	// We keep only boxes to show for user
1031
+            if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id;	// We keep only boxes to show for user
1032 1032
         }
1033 1033
 
1034 1034
         // Define selectboxlist
1035 1035
         $arrayboxtoactivatelabel=array();
1036 1036
         if (! empty($user->conf->$confuserzone))
1037 1037
         {
1038
-        	$boxorder='';
1039
-        	$langs->load("boxes");	// Load label of boxes
1040
-        	foreach($boxactivated as $box)
1041
-        	{
1042
-        		if (! empty($boxidactivatedforuser[$box->id])) continue;	// Already visible for user
1043
-        		$label=$langs->transnoentitiesnoconv($box->boxlabel);
1044
-        		//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1045
-        		if (preg_match('/graph/',$box->class) && $conf->browser->layout != 'phone')
1046
-        		{
1047
-        			$label=$label.' <span class="fa fa-bar-chart"></span>';
1048
-        		}
1049
-        		$arrayboxtoactivatelabel[$box->id]=$label;			// We keep only boxes not shown for user, to show into combo list
1050
-        	}
1038
+            $boxorder='';
1039
+            $langs->load("boxes");	// Load label of boxes
1040
+            foreach($boxactivated as $box)
1041
+            {
1042
+                if (! empty($boxidactivatedforuser[$box->id])) continue;	// Already visible for user
1043
+                $label=$langs->transnoentitiesnoconv($box->boxlabel);
1044
+                //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1045
+                if (preg_match('/graph/',$box->class) && $conf->browser->layout != 'phone')
1046
+                {
1047
+                    $label=$label.' <span class="fa fa-bar-chart"></span>';
1048
+                }
1049
+                $arrayboxtoactivatelabel[$box->id]=$label;			// We keep only boxes not shown for user, to show into combo list
1050
+            }
1051 1051
             foreach($boxidactivatedforuser as $boxid)
1052
-        	{
1053
-       			if (empty($boxorder)) $boxorder.='A:';
1054
-  				$boxorder.=$boxid.',';
1055
-        	}
1056
-
1057
-        	//var_dump($boxidactivatedforuser);
1058
-
1059
-        	// Class Form must have been already loaded
1060
-        	$selectboxlist.='<!-- Form with select box list -->'."\n";
1061
-			$selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1062
-			$selectboxlist.='<input type="hidden" name="addbox" value="addbox">';
1063
-			$selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">';
1064
-			$selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1065
-			$selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1066
-			$selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1052
+            {
1053
+                    if (empty($boxorder)) $boxorder.='A:';
1054
+                    $boxorder.=$boxid.',';
1055
+            }
1056
+
1057
+            //var_dump($boxidactivatedforuser);
1058
+
1059
+            // Class Form must have been already loaded
1060
+            $selectboxlist.='<!-- Form with select box list -->'."\n";
1061
+            $selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1062
+            $selectboxlist.='<input type="hidden" name="addbox" value="addbox">';
1063
+            $selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">';
1064
+            $selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1065
+            $selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1066
+            $selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1067 1067
             if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1068 1068
             $selectboxlist.='</form>';
1069 1069
             if (! empty($conf->use_javascript_ajax))
1070 1070
             {
1071
-            	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
1072
-            	$selectboxlist.=ajax_combobox("boxcombo");
1071
+                include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
1072
+                $selectboxlist.=ajax_combobox("boxcombo");
1073 1073
             }
1074 1074
         }
1075 1075
 
1076 1076
         // Javascript code for dynamic actions
1077 1077
         if (! empty($conf->use_javascript_ajax))
1078 1078
         {
1079
-	        $selectboxlist.='<script type="text/javascript" language="javascript">
1079
+            $selectboxlist.='<script type="text/javascript" language="javascript">
1080 1080
 
1081 1081
 	        // To update list of activated boxes
1082 1082
 	        function updateBoxOrder(closing) {
@@ -1115,8 +1115,8 @@  discard block
 block discarded – undo
1115 1115
 	        			window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid;
1116 1116
 	                }
1117 1117
 	        	});';
1118
-	        	if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1119
-	        	$selectboxlist.='
1118
+                if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1119
+                $selectboxlist.='
1120 1120
 
1121 1121
 	        	jQuery("#boxhalfleft, #boxhalfright").sortable({
1122 1122
 	    	    	handle: \'.boxhandle\',
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 
1142 1142
         	});'."\n";
1143 1143
 
1144
-	        $selectboxlist.='</script>'."\n";
1144
+            $selectboxlist.='</script>'."\n";
1145 1145
         }
1146 1146
 
1147 1147
         // Define boxlista and boxlistb
@@ -1149,10 +1149,10 @@  discard block
 block discarded – undo
1149 1149
 
1150 1150
         if ($nbboxactivated)
1151 1151
         {
1152
-        	// Load translation files required by the page
1152
+            // Load translation files required by the page
1153 1153
             $langs->loadLangs(array("boxes","projects"));
1154 1154
 
1155
-        	$emptybox=new ModeleBoxes($db);
1155
+            $emptybox=new ModeleBoxes($db);
1156 1156
 
1157 1157
             $boxlista.="\n<!-- Box left container -->\n";
1158 1158
 
@@ -1163,9 +1163,9 @@  discard block
 block discarded – undo
1163 1163
             $ii=0;
1164 1164
             foreach ($boxactivated as $key => $box)
1165 1165
             {
1166
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1167
-				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
1168
-            	if (preg_match('/^A/i',$box->box_order)) // column A
1166
+                if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1167
+                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
1168
+                if (preg_match('/^A/i',$box->box_order)) // column A
1169 1169
                 {
1170 1170
                     $ii++;
1171 1171
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
@@ -1178,10 +1178,10 @@  discard block
 block discarded – undo
1178 1178
 
1179 1179
             if ($conf->browser->layout != 'phone')
1180 1180
             {
1181
-            	$emptybox->box_id='A';
1182
-            	$emptybox->info_box_head=array();
1183
-            	$emptybox->info_box_contents=array();
1184
-            	$boxlista.= $emptybox->outputBox(array(),array());
1181
+                $emptybox->box_id='A';
1182
+                $emptybox->info_box_head=array();
1183
+                $emptybox->info_box_contents=array();
1184
+                $boxlista.= $emptybox->outputBox(array(),array());
1185 1185
             }
1186 1186
             $boxlista.= "<!-- End box left container -->\n";
1187 1187
 
@@ -1190,9 +1190,9 @@  discard block
 block discarded – undo
1190 1190
             $ii=0;
1191 1191
             foreach ($boxactivated as $key => $box)
1192 1192
             {
1193
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1194
-            	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
1195
-            	if (preg_match('/^B/i',$box->box_order)) // colonne B
1193
+                if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1194
+                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
1195
+                if (preg_match('/^B/i',$box->box_order)) // colonne B
1196 1196
                 {
1197 1197
                     $ii++;
1198 1198
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
@@ -1205,10 +1205,10 @@  discard block
 block discarded – undo
1205 1205
 
1206 1206
             if ($conf->browser->layout != 'phone')
1207 1207
             {
1208
-            	$emptybox->box_id='B';
1209
-            	$emptybox->info_box_head=array();
1210
-            	$emptybox->info_box_contents=array();
1211
-            	$boxlistb.= $emptybox->outputBox(array(),array());
1208
+                $emptybox->box_id='B';
1209
+                $emptybox->info_box_head=array();
1210
+                $emptybox->info_box_contents=array();
1211
+                $boxlistb.= $emptybox->outputBox(array(),array());
1212 1212
             }
1213 1213
 
1214 1214
             $boxlistb.= "<!-- End box right container -->\n";
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
                 print "</select>";
1275 1275
             }
1276 1276
             else
1277
-			{
1277
+            {
1278 1278
                 print $langs->trans("DictionaryEmpty");
1279 1279
             }
1280 1280
         }
Please login to merge, or discard this patch.
Spacing   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
      *    @param    int		$fk_user          Utilisateur créant le modèle
68 68
      *    @return	void
69 69
      */
70
-    function select_export_model($selected='', $htmlname='exportmodelid', $type='', $useempty=0, $fk_user=null)
70
+    function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
71 71
     {
72 72
         // phpcs:enable
73 73
         $sql = "SELECT rowid, label";
74
-        $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
75
-        $sql.= " WHERE type = '".$type."'";
76
-		if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user;
77
-        $sql.= " ORDER BY rowid";
74
+        $sql .= " FROM ".MAIN_DB_PREFIX."export_model";
75
+        $sql .= " WHERE type = '".$type."'";
76
+		if (!empty($fk_user)) $sql .= " AND fk_user=".$fk_user;
77
+        $sql .= " ORDER BY rowid";
78 78
         $result = $this->db->query($sql);
79 79
         if ($result)
80 80
         {
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
      *    @param    int		$useempty          Affiche valeur vide dans liste
120 120
      *    @return	void
121 121
      */
122
-    function select_import_model($selected='', $htmlname='importmodelid', $type='', $useempty=0)
122
+    function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0)
123 123
     {
124 124
         // phpcs:enable
125 125
         $sql = "SELECT rowid, label";
126
-        $sql.= " FROM ".MAIN_DB_PREFIX."import_model";
127
-        $sql.= " WHERE type = '".$type."'";
128
-        $sql.= " ORDER BY rowid";
126
+        $sql .= " FROM ".MAIN_DB_PREFIX."import_model";
127
+        $sql .= " WHERE type = '".$type."'";
128
+        $sql .= " ORDER BY rowid";
129 129
         $result = $this->db->query($sql);
130 130
         if ($result)
131 131
         {
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
      *    @param    string	$htmlname	Name of combo list
169 169
      *    @return	integer
170 170
      */
171
-    function select_ecotaxes($selected='', $htmlname='ecotaxe_id')
171
+    function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
172 172
     {
173 173
         // phpcs:enable
174 174
         global $langs;
175 175
 
176 176
         $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
177
-        $sql.= " c.label as country";
178
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
179
-        $sql.= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
180
-        $sql.= " ORDER BY country, e.organization ASC, e.code ASC";
177
+        $sql .= " c.label as country";
178
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
179
+        $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
180
+        $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
181 181
 
182 182
     	dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
183
-        $resql=$this->db->query($sql);
183
+        $resql = $this->db->query($sql);
184 184
         if ($resql)
185 185
         {
186 186
             print '<select class="flat" name="'.$htmlname.'">';
@@ -227,26 +227,26 @@  discard block
 block discarded – undo
227 227
      *    @param    string	$country_code   Country Code
228 228
      *    @return	string					HTML select list
229 229
      */
230
-    function select_revenue_stamp($selected='', $htmlname='revenuestamp', $country_code='')
230
+    function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
231 231
     {
232 232
         // phpcs:enable
233 233
     	global $langs;
234 234
 
235
-    	$out='';
235
+    	$out = '';
236 236
 
237 237
     	$sql = "SELECT r.taux, r.revenuestamp_type";
238
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
239
-    	$sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
240
-    	$sql.= " AND c.code = '".$country_code."'";
238
+    	$sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
239
+    	$sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
240
+    	$sql .= " AND c.code = '".$country_code."'";
241 241
 
242 242
     	dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
243
-    	$resql=$this->db->query($sql);
243
+    	$resql = $this->db->query($sql);
244 244
     	if ($resql)
245 245
     	{
246
-    		$out.='<select class="flat" name="'.$htmlname.'">';
246
+    		$out .= '<select class="flat" name="'.$htmlname.'">';
247 247
     		$num = $this->db->num_rows($resql);
248 248
     		$i = 0;
249
-    		$out.='<option value="0">&nbsp;</option>'."\n";
249
+    		$out .= '<option value="0">&nbsp;</option>'."\n";
250 250
     		if ($num)
251 251
     		{
252 252
     			while ($i < $num)
@@ -254,19 +254,19 @@  discard block
 block discarded – undo
254 254
     				$obj = $this->db->fetch_object($resql);
255 255
     				if (($selected && $selected == $obj->taux) || $num == 1)
256 256
     				{
257
-    					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
257
+    					$out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
258 258
     				}
259 259
     				else
260 260
     				{
261
-    					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
261
+    					$out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
262 262
     					//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
263 263
     				}
264
-    				$out.=$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
265
-    				$out.='</option>';
264
+    				$out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
265
+    				$out .= '</option>';
266 266
     				$i++;
267 267
     			}
268 268
     		}
269
-    		$out.='</select>';
269
+    		$out .= '</select>';
270 270
     		return $out;
271 271
     	}
272 272
     	else
@@ -290,27 +290,27 @@  discard block
 block discarded – undo
290 290
      *    @param    int     $showempty      Add also an empty line
291 291
      *    @return   string					HTML select string
292 292
      */
293
-    function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100,$showempty=0)
293
+    function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
294 294
     {
295 295
         // phpcs:enable
296
-        $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>';
297
-        if ($showempty) $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'>&nbsp;</option>';
296
+        $return = '<select class="flat" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
297
+        if ($showempty) $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
298 298
 
299
-        for ($i = $start ; $i <= $end ; $i += $increment)
299
+        for ($i = $start; $i <= $end; $i += $increment)
300 300
         {
301 301
             if ($selected != '' && (int) $selected == $i)
302 302
             {
303
-                $return.= '<option value="'.$i.'" selected>';
303
+                $return .= '<option value="'.$i.'" selected>';
304 304
             }
305 305
             else
306 306
             {
307
-                $return.= '<option value="'.$i.'">';
307
+                $return .= '<option value="'.$i.'">';
308 308
             }
309
-            $return.= $i.' % ';
310
-            $return.= '</option>';
309
+            $return .= $i.' % ';
310
+            $return .= '</option>';
311 311
         }
312 312
 
313
-        $return.= '</select>';
313
+        $return .= '</select>';
314 314
 
315 315
         return $return;
316 316
     }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
      * @return  string		        	Html combo list code
329 329
      * @see	select_all_categories
330 330
      */
331
-    function select_categories($type, $selected=0, $htmlname='search_categ', $nocateg=0, $showempty=1, $morecss='')
331
+    function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
332 332
     {
333 333
         // phpcs:enable
334 334
         global $conf, $langs;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
         // For backward compatibility
338 338
         if (is_numeric($type))
339 339
         {
340
-            dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
340
+            dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
341 341
         }
342 342
 
343 343
         // Load list of "categories"
@@ -348,30 +348,30 @@  discard block
 block discarded – undo
348 348
         // Enhance with select2
349 349
         if ($conf->use_javascript_ajax)
350 350
         {
351
-            include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
351
+            include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
352 352
             $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
353
-            $moreforfilter.=$comboenhancement;
353
+            $moreforfilter .= $comboenhancement;
354 354
         }
355 355
 
356 356
         // Print a select with each of them
357
-        $moreforfilter.='<select class="flat minwidth100'.($morecss?' '.$morecss:'').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
358
-        if ($showempty) $moreforfilter.='<option value="0">&nbsp;</option>';	// Should use -1 to say nothing
357
+        $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
358
+        if ($showempty) $moreforfilter .= '<option value="0">&nbsp;</option>'; // Should use -1 to say nothing
359 359
 
360 360
         if (is_array($tab_categs))
361 361
         {
362 362
             foreach ($tab_categs as $categ)
363 363
             {
364
-                $moreforfilter.='<option value="'.$categ['id'].'"';
365
-                if ($categ['id'] == $selected) $moreforfilter.=' selected';
366
-                $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
364
+                $moreforfilter .= '<option value="'.$categ['id'].'"';
365
+                if ($categ['id'] == $selected) $moreforfilter .= ' selected';
366
+                $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
367 367
             }
368 368
         }
369 369
         if ($nocateg)
370 370
         {
371 371
         	$langs->load("categories");
372
-        	$moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>';
372
+        	$moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
373 373
         }
374
-        $moreforfilter.='</select>';
374
+        $moreforfilter .= '</select>';
375 375
 
376 376
         return $moreforfilter;
377 377
     }
@@ -389,44 +389,44 @@  discard block
 block discarded – undo
389 389
      *  @param	string	$morecss		More CSS
390 390
      *  @return string					Html combo list code
391 391
      */
392
-    function select_salesrepresentatives($selected,$htmlname,$user,$showstatus=0,$showempty=1,$morecss='')
392
+    function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '')
393 393
     {
394 394
         // phpcs:enable
395
-        global $conf,$langs;
395
+        global $conf, $langs;
396 396
         $langs->load('users');
397 397
 
398 398
         $out = '';
399 399
         // Enhance with select2
400 400
         if ($conf->use_javascript_ajax)
401 401
         {
402
-            include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
402
+            include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
403 403
 
404 404
             $comboenhancement = ajax_combobox($htmlname);
405 405
             if ($comboenhancement)
406 406
             {
407
-            	$out.=$comboenhancement;
407
+            	$out .= $comboenhancement;
408 408
             }
409 409
         }
410 410
         // Select each sales and print them in a select input
411
-        $out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
412
-        if ($showempty) $out.='<option value="0">&nbsp;</option>';
411
+        $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
412
+        if ($showempty) $out .= '<option value="0">&nbsp;</option>';
413 413
 
414 414
         // Get list of users allowed to be viewed
415 415
         $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
416
-        $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
417
-        $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
418
-        if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
419
-        if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
416
+        $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u";
417
+        $sql_usr .= " WHERE u.entity IN (0,".$conf->entity.")";
418
+        if (empty($user->rights->user->user->lire)) $sql_usr .= " AND u.rowid = ".$user->id;
419
+        if (!empty($user->societe_id)) $sql_usr .= " AND u.fk_soc = ".$user->societe_id;
420 420
         // Add existing sales representatives of thirdparty of external user
421 421
         if (empty($user->rights->user->user->lire) && $user->societe_id)
422 422
         {
423
-            $sql_usr.=" UNION ";
424
-            $sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login";
425
-            $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
426
-            $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
427
-            $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
423
+            $sql_usr .= " UNION ";
424
+            $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login";
425
+            $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
426
+            $sql_usr .= " WHERE u2.entity IN (0,".$conf->entity.")";
427
+            $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
428 428
         }
429
-	    $sql_usr.= " ORDER BY statut DESC, lastname ASC";  // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
429
+	    $sql_usr .= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
430 430
         //print $sql_usr;exit;
431 431
 
432 432
         $resql_usr = $this->db->query($sql_usr);
@@ -435,34 +435,34 @@  discard block
 block discarded – undo
435 435
             while ($obj_usr = $this->db->fetch_object($resql_usr))
436 436
             {
437 437
 
438
-                $out.='<option value="'.$obj_usr->rowid.'"';
438
+                $out .= '<option value="'.$obj_usr->rowid.'"';
439 439
 
440
-                if ($obj_usr->rowid == $selected) $out.=' selected';
440
+                if ($obj_usr->rowid == $selected) $out .= ' selected';
441 441
 
442
-                $out.='>';
443
-                $out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname);
442
+                $out .= '>';
443
+                $out .= dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
444 444
                 // Complete name with more info
445
-                $moreinfo=0;
446
-                if (! empty($conf->global->MAIN_SHOW_LOGIN))
445
+                $moreinfo = 0;
446
+                if (!empty($conf->global->MAIN_SHOW_LOGIN))
447 447
                 {
448
-                    $out.=($moreinfo?' - ':' (').$obj_usr->login;
448
+                    $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
449 449
                     $moreinfo++;
450 450
                 }
451 451
                 if ($showstatus >= 0)
452 452
                 {
453 453
 					if ($obj_usr->statut == 1 && $showstatus == 1)
454 454
 					{
455
-						$out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
455
+						$out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
456 456
 	                	$moreinfo++;
457 457
 					}
458 458
 					if ($obj_usr->statut == 0)
459 459
 					{
460
-						$out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
460
+						$out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
461 461
                 		$moreinfo++;
462 462
 					}
463 463
 				}
464
-				$out.=($moreinfo?')':'');
465
-                $out.='</option>';
464
+				$out .= ($moreinfo ? ')' : '');
465
+                $out .= '</option>';
466 466
             }
467 467
             $this->db->free($resql_usr);
468 468
         }
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
         {
471 471
             dol_print_error($this->db);
472 472
         }
473
-        $out.='</select>';
473
+        $out .= '</select>';
474 474
 
475 475
         return $out;
476 476
     }
@@ -490,21 +490,21 @@  discard block
 block discarded – undo
490 490
      *  @param	string	$morecss				More css
491 491
      *  @return	void
492 492
      */
493
-    function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0, $filteronprojstatus='', $morecss='')
493
+    function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
494 494
     {
495 495
         global $user, $langs;
496 496
 
497 497
         require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
498 498
 
499 499
         //print $modeproject.'-'.$modetask;
500
-        $task=new Task($this->db);
501
-        $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode, '', $filteronprojstatus);
500
+        $task = new Task($this->db);
501
+        $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
502 502
         if ($tasksarray)
503 503
         {
504
-        	print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
504
+        	print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
505 505
             if ($useempty) print '<option value="0">&nbsp;</option>';
506
-            $j=0;
507
-            $level=0;
506
+            $j = 0;
507
+            $level = 0;
508 508
             $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
509 509
             print '</select>';
510 510
 
@@ -528,14 +528,14 @@  discard block
 block discarded – undo
528 528
      * @param	int		$disablechildoftaskid	1=Disable task that are child of the provided task id
529 529
      * @return	void
530 530
      */
531
-    private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0, $disablechildoftaskid=0)
531
+    private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
532 532
     {
533 533
         global $langs, $user, $conf;
534 534
 
535
-        $lastprojectid=0;
535
+        $lastprojectid = 0;
536 536
 
537
-        $numlines=count($lines);
538
-        for ($i = 0 ; $i < $numlines ; $i++)
537
+        $numlines = count($lines);
538
+        for ($i = 0; $i < $numlines; $i++)
539 539
         {
540 540
         	if ($lines[$i]->fk_parent == $parent)
541 541
             {
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
                         if ($i > 0) print '<option value="0" disabled>----------</option>';
552 552
                         print '<option value="'.$lines[$i]->fk_project.'_0"';
553 553
                         if ($selectedproject == $lines[$i]->fk_project) print ' selected';
554
-                        print '>';	// Project -> Task
554
+                        print '>'; // Project -> Task
555 555
                         print $langs->trans("Project").' '.$lines[$i]->projectref;
556 556
                         if (empty($lines[$i]->public))
557 557
                         {
@@ -564,22 +564,22 @@  discard block
 block discarded – undo
564 564
                         //print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
565 565
                         print "</option>\n";
566 566
 
567
-                        $lastprojectid=$lines[$i]->fk_project;
567
+                        $lastprojectid = $lines[$i]->fk_project;
568 568
                         $inc++;
569 569
                     }
570 570
                 }
571 571
 
572
-                $newdisablechildoftaskid=$disablechildoftaskid;
572
+                $newdisablechildoftaskid = $disablechildoftaskid;
573 573
 
574 574
                 // Print task
575 575
                 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
576 576
                 {
577 577
                 	// Check if we must disable entry
578
-                	$disabled=0;
578
+                	$disabled = 0;
579 579
                 	if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
580 580
                 	{
581 581
                			$disabled++;
582
-               			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
582
+               			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
583 583
                 	}
584 584
 
585 585
                     print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
                         print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
598 598
                     }
599 599
                     if ($lines[$i]->id) print ' > ';
600
-                    for ($k = 0 ; $k < $level ; $k++)
600
+                    for ($k = 0; $k < $level; $k++)
601 601
                     {
602 602
                         print "&nbsp;&nbsp;&nbsp;";
603 603
                     }
@@ -621,13 +621,13 @@  discard block
 block discarded – undo
621 621
      * 		@return	string							HTML code for color thumb
622 622
      *		@see selectColor
623 623
      */
624
-    static function showColor($color, $textifnotdefined='')
624
+    static function showColor($color, $textifnotdefined = '')
625 625
     {
626
-    	$textcolor='FFF';
626
+    	$textcolor = 'FFF';
627 627
     	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
628
-    	if(colorIsLight($color)) $textcolor='000';
628
+    	if (colorIsLight($color)) $textcolor = '000';
629 629
 
630
-    	$color = colorArrayToHex(colorStringToArray($color,array()),'');
630
+    	$color = colorArrayToHex(colorStringToArray($color, array()), '');
631 631
 
632 632
 		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.'">';
633 633
 		else print $textifnotdefined;
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
      * 		@deprecated Use instead selectColor
647 647
      *      @see selectColor()
648 648
      */
649
-    function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='')
649
+    function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
650 650
     {
651 651
         // phpcs:enable
652 652
     	print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
@@ -664,25 +664,25 @@  discard block
 block discarded – undo
664 664
      * 		@return	string
665 665
      *		@see showColor
666 666
      */
667
-    static function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='')
667
+    static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '')
668 668
     {
669 669
 	    // Deprecation warning
670 670
 	    if ($form_name) {
671
-		    dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING);
671
+		    dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
672 672
 	    }
673 673
 
674
-        global $langs,$conf;
674
+        global $langs, $conf;
675 675
 
676
-        $out='';
676
+        $out = '';
677 677
 
678
-        if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
678
+        if (!is_array($arrayofcolors) || count($arrayofcolors) < 1)
679 679
         {
680 680
             $langs->load("other");
681 681
             if (empty($conf->dol_use_jmobile))
682 682
             {
683
-	            $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
684
-	            $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
685
-	            $out.= '<script type="text/javascript">
683
+	            $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
684
+	            $out .= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
685
+	            $out .= '<script type="text/javascript">
686 686
 	             jQuery(document).ready(function(){
687 687
 	                $(\'#colorpicker'.$prefix.'\').jPicker( {
688 688
 	                window: {
@@ -720,15 +720,15 @@  discard block
 block discarded – undo
720 720
 			        } ); });
721 721
 	             </script>';
722 722
             }
723
-            $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />';
723
+            $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss ? ' '.$morecss : '').'" type="text" value="'.$set_color.'" />';
724 724
         }
725 725
         else  // In most cases, this is not used. We used instead function with no specific list of colors
726 726
         {
727 727
             if (empty($conf->dol_use_jmobile))
728 728
             {
729
-	        	$out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
730
-	            $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
731
-	            $out.= '<script type="text/javascript">
729
+	        	$out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
730
+	            $out .= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
731
+	            $out .= '<script type="text/javascript">
732 732
 	             jQuery(document).ready(function(){
733 733
 	                 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
734 734
 	                     size: 14,
@@ -738,15 +738,15 @@  discard block
 block discarded – undo
738 738
 	             });
739 739
 	             </script>';
740 740
             }
741
-            $out.= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss?' '.$morecss:'').'" name="'.$prefix.'">';
741
+            $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
742 742
             //print '<option value="-1">&nbsp;</option>';
743 743
             foreach ($arrayofcolors as $val)
744 744
             {
745
-                $out.= '<option value="'.$val.'"';
746
-                if ($set_color == $val) $out.= ' selected';
747
-                $out.= '>'.$val.'</option>';
745
+                $out .= '<option value="'.$val.'"';
746
+                if ($set_color == $val) $out .= ' selected';
747
+                $out .= '>'.$val.'</option>';
748 748
             }
749
-            $out.= '</select>';
749
+            $out .= '</select>';
750 750
         }
751 751
 
752 752
         return $out;
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
      *	@param	int		$y      	Hauteur de l'image en pixels
764 764
      *	@return	void
765 765
      */
766
-    function CreateColorIcon($color,$module,$name,$x='12',$y='12')
766
+    function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
767 767
     {
768 768
         // phpcs:enable
769 769
         global $conf;
@@ -771,25 +771,25 @@  discard block
 block discarded – undo
771 771
         $file = $conf->$module->dir_temp.'/'.$name.'.png';
772 772
 
773 773
         // On cree le repertoire contenant les icones
774
-        if (! file_exists($conf->$module->dir_temp))
774
+        if (!file_exists($conf->$module->dir_temp))
775 775
         {
776 776
             dol_mkdir($conf->$module->dir_temp);
777 777
         }
778 778
 
779 779
         // On cree l'image en vraies couleurs
780
-        $image = imagecreatetruecolor($x,$y);
780
+        $image = imagecreatetruecolor($x, $y);
781 781
 
782
-        $color = substr($color,1,6);
782
+        $color = substr($color, 1, 6);
783 783
 
784
-        $rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
785
-        $vert  = hexdec(substr($color,2,2)); //conversion du canal vert
786
-        $bleu  = hexdec(substr($color,4,2)); //conversion du canal bleu
784
+        $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
785
+        $vert  = hexdec(substr($color, 2, 2)); //conversion du canal vert
786
+        $bleu  = hexdec(substr($color, 4, 2)); //conversion du canal bleu
787 787
 
788
-        $couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
788
+        $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
789 789
         //print $rouge.$vert.$bleu;
790
-        imagefill($image,0,0,$couleur); //on remplit l'image
790
+        imagefill($image, 0, 0, $couleur); //on remplit l'image
791 791
         // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
792
-        ImagePng($image,$file); //renvoie une image sous format png
792
+        ImagePng($image, $file); //renvoie une image sous format png
793 793
         ImageDestroy($image);
794 794
     }
795 795
 
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
      *    	@param  int			$useempty          Affiche valeur vide dans liste
803 803
      *    	@return	string
804 804
      */
805
-    function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
805
+    function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
806 806
     {
807 807
         // phpcs:enable
808 808
         global $langs;
@@ -850,17 +850,17 @@  discard block
 block discarded – undo
850 850
      *      @param	string		$morecss			More Css
851 851
      *      @return string
852 852
      */
853
-    function select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0, $morecss='')
853
+    function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = '')
854 854
     {
855 855
         // phpcs:enable
856 856
         global $langs;
857 857
 
858 858
         require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
859 859
 
860
-        if ($longlabel) $montharray = monthArray($langs, 0);	// Get array
860
+        if ($longlabel) $montharray = monthArray($langs, 0); // Get array
861 861
         else $montharray = monthArray($langs, 1);
862 862
 
863
-        $select_month = '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
863
+        $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
864 864
         if ($useempty)
865 865
         {
866 866
             $select_month .= '<option value="0">&nbsp;</option>';
@@ -897,10 +897,10 @@  discard block
 block discarded – undo
897 897
      *  @param	string		$morecss		More CSS
898 898
      *  @return	string
899 899
      */
900
-    function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle widthauto')
900
+    function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle widthauto')
901 901
     {
902 902
         // phpcs:enable
903
-        print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option,$morecss);
903
+        print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss);
904 904
     }
905 905
 
906 906
     /**
@@ -917,41 +917,41 @@  discard block
 block discarded – undo
917 917
      *  @param	string	$morecss		More css
918 918
      *  @return	string
919 919
      */
920
-    function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle widthauto')
920
+    function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle widthauto')
921 921
     {
922
-        $out='';
922
+        $out = '';
923 923
 
924
-        $currentyear = date("Y")+$offset;
925
-        $max_year = $currentyear+$max_year;
926
-        $min_year = $currentyear-$min_year;
927
-        if(empty($selected) && empty($useempty)) $selected = $currentyear;
924
+        $currentyear = date("Y") + $offset;
925
+        $max_year = $currentyear + $max_year;
926
+        $min_year = $currentyear - $min_year;
927
+        if (empty($selected) && empty($useempty)) $selected = $currentyear;
928 928
 
929
-        $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
930
-        if($useempty)
929
+        $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
930
+        if ($useempty)
931 931
         {
932
-        	$selected_html='';
932
+        	$selected_html = '';
933 933
             if ($selected == '') $selected_html = ' selected';
934
-            $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
934
+            $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
935 935
         }
936
-        if (! $invert)
936
+        if (!$invert)
937 937
         {
938 938
             for ($y = $max_year; $y >= $min_year; $y--)
939 939
             {
940
-                $selected_html='';
940
+                $selected_html = '';
941 941
                 if ($selected > 0 && $y == $selected) $selected_html = ' selected';
942
-                $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
942
+                $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
943 943
             }
944 944
         }
945 945
         else
946 946
         {
947 947
             for ($y = $min_year; $y <= $max_year; $y++)
948 948
             {
949
-                $selected_html='';
949
+                $selected_html = '';
950 950
                 if ($selected > 0 && $y == $selected) $selected_html = ' selected';
951
-                $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
951
+                $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
952 952
             }
953 953
         }
954
-        $out.= "</select>\n";
954
+        $out .= "</select>\n";
955 955
 
956 956
         return $out;
957 957
     }
@@ -968,10 +968,10 @@  discard block
 block discarded – undo
968 968
      * @param  	int		$originid      	Id de l'origine
969 969
      * @return	void
970 970
      */
971
-    function form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='')
971
+    function form_address($page, $selected, $socid, $htmlname = 'address_id', $origin = '', $originid = '')
972 972
     {
973 973
         // phpcs:enable
974
-        global $langs,$conf;
974
+        global $langs, $conf;
975 975
         global $form;
976 976
 
977 977
         if ($htmlname != "none")
@@ -989,9 +989,9 @@  discard block
 block discarded – undo
989 989
         {
990 990
             if ($selected)
991 991
             {
992
-                require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php';
993
-                $address=new Address($this->db);
994
-                $result=$address->fetch_address($selected);
992
+                require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php';
993
+                $address = new Address($this->db);
994
+                $result = $address->fetch_address($selected);
995 995
                 print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
996 996
             }
997 997
             else
@@ -1011,72 +1011,72 @@  discard block
 block discarded – undo
1011 1011
      * 	@param	   String       $areacode    Code of area for pages ('0'=value for Home page)
1012 1012
      * 	@return    array                     array('selectboxlist'=>, 'boxactivated'=>, 'boxlista'=>, 'boxlistb'=>)
1013 1013
      */
1014
-    static function getBoxesArea($user,$areacode)
1014
+    static function getBoxesArea($user, $areacode)
1015 1015
     {
1016
-        global $conf,$langs,$db;
1016
+        global $conf, $langs, $db;
1017 1017
 
1018 1018
         include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1019 1019
 
1020
-        $confuserzone='MAIN_BOXES_'.$areacode;
1020
+        $confuserzone = 'MAIN_BOXES_'.$areacode;
1021 1021
 
1022 1022
         // $boxactivated will be array of boxes enabled into global setup
1023 1023
         // $boxidactivatedforuser will be array of boxes choosed by user
1024 1024
 
1025
-        $selectboxlist='';
1026
-        $boxactivated=InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone)?null:$user), array(), 0);	// Search boxes of common+user (or common only if user has no specific setup)
1025
+        $selectboxlist = '';
1026
+        $boxactivated = InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone) ?null:$user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
1027 1027
 
1028
-        $boxidactivatedforuser=array();
1029
-        foreach($boxactivated as $box)
1028
+        $boxidactivatedforuser = array();
1029
+        foreach ($boxactivated as $box)
1030 1030
         {
1031
-        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id;	// We keep only boxes to show for user
1031
+        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1032 1032
         }
1033 1033
 
1034 1034
         // Define selectboxlist
1035
-        $arrayboxtoactivatelabel=array();
1036
-        if (! empty($user->conf->$confuserzone))
1035
+        $arrayboxtoactivatelabel = array();
1036
+        if (!empty($user->conf->$confuserzone))
1037 1037
         {
1038
-        	$boxorder='';
1039
-        	$langs->load("boxes");	// Load label of boxes
1040
-        	foreach($boxactivated as $box)
1038
+        	$boxorder = '';
1039
+        	$langs->load("boxes"); // Load label of boxes
1040
+        	foreach ($boxactivated as $box)
1041 1041
         	{
1042
-        		if (! empty($boxidactivatedforuser[$box->id])) continue;	// Already visible for user
1043
-        		$label=$langs->transnoentitiesnoconv($box->boxlabel);
1042
+        		if (!empty($boxidactivatedforuser[$box->id])) continue; // Already visible for user
1043
+        		$label = $langs->transnoentitiesnoconv($box->boxlabel);
1044 1044
         		//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1045
-        		if (preg_match('/graph/',$box->class) && $conf->browser->layout != 'phone')
1045
+        		if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone')
1046 1046
         		{
1047
-        			$label=$label.' <span class="fa fa-bar-chart"></span>';
1047
+        			$label = $label.' <span class="fa fa-bar-chart"></span>';
1048 1048
         		}
1049
-        		$arrayboxtoactivatelabel[$box->id]=$label;			// We keep only boxes not shown for user, to show into combo list
1049
+        		$arrayboxtoactivatelabel[$box->id] = $label; // We keep only boxes not shown for user, to show into combo list
1050 1050
         	}
1051
-            foreach($boxidactivatedforuser as $boxid)
1051
+            foreach ($boxidactivatedforuser as $boxid)
1052 1052
         	{
1053
-       			if (empty($boxorder)) $boxorder.='A:';
1054
-  				$boxorder.=$boxid.',';
1053
+       			if (empty($boxorder)) $boxorder .= 'A:';
1054
+  				$boxorder .= $boxid.',';
1055 1055
         	}
1056 1056
 
1057 1057
         	//var_dump($boxidactivatedforuser);
1058 1058
 
1059 1059
         	// Class Form must have been already loaded
1060
-        	$selectboxlist.='<!-- Form with select box list -->'."\n";
1061
-			$selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1062
-			$selectboxlist.='<input type="hidden" name="addbox" value="addbox">';
1063
-			$selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">';
1064
-			$selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1065
-			$selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1066
-			$selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1067
-            if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1068
-            $selectboxlist.='</form>';
1069
-            if (! empty($conf->use_javascript_ajax))
1060
+        	$selectboxlist .= '<!-- Form with select box list -->'."\n";
1061
+			$selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1062
+			$selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1063
+			$selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1064
+			$selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1065
+			$selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1066
+			$selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1067
+            if (empty($conf->use_javascript_ajax)) $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1068
+            $selectboxlist .= '</form>';
1069
+            if (!empty($conf->use_javascript_ajax))
1070 1070
             {
1071
-            	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
1072
-            	$selectboxlist.=ajax_combobox("boxcombo");
1071
+            	include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1072
+            	$selectboxlist .= ajax_combobox("boxcombo");
1073 1073
             }
1074 1074
         }
1075 1075
 
1076 1076
         // Javascript code for dynamic actions
1077
-        if (! empty($conf->use_javascript_ajax))
1077
+        if (!empty($conf->use_javascript_ajax))
1078 1078
         {
1079
-	        $selectboxlist.='<script type="text/javascript" language="javascript">
1079
+	        $selectboxlist .= '<script type="text/javascript" language="javascript">
1080 1080
 
1081 1081
 	        // To update list of activated boxes
1082 1082
 	        function updateBoxOrder(closing) {
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
 	        			async: false
1091 1091
 	        		});
1092 1092
 	        		// We force reload to be sure to get all boxes into list
1093
-	        		window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=delbox\';
1093
+	        		window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox\';
1094 1094
 	        	}
1095 1095
 	        	else
1096 1096
 	        	{
@@ -1112,11 +1112,11 @@  discard block
 block discarded – undo
1112 1112
 	    					url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\',
1113 1113
 	    			        async: false
1114 1114
 	    		        });
1115
-	        			window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid;
1115
+	        			window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=addbox&boxid=\'+boxid;
1116 1116
 	                }
1117 1117
 	        	});';
1118
-	        	if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1119
-	        	$selectboxlist.='
1118
+	        	if (!count($arrayboxtoactivatelabel)) $selectboxlist .= 'jQuery("#boxcombo").hide();';
1119
+	        	$selectboxlist .= '
1120 1120
 
1121 1121
 	        	jQuery("#boxhalfleft, #boxhalfright").sortable({
1122 1122
 	    	    	handle: \'.boxhandle\',
@@ -1141,80 +1141,80 @@  discard block
 block discarded – undo
1141 1141
 
1142 1142
         	});'."\n";
1143 1143
 
1144
-	        $selectboxlist.='</script>'."\n";
1144
+	        $selectboxlist .= '</script>'."\n";
1145 1145
         }
1146 1146
 
1147 1147
         // Define boxlista and boxlistb
1148
-        $nbboxactivated=count($boxidactivatedforuser);
1148
+        $nbboxactivated = count($boxidactivatedforuser);
1149 1149
 
1150 1150
         if ($nbboxactivated)
1151 1151
         {
1152 1152
         	// Load translation files required by the page
1153
-            $langs->loadLangs(array("boxes","projects"));
1153
+            $langs->loadLangs(array("boxes", "projects"));
1154 1154
 
1155
-        	$emptybox=new ModeleBoxes($db);
1155
+        	$emptybox = new ModeleBoxes($db);
1156 1156
 
1157
-            $boxlista.="\n<!-- Box left container -->\n";
1157
+            $boxlista .= "\n<!-- Box left container -->\n";
1158 1158
 
1159 1159
             // Define $box_max_lines
1160
-            $box_max_lines=5;
1161
-            if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1160
+            $box_max_lines = 5;
1161
+            if (!empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
1162 1162
 
1163
-            $ii=0;
1163
+            $ii = 0;
1164 1164
             foreach ($boxactivated as $key => $box)
1165 1165
             {
1166
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1167
-				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
1168
-            	if (preg_match('/^A/i',$box->box_order)) // column A
1166
+            	if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1167
+				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
1168
+            	if (preg_match('/^A/i', $box->box_order)) // column A
1169 1169
                 {
1170 1170
                     $ii++;
1171 1171
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1172 1172
                     //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1173 1173
                     // Show box
1174 1174
                     $box->loadBox($box_max_lines);
1175
-                    $boxlista.= $box->outputBox();
1175
+                    $boxlista .= $box->outputBox();
1176 1176
                 }
1177 1177
             }
1178 1178
 
1179 1179
             if ($conf->browser->layout != 'phone')
1180 1180
             {
1181
-            	$emptybox->box_id='A';
1182
-            	$emptybox->info_box_head=array();
1183
-            	$emptybox->info_box_contents=array();
1184
-            	$boxlista.= $emptybox->outputBox(array(),array());
1181
+            	$emptybox->box_id = 'A';
1182
+            	$emptybox->info_box_head = array();
1183
+            	$emptybox->info_box_contents = array();
1184
+            	$boxlista .= $emptybox->outputBox(array(), array());
1185 1185
             }
1186
-            $boxlista.= "<!-- End box left container -->\n";
1186
+            $boxlista .= "<!-- End box left container -->\n";
1187 1187
 
1188
-            $boxlistb.= "\n<!-- Box right container -->\n";
1188
+            $boxlistb .= "\n<!-- Box right container -->\n";
1189 1189
 
1190
-            $ii=0;
1190
+            $ii = 0;
1191 1191
             foreach ($boxactivated as $key => $box)
1192 1192
             {
1193
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1194
-            	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
1195
-            	if (preg_match('/^B/i',$box->box_order)) // colonne B
1193
+            	if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1194
+            	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
1195
+            	if (preg_match('/^B/i', $box->box_order)) // colonne B
1196 1196
                 {
1197 1197
                     $ii++;
1198 1198
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1199 1199
                     //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1200 1200
                     // Show box
1201 1201
                     $box->loadBox($box_max_lines);
1202
-                    $boxlistb.= $box->outputBox();
1202
+                    $boxlistb .= $box->outputBox();
1203 1203
                 }
1204 1204
             }
1205 1205
 
1206 1206
             if ($conf->browser->layout != 'phone')
1207 1207
             {
1208
-            	$emptybox->box_id='B';
1209
-            	$emptybox->info_box_head=array();
1210
-            	$emptybox->info_box_contents=array();
1211
-            	$boxlistb.= $emptybox->outputBox(array(),array());
1208
+            	$emptybox->box_id = 'B';
1209
+            	$emptybox->info_box_head = array();
1210
+            	$emptybox->info_box_contents = array();
1211
+            	$boxlistb .= $emptybox->outputBox(array(), array());
1212 1212
             }
1213 1213
 
1214
-            $boxlistb.= "<!-- End box right container -->\n";
1214
+            $boxlistb .= "<!-- End box right container -->\n";
1215 1215
         }
1216 1216
 
1217
-        return array('selectboxlist'=>count($boxactivated)?$selectboxlist:'', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1217
+        return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1218 1218
     }
1219 1219
 
1220 1220
 
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
      *  @param  string  $moreattrib         More attributes on HTML select tag
1232 1232
      * 	@return	void
1233 1233
      */
1234
-    function select_dictionary($htmlname,$dictionarytable,$keyfield='code',$labelfield='label',$selected='',$useempty=0,$moreattrib='')
1234
+    function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1235 1235
     {
1236 1236
         // phpcs:enable
1237 1237
         global $langs, $conf;
@@ -1239,8 +1239,8 @@  discard block
 block discarded – undo
1239 1239
         $langs->load("admin");
1240 1240
 
1241 1241
         $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1242
-        $sql.= " FROM ".MAIN_DB_PREFIX.$dictionarytable;
1243
-        $sql.= " ORDER BY ".$labelfield;
1242
+        $sql .= " FROM ".MAIN_DB_PREFIX.$dictionarytable;
1243
+        $sql .= " ORDER BY ".$labelfield;
1244 1244
 
1245 1245
         dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1246 1246
         $result = $this->db->query($sql);
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
             $i = 0;
1251 1251
             if ($num)
1252 1252
             {
1253
-                print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
1253
+                print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1254 1254
                 if ($useempty == 1 || ($useempty == 2 && $num > 1))
1255 1255
                 {
1256 1256
                     print '<option value="-1">&nbsp;</option>';
Please login to merge, or discard this patch.
Braces   +145 added lines, -83 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
         $sql = "SELECT rowid, label";
74 74
         $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
75 75
         $sql.= " WHERE type = '".$type."'";
76
-		if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user;
76
+		if (!empty($fk_user)) {
77
+		    $sql.=" AND fk_user=".$fk_user;
78
+		}
77 79
         $sql.= " ORDER BY rowid";
78 80
         $result = $this->db->query($sql);
79 81
         if ($result)
@@ -92,8 +94,7 @@  discard block
 block discarded – undo
92 94
                 if ($selected == $obj->rowid)
93 95
                 {
94 96
                     print '<option value="'.$obj->rowid.'" selected>';
95
-                }
96
-                else
97
+                } else
97 98
                 {
98 99
                     print '<option value="'.$obj->rowid.'">';
99 100
                 }
@@ -102,8 +103,7 @@  discard block
 block discarded – undo
102 103
                 $i++;
103 104
             }
104 105
             print "</select>";
105
-        }
106
-        else {
106
+        } else {
107 107
             dol_print_error($this->db);
108 108
         }
109 109
     }
@@ -143,8 +143,7 @@  discard block
 block discarded – undo
143 143
                 if ($selected == $obj->rowid)
144 144
                 {
145 145
                     print '<option value="'.$obj->rowid.'" selected>';
146
-                }
147
-                else
146
+                } else
148 147
                 {
149 148
                     print '<option value="'.$obj->rowid.'">';
150 149
                 }
@@ -153,8 +152,7 @@  discard block
 block discarded – undo
153 152
                 $i++;
154 153
             }
155 154
             print "</select>";
156
-        }
157
-        else {
155
+        } else {
158 156
             dol_print_error($this->db);
159 157
         }
160 158
     }
@@ -195,8 +193,7 @@  discard block
 block discarded – undo
195 193
                     if ($selected && $selected == $obj->rowid)
196 194
                     {
197 195
                         print '<option value="'.$obj->rowid.'" selected>';
198
-                    }
199
-                    else
196
+                    } else
200 197
                     {
201 198
                         print '<option value="'.$obj->rowid.'">';
202 199
                         //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
@@ -209,8 +206,7 @@  discard block
 block discarded – undo
209 206
             }
210 207
             print '</select>';
211 208
             return 0;
212
-        }
213
-        else
209
+        } else
214 210
         {
215 211
             dol_print_error($this->db);
216 212
             return 1;
@@ -255,8 +251,7 @@  discard block
 block discarded – undo
255 251
     				if (($selected && $selected == $obj->taux) || $num == 1)
256 252
     				{
257 253
     					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
258
-    				}
259
-    				else
254
+    				} else
260 255
     				{
261 256
     					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
262 257
     					//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
@@ -268,8 +263,7 @@  discard block
 block discarded – undo
268 263
     		}
269 264
     		$out.='</select>';
270 265
     		return $out;
271
-    	}
272
-    	else
266
+    	} else
273 267
     	{
274 268
     		dol_print_error($this->db);
275 269
     		return '';
@@ -294,15 +288,16 @@  discard block
 block discarded – undo
294 288
     {
295 289
         // phpcs:enable
296 290
         $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>';
297
-        if ($showempty) $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'>&nbsp;</option>';
291
+        if ($showempty) {
292
+            $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'>&nbsp;</option>';
293
+        }
298 294
 
299 295
         for ($i = $start ; $i <= $end ; $i += $increment)
300 296
         {
301 297
             if ($selected != '' && (int) $selected == $i)
302 298
             {
303 299
                 $return.= '<option value="'.$i.'" selected>';
304
-            }
305
-            else
300
+            } else
306 301
             {
307 302
                 $return.= '<option value="'.$i.'">';
308 303
             }
@@ -355,14 +350,19 @@  discard block
 block discarded – undo
355 350
 
356 351
         // Print a select with each of them
357 352
         $moreforfilter.='<select class="flat minwidth100'.($morecss?' '.$morecss:'').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
358
-        if ($showempty) $moreforfilter.='<option value="0">&nbsp;</option>';	// Should use -1 to say nothing
353
+        if ($showempty) {
354
+            $moreforfilter.='<option value="0">&nbsp;</option>';
355
+        }
356
+        // Should use -1 to say nothing
359 357
 
360 358
         if (is_array($tab_categs))
361 359
         {
362 360
             foreach ($tab_categs as $categ)
363 361
             {
364 362
                 $moreforfilter.='<option value="'.$categ['id'].'"';
365
-                if ($categ['id'] == $selected) $moreforfilter.=' selected';
363
+                if ($categ['id'] == $selected) {
364
+                    $moreforfilter.=' selected';
365
+                }
366 366
                 $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
367 367
             }
368 368
         }
@@ -409,14 +409,20 @@  discard block
 block discarded – undo
409 409
         }
410 410
         // Select each sales and print them in a select input
411 411
         $out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
412
-        if ($showempty) $out.='<option value="0">&nbsp;</option>';
412
+        if ($showempty) {
413
+            $out.='<option value="0">&nbsp;</option>';
414
+        }
413 415
 
414 416
         // Get list of users allowed to be viewed
415 417
         $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
416 418
         $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
417 419
         $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
418
-        if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
419
-        if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
420
+        if (empty($user->rights->user->user->lire)) {
421
+            $sql_usr.=" AND u.rowid = ".$user->id;
422
+        }
423
+        if (! empty($user->societe_id)) {
424
+            $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
425
+        }
420 426
         // Add existing sales representatives of thirdparty of external user
421 427
         if (empty($user->rights->user->user->lire) && $user->societe_id)
422 428
         {
@@ -437,7 +443,9 @@  discard block
 block discarded – undo
437 443
 
438 444
                 $out.='<option value="'.$obj_usr->rowid.'"';
439 445
 
440
-                if ($obj_usr->rowid == $selected) $out.=' selected';
446
+                if ($obj_usr->rowid == $selected) {
447
+                    $out.=' selected';
448
+                }
441 449
 
442 450
                 $out.='>';
443 451
                 $out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname);
@@ -465,8 +473,7 @@  discard block
 block discarded – undo
465 473
                 $out.='</option>';
466 474
             }
467 475
             $this->db->free($resql_usr);
468
-        }
469
-        else
476
+        } else
470 477
         {
471 478
             dol_print_error($this->db);
472 479
         }
@@ -502,15 +509,16 @@  discard block
 block discarded – undo
502 509
         if ($tasksarray)
503 510
         {
504 511
         	print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
505
-            if ($useempty) print '<option value="0">&nbsp;</option>';
512
+            if ($useempty) {
513
+                print '<option value="0">&nbsp;</option>';
514
+            }
506 515
             $j=0;
507 516
             $level=0;
508 517
             $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
509 518
             print '</select>';
510 519
 
511 520
             print ajax_combobox($htmlname);
512
-        }
513
-        else
521
+        } else
514 522
         {
515 523
             print '<div class="warning">'.$langs->trans("NoProject").'</div>';
516 524
         }
@@ -544,20 +552,23 @@  discard block
 block discarded – undo
544 552
 				//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id);		// $lines[$i]->id may be empty if project has no lines
545 553
 
546 554
                 // Break on a new project
547
-                if ($parent == 0)	// We are on a task at first level
555
+                if ($parent == 0) {
556
+                    // We are on a task at first level
548 557
                 {
549 558
                     if ($lines[$i]->fk_project != $lastprojectid)	// Break found on project
550 559
                     {
551 560
                         if ($i > 0) print '<option value="0" disabled>----------</option>';
561
+                }
552 562
                         print '<option value="'.$lines[$i]->fk_project.'_0"';
553
-                        if ($selectedproject == $lines[$i]->fk_project) print ' selected';
563
+                        if ($selectedproject == $lines[$i]->fk_project) {
564
+                            print ' selected';
565
+                        }
554 566
                         print '>';	// Project -> Task
555 567
                         print $langs->trans("Project").' '.$lines[$i]->projectref;
556 568
                         if (empty($lines[$i]->public))
557 569
                         {
558 570
                             print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
559
-                        }
560
-                        else
571
+                        } else
561 572
                         {
562 573
                             print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
563 574
                         }
@@ -572,31 +583,41 @@  discard block
 block discarded – undo
572 583
                 $newdisablechildoftaskid=$disablechildoftaskid;
573 584
 
574 585
                 // Print task
575
-                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
586
+                if (isset($lines[$i]->id)) {
587
+                    // 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
576 588
                 {
577 589
                 	// Check if we must disable entry
578 590
                 	$disabled=0;
591
+                }
579 592
                 	if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
580 593
                 	{
581 594
                			$disabled++;
582
-               			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
595
+               			if ($lines[$i]->fk_parent == $disablechildoftaskid) {
596
+               			    $newdisablechildoftaskid=$lines[$i]->id;
597
+               			}
598
+               			// If task is child of a disabled parent, we will propagate id to disable next child too
583 599
                 	}
584 600
 
585 601
                     print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
586
-                    if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
587
-                    if ($disabled) print ' disabled';
602
+                    if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
603
+                        print ' selected';
604
+                    }
605
+                    if ($disabled) {
606
+                        print ' disabled';
607
+                    }
588 608
                     print '>';
589 609
                     print $langs->trans("Project").' '.$lines[$i]->projectref;
590 610
                     print ' '.$lines[$i]->projectlabel;
591 611
                     if (empty($lines[$i]->public))
592 612
                     {
593 613
                         print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
594
-                    }
595
-                    else
614
+                    } else
596 615
                     {
597 616
                         print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
598 617
                     }
599
-                    if ($lines[$i]->id) print ' > ';
618
+                    if ($lines[$i]->id) {
619
+                        print ' > ';
620
+                    }
600 621
                     for ($k = 0 ; $k < $level ; $k++)
601 622
                     {
602 623
                         print "&nbsp;&nbsp;&nbsp;";
@@ -606,7 +627,9 @@  discard block
 block discarded – undo
606 627
                 }
607 628
 
608 629
                 $level++;
609
-                if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
630
+                if ($lines[$i]->id) {
631
+                    $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
632
+                }
610 633
                 $level--;
611 634
             }
612 635
         }
@@ -625,12 +648,17 @@  discard block
 block discarded – undo
625 648
     {
626 649
     	$textcolor='FFF';
627 650
     	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
628
-    	if(colorIsLight($color)) $textcolor='000';
651
+    	if(colorIsLight($color)) {
652
+    	    $textcolor='000';
653
+    	}
629 654
 
630 655
     	$color = colorArrayToHex(colorStringToArray($color,array()),'');
631 656
 
632
-		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.'">';
633
-		else print $textifnotdefined;
657
+		if ($color) {
658
+		    print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
659
+		} else {
660
+		    print $textifnotdefined;
661
+		}
634 662
     }
635 663
 
636 664
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -721,8 +749,7 @@  discard block
 block discarded – undo
721 749
 	             </script>';
722 750
             }
723 751
             $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />';
724
-        }
725
-        else  // In most cases, this is not used. We used instead function with no specific list of colors
752
+        } else  // In most cases, this is not used. We used instead function with no specific list of colors
726 753
         {
727 754
             if (empty($conf->dol_use_jmobile))
728 755
             {
@@ -743,7 +770,9 @@  discard block
 block discarded – undo
743 770
             foreach ($arrayofcolors as $val)
744 771
             {
745 772
                 $out.= '<option value="'.$val.'"';
746
-                if ($set_color == $val) $out.= ' selected';
773
+                if ($set_color == $val) {
774
+                    $out.= ' selected';
775
+                }
747 776
                 $out.= '>'.$val.'</option>';
748 777
             }
749 778
             $out.= '</select>';
@@ -827,8 +856,7 @@  discard block
 block discarded – undo
827 856
             if ($selected == $key)
828 857
             {
829 858
                 $select_week .= '<option value="'.$key.'" selected>';
830
-            }
831
-            else
859
+            } else
832 860
             {
833 861
                 $select_week .= '<option value="'.$key.'">';
834 862
             }
@@ -857,8 +885,13 @@  discard block
 block discarded – undo
857 885
 
858 886
         require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
859 887
 
860
-        if ($longlabel) $montharray = monthArray($langs, 0);	// Get array
861
-        else $montharray = monthArray($langs, 1);
888
+        if ($longlabel) {
889
+            $montharray = monthArray($langs, 0);
890
+        }
891
+        // Get array
892
+        else {
893
+            $montharray = monthArray($langs, 1);
894
+        }
862 895
 
863 896
         $select_month = '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
864 897
         if ($useempty)
@@ -870,8 +903,7 @@  discard block
 block discarded – undo
870 903
             if ($selected == $key)
871 904
             {
872 905
                 $select_month .= '<option value="'.$key.'" selected>';
873
-            }
874
-            else
906
+            } else
875 907
             {
876 908
                 $select_month .= '<option value="'.$key.'">';
877 909
             }
@@ -924,13 +956,17 @@  discard block
 block discarded – undo
924 956
         $currentyear = date("Y")+$offset;
925 957
         $max_year = $currentyear+$max_year;
926 958
         $min_year = $currentyear-$min_year;
927
-        if(empty($selected) && empty($useempty)) $selected = $currentyear;
959
+        if(empty($selected) && empty($useempty)) {
960
+            $selected = $currentyear;
961
+        }
928 962
 
929 963
         $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
930 964
         if($useempty)
931 965
         {
932 966
         	$selected_html='';
933
-            if ($selected == '') $selected_html = ' selected';
967
+            if ($selected == '') {
968
+                $selected_html = ' selected';
969
+            }
934 970
             $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
935 971
         }
936 972
         if (! $invert)
@@ -938,16 +974,19 @@  discard block
 block discarded – undo
938 974
             for ($y = $max_year; $y >= $min_year; $y--)
939 975
             {
940 976
                 $selected_html='';
941
-                if ($selected > 0 && $y == $selected) $selected_html = ' selected';
977
+                if ($selected > 0 && $y == $selected) {
978
+                    $selected_html = ' selected';
979
+                }
942 980
                 $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
943 981
             }
944
-        }
945
-        else
982
+        } else
946 983
         {
947 984
             for ($y = $min_year; $y <= $max_year; $y++)
948 985
             {
949 986
                 $selected_html='';
950
-                if ($selected > 0 && $y == $selected) $selected_html = ' selected';
987
+                if ($selected > 0 && $y == $selected) {
988
+                    $selected_html = ' selected';
989
+                }
951 990
                 $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
952 991
             }
953 992
         }
@@ -984,8 +1023,7 @@  discard block
 block discarded – undo
984 1023
             $langs->load("companies");
985 1024
             print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
986 1025
             print '</form>';
987
-        }
988
-        else
1026
+        } else
989 1027
         {
990 1028
             if ($selected)
991 1029
             {
@@ -993,8 +1031,7 @@  discard block
 block discarded – undo
993 1031
                 $address=new Address($this->db);
994 1032
                 $result=$address->fetch_address($selected);
995 1033
                 print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
996
-            }
997
-            else
1034
+            } else
998 1035
             {
999 1036
                 print "&nbsp;";
1000 1037
             }
@@ -1028,7 +1065,10 @@  discard block
 block discarded – undo
1028 1065
         $boxidactivatedforuser=array();
1029 1066
         foreach($boxactivated as $box)
1030 1067
         {
1031
-        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id;	// We keep only boxes to show for user
1068
+        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1069
+        	    $boxidactivatedforuser[$box->id]=$box->id;
1070
+        	}
1071
+        	// We keep only boxes to show for user
1032 1072
         }
1033 1073
 
1034 1074
         // Define selectboxlist
@@ -1039,7 +1079,10 @@  discard block
 block discarded – undo
1039 1079
         	$langs->load("boxes");	// Load label of boxes
1040 1080
         	foreach($boxactivated as $box)
1041 1081
         	{
1042
-        		if (! empty($boxidactivatedforuser[$box->id])) continue;	// Already visible for user
1082
+        		if (! empty($boxidactivatedforuser[$box->id])) {
1083
+        		    continue;
1084
+        		}
1085
+        		// Already visible for user
1043 1086
         		$label=$langs->transnoentitiesnoconv($box->boxlabel);
1044 1087
         		//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1045 1088
         		if (preg_match('/graph/',$box->class) && $conf->browser->layout != 'phone')
@@ -1050,7 +1093,9 @@  discard block
 block discarded – undo
1050 1093
         	}
1051 1094
             foreach($boxidactivatedforuser as $boxid)
1052 1095
         	{
1053
-       			if (empty($boxorder)) $boxorder.='A:';
1096
+       			if (empty($boxorder)) {
1097
+       			    $boxorder.='A:';
1098
+       			}
1054 1099
   				$boxorder.=$boxid.',';
1055 1100
         	}
1056 1101
 
@@ -1064,7 +1109,9 @@  discard block
 block discarded – undo
1064 1109
 			$selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1065 1110
 			$selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1066 1111
 			$selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1067
-            if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1112
+            if (empty($conf->use_javascript_ajax)) {
1113
+                $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1114
+            }
1068 1115
             $selectboxlist.='</form>';
1069 1116
             if (! empty($conf->use_javascript_ajax))
1070 1117
             {
@@ -1115,7 +1162,9 @@  discard block
 block discarded – undo
1115 1162
 	        			window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid;
1116 1163
 	                }
1117 1164
 	        	});';
1118
-	        	if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1165
+	        	if (! count($arrayboxtoactivatelabel)) {
1166
+	        	    $selectboxlist.='jQuery("#boxcombo").hide();';
1167
+	        	}
1119 1168
 	        	$selectboxlist.='
1120 1169
 
1121 1170
 	        	jQuery("#boxhalfleft, #boxhalfright").sortable({
@@ -1158,16 +1207,25 @@  discard block
 block discarded – undo
1158 1207
 
1159 1208
             // Define $box_max_lines
1160 1209
             $box_max_lines=5;
1161
-            if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1210
+            if (! empty($conf->global->MAIN_BOXES_MAXLINES)) {
1211
+                $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1212
+            }
1162 1213
 
1163 1214
             $ii=0;
1164 1215
             foreach ($boxactivated as $key => $box)
1165 1216
             {
1166
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1167
-				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
1168
-            	if (preg_match('/^A/i',$box->box_order)) // column A
1217
+            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1218
+            	    continue;
1219
+            	}
1220
+				if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1221
+				    $box->box_order='A'.sprintf("%02d",($ii+1));
1222
+				}
1223
+				// When box_order was not yet set to Axx or Bxx and is still 0
1224
+            	if (preg_match('/^A/i',$box->box_order)) {
1225
+            	    // column A
1169 1226
                 {
1170 1227
                     $ii++;
1228
+            	}
1171 1229
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1172 1230
                     //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1173 1231
                     // Show box
@@ -1190,11 +1248,18 @@  discard block
 block discarded – undo
1190 1248
             $ii=0;
1191 1249
             foreach ($boxactivated as $key => $box)
1192 1250
             {
1193
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1194
-            	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
1195
-            	if (preg_match('/^B/i',$box->box_order)) // colonne B
1251
+            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1252
+            	    continue;
1253
+            	}
1254
+            	if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1255
+            	    $box->box_order='B'.sprintf("%02d",($ii+1));
1256
+            	}
1257
+            	// When box_order was not yet set to Axx or Bxx and is still 0
1258
+            	if (preg_match('/^B/i',$box->box_order)) {
1259
+            	    // colonne B
1196 1260
                 {
1197 1261
                     $ii++;
1262
+            	}
1198 1263
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1199 1264
                     //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1200 1265
                     // Show box
@@ -1262,8 +1327,7 @@  discard block
 block discarded – undo
1262 1327
                     if ($selected == $obj->rowid || $selected == $obj->$keyfield)
1263 1328
                     {
1264 1329
                         print '<option value="'.$obj->$keyfield.'" selected>';
1265
-                    }
1266
-                    else
1330
+                    } else
1267 1331
                     {
1268 1332
                         print '<option value="'.$obj->$keyfield.'">';
1269 1333
                     }
@@ -1272,13 +1336,11 @@  discard block
 block discarded – undo
1272 1336
                     $i++;
1273 1337
                 }
1274 1338
                 print "</select>";
1275
-            }
1276
-            else
1339
+            } else
1277 1340
 			{
1278 1341
                 print $langs->trans("DictionaryEmpty");
1279 1342
             }
1280
-        }
1281
-        else {
1343
+        } else {
1282 1344
             dol_print_error($this->db);
1283 1345
         }
1284 1346
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/notify.class.php 3 patches
Indentation   +750 added lines, -750 removed lines patch added patch discarded remove patch
@@ -31,766 +31,766 @@
 block discarded – undo
31 31
  */
32 32
 class Notify
33 33
 {
34
-	/**
35
-	 * @var int ID
36
-	 */
37
-	public $id;
34
+    /**
35
+     * @var int ID
36
+     */
37
+    public $id;
38 38
 
39
-	/**
39
+    /**
40 40
      * @var DoliDB Database handler.
41 41
      */
42 42
     public $db;
43 43
 
44
-	/**
45
-	 * @var string Error code (or message)
46
-	 */
47
-	public $error='';
44
+    /**
45
+     * @var string Error code (or message)
46
+     */
47
+    public $error='';
48 48
 
49
-	/**
50
-	 * @var string[] Error codes (or messages)
51
-	 */
52
-	public $errors = array();
49
+    /**
50
+     * @var string[] Error codes (or messages)
51
+     */
52
+    public $errors = array();
53 53
 
54
-	public $author;
55
-	public $ref;
56
-	public $date;
57
-	public $duree;
58
-	public $note;
54
+    public $author;
55
+    public $ref;
56
+    public $date;
57
+    public $duree;
58
+    public $note;
59 59
 
60
-	/**
60
+    /**
61 61
      * @var int Project ID
62 62
      */
63 63
     public $fk_project;
64 64
 
65
-	// Les codes actions sont definis dans la table llx_notify_def
66
-
67
-	// codes actions supported are
68
-	// @TODO defined also into interface_50_modNotificiation_Notificiation.class.php
69
-	public $arrayofnotifsupported = array(
70
-		'BILL_VALIDATE',
71
-		'BILL_PAYED',
72
-		'ORDER_VALIDATE',
73
-		'PROPAL_VALIDATE',
74
-		'PROPAL_CLOSE_SIGNED',
75
-		'FICHINTER_VALIDATE',
76
-		'FICHINTER_ADD_CONTACT',
77
-		'ORDER_SUPPLIER_VALIDATE',
78
-		'ORDER_SUPPLIER_APPROVE',
79
-		'ORDER_SUPPLIER_REFUSE',
80
-		'SHIPPING_VALIDATE',
81
-		'EXPENSE_REPORT_VALIDATE',
82
-		'EXPENSE_REPORT_APPROVE',
83
-		'HOLIDAY_VALIDATE',
84
-		'HOLIDAY_APPROVE'
85
-	);
86
-
87
-
88
-	/**
89
-	 *	Constructor
90
-	 *
91
-	 *	@param 		DoliDB		$db		Database handler
92
-	 */
93
-	function __construct($db)
94
-	{
95
-		$this->db = $db;
96
-	}
97
-
98
-
99
-	/**
100
-	 *  Return message that say how many notification (and to which email) will occurs on requested event.
101
-	 *	This is to show confirmation messages before event is recorded.
102
-	 *
103
-	 * 	@param	string	$action		Id of action in llx_c_action_trigger
104
-	 * 	@param	int		$socid		Id of third party
105
-	 *  @param	Object	$object		Object the notification is about
106
-	 *	@return	string				Message
107
-	 */
108
-	function confirmMessage($action,$socid,$object)
109
-	{
110
-		global $langs;
111
-		$langs->load("mails");
112
-
113
-		$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
114
-
115
-		$nb=-1;
116
-		if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
117
-		if ($nb < 0)  $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
118
-		if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
119
-   		if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
120
-   		if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
121
-
122
-   		if (is_array($listofnotiftodo))
123
-   		{
124
-			$i=0;
125
-			foreach ($listofnotiftodo as $key => $val)
126
-			{
127
-				if ($i) $texte.=', ';
128
-				else $texte.=' (';
129
-				if ($val['isemailvalid']) $texte.=$val['email'];
130
-				else $texte.=$val['emaildesc'];
131
-				$i++;
132
-			}
133
-			if ($i) $texte.=')';
134
-   		}
135
-
136
-		return $texte;
137
-	}
138
-
139
-	/**
140
-	 * Return number of notifications activated for action code (and third party)
141
-	 *
142
-	 * @param	string	$notifcode		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
143
-	 * @param	int		$socid			Id of third party or 0 for all thirdparties or -1 for no thirdparties
144
-	 * @param	Object	$object			Object the notification is about (need it to check threshold value of some notifications)
145
-	 * @param	int		$userid         Id of user or 0 for all users or -1 for no users
146
-	 * @param   array   $scope          Scope where to search
147
-	 * @return	array|int				<0 if KO, array of notifications to send if OK
148
-	 */
149
-	function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
150
-	{
151
-		global $conf, $user;
152
-
153
-		$error=0;
154
-		$resarray=array();
155
-
156
-		$valueforthreshold = 0;
157
-		if (is_object($object)) $valueforthreshold = $object->total_ht;
158
-
159
-		if (! $error)
160
-		{
161
-			if ($socid >= 0 && in_array('thirdparty', $scope))
162
-			{
163
-				$sql = "SELECT a.code, c.email, c.rowid";
164
-				$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
165
-				$sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
166
-				$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
167
-				$sql.= " ".MAIN_DB_PREFIX."societe as s";
168
-				$sql.= " WHERE n.fk_contact = c.rowid";
169
-				$sql.= " AND a.rowid = n.fk_action";
170
-				$sql.= " AND n.fk_soc = s.rowid";
171
-				if ($notifcode)
172
-				{
173
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
174
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
175
-				}
176
-				$sql.= " AND s.entity IN (".getEntity('societe').")";
177
-				if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
178
-
179
-				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
180
-
181
-				$resql = $this->db->query($sql);
182
-				if ($resql)
183
-				{
184
-					$num = $this->db->num_rows($resql);
185
-					$i=0;
186
-					while ($i < $num)
187
-					{
188
-						$obj = $this->db->fetch_object($resql);
189
-						if ($obj)
190
-						{
191
-							$newval2=trim($obj->email);
192
-							$isvalid=isValidEmail($newval2);
193
-							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
194
-						}
195
-						$i++;
196
-					}
197
-				}
198
-				else
199
-				{
200
-					$error++;
201
-					$this->error=$this->db->lasterror();
202
-				}
203
-			}
204
-		}
205
-
206
-		if (! $error)
207
-		{
208
-			if ($userid >= 0 && in_array('user', $scope))
209
-			{
210
-				$sql = "SELECT a.code, c.email, c.rowid";
211
-				$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
212
-				$sql.= " ".MAIN_DB_PREFIX."user as c,";
213
-				$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a";
214
-				$sql.= " WHERE n.fk_user = c.rowid";
215
-				$sql.= " AND a.rowid = n.fk_action";
216
-				if ($notifcode)
217
-				{
218
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
219
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
220
-				}
221
-				$sql.= " AND c.entity IN (".getEntity('user').")";
222
-				if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
223
-
224
-				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
225
-
226
-				$resql = $this->db->query($sql);
227
-				if ($resql)
228
-				{
229
-					$num = $this->db->num_rows($resql);
230
-					$i=0;
231
-					while ($i < $num)
232
-					{
233
-						$obj = $this->db->fetch_object($resql);
234
-						if ($obj)
235
-						{
236
-							$newval2=trim($obj->email);
237
-							$isvalid=isValidEmail($newval2);
238
-							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
239
-						}
240
-						$i++;
241
-					}
242
-				}
243
-				else
244
-				{
245
-					$error++;
246
-					$this->error=$this->db->lasterror();
247
-				}
248
-			}
249
-		}
250
-
251
-		if (! $error)
252
-		{
253
-			if (in_array('global', $scope))
254
-			{
255
-				// List of notifications enabled for fixed email
256
-				foreach($conf->global as $key => $val)
257
-				{
258
-					if ($notifcode)
259
-					{
260
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
261
-					}
262
-					else
263
-					{
264
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
265
-					}
266
-
267
-					$threshold = (float) $reg[1];
268
-					if ($valueforthreshold < $threshold) continue;
269
-
270
-					$tmpemail=explode(',',$val);
271
-					foreach($tmpemail as $key2 => $val2)
272
-					{
273
-						$newval2=trim($val2);
274
-						if ($newval2 == '__SUPERVISOREMAIL__')
275
-						{
276
-							if ($user->fk_user > 0)
277
-							{
278
-								$tmpuser=new User($this->db);
279
-								$tmpuser->fetch($user->fk_user);
280
-								if ($tmpuser->email) $newval2=trim($tmpuser->email);
281
-								else $newval2='';
282
-							}
283
-							else $newval2='';
284
-						}
285
-						if ($newval2)
286
-						{
287
-							$isvalid=isValidEmail($newval2, 0);
288
-							if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
289
-						}
290
-					}
291
-				}
292
-			}
293
-		}
294
-
295
-		if ($error) return -1;
296
-
297
-		//var_dump($resarray);
298
-		return $resarray;
299
-	}
300
-
301
-	/**
302
-	 *  Check if notification are active for couple action/company.
303
-	 * 	If yes, send mail and save trace into llx_notify.
304
-	 *
305
-	 * 	@param	string	$notifcode			Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
306
-	 * 	@param	Object	$object				Object the notification deals on
307
-	 *	@param 	array	$filename_list		List of files to attach (full path of filename on file system)
308
-	 *	@param 	array	$mimetype_list		List of MIME type of attached files
309
-	 *	@param 	array	$mimefilename_list	List of attached file name in message
310
-	 *	@return	int							<0 if KO, or number of changes if OK
311
-	 */
312
-	function send($notifcode, $object, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
313
-	{
314
-		global $user,$conf,$langs,$mysoc;
315
-		global $hookmanager;
316
-		global $dolibarr_main_url_root;
317
-
318
-		if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
319
-
320
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
321
-		if (! is_object($hookmanager))
322
-		{
323
-			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
324
-			$hookmanager=new HookManager($this->db);
325
-		}
326
-		$hookmanager->initHooks(array('notification'));
327
-
328
-		dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id);
329
-
330
-		$langs->load("other");
331
-
332
-		// Define $urlwithroot
333
-		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
334
-		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;			// This is to use external domain name found into config file
335
-		//$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
336
-
337
-		// Define some vars
338
-		$application = 'Dolibarr';
339
-		if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
340
-		$replyto = $conf->notification->email_from;
341
-		$object_type = '';
342
-		$link = '';
343
-		$num = 0;
344
-
345
-		$oldref=(empty($object->oldref)?$object->ref:$object->oldref);
346
-		$newref=(empty($object->newref)?$object->ref:$object->newref);
347
-
348
-		$sql = '';
349
-
350
-		// Check notification per third party
351
-		if ($object->socid > 0)
352
-		{
353
-			$sql.= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
354
-			$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
355
-			$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
356
-			$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
357
-			$sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
358
-			$sql.= " ".MAIN_DB_PREFIX."societe as s";
359
-			$sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
360
-			$sql.= " AND n.fk_soc = s.rowid";
361
-			if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
362
-			else $sql.= " AND a.code = '".$notifcode."'";	// New usage
363
-			$sql .= " AND s.rowid = ".$object->socid;
364
-
365
-			$sql.= "\nUNION\n";
366
-		}
367
-
368
-		// Check notification per user
369
-		$sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
370
-		$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
371
-		$sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
372
-		$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
373
-		$sql.= " ".MAIN_DB_PREFIX."notify_def as n";
374
-		$sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
375
-		if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
376
-		else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";	// New usage
377
-
378
-		$result = $this->db->query($sql);
379
-		if ($result)
380
-		{
381
-			$num = $this->db->num_rows($result);
382
-			$projtitle='';
383
-			if (! empty($object->fk_project))
384
-			{
385
-				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
386
-				$proj = new Project($this->db);
387
-				$proj->fetch($object->fk_project);
388
-				$projtitle='('.$proj->title.')';
389
-			}
390
-
391
-			if ($num > 0)
392
-			{
393
-				$i = 0;
394
-				while ($i < $num && ! $error)	// For each notification couple defined (third party/actioncode)
395
-				{
396
-					$obj = $this->db->fetch_object($result);
397
-
398
-					$sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">";
399
-					$notifcodedefid = $obj->adid;
400
-
401
-					if (dol_strlen($obj->email))
402
-					{
403
-						// Set output language
404
-						$outputlangs = $langs;
405
-						if ($obj->default_lang && $obj->default_lang != $langs->defaultlang)
406
-						{
407
-							$outputlangs = new Translate('', $conf);
408
-							$outputlangs->setDefaultLang($obj->default_lang);
409
-							$outputlangs->loadLangs(array("main","other"));
410
-						}
411
-
412
-						$subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:'');
413
-
414
-						switch ($notifcode) {
415
-							case 'BILL_VALIDATE':
416
-								$link='/compta/facture/card.php?facid='.$object->id;
417
-								$dir_output = $conf->facture->dir_output;
418
-								$object_type = 'facture';
419
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
420
-								break;
421
-							case 'BILL_PAYED':
422
-								$link='/compta/facture/card.php?facid='.$object->id;
423
-								$dir_output = $conf->facture->dir_output;
424
-								$object_type = 'facture';
425
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
426
-								break;
427
-							case 'ORDER_VALIDATE':
428
-								$link='/commande/card.php?id='.$object->id;
429
-								$dir_output = $conf->commande->dir_output;
430
-								$object_type = 'order';
431
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
432
-								break;
433
-							case 'PROPAL_VALIDATE':
434
-								$link='/comm/propal/card.php?id='.$object->id;
435
-								$dir_output = $conf->propal->multidir_output[$object->entity];
436
-								$object_type = 'propal';
437
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
438
-								break;
439
-							case 'PROPAL_CLOSE_SIGNED':
440
-								$link='/comm/propal/card.php?id='.$object->id;
441
-								$dir_output = $conf->propal->multidir_output[$object->entity];
442
-								$object_type = 'propal';
443
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
444
-								break;
445
-							case 'FICHINTER_ADD_CONTACT':
446
-								$link='/fichinter/card.php?id='.$object->id;
447
-								$dir_output = $conf->ficheinter->dir_output;
448
-								$object_type = 'ficheinter';
449
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref);
450
-								break;
451
-							case 'FICHINTER_VALIDATE':
452
-								$link='/fichinter/card.php?id='.$object->id;
453
-								$dir_output = $conf->ficheinter->dir_output;
454
-								$object_type = 'ficheinter';
455
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref);
456
-								break;
457
-							case 'ORDER_SUPPLIER_VALIDATE':
458
-								$link='/fourn/commande/card.php?id='.$object->id;
459
-								$dir_output = $conf->fournisseur->commande->dir_output;
460
-								$object_type = 'order_supplier';
461
-								$mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
462
-								$mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs));
463
-								$mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
464
-								break;
465
-							case 'ORDER_SUPPLIER_APPROVE':
466
-								$link='/fourn/commande/card.php?id='.$object->id;
467
-								$dir_output = $conf->fournisseur->commande->dir_output;
468
-								$object_type = 'order_supplier';
469
-								$mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
470
-								$mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
471
-								$mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
472
-								break;
473
-							case 'ORDER_SUPPLIER_REFUSE':
474
-								$link='/fourn/commande/card.php?id='.$object->id;
475
-								$dir_output = $conf->fournisseur->commande->dir_output;
476
-								$object_type = 'order_supplier';
477
-								$mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
478
-								$mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
479
-								$mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
480
-								break;
481
-							case 'SHIPPING_VALIDATE':
482
-								$dir_output = $conf->expedition->dir_output.'/sending/';
483
-								$object_type = 'order_supplier';
484
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
485
-								break;
486
-							case 'EXPENSE_REPORT_VALIDATE':
487
-								$dir_output = $conf->expensereport->dir_output;
488
-								$object_type = 'expensereport';
489
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref);
490
-								break;
491
-							case 'EXPENSE_REPORT_APPROVE':
492
-								$dir_output = $conf->expensereport->dir_output;
493
-								$object_type = 'expensereport';
494
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref);
495
-								break;
496
-							case 'HOLIDAY_VALIDATE':
497
-								$dir_output = $conf->holiday->dir_output;
498
-								$object_type = 'holiday';
499
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref);
500
-								break;
501
-							case 'HOLIDAY_APPROVE':
502
-								$dir_output = $conf->holiday->dir_output;
503
-								$object_type = 'holiday';
504
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref);
505
-								break;
506
-						}
507
-						$ref = dol_sanitizeFileName($newref);
508
-						$pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
509
-						if (! dol_is_file($pdf_path))
510
-						{
511
-							// We can't add PDF as it is not generated yet.
512
-							$filepdf = '';
513
-						}
514
-						else
515
-						{
516
-							$filepdf = $pdf_path;
517
-						}
518
-
519
-						$message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
520
-						$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
521
-						$message.= "\n";
522
-						$message.= $mesg;
523
-						if ($link) $message.= "\n" . $urlwithroot . $link;
524
-
525
-						$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
526
-						$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
527
-						if (empty($reshook))
528
-						{
529
-							if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
530
-							if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
531
-						}
532
-
533
-						$mailfile = new CMailFile(
534
-							$subject,
535
-							$sendto,
536
-							$replyto,
537
-							$message,
538
-							$filename_list,
539
-							$mimetype_list,
540
-							$mimefilename_list,
541
-							'',
542
-							'',
543
-							0,
544
-							-1
545
-						);
546
-
547
-						if ($mailfile->sendfile())
548
-						{
549
-							if ($obj->type_target == 'touserid') {
550
-	 							$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
551
-								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
552
-							}
553
-							else {
554
-								$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
555
-								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
556
-							}
557
-							if (! $this->db->query($sql))
558
-							{
559
-								dol_print_error($this->db);
560
-							}
561
-						}
562
-						else
563
-						{
564
-							$error++;
565
-							$this->errors[]=$mailfile->error;
566
-						}
567
-					}
568
-					else
569
-				  {
570
-						dol_syslog("No notification sent for ".$sendto." because email is empty");
571
-					}
572
-					$i++;
573
-				}
574
-			}
575
-			else
576
-			{
577
-				dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid);
578
-			}
579
-		}
580
-		else
581
-		{
582
-	   		$error++;
583
-			$this->errors[]=$this->db->lasterror();
584
-			dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
585
-	   		return -1;
586
-		}
587
-
588
-		// Check notification using fixed email
589
-		if (! $error)
590
-		{
591
-			foreach($conf->global as $key => $val)
592
-			{
593
-				if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
594
-
595
-				$threshold = (float) $reg[1];
596
-				if (!empty($object->total_ht) && $object->total_ht <= $threshold)
597
-				{
598
-					dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification");
599
-					continue;
600
-				}
601
-
602
-				$param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
603
-
604
-				$sendto = $conf->global->$param;
605
-				$notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
606
-				if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code');
607
-
608
-				$object_type = '';
609
-				$link = '';
610
-				$num++;
611
-
612
-				$subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:'');
613
-
614
-				switch ($notifcode) {
615
-					case 'BILL_VALIDATE':
616
-						$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>';
617
-						$dir_output = $conf->facture->dir_output;
618
-						$object_type = 'facture';
619
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link);
620
-						break;
621
-					case 'BILL_PAYED':
622
-						$link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>';
623
-						$dir_output = $conf->facture->dir_output;
624
-						$object_type = 'facture';
625
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link);
626
-						break;
627
-					case 'ORDER_VALIDATE':
628
-						$link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
629
-						$dir_output = $conf->commande->dir_output;
630
-						$object_type = 'order';
631
-						$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link);
632
-						break;
633
-					case 'PROPAL_VALIDATE':
634
-						$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
635
-						$dir_output = $conf->propal->multidir_output[$object->entity];
636
-						$object_type = 'propal';
637
-						$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link);
638
-						break;
639
-					case 'PROPAL_CLOSE_SIGNED':
640
-						$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
641
-						$dir_output = $conf->propal->multidir_output[$object->entity];
642
-						$object_type = 'propal';
643
-						$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link);
644
-						break;
645
-					case 'FICHINTER_ADD_CONTACT':
646
-						$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
647
-						$dir_output = $conf->facture->dir_output;
648
-						$object_type = 'ficheinter';
649
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link);
650
-						break;
651
-					case 'FICHINTER_VALIDATE':
652
-						$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
653
-						$dir_output = $conf->facture->dir_output;
654
-						$object_type = 'ficheinter';
655
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link);
656
-						break;
657
-					case 'ORDER_SUPPLIER_VALIDATE':
658
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
659
-						$dir_output = $conf->fournisseur->commande->dir_output;
660
-						$object_type = 'order_supplier';
661
-						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
662
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs));
663
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
664
-						break;
665
-					case 'ORDER_SUPPLIER_APPROVE':
666
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
667
-						$dir_output = $conf->fournisseur->commande->dir_output;
668
-						$object_type = 'order_supplier';
669
-						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
670
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
671
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
672
-						break;
673
-					case 'ORDER_SUPPLIER_APPROVE2':
674
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
675
-						$dir_output = $conf->fournisseur->commande->dir_output;
676
-						$object_type = 'order_supplier';
677
-						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
678
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
679
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
680
-						break;
681
-					case 'ORDER_SUPPLIER_REFUSE':
682
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
683
-						$dir_output = $conf->fournisseur->dir_output.'/commande/';
684
-						$object_type = 'order_supplier';
685
-						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
686
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs));
687
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
688
-						break;
689
-					case 'SHIPPING_VALIDATE':
690
-						$dir_output = $conf->expedition->dir_output.'/sending/';
691
-						$object_type = 'order_supplier';
692
-						$mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
693
-						break;
694
-					case 'EXPENSE_REPORT_VALIDATE':
695
-						$dir_output = $conf->expensereport->dir_output;
696
-						$object_type = 'expensereport';
697
-						$mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref);
698
-						break;
699
-					case 'EXPENSE_REPORT_APPROVE':
700
-						$dir_output = $conf->expensereport->dir_output;
701
-						$object_type = 'expensereport';
702
-						$mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref);
703
-						break;
704
-					case 'HOLIDAY_VALIDATE':
705
-						$dir_output = $conf->holiday->dir_output;
706
-						$object_type = 'holiday';
707
-						$mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref);
708
-						break;
709
-					case 'HOLIDAY_APPROVE':
710
-						$dir_output = $conf->holiday->dir_output;
711
-						$object_type = 'holiday';
712
-						$mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref);
713
-						break;
714
-				}
715
-				$ref = dol_sanitizeFileName($newref);
716
-				$pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
717
-				if (! dol_is_file($pdf_path))
718
-				{
719
-					// We can't add PDF as it is not generated yet.
720
-					$filepdf = '';
721
-				}
722
-				else
723
-				{
724
-					$filepdf = $pdf_path;
725
-				}
726
-
727
-				$message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
728
-				$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
729
-				$message.= "\n";
730
-				$message.= $mesg;
731
-				//if ($link) $message.= "\n" . $urlwithroot . $link;	// link already added around the ref into the text
732
-
733
-				$message = nl2br($message);
734
-
735
-				// Replace keyword __SUPERVISOREMAIL__
736
-				if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
737
-				{
738
-					$newval='';
739
-					if ($user->fk_user > 0)
740
-					{
741
-						$supervisoruser=new User($this->db);
742
-						$supervisoruser->fetch($user->fk_user);
743
-						if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
744
-					}
745
-					dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
746
-					$sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
747
-					$sendto = preg_replace('/,\s*,/', ',', $sendto);	// in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email,  , othermail" and it's not valid
748
-					$sendto = preg_replace('/^[\s,]+/', '', $sendto);	// Clean start of string
749
-					$sendto = preg_replace('/[\s,]+$/', '', $sendto);	// Clean end of string
750
-				}
751
-
752
-				if ($sendto)
753
-				{
754
-					$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
755
-					$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
756
-					if (empty($reshook))
757
-					{
758
-						if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
759
-						if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
760
-					}
761
-					$mailfile = new CMailFile(
762
-						$subject,
763
-						$sendto,
764
-						$replyto,
765
-						$message,
766
-						$filename_list,
767
-						$mimetype_list,
768
-						$mimefilename_list,
769
-						'',
770
-						'',
771
-						0,
772
-						1
773
-					);
774
-
775
-					if ($mailfile->sendfile())
776
-					{
777
-						$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
778
-						$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
779
-						if (! $this->db->query($sql))
780
-						{
781
-							dol_print_error($this->db);
782
-						}
783
-					}
784
-					else
785
-					{
786
-						$error++;
787
-						$this->errors[]=$mailfile->error;
788
-					}
789
-				}
790
-			}
791
-		}
792
-
793
-		if (! $error) return $num;
794
-		else return -1 * $error;
795
-	}
65
+    // Les codes actions sont definis dans la table llx_notify_def
66
+
67
+    // codes actions supported are
68
+    // @TODO defined also into interface_50_modNotificiation_Notificiation.class.php
69
+    public $arrayofnotifsupported = array(
70
+        'BILL_VALIDATE',
71
+        'BILL_PAYED',
72
+        'ORDER_VALIDATE',
73
+        'PROPAL_VALIDATE',
74
+        'PROPAL_CLOSE_SIGNED',
75
+        'FICHINTER_VALIDATE',
76
+        'FICHINTER_ADD_CONTACT',
77
+        'ORDER_SUPPLIER_VALIDATE',
78
+        'ORDER_SUPPLIER_APPROVE',
79
+        'ORDER_SUPPLIER_REFUSE',
80
+        'SHIPPING_VALIDATE',
81
+        'EXPENSE_REPORT_VALIDATE',
82
+        'EXPENSE_REPORT_APPROVE',
83
+        'HOLIDAY_VALIDATE',
84
+        'HOLIDAY_APPROVE'
85
+    );
86
+
87
+
88
+    /**
89
+     *	Constructor
90
+     *
91
+     *	@param 		DoliDB		$db		Database handler
92
+     */
93
+    function __construct($db)
94
+    {
95
+        $this->db = $db;
96
+    }
97
+
98
+
99
+    /**
100
+     *  Return message that say how many notification (and to which email) will occurs on requested event.
101
+     *	This is to show confirmation messages before event is recorded.
102
+     *
103
+     * 	@param	string	$action		Id of action in llx_c_action_trigger
104
+     * 	@param	int		$socid		Id of third party
105
+     *  @param	Object	$object		Object the notification is about
106
+     *	@return	string				Message
107
+     */
108
+    function confirmMessage($action,$socid,$object)
109
+    {
110
+        global $langs;
111
+        $langs->load("mails");
112
+
113
+        $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
114
+
115
+        $nb=-1;
116
+        if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
117
+        if ($nb < 0)  $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
118
+        if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
119
+            if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
120
+            if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
121
+
122
+            if (is_array($listofnotiftodo))
123
+            {
124
+            $i=0;
125
+            foreach ($listofnotiftodo as $key => $val)
126
+            {
127
+                if ($i) $texte.=', ';
128
+                else $texte.=' (';
129
+                if ($val['isemailvalid']) $texte.=$val['email'];
130
+                else $texte.=$val['emaildesc'];
131
+                $i++;
132
+            }
133
+            if ($i) $texte.=')';
134
+            }
135
+
136
+        return $texte;
137
+    }
138
+
139
+    /**
140
+     * Return number of notifications activated for action code (and third party)
141
+     *
142
+     * @param	string	$notifcode		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
143
+     * @param	int		$socid			Id of third party or 0 for all thirdparties or -1 for no thirdparties
144
+     * @param	Object	$object			Object the notification is about (need it to check threshold value of some notifications)
145
+     * @param	int		$userid         Id of user or 0 for all users or -1 for no users
146
+     * @param   array   $scope          Scope where to search
147
+     * @return	array|int				<0 if KO, array of notifications to send if OK
148
+     */
149
+    function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
150
+    {
151
+        global $conf, $user;
152
+
153
+        $error=0;
154
+        $resarray=array();
155
+
156
+        $valueforthreshold = 0;
157
+        if (is_object($object)) $valueforthreshold = $object->total_ht;
158
+
159
+        if (! $error)
160
+        {
161
+            if ($socid >= 0 && in_array('thirdparty', $scope))
162
+            {
163
+                $sql = "SELECT a.code, c.email, c.rowid";
164
+                $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
165
+                $sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
166
+                $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
167
+                $sql.= " ".MAIN_DB_PREFIX."societe as s";
168
+                $sql.= " WHERE n.fk_contact = c.rowid";
169
+                $sql.= " AND a.rowid = n.fk_action";
170
+                $sql.= " AND n.fk_soc = s.rowid";
171
+                if ($notifcode)
172
+                {
173
+                    if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
174
+                    else $sql.= " AND a.code = '".$notifcode."'";			// New usage
175
+                }
176
+                $sql.= " AND s.entity IN (".getEntity('societe').")";
177
+                if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
178
+
179
+                dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
180
+
181
+                $resql = $this->db->query($sql);
182
+                if ($resql)
183
+                {
184
+                    $num = $this->db->num_rows($resql);
185
+                    $i=0;
186
+                    while ($i < $num)
187
+                    {
188
+                        $obj = $this->db->fetch_object($resql);
189
+                        if ($obj)
190
+                        {
191
+                            $newval2=trim($obj->email);
192
+                            $isvalid=isValidEmail($newval2);
193
+                            if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
194
+                        }
195
+                        $i++;
196
+                    }
197
+                }
198
+                else
199
+                {
200
+                    $error++;
201
+                    $this->error=$this->db->lasterror();
202
+                }
203
+            }
204
+        }
205
+
206
+        if (! $error)
207
+        {
208
+            if ($userid >= 0 && in_array('user', $scope))
209
+            {
210
+                $sql = "SELECT a.code, c.email, c.rowid";
211
+                $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
212
+                $sql.= " ".MAIN_DB_PREFIX."user as c,";
213
+                $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a";
214
+                $sql.= " WHERE n.fk_user = c.rowid";
215
+                $sql.= " AND a.rowid = n.fk_action";
216
+                if ($notifcode)
217
+                {
218
+                    if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
219
+                    else $sql.= " AND a.code = '".$notifcode."'";			// New usage
220
+                }
221
+                $sql.= " AND c.entity IN (".getEntity('user').")";
222
+                if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
223
+
224
+                dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
225
+
226
+                $resql = $this->db->query($sql);
227
+                if ($resql)
228
+                {
229
+                    $num = $this->db->num_rows($resql);
230
+                    $i=0;
231
+                    while ($i < $num)
232
+                    {
233
+                        $obj = $this->db->fetch_object($resql);
234
+                        if ($obj)
235
+                        {
236
+                            $newval2=trim($obj->email);
237
+                            $isvalid=isValidEmail($newval2);
238
+                            if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
239
+                        }
240
+                        $i++;
241
+                    }
242
+                }
243
+                else
244
+                {
245
+                    $error++;
246
+                    $this->error=$this->db->lasterror();
247
+                }
248
+            }
249
+        }
250
+
251
+        if (! $error)
252
+        {
253
+            if (in_array('global', $scope))
254
+            {
255
+                // List of notifications enabled for fixed email
256
+                foreach($conf->global as $key => $val)
257
+                {
258
+                    if ($notifcode)
259
+                    {
260
+                        if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
261
+                    }
262
+                    else
263
+                    {
264
+                        if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
265
+                    }
266
+
267
+                    $threshold = (float) $reg[1];
268
+                    if ($valueforthreshold < $threshold) continue;
269
+
270
+                    $tmpemail=explode(',',$val);
271
+                    foreach($tmpemail as $key2 => $val2)
272
+                    {
273
+                        $newval2=trim($val2);
274
+                        if ($newval2 == '__SUPERVISOREMAIL__')
275
+                        {
276
+                            if ($user->fk_user > 0)
277
+                            {
278
+                                $tmpuser=new User($this->db);
279
+                                $tmpuser->fetch($user->fk_user);
280
+                                if ($tmpuser->email) $newval2=trim($tmpuser->email);
281
+                                else $newval2='';
282
+                            }
283
+                            else $newval2='';
284
+                        }
285
+                        if ($newval2)
286
+                        {
287
+                            $isvalid=isValidEmail($newval2, 0);
288
+                            if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
289
+                        }
290
+                    }
291
+                }
292
+            }
293
+        }
294
+
295
+        if ($error) return -1;
296
+
297
+        //var_dump($resarray);
298
+        return $resarray;
299
+    }
300
+
301
+    /**
302
+     *  Check if notification are active for couple action/company.
303
+     * 	If yes, send mail and save trace into llx_notify.
304
+     *
305
+     * 	@param	string	$notifcode			Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
306
+     * 	@param	Object	$object				Object the notification deals on
307
+     *	@param 	array	$filename_list		List of files to attach (full path of filename on file system)
308
+     *	@param 	array	$mimetype_list		List of MIME type of attached files
309
+     *	@param 	array	$mimefilename_list	List of attached file name in message
310
+     *	@return	int							<0 if KO, or number of changes if OK
311
+     */
312
+    function send($notifcode, $object, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
313
+    {
314
+        global $user,$conf,$langs,$mysoc;
315
+        global $hookmanager;
316
+        global $dolibarr_main_url_root;
317
+
318
+        if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
319
+
320
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
321
+        if (! is_object($hookmanager))
322
+        {
323
+            include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
324
+            $hookmanager=new HookManager($this->db);
325
+        }
326
+        $hookmanager->initHooks(array('notification'));
327
+
328
+        dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id);
329
+
330
+        $langs->load("other");
331
+
332
+        // Define $urlwithroot
333
+        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
334
+        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;			// This is to use external domain name found into config file
335
+        //$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
336
+
337
+        // Define some vars
338
+        $application = 'Dolibarr';
339
+        if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
340
+        $replyto = $conf->notification->email_from;
341
+        $object_type = '';
342
+        $link = '';
343
+        $num = 0;
344
+
345
+        $oldref=(empty($object->oldref)?$object->ref:$object->oldref);
346
+        $newref=(empty($object->newref)?$object->ref:$object->newref);
347
+
348
+        $sql = '';
349
+
350
+        // Check notification per third party
351
+        if ($object->socid > 0)
352
+        {
353
+            $sql.= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
354
+            $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
355
+            $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
356
+            $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
357
+            $sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
358
+            $sql.= " ".MAIN_DB_PREFIX."societe as s";
359
+            $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
360
+            $sql.= " AND n.fk_soc = s.rowid";
361
+            if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
362
+            else $sql.= " AND a.code = '".$notifcode."'";	// New usage
363
+            $sql .= " AND s.rowid = ".$object->socid;
364
+
365
+            $sql.= "\nUNION\n";
366
+        }
367
+
368
+        // Check notification per user
369
+        $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
370
+        $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
371
+        $sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
372
+        $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
373
+        $sql.= " ".MAIN_DB_PREFIX."notify_def as n";
374
+        $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
375
+        if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
376
+        else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";	// New usage
377
+
378
+        $result = $this->db->query($sql);
379
+        if ($result)
380
+        {
381
+            $num = $this->db->num_rows($result);
382
+            $projtitle='';
383
+            if (! empty($object->fk_project))
384
+            {
385
+                require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
386
+                $proj = new Project($this->db);
387
+                $proj->fetch($object->fk_project);
388
+                $projtitle='('.$proj->title.')';
389
+            }
390
+
391
+            if ($num > 0)
392
+            {
393
+                $i = 0;
394
+                while ($i < $num && ! $error)	// For each notification couple defined (third party/actioncode)
395
+                {
396
+                    $obj = $this->db->fetch_object($result);
397
+
398
+                    $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">";
399
+                    $notifcodedefid = $obj->adid;
400
+
401
+                    if (dol_strlen($obj->email))
402
+                    {
403
+                        // Set output language
404
+                        $outputlangs = $langs;
405
+                        if ($obj->default_lang && $obj->default_lang != $langs->defaultlang)
406
+                        {
407
+                            $outputlangs = new Translate('', $conf);
408
+                            $outputlangs->setDefaultLang($obj->default_lang);
409
+                            $outputlangs->loadLangs(array("main","other"));
410
+                        }
411
+
412
+                        $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:'');
413
+
414
+                        switch ($notifcode) {
415
+                            case 'BILL_VALIDATE':
416
+                                $link='/compta/facture/card.php?facid='.$object->id;
417
+                                $dir_output = $conf->facture->dir_output;
418
+                                $object_type = 'facture';
419
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
420
+                                break;
421
+                            case 'BILL_PAYED':
422
+                                $link='/compta/facture/card.php?facid='.$object->id;
423
+                                $dir_output = $conf->facture->dir_output;
424
+                                $object_type = 'facture';
425
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
426
+                                break;
427
+                            case 'ORDER_VALIDATE':
428
+                                $link='/commande/card.php?id='.$object->id;
429
+                                $dir_output = $conf->commande->dir_output;
430
+                                $object_type = 'order';
431
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
432
+                                break;
433
+                            case 'PROPAL_VALIDATE':
434
+                                $link='/comm/propal/card.php?id='.$object->id;
435
+                                $dir_output = $conf->propal->multidir_output[$object->entity];
436
+                                $object_type = 'propal';
437
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
438
+                                break;
439
+                            case 'PROPAL_CLOSE_SIGNED':
440
+                                $link='/comm/propal/card.php?id='.$object->id;
441
+                                $dir_output = $conf->propal->multidir_output[$object->entity];
442
+                                $object_type = 'propal';
443
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
444
+                                break;
445
+                            case 'FICHINTER_ADD_CONTACT':
446
+                                $link='/fichinter/card.php?id='.$object->id;
447
+                                $dir_output = $conf->ficheinter->dir_output;
448
+                                $object_type = 'ficheinter';
449
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref);
450
+                                break;
451
+                            case 'FICHINTER_VALIDATE':
452
+                                $link='/fichinter/card.php?id='.$object->id;
453
+                                $dir_output = $conf->ficheinter->dir_output;
454
+                                $object_type = 'ficheinter';
455
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref);
456
+                                break;
457
+                            case 'ORDER_SUPPLIER_VALIDATE':
458
+                                $link='/fourn/commande/card.php?id='.$object->id;
459
+                                $dir_output = $conf->fournisseur->commande->dir_output;
460
+                                $object_type = 'order_supplier';
461
+                                $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
462
+                                $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs));
463
+                                $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
464
+                                break;
465
+                            case 'ORDER_SUPPLIER_APPROVE':
466
+                                $link='/fourn/commande/card.php?id='.$object->id;
467
+                                $dir_output = $conf->fournisseur->commande->dir_output;
468
+                                $object_type = 'order_supplier';
469
+                                $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
470
+                                $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
471
+                                $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
472
+                                break;
473
+                            case 'ORDER_SUPPLIER_REFUSE':
474
+                                $link='/fourn/commande/card.php?id='.$object->id;
475
+                                $dir_output = $conf->fournisseur->commande->dir_output;
476
+                                $object_type = 'order_supplier';
477
+                                $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
478
+                                $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
479
+                                $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
480
+                                break;
481
+                            case 'SHIPPING_VALIDATE':
482
+                                $dir_output = $conf->expedition->dir_output.'/sending/';
483
+                                $object_type = 'order_supplier';
484
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
485
+                                break;
486
+                            case 'EXPENSE_REPORT_VALIDATE':
487
+                                $dir_output = $conf->expensereport->dir_output;
488
+                                $object_type = 'expensereport';
489
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref);
490
+                                break;
491
+                            case 'EXPENSE_REPORT_APPROVE':
492
+                                $dir_output = $conf->expensereport->dir_output;
493
+                                $object_type = 'expensereport';
494
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref);
495
+                                break;
496
+                            case 'HOLIDAY_VALIDATE':
497
+                                $dir_output = $conf->holiday->dir_output;
498
+                                $object_type = 'holiday';
499
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref);
500
+                                break;
501
+                            case 'HOLIDAY_APPROVE':
502
+                                $dir_output = $conf->holiday->dir_output;
503
+                                $object_type = 'holiday';
504
+                                $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref);
505
+                                break;
506
+                        }
507
+                        $ref = dol_sanitizeFileName($newref);
508
+                        $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
509
+                        if (! dol_is_file($pdf_path))
510
+                        {
511
+                            // We can't add PDF as it is not generated yet.
512
+                            $filepdf = '';
513
+                        }
514
+                        else
515
+                        {
516
+                            $filepdf = $pdf_path;
517
+                        }
518
+
519
+                        $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
520
+                        $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
521
+                        $message.= "\n";
522
+                        $message.= $mesg;
523
+                        if ($link) $message.= "\n" . $urlwithroot . $link;
524
+
525
+                        $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
526
+                        $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
527
+                        if (empty($reshook))
528
+                        {
529
+                            if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
530
+                            if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
531
+                        }
532
+
533
+                        $mailfile = new CMailFile(
534
+                            $subject,
535
+                            $sendto,
536
+                            $replyto,
537
+                            $message,
538
+                            $filename_list,
539
+                            $mimetype_list,
540
+                            $mimefilename_list,
541
+                            '',
542
+                            '',
543
+                            0,
544
+                            -1
545
+                        );
546
+
547
+                        if ($mailfile->sendfile())
548
+                        {
549
+                            if ($obj->type_target == 'touserid') {
550
+                                    $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
551
+                                $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
552
+                            }
553
+                            else {
554
+                                $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
555
+                                $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
556
+                            }
557
+                            if (! $this->db->query($sql))
558
+                            {
559
+                                dol_print_error($this->db);
560
+                            }
561
+                        }
562
+                        else
563
+                        {
564
+                            $error++;
565
+                            $this->errors[]=$mailfile->error;
566
+                        }
567
+                    }
568
+                    else
569
+                    {
570
+                        dol_syslog("No notification sent for ".$sendto." because email is empty");
571
+                    }
572
+                    $i++;
573
+                }
574
+            }
575
+            else
576
+            {
577
+                dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid);
578
+            }
579
+        }
580
+        else
581
+        {
582
+                $error++;
583
+            $this->errors[]=$this->db->lasterror();
584
+            dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
585
+                return -1;
586
+        }
587
+
588
+        // Check notification using fixed email
589
+        if (! $error)
590
+        {
591
+            foreach($conf->global as $key => $val)
592
+            {
593
+                if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
594
+
595
+                $threshold = (float) $reg[1];
596
+                if (!empty($object->total_ht) && $object->total_ht <= $threshold)
597
+                {
598
+                    dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification");
599
+                    continue;
600
+                }
601
+
602
+                $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
603
+
604
+                $sendto = $conf->global->$param;
605
+                $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
606
+                if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code');
607
+
608
+                $object_type = '';
609
+                $link = '';
610
+                $num++;
611
+
612
+                $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:'');
613
+
614
+                switch ($notifcode) {
615
+                    case 'BILL_VALIDATE':
616
+                        $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>';
617
+                        $dir_output = $conf->facture->dir_output;
618
+                        $object_type = 'facture';
619
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link);
620
+                        break;
621
+                    case 'BILL_PAYED':
622
+                        $link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>';
623
+                        $dir_output = $conf->facture->dir_output;
624
+                        $object_type = 'facture';
625
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link);
626
+                        break;
627
+                    case 'ORDER_VALIDATE':
628
+                        $link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
629
+                        $dir_output = $conf->commande->dir_output;
630
+                        $object_type = 'order';
631
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link);
632
+                        break;
633
+                    case 'PROPAL_VALIDATE':
634
+                        $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
635
+                        $dir_output = $conf->propal->multidir_output[$object->entity];
636
+                        $object_type = 'propal';
637
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link);
638
+                        break;
639
+                    case 'PROPAL_CLOSE_SIGNED':
640
+                        $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
641
+                        $dir_output = $conf->propal->multidir_output[$object->entity];
642
+                        $object_type = 'propal';
643
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link);
644
+                        break;
645
+                    case 'FICHINTER_ADD_CONTACT':
646
+                        $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
647
+                        $dir_output = $conf->facture->dir_output;
648
+                        $object_type = 'ficheinter';
649
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link);
650
+                        break;
651
+                    case 'FICHINTER_VALIDATE':
652
+                        $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
653
+                        $dir_output = $conf->facture->dir_output;
654
+                        $object_type = 'ficheinter';
655
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link);
656
+                        break;
657
+                    case 'ORDER_SUPPLIER_VALIDATE':
658
+                        $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
659
+                        $dir_output = $conf->fournisseur->commande->dir_output;
660
+                        $object_type = 'order_supplier';
661
+                        $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
662
+                        $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs));
663
+                        $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
664
+                        break;
665
+                    case 'ORDER_SUPPLIER_APPROVE':
666
+                        $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
667
+                        $dir_output = $conf->fournisseur->commande->dir_output;
668
+                        $object_type = 'order_supplier';
669
+                        $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
670
+                        $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
671
+                        $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
672
+                        break;
673
+                    case 'ORDER_SUPPLIER_APPROVE2':
674
+                        $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
675
+                        $dir_output = $conf->fournisseur->commande->dir_output;
676
+                        $object_type = 'order_supplier';
677
+                        $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
678
+                        $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
679
+                        $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
680
+                        break;
681
+                    case 'ORDER_SUPPLIER_REFUSE':
682
+                        $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
683
+                        $dir_output = $conf->fournisseur->dir_output.'/commande/';
684
+                        $object_type = 'order_supplier';
685
+                        $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
686
+                        $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs));
687
+                        $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
688
+                        break;
689
+                    case 'SHIPPING_VALIDATE':
690
+                        $dir_output = $conf->expedition->dir_output.'/sending/';
691
+                        $object_type = 'order_supplier';
692
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
693
+                        break;
694
+                    case 'EXPENSE_REPORT_VALIDATE':
695
+                        $dir_output = $conf->expensereport->dir_output;
696
+                        $object_type = 'expensereport';
697
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref);
698
+                        break;
699
+                    case 'EXPENSE_REPORT_APPROVE':
700
+                        $dir_output = $conf->expensereport->dir_output;
701
+                        $object_type = 'expensereport';
702
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref);
703
+                        break;
704
+                    case 'HOLIDAY_VALIDATE':
705
+                        $dir_output = $conf->holiday->dir_output;
706
+                        $object_type = 'holiday';
707
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref);
708
+                        break;
709
+                    case 'HOLIDAY_APPROVE':
710
+                        $dir_output = $conf->holiday->dir_output;
711
+                        $object_type = 'holiday';
712
+                        $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref);
713
+                        break;
714
+                }
715
+                $ref = dol_sanitizeFileName($newref);
716
+                $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
717
+                if (! dol_is_file($pdf_path))
718
+                {
719
+                    // We can't add PDF as it is not generated yet.
720
+                    $filepdf = '';
721
+                }
722
+                else
723
+                {
724
+                    $filepdf = $pdf_path;
725
+                }
726
+
727
+                $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
728
+                $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
729
+                $message.= "\n";
730
+                $message.= $mesg;
731
+                //if ($link) $message.= "\n" . $urlwithroot . $link;	// link already added around the ref into the text
732
+
733
+                $message = nl2br($message);
734
+
735
+                // Replace keyword __SUPERVISOREMAIL__
736
+                if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
737
+                {
738
+                    $newval='';
739
+                    if ($user->fk_user > 0)
740
+                    {
741
+                        $supervisoruser=new User($this->db);
742
+                        $supervisoruser->fetch($user->fk_user);
743
+                        if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
744
+                    }
745
+                    dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
746
+                    $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
747
+                    $sendto = preg_replace('/,\s*,/', ',', $sendto);	// in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email,  , othermail" and it's not valid
748
+                    $sendto = preg_replace('/^[\s,]+/', '', $sendto);	// Clean start of string
749
+                    $sendto = preg_replace('/[\s,]+$/', '', $sendto);	// Clean end of string
750
+                }
751
+
752
+                if ($sendto)
753
+                {
754
+                    $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
755
+                    $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
756
+                    if (empty($reshook))
757
+                    {
758
+                        if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
759
+                        if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
760
+                    }
761
+                    $mailfile = new CMailFile(
762
+                        $subject,
763
+                        $sendto,
764
+                        $replyto,
765
+                        $message,
766
+                        $filename_list,
767
+                        $mimetype_list,
768
+                        $mimefilename_list,
769
+                        '',
770
+                        '',
771
+                        0,
772
+                        1
773
+                    );
774
+
775
+                    if ($mailfile->sendfile())
776
+                    {
777
+                        $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
778
+                        $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
779
+                        if (! $this->db->query($sql))
780
+                        {
781
+                            dol_print_error($this->db);
782
+                        }
783
+                    }
784
+                    else
785
+                    {
786
+                        $error++;
787
+                        $this->errors[]=$mailfile->error;
788
+                    }
789
+                }
790
+            }
791
+        }
792
+
793
+        if (! $error) return $num;
794
+        else return -1 * $error;
795
+    }
796 796
 }
Please login to merge, or discard this patch.
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *      \ingroup    notification
24 24
  *      \brief      File of class to manage notifications
25 25
  */
26
-require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
26
+require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
27 27
 
28 28
 
29 29
 /**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	/**
45 45
 	 * @var string Error code (or message)
46 46
 	 */
47
-	public $error='';
47
+	public $error = '';
48 48
 
49 49
 	/**
50 50
 	 * @var string[] Error codes (or messages)
@@ -105,32 +105,32 @@  discard block
 block discarded – undo
105 105
 	 *  @param	Object	$object		Object the notification is about
106 106
 	 *	@return	string				Message
107 107
 	 */
108
-	function confirmMessage($action,$socid,$object)
108
+	function confirmMessage($action, $socid, $object)
109 109
 	{
110 110
 		global $langs;
111 111
 		$langs->load("mails");
112 112
 
113
-		$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
113
+		$listofnotiftodo = $this->getNotificationsArray($action, $socid, $object, 0);
114 114
 
115
-		$nb=-1;
116
-		if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
117
-		if ($nb < 0)  $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
118
-		if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
119
-   		if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
120
-   		if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
115
+		$nb = -1;
116
+		if (is_array($listofnotiftodo)) $nb = count($listofnotiftodo);
117
+		if ($nb < 0)  $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
118
+		if ($nb == 0) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("NoNotificationsWillBeSent");
119
+   		if ($nb == 1) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ANotificationsWillBeSent");
120
+   		if ($nb >= 2) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("SomeNotificationsWillBeSent", $nb);
121 121
 
122 122
    		if (is_array($listofnotiftodo))
123 123
    		{
124
-			$i=0;
124
+			$i = 0;
125 125
 			foreach ($listofnotiftodo as $key => $val)
126 126
 			{
127
-				if ($i) $texte.=', ';
128
-				else $texte.=' (';
129
-				if ($val['isemailvalid']) $texte.=$val['email'];
130
-				else $texte.=$val['emaildesc'];
127
+				if ($i) $texte .= ', ';
128
+				else $texte .= ' (';
129
+				if ($val['isemailvalid']) $texte .= $val['email'];
130
+				else $texte .= $val['emaildesc'];
131 131
 				$i++;
132 132
 			}
133
-			if ($i) $texte.=')';
133
+			if ($i) $texte .= ')';
134 134
    		}
135 135
 
136 136
 		return $texte;
@@ -146,35 +146,35 @@  discard block
 block discarded – undo
146 146
 	 * @param   array   $scope          Scope where to search
147 147
 	 * @return	array|int				<0 if KO, array of notifications to send if OK
148 148
 	 */
149
-	function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
149
+	function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global'))
150 150
 	{
151 151
 		global $conf, $user;
152 152
 
153
-		$error=0;
154
-		$resarray=array();
153
+		$error = 0;
154
+		$resarray = array();
155 155
 
156 156
 		$valueforthreshold = 0;
157 157
 		if (is_object($object)) $valueforthreshold = $object->total_ht;
158 158
 
159
-		if (! $error)
159
+		if (!$error)
160 160
 		{
161 161
 			if ($socid >= 0 && in_array('thirdparty', $scope))
162 162
 			{
163 163
 				$sql = "SELECT a.code, c.email, c.rowid";
164
-				$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
165
-				$sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
166
-				$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
167
-				$sql.= " ".MAIN_DB_PREFIX."societe as s";
168
-				$sql.= " WHERE n.fk_contact = c.rowid";
169
-				$sql.= " AND a.rowid = n.fk_action";
170
-				$sql.= " AND n.fk_soc = s.rowid";
164
+				$sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
165
+				$sql .= " ".MAIN_DB_PREFIX."socpeople as c,";
166
+				$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
167
+				$sql .= " ".MAIN_DB_PREFIX."societe as s";
168
+				$sql .= " WHERE n.fk_contact = c.rowid";
169
+				$sql .= " AND a.rowid = n.fk_action";
170
+				$sql .= " AND n.fk_soc = s.rowid";
171 171
 				if ($notifcode)
172 172
 				{
173
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
174
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
173
+					if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage
174
+					else $sql .= " AND a.code = '".$notifcode."'"; // New usage
175 175
 				}
176
-				$sql.= " AND s.entity IN (".getEntity('societe').")";
177
-				if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
176
+				$sql .= " AND s.entity IN (".getEntity('societe').")";
177
+				if ($socid > 0) $sql .= " AND s.rowid = ".$socid;
178 178
 
179 179
 				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
180 180
 
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 				if ($resql)
183 183
 				{
184 184
 					$num = $this->db->num_rows($resql);
185
-					$i=0;
185
+					$i = 0;
186 186
 					while ($i < $num)
187 187
 					{
188 188
 						$obj = $this->db->fetch_object($resql);
189 189
 						if ($obj)
190 190
 						{
191
-							$newval2=trim($obj->email);
192
-							$isvalid=isValidEmail($newval2);
191
+							$newval2 = trim($obj->email);
192
+							$isvalid = isValidEmail($newval2);
193 193
 							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
194 194
 						}
195 195
 						$i++;
@@ -198,28 +198,28 @@  discard block
 block discarded – undo
198 198
 				else
199 199
 				{
200 200
 					$error++;
201
-					$this->error=$this->db->lasterror();
201
+					$this->error = $this->db->lasterror();
202 202
 				}
203 203
 			}
204 204
 		}
205 205
 
206
-		if (! $error)
206
+		if (!$error)
207 207
 		{
208 208
 			if ($userid >= 0 && in_array('user', $scope))
209 209
 			{
210 210
 				$sql = "SELECT a.code, c.email, c.rowid";
211
-				$sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
212
-				$sql.= " ".MAIN_DB_PREFIX."user as c,";
213
-				$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a";
214
-				$sql.= " WHERE n.fk_user = c.rowid";
215
-				$sql.= " AND a.rowid = n.fk_action";
211
+				$sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
212
+				$sql .= " ".MAIN_DB_PREFIX."user as c,";
213
+				$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a";
214
+				$sql .= " WHERE n.fk_user = c.rowid";
215
+				$sql .= " AND a.rowid = n.fk_action";
216 216
 				if ($notifcode)
217 217
 				{
218
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
219
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
218
+					if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage
219
+					else $sql .= " AND a.code = '".$notifcode."'"; // New usage
220 220
 				}
221
-				$sql.= " AND c.entity IN (".getEntity('user').")";
222
-				if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
221
+				$sql .= " AND c.entity IN (".getEntity('user').")";
222
+				if ($userid > 0) $sql .= " AND c.rowid = ".$userid;
223 223
 
224 224
 				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
225 225
 
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 				if ($resql)
228 228
 				{
229 229
 					$num = $this->db->num_rows($resql);
230
-					$i=0;
230
+					$i = 0;
231 231
 					while ($i < $num)
232 232
 					{
233 233
 						$obj = $this->db->fetch_object($resql);
234 234
 						if ($obj)
235 235
 						{
236
-							$newval2=trim($obj->email);
237
-							$isvalid=isValidEmail($newval2);
236
+							$newval2 = trim($obj->email);
237
+							$isvalid = isValidEmail($newval2);
238 238
 							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
239 239
 						}
240 240
 						$i++;
@@ -243,49 +243,49 @@  discard block
 block discarded – undo
243 243
 				else
244 244
 				{
245 245
 					$error++;
246
-					$this->error=$this->db->lasterror();
246
+					$this->error = $this->db->lasterror();
247 247
 				}
248 248
 			}
249 249
 		}
250 250
 
251
-		if (! $error)
251
+		if (!$error)
252 252
 		{
253 253
 			if (in_array('global', $scope))
254 254
 			{
255 255
 				// List of notifications enabled for fixed email
256
-				foreach($conf->global as $key => $val)
256
+				foreach ($conf->global as $key => $val)
257 257
 				{
258 258
 					if ($notifcode)
259 259
 					{
260
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
260
+						if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
261 261
 					}
262 262
 					else
263 263
 					{
264
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
264
+						if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
265 265
 					}
266 266
 
267 267
 					$threshold = (float) $reg[1];
268 268
 					if ($valueforthreshold < $threshold) continue;
269 269
 
270
-					$tmpemail=explode(',',$val);
271
-					foreach($tmpemail as $key2 => $val2)
270
+					$tmpemail = explode(',', $val);
271
+					foreach ($tmpemail as $key2 => $val2)
272 272
 					{
273
-						$newval2=trim($val2);
273
+						$newval2 = trim($val2);
274 274
 						if ($newval2 == '__SUPERVISOREMAIL__')
275 275
 						{
276 276
 							if ($user->fk_user > 0)
277 277
 							{
278
-								$tmpuser=new User($this->db);
278
+								$tmpuser = new User($this->db);
279 279
 								$tmpuser->fetch($user->fk_user);
280
-								if ($tmpuser->email) $newval2=trim($tmpuser->email);
281
-								else $newval2='';
280
+								if ($tmpuser->email) $newval2 = trim($tmpuser->email);
281
+								else $newval2 = '';
282 282
 							}
283
-							else $newval2='';
283
+							else $newval2 = '';
284 284
 						}
285 285
 						if ($newval2)
286 286
 						{
287
-							$isvalid=isValidEmail($newval2, 0);
288
-							if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
287
+							$isvalid = isValidEmail($newval2, 0);
288
+							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
289 289
 						}
290 290
 					}
291 291
 				}
@@ -309,19 +309,19 @@  discard block
 block discarded – undo
309 309
 	 *	@param 	array	$mimefilename_list	List of attached file name in message
310 310
 	 *	@return	int							<0 if KO, or number of changes if OK
311 311
 	 */
312
-	function send($notifcode, $object, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
312
+	function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
313 313
 	{
314
-		global $user,$conf,$langs,$mysoc;
314
+		global $user, $conf, $langs, $mysoc;
315 315
 		global $hookmanager;
316 316
 		global $dolibarr_main_url_root;
317 317
 
318
-		if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
318
+		if (!in_array($notifcode, $this->arrayofnotifsupported)) return 0;
319 319
 
320 320
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
321
-		if (! is_object($hookmanager))
321
+		if (!is_object($hookmanager))
322 322
 		{
323 323
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
324
-			$hookmanager=new HookManager($this->db);
324
+			$hookmanager = new HookManager($this->db);
325 325
 		}
326 326
 		$hookmanager->initHooks(array('notification'));
327 327
 
@@ -330,72 +330,72 @@  discard block
 block discarded – undo
330 330
 		$langs->load("other");
331 331
 
332 332
 		// Define $urlwithroot
333
-		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
334
-		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;			// This is to use external domain name found into config file
333
+		$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
334
+		$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
335 335
 		//$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
336 336
 
337 337
 		// Define some vars
338 338
 		$application = 'Dolibarr';
339
-		if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
339
+		if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
340 340
 		$replyto = $conf->notification->email_from;
341 341
 		$object_type = '';
342 342
 		$link = '';
343 343
 		$num = 0;
344 344
 
345
-		$oldref=(empty($object->oldref)?$object->ref:$object->oldref);
346
-		$newref=(empty($object->newref)?$object->ref:$object->newref);
345
+		$oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
346
+		$newref = (empty($object->newref) ? $object->ref : $object->newref);
347 347
 
348 348
 		$sql = '';
349 349
 
350 350
 		// Check notification per third party
351 351
 		if ($object->socid > 0)
352 352
 		{
353
-			$sql.= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
354
-			$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
355
-			$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
356
-			$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
357
-			$sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
358
-			$sql.= " ".MAIN_DB_PREFIX."societe as s";
359
-			$sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
360
-			$sql.= " AND n.fk_soc = s.rowid";
361
-			if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
362
-			else $sql.= " AND a.code = '".$notifcode."'";	// New usage
353
+			$sql .= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
354
+			$sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
355
+			$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
356
+			$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
357
+			$sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
358
+			$sql .= " ".MAIN_DB_PREFIX."societe as s";
359
+			$sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
360
+			$sql .= " AND n.fk_soc = s.rowid";
361
+			if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage
362
+			else $sql .= " AND a.code = '".$notifcode."'"; // New usage
363 363
 			$sql .= " AND s.rowid = ".$object->socid;
364 364
 
365
-			$sql.= "\nUNION\n";
365
+			$sql .= "\nUNION\n";
366 366
 		}
367 367
 
368 368
 		// Check notification per user
369
-		$sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
370
-		$sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
371
-		$sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
372
-		$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
373
-		$sql.= " ".MAIN_DB_PREFIX."notify_def as n";
374
-		$sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
375
-		if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
376
-		else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";	// New usage
369
+		$sql .= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
370
+		$sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
371
+		$sql .= " FROM ".MAIN_DB_PREFIX."user as c,";
372
+		$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
373
+		$sql .= " ".MAIN_DB_PREFIX."notify_def as n";
374
+		$sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
375
+		if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage
376
+		else $sql .= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
377 377
 
378 378
 		$result = $this->db->query($sql);
379 379
 		if ($result)
380 380
 		{
381 381
 			$num = $this->db->num_rows($result);
382
-			$projtitle='';
383
-			if (! empty($object->fk_project))
382
+			$projtitle = '';
383
+			if (!empty($object->fk_project))
384 384
 			{
385 385
 				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
386 386
 				$proj = new Project($this->db);
387 387
 				$proj->fetch($object->fk_project);
388
-				$projtitle='('.$proj->title.')';
388
+				$projtitle = '('.$proj->title.')';
389 389
 			}
390 390
 
391 391
 			if ($num > 0)
392 392
 			{
393 393
 				$i = 0;
394
-				while ($i < $num && ! $error)	// For each notification couple defined (third party/actioncode)
394
+				while ($i < $num && !$error)	// For each notification couple defined (third party/actioncode)
395 395
 				{
396 396
 					$obj = $this->db->fetch_object($result);
397 397
 
398
-					$sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">";
398
+					$sendto = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
399 399
 					$notifcodedefid = $obj->adid;
400 400
 
401 401
 					if (dol_strlen($obj->email))
@@ -406,107 +406,107 @@  discard block
 block discarded – undo
406 406
 						{
407 407
 							$outputlangs = new Translate('', $conf);
408 408
 							$outputlangs->setDefaultLang($obj->default_lang);
409
-							$outputlangs->loadLangs(array("main","other"));
409
+							$outputlangs->loadLangs(array("main", "other"));
410 410
 						}
411 411
 
412
-						$subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:'');
412
+						$subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
413 413
 
414 414
 						switch ($notifcode) {
415 415
 							case 'BILL_VALIDATE':
416
-								$link='/compta/facture/card.php?facid='.$object->id;
416
+								$link = '/compta/facture/card.php?facid='.$object->id;
417 417
 								$dir_output = $conf->facture->dir_output;
418 418
 								$object_type = 'facture';
419
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
419
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref);
420 420
 								break;
421 421
 							case 'BILL_PAYED':
422
-								$link='/compta/facture/card.php?facid='.$object->id;
422
+								$link = '/compta/facture/card.php?facid='.$object->id;
423 423
 								$dir_output = $conf->facture->dir_output;
424 424
 								$object_type = 'facture';
425
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
425
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed", $newref);
426 426
 								break;
427 427
 							case 'ORDER_VALIDATE':
428
-								$link='/commande/card.php?id='.$object->id;
428
+								$link = '/commande/card.php?id='.$object->id;
429 429
 								$dir_output = $conf->commande->dir_output;
430 430
 								$object_type = 'order';
431
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
431
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated", $newref);
432 432
 								break;
433 433
 							case 'PROPAL_VALIDATE':
434
-								$link='/comm/propal/card.php?id='.$object->id;
434
+								$link = '/comm/propal/card.php?id='.$object->id;
435 435
 								$dir_output = $conf->propal->multidir_output[$object->entity];
436 436
 								$object_type = 'propal';
437
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
437
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated", $newref);
438 438
 								break;
439 439
 							case 'PROPAL_CLOSE_SIGNED':
440
-								$link='/comm/propal/card.php?id='.$object->id;
440
+								$link = '/comm/propal/card.php?id='.$object->id;
441 441
 								$dir_output = $conf->propal->multidir_output[$object->entity];
442 442
 								$object_type = 'propal';
443
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
443
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $newref);
444 444
 								break;
445 445
 							case 'FICHINTER_ADD_CONTACT':
446
-								$link='/fichinter/card.php?id='.$object->id;
446
+								$link = '/fichinter/card.php?id='.$object->id;
447 447
 								$dir_output = $conf->ficheinter->dir_output;
448 448
 								$object_type = 'ficheinter';
449
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref);
449
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $newref);
450 450
 								break;
451 451
 							case 'FICHINTER_VALIDATE':
452
-								$link='/fichinter/card.php?id='.$object->id;
452
+								$link = '/fichinter/card.php?id='.$object->id;
453 453
 								$dir_output = $conf->ficheinter->dir_output;
454 454
 								$object_type = 'ficheinter';
455
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref);
455
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated", $newref);
456 456
 								break;
457 457
 							case 'ORDER_SUPPLIER_VALIDATE':
458
-								$link='/fourn/commande/card.php?id='.$object->id;
458
+								$link = '/fourn/commande/card.php?id='.$object->id;
459 459
 								$dir_output = $conf->fournisseur->commande->dir_output;
460 460
 								$object_type = 'order_supplier';
461 461
 								$mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
462
-								$mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs));
463
-								$mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
462
+								$mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $newref, $user->getFullName($langs));
463
+								$mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
464 464
 								break;
465 465
 							case 'ORDER_SUPPLIER_APPROVE':
466
-								$link='/fourn/commande/card.php?id='.$object->id;
466
+								$link = '/fourn/commande/card.php?id='.$object->id;
467 467
 								$dir_output = $conf->fournisseur->commande->dir_output;
468 468
 								$object_type = 'order_supplier';
469 469
 								$mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
470
-								$mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
471
-								$mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
470
+								$mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
471
+								$mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
472 472
 								break;
473 473
 							case 'ORDER_SUPPLIER_REFUSE':
474
-								$link='/fourn/commande/card.php?id='.$object->id;
474
+								$link = '/fourn/commande/card.php?id='.$object->id;
475 475
 								$dir_output = $conf->fournisseur->commande->dir_output;
476 476
 								$object_type = 'order_supplier';
477 477
 								$mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
478
-								$mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
479
-								$mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
478
+								$mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs));
479
+								$mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
480 480
 								break;
481 481
 							case 'SHIPPING_VALIDATE':
482 482
 								$dir_output = $conf->expedition->dir_output.'/sending/';
483 483
 								$object_type = 'order_supplier';
484
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
484
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref);
485 485
 								break;
486 486
 							case 'EXPENSE_REPORT_VALIDATE':
487 487
 								$dir_output = $conf->expensereport->dir_output;
488 488
 								$object_type = 'expensereport';
489
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref);
489
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $newref);
490 490
 								break;
491 491
 							case 'EXPENSE_REPORT_APPROVE':
492 492
 								$dir_output = $conf->expensereport->dir_output;
493 493
 								$object_type = 'expensereport';
494
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref);
494
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $newref);
495 495
 								break;
496 496
 							case 'HOLIDAY_VALIDATE':
497 497
 								$dir_output = $conf->holiday->dir_output;
498 498
 								$object_type = 'holiday';
499
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref);
499
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated", $newref);
500 500
 								break;
501 501
 							case 'HOLIDAY_APPROVE':
502 502
 								$dir_output = $conf->holiday->dir_output;
503 503
 								$object_type = 'holiday';
504
-								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref);
504
+								$mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved", $newref);
505 505
 								break;
506 506
 						}
507 507
 						$ref = dol_sanitizeFileName($newref);
508 508
 						$pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
509
-						if (! dol_is_file($pdf_path))
509
+						if (!dol_is_file($pdf_path))
510 510
 						{
511 511
 							// We can't add PDF as it is not generated yet.
512 512
 							$filepdf = '';
@@ -516,18 +516,18 @@  discard block
 block discarded – undo
516 516
 							$filepdf = $pdf_path;
517 517
 						}
518 518
 
519
-						$message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
520
-						$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
521
-						$message.= "\n";
522
-						$message.= $mesg;
523
-						if ($link) $message.= "\n" . $urlwithroot . $link;
519
+						$message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n";
520
+						$message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
521
+						$message .= "\n";
522
+						$message .= $mesg;
523
+						if ($link) $message .= "\n".$urlwithroot.$link;
524 524
 
525
-						$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
526
-						$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
525
+						$parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
526
+						$reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
527 527
 						if (empty($reshook))
528 528
 						{
529
-							if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
530
-							if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
529
+							if (!empty($hookmanager->resArray['subject'])) $subject .= $hookmanager->resArray['subject'];
530
+							if (!empty($hookmanager->resArray['message'])) $message .= $hookmanager->resArray['message'];
531 531
 						}
532 532
 
533 533
 						$mailfile = new CMailFile(
@@ -548,13 +548,13 @@  discard block
 block discarded – undo
548 548
 						{
549 549
 							if ($obj->type_target == 'touserid') {
550 550
 	 							$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
551
-								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
551
+								$sql .= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid ? $object->socid : 'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
552 552
 							}
553 553
 							else {
554 554
 								$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
555
-								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
555
+								$sql .= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid ? $object->socid : 'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
556 556
 							}
557
-							if (! $this->db->query($sql))
557
+							if (!$this->db->query($sql))
558 558
 							{
559 559
 								dol_print_error($this->db);
560 560
 							}
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 						else
563 563
 						{
564 564
 							$error++;
565
-							$this->errors[]=$mailfile->error;
565
+							$this->errors[] = $mailfile->error;
566 566
 						}
567 567
 					}
568 568
 					else
@@ -580,17 +580,17 @@  discard block
 block discarded – undo
580 580
 		else
581 581
 		{
582 582
 	   		$error++;
583
-			$this->errors[]=$this->db->lasterror();
583
+			$this->errors[] = $this->db->lasterror();
584 584
 			dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
585 585
 	   		return -1;
586 586
 		}
587 587
 
588 588
 		// Check notification using fixed email
589
-		if (! $error)
589
+		if (!$error)
590 590
 		{
591
-			foreach($conf->global as $key => $val)
591
+			foreach ($conf->global as $key => $val)
592 592
 			{
593
-				if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
593
+				if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
594 594
 
595 595
 				$threshold = (float) $reg[1];
596 596
 				if (!empty($object->total_ht) && $object->total_ht <= $threshold)
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 					continue;
600 600
 				}
601 601
 
602
-				$param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
602
+				$param = 'NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
603 603
 
604 604
 				$sendto = $conf->global->$param;
605 605
 				$notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
@@ -609,112 +609,112 @@  discard block
 block discarded – undo
609 609
 				$link = '';
610 610
 				$num++;
611 611
 
612
-				$subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:'');
612
+				$subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
613 613
 
614 614
 				switch ($notifcode) {
615 615
 					case 'BILL_VALIDATE':
616
-						$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>';
616
+						$link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'">'.$newref.'</a>';
617 617
 						$dir_output = $conf->facture->dir_output;
618 618
 						$object_type = 'facture';
619
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link);
619
+						$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link);
620 620
 						break;
621 621
 					case 'BILL_PAYED':
622
-						$link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>';
622
+						$link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'">'.$newref.'</a>';
623 623
 						$dir_output = $conf->facture->dir_output;
624 624
 						$object_type = 'facture';
625
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link);
625
+						$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $link);
626 626
 						break;
627 627
 					case 'ORDER_VALIDATE':
628
-						$link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
628
+						$link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'">'.$newref.'</a>';
629 629
 						$dir_output = $conf->commande->dir_output;
630 630
 						$object_type = 'order';
631
-						$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link);
631
+						$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $link);
632 632
 						break;
633 633
 					case 'PROPAL_VALIDATE':
634
-						$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
634
+						$link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'">'.$newref.'</a>';
635 635
 						$dir_output = $conf->propal->multidir_output[$object->entity];
636 636
 						$object_type = 'propal';
637
-						$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link);
637
+						$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $link);
638 638
 						break;
639 639
 					case 'PROPAL_CLOSE_SIGNED':
640
-						$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
640
+						$link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'">'.$newref.'</a>';
641 641
 						$dir_output = $conf->propal->multidir_output[$object->entity];
642 642
 						$object_type = 'propal';
643
-						$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link);
643
+						$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link);
644 644
 						break;
645 645
 					case 'FICHINTER_ADD_CONTACT':
646
-						$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
646
+						$link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'">'.$newref.'</a>';
647 647
 						$dir_output = $conf->facture->dir_output;
648 648
 						$object_type = 'ficheinter';
649
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link);
649
+						$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link);
650 650
 						break;
651 651
 					case 'FICHINTER_VALIDATE':
652
-						$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
652
+						$link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'">'.$newref.'</a>';
653 653
 						$dir_output = $conf->facture->dir_output;
654 654
 						$object_type = 'ficheinter';
655
-						$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link);
655
+						$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link);
656 656
 						break;
657 657
 					case 'ORDER_SUPPLIER_VALIDATE':
658
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
658
+						$link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'">'.$newref.'</a>';
659 659
 						$dir_output = $conf->fournisseur->commande->dir_output;
660 660
 						$object_type = 'order_supplier';
661 661
 						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
662
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs));
663
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
662
+						$mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
663
+						$mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
664 664
 						break;
665 665
 					case 'ORDER_SUPPLIER_APPROVE':
666
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
666
+						$link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'">'.$newref.'</a>';
667 667
 						$dir_output = $conf->fournisseur->commande->dir_output;
668 668
 						$object_type = 'order_supplier';
669 669
 						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
670
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
671
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
670
+						$mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
671
+						$mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
672 672
 						break;
673 673
 					case 'ORDER_SUPPLIER_APPROVE2':
674
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
674
+						$link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'">'.$newref.'</a>';
675 675
 						$dir_output = $conf->fournisseur->commande->dir_output;
676 676
 						$object_type = 'order_supplier';
677 677
 						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
678
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
679
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
678
+						$mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
679
+						$mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
680 680
 						break;
681 681
 					case 'ORDER_SUPPLIER_REFUSE':
682
-						$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
682
+						$link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'">'.$newref.'</a>';
683 683
 						$dir_output = $conf->fournisseur->dir_output.'/commande/';
684 684
 						$object_type = 'order_supplier';
685 685
 						$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
686
-						$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs));
687
-						$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
686
+						$mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
687
+						$mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
688 688
 						break;
689 689
 					case 'SHIPPING_VALIDATE':
690 690
 						$dir_output = $conf->expedition->dir_output.'/sending/';
691 691
 						$object_type = 'order_supplier';
692
-						$mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
692
+						$mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref);
693 693
 						break;
694 694
 					case 'EXPENSE_REPORT_VALIDATE':
695 695
 						$dir_output = $conf->expensereport->dir_output;
696 696
 						$object_type = 'expensereport';
697
-						$mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref);
697
+						$mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $newref);
698 698
 						break;
699 699
 					case 'EXPENSE_REPORT_APPROVE':
700 700
 						$dir_output = $conf->expensereport->dir_output;
701 701
 						$object_type = 'expensereport';
702
-						$mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref);
702
+						$mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $newref);
703 703
 						break;
704 704
 					case 'HOLIDAY_VALIDATE':
705 705
 						$dir_output = $conf->holiday->dir_output;
706 706
 						$object_type = 'holiday';
707
-						$mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref);
707
+						$mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated", $newref);
708 708
 						break;
709 709
 					case 'HOLIDAY_APPROVE':
710 710
 						$dir_output = $conf->holiday->dir_output;
711 711
 						$object_type = 'holiday';
712
-						$mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref);
712
+						$mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved", $newref);
713 713
 						break;
714 714
 				}
715 715
 				$ref = dol_sanitizeFileName($newref);
716 716
 				$pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
717
-				if (! dol_is_file($pdf_path))
717
+				if (!dol_is_file($pdf_path))
718 718
 				{
719 719
 					// We can't add PDF as it is not generated yet.
720 720
 					$filepdf = '';
@@ -724,10 +724,10 @@  discard block
 block discarded – undo
724 724
 					$filepdf = $pdf_path;
725 725
 				}
726 726
 
727
-				$message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
728
-				$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
729
-				$message.= "\n";
730
-				$message.= $mesg;
727
+				$message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n";
728
+				$message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
729
+				$message .= "\n";
730
+				$message .= $mesg;
731 731
 				//if ($link) $message.= "\n" . $urlwithroot . $link;	// link already added around the ref into the text
732 732
 
733 733
 				$message = nl2br($message);
@@ -735,28 +735,28 @@  discard block
 block discarded – undo
735 735
 				// Replace keyword __SUPERVISOREMAIL__
736 736
 				if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
737 737
 				{
738
-					$newval='';
738
+					$newval = '';
739 739
 					if ($user->fk_user > 0)
740 740
 					{
741
-						$supervisoruser=new User($this->db);
741
+						$supervisoruser = new User($this->db);
742 742
 						$supervisoruser->fetch($user->fk_user);
743
-						if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
743
+						if ($supervisoruser->email) $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
744 744
 					}
745 745
 					dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
746 746
 					$sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
747
-					$sendto = preg_replace('/,\s*,/', ',', $sendto);	// in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email,  , othermail" and it's not valid
748
-					$sendto = preg_replace('/^[\s,]+/', '', $sendto);	// Clean start of string
749
-					$sendto = preg_replace('/[\s,]+$/', '', $sendto);	// Clean end of string
747
+					$sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email,  , othermail" and it's not valid
748
+					$sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string
749
+					$sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
750 750
 				}
751 751
 
752 752
 				if ($sendto)
753 753
 				{
754
-					$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
755
-					$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
754
+					$parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
755
+					$reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
756 756
 					if (empty($reshook))
757 757
 					{
758
-						if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
759
-						if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
758
+						if (!empty($hookmanager->resArray['subject'])) $subject .= $hookmanager->resArray['subject'];
759
+						if (!empty($hookmanager->resArray['message'])) $message .= $hookmanager->resArray['message'];
760 760
 					}
761 761
 					$mailfile = new CMailFile(
762 762
 						$subject,
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
 					if ($mailfile->sendfile())
776 776
 					{
777 777
 						$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
778
-						$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
779
-						if (! $this->db->query($sql))
778
+						$sql .= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid ? $object->socid : 'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
779
+						if (!$this->db->query($sql))
780 780
 						{
781 781
 							dol_print_error($this->db);
782 782
 						}
@@ -784,13 +784,13 @@  discard block
 block discarded – undo
784 784
 					else
785 785
 					{
786 786
 						$error++;
787
-						$this->errors[]=$mailfile->error;
787
+						$this->errors[] = $mailfile->error;
788 788
 					}
789 789
 				}
790 790
 			}
791 791
 		}
792 792
 
793
-		if (! $error) return $num;
793
+		if (!$error) return $num;
794 794
 		else return -1 * $error;
795 795
 	}
796 796
 }
Please login to merge, or discard this patch.
Braces   +146 added lines, -66 removed lines patch added patch discarded remove patch
@@ -113,24 +113,42 @@  discard block
 block discarded – undo
113 113
 		$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
114 114
 
115 115
 		$nb=-1;
116
-		if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
117
-		if ($nb < 0)  $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
118
-		if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
119
-   		if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
120
-   		if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
116
+		if (is_array($listofnotiftodo)) {
117
+		    $nb=count($listofnotiftodo);
118
+		}
119
+		if ($nb < 0) {
120
+		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
121
+		}
122
+		if ($nb == 0) {
123
+		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
124
+		}
125
+   		if ($nb == 1) {
126
+   		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
127
+   		}
128
+   		if ($nb >= 2) {
129
+   		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
130
+   		}
121 131
 
122 132
    		if (is_array($listofnotiftodo))
123 133
    		{
124 134
 			$i=0;
125 135
 			foreach ($listofnotiftodo as $key => $val)
126 136
 			{
127
-				if ($i) $texte.=', ';
128
-				else $texte.=' (';
129
-				if ($val['isemailvalid']) $texte.=$val['email'];
130
-				else $texte.=$val['emaildesc'];
137
+				if ($i) {
138
+				    $texte.=', ';
139
+				} else {
140
+				    $texte.=' (';
141
+				}
142
+				if ($val['isemailvalid']) {
143
+				    $texte.=$val['email'];
144
+				} else {
145
+				    $texte.=$val['emaildesc'];
146
+				}
131 147
 				$i++;
132 148
 			}
133
-			if ($i) $texte.=')';
149
+			if ($i) {
150
+			    $texte.=')';
151
+			}
134 152
    		}
135 153
 
136 154
 		return $texte;
@@ -154,7 +172,9 @@  discard block
 block discarded – undo
154 172
 		$resarray=array();
155 173
 
156 174
 		$valueforthreshold = 0;
157
-		if (is_object($object)) $valueforthreshold = $object->total_ht;
175
+		if (is_object($object)) {
176
+		    $valueforthreshold = $object->total_ht;
177
+		}
158 178
 
159 179
 		if (! $error)
160 180
 		{
@@ -170,11 +190,19 @@  discard block
 block discarded – undo
170 190
 				$sql.= " AND n.fk_soc = s.rowid";
171 191
 				if ($notifcode)
172 192
 				{
173
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
174
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
193
+					if (is_numeric($notifcode)) {
194
+					    $sql.= " AND n.fk_action = ".$notifcode;
195
+					}
196
+					// Old usage
197
+					else {
198
+					    $sql.= " AND a.code = '".$notifcode."'";
199
+					}
200
+					// New usage
175 201
 				}
176 202
 				$sql.= " AND s.entity IN (".getEntity('societe').")";
177
-				if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
203
+				if ($socid > 0) {
204
+				    $sql.= " AND s.rowid = ".$socid;
205
+				}
178 206
 
179 207
 				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
180 208
 
@@ -190,12 +218,13 @@  discard block
 block discarded – undo
190 218
 						{
191 219
 							$newval2=trim($obj->email);
192 220
 							$isvalid=isValidEmail($newval2);
193
-							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
221
+							if (empty($resarray[$newval2])) {
222
+							    $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
223
+							}
194 224
 						}
195 225
 						$i++;
196 226
 					}
197
-				}
198
-				else
227
+				} else
199 228
 				{
200 229
 					$error++;
201 230
 					$this->error=$this->db->lasterror();
@@ -215,11 +244,19 @@  discard block
 block discarded – undo
215 244
 				$sql.= " AND a.rowid = n.fk_action";
216 245
 				if ($notifcode)
217 246
 				{
218
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
219
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
247
+					if (is_numeric($notifcode)) {
248
+					    $sql.= " AND n.fk_action = ".$notifcode;
249
+					}
250
+					// Old usage
251
+					else {
252
+					    $sql.= " AND a.code = '".$notifcode."'";
253
+					}
254
+					// New usage
220 255
 				}
221 256
 				$sql.= " AND c.entity IN (".getEntity('user').")";
222
-				if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
257
+				if ($userid > 0) {
258
+				    $sql.= " AND c.rowid = ".$userid;
259
+				}
223 260
 
224 261
 				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
225 262
 
@@ -235,12 +272,13 @@  discard block
 block discarded – undo
235 272
 						{
236 273
 							$newval2=trim($obj->email);
237 274
 							$isvalid=isValidEmail($newval2);
238
-							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
275
+							if (empty($resarray[$newval2])) {
276
+							    $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
277
+							}
239 278
 						}
240 279
 						$i++;
241 280
 					}
242
-				}
243
-				else
281
+				} else
244 282
 				{
245 283
 					$error++;
246 284
 					$this->error=$this->db->lasterror();
@@ -257,15 +295,20 @@  discard block
 block discarded – undo
257 295
 				{
258 296
 					if ($notifcode)
259 297
 					{
260
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
261
-					}
262
-					else
298
+						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
299
+						    continue;
300
+						}
301
+					} else
263 302
 					{
264
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
303
+						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
304
+						    continue;
305
+						}
265 306
 					}
266 307
 
267 308
 					$threshold = (float) $reg[1];
268
-					if ($valueforthreshold < $threshold) continue;
309
+					if ($valueforthreshold < $threshold) {
310
+					    continue;
311
+					}
269 312
 
270 313
 					$tmpemail=explode(',',$val);
271 314
 					foreach($tmpemail as $key2 => $val2)
@@ -277,22 +320,30 @@  discard block
 block discarded – undo
277 320
 							{
278 321
 								$tmpuser=new User($this->db);
279 322
 								$tmpuser->fetch($user->fk_user);
280
-								if ($tmpuser->email) $newval2=trim($tmpuser->email);
281
-								else $newval2='';
323
+								if ($tmpuser->email) {
324
+								    $newval2=trim($tmpuser->email);
325
+								} else {
326
+								    $newval2='';
327
+								}
328
+							} else {
329
+							    $newval2='';
282 330
 							}
283
-							else $newval2='';
284 331
 						}
285 332
 						if ($newval2)
286 333
 						{
287 334
 							$isvalid=isValidEmail($newval2, 0);
288
-							if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
335
+							if (empty($resarray[$newval2])) {
336
+							    $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
337
+							}
289 338
 						}
290 339
 					}
291 340
 				}
292 341
 			}
293 342
 		}
294 343
 
295
-		if ($error) return -1;
344
+		if ($error) {
345
+		    return -1;
346
+		}
296 347
 
297 348
 		//var_dump($resarray);
298 349
 		return $resarray;
@@ -315,7 +366,9 @@  discard block
 block discarded – undo
315 366
 		global $hookmanager;
316 367
 		global $dolibarr_main_url_root;
317 368
 
318
-		if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
369
+		if (! in_array($notifcode, $this->arrayofnotifsupported)) {
370
+		    return 0;
371
+		}
319 372
 
320 373
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
321 374
 		if (! is_object($hookmanager))
@@ -336,7 +389,9 @@  discard block
 block discarded – undo
336 389
 
337 390
 		// Define some vars
338 391
 		$application = 'Dolibarr';
339
-		if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
392
+		if (! empty($conf->global->MAIN_APPLICATION_TITLE)) {
393
+		    $application = $conf->global->MAIN_APPLICATION_TITLE;
394
+		}
340 395
 		$replyto = $conf->notification->email_from;
341 396
 		$object_type = '';
342 397
 		$link = '';
@@ -358,8 +413,14 @@  discard block
 block discarded – undo
358 413
 			$sql.= " ".MAIN_DB_PREFIX."societe as s";
359 414
 			$sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
360 415
 			$sql.= " AND n.fk_soc = s.rowid";
361
-			if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
362
-			else $sql.= " AND a.code = '".$notifcode."'";	// New usage
416
+			if (is_numeric($notifcode)) {
417
+			    $sql.= " AND n.fk_action = ".$notifcode;
418
+			}
419
+			// Old usage
420
+			else {
421
+			    $sql.= " AND a.code = '".$notifcode."'";
422
+			}
423
+			// New usage
363 424
 			$sql .= " AND s.rowid = ".$object->socid;
364 425
 
365 426
 			$sql.= "\nUNION\n";
@@ -372,8 +433,14 @@  discard block
 block discarded – undo
372 433
 		$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
373 434
 		$sql.= " ".MAIN_DB_PREFIX."notify_def as n";
374 435
 		$sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
375
-		if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
376
-		else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";	// New usage
436
+		if (is_numeric($notifcode)) {
437
+		    $sql.= " AND n.fk_action = ".$notifcode;
438
+		}
439
+		// Old usage
440
+		else {
441
+		    $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";
442
+		}
443
+		// New usage
377 444
 
378 445
 		$result = $this->db->query($sql);
379 446
 		if ($result)
@@ -391,9 +458,11 @@  discard block
 block discarded – undo
391 458
 			if ($num > 0)
392 459
 			{
393 460
 				$i = 0;
394
-				while ($i < $num && ! $error)	// For each notification couple defined (third party/actioncode)
461
+				while ($i < $num && ! $error) {
462
+				    // For each notification couple defined (third party/actioncode)
395 463
 				{
396 464
 					$obj = $this->db->fetch_object($result);
465
+				}
397 466
 
398 467
 					$sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">";
399 468
 					$notifcodedefid = $obj->adid;
@@ -510,8 +579,7 @@  discard block
 block discarded – undo
510 579
 						{
511 580
 							// We can't add PDF as it is not generated yet.
512 581
 							$filepdf = '';
513
-						}
514
-						else
582
+						} else
515 583
 						{
516 584
 							$filepdf = $pdf_path;
517 585
 						}
@@ -520,14 +588,20 @@  discard block
 block discarded – undo
520 588
 						$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
521 589
 						$message.= "\n";
522 590
 						$message.= $mesg;
523
-						if ($link) $message.= "\n" . $urlwithroot . $link;
591
+						if ($link) {
592
+						    $message.= "\n" . $urlwithroot . $link;
593
+						}
524 594
 
525 595
 						$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
526 596
 						$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
527 597
 						if (empty($reshook))
528 598
 						{
529
-							if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
530
-							if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
599
+							if (! empty($hookmanager->resArray['subject'])) {
600
+							    $subject.=$hookmanager->resArray['subject'];
601
+							}
602
+							if (! empty($hookmanager->resArray['message'])) {
603
+							    $message.=$hookmanager->resArray['message'];
604
+							}
531 605
 						}
532 606
 
533 607
 						$mailfile = new CMailFile(
@@ -549,8 +623,7 @@  discard block
 block discarded – undo
549 623
 							if ($obj->type_target == 'touserid') {
550 624
 	 							$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
551 625
 								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
552
-							}
553
-							else {
626
+							} else {
554 627
 								$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
555 628
 								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
556 629
 							}
@@ -558,26 +631,22 @@  discard block
 block discarded – undo
558 631
 							{
559 632
 								dol_print_error($this->db);
560 633
 							}
561
-						}
562
-						else
634
+						} else
563 635
 						{
564 636
 							$error++;
565 637
 							$this->errors[]=$mailfile->error;
566 638
 						}
567
-					}
568
-					else
639
+					} else
569 640
 				  {
570 641
 						dol_syslog("No notification sent for ".$sendto." because email is empty");
571 642
 					}
572 643
 					$i++;
573 644
 				}
574
-			}
575
-			else
645
+			} else
576 646
 			{
577 647
 				dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid);
578 648
 			}
579
-		}
580
-		else
649
+		} else
581 650
 		{
582 651
 	   		$error++;
583 652
 			$this->errors[]=$this->db->lasterror();
@@ -590,7 +659,9 @@  discard block
 block discarded – undo
590 659
 		{
591 660
 			foreach($conf->global as $key => $val)
592 661
 			{
593
-				if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
662
+				if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
663
+				    continue;
664
+				}
594 665
 
595 666
 				$threshold = (float) $reg[1];
596 667
 				if (!empty($object->total_ht) && $object->total_ht <= $threshold)
@@ -603,7 +674,9 @@  discard block
 block discarded – undo
603 674
 
604 675
 				$sendto = $conf->global->$param;
605 676
 				$notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
606
-				if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code');
677
+				if ($notifcodedefid <= 0) {
678
+				    dol_print_error($this->db, 'Failed to get id from code');
679
+				}
607 680
 
608 681
 				$object_type = '';
609 682
 				$link = '';
@@ -718,8 +791,7 @@  discard block
 block discarded – undo
718 791
 				{
719 792
 					// We can't add PDF as it is not generated yet.
720 793
 					$filepdf = '';
721
-				}
722
-				else
794
+				} else
723 795
 				{
724 796
 					$filepdf = $pdf_path;
725 797
 				}
@@ -740,7 +812,9 @@  discard block
 block discarded – undo
740 812
 					{
741 813
 						$supervisoruser=new User($this->db);
742 814
 						$supervisoruser->fetch($user->fk_user);
743
-						if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
815
+						if ($supervisoruser->email) {
816
+						    $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
817
+						}
744 818
 					}
745 819
 					dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
746 820
 					$sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
@@ -755,8 +829,12 @@  discard block
 block discarded – undo
755 829
 					$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
756 830
 					if (empty($reshook))
757 831
 					{
758
-						if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
759
-						if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
832
+						if (! empty($hookmanager->resArray['subject'])) {
833
+						    $subject.=$hookmanager->resArray['subject'];
834
+						}
835
+						if (! empty($hookmanager->resArray['message'])) {
836
+						    $message.=$hookmanager->resArray['message'];
837
+						}
760 838
 					}
761 839
 					$mailfile = new CMailFile(
762 840
 						$subject,
@@ -780,8 +858,7 @@  discard block
 block discarded – undo
780 858
 						{
781 859
 							dol_print_error($this->db);
782 860
 						}
783
-					}
784
-					else
861
+					} else
785 862
 					{
786 863
 						$error++;
787 864
 						$this->errors[]=$mailfile->error;
@@ -790,7 +867,10 @@  discard block
 block discarded – undo
790 867
 			}
791 868
 		}
792 869
 
793
-		if (! $error) return $num;
794
-		else return -1 * $error;
870
+		if (! $error) {
871
+		    return $num;
872
+		} else {
873
+		    return -1 * $error;
874
+		}
795 875
 	}
796 876
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/dolgeoip.class.php 3 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -33,115 +33,115 @@
 block discarded – undo
33 33
  */
34 34
 class DolGeoIP
35 35
 {
36
-	var $gi;
36
+    var $gi;
37 37
 
38
-	/**
39
-	 * Constructor
40
-	 *
41
-	 * @param 	string	$type		'country' or 'city'
42
-	 * @param	string	$datfile	Data file
43
-	 */
44
-	function __construct($type,$datfile)
45
-	{
46
-		if ($type == 'country')
47
-		{
48
-		    // geoip may have been already included with PEAR
49
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc';
50
-		}
51
-		else if ($type == 'city')
52
-		{
53
-		    // geoip may have been already included with PEAR
54
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc';
55
-		}
56
-		else { print 'ErrorBadParameterInConstructor'; return 0; }
38
+    /**
39
+     * Constructor
40
+     *
41
+     * @param 	string	$type		'country' or 'city'
42
+     * @param	string	$datfile	Data file
43
+     */
44
+    function __construct($type,$datfile)
45
+    {
46
+        if ($type == 'country')
47
+        {
48
+            // geoip may have been already included with PEAR
49
+            if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc';
50
+        }
51
+        else if ($type == 'city')
52
+        {
53
+            // geoip may have been already included with PEAR
54
+            if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc';
55
+        }
56
+        else { print 'ErrorBadParameterInConstructor'; return 0; }
57 57
 
58
-		// Here, function exists (embedded into PHP or exists because we made include)
59
-		if (empty($type) || empty($datfile))
60
-		{
61
-			$this->errorlabel='Constructor was called with no datafile parameter';
62
-			dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR);
63
-			return 0;
64
-		}
65
-		if (! file_exists($datfile) || ! is_readable($datfile))
66
-		{
67
-			$this->error='ErrorGeoIPClassNotInitialized';
68
-			$this->errorlabel="Datafile ".$datfile." not found";
69
-			dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR);
70
-			return 0;
71
-		}
58
+        // Here, function exists (embedded into PHP or exists because we made include)
59
+        if (empty($type) || empty($datfile))
60
+        {
61
+            $this->errorlabel='Constructor was called with no datafile parameter';
62
+            dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR);
63
+            return 0;
64
+        }
65
+        if (! file_exists($datfile) || ! is_readable($datfile))
66
+        {
67
+            $this->error='ErrorGeoIPClassNotInitialized';
68
+            $this->errorlabel="Datafile ".$datfile." not found";
69
+            dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR);
70
+            return 0;
71
+        }
72 72
 
73
-		if (function_exists('geoip_open'))
74
-		{
75
-			$this->gi = geoip_open($datfile,GEOIP_STANDARD);
76
-		}
77
-		else
78
-		{
79
-		    $this->gi = 'NOGI';    // We are using embedded php geoip functions
80
-		    //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name');
81
-		    //print geoip_database_info();
82
-		}
83
-	}
73
+        if (function_exists('geoip_open'))
74
+        {
75
+            $this->gi = geoip_open($datfile,GEOIP_STANDARD);
76
+        }
77
+        else
78
+        {
79
+            $this->gi = 'NOGI';    // We are using embedded php geoip functions
80
+            //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name');
81
+            //print geoip_database_info();
82
+        }
83
+    }
84 84
 
85
-	/**
86
-	 * Return in lower case the country code from an ip
87
-	 *
88
-	 * @param	string	$ip		IP to scan
89
-	 * @return	string			Country code (two letters)
90
-	 */
91
-	function getCountryCodeFromIP($ip)
92
-	{
93
-		if (empty($this->gi))
94
-		{
95
-			return '';
96
-		}
97
-		if ($this->gi == 'NOGI')
98
-		{
99
-		    // geoip_country_code_by_addr does not exists
100
-    		return strtolower(geoip_country_code_by_name($ip));
101
-		}
102
-		else
103
-		{
104
-		    if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
105
-		    return strtolower(geoip_country_code_by_addr($this->gi, $ip));
106
-		}
107
-	}
85
+    /**
86
+     * Return in lower case the country code from an ip
87
+     *
88
+     * @param	string	$ip		IP to scan
89
+     * @return	string			Country code (two letters)
90
+     */
91
+    function getCountryCodeFromIP($ip)
92
+    {
93
+        if (empty($this->gi))
94
+        {
95
+            return '';
96
+        }
97
+        if ($this->gi == 'NOGI')
98
+        {
99
+            // geoip_country_code_by_addr does not exists
100
+            return strtolower(geoip_country_code_by_name($ip));
101
+        }
102
+        else
103
+        {
104
+            if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
105
+            return strtolower(geoip_country_code_by_addr($this->gi, $ip));
106
+        }
107
+    }
108 108
 
109
-	/**
110
-	 * Return in lower case the country code from a host name
111
-	 *
112
-	 * @param	string	$name	FQN of host (example: myserver.xyz.com)
113
-	 * @return	string			Country code (two letters)
114
-	 */
115
-	function getCountryCodeFromName($name)
116
-	{
117
-		if (empty($this->gi))
118
-		{
119
-			return '';
120
-		}
121
-		return geoip_country_code_by_name($this->gi, $name);
122
-	}
109
+    /**
110
+     * Return in lower case the country code from a host name
111
+     *
112
+     * @param	string	$name	FQN of host (example: myserver.xyz.com)
113
+     * @return	string			Country code (two letters)
114
+     */
115
+    function getCountryCodeFromName($name)
116
+    {
117
+        if (empty($this->gi))
118
+        {
119
+            return '';
120
+        }
121
+        return geoip_country_code_by_name($this->gi, $name);
122
+    }
123 123
 
124
-	/**
125
-	 * Return verion of data file
126
-	 *
127
-	 * @return	string		Version of datafile
128
-	 */
129
-	function getVersion()
130
-	{
131
-	    if ($this->gi == 'NOGI') return geoip_database_info();
132
-		return 'Not available (not using PHP internal geo functions)';
133
-	}
124
+    /**
125
+     * Return verion of data file
126
+     *
127
+     * @return	string		Version of datafile
128
+     */
129
+    function getVersion()
130
+    {
131
+        if ($this->gi == 'NOGI') return geoip_database_info();
132
+        return 'Not available (not using PHP internal geo functions)';
133
+    }
134 134
 
135
-	/**
136
-	 * Close geoip object
137
-	 *
138
-	 * @return	void
139
-	 */
140
-	function close()
141
-	{
142
-	    if (function_exists('geoip_close'))    // With some geoip with PEAR, geoip_close function may not exists
143
-	    {
144
-	        geoip_close($this->gi);
145
-	    }
146
-	}
135
+    /**
136
+     * Close geoip object
137
+     *
138
+     * @return	void
139
+     */
140
+    function close()
141
+    {
142
+        if (function_exists('geoip_close'))    // With some geoip with PEAR, geoip_close function may not exists
143
+        {
144
+            geoip_close($this->gi);
145
+        }
146
+    }
147 147
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -41,42 +41,42 @@  discard block
 block discarded – undo
41 41
 	 * @param 	string	$type		'country' or 'city'
42 42
 	 * @param	string	$datfile	Data file
43 43
 	 */
44
-	function __construct($type,$datfile)
44
+	function __construct($type, $datfile)
45 45
 	{
46 46
 		if ($type == 'country')
47 47
 		{
48 48
 		    // geoip may have been already included with PEAR
49
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc';
49
+		    if (!function_exists('geoip_country_code_by_name')) $res = include_once GEOIP_PATH.'geoip.inc';
50 50
 		}
51 51
 		else if ($type == 'city')
52 52
 		{
53 53
 		    // geoip may have been already included with PEAR
54
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc';
54
+		    if (!function_exists('geoip_country_code_by_name')) $res = include_once GEOIP_PATH.'geoipcity.inc';
55 55
 		}
56 56
 		else { print 'ErrorBadParameterInConstructor'; return 0; }
57 57
 
58 58
 		// Here, function exists (embedded into PHP or exists because we made include)
59 59
 		if (empty($type) || empty($datfile))
60 60
 		{
61
-			$this->errorlabel='Constructor was called with no datafile parameter';
61
+			$this->errorlabel = 'Constructor was called with no datafile parameter';
62 62
 			dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR);
63 63
 			return 0;
64 64
 		}
65
-		if (! file_exists($datfile) || ! is_readable($datfile))
65
+		if (!file_exists($datfile) || !is_readable($datfile))
66 66
 		{
67
-			$this->error='ErrorGeoIPClassNotInitialized';
68
-			$this->errorlabel="Datafile ".$datfile." not found";
67
+			$this->error = 'ErrorGeoIPClassNotInitialized';
68
+			$this->errorlabel = "Datafile ".$datfile." not found";
69 69
 			dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR);
70 70
 			return 0;
71 71
 		}
72 72
 
73 73
 		if (function_exists('geoip_open'))
74 74
 		{
75
-			$this->gi = geoip_open($datfile,GEOIP_STANDARD);
75
+			$this->gi = geoip_open($datfile, GEOIP_STANDARD);
76 76
 		}
77 77
 		else
78 78
 		{
79
-		    $this->gi = 'NOGI';    // We are using embedded php geoip functions
79
+		    $this->gi = 'NOGI'; // We are using embedded php geoip functions
80 80
 		    //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name');
81 81
 		    //print geoip_database_info();
82 82
 		}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		}
102 102
 		else
103 103
 		{
104
-		    if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
104
+		    if (!function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
105 105
 		    return strtolower(geoip_country_code_by_addr($this->gi, $ip));
106 106
 		}
107 107
 	}
Please login to merge, or discard this patch.
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -46,14 +46,16 @@  discard block
 block discarded – undo
46 46
 		if ($type == 'country')
47 47
 		{
48 48
 		    // geoip may have been already included with PEAR
49
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc';
50
-		}
51
-		else if ($type == 'city')
49
+		    if (! function_exists('geoip_country_code_by_name')) {
50
+		        $res=include_once GEOIP_PATH.'geoip.inc';
51
+		    }
52
+		} else if ($type == 'city')
52 53
 		{
53 54
 		    // geoip may have been already included with PEAR
54
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc';
55
-		}
56
-		else { print 'ErrorBadParameterInConstructor'; return 0; }
55
+		    if (! function_exists('geoip_country_code_by_name')) {
56
+		        $res=include_once GEOIP_PATH.'geoipcity.inc';
57
+		    }
58
+		} else { print 'ErrorBadParameterInConstructor'; return 0; }
57 59
 
58 60
 		// Here, function exists (embedded into PHP or exists because we made include)
59 61
 		if (empty($type) || empty($datfile))
@@ -73,8 +75,7 @@  discard block
 block discarded – undo
73 75
 		if (function_exists('geoip_open'))
74 76
 		{
75 77
 			$this->gi = geoip_open($datfile,GEOIP_STANDARD);
76
-		}
77
-		else
78
+		} else
78 79
 		{
79 80
 		    $this->gi = 'NOGI';    // We are using embedded php geoip functions
80 81
 		    //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name');
@@ -98,10 +99,11 @@  discard block
 block discarded – undo
98 99
 		{
99 100
 		    // geoip_country_code_by_addr does not exists
100 101
     		return strtolower(geoip_country_code_by_name($ip));
101
-		}
102
-		else
102
+		} else
103 103
 		{
104
-		    if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
104
+		    if (! function_exists('geoip_country_code_by_addr')) {
105
+		        return strtolower(geoip_country_code_by_name($this->gi, $ip));
106
+		    }
105 107
 		    return strtolower(geoip_country_code_by_addr($this->gi, $ip));
106 108
 		}
107 109
 	}
@@ -128,7 +130,9 @@  discard block
 block discarded – undo
128 130
 	 */
129 131
 	function getVersion()
130 132
 	{
131
-	    if ($this->gi == 'NOGI') return geoip_database_info();
133
+	    if ($this->gi == 'NOGI') {
134
+	        return geoip_database_info();
135
+	    }
132 136
 		return 'Not available (not using PHP internal geo functions)';
133 137
 	}
134 138
 
@@ -139,9 +143,11 @@  discard block
 block discarded – undo
139 143
 	 */
140 144
 	function close()
141 145
 	{
142
-	    if (function_exists('geoip_close'))    // With some geoip with PEAR, geoip_close function may not exists
146
+	    if (function_exists('geoip_close')) {
147
+	        // With some geoip with PEAR, geoip_close function may not exists
143 148
 	    {
144 149
 	        geoip_close($this->gi);
145 150
 	    }
151
+	    }
146 152
 	}
147 153
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formfile.class.php 3 patches
Indentation   +1761 added lines, -1761 removed lines patch added patch discarded remove patch
@@ -34,312 +34,312 @@  discard block
 block discarded – undo
34 34
  */
35 35
 class FormFile
36 36
 {
37
-	private $db;
37
+    private $db;
38 38
 
39
-	/**
40
-	 * @var string Error code (or message)
41
-	 */
42
-	public $error;
39
+    /**
40
+     * @var string Error code (or message)
41
+     */
42
+    public $error;
43 43
 
44
-	public $numoffiles;
45
-	public $infofiles;			// Used to return informations by function getDocumentsLink
44
+    public $numoffiles;
45
+    public $infofiles;			// Used to return informations by function getDocumentsLink
46 46
 
47 47
 
48
-	/**
49
-	 *	Constructor
50
-	 *
51
-	 *  @param		DoliDB		$db      Database handler
52
-	 */
53
-	function __construct($db)
54
-	{
55
-		$this->db = $db;
56
-		$this->numoffiles=0;
57
-	}
48
+    /**
49
+     *	Constructor
50
+     *
51
+     *  @param		DoliDB		$db      Database handler
52
+     */
53
+    function __construct($db)
54
+    {
55
+        $this->db = $db;
56
+        $this->numoffiles=0;
57
+    }
58 58
 
59 59
 
60 60
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
61
-	/**
62
-	 *  Show form to upload a new file.
63
-	 *
64
-	 *  @param  string		$url			Url
65
-	 *  @param  string		$title			Title zone (Title or '' or 'none')
66
-	 *  @param  int			$addcancel		1=Add 'Cancel' button
67
-	 *	@param	int			$sectionid		If upload must be done inside a particular ECM section (is sectionid defined, sectiondir must not be)
68
-	 * 	@param	int			$perm			Value of permission to allow upload
69
-	 *  @param  int			$size          		Length of input file area. Deprecated.
70
-	 *  @param	Object		$object			Object to use (when attachment is done on an element)
71
-	 *  @param	string		$options		Add an option column
72
-	 *  @param	integer		$useajax		Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). @deprecated 2 should never be used and if 1 is used, option should no be enabled.
73
-	 *  @param	string		$savingdocmask		Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
74
-	 *  @param	integer		$linkfiles		1=Also add form to link files, 0=Do not show form to link files
75
-	 *  @param	string		$htmlname		Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM)
76
-	 *  @param	string		$accept			Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*')
77
-	 *	@param	string		$sectiondir		If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be)
78
-	 * 	@return	int							<0 if KO, >0 if OK
79
-	 */
80
-	function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='')
81
-	{
61
+    /**
62
+     *  Show form to upload a new file.
63
+     *
64
+     *  @param  string		$url			Url
65
+     *  @param  string		$title			Title zone (Title or '' or 'none')
66
+     *  @param  int			$addcancel		1=Add 'Cancel' button
67
+     *	@param	int			$sectionid		If upload must be done inside a particular ECM section (is sectionid defined, sectiondir must not be)
68
+     * 	@param	int			$perm			Value of permission to allow upload
69
+     *  @param  int			$size          		Length of input file area. Deprecated.
70
+     *  @param	Object		$object			Object to use (when attachment is done on an element)
71
+     *  @param	string		$options		Add an option column
72
+     *  @param	integer		$useajax		Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). @deprecated 2 should never be used and if 1 is used, option should no be enabled.
73
+     *  @param	string		$savingdocmask		Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
74
+     *  @param	integer		$linkfiles		1=Also add form to link files, 0=Do not show form to link files
75
+     *  @param	string		$htmlname		Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM)
76
+     *  @param	string		$accept			Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*')
77
+     *	@param	string		$sectiondir		If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be)
78
+     * 	@return	int							<0 if KO, >0 if OK
79
+     */
80
+    function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='')
81
+    {
82 82
         // phpcs:enable
83
-		global $conf,$langs, $hookmanager;
84
-		$hookmanager->initHooks(array('formfile'));
85
-
86
-
87
-		if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0;
88
-
89
-		if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
90
-		{
91
-			// TODO: Check this works with 2 forms on same page
92
-			// TODO: Check this works with GED module, otherwise, force useajax to 0
93
-			// TODO: This does not support option savingdocmask
94
-			// TODO: This break feature to upload links too
95
-			return $this->_formAjaxFileUpload($object);
96
-		}
97
-		else
98
-	   	{
99
-			//If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
100
-			if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
101
-				return 1;
102
-			}
103
-
104
-			$maxlength=$size;
105
-
106
-			$out = "\n\n<!-- Start form attach new file -->\n";
107
-
108
-			if (empty($title)) $title=$langs->trans("AttachANewFile");
109
-			if ($title != 'none') $out.=load_fiche_titre($title, null, null);
110
-
111
-			$out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
112
-			$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
113
-			$out .= '<input type="hidden" id="'.$htmlname.'_section_id"  name="section_id" value="'.$sectionid.'">';
114
-			$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
115
-
116
-			$out .= '<table width="100%" class="nobordernopadding">';
117
-			$out .= '<tr>';
118
-
119
-			if (! empty($options)) $out .= '<td>'.$options.'</td>';
120
-
121
-			$out .= '<td class="valignmiddle nowrap">';
122
-
123
-			$max=$conf->global->MAIN_UPLOAD_DOC;		// En Kb
124
-			$maxphp=@ini_get('upload_max_filesize');	// En inconnu
125
-			if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1;
126
-			if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
127
-			if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024;
128
-			if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024;
129
-			// Now $max and $maxphp are in Kb
130
-			$maxmin = $max;
131
-			if ($maxphp > 0) $maxmin=min($max,$maxphp);
132
-
133
-			if ($maxmin > 0)
134
-			{
135
-				// MAX_FILE_SIZE doit précéder le champ input de type file
136
-				$out .= '<input type="hidden" name="max_file_size" value="'.($maxmin*1024).'">';
137
-			}
138
-
139
-			$out .= '<input class="flat minwidth400" type="file"';
140
-			$out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple');
141
-			$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
142
-			$out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""');
143
-			$out .= '>';
144
-			$out .= ' ';
145
-			$out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
146
-			$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
147
-			$out .= '>';
148
-
149
-			if ($addcancel)
150
-			{
151
-				$out .= ' &nbsp; ';
152
-				$out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
153
-			}
154
-
155
-			if (! empty($conf->global->MAIN_UPLOAD_DOC))
156
-			{
157
-				if ($perm)
158
-				{
159
-					$langs->load('other');
160
-					$out .= ' ';
161
-					$out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
162
-				}
163
-			}
164
-			else
165
-			{
166
-				$out .= ' ('.$langs->trans("UploadDisabled").')';
167
-			}
168
-			$out .= "</td></tr>";
169
-
170
-			if ($savingdocmask)
171
-			{
172
-				$out .= '<tr>';
173
-   				if (! empty($options)) $out .= '<td>'.$options.'</td>';
174
-				$out .= '<td valign="middle" class="nowrap">';
175
-				$out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
176
-				$out .= '</td>';
177
-				$out .= '</tr>';
178
-			}
179
-
180
-			$out .= "</table>";
181
-
182
-			$out .= '</form>';
183
-			if (empty($sectionid)) $out .= '<br>';
184
-
185
-			$out .= "\n<!-- End form attach new file -->\n";
186
-
187
-			if ($linkfiles)
188
-			{
189
-				$out .= "\n<!-- Start form link new url -->\n";
190
-				$langs->load('link');
191
-				$title = $langs->trans("LinkANewFile");
192
-				$out .= load_fiche_titre($title, null, null);
193
-				$out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
194
-				$out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
195
-				$out .= '<input type="hidden" id="'.$htmlname.'_link_section_id"  name="link_section_id" value="'.$sectionid.'">';
196
-				$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
197
-
198
-				$out .= '<div class="valignmiddle" >';
199
-				$out .= '<div class="inline-block" style="padding-right: 10px;">';
200
-				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
201
-				$out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
202
-				$out .= '</div>';
203
-				$out .= '<div class="inline-block" style="padding-right: 10px;">';
204
-				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
205
-				$out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
206
-				$out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
207
-				$out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
208
-				$out .= '</div>';
209
-				$out .= '<div class="inline-block" style="padding-right: 10px;">';
210
-				$out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
211
-				$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
212
-				$out .= '>';
213
-				$out .= '</div>';
214
-				$out .= '</div>';
215
-				$out .= '<div class="clearboth"></div>';
216
-				$out .= '</form><br>';
217
-
218
-				$out .= "\n<!-- End form link new url -->\n";
219
-			}
220
-
221
-			$parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''), 'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
222
-			$res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
223
-			if (empty($res))
224
-			{
225
-				print '<div class="attacharea attacharea'.$htmlname.'">';
226
-				print $out;
227
-				print '</div>';
228
-			}
229
-			print $hookmanager->resPrint;
230
-
231
-			return 1;
232
-		}
233
-	}
83
+        global $conf,$langs, $hookmanager;
84
+        $hookmanager->initHooks(array('formfile'));
85
+
86
+
87
+        if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0;
88
+
89
+        if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
90
+        {
91
+            // TODO: Check this works with 2 forms on same page
92
+            // TODO: Check this works with GED module, otherwise, force useajax to 0
93
+            // TODO: This does not support option savingdocmask
94
+            // TODO: This break feature to upload links too
95
+            return $this->_formAjaxFileUpload($object);
96
+        }
97
+        else
98
+            {
99
+            //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
100
+            if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
101
+                return 1;
102
+            }
103
+
104
+            $maxlength=$size;
105
+
106
+            $out = "\n\n<!-- Start form attach new file -->\n";
107
+
108
+            if (empty($title)) $title=$langs->trans("AttachANewFile");
109
+            if ($title != 'none') $out.=load_fiche_titre($title, null, null);
110
+
111
+            $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
112
+            $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
113
+            $out .= '<input type="hidden" id="'.$htmlname.'_section_id"  name="section_id" value="'.$sectionid.'">';
114
+            $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
115
+
116
+            $out .= '<table width="100%" class="nobordernopadding">';
117
+            $out .= '<tr>';
118
+
119
+            if (! empty($options)) $out .= '<td>'.$options.'</td>';
120
+
121
+            $out .= '<td class="valignmiddle nowrap">';
122
+
123
+            $max=$conf->global->MAIN_UPLOAD_DOC;		// En Kb
124
+            $maxphp=@ini_get('upload_max_filesize');	// En inconnu
125
+            if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1;
126
+            if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
127
+            if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024;
128
+            if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024;
129
+            // Now $max and $maxphp are in Kb
130
+            $maxmin = $max;
131
+            if ($maxphp > 0) $maxmin=min($max,$maxphp);
132
+
133
+            if ($maxmin > 0)
134
+            {
135
+                // MAX_FILE_SIZE doit précéder le champ input de type file
136
+                $out .= '<input type="hidden" name="max_file_size" value="'.($maxmin*1024).'">';
137
+            }
138
+
139
+            $out .= '<input class="flat minwidth400" type="file"';
140
+            $out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple');
141
+            $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
142
+            $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""');
143
+            $out .= '>';
144
+            $out .= ' ';
145
+            $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
146
+            $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
147
+            $out .= '>';
148
+
149
+            if ($addcancel)
150
+            {
151
+                $out .= ' &nbsp; ';
152
+                $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
153
+            }
154
+
155
+            if (! empty($conf->global->MAIN_UPLOAD_DOC))
156
+            {
157
+                if ($perm)
158
+                {
159
+                    $langs->load('other');
160
+                    $out .= ' ';
161
+                    $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
162
+                }
163
+            }
164
+            else
165
+            {
166
+                $out .= ' ('.$langs->trans("UploadDisabled").')';
167
+            }
168
+            $out .= "</td></tr>";
169
+
170
+            if ($savingdocmask)
171
+            {
172
+                $out .= '<tr>';
173
+                    if (! empty($options)) $out .= '<td>'.$options.'</td>';
174
+                $out .= '<td valign="middle" class="nowrap">';
175
+                $out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
176
+                $out .= '</td>';
177
+                $out .= '</tr>';
178
+            }
179
+
180
+            $out .= "</table>";
181
+
182
+            $out .= '</form>';
183
+            if (empty($sectionid)) $out .= '<br>';
184
+
185
+            $out .= "\n<!-- End form attach new file -->\n";
186
+
187
+            if ($linkfiles)
188
+            {
189
+                $out .= "\n<!-- Start form link new url -->\n";
190
+                $langs->load('link');
191
+                $title = $langs->trans("LinkANewFile");
192
+                $out .= load_fiche_titre($title, null, null);
193
+                $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
194
+                $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
195
+                $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id"  name="link_section_id" value="'.$sectionid.'">';
196
+                $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
197
+
198
+                $out .= '<div class="valignmiddle" >';
199
+                $out .= '<div class="inline-block" style="padding-right: 10px;">';
200
+                if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
201
+                $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
202
+                $out .= '</div>';
203
+                $out .= '<div class="inline-block" style="padding-right: 10px;">';
204
+                if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
205
+                $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
206
+                $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
207
+                $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
208
+                $out .= '</div>';
209
+                $out .= '<div class="inline-block" style="padding-right: 10px;">';
210
+                $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
211
+                $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
212
+                $out .= '>';
213
+                $out .= '</div>';
214
+                $out .= '</div>';
215
+                $out .= '<div class="clearboth"></div>';
216
+                $out .= '</form><br>';
217
+
218
+                $out .= "\n<!-- End form link new url -->\n";
219
+            }
220
+
221
+            $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''), 'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
222
+            $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
223
+            if (empty($res))
224
+            {
225
+                print '<div class="attacharea attacharea'.$htmlname.'">';
226
+                print $out;
227
+                print '</div>';
228
+            }
229
+            print $hookmanager->resPrint;
230
+
231
+            return 1;
232
+        }
233
+    }
234 234
 
235 235
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
236
-	/**
237
-	 *      Show the box with list of available documents for object
238
-	 *
239
-	 *      @param      string				$modulepart         propal, facture, facture_fourn, ...
240
-	 *      @param      string				$modulesubdir       Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
241
-	 *      @param      string				$filedir            Directory to scan
242
-	 *      @param      string				$urlsource          Url of origin page (for return)
243
-	 *      @param      int					$genallowed         Generation is allowed (1/0 or array of formats)
244
-	 *      @param      int					$delallowed         Remove is allowed (1/0)
245
-	 *      @param      string				$modelselected      Model to preselect by default
246
-	 *      @param      integer				$allowgenifempty	Show warning if no model activated
247
-	 *      @param      integer				$forcenomultilang	Do not show language option (even if MAIN_MULTILANGS defined)
248
-	 *      @param      int					$iconPDF            Show only PDF icon with link (1/0)
249
-	 * 		@param		int					$notused	        Not used
250
-	 * 		@param		integer				$noform				Do not output html form tags
251
-	 * 		@param		string				$param				More param on http links
252
-	 * 		@param		string				$title				Title to show on top of form
253
-	 * 		@param		string				$buttonlabel		Label on submit button
254
-	 * 		@param		string				$codelang			Default language code to use on lang combo box if multilang is enabled
255
-	 * 		@return		int										<0 if KO, number of shown files if OK
256
-	 *      @deprecated                                         Use print xxx->showdocuments() instead.
257
-	 */
258
-	function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='')
259
-	{
236
+    /**
237
+     *      Show the box with list of available documents for object
238
+     *
239
+     *      @param      string				$modulepart         propal, facture, facture_fourn, ...
240
+     *      @param      string				$modulesubdir       Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
241
+     *      @param      string				$filedir            Directory to scan
242
+     *      @param      string				$urlsource          Url of origin page (for return)
243
+     *      @param      int					$genallowed         Generation is allowed (1/0 or array of formats)
244
+     *      @param      int					$delallowed         Remove is allowed (1/0)
245
+     *      @param      string				$modelselected      Model to preselect by default
246
+     *      @param      integer				$allowgenifempty	Show warning if no model activated
247
+     *      @param      integer				$forcenomultilang	Do not show language option (even if MAIN_MULTILANGS defined)
248
+     *      @param      int					$iconPDF            Show only PDF icon with link (1/0)
249
+     * 		@param		int					$notused	        Not used
250
+     * 		@param		integer				$noform				Do not output html form tags
251
+     * 		@param		string				$param				More param on http links
252
+     * 		@param		string				$title				Title to show on top of form
253
+     * 		@param		string				$buttonlabel		Label on submit button
254
+     * 		@param		string				$codelang			Default language code to use on lang combo box if multilang is enabled
255
+     * 		@return		int										<0 if KO, number of shown files if OK
256
+     *      @deprecated                                         Use print xxx->showdocuments() instead.
257
+     */
258
+    function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='')
259
+    {
260 260
         // phpcs:enable
261
-		$this->numoffiles=0;
262
-		print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang);
263
-		return $this->numoffiles;
264
-	}
265
-
266
-	/**
267
-	 *      Return a string to show the box with list of available documents for object.
268
-	 *      This also set the property $this->numoffiles
269
-	 *
270
-	 *      @param      string				$modulepart         Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...)
271
-	 *      @param      string				$modulesubdir       Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
272
-	 *      @param      string				$filedir            Directory to scan
273
-	 *      @param      string				$urlsource          Url of origin page (for return)
274
-	 *      @param      int					$genallowed         Generation is allowed (1/0 or array list of templates)
275
-	 *      @param      int					$delallowed         Remove is allowed (1/0)
276
-	 *      @param      string				$modelselected      Model to preselect by default
277
-	 *      @param      integer				$allowgenifempty	Allow generation even if list of template ($genallowed) is empty (show however a warning)
278
-	 *      @param      integer				$forcenomultilang	Do not show language option (even if MAIN_MULTILANGS defined)
279
-	 *      @param      int					$iconPDF            Deprecated, see getDocumentsLink
280
-	 * 		@param		int					$notused	        Not used
281
-	 * 		@param		integer				$noform				Do not output html form tags
282
-	 * 		@param		string				$param				More param on http links
283
-	 * 		@param		string				$title				Title to show on top of form
284
-	 * 		@param		string				$buttonlabel		Label on submit button
285
-	 * 		@param		string				$codelang			Default language code to use on lang combo box if multilang is enabled
286
-	 * 		@param		string				$morepicto			Add more HTML content into cell with picto
287
-	 *      @param      Object              $object             Object when method is called from an object card.
288
-	 *      @param		int					$hideifempty		Hide section of generated files if there is no file
289
-	 * 		@return		string              					Output string with HTML array of documents (might be empty string)
290
-	 */
291
-	function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null,$hideifempty=0)
292
-	{
293
-		// Deprecation warning
294
-		if (! empty($iconPDF)) {
295
-			dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING);
296
-		}
297
-
298
-		global $langs, $conf, $user, $hookmanager;
299
-		global $form;
300
-
301
-		if (! is_object($form)) $form=new Form($this->db);
302
-
303
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
304
-
305
-		// For backward compatibility
306
-		if (! empty($iconPDF)) {
307
-			return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
308
-		}
309
-
310
-		// Add entity in $param
311
-		$param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity);
312
-
313
-		$printer=0;
314
-		if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison')))	// The direct print feature is implemented only for such elements
315
-		{
316
-			$printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
317
-		}
318
-
319
-		$hookmanager->initHooks(array('formfile'));
320
-
321
-		// Get list of files
322
-		$file_list=null;
323
-		if (! empty($filedir))
324
-		{
325
-			$file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC);
326
-		}
327
-		if ($hideifempty && empty($file_list)) return '';
328
-
329
-		$out='';
330
-		$forname='builddoc';
331
-		$headershown=0;
332
-		$showempty=0;
333
-		$i=0;
334
-
335
-		$out.= "\n".'<!-- Start show_document -->'."\n";
336
-		//print 'filedir='.$filedir;
337
-
338
-		if (preg_match('/massfilesarea_/', $modulepart))
339
-		{
340
-			$out.='<div id="show_files"><br></div>'."\n";
341
-			$title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
342
-			$title.='<script type="text/javascript" language="javascript">
261
+        $this->numoffiles=0;
262
+        print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang);
263
+        return $this->numoffiles;
264
+    }
265
+
266
+    /**
267
+     *      Return a string to show the box with list of available documents for object.
268
+     *      This also set the property $this->numoffiles
269
+     *
270
+     *      @param      string				$modulepart         Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...)
271
+     *      @param      string				$modulesubdir       Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
272
+     *      @param      string				$filedir            Directory to scan
273
+     *      @param      string				$urlsource          Url of origin page (for return)
274
+     *      @param      int					$genallowed         Generation is allowed (1/0 or array list of templates)
275
+     *      @param      int					$delallowed         Remove is allowed (1/0)
276
+     *      @param      string				$modelselected      Model to preselect by default
277
+     *      @param      integer				$allowgenifempty	Allow generation even if list of template ($genallowed) is empty (show however a warning)
278
+     *      @param      integer				$forcenomultilang	Do not show language option (even if MAIN_MULTILANGS defined)
279
+     *      @param      int					$iconPDF            Deprecated, see getDocumentsLink
280
+     * 		@param		int					$notused	        Not used
281
+     * 		@param		integer				$noform				Do not output html form tags
282
+     * 		@param		string				$param				More param on http links
283
+     * 		@param		string				$title				Title to show on top of form
284
+     * 		@param		string				$buttonlabel		Label on submit button
285
+     * 		@param		string				$codelang			Default language code to use on lang combo box if multilang is enabled
286
+     * 		@param		string				$morepicto			Add more HTML content into cell with picto
287
+     *      @param      Object              $object             Object when method is called from an object card.
288
+     *      @param		int					$hideifempty		Hide section of generated files if there is no file
289
+     * 		@return		string              					Output string with HTML array of documents (might be empty string)
290
+     */
291
+    function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null,$hideifempty=0)
292
+    {
293
+        // Deprecation warning
294
+        if (! empty($iconPDF)) {
295
+            dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING);
296
+        }
297
+
298
+        global $langs, $conf, $user, $hookmanager;
299
+        global $form;
300
+
301
+        if (! is_object($form)) $form=new Form($this->db);
302
+
303
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
304
+
305
+        // For backward compatibility
306
+        if (! empty($iconPDF)) {
307
+            return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
308
+        }
309
+
310
+        // Add entity in $param
311
+        $param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity);
312
+
313
+        $printer=0;
314
+        if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison')))	// The direct print feature is implemented only for such elements
315
+        {
316
+            $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
317
+        }
318
+
319
+        $hookmanager->initHooks(array('formfile'));
320
+
321
+        // Get list of files
322
+        $file_list=null;
323
+        if (! empty($filedir))
324
+        {
325
+            $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC);
326
+        }
327
+        if ($hideifempty && empty($file_list)) return '';
328
+
329
+        $out='';
330
+        $forname='builddoc';
331
+        $headershown=0;
332
+        $showempty=0;
333
+        $i=0;
334
+
335
+        $out.= "\n".'<!-- Start show_document -->'."\n";
336
+        //print 'filedir='.$filedir;
337
+
338
+        if (preg_match('/massfilesarea_/', $modulepart))
339
+        {
340
+            $out.='<div id="show_files"><br></div>'."\n";
341
+            $title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
342
+            $title.='<script type="text/javascript" language="javascript">
343 343
 				jQuery(document).ready(function() {
344 344
 					jQuery(\'#togglemassfilesarea\').click(function() {
345 345
 						if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown")
@@ -358,1489 +358,1489 @@  discard block
 block discarded – undo
358 358
 					});
359 359
 				});
360 360
 				</script>';
361
-		}
362
-
363
-		$titletoshow=$langs->trans("Documents");
364
-		if (! empty($title)) $titletoshow=$title;
365
-
366
-		// Show table
367
-		if ($genallowed)
368
-		{
369
-			$modellist=array();
370
-
371
-			if ($modulepart == 'company')
372
-			{
373
-				$showempty=1;
374
-				if (is_array($genallowed)) $modellist=$genallowed;
375
-				else
376
-				{
377
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
378
-					$modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
379
-				}
380
-			}
381
-			else if ($modulepart == 'propal')
382
-			{
383
-				if (is_array($genallowed)) $modellist=$genallowed;
384
-				else
385
-				{
386
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
387
-					$modellist=ModelePDFPropales::liste_modeles($this->db);
388
-				}
389
-			}
390
-			else if ($modulepart == 'supplier_proposal')
391
-			{
392
-				if (is_array($genallowed)) $modellist=$genallowed;
393
-				else
394
-				{
395
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
396
-					$modellist=ModelePDFSupplierProposal::liste_modeles($this->db);
397
-				}
398
-			}
399
-			else if ($modulepart == 'commande')
400
-			{
401
-				if (is_array($genallowed)) $modellist=$genallowed;
402
-				else
403
-				{
404
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
405
-					$modellist=ModelePDFCommandes::liste_modeles($this->db);
406
-				}
407
-			}
408
-			elseif ($modulepart == 'expedition')
409
-			{
410
-				if (is_array($genallowed)) $modellist=$genallowed;
411
-				else
412
-				{
413
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
414
-					$modellist=ModelePDFExpedition::liste_modeles($this->db);
415
-				}
416
-			}
361
+        }
362
+
363
+        $titletoshow=$langs->trans("Documents");
364
+        if (! empty($title)) $titletoshow=$title;
365
+
366
+        // Show table
367
+        if ($genallowed)
368
+        {
369
+            $modellist=array();
370
+
371
+            if ($modulepart == 'company')
372
+            {
373
+                $showempty=1;
374
+                if (is_array($genallowed)) $modellist=$genallowed;
375
+                else
376
+                {
377
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
378
+                    $modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
379
+                }
380
+            }
381
+            else if ($modulepart == 'propal')
382
+            {
383
+                if (is_array($genallowed)) $modellist=$genallowed;
384
+                else
385
+                {
386
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
387
+                    $modellist=ModelePDFPropales::liste_modeles($this->db);
388
+                }
389
+            }
390
+            else if ($modulepart == 'supplier_proposal')
391
+            {
392
+                if (is_array($genallowed)) $modellist=$genallowed;
393
+                else
394
+                {
395
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
396
+                    $modellist=ModelePDFSupplierProposal::liste_modeles($this->db);
397
+                }
398
+            }
399
+            else if ($modulepart == 'commande')
400
+            {
401
+                if (is_array($genallowed)) $modellist=$genallowed;
402
+                else
403
+                {
404
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
405
+                    $modellist=ModelePDFCommandes::liste_modeles($this->db);
406
+                }
407
+            }
408
+            elseif ($modulepart == 'expedition')
409
+            {
410
+                if (is_array($genallowed)) $modellist=$genallowed;
411
+                else
412
+                {
413
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
414
+                    $modellist=ModelePDFExpedition::liste_modeles($this->db);
415
+                }
416
+            }
417 417
             elseif ($modulepart == 'reception')
418 418
             {
419 419
                 if (is_array($genallowed)) $modellist=$genallowed;
420 420
                 else
421 421
                 {
422
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
423
-					$modellist = ModelePdfReception::liste_modeles($this->db);
424
-				}
425
-            }
426
-			elseif ($modulepart == 'livraison')
427
-			{
428
-				if (is_array($genallowed)) $modellist=$genallowed;
429
-				else
430
-				{
431
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
432
-					$modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
433
-				}
434
-			}
435
-			else if ($modulepart == 'ficheinter')
436
-			{
437
-				if (is_array($genallowed)) $modellist=$genallowed;
438
-				else
439
-				{
440
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
441
-					$modellist=ModelePDFFicheinter::liste_modeles($this->db);
442
-				}
443
-			}
444
-			elseif ($modulepart == 'facture')
445
-			{
446
-				if (is_array($genallowed)) $modellist=$genallowed;
447
-				else
448
-				{
449
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
450
-					$modellist=ModelePDFFactures::liste_modeles($this->db);
451
-				}
452
-			}
453
-			elseif ($modulepart == 'contract')
454
-			{
455
-				if (is_array($genallowed)) $modellist=$genallowed;
456
-				else
457
-				{
458
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
459
-					$modellist=ModelePDFContract::liste_modeles($this->db);
460
-				}
461
-			}
462
-			elseif ($modulepart == 'project')
463
-			{
464
-				if (is_array($genallowed)) $modellist=$genallowed;
465
-				else
466
-				{
467
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
468
-					$modellist=ModelePDFProjects::liste_modeles($this->db);
469
-				}
470
-			}
471
-			elseif ($modulepart == 'project_task')
472
-			{
473
-				if (is_array($genallowed)) $modellist=$genallowed;
474
-				else
475
-				{
476
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
477
-					$modellist=ModelePDFTask::liste_modeles($this->db);
478
-				}
479
-			}
480
-			elseif ($modulepart == 'product')
481
-			{
482
-				if (is_array($genallowed)) $modellist=$genallowed;
483
-				else
484
-				{
485
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
486
-					$modellist=ModelePDFProduct::liste_modeles($this->db);
487
-				}
488
-			}
489
-			elseif ($modulepart == 'product_batch')
490
-			{
491
-				if (is_array($genallowed)) $modellist=$genallowed;
492
-				else
493
-				{
494
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
495
-					$modellist=ModelePDFProductBatch::liste_modeles($this->db);
496
-				}
497
-			}
498
-			elseif ($modulepart == 'stock')
499
-			{
500
-				if (is_array($genallowed)) $modellist=$genallowed;
501
-				else
502
-				{
503
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
504
-					$modellist=ModelePDFStock::liste_modeles($this->db);
505
-				}
506
-			}
507
-			elseif ($modulepart == 'movement')
508
-			{
509
-				if (is_array($genallowed)) $modellist=$genallowed;
510
-				else
511
-				{
512
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php';
513
-					$modellist=ModelePDFMovement::liste_modeles($this->db);
514
-				}
515
-			}
516
-			elseif ($modulepart == 'export')
517
-			{
518
-				if (is_array($genallowed)) $modellist=$genallowed;
519
-				else
520
-				{
521
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
522
-					$modellist=ModeleExports::liste_modeles($this->db);
523
-				}
524
-			}
525
-			else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
526
-			{
527
-				if (is_array($genallowed)) $modellist=$genallowed;
528
-				else
529
-				{
530
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
531
-					$modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
532
-				}
533
-			}
534
-			else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
535
-			{
536
-				if (is_array($genallowed)) $modellist=$genallowed;
537
-				else
538
-				{
539
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
540
-					$modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
541
-				}
542
-			}
543
-			else if ($modulepart == 'supplier_payment')
544
-			{
545
-				if (is_array($genallowed)) $modellist=$genallowed;
546
-				else
547
-				{
548
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
549
-					$modellist=ModelePDFSuppliersPayments::liste_modeles($this->db);
550
-				}
551
-			}
552
-			else if ($modulepart == 'remisecheque')
553
-			{
554
-				if (is_array($genallowed)) $modellist=$genallowed;
555
-				else
556
-				{
557
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
558
-					$modellist=ModeleChequeReceipts::liste_modeles($this->db);
559
-				}
560
-			}
561
-			elseif ($modulepart == 'donation')
562
-			{
563
-				if (is_array($genallowed)) $modellist=$genallowed;
564
-				else
565
-				{
566
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
567
-					$modellist=ModeleDon::liste_modeles($this->db);
568
-				}
569
-			}
570
-			elseif ($modulepart == 'member')
571
-			{
572
-				if (is_array($genallowed)) $modellist=$genallowed;
573
-				else
574
-				{
575
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
576
-					$modellist=ModelePDFCards::liste_modeles($this->db);
577
-				}
578
-			}
579
-			elseif ($modulepart == 'agenda' || $modulepart == 'actions')
580
-			{
581
-				if (is_array($genallowed)) $modellist=$genallowed;
582
-				else
583
-				{
584
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
585
-					$modellist=ModeleAction::liste_modeles($this->db);
586
-				}
587
-			}
588
-			else if ($modulepart == 'expensereport')
589
-			{
590
-				if (is_array($genallowed)) $modellist=$genallowed;
591
-				else
592
-				{
593
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
594
-					$modellist=ModeleExpenseReport::liste_modeles($this->db);
595
-				}
596
-			}
597
-			else if ($modulepart == 'unpaid')
598
-			{
599
-				$modellist='';
600
-			}
601
-			elseif ($modulepart == 'user')
602
-			{
603
-				if (is_array($genallowed)) $modellist=$genallowed;
604
-				else
605
-				{
606
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
607
-					$modellist=ModelePDFUser::liste_modeles($this->db);
608
-				}
609
-			}
610
-			elseif ($modulepart == 'usergroup')
611
-			{
612
-				if (is_array($genallowed)) $modellist=$genallowed;
613
-				else
614
-				{
615
-					include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
616
-					$modellist=ModelePDFUserGroup::liste_modeles($this->db);
617
-				}
618
-			}
619
-			else
620
-			{
621
-				// For normalized standard modules
622
-				$file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
623
-				if (file_exists($file))
624
-				{
625
-					$res=include_once $file;
626
-				}
627
-				// For normalized external modules
628
-				else
629
-				{
630
-					$file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
631
-					$res=include_once $file;
632
-				}
633
-				$class='ModelePDF'.ucfirst($modulepart);
634
-				if (class_exists($class))
635
-				{
636
-					$modellist=call_user_func($class.'::liste_modeles',$this->db);
637
-				}
638
-				else
639
-				{
640
-					dol_print_error($this->db,'Bad value for modulepart');
641
-					return -1;
642
-				}
643
-			}
644
-
645
-			// Set headershown to avoid to have table opened a second time later
646
-			$headershown=1;
647
-
648
-			$buttonlabeltoshow=$buttonlabel;
649
-			if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
650
-
651
-			if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form';   // So we switch to form after a generation
652
-			if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
653
-			$out.= '<input type="hidden" name="action" value="builddoc">';
654
-			$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
655
-
656
-			$out.= load_fiche_titre($titletoshow, '', '');
657
-			$out.= '<div class="div-table-responsive-no-min">';
658
-			$out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
659
-
660
-			$out.= '<tr class="liste_titre">';
661
-
662
-			$addcolumforpicto=($delallowed || $printer || $morepicto);
663
-			$out.= '<th align="center" colspan="'.(3+($addcolumforpicto?1:0)).'" class="formdoc liste_titre maxwidthonsmartphone">';
664
-
665
-			// Model
666
-			if (! empty($modellist))
667
-			{
668
-				$out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
669
-				if (is_array($modellist) && count($modellist) == 1)    // If there is only one element
670
-				{
671
-					$arraykeys=array_keys($modellist);
672
-					$modelselected=$arraykeys[0];
673
-				}
674
-				$out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
675
-				if ($conf->use_javascript_ajax)
676
-				{
677
-					$out.= ajax_combobox('model');
678
-				}
679
-			}
680
-			else
681
-			{
682
-				$out.= '<div class="float">'.$langs->trans("Files").'</div>';
683
-			}
684
-
685
-			// Language code (if multilang)
686
-			if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty))
687
-			{
688
-				include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
689
-				$formadmin=new FormAdmin($this->db);
690
-				$defaultlang=$codelang?$codelang:$langs->getDefaultLang();
691
-				$morecss='maxwidth150';
692
-				if ($conf->browser->layout == 'phone') $morecss='maxwidth100';
693
-				$out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
694
-			}
695
-			else
696
-			{
697
-				$out.= '&nbsp;';
698
-			}
699
-
700
-			// Button
701
-			$genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
702
-			$genbutton.= ' type="submit" value="'.$buttonlabel.'"';
703
-			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled';
704
-			$genbutton.= '>';
705
-			if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
706
-			{
707
-			   	$langs->load("errors");
708
-			   	$genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
709
-			}
710
-			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
711
-			if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton='';
712
-			$out.= $genbutton;
713
-			$out.= '</th>';
714
-
715
-			if (!empty($hookmanager->hooks['formfile']))
716
-			{
717
-				foreach($hookmanager->hooks['formfile'] as $module)
718
-				{
719
-					if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
720
-				}
721
-			}
722
-			$out.= '</tr>';
723
-
724
-			// Execute hooks
725
-			$parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
726
-			if (is_object($hookmanager))
727
-			{
728
-				$reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
729
-				$out.= $hookmanager->resPrint;
730
-			}
731
-		}
732
-
733
-		// Get list of files
734
-		if (! empty($filedir))
735
-		{
736
-			$link_list = array();
737
-			if (is_object($object))
738
-			{
739
-				require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
740
-				$link = new Link($this->db);
741
-				$sortfield = $sortorder = null;
742
-				$res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
743
-			}
744
-
745
-			$out.= '<!-- html.formfile::showdocuments -->'."\n";
746
-
747
-			// Show title of array if not already shown
748
-			if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
749
-				&& ! $headershown)
750
-			{
751
-				$headershown=1;
752
-				$out.= '<div class="titre">'.$titletoshow.'</div>'."\n";
753
-				$out.= '<div class="div-table-responsive-no-min">';
754
-				$out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n";
755
-			}
756
-
757
-			// Loop on each file found
758
-			if (is_array($file_list))
759
-			{
760
-				foreach($file_list as $file)
761
-				{
762
-					// Define relative path for download link (depends on module)
763
-					$relativepath=$file["name"];										// Cas general
764
-					if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
765
-					if ($modulepart == 'export') $relativepath = $file["name"];			// Other case
766
-
767
-					$out.= '<tr class="oddeven">';
768
-
769
-					$documenturl = DOL_URL_ROOT.'/document.php';
770
-					if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP;    // To use another wrapper
771
-
772
-					// Show file name with link to download
773
-					$out.= '<td class="minwidth200">';
774
-					$out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param?'&'.$param:'').'"';
775
-					$mime=dol_mimetype($relativepath,'',0);
776
-					if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
777
-					$out.= ' target="_blank">';
778
-					$out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]);
779
-					$out.= dol_trunc($file["name"], 150);
780
-					$out.= '</a>'."\n";
781
-					$out.= $this->showPreview($file,$modulepart,$relativepath,0,$param);
782
-					$out.= '</td>';
783
-
784
-					// Show file size
785
-					$size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
786
-					$out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>';
787
-
788
-					// Show file date
789
-					$date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
790
-					$out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
791
-
792
-					if ($delallowed || $printer || $morepicto)
793
-					{
794
-						$out.= '<td class="right nowraponall">';
795
-						if ($delallowed)
796
-						{
797
-							$tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
798
-							$out.= '<a href="'.$tmpurlsource.(strpos($tmpurlsource,'?')?'&amp;':'?').'action=remove_file&amp;file='.urlencode($relativepath);
799
-							$out.= ($param?'&amp;'.$param:'');
800
-							//$out.= '&modulepart='.$modulepart; // TODO obsolete ?
801
-							//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
802
-							$out.= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
803
-						}
804
-						if ($printer)
805
-						{
806
-							//$out.= '<td align="right">';
807
-							$out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
808
-							$out.= ($param?'&amp;'.$param:'');
809
-							$out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>';
810
-						}
811
-						if ($morepicto)
812
-						{
813
-							$morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto);
814
-							$out.=$morepicto;
815
-						}
816
-						$out.='</td>';
817
-					}
818
-
819
-					if (is_object($hookmanager))
820
-					{
821
-						$parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath);
822
-						$res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file);
823
-						if (empty($res))
824
-						{
825
-							$out.= $hookmanager->resPrint;		// Complete line
826
-							$out.= '</tr>';
827
-						}
828
-						else $out = $hookmanager->resPrint;		// Replace line
829
-			  		}
830
-				}
831
-
832
-				$this->numoffiles++;
833
-			}
834
-			// Loop on each link found
835
-			if (is_array($link_list))
836
-			{
837
-				$colspan=2;
838
-
839
-				foreach($link_list as $file)
840
-				{
841
-					$out.='<tr class="oddeven">';
842
-					$out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
843
-					$out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">';
844
-					$out.=$file->label;
845
-					$out.='</a>';
846
-					$out.='</td>';
847
-					$out.='<td align="right">';
848
-					$out.=dol_print_date($file->datea,'dayhour');
849
-					$out.='</td>';
850
-					if ($delallowed || $printer || $morepicto) $out.='<td></td>';
851
-					$out.='</tr>'."\n";
852
-				}
853
-				$this->numoffiles++;
854
-			}
855
-
856
-		 	if (count($file_list) == 0 && count($link_list) == 0 && $headershown)
857
-			{
858
-				$out.='<tr><td colspan="'.(3+($addcolumforpicto?1:0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
859
-			}
860
-		}
861
-
862
-		if ($headershown)
863
-		{
864
-			// Affiche pied du tableau
865
-			$out.= "</table>\n";
866
-			$out.= "</div>\n";
867
-			if ($genallowed)
868
-			{
869
-				if (empty($noform)) $out.= '</form>'."\n";
870
-			}
871
-		}
872
-		$out.= '<!-- End show_document -->'."\n";
873
-		//return ($i?$i:$headershown);
874
-		return $out;
875
-	}
876
-
877
-	/**
878
-	 *	Show a Document icon with link(s)
879
-	 *  You may want to call this into a div like this:
880
-	 *  print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
881
-	 *
882
-	 *	@param	string	$modulepart		propal, facture, facture_fourn, ...
883
-	 *	@param	string	$modulesubdir	Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
884
-	 *	@param	string	$filedir		Full path to directory to scan
885
-	 *  @param	string	$filter			Filter filenames on this regex string (Example: '\.pdf$')
886
-	 *	@return	string              	Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles
887
-	 */
888
-	function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
889
-	{
890
-		global $conf, $langs;
891
-
892
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
893
-
894
-		$out='';
895
-		$this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
896
-
897
-		$entity = 1; // Without multicompany
898
-
899
-		// Get object entity
900
-		if (! empty($conf->multicompany->enabled))
901
-		{
902
-			preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs);
903
-			$entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
904
-		}
905
-
906
-		// Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files)
907
-		// @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ?
908
-		if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
909
-		{
910
-			$filterforfilesearch = preg_quote(basename($modulesubdir),'/');
911
-		}
912
-		else
913
-		{
914
-			$filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+';
915
-		}
916
-		$file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$');	// We also discard .meta and .png preview
917
-
918
-		//var_dump($file_list);
919
-		// For ajax treatment
920
-		$out.= '<!-- html.formfile::getDocumentsLink -->'."\n";
921
-		if (! empty($file_list))
922
-		{
923
-			$out='<dl class="dropdown inline-block">
422
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
423
+                    $modellist = ModelePdfReception::liste_modeles($this->db);
424
+                }
425
+            }
426
+            elseif ($modulepart == 'livraison')
427
+            {
428
+                if (is_array($genallowed)) $modellist=$genallowed;
429
+                else
430
+                {
431
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
432
+                    $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
433
+                }
434
+            }
435
+            else if ($modulepart == 'ficheinter')
436
+            {
437
+                if (is_array($genallowed)) $modellist=$genallowed;
438
+                else
439
+                {
440
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
441
+                    $modellist=ModelePDFFicheinter::liste_modeles($this->db);
442
+                }
443
+            }
444
+            elseif ($modulepart == 'facture')
445
+            {
446
+                if (is_array($genallowed)) $modellist=$genallowed;
447
+                else
448
+                {
449
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
450
+                    $modellist=ModelePDFFactures::liste_modeles($this->db);
451
+                }
452
+            }
453
+            elseif ($modulepart == 'contract')
454
+            {
455
+                if (is_array($genallowed)) $modellist=$genallowed;
456
+                else
457
+                {
458
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
459
+                    $modellist=ModelePDFContract::liste_modeles($this->db);
460
+                }
461
+            }
462
+            elseif ($modulepart == 'project')
463
+            {
464
+                if (is_array($genallowed)) $modellist=$genallowed;
465
+                else
466
+                {
467
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
468
+                    $modellist=ModelePDFProjects::liste_modeles($this->db);
469
+                }
470
+            }
471
+            elseif ($modulepart == 'project_task')
472
+            {
473
+                if (is_array($genallowed)) $modellist=$genallowed;
474
+                else
475
+                {
476
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
477
+                    $modellist=ModelePDFTask::liste_modeles($this->db);
478
+                }
479
+            }
480
+            elseif ($modulepart == 'product')
481
+            {
482
+                if (is_array($genallowed)) $modellist=$genallowed;
483
+                else
484
+                {
485
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
486
+                    $modellist=ModelePDFProduct::liste_modeles($this->db);
487
+                }
488
+            }
489
+            elseif ($modulepart == 'product_batch')
490
+            {
491
+                if (is_array($genallowed)) $modellist=$genallowed;
492
+                else
493
+                {
494
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
495
+                    $modellist=ModelePDFProductBatch::liste_modeles($this->db);
496
+                }
497
+            }
498
+            elseif ($modulepart == 'stock')
499
+            {
500
+                if (is_array($genallowed)) $modellist=$genallowed;
501
+                else
502
+                {
503
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
504
+                    $modellist=ModelePDFStock::liste_modeles($this->db);
505
+                }
506
+            }
507
+            elseif ($modulepart == 'movement')
508
+            {
509
+                if (is_array($genallowed)) $modellist=$genallowed;
510
+                else
511
+                {
512
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php';
513
+                    $modellist=ModelePDFMovement::liste_modeles($this->db);
514
+                }
515
+            }
516
+            elseif ($modulepart == 'export')
517
+            {
518
+                if (is_array($genallowed)) $modellist=$genallowed;
519
+                else
520
+                {
521
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
522
+                    $modellist=ModeleExports::liste_modeles($this->db);
523
+                }
524
+            }
525
+            else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
526
+            {
527
+                if (is_array($genallowed)) $modellist=$genallowed;
528
+                else
529
+                {
530
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
531
+                    $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
532
+                }
533
+            }
534
+            else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
535
+            {
536
+                if (is_array($genallowed)) $modellist=$genallowed;
537
+                else
538
+                {
539
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
540
+                    $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
541
+                }
542
+            }
543
+            else if ($modulepart == 'supplier_payment')
544
+            {
545
+                if (is_array($genallowed)) $modellist=$genallowed;
546
+                else
547
+                {
548
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
549
+                    $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db);
550
+                }
551
+            }
552
+            else if ($modulepart == 'remisecheque')
553
+            {
554
+                if (is_array($genallowed)) $modellist=$genallowed;
555
+                else
556
+                {
557
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
558
+                    $modellist=ModeleChequeReceipts::liste_modeles($this->db);
559
+                }
560
+            }
561
+            elseif ($modulepart == 'donation')
562
+            {
563
+                if (is_array($genallowed)) $modellist=$genallowed;
564
+                else
565
+                {
566
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
567
+                    $modellist=ModeleDon::liste_modeles($this->db);
568
+                }
569
+            }
570
+            elseif ($modulepart == 'member')
571
+            {
572
+                if (is_array($genallowed)) $modellist=$genallowed;
573
+                else
574
+                {
575
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
576
+                    $modellist=ModelePDFCards::liste_modeles($this->db);
577
+                }
578
+            }
579
+            elseif ($modulepart == 'agenda' || $modulepart == 'actions')
580
+            {
581
+                if (is_array($genallowed)) $modellist=$genallowed;
582
+                else
583
+                {
584
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
585
+                    $modellist=ModeleAction::liste_modeles($this->db);
586
+                }
587
+            }
588
+            else if ($modulepart == 'expensereport')
589
+            {
590
+                if (is_array($genallowed)) $modellist=$genallowed;
591
+                else
592
+                {
593
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
594
+                    $modellist=ModeleExpenseReport::liste_modeles($this->db);
595
+                }
596
+            }
597
+            else if ($modulepart == 'unpaid')
598
+            {
599
+                $modellist='';
600
+            }
601
+            elseif ($modulepart == 'user')
602
+            {
603
+                if (is_array($genallowed)) $modellist=$genallowed;
604
+                else
605
+                {
606
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
607
+                    $modellist=ModelePDFUser::liste_modeles($this->db);
608
+                }
609
+            }
610
+            elseif ($modulepart == 'usergroup')
611
+            {
612
+                if (is_array($genallowed)) $modellist=$genallowed;
613
+                else
614
+                {
615
+                    include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
616
+                    $modellist=ModelePDFUserGroup::liste_modeles($this->db);
617
+                }
618
+            }
619
+            else
620
+            {
621
+                // For normalized standard modules
622
+                $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
623
+                if (file_exists($file))
624
+                {
625
+                    $res=include_once $file;
626
+                }
627
+                // For normalized external modules
628
+                else
629
+                {
630
+                    $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
631
+                    $res=include_once $file;
632
+                }
633
+                $class='ModelePDF'.ucfirst($modulepart);
634
+                if (class_exists($class))
635
+                {
636
+                    $modellist=call_user_func($class.'::liste_modeles',$this->db);
637
+                }
638
+                else
639
+                {
640
+                    dol_print_error($this->db,'Bad value for modulepart');
641
+                    return -1;
642
+                }
643
+            }
644
+
645
+            // Set headershown to avoid to have table opened a second time later
646
+            $headershown=1;
647
+
648
+            $buttonlabeltoshow=$buttonlabel;
649
+            if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
650
+
651
+            if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form';   // So we switch to form after a generation
652
+            if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
653
+            $out.= '<input type="hidden" name="action" value="builddoc">';
654
+            $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
655
+
656
+            $out.= load_fiche_titre($titletoshow, '', '');
657
+            $out.= '<div class="div-table-responsive-no-min">';
658
+            $out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
659
+
660
+            $out.= '<tr class="liste_titre">';
661
+
662
+            $addcolumforpicto=($delallowed || $printer || $morepicto);
663
+            $out.= '<th align="center" colspan="'.(3+($addcolumforpicto?1:0)).'" class="formdoc liste_titre maxwidthonsmartphone">';
664
+
665
+            // Model
666
+            if (! empty($modellist))
667
+            {
668
+                $out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
669
+                if (is_array($modellist) && count($modellist) == 1)    // If there is only one element
670
+                {
671
+                    $arraykeys=array_keys($modellist);
672
+                    $modelselected=$arraykeys[0];
673
+                }
674
+                $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
675
+                if ($conf->use_javascript_ajax)
676
+                {
677
+                    $out.= ajax_combobox('model');
678
+                }
679
+            }
680
+            else
681
+            {
682
+                $out.= '<div class="float">'.$langs->trans("Files").'</div>';
683
+            }
684
+
685
+            // Language code (if multilang)
686
+            if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty))
687
+            {
688
+                include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
689
+                $formadmin=new FormAdmin($this->db);
690
+                $defaultlang=$codelang?$codelang:$langs->getDefaultLang();
691
+                $morecss='maxwidth150';
692
+                if ($conf->browser->layout == 'phone') $morecss='maxwidth100';
693
+                $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
694
+            }
695
+            else
696
+            {
697
+                $out.= '&nbsp;';
698
+            }
699
+
700
+            // Button
701
+            $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
702
+            $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
703
+            if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled';
704
+            $genbutton.= '>';
705
+            if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
706
+            {
707
+                    $langs->load("errors");
708
+                    $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
709
+            }
710
+            if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
711
+            if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton='';
712
+            $out.= $genbutton;
713
+            $out.= '</th>';
714
+
715
+            if (!empty($hookmanager->hooks['formfile']))
716
+            {
717
+                foreach($hookmanager->hooks['formfile'] as $module)
718
+                {
719
+                    if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
720
+                }
721
+            }
722
+            $out.= '</tr>';
723
+
724
+            // Execute hooks
725
+            $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
726
+            if (is_object($hookmanager))
727
+            {
728
+                $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
729
+                $out.= $hookmanager->resPrint;
730
+            }
731
+        }
732
+
733
+        // Get list of files
734
+        if (! empty($filedir))
735
+        {
736
+            $link_list = array();
737
+            if (is_object($object))
738
+            {
739
+                require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
740
+                $link = new Link($this->db);
741
+                $sortfield = $sortorder = null;
742
+                $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
743
+            }
744
+
745
+            $out.= '<!-- html.formfile::showdocuments -->'."\n";
746
+
747
+            // Show title of array if not already shown
748
+            if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
749
+                && ! $headershown)
750
+            {
751
+                $headershown=1;
752
+                $out.= '<div class="titre">'.$titletoshow.'</div>'."\n";
753
+                $out.= '<div class="div-table-responsive-no-min">';
754
+                $out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n";
755
+            }
756
+
757
+            // Loop on each file found
758
+            if (is_array($file_list))
759
+            {
760
+                foreach($file_list as $file)
761
+                {
762
+                    // Define relative path for download link (depends on module)
763
+                    $relativepath=$file["name"];										// Cas general
764
+                    if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
765
+                    if ($modulepart == 'export') $relativepath = $file["name"];			// Other case
766
+
767
+                    $out.= '<tr class="oddeven">';
768
+
769
+                    $documenturl = DOL_URL_ROOT.'/document.php';
770
+                    if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP;    // To use another wrapper
771
+
772
+                    // Show file name with link to download
773
+                    $out.= '<td class="minwidth200">';
774
+                    $out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param?'&'.$param:'').'"';
775
+                    $mime=dol_mimetype($relativepath,'',0);
776
+                    if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
777
+                    $out.= ' target="_blank">';
778
+                    $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]);
779
+                    $out.= dol_trunc($file["name"], 150);
780
+                    $out.= '</a>'."\n";
781
+                    $out.= $this->showPreview($file,$modulepart,$relativepath,0,$param);
782
+                    $out.= '</td>';
783
+
784
+                    // Show file size
785
+                    $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
786
+                    $out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>';
787
+
788
+                    // Show file date
789
+                    $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
790
+                    $out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
791
+
792
+                    if ($delallowed || $printer || $morepicto)
793
+                    {
794
+                        $out.= '<td class="right nowraponall">';
795
+                        if ($delallowed)
796
+                        {
797
+                            $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
798
+                            $out.= '<a href="'.$tmpurlsource.(strpos($tmpurlsource,'?')?'&amp;':'?').'action=remove_file&amp;file='.urlencode($relativepath);
799
+                            $out.= ($param?'&amp;'.$param:'');
800
+                            //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
801
+                            //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
802
+                            $out.= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
803
+                        }
804
+                        if ($printer)
805
+                        {
806
+                            //$out.= '<td align="right">';
807
+                            $out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
808
+                            $out.= ($param?'&amp;'.$param:'');
809
+                            $out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>';
810
+                        }
811
+                        if ($morepicto)
812
+                        {
813
+                            $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto);
814
+                            $out.=$morepicto;
815
+                        }
816
+                        $out.='</td>';
817
+                    }
818
+
819
+                    if (is_object($hookmanager))
820
+                    {
821
+                        $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath);
822
+                        $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file);
823
+                        if (empty($res))
824
+                        {
825
+                            $out.= $hookmanager->resPrint;		// Complete line
826
+                            $out.= '</tr>';
827
+                        }
828
+                        else $out = $hookmanager->resPrint;		// Replace line
829
+                        }
830
+                }
831
+
832
+                $this->numoffiles++;
833
+            }
834
+            // Loop on each link found
835
+            if (is_array($link_list))
836
+            {
837
+                $colspan=2;
838
+
839
+                foreach($link_list as $file)
840
+                {
841
+                    $out.='<tr class="oddeven">';
842
+                    $out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
843
+                    $out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">';
844
+                    $out.=$file->label;
845
+                    $out.='</a>';
846
+                    $out.='</td>';
847
+                    $out.='<td align="right">';
848
+                    $out.=dol_print_date($file->datea,'dayhour');
849
+                    $out.='</td>';
850
+                    if ($delallowed || $printer || $morepicto) $out.='<td></td>';
851
+                    $out.='</tr>'."\n";
852
+                }
853
+                $this->numoffiles++;
854
+            }
855
+
856
+                if (count($file_list) == 0 && count($link_list) == 0 && $headershown)
857
+            {
858
+                $out.='<tr><td colspan="'.(3+($addcolumforpicto?1:0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
859
+            }
860
+        }
861
+
862
+        if ($headershown)
863
+        {
864
+            // Affiche pied du tableau
865
+            $out.= "</table>\n";
866
+            $out.= "</div>\n";
867
+            if ($genallowed)
868
+            {
869
+                if (empty($noform)) $out.= '</form>'."\n";
870
+            }
871
+        }
872
+        $out.= '<!-- End show_document -->'."\n";
873
+        //return ($i?$i:$headershown);
874
+        return $out;
875
+    }
876
+
877
+    /**
878
+     *	Show a Document icon with link(s)
879
+     *  You may want to call this into a div like this:
880
+     *  print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
881
+     *
882
+     *	@param	string	$modulepart		propal, facture, facture_fourn, ...
883
+     *	@param	string	$modulesubdir	Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
884
+     *	@param	string	$filedir		Full path to directory to scan
885
+     *  @param	string	$filter			Filter filenames on this regex string (Example: '\.pdf$')
886
+     *	@return	string              	Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles
887
+     */
888
+    function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
889
+    {
890
+        global $conf, $langs;
891
+
892
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
893
+
894
+        $out='';
895
+        $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
896
+
897
+        $entity = 1; // Without multicompany
898
+
899
+        // Get object entity
900
+        if (! empty($conf->multicompany->enabled))
901
+        {
902
+            preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs);
903
+            $entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
904
+        }
905
+
906
+        // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files)
907
+        // @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ?
908
+        if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
909
+        {
910
+            $filterforfilesearch = preg_quote(basename($modulesubdir),'/');
911
+        }
912
+        else
913
+        {
914
+            $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+';
915
+        }
916
+        $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$');	// We also discard .meta and .png preview
917
+
918
+        //var_dump($file_list);
919
+        // For ajax treatment
920
+        $out.= '<!-- html.formfile::getDocumentsLink -->'."\n";
921
+        if (! empty($file_list))
922
+        {
923
+            $out='<dl class="dropdown inline-block">
924 924
     			<dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', 'valignmiddle').'</a></dt>
925 925
     			<dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields" style="display: none;">';
926
-			$tmpout='';
927
-
928
-			// Loop on each file found
929
-			$found=0;
930
-			foreach($file_list as $file)
931
-			{
932
-				$i++;
933
-				if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue;	// Discard this. It does not match provided filter.
934
-
935
-				$found++;
936
-				// Define relative path for download link (depends on module)
937
-				$relativepath=$file["name"];								// Cas general
938
-				if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
939
-				// Autre cas
940
-				if ($modulepart == 'donation')            {
941
-					$relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
942
-				}
943
-				if ($modulepart == 'export')              {
944
-					$relativepath = $file["name"];
945
-				}
946
-
947
-				$this->infofiles['nboffiles']++;
948
-				$this->infofiles['files'][]=$file['fullname'];
949
-				$ext=pathinfo($file["name"], PATHINFO_EXTENSION);
950
-				if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
951
-				else $this->infofiles['extensions'][$ext]++;
952
-
953
-				// Preview
954
-				if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
955
-				{
956
-					$tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
957
-					if ($tmparray && $tmparray['url'])
958
-					{
959
-						$tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>';
960
-						//$tmpout.= img_picto('','detail');
961
-						$tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
962
-						$tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>';
963
-					}
964
-				}
965
-
966
-				// Download
967
-				$tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
968
-				$mime=dol_mimetype($relativepath,'',0);
969
-				if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
970
-				$tmpout.= '>';
971
-				$tmpout.= img_mime($relativepath, $file["name"]);
972
-				$tmpout.= $langs->trans("Download").' '.$ext;
973
-				$tmpout.= '</a></li>'."\n";
974
-			}
975
-			$out.=$tmpout;
976
-			$out.='</ul></div></dd>
926
+            $tmpout='';
927
+
928
+            // Loop on each file found
929
+            $found=0;
930
+            foreach($file_list as $file)
931
+            {
932
+                $i++;
933
+                if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue;	// Discard this. It does not match provided filter.
934
+
935
+                $found++;
936
+                // Define relative path for download link (depends on module)
937
+                $relativepath=$file["name"];								// Cas general
938
+                if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
939
+                // Autre cas
940
+                if ($modulepart == 'donation')            {
941
+                    $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
942
+                }
943
+                if ($modulepart == 'export')              {
944
+                    $relativepath = $file["name"];
945
+                }
946
+
947
+                $this->infofiles['nboffiles']++;
948
+                $this->infofiles['files'][]=$file['fullname'];
949
+                $ext=pathinfo($file["name"], PATHINFO_EXTENSION);
950
+                if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
951
+                else $this->infofiles['extensions'][$ext]++;
952
+
953
+                // Preview
954
+                if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
955
+                {
956
+                    $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
957
+                    if ($tmparray && $tmparray['url'])
958
+                    {
959
+                        $tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>';
960
+                        //$tmpout.= img_picto('','detail');
961
+                        $tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
962
+                        $tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>';
963
+                    }
964
+                }
965
+
966
+                // Download
967
+                $tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
968
+                $mime=dol_mimetype($relativepath,'',0);
969
+                if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
970
+                $tmpout.= '>';
971
+                $tmpout.= img_mime($relativepath, $file["name"]);
972
+                $tmpout.= $langs->trans("Download").' '.$ext;
973
+                $tmpout.= '</a></li>'."\n";
974
+            }
975
+            $out.=$tmpout;
976
+            $out.='</ul></div></dd>
977 977
     			</dl>';
978 978
 
979
-			if (! $found) $out='';
980
-		}
981
-		else
982
-		{
983
-			// TODO Add link to regenerate doc ?
984
-			//$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
985
-		}
979
+            if (! $found) $out='';
980
+        }
981
+        else
982
+        {
983
+            // TODO Add link to regenerate doc ?
984
+            //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
985
+        }
986 986
 
987
-		return $out;
988
-	}
987
+        return $out;
988
+    }
989 989
 
990 990
 
991 991
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
992
-	/**
993
-	 *  Show list of documents in $filearray (may be they are all in same directory but may not)
994
-	 *  This also sync database if $upload_dir is defined.
995
-	 *
996
-	 *  @param	 array	$filearray          Array of files loaded by dol_dir_list('files') function before calling this.
997
-	 * 	@param	 Object	$object				Object on which document is linked to.
998
-	 * 	@param	 string	$modulepart			Value for modulepart used by download or viewimage wrapper.
999
-	 * 	@param	 string	$param				Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd)
1000
-	 * 	@param	 int	$forcedownload		Force to open dialog box "Save As" when clicking on file.
1001
-	 * 	@param	 string	$relativepath		Relative path of docs (autodefined if not provided), relative to module dir, not to MAIN_DATA_ROOT.
1002
-	 * 	@param	 int	$permonobject		Permission on object (so permission to delete or crop document)
1003
-	 * 	@param	 int	$useinecm			Change output for use in ecm module:
1004
-	 * 										0: Add a previw link. Show also rename and crop file
1005
-	 * 										1: Add link to edit ECM entry
1006
-	 * 										2: Add rename and crop file
1007
-	 * 	@param	 string	$textifempty		Text to show if filearray is empty ('NoFileFound' if not defined)
1008
-	 *  @param   int	$maxlength          Maximum length of file name shown.
1009
-	 *  @param	 string	$title				Title before list. Use 'none' to disable title.
1010
-	 *  @param	 string $url				Full url to use for click links ('' = autodetect)
1011
-	 *  @param	 int	$showrelpart		0=Show only filename (default), 1=Show first level 1 dir
1012
-	 *  @param   int    $permtoeditline     Permission to edit document line (You must provide a value, -1 is deprecated and must not be used any more)
1013
-	 *  @param   string $upload_dir         Full path directory so we can know dir relative to MAIN_DATA_ROOT. Fill this to complete file data with database indexes.
1014
-	 *  @param   string $sortfield          Sort field ('name', 'size', 'position', ...)
1015
-	 *  @param   string $sortorder          Sort order ('ASC' or 'DESC')
1016
-	 *  @param   int    $disablemove        1=Disable move button, 0=Position move is possible.
1017
-	 *  @param	 int	$addfilterfields	Add line with filters
1018
-	 * 	@return	 int						<0 if KO, nb of files shown if OK
1019
-	 *  @see list_of_autoecmfiles
1020
-	 */
1021
-	function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1, $addfilterfields=0)
1022
-	{
992
+    /**
993
+     *  Show list of documents in $filearray (may be they are all in same directory but may not)
994
+     *  This also sync database if $upload_dir is defined.
995
+     *
996
+     *  @param	 array	$filearray          Array of files loaded by dol_dir_list('files') function before calling this.
997
+     * 	@param	 Object	$object				Object on which document is linked to.
998
+     * 	@param	 string	$modulepart			Value for modulepart used by download or viewimage wrapper.
999
+     * 	@param	 string	$param				Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd)
1000
+     * 	@param	 int	$forcedownload		Force to open dialog box "Save As" when clicking on file.
1001
+     * 	@param	 string	$relativepath		Relative path of docs (autodefined if not provided), relative to module dir, not to MAIN_DATA_ROOT.
1002
+     * 	@param	 int	$permonobject		Permission on object (so permission to delete or crop document)
1003
+     * 	@param	 int	$useinecm			Change output for use in ecm module:
1004
+     * 										0: Add a previw link. Show also rename and crop file
1005
+     * 										1: Add link to edit ECM entry
1006
+     * 										2: Add rename and crop file
1007
+     * 	@param	 string	$textifempty		Text to show if filearray is empty ('NoFileFound' if not defined)
1008
+     *  @param   int	$maxlength          Maximum length of file name shown.
1009
+     *  @param	 string	$title				Title before list. Use 'none' to disable title.
1010
+     *  @param	 string $url				Full url to use for click links ('' = autodetect)
1011
+     *  @param	 int	$showrelpart		0=Show only filename (default), 1=Show first level 1 dir
1012
+     *  @param   int    $permtoeditline     Permission to edit document line (You must provide a value, -1 is deprecated and must not be used any more)
1013
+     *  @param   string $upload_dir         Full path directory so we can know dir relative to MAIN_DATA_ROOT. Fill this to complete file data with database indexes.
1014
+     *  @param   string $sortfield          Sort field ('name', 'size', 'position', ...)
1015
+     *  @param   string $sortorder          Sort order ('ASC' or 'DESC')
1016
+     *  @param   int    $disablemove        1=Disable move button, 0=Position move is possible.
1017
+     *  @param	 int	$addfilterfields	Add line with filters
1018
+     * 	@return	 int						<0 if KO, nb of files shown if OK
1019
+     *  @see list_of_autoecmfiles
1020
+     */
1021
+    function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1, $addfilterfields=0)
1022
+    {
1023 1023
         // phpcs:enable
1024
-		global $user, $conf, $langs, $hookmanager;
1025
-		global $sortfield, $sortorder, $maxheightmini;
1026
-		global $dolibarr_main_url_root;
1027
-		global $form;
1028
-
1029
-		$disablecrop=1;
1030
-		if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0;
1031
-
1032
-		// Define relative path used to store the file
1033
-		if (empty($relativepath))
1034
-		{
1035
-			$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
1036
-			if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;	// TODO Call using a defined value for $relativepath
1037
-			if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1038
-		}
1039
-		// For backward compatiblity, we detect file stored into an old path
1040
-		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
1041
-		{
1042
-		    $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/';
1043
-		}
1044
-		// Defined relative dir to DOL_DATA_ROOT
1045
-		$relativedir = '';
1046
-		if ($upload_dir)
1047
-		{
1048
-			$relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
1049
-			$relativedir = preg_replace('/^[\\/]/','',$relativedir);
1050
-		}
1051
-
1052
-		$hookmanager->initHooks(array('formfile'));
1053
-		$parameters=array(
1054
-				'filearray' => $filearray,
1055
-				'modulepart'=> $modulepart,
1056
-				'param' => $param,
1057
-				'forcedownload' => $forcedownload,
1058
-				'relativepath' => $relativepath,    // relative filename to module dir
1059
-				'relativedir' => $relativedir,      // relative dirname to DOL_DATA_ROOT
1060
-				'permtodelete' => $permonobject,
1061
-				'useinecm' => $useinecm,
1062
-				'textifempty' => $textifempty,
1063
-				'maxlength' => $maxlength,
1064
-				'title' => $title,
1065
-				'url' => $url
1066
-		);
1067
-		$reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
1068
-
1069
-		if (isset($reshook) && $reshook != '') // null or '' for bypass
1070
-		{
1071
-			return $reshook;
1072
-		}
1073
-		else
1074
-		{
1075
-			if (! is_object($form))
1076
-			{
1077
-				include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';		// The compoent may be included into ajax page that does not include the Form class
1078
-				$form=new Form($this->db);
1079
-			}
1080
-
1081
-			if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id;
1082
-			$relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath);
1083
-			if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend);
1084
-
1085
-			if ($permtoeditline < 0)  // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1086
-			{
1087
-				$permtoeditline=0;
1088
-				if (in_array($modulepart, array('product','produit','service')))
1089
-				{
1090
-					if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1;
1091
-					if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1;
1092
-				}
1093
-			}
1094
-			if (empty($conf->global->MAIN_UPLOAD_DOC))
1095
-			{
1096
-				$permtoeditline=0;
1097
-				$permonobject=0;
1098
-			}
1099
-
1100
-			// Show list of existing files
1101
-			if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1102
-			if (empty($url)) $url=$_SERVER["PHP_SELF"];
1103
-
1104
-			print '<!-- html.formfile::list_of_documents -->'."\n";
1105
-			if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1106
-			{
1107
-				print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1108
-				print '<input type="hidden" name="action" value="renamefile">';
1109
-				print '<input type="hidden" name="id" value="'.$object->id.'">';
1110
-				print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
1111
-			}
1112
-
1113
-			print '<div class="div-table-responsive-no-min">';
1114
-			print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
1115
-
1116
-			if (! empty($addfilterfields))
1117
-			{
1118
-				print '<tr class="liste_titre nodrag nodrop">';
1119
-				print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
1120
-				print '<td></td>';
1121
-				print '<td></td>';
1122
-				if (empty($useinecm)) print '<td></td>';
1123
-				print '<td></td>';
1124
-				print '<td></td>';
1125
-				if (! $disablemove) print '<td></td>';
1126
-				print "</tr>\n";
1127
-			}
1128
-
1129
-			print '<tr class="liste_titre nodrag nodrop">';
1130
-			//print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
1131
-			print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1132
-			print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1133
-			print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1134
-			if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');					// Preview
1135
-			print_liste_field_titre('');
1136
-			print_liste_field_titre('');
1137
-			if (! $disablemove) print_liste_field_titre('');
1138
-			print "</tr>\n";
1139
-
1140
-			// Get list of files stored into database for same relative directory
1141
-			if ($relativedir)
1142
-			{
1143
-				completeFileArrayWithDatabaseInfo($filearray, $relativedir);
1144
-
1145
-				//var_dump($sortfield.' - '.$sortorder);
1146
-				if ($sortfield && $sortorder)	// If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1147
-				{
1148
-					$filearray=dol_sort_array($filearray, $sortfield, $sortorder);
1149
-				}
1150
-			}
1151
-
1152
-			$nboffiles=count($filearray);
1153
-			if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1154
-
1155
-			$i=0; $nboflines = 0; $lastrowid=0;
1156
-			foreach($filearray as $key => $file)      // filearray must be only files here
1157
-			{
1158
-				if ($file['name'] != '.'
1159
-						&& $file['name'] != '..'
1160
-						&& ! preg_match('/\.meta$/i',$file['name']))
1161
-				{
1162
-					if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
1163
-					$filepath=$relativepath.$file['name'];
1164
-
1165
-					$editline=0;
1166
-					$nboflines++;
1167
-					print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1168
-					// Do we have entry into database ?
1169
-					print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
1170
-					print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'AFTER'.$lastrowid.'POS'.($i+1)).'">';
1171
-
1172
-					// File name
1173
-					print '<td class="minwith200">';
1174
-
1175
-					// Show file name with link to download
1176
-					//print "XX".$file['name'];	//$file['name'] must be utf8
1177
-					print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1178
-					if ($forcedownload) print '&attachment=1';
1179
-					if (! empty($object->entity)) print '&entity='.$object->entity;
1180
-					print '&file='.urlencode($filepath);
1181
-					print '">';
1182
-					print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
1183
-					if ($showrelpart == 1) print $relativepath;
1184
-					//print dol_trunc($file['name'],$maxlength,'middle');
1185
-					if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
1186
-					{
1187
-						print '</a>';
1188
-						$section_dir=dirname(GETPOST('urlfile','alpha'));
1189
-						print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1190
-						print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1191
-						print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1192
-						$editline=1;
1193
-					}
1194
-					else
1195
-					{
1196
-						print dol_trunc($file['name'], 200);
1197
-						print '</a>';
1198
-					}
1199
-					// Preview link
1200
-					if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
1201
-					// Public share link
1202
-					//if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
1203
-
1204
-					print "</td>\n";
1205
-
1206
-					// Size
1207
-					$sizetoshow = dol_print_size($file['size'],1,1);
1208
-					$sizetoshowbytes = dol_print_size($file['size'],0,1);
1209
-
1210
-					print '<td align="right" width="80px">';
1211
-					if ($sizetoshow == $sizetoshowbytes) print $sizetoshow;
1212
-					else {
1213
-						print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
1214
-					}
1215
-					print '</td>';
1216
-
1217
-					// Date
1218
-					print '<td align="center" width="140px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>';	// 140px = width for date with PM format
1219
-
1220
-					// Preview
1221
-					if (empty($useinecm))
1222
-					{
1223
-						$fileinfo = pathinfo($file['name']);
1224
-						print '<td align="center">';
1225
-						if (image_format_supported($file['name']) > 0)
1226
-						{
1227
-							$minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1228
-							if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1229
-							//print $file['path'].'/'.$minifile.'<br>';
1230
-
1231
-							$urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity));
1232
-							if (empty($urlforhref)) {
1233
-								$urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1234
-								print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
1235
-							} else {
1236
-								print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
1237
-							}
1238
-							print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
1239
-							print '</a>';
1240
-						}
1241
-						else print '&nbsp;';
1242
-						print '</td>';
1243
-					}
1244
-
1245
-					// Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table)
1246
-					print '<td align="center">';
1247
-					if ($relativedir && $filearray[$key]['rowid'] > 0)
1248
-					{
1249
-						if ($editline)
1250
-						{
1251
-							print $langs->trans("FileSharedViaALink").' ';
1252
-							print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> ';
1253
-						}
1254
-						else
1255
-						{
1256
-							if ($file['share'])
1257
-							{
1258
-								// Define $urlwithroot
1259
-								$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
1260
-								$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
1261
-								//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
1262
-
1263
-								//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1264
-								$forcedownload=0;
1265
-								$paramlink='';
1266
-								if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share'];			// Hash for public share
1267
-								if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
1268
-
1269
-								$fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
1270
-
1271
-								print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' ';
1272
-								print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
1273
-							}
1274
-							else
1275
-							{
1276
-								//print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1277
-							}
1278
-						}
1279
-					}
1280
-					print '</td>';
1281
-
1282
-					// Actions buttons
1283
-					if (! $editline)
1284
-					{
1285
-						// Delete or view link
1286
-						// ($param must start with &)
1287
-						print '<td class="valignmiddle right actionbuttons"><!-- action on files -->';
1288
-						if ($useinecm == 1)
1289
-						{
1290
-							print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1291
-						}
1292
-						if (! $useinecm || $useinecm == 2)
1293
-						{
1294
-							$newmodulepart=$modulepart;
1295
-							if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
1296
-
1297
-							if (! $disablecrop && image_format_supported($file['name']) > 0)
1298
-							{
1299
-								if ($permtoeditline)
1300
-								{
1301
-	   								// Link to resize
1302
-	   						   		print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>';
1303
-								}
1304
-							}
1305
-
1306
-							if ($permtoeditline)
1307
-							{
1308
-								$paramsectiondir=(in_array($modulepart, array('medias','ecm'))?'&section_dir='.urlencode($relativepath):'');
1309
-								print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>';
1310
-							}
1311
-						}
1312
-						if ($permonobject)
1313
-						{
1314
-							$useajax=1;
1315
-							if (! empty($conf->dol_use_jmobile)) $useajax=0;
1316
-							if (empty($conf->use_javascript_ajax)) $useajax=0;
1317
-							if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
1318
-							print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1319
-						}
1320
-						print "</td>";
1024
+        global $user, $conf, $langs, $hookmanager;
1025
+        global $sortfield, $sortorder, $maxheightmini;
1026
+        global $dolibarr_main_url_root;
1027
+        global $form;
1028
+
1029
+        $disablecrop=1;
1030
+        if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0;
1031
+
1032
+        // Define relative path used to store the file
1033
+        if (empty($relativepath))
1034
+        {
1035
+            $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
1036
+            if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;	// TODO Call using a defined value for $relativepath
1037
+            if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1038
+        }
1039
+        // For backward compatiblity, we detect file stored into an old path
1040
+        if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
1041
+        {
1042
+            $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/';
1043
+        }
1044
+        // Defined relative dir to DOL_DATA_ROOT
1045
+        $relativedir = '';
1046
+        if ($upload_dir)
1047
+        {
1048
+            $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
1049
+            $relativedir = preg_replace('/^[\\/]/','',$relativedir);
1050
+        }
1051
+
1052
+        $hookmanager->initHooks(array('formfile'));
1053
+        $parameters=array(
1054
+                'filearray' => $filearray,
1055
+                'modulepart'=> $modulepart,
1056
+                'param' => $param,
1057
+                'forcedownload' => $forcedownload,
1058
+                'relativepath' => $relativepath,    // relative filename to module dir
1059
+                'relativedir' => $relativedir,      // relative dirname to DOL_DATA_ROOT
1060
+                'permtodelete' => $permonobject,
1061
+                'useinecm' => $useinecm,
1062
+                'textifempty' => $textifempty,
1063
+                'maxlength' => $maxlength,
1064
+                'title' => $title,
1065
+                'url' => $url
1066
+        );
1067
+        $reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
1068
+
1069
+        if (isset($reshook) && $reshook != '') // null or '' for bypass
1070
+        {
1071
+            return $reshook;
1072
+        }
1073
+        else
1074
+        {
1075
+            if (! is_object($form))
1076
+            {
1077
+                include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';		// The compoent may be included into ajax page that does not include the Form class
1078
+                $form=new Form($this->db);
1079
+            }
1321 1080
 
1322
-						if (empty($disablemove))
1323
-						{
1324
-							if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
1325
-								print '<td align="center" class="linecolmove tdlineupdown">';
1326
-								if ($i > 0) {
1327
-									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>';
1328
-								}
1329
-								if ($i < $nboffiles-1) {
1330
-									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
1331
-								}
1332
-								print '</td>';
1333
-							}
1334
-							else {
1335
-							   	print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
1336
-							   	print '</td>';
1337
-							}
1338
-					   }
1339
-					}
1340
-					else
1341
-					{
1342
-						print '<td class="right">';
1343
-						print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">';
1344
-						print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1345
-						print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1346
-						print '</td>';
1347
-						if (empty($disablemove)) print '<td class="right"></td>';
1348
-					}
1349
-					print "</tr>\n";
1350
-
1351
-					$i++;
1352
-				}
1353
-			}
1354
-			if ($nboffiles == 0)
1355
-			{
1356
-				$colspan=(empty($useinecm)?'6':'6');
1357
-				if (empty($disablemove)) $colspan++;		// 6 columns or 7
1358
-				print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">';
1359
-				if (empty($textifempty)) print $langs->trans("NoFileFound");
1360
-				else print $textifempty;
1361
-				print '</td></tr>';
1362
-			}
1363
-			print "</table>";
1364
-			print '</div>';
1365
-
1366
-			if ($nboflines > 1 && is_object($object)) {
1367
-				if (! empty($conf->use_javascript_ajax) && $permtoeditline) {
1368
-					$table_element_line = 'ecm_files';
1369
-					include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1370
-				}
1371
-			}
1372
-
1373
-			print ajax_autoselect('downloadlink');
1374
-
1375
-			if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1376
-			{
1377
-				print '</form>';
1378
-			}
1379
-
1380
-			return $nboffiles;
1381
-		}
1382
-	}
1081
+            if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id;
1082
+            $relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath);
1083
+            if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend);
1084
+
1085
+            if ($permtoeditline < 0)  // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1086
+            {
1087
+                $permtoeditline=0;
1088
+                if (in_array($modulepart, array('product','produit','service')))
1089
+                {
1090
+                    if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1;
1091
+                    if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1;
1092
+                }
1093
+            }
1094
+            if (empty($conf->global->MAIN_UPLOAD_DOC))
1095
+            {
1096
+                $permtoeditline=0;
1097
+                $permonobject=0;
1098
+            }
1099
+
1100
+            // Show list of existing files
1101
+            if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1102
+            if (empty($url)) $url=$_SERVER["PHP_SELF"];
1103
+
1104
+            print '<!-- html.formfile::list_of_documents -->'."\n";
1105
+            if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1106
+            {
1107
+                print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1108
+                print '<input type="hidden" name="action" value="renamefile">';
1109
+                print '<input type="hidden" name="id" value="'.$object->id.'">';
1110
+                print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
1111
+            }
1112
+
1113
+            print '<div class="div-table-responsive-no-min">';
1114
+            print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
1115
+
1116
+            if (! empty($addfilterfields))
1117
+            {
1118
+                print '<tr class="liste_titre nodrag nodrop">';
1119
+                print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
1120
+                print '<td></td>';
1121
+                print '<td></td>';
1122
+                if (empty($useinecm)) print '<td></td>';
1123
+                print '<td></td>';
1124
+                print '<td></td>';
1125
+                if (! $disablemove) print '<td></td>';
1126
+                print "</tr>\n";
1127
+            }
1128
+
1129
+            print '<tr class="liste_titre nodrag nodrop">';
1130
+            //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
1131
+            print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1132
+            print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1133
+            print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1134
+            if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');					// Preview
1135
+            print_liste_field_titre('');
1136
+            print_liste_field_titre('');
1137
+            if (! $disablemove) print_liste_field_titre('');
1138
+            print "</tr>\n";
1139
+
1140
+            // Get list of files stored into database for same relative directory
1141
+            if ($relativedir)
1142
+            {
1143
+                completeFileArrayWithDatabaseInfo($filearray, $relativedir);
1144
+
1145
+                //var_dump($sortfield.' - '.$sortorder);
1146
+                if ($sortfield && $sortorder)	// If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1147
+                {
1148
+                    $filearray=dol_sort_array($filearray, $sortfield, $sortorder);
1149
+                }
1150
+            }
1151
+
1152
+            $nboffiles=count($filearray);
1153
+            if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1154
+
1155
+            $i=0; $nboflines = 0; $lastrowid=0;
1156
+            foreach($filearray as $key => $file)      // filearray must be only files here
1157
+            {
1158
+                if ($file['name'] != '.'
1159
+                        && $file['name'] != '..'
1160
+                        && ! preg_match('/\.meta$/i',$file['name']))
1161
+                {
1162
+                    if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
1163
+                    $filepath=$relativepath.$file['name'];
1164
+
1165
+                    $editline=0;
1166
+                    $nboflines++;
1167
+                    print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1168
+                    // Do we have entry into database ?
1169
+                    print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
1170
+                    print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'AFTER'.$lastrowid.'POS'.($i+1)).'">';
1171
+
1172
+                    // File name
1173
+                    print '<td class="minwith200">';
1174
+
1175
+                    // Show file name with link to download
1176
+                    //print "XX".$file['name'];	//$file['name'] must be utf8
1177
+                    print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1178
+                    if ($forcedownload) print '&attachment=1';
1179
+                    if (! empty($object->entity)) print '&entity='.$object->entity;
1180
+                    print '&file='.urlencode($filepath);
1181
+                    print '">';
1182
+                    print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
1183
+                    if ($showrelpart == 1) print $relativepath;
1184
+                    //print dol_trunc($file['name'],$maxlength,'middle');
1185
+                    if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
1186
+                    {
1187
+                        print '</a>';
1188
+                        $section_dir=dirname(GETPOST('urlfile','alpha'));
1189
+                        print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1190
+                        print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1191
+                        print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1192
+                        $editline=1;
1193
+                    }
1194
+                    else
1195
+                    {
1196
+                        print dol_trunc($file['name'], 200);
1197
+                        print '</a>';
1198
+                    }
1199
+                    // Preview link
1200
+                    if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
1201
+                    // Public share link
1202
+                    //if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
1203
+
1204
+                    print "</td>\n";
1205
+
1206
+                    // Size
1207
+                    $sizetoshow = dol_print_size($file['size'],1,1);
1208
+                    $sizetoshowbytes = dol_print_size($file['size'],0,1);
1209
+
1210
+                    print '<td align="right" width="80px">';
1211
+                    if ($sizetoshow == $sizetoshowbytes) print $sizetoshow;
1212
+                    else {
1213
+                        print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
1214
+                    }
1215
+                    print '</td>';
1216
+
1217
+                    // Date
1218
+                    print '<td align="center" width="140px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>';	// 140px = width for date with PM format
1219
+
1220
+                    // Preview
1221
+                    if (empty($useinecm))
1222
+                    {
1223
+                        $fileinfo = pathinfo($file['name']);
1224
+                        print '<td align="center">';
1225
+                        if (image_format_supported($file['name']) > 0)
1226
+                        {
1227
+                            $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1228
+                            if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1229
+                            //print $file['path'].'/'.$minifile.'<br>';
1230
+
1231
+                            $urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity));
1232
+                            if (empty($urlforhref)) {
1233
+                                $urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1234
+                                print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
1235
+                            } else {
1236
+                                print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
1237
+                            }
1238
+                            print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
1239
+                            print '</a>';
1240
+                        }
1241
+                        else print '&nbsp;';
1242
+                        print '</td>';
1243
+                    }
1244
+
1245
+                    // Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table)
1246
+                    print '<td align="center">';
1247
+                    if ($relativedir && $filearray[$key]['rowid'] > 0)
1248
+                    {
1249
+                        if ($editline)
1250
+                        {
1251
+                            print $langs->trans("FileSharedViaALink").' ';
1252
+                            print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> ';
1253
+                        }
1254
+                        else
1255
+                        {
1256
+                            if ($file['share'])
1257
+                            {
1258
+                                // Define $urlwithroot
1259
+                                $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
1260
+                                $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
1261
+                                //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
1262
+
1263
+                                //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1264
+                                $forcedownload=0;
1265
+                                $paramlink='';
1266
+                                if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share'];			// Hash for public share
1267
+                                if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
1268
+
1269
+                                $fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
1270
+
1271
+                                print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' ';
1272
+                                print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
1273
+                            }
1274
+                            else
1275
+                            {
1276
+                                //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1277
+                            }
1278
+                        }
1279
+                    }
1280
+                    print '</td>';
1281
+
1282
+                    // Actions buttons
1283
+                    if (! $editline)
1284
+                    {
1285
+                        // Delete or view link
1286
+                        // ($param must start with &)
1287
+                        print '<td class="valignmiddle right actionbuttons"><!-- action on files -->';
1288
+                        if ($useinecm == 1)
1289
+                        {
1290
+                            print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1291
+                        }
1292
+                        if (! $useinecm || $useinecm == 2)
1293
+                        {
1294
+                            $newmodulepart=$modulepart;
1295
+                            if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
1296
+
1297
+                            if (! $disablecrop && image_format_supported($file['name']) > 0)
1298
+                            {
1299
+                                if ($permtoeditline)
1300
+                                {
1301
+                                        // Link to resize
1302
+                                            print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>';
1303
+                                }
1304
+                            }
1305
+
1306
+                            if ($permtoeditline)
1307
+                            {
1308
+                                $paramsectiondir=(in_array($modulepart, array('medias','ecm'))?'&section_dir='.urlencode($relativepath):'');
1309
+                                print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>';
1310
+                            }
1311
+                        }
1312
+                        if ($permonobject)
1313
+                        {
1314
+                            $useajax=1;
1315
+                            if (! empty($conf->dol_use_jmobile)) $useajax=0;
1316
+                            if (empty($conf->use_javascript_ajax)) $useajax=0;
1317
+                            if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
1318
+                            print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1319
+                        }
1320
+                        print "</td>";
1321
+
1322
+                        if (empty($disablemove))
1323
+                        {
1324
+                            if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
1325
+                                print '<td align="center" class="linecolmove tdlineupdown">';
1326
+                                if ($i > 0) {
1327
+                                    print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>';
1328
+                                }
1329
+                                if ($i < $nboffiles-1) {
1330
+                                    print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
1331
+                                }
1332
+                                print '</td>';
1333
+                            }
1334
+                            else {
1335
+                                    print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
1336
+                                    print '</td>';
1337
+                            }
1338
+                        }
1339
+                    }
1340
+                    else
1341
+                    {
1342
+                        print '<td class="right">';
1343
+                        print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">';
1344
+                        print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1345
+                        print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1346
+                        print '</td>';
1347
+                        if (empty($disablemove)) print '<td class="right"></td>';
1348
+                    }
1349
+                    print "</tr>\n";
1350
+
1351
+                    $i++;
1352
+                }
1353
+            }
1354
+            if ($nboffiles == 0)
1355
+            {
1356
+                $colspan=(empty($useinecm)?'6':'6');
1357
+                if (empty($disablemove)) $colspan++;		// 6 columns or 7
1358
+                print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">';
1359
+                if (empty($textifempty)) print $langs->trans("NoFileFound");
1360
+                else print $textifempty;
1361
+                print '</td></tr>';
1362
+            }
1363
+            print "</table>";
1364
+            print '</div>';
1365
+
1366
+            if ($nboflines > 1 && is_object($object)) {
1367
+                if (! empty($conf->use_javascript_ajax) && $permtoeditline) {
1368
+                    $table_element_line = 'ecm_files';
1369
+                    include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1370
+                }
1371
+            }
1372
+
1373
+            print ajax_autoselect('downloadlink');
1374
+
1375
+            if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1376
+            {
1377
+                print '</form>';
1378
+            }
1379
+
1380
+            return $nboffiles;
1381
+        }
1382
+    }
1383 1383
 
1384 1384
 
1385 1385
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1386
-	/**
1387
-	 *	Show list of documents in a directory
1388
-	 *
1389
-	 *  @param	string	$upload_dir         Directory that was scanned
1390
-	 *  @param  array	$filearray          Array of files loaded by dol_dir_list function before calling this function
1391
-	 *  @param  string	$modulepart         Value for modulepart used by download wrapper
1392
-	 *  @param  string	$param              Parameters on sort links
1393
-	 *  @param  int		$forcedownload      Force to open dialog box "Save As" when clicking on file
1394
-	 *  @param  string	$relativepath       Relative path of docs (autodefined if not provided)
1395
-	 *  @param  int		$permtodelete       Permission to delete
1396
-	 *  @param  int		$useinecm           Change output for use in ecm module
1397
-	 *  @param  int		$textifempty        Text to show if filearray is empty
1398
-	 *  @param  int		$maxlength          Maximum length of file name shown
1399
-	 *  @param	string 	$url				Full url to use for click links ('' = autodetect)
1400
-	 *  @param	int		$addfilterfields	Add line with filters
1401
-	 *  @return int                 		<0 if KO, nb of files shown if OK
1402
-	 *  @see list_of_documents
1403
-	 */
1404
-	function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0)
1405
-	{
1386
+    /**
1387
+     *	Show list of documents in a directory
1388
+     *
1389
+     *  @param	string	$upload_dir         Directory that was scanned
1390
+     *  @param  array	$filearray          Array of files loaded by dol_dir_list function before calling this function
1391
+     *  @param  string	$modulepart         Value for modulepart used by download wrapper
1392
+     *  @param  string	$param              Parameters on sort links
1393
+     *  @param  int		$forcedownload      Force to open dialog box "Save As" when clicking on file
1394
+     *  @param  string	$relativepath       Relative path of docs (autodefined if not provided)
1395
+     *  @param  int		$permtodelete       Permission to delete
1396
+     *  @param  int		$useinecm           Change output for use in ecm module
1397
+     *  @param  int		$textifempty        Text to show if filearray is empty
1398
+     *  @param  int		$maxlength          Maximum length of file name shown
1399
+     *  @param	string 	$url				Full url to use for click links ('' = autodetect)
1400
+     *  @param	int		$addfilterfields	Add line with filters
1401
+     *  @return int                 		<0 if KO, nb of files shown if OK
1402
+     *  @see list_of_documents
1403
+     */
1404
+    function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0)
1405
+    {
1406 1406
         // phpcs:enable
1407
-		global $user, $conf, $langs, $form;
1408
-		global $sortfield, $sortorder;
1409
-		global $search_doc_ref;
1410
-
1411
-		dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1412
-
1413
-		// Show list of documents
1414
-		if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
1415
-		if (empty($url)) $url=$_SERVER["PHP_SELF"];
1416
-
1417
-		if (! empty($addfilterfields))
1418
-		{
1419
-			print '<form action="'.$_SERVER['PHP_SELF'].'">';
1420
-			print '<input type="hidden" name="module" value="'.$modulepart.'">';
1421
-		}
1422
-
1423
-		print '<div class="div-table-responsive-no-min">';
1424
-		print '<table width="100%" class="noborder">'."\n";
1425
-
1426
-		if (! empty($addfilterfields))
1427
-		{
1428
-			print '<tr class="liste_titre nodrag nodrop">';
1429
-			print '<td></td>';
1430
-			print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1431
-			print '<td></td>';
1432
-			print '<td></td>';
1433
-			// Action column
1434
-			print '<td class="liste_titre" align="middle">';
1435
-			$searchpicto=$form->showFilterButtons();
1436
-			print $searchpicto;
1437
-			print '</td>';
1438
-			print "</tr>\n";
1439
-		}
1440
-
1441
-		print '<tr class="liste_titre">';
1442
-		$sortref="fullname";
1443
-		if ($modulepart == 'invoice_supplier') $sortref='level1name';
1444
-		print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
1445
-		print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1446
-		print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1447
-		print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1448
-		print_liste_field_titre('','','');
1449
-		print '</tr>'."\n";
1450
-
1451
-		// To show ref or specific information according to view to show (defined by $module)
1452
-		if ($modulepart == 'company')
1453
-		{
1454
-			include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1455
-			$object_instance=new Societe($this->db);
1456
-		}
1457
-		else if ($modulepart == 'invoice')
1458
-		{
1459
-			include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1460
-			$object_instance=new Facture($this->db);
1461
-		}
1462
-		else if ($modulepart == 'invoice_supplier')
1463
-		{
1464
-			include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1465
-			$object_instance=new FactureFournisseur($this->db);
1466
-		}
1467
-		else if ($modulepart == 'propal')
1468
-		{
1469
-			include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1470
-			$object_instance=new Propal($this->db);
1471
-		}
1472
-		else if ($modulepart == 'supplier_proposal')
1473
-		{
1474
-			include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1475
-			$object_instance=new SupplierProposal($this->db);
1476
-		}
1477
-		else if ($modulepart == 'order')
1478
-		{
1479
-			include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1480
-			$object_instance=new Commande($this->db);
1481
-		}
1482
-		else if ($modulepart == 'order_supplier')
1483
-		{
1484
-			include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1485
-			$object_instance=new CommandeFournisseur($this->db);
1486
-		}
1487
-		else if ($modulepart == 'contract')
1488
-		{
1489
-			include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1490
-			$object_instance=new Contrat($this->db);
1491
-		}
1492
-		else if ($modulepart == 'product')
1493
-		{
1494
-			include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1495
-			$object_instance=new Product($this->db);
1496
-		}
1497
-		else if ($modulepart == 'tax')
1498
-		{
1499
-			include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1500
-			$object_instance=new ChargeSociales($this->db);
1501
-		}
1502
-		else if ($modulepart == 'project')
1503
-		{
1504
-			include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1505
-			$object_instance=new Project($this->db);
1506
-		}
1507
-		else if ($modulepart == 'fichinter')
1508
-		{
1509
-			include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1510
-			$object_instance=new Fichinter($this->db);
1511
-		}
1512
-		else if ($modulepart == 'user')
1513
-		{
1514
-			include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1515
-			$object_instance=new User($this->db);
1516
-		}
1517
-		else if ($modulepart == 'expensereport')
1518
-		{
1519
-			include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1520
-			$object_instance=new ExpenseReport($this->db);
1521
-		}
1522
-		else if ($modulepart == 'holiday')
1523
-		{
1524
-			include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1525
-			$object_instance=new Holiday($this->db);
1526
-		}
1527
-
1528
-		foreach($filearray as $key => $file)
1529
-		{
1530
-			if (!is_dir($file['name'])
1531
-			&& $file['name'] != '.'
1532
-			&& $file['name'] != '..'
1533
-			&& $file['name'] != 'CVS'
1534
-			&& ! preg_match('/\.meta$/i',$file['name']))
1535
-			{
1536
-				// Define relative path used to store the file
1537
-				$relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
1538
-
1539
-				//var_dump($file);
1540
-				$id=0; $ref=''; $label='';
1541
-
1542
-				// To show ref or specific information according to view to show (defined by $module)
1543
-				if ($modulepart == 'company')           { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1544
-				if ($modulepart == 'invoice')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1545
-				if ($modulepart == 'invoice_supplier')  { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } }	// $ref may be also id with old supplier invoices
1546
-				if ($modulepart == 'propal')            { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1547
-				if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1548
-				if ($modulepart == 'order')             { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1549
-				if ($modulepart == 'order_supplier')    { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1550
-				if ($modulepart == 'contract')          { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1551
-				if ($modulepart == 'product')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1552
-				if ($modulepart == 'tax')               { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1553
-				if ($modulepart == 'project')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1554
-				if ($modulepart == 'fichinter')         { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1555
-				if ($modulepart == 'user')              { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1556
-				if ($modulepart == 'expensereport')     { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1557
-				if ($modulepart == 'holiday')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1558
-
1559
-				if (! $id && ! $ref) continue;
1560
-				$found=0;
1561
-				if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1562
-				{
1563
-					$found=1;
1564
-				}
1565
-				else
1566
-				{
1567
-					//print 'Fetch '.$id." - ".$ref.'<br>';
1568
-
1569
-					if ($id) {
1570
-						$result = $object_instance->fetch($id);
1571
-					} else {
1572
-						//fetchOneLike looks for objects with wildcards in its reference.
1573
-						//It is useful for those masks who get underscores instead of their actual symbols
1574
-						//fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
1575
-						//that's why we look only look fetchOneLike when fetch returns 0
1576
-						if (!$result = $object_instance->fetch('', $ref)) {
1577
-							$result = $object_instance->fetchOneLike($ref);
1578
-						}
1579
-					}
1580
-
1581
-					if ($result > 0) {  // Save object into a cache
1582
-						$found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
1583
-					}
1584
-					if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
1585
-				}
1586
-
1587
-				if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue;    // We do not show orphelins files
1588
-
1589
-				print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
1590
-				print '<tr class="oddeven">';
1591
-				print '<td>';
1592
-				if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1593
-				else print $langs->trans("ObjectDeleted",($id?$id:$ref));
1594
-
1595
-				//$modulesubdir=dol_sanitizeFileName($ref);
1596
-				$modulesubdir=dirname($relativefile);
1597
-
1598
-				//$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
1599
-				$filedir=$file['path'];
1600
-				//$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1601
-				//print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
1602
-
1603
-				print '</td>';
1604
-
1605
-				// File
1606
-				print '<td>';
1607
-				//print "XX".$file['name']; //$file['name'] must be utf8
1608
-				print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1609
-				if ($forcedownload) print '&attachment=1';
1610
-				print '&file='.urlencode($relativefile).'">';
1611
-				print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')');
1612
-				print dol_trunc($file['name'],$maxlength,'middle');
1613
-				print '</a>';
1614
-
1615
-				//print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
1616
-				print $this->showPreview($file, $modulepart, $file['relativename']);
1617
-
1618
-				print "</td>\n";
1619
-				print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
1620
-				print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
1621
-				print '<td align="right">';
1622
-				//if (! empty($useinecm))  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1623
-				//if ($forcedownload) print '&attachment=1';
1624
-				//print '&file='.urlencode($relativefile).'">';
1625
-				//print img_view().'</a> &nbsp; ';
1626
-				//if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
1627
-				//else print '&nbsp;';
1628
-				print "</td></tr>\n";
1629
-			}
1630
-		}
1631
-
1632
-		if (count($filearray) == 0)
1633
-		{
1634
-			print '<tr class="oddeven"><td colspan="5">';
1635
-			if (empty($textifempty)) print $langs->trans("NoFileFound");
1636
-			else print $textifempty;
1637
-			print '</td></tr>';
1638
-		}
1639
-		print "</table>";
1640
-		print '</div>';
1641
-
1642
-		if (! empty($addfilterfields)) print '</form>';
1643
-		// Fin de zone
1644
-	}
1645
-
1646
-	/**
1647
-	 *    Show form to upload a new file with jquery fileupload.
1648
-	 *    This form use the fileupload.php file.
1649
-	 *
1650
-	 *    @param	Object	$object		Object to use
1651
-	 *    @return	void
1652
-	 */
1653
-	private function _formAjaxFileUpload($object)
1654
-	{
1655
-		global $langs, $conf;
1656
-
1657
-		// PHP post_max_size
1658
-		$post_max_size				= ini_get('post_max_size');
1659
-		$mul_post_max_size			= substr($post_max_size, -1);
1660
-		$mul_post_max_size			= ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1)));
1661
-		$post_max_size				= $mul_post_max_size * (int) $post_max_size;
1662
-		// PHP upload_max_filesize
1663
-		$upload_max_filesize		= ini_get('upload_max_filesize');
1664
-		$mul_upload_max_filesize	= substr($upload_max_filesize, -1);
1665
-		$mul_upload_max_filesize	= ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
1666
-		$upload_max_filesize		= $mul_upload_max_filesize * (int) $upload_max_filesize;
1667
-		// Max file size
1668
-		$max_file_size 				= (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
1669
-
1670
-		// Include main
1671
-		include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
1672
-
1673
-		// Include template
1674
-		include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
1675
-	}
1676
-
1677
-	/**
1678
-	 * Show array with linked files
1679
-	 *
1680
-	 * @param 	Object		$object			Object
1681
-	 * @param 	int			$permtodelete	Deletion is allowed
1682
-	 * @param 	string		$action			Action
1683
-	 * @param 	string		$selected		???
1684
-	 * @param	string		$param			More param to add into URL
1685
-	 * @return 	int							Number of links
1686
-	 */
1687
-	public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
1688
-	{
1689
-		global $user, $conf, $langs, $user;
1690
-		global $sortfield, $sortorder;
1691
-
1692
-		$langs->load("link");
1693
-
1694
-		require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1695
-		$link = new Link($this->db);
1696
-		$links = array();
1697
-		if ($sortfield == "name") {
1698
-			$sortfield = "label";
1699
-		} elseif ($sortfield == "date") {
1700
-			$sortfield = "datea";
1701
-		} else {
1702
-			$sortfield = null;
1703
-		}
1704
-		$res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
1705
-		$param .= (isset($object->id)?'&id=' . $object->id : '');
1706
-
1707
-		// Show list of associated links
1708
-		print load_fiche_titre($langs->trans("LinkedFiles"));
1709
-
1710
-		print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">';
1711
-
1712
-		print '<table width="100%" class="liste">';
1713
-		print '<tr class="liste_titre">';
1714
-		print_liste_field_titre(
1715
-			$langs->trans("Links"),
1716
-			$_SERVER['PHP_SELF'],
1717
-			"name",
1718
-			"",
1719
-			$param,
1720
-			'align="left"',
1721
-			$sortfield,
1722
-			$sortorder
1723
-		);
1724
-		print_liste_field_titre(
1725
-			"",
1726
-			"",
1727
-			"",
1728
-			"",
1729
-			"",
1730
-			'align="right"'
1731
-		);
1732
-		print_liste_field_titre(
1733
-			$langs->trans("Date"),
1734
-			$_SERVER['PHP_SELF'],
1735
-			"date",
1736
-			"",
1737
-			$param,
1738
-			'align="center"',
1739
-			$sortfield,
1740
-			$sortorder
1741
-		);
1742
-		print_liste_field_titre(
1743
-			'',
1744
-			$_SERVER['PHP_SELF'],
1745
-			"",
1746
-			"",
1747
-			$param,
1748
-			'align="center"'
1749
-		);
1750
-		print_liste_field_titre('','','');
1751
-		print '</tr>';
1752
-		$nboflinks = count($links);
1753
-		if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1754
-
1755
-		foreach ($links as $link)
1756
-		{
1757
-			print '<tr class="oddeven">';
1758
-			//edit mode
1759
-			if ($action == 'update' && $selected === $link->id)
1760
-			{
1761
-				print '<td>';
1762
-				print '<input type="hidden" name="id" value="' . $object->id . '">';
1763
-				print '<input type="hidden" name="linkid" value="' . $link->id . '">';
1764
-				print '<input type="hidden" name="action" value="confirm_updateline">';
1765
-				print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">';
1766
-				print '</td>';
1767
-				print '<td>';
1768
-				print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">';
1769
-				print '</td>';
1770
-				print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
1771
-				print '<td align="right"></td>';
1772
-				print '<td align="right">';
1773
-				print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
1774
-				print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
1775
-				print '</td>';
1776
-			}
1777
-			else
1778
-			{
1779
-				print '<td>';
1780
-				print img_picto('', 'object_globe').' ';
1781
-				print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
1782
-				print $link->label;
1783
-				print '</a>';
1784
-				print '</td>'."\n";
1785
-				print '<td align="right"></td>';
1786
-				print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>';
1787
-				print '<td align="center"></td>';
1788
-				print '<td align="right">';
1789
-				print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>';	// id= is included into $param
1790
-				if ($permtodelete) {
1791
-					print ' &nbsp; <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>';	// id= is included into $param
1792
-				} else {
1793
-					print '&nbsp;';
1794
-				}
1795
-				print '</td>';
1796
-			}
1797
-			print "</tr>\n";
1798
-		}
1799
-		if ($nboflinks == 0)
1800
-		{
1801
-			print '<tr class="oddeven"><td colspan="5" class="opacitymedium">';
1802
-			print $langs->trans("NoLinkFound");
1803
-			print '</td></tr>';
1804
-		}
1805
-		print "</table>";
1806
-
1807
-		print '</form>';
1808
-
1809
-		return $nboflinks;
1810
-	}
1811
-
1812
-
1813
-	/**
1814
-	 * Show detail icon with link for preview
1815
-	 *
1816
-	 * @param   array     $file           Array with data of file. Example: array('name'=>...)
1817
-	 * @param   string    $modulepart     propal, facture, facture_fourn, ...
1818
-	 * @param   string    $relativepath   Relative path of docs
1819
-	 * @param   string    $ruleforpicto   Rule for picto: 0=Use the generic preview picto, 1=Use the picto of mime type of file)
1820
-	 * @param	string	  $param		  More param on http links
1821
-	 * @return  string    $out            Output string with HTML
1822
-	 */
1823
-	public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
1824
-	{
1825
-		global $langs, $conf;
1826
-
1827
-		$out='';
1828
-		if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax))
1829
-		{
1830
-			$urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param);      // Return if a file is qualified for preview.
1831
-			if (count($urladvancedpreview))
1832
-			{
1833
-				$out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>';
1834
-				//$out.= '<a class="pictopreview">';
1835
-				if (empty($ruleforpicto))
1836
-				{
1837
-					//$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
1838
-					$out.='<span class="fa fa-search-plus" style="color: gray"></span>';
1839
-				}
1840
-				else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1841
-				$out.= '</a>';
1842
-			}
1843
-		}
1844
-		return $out;
1845
-	}
1407
+        global $user, $conf, $langs, $form;
1408
+        global $sortfield, $sortorder;
1409
+        global $search_doc_ref;
1410
+
1411
+        dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1412
+
1413
+        // Show list of documents
1414
+        if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
1415
+        if (empty($url)) $url=$_SERVER["PHP_SELF"];
1416
+
1417
+        if (! empty($addfilterfields))
1418
+        {
1419
+            print '<form action="'.$_SERVER['PHP_SELF'].'">';
1420
+            print '<input type="hidden" name="module" value="'.$modulepart.'">';
1421
+        }
1422
+
1423
+        print '<div class="div-table-responsive-no-min">';
1424
+        print '<table width="100%" class="noborder">'."\n";
1425
+
1426
+        if (! empty($addfilterfields))
1427
+        {
1428
+            print '<tr class="liste_titre nodrag nodrop">';
1429
+            print '<td></td>';
1430
+            print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1431
+            print '<td></td>';
1432
+            print '<td></td>';
1433
+            // Action column
1434
+            print '<td class="liste_titre" align="middle">';
1435
+            $searchpicto=$form->showFilterButtons();
1436
+            print $searchpicto;
1437
+            print '</td>';
1438
+            print "</tr>\n";
1439
+        }
1440
+
1441
+        print '<tr class="liste_titre">';
1442
+        $sortref="fullname";
1443
+        if ($modulepart == 'invoice_supplier') $sortref='level1name';
1444
+        print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
1445
+        print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1446
+        print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1447
+        print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1448
+        print_liste_field_titre('','','');
1449
+        print '</tr>'."\n";
1450
+
1451
+        // To show ref or specific information according to view to show (defined by $module)
1452
+        if ($modulepart == 'company')
1453
+        {
1454
+            include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1455
+            $object_instance=new Societe($this->db);
1456
+        }
1457
+        else if ($modulepart == 'invoice')
1458
+        {
1459
+            include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1460
+            $object_instance=new Facture($this->db);
1461
+        }
1462
+        else if ($modulepart == 'invoice_supplier')
1463
+        {
1464
+            include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1465
+            $object_instance=new FactureFournisseur($this->db);
1466
+        }
1467
+        else if ($modulepart == 'propal')
1468
+        {
1469
+            include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1470
+            $object_instance=new Propal($this->db);
1471
+        }
1472
+        else if ($modulepart == 'supplier_proposal')
1473
+        {
1474
+            include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1475
+            $object_instance=new SupplierProposal($this->db);
1476
+        }
1477
+        else if ($modulepart == 'order')
1478
+        {
1479
+            include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1480
+            $object_instance=new Commande($this->db);
1481
+        }
1482
+        else if ($modulepart == 'order_supplier')
1483
+        {
1484
+            include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1485
+            $object_instance=new CommandeFournisseur($this->db);
1486
+        }
1487
+        else if ($modulepart == 'contract')
1488
+        {
1489
+            include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1490
+            $object_instance=new Contrat($this->db);
1491
+        }
1492
+        else if ($modulepart == 'product')
1493
+        {
1494
+            include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1495
+            $object_instance=new Product($this->db);
1496
+        }
1497
+        else if ($modulepart == 'tax')
1498
+        {
1499
+            include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1500
+            $object_instance=new ChargeSociales($this->db);
1501
+        }
1502
+        else if ($modulepart == 'project')
1503
+        {
1504
+            include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1505
+            $object_instance=new Project($this->db);
1506
+        }
1507
+        else if ($modulepart == 'fichinter')
1508
+        {
1509
+            include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1510
+            $object_instance=new Fichinter($this->db);
1511
+        }
1512
+        else if ($modulepart == 'user')
1513
+        {
1514
+            include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1515
+            $object_instance=new User($this->db);
1516
+        }
1517
+        else if ($modulepart == 'expensereport')
1518
+        {
1519
+            include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1520
+            $object_instance=new ExpenseReport($this->db);
1521
+        }
1522
+        else if ($modulepart == 'holiday')
1523
+        {
1524
+            include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1525
+            $object_instance=new Holiday($this->db);
1526
+        }
1527
+
1528
+        foreach($filearray as $key => $file)
1529
+        {
1530
+            if (!is_dir($file['name'])
1531
+            && $file['name'] != '.'
1532
+            && $file['name'] != '..'
1533
+            && $file['name'] != 'CVS'
1534
+            && ! preg_match('/\.meta$/i',$file['name']))
1535
+            {
1536
+                // Define relative path used to store the file
1537
+                $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
1538
+
1539
+                //var_dump($file);
1540
+                $id=0; $ref=''; $label='';
1541
+
1542
+                // To show ref or specific information according to view to show (defined by $module)
1543
+                if ($modulepart == 'company')           { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1544
+                if ($modulepart == 'invoice')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1545
+                if ($modulepart == 'invoice_supplier')  { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } }	// $ref may be also id with old supplier invoices
1546
+                if ($modulepart == 'propal')            { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1547
+                if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1548
+                if ($modulepart == 'order')             { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1549
+                if ($modulepart == 'order_supplier')    { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1550
+                if ($modulepart == 'contract')          { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1551
+                if ($modulepart == 'product')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1552
+                if ($modulepart == 'tax')               { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1553
+                if ($modulepart == 'project')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1554
+                if ($modulepart == 'fichinter')         { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1555
+                if ($modulepart == 'user')              { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1556
+                if ($modulepart == 'expensereport')     { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1557
+                if ($modulepart == 'holiday')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1558
+
1559
+                if (! $id && ! $ref) continue;
1560
+                $found=0;
1561
+                if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1562
+                {
1563
+                    $found=1;
1564
+                }
1565
+                else
1566
+                {
1567
+                    //print 'Fetch '.$id." - ".$ref.'<br>';
1568
+
1569
+                    if ($id) {
1570
+                        $result = $object_instance->fetch($id);
1571
+                    } else {
1572
+                        //fetchOneLike looks for objects with wildcards in its reference.
1573
+                        //It is useful for those masks who get underscores instead of their actual symbols
1574
+                        //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
1575
+                        //that's why we look only look fetchOneLike when fetch returns 0
1576
+                        if (!$result = $object_instance->fetch('', $ref)) {
1577
+                            $result = $object_instance->fetchOneLike($ref);
1578
+                        }
1579
+                    }
1580
+
1581
+                    if ($result > 0) {  // Save object into a cache
1582
+                        $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
1583
+                    }
1584
+                    if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
1585
+                }
1586
+
1587
+                if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue;    // We do not show orphelins files
1588
+
1589
+                print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
1590
+                print '<tr class="oddeven">';
1591
+                print '<td>';
1592
+                if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1593
+                else print $langs->trans("ObjectDeleted",($id?$id:$ref));
1594
+
1595
+                //$modulesubdir=dol_sanitizeFileName($ref);
1596
+                $modulesubdir=dirname($relativefile);
1597
+
1598
+                //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
1599
+                $filedir=$file['path'];
1600
+                //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1601
+                //print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
1602
+
1603
+                print '</td>';
1604
+
1605
+                // File
1606
+                print '<td>';
1607
+                //print "XX".$file['name']; //$file['name'] must be utf8
1608
+                print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1609
+                if ($forcedownload) print '&attachment=1';
1610
+                print '&file='.urlencode($relativefile).'">';
1611
+                print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')');
1612
+                print dol_trunc($file['name'],$maxlength,'middle');
1613
+                print '</a>';
1614
+
1615
+                //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
1616
+                print $this->showPreview($file, $modulepart, $file['relativename']);
1617
+
1618
+                print "</td>\n";
1619
+                print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
1620
+                print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
1621
+                print '<td align="right">';
1622
+                //if (! empty($useinecm))  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1623
+                //if ($forcedownload) print '&attachment=1';
1624
+                //print '&file='.urlencode($relativefile).'">';
1625
+                //print img_view().'</a> &nbsp; ';
1626
+                //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
1627
+                //else print '&nbsp;';
1628
+                print "</td></tr>\n";
1629
+            }
1630
+        }
1631
+
1632
+        if (count($filearray) == 0)
1633
+        {
1634
+            print '<tr class="oddeven"><td colspan="5">';
1635
+            if (empty($textifempty)) print $langs->trans("NoFileFound");
1636
+            else print $textifempty;
1637
+            print '</td></tr>';
1638
+        }
1639
+        print "</table>";
1640
+        print '</div>';
1641
+
1642
+        if (! empty($addfilterfields)) print '</form>';
1643
+        // Fin de zone
1644
+    }
1645
+
1646
+    /**
1647
+     *    Show form to upload a new file with jquery fileupload.
1648
+     *    This form use the fileupload.php file.
1649
+     *
1650
+     *    @param	Object	$object		Object to use
1651
+     *    @return	void
1652
+     */
1653
+    private function _formAjaxFileUpload($object)
1654
+    {
1655
+        global $langs, $conf;
1656
+
1657
+        // PHP post_max_size
1658
+        $post_max_size				= ini_get('post_max_size');
1659
+        $mul_post_max_size			= substr($post_max_size, -1);
1660
+        $mul_post_max_size			= ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1)));
1661
+        $post_max_size				= $mul_post_max_size * (int) $post_max_size;
1662
+        // PHP upload_max_filesize
1663
+        $upload_max_filesize		= ini_get('upload_max_filesize');
1664
+        $mul_upload_max_filesize	= substr($upload_max_filesize, -1);
1665
+        $mul_upload_max_filesize	= ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
1666
+        $upload_max_filesize		= $mul_upload_max_filesize * (int) $upload_max_filesize;
1667
+        // Max file size
1668
+        $max_file_size 				= (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
1669
+
1670
+        // Include main
1671
+        include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
1672
+
1673
+        // Include template
1674
+        include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
1675
+    }
1676
+
1677
+    /**
1678
+     * Show array with linked files
1679
+     *
1680
+     * @param 	Object		$object			Object
1681
+     * @param 	int			$permtodelete	Deletion is allowed
1682
+     * @param 	string		$action			Action
1683
+     * @param 	string		$selected		???
1684
+     * @param	string		$param			More param to add into URL
1685
+     * @return 	int							Number of links
1686
+     */
1687
+    public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
1688
+    {
1689
+        global $user, $conf, $langs, $user;
1690
+        global $sortfield, $sortorder;
1691
+
1692
+        $langs->load("link");
1693
+
1694
+        require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1695
+        $link = new Link($this->db);
1696
+        $links = array();
1697
+        if ($sortfield == "name") {
1698
+            $sortfield = "label";
1699
+        } elseif ($sortfield == "date") {
1700
+            $sortfield = "datea";
1701
+        } else {
1702
+            $sortfield = null;
1703
+        }
1704
+        $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
1705
+        $param .= (isset($object->id)?'&id=' . $object->id : '');
1706
+
1707
+        // Show list of associated links
1708
+        print load_fiche_titre($langs->trans("LinkedFiles"));
1709
+
1710
+        print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">';
1711
+
1712
+        print '<table width="100%" class="liste">';
1713
+        print '<tr class="liste_titre">';
1714
+        print_liste_field_titre(
1715
+            $langs->trans("Links"),
1716
+            $_SERVER['PHP_SELF'],
1717
+            "name",
1718
+            "",
1719
+            $param,
1720
+            'align="left"',
1721
+            $sortfield,
1722
+            $sortorder
1723
+        );
1724
+        print_liste_field_titre(
1725
+            "",
1726
+            "",
1727
+            "",
1728
+            "",
1729
+            "",
1730
+            'align="right"'
1731
+        );
1732
+        print_liste_field_titre(
1733
+            $langs->trans("Date"),
1734
+            $_SERVER['PHP_SELF'],
1735
+            "date",
1736
+            "",
1737
+            $param,
1738
+            'align="center"',
1739
+            $sortfield,
1740
+            $sortorder
1741
+        );
1742
+        print_liste_field_titre(
1743
+            '',
1744
+            $_SERVER['PHP_SELF'],
1745
+            "",
1746
+            "",
1747
+            $param,
1748
+            'align="center"'
1749
+        );
1750
+        print_liste_field_titre('','','');
1751
+        print '</tr>';
1752
+        $nboflinks = count($links);
1753
+        if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1754
+
1755
+        foreach ($links as $link)
1756
+        {
1757
+            print '<tr class="oddeven">';
1758
+            //edit mode
1759
+            if ($action == 'update' && $selected === $link->id)
1760
+            {
1761
+                print '<td>';
1762
+                print '<input type="hidden" name="id" value="' . $object->id . '">';
1763
+                print '<input type="hidden" name="linkid" value="' . $link->id . '">';
1764
+                print '<input type="hidden" name="action" value="confirm_updateline">';
1765
+                print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">';
1766
+                print '</td>';
1767
+                print '<td>';
1768
+                print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">';
1769
+                print '</td>';
1770
+                print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
1771
+                print '<td align="right"></td>';
1772
+                print '<td align="right">';
1773
+                print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
1774
+                print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
1775
+                print '</td>';
1776
+            }
1777
+            else
1778
+            {
1779
+                print '<td>';
1780
+                print img_picto('', 'object_globe').' ';
1781
+                print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
1782
+                print $link->label;
1783
+                print '</a>';
1784
+                print '</td>'."\n";
1785
+                print '<td align="right"></td>';
1786
+                print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>';
1787
+                print '<td align="center"></td>';
1788
+                print '<td align="right">';
1789
+                print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>';	// id= is included into $param
1790
+                if ($permtodelete) {
1791
+                    print ' &nbsp; <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>';	// id= is included into $param
1792
+                } else {
1793
+                    print '&nbsp;';
1794
+                }
1795
+                print '</td>';
1796
+            }
1797
+            print "</tr>\n";
1798
+        }
1799
+        if ($nboflinks == 0)
1800
+        {
1801
+            print '<tr class="oddeven"><td colspan="5" class="opacitymedium">';
1802
+            print $langs->trans("NoLinkFound");
1803
+            print '</td></tr>';
1804
+        }
1805
+        print "</table>";
1806
+
1807
+        print '</form>';
1808
+
1809
+        return $nboflinks;
1810
+    }
1811
+
1812
+
1813
+    /**
1814
+     * Show detail icon with link for preview
1815
+     *
1816
+     * @param   array     $file           Array with data of file. Example: array('name'=>...)
1817
+     * @param   string    $modulepart     propal, facture, facture_fourn, ...
1818
+     * @param   string    $relativepath   Relative path of docs
1819
+     * @param   string    $ruleforpicto   Rule for picto: 0=Use the generic preview picto, 1=Use the picto of mime type of file)
1820
+     * @param	string	  $param		  More param on http links
1821
+     * @return  string    $out            Output string with HTML
1822
+     */
1823
+    public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
1824
+    {
1825
+        global $langs, $conf;
1826
+
1827
+        $out='';
1828
+        if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax))
1829
+        {
1830
+            $urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param);      // Return if a file is qualified for preview.
1831
+            if (count($urladvancedpreview))
1832
+            {
1833
+                $out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>';
1834
+                //$out.= '<a class="pictopreview">';
1835
+                if (empty($ruleforpicto))
1836
+                {
1837
+                    //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
1838
+                    $out.='<span class="fa fa-search-plus" style="color: gray"></span>';
1839
+                }
1840
+                else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1841
+                $out.= '</a>';
1842
+            }
1843
+        }
1844
+        return $out;
1845
+    }
1846 1846
 }
Please login to merge, or discard this patch.
Spacing   +444 added lines, -444 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public $error;
43 43
 
44 44
 	public $numoffiles;
45
-	public $infofiles;			// Used to return informations by function getDocumentsLink
45
+	public $infofiles; // Used to return informations by function getDocumentsLink
46 46
 
47 47
 
48 48
 	/**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	function __construct($db)
54 54
 	{
55 55
 		$this->db = $db;
56
-		$this->numoffiles=0;
56
+		$this->numoffiles = 0;
57 57
 	}
58 58
 
59 59
 
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
 	 *	@param	string		$sectiondir		If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be)
78 78
 	 * 	@return	int							<0 if KO, >0 if OK
79 79
 	 */
80
-	function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='')
80
+	function form_attach_new_file($url, $title = '', $addcancel = 0, $sectionid = 0, $perm = 1, $size = 50, $object = '', $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', $sectiondir = '')
81 81
 	{
82 82
         // phpcs:enable
83
-		global $conf,$langs, $hookmanager;
83
+		global $conf, $langs, $hookmanager;
84 84
 		$hookmanager->initHooks(array('formfile'));
85 85
 
86 86
 
87
-		if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0;
87
+		if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax = 0;
88 88
 
89
-		if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
89
+		if ((!empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax == 2))
90 90
 		{
91 91
 			// TODO: Check this works with 2 forms on same page
92 92
 			// TODO: Check this works with GED module, otherwise, force useajax to 0
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
 				return 1;
102 102
 			}
103 103
 
104
-			$maxlength=$size;
104
+			$maxlength = $size;
105 105
 
106 106
 			$out = "\n\n<!-- Start form attach new file -->\n";
107 107
 
108
-			if (empty($title)) $title=$langs->trans("AttachANewFile");
109
-			if ($title != 'none') $out.=load_fiche_titre($title, null, null);
108
+			if (empty($title)) $title = $langs->trans("AttachANewFile");
109
+			if ($title != 'none') $out .= load_fiche_titre($title, null, null);
110 110
 
111 111
 			$out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
112 112
 			$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
@@ -116,34 +116,34 @@  discard block
 block discarded – undo
116 116
 			$out .= '<table width="100%" class="nobordernopadding">';
117 117
 			$out .= '<tr>';
118 118
 
119
-			if (! empty($options)) $out .= '<td>'.$options.'</td>';
119
+			if (!empty($options)) $out .= '<td>'.$options.'</td>';
120 120
 
121 121
 			$out .= '<td class="valignmiddle nowrap">';
122 122
 
123
-			$max=$conf->global->MAIN_UPLOAD_DOC;		// En Kb
124
-			$maxphp=@ini_get('upload_max_filesize');	// En inconnu
125
-			if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1;
126
-			if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
127
-			if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024;
128
-			if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024;
123
+			$max = $conf->global->MAIN_UPLOAD_DOC; // En Kb
124
+			$maxphp = @ini_get('upload_max_filesize'); // En inconnu
125
+			if (preg_match('/k$/i', $maxphp)) $maxphp = $maxphp * 1;
126
+			if (preg_match('/m$/i', $maxphp)) $maxphp = $maxphp * 1024;
127
+			if (preg_match('/g$/i', $maxphp)) $maxphp = $maxphp * 1024 * 1024;
128
+			if (preg_match('/t$/i', $maxphp)) $maxphp = $maxphp * 1024 * 1024 * 1024;
129 129
 			// Now $max and $maxphp are in Kb
130 130
 			$maxmin = $max;
131
-			if ($maxphp > 0) $maxmin=min($max,$maxphp);
131
+			if ($maxphp > 0) $maxmin = min($max, $maxphp);
132 132
 
133 133
 			if ($maxmin > 0)
134 134
 			{
135 135
 				// MAX_FILE_SIZE doit précéder le champ input de type file
136
-				$out .= '<input type="hidden" name="max_file_size" value="'.($maxmin*1024).'">';
136
+				$out .= '<input type="hidden" name="max_file_size" value="'.($maxmin * 1024).'">';
137 137
 			}
138 138
 
139 139
 			$out .= '<input class="flat minwidth400" type="file"';
140
-			$out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple');
141
-			$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
142
-			$out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""');
140
+			$out .= ((!empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic') ? ' name="userfile"' : ' name="userfile[]" multiple');
141
+			$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
142
+			$out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
143 143
 			$out .= '>';
144 144
 			$out .= ' ';
145 145
 			$out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
146
-			$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
146
+			$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
147 147
 			$out .= '>';
148 148
 
149 149
 			if ($addcancel)
@@ -152,13 +152,13 @@  discard block
 block discarded – undo
152 152
 				$out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
153 153
 			}
154 154
 
155
-			if (! empty($conf->global->MAIN_UPLOAD_DOC))
155
+			if (!empty($conf->global->MAIN_UPLOAD_DOC))
156 156
 			{
157 157
 				if ($perm)
158 158
 				{
159 159
 					$langs->load('other');
160 160
 					$out .= ' ';
161
-					$out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
161
+					$out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup", $max, $maxphp), 1);
162 162
 				}
163 163
 			}
164 164
 			else
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 			if ($savingdocmask)
171 171
 			{
172 172
 				$out .= '<tr>';
173
-   				if (! empty($options)) $out .= '<td>'.$options.'</td>';
173
+   				if (!empty($options)) $out .= '<td>'.$options.'</td>';
174 174
 				$out .= '<td valign="middle" class="nowrap">';
175
-				$out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
175
+				$out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
176 176
 				$out .= '</td>';
177 177
 				$out .= '</tr>';
178 178
 			}
@@ -197,18 +197,18 @@  discard block
 block discarded – undo
197 197
 
198 198
 				$out .= '<div class="valignmiddle" >';
199 199
 				$out .= '<div class="inline-block" style="padding-right: 10px;">';
200
-				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
200
+				if (!empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink").':</label> ';
201 201
 				$out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
202 202
 				$out .= '</div>';
203 203
 				$out .= '<div class="inline-block" style="padding-right: 10px;">';
204
-				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
204
+				if (!empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label").':</label> ';
205 205
 				$out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
206
-				$out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
207
-				$out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
206
+				$out .= '<input type="hidden" name="objecttype" value="'.$object->element.'">';
207
+				$out .= '<input type="hidden" name="objectid" value="'.$object->id.'">';
208 208
 				$out .= '</div>';
209 209
 				$out .= '<div class="inline-block" style="padding-right: 10px;">';
210 210
 				$out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
211
-				$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
211
+				$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
212 212
 				$out .= '>';
213 213
 				$out .= '</div>';
214 214
 				$out .= '</div>';
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 				$out .= "\n<!-- End form link new url -->\n";
219 219
 			}
220 220
 
221
-			$parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''), 'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
222
-			$res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
221
+			$parameters = array('socid'=>(isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id'=>(isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'url'=>$url, 'perm'=>$perm);
222
+			$res = $hookmanager->executeHooks('formattachOptions', $parameters, $object);
223 223
 			if (empty($res))
224 224
 			{
225 225
 				print '<div class="attacharea attacharea'.$htmlname.'">';
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 	 * 		@return		int										<0 if KO, number of shown files if OK
256 256
 	 *      @deprecated                                         Use print xxx->showdocuments() instead.
257 257
 	 */
258
-	function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='')
258
+	function show_documents($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '')
259 259
 	{
260 260
         // phpcs:enable
261
-		$this->numoffiles=0;
262
-		print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang);
261
+		$this->numoffiles = 0;
262
+		print $this->showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed, $modelselected, $allowgenifempty, $forcenomultilang, $iconPDF, $notused, $noform, $param, $title, $buttonlabel, $codelang);
263 263
 		return $this->numoffiles;
264 264
 	}
265 265
 
@@ -288,58 +288,58 @@  discard block
 block discarded – undo
288 288
 	 *      @param		int					$hideifempty		Hide section of generated files if there is no file
289 289
 	 * 		@return		string              					Output string with HTML array of documents (might be empty string)
290 290
 	 */
291
-	function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null,$hideifempty=0)
291
+	function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '', $morepicto = '', $object = null, $hideifempty = 0)
292 292
 	{
293 293
 		// Deprecation warning
294
-		if (! empty($iconPDF)) {
295
-			dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING);
294
+		if (!empty($iconPDF)) {
295
+			dol_syslog(__METHOD__.": passing iconPDF parameter is deprecated", LOG_WARNING);
296 296
 		}
297 297
 
298 298
 		global $langs, $conf, $user, $hookmanager;
299 299
 		global $form;
300 300
 
301
-		if (! is_object($form)) $form=new Form($this->db);
301
+		if (!is_object($form)) $form = new Form($this->db);
302 302
 
303 303
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
304 304
 
305 305
 		// For backward compatibility
306
-		if (! empty($iconPDF)) {
306
+		if (!empty($iconPDF)) {
307 307
 			return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
308 308
 		}
309 309
 
310 310
 		// Add entity in $param
311
-		$param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity);
311
+		$param .= 'entity='.(!empty($object->entity) ? $object->entity : $conf->entity);
312 312
 
313
-		$printer=0;
314
-		if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison')))	// The direct print feature is implemented only for such elements
313
+		$printer = 0;
314
+		if (in_array($modulepart, array('facture', 'supplier_proposal', 'propal', 'proposal', 'order', 'commande', 'expedition', 'commande_fournisseur', 'expensereport', 'livraison')))	// The direct print feature is implemented only for such elements
315 315
 		{
316
-			$printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
316
+			$printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled)) ?true:false;
317 317
 		}
318 318
 
319 319
 		$hookmanager->initHooks(array('formfile'));
320 320
 
321 321
 		// Get list of files
322
-		$file_list=null;
323
-		if (! empty($filedir))
322
+		$file_list = null;
323
+		if (!empty($filedir))
324 324
 		{
325
-			$file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC);
325
+			$file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
326 326
 		}
327 327
 		if ($hideifempty && empty($file_list)) return '';
328 328
 
329
-		$out='';
330
-		$forname='builddoc';
331
-		$headershown=0;
332
-		$showempty=0;
333
-		$i=0;
329
+		$out = '';
330
+		$forname = 'builddoc';
331
+		$headershown = 0;
332
+		$showempty = 0;
333
+		$i = 0;
334 334
 
335
-		$out.= "\n".'<!-- Start show_document -->'."\n";
335
+		$out .= "\n".'<!-- Start show_document -->'."\n";
336 336
 		//print 'filedir='.$filedir;
337 337
 
338 338
 		if (preg_match('/massfilesarea_/', $modulepart))
339 339
 		{
340
-			$out.='<div id="show_files"><br></div>'."\n";
341
-			$title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
342
-			$title.='<script type="text/javascript" language="javascript">
340
+			$out .= '<div id="show_files"><br></div>'."\n";
341
+			$title = $langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
342
+			$title .= '<script type="text/javascript" language="javascript">
343 343
 				jQuery(document).ready(function() {
344 344
 					jQuery(\'#togglemassfilesarea\').click(function() {
345 345
 						if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown")
@@ -360,63 +360,63 @@  discard block
 block discarded – undo
360 360
 				</script>';
361 361
 		}
362 362
 
363
-		$titletoshow=$langs->trans("Documents");
364
-		if (! empty($title)) $titletoshow=$title;
363
+		$titletoshow = $langs->trans("Documents");
364
+		if (!empty($title)) $titletoshow = $title;
365 365
 
366 366
 		// Show table
367 367
 		if ($genallowed)
368 368
 		{
369
-			$modellist=array();
369
+			$modellist = array();
370 370
 
371 371
 			if ($modulepart == 'company')
372 372
 			{
373
-				$showempty=1;
374
-				if (is_array($genallowed)) $modellist=$genallowed;
373
+				$showempty = 1;
374
+				if (is_array($genallowed)) $modellist = $genallowed;
375 375
 				else
376 376
 				{
377 377
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
378
-					$modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
378
+					$modellist = ModeleThirdPartyDoc::liste_modeles($this->db);
379 379
 				}
380 380
 			}
381 381
 			else if ($modulepart == 'propal')
382 382
 			{
383
-				if (is_array($genallowed)) $modellist=$genallowed;
383
+				if (is_array($genallowed)) $modellist = $genallowed;
384 384
 				else
385 385
 				{
386 386
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
387
-					$modellist=ModelePDFPropales::liste_modeles($this->db);
387
+					$modellist = ModelePDFPropales::liste_modeles($this->db);
388 388
 				}
389 389
 			}
390 390
 			else if ($modulepart == 'supplier_proposal')
391 391
 			{
392
-				if (is_array($genallowed)) $modellist=$genallowed;
392
+				if (is_array($genallowed)) $modellist = $genallowed;
393 393
 				else
394 394
 				{
395 395
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
396
-					$modellist=ModelePDFSupplierProposal::liste_modeles($this->db);
396
+					$modellist = ModelePDFSupplierProposal::liste_modeles($this->db);
397 397
 				}
398 398
 			}
399 399
 			else if ($modulepart == 'commande')
400 400
 			{
401
-				if (is_array($genallowed)) $modellist=$genallowed;
401
+				if (is_array($genallowed)) $modellist = $genallowed;
402 402
 				else
403 403
 				{
404 404
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
405
-					$modellist=ModelePDFCommandes::liste_modeles($this->db);
405
+					$modellist = ModelePDFCommandes::liste_modeles($this->db);
406 406
 				}
407 407
 			}
408 408
 			elseif ($modulepart == 'expedition')
409 409
 			{
410
-				if (is_array($genallowed)) $modellist=$genallowed;
410
+				if (is_array($genallowed)) $modellist = $genallowed;
411 411
 				else
412 412
 				{
413 413
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
414
-					$modellist=ModelePDFExpedition::liste_modeles($this->db);
414
+					$modellist = ModelePDFExpedition::liste_modeles($this->db);
415 415
 				}
416 416
 			}
417 417
             elseif ($modulepart == 'reception')
418 418
             {
419
-                if (is_array($genallowed)) $modellist=$genallowed;
419
+                if (is_array($genallowed)) $modellist = $genallowed;
420 420
                 else
421 421
                 {
422 422
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
@@ -425,407 +425,407 @@  discard block
 block discarded – undo
425 425
             }
426 426
 			elseif ($modulepart == 'livraison')
427 427
 			{
428
-				if (is_array($genallowed)) $modellist=$genallowed;
428
+				if (is_array($genallowed)) $modellist = $genallowed;
429 429
 				else
430 430
 				{
431 431
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
432
-					$modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
432
+					$modellist = ModelePDFDeliveryOrder::liste_modeles($this->db);
433 433
 				}
434 434
 			}
435 435
 			else if ($modulepart == 'ficheinter')
436 436
 			{
437
-				if (is_array($genallowed)) $modellist=$genallowed;
437
+				if (is_array($genallowed)) $modellist = $genallowed;
438 438
 				else
439 439
 				{
440 440
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
441
-					$modellist=ModelePDFFicheinter::liste_modeles($this->db);
441
+					$modellist = ModelePDFFicheinter::liste_modeles($this->db);
442 442
 				}
443 443
 			}
444 444
 			elseif ($modulepart == 'facture')
445 445
 			{
446
-				if (is_array($genallowed)) $modellist=$genallowed;
446
+				if (is_array($genallowed)) $modellist = $genallowed;
447 447
 				else
448 448
 				{
449 449
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
450
-					$modellist=ModelePDFFactures::liste_modeles($this->db);
450
+					$modellist = ModelePDFFactures::liste_modeles($this->db);
451 451
 				}
452 452
 			}
453 453
 			elseif ($modulepart == 'contract')
454 454
 			{
455
-				if (is_array($genallowed)) $modellist=$genallowed;
455
+				if (is_array($genallowed)) $modellist = $genallowed;
456 456
 				else
457 457
 				{
458 458
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
459
-					$modellist=ModelePDFContract::liste_modeles($this->db);
459
+					$modellist = ModelePDFContract::liste_modeles($this->db);
460 460
 				}
461 461
 			}
462 462
 			elseif ($modulepart == 'project')
463 463
 			{
464
-				if (is_array($genallowed)) $modellist=$genallowed;
464
+				if (is_array($genallowed)) $modellist = $genallowed;
465 465
 				else
466 466
 				{
467 467
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
468
-					$modellist=ModelePDFProjects::liste_modeles($this->db);
468
+					$modellist = ModelePDFProjects::liste_modeles($this->db);
469 469
 				}
470 470
 			}
471 471
 			elseif ($modulepart == 'project_task')
472 472
 			{
473
-				if (is_array($genallowed)) $modellist=$genallowed;
473
+				if (is_array($genallowed)) $modellist = $genallowed;
474 474
 				else
475 475
 				{
476 476
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
477
-					$modellist=ModelePDFTask::liste_modeles($this->db);
477
+					$modellist = ModelePDFTask::liste_modeles($this->db);
478 478
 				}
479 479
 			}
480 480
 			elseif ($modulepart == 'product')
481 481
 			{
482
-				if (is_array($genallowed)) $modellist=$genallowed;
482
+				if (is_array($genallowed)) $modellist = $genallowed;
483 483
 				else
484 484
 				{
485 485
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
486
-					$modellist=ModelePDFProduct::liste_modeles($this->db);
486
+					$modellist = ModelePDFProduct::liste_modeles($this->db);
487 487
 				}
488 488
 			}
489 489
 			elseif ($modulepart == 'product_batch')
490 490
 			{
491
-				if (is_array($genallowed)) $modellist=$genallowed;
491
+				if (is_array($genallowed)) $modellist = $genallowed;
492 492
 				else
493 493
 				{
494 494
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
495
-					$modellist=ModelePDFProductBatch::liste_modeles($this->db);
495
+					$modellist = ModelePDFProductBatch::liste_modeles($this->db);
496 496
 				}
497 497
 			}
498 498
 			elseif ($modulepart == 'stock')
499 499
 			{
500
-				if (is_array($genallowed)) $modellist=$genallowed;
500
+				if (is_array($genallowed)) $modellist = $genallowed;
501 501
 				else
502 502
 				{
503 503
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
504
-					$modellist=ModelePDFStock::liste_modeles($this->db);
504
+					$modellist = ModelePDFStock::liste_modeles($this->db);
505 505
 				}
506 506
 			}
507 507
 			elseif ($modulepart == 'movement')
508 508
 			{
509
-				if (is_array($genallowed)) $modellist=$genallowed;
509
+				if (is_array($genallowed)) $modellist = $genallowed;
510 510
 				else
511 511
 				{
512 512
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php';
513
-					$modellist=ModelePDFMovement::liste_modeles($this->db);
513
+					$modellist = ModelePDFMovement::liste_modeles($this->db);
514 514
 				}
515 515
 			}
516 516
 			elseif ($modulepart == 'export')
517 517
 			{
518
-				if (is_array($genallowed)) $modellist=$genallowed;
518
+				if (is_array($genallowed)) $modellist = $genallowed;
519 519
 				else
520 520
 				{
521 521
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
522
-					$modellist=ModeleExports::liste_modeles($this->db);
522
+					$modellist = ModeleExports::liste_modeles($this->db);
523 523
 				}
524 524
 			}
525 525
 			else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
526 526
 			{
527
-				if (is_array($genallowed)) $modellist=$genallowed;
527
+				if (is_array($genallowed)) $modellist = $genallowed;
528 528
 				else
529 529
 				{
530 530
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
531
-					$modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
531
+					$modellist = ModelePDFSuppliersOrders::liste_modeles($this->db);
532 532
 				}
533 533
 			}
534 534
 			else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
535 535
 			{
536
-				if (is_array($genallowed)) $modellist=$genallowed;
536
+				if (is_array($genallowed)) $modellist = $genallowed;
537 537
 				else
538 538
 				{
539 539
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
540
-					$modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
540
+					$modellist = ModelePDFSuppliersInvoices::liste_modeles($this->db);
541 541
 				}
542 542
 			}
543 543
 			else if ($modulepart == 'supplier_payment')
544 544
 			{
545
-				if (is_array($genallowed)) $modellist=$genallowed;
545
+				if (is_array($genallowed)) $modellist = $genallowed;
546 546
 				else
547 547
 				{
548 548
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
549
-					$modellist=ModelePDFSuppliersPayments::liste_modeles($this->db);
549
+					$modellist = ModelePDFSuppliersPayments::liste_modeles($this->db);
550 550
 				}
551 551
 			}
552 552
 			else if ($modulepart == 'remisecheque')
553 553
 			{
554
-				if (is_array($genallowed)) $modellist=$genallowed;
554
+				if (is_array($genallowed)) $modellist = $genallowed;
555 555
 				else
556 556
 				{
557 557
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
558
-					$modellist=ModeleChequeReceipts::liste_modeles($this->db);
558
+					$modellist = ModeleChequeReceipts::liste_modeles($this->db);
559 559
 				}
560 560
 			}
561 561
 			elseif ($modulepart == 'donation')
562 562
 			{
563
-				if (is_array($genallowed)) $modellist=$genallowed;
563
+				if (is_array($genallowed)) $modellist = $genallowed;
564 564
 				else
565 565
 				{
566 566
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
567
-					$modellist=ModeleDon::liste_modeles($this->db);
567
+					$modellist = ModeleDon::liste_modeles($this->db);
568 568
 				}
569 569
 			}
570 570
 			elseif ($modulepart == 'member')
571 571
 			{
572
-				if (is_array($genallowed)) $modellist=$genallowed;
572
+				if (is_array($genallowed)) $modellist = $genallowed;
573 573
 				else
574 574
 				{
575 575
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
576
-					$modellist=ModelePDFCards::liste_modeles($this->db);
576
+					$modellist = ModelePDFCards::liste_modeles($this->db);
577 577
 				}
578 578
 			}
579 579
 			elseif ($modulepart == 'agenda' || $modulepart == 'actions')
580 580
 			{
581
-				if (is_array($genallowed)) $modellist=$genallowed;
581
+				if (is_array($genallowed)) $modellist = $genallowed;
582 582
 				else
583 583
 				{
584 584
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
585
-					$modellist=ModeleAction::liste_modeles($this->db);
585
+					$modellist = ModeleAction::liste_modeles($this->db);
586 586
 				}
587 587
 			}
588 588
 			else if ($modulepart == 'expensereport')
589 589
 			{
590
-				if (is_array($genallowed)) $modellist=$genallowed;
590
+				if (is_array($genallowed)) $modellist = $genallowed;
591 591
 				else
592 592
 				{
593 593
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
594
-					$modellist=ModeleExpenseReport::liste_modeles($this->db);
594
+					$modellist = ModeleExpenseReport::liste_modeles($this->db);
595 595
 				}
596 596
 			}
597 597
 			else if ($modulepart == 'unpaid')
598 598
 			{
599
-				$modellist='';
599
+				$modellist = '';
600 600
 			}
601 601
 			elseif ($modulepart == 'user')
602 602
 			{
603
-				if (is_array($genallowed)) $modellist=$genallowed;
603
+				if (is_array($genallowed)) $modellist = $genallowed;
604 604
 				else
605 605
 				{
606 606
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
607
-					$modellist=ModelePDFUser::liste_modeles($this->db);
607
+					$modellist = ModelePDFUser::liste_modeles($this->db);
608 608
 				}
609 609
 			}
610 610
 			elseif ($modulepart == 'usergroup')
611 611
 			{
612
-				if (is_array($genallowed)) $modellist=$genallowed;
612
+				if (is_array($genallowed)) $modellist = $genallowed;
613 613
 				else
614 614
 				{
615 615
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
616
-					$modellist=ModelePDFUserGroup::liste_modeles($this->db);
616
+					$modellist = ModelePDFUserGroup::liste_modeles($this->db);
617 617
 				}
618 618
 			}
619 619
 			else
620 620
 			{
621 621
 				// For normalized standard modules
622
-				$file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
622
+				$file = dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php', 0);
623 623
 				if (file_exists($file))
624 624
 				{
625
-					$res=include_once $file;
625
+					$res = include_once $file;
626 626
 				}
627 627
 				// For normalized external modules
628 628
 				else
629 629
 				{
630
-					$file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
631
-					$res=include_once $file;
630
+					$file = dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php', 0);
631
+					$res = include_once $file;
632 632
 				}
633
-				$class='ModelePDF'.ucfirst($modulepart);
633
+				$class = 'ModelePDF'.ucfirst($modulepart);
634 634
 				if (class_exists($class))
635 635
 				{
636
-					$modellist=call_user_func($class.'::liste_modeles',$this->db);
636
+					$modellist = call_user_func($class.'::liste_modeles', $this->db);
637 637
 				}
638 638
 				else
639 639
 				{
640
-					dol_print_error($this->db,'Bad value for modulepart');
640
+					dol_print_error($this->db, 'Bad value for modulepart');
641 641
 					return -1;
642 642
 				}
643 643
 			}
644 644
 
645 645
 			// Set headershown to avoid to have table opened a second time later
646
-			$headershown=1;
646
+			$headershown = 1;
647 647
 
648
-			$buttonlabeltoshow=$buttonlabel;
649
-			if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
648
+			$buttonlabeltoshow = $buttonlabel;
649
+			if (empty($buttonlabel)) $buttonlabel = $langs->trans('Generate');
650 650
 
651
-			if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form';   // So we switch to form after a generation
652
-			if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
653
-			$out.= '<input type="hidden" name="action" value="builddoc">';
654
-			$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
651
+			if ($conf->browser->layout == 'phone') $urlsource .= '#'.$forname.'_form'; // So we switch to form after a generation
652
+			if (empty($noform)) $out .= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc').'" id="'.$forname.'_form" method="post">';
653
+			$out .= '<input type="hidden" name="action" value="builddoc">';
654
+			$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
655 655
 
656
-			$out.= load_fiche_titre($titletoshow, '', '');
657
-			$out.= '<div class="div-table-responsive-no-min">';
658
-			$out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
656
+			$out .= load_fiche_titre($titletoshow, '', '');
657
+			$out .= '<div class="div-table-responsive-no-min">';
658
+			$out .= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
659 659
 
660
-			$out.= '<tr class="liste_titre">';
660
+			$out .= '<tr class="liste_titre">';
661 661
 
662
-			$addcolumforpicto=($delallowed || $printer || $morepicto);
663
-			$out.= '<th align="center" colspan="'.(3+($addcolumforpicto?1:0)).'" class="formdoc liste_titre maxwidthonsmartphone">';
662
+			$addcolumforpicto = ($delallowed || $printer || $morepicto);
663
+			$out .= '<th align="center" colspan="'.(3 + ($addcolumforpicto ? 1 : 0)).'" class="formdoc liste_titre maxwidthonsmartphone">';
664 664
 
665 665
 			// Model
666
-			if (! empty($modellist))
666
+			if (!empty($modellist))
667 667
 			{
668
-				$out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
668
+				$out .= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
669 669
 				if (is_array($modellist) && count($modellist) == 1)    // If there is only one element
670 670
 				{
671
-					$arraykeys=array_keys($modellist);
672
-					$modelselected=$arraykeys[0];
671
+					$arraykeys = array_keys($modellist);
672
+					$modelselected = $arraykeys[0];
673 673
 				}
674
-				$out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
674
+				$out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
675 675
 				if ($conf->use_javascript_ajax)
676 676
 				{
677
-					$out.= ajax_combobox('model');
677
+					$out .= ajax_combobox('model');
678 678
 				}
679 679
 			}
680 680
 			else
681 681
 			{
682
-				$out.= '<div class="float">'.$langs->trans("Files").'</div>';
682
+				$out .= '<div class="float">'.$langs->trans("Files").'</div>';
683 683
 			}
684 684
 
685 685
 			// Language code (if multilang)
686
-			if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty))
686
+			if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && !$forcenomultilang && (!empty($modellist) || $showempty))
687 687
 			{
688 688
 				include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
689
-				$formadmin=new FormAdmin($this->db);
690
-				$defaultlang=$codelang?$codelang:$langs->getDefaultLang();
691
-				$morecss='maxwidth150';
692
-				if ($conf->browser->layout == 'phone') $morecss='maxwidth100';
693
-				$out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
689
+				$formadmin = new FormAdmin($this->db);
690
+				$defaultlang = $codelang ? $codelang : $langs->getDefaultLang();
691
+				$morecss = 'maxwidth150';
692
+				if ($conf->browser->layout == 'phone') $morecss = 'maxwidth100';
693
+				$out .= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
694 694
 			}
695 695
 			else
696 696
 			{
697
-				$out.= '&nbsp;';
697
+				$out .= '&nbsp;';
698 698
 			}
699 699
 
700 700
 			// Button
701 701
 			$genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
702
-			$genbutton.= ' type="submit" value="'.$buttonlabel.'"';
703
-			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled';
704
-			$genbutton.= '>';
705
-			if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
702
+			$genbutton .= ' type="submit" value="'.$buttonlabel.'"';
703
+			if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) $genbutton .= ' disabled';
704
+			$genbutton .= '>';
705
+			if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
706 706
 			{
707 707
 			   	$langs->load("errors");
708
-			   	$genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
708
+			   	$genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
709 709
 			}
710
-			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
711
-			if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton='';
712
-			$out.= $genbutton;
713
-			$out.= '</th>';
710
+			if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton = '';
711
+			if (empty($modellist) && !$showempty && $modulepart != 'unpaid') $genbutton = '';
712
+			$out .= $genbutton;
713
+			$out .= '</th>';
714 714
 
715 715
 			if (!empty($hookmanager->hooks['formfile']))
716 716
 			{
717
-				foreach($hookmanager->hooks['formfile'] as $module)
717
+				foreach ($hookmanager->hooks['formfile'] as $module)
718 718
 				{
719 719
 					if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
720 720
 				}
721 721
 			}
722
-			$out.= '</tr>';
722
+			$out .= '</tr>';
723 723
 
724 724
 			// Execute hooks
725
-			$parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
725
+			$parameters = array('socid'=>(isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id'=>(isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart'=>$modulepart);
726 726
 			if (is_object($hookmanager))
727 727
 			{
728
-				$reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
729
-				$out.= $hookmanager->resPrint;
728
+				$reshook = $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']);
729
+				$out .= $hookmanager->resPrint;
730 730
 			}
731 731
 		}
732 732
 
733 733
 		// Get list of files
734
-		if (! empty($filedir))
734
+		if (!empty($filedir))
735 735
 		{
736 736
 			$link_list = array();
737 737
 			if (is_object($object))
738 738
 			{
739
-				require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
739
+				require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
740 740
 				$link = new Link($this->db);
741 741
 				$sortfield = $sortorder = null;
742 742
 				$res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
743 743
 			}
744 744
 
745
-			$out.= '<!-- html.formfile::showdocuments -->'."\n";
745
+			$out .= '<!-- html.formfile::showdocuments -->'."\n";
746 746
 
747 747
 			// Show title of array if not already shown
748
-			if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
749
-				&& ! $headershown)
748
+			if ((!empty($file_list) || !empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
749
+				&& !$headershown)
750 750
 			{
751
-				$headershown=1;
752
-				$out.= '<div class="titre">'.$titletoshow.'</div>'."\n";
753
-				$out.= '<div class="div-table-responsive-no-min">';
754
-				$out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n";
751
+				$headershown = 1;
752
+				$out .= '<div class="titre">'.$titletoshow.'</div>'."\n";
753
+				$out .= '<div class="div-table-responsive-no-min">';
754
+				$out .= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n";
755 755
 			}
756 756
 
757 757
 			// Loop on each file found
758 758
 			if (is_array($file_list))
759 759
 			{
760
-				foreach($file_list as $file)
760
+				foreach ($file_list as $file)
761 761
 				{
762 762
 					// Define relative path for download link (depends on module)
763
-					$relativepath=$file["name"];										// Cas general
764
-					if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
765
-					if ($modulepart == 'export') $relativepath = $file["name"];			// Other case
763
+					$relativepath = $file["name"]; // Cas general
764
+					if ($modulesubdir) $relativepath = $modulesubdir."/".$file["name"]; // Cas propal, facture...
765
+					if ($modulepart == 'export') $relativepath = $file["name"]; // Other case
766 766
 
767
-					$out.= '<tr class="oddeven">';
767
+					$out .= '<tr class="oddeven">';
768 768
 
769 769
 					$documenturl = DOL_URL_ROOT.'/document.php';
770
-					if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP;    // To use another wrapper
770
+					if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
771 771
 
772 772
 					// Show file name with link to download
773
-					$out.= '<td class="minwidth200">';
774
-					$out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param?'&'.$param:'').'"';
775
-					$mime=dol_mimetype($relativepath,'',0);
776
-					if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
777
-					$out.= ' target="_blank">';
778
-					$out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]);
779
-					$out.= dol_trunc($file["name"], 150);
780
-					$out.= '</a>'."\n";
781
-					$out.= $this->showPreview($file,$modulepart,$relativepath,0,$param);
782
-					$out.= '</td>';
773
+					$out .= '<td class="minwidth200">';
774
+					$out .= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
775
+					$mime = dol_mimetype($relativepath, '', 0);
776
+					if (preg_match('/text/', $mime)) $out .= ' target="_blank"';
777
+					$out .= ' target="_blank">';
778
+					$out .= img_mime($file["name"], $langs->trans("File").': '.$file["name"]);
779
+					$out .= dol_trunc($file["name"], 150);
780
+					$out .= '</a>'."\n";
781
+					$out .= $this->showPreview($file, $modulepart, $relativepath, 0, $param);
782
+					$out .= '</td>';
783 783
 
784 784
 					// Show file size
785
-					$size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
786
-					$out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>';
785
+					$size = (!empty($file['size']) ? $file['size'] : dol_filesize($filedir."/".$file["name"]));
786
+					$out .= '<td align="right" class="nowrap">'.dol_print_size($size, 1, 1).'</td>';
787 787
 
788 788
 					// Show file date
789
-					$date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
790
-					$out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
789
+					$date = (!empty($file['date']) ? $file['date'] : dol_filemtime($filedir."/".$file["name"]));
790
+					$out .= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
791 791
 
792 792
 					if ($delallowed || $printer || $morepicto)
793 793
 					{
794
-						$out.= '<td class="right nowraponall">';
794
+						$out .= '<td class="right nowraponall">';
795 795
 						if ($delallowed)
796 796
 						{
797 797
 							$tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
798
-							$out.= '<a href="'.$tmpurlsource.(strpos($tmpurlsource,'?')?'&amp;':'?').'action=remove_file&amp;file='.urlencode($relativepath);
799
-							$out.= ($param?'&amp;'.$param:'');
798
+							$out .= '<a href="'.$tmpurlsource.(strpos($tmpurlsource, '?') ? '&amp;' : '?').'action=remove_file&amp;file='.urlencode($relativepath);
799
+							$out .= ($param ? '&amp;'.$param : '');
800 800
 							//$out.= '&modulepart='.$modulepart; // TODO obsolete ?
801 801
 							//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
802
-							$out.= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
802
+							$out .= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
803 803
 						}
804 804
 						if ($printer)
805 805
 						{
806 806
 							//$out.= '<td align="right">';
807
-							$out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
808
-							$out.= ($param?'&amp;'.$param:'');
809
-							$out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>';
807
+							$out .= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource, '?') ? '&amp;' : '?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
808
+							$out .= ($param ? '&amp;'.$param : '');
809
+							$out .= '">'.img_picto($langs->trans("PrintFile", $relativepath), 'printer.png').'</a>';
810 810
 						}
811 811
 						if ($morepicto)
812 812
 						{
813
-							$morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto);
814
-							$out.=$morepicto;
813
+							$morepicto = preg_replace('/__FILENAMEURLENCODED__/', urlencode($relativepath), $morepicto);
814
+							$out .= $morepicto;
815 815
 						}
816
-						$out.='</td>';
816
+						$out .= '</td>';
817 817
 					}
818 818
 
819 819
 					if (is_object($hookmanager))
820 820
 					{
821
-						$parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath);
822
-						$res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file);
821
+						$parameters = array('socid'=>(isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id'=>(isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart'=>$modulepart, 'relativepath'=>$relativepath);
822
+						$res = $hookmanager->executeHooks('formBuilddocLineOptions', $parameters, $file);
823 823
 						if (empty($res))
824 824
 						{
825
-							$out.= $hookmanager->resPrint;		// Complete line
826
-							$out.= '</tr>';
825
+							$out .= $hookmanager->resPrint; // Complete line
826
+							$out .= '</tr>';
827 827
 						}
828
-						else $out = $hookmanager->resPrint;		// Replace line
828
+						else $out = $hookmanager->resPrint; // Replace line
829 829
 			  		}
830 830
 				}
831 831
 
@@ -834,42 +834,42 @@  discard block
 block discarded – undo
834 834
 			// Loop on each link found
835 835
 			if (is_array($link_list))
836 836
 			{
837
-				$colspan=2;
837
+				$colspan = 2;
838 838
 
839
-				foreach($link_list as $file)
839
+				foreach ($link_list as $file)
840 840
 				{
841
-					$out.='<tr class="oddeven">';
842
-					$out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
843
-					$out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">';
844
-					$out.=$file->label;
845
-					$out.='</a>';
846
-					$out.='</td>';
847
-					$out.='<td align="right">';
848
-					$out.=dol_print_date($file->datea,'dayhour');
849
-					$out.='</td>';
850
-					if ($delallowed || $printer || $morepicto) $out.='<td></td>';
851
-					$out.='</tr>'."\n";
841
+					$out .= '<tr class="oddeven">';
842
+					$out .= '<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
843
+					$out .= '<a data-ajax="false" href="'.$link->url.'" target="_blank">';
844
+					$out .= $file->label;
845
+					$out .= '</a>';
846
+					$out .= '</td>';
847
+					$out .= '<td align="right">';
848
+					$out .= dol_print_date($file->datea, 'dayhour');
849
+					$out .= '</td>';
850
+					if ($delallowed || $printer || $morepicto) $out .= '<td></td>';
851
+					$out .= '</tr>'."\n";
852 852
 				}
853 853
 				$this->numoffiles++;
854 854
 			}
855 855
 
856 856
 		 	if (count($file_list) == 0 && count($link_list) == 0 && $headershown)
857 857
 			{
858
-				$out.='<tr><td colspan="'.(3+($addcolumforpicto?1:0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
858
+				$out .= '<tr><td colspan="'.(3 + ($addcolumforpicto ? 1 : 0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
859 859
 			}
860 860
 		}
861 861
 
862 862
 		if ($headershown)
863 863
 		{
864 864
 			// Affiche pied du tableau
865
-			$out.= "</table>\n";
866
-			$out.= "</div>\n";
865
+			$out .= "</table>\n";
866
+			$out .= "</div>\n";
867 867
 			if ($genallowed)
868 868
 			{
869
-				if (empty($noform)) $out.= '</form>'."\n";
869
+				if (empty($noform)) $out .= '</form>'."\n";
870 870
 			}
871 871
 		}
872
-		$out.= '<!-- End show_document -->'."\n";
872
+		$out .= '<!-- End show_document -->'."\n";
873 873
 		//return ($i?$i:$headershown);
874 874
 		return $out;
875 875
 	}
@@ -885,98 +885,98 @@  discard block
 block discarded – undo
885 885
 	 *  @param	string	$filter			Filter filenames on this regex string (Example: '\.pdf$')
886 886
 	 *	@return	string              	Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles
887 887
 	 */
888
-	function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
888
+	function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '')
889 889
 	{
890 890
 		global $conf, $langs;
891 891
 
892 892
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
893 893
 
894
-		$out='';
895
-		$this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
894
+		$out = '';
895
+		$this->infofiles = array('nboffiles'=>0, 'extensions'=>array(), 'files'=>array());
896 896
 
897 897
 		$entity = 1; // Without multicompany
898 898
 
899 899
 		// Get object entity
900
-		if (! empty($conf->multicompany->enabled))
900
+		if (!empty($conf->multicompany->enabled))
901 901
 		{
902
-			preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs);
903
-			$entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
902
+			preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir, '/').'$/', $filedir, $regs);
903
+			$entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
904 904
 		}
905 905
 
906 906
 		// Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files)
907 907
 		// @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ?
908
-		if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
908
+		if (!empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
909 909
 		{
910
-			$filterforfilesearch = preg_quote(basename($modulesubdir),'/');
910
+			$filterforfilesearch = preg_quote(basename($modulesubdir), '/');
911 911
 		}
912 912
 		else
913 913
 		{
914
-			$filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+';
914
+			$filterforfilesearch = preg_quote(basename($modulesubdir), '/').'[^\-]+';
915 915
 		}
916
-		$file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$');	// We also discard .meta and .png preview
916
+		$file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
917 917
 
918 918
 		//var_dump($file_list);
919 919
 		// For ajax treatment
920
-		$out.= '<!-- html.formfile::getDocumentsLink -->'."\n";
921
-		if (! empty($file_list))
920
+		$out .= '<!-- html.formfile::getDocumentsLink -->'."\n";
921
+		if (!empty($file_list))
922 922
 		{
923
-			$out='<dl class="dropdown inline-block">
923
+			$out = '<dl class="dropdown inline-block">
924 924
     			<dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', 'valignmiddle').'</a></dt>
925 925
     			<dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields" style="display: none;">';
926
-			$tmpout='';
926
+			$tmpout = '';
927 927
 
928 928
 			// Loop on each file found
929
-			$found=0;
930
-			foreach($file_list as $file)
929
+			$found = 0;
930
+			foreach ($file_list as $file)
931 931
 			{
932 932
 				$i++;
933
-				if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue;	// Discard this. It does not match provided filter.
933
+				if ($filter && !preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter.
934 934
 
935 935
 				$found++;
936 936
 				// Define relative path for download link (depends on module)
937
-				$relativepath=$file["name"];								// Cas general
938
-				if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
937
+				$relativepath = $file["name"]; // Cas general
938
+				if ($modulesubdir) $relativepath = $modulesubdir."/".$file["name"]; // Cas propal, facture...
939 939
 				// Autre cas
940
-				if ($modulepart == 'donation')            {
941
-					$relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
940
+				if ($modulepart == 'donation') {
941
+					$relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'donation').$file["name"];
942 942
 				}
943
-				if ($modulepart == 'export')              {
943
+				if ($modulepart == 'export') {
944 944
 					$relativepath = $file["name"];
945 945
 				}
946 946
 
947 947
 				$this->infofiles['nboffiles']++;
948
-				$this->infofiles['files'][]=$file['fullname'];
949
-				$ext=pathinfo($file["name"], PATHINFO_EXTENSION);
950
-				if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
948
+				$this->infofiles['files'][] = $file['fullname'];
949
+				$ext = pathinfo($file["name"], PATHINFO_EXTENSION);
950
+				if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext] = 1;
951 951
 				else $this->infofiles['extensions'][$ext]++;
952 952
 
953 953
 				// Preview
954
-				if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
954
+				if (!empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
955 955
 				{
956 956
 					$tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
957 957
 					if ($tmparray && $tmparray['url'])
958 958
 					{
959
-						$tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>';
959
+						$tmpout .= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css'] ? ' class="'.$tmparray['css'].'"' : '').($tmparray['mime'] ? ' mime="'.$tmparray['mime'].'"' : '').($tmparray['target'] ? ' target="'.$tmparray['target'].'"' : '').'>';
960 960
 						//$tmpout.= img_picto('','detail');
961
-						$tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
962
-						$tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>';
961
+						$tmpout .= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
962
+						$tmpout .= $langs->trans("Preview").' '.$ext.'</a></li>';
963 963
 					}
964 964
 				}
965 965
 
966 966
 				// Download
967
-				$tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
968
-				$mime=dol_mimetype($relativepath,'',0);
969
-				if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
970
-				$tmpout.= '>';
971
-				$tmpout.= img_mime($relativepath, $file["name"]);
972
-				$tmpout.= $langs->trans("Download").' '.$ext;
973
-				$tmpout.= '</a></li>'."\n";
974
-			}
975
-			$out.=$tmpout;
976
-			$out.='</ul></div></dd>
967
+				$tmpout .= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
968
+				$mime = dol_mimetype($relativepath, '', 0);
969
+				if (preg_match('/text/', $mime)) $tmpout .= ' target="_blank"';
970
+				$tmpout .= '>';
971
+				$tmpout .= img_mime($relativepath, $file["name"]);
972
+				$tmpout .= $langs->trans("Download").' '.$ext;
973
+				$tmpout .= '</a></li>'."\n";
974
+			}
975
+			$out .= $tmpout;
976
+			$out .= '</ul></div></dd>
977 977
     			</dl>';
978 978
 
979
-			if (! $found) $out='';
979
+			if (!$found) $out = '';
980 980
 		}
981 981
 		else
982 982
 		{
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 	 * 	@return	 int						<0 if KO, nb of files shown if OK
1019 1019
 	 *  @see list_of_autoecmfiles
1020 1020
 	 */
1021
-	function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1, $addfilterfields=0)
1021
+	function list_of_documents($filearray, $object, $modulepart, $param = '', $forcedownload = 0, $relativepath = '', $permonobject = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $title = '', $url = '', $showrelpart = 0, $permtoeditline = -1, $upload_dir = '', $sortfield = '', $sortorder = 'ASC', $disablemove = 1, $addfilterfields = 0)
1022 1022
 	{
1023 1023
         // phpcs:enable
1024 1024
 		global $user, $conf, $langs, $hookmanager;
@@ -1026,37 +1026,37 @@  discard block
 block discarded – undo
1026 1026
 		global $dolibarr_main_url_root;
1027 1027
 		global $form;
1028 1028
 
1029
-		$disablecrop=1;
1030
-		if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0;
1029
+		$disablecrop = 1;
1030
+		if (in_array($modulepart, array('expensereport', 'holiday', 'member', 'project', 'product', 'produit', 'service', 'societe', 'tax', 'ticket', 'user'))) $disablecrop = 0;
1031 1031
 
1032 1032
 		// Define relative path used to store the file
1033 1033
 		if (empty($relativepath))
1034 1034
 		{
1035
-			$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
1036
-			if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;	// TODO Call using a defined value for $relativepath
1037
-			if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1035
+			$relativepath = (!empty($object->ref) ?dol_sanitizeFileName($object->ref) : '').'/';
1036
+			if ($object->element == 'invoice_supplier') $relativepath = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath
1037
+			if ($object->element == 'project_task') $relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1038 1038
 		}
1039 1039
 		// For backward compatiblity, we detect file stored into an old path
1040
-		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
1040
+		if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
1041 1041
 		{
1042
-		    $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/';
1042
+		    $relativepath = preg_replace('/^.*\/produit\//', '', $filearray[0]['path']).'/';
1043 1043
 		}
1044 1044
 		// Defined relative dir to DOL_DATA_ROOT
1045 1045
 		$relativedir = '';
1046 1046
 		if ($upload_dir)
1047 1047
 		{
1048
-			$relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
1049
-			$relativedir = preg_replace('/^[\\/]/','',$relativedir);
1048
+			$relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
1049
+			$relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1050 1050
 		}
1051 1051
 
1052 1052
 		$hookmanager->initHooks(array('formfile'));
1053
-		$parameters=array(
1053
+		$parameters = array(
1054 1054
 				'filearray' => $filearray,
1055 1055
 				'modulepart'=> $modulepart,
1056 1056
 				'param' => $param,
1057 1057
 				'forcedownload' => $forcedownload,
1058
-				'relativepath' => $relativepath,    // relative filename to module dir
1059
-				'relativedir' => $relativedir,      // relative dirname to DOL_DATA_ROOT
1058
+				'relativepath' => $relativepath, // relative filename to module dir
1059
+				'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT
1060 1060
 				'permtodelete' => $permonobject,
1061 1061
 				'useinecm' => $useinecm,
1062 1062
 				'textifempty' => $textifempty,
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 				'title' => $title,
1065 1065
 				'url' => $url
1066 1066
 		);
1067
-		$reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
1067
+		$reshook = $hookmanager->executeHooks('showFilesList', $parameters, $object);
1068 1068
 
1069 1069
 		if (isset($reshook) && $reshook != '') // null or '' for bypass
1070 1070
 		{
@@ -1072,37 +1072,37 @@  discard block
 block discarded – undo
1072 1072
 		}
1073 1073
 		else
1074 1074
 		{
1075
-			if (! is_object($form))
1075
+			if (!is_object($form))
1076 1076
 			{
1077
-				include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';		// The compoent may be included into ajax page that does not include the Form class
1078
-				$form=new Form($this->db);
1077
+				include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // The compoent may be included into ajax page that does not include the Form class
1078
+				$form = new Form($this->db);
1079 1079
 			}
1080 1080
 
1081
-			if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id;
1082
-			$relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath);
1083
-			if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend);
1081
+			if (!preg_match('/&id=/', $param) && isset($object->id)) $param .= '&id='.$object->id;
1082
+			$relativepathwihtoutslashend = preg_replace('/\/$/', '', $relativepath);
1083
+			if ($relativepathwihtoutslashend) $param .= '&file='.urlencode($relativepathwihtoutslashend);
1084 1084
 
1085 1085
 			if ($permtoeditline < 0)  // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1086 1086
 			{
1087
-				$permtoeditline=0;
1088
-				if (in_array($modulepart, array('product','produit','service')))
1087
+				$permtoeditline = 0;
1088
+				if (in_array($modulepart, array('product', 'produit', 'service')))
1089 1089
 				{
1090
-					if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1;
1091
-					if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1;
1090
+					if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline = 1;
1091
+					if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline = 1;
1092 1092
 				}
1093 1093
 			}
1094 1094
 			if (empty($conf->global->MAIN_UPLOAD_DOC))
1095 1095
 			{
1096
-				$permtoeditline=0;
1097
-				$permonobject=0;
1096
+				$permtoeditline = 0;
1097
+				$permonobject = 0;
1098 1098
 			}
1099 1099
 
1100 1100
 			// Show list of existing files
1101
-			if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1102
-			if (empty($url)) $url=$_SERVER["PHP_SELF"];
1101
+			if (empty($useinecm) && $title != 'none') print load_fiche_titre($title ? $title : $langs->trans("AttachedFiles"));
1102
+			if (empty($url)) $url = $_SERVER["PHP_SELF"];
1103 1103
 
1104 1104
 			print '<!-- html.formfile::list_of_documents -->'."\n";
1105
-			if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1105
+			if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline)
1106 1106
 			{
1107 1107
 				print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1108 1108
 				print '<input type="hidden" name="action" value="renamefile">';
@@ -1111,30 +1111,30 @@  discard block
 block discarded – undo
1111 1111
 			}
1112 1112
 
1113 1113
 			print '<div class="div-table-responsive-no-min">';
1114
-			print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
1114
+			print '<table width="100%" id="tablelines" class="'.($useinecm ? 'liste noborder' : 'liste').'">'."\n";
1115 1115
 
1116
-			if (! empty($addfilterfields))
1116
+			if (!empty($addfilterfields))
1117 1117
 			{
1118 1118
 				print '<tr class="liste_titre nodrag nodrop">';
1119
-				print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
1119
+				print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref', 'alpha')).'"></td>';
1120 1120
 				print '<td></td>';
1121 1121
 				print '<td></td>';
1122 1122
 				if (empty($useinecm)) print '<td></td>';
1123 1123
 				print '<td></td>';
1124 1124
 				print '<td></td>';
1125
-				if (! $disablemove) print '<td></td>';
1125
+				if (!$disablemove) print '<td></td>';
1126 1126
 				print "</tr>\n";
1127 1127
 			}
1128 1128
 
1129 1129
 			print '<tr class="liste_titre nodrag nodrop">';
1130 1130
 			//print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
1131
-			print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1132
-			print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1133
-			print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1134
-			if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');					// Preview
1131
+			print_liste_field_titre('Documents2', $url, "name", "", $param, 'align="left"', $sortfield, $sortorder);
1132
+			print_liste_field_titre('Size', $url, "size", "", $param, 'align="right"', $sortfield, $sortorder);
1133
+			print_liste_field_titre('Date', $url, "date", "", $param, 'align="center"', $sortfield, $sortorder);
1134
+			if (empty($useinecm)) print_liste_field_titre('', $url, "", "", $param, 'align="center"'); // Preview
1135 1135
 			print_liste_field_titre('');
1136 1136
 			print_liste_field_titre('');
1137
-			if (! $disablemove) print_liste_field_titre('');
1137
+			if (!$disablemove) print_liste_field_titre('');
1138 1138
 			print "</tr>\n";
1139 1139
 
1140 1140
 			// Get list of files stored into database for same relative directory
@@ -1145,29 +1145,29 @@  discard block
 block discarded – undo
1145 1145
 				//var_dump($sortfield.' - '.$sortorder);
1146 1146
 				if ($sortfield && $sortorder)	// If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1147 1147
 				{
1148
-					$filearray=dol_sort_array($filearray, $sortfield, $sortorder);
1148
+					$filearray = dol_sort_array($filearray, $sortfield, $sortorder);
1149 1149
 				}
1150 1150
 			}
1151 1151
 
1152
-			$nboffiles=count($filearray);
1152
+			$nboffiles = count($filearray);
1153 1153
 			if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1154 1154
 
1155
-			$i=0; $nboflines = 0; $lastrowid=0;
1156
-			foreach($filearray as $key => $file)      // filearray must be only files here
1155
+			$i = 0; $nboflines = 0; $lastrowid = 0;
1156
+			foreach ($filearray as $key => $file)      // filearray must be only files here
1157 1157
 			{
1158 1158
 				if ($file['name'] != '.'
1159 1159
 						&& $file['name'] != '..'
1160
-						&& ! preg_match('/\.meta$/i',$file['name']))
1160
+						&& !preg_match('/\.meta$/i', $file['name']))
1161 1161
 				{
1162 1162
 					if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
1163
-					$filepath=$relativepath.$file['name'];
1163
+					$filepath = $relativepath.$file['name'];
1164 1164
 
1165
-					$editline=0;
1165
+					$editline = 0;
1166 1166
 					$nboflines++;
1167 1167
 					print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1168 1168
 					// Do we have entry into database ?
1169 1169
 					print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
1170
-					print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'AFTER'.$lastrowid.'POS'.($i+1)).'">';
1170
+					print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid'] > 0 ? $filearray[$key]['rowid'] : 'AFTER'.$lastrowid.'POS'.($i + 1)).'">';
1171 1171
 
1172 1172
 					// File name
1173 1173
 					print '<td class="minwith200">';
@@ -1176,20 +1176,20 @@  discard block
 block discarded – undo
1176 1176
 					//print "XX".$file['name'];	//$file['name'] must be utf8
1177 1177
 					print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1178 1178
 					if ($forcedownload) print '&attachment=1';
1179
-					if (! empty($object->entity)) print '&entity='.$object->entity;
1179
+					if (!empty($object->entity)) print '&entity='.$object->entity;
1180 1180
 					print '&file='.urlencode($filepath);
1181 1181
 					print '">';
1182
-					print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
1182
+					print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')', 'inline-block valignbottom paddingright');
1183 1183
 					if ($showrelpart == 1) print $relativepath;
1184 1184
 					//print dol_trunc($file['name'],$maxlength,'middle');
1185
-					if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
1185
+					if (GETPOST('action', 'aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile', 'alpha')))
1186 1186
 					{
1187 1187
 						print '</a>';
1188
-						$section_dir=dirname(GETPOST('urlfile','alpha'));
1188
+						$section_dir = dirname(GETPOST('urlfile', 'alpha'));
1189 1189
 						print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1190 1190
 						print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1191 1191
 						print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1192
-						$editline=1;
1192
+						$editline = 1;
1193 1193
 					}
1194 1194
 					else
1195 1195
 					{
@@ -1197,15 +1197,15 @@  discard block
 block discarded – undo
1197 1197
 						print '</a>';
1198 1198
 					}
1199 1199
 					// Preview link
1200
-					if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
1200
+					if (!$editline) print $this->showPreview($file, $modulepart, $filepath);
1201 1201
 					// Public share link
1202 1202
 					//if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
1203 1203
 
1204 1204
 					print "</td>\n";
1205 1205
 
1206 1206
 					// Size
1207
-					$sizetoshow = dol_print_size($file['size'],1,1);
1208
-					$sizetoshowbytes = dol_print_size($file['size'],0,1);
1207
+					$sizetoshow = dol_print_size($file['size'], 1, 1);
1208
+					$sizetoshowbytes = dol_print_size($file['size'], 0, 1);
1209 1209
 
1210 1210
 					print '<td align="right" width="80px">';
1211 1211
 					if ($sizetoshow == $sizetoshowbytes) print $sizetoshow;
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
 					print '</td>';
1216 1216
 
1217 1217
 					// Date
1218
-					print '<td align="center" width="140px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>';	// 140px = width for date with PM format
1218
+					print '<td align="center" width="140px">'.dol_print_date($file['date'], "dayhour", "tzuser").'</td>'; // 140px = width for date with PM format
1219 1219
 
1220 1220
 					// Preview
1221 1221
 					if (empty($useinecm))
@@ -1224,18 +1224,18 @@  discard block
 block discarded – undo
1224 1224
 						print '<td align="center">';
1225 1225
 						if (image_format_supported($file['name']) > 0)
1226 1226
 						{
1227
-							$minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1228
-							if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1227
+							$minifile = getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1228
+							if (!dol_is_file($file['path'].'/'.$minifile)) $minifile = getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1229 1229
 							//print $file['path'].'/'.$minifile.'<br>';
1230 1230
 
1231
-							$urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity));
1231
+							$urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
1232 1232
 							if (empty($urlforhref)) {
1233
-								$urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1233
+								$urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1234 1234
 								print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
1235 1235
 							} else {
1236 1236
 								print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
1237 1237
 							}
1238
-							print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
1238
+							print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
1239 1239
 							print '</a>';
1240 1240
 						}
1241 1241
 						else print '&nbsp;';
@@ -1249,26 +1249,26 @@  discard block
 block discarded – undo
1249 1249
 						if ($editline)
1250 1250
 						{
1251 1251
 							print $langs->trans("FileSharedViaALink").' ';
1252
-							print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> ';
1252
+							print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share'] ? ' checked="checked"' : '').' /> ';
1253 1253
 						}
1254 1254
 						else
1255 1255
 						{
1256 1256
 							if ($file['share'])
1257 1257
 							{
1258 1258
 								// Define $urlwithroot
1259
-								$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
1260
-								$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
1259
+								$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
1260
+								$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
1261 1261
 								//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
1262 1262
 
1263 1263
 								//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1264
-								$forcedownload=0;
1265
-								$paramlink='';
1266
-								if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share'];			// Hash for public share
1267
-								if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
1264
+								$forcedownload = 0;
1265
+								$paramlink = '';
1266
+								if (!empty($file['share'])) $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
1267
+								if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1';
1268 1268
 
1269
-								$fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
1269
+								$fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
1270 1270
 
1271
-								print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' ';
1271
+								print img_picto($langs->trans("FileSharedViaALink"), 'object_globe.png').' ';
1272 1272
 								print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
1273 1273
 							}
1274 1274
 							else
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
 					print '</td>';
1281 1281
 
1282 1282
 					// Actions buttons
1283
-					if (! $editline)
1283
+					if (!$editline)
1284 1284
 					{
1285 1285
 						// Delete or view link
1286 1286
 						// ($param must start with &)
@@ -1289,33 +1289,33 @@  discard block
 block discarded – undo
1289 1289
 						{
1290 1290
 							print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1291 1291
 						}
1292
-						if (! $useinecm || $useinecm == 2)
1292
+						if (!$useinecm || $useinecm == 2)
1293 1293
 						{
1294
-							$newmodulepart=$modulepart;
1295
-							if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
1294
+							$newmodulepart = $modulepart;
1295
+							if (in_array($modulepart, array('product', 'produit', 'service'))) $newmodulepart = 'produit|service';
1296 1296
 
1297
-							if (! $disablecrop && image_format_supported($file['name']) > 0)
1297
+							if (!$disablecrop && image_format_supported($file['name']) > 0)
1298 1298
 							{
1299 1299
 								if ($permtoeditline)
1300 1300
 								{
1301 1301
 	   								// Link to resize
1302
-	   						   		print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>';
1302
+	   						   		print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"), 'resize', 'class="paddingrightonly"').'</a>';
1303 1303
 								}
1304 1304
 							}
1305 1305
 
1306 1306
 							if ($permtoeditline)
1307 1307
 							{
1308
-								$paramsectiondir=(in_array($modulepart, array('medias','ecm'))?'&section_dir='.urlencode($relativepath):'');
1309
-								print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>';
1308
+								$paramsectiondir = (in_array($modulepart, array('medias', 'ecm')) ? '&section_dir='.urlencode($relativepath) : '');
1309
+								print '<a href="'.(($useinecm == 1) ? '#' : ($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1310 1310
 							}
1311 1311
 						}
1312 1312
 						if ($permonobject)
1313 1313
 						{
1314
-							$useajax=1;
1315
-							if (! empty($conf->dol_use_jmobile)) $useajax=0;
1316
-							if (empty($conf->use_javascript_ajax)) $useajax=0;
1317
-							if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
1318
-							print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1314
+							$useajax = 1;
1315
+							if (!empty($conf->dol_use_jmobile)) $useajax = 0;
1316
+							if (empty($conf->use_javascript_ajax)) $useajax = 0;
1317
+							if (!empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax = 0;
1318
+							print '<a href="'.(($useinecm && $useajax) ? '#' : ($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1319 1319
 						}
1320 1320
 						print "</td>";
1321 1321
 
@@ -1324,15 +1324,15 @@  discard block
 block discarded – undo
1324 1324
 							if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
1325 1325
 								print '<td align="center" class="linecolmove tdlineupdown">';
1326 1326
 								if ($i > 0) {
1327
-									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>';
1327
+									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default', 0, 'imgupforline').'</a>';
1328 1328
 								}
1329
-								if ($i < $nboffiles-1) {
1330
-									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
1329
+								if ($i < $nboffiles - 1) {
1330
+									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default', 0, 'imgdownforline').'</a>';
1331 1331
 								}
1332 1332
 								print '</td>';
1333 1333
 							}
1334 1334
 							else {
1335
-							   	print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
1335
+							   	print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown"' : ' class="linecolmove"').'>';
1336 1336
 							   	print '</td>';
1337 1337
 							}
1338 1338
 					   }
@@ -1353,8 +1353,8 @@  discard block
 block discarded – undo
1353 1353
 			}
1354 1354
 			if ($nboffiles == 0)
1355 1355
 			{
1356
-				$colspan=(empty($useinecm)?'6':'6');
1357
-				if (empty($disablemove)) $colspan++;		// 6 columns or 7
1356
+				$colspan = (empty($useinecm) ? '6' : '6');
1357
+				if (empty($disablemove)) $colspan++; // 6 columns or 7
1358 1358
 				print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">';
1359 1359
 				if (empty($textifempty)) print $langs->trans("NoFileFound");
1360 1360
 				else print $textifempty;
@@ -1364,15 +1364,15 @@  discard block
 block discarded – undo
1364 1364
 			print '</div>';
1365 1365
 
1366 1366
 			if ($nboflines > 1 && is_object($object)) {
1367
-				if (! empty($conf->use_javascript_ajax) && $permtoeditline) {
1367
+				if (!empty($conf->use_javascript_ajax) && $permtoeditline) {
1368 1368
 					$table_element_line = 'ecm_files';
1369
-					include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1369
+					include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
1370 1370
 				}
1371 1371
 			}
1372 1372
 
1373 1373
 			print ajax_autoselect('downloadlink');
1374 1374
 
1375
-			if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1375
+			if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline)
1376 1376
 			{
1377 1377
 				print '</form>';
1378 1378
 			}
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
 	 *  @return int                 		<0 if KO, nb of files shown if OK
1402 1402
 	 *  @see list_of_documents
1403 1403
 	 */
1404
-	function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0)
1404
+	function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permtodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)
1405 1405
 	{
1406 1406
         // phpcs:enable
1407 1407
 		global $user, $conf, $langs, $form;
@@ -1412,9 +1412,9 @@  discard block
 block discarded – undo
1412 1412
 
1413 1413
 		// Show list of documents
1414 1414
 		if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
1415
-		if (empty($url)) $url=$_SERVER["PHP_SELF"];
1415
+		if (empty($url)) $url = $_SERVER["PHP_SELF"];
1416 1416
 
1417
-		if (! empty($addfilterfields))
1417
+		if (!empty($addfilterfields))
1418 1418
 		{
1419 1419
 			print '<form action="'.$_SERVER['PHP_SELF'].'">';
1420 1420
 			print '<input type="hidden" name="module" value="'.$modulepart.'">';
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
 		print '<div class="div-table-responsive-no-min">';
1424 1424
 		print '<table width="100%" class="noborder">'."\n";
1425 1425
 
1426
-		if (! empty($addfilterfields))
1426
+		if (!empty($addfilterfields))
1427 1427
 		{
1428 1428
 			print '<tr class="liste_titre nodrag nodrop">';
1429 1429
 			print '<td></td>';
@@ -1432,135 +1432,135 @@  discard block
 block discarded – undo
1432 1432
 			print '<td></td>';
1433 1433
 			// Action column
1434 1434
 			print '<td class="liste_titre" align="middle">';
1435
-			$searchpicto=$form->showFilterButtons();
1435
+			$searchpicto = $form->showFilterButtons();
1436 1436
 			print $searchpicto;
1437 1437
 			print '</td>';
1438 1438
 			print "</tr>\n";
1439 1439
 		}
1440 1440
 
1441 1441
 		print '<tr class="liste_titre">';
1442
-		$sortref="fullname";
1443
-		if ($modulepart == 'invoice_supplier') $sortref='level1name';
1444
-		print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
1445
-		print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1446
-		print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1447
-		print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1448
-		print_liste_field_titre('','','');
1442
+		$sortref = "fullname";
1443
+		if ($modulepart == 'invoice_supplier') $sortref = 'level1name';
1444
+		print_liste_field_titre("Ref", $url, $sortref, "", $param, 'align="left"', $sortfield, $sortorder);
1445
+		print_liste_field_titre("Documents2", $url, "name", "", $param, 'align="left"', $sortfield, $sortorder);
1446
+		print_liste_field_titre("Size", $url, "size", "", $param, 'align="right"', $sortfield, $sortorder);
1447
+		print_liste_field_titre("Date", $url, "date", "", $param, 'align="center"', $sortfield, $sortorder);
1448
+		print_liste_field_titre('', '', '');
1449 1449
 		print '</tr>'."\n";
1450 1450
 
1451 1451
 		// To show ref or specific information according to view to show (defined by $module)
1452 1452
 		if ($modulepart == 'company')
1453 1453
 		{
1454 1454
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1455
-			$object_instance=new Societe($this->db);
1455
+			$object_instance = new Societe($this->db);
1456 1456
 		}
1457 1457
 		else if ($modulepart == 'invoice')
1458 1458
 		{
1459 1459
 			include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1460
-			$object_instance=new Facture($this->db);
1460
+			$object_instance = new Facture($this->db);
1461 1461
 		}
1462 1462
 		else if ($modulepart == 'invoice_supplier')
1463 1463
 		{
1464 1464
 			include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1465
-			$object_instance=new FactureFournisseur($this->db);
1465
+			$object_instance = new FactureFournisseur($this->db);
1466 1466
 		}
1467 1467
 		else if ($modulepart == 'propal')
1468 1468
 		{
1469 1469
 			include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1470
-			$object_instance=new Propal($this->db);
1470
+			$object_instance = new Propal($this->db);
1471 1471
 		}
1472 1472
 		else if ($modulepart == 'supplier_proposal')
1473 1473
 		{
1474 1474
 			include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1475
-			$object_instance=new SupplierProposal($this->db);
1475
+			$object_instance = new SupplierProposal($this->db);
1476 1476
 		}
1477 1477
 		else if ($modulepart == 'order')
1478 1478
 		{
1479 1479
 			include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1480
-			$object_instance=new Commande($this->db);
1480
+			$object_instance = new Commande($this->db);
1481 1481
 		}
1482 1482
 		else if ($modulepart == 'order_supplier')
1483 1483
 		{
1484 1484
 			include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1485
-			$object_instance=new CommandeFournisseur($this->db);
1485
+			$object_instance = new CommandeFournisseur($this->db);
1486 1486
 		}
1487 1487
 		else if ($modulepart == 'contract')
1488 1488
 		{
1489 1489
 			include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1490
-			$object_instance=new Contrat($this->db);
1490
+			$object_instance = new Contrat($this->db);
1491 1491
 		}
1492 1492
 		else if ($modulepart == 'product')
1493 1493
 		{
1494 1494
 			include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1495
-			$object_instance=new Product($this->db);
1495
+			$object_instance = new Product($this->db);
1496 1496
 		}
1497 1497
 		else if ($modulepart == 'tax')
1498 1498
 		{
1499 1499
 			include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1500
-			$object_instance=new ChargeSociales($this->db);
1500
+			$object_instance = new ChargeSociales($this->db);
1501 1501
 		}
1502 1502
 		else if ($modulepart == 'project')
1503 1503
 		{
1504 1504
 			include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1505
-			$object_instance=new Project($this->db);
1505
+			$object_instance = new Project($this->db);
1506 1506
 		}
1507 1507
 		else if ($modulepart == 'fichinter')
1508 1508
 		{
1509 1509
 			include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1510
-			$object_instance=new Fichinter($this->db);
1510
+			$object_instance = new Fichinter($this->db);
1511 1511
 		}
1512 1512
 		else if ($modulepart == 'user')
1513 1513
 		{
1514 1514
 			include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1515
-			$object_instance=new User($this->db);
1515
+			$object_instance = new User($this->db);
1516 1516
 		}
1517 1517
 		else if ($modulepart == 'expensereport')
1518 1518
 		{
1519 1519
 			include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1520
-			$object_instance=new ExpenseReport($this->db);
1520
+			$object_instance = new ExpenseReport($this->db);
1521 1521
 		}
1522 1522
 		else if ($modulepart == 'holiday')
1523 1523
 		{
1524 1524
 			include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1525
-			$object_instance=new Holiday($this->db);
1525
+			$object_instance = new Holiday($this->db);
1526 1526
 		}
1527 1527
 
1528
-		foreach($filearray as $key => $file)
1528
+		foreach ($filearray as $key => $file)
1529 1529
 		{
1530 1530
 			if (!is_dir($file['name'])
1531 1531
 			&& $file['name'] != '.'
1532 1532
 			&& $file['name'] != '..'
1533 1533
 			&& $file['name'] != 'CVS'
1534
-			&& ! preg_match('/\.meta$/i',$file['name']))
1534
+			&& !preg_match('/\.meta$/i', $file['name']))
1535 1535
 			{
1536 1536
 				// Define relative path used to store the file
1537
-				$relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
1537
+				$relativefile = preg_replace('/'.preg_quote($upload_dir.'/', '/').'/', '', $file['fullname']);
1538 1538
 
1539 1539
 				//var_dump($file);
1540
-				$id=0; $ref=''; $label='';
1540
+				$id = 0; $ref = ''; $label = '';
1541 1541
 
1542 1542
 				// To show ref or specific information according to view to show (defined by $module)
1543
-				if ($modulepart == 'company')           { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1544
-				if ($modulepart == 'invoice')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1545
-				if ($modulepart == 'invoice_supplier')  { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } }	// $ref may be also id with old supplier invoices
1546
-				if ($modulepart == 'propal')            { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1547
-				if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1548
-				if ($modulepart == 'order')             { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1549
-				if ($modulepart == 'order_supplier')    { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1550
-				if ($modulepart == 'contract')          { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1551
-				if ($modulepart == 'product')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:''); }
1552
-				if ($modulepart == 'tax')               { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1553
-				if ($modulepart == 'project')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1554
-				if ($modulepart == 'fichinter')         { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1555
-				if ($modulepart == 'user')              { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1556
-				if ($modulepart == 'expensereport')     { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1557
-				if ($modulepart == 'holiday')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1558
-
1559
-				if (! $id && ! $ref) continue;
1560
-				$found=0;
1561
-				if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1543
+				if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg); $id = (isset($reg[1]) ? $reg[1] : ''); }
1544
+				if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1545
+				if ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); if (is_numeric($ref)) { $id = $ref; $ref = ''; } }	// $ref may be also id with old supplier invoices
1546
+				if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1547
+				if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1548
+				if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1549
+				if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1550
+				if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1551
+				if ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1552
+				if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg); $id = (isset($reg[1]) ? $reg[1] : ''); }
1553
+				if ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1554
+				if ($modulepart == 'fichinter') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1555
+				if ($modulepart == 'user') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $id = (isset($reg[1]) ? $reg[1] : ''); }
1556
+				if ($modulepart == 'expensereport') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : ''); }
1557
+				if ($modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $id = (isset($reg[1]) ? $reg[1] : ''); }
1558
+
1559
+				if (!$id && !$ref) continue;
1560
+				$found = 0;
1561
+				if (!empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1562 1562
 				{
1563
-					$found=1;
1563
+					$found = 1;
1564 1564
 				}
1565 1565
 				else
1566 1566
 				{
@@ -1579,24 +1579,24 @@  discard block
 block discarded – undo
1579 1579
 					}
1580 1580
 
1581 1581
 					if ($result > 0) {  // Save object into a cache
1582
-						$found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
1582
+						$found = 1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
1583 1583
 					}
1584
-					if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
1584
+					if ($result == 0) { $found = 1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = 'notfound'; unset($filearray[$key]); }
1585 1585
 				}
1586 1586
 
1587
-				if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue;    // We do not show orphelins files
1587
+				if (!$found > 0 || !is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files
1588 1588
 
1589 1589
 				print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
1590 1590
 				print '<tr class="oddeven">';
1591 1591
 				print '<td>';
1592
-				if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1593
-				else print $langs->trans("ObjectDeleted",($id?$id:$ref));
1592
+				if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1, 'document');
1593
+				else print $langs->trans("ObjectDeleted", ($id ? $id : $ref));
1594 1594
 
1595 1595
 				//$modulesubdir=dol_sanitizeFileName($ref);
1596
-				$modulesubdir=dirname($relativefile);
1596
+				$modulesubdir = dirname($relativefile);
1597 1597
 
1598 1598
 				//$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
1599
-				$filedir=$file['path'];
1599
+				$filedir = $file['path'];
1600 1600
 				//$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1601 1601
 				//print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
1602 1602
 
@@ -1608,16 +1608,16 @@  discard block
 block discarded – undo
1608 1608
 				print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1609 1609
 				if ($forcedownload) print '&attachment=1';
1610 1610
 				print '&file='.urlencode($relativefile).'">';
1611
-				print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')');
1612
-				print dol_trunc($file['name'],$maxlength,'middle');
1611
+				print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')');
1612
+				print dol_trunc($file['name'], $maxlength, 'middle');
1613 1613
 				print '</a>';
1614 1614
 
1615 1615
 				//print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
1616 1616
 				print $this->showPreview($file, $modulepart, $file['relativename']);
1617 1617
 
1618 1618
 				print "</td>\n";
1619
-				print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
1620
-				print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
1619
+				print '<td align="right">'.dol_print_size($file['size'], 1, 1).'</td>';
1620
+				print '<td align="center">'.dol_print_date($file['date'], "dayhour").'</td>';
1621 1621
 				print '<td align="right">';
1622 1622
 				//if (! empty($useinecm))  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1623 1623
 				//if ($forcedownload) print '&attachment=1';
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
 		print "</table>";
1640 1640
 		print '</div>';
1641 1641
 
1642
-		if (! empty($addfilterfields)) print '</form>';
1642
+		if (!empty($addfilterfields)) print '</form>';
1643 1643
 		// Fin de zone
1644 1644
 	}
1645 1645
 
@@ -1665,7 +1665,7 @@  discard block
 block discarded – undo
1665 1665
 		$mul_upload_max_filesize	= ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
1666 1666
 		$upload_max_filesize		= $mul_upload_max_filesize * (int) $upload_max_filesize;
1667 1667
 		// Max file size
1668
-		$max_file_size 				= (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
1668
+		$max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
1669 1669
 
1670 1670
 		// Include main
1671 1671
 		include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
@@ -1684,14 +1684,14 @@  discard block
 block discarded – undo
1684 1684
 	 * @param	string		$param			More param to add into URL
1685 1685
 	 * @return 	int							Number of links
1686 1686
 	 */
1687
-	public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
1687
+	public function listOfLinks($object, $permtodelete = 1, $action = null, $selected = null, $param = '')
1688 1688
 	{
1689 1689
 		global $user, $conf, $langs, $user;
1690 1690
 		global $sortfield, $sortorder;
1691 1691
 
1692 1692
 		$langs->load("link");
1693 1693
 
1694
-		require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1694
+		require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1695 1695
 		$link = new Link($this->db);
1696 1696
 		$links = array();
1697 1697
 		if ($sortfield == "name") {
@@ -1702,12 +1702,12 @@  discard block
 block discarded – undo
1702 1702
 			$sortfield = null;
1703 1703
 		}
1704 1704
 		$res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
1705
-		$param .= (isset($object->id)?'&id=' . $object->id : '');
1705
+		$param .= (isset($object->id) ? '&id='.$object->id : '');
1706 1706
 
1707 1707
 		// Show list of associated links
1708 1708
 		print load_fiche_titre($langs->trans("LinkedFiles"));
1709 1709
 
1710
-		print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">';
1710
+		print '<form action="'.$_SERVER['PHP_SELF'].($param ? '?'.$param : '').'" method="POST">';
1711 1711
 
1712 1712
 		print '<table width="100%" class="liste">';
1713 1713
 		print '<tr class="liste_titre">';
@@ -1747,7 +1747,7 @@  discard block
 block discarded – undo
1747 1747
 			$param,
1748 1748
 			'align="center"'
1749 1749
 		);
1750
-		print_liste_field_titre('','','');
1750
+		print_liste_field_titre('', '', '');
1751 1751
 		print '</tr>';
1752 1752
 		$nboflinks = count($links);
1753 1753
 		if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
@@ -1759,36 +1759,36 @@  discard block
 block discarded – undo
1759 1759
 			if ($action == 'update' && $selected === $link->id)
1760 1760
 			{
1761 1761
 				print '<td>';
1762
-				print '<input type="hidden" name="id" value="' . $object->id . '">';
1763
-				print '<input type="hidden" name="linkid" value="' . $link->id . '">';
1762
+				print '<input type="hidden" name="id" value="'.$object->id.'">';
1763
+				print '<input type="hidden" name="linkid" value="'.$link->id.'">';
1764 1764
 				print '<input type="hidden" name="action" value="confirm_updateline">';
1765
-				print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">';
1765
+				print $langs->trans('Link').': <input type="text" name="link" value="'.$link->url.'">';
1766 1766
 				print '</td>';
1767 1767
 				print '<td>';
1768
-				print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">';
1768
+				print $langs->trans('Label').': <input type="text" name="label" value="'.$link->label.'">';
1769 1769
 				print '</td>';
1770
-				print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
1770
+				print '<td align="center">'.dol_print_date(dol_now(), "dayhour", "tzuser").'</td>';
1771 1771
 				print '<td align="right"></td>';
1772 1772
 				print '<td align="right">';
1773
-				print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
1774
-				print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
1773
+				print '<input type="submit" name="save" class="button" value="'.dol_escape_htmltag($langs->trans('Save')).'">';
1774
+				print '<input type="submit" name="cancel" class="button" value="'.dol_escape_htmltag($langs->trans('Cancel')).'">';
1775 1775
 				print '</td>';
1776 1776
 			}
1777 1777
 			else
1778 1778
 			{
1779 1779
 				print '<td>';
1780 1780
 				print img_picto('', 'object_globe').' ';
1781
-				print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
1781
+				print '<a data-ajax="false" href="'.$link->url.'" target="_blank">';
1782 1782
 				print $link->label;
1783 1783
 				print '</a>';
1784 1784
 				print '</td>'."\n";
1785 1785
 				print '<td align="right"></td>';
1786
-				print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>';
1786
+				print '<td align="center">'.dol_print_date($link->datea, "dayhour", "tzuser").'</td>';
1787 1787
 				print '<td align="center"></td>';
1788 1788
 				print '<td align="right">';
1789
-				print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>';	// id= is included into $param
1789
+				print '<a href="'.$_SERVER['PHP_SELF'].'?action=update&linkid='.$link->id.$param.'" class="editfilelink" >'.img_edit().'</a>'; // id= is included into $param
1790 1790
 				if ($permtodelete) {
1791
-					print ' &nbsp; <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>';	// id= is included into $param
1791
+					print ' &nbsp; <a href="'.$_SERVER['PHP_SELF'].'?action=delete&linkid='.$link->id.$param.'" class="deletefilelink">'.img_delete().'</a>'; // id= is included into $param
1792 1792
 				} else {
1793 1793
 					print '&nbsp;';
1794 1794
 				}
@@ -1820,25 +1820,25 @@  discard block
 block discarded – undo
1820 1820
 	 * @param	string	  $param		  More param on http links
1821 1821
 	 * @return  string    $out            Output string with HTML
1822 1822
 	 */
1823
-	public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
1823
+	public function showPreview($file, $modulepart, $relativepath, $ruleforpicto = 0, $param = '')
1824 1824
 	{
1825 1825
 		global $langs, $conf;
1826 1826
 
1827
-		$out='';
1828
-		if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax))
1827
+		$out = '';
1828
+		if ($conf->browser->layout != 'phone' && !empty($conf->use_javascript_ajax))
1829 1829
 		{
1830
-			$urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param);      // Return if a file is qualified for preview.
1830
+			$urladvancedpreview = getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview.
1831 1831
 			if (count($urladvancedpreview))
1832 1832
 			{
1833
-				$out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>';
1833
+				$out .= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime']) ? '' : ' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target']) ? '' : ' target="'.$urladvancedpreview['target'].'"').'>';
1834 1834
 				//$out.= '<a class="pictopreview">';
1835 1835
 				if (empty($ruleforpicto))
1836 1836
 				{
1837 1837
 					//$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
1838
-					$out.='<span class="fa fa-search-plus" style="color: gray"></span>';
1838
+					$out .= '<span class="fa fa-search-plus" style="color: gray"></span>';
1839 1839
 				}
1840
-				else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1841
-				$out.= '</a>';
1840
+				else $out .= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1841
+				$out .= '</a>';
1842 1842
 			}
1843 1843
 		}
1844 1844
 		return $out;
Please login to merge, or discard this patch.
Braces   +404 added lines, -255 removed lines patch added patch discarded remove patch
@@ -84,7 +84,9 @@  discard block
 block discarded – undo
84 84
 		$hookmanager->initHooks(array('formfile'));
85 85
 
86 86
 
87
-		if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0;
87
+		if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') {
88
+		    $useajax=0;
89
+		}
88 90
 
89 91
 		if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
90 92
 		{
@@ -93,8 +95,7 @@  discard block
 block discarded – undo
93 95
 			// TODO: This does not support option savingdocmask
94 96
 			// TODO: This break feature to upload links too
95 97
 			return $this->_formAjaxFileUpload($object);
96
-		}
97
-		else
98
+		} else
98 99
 	   	{
99 100
 			//If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
100 101
 			if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
@@ -105,8 +106,12 @@  discard block
 block discarded – undo
105 106
 
106 107
 			$out = "\n\n<!-- Start form attach new file -->\n";
107 108
 
108
-			if (empty($title)) $title=$langs->trans("AttachANewFile");
109
-			if ($title != 'none') $out.=load_fiche_titre($title, null, null);
109
+			if (empty($title)) {
110
+			    $title=$langs->trans("AttachANewFile");
111
+			}
112
+			if ($title != 'none') {
113
+			    $out.=load_fiche_titre($title, null, null);
114
+			}
110 115
 
111 116
 			$out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
112 117
 			$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
@@ -116,19 +121,31 @@  discard block
 block discarded – undo
116 121
 			$out .= '<table width="100%" class="nobordernopadding">';
117 122
 			$out .= '<tr>';
118 123
 
119
-			if (! empty($options)) $out .= '<td>'.$options.'</td>';
124
+			if (! empty($options)) {
125
+			    $out .= '<td>'.$options.'</td>';
126
+			}
120 127
 
121 128
 			$out .= '<td class="valignmiddle nowrap">';
122 129
 
123 130
 			$max=$conf->global->MAIN_UPLOAD_DOC;		// En Kb
124 131
 			$maxphp=@ini_get('upload_max_filesize');	// En inconnu
125
-			if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1;
126
-			if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
127
-			if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024;
128
-			if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024;
132
+			if (preg_match('/k$/i',$maxphp)) {
133
+			    $maxphp=$maxphp*1;
134
+			}
135
+			if (preg_match('/m$/i',$maxphp)) {
136
+			    $maxphp=$maxphp*1024;
137
+			}
138
+			if (preg_match('/g$/i',$maxphp)) {
139
+			    $maxphp=$maxphp*1024*1024;
140
+			}
141
+			if (preg_match('/t$/i',$maxphp)) {
142
+			    $maxphp=$maxphp*1024*1024*1024;
143
+			}
129 144
 			// Now $max and $maxphp are in Kb
130 145
 			$maxmin = $max;
131
-			if ($maxphp > 0) $maxmin=min($max,$maxphp);
146
+			if ($maxphp > 0) {
147
+			    $maxmin=min($max,$maxphp);
148
+			}
132 149
 
133 150
 			if ($maxmin > 0)
134 151
 			{
@@ -160,8 +177,7 @@  discard block
 block discarded – undo
160 177
 					$out .= ' ';
161 178
 					$out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
162 179
 				}
163
-			}
164
-			else
180
+			} else
165 181
 			{
166 182
 				$out .= ' ('.$langs->trans("UploadDisabled").')';
167 183
 			}
@@ -170,7 +186,9 @@  discard block
 block discarded – undo
170 186
 			if ($savingdocmask)
171 187
 			{
172 188
 				$out .= '<tr>';
173
-   				if (! empty($options)) $out .= '<td>'.$options.'</td>';
189
+   				if (! empty($options)) {
190
+   				    $out .= '<td>'.$options.'</td>';
191
+   				}
174 192
 				$out .= '<td valign="middle" class="nowrap">';
175 193
 				$out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
176 194
 				$out .= '</td>';
@@ -180,7 +198,9 @@  discard block
 block discarded – undo
180 198
 			$out .= "</table>";
181 199
 
182 200
 			$out .= '</form>';
183
-			if (empty($sectionid)) $out .= '<br>';
201
+			if (empty($sectionid)) {
202
+			    $out .= '<br>';
203
+			}
184 204
 
185 205
 			$out .= "\n<!-- End form attach new file -->\n";
186 206
 
@@ -197,11 +217,15 @@  discard block
 block discarded – undo
197 217
 
198 218
 				$out .= '<div class="valignmiddle" >';
199 219
 				$out .= '<div class="inline-block" style="padding-right: 10px;">';
200
-				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
220
+				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) {
221
+				    $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
222
+				}
201 223
 				$out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
202 224
 				$out .= '</div>';
203 225
 				$out .= '<div class="inline-block" style="padding-right: 10px;">';
204
-				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
226
+				if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) {
227
+				    $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
228
+				}
205 229
 				$out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
206 230
 				$out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
207 231
 				$out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
@@ -298,7 +322,9 @@  discard block
 block discarded – undo
298 322
 		global $langs, $conf, $user, $hookmanager;
299 323
 		global $form;
300 324
 
301
-		if (! is_object($form)) $form=new Form($this->db);
325
+		if (! is_object($form)) {
326
+		    $form=new Form($this->db);
327
+		}
302 328
 
303 329
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
304 330
 
@@ -311,10 +337,12 @@  discard block
 block discarded – undo
311 337
 		$param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity);
312 338
 
313 339
 		$printer=0;
314
-		if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison')))	// The direct print feature is implemented only for such elements
340
+		if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison'))) {
341
+		    // The direct print feature is implemented only for such elements
315 342
 		{
316 343
 			$printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
317 344
 		}
345
+		}
318 346
 
319 347
 		$hookmanager->initHooks(array('formfile'));
320 348
 
@@ -324,7 +352,9 @@  discard block
 block discarded – undo
324 352
 		{
325 353
 			$file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC);
326 354
 		}
327
-		if ($hideifempty && empty($file_list)) return '';
355
+		if ($hideifempty && empty($file_list)) {
356
+		    return '';
357
+		}
328 358
 
329 359
 		$out='';
330 360
 		$forname='builddoc';
@@ -361,7 +391,9 @@  discard block
 block discarded – undo
361 391
 		}
362 392
 
363 393
 		$titletoshow=$langs->trans("Documents");
364
-		if (! empty($title)) $titletoshow=$title;
394
+		if (! empty($title)) {
395
+		    $titletoshow=$title;
396
+		}
365 397
 
366 398
 		// Show table
367 399
 		if ($genallowed)
@@ -371,252 +403,251 @@  discard block
 block discarded – undo
371 403
 			if ($modulepart == 'company')
372 404
 			{
373 405
 				$showempty=1;
374
-				if (is_array($genallowed)) $modellist=$genallowed;
375
-				else
406
+				if (is_array($genallowed)) {
407
+				    $modellist=$genallowed;
408
+				} else
376 409
 				{
377 410
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
378 411
 					$modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
379 412
 				}
380
-			}
381
-			else if ($modulepart == 'propal')
413
+			} else if ($modulepart == 'propal')
382 414
 			{
383
-				if (is_array($genallowed)) $modellist=$genallowed;
384
-				else
415
+				if (is_array($genallowed)) {
416
+				    $modellist=$genallowed;
417
+				} else
385 418
 				{
386 419
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
387 420
 					$modellist=ModelePDFPropales::liste_modeles($this->db);
388 421
 				}
389
-			}
390
-			else if ($modulepart == 'supplier_proposal')
422
+			} else if ($modulepart == 'supplier_proposal')
391 423
 			{
392
-				if (is_array($genallowed)) $modellist=$genallowed;
393
-				else
424
+				if (is_array($genallowed)) {
425
+				    $modellist=$genallowed;
426
+				} else
394 427
 				{
395 428
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
396 429
 					$modellist=ModelePDFSupplierProposal::liste_modeles($this->db);
397 430
 				}
398
-			}
399
-			else if ($modulepart == 'commande')
431
+			} else if ($modulepart == 'commande')
400 432
 			{
401
-				if (is_array($genallowed)) $modellist=$genallowed;
402
-				else
433
+				if (is_array($genallowed)) {
434
+				    $modellist=$genallowed;
435
+				} else
403 436
 				{
404 437
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
405 438
 					$modellist=ModelePDFCommandes::liste_modeles($this->db);
406 439
 				}
407
-			}
408
-			elseif ($modulepart == 'expedition')
440
+			} elseif ($modulepart == 'expedition')
409 441
 			{
410
-				if (is_array($genallowed)) $modellist=$genallowed;
411
-				else
442
+				if (is_array($genallowed)) {
443
+				    $modellist=$genallowed;
444
+				} else
412 445
 				{
413 446
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
414 447
 					$modellist=ModelePDFExpedition::liste_modeles($this->db);
415 448
 				}
416
-			}
417
-            elseif ($modulepart == 'reception')
449
+			} elseif ($modulepart == 'reception')
418 450
             {
419
-                if (is_array($genallowed)) $modellist=$genallowed;
420
-                else
451
+                if (is_array($genallowed)) {
452
+                    $modellist=$genallowed;
453
+                } else
421 454
                 {
422 455
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
423 456
 					$modellist = ModelePdfReception::liste_modeles($this->db);
424 457
 				}
425
-            }
426
-			elseif ($modulepart == 'livraison')
458
+            } elseif ($modulepart == 'livraison')
427 459
 			{
428
-				if (is_array($genallowed)) $modellist=$genallowed;
429
-				else
460
+				if (is_array($genallowed)) {
461
+				    $modellist=$genallowed;
462
+				} else
430 463
 				{
431 464
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
432 465
 					$modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
433 466
 				}
434
-			}
435
-			else if ($modulepart == 'ficheinter')
467
+			} else if ($modulepart == 'ficheinter')
436 468
 			{
437
-				if (is_array($genallowed)) $modellist=$genallowed;
438
-				else
469
+				if (is_array($genallowed)) {
470
+				    $modellist=$genallowed;
471
+				} else
439 472
 				{
440 473
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
441 474
 					$modellist=ModelePDFFicheinter::liste_modeles($this->db);
442 475
 				}
443
-			}
444
-			elseif ($modulepart == 'facture')
476
+			} elseif ($modulepart == 'facture')
445 477
 			{
446
-				if (is_array($genallowed)) $modellist=$genallowed;
447
-				else
478
+				if (is_array($genallowed)) {
479
+				    $modellist=$genallowed;
480
+				} else
448 481
 				{
449 482
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
450 483
 					$modellist=ModelePDFFactures::liste_modeles($this->db);
451 484
 				}
452
-			}
453
-			elseif ($modulepart == 'contract')
485
+			} elseif ($modulepart == 'contract')
454 486
 			{
455
-				if (is_array($genallowed)) $modellist=$genallowed;
456
-				else
487
+				if (is_array($genallowed)) {
488
+				    $modellist=$genallowed;
489
+				} else
457 490
 				{
458 491
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
459 492
 					$modellist=ModelePDFContract::liste_modeles($this->db);
460 493
 				}
461
-			}
462
-			elseif ($modulepart == 'project')
494
+			} elseif ($modulepart == 'project')
463 495
 			{
464
-				if (is_array($genallowed)) $modellist=$genallowed;
465
-				else
496
+				if (is_array($genallowed)) {
497
+				    $modellist=$genallowed;
498
+				} else
466 499
 				{
467 500
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
468 501
 					$modellist=ModelePDFProjects::liste_modeles($this->db);
469 502
 				}
470
-			}
471
-			elseif ($modulepart == 'project_task')
503
+			} elseif ($modulepart == 'project_task')
472 504
 			{
473
-				if (is_array($genallowed)) $modellist=$genallowed;
474
-				else
505
+				if (is_array($genallowed)) {
506
+				    $modellist=$genallowed;
507
+				} else
475 508
 				{
476 509
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
477 510
 					$modellist=ModelePDFTask::liste_modeles($this->db);
478 511
 				}
479
-			}
480
-			elseif ($modulepart == 'product')
512
+			} elseif ($modulepart == 'product')
481 513
 			{
482
-				if (is_array($genallowed)) $modellist=$genallowed;
483
-				else
514
+				if (is_array($genallowed)) {
515
+				    $modellist=$genallowed;
516
+				} else
484 517
 				{
485 518
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
486 519
 					$modellist=ModelePDFProduct::liste_modeles($this->db);
487 520
 				}
488
-			}
489
-			elseif ($modulepart == 'product_batch')
521
+			} elseif ($modulepart == 'product_batch')
490 522
 			{
491
-				if (is_array($genallowed)) $modellist=$genallowed;
492
-				else
523
+				if (is_array($genallowed)) {
524
+				    $modellist=$genallowed;
525
+				} else
493 526
 				{
494 527
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
495 528
 					$modellist=ModelePDFProductBatch::liste_modeles($this->db);
496 529
 				}
497
-			}
498
-			elseif ($modulepart == 'stock')
530
+			} elseif ($modulepart == 'stock')
499 531
 			{
500
-				if (is_array($genallowed)) $modellist=$genallowed;
501
-				else
532
+				if (is_array($genallowed)) {
533
+				    $modellist=$genallowed;
534
+				} else
502 535
 				{
503 536
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
504 537
 					$modellist=ModelePDFStock::liste_modeles($this->db);
505 538
 				}
506
-			}
507
-			elseif ($modulepart == 'movement')
539
+			} elseif ($modulepart == 'movement')
508 540
 			{
509
-				if (is_array($genallowed)) $modellist=$genallowed;
510
-				else
541
+				if (is_array($genallowed)) {
542
+				    $modellist=$genallowed;
543
+				} else
511 544
 				{
512 545
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php';
513 546
 					$modellist=ModelePDFMovement::liste_modeles($this->db);
514 547
 				}
515
-			}
516
-			elseif ($modulepart == 'export')
548
+			} elseif ($modulepart == 'export')
517 549
 			{
518
-				if (is_array($genallowed)) $modellist=$genallowed;
519
-				else
550
+				if (is_array($genallowed)) {
551
+				    $modellist=$genallowed;
552
+				} else
520 553
 				{
521 554
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
522 555
 					$modellist=ModeleExports::liste_modeles($this->db);
523 556
 				}
524
-			}
525
-			else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
557
+			} else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
526 558
 			{
527
-				if (is_array($genallowed)) $modellist=$genallowed;
528
-				else
559
+				if (is_array($genallowed)) {
560
+				    $modellist=$genallowed;
561
+				} else
529 562
 				{
530 563
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
531 564
 					$modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
532 565
 				}
533
-			}
534
-			else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
566
+			} else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
535 567
 			{
536
-				if (is_array($genallowed)) $modellist=$genallowed;
537
-				else
568
+				if (is_array($genallowed)) {
569
+				    $modellist=$genallowed;
570
+				} else
538 571
 				{
539 572
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
540 573
 					$modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
541 574
 				}
542
-			}
543
-			else if ($modulepart == 'supplier_payment')
575
+			} else if ($modulepart == 'supplier_payment')
544 576
 			{
545
-				if (is_array($genallowed)) $modellist=$genallowed;
546
-				else
577
+				if (is_array($genallowed)) {
578
+				    $modellist=$genallowed;
579
+				} else
547 580
 				{
548 581
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
549 582
 					$modellist=ModelePDFSuppliersPayments::liste_modeles($this->db);
550 583
 				}
551
-			}
552
-			else if ($modulepart == 'remisecheque')
584
+			} else if ($modulepart == 'remisecheque')
553 585
 			{
554
-				if (is_array($genallowed)) $modellist=$genallowed;
555
-				else
586
+				if (is_array($genallowed)) {
587
+				    $modellist=$genallowed;
588
+				} else
556 589
 				{
557 590
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
558 591
 					$modellist=ModeleChequeReceipts::liste_modeles($this->db);
559 592
 				}
560
-			}
561
-			elseif ($modulepart == 'donation')
593
+			} elseif ($modulepart == 'donation')
562 594
 			{
563
-				if (is_array($genallowed)) $modellist=$genallowed;
564
-				else
595
+				if (is_array($genallowed)) {
596
+				    $modellist=$genallowed;
597
+				} else
565 598
 				{
566 599
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
567 600
 					$modellist=ModeleDon::liste_modeles($this->db);
568 601
 				}
569
-			}
570
-			elseif ($modulepart == 'member')
602
+			} elseif ($modulepart == 'member')
571 603
 			{
572
-				if (is_array($genallowed)) $modellist=$genallowed;
573
-				else
604
+				if (is_array($genallowed)) {
605
+				    $modellist=$genallowed;
606
+				} else
574 607
 				{
575 608
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
576 609
 					$modellist=ModelePDFCards::liste_modeles($this->db);
577 610
 				}
578
-			}
579
-			elseif ($modulepart == 'agenda' || $modulepart == 'actions')
611
+			} elseif ($modulepart == 'agenda' || $modulepart == 'actions')
580 612
 			{
581
-				if (is_array($genallowed)) $modellist=$genallowed;
582
-				else
613
+				if (is_array($genallowed)) {
614
+				    $modellist=$genallowed;
615
+				} else
583 616
 				{
584 617
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
585 618
 					$modellist=ModeleAction::liste_modeles($this->db);
586 619
 				}
587
-			}
588
-			else if ($modulepart == 'expensereport')
620
+			} else if ($modulepart == 'expensereport')
589 621
 			{
590
-				if (is_array($genallowed)) $modellist=$genallowed;
591
-				else
622
+				if (is_array($genallowed)) {
623
+				    $modellist=$genallowed;
624
+				} else
592 625
 				{
593 626
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
594 627
 					$modellist=ModeleExpenseReport::liste_modeles($this->db);
595 628
 				}
596
-			}
597
-			else if ($modulepart == 'unpaid')
629
+			} else if ($modulepart == 'unpaid')
598 630
 			{
599 631
 				$modellist='';
600
-			}
601
-			elseif ($modulepart == 'user')
632
+			} elseif ($modulepart == 'user')
602 633
 			{
603
-				if (is_array($genallowed)) $modellist=$genallowed;
604
-				else
634
+				if (is_array($genallowed)) {
635
+				    $modellist=$genallowed;
636
+				} else
605 637
 				{
606 638
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
607 639
 					$modellist=ModelePDFUser::liste_modeles($this->db);
608 640
 				}
609
-			}
610
-			elseif ($modulepart == 'usergroup')
641
+			} elseif ($modulepart == 'usergroup')
611 642
 			{
612
-				if (is_array($genallowed)) $modellist=$genallowed;
613
-				else
643
+				if (is_array($genallowed)) {
644
+				    $modellist=$genallowed;
645
+				} else
614 646
 				{
615 647
 					include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
616 648
 					$modellist=ModelePDFUserGroup::liste_modeles($this->db);
617 649
 				}
618
-			}
619
-			else
650
+			} else
620 651
 			{
621 652
 				// For normalized standard modules
622 653
 				$file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
@@ -634,8 +665,7 @@  discard block
 block discarded – undo
634 665
 				if (class_exists($class))
635 666
 				{
636 667
 					$modellist=call_user_func($class.'::liste_modeles',$this->db);
637
-				}
638
-				else
668
+				} else
639 669
 				{
640 670
 					dol_print_error($this->db,'Bad value for modulepart');
641 671
 					return -1;
@@ -646,10 +676,17 @@  discard block
 block discarded – undo
646 676
 			$headershown=1;
647 677
 
648 678
 			$buttonlabeltoshow=$buttonlabel;
649
-			if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
679
+			if (empty($buttonlabel)) {
680
+			    $buttonlabel=$langs->trans('Generate');
681
+			}
650 682
 
651
-			if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form';   // So we switch to form after a generation
652
-			if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
683
+			if ($conf->browser->layout == 'phone') {
684
+			    $urlsource.='#'.$forname.'_form';
685
+			}
686
+			// So we switch to form after a generation
687
+			if (empty($noform)) {
688
+			    $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
689
+			}
653 690
 			$out.= '<input type="hidden" name="action" value="builddoc">';
654 691
 			$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
655 692
 
@@ -666,9 +703,11 @@  discard block
 block discarded – undo
666 703
 			if (! empty($modellist))
667 704
 			{
668 705
 				$out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
669
-				if (is_array($modellist) && count($modellist) == 1)    // If there is only one element
706
+				if (is_array($modellist) && count($modellist) == 1) {
707
+				    // If there is only one element
670 708
 				{
671 709
 					$arraykeys=array_keys($modellist);
710
+				}
672 711
 					$modelselected=$arraykeys[0];
673 712
 				}
674 713
 				$out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
@@ -676,8 +715,7 @@  discard block
 block discarded – undo
676 715
 				{
677 716
 					$out.= ajax_combobox('model');
678 717
 				}
679
-			}
680
-			else
718
+			} else
681 719
 			{
682 720
 				$out.= '<div class="float">'.$langs->trans("Files").'</div>';
683 721
 			}
@@ -689,10 +727,11 @@  discard block
 block discarded – undo
689 727
 				$formadmin=new FormAdmin($this->db);
690 728
 				$defaultlang=$codelang?$codelang:$langs->getDefaultLang();
691 729
 				$morecss='maxwidth150';
692
-				if ($conf->browser->layout == 'phone') $morecss='maxwidth100';
730
+				if ($conf->browser->layout == 'phone') {
731
+				    $morecss='maxwidth100';
732
+				}
693 733
 				$out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
694
-			}
695
-			else
734
+			} else
696 735
 			{
697 736
 				$out.= '&nbsp;';
698 737
 			}
@@ -700,15 +739,21 @@  discard block
 block discarded – undo
700 739
 			// Button
701 740
 			$genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
702 741
 			$genbutton.= ' type="submit" value="'.$buttonlabel.'"';
703
-			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled';
742
+			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) {
743
+			    $genbutton.= ' disabled';
744
+			}
704 745
 			$genbutton.= '>';
705 746
 			if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
706 747
 			{
707 748
 			   	$langs->load("errors");
708 749
 			   	$genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
709 750
 			}
710
-			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
711
-			if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton='';
751
+			if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
752
+			    $genbutton='';
753
+			}
754
+			if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') {
755
+			    $genbutton='';
756
+			}
712 757
 			$out.= $genbutton;
713 758
 			$out.= '</th>';
714 759
 
@@ -716,7 +761,9 @@  discard block
 block discarded – undo
716 761
 			{
717 762
 				foreach($hookmanager->hooks['formfile'] as $module)
718 763
 				{
719
-					if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
764
+					if (method_exists($module, 'formBuilddocLineOptions')) {
765
+					    $out .= '<th></th>';
766
+					}
720 767
 				}
721 768
 			}
722 769
 			$out.= '</tr>';
@@ -761,19 +808,30 @@  discard block
 block discarded – undo
761 808
 				{
762 809
 					// Define relative path for download link (depends on module)
763 810
 					$relativepath=$file["name"];										// Cas general
764
-					if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
765
-					if ($modulepart == 'export') $relativepath = $file["name"];			// Other case
811
+					if ($modulesubdir) {
812
+					    $relativepath=$modulesubdir."/".$file["name"];
813
+					}
814
+					// Cas propal, facture...
815
+					if ($modulepart == 'export') {
816
+					    $relativepath = $file["name"];
817
+					}
818
+					// Other case
766 819
 
767 820
 					$out.= '<tr class="oddeven">';
768 821
 
769 822
 					$documenturl = DOL_URL_ROOT.'/document.php';
770
-					if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP;    // To use another wrapper
823
+					if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
824
+					    $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP;
825
+					}
826
+					// To use another wrapper
771 827
 
772 828
 					// Show file name with link to download
773 829
 					$out.= '<td class="minwidth200">';
774 830
 					$out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param?'&'.$param:'').'"';
775 831
 					$mime=dol_mimetype($relativepath,'',0);
776
-					if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
832
+					if (preg_match('/text/',$mime)) {
833
+					    $out.= ' target="_blank"';
834
+					}
777 835
 					$out.= ' target="_blank">';
778 836
 					$out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]);
779 837
 					$out.= dol_trunc($file["name"], 150);
@@ -824,8 +882,10 @@  discard block
 block discarded – undo
824 882
 						{
825 883
 							$out.= $hookmanager->resPrint;		// Complete line
826 884
 							$out.= '</tr>';
885
+						} else {
886
+						    $out = $hookmanager->resPrint;
827 887
 						}
828
-						else $out = $hookmanager->resPrint;		// Replace line
888
+						// Replace line
829 889
 			  		}
830 890
 				}
831 891
 
@@ -847,7 +907,9 @@  discard block
 block discarded – undo
847 907
 					$out.='<td align="right">';
848 908
 					$out.=dol_print_date($file->datea,'dayhour');
849 909
 					$out.='</td>';
850
-					if ($delallowed || $printer || $morepicto) $out.='<td></td>';
910
+					if ($delallowed || $printer || $morepicto) {
911
+					    $out.='<td></td>';
912
+					}
851 913
 					$out.='</tr>'."\n";
852 914
 				}
853 915
 				$this->numoffiles++;
@@ -866,7 +928,9 @@  discard block
 block discarded – undo
866 928
 			$out.= "</div>\n";
867 929
 			if ($genallowed)
868 930
 			{
869
-				if (empty($noform)) $out.= '</form>'."\n";
931
+				if (empty($noform)) {
932
+				    $out.= '</form>'."\n";
933
+				}
870 934
 			}
871 935
 		}
872 936
 		$out.= '<!-- End show_document -->'."\n";
@@ -908,8 +972,7 @@  discard block
 block discarded – undo
908 972
 		if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
909 973
 		{
910 974
 			$filterforfilesearch = preg_quote(basename($modulesubdir),'/');
911
-		}
912
-		else
975
+		} else
913 976
 		{
914 977
 			$filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+';
915 978
 		}
@@ -930,12 +993,18 @@  discard block
 block discarded – undo
930 993
 			foreach($file_list as $file)
931 994
 			{
932 995
 				$i++;
933
-				if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue;	// Discard this. It does not match provided filter.
996
+				if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) {
997
+				    continue;
998
+				}
999
+				// Discard this. It does not match provided filter.
934 1000
 
935 1001
 				$found++;
936 1002
 				// Define relative path for download link (depends on module)
937 1003
 				$relativepath=$file["name"];								// Cas general
938
-				if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"];	// Cas propal, facture...
1004
+				if ($modulesubdir) {
1005
+				    $relativepath=$modulesubdir."/".$file["name"];
1006
+				}
1007
+				// Cas propal, facture...
939 1008
 				// Autre cas
940 1009
 				if ($modulepart == 'donation')            {
941 1010
 					$relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
@@ -947,8 +1016,11 @@  discard block
 block discarded – undo
947 1016
 				$this->infofiles['nboffiles']++;
948 1017
 				$this->infofiles['files'][]=$file['fullname'];
949 1018
 				$ext=pathinfo($file["name"], PATHINFO_EXTENSION);
950
-				if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
951
-				else $this->infofiles['extensions'][$ext]++;
1019
+				if (empty($this->infofiles[$ext])) {
1020
+				    $this->infofiles['extensions'][$ext]=1;
1021
+				} else {
1022
+				    $this->infofiles['extensions'][$ext]++;
1023
+				}
952 1024
 
953 1025
 				// Preview
954 1026
 				if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
@@ -966,7 +1038,9 @@  discard block
 block discarded – undo
966 1038
 				// Download
967 1039
 				$tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
968 1040
 				$mime=dol_mimetype($relativepath,'',0);
969
-				if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
1041
+				if (preg_match('/text/',$mime)) {
1042
+				    $tmpout.= ' target="_blank"';
1043
+				}
970 1044
 				$tmpout.= '>';
971 1045
 				$tmpout.= img_mime($relativepath, $file["name"]);
972 1046
 				$tmpout.= $langs->trans("Download").' '.$ext;
@@ -976,9 +1050,10 @@  discard block
 block discarded – undo
976 1050
 			$out.='</ul></div></dd>
977 1051
     			</dl>';
978 1052
 
979
-			if (! $found) $out='';
980
-		}
981
-		else
1053
+			if (! $found) {
1054
+			    $out='';
1055
+			}
1056
+		} else
982 1057
 		{
983 1058
 			// TODO Add link to regenerate doc ?
984 1059
 			//$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
@@ -1027,14 +1102,21 @@  discard block
 block discarded – undo
1027 1102
 		global $form;
1028 1103
 
1029 1104
 		$disablecrop=1;
1030
-		if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0;
1105
+		if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) {
1106
+		    $disablecrop=0;
1107
+		}
1031 1108
 
1032 1109
 		// Define relative path used to store the file
1033 1110
 		if (empty($relativepath))
1034 1111
 		{
1035 1112
 			$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
1036
-			if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;	// TODO Call using a defined value for $relativepath
1037
-			if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1113
+			if ($object->element == 'invoice_supplier') {
1114
+			    $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath;
1115
+			}
1116
+			// TODO Call using a defined value for $relativepath
1117
+			if ($object->element == 'project_task') {
1118
+			    $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1119
+			}
1038 1120
 		}
1039 1121
 		// For backward compatiblity, we detect file stored into an old path
1040 1122
 		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
@@ -1066,11 +1148,12 @@  discard block
 block discarded – undo
1066 1148
 		);
1067 1149
 		$reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
1068 1150
 
1069
-		if (isset($reshook) && $reshook != '') // null or '' for bypass
1151
+		if (isset($reshook) && $reshook != '') {
1152
+		    // null or '' for bypass
1070 1153
 		{
1071 1154
 			return $reshook;
1072 1155
 		}
1073
-		else
1156
+		} else
1074 1157
 		{
1075 1158
 			if (! is_object($form))
1076 1159
 			{
@@ -1078,17 +1161,27 @@  discard block
 block discarded – undo
1078 1161
 				$form=new Form($this->db);
1079 1162
 			}
1080 1163
 
1081
-			if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id;
1164
+			if (! preg_match('/&id=/', $param) && isset($object->id)) {
1165
+			    $param.='&id='.$object->id;
1166
+			}
1082 1167
 			$relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath);
1083
-			if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend);
1168
+			if ($relativepathwihtoutslashend) {
1169
+			    $param.= '&file='.urlencode($relativepathwihtoutslashend);
1170
+			}
1084 1171
 
1085
-			if ($permtoeditline < 0)  // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1172
+			if ($permtoeditline < 0) {
1173
+			    // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1086 1174
 			{
1087 1175
 				$permtoeditline=0;
1176
+			}
1088 1177
 				if (in_array($modulepart, array('product','produit','service')))
1089 1178
 				{
1090
-					if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1;
1091
-					if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1;
1179
+					if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) {
1180
+					    $permtoeditline=1;
1181
+					}
1182
+					if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) {
1183
+					    $permtoeditline=1;
1184
+					}
1092 1185
 				}
1093 1186
 			}
1094 1187
 			if (empty($conf->global->MAIN_UPLOAD_DOC))
@@ -1098,8 +1191,12 @@  discard block
 block discarded – undo
1098 1191
 			}
1099 1192
 
1100 1193
 			// Show list of existing files
1101
-			if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1102
-			if (empty($url)) $url=$_SERVER["PHP_SELF"];
1194
+			if (empty($useinecm) && $title != 'none') {
1195
+			    print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1196
+			}
1197
+			if (empty($url)) {
1198
+			    $url=$_SERVER["PHP_SELF"];
1199
+			}
1103 1200
 
1104 1201
 			print '<!-- html.formfile::list_of_documents -->'."\n";
1105 1202
 			if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
@@ -1119,10 +1216,14 @@  discard block
 block discarded – undo
1119 1216
 				print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
1120 1217
 				print '<td></td>';
1121 1218
 				print '<td></td>';
1122
-				if (empty($useinecm)) print '<td></td>';
1219
+				if (empty($useinecm)) {
1220
+				    print '<td></td>';
1221
+				}
1123 1222
 				print '<td></td>';
1124 1223
 				print '<td></td>';
1125
-				if (! $disablemove) print '<td></td>';
1224
+				if (! $disablemove) {
1225
+				    print '<td></td>';
1226
+				}
1126 1227
 				print "</tr>\n";
1127 1228
 			}
1128 1229
 
@@ -1131,10 +1232,15 @@  discard block
 block discarded – undo
1131 1232
 			print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1132 1233
 			print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1133 1234
 			print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1134
-			if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');					// Preview
1235
+			if (empty($useinecm)) {
1236
+			    print_liste_field_titre('',$url,"","",$param,'align="center"');
1237
+			}
1238
+			// Preview
1135 1239
 			print_liste_field_titre('');
1136 1240
 			print_liste_field_titre('');
1137
-			if (! $disablemove) print_liste_field_titre('');
1241
+			if (! $disablemove) {
1242
+			    print_liste_field_titre('');
1243
+			}
1138 1244
 			print "</tr>\n";
1139 1245
 
1140 1246
 			// Get list of files stored into database for same relative directory
@@ -1143,23 +1249,29 @@  discard block
 block discarded – undo
1143 1249
 				completeFileArrayWithDatabaseInfo($filearray, $relativedir);
1144 1250
 
1145 1251
 				//var_dump($sortfield.' - '.$sortorder);
1146
-				if ($sortfield && $sortorder)	// If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1252
+				if ($sortfield && $sortorder) {
1253
+				    // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1147 1254
 				{
1148 1255
 					$filearray=dol_sort_array($filearray, $sortfield, $sortorder);
1149 1256
 				}
1257
+				}
1150 1258
 			}
1151 1259
 
1152 1260
 			$nboffiles=count($filearray);
1153
-			if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1261
+			if ($nboffiles > 0) {
1262
+			    include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1263
+			}
1154 1264
 
1155 1265
 			$i=0; $nboflines = 0; $lastrowid=0;
1156
-			foreach($filearray as $key => $file)      // filearray must be only files here
1266
+			foreach($filearray as $key => $file) {
1267
+			    // filearray must be only files here
1157 1268
 			{
1158 1269
 				if ($file['name'] != '.'
1159 1270
 						&& $file['name'] != '..'
1160 1271
 						&& ! preg_match('/\.meta$/i',$file['name']))
1161 1272
 				{
1162 1273
 					if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
1274
+			}
1163 1275
 					$filepath=$relativepath.$file['name'];
1164 1276
 
1165 1277
 					$editline=0;
@@ -1175,12 +1287,18 @@  discard block
 block discarded – undo
1175 1287
 					// Show file name with link to download
1176 1288
 					//print "XX".$file['name'];	//$file['name'] must be utf8
1177 1289
 					print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1178
-					if ($forcedownload) print '&attachment=1';
1179
-					if (! empty($object->entity)) print '&entity='.$object->entity;
1290
+					if ($forcedownload) {
1291
+					    print '&attachment=1';
1292
+					}
1293
+					if (! empty($object->entity)) {
1294
+					    print '&entity='.$object->entity;
1295
+					}
1180 1296
 					print '&file='.urlencode($filepath);
1181 1297
 					print '">';
1182 1298
 					print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
1183
-					if ($showrelpart == 1) print $relativepath;
1299
+					if ($showrelpart == 1) {
1300
+					    print $relativepath;
1301
+					}
1184 1302
 					//print dol_trunc($file['name'],$maxlength,'middle');
1185 1303
 					if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
1186 1304
 					{
@@ -1190,14 +1308,15 @@  discard block
 block discarded – undo
1190 1308
 						print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1191 1309
 						print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1192 1310
 						$editline=1;
1193
-					}
1194
-					else
1311
+					} else
1195 1312
 					{
1196 1313
 						print dol_trunc($file['name'], 200);
1197 1314
 						print '</a>';
1198 1315
 					}
1199 1316
 					// Preview link
1200
-					if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
1317
+					if (! $editline) {
1318
+					    print $this->showPreview($file, $modulepart, $filepath);
1319
+					}
1201 1320
 					// Public share link
1202 1321
 					//if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
1203 1322
 
@@ -1208,8 +1327,9 @@  discard block
 block discarded – undo
1208 1327
 					$sizetoshowbytes = dol_print_size($file['size'],0,1);
1209 1328
 
1210 1329
 					print '<td align="right" width="80px">';
1211
-					if ($sizetoshow == $sizetoshowbytes) print $sizetoshow;
1212
-					else {
1330
+					if ($sizetoshow == $sizetoshowbytes) {
1331
+					    print $sizetoshow;
1332
+					} else {
1213 1333
 						print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
1214 1334
 					}
1215 1335
 					print '</td>';
@@ -1225,7 +1345,10 @@  discard block
 block discarded – undo
1225 1345
 						if (image_format_supported($file['name']) > 0)
1226 1346
 						{
1227 1347
 							$minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1228
-							if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1348
+							if (! dol_is_file($file['path'].'/'.$minifile)) {
1349
+							    $minifile=getImageFileNameForSize($file['name'], '_mini', '.png');
1350
+							}
1351
+							// For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1229 1352
 							//print $file['path'].'/'.$minifile.'<br>';
1230 1353
 
1231 1354
 							$urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity));
@@ -1237,8 +1360,9 @@  discard block
 block discarded – undo
1237 1360
 							}
1238 1361
 							print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
1239 1362
 							print '</a>';
1363
+						} else {
1364
+						    print '&nbsp;';
1240 1365
 						}
1241
-						else print '&nbsp;';
1242 1366
 						print '</td>';
1243 1367
 					}
1244 1368
 
@@ -1250,8 +1374,7 @@  discard block
 block discarded – undo
1250 1374
 						{
1251 1375
 							print $langs->trans("FileSharedViaALink").' ';
1252 1376
 							print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> ';
1253
-						}
1254
-						else
1377
+						} else
1255 1378
 						{
1256 1379
 							if ($file['share'])
1257 1380
 							{
@@ -1263,15 +1386,19 @@  discard block
 block discarded – undo
1263 1386
 								//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1264 1387
 								$forcedownload=0;
1265 1388
 								$paramlink='';
1266
-								if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share'];			// Hash for public share
1267
-								if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
1389
+								if (! empty($file['share'])) {
1390
+								    $paramlink.=($paramlink?'&':'').'hashp='.$file['share'];
1391
+								}
1392
+								// Hash for public share
1393
+								if ($forcedownload) {
1394
+								    $paramlink.=($paramlink?'&':'').'attachment=1';
1395
+								}
1268 1396
 
1269 1397
 								$fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
1270 1398
 
1271 1399
 								print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' ';
1272 1400
 								print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
1273
-							}
1274
-							else
1401
+							} else
1275 1402
 							{
1276 1403
 								//print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1277 1404
 							}
@@ -1292,7 +1419,9 @@  discard block
 block discarded – undo
1292 1419
 						if (! $useinecm || $useinecm == 2)
1293 1420
 						{
1294 1421
 							$newmodulepart=$modulepart;
1295
-							if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
1422
+							if (in_array($modulepart, array('product','produit','service'))) {
1423
+							    $newmodulepart='produit|service';
1424
+							}
1296 1425
 
1297 1426
 							if (! $disablecrop && image_format_supported($file['name']) > 0)
1298 1427
 							{
@@ -1312,9 +1441,15 @@  discard block
 block discarded – undo
1312 1441
 						if ($permonobject)
1313 1442
 						{
1314 1443
 							$useajax=1;
1315
-							if (! empty($conf->dol_use_jmobile)) $useajax=0;
1316
-							if (empty($conf->use_javascript_ajax)) $useajax=0;
1317
-							if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
1444
+							if (! empty($conf->dol_use_jmobile)) {
1445
+							    $useajax=0;
1446
+							}
1447
+							if (empty($conf->use_javascript_ajax)) {
1448
+							    $useajax=0;
1449
+							}
1450
+							if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) {
1451
+							    $useajax=0;
1452
+							}
1318 1453
 							print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1319 1454
 						}
1320 1455
 						print "</td>";
@@ -1330,21 +1465,21 @@  discard block
 block discarded – undo
1330 1465
 									print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
1331 1466
 								}
1332 1467
 								print '</td>';
1333
-							}
1334
-							else {
1468
+							} else {
1335 1469
 							   	print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
1336 1470
 							   	print '</td>';
1337 1471
 							}
1338 1472
 					   }
1339
-					}
1340
-					else
1473
+					} else
1341 1474
 					{
1342 1475
 						print '<td class="right">';
1343 1476
 						print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">';
1344 1477
 						print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1345 1478
 						print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1346 1479
 						print '</td>';
1347
-						if (empty($disablemove)) print '<td class="right"></td>';
1480
+						if (empty($disablemove)) {
1481
+						    print '<td class="right"></td>';
1482
+						}
1348 1483
 					}
1349 1484
 					print "</tr>\n";
1350 1485
 
@@ -1354,10 +1489,16 @@  discard block
 block discarded – undo
1354 1489
 			if ($nboffiles == 0)
1355 1490
 			{
1356 1491
 				$colspan=(empty($useinecm)?'6':'6');
1357
-				if (empty($disablemove)) $colspan++;		// 6 columns or 7
1492
+				if (empty($disablemove)) {
1493
+				    $colspan++;
1494
+				}
1495
+				// 6 columns or 7
1358 1496
 				print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">';
1359
-				if (empty($textifempty)) print $langs->trans("NoFileFound");
1360
-				else print $textifempty;
1497
+				if (empty($textifempty)) {
1498
+				    print $langs->trans("NoFileFound");
1499
+				} else {
1500
+				    print $textifempty;
1501
+				}
1361 1502
 				print '</td></tr>';
1362 1503
 			}
1363 1504
 			print "</table>";
@@ -1411,8 +1552,12 @@  discard block
 block discarded – undo
1411 1552
 		dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1412 1553
 
1413 1554
 		// Show list of documents
1414
-		if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
1415
-		if (empty($url)) $url=$_SERVER["PHP_SELF"];
1555
+		if (empty($useinecm)) {
1556
+		    print load_fiche_titre($langs->trans("AttachedFiles"));
1557
+		}
1558
+		if (empty($url)) {
1559
+		    $url=$_SERVER["PHP_SELF"];
1560
+		}
1416 1561
 
1417 1562
 		if (! empty($addfilterfields))
1418 1563
 		{
@@ -1440,7 +1585,9 @@  discard block
 block discarded – undo
1440 1585
 
1441 1586
 		print '<tr class="liste_titre">';
1442 1587
 		$sortref="fullname";
1443
-		if ($modulepart == 'invoice_supplier') $sortref='level1name';
1588
+		if ($modulepart == 'invoice_supplier') {
1589
+		    $sortref='level1name';
1590
+		}
1444 1591
 		print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
1445 1592
 		print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1446 1593
 		print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder);
@@ -1453,73 +1600,59 @@  discard block
 block discarded – undo
1453 1600
 		{
1454 1601
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1455 1602
 			$object_instance=new Societe($this->db);
1456
-		}
1457
-		else if ($modulepart == 'invoice')
1603
+		} else if ($modulepart == 'invoice')
1458 1604
 		{
1459 1605
 			include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1460 1606
 			$object_instance=new Facture($this->db);
1461
-		}
1462
-		else if ($modulepart == 'invoice_supplier')
1607
+		} else if ($modulepart == 'invoice_supplier')
1463 1608
 		{
1464 1609
 			include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1465 1610
 			$object_instance=new FactureFournisseur($this->db);
1466
-		}
1467
-		else if ($modulepart == 'propal')
1611
+		} else if ($modulepart == 'propal')
1468 1612
 		{
1469 1613
 			include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1470 1614
 			$object_instance=new Propal($this->db);
1471
-		}
1472
-		else if ($modulepart == 'supplier_proposal')
1615
+		} else if ($modulepart == 'supplier_proposal')
1473 1616
 		{
1474 1617
 			include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1475 1618
 			$object_instance=new SupplierProposal($this->db);
1476
-		}
1477
-		else if ($modulepart == 'order')
1619
+		} else if ($modulepart == 'order')
1478 1620
 		{
1479 1621
 			include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1480 1622
 			$object_instance=new Commande($this->db);
1481
-		}
1482
-		else if ($modulepart == 'order_supplier')
1623
+		} else if ($modulepart == 'order_supplier')
1483 1624
 		{
1484 1625
 			include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1485 1626
 			$object_instance=new CommandeFournisseur($this->db);
1486
-		}
1487
-		else if ($modulepart == 'contract')
1627
+		} else if ($modulepart == 'contract')
1488 1628
 		{
1489 1629
 			include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1490 1630
 			$object_instance=new Contrat($this->db);
1491
-		}
1492
-		else if ($modulepart == 'product')
1631
+		} else if ($modulepart == 'product')
1493 1632
 		{
1494 1633
 			include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1495 1634
 			$object_instance=new Product($this->db);
1496
-		}
1497
-		else if ($modulepart == 'tax')
1635
+		} else if ($modulepart == 'tax')
1498 1636
 		{
1499 1637
 			include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1500 1638
 			$object_instance=new ChargeSociales($this->db);
1501
-		}
1502
-		else if ($modulepart == 'project')
1639
+		} else if ($modulepart == 'project')
1503 1640
 		{
1504 1641
 			include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1505 1642
 			$object_instance=new Project($this->db);
1506
-		}
1507
-		else if ($modulepart == 'fichinter')
1643
+		} else if ($modulepart == 'fichinter')
1508 1644
 		{
1509 1645
 			include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1510 1646
 			$object_instance=new Fichinter($this->db);
1511
-		}
1512
-		else if ($modulepart == 'user')
1647
+		} else if ($modulepart == 'user')
1513 1648
 		{
1514 1649
 			include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1515 1650
 			$object_instance=new User($this->db);
1516
-		}
1517
-		else if ($modulepart == 'expensereport')
1651
+		} else if ($modulepart == 'expensereport')
1518 1652
 		{
1519 1653
 			include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1520 1654
 			$object_instance=new ExpenseReport($this->db);
1521
-		}
1522
-		else if ($modulepart == 'holiday')
1655
+		} else if ($modulepart == 'holiday')
1523 1656
 		{
1524 1657
 			include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1525 1658
 			$object_instance=new Holiday($this->db);
@@ -1556,13 +1689,14 @@  discard block
 block discarded – undo
1556 1689
 				if ($modulepart == 'expensereport')     { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $ref=(isset($reg[1])?$reg[1]:'');}
1557 1690
 				if ($modulepart == 'holiday')           { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);  $id=(isset($reg[1])?$reg[1]:'');}
1558 1691
 
1559
-				if (! $id && ! $ref) continue;
1692
+				if (! $id && ! $ref) {
1693
+				    continue;
1694
+				}
1560 1695
 				$found=0;
1561 1696
 				if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1562 1697
 				{
1563 1698
 					$found=1;
1564
-				}
1565
-				else
1699
+				} else
1566 1700
 				{
1567 1701
 					//print 'Fetch '.$id." - ".$ref.'<br>';
1568 1702
 
@@ -1584,13 +1718,19 @@  discard block
 block discarded – undo
1584 1718
 					if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
1585 1719
 				}
1586 1720
 
1587
-				if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue;    // We do not show orphelins files
1721
+				if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) {
1722
+				    continue;
1723
+				}
1724
+				// We do not show orphelins files
1588 1725
 
1589 1726
 				print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
1590 1727
 				print '<tr class="oddeven">';
1591 1728
 				print '<td>';
1592
-				if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1593
-				else print $langs->trans("ObjectDeleted",($id?$id:$ref));
1729
+				if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) {
1730
+				    print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1731
+				} else {
1732
+				    print $langs->trans("ObjectDeleted",($id?$id:$ref));
1733
+				}
1594 1734
 
1595 1735
 				//$modulesubdir=dol_sanitizeFileName($ref);
1596 1736
 				$modulesubdir=dirname($relativefile);
@@ -1606,7 +1746,9 @@  discard block
 block discarded – undo
1606 1746
 				print '<td>';
1607 1747
 				//print "XX".$file['name']; //$file['name'] must be utf8
1608 1748
 				print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1609
-				if ($forcedownload) print '&attachment=1';
1749
+				if ($forcedownload) {
1750
+				    print '&attachment=1';
1751
+				}
1610 1752
 				print '&file='.urlencode($relativefile).'">';
1611 1753
 				print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')');
1612 1754
 				print dol_trunc($file['name'],$maxlength,'middle');
@@ -1632,14 +1774,19 @@  discard block
 block discarded – undo
1632 1774
 		if (count($filearray) == 0)
1633 1775
 		{
1634 1776
 			print '<tr class="oddeven"><td colspan="5">';
1635
-			if (empty($textifempty)) print $langs->trans("NoFileFound");
1636
-			else print $textifempty;
1777
+			if (empty($textifempty)) {
1778
+			    print $langs->trans("NoFileFound");
1779
+			} else {
1780
+			    print $textifempty;
1781
+			}
1637 1782
 			print '</td></tr>';
1638 1783
 		}
1639 1784
 		print "</table>";
1640 1785
 		print '</div>';
1641 1786
 
1642
-		if (! empty($addfilterfields)) print '</form>';
1787
+		if (! empty($addfilterfields)) {
1788
+		    print '</form>';
1789
+		}
1643 1790
 		// Fin de zone
1644 1791
 	}
1645 1792
 
@@ -1750,7 +1897,9 @@  discard block
 block discarded – undo
1750 1897
 		print_liste_field_titre('','','');
1751 1898
 		print '</tr>';
1752 1899
 		$nboflinks = count($links);
1753
-		if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1900
+		if ($nboflinks > 0) {
1901
+		    include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1902
+		}
1754 1903
 
1755 1904
 		foreach ($links as $link)
1756 1905
 		{
@@ -1773,8 +1922,7 @@  discard block
 block discarded – undo
1773 1922
 				print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
1774 1923
 				print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
1775 1924
 				print '</td>';
1776
-			}
1777
-			else
1925
+			} else
1778 1926
 			{
1779 1927
 				print '<td>';
1780 1928
 				print img_picto('', 'object_globe').' ';
@@ -1836,8 +1984,9 @@  discard block
 block discarded – undo
1836 1984
 				{
1837 1985
 					//$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
1838 1986
 					$out.='<span class="fa fa-search-plus" style="color: gray"></span>';
1987
+				} else {
1988
+				    $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1839 1989
 				}
1840
-				else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1841 1990
 				$out.= '</a>';
1842 1991
 			}
1843 1992
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formaccounting.class.php 3 patches
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -33,110 +33,110 @@  discard block
 block discarded – undo
33 33
 class FormAccounting extends Form
34 34
 {
35 35
 
36
-	private $options_cache = array();
36
+    private $options_cache = array();
37 37
 
38
-	/**
38
+    /**
39 39
      * @var DoliDB Database handler.
40 40
      */
41 41
     public $db;
42 42
 
43
-	/**
44
-	 * @var string Error code (or message)
45
-	 */
46
-	public $error='';
47
-
48
-   /**
49
-	* Constructor
50
-	*
51
-	* @param		DoliDB		$db      Database handler
52
-	*/
53
-	public function __construct($db)
54
-	{
55
-	    $this->db = $db;
56
-	}
43
+    /**
44
+     * @var string Error code (or message)
45
+     */
46
+    public $error='';
47
+
48
+    /**
49
+     * Constructor
50
+     *
51
+     * @param		DoliDB		$db      Database handler
52
+     */
53
+    public function __construct($db)
54
+    {
55
+        $this->db = $db;
56
+    }
57 57
 
58 58
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
59
-	/**
60
-	 * Return list of journals with label by nature
61
-	 *
62
-	 * @param	string	$selectid	Preselected pcg_type
63
-	 * @param	string	$htmlname	Name of field in html form
64
-	 * @param	int		$nature		Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
65
-	 * @param	int		$showempty	Add an empty field
66
-	 * @param	int		$select_in	0=selectid value is the journal rowid (default) or 1=selectid is journal code
67
-	 * @param	int		$select_out	Set value returned by select. 0=rowid (default), 1=code
68
-	 * @param	string	$morecss	More css non HTML object
69
-	 * @param	string	$usecache	Key to use to store result into a cache. Next call with same key will reuse the cache.
70
-	 * @param   int     $disabledajaxcombo Disable ajax combo box.
71
-	 * @return	string				String with HTML select
72
-	 */
73
-	function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='', $disabledajaxcombo=0)
74
-	{
59
+    /**
60
+     * Return list of journals with label by nature
61
+     *
62
+     * @param	string	$selectid	Preselected pcg_type
63
+     * @param	string	$htmlname	Name of field in html form
64
+     * @param	int		$nature		Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
65
+     * @param	int		$showempty	Add an empty field
66
+     * @param	int		$select_in	0=selectid value is the journal rowid (default) or 1=selectid is journal code
67
+     * @param	int		$select_out	Set value returned by select. 0=rowid (default), 1=code
68
+     * @param	string	$morecss	More css non HTML object
69
+     * @param	string	$usecache	Key to use to store result into a cache. Next call with same key will reuse the cache.
70
+     * @param   int     $disabledajaxcombo Disable ajax combo box.
71
+     * @return	string				String with HTML select
72
+     */
73
+    function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='', $disabledajaxcombo=0)
74
+    {
75 75
         // phpcs:enable
76
-		global $conf,$langs;
77
-
78
-		$out = '';
79
-
80
-    	$options = array();
81
-		if ($usecache && ! empty($this->options_cache[$usecache]))
82
-		{
83
-		    $options = $this->options_cache[$usecache];
84
-		    $selected=$selectid;
85
-		}
86
-		else
87
-		{
88
-			$sql = "SELECT rowid, code, label, nature, entity, active";
89
-			$sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal";
90
-			$sql.= " WHERE active = 1";
91
-			$sql.= " AND entity = ".$conf->entity;
92
-			//if ($nature && is_numeric($nature))   $sql .= " AND nature = ".$nature;
93
-			$sql.= " ORDER BY code";
94
-
95
-			dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG);
96
-			$resql = $this->db->query($sql);
97
-
98
-			if (!$resql) {
99
-				$this->error = "Error ".$this->db->lasterror();
100
-				dol_syslog(get_class($this)."::select_journal ".$this->error, LOG_ERR);
101
-				return -1;
102
-			}
103
-
104
-    		$selected = 0;
105
-			$langs->load('accountancy');
106
-			while ($obj = $this->db->fetch_object($resql))
107
-			{
108
-				$label = $obj->code . ' - ' . $langs->trans($obj->label);
109
-
110
-    			$select_value_in = $obj->rowid;
111
-				$select_value_out = $obj->rowid;
112
-
113
-				// Try to guess if we have found default value
114
-    			if ($select_in == 1) {
115
-    				$select_value_in = $obj->code;
116
-    			}
117
-    			if ($select_out == 1) {
118
-    				$select_value_out = $obj->code;
119
-    			}
120
-    			// Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid
121
-    			if ($selectid != '' && $selectid == $select_value_in) {
122
-    			    //var_dump("Found ".$selectid." ".$select_value_in);
123
-    				$selected = $select_value_out;
124
-    			}
125
-
126
-				$options[$select_value_out] = $label;
127
-			}
128
-			$this->db->free($resql);
129
-
130
-			if ($usecache)
131
-			{
132
-				$this->options_cache[$usecache] = $options;
133
-			}
134
-		}
135
-
136
-		$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, ($disabledajaxcombo?0:1));
137
-
138
-		return $out;
139
-	}
76
+        global $conf,$langs;
77
+
78
+        $out = '';
79
+
80
+        $options = array();
81
+        if ($usecache && ! empty($this->options_cache[$usecache]))
82
+        {
83
+            $options = $this->options_cache[$usecache];
84
+            $selected=$selectid;
85
+        }
86
+        else
87
+        {
88
+            $sql = "SELECT rowid, code, label, nature, entity, active";
89
+            $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal";
90
+            $sql.= " WHERE active = 1";
91
+            $sql.= " AND entity = ".$conf->entity;
92
+            //if ($nature && is_numeric($nature))   $sql .= " AND nature = ".$nature;
93
+            $sql.= " ORDER BY code";
94
+
95
+            dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG);
96
+            $resql = $this->db->query($sql);
97
+
98
+            if (!$resql) {
99
+                $this->error = "Error ".$this->db->lasterror();
100
+                dol_syslog(get_class($this)."::select_journal ".$this->error, LOG_ERR);
101
+                return -1;
102
+            }
103
+
104
+            $selected = 0;
105
+            $langs->load('accountancy');
106
+            while ($obj = $this->db->fetch_object($resql))
107
+            {
108
+                $label = $obj->code . ' - ' . $langs->trans($obj->label);
109
+
110
+                $select_value_in = $obj->rowid;
111
+                $select_value_out = $obj->rowid;
112
+
113
+                // Try to guess if we have found default value
114
+                if ($select_in == 1) {
115
+                    $select_value_in = $obj->code;
116
+                }
117
+                if ($select_out == 1) {
118
+                    $select_value_out = $obj->code;
119
+                }
120
+                // Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid
121
+                if ($selectid != '' && $selectid == $select_value_in) {
122
+                    //var_dump("Found ".$selectid." ".$select_value_in);
123
+                    $selected = $select_value_out;
124
+                }
125
+
126
+                $options[$select_value_out] = $label;
127
+            }
128
+            $this->db->free($resql);
129
+
130
+            if ($usecache)
131
+            {
132
+                $this->options_cache[$usecache] = $options;
133
+            }
134
+        }
135
+
136
+        $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, ($disabledajaxcombo?0:1));
137
+
138
+        return $out;
139
+    }
140 140
 
141 141
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
142 142
     /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
             $sql = "SELECT c.rowid, c.label as type, c.range_account";
168 168
             $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
169 169
             $sql.= " WHERE c.active = 1";
170
-			$sql.= " AND c.category_type = 0";
170
+            $sql.= " AND c.category_type = 0";
171 171
             if (empty($allcountries)) $sql.= " AND c.fk_country = ".$mysoc->country_id;
172 172
             $sql.= " ORDER BY c.label ASC";
173 173
         }
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
             $sql = "SELECT c.rowid, c.label as type, c.range_account";
177 177
             $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co";
178 178
             $sql.= " WHERE c.active = 1";
179
-			$sql.= " AND c.category_type = 0";
180
-			$sql.= " AND c.fk_country = co.rowid";
179
+            $sql.= " AND c.category_type = 0";
180
+            $sql.= " AND c.fk_country = co.rowid";
181 181
             if (empty($allcountries)) $sql.= " AND co.code = '".$mysoc->country_code."'";
182 182
             $sql.= " ORDER BY c.label ASC";
183 183
         }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                     $out .= '<option value="'.$obj->rowid.'"';
200 200
                     if ($obj->rowid == $selected) $out .= ' selected';
201 201
                     $out .= '>'.($maxlen ? dol_trunc($obj->type,$maxlen) : $obj->type);
202
-					$out .= ' ('.$obj->range_account.')';
202
+                    $out .= ' ('.$obj->range_account.')';
203 203
                     $i++;
204 204
                 }
205 205
                 $out .=  '</select>';
@@ -221,231 +221,231 @@  discard block
 block discarded – undo
221 221
     }
222 222
 
223 223
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
224
-	/**
225
-	 * Return select filter with date of transaction
226
-	 *
227
-	 * @param string $htmlname Name of select field
228
-	 * @param string $selectedkey Value
229
-	 * @return string HTML edit field
230
-	 */
224
+    /**
225
+     * Return select filter with date of transaction
226
+     *
227
+     * @param string $htmlname Name of select field
228
+     * @param string $selectedkey Value
229
+     * @return string HTML edit field
230
+     */
231 231
     function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '')
232 232
     {
233 233
         // phpcs:enable
234
-		$options = array();
234
+        $options = array();
235 235
 
236
-		$sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
237
-	    $sql .= " WHERE entity IN (".getEntity('accountancy').")";
238
-		$sql .= ' ORDER BY import_key DESC';
236
+        $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
237
+        $sql .= " WHERE entity IN (".getEntity('accountancy').")";
238
+        $sql .= ' ORDER BY import_key DESC';
239 239
 
240
-		dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
241
-		$resql = $this->db->query($sql);
240
+        dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
241
+        $resql = $this->db->query($sql);
242 242
 
243
-		if (!$resql) {
244
-			$this->error = "Error " . $this->db->lasterror();
245
-			dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
246
-			return - 1;
247
-		}
243
+        if (!$resql) {
244
+            $this->error = "Error " . $this->db->lasterror();
245
+            dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
246
+            return - 1;
247
+        }
248 248
 
249
-		while ($obj = $this->db->fetch_object($resql)) {
250
-			$options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext');
251
-		}
249
+        while ($obj = $this->db->fetch_object($resql)) {
250
+            $options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext');
251
+        }
252 252
 
253
-		return Form::selectarray($htmlname, $options, $selectedkey);
254
-	}
253
+        return Form::selectarray($htmlname, $options, $selectedkey);
254
+    }
255 255
 
256 256
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
257
-	/**
258
-	 * Return list of accounts with label by chart of accounts
259
-	 *
260
-	 * @param string   $selectid           Preselected id or code of accounting accounts (depends on $select_in)
261
-	 * @param string   $htmlname           Name of HTML field id. If name start with '.', it is name of HTML css class, so several component with same name in different forms can be used.
262
-	 * @param int      $showempty          1=Add an empty field, 2=Add an empty field+'None' field
263
-	 * @param array    $event              Event options
264
-	 * @param int      $select_in          0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number
265
-	 * @param int      $select_out         Set value returned by select. 0=rowid (default), 1=account_number
266
-	 * @param string   $morecss            More css non HTML object
267
-	 * @param string   $usecache           Key to use to store result into a cache. Next call with same key will reuse the cache.
268
-	 * @return string                      String with HTML select
269
-	 */
270
-	function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
271
-	{
257
+    /**
258
+     * Return list of accounts with label by chart of accounts
259
+     *
260
+     * @param string   $selectid           Preselected id or code of accounting accounts (depends on $select_in)
261
+     * @param string   $htmlname           Name of HTML field id. If name start with '.', it is name of HTML css class, so several component with same name in different forms can be used.
262
+     * @param int      $showempty          1=Add an empty field, 2=Add an empty field+'None' field
263
+     * @param array    $event              Event options
264
+     * @param int      $select_in          0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number
265
+     * @param int      $select_out         Set value returned by select. 0=rowid (default), 1=account_number
266
+     * @param string   $morecss            More css non HTML object
267
+     * @param string   $usecache           Key to use to store result into a cache. Next call with same key will reuse the cache.
268
+     * @return string                      String with HTML select
269
+     */
270
+    function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
271
+    {
272 272
         // phpcs:enable
273
-		global $conf, $langs;
274
-
275
-		require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
276
-
277
-		$out = '';
278
-
279
-    	$options = array();
280
-		if ($usecache && ! empty($this->options_cache[$usecache]))
281
-		{
282
-		    $options = $this->options_cache[$usecache];
283
-		    $selected=$selectid;
284
-		}
285
-		else
286
-		{
287
-    		$trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT;
288
-
289
-    		$sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
290
-    		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
291
-    		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
292
-    		$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
293
-    		$sql .= " AND aa.active = 1";
294
-    		$sql .= " AND aa.entity=".$conf->entity;
295
-    		$sql .= " ORDER BY aa.account_number";
296
-
297
-    		dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
298
-    		$resql = $this->db->query($sql);
299
-
300
-    		if (!$resql) {
301
-    			$this->error = "Error " . $this->db->lasterror();
302
-    			dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
303
-    			return -1;
304
-    		}
305
-
306
-    		$selected = 0;
307
-    		while ($obj = $this->db->fetch_object($resql))
308
-    		{
309
-    			$label = length_accountg($obj->account_number) . ' - ' . $obj->label;
310
-    			$label = dol_trunc($label, $trunclength);
311
-
312
-    			$select_value_in = $obj->rowid;
313
-    			$select_value_out = $obj->rowid;
314
-
315
-    			// Try to guess if we have found default value
316
-    			if ($select_in == 1) {
317
-    				$select_value_in = $obj->account_number;
318
-    			}
319
-    			if ($select_out == 1) {
320
-    				$select_value_out = $obj->account_number;
321
-    			}
322
-    			// Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
323
-    			// Because same account_number can be share between different accounting_system and do have the same meaning
324
-    			if ($selectid != '' && $selectid == $select_value_in) {
325
-    			    //var_dump("Found ".$selectid." ".$select_value_in);
326
-    				$selected = $select_value_out;
327
-    			}
328
-
329
-    			$options[$select_value_out] = $label;
330
-    		}
331
-    		$this->db->free($resql);
332
-
333
-    		if ($usecache)
334
-    		{
273
+        global $conf, $langs;
274
+
275
+        require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
276
+
277
+        $out = '';
278
+
279
+        $options = array();
280
+        if ($usecache && ! empty($this->options_cache[$usecache]))
281
+        {
282
+            $options = $this->options_cache[$usecache];
283
+            $selected=$selectid;
284
+        }
285
+        else
286
+        {
287
+            $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT;
288
+
289
+            $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
290
+            $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
291
+            $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
292
+            $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
293
+            $sql .= " AND aa.active = 1";
294
+            $sql .= " AND aa.entity=".$conf->entity;
295
+            $sql .= " ORDER BY aa.account_number";
296
+
297
+            dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
298
+            $resql = $this->db->query($sql);
299
+
300
+            if (!$resql) {
301
+                $this->error = "Error " . $this->db->lasterror();
302
+                dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
303
+                return -1;
304
+            }
305
+
306
+            $selected = 0;
307
+            while ($obj = $this->db->fetch_object($resql))
308
+            {
309
+                $label = length_accountg($obj->account_number) . ' - ' . $obj->label;
310
+                $label = dol_trunc($label, $trunclength);
311
+
312
+                $select_value_in = $obj->rowid;
313
+                $select_value_out = $obj->rowid;
314
+
315
+                // Try to guess if we have found default value
316
+                if ($select_in == 1) {
317
+                    $select_value_in = $obj->account_number;
318
+                }
319
+                if ($select_out == 1) {
320
+                    $select_value_out = $obj->account_number;
321
+                }
322
+                // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
323
+                // Because same account_number can be share between different accounting_system and do have the same meaning
324
+                if ($selectid != '' && $selectid == $select_value_in) {
325
+                    //var_dump("Found ".$selectid." ".$select_value_in);
326
+                    $selected = $select_value_out;
327
+                }
328
+
329
+                $options[$select_value_out] = $label;
330
+            }
331
+            $this->db->free($resql);
332
+
333
+            if ($usecache)
334
+            {
335 335
                 $this->options_cache[$usecache] = $options;
336
-    		}
337
-		}
336
+            }
337
+        }
338 338
 
339
-		if ($showempty == 2)
340
-		{
341
-			$options['0'] = $langs->trans("None");
342
-		}
339
+        if ($showempty == 2)
340
+        {
341
+            $options['0'] = $langs->trans("None");
342
+        }
343 343
 
344
-		$out .= Form::selectarray($htmlname, $options, $selected, ($showempty > 0 ? 1 : 0), 0, 0, '', 0, 0, 0, '', $morecss, 1);
344
+        $out .= Form::selectarray($htmlname, $options, $selected, ($showempty > 0 ? 1 : 0), 0, 0, '', 0, 0, 0, '', $morecss, 1);
345 345
 
346
-		return $out;
347
-	}
346
+        return $out;
347
+    }
348 348
 
349 349
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
350
-	/**
351
-	 * Return list of auxilary thirdparty accounts
352
-	 *
353
-	 * @param string   $selectid       Preselected pcg_type
354
-	 * @param string   $htmlname       Name of field in html form
355
-	 * @param int      $showempty      Add an empty field
356
-	 * @param string   $morecss        More css
357
-	 * @return string                  String with HTML select
358
-	 */
350
+    /**
351
+     * Return list of auxilary thirdparty accounts
352
+     *
353
+     * @param string   $selectid       Preselected pcg_type
354
+     * @param string   $htmlname       Name of field in html form
355
+     * @param int      $showempty      Add an empty field
356
+     * @param string   $morecss        More css
357
+     * @return string                  String with HTML select
358
+     */
359 359
     function select_auxaccount($selectid, $htmlname='account_num_aux', $showempty=0, $morecss='maxwidth200')
360 360
     {
361 361
         // phpcs:enable
362 362
 
363
-		$aux_account = array();
364
-
365
-		// Auxiliary customer account
366
-		$sql = "SELECT DISTINCT code_compta, nom ";
367
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
368
-	    $sql .= " WHERE entity IN (" . getEntity('societe') . ")";
369
-		$sql .= " ORDER BY code_compta";
370
-		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
371
-		$resql = $this->db->query($sql);
372
-		if ($resql) {
373
-			while ($obj = $this->db->fetch_object($resql)) {
374
-				if (!empty($obj->code_compta)) {
375
-					$aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')';
376
-				}
377
-			}
378
-		} else {
379
-			$this->error = "Error ".$this->db->lasterror();
380
-			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
381
-			return -1;
382
-		}
383
-		$this->db->free($resql);
384
-
385
-		// Auxiliary supplier account
386
-		$sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
387
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
388
-		$sql .= " WHERE entity IN (" . getEntity('societe') . ")";
389
-		$sql .= " ORDER BY code_compta_fournisseur";
390
-		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
391
-		$resql = $this->db->query($sql);
392
-		if ($resql) {
393
-			while ($obj = $this->db->fetch_object($resql)) {
394
-				if (!empty($obj->code_compta_fournisseur)) {
395
-					$aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')';
396
-				}
397
-			}
398
-		} else {
399
-			$this->error = "Error ".$this->db->lasterror();
400
-			dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
401
-			return -1;
402
-		}
403
-		$this->db->free($resql);
404
-
405
-		// Build select
406
-		$out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
407
-
408
-		return $out;
409
-	}
363
+        $aux_account = array();
364
+
365
+        // Auxiliary customer account
366
+        $sql = "SELECT DISTINCT code_compta, nom ";
367
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe";
368
+        $sql .= " WHERE entity IN (" . getEntity('societe') . ")";
369
+        $sql .= " ORDER BY code_compta";
370
+        dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
371
+        $resql = $this->db->query($sql);
372
+        if ($resql) {
373
+            while ($obj = $this->db->fetch_object($resql)) {
374
+                if (!empty($obj->code_compta)) {
375
+                    $aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')';
376
+                }
377
+            }
378
+        } else {
379
+            $this->error = "Error ".$this->db->lasterror();
380
+            dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
381
+            return -1;
382
+        }
383
+        $this->db->free($resql);
384
+
385
+        // Auxiliary supplier account
386
+        $sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
387
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe";
388
+        $sql .= " WHERE entity IN (" . getEntity('societe') . ")";
389
+        $sql .= " ORDER BY code_compta_fournisseur";
390
+        dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
391
+        $resql = $this->db->query($sql);
392
+        if ($resql) {
393
+            while ($obj = $this->db->fetch_object($resql)) {
394
+                if (!empty($obj->code_compta_fournisseur)) {
395
+                    $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')';
396
+                }
397
+            }
398
+        } else {
399
+            $this->error = "Error ".$this->db->lasterror();
400
+            dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
401
+            return -1;
402
+        }
403
+        $this->db->free($resql);
404
+
405
+        // Build select
406
+        $out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
407
+
408
+        return $out;
409
+    }
410 410
 
411 411
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
412
-	/**
413
-	 * Return HTML combo list of years existing into book keepping
414
-	 *
415
-	 * @param string $selected Preselected value
416
-	 * @param string $htmlname Name of HTML select object
417
-	 * @param int $useempty Affiche valeur vide dans liste
418
-	 * @param string $output_format (html/opton (for option html only)/array (to return options arrays
419
-	 * @return string/array
420
-	 */
421
-	function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
422
-	{
412
+    /**
413
+     * Return HTML combo list of years existing into book keepping
414
+     *
415
+     * @param string $selected Preselected value
416
+     * @param string $htmlname Name of HTML select object
417
+     * @param int $useempty Affiche valeur vide dans liste
418
+     * @param string $output_format (html/opton (for option html only)/array (to return options arrays
419
+     * @return string/array
420
+     */
421
+    function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
422
+    {
423 423
         // phpcs:enable
424
-	    global $conf;
425
-
426
-		$out_array = array();
427
-
428
-		$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
429
-		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
430
-	    $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")";
431
-		$sql .= " ORDER BY date_format(doc_date,'%Y')";
432
-		dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
433
-		$resql = $this->db->query($sql);
434
-
435
-		if (!$resql) {
436
-			$this->error = "Error ".$this->db->lasterror();
437
-			dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
438
-			return -1;
439
-		}
440
-		while ($obj = $this->db->fetch_object($resql)) {
441
-			$out_array[$obj->dtyear] = $obj->dtyear;
442
-		}
443
-		$this->db->free($resql);
444
-
445
-		if ($output_format == 'html') {
446
-			return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
447
-		} else {
448
-			return $out_array;
449
-		}
450
-	}
424
+        global $conf;
425
+
426
+        $out_array = array();
427
+
428
+        $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
429
+        $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
430
+        $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")";
431
+        $sql .= " ORDER BY date_format(doc_date,'%Y')";
432
+        dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
433
+        $resql = $this->db->query($sql);
434
+
435
+        if (!$resql) {
436
+            $this->error = "Error ".$this->db->lasterror();
437
+            dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
438
+            return -1;
439
+        }
440
+        while ($obj = $this->db->fetch_object($resql)) {
441
+            $out_array[$obj->dtyear] = $obj->dtyear;
442
+        }
443
+        $this->db->free($resql);
444
+
445
+        if ($output_format == 'html') {
446
+            return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
447
+        } else {
448
+            return $out_array;
449
+        }
450
+    }
451 451
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  *  \ingroup    Advanced accountancy
25 25
  *	\brief      File of class with all html predefined components
26 26
  */
27
-require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
27
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
28 28
 
29 29
 
30 30
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	/**
44 44
 	 * @var string Error code (or message)
45 45
 	 */
46
-	public $error='';
46
+	public $error = '';
47 47
 
48 48
    /**
49 49
 	* Constructor
@@ -70,29 +70,29 @@  discard block
 block discarded – undo
70 70
 	 * @param   int     $disabledajaxcombo Disable ajax combo box.
71 71
 	 * @return	string				String with HTML select
72 72
 	 */
73
-	function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='', $disabledajaxcombo=0)
73
+	function select_journal($selectid, $htmlname = 'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss = 'maxwidth300 maxwidthonsmartphone', $usecache = '', $disabledajaxcombo = 0)
74 74
 	{
75 75
         // phpcs:enable
76
-		global $conf,$langs;
76
+		global $conf, $langs;
77 77
 
78 78
 		$out = '';
79 79
 
80 80
     	$options = array();
81
-		if ($usecache && ! empty($this->options_cache[$usecache]))
81
+		if ($usecache && !empty($this->options_cache[$usecache]))
82 82
 		{
83 83
 		    $options = $this->options_cache[$usecache];
84
-		    $selected=$selectid;
84
+		    $selected = $selectid;
85 85
 		}
86 86
 		else
87 87
 		{
88 88
 			$sql = "SELECT rowid, code, label, nature, entity, active";
89
-			$sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal";
90
-			$sql.= " WHERE active = 1";
91
-			$sql.= " AND entity = ".$conf->entity;
89
+			$sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
90
+			$sql .= " WHERE active = 1";
91
+			$sql .= " AND entity = ".$conf->entity;
92 92
 			//if ($nature && is_numeric($nature))   $sql .= " AND nature = ".$nature;
93
-			$sql.= " ORDER BY code";
93
+			$sql .= " ORDER BY code";
94 94
 
95
-			dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG);
95
+			dol_syslog(get_class($this)."::select_journal", LOG_DEBUG);
96 96
 			$resql = $this->db->query($sql);
97 97
 
98 98
 			if (!$resql) {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 			$langs->load('accountancy');
106 106
 			while ($obj = $this->db->fetch_object($resql))
107 107
 			{
108
-				$label = $obj->code . ' - ' . $langs->trans($obj->label);
108
+				$label = $obj->code.' - '.$langs->trans($obj->label);
109 109
 
110 110
     			$select_value_in = $obj->rowid;
111 111
 				$select_value_out = $obj->rowid;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			}
134 134
 		}
135 135
 
136
-		$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, ($disabledajaxcombo?0:1));
136
+		$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, ($disabledajaxcombo ? 0 : 1));
137 137
 
138 138
 		return $out;
139 139
 	}
@@ -151,39 +151,39 @@  discard block
 block discarded – undo
151 151
      *  @param  int     $allcountries   All countries
152 152
      * 	@return	void
153 153
      */
154
-    function select_accounting_category($selected='',$htmlname='account_category', $useempty=0, $maxlen=0, $help=1, $allcountries=0)
154
+    function select_accounting_category($selected = '', $htmlname = 'account_category', $useempty = 0, $maxlen = 0, $help = 1, $allcountries = 0)
155 155
     {
156 156
         // phpcs:enable
157
-        global $db,$langs,$user,$mysoc;
157
+        global $db, $langs, $user, $mysoc;
158 158
 
159 159
         if (empty($mysoc->country_id) && empty($mysoc->country_code) && empty($allcountries))
160 160
         {
161
-            dol_print_error('','Call to select_accounting_account with mysoc country not yet defined');
161
+            dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
162 162
             exit;
163 163
         }
164 164
 
165
-        if (! empty($mysoc->country_id))
165
+        if (!empty($mysoc->country_id))
166 166
         {
167 167
             $sql = "SELECT c.rowid, c.label as type, c.range_account";
168
-            $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
169
-            $sql.= " WHERE c.active = 1";
170
-			$sql.= " AND c.category_type = 0";
171
-            if (empty($allcountries)) $sql.= " AND c.fk_country = ".$mysoc->country_id;
172
-            $sql.= " ORDER BY c.label ASC";
168
+            $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
169
+            $sql .= " WHERE c.active = 1";
170
+			$sql .= " AND c.category_type = 0";
171
+            if (empty($allcountries)) $sql .= " AND c.fk_country = ".$mysoc->country_id;
172
+            $sql .= " ORDER BY c.label ASC";
173 173
         }
174 174
         else
175 175
         {
176 176
             $sql = "SELECT c.rowid, c.label as type, c.range_account";
177
-            $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co";
178
-            $sql.= " WHERE c.active = 1";
179
-			$sql.= " AND c.category_type = 0";
180
-			$sql.= " AND c.fk_country = co.rowid";
181
-            if (empty($allcountries)) $sql.= " AND co.code = '".$mysoc->country_code."'";
182
-            $sql.= " ORDER BY c.label ASC";
177
+            $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co";
178
+            $sql .= " WHERE c.active = 1";
179
+			$sql .= " AND c.category_type = 0";
180
+			$sql .= " AND c.fk_country = co.rowid";
181
+            if (empty($allcountries)) $sql .= " AND co.code = '".$mysoc->country_code."'";
182
+            $sql .= " ORDER BY c.label ASC";
183 183
         }
184 184
 
185 185
         dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG);
186
-        $resql=$db->query($sql);
186
+        $resql = $db->query($sql);
187 187
         if ($resql)
188 188
         {
189 189
             $num = $db->num_rows($resql);
@@ -192,27 +192,27 @@  discard block
 block discarded – undo
192 192
                 $out = '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.'">';
193 193
                 $i = 0;
194 194
 
195
-                if ($useempty) $out.= '<option value="0">&nbsp;</option>';
195
+                if ($useempty) $out .= '<option value="0">&nbsp;</option>';
196 196
                 while ($i < $num)
197 197
                 {
198 198
                     $obj = $db->fetch_object($resql);
199 199
                     $out .= '<option value="'.$obj->rowid.'"';
200 200
                     if ($obj->rowid == $selected) $out .= ' selected';
201
-                    $out .= '>'.($maxlen ? dol_trunc($obj->type,$maxlen) : $obj->type);
201
+                    $out .= '>'.($maxlen ? dol_trunc($obj->type, $maxlen) : $obj->type);
202 202
 					$out .= ' ('.$obj->range_account.')';
203 203
                     $i++;
204 204
                 }
205
-                $out .=  '</select>';
205
+                $out .= '</select>';
206 206
                 //if ($user->admin && $help) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
207 207
             }
208 208
             else
209 209
             {
210
-                $out .= $langs->trans("ErrorNoAccountingCategoryForThisCountry",$mysoc->country_code);
210
+                $out .= $langs->trans("ErrorNoAccountingCategoryForThisCountry", $mysoc->country_code);
211 211
             }
212 212
         }
213 213
         else
214 214
         {
215
-            dol_print_error($db,$db->lasterror());
215
+            dol_print_error($db, $db->lasterror());
216 216
         }
217 217
 
218 218
         $out .= ajax_combobox($htmlname, array());
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
         // phpcs:enable
234 234
 		$options = array();
235 235
 
236
-		$sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
236
+		$sql = 'SELECT DISTINCT import_key from '.MAIN_DB_PREFIX.'accounting_bookkeeping';
237 237
 	    $sql .= " WHERE entity IN (".getEntity('accountancy').")";
238 238
 		$sql .= ' ORDER BY import_key DESC';
239 239
 
240
-		dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
240
+		dol_syslog(get_class($this)."::select_bookkeeping_importkey", LOG_DEBUG);
241 241
 		$resql = $this->db->query($sql);
242 242
 
243 243
 		if (!$resql) {
244
-			$this->error = "Error " . $this->db->lasterror();
245
-			dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
246
-			return - 1;
244
+			$this->error = "Error ".$this->db->lasterror();
245
+			dol_syslog(get_class($this)."::select_bookkeeping_importkey ".$this->error, LOG_ERR);
246
+			return -1;
247 247
 		}
248 248
 
249 249
 		while ($obj = $this->db->fetch_object($resql)) {
@@ -267,46 +267,46 @@  discard block
 block discarded – undo
267 267
 	 * @param string   $usecache           Key to use to store result into a cache. Next call with same key will reuse the cache.
268 268
 	 * @return string                      String with HTML select
269 269
 	 */
270
-	function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
270
+	function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss = 'maxwidth300 maxwidthonsmartphone', $usecache = '')
271 271
 	{
272 272
         // phpcs:enable
273 273
 		global $conf, $langs;
274 274
 
275
-		require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
275
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
276 276
 
277 277
 		$out = '';
278 278
 
279 279
     	$options = array();
280
-		if ($usecache && ! empty($this->options_cache[$usecache]))
280
+		if ($usecache && !empty($this->options_cache[$usecache]))
281 281
 		{
282 282
 		    $options = $this->options_cache[$usecache];
283
-		    $selected=$selectid;
283
+		    $selected = $selectid;
284 284
 		}
285 285
 		else
286 286
 		{
287 287
     		$trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT;
288 288
 
289 289
     		$sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
290
-    		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
291
-    		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
292
-    		$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
290
+    		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
291
+    		$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
292
+    		$sql .= " AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS;
293 293
     		$sql .= " AND aa.active = 1";
294 294
     		$sql .= " AND aa.entity=".$conf->entity;
295 295
     		$sql .= " ORDER BY aa.account_number";
296 296
 
297
-    		dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
297
+    		dol_syslog(get_class($this)."::select_account", LOG_DEBUG);
298 298
     		$resql = $this->db->query($sql);
299 299
 
300 300
     		if (!$resql) {
301
-    			$this->error = "Error " . $this->db->lasterror();
302
-    			dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
301
+    			$this->error = "Error ".$this->db->lasterror();
302
+    			dol_syslog(get_class($this)."::select_account ".$this->error, LOG_ERR);
303 303
     			return -1;
304 304
     		}
305 305
 
306 306
     		$selected = 0;
307 307
     		while ($obj = $this->db->fetch_object($resql))
308 308
     		{
309
-    			$label = length_accountg($obj->account_number) . ' - ' . $obj->label;
309
+    			$label = length_accountg($obj->account_number).' - '.$obj->label;
310 310
     			$label = dol_trunc($label, $trunclength);
311 311
 
312 312
     			$select_value_in = $obj->rowid;
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 	 * @param string   $morecss        More css
357 357
 	 * @return string                  String with HTML select
358 358
 	 */
359
-    function select_auxaccount($selectid, $htmlname='account_num_aux', $showempty=0, $morecss='maxwidth200')
359
+    function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $morecss = 'maxwidth200')
360 360
     {
361 361
         // phpcs:enable
362 362
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		// Auxiliary customer account
366 366
 		$sql = "SELECT DISTINCT code_compta, nom ";
367 367
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
368
-	    $sql .= " WHERE entity IN (" . getEntity('societe') . ")";
368
+	    $sql .= " WHERE entity IN (".getEntity('societe').")";
369 369
 		$sql .= " ORDER BY code_compta";
370 370
 		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
371 371
 		$resql = $this->db->query($sql);
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 		// Auxiliary supplier account
386 386
 		$sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
387 387
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe";
388
-		$sql .= " WHERE entity IN (" . getEntity('societe') . ")";
388
+		$sql .= " WHERE entity IN (".getEntity('societe').")";
389 389
 		$sql .= " ORDER BY code_compta_fournisseur";
390 390
 		dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
391 391
 		$resql = $this->db->query($sql);
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 
428 428
 		$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
429 429
 		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
430
-	    $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")";
430
+	    $sql .= " WHERE entity IN (".getEntity('accountancy').")";
431 431
 		$sql .= " ORDER BY date_format(doc_date,'%Y')";
432 432
 		dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
433 433
 		$resql = $this->db->query($sql);
Please login to merge, or discard this patch.
Braces   +17 added lines, -14 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@  discard block
 block discarded – undo
82 82
 		{
83 83
 		    $options = $this->options_cache[$usecache];
84 84
 		    $selected=$selectid;
85
-		}
86
-		else
85
+		} else
87 86
 		{
88 87
 			$sql = "SELECT rowid, code, label, nature, entity, active";
89 88
 			$sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal";
@@ -168,17 +167,20 @@  discard block
 block discarded – undo
168 167
             $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
169 168
             $sql.= " WHERE c.active = 1";
170 169
 			$sql.= " AND c.category_type = 0";
171
-            if (empty($allcountries)) $sql.= " AND c.fk_country = ".$mysoc->country_id;
170
+            if (empty($allcountries)) {
171
+                $sql.= " AND c.fk_country = ".$mysoc->country_id;
172
+            }
172 173
             $sql.= " ORDER BY c.label ASC";
173
-        }
174
-        else
174
+        } else
175 175
         {
176 176
             $sql = "SELECT c.rowid, c.label as type, c.range_account";
177 177
             $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co";
178 178
             $sql.= " WHERE c.active = 1";
179 179
 			$sql.= " AND c.category_type = 0";
180 180
 			$sql.= " AND c.fk_country = co.rowid";
181
-            if (empty($allcountries)) $sql.= " AND co.code = '".$mysoc->country_code."'";
181
+            if (empty($allcountries)) {
182
+                $sql.= " AND co.code = '".$mysoc->country_code."'";
183
+            }
182 184
             $sql.= " ORDER BY c.label ASC";
183 185
         }
184 186
 
@@ -192,25 +194,27 @@  discard block
 block discarded – undo
192 194
                 $out = '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.'">';
193 195
                 $i = 0;
194 196
 
195
-                if ($useempty) $out.= '<option value="0">&nbsp;</option>';
197
+                if ($useempty) {
198
+                    $out.= '<option value="0">&nbsp;</option>';
199
+                }
196 200
                 while ($i < $num)
197 201
                 {
198 202
                     $obj = $db->fetch_object($resql);
199 203
                     $out .= '<option value="'.$obj->rowid.'"';
200
-                    if ($obj->rowid == $selected) $out .= ' selected';
204
+                    if ($obj->rowid == $selected) {
205
+                        $out .= ' selected';
206
+                    }
201 207
                     $out .= '>'.($maxlen ? dol_trunc($obj->type,$maxlen) : $obj->type);
202 208
 					$out .= ' ('.$obj->range_account.')';
203 209
                     $i++;
204 210
                 }
205 211
                 $out .=  '</select>';
206 212
                 //if ($user->admin && $help) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
207
-            }
208
-            else
213
+            } else
209 214
             {
210 215
                 $out .= $langs->trans("ErrorNoAccountingCategoryForThisCountry",$mysoc->country_code);
211 216
             }
212
-        }
213
-        else
217
+        } else
214 218
         {
215 219
             dol_print_error($db,$db->lasterror());
216 220
         }
@@ -281,8 +285,7 @@  discard block
 block discarded – undo
281 285
 		{
282 286
 		    $options = $this->options_cache[$usecache];
283 287
 		    $selected=$selectid;
284
-		}
285
-		else
288
+		} else
286 289
 		{
287 290
     		$trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT;
288 291
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/vcard.class.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function encode($string)
32 32
 {
33
-    return str_replace(";","\;",(dol_quoted_printable_encode(utf8_decode($string))));
33
+    return str_replace(";", "\;", (dol_quoted_printable_encode(utf8_decode($string))));
34 34
 }
35 35
 
36 36
 
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
  * @param	int		$line_max	Max length of lines
43 43
  * @return	string				Encoded string
44 44
  */
45
-function dol_quoted_printable_encode($input, $line_max=76)
45
+function dol_quoted_printable_encode($input, $line_max = 76)
46 46
 {
47
-    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
47
+    $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
48 48
     $lines = preg_split("/(\?:\r\n|\r|\n)/", $input);
49 49
     $eol = "\r\n";
50 50
     $linebreak = "=0D=0A";
@@ -57,23 +57,23 @@  discard block
 block discarded – undo
57 57
         $line = $lines[$j];
58 58
         $linlen = strlen($line);
59 59
         $newline = "";
60
-        for($i = 0; $i < $linlen; $i++) {
60
+        for ($i = 0; $i < $linlen; $i++) {
61 61
             $c = substr($line, $i, 1);
62 62
             $dec = ord($c);
63
-            if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
63
+            if (($dec == 32) && ($i == ($linlen - 1))) { // convert space at eol only
64 64
                 $c = "=20";
65
-            } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
66
-                $h2 = floor($dec/16); $h1 = floor($dec%16);
65
+            } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required
66
+                $h2 = floor($dec / 16); $h1 = floor($dec % 16);
67 67
                 $c = $escape.$hex["$h2"].$hex["$h1"];
68 68
             }
69
-            if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
69
+            if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted
70 70
                 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
71 71
                 $newline = "    ";
72 72
             }
73 73
             $newline .= $c;
74 74
         } // end of for
75 75
         $output .= $newline;
76
-        if ($j<count($lines)-1) $output .= $linebreak;
76
+        if ($j < count($lines) - 1) $output .= $linebreak;
77 77
     }
78 78
     return trim($output);
79 79
 }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     var $filename;
89 89
 
90 90
     //var $encoding="UTF-8";
91
-    var $encoding="ISO-8859-1;ENCODING=QUOTED-PRINTABLE";
91
+    var $encoding = "ISO-8859-1;ENCODING=QUOTED-PRINTABLE";
92 92
 
93 93
 
94 94
     /**
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
      *	@param	string	$type		Type
99 99
      *	@return	void
100 100
      */
101
-    function setPhoneNumber($number, $type="")
101
+    function setPhoneNumber($number, $type = "")
102 102
     {
103 103
         // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE"
104 104
         $key = "TEL";
105
-        if ($type!="") $key .= ";".$type;
106
-        $key.= ";CHARSET=".$this->encoding;
105
+        if ($type != "") $key .= ";".$type;
106
+        $key .= ";CHARSET=".$this->encoding;
107 107
         $this->properties[$key] = encode($number);
108 108
     }
109 109
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      *	@param	string	$suffix			Suffix
143 143
      *	@return	void
144 144
      */
145
-    function setName($family="", $first="", $additional="", $prefix="", $suffix="")
145
+    function setName($family = "", $first = "", $additional = "", $prefix = "", $suffix = "")
146 146
     {
147 147
         $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix);
148 148
         $this->filename = "$first%20$family.vcf";
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
      *	@param	string	$type			Type
175 175
      *	@return	void
176 176
      */
177
-    function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
177
+    function setAddress($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL")
178 178
     {
179 179
         // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
180 180
         $key = "ADR";
181
-        if ($type!="") $key.= ";$type";
182
-        $key.= ";CHARSET=".$this->encoding;
181
+        if ($type != "") $key .= ";$type";
182
+        $key .= ";CHARSET=".$this->encoding;
183 183
         $this->properties[$key] = ";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
184 184
 
185 185
         if ($this->properties["LABEL;$type;CHARSET=".$this->encoding] == "")
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
      *	@param	string	$type			Type
202 202
      *	@return	void
203 203
      */
204
-    function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
204
+    function setLabel($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL")
205 205
     {
206 206
         $label = "";
207
-        if ($postoffice!="") $label.= "$postoffice\r\n";
208
-        if ($extended!="") $label.= "$extended\r\n";
209
-        if ($street!="") $label.= "$street\r\n";
210
-        if ($zip!="") $label.= "$zip ";
211
-        if ($city!="") $label.= "$city\r\n";
212
-        if ($region!="") $label.= "$region\r\n";
213
-        if ($country!="") $country.= "$country\r\n";
207
+        if ($postoffice != "") $label .= "$postoffice\r\n";
208
+        if ($extended != "") $label .= "$extended\r\n";
209
+        if ($street != "") $label .= "$street\r\n";
210
+        if ($zip != "") $label .= "$zip ";
211
+        if ($city != "") $label .= "$city\r\n";
212
+        if ($region != "") $label .= "$region\r\n";
213
+        if ($country != "") $country .= "$country\r\n";
214 214
 
215 215
         $this->properties["LABEL;$type;CHARSET=".$this->encoding] = encode($label);
216 216
     }
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
      *	@param	string	$type			Vcard type
223 223
      *	@return	void
224 224
      */
225
-    function setEmail($address,$type="internet,pref")
225
+    function setEmail($address, $type = "internet,pref")
226 226
     {
227 227
         $this->properties["EMAIL;TYPE=".$type] = $address;
228 228
     }
@@ -293,11 +293,11 @@  discard block
 block discarded – undo
293 293
      *  @param	string	$type		Type
294 294
      *	@return	void
295 295
      */
296
-    function setURL($url, $type="")
296
+    function setURL($url, $type = "")
297 297
     {
298 298
         // $type may be WORK | HOME
299 299
         $key = "URL";
300
-        if ($type!="") $key.= ";$type";
300
+        if ($type != "") $key .= ";$type";
301 301
         $this->properties[$key] = $url;
302 302
     }
303 303
 
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
     function getVCard()
310 310
     {
311 311
         $text = "BEGIN:VCARD\r\n";
312
-        $text.= "VERSION:3.0\r\n";
312
+        $text .= "VERSION:3.0\r\n";
313 313
         //$text.= "VERSION:2.1\r\n";
314
-        foreach($this->properties as $key => $value)
314
+        foreach ($this->properties as $key => $value)
315 315
         {
316
-            $text.= "$key:$value\r\n";
316
+            $text .= "$key:$value\r\n";
317 317
         }
318
-        $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
319
-        $text.= "MAILER: Dolibarr\r\n";
320
-        $text.= "END:VCARD\r\n";
318
+        $text .= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
319
+        $text .= "MAILER: Dolibarr\r\n";
320
+        $text .= "END:VCARD\r\n";
321 321
         return $text;
322 322
     }
323 323
 
Please login to merge, or discard this patch.
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
             $newline .= $c;
74 74
         } // end of for
75 75
         $output .= $newline;
76
-        if ($j<count($lines)-1) $output .= $linebreak;
76
+        if ($j<count($lines)-1) {
77
+            $output .= $linebreak;
78
+        }
77 79
     }
78 80
     return trim($output);
79 81
 }
@@ -102,7 +104,9 @@  discard block
 block discarded – undo
102 104
     {
103 105
         // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE"
104 106
         $key = "TEL";
105
-        if ($type!="") $key .= ";".$type;
107
+        if ($type!="") {
108
+            $key .= ";".$type;
109
+        }
106 110
         $key.= ";CHARSET=".$this->encoding;
107 111
         $this->properties[$key] = encode($number);
108 112
     }
@@ -146,7 +150,9 @@  discard block
 block discarded – undo
146 150
     {
147 151
         $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix);
148 152
         $this->filename = "$first%20$family.vcf";
149
-        if (empty($this->properties["FN"])) $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
153
+        if (empty($this->properties["FN"])) {
154
+            $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
155
+        }
150 156
     }
151 157
 
152 158
     /**
@@ -178,7 +184,9 @@  discard block
 block discarded – undo
178 184
     {
179 185
         // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
180 186
         $key = "ADR";
181
-        if ($type!="") $key.= ";$type";
187
+        if ($type!="") {
188
+            $key.= ";$type";
189
+        }
182 190
         $key.= ";CHARSET=".$this->encoding;
183 191
         $this->properties[$key] = ";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
184 192
 
@@ -204,13 +212,27 @@  discard block
 block discarded – undo
204 212
     function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
205 213
     {
206 214
         $label = "";
207
-        if ($postoffice!="") $label.= "$postoffice\r\n";
208
-        if ($extended!="") $label.= "$extended\r\n";
209
-        if ($street!="") $label.= "$street\r\n";
210
-        if ($zip!="") $label.= "$zip ";
211
-        if ($city!="") $label.= "$city\r\n";
212
-        if ($region!="") $label.= "$region\r\n";
213
-        if ($country!="") $country.= "$country\r\n";
215
+        if ($postoffice!="") {
216
+            $label.= "$postoffice\r\n";
217
+        }
218
+        if ($extended!="") {
219
+            $label.= "$extended\r\n";
220
+        }
221
+        if ($street!="") {
222
+            $label.= "$street\r\n";
223
+        }
224
+        if ($zip!="") {
225
+            $label.= "$zip ";
226
+        }
227
+        if ($city!="") {
228
+            $label.= "$city\r\n";
229
+        }
230
+        if ($region!="") {
231
+            $label.= "$region\r\n";
232
+        }
233
+        if ($country!="") {
234
+            $country.= "$country\r\n";
235
+        }
214 236
 
215 237
         $this->properties["LABEL;$type;CHARSET=".$this->encoding] = encode($label);
216 238
     }
@@ -297,7 +319,9 @@  discard block
 block discarded – undo
297 319
     {
298 320
         // $type may be WORK | HOME
299 321
         $key = "URL";
300
-        if ($type!="") $key.= ";$type";
322
+        if ($type!="") {
323
+            $key.= ";$type";
324
+        }
301 325
         $this->properties[$key] = $url;
302 326
     }
303 327
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/commonstickergenerator.class.php 3 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -61,226 +61,226 @@
 block discarded – undo
61 61
  */
62 62
 abstract class CommonStickerGenerator
63 63
 {
64
-	public $code;   // Code of format
64
+    public $code;   // Code of format
65 65
 
66
-	/**
66
+    /**
67 67
      * @var array format Array with informations
68 68
      */
69 69
     public $format;
70 70
 
71
-	// protected
72
-	var $_Avery_Name	= '';	// Nom du format de l'etiquette
73
-	var $_Margin_Left	= 0;	// Marge de gauche de l'etiquette
74
-	var $_Margin_Top	= 0;	// marge en haut de la page avant la premiere etiquette
75
-	var $_X_Space 	= 0;	// Espace horizontal entre 2 bandes d'etiquettes
76
-	var $_Y_Space 	= 0;	// Espace vertical entre 2 bandes d'etiquettes
77
-	var $_X_Number 	= 0;	// NX Nombre d'etiquettes sur la largeur de la page
78
-	var $_Y_Number 	= 0;	// NY Nombre d'etiquettes sur la hauteur de la page
79
-	var $_Width 		= 0;	// Largeur de chaque etiquette
80
-	var $_Height 		= 0;	// Hauteur de chaque etiquette
81
-	var $_Char_Size	= 10;	// Hauteur des caracteres
82
-	var $_Line_Height	= 10;	// Hauteur par defaut d'une ligne
83
-	var $_Metric 		= 'mm';	// Type of metric.. Will help to calculate good values
84
-	var $_Metric_Doc 	= 'mm';	// Type of metric for the doc..
85
-	var $_COUNTX = 1;
86
-	var $_COUNTY = 1;
87
-	var $_First = 1;
88
-	var $Tformat;
71
+    // protected
72
+    var $_Avery_Name	= '';	// Nom du format de l'etiquette
73
+    var $_Margin_Left	= 0;	// Marge de gauche de l'etiquette
74
+    var $_Margin_Top	= 0;	// marge en haut de la page avant la premiere etiquette
75
+    var $_X_Space 	= 0;	// Espace horizontal entre 2 bandes d'etiquettes
76
+    var $_Y_Space 	= 0;	// Espace vertical entre 2 bandes d'etiquettes
77
+    var $_X_Number 	= 0;	// NX Nombre d'etiquettes sur la largeur de la page
78
+    var $_Y_Number 	= 0;	// NY Nombre d'etiquettes sur la hauteur de la page
79
+    var $_Width 		= 0;	// Largeur de chaque etiquette
80
+    var $_Height 		= 0;	// Hauteur de chaque etiquette
81
+    var $_Char_Size	= 10;	// Hauteur des caracteres
82
+    var $_Line_Height	= 10;	// Hauteur par defaut d'une ligne
83
+    var $_Metric 		= 'mm';	// Type of metric.. Will help to calculate good values
84
+    var $_Metric_Doc 	= 'mm';	// Type of metric for the doc..
85
+    var $_COUNTX = 1;
86
+    var $_COUNTY = 1;
87
+    var $_First = 1;
88
+    var $Tformat;
89 89
 
90
-	/**
91
-	 *	Constructor
92
-	 *
93
-	 *  @param		DoliDB		$db      Database handler
94
-	 */
95
-	function __construct($db)
96
-	{
97
-		$this->db = $db;
98
-	}
90
+    /**
91
+     *	Constructor
92
+     *
93
+     *  @param		DoliDB		$db      Database handler
94
+     */
95
+    function __construct($db)
96
+    {
97
+        $this->db = $db;
98
+    }
99 99
 
100 100
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
101
-	/**
102
-	 *  Function to build PDF on disk, then output on HTTP strem.
103
-	 *
104
-	 *  @param	array		$arrayofrecords  	Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
105
-	 *  @param  Translate	$outputlangs     	Lang object for output language
106
-	 *  @param	string		$srctemplatepath	Full path of source filename for generator using a template file
107
-	 *	@param	string		$outputdir			Output directory for pdf file
108
-	 *  @return int             				1=OK, 0=KO
109
-	 */
110
-	abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='');
101
+    /**
102
+     *  Function to build PDF on disk, then output on HTTP strem.
103
+     *
104
+     *  @param	array		$arrayofrecords  	Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
105
+     *  @param  Translate	$outputlangs     	Lang object for output language
106
+     *  @param	string		$srctemplatepath	Full path of source filename for generator using a template file
107
+     *	@param	string		$outputdir			Output directory for pdf file
108
+     *  @return int             				1=OK, 0=KO
109
+     */
110
+    abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='');
111 111
     // phpcs:enable
112 112
 
113
-	/**
114
-	 * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
115
-	 *
116
-	 * @param   PDF         $pdf            PDF reference
117
-	 * @param   Translate  	$outputlangs    Output langs
118
-	 * @param   array     	$param          Associative array containing label content and optional parameters
119
-	 * @return  void
120
-	 */
121
-	abstract function addSticker(&$pdf,$outputlangs,$param);
113
+    /**
114
+     * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
115
+     *
116
+     * @param   PDF         $pdf            PDF reference
117
+     * @param   Translate  	$outputlangs    Output langs
118
+     * @param   array     	$param          Associative array containing label content and optional parameters
119
+     * @return  void
120
+     */
121
+    abstract function addSticker(&$pdf,$outputlangs,$param);
122 122
 
123 123
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
124
-	/**
125
-	 * Methode qui permet de modifier la taille des caracteres
126
-	 * Cela modiera aussi l'espace entre chaque ligne
127
-	 *
128
-	 * @param    PDF        $pdf   PDF reference
129
-	 * @param    int        $pt    point
130
-	 * @return   void
131
-	 */
132
-	function Set_Char_Size(&$pdf,$pt)
133
-	{
124
+    /**
125
+     * Methode qui permet de modifier la taille des caracteres
126
+     * Cela modiera aussi l'espace entre chaque ligne
127
+     *
128
+     * @param    PDF        $pdf   PDF reference
129
+     * @param    int        $pt    point
130
+     * @return   void
131
+     */
132
+    function Set_Char_Size(&$pdf,$pt)
133
+    {
134 134
         // phpcs:enable
135
-		if ($pt > 3) {
136
-			$this->_Char_Size = $pt;
137
-			$this->_Line_Height = $this->_Get_Height_Chars($pt);
138
-			$pdf->SetFont('','',$pt);
139
-		}
140
-	}
135
+        if ($pt > 3) {
136
+            $this->_Char_Size = $pt;
137
+            $this->_Line_Height = $this->_Get_Height_Chars($pt);
138
+            $pdf->SetFont('','',$pt);
139
+        }
140
+    }
141 141
 
142 142
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
143
-	/**
144
-	 * protected Print dot line
145
-	 *
146
-	 * @param	PDF     $pdf                PDF reference
147
-	 * @param 	int		$x1					X1
148
-	 * @param 	int		$y1					Y1
149
-	 * @param 	int		$x2					X2
150
-	 * @param 	int		$y2					Y2
151
-	 * @param 	int		$epaisseur			Epaisseur
152
-	 * @param 	int		$nbPointilles		Nb pointilles
153
-	 * @return	void
154
-	 */
143
+    /**
144
+     * protected Print dot line
145
+     *
146
+     * @param	PDF     $pdf                PDF reference
147
+     * @param 	int		$x1					X1
148
+     * @param 	int		$y1					Y1
149
+     * @param 	int		$x2					X2
150
+     * @param 	int		$y2					Y2
151
+     * @param 	int		$epaisseur			Epaisseur
152
+     * @param 	int		$nbPointilles		Nb pointilles
153
+     * @return	void
154
+     */
155 155
     function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15)
156
-	{
156
+    {
157 157
         // phpcs:enable
158
-		$pdf->SetLineWidth($epaisseur);
159
-		$length=abs($x1-$x2);
160
-		$hauteur=abs($y1-$y2);
161
-		if($length>$hauteur) {
162
-			$Pointilles=($length/$nbPointilles)/2; // taille des pointilles
163
-		}
164
-		else {
165
-			$Pointilles=($hauteur/$nbPointilles)/2;
166
-		}
167
-		for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
168
-			for($j=$i;$j<=($i+$Pointilles);$j++) {
169
-				if($j<=($x2-1)) {
170
-		$pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point
171
-		$pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point
172
-				}
173
-			}
174
-		}
175
-		for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
176
-			for($j=$i;$j<=($i+$Pointilles);$j++) {
177
-				if($j<=($y2-1)) {
178
-		$pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point
179
-		$pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point
180
-				}
181
-			}
182
-		}
183
-	}
158
+        $pdf->SetLineWidth($epaisseur);
159
+        $length=abs($x1-$x2);
160
+        $hauteur=abs($y1-$y2);
161
+        if($length>$hauteur) {
162
+            $Pointilles=($length/$nbPointilles)/2; // taille des pointilles
163
+        }
164
+        else {
165
+            $Pointilles=($hauteur/$nbPointilles)/2;
166
+        }
167
+        for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
168
+            for($j=$i;$j<=($i+$Pointilles);$j++) {
169
+                if($j<=($x2-1)) {
170
+        $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point
171
+        $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point
172
+                }
173
+            }
174
+        }
175
+        for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
176
+            for($j=$i;$j<=($i+$Pointilles);$j++) {
177
+                if($j<=($y2-1)) {
178
+        $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point
179
+        $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point
180
+                }
181
+            }
182
+        }
183
+    }
184 184
 
185 185
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
186
-	/**
187
-	 * protected Function realisant une croix aux 4 coins des cartes
188
-	 *
189
-	 * @param PDF   $pdf                PDF reference
190
-	 * @param int   $x1					X1
191
-	 * @param int	$y1					Y1
192
-	 * @param int	$x2					X2
193
-	 * @param int	$y2					Y2
194
-	 * @param int	$epaisseur			Epaisseur
195
-	 * @param int	$taille             Size
196
-	 * @return void
197
-	 */
198
-	function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4)
199
-	{
186
+    /**
187
+     * protected Function realisant une croix aux 4 coins des cartes
188
+     *
189
+     * @param PDF   $pdf                PDF reference
190
+     * @param int   $x1					X1
191
+     * @param int	$y1					Y1
192
+     * @param int	$x2					X2
193
+     * @param int	$y2					Y2
194
+     * @param int	$epaisseur			Epaisseur
195
+     * @param int	$taille             Size
196
+     * @return void
197
+     */
198
+    function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4)
199
+    {
200 200
         // phpcs:enable
201
-		$pdf->SetDrawColor(192,192,192);
201
+        $pdf->SetDrawColor(192,192,192);
202 202
 
203
-		$pdf->SetLineWidth($epaisseur);
204
-		$lg=$taille/2;
205
-		// croix haut gauche
206
-		$pdf->Line($x1,$y1-$lg,$x1,$y1+$lg);
207
-		$pdf->Line($x1-$lg,$y1,$x1+$lg,$y1);
208
-		// croix bas gauche
209
-		$pdf->Line($x1,$y2-$lg,$x1,$y2+$lg);
210
-		$pdf->Line($x1-$lg,$y2,$x1+$lg,$y2);
211
-		// croix haut droit
212
-		$pdf->Line($x2,$y1-$lg,$x2,$y1+$lg);
213
-		$pdf->Line($x2-$lg,$y1,$x2+$lg,$y1);
214
-		// croix bas droit
215
-		$pdf->Line($x2,$y2-$lg,$x2,$y2+$lg);
216
-		$pdf->Line($x2-$lg,$y2,$x2+$lg,$y2);
203
+        $pdf->SetLineWidth($epaisseur);
204
+        $lg=$taille/2;
205
+        // croix haut gauche
206
+        $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg);
207
+        $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1);
208
+        // croix bas gauche
209
+        $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg);
210
+        $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2);
211
+        // croix haut droit
212
+        $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg);
213
+        $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1);
214
+        // croix bas droit
215
+        $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg);
216
+        $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2);
217 217
 
218
-		$pdf->SetDrawColor(0,0,0);
219
-	}
218
+        $pdf->SetDrawColor(0,0,0);
219
+    }
220 220
 
221
-	/**
222
-	 * Convert units (in to mm, mm to in)
223
-	 * $src and $dest must be 'in' or 'mm'
224
-	 *
225
-	 * @param int       $value  value
226
-	 * @param string    $src    from ('in' or 'mm')
227
-	 * @param string    $dest   to ('in' or 'mm')
228
-	 * @return float    value   value after conversion
229
-	 */
230
-	private function convertMetric($value, $src, $dest)
231
-	{
232
-		if ($src != $dest) {
233
-			$tab = array(
234
-				'in'=>39.37008,
235
-				'mm'=>1000
236
-			);
237
-			return $value * $tab[$dest] / $tab[$src];
238
-		}
221
+    /**
222
+     * Convert units (in to mm, mm to in)
223
+     * $src and $dest must be 'in' or 'mm'
224
+     *
225
+     * @param int       $value  value
226
+     * @param string    $src    from ('in' or 'mm')
227
+     * @param string    $dest   to ('in' or 'mm')
228
+     * @return float    value   value after conversion
229
+     */
230
+    private function convertMetric($value, $src, $dest)
231
+    {
232
+        if ($src != $dest) {
233
+            $tab = array(
234
+                'in'=>39.37008,
235
+                'mm'=>1000
236
+            );
237
+            return $value * $tab[$dest] / $tab[$src];
238
+        }
239 239
 
240
-		return $value;
241
-	}
240
+        return $value;
241
+    }
242 242
 
243 243
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
244
-	/**
245
-	 * protected Give the height for a char size given.
246
-	 *
247
-	 * @param  int    $pt    Point
248
-	 * @return int           Height chars
249
-	 */
250
-	function _Get_Height_Chars($pt)
251
-	{
244
+    /**
245
+     * protected Give the height for a char size given.
246
+     *
247
+     * @param  int    $pt    Point
248
+     * @return int           Height chars
249
+     */
250
+    function _Get_Height_Chars($pt)
251
+    {
252 252
         // phpcs:enable
253
-		// Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes
254
-		$_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
255
-		if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
256
-			return $_Table_Hauteur_Chars[$pt];
257
-		} else {
258
-			return 100; // There is a prob..
259
-		}
260
-	}
253
+        // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes
254
+        $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
255
+        if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
256
+            return $_Table_Hauteur_Chars[$pt];
257
+        } else {
258
+            return 100; // There is a prob..
259
+        }
260
+    }
261 261
 
262 262
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
263
-	/**
264
-	 * protected Set format
265
-	 *
266
-	 * @param    PDF       $pdf     PDF reference
267
-	 * @param    string    $format  Format
268
-	 * @return   void
269
-	 */
270
-	function _Set_Format(&$pdf, $format)
271
-	{
263
+    /**
264
+     * protected Set format
265
+     *
266
+     * @param    PDF       $pdf     PDF reference
267
+     * @param    string    $format  Format
268
+     * @return   void
269
+     */
270
+    function _Set_Format(&$pdf, $format)
271
+    {
272 272
         // phpcs:enable
273
-		$this->_Metric = $format['metric'];
274
-		$this->_Avery_Name = $format['name'];
275
-		$this->_Avery_Code = $format['code'];
276
-		$this->_Margin_Left	= $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
277
-		$this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
278
-		$this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
279
-		$this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
280
-		$this->_X_Number = $format['NX'];
281
-		$this->_Y_Number = $format['NY'];
282
-		$this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc);
283
-		$this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc);
284
-		$this->Set_Char_Size($pdf, $format['font-size']);
285
-	}
273
+        $this->_Metric = $format['metric'];
274
+        $this->_Avery_Name = $format['name'];
275
+        $this->_Avery_Code = $format['code'];
276
+        $this->_Margin_Left	= $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
277
+        $this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
278
+        $this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
279
+        $this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
280
+        $this->_X_Number = $format['NX'];
281
+        $this->_Y_Number = $format['NY'];
282
+        $this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc);
283
+        $this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc);
284
+        $this->Set_Char_Size($pdf, $format['font-size']);
285
+    }
286 286
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
  */
62 62
 abstract class CommonStickerGenerator
63 63
 {
64
-	public $code;   // Code of format
64
+	public $code; // Code of format
65 65
 
66 66
 	/**
67 67
      * @var array format Array with informations
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
     public $format;
70 70
 
71 71
 	// protected
72
-	var $_Avery_Name	= '';	// Nom du format de l'etiquette
73
-	var $_Margin_Left	= 0;	// Marge de gauche de l'etiquette
74
-	var $_Margin_Top	= 0;	// marge en haut de la page avant la premiere etiquette
75
-	var $_X_Space 	= 0;	// Espace horizontal entre 2 bandes d'etiquettes
76
-	var $_Y_Space 	= 0;	// Espace vertical entre 2 bandes d'etiquettes
77
-	var $_X_Number 	= 0;	// NX Nombre d'etiquettes sur la largeur de la page
78
-	var $_Y_Number 	= 0;	// NY Nombre d'etiquettes sur la hauteur de la page
79
-	var $_Width 		= 0;	// Largeur de chaque etiquette
80
-	var $_Height 		= 0;	// Hauteur de chaque etiquette
81
-	var $_Char_Size	= 10;	// Hauteur des caracteres
82
-	var $_Line_Height	= 10;	// Hauteur par defaut d'une ligne
83
-	var $_Metric 		= 'mm';	// Type of metric.. Will help to calculate good values
84
-	var $_Metric_Doc 	= 'mm';	// Type of metric for the doc..
72
+	var $_Avery_Name	= ''; // Nom du format de l'etiquette
73
+	var $_Margin_Left = 0; // Marge de gauche de l'etiquette
74
+	var $_Margin_Top	= 0; // marge en haut de la page avant la premiere etiquette
75
+	var $_X_Space 	= 0; // Espace horizontal entre 2 bandes d'etiquettes
76
+	var $_Y_Space 	= 0; // Espace vertical entre 2 bandes d'etiquettes
77
+	var $_X_Number 	= 0; // NX Nombre d'etiquettes sur la largeur de la page
78
+	var $_Y_Number 	= 0; // NY Nombre d'etiquettes sur la hauteur de la page
79
+	var $_Width = 0; // Largeur de chaque etiquette
80
+	var $_Height 		= 0; // Hauteur de chaque etiquette
81
+	var $_Char_Size	= 10; // Hauteur des caracteres
82
+	var $_Line_Height	= 10; // Hauteur par defaut d'une ligne
83
+	var $_Metric 		= 'mm'; // Type of metric.. Will help to calculate good values
84
+	var $_Metric_Doc 	= 'mm'; // Type of metric for the doc..
85 85
 	var $_COUNTX = 1;
86 86
 	var $_COUNTY = 1;
87 87
 	var $_First = 1;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 *	@param	string		$outputdir			Output directory for pdf file
108 108
 	 *  @return int             				1=OK, 0=KO
109 109
 	 */
110
-	abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='');
110
+	abstract function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '');
111 111
     // phpcs:enable
112 112
 
113 113
 	/**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @param   array     	$param          Associative array containing label content and optional parameters
119 119
 	 * @return  void
120 120
 	 */
121
-	abstract function addSticker(&$pdf,$outputlangs,$param);
121
+	abstract function addSticker(&$pdf, $outputlangs, $param);
122 122
 
123 123
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
124 124
 	/**
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 	 * @param    int        $pt    point
130 130
 	 * @return   void
131 131
 	 */
132
-	function Set_Char_Size(&$pdf,$pt)
132
+	function Set_Char_Size(&$pdf, $pt)
133 133
 	{
134 134
         // phpcs:enable
135 135
 		if ($pt > 3) {
136 136
 			$this->_Char_Size = $pt;
137 137
 			$this->_Line_Height = $this->_Get_Height_Chars($pt);
138
-			$pdf->SetFont('','',$pt);
138
+			$pdf->SetFont('', '', $pt);
139 139
 		}
140 140
 	}
141 141
 
@@ -152,31 +152,31 @@  discard block
 block discarded – undo
152 152
 	 * @param 	int		$nbPointilles		Nb pointilles
153 153
 	 * @return	void
154 154
 	 */
155
-    function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15)
155
+    function _Pointille(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $nbPointilles = 15)
156 156
 	{
157 157
         // phpcs:enable
158 158
 		$pdf->SetLineWidth($epaisseur);
159
-		$length=abs($x1-$x2);
160
-		$hauteur=abs($y1-$y2);
161
-		if($length>$hauteur) {
162
-			$Pointilles=($length/$nbPointilles)/2; // taille des pointilles
159
+		$length = abs($x1 - $x2);
160
+		$hauteur = abs($y1 - $y2);
161
+		if ($length > $hauteur) {
162
+			$Pointilles = ($length / $nbPointilles) / 2; // taille des pointilles
163 163
 		}
164 164
 		else {
165
-			$Pointilles=($hauteur/$nbPointilles)/2;
165
+			$Pointilles = ($hauteur / $nbPointilles) / 2;
166 166
 		}
167
-		for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
168
-			for($j=$i;$j<=($i+$Pointilles);$j++) {
169
-				if($j<=($x2-1)) {
170
-		$pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point
171
-		$pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point
167
+		for ($i = $x1; $i <= $x2; $i += $Pointilles + $Pointilles) {
168
+			for ($j = $i; $j <= ($i + $Pointilles); $j++) {
169
+				if ($j <= ($x2 - 1)) {
170
+		$pdf->Line($j, $y1, $j + 1, $y1); // on trace le pointill? du haut, point par point
171
+		$pdf->Line($j, $y2, $j + 1, $y2); // on trace le pointill? du bas, point par point
172 172
 				}
173 173
 			}
174 174
 		}
175
-		for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
176
-			for($j=$i;$j<=($i+$Pointilles);$j++) {
177
-				if($j<=($y2-1)) {
178
-		$pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point
179
-		$pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point
175
+		for ($i = $y1; $i <= $y2; $i += $Pointilles + $Pointilles) {
176
+			for ($j = $i; $j <= ($i + $Pointilles); $j++) {
177
+				if ($j <= ($y2 - 1)) {
178
+		$pdf->Line($x1, $j, $x1, $j + 1); // on trace le pointill? du haut, point par point
179
+		$pdf->Line($x2, $j, $x2, $j + 1); // on trace le pointill? du bas, point par point
180 180
 				}
181 181
 			}
182 182
 		}
@@ -195,27 +195,27 @@  discard block
 block discarded – undo
195 195
 	 * @param int	$taille             Size
196 196
 	 * @return void
197 197
 	 */
198
-	function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4)
198
+	function _Croix(&$pdf, $x1 = 0, $y1 = 0, $x2 = 210, $y2 = 297, $epaisseur = 1, $taille = 4)
199 199
 	{
200 200
         // phpcs:enable
201
-		$pdf->SetDrawColor(192,192,192);
201
+		$pdf->SetDrawColor(192, 192, 192);
202 202
 
203 203
 		$pdf->SetLineWidth($epaisseur);
204
-		$lg=$taille/2;
204
+		$lg = $taille / 2;
205 205
 		// croix haut gauche
206
-		$pdf->Line($x1,$y1-$lg,$x1,$y1+$lg);
207
-		$pdf->Line($x1-$lg,$y1,$x1+$lg,$y1);
206
+		$pdf->Line($x1, $y1 - $lg, $x1, $y1 + $lg);
207
+		$pdf->Line($x1 - $lg, $y1, $x1 + $lg, $y1);
208 208
 		// croix bas gauche
209
-		$pdf->Line($x1,$y2-$lg,$x1,$y2+$lg);
210
-		$pdf->Line($x1-$lg,$y2,$x1+$lg,$y2);
209
+		$pdf->Line($x1, $y2 - $lg, $x1, $y2 + $lg);
210
+		$pdf->Line($x1 - $lg, $y2, $x1 + $lg, $y2);
211 211
 		// croix haut droit
212
-		$pdf->Line($x2,$y1-$lg,$x2,$y1+$lg);
213
-		$pdf->Line($x2-$lg,$y1,$x2+$lg,$y1);
212
+		$pdf->Line($x2, $y1 - $lg, $x2, $y1 + $lg);
213
+		$pdf->Line($x2 - $lg, $y1, $x2 + $lg, $y1);
214 214
 		// croix bas droit
215
-		$pdf->Line($x2,$y2-$lg,$x2,$y2+$lg);
216
-		$pdf->Line($x2-$lg,$y2,$x2+$lg,$y2);
215
+		$pdf->Line($x2, $y2 - $lg, $x2, $y2 + $lg);
216
+		$pdf->Line($x2 - $lg, $y2, $x2 + $lg, $y2);
217 217
 
218
-		$pdf->SetDrawColor(0,0,0);
218
+		$pdf->SetDrawColor(0, 0, 0);
219 219
 	}
220 220
 
221 221
 	/**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 		$this->_Metric = $format['metric'];
274 274
 		$this->_Avery_Name = $format['name'];
275 275
 		$this->_Avery_Code = $format['code'];
276
-		$this->_Margin_Left	= $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
276
+		$this->_Margin_Left = $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
277 277
 		$this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
278 278
 		$this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
279 279
 		$this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -160,8 +160,7 @@
 block discarded – undo
160 160
 		$hauteur=abs($y1-$y2);
161 161
 		if($length>$hauteur) {
162 162
 			$Pointilles=($length/$nbPointilles)/2; // taille des pointilles
163
-		}
164
-		else {
163
+		} else {
165 164
 			$Pointilles=($hauteur/$nbPointilles)/2;
166 165
 		}
167 166
 		for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formsocialcontrib.class.php 1 patch
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -79,8 +79,7 @@  discard block
 block discarded – undo
79 79
             $sql.= " WHERE c.active = 1";
80 80
             $sql.= " AND c.fk_pays = ".$mysoc->country_id;
81 81
             $sql.= " ORDER BY c.libelle ASC";
82
-        }
83
-        else
82
+        } else
84 83
         {
85 84
             $sql = "SELECT c.id, c.libelle as type";
86 85
             $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_country as co";
@@ -99,25 +98,31 @@  discard block
 block discarded – undo
99 98
             	print '<select class="'.($morecss?$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
100 99
                 $i = 0;
101 100
 
102
-                if ($useempty) print '<option value="0">&nbsp;</option>';
101
+                if ($useempty) {
102
+                    print '<option value="0">&nbsp;</option>';
103
+                }
103 104
                 while ($i < $num)
104 105
                 {
105 106
                     $obj = $db->fetch_object($resql);
106 107
                     print '<option value="'.$obj->id.'"';
107
-                    if ($obj->id == $selected) print ' selected';
108
+                    if ($obj->id == $selected) {
109
+                        print ' selected';
110
+                    }
108 111
                     print '>'.dol_trunc($obj->type,$maxlen);
109 112
                     $i++;
110 113
                 }
111 114
                 print '</select>';
112
-                if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
113
-                if (! empty($conf->use_javascript_ajax)) print ajax_combobox($htmlname);
114
-            }
115
-            else
115
+                if ($user->admin && $help) {
116
+                    print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
117
+                }
118
+                if (! empty($conf->use_javascript_ajax)) {
119
+                    print ajax_combobox($htmlname);
120
+                }
121
+            } else
116 122
             {
117 123
                 print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->country_code);
118 124
             }
119
-        }
120
-        else
125
+        } else
121 126
         {
122 127
             dol_print_error($db,$db->lasterror());
123 128
         }
Please login to merge, or discard this patch.