@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | ); |
| 30 | 30 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
| 31 | 31 | { |
| 32 | - $supportedoauth2array['OAUTH_STRIPE_TEST_NAME']='stripetest'; |
|
| 33 | - $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME']='stripelive'; |
|
| 32 | + $supportedoauth2array['OAUTH_STRIPE_TEST_NAME']='stripetest'; |
|
| 33 | + $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME']='stripelive'; |
|
| 34 | 34 | } |
| 35 | 35 | $supportedoauth2array['OAUTH_GITHUB_NAME']='github'; |
| 36 | 36 | |
@@ -220,17 +220,17 @@ discard block |
||
| 220 | 220 | 'OAUTH_STRAVA_ID', |
| 221 | 221 | 'OAUTH_STRAVA_SECRET', |
| 222 | 222 | ), |
| 223 | - array( |
|
| 224 | - 'OAUTH_STRIPE_TEST_NAME', |
|
| 225 | - 'OAUTH_STRIPE_TEST_ID', |
|
| 226 | - 'STRIPE_TEST_SECRET_KEY', |
|
| 227 | - ), |
|
| 228 | - array( |
|
| 229 | - 'OAUTH_STRIPE_LIVE_NAME', |
|
| 230 | - 'OAUTH_STRIPE_LIVE_ID', |
|
| 231 | - 'STRIPE_LIVE_SECRET_KEY', |
|
| 232 | - ), |
|
| 233 | - array( |
|
| 223 | + array( |
|
| 224 | + 'OAUTH_STRIPE_TEST_NAME', |
|
| 225 | + 'OAUTH_STRIPE_TEST_ID', |
|
| 226 | + 'STRIPE_TEST_SECRET_KEY', |
|
| 227 | + ), |
|
| 228 | + array( |
|
| 229 | + 'OAUTH_STRIPE_LIVE_NAME', |
|
| 230 | + 'OAUTH_STRIPE_LIVE_ID', |
|
| 231 | + 'STRIPE_LIVE_SECRET_KEY', |
|
| 232 | + ), |
|
| 233 | + array( |
|
| 234 | 234 | 'OAUTH_TUMBLR_NAME', |
| 235 | 235 | 'OAUTH_TUMBLR_ID', |
| 236 | 236 | 'OAUTH_TUMBLR_SECRET', |
@@ -24,20 +24,20 @@ |
||
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | // Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth) |
| 27 | -$supportedoauth2array=array( |
|
| 27 | +$supportedoauth2array = array( |
|
| 28 | 28 | 'OAUTH_GOOGLE_NAME'=>'google', |
| 29 | 29 | ); |
| 30 | 30 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
| 31 | 31 | { |
| 32 | - $supportedoauth2array['OAUTH_STRIPE_TEST_NAME']='stripetest'; |
|
| 33 | - $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME']='stripelive'; |
|
| 32 | + $supportedoauth2array['OAUTH_STRIPE_TEST_NAME'] = 'stripetest'; |
|
| 33 | + $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME'] = 'stripelive'; |
|
| 34 | 34 | } |
| 35 | -$supportedoauth2array['OAUTH_GITHUB_NAME']='github'; |
|
| 35 | +$supportedoauth2array['OAUTH_GITHUB_NAME'] = 'github'; |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | // API access parameters OAUTH |
| 40 | -$list = array ( |
|
| 40 | +$list = array( |
|
| 41 | 41 | array( |
| 42 | 42 | 'OAUTH_AMAZON_NAME', |
| 43 | 43 | 'OAUTH_AMAZON_ID', |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function holiday_prepare_head($object) |
| 31 | 31 | { |
| 32 | - global $db, $langs, $conf, $user; |
|
| 32 | + global $db, $langs, $conf, $user; |
|
| 33 | 33 | |
| 34 | - $h = 0; |
|
| 35 | - $head = array(); |
|
| 34 | + $h = 0; |
|
| 35 | + $head = array(); |
|
| 36 | 36 | |
| 37 | 37 | $head[$h][0] = DOL_URL_ROOT.'/holiday/card.php?id='.$object->id; |
| 38 | 38 | $head[$h][1] = $langs->trans("Card"); |
@@ -57,23 +57,23 @@ discard block |
||
| 57 | 57 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 58 | 58 | complete_head_from_modules($conf,$langs,$object,$head,$h,'holiday'); |
| 59 | 59 | |
| 60 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'holiday','remove'); |
|
| 60 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'holiday','remove'); |
|
| 61 | 61 | |
| 62 | - return $head; |
|
| 62 | + return $head; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Return array head with list of tabs to view object informations |
| 68 | 68 | * |
| 69 | - * @return array head |
|
| 69 | + * @return array head |
|
| 70 | 70 | */ |
| 71 | 71 | function holiday_admin_prepare_head() |
| 72 | 72 | { |
| 73 | - global $db, $langs, $conf, $user; |
|
| 73 | + global $db, $langs, $conf, $user; |
|
| 74 | 74 | |
| 75 | - $h = 0; |
|
| 76 | - $head = array(); |
|
| 75 | + $h = 0; |
|
| 76 | + $head = array(); |
|
| 77 | 77 | |
| 78 | 78 | $head[$h][0] = DOL_URL_ROOT.'/admin/holiday.php'; |
| 79 | 79 | $head[$h][1] = $langs->trans("Setup"); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 87 | 87 | complete_head_from_modules($conf,$langs,null,$head,$h,'holiday_admin'); |
| 88 | 88 | |
| 89 | - complete_head_from_modules($conf,$langs,null,$head,$h,'holiday_admin','remove'); |
|
| 89 | + complete_head_from_modules($conf,$langs,null,$head,$h,'holiday_admin','remove'); |
|
| 90 | 90 | |
| 91 | - return $head; |
|
| 91 | + return $head; |
|
| 92 | 92 | } |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 44 | 44 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 45 | 45 | $upload_dir = $conf->holiday->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); |
| 46 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 47 | - $nbLinks=Link::count($db, $object->element, $object->id); |
|
| 46 | + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
|
| 47 | + $nbLinks = Link::count($db, $object->element, $object->id); |
|
| 48 | 48 | $head[$h][0] = DOL_URL_ROOT.'/holiday/document.php?id='.$object->id; |
| 49 | 49 | $head[$h][1] = $langs->trans('Documents'); |
| 50 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 50 | + if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>'; |
|
| 51 | 51 | $head[$h][2] = 'documents'; |
| 52 | 52 | $h++; |
| 53 | 53 | |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | // Entries must be declared in modules descriptor with line |
| 56 | 56 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 57 | 57 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 58 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'holiday'); |
|
| 58 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'holiday'); |
|
| 59 | 59 | |
| 60 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'holiday','remove'); |
|
| 60 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'holiday', 'remove'); |
|
| 61 | 61 | |
| 62 | 62 | return $head; |
| 63 | 63 | } |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | // Entries must be declared in modules descriptor with line |
| 85 | 85 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 86 | 86 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 87 | - complete_head_from_modules($conf,$langs,null,$head,$h,'holiday_admin'); |
|
| 87 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'holiday_admin'); |
|
| 88 | 88 | |
| 89 | - complete_head_from_modules($conf,$langs,null,$head,$h,'holiday_admin','remove'); |
|
| 89 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'holiday_admin', 'remove'); |
|
| 90 | 90 | |
| 91 | 91 | return $head; |
| 92 | 92 | } |
@@ -47,7 +47,9 @@ |
||
| 47 | 47 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 48 | 48 | $head[$h][0] = DOL_URL_ROOT.'/holiday/document.php?id='.$object->id; |
| 49 | 49 | $head[$h][1] = $langs->trans('Documents'); |
| 50 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 50 | + if (($nbFiles+$nbLinks) > 0) { |
|
| 51 | + $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 52 | + } |
|
| 51 | 53 | $head[$h][2] = 'documents'; |
| 52 | 54 | $h++; |
| 53 | 55 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $PROXY_USER=empty($conf->global->MAIN_PROXY_USER)?0:$conf->global->MAIN_PROXY_USER; |
| 42 | 42 | $PROXY_PASS=empty($conf->global->MAIN_PROXY_PASS)?0:$conf->global->MAIN_PROXY_PASS; |
| 43 | 43 | |
| 44 | - dol_syslog("getURLContent postorget=".$postorget." URL=".$url." param=".$param); |
|
| 44 | + dol_syslog("getURLContent postorget=".$postorget." URL=".$url." param=".$param); |
|
| 45 | 45 | |
| 46 | 46 | //setting the curl parameters. |
| 47 | 47 | $ch = curl_init(); |
@@ -52,17 +52,17 @@ discard block |
||
| 52 | 52 | exit;*/ |
| 53 | 53 | curl_setopt($ch, CURLOPT_URL, $url); |
| 54 | 54 | curl_setopt($ch, CURLOPT_VERBOSE, 1); |
| 55 | - curl_setopt($ch, CURLOPT_USERAGENT, 'Dolibarr geturl function'); |
|
| 55 | + curl_setopt($ch, CURLOPT_USERAGENT, 'Dolibarr geturl function'); |
|
| 56 | 56 | |
| 57 | - @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false)); // We use @ here because this may return warning if safe mode is on or open_basedir is on |
|
| 57 | + @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false)); // We use @ here because this may return warning if safe mode is on or open_basedir is on |
|
| 58 | 58 | |
| 59 | - if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders); |
|
| 60 | - curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it |
|
| 59 | + if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders); |
|
| 60 | + curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it |
|
| 61 | 61 | |
| 62 | - // By default use tls decied by PHP. |
|
| 63 | - // You can force, if supported a version like TLSv1 or TLSv1.2 |
|
| 64 | - if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION); |
|
| 65 | - //curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2 |
|
| 62 | + // By default use tls decied by PHP. |
|
| 63 | + // You can force, if supported a version like TLSv1 or TLSv1.2 |
|
| 64 | + if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION); |
|
| 65 | + //curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2 |
|
| 66 | 66 | |
| 67 | 67 | //turning off the server and peer verification(TrustManager Concept). |
| 68 | 68 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
@@ -75,37 +75,37 @@ discard block |
||
| 75 | 75 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // We want response |
| 76 | 76 | if ($postorget == 'POST') |
| 77 | 77 | { |
| 78 | - curl_setopt($ch, CURLOPT_POST, 1); // POST |
|
| 79 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields |
|
| 78 | + curl_setopt($ch, CURLOPT_POST, 1); // POST |
|
| 79 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields |
|
| 80 | 80 | } |
| 81 | 81 | else if ($postorget == 'PUT') |
| 82 | 82 | { |
| 83 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
|
| 84 | - if (! is_array($param)) parse_str($param, $array_param); |
|
| 85 | - else |
|
| 86 | - { |
|
| 87 | - dol_syslog("parameter param must be a string", LOG_WARNING); |
|
| 88 | - $array_param=$param; |
|
| 89 | - } |
|
| 90 | - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields |
|
| 83 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
|
| 84 | + if (! is_array($param)) parse_str($param, $array_param); |
|
| 85 | + else |
|
| 86 | + { |
|
| 87 | + dol_syslog("parameter param must be a string", LOG_WARNING); |
|
| 88 | + $array_param=$param; |
|
| 89 | + } |
|
| 90 | + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields |
|
| 91 | 91 | } |
| 92 | 92 | else if ($postorget == 'PUTALREADYFORMATED') |
| 93 | 93 | { |
| 94 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
|
| 95 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string |
|
| 94 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
|
| 95 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string |
|
| 96 | 96 | } |
| 97 | 97 | else if ($postorget == 'HEAD') |
| 98 | 98 | { |
| 99 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD' |
|
| 100 | - curl_setopt($ch, CURLOPT_NOBODY, true); |
|
| 99 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD' |
|
| 100 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
| 101 | 101 | } |
| 102 | 102 | else if ($postorget == 'DELETE') |
| 103 | 103 | { |
| 104 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST |
|
| 104 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST |
|
| 105 | 105 | } |
| 106 | 106 | else |
| 107 | 107 | { |
| 108 | - curl_setopt($ch, CURLOPT_POST, 0); // GET |
|
| 108 | + curl_setopt($ch, CURLOPT_POST, 0); // GET |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | //if USE_PROXY constant set at begin of this method. |
@@ -133,27 +133,27 @@ discard block |
||
| 133 | 133 | $rep['content']=$response; |
| 134 | 134 | |
| 135 | 135 | // moving to display page to display curl errors |
| 136 | - $rep['curl_error_no']=curl_errno($ch); |
|
| 136 | + $rep['curl_error_no']=curl_errno($ch); |
|
| 137 | 137 | $rep['curl_error_msg']=curl_error($ch); |
| 138 | 138 | |
| 139 | - dol_syslog("getURLContent response array is ".join(',',$rep)); |
|
| 139 | + dol_syslog("getURLContent response array is ".join(',',$rep)); |
|
| 140 | 140 | } |
| 141 | 141 | else |
| 142 | 142 | { |
| 143 | - $info = curl_getinfo($ch); |
|
| 143 | + $info = curl_getinfo($ch); |
|
| 144 | 144 | |
| 145 | - // Ad keys to $rep |
|
| 146 | - $rep = $info; |
|
| 147 | - //$rep['header_size']=$info['header_size']; |
|
| 148 | - //$rep['http_code']=$info['http_code']; |
|
| 149 | - dol_syslog("getURLContent http_code=".$rep['http_code']); |
|
| 145 | + // Ad keys to $rep |
|
| 146 | + $rep = $info; |
|
| 147 | + //$rep['header_size']=$info['header_size']; |
|
| 148 | + //$rep['http_code']=$info['http_code']; |
|
| 149 | + dol_syslog("getURLContent http_code=".$rep['http_code']); |
|
| 150 | 150 | |
| 151 | 151 | // Add more keys to $rep |
| 152 | 152 | $rep['content']=$response; |
| 153 | - $rep['curl_error_no']=''; |
|
| 154 | - $rep['curl_error_msg']=''; |
|
| 153 | + $rep['curl_error_no']=''; |
|
| 154 | + $rep['curl_error_msg']=''; |
|
| 155 | 155 | |
| 156 | - //closing the curl |
|
| 156 | + //closing the curl |
|
| 157 | 157 | curl_close($ch); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function getDomainFromURL($url) |
| 172 | 172 | { |
| 173 | - $tmpdomain = preg_replace('/^https?:\/\//i', '', $url); // Remove http(s):// |
|
| 174 | - $tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after domain |
|
| 175 | - $tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove first level domain (.com, .net, ...) |
|
| 176 | - $tmpdomain = preg_replace('/^[^\.]+\./', '', $tmpdomain); // Remove part www. before domain name |
|
| 173 | + $tmpdomain = preg_replace('/^https?:\/\//i', '', $url); // Remove http(s):// |
|
| 174 | + $tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after domain |
|
| 175 | + $tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove first level domain (.com, .net, ...) |
|
| 176 | + $tmpdomain = preg_replace('/^[^\.]+\./', '', $tmpdomain); // Remove part www. before domain name |
|
| 177 | 177 | |
| 178 | - return $tmpdomain; |
|
| 178 | + return $tmpdomain; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function getRootURLFromURL($url) |
| 190 | 190 | { |
| 191 | - $prefix=''; |
|
| 192 | - $tmpurl = $url; |
|
| 193 | - if (preg_match('/^(https?:\/\/)/i', $tmpurl, $reg)) $prefix = $reg[1]; |
|
| 194 | - $tmpurl = preg_replace('/^https?:\/\//i', '', $tmpurl); // Remove http(s):// |
|
| 195 | - $tmpurl = preg_replace('/\/.*$/i', '', $tmpurl); // Remove part after domain |
|
| 191 | + $prefix=''; |
|
| 192 | + $tmpurl = $url; |
|
| 193 | + if (preg_match('/^(https?:\/\/)/i', $tmpurl, $reg)) $prefix = $reg[1]; |
|
| 194 | + $tmpurl = preg_replace('/^https?:\/\//i', '', $tmpurl); // Remove http(s):// |
|
| 195 | + $tmpurl = preg_replace('/\/.*$/i', '', $tmpurl); // Remove part after domain |
|
| 196 | 196 | |
| 197 | - return $prefix.$tmpurl; |
|
| 197 | + return $prefix.$tmpurl; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | function removeHtmlComment($content) |
| 207 | 207 | { |
| 208 | - $content = preg_replace('/<!--[^\-]+-->/', '', $content); |
|
| 209 | - return $content; |
|
| 208 | + $content = preg_replace('/<!--[^\-]+-->/', '', $content); |
|
| 209 | + return $content; |
|
| 210 | 210 | } |
| 211 | 211 | |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | * @param string[] $addheaders Array of string to add into header. Example: ('Accept: application/xrds+xml', ....) |
| 32 | 32 | * @return array Returns an associative array containing the response from the server array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) |
| 33 | 33 | */ |
| 34 | -function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addheaders=array()) |
|
| 34 | +function getURLContent($url, $postorget = 'GET', $param = '', $followlocation = 1, $addheaders = array()) |
|
| 35 | 35 | { |
| 36 | 36 | //declaring of global variables |
| 37 | 37 | global $conf, $langs; |
| 38 | - $USE_PROXY=empty($conf->global->MAIN_PROXY_USE)?0:$conf->global->MAIN_PROXY_USE; |
|
| 39 | - $PROXY_HOST=empty($conf->global->MAIN_PROXY_HOST)?0:$conf->global->MAIN_PROXY_HOST; |
|
| 40 | - $PROXY_PORT=empty($conf->global->MAIN_PROXY_PORT)?0:$conf->global->MAIN_PROXY_PORT; |
|
| 41 | - $PROXY_USER=empty($conf->global->MAIN_PROXY_USER)?0:$conf->global->MAIN_PROXY_USER; |
|
| 42 | - $PROXY_PASS=empty($conf->global->MAIN_PROXY_PASS)?0:$conf->global->MAIN_PROXY_PASS; |
|
| 38 | + $USE_PROXY = empty($conf->global->MAIN_PROXY_USE) ? 0 : $conf->global->MAIN_PROXY_USE; |
|
| 39 | + $PROXY_HOST = empty($conf->global->MAIN_PROXY_HOST) ? 0 : $conf->global->MAIN_PROXY_HOST; |
|
| 40 | + $PROXY_PORT = empty($conf->global->MAIN_PROXY_PORT) ? 0 : $conf->global->MAIN_PROXY_PORT; |
|
| 41 | + $PROXY_USER = empty($conf->global->MAIN_PROXY_USER) ? 0 : $conf->global->MAIN_PROXY_USER; |
|
| 42 | + $PROXY_PASS = empty($conf->global->MAIN_PROXY_PASS) ? 0 : $conf->global->MAIN_PROXY_PASS; |
|
| 43 | 43 | |
| 44 | 44 | dol_syslog("getURLContent postorget=".$postorget." URL=".$url." param=".$param); |
| 45 | 45 | |
@@ -54,45 +54,45 @@ discard block |
||
| 54 | 54 | curl_setopt($ch, CURLOPT_VERBOSE, 1); |
| 55 | 55 | curl_setopt($ch, CURLOPT_USERAGENT, 'Dolibarr geturl function'); |
| 56 | 56 | |
| 57 | - @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false)); // We use @ here because this may return warning if safe mode is on or open_basedir is on |
|
| 57 | + @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation ?true:false)); // We use @ here because this may return warning if safe mode is on or open_basedir is on |
|
| 58 | 58 | |
| 59 | 59 | if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders); |
| 60 | - curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it |
|
| 60 | + curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it |
|
| 61 | 61 | |
| 62 | 62 | // By default use tls decied by PHP. |
| 63 | 63 | // You can force, if supported a version like TLSv1 or TLSv1.2 |
| 64 | - if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION); |
|
| 64 | + if (!empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION); |
|
| 65 | 65 | //curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2 |
| 66 | 66 | |
| 67 | 67 | //turning off the server and peer verification(TrustManager Concept). |
| 68 | 68 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 69 | 69 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 70 | 70 | |
| 71 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT); |
|
| 72 | - curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT); |
|
| 71 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT); |
|
| 72 | + curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT); |
|
| 73 | 73 | |
| 74 | 74 | //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); // PHP 5.5 |
| 75 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // We want response |
|
| 75 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // We want response |
|
| 76 | 76 | if ($postorget == 'POST') |
| 77 | 77 | { |
| 78 | - curl_setopt($ch, CURLOPT_POST, 1); // POST |
|
| 79 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields |
|
| 78 | + curl_setopt($ch, CURLOPT_POST, 1); // POST |
|
| 79 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields |
|
| 80 | 80 | } |
| 81 | 81 | else if ($postorget == 'PUT') |
| 82 | 82 | { |
| 83 | 83 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
| 84 | - if (! is_array($param)) parse_str($param, $array_param); |
|
| 84 | + if (!is_array($param)) parse_str($param, $array_param); |
|
| 85 | 85 | else |
| 86 | 86 | { |
| 87 | 87 | dol_syslog("parameter param must be a string", LOG_WARNING); |
| 88 | - $array_param=$param; |
|
| 88 | + $array_param = $param; |
|
| 89 | 89 | } |
| 90 | - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields |
|
| 90 | + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields |
|
| 91 | 91 | } |
| 92 | 92 | else if ($postorget == 'PUTALREADYFORMATED') |
| 93 | 93 | { |
| 94 | 94 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
| 95 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string |
|
| 95 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string |
|
| 96 | 96 | } |
| 97 | 97 | else if ($postorget == 'HEAD') |
| 98 | 98 | { |
@@ -101,42 +101,42 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | else if ($postorget == 'DELETE') |
| 103 | 103 | { |
| 104 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST |
|
| 104 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST |
|
| 105 | 105 | } |
| 106 | 106 | else |
| 107 | 107 | { |
| 108 | - curl_setopt($ch, CURLOPT_POST, 0); // GET |
|
| 108 | + curl_setopt($ch, CURLOPT_POST, 0); // GET |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | //if USE_PROXY constant set at begin of this method. |
| 112 | 112 | if ($USE_PROXY) |
| 113 | 113 | { |
| 114 | - dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS); |
|
| 114 | + dol_syslog("getURLContent set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS); |
|
| 115 | 115 | //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10 |
| 116 | - curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT); |
|
| 117 | - if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS); |
|
| 116 | + curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT); |
|
| 117 | + if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | //getting response from server |
| 121 | 121 | $response = curl_exec($ch); |
| 122 | 122 | |
| 123 | - $request = curl_getinfo($ch, CURLINFO_HEADER_OUT); // Reading of request must be done after sending request |
|
| 123 | + $request = curl_getinfo($ch, CURLINFO_HEADER_OUT); // Reading of request must be done after sending request |
|
| 124 | 124 | |
| 125 | 125 | dol_syslog("getURLContent request=".$request); |
| 126 | 126 | //dol_syslog("getURLContent response =".response); // This may contains binary data, so we dont output it |
| 127 | - dol_syslog("getURLContent response size=".strlen($response)); // This may contains binary data, so we dont output it |
|
| 127 | + dol_syslog("getURLContent response size=".strlen($response)); // This may contains binary data, so we dont output it |
|
| 128 | 128 | |
| 129 | - $rep=array(); |
|
| 129 | + $rep = array(); |
|
| 130 | 130 | if (curl_errno($ch)) |
| 131 | 131 | { |
| 132 | 132 | // Ad keys to $rep |
| 133 | - $rep['content']=$response; |
|
| 133 | + $rep['content'] = $response; |
|
| 134 | 134 | |
| 135 | 135 | // moving to display page to display curl errors |
| 136 | - $rep['curl_error_no']=curl_errno($ch); |
|
| 137 | - $rep['curl_error_msg']=curl_error($ch); |
|
| 136 | + $rep['curl_error_no'] = curl_errno($ch); |
|
| 137 | + $rep['curl_error_msg'] = curl_error($ch); |
|
| 138 | 138 | |
| 139 | - dol_syslog("getURLContent response array is ".join(',',$rep)); |
|
| 139 | + dol_syslog("getURLContent response array is ".join(',', $rep)); |
|
| 140 | 140 | } |
| 141 | 141 | else |
| 142 | 142 | { |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | dol_syslog("getURLContent http_code=".$rep['http_code']); |
| 150 | 150 | |
| 151 | 151 | // Add more keys to $rep |
| 152 | - $rep['content']=$response; |
|
| 153 | - $rep['curl_error_no']=''; |
|
| 154 | - $rep['curl_error_msg']=''; |
|
| 152 | + $rep['content'] = $response; |
|
| 153 | + $rep['curl_error_no'] = ''; |
|
| 154 | + $rep['curl_error_msg'] = ''; |
|
| 155 | 155 | |
| 156 | 156 | //closing the curl |
| 157 | 157 | curl_close($ch); |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function getDomainFromURL($url) |
| 172 | 172 | { |
| 173 | - $tmpdomain = preg_replace('/^https?:\/\//i', '', $url); // Remove http(s):// |
|
| 174 | - $tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after domain |
|
| 175 | - $tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove first level domain (.com, .net, ...) |
|
| 176 | - $tmpdomain = preg_replace('/^[^\.]+\./', '', $tmpdomain); // Remove part www. before domain name |
|
| 173 | + $tmpdomain = preg_replace('/^https?:\/\//i', '', $url); // Remove http(s):// |
|
| 174 | + $tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after domain |
|
| 175 | + $tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove first level domain (.com, .net, ...) |
|
| 176 | + $tmpdomain = preg_replace('/^[^\.]+\./', '', $tmpdomain); // Remove part www. before domain name |
|
| 177 | 177 | |
| 178 | 178 | return $tmpdomain; |
| 179 | 179 | } |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function getRootURLFromURL($url) |
| 190 | 190 | { |
| 191 | - $prefix=''; |
|
| 191 | + $prefix = ''; |
|
| 192 | 192 | $tmpurl = $url; |
| 193 | 193 | if (preg_match('/^(https?:\/\/)/i', $tmpurl, $reg)) $prefix = $reg[1]; |
| 194 | - $tmpurl = preg_replace('/^https?:\/\//i', '', $tmpurl); // Remove http(s):// |
|
| 195 | - $tmpurl = preg_replace('/\/.*$/i', '', $tmpurl); // Remove part after domain |
|
| 194 | + $tmpurl = preg_replace('/^https?:\/\//i', '', $tmpurl); // Remove http(s):// |
|
| 195 | + $tmpurl = preg_replace('/\/.*$/i', '', $tmpurl); // Remove part after domain |
|
| 196 | 196 | |
| 197 | 197 | return $prefix.$tmpurl; |
| 198 | 198 | } |
@@ -56,12 +56,16 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false)); // We use @ here because this may return warning if safe mode is on or open_basedir is on |
| 58 | 58 | |
| 59 | - if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders); |
|
| 59 | + if (count($addheaders)) { |
|
| 60 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders); |
|
| 61 | + } |
|
| 60 | 62 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it |
| 61 | 63 | |
| 62 | 64 | // By default use tls decied by PHP. |
| 63 | 65 | // You can force, if supported a version like TLSv1 or TLSv1.2 |
| 64 | - if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION); |
|
| 66 | + if (! empty($conf->global->MAIN_CURL_SSLVERSION)) { |
|
| 67 | + curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION); |
|
| 68 | + } |
|
| 65 | 69 | //curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2 |
| 66 | 70 | |
| 67 | 71 | //turning off the server and peer verification(TrustManager Concept). |
@@ -77,33 +81,29 @@ discard block |
||
| 77 | 81 | { |
| 78 | 82 | curl_setopt($ch, CURLOPT_POST, 1); // POST |
| 79 | 83 | curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields |
| 80 | - } |
|
| 81 | - else if ($postorget == 'PUT') |
|
| 84 | + } else if ($postorget == 'PUT') |
|
| 82 | 85 | { |
| 83 | 86 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
| 84 | - if (! is_array($param)) parse_str($param, $array_param); |
|
| 85 | - else |
|
| 87 | + if (! is_array($param)) { |
|
| 88 | + parse_str($param, $array_param); |
|
| 89 | + } else |
|
| 86 | 90 | { |
| 87 | 91 | dol_syslog("parameter param must be a string", LOG_WARNING); |
| 88 | 92 | $array_param=$param; |
| 89 | 93 | } |
| 90 | 94 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields |
| 91 | - } |
|
| 92 | - else if ($postorget == 'PUTALREADYFORMATED') |
|
| 95 | + } else if ($postorget == 'PUTALREADYFORMATED') |
|
| 93 | 96 | { |
| 94 | 97 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' |
| 95 | 98 | curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string |
| 96 | - } |
|
| 97 | - else if ($postorget == 'HEAD') |
|
| 99 | + } else if ($postorget == 'HEAD') |
|
| 98 | 100 | { |
| 99 | 101 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD' |
| 100 | 102 | curl_setopt($ch, CURLOPT_NOBODY, true); |
| 101 | - } |
|
| 102 | - else if ($postorget == 'DELETE') |
|
| 103 | + } else if ($postorget == 'DELETE') |
|
| 103 | 104 | { |
| 104 | 105 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST |
| 105 | - } |
|
| 106 | - else |
|
| 106 | + } else |
|
| 107 | 107 | { |
| 108 | 108 | curl_setopt($ch, CURLOPT_POST, 0); // GET |
| 109 | 109 | } |
@@ -114,7 +114,9 @@ discard block |
||
| 114 | 114 | dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS); |
| 115 | 115 | //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10 |
| 116 | 116 | curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT); |
| 117 | - if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS); |
|
| 117 | + if ($PROXY_USER) { |
|
| 118 | + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS); |
|
| 119 | + } |
|
| 118 | 120 | } |
| 119 | 121 | |
| 120 | 122 | //getting response from server |
@@ -137,8 +139,7 @@ discard block |
||
| 137 | 139 | $rep['curl_error_msg']=curl_error($ch); |
| 138 | 140 | |
| 139 | 141 | dol_syslog("getURLContent response array is ".join(',',$rep)); |
| 140 | - } |
|
| 141 | - else |
|
| 142 | + } else |
|
| 142 | 143 | { |
| 143 | 144 | $info = curl_getinfo($ch); |
| 144 | 145 | |
@@ -190,7 +191,9 @@ discard block |
||
| 190 | 191 | { |
| 191 | 192 | $prefix=''; |
| 192 | 193 | $tmpurl = $url; |
| 193 | - if (preg_match('/^(https?:\/\/)/i', $tmpurl, $reg)) $prefix = $reg[1]; |
|
| 194 | + if (preg_match('/^(https?:\/\/)/i', $tmpurl, $reg)) { |
|
| 195 | + $prefix = $reg[1]; |
|
| 196 | + } |
|
| 194 | 197 | $tmpurl = preg_replace('/^https?:\/\//i', '', $tmpurl); // Remove http(s):// |
| 195 | 198 | $tmpurl = preg_replace('/\/.*$/i', '', $tmpurl); // Remove part after domain |
| 196 | 199 | |
@@ -46,37 +46,37 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval'])) |
| 48 | 48 | { |
| 49 | - dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.'); |
|
| 50 | - return -1; |
|
| 49 | + dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.'); |
|
| 50 | + return -1; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Check parameters |
| 54 | 54 | if (count($addfieldentry) > 0) |
| 55 | 55 | { |
| 56 | 56 | if (empty($addfieldentry['name'])) |
| 57 | - { |
|
| 58 | - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors'); |
|
| 59 | - return -2; |
|
| 60 | - } |
|
| 57 | + { |
|
| 58 | + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors'); |
|
| 59 | + return -2; |
|
| 60 | + } |
|
| 61 | 61 | if (empty($addfieldentry['label'])) |
| 62 | - { |
|
| 63 | - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
|
| 64 | - return -2; |
|
| 65 | - } |
|
| 62 | + { |
|
| 63 | + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
|
| 64 | + return -2; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if (! preg_match('/^(price|boolean|sellist|integer|date|timestamp|varchar|double|text|html)/', $addfieldentry['type'])) |
|
| 67 | + if (! preg_match('/^(price|boolean|sellist|integer|date|timestamp|varchar|double|text|html)/', $addfieldentry['type'])) |
|
| 68 | 68 | |
| 69 | - { |
|
| 70 | - setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors'); |
|
| 71 | - return -2; |
|
| 72 | - } |
|
| 69 | + { |
|
| 70 | + setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors'); |
|
| 71 | + return -2; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $pathoffiletoeditsrc=$readdir.'/class/'.strtolower($objectname).'.class.php'; |
| 76 | 76 | $pathoffiletoedittarget=$destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : ''); |
| 77 | 77 | if (! dol_is_file($pathoffiletoeditsrc)) |
| 78 | 78 | { |
| 79 | - $langs->load("errors"); |
|
| 79 | + $langs->load("errors"); |
|
| 80 | 80 | setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); |
| 81 | 81 | return -3; |
| 82 | 82 | } |
@@ -96,21 +96,21 @@ discard block |
||
| 96 | 96 | // Edit class files |
| 97 | 97 | $contentclass = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); |
| 98 | 98 | |
| 99 | - // Update ->fields (add or remove entries) |
|
| 99 | + // Update ->fields (add or remove entries) |
|
| 100 | 100 | if (count($object->fields)) |
| 101 | 101 | { |
| 102 | - if (is_array($addfieldentry) && count($addfieldentry)) |
|
| 103 | - { |
|
| 104 | - $name=$addfieldentry['name']; |
|
| 105 | - unset($addfieldentry['name']); |
|
| 106 | - |
|
| 107 | - $object->fields[$name]=$addfieldentry; |
|
| 108 | - } |
|
| 109 | - if (! empty($delfieldentry)) |
|
| 110 | - { |
|
| 111 | - $name=$delfieldentry; |
|
| 112 | - unset($object->fields[$name]); |
|
| 113 | - } |
|
| 102 | + if (is_array($addfieldentry) && count($addfieldentry)) |
|
| 103 | + { |
|
| 104 | + $name=$addfieldentry['name']; |
|
| 105 | + unset($addfieldentry['name']); |
|
| 106 | + |
|
| 107 | + $object->fields[$name]=$addfieldentry; |
|
| 108 | + } |
|
| 109 | + if (! empty($delfieldentry)) |
|
| 110 | + { |
|
| 111 | + $name=$delfieldentry; |
|
| 112 | + unset($object->fields[$name]); |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | dol_sort_array($object->fields, 'position'); |
@@ -143,28 +143,28 @@ discard block |
||
| 143 | 143 | if ($val['showoncombobox']) $texttoinsert.= " 'showoncombobox'=>'".$val['showoncombobox']."',"; |
| 144 | 144 | if ($val['arrayofkeyval']) |
| 145 | 145 | { |
| 146 | - $texttoinsert.= " 'arrayofkeyval'=>array("; |
|
| 147 | - $i=0; |
|
| 148 | - foreach($val['arrayofkeyval'] as $key2 => $val2) |
|
| 149 | - { |
|
| 150 | - if ($i) $texttoinsert.=", "; |
|
| 151 | - $texttoinsert.="'".$key2."'=>'".$val2."'"; |
|
| 152 | - $i++; |
|
| 153 | - } |
|
| 154 | - $texttoinsert.= ")"; |
|
| 146 | + $texttoinsert.= " 'arrayofkeyval'=>array("; |
|
| 147 | + $i=0; |
|
| 148 | + foreach($val['arrayofkeyval'] as $key2 => $val2) |
|
| 149 | + { |
|
| 150 | + if ($i) $texttoinsert.=", "; |
|
| 151 | + $texttoinsert.="'".$key2."'=>'".$val2."'"; |
|
| 152 | + $i++; |
|
| 153 | + } |
|
| 154 | + $texttoinsert.= ")"; |
|
| 155 | 155 | } |
| 156 | 156 | $texttoinsert.= "),\n"; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $texttoinsert.= "\t".');'."\n"; |
| 161 | - //print ($texttoinsert);exit; |
|
| 161 | + //print ($texttoinsert);exit; |
|
| 162 | 162 | |
| 163 | 163 | if (count($object->fields)) |
| 164 | 164 | { |
| 165 | - $typetotypephp=array('integer'=>'integer', 'varchar'=>'string'); |
|
| 165 | + $typetotypephp=array('integer'=>'integer', 'varchar'=>'string'); |
|
| 166 | 166 | |
| 167 | - foreach($object->fields as $key => $val) |
|
| 167 | + foreach($object->fields as $key => $val) |
|
| 168 | 168 | { |
| 169 | 169 | $i++; |
| 170 | 170 | //$typephp=$typetotypephp[$val['type']]; |
@@ -224,22 +224,22 @@ discard block |
||
| 224 | 224 | // Edit .sql file |
| 225 | 225 | $pathoffiletoeditsrc=$readdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'; |
| 226 | 226 | $pathoffiletoedittarget=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : ''); |
| 227 | - if (! dol_is_file($pathoffiletoeditsrc)) |
|
| 227 | + if (! dol_is_file($pathoffiletoeditsrc)) |
|
| 228 | 228 | { |
| 229 | - $langs->load("errors"); |
|
| 230 | - setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); |
|
| 231 | - return -1; |
|
| 229 | + $langs->load("errors"); |
|
| 230 | + setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); |
|
| 231 | + return -1; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // Load object from myobject.class.php |
| 235 | 235 | try |
| 236 | 236 | { |
| 237 | - if (! is_object($object)) |
|
| 238 | - { |
|
| 239 | - include_once $pathoffiletoclasssrc; |
|
| 240 | - if (class_exists($objectname)) $object=new $objectname($db); |
|
| 241 | - else return -1; |
|
| 242 | - } |
|
| 237 | + if (! is_object($object)) |
|
| 238 | + { |
|
| 239 | + include_once $pathoffiletoclasssrc; |
|
| 240 | + if (class_exists($objectname)) $object=new $objectname($db); |
|
| 241 | + else return -1; |
|
| 242 | + } |
|
| 243 | 243 | } |
| 244 | 244 | catch(Exception $e) |
| 245 | 245 | { |
@@ -270,12 +270,12 @@ discard block |
||
| 270 | 270 | if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; |
| 271 | 271 | else |
| 272 | 272 | { |
| 273 | - if ($val['default'] != '') |
|
| 274 | - { |
|
| 275 | - if (preg_match('/^null$/i', $val['default'])) $texttoinsert.= " DEFAULT NULL"; |
|
| 276 | - else if (preg_match('/varchar/', $type )) $texttoinsert.= " DEFAULT '".$db->escape($val['default'])."'"; |
|
| 277 | - else $texttoinsert.= (($val['default'] > 0)?' DEFAULT '.$val['default']:''); |
|
| 278 | - } |
|
| 273 | + if ($val['default'] != '') |
|
| 274 | + { |
|
| 275 | + if (preg_match('/^null$/i', $val['default'])) $texttoinsert.= " DEFAULT NULL"; |
|
| 276 | + else if (preg_match('/varchar/', $type )) $texttoinsert.= " DEFAULT '".$db->escape($val['default'])."'"; |
|
| 277 | + else $texttoinsert.= (($val['default'] > 0)?' DEFAULT '.$val['default']:''); |
|
| 278 | + } |
|
| 279 | 279 | } |
| 280 | 280 | $texttoinsert.= (($val['notnull'] > 0)?' NOT NULL':''); |
| 281 | 281 | if ($i < count($object->fields)) $texttoinsert.=", "; |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | $result = file_put_contents($pathoffiletoedittarget, $contentsql); |
| 290 | 290 | if ($result) |
| 291 | 291 | { |
| 292 | - @chmod($pathoffiletoedittarget, octdec($newmask)); |
|
| 292 | + @chmod($pathoffiletoedittarget, octdec($newmask)); |
|
| 293 | 293 | } |
| 294 | 294 | else |
| 295 | 295 | { |
| 296 | - $error++; |
|
| 296 | + $error++; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Edit .key.sql file |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | if (! empty($val['foreignkey'])) |
| 318 | 318 | { |
| 319 | - $tmp=explode('.',$val['foreignkey']); |
|
| 320 | - if (! empty($tmp[0]) && ! empty($tmp[1])) |
|
| 321 | - { |
|
| 322 | - $texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");"; |
|
| 323 | - $texttoinsert.= "\n"; |
|
| 324 | - } |
|
| 319 | + $tmp=explode('.',$val['foreignkey']); |
|
| 320 | + if (! empty($tmp[0]) && ! empty($tmp[1])) |
|
| 321 | + { |
|
| 322 | + $texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");"; |
|
| 323 | + $texttoinsert.= "\n"; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -334,11 +334,11 @@ discard block |
||
| 334 | 334 | $result2 = file_put_contents($pathoffiletoedittarget, $contentsql); |
| 335 | 335 | if ($result) |
| 336 | 336 | { |
| 337 | - @chmod($pathoffiletoedittarget, octdec($newmask)); |
|
| 337 | + @chmod($pathoffiletoedittarget, octdec($newmask)); |
|
| 338 | 338 | } |
| 339 | 339 | else |
| 340 | 340 | { |
| 341 | - $error++; |
|
| 341 | + $error++; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | return $error ? -1 : 1; |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | * @return int|object <=0 if KO, Object if OK |
| 38 | 38 | * @see rebuildObjectSql |
| 39 | 39 | */ |
| 40 | -function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array() ,$delfieldentry='') |
|
| 40 | +function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = '', $addfieldentry = array(), $delfieldentry = '') |
|
| 41 | 41 | { |
| 42 | 42 | global $db, $langs; |
| 43 | 43 | |
| 44 | 44 | if (empty($objectname)) return -1; |
| 45 | - if (empty($readdir)) $readdir=$destdir; |
|
| 45 | + if (empty($readdir)) $readdir = $destdir; |
|
| 46 | 46 | |
| 47 | - if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval'])) |
|
| 47 | + if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) |
|
| 48 | 48 | { |
| 49 | 49 | dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.'); |
| 50 | 50 | return -1; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | return -2; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if (! preg_match('/^(price|boolean|sellist|integer|date|timestamp|varchar|double|text|html)/', $addfieldentry['type'])) |
|
| 67 | + if (!preg_match('/^(price|boolean|sellist|integer|date|timestamp|varchar|double|text|html)/', $addfieldentry['type'])) |
|
| 68 | 68 | |
| 69 | 69 | { |
| 70 | 70 | setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors'); |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $pathoffiletoeditsrc=$readdir.'/class/'.strtolower($objectname).'.class.php'; |
|
| 76 | - $pathoffiletoedittarget=$destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : ''); |
|
| 77 | - if (! dol_is_file($pathoffiletoeditsrc)) |
|
| 75 | + $pathoffiletoeditsrc = $readdir.'/class/'.strtolower($objectname).'.class.php'; |
|
| 76 | + $pathoffiletoedittarget = $destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : ''); |
|
| 77 | + if (!dol_is_file($pathoffiletoeditsrc)) |
|
| 78 | 78 | { |
| 79 | 79 | $langs->load("errors"); |
| 80 | 80 | setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | try |
| 88 | 88 | { |
| 89 | 89 | include_once $pathoffiletoeditsrc; |
| 90 | - if (class_exists($objectname)) $object=new $objectname($db); |
|
| 90 | + if (class_exists($objectname)) $object = new $objectname($db); |
|
| 91 | 91 | else return -4; |
| 92 | 92 | |
| 93 | 93 | // Backup old file |
@@ -101,83 +101,83 @@ discard block |
||
| 101 | 101 | { |
| 102 | 102 | if (is_array($addfieldentry) && count($addfieldentry)) |
| 103 | 103 | { |
| 104 | - $name=$addfieldentry['name']; |
|
| 104 | + $name = $addfieldentry['name']; |
|
| 105 | 105 | unset($addfieldentry['name']); |
| 106 | 106 | |
| 107 | - $object->fields[$name]=$addfieldentry; |
|
| 107 | + $object->fields[$name] = $addfieldentry; |
|
| 108 | 108 | } |
| 109 | - if (! empty($delfieldentry)) |
|
| 109 | + if (!empty($delfieldentry)) |
|
| 110 | 110 | { |
| 111 | - $name=$delfieldentry; |
|
| 111 | + $name = $delfieldentry; |
|
| 112 | 112 | unset($object->fields[$name]); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | dol_sort_array($object->fields, 'position'); |
| 117 | 117 | |
| 118 | - $i=0; |
|
| 118 | + $i = 0; |
|
| 119 | 119 | $texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n"; |
| 120 | - $texttoinsert.= "\t".'/**'."\n"; |
|
| 121 | - $texttoinsert.= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n"; |
|
| 122 | - $texttoinsert.= "\t".' */'."\n"; |
|
| 123 | - $texttoinsert.= "\t".'public $fields=array('."\n"; |
|
| 120 | + $texttoinsert .= "\t".'/**'."\n"; |
|
| 121 | + $texttoinsert .= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n"; |
|
| 122 | + $texttoinsert .= "\t".' */'."\n"; |
|
| 123 | + $texttoinsert .= "\t".'public $fields=array('."\n"; |
|
| 124 | 124 | |
| 125 | 125 | if (count($object->fields)) |
| 126 | 126 | { |
| 127 | 127 | |
| 128 | - foreach($object->fields as $key => $val) |
|
| 128 | + foreach ($object->fields as $key => $val) |
|
| 129 | 129 | { |
| 130 | 130 | $i++; |
| 131 | - $texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; |
|
| 132 | - $texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).","; |
|
| 133 | - $texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).","; |
|
| 134 | - $texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).","; |
|
| 135 | - $texttoinsert.= " 'notnull'=>".($val['notnull']!=''?$val['notnull']:-1).","; |
|
| 136 | - if ($val['default']) $texttoinsert.= " 'default'=>'".$val['default']."',"; |
|
| 137 | - if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; |
|
| 138 | - if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; |
|
| 139 | - if ($val['isameasure']) $texttoinsert.= " 'isameasure'=>'".$val['isameasure']."',"; |
|
| 140 | - if ($val['foreignkey']) $texttoinsert.= " 'foreignkey'=>'".$val['foreignkey']."',"; |
|
| 141 | - if ($val['help']) $texttoinsert.= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; |
|
| 142 | - if ($val['comment']) $texttoinsert.= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\","; |
|
| 143 | - if ($val['showoncombobox']) $texttoinsert.= " 'showoncombobox'=>'".$val['showoncombobox']."',"; |
|
| 131 | + $texttoinsert .= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; |
|
| 132 | + $texttoinsert .= " 'enabled'=>".($val['enabled'] != '' ? $val['enabled'] : 1).","; |
|
| 133 | + $texttoinsert .= " 'visible'=>".($val['visible'] != '' ? $val['visible'] : -1).","; |
|
| 134 | + $texttoinsert .= " 'position'=>".($val['position'] != '' ? $val['position'] : 50).","; |
|
| 135 | + $texttoinsert .= " 'notnull'=>".($val['notnull'] != '' ? $val['notnull'] : -1).","; |
|
| 136 | + if ($val['default']) $texttoinsert .= " 'default'=>'".$val['default']."',"; |
|
| 137 | + if ($val['index']) $texttoinsert .= " 'index'=>".$val['index'].","; |
|
| 138 | + if ($val['searchall']) $texttoinsert .= " 'searchall'=>".$val['searchall'].","; |
|
| 139 | + if ($val['isameasure']) $texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',"; |
|
| 140 | + if ($val['foreignkey']) $texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',"; |
|
| 141 | + if ($val['help']) $texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; |
|
| 142 | + if ($val['comment']) $texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\","; |
|
| 143 | + if ($val['showoncombobox']) $texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',"; |
|
| 144 | 144 | if ($val['arrayofkeyval']) |
| 145 | 145 | { |
| 146 | - $texttoinsert.= " 'arrayofkeyval'=>array("; |
|
| 147 | - $i=0; |
|
| 148 | - foreach($val['arrayofkeyval'] as $key2 => $val2) |
|
| 146 | + $texttoinsert .= " 'arrayofkeyval'=>array("; |
|
| 147 | + $i = 0; |
|
| 148 | + foreach ($val['arrayofkeyval'] as $key2 => $val2) |
|
| 149 | 149 | { |
| 150 | - if ($i) $texttoinsert.=", "; |
|
| 151 | - $texttoinsert.="'".$key2."'=>'".$val2."'"; |
|
| 150 | + if ($i) $texttoinsert .= ", "; |
|
| 151 | + $texttoinsert .= "'".$key2."'=>'".$val2."'"; |
|
| 152 | 152 | $i++; |
| 153 | 153 | } |
| 154 | - $texttoinsert.= ")"; |
|
| 154 | + $texttoinsert .= ")"; |
|
| 155 | 155 | } |
| 156 | - $texttoinsert.= "),\n"; |
|
| 156 | + $texttoinsert .= "),\n"; |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - $texttoinsert.= "\t".');'."\n"; |
|
| 160 | + $texttoinsert .= "\t".');'."\n"; |
|
| 161 | 161 | //print ($texttoinsert);exit; |
| 162 | 162 | |
| 163 | 163 | if (count($object->fields)) |
| 164 | 164 | { |
| 165 | - $typetotypephp=array('integer'=>'integer', 'varchar'=>'string'); |
|
| 165 | + $typetotypephp = array('integer'=>'integer', 'varchar'=>'string'); |
|
| 166 | 166 | |
| 167 | - foreach($object->fields as $key => $val) |
|
| 167 | + foreach ($object->fields as $key => $val) |
|
| 168 | 168 | { |
| 169 | 169 | $i++; |
| 170 | 170 | //$typephp=$typetotypephp[$val['type']]; |
| 171 | - $texttoinsert.= "\t".'public $'.$key.";"; |
|
| 171 | + $texttoinsert .= "\t".'public $'.$key.";"; |
|
| 172 | 172 | //if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; |
| 173 | 173 | //if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; |
| 174 | 174 | //$texttoinsert.= ($val['notnull']?' NOT NULL':''); |
| 175 | 175 | //if ($i < count($object->fields)) $texttoinsert.=";"; |
| 176 | - $texttoinsert.= "\n"; |
|
| 176 | + $texttoinsert .= "\n"; |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - $texttoinsert.= "\t".'// END MODULEBUILDER PROPERTIES'; |
|
| 180 | + $texttoinsert .= "\t".'// END MODULEBUILDER PROPERTIES'; |
|
| 181 | 181 | |
| 182 | 182 | //print($texttoinsert);exit; |
| 183 | 183 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | return $object; |
| 193 | 193 | } |
| 194 | - catch(Exception $e) |
|
| 194 | + catch (Exception $e) |
|
| 195 | 195 | { |
| 196 | 196 | print $e->getMessage(); |
| 197 | 197 | return -5; |
@@ -210,21 +210,21 @@ discard block |
||
| 210 | 210 | * @return int <=0 if KO, >0 if OK |
| 211 | 211 | * @see rebuildObjectClass |
| 212 | 212 | */ |
| 213 | -function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $object=null) |
|
| 213 | +function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '', $object = null) |
|
| 214 | 214 | { |
| 215 | 215 | global $db, $langs; |
| 216 | 216 | |
| 217 | 217 | $error = 0; |
| 218 | 218 | |
| 219 | 219 | if (empty($objectname)) return -1; |
| 220 | - if (empty($readdir)) $readdir=$destdir; |
|
| 220 | + if (empty($readdir)) $readdir = $destdir; |
|
| 221 | 221 | |
| 222 | - $pathoffiletoclasssrc=$readdir.'/class/'.strtolower($objectname).'.class.php'; |
|
| 222 | + $pathoffiletoclasssrc = $readdir.'/class/'.strtolower($objectname).'.class.php'; |
|
| 223 | 223 | |
| 224 | 224 | // Edit .sql file |
| 225 | - $pathoffiletoeditsrc=$readdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'; |
|
| 226 | - $pathoffiletoedittarget=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : ''); |
|
| 227 | - if (! dol_is_file($pathoffiletoeditsrc)) |
|
| 225 | + $pathoffiletoeditsrc = $readdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'; |
|
| 226 | + $pathoffiletoedittarget = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : ''); |
|
| 227 | + if (!dol_is_file($pathoffiletoeditsrc)) |
|
| 228 | 228 | { |
| 229 | 229 | $langs->load("errors"); |
| 230 | 230 | setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); |
@@ -234,14 +234,14 @@ discard block |
||
| 234 | 234 | // Load object from myobject.class.php |
| 235 | 235 | try |
| 236 | 236 | { |
| 237 | - if (! is_object($object)) |
|
| 237 | + if (!is_object($object)) |
|
| 238 | 238 | { |
| 239 | 239 | include_once $pathoffiletoclasssrc; |
| 240 | - if (class_exists($objectname)) $object=new $objectname($db); |
|
| 240 | + if (class_exists($objectname)) $object = new $objectname($db); |
|
| 241 | 241 | else return -1; |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | - catch(Exception $e) |
|
| 244 | + catch (Exception $e) |
|
| 245 | 245 | { |
| 246 | 246 | print $e->getMessage(); |
| 247 | 247 | } |
@@ -251,38 +251,38 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | $contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); |
| 253 | 253 | |
| 254 | - $i=0; |
|
| 254 | + $i = 0; |
|
| 255 | 255 | $texttoinsert = '-- BEGIN MODULEBUILDER FIELDS'."\n"; |
| 256 | 256 | if (count($object->fields)) |
| 257 | 257 | { |
| 258 | - foreach($object->fields as $key => $val) |
|
| 258 | + foreach ($object->fields as $key => $val) |
|
| 259 | 259 | { |
| 260 | 260 | $i++; |
| 261 | 261 | |
| 262 | 262 | $type = $val['type']; |
| 263 | - $type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php' |
|
| 263 | + $type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php' |
|
| 264 | 264 | |
| 265 | - if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database |
|
| 266 | - else if ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database |
|
| 265 | + if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database |
|
| 266 | + else if ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database |
|
| 267 | 267 | else if ($type == 'link' || $type == 'sellist') $type = 'integer'; |
| 268 | - $texttoinsert.= "\t".$key." ".$type; |
|
| 269 | - if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; |
|
| 270 | - if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; |
|
| 268 | + $texttoinsert .= "\t".$key." ".$type; |
|
| 269 | + if ($key == 'rowid') $texttoinsert .= ' AUTO_INCREMENT PRIMARY KEY'; |
|
| 270 | + if ($key == 'entity') $texttoinsert .= ' DEFAULT 1'; |
|
| 271 | 271 | else |
| 272 | 272 | { |
| 273 | 273 | if ($val['default'] != '') |
| 274 | 274 | { |
| 275 | - if (preg_match('/^null$/i', $val['default'])) $texttoinsert.= " DEFAULT NULL"; |
|
| 276 | - else if (preg_match('/varchar/', $type )) $texttoinsert.= " DEFAULT '".$db->escape($val['default'])."'"; |
|
| 277 | - else $texttoinsert.= (($val['default'] > 0)?' DEFAULT '.$val['default']:''); |
|
| 275 | + if (preg_match('/^null$/i', $val['default'])) $texttoinsert .= " DEFAULT NULL"; |
|
| 276 | + else if (preg_match('/varchar/', $type)) $texttoinsert .= " DEFAULT '".$db->escape($val['default'])."'"; |
|
| 277 | + else $texttoinsert .= (($val['default'] > 0) ? ' DEFAULT '.$val['default'] : ''); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | - $texttoinsert.= (($val['notnull'] > 0)?' NOT NULL':''); |
|
| 281 | - if ($i < count($object->fields)) $texttoinsert.=", "; |
|
| 282 | - $texttoinsert.= "\n"; |
|
| 280 | + $texttoinsert .= (($val['notnull'] > 0) ? ' NOT NULL' : ''); |
|
| 281 | + if ($i < count($object->fields)) $texttoinsert .= ", "; |
|
| 282 | + $texttoinsert .= "\n"; |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | - $texttoinsert.= "\t".'-- END MODULEBUILDER FIELDS'; |
|
| 285 | + $texttoinsert .= "\t".'-- END MODULEBUILDER FIELDS'; |
|
| 286 | 286 | |
| 287 | 287 | $contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql); |
| 288 | 288 | |
@@ -297,35 +297,35 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Edit .key.sql file |
| 300 | - $pathoffiletoeditsrc=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'; |
|
| 301 | - $pathoffiletoedittarget=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'.($readdir != $destdir ? '.new' : ''); |
|
| 300 | + $pathoffiletoeditsrc = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'; |
|
| 301 | + $pathoffiletoedittarget = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'.($readdir != $destdir ? '.new' : ''); |
|
| 302 | 302 | |
| 303 | 303 | $contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); |
| 304 | 304 | |
| 305 | - $i=0; |
|
| 305 | + $i = 0; |
|
| 306 | 306 | $texttoinsert = '-- BEGIN MODULEBUILDER INDEXES'."\n"; |
| 307 | 307 | if (count($object->fields)) |
| 308 | 308 | { |
| 309 | - foreach($object->fields as $key => $val) |
|
| 309 | + foreach ($object->fields as $key => $val) |
|
| 310 | 310 | { |
| 311 | 311 | $i++; |
| 312 | - if (! empty($val['index'])) |
|
| 312 | + if (!empty($val['index'])) |
|
| 313 | 313 | { |
| 314 | - $texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD INDEX idx_".strtolower($module).'_'.strtolower($objectname)."_".$key." (".$key.");"; |
|
| 315 | - $texttoinsert.= "\n"; |
|
| 314 | + $texttoinsert .= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD INDEX idx_".strtolower($module).'_'.strtolower($objectname)."_".$key." (".$key.");"; |
|
| 315 | + $texttoinsert .= "\n"; |
|
| 316 | 316 | } |
| 317 | - if (! empty($val['foreignkey'])) |
|
| 317 | + if (!empty($val['foreignkey'])) |
|
| 318 | 318 | { |
| 319 | - $tmp=explode('.',$val['foreignkey']); |
|
| 320 | - if (! empty($tmp[0]) && ! empty($tmp[1])) |
|
| 319 | + $tmp = explode('.', $val['foreignkey']); |
|
| 320 | + if (!empty($tmp[0]) && !empty($tmp[1])) |
|
| 321 | 321 | { |
| 322 | - $texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");"; |
|
| 323 | - $texttoinsert.= "\n"; |
|
| 322 | + $texttoinsert .= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");"; |
|
| 323 | + $texttoinsert .= "\n"; |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | - $texttoinsert.= '-- END MODULEBUILDER INDEXES'; |
|
| 328 | + $texttoinsert .= '-- END MODULEBUILDER INDEXES'; |
|
| 329 | 329 | |
| 330 | 330 | $contentsql = preg_replace('/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql); |
| 331 | 331 | |
@@ -41,8 +41,12 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | global $db, $langs; |
| 43 | 43 | |
| 44 | - if (empty($objectname)) return -1; |
|
| 45 | - if (empty($readdir)) $readdir=$destdir; |
|
| 44 | + if (empty($objectname)) { |
|
| 45 | + return -1; |
|
| 46 | + } |
|
| 47 | + if (empty($readdir)) { |
|
| 48 | + $readdir=$destdir; |
|
| 49 | + } |
|
| 46 | 50 | |
| 47 | 51 | if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval'])) |
| 48 | 52 | { |
@@ -87,8 +91,11 @@ discard block |
||
| 87 | 91 | try |
| 88 | 92 | { |
| 89 | 93 | include_once $pathoffiletoeditsrc; |
| 90 | - if (class_exists($objectname)) $object=new $objectname($db); |
|
| 91 | - else return -4; |
|
| 94 | + if (class_exists($objectname)) { |
|
| 95 | + $object=new $objectname($db); |
|
| 96 | + } else { |
|
| 97 | + return -4; |
|
| 98 | + } |
|
| 92 | 99 | |
| 93 | 100 | // Backup old file |
| 94 | 101 | dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1); |
@@ -133,21 +140,39 @@ discard block |
||
| 133 | 140 | $texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).","; |
| 134 | 141 | $texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).","; |
| 135 | 142 | $texttoinsert.= " 'notnull'=>".($val['notnull']!=''?$val['notnull']:-1).","; |
| 136 | - if ($val['default']) $texttoinsert.= " 'default'=>'".$val['default']."',"; |
|
| 137 | - if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; |
|
| 138 | - if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; |
|
| 139 | - if ($val['isameasure']) $texttoinsert.= " 'isameasure'=>'".$val['isameasure']."',"; |
|
| 140 | - if ($val['foreignkey']) $texttoinsert.= " 'foreignkey'=>'".$val['foreignkey']."',"; |
|
| 141 | - if ($val['help']) $texttoinsert.= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; |
|
| 142 | - if ($val['comment']) $texttoinsert.= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\","; |
|
| 143 | - if ($val['showoncombobox']) $texttoinsert.= " 'showoncombobox'=>'".$val['showoncombobox']."',"; |
|
| 143 | + if ($val['default']) { |
|
| 144 | + $texttoinsert.= " 'default'=>'".$val['default']."',"; |
|
| 145 | + } |
|
| 146 | + if ($val['index']) { |
|
| 147 | + $texttoinsert.= " 'index'=>".$val['index'].","; |
|
| 148 | + } |
|
| 149 | + if ($val['searchall']) { |
|
| 150 | + $texttoinsert.= " 'searchall'=>".$val['searchall'].","; |
|
| 151 | + } |
|
| 152 | + if ($val['isameasure']) { |
|
| 153 | + $texttoinsert.= " 'isameasure'=>'".$val['isameasure']."',"; |
|
| 154 | + } |
|
| 155 | + if ($val['foreignkey']) { |
|
| 156 | + $texttoinsert.= " 'foreignkey'=>'".$val['foreignkey']."',"; |
|
| 157 | + } |
|
| 158 | + if ($val['help']) { |
|
| 159 | + $texttoinsert.= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; |
|
| 160 | + } |
|
| 161 | + if ($val['comment']) { |
|
| 162 | + $texttoinsert.= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\","; |
|
| 163 | + } |
|
| 164 | + if ($val['showoncombobox']) { |
|
| 165 | + $texttoinsert.= " 'showoncombobox'=>'".$val['showoncombobox']."',"; |
|
| 166 | + } |
|
| 144 | 167 | if ($val['arrayofkeyval']) |
| 145 | 168 | { |
| 146 | 169 | $texttoinsert.= " 'arrayofkeyval'=>array("; |
| 147 | 170 | $i=0; |
| 148 | 171 | foreach($val['arrayofkeyval'] as $key2 => $val2) |
| 149 | 172 | { |
| 150 | - if ($i) $texttoinsert.=", "; |
|
| 173 | + if ($i) { |
|
| 174 | + $texttoinsert.=", "; |
|
| 175 | + } |
|
| 151 | 176 | $texttoinsert.="'".$key2."'=>'".$val2."'"; |
| 152 | 177 | $i++; |
| 153 | 178 | } |
@@ -190,8 +215,7 @@ discard block |
||
| 190 | 215 | @chmod($pathoffiletoedittarget, octdec($newmask)); |
| 191 | 216 | |
| 192 | 217 | return $object; |
| 193 | - } |
|
| 194 | - catch(Exception $e) |
|
| 218 | + } catch(Exception $e) |
|
| 195 | 219 | { |
| 196 | 220 | print $e->getMessage(); |
| 197 | 221 | return -5; |
@@ -216,8 +240,12 @@ discard block |
||
| 216 | 240 | |
| 217 | 241 | $error = 0; |
| 218 | 242 | |
| 219 | - if (empty($objectname)) return -1; |
|
| 220 | - if (empty($readdir)) $readdir=$destdir; |
|
| 243 | + if (empty($objectname)) { |
|
| 244 | + return -1; |
|
| 245 | + } |
|
| 246 | + if (empty($readdir)) { |
|
| 247 | + $readdir=$destdir; |
|
| 248 | + } |
|
| 221 | 249 | |
| 222 | 250 | $pathoffiletoclasssrc=$readdir.'/class/'.strtolower($objectname).'.class.php'; |
| 223 | 251 | |
@@ -237,11 +265,13 @@ discard block |
||
| 237 | 265 | if (! is_object($object)) |
| 238 | 266 | { |
| 239 | 267 | include_once $pathoffiletoclasssrc; |
| 240 | - if (class_exists($objectname)) $object=new $objectname($db); |
|
| 241 | - else return -1; |
|
| 268 | + if (class_exists($objectname)) { |
|
| 269 | + $object=new $objectname($db); |
|
| 270 | + } else { |
|
| 271 | + return -1; |
|
| 272 | + } |
|
| 242 | 273 | } |
| 243 | - } |
|
| 244 | - catch(Exception $e) |
|
| 274 | + } catch(Exception $e) |
|
| 245 | 275 | { |
| 246 | 276 | print $e->getMessage(); |
| 247 | 277 | } |
@@ -262,23 +292,40 @@ discard block |
||
| 262 | 292 | $type = $val['type']; |
| 263 | 293 | $type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php' |
| 264 | 294 | |
| 265 | - if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database |
|
| 266 | - else if ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database |
|
| 267 | - else if ($type == 'link' || $type == 'sellist') $type = 'integer'; |
|
| 295 | + if ($type == 'html') { |
|
| 296 | + $type = 'text'; |
|
| 297 | + } |
|
| 298 | + // html modulebuilder type is a text type in database |
|
| 299 | + else if ($type == 'price') { |
|
| 300 | + $type = 'double'; |
|
| 301 | + } |
|
| 302 | + // html modulebuilder type is a text type in database |
|
| 303 | + else if ($type == 'link' || $type == 'sellist') { |
|
| 304 | + $type = 'integer'; |
|
| 305 | + } |
|
| 268 | 306 | $texttoinsert.= "\t".$key." ".$type; |
| 269 | - if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; |
|
| 270 | - if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; |
|
| 271 | - else |
|
| 307 | + if ($key == 'rowid') { |
|
| 308 | + $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; |
|
| 309 | + } |
|
| 310 | + if ($key == 'entity') { |
|
| 311 | + $texttoinsert.= ' DEFAULT 1'; |
|
| 312 | + } else |
|
| 272 | 313 | { |
| 273 | 314 | if ($val['default'] != '') |
| 274 | 315 | { |
| 275 | - if (preg_match('/^null$/i', $val['default'])) $texttoinsert.= " DEFAULT NULL"; |
|
| 276 | - else if (preg_match('/varchar/', $type )) $texttoinsert.= " DEFAULT '".$db->escape($val['default'])."'"; |
|
| 277 | - else $texttoinsert.= (($val['default'] > 0)?' DEFAULT '.$val['default']:''); |
|
| 316 | + if (preg_match('/^null$/i', $val['default'])) { |
|
| 317 | + $texttoinsert.= " DEFAULT NULL"; |
|
| 318 | + } else if (preg_match('/varchar/', $type )) { |
|
| 319 | + $texttoinsert.= " DEFAULT '".$db->escape($val['default'])."'"; |
|
| 320 | + } else { |
|
| 321 | + $texttoinsert.= (($val['default'] > 0)?' DEFAULT '.$val['default']:''); |
|
| 322 | + } |
|
| 278 | 323 | } |
| 279 | 324 | } |
| 280 | 325 | $texttoinsert.= (($val['notnull'] > 0)?' NOT NULL':''); |
| 281 | - if ($i < count($object->fields)) $texttoinsert.=", "; |
|
| 326 | + if ($i < count($object->fields)) { |
|
| 327 | + $texttoinsert.=", "; |
|
| 328 | + } |
|
| 282 | 329 | $texttoinsert.= "\n"; |
| 283 | 330 | } |
| 284 | 331 | } |
@@ -290,8 +337,7 @@ discard block |
||
| 290 | 337 | if ($result) |
| 291 | 338 | { |
| 292 | 339 | @chmod($pathoffiletoedittarget, octdec($newmask)); |
| 293 | - } |
|
| 294 | - else |
|
| 340 | + } else |
|
| 295 | 341 | { |
| 296 | 342 | $error++; |
| 297 | 343 | } |
@@ -335,8 +381,7 @@ discard block |
||
| 335 | 381 | if ($result) |
| 336 | 382 | { |
| 337 | 383 | @chmod($pathoffiletoedittarget, octdec($newmask)); |
| 338 | - } |
|
| 339 | - else |
|
| 384 | + } else |
|
| 340 | 385 | { |
| 341 | 386 | $error++; |
| 342 | 387 | } |
@@ -32,36 +32,36 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function member_prepare_head(Adherent $object) |
| 34 | 34 | { |
| 35 | - global $db, $langs, $conf, $user; |
|
| 36 | - |
|
| 37 | - $h = 0; |
|
| 38 | - $head = array(); |
|
| 39 | - |
|
| 40 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/card.php?rowid='.$object->id; |
|
| 41 | - $head[$h][1] = $langs->trans("Card"); |
|
| 42 | - $head[$h][2] = 'general'; |
|
| 43 | - $h++; |
|
| 44 | - |
|
| 45 | - if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_ACTIVE)) |
|
| 46 | - && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin))) |
|
| 47 | - { |
|
| 48 | - $langs->load("ldap"); |
|
| 49 | - |
|
| 50 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/ldap.php?id='.$object->id; |
|
| 51 | - $head[$h][1] = $langs->trans("LDAPCard"); |
|
| 52 | - $head[$h][2] = 'ldap'; |
|
| 53 | - $h++; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - if (! empty($user->rights->adherent->cotisation->lire)) |
|
| 57 | - { |
|
| 58 | - $nbSubscription = is_array($object->subscriptions)?count($object->subscriptions):0; |
|
| 59 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$object->id; |
|
| 60 | - $head[$h][1] = $langs->trans("Subscriptions"); |
|
| 61 | - $head[$h][2] = 'subscription'; |
|
| 62 | - if ($nbSubscription > 0) $head[$h][1].= ' <span class="badge">'.$nbSubscription.'</span>'; |
|
| 63 | - $h++; |
|
| 64 | - } |
|
| 35 | + global $db, $langs, $conf, $user; |
|
| 36 | + |
|
| 37 | + $h = 0; |
|
| 38 | + $head = array(); |
|
| 39 | + |
|
| 40 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/card.php?rowid='.$object->id; |
|
| 41 | + $head[$h][1] = $langs->trans("Card"); |
|
| 42 | + $head[$h][2] = 'general'; |
|
| 43 | + $h++; |
|
| 44 | + |
|
| 45 | + if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_ACTIVE)) |
|
| 46 | + && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin))) |
|
| 47 | + { |
|
| 48 | + $langs->load("ldap"); |
|
| 49 | + |
|
| 50 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/ldap.php?id='.$object->id; |
|
| 51 | + $head[$h][1] = $langs->trans("LDAPCard"); |
|
| 52 | + $head[$h][2] = 'ldap'; |
|
| 53 | + $h++; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + if (! empty($user->rights->adherent->cotisation->lire)) |
|
| 57 | + { |
|
| 58 | + $nbSubscription = is_array($object->subscriptions)?count($object->subscriptions):0; |
|
| 59 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$object->id; |
|
| 60 | + $head[$h][1] = $langs->trans("Subscriptions"); |
|
| 61 | + $head[$h][2] = 'subscription'; |
|
| 62 | + if ($nbSubscription > 0) $head[$h][1].= ' <span class="badge">'.$nbSubscription.'</span>'; |
|
| 63 | + $h++; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | // Show more tabs from modules |
| 67 | 67 | // Entries must be declared in modules descriptor with line |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | if(!empty($object->note_private)) $nbNote++; |
| 75 | 75 | if(!empty($object->note_public)) $nbNote++; |
| 76 | 76 | $head[$h][0] = DOL_URL_ROOT.'/adherents/note.php?id='.$object->id; |
| 77 | - $head[$h][1] = $langs->trans("Note"); |
|
| 78 | - $head[$h][2] = 'note'; |
|
| 77 | + $head[$h][1] = $langs->trans("Note"); |
|
| 78 | + $head[$h][2] = 'note'; |
|
| 79 | 79 | if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
| 80 | - $h++; |
|
| 80 | + $h++; |
|
| 81 | 81 | |
| 82 | 82 | // Attachments |
| 83 | 83 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
@@ -91,23 +91,23 @@ discard block |
||
| 91 | 91 | $head[$h][2] = 'document'; |
| 92 | 92 | $h++; |
| 93 | 93 | |
| 94 | - // Show agenda tab |
|
| 95 | - if (! empty($conf->agenda->enabled)) |
|
| 96 | - { |
|
| 97 | - $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id; |
|
| 98 | - $head[$h][1] = $langs->trans("Events"); |
|
| 99 | - if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) |
|
| 100 | - { |
|
| 101 | - $head[$h][1].= '/'; |
|
| 102 | - $head[$h][1].= $langs->trans("Agenda"); |
|
| 103 | - } |
|
| 104 | - $head[$h][2] = 'agenda'; |
|
| 105 | - $h++; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'member','remove'); |
|
| 109 | - |
|
| 110 | - return $head; |
|
| 94 | + // Show agenda tab |
|
| 95 | + if (! empty($conf->agenda->enabled)) |
|
| 96 | + { |
|
| 97 | + $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id; |
|
| 98 | + $head[$h][1] = $langs->trans("Events"); |
|
| 99 | + if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) |
|
| 100 | + { |
|
| 101 | + $head[$h][1].= '/'; |
|
| 102 | + $head[$h][1].= $langs->trans("Agenda"); |
|
| 103 | + } |
|
| 104 | + $head[$h][2] = 'agenda'; |
|
| 105 | + $h++; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'member','remove'); |
|
| 109 | + |
|
| 110 | + return $head; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -118,26 +118,26 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function member_type_prepare_head(AdherentType $object) |
| 120 | 120 | { |
| 121 | - global $langs, $conf, $user; |
|
| 121 | + global $langs, $conf, $user; |
|
| 122 | 122 | |
| 123 | - $h=0; |
|
| 124 | - $head = array(); |
|
| 123 | + $h=0; |
|
| 124 | + $head = array(); |
|
| 125 | 125 | |
| 126 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/type.php?rowid='.$object->id; |
|
| 127 | - $head[$h][1] = $langs->trans("Card"); |
|
| 128 | - $head[$h][2] = 'card'; |
|
| 129 | - $h++; |
|
| 126 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/type.php?rowid='.$object->id; |
|
| 127 | + $head[$h][1] = $langs->trans("Card"); |
|
| 128 | + $head[$h][2] = 'card'; |
|
| 129 | + $h++; |
|
| 130 | 130 | |
| 131 | - if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE)) |
|
| 132 | - && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin))) |
|
| 133 | - { |
|
| 134 | - $langs->load("ldap"); |
|
| 131 | + if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE)) |
|
| 132 | + && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin))) |
|
| 133 | + { |
|
| 134 | + $langs->load("ldap"); |
|
| 135 | 135 | |
| 136 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/type_ldap.php?rowid='.$object->id; |
|
| 137 | - $head[$h][1] = $langs->trans("LDAPCard"); |
|
| 138 | - $head[$h][2] = 'ldap'; |
|
| 139 | - $h++; |
|
| 140 | - } |
|
| 136 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/type_ldap.php?rowid='.$object->id; |
|
| 137 | + $head[$h][1] = $langs->trans("LDAPCard"); |
|
| 138 | + $head[$h][2] = 'ldap'; |
|
| 139 | + $h++; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | // Show more tabs from modules |
| 143 | 143 | // Entries must be declared in modules descriptor with line |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 146 | 146 | complete_head_from_modules($conf,$langs,$object,$head,$h,'membertype'); |
| 147 | 147 | |
| 148 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'membertype','remove'); |
|
| 148 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'membertype','remove'); |
|
| 149 | 149 | |
| 150 | - return $head; |
|
| 150 | + return $head; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -261,28 +261,28 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | function subscription_prepare_head(Subscription $object) |
| 263 | 263 | { |
| 264 | - global $db, $langs, $conf, $user; |
|
| 264 | + global $db, $langs, $conf, $user; |
|
| 265 | 265 | |
| 266 | - $h = 0; |
|
| 267 | - $head = array(); |
|
| 266 | + $h = 0; |
|
| 267 | + $head = array(); |
|
| 268 | 268 | |
| 269 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/card.php?rowid='.$object->id; |
|
| 270 | - $head[$h][1] = $langs->trans("Card"); |
|
| 271 | - $head[$h][2] = 'general'; |
|
| 272 | - $h++; |
|
| 269 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/card.php?rowid='.$object->id; |
|
| 270 | + $head[$h][1] = $langs->trans("Card"); |
|
| 271 | + $head[$h][2] = 'general'; |
|
| 272 | + $h++; |
|
| 273 | 273 | |
| 274 | - $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/info.php?rowid='.$object->id; |
|
| 275 | - $head[$h][1] = $langs->trans("Info"); |
|
| 276 | - $head[$h][2] = 'info'; |
|
| 277 | - $h++; |
|
| 274 | + $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription/info.php?rowid='.$object->id; |
|
| 275 | + $head[$h][1] = $langs->trans("Info"); |
|
| 276 | + $head[$h][2] = 'info'; |
|
| 277 | + $h++; |
|
| 278 | 278 | |
| 279 | - // Show more tabs from modules |
|
| 280 | - // Entries must be declared in modules descriptor with line |
|
| 281 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
| 282 | - // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
| 283 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'subscription'); |
|
| 279 | + // Show more tabs from modules |
|
| 280 | + // Entries must be declared in modules descriptor with line |
|
| 281 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
| 282 | + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
| 283 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'subscription'); |
|
| 284 | 284 | |
| 285 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'subscription','remove'); |
|
| 285 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'subscription','remove'); |
|
| 286 | 286 | |
| 287 | - return $head; |
|
| 287 | + return $head; |
|
| 288 | 288 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | $head[$h][2] = 'general'; |
| 43 | 43 | $h++; |
| 44 | 44 | |
| 45 | - if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_ACTIVE)) |
|
| 46 | - && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin))) |
|
| 45 | + if ((!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_MEMBER_ACTIVE)) |
|
| 46 | + && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || !empty($user->admin))) |
|
| 47 | 47 | { |
| 48 | 48 | $langs->load("ldap"); |
| 49 | 49 | |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | $h++; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if (! empty($user->rights->adherent->cotisation->lire)) |
|
| 56 | + if (!empty($user->rights->adherent->cotisation->lire)) |
|
| 57 | 57 | { |
| 58 | - $nbSubscription = is_array($object->subscriptions)?count($object->subscriptions):0; |
|
| 58 | + $nbSubscription = is_array($object->subscriptions) ?count($object->subscriptions) : 0; |
|
| 59 | 59 | $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$object->id; |
| 60 | 60 | $head[$h][1] = $langs->trans("Subscriptions"); |
| 61 | 61 | $head[$h][2] = 'subscription'; |
| 62 | - if ($nbSubscription > 0) $head[$h][1].= ' <span class="badge">'.$nbSubscription.'</span>'; |
|
| 62 | + if ($nbSubscription > 0) $head[$h][1] .= ' <span class="badge">'.$nbSubscription.'</span>'; |
|
| 63 | 63 | $h++; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -67,45 +67,45 @@ discard block |
||
| 67 | 67 | // Entries must be declared in modules descriptor with line |
| 68 | 68 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 69 | 69 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 70 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'member'); |
|
| 70 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'member'); |
|
| 71 | 71 | |
| 72 | 72 | $nbNote = 0; |
| 73 | - if(!empty($object->note)) $nbNote++; |
|
| 74 | - if(!empty($object->note_private)) $nbNote++; |
|
| 75 | - if(!empty($object->note_public)) $nbNote++; |
|
| 73 | + if (!empty($object->note)) $nbNote++; |
|
| 74 | + if (!empty($object->note_private)) $nbNote++; |
|
| 75 | + if (!empty($object->note_public)) $nbNote++; |
|
| 76 | 76 | $head[$h][0] = DOL_URL_ROOT.'/adherents/note.php?id='.$object->id; |
| 77 | 77 | $head[$h][1] = $langs->trans("Note"); |
| 78 | 78 | $head[$h][2] = 'note'; |
| 79 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 79 | + if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 80 | 80 | $h++; |
| 81 | 81 | |
| 82 | 82 | // Attachments |
| 83 | 83 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 84 | 84 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 85 | - $upload_dir = $conf->adherent->multidir_output[$object->entity].'/'.get_exdir(0,0,0,1,$object,'member'); |
|
| 86 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 87 | - $nbLinks=Link::count($db, $object->element, $object->id); |
|
| 85 | + $upload_dir = $conf->adherent->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'member'); |
|
| 86 | + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
|
| 87 | + $nbLinks = Link::count($db, $object->element, $object->id); |
|
| 88 | 88 | $head[$h][0] = DOL_URL_ROOT.'/adherents/document.php?id='.$object->id; |
| 89 | 89 | $head[$h][1] = $langs->trans('Documents'); |
| 90 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 90 | + if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>'; |
|
| 91 | 91 | $head[$h][2] = 'document'; |
| 92 | 92 | $h++; |
| 93 | 93 | |
| 94 | 94 | // Show agenda tab |
| 95 | - if (! empty($conf->agenda->enabled)) |
|
| 95 | + if (!empty($conf->agenda->enabled)) |
|
| 96 | 96 | { |
| 97 | 97 | $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id; |
| 98 | 98 | $head[$h][1] = $langs->trans("Events"); |
| 99 | - if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) |
|
| 99 | + if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) |
|
| 100 | 100 | { |
| 101 | - $head[$h][1].= '/'; |
|
| 102 | - $head[$h][1].= $langs->trans("Agenda"); |
|
| 101 | + $head[$h][1] .= '/'; |
|
| 102 | + $head[$h][1] .= $langs->trans("Agenda"); |
|
| 103 | 103 | } |
| 104 | 104 | $head[$h][2] = 'agenda'; |
| 105 | 105 | $h++; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'member','remove'); |
|
| 108 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'remove'); |
|
| 109 | 109 | |
| 110 | 110 | return $head; |
| 111 | 111 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | global $langs, $conf, $user; |
| 122 | 122 | |
| 123 | - $h=0; |
|
| 123 | + $h = 0; |
|
| 124 | 124 | $head = array(); |
| 125 | 125 | |
| 126 | 126 | $head[$h][0] = DOL_URL_ROOT.'/adherents/type.php?rowid='.$object->id; |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | $head[$h][2] = 'card'; |
| 129 | 129 | $h++; |
| 130 | 130 | |
| 131 | - if ((! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE)) |
|
| 132 | - && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || ! empty($user->admin))) |
|
| 131 | + if ((!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE)) |
|
| 132 | + && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || !empty($user->admin))) |
|
| 133 | 133 | { |
| 134 | 134 | $langs->load("ldap"); |
| 135 | 135 | |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | // Entries must be declared in modules descriptor with line |
| 144 | 144 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 145 | 145 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 146 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'membertype'); |
|
| 146 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'membertype'); |
|
| 147 | 147 | |
| 148 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'membertype','remove'); |
|
| 148 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'membertype', 'remove'); |
|
| 149 | 149 | |
| 150 | 150 | return $head; |
| 151 | 151 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | // Entries must be declared in modules descriptor with line |
| 177 | 177 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 178 | 178 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 179 | - complete_head_from_modules($conf,$langs,'',$head,$h,'member_admin'); |
|
| 179 | + complete_head_from_modules($conf, $langs, '', $head, $h, 'member_admin'); |
|
| 180 | 180 | |
| 181 | 181 | $head[$h][0] = DOL_URL_ROOT.'/adherents/admin/adherent_extrafields.php'; |
| 182 | 182 | $head[$h][1] = $langs->trans("ExtraFieldsMember"); |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | $head[$h][2] = 'website'; |
| 194 | 194 | $h++; |
| 195 | 195 | |
| 196 | - complete_head_from_modules($conf,$langs,'',$head,$h,'member_admin','remove'); |
|
| 196 | + complete_head_from_modules($conf, $langs, '', $head, $h, 'member_admin', 'remove'); |
|
| 197 | 197 | |
| 198 | 198 | return $head; |
| 199 | 199 | } |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | // Entries must be declared in modules descriptor with line |
| 247 | 247 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 248 | 248 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 249 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'member_stats'); |
|
| 249 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'member_stats'); |
|
| 250 | 250 | |
| 251 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'member_stats','remove'); |
|
| 251 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'member_stats', 'remove'); |
|
| 252 | 252 | |
| 253 | 253 | return $head; |
| 254 | 254 | } |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | // Entries must be declared in modules descriptor with line |
| 281 | 281 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 282 | 282 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 283 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'subscription'); |
|
| 283 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'subscription'); |
|
| 284 | 284 | |
| 285 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'subscription','remove'); |
|
| 285 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'subscription', 'remove'); |
|
| 286 | 286 | |
| 287 | 287 | return $head; |
| 288 | 288 | } |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | $head[$h][0] = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$object->id; |
| 60 | 60 | $head[$h][1] = $langs->trans("Subscriptions"); |
| 61 | 61 | $head[$h][2] = 'subscription'; |
| 62 | - if ($nbSubscription > 0) $head[$h][1].= ' <span class="badge">'.$nbSubscription.'</span>'; |
|
| 62 | + if ($nbSubscription > 0) { |
|
| 63 | + $head[$h][1].= ' <span class="badge">'.$nbSubscription.'</span>'; |
|
| 64 | + } |
|
| 63 | 65 | $h++; |
| 64 | 66 | } |
| 65 | 67 | |
@@ -70,13 +72,21 @@ discard block |
||
| 70 | 72 | complete_head_from_modules($conf,$langs,$object,$head,$h,'member'); |
| 71 | 73 | |
| 72 | 74 | $nbNote = 0; |
| 73 | - if(!empty($object->note)) $nbNote++; |
|
| 74 | - if(!empty($object->note_private)) $nbNote++; |
|
| 75 | - if(!empty($object->note_public)) $nbNote++; |
|
| 75 | + if(!empty($object->note)) { |
|
| 76 | + $nbNote++; |
|
| 77 | + } |
|
| 78 | + if(!empty($object->note_private)) { |
|
| 79 | + $nbNote++; |
|
| 80 | + } |
|
| 81 | + if(!empty($object->note_public)) { |
|
| 82 | + $nbNote++; |
|
| 83 | + } |
|
| 76 | 84 | $head[$h][0] = DOL_URL_ROOT.'/adherents/note.php?id='.$object->id; |
| 77 | 85 | $head[$h][1] = $langs->trans("Note"); |
| 78 | 86 | $head[$h][2] = 'note'; |
| 79 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 87 | + if ($nbNote > 0) { |
|
| 88 | + $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 89 | + } |
|
| 80 | 90 | $h++; |
| 81 | 91 | |
| 82 | 92 | // Attachments |
@@ -87,7 +97,9 @@ discard block |
||
| 87 | 97 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 88 | 98 | $head[$h][0] = DOL_URL_ROOT.'/adherents/document.php?id='.$object->id; |
| 89 | 99 | $head[$h][1] = $langs->trans('Documents'); |
| 90 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 100 | + if (($nbFiles+$nbLinks) > 0) { |
|
| 101 | + $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 102 | + } |
|
| 91 | 103 | $head[$h][2] = 'document'; |
| 92 | 104 | $h++; |
| 93 | 105 | |
@@ -30,25 +30,25 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function contract_prepare_head(Contrat $object) |
| 32 | 32 | { |
| 33 | - global $db, $langs, $conf; |
|
| 33 | + global $db, $langs, $conf; |
|
| 34 | 34 | |
| 35 | - $h = 0; |
|
| 36 | - $head = array(); |
|
| 37 | - |
|
| 38 | - $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id; |
|
| 39 | - $head[$h][1] = $langs->trans("ContractCard"); |
|
| 40 | - $head[$h][2] = 'card'; |
|
| 41 | - $h++; |
|
| 42 | - |
|
| 43 | - if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
|
| 44 | - { |
|
| 45 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 46 | - $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id; |
|
| 47 | - $head[$h][1] = $langs->trans("ContactsAddresses"); |
|
| 48 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 49 | - $head[$h][2] = 'contact'; |
|
| 50 | - $h++; |
|
| 51 | - } |
|
| 35 | + $h = 0; |
|
| 36 | + $head = array(); |
|
| 37 | + |
|
| 38 | + $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id; |
|
| 39 | + $head[$h][1] = $langs->trans("ContractCard"); |
|
| 40 | + $head[$h][2] = 'card'; |
|
| 41 | + $h++; |
|
| 42 | + |
|
| 43 | + if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
|
| 44 | + { |
|
| 45 | + $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 46 | + $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id; |
|
| 47 | + $head[$h][1] = $langs->trans("ContactsAddresses"); |
|
| 48 | + if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 49 | + $head[$h][2] = 'contact'; |
|
| 50 | + $h++; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | // Show more tabs from modules |
| 54 | 54 | // Entries must be declared in modules descriptor with line |
@@ -58,35 +58,35 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 60 | 60 | { |
| 61 | - $nbNote = 0; |
|
| 61 | + $nbNote = 0; |
|
| 62 | 62 | if(!empty($object->note_private)) $nbNote++; |
| 63 | - if(!empty($object->note_public)) $nbNote++; |
|
| 64 | - $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id; |
|
| 65 | - $head[$h][1] = $langs->trans("Notes"); |
|
| 66 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 67 | - $head[$h][2] = 'note'; |
|
| 68 | - $h++; |
|
| 63 | + if(!empty($object->note_public)) $nbNote++; |
|
| 64 | + $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id; |
|
| 65 | + $head[$h][1] = $langs->trans("Notes"); |
|
| 66 | + if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 67 | + $head[$h][2] = 'note'; |
|
| 68 | + $h++; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 71 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 72 | 72 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 73 | - $upload_dir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 74 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 73 | + $upload_dir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 74 | + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 75 | 75 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 76 | - $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id; |
|
| 77 | - $head[$h][1] = $langs->trans("Documents"); |
|
| 78 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 79 | - $head[$h][2] = 'documents'; |
|
| 80 | - $h++; |
|
| 76 | + $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id; |
|
| 77 | + $head[$h][1] = $langs->trans("Documents"); |
|
| 78 | + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 79 | + $head[$h][2] = 'documents'; |
|
| 80 | + $h++; |
|
| 81 | 81 | |
| 82 | - $head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$object->id; |
|
| 83 | - $head[$h][1] = $langs->trans("Info"); |
|
| 84 | - $head[$h][2] = 'info'; |
|
| 85 | - $h++; |
|
| 82 | + $head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$object->id; |
|
| 83 | + $head[$h][1] = $langs->trans("Info"); |
|
| 84 | + $head[$h][2] = 'info'; |
|
| 85 | + $h++; |
|
| 86 | 86 | |
| 87 | 87 | complete_head_from_modules($conf,$langs,$object,$head,$h,'contract','remove'); |
| 88 | 88 | |
| 89 | - return $head; |
|
| 89 | + return $head; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -96,24 +96,24 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function contract_admin_prepare_head() |
| 98 | 98 | { |
| 99 | - global $langs, $conf, $user; |
|
| 99 | + global $langs, $conf, $user; |
|
| 100 | 100 | |
| 101 | - $h = 0; |
|
| 102 | - $head = array(); |
|
| 101 | + $h = 0; |
|
| 102 | + $head = array(); |
|
| 103 | 103 | |
| 104 | - $head[$h][0] = DOL_URL_ROOT."/admin/contract.php"; |
|
| 105 | - $head[$h][1] = $langs->trans("Contracts"); |
|
| 106 | - $head[$h][2] = 'contract'; |
|
| 107 | - $h++; |
|
| 104 | + $head[$h][0] = DOL_URL_ROOT."/admin/contract.php"; |
|
| 105 | + $head[$h][1] = $langs->trans("Contracts"); |
|
| 106 | + $head[$h][2] = 'contract'; |
|
| 107 | + $h++; |
|
| 108 | 108 | |
| 109 | - // Show more tabs from modules |
|
| 110 | - // Entries must be declared in modules descriptor with line |
|
| 111 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
| 112 | - // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
| 113 | - complete_head_from_modules($conf,$langs,null,$head,$h,'contract_admin'); |
|
| 109 | + // Show more tabs from modules |
|
| 110 | + // Entries must be declared in modules descriptor with line |
|
| 111 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
| 112 | + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
| 113 | + complete_head_from_modules($conf,$langs,null,$head,$h,'contract_admin'); |
|
| 114 | 114 | |
| 115 | - $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php'; |
|
| 116 | - $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 115 | + $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php'; |
|
| 116 | + $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 117 | 117 | $head[$h][2] = 'attributes'; |
| 118 | 118 | $h++; |
| 119 | 119 | |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | |
| 127 | - complete_head_from_modules($conf,$langs,null,$head,$h,'contract_admin','remove'); |
|
| 127 | + complete_head_from_modules($conf,$langs,null,$head,$h,'contract_admin','remove'); |
|
| 128 | 128 | |
| 129 | - return $head; |
|
| 129 | + return $head; |
|
| 130 | 130 | } |
| 131 | 131 | |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
| 44 | 44 | { |
| 45 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 45 | + $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); |
|
| 46 | 46 | $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id; |
| 47 | 47 | $head[$h][1] = $langs->trans("ContactsAddresses"); |
| 48 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 48 | + if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 49 | 49 | $head[$h][2] = 'contact'; |
| 50 | 50 | $h++; |
| 51 | 51 | } |
@@ -54,28 +54,28 @@ discard block |
||
| 54 | 54 | // Entries must be declared in modules descriptor with line |
| 55 | 55 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 56 | 56 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 57 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'contract'); |
|
| 57 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract'); |
|
| 58 | 58 | |
| 59 | 59 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 60 | 60 | { |
| 61 | 61 | $nbNote = 0; |
| 62 | - if(!empty($object->note_private)) $nbNote++; |
|
| 63 | - if(!empty($object->note_public)) $nbNote++; |
|
| 62 | + if (!empty($object->note_private)) $nbNote++; |
|
| 63 | + if (!empty($object->note_public)) $nbNote++; |
|
| 64 | 64 | $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id; |
| 65 | 65 | $head[$h][1] = $langs->trans("Notes"); |
| 66 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 66 | + if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 67 | 67 | $head[$h][2] = 'note'; |
| 68 | 68 | $h++; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 72 | 72 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 73 | - $upload_dir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 74 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 75 | - $nbLinks=Link::count($db, $object->element, $object->id); |
|
| 73 | + $upload_dir = $conf->contrat->dir_output."/".dol_sanitizeFileName($object->ref); |
|
| 74 | + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
|
| 75 | + $nbLinks = Link::count($db, $object->element, $object->id); |
|
| 76 | 76 | $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id; |
| 77 | 77 | $head[$h][1] = $langs->trans("Documents"); |
| 78 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 78 | + if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>'; |
|
| 79 | 79 | $head[$h][2] = 'documents'; |
| 80 | 80 | $h++; |
| 81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $head[$h][2] = 'info'; |
| 85 | 85 | $h++; |
| 86 | 86 | |
| 87 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'contract','remove'); |
|
| 87 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove'); |
|
| 88 | 88 | |
| 89 | 89 | return $head; |
| 90 | 90 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | // Entries must be declared in modules descriptor with line |
| 111 | 111 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 112 | 112 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 113 | - complete_head_from_modules($conf,$langs,null,$head,$h,'contract_admin'); |
|
| 113 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin'); |
|
| 114 | 114 | |
| 115 | 115 | $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php'; |
| 116 | 116 | $head[$h][1] = $langs->trans("ExtraFields"); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | |
| 127 | - complete_head_from_modules($conf,$langs,null,$head,$h,'contract_admin','remove'); |
|
| 127 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'remove'); |
|
| 128 | 128 | |
| 129 | 129 | return $head; |
| 130 | 130 | } |
@@ -45,7 +45,9 @@ discard block |
||
| 45 | 45 | $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
| 46 | 46 | $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id; |
| 47 | 47 | $head[$h][1] = $langs->trans("ContactsAddresses"); |
| 48 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 48 | + if ($nbContact > 0) { |
|
| 49 | + $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 50 | + } |
|
| 49 | 51 | $head[$h][2] = 'contact'; |
| 50 | 52 | $h++; |
| 51 | 53 | } |
@@ -59,11 +61,17 @@ discard block |
||
| 59 | 61 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 60 | 62 | { |
| 61 | 63 | $nbNote = 0; |
| 62 | - if(!empty($object->note_private)) $nbNote++; |
|
| 63 | - if(!empty($object->note_public)) $nbNote++; |
|
| 64 | + if(!empty($object->note_private)) { |
|
| 65 | + $nbNote++; |
|
| 66 | + } |
|
| 67 | + if(!empty($object->note_public)) { |
|
| 68 | + $nbNote++; |
|
| 69 | + } |
|
| 64 | 70 | $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id; |
| 65 | 71 | $head[$h][1] = $langs->trans("Notes"); |
| 66 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 72 | + if ($nbNote > 0) { |
|
| 73 | + $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 74 | + } |
|
| 67 | 75 | $head[$h][2] = 'note'; |
| 68 | 76 | $h++; |
| 69 | 77 | } |
@@ -75,7 +83,9 @@ discard block |
||
| 75 | 83 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 76 | 84 | $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id; |
| 77 | 85 | $head[$h][1] = $langs->trans("Documents"); |
| 78 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 86 | + if (($nbFiles+$nbLinks) > 0) { |
|
| 87 | + $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 88 | + } |
|
| 79 | 89 | $head[$h][2] = 'documents'; |
| 80 | 90 | $h++; |
| 81 | 91 | |
@@ -64,6 +64,6 @@ |
||
| 64 | 64 | // We add characteristics to the name |
| 65 | 65 | foreach($_Avery_Labels as $key => $val) |
| 66 | 66 | { |
| 67 | - $_Avery_Labels[$key]['name'].=' ('.$_Avery_Labels[$key]['paper-size'].' - '.$_Avery_Labels[$key]['NX'].'x'.$_Avery_Labels[$key]['NY'].')'; |
|
| 67 | + $_Avery_Labels[$key]['name'].=' ('.$_Avery_Labels[$key]['paper-size'].' - '.$_Avery_Labels[$key]['NX'].'x'.$_Avery_Labels[$key]['NY'].')'; |
|
| 68 | 68 | } |
| 69 | 69 | |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | while ($row = $db->fetch_array($resql)) |
| 40 | 40 | { |
| 41 | - $_Avery_Labels[$row['code']]['name']=$row['name']; |
|
| 42 | - $_Avery_Labels[$row['code']]['paper-size']=$row['paper_size']; |
|
| 43 | - $_Avery_Labels[$row['code']]['orientation']=$row['orientation']; |
|
| 44 | - $_Avery_Labels[$row['code']]['metric']=$row['metric']; |
|
| 45 | - $_Avery_Labels[$row['code']]['marginLeft']=$row['leftmargin']; |
|
| 46 | - $_Avery_Labels[$row['code']]['marginTop']=$row['topmargin']; |
|
| 47 | - $_Avery_Labels[$row['code']]['marginTop']=$row['topmargin']; |
|
| 48 | - $_Avery_Labels[$row['code']]['NX']=$row['nx']; |
|
| 49 | - $_Avery_Labels[$row['code']]['NY']=$row['ny']; |
|
| 50 | - $_Avery_Labels[$row['code']]['SpaceX']=$row['spacex']; |
|
| 51 | - $_Avery_Labels[$row['code']]['SpaceY']=$row['spacey']; |
|
| 52 | - $_Avery_Labels[$row['code']]['width']=$row['width']; |
|
| 53 | - $_Avery_Labels[$row['code']]['height']=$row['height']; |
|
| 54 | - $_Avery_Labels[$row['code']]['font-size']=$row['font_size']; |
|
| 55 | - $_Avery_Labels[$row['code']]['custom_x']=$row['custom_x']; |
|
| 56 | - $_Avery_Labels[$row['code']]['custom_y']=$row['custom_y']; |
|
| 41 | + $_Avery_Labels[$row['code']]['name'] = $row['name']; |
|
| 42 | + $_Avery_Labels[$row['code']]['paper-size'] = $row['paper_size']; |
|
| 43 | + $_Avery_Labels[$row['code']]['orientation'] = $row['orientation']; |
|
| 44 | + $_Avery_Labels[$row['code']]['metric'] = $row['metric']; |
|
| 45 | + $_Avery_Labels[$row['code']]['marginLeft'] = $row['leftmargin']; |
|
| 46 | + $_Avery_Labels[$row['code']]['marginTop'] = $row['topmargin']; |
|
| 47 | + $_Avery_Labels[$row['code']]['marginTop'] = $row['topmargin']; |
|
| 48 | + $_Avery_Labels[$row['code']]['NX'] = $row['nx']; |
|
| 49 | + $_Avery_Labels[$row['code']]['NY'] = $row['ny']; |
|
| 50 | + $_Avery_Labels[$row['code']]['SpaceX'] = $row['spacex']; |
|
| 51 | + $_Avery_Labels[$row['code']]['SpaceY'] = $row['spacey']; |
|
| 52 | + $_Avery_Labels[$row['code']]['width'] = $row['width']; |
|
| 53 | + $_Avery_Labels[$row['code']]['height'] = $row['height']; |
|
| 54 | + $_Avery_Labels[$row['code']]['font-size'] = $row['font_size']; |
|
| 55 | + $_Avery_Labels[$row['code']]['custom_x'] = $row['custom_x']; |
|
| 56 | + $_Avery_Labels[$row['code']]['custom_y'] = $row['custom_y']; |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | else |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // We add characteristics to the name |
| 65 | -foreach($_Avery_Labels as $key => $val) |
|
| 65 | +foreach ($_Avery_Labels as $key => $val) |
|
| 66 | 66 | { |
| 67 | - $_Avery_Labels[$key]['name'].=' ('.$_Avery_Labels[$key]['paper-size'].' - '.$_Avery_Labels[$key]['NX'].'x'.$_Avery_Labels[$key]['NY'].')'; |
|
| 67 | + $_Avery_Labels[$key]['name'] .= ' ('.$_Avery_Labels[$key]['paper-size'].' - '.$_Avery_Labels[$key]['NX'].'x'.$_Avery_Labels[$key]['NY'].')'; |
|
| 68 | 68 | } |
| 69 | 69 | |
@@ -55,8 +55,7 @@ |
||
| 55 | 55 | $_Avery_Labels[$row['code']]['custom_x']=$row['custom_x']; |
| 56 | 56 | $_Avery_Labels[$row['code']]['custom_y']=$row['custom_y']; |
| 57 | 57 | } |
| 58 | -} |
|
| 59 | -else |
|
| 58 | +} else |
|
| 60 | 59 | { |
| 61 | 60 | dol_print_error($db); |
| 62 | 61 | } |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | $tab = 0; |
| 37 | 37 | $head = array(); |
| 38 | 38 | |
| 39 | - $head[$tab][0] = DOL_URL_ROOT.'/loan/card.php?id='.$object->id; |
|
| 40 | - $head[$tab][1] = $langs->trans('Card'); |
|
| 41 | - $head[$tab][2] = 'card'; |
|
| 42 | - $tab++; |
|
| 39 | + $head[$tab][0] = DOL_URL_ROOT.'/loan/card.php?id='.$object->id; |
|
| 40 | + $head[$tab][1] = $langs->trans('Card'); |
|
| 41 | + $head[$tab][2] = 'card'; |
|
| 42 | + $tab++; |
|
| 43 | 43 | |
| 44 | - $head[$tab][0] = DOL_URL_ROOT.'/loan/schedule.php?loanid='.$object->id; |
|
| 45 | - $head[$tab][1] = $langs->trans('FinancialCommitment'); |
|
| 46 | - $head[$tab][2] = 'FinancialCommitment'; |
|
| 47 | - $tab++; |
|
| 44 | + $head[$tab][0] = DOL_URL_ROOT.'/loan/schedule.php?loanid='.$object->id; |
|
| 45 | + $head[$tab][1] = $langs->trans('FinancialCommitment'); |
|
| 46 | + $head[$tab][2] = 'FinancialCommitment'; |
|
| 47 | + $tab++; |
|
| 48 | 48 | |
| 49 | 49 | // Show more tabs from modules |
| 50 | 50 | // Entries must be declared in modules descriptor with line |
@@ -52,26 +52,26 @@ discard block |
||
| 52 | 52 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 53 | 53 | complete_head_from_modules($conf, $langs, $object, $head, $tab,'loan'); |
| 54 | 54 | |
| 55 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 55 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 56 | 56 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 57 | - $upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 58 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 57 | + $upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 58 | + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 59 | 59 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 60 | - $head[$tab][0] = DOL_URL_ROOT.'/loan/document.php?id='.$object->id; |
|
| 61 | - $head[$tab][1] = $langs->trans("Documents"); |
|
| 62 | - if (($nbFiles+$nbLinks) > 0) $head[$tab][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 63 | - $head[$tab][2] = 'documents'; |
|
| 64 | - $tab++; |
|
| 60 | + $head[$tab][0] = DOL_URL_ROOT.'/loan/document.php?id='.$object->id; |
|
| 61 | + $head[$tab][1] = $langs->trans("Documents"); |
|
| 62 | + if (($nbFiles+$nbLinks) > 0) $head[$tab][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 63 | + $head[$tab][2] = 'documents'; |
|
| 64 | + $tab++; |
|
| 65 | 65 | |
| 66 | - if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
|
| 67 | - { |
|
| 68 | - $nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1); |
|
| 69 | - $head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id; |
|
| 70 | - $head[$tab][1] = $langs->trans("Notes"); |
|
| 71 | - if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 72 | - $head[$tab][2] = 'note'; |
|
| 73 | - $tab++; |
|
| 74 | - } |
|
| 66 | + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
|
| 67 | + { |
|
| 68 | + $nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1); |
|
| 69 | + $head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id; |
|
| 70 | + $head[$tab][1] = $langs->trans("Notes"); |
|
| 71 | + if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 72 | + $head[$tab][2] = 'note'; |
|
| 73 | + $tab++; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | $head[$tab][0] = DOL_URL_ROOT.'/loan/info.php?id='.$object->id; |
| 77 | 77 | $head[$tab][1] = $langs->trans("Info"); |
@@ -50,25 +50,25 @@ discard block |
||
| 50 | 50 | // Entries must be declared in modules descriptor with line |
| 51 | 51 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 52 | 52 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 53 | - complete_head_from_modules($conf, $langs, $object, $head, $tab,'loan'); |
|
| 53 | + complete_head_from_modules($conf, $langs, $object, $head, $tab, 'loan'); |
|
| 54 | 54 | |
| 55 | 55 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 56 | 56 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 57 | - $upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 58 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 59 | - $nbLinks=Link::count($db, $object->element, $object->id); |
|
| 57 | + $upload_dir = $conf->loan->dir_output."/".dol_sanitizeFileName($object->ref); |
|
| 58 | + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
|
| 59 | + $nbLinks = Link::count($db, $object->element, $object->id); |
|
| 60 | 60 | $head[$tab][0] = DOL_URL_ROOT.'/loan/document.php?id='.$object->id; |
| 61 | 61 | $head[$tab][1] = $langs->trans("Documents"); |
| 62 | - if (($nbFiles+$nbLinks) > 0) $head[$tab][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 62 | + if (($nbFiles + $nbLinks) > 0) $head[$tab][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>'; |
|
| 63 | 63 | $head[$tab][2] = 'documents'; |
| 64 | 64 | $tab++; |
| 65 | 65 | |
| 66 | 66 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 67 | 67 | { |
| 68 | - $nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1); |
|
| 68 | + $nbNote = (empty($object->note_private) ? 0 : 1) + (empty($object->note_public) ? 0 : 1); |
|
| 69 | 69 | $head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id; |
| 70 | 70 | $head[$tab][1] = $langs->trans("Notes"); |
| 71 | - if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 71 | + if ($nbNote > 0) $head[$tab][1] .= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 72 | 72 | $head[$tab][2] = 'note'; |
| 73 | 73 | $tab++; |
| 74 | 74 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $head[$tab][2] = 'info'; |
| 79 | 79 | $tab++; |
| 80 | 80 | |
| 81 | - complete_head_from_modules($conf,$langs,$object,$head,$tab,'loan','remove'); |
|
| 81 | + complete_head_from_modules($conf, $langs, $object, $head, $tab, 'loan', 'remove'); |
|
| 82 | 82 | |
| 83 | 83 | return $head; |
| 84 | 84 | } |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 60 | 60 | $head[$tab][0] = DOL_URL_ROOT.'/loan/document.php?id='.$object->id; |
| 61 | 61 | $head[$tab][1] = $langs->trans("Documents"); |
| 62 | - if (($nbFiles+$nbLinks) > 0) $head[$tab][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 62 | + if (($nbFiles+$nbLinks) > 0) { |
|
| 63 | + $head[$tab][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 64 | + } |
|
| 63 | 65 | $head[$tab][2] = 'documents'; |
| 64 | 66 | $tab++; |
| 65 | 67 | |
@@ -68,7 +70,9 @@ discard block |
||
| 68 | 70 | $nbNote = (empty($object->note_private)?0:1)+(empty($object->note_public)?0:1); |
| 69 | 71 | $head[$tab][0] = DOL_URL_ROOT."/loan/note.php?id=".$object->id; |
| 70 | 72 | $head[$tab][1] = $langs->trans("Notes"); |
| 71 | - if($nbNote > 0) $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 73 | + if($nbNote > 0) { |
|
| 74 | + $head[$tab][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 75 | + } |
|
| 72 | 76 | $head[$tab][2] = 'note'; |
| 73 | 77 | $tab++; |
| 74 | 78 | } |
@@ -74,24 +74,24 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | function dol_getImageSize($file, $url = false) |
| 76 | 76 | { |
| 77 | - $ret=array(); |
|
| 77 | + $ret=array(); |
|
| 78 | 78 | |
| 79 | - if (image_format_supported($file) < 0) return $ret; |
|
| 79 | + if (image_format_supported($file) < 0) return $ret; |
|
| 80 | 80 | |
| 81 | - $filetoread = $file; |
|
| 82 | - if (!$url) |
|
| 83 | - { |
|
| 84 | - $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 85 | - } |
|
| 81 | + $filetoread = $file; |
|
| 82 | + if (!$url) |
|
| 83 | + { |
|
| 84 | + $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if ($filetoread) |
|
| 88 | - { |
|
| 89 | - $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
|
| 90 | - $ret['width']=$infoImg[0]; // Largeur de l'image |
|
| 91 | - $ret['height']=$infoImg[1]; // Hauteur de l'image |
|
| 92 | - } |
|
| 87 | + if ($filetoread) |
|
| 88 | + { |
|
| 89 | + $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
|
| 90 | + $ret['width']=$infoImg[0]; // Largeur de l'image |
|
| 91 | + $ret['height']=$infoImg[1]; // Hauteur de l'image |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $ret; |
|
| 94 | + return $ret; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -108,191 +108,191 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0) |
| 110 | 110 | { |
| 111 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
| 112 | - |
|
| 113 | - global $conf,$langs; |
|
| 114 | - |
|
| 115 | - dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y); |
|
| 116 | - |
|
| 117 | - // Clean parameters |
|
| 118 | - $file=trim($file); |
|
| 119 | - |
|
| 120 | - // Check parameters |
|
| 121 | - if (! $file) |
|
| 122 | - { |
|
| 123 | - // Si le fichier n'a pas ete indique |
|
| 124 | - return 'Bad parameter file'; |
|
| 125 | - } |
|
| 126 | - elseif (! file_exists($file)) |
|
| 127 | - { |
|
| 128 | - // Si le fichier passe en parametre n'existe pas |
|
| 129 | - return $langs->trans("ErrorFileNotFound",$file); |
|
| 130 | - } |
|
| 131 | - elseif(image_format_supported($file) < 0) |
|
| 132 | - { |
|
| 133 | - return 'This filename '.$file.' does not seem to be an image filename.'; |
|
| 134 | - } |
|
| 135 | - elseif(!is_numeric($newWidth) && !is_numeric($newHeight)) |
|
| 136 | - { |
|
| 137 | - return 'Wrong value for parameter newWidth or newHeight'; |
|
| 138 | - } |
|
| 139 | - elseif ($mode == 0 && $newWidth <= 0 && $newHeight <= 0) |
|
| 140 | - { |
|
| 141 | - return 'At least newHeight or newWidth must be defined for resizing'; |
|
| 142 | - } |
|
| 143 | - elseif ($mode == 1 && ($newWidth <= 0 || $newHeight <= 0)) |
|
| 144 | - { |
|
| 145 | - return 'Both newHeight or newWidth must be defined for croping'; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 149 | - |
|
| 150 | - $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
|
| 151 | - $imgWidth = $infoImg[0]; // Largeur de l'image |
|
| 152 | - $imgHeight = $infoImg[1]; // Hauteur de l'image |
|
| 153 | - |
|
| 154 | - if ($mode == 0) // If resize, we check parameters |
|
| 155 | - { |
|
| 156 | - if ($newWidth <= 0) |
|
| 157 | - { |
|
| 158 | - $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio |
|
| 159 | - } |
|
| 160 | - if ($newHeight <= 0) |
|
| 161 | - { |
|
| 162 | - $newHeight=intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $imgfonction=''; |
|
| 167 | - switch($infoImg[2]) |
|
| 168 | - { |
|
| 169 | - case 1: // IMG_GIF |
|
| 170 | - $imgfonction = 'imagecreatefromgif'; |
|
| 171 | - break; |
|
| 172 | - case 2: // IMG_JPG |
|
| 173 | - $imgfonction = 'imagecreatefromjpeg'; |
|
| 174 | - break; |
|
| 175 | - case 3: // IMG_PNG |
|
| 176 | - $imgfonction = 'imagecreatefrompng'; |
|
| 177 | - break; |
|
| 178 | - case 4: // IMG_WBMP |
|
| 179 | - $imgfonction = 'imagecreatefromwbmp'; |
|
| 180 | - break; |
|
| 181 | - } |
|
| 182 | - if ($imgfonction) |
|
| 183 | - { |
|
| 184 | - if (! function_exists($imgfonction)) |
|
| 185 | - { |
|
| 186 | - // Fonctions de conversion non presente dans ce PHP |
|
| 187 | - return 'Resize not possible. This PHP does not support GD functions '.$imgfonction; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Initialisation des variables selon l'extension de l'image |
|
| 192 | - switch($infoImg[2]) |
|
| 193 | - { |
|
| 194 | - case 1: // Gif |
|
| 195 | - $img = imagecreatefromgif($filetoread); |
|
| 196 | - $extImg = '.gif'; // File name extension of image |
|
| 197 | - $newquality='NU'; // Quality is not used for this format |
|
| 198 | - break; |
|
| 199 | - case 2: // Jpg |
|
| 200 | - $img = imagecreatefromjpeg($filetoread); |
|
| 201 | - $extImg = '.jpg'; |
|
| 202 | - $newquality=100; // % quality maximum |
|
| 203 | - break; |
|
| 204 | - case 3: // Png |
|
| 205 | - $img = imagecreatefrompng($filetoread); |
|
| 206 | - $extImg = '.png'; |
|
| 207 | - $newquality=0; // No compression (0-9) |
|
| 208 | - break; |
|
| 209 | - case 4: // Bmp |
|
| 210 | - $img = imagecreatefromwbmp($filetoread); |
|
| 211 | - $extImg = '.bmp'; |
|
| 212 | - $newquality='NU'; // Quality is not used for this format |
|
| 213 | - break; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // Create empty image |
|
| 217 | - if ($infoImg[2] == 1) |
|
| 218 | - { |
|
| 219 | - // Compatibilite image GIF |
|
| 220 | - $imgThumb = imagecreate($newWidth, $newHeight); |
|
| 221 | - } |
|
| 222 | - else |
|
| 223 | - { |
|
| 224 | - $imgThumb = imagecreatetruecolor($newWidth, $newHeight); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Activate antialiasing for better quality |
|
| 228 | - if (function_exists('imageantialias')) |
|
| 229 | - { |
|
| 230 | - imageantialias($imgThumb, true); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // This is to keep transparent alpha channel if exists (PHP >= 4.2) |
|
| 234 | - if (function_exists('imagesavealpha')) |
|
| 235 | - { |
|
| 236 | - imagesavealpha($imgThumb, true); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Initialisation des variables selon l'extension de l'image |
|
| 240 | - switch($infoImg[2]) |
|
| 241 | - { |
|
| 242 | - case 1: // Gif |
|
| 243 | - $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF |
|
| 244 | - imagecolortransparent($imgThumb,$trans_colour); |
|
| 245 | - break; |
|
| 246 | - case 2: // Jpg |
|
| 247 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
|
| 248 | - break; |
|
| 249 | - case 3: // Png |
|
| 250 | - imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme |
|
| 251 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 252 | - break; |
|
| 253 | - case 4: // Bmp |
|
| 254 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
|
| 255 | - break; |
|
| 256 | - } |
|
| 257 | - if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 258 | - |
|
| 259 | - dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality"); |
|
| 260 | - //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
|
| 261 | - imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode==0?$imgWidth:$newWidth), ($mode==0?$imgHeight:$newHeight)); // Insere l'image de base redimensionnee |
|
| 262 | - |
|
| 263 | - $imgThumbName = $file; |
|
| 264 | - |
|
| 265 | - // Check if permission are ok |
|
| 266 | - //$fp = fopen($imgThumbName, "w"); |
|
| 267 | - //fclose($fp); |
|
| 268 | - |
|
| 269 | - // Create image on disk |
|
| 270 | - switch($infoImg[2]) |
|
| 271 | - { |
|
| 272 | - case 1: // Gif |
|
| 273 | - imagegif($imgThumb, $imgThumbName); |
|
| 274 | - break; |
|
| 275 | - case 2: // Jpg |
|
| 276 | - imagejpeg($imgThumb, $imgThumbName, $newquality); |
|
| 277 | - break; |
|
| 278 | - case 3: // Png |
|
| 279 | - imagepng($imgThumb, $imgThumbName, $newquality); |
|
| 280 | - break; |
|
| 281 | - case 4: // Bmp |
|
| 282 | - image2wbmp($imgThumb, $imgThumbName); |
|
| 283 | - break; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // Set permissions on file |
|
| 287 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 288 | - |
|
| 289 | - // Free memory. This does not delete image. |
|
| 111 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
| 112 | + |
|
| 113 | + global $conf,$langs; |
|
| 114 | + |
|
| 115 | + dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y); |
|
| 116 | + |
|
| 117 | + // Clean parameters |
|
| 118 | + $file=trim($file); |
|
| 119 | + |
|
| 120 | + // Check parameters |
|
| 121 | + if (! $file) |
|
| 122 | + { |
|
| 123 | + // Si le fichier n'a pas ete indique |
|
| 124 | + return 'Bad parameter file'; |
|
| 125 | + } |
|
| 126 | + elseif (! file_exists($file)) |
|
| 127 | + { |
|
| 128 | + // Si le fichier passe en parametre n'existe pas |
|
| 129 | + return $langs->trans("ErrorFileNotFound",$file); |
|
| 130 | + } |
|
| 131 | + elseif(image_format_supported($file) < 0) |
|
| 132 | + { |
|
| 133 | + return 'This filename '.$file.' does not seem to be an image filename.'; |
|
| 134 | + } |
|
| 135 | + elseif(!is_numeric($newWidth) && !is_numeric($newHeight)) |
|
| 136 | + { |
|
| 137 | + return 'Wrong value for parameter newWidth or newHeight'; |
|
| 138 | + } |
|
| 139 | + elseif ($mode == 0 && $newWidth <= 0 && $newHeight <= 0) |
|
| 140 | + { |
|
| 141 | + return 'At least newHeight or newWidth must be defined for resizing'; |
|
| 142 | + } |
|
| 143 | + elseif ($mode == 1 && ($newWidth <= 0 || $newHeight <= 0)) |
|
| 144 | + { |
|
| 145 | + return 'Both newHeight or newWidth must be defined for croping'; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 149 | + |
|
| 150 | + $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
|
| 151 | + $imgWidth = $infoImg[0]; // Largeur de l'image |
|
| 152 | + $imgHeight = $infoImg[1]; // Hauteur de l'image |
|
| 153 | + |
|
| 154 | + if ($mode == 0) // If resize, we check parameters |
|
| 155 | + { |
|
| 156 | + if ($newWidth <= 0) |
|
| 157 | + { |
|
| 158 | + $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio |
|
| 159 | + } |
|
| 160 | + if ($newHeight <= 0) |
|
| 161 | + { |
|
| 162 | + $newHeight=intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $imgfonction=''; |
|
| 167 | + switch($infoImg[2]) |
|
| 168 | + { |
|
| 169 | + case 1: // IMG_GIF |
|
| 170 | + $imgfonction = 'imagecreatefromgif'; |
|
| 171 | + break; |
|
| 172 | + case 2: // IMG_JPG |
|
| 173 | + $imgfonction = 'imagecreatefromjpeg'; |
|
| 174 | + break; |
|
| 175 | + case 3: // IMG_PNG |
|
| 176 | + $imgfonction = 'imagecreatefrompng'; |
|
| 177 | + break; |
|
| 178 | + case 4: // IMG_WBMP |
|
| 179 | + $imgfonction = 'imagecreatefromwbmp'; |
|
| 180 | + break; |
|
| 181 | + } |
|
| 182 | + if ($imgfonction) |
|
| 183 | + { |
|
| 184 | + if (! function_exists($imgfonction)) |
|
| 185 | + { |
|
| 186 | + // Fonctions de conversion non presente dans ce PHP |
|
| 187 | + return 'Resize not possible. This PHP does not support GD functions '.$imgfonction; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Initialisation des variables selon l'extension de l'image |
|
| 192 | + switch($infoImg[2]) |
|
| 193 | + { |
|
| 194 | + case 1: // Gif |
|
| 195 | + $img = imagecreatefromgif($filetoread); |
|
| 196 | + $extImg = '.gif'; // File name extension of image |
|
| 197 | + $newquality='NU'; // Quality is not used for this format |
|
| 198 | + break; |
|
| 199 | + case 2: // Jpg |
|
| 200 | + $img = imagecreatefromjpeg($filetoread); |
|
| 201 | + $extImg = '.jpg'; |
|
| 202 | + $newquality=100; // % quality maximum |
|
| 203 | + break; |
|
| 204 | + case 3: // Png |
|
| 205 | + $img = imagecreatefrompng($filetoread); |
|
| 206 | + $extImg = '.png'; |
|
| 207 | + $newquality=0; // No compression (0-9) |
|
| 208 | + break; |
|
| 209 | + case 4: // Bmp |
|
| 210 | + $img = imagecreatefromwbmp($filetoread); |
|
| 211 | + $extImg = '.bmp'; |
|
| 212 | + $newquality='NU'; // Quality is not used for this format |
|
| 213 | + break; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // Create empty image |
|
| 217 | + if ($infoImg[2] == 1) |
|
| 218 | + { |
|
| 219 | + // Compatibilite image GIF |
|
| 220 | + $imgThumb = imagecreate($newWidth, $newHeight); |
|
| 221 | + } |
|
| 222 | + else |
|
| 223 | + { |
|
| 224 | + $imgThumb = imagecreatetruecolor($newWidth, $newHeight); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + // Activate antialiasing for better quality |
|
| 228 | + if (function_exists('imageantialias')) |
|
| 229 | + { |
|
| 230 | + imageantialias($imgThumb, true); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // This is to keep transparent alpha channel if exists (PHP >= 4.2) |
|
| 234 | + if (function_exists('imagesavealpha')) |
|
| 235 | + { |
|
| 236 | + imagesavealpha($imgThumb, true); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Initialisation des variables selon l'extension de l'image |
|
| 240 | + switch($infoImg[2]) |
|
| 241 | + { |
|
| 242 | + case 1: // Gif |
|
| 243 | + $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF |
|
| 244 | + imagecolortransparent($imgThumb,$trans_colour); |
|
| 245 | + break; |
|
| 246 | + case 2: // Jpg |
|
| 247 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
|
| 248 | + break; |
|
| 249 | + case 3: // Png |
|
| 250 | + imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme |
|
| 251 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 252 | + break; |
|
| 253 | + case 4: // Bmp |
|
| 254 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
|
| 255 | + break; |
|
| 256 | + } |
|
| 257 | + if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 258 | + |
|
| 259 | + dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality"); |
|
| 260 | + //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
|
| 261 | + imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode==0?$imgWidth:$newWidth), ($mode==0?$imgHeight:$newHeight)); // Insere l'image de base redimensionnee |
|
| 262 | + |
|
| 263 | + $imgThumbName = $file; |
|
| 264 | + |
|
| 265 | + // Check if permission are ok |
|
| 266 | + //$fp = fopen($imgThumbName, "w"); |
|
| 267 | + //fclose($fp); |
|
| 268 | + |
|
| 269 | + // Create image on disk |
|
| 270 | + switch($infoImg[2]) |
|
| 271 | + { |
|
| 272 | + case 1: // Gif |
|
| 273 | + imagegif($imgThumb, $imgThumbName); |
|
| 274 | + break; |
|
| 275 | + case 2: // Jpg |
|
| 276 | + imagejpeg($imgThumb, $imgThumbName, $newquality); |
|
| 277 | + break; |
|
| 278 | + case 3: // Png |
|
| 279 | + imagepng($imgThumb, $imgThumbName, $newquality); |
|
| 280 | + break; |
|
| 281 | + case 4: // Bmp |
|
| 282 | + image2wbmp($imgThumb, $imgThumbName); |
|
| 283 | + break; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // Set permissions on file |
|
| 287 | + if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 288 | + |
|
| 289 | + // Free memory. This does not delete image. |
|
| 290 | 290 | imagedestroy($img); |
| 291 | - imagedestroy($imgThumb); |
|
| 291 | + imagedestroy($imgThumb); |
|
| 292 | 292 | |
| 293 | - clearstatcache(); // File was replaced by a modified one, so we clear file caches. |
|
| 293 | + clearstatcache(); // File was replaced by a modified one, so we clear file caches. |
|
| 294 | 294 | |
| 295 | - return $imgThumbName; |
|
| 295 | + return $imgThumbName; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | |
@@ -351,247 +351,247 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0) |
| 353 | 353 | { |
| 354 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
| 354 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
| 355 | 355 | |
| 356 | - global $conf,$langs; |
|
| 356 | + global $conf,$langs; |
|
| 357 | 357 | |
| 358 | - dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." outdir=".$outdir." targetformat=".$targetformat); |
|
| 358 | + dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." outdir=".$outdir." targetformat=".$targetformat); |
|
| 359 | 359 | |
| 360 | - // Clean parameters |
|
| 361 | - $file=trim($file); |
|
| 360 | + // Clean parameters |
|
| 361 | + $file=trim($file); |
|
| 362 | 362 | |
| 363 | - // Check parameters |
|
| 364 | - if (! $file) |
|
| 365 | - { |
|
| 366 | - // Si le fichier n'a pas ete indique |
|
| 367 | - return 'ErrorBadParameters'; |
|
| 368 | - } |
|
| 369 | - elseif (! file_exists($file)) |
|
| 370 | - { |
|
| 371 | - // Si le fichier passe en parametre n'existe pas |
|
| 363 | + // Check parameters |
|
| 364 | + if (! $file) |
|
| 365 | + { |
|
| 366 | + // Si le fichier n'a pas ete indique |
|
| 367 | + return 'ErrorBadParameters'; |
|
| 368 | + } |
|
| 369 | + elseif (! file_exists($file)) |
|
| 370 | + { |
|
| 371 | + // Si le fichier passe en parametre n'existe pas |
|
| 372 | 372 | dol_syslog($langs->trans("ErrorFileNotFound",$file),LOG_ERR); |
| 373 | - return $langs->trans("ErrorFileNotFound",$file); |
|
| 374 | - } |
|
| 375 | - elseif(image_format_supported($file) < 0) |
|
| 376 | - { |
|
| 373 | + return $langs->trans("ErrorFileNotFound",$file); |
|
| 374 | + } |
|
| 375 | + elseif(image_format_supported($file) < 0) |
|
| 376 | + { |
|
| 377 | 377 | dol_syslog('This file '.$file.' does not seem to be an image format file name.',LOG_WARNING); |
| 378 | - return 'ErrorBadImageFormat'; |
|
| 379 | - } |
|
| 380 | - elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ |
|
| 381 | - // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
|
| 378 | + return 'ErrorBadImageFormat'; |
|
| 379 | + } |
|
| 380 | + elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ |
|
| 381 | + // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
|
| 382 | 382 | dol_syslog('Wrong value for parameter maxWidth',LOG_ERR); |
| 383 | - return 'Error: Wrong value for parameter maxWidth'; |
|
| 384 | - } |
|
| 385 | - elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ |
|
| 386 | - // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
|
| 383 | + return 'Error: Wrong value for parameter maxWidth'; |
|
| 384 | + } |
|
| 385 | + elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ |
|
| 386 | + // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
|
| 387 | 387 | dol_syslog('Wrong value for parameter maxHeight',LOG_ERR); |
| 388 | - return 'Error: Wrong value for parameter maxHeight'; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 392 | - |
|
| 393 | - $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
|
| 394 | - $imgWidth = $infoImg[0]; // Largeur de l'image |
|
| 395 | - $imgHeight = $infoImg[1]; // Hauteur de l'image |
|
| 396 | - |
|
| 397 | - if ($maxWidth == -1) $maxWidth=$infoImg[0]; // If size is -1, we keep unchanged |
|
| 398 | - if ($maxHeight == -1) $maxHeight=$infoImg[1]; // If size is -1, we keep unchanged |
|
| 399 | - |
|
| 400 | - // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette |
|
| 401 | - if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) |
|
| 402 | - { |
|
| 403 | - // On cree toujours les vignettes |
|
| 404 | - dol_syslog("File size is smaller than thumb size",LOG_DEBUG); |
|
| 405 | - //return 'Le fichier '.$file.' ne necessite pas de creation de vignette'; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - $imgfonction=''; |
|
| 409 | - switch($infoImg[2]) |
|
| 410 | - { |
|
| 411 | - case IMAGETYPE_GIF: // 1 |
|
| 412 | - $imgfonction = 'imagecreatefromgif'; |
|
| 413 | - break; |
|
| 414 | - case IMAGETYPE_JPEG: // 2 |
|
| 415 | - $imgfonction = 'imagecreatefromjpeg'; |
|
| 416 | - break; |
|
| 417 | - case IMAGETYPE_PNG: // 3 |
|
| 418 | - $imgfonction = 'imagecreatefrompng'; |
|
| 419 | - break; |
|
| 420 | - case IMAGETYPE_BMP: // 6 |
|
| 388 | + return 'Error: Wrong value for parameter maxHeight'; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 392 | + |
|
| 393 | + $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
|
| 394 | + $imgWidth = $infoImg[0]; // Largeur de l'image |
|
| 395 | + $imgHeight = $infoImg[1]; // Hauteur de l'image |
|
| 396 | + |
|
| 397 | + if ($maxWidth == -1) $maxWidth=$infoImg[0]; // If size is -1, we keep unchanged |
|
| 398 | + if ($maxHeight == -1) $maxHeight=$infoImg[1]; // If size is -1, we keep unchanged |
|
| 399 | + |
|
| 400 | + // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette |
|
| 401 | + if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) |
|
| 402 | + { |
|
| 403 | + // On cree toujours les vignettes |
|
| 404 | + dol_syslog("File size is smaller than thumb size",LOG_DEBUG); |
|
| 405 | + //return 'Le fichier '.$file.' ne necessite pas de creation de vignette'; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + $imgfonction=''; |
|
| 409 | + switch($infoImg[2]) |
|
| 410 | + { |
|
| 411 | + case IMAGETYPE_GIF: // 1 |
|
| 412 | + $imgfonction = 'imagecreatefromgif'; |
|
| 413 | + break; |
|
| 414 | + case IMAGETYPE_JPEG: // 2 |
|
| 415 | + $imgfonction = 'imagecreatefromjpeg'; |
|
| 416 | + break; |
|
| 417 | + case IMAGETYPE_PNG: // 3 |
|
| 418 | + $imgfonction = 'imagecreatefrompng'; |
|
| 419 | + break; |
|
| 420 | + case IMAGETYPE_BMP: // 6 |
|
| 421 | 421 | // Not supported by PHP GD |
| 422 | - break; |
|
| 423 | - case IMAGETYPE_WBMP: // 15 |
|
| 424 | - $imgfonction = 'imagecreatefromwbmp'; |
|
| 425 | - break; |
|
| 426 | - } |
|
| 427 | - if ($imgfonction) |
|
| 428 | - { |
|
| 429 | - if (! function_exists($imgfonction)) |
|
| 430 | - { |
|
| 431 | - // Fonctions de conversion non presente dans ce PHP |
|
| 432 | - return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction; |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - // On cree le repertoire contenant les vignettes |
|
| 437 | - $dirthumb = dirname($file).($outdir?'/'.$outdir:''); // Chemin du dossier contenant les vignettes |
|
| 438 | - dol_mkdir($dirthumb); |
|
| 439 | - |
|
| 440 | - // Initialisation des variables selon l'extension de l'image |
|
| 441 | - $img=null; |
|
| 442 | - switch($infoImg[2]) |
|
| 443 | - { |
|
| 444 | - case IMAGETYPE_GIF: // 1 |
|
| 445 | - $img = imagecreatefromgif($filetoread); |
|
| 446 | - $extImg = '.gif'; // Extension de l'image |
|
| 447 | - break; |
|
| 448 | - case IMAGETYPE_JPEG: // 2 |
|
| 449 | - $img = imagecreatefromjpeg($filetoread); |
|
| 450 | - $extImg = (preg_match('/\.jpeg$/',$file)?'.jpeg':'.jpg'); // Extension de l'image |
|
| 451 | - break; |
|
| 452 | - case IMAGETYPE_PNG: // 3 |
|
| 453 | - $img = imagecreatefrompng($filetoread); |
|
| 454 | - $extImg = '.png'; |
|
| 455 | - break; |
|
| 456 | - case IMAGETYPE_BMP: // 6 |
|
| 422 | + break; |
|
| 423 | + case IMAGETYPE_WBMP: // 15 |
|
| 424 | + $imgfonction = 'imagecreatefromwbmp'; |
|
| 425 | + break; |
|
| 426 | + } |
|
| 427 | + if ($imgfonction) |
|
| 428 | + { |
|
| 429 | + if (! function_exists($imgfonction)) |
|
| 430 | + { |
|
| 431 | + // Fonctions de conversion non presente dans ce PHP |
|
| 432 | + return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + // On cree le repertoire contenant les vignettes |
|
| 437 | + $dirthumb = dirname($file).($outdir?'/'.$outdir:''); // Chemin du dossier contenant les vignettes |
|
| 438 | + dol_mkdir($dirthumb); |
|
| 439 | + |
|
| 440 | + // Initialisation des variables selon l'extension de l'image |
|
| 441 | + $img=null; |
|
| 442 | + switch($infoImg[2]) |
|
| 443 | + { |
|
| 444 | + case IMAGETYPE_GIF: // 1 |
|
| 445 | + $img = imagecreatefromgif($filetoread); |
|
| 446 | + $extImg = '.gif'; // Extension de l'image |
|
| 447 | + break; |
|
| 448 | + case IMAGETYPE_JPEG: // 2 |
|
| 449 | + $img = imagecreatefromjpeg($filetoread); |
|
| 450 | + $extImg = (preg_match('/\.jpeg$/',$file)?'.jpeg':'.jpg'); // Extension de l'image |
|
| 451 | + break; |
|
| 452 | + case IMAGETYPE_PNG: // 3 |
|
| 453 | + $img = imagecreatefrompng($filetoread); |
|
| 454 | + $extImg = '.png'; |
|
| 455 | + break; |
|
| 456 | + case IMAGETYPE_BMP: // 6 |
|
| 457 | 457 | // Not supported by PHP GD |
| 458 | - $extImg = '.bmp'; |
|
| 459 | - break; |
|
| 460 | - case IMAGETYPE_WBMP: // 15 |
|
| 461 | - $img = imagecreatefromwbmp($filetoread); |
|
| 462 | - $extImg = '.bmp'; |
|
| 463 | - break; |
|
| 464 | - } |
|
| 458 | + $extImg = '.bmp'; |
|
| 459 | + break; |
|
| 460 | + case IMAGETYPE_WBMP: // 15 |
|
| 461 | + $img = imagecreatefromwbmp($filetoread); |
|
| 462 | + $extImg = '.bmp'; |
|
| 463 | + break; |
|
| 464 | + } |
|
| 465 | 465 | if (! is_resource($img)) |
| 466 | 466 | { |
| 467 | 467 | dol_syslog('Failed to detect type of image. We found infoImg[2]='.$infoImg[2], LOG_WARNING); |
| 468 | 468 | return 0; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - // Initialisation des dimensions de la vignette si elles sont superieures a l'original |
|
| 472 | - if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } |
|
| 473 | - if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; } |
|
| 474 | - |
|
| 475 | - $whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette |
|
| 476 | - $imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original |
|
| 477 | - |
|
| 478 | - // Fixe les dimensions de la vignette |
|
| 479 | - if($whFact < $imgWhFact) |
|
| 480 | - { |
|
| 481 | - // Si largeur determinante |
|
| 482 | - $thumbWidth = $maxWidth; |
|
| 483 | - $thumbHeight = $thumbWidth / $imgWhFact; |
|
| 484 | - } |
|
| 485 | - else |
|
| 486 | - { |
|
| 487 | - // Si hauteur determinante |
|
| 488 | - $thumbHeight = $maxHeight; |
|
| 489 | - $thumbWidth = $thumbHeight * $imgWhFact; |
|
| 490 | - } |
|
| 491 | - $thumbHeight=round($thumbHeight); |
|
| 492 | - $thumbWidth=round($thumbWidth); |
|
| 471 | + // Initialisation des dimensions de la vignette si elles sont superieures a l'original |
|
| 472 | + if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } |
|
| 473 | + if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; } |
|
| 474 | + |
|
| 475 | + $whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette |
|
| 476 | + $imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original |
|
| 477 | + |
|
| 478 | + // Fixe les dimensions de la vignette |
|
| 479 | + if($whFact < $imgWhFact) |
|
| 480 | + { |
|
| 481 | + // Si largeur determinante |
|
| 482 | + $thumbWidth = $maxWidth; |
|
| 483 | + $thumbHeight = $thumbWidth / $imgWhFact; |
|
| 484 | + } |
|
| 485 | + else |
|
| 486 | + { |
|
| 487 | + // Si hauteur determinante |
|
| 488 | + $thumbHeight = $maxHeight; |
|
| 489 | + $thumbWidth = $thumbHeight * $imgWhFact; |
|
| 490 | + } |
|
| 491 | + $thumbHeight=round($thumbHeight); |
|
| 492 | + $thumbWidth=round($thumbWidth); |
|
| 493 | 493 | |
| 494 | 494 | // Define target format |
| 495 | 495 | if (empty($targetformat)) $targetformat=$infoImg[2]; |
| 496 | 496 | |
| 497 | - // Create empty image |
|
| 498 | - if ($targetformat == IMAGETYPE_GIF) |
|
| 499 | - { |
|
| 500 | - // Compatibilite image GIF |
|
| 501 | - $imgThumb = imagecreate($thumbWidth, $thumbHeight); |
|
| 502 | - } |
|
| 503 | - else |
|
| 504 | - { |
|
| 505 | - $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - // Activate antialiasing for better quality |
|
| 509 | - if (function_exists('imageantialias')) |
|
| 510 | - { |
|
| 511 | - imageantialias($imgThumb, true); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - // This is to keep transparent alpha channel if exists (PHP >= 4.2) |
|
| 515 | - if (function_exists('imagesavealpha')) |
|
| 516 | - { |
|
| 517 | - imagesavealpha($imgThumb, true); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - // Initialisation des variables selon l'extension de l'image |
|
| 521 | - // $targetformat is 0 by default, in such case, we keep original extension |
|
| 522 | - switch($targetformat) |
|
| 523 | - { |
|
| 524 | - case IMAGETYPE_GIF: // 1 |
|
| 525 | - $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF |
|
| 526 | - imagecolortransparent($imgThumb,$trans_colour); |
|
| 497 | + // Create empty image |
|
| 498 | + if ($targetformat == IMAGETYPE_GIF) |
|
| 499 | + { |
|
| 500 | + // Compatibilite image GIF |
|
| 501 | + $imgThumb = imagecreate($thumbWidth, $thumbHeight); |
|
| 502 | + } |
|
| 503 | + else |
|
| 504 | + { |
|
| 505 | + $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + // Activate antialiasing for better quality |
|
| 509 | + if (function_exists('imageantialias')) |
|
| 510 | + { |
|
| 511 | + imageantialias($imgThumb, true); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + // This is to keep transparent alpha channel if exists (PHP >= 4.2) |
|
| 515 | + if (function_exists('imagesavealpha')) |
|
| 516 | + { |
|
| 517 | + imagesavealpha($imgThumb, true); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + // Initialisation des variables selon l'extension de l'image |
|
| 521 | + // $targetformat is 0 by default, in such case, we keep original extension |
|
| 522 | + switch($targetformat) |
|
| 523 | + { |
|
| 524 | + case IMAGETYPE_GIF: // 1 |
|
| 525 | + $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF |
|
| 526 | + imagecolortransparent($imgThumb,$trans_colour); |
|
| 527 | 527 | $extImgTarget = '.gif'; |
| 528 | 528 | $newquality='NU'; |
| 529 | 529 | break; |
| 530 | - case IMAGETYPE_JPEG: // 2 |
|
| 530 | + case IMAGETYPE_JPEG: // 2 |
|
| 531 | 531 | $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
| 532 | 532 | $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'.jpg'); |
| 533 | 533 | $newquality=$quality; |
| 534 | 534 | break; |
| 535 | - case IMAGETYPE_PNG: // 3 |
|
| 536 | - imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme |
|
| 537 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 535 | + case IMAGETYPE_PNG: // 3 |
|
| 536 | + imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme |
|
| 537 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 538 | 538 | $extImgTarget = '.png'; |
| 539 | 539 | $newquality=$quality-100; |
| 540 | 540 | $newquality=round(abs($quality-100)*9/100); |
| 541 | 541 | break; |
| 542 | - case IMAGETYPE_BMP: // 6 |
|
| 542 | + case IMAGETYPE_BMP: // 6 |
|
| 543 | 543 | // Not supported by PHP GD |
| 544 | 544 | $extImgTarget = '.bmp'; |
| 545 | 545 | $newquality='NU'; |
| 546 | 546 | break; |
| 547 | - case IMAGETYPE_WBMP: // 15 |
|
| 548 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
|
| 547 | + case IMAGETYPE_WBMP: // 15 |
|
| 548 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
|
| 549 | 549 | $extImgTarget = '.bmp'; |
| 550 | 550 | $newquality='NU'; |
| 551 | 551 | break; |
| 552 | - } |
|
| 553 | - if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 554 | - |
|
| 555 | - dol_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality"); |
|
| 556 | - //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
|
| 557 | - imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
|
| 558 | - |
|
| 559 | - $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse |
|
| 560 | - $fileName = basename($fileName); |
|
| 561 | - //$imgThumbName = $dirthumb.'/'.getImageFileNameForSize(basename($file), $extName, $extImgTarget); // Full path of thumb file |
|
| 562 | - $imgThumbName = getImageFileNameForSize($file, $extName, $extImgTarget); // Full path of thumb file |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - // Check if permission are ok |
|
| 566 | - //$fp = fopen($imgThumbName, "w"); |
|
| 567 | - //fclose($fp); |
|
| 568 | - |
|
| 569 | - // Create image on disk |
|
| 570 | - switch($targetformat) |
|
| 571 | - { |
|
| 572 | - case IMAGETYPE_GIF: // 1 |
|
| 573 | - imagegif($imgThumb, $imgThumbName); |
|
| 574 | - break; |
|
| 575 | - case IMAGETYPE_JPEG: // 2 |
|
| 576 | - imagejpeg($imgThumb, $imgThumbName, $newquality); |
|
| 577 | - break; |
|
| 578 | - case IMAGETYPE_PNG: // 3 |
|
| 579 | - imagepng($imgThumb, $imgThumbName, $newquality); |
|
| 580 | - break; |
|
| 581 | - case IMAGETYPE_BMP: // 6 |
|
| 552 | + } |
|
| 553 | + if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 554 | + |
|
| 555 | + dol_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality"); |
|
| 556 | + //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
|
| 557 | + imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
|
| 558 | + |
|
| 559 | + $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse |
|
| 560 | + $fileName = basename($fileName); |
|
| 561 | + //$imgThumbName = $dirthumb.'/'.getImageFileNameForSize(basename($file), $extName, $extImgTarget); // Full path of thumb file |
|
| 562 | + $imgThumbName = getImageFileNameForSize($file, $extName, $extImgTarget); // Full path of thumb file |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + // Check if permission are ok |
|
| 566 | + //$fp = fopen($imgThumbName, "w"); |
|
| 567 | + //fclose($fp); |
|
| 568 | + |
|
| 569 | + // Create image on disk |
|
| 570 | + switch($targetformat) |
|
| 571 | + { |
|
| 572 | + case IMAGETYPE_GIF: // 1 |
|
| 573 | + imagegif($imgThumb, $imgThumbName); |
|
| 574 | + break; |
|
| 575 | + case IMAGETYPE_JPEG: // 2 |
|
| 576 | + imagejpeg($imgThumb, $imgThumbName, $newquality); |
|
| 577 | + break; |
|
| 578 | + case IMAGETYPE_PNG: // 3 |
|
| 579 | + imagepng($imgThumb, $imgThumbName, $newquality); |
|
| 580 | + break; |
|
| 581 | + case IMAGETYPE_BMP: // 6 |
|
| 582 | 582 | // Not supported by PHP GD |
| 583 | - break; |
|
| 584 | - case IMAGETYPE_WBMP: // 15 |
|
| 585 | - image2wbmp($imgThumb, $imgThumbName); |
|
| 586 | - break; |
|
| 587 | - } |
|
| 583 | + break; |
|
| 584 | + case IMAGETYPE_WBMP: // 15 |
|
| 585 | + image2wbmp($imgThumb, $imgThumbName); |
|
| 586 | + break; |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - // Set permissions on file |
|
| 590 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 589 | + // Set permissions on file |
|
| 590 | + if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 591 | 591 | |
| 592 | 592 | // Free memory. This does not delete image. |
| 593 | 593 | imagedestroy($img); |
| 594 | 594 | imagedestroy($imgThumb); |
| 595 | 595 | |
| 596 | - return $imgThumbName; |
|
| 596 | + return $imgThumbName; |
|
| 597 | 597 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | // Define size of logo small and mini |
| 26 | -$maxwidthsmall=270;$maxheightsmall=150; |
|
| 27 | -$maxwidthmini=128;$maxheightmini=72; |
|
| 26 | +$maxwidthsmall = 270; $maxheightsmall = 150; |
|
| 27 | +$maxwidthmini = 128; $maxheightmini = 72; |
|
| 28 | 28 | $quality = 80; |
| 29 | 29 | |
| 30 | 30 | |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function image_format_supported($file) |
| 39 | 39 | { |
| 40 | - $regeximgext='\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm|\.svg'; // See also into product.class.php |
|
| 40 | + $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm|\.svg'; // See also into product.class.php |
|
| 41 | 41 | |
| 42 | 42 | // Case filename is not a format image |
| 43 | - if (! preg_match('/('.$regeximgext.')$/i',$file,$reg)) return -1; |
|
| 43 | + if (!preg_match('/('.$regeximgext.')$/i', $file, $reg)) return -1; |
|
| 44 | 44 | |
| 45 | 45 | // Case filename is a format image but not supported by this PHP |
| 46 | - $imgfonction=''; |
|
| 46 | + $imgfonction = ''; |
|
| 47 | 47 | if (strtolower($reg[1]) == '.gif') $imgfonction = 'imagecreatefromgif'; |
| 48 | 48 | if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng'; |
| 49 | 49 | if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg'; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | if (strtolower($reg[1]) == '.xbm') $imgfonction = 'imagecreatefromxbm'; |
| 54 | 54 | if ($imgfonction) |
| 55 | 55 | { |
| 56 | - if (! function_exists($imgfonction)) |
|
| 56 | + if (!function_exists($imgfonction)) |
|
| 57 | 57 | { |
| 58 | 58 | // Fonctions de conversion non presente dans ce PHP |
| 59 | 59 | return 0; |
@@ -74,21 +74,21 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | function dol_getImageSize($file, $url = false) |
| 76 | 76 | { |
| 77 | - $ret=array(); |
|
| 77 | + $ret = array(); |
|
| 78 | 78 | |
| 79 | 79 | if (image_format_supported($file) < 0) return $ret; |
| 80 | 80 | |
| 81 | 81 | $filetoread = $file; |
| 82 | 82 | if (!$url) |
| 83 | 83 | { |
| 84 | - $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 84 | + $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | if ($filetoread) |
| 88 | 88 | { |
| 89 | 89 | $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
| 90 | - $ret['width']=$infoImg[0]; // Largeur de l'image |
|
| 91 | - $ret['height']=$infoImg[1]; // Hauteur de l'image |
|
| 90 | + $ret['width'] = $infoImg[0]; // Largeur de l'image |
|
| 91 | + $ret['height'] = $infoImg[1]; // Hauteur de l'image |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return $ret; |
@@ -106,33 +106,33 @@ discard block |
||
| 106 | 106 | * @param int $src_y Position of croping image in source image (not use if mode=0) |
| 107 | 107 | * @return int File name if OK, error message if KO |
| 108 | 108 | */ |
| 109 | -function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0) |
|
| 109 | +function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0, $src_y = 0) |
|
| 110 | 110 | { |
| 111 | 111 | require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
| 112 | 112 | |
| 113 | - global $conf,$langs; |
|
| 113 | + global $conf, $langs; |
|
| 114 | 114 | |
| 115 | 115 | dol_syslog("dol_imageResizeOrCrop file=".$file." mode=".$mode." newWidth=".$newWidth." newHeight=".$newHeight." src_x=".$src_x." src_y=".$src_y); |
| 116 | 116 | |
| 117 | 117 | // Clean parameters |
| 118 | - $file=trim($file); |
|
| 118 | + $file = trim($file); |
|
| 119 | 119 | |
| 120 | 120 | // Check parameters |
| 121 | - if (! $file) |
|
| 121 | + if (!$file) |
|
| 122 | 122 | { |
| 123 | 123 | // Si le fichier n'a pas ete indique |
| 124 | 124 | return 'Bad parameter file'; |
| 125 | 125 | } |
| 126 | - elseif (! file_exists($file)) |
|
| 126 | + elseif (!file_exists($file)) |
|
| 127 | 127 | { |
| 128 | 128 | // Si le fichier passe en parametre n'existe pas |
| 129 | - return $langs->trans("ErrorFileNotFound",$file); |
|
| 129 | + return $langs->trans("ErrorFileNotFound", $file); |
|
| 130 | 130 | } |
| 131 | - elseif(image_format_supported($file) < 0) |
|
| 131 | + elseif (image_format_supported($file) < 0) |
|
| 132 | 132 | { |
| 133 | 133 | return 'This filename '.$file.' does not seem to be an image filename.'; |
| 134 | 134 | } |
| 135 | - elseif(!is_numeric($newWidth) && !is_numeric($newHeight)) |
|
| 135 | + elseif (!is_numeric($newWidth) && !is_numeric($newHeight)) |
|
| 136 | 136 | { |
| 137 | 137 | return 'Wrong value for parameter newWidth or newHeight'; |
| 138 | 138 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | return 'Both newHeight or newWidth must be defined for croping'; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 148 | + $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 149 | 149 | |
| 150 | 150 | $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
| 151 | 151 | $imgWidth = $infoImg[0]; // Largeur de l'image |
@@ -153,18 +153,18 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | if ($mode == 0) // If resize, we check parameters |
| 155 | 155 | { |
| 156 | - if ($newWidth <= 0) |
|
| 156 | + if ($newWidth <= 0) |
|
| 157 | 157 | { |
| 158 | - $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio |
|
| 158 | + $newWidth = intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio |
|
| 159 | 159 | } |
| 160 | 160 | if ($newHeight <= 0) |
| 161 | 161 | { |
| 162 | - $newHeight=intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio |
|
| 162 | + $newHeight = intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $imgfonction=''; |
|
| 167 | - switch($infoImg[2]) |
|
| 166 | + $imgfonction = ''; |
|
| 167 | + switch ($infoImg[2]) |
|
| 168 | 168 | { |
| 169 | 169 | case 1: // IMG_GIF |
| 170 | 170 | $imgfonction = 'imagecreatefromgif'; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | if ($imgfonction) |
| 183 | 183 | { |
| 184 | - if (! function_exists($imgfonction)) |
|
| 184 | + if (!function_exists($imgfonction)) |
|
| 185 | 185 | { |
| 186 | 186 | // Fonctions de conversion non presente dans ce PHP |
| 187 | 187 | return 'Resize not possible. This PHP does not support GD functions '.$imgfonction; |
@@ -189,27 +189,27 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // Initialisation des variables selon l'extension de l'image |
| 192 | - switch($infoImg[2]) |
|
| 192 | + switch ($infoImg[2]) |
|
| 193 | 193 | { |
| 194 | 194 | case 1: // Gif |
| 195 | 195 | $img = imagecreatefromgif($filetoread); |
| 196 | - $extImg = '.gif'; // File name extension of image |
|
| 197 | - $newquality='NU'; // Quality is not used for this format |
|
| 196 | + $extImg = '.gif'; // File name extension of image |
|
| 197 | + $newquality = 'NU'; // Quality is not used for this format |
|
| 198 | 198 | break; |
| 199 | 199 | case 2: // Jpg |
| 200 | 200 | $img = imagecreatefromjpeg($filetoread); |
| 201 | 201 | $extImg = '.jpg'; |
| 202 | - $newquality=100; // % quality maximum |
|
| 202 | + $newquality = 100; // % quality maximum |
|
| 203 | 203 | break; |
| 204 | 204 | case 3: // Png |
| 205 | 205 | $img = imagecreatefrompng($filetoread); |
| 206 | 206 | $extImg = '.png'; |
| 207 | - $newquality=0; // No compression (0-9) |
|
| 207 | + $newquality = 0; // No compression (0-9) |
|
| 208 | 208 | break; |
| 209 | 209 | case 4: // Bmp |
| 210 | 210 | $img = imagecreatefromwbmp($filetoread); |
| 211 | 211 | $extImg = '.bmp'; |
| 212 | - $newquality='NU'; // Quality is not used for this format |
|
| 212 | + $newquality = 'NU'; // Quality is not used for this format |
|
| 213 | 213 | break; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -237,18 +237,18 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Initialisation des variables selon l'extension de l'image |
| 240 | - switch($infoImg[2]) |
|
| 240 | + switch ($infoImg[2]) |
|
| 241 | 241 | { |
| 242 | 242 | case 1: // Gif |
| 243 | 243 | $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF |
| 244 | - imagecolortransparent($imgThumb,$trans_colour); |
|
| 244 | + imagecolortransparent($imgThumb, $trans_colour); |
|
| 245 | 245 | break; |
| 246 | 246 | case 2: // Jpg |
| 247 | 247 | $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
| 248 | 248 | break; |
| 249 | 249 | case 3: // Png |
| 250 | - imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme |
|
| 251 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 250 | + imagealphablending($imgThumb, false); // Pour compatibilite sur certain systeme |
|
| 251 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 252 | 252 | break; |
| 253 | 253 | case 4: // Bmp |
| 254 | 254 | $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality"); |
| 260 | 260 | //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
| 261 | - imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode==0?$imgWidth:$newWidth), ($mode==0?$imgHeight:$newHeight)); // Insere l'image de base redimensionnee |
|
| 261 | + imagecopyresampled($imgThumb, $img, 0, 0, $src_x, $src_y, $newWidth, $newHeight, ($mode == 0 ? $imgWidth : $newWidth), ($mode == 0 ? $imgHeight : $newHeight)); // Insere l'image de base redimensionnee |
|
| 262 | 262 | |
| 263 | 263 | $imgThumbName = $file; |
| 264 | 264 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | //fclose($fp); |
| 268 | 268 | |
| 269 | 269 | // Create image on disk |
| 270 | - switch($infoImg[2]) |
|
| 270 | + switch ($infoImg[2]) |
|
| 271 | 271 | { |
| 272 | 272 | case 1: // Gif |
| 273 | 273 | imagegif($imgThumb, $imgThumbName); |
@@ -284,13 +284,13 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Set permissions on file |
| 287 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 287 | + if (!empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 288 | 288 | |
| 289 | 289 | // Free memory. This does not delete image. |
| 290 | 290 | imagedestroy($img); |
| 291 | 291 | imagedestroy($imgThumb); |
| 292 | 292 | |
| 293 | - clearstatcache(); // File was replaced by a modified one, so we clear file caches. |
|
| 293 | + clearstatcache(); // File was replaced by a modified one, so we clear file caches. |
|
| 294 | 294 | |
| 295 | 295 | return $imgThumbName; |
| 296 | 296 | } |
@@ -349,64 +349,64 @@ discard block |
||
| 349 | 349 | * @param int $targetformat New format of target (IMAGETYPE_GIF, IMAGETYPE_JPG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_WBMP ... or 0 to keep old format) |
| 350 | 350 | * @return string Full path of thumb or '' if it fails or 'Error...' if it fails |
| 351 | 351 | */ |
| 352 | -function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0) |
|
| 352 | +function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small', $quality = 50, $outdir = 'thumbs', $targetformat = 0) |
|
| 353 | 353 | { |
| 354 | 354 | require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
| 355 | 355 | |
| 356 | - global $conf,$langs; |
|
| 356 | + global $conf, $langs; |
|
| 357 | 357 | |
| 358 | 358 | dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." outdir=".$outdir." targetformat=".$targetformat); |
| 359 | 359 | |
| 360 | 360 | // Clean parameters |
| 361 | - $file=trim($file); |
|
| 361 | + $file = trim($file); |
|
| 362 | 362 | |
| 363 | 363 | // Check parameters |
| 364 | - if (! $file) |
|
| 364 | + if (!$file) |
|
| 365 | 365 | { |
| 366 | 366 | // Si le fichier n'a pas ete indique |
| 367 | 367 | return 'ErrorBadParameters'; |
| 368 | 368 | } |
| 369 | - elseif (! file_exists($file)) |
|
| 369 | + elseif (!file_exists($file)) |
|
| 370 | 370 | { |
| 371 | 371 | // Si le fichier passe en parametre n'existe pas |
| 372 | - dol_syslog($langs->trans("ErrorFileNotFound",$file),LOG_ERR); |
|
| 373 | - return $langs->trans("ErrorFileNotFound",$file); |
|
| 372 | + dol_syslog($langs->trans("ErrorFileNotFound", $file), LOG_ERR); |
|
| 373 | + return $langs->trans("ErrorFileNotFound", $file); |
|
| 374 | 374 | } |
| 375 | - elseif(image_format_supported($file) < 0) |
|
| 375 | + elseif (image_format_supported($file) < 0) |
|
| 376 | 376 | { |
| 377 | - dol_syslog('This file '.$file.' does not seem to be an image format file name.',LOG_WARNING); |
|
| 377 | + dol_syslog('This file '.$file.' does not seem to be an image format file name.', LOG_WARNING); |
|
| 378 | 378 | return 'ErrorBadImageFormat'; |
| 379 | 379 | } |
| 380 | - elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ |
|
| 380 | + elseif (!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1) { |
|
| 381 | 381 | // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
| 382 | - dol_syslog('Wrong value for parameter maxWidth',LOG_ERR); |
|
| 382 | + dol_syslog('Wrong value for parameter maxWidth', LOG_ERR); |
|
| 383 | 383 | return 'Error: Wrong value for parameter maxWidth'; |
| 384 | 384 | } |
| 385 | - elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ |
|
| 385 | + elseif (!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1) { |
|
| 386 | 386 | // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
| 387 | - dol_syslog('Wrong value for parameter maxHeight',LOG_ERR); |
|
| 387 | + dol_syslog('Wrong value for parameter maxHeight', LOG_ERR); |
|
| 388 | 388 | return 'Error: Wrong value for parameter maxHeight'; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 391 | + $filetoread = realpath(dol_osencode($file)); // Chemin canonique absolu de l'image |
|
| 392 | 392 | |
| 393 | 393 | $infoImg = getimagesize($filetoread); // Recuperation des infos de l'image |
| 394 | 394 | $imgWidth = $infoImg[0]; // Largeur de l'image |
| 395 | 395 | $imgHeight = $infoImg[1]; // Hauteur de l'image |
| 396 | 396 | |
| 397 | - if ($maxWidth == -1) $maxWidth=$infoImg[0]; // If size is -1, we keep unchanged |
|
| 398 | - if ($maxHeight == -1) $maxHeight=$infoImg[1]; // If size is -1, we keep unchanged |
|
| 397 | + if ($maxWidth == -1) $maxWidth = $infoImg[0]; // If size is -1, we keep unchanged |
|
| 398 | + if ($maxHeight == -1) $maxHeight = $infoImg[1]; // If size is -1, we keep unchanged |
|
| 399 | 399 | |
| 400 | 400 | // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette |
| 401 | 401 | if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) |
| 402 | 402 | { |
| 403 | 403 | // On cree toujours les vignettes |
| 404 | - dol_syslog("File size is smaller than thumb size",LOG_DEBUG); |
|
| 404 | + dol_syslog("File size is smaller than thumb size", LOG_DEBUG); |
|
| 405 | 405 | //return 'Le fichier '.$file.' ne necessite pas de creation de vignette'; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | - $imgfonction=''; |
|
| 409 | - switch($infoImg[2]) |
|
| 408 | + $imgfonction = ''; |
|
| 409 | + switch ($infoImg[2]) |
|
| 410 | 410 | { |
| 411 | 411 | case IMAGETYPE_GIF: // 1 |
| 412 | 412 | $imgfonction = 'imagecreatefromgif'; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | } |
| 427 | 427 | if ($imgfonction) |
| 428 | 428 | { |
| 429 | - if (! function_exists($imgfonction)) |
|
| 429 | + if (!function_exists($imgfonction)) |
|
| 430 | 430 | { |
| 431 | 431 | // Fonctions de conversion non presente dans ce PHP |
| 432 | 432 | return 'Error: Creation of thumbs not possible. This PHP does not support GD function '.$imgfonction; |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // On cree le repertoire contenant les vignettes |
| 437 | - $dirthumb = dirname($file).($outdir?'/'.$outdir:''); // Chemin du dossier contenant les vignettes |
|
| 437 | + $dirthumb = dirname($file).($outdir ? '/'.$outdir : ''); // Chemin du dossier contenant les vignettes |
|
| 438 | 438 | dol_mkdir($dirthumb); |
| 439 | 439 | |
| 440 | 440 | // Initialisation des variables selon l'extension de l'image |
| 441 | - $img=null; |
|
| 442 | - switch($infoImg[2]) |
|
| 441 | + $img = null; |
|
| 442 | + switch ($infoImg[2]) |
|
| 443 | 443 | { |
| 444 | 444 | case IMAGETYPE_GIF: // 1 |
| 445 | 445 | $img = imagecreatefromgif($filetoread); |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | break; |
| 448 | 448 | case IMAGETYPE_JPEG: // 2 |
| 449 | 449 | $img = imagecreatefromjpeg($filetoread); |
| 450 | - $extImg = (preg_match('/\.jpeg$/',$file)?'.jpeg':'.jpg'); // Extension de l'image |
|
| 450 | + $extImg = (preg_match('/\.jpeg$/', $file) ? '.jpeg' : '.jpg'); // Extension de l'image |
|
| 451 | 451 | break; |
| 452 | 452 | case IMAGETYPE_PNG: // 3 |
| 453 | 453 | $img = imagecreatefrompng($filetoread); |
@@ -462,21 +462,21 @@ discard block |
||
| 462 | 462 | $extImg = '.bmp'; |
| 463 | 463 | break; |
| 464 | 464 | } |
| 465 | - if (! is_resource($img)) |
|
| 465 | + if (!is_resource($img)) |
|
| 466 | 466 | { |
| 467 | 467 | dol_syslog('Failed to detect type of image. We found infoImg[2]='.$infoImg[2], LOG_WARNING); |
| 468 | 468 | return 0; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | // Initialisation des dimensions de la vignette si elles sont superieures a l'original |
| 472 | - if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } |
|
| 473 | - if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; } |
|
| 472 | + if ($maxWidth > $imgWidth) { $maxWidth = $imgWidth; } |
|
| 473 | + if ($maxHeight > $imgHeight) { $maxHeight = $imgHeight; } |
|
| 474 | 474 | |
| 475 | - $whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette |
|
| 476 | - $imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original |
|
| 475 | + $whFact = $maxWidth / $maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette |
|
| 476 | + $imgWhFact = $imgWidth / $imgHeight; // Facteur largeur/hauteur de l'original |
|
| 477 | 477 | |
| 478 | 478 | // Fixe les dimensions de la vignette |
| 479 | - if($whFact < $imgWhFact) |
|
| 479 | + if ($whFact < $imgWhFact) |
|
| 480 | 480 | { |
| 481 | 481 | // Si largeur determinante |
| 482 | 482 | $thumbWidth = $maxWidth; |
@@ -488,11 +488,11 @@ discard block |
||
| 488 | 488 | $thumbHeight = $maxHeight; |
| 489 | 489 | $thumbWidth = $thumbHeight * $imgWhFact; |
| 490 | 490 | } |
| 491 | - $thumbHeight=round($thumbHeight); |
|
| 492 | - $thumbWidth=round($thumbWidth); |
|
| 491 | + $thumbHeight = round($thumbHeight); |
|
| 492 | + $thumbWidth = round($thumbWidth); |
|
| 493 | 493 | |
| 494 | 494 | // Define target format |
| 495 | - if (empty($targetformat)) $targetformat=$infoImg[2]; |
|
| 495 | + if (empty($targetformat)) $targetformat = $infoImg[2]; |
|
| 496 | 496 | |
| 497 | 497 | // Create empty image |
| 498 | 498 | if ($targetformat == IMAGETYPE_GIF) |
@@ -519,35 +519,35 @@ discard block |
||
| 519 | 519 | |
| 520 | 520 | // Initialisation des variables selon l'extension de l'image |
| 521 | 521 | // $targetformat is 0 by default, in such case, we keep original extension |
| 522 | - switch($targetformat) |
|
| 522 | + switch ($targetformat) |
|
| 523 | 523 | { |
| 524 | 524 | case IMAGETYPE_GIF: // 1 |
| 525 | 525 | $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF |
| 526 | - imagecolortransparent($imgThumb,$trans_colour); |
|
| 526 | + imagecolortransparent($imgThumb, $trans_colour); |
|
| 527 | 527 | $extImgTarget = '.gif'; |
| 528 | - $newquality='NU'; |
|
| 528 | + $newquality = 'NU'; |
|
| 529 | 529 | break; |
| 530 | 530 | case IMAGETYPE_JPEG: // 2 |
| 531 | 531 | $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
| 532 | - $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'.jpg'); |
|
| 533 | - $newquality=$quality; |
|
| 532 | + $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '.jpg'); |
|
| 533 | + $newquality = $quality; |
|
| 534 | 534 | break; |
| 535 | 535 | case IMAGETYPE_PNG: // 3 |
| 536 | - imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme |
|
| 537 | - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 536 | + imagealphablending($imgThumb, false); // Pour compatibilite sur certain systeme |
|
| 537 | + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel |
|
| 538 | 538 | $extImgTarget = '.png'; |
| 539 | - $newquality=$quality-100; |
|
| 540 | - $newquality=round(abs($quality-100)*9/100); |
|
| 539 | + $newquality = $quality - 100; |
|
| 540 | + $newquality = round(abs($quality - 100) * 9 / 100); |
|
| 541 | 541 | break; |
| 542 | 542 | case IMAGETYPE_BMP: // 6 |
| 543 | 543 | // Not supported by PHP GD |
| 544 | 544 | $extImgTarget = '.bmp'; |
| 545 | - $newquality='NU'; |
|
| 545 | + $newquality = 'NU'; |
|
| 546 | 546 | break; |
| 547 | 547 | case IMAGETYPE_WBMP: // 15 |
| 548 | 548 | $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
| 549 | 549 | $extImgTarget = '.bmp'; |
| 550 | - $newquality='NU'; |
|
| 550 | + $newquality = 'NU'; |
|
| 551 | 551 | break; |
| 552 | 552 | } |
| 553 | 553 | if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
@@ -556,10 +556,10 @@ discard block |
||
| 556 | 556 | //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
| 557 | 557 | imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
| 558 | 558 | |
| 559 | - $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse |
|
| 559 | + $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i', '', $file); // On enleve extension quelquesoit la casse |
|
| 560 | 560 | $fileName = basename($fileName); |
| 561 | 561 | //$imgThumbName = $dirthumb.'/'.getImageFileNameForSize(basename($file), $extName, $extImgTarget); // Full path of thumb file |
| 562 | - $imgThumbName = getImageFileNameForSize($file, $extName, $extImgTarget); // Full path of thumb file |
|
| 562 | + $imgThumbName = getImageFileNameForSize($file, $extName, $extImgTarget); // Full path of thumb file |
|
| 563 | 563 | |
| 564 | 564 | |
| 565 | 565 | // Check if permission are ok |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | //fclose($fp); |
| 568 | 568 | |
| 569 | 569 | // Create image on disk |
| 570 | - switch($targetformat) |
|
| 570 | + switch ($targetformat) |
|
| 571 | 571 | { |
| 572 | 572 | case IMAGETYPE_GIF: // 1 |
| 573 | 573 | imagegif($imgThumb, $imgThumbName); |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | // Set permissions on file |
| 590 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 590 | + if (!empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 591 | 591 | |
| 592 | 592 | // Free memory. This does not delete image. |
| 593 | 593 | imagedestroy($img); |
@@ -40,17 +40,33 @@ discard block |
||
| 40 | 40 | $regeximgext='\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm|\.svg'; // See also into product.class.php |
| 41 | 41 | |
| 42 | 42 | // Case filename is not a format image |
| 43 | - if (! preg_match('/('.$regeximgext.')$/i',$file,$reg)) return -1; |
|
| 43 | + if (! preg_match('/('.$regeximgext.')$/i',$file,$reg)) { |
|
| 44 | + return -1; |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | // Case filename is a format image but not supported by this PHP |
| 46 | 48 | $imgfonction=''; |
| 47 | - if (strtolower($reg[1]) == '.gif') $imgfonction = 'imagecreatefromgif'; |
|
| 48 | - if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng'; |
|
| 49 | - if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg'; |
|
| 50 | - if (strtolower($reg[1]) == '.jpeg') $imgfonction = 'imagecreatefromjpeg'; |
|
| 51 | - if (strtolower($reg[1]) == '.bmp') $imgfonction = 'imagecreatefromwbmp'; |
|
| 52 | - if (strtolower($reg[1]) == '.xpm') $imgfonction = 'imagecreatefromxpm'; |
|
| 53 | - if (strtolower($reg[1]) == '.xbm') $imgfonction = 'imagecreatefromxbm'; |
|
| 49 | + if (strtolower($reg[1]) == '.gif') { |
|
| 50 | + $imgfonction = 'imagecreatefromgif'; |
|
| 51 | + } |
|
| 52 | + if (strtolower($reg[1]) == '.png') { |
|
| 53 | + $imgfonction = 'imagecreatefrompng'; |
|
| 54 | + } |
|
| 55 | + if (strtolower($reg[1]) == '.jpg') { |
|
| 56 | + $imgfonction = 'imagecreatefromjpeg'; |
|
| 57 | + } |
|
| 58 | + if (strtolower($reg[1]) == '.jpeg') { |
|
| 59 | + $imgfonction = 'imagecreatefromjpeg'; |
|
| 60 | + } |
|
| 61 | + if (strtolower($reg[1]) == '.bmp') { |
|
| 62 | + $imgfonction = 'imagecreatefromwbmp'; |
|
| 63 | + } |
|
| 64 | + if (strtolower($reg[1]) == '.xpm') { |
|
| 65 | + $imgfonction = 'imagecreatefromxpm'; |
|
| 66 | + } |
|
| 67 | + if (strtolower($reg[1]) == '.xbm') { |
|
| 68 | + $imgfonction = 'imagecreatefromxbm'; |
|
| 69 | + } |
|
| 54 | 70 | if ($imgfonction) |
| 55 | 71 | { |
| 56 | 72 | if (! function_exists($imgfonction)) |
@@ -76,7 +92,9 @@ discard block |
||
| 76 | 92 | { |
| 77 | 93 | $ret=array(); |
| 78 | 94 | |
| 79 | - if (image_format_supported($file) < 0) return $ret; |
|
| 95 | + if (image_format_supported($file) < 0) { |
|
| 96 | + return $ret; |
|
| 97 | + } |
|
| 80 | 98 | |
| 81 | 99 | $filetoread = $file; |
| 82 | 100 | if (!$url) |
@@ -122,25 +140,20 @@ discard block |
||
| 122 | 140 | { |
| 123 | 141 | // Si le fichier n'a pas ete indique |
| 124 | 142 | return 'Bad parameter file'; |
| 125 | - } |
|
| 126 | - elseif (! file_exists($file)) |
|
| 143 | + } elseif (! file_exists($file)) |
|
| 127 | 144 | { |
| 128 | 145 | // Si le fichier passe en parametre n'existe pas |
| 129 | 146 | return $langs->trans("ErrorFileNotFound",$file); |
| 130 | - } |
|
| 131 | - elseif(image_format_supported($file) < 0) |
|
| 147 | + } elseif(image_format_supported($file) < 0) |
|
| 132 | 148 | { |
| 133 | 149 | return 'This filename '.$file.' does not seem to be an image filename.'; |
| 134 | - } |
|
| 135 | - elseif(!is_numeric($newWidth) && !is_numeric($newHeight)) |
|
| 150 | + } elseif(!is_numeric($newWidth) && !is_numeric($newHeight)) |
|
| 136 | 151 | { |
| 137 | 152 | return 'Wrong value for parameter newWidth or newHeight'; |
| 138 | - } |
|
| 139 | - elseif ($mode == 0 && $newWidth <= 0 && $newHeight <= 0) |
|
| 153 | + } elseif ($mode == 0 && $newWidth <= 0 && $newHeight <= 0) |
|
| 140 | 154 | { |
| 141 | 155 | return 'At least newHeight or newWidth must be defined for resizing'; |
| 142 | - } |
|
| 143 | - elseif ($mode == 1 && ($newWidth <= 0 || $newHeight <= 0)) |
|
| 156 | + } elseif ($mode == 1 && ($newWidth <= 0 || $newHeight <= 0)) |
|
| 144 | 157 | { |
| 145 | 158 | return 'Both newHeight or newWidth must be defined for croping'; |
| 146 | 159 | } |
@@ -151,11 +164,14 @@ discard block |
||
| 151 | 164 | $imgWidth = $infoImg[0]; // Largeur de l'image |
| 152 | 165 | $imgHeight = $infoImg[1]; // Hauteur de l'image |
| 153 | 166 | |
| 154 | - if ($mode == 0) // If resize, we check parameters |
|
| 167 | + if ($mode == 0) { |
|
| 168 | + // If resize, we check parameters |
|
| 155 | 169 | { |
| 156 | 170 | if ($newWidth <= 0) |
| 157 | 171 | { |
| 158 | - $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio |
|
| 172 | + $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); |
|
| 173 | + } |
|
| 174 | + // Keep ratio |
|
| 159 | 175 | } |
| 160 | 176 | if ($newHeight <= 0) |
| 161 | 177 | { |
@@ -218,8 +234,7 @@ discard block |
||
| 218 | 234 | { |
| 219 | 235 | // Compatibilite image GIF |
| 220 | 236 | $imgThumb = imagecreate($newWidth, $newHeight); |
| 221 | - } |
|
| 222 | - else |
|
| 237 | + } else |
|
| 223 | 238 | { |
| 224 | 239 | $imgThumb = imagecreatetruecolor($newWidth, $newHeight); |
| 225 | 240 | } |
@@ -254,7 +269,9 @@ discard block |
||
| 254 | 269 | $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); |
| 255 | 270 | break; |
| 256 | 271 | } |
| 257 | - if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 272 | + if (function_exists("imagefill")) { |
|
| 273 | + imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 274 | + } |
|
| 258 | 275 | |
| 259 | 276 | dol_syslog("dol_imageResizeOrCrop: convert image from ($imgWidth x $imgHeight) at position ($src_x x $src_y) to ($newWidth x $newHeight) as $extImg, newquality=$newquality"); |
| 260 | 277 | //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
@@ -284,7 +301,9 @@ discard block |
||
| 284 | 301 | } |
| 285 | 302 | |
| 286 | 303 | // Set permissions on file |
| 287 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 304 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 305 | + @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 306 | + } |
|
| 288 | 307 | |
| 289 | 308 | // Free memory. This does not delete image. |
| 290 | 309 | imagedestroy($img); |
@@ -365,24 +384,20 @@ discard block |
||
| 365 | 384 | { |
| 366 | 385 | // Si le fichier n'a pas ete indique |
| 367 | 386 | return 'ErrorBadParameters'; |
| 368 | - } |
|
| 369 | - elseif (! file_exists($file)) |
|
| 387 | + } elseif (! file_exists($file)) |
|
| 370 | 388 | { |
| 371 | 389 | // Si le fichier passe en parametre n'existe pas |
| 372 | 390 | dol_syslog($langs->trans("ErrorFileNotFound",$file),LOG_ERR); |
| 373 | 391 | return $langs->trans("ErrorFileNotFound",$file); |
| 374 | - } |
|
| 375 | - elseif(image_format_supported($file) < 0) |
|
| 392 | + } elseif(image_format_supported($file) < 0) |
|
| 376 | 393 | { |
| 377 | 394 | dol_syslog('This file '.$file.' does not seem to be an image format file name.',LOG_WARNING); |
| 378 | 395 | return 'ErrorBadImageFormat'; |
| 379 | - } |
|
| 380 | - elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ |
|
| 396 | + } elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ |
|
| 381 | 397 | // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
| 382 | 398 | dol_syslog('Wrong value for parameter maxWidth',LOG_ERR); |
| 383 | 399 | return 'Error: Wrong value for parameter maxWidth'; |
| 384 | - } |
|
| 385 | - elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ |
|
| 400 | + } elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ |
|
| 386 | 401 | // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) |
| 387 | 402 | dol_syslog('Wrong value for parameter maxHeight',LOG_ERR); |
| 388 | 403 | return 'Error: Wrong value for parameter maxHeight'; |
@@ -394,8 +409,14 @@ discard block |
||
| 394 | 409 | $imgWidth = $infoImg[0]; // Largeur de l'image |
| 395 | 410 | $imgHeight = $infoImg[1]; // Hauteur de l'image |
| 396 | 411 | |
| 397 | - if ($maxWidth == -1) $maxWidth=$infoImg[0]; // If size is -1, we keep unchanged |
|
| 398 | - if ($maxHeight == -1) $maxHeight=$infoImg[1]; // If size is -1, we keep unchanged |
|
| 412 | + if ($maxWidth == -1) { |
|
| 413 | + $maxWidth=$infoImg[0]; |
|
| 414 | + } |
|
| 415 | + // If size is -1, we keep unchanged |
|
| 416 | + if ($maxHeight == -1) { |
|
| 417 | + $maxHeight=$infoImg[1]; |
|
| 418 | + } |
|
| 419 | + // If size is -1, we keep unchanged |
|
| 399 | 420 | |
| 400 | 421 | // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette |
| 401 | 422 | if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) |
@@ -481,8 +502,7 @@ discard block |
||
| 481 | 502 | // Si largeur determinante |
| 482 | 503 | $thumbWidth = $maxWidth; |
| 483 | 504 | $thumbHeight = $thumbWidth / $imgWhFact; |
| 484 | - } |
|
| 485 | - else |
|
| 505 | + } else |
|
| 486 | 506 | { |
| 487 | 507 | // Si hauteur determinante |
| 488 | 508 | $thumbHeight = $maxHeight; |
@@ -492,15 +512,16 @@ discard block |
||
| 492 | 512 | $thumbWidth=round($thumbWidth); |
| 493 | 513 | |
| 494 | 514 | // Define target format |
| 495 | - if (empty($targetformat)) $targetformat=$infoImg[2]; |
|
| 515 | + if (empty($targetformat)) { |
|
| 516 | + $targetformat=$infoImg[2]; |
|
| 517 | + } |
|
| 496 | 518 | |
| 497 | 519 | // Create empty image |
| 498 | 520 | if ($targetformat == IMAGETYPE_GIF) |
| 499 | 521 | { |
| 500 | 522 | // Compatibilite image GIF |
| 501 | 523 | $imgThumb = imagecreate($thumbWidth, $thumbHeight); |
| 502 | - } |
|
| 503 | - else |
|
| 524 | + } else |
|
| 504 | 525 | { |
| 505 | 526 | $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); |
| 506 | 527 | } |
@@ -550,7 +571,9 @@ discard block |
||
| 550 | 571 | $newquality='NU'; |
| 551 | 572 | break; |
| 552 | 573 | } |
| 553 | - if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 574 | + if (function_exists("imagefill")) { |
|
| 575 | + imagefill($imgThumb, 0, 0, $trans_colour); |
|
| 576 | + } |
|
| 554 | 577 | |
| 555 | 578 | dol_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality"); |
| 556 | 579 | //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee |
@@ -587,7 +610,9 @@ discard block |
||
| 587 | 610 | } |
| 588 | 611 | |
| 589 | 612 | // Set permissions on file |
| 590 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 613 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 614 | + @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); |
|
| 615 | + } |
|
| 591 | 616 | |
| 592 | 617 | // Free memory. This does not delete image. |
| 593 | 618 | imagedestroy($img); |