Test Failed
Branch develop (86e751)
by Laurent
34:11
created
htdocs/core/boxes/box_project.php 3 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -40,30 +40,30 @@  discard block
 block discarded – undo
40 40
 	var $info_box_head = array();
41 41
 	var $info_box_contents = array();
42 42
 
43
-    /**
44
-     *  Constructor
45
-     *
46
-     *  @param  DoliDB  $db         Database handler
47
-     *  @param  string  $param      More parameters
48
-     */
49
-    function __construct($db,$param='')
50
-    {
51
-        global $user, $langs;
52
-        $langs->load("boxes");
53
-        $langs->load("projects");
54
-
55
-        $this->db = $db;
56
-        $this->boxlabel="Projects";
57
-
58
-        $this->hidden=! ($user->rights->projet->lire);
59
-    }
43
+	/**
44
+	 *  Constructor
45
+	 *
46
+	 *  @param  DoliDB  $db         Database handler
47
+	 *  @param  string  $param      More parameters
48
+	 */
49
+	function __construct($db,$param='')
50
+	{
51
+		global $user, $langs;
52
+		$langs->load("boxes");
53
+		$langs->load("projects");
54
+
55
+		$this->db = $db;
56
+		$this->boxlabel="Projects";
57
+
58
+		$this->hidden=! ($user->rights->projet->lire);
59
+	}
60 60
 
61 61
 	/**
62
-	*  Load data for box to show them later
63
-	*
64
-	*  @param   int		$max        Maximum number of records to load
65
-	*  @return  void
66
-	*/
62
+	 *  Load data for box to show them later
63
+	 *
64
+	 *  @param   int		$max        Maximum number of records to load
65
+	 *  @return  void
66
+	 */
67 67
 	function loadBox($max=5)
68 68
 	{
69 69
 		global $conf, $user, $langs, $db;
@@ -80,72 +80,72 @@  discard block
 block discarded – undo
80 80
 		// list the summary of the orders
81 81
 		if ($user->rights->projet->lire) {
82 82
 
83
-		    include_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
84
-		    $projectstatic = new Project($this->db);
83
+			include_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
84
+			$projectstatic = new Project($this->db);
85 85
 
86
-		    $socid=$user->societe_id;
86
+			$socid=$user->societe_id;
87 87
 
88
-    		// Get list of project id allowed to user (in a string list separated by coma)
89
-		    $projectsListId='';
90
-    		if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
88
+			// Get list of project id allowed to user (in a string list separated by coma)
89
+			$projectsListId='';
90
+			if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
91 91
 
92
-		    $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
92
+			$sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
93 93
 			$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
94
-            if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
94
+			if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
95 95
 			$sql.= " WHERE p.entity IN (".getEntity('project').')';
96
-            if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";     // public and assigned to, or restricted to company for external users
96
+			if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";     // public and assigned to, or restricted to company for external users
97 97
 			if ($user->socid) $sql.= " AND s.rowid = ".$user->socid;
98
-            $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
99
-            if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
100
-            if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
98
+			$sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
99
+			if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
100
+			if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
101 101
 
102
-            $sql.= " ORDER BY p.datec DESC";
102
+			$sql.= " ORDER BY p.datec DESC";
103 103
 			//$sql.= $db->plimit($max, 0);
104 104
 
105
-            $result = $db->query($sql);
106
-
107
-            if ($result) {
108
-                $num = $db->num_rows($result);
109
-                $i = 0;
110
-                while ($i < min($num, $max)) {
111
-                    $objp = $db->fetch_object($result);
112
-
113
-                    $tooltip = $langs->trans('Project') . ': ' . $objp->ref;
114
-                    $this->info_box_contents[$i][0] = array(
115
-                        'td' => 'align="left" width="16"',
116
-                        'logo' => 'object_project'.($objp->public?'pub':''),
117
-                        'tooltip' => $tooltip,
118
-                        'url' => DOL_URL_ROOT."/projet/card.php?id=".$objp->rowid,
119
-                    );
120
-
121
-                    $this->info_box_contents[$i][1] = array(
122
-                        'td' => '',
123
-                        'text' => $objp->ref,
124
-                        'tooltip' => $tooltip,
125
-                        'url' => DOL_URL_ROOT."/projet/card.php?id=".$objp->rowid,
126
-                    );
127
-
128
-                    $this->info_box_contents[$i][2] = array(
129
-                        'td' => '',
130
-                        'text' => $objp->title,
131
-                    );
105
+			$result = $db->query($sql);
106
+
107
+			if ($result) {
108
+				$num = $db->num_rows($result);
109
+				$i = 0;
110
+				while ($i < min($num, $max)) {
111
+					$objp = $db->fetch_object($result);
112
+
113
+					$tooltip = $langs->trans('Project') . ': ' . $objp->ref;
114
+					$this->info_box_contents[$i][0] = array(
115
+						'td' => 'align="left" width="16"',
116
+						'logo' => 'object_project'.($objp->public?'pub':''),
117
+						'tooltip' => $tooltip,
118
+						'url' => DOL_URL_ROOT."/projet/card.php?id=".$objp->rowid,
119
+					);
120
+
121
+					$this->info_box_contents[$i][1] = array(
122
+						'td' => '',
123
+						'text' => $objp->ref,
124
+						'tooltip' => $tooltip,
125
+						'url' => DOL_URL_ROOT."/projet/card.php?id=".$objp->rowid,
126
+					);
127
+
128
+					$this->info_box_contents[$i][2] = array(
129
+						'td' => '',
130
+						'text' => $objp->title,
131
+					);
132 132
 
133 133
 					$sql ="SELECT count(*) as nb, sum(progress) as totprogress";
134 134
 					$sql.=" FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
135
-	           		$sql.= " WHERE p.entity IN (".getEntity('project').')';
136
-    				$sql.=" AND p.rowid = ".$objp->rowid;
135
+			   		$sql.= " WHERE p.entity IN (".getEntity('project').')';
136
+					$sql.=" AND p.rowid = ".$objp->rowid;
137 137
 					$resultTask = $db->query($sql);
138 138
 					if ($resultTask) {
139 139
 						$objTask = $db->fetch_object($resultTask);
140
-                        $this->info_box_contents[$i][3] = array(
141
-                            'td' => 'class="right"',
142
-                            'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
143
-                        );
140
+						$this->info_box_contents[$i][3] = array(
141
+							'td' => 'class="right"',
142
+							'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
143
+						);
144 144
 						if ($objTask->nb  > 0)
145
-                            $this->info_box_contents[$i][4] = array(
146
-                                'td' => 'class="right"',
147
-                                'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
148
-                            );
145
+							$this->info_box_contents[$i][4] = array(
146
+								'td' => 'class="right"',
147
+								'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
148
+							);
149 149
 						else
150 150
 							$this->info_box_contents[$i][4] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
151 151
 						$totalnbTask += $objTask->nb;
@@ -158,36 +158,36 @@  discard block
 block discarded – undo
158 158
 				}
159 159
 				if ($max < $num)
160 160
 				{
161
-				    $this->info_box_contents[$i][0] = array('td' => 'colspan="5"', 'text' => '...');
162
-				    $i++;
161
+					$this->info_box_contents[$i][0] = array('td' => 'colspan="5"', 'text' => '...');
162
+					$i++;
163 163
 				}
164 164
 			}
165 165
 		}
166 166
 
167 167
 
168 168
 		// Add the sum à the bottom of the boxes
169
-        $this->info_box_contents[$i][0] = array(
170
-            'tr' => 'class="liste_total"',
171
-            'td' => 'align="left" ',
172
-            'text' => "&nbsp;",
173
-       );
174
-        $this->info_box_contents[$i][1] = array(
175
-            'td' => '',
176
-            'text' => $langs->trans("Total")."&nbsp;".$textHead,
177
-             'text' => "&nbsp;",
178
-        );
179
-        $this->info_box_contents[$i][2] = array(
180
-            'td' => 'align="right" ',
181
-            'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
182
-        );
183
-        $this->info_box_contents[$i][3] = array(
184
-            'td' => 'align="right" ',
185
-            'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
186
-        );
187
-        $this->info_box_contents[$i][4] = array(
188
-            'td' => '',
189
-            'text' => "&nbsp;",
190
-        );
169
+		$this->info_box_contents[$i][0] = array(
170
+			'tr' => 'class="liste_total"',
171
+			'td' => 'align="left" ',
172
+			'text' => "&nbsp;",
173
+	   );
174
+		$this->info_box_contents[$i][1] = array(
175
+			'td' => '',
176
+			'text' => $langs->trans("Total")."&nbsp;".$textHead,
177
+			 'text' => "&nbsp;",
178
+		);
179
+		$this->info_box_contents[$i][2] = array(
180
+			'td' => 'align="right" ',
181
+			'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
182
+		);
183
+		$this->info_box_contents[$i][3] = array(
184
+			'td' => 'align="right" ',
185
+			'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
186
+		);
187
+		$this->info_box_contents[$i][4] = array(
188
+			'td' => '',
189
+			'text' => "&nbsp;",
190
+		);
191 191
 
192 192
 	}
193 193
 
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 *  @param	int		$nooutput	No print, only return string
200 200
 	 *	@return	string
201 201
 	 */
202
-    function showBox($head = null, $contents = null, $nooutput=0)
203
-    {
202
+	function showBox($head = null, $contents = null, $nooutput=0)
203
+	{
204 204
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
205 205
 	}
206 206
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class box_project extends ModeleBoxes
32 32
 {
33
-	var $boxcode="project";
34
-	var $boximg="object_projectpub";
33
+	var $boxcode = "project";
34
+	var $boximg = "object_projectpub";
35 35
 	var $boxlabel;
36 36
 	//var $depends = array("projet");
37 37
 	var $db;
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
      *  @param  DoliDB  $db         Database handler
47 47
      *  @param  string  $param      More parameters
48 48
      */
49
-    function __construct($db,$param='')
49
+    function __construct($db, $param = '')
50 50
     {
51 51
         global $user, $langs;
52 52
         $langs->load("boxes");
53 53
         $langs->load("projects");
54 54
 
55 55
         $this->db = $db;
56
-        $this->boxlabel="Projects";
56
+        $this->boxlabel = "Projects";
57 57
 
58
-        $this->hidden=! ($user->rights->projet->lire);
58
+        $this->hidden = !($user->rights->projet->lire);
59 59
     }
60 60
 
61 61
 	/**
@@ -64,15 +64,15 @@  discard block
 block discarded – undo
64 64
 	*  @param   int		$max        Maximum number of records to load
65 65
 	*  @return  void
66 66
 	*/
67
-	function loadBox($max=5)
67
+	function loadBox($max = 5)
68 68
 	{
69 69
 		global $conf, $user, $langs, $db;
70 70
 
71
-		$this->max=$max;
71
+		$this->max = $max;
72 72
 
73 73
 		$totalMnt = 0;
74 74
 		$totalnb = 0;
75
-		$totalnbTask=0;
75
+		$totalnbTask = 0;
76 76
 
77 77
 		$textHead = $langs->trans("OpenedProjects");
78 78
 		$this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
 		    include_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
84 84
 		    $projectstatic = new Project($this->db);
85 85
 
86
-		    $socid=$user->societe_id;
86
+		    $socid = $user->societe_id;
87 87
 
88 88
     		// Get list of project id allowed to user (in a string list separated by coma)
89
-		    $projectsListId='';
90
-    		if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
89
+		    $projectsListId = '';
90
+    		if (!$user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
91 91
 
92 92
 		    $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
93
-			$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
94
-            if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
95
-			$sql.= " WHERE p.entity IN (".getEntity('project').')';
96
-            if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";     // public and assigned to, or restricted to company for external users
97
-			if ($user->socid) $sql.= " AND s.rowid = ".$user->socid;
98
-            $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
99
-            if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
100
-            if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
101
-
102
-            $sql.= " ORDER BY p.datec DESC";
93
+			$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
94
+            if ($user->socid) $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
95
+			$sql .= " WHERE p.entity IN (".getEntity('project').')';
96
+            if (!$user->rights->projet->all->lire) $sql .= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
97
+			if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
98
+            $sql .= " AND p.fk_statut = 1"; // Seulement les projets ouverts
99
+            if ($socid) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
100
+            if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id.") OR (s.rowid IS NULL))";
101
+
102
+            $sql .= " ORDER BY p.datec DESC";
103 103
 			//$sql.= $db->plimit($max, 0);
104 104
 
105 105
             $result = $db->query($sql);
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
                 while ($i < min($num, $max)) {
111 111
                     $objp = $db->fetch_object($result);
112 112
 
113
-                    $tooltip = $langs->trans('Project') . ': ' . $objp->ref;
113
+                    $tooltip = $langs->trans('Project').': '.$objp->ref;
114 114
                     $this->info_box_contents[$i][0] = array(
115 115
                         'td' => 'align="left" width="16"',
116
-                        'logo' => 'object_project'.($objp->public?'pub':''),
116
+                        'logo' => 'object_project'.($objp->public ? 'pub' : ''),
117 117
                         'tooltip' => $tooltip,
118 118
                         'url' => DOL_URL_ROOT."/projet/card.php?id=".$objp->rowid,
119 119
                     );
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
                         'text' => $objp->title,
131 131
                     );
132 132
 
133
-					$sql ="SELECT count(*) as nb, sum(progress) as totprogress";
134
-					$sql.=" FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
135
-	           		$sql.= " WHERE p.entity IN (".getEntity('project').')';
136
-    				$sql.=" AND p.rowid = ".$objp->rowid;
133
+					$sql = "SELECT count(*) as nb, sum(progress) as totprogress";
134
+					$sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
135
+	           		$sql .= " WHERE p.entity IN (".getEntity('project').')';
136
+    				$sql .= " AND p.rowid = ".$objp->rowid;
137 137
 					$resultTask = $db->query($sql);
138 138
 					if ($resultTask) {
139 139
 						$objTask = $db->fetch_object($resultTask);
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
                             'td' => 'class="right"',
142 142
                             'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
143 143
                         );
144
-						if ($objTask->nb  > 0)
144
+						if ($objTask->nb > 0)
145 145
                             $this->info_box_contents[$i][4] = array(
146 146
                                 'td' => 'class="right"',
147
-                                'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
147
+                                'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
148 148
                             );
149 149
 						else
150 150
 							$this->info_box_contents[$i][4] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 *  @param	int		$nooutput	No print, only return string
200 200
 	 *	@return	string
201 201
 	 */
202
-    function showBox($head = null, $contents = null, $nooutput=0)
202
+    function showBox($head = null, $contents = null, $nooutput = 0)
203 203
     {
204 204
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
205 205
 	}
Please login to merge, or discard this patch.
Braces   +24 added lines, -10 removed lines patch added patch discarded remove patch
@@ -87,17 +87,30 @@  discard block
 block discarded – undo
87 87
 
88 88
     		// Get list of project id allowed to user (in a string list separated by coma)
89 89
 		    $projectsListId='';
90
-    		if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
90
+    		if (! $user->rights->projet->all->lire) {
91
+    			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
92
+    		}
91 93
 
92 94
 		    $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
93 95
 			$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
94
-            if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
96
+            if($user->socid) {
97
+            	$sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
98
+            }
95 99
 			$sql.= " WHERE p.entity IN (".getEntity('project').')';
96
-            if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";     // public and assigned to, or restricted to company for external users
97
-			if ($user->socid) $sql.= " AND s.rowid = ".$user->socid;
100
+            if (! $user->rights->projet->all->lire) {
101
+            	$sql.= " AND p.rowid IN (".$projectsListId.")";
102
+            }
103
+            // public and assigned to, or restricted to company for external users
104
+			if ($user->socid) {
105
+				$sql.= " AND s.rowid = ".$user->socid;
106
+			}
98 107
             $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
99
-            if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
100
-            if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
108
+            if ($socid) {
109
+            	$sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
110
+            }
111
+            if (! $user->rights->societe->client->voir && ! $socid) {
112
+            	$sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
113
+            }
101 114
 
102 115
             $sql.= " ORDER BY p.datec DESC";
103 116
 			//$sql.= $db->plimit($max, 0);
@@ -141,13 +154,14 @@  discard block
 block discarded – undo
141 154
                             'td' => 'class="right"',
142 155
                             'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
143 156
                         );
144
-						if ($objTask->nb  > 0)
145
-                            $this->info_box_contents[$i][4] = array(
157
+						if ($objTask->nb  > 0) {
158
+						                            $this->info_box_contents[$i][4] = array(
146 159
                                 'td' => 'class="right"',
147 160
                                 'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
148 161
                             );
149
-						else
150
-							$this->info_box_contents[$i][4] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
162
+						} else {
163
+													$this->info_box_contents[$i][4] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
164
+						}
151 165
 						$totalnbTask += $objTask->nb;
152 166
 					} else {
153 167
 						$this->info_box_contents[$i][3] = array('td' => 'class="right"', 'text' => round(0));
Please login to merge, or discard this patch.
htdocs/core/boxes/box_graph_orders_permonth.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 *  Load data into info_box_contents array to show array later.
59 59
 	 *
60 60
 	 *  @param	int		$max        Maximum number of records to load
61
-     *  @return	void
61
+	 *  @return	void
62 62
 	 */
63 63
 	function loadBox($max=5)
64 64
 	{
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 
92 92
 		if ($user->rights->commande->lire)
93 93
 		{
94
-		    $langs->load("orders");
94
+			$langs->load("orders");
95 95
 
96
-		    $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
96
+			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
97 97
 			$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
98 98
 			$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
99 99
 
@@ -249,15 +249,15 @@  discard block
 block discarded – undo
249 249
 			else
250 250
 			{
251 251
 				$this->info_box_contents[0][0] = array(	'td' => 'align="left" class="nohover"',
252
-    	        										'maxlength'=>500,
253
-	            										'text' => $mesg);
252
+														'maxlength'=>500,
253
+														'text' => $mesg);
254 254
 			}
255 255
 
256 256
 		}
257 257
 		else {
258 258
 			$this->info_box_contents[0][0] = array(
259
-			    'td' => 'align="left" class="nohover opacitymedium"',
260
-                'text' => $langs->trans("ReadPermissionNotAllowed")
259
+				'td' => 'align="left" class="nohover opacitymedium"',
260
+				'text' => $langs->trans("ReadPermissionNotAllowed")
261 261
 			);
262 262
 		}
263 263
 	}
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	 *  @param	int		$nooutput	No print, only return string
271 271
 	 *	@return	string
272 272
 	 */
273
-    function showBox($head = null, $contents = null, $nooutput=0)
274
-    {
273
+	function showBox($head = null, $contents = null, $nooutput=0)
274
+	{
275 275
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
276 276
 	}
277 277
 
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class box_graph_orders_permonth extends ModeleBoxes
30 30
 {
31
-	var $boxcode="orderspermonth";
32
-	var $boximg="object_order";
33
-	var $boxlabel="BoxCustomersOrdersPerMonth";
31
+	var $boxcode = "orderspermonth";
32
+	var $boximg = "object_order";
33
+	var $boxlabel = "BoxCustomersOrdersPerMonth";
34 34
 	var $depends = array("commande");
35 35
 
36 36
 	var $db;
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 	 * 	@param	DoliDB	$db			Database handler
46 46
 	 *  @param	string	$param		More parameters
47 47
 	 */
48
-	function __construct($db,$param)
48
+	function __construct($db, $param)
49 49
 	{
50 50
 		global $user;
51 51
 
52
-		$this->db=$db;
52
+		$this->db = $db;
53 53
 
54
-		$this->hidden = ! ($user->rights->commande->lire);
54
+		$this->hidden = !($user->rights->commande->lire);
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,18 +60,18 @@  discard block
 block discarded – undo
60 60
 	 *  @param	int		$max        Maximum number of records to load
61 61
      *  @return	void
62 62
 	 */
63
-	function loadBox($max=5)
63
+	function loadBox($max = 5)
64 64
 	{
65 65
 		global $conf, $user, $langs, $db;
66 66
 
67
-		$this->max=$max;
67
+		$this->max = $max;
68 68
 
69
-		$refreshaction='refresh_'.$this->boxcode;
69
+		$refreshaction = 'refresh_'.$this->boxcode;
70 70
 
71 71
 		//include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
72 72
 		//$commandestatic=new Commande($db);
73 73
 
74
-		$text = $langs->trans("BoxCustomersOrdersPerMonth",$max);
74
+		$text = $langs->trans("BoxCustomersOrdersPerMonth", $max);
75 75
 		$this->info_box_head = array(
76 76
 				'text' => $text,
77 77
 				'limit'=> dol_strlen($text),
@@ -83,50 +83,50 @@  discard block
 block discarded – undo
83 83
 				'target'=>'none'	// Set '' to get target="_blank"
84 84
 		);
85 85
 
86
-		$dir=''; 	// We don't need a path because image file will not be saved into disk
87
-		$prefix='';
88
-		$socid=0;
89
-		if ($user->societe_id) $socid=$user->societe_id;
90
-		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
86
+		$dir = ''; // We don't need a path because image file will not be saved into disk
87
+		$prefix = '';
88
+		$socid = 0;
89
+		if ($user->societe_id) $socid = $user->societe_id;
90
+		if (!$user->rights->societe->client->voir || $socid) $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
91 91
 
92 92
 		if ($user->rights->commande->lire)
93 93
 		{
94 94
 		    $langs->load("orders");
95 95
 
96
-		    $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
97
-			$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
98
-			$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
96
+		    $param_year = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
97
+			$param_shownb = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
98
+			$param_showtot = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
99 99
 
100 100
 			include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
101 101
 			include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
102
-			$autosetarray=preg_split("/[,;:]+/",GETPOST('DOL_AUTOSET_COOKIE'));
103
-			if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode,$autosetarray))
102
+			$autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
103
+			if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray))
104 104
 			{
105
-				$endyear=GETPOST($param_year,'int');
106
-				$shownb=GETPOST($param_shownb,'alpha');
107
-				$showtot=GETPOST($param_showtot,'alpha');
105
+				$endyear = GETPOST($param_year, 'int');
106
+				$shownb = GETPOST($param_shownb, 'alpha');
107
+				$showtot = GETPOST($param_showtot, 'alpha');
108 108
 			}
109 109
 			else
110 110
 			{
111
-				$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
112
-				$endyear=$tmparray['year'];
113
-				$shownb=$tmparray['shownb'];
114
-				$showtot=$tmparray['showtot'];
111
+				$tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode], true);
112
+				$endyear = $tmparray['year'];
113
+				$shownb = $tmparray['shownb'];
114
+				$showtot = $tmparray['showtot'];
115 115
 			}
116
-			if (empty($shownb) && empty($showtot)) $showtot=1;
117
-			$nowarray=dol_getdate(dol_now(),true);
118
-			if (empty($endyear)) $endyear=$nowarray['year'];
119
-			$startyear=$endyear-1;
120
-			$mode='customer';
121
-			$WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
122
-			$HEIGHT='192';
116
+			if (empty($shownb) && empty($showtot)) $showtot = 1;
117
+			$nowarray = dol_getdate(dol_now(), true);
118
+			if (empty($endyear)) $endyear = $nowarray['year'];
119
+			$startyear = $endyear - 1;
120
+			$mode = 'customer';
121
+			$WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
122
+			$HEIGHT = '192';
123 123
 
124 124
 			$stats = new CommandeStats($this->db, $socid, $mode, 0);
125 125
 
126 126
 			// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
127 127
 			if ($shownb)
128 128
 			{
129
-				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
129
+				$data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)));
130 130
 
131 131
 				$filenamenb = $dir."/".$prefix."ordersnbinyear-".$endyear.".png";
132 132
 				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
@@ -134,15 +134,15 @@  discard block
 block discarded – undo
134 134
 
135 135
 				$px1 = new DolGraph();
136 136
 				$mesg = $px1->isGraphKo();
137
-				if (! $mesg)
137
+				if (!$mesg)
138 138
 				{
139 139
 					$px1->SetData($data1);
140 140
 					unset($data1);
141 141
 					$px1->SetPrecisionY(0);
142
-					$i=$startyear;$legend=array();
142
+					$i = $startyear; $legend = array();
143 143
 					while ($i <= $endyear)
144 144
 					{
145
-						$legend[]=$i;
145
+						$legend[] = $i;
146 146
 						$i++;
147 147
 					}
148 148
 					$px1->SetLegend($legend);
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 					$px1->SetHorizTickIncrement(1);
155 155
 					$px1->SetPrecisionY(0);
156 156
 					$px1->SetCssPrefix("cssboxes");
157
-					$px1->mode='depth';
157
+					$px1->mode = 'depth';
158 158
 					$px1->SetTitle($langs->trans("NumberOfOrdersByMonth"));
159 159
 
160
-					$px1->draw($filenamenb,$fileurlnb);
160
+					$px1->draw($filenamenb, $fileurlnb);
161 161
 				}
162 162
 			}
163 163
 
164 164
 			// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
165 165
 			if ($showtot)
166 166
 			{
167
-				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
167
+				$data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)));
168 168
 
169 169
 				$filenamenb = $dir."/".$prefix."ordersamountinyear-".$endyear.".png";
170 170
 				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
@@ -172,15 +172,15 @@  discard block
 block discarded – undo
172 172
 
173 173
 				$px2 = new DolGraph();
174 174
 				$mesg = $px2->isGraphKo();
175
-				if (! $mesg)
175
+				if (!$mesg)
176 176
 				{
177 177
 					$px2->SetData($data2);
178 178
 					unset($data2);
179 179
 					$px2->SetPrecisionY(0);
180
-					$i=$startyear;$legend=array();
180
+					$i = $startyear; $legend = array();
181 181
 					while ($i <= $endyear)
182 182
 					{
183
-						$legend[]=$i;
183
+						$legend[] = $i;
184 184
 						$i++;
185 185
 					}
186 186
 					$px2->SetLegend($legend);
@@ -192,63 +192,63 @@  discard block
 block discarded – undo
192 192
 					$px2->SetHorizTickIncrement(1);
193 193
 					$px2->SetPrecisionY(0);
194 194
 					$px2->SetCssPrefix("cssboxes");
195
-					$px2->mode='depth';
195
+					$px2->mode = 'depth';
196 196
 					$px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
197 197
 
198
-					$px2->draw($filenamenb,$fileurlnb);
198
+					$px2->draw($filenamenb, $fileurlnb);
199 199
 				}
200 200
 			}
201 201
 
202 202
 			if (empty($conf->use_javascript_ajax))
203 203
 			{
204 204
 				$langs->load("errors");
205
-				$mesg=$langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
205
+				$mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
206 206
 			}
207 207
 
208
-			if (! $mesg)
208
+			if (!$mesg)
209 209
 			{
210
-				$stringtoshow='';
211
-				$stringtoshow.='<script type="text/javascript" language="javascript">
210
+				$stringtoshow = '';
211
+				$stringtoshow .= '<script type="text/javascript" language="javascript">
212 212
 					jQuery(document).ready(function() {
213 213
 						jQuery("#idsubimg'.$this->boxcode.'").click(function() {
214 214
 							jQuery("#idfilter'.$this->boxcode.'").toggle();
215 215
 						});
216 216
 					});
217 217
 					</script>';
218
-				$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">';	// hideobject is to start hidden
219
-				$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
220
-				$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
221
-				$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
222
-				$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked':'').'> '.$langs->trans("NumberOfOrdersByMonth");
223
-				$stringtoshow.=' &nbsp; ';
224
-				$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked':'').'> '.$langs->trans("AmountOfOrdersByMonthHT");
225
-				$stringtoshow.='<br>';
226
-				$stringtoshow.=$langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
227
-				$stringtoshow.='<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"),'refresh.png','','',1).'">';
228
-				$stringtoshow.='</form>';
229
-				$stringtoshow.='</div>';
218
+				$stringtoshow .= '<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
219
+				$stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
220
+				$stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
221
+				$stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
222
+				$stringtoshow .= '<input type="checkbox" name="'.$param_shownb.'"'.($shownb ? ' checked' : '').'> '.$langs->trans("NumberOfOrdersByMonth");
223
+				$stringtoshow .= ' &nbsp; ';
224
+				$stringtoshow .= '<input type="checkbox" name="'.$param_showtot.'"'.($showtot ? ' checked' : '').'> '.$langs->trans("AmountOfOrdersByMonthHT");
225
+				$stringtoshow .= '<br>';
226
+				$stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
227
+				$stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
228
+				$stringtoshow .= '</form>';
229
+				$stringtoshow .= '</div>';
230 230
 				if ($shownb && $showtot)
231 231
 				{
232
-					$stringtoshow.='<div class="fichecenter">';
233
-					$stringtoshow.='<div class="fichehalfleft">';
232
+					$stringtoshow .= '<div class="fichecenter">';
233
+					$stringtoshow .= '<div class="fichehalfleft">';
234 234
 				}
235
-				if ($shownb) $stringtoshow.=$px1->show();
235
+				if ($shownb) $stringtoshow .= $px1->show();
236 236
 				if ($shownb && $showtot)
237 237
 				{
238
-					$stringtoshow.='</div>';
239
-					$stringtoshow.='<div class="fichehalfright">';
238
+					$stringtoshow .= '</div>';
239
+					$stringtoshow .= '<div class="fichehalfright">';
240 240
 				}
241
-				if ($showtot) $stringtoshow.=$px2->show();
241
+				if ($showtot) $stringtoshow .= $px2->show();
242 242
 				if ($shownb && $showtot)
243 243
 				{
244
-					$stringtoshow.='</div>';
245
-					$stringtoshow.='</div>';
244
+					$stringtoshow .= '</div>';
245
+					$stringtoshow .= '</div>';
246 246
 				}
247
-				$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
247
+				$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"', 'textnoformat'=>$stringtoshow);
248 248
 			}
249 249
 			else
250 250
 			{
251
-				$this->info_box_contents[0][0] = array(	'td' => 'align="left" class="nohover"',
251
+				$this->info_box_contents[0][0] = array('td' => 'align="left" class="nohover"',
252 252
     	        										'maxlength'=>500,
253 253
 	            										'text' => $mesg);
254 254
 			}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 *  @param	int		$nooutput	No print, only return string
271 271
 	 *	@return	string
272 272
 	 */
273
-    function showBox($head = null, $contents = null, $nooutput=0)
273
+    function showBox($head = null, $contents = null, $nooutput = 0)
274 274
     {
275 275
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
276 276
 	}
Please login to merge, or discard this patch.
Braces   +34 added lines, -16 removed lines patch added patch discarded remove patch
@@ -86,8 +86,13 @@  discard block
 block discarded – undo
86 86
 		$dir=''; 	// We don't need a path because image file will not be saved into disk
87 87
 		$prefix='';
88 88
 		$socid=0;
89
-		if ($user->societe_id) $socid=$user->societe_id;
90
-		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
89
+		if ($user->societe_id) {
90
+			$socid=$user->societe_id;
91
+		}
92
+		if (! $user->rights->societe->client->voir || $socid) {
93
+			$prefix.='private-'.$user->id.'-';
94
+		}
95
+		// If user has no permission to see all, output dir is specific to user
91 96
 
92 97
 		if ($user->rights->commande->lire)
93 98
 		{
@@ -105,17 +110,20 @@  discard block
 block discarded – undo
105 110
 				$endyear=GETPOST($param_year,'int');
106 111
 				$shownb=GETPOST($param_shownb,'alpha');
107 112
 				$showtot=GETPOST($param_showtot,'alpha');
108
-			}
109
-			else
113
+			} else
110 114
 			{
111 115
 				$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
112 116
 				$endyear=$tmparray['year'];
113 117
 				$shownb=$tmparray['shownb'];
114 118
 				$showtot=$tmparray['showtot'];
115 119
 			}
116
-			if (empty($shownb) && empty($showtot)) $showtot=1;
120
+			if (empty($shownb) && empty($showtot)) {
121
+				$showtot=1;
122
+			}
117 123
 			$nowarray=dol_getdate(dol_now(),true);
118
-			if (empty($endyear)) $endyear=$nowarray['year'];
124
+			if (empty($endyear)) {
125
+				$endyear=$nowarray['year'];
126
+			}
119 127
 			$startyear=$endyear-1;
120 128
 			$mode='customer';
121 129
 			$WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
@@ -129,8 +137,12 @@  discard block
 block discarded – undo
129 137
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
130 138
 
131 139
 				$filenamenb = $dir."/".$prefix."ordersnbinyear-".$endyear.".png";
132
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
133
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersnbinyear-'.$endyear.'.png';
140
+				if ($mode == 'customer') {
141
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
142
+				}
143
+				if ($mode == 'supplier') {
144
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersnbinyear-'.$endyear.'.png';
145
+				}
134 146
 
135 147
 				$px1 = new DolGraph();
136 148
 				$mesg = $px1->isGraphKo();
@@ -167,8 +179,12 @@  discard block
 block discarded – undo
167 179
 				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
168 180
 
169 181
 				$filenamenb = $dir."/".$prefix."ordersamountinyear-".$endyear.".png";
170
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
171
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersamountinyear-'.$endyear.'.png';
182
+				if ($mode == 'customer') {
183
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
184
+				}
185
+				if ($mode == 'supplier') {
186
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersamountinyear-'.$endyear.'.png';
187
+				}
172 188
 
173 189
 				$px2 = new DolGraph();
174 190
 				$mesg = $px2->isGraphKo();
@@ -232,29 +248,31 @@  discard block
 block discarded – undo
232 248
 					$stringtoshow.='<div class="fichecenter">';
233 249
 					$stringtoshow.='<div class="fichehalfleft">';
234 250
 				}
235
-				if ($shownb) $stringtoshow.=$px1->show();
251
+				if ($shownb) {
252
+					$stringtoshow.=$px1->show();
253
+				}
236 254
 				if ($shownb && $showtot)
237 255
 				{
238 256
 					$stringtoshow.='</div>';
239 257
 					$stringtoshow.='<div class="fichehalfright">';
240 258
 				}
241
-				if ($showtot) $stringtoshow.=$px2->show();
259
+				if ($showtot) {
260
+					$stringtoshow.=$px2->show();
261
+				}
242 262
 				if ($shownb && $showtot)
243 263
 				{
244 264
 					$stringtoshow.='</div>';
245 265
 					$stringtoshow.='</div>';
246 266
 				}
247 267
 				$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
248
-			}
249
-			else
268
+			} else
250 269
 			{
251 270
 				$this->info_box_contents[0][0] = array(	'td' => 'align="left" class="nohover"',
252 271
     	        										'maxlength'=>500,
253 272
 	            										'text' => $mesg);
254 273
 			}
255 274
 
256
-		}
257
-		else {
275
+		} else {
258 276
 			$this->info_box_contents[0][0] = array(
259 277
 			    'td' => 'align="left" class="nohover opacitymedium"',
260 278
                 'text' => $langs->trans("ReadPermissionNotAllowed")
Please login to merge, or discard this patch.
htdocs/core/boxes/box_prospect.php 3 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 *  Constructor
51 51
 	 *
52 52
 	 *  @param  DoliDB	$db      	Database handler
53
-     *  @param	string	$param		More parameters
53
+	 *  @param	string	$param		More parameters
54 54
 	 */
55 55
 	function __construct($db,$param='')
56 56
 	{
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 *  Load data into info_box_contents array to show array later.
69 69
 	 *
70 70
 	 *  @param	int		$max        Maximum number of records to load
71
-     *  @return	void
71
+	 *  @return	void
72 72
 	 */
73 73
 	function loadBox($max=5)
74 74
 	{
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 		{
85 85
 			$sql = "SELECT s.nom as name, s.rowid as socid";
86 86
 			$sql.= ", s.code_client";
87
-            $sql.= ", s.client";
88
-            $sql.= ", s.code_fournisseur";
89
-            $sql.= ", s.fournisseur";
90
-            $sql.= ", s.logo";
87
+			$sql.= ", s.client";
88
+			$sql.= ", s.code_fournisseur";
89
+			$sql.= ", s.fournisseur";
90
+			$sql.= ", s.logo";
91 91
 			$sql.= ", s.fk_stcomm, s.datec, s.tms, s.status";
92 92
 			$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
93 93
 			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -111,56 +111,56 @@  discard block
 block discarded – undo
111 111
 					$datec=$db->jdate($objp->datec);
112 112
 					$datem=$db->jdate($objp->tms);
113 113
 					$thirdpartystatic->id = $objp->socid;
114
-                    $thirdpartystatic->name = $objp->name;
115
-                    $thirdpartystatic->code_client = $objp->code_client;
116
-                    $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
117
-                    $thirdpartystatic->client = $objp->client;
118
-                    $thirdpartystatic->fournisseur = $objp->fournisseur;
119
-                    $thirdpartystatic->logo = $objp->logo;
120
-
121
-                    $this->info_box_contents[$line][] = array(
122
-                        'td' => '',
123
-                        'text' => $thirdpartystatic->getNomUrl(1),
124
-                    	'asis' => 1,
125
-                    );
126
-
127
-                    $this->info_box_contents[$line][] = array(
128
-                        'td' => 'class="right"',
129
-                        'text' => dol_print_date($datem, "day"),
130
-                    );
131
-
132
-                    $this->info_box_contents[$line][] = array(
133
-                        'td' => 'align="right" width="18"',
134
-                        'text' => str_replace('img ','img height="14" ',$thirdpartystatic->LibProspCommStatut($objp->fk_stcomm,3)),
135
-                    );
136
-
137
-                    $this->info_box_contents[$line][] = array(
138
-                        'td' => 'align="right" width="18"',
139
-                        'text' => $thirdpartystatic->LibStatut($objp->status,3),
140
-                    );
141
-
142
-                    $line++;
143
-                }
144
-
145
-                if ($num==0)
146
-                    $this->info_box_contents[$line][0] = array(
147
-                        'td' => 'align="center"',
148
-                        'text'=>$langs->trans("NoRecordedProspects"),
149
-                );
150
-
151
-                $db->free($resql);
152
-            } else {
153
-                $this->info_box_contents[0][0] = array(
154
-                    'td' => '',
155
-                    'maxlength'=>500,
156
-                    'text' => ($db->error().' sql='.$sql),
157
-                );
158
-            }
159
-        } else {
160
-            $this->info_box_contents[0][0] = array(
161
-                'td' => 'align="left" class="nohover opacitymedium"',
162
-                'text' => $langs->trans("ReadPermissionNotAllowed")
163
-            );
114
+					$thirdpartystatic->name = $objp->name;
115
+					$thirdpartystatic->code_client = $objp->code_client;
116
+					$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
117
+					$thirdpartystatic->client = $objp->client;
118
+					$thirdpartystatic->fournisseur = $objp->fournisseur;
119
+					$thirdpartystatic->logo = $objp->logo;
120
+
121
+					$this->info_box_contents[$line][] = array(
122
+						'td' => '',
123
+						'text' => $thirdpartystatic->getNomUrl(1),
124
+						'asis' => 1,
125
+					);
126
+
127
+					$this->info_box_contents[$line][] = array(
128
+						'td' => 'class="right"',
129
+						'text' => dol_print_date($datem, "day"),
130
+					);
131
+
132
+					$this->info_box_contents[$line][] = array(
133
+						'td' => 'align="right" width="18"',
134
+						'text' => str_replace('img ','img height="14" ',$thirdpartystatic->LibProspCommStatut($objp->fk_stcomm,3)),
135
+					);
136
+
137
+					$this->info_box_contents[$line][] = array(
138
+						'td' => 'align="right" width="18"',
139
+						'text' => $thirdpartystatic->LibStatut($objp->status,3),
140
+					);
141
+
142
+					$line++;
143
+				}
144
+
145
+				if ($num==0)
146
+					$this->info_box_contents[$line][0] = array(
147
+						'td' => 'align="center"',
148
+						'text'=>$langs->trans("NoRecordedProspects"),
149
+				);
150
+
151
+				$db->free($resql);
152
+			} else {
153
+				$this->info_box_contents[0][0] = array(
154
+					'td' => '',
155
+					'maxlength'=>500,
156
+					'text' => ($db->error().' sql='.$sql),
157
+				);
158
+			}
159
+		} else {
160
+			$this->info_box_contents[0][0] = array(
161
+				'td' => 'align="left" class="nohover opacitymedium"',
162
+				'text' => $langs->trans("ReadPermissionNotAllowed")
163
+			);
164 164
 		}
165 165
 	}
166 166
 
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	 *  @param	int		$nooutput	No print, only return string
173 173
 	 *	@return	string
174 174
 	 */
175
-    function showBox($head = null, $contents = null, $nooutput=0)
176
-    {
175
+	function showBox($head = null, $contents = null, $nooutput=0)
176
+	{
177 177
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
178 178
 	}
179 179
 
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
  */
35 35
 class box_prospect extends ModeleBoxes
36 36
 {
37
-	var $boxcode="lastprospects";
38
-	var $boximg="object_company";
39
-	var $boxlabel="BoxLastProspects";
37
+	var $boxcode = "lastprospects";
38
+	var $boximg = "object_company";
39
+	var $boxlabel = "BoxLastProspects";
40 40
 	var $depends = array("societe");
41 41
 
42 42
 	var $db;
@@ -52,16 +52,16 @@  discard block
 block discarded – undo
52 52
 	 *  @param  DoliDB	$db      	Database handler
53 53
      *  @param	string	$param		More parameters
54 54
 	 */
55
-	function __construct($db,$param='')
55
+	function __construct($db, $param = '')
56 56
 	{
57 57
 		global $conf, $user;
58 58
 
59 59
 		$this->db = $db;
60 60
 
61 61
 		// disable box for such cases
62
-		if (! empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $this->enabled=0;	// disabled by this option
62
+		if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $this->enabled = 0; // disabled by this option
63 63
 
64
-		$this->hidden=! ($user->rights->societe->lire && empty($user->socid));
64
+		$this->hidden = !($user->rights->societe->lire && empty($user->socid));
65 65
 	}
66 66
 
67 67
 	/**
@@ -70,33 +70,33 @@  discard block
 block discarded – undo
70 70
 	 *  @param	int		$max        Maximum number of records to load
71 71
      *  @return	void
72 72
 	 */
73
-	function loadBox($max=5)
73
+	function loadBox($max = 5)
74 74
 	{
75 75
 		global $user, $langs, $db, $conf;
76 76
 
77
-		$this->max=$max;
77
+		$this->max = $max;
78 78
 
79
-		$thirdpartystatic=new Client($db);
79
+		$thirdpartystatic = new Client($db);
80 80
 
81
-		$this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedProspects",$max));
81
+		$this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedProspects", $max));
82 82
 
83 83
 		if ($user->rights->societe->lire)
84 84
 		{
85 85
 			$sql = "SELECT s.nom as name, s.rowid as socid";
86
-			$sql.= ", s.code_client";
87
-            $sql.= ", s.client";
88
-            $sql.= ", s.code_fournisseur";
89
-            $sql.= ", s.fournisseur";
90
-            $sql.= ", s.logo";
91
-			$sql.= ", s.fk_stcomm, s.datec, s.tms, s.status";
92
-			$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
93
-			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94
-			$sql.= " WHERE s.client IN (2, 3)";
95
-			$sql.= " AND s.entity IN (".getEntity('societe').")";
96
-			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
97
-			if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
98
-			$sql.= " ORDER BY s.tms DESC";
99
-			$sql.= $db->plimit($max, 0);
86
+			$sql .= ", s.code_client";
87
+            $sql .= ", s.client";
88
+            $sql .= ", s.code_fournisseur";
89
+            $sql .= ", s.fournisseur";
90
+            $sql .= ", s.logo";
91
+			$sql .= ", s.fk_stcomm, s.datec, s.tms, s.status";
92
+			$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93
+			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94
+			$sql .= " WHERE s.client IN (2, 3)";
95
+			$sql .= " AND s.entity IN (".getEntity('societe').")";
96
+			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
97
+			if ($user->societe_id) $sql .= " AND s.rowid = ".$user->societe_id;
98
+			$sql .= " ORDER BY s.tms DESC";
99
+			$sql .= $db->plimit($max, 0);
100 100
 
101 101
 			dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
102 102
 			$resql = $db->query($sql);
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 				while ($line < $num)
109 109
 				{
110 110
 					$objp = $db->fetch_object($resql);
111
-					$datec=$db->jdate($objp->datec);
112
-					$datem=$db->jdate($objp->tms);
111
+					$datec = $db->jdate($objp->datec);
112
+					$datem = $db->jdate($objp->tms);
113 113
 					$thirdpartystatic->id = $objp->socid;
114 114
                     $thirdpartystatic->name = $objp->name;
115 115
                     $thirdpartystatic->code_client = $objp->code_client;
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 
132 132
                     $this->info_box_contents[$line][] = array(
133 133
                         'td' => 'align="right" width="18"',
134
-                        'text' => str_replace('img ','img height="14" ',$thirdpartystatic->LibProspCommStatut($objp->fk_stcomm,3)),
134
+                        'text' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3)),
135 135
                     );
136 136
 
137 137
                     $this->info_box_contents[$line][] = array(
138 138
                         'td' => 'align="right" width="18"',
139
-                        'text' => $thirdpartystatic->LibStatut($objp->status,3),
139
+                        'text' => $thirdpartystatic->LibStatut($objp->status, 3),
140 140
                     );
141 141
 
142 142
                     $line++;
143 143
                 }
144 144
 
145
-                if ($num==0)
145
+                if ($num == 0)
146 146
                     $this->info_box_contents[$line][0] = array(
147 147
                         'td' => 'align="center"',
148 148
                         'text'=>$langs->trans("NoRecordedProspects"),
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 *  @param	int		$nooutput	No print, only return string
173 173
 	 *	@return	string
174 174
 	 */
175
-    function showBox($head = null, $contents = null, $nooutput=0)
175
+    function showBox($head = null, $contents = null, $nooutput = 0)
176 176
     {
177 177
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
178 178
 	}
Please login to merge, or discard this patch.
Braces   +16 added lines, -6 removed lines patch added patch discarded remove patch
@@ -59,7 +59,10 @@  discard block
 block discarded – undo
59 59
 		$this->db = $db;
60 60
 
61 61
 		// disable box for such cases
62
-		if (! empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $this->enabled=0;	// disabled by this option
62
+		if (! empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
63
+			$this->enabled=0;
64
+		}
65
+		// disabled by this option
63 66
 
64 67
 		$this->hidden=! ($user->rights->societe->lire && empty($user->socid));
65 68
 	}
@@ -90,11 +93,17 @@  discard block
 block discarded – undo
90 93
             $sql.= ", s.logo";
91 94
 			$sql.= ", s.fk_stcomm, s.datec, s.tms, s.status";
92 95
 			$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
93
-			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
96
+			if (!$user->rights->societe->client->voir && !$user->societe_id) {
97
+				$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98
+			}
94 99
 			$sql.= " WHERE s.client IN (2, 3)";
95 100
 			$sql.= " AND s.entity IN (".getEntity('societe').")";
96
-			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
97
-			if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
101
+			if (!$user->rights->societe->client->voir && !$user->societe_id) {
102
+				$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
103
+			}
104
+			if ($user->societe_id) {
105
+				$sql.= " AND s.rowid = ".$user->societe_id;
106
+			}
98 107
 			$sql.= " ORDER BY s.tms DESC";
99 108
 			$sql.= $db->plimit($max, 0);
100 109
 
@@ -142,11 +151,12 @@  discard block
 block discarded – undo
142 151
                     $line++;
143 152
                 }
144 153
 
145
-                if ($num==0)
146
-                    $this->info_box_contents[$line][0] = array(
154
+                if ($num==0) {
155
+                                    $this->info_box_contents[$line][0] = array(
147 156
                         'td' => 'align="center"',
148 157
                         'text'=>$langs->trans("NoRecordedProspects"),
149 158
                 );
159
+                }
150 160
 
151 161
                 $db->free($resql);
152 162
             } else {
Please login to merge, or discard this patch.
htdocs/core/boxes/box_graph_invoices_supplier_permonth.php 3 patches
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class box_graph_invoices_supplier_permonth extends ModeleBoxes
30 30
 {
31
-	var $boxcode="invoicessupplierpermonth";
32
-	var $boximg="object_bill";
33
-	var $boxlabel="BoxSuppliersInvoicesPerMonth";
31
+	var $boxcode = "invoicessupplierpermonth";
32
+	var $boximg = "object_bill";
33
+	var $boxlabel = "BoxSuppliersInvoicesPerMonth";
34 34
 	var $depends = array("fournisseur");
35 35
 
36 36
 	var $db;
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 	 * 	@param	DoliDB	$db			Database handler
46 46
 	 *  @param	string	$param		More parameters
47 47
 	 */
48
-	function __construct($db,$param)
48
+	function __construct($db, $param)
49 49
 	{
50 50
 		global $user;
51 51
 
52
-		$this->db=$db;
52
+		$this->db = $db;
53 53
 
54
-		$this->hidden = ! ($user->rights->fournisseur->facture->lire);
54
+		$this->hidden = !($user->rights->fournisseur->facture->lire);
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 	 *  @param	int		$max        Maximum number of records to load
61 61
      *  @return	void
62 62
 	 */
63
-	function loadBox($max=5)
63
+	function loadBox($max = 5)
64 64
 	{
65 65
 		global $conf, $user, $langs, $db;
66 66
 
67
-		$this->max=$max;
67
+		$this->max = $max;
68 68
 
69
-		$refreshaction='refresh_'.$this->boxcode;
69
+		$refreshaction = 'refresh_'.$this->boxcode;
70 70
 
71 71
 		include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
72 72
 
73
-		$text = $langs->trans("BoxSuppliersInvoicesPerMonth",$max);
73
+		$text = $langs->trans("BoxSuppliersInvoicesPerMonth", $max);
74 74
 		$this->info_box_head = array(
75 75
 				'text' => $text,
76 76
 				'limit'=> dol_strlen($text),
@@ -82,48 +82,48 @@  discard block
 block discarded – undo
82 82
 				'target'=>'none'	// Set '' to get target="_blank"
83 83
 		);
84 84
 
85
-		$dir=''; 	// We don't need a path because image file will not be saved into disk
86
-		$prefix='';
87
-		$socid=0;
88
-		if ($user->societe_id) $socid=$user->societe_id;
89
-		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
85
+		$dir = ''; // We don't need a path because image file will not be saved into disk
86
+		$prefix = '';
87
+		$socid = 0;
88
+		if ($user->societe_id) $socid = $user->societe_id;
89
+		if (!$user->rights->societe->client->voir || $socid) $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
90 90
 
91 91
 		if ($user->rights->fournisseur->facture->lire)
92 92
 		{
93
-			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
94
-			$param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
95
-			$param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
93
+			$param_year = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
94
+			$param_shownb = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
95
+			$param_showtot = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
96 96
 
97 97
 			include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
98 98
 			include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
99
-			$autosetarray=preg_split("/[,;:]+/",GETPOST('DOL_AUTOSET_COOKIE'));
100
-			if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode,$autosetarray))
99
+			$autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
100
+			if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode, $autosetarray))
101 101
 			{
102
-				$endyear=GETPOST($param_year,'int');
103
-				$shownb=GETPOST($param_shownb,'alpha');
104
-				$showtot=GETPOST($param_showtot,'alpha');
102
+				$endyear = GETPOST($param_year, 'int');
103
+				$shownb = GETPOST($param_shownb, 'alpha');
104
+				$showtot = GETPOST($param_showtot, 'alpha');
105 105
 			}
106 106
 			else
107 107
 			{
108
-				$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
109
-				$endyear=$tmparray['year'];
110
-				$shownb=$tmparray['shownb'];
111
-				$showtot=$tmparray['showtot'];
108
+				$tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode], true);
109
+				$endyear = $tmparray['year'];
110
+				$shownb = $tmparray['shownb'];
111
+				$showtot = $tmparray['showtot'];
112 112
 			}
113
-			if (empty($shownb) && empty($showtot)) $showtot=1;
114
-			$nowarray=dol_getdate(dol_now(),true);
115
-			if (empty($endyear)) $endyear=$nowarray['year'];
116
-			$startyear=$endyear-1;
117
-			$mode='supplier';
118
-			$WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
119
-			$HEIGHT='192';
113
+			if (empty($shownb) && empty($showtot)) $showtot = 1;
114
+			$nowarray = dol_getdate(dol_now(), true);
115
+			if (empty($endyear)) $endyear = $nowarray['year'];
116
+			$startyear = $endyear - 1;
117
+			$mode = 'supplier';
118
+			$WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '256' : '320';
119
+			$HEIGHT = '192';
120 120
 
121 121
 			$stats = new FactureStats($this->db, $socid, $mode, 0);
122 122
 
123 123
 			// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
124 124
 			if ($shownb)
125 125
 			{
126
-				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
126
+				$data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)));
127 127
 
128 128
 				$filenamenb = $dir."/".$prefix."invoicessuppliernbinyear-".$year.".png";
129 129
 				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
@@ -131,17 +131,17 @@  discard block
 block discarded – undo
131 131
 
132 132
 				$px1 = new DolGraph();
133 133
 				$mesg = $px1->isGraphKo();
134
-				if (! $mesg)
134
+				if (!$mesg)
135 135
 				{
136 136
 				    $langs->load("bills");
137 137
 
138 138
 				    $px1->SetData($data1);
139 139
 					unset($data1);
140 140
 					$px1->SetPrecisionY(0);
141
-					$i=$startyear;$legend=array();
141
+					$i = $startyear; $legend = array();
142 142
 					while ($i <= $endyear)
143 143
 					{
144
-						$legend[]=$i;
144
+						$legend[] = $i;
145 145
 						$i++;
146 146
 					}
147 147
 					$px1->SetLegend($legend);
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
 					$px1->SetHorizTickIncrement(1);
154 154
 					$px1->SetPrecisionY(0);
155 155
 					$px1->SetCssPrefix("cssboxes");
156
-					$px1->mode='depth';
156
+					$px1->mode = 'depth';
157 157
 					$px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
158 158
 
159
-					$px1->draw($filenamenb,$fileurlnb);
159
+					$px1->draw($filenamenb, $fileurlnb);
160 160
 				}
161 161
 			}
162 162
 
163 163
 			// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
164 164
 			if ($showtot)
165 165
 			{
166
-				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
166
+				$data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)));
167 167
 
168 168
 				$filenamenb = $dir."/".$prefix."invoicessupplieramountinyear-".$year.".png";
169 169
 				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
@@ -171,17 +171,17 @@  discard block
 block discarded – undo
171 171
 
172 172
 				$px2 = new DolGraph();
173 173
 				$mesg = $px2->isGraphKo();
174
-				if (! $mesg)
174
+				if (!$mesg)
175 175
 				{
176 176
 				    $langs->load("bills");
177 177
 
178 178
 					$px2->SetData($data2);
179 179
 					unset($data2);
180 180
 					$px2->SetPrecisionY(0);
181
-					$i=$startyear;$legend=array();
181
+					$i = $startyear; $legend = array();
182 182
 					while ($i <= $endyear)
183 183
 					{
184
-						$legend[]=$i;
184
+						$legend[] = $i;
185 185
 						$i++;
186 186
 					}
187 187
 					$px2->SetLegend($legend);
@@ -193,63 +193,63 @@  discard block
 block discarded – undo
193 193
 					$px2->SetHorizTickIncrement(1);
194 194
 					$px2->SetPrecisionY(0);
195 195
 					$px2->SetCssPrefix("cssboxes");
196
-					$px2->mode='depth';
196
+					$px2->mode = 'depth';
197 197
 					$px2->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
198 198
 
199
-					$px2->draw($filenamenb,$fileurlnb);
199
+					$px2->draw($filenamenb, $fileurlnb);
200 200
 				}
201 201
 			}
202 202
 
203 203
 			if (empty($conf->use_javascript_ajax))
204 204
 			{
205 205
 				$langs->load("errors");
206
-				$mesg=$langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
206
+				$mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
207 207
 			}
208 208
 
209
-			if (! $mesg)
209
+			if (!$mesg)
210 210
 			{
211
-				$stringtoshow='';
212
-				$stringtoshow.='<script type="text/javascript" language="javascript">
211
+				$stringtoshow = '';
212
+				$stringtoshow .= '<script type="text/javascript" language="javascript">
213 213
 					jQuery(document).ready(function() {
214 214
 						jQuery("#idsubimg'.$this->boxcode.'").click(function() {
215 215
 							jQuery("#idfilter'.$this->boxcode.'").toggle();
216 216
 						});
217 217
 					});
218 218
 					</script>';
219
-				$stringtoshow.='<div class="center hideobject" id="idfilter'.$this->boxcode.'">';	// hideobject is to start hidden
220
-				$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
221
-				$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
222
-				$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
223
-				$stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked':'').'> '.$langs->trans("NumberOfBillsByMonth");
224
-				$stringtoshow.=' &nbsp; ';
225
-				$stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked':'').'> '.$langs->trans("AmountOfBillsByMonthHT");
226
-				$stringtoshow.='<br>';
227
-				$stringtoshow.=$langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
228
-				$stringtoshow.='<input type="image" class="inline-block valigntextbottom" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"),'refresh.png','','',1).'">';
229
-				$stringtoshow.='</form>';
230
-				$stringtoshow.='</div>';
219
+				$stringtoshow .= '<div class="center hideobject" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
220
+				$stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
221
+				$stringtoshow .= '<input type="hidden" name="action" value="'.$refreshaction.'">';
222
+				$stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
223
+				$stringtoshow .= '<input type="checkbox" name="'.$param_shownb.'"'.($shownb ? ' checked' : '').'> '.$langs->trans("NumberOfBillsByMonth");
224
+				$stringtoshow .= ' &nbsp; ';
225
+				$stringtoshow .= '<input type="checkbox" name="'.$param_showtot.'"'.($showtot ? ' checked' : '').'> '.$langs->trans("AmountOfBillsByMonthHT");
226
+				$stringtoshow .= '<br>';
227
+				$stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
228
+				$stringtoshow .= '<input type="image" class="inline-block valigntextbottom" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
229
+				$stringtoshow .= '</form>';
230
+				$stringtoshow .= '</div>';
231 231
 				if ($shownb && $showtot)
232 232
 				{
233
-					$stringtoshow.='<div class="fichecenter">';
234
-					$stringtoshow.='<div class="fichehalfleft">';
233
+					$stringtoshow .= '<div class="fichecenter">';
234
+					$stringtoshow .= '<div class="fichehalfleft">';
235 235
 				}
236
-				if ($shownb) $stringtoshow.=$px1->show();
236
+				if ($shownb) $stringtoshow .= $px1->show();
237 237
 				if ($shownb && $showtot)
238 238
 				{
239
-					$stringtoshow.='</div>';
240
-					$stringtoshow.='<div class="fichehalfright">';
239
+					$stringtoshow .= '</div>';
240
+					$stringtoshow .= '<div class="fichehalfright">';
241 241
 				}
242
-				if ($showtot) $stringtoshow.=$px2->show();
242
+				if ($showtot) $stringtoshow .= $px2->show();
243 243
 				if ($shownb && $showtot)
244 244
 				{
245
-					$stringtoshow.='</div>';
246
-					$stringtoshow.='</div>';
245
+					$stringtoshow .= '</div>';
246
+					$stringtoshow .= '</div>';
247 247
 				}
248
-				$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
248
+				$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"', 'textnoformat'=>$stringtoshow);
249 249
 			}
250 250
 			else
251 251
 			{
252
-				$this->info_box_contents[0][0] = array(	'td' => 'align="left" class="nohover"',
252
+				$this->info_box_contents[0][0] = array('td' => 'align="left" class="nohover"',
253 253
     	        										'maxlength'=>500,
254 254
 	            										'text' => $mesg);
255 255
 			}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 *  @param	int		$nooutput	No print, only return string
272 272
 	 *	@return	string
273 273
 	 */
274
-    function showBox($head = null, $contents = null, $nooutput=0)
274
+    function showBox($head = null, $contents = null, $nooutput = 0)
275 275
     {
276 276
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
277 277
 	}
Please login to merge, or discard this patch.
Braces   +34 added lines, -16 removed lines patch added patch discarded remove patch
@@ -85,8 +85,13 @@  discard block
 block discarded – undo
85 85
 		$dir=''; 	// We don't need a path because image file will not be saved into disk
86 86
 		$prefix='';
87 87
 		$socid=0;
88
-		if ($user->societe_id) $socid=$user->societe_id;
89
-		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
88
+		if ($user->societe_id) {
89
+			$socid=$user->societe_id;
90
+		}
91
+		if (! $user->rights->societe->client->voir || $socid) {
92
+			$prefix.='private-'.$user->id.'-';
93
+		}
94
+		// If user has no permission to see all, output dir is specific to user
90 95
 
91 96
 		if ($user->rights->fournisseur->facture->lire)
92 97
 		{
@@ -102,17 +107,20 @@  discard block
 block discarded – undo
102 107
 				$endyear=GETPOST($param_year,'int');
103 108
 				$shownb=GETPOST($param_shownb,'alpha');
104 109
 				$showtot=GETPOST($param_showtot,'alpha');
105
-			}
106
-			else
110
+			} else
107 111
 			{
108 112
 				$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
109 113
 				$endyear=$tmparray['year'];
110 114
 				$shownb=$tmparray['shownb'];
111 115
 				$showtot=$tmparray['showtot'];
112 116
 			}
113
-			if (empty($shownb) && empty($showtot)) $showtot=1;
117
+			if (empty($shownb) && empty($showtot)) {
118
+				$showtot=1;
119
+			}
114 120
 			$nowarray=dol_getdate(dol_now(),true);
115
-			if (empty($endyear)) $endyear=$nowarray['year'];
121
+			if (empty($endyear)) {
122
+				$endyear=$nowarray['year'];
123
+			}
116 124
 			$startyear=$endyear-1;
117 125
 			$mode='supplier';
118 126
 			$WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
@@ -126,8 +134,12 @@  discard block
 block discarded – undo
126 134
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
127 135
 
128 136
 				$filenamenb = $dir."/".$prefix."invoicessuppliernbinyear-".$year.".png";
129
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
130
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-'.$year.'.png';
137
+				if ($mode == 'customer') {
138
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
139
+				}
140
+				if ($mode == 'supplier') {
141
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-'.$year.'.png';
142
+				}
131 143
 
132 144
 				$px1 = new DolGraph();
133 145
 				$mesg = $px1->isGraphKo();
@@ -166,8 +178,12 @@  discard block
 block discarded – undo
166 178
 				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action','aZ09')==$refreshaction?-1:(3600*24)));
167 179
 
168 180
 				$filenamenb = $dir."/".$prefix."invoicessupplieramountinyear-".$year.".png";
169
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
170
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-'.$year.'.png';
181
+				if ($mode == 'customer') {
182
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
183
+				}
184
+				if ($mode == 'supplier') {
185
+					$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-'.$year.'.png';
186
+				}
171 187
 
172 188
 				$px2 = new DolGraph();
173 189
 				$mesg = $px2->isGraphKo();
@@ -233,29 +249,31 @@  discard block
 block discarded – undo
233 249
 					$stringtoshow.='<div class="fichecenter">';
234 250
 					$stringtoshow.='<div class="fichehalfleft">';
235 251
 				}
236
-				if ($shownb) $stringtoshow.=$px1->show();
252
+				if ($shownb) {
253
+					$stringtoshow.=$px1->show();
254
+				}
237 255
 				if ($shownb && $showtot)
238 256
 				{
239 257
 					$stringtoshow.='</div>';
240 258
 					$stringtoshow.='<div class="fichehalfright">';
241 259
 				}
242
-				if ($showtot) $stringtoshow.=$px2->show();
260
+				if ($showtot) {
261
+					$stringtoshow.=$px2->show();
262
+				}
243 263
 				if ($shownb && $showtot)
244 264
 				{
245 265
 					$stringtoshow.='</div>';
246 266
 					$stringtoshow.='</div>';
247 267
 				}
248 268
 				$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
249
-			}
250
-			else
269
+			} else
251 270
 			{
252 271
 				$this->info_box_contents[0][0] = array(	'td' => 'align="left" class="nohover"',
253 272
     	        										'maxlength'=>500,
254 273
 	            										'text' => $mesg);
255 274
 			}
256 275
 
257
-		}
258
-		else {
276
+		} else {
259 277
 			$this->info_box_contents[0][0] = array(
260 278
 			    'td' => 'align="left" class="nohover opacitymedium"',
261 279
                 'text' => $langs->trans("ReadPermissionNotAllowed")
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 *  Load data into info_box_contents array to show array later.
59 59
 	 *
60 60
 	 *  @param	int		$max        Maximum number of records to load
61
-     *  @return	void
61
+	 *  @return	void
62 62
 	 */
63 63
 	function loadBox($max=5)
64 64
 	{
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 				$mesg = $px1->isGraphKo();
135 135
 				if (! $mesg)
136 136
 				{
137
-				    $langs->load("bills");
137
+					$langs->load("bills");
138 138
 
139
-				    $px1->SetData($data1);
139
+					$px1->SetData($data1);
140 140
 					unset($data1);
141 141
 					$px1->SetPrecisionY(0);
142 142
 					$i=$startyear;$legend=array();
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 				$mesg = $px2->isGraphKo();
175 175
 				if (! $mesg)
176 176
 				{
177
-				    $langs->load("bills");
177
+					$langs->load("bills");
178 178
 
179 179
 					$px2->SetData($data2);
180 180
 					unset($data2);
@@ -251,15 +251,15 @@  discard block
 block discarded – undo
251 251
 			else
252 252
 			{
253 253
 				$this->info_box_contents[0][0] = array(	'td' => 'align="left" class="nohover"',
254
-    	        										'maxlength'=>500,
255
-	            										'text' => $mesg);
254
+														'maxlength'=>500,
255
+														'text' => $mesg);
256 256
 			}
257 257
 
258 258
 		}
259 259
 		else {
260 260
 			$this->info_box_contents[0][0] = array(
261
-			    'td' => 'align="left" class="nohover opacitymedium"',
262
-                'text' => $langs->trans("ReadPermissionNotAllowed")
261
+				'td' => 'align="left" class="nohover opacitymedium"',
262
+				'text' => $langs->trans("ReadPermissionNotAllowed")
263 263
 			);
264 264
 		}
265 265
 	}
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
 	 *  @param	int		$nooutput	No print, only return string
273 273
 	 *	@return	string
274 274
 	 */
275
-    function showBox($head = null, $contents = null, $nooutput=0)
276
-    {
275
+	function showBox($head = null, $contents = null, $nooutput=0)
276
+	{
277 277
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
278 278
 	}
279 279
 
Please login to merge, or discard this patch.
htdocs/core/boxes/box_produits.php 3 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -53,18 +53,18 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	function __construct($db,$param)
55 55
 	{
56
-	    global $user;
56
+		global $user;
57 57
 
58
-	    $this->db=$db;
58
+		$this->db=$db;
59 59
 
60
-	    $this->hidden=! ($user->rights->produit->lire || $user->rights->service->lire);
60
+		$this->hidden=! ($user->rights->produit->lire || $user->rights->service->lire);
61 61
 	}
62 62
 
63 63
 	/**
64 64
 	 *  Load data into info_box_contents array to show array later.
65 65
 	 *
66 66
 	 *  @param	int		$max        Maximum number of records to load
67
-     *  @return	void
67
+	 *  @return	void
68 68
 	 */
69 69
 	function loadBox($max=5)
70 70
 	{
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 			// Add where from hooks
88 88
 			if (is_object($hookmanager))
89 89
 			{
90
-			    $parameters=array('boxproductlist'=>1);
91
-			    $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
92
-			    $sql.=$hookmanager->resPrint;
90
+				$parameters=array('boxproductlist'=>1);
91
+				$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
92
+				$sql.=$hookmanager->resPrint;
93 93
 			}
94 94
 			$sql.= $db->order('p.datec', 'DESC');
95 95
 			$sql.= $db->plimit($max, 0);
@@ -121,33 +121,33 @@  discard block
 block discarded – undo
121 121
 								$objp->label = $objtp->label;
122 122
 						}
123 123
 					}
124
-                    $productstatic->id = $objp->rowid;
125
-                    $productstatic->ref = $objp->ref;
126
-                    $productstatic->type = $objp->fk_product_type;
127
-                    $productstatic->label = $objp->label;
124
+					$productstatic->id = $objp->rowid;
125
+					$productstatic->ref = $objp->ref;
126
+					$productstatic->type = $objp->fk_product_type;
127
+					$productstatic->label = $objp->label;
128 128
 					$productstatic->entity = $objp->entity;
129 129
 
130 130
 					$this->info_box_contents[$line][] = array(
131
-                        'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
132
-                        'text' => $productstatic->getNomUrl(1),
133
-                        'asis' => 1,
134
-                    );
135
-
136
-                    $this->info_box_contents[$line][] = array(
137
-                        'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
138
-                        'text' => $objp->label,
139
-                    );
140
-
141
-                    if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
142
-                        $price_base_type=$langs->trans($objp->price_base_type);
143
-                        $price=($objp->price_base_type == 'HT')?price($objp->price):$price=price($objp->price_ttc);
144
-	                }
145
-	                else //Parse the dynamic price
146
-	               	{
131
+						'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
132
+						'text' => $productstatic->getNomUrl(1),
133
+						'asis' => 1,
134
+					);
135
+
136
+					$this->info_box_contents[$line][] = array(
137
+						'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
138
+						'text' => $objp->label,
139
+					);
140
+
141
+					if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
142
+						$price_base_type=$langs->trans($objp->price_base_type);
143
+						$price=($objp->price_base_type == 'HT')?price($objp->price):$price=price($objp->price_ttc);
144
+					}
145
+					else //Parse the dynamic price
146
+				   	{
147 147
 						$productstatic->fetch($objp->rowid, '', '', 1);
148
-	                    $priceparser = new PriceParser($this->db);
149
-	                    $price_result = $priceparser->parseProduct($productstatic);
150
-	                    if ($price_result >= 0) {
148
+						$priceparser = new PriceParser($this->db);
149
+						$price_result = $priceparser->parseProduct($productstatic);
150
+						if ($price_result >= 0) {
151 151
 							if ($objp->price_base_type == 'HT')
152 152
 							{
153 153
 								$price_base_type=$langs->trans("HT");
@@ -158,58 +158,58 @@  discard block
 block discarded – undo
158 158
 								$price_base_type=$langs->trans("TTC");
159 159
 							}
160 160
 							$price=price($price_result);
161
-	                    }
162
-	               	}
161
+						}
162
+				   	}
163 163
 					$this->info_box_contents[$line][] = array(
164
-                        'td' => 'class="right"',
165
-                        'text' => $price,
166
-                    );
164
+						'td' => 'class="right"',
165
+						'text' => $price,
166
+					);
167 167
 
168 168
 					$this->info_box_contents[$line][] = array(
169
-                        'td' => 'class="nowrap"',
170
-                        'text' => $price_base_type,
171
-                    );
169
+						'td' => 'class="nowrap"',
170
+						'text' => $price_base_type,
171
+					);
172 172
 
173 173
 					$this->info_box_contents[$line][] = array(
174
-                        'td' => 'class="right"',
175
-                        'text' => dol_print_date($datem,'day'),
176
-                    );
174
+						'td' => 'class="right"',
175
+						'text' => dol_print_date($datem,'day'),
176
+					);
177 177
 
178 178
 					$this->info_box_contents[$line][] = array(
179
-                        'td' => 'align="right" width="18"',
180
-                        'text' => '<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell,3,0).'<span>',
181
-					    'asis' => 1
182
-                    );
183
-
184
-                    $this->info_box_contents[$line][] = array(
185
-                        'td' => 'align="right" width="18"',
186
-                        'text' => '<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy,3,1).'</span>',
187
-					    'asis' => 1
188
-                    );
189
-
190
-                    $line++;
191
-                }
192
-                if ($num==0)
193
-                    $this->info_box_contents[$line][0] = array(
194
-                        'td' => 'align="center"',
195
-                        'text'=>$langs->trans("NoRecordedProducts"),
196
-                    );
197
-
198
-                $db->free($result);
199
-            } else {
200
-                $this->info_box_contents[0][0] = array(
201
-                    'td' => '',
202
-                    'maxlength'=>500,
203
-                    'text' => ($db->error().' sql='.$sql),
204
-                );
205
-            }
206
-        } else {
207
-            $this->info_box_contents[0][0] = array(
208
-                'td' => 'align="left" class="nohover opacitymedium"',
209
-                'text' => $langs->trans("ReadPermissionNotAllowed")
210
-            );
211
-        }
212
-    }
179
+						'td' => 'align="right" width="18"',
180
+						'text' => '<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell,3,0).'<span>',
181
+						'asis' => 1
182
+					);
183
+
184
+					$this->info_box_contents[$line][] = array(
185
+						'td' => 'align="right" width="18"',
186
+						'text' => '<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy,3,1).'</span>',
187
+						'asis' => 1
188
+					);
189
+
190
+					$line++;
191
+				}
192
+				if ($num==0)
193
+					$this->info_box_contents[$line][0] = array(
194
+						'td' => 'align="center"',
195
+						'text'=>$langs->trans("NoRecordedProducts"),
196
+					);
197
+
198
+				$db->free($result);
199
+			} else {
200
+				$this->info_box_contents[0][0] = array(
201
+					'td' => '',
202
+					'maxlength'=>500,
203
+					'text' => ($db->error().' sql='.$sql),
204
+				);
205
+			}
206
+		} else {
207
+			$this->info_box_contents[0][0] = array(
208
+				'td' => 'align="left" class="nohover opacitymedium"',
209
+				'text' => $langs->trans("ReadPermissionNotAllowed")
210
+			);
211
+		}
212
+	}
213 213
 
214 214
 	/**
215 215
 	 *	Method to show box
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 *  @param	int		$nooutput	No print, only return string
220 220
 	 *	@return	string
221 221
 	 */
222
-    function showBox($head = null, $contents = null, $nooutput=0)
223
-    {
222
+	function showBox($head = null, $contents = null, $nooutput=0)
223
+	{
224 224
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
225 225
 	}
226 226
 
Please login to merge, or discard this patch.
Braces   +17 added lines, -11 removed lines patch added patch discarded remove patch
@@ -82,8 +82,12 @@  discard block
 block discarded – undo
82 82
 			$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.fk_price_expression, p.entity";
83 83
 			$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
84 84
 			$sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')';
85
-			if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
86
-			if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
85
+			if (empty($user->rights->produit->lire)) {
86
+				$sql.=' AND p.fk_product_type != 0';
87
+			}
88
+			if (empty($user->rights->service->lire)) {
89
+				$sql.=' AND p.fk_product_type != 1';
90
+			}
87 91
 			// Add where from hooks
88 92
 			if (is_object($hookmanager))
89 93
 			{
@@ -105,9 +109,11 @@  discard block
 block discarded – undo
105 109
 					$datem=$db->jdate($objp->tms);
106 110
 
107 111
 					// Multilangs
108
-					if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
112
+					if (! empty($conf->global->MAIN_MULTILANGS)) {
113
+						// si l'option est active
109 114
 					{
110 115
 						$sqld = "SELECT label";
116
+					}
111 117
 						$sqld.= " FROM ".MAIN_DB_PREFIX."product_lang";
112 118
 						$sqld.= " WHERE fk_product=".$objp->rowid;
113 119
 						$sqld.= " AND lang='". $langs->getDefaultLang() ."'";
@@ -117,8 +123,9 @@  discard block
 block discarded – undo
117 123
 						if ($resultd)
118 124
 						{
119 125
 							$objtp = $db->fetch_object($resultd);
120
-							if (isset($objtp->label) && $objtp->label != '')
121
-								$objp->label = $objtp->label;
126
+							if (isset($objtp->label) && $objtp->label != '') {
127
+															$objp->label = $objtp->label;
128
+							}
122 129
 						}
123 130
 					}
124 131
                     $productstatic->id = $objp->rowid;
@@ -141,8 +148,7 @@  discard block
 block discarded – undo
141 148
                     if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
142 149
                         $price_base_type=$langs->trans($objp->price_base_type);
143 150
                         $price=($objp->price_base_type == 'HT')?price($objp->price):$price=price($objp->price_ttc);
144
-	                }
145
-	                else //Parse the dynamic price
151
+	                } else //Parse the dynamic price
146 152
 	               	{
147 153
 						$productstatic->fetch($objp->rowid, '', '', 1);
148 154
 	                    $priceparser = new PriceParser($this->db);
@@ -151,8 +157,7 @@  discard block
 block discarded – undo
151 157
 							if ($objp->price_base_type == 'HT')
152 158
 							{
153 159
 								$price_base_type=$langs->trans("HT");
154
-							}
155
-							else
160
+							} else
156 161
 							{
157 162
 								$price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
158 163
 								$price_base_type=$langs->trans("TTC");
@@ -189,11 +194,12 @@  discard block
 block discarded – undo
189 194
 
190 195
                     $line++;
191 196
                 }
192
-                if ($num==0)
193
-                    $this->info_box_contents[$line][0] = array(
197
+                if ($num==0) {
198
+                                    $this->info_box_contents[$line][0] = array(
194 199
                         'td' => 'align="center"',
195 200
                         'text'=>$langs->trans("NoRecordedProducts"),
196 201
                     );
202
+                }
197 203
 
198 204
                 $db->free($result);
199 205
             } else {
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class box_produits extends ModeleBoxes
35 35
 {
36
-	var $boxcode="lastproducts";
37
-	var $boximg="object_product";
38
-	var $boxlabel="BoxLastProducts";
36
+	var $boxcode = "lastproducts";
37
+	var $boximg = "object_product";
38
+	var $boxlabel = "BoxLastProducts";
39 39
 	var $depends = array("produit");
40 40
 
41 41
 	var $db;
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	 *  @param  DoliDB  $db         Database handler
52 52
 	 *  @param  string  $param      More parameters
53 53
 	 */
54
-	function __construct($db,$param)
54
+	function __construct($db, $param)
55 55
 	{
56 56
 	    global $user;
57 57
 
58
-	    $this->db=$db;
58
+	    $this->db = $db;
59 59
 
60
-	    $this->hidden=! ($user->rights->produit->lire || $user->rights->service->lire);
60
+	    $this->hidden = !($user->rights->produit->lire || $user->rights->service->lire);
61 61
 	}
62 62
 
63 63
 	/**
@@ -66,33 +66,33 @@  discard block
 block discarded – undo
66 66
 	 *  @param	int		$max        Maximum number of records to load
67 67
      *  @return	void
68 68
 	 */
69
-	function loadBox($max=5)
69
+	function loadBox($max = 5)
70 70
 	{
71 71
 		global $user, $langs, $db, $conf, $hookmanager;
72 72
 
73
-		$this->max=$max;
73
+		$this->max = $max;
74 74
 
75 75
 		include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
76
-		$productstatic=new Product($db);
76
+		$productstatic = new Product($db);
77 77
 
78
-		$this->info_box_head = array('text' => $langs->trans("BoxTitleLastProducts",$max));
78
+		$this->info_box_head = array('text' => $langs->trans("BoxTitleLastProducts", $max));
79 79
 
80 80
 		if ($user->rights->produit->lire || $user->rights->service->lire)
81 81
 		{
82 82
 			$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.fk_price_expression, p.entity";
83
-			$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
84
-			$sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')';
85
-			if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
86
-			if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
83
+			$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
84
+			$sql .= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')';
85
+			if (empty($user->rights->produit->lire)) $sql .= ' AND p.fk_product_type != 0';
86
+			if (empty($user->rights->service->lire)) $sql .= ' AND p.fk_product_type != 1';
87 87
 			// Add where from hooks
88 88
 			if (is_object($hookmanager))
89 89
 			{
90
-			    $parameters=array('boxproductlist'=>1);
91
-			    $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
92
-			    $sql.=$hookmanager->resPrint;
90
+			    $parameters = array('boxproductlist'=>1);
91
+			    $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
92
+			    $sql .= $hookmanager->resPrint;
93 93
 			}
94
-			$sql.= $db->order('p.datec', 'DESC');
95
-			$sql.= $db->plimit($max, 0);
94
+			$sql .= $db->order('p.datec', 'DESC');
95
+			$sql .= $db->plimit($max, 0);
96 96
 
97 97
 			$result = $db->query($sql);
98 98
 			if ($result)
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
 				while ($line < $num)
103 103
 				{
104 104
 					$objp = $db->fetch_object($result);
105
-					$datem=$db->jdate($objp->tms);
105
+					$datem = $db->jdate($objp->tms);
106 106
 
107 107
 					// Multilangs
108
-					if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
108
+					if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
109 109
 					{
110 110
 						$sqld = "SELECT label";
111
-						$sqld.= " FROM ".MAIN_DB_PREFIX."product_lang";
112
-						$sqld.= " WHERE fk_product=".$objp->rowid;
113
-						$sqld.= " AND lang='". $langs->getDefaultLang() ."'";
114
-						$sqld.= " LIMIT 1";
111
+						$sqld .= " FROM ".MAIN_DB_PREFIX."product_lang";
112
+						$sqld .= " WHERE fk_product=".$objp->rowid;
113
+						$sqld .= " AND lang='".$langs->getDefaultLang()."'";
114
+						$sqld .= " LIMIT 1";
115 115
 
116 116
 						$resultd = $db->query($sqld);
117 117
 						if ($resultd)
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
                     );
140 140
 
141 141
                     if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
142
-                        $price_base_type=$langs->trans($objp->price_base_type);
143
-                        $price=($objp->price_base_type == 'HT')?price($objp->price):$price=price($objp->price_ttc);
142
+                        $price_base_type = $langs->trans($objp->price_base_type);
143
+                        $price = ($objp->price_base_type == 'HT') ?price($objp->price) : $price = price($objp->price_ttc);
144 144
 	                }
145 145
 	                else //Parse the dynamic price
146 146
 	               	{
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
 	                    if ($price_result >= 0) {
151 151
 							if ($objp->price_base_type == 'HT')
152 152
 							{
153
-								$price_base_type=$langs->trans("HT");
153
+								$price_base_type = $langs->trans("HT");
154 154
 							}
155 155
 							else
156 156
 							{
157 157
 								$price_result = $price_result * (1 + ($productstatic->tva_tx / 100));
158
-								$price_base_type=$langs->trans("TTC");
158
+								$price_base_type = $langs->trans("TTC");
159 159
 							}
160
-							$price=price($price_result);
160
+							$price = price($price_result);
161 161
 	                    }
162 162
 	               	}
163 163
 					$this->info_box_contents[$line][] = array(
@@ -172,24 +172,24 @@  discard block
 block discarded – undo
172 172
 
173 173
 					$this->info_box_contents[$line][] = array(
174 174
                         'td' => 'class="right"',
175
-                        'text' => dol_print_date($datem,'day'),
175
+                        'text' => dol_print_date($datem, 'day'),
176 176
                     );
177 177
 
178 178
 					$this->info_box_contents[$line][] = array(
179 179
                         'td' => 'align="right" width="18"',
180
-                        'text' => '<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell,3,0).'<span>',
180
+                        'text' => '<span class="statusrefsell">'.$productstatic->LibStatut($objp->tosell, 3, 0).'<span>',
181 181
 					    'asis' => 1
182 182
                     );
183 183
 
184 184
                     $this->info_box_contents[$line][] = array(
185 185
                         'td' => 'align="right" width="18"',
186
-                        'text' => '<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy,3,1).'</span>',
186
+                        'text' => '<span class="statusrefbuy">'.$productstatic->LibStatut($objp->tobuy, 3, 1).'</span>',
187 187
 					    'asis' => 1
188 188
                     );
189 189
 
190 190
                     $line++;
191 191
                 }
192
-                if ($num==0)
192
+                if ($num == 0)
193 193
                     $this->info_box_contents[$line][0] = array(
194 194
                         'td' => 'align="center"',
195 195
                         'text'=>$langs->trans("NoRecordedProducts"),
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 *  @param	int		$nooutput	No print, only return string
220 220
 	 *	@return	string
221 221
 	 */
222
-    function showBox($head = null, $contents = null, $nooutput=0)
222
+    function showBox($head = null, $contents = null, $nooutput = 0)
223 223
     {
224 224
 		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
225 225
 	}
Please login to merge, or discard this patch.
htdocs/core/class/ccountry.class.php 3 patches
Braces   +34 added lines, -20 removed lines patch added patch discarded remove patch
@@ -72,10 +72,18 @@  discard block
 block discarded – undo
72 72
 		$error=0;
73 73
 
74 74
 		// Clean parameters
75
-		if (isset($this->code)) $this->code=trim($this->code);
76
-		if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso);
77
-		if (isset($this->label)) $this->label=trim($this->label);
78
-		if (isset($this->active)) $this->active=trim($this->active);
75
+		if (isset($this->code)) {
76
+			$this->code=trim($this->code);
77
+		}
78
+		if (isset($this->code_iso)) {
79
+			$this->code_iso=trim($this->code_iso);
80
+		}
81
+		if (isset($this->label)) {
82
+			$this->label=trim($this->label);
83
+		}
84
+		if (isset($this->active)) {
85
+			$this->active=trim($this->active);
86
+		}
79 87
 
80 88
 		// Check parameters
81 89
 		// Put here code to add control on parameters values
@@ -129,8 +137,7 @@  discard block
 block discarded – undo
129 137
 			}
130 138
 			$this->db->rollback();
131 139
 			return -1*$error;
132
-		}
133
-		else
140
+		} else
134 141
 		{
135 142
 			$this->db->commit();
136 143
             return $this->id;
@@ -155,8 +162,11 @@  discard block
 block discarded – undo
155 162
 		$sql.= " t.label,";
156 163
 		$sql.= " t.active";
157 164
         $sql.= " FROM ".MAIN_DB_PREFIX."c_country as t";
158
-        if ($id)   $sql.= " WHERE t.rowid = ".$id;
159
-        elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
165
+        if ($id) {
166
+        	$sql.= " WHERE t.rowid = ".$id;
167
+        } elseif ($code) {
168
+        	$sql.= " WHERE t.code = '".$this->db->escape($code)."'";
169
+        }
160 170
 
161 171
     	dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
162 172
         $resql=$this->db->query($sql);
@@ -174,12 +184,10 @@  discard block
 block discarded – undo
174 184
 
175 185
                 $this->db->free($resql);
176 186
                 return 1;
177
-            }
178
-            else {
187
+            } else {
179 188
                 return 0;
180 189
             }
181
-        }
182
-        else
190
+        } else
183 191
         {
184 192
       	    $this->error="Error ".$this->db->lasterror();
185 193
             return -1;
@@ -200,10 +208,18 @@  discard block
 block discarded – undo
200 208
 		$error=0;
201 209
 
202 210
 		// Clean parameters
203
-		if (isset($this->code)) $this->code=trim($this->code);
204
-		if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso);
205
-		if (isset($this->label)) $this->label=trim($this->label);
206
-		if (isset($this->active)) $this->active=trim($this->active);
211
+		if (isset($this->code)) {
212
+			$this->code=trim($this->code);
213
+		}
214
+		if (isset($this->code_iso)) {
215
+			$this->code_iso=trim($this->code_iso);
216
+		}
217
+		if (isset($this->label)) {
218
+			$this->label=trim($this->label);
219
+		}
220
+		if (isset($this->active)) {
221
+			$this->active=trim($this->active);
222
+		}
207 223
 
208 224
 
209 225
 		// Check parameters
@@ -249,8 +265,7 @@  discard block
 block discarded – undo
249 265
 			}
250 266
 			$this->db->rollback();
251 267
 			return -1*$error;
252
-		}
253
-		else
268
+		} else
254 269
 		{
255 270
 			$this->db->commit();
256 271
 			return 1;
@@ -305,8 +320,7 @@  discard block
 block discarded – undo
305 320
 			}
306 321
 			$this->db->rollback();
307 322
 			return -1*$error;
308
-		}
309
-		else
323
+		} else
310 324
 		{
311 325
 			$this->db->commit();
312 326
 			return 1;
Please login to merge, or discard this patch.
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	//var $element='ccountry';			//!< Id that identify managed objects
39 39
 	//var $table_element='ccountry';	//!< Name of table without prefix where object is stored
40 40
 
41
-    var $id;
41
+	var $id;
42 42
 	var $code;
43 43
 	var $code_iso;
44 44
 	var $label;
@@ -47,28 +47,28 @@  discard block
 block discarded – undo
47 47
 
48 48
 
49 49
 
50
-    /**
51
-     *  Constructor
52
-     *
53
-     *  @param      DoliDb		$db      Database handler
54
-     */
55
-    function __construct($db)
56
-    {
57
-        $this->db = $db;
58
-        return 1;
59
-    }
50
+	/**
51
+	 *  Constructor
52
+	 *
53
+	 *  @param      DoliDb		$db      Database handler
54
+	 */
55
+	function __construct($db)
56
+	{
57
+		$this->db = $db;
58
+		return 1;
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     *  Create object into database
64
-     *
65
-     *  @param      User	$user        User that create
66
-     *  @param      int		$notrigger   0=launch triggers after, 1=disable triggers
67
-     *  @return     int      		   	 <0 if KO, Id of created object if OK
68
-     */
69
-    function create($user, $notrigger=0)
70
-    {
71
-    	global $conf, $langs;
62
+	/**
63
+	 *  Create object into database
64
+	 *
65
+	 *  @param      User	$user        User that create
66
+	 *  @param      int		$notrigger   0=launch triggers after, 1=disable triggers
67
+	 *  @return     int      		   	 <0 if KO, Id of created object if OK
68
+	 */
69
+	function create($user, $notrigger=0)
70
+	{
71
+		global $conf, $langs;
72 72
 		$error=0;
73 73
 
74 74
 		// Clean parameters
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 		// Check parameters
81 81
 		// Put here code to add control on parameters values
82 82
 
83
-        // Insert request
83
+		// Insert request
84 84
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country(";
85 85
 		$sql.= "rowid,";
86 86
 		$sql.= "code,";
87 87
 		$sql.= "code_iso,";
88 88
 		$sql.= "label,";
89 89
 		$sql.= "active";
90
-        $sql.= ") VALUES (";
90
+		$sql.= ") VALUES (";
91 91
 		$sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").",";
92 92
 		$sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
93 93
 		$sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").",";
@@ -98,34 +98,34 @@  discard block
 block discarded – undo
98 98
 		$this->db->begin();
99 99
 
100 100
 	   	dol_syslog(get_class($this)."::create", LOG_DEBUG);
101
-        $resql=$this->db->query($sql);
102
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
101
+		$resql=$this->db->query($sql);
102
+		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
103 103
 
104 104
 		if (! $error)
105
-        {
106
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country");
105
+		{
106
+			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country");
107 107
 
108 108
 			if (! $notrigger)
109 109
 			{
110
-	            // Uncomment this and change MYOBJECT to your own tag if you
111
-	            // want this action call a trigger.
112
-
113
-	            //// Call triggers
114
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
115
-	            //$interface=new Interfaces($this->db);
116
-	            //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
117
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
118
-	            //// End call triggers
110
+				// Uncomment this and change MYOBJECT to your own tag if you
111
+				// want this action call a trigger.
112
+
113
+				//// Call triggers
114
+				//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
115
+				//$interface=new Interfaces($this->db);
116
+				//$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
117
+				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
118
+				//// End call triggers
119 119
 			}
120
-        }
120
+		}
121 121
 
122
-        // Commit or rollback
123
-        if ($error)
122
+		// Commit or rollback
123
+		if ($error)
124 124
 		{
125 125
 			foreach($this->errors as $errmsg)
126 126
 			{
127
-	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
128
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
127
+				dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
128
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
129 129
 			}
130 130
 			$this->db->rollback();
131 131
 			return -1*$error;
@@ -133,70 +133,70 @@  discard block
 block discarded – undo
133 133
 		else
134 134
 		{
135 135
 			$this->db->commit();
136
-            return $this->id;
136
+			return $this->id;
137 137
 		}
138
-    }
139
-
140
-
141
-    /**
142
-     *  Load object in memory from database
143
-     *
144
-     *  @param      int		$id    	Id object
145
-     *  @param		string	$code	Code
146
-     *  @return     int          	>0 if OK, 0 if not found, <0 if KO
147
-     */
148
-    function fetch($id,$code='')
149
-    {
150
-    	global $langs;
151
-        $sql = "SELECT";
138
+	}
139
+
140
+
141
+	/**
142
+	 *  Load object in memory from database
143
+	 *
144
+	 *  @param      int		$id    	Id object
145
+	 *  @param		string	$code	Code
146
+	 *  @return     int          	>0 if OK, 0 if not found, <0 if KO
147
+	 */
148
+	function fetch($id,$code='')
149
+	{
150
+		global $langs;
151
+		$sql = "SELECT";
152 152
 		$sql.= " t.rowid,";
153 153
 		$sql.= " t.code,";
154 154
 		$sql.= " t.code_iso,";
155 155
 		$sql.= " t.label,";
156 156
 		$sql.= " t.active";
157
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_country as t";
158
-        if ($id)   $sql.= " WHERE t.rowid = ".$id;
159
-        elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
160
-
161
-    	dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
162
-        $resql=$this->db->query($sql);
163
-        if ($resql)
164
-        {
165
-            if ($this->db->num_rows($resql))
166
-            {
167
-                $obj = $this->db->fetch_object($resql);
168
-
169
-                $this->id    = $obj->rowid;
157
+		$sql.= " FROM ".MAIN_DB_PREFIX."c_country as t";
158
+		if ($id)   $sql.= " WHERE t.rowid = ".$id;
159
+		elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
160
+
161
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
162
+		$resql=$this->db->query($sql);
163
+		if ($resql)
164
+		{
165
+			if ($this->db->num_rows($resql))
166
+			{
167
+				$obj = $this->db->fetch_object($resql);
168
+
169
+				$this->id    = $obj->rowid;
170 170
 				$this->code = $obj->code;
171 171
 				$this->code_iso = $obj->code_iso;
172 172
 				$this->label = $obj->label;
173 173
 				$this->active = $obj->active;
174 174
 
175
-                $this->db->free($resql);
176
-                return 1;
177
-            }
178
-            else {
179
-                return 0;
180
-            }
181
-        }
182
-        else
183
-        {
184
-      	    $this->error="Error ".$this->db->lasterror();
185
-            return -1;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     *  Update object into database
192
-     *
193
-     *  @param      User	$user        User that modify
194
-     *  @param      int		$notrigger	 0=launch triggers after, 1=disable triggers
195
-     *  @return     int     		   	 <0 if KO, >0 if OK
196
-     */
197
-    function update($user=null, $notrigger=0)
198
-    {
199
-    	global $conf, $langs;
175
+				$this->db->free($resql);
176
+				return 1;
177
+			}
178
+			else {
179
+				return 0;
180
+			}
181
+		}
182
+		else
183
+		{
184
+	  		$this->error="Error ".$this->db->lasterror();
185
+			return -1;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 *  Update object into database
192
+	 *
193
+	 *  @param      User	$user        User that modify
194
+	 *  @param      int		$notrigger	 0=launch triggers after, 1=disable triggers
195
+	 *  @return     int     		   	 <0 if KO, >0 if OK
196
+	 */
197
+	function update($user=null, $notrigger=0)
198
+	{
199
+		global $conf, $langs;
200 200
 		$error=0;
201 201
 
202 202
 		// Clean parameters
@@ -209,43 +209,43 @@  discard block
 block discarded – undo
209 209
 		// Check parameters
210 210
 		// Put here code to add control on parameters values
211 211
 
212
-        // Update request
213
-        $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET";
212
+		// Update request
213
+		$sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET";
214 214
 		$sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
215 215
 		$sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").",";
216 216
 		$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
217 217
 		$sql.= " active=".(isset($this->active)?$this->active:"null")."";
218
-        $sql.= " WHERE rowid=".$this->id;
218
+		$sql.= " WHERE rowid=".$this->id;
219 219
 
220 220
 		$this->db->begin();
221 221
 
222 222
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
223
-        $resql = $this->db->query($sql);
224
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
223
+		$resql = $this->db->query($sql);
224
+		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
225 225
 
226 226
 		if (! $error)
227 227
 		{
228 228
 			if (! $notrigger)
229 229
 			{
230
-	            // Uncomment this and change MYOBJECT to your own tag if you
231
-	            // want this action call a trigger.
232
-
233
-	            //// Call triggers
234
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
235
-	            //$interface=new Interfaces($this->db);
236
-	            //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
237
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
238
-	            //// End call triggers
239
-	    	}
230
+				// Uncomment this and change MYOBJECT to your own tag if you
231
+				// want this action call a trigger.
232
+
233
+				//// Call triggers
234
+				//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
235
+				//$interface=new Interfaces($this->db);
236
+				//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
237
+				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
238
+				//// End call triggers
239
+			}
240 240
 		}
241 241
 
242
-        // Commit or rollback
242
+		// Commit or rollback
243 243
 		if ($error)
244 244
 		{
245 245
 			foreach($this->errors as $errmsg)
246 246
 			{
247
-	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
248
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
247
+				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
248
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
249 249
 			}
250 250
 			$this->db->rollback();
251 251
 			return -1*$error;
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
 			$this->db->commit();
256 256
 			return 1;
257 257
 		}
258
-    }
258
+	}
259 259
 
260 260
 
261 261
  	/**
262 262
  	 *  Delete object in database
263
-	 *
264
-     *	@param  User	$user        User that delete
265
-     *  @param	int		$notrigger	 0=launch triggers after, 1=disable triggers
266
-	 *  @return	int					 <0 if KO, >0 if OK
267
-	 */
263
+ 	 *
264
+ 	 *	@param  User	$user        User that delete
265
+ 	 *  @param	int		$notrigger	 0=launch triggers after, 1=disable triggers
266
+ 	 *  @return	int					 <0 if KO, >0 if OK
267
+ 	 */
268 268
 	function delete($user, $notrigger=0)
269 269
 	{
270 270
 		global $conf, $langs;
@@ -277,31 +277,31 @@  discard block
 block discarded – undo
277 277
 
278 278
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
279 279
 		$resql = $this->db->query($sql);
280
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
280
+		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
281 281
 
282 282
 		if (! $error)
283 283
 		{
284 284
 			if (! $notrigger)
285 285
 			{
286 286
 				// Uncomment this and change MYOBJECT to your own tag if you
287
-		        // want this action call a trigger.
288
-
289
-		        //// Call triggers
290
-		        //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
291
-		        //$interface=new Interfaces($this->db);
292
-		        //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
293
-		        //if ($result < 0) { $error++; $this->errors=$interface->errors; }
294
-		        //// End call triggers
287
+				// want this action call a trigger.
288
+
289
+				//// Call triggers
290
+				//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
291
+				//$interface=new Interfaces($this->db);
292
+				//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
293
+				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
294
+				//// End call triggers
295 295
 			}
296 296
 		}
297 297
 
298
-        // Commit or rollback
298
+		// Commit or rollback
299 299
 		if ($error)
300 300
 		{
301 301
 			foreach($this->errors as $errmsg)
302 302
 			{
303
-	            dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
304
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
303
+				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
304
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
305 305
 			}
306 306
 			$this->db->rollback();
307 307
 			return -1*$error;
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class Ccountry // extends CommonObject
34 34
 {
35
-	var $db;							//!< To store db handler
36
-	var $error;							//!< To return error code (or message)
37
-	var $errors=array();				//!< To return several error codes (or messages)
35
+	var $db; //!< To store db handler
36
+	var $error; //!< To return error code (or message)
37
+	var $errors = array(); //!< To return several error codes (or messages)
38 38
 	//var $element='ccountry';			//!< Id that identify managed objects
39 39
 	//var $table_element='ccountry';	//!< Name of table without prefix where object is stored
40 40
 
@@ -66,46 +66,46 @@  discard block
 block discarded – undo
66 66
      *  @param      int		$notrigger   0=launch triggers after, 1=disable triggers
67 67
      *  @return     int      		   	 <0 if KO, Id of created object if OK
68 68
      */
69
-    function create($user, $notrigger=0)
69
+    function create($user, $notrigger = 0)
70 70
     {
71 71
     	global $conf, $langs;
72
-		$error=0;
72
+		$error = 0;
73 73
 
74 74
 		// Clean parameters
75
-		if (isset($this->code)) $this->code=trim($this->code);
76
-		if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso);
77
-		if (isset($this->label)) $this->label=trim($this->label);
78
-		if (isset($this->active)) $this->active=trim($this->active);
75
+		if (isset($this->code)) $this->code = trim($this->code);
76
+		if (isset($this->code_iso)) $this->code_iso = trim($this->code_iso);
77
+		if (isset($this->label)) $this->label = trim($this->label);
78
+		if (isset($this->active)) $this->active = trim($this->active);
79 79
 
80 80
 		// Check parameters
81 81
 		// Put here code to add control on parameters values
82 82
 
83 83
         // Insert request
84 84
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country(";
85
-		$sql.= "rowid,";
86
-		$sql.= "code,";
87
-		$sql.= "code_iso,";
88
-		$sql.= "label,";
89
-		$sql.= "active";
90
-        $sql.= ") VALUES (";
91
-		$sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").",";
92
-		$sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
93
-		$sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").",";
94
-		$sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
95
-		$sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'")."";
96
-		$sql.= ")";
85
+		$sql .= "rowid,";
86
+		$sql .= "code,";
87
+		$sql .= "code_iso,";
88
+		$sql .= "label,";
89
+		$sql .= "active";
90
+        $sql .= ") VALUES (";
91
+		$sql .= " ".(!isset($this->rowid) ? 'NULL' : "'".$this->db->escape($this->rowid)."'").",";
92
+		$sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
93
+		$sql .= " ".(!isset($this->code_iso) ? 'NULL' : "'".$this->db->escape($this->code_iso)."'").",";
94
+		$sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
95
+		$sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'")."";
96
+		$sql .= ")";
97 97
 
98 98
 		$this->db->begin();
99 99
 
100 100
 	   	dol_syslog(get_class($this)."::create", LOG_DEBUG);
101
-        $resql=$this->db->query($sql);
102
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
101
+        $resql = $this->db->query($sql);
102
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
103 103
 
104
-		if (! $error)
104
+		if (!$error)
105 105
         {
106 106
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country");
107 107
 
108
-			if (! $notrigger)
108
+			if (!$notrigger)
109 109
 			{
110 110
 	            // Uncomment this and change MYOBJECT to your own tag if you
111 111
 	            // want this action call a trigger.
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
         // Commit or rollback
123 123
         if ($error)
124 124
 		{
125
-			foreach($this->errors as $errmsg)
125
+			foreach ($this->errors as $errmsg)
126 126
 			{
127 127
 	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
128
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
128
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
129 129
 			}
130 130
 			$this->db->rollback();
131
-			return -1*$error;
131
+			return -1 * $error;
132 132
 		}
133 133
 		else
134 134
 		{
@@ -145,28 +145,28 @@  discard block
 block discarded – undo
145 145
      *  @param		string	$code	Code
146 146
      *  @return     int          	>0 if OK, 0 if not found, <0 if KO
147 147
      */
148
-    function fetch($id,$code='')
148
+    function fetch($id, $code = '')
149 149
     {
150 150
     	global $langs;
151 151
         $sql = "SELECT";
152
-		$sql.= " t.rowid,";
153
-		$sql.= " t.code,";
154
-		$sql.= " t.code_iso,";
155
-		$sql.= " t.label,";
156
-		$sql.= " t.active";
157
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_country as t";
158
-        if ($id)   $sql.= " WHERE t.rowid = ".$id;
159
-        elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
152
+		$sql .= " t.rowid,";
153
+		$sql .= " t.code,";
154
+		$sql .= " t.code_iso,";
155
+		$sql .= " t.label,";
156
+		$sql .= " t.active";
157
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_country as t";
158
+        if ($id)   $sql .= " WHERE t.rowid = ".$id;
159
+        elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
160 160
 
161 161
     	dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
162
-        $resql=$this->db->query($sql);
162
+        $resql = $this->db->query($sql);
163 163
         if ($resql)
164 164
         {
165 165
             if ($this->db->num_rows($resql))
166 166
             {
167 167
                 $obj = $this->db->fetch_object($resql);
168 168
 
169
-                $this->id    = $obj->rowid;
169
+                $this->id = $obj->rowid;
170 170
 				$this->code = $obj->code;
171 171
 				$this->code_iso = $obj->code_iso;
172 172
 				$this->label = $obj->label;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         }
182 182
         else
183 183
         {
184
-      	    $this->error="Error ".$this->db->lasterror();
184
+      	    $this->error = "Error ".$this->db->lasterror();
185 185
             return -1;
186 186
         }
187 187
     }
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
      *  @param      int		$notrigger	 0=launch triggers after, 1=disable triggers
195 195
      *  @return     int     		   	 <0 if KO, >0 if OK
196 196
      */
197
-    function update($user=null, $notrigger=0)
197
+    function update($user = null, $notrigger = 0)
198 198
     {
199 199
     	global $conf, $langs;
200
-		$error=0;
200
+		$error = 0;
201 201
 
202 202
 		// Clean parameters
203
-		if (isset($this->code)) $this->code=trim($this->code);
204
-		if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso);
205
-		if (isset($this->label)) $this->label=trim($this->label);
206
-		if (isset($this->active)) $this->active=trim($this->active);
203
+		if (isset($this->code)) $this->code = trim($this->code);
204
+		if (isset($this->code_iso)) $this->code_iso = trim($this->code_iso);
205
+		if (isset($this->label)) $this->label = trim($this->label);
206
+		if (isset($this->active)) $this->active = trim($this->active);
207 207
 
208 208
 
209 209
 		// Check parameters
@@ -211,21 +211,21 @@  discard block
 block discarded – undo
211 211
 
212 212
         // Update request
213 213
         $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET";
214
-		$sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
215
-		$sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").",";
216
-		$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
217
-		$sql.= " active=".(isset($this->active)?$this->active:"null")."";
218
-        $sql.= " WHERE rowid=".$this->id;
214
+		$sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
215
+		$sql .= " code_iso=".(isset($this->code_iso) ? "'".$this->db->escape($this->code_iso)."'" : "null").",";
216
+		$sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
217
+		$sql .= " active=".(isset($this->active) ? $this->active : "null")."";
218
+        $sql .= " WHERE rowid=".$this->id;
219 219
 
220 220
 		$this->db->begin();
221 221
 
222 222
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
223 223
         $resql = $this->db->query($sql);
224
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
224
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
225 225
 
226
-		if (! $error)
226
+		if (!$error)
227 227
 		{
228
-			if (! $notrigger)
228
+			if (!$notrigger)
229 229
 			{
230 230
 	            // Uncomment this and change MYOBJECT to your own tag if you
231 231
 	            // want this action call a trigger.
@@ -242,13 +242,13 @@  discard block
 block discarded – undo
242 242
         // Commit or rollback
243 243
 		if ($error)
244 244
 		{
245
-			foreach($this->errors as $errmsg)
245
+			foreach ($this->errors as $errmsg)
246 246
 			{
247 247
 	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
248
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
248
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
249 249
 			}
250 250
 			$this->db->rollback();
251
-			return -1*$error;
251
+			return -1 * $error;
252 252
 		}
253 253
 		else
254 254
 		{
@@ -265,23 +265,23 @@  discard block
 block discarded – undo
265 265
      *  @param	int		$notrigger	 0=launch triggers after, 1=disable triggers
266 266
 	 *  @return	int					 <0 if KO, >0 if OK
267 267
 	 */
268
-	function delete($user, $notrigger=0)
268
+	function delete($user, $notrigger = 0)
269 269
 	{
270 270
 		global $conf, $langs;
271
-		$error=0;
271
+		$error = 0;
272 272
 
273 273
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country";
274
-		$sql.= " WHERE rowid=".$this->id;
274
+		$sql .= " WHERE rowid=".$this->id;
275 275
 
276 276
 		$this->db->begin();
277 277
 
278 278
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
279 279
 		$resql = $this->db->query($sql);
280
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
280
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
281 281
 
282
-		if (! $error)
282
+		if (!$error)
283 283
 		{
284
-			if (! $notrigger)
284
+			if (!$notrigger)
285 285
 			{
286 286
 				// Uncomment this and change MYOBJECT to your own tag if you
287 287
 		        // want this action call a trigger.
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
         // Commit or rollback
299 299
 		if ($error)
300 300
 		{
301
-			foreach($this->errors as $errmsg)
301
+			foreach ($this->errors as $errmsg)
302 302
 			{
303 303
 	            dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
304
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
304
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
305 305
 			}
306 306
 			$this->db->rollback();
307
-			return -1*$error;
307
+			return -1 * $error;
308 308
 		}
309 309
 		else
310 310
 		{
Please login to merge, or discard this patch.
htdocs/core/class/coreobject.class.php 3 patches
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -34,23 +34,23 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	protected $fields=array();
36 36
 
37
-    /**
37
+	/**
38 38
 	 *  Constructor
39 39
 	 *
40 40
 	 *  @param      DoliDB		$db      Database handler
41 41
 	 */
42 42
 	function __construct(DoliDB &$db)
43
-    {
44
-        $this->db = $db;
43
+	{
44
+		$this->db = $db;
45 45
 	}
46 46
 
47
-    /**
48
-     * Function to init fields
49
-     *
50
-     * @return bool
51
-     */
47
+	/**
48
+	 * Function to init fields
49
+	 *
50
+	 * @return bool
51
+	 */
52 52
 	protected function init()
53
-    {
53
+	{
54 54
 		$this->id = 0;
55 55
 		$this->datec = 0;
56 56
 		$this->tms = 0;
@@ -59,73 +59,73 @@  discard block
 block discarded – undo
59 59
 		{
60 60
 			foreach ($this->fields as $field=>$info)
61 61
 			{
62
-		        if ($this->isDate($info)) $this->{$field} = time();
63
-		        elseif ($this->isArray($info)) $this->{$field} = array();
64
-		        elseif ($this->isInt($info)) $this->{$field} = (int) 0;
65
-		        elseif ($this->isFloat($info)) $this->{$field} = (double) 0;
62
+				if ($this->isDate($info)) $this->{$field} = time();
63
+				elseif ($this->isArray($info)) $this->{$field} = array();
64
+				elseif ($this->isInt($info)) $this->{$field} = (int) 0;
65
+				elseif ($this->isFloat($info)) $this->{$field} = (double) 0;
66 66
 				else $this->{$field} = '';
67
-		    }
67
+			}
68 68
 
69
-            $this->to_delete=false;
70
-            $this->is_clone=false;
69
+			$this->to_delete=false;
70
+			$this->is_clone=false;
71 71
 			
72 72
 			return true;
73 73
 		}
74 74
 		else
75
-        {
75
+		{
76 76
 			return false;
77 77
 		}
78 78
 			
79 79
 	}
80 80
 
81
-    /**
82
-     * Test type of field
83
-     *
84
-     * @param   string  $field  name of field
85
-     * @param   string  $type   type of field to test
86
-     * @return                  value of field or false
87
-     */
88
-    private function checkFieldType($field, $type)
89
-    {
81
+	/**
82
+	 * Test type of field
83
+	 *
84
+	 * @param   string  $field  name of field
85
+	 * @param   string  $type   type of field to test
86
+	 * @return                  value of field or false
87
+	 */
88
+	private function checkFieldType($field, $type)
89
+	{
90 90
 		if (isset($this->fields[$field]) && method_exists($this, 'is_'.$type))
91 91
 		{
92 92
 			return $this->{'is_'.$type}($this->fields[$field]);
93 93
 		}
94 94
 		else
95
-        {
96
-            return false;
97
-        }
95
+		{
96
+			return false;
97
+		}
98 98
 	}
99 99
 
100
-    /**
101
-     *	Get object and children from database
102
-     *
103
-     *	@param      int			$id       		Id of object to load
104
-     * 	@param		bool		$loadChild		used to load children from database
105
-     *	@return     int         				>0 if OK, <0 if KO, 0 if not found
106
-     */
100
+	/**
101
+	 *	Get object and children from database
102
+	 *
103
+	 *	@param      int			$id       		Id of object to load
104
+	 * 	@param		bool		$loadChild		used to load children from database
105
+	 *	@return     int         				>0 if OK, <0 if KO, 0 if not found
106
+	 */
107 107
 	public function fetch($id, $loadChild = true)
108
-    {
109
-    	$res = $this->fetchCommon($id);
110
-    	if($res>0) {
111
-    		if ($loadChild) $this->fetchChild();
112
-    	}
108
+	{
109
+		$res = $this->fetchCommon($id);
110
+		if($res>0) {
111
+			if ($loadChild) $this->fetchChild();
112
+		}
113 113
     	
114
-    	return $res;
114
+		return $res;
115 115
 	}
116 116
 
117 117
 
118
-    /**
119
-     * Function to instantiate a new child
120
-     *
121
-     * @param   string  $tabName        Table name of child
122
-     * @param   int     $id             If id is given, we try to return his key if exist or load if we try_to_load
123
-     * @param   string  $key            Attribute name of the object id
124
-     * @param   bool    $try_to_load    Force the fetch if an id is given
125
-     * @return                          int
126
-     */
127
-    public function addChild($tabName, $id=0, $key='id', $try_to_load = false)
128
-    {
118
+	/**
119
+	 * Function to instantiate a new child
120
+	 *
121
+	 * @param   string  $tabName        Table name of child
122
+	 * @param   int     $id             If id is given, we try to return his key if exist or load if we try_to_load
123
+	 * @param   string  $key            Attribute name of the object id
124
+	 * @param   bool    $try_to_load    Force the fetch if an id is given
125
+	 * @return                          int
126
+	 */
127
+	public function addChild($tabName, $id=0, $key='id', $try_to_load = false)
128
+	{
129 129
 		if(!empty($id))
130 130
 		{
131 131
 			foreach($this->{$tabName} as $k=>&$object)
@@ -147,16 +147,16 @@  discard block
 block discarded – undo
147 147
 	}
148 148
 
149 149
 
150
-    /**
151
-     * Function to set a child as to delete
152
-     *
153
-     * @param   string  $tabName        Table name of child
154
-     * @param   int     $id             Id of child to set as to delete
155
-     * @param   string  $key            Attribute name of the object id
156
-     * @return                          bool
157
-     */
158
-    public function removeChild($tabName, $id, $key='id')
159
-    {
150
+	/**
151
+	 * Function to set a child as to delete
152
+	 *
153
+	 * @param   string  $tabName        Table name of child
154
+	 * @param   int     $id             Id of child to set as to delete
155
+	 * @param   string  $key            Attribute name of the object id
156
+	 * @return                          bool
157
+	 */
158
+	public function removeChild($tabName, $id, $key='id')
159
+	{
160 160
 		foreach ($this->{$tabName} as &$object)
161 161
 		{
162 162
 			if ($object->{$key} == $id)
@@ -169,47 +169,47 @@  discard block
 block discarded – undo
169 169
 	}
170 170
 
171 171
 
172
-    /**
173
-     * Function to fetch children objects
174
-     */
175
-    public function fetchChild()
176
-    {
172
+	/**
173
+	 * Function to fetch children objects
174
+	 */
175
+	public function fetchChild()
176
+	{
177 177
 		if($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
178 178
 		{
179 179
 			foreach($this->childtables as &$childTable)
180 180
 			{
181
-                $className = ucfirst($childTable);
182
-
183
-                $this->{$className}=array();
184
-
185
-                $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$childTable.' WHERE '.$this->fk_element.' = '.$this->id;
186
-                $res = $this->db->query($sql);
187
-
188
-                if($res)
189
-                {
190
-                    while($obj = $this->db->fetch_object($res))
191
-                    {
192
-                        $o=new $className($this->db);
193
-                        $o->fetch($obj->rowid);
194
-
195
-                        $this->{$className}[] = $o;
196
-                    }
197
-                }
198
-                else
199
-                {
200
-                    $this->errors[] = $this->db->lasterror();
201
-                }
181
+				$className = ucfirst($childTable);
182
+
183
+				$this->{$className}=array();
184
+
185
+				$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$childTable.' WHERE '.$this->fk_element.' = '.$this->id;
186
+				$res = $this->db->query($sql);
187
+
188
+				if($res)
189
+				{
190
+					while($obj = $this->db->fetch_object($res))
191
+					{
192
+						$o=new $className($this->db);
193
+						$o->fetch($obj->rowid);
194
+
195
+						$this->{$className}[] = $o;
196
+					}
197
+				}
198
+				else
199
+				{
200
+					$this->errors[] = $this->db->lasterror();
201
+				}
202 202
 			}
203 203
 		}
204 204
 	}
205 205
 
206
-    /**
207
-     * Function to update children data
208
-     *
209
-     * @param   User    $user   user object
210
-     */
206
+	/**
207
+	 * Function to update children data
208
+	 *
209
+	 * @param   User    $user   user object
210
+	 */
211 211
 	public function saveChild(User &$user)
212
-    {
212
+	{
213 213
 		if($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
214 214
 		{
215 215
 			foreach($this->childtables as &$childTable)
@@ -230,169 +230,169 @@  discard block
 block discarded – undo
230 230
 	}
231 231
 
232 232
 
233
-    /**
234
-     * Function to update object or create or delete if needed
235
-     *
236
-     * @param   User    $user   user object
237
-     * @return                  < 0 if ko, > 0 if ok
238
-     */
239
-    public function update(User &$user)
240
-    {
233
+	/**
234
+	 * Function to update object or create or delete if needed
235
+	 *
236
+	 * @param   User    $user   user object
237
+	 * @return                  < 0 if ko, > 0 if ok
238
+	 */
239
+	public function update(User &$user)
240
+	{
241 241
 		if (empty($this->id)) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed
242
-        elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user);
243
-
244
-        $error = 0;
245
-        $this->db->begin();
246
-
247
-        $res = $this->updateCommon($user);
248
-        if ($res)
249
-        {
250
-            $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
251
-            if ($result < 0) $error++;
252
-            else $this->saveChild($user);
253
-        }
254
-        else
255
-        {
256
-            $error++;
257
-            $this->error = $this->db->lasterror();
258
-            $this->errors[] = $this->error;
259
-        }
260
-
261
-        if (empty($error))
262
-        {
263
-            $this->db->commit();
264
-            return $this->id;
265
-        }
266
-        else
267
-        {
268
-            $this->db->rollback();
269
-            return -1;
270
-        }
242
+		elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user);
243
+
244
+		$error = 0;
245
+		$this->db->begin();
246
+
247
+		$res = $this->updateCommon($user);
248
+		if ($res)
249
+		{
250
+			$result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
251
+			if ($result < 0) $error++;
252
+			else $this->saveChild($user);
253
+		}
254
+		else
255
+		{
256
+			$error++;
257
+			$this->error = $this->db->lasterror();
258
+			$this->errors[] = $this->error;
259
+		}
260
+
261
+		if (empty($error))
262
+		{
263
+			$this->db->commit();
264
+			return $this->id;
265
+		}
266
+		else
267
+		{
268
+			$this->db->rollback();
269
+			return -1;
270
+		}
271 271
 
272 272
 	}
273 273
 
274
-    /**
275
-     * Function to create object in database
276
-     *
277
-     * @param   User    $user   user object
278
-     * @return                  < 0 if ko, > 0 if ok
279
-     */
280
-    public function create(User &$user)
281
-    {
274
+	/**
275
+	 * Function to create object in database
276
+	 *
277
+	 * @param   User    $user   user object
278
+	 * @return                  < 0 if ko, > 0 if ok
279
+	 */
280
+	public function create(User &$user)
281
+	{
282 282
 		if($this->id > 0) return $this->update($user);
283 283
 
284
-        $error = 0;
285
-        $this->db->begin();
284
+		$error = 0;
285
+		$this->db->begin();
286 286
 
287
-        $res = $this->createCommon($user);
287
+		$res = $this->createCommon($user);
288 288
 		if($res)
289 289
 		{
290 290
 			$this->id = $this->db->last_insert_id($this->table_element);
291 291
 
292 292
 			$result = $this->call_trigger(strtoupper($this->element). '_CREATE', $user);
293
-            if ($result < 0) $error++;
294
-            else $this->saveChild($user);
293
+			if ($result < 0) $error++;
294
+			else $this->saveChild($user);
295 295
 		}
296 296
 		else
297
-        {
298
-            $error++;
299
-            $this->error = $this->db->lasterror();
300
-            $this->errors[] = $this->error;
297
+		{
298
+			$error++;
299
+			$this->error = $this->db->lasterror();
300
+			$this->errors[] = $this->error;
301 301
 		}
302 302
 
303
-        if (empty($error))
304
-        {
305
-            $this->db->commit();
306
-            return $this->id;
307
-        }
308
-        else
309
-        {
310
-            $this->db->rollback();
311
-            return -1;
312
-        }
303
+		if (empty($error))
304
+		{
305
+			$this->db->commit();
306
+			return $this->id;
307
+		}
308
+		else
309
+		{
310
+			$this->db->rollback();
311
+			return -1;
312
+		}
313 313
 	}
314 314
 
315
-    /**
316
-     * Function to delete object in database
317
-     *
318
-     * @param   User    $user   user object
319
-     * @return                  < 0 if ko, > 0 if ok
320
-     */
315
+	/**
316
+	 * Function to delete object in database
317
+	 *
318
+	 * @param   User    $user   user object
319
+	 * @return                  < 0 if ko, > 0 if ok
320
+	 */
321 321
 	public function delete(User &$user)
322
-    {
322
+	{
323 323
 		if ($this->id <= 0) return 0;
324 324
 
325
-        $error = 0;
326
-        $this->db->begin();
327
-
328
-        $result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user);
329
-        if ($result < 0) $error++;
330
-
331
-        if (!$error)
332
-        {
333
-            $this->deleteCommon($user);
334
-            if($this->withChild && !empty($this->childtables))
335
-            {
336
-                foreach($this->childtables as &$childTable)
337
-                {
338
-                    $className = ucfirst($childTable);
339
-                    if (!empty($this->{$className}))
340
-                    {
341
-                        foreach($this->{$className} as &$object)
342
-                        {
343
-                            $object->delete($user);
344
-                        }
345
-                    }
346
-                }
347
-            }
348
-        }
349
-
350
-        if (empty($error))
351
-        {
352
-            $this->db->commit();
353
-            return 1;
354
-        }
355
-        else
356
-        {
357
-            $this->error = $this->db->lasterror();
358
-            $this->errors[] = $this->error;
359
-            $this->db->rollback();
360
-            return -1;
361
-        }
325
+		$error = 0;
326
+		$this->db->begin();
327
+
328
+		$result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user);
329
+		if ($result < 0) $error++;
330
+
331
+		if (!$error)
332
+		{
333
+			$this->deleteCommon($user);
334
+			if($this->withChild && !empty($this->childtables))
335
+			{
336
+				foreach($this->childtables as &$childTable)
337
+				{
338
+					$className = ucfirst($childTable);
339
+					if (!empty($this->{$className}))
340
+					{
341
+						foreach($this->{$className} as &$object)
342
+						{
343
+							$object->delete($user);
344
+						}
345
+					}
346
+				}
347
+			}
348
+		}
349
+
350
+		if (empty($error))
351
+		{
352
+			$this->db->commit();
353
+			return 1;
354
+		}
355
+		else
356
+		{
357
+			$this->error = $this->db->lasterror();
358
+			$this->errors[] = $this->error;
359
+			$this->db->rollback();
360
+			return -1;
361
+		}
362 362
 	}
363 363
 
364 364
 
365
-    /**
366
-     * Function to get a formatted date
367
-     *
368
-     * @param   string  $field  Attribute to return
369
-     * @param   string  $format Output date format
370
-     * @return          string
371
-     */
372
-    public function getDate($field, $format='')
373
-    {
365
+	/**
366
+	 * Function to get a formatted date
367
+	 *
368
+	 * @param   string  $field  Attribute to return
369
+	 * @param   string  $format Output date format
370
+	 * @return          string
371
+	 */
372
+	public function getDate($field, $format='')
373
+	{
374 374
 		if(empty($this->{$field})) return '';
375 375
 		else
376
-        {
376
+		{
377 377
 			return dol_print_date($this->{$field}, $format);
378 378
 		}
379 379
 	}
380 380
 
381
-    /**
382
-     * Function to set date in field
383
-     *
384
-     * @param   string  $field  field to set
385
-     * @param   string  $date   formatted date to convert
386
-     * @return                  mixed
387
-     */
388
-    public function setDate($field, $date)
389
-    {
381
+	/**
382
+	 * Function to set date in field
383
+	 *
384
+	 * @param   string  $field  field to set
385
+	 * @param   string  $date   formatted date to convert
386
+	 * @return                  mixed
387
+	 */
388
+	public function setDate($field, $date)
389
+	{
390 390
 	  	if (empty($date))
391 391
 	  	{
392 392
 	  		$this->{$field} = 0;
393 393
 	  	}
394 394
 		else
395
-        {
395
+		{
396 396
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
397 397
 			$this->{$field} = dol_stringtotime($date);
398 398
 		}
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
 	}
402 402
 
403 403
 
404
-    /**
405
-     * Function to update current object
406
-     *
407
-     * @param   array   $Tab    Array of values
408
-     * @return                  int
409
-     */
410
-    public function setValues(&$Tab)
411
-    {
404
+	/**
405
+	 * Function to update current object
406
+	 *
407
+	 * @param   array   $Tab    Array of values
408
+	 * @return                  int
409
+	 */
410
+	public function setValues(&$Tab)
411
+	{
412 412
 		foreach ($Tab as $key => $value)
413 413
 		{
414 414
 			if($this->checkFieldType($key, 'date'))
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 				$this->{$key} = (int) price2num($value);
428 428
 			}
429 429
 			else
430
-            {
430
+			{
431 431
 				$this->{$key} = $value;
432 432
 			}
433 433
 		}
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 *  @var Array $_fields Fields to synchronize with Database
34 34
 	 */
35
-	protected $fields=array();
35
+	protected $fields = array();
36 36
 
37 37
     /**
38 38
 	 *  Constructor
39 39
 	 *
40 40
 	 *  @param      DoliDB		$db      Database handler
41 41
 	 */
42
-	function __construct(DoliDB &$db)
42
+	function __construct(DoliDB & $db)
43 43
     {
44 44
         $this->db = $db;
45 45
 	}
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 				else $this->{$field} = '';
67 67
 		    }
68 68
 
69
-            $this->to_delete=false;
70
-            $this->is_clone=false;
69
+            $this->to_delete = false;
70
+            $this->is_clone = false;
71 71
 			
72 72
 			return true;
73 73
 		}
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	public function fetch($id, $loadChild = true)
108 108
     {
109 109
     	$res = $this->fetchCommon($id);
110
-    	if($res>0) {
110
+    	if ($res > 0) {
111 111
     		if ($loadChild) $this->fetchChild();
112 112
     	}
113 113
     	
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
      * @param   bool    $try_to_load    Force the fetch if an id is given
125 125
      * @return                          int
126 126
      */
127
-    public function addChild($tabName, $id=0, $key='id', $try_to_load = false)
127
+    public function addChild($tabName, $id = 0, $key = 'id', $try_to_load = false)
128 128
     {
129
-		if(!empty($id))
129
+		if (!empty($id))
130 130
 		{
131
-			foreach($this->{$tabName} as $k=>&$object)
131
+			foreach ($this->{$tabName} as $k=>&$object)
132 132
 			{
133
-				if($object->{$key} === $id) return $k;
133
+				if ($object->{$key} === $id) return $k;
134 134
 			}
135 135
 		}
136 136
 	
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	
139 139
 		$className = ucfirst($tabName);
140 140
 		$this->{$tabName}[$k] = new $className($this->db);
141
-		if($id>0 && $key==='id' && $try_to_load)
141
+		if ($id > 0 && $key === 'id' && $try_to_load)
142 142
 		{
143 143
 			$this->{$tabName}[$k]->fetch($id); 
144 144
 		}
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * @param   string  $key            Attribute name of the object id
156 156
      * @return                          bool
157 157
      */
158
-    public function removeChild($tabName, $id, $key='id')
158
+    public function removeChild($tabName, $id, $key = 'id')
159 159
     {
160 160
 		foreach ($this->{$tabName} as &$object)
161 161
 		{
@@ -174,22 +174,22 @@  discard block
 block discarded – undo
174 174
      */
175 175
     public function fetchChild()
176 176
     {
177
-		if($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
177
+		if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
178 178
 		{
179
-			foreach($this->childtables as &$childTable)
179
+			foreach ($this->childtables as &$childTable)
180 180
 			{
181 181
                 $className = ucfirst($childTable);
182 182
 
183
-                $this->{$className}=array();
183
+                $this->{$className} = array();
184 184
 
185 185
                 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$childTable.' WHERE '.$this->fk_element.' = '.$this->id;
186 186
                 $res = $this->db->query($sql);
187 187
 
188
-                if($res)
188
+                if ($res)
189 189
                 {
190
-                    while($obj = $this->db->fetch_object($res))
190
+                    while ($obj = $this->db->fetch_object($res))
191 191
                     {
192
-                        $o=new $className($this->db);
192
+                        $o = new $className($this->db);
193 193
                         $o->fetch($obj->rowid);
194 194
 
195 195
                         $this->{$className}[] = $o;
@@ -208,21 +208,21 @@  discard block
 block discarded – undo
208 208
      *
209 209
      * @param   User    $user   user object
210 210
      */
211
-	public function saveChild(User &$user)
211
+	public function saveChild(User & $user)
212 212
     {
213
-		if($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
213
+		if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
214 214
 		{
215
-			foreach($this->childtables as &$childTable)
215
+			foreach ($this->childtables as &$childTable)
216 216
 			{
217 217
 				$className = ucfirst($childTable);
218
-				if(!empty($this->{$className}))
218
+				if (!empty($this->{$className}))
219 219
 				{
220
-					foreach($this->{$className} as $i => &$object)
220
+					foreach ($this->{$className} as $i => &$object)
221 221
 					{
222 222
 						$object->{$this->fk_element} = $this->id;
223 223
 						
224 224
 						$object->update($user);
225
-						if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]);
225
+						if ($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete == true) unset($this->{$className}[$i]);
226 226
 					}
227 227
 				}
228 228
 			}
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
      * @param   User    $user   user object
237 237
      * @return                  < 0 if ko, > 0 if ok
238 238
      */
239
-    public function update(User &$user)
239
+    public function update(User & $user)
240 240
     {
241 241
 		if (empty($this->id)) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed
242
-        elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user);
242
+        elseif (isset($this->to_delete) && $this->to_delete == true) return $this->delete($user);
243 243
 
244 244
         $error = 0;
245 245
         $this->db->begin();
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         $res = $this->updateCommon($user);
248 248
         if ($res)
249 249
         {
250
-            $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
250
+            $result = $this->call_trigger(strtoupper($this->element).'_UPDATE', $user);
251 251
             if ($result < 0) $error++;
252 252
             else $this->saveChild($user);
253 253
         }
@@ -277,19 +277,19 @@  discard block
 block discarded – undo
277 277
      * @param   User    $user   user object
278 278
      * @return                  < 0 if ko, > 0 if ok
279 279
      */
280
-    public function create(User &$user)
280
+    public function create(User & $user)
281 281
     {
282
-		if($this->id > 0) return $this->update($user);
282
+		if ($this->id > 0) return $this->update($user);
283 283
 
284 284
         $error = 0;
285 285
         $this->db->begin();
286 286
 
287 287
         $res = $this->createCommon($user);
288
-		if($res)
288
+		if ($res)
289 289
 		{
290 290
 			$this->id = $this->db->last_insert_id($this->table_element);
291 291
 
292
-			$result = $this->call_trigger(strtoupper($this->element). '_CREATE', $user);
292
+			$result = $this->call_trigger(strtoupper($this->element).'_CREATE', $user);
293 293
             if ($result < 0) $error++;
294 294
             else $this->saveChild($user);
295 295
 		}
@@ -318,27 +318,27 @@  discard block
 block discarded – undo
318 318
      * @param   User    $user   user object
319 319
      * @return                  < 0 if ko, > 0 if ok
320 320
      */
321
-	public function delete(User &$user)
321
+	public function delete(User & $user)
322 322
     {
323 323
 		if ($this->id <= 0) return 0;
324 324
 
325 325
         $error = 0;
326 326
         $this->db->begin();
327 327
 
328
-        $result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user);
328
+        $result = $this->call_trigger(strtoupper($this->element).'_DELETE', $user);
329 329
         if ($result < 0) $error++;
330 330
 
331 331
         if (!$error)
332 332
         {
333 333
             $this->deleteCommon($user);
334
-            if($this->withChild && !empty($this->childtables))
334
+            if ($this->withChild && !empty($this->childtables))
335 335
             {
336
-                foreach($this->childtables as &$childTable)
336
+                foreach ($this->childtables as &$childTable)
337 337
                 {
338 338
                     $className = ucfirst($childTable);
339 339
                     if (!empty($this->{$className}))
340 340
                     {
341
-                        foreach($this->{$className} as &$object)
341
+                        foreach ($this->{$className} as &$object)
342 342
                         {
343 343
                             $object->delete($user);
344 344
                         }
@@ -369,9 +369,9 @@  discard block
 block discarded – undo
369 369
      * @param   string  $format Output date format
370 370
      * @return          string
371 371
      */
372
-    public function getDate($field, $format='')
372
+    public function getDate($field, $format = '')
373 373
     {
374
-		if(empty($this->{$field})) return '';
374
+		if (empty($this->{$field})) return '';
375 375
 		else
376 376
         {
377 377
 			return dol_print_date($this->{$field}, $format);
@@ -411,19 +411,19 @@  discard block
 block discarded – undo
411 411
     {
412 412
 		foreach ($Tab as $key => $value)
413 413
 		{
414
-			if($this->checkFieldType($key, 'date'))
414
+			if ($this->checkFieldType($key, 'date'))
415 415
 			{
416 416
 				$this->setDate($key, $value);
417 417
 			}
418
-			else if( $this->checkFieldType($key, 'array'))
418
+			else if ($this->checkFieldType($key, 'array'))
419 419
 			{
420 420
 				$this->{$key} = $value;
421 421
 			}
422
-			else if( $this->checkFieldType($key, 'float') )
422
+			else if ($this->checkFieldType($key, 'float'))
423 423
 			{
424 424
 				$this->{$key} = (double) price2num($value);
425 425
 			}
426
-			else if( $this->checkFieldType($key, 'int') ) {
426
+			else if ($this->checkFieldType($key, 'int')) {
427 427
 				$this->{$key} = (int) price2num($value);
428 428
 			}
429 429
 			else
Please login to merge, or discard this patch.
Braces   +62 added lines, -45 removed lines patch added patch discarded remove patch
@@ -59,19 +59,24 @@  discard block
 block discarded – undo
59 59
 		{
60 60
 			foreach ($this->fields as $field=>$info)
61 61
 			{
62
-		        if ($this->isDate($info)) $this->{$field} = time();
63
-		        elseif ($this->isArray($info)) $this->{$field} = array();
64
-		        elseif ($this->isInt($info)) $this->{$field} = (int) 0;
65
-		        elseif ($this->isFloat($info)) $this->{$field} = (double) 0;
66
-				else $this->{$field} = '';
62
+		        if ($this->isDate($info)) {
63
+		        	$this->{$field} = time();
64
+		        } elseif ($this->isArray($info)) {
65
+		        	$this->{$field} = array();
66
+		        } elseif ($this->isInt($info)) {
67
+		        	$this->{$field} = (int) 0;
68
+		        } elseif ($this->isFloat($info)) {
69
+		        	$this->{$field} = (double) 0;
70
+		        } else {
71
+					$this->{$field} = '';
72
+				}
67 73
 		    }
68 74
 
69 75
             $this->to_delete=false;
70 76
             $this->is_clone=false;
71 77
 			
72 78
 			return true;
73
-		}
74
-		else
79
+		} else
75 80
         {
76 81
 			return false;
77 82
 		}
@@ -90,8 +95,7 @@  discard block
 block discarded – undo
90 95
 		if (isset($this->fields[$field]) && method_exists($this, 'is_'.$type))
91 96
 		{
92 97
 			return $this->{'is_'.$type}($this->fields[$field]);
93
-		}
94
-		else
98
+		} else
95 99
         {
96 100
             return false;
97 101
         }
@@ -108,7 +112,9 @@  discard block
 block discarded – undo
108 112
     {
109 113
     	$res = $this->fetchCommon($id);
110 114
     	if($res>0) {
111
-    		if ($loadChild) $this->fetchChild();
115
+    		if ($loadChild) {
116
+    			$this->fetchChild();
117
+    		}
112 118
     	}
113 119
     	
114 120
     	return $res;
@@ -130,7 +136,9 @@  discard block
 block discarded – undo
130 136
 		{
131 137
 			foreach($this->{$tabName} as $k=>&$object)
132 138
 			{
133
-				if($object->{$key} === $id) return $k;
139
+				if($object->{$key} === $id) {
140
+					return $k;
141
+				}
134 142
 			}
135 143
 		}
136 144
 	
@@ -194,8 +202,7 @@  discard block
 block discarded – undo
194 202
 
195 203
                         $this->{$className}[] = $o;
196 204
                     }
197
-                }
198
-                else
205
+                } else
199 206
                 {
200 207
                     $this->errors[] = $this->db->lasterror();
201 208
                 }
@@ -222,7 +229,9 @@  discard block
 block discarded – undo
222 229
 						$object->{$this->fk_element} = $this->id;
223 230
 						
224 231
 						$object->update($user);
225
-						if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]);
232
+						if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) {
233
+							unset($this->{$className}[$i]);
234
+						}
226 235
 					}
227 236
 				}
228 237
 			}
@@ -238,8 +247,13 @@  discard block
 block discarded – undo
238 247
      */
239 248
     public function update(User &$user)
240 249
     {
241
-		if (empty($this->id)) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed
242
-        elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user);
250
+		if (empty($this->id)) {
251
+			return $this->create($user);
252
+		}
253
+		// To test, with that, no need to test on high level object, the core decide it, update just needed
254
+        elseif (isset($this->to_delete) && $this->to_delete==true) {
255
+        	return $this->delete($user);
256
+        }
243 257
 
244 258
         $error = 0;
245 259
         $this->db->begin();
@@ -248,10 +262,12 @@  discard block
 block discarded – undo
248 262
         if ($res)
249 263
         {
250 264
             $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
251
-            if ($result < 0) $error++;
252
-            else $this->saveChild($user);
253
-        }
254
-        else
265
+            if ($result < 0) {
266
+            	$error++;
267
+            } else {
268
+            	$this->saveChild($user);
269
+            }
270
+        } else
255 271
         {
256 272
             $error++;
257 273
             $this->error = $this->db->lasterror();
@@ -262,8 +278,7 @@  discard block
 block discarded – undo
262 278
         {
263 279
             $this->db->commit();
264 280
             return $this->id;
265
-        }
266
-        else
281
+        } else
267 282
         {
268 283
             $this->db->rollback();
269 284
             return -1;
@@ -279,7 +294,9 @@  discard block
 block discarded – undo
279 294
      */
280 295
     public function create(User &$user)
281 296
     {
282
-		if($this->id > 0) return $this->update($user);
297
+		if($this->id > 0) {
298
+			return $this->update($user);
299
+		}
283 300
 
284 301
         $error = 0;
285 302
         $this->db->begin();
@@ -290,10 +307,12 @@  discard block
 block discarded – undo
290 307
 			$this->id = $this->db->last_insert_id($this->table_element);
291 308
 
292 309
 			$result = $this->call_trigger(strtoupper($this->element). '_CREATE', $user);
293
-            if ($result < 0) $error++;
294
-            else $this->saveChild($user);
295
-		}
296
-		else
310
+            if ($result < 0) {
311
+            	$error++;
312
+            } else {
313
+            	$this->saveChild($user);
314
+            }
315
+		} else
297 316
         {
298 317
             $error++;
299 318
             $this->error = $this->db->lasterror();
@@ -304,8 +323,7 @@  discard block
 block discarded – undo
304 323
         {
305 324
             $this->db->commit();
306 325
             return $this->id;
307
-        }
308
-        else
326
+        } else
309 327
         {
310 328
             $this->db->rollback();
311 329
             return -1;
@@ -320,13 +338,17 @@  discard block
 block discarded – undo
320 338
      */
321 339
 	public function delete(User &$user)
322 340
     {
323
-		if ($this->id <= 0) return 0;
341
+		if ($this->id <= 0) {
342
+			return 0;
343
+		}
324 344
 
325 345
         $error = 0;
326 346
         $this->db->begin();
327 347
 
328 348
         $result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user);
329
-        if ($result < 0) $error++;
349
+        if ($result < 0) {
350
+        	$error++;
351
+        }
330 352
 
331 353
         if (!$error)
332 354
         {
@@ -351,8 +373,7 @@  discard block
 block discarded – undo
351 373
         {
352 374
             $this->db->commit();
353 375
             return 1;
354
-        }
355
-        else
376
+        } else
356 377
         {
357 378
             $this->error = $this->db->lasterror();
358 379
             $this->errors[] = $this->error;
@@ -371,8 +392,9 @@  discard block
 block discarded – undo
371 392
      */
372 393
     public function getDate($field, $format='')
373 394
     {
374
-		if(empty($this->{$field})) return '';
375
-		else
395
+		if(empty($this->{$field})) {
396
+			return '';
397
+		} else
376 398
         {
377 399
 			return dol_print_date($this->{$field}, $format);
378 400
 		}
@@ -390,8 +412,7 @@  discard block
 block discarded – undo
390 412
 	  	if (empty($date))
391 413
 	  	{
392 414
 	  		$this->{$field} = 0;
393
-	  	}
394
-		else
415
+	  	} else
395 416
         {
396 417
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
397 418
 			$this->{$field} = dol_stringtotime($date);
@@ -414,19 +435,15 @@  discard block
 block discarded – undo
414 435
 			if($this->checkFieldType($key, 'date'))
415 436
 			{
416 437
 				$this->setDate($key, $value);
417
-			}
418
-			else if( $this->checkFieldType($key, 'array'))
438
+			} else if( $this->checkFieldType($key, 'array'))
419 439
 			{
420 440
 				$this->{$key} = $value;
421
-			}
422
-			else if( $this->checkFieldType($key, 'float') )
441
+			} else if( $this->checkFieldType($key, 'float') )
423 442
 			{
424 443
 				$this->{$key} = (double) price2num($value);
425
-			}
426
-			else if( $this->checkFieldType($key, 'int') ) {
444
+			} else if( $this->checkFieldType($key, 'int') ) {
427 445
 				$this->{$key} = (int) price2num($value);
428
-			}
429
-			else
446
+			} else
430 447
             {
431 448
 				$this->{$key} = $value;
432 449
 			}
Please login to merge, or discard this patch.
htdocs/core/class/html.formbank.class.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -29,33 +29,33 @@
 block discarded – undo
29 29
  */
30 30
 class FormBank
31 31
 {
32
-    var $db;
33
-    var $error;
32
+	var $db;
33
+	var $error;
34 34
 
35 35
 
36
-    /**
37
-     * Constructor
38
-     *
39
-     * @param		DoliDB		$db      Database handler
40
-     */
41
-    public function __construct($db)
42
-    {
43
-        $this->db = $db;
44
-    }
36
+	/**
37
+	 * Constructor
38
+	 *
39
+	 * @param		DoliDB		$db      Database handler
40
+	 */
41
+	public function __construct($db)
42
+	{
43
+		$this->db = $db;
44
+	}
45 45
 
46
-    /**
47
-     *  Retourne la liste des types de comptes financiers
48
-     *
49
-     *  @param	integer	$selected        Type pre-selectionne
50
-     *  @param  string	$htmlname        Nom champ formulaire
51
-     *  @return	void
52
-     */
53
-    public function selectTypeOfBankAccount($selected = Account::TYPE_CURRENT, $htmlname = 'type')
54
-    {
55
-        $account = new Account($this->db);
46
+	/**
47
+	 *  Retourne la liste des types de comptes financiers
48
+	 *
49
+	 *  @param	integer	$selected        Type pre-selectionne
50
+	 *  @param  string	$htmlname        Nom champ formulaire
51
+	 *  @return	void
52
+	 */
53
+	public function selectTypeOfBankAccount($selected = Account::TYPE_CURRENT, $htmlname = 'type')
54
+	{
55
+		$account = new Account($this->db);
56 56
 
57
-        print Form::selectarray($htmlname, $account->type_lib, $selected);
58
-    }
57
+		print Form::selectarray($htmlname, $account->type_lib, $selected);
58
+	}
59 59
 
60 60
 	/**
61 61
 	 * Returns the name of the Iban label. India uses 'IFSC' and the rest of the world 'IBAN' name.
Please login to merge, or discard this patch.
htdocs/core/class/rssparser.class.php 3 patches
Indentation   +734 added lines, -734 removed lines patch added patch discarded remove patch
@@ -26,695 +26,695 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class RssParser
28 28
 {
29
-    var $db;
30
-    var $error;
31
-
32
-    private $_format='';
33
-    private $_urlRSS;
34
-    private $_language;
35
-    private $_generator;
36
-    private $_copyright;
37
-    private $_lastbuilddate;
38
-    private $_imageurl;
39
-    private $_link;
40
-    private $_title;
41
-    private $_description;
42
-    private $_lastfetchdate;    // Last successful fetch
43
-    private $_rssarray=array();
44
-
45
-    // For parsing with xmlparser
46
-    var $stack               = array(); // parser stack
47
-    var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
48
-
49
-
50
-    /**
51
-     *	Constructor
52
-     *
53
-     *  @param		DoliDB		$db      Database handler
54
-     */
55
-    public function __construct($db)
56
-    {
57
-    	$this->db=$db;
58
-    }
59
-
60
-    /**
61
-     * getFormat
62
-     *
63
-     * @return string
64
-     */
65
-    public function getFormat()
66
-    {
67
-        return $this->_format;
68
-    }
69
-
70
-    /**
71
-     * getUrlRss
72
-     *
73
-     * @return string
74
-     */
75
-    public function getUrlRss()
76
-    {
77
-        return $this->_urlRSS;
78
-    }
79
-    /**
80
-     * getLanguage
81
-     *
82
-     * @return string
83
-     */
84
-    public function getLanguage()
85
-    {
86
-        return $this->_language;
87
-    }
88
-    /**
89
-     * getGenerator
90
-     *
91
-     * @return string
92
-     */
93
-    public function getGenerator()
94
-    {
95
-        return $this->_generator;
96
-    }
97
-    /**
98
-     * getCopyright
99
-     *
100
-     * @return string
101
-     */
102
-    public function getCopyright()
103
-    {
104
-        return $this->_copyright;
105
-    }
106
-    /**
107
-     * getLastBuildDate
108
-     *
109
-     * @return string
110
-     */
111
-    public function getLastBuildDate()
112
-    {
113
-        return $this->_lastbuilddate;
114
-    }
115
-    /**
116
-     * getImageUrl
117
-     *
118
-     * @return string
119
-     */
120
-    public function getImageUrl()
121
-    {
122
-        return $this->_imageurl;
123
-    }
124
-    /**
125
-     * getLink
126
-     *
127
-     * @return string
128
-     */
129
-    public function getLink()
130
-    {
131
-        return $this->_link;
132
-    }
133
-    /**
134
-     * getTitle
135
-     *
136
-     * @return string
137
-     */
138
-    public function getTitle()
139
-    {
140
-        return $this->_title;
141
-    }
142
-    /**
143
-     * getDescription
144
-     *
145
-     * @return string
146
-     */
147
-    public function getDescription()
148
-    {
149
-        return $this->_description;
150
-    }
151
-    /**
152
-     * getLastFetchDate
153
-     *
154
-     * @return string
155
-     */
156
-    public function getLastFetchDate()
157
-    {
158
-        return $this->_lastfetchdate;
159
-    }
160
-    /**
161
-     * getItems
162
-     *
163
-     * @return string
164
-     */
165
-    public function getItems()
166
-    {
167
-        return $this->_rssarray;
168
-    }
169
-
170
-
171
-    /**
172
-     * 	Parse rss URL
173
-     *
174
-     * 	@param	string	$urlRSS		Url to parse
175
-     * 	@param	int		$maxNb		Max nb of records to get (0 for no limit)
176
-     * 	@param	int		$cachedelay	0=No cache, nb of seconds we accept cache files (cachedir must also be defined)
177
-     * 	@param	string	$cachedir	Directory where to save cache file
178
-     *	@return	int					<0 if KO, >0 if OK
179
-     */
180
-    public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
181
-    {
182
-        global $conf;
183
-
184
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
185
-
186
-        $rss='';
187
-        $str='';    // This will contain content of feed
188
-
189
-        // Check parameters
190
-        if (! dol_is_url($urlRSS))
191
-        {
192
-            $this->error="ErrorBadUrl";
193
-            return -1;
194
-        }
195
-
196
-        $this->_urlRSS = $urlRSS;
197
-        $newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS,3);	// Force md5 hash (does not contains special chars)
198
-        $newmask='0644';
199
-
200
-        //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
201
-        $nowgmt = dol_now();
202
-
203
-        // Search into cache
204
-        $foundintocache=0;
205
-        if ($cachedelay > 0 && $cachedir)
206
-        {
207
-            $filedate=dol_filemtime($newpathofdestfile);
208
-            if ($filedate >= ($nowgmt - $cachedelay))
209
-            {
210
-                //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
211
-                $foundintocache=1;
212
-
213
-                $this->_lastfetchdate=$filedate;
214
-            }
215
-            else
216
-            {
217
-                dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
218
-            }
219
-        }
220
-
221
-        // Load file into $str
222
-        if ($foundintocache)    // Cache file found and is not too old
223
-        {
224
-            $str = file_get_contents($newpathofdestfile);
225
-        }
226
-        else
227
-        {
228
-            try {
229
-                ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
230
-                ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
231
-                ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
232
-
233
-                $opts = array('http'=>array('method'=>"GET"));
234
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
235
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
236
-                //var_dump($opts);exit;
237
-                $context = stream_context_create($opts);
238
-
239
-                $str = file_get_contents($this->_urlRSS, false, $context);
240
-            }
241
-            catch (Exception $e) {
242
-                print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
243
-            }
244
-        }
245
-
246
-        if ($str !== false)
247
-        {
248
-	        // Convert $str into xml
249
-	        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
250
-	        {
251
-	            //print 'xx'.LIBXML_NOCDATA;
252
-	            libxml_use_internal_errors(false);
253
-	            $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
254
-	        }
255
-	        else
256
-	        {
257
-	            $xmlparser=xml_parser_create('');
258
-	            if (!is_resource($xmlparser)) {
259
-	                $this->error="ErrorFailedToCreateParser"; return -1;
260
-	            }
261
-
262
-	            xml_set_object($xmlparser, $this);
263
-	            xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element');
264
-	            xml_set_character_data_handler($xmlparser, 'feed_cdata');
265
-	            $status = xml_parse($xmlparser, $str);
266
-	            xml_parser_free($xmlparser);
267
-	            $rss=$this;
268
-	            //var_dump($rss->_format);exit;
269
-	        }
270
-        }
271
-
272
-        // If $rss loaded
273
-        if ($rss)
274
-        {
275
-            // Save file into cache
276
-            if (empty($foundintocache) && $cachedir)
277
-            {
278
-                dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
279
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
280
-                $fp = fopen($newpathofdestfile, 'w');
281
-                fwrite($fp, $str);
282
-                fclose($fp);
283
-                if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
284
-                @chmod($newpathofdestfile, octdec($newmask));
285
-
286
-                $this->_lastfetchdate=$nowgmt;
287
-            }
288
-
289
-            unset($str);    // Free memory
290
-
291
-            if (empty($rss->_format))    // If format not detected automatically
292
-            {
293
-                $rss->_format='rss';
294
-                if (empty($rss->channel)) $rss->_format='atom';
295
-            }
296
-
297
-            $items=array();
298
-
299
-            // Save description entries
300
-            if ($rss->_format == 'rss')
301
-            {
302
-                //var_dump($rss);
303
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
304
-                {
305
-                    if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
306
-                    if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
307
-                    if (!empty($rss->channel->copyright))     $this->_copyright = (string) $rss->channel->copyright;
308
-                    if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
309
-                    if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
310
-                    if (!empty($rss->channel->link))		  $this->_link = (string) $rss->channel->link;
311
-                    if (!empty($rss->channel->title))         $this->_title = (string) $rss->channel->title;
312
-                    if (!empty($rss->channel->description))	  $this->_description = (string) $rss->channel->description;
313
-                }
314
-                else
315
-                {
316
-                    //var_dump($rss->channel);
317
-                    if (!empty($rss->channel['language']))      $this->_language = (string) $rss->channel['language'];
318
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
319
-                    if (!empty($rss->channel['copyright']))     $this->_copyright = (string) $rss->channel['copyright'];
320
-                    if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
321
-                    if (!empty($rss->image['url']))             $this->_imageurl = (string) $rss->image['url'];
322
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
323
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
324
-                    if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
325
-                }
326
-
327
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
328
-                else $items=$rss->items;                                                              // With xmlparse
329
-                //var_dump($items);exit;
330
-            }
331
-            else if ($rss->_format == 'atom')
332
-            {
333
-                //var_dump($rss);
334
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
335
-                {
336
-                    if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
337
-                    if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
338
-                    if (!empty($rss->link->href))    $this->_link = (string) $rss->link->href;
339
-                    if (!empty($rss->title))         $this->_title = (string) $rss->title;
340
-                    if (!empty($rss->description))	 $this->_description = (string) $rss->description;
341
-                }
342
-                else
343
-                {
344
-                    //if (!empty($rss->channel['rss_language']))      $this->_language = (string) $rss->channel['rss_language'];
345
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
346
-                    //if (!empty($rss->channel['rss_copyright']))     $this->_copyright = (string) $rss->channel['rss_copyright'];
347
-                    if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
348
-                    //if (!empty($rss->image['rss_url']))             $this->_imageurl = (string) $rss->image['rss_url'];
349
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
350
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
351
-                    //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
352
-                }
353
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
354
-                    $tmprss=xml2php($rss); $items=$tmprss['entry'];
355
-                } // With simplexml
356
-                else $items=$rss->items;                                                              // With xmlparse
357
-                //var_dump($items);exit;
358
-            }
359
-
360
-            $i = 0;
361
-
362
-            // Loop on each record
363
-            if (is_array($items))
364
-            {
365
-                foreach($items as $item)
366
-                {
367
-                    //var_dump($item);exit;
368
-                    if ($rss->_format == 'rss')
369
-                    {
370
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
371
-                        {
372
-                            $itemLink = (string) $item->link;
373
-                            $itemTitle = (string) $item->title;
374
-                            $itemDescription = (string) $item->description;
375
-                            $itemPubDate = (string) $item->pubDate;
376
-                            $itemId = '';
377
-                            $itemAuthor = '';
378
-                        }
379
-                        else
380
-                        {
381
-                            $itemLink = (string) $item['link'];
382
-                            $itemTitle = (string) $item['title'];
383
-                            $itemDescription = (string) $item['description'];
384
-                            $itemPubDate = (string) $item['pubdate'];
385
-                            $itemId = (string) $item['guid'];
386
-                            $itemAuthor = (string) $item['author'];
387
-                        }
388
-
389
-                        // Loop on each category
390
-                        $itemCategory=array();
391
-                        if (is_array($item->category))
392
-                        {
393
-                            foreach ($item->category as $cat)
394
-                            {
395
-                                $itemCategory[] = (string) $cat;
396
-                            }
397
-                        }
398
-                    }
399
-                    else if ($rss->_format == 'atom')
400
-                    {
401
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
402
-                        {
403
-                            $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
404
-                            $itemTitle = (string) $item['title'];
405
-                            $itemDescription = (string) $item['summary'];
406
-                            $itemPubDate = (string) $item['created'];
407
-                            $itemId = (string) $item['id'];
408
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
409
-                        }
410
-                        else
411
-                        {
412
-                            $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
413
-                            $itemTitle = (string) $item['title'];
414
-                            $itemDescription = (string) $item['summary'];
415
-                            $itemPubDate = (string) $item['created'];
416
-                            $itemId = (string) $item['id'];
417
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
418
-                        }
419
-                    }
420
-                    else print 'ErrorBadFeedFormat';
421
-
422
-                    // Add record to result array
423
-                    $this->_rssarray[$i] = array(
424
-    					'link'=>$itemLink,
425
-    					'title'=>$itemTitle,
426
-    					'description'=>$itemDescription,
427
-    					'pubDate'=>$itemPubDate,
428
-    					'category'=>$itemCategory,
429
-    				    'id'=>$itemId,
430
-    				    'author'=>$itemAuthor);
431
-                    //var_dump($this->_rssarray);
432
-
433
-                    $i++;
434
-
435
-                    if ($i > $maxNb)    break;    // We get all records we want
436
-                }
437
-            }
438
-
439
-            return 1;
440
-        }
441
-        else
442
-        {
443
-            $this->error='ErrorFailedToLoadRSSFile';
444
-            return -1;
445
-        }
446
-    }
447
-
448
-
449
-
450
-    /**
451
-     * 	Triggered when opened tag is found
452
-     *
453
-     * 	@param	string		$p			Start
454
-     *  @param	string		$element	Tag
455
-     *  @param	array		$attrs		Attributes of tags
456
-     *  @return	void
457
-     */
458
-    function feed_start_element($p, $element, &$attrs)
459
-    {
460
-        $el = $element = strtolower($element);
461
-        $attrs = array_change_key_case($attrs, CASE_LOWER);
462
-
463
-        // check for a namespace, and split if found
464
-        $ns = false;
465
-        if (strpos($element, ':'))
466
-        {
467
-            list($ns, $el) = explode(':', $element, 2);
468
-        }
469
-        if ( $ns and $ns != 'rdf' )
470
-        {
471
-            $this->current_namespace = $ns;
472
-        }
473
-
474
-        // if feed type isn't set, then this is first element of feed identify feed from root element
475
-        if (empty($this->_format))
476
-        {
477
-            if ( $el == 'rdf' ) {
478
-                $this->_format = 'rss';
479
-                $this->feed_version = '1.0';
480
-            }
481
-            elseif ( $el == 'rss' ) {
482
-                $this->_format = 'rss';
483
-                $this->feed_version = $attrs['version'];
484
-            }
485
-            elseif ( $el == 'feed' ) {
486
-                $this->_format = 'atom';
487
-                $this->feed_version = $attrs['version'];
488
-                $this->inchannel = true;
489
-            }
490
-            return;
491
-        }
492
-
493
-        if ( $el == 'channel' )
494
-        {
495
-            $this->inchannel = true;
496
-        }
497
-        elseif ($el == 'item' or $el == 'entry' )
498
-        {
499
-            $this->initem = true;
500
-            if ( isset($attrs['rdf:about']) ) {
501
-                $this->current_item['about'] = $attrs['rdf:about'];
502
-            }
503
-        }
504
-
505
-        // if we're in the default namespace of an RSS feed,
506
-        //  record textinput or image fields
507
-        elseif (
508
-        $this->_format == 'rss' and
509
-        $this->current_namespace == '' and
510
-        $el == 'textinput' )
511
-        {
512
-            $this->intextinput = true;
513
-        }
514
-
515
-        elseif (
516
-        $this->_format == 'rss' and
517
-        $this->current_namespace == '' and
518
-        $el == 'image' )
519
-        {
520
-            $this->inimage = true;
521
-        }
522
-
523
-        // handle atom content constructs
524
-        elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
525
-        {
526
-            // avoid clashing w/ RSS mod_content
527
-            if ($el == 'content' ) {
528
-                $el = 'atom_content';
529
-            }
530
-
531
-            $this->incontent = $el;
532
-
533
-
534
-        }
535
-
536
-        // if inside an Atom content construct (e.g. content or summary) field treat tags as text
537
-        elseif ($this->_format == 'atom' and $this->incontent )
538
-        {
539
-            // if tags are inlined, then flatten
540
-            $attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs)));
541
-
542
-            $this->append_content("<$element $attrs_str>");
543
-
544
-            array_unshift($this->stack, $el);
545
-        }
546
-
547
-        // Atom support many links per containging element.
548
-        // Magpie treats link elements of type rel='alternate'
549
-        // as being equivalent to RSS's simple link element.
550
-        //
551
-        elseif ($this->_format == 'atom' and $el == 'link' )
552
-        {
553
-            if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
554
-            {
555
-                $link_el = 'link';
556
-            }
557
-            else {
558
-                $link_el = 'link_' . $attrs['rel'];
559
-            }
560
-
561
-            $this->append($link_el, $attrs['href']);
562
-        }
563
-        // set stack[0] to current element
564
-        else {
565
-            array_unshift($this->stack, $el);
566
-        }
567
-    }
568
-
569
-
570
-    /**
571
-     * 	Triggered when CDATA is found
572
-     *
573
-     * 	@param	string	$p		P
574
-     *  @param	string	$text	Tag
575
-     *  @return	void
576
-     */
577
-    function feed_cdata($p, $text)
578
-    {
579
-        if ($this->_format == 'atom' and $this->incontent)
580
-        {
581
-            $this->append_content($text);
582
-        }
583
-        else
584
-        {
585
-            $current_el = join('_', array_reverse($this->stack));
586
-            $this->append($current_el, $text);
587
-        }
588
-    }
589
-
590
-    /**
591
-     * 	Triggered when closed tag is found
592
-     *
593
-     * 	@param	string		$p		P
594
-     *  @param	string		$el		Tag
595
-     *  @return	void
596
-     */
597
-    function feed_end_element($p, $el)
598
-    {
599
-        $el = strtolower($el);
600
-
601
-        if ($el == 'item' or $el == 'entry')
602
-        {
603
-            $this->items[] = $this->current_item;
604
-            $this->current_item = array();
605
-            $this->initem = false;
606
-        }
607
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
608
-        {
609
-            $this->intextinput = false;
610
-        }
611
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
612
-        {
613
-            $this->inimage = false;
614
-        }
615
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
616
-        {
617
-            $this->incontent = false;
618
-        }
619
-        elseif ($el == 'channel' or $el == 'feed' )
620
-        {
621
-            $this->inchannel = false;
622
-        }
623
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
624
-            // balance tags properly
625
-            // note:  i don't think this is actually neccessary
626
-            if ( $this->stack[0] == $el )
627
-            {
628
-                $this->append_content("</$el>");
629
-            }
630
-            else {
631
-                $this->append_content("<$el />");
632
-            }
633
-
634
-            array_shift($this->stack);
635
-        }
636
-        else {
637
-            array_shift($this->stack);
638
-        }
639
-
640
-        $this->current_namespace = false;
641
-    }
642
-
643
-
644
-    /**
645
-     * 	To concat 2 string with no warning if an operand is not defined
646
-     *
647
-     * 	@param	string	$str1		Str1
648
-     *  @param	string	$str2		Str2
649
-     *  @return	string				String cancatenated
650
-     */
651
-    function concat(&$str1, $str2="")
652
-    {
653
-        if (!isset($str1) ) {
654
-            $str1="";
655
-        }
656
-        $str1 .= $str2;
657
-    }
658
-
659
-    /**
660
-     * Enter description here ...
661
-     *
662
-     * @param	string	$text		Text
663
-     * @return	void
664
-     */
665
-    function append_content($text)
666
-    {
667
-        if ( $this->initem ) {
668
-            $this->concat($this->current_item[ $this->incontent ], $text);
669
-        }
670
-        elseif ( $this->inchannel ) {
671
-            $this->concat($this->channel[ $this->incontent ], $text);
672
-        }
673
-    }
674
-
675
-    /**
676
-     * 	smart append - field and namespace aware
677
-     *
678
-     * 	@param	string	$el		El
679
-     * 	@param	string	$text	Text
680
-     * 	@return	void
681
-     */
682
-    function append($el, $text)
683
-    {
684
-        if (!$el) {
685
-            return;
686
-        }
687
-        if ( $this->current_namespace )
688
-        {
689
-            if ( $this->initem ) {
690
-                $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
691
-            }
692
-            elseif ($this->inchannel) {
693
-                $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
694
-            }
695
-            elseif ($this->intextinput) {
696
-                $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
697
-            }
698
-            elseif ($this->inimage) {
699
-                $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
700
-            }
701
-        }
702
-        else {
703
-            if ( $this->initem ) {
704
-                $this->concat($this->current_item[ $el ], $text);
705
-            }
706
-            elseif ($this->intextinput) {
707
-                $this->concat($this->textinput[ $el ], $text);
708
-            }
709
-            elseif ($this->inimage) {
710
-                $this->concat($this->image[ $el ], $text);
711
-            }
712
-            elseif ($this->inchannel) {
713
-                $this->concat($this->channel[ $el ], $text);
714
-            }
715
-
716
-        }
717
-    }
29
+	var $db;
30
+	var $error;
31
+
32
+	private $_format='';
33
+	private $_urlRSS;
34
+	private $_language;
35
+	private $_generator;
36
+	private $_copyright;
37
+	private $_lastbuilddate;
38
+	private $_imageurl;
39
+	private $_link;
40
+	private $_title;
41
+	private $_description;
42
+	private $_lastfetchdate;    // Last successful fetch
43
+	private $_rssarray=array();
44
+
45
+	// For parsing with xmlparser
46
+	var $stack               = array(); // parser stack
47
+	var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
48
+
49
+
50
+	/**
51
+	 *	Constructor
52
+	 *
53
+	 *  @param		DoliDB		$db      Database handler
54
+	 */
55
+	public function __construct($db)
56
+	{
57
+		$this->db=$db;
58
+	}
59
+
60
+	/**
61
+	 * getFormat
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function getFormat()
66
+	{
67
+		return $this->_format;
68
+	}
69
+
70
+	/**
71
+	 * getUrlRss
72
+	 *
73
+	 * @return string
74
+	 */
75
+	public function getUrlRss()
76
+	{
77
+		return $this->_urlRSS;
78
+	}
79
+	/**
80
+	 * getLanguage
81
+	 *
82
+	 * @return string
83
+	 */
84
+	public function getLanguage()
85
+	{
86
+		return $this->_language;
87
+	}
88
+	/**
89
+	 * getGenerator
90
+	 *
91
+	 * @return string
92
+	 */
93
+	public function getGenerator()
94
+	{
95
+		return $this->_generator;
96
+	}
97
+	/**
98
+	 * getCopyright
99
+	 *
100
+	 * @return string
101
+	 */
102
+	public function getCopyright()
103
+	{
104
+		return $this->_copyright;
105
+	}
106
+	/**
107
+	 * getLastBuildDate
108
+	 *
109
+	 * @return string
110
+	 */
111
+	public function getLastBuildDate()
112
+	{
113
+		return $this->_lastbuilddate;
114
+	}
115
+	/**
116
+	 * getImageUrl
117
+	 *
118
+	 * @return string
119
+	 */
120
+	public function getImageUrl()
121
+	{
122
+		return $this->_imageurl;
123
+	}
124
+	/**
125
+	 * getLink
126
+	 *
127
+	 * @return string
128
+	 */
129
+	public function getLink()
130
+	{
131
+		return $this->_link;
132
+	}
133
+	/**
134
+	 * getTitle
135
+	 *
136
+	 * @return string
137
+	 */
138
+	public function getTitle()
139
+	{
140
+		return $this->_title;
141
+	}
142
+	/**
143
+	 * getDescription
144
+	 *
145
+	 * @return string
146
+	 */
147
+	public function getDescription()
148
+	{
149
+		return $this->_description;
150
+	}
151
+	/**
152
+	 * getLastFetchDate
153
+	 *
154
+	 * @return string
155
+	 */
156
+	public function getLastFetchDate()
157
+	{
158
+		return $this->_lastfetchdate;
159
+	}
160
+	/**
161
+	 * getItems
162
+	 *
163
+	 * @return string
164
+	 */
165
+	public function getItems()
166
+	{
167
+		return $this->_rssarray;
168
+	}
169
+
170
+
171
+	/**
172
+	 * 	Parse rss URL
173
+	 *
174
+	 * 	@param	string	$urlRSS		Url to parse
175
+	 * 	@param	int		$maxNb		Max nb of records to get (0 for no limit)
176
+	 * 	@param	int		$cachedelay	0=No cache, nb of seconds we accept cache files (cachedir must also be defined)
177
+	 * 	@param	string	$cachedir	Directory where to save cache file
178
+	 *	@return	int					<0 if KO, >0 if OK
179
+	 */
180
+	public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
181
+	{
182
+		global $conf;
183
+
184
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
185
+
186
+		$rss='';
187
+		$str='';    // This will contain content of feed
188
+
189
+		// Check parameters
190
+		if (! dol_is_url($urlRSS))
191
+		{
192
+			$this->error="ErrorBadUrl";
193
+			return -1;
194
+		}
195
+
196
+		$this->_urlRSS = $urlRSS;
197
+		$newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS,3);	// Force md5 hash (does not contains special chars)
198
+		$newmask='0644';
199
+
200
+		//dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
201
+		$nowgmt = dol_now();
202
+
203
+		// Search into cache
204
+		$foundintocache=0;
205
+		if ($cachedelay > 0 && $cachedir)
206
+		{
207
+			$filedate=dol_filemtime($newpathofdestfile);
208
+			if ($filedate >= ($nowgmt - $cachedelay))
209
+			{
210
+				//dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
211
+				$foundintocache=1;
212
+
213
+				$this->_lastfetchdate=$filedate;
214
+			}
215
+			else
216
+			{
217
+				dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
218
+			}
219
+		}
220
+
221
+		// Load file into $str
222
+		if ($foundintocache)    // Cache file found and is not too old
223
+		{
224
+			$str = file_get_contents($newpathofdestfile);
225
+		}
226
+		else
227
+		{
228
+			try {
229
+				ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
230
+				ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
231
+				ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
232
+
233
+				$opts = array('http'=>array('method'=>"GET"));
234
+				if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
235
+				if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
236
+				//var_dump($opts);exit;
237
+				$context = stream_context_create($opts);
238
+
239
+				$str = file_get_contents($this->_urlRSS, false, $context);
240
+			}
241
+			catch (Exception $e) {
242
+				print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
243
+			}
244
+		}
245
+
246
+		if ($str !== false)
247
+		{
248
+			// Convert $str into xml
249
+			if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
250
+			{
251
+				//print 'xx'.LIBXML_NOCDATA;
252
+				libxml_use_internal_errors(false);
253
+				$rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
254
+			}
255
+			else
256
+			{
257
+				$xmlparser=xml_parser_create('');
258
+				if (!is_resource($xmlparser)) {
259
+					$this->error="ErrorFailedToCreateParser"; return -1;
260
+				}
261
+
262
+				xml_set_object($xmlparser, $this);
263
+				xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element');
264
+				xml_set_character_data_handler($xmlparser, 'feed_cdata');
265
+				$status = xml_parse($xmlparser, $str);
266
+				xml_parser_free($xmlparser);
267
+				$rss=$this;
268
+				//var_dump($rss->_format);exit;
269
+			}
270
+		}
271
+
272
+		// If $rss loaded
273
+		if ($rss)
274
+		{
275
+			// Save file into cache
276
+			if (empty($foundintocache) && $cachedir)
277
+			{
278
+				dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
279
+				if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
280
+				$fp = fopen($newpathofdestfile, 'w');
281
+				fwrite($fp, $str);
282
+				fclose($fp);
283
+				if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
284
+				@chmod($newpathofdestfile, octdec($newmask));
285
+
286
+				$this->_lastfetchdate=$nowgmt;
287
+			}
288
+
289
+			unset($str);    // Free memory
290
+
291
+			if (empty($rss->_format))    // If format not detected automatically
292
+			{
293
+				$rss->_format='rss';
294
+				if (empty($rss->channel)) $rss->_format='atom';
295
+			}
296
+
297
+			$items=array();
298
+
299
+			// Save description entries
300
+			if ($rss->_format == 'rss')
301
+			{
302
+				//var_dump($rss);
303
+				if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
304
+				{
305
+					if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
306
+					if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
307
+					if (!empty($rss->channel->copyright))     $this->_copyright = (string) $rss->channel->copyright;
308
+					if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
309
+					if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
310
+					if (!empty($rss->channel->link))		  $this->_link = (string) $rss->channel->link;
311
+					if (!empty($rss->channel->title))         $this->_title = (string) $rss->channel->title;
312
+					if (!empty($rss->channel->description))	  $this->_description = (string) $rss->channel->description;
313
+				}
314
+				else
315
+				{
316
+					//var_dump($rss->channel);
317
+					if (!empty($rss->channel['language']))      $this->_language = (string) $rss->channel['language'];
318
+					if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
319
+					if (!empty($rss->channel['copyright']))     $this->_copyright = (string) $rss->channel['copyright'];
320
+					if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
321
+					if (!empty($rss->image['url']))             $this->_imageurl = (string) $rss->image['url'];
322
+					if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
323
+					if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
324
+					if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
325
+				}
326
+
327
+				if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
328
+				else $items=$rss->items;                                                              // With xmlparse
329
+				//var_dump($items);exit;
330
+			}
331
+			else if ($rss->_format == 'atom')
332
+			{
333
+				//var_dump($rss);
334
+				if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
335
+				{
336
+					if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
337
+					if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
338
+					if (!empty($rss->link->href))    $this->_link = (string) $rss->link->href;
339
+					if (!empty($rss->title))         $this->_title = (string) $rss->title;
340
+					if (!empty($rss->description))	 $this->_description = (string) $rss->description;
341
+				}
342
+				else
343
+				{
344
+					//if (!empty($rss->channel['rss_language']))      $this->_language = (string) $rss->channel['rss_language'];
345
+					if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
346
+					//if (!empty($rss->channel['rss_copyright']))     $this->_copyright = (string) $rss->channel['rss_copyright'];
347
+					if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
348
+					//if (!empty($rss->image['rss_url']))             $this->_imageurl = (string) $rss->image['rss_url'];
349
+					if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
350
+					if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
351
+					//if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
352
+				}
353
+				if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
354
+					$tmprss=xml2php($rss); $items=$tmprss['entry'];
355
+				} // With simplexml
356
+				else $items=$rss->items;                                                              // With xmlparse
357
+				//var_dump($items);exit;
358
+			}
359
+
360
+			$i = 0;
361
+
362
+			// Loop on each record
363
+			if (is_array($items))
364
+			{
365
+				foreach($items as $item)
366
+				{
367
+					//var_dump($item);exit;
368
+					if ($rss->_format == 'rss')
369
+					{
370
+						if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
371
+						{
372
+							$itemLink = (string) $item->link;
373
+							$itemTitle = (string) $item->title;
374
+							$itemDescription = (string) $item->description;
375
+							$itemPubDate = (string) $item->pubDate;
376
+							$itemId = '';
377
+							$itemAuthor = '';
378
+						}
379
+						else
380
+						{
381
+							$itemLink = (string) $item['link'];
382
+							$itemTitle = (string) $item['title'];
383
+							$itemDescription = (string) $item['description'];
384
+							$itemPubDate = (string) $item['pubdate'];
385
+							$itemId = (string) $item['guid'];
386
+							$itemAuthor = (string) $item['author'];
387
+						}
388
+
389
+						// Loop on each category
390
+						$itemCategory=array();
391
+						if (is_array($item->category))
392
+						{
393
+							foreach ($item->category as $cat)
394
+							{
395
+								$itemCategory[] = (string) $cat;
396
+							}
397
+						}
398
+					}
399
+					else if ($rss->_format == 'atom')
400
+					{
401
+						if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
402
+						{
403
+							$itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
404
+							$itemTitle = (string) $item['title'];
405
+							$itemDescription = (string) $item['summary'];
406
+							$itemPubDate = (string) $item['created'];
407
+							$itemId = (string) $item['id'];
408
+							$itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
409
+						}
410
+						else
411
+						{
412
+							$itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
413
+							$itemTitle = (string) $item['title'];
414
+							$itemDescription = (string) $item['summary'];
415
+							$itemPubDate = (string) $item['created'];
416
+							$itemId = (string) $item['id'];
417
+							$itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
418
+						}
419
+					}
420
+					else print 'ErrorBadFeedFormat';
421
+
422
+					// Add record to result array
423
+					$this->_rssarray[$i] = array(
424
+						'link'=>$itemLink,
425
+						'title'=>$itemTitle,
426
+						'description'=>$itemDescription,
427
+						'pubDate'=>$itemPubDate,
428
+						'category'=>$itemCategory,
429
+						'id'=>$itemId,
430
+						'author'=>$itemAuthor);
431
+					//var_dump($this->_rssarray);
432
+
433
+					$i++;
434
+
435
+					if ($i > $maxNb)    break;    // We get all records we want
436
+				}
437
+			}
438
+
439
+			return 1;
440
+		}
441
+		else
442
+		{
443
+			$this->error='ErrorFailedToLoadRSSFile';
444
+			return -1;
445
+		}
446
+	}
447
+
448
+
449
+
450
+	/**
451
+	 * 	Triggered when opened tag is found
452
+	 *
453
+	 * 	@param	string		$p			Start
454
+	 *  @param	string		$element	Tag
455
+	 *  @param	array		$attrs		Attributes of tags
456
+	 *  @return	void
457
+	 */
458
+	function feed_start_element($p, $element, &$attrs)
459
+	{
460
+		$el = $element = strtolower($element);
461
+		$attrs = array_change_key_case($attrs, CASE_LOWER);
462
+
463
+		// check for a namespace, and split if found
464
+		$ns = false;
465
+		if (strpos($element, ':'))
466
+		{
467
+			list($ns, $el) = explode(':', $element, 2);
468
+		}
469
+		if ( $ns and $ns != 'rdf' )
470
+		{
471
+			$this->current_namespace = $ns;
472
+		}
473
+
474
+		// if feed type isn't set, then this is first element of feed identify feed from root element
475
+		if (empty($this->_format))
476
+		{
477
+			if ( $el == 'rdf' ) {
478
+				$this->_format = 'rss';
479
+				$this->feed_version = '1.0';
480
+			}
481
+			elseif ( $el == 'rss' ) {
482
+				$this->_format = 'rss';
483
+				$this->feed_version = $attrs['version'];
484
+			}
485
+			elseif ( $el == 'feed' ) {
486
+				$this->_format = 'atom';
487
+				$this->feed_version = $attrs['version'];
488
+				$this->inchannel = true;
489
+			}
490
+			return;
491
+		}
492
+
493
+		if ( $el == 'channel' )
494
+		{
495
+			$this->inchannel = true;
496
+		}
497
+		elseif ($el == 'item' or $el == 'entry' )
498
+		{
499
+			$this->initem = true;
500
+			if ( isset($attrs['rdf:about']) ) {
501
+				$this->current_item['about'] = $attrs['rdf:about'];
502
+			}
503
+		}
504
+
505
+		// if we're in the default namespace of an RSS feed,
506
+		//  record textinput or image fields
507
+		elseif (
508
+		$this->_format == 'rss' and
509
+		$this->current_namespace == '' and
510
+		$el == 'textinput' )
511
+		{
512
+			$this->intextinput = true;
513
+		}
514
+
515
+		elseif (
516
+		$this->_format == 'rss' and
517
+		$this->current_namespace == '' and
518
+		$el == 'image' )
519
+		{
520
+			$this->inimage = true;
521
+		}
522
+
523
+		// handle atom content constructs
524
+		elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
525
+		{
526
+			// avoid clashing w/ RSS mod_content
527
+			if ($el == 'content' ) {
528
+				$el = 'atom_content';
529
+			}
530
+
531
+			$this->incontent = $el;
532
+
533
+
534
+		}
535
+
536
+		// if inside an Atom content construct (e.g. content or summary) field treat tags as text
537
+		elseif ($this->_format == 'atom' and $this->incontent )
538
+		{
539
+			// if tags are inlined, then flatten
540
+			$attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs)));
541
+
542
+			$this->append_content("<$element $attrs_str>");
543
+
544
+			array_unshift($this->stack, $el);
545
+		}
546
+
547
+		// Atom support many links per containging element.
548
+		// Magpie treats link elements of type rel='alternate'
549
+		// as being equivalent to RSS's simple link element.
550
+		//
551
+		elseif ($this->_format == 'atom' and $el == 'link' )
552
+		{
553
+			if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
554
+			{
555
+				$link_el = 'link';
556
+			}
557
+			else {
558
+				$link_el = 'link_' . $attrs['rel'];
559
+			}
560
+
561
+			$this->append($link_el, $attrs['href']);
562
+		}
563
+		// set stack[0] to current element
564
+		else {
565
+			array_unshift($this->stack, $el);
566
+		}
567
+	}
568
+
569
+
570
+	/**
571
+	 * 	Triggered when CDATA is found
572
+	 *
573
+	 * 	@param	string	$p		P
574
+	 *  @param	string	$text	Tag
575
+	 *  @return	void
576
+	 */
577
+	function feed_cdata($p, $text)
578
+	{
579
+		if ($this->_format == 'atom' and $this->incontent)
580
+		{
581
+			$this->append_content($text);
582
+		}
583
+		else
584
+		{
585
+			$current_el = join('_', array_reverse($this->stack));
586
+			$this->append($current_el, $text);
587
+		}
588
+	}
589
+
590
+	/**
591
+	 * 	Triggered when closed tag is found
592
+	 *
593
+	 * 	@param	string		$p		P
594
+	 *  @param	string		$el		Tag
595
+	 *  @return	void
596
+	 */
597
+	function feed_end_element($p, $el)
598
+	{
599
+		$el = strtolower($el);
600
+
601
+		if ($el == 'item' or $el == 'entry')
602
+		{
603
+			$this->items[] = $this->current_item;
604
+			$this->current_item = array();
605
+			$this->initem = false;
606
+		}
607
+		elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
608
+		{
609
+			$this->intextinput = false;
610
+		}
611
+		elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
612
+		{
613
+			$this->inimage = false;
614
+		}
615
+		elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
616
+		{
617
+			$this->incontent = false;
618
+		}
619
+		elseif ($el == 'channel' or $el == 'feed' )
620
+		{
621
+			$this->inchannel = false;
622
+		}
623
+		elseif ($this->_format == 'atom' and $this->incontent  ) {
624
+			// balance tags properly
625
+			// note:  i don't think this is actually neccessary
626
+			if ( $this->stack[0] == $el )
627
+			{
628
+				$this->append_content("</$el>");
629
+			}
630
+			else {
631
+				$this->append_content("<$el />");
632
+			}
633
+
634
+			array_shift($this->stack);
635
+		}
636
+		else {
637
+			array_shift($this->stack);
638
+		}
639
+
640
+		$this->current_namespace = false;
641
+	}
642
+
643
+
644
+	/**
645
+	 * 	To concat 2 string with no warning if an operand is not defined
646
+	 *
647
+	 * 	@param	string	$str1		Str1
648
+	 *  @param	string	$str2		Str2
649
+	 *  @return	string				String cancatenated
650
+	 */
651
+	function concat(&$str1, $str2="")
652
+	{
653
+		if (!isset($str1) ) {
654
+			$str1="";
655
+		}
656
+		$str1 .= $str2;
657
+	}
658
+
659
+	/**
660
+	 * Enter description here ...
661
+	 *
662
+	 * @param	string	$text		Text
663
+	 * @return	void
664
+	 */
665
+	function append_content($text)
666
+	{
667
+		if ( $this->initem ) {
668
+			$this->concat($this->current_item[ $this->incontent ], $text);
669
+		}
670
+		elseif ( $this->inchannel ) {
671
+			$this->concat($this->channel[ $this->incontent ], $text);
672
+		}
673
+	}
674
+
675
+	/**
676
+	 * 	smart append - field and namespace aware
677
+	 *
678
+	 * 	@param	string	$el		El
679
+	 * 	@param	string	$text	Text
680
+	 * 	@return	void
681
+	 */
682
+	function append($el, $text)
683
+	{
684
+		if (!$el) {
685
+			return;
686
+		}
687
+		if ( $this->current_namespace )
688
+		{
689
+			if ( $this->initem ) {
690
+				$this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
691
+			}
692
+			elseif ($this->inchannel) {
693
+				$this->concat($this->channel[ $this->current_namespace][ $el ], $text);
694
+			}
695
+			elseif ($this->intextinput) {
696
+				$this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
697
+			}
698
+			elseif ($this->inimage) {
699
+				$this->concat($this->image[ $this->current_namespace ][ $el ], $text);
700
+			}
701
+		}
702
+		else {
703
+			if ( $this->initem ) {
704
+				$this->concat($this->current_item[ $el ], $text);
705
+			}
706
+			elseif ($this->intextinput) {
707
+				$this->concat($this->textinput[ $el ], $text);
708
+			}
709
+			elseif ($this->inimage) {
710
+				$this->concat($this->image[ $el ], $text);
711
+			}
712
+			elseif ($this->inchannel) {
713
+				$this->concat($this->channel[ $el ], $text);
714
+			}
715
+
716
+		}
717
+	}
718 718
 
719 719
 }
720 720
 
@@ -727,51 +727,51 @@  discard block
 block discarded – undo
727 727
  */
728 728
 function xml2php($xml)
729 729
 {
730
-    $fils = 0;
731
-    $tab = false;
732
-    $array = array();
733
-    foreach($xml->children() as $key => $value)
734
-    {
735
-        $child = xml2php($value);
736
-
737
-        //To deal with the attributes
738
-        foreach($value->attributes() as $ak=>$av)
739
-        {
740
-            $child[$ak] = (string) $av;
741
-
742
-        }
743
-
744
-        //Let see if the new child is not in the array
745
-        if($tab==false && in_array($key,array_keys($array)))
746
-        {
747
-            //If this element is already in the array we will create an indexed array
748
-            $tmp = $array[$key];
749
-            $array[$key] = NULL;
750
-            $array[$key][] = $tmp;
751
-            $array[$key][] = $child;
752
-            $tab = true;
753
-        }
754
-        elseif($tab == true)
755
-        {
756
-            //Add an element in an existing array
757
-            $array[$key][] = $child;
758
-        }
759
-        else
760
-        {
761
-            //Add a simple element
762
-            $array[$key] = $child;
763
-        }
764
-
765
-        $fils++;
766
-    }
767
-
768
-
769
-    if($fils==0)
770
-    {
771
-        return (string) $xml;
772
-    }
773
-
774
-    return $array;
730
+	$fils = 0;
731
+	$tab = false;
732
+	$array = array();
733
+	foreach($xml->children() as $key => $value)
734
+	{
735
+		$child = xml2php($value);
736
+
737
+		//To deal with the attributes
738
+		foreach($value->attributes() as $ak=>$av)
739
+		{
740
+			$child[$ak] = (string) $av;
741
+
742
+		}
743
+
744
+		//Let see if the new child is not in the array
745
+		if($tab==false && in_array($key,array_keys($array)))
746
+		{
747
+			//If this element is already in the array we will create an indexed array
748
+			$tmp = $array[$key];
749
+			$array[$key] = NULL;
750
+			$array[$key][] = $tmp;
751
+			$array[$key][] = $child;
752
+			$tab = true;
753
+		}
754
+		elseif($tab == true)
755
+		{
756
+			//Add an element in an existing array
757
+			$array[$key][] = $child;
758
+		}
759
+		else
760
+		{
761
+			//Add a simple element
762
+			$array[$key] = $child;
763
+		}
764
+
765
+		$fils++;
766
+	}
767
+
768
+
769
+	if($fils==0)
770
+	{
771
+		return (string) $xml;
772
+	}
773
+
774
+	return $array;
775 775
 
776 776
 }
777 777
 
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     var $db;
30 30
     var $error;
31 31
 
32
-    private $_format='';
32
+    private $_format = '';
33 33
     private $_urlRSS;
34 34
     private $_language;
35 35
     private $_generator;
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
     private $_link;
40 40
     private $_title;
41 41
     private $_description;
42
-    private $_lastfetchdate;    // Last successful fetch
43
-    private $_rssarray=array();
42
+    private $_lastfetchdate; // Last successful fetch
43
+    private $_rssarray = array();
44 44
 
45 45
     // For parsing with xmlparser
46 46
     var $stack               = array(); // parser stack
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function __construct($db)
56 56
     {
57
-    	$this->db=$db;
57
+    	$this->db = $db;
58 58
     }
59 59
 
60 60
     /**
@@ -177,40 +177,40 @@  discard block
 block discarded – undo
177 177
      * 	@param	string	$cachedir	Directory where to save cache file
178 178
      *	@return	int					<0 if KO, >0 if OK
179 179
      */
180
-    public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
180
+    public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
181 181
     {
182 182
         global $conf;
183 183
 
184 184
         include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
185 185
 
186
-        $rss='';
187
-        $str='';    // This will contain content of feed
186
+        $rss = '';
187
+        $str = ''; // This will contain content of feed
188 188
 
189 189
         // Check parameters
190
-        if (! dol_is_url($urlRSS))
190
+        if (!dol_is_url($urlRSS))
191 191
         {
192
-            $this->error="ErrorBadUrl";
192
+            $this->error = "ErrorBadUrl";
193 193
             return -1;
194 194
         }
195 195
 
196 196
         $this->_urlRSS = $urlRSS;
197
-        $newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS,3);	// Force md5 hash (does not contains special chars)
198
-        $newmask='0644';
197
+        $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, 3); // Force md5 hash (does not contains special chars)
198
+        $newmask = '0644';
199 199
 
200 200
         //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
201 201
         $nowgmt = dol_now();
202 202
 
203 203
         // Search into cache
204
-        $foundintocache=0;
204
+        $foundintocache = 0;
205 205
         if ($cachedelay > 0 && $cachedir)
206 206
         {
207
-            $filedate=dol_filemtime($newpathofdestfile);
207
+            $filedate = dol_filemtime($newpathofdestfile);
208 208
             if ($filedate >= ($nowgmt - $cachedelay))
209 209
             {
210 210
                 //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
211
-                $foundintocache=1;
211
+                $foundintocache = 1;
212 212
 
213
-                $this->_lastfetchdate=$filedate;
213
+                $this->_lastfetchdate = $filedate;
214 214
             }
215 215
             else
216 216
             {
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
         else
227 227
         {
228 228
             try {
229
-                ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
229
+                ini_set("user_agent", "Dolibarr ERP-CRM RSS reader");
230 230
                 ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
231 231
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
232 232
 
233 233
                 $opts = array('http'=>array('method'=>"GET"));
234
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
235
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
234
+                if (!empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout'] = $conf->global->MAIN_USE_CONNECT_TIMEOUT;
235
+                if (!empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy'] = 'tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
236 236
                 //var_dump($opts);exit;
237 237
                 $context = stream_context_create($opts);
238 238
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         if ($str !== false)
247 247
         {
248 248
 	        // Convert $str into xml
249
-	        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
249
+	        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
250 250
 	        {
251 251
 	            //print 'xx'.LIBXML_NOCDATA;
252 252
 	            libxml_use_internal_errors(false);
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 	        }
255 255
 	        else
256 256
 	        {
257
-	            $xmlparser=xml_parser_create('');
257
+	            $xmlparser = xml_parser_create('');
258 258
 	            if (!is_resource($xmlparser)) {
259
-	                $this->error="ErrorFailedToCreateParser"; return -1;
259
+	                $this->error = "ErrorFailedToCreateParser"; return -1;
260 260
 	            }
261 261
 
262 262
 	            xml_set_object($xmlparser, $this);
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	            xml_set_character_data_handler($xmlparser, 'feed_cdata');
265 265
 	            $status = xml_parse($xmlparser, $str);
266 266
 	            xml_parser_free($xmlparser);
267
-	            $rss=$this;
267
+	            $rss = $this;
268 268
 	            //var_dump($rss->_format);exit;
269 269
 	        }
270 270
         }
@@ -276,31 +276,31 @@  discard block
 block discarded – undo
276 276
             if (empty($foundintocache) && $cachedir)
277 277
             {
278 278
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
279
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
279
+                if (!dol_is_dir($cachedir)) dol_mkdir($cachedir);
280 280
                 $fp = fopen($newpathofdestfile, 'w');
281 281
                 fwrite($fp, $str);
282 282
                 fclose($fp);
283
-                if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
283
+                if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
284 284
                 @chmod($newpathofdestfile, octdec($newmask));
285 285
 
286
-                $this->_lastfetchdate=$nowgmt;
286
+                $this->_lastfetchdate = $nowgmt;
287 287
             }
288 288
 
289
-            unset($str);    // Free memory
289
+            unset($str); // Free memory
290 290
 
291 291
             if (empty($rss->_format))    // If format not detected automatically
292 292
             {
293
-                $rss->_format='rss';
294
-                if (empty($rss->channel)) $rss->_format='atom';
293
+                $rss->_format = 'rss';
294
+                if (empty($rss->channel)) $rss->_format = 'atom';
295 295
             }
296 296
 
297
-            $items=array();
297
+            $items = array();
298 298
 
299 299
             // Save description entries
300 300
             if ($rss->_format == 'rss')
301 301
             {
302 302
                 //var_dump($rss);
303
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
303
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
304 304
                 {
305 305
                     if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
306 306
                     if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
@@ -324,14 +324,14 @@  discard block
 block discarded – undo
324 324
                     if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
325 325
                 }
326 326
 
327
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
328
-                else $items=$rss->items;                                                              // With xmlparse
327
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items = $rss->channel->item; // With simplexml
328
+                else $items = $rss->items; // With xmlparse
329 329
                 //var_dump($items);exit;
330 330
             }
331 331
             else if ($rss->_format == 'atom')
332 332
             {
333 333
                 //var_dump($rss);
334
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
334
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
335 335
                 {
336 336
                     if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
337 337
                     if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
                     if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
351 351
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
352 352
                 }
353
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
354
-                    $tmprss=xml2php($rss); $items=$tmprss['entry'];
353
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
354
+                    $tmprss = xml2php($rss); $items = $tmprss['entry'];
355 355
                 } // With simplexml
356
-                else $items=$rss->items;                                                              // With xmlparse
356
+                else $items = $rss->items; // With xmlparse
357 357
                 //var_dump($items);exit;
358 358
             }
359 359
 
@@ -362,12 +362,12 @@  discard block
 block discarded – undo
362 362
             // Loop on each record
363 363
             if (is_array($items))
364 364
             {
365
-                foreach($items as $item)
365
+                foreach ($items as $item)
366 366
                 {
367 367
                     //var_dump($item);exit;
368 368
                     if ($rss->_format == 'rss')
369 369
                     {
370
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
370
+                        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
371 371
                         {
372 372
                             $itemLink = (string) $item->link;
373 373
                             $itemTitle = (string) $item->title;
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
                         }
388 388
 
389 389
                         // Loop on each category
390
-                        $itemCategory=array();
390
+                        $itemCategory = array();
391 391
                         if (is_array($item->category))
392 392
                         {
393 393
                             foreach ($item->category as $cat)
@@ -398,14 +398,14 @@  discard block
 block discarded – undo
398 398
                     }
399 399
                     else if ($rss->_format == 'atom')
400 400
                     {
401
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
401
+                        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
402 402
                         {
403 403
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
404 404
                             $itemTitle = (string) $item['title'];
405 405
                             $itemDescription = (string) $item['summary'];
406 406
                             $itemPubDate = (string) $item['created'];
407 407
                             $itemId = (string) $item['id'];
408
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
408
+                            $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
409 409
                         }
410 410
                         else
411 411
                         {
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
                             $itemDescription = (string) $item['summary'];
415 415
                             $itemPubDate = (string) $item['created'];
416 416
                             $itemId = (string) $item['id'];
417
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
417
+                            $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
418 418
                         }
419 419
                     }
420 420
                     else print 'ErrorBadFeedFormat';
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 
433 433
                     $i++;
434 434
 
435
-                    if ($i > $maxNb)    break;    // We get all records we want
435
+                    if ($i > $maxNb)    break; // We get all records we want
436 436
                 }
437 437
             }
438 438
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
         }
441 441
         else
442 442
         {
443
-            $this->error='ErrorFailedToLoadRSSFile';
443
+            $this->error = 'ErrorFailedToLoadRSSFile';
444 444
             return -1;
445 445
         }
446 446
     }
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         {
467 467
             list($ns, $el) = explode(':', $element, 2);
468 468
         }
469
-        if ( $ns and $ns != 'rdf' )
469
+        if ($ns and $ns != 'rdf')
470 470
         {
471 471
             $this->current_namespace = $ns;
472 472
         }
@@ -474,15 +474,15 @@  discard block
 block discarded – undo
474 474
         // if feed type isn't set, then this is first element of feed identify feed from root element
475 475
         if (empty($this->_format))
476 476
         {
477
-            if ( $el == 'rdf' ) {
477
+            if ($el == 'rdf') {
478 478
                 $this->_format = 'rss';
479 479
                 $this->feed_version = '1.0';
480 480
             }
481
-            elseif ( $el == 'rss' ) {
481
+            elseif ($el == 'rss') {
482 482
                 $this->_format = 'rss';
483 483
                 $this->feed_version = $attrs['version'];
484 484
             }
485
-            elseif ( $el == 'feed' ) {
485
+            elseif ($el == 'feed') {
486 486
                 $this->_format = 'atom';
487 487
                 $this->feed_version = $attrs['version'];
488 488
                 $this->inchannel = true;
@@ -490,14 +490,14 @@  discard block
 block discarded – undo
490 490
             return;
491 491
         }
492 492
 
493
-        if ( $el == 'channel' )
493
+        if ($el == 'channel')
494 494
         {
495 495
             $this->inchannel = true;
496 496
         }
497
-        elseif ($el == 'item' or $el == 'entry' )
497
+        elseif ($el == 'item' or $el == 'entry')
498 498
         {
499 499
             $this->initem = true;
500
-            if ( isset($attrs['rdf:about']) ) {
500
+            if (isset($attrs['rdf:about'])) {
501 501
                 $this->current_item['about'] = $attrs['rdf:about'];
502 502
             }
503 503
         }
@@ -521,10 +521,10 @@  discard block
 block discarded – undo
521 521
         }
522 522
 
523 523
         // handle atom content constructs
524
-        elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
524
+        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS))
525 525
         {
526 526
             // avoid clashing w/ RSS mod_content
527
-            if ($el == 'content' ) {
527
+            if ($el == 'content') {
528 528
                 $el = 'atom_content';
529 529
             }
530 530
 
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         }
535 535
 
536 536
         // if inside an Atom content construct (e.g. content or summary) field treat tags as text
537
-        elseif ($this->_format == 'atom' and $this->incontent )
537
+        elseif ($this->_format == 'atom' and $this->incontent)
538 538
         {
539 539
             // if tags are inlined, then flatten
540 540
             $attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs)));
@@ -548,14 +548,14 @@  discard block
 block discarded – undo
548 548
         // Magpie treats link elements of type rel='alternate'
549 549
         // as being equivalent to RSS's simple link element.
550 550
         //
551
-        elseif ($this->_format == 'atom' and $el == 'link' )
551
+        elseif ($this->_format == 'atom' and $el == 'link')
552 552
         {
553
-            if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
553
+            if (isset($attrs['rel']) && $attrs['rel'] == 'alternate')
554 554
             {
555 555
                 $link_el = 'link';
556 556
             }
557 557
             else {
558
-                $link_el = 'link_' . $attrs['rel'];
558
+                $link_el = 'link_'.$attrs['rel'];
559 559
             }
560 560
 
561 561
             $this->append($link_el, $attrs['href']);
@@ -604,26 +604,26 @@  discard block
 block discarded – undo
604 604
             $this->current_item = array();
605 605
             $this->initem = false;
606 606
         }
607
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
607
+        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput')
608 608
         {
609 609
             $this->intextinput = false;
610 610
         }
611
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
611
+        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image')
612 612
         {
613 613
             $this->inimage = false;
614 614
         }
615
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
615
+        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS))
616 616
         {
617 617
             $this->incontent = false;
618 618
         }
619
-        elseif ($el == 'channel' or $el == 'feed' )
619
+        elseif ($el == 'channel' or $el == 'feed')
620 620
         {
621 621
             $this->inchannel = false;
622 622
         }
623
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
623
+        elseif ($this->_format == 'atom' and $this->incontent) {
624 624
             // balance tags properly
625 625
             // note:  i don't think this is actually neccessary
626
-            if ( $this->stack[0] == $el )
626
+            if ($this->stack[0] == $el)
627 627
             {
628 628
                 $this->append_content("</$el>");
629 629
             }
@@ -648,10 +648,10 @@  discard block
 block discarded – undo
648 648
      *  @param	string	$str2		Str2
649 649
      *  @return	string				String cancatenated
650 650
      */
651
-    function concat(&$str1, $str2="")
651
+    function concat(&$str1, $str2 = "")
652 652
     {
653
-        if (!isset($str1) ) {
654
-            $str1="";
653
+        if (!isset($str1)) {
654
+            $str1 = "";
655 655
         }
656 656
         $str1 .= $str2;
657 657
     }
@@ -664,11 +664,11 @@  discard block
 block discarded – undo
664 664
      */
665 665
     function append_content($text)
666 666
     {
667
-        if ( $this->initem ) {
668
-            $this->concat($this->current_item[ $this->incontent ], $text);
667
+        if ($this->initem) {
668
+            $this->concat($this->current_item[$this->incontent], $text);
669 669
         }
670
-        elseif ( $this->inchannel ) {
671
-            $this->concat($this->channel[ $this->incontent ], $text);
670
+        elseif ($this->inchannel) {
671
+            $this->concat($this->channel[$this->incontent], $text);
672 672
         }
673 673
     }
674 674
 
@@ -684,33 +684,33 @@  discard block
 block discarded – undo
684 684
         if (!$el) {
685 685
             return;
686 686
         }
687
-        if ( $this->current_namespace )
687
+        if ($this->current_namespace)
688 688
         {
689
-            if ( $this->initem ) {
690
-                $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
689
+            if ($this->initem) {
690
+                $this->concat($this->current_item[$this->current_namespace][$el], $text);
691 691
             }
692 692
             elseif ($this->inchannel) {
693
-                $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
693
+                $this->concat($this->channel[$this->current_namespace][$el], $text);
694 694
             }
695 695
             elseif ($this->intextinput) {
696
-                $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
696
+                $this->concat($this->textinput[$this->current_namespace][$el], $text);
697 697
             }
698 698
             elseif ($this->inimage) {
699
-                $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
699
+                $this->concat($this->image[$this->current_namespace][$el], $text);
700 700
             }
701 701
         }
702 702
         else {
703
-            if ( $this->initem ) {
704
-                $this->concat($this->current_item[ $el ], $text);
703
+            if ($this->initem) {
704
+                $this->concat($this->current_item[$el], $text);
705 705
             }
706 706
             elseif ($this->intextinput) {
707
-                $this->concat($this->textinput[ $el ], $text);
707
+                $this->concat($this->textinput[$el], $text);
708 708
             }
709 709
             elseif ($this->inimage) {
710
-                $this->concat($this->image[ $el ], $text);
710
+                $this->concat($this->image[$el], $text);
711 711
             }
712 712
             elseif ($this->inchannel) {
713
-                $this->concat($this->channel[ $el ], $text);
713
+                $this->concat($this->channel[$el], $text);
714 714
             }
715 715
 
716 716
         }
@@ -730,19 +730,19 @@  discard block
 block discarded – undo
730 730
     $fils = 0;
731 731
     $tab = false;
732 732
     $array = array();
733
-    foreach($xml->children() as $key => $value)
733
+    foreach ($xml->children() as $key => $value)
734 734
     {
735 735
         $child = xml2php($value);
736 736
 
737 737
         //To deal with the attributes
738
-        foreach($value->attributes() as $ak=>$av)
738
+        foreach ($value->attributes() as $ak=>$av)
739 739
         {
740 740
             $child[$ak] = (string) $av;
741 741
 
742 742
         }
743 743
 
744 744
         //Let see if the new child is not in the array
745
-        if($tab==false && in_array($key,array_keys($array)))
745
+        if ($tab == false && in_array($key, array_keys($array)))
746 746
         {
747 747
             //If this element is already in the array we will create an indexed array
748 748
             $tmp = $array[$key];
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
             $array[$key][] = $child;
752 752
             $tab = true;
753 753
         }
754
-        elseif($tab == true)
754
+        elseif ($tab == true)
755 755
         {
756 756
             //Add an element in an existing array
757 757
             $array[$key][] = $child;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
     }
767 767
 
768 768
 
769
-    if($fils==0)
769
+    if ($fils == 0)
770 770
     {
771 771
         return (string) $xml;
772 772
     }
Please login to merge, or discard this patch.
Braces   +147 added lines, -105 removed lines patch added patch discarded remove patch
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
                 $foundintocache=1;
212 212
 
213 213
                 $this->_lastfetchdate=$filedate;
214
-            }
215
-            else
214
+            } else
216 215
             {
217 216
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
218 217
             }
219 218
         }
220 219
 
221 220
         // Load file into $str
222
-        if ($foundintocache)    // Cache file found and is not too old
221
+        if ($foundintocache) {
222
+        	// Cache file found and is not too old
223 223
         {
224 224
             $str = file_get_contents($newpathofdestfile);
225 225
         }
226
-        else
226
+        } else
227 227
         {
228 228
             try {
229 229
                 ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
@@ -231,14 +231,17 @@  discard block
 block discarded – undo
231 231
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
232 232
 
233 233
                 $opts = array('http'=>array('method'=>"GET"));
234
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
235
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
234
+                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) {
235
+                	$opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
236
+                }
237
+                if (! empty($conf->global->MAIN_PROXY_USE)) {
238
+                	$opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
239
+                }
236 240
                 //var_dump($opts);exit;
237 241
                 $context = stream_context_create($opts);
238 242
 
239 243
                 $str = file_get_contents($this->_urlRSS, false, $context);
240
-            }
241
-            catch (Exception $e) {
244
+            } catch (Exception $e) {
242 245
                 print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
243 246
             }
244 247
         }
@@ -251,8 +254,7 @@  discard block
 block discarded – undo
251 254
 	            //print 'xx'.LIBXML_NOCDATA;
252 255
 	            libxml_use_internal_errors(false);
253 256
 	            $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
254
-	        }
255
-	        else
257
+	        } else
256 258
 	        {
257 259
 	            $xmlparser=xml_parser_create('');
258 260
 	            if (!is_resource($xmlparser)) {
@@ -276,11 +278,15 @@  discard block
 block discarded – undo
276 278
             if (empty($foundintocache) && $cachedir)
277 279
             {
278 280
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
279
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
281
+                if (! dol_is_dir($cachedir)) {
282
+                	dol_mkdir($cachedir);
283
+                }
280 284
                 $fp = fopen($newpathofdestfile, 'w');
281 285
                 fwrite($fp, $str);
282 286
                 fclose($fp);
283
-                if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
287
+                if (! empty($conf->global->MAIN_UMASK)) {
288
+                	$newmask=$conf->global->MAIN_UMASK;
289
+                }
284 290
                 @chmod($newpathofdestfile, octdec($newmask));
285 291
 
286 292
                 $this->_lastfetchdate=$nowgmt;
@@ -288,10 +294,14 @@  discard block
 block discarded – undo
288 294
 
289 295
             unset($str);    // Free memory
290 296
 
291
-            if (empty($rss->_format))    // If format not detected automatically
297
+            if (empty($rss->_format)) {
298
+            	// If format not detected automatically
292 299
             {
293 300
                 $rss->_format='rss';
294
-                if (empty($rss->channel)) $rss->_format='atom';
301
+            }
302
+                if (empty($rss->channel)) {
303
+                	$rss->_format='atom';
304
+                }
295 305
             }
296 306
 
297 307
             $items=array();
@@ -302,58 +312,114 @@  discard block
 block discarded – undo
302 312
                 //var_dump($rss);
303 313
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
304 314
                 {
305
-                    if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
306
-                    if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
307
-                    if (!empty($rss->channel->copyright))     $this->_copyright = (string) $rss->channel->copyright;
308
-                    if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
309
-                    if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
310
-                    if (!empty($rss->channel->link))		  $this->_link = (string) $rss->channel->link;
311
-                    if (!empty($rss->channel->title))         $this->_title = (string) $rss->channel->title;
312
-                    if (!empty($rss->channel->description))	  $this->_description = (string) $rss->channel->description;
313
-                }
314
-                else
315
+                    if (!empty($rss->channel->language)) {
316
+                    	$this->_language = (string) $rss->channel->language;
317
+                    }
318
+                    if (!empty($rss->channel->generator)) {
319
+                    	$this->_generator = (string) $rss->channel->generator;
320
+                    }
321
+                    if (!empty($rss->channel->copyright)) {
322
+                    	$this->_copyright = (string) $rss->channel->copyright;
323
+                    }
324
+                    if (!empty($rss->channel->lastbuilddate)) {
325
+                    	$this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
326
+                    }
327
+                    if (!empty($rss->channel->image->url[0])) {
328
+                    	$this->_imageurl = (string) $rss->channel->image->url[0];
329
+                    }
330
+                    if (!empty($rss->channel->link)) {
331
+                    	$this->_link = (string) $rss->channel->link;
332
+                    }
333
+                    if (!empty($rss->channel->title)) {
334
+                    	$this->_title = (string) $rss->channel->title;
335
+                    }
336
+                    if (!empty($rss->channel->description)) {
337
+                    	$this->_description = (string) $rss->channel->description;
338
+                    }
339
+                } else
315 340
                 {
316 341
                     //var_dump($rss->channel);
317
-                    if (!empty($rss->channel['language']))      $this->_language = (string) $rss->channel['language'];
318
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
319
-                    if (!empty($rss->channel['copyright']))     $this->_copyright = (string) $rss->channel['copyright'];
320
-                    if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
321
-                    if (!empty($rss->image['url']))             $this->_imageurl = (string) $rss->image['url'];
322
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
323
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
324
-                    if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
342
+                    if (!empty($rss->channel['language'])) {
343
+                    	$this->_language = (string) $rss->channel['language'];
344
+                    }
345
+                    if (!empty($rss->channel['generator'])) {
346
+                    	$this->_generator = (string) $rss->channel['generator'];
347
+                    }
348
+                    if (!empty($rss->channel['copyright'])) {
349
+                    	$this->_copyright = (string) $rss->channel['copyright'];
350
+                    }
351
+                    if (!empty($rss->channel['lastbuilddate'])) {
352
+                    	$this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
353
+                    }
354
+                    if (!empty($rss->image['url'])) {
355
+                    	$this->_imageurl = (string) $rss->image['url'];
356
+                    }
357
+                    if (!empty($rss->channel['link'])) {
358
+                    	$this->_link = (string) $rss->channel['link'];
359
+                    }
360
+                    if (!empty($rss->channel['title'])) {
361
+                    	$this->_title = (string) $rss->channel['title'];
362
+                    }
363
+                    if (!empty($rss->channel['description'])) {
364
+                    	$this->_description = (string) $rss->channel['description'];
365
+                    }
325 366
                 }
326 367
 
327
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
328
-                else $items=$rss->items;                                                              // With xmlparse
368
+                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
369
+                	$items=$rss->channel->item;
370
+                }
371
+                // With simplexml
372
+                else {
373
+                	$items=$rss->items;
374
+                }
375
+                // With xmlparse
329 376
                 //var_dump($items);exit;
330
-            }
331
-            else if ($rss->_format == 'atom')
377
+            } else if ($rss->_format == 'atom')
332 378
             {
333 379
                 //var_dump($rss);
334 380
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
335 381
                 {
336
-                    if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
337
-                    if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
338
-                    if (!empty($rss->link->href))    $this->_link = (string) $rss->link->href;
339
-                    if (!empty($rss->title))         $this->_title = (string) $rss->title;
340
-                    if (!empty($rss->description))	 $this->_description = (string) $rss->description;
341
-                }
342
-                else
382
+                    if (!empty($rss->generator)) {
383
+                    	$this->_generator = (string) $rss->generator;
384
+                    }
385
+                    if (!empty($rss->lastbuilddate)) {
386
+                    	$this->_lastbuilddate = (string) $rss->modified;
387
+                    }
388
+                    if (!empty($rss->link->href)) {
389
+                    	$this->_link = (string) $rss->link->href;
390
+                    }
391
+                    if (!empty($rss->title)) {
392
+                    	$this->_title = (string) $rss->title;
393
+                    }
394
+                    if (!empty($rss->description)) {
395
+                    	$this->_description = (string) $rss->description;
396
+                    }
397
+                } else
343 398
                 {
344 399
                     //if (!empty($rss->channel['rss_language']))      $this->_language = (string) $rss->channel['rss_language'];
345
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
400
+                    if (!empty($rss->channel['generator'])) {
401
+                    	$this->_generator = (string) $rss->channel['generator'];
402
+                    }
346 403
                     //if (!empty($rss->channel['rss_copyright']))     $this->_copyright = (string) $rss->channel['rss_copyright'];
347
-                    if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
404
+                    if (!empty($rss->channel['modified'])) {
405
+                    	$this->_lastbuilddate = (string) $rss->channel['modified'];
406
+                    }
348 407
                     //if (!empty($rss->image['rss_url']))             $this->_imageurl = (string) $rss->image['rss_url'];
349
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
350
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
408
+                    if (!empty($rss->channel['link'])) {
409
+                    	$this->_link = (string) $rss->channel['link'];
410
+                    }
411
+                    if (!empty($rss->channel['title'])) {
412
+                    	$this->_title = (string) $rss->channel['title'];
413
+                    }
351 414
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
352 415
                 }
353 416
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
354 417
                     $tmprss=xml2php($rss); $items=$tmprss['entry'];
355 418
                 } // With simplexml
356
-                else $items=$rss->items;                                                              // With xmlparse
419
+                else {
420
+                	$items=$rss->items;
421
+                }
422
+                // With xmlparse
357 423
                 //var_dump($items);exit;
358 424
             }
359 425
 
@@ -375,8 +441,7 @@  discard block
 block discarded – undo
375 441
                             $itemPubDate = (string) $item->pubDate;
376 442
                             $itemId = '';
377 443
                             $itemAuthor = '';
378
-                        }
379
-                        else
444
+                        } else
380 445
                         {
381 446
                             $itemLink = (string) $item['link'];
382 447
                             $itemTitle = (string) $item['title'];
@@ -395,8 +460,7 @@  discard block
 block discarded – undo
395 460
                                 $itemCategory[] = (string) $cat;
396 461
                             }
397 462
                         }
398
-                    }
399
-                    else if ($rss->_format == 'atom')
463
+                    } else if ($rss->_format == 'atom')
400 464
                     {
401 465
                         if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
402 466
                         {
@@ -406,8 +470,7 @@  discard block
 block discarded – undo
406 470
                             $itemPubDate = (string) $item['created'];
407 471
                             $itemId = (string) $item['id'];
408 472
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
409
-                        }
410
-                        else
473
+                        } else
411 474
                         {
412 475
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
413 476
                             $itemTitle = (string) $item['title'];
@@ -416,8 +479,9 @@  discard block
 block discarded – undo
416 479
                             $itemId = (string) $item['id'];
417 480
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
418 481
                         }
482
+                    } else {
483
+                    	print 'ErrorBadFeedFormat';
419 484
                     }
420
-                    else print 'ErrorBadFeedFormat';
421 485
 
422 486
                     // Add record to result array
423 487
                     $this->_rssarray[$i] = array(
@@ -432,13 +496,15 @@  discard block
 block discarded – undo
432 496
 
433 497
                     $i++;
434 498
 
435
-                    if ($i > $maxNb)    break;    // We get all records we want
499
+                    if ($i > $maxNb) {
500
+                    	break;
501
+                    }
502
+                    // We get all records we want
436 503
                 }
437 504
             }
438 505
 
439 506
             return 1;
440
-        }
441
-        else
507
+        } else
442 508
         {
443 509
             $this->error='ErrorFailedToLoadRSSFile';
444 510
             return -1;
@@ -477,12 +543,10 @@  discard block
 block discarded – undo
477 543
             if ( $el == 'rdf' ) {
478 544
                 $this->_format = 'rss';
479 545
                 $this->feed_version = '1.0';
480
-            }
481
-            elseif ( $el == 'rss' ) {
546
+            } elseif ( $el == 'rss' ) {
482 547
                 $this->_format = 'rss';
483 548
                 $this->feed_version = $attrs['version'];
484
-            }
485
-            elseif ( $el == 'feed' ) {
549
+            } elseif ( $el == 'feed' ) {
486 550
                 $this->_format = 'atom';
487 551
                 $this->feed_version = $attrs['version'];
488 552
                 $this->inchannel = true;
@@ -493,8 +557,7 @@  discard block
 block discarded – undo
493 557
         if ( $el == 'channel' )
494 558
         {
495 559
             $this->inchannel = true;
496
-        }
497
-        elseif ($el == 'item' or $el == 'entry' )
560
+        } elseif ($el == 'item' or $el == 'entry' )
498 561
         {
499 562
             $this->initem = true;
500 563
             if ( isset($attrs['rdf:about']) ) {
@@ -510,9 +573,7 @@  discard block
 block discarded – undo
510 573
         $el == 'textinput' )
511 574
         {
512 575
             $this->intextinput = true;
513
-        }
514
-
515
-        elseif (
576
+        } elseif (
516 577
         $this->_format == 'rss' and
517 578
         $this->current_namespace == '' and
518 579
         $el == 'image' )
@@ -553,8 +614,7 @@  discard block
 block discarded – undo
553 614
             if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
554 615
             {
555 616
                 $link_el = 'link';
556
-            }
557
-            else {
617
+            } else {
558 618
                 $link_el = 'link_' . $attrs['rel'];
559 619
             }
560 620
 
@@ -579,8 +639,7 @@  discard block
 block discarded – undo
579 639
         if ($this->_format == 'atom' and $this->incontent)
580 640
         {
581 641
             $this->append_content($text);
582
-        }
583
-        else
642
+        } else
584 643
         {
585 644
             $current_el = join('_', array_reverse($this->stack));
586 645
             $this->append($current_el, $text);
@@ -603,37 +662,30 @@  discard block
 block discarded – undo
603 662
             $this->items[] = $this->current_item;
604 663
             $this->current_item = array();
605 664
             $this->initem = false;
606
-        }
607
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
665
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
608 666
         {
609 667
             $this->intextinput = false;
610
-        }
611
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
668
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
612 669
         {
613 670
             $this->inimage = false;
614
-        }
615
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
671
+        } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
616 672
         {
617 673
             $this->incontent = false;
618
-        }
619
-        elseif ($el == 'channel' or $el == 'feed' )
674
+        } elseif ($el == 'channel' or $el == 'feed' )
620 675
         {
621 676
             $this->inchannel = false;
622
-        }
623
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
677
+        } elseif ($this->_format == 'atom' and $this->incontent  ) {
624 678
             // balance tags properly
625 679
             // note:  i don't think this is actually neccessary
626 680
             if ( $this->stack[0] == $el )
627 681
             {
628 682
                 $this->append_content("</$el>");
629
-            }
630
-            else {
683
+            } else {
631 684
                 $this->append_content("<$el />");
632 685
             }
633 686
 
634 687
             array_shift($this->stack);
635
-        }
636
-        else {
688
+        } else {
637 689
             array_shift($this->stack);
638 690
         }
639 691
 
@@ -666,8 +718,7 @@  discard block
 block discarded – undo
666 718
     {
667 719
         if ( $this->initem ) {
668 720
             $this->concat($this->current_item[ $this->incontent ], $text);
669
-        }
670
-        elseif ( $this->inchannel ) {
721
+        } elseif ( $this->inchannel ) {
671 722
             $this->concat($this->channel[ $this->incontent ], $text);
672 723
         }
673 724
     }
@@ -688,28 +739,21 @@  discard block
 block discarded – undo
688 739
         {
689 740
             if ( $this->initem ) {
690 741
                 $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
691
-            }
692
-            elseif ($this->inchannel) {
742
+            } elseif ($this->inchannel) {
693 743
                 $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
694
-            }
695
-            elseif ($this->intextinput) {
744
+            } elseif ($this->intextinput) {
696 745
                 $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
697
-            }
698
-            elseif ($this->inimage) {
746
+            } elseif ($this->inimage) {
699 747
                 $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
700 748
             }
701
-        }
702
-        else {
749
+        } else {
703 750
             if ( $this->initem ) {
704 751
                 $this->concat($this->current_item[ $el ], $text);
705
-            }
706
-            elseif ($this->intextinput) {
752
+            } elseif ($this->intextinput) {
707 753
                 $this->concat($this->textinput[ $el ], $text);
708
-            }
709
-            elseif ($this->inimage) {
754
+            } elseif ($this->inimage) {
710 755
                 $this->concat($this->image[ $el ], $text);
711
-            }
712
-            elseif ($this->inchannel) {
756
+            } elseif ($this->inchannel) {
713 757
                 $this->concat($this->channel[ $el ], $text);
714 758
             }
715 759
 
@@ -750,13 +794,11 @@  discard block
 block discarded – undo
750 794
             $array[$key][] = $tmp;
751 795
             $array[$key][] = $child;
752 796
             $tab = true;
753
-        }
754
-        elseif($tab == true)
797
+        } elseif($tab == true)
755 798
         {
756 799
             //Add an element in an existing array
757 800
             $array[$key][] = $child;
758
-        }
759
-        else
801
+        } else
760 802
         {
761 803
             //Add a simple element
762 804
             $array[$key] = $child;
Please login to merge, or discard this patch.