@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | // Setup the credentials for the requests |
67 | 67 | $credentials = new Credentials( |
68 | 68 | $conf->global->OAUTH_STRIPE_TEST_ID, |
69 | - $conf->global->STRIPE_TEST_SECRET_KEY, |
|
69 | + $conf->global->STRIPE_TEST_SECRET_KEY, |
|
70 | 70 | $currentUri->getAbsoluteUri() |
71 | 71 | ); |
72 | 72 | |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | |
110 | 110 | if (! empty($_GET['code'])) // We are coming from oauth provider page |
111 | 111 | { |
112 | - // We should have |
|
113 | - //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
112 | + // We should have |
|
113 | + //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
114 | 114 | |
115 | - dol_syslog("We are coming from the oauth provider page"); |
|
115 | + dol_syslog("We are coming from the oauth provider page"); |
|
116 | 116 | //llxHeader('',$langs->trans("OAuthSetup")); |
117 | 117 | |
118 | 118 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | else |
161 | 161 | { |
162 | 162 | //$url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
163 | - //https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write |
|
164 | - $url = 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id='.$conf->global->OAUTH_STRIPE_TEST_ID.'&scope=read_write'; |
|
163 | + //https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write |
|
164 | + $url = 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id='.$conf->global->OAUTH_STRIPE_TEST_ID.'&scope=read_write'; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // we go on oauth provider authorization page |
@@ -71,7 +71,10 @@ discard block |
||
71 | 71 | ); |
72 | 72 | |
73 | 73 | $requestedpermissionsarray=array(); |
74 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
74 | +if (GETPOST('state')) { |
|
75 | + $requestedpermissionsarray=explode(',', GETPOST('state')); |
|
76 | +} |
|
77 | +// Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
75 | 78 | /*if ($action != 'delete' && empty($requestedpermissionsarray)) |
76 | 79 | { |
77 | 80 | print 'Error, parameter state is not defined'; |
@@ -107,12 +110,14 @@ discard block |
||
107 | 110 | exit(); |
108 | 111 | } |
109 | 112 | |
110 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (! empty($_GET['code'])) { |
|
114 | + // We are coming from oauth provider page |
|
111 | 115 | { |
112 | 116 | // We should have |
113 | 117 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
114 | 118 | |
115 | 119 | dol_syslog("We are coming from the oauth provider page"); |
120 | +} |
|
116 | 121 | //llxHeader('',$langs->trans("OAuthSetup")); |
117 | 122 | |
118 | 123 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -146,8 +151,7 @@ discard block |
||
146 | 151 | } catch (Exception $e) { |
147 | 152 | print $e->getMessage(); |
148 | 153 | } |
149 | -} |
|
150 | -else // If entry on page with no parameter, we arrive here |
|
154 | +} else // If entry on page with no parameter, we arrive here |
|
151 | 155 | { |
152 | 156 | $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
153 | 157 | |
@@ -156,8 +160,7 @@ discard block |
||
156 | 160 | if (GETPOST('state')) |
157 | 161 | { |
158 | 162 | $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); |
159 | - } |
|
160 | - else |
|
163 | + } else |
|
161 | 164 | { |
162 | 165 | //$url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
163 | 166 | //https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; |
30 | 30 | use OAuth\Common\Storage\DoliStorage; |
31 | 31 | use OAuth\Common\Consumer\Credentials; |
32 | 32 | use OAuth\OAuth2\Service\GitHub; |
33 | 33 | |
34 | 34 | // Define $urlwithroot |
35 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
36 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
35 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
36 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
37 | 37 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
38 | 38 | |
39 | 39 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $currentUri->getAbsoluteUri() |
74 | 74 | ); |
75 | 75 | |
76 | -$requestedpermissionsarray=array(); |
|
77 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
76 | +$requestedpermissionsarray = array(); |
|
77 | +if (GETPOST('state')) $requestedpermissionsarray = explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
78 | 78 | /*if ($action != 'delete' && empty($requestedpermissionsarray)) |
79 | 79 | { |
80 | 80 | print 'Error, parameter state is not defined'; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | /** @var $apiService Service */ |
87 | 87 | //$apiService = $serviceFactory->createService('StripeTest', $credentials, $storage, $requestedpermissionsarray); |
88 | 88 | |
89 | -$sql="INSERT INTO ".MAIN_DB_PREFIX."oauth_token set service='StripeTest', entity=".$conf->entity; |
|
89 | +$sql = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token set service='StripeTest', entity=".$conf->entity; |
|
90 | 90 | $db->query($sql); |
91 | 91 | |
92 | 92 | // access type needed to have oauth provider refreshing token |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | |
107 | 107 | setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); |
108 | 108 | |
109 | - header('Location: ' . $backtourl); |
|
109 | + header('Location: '.$backtourl); |
|
110 | 110 | exit(); |
111 | 111 | } |
112 | 112 | |
113 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (!empty($_GET['code'])) // We are coming from oauth provider page |
|
114 | 114 | { |
115 | 115 | // We should have |
116 | 116 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | // parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri) |
140 | 140 | // has not the ending parameter to true like the Google class constructor. |
141 | 141 | |
142 | - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
142 | + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
143 | 143 | |
144 | 144 | $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; |
145 | 145 | unset($_SESSION["backtourlsavedbeforeoauthjump"]); |
146 | 146 | |
147 | - header('Location: ' . $backtourl); |
|
147 | + header('Location: '.$backtourl); |
|
148 | 148 | exit(); |
149 | 149 | } catch (Exception $e) { |
150 | 150 | print $e->getMessage(); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | else // If entry on page with no parameter, we arrive here |
154 | 154 | { |
155 | - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
|
155 | + $_SESSION["backtourlsavedbeforeoauthjump"] = $backtourl; |
|
156 | 156 | |
157 | 157 | // This may create record into oauth_state before the header redirect. |
158 | 158 | // Creation of record with state in this tables depend on the Provider used (see its constructor). |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // we go on oauth provider authorization page |
171 | - header('Location: ' . $url); |
|
171 | + header('Location: '.$url); |
|
172 | 172 | exit(); |
173 | 173 | } |
174 | 174 |
@@ -109,8 +109,8 @@ |
||
109 | 109 | |
110 | 110 | if (! empty($_GET['code'])) // We are coming from oauth provider page |
111 | 111 | { |
112 | - dol_syslog("We are coming from the oauth provider page"); |
|
113 | - //llxHeader('',$langs->trans("OAuthSetup")); |
|
112 | + dol_syslog("We are coming from the oauth provider page"); |
|
113 | + //llxHeader('',$langs->trans("OAuthSetup")); |
|
114 | 114 | |
115 | 115 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
116 | 116 | //print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup'); |
@@ -71,7 +71,10 @@ discard block |
||
71 | 71 | ); |
72 | 72 | |
73 | 73 | $requestedpermissionsarray=array(); |
74 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
74 | +if (GETPOST('state')) { |
|
75 | + $requestedpermissionsarray=explode(',', GETPOST('state')); |
|
76 | +} |
|
77 | +// Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
75 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
76 | 79 | { |
77 | 80 | print 'Error, parameter state is not defined'; |
@@ -107,9 +110,11 @@ discard block |
||
107 | 110 | exit(); |
108 | 111 | } |
109 | 112 | |
110 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (! empty($_GET['code'])) { |
|
114 | + // We are coming from oauth provider page |
|
111 | 115 | { |
112 | 116 | dol_syslog("We are coming from the oauth provider page"); |
117 | +} |
|
113 | 118 | //llxHeader('',$langs->trans("OAuthSetup")); |
114 | 119 | |
115 | 120 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -138,8 +143,7 @@ discard block |
||
138 | 143 | } catch (Exception $e) { |
139 | 144 | print $e->getMessage(); |
140 | 145 | } |
141 | -} |
|
142 | -else // If entry on page with no parameter, we arrive here |
|
146 | +} else // If entry on page with no parameter, we arrive here |
|
143 | 147 | { |
144 | 148 | $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
145 | 149 | |
@@ -148,8 +152,7 @@ discard block |
||
148 | 152 | if (GETPOST('state')) |
149 | 153 | { |
150 | 154 | $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); |
151 | - } |
|
152 | - else |
|
155 | + } else |
|
153 | 156 | { |
154 | 157 | $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
155 | 158 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; |
30 | 30 | use OAuth\Common\Storage\DoliStorage; |
31 | 31 | use OAuth\Common\Consumer\Credentials; |
32 | 32 | use OAuth\OAuth2\Service\Google; |
33 | 33 | |
34 | 34 | // Define $urlwithroot |
35 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
36 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
35 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
36 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
37 | 37 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
38 | 38 | |
39 | 39 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $currentUri->getAbsoluteUri() |
74 | 74 | ); |
75 | 75 | |
76 | -$requestedpermissionsarray=array(); |
|
77 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
76 | +$requestedpermissionsarray = array(); |
|
77 | +if (GETPOST('state')) $requestedpermissionsarray = explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
78 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
79 | 79 | { |
80 | 80 | print 'Error, parameter state is not defined'; |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | |
107 | 107 | setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); |
108 | 108 | |
109 | - header('Location: ' . $backtourl); |
|
109 | + header('Location: '.$backtourl); |
|
110 | 110 | exit(); |
111 | 111 | } |
112 | 112 | |
113 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (!empty($_GET['code'])) // We are coming from oauth provider page |
|
114 | 114 | { |
115 | 115 | dol_syslog("We are coming from the oauth provider page"); |
116 | 116 | //llxHeader('',$langs->trans("OAuthSetup")); |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | |
132 | 132 | $token = $apiService->requestAccessToken($_GET['code'], $state); |
133 | 133 | |
134 | - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
134 | + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
135 | 135 | |
136 | 136 | $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; |
137 | 137 | unset($_SESSION["backtourlsavedbeforeoauthjump"]); |
138 | 138 | |
139 | - header('Location: ' . $backtourl); |
|
139 | + header('Location: '.$backtourl); |
|
140 | 140 | exit(); |
141 | 141 | } catch (Exception $e) { |
142 | 142 | print $e->getMessage(); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | } |
145 | 145 | else // If entry on page with no parameter, we arrive here |
146 | 146 | { |
147 | - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
|
147 | + $_SESSION["backtourlsavedbeforeoauthjump"] = $backtourl; |
|
148 | 148 | |
149 | 149 | // This may create record into oauth_state before the header redirect. |
150 | 150 | // Creation of record with state in this tables depend on the Provider used (see its constructor). |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | } |
155 | 155 | else |
156 | 156 | { |
157 | - $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
157 | + $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // we go on oauth provider authorization page |
161 | - header('Location: ' . $url); |
|
161 | + header('Location: '.$url); |
|
162 | 162 | exit(); |
163 | 163 | } |
164 | 164 |
@@ -106,10 +106,10 @@ |
||
106 | 106 | |
107 | 107 | if (! empty($_GET['code'])) // We are coming from oauth provider page |
108 | 108 | { |
109 | - // We should have |
|
110 | - //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
109 | + // We should have |
|
110 | + //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
111 | 111 | |
112 | - dol_syslog("We are coming from the oauth provider page"); |
|
112 | + dol_syslog("We are coming from the oauth provider page"); |
|
113 | 113 | //llxHeader('',$langs->trans("OAuthSetup")); |
114 | 114 | |
115 | 115 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -71,7 +71,10 @@ discard block |
||
71 | 71 | ); |
72 | 72 | |
73 | 73 | $requestedpermissionsarray=array(); |
74 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
74 | +if (GETPOST('state')) { |
|
75 | + $requestedpermissionsarray=explode(',', GETPOST('state')); |
|
76 | +} |
|
77 | +// Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
75 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
76 | 79 | { |
77 | 80 | print 'Error, parameter state is not defined'; |
@@ -104,12 +107,14 @@ discard block |
||
104 | 107 | exit(); |
105 | 108 | } |
106 | 109 | |
107 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
110 | +if (! empty($_GET['code'])) { |
|
111 | + // We are coming from oauth provider page |
|
108 | 112 | { |
109 | 113 | // We should have |
110 | 114 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
111 | 115 | |
112 | 116 | dol_syslog("We are coming from the oauth provider page"); |
117 | +} |
|
113 | 118 | //llxHeader('',$langs->trans("OAuthSetup")); |
114 | 119 | |
115 | 120 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -143,8 +148,7 @@ discard block |
||
143 | 148 | } catch (Exception $e) { |
144 | 149 | print $e->getMessage(); |
145 | 150 | } |
146 | -} |
|
147 | -else // If entry on page with no parameter, we arrive here |
|
151 | +} else // If entry on page with no parameter, we arrive here |
|
148 | 152 | { |
149 | 153 | $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
150 | 154 | |
@@ -153,8 +157,7 @@ discard block |
||
153 | 157 | if (GETPOST('state')) |
154 | 158 | { |
155 | 159 | $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); |
156 | - } |
|
157 | - else |
|
160 | + } else |
|
158 | 161 | { |
159 | 162 | $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
160 | 163 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; |
30 | 30 | use OAuth\Common\Storage\DoliStorage; |
31 | 31 | use OAuth\Common\Consumer\Credentials; |
32 | 32 | use OAuth\OAuth2\Service\GitHub; |
33 | 33 | |
34 | 34 | // Define $urlwithroot |
35 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
36 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
35 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
36 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
37 | 37 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
38 | 38 | |
39 | 39 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $currentUri->getAbsoluteUri() |
74 | 74 | ); |
75 | 75 | |
76 | -$requestedpermissionsarray=array(); |
|
77 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
76 | +$requestedpermissionsarray = array(); |
|
77 | +if (GETPOST('state')) $requestedpermissionsarray = explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
78 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
79 | 79 | { |
80 | 80 | print 'Error, parameter state is not defined'; |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | |
104 | 104 | setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); |
105 | 105 | |
106 | - header('Location: ' . $backtourl); |
|
106 | + header('Location: '.$backtourl); |
|
107 | 107 | exit(); |
108 | 108 | } |
109 | 109 | |
110 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
110 | +if (!empty($_GET['code'])) // We are coming from oauth provider page |
|
111 | 111 | { |
112 | 112 | // We should have |
113 | 113 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | // parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri) |
137 | 137 | // has not the ending parameter to true like the Google class constructor. |
138 | 138 | |
139 | - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
139 | + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
140 | 140 | |
141 | 141 | $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; |
142 | 142 | unset($_SESSION["backtourlsavedbeforeoauthjump"]); |
143 | 143 | |
144 | - header('Location: ' . $backtourl); |
|
144 | + header('Location: '.$backtourl); |
|
145 | 145 | exit(); |
146 | 146 | } catch (Exception $e) { |
147 | 147 | print $e->getMessage(); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | else // If entry on page with no parameter, we arrive here |
151 | 151 | { |
152 | - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
|
152 | + $_SESSION["backtourlsavedbeforeoauthjump"] = $backtourl; |
|
153 | 153 | |
154 | 154 | // This may create record into oauth_state before the header redirect. |
155 | 155 | // Creation of record with state in this tables depend on the Provider used (see its constructor). |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | } |
160 | 160 | else |
161 | 161 | { |
162 | - $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
162 | + $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // we go on oauth provider authorization page |
166 | - header('Location: ' . $url); |
|
166 | + header('Location: '.$url); |
|
167 | 167 | exit(); |
168 | 168 | } |
169 | 169 |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | public $db; |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string Error code (or message) |
|
41 | - */ |
|
42 | - public $error=''; |
|
40 | + * @var string Error code (or message) |
|
41 | + */ |
|
42 | + public $error=''; |
|
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param DoliDB $db Database handler |
59 | 59 | * @param integer $maxfilenamelength Max length of value to show |
60 | 60 | * @return array List of drivers |
61 | - */ |
|
61 | + */ |
|
62 | 62 | static function listDrivers($db,$maxfilenamelength=0) |
63 | 63 | { |
64 | 64 | global $conf; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var string Error code (or message) |
41 | 41 | */ |
42 | - public $error=''; |
|
42 | + public $error = ''; |
|
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @param integer $maxfilenamelength Max length of value to show |
60 | 60 | * @return array List of drivers |
61 | 61 | */ |
62 | - static function listDrivers($db,$maxfilenamelength=0) |
|
62 | + static function listDrivers($db, $maxfilenamelength = 0) |
|
63 | 63 | { |
64 | 64 | global $conf; |
65 | 65 | |
66 | 66 | $type = 'printing'; |
67 | 67 | $list = array(); |
68 | 68 | |
69 | - $moduledir=DOL_DOCUMENT_ROOT."/core/modules/printing/"; |
|
70 | - $tmpfiles=dol_dir_list($moduledir,'all',0,'\modules.php','','name',SORT_ASC,0); |
|
71 | - foreach($tmpfiles as $record) { |
|
72 | - $list[$record['fullname']]=str_replace('.modules.php', '',$record['name']); |
|
69 | + $moduledir = DOL_DOCUMENT_ROOT."/core/modules/printing/"; |
|
70 | + $tmpfiles = dol_dir_list($moduledir, 'all', 0, '\modules.php', '', 'name', SORT_ASC, 0); |
|
71 | + foreach ($tmpfiles as $record) { |
|
72 | + $list[$record['fullname']] = str_replace('.modules.php', '', $record['name']); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return $list; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | { |
85 | 85 | global $langs; |
86 | 86 | $langs->load("printing"); |
87 | - $transstring="PrintingModuleDesc".$this->name; |
|
87 | + $transstring = "PrintingModuleDesc".$this->name; |
|
88 | 88 | if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring); |
89 | 89 | else return $this->desc; |
90 | 90 | } |
@@ -85,7 +85,10 @@ |
||
85 | 85 | global $langs; |
86 | 86 | $langs->load("printing"); |
87 | 87 | $transstring="PrintingModuleDesc".$this->name; |
88 | - if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring); |
|
89 | - else return $this->desc; |
|
88 | + if ($langs->trans($transstring) != $transstring) { |
|
89 | + return $langs->trans($transstring); |
|
90 | + } else { |
|
91 | + return $this->desc; |
|
92 | + } |
|
90 | 93 | } |
91 | 94 | } |
@@ -89,47 +89,47 @@ |
||
89 | 89 | ); |
90 | 90 | } else { |
91 | 91 | |
92 | - $this->google_id = $conf->global->OAUTH_GOOGLE_ID; |
|
93 | - $this->google_secret = $conf->global->OAUTH_GOOGLE_SECRET; |
|
94 | - // Token storage |
|
95 | - $storage = new DoliStorage($this->db, $this->conf); |
|
96 | - //$storage->clearToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
97 | - // Setup the credentials for the requests |
|
98 | - $credentials = new Credentials( |
|
99 | - $this->google_id, |
|
100 | - $this->google_secret, |
|
101 | - $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' |
|
102 | - ); |
|
103 | - $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); |
|
104 | - $serviceFactory = new \OAuth\ServiceFactory(); |
|
105 | - $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
|
106 | - $token_ok=true; |
|
107 | - try { |
|
108 | - $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
109 | - } catch (Exception $e) { |
|
110 | - $this->errors[] = $e->getMessage(); |
|
111 | - $token_ok = false; |
|
112 | - } |
|
113 | - //var_dump($this->errors);exit; |
|
114 | - |
|
115 | - $expire = false; |
|
116 | - // Is token expired or will token expire in the next 30 seconds |
|
117 | - if ($token_ok) { |
|
118 | - $expire = ($token->getEndOfLife() !== -9002 && $token->getEndOfLife() !== -9001 && time() > ($token->getEndOfLife() - 30)); |
|
119 | - } |
|
120 | - |
|
121 | - // Token expired so we refresh it |
|
122 | - if ($token_ok && $expire) { |
|
123 | - try { |
|
124 | - // il faut sauvegarder le refresh token car google ne le donne qu'une seule fois |
|
125 | - $refreshtoken = $token->getRefreshToken(); |
|
126 | - $token = $apiService->refreshAccessToken($token); |
|
127 | - $token->setRefreshToken($refreshtoken); |
|
128 | - $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); |
|
129 | - } catch (Exception $e) { |
|
130 | - $this->errors[] = $e->getMessage(); |
|
131 | - } |
|
132 | - } |
|
92 | + $this->google_id = $conf->global->OAUTH_GOOGLE_ID; |
|
93 | + $this->google_secret = $conf->global->OAUTH_GOOGLE_SECRET; |
|
94 | + // Token storage |
|
95 | + $storage = new DoliStorage($this->db, $this->conf); |
|
96 | + //$storage->clearToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
97 | + // Setup the credentials for the requests |
|
98 | + $credentials = new Credentials( |
|
99 | + $this->google_id, |
|
100 | + $this->google_secret, |
|
101 | + $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' |
|
102 | + ); |
|
103 | + $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); |
|
104 | + $serviceFactory = new \OAuth\ServiceFactory(); |
|
105 | + $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
|
106 | + $token_ok=true; |
|
107 | + try { |
|
108 | + $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
109 | + } catch (Exception $e) { |
|
110 | + $this->errors[] = $e->getMessage(); |
|
111 | + $token_ok = false; |
|
112 | + } |
|
113 | + //var_dump($this->errors);exit; |
|
114 | + |
|
115 | + $expire = false; |
|
116 | + // Is token expired or will token expire in the next 30 seconds |
|
117 | + if ($token_ok) { |
|
118 | + $expire = ($token->getEndOfLife() !== -9002 && $token->getEndOfLife() !== -9001 && time() > ($token->getEndOfLife() - 30)); |
|
119 | + } |
|
120 | + |
|
121 | + // Token expired so we refresh it |
|
122 | + if ($token_ok && $expire) { |
|
123 | + try { |
|
124 | + // il faut sauvegarder le refresh token car google ne le donne qu'une seule fois |
|
125 | + $refreshtoken = $token->getRefreshToken(); |
|
126 | + $token = $apiService->refreshAccessToken($token); |
|
127 | + $token->setRefreshToken($refreshtoken); |
|
128 | + $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); |
|
129 | + } catch (Exception $e) { |
|
130 | + $this->errors[] = $e->getMessage(); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | if ($this->google_id != '' && $this->google_secret != '') { |
134 | 134 | $this->conf[] = array('varname'=>'PRINTGCP_INFO', 'info'=>'GoogleAuthConfigured', 'type'=>'info'); |
135 | 135 | $this->conf[] = array( |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | global $conf, $langs, $dolibarr_main_url_root; |
76 | 76 | |
77 | 77 | // Define $urlwithroot |
78 | - $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
79 | - $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
78 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
79 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
80 | 80 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
81 | 81 | |
82 | 82 | $this->db = $db; |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | $this->google_secret, |
101 | 101 | $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' |
102 | 102 | ); |
103 | - $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); |
|
103 | + $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE) ? 'HasAccessToken' : 'NoAccessToken'); |
|
104 | 104 | $serviceFactory = new \OAuth\ServiceFactory(); |
105 | 105 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
106 | - $token_ok=true; |
|
106 | + $token_ok = true; |
|
107 | 107 | try { |
108 | 108 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
109 | 109 | } catch (Exception $e) { |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | 'info'=>$access, |
138 | 138 | 'type'=>'info', |
139 | 139 | 'renew'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), |
140 | - 'delete'=>($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'):'') |
|
140 | + 'delete'=>($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE) ? $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp') : '') |
|
141 | 141 | ); |
142 | 142 | if ($token_ok) { |
143 | - $expiredat=''; |
|
143 | + $expiredat = ''; |
|
144 | 144 | |
145 | 145 | $refreshtoken = $token->getRefreshToken(); |
146 | 146 | |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | } |
157 | 157 | else |
158 | 158 | { |
159 | - $expiredat=dol_print_date($endoflife, "dayhour"); |
|
159 | + $expiredat = dol_print_date($endoflife, "dayhour"); |
|
160 | 160 | } |
161 | 161 | |
162 | - $this->conf[] = array('varname'=>'TOKEN_REFRESH', 'info'=>((! empty($refreshtoken))?'Yes':'No'), 'type'=>'info'); |
|
163 | - $this->conf[] = array('varname'=>'TOKEN_EXPIRED', 'info'=>($expire?'Yes':'No'), 'type'=>'info'); |
|
162 | + $this->conf[] = array('varname'=>'TOKEN_REFRESH', 'info'=>((!empty($refreshtoken)) ? 'Yes' : 'No'), 'type'=>'info'); |
|
163 | + $this->conf[] = array('varname'=>'TOKEN_EXPIRED', 'info'=>($expire ? 'Yes' : 'No'), 'type'=>'info'); |
|
164 | 164 | $this->conf[] = array('varname'=>'TOKEN_EXPIRE_AT', 'info'=>($expiredat), 'type'=>'info'); |
165 | 165 | } |
166 | 166 | /* |
@@ -190,37 +190,37 @@ discard block |
||
190 | 190 | $langs->load('printing'); |
191 | 191 | |
192 | 192 | $html = '<tr class="liste_titre">'; |
193 | - $html.= '<td>'.$langs->trans('GCP_Name').'</td>'; |
|
194 | - $html.= '<td>'.$langs->trans('GCP_displayName').'</td>'; |
|
195 | - $html.= '<td>'.$langs->trans('GCP_Id').'</td>'; |
|
196 | - $html.= '<td>'.$langs->trans('GCP_OwnerName').'</td>'; |
|
197 | - $html.= '<td>'.$langs->trans('GCP_State').'</td>'; |
|
198 | - $html.= '<td>'.$langs->trans('GCP_connectionStatus').'</td>'; |
|
199 | - $html.= '<td>'.$langs->trans('GCP_Type').'</td>'; |
|
200 | - $html.= '<td align="center">'.$langs->trans("Select").'</td>'; |
|
201 | - $html.= '</tr>'."\n"; |
|
193 | + $html .= '<td>'.$langs->trans('GCP_Name').'</td>'; |
|
194 | + $html .= '<td>'.$langs->trans('GCP_displayName').'</td>'; |
|
195 | + $html .= '<td>'.$langs->trans('GCP_Id').'</td>'; |
|
196 | + $html .= '<td>'.$langs->trans('GCP_OwnerName').'</td>'; |
|
197 | + $html .= '<td>'.$langs->trans('GCP_State').'</td>'; |
|
198 | + $html .= '<td>'.$langs->trans('GCP_connectionStatus').'</td>'; |
|
199 | + $html .= '<td>'.$langs->trans('GCP_Type').'</td>'; |
|
200 | + $html .= '<td align="center">'.$langs->trans("Select").'</td>'; |
|
201 | + $html .= '</tr>'."\n"; |
|
202 | 202 | $list = $this->getlistAvailablePrinters(); |
203 | 203 | //$html.= '<td><pre>'.print_r($list,true).'</pre></td>'; |
204 | 204 | foreach ($list['available'] as $printer_det) |
205 | 205 | { |
206 | - $html.= '<tr class="oddeven">'; |
|
207 | - $html.= '<td>'.$printer_det['name'].'</td>'; |
|
208 | - $html.= '<td>'.$printer_det['displayName'].'</td>'; |
|
209 | - $html.= '<td>'.$printer_det['id'].'</td>'; // id to identify printer to use |
|
210 | - $html.= '<td>'.$printer_det['ownerName'].'</td>'; |
|
211 | - $html.= '<td>'.$printer_det['status'].'</td>'; |
|
212 | - $html.= '<td>'.$langs->trans('STATE_'.$printer_det['connectionStatus']).'</td>'; |
|
213 | - $html.= '<td>'.$langs->trans('TYPE_'.$printer_det['type']).'</td>'; |
|
206 | + $html .= '<tr class="oddeven">'; |
|
207 | + $html .= '<td>'.$printer_det['name'].'</td>'; |
|
208 | + $html .= '<td>'.$printer_det['displayName'].'</td>'; |
|
209 | + $html .= '<td>'.$printer_det['id'].'</td>'; // id to identify printer to use |
|
210 | + $html .= '<td>'.$printer_det['ownerName'].'</td>'; |
|
211 | + $html .= '<td>'.$printer_det['status'].'</td>'; |
|
212 | + $html .= '<td>'.$langs->trans('STATE_'.$printer_det['connectionStatus']).'</td>'; |
|
213 | + $html .= '<td>'.$langs->trans('TYPE_'.$printer_det['type']).'</td>'; |
|
214 | 214 | // Defaut |
215 | - $html.= '<td align="center">'; |
|
215 | + $html .= '<td align="center">'; |
|
216 | 216 | if ($conf->global->PRINTING_GCP_DEFAULT == $printer_det['id']) |
217 | 217 | { |
218 | - $html.= img_picto($langs->trans("Default"),'on'); |
|
218 | + $html .= img_picto($langs->trans("Default"), 'on'); |
|
219 | 219 | } |
220 | 220 | else |
221 | - $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
222 | - $html.= '</td>'; |
|
223 | - $html.= '</tr>'."\n"; |
|
221 | + $html .= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; |
|
222 | + $html .= '</td>'; |
|
223 | + $html .= '</tr>'."\n"; |
|
224 | 224 | } |
225 | 225 | $this->resprint = $html; |
226 | 226 | return $error; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $serviceFactory = new \OAuth\ServiceFactory(); |
246 | 246 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
247 | 247 | // Check if we have auth token |
248 | - $token_ok=true; |
|
248 | + $token_ok = true; |
|
249 | 249 | try { |
250 | 250 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
251 | 251 | } catch (Exception $e) { |
@@ -275,18 +275,18 @@ discard block |
||
275 | 275 | $response = $apiService->request(self::PRINTERS_SEARCH_URL); |
276 | 276 | } catch (Exception $e) { |
277 | 277 | $this->errors[] = $e->getMessage(); |
278 | - print '<pre>'.print_r($e->getMessage(),true).'</pre>'; |
|
278 | + print '<pre>'.print_r($e->getMessage(), true).'</pre>'; |
|
279 | 279 | } |
280 | 280 | //print '<tr><td><pre>'.print_r($response, true).'</pre></td></tr>'; |
281 | 281 | $responsedata = json_decode($response, true); |
282 | 282 | $printers = $responsedata['printers']; |
283 | 283 | // Check if we have printers? |
284 | - if(count($printers)==0) { |
|
284 | + if (count($printers) == 0) { |
|
285 | 285 | // We dont have printers so return blank array |
286 | - $ret['available'] = array(); |
|
286 | + $ret['available'] = array(); |
|
287 | 287 | } else { |
288 | 288 | // We have printers so returns printers as array |
289 | - $ret['available'] = $printers; |
|
289 | + $ret['available'] = $printers; |
|
290 | 290 | } |
291 | 291 | return $ret; |
292 | 292 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param string $subdir subdir for file |
300 | 300 | * @return int 0 if OK, >0 if KO |
301 | 301 | */ |
302 | - public function printFile($file, $module, $subdir='') |
|
302 | + public function printFile($file, $module, $subdir = '') |
|
303 | 303 | { |
304 | 304 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
305 | 305 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | $error = 0; |
308 | 308 | |
309 | 309 | $fileprint = $conf->{$module}->dir_output; |
310 | - if ($subdir!='') { |
|
311 | - $fileprint.='/'.$subdir; |
|
310 | + if ($subdir != '') { |
|
311 | + $fileprint .= '/'.$subdir; |
|
312 | 312 | } |
313 | - $fileprint.='/'.$file; |
|
313 | + $fileprint .= '/'.$file; |
|
314 | 314 | $mimetype = dol_mimetype($fileprint); |
315 | 315 | // select printer uri for module order, propal,... |
316 | 316 | $sql = "SELECT rowid, printer_id, copy FROM ".MAIN_DB_PREFIX."printing WHERE module='".$module."' AND driver='printgcp' AND userid=".$user->id; |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | } |
325 | 325 | else |
326 | 326 | { |
327 | - if (! empty($conf->global->PRINTING_GCP_DEFAULT)) |
|
327 | + if (!empty($conf->global->PRINTING_GCP_DEFAULT)) |
|
328 | 328 | { |
329 | - $printer_id=$conf->global->PRINTING_GCP_DEFAULT; |
|
329 | + $printer_id = $conf->global->PRINTING_GCP_DEFAULT; |
|
330 | 330 | } |
331 | 331 | else |
332 | 332 | { |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | |
341 | 341 | $ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype); |
342 | 342 | $this->error = 'PRINTGCP: '.$ret['errormessage']; |
343 | - if ($ret['status']!=1) { |
|
343 | + if ($ret['status'] != 1) { |
|
344 | 344 | $error++; |
345 | 345 | } |
346 | 346 | return $error; |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | public function sendPrintToPrinter($printerid, $printjobtitle, $filepath, $contenttype) |
359 | 359 | { |
360 | 360 | // Check if printer id |
361 | - if(empty($printerid)) { |
|
362 | - return array('status' =>0, 'errorcode' =>'','errormessage'=>'No provided printer ID'); |
|
361 | + if (empty($printerid)) { |
|
362 | + return array('status' =>0, 'errorcode' =>'', 'errormessage'=>'No provided printer ID'); |
|
363 | 363 | } |
364 | 364 | // Open the file which needs to be print |
365 | 365 | $handle = fopen($filepath, "rb"); |
366 | - if(!$handle) { |
|
367 | - return array('status' =>0, 'errorcode' =>'','errormessage'=>'Could not read the file.'); |
|
366 | + if (!$handle) { |
|
367 | + return array('status' =>0, 'errorcode' =>'', 'errormessage'=>'Could not read the file.'); |
|
368 | 368 | } |
369 | 369 | // Read file content |
370 | 370 | $contents = fread($handle, filesize($filepath)); |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
390 | 390 | |
391 | 391 | // Check if we have auth token and refresh it |
392 | - $token_ok=true; |
|
392 | + $token_ok = true; |
|
393 | 393 | try { |
394 | 394 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
395 | 395 | } catch (Exception $e) { |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | $serviceFactory = new \OAuth\ServiceFactory(); |
438 | 438 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
439 | 439 | // Check if we have auth token |
440 | - $token_ok=true; |
|
440 | + $token_ok = true; |
|
441 | 441 | try { |
442 | 442 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
443 | 443 | } catch (Exception $e) { |
@@ -149,12 +149,10 @@ discard block |
||
149 | 149 | if ($endoflife == $token::EOL_NEVER_EXPIRES) |
150 | 150 | { |
151 | 151 | $expiredat = $langs->trans("Never"); |
152 | - } |
|
153 | - elseif ($endoflife == $token::EOL_UNKNOWN) |
|
152 | + } elseif ($endoflife == $token::EOL_UNKNOWN) |
|
154 | 153 | { |
155 | 154 | $expiredat = $langs->trans("Unknown"); |
156 | - } |
|
157 | - else |
|
155 | + } else |
|
158 | 156 | { |
159 | 157 | $expiredat=dol_print_date($endoflife, "dayhour"); |
160 | 158 | } |
@@ -216,9 +214,9 @@ discard block |
||
216 | 214 | if ($conf->global->PRINTING_GCP_DEFAULT == $printer_det['id']) |
217 | 215 | { |
218 | 216 | $html.= img_picto($langs->trans("Default"),'on'); |
217 | + } else { |
|
218 | + $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
219 | 219 | } |
220 | - else |
|
221 | - $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
222 | 220 | $html.= '</td>'; |
223 | 221 | $html.= '</tr>'."\n"; |
224 | 222 | } |
@@ -321,22 +319,21 @@ discard block |
||
321 | 319 | if ($obj) |
322 | 320 | { |
323 | 321 | $printer_id = $obj->printer_id; |
324 | - } |
|
325 | - else |
|
322 | + } else |
|
326 | 323 | { |
327 | 324 | if (! empty($conf->global->PRINTING_GCP_DEFAULT)) |
328 | 325 | { |
329 | 326 | $printer_id=$conf->global->PRINTING_GCP_DEFAULT; |
330 | - } |
|
331 | - else |
|
327 | + } else |
|
332 | 328 | { |
333 | 329 | $this->errors[] = 'NoDefaultPrinterDefined'; |
334 | 330 | $error++; |
335 | 331 | return $error; |
336 | 332 | } |
337 | 333 | } |
334 | + } else { |
|
335 | + dol_print_error($this->db); |
|
338 | 336 | } |
339 | - else dol_print_error($this->db); |
|
340 | 337 | |
341 | 338 | $ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype); |
342 | 339 | $this->error = 'PRINTGCP: '.$ret['errormessage']; |
@@ -501,8 +498,7 @@ discard block |
||
501 | 498 | $html .= '<td> </td>'; |
502 | 499 | $html .= '</tr>'; |
503 | 500 | } |
504 | - } |
|
505 | - else |
|
501 | + } else |
|
506 | 502 | { |
507 | 503 | $html .= '<tr class="oddeven">'; |
508 | 504 | $html .= '<td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td>'; |
@@ -109,7 +109,7 @@ |
||
109 | 109 | $obj = $this->db->fetch_object($result); |
110 | 110 | if ($obj) |
111 | 111 | { |
112 | - dol_syslog("Found a default printer for user ".$user->id." = ".$obj->printer_id); |
|
112 | + dol_syslog("Found a default printer for user ".$user->id." = ".$obj->printer_id); |
|
113 | 113 | $ipp->setPrinterURI($obj->printer_id); |
114 | 114 | } |
115 | 115 | else |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | public $conf = array(); |
38 | 38 | public $host; |
39 | 39 | public $port; |
40 | - public $userid; /* user login */ |
|
40 | + public $userid; /* user login */ |
|
41 | 41 | public $user; |
42 | 42 | public $password; |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var string Error code (or message) |
46 | 46 | */ |
47 | - public $error=''; |
|
47 | + public $error = ''; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @var string[] Error codes (or messages) |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | { |
67 | 67 | global $conf; |
68 | 68 | |
69 | - $this->db=$db; |
|
70 | - $this->host=$conf->global->PRINTIPP_HOST; |
|
71 | - $this->port=$conf->global->PRINTIPP_PORT; |
|
72 | - $this->user=$conf->global->PRINTIPP_USER; |
|
73 | - $this->password=$conf->global->PRINTIPP_PASSWORD; |
|
69 | + $this->db = $db; |
|
70 | + $this->host = $conf->global->PRINTIPP_HOST; |
|
71 | + $this->port = $conf->global->PRINTIPP_PORT; |
|
72 | + $this->user = $conf->global->PRINTIPP_USER; |
|
73 | + $this->password = $conf->global->PRINTIPP_PASSWORD; |
|
74 | 74 | $this->conf[] = array('varname'=>'PRINTIPP_HOST', 'required'=>1, 'example'=>'localhost', 'type'=>'text'); |
75 | 75 | $this->conf[] = array('varname'=>'PRINTIPP_PORT', 'required'=>1, 'example'=>'631', 'type'=>'text'); |
76 | 76 | $this->conf[] = array('varname'=>'PRINTIPP_USER', 'required'=>0, 'example'=>'', 'type'=>'text', 'moreattributes'=>'autocomplete="off"'); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return int 0 if OK, >0 if KO |
89 | 89 | */ |
90 | - public function printFile($file, $module, $subdir='') |
|
90 | + public function printFile($file, $module, $subdir = '') |
|
91 | 91 | { |
92 | 92 | global $conf, $user; |
93 | 93 | $error = 0; |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; |
96 | 96 | |
97 | 97 | $ipp = new CupsPrintIPP(); |
98 | - $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose |
|
98 | + $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log', 'file', 3); // logging very verbose |
|
99 | 99 | $ipp->setHost($this->host); |
100 | 100 | $ipp->setPort($this->port); |
101 | - $ipp->setJobName($file,true); |
|
101 | + $ipp->setJobName($file, true); |
|
102 | 102 | $ipp->setUserName($this->userid); |
103 | - if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password); |
|
103 | + if (!empty($this->user)) $ipp->setAuthentication($this->user, $this->password); |
|
104 | 104 | |
105 | 105 | // select printer uri for module order, propal,... |
106 | 106 | $sql = "SELECT rowid,printer_id,copy FROM ".MAIN_DB_PREFIX."printing WHERE module = '".$module."' AND driver = 'printipp' AND userid = ".$user->id; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | } |
115 | 115 | else |
116 | 116 | { |
117 | - if (! empty($conf->global->PRINTIPP_URI_DEFAULT)) |
|
117 | + if (!empty($conf->global->PRINTIPP_URI_DEFAULT)) |
|
118 | 118 | { |
119 | 119 | dol_syslog("Will use default printer conf->global->PRINTIPP_URI_DEFAULT = ".$conf->global->PRINTIPP_URI_DEFAULT); |
120 | 120 | $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT); |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | |
133 | 133 | // Set number of copy |
134 | 134 | $ipp->setCopies($obj->copy); |
135 | - $fileprint=$conf->{$module}->dir_output; |
|
136 | - if ($subdir!='') $fileprint.='/'.$subdir; |
|
137 | - $fileprint.='/'.$file; |
|
135 | + $fileprint = $conf->{$module}->dir_output; |
|
136 | + if ($subdir != '') $fileprint .= '/'.$subdir; |
|
137 | + $fileprint .= '/'.$file; |
|
138 | 138 | $ipp->setData($fileprint); |
139 | 139 | try { |
140 | 140 | $ipp->printJob(); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $this->errors[] = $e->getMessage(); |
143 | 143 | $error++; |
144 | 144 | } |
145 | - if ($error==0) $this->errors[] = 'PRINTIPP: Job added'; |
|
145 | + if ($error == 0) $this->errors[] = 'PRINTIPP: Job added'; |
|
146 | 146 | |
147 | 147 | return $error; |
148 | 148 | } |
@@ -158,42 +158,42 @@ discard block |
||
158 | 158 | $error = 0; |
159 | 159 | |
160 | 160 | $html = '<tr class="liste_titre">'; |
161 | - $html.= '<td>'.$langs->trans('IPP_Uri').'</td>'; |
|
162 | - $html.= '<td>'.$langs->trans('IPP_Name').'</td>'; |
|
163 | - $html.= '<td>'.$langs->trans('IPP_State').'</td>'; |
|
164 | - $html.= '<td>'.$langs->trans('IPP_State_reason').'</td>'; |
|
165 | - $html.= '<td>'.$langs->trans('IPP_State_reason1').'</td>'; |
|
166 | - $html.= '<td>'.$langs->trans('IPP_BW').'</td>'; |
|
167 | - $html.= '<td>'.$langs->trans('IPP_Color').'</td>'; |
|
161 | + $html .= '<td>'.$langs->trans('IPP_Uri').'</td>'; |
|
162 | + $html .= '<td>'.$langs->trans('IPP_Name').'</td>'; |
|
163 | + $html .= '<td>'.$langs->trans('IPP_State').'</td>'; |
|
164 | + $html .= '<td>'.$langs->trans('IPP_State_reason').'</td>'; |
|
165 | + $html .= '<td>'.$langs->trans('IPP_State_reason1').'</td>'; |
|
166 | + $html .= '<td>'.$langs->trans('IPP_BW').'</td>'; |
|
167 | + $html .= '<td>'.$langs->trans('IPP_Color').'</td>'; |
|
168 | 168 | //$html.= '<td>'.$langs->trans('IPP_Device').'</td>'; |
169 | - $html.= '<td>'.$langs->trans('IPP_Media').'</td>'; |
|
170 | - $html.= '<td>'.$langs->trans('IPP_Supported').'</td>'; |
|
171 | - $html.= '<td align="center">'.$langs->trans("Select").'</td>'; |
|
172 | - $html.= "</tr>\n"; |
|
169 | + $html .= '<td>'.$langs->trans('IPP_Media').'</td>'; |
|
170 | + $html .= '<td>'.$langs->trans('IPP_Supported').'</td>'; |
|
171 | + $html .= '<td align="center">'.$langs->trans("Select").'</td>'; |
|
172 | + $html .= "</tr>\n"; |
|
173 | 173 | $list = $this->getlistAvailablePrinters(); |
174 | 174 | foreach ($list as $value) { |
175 | 175 | $printer_det = $this->getPrinterDetail($value); |
176 | - $html.= '<tr class="oddeven">'; |
|
177 | - $html.= '<td>'.$value.'</td>'; |
|
176 | + $html .= '<tr class="oddeven">'; |
|
177 | + $html .= '<td>'.$value.'</td>'; |
|
178 | 178 | //$html.= '<td><pre>'.print_r($printer_det,true).'</pre></td>'; |
179 | - $html.= '<td>'.$printer_det->printer_name->_value0.'</td>'; |
|
180 | - $html.= '<td>'.$langs->trans('STATE_IPP_'.$printer_det->printer_state->_value0).'</td>'; |
|
181 | - $html.= '<td>'.$langs->trans('STATE_IPP_'.$printer_det->printer_state_reasons->_value0).'</td>'; |
|
182 | - $html.= '<td>'.(! empty($printer_det->printer_state_reasons->_value1)?$langs->trans('STATE_IPP_'.$printer_det->printer_state_reasons->_value1):'').'</td>'; |
|
183 | - $html.= '<td>'.$langs->trans('IPP_COLOR_'.$printer_det->printer_type->_value2).'</td>'; |
|
184 | - $html.= '<td>'.$langs->trans('IPP_COLOR_'.$printer_det->printer_type->_value3).'</td>'; |
|
179 | + $html .= '<td>'.$printer_det->printer_name->_value0.'</td>'; |
|
180 | + $html .= '<td>'.$langs->trans('STATE_IPP_'.$printer_det->printer_state->_value0).'</td>'; |
|
181 | + $html .= '<td>'.$langs->trans('STATE_IPP_'.$printer_det->printer_state_reasons->_value0).'</td>'; |
|
182 | + $html .= '<td>'.(!empty($printer_det->printer_state_reasons->_value1) ? $langs->trans('STATE_IPP_'.$printer_det->printer_state_reasons->_value1) : '').'</td>'; |
|
183 | + $html .= '<td>'.$langs->trans('IPP_COLOR_'.$printer_det->printer_type->_value2).'</td>'; |
|
184 | + $html .= '<td>'.$langs->trans('IPP_COLOR_'.$printer_det->printer_type->_value3).'</td>'; |
|
185 | 185 | //$html.= '<td>'.$printer_det->device_uri->_value0.'</td>'; |
186 | - $html.= '<td>'.$printer_det->media_default->_value0.'</td>'; |
|
187 | - $html.= '<td>'.$langs->trans('MEDIA_IPP_'.$printer_det->media_type_supported->_value1).'</td>'; |
|
186 | + $html .= '<td>'.$printer_det->media_default->_value0.'</td>'; |
|
187 | + $html .= '<td>'.$langs->trans('MEDIA_IPP_'.$printer_det->media_type_supported->_value1).'</td>'; |
|
188 | 188 | // Defaut |
189 | - $html.= '<td align="center">'; |
|
189 | + $html .= '<td align="center">'; |
|
190 | 190 | if ($conf->global->PRINTIPP_URI_DEFAULT == $value) { |
191 | - $html.= img_picto($langs->trans("Default"),'on'); |
|
191 | + $html .= img_picto($langs->trans("Default"), 'on'); |
|
192 | 192 | } else { |
193 | - $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTIPP_URI_DEFAULT&driver=printipp&value='.urlencode($value).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
193 | + $html .= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTIPP_URI_DEFAULT&driver=printipp&value='.urlencode($value).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; |
|
194 | 194 | } |
195 | - $html.= '</td>'; |
|
196 | - $html.= '</tr>'."\n"; |
|
195 | + $html .= '</td>'; |
|
196 | + $html .= '</tr>'."\n"; |
|
197 | 197 | } |
198 | 198 | $this->resprint = $html; |
199 | 199 | return $error; |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | global $conf, $db; |
210 | 210 | include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; |
211 | 211 | $ipp = new CupsPrintIPP(); |
212 | - $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose |
|
212 | + $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log', 'file', 3); // logging very verbose |
|
213 | 213 | $ipp->setHost($this->host); |
214 | 214 | $ipp->setPort($this->port); |
215 | 215 | $ipp->setUserName($this->userid); |
216 | - if (! empty($this->user)) { |
|
216 | + if (!empty($this->user)) { |
|
217 | 217 | $ipp->setAuthentication($this->user, $this->password); |
218 | 218 | } |
219 | 219 | $ipp->getPrinters(); |
@@ -228,15 +228,15 @@ discard block |
||
228 | 228 | */ |
229 | 229 | private function getPrinterDetail($uri) |
230 | 230 | { |
231 | - global $conf,$db; |
|
231 | + global $conf, $db; |
|
232 | 232 | |
233 | 233 | include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; |
234 | 234 | $ipp = new CupsPrintIPP(); |
235 | - $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose |
|
235 | + $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log', 'file', 3); // logging very verbose |
|
236 | 236 | $ipp->setHost($this->host); |
237 | 237 | $ipp->setPort($this->port); |
238 | 238 | $ipp->setUserName($this->userid); |
239 | - if (! empty($this->user)) { |
|
239 | + if (!empty($this->user)) { |
|
240 | 240 | $ipp->setAuthentication($this->user, $this->password); |
241 | 241 | } |
242 | 242 | $ipp->setPrinterURI($uri); |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | $html = ''; |
259 | 259 | include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; |
260 | 260 | $ipp = new CupsPrintIPP(); |
261 | - $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose |
|
261 | + $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log', 'file', 3); // logging very verbose |
|
262 | 262 | $ipp->setHost($this->host); |
263 | 263 | $ipp->setPort($this->port); |
264 | 264 | $ipp->setUserName($this->userid); |
265 | - if (! empty($this->user)) { |
|
266 | - $ipp->setAuthentication($this->user,$this->password); |
|
265 | + if (!empty($this->user)) { |
|
266 | + $ipp->setAuthentication($this->user, $this->password); |
|
267 | 267 | } |
268 | 268 | // select printer uri for module order, propal,... |
269 | 269 | $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"'; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | } |
280 | 280 | // Getting Jobs |
281 | 281 | try { |
282 | - $ipp->getJobs(false,0,'completed',false); |
|
282 | + $ipp->getJobs(false, 0, 'completed', false); |
|
283 | 283 | } catch (Exception $e) { |
284 | 284 | $this->errors[] = $e->getMessage(); |
285 | 285 | $error++; |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $jobs = $ipp->jobs_attributes; |
297 | 297 | |
298 | 298 | //$html .= '<pre>'.print_r($jobs,true).'</pre>'; |
299 | - foreach ($jobs as $value ) { |
|
299 | + foreach ($jobs as $value) { |
|
300 | 300 | $html .= '<tr class="oddeven">'; |
301 | 301 | $html .= '<td>'.$value->job_id->_value0.'</td>'; |
302 | 302 | $html .= '<td>'.$value->job_originating_user_name->_value0.'</td>'; |
@@ -100,7 +100,9 @@ discard block |
||
100 | 100 | $ipp->setPort($this->port); |
101 | 101 | $ipp->setJobName($file,true); |
102 | 102 | $ipp->setUserName($this->userid); |
103 | - if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password); |
|
103 | + if (! empty($this->user)) { |
|
104 | + $ipp->setAuthentication($this->user,$this->password); |
|
105 | + } |
|
104 | 106 | |
105 | 107 | // select printer uri for module order, propal,... |
106 | 108 | $sql = "SELECT rowid,printer_id,copy FROM ".MAIN_DB_PREFIX."printing WHERE module = '".$module."' AND driver = 'printipp' AND userid = ".$user->id; |
@@ -111,15 +113,13 @@ discard block |
||
111 | 113 | { |
112 | 114 | dol_syslog("Found a default printer for user ".$user->id." = ".$obj->printer_id); |
113 | 115 | $ipp->setPrinterURI($obj->printer_id); |
114 | - } |
|
115 | - else |
|
116 | + } else |
|
116 | 117 | { |
117 | 118 | if (! empty($conf->global->PRINTIPP_URI_DEFAULT)) |
118 | 119 | { |
119 | 120 | dol_syslog("Will use default printer conf->global->PRINTIPP_URI_DEFAULT = ".$conf->global->PRINTIPP_URI_DEFAULT); |
120 | 121 | $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT); |
121 | - } |
|
122 | - else |
|
122 | + } else |
|
123 | 123 | { |
124 | 124 | $this->errors[] = 'NoDefaultPrinterDefined'; |
125 | 125 | $error++; |
@@ -133,7 +133,9 @@ discard block |
||
133 | 133 | // Set number of copy |
134 | 134 | $ipp->setCopies($obj->copy); |
135 | 135 | $fileprint=$conf->{$module}->dir_output; |
136 | - if ($subdir!='') $fileprint.='/'.$subdir; |
|
136 | + if ($subdir!='') { |
|
137 | + $fileprint.='/'.$subdir; |
|
138 | + } |
|
137 | 139 | $fileprint.='/'.$file; |
138 | 140 | $ipp->setData($fileprint); |
139 | 141 | try { |
@@ -142,7 +144,9 @@ discard block |
||
142 | 144 | $this->errors[] = $e->getMessage(); |
143 | 145 | $error++; |
144 | 146 | } |
145 | - if ($error==0) $this->errors[] = 'PRINTIPP: Job added'; |
|
147 | + if ($error==0) { |
|
148 | + $this->errors[] = 'PRINTIPP: Job added'; |
|
149 | + } |
|
146 | 150 | |
147 | 151 | return $error; |
148 | 152 | } |
@@ -37,114 +37,114 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class modProduct extends DolibarrModules |
39 | 39 | { |
40 | - /** |
|
41 | - * Constructor. Define names, constants, directories, boxes, permissions |
|
42 | - * |
|
43 | - * @param DoliDB $db Database handler |
|
44 | - */ |
|
45 | - function __construct($db) |
|
46 | - { |
|
47 | - global $conf, $mysoc; |
|
48 | - |
|
49 | - $this->db = $db; |
|
50 | - $this->numero = 50; |
|
51 | - |
|
52 | - $this->family = "products"; |
|
53 | - $this->module_position = '20'; |
|
54 | - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
|
55 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
56 | - $this->description = "Product management"; |
|
57 | - |
|
58 | - // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
|
59 | - $this->version = 'dolibarr'; |
|
60 | - |
|
61 | - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
62 | - $this->picto='product'; |
|
63 | - |
|
64 | - // Data directories to create when module is enabled |
|
65 | - $this->dirs = array("/product/temp"); |
|
66 | - |
|
67 | - // Dependencies |
|
68 | - $this->hidden = false; // A condition to hide module |
|
69 | - $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
70 | - $this->requiredby = array("modStock","modBarcode","modProductBatch"); // List of module ids to disable if this one is disabled |
|
71 | - $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
72 | - $this->phpmin = array(5,4); // Minimum version of PHP required by module |
|
73 | - |
|
74 | - // Config pages |
|
75 | - $this->config_page_url = array("product.php@product"); |
|
76 | - $this->langfiles = array("products","companies","stocks","bills"); |
|
77 | - |
|
78 | - // Constants |
|
79 | - $this->const = array(); |
|
80 | - $r=0; |
|
81 | - |
|
82 | - $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON"; |
|
83 | - $this->const[$r][1] = "chaine"; |
|
84 | - $this->const[$r][2] = "mod_codeproduct_leopard"; |
|
85 | - $this->const[$r][3] = 'Module to control product codes'; |
|
86 | - $this->const[$r][4] = 0; |
|
87 | - $r++; |
|
40 | + /** |
|
41 | + * Constructor. Define names, constants, directories, boxes, permissions |
|
42 | + * |
|
43 | + * @param DoliDB $db Database handler |
|
44 | + */ |
|
45 | + function __construct($db) |
|
46 | + { |
|
47 | + global $conf, $mysoc; |
|
48 | + |
|
49 | + $this->db = $db; |
|
50 | + $this->numero = 50; |
|
51 | + |
|
52 | + $this->family = "products"; |
|
53 | + $this->module_position = '20'; |
|
54 | + // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
|
55 | + $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
56 | + $this->description = "Product management"; |
|
57 | + |
|
58 | + // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
|
59 | + $this->version = 'dolibarr'; |
|
60 | + |
|
61 | + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
62 | + $this->picto='product'; |
|
63 | + |
|
64 | + // Data directories to create when module is enabled |
|
65 | + $this->dirs = array("/product/temp"); |
|
66 | + |
|
67 | + // Dependencies |
|
68 | + $this->hidden = false; // A condition to hide module |
|
69 | + $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
70 | + $this->requiredby = array("modStock","modBarcode","modProductBatch"); // List of module ids to disable if this one is disabled |
|
71 | + $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
72 | + $this->phpmin = array(5,4); // Minimum version of PHP required by module |
|
73 | + |
|
74 | + // Config pages |
|
75 | + $this->config_page_url = array("product.php@product"); |
|
76 | + $this->langfiles = array("products","companies","stocks","bills"); |
|
77 | + |
|
78 | + // Constants |
|
79 | + $this->const = array(); |
|
80 | + $r=0; |
|
81 | + |
|
82 | + $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON"; |
|
83 | + $this->const[$r][1] = "chaine"; |
|
84 | + $this->const[$r][2] = "mod_codeproduct_leopard"; |
|
85 | + $this->const[$r][3] = 'Module to control product codes'; |
|
86 | + $this->const[$r][4] = 0; |
|
87 | + $r++; |
|
88 | 88 | |
89 | - /*$this->const[$r][0] = "PRODUCT_ADDON_PDF"; |
|
89 | + /*$this->const[$r][0] = "PRODUCT_ADDON_PDF"; |
|
90 | 90 | $this->const[$r][1] = "chaine"; |
91 | 91 | $this->const[$r][2] = "standard"; |
92 | 92 | $this->const[$r][3] = 'Default module for document generation'; |
93 | 93 | $this->const[$r][4] = 0; |
94 | 94 | $r++;*/ |
95 | 95 | |
96 | - // Boxes |
|
97 | - $this->boxes = array( |
|
98 | - 0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'), |
|
99 | - 1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''), |
|
100 | - 2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home') |
|
101 | - ); |
|
102 | - |
|
103 | - // Permissions |
|
104 | - $this->rights = array(); |
|
105 | - $this->rights_class = 'produit'; |
|
106 | - $r=0; |
|
107 | - |
|
108 | - $this->rights[$r][0] = 31; // id de la permission |
|
109 | - $this->rights[$r][1] = 'Read products'; // libelle de la permission |
|
110 | - $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour) |
|
111 | - $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut |
|
112 | - $this->rights[$r][4] = 'lire'; |
|
113 | - $r++; |
|
96 | + // Boxes |
|
97 | + $this->boxes = array( |
|
98 | + 0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'), |
|
99 | + 1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''), |
|
100 | + 2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home') |
|
101 | + ); |
|
102 | + |
|
103 | + // Permissions |
|
104 | + $this->rights = array(); |
|
105 | + $this->rights_class = 'produit'; |
|
106 | + $r=0; |
|
107 | + |
|
108 | + $this->rights[$r][0] = 31; // id de la permission |
|
109 | + $this->rights[$r][1] = 'Read products'; // libelle de la permission |
|
110 | + $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour) |
|
111 | + $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut |
|
112 | + $this->rights[$r][4] = 'lire'; |
|
113 | + $r++; |
|
114 | 114 | |
115 | - $this->rights[$r][0] = 32; // id de la permission |
|
116 | - $this->rights[$r][1] = 'Create/modify products'; // libelle de la permission |
|
117 | - $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour) |
|
118 | - $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut |
|
119 | - $this->rights[$r][4] = 'creer'; |
|
120 | - $r++; |
|
115 | + $this->rights[$r][0] = 32; // id de la permission |
|
116 | + $this->rights[$r][1] = 'Create/modify products'; // libelle de la permission |
|
117 | + $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour) |
|
118 | + $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut |
|
119 | + $this->rights[$r][4] = 'creer'; |
|
120 | + $r++; |
|
121 | 121 | |
122 | - $this->rights[$r][0] = 34; // id de la permission |
|
123 | - $this->rights[$r][1] = 'Delete products'; // libelle de la permission |
|
124 | - $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) |
|
125 | - $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut |
|
126 | - $this->rights[$r][4] = 'supprimer'; |
|
122 | + $this->rights[$r][0] = 34; // id de la permission |
|
123 | + $this->rights[$r][1] = 'Delete products'; // libelle de la permission |
|
124 | + $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) |
|
125 | + $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut |
|
126 | + $this->rights[$r][4] = 'supprimer'; |
|
127 | 127 | $r++; |
128 | 128 | |
129 | - $this->rights[$r][0] = 38; // Must be same permission than in service module |
|
130 | - $this->rights[$r][1] = 'Export products'; |
|
131 | - $this->rights[$r][2] = 'r'; |
|
132 | - $this->rights[$r][3] = 0; |
|
133 | - $this->rights[$r][4] = 'export'; |
|
129 | + $this->rights[$r][0] = 38; // Must be same permission than in service module |
|
130 | + $this->rights[$r][1] = 'Export products'; |
|
131 | + $this->rights[$r][2] = 'r'; |
|
132 | + $this->rights[$r][3] = 0; |
|
133 | + $this->rights[$r][4] = 'export'; |
|
134 | 134 | $r++; |
135 | 135 | |
136 | - $this->rights[$r][0] = 39; |
|
137 | - $this->rights[$r][1] = 'Ignore minimum price'; |
|
138 | - $this->rights[$r][2] = 'r'; |
|
139 | - $this->rights[$r][3] = 0; |
|
140 | - $this->rights[$r][4] = 'ignore_price_min_advance'; |
|
136 | + $this->rights[$r][0] = 39; |
|
137 | + $this->rights[$r][1] = 'Ignore minimum price'; |
|
138 | + $this->rights[$r][2] = 'r'; |
|
139 | + $this->rights[$r][3] = 0; |
|
140 | + $this->rights[$r][4] = 'ignore_price_min_advance'; |
|
141 | 141 | $r++; |
142 | 142 | |
143 | 143 | // Menus |
144 | 144 | //------- |
145 | 145 | |
146 | 146 | $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
147 | - /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert |
|
147 | + /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert |
|
148 | 148 | $r=0; |
149 | 149 | $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
150 | 150 | 'type'=>'left', // This is a Left menu entry |
@@ -159,279 +159,279 @@ discard block |
||
159 | 159 | $r++; |
160 | 160 | */ |
161 | 161 | |
162 | - // Exports |
|
163 | - //-------- |
|
164 | - $r=0; |
|
162 | + // Exports |
|
163 | + //-------- |
|
164 | + $r=0; |
|
165 | 165 | |
166 | - $r++; |
|
167 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
168 | - $this->export_label[$r]="Products"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
169 | - $this->export_permission[$r]=array(array("produit","export")); |
|
170 | - $this->export_fields_array[$r]=array( |
|
171 | - 'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
172 | - 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface", |
|
173 | - 'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC", |
|
174 | - 'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
|
175 | - ); |
|
176 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR'; |
|
177 | - if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
178 | - if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
179 | - if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
180 | - $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
|
181 | - include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
182 | - if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery')); |
|
183 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories')); |
|
184 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote')); |
|
185 | - if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
186 | - $this->export_TypeFields_array[$r]=array( |
|
187 | - 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
188 | - 'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric", |
|
189 | - 'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean", |
|
190 | - 'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date' |
|
191 | - ); |
|
192 | - if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
193 | - if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
194 | - if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric')); |
|
195 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text')); |
|
196 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text')); |
|
197 | - $this->export_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
198 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category')); |
|
199 | - if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product')); |
|
200 | - if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product')); |
|
201 | - if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref')); |
|
202 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation')); |
|
203 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid'); |
|
204 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
205 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
206 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid'; |
|
207 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid'; |
|
208 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; |
|
209 | - if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc'; |
|
210 | - $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
211 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields" |
|
212 | - |
|
213 | - if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
|
214 | - { |
|
215 | - // Exports product multiprice |
|
216 | - $r++; |
|
217 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
218 | - $this->export_label[$r]="ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
219 | - $this->export_permission[$r]=array(array("produit","export")); |
|
220 | - $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref", |
|
221 | - 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel", |
|
222 | - 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
223 | - 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
224 | - 'pr.tva_tx'=>'PriceLevelVATRate', |
|
225 | - 'pr.date_price'=>'DateCreation'); |
|
226 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR'; |
|
227 | - //$this->export_TypeFields_array[$r]=array( |
|
228 | - // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
229 | - // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
|
230 | - // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
|
231 | - // 'p.datec'=>'Date','p.tms'=>'Date' |
|
232 | - //); |
|
233 | - $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product", |
|
234 | - 'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product", |
|
235 | - 'pr.price_ttc'=>"product", |
|
236 | - 'pr.price_min'=>"product",'pr.price_min_ttc'=>"product", |
|
237 | - 'pr.tva_tx'=>'product', |
|
238 | - 'pr.recuperableonly'=>'product', |
|
239 | - 'pr.date_price'=>"product"); |
|
240 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
241 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
242 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity |
|
243 | - $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
244 | - } |
|
245 | - |
|
246 | - if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) |
|
247 | - { |
|
248 | - // Exports virtual products |
|
249 | - $r++; |
|
250 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
251 | - $this->export_label[$r]="AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
252 | - $this->export_permission[$r]=array(array("produit","export")); |
|
253 | - $this->export_fields_array[$r]=array( |
|
254 | - 'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl", |
|
255 | - 'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note", |
|
256 | - 'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode', |
|
257 | - 'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell", |
|
258 | - 'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
|
259 | - ); |
|
260 | - if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
261 | - if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
262 | - $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock')); |
|
263 | - $this->export_TypeFields_array[$r]=array( |
|
264 | - 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
265 | - 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
|
266 | - 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
|
267 | - 'p.datec'=>'Date','p.tms'=>'Date' |
|
268 | - ); |
|
269 | - if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
270 | - if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
271 | - $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric')); |
|
272 | - $this->export_entities_array[$r]=array( |
|
273 | - 'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct", |
|
274 | - 'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct", |
|
275 | - 'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct', |
|
276 | - 'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct", |
|
277 | - 'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct" |
|
278 | - ); |
|
279 | - if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct')); |
|
280 | - if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct')); |
|
166 | + $r++; |
|
167 | + $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
168 | + $this->export_label[$r]="Products"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
169 | + $this->export_permission[$r]=array(array("produit","export")); |
|
170 | + $this->export_fields_array[$r]=array( |
|
171 | + 'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
172 | + 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface", |
|
173 | + 'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC", |
|
174 | + 'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
|
175 | + ); |
|
176 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR'; |
|
177 | + if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
178 | + if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
179 | + if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
180 | + $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
|
181 | + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
182 | + if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery')); |
|
183 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories')); |
|
184 | + if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote')); |
|
185 | + if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
186 | + $this->export_TypeFields_array[$r]=array( |
|
187 | + 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
188 | + 'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric", |
|
189 | + 'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean", |
|
190 | + 'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date' |
|
191 | + ); |
|
192 | + if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
193 | + if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
194 | + if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric')); |
|
195 | + if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text')); |
|
196 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text')); |
|
197 | + $this->export_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
198 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category')); |
|
199 | + if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product')); |
|
200 | + if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product')); |
|
201 | + if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref')); |
|
202 | + if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation')); |
|
203 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid'); |
|
204 | + $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
205 | + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
206 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid'; |
|
207 | + if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid'; |
|
208 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; |
|
209 | + if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc'; |
|
210 | + $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
211 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields" |
|
212 | + |
|
213 | + if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
|
214 | + { |
|
215 | + // Exports product multiprice |
|
216 | + $r++; |
|
217 | + $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
218 | + $this->export_label[$r]="ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
219 | + $this->export_permission[$r]=array(array("produit","export")); |
|
220 | + $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref", |
|
221 | + 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel", |
|
222 | + 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
223 | + 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
224 | + 'pr.tva_tx'=>'PriceLevelVATRate', |
|
225 | + 'pr.date_price'=>'DateCreation'); |
|
226 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR'; |
|
227 | + //$this->export_TypeFields_array[$r]=array( |
|
228 | + // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
229 | + // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
|
230 | + // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
|
231 | + // 'p.datec'=>'Date','p.tms'=>'Date' |
|
232 | + //); |
|
233 | + $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product", |
|
234 | + 'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product", |
|
235 | + 'pr.price_ttc'=>"product", |
|
236 | + 'pr.price_min'=>"product",'pr.price_min_ttc'=>"product", |
|
237 | + 'pr.tva_tx'=>'product', |
|
238 | + 'pr.recuperableonly'=>'product', |
|
239 | + 'pr.date_price'=>"product"); |
|
240 | + $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
241 | + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
242 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity |
|
243 | + $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
244 | + } |
|
245 | + |
|
246 | + if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) |
|
247 | + { |
|
248 | + // Exports virtual products |
|
249 | + $r++; |
|
250 | + $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
251 | + $this->export_label[$r]="AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
252 | + $this->export_permission[$r]=array(array("produit","export")); |
|
253 | + $this->export_fields_array[$r]=array( |
|
254 | + 'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl", |
|
255 | + 'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note", |
|
256 | + 'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode', |
|
257 | + 'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell", |
|
258 | + 'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
|
259 | + ); |
|
260 | + if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
261 | + if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
262 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock')); |
|
263 | + $this->export_TypeFields_array[$r]=array( |
|
264 | + 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
265 | + 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
|
266 | + 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
|
267 | + 'p.datec'=>'Date','p.tms'=>'Date' |
|
268 | + ); |
|
269 | + if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
270 | + if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
271 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric')); |
|
272 | + $this->export_entities_array[$r]=array( |
|
273 | + 'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct", |
|
274 | + 'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct", |
|
275 | + 'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct', |
|
276 | + 'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct", |
|
277 | + 'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct" |
|
278 | + ); |
|
279 | + if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct')); |
|
280 | + if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct')); |
|
281 | 281 | $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct')); |
282 | - $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
|
283 | - include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
282 | + $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
|
283 | + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
284 | 284 | $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p2.rowid'=>"Id",'p2.ref'=>"Ref",'p2.label'=>"Label",'p2.description'=>"Description")); |
285 | - $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct")); |
|
286 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
287 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
288 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,'; |
|
289 | - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2'; |
|
290 | - $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
291 | - $this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils'; |
|
292 | - } |
|
293 | - |
|
294 | - // Imports |
|
295 | - //-------- |
|
296 | - $r=0; |
|
285 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct")); |
|
286 | + $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
287 | + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
288 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,'; |
|
289 | + $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2'; |
|
290 | + $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
291 | + $this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils'; |
|
292 | + } |
|
293 | + |
|
294 | + // Imports |
|
295 | + //-------- |
|
296 | + $r=0; |
|
297 | 297 | |
298 | - $r++; |
|
299 | - $this->import_code[$r]=$this->rights_class.'_'.$r; |
|
300 | - $this->import_label[$r]="Products"; // Translation key |
|
301 | - $this->import_icon[$r]=$this->picto; |
|
302 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
303 | - $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields'); |
|
304 | - $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id |
|
305 | - $this->import_fields_array[$r]=array( |
|
306 | - 'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
307 | - 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume", |
|
308 | - 'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC", |
|
309 | - 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation' |
|
310 | - ); |
|
311 | - if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
312 | - if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
313 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR')); |
|
314 | - if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type')); |
|
315 | - if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type')); |
|
316 | - if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
317 | - if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
318 | - // Add extra fields |
|
319 | - $import_extrafield_sample=array(); |
|
320 | - $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")"; |
|
321 | - $resql=$this->db->query($sql); |
|
322 | - if ($resql) // This can fail when class is used on old database (during migration for example) |
|
323 | - { |
|
324 | - while ($obj=$this->db->fetch_object($resql)) |
|
325 | - { |
|
326 | - $fieldname='extra.'.$obj->name; |
|
327 | - $fieldlabel=ucfirst($obj->label); |
|
328 | - $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); |
|
329 | - $import_extrafield_sample[$fieldname]=$fieldlabel; |
|
330 | - } |
|
331 | - } |
|
332 | - // End add extra fields |
|
333 | - $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) |
|
334 | - $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','p.recuperableonly'=>'^[0|1]$'); |
|
335 | - $import_sample=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31','p.recuperableonly'=>'0 or 1'); |
|
336 | - $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample); |
|
337 | - $this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode'); |
|
338 | - |
|
339 | - if (! empty($conf->fournisseur->enabled)) |
|
340 | - { |
|
341 | - // Import suppliers prices (note: this code is duplicated into module service) |
|
342 | - $r++; |
|
343 | - $this->import_code[$r]=$this->rights_class.'_supplierprices'; |
|
344 | - $this->import_label[$r]="SuppliersPricesOfProductsOrServices"; // Translation key |
|
345 | - $this->import_icon[$r]=$this->picto; |
|
346 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
347 | - $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price'); |
|
348 | - $this->import_tables_creator_array[$r]=array('sp'=>'fk_user'); |
|
349 | - $this->import_fields_array[$r]=array( |
|
350 | - 'sp.fk_product'=>"ProductOrService*", |
|
351 | - 'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode' |
|
352 | - ); |
|
353 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR')); |
|
354 | - if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); |
|
355 | - if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); |
|
356 | - $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array( |
|
357 | - 'sp.price'=>"PriceQtyMinHT*", |
|
358 | - 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty |
|
359 | - 'sp.remise_percent'=>'DiscountQtyMin' |
|
360 | - )); |
|
361 | - $this->import_convertvalue_array[$r]=array( |
|
362 | - 'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'), |
|
363 | - 'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product') |
|
364 | - ); |
|
365 | - $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456", |
|
366 | - 'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21', |
|
367 | - 'sp.price'=>"50", |
|
368 | - 'sp.unitprice'=>'50', |
|
369 | - 'sp.remise_percent'=>'0' |
|
370 | - ); |
|
371 | - $this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef','sp.fk_soc'=>'Supplier'); |
|
372 | - } |
|
373 | - |
|
374 | - if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
|
375 | - { |
|
376 | - // Import product multiprice |
|
377 | - $r++; |
|
378 | - $this->import_code[$r]=$this->rights_class.'_multiprice'; |
|
379 | - $this->import_label[$r]="ProductsOrServiceMultiPrice"; // Translation key |
|
380 | - $this->import_icon[$r]=$this->picto; |
|
381 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
382 | - $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price'); |
|
383 | - $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author'); // Fields to store import user id |
|
384 | - $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*", |
|
385 | - 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel", |
|
386 | - 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
387 | - 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
388 | - 'pr.tva_tx'=>'PriceLevelVATRate', |
|
389 | - 'pr.date_price'=>'DateCreation*'); |
|
390 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR')); |
|
391 | - $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$'); |
|
392 | - $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1", |
|
393 | - 'pr.price_base_type'=>"HT",'pr.price_level'=>"1", |
|
394 | - 'pr.price'=>"100",'pr.price_ttc'=>"110", |
|
395 | - 'pr.price_min'=>"100",'pr.price_min_ttc'=>"110", |
|
396 | - 'pr.tva_tx'=>'20', |
|
397 | - 'pr.recuperableonly'=>'0', |
|
398 | - 'pr.date_price'=>'2013-04-10'); |
|
399 | - } |
|
400 | - |
|
401 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
402 | - { |
|
403 | - $r++; |
|
404 | - $this->import_code[$r]=$this->rights_class.'_languages'; |
|
405 | - $this->import_label[$r]="ProductsOrServicesTranslations"; |
|
406 | - $this->import_icon[$r]=$this->picto; |
|
407 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
408 | - $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang'); |
|
409 | - // multiline translation, one line per translation |
|
410 | - $this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription'); |
|
411 | - //$this->import_fields_array[$r]['l.note']='TranslatedNote'; |
|
412 | - $this->import_convertvalue_array[$r]=array( |
|
413 | - 'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product') |
|
414 | - ); |
|
415 | - $this->import_examplevalues_array[$r]=array('l.fk_product'=>'MyProductRef','l.lang'=>'en_US','l.label'=>'Label in en_US','l.description'=>'Desc in en_US'); |
|
416 | - $this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language'); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * Function called when module is enabled. |
|
423 | - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
424 | - * It also creates data directories |
|
425 | - * |
|
298 | + $r++; |
|
299 | + $this->import_code[$r]=$this->rights_class.'_'.$r; |
|
300 | + $this->import_label[$r]="Products"; // Translation key |
|
301 | + $this->import_icon[$r]=$this->picto; |
|
302 | + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
303 | + $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields'); |
|
304 | + $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id |
|
305 | + $this->import_fields_array[$r]=array( |
|
306 | + 'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
307 | + 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume", |
|
308 | + 'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC", |
|
309 | + 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation' |
|
310 | + ); |
|
311 | + if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
312 | + if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
313 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR')); |
|
314 | + if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type')); |
|
315 | + if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type')); |
|
316 | + if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
317 | + if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
318 | + // Add extra fields |
|
319 | + $import_extrafield_sample=array(); |
|
320 | + $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")"; |
|
321 | + $resql=$this->db->query($sql); |
|
322 | + if ($resql) // This can fail when class is used on old database (during migration for example) |
|
323 | + { |
|
324 | + while ($obj=$this->db->fetch_object($resql)) |
|
325 | + { |
|
326 | + $fieldname='extra.'.$obj->name; |
|
327 | + $fieldlabel=ucfirst($obj->label); |
|
328 | + $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); |
|
329 | + $import_extrafield_sample[$fieldname]=$fieldlabel; |
|
330 | + } |
|
331 | + } |
|
332 | + // End add extra fields |
|
333 | + $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) |
|
334 | + $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','p.recuperableonly'=>'^[0|1]$'); |
|
335 | + $import_sample=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31','p.recuperableonly'=>'0 or 1'); |
|
336 | + $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample); |
|
337 | + $this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode'); |
|
338 | + |
|
339 | + if (! empty($conf->fournisseur->enabled)) |
|
340 | + { |
|
341 | + // Import suppliers prices (note: this code is duplicated into module service) |
|
342 | + $r++; |
|
343 | + $this->import_code[$r]=$this->rights_class.'_supplierprices'; |
|
344 | + $this->import_label[$r]="SuppliersPricesOfProductsOrServices"; // Translation key |
|
345 | + $this->import_icon[$r]=$this->picto; |
|
346 | + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
347 | + $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price'); |
|
348 | + $this->import_tables_creator_array[$r]=array('sp'=>'fk_user'); |
|
349 | + $this->import_fields_array[$r]=array( |
|
350 | + 'sp.fk_product'=>"ProductOrService*", |
|
351 | + 'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode' |
|
352 | + ); |
|
353 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR')); |
|
354 | + if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); |
|
355 | + if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); |
|
356 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array( |
|
357 | + 'sp.price'=>"PriceQtyMinHT*", |
|
358 | + 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty |
|
359 | + 'sp.remise_percent'=>'DiscountQtyMin' |
|
360 | + )); |
|
361 | + $this->import_convertvalue_array[$r]=array( |
|
362 | + 'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'), |
|
363 | + 'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product') |
|
364 | + ); |
|
365 | + $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456", |
|
366 | + 'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21', |
|
367 | + 'sp.price'=>"50", |
|
368 | + 'sp.unitprice'=>'50', |
|
369 | + 'sp.remise_percent'=>'0' |
|
370 | + ); |
|
371 | + $this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef','sp.fk_soc'=>'Supplier'); |
|
372 | + } |
|
373 | + |
|
374 | + if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
|
375 | + { |
|
376 | + // Import product multiprice |
|
377 | + $r++; |
|
378 | + $this->import_code[$r]=$this->rights_class.'_multiprice'; |
|
379 | + $this->import_label[$r]="ProductsOrServiceMultiPrice"; // Translation key |
|
380 | + $this->import_icon[$r]=$this->picto; |
|
381 | + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
382 | + $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price'); |
|
383 | + $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author'); // Fields to store import user id |
|
384 | + $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*", |
|
385 | + 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel", |
|
386 | + 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
387 | + 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
388 | + 'pr.tva_tx'=>'PriceLevelVATRate', |
|
389 | + 'pr.date_price'=>'DateCreation*'); |
|
390 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR')); |
|
391 | + $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$'); |
|
392 | + $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1", |
|
393 | + 'pr.price_base_type'=>"HT",'pr.price_level'=>"1", |
|
394 | + 'pr.price'=>"100",'pr.price_ttc'=>"110", |
|
395 | + 'pr.price_min'=>"100",'pr.price_min_ttc'=>"110", |
|
396 | + 'pr.tva_tx'=>'20', |
|
397 | + 'pr.recuperableonly'=>'0', |
|
398 | + 'pr.date_price'=>'2013-04-10'); |
|
399 | + } |
|
400 | + |
|
401 | + if (! empty($conf->global->MAIN_MULTILANGS)) |
|
402 | + { |
|
403 | + $r++; |
|
404 | + $this->import_code[$r]=$this->rights_class.'_languages'; |
|
405 | + $this->import_label[$r]="ProductsOrServicesTranslations"; |
|
406 | + $this->import_icon[$r]=$this->picto; |
|
407 | + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
408 | + $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang'); |
|
409 | + // multiline translation, one line per translation |
|
410 | + $this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription'); |
|
411 | + //$this->import_fields_array[$r]['l.note']='TranslatedNote'; |
|
412 | + $this->import_convertvalue_array[$r]=array( |
|
413 | + 'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product') |
|
414 | + ); |
|
415 | + $this->import_examplevalues_array[$r]=array('l.fk_product'=>'MyProductRef','l.lang'=>'en_US','l.label'=>'Label in en_US','l.description'=>'Desc in en_US'); |
|
416 | + $this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language'); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * Function called when module is enabled. |
|
423 | + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
424 | + * It also creates data directories |
|
425 | + * |
|
426 | 426 | * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') |
427 | - * @return int 1 if OK, 0 if KO |
|
428 | - */ |
|
429 | - function init($options='') |
|
430 | - { |
|
431 | - $this->remove($options); |
|
427 | + * @return int 1 if OK, 0 if KO |
|
428 | + */ |
|
429 | + function init($options='') |
|
430 | + { |
|
431 | + $this->remove($options); |
|
432 | 432 | |
433 | - $sql = array(); |
|
433 | + $sql = array(); |
|
434 | 434 | |
435 | - return $this->_init($sql,$options); |
|
436 | - } |
|
435 | + return $this->_init($sql,$options); |
|
436 | + } |
|
437 | 437 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * \ingroup produit |
30 | 30 | * \brief File to describe module to manage catalog of predefined products |
31 | 31 | */ |
32 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
32 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -52,32 +52,32 @@ discard block |
||
52 | 52 | $this->family = "products"; |
53 | 53 | $this->module_position = '20'; |
54 | 54 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
55 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
55 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
56 | 56 | $this->description = "Product management"; |
57 | 57 | |
58 | 58 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
59 | 59 | $this->version = 'dolibarr'; |
60 | 60 | |
61 | 61 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
62 | - $this->picto='product'; |
|
62 | + $this->picto = 'product'; |
|
63 | 63 | |
64 | 64 | // Data directories to create when module is enabled |
65 | 65 | $this->dirs = array("/product/temp"); |
66 | 66 | |
67 | 67 | // Dependencies |
68 | - $this->hidden = false; // A condition to hide module |
|
69 | - $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
70 | - $this->requiredby = array("modStock","modBarcode","modProductBatch"); // List of module ids to disable if this one is disabled |
|
71 | - $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
72 | - $this->phpmin = array(5,4); // Minimum version of PHP required by module |
|
68 | + $this->hidden = false; // A condition to hide module |
|
69 | + $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
70 | + $this->requiredby = array("modStock", "modBarcode", "modProductBatch"); // List of module ids to disable if this one is disabled |
|
71 | + $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
72 | + $this->phpmin = array(5, 4); // Minimum version of PHP required by module |
|
73 | 73 | |
74 | 74 | // Config pages |
75 | 75 | $this->config_page_url = array("product.php@product"); |
76 | - $this->langfiles = array("products","companies","stocks","bills"); |
|
76 | + $this->langfiles = array("products", "companies", "stocks", "bills"); |
|
77 | 77 | |
78 | 78 | // Constants |
79 | 79 | $this->const = array(); |
80 | - $r=0; |
|
80 | + $r = 0; |
|
81 | 81 | |
82 | 82 | $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON"; |
83 | 83 | $this->const[$r][1] = "chaine"; |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | |
96 | 96 | // Boxes |
97 | 97 | $this->boxes = array( |
98 | - 0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'), |
|
99 | - 1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''), |
|
100 | - 2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home') |
|
98 | + 0=>array('file'=>'box_produits.php', 'enabledbydefaulton'=>'Home'), |
|
99 | + 1=>array('file'=>'box_produits_alerte_stock.php', 'enabledbydefaulton'=>''), |
|
100 | + 2=>array('file'=>'box_graph_product_distribution.php', 'enabledbydefaulton'=>'Home') |
|
101 | 101 | ); |
102 | 102 | |
103 | 103 | // Permissions |
104 | 104 | $this->rights = array(); |
105 | 105 | $this->rights_class = 'produit'; |
106 | - $r=0; |
|
106 | + $r = 0; |
|
107 | 107 | |
108 | 108 | $this->rights[$r][0] = 31; // id de la permission |
109 | 109 | $this->rights[$r][1] = 'Read products'; // libelle de la permission |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $this->rights[$r][4] = 'supprimer'; |
127 | 127 | $r++; |
128 | 128 | |
129 | - $this->rights[$r][0] = 38; // Must be same permission than in service module |
|
129 | + $this->rights[$r][0] = 38; // Must be same permission than in service module |
|
130 | 130 | $this->rights[$r][1] = 'Export products'; |
131 | 131 | $this->rights[$r][2] = 'r'; |
132 | 132 | $this->rights[$r][3] = 0; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | // Menus |
144 | 144 | //------- |
145 | 145 | |
146 | - $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
146 | + $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
147 | 147 | /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert |
148 | 148 | $r=0; |
149 | 149 | $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
@@ -161,259 +161,259 @@ discard block |
||
161 | 161 | |
162 | 162 | // Exports |
163 | 163 | //-------- |
164 | - $r=0; |
|
164 | + $r = 0; |
|
165 | 165 | |
166 | 166 | $r++; |
167 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
168 | - $this->export_label[$r]="Products"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
169 | - $this->export_permission[$r]=array(array("produit","export")); |
|
170 | - $this->export_fields_array[$r]=array( |
|
171 | - 'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
172 | - 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.width'=>"Width",'p.height'=>"Height",'p.surface'=>"Surface", |
|
173 | - 'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC", |
|
174 | - 'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
|
167 | + $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
168 | + $this->export_label[$r] = "Products"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
169 | + $this->export_permission[$r] = array(array("produit", "export")); |
|
170 | + $this->export_fields_array[$r] = array( |
|
171 | + 'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl", 'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
172 | + 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode", 'p.note'=>"Note", 'p.length'=>"Length", 'p.width'=>"Width", 'p.height'=>"Height", 'p.surface'=>"Surface", |
|
173 | + 'p.volume'=>"Volume", 'p.weight'=>"Weight", 'p.customcode'=>'CustomCode', 'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC", |
|
174 | + 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell", 'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification' |
|
175 | 175 | ); |
176 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR'; |
|
177 | - if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
178 | - if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
179 | - if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
180 | - $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
|
176 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly'] = 'NPR'; |
|
177 | + if (!empty($conf->stock->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.stock'=>'Stock', 'p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue')); |
|
178 | + if (!empty($conf->barcode->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode')); |
|
179 | + if (!empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.cost_price'=>'CostPrice')); |
|
180 | + $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra'; |
|
181 | 181 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
182 | - if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery')); |
|
183 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories')); |
|
184 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote')); |
|
185 | - if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
186 | - $this->export_TypeFields_array[$r]=array( |
|
187 | - 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
188 | - 'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric", |
|
189 | - 'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean", |
|
190 | - 'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date' |
|
182 | + if (!empty($conf->fournisseur->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('s.nom'=>'Supplier', 'pf.ref_fourn'=>'SupplierRef', 'pf.quantity'=>'QtyMin', 'pf.remise_percent'=>'DiscountQtyMin', 'pf.unitprice'=>'BuyingPrice', 'pf.delivery_time_days'=>'NbDaysToDelivery')); |
|
183 | + if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('group_concat(cat.label)'=>'Categories')); |
|
184 | + if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription', 'l.note'=>'TranslatedNote')); |
|
185 | + if (!empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
186 | + $this->export_TypeFields_array[$r] = array( |
|
187 | + 'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text", 'p.accountancy_code_sell'=>"Text", 'p.accountancy_code_buy'=>"Text", |
|
188 | + 'p.note'=>"Text", 'p.length'=>"Numeric", 'p.width'=>"Numeric", 'p.height'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.weight'=>"Numeric", |
|
189 | + 'p.customcode'=>'Text', 'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", |
|
190 | + 'p.tobuy'=>"Boolean", 'p.datec'=>'Date', 'p.tms'=>'Date' |
|
191 | 191 | ); |
192 | - if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
193 | - if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
194 | - if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric')); |
|
195 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text')); |
|
196 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text')); |
|
197 | - $this->export_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
198 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category')); |
|
199 | - if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product')); |
|
200 | - if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product')); |
|
201 | - if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref')); |
|
202 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation')); |
|
203 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid'); |
|
204 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
205 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
206 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid'; |
|
207 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid'; |
|
208 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; |
|
209 | - if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc'; |
|
210 | - $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
211 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields" |
|
212 | - |
|
213 | - if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
|
192 | + if (!empty($conf->stock->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.stock'=>'Numeric', 'p.seuil_stock_alerte'=>'Numeric', 'p.desiredstock'=>'Numeric', 'p.pmp'=>'Numeric', 'p.cost_price'=>'Numeric')); |
|
193 | + if (!empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text')); |
|
194 | + if (!empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('s.nom'=>'Text', 'pf.ref_fourn'=>'Text', 'pf.unitprice'=>'Numeric', 'pf.quantity'=>'Numeric', 'pf.remise_percent'=>'Numeric', 'pf.delivery_time_days'=>'Numeric')); |
|
195 | + if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('l.lang'=>'Text', 'l.label'=>'Text', 'l.description'=>'Text', 'l.note'=>'Text')); |
|
196 | + if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array("group_concat(cat.label)"=>'Text')); |
|
197 | + $this->export_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
|
198 | + if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array("group_concat(cat.label)"=>'category')); |
|
199 | + if (!empty($conf->stock->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product')); |
|
200 | + if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product')); |
|
201 | + if (!empty($conf->fournisseur->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('s.nom'=>'product_supplier_ref', 'pf.ref_fourn'=>'product_supplier_ref', 'pf.unitprice'=>'product_supplier_ref', 'pf.quantity'=>'product_supplier_ref', 'pf.remise_percent'=>'product_supplier_ref', 'pf.delivery_time_days'=>'product_supplier_ref')); |
|
202 | + if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('l.lang'=>'translation', 'l.label'=>'translation', 'l.description'=>'translation', 'l.note'=>'translation')); |
|
203 | + if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r] = array('category'=>'p.rowid'); |
|
204 | + $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
205 | + $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
206 | + if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid'; |
|
207 | + if (!empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid'; |
|
208 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; |
|
209 | + if (!empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc'; |
|
210 | + $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
211 | + if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] = ' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields" |
|
212 | + |
|
213 | + if (!empty($conf->global->PRODUIT_MULTIPRICES)) |
|
214 | 214 | { |
215 | 215 | // Exports product multiprice |
216 | 216 | $r++; |
217 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
218 | - $this->export_label[$r]="ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
219 | - $this->export_permission[$r]=array(array("produit","export")); |
|
220 | - $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref", |
|
221 | - 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel", |
|
222 | - 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
223 | - 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
217 | + $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
218 | + $this->export_label[$r] = "ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
219 | + $this->export_permission[$r] = array(array("produit", "export")); |
|
220 | + $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref", |
|
221 | + 'pr.price_base_type'=>"PriceLevelPriceBase", 'pr.price_level'=>"PriceLevel", |
|
222 | + 'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
223 | + 'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
224 | 224 | 'pr.tva_tx'=>'PriceLevelVATRate', |
225 | 225 | 'pr.date_price'=>'DateCreation'); |
226 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR'; |
|
226 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR'; |
|
227 | 227 | //$this->export_TypeFields_array[$r]=array( |
228 | 228 | // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
229 | 229 | // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
230 | 230 | // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
231 | 231 | // 'p.datec'=>'Date','p.tms'=>'Date' |
232 | 232 | //); |
233 | - $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product", |
|
234 | - 'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product", |
|
233 | + $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product", |
|
234 | + 'pr.price_base_type'=>"product", 'pr.price_level'=>"product", 'pr.price'=>"product", |
|
235 | 235 | 'pr.price_ttc'=>"product", |
236 | - 'pr.price_min'=>"product",'pr.price_min_ttc'=>"product", |
|
236 | + 'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product", |
|
237 | 237 | 'pr.tva_tx'=>'product', |
238 | 238 | 'pr.recuperableonly'=>'product', |
239 | 239 | 'pr.date_price'=>"product"); |
240 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
241 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
242 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity |
|
243 | - $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
240 | + $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
241 | + $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
242 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity |
|
243 | + $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
244 | 244 | } |
245 | 245 | |
246 | - if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) |
|
246 | + if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) |
|
247 | 247 | { |
248 | 248 | // Exports virtual products |
249 | 249 | $r++; |
250 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
251 | - $this->export_label[$r]="AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
252 | - $this->export_permission[$r]=array(array("produit","export")); |
|
253 | - $this->export_fields_array[$r]=array( |
|
254 | - 'p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl", |
|
255 | - 'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note", |
|
256 | - 'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode', |
|
257 | - 'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell", |
|
258 | - 'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
|
250 | + $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
251 | + $this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
252 | + $this->export_permission[$r] = array(array("produit", "export")); |
|
253 | + $this->export_fields_array[$r] = array( |
|
254 | + 'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl", |
|
255 | + 'p.accountancy_code_sell'=>"ProductAccountancySellCode", 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode", 'p.note'=>"Note", |
|
256 | + 'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume", 'p.weight'=>"Weight", 'p.customcode'=>'CustomCode', |
|
257 | + 'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC", 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell", |
|
258 | + 'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification' |
|
259 | 259 | ); |
260 | - if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
261 | - if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
262 | - $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock')); |
|
263 | - $this->export_TypeFields_array[$r]=array( |
|
264 | - 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
|
265 | - 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
|
266 | - 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
|
267 | - 'p.datec'=>'Date','p.tms'=>'Date' |
|
260 | + if (!empty($conf->stock->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.stock'=>'Stock', 'p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue')); |
|
261 | + if (!empty($conf->barcode->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode')); |
|
262 | + $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty'=>'Qty', 'pa.incdec'=>'ComposedProductIncDecStock')); |
|
263 | + $this->export_TypeFields_array[$r] = array( |
|
264 | + 'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text", 'p.accountancy_code_sell'=>"Text", 'p.accountancy_code_buy'=>"Text", |
|
265 | + 'p.note'=>"Text", 'p.length'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.weight'=>"Numeric", 'p.customcode'=>'Text', |
|
266 | + 'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean", |
|
267 | + 'p.datec'=>'Date', 'p.tms'=>'Date' |
|
268 | 268 | ); |
269 | - if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
270 | - if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
271 | - $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric')); |
|
272 | - $this->export_entities_array[$r]=array( |
|
273 | - 'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct", |
|
274 | - 'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct", |
|
275 | - 'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct', |
|
276 | - 'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct", |
|
277 | - 'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct" |
|
269 | + if (!empty($conf->stock->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.stock'=>'Numeric', 'p.seuil_stock_alerte'=>'Numeric', 'p.desiredstock'=>'Numeric', 'p.pmp'=>'Numeric', 'p.cost_price'=>'Numeric')); |
|
270 | + if (!empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text')); |
|
271 | + $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty'=>'Numeric')); |
|
272 | + $this->export_entities_array[$r] = array( |
|
273 | + 'p.rowid'=>"virtualproduct", 'p.ref'=>"virtualproduct", 'p.label'=>"virtualproduct", 'p.description'=>"virtualproduct", 'p.url'=>"virtualproduct", |
|
274 | + 'p.accountancy_code_sell'=>'virtualproduct', 'p.accountancy_code_buy'=>'virtualproduct', 'p.note'=>"virtualproduct", 'p.length'=>"virtualproduct", |
|
275 | + 'p.surface'=>"virtualproduct", 'p.volume'=>"virtualproduct", 'p.weight'=>"virtualproduct", 'p.customcode'=>'virtualproduct', |
|
276 | + 'p.price_base_type'=>"virtualproduct", 'p.price'=>"virtualproduct", 'p.price_ttc'=>"virtualproduct", 'p.tva_tx'=>"virtualproduct", |
|
277 | + 'p.tosell'=>"virtualproduct", 'p.tobuy'=>"virtualproduct", 'p.datec'=>"virtualproduct", 'p.tms'=>"virtualproduct" |
|
278 | 278 | ); |
279 | - if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct')); |
|
280 | - if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct')); |
|
281 | - $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct')); |
|
282 | - $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
|
279 | + if (!empty($conf->stock->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'virtualproduct', 'p.seuil_stock_alerte'=>'virtualproduct', 'p.desiredstock'=>'virtualproduct', 'p.pmp'=>'virtualproduct')); |
|
280 | + if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'virtualproduct')); |
|
281 | + $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty'=>"subproduct", 'pa.incdec'=>'subproduct')); |
|
282 | + $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra'; |
|
283 | 283 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
284 | - $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p2.rowid'=>"Id",'p2.ref'=>"Ref",'p2.label'=>"Label",'p2.description'=>"Description")); |
|
285 | - $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct")); |
|
286 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
287 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
288 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,'; |
|
289 | - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2'; |
|
290 | - $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
291 | - $this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils'; |
|
284 | + $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p2.rowid'=>"Id", 'p2.ref'=>"Ref", 'p2.label'=>"Label", 'p2.description'=>"Description")); |
|
285 | + $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p2.rowid'=>"subproduct", 'p2.ref'=>"subproduct", 'p2.label'=>"subproduct", 'p2.description'=>"subproduct")); |
|
286 | + $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
287 | + $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p'; |
|
288 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,'; |
|
289 | + $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2'; |
|
290 | + $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
|
291 | + $this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils'; |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | // Imports |
295 | 295 | //-------- |
296 | - $r=0; |
|
296 | + $r = 0; |
|
297 | 297 | |
298 | 298 | $r++; |
299 | - $this->import_code[$r]=$this->rights_class.'_'.$r; |
|
300 | - $this->import_label[$r]="Products"; // Translation key |
|
301 | - $this->import_icon[$r]=$this->picto; |
|
302 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
303 | - $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields'); |
|
304 | - $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id |
|
305 | - $this->import_fields_array[$r]=array( |
|
306 | - 'p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
307 | - 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume", |
|
308 | - 'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC", |
|
309 | - 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation' |
|
299 | + $this->import_code[$r] = $this->rights_class.'_'.$r; |
|
300 | + $this->import_label[$r] = "Products"; // Translation key |
|
301 | + $this->import_icon[$r] = $this->picto; |
|
302 | + $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
|
303 | + $this->import_tables_array[$r] = array('p'=>MAIN_DB_PREFIX.'product', 'extra'=>MAIN_DB_PREFIX.'product_extrafields'); |
|
304 | + $this->import_tables_creator_array[$r] = array('p'=>'fk_user_author'); // Fields to store import user id |
|
305 | + $this->import_fields_array[$r] = array( |
|
306 | + 'p.ref'=>"Ref*", 'p.label'=>"Label*", 'p.description'=>"Description", 'p.url'=>"PublicUrl", 'p.accountancy_code_sell'=>"ProductAccountancySellCode", |
|
307 | + 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode", 'p.note'=>"Note", 'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume", |
|
308 | + 'p.weight'=>"Weight", 'p.duration'=>"Duration", 'p.customcode'=>'CustomCode', 'p.price'=>"SellingPriceHT", 'p.price_ttc'=>"SellingPriceTTC", |
|
309 | + 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*", 'p.tobuy'=>"OnBuy*", 'p.fk_product_type'=>"Type*", 'p.finished'=>'Nature', 'p.datec'=>'DateCreation' |
|
310 | 310 | ); |
311 | - if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
312 | - if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
313 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR')); |
|
314 | - if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type')); |
|
315 | - if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type')); |
|
316 | - if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
317 | - if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
311 | + if (!empty($conf->stock->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue')); |
|
312 | + if (!empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price'=>'CostPrice')); |
|
313 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly'=>'NPR')); |
|
314 | + if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type')); |
|
315 | + if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type')); |
|
316 | + if (!empty($conf->barcode->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode'=>'BarCode')); |
|
317 | + if (!empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
318 | 318 | // Add extra fields |
319 | - $import_extrafield_sample=array(); |
|
320 | - $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")"; |
|
321 | - $resql=$this->db->query($sql); |
|
319 | + $import_extrafield_sample = array(); |
|
320 | + $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")"; |
|
321 | + $resql = $this->db->query($sql); |
|
322 | 322 | if ($resql) // This can fail when class is used on old database (during migration for example) |
323 | 323 | { |
324 | - while ($obj=$this->db->fetch_object($resql)) |
|
324 | + while ($obj = $this->db->fetch_object($resql)) |
|
325 | 325 | { |
326 | - $fieldname='extra.'.$obj->name; |
|
327 | - $fieldlabel=ucfirst($obj->label); |
|
328 | - $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); |
|
329 | - $import_extrafield_sample[$fieldname]=$fieldlabel; |
|
326 | + $fieldname = 'extra.'.$obj->name; |
|
327 | + $fieldlabel = ucfirst($obj->label); |
|
328 | + $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : ''); |
|
329 | + $import_extrafield_sample[$fieldname] = $fieldlabel; |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | // End add extra fields |
333 | - $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) |
|
334 | - $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','p.recuperableonly'=>'^[0|1]$'); |
|
335 | - $import_sample=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31','p.recuperableonly'=>'0 or 1'); |
|
336 | - $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample); |
|
337 | - $this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode'); |
|
333 | + $this->import_fieldshidden_array[$r] = array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) |
|
334 | + $this->import_regex_array[$r] = array('p.ref'=>'[^ ]', 'p.tosell'=>'^[0|1]$', 'p.tobuy'=>'^[0|1]$', 'p.fk_product_type'=>'^[0|1]$', 'p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 'p.recuperableonly'=>'^[0|1]$'); |
|
335 | + $import_sample = array('p.ref'=>"PREF123456", 'p.label'=>"My product", 'p.description'=>"This is a description example for record", 'p.note'=>"Some note", 'p.price'=>"100", 'p.price_ttc'=>"110", 'p.tva_tx'=>'10', 'p.tosell'=>"0 or 1", 'p.tobuy'=>"0 or 1", 'p.fk_product_type'=>"0 for product/1 for service", 'p.finished'=>'', 'p.duration'=>"1y", 'p.datec'=>'2008-12-31', 'p.recuperableonly'=>'0 or 1'); |
|
336 | + $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample); |
|
337 | + $this->import_updatekeys_array[$r] = array('p.ref'=>'Ref', 'p.barcode'=>'BarCode'); |
|
338 | 338 | |
339 | - if (! empty($conf->fournisseur->enabled)) |
|
339 | + if (!empty($conf->fournisseur->enabled)) |
|
340 | 340 | { |
341 | 341 | // Import suppliers prices (note: this code is duplicated into module service) |
342 | 342 | $r++; |
343 | - $this->import_code[$r]=$this->rights_class.'_supplierprices'; |
|
344 | - $this->import_label[$r]="SuppliersPricesOfProductsOrServices"; // Translation key |
|
345 | - $this->import_icon[$r]=$this->picto; |
|
346 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
347 | - $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price'); |
|
348 | - $this->import_tables_creator_array[$r]=array('sp'=>'fk_user'); |
|
349 | - $this->import_fields_array[$r]=array( |
|
343 | + $this->import_code[$r] = $this->rights_class.'_supplierprices'; |
|
344 | + $this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key |
|
345 | + $this->import_icon[$r] = $this->picto; |
|
346 | + $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
|
347 | + $this->import_tables_array[$r] = array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price'); |
|
348 | + $this->import_tables_creator_array[$r] = array('sp'=>'fk_user'); |
|
349 | + $this->import_fields_array[$r] = array( |
|
350 | 350 | 'sp.fk_product'=>"ProductOrService*", |
351 | 351 | 'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode' |
352 | 352 | ); |
353 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR')); |
|
354 | - if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); |
|
355 | - if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); |
|
356 | - $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array( |
|
353 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly'=>'VATNPR')); |
|
354 | + if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); |
|
355 | + if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); |
|
356 | + $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array( |
|
357 | 357 | 'sp.price'=>"PriceQtyMinHT*", |
358 | - 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty |
|
358 | + 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty |
|
359 | 359 | 'sp.remise_percent'=>'DiscountQtyMin' |
360 | 360 | )); |
361 | - $this->import_convertvalue_array[$r]=array( |
|
362 | - 'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'), |
|
363 | - 'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product') |
|
361 | + $this->import_convertvalue_array[$r] = array( |
|
362 | + 'sp.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'), |
|
363 | + 'sp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product') |
|
364 | 364 | ); |
365 | - $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456", |
|
366 | - 'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21', |
|
365 | + $this->import_examplevalues_array[$r] = array('sp.fk_product'=>"PREF123456", |
|
366 | + 'sp.fk_soc'=>"My Supplier", 'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21', |
|
367 | 367 | 'sp.price'=>"50", |
368 | 368 | 'sp.unitprice'=>'50', |
369 | 369 | 'sp.remise_percent'=>'0' |
370 | 370 | ); |
371 | - $this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef','sp.fk_soc'=>'Supplier'); |
|
371 | + $this->import_updatekeys_array[$r] = array('sp.fk_product'=>'ProductOrService', 'sp.ref_fourn'=>'SupplierRef', 'sp.fk_soc'=>'Supplier'); |
|
372 | 372 | } |
373 | 373 | |
374 | - if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
|
374 | + if (!empty($conf->global->PRODUIT_MULTIPRICES)) |
|
375 | 375 | { |
376 | 376 | // Import product multiprice |
377 | 377 | $r++; |
378 | - $this->import_code[$r]=$this->rights_class.'_multiprice'; |
|
379 | - $this->import_label[$r]="ProductsOrServiceMultiPrice"; // Translation key |
|
380 | - $this->import_icon[$r]=$this->picto; |
|
381 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
382 | - $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price'); |
|
383 | - $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author'); // Fields to store import user id |
|
384 | - $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*", |
|
385 | - 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel", |
|
386 | - 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
387 | - 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
378 | + $this->import_code[$r] = $this->rights_class.'_multiprice'; |
|
379 | + $this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key |
|
380 | + $this->import_icon[$r] = $this->picto; |
|
381 | + $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
|
382 | + $this->import_tables_array[$r] = array('pr'=>MAIN_DB_PREFIX.'product_price'); |
|
383 | + $this->import_tables_creator_array[$r] = array('pr'=>'fk_user_author'); // Fields to store import user id |
|
384 | + $this->import_fields_array[$r] = array('pr.fk_product'=>"ProductRowid*", |
|
385 | + 'pr.price_base_type'=>"PriceLevelPriceBase", 'pr.price_level'=>"PriceLevel", |
|
386 | + 'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC", |
|
387 | + 'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
|
388 | 388 | 'pr.tva_tx'=>'PriceLevelVATRate', |
389 | 389 | 'pr.date_price'=>'DateCreation*'); |
390 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR')); |
|
391 | - $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$'); |
|
392 | - $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1", |
|
393 | - 'pr.price_base_type'=>"HT",'pr.price_level'=>"1", |
|
394 | - 'pr.price'=>"100",'pr.price_ttc'=>"110", |
|
395 | - 'pr.price_min'=>"100",'pr.price_min_ttc'=>"110", |
|
390 | + if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly'=>'NPR')); |
|
391 | + $this->import_regex_array[$r] = array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$', 'pr.recuperableonly'=>'^[0|1]$'); |
|
392 | + $this->import_examplevalues_array[$r] = array('pr.fk_product'=>"1", |
|
393 | + 'pr.price_base_type'=>"HT", 'pr.price_level'=>"1", |
|
394 | + 'pr.price'=>"100", 'pr.price_ttc'=>"110", |
|
395 | + 'pr.price_min'=>"100", 'pr.price_min_ttc'=>"110", |
|
396 | 396 | 'pr.tva_tx'=>'20', |
397 | 397 | 'pr.recuperableonly'=>'0', |
398 | 398 | 'pr.date_price'=>'2013-04-10'); |
399 | 399 | } |
400 | 400 | |
401 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
401 | + if (!empty($conf->global->MAIN_MULTILANGS)) |
|
402 | 402 | { |
403 | 403 | $r++; |
404 | - $this->import_code[$r]=$this->rights_class.'_languages'; |
|
405 | - $this->import_label[$r]="ProductsOrServicesTranslations"; |
|
406 | - $this->import_icon[$r]=$this->picto; |
|
407 | - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
|
408 | - $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang'); |
|
404 | + $this->import_code[$r] = $this->rights_class.'_languages'; |
|
405 | + $this->import_label[$r] = "ProductsOrServicesTranslations"; |
|
406 | + $this->import_icon[$r] = $this->picto; |
|
407 | + $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon |
|
408 | + $this->import_tables_array[$r] = array('l'=>MAIN_DB_PREFIX.'product_lang'); |
|
409 | 409 | // multiline translation, one line per translation |
410 | - $this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription'); |
|
410 | + $this->import_fields_array[$r] = array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription'); |
|
411 | 411 | //$this->import_fields_array[$r]['l.note']='TranslatedNote'; |
412 | - $this->import_convertvalue_array[$r]=array( |
|
413 | - 'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product') |
|
412 | + $this->import_convertvalue_array[$r] = array( |
|
413 | + 'l.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product') |
|
414 | 414 | ); |
415 | - $this->import_examplevalues_array[$r]=array('l.fk_product'=>'MyProductRef','l.lang'=>'en_US','l.label'=>'Label in en_US','l.description'=>'Desc in en_US'); |
|
416 | - $this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language'); |
|
415 | + $this->import_examplevalues_array[$r] = array('l.fk_product'=>'MyProductRef', 'l.lang'=>'en_US', 'l.label'=>'Label in en_US', 'l.description'=>'Desc in en_US'); |
|
416 | + $this->import_updatekeys_array[$r] = array('l.fk_product'=>'Ref', 'l.lang'=>'Language'); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
@@ -426,12 +426,12 @@ discard block |
||
426 | 426 | * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') |
427 | 427 | * @return int 1 if OK, 0 if KO |
428 | 428 | */ |
429 | - function init($options='') |
|
429 | + function init($options = '') |
|
430 | 430 | { |
431 | 431 | $this->remove($options); |
432 | 432 | |
433 | 433 | $sql = array(); |
434 | 434 | |
435 | - return $this->_init($sql,$options); |
|
435 | + return $this->_init($sql, $options); |
|
436 | 436 | } |
437 | 437 | } |
@@ -173,42 +173,89 @@ discard block |
||
173 | 173 | 'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC", |
174 | 174 | 'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
175 | 175 | ); |
176 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR'; |
|
177 | - if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
178 | - if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
179 | - if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
176 | + if (is_object($mysoc) && $mysoc->useNPR()) { |
|
177 | + $this->export_fields_array[$r]['p.recuperableonly']='NPR'; |
|
178 | + } |
|
179 | + if (! empty($conf->stock->enabled)) { |
|
180 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
181 | + } |
|
182 | + if (! empty($conf->barcode->enabled)) { |
|
183 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
184 | + } |
|
185 | + if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) { |
|
186 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
187 | + } |
|
180 | 188 | $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
181 | 189 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
182 | - if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery')); |
|
183 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories')); |
|
184 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote')); |
|
185 | - if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
190 | + if (! empty($conf->fournisseur->enabled)) { |
|
191 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin','pf.unitprice'=>'BuyingPrice','pf.delivery_time_days'=>'NbDaysToDelivery')); |
|
192 | + } |
|
193 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) { |
|
194 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories')); |
|
195 | + } |
|
196 | + if (! empty($conf->global->MAIN_MULTILANGS)) { |
|
197 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote')); |
|
198 | + } |
|
199 | + if (! empty($conf->global->PRODUCT_USE_UNITS)) { |
|
200 | + $this->export_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
201 | + } |
|
186 | 202 | $this->export_TypeFields_array[$r]=array( |
187 | 203 | 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
188 | 204 | 'p.note'=>"Text",'p.length'=>"Numeric",'p.width'=>"Numeric",'p.height'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric", |
189 | 205 | 'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean", |
190 | 206 | 'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date' |
191 | 207 | ); |
192 | - if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
193 | - if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
194 | - if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric')); |
|
195 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text')); |
|
196 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text')); |
|
208 | + if (! empty($conf->stock->enabled)) { |
|
209 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
210 | + } |
|
211 | + if (! empty($conf->barcode->enabled)) { |
|
212 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
213 | + } |
|
214 | + if (! empty($conf->fournisseur->enabled)) { |
|
215 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric','pf.delivery_time_days'=>'Numeric')); |
|
216 | + } |
|
217 | + if (! empty($conf->global->MAIN_MULTILANGS)) { |
|
218 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text')); |
|
219 | + } |
|
220 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) { |
|
221 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text')); |
|
222 | + } |
|
197 | 223 | $this->export_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon |
198 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category')); |
|
199 | - if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product')); |
|
200 | - if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product')); |
|
201 | - if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref')); |
|
202 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation')); |
|
203 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid'); |
|
224 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) { |
|
225 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category')); |
|
226 | + } |
|
227 | + if (! empty($conf->stock->enabled)) { |
|
228 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product')); |
|
229 | + } |
|
230 | + if (! empty($conf->barcode->enabled)) { |
|
231 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product')); |
|
232 | + } |
|
233 | + if (! empty($conf->fournisseur->enabled)) { |
|
234 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product_supplier_ref','pf.ref_fourn'=>'product_supplier_ref','pf.unitprice'=>'product_supplier_ref','pf.quantity'=>'product_supplier_ref','pf.remise_percent'=>'product_supplier_ref','pf.delivery_time_days'=>'product_supplier_ref')); |
|
235 | + } |
|
236 | + if (! empty($conf->global->MAIN_MULTILANGS)) { |
|
237 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation')); |
|
238 | + } |
|
239 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) { |
|
240 | + $this->export_dependencies_array[$r]=array('category'=>'p.rowid'); |
|
241 | + } |
|
204 | 242 | $this->export_sql_start[$r]='SELECT DISTINCT '; |
205 | 243 | $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; |
206 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid'; |
|
207 | - if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid'; |
|
244 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) { |
|
245 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid'; |
|
246 | + } |
|
247 | + if (! empty($conf->global->MAIN_MULTILANGS)) { |
|
248 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid'; |
|
249 | + } |
|
208 | 250 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; |
209 | - if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc'; |
|
251 | + if (! empty($conf->fournisseur->enabled)) { |
|
252 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc'; |
|
253 | + } |
|
210 | 254 | $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')'; |
211 | - if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields" |
|
255 | + if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) { |
|
256 | + $this->export_sql_order[$r] =' GROUP BY p.rowid'; |
|
257 | + } |
|
258 | + // FIXME The group by used a generic value to say "all fields in select except function fields" |
|
212 | 259 | |
213 | 260 | if (! empty($conf->global->PRODUIT_MULTIPRICES)) |
214 | 261 | { |
@@ -223,7 +270,9 @@ discard block |
||
223 | 270 | 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
224 | 271 | 'pr.tva_tx'=>'PriceLevelVATRate', |
225 | 272 | 'pr.date_price'=>'DateCreation'); |
226 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR'; |
|
273 | + if (is_object($mysoc) && $mysoc->useNPR()) { |
|
274 | + $this->export_fields_array[$r]['pr.recuperableonly']='NPR'; |
|
275 | + } |
|
227 | 276 | //$this->export_TypeFields_array[$r]=array( |
228 | 277 | // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
229 | 278 | // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text', |
@@ -257,8 +306,12 @@ discard block |
||
257 | 306 | 'p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell", |
258 | 307 | 'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification' |
259 | 308 | ); |
260 | - if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
261 | - if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
309 | + if (! empty($conf->stock->enabled)) { |
|
310 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
311 | + } |
|
312 | + if (! empty($conf->barcode->enabled)) { |
|
313 | + $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
314 | + } |
|
262 | 315 | $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock')); |
263 | 316 | $this->export_TypeFields_array[$r]=array( |
264 | 317 | 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text", |
@@ -266,8 +319,12 @@ discard block |
||
266 | 319 | 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean", |
267 | 320 | 'p.datec'=>'Date','p.tms'=>'Date' |
268 | 321 | ); |
269 | - if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
270 | - if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
322 | + if (! empty($conf->stock->enabled)) { |
|
323 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric')); |
|
324 | + } |
|
325 | + if (! empty($conf->barcode->enabled)) { |
|
326 | + $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text')); |
|
327 | + } |
|
271 | 328 | $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric')); |
272 | 329 | $this->export_entities_array[$r]=array( |
273 | 330 | 'p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct", |
@@ -276,8 +333,12 @@ discard block |
||
276 | 333 | 'p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct", |
277 | 334 | 'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct" |
278 | 335 | ); |
279 | - if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct')); |
|
280 | - if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct')); |
|
336 | + if (! empty($conf->stock->enabled)) { |
|
337 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct')); |
|
338 | + } |
|
339 | + if (! empty($conf->barcode->enabled)) { |
|
340 | + $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct')); |
|
341 | + } |
|
281 | 342 | $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct')); |
282 | 343 | $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra'; |
283 | 344 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
@@ -308,22 +369,38 @@ discard block |
||
308 | 369 | 'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC", |
309 | 370 | 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation' |
310 | 371 | ); |
311 | - if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
312 | - if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
313 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR')); |
|
314 | - if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type')); |
|
315 | - if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type')); |
|
316 | - if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
317 | - if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
372 | + if (! empty($conf->stock->enabled)) { |
|
373 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue')); |
|
374 | + } |
|
375 | + if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) { |
|
376 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice')); |
|
377 | + } |
|
378 | + if (is_object($mysoc) && $mysoc->useNPR()) { |
|
379 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR')); |
|
380 | + } |
|
381 | + if (is_object($mysoc) && $mysoc->useLocalTax(1)) { |
|
382 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type')); |
|
383 | + } |
|
384 | + if (is_object($mysoc) && $mysoc->useLocalTax(2)) { |
|
385 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type')); |
|
386 | + } |
|
387 | + if (! empty($conf->barcode->enabled)) { |
|
388 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode')); |
|
389 | + } |
|
390 | + if (! empty($conf->global->PRODUCT_USE_UNITS)) { |
|
391 | + $this->import_fields_array[$r]['p.fk_unit'] = 'Unit'; |
|
392 | + } |
|
318 | 393 | // Add extra fields |
319 | 394 | $import_extrafield_sample=array(); |
320 | 395 | $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.")"; |
321 | 396 | $resql=$this->db->query($sql); |
322 | - if ($resql) // This can fail when class is used on old database (during migration for example) |
|
397 | + if ($resql) { |
|
398 | + // This can fail when class is used on old database (during migration for example) |
|
323 | 399 | { |
324 | 400 | while ($obj=$this->db->fetch_object($resql)) |
325 | 401 | { |
326 | 402 | $fieldname='extra.'.$obj->name; |
403 | + } |
|
327 | 404 | $fieldlabel=ucfirst($obj->label); |
328 | 405 | $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); |
329 | 406 | $import_extrafield_sample[$fieldname]=$fieldlabel; |
@@ -350,9 +427,15 @@ discard block |
||
350 | 427 | 'sp.fk_product'=>"ProductOrService*", |
351 | 428 | 'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate', 'sp.default_vat_code'=>'VATCode' |
352 | 429 | ); |
353 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR')); |
|
354 | - if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); |
|
355 | - if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); |
|
430 | + if (is_object($mysoc) && $mysoc->useNPR()) { |
|
431 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'VATNPR')); |
|
432 | + } |
|
433 | + if (is_object($mysoc) && $mysoc->useLocalTax(1)) { |
|
434 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type')); |
|
435 | + } |
|
436 | + if (is_object($mysoc) && $mysoc->useLocalTax(2)) { |
|
437 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type')); |
|
438 | + } |
|
356 | 439 | $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array( |
357 | 440 | 'sp.price'=>"PriceQtyMinHT*", |
358 | 441 | 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty |
@@ -387,7 +470,9 @@ discard block |
||
387 | 470 | 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC", |
388 | 471 | 'pr.tva_tx'=>'PriceLevelVATRate', |
389 | 472 | 'pr.date_price'=>'DateCreation*'); |
390 | - if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR')); |
|
473 | + if (is_object($mysoc) && $mysoc->useNPR()) { |
|
474 | + $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR')); |
|
475 | + } |
|
391 | 476 | $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$'); |
392 | 477 | $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1", |
393 | 478 | 'pr.price_base_type'=>"HT",'pr.price_level'=>"1", |
@@ -24,9 +24,9 @@ |
||
24 | 24 | abstract class ModelePDFStock extends CommonDocGenerator |
25 | 25 | { |
26 | 26 | /** |
27 | - * @var string Error code (or message) |
|
28 | - */ |
|
29 | - public $error=''; |
|
27 | + * @var string Error code (or message) |
|
28 | + */ |
|
29 | + public $error=''; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @var string Error code (or message) |
28 | 28 | */ |
29 | - public $error=''; |
|
29 | + public $error = ''; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | * @param integer $maxfilenamelength Max length of value to show |
38 | 38 | * @return array List of templates |
39 | 39 | */ |
40 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
40 | + static function liste_modeles($db, $maxfilenamelength = 0) |
|
41 | 41 | { |
42 | 42 | // phpcs:enable |
43 | 43 | global $conf; |
44 | 44 | |
45 | - $type='stock'; |
|
46 | - $liste=array(); |
|
45 | + $type = 'stock'; |
|
46 | + $liste = array(); |
|
47 | 47 | |
48 | 48 | include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
49 | - $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
49 | + $liste = getListOfModels($db, $type, $maxfilenamelength); |
|
50 | 50 | |
51 | 51 | return $liste; |
52 | 52 | } |
@@ -37,136 +37,136 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class doc_generic_stock_odt extends ModelePDFStock |
39 | 39 | { |
40 | - /** |
|
41 | - * Issuer |
|
42 | - * @var Societe |
|
43 | - */ |
|
44 | - public $emetteur; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array() Minimum version of PHP required by module. |
|
48 | - * e.g.: PHP ≥ 5.4 = array(5, 4) |
|
49 | - */ |
|
50 | - public $phpmin = array(5, 4); |
|
51 | - |
|
52 | - /** |
|
40 | + /** |
|
41 | + * Issuer |
|
42 | + * @var Societe |
|
43 | + */ |
|
44 | + public $emetteur; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array() Minimum version of PHP required by module. |
|
48 | + * e.g.: PHP ≥ 5.4 = array(5, 4) |
|
49 | + */ |
|
50 | + public $phpmin = array(5, 4); |
|
51 | + |
|
52 | + /** |
|
53 | 53 | * Dolibarr version of the loaded document |
54 | 54 | * @public string |
55 | 55 | */ |
56 | - public $version = 'dolibarr'; |
|
56 | + public $version = 'dolibarr'; |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Constructor |
|
61 | - * |
|
62 | - * @param DoliDB $db Database handler |
|
63 | - */ |
|
64 | - function __construct($db) |
|
65 | - { |
|
66 | - global $conf, $langs, $mysoc; |
|
59 | + /** |
|
60 | + * Constructor |
|
61 | + * |
|
62 | + * @param DoliDB $db Database handler |
|
63 | + */ |
|
64 | + function __construct($db) |
|
65 | + { |
|
66 | + global $conf, $langs, $mysoc; |
|
67 | 67 | |
68 | - // Load translation files required by the page |
|
68 | + // Load translation files required by the page |
|
69 | 69 | $langs->loadLangs(array("main","companies")); |
70 | 70 | |
71 | - $this->db = $db; |
|
72 | - $this->name = "ODT templates"; |
|
73 | - $this->description = $langs->trans("DocumentModelOdt"); |
|
74 | - $this->scandir = 'STOCK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
75 | - |
|
76 | - // Dimension page pour format A4 |
|
77 | - $this->type = 'odt'; |
|
78 | - $this->page_largeur = 0; |
|
79 | - $this->page_hauteur = 0; |
|
80 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
81 | - $this->marge_gauche=0; |
|
82 | - $this->marge_droite=0; |
|
83 | - $this->marge_haute=0; |
|
84 | - $this->marge_basse=0; |
|
85 | - |
|
86 | - $this->option_logo = 1; // Affiche logo |
|
87 | - $this->option_tva = 0; // Gere option tva STOCK_TVAOPTION |
|
88 | - $this->option_modereg = 0; // Affiche mode reglement |
|
89 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
90 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
91 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
92 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
93 | - $this->option_credit_note = 0; // Support credit notes |
|
94 | - $this->option_freetext = 1; // Support add of a personalised text |
|
95 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
96 | - |
|
97 | - // Recupere emetteur |
|
98 | - $this->emetteur=$mysoc; |
|
99 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Return description of a module |
|
105 | - * |
|
106 | - * @param Translate $langs Lang object to use for output |
|
107 | - * @return string Description |
|
108 | - */ |
|
109 | - function info($langs) |
|
110 | - { |
|
111 | - global $conf, $langs; |
|
112 | - |
|
113 | - // Load translation files required by the page |
|
71 | + $this->db = $db; |
|
72 | + $this->name = "ODT templates"; |
|
73 | + $this->description = $langs->trans("DocumentModelOdt"); |
|
74 | + $this->scandir = 'STOCK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
75 | + |
|
76 | + // Dimension page pour format A4 |
|
77 | + $this->type = 'odt'; |
|
78 | + $this->page_largeur = 0; |
|
79 | + $this->page_hauteur = 0; |
|
80 | + $this->format = array($this->page_largeur,$this->page_hauteur); |
|
81 | + $this->marge_gauche=0; |
|
82 | + $this->marge_droite=0; |
|
83 | + $this->marge_haute=0; |
|
84 | + $this->marge_basse=0; |
|
85 | + |
|
86 | + $this->option_logo = 1; // Affiche logo |
|
87 | + $this->option_tva = 0; // Gere option tva STOCK_TVAOPTION |
|
88 | + $this->option_modereg = 0; // Affiche mode reglement |
|
89 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
90 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
91 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
92 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
93 | + $this->option_credit_note = 0; // Support credit notes |
|
94 | + $this->option_freetext = 1; // Support add of a personalised text |
|
95 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
96 | + |
|
97 | + // Recupere emetteur |
|
98 | + $this->emetteur=$mysoc; |
|
99 | + if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Return description of a module |
|
105 | + * |
|
106 | + * @param Translate $langs Lang object to use for output |
|
107 | + * @return string Description |
|
108 | + */ |
|
109 | + function info($langs) |
|
110 | + { |
|
111 | + global $conf, $langs; |
|
112 | + |
|
113 | + // Load translation files required by the page |
|
114 | 114 | $langs->loadLangs(array("errors","companies")); |
115 | 115 | |
116 | - $form = new Form($this->db); |
|
117 | - |
|
118 | - $texte = $this->description.".<br>\n"; |
|
119 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
120 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
121 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
122 | - $texte.= '<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">'; |
|
123 | - if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) |
|
124 | - { |
|
125 | - $texte.= '<input type="hidden" name="param2" value="STOCK_ADDON_PDF_ODT_DEFAULT">'; |
|
126 | - $texte.= '<input type="hidden" name="param3" value="STOCK_ADDON_PDF_ODT_TOBILL">'; |
|
127 | - $texte.= '<input type="hidden" name="param4" value="STOCK_ADDON_PDF_ODT_CLOSED">'; |
|
128 | - } |
|
129 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
130 | - |
|
131 | - // List of directories area |
|
132 | - $texte.= '<tr><td>'; |
|
133 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
134 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->STOCK_ADDON_PDF_ODT_PATH))); |
|
135 | - $listoffiles=array(); |
|
136 | - foreach($listofdir as $key=>$tmpdir) |
|
137 | - { |
|
138 | - $tmpdir=trim($tmpdir); |
|
139 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
140 | - if (! $tmpdir) { |
|
141 | - unset($listofdir[$key]); continue; |
|
142 | - } |
|
143 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
144 | - else |
|
145 | - { |
|
146 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
147 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
148 | - } |
|
149 | - } |
|
150 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
151 | - // Add list of substitution keys |
|
152 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
153 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
154 | - |
|
155 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
156 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
157 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
158 | - $texte.=$conf->global->STOCK_ADDON_PDF_ODT_PATH; |
|
159 | - $texte.= '</textarea>'; |
|
160 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
161 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
162 | - $texte.= '<br></div></div>'; |
|
163 | - |
|
164 | - // Scan directories |
|
165 | - if (count($listofdir)) |
|
166 | - { |
|
167 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; |
|
168 | - |
|
169 | - /*if ($conf->global->MAIN_STOCK_CHOOSE_ODT_DOCUMENT > 0) |
|
116 | + $form = new Form($this->db); |
|
117 | + |
|
118 | + $texte = $this->description.".<br>\n"; |
|
119 | + $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
120 | + $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
121 | + $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
122 | + $texte.= '<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">'; |
|
123 | + if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) |
|
124 | + { |
|
125 | + $texte.= '<input type="hidden" name="param2" value="STOCK_ADDON_PDF_ODT_DEFAULT">'; |
|
126 | + $texte.= '<input type="hidden" name="param3" value="STOCK_ADDON_PDF_ODT_TOBILL">'; |
|
127 | + $texte.= '<input type="hidden" name="param4" value="STOCK_ADDON_PDF_ODT_CLOSED">'; |
|
128 | + } |
|
129 | + $texte.= '<table class="nobordernopadding" width="100%">'; |
|
130 | + |
|
131 | + // List of directories area |
|
132 | + $texte.= '<tr><td>'; |
|
133 | + $texttitle=$langs->trans("ListOfDirectories"); |
|
134 | + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->STOCK_ADDON_PDF_ODT_PATH))); |
|
135 | + $listoffiles=array(); |
|
136 | + foreach($listofdir as $key=>$tmpdir) |
|
137 | + { |
|
138 | + $tmpdir=trim($tmpdir); |
|
139 | + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
140 | + if (! $tmpdir) { |
|
141 | + unset($listofdir[$key]); continue; |
|
142 | + } |
|
143 | + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
144 | + else |
|
145 | + { |
|
146 | + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
147 | + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
148 | + } |
|
149 | + } |
|
150 | + $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
151 | + // Add list of substitution keys |
|
152 | + $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
153 | + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
154 | + |
|
155 | + $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
156 | + $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
157 | + $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
158 | + $texte.=$conf->global->STOCK_ADDON_PDF_ODT_PATH; |
|
159 | + $texte.= '</textarea>'; |
|
160 | + $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
161 | + $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
162 | + $texte.= '<br></div></div>'; |
|
163 | + |
|
164 | + // Scan directories |
|
165 | + if (count($listofdir)) |
|
166 | + { |
|
167 | + $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; |
|
168 | + |
|
169 | + /*if ($conf->global->MAIN_STOCK_CHOOSE_ODT_DOCUMENT > 0) |
|
170 | 170 | { |
171 | 171 | // Model for creation |
172 | 172 | $liste=ModelePDFStock::liste_modeles($this->db); |
@@ -190,336 +190,336 @@ discard block |
||
190 | 190 | $texte.= "</td></tr>"; |
191 | 191 | $texte.= '</table>'; |
192 | 192 | }*/ |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - $texte.= '</td>'; |
|
195 | + $texte.= '</td>'; |
|
196 | 196 | |
197 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
198 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
199 | - $texte.= '</td>'; |
|
200 | - $texte.= '</tr>'; |
|
197 | + $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
198 | + $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
199 | + $texte.= '</td>'; |
|
200 | + $texte.= '</tr>'; |
|
201 | 201 | |
202 | - $texte.= '</table>'; |
|
203 | - $texte.= '</form>'; |
|
202 | + $texte.= '</table>'; |
|
203 | + $texte.= '</form>'; |
|
204 | 204 | |
205 | - return $texte; |
|
206 | - } |
|
205 | + return $texte; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
209 | - /** |
|
210 | - * Function to build a document on disk using the generic odt module. |
|
211 | - * |
|
212 | - * @param Stock $object Object source to build document |
|
213 | - * @param Translate $outputlangs Lang output object |
|
214 | - * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
215 | - * @param int $hidedetails Do not show line details |
|
216 | - * @param int $hidedesc Do not show desc |
|
217 | - * @param int $hideref Do not show ref |
|
218 | - * @return int 1 if OK, <=0 if KO |
|
219 | - */ |
|
220 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
221 | - { |
|
209 | + /** |
|
210 | + * Function to build a document on disk using the generic odt module. |
|
211 | + * |
|
212 | + * @param Stock $object Object source to build document |
|
213 | + * @param Translate $outputlangs Lang output object |
|
214 | + * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
215 | + * @param int $hidedetails Do not show line details |
|
216 | + * @param int $hidedesc Do not show desc |
|
217 | + * @param int $hideref Do not show ref |
|
218 | + * @return int 1 if OK, <=0 if KO |
|
219 | + */ |
|
220 | + function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
221 | + { |
|
222 | 222 | // phpcs:enable |
223 | - global $stock,$langs,$conf,$mysoc,$hookmanager,$user; |
|
224 | - |
|
225 | - if (empty($srctemplatepath)) |
|
226 | - { |
|
227 | - dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); |
|
228 | - return -1; |
|
229 | - } |
|
230 | - |
|
231 | - // Add odtgeneration hook |
|
232 | - if (! is_object($hookmanager)) |
|
233 | - { |
|
234 | - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
235 | - $hookmanager=new HookManager($this->db); |
|
236 | - } |
|
237 | - $hookmanager->initHooks(array('odtgeneration')); |
|
238 | - global $action; |
|
239 | - |
|
240 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
241 | - $sav_charset_output=$outputlangs->charset_output; |
|
242 | - $outputlangs->charset_output='UTF-8'; |
|
243 | - |
|
244 | - // Load translation files required by the page |
|
245 | - $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
|
246 | - |
|
247 | - if ($conf->produit->dir_output) |
|
248 | - { |
|
249 | - // If $object is id instead of object |
|
250 | - if (! is_object($object)) |
|
251 | - { |
|
252 | - $id = $object; |
|
253 | - $object = new Stock($this->db); |
|
254 | - $result=$object->fetch($id); |
|
255 | - if ($result < 0) |
|
256 | - { |
|
257 | - dol_print_error($this->db,$object->error); |
|
258 | - return -1; |
|
259 | - } |
|
260 | - } |
|
261 | - $stockFournisseur = new StockFournisseur($this->db); |
|
262 | - $supplierprices = $stockFournisseur->list_stock_fournisseur_price($object->id); |
|
263 | - $object->supplierprices = $supplierprices; |
|
264 | - |
|
265 | - $dir = $conf->produit->dir_output; |
|
266 | - $objectref = dol_sanitizeFileName($object->ref); |
|
267 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
268 | - $file = $dir . "/" . $objectref . ".odt"; |
|
269 | - |
|
270 | - if (! file_exists($dir)) |
|
271 | - { |
|
272 | - if (dol_mkdir($dir) < 0) |
|
273 | - { |
|
274 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
275 | - return -1; |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - if (file_exists($dir)) |
|
280 | - { |
|
281 | - //print "srctemplatepath=".$srctemplatepath; // Src filename |
|
282 | - $newfile=basename($srctemplatepath); |
|
283 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
284 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
285 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
286 | - |
|
287 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
288 | - |
|
289 | - // Get extension (ods or odt) |
|
290 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
291 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
292 | - { |
|
293 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
294 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
295 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
296 | - } |
|
297 | - else |
|
298 | - { |
|
299 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
300 | - } |
|
301 | - $file=$dir.'/'.$filename; |
|
302 | - //print "newdir=".$dir; |
|
303 | - //print "newfile=".$newfile; |
|
304 | - //print "file=".$file; |
|
305 | - //print "conf->produit->dir_temp=".$conf->produit->dir_temp; |
|
306 | - |
|
307 | - dol_mkdir($conf->produit->dir_temp); |
|
308 | - |
|
309 | - |
|
310 | - // If CUSTOMER contact defined on stock, we use it |
|
311 | - $usecontact=false; |
|
312 | - $arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
|
313 | - if (count($arrayidcontact) > 0) |
|
314 | - { |
|
315 | - $usecontact=true; |
|
316 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
317 | - } |
|
318 | - |
|
319 | - // Recipient name |
|
320 | - $contactobject=null; |
|
321 | - if (! empty($usecontact)) |
|
322 | - { |
|
323 | - // On peut utiliser le nom de la societe du contact |
|
324 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
325 | - else { |
|
326 | - $socobject = $object->thirdparty; |
|
327 | - // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
|
328 | - $contactobject = $object->contact; |
|
329 | - } |
|
330 | - } |
|
331 | - else |
|
332 | - { |
|
333 | - $socobject=$object->thirdparty; |
|
334 | - } |
|
335 | - // Make substitution |
|
336 | - $substitutionarray=array( |
|
337 | - '__FROM_NAME__' => $this->emetteur->name, |
|
338 | - '__FROM_EMAIL__' => $this->emetteur->email, |
|
339 | - '__TOTAL_TTC__' => $object->total_ttc, |
|
340 | - '__TOTAL_HT__' => $object->total_ht, |
|
341 | - '__TOTAL_VAT__' => $object->total_vat |
|
342 | - ); |
|
343 | - complete_substitutions_array($substitutionarray, $langs, $object); |
|
344 | - // Call the ODTSubstitution hook |
|
345 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
346 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
347 | - |
|
348 | - // Line of free text |
|
349 | - $newfreetext=''; |
|
350 | - $paramfreetext='stock_FREE_TEXT'; |
|
351 | - if (! empty($conf->global->$paramfreetext)) |
|
352 | - { |
|
353 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
354 | - } |
|
355 | - |
|
356 | - // Open and load template |
|
357 | - require_once ODTPHP_PATH.'odf.php'; |
|
358 | - try { |
|
359 | - $odfHandler = new odf( |
|
360 | - $srctemplatepath, |
|
361 | - array( |
|
362 | - 'PATH_TO_TMP' => $conf->produit->dir_temp, |
|
363 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
364 | - 'DELIMITER_LEFT' => '{', |
|
365 | - 'DELIMITER_RIGHT' => '}' |
|
366 | - ) |
|
367 | - ); |
|
368 | - } |
|
369 | - catch(Exception $e) |
|
370 | - { |
|
371 | - $this->error=$e->getMessage(); |
|
372 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
373 | - return -1; |
|
374 | - } |
|
375 | - // After construction $odfHandler->contentXml contains content and |
|
376 | - // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by |
|
377 | - // [!-- BEGIN lines --]*[!-- END lines --] |
|
378 | - //print html_entity_decode($odfHandler->__toString()); |
|
379 | - //print exit; |
|
380 | - |
|
381 | - $object->fetch_optionals(); |
|
382 | - |
|
383 | - // Make substitutions into odt of freetext |
|
384 | - try { |
|
385 | - $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
|
386 | - } |
|
387 | - catch (OdfException $e) |
|
388 | - { |
|
389 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
390 | - } |
|
391 | - |
|
392 | - // Define substitution array |
|
393 | - $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
|
394 | - $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
395 | - //$array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
396 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
397 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
398 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
399 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
400 | - // retrieve contact information for use in stock as contact_xxx tags |
|
401 | - $array_thirdparty_contact = array(); |
|
402 | - if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
403 | - |
|
404 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact); |
|
405 | - complete_substitutions_array($tmparray, $outputlangs, $object); |
|
406 | - |
|
407 | - // Call the ODTSubstitution hook |
|
408 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
409 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
410 | - |
|
411 | - foreach($tmparray as $key=>$value) |
|
412 | - { |
|
413 | - try { |
|
414 | - if (preg_match('/logo$/',$key)) // Image |
|
415 | - { |
|
416 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
417 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
418 | - } |
|
419 | - else // Text |
|
420 | - { |
|
421 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
422 | - } |
|
423 | - } |
|
424 | - catch (OdfException $e) |
|
425 | - { |
|
223 | + global $stock,$langs,$conf,$mysoc,$hookmanager,$user; |
|
224 | + |
|
225 | + if (empty($srctemplatepath)) |
|
226 | + { |
|
227 | + dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); |
|
228 | + return -1; |
|
229 | + } |
|
230 | + |
|
231 | + // Add odtgeneration hook |
|
232 | + if (! is_object($hookmanager)) |
|
233 | + { |
|
234 | + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
235 | + $hookmanager=new HookManager($this->db); |
|
236 | + } |
|
237 | + $hookmanager->initHooks(array('odtgeneration')); |
|
238 | + global $action; |
|
239 | + |
|
240 | + if (! is_object($outputlangs)) $outputlangs=$langs; |
|
241 | + $sav_charset_output=$outputlangs->charset_output; |
|
242 | + $outputlangs->charset_output='UTF-8'; |
|
243 | + |
|
244 | + // Load translation files required by the page |
|
245 | + $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
|
246 | + |
|
247 | + if ($conf->produit->dir_output) |
|
248 | + { |
|
249 | + // If $object is id instead of object |
|
250 | + if (! is_object($object)) |
|
251 | + { |
|
252 | + $id = $object; |
|
253 | + $object = new Stock($this->db); |
|
254 | + $result=$object->fetch($id); |
|
255 | + if ($result < 0) |
|
256 | + { |
|
257 | + dol_print_error($this->db,$object->error); |
|
258 | + return -1; |
|
259 | + } |
|
260 | + } |
|
261 | + $stockFournisseur = new StockFournisseur($this->db); |
|
262 | + $supplierprices = $stockFournisseur->list_stock_fournisseur_price($object->id); |
|
263 | + $object->supplierprices = $supplierprices; |
|
264 | + |
|
265 | + $dir = $conf->produit->dir_output; |
|
266 | + $objectref = dol_sanitizeFileName($object->ref); |
|
267 | + if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
268 | + $file = $dir . "/" . $objectref . ".odt"; |
|
269 | + |
|
270 | + if (! file_exists($dir)) |
|
271 | + { |
|
272 | + if (dol_mkdir($dir) < 0) |
|
273 | + { |
|
274 | + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
275 | + return -1; |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + if (file_exists($dir)) |
|
280 | + { |
|
281 | + //print "srctemplatepath=".$srctemplatepath; // Src filename |
|
282 | + $newfile=basename($srctemplatepath); |
|
283 | + $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
284 | + $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
285 | + $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
286 | + |
|
287 | + $newfiletmp=$objectref.'_'.$newfiletmp; |
|
288 | + |
|
289 | + // Get extension (ods or odt) |
|
290 | + $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
291 | + if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
292 | + { |
|
293 | + $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
294 | + if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
295 | + $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
296 | + } |
|
297 | + else |
|
298 | + { |
|
299 | + $filename=$newfiletmp.'.'.$newfileformat; |
|
300 | + } |
|
301 | + $file=$dir.'/'.$filename; |
|
302 | + //print "newdir=".$dir; |
|
303 | + //print "newfile=".$newfile; |
|
304 | + //print "file=".$file; |
|
305 | + //print "conf->produit->dir_temp=".$conf->produit->dir_temp; |
|
306 | + |
|
307 | + dol_mkdir($conf->produit->dir_temp); |
|
308 | + |
|
309 | + |
|
310 | + // If CUSTOMER contact defined on stock, we use it |
|
311 | + $usecontact=false; |
|
312 | + $arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
|
313 | + if (count($arrayidcontact) > 0) |
|
314 | + { |
|
315 | + $usecontact=true; |
|
316 | + $result=$object->fetch_contact($arrayidcontact[0]); |
|
317 | + } |
|
318 | + |
|
319 | + // Recipient name |
|
320 | + $contactobject=null; |
|
321 | + if (! empty($usecontact)) |
|
322 | + { |
|
323 | + // On peut utiliser le nom de la societe du contact |
|
324 | + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
325 | + else { |
|
326 | + $socobject = $object->thirdparty; |
|
327 | + // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
|
328 | + $contactobject = $object->contact; |
|
329 | + } |
|
330 | + } |
|
331 | + else |
|
332 | + { |
|
333 | + $socobject=$object->thirdparty; |
|
334 | + } |
|
335 | + // Make substitution |
|
336 | + $substitutionarray=array( |
|
337 | + '__FROM_NAME__' => $this->emetteur->name, |
|
338 | + '__FROM_EMAIL__' => $this->emetteur->email, |
|
339 | + '__TOTAL_TTC__' => $object->total_ttc, |
|
340 | + '__TOTAL_HT__' => $object->total_ht, |
|
341 | + '__TOTAL_VAT__' => $object->total_vat |
|
342 | + ); |
|
343 | + complete_substitutions_array($substitutionarray, $langs, $object); |
|
344 | + // Call the ODTSubstitution hook |
|
345 | + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
346 | + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
347 | + |
|
348 | + // Line of free text |
|
349 | + $newfreetext=''; |
|
350 | + $paramfreetext='stock_FREE_TEXT'; |
|
351 | + if (! empty($conf->global->$paramfreetext)) |
|
352 | + { |
|
353 | + $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
354 | + } |
|
355 | + |
|
356 | + // Open and load template |
|
357 | + require_once ODTPHP_PATH.'odf.php'; |
|
358 | + try { |
|
359 | + $odfHandler = new odf( |
|
360 | + $srctemplatepath, |
|
361 | + array( |
|
362 | + 'PATH_TO_TMP' => $conf->produit->dir_temp, |
|
363 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
364 | + 'DELIMITER_LEFT' => '{', |
|
365 | + 'DELIMITER_RIGHT' => '}' |
|
366 | + ) |
|
367 | + ); |
|
368 | + } |
|
369 | + catch(Exception $e) |
|
370 | + { |
|
371 | + $this->error=$e->getMessage(); |
|
372 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
373 | + return -1; |
|
374 | + } |
|
375 | + // After construction $odfHandler->contentXml contains content and |
|
376 | + // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by |
|
377 | + // [!-- BEGIN lines --]*[!-- END lines --] |
|
378 | + //print html_entity_decode($odfHandler->__toString()); |
|
379 | + //print exit; |
|
380 | + |
|
381 | + $object->fetch_optionals(); |
|
382 | + |
|
383 | + // Make substitutions into odt of freetext |
|
384 | + try { |
|
385 | + $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
|
386 | + } |
|
387 | + catch (OdfException $e) |
|
388 | + { |
|
389 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
390 | + } |
|
391 | + |
|
392 | + // Define substitution array |
|
393 | + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
|
394 | + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
395 | + //$array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
396 | + $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
397 | + $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
398 | + $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
399 | + $array_other=$this->get_substitutionarray_other($outputlangs); |
|
400 | + // retrieve contact information for use in stock as contact_xxx tags |
|
401 | + $array_thirdparty_contact = array(); |
|
402 | + if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
403 | + |
|
404 | + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact); |
|
405 | + complete_substitutions_array($tmparray, $outputlangs, $object); |
|
406 | + |
|
407 | + // Call the ODTSubstitution hook |
|
408 | + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
409 | + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
410 | + |
|
411 | + foreach($tmparray as $key=>$value) |
|
412 | + { |
|
413 | + try { |
|
414 | + if (preg_match('/logo$/',$key)) // Image |
|
415 | + { |
|
416 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
417 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
418 | + } |
|
419 | + else // Text |
|
420 | + { |
|
421 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
422 | + } |
|
423 | + } |
|
424 | + catch (OdfException $e) |
|
425 | + { |
|
426 | 426 | dol_syslog($e->getMessage(), LOG_INFO); |
427 | - } |
|
428 | - } |
|
429 | - // Replace tags of lines |
|
430 | - try |
|
431 | - { |
|
432 | - $listlines = $odfHandler->setSegment('supplierprices'); |
|
433 | - if(!empty($object->supplierprices)){ |
|
434 | - foreach ($object->supplierprices as $supplierprice) |
|
435 | - { |
|
436 | - $array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs); |
|
437 | - complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines"); |
|
438 | - // Call the ODTSubstitutionLine hook |
|
439 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$array_lines,'line'=>$supplierprice); |
|
440 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
441 | - foreach($array_lines as $key => $val) |
|
442 | - { |
|
443 | - try |
|
444 | - { |
|
445 | - $listlines->setVars($key, $val, true, 'UTF-8'); |
|
446 | - } |
|
447 | - catch(OdfException $e) |
|
448 | - { |
|
449 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
450 | - } |
|
451 | - catch(SegmentException $e) |
|
452 | - { |
|
453 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
454 | - } |
|
455 | - } |
|
456 | - $listlines->merge(); |
|
457 | - } |
|
458 | - } |
|
459 | - $odfHandler->mergeSegment($listlines); |
|
460 | - } |
|
461 | - catch(OdfException $e) |
|
462 | - { |
|
463 | - $this->error=$e->getMessage(); |
|
464 | - dol_syslog($this->error, LOG_WARNING); |
|
465 | - return -1; |
|
466 | - } |
|
467 | - |
|
468 | - // Replace labels translated |
|
469 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
470 | - foreach($tmparray as $key=>$value) |
|
471 | - { |
|
472 | - try { |
|
473 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
474 | - } |
|
475 | - catch(OdfException $e) |
|
476 | - { |
|
427 | + } |
|
428 | + } |
|
429 | + // Replace tags of lines |
|
430 | + try |
|
431 | + { |
|
432 | + $listlines = $odfHandler->setSegment('supplierprices'); |
|
433 | + if(!empty($object->supplierprices)){ |
|
434 | + foreach ($object->supplierprices as $supplierprice) |
|
435 | + { |
|
436 | + $array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs); |
|
437 | + complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines"); |
|
438 | + // Call the ODTSubstitutionLine hook |
|
439 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$array_lines,'line'=>$supplierprice); |
|
440 | + $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
441 | + foreach($array_lines as $key => $val) |
|
442 | + { |
|
443 | + try |
|
444 | + { |
|
445 | + $listlines->setVars($key, $val, true, 'UTF-8'); |
|
446 | + } |
|
447 | + catch(OdfException $e) |
|
448 | + { |
|
449 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
450 | + } |
|
451 | + catch(SegmentException $e) |
|
452 | + { |
|
453 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
454 | + } |
|
455 | + } |
|
456 | + $listlines->merge(); |
|
457 | + } |
|
458 | + } |
|
459 | + $odfHandler->mergeSegment($listlines); |
|
460 | + } |
|
461 | + catch(OdfException $e) |
|
462 | + { |
|
463 | + $this->error=$e->getMessage(); |
|
464 | + dol_syslog($this->error, LOG_WARNING); |
|
465 | + return -1; |
|
466 | + } |
|
467 | + |
|
468 | + // Replace labels translated |
|
469 | + $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
470 | + foreach($tmparray as $key=>$value) |
|
471 | + { |
|
472 | + try { |
|
473 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
474 | + } |
|
475 | + catch(OdfException $e) |
|
476 | + { |
|
477 | 477 | dol_syslog($e->getMessage(), LOG_INFO); |
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - // Call the beforeODTSave hook |
|
482 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
483 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
484 | - |
|
485 | - // Write new file |
|
486 | - if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
|
487 | - try { |
|
488 | - $odfHandler->exportAsAttachedPDF($file); |
|
489 | - } catch (Exception $e) { |
|
490 | - $this->error=$e->getMessage(); |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + // Call the beforeODTSave hook |
|
482 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
483 | + $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
484 | + |
|
485 | + // Write new file |
|
486 | + if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
|
487 | + try { |
|
488 | + $odfHandler->exportAsAttachedPDF($file); |
|
489 | + } catch (Exception $e) { |
|
490 | + $this->error=$e->getMessage(); |
|
491 | 491 | dol_syslog($e->getMessage(), LOG_INFO); |
492 | - return -1; |
|
493 | - } |
|
494 | - } |
|
495 | - else { |
|
496 | - try { |
|
497 | - $odfHandler->saveToDisk($file); |
|
498 | - } catch (Exception $e) { |
|
499 | - $this->error=$e->getMessage(); |
|
492 | + return -1; |
|
493 | + } |
|
494 | + } |
|
495 | + else { |
|
496 | + try { |
|
497 | + $odfHandler->saveToDisk($file); |
|
498 | + } catch (Exception $e) { |
|
499 | + $this->error=$e->getMessage(); |
|
500 | 500 | dol_syslog($e->getMessage(), LOG_INFO); |
501 | - return -1; |
|
502 | - } |
|
503 | - } |
|
501 | + return -1; |
|
502 | + } |
|
503 | + } |
|
504 | 504 | |
505 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
505 | + $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
506 | 506 | |
507 | - if (! empty($conf->global->MAIN_UMASK)) |
|
508 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
507 | + if (! empty($conf->global->MAIN_UMASK)) |
|
508 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
509 | 509 | |
510 | - $odfHandler=null; // Destroy object |
|
510 | + $odfHandler=null; // Destroy object |
|
511 | 511 | |
512 | - $this->result = array('fullpath'=>$file); |
|
512 | + $this->result = array('fullpath'=>$file); |
|
513 | 513 | |
514 | - return 1; // Success |
|
515 | - } |
|
516 | - else |
|
517 | - { |
|
518 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
519 | - return -1; |
|
520 | - } |
|
521 | - } |
|
514 | + return 1; // Success |
|
515 | + } |
|
516 | + else |
|
517 | + { |
|
518 | + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
519 | + return -1; |
|
520 | + } |
|
521 | + } |
|
522 | 522 | |
523 | - return -1; |
|
524 | - } |
|
523 | + return -1; |
|
524 | + } |
|
525 | 525 | } |
@@ -66,37 +66,37 @@ discard block |
||
66 | 66 | global $conf, $langs, $mysoc; |
67 | 67 | |
68 | 68 | // Load translation files required by the page |
69 | - $langs->loadLangs(array("main","companies")); |
|
69 | + $langs->loadLangs(array("main", "companies")); |
|
70 | 70 | |
71 | 71 | $this->db = $db; |
72 | 72 | $this->name = "ODT templates"; |
73 | 73 | $this->description = $langs->trans("DocumentModelOdt"); |
74 | - $this->scandir = 'STOCK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
74 | + $this->scandir = 'STOCK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
75 | 75 | |
76 | 76 | // Dimension page pour format A4 |
77 | 77 | $this->type = 'odt'; |
78 | 78 | $this->page_largeur = 0; |
79 | 79 | $this->page_hauteur = 0; |
80 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
81 | - $this->marge_gauche=0; |
|
82 | - $this->marge_droite=0; |
|
83 | - $this->marge_haute=0; |
|
84 | - $this->marge_basse=0; |
|
85 | - |
|
86 | - $this->option_logo = 1; // Affiche logo |
|
87 | - $this->option_tva = 0; // Gere option tva STOCK_TVAOPTION |
|
88 | - $this->option_modereg = 0; // Affiche mode reglement |
|
89 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
90 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
91 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
92 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
93 | - $this->option_credit_note = 0; // Support credit notes |
|
94 | - $this->option_freetext = 1; // Support add of a personalised text |
|
95 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
80 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
81 | + $this->marge_gauche = 0; |
|
82 | + $this->marge_droite = 0; |
|
83 | + $this->marge_haute = 0; |
|
84 | + $this->marge_basse = 0; |
|
85 | + |
|
86 | + $this->option_logo = 1; // Affiche logo |
|
87 | + $this->option_tva = 0; // Gere option tva STOCK_TVAOPTION |
|
88 | + $this->option_modereg = 0; // Affiche mode reglement |
|
89 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
90 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
91 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
92 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
93 | + $this->option_credit_note = 0; // Support credit notes |
|
94 | + $this->option_freetext = 1; // Support add of a personalised text |
|
95 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
96 | 96 | |
97 | 97 | // Recupere emetteur |
98 | - $this->emetteur=$mysoc; |
|
99 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
98 | + $this->emetteur = $mysoc; |
|
99 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | |
@@ -111,60 +111,60 @@ discard block |
||
111 | 111 | global $conf, $langs; |
112 | 112 | |
113 | 113 | // Load translation files required by the page |
114 | - $langs->loadLangs(array("errors","companies")); |
|
114 | + $langs->loadLangs(array("errors", "companies")); |
|
115 | 115 | |
116 | 116 | $form = new Form($this->db); |
117 | 117 | |
118 | 118 | $texte = $this->description.".<br>\n"; |
119 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
120 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
121 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
122 | - $texte.= '<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">'; |
|
119 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
120 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
121 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
122 | + $texte .= '<input type="hidden" name="param1" value="STOCK_ADDON_PDF_ODT_PATH">'; |
|
123 | 123 | if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) |
124 | 124 | { |
125 | - $texte.= '<input type="hidden" name="param2" value="STOCK_ADDON_PDF_ODT_DEFAULT">'; |
|
126 | - $texte.= '<input type="hidden" name="param3" value="STOCK_ADDON_PDF_ODT_TOBILL">'; |
|
127 | - $texte.= '<input type="hidden" name="param4" value="STOCK_ADDON_PDF_ODT_CLOSED">'; |
|
125 | + $texte .= '<input type="hidden" name="param2" value="STOCK_ADDON_PDF_ODT_DEFAULT">'; |
|
126 | + $texte .= '<input type="hidden" name="param3" value="STOCK_ADDON_PDF_ODT_TOBILL">'; |
|
127 | + $texte .= '<input type="hidden" name="param4" value="STOCK_ADDON_PDF_ODT_CLOSED">'; |
|
128 | 128 | } |
129 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
129 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
130 | 130 | |
131 | 131 | // List of directories area |
132 | - $texte.= '<tr><td>'; |
|
133 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
134 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->STOCK_ADDON_PDF_ODT_PATH))); |
|
135 | - $listoffiles=array(); |
|
136 | - foreach($listofdir as $key=>$tmpdir) |
|
132 | + $texte .= '<tr><td>'; |
|
133 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
134 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->STOCK_ADDON_PDF_ODT_PATH))); |
|
135 | + $listoffiles = array(); |
|
136 | + foreach ($listofdir as $key=>$tmpdir) |
|
137 | 137 | { |
138 | - $tmpdir=trim($tmpdir); |
|
139 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
140 | - if (! $tmpdir) { |
|
138 | + $tmpdir = trim($tmpdir); |
|
139 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
140 | + if (!$tmpdir) { |
|
141 | 141 | unset($listofdir[$key]); continue; |
142 | 142 | } |
143 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
143 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
144 | 144 | else |
145 | 145 | { |
146 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
147 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
146 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
147 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
148 | 148 | } |
149 | 149 | } |
150 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
150 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
151 | 151 | // Add list of substitution keys |
152 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
153 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
154 | - |
|
155 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
156 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
157 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
158 | - $texte.=$conf->global->STOCK_ADDON_PDF_ODT_PATH; |
|
159 | - $texte.= '</textarea>'; |
|
160 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
161 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
162 | - $texte.= '<br></div></div>'; |
|
152 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
153 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
154 | + |
|
155 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
156 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
157 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
158 | + $texte .= $conf->global->STOCK_ADDON_PDF_ODT_PATH; |
|
159 | + $texte .= '</textarea>'; |
|
160 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
161 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
162 | + $texte .= '<br></div></div>'; |
|
163 | 163 | |
164 | 164 | // Scan directories |
165 | 165 | if (count($listofdir)) |
166 | 166 | { |
167 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; |
|
167 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; |
|
168 | 168 | |
169 | 169 | /*if ($conf->global->MAIN_STOCK_CHOOSE_ODT_DOCUMENT > 0) |
170 | 170 | { |
@@ -192,15 +192,15 @@ discard block |
||
192 | 192 | }*/ |
193 | 193 | } |
194 | 194 | |
195 | - $texte.= '</td>'; |
|
195 | + $texte .= '</td>'; |
|
196 | 196 | |
197 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
198 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
199 | - $texte.= '</td>'; |
|
200 | - $texte.= '</tr>'; |
|
197 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
198 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
199 | + $texte .= '</td>'; |
|
200 | + $texte .= '</tr>'; |
|
201 | 201 | |
202 | - $texte.= '</table>'; |
|
203 | - $texte.= '</form>'; |
|
202 | + $texte .= '</table>'; |
|
203 | + $texte .= '</form>'; |
|
204 | 204 | |
205 | 205 | return $texte; |
206 | 206 | } |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | * @param int $hideref Do not show ref |
218 | 218 | * @return int 1 if OK, <=0 if KO |
219 | 219 | */ |
220 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
220 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
221 | 221 | { |
222 | 222 | // phpcs:enable |
223 | - global $stock,$langs,$conf,$mysoc,$hookmanager,$user; |
|
223 | + global $stock, $langs, $conf, $mysoc, $hookmanager, $user; |
|
224 | 224 | |
225 | 225 | if (empty($srctemplatepath)) |
226 | 226 | { |
@@ -229,17 +229,17 @@ discard block |
||
229 | 229 | } |
230 | 230 | |
231 | 231 | // Add odtgeneration hook |
232 | - if (! is_object($hookmanager)) |
|
232 | + if (!is_object($hookmanager)) |
|
233 | 233 | { |
234 | 234 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
235 | - $hookmanager=new HookManager($this->db); |
|
235 | + $hookmanager = new HookManager($this->db); |
|
236 | 236 | } |
237 | 237 | $hookmanager->initHooks(array('odtgeneration')); |
238 | 238 | global $action; |
239 | 239 | |
240 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
241 | - $sav_charset_output=$outputlangs->charset_output; |
|
242 | - $outputlangs->charset_output='UTF-8'; |
|
240 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
241 | + $sav_charset_output = $outputlangs->charset_output; |
|
242 | + $outputlangs->charset_output = 'UTF-8'; |
|
243 | 243 | |
244 | 244 | // Load translation files required by the page |
245 | 245 | $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
@@ -247,14 +247,14 @@ discard block |
||
247 | 247 | if ($conf->produit->dir_output) |
248 | 248 | { |
249 | 249 | // If $object is id instead of object |
250 | - if (! is_object($object)) |
|
250 | + if (!is_object($object)) |
|
251 | 251 | { |
252 | 252 | $id = $object; |
253 | 253 | $object = new Stock($this->db); |
254 | - $result=$object->fetch($id); |
|
254 | + $result = $object->fetch($id); |
|
255 | 255 | if ($result < 0) |
256 | 256 | { |
257 | - dol_print_error($this->db,$object->error); |
|
257 | + dol_print_error($this->db, $object->error); |
|
258 | 258 | return -1; |
259 | 259 | } |
260 | 260 | } |
@@ -264,14 +264,14 @@ discard block |
||
264 | 264 | |
265 | 265 | $dir = $conf->produit->dir_output; |
266 | 266 | $objectref = dol_sanitizeFileName($object->ref); |
267 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
268 | - $file = $dir . "/" . $objectref . ".odt"; |
|
267 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
268 | + $file = $dir."/".$objectref.".odt"; |
|
269 | 269 | |
270 | - if (! file_exists($dir)) |
|
270 | + if (!file_exists($dir)) |
|
271 | 271 | { |
272 | 272 | if (dol_mkdir($dir) < 0) |
273 | 273 | { |
274 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
274 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
275 | 275 | return -1; |
276 | 276 | } |
277 | 277 | } |
@@ -279,26 +279,26 @@ discard block |
||
279 | 279 | if (file_exists($dir)) |
280 | 280 | { |
281 | 281 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
282 | - $newfile=basename($srctemplatepath); |
|
283 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
284 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
285 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
282 | + $newfile = basename($srctemplatepath); |
|
283 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
284 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
285 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
286 | 286 | |
287 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
287 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
288 | 288 | |
289 | 289 | // Get extension (ods or odt) |
290 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
291 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
290 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
291 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
292 | 292 | { |
293 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
294 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
295 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
293 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
294 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
295 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
296 | 296 | } |
297 | 297 | else |
298 | 298 | { |
299 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
299 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
300 | 300 | } |
301 | - $file=$dir.'/'.$filename; |
|
301 | + $file = $dir.'/'.$filename; |
|
302 | 302 | //print "newdir=".$dir; |
303 | 303 | //print "newfile=".$newfile; |
304 | 304 | //print "file=".$file; |
@@ -308,20 +308,20 @@ discard block |
||
308 | 308 | |
309 | 309 | |
310 | 310 | // If CUSTOMER contact defined on stock, we use it |
311 | - $usecontact=false; |
|
312 | - $arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
|
311 | + $usecontact = false; |
|
312 | + $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); |
|
313 | 313 | if (count($arrayidcontact) > 0) |
314 | 314 | { |
315 | - $usecontact=true; |
|
316 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
315 | + $usecontact = true; |
|
316 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | // Recipient name |
320 | - $contactobject=null; |
|
321 | - if (! empty($usecontact)) |
|
320 | + $contactobject = null; |
|
321 | + if (!empty($usecontact)) |
|
322 | 322 | { |
323 | 323 | // On peut utiliser le nom de la societe du contact |
324 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
324 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
325 | 325 | else { |
326 | 326 | $socobject = $object->thirdparty; |
327 | 327 | // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
@@ -330,10 +330,10 @@ discard block |
||
330 | 330 | } |
331 | 331 | else |
332 | 332 | { |
333 | - $socobject=$object->thirdparty; |
|
333 | + $socobject = $object->thirdparty; |
|
334 | 334 | } |
335 | 335 | // Make substitution |
336 | - $substitutionarray=array( |
|
336 | + $substitutionarray = array( |
|
337 | 337 | '__FROM_NAME__' => $this->emetteur->name, |
338 | 338 | '__FROM_EMAIL__' => $this->emetteur->email, |
339 | 339 | '__TOTAL_TTC__' => $object->total_ttc, |
@@ -342,15 +342,15 @@ discard block |
||
342 | 342 | ); |
343 | 343 | complete_substitutions_array($substitutionarray, $langs, $object); |
344 | 344 | // Call the ODTSubstitution hook |
345 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
346 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
345 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray); |
|
346 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
347 | 347 | |
348 | 348 | // Line of free text |
349 | - $newfreetext=''; |
|
350 | - $paramfreetext='stock_FREE_TEXT'; |
|
351 | - if (! empty($conf->global->$paramfreetext)) |
|
349 | + $newfreetext = ''; |
|
350 | + $paramfreetext = 'stock_FREE_TEXT'; |
|
351 | + if (!empty($conf->global->$paramfreetext)) |
|
352 | 352 | { |
353 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
353 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Open and load template |
@@ -360,15 +360,15 @@ discard block |
||
360 | 360 | $srctemplatepath, |
361 | 361 | array( |
362 | 362 | 'PATH_TO_TMP' => $conf->produit->dir_temp, |
363 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
363 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
364 | 364 | 'DELIMITER_LEFT' => '{', |
365 | 365 | 'DELIMITER_RIGHT' => '}' |
366 | 366 | ) |
367 | 367 | ); |
368 | 368 | } |
369 | - catch(Exception $e) |
|
369 | + catch (Exception $e) |
|
370 | 370 | { |
371 | - $this->error=$e->getMessage(); |
|
371 | + $this->error = $e->getMessage(); |
|
372 | 372 | dol_syslog($e->getMessage(), LOG_INFO); |
373 | 373 | return -1; |
374 | 374 | } |
@@ -393,25 +393,25 @@ discard block |
||
393 | 393 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
394 | 394 | $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
395 | 395 | //$array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
396 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
397 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
398 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
399 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
396 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
397 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
398 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
399 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
400 | 400 | // retrieve contact information for use in stock as contact_xxx tags |
401 | 401 | $array_thirdparty_contact = array(); |
402 | - if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
402 | + if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
403 | 403 | |
404 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact); |
|
404 | + $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact); |
|
405 | 405 | complete_substitutions_array($tmparray, $outputlangs, $object); |
406 | 406 | |
407 | 407 | // Call the ODTSubstitution hook |
408 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
409 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
408 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
409 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
410 | 410 | |
411 | - foreach($tmparray as $key=>$value) |
|
411 | + foreach ($tmparray as $key=>$value) |
|
412 | 412 | { |
413 | 413 | try { |
414 | - if (preg_match('/logo$/',$key)) // Image |
|
414 | + if (preg_match('/logo$/', $key)) // Image |
|
415 | 415 | { |
416 | 416 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
417 | 417 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -430,25 +430,25 @@ discard block |
||
430 | 430 | try |
431 | 431 | { |
432 | 432 | $listlines = $odfHandler->setSegment('supplierprices'); |
433 | - if(!empty($object->supplierprices)){ |
|
433 | + if (!empty($object->supplierprices)) { |
|
434 | 434 | foreach ($object->supplierprices as $supplierprice) |
435 | 435 | { |
436 | 436 | $array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs); |
437 | 437 | complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines"); |
438 | 438 | // Call the ODTSubstitutionLine hook |
439 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$array_lines,'line'=>$supplierprice); |
|
440 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
441 | - foreach($array_lines as $key => $val) |
|
439 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$array_lines, 'line'=>$supplierprice); |
|
440 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
441 | + foreach ($array_lines as $key => $val) |
|
442 | 442 | { |
443 | 443 | try |
444 | 444 | { |
445 | 445 | $listlines->setVars($key, $val, true, 'UTF-8'); |
446 | 446 | } |
447 | - catch(OdfException $e) |
|
447 | + catch (OdfException $e) |
|
448 | 448 | { |
449 | 449 | dol_syslog($e->getMessage(), LOG_INFO); |
450 | 450 | } |
451 | - catch(SegmentException $e) |
|
451 | + catch (SegmentException $e) |
|
452 | 452 | { |
453 | 453 | dol_syslog($e->getMessage(), LOG_INFO); |
454 | 454 | } |
@@ -458,36 +458,36 @@ discard block |
||
458 | 458 | } |
459 | 459 | $odfHandler->mergeSegment($listlines); |
460 | 460 | } |
461 | - catch(OdfException $e) |
|
461 | + catch (OdfException $e) |
|
462 | 462 | { |
463 | - $this->error=$e->getMessage(); |
|
463 | + $this->error = $e->getMessage(); |
|
464 | 464 | dol_syslog($this->error, LOG_WARNING); |
465 | 465 | return -1; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Replace labels translated |
469 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
470 | - foreach($tmparray as $key=>$value) |
|
469 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
470 | + foreach ($tmparray as $key=>$value) |
|
471 | 471 | { |
472 | 472 | try { |
473 | 473 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
474 | 474 | } |
475 | - catch(OdfException $e) |
|
475 | + catch (OdfException $e) |
|
476 | 476 | { |
477 | 477 | dol_syslog($e->getMessage(), LOG_INFO); |
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Call the beforeODTSave hook |
482 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
483 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
482 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
|
483 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
484 | 484 | |
485 | 485 | // Write new file |
486 | 486 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
487 | 487 | try { |
488 | 488 | $odfHandler->exportAsAttachedPDF($file); |
489 | 489 | } catch (Exception $e) { |
490 | - $this->error=$e->getMessage(); |
|
490 | + $this->error = $e->getMessage(); |
|
491 | 491 | dol_syslog($e->getMessage(), LOG_INFO); |
492 | 492 | return -1; |
493 | 493 | } |
@@ -496,26 +496,26 @@ discard block |
||
496 | 496 | try { |
497 | 497 | $odfHandler->saveToDisk($file); |
498 | 498 | } catch (Exception $e) { |
499 | - $this->error=$e->getMessage(); |
|
499 | + $this->error = $e->getMessage(); |
|
500 | 500 | dol_syslog($e->getMessage(), LOG_INFO); |
501 | 501 | return -1; |
502 | 502 | } |
503 | 503 | } |
504 | 504 | |
505 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
505 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
506 | 506 | |
507 | - if (! empty($conf->global->MAIN_UMASK)) |
|
507 | + if (!empty($conf->global->MAIN_UMASK)) |
|
508 | 508 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
509 | 509 | |
510 | - $odfHandler=null; // Destroy object |
|
510 | + $odfHandler = null; // Destroy object |
|
511 | 511 | |
512 | 512 | $this->result = array('fullpath'=>$file); |
513 | 513 | |
514 | - return 1; // Success |
|
514 | + return 1; // Success |
|
515 | 515 | } |
516 | 516 | else |
517 | 517 | { |
518 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
518 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
519 | 519 | return -1; |
520 | 520 | } |
521 | 521 | } |
@@ -96,7 +96,10 @@ discard block |
||
96 | 96 | |
97 | 97 | // Recupere emetteur |
98 | 98 | $this->emetteur=$mysoc; |
99 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
99 | + if (! $this->emetteur->country_code) { |
|
100 | + $this->emetteur->country_code=substr($langs->defaultlang,-2); |
|
101 | + } |
|
102 | + // By default if not defined |
|
100 | 103 | } |
101 | 104 | |
102 | 105 | |
@@ -140,11 +143,14 @@ discard block |
||
140 | 143 | if (! $tmpdir) { |
141 | 144 | unset($listofdir[$key]); continue; |
142 | 145 | } |
143 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
144 | - else |
|
146 | + if (! is_dir($tmpdir)) { |
|
147 | + $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
148 | + } else |
|
145 | 149 | { |
146 | 150 | $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
147 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
151 | + if (count($tmpfiles)) { |
|
152 | + $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
153 | + } |
|
148 | 154 | } |
149 | 155 | } |
150 | 156 | $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
@@ -237,7 +243,9 @@ discard block |
||
237 | 243 | $hookmanager->initHooks(array('odtgeneration')); |
238 | 244 | global $action; |
239 | 245 | |
240 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
246 | + if (! is_object($outputlangs)) { |
|
247 | + $outputlangs=$langs; |
|
248 | + } |
|
241 | 249 | $sav_charset_output=$outputlangs->charset_output; |
242 | 250 | $outputlangs->charset_output='UTF-8'; |
243 | 251 | |
@@ -264,7 +272,9 @@ discard block |
||
264 | 272 | |
265 | 273 | $dir = $conf->produit->dir_output; |
266 | 274 | $objectref = dol_sanitizeFileName($object->ref); |
267 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
275 | + if (! preg_match('/specimen/i',$objectref)) { |
|
276 | + $dir.= "/" . $objectref; |
|
277 | + } |
|
268 | 278 | $file = $dir . "/" . $objectref . ".odt"; |
269 | 279 | |
270 | 280 | if (! file_exists($dir)) |
@@ -291,10 +301,11 @@ discard block |
||
291 | 301 | if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
292 | 302 | { |
293 | 303 | $format=$conf->global->MAIN_DOC_USE_TIMING; |
294 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
304 | + if ($format == '1') { |
|
305 | + $format='%Y%m%d%H%M%S'; |
|
306 | + } |
|
295 | 307 | $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
296 | - } |
|
297 | - else |
|
308 | + } else |
|
298 | 309 | { |
299 | 310 | $filename=$newfiletmp.'.'.$newfileformat; |
300 | 311 | } |
@@ -321,14 +332,14 @@ discard block |
||
321 | 332 | if (! empty($usecontact)) |
322 | 333 | { |
323 | 334 | // On peut utiliser le nom de la societe du contact |
324 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
325 | - else { |
|
335 | + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { |
|
336 | + $socobject = $object->contact; |
|
337 | + } else { |
|
326 | 338 | $socobject = $object->thirdparty; |
327 | 339 | // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
328 | 340 | $contactobject = $object->contact; |
329 | 341 | } |
330 | - } |
|
331 | - else |
|
342 | + } else |
|
332 | 343 | { |
333 | 344 | $socobject=$object->thirdparty; |
334 | 345 | } |
@@ -365,8 +376,7 @@ discard block |
||
365 | 376 | 'DELIMITER_RIGHT' => '}' |
366 | 377 | ) |
367 | 378 | ); |
368 | - } |
|
369 | - catch(Exception $e) |
|
379 | + } catch(Exception $e) |
|
370 | 380 | { |
371 | 381 | $this->error=$e->getMessage(); |
372 | 382 | dol_syslog($e->getMessage(), LOG_INFO); |
@@ -383,8 +393,7 @@ discard block |
||
383 | 393 | // Make substitutions into odt of freetext |
384 | 394 | try { |
385 | 395 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
386 | - } |
|
387 | - catch (OdfException $e) |
|
396 | + } catch (OdfException $e) |
|
388 | 397 | { |
389 | 398 | dol_syslog($e->getMessage(), LOG_INFO); |
390 | 399 | } |
@@ -399,7 +408,9 @@ discard block |
||
399 | 408 | $array_other=$this->get_substitutionarray_other($outputlangs); |
400 | 409 | // retrieve contact information for use in stock as contact_xxx tags |
401 | 410 | $array_thirdparty_contact = array(); |
402 | - if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
411 | + if ($usecontact && is_object($contactobject)) { |
|
412 | + $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
413 | + } |
|
403 | 414 | |
404 | 415 | $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact); |
405 | 416 | complete_substitutions_array($tmparray, $outputlangs, $object); |
@@ -411,17 +422,18 @@ discard block |
||
411 | 422 | foreach($tmparray as $key=>$value) |
412 | 423 | { |
413 | 424 | try { |
414 | - if (preg_match('/logo$/',$key)) // Image |
|
425 | + if (preg_match('/logo$/',$key)) { |
|
426 | + // Image |
|
415 | 427 | { |
416 | 428 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
417 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
418 | - } |
|
419 | - else // Text |
|
429 | + } else { |
|
430 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
431 | + } |
|
432 | + } else // Text |
|
420 | 433 | { |
421 | 434 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
422 | 435 | } |
423 | - } |
|
424 | - catch (OdfException $e) |
|
436 | + } catch (OdfException $e) |
|
425 | 437 | { |
426 | 438 | dol_syslog($e->getMessage(), LOG_INFO); |
427 | 439 | } |
@@ -443,12 +455,10 @@ discard block |
||
443 | 455 | try |
444 | 456 | { |
445 | 457 | $listlines->setVars($key, $val, true, 'UTF-8'); |
446 | - } |
|
447 | - catch(OdfException $e) |
|
458 | + } catch(OdfException $e) |
|
448 | 459 | { |
449 | 460 | dol_syslog($e->getMessage(), LOG_INFO); |
450 | - } |
|
451 | - catch(SegmentException $e) |
|
461 | + } catch(SegmentException $e) |
|
452 | 462 | { |
453 | 463 | dol_syslog($e->getMessage(), LOG_INFO); |
454 | 464 | } |
@@ -457,8 +467,7 @@ discard block |
||
457 | 467 | } |
458 | 468 | } |
459 | 469 | $odfHandler->mergeSegment($listlines); |
460 | - } |
|
461 | - catch(OdfException $e) |
|
470 | + } catch(OdfException $e) |
|
462 | 471 | { |
463 | 472 | $this->error=$e->getMessage(); |
464 | 473 | dol_syslog($this->error, LOG_WARNING); |
@@ -471,8 +480,7 @@ discard block |
||
471 | 480 | { |
472 | 481 | try { |
473 | 482 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
474 | - } |
|
475 | - catch(OdfException $e) |
|
483 | + } catch(OdfException $e) |
|
476 | 484 | { |
477 | 485 | dol_syslog($e->getMessage(), LOG_INFO); |
478 | 486 | } |
@@ -491,8 +499,7 @@ discard block |
||
491 | 499 | dol_syslog($e->getMessage(), LOG_INFO); |
492 | 500 | return -1; |
493 | 501 | } |
494 | - } |
|
495 | - else { |
|
502 | + } else { |
|
496 | 503 | try { |
497 | 504 | $odfHandler->saveToDisk($file); |
498 | 505 | } catch (Exception $e) { |
@@ -504,16 +511,16 @@ discard block |
||
504 | 511 | |
505 | 512 | $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
506 | 513 | |
507 | - if (! empty($conf->global->MAIN_UMASK)) |
|
508 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
514 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
515 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
516 | + } |
|
509 | 517 | |
510 | 518 | $odfHandler=null; // Destroy object |
511 | 519 | |
512 | 520 | $this->result = array('fullpath'=>$file); |
513 | 521 | |
514 | 522 | return 1; // Success |
515 | - } |
|
516 | - else |
|
523 | + } else |
|
517 | 524 | { |
518 | 525 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
519 | 526 | return -1; |