@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @var string Error code (or message) |
| 38 | 38 | */ |
| 39 | - public $error=''; |
|
| 39 | + public $error = ''; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @var string[] Error codes (or messages) |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public $actiontype; |
| 47 | 47 | |
| 48 | - public $dirmodule; // Module directory |
|
| 49 | - public $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) |
|
| 50 | - public $canvas; // Name of canvas (ex: company, individual, product, service, ...) |
|
| 51 | - public $card; // Tab (sub-canvas) |
|
| 48 | + public $dirmodule; // Module directory |
|
| 49 | + public $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) |
|
| 50 | + public $canvas; // Name of canvas (ex: company, individual, product, service, ...) |
|
| 51 | + public $card; // Tab (sub-canvas) |
|
| 52 | 52 | |
| 53 | - public $template_dir; // Initialized by getCanvas with templates directory |
|
| 54 | - public $control; // Initialized by getCanvas with controller instance |
|
| 53 | + public $template_dir; // Initialized by getCanvas with templates directory |
|
| 54 | + public $control; // Initialized by getCanvas with controller instance |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param DoliDB $db Database handler |
| 61 | 61 | * @param string $actiontype Action type ('create', 'view', 'edit', 'list') |
| 62 | 62 | */ |
| 63 | - function __construct($db, $actiontype='view') |
|
| 63 | + function __construct($db, $actiontype = 'view') |
|
| 64 | 64 | { |
| 65 | 65 | $this->db = $db; |
| 66 | 66 | |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | private function _cleanaction($action) |
| 77 | 77 | { |
| 78 | 78 | $newaction = $action; |
| 79 | - if ($newaction == 'add') $newaction='create'; |
|
| 80 | - if ($newaction == 'update') $newaction='edit'; |
|
| 81 | - if (empty($newaction) || $newaction == 'delete' || $newaction == 'create_user' || $newaction == 'presend' || $newaction == 'send') $newaction='view'; |
|
| 79 | + if ($newaction == 'add') $newaction = 'create'; |
|
| 80 | + if ($newaction == 'update') $newaction = 'edit'; |
|
| 81 | + if (empty($newaction) || $newaction == 'delete' || $newaction == 'create_user' || $newaction == 'presend' || $newaction == 'send') $newaction = 'view'; |
|
| 82 | 82 | return $newaction; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->card = $card; |
| 102 | 102 | $this->dirmodule = $module; |
| 103 | 103 | // Correct values if canvas is into an external module |
| 104 | - if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs)) |
|
| 104 | + if (preg_match('/^([^@]+)@([^@]+)$/i', $canvas, $regs)) |
|
| 105 | 105 | { |
| 106 | 106 | $this->canvas = $regs[1]; |
| 107 | 107 | $this->dirmodule = $regs[2]; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | if (file_exists($controlclassfile)) |
| 115 | 115 | { |
| 116 | 116 | // Include actions class (controller) |
| 117 | - $this->control_file=$controlclassfile; |
|
| 117 | + $this->control_file = $controlclassfile; |
|
| 118 | 118 | require_once $controlclassfile; |
| 119 | 119 | |
| 120 | 120 | // Instantiate actions class (controller) |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | // Template dir |
| 126 | 126 | $this->template_dir = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/tpl/'); |
| 127 | - if (! is_dir($this->template_dir)) |
|
| 127 | + if (!is_dir($this->template_dir)) |
|
| 128 | 128 | { |
| 129 | - $this->template_dir=''; |
|
| 129 | + $this->template_dir = ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'<br>'; |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * @param string $ref Object ref (if id not provided) |
| 143 | 143 | * @return void |
| 144 | 144 | */ |
| 145 | - function assign_values(&$action='view', $id=0, $ref='') |
|
| 145 | + function assign_values(&$action = 'view', $id = 0, $ref = '') |
|
| 146 | 146 | { |
| 147 | 147 | // phpcs:enable |
| 148 | - if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id, $ref); |
|
| 148 | + if (method_exists($this->control, 'assign_values')) $this->control->assign_values($action, $id, $ref); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | if (empty($this->template_dir)) return 0; |
| 160 | 160 | |
| 161 | - if (file_exists($this->template_dir.(!empty($this->card)?$this->card.'_':'').$this->_cleanaction($action).'.tpl.php')) return 1; |
|
| 161 | + if (file_exists($this->template_dir.(!empty($this->card) ? $this->card.'_' : '').$this->_cleanaction($action).'.tpl.php')) return 1; |
|
| 162 | 162 | else return 0; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | global $db, $conf, $langs, $user, $canvas; |
| 177 | 177 | global $form, $formfile; |
| 178 | 178 | |
| 179 | - include $this->template_dir.(!empty($this->card)?$this->card.'_':'').$this->_cleanaction($action).'.tpl.php'; // Include native PHP template |
|
| 179 | + include $this->template_dir.(!empty($this->card) ? $this->card.'_' : '').$this->_cleanaction($action).'.tpl.php'; // Include native PHP template |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | * @return mixed Return return code of doActions of canvas |
| 205 | 205 | * @see http://wiki.dolibarr.org/index.php/Canvas_development |
| 206 | 206 | */ |
| 207 | - function doActions(&$action='view', $id=0) |
|
| 207 | + function doActions(&$action = 'view', $id = 0) |
|
| 208 | 208 | { |
| 209 | - if (method_exists($this->control,'doActions')) |
|
| 209 | + if (method_exists($this->control, 'doActions')) |
|
| 210 | 210 | { |
| 211 | 211 | $ret = $this->control->doActions($action, $id); |
| 212 | 212 | return $ret; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * @var Array $_fields Fields to synchronize with Database |
| 34 | 34 | */ |
| 35 | - protected $fields=array(); |
|
| 35 | + protected $fields = array(); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Constructor |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | else $this->{$field} = ''; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $this->to_delete=false; |
|
| 70 | - $this->is_clone=false; |
|
| 69 | + $this->to_delete = false; |
|
| 70 | + $this->is_clone = false; |
|
| 71 | 71 | |
| 72 | 72 | return true; |
| 73 | 73 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | public function fetch($id, $loadChild = true) |
| 107 | 107 | { |
| 108 | 108 | $res = $this->fetchCommon($id); |
| 109 | - if($res>0) { |
|
| 109 | + if ($res > 0) { |
|
| 110 | 110 | if ($loadChild) $this->fetchChild(); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | * @param bool $try_to_load Force the fetch if an id is given |
| 124 | 124 | * @return int |
| 125 | 125 | */ |
| 126 | - public function addChild($tabName, $id=0, $key='id', $try_to_load = false) |
|
| 126 | + public function addChild($tabName, $id = 0, $key = 'id', $try_to_load = false) |
|
| 127 | 127 | { |
| 128 | - if(!empty($id)) |
|
| 128 | + if (!empty($id)) |
|
| 129 | 129 | { |
| 130 | - foreach($this->{$tabName} as $k=>&$object) |
|
| 130 | + foreach ($this->{$tabName} as $k=>&$object) |
|
| 131 | 131 | { |
| 132 | - if($object->{$key} === $id) return $k; |
|
| 132 | + if ($object->{$key} === $id) return $k; |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $className = ucfirst($tabName); |
| 139 | 139 | $this->{$tabName}[$k] = new $className($this->db); |
| 140 | - if($id>0 && $key==='id' && $try_to_load) |
|
| 140 | + if ($id > 0 && $key === 'id' && $try_to_load) |
|
| 141 | 141 | { |
| 142 | 142 | $this->{$tabName}[$k]->fetch($id); |
| 143 | 143 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param string $key Attribute name of the object id |
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | - public function removeChild($tabName, $id, $key='id') |
|
| 157 | + public function removeChild($tabName, $id, $key = 'id') |
|
| 158 | 158 | { |
| 159 | 159 | foreach ($this->{$tabName} as &$object) |
| 160 | 160 | { |
@@ -175,22 +175,22 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function fetchChild() |
| 177 | 177 | { |
| 178 | - if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 178 | + if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 179 | 179 | { |
| 180 | - foreach($this->childtables as &$childTable) |
|
| 180 | + foreach ($this->childtables as &$childTable) |
|
| 181 | 181 | { |
| 182 | 182 | $className = ucfirst($childTable); |
| 183 | 183 | |
| 184 | - $this->{$className}=array(); |
|
| 184 | + $this->{$className} = array(); |
|
| 185 | 185 | |
| 186 | 186 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$childTable.' WHERE '.$this->fk_element.' = '.$this->id; |
| 187 | 187 | $res = $this->db->query($sql); |
| 188 | 188 | |
| 189 | - if($res) |
|
| 189 | + if ($res) |
|
| 190 | 190 | { |
| 191 | - while($obj = $this->db->fetch_object($res)) |
|
| 191 | + while ($obj = $this->db->fetch_object($res)) |
|
| 192 | 192 | { |
| 193 | - $o=new $className($this->db); |
|
| 193 | + $o = new $className($this->db); |
|
| 194 | 194 | $o->fetch($obj->rowid); |
| 195 | 195 | |
| 196 | 196 | $this->{$className}[] = $o; |
@@ -212,19 +212,19 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function saveChild(User &$user) |
| 214 | 214 | { |
| 215 | - if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 215 | + if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 216 | 216 | { |
| 217 | - foreach($this->childtables as &$childTable) |
|
| 217 | + foreach ($this->childtables as &$childTable) |
|
| 218 | 218 | { |
| 219 | 219 | $className = ucfirst($childTable); |
| 220 | - if(!empty($this->{$className})) |
|
| 220 | + if (!empty($this->{$className})) |
|
| 221 | 221 | { |
| 222 | - foreach($this->{$className} as $i => &$object) |
|
| 222 | + foreach ($this->{$className} as $i => &$object) |
|
| 223 | 223 | { |
| 224 | 224 | $object->{$this->fk_element} = $this->id; |
| 225 | 225 | |
| 226 | 226 | $object->update($user); |
| 227 | - if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]); |
|
| 227 | + if ($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete == true) unset($this->{$className}[$i]); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | public function update(User &$user) |
| 242 | 242 | { |
| 243 | 243 | if (empty($this->id)) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed |
| 244 | - elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user); |
|
| 244 | + elseif (isset($this->to_delete) && $this->to_delete == true) return $this->delete($user); |
|
| 245 | 245 | |
| 246 | 246 | $error = 0; |
| 247 | 247 | $this->db->begin(); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $res = $this->updateCommon($user); |
| 250 | 250 | if ($res) |
| 251 | 251 | { |
| 252 | - $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user); |
|
| 252 | + $result = $this->call_trigger(strtoupper($this->element).'_UPDATE', $user); |
|
| 253 | 253 | if ($result < 0) $error++; |
| 254 | 254 | else $this->saveChild($user); |
| 255 | 255 | } |
@@ -280,17 +280,17 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | public function create(User &$user) |
| 282 | 282 | { |
| 283 | - if($this->id > 0) return $this->update($user); |
|
| 283 | + if ($this->id > 0) return $this->update($user); |
|
| 284 | 284 | |
| 285 | 285 | $error = 0; |
| 286 | 286 | $this->db->begin(); |
| 287 | 287 | |
| 288 | 288 | $res = $this->createCommon($user); |
| 289 | - if($res) |
|
| 289 | + if ($res) |
|
| 290 | 290 | { |
| 291 | 291 | $this->id = $this->db->last_insert_id($this->table_element); |
| 292 | 292 | |
| 293 | - $result = $this->call_trigger(strtoupper($this->element). '_CREATE', $user); |
|
| 293 | + $result = $this->call_trigger(strtoupper($this->element).'_CREATE', $user); |
|
| 294 | 294 | if ($result < 0) $error++; |
| 295 | 295 | else $this->saveChild($user); |
| 296 | 296 | } |
@@ -326,20 +326,20 @@ discard block |
||
| 326 | 326 | $error = 0; |
| 327 | 327 | $this->db->begin(); |
| 328 | 328 | |
| 329 | - $result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user); |
|
| 329 | + $result = $this->call_trigger(strtoupper($this->element).'_DELETE', $user); |
|
| 330 | 330 | if ($result < 0) $error++; |
| 331 | 331 | |
| 332 | 332 | if (!$error) |
| 333 | 333 | { |
| 334 | 334 | $this->deleteCommon($user); |
| 335 | - if($this->withChild && !empty($this->childtables)) |
|
| 335 | + if ($this->withChild && !empty($this->childtables)) |
|
| 336 | 336 | { |
| 337 | - foreach($this->childtables as &$childTable) |
|
| 337 | + foreach ($this->childtables as &$childTable) |
|
| 338 | 338 | { |
| 339 | 339 | $className = ucfirst($childTable); |
| 340 | 340 | if (!empty($this->{$className})) |
| 341 | 341 | { |
| 342 | - foreach($this->{$className} as &$object) |
|
| 342 | + foreach ($this->{$className} as &$object) |
|
| 343 | 343 | { |
| 344 | 344 | $object->delete($user); |
| 345 | 345 | } |
@@ -370,9 +370,9 @@ discard block |
||
| 370 | 370 | * @param string $format Output date format |
| 371 | 371 | * @return string |
| 372 | 372 | */ |
| 373 | - public function getDate($field, $format='') |
|
| 373 | + public function getDate($field, $format = '') |
|
| 374 | 374 | { |
| 375 | - if(empty($this->{$field})) return ''; |
|
| 375 | + if (empty($this->{$field})) return ''; |
|
| 376 | 376 | else |
| 377 | 377 | { |
| 378 | 378 | return dol_print_date($this->{$field}, $format); |
@@ -412,19 +412,19 @@ discard block |
||
| 412 | 412 | { |
| 413 | 413 | foreach ($Tab as $key => $value) |
| 414 | 414 | { |
| 415 | - if($this->checkFieldType($key, 'date')) |
|
| 415 | + if ($this->checkFieldType($key, 'date')) |
|
| 416 | 416 | { |
| 417 | 417 | $this->setDate($key, $value); |
| 418 | 418 | } |
| 419 | - else if( $this->checkFieldType($key, 'array')) |
|
| 419 | + else if ($this->checkFieldType($key, 'array')) |
|
| 420 | 420 | { |
| 421 | 421 | $this->{$key} = $value; |
| 422 | 422 | } |
| 423 | - else if( $this->checkFieldType($key, 'float') ) |
|
| 423 | + else if ($this->checkFieldType($key, 'float')) |
|
| 424 | 424 | { |
| 425 | 425 | $this->{$key} = (double) price2num($value); |
| 426 | 426 | } |
| 427 | - else if( $this->checkFieldType($key, 'int') ) { |
|
| 427 | + else if ($this->checkFieldType($key, 'int')) { |
|
| 428 | 428 | $this->{$key} = (int) price2num($value); |
| 429 | 429 | } |
| 430 | 430 | else |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * @var string Error code (or message) |
| 42 | 42 | */ |
| 43 | - public $error=''; |
|
| 43 | + public $error = ''; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * @var string[] Error codes (or messages) |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | * @deprecated |
| 63 | 63 | * @see name |
| 64 | 64 | */ |
| 65 | - public $nom=''; |
|
| 65 | + public $nom = ''; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @var string name |
| 69 | 69 | */ |
| 70 | - public $name=''; |
|
| 70 | + public $name = ''; |
|
| 71 | 71 | |
| 72 | 72 | public $active; |
| 73 | 73 | |
@@ -92,43 +92,43 @@ discard block |
||
| 92 | 92 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
| 93 | 93 | * @return int <0 if KO, Id of created object if OK |
| 94 | 94 | */ |
| 95 | - function create($user, $notrigger=0) |
|
| 95 | + function create($user, $notrigger = 0) |
|
| 96 | 96 | { |
| 97 | 97 | global $conf, $langs; |
| 98 | - $error=0; |
|
| 98 | + $error = 0; |
|
| 99 | 99 | |
| 100 | 100 | // Clean parameters |
| 101 | - if (isset($this->code_departement)) $this->code_departement=trim($this->code_departement); |
|
| 102 | - if (isset($this->nom)) $this->nom=trim($this->nom); |
|
| 103 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 101 | + if (isset($this->code_departement)) $this->code_departement = trim($this->code_departement); |
|
| 102 | + if (isset($this->nom)) $this->nom = trim($this->nom); |
|
| 103 | + if (isset($this->active)) $this->active = trim($this->active); |
|
| 104 | 104 | |
| 105 | 105 | // Check parameters |
| 106 | 106 | // Put here code to add control on parameters values |
| 107 | 107 | |
| 108 | 108 | // Insert request |
| 109 | 109 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements("; |
| 110 | - $sql.= "rowid,"; |
|
| 111 | - $sql.= "code_departement,"; |
|
| 112 | - $sql.= "nom,"; |
|
| 113 | - $sql.= "active"; |
|
| 114 | - $sql.= ") VALUES ("; |
|
| 115 | - $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").","; |
|
| 116 | - $sql.= " ".(! isset($this->code_departement)?'NULL':"'".$this->db->escape($this->code_departement)."'").","; |
|
| 117 | - $sql.= " ".(! isset($this->nom)?'NULL':"'".$this->db->escape($this->nom)."'").","; |
|
| 118 | - $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'").""; |
|
| 119 | - $sql.= ")"; |
|
| 110 | + $sql .= "rowid,"; |
|
| 111 | + $sql .= "code_departement,"; |
|
| 112 | + $sql .= "nom,"; |
|
| 113 | + $sql .= "active"; |
|
| 114 | + $sql .= ") VALUES ("; |
|
| 115 | + $sql .= " ".(!isset($this->rowid) ? 'NULL' : "'".$this->db->escape($this->rowid)."'").","; |
|
| 116 | + $sql .= " ".(!isset($this->code_departement) ? 'NULL' : "'".$this->db->escape($this->code_departement)."'").","; |
|
| 117 | + $sql .= " ".(!isset($this->nom) ? 'NULL' : "'".$this->db->escape($this->nom)."'").","; |
|
| 118 | + $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'").""; |
|
| 119 | + $sql .= ")"; |
|
| 120 | 120 | |
| 121 | 121 | $this->db->begin(); |
| 122 | 122 | |
| 123 | 123 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
| 124 | - $resql=$this->db->query($sql); |
|
| 125 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 124 | + $resql = $this->db->query($sql); |
|
| 125 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
| 126 | 126 | |
| 127 | - if (! $error) |
|
| 127 | + if (!$error) |
|
| 128 | 128 | { |
| 129 | 129 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_departements"); |
| 130 | 130 | |
| 131 | - if (! $notrigger) |
|
| 131 | + if (!$notrigger) |
|
| 132 | 132 | { |
| 133 | 133 | // Uncomment this and change MYOBJECT to your own tag if you |
| 134 | 134 | // want this action call a trigger. |
@@ -145,13 +145,13 @@ discard block |
||
| 145 | 145 | // Commit or rollback |
| 146 | 146 | if ($error) |
| 147 | 147 | { |
| 148 | - foreach($this->errors as $errmsg) |
|
| 148 | + foreach ($this->errors as $errmsg) |
|
| 149 | 149 | { |
| 150 | 150 | dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
| 151 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 151 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
| 152 | 152 | } |
| 153 | 153 | $this->db->rollback(); |
| 154 | - return -1*$error; |
|
| 154 | + return -1 * $error; |
|
| 155 | 155 | } |
| 156 | 156 | else |
| 157 | 157 | { |
@@ -168,27 +168,27 @@ discard block |
||
| 168 | 168 | * @param string $code Code |
| 169 | 169 | * @return int <0 if KO, >0 if OK |
| 170 | 170 | */ |
| 171 | - function fetch($id,$code='') |
|
| 171 | + function fetch($id, $code = '') |
|
| 172 | 172 | { |
| 173 | 173 | global $langs; |
| 174 | 174 | $sql = "SELECT"; |
| 175 | - $sql.= " t.rowid,"; |
|
| 176 | - $sql.= " t.code_departement,"; |
|
| 177 | - $sql.= " t.nom,"; |
|
| 178 | - $sql.= " t.active"; |
|
| 179 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_departements as t"; |
|
| 180 | - if ($id) $sql.= " WHERE t.rowid = ".$id; |
|
| 181 | - elseif ($code) $sql.= " WHERE t.code_departement = '".$this->db->escape($code)."'"; |
|
| 175 | + $sql .= " t.rowid,"; |
|
| 176 | + $sql .= " t.code_departement,"; |
|
| 177 | + $sql .= " t.nom,"; |
|
| 178 | + $sql .= " t.active"; |
|
| 179 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_departements as t"; |
|
| 180 | + if ($id) $sql .= " WHERE t.rowid = ".$id; |
|
| 181 | + elseif ($code) $sql .= " WHERE t.code_departement = '".$this->db->escape($code)."'"; |
|
| 182 | 182 | |
| 183 | 183 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
| 184 | - $resql=$this->db->query($sql); |
|
| 184 | + $resql = $this->db->query($sql); |
|
| 185 | 185 | if ($resql) |
| 186 | 186 | { |
| 187 | 187 | if ($this->db->num_rows($resql)) |
| 188 | 188 | { |
| 189 | 189 | $obj = $this->db->fetch_object($resql); |
| 190 | 190 | |
| 191 | - $this->id = $obj->rowid; |
|
| 191 | + $this->id = $obj->rowid; |
|
| 192 | 192 | $this->code_departement = $obj->code_departement; |
| 193 | 193 | $this->nom = $obj->nom; |
| 194 | 194 | $this->active = $obj->active; |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | else |
| 201 | 201 | { |
| 202 | - $this->error="Error ".$this->db->lasterror(); |
|
| 202 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 203 | 203 | return -1; |
| 204 | 204 | } |
| 205 | 205 | } |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
| 213 | 213 | * @return int <0 if KO, >0 if OK |
| 214 | 214 | */ |
| 215 | - function update($user=null, $notrigger=0) |
|
| 215 | + function update($user = null, $notrigger = 0) |
|
| 216 | 216 | { |
| 217 | 217 | global $conf, $langs; |
| 218 | - $error=0; |
|
| 218 | + $error = 0; |
|
| 219 | 219 | |
| 220 | 220 | // Clean parameters |
| 221 | - if (isset($this->code_departement)) $this->code_departement=trim($this->code_departement); |
|
| 222 | - if (isset($this->nom)) $this->nom=trim($this->nom); |
|
| 223 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 221 | + if (isset($this->code_departement)) $this->code_departement = trim($this->code_departement); |
|
| 222 | + if (isset($this->nom)) $this->nom = trim($this->nom); |
|
| 223 | + if (isset($this->active)) $this->active = trim($this->active); |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | 226 | // Check parameters |
@@ -228,20 +228,20 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | // Update request |
| 230 | 230 | $sql = "UPDATE ".MAIN_DB_PREFIX."c_departements SET"; |
| 231 | - $sql.= " code_departement=".(isset($this->code_departement)?"'".$this->db->escape($this->code_departement)."'":"null").","; |
|
| 232 | - $sql.= " nom=".(isset($this->nom)?"'".$this->db->escape($this->nom)."'":"null").","; |
|
| 233 | - $sql.= " active=".(isset($this->active)?$this->active:"null").""; |
|
| 234 | - $sql.= " WHERE rowid=".$this->id; |
|
| 231 | + $sql .= " code_departement=".(isset($this->code_departement) ? "'".$this->db->escape($this->code_departement)."'" : "null").","; |
|
| 232 | + $sql .= " nom=".(isset($this->nom) ? "'".$this->db->escape($this->nom)."'" : "null").","; |
|
| 233 | + $sql .= " active=".(isset($this->active) ? $this->active : "null").""; |
|
| 234 | + $sql .= " WHERE rowid=".$this->id; |
|
| 235 | 235 | |
| 236 | 236 | $this->db->begin(); |
| 237 | 237 | |
| 238 | 238 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
| 239 | 239 | $resql = $this->db->query($sql); |
| 240 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 240 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
| 241 | 241 | |
| 242 | - if (! $error) |
|
| 242 | + if (!$error) |
|
| 243 | 243 | { |
| 244 | - if (! $notrigger) |
|
| 244 | + if (!$notrigger) |
|
| 245 | 245 | { |
| 246 | 246 | // Uncomment this and change MYOBJECT to your own tag if you |
| 247 | 247 | // want this action call a trigger. |
@@ -258,13 +258,13 @@ discard block |
||
| 258 | 258 | // Commit or rollback |
| 259 | 259 | if ($error) |
| 260 | 260 | { |
| 261 | - foreach($this->errors as $errmsg) |
|
| 261 | + foreach ($this->errors as $errmsg) |
|
| 262 | 262 | { |
| 263 | 263 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
| 264 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 264 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
| 265 | 265 | } |
| 266 | 266 | $this->db->rollback(); |
| 267 | - return -1*$error; |
|
| 267 | + return -1 * $error; |
|
| 268 | 268 | } |
| 269 | 269 | else |
| 270 | 270 | { |
@@ -281,23 +281,23 @@ discard block |
||
| 281 | 281 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
| 282 | 282 | * @return int <0 if KO, >0 if OK |
| 283 | 283 | */ |
| 284 | - function delete($user, $notrigger=0) |
|
| 284 | + function delete($user, $notrigger = 0) |
|
| 285 | 285 | { |
| 286 | 286 | global $conf, $langs; |
| 287 | - $error=0; |
|
| 287 | + $error = 0; |
|
| 288 | 288 | |
| 289 | 289 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements"; |
| 290 | - $sql.= " WHERE rowid=".$this->id; |
|
| 290 | + $sql .= " WHERE rowid=".$this->id; |
|
| 291 | 291 | |
| 292 | 292 | $this->db->begin(); |
| 293 | 293 | |
| 294 | 294 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
| 295 | 295 | $resql = $this->db->query($sql); |
| 296 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 296 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
| 297 | 297 | |
| 298 | - if (! $error) |
|
| 298 | + if (!$error) |
|
| 299 | 299 | { |
| 300 | - if (! $notrigger) |
|
| 300 | + if (!$notrigger) |
|
| 301 | 301 | { |
| 302 | 302 | // Uncomment this and change MYOBJECT to your own tag if you |
| 303 | 303 | // want this action call a trigger. |
@@ -314,13 +314,13 @@ discard block |
||
| 314 | 314 | // Commit or rollback |
| 315 | 315 | if ($error) |
| 316 | 316 | { |
| 317 | - foreach($this->errors as $errmsg) |
|
| 317 | + foreach ($this->errors as $errmsg) |
|
| 318 | 318 | { |
| 319 | 319 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
| 320 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 320 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
| 321 | 321 | } |
| 322 | 322 | $this->db->rollback(); |
| 323 | - return -1*$error; |
|
| 323 | + return -1 * $error; |
|
| 324 | 324 | } |
| 325 | 325 | else |
| 326 | 326 | { |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | * @param User $user Object of user that ask creation |
| 73 | 73 | * @return int >= 0 if OK, < 0 if KO |
| 74 | 74 | */ |
| 75 | - public function create($user='') |
|
| 75 | + public function create($user = '') |
|
| 76 | 76 | { |
| 77 | - global $langs,$conf; |
|
| 77 | + global $langs, $conf; |
|
| 78 | 78 | |
| 79 | - $error=0; |
|
| 79 | + $error = 0; |
|
| 80 | 80 | $langs->load("errors"); |
| 81 | 81 | // Clean parameters |
| 82 | 82 | if (empty($this->label)) { |
@@ -99,34 +99,34 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."links (entity, datea, url, label, objecttype, objectid)"; |
| 101 | 101 | $sql .= " VALUES ('".$conf->entity."', '".$this->db->idate($this->datea)."'"; |
| 102 | - $sql .= ", '" . $this->db->escape($this->url) . "'"; |
|
| 103 | - $sql .= ", '" . $this->db->escape($this->label) . "'"; |
|
| 104 | - $sql .= ", '" . $this->db->escape($this->objecttype) . "'"; |
|
| 105 | - $sql .= ", " . $this->objectid . ")"; |
|
| 102 | + $sql .= ", '".$this->db->escape($this->url)."'"; |
|
| 103 | + $sql .= ", '".$this->db->escape($this->label)."'"; |
|
| 104 | + $sql .= ", '".$this->db->escape($this->objecttype)."'"; |
|
| 105 | + $sql .= ", ".$this->objectid.")"; |
|
| 106 | 106 | |
| 107 | 107 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
| 108 | 108 | $result = $this->db->query($sql); |
| 109 | 109 | if ($result) { |
| 110 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "links"); |
|
| 110 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."links"); |
|
| 111 | 111 | |
| 112 | 112 | if ($this->id > 0) { |
| 113 | 113 | // Call trigger |
| 114 | - $result=$this->call_trigger('LINK_CREATE',$user); |
|
| 114 | + $result = $this->call_trigger('LINK_CREATE', $user); |
|
| 115 | 115 | if ($result < 0) $error++; |
| 116 | 116 | // End call triggers |
| 117 | 117 | } else { |
| 118 | 118 | $error++; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if (! $error) |
|
| 121 | + if (!$error) |
|
| 122 | 122 | { |
| 123 | - dol_syslog(get_class($this)."::Create success id=" . $this->id); |
|
| 123 | + dol_syslog(get_class($this)."::Create success id=".$this->id); |
|
| 124 | 124 | $this->db->commit(); |
| 125 | 125 | return $this->id; |
| 126 | 126 | } |
| 127 | 127 | else |
| 128 | 128 | { |
| 129 | - dol_syslog(get_class($this)."::Create echec update " . $this->error, LOG_ERR); |
|
| 129 | + dol_syslog(get_class($this)."::Create echec update ".$this->error, LOG_ERR); |
|
| 130 | 130 | $this->db->rollback(); |
| 131 | 131 | return -3; |
| 132 | 132 | } |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 137 | 137 | { |
| 138 | 138 | |
| 139 | - $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); |
|
| 140 | - $result=-1; |
|
| 139 | + $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); |
|
| 140 | + $result = -1; |
|
| 141 | 141 | } |
| 142 | 142 | else |
| 143 | 143 | { |
| 144 | - $this->error=$this->db->lasterror(); |
|
| 145 | - $result=-2; |
|
| 144 | + $this->error = $this->db->lasterror(); |
|
| 145 | + $result = -2; |
|
| 146 | 146 | } |
| 147 | 147 | $this->db->rollback(); |
| 148 | 148 | return $result; |
@@ -156,15 +156,15 @@ discard block |
||
| 156 | 156 | * @param int $call_trigger 0=no, 1=yes |
| 157 | 157 | * @return int <0 if KO, >=0 if OK |
| 158 | 158 | */ |
| 159 | - public function update($user='', $call_trigger=1) |
|
| 159 | + public function update($user = '', $call_trigger = 1) |
|
| 160 | 160 | { |
| 161 | - global $langs,$conf; |
|
| 161 | + global $langs, $conf; |
|
| 162 | 162 | require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
| 163 | 163 | |
| 164 | 164 | $langs->load("errors"); |
| 165 | - $error=0; |
|
| 165 | + $error = 0; |
|
| 166 | 166 | |
| 167 | - dol_syslog(get_class($this)."::Update id = " . $this->id . " call_trigger = " . $call_trigger); |
|
| 167 | + dol_syslog(get_class($this)."::Update id = ".$this->id." call_trigger = ".$call_trigger); |
|
| 168 | 168 | |
| 169 | 169 | // Check parameters |
| 170 | 170 | if (empty($this->url)) |
@@ -174,37 +174,37 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // Clean parameters |
| 177 | - $this->url = clean_url($this->url,1); |
|
| 177 | + $this->url = clean_url($this->url, 1); |
|
| 178 | 178 | if (empty($this->label)) $this->label = basename($this->url); |
| 179 | 179 | $this->label = trim($this->label); |
| 180 | 180 | |
| 181 | 181 | |
| 182 | 182 | $this->db->begin(); |
| 183 | 183 | |
| 184 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "links SET "; |
|
| 185 | - $sql .= "entity = '" . $conf->entity ."'"; |
|
| 186 | - $sql .= ", datea = '" . $this->db->idate(dol_now()) . "'"; |
|
| 187 | - $sql .= ", url = '" . $this->db->escape($this->url) . "'"; |
|
| 188 | - $sql .= ", label = '" . $this->db->escape($this->label) . "'"; |
|
| 189 | - $sql .= ", objecttype = '" . $this->db->escape($this->objecttype) . "'"; |
|
| 190 | - $sql .= ", objectid = " . $this->objectid; |
|
| 191 | - $sql .= " WHERE rowid = " . $this->id; |
|
| 184 | + $sql = "UPDATE ".MAIN_DB_PREFIX."links SET "; |
|
| 185 | + $sql .= "entity = '".$conf->entity."'"; |
|
| 186 | + $sql .= ", datea = '".$this->db->idate(dol_now())."'"; |
|
| 187 | + $sql .= ", url = '".$this->db->escape($this->url)."'"; |
|
| 188 | + $sql .= ", label = '".$this->db->escape($this->label)."'"; |
|
| 189 | + $sql .= ", objecttype = '".$this->db->escape($this->objecttype)."'"; |
|
| 190 | + $sql .= ", objectid = ".$this->objectid; |
|
| 191 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 192 | 192 | |
| 193 | - dol_syslog(get_class($this)."::update sql = " .$sql); |
|
| 193 | + dol_syslog(get_class($this)."::update sql = ".$sql); |
|
| 194 | 194 | $resql = $this->db->query($sql); |
| 195 | 195 | if ($resql) |
| 196 | 196 | { |
| 197 | 197 | if ($call_trigger) |
| 198 | 198 | { |
| 199 | 199 | // Call trigger |
| 200 | - $result=$this->call_trigger('LINK_MODIFY',$user); |
|
| 200 | + $result = $this->call_trigger('LINK_MODIFY', $user); |
|
| 201 | 201 | if ($result < 0) $error++; |
| 202 | 202 | // End call triggers |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if (! $error) |
|
| 205 | + if (!$error) |
|
| 206 | 206 | { |
| 207 | - dol_syslog(get_class($this) . "::Update success"); |
|
| 207 | + dol_syslog(get_class($this)."::Update success"); |
|
| 208 | 208 | $this->db->commit(); |
| 209 | 209 | return 1; |
| 210 | 210 | } else { |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | { |
| 220 | 220 | // Doublon |
| 221 | 221 | $this->error = $langs->trans("ErrorDuplicateField"); |
| 222 | - $result = -1; |
|
| 222 | + $result = -1; |
|
| 223 | 223 | } |
| 224 | 224 | else |
| 225 | 225 | { |
| 226 | - $this->error = $langs->trans("Error sql = " . $sql); |
|
| 227 | - $result = -2; |
|
| 226 | + $this->error = $langs->trans("Error sql = ".$sql); |
|
| 227 | + $result = -2; |
|
| 228 | 228 | } |
| 229 | 229 | $this->db->rollback(); |
| 230 | 230 | return $result; |
@@ -241,18 +241,18 @@ discard block |
||
| 241 | 241 | * @param string $sortorder sort order |
| 242 | 242 | * @return int 1 if ok, 0 if no records, -1 if error |
| 243 | 243 | **/ |
| 244 | - public function fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null) |
|
| 244 | + public function fetchAll(&$links, $objecttype, $objectid, $sortfield = null, $sortorder = null) |
|
| 245 | 245 | { |
| 246 | 246 | global $conf; |
| 247 | 247 | |
| 248 | - $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM " . MAIN_DB_PREFIX . "links"; |
|
| 249 | - $sql .= " WHERE objecttype = '" . $objecttype . "' AND objectid = " . $objectid; |
|
| 250 | - if ($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; |
|
| 248 | + $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".MAIN_DB_PREFIX."links"; |
|
| 249 | + $sql .= " WHERE objecttype = '".$objecttype."' AND objectid = ".$objectid; |
|
| 250 | + if ($conf->entity != 0) $sql .= " AND entity = ".$conf->entity; |
|
| 251 | 251 | if ($sortfield) { |
| 252 | 252 | if (empty($sortorder)) { |
| 253 | 253 | $sortorder = "ASC"; |
| 254 | 254 | } |
| 255 | - $sql .= " ORDER BY " . $sortfield . " " . $sortorder; |
|
| 255 | + $sql .= " ORDER BY ".$sortfield." ".$sortorder; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG); |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | if ($resql) |
| 261 | 261 | { |
| 262 | 262 | $num = $this->db->num_rows($resql); |
| 263 | - dol_syslog(get_class($this)."::fetchAll " . $num . "records", LOG_DEBUG); |
|
| 263 | + dol_syslog(get_class($this)."::fetchAll ".$num."records", LOG_DEBUG); |
|
| 264 | 264 | if ($num > 0) |
| 265 | 265 | { |
| 266 | 266 | while ($obj = $this->db->fetch_object($resql)) |
@@ -296,9 +296,9 @@ discard block |
||
| 296 | 296 | { |
| 297 | 297 | global $conf; |
| 298 | 298 | |
| 299 | - $sql = "SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . "links"; |
|
| 300 | - $sql .= " WHERE objecttype = '" . $objecttype . "' AND objectid = " . $objectid; |
|
| 301 | - if ($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; |
|
| 299 | + $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."links"; |
|
| 300 | + $sql .= " WHERE objecttype = '".$objecttype."' AND objectid = ".$objectid; |
|
| 301 | + if ($conf->entity != 0) $sql .= " AND entity = ".$conf->entity; |
|
| 302 | 302 | |
| 303 | 303 | $resql = $db->query($sql); |
| 304 | 304 | if ($resql) |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param int $rowid Id of link to load |
| 316 | 316 | * @return int 1 if ok, 0 if no record found, -1 if error |
| 317 | 317 | **/ |
| 318 | - public function fetch($rowid=null) |
|
| 318 | + public function fetch($rowid = null) |
|
| 319 | 319 | { |
| 320 | 320 | global $conf; |
| 321 | 321 | |
@@ -323,15 +323,15 @@ discard block |
||
| 323 | 323 | $rowid = $this->id; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM " . MAIN_DB_PREFIX . "links"; |
|
| 327 | - $sql .= " WHERE rowid = " . $rowid; |
|
| 328 | - if($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; |
|
| 326 | + $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".MAIN_DB_PREFIX."links"; |
|
| 327 | + $sql .= " WHERE rowid = ".$rowid; |
|
| 328 | + if ($conf->entity != 0) $sql .= " AND entity = ".$conf->entity; |
|
| 329 | 329 | |
| 330 | 330 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
| 331 | 331 | $resql = $this->db->query($sql); |
| 332 | 332 | if ($resql) |
| 333 | 333 | { |
| 334 | - if($this->db->num_rows($resql) > 0) |
|
| 334 | + if ($this->db->num_rows($resql) > 0) |
|
| 335 | 335 | { |
| 336 | 336 | $obj = $this->db->fetch_object($resql); |
| 337 | 337 | $this->entity = $obj->entity; |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | return 0; |
| 348 | 348 | } |
| 349 | 349 | } else { |
| 350 | - $this->error=$this->db->lasterror(); |
|
| 350 | + $this->error = $this->db->lasterror(); |
|
| 351 | 351 | return -1; |
| 352 | 352 | } |
| 353 | 353 | } |
@@ -365,24 +365,24 @@ discard block |
||
| 365 | 365 | $error = 0; |
| 366 | 366 | |
| 367 | 367 | // Call trigger |
| 368 | - $result=$this->call_trigger('LINK_DELETE',$user); |
|
| 368 | + $result = $this->call_trigger('LINK_DELETE', $user); |
|
| 369 | 369 | if ($result < 0) return -1; |
| 370 | 370 | // End call triggers |
| 371 | 371 | |
| 372 | 372 | $this->db->begin(); |
| 373 | 373 | |
| 374 | 374 | // Remove link |
| 375 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "links"; |
|
| 376 | - $sql.= " WHERE rowid = " . $this->id; |
|
| 375 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."links"; |
|
| 376 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 377 | 377 | |
| 378 | 378 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
| 379 | - if (! $this->db->query($sql)) |
|
| 379 | + if (!$this->db->query($sql)) |
|
| 380 | 380 | { |
| 381 | 381 | $error++; |
| 382 | 382 | $this->error = $this->db->lasterror(); |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if (! $error) { |
|
| 385 | + if (!$error) { |
|
| 386 | 386 | $this->db->commit(); |
| 387 | 387 | |
| 388 | 388 | return 1; |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public $db; |
| 34 | 34 | |
| 35 | - var $output; // Used by Cron method to return message |
|
| 36 | - var $result; // Used by Cron method to return data |
|
| 35 | + var $output; // Used by Cron method to return message |
|
| 36 | + var $result; // Used by Cron method to return data |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Constructor |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param string $choice Choice of purge mode ('tempfiles', '' or 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfile') |
| 54 | 54 | * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) |
| 55 | 55 | */ |
| 56 | - function purgeFiles($choice='tempfilesold') |
|
| 56 | + function purgeFiles($choice = 'tempfilesold') |
|
| 57 | 57 | { |
| 58 | 58 | global $conf, $langs, $dolibarr_main_data_root; |
| 59 | 59 | |
@@ -62,80 +62,80 @@ discard block |
||
| 62 | 62 | dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG); |
| 63 | 63 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 64 | 64 | |
| 65 | - $filesarray=array(); |
|
| 66 | - if (empty($choice)) $choice='tempfilesold'; |
|
| 65 | + $filesarray = array(); |
|
| 66 | + if (empty($choice)) $choice = 'tempfilesold'; |
|
| 67 | 67 | |
| 68 | - if ($choice=='tempfiles' || $choice=='tempfilesold') |
|
| 68 | + if ($choice == 'tempfiles' || $choice == 'tempfilesold') |
|
| 69 | 69 | { |
| 70 | 70 | // Delete temporary files |
| 71 | 71 | if ($dolibarr_main_data_root) |
| 72 | 72 | { |
| 73 | - $filesarray=dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks |
|
| 73 | + $filesarray = dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks |
|
| 74 | 74 | if ($choice == 'tempfilesold') |
| 75 | 75 | { |
| 76 | 76 | $now = dol_now(); |
| 77 | - foreach($filesarray as $key => $val) |
|
| 77 | + foreach ($filesarray as $key => $val) |
|
| 78 | 78 | { |
| 79 | - if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h |
|
| 79 | + if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ($choice=='allfiles') |
|
| 85 | + if ($choice == 'allfiles') |
|
| 86 | 86 | { |
| 87 | 87 | // Delete all files (except install.lock, do not follow symbolic links) |
| 88 | 88 | if ($dolibarr_main_data_root) |
| 89 | 89 | { |
| 90 | - $filesarray=dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 90 | + $filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ($choice=='logfile') |
|
| 94 | + if ($choice == 'logfile') |
|
| 95 | 95 | { |
| 96 | 96 | // Define files log |
| 97 | 97 | if ($dolibarr_main_data_root) |
| 98 | 98 | { |
| 99 | - $filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 99 | + $filesarray = dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $filelog=''; |
|
| 103 | - if (! empty($conf->syslog->enabled)) |
|
| 102 | + $filelog = ''; |
|
| 103 | + if (!empty($conf->syslog->enabled)) |
|
| 104 | 104 | { |
| 105 | - $filelog=$conf->global->SYSLOG_FILE; |
|
| 106 | - $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog); |
|
| 105 | + $filelog = $conf->global->SYSLOG_FILE; |
|
| 106 | + $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog); |
|
| 107 | 107 | |
| 108 | - $alreadyincluded=false; |
|
| 108 | + $alreadyincluded = false; |
|
| 109 | 109 | foreach ($filesarray as $tmpcursor) |
| 110 | 110 | { |
| 111 | - if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; } |
|
| 111 | + if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded = true; } |
|
| 112 | 112 | } |
| 113 | - if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file'); |
|
| 113 | + if (!$alreadyincluded) $filesarray[] = array('fullname'=>$filelog, 'type'=>'file'); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $count=0; |
|
| 118 | - $countdeleted=0; |
|
| 119 | - $counterror=0; |
|
| 117 | + $count = 0; |
|
| 118 | + $countdeleted = 0; |
|
| 119 | + $counterror = 0; |
|
| 120 | 120 | if (count($filesarray)) |
| 121 | 121 | { |
| 122 | - foreach($filesarray as $key => $value) |
|
| 122 | + foreach ($filesarray as $key => $value) |
|
| 123 | 123 | { |
| 124 | 124 | //print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."<br>\n"; |
| 125 | 125 | if ($filesarray[$key]['type'] == 'dir') |
| 126 | 126 | { |
| 127 | - $startcount=0; |
|
| 128 | - $tmpcountdeleted=0; |
|
| 129 | - $result=dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted); |
|
| 130 | - $count+=$result; |
|
| 131 | - $countdeleted+=$tmpcountdeleted; |
|
| 127 | + $startcount = 0; |
|
| 128 | + $tmpcountdeleted = 0; |
|
| 129 | + $result = dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted); |
|
| 130 | + $count += $result; |
|
| 131 | + $countdeleted += $tmpcountdeleted; |
|
| 132 | 132 | } |
| 133 | 133 | elseif ($filesarray[$key]['type'] == 'file') |
| 134 | 134 | { |
| 135 | 135 | // If (file that is not logfile) or (if mode is logfile) |
| 136 | - if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile') |
|
| 136 | + if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') |
|
| 137 | 137 | { |
| 138 | - $result=dol_delete_file($filesarray[$key]['fullname'], 1, 1); |
|
| 138 | + $result = dol_delete_file($filesarray[$key]['fullname'], 1, 1); |
|
| 139 | 139 | if ($result) |
| 140 | 140 | { |
| 141 | 141 | $count++; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Update cachenbofdoc |
| 153 | - if (! empty($conf->ecm->enabled) && $choice=='allfiles') |
|
| 153 | + if (!empty($conf->ecm->enabled) && $choice == 'allfiles') |
|
| 154 | 154 | { |
| 155 | 155 | require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; |
| 156 | 156 | $ecmdirstatic = new EcmDirectory($this->db); |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | if ($count > 0) |
| 162 | 162 | { |
| 163 | - $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted); |
|
| 164 | - if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); |
|
| 163 | + $this->output = $langs->trans("PurgeNDirectoriesDeleted", $countdeleted); |
|
| 164 | + if ($count > $countdeleted) $this->output .= '<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); |
|
| 165 | 165 | } |
| 166 | - else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':''); |
|
| 166 | + else $this->output = $langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)' : ''); |
|
| 167 | 167 | |
| 168 | 168 | //return $count; |
| 169 | - return 0; // This function can be called by cron so must return 0 if OK |
|
| 169 | + return 0; // This function can be called by cron so must return 0 if OK |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method |
| 183 | 183 | * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) |
| 184 | 184 | */ |
| 185 | - function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0, $execmethod=0) |
|
| 185 | + function dumpDatabase($compression = 'none', $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0, $execmethod = 0) |
|
| 186 | 186 | { |
| 187 | 187 | global $db, $conf, $langs, $dolibarr_main_data_root; |
| 188 | 188 | global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass; |
@@ -193,112 +193,112 @@ discard block |
||
| 193 | 193 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 194 | 194 | |
| 195 | 195 | // Check compression parameter |
| 196 | - if (! in_array($compression, array('none', 'gz', 'bz', 'zip'))) |
|
| 196 | + if (!in_array($compression, array('none', 'gz', 'bz', 'zip'))) |
|
| 197 | 197 | { |
| 198 | 198 | $langs->load("errors"); |
| 199 | - $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression"); |
|
| 199 | + $this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression"); |
|
| 200 | 200 | return -1; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // Check type parameter |
| 204 | 204 | if ($type == 'auto') $type = $db->type; |
| 205 | - if (! in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin'))) |
|
| 205 | + if (!in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin'))) |
|
| 206 | 206 | { |
| 207 | 207 | $langs->load("errors"); |
| 208 | - $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype"); |
|
| 208 | + $this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype"); |
|
| 209 | 209 | return -1; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // Check file parameter |
| 213 | 213 | if ($file == 'auto') |
| 214 | 214 | { |
| 215 | - $prefix='dump'; |
|
| 216 | - $ext='sql'; |
|
| 217 | - if (in_array($type, array('mysql', 'mysqli'))) { $prefix='mysqldump'; $ext='sql'; } |
|
| 215 | + $prefix = 'dump'; |
|
| 216 | + $ext = 'sql'; |
|
| 217 | + if (in_array($type, array('mysql', 'mysqli'))) { $prefix = 'mysqldump'; $ext = 'sql'; } |
|
| 218 | 218 | //if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; } |
| 219 | - if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; } |
|
| 220 | - $file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext; |
|
| 219 | + if (in_array($type, array('pgsql'))) { $prefix = 'pg_dump'; $ext = 'sql'; } |
|
| 220 | + $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - $outputdir = $conf->admin->dir_output.'/backup'; |
|
| 224 | - $result=dol_mkdir($outputdir); |
|
| 223 | + $outputdir = $conf->admin->dir_output.'/backup'; |
|
| 224 | + $result = dol_mkdir($outputdir); |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | 227 | // MYSQL |
| 228 | 228 | if ($type == 'mysql' || $type == 'mysqli') |
| 229 | 229 | { |
| 230 | - $cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP; |
|
| 230 | + $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP; |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | $outputfile = $outputdir.'/'.$file; |
| 234 | 234 | // for compression format, we add extension |
| 235 | - $compression=$compression ? $compression : 'none'; |
|
| 236 | - if ($compression == 'gz') $outputfile.='.gz'; |
|
| 237 | - if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 235 | + $compression = $compression ? $compression : 'none'; |
|
| 236 | + if ($compression == 'gz') $outputfile .= '.gz'; |
|
| 237 | + if ($compression == 'bz') $outputfile .= '.bz2'; |
|
| 238 | 238 | $outputerror = $outputfile.'.err'; |
| 239 | 239 | dol_mkdir($conf->admin->dir_output.'/backup'); |
| 240 | 240 | |
| 241 | 241 | // Parameteres execution |
| 242 | - $command=$cmddump; |
|
| 243 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command |
|
| 242 | + $command = $cmddump; |
|
| 243 | + if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command |
|
| 244 | 244 | |
| 245 | 245 | //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass); |
| 246 | - $param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host; |
|
| 247 | - $param.=" -u ".$dolibarr_main_db_user; |
|
| 248 | - if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port; |
|
| 249 | - if (! GETPOST("use_transaction")) $param.=" -l --single-transaction"; |
|
| 250 | - if (GETPOST("disable_fk") || $usedefault) $param.=" -K"; |
|
| 251 | - if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha")); |
|
| 252 | - if (GETPOST("drop_database")) $param.=" --add-drop-database"; |
|
| 246 | + $param = $dolibarr_main_db_name." -h ".$dolibarr_main_db_host; |
|
| 247 | + $param .= " -u ".$dolibarr_main_db_user; |
|
| 248 | + if (!empty($dolibarr_main_db_port)) $param .= " -P ".$dolibarr_main_db_port; |
|
| 249 | + if (!GETPOST("use_transaction")) $param .= " -l --single-transaction"; |
|
| 250 | + if (GETPOST("disable_fk") || $usedefault) $param .= " -K"; |
|
| 251 | + if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param .= " --compatible=".escapeshellarg(GETPOST("sql_compat", "alpha")); |
|
| 252 | + if (GETPOST("drop_database")) $param .= " --add-drop-database"; |
|
| 253 | 253 | if (GETPOST("sql_structure") || $usedefault) |
| 254 | 254 | { |
| 255 | - if (GETPOST("drop") || $usedefault) $param.=" --add-drop-table=TRUE"; |
|
| 256 | - else $param.=" --add-drop-table=FALSE"; |
|
| 255 | + if (GETPOST("drop") || $usedefault) $param .= " --add-drop-table=TRUE"; |
|
| 256 | + else $param .= " --add-drop-table=FALSE"; |
|
| 257 | 257 | } |
| 258 | 258 | else |
| 259 | 259 | { |
| 260 | - $param.=" -t"; |
|
| 260 | + $param .= " -t"; |
|
| 261 | 261 | } |
| 262 | - if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE"; |
|
| 262 | + if (GETPOST("disable-add-locks")) $param .= " --add-locks=FALSE"; |
|
| 263 | 263 | if (GETPOST("sql_data") || $usedefault) |
| 264 | 264 | { |
| 265 | - $param.=" --tables"; |
|
| 266 | - if (GETPOST("showcolumns") || $usedefault) $param.=" -c"; |
|
| 267 | - if (GETPOST("extended_ins") || $usedefault) $param.=" -e"; |
|
| 268 | - else $param.=" --skip-extended-insert"; |
|
| 269 | - if (GETPOST("delayed")) $param.=" --delayed-insert"; |
|
| 270 | - if (GETPOST("sql_ignore")) $param.=" --insert-ignore"; |
|
| 271 | - if (GETPOST("hexforbinary") || $usedefault) $param.=" --hex-blob"; |
|
| 265 | + $param .= " --tables"; |
|
| 266 | + if (GETPOST("showcolumns") || $usedefault) $param .= " -c"; |
|
| 267 | + if (GETPOST("extended_ins") || $usedefault) $param .= " -e"; |
|
| 268 | + else $param .= " --skip-extended-insert"; |
|
| 269 | + if (GETPOST("delayed")) $param .= " --delayed-insert"; |
|
| 270 | + if (GETPOST("sql_ignore")) $param .= " --insert-ignore"; |
|
| 271 | + if (GETPOST("hexforbinary") || $usedefault) $param .= " --hex-blob"; |
|
| 272 | 272 | } |
| 273 | 273 | else |
| 274 | 274 | { |
| 275 | - $param.=" -d"; // No row information (no data) |
|
| 275 | + $param .= " -d"; // No row information (no data) |
|
| 276 | 276 | } |
| 277 | - $param.=" --default-character-set=utf8"; // We always save output into utf8 charset |
|
| 278 | - $paramcrypted=$param; |
|
| 279 | - $paramclear=$param; |
|
| 280 | - if (! empty($dolibarr_main_db_pass)) |
|
| 277 | + $param .= " --default-character-set=utf8"; // We always save output into utf8 charset |
|
| 278 | + $paramcrypted = $param; |
|
| 279 | + $paramclear = $param; |
|
| 280 | + if (!empty($dolibarr_main_db_pass)) |
|
| 281 | 281 | { |
| 282 | - $paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"'; |
|
| 283 | - $paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"'; |
|
| 282 | + $paramcrypted .= ' -p"'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'"'; |
|
| 283 | + $paramclear .= ' -p"'.str_replace(array('"', '`'), array('\"', '\`'), $dolibarr_main_db_pass).'"'; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $errormsg=''; |
|
| 286 | + $errormsg = ''; |
|
| 287 | 287 | $handle = ''; |
| 288 | 288 | |
| 289 | 289 | // Start call method to execute dump |
| 290 | - $fullcommandcrypted=$command." ".$paramcrypted." 2>&1"; |
|
| 291 | - $fullcommandclear=$command." ".$paramclear." 2>&1"; |
|
| 290 | + $fullcommandcrypted = $command." ".$paramcrypted." 2>&1"; |
|
| 291 | + $fullcommandclear = $command." ".$paramclear." 2>&1"; |
|
| 292 | 292 | if ($compression == 'none') $handle = fopen($outputfile, 'w'); |
| 293 | 293 | if ($compression == 'gz') $handle = gzopen($outputfile, 'w'); |
| 294 | 294 | if ($compression == 'bz') $handle = bzopen($outputfile, 'w'); |
| 295 | 295 | |
| 296 | 296 | if ($handle) |
| 297 | 297 | { |
| 298 | - if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; |
|
| 299 | - if (empty($execmethod)) $execmethod=1; |
|
| 298 | + if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod = $conf->global->MAIN_EXEC_USE_POPEN; |
|
| 299 | + if (empty($execmethod)) $execmethod = 1; |
|
| 300 | 300 | |
| 301 | - $ok=0; |
|
| 301 | + $ok = 0; |
|
| 302 | 302 | dol_syslog("Utils::dumpDatabase execmethod=".$execmethod." command:".$fullcommandcrypted, LOG_DEBUG); |
| 303 | 303 | |
| 304 | 304 | // TODO Replace with executeCLI function |
@@ -312,35 +312,35 @@ discard block |
||
| 312 | 312 | $langs->load("errors"); |
| 313 | 313 | dol_syslog("Datadump retval after exec=".$retval, LOG_ERR); |
| 314 | 314 | $error = 'Error '.$retval; |
| 315 | - $ok=0; |
|
| 315 | + $ok = 0; |
|
| 316 | 316 | } |
| 317 | 317 | else |
| 318 | 318 | { |
| 319 | - $i=0; |
|
| 319 | + $i = 0; |
|
| 320 | 320 | if (!empty($readt)) |
| 321 | - foreach($readt as $key=>$read) |
|
| 321 | + foreach ($readt as $key=>$read) |
|
| 322 | 322 | { |
| 323 | - $i++; // output line number |
|
| 323 | + $i++; // output line number |
|
| 324 | 324 | if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue; |
| 325 | 325 | fwrite($handle, $read.($execmethod == 2 ? '' : "\n")); |
| 326 | - if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1; |
|
| 327 | - elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1; |
|
| 326 | + if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1; |
|
| 327 | + elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | if ($execmethod == 2) // With this method, there is no way to get the return code, only output |
| 332 | 332 | { |
| 333 | 333 | $handlein = popen($fullcommandclear, 'r'); |
| 334 | - $i=0; |
|
| 334 | + $i = 0; |
|
| 335 | 335 | while (!feof($handlein)) |
| 336 | 336 | { |
| 337 | - $i++; // output line number |
|
| 337 | + $i++; // output line number |
|
| 338 | 338 | $read = fgets($handlein); |
| 339 | 339 | // Exclude warning line we don't want |
| 340 | 340 | if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue; |
| 341 | - fwrite($handle,$read); |
|
| 342 | - if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1; |
|
| 343 | - elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1; |
|
| 341 | + fwrite($handle, $read); |
|
| 342 | + if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1; |
|
| 343 | + elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1; |
|
| 344 | 344 | } |
| 345 | 345 | pclose($handlein); |
| 346 | 346 | } |
@@ -350,14 +350,14 @@ discard block |
||
| 350 | 350 | if ($compression == 'gz') gzclose($handle); |
| 351 | 351 | if ($compression == 'bz') bzclose($handle); |
| 352 | 352 | |
| 353 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 353 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 354 | 354 | @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
| 355 | 355 | } |
| 356 | 356 | else |
| 357 | 357 | { |
| 358 | 358 | $langs->load("errors"); |
| 359 | - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 360 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 359 | + dol_syslog("Failed to open file ".$outputfile, LOG_ERR); |
|
| 360 | + $errormsg = $langs->trans("ErrorFailedToWriteInDir"); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // Get errorstring |
@@ -367,23 +367,23 @@ discard block |
||
| 367 | 367 | if ($handle) |
| 368 | 368 | { |
| 369 | 369 | // Get 2048 first chars of error message. |
| 370 | - $errormsg = fgets($handle,2048); |
|
| 370 | + $errormsg = fgets($handle, 2048); |
|
| 371 | 371 | // Close file |
| 372 | 372 | if ($compression == 'none') fclose($handle); |
| 373 | 373 | if ($compression == 'gz') gzclose($handle); |
| 374 | 374 | if ($compression == 'bz') bzclose($handle); |
| 375 | - if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg=''; // Pas erreur |
|
| 375 | + if ($ok && preg_match('/^-- MySql/i', $errormsg)) $errormsg = ''; // Pas erreur |
|
| 376 | 376 | else |
| 377 | 377 | { |
| 378 | 378 | // Renommer fichier sortie en fichier erreur |
| 379 | 379 | //print "$outputfile -> $outputerror"; |
| 380 | 380 | @dol_delete_file($outputerror, 1, 0, 0, null, false, 0); |
| 381 | - @rename($outputfile,$outputerror); |
|
| 381 | + @rename($outputfile, $outputerror); |
|
| 382 | 382 | // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide |
| 383 | - if (! $errormsg) |
|
| 383 | + if (!$errormsg) |
|
| 384 | 384 | { |
| 385 | 385 | $langs->load("errors"); |
| 386 | - $errormsg=$langs->trans("ErrorFailedToRunExternalCommand"); |
|
| 386 | + $errormsg = $langs->trans("ErrorFailedToRunExternalCommand"); |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | } |
@@ -401,9 +401,9 @@ discard block |
||
| 401 | 401 | $outputfile = $outputdir.'/'.$file; |
| 402 | 402 | $outputfiletemp = $outputfile.'-TMP.sql'; |
| 403 | 403 | // for compression format, we add extension |
| 404 | - $compression=$compression ? $compression : 'none'; |
|
| 405 | - if ($compression == 'gz') $outputfile.='.gz'; |
|
| 406 | - if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 404 | + $compression = $compression ? $compression : 'none'; |
|
| 405 | + if ($compression == 'gz') $outputfile .= '.gz'; |
|
| 406 | + if ($compression == 'bz') $outputfile .= '.bz2'; |
|
| 407 | 407 | $outputerror = $outputfile.'.err'; |
| 408 | 408 | dol_mkdir($conf->admin->dir_output.'/backup'); |
| 409 | 409 | |
@@ -425,51 +425,51 @@ discard block |
||
| 425 | 425 | // POSTGRESQL |
| 426 | 426 | if ($type == 'postgresql' || $type == 'pgsql') |
| 427 | 427 | { |
| 428 | - $cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP; |
|
| 428 | + $cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP; |
|
| 429 | 429 | |
| 430 | 430 | $outputfile = $outputdir.'/'.$file; |
| 431 | 431 | // for compression format, we add extension |
| 432 | - $compression=$compression ? $compression : 'none'; |
|
| 433 | - if ($compression == 'gz') $outputfile.='.gz'; |
|
| 434 | - if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 432 | + $compression = $compression ? $compression : 'none'; |
|
| 433 | + if ($compression == 'gz') $outputfile .= '.gz'; |
|
| 434 | + if ($compression == 'bz') $outputfile .= '.bz2'; |
|
| 435 | 435 | $outputerror = $outputfile.'.err'; |
| 436 | 436 | dol_mkdir($conf->admin->dir_output.'/backup'); |
| 437 | 437 | |
| 438 | 438 | // Parameteres execution |
| 439 | - $command=$cmddump; |
|
| 440 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command |
|
| 439 | + $command = $cmddump; |
|
| 440 | + if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command |
|
| 441 | 441 | |
| 442 | 442 | //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass); |
| 443 | 443 | //$param="-F c"; |
| 444 | - $param="-F p"; |
|
| 445 | - $param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host; |
|
| 446 | - $param.=" -U ".$dolibarr_main_db_user; |
|
| 447 | - if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port; |
|
| 448 | - if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.=" --disable-dollar-quoting"; |
|
| 449 | - if (GETPOST("drop_database")) $param.=" -c -C"; |
|
| 444 | + $param = "-F p"; |
|
| 445 | + $param .= " --no-tablespaces --inserts -h ".$dolibarr_main_db_host; |
|
| 446 | + $param .= " -U ".$dolibarr_main_db_user; |
|
| 447 | + if (!empty($dolibarr_main_db_port)) $param .= " -p ".$dolibarr_main_db_port; |
|
| 448 | + if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param .= " --disable-dollar-quoting"; |
|
| 449 | + if (GETPOST("drop_database")) $param .= " -c -C"; |
|
| 450 | 450 | if (GETPOST("sql_structure")) |
| 451 | 451 | { |
| 452 | - if (GETPOST("drop")) $param.=" --add-drop-table"; |
|
| 453 | - if (! GETPOST("sql_data")) $param.=" -s"; |
|
| 452 | + if (GETPOST("drop")) $param .= " --add-drop-table"; |
|
| 453 | + if (!GETPOST("sql_data")) $param .= " -s"; |
|
| 454 | 454 | } |
| 455 | 455 | if (GETPOST("sql_data")) |
| 456 | 456 | { |
| 457 | - if (! GETPOST("sql_structure")) $param.=" -a"; |
|
| 458 | - if (GETPOST("showcolumns")) $param.=" -c"; |
|
| 457 | + if (!GETPOST("sql_structure")) $param .= " -a"; |
|
| 458 | + if (GETPOST("showcolumns")) $param .= " -c"; |
|
| 459 | 459 | } |
| 460 | - $param.=' -f "'.$outputfile.'"'; |
|
| 460 | + $param .= ' -f "'.$outputfile.'"'; |
|
| 461 | 461 | //if ($compression == 'none') |
| 462 | - if ($compression == 'gz') $param.=' -Z 9'; |
|
| 462 | + if ($compression == 'gz') $param .= ' -Z 9'; |
|
| 463 | 463 | //if ($compression == 'bz') |
| 464 | - $paramcrypted=$param; |
|
| 465 | - $paramclear=$param; |
|
| 464 | + $paramcrypted = $param; |
|
| 465 | + $paramclear = $param; |
|
| 466 | 466 | /*if (! empty($dolibarr_main_db_pass)) |
| 467 | 467 | { |
| 468 | 468 | $paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass); |
| 469 | 469 | $paramclear.=" -W".$dolibarr_main_db_pass; |
| 470 | 470 | }*/ |
| 471 | - $paramcrypted.=" -w ".$dolibarr_main_db_name; |
|
| 472 | - $paramclear.=" -w ".$dolibarr_main_db_name; |
|
| 471 | + $paramcrypted .= " -w ".$dolibarr_main_db_name; |
|
| 472 | + $paramclear .= " -w ".$dolibarr_main_db_name; |
|
| 473 | 473 | |
| 474 | 474 | $this->output = ""; |
| 475 | 475 | $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted); |
@@ -479,8 +479,8 @@ discard block |
||
| 479 | 479 | if ($keeplastnfiles > 0) |
| 480 | 480 | { |
| 481 | 481 | $tmpfiles = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '(\.err|\.old|\.sav)$', 'date', SORT_DESC); |
| 482 | - $i=0; |
|
| 483 | - foreach($tmpfiles as $key => $val) |
|
| 482 | + $i = 0; |
|
| 483 | + foreach ($tmpfiles as $key => $val) |
|
| 484 | 484 | { |
| 485 | 485 | $i++; |
| 486 | 486 | if ($i <= $keeplastnfiles) continue; |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method |
| 502 | 502 | * @return array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK. |
| 503 | 503 | */ |
| 504 | - function executeCLI($command, $outputfile, $execmethod=0) |
|
| 504 | + function executeCLI($command, $outputfile, $execmethod = 0) |
|
| 505 | 505 | { |
| 506 | 506 | global $conf, $langs; |
| 507 | 507 | |
@@ -509,15 +509,15 @@ discard block |
||
| 509 | 509 | $output = ''; |
| 510 | 510 | $error = ''; |
| 511 | 511 | |
| 512 | - $command=escapeshellcmd($command); |
|
| 513 | - $command.=" 2>&1"; |
|
| 512 | + $command = escapeshellcmd($command); |
|
| 513 | + $command .= " 2>&1"; |
|
| 514 | 514 | |
| 515 | - if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; |
|
| 516 | - if (empty($execmethod)) $execmethod=1; |
|
| 515 | + if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod = $conf->global->MAIN_EXEC_USE_POPEN; |
|
| 516 | + if (empty($execmethod)) $execmethod = 1; |
|
| 517 | 517 | //$execmethod=1; |
| 518 | 518 | |
| 519 | 519 | dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG); |
| 520 | - $output_arr=array(); |
|
| 520 | + $output_arr = array(); |
|
| 521 | 521 | |
| 522 | 522 | if ($execmethod == 1) |
| 523 | 523 | { |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | } |
| 533 | 533 | if ($execmethod == 2) // With this method, there is no way to get the return code, only output |
| 534 | 534 | { |
| 535 | - $ok=0; |
|
| 535 | + $ok = 0; |
|
| 536 | 536 | $handle = fopen($outputfile, 'w+b'); |
| 537 | 537 | if ($handle) |
| 538 | 538 | { |
@@ -541,21 +541,21 @@ discard block |
||
| 541 | 541 | while (!feof($handlein)) |
| 542 | 542 | { |
| 543 | 543 | $read = fgets($handlein); |
| 544 | - fwrite($handle,$read); |
|
| 545 | - $output_arr[]=$read; |
|
| 544 | + fwrite($handle, $read); |
|
| 545 | + $output_arr[] = $read; |
|
| 546 | 546 | } |
| 547 | 547 | pclose($handlein); |
| 548 | 548 | fclose($handle); |
| 549 | 549 | } |
| 550 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 550 | + if (!empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | // Update with result |
| 554 | - if (is_array($output_arr) && count($output_arr)>0) |
|
| 554 | + if (is_array($output_arr) && count($output_arr) > 0) |
|
| 555 | 555 | { |
| 556 | - foreach($output_arr as $val) |
|
| 556 | + foreach ($output_arr as $val) |
|
| 557 | 557 | { |
| 558 | - $output.=$val.($execmethod == 2 ? '' : "\n"); |
|
| 558 | + $output .= $val.($execmethod == 2 ? '' : "\n"); |
|
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | 561 | |
@@ -577,23 +577,23 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | $error = 0; |
| 579 | 579 | |
| 580 | - $modulelowercase=strtolower($module); |
|
| 580 | + $modulelowercase = strtolower($module); |
|
| 581 | 581 | |
| 582 | 582 | // Dir for module |
| 583 | 583 | $dir = $dirins.'/'.$modulelowercase; |
| 584 | 584 | // Zip file to build |
| 585 | - $FILENAMEDOC=''; |
|
| 585 | + $FILENAMEDOC = ''; |
|
| 586 | 586 | |
| 587 | 587 | // Load module |
| 588 | 588 | dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php'); |
| 589 | - $class='mod'.$module; |
|
| 589 | + $class = 'mod'.$module; |
|
| 590 | 590 | |
| 591 | 591 | if (class_exists($class)) |
| 592 | 592 | { |
| 593 | 593 | try { |
| 594 | 594 | $moduleobj = new $class($this->db); |
| 595 | 595 | } |
| 596 | - catch(Exception $e) |
|
| 596 | + catch (Exception $e) |
|
| 597 | 597 | { |
| 598 | 598 | $error++; |
| 599 | 599 | dol_print_error($e->getMessage()); |
@@ -607,41 +607,41 @@ discard block |
||
| 607 | 607 | exit; |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | - $arrayversion=explode('.',$moduleobj->version,3); |
|
| 610 | + $arrayversion = explode('.', $moduleobj->version, 3); |
|
| 611 | 611 | if (count($arrayversion)) |
| 612 | 612 | { |
| 613 | - $FILENAMEASCII=strtolower($module).'.asciidoc'; |
|
| 614 | - $FILENAMEDOC=strtolower($module).'.html'; // TODO Use/text PDF |
|
| 613 | + $FILENAMEASCII = strtolower($module).'.asciidoc'; |
|
| 614 | + $FILENAMEDOC = strtolower($module).'.html'; // TODO Use/text PDF |
|
| 615 | 615 | |
| 616 | 616 | $dirofmodule = dol_buildpath(strtolower($module), 0).'/doc'; |
| 617 | 617 | $dirofmoduletmp = dol_buildpath(strtolower($module), 0).'/doc/temp'; |
| 618 | 618 | $outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC; |
| 619 | 619 | if ($dirofmodule) |
| 620 | 620 | { |
| 621 | - if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule); |
|
| 622 | - if (! dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp); |
|
| 623 | - if (! is_writable($dirofmoduletmp)) |
|
| 621 | + if (!dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule); |
|
| 622 | + if (!dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp); |
|
| 623 | + if (!is_writable($dirofmoduletmp)) |
|
| 624 | 624 | { |
| 625 | 625 | $this->error = 'Dir '.$dirofmoduletmp.' does not exists or is not writable'; |
| 626 | 626 | return -1; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - $destfile=$dirofmoduletmp.'/'.$FILENAMEASCII; |
|
| 629 | + $destfile = $dirofmoduletmp.'/'.$FILENAMEASCII; |
|
| 630 | 630 | |
| 631 | 631 | $fhandle = fopen($destfile, 'w+'); |
| 632 | 632 | if ($fhandle) |
| 633 | 633 | { |
| 634 | - $specs=dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/')); |
|
| 634 | + $specs = dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/')); |
|
| 635 | 635 | |
| 636 | 636 | $i = 0; |
| 637 | 637 | foreach ($specs as $spec) |
| 638 | 638 | { |
| 639 | - if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file |
|
| 640 | - if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file |
|
| 639 | + if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file |
|
| 640 | + if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file |
|
| 641 | 641 | |
| 642 | 642 | $pathtofile = strtolower($module).'/doc/'.$spec['relativename']; |
| 643 | - $format='asciidoc'; |
|
| 644 | - if (preg_match('/\.md$/i', $spec['name'])) $format='markdown'; |
|
| 643 | + $format = 'asciidoc'; |
|
| 644 | + if (preg_match('/\.md$/i', $spec['name'])) $format = 'markdown'; |
|
| 645 | 645 | |
| 646 | 646 | $filecursor = @file_get_contents($spec['fullname']); |
| 647 | 647 | if ($filecursor) |
@@ -665,15 +665,15 @@ discard block |
||
| 665 | 665 | fclose($fhandle); |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - $conf->global->MODULEBUILDER_ASCIIDOCTOR='asciidoctor'; |
|
| 668 | + $conf->global->MODULEBUILDER_ASCIIDOCTOR = 'asciidoctor'; |
|
| 669 | 669 | if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR)) |
| 670 | 670 | { |
| 671 | 671 | dol_print_error('', 'Module setup not complete'); |
| 672 | 672 | exit; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - $command=$conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmodule.'/'.$FILENAMEDOC; |
|
| 676 | - $outfile=$dirofmoduletmp.'/out.tmp'; |
|
| 675 | + $command = $conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmodule.'/'.$FILENAMEDOC; |
|
| 676 | + $outfile = $dirofmoduletmp.'/out.tmp'; |
|
| 677 | 677 | |
| 678 | 678 | require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php'; |
| 679 | 679 | $utils = new Utils($db); |
@@ -721,18 +721,18 @@ discard block |
||
| 721 | 721 | { |
| 722 | 722 | global $conf; |
| 723 | 723 | |
| 724 | - if(empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled |
|
| 724 | + if (empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled |
|
| 725 | 725 | return 0; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - if(! function_exists('gzopen')) { |
|
| 728 | + if (!function_exists('gzopen')) { |
|
| 729 | 729 | $this->error = 'Support for gzopen not available in this PHP'; |
| 730 | 730 | return -1; |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | dol_include_once('/core/lib/files.lib.php'); |
| 734 | 734 | |
| 735 | - $nbSaves = ! empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14; |
|
| 735 | + $nbSaves = !empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14; |
|
| 736 | 736 | |
| 737 | 737 | if (empty($conf->global->SYSLOG_FILE)) { |
| 738 | 738 | $mainlogdir = DOL_DATA_ROOT; |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | $tabfiles = dol_dir_list(DOL_DATA_ROOT, 'files', 0, '^(dolibarr_.+|odt2pdf)\.log$'); // Also handle other log files like dolibarr_install.log |
| 747 | 747 | $tabfiles[] = array('name' => $mainlog, 'path' => $mainlogdir); |
| 748 | 748 | |
| 749 | - foreach($tabfiles as $file) { |
|
| 749 | + foreach ($tabfiles as $file) { |
|
| 750 | 750 | |
| 751 | 751 | $logname = $file['name']; |
| 752 | 752 | $logpath = $file['path']; |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | $gzfilestmp = dol_dir_list($logpath, 'files', 0, $filter); |
| 761 | 761 | $gzfiles = array(); |
| 762 | 762 | |
| 763 | - foreach($gzfilestmp as $gzfile) { |
|
| 763 | + foreach ($gzfilestmp as $gzfile) { |
|
| 764 | 764 | $tabmatches = array(); |
| 765 | 765 | preg_match('/'.$filter.'/i', $gzfile['name'], $tabmatches); |
| 766 | 766 | |
@@ -771,15 +771,15 @@ discard block |
||
| 771 | 771 | |
| 772 | 772 | krsort($gzfiles, SORT_NUMERIC); |
| 773 | 773 | |
| 774 | - foreach($gzfiles as $numsave => $dummy) { |
|
| 775 | - if (dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) { |
|
| 774 | + foreach ($gzfiles as $numsave => $dummy) { |
|
| 775 | + if (dol_is_file($logpath.'/'.$logname.'.'.($numsave + 1).'.gz')) { |
|
| 776 | 776 | return -2; |
| 777 | 777 | } |
| 778 | 778 | |
| 779 | - if($numsave >= $nbSaves) { |
|
| 779 | + if ($numsave >= $nbSaves) { |
|
| 780 | 780 | dol_delete_file($logpath.'/'.$logname.'.'.$numsave.'.gz', 0, 0, 0, null, false, 0); |
| 781 | 781 | } else { |
| 782 | - dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave+1).'.gz', 0, 1, 0, 0); |
|
| 782 | + dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave + 1).'.gz', 0, 1, 0, 0); |
|
| 783 | 783 | } |
| 784 | 784 | } |
| 785 | 785 | |
@@ -800,14 +800,14 @@ discard block |
||
| 800 | 800 | return -4; |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - while(! feof($sourcehandle)) { |
|
| 803 | + while (!feof($sourcehandle)) { |
|
| 804 | 804 | gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024)); // Read 512 kB at a time |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | fclose($sourcehandle); |
| 808 | 808 | gzclose($gzfilehandle); |
| 809 | 809 | |
| 810 | - @chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); |
|
| 810 | + @chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK)); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | dol_delete_file($logpath.'/'.$logname, 0, 0, 0, null, false, 0); |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | fclose($newlog); |
| 818 | 818 | |
| 819 | 819 | //var_dump($logpath.'/'.$logname." - ".octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); |
| 820 | - @chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); |
|
| 820 | + @chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK)); |
|
| 821 | 821 | } |
| 822 | 822 | } |
| 823 | 823 | |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * @param string $tables Table name or '*' for all |
| 836 | 836 | * @return int <0 if KO, >0 if OK |
| 837 | 837 | */ |
| 838 | - function backupTables($outputfile, $tables='*') |
|
| 838 | + function backupTables($outputfile, $tables = '*') |
|
| 839 | 839 | { |
| 840 | 840 | global $db, $langs; |
| 841 | 841 | global $errormsg; |
@@ -855,14 +855,14 @@ discard block |
||
| 855 | 855 | { |
| 856 | 856 | $tables = array(); |
| 857 | 857 | $result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\''); |
| 858 | - while($row = $db->fetch_row($result)) |
|
| 858 | + while ($row = $db->fetch_row($result)) |
|
| 859 | 859 | { |
| 860 | 860 | $tables[] = $row[0]; |
| 861 | 861 | } |
| 862 | 862 | } |
| 863 | 863 | else |
| 864 | 864 | { |
| 865 | - $tables = is_array($tables) ? $tables : explode(',',$tables); |
|
| 865 | + $tables = is_array($tables) ? $tables : explode(',', $tables); |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | //cycle through |
@@ -870,8 +870,8 @@ discard block |
||
| 870 | 870 | if (fwrite($handle, '') === false) |
| 871 | 871 | { |
| 872 | 872 | $langs->load("errors"); |
| 873 | - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 874 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 873 | + dol_syslog("Failed to open file ".$outputfile, LOG_ERR); |
|
| 874 | + $errormsg = $langs->trans("ErrorFailedToWriteInDir"); |
|
| 875 | 875 | return -1; |
| 876 | 876 | } |
| 877 | 877 | |
@@ -908,15 +908,15 @@ discard block |
||
| 908 | 908 | if (GETPOST("nobin_delayed")) $delayed = 'DELAYED '; |
| 909 | 909 | |
| 910 | 910 | // Process each table and print their definition + their datas |
| 911 | - foreach($tables as $table) |
|
| 911 | + foreach ($tables as $table) |
|
| 912 | 912 | { |
| 913 | 913 | // Saving the table structure |
| 914 | 914 | fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n"); |
| 915 | 915 | |
| 916 | - if (GETPOST("nobin_drop")) fwrite($handle,"DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it |
|
| 917 | - fwrite($handle,"/*!40101 SET @saved_cs_client = @@character_set_client */;\n"); |
|
| 918 | - fwrite($handle,"/*!40101 SET character_set_client = utf8 */;\n"); |
|
| 919 | - $resqldrop=$db->query('SHOW CREATE TABLE '.$table); |
|
| 916 | + if (GETPOST("nobin_drop")) fwrite($handle, "DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it |
|
| 917 | + fwrite($handle, "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"); |
|
| 918 | + fwrite($handle, "/*!40101 SET character_set_client = utf8 */;\n"); |
|
| 919 | + $resqldrop = $db->query('SHOW CREATE TABLE '.$table); |
|
| 920 | 920 | $row2 = $db->fetch_row($resqldrop); |
| 921 | 921 | if (empty($row2[1])) |
| 922 | 922 | { |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | } |
| 925 | 925 | else |
| 926 | 926 | { |
| 927 | - fwrite($handle,$row2[1].";\n"); |
|
| 927 | + fwrite($handle, $row2[1].";\n"); |
|
| 928 | 928 | //fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n"); |
| 929 | 929 | |
| 930 | 930 | // Dumping the data (locking the table and disabling the keys check while doing the process) |
@@ -933,22 +933,22 @@ discard block |
||
| 933 | 933 | if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n"); |
| 934 | 934 | else fwrite($handle, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n"); |
| 935 | 935 | |
| 936 | - $sql='SELECT * FROM '.$table; |
|
| 936 | + $sql = 'SELECT * FROM '.$table; |
|
| 937 | 937 | $result = $db->query($sql); |
| 938 | - while($row = $db->fetch_row($result)) |
|
| 938 | + while ($row = $db->fetch_row($result)) |
|
| 939 | 939 | { |
| 940 | 940 | // For each row of data we print a line of INSERT |
| 941 | - fwrite($handle,'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES ('); |
|
| 941 | + fwrite($handle, 'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES ('); |
|
| 942 | 942 | $columns = count($row); |
| 943 | - for($j=0; $j<$columns; $j++) { |
|
| 943 | + for ($j = 0; $j < $columns; $j++) { |
|
| 944 | 944 | // Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier) |
| 945 | 945 | if ($row[$j] == null && !is_string($row[$j])) { |
| 946 | 946 | // IMPORTANT: if the field is NULL we set it NULL |
| 947 | 947 | $row[$j] = 'NULL'; |
| 948 | - } elseif(is_string($row[$j]) && $row[$j] == '') { |
|
| 948 | + } elseif (is_string($row[$j]) && $row[$j] == '') { |
|
| 949 | 949 | // if it's an empty string, we set it as an empty string |
| 950 | 950 | $row[$j] = "''"; |
| 951 | - } elseif(is_numeric($row[$j]) && !strcmp($row[$j], $row[$j]+0) ) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0) |
|
| 951 | + } elseif (is_numeric($row[$j]) && !strcmp($row[$j], $row[$j] + 0)) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0) |
|
| 952 | 952 | // if it's a number, we return it as-is |
| 953 | 953 | // $row[$j] = $row[$j]; |
| 954 | 954 | } else { // else for all other cases we escape the value and put quotes around |
@@ -957,11 +957,11 @@ discard block |
||
| 957 | 957 | $row[$j] = "'".$row[$j]."'"; |
| 958 | 958 | } |
| 959 | 959 | } |
| 960 | - fwrite($handle,implode(',', $row).");\n"); |
|
| 960 | + fwrite($handle, implode(',', $row).");\n"); |
|
| 961 | 961 | } |
| 962 | 962 | if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking |
| 963 | 963 | if (!GETPOST("nobin_nolocks")) fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table |
| 964 | - fwrite($handle,"\n\n\n"); |
|
| 964 | + fwrite($handle, "\n\n\n"); |
|
| 965 | 965 | } |
| 966 | 966 | } |
| 967 | 967 | |
@@ -985,10 +985,10 @@ discard block |
||
| 985 | 985 | /* Backup Procedure structure*/ |
| 986 | 986 | |
| 987 | 987 | // Write the footer (restore the previous database settings) |
| 988 | - $sqlfooter="\n\n"; |
|
| 988 | + $sqlfooter = "\n\n"; |
|
| 989 | 989 | if (GETPOST("nobin_use_transaction")) $sqlfooter .= "COMMIT;\n"; |
| 990 | 990 | if (GETPOST("nobin_disable_fk")) $sqlfooter .= "SET FOREIGN_KEY_CHECKS=1;\n"; |
| 991 | - $sqlfooter.="\n\n-- Dump completed on ".date('Y-m-d G-i-s'); |
|
| 991 | + $sqlfooter .= "\n\n-- Dump completed on ".date('Y-m-d G-i-s'); |
|
| 992 | 992 | fwrite($handle, $sqlfooter); |
| 993 | 993 | |
| 994 | 994 | fclose($handle); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * @var string Error code (or message) |
| 37 | 37 | */ |
| 38 | - public $error=''; |
|
| 38 | + public $error = ''; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -60,35 +60,35 @@ discard block |
||
| 60 | 60 | * @param int $showempty Show empty line |
| 61 | 61 | * @return int Nbr of project if OK, <0 if KO |
| 62 | 62 | */ |
| 63 | - function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1) |
|
| 63 | + function select_contract($socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1) |
|
| 64 | 64 | { |
| 65 | 65 | // phpcs:enable |
| 66 | - global $db,$user,$conf,$langs; |
|
| 66 | + global $db, $user, $conf, $langs; |
|
| 67 | 67 | |
| 68 | 68 | $hideunselectables = false; |
| 69 | - if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true; |
|
| 69 | + if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true; |
|
| 70 | 70 | |
| 71 | 71 | // Search all contacts |
| 72 | 72 | $sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut'; |
| 73 | - $sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c'; |
|
| 74 | - $sql.= " WHERE c.entity = ".$conf->entity; |
|
| 73 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'contrat as c'; |
|
| 74 | + $sql .= " WHERE c.entity = ".$conf->entity; |
|
| 75 | 75 | //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")"; |
| 76 | 76 | if ($socid > 0) |
| 77 | 77 | { |
| 78 | 78 | // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma. |
| 79 | 79 | if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) |
| 80 | - $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)"; |
|
| 80 | + $sql .= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)"; |
|
| 81 | 81 | else if ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') |
| 82 | 82 | { |
| 83 | - $sql.= " AND (c.fk_soc IN (".$socid.", ".$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") "; |
|
| 84 | - $sql.= " OR c.fk_soc IS NULL)"; |
|
| 83 | + $sql .= " AND (c.fk_soc IN (".$socid.", ".$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") "; |
|
| 84 | + $sql .= " OR c.fk_soc IS NULL)"; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | - if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)"; |
|
| 88 | - $sql.= " ORDER BY c.ref "; |
|
| 87 | + if ($socid == 0) $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)"; |
|
| 88 | + $sql .= " ORDER BY c.ref "; |
|
| 89 | 89 | |
| 90 | 90 | dol_syslog(get_class($this)."::select_contract", LOG_DEBUG); |
| 91 | - $resql=$db->query($sql); |
|
| 91 | + $resql = $db->query($sql); |
|
| 92 | 92 | if ($resql) |
| 93 | 93 | { |
| 94 | 94 | print '<select class="flat" name="'.$htmlname.'">'; |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | { |
| 102 | 102 | $obj = $db->fetch_object($resql); |
| 103 | 103 | // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
| 104 | - if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
| 104 | + if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire) |
|
| 105 | 105 | { |
| 106 | 106 | // Do nothing |
| 107 | 107 | } |
| 108 | 108 | else |
| 109 | 109 | { |
| 110 | - $labeltoshow=dol_trunc($obj->ref,18); |
|
| 110 | + $labeltoshow = dol_trunc($obj->ref, 18); |
|
| 111 | 111 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; |
| 112 | 112 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
| 113 | 113 | if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
@@ -116,30 +116,30 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | else |
| 118 | 118 | { |
| 119 | - $disabled=0; |
|
| 120 | - if ( $obj->statut == 0) |
|
| 119 | + $disabled = 0; |
|
| 120 | + if ($obj->statut == 0) |
|
| 121 | 121 | { |
| 122 | - $disabled=1; |
|
| 123 | - $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 122 | + $disabled = 1; |
|
| 123 | + $labeltoshow .= ' ('.$langs->trans("Draft").')'; |
|
| 124 | 124 | } |
| 125 | - if ( empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 125 | + if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 126 | 126 | { |
| 127 | - $disabled=1; |
|
| 128 | - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 127 | + $disabled = 1; |
|
| 128 | + $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if ($hideunselectables && $disabled) |
| 132 | 132 | { |
| 133 | - $resultat=''; |
|
| 133 | + $resultat = ''; |
|
| 134 | 134 | } |
| 135 | 135 | else |
| 136 | 136 | { |
| 137 | - $resultat='<option value="'.$obj->rowid.'"'; |
|
| 138 | - if ($disabled) $resultat.=' disabled'; |
|
| 137 | + $resultat = '<option value="'.$obj->rowid.'"'; |
|
| 138 | + if ($disabled) $resultat .= ' disabled'; |
|
| 139 | 139 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; |
| 140 | 140 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
| 141 | - $resultat.='>'.$labeltoshow; |
|
| 142 | - $resultat.='</option>'; |
|
| 141 | + $resultat .= '>'.$labeltoshow; |
|
| 142 | + $resultat .= '</option>'; |
|
| 143 | 143 | } |
| 144 | 144 | print $resultat; |
| 145 | 145 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | if (!empty($conf->use_javascript_ajax)) |
| 154 | 154 | { |
| 155 | 155 | // Make select dynamic |
| 156 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 156 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 157 | 157 | print ajax_combobox($htmlname); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param int $showempty Show empty line |
| 178 | 178 | * @return int Nbr of project if OK, <0 if KO |
| 179 | 179 | */ |
| 180 | - function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1) |
|
| 180 | + function formSelectContract($page, $socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1) |
|
| 181 | 181 | { |
| 182 | 182 | global $langs; |
| 183 | 183 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @var string Error code (or message) |
| 38 | 38 | */ |
| 39 | - public $error=''; |
|
| 39 | + public $error = ''; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param boolean $force_price True of not |
| 60 | 60 | * @return array Array with info |
| 61 | 61 | */ |
| 62 | - function getMarginInfosArray($object, $force_price=false) |
|
| 62 | + function getMarginInfosArray($object, $force_price = false) |
|
| 63 | 63 | { |
| 64 | 64 | global $conf, $db; |
| 65 | 65 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | 'total_mark_rate' => '' |
| 83 | 83 | ); |
| 84 | 84 | |
| 85 | - foreach($object->lines as $line) |
|
| 85 | + foreach ($object->lines as $line) |
|
| 86 | 86 | { |
| 87 | 87 | if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) |
| 88 | 88 | { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); |
| 100 | - $pa_ht = ($pv < 0 ? - $line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign |
|
| 100 | + $pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign |
|
| 101 | 101 | $pa = $line->qty * $pa_ht; |
| 102 | 102 | |
| 103 | 103 | // calcul des marges |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit |
| 106 | 106 | $marginInfos['pa_products'] += $pa; |
| 107 | 107 | $marginInfos['pv_products'] += $pv; |
| 108 | - $marginInfos['pa_total'] += $pa; |
|
| 109 | - $marginInfos['pv_total'] += $pv; |
|
| 108 | + $marginInfos['pa_total'] += $pa; |
|
| 109 | + $marginInfos['pv_total'] += $pv; |
|
| 110 | 110 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
| 111 | 111 | //if ($pv < 0) |
| 112 | 112 | //{ |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service |
| 119 | 119 | $marginInfos['pa_services'] += $pa; |
| 120 | 120 | $marginInfos['pv_services'] += $pv; |
| 121 | - $marginInfos['pa_total'] += $pa; |
|
| 122 | - $marginInfos['pv_total'] += $pv; |
|
| 121 | + $marginInfos['pa_total'] += $pa; |
|
| 122 | + $marginInfos['pv_total'] += $pv; |
|
| 123 | 123 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
| 124 | 124 | //if ($pv < 0) |
| 125 | 125 | // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
@@ -132,12 +132,12 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | else { |
| 135 | - $type=$line->product_type?$line->product_type:$line->fk_product_type; |
|
| 135 | + $type = $line->product_type ? $line->product_type : $line->fk_product_type; |
|
| 136 | 136 | if ($type == 0) { // product |
| 137 | 137 | $marginInfos['pa_products'] += $pa; |
| 138 | 138 | $marginInfos['pv_products'] += $pv; |
| 139 | - $marginInfos['pa_total'] += $pa; |
|
| 140 | - $marginInfos['pv_total'] += $pv; |
|
| 139 | + $marginInfos['pa_total'] += $pa; |
|
| 140 | + $marginInfos['pv_total'] += $pv; |
|
| 141 | 141 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
| 142 | 142 | //if ($pv < 0) |
| 143 | 143 | //{ |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | elseif ($type == 1) { // service |
| 152 | 152 | $marginInfos['pa_services'] += $pa; |
| 153 | 153 | $marginInfos['pv_services'] += $pv; |
| 154 | - $marginInfos['pa_total'] += $pa; |
|
| 155 | - $marginInfos['pv_total'] += $pv; |
|
| 154 | + $marginInfos['pa_total'] += $pa; |
|
| 155 | + $marginInfos['pv_total'] += $pv; |
|
| 156 | 156 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
| 157 | 157 | //if ($pv < 0) |
| 158 | 158 | // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
@@ -191,24 +191,24 @@ discard block |
||
| 191 | 191 | * @param boolean $force_price Force price |
| 192 | 192 | * @return void |
| 193 | 193 | */ |
| 194 | - function displayMarginInfos($object, $force_price=false) |
|
| 194 | + function displayMarginInfos($object, $force_price = false) |
|
| 195 | 195 | { |
| 196 | 196 | global $langs, $conf, $user; |
| 197 | 197 | |
| 198 | - if (! empty($user->societe_id)) return; |
|
| 198 | + if (!empty($user->societe_id)) return; |
|
| 199 | 199 | |
| 200 | - if (! $user->rights->margins->liretous) return; |
|
| 200 | + if (!$user->rights->margins->liretous) return; |
|
| 201 | 201 | |
| 202 | 202 | $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
| 203 | 203 | |
| 204 | 204 | $marginInfo = $this->getMarginInfosArray($object, $force_price); |
| 205 | 205 | |
| 206 | - if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better |
|
| 206 | + if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better |
|
| 207 | 207 | { |
| 208 | 208 | print $langs->trans('ShowMarginInfos').' : '; |
| 209 | 209 | $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; |
| 210 | - print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>'; |
|
| 211 | - print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>'; |
|
| 210 | + print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? '' : 'hideobject').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</span>'; |
|
| 211 | + print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? 'hideobject' : '').'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</span>'; |
|
| 212 | 212 | |
| 213 | 213 | print '<script>$(document).ready(function() { |
| 214 | 214 | $("span#showMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 0); $(".margininfos").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject");})}); |
@@ -229,13 +229,13 @@ discard block |
||
| 229 | 229 | else |
| 230 | 230 | print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>'; |
| 231 | 231 | print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>'; |
| 232 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 232 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 233 | 233 | print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>'; |
| 234 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 234 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 235 | 235 | print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>'; |
| 236 | 236 | print '</tr>'; |
| 237 | 237 | |
| 238 | - if (! empty($conf->product->enabled)) |
|
| 238 | + if (!empty($conf->product->enabled)) |
|
| 239 | 239 | { |
| 240 | 240 | //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { |
| 241 | 241 | print '<tr class="oddeven">'; |
@@ -243,38 +243,38 @@ discard block |
||
| 243 | 243 | print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>'; |
| 244 | 244 | print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>'; |
| 245 | 245 | print '<td align="right">'.price($marginInfo['margin_on_products'], null, null, null, null, $rounding).'</td>'; |
| 246 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 247 | - print '<td align="right">'.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 248 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 249 | - print '<td align="right">'.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 246 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 247 | + print '<td align="right">'.(($marginInfo['margin_rate_products'] == '') ? '' : price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 248 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 249 | + print '<td align="right">'.(($marginInfo['mark_rate_products'] == '') ? '' : price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 250 | 250 | print '</tr>'; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if (! empty($conf->service->enabled)) |
|
| 253 | + if (!empty($conf->service->enabled)) |
|
| 254 | 254 | { |
| 255 | 255 | print '<tr class="oddeven">'; |
| 256 | 256 | print '<td>'.$langs->trans('MarginOnServices').'</td>'; |
| 257 | 257 | print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>'; |
| 258 | 258 | print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>'; |
| 259 | 259 | print '<td align="right">'.price($marginInfo['margin_on_services'], null, null, null, null, $rounding).'</td>'; |
| 260 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 261 | - print '<td align="right">'.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 262 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 263 | - print '<td align="right">'.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 260 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 261 | + print '<td align="right">'.(($marginInfo['margin_rate_services'] == '') ? '' : price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 262 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 263 | + print '<td align="right">'.(($marginInfo['mark_rate_services'] == '') ? '' : price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 264 | 264 | print '</tr>'; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) |
|
| 267 | + if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) |
|
| 268 | 268 | { |
| 269 | 269 | print '<tr class="liste_total">'; |
| 270 | 270 | print '<td>'.$langs->trans('TotalMargin').'</td>'; |
| 271 | 271 | print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>'; |
| 272 | 272 | print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>'; |
| 273 | 273 | print '<td align="right">'.price($marginInfo['total_margin'], null, null, null, null, $rounding).'</td>'; |
| 274 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 275 | - print '<td align="right">'.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 276 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 277 | - print '<td align="right">'.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 274 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 275 | + print '<td align="right">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 276 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 277 | + print '<td align="right">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 278 | 278 | print '</tr>'; |
| 279 | 279 | } |
| 280 | 280 | print '</table>'; |
@@ -32,128 +32,128 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | if ($cancel) |
| 34 | 34 | { |
| 35 | - if (! empty($backtopage)) |
|
| 35 | + if (!empty($backtopage)) |
|
| 36 | 36 | { |
| 37 | 37 | header("Location: ".$backtopage); |
| 38 | 38 | exit; |
| 39 | 39 | } |
| 40 | - $action=''; |
|
| 40 | + $action = ''; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Action to add record |
| 44 | -if ($action == 'add' && ! empty($permissiontoadd)) |
|
| 44 | +if ($action == 'add' && !empty($permissiontoadd)) |
|
| 45 | 45 | { |
| 46 | 46 | foreach ($object->fields as $key => $val) |
| 47 | 47 | { |
| 48 | - if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields |
|
| 48 | + if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields |
|
| 49 | 49 | |
| 50 | 50 | // Set value to insert |
| 51 | 51 | if (in_array($object->fields[$key]['type'], array('text', 'html'))) { |
| 52 | - $value = GETPOST($key,'none'); |
|
| 53 | - } elseif ($object->fields[$key]['type']=='date') { |
|
| 52 | + $value = GETPOST($key, 'none'); |
|
| 53 | + } elseif ($object->fields[$key]['type'] == 'date') { |
|
| 54 | 54 | $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); |
| 55 | - } elseif ($object->fields[$key]['type']=='datetime') { |
|
| 55 | + } elseif ($object->fields[$key]['type'] == 'datetime') { |
|
| 56 | 56 | $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); |
| 57 | - } elseif ($object->fields[$key]['type']=='price') { |
|
| 57 | + } elseif ($object->fields[$key]['type'] == 'price') { |
|
| 58 | 58 | $value = price2num(GETPOST($key)); |
| 59 | 59 | } else { |
| 60 | - $value = GETPOST($key,'alpha'); |
|
| 60 | + $value = GETPOST($key, 'alpha'); |
|
| 61 | 61 | } |
| 62 | - if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field |
|
| 63 | - if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field |
|
| 62 | + if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field |
|
| 63 | + if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field |
|
| 64 | 64 | |
| 65 | - $object->$key=$value; |
|
| 65 | + $object->$key = $value; |
|
| 66 | 66 | if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) |
| 67 | 67 | { |
| 68 | 68 | $error++; |
| 69 | - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); |
|
| 69 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors'); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if (! $error) |
|
| 73 | + if (!$error) |
|
| 74 | 74 | { |
| 75 | - $result=$object->create($user); |
|
| 75 | + $result = $object->create($user); |
|
| 76 | 76 | if ($result > 0) |
| 77 | 77 | { |
| 78 | 78 | // Creation OK |
| 79 | - $urltogo=$backtopage?str_replace('__ID__', $result, $backtopage):$backurlforlist; |
|
| 79 | + $urltogo = $backtopage ?str_replace('__ID__', $result, $backtopage) : $backurlforlist; |
|
| 80 | 80 | header("Location: ".$urltogo); |
| 81 | 81 | exit; |
| 82 | 82 | } |
| 83 | 83 | else |
| 84 | 84 | { |
| 85 | 85 | // Creation KO |
| 86 | - if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); |
|
| 86 | + if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); |
|
| 87 | 87 | else setEventMessages($object->error, null, 'errors'); |
| 88 | - $action='create'; |
|
| 88 | + $action = 'create'; |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | else |
| 92 | 92 | { |
| 93 | - $action='create'; |
|
| 93 | + $action = 'create'; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Action to update record |
| 98 | -if ($action == 'update' && ! empty($permissiontoadd)) |
|
| 98 | +if ($action == 'update' && !empty($permissiontoadd)) |
|
| 99 | 99 | { |
| 100 | 100 | foreach ($object->fields as $key => $val) |
| 101 | 101 | { |
| 102 | - if (! GETPOSTISSET($key)) continue; // The field was not submited to be edited |
|
| 103 | - if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields |
|
| 102 | + if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited |
|
| 103 | + if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields |
|
| 104 | 104 | |
| 105 | 105 | // Set value to update |
| 106 | 106 | if (in_array($object->fields[$key]['type'], array('text', 'html'))) { |
| 107 | - $value = GETPOST($key,'none'); |
|
| 108 | - } elseif ($object->fields[$key]['type']=='date') { |
|
| 107 | + $value = GETPOST($key, 'none'); |
|
| 108 | + } elseif ($object->fields[$key]['type'] == 'date') { |
|
| 109 | 109 | $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); |
| 110 | - } elseif ($object->fields[$key]['type']=='datetime') { |
|
| 110 | + } elseif ($object->fields[$key]['type'] == 'datetime') { |
|
| 111 | 111 | $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); |
| 112 | - } elseif ($object->fields[$key]['type']=='price') { |
|
| 112 | + } elseif ($object->fields[$key]['type'] == 'price') { |
|
| 113 | 113 | $value = price2num(GETPOST($key)); |
| 114 | 114 | } else { |
| 115 | - $value = GETPOST($key,'alpha'); |
|
| 115 | + $value = GETPOST($key, 'alpha'); |
|
| 116 | 116 | } |
| 117 | - if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field |
|
| 118 | - if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field |
|
| 117 | + if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field |
|
| 118 | + if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field |
|
| 119 | 119 | |
| 120 | - $object->$key=$value; |
|
| 120 | + $object->$key = $value; |
|
| 121 | 121 | if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) |
| 122 | 122 | { |
| 123 | 123 | $error++; |
| 124 | - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); |
|
| 124 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors'); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if (! $error) |
|
| 128 | + if (!$error) |
|
| 129 | 129 | { |
| 130 | - $result=$object->update($user); |
|
| 130 | + $result = $object->update($user); |
|
| 131 | 131 | if ($result > 0) |
| 132 | 132 | { |
| 133 | - $action='view'; |
|
| 133 | + $action = 'view'; |
|
| 134 | 134 | } |
| 135 | 135 | else |
| 136 | 136 | { |
| 137 | 137 | // Creation KO |
| 138 | 138 | setEventMessages($object->error, $object->errors, 'errors'); |
| 139 | - $action='edit'; |
|
| 139 | + $action = 'edit'; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | else |
| 143 | 143 | { |
| 144 | - $action='edit'; |
|
| 144 | + $action = 'edit'; |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Action to update one extrafield |
| 149 | -if ($action == "update_extras" && ! empty($permissiontoadd)) |
|
| 149 | +if ($action == "update_extras" && !empty($permissiontoadd)) |
|
| 150 | 150 | { |
| 151 | - $object->fetch(GETPOST('id','int')); |
|
| 152 | - $attributekey = GETPOST('attribute','alpha'); |
|
| 151 | + $object->fetch(GETPOST('id', 'int')); |
|
| 152 | + $attributekey = GETPOST('attribute', 'alpha'); |
|
| 153 | 153 | $attributekeylong = 'options_'.$attributekey; |
| 154 | - $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha'); |
|
| 154 | + $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha'); |
|
| 155 | 155 | |
| 156 | - $result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user); |
|
| 156 | + $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user); |
|
| 157 | 157 | if ($result > 0) |
| 158 | 158 | { |
| 159 | 159 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // Action to delete |
| 170 | -if ($action == 'confirm_delete' && ! empty($permissiontodelete)) |
|
| 170 | +if ($action == 'confirm_delete' && !empty($permissiontodelete)) |
|
| 171 | 171 | { |
| 172 | - $result=$object->delete($user); |
|
| 172 | + $result = $object->delete($user); |
|
| 173 | 173 | if ($result > 0) |
| 174 | 174 | { |
| 175 | 175 | // Delete OK |
@@ -179,15 +179,15 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | else |
| 181 | 181 | { |
| 182 | - if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); |
|
| 182 | + if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); |
|
| 183 | 183 | else setEventMessages($object->error, null, 'errors'); |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Action clone object |
| 188 | -if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)) |
|
| 188 | +if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) |
|
| 189 | 189 | { |
| 190 | - if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) |
|
| 190 | + if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) |
|
| 191 | 191 | { |
| 192 | 192 | setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); |
| 193 | 193 | } |
@@ -198,20 +198,20 @@ discard block |
||
| 198 | 198 | // Because createFromClone modifies the object, we must clone it so that we can restore it later |
| 199 | 199 | $orig = clone $object; |
| 200 | 200 | |
| 201 | - $result=$object->createFromClone($user, $object->id); |
|
| 201 | + $result = $object->createFromClone($user, $object->id); |
|
| 202 | 202 | if ($result > 0) |
| 203 | 203 | { |
| 204 | 204 | $newid = 0; |
| 205 | 205 | if (is_object($result)) $newid = $result->id; |
| 206 | 206 | else $newid = $result; |
| 207 | - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object |
|
| 207 | + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object |
|
| 208 | 208 | exit; |
| 209 | 209 | } |
| 210 | 210 | else |
| 211 | 211 | { |
| 212 | 212 | setEventMessages($object->error, $object->errors, 'errors'); |
| 213 | 213 | $object = $orig; |
| 214 | - $action=''; |
|
| 214 | + $action = ''; |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
| 28 | 28 | |
| 29 | -$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; |
|
| 29 | +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; |
|
| 30 | 30 | $comment = new Comment($db); |
| 31 | 31 | |
| 32 | 32 | /* |
@@ -40,20 +40,20 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $comment->description = $description; |
| 42 | 42 | $comment->datec = time(); |
| 43 | - $comment->fk_element = GETPOST('id','int'); |
|
| 44 | - $comment->element_type = GETPOST('comment_element_type','alpha'); |
|
| 43 | + $comment->fk_element = GETPOST('id', 'int'); |
|
| 44 | + $comment->element_type = GETPOST('comment_element_type', 'alpha'); |
|
| 45 | 45 | $comment->fk_user_author = $user->id; |
| 46 | 46 | $comment->entity = $conf->entity; |
| 47 | 47 | if ($comment->create($user) > 0) |
| 48 | 48 | { |
| 49 | 49 | setEventMessages($langs->trans("CommentAdded"), null, 'mesgs'); |
| 50 | - header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':'')); |
|
| 50 | + header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : '')); |
|
| 51 | 51 | exit; |
| 52 | 52 | } |
| 53 | 53 | else |
| 54 | 54 | { |
| 55 | - setEventMessages($comment->error, $comment->errors,'errors'); |
|
| 56 | - $action=''; |
|
| 55 | + setEventMessages($comment->error, $comment->errors, 'errors'); |
|
| 56 | + $action = ''; |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | if ($comment->delete($user) > 0) |
| 65 | 65 | { |
| 66 | 66 | setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs'); |
| 67 | - header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':'')); |
|
| 67 | + header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : '')); |
|
| 68 | 68 | exit; |
| 69 | 69 | } |
| 70 | 70 | else |
| 71 | 71 | { |
| 72 | - setEventMessages($comment->error, $comment->errors,'errors'); |
|
| 73 | - $action=''; |
|
| 72 | + setEventMessages($comment->error, $comment->errors, 'errors'); |
|
| 73 | + $action = ''; |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | \ No newline at end of file |