Passed
Pull Request — master (#2)
by
unknown
26:19
created
dolibarr/htdocs/core/actions_fetchobject.inc.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -30,25 +30,25 @@
 block discarded – undo
30 30
 
31 31
 if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0))
32 32
 {
33
-	if (($id > 0 && is_numeric($id)) || ! empty($ref))	// To discard case when id is list of ids like '1,2,3...'
34
-	{
35
-	    $ret = $object->fetch($id, $ref);
36
-	    if ($ret > 0)
37
-	    {
38
-	        $object->fetch_thirdparty();
39
-	        $id = $object->id;
40
-	    }
41
-	    else
42
-	    {
43
-	    	if (empty($object->error) && ! count($object->errors))
44
-	    	{
45
-	    		if ($ret < 0)	// if $ret == 0, it means not found.
46
-	    		{
47
-	    			setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
48
-	    		}
49
-	    	}
50
-	        else setEventMessages($object->error, $object->errors, 'errors');
51
-	        $action='';
52
-	    }
53
-	}
33
+    if (($id > 0 && is_numeric($id)) || ! empty($ref))	// To discard case when id is list of ids like '1,2,3...'
34
+    {
35
+        $ret = $object->fetch($id, $ref);
36
+        if ($ret > 0)
37
+        {
38
+            $object->fetch_thirdparty();
39
+            $id = $object->id;
40
+        }
41
+        else
42
+        {
43
+            if (empty($object->error) && ! count($object->errors))
44
+            {
45
+                if ($ret < 0)	// if $ret == 0, it means not found.
46
+                {
47
+                    setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
48
+                }
49
+            }
50
+            else setEventMessages($object->error, $object->errors, 'errors');
51
+            $action='';
52
+        }
53
+    }
54 54
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/selectobject.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,16 +62,16 @@
 block discarded – undo
62 62
 $classpath=$InfoFieldList[1];
63 63
 if (! empty($classpath))
64 64
 {
65
-	dol_include_once($classpath);
66
-	if ($classname && class_exists($classname))
67
-	{
68
-		$objecttmp = new $classname($db);
69
-	}
65
+    dol_include_once($classpath);
66
+    if ($classname && class_exists($classname))
67
+    {
68
+        $objecttmp = new $classname($db);
69
+    }
70 70
 }
71 71
 if (! is_object($objecttmp))
72 72
 {
73
-	dol_syslog('Error bad param objectdesc', LOG_WARNING);
74
-	print 'Error bad param objectdesc';
73
+    dol_syslog('Error bad param objectdesc', LOG_WARNING);
74
+    print 'Error bad param objectdesc';
75 75
 }
76 76
 
77 77
 // When used from jQuery, the search term is added as GET param "term".
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/loadinplace.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -44,72 +44,72 @@
 block discarded – undo
44 44
 // Load original field value
45 45
 if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($fk_element))
46 46
 {
47
-	$ext_element	= GETPOST('ext_element','alpha');
48
-	$field			= substr($field, 8); // remove prefix val_
49
-	$type			= GETPOST('type','alpha');
50
-	$loadmethod		= (GETPOST('loadmethod','alpha') ? GETPOST('loadmethod','alpha') : 'getValueFrom');
47
+    $ext_element	= GETPOST('ext_element','alpha');
48
+    $field			= substr($field, 8); // remove prefix val_
49
+    $type			= GETPOST('type','alpha');
50
+    $loadmethod		= (GETPOST('loadmethod','alpha') ? GETPOST('loadmethod','alpha') : 'getValueFrom');
51 51
 
52
-	if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
53
-	{
54
-		$element = $regs[1];
55
-		$subelement = $regs[2];
56
-	}
52
+    if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
53
+    {
54
+        $element = $regs[1];
55
+        $subelement = $regs[2];
56
+    }
57 57
 
58
-	if ($element == 'propal') $element = 'propale';
59
-	else if ($element == 'fichinter') $element = 'ficheinter';
60
-	else if ($element == 'product') $element = 'produit';
61
-	else if ($element == 'member') $element = 'adherent';
62
-	else if ($element == 'order_supplier') {
63
-		$element = 'fournisseur';
64
-		$subelement = 'commande';
65
-	}
66
-	else if ($element == 'invoice_supplier') {
67
-		$element = 'fournisseur';
68
-		$subelement = 'facture';
69
-	}
58
+    if ($element == 'propal') $element = 'propale';
59
+    else if ($element == 'fichinter') $element = 'ficheinter';
60
+    else if ($element == 'product') $element = 'produit';
61
+    else if ($element == 'member') $element = 'adherent';
62
+    else if ($element == 'order_supplier') {
63
+        $element = 'fournisseur';
64
+        $subelement = 'commande';
65
+    }
66
+    else if ($element == 'invoice_supplier') {
67
+        $element = 'fournisseur';
68
+        $subelement = 'facture';
69
+    }
70 70
 
71
-	if ($user->rights->$element->lire || $user->rights->$element->read
72
-	|| (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
73
-	|| ($element == 'payment' && $user->rights->facture->lire)
74
-	|| ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire))
75
-	{
76
-		if ($type == 'select')
77
-		{
78
-			$methodname	= 'load_cache_'.$loadmethod;
79
-			$cachename = 'cache_'.GETPOST('loadmethod','alpha');
71
+    if ($user->rights->$element->lire || $user->rights->$element->read
72
+    || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
73
+    || ($element == 'payment' && $user->rights->facture->lire)
74
+    || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire))
75
+    {
76
+        if ($type == 'select')
77
+        {
78
+            $methodname	= 'load_cache_'.$loadmethod;
79
+            $cachename = 'cache_'.GETPOST('loadmethod','alpha');
80 80
 
81
-			$form = new Form($db);
82
-			if (method_exists($form, $methodname))
83
-			{
84
-				$ret = $form->$methodname();
85
-				if ($ret > 0) echo json_encode($form->$cachename);
86
-			}
87
-			else if (! empty($ext_element))
88
-			{
89
-				$module = $subelement = $ext_element;
90
-				if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
91
-				{
92
-					$module = $regs[1];
93
-					$subelement = $regs[2];
94
-				}
81
+            $form = new Form($db);
82
+            if (method_exists($form, $methodname))
83
+            {
84
+                $ret = $form->$methodname();
85
+                if ($ret > 0) echo json_encode($form->$cachename);
86
+            }
87
+            else if (! empty($ext_element))
88
+            {
89
+                $module = $subelement = $ext_element;
90
+                if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
91
+                {
92
+                    $module = $regs[1];
93
+                    $subelement = $regs[2];
94
+                }
95 95
 
96
-				dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
97
-				$classname = 'Actions'.ucfirst($subelement);
98
-				$object = new $classname($db);
99
-				$ret = $object->$methodname($fk_element);
100
-				if ($ret > 0) echo json_encode($object->$cachename);
101
-			}
102
-		}
103
-		else
104
-		{
105
-			$object = new GenericObject($db);
106
-			$value=$object->$loadmethod($table_element, $fk_element, $field);
107
-			echo $value;
108
-		}
109
-	}
110
-	else
111
-	{
112
-		echo $langs->transnoentities('NotEnoughPermissions');
113
-	}
96
+                dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
97
+                $classname = 'Actions'.ucfirst($subelement);
98
+                $object = new $classname($db);
99
+                $ret = $object->$methodname($fk_element);
100
+                if ($ret > 0) echo json_encode($object->$cachename);
101
+            }
102
+        }
103
+        else
104
+        {
105
+            $object = new GenericObject($db);
106
+            $value=$object->$loadmethod($table_element, $fk_element, $field);
107
+            echo $value;
108
+        }
109
+    }
110
+    else
111
+    {
112
+        echo $langs->transnoentities('NotEnoughPermissions');
113
+    }
114 114
 }
115 115
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/getaccountcurrency.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -39,19 +39,19 @@
 block discarded – undo
39 39
 // Load original field value
40 40
 if (! empty($id))
41 41
 {
42
-	require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
43
-	$account=new Account($db);
44
-	$result = $account->fetch($id);
45
-	if ($result<0) {
46
-		$return['value']	= '';
47
-		$return['num']		= $result;
48
-		$return['error']	= $account->errors[0];
49
-	} else {
50
-		$return['value']	= $account->currency_code;
51
-		$return['num']		= $result;
52
-		$return['error']	= '';
53
-	}
54
-
55
-	echo json_encode($return);
42
+    require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
43
+    $account=new Account($db);
44
+    $result = $account->fetch($id);
45
+    if ($result<0) {
46
+        $return['value']	= '';
47
+        $return['num']		= $result;
48
+        $return['error']	= $account->errors[0];
49
+    } else {
50
+        $return['value']	= $account->currency_code;
51
+        $return['num']		= $result;
52
+        $return['error']	= '';
53
+    }
54
+
55
+    echo json_encode($return);
56 56
 }
57 57
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/ajaxdirtree.php 1 patch
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -34,35 +34,35 @@  discard block
 block discarded – undo
34 34
 
35 35
 if (! isset($mode) || $mode != 'noajax')    // For ajax call
36 36
 {
37
-	$res=@include '../../main.inc.php';
38
-	include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39
-	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40
-	include_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
41
-	include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
42
-	include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
37
+    $res=@include '../../main.inc.php';
38
+    include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39
+    include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40
+    include_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
41
+    include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
42
+    include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
43 43
 
44
-	//if (GETPOST('preopened')) { $_GET['dir'] = $_POST['dir'] = '/bbb/'; }
44
+    //if (GETPOST('preopened')) { $_GET['dir'] = $_POST['dir'] = '/bbb/'; }
45 45
 
46
-	$openeddir = GETPOST('openeddir');
47
-	$modulepart= GETPOST('modulepart');
48
-	$selecteddir = jsUnEscape(GETPOST('dir'));        // relative path. We must decode using same encoding function used by javascript: escape()
46
+    $openeddir = GETPOST('openeddir');
47
+    $modulepart= GETPOST('modulepart');
48
+    $selecteddir = jsUnEscape(GETPOST('dir'));        // relative path. We must decode using same encoding function used by javascript: escape()
49 49
 
50
-	$preopened = GETPOST('preopened');
50
+    $preopened = GETPOST('preopened');
51 51
 
52
-	if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir);    // We removed last '/' except if it is '/'
52
+    if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir);    // We removed last '/' except if it is '/'
53 53
 }
54 54
 else    // For no ajax call
55 55
 {
56
-	//if (GETPOST('preopened')) { $_GET['dir'] = $_POST['dir'] = GETPOST('preopened'); }
56
+    //if (GETPOST('preopened')) { $_GET['dir'] = $_POST['dir'] = GETPOST('preopened'); }
57 57
 
58
-	$openeddir = GETPOST('openeddir');
59
-	$modulepart= GETPOST('modulepart');
60
-	$selecteddir = GETPOST('dir');
58
+    $openeddir = GETPOST('openeddir');
59
+    $modulepart= GETPOST('modulepart');
60
+    $selecteddir = GETPOST('dir');
61 61
 
62
-	$preopened = GETPOST('preopened');
62
+    $preopened = GETPOST('preopened');
63 63
 
64
-	if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir);    // We removed last '/' except if it is '/'
65
-	if (empty($url)) $url=DOL_URL_ROOT.'/ecm/index.php';
64
+    if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir);    // We removed last '/' except if it is '/'
65
+    if (empty($url)) $url=DOL_URL_ROOT.'/ecm/index.php';
66 66
 }
67 67
 
68 68
 // Load translation files required by the page
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 $fullpathselecteddir='<none>';
73 73
 if ($modulepart == 'ecm')
74 74
 {
75
-	$fullpathselecteddir=$conf->ecm->dir_output.'/'.($selecteddir != '/' ? $selecteddir : '');
76
-	$fullpathpreopened=$conf->ecm->dir_output.'/'.($preopened != '/' ? $preopened : '');
75
+    $fullpathselecteddir=$conf->ecm->dir_output.'/'.($selecteddir != '/' ? $selecteddir : '');
76
+    $fullpathpreopened=$conf->ecm->dir_output.'/'.($preopened != '/' ? $preopened : '');
77 77
 }
78 78
 elseif ($modulepart == 'medias')
79 79
 {
80
-	$fullpathselecteddir=$dolibarr_main_data_root.'/medias/'.($selecteddir != '/' ? $selecteddir : '');
81
-	$fullpathpreopened=$dolibarr_main_data_root.'/medias/'.($preopened != '/' ? $preopened : '');
80
+    $fullpathselecteddir=$dolibarr_main_data_root.'/medias/'.($selecteddir != '/' ? $selecteddir : '');
81
+    $fullpathpreopened=$dolibarr_main_data_root.'/medias/'.($preopened != '/' ? $preopened : '');
82 82
 }
83 83
 
84 84
 
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 // Check permissions
96 96
 if ($modulepart == 'ecm')
97 97
 {
98
-	if (! $user->rights->ecm->read) accessforbidden();
98
+    if (! $user->rights->ecm->read) accessforbidden();
99 99
 }
100 100
 elseif ($modulepart == 'medias')
101 101
 {
102
-	// Always allowed
102
+    // Always allowed
103 103
 }
104 104
 
105 105
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
 if (! isset($mode) || $mode != 'noajax')	// if ajax mode
111 111
 {
112
-	top_httphead();
112
+    top_httphead();
113 113
 }
114 114
 
115 115
 //print '<!-- selecteddir (relative dir we click on) = '.$selecteddir.', openeddir = '.$openeddir.', modulepart='.$modulepart.', preopened='.$preopened.' -->'."\n";
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
 
134 134
 if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
135 135
 {
136
-	treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened);
136
+    treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened);
137 137
 
138
-	// TODO Find a solution to not output this code for each leaf we open
139
-	// Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
140
-	// Because the content is reloaded by ajax call, we must also reenable some jquery hooks
141
-	print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip (reload into ajaxdirtree) -->\n";
142
-	print '<script type="text/javascript">
138
+    // TODO Find a solution to not output this code for each leaf we open
139
+    // Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
140
+    // Because the content is reloaded by ajax call, we must also reenable some jquery hooks
141
+    print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip (reload into ajaxdirtree) -->\n";
142
+    print '<script type="text/javascript">
143 143
 	            	jQuery(document).ready(function () {
144 144
 	            		jQuery(".classfortooltip").tooltip({
145 145
 							show: { collision: "flipfit", effect:\'toggle\', delay:50 },
@@ -152,170 +152,170 @@  discard block
 block discarded – undo
152 152
 	            	});
153 153
 	            	</script>';
154 154
 
155
-	// This ajax service is called only when a directory $selecteddir is opened but not when closed.
156
-	//print '<script language="javascript">';
157
-	//print "loadandshowpreview('".dol_escape_js($selecteddir)."');";
158
-	//print '</script>';
155
+    // This ajax service is called only when a directory $selecteddir is opened but not when closed.
156
+    //print '<script language="javascript">';
157
+    //print "loadandshowpreview('".dol_escape_js($selecteddir)."');";
158
+    //print '</script>';
159 159
 }
160 160
 
161 161
 
162 162
 if (empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_ECM_DISABLE_JS))
163 163
 {
164
-	print '<ul class="ecmjqft">';
165
-
166
-	// Load full tree from database. We will use it to define nbofsubdir and nboffilesinsubdir
167
-	if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);    // Slow
168
-
169
-	// ----- This section will show a tree from a fulltree array -----
170
-	// $section must also be defined
171
-	// ----------------------------------------------------------------
172
-
173
-	// Define fullpathselected ( _x_y_z ) of $section parameter (!! not into ajaxdirtree)
174
-	$fullpathselected='';
175
-	foreach($sqltree as $key => $val)
176
-	{
177
-		//print $val['id']."-".$section."<br>";
178
-		if ($val['id'] == $section)
179
-		{
180
-			$fullpathselected=$val['fullpath'];
181
-			break;
182
-		}
183
-	}
184
-	//print "fullpathselected=".$fullpathselected."<br>";
185
-
186
-	// Update expandedsectionarray in session
187
-	$expandedsectionarray=array();
188
-	if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
189
-
190
-	if ($section && GETPOST('sectionexpand') == 'true')
191
-	{
192
-		// We add all sections that are parent of opened section
193
-		$pathtosection=explode('_',$fullpathselected);
194
-		foreach($pathtosection as $idcursor)
195
-		{
196
-			if ($idcursor && ! in_array($idcursor,$expandedsectionarray))	// Not already in array
197
-			{
198
-				$expandedsectionarray[]=$idcursor;
199
-			}
200
-		}
201
-		$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
202
-	}
203
-	if ($section && GETPOST('sectionexpand') == 'false')
204
-	{
205
-		// We removed all expanded sections that are child of the closed section
206
-		$oldexpandedsectionarray=$expandedsectionarray;
207
-		$expandedsectionarray=array();	// Reset
208
-		foreach($oldexpandedsectionarray as $sectioncursor)
209
-		{
210
-			// TODO is_in_subtree(fulltree,sectionparent,sectionchild) does nox exists. Enable or remove this...
211
-			//if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
212
-		}
213
-		$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
214
-	}
215
-	//print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
216
-
217
-	$nbofentries=0;
218
-	$oldvallevel=0;
219
-	foreach($sqltree as $key => $val)
220
-	{
221
-
222
-		$ecmdirstatic->id=$val['id'];
223
-		$ecmdirstatic->ref=$val['label'];
224
-
225
-		// Refresh cache
226
-		if (preg_match('/refresh/i',$action))
227
-		{
228
-			$result=$ecmdirstatic->fetch($val['id']);
229
-			$ecmdirstatic->ref=$ecmdirstatic->label;
230
-
231
-			$result=$ecmdirstatic->refreshcachenboffile(0);
232
-			$val['cachenbofdoc']=$result;
233
-		}
234
-
235
-		//$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
236
-
237
-		// Define showline
238
-		$showline=0;
239
-
240
-		// If directory is son of expanded directory, we show line
241
-		if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
242
-		// If directory is brother of selected directory, we show line
243
-		elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
244
-		// If directory is parent of selected directory or is selected directory, we show line
245
-		elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
246
-		// If we are level one we show line
247
-		elseif ($val['level'] < 2) $showline=1;
248
-
249
-		if ($showline)
250
-		{
251
-			if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
252
-			else $option='indexnotexpanded';
253
-			//print $option;
254
-
255
-			print '<li class="directory collapsed">';
256
-
257
-			// Show tree graph pictos
258
-			$cpt=1;
259
-			while ($cpt < $sqltree[$key]['level'])
260
-			{
261
-				print ' &nbsp; &nbsp;';
262
-				$cpt++;
263
-			}
264
-			$resarray=tree_showpad($sqltree,$key,1);
265
-			$a=$resarray[0];
266
-			$nbofsubdir=$resarray[1];
267
-			$nboffilesinsubdir=$resarray[2];
268
-
269
-			// Show link
270
-			print $ecmdirstatic->getNomUrl(0,$option,32,'class="fmdirlia jqft ecmjqft"');
271
-
272
-			print '<div class="ecmjqft">';
273
-
274
-			// Nb of docs
275
-			print '<table class="nobordernopadding"><tr><td>';
276
-			print $val['cachenbofdoc'];
277
-			print '</td>';
278
-			print '<td align="left">';
279
-			if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
280
-			print '</td>';
281
-
282
-			// Info
283
-			print '<td align="center">';
284
-			$userstatic->id=$val['fk_user_c'];
285
-			$userstatic->lastname=$val['login_c'];
286
-			$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
287
-			$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
288
-			$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1, '', false, 1).'<br>';
289
-			$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
290
-			$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
291
-			$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
292
-			if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
293
-			else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
294
-			print $form->textwithpicto('', $htmltooltip, 1, 'info');
295
-			print "</td>";
296
-
297
-			print '</tr></table>';
298
-
299
-			print '</div>';
300
-
301
-			print "</li>\n";
302
-		}
303
-
304
-		$oldvallevel=$val['level'];
305
-		$nbofentries++;
306
-	}
307
-
308
-	// If nothing to show
309
-	if ($nbofentries == 0)
310
-	{
311
-		print '<li class="directory collapsed">';
312
-		print '<div class="ecmjqft">';
313
-		print $langs->trans("ECMNoDirectoryYet");
314
-		print '</div>';
315
-		print "</li>\n";
316
-	}
317
-
318
-	print '</ul>';
164
+    print '<ul class="ecmjqft">';
165
+
166
+    // Load full tree from database. We will use it to define nbofsubdir and nboffilesinsubdir
167
+    if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);    // Slow
168
+
169
+    // ----- This section will show a tree from a fulltree array -----
170
+    // $section must also be defined
171
+    // ----------------------------------------------------------------
172
+
173
+    // Define fullpathselected ( _x_y_z ) of $section parameter (!! not into ajaxdirtree)
174
+    $fullpathselected='';
175
+    foreach($sqltree as $key => $val)
176
+    {
177
+        //print $val['id']."-".$section."<br>";
178
+        if ($val['id'] == $section)
179
+        {
180
+            $fullpathselected=$val['fullpath'];
181
+            break;
182
+        }
183
+    }
184
+    //print "fullpathselected=".$fullpathselected."<br>";
185
+
186
+    // Update expandedsectionarray in session
187
+    $expandedsectionarray=array();
188
+    if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
189
+
190
+    if ($section && GETPOST('sectionexpand') == 'true')
191
+    {
192
+        // We add all sections that are parent of opened section
193
+        $pathtosection=explode('_',$fullpathselected);
194
+        foreach($pathtosection as $idcursor)
195
+        {
196
+            if ($idcursor && ! in_array($idcursor,$expandedsectionarray))	// Not already in array
197
+            {
198
+                $expandedsectionarray[]=$idcursor;
199
+            }
200
+        }
201
+        $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
202
+    }
203
+    if ($section && GETPOST('sectionexpand') == 'false')
204
+    {
205
+        // We removed all expanded sections that are child of the closed section
206
+        $oldexpandedsectionarray=$expandedsectionarray;
207
+        $expandedsectionarray=array();	// Reset
208
+        foreach($oldexpandedsectionarray as $sectioncursor)
209
+        {
210
+            // TODO is_in_subtree(fulltree,sectionparent,sectionchild) does nox exists. Enable or remove this...
211
+            //if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
212
+        }
213
+        $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
214
+    }
215
+    //print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
216
+
217
+    $nbofentries=0;
218
+    $oldvallevel=0;
219
+    foreach($sqltree as $key => $val)
220
+    {
221
+
222
+        $ecmdirstatic->id=$val['id'];
223
+        $ecmdirstatic->ref=$val['label'];
224
+
225
+        // Refresh cache
226
+        if (preg_match('/refresh/i',$action))
227
+        {
228
+            $result=$ecmdirstatic->fetch($val['id']);
229
+            $ecmdirstatic->ref=$ecmdirstatic->label;
230
+
231
+            $result=$ecmdirstatic->refreshcachenboffile(0);
232
+            $val['cachenbofdoc']=$result;
233
+        }
234
+
235
+        //$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
236
+
237
+        // Define showline
238
+        $showline=0;
239
+
240
+        // If directory is son of expanded directory, we show line
241
+        if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
242
+        // If directory is brother of selected directory, we show line
243
+        elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
244
+        // If directory is parent of selected directory or is selected directory, we show line
245
+        elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
246
+        // If we are level one we show line
247
+        elseif ($val['level'] < 2) $showline=1;
248
+
249
+        if ($showline)
250
+        {
251
+            if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
252
+            else $option='indexnotexpanded';
253
+            //print $option;
254
+
255
+            print '<li class="directory collapsed">';
256
+
257
+            // Show tree graph pictos
258
+            $cpt=1;
259
+            while ($cpt < $sqltree[$key]['level'])
260
+            {
261
+                print ' &nbsp; &nbsp;';
262
+                $cpt++;
263
+            }
264
+            $resarray=tree_showpad($sqltree,$key,1);
265
+            $a=$resarray[0];
266
+            $nbofsubdir=$resarray[1];
267
+            $nboffilesinsubdir=$resarray[2];
268
+
269
+            // Show link
270
+            print $ecmdirstatic->getNomUrl(0,$option,32,'class="fmdirlia jqft ecmjqft"');
271
+
272
+            print '<div class="ecmjqft">';
273
+
274
+            // Nb of docs
275
+            print '<table class="nobordernopadding"><tr><td>';
276
+            print $val['cachenbofdoc'];
277
+            print '</td>';
278
+            print '<td align="left">';
279
+            if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
280
+            print '</td>';
281
+
282
+            // Info
283
+            print '<td align="center">';
284
+            $userstatic->id=$val['fk_user_c'];
285
+            $userstatic->lastname=$val['login_c'];
286
+            $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
287
+            $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
288
+            $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1, '', false, 1).'<br>';
289
+            $htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
290
+            $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
291
+            $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
292
+            if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
293
+            else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
294
+            print $form->textwithpicto('', $htmltooltip, 1, 'info');
295
+            print "</td>";
296
+
297
+            print '</tr></table>';
298
+
299
+            print '</div>';
300
+
301
+            print "</li>\n";
302
+        }
303
+
304
+        $oldvallevel=$val['level'];
305
+        $nbofentries++;
306
+    }
307
+
308
+    // If nothing to show
309
+    if ($nbofentries == 0)
310
+    {
311
+        print '<li class="directory collapsed">';
312
+        print '<div class="ecmjqft">';
313
+        print $langs->trans("ECMNoDirectoryYet");
314
+        print '</div>';
315
+        print "</li>\n";
316
+    }
317
+
318
+    print '</ul>';
319 319
 }
320 320
 
321 321
 
@@ -340,156 +340,156 @@  discard block
 block discarded – undo
340 340
  */
341 341
 function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened, $depth=0)
342 342
 {
343
-	global $conf, $db, $langs, $form;
344
-	global $dolibarr_main_data_root;
345
-
346
-	$ecmdirstatic = new EcmDirectory($db);
347
-	$userstatic = new User($db);
348
-
349
-	if (file_exists($fullpathselecteddir))
350
-	{
351
-		$files = @scandir($fullpathselecteddir);
352
-
353
-		if (! empty($files))
354
-		{
355
-			natcasesort($files);
356
-			if (count($files) > 2)    /* The 2 accounts for . and .. */
357
-			{
358
-				echo '<ul class="ecmjqft" style="display: none;">'."\n";
359
-
360
-				// All dirs
361
-				foreach ($files as $file)    // $file can be '.', '..', or 'My dir' or 'My file'
362
-				{
363
-					if ($file == 'temp') continue;
364
-
365
-					$nbofsubdir=0;
366
-					$nboffilesinsubdir=0;
367
-
368
-					$val=array();
369
-
370
-					// Loop on all database entries (sqltree) to find the one matching the subdir found into dir to scan
371
-					foreach($sqltree as $key => $tmpval)
372
-					{
373
-						//print "-- key=".$key." - ".$tmpval['fullrelativename']." vs ".(($selecteddir != '/'?$selecteddir.'/':'').$file)."<br>\n";
374
-						if ($tmpval['fullrelativename'] == (($selecteddir != '/'?$selecteddir.'/':'').$file))		// We found equivalent record into database
375
-						{
376
-							$val=$tmpval;
377
-							$resarray=tree_showpad($sqltree,$key,1);
378
-
379
-							// Refresh cache for this subdir
380
-							if (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] < 0)	// Cache is not up to date, so we update it for this directory t
381
-							{
382
-								$result=$ecmdirstatic->fetch($val['id']);
383
-								$ecmdirstatic->ref=$ecmdirstatic->label;
384
-
385
-								$result=$ecmdirstatic->refreshcachenboffile(0);
386
-								$val['cachenbofdoc']=$result;
387
-							}
388
-
389
-							$a=$resarray[0];
390
-							$nbofsubdir=$resarray[1];
391
-							$nboffilesinsubdir=$resarray[2];
392
-							break;
393
-						}
394
-					}
395
-
396
-					//print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
397
-					if ($file != '.' && $file != '..' && ((! empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir . (preg_match('/\/$/',$fullpathselecteddir)?'':'/') . $file)))
398
-					{
399
-						if (empty($val['fullrelativename']))	// If we did not find entry into database, but found a directory (dol_is_dir was ok at previous test)
400
-						{
401
-							$val['fullrelativename']=(($selecteddir && $selecteddir != '/')?$selecteddir.'/':'').$file;
402
-							$val['id']=0;
403
-							$val['label']=$file;
404
-							$val['description']='';
405
-							$nboffilesinsubdir=$langs->trans("Unknown");
406
-						}
407
-
408
-						$collapsedorexpanded='collapsed';
409
-						if (preg_match('/^'.preg_quote($val['fullrelativename'].'/', '/').'/', $preopened)) $collapsedorexpanded='expanded';
410
-						print '<li class="directory '.$collapsedorexpanded.'">';	// collapsed is opposite if expanded
411
-
412
-						print "<a class=\"fmdirlia jqft ecmjqft\" href=\"";
413
-						print "#";
414
-						print "\" rel=\"" . dol_escape_htmltag($val['fullrelativename'].'/') . "\" id=\"fmdirlia_id_".$val['id']."\"";
415
-						print " onClick=\"loadandshowpreview('".dol_escape_js($val['fullrelativename'])."',".$val['id'].")";
416
-						print "\">";
417
-						print dol_escape_htmltag($file);
418
-						print "</a>";
419
-
420
-						print '<div class="ecmjqft">';
421
-
422
-						print '<table class="nobordernopadding"><tr>';
423
-
424
-						/*print '<td align="left">';
343
+    global $conf, $db, $langs, $form;
344
+    global $dolibarr_main_data_root;
345
+
346
+    $ecmdirstatic = new EcmDirectory($db);
347
+    $userstatic = new User($db);
348
+
349
+    if (file_exists($fullpathselecteddir))
350
+    {
351
+        $files = @scandir($fullpathselecteddir);
352
+
353
+        if (! empty($files))
354
+        {
355
+            natcasesort($files);
356
+            if (count($files) > 2)    /* The 2 accounts for . and .. */
357
+            {
358
+                echo '<ul class="ecmjqft" style="display: none;">'."\n";
359
+
360
+                // All dirs
361
+                foreach ($files as $file)    // $file can be '.', '..', or 'My dir' or 'My file'
362
+                {
363
+                    if ($file == 'temp') continue;
364
+
365
+                    $nbofsubdir=0;
366
+                    $nboffilesinsubdir=0;
367
+
368
+                    $val=array();
369
+
370
+                    // Loop on all database entries (sqltree) to find the one matching the subdir found into dir to scan
371
+                    foreach($sqltree as $key => $tmpval)
372
+                    {
373
+                        //print "-- key=".$key." - ".$tmpval['fullrelativename']." vs ".(($selecteddir != '/'?$selecteddir.'/':'').$file)."<br>\n";
374
+                        if ($tmpval['fullrelativename'] == (($selecteddir != '/'?$selecteddir.'/':'').$file))		// We found equivalent record into database
375
+                        {
376
+                            $val=$tmpval;
377
+                            $resarray=tree_showpad($sqltree,$key,1);
378
+
379
+                            // Refresh cache for this subdir
380
+                            if (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] < 0)	// Cache is not up to date, so we update it for this directory t
381
+                            {
382
+                                $result=$ecmdirstatic->fetch($val['id']);
383
+                                $ecmdirstatic->ref=$ecmdirstatic->label;
384
+
385
+                                $result=$ecmdirstatic->refreshcachenboffile(0);
386
+                                $val['cachenbofdoc']=$result;
387
+                            }
388
+
389
+                            $a=$resarray[0];
390
+                            $nbofsubdir=$resarray[1];
391
+                            $nboffilesinsubdir=$resarray[2];
392
+                            break;
393
+                        }
394
+                    }
395
+
396
+                    //print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
397
+                    if ($file != '.' && $file != '..' && ((! empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir . (preg_match('/\/$/',$fullpathselecteddir)?'':'/') . $file)))
398
+                    {
399
+                        if (empty($val['fullrelativename']))	// If we did not find entry into database, but found a directory (dol_is_dir was ok at previous test)
400
+                        {
401
+                            $val['fullrelativename']=(($selecteddir && $selecteddir != '/')?$selecteddir.'/':'').$file;
402
+                            $val['id']=0;
403
+                            $val['label']=$file;
404
+                            $val['description']='';
405
+                            $nboffilesinsubdir=$langs->trans("Unknown");
406
+                        }
407
+
408
+                        $collapsedorexpanded='collapsed';
409
+                        if (preg_match('/^'.preg_quote($val['fullrelativename'].'/', '/').'/', $preopened)) $collapsedorexpanded='expanded';
410
+                        print '<li class="directory '.$collapsedorexpanded.'">';	// collapsed is opposite if expanded
411
+
412
+                        print "<a class=\"fmdirlia jqft ecmjqft\" href=\"";
413
+                        print "#";
414
+                        print "\" rel=\"" . dol_escape_htmltag($val['fullrelativename'].'/') . "\" id=\"fmdirlia_id_".$val['id']."\"";
415
+                        print " onClick=\"loadandshowpreview('".dol_escape_js($val['fullrelativename'])."',".$val['id'].")";
416
+                        print "\">";
417
+                        print dol_escape_htmltag($file);
418
+                        print "</a>";
419
+
420
+                        print '<div class="ecmjqft">';
421
+
422
+                        print '<table class="nobordernopadding"><tr>';
423
+
424
+                        /*print '<td align="left">';
425 425
 						 print dol_escape_htmltag($file);
426 426
 						 print '</td>';*/
427 427
 
428
-						// Nb of docs
429
-						print '<td align="right">';
430
-						print (isset($val['cachenbofdoc']) && $val['cachenbofdoc']  >= 0)?$val['cachenbofdoc']:'&nbsp;';
431
-						print '</td>';
432
-						print '<td align="left">';
433
-						if ($nbofsubdir > 0  && $nboffilesinsubdir > 0) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
434
-						print '</td>';
435
-
436
-						// Edit link
437
-						print '<td align="right" width="18"><a href="';
438
-						print DOL_URL_ROOT.'/ecm/dir_card.php?module='.urlencode($modulepart).'&section='.$val['id'].'&relativedir='.urlencode($val['fullrelativename']);
439
-						print '&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid);
440
-						print '">'.img_edit($langs->trans("Edit").' - '.$langs->trans("View"), 0, 'class="valignmiddle opacitymedium"').'</a></td>';
441
-
442
-						// Add link
443
-						//print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php?action=create&amp;catParent='.$val['id'].'">'.img_edit_add().'</a></td>';
444
-						//print '<td align="right" width="14">&nbsp;</td>';
445
-
446
-						// Info
447
-						if ($modulepart == 'ecm')
448
-						{
449
-							print '<td align="right" width="18">';
450
-							$userstatic->id=isset($val['fk_user_c'])?$val['fk_user_c']:0;
451
-							$userstatic->lastname=isset($val['login_c'])?$val['login_c']:0;
452
-							$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
453
-							$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
454
-							$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1, '', false, 1).'<br>';
455
-							$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.(isset($val['date_c'])?dol_print_date($val['date_c'],"dayhour"):$langs->trans("NeedRefresh")).'<br>';
456
-							$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
457
-							$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.((isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:$langs->trans("NeedRefresh")).'<br>';
458
-							if ($nboffilesinsubdir > 0) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
459
-							else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.($nbofsubdir >= 0 ? $nbofsubdir : $langs->trans("NeedRefresh")).'<br>';
460
-							print $form->textwithpicto('',$htmltooltip,1,"info");
461
-							print "</td>";
462
-						}
463
-
464
-						print "</tr></table>\n";
465
-						print '</div>';
466
-
467
-						//print 'selecteddir='.$selecteddir.' preopened='.$preopened.' $val[\'fullrelativename\']='.$val['fullrelativename']."<br>\n";
468
-						if (preg_match('/^'.preg_quote($val['fullrelativename'].'/', '/').'/', $preopened))
469
-						{
470
-							//print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
471
-							$newselecteddir = $val['fullrelativename'];
472
-							$newfullpathselecteddir='';
473
-							if ($modulepart == 'ecm')
474
-							{
475
-								$newfullpathselecteddir=$conf->ecm->dir_output.'/'.($val['fullrelativename'] != '/' ? $val['fullrelativename'] : '');
476
-							}
477
-							elseif ($modulepart == 'medias')
478
-							{
479
-								$newfullpathselecteddir=$dolibarr_main_data_root.'/medias/'.($val['fullrelativename'] != '/' ? $val['fullrelativename'] : '');
480
-							}
481
-
482
-							if ($newfullpathselecteddir) treeOutputForAbsoluteDir($sqltree, $newselecteddir, $newfullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened, $depth+1);
483
-						}
484
-
485
-						print "</li>\n";
486
-					}
487
-				}
488
-
489
-				echo "</ul>\n";
490
-			}
491
-		}
492
-		else print "PermissionDenied";
493
-	}
428
+                        // Nb of docs
429
+                        print '<td align="right">';
430
+                        print (isset($val['cachenbofdoc']) && $val['cachenbofdoc']  >= 0)?$val['cachenbofdoc']:'&nbsp;';
431
+                        print '</td>';
432
+                        print '<td align="left">';
433
+                        if ($nbofsubdir > 0  && $nboffilesinsubdir > 0) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
434
+                        print '</td>';
435
+
436
+                        // Edit link
437
+                        print '<td align="right" width="18"><a href="';
438
+                        print DOL_URL_ROOT.'/ecm/dir_card.php?module='.urlencode($modulepart).'&section='.$val['id'].'&relativedir='.urlencode($val['fullrelativename']);
439
+                        print '&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid);
440
+                        print '">'.img_edit($langs->trans("Edit").' - '.$langs->trans("View"), 0, 'class="valignmiddle opacitymedium"').'</a></td>';
441
+
442
+                        // Add link
443
+                        //print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/dir_add_card.php?action=create&amp;catParent='.$val['id'].'">'.img_edit_add().'</a></td>';
444
+                        //print '<td align="right" width="14">&nbsp;</td>';
445
+
446
+                        // Info
447
+                        if ($modulepart == 'ecm')
448
+                        {
449
+                            print '<td align="right" width="18">';
450
+                            $userstatic->id=isset($val['fk_user_c'])?$val['fk_user_c']:0;
451
+                            $userstatic->lastname=isset($val['login_c'])?$val['login_c']:0;
452
+                            $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
453
+                            $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
454
+                            $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1, '', false, 1).'<br>';
455
+                            $htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.(isset($val['date_c'])?dol_print_date($val['date_c'],"dayhour"):$langs->trans("NeedRefresh")).'<br>';
456
+                            $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
457
+                            $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.((isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:$langs->trans("NeedRefresh")).'<br>';
458
+                            if ($nboffilesinsubdir > 0) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
459
+                            else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.($nbofsubdir >= 0 ? $nbofsubdir : $langs->trans("NeedRefresh")).'<br>';
460
+                            print $form->textwithpicto('',$htmltooltip,1,"info");
461
+                            print "</td>";
462
+                        }
463
+
464
+                        print "</tr></table>\n";
465
+                        print '</div>';
466
+
467
+                        //print 'selecteddir='.$selecteddir.' preopened='.$preopened.' $val[\'fullrelativename\']='.$val['fullrelativename']."<br>\n";
468
+                        if (preg_match('/^'.preg_quote($val['fullrelativename'].'/', '/').'/', $preopened))
469
+                        {
470
+                            //print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
471
+                            $newselecteddir = $val['fullrelativename'];
472
+                            $newfullpathselecteddir='';
473
+                            if ($modulepart == 'ecm')
474
+                            {
475
+                                $newfullpathselecteddir=$conf->ecm->dir_output.'/'.($val['fullrelativename'] != '/' ? $val['fullrelativename'] : '');
476
+                            }
477
+                            elseif ($modulepart == 'medias')
478
+                            {
479
+                                $newfullpathselecteddir=$dolibarr_main_data_root.'/medias/'.($val['fullrelativename'] != '/' ? $val['fullrelativename'] : '');
480
+                            }
481
+
482
+                            if ($newfullpathselecteddir) treeOutputForAbsoluteDir($sqltree, $newselecteddir, $newfullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened, $depth+1);
483
+                        }
484
+
485
+                        print "</li>\n";
486
+                    }
487
+                }
488
+
489
+                echo "</ul>\n";
490
+            }
491
+        }
492
+        else print "PermissionDenied";
493
+    }
494 494
 }
495 495
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/ajaxdirpreview.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
     if (! $sortorder) $sortorder="ASC";
57 57
     if (! $sortfield) $sortfield="name";
58 58
 
59
-	$rootdirfordoc = $conf->ecm->dir_output;
59
+    $rootdirfordoc = $conf->ecm->dir_output;
60 60
 
61
-	$upload_dir = dirname(str_replace("../", "/", $rootdirfordoc.'/'.$file));
61
+    $upload_dir = dirname(str_replace("../", "/", $rootdirfordoc.'/'.$file));
62 62
 
63 63
     $ecmdir = new EcmDirectory($db);
64 64
     $result=$ecmdir->fetch($section);
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 }
71 71
 else    // For no ajax call
72 72
 {
73
-	$rootdirfordoc = $conf->ecm->dir_output;
73
+    $rootdirfordoc = $conf->ecm->dir_output;
74 74
 
75
-	$ecmdir = new EcmDirectory($db);
75
+    $ecmdir = new EcmDirectory($db);
76 76
     $relativepath='';
77 77
     if ($section > 0)
78 78
     {
@@ -85,19 +85,19 @@  discard block
 block discarded – undo
85 85
 
86 86
         $relativepath=$ecmdir->getRelativePath();	// Example   'mydir/'
87 87
     }
88
-	elseif (GETPOST('section_dir'))
89
-	{
90
-		$relativepath=GETPOST('section_dir');
91
-	}
92
-	//var_dump($section.'-'.GETPOST('section_dir').'-'.$relativepath);
88
+    elseif (GETPOST('section_dir'))
89
+    {
90
+        $relativepath=GETPOST('section_dir');
91
+    }
92
+    //var_dump($section.'-'.GETPOST('section_dir').'-'.$relativepath);
93 93
 
94
-	$upload_dir = $rootdirfordoc.'/'.$relativepath;
94
+    $upload_dir = $rootdirfordoc.'/'.$relativepath;
95 95
 }
96 96
 
97 97
 if (empty($url))
98 98
 {
99
-	if (GETPOSTISSET('website')) $url=DOL_URL_ROOT.'/website/index.php';
100
-	else $url=DOL_URL_ROOT.'/ecm/index.php';
99
+    if (GETPOSTISSET('website')) $url=DOL_URL_ROOT.'/website/index.php';
100
+    else $url=DOL_URL_ROOT.'/ecm/index.php';
101 101
 }
102 102
 
103 103
 // Load translation files required by the page
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 // Check permissions
122 122
 if ($modulepart == 'ecm')
123 123
 {
124
-	if (! $user->rights->ecm->read) accessforbidden();
124
+    if (! $user->rights->ecm->read) accessforbidden();
125 125
 }
126 126
 if ($modulepart == 'medias')
127 127
 {
128
-	// Always allowed
128
+    // Always allowed
129 129
 }
130 130
 
131 131
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
 if (! isset($mode) || $mode != 'noajax')
145 145
 {
146
-	// Ajout directives pour resoudre bug IE
146
+    // Ajout directives pour resoudre bug IE
147 147
     header('Cache-Control: Public, must-revalidate');
148 148
     header('Pragma: public');
149 149
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     else if ($module == 'user') $upload_dir = $conf->user->dir_output;
211 211
     // Auto area for expense report
212 212
     else if ($module == 'expensereport') $upload_dir = $conf->expensereport->dir_output;
213
-	// Auto area for holiday
213
+    // Auto area for holiday
214 214
     else if ($module == 'holiday') $upload_dir = $conf->holiday->dir_output;
215 215
 
216 216
     // Automatic list
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
     // Manual list
234 234
     else
235 235
     {
236
-    	if ($module == 'medias')
237
-    	{
238
-    		/*
236
+        if ($module == 'medias')
237
+        {
238
+            /*
239 239
     		   $_POST is array like
240 240
     		  'token' => string '062380e11b7dcd009d07318b57b71750' (length=32)
241 241
 			  'action' => string 'file_manager' (length=12)
@@ -246,66 +246,66 @@  discard block
 block discarded – undo
246 246
 			  'max_file_size' => string '2097152' (length=7)
247 247
 			  'sendit' => string 'Envoyer fichier' (length=15)
248 248
     		 */
249
-    		$relativepath=GETPOST('file','alpha')?GETPOST('file','alpha'):GETPOST('section_dir','alpha');
250
-    		if ($relativepath && $relativepath!= '/') $relativepath.='/';
251
-    		$upload_dir = $dolibarr_main_data_root.'/'.$module.'/'.$relativepath;
252
-    		if (GETPOSTISSET('website') || GETPOSTISSET('file_manager'))
253
-	    	{
254
-	    		$param.='&file_manager=1';
255
-	    		if (!preg_match('/website=/',$param)) $param.='&website='.urlencode(GETPOST('website','alpha'));
256
-	    		if (!preg_match('/pageid=/',$param)) $param.='&pageid='.urlencode(GETPOST('pageid','int'));
257
-	    		//if (!preg_match('/backtopage=/',$param)) $param.='&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid);
258
-	    	}
259
-    	}
260
-    	else
261
-    	{
262
-        	$relativepath=$ecmdir->getRelativePath();
263
-        	$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
264
-    	}
249
+            $relativepath=GETPOST('file','alpha')?GETPOST('file','alpha'):GETPOST('section_dir','alpha');
250
+            if ($relativepath && $relativepath!= '/') $relativepath.='/';
251
+            $upload_dir = $dolibarr_main_data_root.'/'.$module.'/'.$relativepath;
252
+            if (GETPOSTISSET('website') || GETPOSTISSET('file_manager'))
253
+            {
254
+                $param.='&file_manager=1';
255
+                if (!preg_match('/website=/',$param)) $param.='&website='.urlencode(GETPOST('website','alpha'));
256
+                if (!preg_match('/pageid=/',$param)) $param.='&pageid='.urlencode(GETPOST('pageid','int'));
257
+                //if (!preg_match('/backtopage=/',$param)) $param.='&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid);
258
+            }
259
+        }
260
+        else
261
+        {
262
+            $relativepath=$ecmdir->getRelativePath();
263
+            $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
264
+        }
265 265
 
266 266
         // If $section defined with value 0
267
-		if (($section === '0' || empty($section)) && ($module != 'medias'))
267
+        if (($section === '0' || empty($section)) && ($module != 'medias'))
268 268
         {
269 269
             $filearray=array();
270 270
         }
271 271
         else
272 272
         {
273
-        	$filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','(\.meta|_preview.*\.png)$','^temp$','^CVS$'),$sortfield, $sorting,1);
273
+            $filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','(\.meta|_preview.*\.png)$','^temp$','^CVS$'),$sortfield, $sorting,1);
274 274
         }
275 275
 
276 276
         if ($section)
277 277
         {
278 278
             $param.='&section='.$section;
279
-        	if (isset($search_doc_ref) && $search_doc_ref != '') $param.='&search_doc_ref='.$search_doc_ref;
279
+            if (isset($search_doc_ref) && $search_doc_ref != '') $param.='&search_doc_ref='.$search_doc_ref;
280 280
 
281 281
             $textifempty = $langs->trans('NoFileFound');
282 282
         }
283 283
         else if ($section === '0')
284 284
         {
285
-        	if ($module == 'ecm') $textifempty='<br><div align="center"><font class="warning">'.$langs->trans("DirNotSynchronizedSyncFirst").'</font></div><br>';
286
-        	else $textifempty = $langs->trans('NoFileFound');
285
+            if ($module == 'ecm') $textifempty='<br><div align="center"><font class="warning">'.$langs->trans("DirNotSynchronizedSyncFirst").'</font></div><br>';
286
+            else $textifempty = $langs->trans('NoFileFound');
287 287
         }
288 288
         else $textifempty=($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection"));
289 289
 
290
-    	if ($module == 'medias')
291
-    	{
292
-    		$useinecm = 2;
293
-    		$modulepart='medias';
294
-        	$perm=($user->rights->website->write || $user->rights->emailing->creer);
295
-        	$title='none';
296
-    	}
297
-    	else
298
-    	{
299
-    		$useinecm = 1;
300
-    		$modulepart='ecm';
301
-        	$perm=$user->rights->ecm->upload;
302
-        	$title='';	// Use default
303
-    	}
304
-
305
-    	// When we show list of files for ECM files, $filearray contains file list, and directory is defined with modulepart + section into $param
306
-    	// When we show list of files for a directory, $filearray ciontains file list, and directory is defined with modulepart + $relativepath
307
-    	//var_dump("title=".$title." modulepart=".$modulepart." useinecm=".$useinecm." perm=".$perm." relativepath=".$relativepath." param=".$param." url=".$url);
308
-		$formfile->list_of_documents($filearray, '', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm);
290
+        if ($module == 'medias')
291
+        {
292
+            $useinecm = 2;
293
+            $modulepart='medias';
294
+            $perm=($user->rights->website->write || $user->rights->emailing->creer);
295
+            $title='none';
296
+        }
297
+        else
298
+        {
299
+            $useinecm = 1;
300
+            $modulepart='ecm';
301
+            $perm=$user->rights->ecm->upload;
302
+            $title='';	// Use default
303
+        }
304
+
305
+        // When we show list of files for ECM files, $filearray contains file list, and directory is defined with modulepart + section into $param
306
+        // When we show list of files for a directory, $filearray ciontains file list, and directory is defined with modulepart + $relativepath
307
+        //var_dump("title=".$title." modulepart=".$modulepart." useinecm=".$useinecm." perm=".$perm." relativepath=".$relativepath." param=".$param." url=".$url);
308
+        $formfile->list_of_documents($filearray, '', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm);
309 309
     }
310 310
 }
311 311
 
@@ -321,37 +321,37 @@  discard block
 block discarded – undo
321 321
 
322 322
 if ($useajax || $action == 'delete')
323 323
 {
324
-	$urlfile='';
325
-	if ($action == 'delete') $urlfile=GETPOST('urlfile','alpha');
326
-
327
-	if (empty($section_dir)) $section_dir=GETPOST("file","alpha");
328
-	$section_id=$section;
329
-
330
-	require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
331
-	$useglobalvars=1;
332
-	$form = new Form($db);
333
-	$formquestion['urlfile']=array('type'=>'hidden','value'=>$urlfile,'name'=>'urlfile');				// We must always put field, even if empty because it is fille by javascript later
334
-	$formquestion['section']=array('type'=>'hidden','value'=>$section,'name'=>'section');				// We must always put field, even if empty because it is fille by javascript later
335
-	$formquestion['section_id']=array('type'=>'hidden','value'=>$section_id,'name'=>'section_id');		// We must always put field, even if empty because it is fille by javascript later
336
-	$formquestion['section_dir']=array('type'=>'hidden','value'=>$section_dir,'name'=>'section_dir');	// We must always put field, even if empty because it is fille by javascript later
337
-	if (! empty($action) && $action == 'file_manager')	$formquestion['file_manager']=array('type'=>'hidden','value'=>1,'name'=>'file_manager');
338
-	if (! empty($websitekey))							$formquestion['website']=array('type'=>'hidden','value'=>$websitekey,'name'=>'website');
339
-	if (! empty($pageid) && $pageid > 0)				$formquestion['pageid']=array('type'=>'hidden','value'=>$pageid,'name'=>'pageid');
340
-
341
-	print $form->formconfirm($url,$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",($useajax?'deletefile':0));
324
+    $urlfile='';
325
+    if ($action == 'delete') $urlfile=GETPOST('urlfile','alpha');
326
+
327
+    if (empty($section_dir)) $section_dir=GETPOST("file","alpha");
328
+    $section_id=$section;
329
+
330
+    require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
331
+    $useglobalvars=1;
332
+    $form = new Form($db);
333
+    $formquestion['urlfile']=array('type'=>'hidden','value'=>$urlfile,'name'=>'urlfile');				// We must always put field, even if empty because it is fille by javascript later
334
+    $formquestion['section']=array('type'=>'hidden','value'=>$section,'name'=>'section');				// We must always put field, even if empty because it is fille by javascript later
335
+    $formquestion['section_id']=array('type'=>'hidden','value'=>$section_id,'name'=>'section_id');		// We must always put field, even if empty because it is fille by javascript later
336
+    $formquestion['section_dir']=array('type'=>'hidden','value'=>$section_dir,'name'=>'section_dir');	// We must always put field, even if empty because it is fille by javascript later
337
+    if (! empty($action) && $action == 'file_manager')	$formquestion['file_manager']=array('type'=>'hidden','value'=>1,'name'=>'file_manager');
338
+    if (! empty($websitekey))							$formquestion['website']=array('type'=>'hidden','value'=>$websitekey,'name'=>'website');
339
+    if (! empty($pageid) && $pageid > 0)				$formquestion['pageid']=array('type'=>'hidden','value'=>$pageid,'name'=>'pageid');
340
+
341
+    print $form->formconfirm($url,$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",($useajax?'deletefile':0));
342 342
 }
343 343
 
344 344
 if ($useajax)
345 345
 {
346
-	print '<script type="text/javascript">';
347
-
348
-	// Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
349
-	// Because the content is reloaded by ajax call, we must also reenable some jquery hooks
350
-	// Wrapper to manage document_preview
351
-	if ($conf->browser->layout != 'phone')
352
-	{
353
-		print "\n/* JS CODE TO ENABLE document_preview */\n";
354
-		print '
346
+    print '<script type="text/javascript">';
347
+
348
+    // Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
349
+    // Because the content is reloaded by ajax call, we must also reenable some jquery hooks
350
+    // Wrapper to manage document_preview
351
+    if ($conf->browser->layout != 'phone')
352
+    {
353
+        print "\n/* JS CODE TO ENABLE document_preview */\n";
354
+        print '
355 355
                 jQuery(document).ready(function () {
356 356
 			        jQuery(".documentpreview").click(function () {
357 357
             		    console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
@@ -360,19 +360,19 @@  discard block
 block discarded – undo
360 360
         			});
361 361
         		});
362 362
            ' . "\n";
363
-	}
364
-
365
-	// Enable jquery handlers button to delete files
366
-	print 'jQuery(document).ready(function() {'."\n";
367
-	print '  jQuery(".deletefilelink").click(function(e) { '."\n";
368
-	print '    console.log("We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(this).attr("rel"));'."\n";
369
-	print '    jQuery("#urlfile").val(jQuery(this).attr("rel"));'."\n";
370
-	//print '    jQuery("#section_dir").val(\'aaa\');'."\n";
371
-	print '    jQuery("#dialog-confirm-deletefile").dialog("open");'."\n";
372
-	print '    return false;'."\n";
373
-	print '  });'."\n";
374
-	print '});'."\n";
375
-	print '</script>'."\n";
363
+    }
364
+
365
+    // Enable jquery handlers button to delete files
366
+    print 'jQuery(document).ready(function() {'."\n";
367
+    print '  jQuery(".deletefilelink").click(function(e) { '."\n";
368
+    print '    console.log("We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(this).attr("rel"));'."\n";
369
+    print '    jQuery("#urlfile").val(jQuery(this).attr("rel"));'."\n";
370
+    //print '    jQuery("#section_dir").val(\'aaa\');'."\n";
371
+    print '    jQuery("#dialog-confirm-deletefile").dialog("open");'."\n";
372
+    print '    return false;'."\n";
373
+    print '  });'."\n";
374
+    print '});'."\n";
375
+    print '</script>'."\n";
376 376
 }
377 377
 
378 378
 // Close db if mode is not noajax
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/constantonoff.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,19 +49,19 @@
 block discarded – undo
49 49
 // Registering the location of boxes
50 50
 if (! empty($action) && ! empty($name))
51 51
 {
52
-	$entity = GETPOST('entity','int');
53
-	$value = (GETPOST('value')?GETPOST('value'):1);
52
+    $entity = GETPOST('entity','int');
53
+    $value = (GETPOST('value')?GETPOST('value'):1);
54 54
 
55
-	if ($user->admin)
56
-	{
57
-		if ($action == 'set')
58
-		{
59
-			dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
60
-		}
61
-		else if ($action == 'del')
62
-		{
63
-			dolibarr_del_const($db, $name, $entity);
64
-		}
65
-	}
55
+    if ($user->admin)
56
+    {
57
+        if ($action == 'set')
58
+        {
59
+            dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
60
+        }
61
+        else if ($action == 'del')
62
+        {
63
+            dolibarr_del_const($db, $name, $entity);
64
+        }
65
+    }
66 66
 }
67 67
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/ziptown.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
 // Generation of list of zip-town
54 54
 if (! empty($_GET['zipcode']) || ! empty($_GET['town']))
55 55
 {
56
-	$return_arr = array();
57
-	$formcompany = new FormCompany($db);
58
-
59
-	// Define filter on text typed
60
-	$zipcode = $_GET['zipcode']?$_GET['zipcode']:'';
61
-	$town = $_GET['town']?$_GET['town']:'';
62
-
63
-	if (! empty($conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY))   // Use zip-town table
64
-	{
65
-    	$sql = "SELECT z.rowid, z.zip, z.town, z.fk_county, z.fk_pays as fk_country";
66
-    	$sql.= ", c.rowid as fk_country, c.code as country_code, c.label as country";
67
-    	$sql.= ", d.rowid as fk_county, d.code_departement as county_code, d.nom as county";
68
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as z";
69
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."c_departements as d ON z.fk_county = d.rowid";
70
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r ON d.fk_region = r.code_region,";
71
-    	$sql.= " ".MAIN_DB_PREFIX."c_country as c";
72
-    	$sql.= " WHERE z.fk_pays = c.rowid";
73
-    	$sql.= " AND z.active = 1 AND c.active = 1";
74
-    	if ($zipcode) $sql.=" AND z.zip LIKE '" . $db->escape($zipcode) . "%'";
75
-    	if ($town)    $sql.=" AND z.town LIKE '%" . $db->escape($town) . "%'";
76
-    	$sql.= " ORDER BY z.zip, z.town";
56
+    $return_arr = array();
57
+    $formcompany = new FormCompany($db);
58
+
59
+    // Define filter on text typed
60
+    $zipcode = $_GET['zipcode']?$_GET['zipcode']:'';
61
+    $town = $_GET['town']?$_GET['town']:'';
62
+
63
+    if (! empty($conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY))   // Use zip-town table
64
+    {
65
+        $sql = "SELECT z.rowid, z.zip, z.town, z.fk_county, z.fk_pays as fk_country";
66
+        $sql.= ", c.rowid as fk_country, c.code as country_code, c.label as country";
67
+        $sql.= ", d.rowid as fk_county, d.code_departement as county_code, d.nom as county";
68
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as z";
69
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."c_departements as d ON z.fk_county = d.rowid";
70
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r ON d.fk_region = r.code_region,";
71
+        $sql.= " ".MAIN_DB_PREFIX."c_country as c";
72
+        $sql.= " WHERE z.fk_pays = c.rowid";
73
+        $sql.= " AND z.active = 1 AND c.active = 1";
74
+        if ($zipcode) $sql.=" AND z.zip LIKE '" . $db->escape($zipcode) . "%'";
75
+        if ($town)    $sql.=" AND z.town LIKE '%" . $db->escape($town) . "%'";
76
+        $sql.= " ORDER BY z.zip, z.town";
77 77
         $sql.= $db->plimit(100); // Avoid pb with bad criteria
78
-	}
79
-	else                                               // Use table of third parties
80
-	{
78
+    }
79
+    else                                               // Use table of third parties
80
+    {
81 81
         $sql = "SELECT DISTINCT s.zip, s.town, s.fk_departement as fk_county, s.fk_pays as fk_country";
82 82
         $sql.= ", c.code as country_code, c.label as country";
83 83
         $sql.= ", d.code_departement as county_code , d.nom as county";
@@ -89,45 +89,45 @@  discard block
 block discarded – undo
89 89
         if ($town)    $sql.= " s.town LIKE '%" . $db->escape($town) . "%'";
90 90
         $sql.= " ORDER BY s.fk_pays, s.zip, s.town";
91 91
         $sql.= $db->plimit(100); // Avoid pb with bad criteria
92
-	}
92
+    }
93 93
 
94 94
     //print $sql;
95
-	$resql=$db->query($sql);
96
-	//var_dump($db);
97
-	if ($resql)
98
-	{
99
-		while ($row = $db->fetch_array($resql))
100
-		{
101
-			$country = $row['fk_country']?($langs->transnoentitiesnoconv('Country'.$row['country_code'])!='Country'.$row['country_code']?$langs->transnoentitiesnoconv('Country'.$row['country_code']):$row['country']):'';
102
-			$county = $row['fk_county']?($langs->transnoentitiesnoconv($row['county_code'])!=$row['county_code']?$langs->transnoentitiesnoconv($row['county_code']):($row['county']!='-'?$row['county']:'')):'';
103
-
104
-			$row_array['label'] = $row['zip'].' '.$row['town'];
105
-			$row_array['label'] .= ($county || $country)?' (':'';
95
+    $resql=$db->query($sql);
96
+    //var_dump($db);
97
+    if ($resql)
98
+    {
99
+        while ($row = $db->fetch_array($resql))
100
+        {
101
+            $country = $row['fk_country']?($langs->transnoentitiesnoconv('Country'.$row['country_code'])!='Country'.$row['country_code']?$langs->transnoentitiesnoconv('Country'.$row['country_code']):$row['country']):'';
102
+            $county = $row['fk_county']?($langs->transnoentitiesnoconv($row['county_code'])!=$row['county_code']?$langs->transnoentitiesnoconv($row['county_code']):($row['county']!='-'?$row['county']:'')):'';
103
+
104
+            $row_array['label'] = $row['zip'].' '.$row['town'];
105
+            $row_array['label'] .= ($county || $country)?' (':'';
106 106
             $row_array['label'] .= $county;
107
-			$row_array['label'] .= ($county && $country?' - ':'');
107
+            $row_array['label'] .= ($county && $country?' - ':'');
108 108
             $row_array['label'] .= $country;
109 109
             $row_array['label'] .= ($county || $country)?')':'';
110 110
             if ($zipcode)
111
-			{
112
-				$row_array['value'] = $row['zip'];
113
-				$row_array['town'] = $row['town'];
114
-			}
115
-			if ($town)
116
-			{
117
-				$row_array['value'] = $row['town'];
118
-				$row_array['zipcode'] = $row['zip'];
119
-			}
120
-			$row_array['selectcountry_id'] = $row['fk_country'];
121
-			$row_array['state_id'] = $row['fk_county'];
122
-
123
-			// TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
124
-			$row_array['states'] = $formcompany->select_state('',$row['fk_country'],'');
125
-
126
-			array_push($return_arr,$row_array);
127
-		}
128
-	}
129
-
130
-	echo json_encode($return_arr);
111
+            {
112
+                $row_array['value'] = $row['zip'];
113
+                $row_array['town'] = $row['town'];
114
+            }
115
+            if ($town)
116
+            {
117
+                $row_array['value'] = $row['town'];
118
+                $row_array['zipcode'] = $row['zip'];
119
+            }
120
+            $row_array['selectcountry_id'] = $row['fk_country'];
121
+            $row_array['state_id'] = $row['fk_county'];
122
+
123
+            // TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
124
+            $row_array['states'] = $formcompany->select_state('',$row['fk_country'],'');
125
+
126
+            array_push($return_arr,$row_array);
127
+        }
128
+    }
129
+
130
+    echo json_encode($return_arr);
131 131
 }
132 132
 else
133 133
 {
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/row.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -43,34 +43,34 @@
 block discarded – undo
43 43
 
44 44
 // Registering the location of boxes
45 45
 if ((! empty($_POST['roworder'])) && (! empty($_POST['table_element_line']))
46
-	&& (! empty($_POST['fk_element'])) && (! empty($_POST['element_id'])))
46
+    && (! empty($_POST['fk_element'])) && (! empty($_POST['element_id'])))
47 47
 {
48
-	$roworder=GETPOST('roworder','alpha',2);
49
-	$table_element_line=GETPOST('table_element_line','alpha',2);
50
-	$fk_element=GETPOST('fk_element','alpha',2);
51
-	$element_id=GETPOST('element_id','int',2);
48
+    $roworder=GETPOST('roworder','alpha',2);
49
+    $table_element_line=GETPOST('table_element_line','alpha',2);
50
+    $fk_element=GETPOST('fk_element','alpha',2);
51
+    $element_id=GETPOST('element_id','int',2);
52 52
 
53
-	dol_syslog("AjaxRow roworder=".$roworder." table_element_line=".$table_element_line." fk_element=".$fk_element." element_id=".$element_id, LOG_DEBUG);
53
+    dol_syslog("AjaxRow roworder=".$roworder." table_element_line=".$table_element_line." fk_element=".$fk_element." element_id=".$element_id, LOG_DEBUG);
54 54
 
55
-	$rowordertab = explode(',',$roworder);
56
-	$newrowordertab = array();
57
-	foreach($rowordertab as $value)
58
-	{
59
-		if (! empty($value)) $newrowordertab[] = $value;
60
-	}
55
+    $rowordertab = explode(',',$roworder);
56
+    $newrowordertab = array();
57
+    foreach($rowordertab as $value)
58
+    {
59
+        if (! empty($value)) $newrowordertab[] = $value;
60
+    }
61 61
 
62
-	$row=new GenericObject($db);
63
-	$row->table_element_line = $table_element_line;
64
-	$row->fk_element = $fk_element;
65
-	$row->id = $element_id;
62
+    $row=new GenericObject($db);
63
+    $row->table_element_line = $table_element_line;
64
+    $row->fk_element = $fk_element;
65
+    $row->id = $element_id;
66 66
 
67
-	$row->line_ajaxorder($newrowordertab);		// This update field rank or position in table row->table_element_line
67
+    $row->line_ajaxorder($newrowordertab);		// This update field rank or position in table row->table_element_line
68 68
 
69
-	// Reorder line to have position of children lines sharing same counter than parent lines
70
-	// This should be useless because there is no need to have children sharing same counter than parent, but well, it's cleaner into database.
71
-	if (in_array($fk_element,array('fk_facture','fk_propal','fk_commande')))
72
-	{
73
-		$result=$row->line_order(true);
74
-	}
69
+    // Reorder line to have position of children lines sharing same counter than parent lines
70
+    // This should be useless because there is no need to have children sharing same counter than parent, but well, it's cleaner into database.
71
+    if (in_array($fk_element,array('fk_facture','fk_propal','fk_commande')))
72
+    {
73
+        $result=$row->line_order(true);
74
+    }
75 75
 }
76 76
 
Please login to merge, or discard this patch.