@@ -32,38 +32,38 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class Ccountry // extends CommonObject |
| 34 | 34 | { |
| 35 | - /** |
|
| 35 | + /** |
|
| 36 | 36 | * @var DoliDB Database handler. |
| 37 | 37 | */ |
| 38 | 38 | public $db; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string Error code (or message) |
|
| 42 | - */ |
|
| 43 | - public $error=''; |
|
| 40 | + /** |
|
| 41 | + * @var string Error code (or message) |
|
| 42 | + */ |
|
| 43 | + public $error=''; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[] Error codes (or messages) |
|
| 47 | - */ |
|
| 48 | - public $errors = array(); |
|
| 45 | + /** |
|
| 46 | + * @var string[] Error codes (or messages) |
|
| 47 | + */ |
|
| 48 | + public $errors = array(); |
|
| 49 | 49 | |
| 50 | - //var $element='ccountry'; //!< Id that identify managed objects |
|
| 51 | - //var $table_element='ccountry'; //!< Name of table without prefix where object is stored |
|
| 50 | + //var $element='ccountry'; //!< Id that identify managed objects |
|
| 51 | + //var $table_element='ccountry'; //!< Name of table without prefix where object is stored |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | - * @var int ID |
|
| 55 | - */ |
|
| 56 | - public $id; |
|
| 54 | + * @var int ID |
|
| 55 | + */ |
|
| 56 | + public $id; |
|
| 57 | 57 | |
| 58 | - public $code; |
|
| 59 | - public $code_iso; |
|
| 58 | + public $code; |
|
| 59 | + public $code_iso; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | + /** |
|
| 62 | 62 | * @var string Countries label |
| 63 | 63 | */ |
| 64 | 64 | public $label; |
| 65 | 65 | |
| 66 | - public $active; |
|
| 66 | + public $active; |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
@@ -88,73 +88,73 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function create($user, $notrigger=0) |
| 90 | 90 | { |
| 91 | - global $conf, $langs; |
|
| 92 | - $error=0; |
|
| 91 | + global $conf, $langs; |
|
| 92 | + $error=0; |
|
| 93 | 93 | |
| 94 | - // Clean parameters |
|
| 95 | - if (isset($this->code)) $this->code=trim($this->code); |
|
| 96 | - if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 97 | - if (isset($this->label)) $this->label=trim($this->label); |
|
| 98 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 94 | + // Clean parameters |
|
| 95 | + if (isset($this->code)) $this->code=trim($this->code); |
|
| 96 | + if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 97 | + if (isset($this->label)) $this->label=trim($this->label); |
|
| 98 | + if (isset($this->active)) $this->active=trim($this->active); |
|
| 99 | 99 | |
| 100 | - // Check parameters |
|
| 101 | - // Put here code to add control on parameters values |
|
| 100 | + // Check parameters |
|
| 101 | + // Put here code to add control on parameters values |
|
| 102 | 102 | |
| 103 | 103 | // Insert request |
| 104 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; |
|
| 105 | - $sql.= "rowid,"; |
|
| 106 | - $sql.= "code,"; |
|
| 107 | - $sql.= "code_iso,"; |
|
| 108 | - $sql.= "label,"; |
|
| 109 | - $sql.= "active"; |
|
| 104 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; |
|
| 105 | + $sql.= "rowid,"; |
|
| 106 | + $sql.= "code,"; |
|
| 107 | + $sql.= "code_iso,"; |
|
| 108 | + $sql.= "label,"; |
|
| 109 | + $sql.= "active"; |
|
| 110 | 110 | $sql.= ") VALUES ("; |
| 111 | - $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").","; |
|
| 112 | - $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; |
|
| 113 | - $sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").","; |
|
| 114 | - $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; |
|
| 115 | - $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'").""; |
|
| 116 | - $sql.= ")"; |
|
| 111 | + $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").","; |
|
| 112 | + $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; |
|
| 113 | + $sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").","; |
|
| 114 | + $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; |
|
| 115 | + $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'").""; |
|
| 116 | + $sql.= ")"; |
|
| 117 | 117 | |
| 118 | - $this->db->begin(); |
|
| 118 | + $this->db->begin(); |
|
| 119 | 119 | |
| 120 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 120 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 121 | 121 | $resql=$this->db->query($sql); |
| 122 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 122 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 123 | 123 | |
| 124 | - if (! $error) |
|
| 124 | + if (! $error) |
|
| 125 | 125 | { |
| 126 | 126 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country"); |
| 127 | 127 | |
| 128 | - if (! $notrigger) |
|
| 129 | - { |
|
| 130 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 131 | - // want this action call a trigger. |
|
| 132 | - |
|
| 133 | - //// Call triggers |
|
| 134 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 135 | - //$interface=new Interfaces($this->db); |
|
| 136 | - //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
| 137 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 138 | - //// End call triggers |
|
| 139 | - } |
|
| 128 | + if (! $notrigger) |
|
| 129 | + { |
|
| 130 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 131 | + // want this action call a trigger. |
|
| 132 | + |
|
| 133 | + //// Call triggers |
|
| 134 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 135 | + //$interface=new Interfaces($this->db); |
|
| 136 | + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
| 137 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 138 | + //// End call triggers |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Commit or rollback |
| 143 | 143 | if ($error) |
| 144 | - { |
|
| 145 | - foreach($this->errors as $errmsg) |
|
| 146 | - { |
|
| 147 | - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 148 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 149 | - } |
|
| 150 | - $this->db->rollback(); |
|
| 151 | - return -1*$error; |
|
| 152 | - } |
|
| 153 | - else |
|
| 154 | - { |
|
| 155 | - $this->db->commit(); |
|
| 144 | + { |
|
| 145 | + foreach($this->errors as $errmsg) |
|
| 146 | + { |
|
| 147 | + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 148 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 149 | + } |
|
| 150 | + $this->db->rollback(); |
|
| 151 | + return -1*$error; |
|
| 152 | + } |
|
| 153 | + else |
|
| 154 | + { |
|
| 155 | + $this->db->commit(); |
|
| 156 | 156 | return $this->id; |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
@@ -167,18 +167,18 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | function fetch($id,$code='') |
| 169 | 169 | { |
| 170 | - global $langs; |
|
| 170 | + global $langs; |
|
| 171 | 171 | $sql = "SELECT"; |
| 172 | - $sql.= " t.rowid,"; |
|
| 173 | - $sql.= " t.code,"; |
|
| 174 | - $sql.= " t.code_iso,"; |
|
| 175 | - $sql.= " t.label,"; |
|
| 176 | - $sql.= " t.active"; |
|
| 172 | + $sql.= " t.rowid,"; |
|
| 173 | + $sql.= " t.code,"; |
|
| 174 | + $sql.= " t.code_iso,"; |
|
| 175 | + $sql.= " t.label,"; |
|
| 176 | + $sql.= " t.active"; |
|
| 177 | 177 | $sql.= " FROM ".MAIN_DB_PREFIX."c_country as t"; |
| 178 | 178 | if ($id) $sql.= " WHERE t.rowid = ".$id; |
| 179 | 179 | elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
| 180 | 180 | |
| 181 | - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 181 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 182 | 182 | $resql=$this->db->query($sql); |
| 183 | 183 | if ($resql) |
| 184 | 184 | { |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | $obj = $this->db->fetch_object($resql); |
| 188 | 188 | |
| 189 | 189 | $this->id = $obj->rowid; |
| 190 | - $this->code = $obj->code; |
|
| 191 | - $this->code_iso = $obj->code_iso; |
|
| 192 | - $this->label = $obj->label; |
|
| 193 | - $this->active = $obj->active; |
|
| 190 | + $this->code = $obj->code; |
|
| 191 | + $this->code_iso = $obj->code_iso; |
|
| 192 | + $this->label = $obj->label; |
|
| 193 | + $this->active = $obj->active; |
|
| 194 | 194 | |
| 195 | 195 | $this->db->free($resql); |
| 196 | 196 | return 1; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | else |
| 203 | 203 | { |
| 204 | - $this->error="Error ".$this->db->lasterror(); |
|
| 204 | + $this->error="Error ".$this->db->lasterror(); |
|
| 205 | 205 | return -1; |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -216,120 +216,120 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | function update($user=null, $notrigger=0) |
| 218 | 218 | { |
| 219 | - global $conf, $langs; |
|
| 220 | - $error=0; |
|
| 219 | + global $conf, $langs; |
|
| 220 | + $error=0; |
|
| 221 | 221 | |
| 222 | - // Clean parameters |
|
| 223 | - if (isset($this->code)) $this->code=trim($this->code); |
|
| 224 | - if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 225 | - if (isset($this->label)) $this->label=trim($this->label); |
|
| 226 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 222 | + // Clean parameters |
|
| 223 | + if (isset($this->code)) $this->code=trim($this->code); |
|
| 224 | + if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 225 | + if (isset($this->label)) $this->label=trim($this->label); |
|
| 226 | + if (isset($this->active)) $this->active=trim($this->active); |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | - // Check parameters |
|
| 230 | - // Put here code to add control on parameters values |
|
| 229 | + // Check parameters |
|
| 230 | + // Put here code to add control on parameters values |
|
| 231 | 231 | |
| 232 | 232 | // Update request |
| 233 | 233 | $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET"; |
| 234 | - $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").","; |
|
| 235 | - $sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").","; |
|
| 236 | - $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; |
|
| 237 | - $sql.= " active=".(isset($this->active)?$this->active:"null").""; |
|
| 234 | + $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").","; |
|
| 235 | + $sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").","; |
|
| 236 | + $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; |
|
| 237 | + $sql.= " active=".(isset($this->active)?$this->active:"null").""; |
|
| 238 | 238 | $sql.= " WHERE rowid=".$this->id; |
| 239 | 239 | |
| 240 | - $this->db->begin(); |
|
| 240 | + $this->db->begin(); |
|
| 241 | 241 | |
| 242 | - dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 242 | + dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 243 | 243 | $resql = $this->db->query($sql); |
| 244 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 245 | - |
|
| 246 | - if (! $error) |
|
| 247 | - { |
|
| 248 | - if (! $notrigger) |
|
| 249 | - { |
|
| 250 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 251 | - // want this action call a trigger. |
|
| 252 | - |
|
| 253 | - //// Call triggers |
|
| 254 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 255 | - //$interface=new Interfaces($this->db); |
|
| 256 | - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
| 257 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 258 | - //// End call triggers |
|
| 259 | - } |
|
| 260 | - } |
|
| 244 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 245 | + |
|
| 246 | + if (! $error) |
|
| 247 | + { |
|
| 248 | + if (! $notrigger) |
|
| 249 | + { |
|
| 250 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 251 | + // want this action call a trigger. |
|
| 252 | + |
|
| 253 | + //// Call triggers |
|
| 254 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 255 | + //$interface=new Interfaces($this->db); |
|
| 256 | + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
| 257 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 258 | + //// End call triggers |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | 262 | // Commit or rollback |
| 263 | - if ($error) |
|
| 264 | - { |
|
| 265 | - foreach($this->errors as $errmsg) |
|
| 266 | - { |
|
| 267 | - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 268 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 269 | - } |
|
| 270 | - $this->db->rollback(); |
|
| 271 | - return -1*$error; |
|
| 272 | - } |
|
| 273 | - else |
|
| 274 | - { |
|
| 275 | - $this->db->commit(); |
|
| 276 | - return 1; |
|
| 277 | - } |
|
| 263 | + if ($error) |
|
| 264 | + { |
|
| 265 | + foreach($this->errors as $errmsg) |
|
| 266 | + { |
|
| 267 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 268 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 269 | + } |
|
| 270 | + $this->db->rollback(); |
|
| 271 | + return -1*$error; |
|
| 272 | + } |
|
| 273 | + else |
|
| 274 | + { |
|
| 275 | + $this->db->commit(); |
|
| 276 | + return 1; |
|
| 277 | + } |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Delete object in database |
|
| 283 | - * |
|
| 284 | - * @param User $user User that delete |
|
| 285 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 286 | - * @return int <0 if KO, >0 if OK |
|
| 287 | - */ |
|
| 288 | - function delete($user, $notrigger=0) |
|
| 289 | - { |
|
| 290 | - global $conf, $langs; |
|
| 291 | - $error=0; |
|
| 292 | - |
|
| 293 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; |
|
| 294 | - $sql.= " WHERE rowid=".$this->id; |
|
| 295 | - |
|
| 296 | - $this->db->begin(); |
|
| 297 | - |
|
| 298 | - dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 299 | - $resql = $this->db->query($sql); |
|
| 300 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 301 | - |
|
| 302 | - if (! $error) |
|
| 303 | - { |
|
| 304 | - if (! $notrigger) |
|
| 305 | - { |
|
| 306 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 307 | - // want this action call a trigger. |
|
| 308 | - |
|
| 309 | - //// Call triggers |
|
| 310 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 311 | - //$interface=new Interfaces($this->db); |
|
| 312 | - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
| 313 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 314 | - //// End call triggers |
|
| 315 | - } |
|
| 316 | - } |
|
| 281 | + /** |
|
| 282 | + * Delete object in database |
|
| 283 | + * |
|
| 284 | + * @param User $user User that delete |
|
| 285 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 286 | + * @return int <0 if KO, >0 if OK |
|
| 287 | + */ |
|
| 288 | + function delete($user, $notrigger=0) |
|
| 289 | + { |
|
| 290 | + global $conf, $langs; |
|
| 291 | + $error=0; |
|
| 292 | + |
|
| 293 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; |
|
| 294 | + $sql.= " WHERE rowid=".$this->id; |
|
| 295 | + |
|
| 296 | + $this->db->begin(); |
|
| 297 | + |
|
| 298 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 299 | + $resql = $this->db->query($sql); |
|
| 300 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 301 | + |
|
| 302 | + if (! $error) |
|
| 303 | + { |
|
| 304 | + if (! $notrigger) |
|
| 305 | + { |
|
| 306 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 307 | + // want this action call a trigger. |
|
| 308 | + |
|
| 309 | + //// Call triggers |
|
| 310 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 311 | + //$interface=new Interfaces($this->db); |
|
| 312 | + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
| 313 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 314 | + //// End call triggers |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | // Commit or rollback |
| 319 | - if ($error) |
|
| 320 | - { |
|
| 321 | - foreach($this->errors as $errmsg) |
|
| 322 | - { |
|
| 323 | - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 324 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 325 | - } |
|
| 326 | - $this->db->rollback(); |
|
| 327 | - return -1*$error; |
|
| 328 | - } |
|
| 329 | - else |
|
| 330 | - { |
|
| 331 | - $this->db->commit(); |
|
| 332 | - return 1; |
|
| 333 | - } |
|
| 334 | - } |
|
| 319 | + if ($error) |
|
| 320 | + { |
|
| 321 | + foreach($this->errors as $errmsg) |
|
| 322 | + { |
|
| 323 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 324 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 325 | + } |
|
| 326 | + $this->db->rollback(); |
|
| 327 | + return -1*$error; |
|
| 328 | + } |
|
| 329 | + else |
|
| 330 | + { |
|
| 331 | + $this->db->commit(); |
|
| 332 | + return 1; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | 335 | } |
@@ -34,27 +34,27 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | abstract class CommonDocGenerator |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * @var string Error code (or message) |
|
| 39 | - */ |
|
| 40 | - public $error=''; |
|
| 37 | + /** |
|
| 38 | + * @var string Error code (or message) |
|
| 39 | + */ |
|
| 40 | + public $error=''; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @var string[] Array of error strings |
| 44 | 44 | */ |
| 45 | 45 | public $errors = array(); |
| 46 | 46 | |
| 47 | - /** |
|
| 47 | + /** |
|
| 48 | 48 | * @var DoliDB Database handler. |
| 49 | 49 | */ |
| 50 | - protected $db; |
|
| 50 | + protected $db; |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Constructor |
|
| 55 | - * |
|
| 56 | - * @param DoliDB $db Database handler |
|
| 57 | - */ |
|
| 53 | + /** |
|
| 54 | + * Constructor |
|
| 55 | + * |
|
| 56 | + * @param DoliDB $db Database handler |
|
| 57 | + */ |
|
| 58 | 58 | public function __construct($db) |
| 59 | 59 | { |
| 60 | 60 | $this->db = $db; |
@@ -82,18 +82,18 @@ discard block |
||
| 82 | 82 | 'myuser_fullname'=>$user->getFullName($outputlangs,1), |
| 83 | 83 | 'myuser_login'=>$user->login, |
| 84 | 84 | 'myuser_phone'=>$user->office_phone, |
| 85 | - 'myuser_address'=>$user->address, |
|
| 86 | - 'myuser_zip'=>$user->zip, |
|
| 87 | - 'myuser_town'=>$user->town, |
|
| 88 | - 'myuser_country'=>$user->country, |
|
| 89 | - 'myuser_country_code'=>$user->country_code, |
|
| 90 | - 'myuser_state'=>$user->state, |
|
| 91 | - 'myuser_state_code'=>$user->state_code, |
|
| 92 | - 'myuser_fax'=>$user->office_fax, |
|
| 85 | + 'myuser_address'=>$user->address, |
|
| 86 | + 'myuser_zip'=>$user->zip, |
|
| 87 | + 'myuser_town'=>$user->town, |
|
| 88 | + 'myuser_country'=>$user->country, |
|
| 89 | + 'myuser_country_code'=>$user->country_code, |
|
| 90 | + 'myuser_state'=>$user->state, |
|
| 91 | + 'myuser_state_code'=>$user->state_code, |
|
| 92 | + 'myuser_fax'=>$user->office_fax, |
|
| 93 | 93 | 'myuser_mobile'=>$user->user_mobile, |
| 94 | 94 | 'myuser_email'=>$user->email, |
| 95 | - 'myuser_logo'=>$logotouse, |
|
| 96 | - 'myuser_job'=>$user->job, |
|
| 95 | + 'myuser_logo'=>$logotouse, |
|
| 96 | + 'myuser_job'=>$user->job, |
|
| 97 | 97 | 'myuser_web'=>'' // url not exist in $user object |
| 98 | 98 | ); |
| 99 | 99 | } |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | if (empty($mysoc->country) && ! empty($mysoc->country_code)) |
| 120 | 120 | { |
| 121 | - $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code); |
|
| 121 | + $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code); |
|
| 122 | 122 | } |
| 123 | 123 | if (empty($mysoc->state) && ! empty($mysoc->state_code)) |
| 124 | 124 | { |
| 125 | - $mysoc->state=getState($mysoc->state_code,0); |
|
| 125 | + $mysoc->state=getState($mysoc->state_code,0); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | 'mycompany_country_code'=>$mysoc->country_code, |
| 141 | 141 | 'mycompany_state'=>$mysoc->state, |
| 142 | 142 | 'mycompany_state_code'=>$mysoc->state_code, |
| 143 | - 'mycompany_web'=>$mysoc->url, |
|
| 143 | + 'mycompany_web'=>$mysoc->url, |
|
| 144 | 144 | 'mycompany_juridicalstatus'=>$mysoc->forme_juridique, |
| 145 | 145 | 'mycompany_managers'=>$mysoc->managers, |
| 146 | 146 | 'mycompany_capital'=>$mysoc->capital, |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | 'mycompany_idprof4'=>$mysoc->idprof4, |
| 152 | 152 | 'mycompany_idprof5'=>$mysoc->idprof5, |
| 153 | 153 | 'mycompany_idprof6'=>$mysoc->idprof6, |
| 154 | - 'mycompany_vatnumber'=>$mysoc->tva_intra, |
|
| 155 | - 'mycompany_object'=>$mysoc->object, |
|
| 154 | + 'mycompany_vatnumber'=>$mysoc->tva_intra, |
|
| 155 | + 'mycompany_object'=>$mysoc->object, |
|
| 156 | 156 | 'mycompany_note_private'=>$mysoc->note_private, |
| 157 | 157 | //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties |
| 158 | 158 | ); |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | if (empty($object->country) && ! empty($object->country_code)) |
| 176 | 176 | { |
| 177 | - $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 177 | + $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 178 | 178 | } |
| 179 | 179 | if (empty($object->state) && ! empty($object->state_code)) |
| 180 | 180 | { |
| 181 | - $object->state=getState($object->state_code,0); |
|
| 181 | + $object->state=getState($object->state_code,0); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $array_thirdparty = array( |
| 185 | 185 | 'company_name'=>$object->name, |
| 186 | - 'company_name_alias' => $object->name_alias, |
|
| 186 | + 'company_name_alias' => $object->name_alias, |
|
| 187 | 187 | 'company_email'=>$object->email, |
| 188 | 188 | 'company_phone'=>$object->phone, |
| 189 | 189 | 'company_fax'=>$object->fax, |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | 'company_zip'=>$object->zip, |
| 192 | 192 | 'company_town'=>$object->town, |
| 193 | 193 | 'company_country'=>$object->country, |
| 194 | - 'company_country_code'=>$object->country_code, |
|
| 194 | + 'company_country_code'=>$object->country_code, |
|
| 195 | 195 | 'company_state'=>$object->state, |
| 196 | - 'company_state_code'=>$object->state_code, |
|
| 197 | - 'company_web'=>$object->url, |
|
| 196 | + 'company_state_code'=>$object->state_code, |
|
| 197 | + 'company_web'=>$object->url, |
|
| 198 | 198 | 'company_barcode'=>$object->barcode, |
| 199 | 199 | 'company_vatnumber'=>$object->tva_intra, |
| 200 | 200 | 'company_customercode'=>$object->code_client, |
@@ -219,52 +219,52 @@ discard block |
||
| 219 | 219 | // Retrieve extrafields |
| 220 | 220 | if(is_array($object->array_options) && count($object->array_options)) |
| 221 | 221 | { |
| 222 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 223 | - $extrafields = new ExtraFields($this->db); |
|
| 224 | - $extralabels = $extrafields->fetch_name_optionals_label('societe',true); |
|
| 225 | - $object->fetch_optionals(); |
|
| 226 | - |
|
| 227 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 228 | - { |
|
| 229 | - if($extrafields->attribute_type[$key] == 'price') |
|
| 230 | - { |
|
| 231 | - $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 232 | - } |
|
| 233 | - else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 234 | - { |
|
| 235 | - $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 236 | - } |
|
| 237 | - $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key])); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - return $array_thirdparty; |
|
| 241 | - } |
|
| 222 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 223 | + $extrafields = new ExtraFields($this->db); |
|
| 224 | + $extralabels = $extrafields->fetch_name_optionals_label('societe',true); |
|
| 225 | + $object->fetch_optionals(); |
|
| 226 | + |
|
| 227 | + foreach($extrafields->attribute_label as $key=>$label) |
|
| 228 | + { |
|
| 229 | + if($extrafields->attribute_type[$key] == 'price') |
|
| 230 | + { |
|
| 231 | + $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 232 | + } |
|
| 233 | + else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 234 | + { |
|
| 235 | + $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 236 | + } |
|
| 237 | + $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key])); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + return $array_thirdparty; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 244 | - /** |
|
| 245 | - * Define array with couple subtitution key => subtitution value |
|
| 246 | - * |
|
| 247 | - * @param Contact $object contact |
|
| 248 | - * @param Translate $outputlangs object for output |
|
| 249 | - * @param array $array_key Name of the key for return array |
|
| 250 | - * @return array Array of substitution key->code |
|
| 251 | - */ |
|
| 244 | + /** |
|
| 245 | + * Define array with couple subtitution key => subtitution value |
|
| 246 | + * |
|
| 247 | + * @param Contact $object contact |
|
| 248 | + * @param Translate $outputlangs object for output |
|
| 249 | + * @param array $array_key Name of the key for return array |
|
| 250 | + * @return array Array of substitution key->code |
|
| 251 | + */ |
|
| 252 | 252 | function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') |
| 253 | 253 | { |
| 254 | 254 | // phpcs:enable |
| 255 | - global $conf; |
|
| 256 | - |
|
| 257 | - if(empty($object->country) && ! empty($object->country_code)) |
|
| 258 | - { |
|
| 259 | - $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code); |
|
| 260 | - } |
|
| 261 | - if(empty($object->state) && ! empty($object->state_code)) |
|
| 262 | - { |
|
| 263 | - $object->state = getState($object->state_code, 0); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $array_contact = array ( |
|
| 267 | - $array_key . '_fullname' => $object->getFullName($outputlangs, 1), |
|
| 255 | + global $conf; |
|
| 256 | + |
|
| 257 | + if(empty($object->country) && ! empty($object->country_code)) |
|
| 258 | + { |
|
| 259 | + $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code); |
|
| 260 | + } |
|
| 261 | + if(empty($object->state) && ! empty($object->state_code)) |
|
| 262 | + { |
|
| 263 | + $object->state = getState($object->state_code, 0); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $array_contact = array ( |
|
| 267 | + $array_key . '_fullname' => $object->getFullName($outputlangs, 1), |
|
| 268 | 268 | $array_key . '_lastname' => $object->lastname, |
| 269 | 269 | $array_key . '_firstname' => $object->firstname, |
| 270 | 270 | $array_key . '_address' => $object->address, |
@@ -290,28 +290,28 @@ discard block |
||
| 290 | 290 | $array_key . '_default_lang' => $object->default_lang, |
| 291 | 291 | $array_key . '_note_public' => $object->note_public, |
| 292 | 292 | $array_key . '_note_private' => $object->note_private |
| 293 | - ); |
|
| 294 | - |
|
| 295 | - // Retrieve extrafields |
|
| 296 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
| 297 | - $extrafields = new ExtraFields($this->db); |
|
| 298 | - $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); |
|
| 299 | - $object->fetch_optionals(); |
|
| 300 | - |
|
| 301 | - foreach($extrafields->attribute_label as $key => $label) |
|
| 302 | - { |
|
| 303 | - if ($extrafields->attribute_type[$key] == 'price') |
|
| 304 | - { |
|
| 305 | - $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency); |
|
| 306 | - } |
|
| 307 | - elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 308 | - { |
|
| 309 | - $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]]; |
|
| 310 | - } |
|
| 311 | - $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key])); |
|
| 312 | - } |
|
| 313 | - return $array_contact; |
|
| 314 | - } |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + // Retrieve extrafields |
|
| 296 | + require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
| 297 | + $extrafields = new ExtraFields($this->db); |
|
| 298 | + $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); |
|
| 299 | + $object->fetch_optionals(); |
|
| 300 | + |
|
| 301 | + foreach($extrafields->attribute_label as $key => $label) |
|
| 302 | + { |
|
| 303 | + if ($extrafields->attribute_type[$key] == 'price') |
|
| 304 | + { |
|
| 305 | + $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency); |
|
| 306 | + } |
|
| 307 | + elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 308 | + { |
|
| 309 | + $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]]; |
|
| 310 | + } |
|
| 311 | + $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key])); |
|
| 312 | + } |
|
| 313 | + return $array_contact; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | |
| 317 | 317 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -324,260 +324,260 @@ discard block |
||
| 324 | 324 | function get_substitutionarray_other($outputlangs) |
| 325 | 325 | { |
| 326 | 326 | // phpcs:enable |
| 327 | - global $conf; |
|
| 328 | - |
|
| 329 | - $now=dol_now('gmt'); // gmt |
|
| 330 | - $array_other = array( |
|
| 331 | - // Date in default language |
|
| 332 | - 'current_date'=>dol_print_date($now,'day','tzuser'), |
|
| 333 | - 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'), |
|
| 334 | - 'current_server_date'=>dol_print_date($now,'day','tzserver'), |
|
| 335 | - 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'), |
|
| 336 | - // Date in requested output language |
|
| 337 | - 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs), |
|
| 338 | - 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs), |
|
| 339 | - 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs), |
|
| 340 | - 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs), |
|
| 341 | - ); |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - foreach($conf->global as $key => $val) |
|
| 345 | - { |
|
| 346 | - if (preg_match('/(_pass|password|secret|_key|key$)/i', $key)) $newval = '*****forbidden*****'; |
|
| 347 | - else $newval = $val; |
|
| 348 | - $array_other['__['.$key.']__'] = $newval; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $array_other; |
|
| 327 | + global $conf; |
|
| 328 | + |
|
| 329 | + $now=dol_now('gmt'); // gmt |
|
| 330 | + $array_other = array( |
|
| 331 | + // Date in default language |
|
| 332 | + 'current_date'=>dol_print_date($now,'day','tzuser'), |
|
| 333 | + 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'), |
|
| 334 | + 'current_server_date'=>dol_print_date($now,'day','tzserver'), |
|
| 335 | + 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'), |
|
| 336 | + // Date in requested output language |
|
| 337 | + 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs), |
|
| 338 | + 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs), |
|
| 339 | + 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs), |
|
| 340 | + 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs), |
|
| 341 | + ); |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + foreach($conf->global as $key => $val) |
|
| 345 | + { |
|
| 346 | + if (preg_match('/(_pass|password|secret|_key|key$)/i', $key)) $newval = '*****forbidden*****'; |
|
| 347 | + else $newval = $val; |
|
| 348 | + $array_other['__['.$key.']__'] = $newval; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $array_other; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 356 | - /** |
|
| 357 | - * Define array with couple substitution key => substitution value |
|
| 358 | - * |
|
| 359 | - * @param Object $object Main object to use as data source |
|
| 360 | - * @param Translate $outputlangs Lang object to use for output |
|
| 356 | + /** |
|
| 357 | + * Define array with couple substitution key => substitution value |
|
| 358 | + * |
|
| 359 | + * @param Object $object Main object to use as data source |
|
| 360 | + * @param Translate $outputlangs Lang object to use for output |
|
| 361 | 361 | * @param string $array_key Name of the key for return array |
| 362 | - * @return array Array of substitution |
|
| 363 | - */ |
|
| 364 | - function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 365 | - { |
|
| 362 | + * @return array Array of substitution |
|
| 363 | + */ |
|
| 364 | + function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 365 | + { |
|
| 366 | 366 | // phpcs:enable |
| 367 | - global $conf; |
|
| 368 | - |
|
| 369 | - $sumpayed=$sumdeposit=$sumcreditnote=''; |
|
| 370 | - if ($object->element == 'facture') |
|
| 371 | - { |
|
| 372 | - $invoice_source=new Facture($this->db); |
|
| 373 | - if ($object->fk_facture_source > 0) |
|
| 374 | - { |
|
| 375 | - $invoice_source->fetch($object->fk_facture_source); |
|
| 376 | - } |
|
| 377 | - $sumpayed = $object->getSommePaiement(); |
|
| 378 | - $sumdeposit = $object->getSumDepositsUsed(); |
|
| 379 | - $sumcreditnote = $object->getSumCreditNotesUsed(); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date); |
|
| 383 | - |
|
| 384 | - $resarray=array( |
|
| 385 | - $array_key.'_id'=>$object->id, |
|
| 386 | - $array_key.'_ref'=>$object->ref, |
|
| 387 | - $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 388 | - $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), |
|
| 389 | - $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), |
|
| 390 | - $array_key.'_source_invoice_ref'=>$invoice_source->ref, |
|
| 391 | - // Dates |
|
| 367 | + global $conf; |
|
| 368 | + |
|
| 369 | + $sumpayed=$sumdeposit=$sumcreditnote=''; |
|
| 370 | + if ($object->element == 'facture') |
|
| 371 | + { |
|
| 372 | + $invoice_source=new Facture($this->db); |
|
| 373 | + if ($object->fk_facture_source > 0) |
|
| 374 | + { |
|
| 375 | + $invoice_source->fetch($object->fk_facture_source); |
|
| 376 | + } |
|
| 377 | + $sumpayed = $object->getSommePaiement(); |
|
| 378 | + $sumdeposit = $object->getSumDepositsUsed(); |
|
| 379 | + $sumcreditnote = $object->getSumCreditNotesUsed(); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date); |
|
| 383 | + |
|
| 384 | + $resarray=array( |
|
| 385 | + $array_key.'_id'=>$object->id, |
|
| 386 | + $array_key.'_ref'=>$object->ref, |
|
| 387 | + $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 388 | + $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), |
|
| 389 | + $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), |
|
| 390 | + $array_key.'_source_invoice_ref'=>$invoice_source->ref, |
|
| 391 | + // Dates |
|
| 392 | 392 | $array_key.'_hour'=>dol_print_date($date,'hour'), |
| 393 | - $array_key.'_date'=>dol_print_date($date,'day'), |
|
| 394 | - $array_key.'_date_rfc'=>dol_print_date($date,'dayrfc'), |
|
| 395 | - $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''), |
|
| 396 | - $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''), |
|
| 397 | - $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 398 | - $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), |
|
| 399 | - $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), |
|
| 400 | - $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), |
|
| 401 | - $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''), |
|
| 402 | - |
|
| 403 | - $array_key.'_payment_mode_code'=>$object->mode_reglement_code, |
|
| 404 | - $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), |
|
| 405 | - $array_key.'_payment_term_code'=>$object->cond_reglement_code, |
|
| 406 | - $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):($object->cond_reglement_doc?$object->cond_reglement_doc:$object->cond_reglement)), |
|
| 407 | - |
|
| 408 | - $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs), |
|
| 409 | - $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)), |
|
| 410 | - $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs), |
|
| 411 | - $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs), |
|
| 412 | - $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs), |
|
| 413 | - |
|
| 414 | - $array_key.'_total_ht'=>price2num($object->total_ht), |
|
| 415 | - $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)), |
|
| 416 | - $array_key.'_total_localtax1'=>price2num($object->total_localtax1), |
|
| 417 | - $array_key.'_total_localtax2'=>price2num($object->total_localtax2), |
|
| 418 | - $array_key.'_total_ttc'=>price2num($object->total_ttc), |
|
| 419 | - |
|
| 420 | - $array_key.'_multicurrency_code' => price2num($object->multicurrency_code), |
|
| 421 | - $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx), |
|
| 422 | - $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht), |
|
| 423 | - $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva), |
|
| 424 | - $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc), |
|
| 425 | - $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs), |
|
| 426 | - $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs), |
|
| 427 | - $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs), |
|
| 428 | - |
|
| 429 | - $array_key.'_note_private'=>$object->note, |
|
| 430 | - $array_key.'_note_public'=>$object->note_public, |
|
| 431 | - $array_key.'_note'=>$object->note_public, // For backward compatibility |
|
| 432 | - |
|
| 433 | - // Payments |
|
| 434 | - $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), |
|
| 435 | - $array_key.'_already_payed'=>price2num($sumpayed), |
|
| 436 | - $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs), |
|
| 437 | - $array_key.'_already_deposit'=>price2num($sumdeposit), |
|
| 438 | - $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), |
|
| 439 | - $array_key.'_already_creditnote'=>price2num($sumcreditnote), |
|
| 440 | - |
|
| 441 | - $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 442 | - $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), |
|
| 443 | - |
|
| 444 | - // Remain to pay with all know infrmation (except open direct debit requests) |
|
| 445 | - $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 446 | - $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') |
|
| 447 | - ); |
|
| 448 | - |
|
| 449 | - if (method_exists($object, 'getTotalDiscount')) { |
|
| 450 | - $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs); |
|
| 451 | - $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount()); |
|
| 452 | - } else { |
|
| 453 | - $resarray[$array_key.'_total_discount_ht_locale'] = ''; |
|
| 454 | - $resarray[$array_key.'_total_discount_ht'] = ''; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - // Fetch project information if there is a project assigned to this object |
|
| 458 | - if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0) |
|
| 459 | - { |
|
| 460 | - if (! is_object($object->project)) |
|
| 461 | - { |
|
| 462 | - $object->fetch_projet(); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $resarray[$array_key.'_project_ref'] = $object->project->ref; |
|
| 466 | - $resarray[$array_key.'_project_title'] = $object->project->title; |
|
| 467 | - $resarray[$array_key.'_project_description'] = $object->project->description; |
|
| 468 | - $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day'); |
|
| 469 | - $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day'); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - // Add vat by rates |
|
| 473 | - if (is_array($object->lines) && count($object->lines)>0) |
|
| 474 | - { |
|
| 475 | - foreach ($object->lines as $line) |
|
| 476 | - { |
|
| 477 | - // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility |
|
| 478 | - if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 479 | - $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 480 | - $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]); |
|
| 481 | - // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example) |
|
| 482 | - $vatformated=vatrate($line->tva_tx); |
|
| 483 | - if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0; |
|
| 484 | - $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva; |
|
| 485 | - $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - // Retrieve extrafields |
|
| 489 | - if (is_array($object->array_options) && count($object->array_options)) |
|
| 490 | - { |
|
| 491 | - $extrafieldkey=$object->element; |
|
| 492 | - |
|
| 493 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 494 | - $extrafields = new ExtraFields($this->db); |
|
| 495 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 496 | - $object->fetch_optionals(); |
|
| 497 | - |
|
| 498 | - $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 499 | - } |
|
| 500 | - return $resarray; |
|
| 501 | - } |
|
| 393 | + $array_key.'_date'=>dol_print_date($date,'day'), |
|
| 394 | + $array_key.'_date_rfc'=>dol_print_date($date,'dayrfc'), |
|
| 395 | + $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''), |
|
| 396 | + $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''), |
|
| 397 | + $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 398 | + $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), |
|
| 399 | + $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), |
|
| 400 | + $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), |
|
| 401 | + $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''), |
|
| 402 | + |
|
| 403 | + $array_key.'_payment_mode_code'=>$object->mode_reglement_code, |
|
| 404 | + $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), |
|
| 405 | + $array_key.'_payment_term_code'=>$object->cond_reglement_code, |
|
| 406 | + $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):($object->cond_reglement_doc?$object->cond_reglement_doc:$object->cond_reglement)), |
|
| 407 | + |
|
| 408 | + $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs), |
|
| 409 | + $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)), |
|
| 410 | + $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs), |
|
| 411 | + $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs), |
|
| 412 | + $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs), |
|
| 413 | + |
|
| 414 | + $array_key.'_total_ht'=>price2num($object->total_ht), |
|
| 415 | + $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)), |
|
| 416 | + $array_key.'_total_localtax1'=>price2num($object->total_localtax1), |
|
| 417 | + $array_key.'_total_localtax2'=>price2num($object->total_localtax2), |
|
| 418 | + $array_key.'_total_ttc'=>price2num($object->total_ttc), |
|
| 419 | + |
|
| 420 | + $array_key.'_multicurrency_code' => price2num($object->multicurrency_code), |
|
| 421 | + $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx), |
|
| 422 | + $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht), |
|
| 423 | + $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva), |
|
| 424 | + $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc), |
|
| 425 | + $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs), |
|
| 426 | + $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs), |
|
| 427 | + $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs), |
|
| 428 | + |
|
| 429 | + $array_key.'_note_private'=>$object->note, |
|
| 430 | + $array_key.'_note_public'=>$object->note_public, |
|
| 431 | + $array_key.'_note'=>$object->note_public, // For backward compatibility |
|
| 432 | + |
|
| 433 | + // Payments |
|
| 434 | + $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), |
|
| 435 | + $array_key.'_already_payed'=>price2num($sumpayed), |
|
| 436 | + $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs), |
|
| 437 | + $array_key.'_already_deposit'=>price2num($sumdeposit), |
|
| 438 | + $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), |
|
| 439 | + $array_key.'_already_creditnote'=>price2num($sumcreditnote), |
|
| 440 | + |
|
| 441 | + $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 442 | + $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), |
|
| 443 | + |
|
| 444 | + // Remain to pay with all know infrmation (except open direct debit requests) |
|
| 445 | + $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 446 | + $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') |
|
| 447 | + ); |
|
| 448 | + |
|
| 449 | + if (method_exists($object, 'getTotalDiscount')) { |
|
| 450 | + $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs); |
|
| 451 | + $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount()); |
|
| 452 | + } else { |
|
| 453 | + $resarray[$array_key.'_total_discount_ht_locale'] = ''; |
|
| 454 | + $resarray[$array_key.'_total_discount_ht'] = ''; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + // Fetch project information if there is a project assigned to this object |
|
| 458 | + if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0) |
|
| 459 | + { |
|
| 460 | + if (! is_object($object->project)) |
|
| 461 | + { |
|
| 462 | + $object->fetch_projet(); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $resarray[$array_key.'_project_ref'] = $object->project->ref; |
|
| 466 | + $resarray[$array_key.'_project_title'] = $object->project->title; |
|
| 467 | + $resarray[$array_key.'_project_description'] = $object->project->description; |
|
| 468 | + $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day'); |
|
| 469 | + $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day'); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + // Add vat by rates |
|
| 473 | + if (is_array($object->lines) && count($object->lines)>0) |
|
| 474 | + { |
|
| 475 | + foreach ($object->lines as $line) |
|
| 476 | + { |
|
| 477 | + // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility |
|
| 478 | + if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 479 | + $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 480 | + $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]); |
|
| 481 | + // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example) |
|
| 482 | + $vatformated=vatrate($line->tva_tx); |
|
| 483 | + if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0; |
|
| 484 | + $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva; |
|
| 485 | + $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + // Retrieve extrafields |
|
| 489 | + if (is_array($object->array_options) && count($object->array_options)) |
|
| 490 | + { |
|
| 491 | + $extrafieldkey=$object->element; |
|
| 492 | + |
|
| 493 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 494 | + $extrafields = new ExtraFields($this->db); |
|
| 495 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 496 | + $object->fetch_optionals(); |
|
| 497 | + |
|
| 498 | + $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 499 | + } |
|
| 500 | + return $resarray; |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | 503 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 504 | - /** |
|
| 505 | - * Define array with couple substitution key => substitution value |
|
| 506 | - * |
|
| 507 | - * @param Object $line Object line |
|
| 508 | - * @param Translate $outputlangs Lang object to use for output |
|
| 509 | - * @return array Return a substitution array |
|
| 510 | - */ |
|
| 511 | - function get_substitutionarray_lines($line, $outputlangs) |
|
| 512 | - { |
|
| 504 | + /** |
|
| 505 | + * Define array with couple substitution key => substitution value |
|
| 506 | + * |
|
| 507 | + * @param Object $line Object line |
|
| 508 | + * @param Translate $outputlangs Lang object to use for output |
|
| 509 | + * @return array Return a substitution array |
|
| 510 | + */ |
|
| 511 | + function get_substitutionarray_lines($line, $outputlangs) |
|
| 512 | + { |
|
| 513 | 513 | // phpcs:enable |
| 514 | - global $conf; |
|
| 515 | - |
|
| 516 | - $resarray= array( |
|
| 517 | - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 518 | - 'line_product_ref'=>$line->product_ref, |
|
| 519 | - 'line_product_ref_fourn'=>$line->ref_fourn, // for supplier doc lines |
|
| 520 | - 'line_product_label'=>$line->product_label, |
|
| 521 | - 'line_product_type'=>$line->product_type, |
|
| 522 | - 'line_desc'=>$line->desc, |
|
| 523 | - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 524 | - 'line_up'=>price2num($line->subprice), |
|
| 525 | - 'line_up_locale'=>price($line->subprice, 0, $outputlangs), |
|
| 526 | - 'line_qty'=>$line->qty, |
|
| 527 | - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 528 | - 'line_price_ht'=>price2num($line->total_ht), |
|
| 529 | - 'line_price_ttc'=>price2num($line->total_ttc), |
|
| 530 | - 'line_price_vat'=>price2num($line->total_tva), |
|
| 531 | - 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs), |
|
| 532 | - 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs), |
|
| 533 | - 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs), |
|
| 534 | - // Dates |
|
| 535 | - 'line_date_start'=>dol_print_date($line->date_start, 'day', 'tzuser'), |
|
| 536 | - 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzuser', $outputlangs), |
|
| 537 | - 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc', 'tzuser'), |
|
| 538 | - 'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'), |
|
| 539 | - 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs), |
|
| 540 | - 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'), |
|
| 541 | - |
|
| 542 | - 'line_multicurrency_code' => price2num($line->multicurrency_code), |
|
| 543 | - 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice), |
|
| 544 | - 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht), |
|
| 545 | - 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva), |
|
| 546 | - 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc), |
|
| 547 | - 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs), |
|
| 548 | - 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs), |
|
| 549 | - 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs), |
|
| 550 | - 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs), |
|
| 551 | - ); |
|
| 552 | - |
|
| 553 | - // Units |
|
| 554 | - if ($conf->global->PRODUCT_USE_UNITS) |
|
| 555 | - { |
|
| 556 | - $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long')); |
|
| 557 | - $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short')); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // Retrieve extrafields |
|
| 561 | - $extrafieldkey=$line->element; |
|
| 562 | - $array_key="line"; |
|
| 563 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 564 | - $extrafields = new ExtraFields($this->db); |
|
| 565 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 566 | - $line->fetch_optionals(); |
|
| 567 | - |
|
| 568 | - $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs); |
|
| 569 | - |
|
| 570 | - // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" |
|
| 571 | - if (isset($line->fk_product) && $line->fk_product > 0) |
|
| 572 | - { |
|
| 573 | - $tmpproduct = new Product($this->db); |
|
| 574 | - $result = $tmpproduct->fetch($line->fk_product); |
|
| 575 | - foreach($tmpproduct->array_options as $key=>$label) |
|
| 576 | - $resarray["line_product_".$key] = $label; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return $resarray; |
|
| 580 | - } |
|
| 514 | + global $conf; |
|
| 515 | + |
|
| 516 | + $resarray= array( |
|
| 517 | + 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 518 | + 'line_product_ref'=>$line->product_ref, |
|
| 519 | + 'line_product_ref_fourn'=>$line->ref_fourn, // for supplier doc lines |
|
| 520 | + 'line_product_label'=>$line->product_label, |
|
| 521 | + 'line_product_type'=>$line->product_type, |
|
| 522 | + 'line_desc'=>$line->desc, |
|
| 523 | + 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 524 | + 'line_up'=>price2num($line->subprice), |
|
| 525 | + 'line_up_locale'=>price($line->subprice, 0, $outputlangs), |
|
| 526 | + 'line_qty'=>$line->qty, |
|
| 527 | + 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 528 | + 'line_price_ht'=>price2num($line->total_ht), |
|
| 529 | + 'line_price_ttc'=>price2num($line->total_ttc), |
|
| 530 | + 'line_price_vat'=>price2num($line->total_tva), |
|
| 531 | + 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs), |
|
| 532 | + 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs), |
|
| 533 | + 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs), |
|
| 534 | + // Dates |
|
| 535 | + 'line_date_start'=>dol_print_date($line->date_start, 'day', 'tzuser'), |
|
| 536 | + 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzuser', $outputlangs), |
|
| 537 | + 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc', 'tzuser'), |
|
| 538 | + 'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'), |
|
| 539 | + 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs), |
|
| 540 | + 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'), |
|
| 541 | + |
|
| 542 | + 'line_multicurrency_code' => price2num($line->multicurrency_code), |
|
| 543 | + 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice), |
|
| 544 | + 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht), |
|
| 545 | + 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva), |
|
| 546 | + 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc), |
|
| 547 | + 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs), |
|
| 548 | + 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs), |
|
| 549 | + 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs), |
|
| 550 | + 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs), |
|
| 551 | + ); |
|
| 552 | + |
|
| 553 | + // Units |
|
| 554 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 555 | + { |
|
| 556 | + $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long')); |
|
| 557 | + $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short')); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // Retrieve extrafields |
|
| 561 | + $extrafieldkey=$line->element; |
|
| 562 | + $array_key="line"; |
|
| 563 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 564 | + $extrafields = new ExtraFields($this->db); |
|
| 565 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 566 | + $line->fetch_optionals(); |
|
| 567 | + |
|
| 568 | + $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs); |
|
| 569 | + |
|
| 570 | + // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" |
|
| 571 | + if (isset($line->fk_product) && $line->fk_product > 0) |
|
| 572 | + { |
|
| 573 | + $tmpproduct = new Product($this->db); |
|
| 574 | + $result = $tmpproduct->fetch($line->fk_product); |
|
| 575 | + foreach($tmpproduct->array_options as $key=>$label) |
|
| 576 | + $resarray["line_product_".$key] = $label; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $resarray; |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | 582 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 583 | 583 | /** |
@@ -591,54 +591,54 @@ discard block |
||
| 591 | 591 | function get_substitutionarray_shipment($object,$outputlangs,$array_key='object') |
| 592 | 592 | { |
| 593 | 593 | // phpcs:enable |
| 594 | - global $conf; |
|
| 595 | - dol_include_once('/core/lib/product.lib.php'); |
|
| 596 | - $object->list_delivery_methods($object->shipping_method_id); |
|
| 597 | - $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); |
|
| 598 | - |
|
| 599 | - $array_shipment=array( |
|
| 600 | - $array_key.'_id'=>$object->id, |
|
| 601 | - $array_key.'_ref'=>$object->ref, |
|
| 602 | - $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 603 | - $array_key.'_ref_customer'=>$object->ref_customer, |
|
| 604 | - $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'), |
|
| 605 | - $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'), |
|
| 606 | - $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 607 | - $array_key.'_total_ht'=>price($object->total_ht), |
|
| 608 | - $array_key.'_total_vat'=>price($object->total_tva), |
|
| 609 | - $array_key.'_total_ttc'=>price($object->total_ttc), |
|
| 610 | - $array_key.'_total_discount_ht' => price($object->getTotalDiscount()), |
|
| 611 | - $array_key.'_note_private'=>$object->note_private, |
|
| 612 | - $array_key.'_note'=>$object->note_public, |
|
| 613 | - $array_key.'_tracking_number'=>$object->tracking_number, |
|
| 614 | - $array_key.'_tracking_url'=>$object->tracking_url, |
|
| 615 | - $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'], |
|
| 616 | - $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'), |
|
| 617 | - $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'), |
|
| 618 | - $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'), |
|
| 619 | - $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'), |
|
| 620 | - $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'), |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - // Add vat by rates |
|
| 624 | - foreach ($object->lines as $line) |
|
| 625 | - { |
|
| 626 | - if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 627 | - $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // Retrieve extrafields |
|
| 631 | - if (is_array($object->array_options) && count($object->array_options)) |
|
| 632 | - { |
|
| 633 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 634 | - $extrafields = new ExtraFields($this->db); |
|
| 635 | - $extralabels = $extrafields->fetch_name_optionals_label('expedition',true); |
|
| 636 | - $object->fetch_optionals(); |
|
| 637 | - |
|
| 638 | - $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - return $array_shipment; |
|
| 594 | + global $conf; |
|
| 595 | + dol_include_once('/core/lib/product.lib.php'); |
|
| 596 | + $object->list_delivery_methods($object->shipping_method_id); |
|
| 597 | + $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); |
|
| 598 | + |
|
| 599 | + $array_shipment=array( |
|
| 600 | + $array_key.'_id'=>$object->id, |
|
| 601 | + $array_key.'_ref'=>$object->ref, |
|
| 602 | + $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 603 | + $array_key.'_ref_customer'=>$object->ref_customer, |
|
| 604 | + $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'), |
|
| 605 | + $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'), |
|
| 606 | + $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 607 | + $array_key.'_total_ht'=>price($object->total_ht), |
|
| 608 | + $array_key.'_total_vat'=>price($object->total_tva), |
|
| 609 | + $array_key.'_total_ttc'=>price($object->total_ttc), |
|
| 610 | + $array_key.'_total_discount_ht' => price($object->getTotalDiscount()), |
|
| 611 | + $array_key.'_note_private'=>$object->note_private, |
|
| 612 | + $array_key.'_note'=>$object->note_public, |
|
| 613 | + $array_key.'_tracking_number'=>$object->tracking_number, |
|
| 614 | + $array_key.'_tracking_url'=>$object->tracking_url, |
|
| 615 | + $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'], |
|
| 616 | + $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'), |
|
| 617 | + $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'), |
|
| 618 | + $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'), |
|
| 619 | + $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'), |
|
| 620 | + $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'), |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + // Add vat by rates |
|
| 624 | + foreach ($object->lines as $line) |
|
| 625 | + { |
|
| 626 | + if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 627 | + $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // Retrieve extrafields |
|
| 631 | + if (is_array($object->array_options) && count($object->array_options)) |
|
| 632 | + { |
|
| 633 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 634 | + $extrafields = new ExtraFields($this->db); |
|
| 635 | + $extralabels = $extrafields->fetch_name_optionals_label('expedition',true); |
|
| 636 | + $object->fetch_optionals(); |
|
| 637 | + |
|
| 638 | + $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + return $array_shipment; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | |
@@ -657,24 +657,24 @@ discard block |
||
| 657 | 657 | dol_include_once('/core/lib/product.lib.php'); |
| 658 | 658 | |
| 659 | 659 | $resarray = array( |
| 660 | - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 661 | - 'line_product_ref'=>$line->product_ref, |
|
| 662 | - 'line_product_label'=>$line->product_label, |
|
| 663 | - 'line_desc'=>$line->desc, |
|
| 664 | - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 665 | - 'line_up'=>price($line->subprice), |
|
| 666 | - 'line_qty'=>$line->qty, |
|
| 667 | - 'line_qty_shipped'=>$line->qty_shipped, |
|
| 668 | - 'line_qty_asked'=>$line->qty_asked, |
|
| 669 | - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 670 | - 'line_price_ht'=>price($line->total_ht), |
|
| 671 | - 'line_price_ttc'=>price($line->total_ttc), |
|
| 672 | - 'line_price_vat'=>price($line->total_tva), |
|
| 673 | - 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'), |
|
| 674 | - 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'), |
|
| 675 | - 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'), |
|
| 676 | - 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'), |
|
| 677 | - ); |
|
| 660 | + 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 661 | + 'line_product_ref'=>$line->product_ref, |
|
| 662 | + 'line_product_label'=>$line->product_label, |
|
| 663 | + 'line_desc'=>$line->desc, |
|
| 664 | + 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 665 | + 'line_up'=>price($line->subprice), |
|
| 666 | + 'line_qty'=>$line->qty, |
|
| 667 | + 'line_qty_shipped'=>$line->qty_shipped, |
|
| 668 | + 'line_qty_asked'=>$line->qty_asked, |
|
| 669 | + 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 670 | + 'line_price_ht'=>price($line->total_ht), |
|
| 671 | + 'line_price_ttc'=>price($line->total_ttc), |
|
| 672 | + 'line_price_vat'=>price($line->total_tva), |
|
| 673 | + 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'), |
|
| 674 | + 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'), |
|
| 675 | + 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'), |
|
| 676 | + 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'), |
|
| 677 | + ); |
|
| 678 | 678 | |
| 679 | 679 | // Retrieve extrafields |
| 680 | 680 | $extrafieldkey = $line->element; |
@@ -731,92 +731,92 @@ discard block |
||
| 731 | 731 | * @return array Substitution array |
| 732 | 732 | */ |
| 733 | 733 | function fill_substitutionarray_with_extrafields($object,$array_to_fill,$extrafields,$array_key,$outputlangs) |
| 734 | - { |
|
| 734 | + { |
|
| 735 | 735 | // phpcs:enable |
| 736 | - global $conf; |
|
| 737 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 738 | - { |
|
| 739 | - if($extrafields->attribute_type[$key] == 'price') |
|
| 740 | - { |
|
| 741 | - $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]); |
|
| 742 | - $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 743 | - //Add value to store price with currency |
|
| 744 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); |
|
| 745 | - } |
|
| 746 | - else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 747 | - { |
|
| 748 | - $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 749 | - } |
|
| 750 | - else if($extrafields->attribute_type[$key] == 'date') |
|
| 751 | - { |
|
| 752 | - if (strlen($object->array_options['options_'.$key])>0) |
|
| 753 | - { |
|
| 754 | - $date = $object->array_options['options_'.$key]; |
|
| 755 | - $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language |
|
| 756 | - $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format |
|
| 757 | - $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format |
|
| 758 | - } |
|
| 759 | - else |
|
| 760 | - { |
|
| 761 | - $object->array_options['options_'.$key] = ''; |
|
| 762 | - $object->array_options['options_'.$key.'_locale'] = ''; |
|
| 763 | - $object->array_options['options_'.$key.'_rfc'] = ''; |
|
| 764 | - } |
|
| 765 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 766 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 767 | - } |
|
| 768 | - else if($extrafields->attribute_type[$key] == 'datetime') |
|
| 769 | - { |
|
| 770 | - $datetime = $object->array_options['options_'.$key]; |
|
| 771 | - $object->array_options['options_'.$key] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language |
|
| 772 | - $object->array_options['options_'.$key.'_locale'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format |
|
| 773 | - $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format |
|
| 774 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 775 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 776 | - } |
|
| 777 | - else if($extrafields->attribute_type[$key] == 'link') |
|
| 778 | - { |
|
| 779 | - $id = $object->array_options['options_'.$key]; |
|
| 780 | - if ($id != "") |
|
| 781 | - { |
|
| 782 | - $param = $extrafields->attribute_param[$key]; |
|
| 783 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 784 | - $InfoFieldList = explode(":", $param_list[0]); |
|
| 785 | - $classname=$InfoFieldList[0]; |
|
| 786 | - $classpath=$InfoFieldList[1]; |
|
| 787 | - if (! empty($classpath)) |
|
| 788 | - { |
|
| 789 | - dol_include_once($InfoFieldList[1]); |
|
| 790 | - if ($classname && class_exists($classname)) |
|
| 791 | - { |
|
| 792 | - $tmpobject = new $classname($this->db); |
|
| 793 | - $tmpobject->fetch($id); |
|
| 794 | - // completely replace the id with the linked object name |
|
| 795 | - $object->array_options['options_'.$key] = $tmpobject->name; |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - return $array_to_fill; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * Rect pdf |
|
| 810 | - * |
|
| 811 | - * @param TCPDF $pdf Object PDF |
|
| 812 | - * @param float $x Abscissa of first point |
|
| 813 | - * @param float $y Ordinate of first point |
|
| 814 | - * @param float $l ?? |
|
| 815 | - * @param float $h ?? |
|
| 816 | - * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
|
| 817 | - * @param int $hidebottom Hide bottom |
|
| 818 | - * @return void |
|
| 819 | - */ |
|
| 736 | + global $conf; |
|
| 737 | + foreach($extrafields->attribute_label as $key=>$label) |
|
| 738 | + { |
|
| 739 | + if($extrafields->attribute_type[$key] == 'price') |
|
| 740 | + { |
|
| 741 | + $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]); |
|
| 742 | + $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 743 | + //Add value to store price with currency |
|
| 744 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); |
|
| 745 | + } |
|
| 746 | + else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 747 | + { |
|
| 748 | + $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 749 | + } |
|
| 750 | + else if($extrafields->attribute_type[$key] == 'date') |
|
| 751 | + { |
|
| 752 | + if (strlen($object->array_options['options_'.$key])>0) |
|
| 753 | + { |
|
| 754 | + $date = $object->array_options['options_'.$key]; |
|
| 755 | + $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language |
|
| 756 | + $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format |
|
| 757 | + $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format |
|
| 758 | + } |
|
| 759 | + else |
|
| 760 | + { |
|
| 761 | + $object->array_options['options_'.$key] = ''; |
|
| 762 | + $object->array_options['options_'.$key.'_locale'] = ''; |
|
| 763 | + $object->array_options['options_'.$key.'_rfc'] = ''; |
|
| 764 | + } |
|
| 765 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 766 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 767 | + } |
|
| 768 | + else if($extrafields->attribute_type[$key] == 'datetime') |
|
| 769 | + { |
|
| 770 | + $datetime = $object->array_options['options_'.$key]; |
|
| 771 | + $object->array_options['options_'.$key] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language |
|
| 772 | + $object->array_options['options_'.$key.'_locale'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format |
|
| 773 | + $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format |
|
| 774 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 775 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 776 | + } |
|
| 777 | + else if($extrafields->attribute_type[$key] == 'link') |
|
| 778 | + { |
|
| 779 | + $id = $object->array_options['options_'.$key]; |
|
| 780 | + if ($id != "") |
|
| 781 | + { |
|
| 782 | + $param = $extrafields->attribute_param[$key]; |
|
| 783 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 784 | + $InfoFieldList = explode(":", $param_list[0]); |
|
| 785 | + $classname=$InfoFieldList[0]; |
|
| 786 | + $classpath=$InfoFieldList[1]; |
|
| 787 | + if (! empty($classpath)) |
|
| 788 | + { |
|
| 789 | + dol_include_once($InfoFieldList[1]); |
|
| 790 | + if ($classname && class_exists($classname)) |
|
| 791 | + { |
|
| 792 | + $tmpobject = new $classname($this->db); |
|
| 793 | + $tmpobject->fetch($id); |
|
| 794 | + // completely replace the id with the linked object name |
|
| 795 | + $object->array_options['options_'.$key] = $tmpobject->name; |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + return $array_to_fill; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Rect pdf |
|
| 810 | + * |
|
| 811 | + * @param TCPDF $pdf Object PDF |
|
| 812 | + * @param float $x Abscissa of first point |
|
| 813 | + * @param float $y Ordinate of first point |
|
| 814 | + * @param float $l ?? |
|
| 815 | + * @param float $h ?? |
|
| 816 | + * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
|
| 817 | + * @param int $hidebottom Hide bottom |
|
| 818 | + * @return void |
|
| 819 | + */ |
|
| 820 | 820 | function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0) |
| 821 | 821 | { |
| 822 | 822 | if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y); |
@@ -28,22 +28,22 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class Canvas |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | + /** |
|
| 32 | 32 | * @var DoliDB Database handler. |
| 33 | 33 | */ |
| 34 | 34 | public $db; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string Error code (or message) |
|
| 38 | - */ |
|
| 39 | - public $error=''; |
|
| 36 | + /** |
|
| 37 | + * @var string Error code (or message) |
|
| 38 | + */ |
|
| 39 | + public $error=''; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string[] Error codes (or messages) |
|
| 43 | - */ |
|
| 44 | - public $errors = array(); |
|
| 41 | + /** |
|
| 42 | + * @var string[] Error codes (or messages) |
|
| 43 | + */ |
|
| 44 | + public $errors = array(); |
|
| 45 | 45 | |
| 46 | - public $actiontype; |
|
| 46 | + public $actiontype; |
|
| 47 | 47 | |
| 48 | 48 | public $dirmodule; // Module directory |
| 49 | 49 | public $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) |
@@ -54,65 +54,65 @@ discard block |
||
| 54 | 54 | public $control; // Initialized by getCanvas with controller instance |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Constructor |
|
| 59 | - * |
|
| 60 | - * @param DoliDB $db Database handler |
|
| 61 | - * @param string $actiontype Action type ('create', 'view', 'edit', 'list') |
|
| 62 | - */ |
|
| 63 | - function __construct($db, $actiontype='view') |
|
| 64 | - { |
|
| 65 | - $this->db = $db; |
|
| 66 | - |
|
| 67 | - $this->actiontype = $this->_cleanaction($actiontype); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Return action code cleaned |
|
| 72 | - * |
|
| 73 | - * @param string $action Action type ('create', 'view', 'edit', 'list', 'add', 'update') |
|
| 74 | - * @return string Cleaned action type ('create', 'view', 'edit', 'list') |
|
| 75 | - */ |
|
| 76 | - private function _cleanaction($action) |
|
| 77 | - { |
|
| 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'; |
|
| 82 | - return $newaction; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Initialize properties: ->targetmodule, ->canvas, ->card, ->dirmodule, ->template_dir |
|
| 88 | - * |
|
| 89 | - * @param string $module Name of target module (thirdparty, contact, ...) |
|
| 90 | - * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page |
|
| 91 | - * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - function getCanvas($module, $card, $canvas) |
|
| 95 | - { |
|
| 96 | - global $conf, $langs; |
|
| 97 | - |
|
| 98 | - // Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas |
|
| 57 | + /** |
|
| 58 | + * Constructor |
|
| 59 | + * |
|
| 60 | + * @param DoliDB $db Database handler |
|
| 61 | + * @param string $actiontype Action type ('create', 'view', 'edit', 'list') |
|
| 62 | + */ |
|
| 63 | + function __construct($db, $actiontype='view') |
|
| 64 | + { |
|
| 65 | + $this->db = $db; |
|
| 66 | + |
|
| 67 | + $this->actiontype = $this->_cleanaction($actiontype); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Return action code cleaned |
|
| 72 | + * |
|
| 73 | + * @param string $action Action type ('create', 'view', 'edit', 'list', 'add', 'update') |
|
| 74 | + * @return string Cleaned action type ('create', 'view', 'edit', 'list') |
|
| 75 | + */ |
|
| 76 | + private function _cleanaction($action) |
|
| 77 | + { |
|
| 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'; |
|
| 82 | + return $newaction; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Initialize properties: ->targetmodule, ->canvas, ->card, ->dirmodule, ->template_dir |
|
| 88 | + * |
|
| 89 | + * @param string $module Name of target module (thirdparty, contact, ...) |
|
| 90 | + * @param string $card Tab name of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page |
|
| 91 | + * @param string $canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + function getCanvas($module, $card, $canvas) |
|
| 95 | + { |
|
| 96 | + global $conf, $langs; |
|
| 97 | + |
|
| 98 | + // Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas |
|
| 99 | 99 | $this->targetmodule = $module; |
| 100 | 100 | $this->canvas = $canvas; |
| 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)) |
|
| 105 | - { |
|
| 104 | + if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs)) |
|
| 105 | + { |
|
| 106 | 106 | $this->canvas = $regs[1]; |
| 107 | - $this->dirmodule = $regs[2]; |
|
| 108 | - } |
|
| 109 | - // For compatibility |
|
| 107 | + $this->dirmodule = $regs[2]; |
|
| 108 | + } |
|
| 109 | + // For compatibility |
|
| 110 | 110 | if ($this->dirmodule == 'thirdparty') { $this->dirmodule = 'societe'; } |
| 111 | 111 | |
| 112 | 112 | // Control file |
| 113 | - $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); |
|
| 114 | - if (file_exists($controlclassfile)) |
|
| 115 | - { |
|
| 113 | + $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); |
|
| 114 | + if (file_exists($controlclassfile)) |
|
| 115 | + { |
|
| 116 | 116 | // Include actions class (controller) |
| 117 | 117 | $this->control_file=$controlclassfile; |
| 118 | 118 | require_once $controlclassfile; |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | // Instantiate actions class (controller) |
| 121 | 121 | $controlclassname = 'Actions'.ucfirst($this->card).ucfirst($this->canvas); |
| 122 | 122 | $this->control = new $controlclassname($this->db, $this->dirmodule, $this->targetmodule, $this->canvas, $this->card); |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - // Template dir |
|
| 126 | - $this->template_dir = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/tpl/'); |
|
| 125 | + // Template dir |
|
| 126 | + $this->template_dir = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/tpl/'); |
|
| 127 | 127 | if (! is_dir($this->template_dir)) |
| 128 | 128 | { |
| 129 | 129 | $this->template_dir=''; |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | //print 'dimodule='.$dirmodule.' canvas='.$this->canvas.'<br>'; |
| 133 | 133 | //print ' => template_dir='.$this->template_dir.'<br>'; |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 137 | 137 | /** |
| 138 | - * Shared method for canvas to assign values for templates |
|
| 139 | - * |
|
| 140 | - * @param string $action Action string |
|
| 141 | - * @param int $id Object id (if ref not provided) |
|
| 142 | - * @param string $ref Object ref (if id not provided) |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - function assign_values(&$action='view', $id=0, $ref='') |
|
| 146 | - { |
|
| 138 | + * Shared method for canvas to assign values for templates |
|
| 139 | + * |
|
| 140 | + * @param string $action Action string |
|
| 141 | + * @param int $id Object id (if ref not provided) |
|
| 142 | + * @param string $ref Object ref (if id not provided) |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + function assign_values(&$action='view', $id=0, $ref='') |
|
| 146 | + { |
|
| 147 | 147 | // phpcs:enable |
| 148 | - if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id, $ref); |
|
| 149 | - } |
|
| 148 | + if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id, $ref); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * Return the template to display canvas (if it exists) |
| 153 | - * |
|
| 154 | - * @param string $action Action code |
|
| 153 | + * |
|
| 154 | + * @param string $action Action code |
|
| 155 | 155 | * @return int 0=Canvas template file does not exist, 1=Canvas template file exists |
| 156 | 156 | */ |
| 157 | 157 | function displayCanvasExists($action) |
@@ -163,53 +163,53 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 166 | - /** |
|
| 167 | - * Display a canvas page. This will include the template for output. |
|
| 168 | - * Variables used by templates may have been defined or loaded before into the assign_values function. |
|
| 169 | - * |
|
| 170 | - * @param string $action Action code |
|
| 171 | - * @return void |
|
| 172 | - */ |
|
| 173 | - function display_canvas($action) |
|
| 174 | - { |
|
| 166 | + /** |
|
| 167 | + * Display a canvas page. This will include the template for output. |
|
| 168 | + * Variables used by templates may have been defined or loaded before into the assign_values function. |
|
| 169 | + * |
|
| 170 | + * @param string $action Action code |
|
| 171 | + * @return void |
|
| 172 | + */ |
|
| 173 | + function display_canvas($action) |
|
| 174 | + { |
|
| 175 | 175 | // phpcs:enable |
| 176 | - global $db, $conf, $langs, $user, $canvas; |
|
| 177 | - global $form, $formfile; |
|
| 176 | + global $db, $conf, $langs, $user, $canvas; |
|
| 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 |
|
| 180 | - } |
|
| 179 | + include $this->template_dir.(!empty($this->card)?$this->card.'_':'').$this->_cleanaction($action).'.tpl.php'; // Include native PHP template |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | - // This functions should not be used anymore because canvas should contains only templates. |
|
| 184 | - // http://wiki.dolibarr.org/index.php/Canvas_development |
|
| 183 | + // This functions should not be used anymore because canvas should contains only templates. |
|
| 184 | + // http://wiki.dolibarr.org/index.php/Canvas_development |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Return if a canvas contains an action controller |
|
| 188 | - * |
|
| 189 | - * @return boolean Return if canvas contains actions (old feature. now actions should be inside hooks) |
|
| 190 | - */ |
|
| 191 | - function hasActions() |
|
| 192 | - { |
|
| 186 | + /** |
|
| 187 | + * Return if a canvas contains an action controller |
|
| 188 | + * |
|
| 189 | + * @return boolean Return if canvas contains actions (old feature. now actions should be inside hooks) |
|
| 190 | + */ |
|
| 191 | + function hasActions() |
|
| 192 | + { |
|
| 193 | 193 | return (is_object($this->control)); |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Shared method for canvas to execute actions. |
|
| 196 | + /** |
|
| 197 | + * Shared method for canvas to execute actions. |
|
| 198 | 198 | * @deprecated Use the doActions of hooks instead of this. |
| 199 | - * This function is called if you add a doActions class inside your canvas. Try to not |
|
| 200 | - * do that and add action code into a hook instead. |
|
| 201 | - * |
|
| 202 | - * @param string $action Action string |
|
| 203 | - * @param int $id Object id |
|
| 204 | - * @return mixed Return return code of doActions of canvas |
|
| 205 | - * @see http://wiki.dolibarr.org/index.php/Canvas_development |
|
| 206 | - */ |
|
| 207 | - function doActions(&$action='view', $id=0) |
|
| 208 | - { |
|
| 209 | - if (method_exists($this->control,'doActions')) |
|
| 210 | - { |
|
| 211 | - $ret = $this->control->doActions($action, $id); |
|
| 212 | - return $ret; |
|
| 213 | - } |
|
| 214 | - } |
|
| 199 | + * This function is called if you add a doActions class inside your canvas. Try to not |
|
| 200 | + * do that and add action code into a hook instead. |
|
| 201 | + * |
|
| 202 | + * @param string $action Action string |
|
| 203 | + * @param int $id Object id |
|
| 204 | + * @return mixed Return return code of doActions of canvas |
|
| 205 | + * @see http://wiki.dolibarr.org/index.php/Canvas_development |
|
| 206 | + */ |
|
| 207 | + function doActions(&$action='view', $id=0) |
|
| 208 | + { |
|
| 209 | + if (method_exists($this->control,'doActions')) |
|
| 210 | + { |
|
| 211 | + $ret = $this->control->doActions($action, $id); |
|
| 212 | + return $ret; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | } |
@@ -27,55 +27,55 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class CoreObject extends CommonObject |
| 29 | 29 | { |
| 30 | - public $withChild = true; |
|
| 30 | + public $withChild = true; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var Array $_fields Fields to synchronize with Database |
|
| 34 | - */ |
|
| 35 | - protected $fields=array(); |
|
| 32 | + /** |
|
| 33 | + * @var Array $_fields Fields to synchronize with Database |
|
| 34 | + */ |
|
| 35 | + protected $fields=array(); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * Constructor |
|
| 39 | - * |
|
| 40 | - * @param DoliDB $db Database handler |
|
| 41 | - */ |
|
| 42 | - function __construct(DoliDB &$db) |
|
| 38 | + * Constructor |
|
| 39 | + * |
|
| 40 | + * @param DoliDB $db Database handler |
|
| 41 | + */ |
|
| 42 | + function __construct(DoliDB &$db) |
|
| 43 | 43 | { |
| 44 | 44 | $this->db = $db; |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Function to init fields |
| 49 | 49 | * |
| 50 | 50 | * @return bool |
| 51 | 51 | */ |
| 52 | - protected function init() |
|
| 52 | + protected function init() |
|
| 53 | 53 | { |
| 54 | - $this->id = 0; |
|
| 55 | - $this->datec = 0; |
|
| 56 | - $this->tms = 0; |
|
| 57 | - |
|
| 58 | - if (!empty($this->fields)) |
|
| 59 | - { |
|
| 60 | - foreach ($this->fields as $field=>$info) |
|
| 61 | - { |
|
| 62 | - if ($this->isDate($info)) $this->{$field} = time(); |
|
| 63 | - elseif ($this->isArray($info)) $this->{$field} = array(); |
|
| 64 | - elseif ($this->isInt($info)) $this->{$field} = (int) 0; |
|
| 65 | - elseif ($this->isFloat($info)) $this->{$field} = (double) 0; |
|
| 66 | - else $this->{$field} = ''; |
|
| 67 | - } |
|
| 54 | + $this->id = 0; |
|
| 55 | + $this->datec = 0; |
|
| 56 | + $this->tms = 0; |
|
| 57 | + |
|
| 58 | + if (!empty($this->fields)) |
|
| 59 | + { |
|
| 60 | + foreach ($this->fields as $field=>$info) |
|
| 61 | + { |
|
| 62 | + if ($this->isDate($info)) $this->{$field} = time(); |
|
| 63 | + elseif ($this->isArray($info)) $this->{$field} = array(); |
|
| 64 | + elseif ($this->isInt($info)) $this->{$field} = (int) 0; |
|
| 65 | + elseif ($this->isFloat($info)) $this->{$field} = (double) 0; |
|
| 66 | + else $this->{$field} = ''; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | $this->to_delete=false; |
| 70 | 70 | $this->is_clone=false; |
| 71 | 71 | |
| 72 | - return true; |
|
| 73 | - } |
|
| 74 | - else |
|
| 72 | + return true; |
|
| 73 | + } |
|
| 74 | + else |
|
| 75 | 75 | { |
| 76 | - return false; |
|
| 77 | - } |
|
| 78 | - } |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Test type of field |
@@ -86,15 +86,15 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private function checkFieldType($field, $type) |
| 88 | 88 | { |
| 89 | - if (isset($this->fields[$field]) && method_exists($this, 'is_'.$type)) |
|
| 90 | - { |
|
| 91 | - return $this->{'is_'.$type}($this->fields[$field]); |
|
| 92 | - } |
|
| 93 | - else |
|
| 89 | + if (isset($this->fields[$field]) && method_exists($this, 'is_'.$type)) |
|
| 90 | + { |
|
| 91 | + return $this->{'is_'.$type}($this->fields[$field]); |
|
| 92 | + } |
|
| 93 | + else |
|
| 94 | 94 | { |
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Get object and children from database |
@@ -103,15 +103,15 @@ discard block |
||
| 103 | 103 | * @param bool $loadChild used to load children from database |
| 104 | 104 | * @return int >0 if OK, <0 if KO, 0 if not found |
| 105 | 105 | */ |
| 106 | - public function fetch($id, $loadChild = true) |
|
| 106 | + public function fetch($id, $loadChild = true) |
|
| 107 | 107 | { |
| 108 | - $res = $this->fetchCommon($id); |
|
| 109 | - if($res>0) { |
|
| 110 | - if ($loadChild) $this->fetchChild(); |
|
| 111 | - } |
|
| 108 | + $res = $this->fetchCommon($id); |
|
| 109 | + if($res>0) { |
|
| 110 | + if ($loadChild) $this->fetchChild(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $res; |
|
| 114 | - } |
|
| 113 | + return $res; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -125,25 +125,25 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function addChild($tabName, $id=0, $key='id', $try_to_load = false) |
| 127 | 127 | { |
| 128 | - if(!empty($id)) |
|
| 129 | - { |
|
| 130 | - foreach($this->{$tabName} as $k=>&$object) |
|
| 131 | - { |
|
| 132 | - if($object->{$key} === $id) return $k; |
|
| 133 | - } |
|
| 134 | - } |
|
| 128 | + if(!empty($id)) |
|
| 129 | + { |
|
| 130 | + foreach($this->{$tabName} as $k=>&$object) |
|
| 131 | + { |
|
| 132 | + if($object->{$key} === $id) return $k; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - $k = count($this->{$tabName}); |
|
| 136 | + $k = count($this->{$tabName}); |
|
| 137 | 137 | |
| 138 | - $className = ucfirst($tabName); |
|
| 139 | - $this->{$tabName}[$k] = new $className($this->db); |
|
| 140 | - if($id>0 && $key==='id' && $try_to_load) |
|
| 141 | - { |
|
| 142 | - $this->{$tabName}[$k]->fetch($id); |
|
| 143 | - } |
|
| 138 | + $className = ucfirst($tabName); |
|
| 139 | + $this->{$tabName}[$k] = new $className($this->db); |
|
| 140 | + if($id>0 && $key==='id' && $try_to_load) |
|
| 141 | + { |
|
| 142 | + $this->{$tabName}[$k]->fetch($id); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return $k; |
|
| 146 | - } |
|
| 145 | + return $k; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function removeChild($tabName, $id, $key='id') |
| 158 | 158 | { |
| 159 | - foreach ($this->{$tabName} as &$object) |
|
| 160 | - { |
|
| 161 | - if ($object->{$key} == $id) |
|
| 162 | - { |
|
| 163 | - $object->to_delete = true; |
|
| 164 | - return true; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 159 | + foreach ($this->{$tabName} as &$object) |
|
| 160 | + { |
|
| 161 | + if ($object->{$key} == $id) |
|
| 162 | + { |
|
| 163 | + $object->to_delete = true; |
|
| 164 | + return true; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function fetchChild() |
| 177 | 177 | { |
| 178 | - if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 179 | - { |
|
| 180 | - foreach($this->childtables as &$childTable) |
|
| 181 | - { |
|
| 178 | + if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 179 | + { |
|
| 180 | + foreach($this->childtables as &$childTable) |
|
| 181 | + { |
|
| 182 | 182 | $className = ucfirst($childTable); |
| 183 | 183 | |
| 184 | 184 | $this->{$className}=array(); |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $this->errors[] = $this->db->lasterror(); |
| 202 | 202 | } |
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Function to update children data |
@@ -210,26 +210,26 @@ discard block |
||
| 210 | 210 | * @param User $user user object |
| 211 | 211 | * @return void |
| 212 | 212 | */ |
| 213 | - public function saveChild(User &$user) |
|
| 213 | + public function saveChild(User &$user) |
|
| 214 | 214 | { |
| 215 | - if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 216 | - { |
|
| 217 | - foreach($this->childtables as &$childTable) |
|
| 218 | - { |
|
| 219 | - $className = ucfirst($childTable); |
|
| 220 | - if(!empty($this->{$className})) |
|
| 221 | - { |
|
| 222 | - foreach($this->{$className} as $i => &$object) |
|
| 223 | - { |
|
| 224 | - $object->{$this->fk_element} = $this->id; |
|
| 225 | - |
|
| 226 | - $object->update($user); |
|
| 227 | - if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - } |
|
| 215 | + if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) |
|
| 216 | + { |
|
| 217 | + foreach($this->childtables as &$childTable) |
|
| 218 | + { |
|
| 219 | + $className = ucfirst($childTable); |
|
| 220 | + if(!empty($this->{$className})) |
|
| 221 | + { |
|
| 222 | + foreach($this->{$className} as $i => &$object) |
|
| 223 | + { |
|
| 224 | + $object->{$this->fk_element} = $this->id; |
|
| 225 | + |
|
| 226 | + $object->update($user); |
|
| 227 | + if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function update(User &$user) |
| 242 | 242 | { |
| 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 |
|
| 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 | 244 | elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user); |
| 245 | 245 | |
| 246 | 246 | $error = 0; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $this->db->rollback(); |
| 271 | 271 | return -1; |
| 272 | 272 | } |
| 273 | - } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | 276 | * Function to create object in database |
@@ -280,26 +280,26 @@ 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) |
|
| 290 | - { |
|
| 291 | - $this->id = $this->db->last_insert_id($this->table_element); |
|
| 289 | + if($res) |
|
| 290 | + { |
|
| 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 | - } |
|
| 297 | - else |
|
| 296 | + } |
|
| 297 | + else |
|
| 298 | 298 | { |
| 299 | 299 | $error++; |
| 300 | 300 | $this->error = $this->db->lasterror(); |
| 301 | 301 | $this->errors[] = $this->error; |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | if (empty($error)) |
| 305 | 305 | { |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | $this->db->rollback(); |
| 312 | 312 | return -1; |
| 313 | 313 | } |
| 314 | - } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | 317 | * Function to delete object in database |
@@ -319,9 +319,9 @@ discard block |
||
| 319 | 319 | * @param User $user user object |
| 320 | 320 | * @return < 0 if ko, > 0 if ok |
| 321 | 321 | */ |
| 322 | - public function delete(User &$user) |
|
| 322 | + public function delete(User &$user) |
|
| 323 | 323 | { |
| 324 | - if ($this->id <= 0) return 0; |
|
| 324 | + if ($this->id <= 0) return 0; |
|
| 325 | 325 | |
| 326 | 326 | $error = 0; |
| 327 | 327 | $this->db->begin(); |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | $this->db->rollback(); |
| 361 | 361 | return -1; |
| 362 | 362 | } |
| 363 | - } |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function getDate($field, $format='') |
| 374 | 374 | { |
| 375 | - if(empty($this->{$field})) return ''; |
|
| 376 | - else |
|
| 375 | + if(empty($this->{$field})) return ''; |
|
| 376 | + else |
|
| 377 | 377 | { |
| 378 | - return dol_print_date($this->{$field}, $format); |
|
| 379 | - } |
|
| 380 | - } |
|
| 378 | + return dol_print_date($this->{$field}, $format); |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * Function to set date in field |
@@ -388,18 +388,18 @@ discard block |
||
| 388 | 388 | */ |
| 389 | 389 | public function setDate($field, $date) |
| 390 | 390 | { |
| 391 | - if (empty($date)) |
|
| 392 | - { |
|
| 393 | - $this->{$field} = 0; |
|
| 394 | - } |
|
| 395 | - else |
|
| 391 | + if (empty($date)) |
|
| 392 | + { |
|
| 393 | + $this->{$field} = 0; |
|
| 394 | + } |
|
| 395 | + else |
|
| 396 | 396 | { |
| 397 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
| 398 | - $this->{$field} = dol_stringtotime($date); |
|
| 399 | - } |
|
| 397 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
| 398 | + $this->{$field} = dol_stringtotime($date); |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - return $this->{$field}; |
|
| 402 | - } |
|
| 401 | + return $this->{$field}; |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -410,29 +410,29 @@ discard block |
||
| 410 | 410 | */ |
| 411 | 411 | public function setValues(&$Tab) |
| 412 | 412 | { |
| 413 | - foreach ($Tab as $key => $value) |
|
| 414 | - { |
|
| 415 | - if($this->checkFieldType($key, 'date')) |
|
| 416 | - { |
|
| 417 | - $this->setDate($key, $value); |
|
| 418 | - } |
|
| 419 | - else if( $this->checkFieldType($key, 'array')) |
|
| 420 | - { |
|
| 421 | - $this->{$key} = $value; |
|
| 422 | - } |
|
| 423 | - else if( $this->checkFieldType($key, 'float') ) |
|
| 424 | - { |
|
| 425 | - $this->{$key} = (double) price2num($value); |
|
| 426 | - } |
|
| 427 | - else if( $this->checkFieldType($key, 'int') ) { |
|
| 428 | - $this->{$key} = (int) price2num($value); |
|
| 429 | - } |
|
| 430 | - else |
|
| 413 | + foreach ($Tab as $key => $value) |
|
| 414 | + { |
|
| 415 | + if($this->checkFieldType($key, 'date')) |
|
| 416 | + { |
|
| 417 | + $this->setDate($key, $value); |
|
| 418 | + } |
|
| 419 | + else if( $this->checkFieldType($key, 'array')) |
|
| 431 | 420 | { |
| 432 | - $this->{$key} = $value; |
|
| 433 | - } |
|
| 434 | - } |
|
| 421 | + $this->{$key} = $value; |
|
| 422 | + } |
|
| 423 | + else if( $this->checkFieldType($key, 'float') ) |
|
| 424 | + { |
|
| 425 | + $this->{$key} = (double) price2num($value); |
|
| 426 | + } |
|
| 427 | + else if( $this->checkFieldType($key, 'int') ) { |
|
| 428 | + $this->{$key} = (int) price2num($value); |
|
| 429 | + } |
|
| 430 | + else |
|
| 431 | + { |
|
| 432 | + $this->{$key} = $value; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - return 1; |
|
| 437 | - } |
|
| 436 | + return 1; |
|
| 437 | + } |
|
| 438 | 438 | } |
@@ -32,44 +32,44 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class Cstate // extends CommonObject |
| 34 | 34 | { |
| 35 | - /** |
|
| 35 | + /** |
|
| 36 | 36 | * @var DoliDB Database handler. |
| 37 | 37 | */ |
| 38 | 38 | public $db; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string Error code (or message) |
|
| 42 | - */ |
|
| 43 | - public $error=''; |
|
| 40 | + /** |
|
| 41 | + * @var string Error code (or message) |
|
| 42 | + */ |
|
| 43 | + public $error=''; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[] Error codes (or messages) |
|
| 47 | - */ |
|
| 48 | - public $errors = array(); |
|
| 45 | + /** |
|
| 46 | + * @var string[] Error codes (or messages) |
|
| 47 | + */ |
|
| 48 | + public $errors = array(); |
|
| 49 | 49 | |
| 50 | - //var $element='cstate'; //!< Id that identify managed objects |
|
| 51 | - //var $table_element='cstate'; //!< Name of table without prefix where object is stored |
|
| 50 | + //var $element='cstate'; //!< Id that identify managed objects |
|
| 51 | + //var $table_element='cstate'; //!< Name of table without prefix where object is stored |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | - * @var int ID |
|
| 55 | - */ |
|
| 56 | - public $id; |
|
| 54 | + * @var int ID |
|
| 55 | + */ |
|
| 56 | + public $id; |
|
| 57 | 57 | |
| 58 | - public $code_departement; |
|
| 58 | + public $code_departement; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var string |
|
| 62 | - * @deprecated |
|
| 63 | - * @see name |
|
| 64 | - */ |
|
| 65 | - public $nom=''; |
|
| 60 | + /** |
|
| 61 | + * @var string |
|
| 62 | + * @deprecated |
|
| 63 | + * @see name |
|
| 64 | + */ |
|
| 65 | + public $nom=''; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @var string name |
|
| 69 | - */ |
|
| 70 | - public $name=''; |
|
| 67 | + /** |
|
| 68 | + * @var string name |
|
| 69 | + */ |
|
| 70 | + public $name=''; |
|
| 71 | 71 | |
| 72 | - public $active; |
|
| 72 | + public $active; |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | |
@@ -94,70 +94,70 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | function create($user, $notrigger=0) |
| 96 | 96 | { |
| 97 | - global $conf, $langs; |
|
| 98 | - $error=0; |
|
| 97 | + global $conf, $langs; |
|
| 98 | + $error=0; |
|
| 99 | 99 | |
| 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); |
|
| 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); |
|
| 104 | 104 | |
| 105 | - // Check parameters |
|
| 106 | - // Put here code to add control on parameters values |
|
| 105 | + // Check parameters |
|
| 106 | + // Put here code to add control on parameters values |
|
| 107 | 107 | |
| 108 | 108 | // Insert request |
| 109 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements("; |
|
| 110 | - $sql.= "rowid,"; |
|
| 111 | - $sql.= "code_departement,"; |
|
| 112 | - $sql.= "nom,"; |
|
| 113 | - $sql.= "active"; |
|
| 109 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements("; |
|
| 110 | + $sql.= "rowid,"; |
|
| 111 | + $sql.= "code_departement,"; |
|
| 112 | + $sql.= "nom,"; |
|
| 113 | + $sql.= "active"; |
|
| 114 | 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.= ")"; |
|
| 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 | - $this->db->begin(); |
|
| 121 | + $this->db->begin(); |
|
| 122 | 122 | |
| 123 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 123 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 124 | 124 | $resql=$this->db->query($sql); |
| 125 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 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) |
|
| 132 | - { |
|
| 133 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 134 | - // want this action call a trigger. |
|
| 135 | - |
|
| 136 | - //// Call triggers |
|
| 137 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 138 | - //$interface=new Interfaces($this->db); |
|
| 139 | - //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
| 140 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 141 | - //// End call triggers |
|
| 142 | - } |
|
| 131 | + if (! $notrigger) |
|
| 132 | + { |
|
| 133 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 134 | + // want this action call a trigger. |
|
| 135 | + |
|
| 136 | + //// Call triggers |
|
| 137 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 138 | + //$interface=new Interfaces($this->db); |
|
| 139 | + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
| 140 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 141 | + //// End call triggers |
|
| 142 | + } |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // Commit or rollback |
| 146 | 146 | if ($error) |
| 147 | - { |
|
| 148 | - foreach($this->errors as $errmsg) |
|
| 149 | - { |
|
| 150 | - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 151 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 152 | - } |
|
| 153 | - $this->db->rollback(); |
|
| 154 | - return -1*$error; |
|
| 155 | - } |
|
| 156 | - else |
|
| 157 | - { |
|
| 158 | - $this->db->commit(); |
|
| 147 | + { |
|
| 148 | + foreach($this->errors as $errmsg) |
|
| 149 | + { |
|
| 150 | + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 151 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 152 | + } |
|
| 153 | + $this->db->rollback(); |
|
| 154 | + return -1*$error; |
|
| 155 | + } |
|
| 156 | + else |
|
| 157 | + { |
|
| 158 | + $this->db->commit(); |
|
| 159 | 159 | return $this->id; |
| 160 | - } |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -170,17 +170,17 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function fetch($id,$code='') |
| 172 | 172 | { |
| 173 | - global $langs; |
|
| 173 | + global $langs; |
|
| 174 | 174 | $sql = "SELECT"; |
| 175 | - $sql.= " t.rowid,"; |
|
| 176 | - $sql.= " t.code_departement,"; |
|
| 177 | - $sql.= " t.nom,"; |
|
| 178 | - $sql.= " t.active"; |
|
| 175 | + $sql.= " t.rowid,"; |
|
| 176 | + $sql.= " t.code_departement,"; |
|
| 177 | + $sql.= " t.nom,"; |
|
| 178 | + $sql.= " t.active"; |
|
| 179 | 179 | $sql.= " FROM ".MAIN_DB_PREFIX."c_departements as t"; |
| 180 | 180 | if ($id) $sql.= " WHERE t.rowid = ".$id; |
| 181 | 181 | elseif ($code) $sql.= " WHERE t.code_departement = '".$this->db->escape($code)."'"; |
| 182 | 182 | |
| 183 | - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 183 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 184 | 184 | $resql=$this->db->query($sql); |
| 185 | 185 | if ($resql) |
| 186 | 186 | { |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | $obj = $this->db->fetch_object($resql); |
| 190 | 190 | |
| 191 | 191 | $this->id = $obj->rowid; |
| 192 | - $this->code_departement = $obj->code_departement; |
|
| 193 | - $this->nom = $obj->nom; |
|
| 194 | - $this->active = $obj->active; |
|
| 192 | + $this->code_departement = $obj->code_departement; |
|
| 193 | + $this->nom = $obj->nom; |
|
| 194 | + $this->active = $obj->active; |
|
| 195 | 195 | } |
| 196 | 196 | $this->db->free($resql); |
| 197 | 197 | |
@@ -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 | } |
@@ -214,118 +214,118 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | function update($user=null, $notrigger=0) |
| 216 | 216 | { |
| 217 | - global $conf, $langs; |
|
| 218 | - $error=0; |
|
| 217 | + global $conf, $langs; |
|
| 218 | + $error=0; |
|
| 219 | 219 | |
| 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); |
|
| 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); |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | - // Check parameters |
|
| 227 | - // Put here code to add control on parameters values |
|
| 226 | + // Check parameters |
|
| 227 | + // Put here code to add control on parameters values |
|
| 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").""; |
|
| 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 | 234 | $sql.= " WHERE rowid=".$this->id; |
| 235 | 235 | |
| 236 | - $this->db->begin(); |
|
| 236 | + $this->db->begin(); |
|
| 237 | 237 | |
| 238 | - dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 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(); } |
|
| 241 | - |
|
| 242 | - if (! $error) |
|
| 243 | - { |
|
| 244 | - if (! $notrigger) |
|
| 245 | - { |
|
| 246 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 247 | - // want this action call a trigger. |
|
| 248 | - |
|
| 249 | - //// Call triggers |
|
| 250 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 251 | - //$interface=new Interfaces($this->db); |
|
| 252 | - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
| 253 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 254 | - //// End call triggers |
|
| 255 | - } |
|
| 256 | - } |
|
| 240 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 241 | + |
|
| 242 | + if (! $error) |
|
| 243 | + { |
|
| 244 | + if (! $notrigger) |
|
| 245 | + { |
|
| 246 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 247 | + // want this action call a trigger. |
|
| 248 | + |
|
| 249 | + //// Call triggers |
|
| 250 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 251 | + //$interface=new Interfaces($this->db); |
|
| 252 | + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
| 253 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 254 | + //// End call triggers |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | // Commit or rollback |
| 259 | - if ($error) |
|
| 260 | - { |
|
| 261 | - foreach($this->errors as $errmsg) |
|
| 262 | - { |
|
| 263 | - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 264 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 265 | - } |
|
| 266 | - $this->db->rollback(); |
|
| 267 | - return -1*$error; |
|
| 268 | - } |
|
| 269 | - else |
|
| 270 | - { |
|
| 271 | - $this->db->commit(); |
|
| 272 | - return 1; |
|
| 273 | - } |
|
| 259 | + if ($error) |
|
| 260 | + { |
|
| 261 | + foreach($this->errors as $errmsg) |
|
| 262 | + { |
|
| 263 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 264 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 265 | + } |
|
| 266 | + $this->db->rollback(); |
|
| 267 | + return -1*$error; |
|
| 268 | + } |
|
| 269 | + else |
|
| 270 | + { |
|
| 271 | + $this->db->commit(); |
|
| 272 | + return 1; |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Delete object in database |
|
| 279 | - * |
|
| 280 | - * @param User $user User that delete |
|
| 281 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 282 | - * @return int <0 if KO, >0 if OK |
|
| 283 | - */ |
|
| 284 | - function delete($user, $notrigger=0) |
|
| 285 | - { |
|
| 286 | - global $conf, $langs; |
|
| 287 | - $error=0; |
|
| 288 | - |
|
| 289 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements"; |
|
| 290 | - $sql.= " WHERE rowid=".$this->id; |
|
| 291 | - |
|
| 292 | - $this->db->begin(); |
|
| 293 | - |
|
| 294 | - dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 295 | - $resql = $this->db->query($sql); |
|
| 296 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 297 | - |
|
| 298 | - if (! $error) |
|
| 299 | - { |
|
| 300 | - if (! $notrigger) |
|
| 301 | - { |
|
| 302 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 303 | - // want this action call a trigger. |
|
| 304 | - |
|
| 305 | - //// Call triggers |
|
| 306 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 307 | - //$interface=new Interfaces($this->db); |
|
| 308 | - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
| 309 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 310 | - //// End call triggers |
|
| 311 | - } |
|
| 312 | - } |
|
| 277 | + /** |
|
| 278 | + * Delete object in database |
|
| 279 | + * |
|
| 280 | + * @param User $user User that delete |
|
| 281 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 282 | + * @return int <0 if KO, >0 if OK |
|
| 283 | + */ |
|
| 284 | + function delete($user, $notrigger=0) |
|
| 285 | + { |
|
| 286 | + global $conf, $langs; |
|
| 287 | + $error=0; |
|
| 288 | + |
|
| 289 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements"; |
|
| 290 | + $sql.= " WHERE rowid=".$this->id; |
|
| 291 | + |
|
| 292 | + $this->db->begin(); |
|
| 293 | + |
|
| 294 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 295 | + $resql = $this->db->query($sql); |
|
| 296 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 297 | + |
|
| 298 | + if (! $error) |
|
| 299 | + { |
|
| 300 | + if (! $notrigger) |
|
| 301 | + { |
|
| 302 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 303 | + // want this action call a trigger. |
|
| 304 | + |
|
| 305 | + //// Call triggers |
|
| 306 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 307 | + //$interface=new Interfaces($this->db); |
|
| 308 | + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
| 309 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 310 | + //// End call triggers |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | // Commit or rollback |
| 315 | - if ($error) |
|
| 316 | - { |
|
| 317 | - foreach($this->errors as $errmsg) |
|
| 318 | - { |
|
| 319 | - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 320 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 321 | - } |
|
| 322 | - $this->db->rollback(); |
|
| 323 | - return -1*$error; |
|
| 324 | - } |
|
| 325 | - else |
|
| 326 | - { |
|
| 327 | - $this->db->commit(); |
|
| 328 | - return 1; |
|
| 329 | - } |
|
| 330 | - } |
|
| 315 | + if ($error) |
|
| 316 | + { |
|
| 317 | + foreach($this->errors as $errmsg) |
|
| 318 | + { |
|
| 319 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 320 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 321 | + } |
|
| 322 | + $this->db->rollback(); |
|
| 323 | + return -1*$error; |
|
| 324 | + } |
|
| 325 | + else |
|
| 326 | + { |
|
| 327 | + $this->db->commit(); |
|
| 328 | + return 1; |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | 331 | } |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | class Link extends CommonObject |
| 30 | 30 | { |
| 31 | 31 | /** |
| 32 | - * @var string ID to identify managed object |
|
| 33 | - */ |
|
| 34 | - public $element = 'link'; |
|
| 32 | + * @var string ID to identify managed object |
|
| 33 | + */ |
|
| 34 | + public $element = 'link'; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * @var string Name of table without prefix where object is stored |
|
| 38 | - */ |
|
| 39 | - public $table_element = 'links'; |
|
| 37 | + * @var string Name of table without prefix where object is stored |
|
| 38 | + */ |
|
| 39 | + public $table_element = 'links'; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * @var int Entity |
|
| 43 | - */ |
|
| 44 | - public $entity; |
|
| 42 | + * @var int Entity |
|
| 43 | + */ |
|
| 44 | + public $entity; |
|
| 45 | 45 | |
| 46 | 46 | public $datea; |
| 47 | 47 | public $url; |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | return 1; |
| 344 | 344 | } |
| 345 | 345 | else |
| 346 | - { |
|
| 346 | + { |
|
| 347 | 347 | return 0; |
| 348 | 348 | } |
| 349 | 349 | } else { |
@@ -27,857 +27,857 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | class Utils |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | + /** |
|
| 31 | 31 | * @var DoliDB Database handler. |
| 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 |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Constructor |
|
| 40 | - * |
|
| 41 | - * @param DoliDB $db Database handler |
|
| 42 | - */ |
|
| 43 | - function __construct($db) |
|
| 44 | - { |
|
| 45 | - $this->db = $db; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Purge files into directory of data files. |
|
| 51 | - * CAN BE A CRON TASK |
|
| 52 | - * |
|
| 53 | - * @param string $choice Choice of purge mode ('tempfiles', '' or 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfile') |
|
| 54 | - * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) |
|
| 55 | - */ |
|
| 56 | - function purgeFiles($choice='tempfilesold') |
|
| 57 | - { |
|
| 58 | - global $conf, $langs, $dolibarr_main_data_root; |
|
| 59 | - |
|
| 60 | - $langs->load("admin"); |
|
| 61 | - |
|
| 62 | - dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG); |
|
| 63 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 64 | - |
|
| 65 | - $filesarray=array(); |
|
| 66 | - if (empty($choice)) $choice='tempfilesold'; |
|
| 67 | - |
|
| 68 | - if ($choice=='tempfiles' || $choice=='tempfilesold') |
|
| 69 | - { |
|
| 70 | - // Delete temporary files |
|
| 71 | - if ($dolibarr_main_data_root) |
|
| 72 | - { |
|
| 73 | - $filesarray=dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks |
|
| 74 | - if ($choice == 'tempfilesold') |
|
| 75 | - { |
|
| 76 | - $now = dol_now(); |
|
| 77 | - foreach($filesarray as $key => $val) |
|
| 78 | - { |
|
| 79 | - if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ($choice=='allfiles') |
|
| 86 | - { |
|
| 87 | - // Delete all files (except install.lock, do not follow symbolic links) |
|
| 88 | - if ($dolibarr_main_data_root) |
|
| 89 | - { |
|
| 90 | - $filesarray=dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ($choice=='logfile') |
|
| 95 | - { |
|
| 96 | - // Define files log |
|
| 97 | - if ($dolibarr_main_data_root) |
|
| 98 | - { |
|
| 99 | - $filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $filelog=''; |
|
| 103 | - if (! empty($conf->syslog->enabled)) |
|
| 104 | - { |
|
| 105 | - $filelog=$conf->global->SYSLOG_FILE; |
|
| 106 | - $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog); |
|
| 107 | - |
|
| 108 | - $alreadyincluded=false; |
|
| 109 | - foreach ($filesarray as $tmpcursor) |
|
| 110 | - { |
|
| 111 | - if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; } |
|
| 112 | - } |
|
| 113 | - if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file'); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $count=0; |
|
| 118 | - $countdeleted=0; |
|
| 119 | - $counterror=0; |
|
| 120 | - if (count($filesarray)) |
|
| 121 | - { |
|
| 122 | - foreach($filesarray as $key => $value) |
|
| 123 | - { |
|
| 124 | - //print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."<br>\n"; |
|
| 125 | - if ($filesarray[$key]['type'] == 'dir') |
|
| 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; |
|
| 132 | - } |
|
| 133 | - elseif ($filesarray[$key]['type'] == 'file') |
|
| 134 | - { |
|
| 135 | - // If (file that is not logfile) or (if mode is logfile) |
|
| 136 | - if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile') |
|
| 137 | - { |
|
| 138 | - $result=dol_delete_file($filesarray[$key]['fullname'], 1, 1); |
|
| 139 | - if ($result) |
|
| 140 | - { |
|
| 141 | - $count++; |
|
| 142 | - $countdeleted++; |
|
| 143 | - } |
|
| 144 | - else |
|
| 145 | - { |
|
| 146 | - $counterror++; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Update cachenbofdoc |
|
| 153 | - if (! empty($conf->ecm->enabled) && $choice=='allfiles') |
|
| 154 | - { |
|
| 155 | - require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; |
|
| 156 | - $ecmdirstatic = new EcmDirectory($this->db); |
|
| 157 | - $result = $ecmdirstatic->refreshcachenboffile(1); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ($count > 0) |
|
| 162 | - { |
|
| 163 | - $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted); |
|
| 164 | - if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); |
|
| 165 | - } |
|
| 166 | - else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':''); |
|
| 167 | - |
|
| 168 | - //return $count; |
|
| 169 | - return 0; // This function can be called by cron so must return 0 if OK |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Make a backup of database |
|
| 175 | - * CAN BE A CRON TASK |
|
| 176 | - * |
|
| 177 | - * @param string $compression 'gz' or 'bz' or 'none' |
|
| 178 | - * @param string $type 'mysql', 'postgresql', ... |
|
| 179 | - * @param int $usedefault 1=Use default backup profile (Set this to 1 when used as cron) |
|
| 180 | - * @param string $file 'auto' or filename to build |
|
| 181 | - * @param int $keeplastnfiles Keep only last n files (not used yet) |
|
| 182 | - * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method |
|
| 183 | - * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) |
|
| 184 | - */ |
|
| 185 | - function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0, $execmethod=0) |
|
| 186 | - { |
|
| 187 | - global $db, $conf, $langs, $dolibarr_main_data_root; |
|
| 188 | - global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass; |
|
| 189 | - |
|
| 190 | - $langs->load("admin"); |
|
| 191 | - |
|
| 192 | - dol_syslog("Utils::dumpDatabase type=".$type." compression=".$compression." file=".$file, LOG_DEBUG); |
|
| 193 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 194 | - |
|
| 195 | - // Check compression parameter |
|
| 196 | - if (! in_array($compression, array('none', 'gz', 'bz', 'zip'))) |
|
| 197 | - { |
|
| 198 | - $langs->load("errors"); |
|
| 199 | - $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression"); |
|
| 200 | - return -1; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // Check type parameter |
|
| 204 | - if ($type == 'auto') $type = $db->type; |
|
| 205 | - if (! in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin'))) |
|
| 206 | - { |
|
| 207 | - $langs->load("errors"); |
|
| 208 | - $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype"); |
|
| 209 | - return -1; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // Check file parameter |
|
| 213 | - if ($file == 'auto') |
|
| 214 | - { |
|
| 215 | - $prefix='dump'; |
|
| 216 | - $ext='sql'; |
|
| 217 | - if (in_array($type, array('mysql', 'mysqli'))) { $prefix='mysqldump'; $ext='sql'; } |
|
| 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; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $outputdir = $conf->admin->dir_output.'/backup'; |
|
| 224 | - $result=dol_mkdir($outputdir); |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - // MYSQL |
|
| 228 | - if ($type == 'mysql' || $type == 'mysqli') |
|
| 229 | - { |
|
| 230 | - $cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP; |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - $outputfile = $outputdir.'/'.$file; |
|
| 234 | - // for compression format, we add extension |
|
| 235 | - $compression=$compression ? $compression : 'none'; |
|
| 236 | - if ($compression == 'gz') $outputfile.='.gz'; |
|
| 237 | - if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 238 | - $outputerror = $outputfile.'.err'; |
|
| 239 | - dol_mkdir($conf->admin->dir_output.'/backup'); |
|
| 240 | - |
|
| 241 | - // Parameteres execution |
|
| 242 | - $command=$cmddump; |
|
| 243 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command |
|
| 244 | - |
|
| 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"; |
|
| 253 | - if (GETPOST("sql_structure") || $usedefault) |
|
| 254 | - { |
|
| 255 | - if (GETPOST("drop") || $usedefault) $param.=" --add-drop-table=TRUE"; |
|
| 256 | - else $param.=" --add-drop-table=FALSE"; |
|
| 257 | - } |
|
| 258 | - else |
|
| 259 | - { |
|
| 260 | - $param.=" -t"; |
|
| 261 | - } |
|
| 262 | - if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE"; |
|
| 263 | - if (GETPOST("sql_data") || $usedefault) |
|
| 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"; |
|
| 272 | - } |
|
| 273 | - else |
|
| 274 | - { |
|
| 275 | - $param.=" -d"; // No row information (no data) |
|
| 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)) |
|
| 281 | - { |
|
| 282 | - $paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"'; |
|
| 283 | - $paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"'; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $errormsg=''; |
|
| 287 | - $handle = ''; |
|
| 288 | - |
|
| 289 | - // Start call method to execute dump |
|
| 290 | - $fullcommandcrypted=$command." ".$paramcrypted." 2>&1"; |
|
| 291 | - $fullcommandclear=$command." ".$paramclear." 2>&1"; |
|
| 292 | - if ($compression == 'none') $handle = fopen($outputfile, 'w'); |
|
| 293 | - if ($compression == 'gz') $handle = gzopen($outputfile, 'w'); |
|
| 294 | - if ($compression == 'bz') $handle = bzopen($outputfile, 'w'); |
|
| 295 | - |
|
| 296 | - if ($handle) |
|
| 297 | - { |
|
| 298 | - if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; |
|
| 299 | - if (empty($execmethod)) $execmethod=1; |
|
| 300 | - |
|
| 301 | - $ok=0; |
|
| 302 | - dol_syslog("Utils::dumpDatabase execmethod=".$execmethod." command:".$fullcommandcrypted, LOG_DEBUG); |
|
| 303 | - |
|
| 304 | - // TODO Replace with executeCLI function |
|
| 305 | - if ($execmethod == 1) |
|
| 306 | - { |
|
| 307 | - exec($fullcommandclear, $readt, $retval); |
|
| 308 | - $result = $retval; |
|
| 309 | - |
|
| 310 | - if ($retval != 0) |
|
| 311 | - { |
|
| 312 | - $langs->load("errors"); |
|
| 313 | - dol_syslog("Datadump retval after exec=".$retval, LOG_ERR); |
|
| 314 | - $error = 'Error '.$retval; |
|
| 315 | - $ok=0; |
|
| 316 | - } |
|
| 317 | - else |
|
| 318 | - { |
|
| 319 | - $i=0; |
|
| 320 | - if (!empty($readt)) |
|
| 321 | - foreach($readt as $key=>$read) |
|
| 322 | - { |
|
| 323 | - $i++; // output line number |
|
| 324 | - if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue; |
|
| 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; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - if ($execmethod == 2) // With this method, there is no way to get the return code, only output |
|
| 332 | - { |
|
| 333 | - $handlein = popen($fullcommandclear, 'r'); |
|
| 334 | - $i=0; |
|
| 335 | - while (!feof($handlein)) |
|
| 336 | - { |
|
| 337 | - $i++; // output line number |
|
| 338 | - $read = fgets($handlein); |
|
| 339 | - // Exclude warning line we don't want |
|
| 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; |
|
| 344 | - } |
|
| 345 | - pclose($handlein); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - if ($compression == 'none') fclose($handle); |
|
| 350 | - if ($compression == 'gz') gzclose($handle); |
|
| 351 | - if ($compression == 'bz') bzclose($handle); |
|
| 352 | - |
|
| 353 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 354 | - @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 355 | - } |
|
| 356 | - else |
|
| 357 | - { |
|
| 358 | - $langs->load("errors"); |
|
| 359 | - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 360 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Get errorstring |
|
| 364 | - if ($compression == 'none') $handle = fopen($outputfile, 'r'); |
|
| 365 | - if ($compression == 'gz') $handle = gzopen($outputfile, 'r'); |
|
| 366 | - if ($compression == 'bz') $handle = bzopen($outputfile, 'r'); |
|
| 367 | - if ($handle) |
|
| 368 | - { |
|
| 369 | - // Get 2048 first chars of error message. |
|
| 370 | - $errormsg = fgets($handle,2048); |
|
| 371 | - // Close file |
|
| 372 | - if ($compression == 'none') fclose($handle); |
|
| 373 | - if ($compression == 'gz') gzclose($handle); |
|
| 374 | - if ($compression == 'bz') bzclose($handle); |
|
| 375 | - if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg=''; // Pas erreur |
|
| 376 | - else |
|
| 377 | - { |
|
| 378 | - // Renommer fichier sortie en fichier erreur |
|
| 379 | - //print "$outputfile -> $outputerror"; |
|
| 380 | - @dol_delete_file($outputerror, 1, 0, 0, null, false, 0); |
|
| 381 | - @rename($outputfile,$outputerror); |
|
| 382 | - // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide |
|
| 383 | - if (! $errormsg) |
|
| 384 | - { |
|
| 385 | - $langs->load("errors"); |
|
| 386 | - $errormsg=$langs->trans("ErrorFailedToRunExternalCommand"); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - // Fin execution commande |
|
| 391 | - |
|
| 392 | - $this->output = $errormsg; |
|
| 393 | - $this->error = $errormsg; |
|
| 394 | - $this->result = array("commandbackuplastdone" => $command." ".$paramcrypted, "commandbackuptorun" => ""); |
|
| 395 | - //if (empty($this->output)) $this->output=$this->result['commandbackuplastdone']; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - // MYSQL NO BIN |
|
| 399 | - if ($type == 'mysqlnobin') |
|
| 400 | - { |
|
| 401 | - $outputfile = $outputdir.'/'.$file; |
|
| 402 | - $outputfiletemp = $outputfile.'-TMP.sql'; |
|
| 403 | - // for compression format, we add extension |
|
| 404 | - $compression=$compression ? $compression : 'none'; |
|
| 405 | - if ($compression == 'gz') $outputfile.='.gz'; |
|
| 406 | - if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 407 | - $outputerror = $outputfile.'.err'; |
|
| 408 | - dol_mkdir($conf->admin->dir_output.'/backup'); |
|
| 409 | - |
|
| 410 | - if ($compression == 'gz' or $compression == 'bz') |
|
| 411 | - { |
|
| 412 | - $this->backupTables($outputfiletemp); |
|
| 413 | - dol_compress_file($outputfiletemp, $outputfile, $compression); |
|
| 414 | - unlink($outputfiletemp); |
|
| 415 | - } |
|
| 416 | - else |
|
| 417 | - { |
|
| 418 | - $this->backupTables($outputfile); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $this->output = ""; |
|
| 422 | - $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => ""); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - // POSTGRESQL |
|
| 426 | - if ($type == 'postgresql' || $type == 'pgsql') |
|
| 427 | - { |
|
| 428 | - $cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP; |
|
| 429 | - |
|
| 430 | - $outputfile = $outputdir.'/'.$file; |
|
| 431 | - // for compression format, we add extension |
|
| 432 | - $compression=$compression ? $compression : 'none'; |
|
| 433 | - if ($compression == 'gz') $outputfile.='.gz'; |
|
| 434 | - if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 435 | - $outputerror = $outputfile.'.err'; |
|
| 436 | - dol_mkdir($conf->admin->dir_output.'/backup'); |
|
| 437 | - |
|
| 438 | - // Parameteres execution |
|
| 439 | - $command=$cmddump; |
|
| 440 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command |
|
| 441 | - |
|
| 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 | - //$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"; |
|
| 450 | - if (GETPOST("sql_structure")) |
|
| 451 | - { |
|
| 452 | - if (GETPOST("drop")) $param.=" --add-drop-table"; |
|
| 453 | - if (! GETPOST("sql_data")) $param.=" -s"; |
|
| 454 | - } |
|
| 455 | - if (GETPOST("sql_data")) |
|
| 456 | - { |
|
| 457 | - if (! GETPOST("sql_structure")) $param.=" -a"; |
|
| 458 | - if (GETPOST("showcolumns")) $param.=" -c"; |
|
| 459 | - } |
|
| 460 | - $param.=' -f "'.$outputfile.'"'; |
|
| 461 | - //if ($compression == 'none') |
|
| 462 | - if ($compression == 'gz') $param.=' -Z 9'; |
|
| 463 | - //if ($compression == 'bz') |
|
| 464 | - $paramcrypted=$param; |
|
| 465 | - $paramclear=$param; |
|
| 466 | - /*if (! empty($dolibarr_main_db_pass)) |
|
| 35 | + var $output; // Used by Cron method to return message |
|
| 36 | + var $result; // Used by Cron method to return data |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructor |
|
| 40 | + * |
|
| 41 | + * @param DoliDB $db Database handler |
|
| 42 | + */ |
|
| 43 | + function __construct($db) |
|
| 44 | + { |
|
| 45 | + $this->db = $db; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Purge files into directory of data files. |
|
| 51 | + * CAN BE A CRON TASK |
|
| 52 | + * |
|
| 53 | + * @param string $choice Choice of purge mode ('tempfiles', '' or 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfile') |
|
| 54 | + * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) |
|
| 55 | + */ |
|
| 56 | + function purgeFiles($choice='tempfilesold') |
|
| 57 | + { |
|
| 58 | + global $conf, $langs, $dolibarr_main_data_root; |
|
| 59 | + |
|
| 60 | + $langs->load("admin"); |
|
| 61 | + |
|
| 62 | + dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG); |
|
| 63 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 64 | + |
|
| 65 | + $filesarray=array(); |
|
| 66 | + if (empty($choice)) $choice='tempfilesold'; |
|
| 67 | + |
|
| 68 | + if ($choice=='tempfiles' || $choice=='tempfilesold') |
|
| 69 | + { |
|
| 70 | + // Delete temporary files |
|
| 71 | + if ($dolibarr_main_data_root) |
|
| 72 | + { |
|
| 73 | + $filesarray=dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks |
|
| 74 | + if ($choice == 'tempfilesold') |
|
| 75 | + { |
|
| 76 | + $now = dol_now(); |
|
| 77 | + foreach($filesarray as $key => $val) |
|
| 78 | + { |
|
| 79 | + if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if ($choice=='allfiles') |
|
| 86 | + { |
|
| 87 | + // Delete all files (except install.lock, do not follow symbolic links) |
|
| 88 | + if ($dolibarr_main_data_root) |
|
| 89 | + { |
|
| 90 | + $filesarray=dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ($choice=='logfile') |
|
| 95 | + { |
|
| 96 | + // Define files log |
|
| 97 | + if ($dolibarr_main_data_root) |
|
| 98 | + { |
|
| 99 | + $filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $filelog=''; |
|
| 103 | + if (! empty($conf->syslog->enabled)) |
|
| 104 | + { |
|
| 105 | + $filelog=$conf->global->SYSLOG_FILE; |
|
| 106 | + $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog); |
|
| 107 | + |
|
| 108 | + $alreadyincluded=false; |
|
| 109 | + foreach ($filesarray as $tmpcursor) |
|
| 110 | + { |
|
| 111 | + if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; } |
|
| 112 | + } |
|
| 113 | + if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file'); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $count=0; |
|
| 118 | + $countdeleted=0; |
|
| 119 | + $counterror=0; |
|
| 120 | + if (count($filesarray)) |
|
| 121 | + { |
|
| 122 | + foreach($filesarray as $key => $value) |
|
| 123 | + { |
|
| 124 | + //print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."<br>\n"; |
|
| 125 | + if ($filesarray[$key]['type'] == 'dir') |
|
| 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; |
|
| 132 | + } |
|
| 133 | + elseif ($filesarray[$key]['type'] == 'file') |
|
| 134 | + { |
|
| 135 | + // If (file that is not logfile) or (if mode is logfile) |
|
| 136 | + if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile') |
|
| 137 | + { |
|
| 138 | + $result=dol_delete_file($filesarray[$key]['fullname'], 1, 1); |
|
| 139 | + if ($result) |
|
| 140 | + { |
|
| 141 | + $count++; |
|
| 142 | + $countdeleted++; |
|
| 143 | + } |
|
| 144 | + else |
|
| 145 | + { |
|
| 146 | + $counterror++; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Update cachenbofdoc |
|
| 153 | + if (! empty($conf->ecm->enabled) && $choice=='allfiles') |
|
| 154 | + { |
|
| 155 | + require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; |
|
| 156 | + $ecmdirstatic = new EcmDirectory($this->db); |
|
| 157 | + $result = $ecmdirstatic->refreshcachenboffile(1); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ($count > 0) |
|
| 162 | + { |
|
| 163 | + $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted); |
|
| 164 | + if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); |
|
| 165 | + } |
|
| 166 | + else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':''); |
|
| 167 | + |
|
| 168 | + //return $count; |
|
| 169 | + return 0; // This function can be called by cron so must return 0 if OK |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Make a backup of database |
|
| 175 | + * CAN BE A CRON TASK |
|
| 176 | + * |
|
| 177 | + * @param string $compression 'gz' or 'bz' or 'none' |
|
| 178 | + * @param string $type 'mysql', 'postgresql', ... |
|
| 179 | + * @param int $usedefault 1=Use default backup profile (Set this to 1 when used as cron) |
|
| 180 | + * @param string $file 'auto' or filename to build |
|
| 181 | + * @param int $keeplastnfiles Keep only last n files (not used yet) |
|
| 182 | + * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method |
|
| 183 | + * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) |
|
| 184 | + */ |
|
| 185 | + function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0, $execmethod=0) |
|
| 186 | + { |
|
| 187 | + global $db, $conf, $langs, $dolibarr_main_data_root; |
|
| 188 | + global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass; |
|
| 189 | + |
|
| 190 | + $langs->load("admin"); |
|
| 191 | + |
|
| 192 | + dol_syslog("Utils::dumpDatabase type=".$type." compression=".$compression." file=".$file, LOG_DEBUG); |
|
| 193 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 194 | + |
|
| 195 | + // Check compression parameter |
|
| 196 | + if (! in_array($compression, array('none', 'gz', 'bz', 'zip'))) |
|
| 197 | + { |
|
| 198 | + $langs->load("errors"); |
|
| 199 | + $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression"); |
|
| 200 | + return -1; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // Check type parameter |
|
| 204 | + if ($type == 'auto') $type = $db->type; |
|
| 205 | + if (! in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin'))) |
|
| 206 | + { |
|
| 207 | + $langs->load("errors"); |
|
| 208 | + $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype"); |
|
| 209 | + return -1; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // Check file parameter |
|
| 213 | + if ($file == 'auto') |
|
| 214 | + { |
|
| 215 | + $prefix='dump'; |
|
| 216 | + $ext='sql'; |
|
| 217 | + if (in_array($type, array('mysql', 'mysqli'))) { $prefix='mysqldump'; $ext='sql'; } |
|
| 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; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $outputdir = $conf->admin->dir_output.'/backup'; |
|
| 224 | + $result=dol_mkdir($outputdir); |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + // MYSQL |
|
| 228 | + if ($type == 'mysql' || $type == 'mysqli') |
|
| 229 | + { |
|
| 230 | + $cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP; |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + $outputfile = $outputdir.'/'.$file; |
|
| 234 | + // for compression format, we add extension |
|
| 235 | + $compression=$compression ? $compression : 'none'; |
|
| 236 | + if ($compression == 'gz') $outputfile.='.gz'; |
|
| 237 | + if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 238 | + $outputerror = $outputfile.'.err'; |
|
| 239 | + dol_mkdir($conf->admin->dir_output.'/backup'); |
|
| 240 | + |
|
| 241 | + // Parameteres execution |
|
| 242 | + $command=$cmddump; |
|
| 243 | + if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command |
|
| 244 | + |
|
| 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"; |
|
| 253 | + if (GETPOST("sql_structure") || $usedefault) |
|
| 254 | + { |
|
| 255 | + if (GETPOST("drop") || $usedefault) $param.=" --add-drop-table=TRUE"; |
|
| 256 | + else $param.=" --add-drop-table=FALSE"; |
|
| 257 | + } |
|
| 258 | + else |
|
| 259 | + { |
|
| 260 | + $param.=" -t"; |
|
| 261 | + } |
|
| 262 | + if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE"; |
|
| 263 | + if (GETPOST("sql_data") || $usedefault) |
|
| 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"; |
|
| 272 | + } |
|
| 273 | + else |
|
| 274 | + { |
|
| 275 | + $param.=" -d"; // No row information (no data) |
|
| 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)) |
|
| 281 | + { |
|
| 282 | + $paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"'; |
|
| 283 | + $paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"'; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $errormsg=''; |
|
| 287 | + $handle = ''; |
|
| 288 | + |
|
| 289 | + // Start call method to execute dump |
|
| 290 | + $fullcommandcrypted=$command." ".$paramcrypted." 2>&1"; |
|
| 291 | + $fullcommandclear=$command." ".$paramclear." 2>&1"; |
|
| 292 | + if ($compression == 'none') $handle = fopen($outputfile, 'w'); |
|
| 293 | + if ($compression == 'gz') $handle = gzopen($outputfile, 'w'); |
|
| 294 | + if ($compression == 'bz') $handle = bzopen($outputfile, 'w'); |
|
| 295 | + |
|
| 296 | + if ($handle) |
|
| 297 | + { |
|
| 298 | + if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; |
|
| 299 | + if (empty($execmethod)) $execmethod=1; |
|
| 300 | + |
|
| 301 | + $ok=0; |
|
| 302 | + dol_syslog("Utils::dumpDatabase execmethod=".$execmethod." command:".$fullcommandcrypted, LOG_DEBUG); |
|
| 303 | + |
|
| 304 | + // TODO Replace with executeCLI function |
|
| 305 | + if ($execmethod == 1) |
|
| 306 | + { |
|
| 307 | + exec($fullcommandclear, $readt, $retval); |
|
| 308 | + $result = $retval; |
|
| 309 | + |
|
| 310 | + if ($retval != 0) |
|
| 311 | + { |
|
| 312 | + $langs->load("errors"); |
|
| 313 | + dol_syslog("Datadump retval after exec=".$retval, LOG_ERR); |
|
| 314 | + $error = 'Error '.$retval; |
|
| 315 | + $ok=0; |
|
| 316 | + } |
|
| 317 | + else |
|
| 318 | + { |
|
| 319 | + $i=0; |
|
| 320 | + if (!empty($readt)) |
|
| 321 | + foreach($readt as $key=>$read) |
|
| 322 | + { |
|
| 323 | + $i++; // output line number |
|
| 324 | + if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue; |
|
| 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; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + if ($execmethod == 2) // With this method, there is no way to get the return code, only output |
|
| 332 | + { |
|
| 333 | + $handlein = popen($fullcommandclear, 'r'); |
|
| 334 | + $i=0; |
|
| 335 | + while (!feof($handlein)) |
|
| 336 | + { |
|
| 337 | + $i++; // output line number |
|
| 338 | + $read = fgets($handlein); |
|
| 339 | + // Exclude warning line we don't want |
|
| 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; |
|
| 344 | + } |
|
| 345 | + pclose($handlein); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + if ($compression == 'none') fclose($handle); |
|
| 350 | + if ($compression == 'gz') gzclose($handle); |
|
| 351 | + if ($compression == 'bz') bzclose($handle); |
|
| 352 | + |
|
| 353 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 354 | + @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 355 | + } |
|
| 356 | + else |
|
| 357 | + { |
|
| 358 | + $langs->load("errors"); |
|
| 359 | + dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 360 | + $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Get errorstring |
|
| 364 | + if ($compression == 'none') $handle = fopen($outputfile, 'r'); |
|
| 365 | + if ($compression == 'gz') $handle = gzopen($outputfile, 'r'); |
|
| 366 | + if ($compression == 'bz') $handle = bzopen($outputfile, 'r'); |
|
| 367 | + if ($handle) |
|
| 368 | + { |
|
| 369 | + // Get 2048 first chars of error message. |
|
| 370 | + $errormsg = fgets($handle,2048); |
|
| 371 | + // Close file |
|
| 372 | + if ($compression == 'none') fclose($handle); |
|
| 373 | + if ($compression == 'gz') gzclose($handle); |
|
| 374 | + if ($compression == 'bz') bzclose($handle); |
|
| 375 | + if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg=''; // Pas erreur |
|
| 376 | + else |
|
| 377 | + { |
|
| 378 | + // Renommer fichier sortie en fichier erreur |
|
| 379 | + //print "$outputfile -> $outputerror"; |
|
| 380 | + @dol_delete_file($outputerror, 1, 0, 0, null, false, 0); |
|
| 381 | + @rename($outputfile,$outputerror); |
|
| 382 | + // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide |
|
| 383 | + if (! $errormsg) |
|
| 384 | + { |
|
| 385 | + $langs->load("errors"); |
|
| 386 | + $errormsg=$langs->trans("ErrorFailedToRunExternalCommand"); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + // Fin execution commande |
|
| 391 | + |
|
| 392 | + $this->output = $errormsg; |
|
| 393 | + $this->error = $errormsg; |
|
| 394 | + $this->result = array("commandbackuplastdone" => $command." ".$paramcrypted, "commandbackuptorun" => ""); |
|
| 395 | + //if (empty($this->output)) $this->output=$this->result['commandbackuplastdone']; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + // MYSQL NO BIN |
|
| 399 | + if ($type == 'mysqlnobin') |
|
| 400 | + { |
|
| 401 | + $outputfile = $outputdir.'/'.$file; |
|
| 402 | + $outputfiletemp = $outputfile.'-TMP.sql'; |
|
| 403 | + // for compression format, we add extension |
|
| 404 | + $compression=$compression ? $compression : 'none'; |
|
| 405 | + if ($compression == 'gz') $outputfile.='.gz'; |
|
| 406 | + if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 407 | + $outputerror = $outputfile.'.err'; |
|
| 408 | + dol_mkdir($conf->admin->dir_output.'/backup'); |
|
| 409 | + |
|
| 410 | + if ($compression == 'gz' or $compression == 'bz') |
|
| 411 | + { |
|
| 412 | + $this->backupTables($outputfiletemp); |
|
| 413 | + dol_compress_file($outputfiletemp, $outputfile, $compression); |
|
| 414 | + unlink($outputfiletemp); |
|
| 415 | + } |
|
| 416 | + else |
|
| 417 | + { |
|
| 418 | + $this->backupTables($outputfile); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $this->output = ""; |
|
| 422 | + $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => ""); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + // POSTGRESQL |
|
| 426 | + if ($type == 'postgresql' || $type == 'pgsql') |
|
| 427 | + { |
|
| 428 | + $cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP; |
|
| 429 | + |
|
| 430 | + $outputfile = $outputdir.'/'.$file; |
|
| 431 | + // for compression format, we add extension |
|
| 432 | + $compression=$compression ? $compression : 'none'; |
|
| 433 | + if ($compression == 'gz') $outputfile.='.gz'; |
|
| 434 | + if ($compression == 'bz') $outputfile.='.bz2'; |
|
| 435 | + $outputerror = $outputfile.'.err'; |
|
| 436 | + dol_mkdir($conf->admin->dir_output.'/backup'); |
|
| 437 | + |
|
| 438 | + // Parameteres execution |
|
| 439 | + $command=$cmddump; |
|
| 440 | + if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command |
|
| 441 | + |
|
| 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 | + //$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"; |
|
| 450 | + if (GETPOST("sql_structure")) |
|
| 451 | + { |
|
| 452 | + if (GETPOST("drop")) $param.=" --add-drop-table"; |
|
| 453 | + if (! GETPOST("sql_data")) $param.=" -s"; |
|
| 454 | + } |
|
| 455 | + if (GETPOST("sql_data")) |
|
| 456 | + { |
|
| 457 | + if (! GETPOST("sql_structure")) $param.=" -a"; |
|
| 458 | + if (GETPOST("showcolumns")) $param.=" -c"; |
|
| 459 | + } |
|
| 460 | + $param.=' -f "'.$outputfile.'"'; |
|
| 461 | + //if ($compression == 'none') |
|
| 462 | + if ($compression == 'gz') $param.=' -Z 9'; |
|
| 463 | + //if ($compression == 'bz') |
|
| 464 | + $paramcrypted=$param; |
|
| 465 | + $paramclear=$param; |
|
| 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; |
|
| 473 | - |
|
| 474 | - $this->output = ""; |
|
| 475 | - $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - // Clean old files |
|
| 479 | - if ($keeplastnfiles > 0) |
|
| 480 | - { |
|
| 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) |
|
| 484 | - { |
|
| 485 | - $i++; |
|
| 486 | - if ($i <= $keeplastnfiles) continue; |
|
| 487 | - dol_delete_file($val['fullname'], 0, 0, 0, null, false, 0); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - return 0; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Execute a CLI command. |
|
| 498 | - * |
|
| 499 | - * @param string $command Command line to execute. |
|
| 500 | - * @param string $outputfile Output file (used only when method is 2). For exemple $conf->admin->dir_temp.'/out.tmp'; |
|
| 501 | - * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method |
|
| 502 | - * @return array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK. |
|
| 503 | - */ |
|
| 504 | - function executeCLI($command, $outputfile, $execmethod=0) |
|
| 505 | - { |
|
| 506 | - global $conf, $langs; |
|
| 507 | - |
|
| 508 | - $result = 0; |
|
| 509 | - $output = ''; |
|
| 510 | - $error = ''; |
|
| 511 | - |
|
| 512 | - $command=escapeshellcmd($command); |
|
| 513 | - $command.=" 2>&1"; |
|
| 514 | - |
|
| 515 | - if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; |
|
| 516 | - if (empty($execmethod)) $execmethod=1; |
|
| 517 | - //$execmethod=1; |
|
| 518 | - |
|
| 519 | - dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG); |
|
| 520 | - $output_arr=array(); |
|
| 521 | - |
|
| 522 | - if ($execmethod == 1) |
|
| 523 | - { |
|
| 524 | - exec($command, $output_arr, $retval); |
|
| 525 | - $result = $retval; |
|
| 526 | - if ($retval != 0) |
|
| 527 | - { |
|
| 528 | - $langs->load("errors"); |
|
| 529 | - dol_syslog("Utils::executeCLI retval after exec=".$retval, LOG_ERR); |
|
| 530 | - $error = 'Error '.$retval; |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - if ($execmethod == 2) // With this method, there is no way to get the return code, only output |
|
| 534 | - { |
|
| 535 | - $ok=0; |
|
| 536 | - $handle = fopen($outputfile, 'w+b'); |
|
| 537 | - if ($handle) |
|
| 538 | - { |
|
| 539 | - dol_syslog("Utils::executeCLI run command ".$command); |
|
| 540 | - $handlein = popen($command, 'r'); |
|
| 541 | - while (!feof($handlein)) |
|
| 542 | - { |
|
| 543 | - $read = fgets($handlein); |
|
| 544 | - fwrite($handle,$read); |
|
| 545 | - $output_arr[]=$read; |
|
| 546 | - } |
|
| 547 | - pclose($handlein); |
|
| 548 | - fclose($handle); |
|
| 549 | - } |
|
| 550 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // Update with result |
|
| 554 | - if (is_array($output_arr) && count($output_arr)>0) |
|
| 555 | - { |
|
| 556 | - foreach($output_arr as $val) |
|
| 557 | - { |
|
| 558 | - $output.=$val.($execmethod == 2 ? '' : "\n"); |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - dol_syslog("Utils::executeCLI result=".$result." output=".$output." error=".$error, LOG_DEBUG); |
|
| 563 | - |
|
| 564 | - return array('result'=>$result, 'output'=>$output, 'error'=>$error); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Generate documentation of a Module |
|
| 569 | - * |
|
| 570 | - * @param string $module Module name |
|
| 571 | - * @return int <0 if KO, >0 if OK |
|
| 572 | - */ |
|
| 573 | - function generateDoc($module) |
|
| 574 | - { |
|
| 575 | - global $conf, $langs; |
|
| 576 | - global $dirins; |
|
| 577 | - |
|
| 578 | - $error = 0; |
|
| 579 | - |
|
| 580 | - $modulelowercase=strtolower($module); |
|
| 581 | - |
|
| 582 | - // Dir for module |
|
| 583 | - $dir = $dirins.'/'.$modulelowercase; |
|
| 584 | - // Zip file to build |
|
| 585 | - $FILENAMEDOC=''; |
|
| 586 | - |
|
| 587 | - // Load module |
|
| 588 | - dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php'); |
|
| 589 | - $class='mod'.$module; |
|
| 590 | - |
|
| 591 | - if (class_exists($class)) |
|
| 592 | - { |
|
| 593 | - try { |
|
| 594 | - $moduleobj = new $class($this->db); |
|
| 595 | - } |
|
| 596 | - catch(Exception $e) |
|
| 597 | - { |
|
| 598 | - $error++; |
|
| 599 | - dol_print_error($e->getMessage()); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - else |
|
| 603 | - { |
|
| 604 | - $error++; |
|
| 605 | - $langs->load("errors"); |
|
| 606 | - dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); |
|
| 607 | - exit; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - $arrayversion=explode('.',$moduleobj->version,3); |
|
| 611 | - if (count($arrayversion)) |
|
| 612 | - { |
|
| 613 | - $FILENAMEASCII=strtolower($module).'.asciidoc'; |
|
| 614 | - $FILENAMEDOC=strtolower($module).'.html'; // TODO Use/text PDF |
|
| 615 | - |
|
| 616 | - $dirofmodule = dol_buildpath(strtolower($module), 0).'/doc'; |
|
| 617 | - $dirofmoduletmp = dol_buildpath(strtolower($module), 0).'/doc/temp'; |
|
| 618 | - $outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC; |
|
| 619 | - if ($dirofmodule) |
|
| 620 | - { |
|
| 621 | - if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule); |
|
| 622 | - if (! dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp); |
|
| 623 | - if (! is_writable($dirofmoduletmp)) |
|
| 624 | - { |
|
| 625 | - $this->error = 'Dir '.$dirofmoduletmp.' does not exists or is not writable'; |
|
| 626 | - return -1; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - $destfile=$dirofmoduletmp.'/'.$FILENAMEASCII; |
|
| 630 | - |
|
| 631 | - $fhandle = fopen($destfile, 'w+'); |
|
| 632 | - if ($fhandle) |
|
| 633 | - { |
|
| 634 | - $specs=dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/')); |
|
| 635 | - |
|
| 636 | - $i = 0; |
|
| 637 | - foreach ($specs as $spec) |
|
| 638 | - { |
|
| 639 | - if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file |
|
| 640 | - if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file |
|
| 641 | - |
|
| 642 | - $pathtofile = strtolower($module).'/doc/'.$spec['relativename']; |
|
| 643 | - $format='asciidoc'; |
|
| 644 | - if (preg_match('/\.md$/i', $spec['name'])) $format='markdown'; |
|
| 645 | - |
|
| 646 | - $filecursor = @file_get_contents($spec['fullname']); |
|
| 647 | - if ($filecursor) |
|
| 648 | - { |
|
| 649 | - fwrite($fhandle, ($i ? "\n<<<\n\n" : "").$filecursor."\n"); |
|
| 650 | - } |
|
| 651 | - else |
|
| 652 | - { |
|
| 653 | - $this->error = 'Failed to concat content of file '.$spec['fullname']; |
|
| 654 | - return -1; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - $i++; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - fwrite($fhandle, "\n\n\n== DATA SPECIFICATIONS...\n\n"); |
|
| 661 | - |
|
| 662 | - // TODO |
|
| 663 | - fwrite($fhandle, "TODO..."); |
|
| 664 | - |
|
| 665 | - fclose($fhandle); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - $conf->global->MODULEBUILDER_ASCIIDOCTOR='asciidoctor'; |
|
| 669 | - if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR)) |
|
| 670 | - { |
|
| 671 | - dol_print_error('', 'Module setup not complete'); |
|
| 672 | - exit; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - $command=$conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmodule.'/'.$FILENAMEDOC; |
|
| 676 | - $outfile=$dirofmoduletmp.'/out.tmp'; |
|
| 677 | - |
|
| 678 | - require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php'; |
|
| 679 | - $utils = new Utils($db); |
|
| 680 | - $resarray = $utils->executeCLI($command, $outfile); |
|
| 681 | - if ($resarray['result'] != '0') |
|
| 682 | - { |
|
| 683 | - $this->error = $resarray['error'].' '.$resarray['output']; |
|
| 684 | - } |
|
| 685 | - $result = ($resarray['result'] == 0) ? 1 : 0; |
|
| 686 | - } |
|
| 687 | - else |
|
| 688 | - { |
|
| 689 | - $result = 0; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - if ($result > 0) |
|
| 693 | - { |
|
| 694 | - return 1; |
|
| 695 | - } |
|
| 696 | - else |
|
| 697 | - { |
|
| 698 | - $error++; |
|
| 699 | - $langs->load("errors"); |
|
| 700 | - $this->error = $langs->trans("ErrorFailToGenerateFile", $outputfiledoc); |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - else |
|
| 704 | - { |
|
| 705 | - $error++; |
|
| 706 | - $langs->load("errors"); |
|
| 707 | - $this->error = $langs->trans("ErrorCheckVersionIsDefined"); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return -1; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * This saves syslog files and compresses older ones. |
|
| 715 | - * Nb of archive to keep is defined into $conf->global->SYSLOG_FILE_SAVES |
|
| 716 | - * CAN BE A CRON TASK |
|
| 717 | - * |
|
| 718 | - * @return int 0 if OK, < 0 if KO |
|
| 719 | - */ |
|
| 471 | + $paramcrypted.=" -w ".$dolibarr_main_db_name; |
|
| 472 | + $paramclear.=" -w ".$dolibarr_main_db_name; |
|
| 473 | + |
|
| 474 | + $this->output = ""; |
|
| 475 | + $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + // Clean old files |
|
| 479 | + if ($keeplastnfiles > 0) |
|
| 480 | + { |
|
| 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) |
|
| 484 | + { |
|
| 485 | + $i++; |
|
| 486 | + if ($i <= $keeplastnfiles) continue; |
|
| 487 | + dol_delete_file($val['fullname'], 0, 0, 0, null, false, 0); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + return 0; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Execute a CLI command. |
|
| 498 | + * |
|
| 499 | + * @param string $command Command line to execute. |
|
| 500 | + * @param string $outputfile Output file (used only when method is 2). For exemple $conf->admin->dir_temp.'/out.tmp'; |
|
| 501 | + * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method |
|
| 502 | + * @return array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK. |
|
| 503 | + */ |
|
| 504 | + function executeCLI($command, $outputfile, $execmethod=0) |
|
| 505 | + { |
|
| 506 | + global $conf, $langs; |
|
| 507 | + |
|
| 508 | + $result = 0; |
|
| 509 | + $output = ''; |
|
| 510 | + $error = ''; |
|
| 511 | + |
|
| 512 | + $command=escapeshellcmd($command); |
|
| 513 | + $command.=" 2>&1"; |
|
| 514 | + |
|
| 515 | + if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; |
|
| 516 | + if (empty($execmethod)) $execmethod=1; |
|
| 517 | + //$execmethod=1; |
|
| 518 | + |
|
| 519 | + dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG); |
|
| 520 | + $output_arr=array(); |
|
| 521 | + |
|
| 522 | + if ($execmethod == 1) |
|
| 523 | + { |
|
| 524 | + exec($command, $output_arr, $retval); |
|
| 525 | + $result = $retval; |
|
| 526 | + if ($retval != 0) |
|
| 527 | + { |
|
| 528 | + $langs->load("errors"); |
|
| 529 | + dol_syslog("Utils::executeCLI retval after exec=".$retval, LOG_ERR); |
|
| 530 | + $error = 'Error '.$retval; |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + if ($execmethod == 2) // With this method, there is no way to get the return code, only output |
|
| 534 | + { |
|
| 535 | + $ok=0; |
|
| 536 | + $handle = fopen($outputfile, 'w+b'); |
|
| 537 | + if ($handle) |
|
| 538 | + { |
|
| 539 | + dol_syslog("Utils::executeCLI run command ".$command); |
|
| 540 | + $handlein = popen($command, 'r'); |
|
| 541 | + while (!feof($handlein)) |
|
| 542 | + { |
|
| 543 | + $read = fgets($handlein); |
|
| 544 | + fwrite($handle,$read); |
|
| 545 | + $output_arr[]=$read; |
|
| 546 | + } |
|
| 547 | + pclose($handlein); |
|
| 548 | + fclose($handle); |
|
| 549 | + } |
|
| 550 | + if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + // Update with result |
|
| 554 | + if (is_array($output_arr) && count($output_arr)>0) |
|
| 555 | + { |
|
| 556 | + foreach($output_arr as $val) |
|
| 557 | + { |
|
| 558 | + $output.=$val.($execmethod == 2 ? '' : "\n"); |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + dol_syslog("Utils::executeCLI result=".$result." output=".$output." error=".$error, LOG_DEBUG); |
|
| 563 | + |
|
| 564 | + return array('result'=>$result, 'output'=>$output, 'error'=>$error); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Generate documentation of a Module |
|
| 569 | + * |
|
| 570 | + * @param string $module Module name |
|
| 571 | + * @return int <0 if KO, >0 if OK |
|
| 572 | + */ |
|
| 573 | + function generateDoc($module) |
|
| 574 | + { |
|
| 575 | + global $conf, $langs; |
|
| 576 | + global $dirins; |
|
| 577 | + |
|
| 578 | + $error = 0; |
|
| 579 | + |
|
| 580 | + $modulelowercase=strtolower($module); |
|
| 581 | + |
|
| 582 | + // Dir for module |
|
| 583 | + $dir = $dirins.'/'.$modulelowercase; |
|
| 584 | + // Zip file to build |
|
| 585 | + $FILENAMEDOC=''; |
|
| 586 | + |
|
| 587 | + // Load module |
|
| 588 | + dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php'); |
|
| 589 | + $class='mod'.$module; |
|
| 590 | + |
|
| 591 | + if (class_exists($class)) |
|
| 592 | + { |
|
| 593 | + try { |
|
| 594 | + $moduleobj = new $class($this->db); |
|
| 595 | + } |
|
| 596 | + catch(Exception $e) |
|
| 597 | + { |
|
| 598 | + $error++; |
|
| 599 | + dol_print_error($e->getMessage()); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + else |
|
| 603 | + { |
|
| 604 | + $error++; |
|
| 605 | + $langs->load("errors"); |
|
| 606 | + dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); |
|
| 607 | + exit; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + $arrayversion=explode('.',$moduleobj->version,3); |
|
| 611 | + if (count($arrayversion)) |
|
| 612 | + { |
|
| 613 | + $FILENAMEASCII=strtolower($module).'.asciidoc'; |
|
| 614 | + $FILENAMEDOC=strtolower($module).'.html'; // TODO Use/text PDF |
|
| 615 | + |
|
| 616 | + $dirofmodule = dol_buildpath(strtolower($module), 0).'/doc'; |
|
| 617 | + $dirofmoduletmp = dol_buildpath(strtolower($module), 0).'/doc/temp'; |
|
| 618 | + $outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC; |
|
| 619 | + if ($dirofmodule) |
|
| 620 | + { |
|
| 621 | + if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule); |
|
| 622 | + if (! dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp); |
|
| 623 | + if (! is_writable($dirofmoduletmp)) |
|
| 624 | + { |
|
| 625 | + $this->error = 'Dir '.$dirofmoduletmp.' does not exists or is not writable'; |
|
| 626 | + return -1; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + $destfile=$dirofmoduletmp.'/'.$FILENAMEASCII; |
|
| 630 | + |
|
| 631 | + $fhandle = fopen($destfile, 'w+'); |
|
| 632 | + if ($fhandle) |
|
| 633 | + { |
|
| 634 | + $specs=dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/')); |
|
| 635 | + |
|
| 636 | + $i = 0; |
|
| 637 | + foreach ($specs as $spec) |
|
| 638 | + { |
|
| 639 | + if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file |
|
| 640 | + if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file |
|
| 641 | + |
|
| 642 | + $pathtofile = strtolower($module).'/doc/'.$spec['relativename']; |
|
| 643 | + $format='asciidoc'; |
|
| 644 | + if (preg_match('/\.md$/i', $spec['name'])) $format='markdown'; |
|
| 645 | + |
|
| 646 | + $filecursor = @file_get_contents($spec['fullname']); |
|
| 647 | + if ($filecursor) |
|
| 648 | + { |
|
| 649 | + fwrite($fhandle, ($i ? "\n<<<\n\n" : "").$filecursor."\n"); |
|
| 650 | + } |
|
| 651 | + else |
|
| 652 | + { |
|
| 653 | + $this->error = 'Failed to concat content of file '.$spec['fullname']; |
|
| 654 | + return -1; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + $i++; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + fwrite($fhandle, "\n\n\n== DATA SPECIFICATIONS...\n\n"); |
|
| 661 | + |
|
| 662 | + // TODO |
|
| 663 | + fwrite($fhandle, "TODO..."); |
|
| 664 | + |
|
| 665 | + fclose($fhandle); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + $conf->global->MODULEBUILDER_ASCIIDOCTOR='asciidoctor'; |
|
| 669 | + if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR)) |
|
| 670 | + { |
|
| 671 | + dol_print_error('', 'Module setup not complete'); |
|
| 672 | + exit; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + $command=$conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmodule.'/'.$FILENAMEDOC; |
|
| 676 | + $outfile=$dirofmoduletmp.'/out.tmp'; |
|
| 677 | + |
|
| 678 | + require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php'; |
|
| 679 | + $utils = new Utils($db); |
|
| 680 | + $resarray = $utils->executeCLI($command, $outfile); |
|
| 681 | + if ($resarray['result'] != '0') |
|
| 682 | + { |
|
| 683 | + $this->error = $resarray['error'].' '.$resarray['output']; |
|
| 684 | + } |
|
| 685 | + $result = ($resarray['result'] == 0) ? 1 : 0; |
|
| 686 | + } |
|
| 687 | + else |
|
| 688 | + { |
|
| 689 | + $result = 0; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + if ($result > 0) |
|
| 693 | + { |
|
| 694 | + return 1; |
|
| 695 | + } |
|
| 696 | + else |
|
| 697 | + { |
|
| 698 | + $error++; |
|
| 699 | + $langs->load("errors"); |
|
| 700 | + $this->error = $langs->trans("ErrorFailToGenerateFile", $outputfiledoc); |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + else |
|
| 704 | + { |
|
| 705 | + $error++; |
|
| 706 | + $langs->load("errors"); |
|
| 707 | + $this->error = $langs->trans("ErrorCheckVersionIsDefined"); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return -1; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * This saves syslog files and compresses older ones. |
|
| 715 | + * Nb of archive to keep is defined into $conf->global->SYSLOG_FILE_SAVES |
|
| 716 | + * CAN BE A CRON TASK |
|
| 717 | + * |
|
| 718 | + * @return int 0 if OK, < 0 if KO |
|
| 719 | + */ |
|
| 720 | 720 | function compressSyslogs() |
| 721 | 721 | { |
| 722 | - global $conf; |
|
| 722 | + global $conf; |
|
| 723 | + |
|
| 724 | + if(empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled |
|
| 725 | + return 0; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + if(! function_exists('gzopen')) { |
|
| 729 | + $this->error = 'Support for gzopen not available in this PHP'; |
|
| 730 | + return -1; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + dol_include_once('/core/lib/files.lib.php'); |
|
| 734 | + |
|
| 735 | + $nbSaves = ! empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14; |
|
| 736 | + |
|
| 737 | + if (empty($conf->global->SYSLOG_FILE)) { |
|
| 738 | + $mainlogdir = DOL_DATA_ROOT; |
|
| 739 | + $mainlog = 'dolibarr.log'; |
|
| 740 | + } else { |
|
| 741 | + $mainlogfull = str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE); |
|
| 742 | + $mainlogdir = dirname($mainlogfull); |
|
| 743 | + $mainlog = basename($mainlogfull); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + $tabfiles = dol_dir_list(DOL_DATA_ROOT, 'files', 0, '^(dolibarr_.+|odt2pdf)\.log$'); // Also handle other log files like dolibarr_install.log |
|
| 747 | + $tabfiles[] = array('name' => $mainlog, 'path' => $mainlogdir); |
|
| 723 | 748 | |
| 724 | - if(empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled |
|
| 725 | - return 0; |
|
| 726 | - } |
|
| 749 | + foreach($tabfiles as $file) { |
|
| 727 | 750 | |
| 728 | - if(! function_exists('gzopen')) { |
|
| 729 | - $this->error = 'Support for gzopen not available in this PHP'; |
|
| 730 | - return -1; |
|
| 731 | - } |
|
| 751 | + $logname = $file['name']; |
|
| 752 | + $logpath = $file['path']; |
|
| 732 | 753 | |
| 733 | - dol_include_once('/core/lib/files.lib.php'); |
|
| 754 | + if (dol_is_file($logpath.'/'.$logname) && dol_filesize($logpath.'/'.$logname) > 0) // If log file exists and is not empty |
|
| 755 | + { |
|
| 756 | + // Handle already compressed files to rename them and add +1 |
|
| 734 | 757 | |
| 735 | - $nbSaves = ! empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14; |
|
| 758 | + $filter = '^'.preg_quote($logname, '/').'\.([0-9]+)\.gz$'; |
|
| 736 | 759 | |
| 737 | - if (empty($conf->global->SYSLOG_FILE)) { |
|
| 738 | - $mainlogdir = DOL_DATA_ROOT; |
|
| 739 | - $mainlog = 'dolibarr.log'; |
|
| 740 | - } else { |
|
| 741 | - $mainlogfull = str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE); |
|
| 742 | - $mainlogdir = dirname($mainlogfull); |
|
| 743 | - $mainlog = basename($mainlogfull); |
|
| 744 | - } |
|
| 760 | + $gzfilestmp = dol_dir_list($logpath, 'files', 0, $filter); |
|
| 761 | + $gzfiles = array(); |
|
| 745 | 762 | |
| 746 | - $tabfiles = dol_dir_list(DOL_DATA_ROOT, 'files', 0, '^(dolibarr_.+|odt2pdf)\.log$'); // Also handle other log files like dolibarr_install.log |
|
| 747 | - $tabfiles[] = array('name' => $mainlog, 'path' => $mainlogdir); |
|
| 763 | + foreach($gzfilestmp as $gzfile) { |
|
| 764 | + $tabmatches = array(); |
|
| 765 | + preg_match('/'.$filter.'/i', $gzfile['name'], $tabmatches); |
|
| 748 | 766 | |
| 749 | - foreach($tabfiles as $file) { |
|
| 750 | - |
|
| 751 | - $logname = $file['name']; |
|
| 752 | - $logpath = $file['path']; |
|
| 753 | - |
|
| 754 | - if (dol_is_file($logpath.'/'.$logname) && dol_filesize($logpath.'/'.$logname) > 0) // If log file exists and is not empty |
|
| 755 | - { |
|
| 756 | - // Handle already compressed files to rename them and add +1 |
|
| 757 | - |
|
| 758 | - $filter = '^'.preg_quote($logname, '/').'\.([0-9]+)\.gz$'; |
|
| 759 | - |
|
| 760 | - $gzfilestmp = dol_dir_list($logpath, 'files', 0, $filter); |
|
| 761 | - $gzfiles = array(); |
|
| 762 | - |
|
| 763 | - foreach($gzfilestmp as $gzfile) { |
|
| 764 | - $tabmatches = array(); |
|
| 765 | - preg_match('/'.$filter.'/i', $gzfile['name'], $tabmatches); |
|
| 766 | - |
|
| 767 | - $numsave = intval($tabmatches[1]); |
|
| 768 | - |
|
| 769 | - $gzfiles[$numsave] = $gzfile; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - krsort($gzfiles, SORT_NUMERIC); |
|
| 773 | - |
|
| 774 | - foreach($gzfiles as $numsave => $dummy) { |
|
| 775 | - if (dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) { |
|
| 776 | - return -2; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - if($numsave >= $nbSaves) { |
|
| 780 | - dol_delete_file($logpath.'/'.$logname.'.'.$numsave.'.gz', 0, 0, 0, null, false, 0); |
|
| 781 | - } else { |
|
| 782 | - dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave+1).'.gz', 0, 1, 0, 0); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // Compress current file and recreate it |
|
| 787 | - |
|
| 788 | - if ($nbSaves > 0) { // If $nbSaves is 1, we keep 1 archive .gz file, If 2, we keep 2 .gz files |
|
| 789 | - $gzfilehandle = gzopen($logpath.'/'.$logname.'.1.gz', 'wb9'); |
|
| 790 | - |
|
| 791 | - if (empty($gzfilehandle)) { |
|
| 792 | - $this->error = 'Failted to open file '.$logpath.'/'.$logname.'.1.gz'; |
|
| 793 | - return -3; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - $sourcehandle = fopen($logpath.'/'.$logname, 'r'); |
|
| 797 | - |
|
| 798 | - if (empty($sourcehandle)) { |
|
| 799 | - $this->error = 'Failed to open file '.$logpath.'/'.$logname; |
|
| 800 | - return -4; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - while(! feof($sourcehandle)) { |
|
| 804 | - gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024)); // Read 512 kB at a time |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - fclose($sourcehandle); |
|
| 808 | - gzclose($gzfilehandle); |
|
| 809 | - |
|
| 810 | - @chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - dol_delete_file($logpath.'/'.$logname, 0, 0, 0, null, false, 0); |
|
| 814 | - |
|
| 815 | - // Create empty file |
|
| 816 | - $newlog = fopen($logpath.'/'.$logname, 'a+'); |
|
| 817 | - fclose($newlog); |
|
| 818 | - |
|
| 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)); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - $this->output = 'Archive log files (keeping last SYSLOG_FILE_SAVES='.$nbSaves.' files) done.'; |
|
| 825 | - return 0; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - /** Backup the db OR just a table without mysqldump binary, with PHP only (does not require any exec permission) |
|
| 829 | - * Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php) |
|
| 830 | - * Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog |
|
| 831 | - * Note about foreign keys constraints: for Dolibarr, since there are a lot of constraints and when imported the tables will be inserted in the dumped order, not in constraints order, then we ABSOLUTELY need to use SET FOREIGN_KEY_CHECKS=0; when importing the sql dump. |
|
| 832 | - * Note2: db2SQL by Howard Yeend can be an alternative, by using SHOW FIELDS FROM and SHOW KEYS FROM we could generate a more precise dump (eg: by getting the type of the field and then precisely outputting the right formatting - in quotes, numeric or null - instead of trying to guess like we are doing now). |
|
| 833 | - * |
|
| 834 | - * @param string $outputfile Output file name |
|
| 835 | - * @param string $tables Table name or '*' for all |
|
| 836 | - * @return int <0 if KO, >0 if OK |
|
| 837 | - */ |
|
| 838 | - function backupTables($outputfile, $tables='*') |
|
| 839 | - { |
|
| 840 | - global $db, $langs; |
|
| 841 | - global $errormsg; |
|
| 842 | - |
|
| 843 | - // Set to UTF-8 |
|
| 844 | - if (is_a($db, 'DoliDBMysqli')) { |
|
| 845 | - /** @var DoliDBMysqli $db */ |
|
| 846 | - $db->db->set_charset('utf8'); |
|
| 847 | - } else { |
|
| 848 | - /** @var DoliDB $db */ |
|
| 849 | - $db->query('SET NAMES utf8'); |
|
| 850 | - $db->query('SET CHARACTER SET utf8'); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - //get all of the tables |
|
| 854 | - if ($tables == '*') |
|
| 855 | - { |
|
| 856 | - $tables = array(); |
|
| 857 | - $result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\''); |
|
| 858 | - while($row = $db->fetch_row($result)) |
|
| 859 | - { |
|
| 860 | - $tables[] = $row[0]; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - else |
|
| 864 | - { |
|
| 865 | - $tables = is_array($tables) ? $tables : explode(',',$tables); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - //cycle through |
|
| 869 | - $handle = fopen($outputfile, 'w+'); |
|
| 870 | - if (fwrite($handle, '') === false) |
|
| 871 | - { |
|
| 872 | - $langs->load("errors"); |
|
| 873 | - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 874 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 875 | - return -1; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - // Print headers and global mysql config vars |
|
| 879 | - $sqlhead = ''; |
|
| 880 | - $sqlhead .= "-- ".$db::LABEL." dump via php with Dolibarr ".DOL_VERSION." |
|
| 767 | + $numsave = intval($tabmatches[1]); |
|
| 768 | + |
|
| 769 | + $gzfiles[$numsave] = $gzfile; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + krsort($gzfiles, SORT_NUMERIC); |
|
| 773 | + |
|
| 774 | + foreach($gzfiles as $numsave => $dummy) { |
|
| 775 | + if (dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) { |
|
| 776 | + return -2; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + if($numsave >= $nbSaves) { |
|
| 780 | + dol_delete_file($logpath.'/'.$logname.'.'.$numsave.'.gz', 0, 0, 0, null, false, 0); |
|
| 781 | + } else { |
|
| 782 | + dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave+1).'.gz', 0, 1, 0, 0); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // Compress current file and recreate it |
|
| 787 | + |
|
| 788 | + if ($nbSaves > 0) { // If $nbSaves is 1, we keep 1 archive .gz file, If 2, we keep 2 .gz files |
|
| 789 | + $gzfilehandle = gzopen($logpath.'/'.$logname.'.1.gz', 'wb9'); |
|
| 790 | + |
|
| 791 | + if (empty($gzfilehandle)) { |
|
| 792 | + $this->error = 'Failted to open file '.$logpath.'/'.$logname.'.1.gz'; |
|
| 793 | + return -3; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + $sourcehandle = fopen($logpath.'/'.$logname, 'r'); |
|
| 797 | + |
|
| 798 | + if (empty($sourcehandle)) { |
|
| 799 | + $this->error = 'Failed to open file '.$logpath.'/'.$logname; |
|
| 800 | + return -4; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + while(! feof($sourcehandle)) { |
|
| 804 | + gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024)); // Read 512 kB at a time |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + fclose($sourcehandle); |
|
| 808 | + gzclose($gzfilehandle); |
|
| 809 | + |
|
| 810 | + @chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + dol_delete_file($logpath.'/'.$logname, 0, 0, 0, null, false, 0); |
|
| 814 | + |
|
| 815 | + // Create empty file |
|
| 816 | + $newlog = fopen($logpath.'/'.$logname, 'a+'); |
|
| 817 | + fclose($newlog); |
|
| 818 | + |
|
| 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)); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + $this->output = 'Archive log files (keeping last SYSLOG_FILE_SAVES='.$nbSaves.' files) done.'; |
|
| 825 | + return 0; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + /** Backup the db OR just a table without mysqldump binary, with PHP only (does not require any exec permission) |
|
| 829 | + * Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php) |
|
| 830 | + * Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog |
|
| 831 | + * Note about foreign keys constraints: for Dolibarr, since there are a lot of constraints and when imported the tables will be inserted in the dumped order, not in constraints order, then we ABSOLUTELY need to use SET FOREIGN_KEY_CHECKS=0; when importing the sql dump. |
|
| 832 | + * Note2: db2SQL by Howard Yeend can be an alternative, by using SHOW FIELDS FROM and SHOW KEYS FROM we could generate a more precise dump (eg: by getting the type of the field and then precisely outputting the right formatting - in quotes, numeric or null - instead of trying to guess like we are doing now). |
|
| 833 | + * |
|
| 834 | + * @param string $outputfile Output file name |
|
| 835 | + * @param string $tables Table name or '*' for all |
|
| 836 | + * @return int <0 if KO, >0 if OK |
|
| 837 | + */ |
|
| 838 | + function backupTables($outputfile, $tables='*') |
|
| 839 | + { |
|
| 840 | + global $db, $langs; |
|
| 841 | + global $errormsg; |
|
| 842 | + |
|
| 843 | + // Set to UTF-8 |
|
| 844 | + if (is_a($db, 'DoliDBMysqli')) { |
|
| 845 | + /** @var DoliDBMysqli $db */ |
|
| 846 | + $db->db->set_charset('utf8'); |
|
| 847 | + } else { |
|
| 848 | + /** @var DoliDB $db */ |
|
| 849 | + $db->query('SET NAMES utf8'); |
|
| 850 | + $db->query('SET CHARACTER SET utf8'); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + //get all of the tables |
|
| 854 | + if ($tables == '*') |
|
| 855 | + { |
|
| 856 | + $tables = array(); |
|
| 857 | + $result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\''); |
|
| 858 | + while($row = $db->fetch_row($result)) |
|
| 859 | + { |
|
| 860 | + $tables[] = $row[0]; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + else |
|
| 864 | + { |
|
| 865 | + $tables = is_array($tables) ? $tables : explode(',',$tables); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + //cycle through |
|
| 869 | + $handle = fopen($outputfile, 'w+'); |
|
| 870 | + if (fwrite($handle, '') === false) |
|
| 871 | + { |
|
| 872 | + $langs->load("errors"); |
|
| 873 | + dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 874 | + $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 875 | + return -1; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + // Print headers and global mysql config vars |
|
| 879 | + $sqlhead = ''; |
|
| 880 | + $sqlhead .= "-- ".$db::LABEL." dump via php with Dolibarr ".DOL_VERSION." |
|
| 881 | 881 | -- |
| 882 | 882 | -- Host: ".$db->db->host_info." Database: ".$db->database_name." |
| 883 | 883 | -- ------------------------------------------------------ |
@@ -896,77 +896,77 @@ discard block |
||
| 896 | 896 | |
| 897 | 897 | "; |
| 898 | 898 | |
| 899 | - if (GETPOST("nobin_disable_fk")) $sqlhead .= "SET FOREIGN_KEY_CHECKS=0;\n"; |
|
| 900 | - //$sqlhead .= "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\n"; |
|
| 901 | - if (GETPOST("nobin_use_transaction")) $sqlhead .= "SET AUTOCOMMIT=0;\nSTART TRANSACTION;\n"; |
|
| 902 | - |
|
| 903 | - fwrite($handle, $sqlhead); |
|
| 904 | - |
|
| 905 | - $ignore = ''; |
|
| 906 | - if (GETPOST("nobin_sql_ignore")) $ignore = 'IGNORE '; |
|
| 907 | - $delayed = ''; |
|
| 908 | - if (GETPOST("nobin_delayed")) $delayed = 'DELAYED '; |
|
| 909 | - |
|
| 910 | - // Process each table and print their definition + their datas |
|
| 911 | - foreach($tables as $table) |
|
| 912 | - { |
|
| 913 | - // Saving the table structure |
|
| 914 | - fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n"); |
|
| 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); |
|
| 920 | - $row2 = $db->fetch_row($resqldrop); |
|
| 921 | - if (empty($row2[1])) |
|
| 922 | - { |
|
| 923 | - fwrite($handle, "\n-- WARNING: Show create table ".$table." return empy string when it should not.\n"); |
|
| 924 | - } |
|
| 925 | - else |
|
| 926 | - { |
|
| 927 | - fwrite($handle,$row2[1].";\n"); |
|
| 928 | - //fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n"); |
|
| 929 | - |
|
| 930 | - // Dumping the data (locking the table and disabling the keys check while doing the process) |
|
| 931 | - fwrite($handle, "\n--\n-- Dumping data for table `".$table."`\n--\n"); |
|
| 932 | - if (!GETPOST("nobin_nolocks")) fwrite($handle, "LOCK TABLES `".$table."` WRITE;\n"); // Lock the table before inserting data (when the data will be imported back) |
|
| 933 | - if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n"); |
|
| 934 | - else fwrite($handle, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n"); |
|
| 935 | - |
|
| 936 | - $sql='SELECT * FROM '.$table; |
|
| 937 | - $result = $db->query($sql); |
|
| 938 | - while($row = $db->fetch_row($result)) |
|
| 939 | - { |
|
| 940 | - // For each row of data we print a line of INSERT |
|
| 941 | - fwrite($handle,'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES ('); |
|
| 942 | - $columns = count($row); |
|
| 943 | - for($j=0; $j<$columns; $j++) { |
|
| 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 | - if ($row[$j] == null && !is_string($row[$j])) { |
|
| 946 | - // IMPORTANT: if the field is NULL we set it NULL |
|
| 947 | - $row[$j] = 'NULL'; |
|
| 948 | - } elseif(is_string($row[$j]) && $row[$j] == '') { |
|
| 949 | - // if it's an empty string, we set it as an empty string |
|
| 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) |
|
| 952 | - // if it's a number, we return it as-is |
|
| 953 | - // $row[$j] = $row[$j]; |
|
| 954 | - } else { // else for all other cases we escape the value and put quotes around |
|
| 955 | - $row[$j] = addslashes($row[$j]); |
|
| 956 | - $row[$j] = preg_replace("#\n#", "\\n", $row[$j]); |
|
| 957 | - $row[$j] = "'".$row[$j]."'"; |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - fwrite($handle,implode(',', $row).");\n"); |
|
| 961 | - } |
|
| 962 | - if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking |
|
| 963 | - if (!GETPOST("nobin_nolocks")) fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table |
|
| 964 | - fwrite($handle,"\n\n\n"); |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /* Backup Procedure structure*/ |
|
| 969 | - /* |
|
| 899 | + if (GETPOST("nobin_disable_fk")) $sqlhead .= "SET FOREIGN_KEY_CHECKS=0;\n"; |
|
| 900 | + //$sqlhead .= "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\n"; |
|
| 901 | + if (GETPOST("nobin_use_transaction")) $sqlhead .= "SET AUTOCOMMIT=0;\nSTART TRANSACTION;\n"; |
|
| 902 | + |
|
| 903 | + fwrite($handle, $sqlhead); |
|
| 904 | + |
|
| 905 | + $ignore = ''; |
|
| 906 | + if (GETPOST("nobin_sql_ignore")) $ignore = 'IGNORE '; |
|
| 907 | + $delayed = ''; |
|
| 908 | + if (GETPOST("nobin_delayed")) $delayed = 'DELAYED '; |
|
| 909 | + |
|
| 910 | + // Process each table and print their definition + their datas |
|
| 911 | + foreach($tables as $table) |
|
| 912 | + { |
|
| 913 | + // Saving the table structure |
|
| 914 | + fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n"); |
|
| 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); |
|
| 920 | + $row2 = $db->fetch_row($resqldrop); |
|
| 921 | + if (empty($row2[1])) |
|
| 922 | + { |
|
| 923 | + fwrite($handle, "\n-- WARNING: Show create table ".$table." return empy string when it should not.\n"); |
|
| 924 | + } |
|
| 925 | + else |
|
| 926 | + { |
|
| 927 | + fwrite($handle,$row2[1].";\n"); |
|
| 928 | + //fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n"); |
|
| 929 | + |
|
| 930 | + // Dumping the data (locking the table and disabling the keys check while doing the process) |
|
| 931 | + fwrite($handle, "\n--\n-- Dumping data for table `".$table."`\n--\n"); |
|
| 932 | + if (!GETPOST("nobin_nolocks")) fwrite($handle, "LOCK TABLES `".$table."` WRITE;\n"); // Lock the table before inserting data (when the data will be imported back) |
|
| 933 | + if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n"); |
|
| 934 | + else fwrite($handle, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n"); |
|
| 935 | + |
|
| 936 | + $sql='SELECT * FROM '.$table; |
|
| 937 | + $result = $db->query($sql); |
|
| 938 | + while($row = $db->fetch_row($result)) |
|
| 939 | + { |
|
| 940 | + // For each row of data we print a line of INSERT |
|
| 941 | + fwrite($handle,'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES ('); |
|
| 942 | + $columns = count($row); |
|
| 943 | + for($j=0; $j<$columns; $j++) { |
|
| 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 | + if ($row[$j] == null && !is_string($row[$j])) { |
|
| 946 | + // IMPORTANT: if the field is NULL we set it NULL |
|
| 947 | + $row[$j] = 'NULL'; |
|
| 948 | + } elseif(is_string($row[$j]) && $row[$j] == '') { |
|
| 949 | + // if it's an empty string, we set it as an empty string |
|
| 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) |
|
| 952 | + // if it's a number, we return it as-is |
|
| 953 | + // $row[$j] = $row[$j]; |
|
| 954 | + } else { // else for all other cases we escape the value and put quotes around |
|
| 955 | + $row[$j] = addslashes($row[$j]); |
|
| 956 | + $row[$j] = preg_replace("#\n#", "\\n", $row[$j]); |
|
| 957 | + $row[$j] = "'".$row[$j]."'"; |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + fwrite($handle,implode(',', $row).");\n"); |
|
| 961 | + } |
|
| 962 | + if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking |
|
| 963 | + if (!GETPOST("nobin_nolocks")) fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table |
|
| 964 | + fwrite($handle,"\n\n\n"); |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /* Backup Procedure structure*/ |
|
| 969 | + /* |
|
| 970 | 970 | $result = $db->query('SHOW PROCEDURE STATUS'); |
| 971 | 971 | if ($db->num_rows($result) > 0) |
| 972 | 972 | { |
@@ -982,17 +982,17 @@ discard block |
||
| 982 | 982 | } |
| 983 | 983 | } |
| 984 | 984 | */ |
| 985 | - /* Backup Procedure structure*/ |
|
| 985 | + /* Backup Procedure structure*/ |
|
| 986 | 986 | |
| 987 | - // Write the footer (restore the previous database settings) |
|
| 988 | - $sqlfooter="\n\n"; |
|
| 989 | - if (GETPOST("nobin_use_transaction")) $sqlfooter .= "COMMIT;\n"; |
|
| 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'); |
|
| 992 | - fwrite($handle, $sqlfooter); |
|
| 987 | + // Write the footer (restore the previous database settings) |
|
| 988 | + $sqlfooter="\n\n"; |
|
| 989 | + if (GETPOST("nobin_use_transaction")) $sqlfooter .= "COMMIT;\n"; |
|
| 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'); |
|
| 992 | + fwrite($handle, $sqlfooter); |
|
| 993 | 993 | |
| 994 | - fclose($handle); |
|
| 994 | + fclose($handle); |
|
| 995 | 995 | |
| 996 | - return 1; |
|
| 997 | - } |
|
| 996 | + return 1; |
|
| 997 | + } |
|
| 998 | 998 | } |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | public $db; |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * @var string Error code (or message) |
|
| 37 | - */ |
|
| 38 | - public $error=''; |
|
| 36 | + * @var string Error code (or message) |
|
| 37 | + */ |
|
| 38 | + public $error=''; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -50,135 +50,135 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 53 | - /** |
|
| 54 | - * Show a combo list with contracts qualified for a third party |
|
| 55 | - * |
|
| 56 | - * @param int $socid Id third party (-1=all, 0=only contracts not linked to a third party, id=contracts not linked or linked to third party id) |
|
| 57 | - * @param int $selected Id contract preselected |
|
| 58 | - * @param string $htmlname Nom de la zone html |
|
| 59 | - * @param int $maxlength Maximum length of label |
|
| 60 | - * @param int $showempty Show empty line |
|
| 61 | - * @return int Nbr of project if OK, <0 if KO |
|
| 62 | - */ |
|
| 63 | - function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1) |
|
| 64 | - { |
|
| 53 | + /** |
|
| 54 | + * Show a combo list with contracts qualified for a third party |
|
| 55 | + * |
|
| 56 | + * @param int $socid Id third party (-1=all, 0=only contracts not linked to a third party, id=contracts not linked or linked to third party id) |
|
| 57 | + * @param int $selected Id contract preselected |
|
| 58 | + * @param string $htmlname Nom de la zone html |
|
| 59 | + * @param int $maxlength Maximum length of label |
|
| 60 | + * @param int $showempty Show empty line |
|
| 61 | + * @return int Nbr of project if OK, <0 if KO |
|
| 62 | + */ |
|
| 63 | + function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1) |
|
| 64 | + { |
|
| 65 | 65 | // phpcs:enable |
| 66 | - global $db,$user,$conf,$langs; |
|
| 66 | + global $db,$user,$conf,$langs; |
|
| 67 | 67 | |
| 68 | - $hideunselectables = false; |
|
| 69 | - if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true; |
|
| 68 | + $hideunselectables = false; |
|
| 69 | + if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true; |
|
| 70 | 70 | |
| 71 | - // Search all contacts |
|
| 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; |
|
| 75 | - //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")"; |
|
| 76 | - if ($socid > 0) |
|
| 77 | - { |
|
| 78 | - // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma. |
|
| 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)"; |
|
| 81 | - else if ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') |
|
| 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)"; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)"; |
|
| 88 | - $sql.= " ORDER BY c.ref "; |
|
| 71 | + // Search all contacts |
|
| 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; |
|
| 75 | + //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")"; |
|
| 76 | + if ($socid > 0) |
|
| 77 | + { |
|
| 78 | + // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma. |
|
| 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)"; |
|
| 81 | + else if ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') |
|
| 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)"; |
|
| 85 | + } |
|
| 86 | + } |
|
| 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 | - dol_syslog(get_class($this)."::select_contract", LOG_DEBUG); |
|
| 91 | - $resql=$db->query($sql); |
|
| 92 | - if ($resql) |
|
| 93 | - { |
|
| 94 | - print '<select class="flat" name="'.$htmlname.'">'; |
|
| 95 | - if ($showempty) print '<option value="0"> </option>'; |
|
| 96 | - $num = $db->num_rows($resql); |
|
| 97 | - $i = 0; |
|
| 98 | - if ($num) |
|
| 99 | - { |
|
| 100 | - while ($i < $num) |
|
| 101 | - { |
|
| 102 | - $obj = $db->fetch_object($resql); |
|
| 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) |
|
| 105 | - { |
|
| 106 | - // Do nothing |
|
| 107 | - } |
|
| 108 | - else |
|
| 109 | - { |
|
| 110 | - $labeltoshow=dol_trunc($obj->ref,18); |
|
| 111 | - //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; |
|
| 112 | - //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
|
| 113 | - if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
|
| 114 | - { |
|
| 115 | - print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 116 | - } |
|
| 117 | - else |
|
| 118 | - { |
|
| 119 | - $disabled=0; |
|
| 120 | - if ( $obj->statut == 0) |
|
| 121 | - { |
|
| 122 | - $disabled=1; |
|
| 123 | - $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 124 | - } |
|
| 125 | - if ( empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 126 | - { |
|
| 127 | - $disabled=1; |
|
| 128 | - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 129 | - } |
|
| 90 | + dol_syslog(get_class($this)."::select_contract", LOG_DEBUG); |
|
| 91 | + $resql=$db->query($sql); |
|
| 92 | + if ($resql) |
|
| 93 | + { |
|
| 94 | + print '<select class="flat" name="'.$htmlname.'">'; |
|
| 95 | + if ($showempty) print '<option value="0"> </option>'; |
|
| 96 | + $num = $db->num_rows($resql); |
|
| 97 | + $i = 0; |
|
| 98 | + if ($num) |
|
| 99 | + { |
|
| 100 | + while ($i < $num) |
|
| 101 | + { |
|
| 102 | + $obj = $db->fetch_object($resql); |
|
| 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) |
|
| 105 | + { |
|
| 106 | + // Do nothing |
|
| 107 | + } |
|
| 108 | + else |
|
| 109 | + { |
|
| 110 | + $labeltoshow=dol_trunc($obj->ref,18); |
|
| 111 | + //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; |
|
| 112 | + //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
|
| 113 | + if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
|
| 114 | + { |
|
| 115 | + print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 116 | + } |
|
| 117 | + else |
|
| 118 | + { |
|
| 119 | + $disabled=0; |
|
| 120 | + if ( $obj->statut == 0) |
|
| 121 | + { |
|
| 122 | + $disabled=1; |
|
| 123 | + $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 124 | + } |
|
| 125 | + if ( empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 126 | + { |
|
| 127 | + $disabled=1; |
|
| 128 | + $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - if ($hideunselectables && $disabled) |
|
| 132 | - { |
|
| 133 | - $resultat=''; |
|
| 134 | - } |
|
| 135 | - else |
|
| 136 | - { |
|
| 137 | - $resultat='<option value="'.$obj->rowid.'"'; |
|
| 138 | - if ($disabled) $resultat.=' disabled'; |
|
| 139 | - //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; |
|
| 140 | - //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
|
| 141 | - $resultat.='>'.$labeltoshow; |
|
| 142 | - $resultat.='</option>'; |
|
| 143 | - } |
|
| 144 | - print $resultat; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $i++; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - print '</select>'; |
|
| 151 | - $db->free($resql); |
|
| 131 | + if ($hideunselectables && $disabled) |
|
| 132 | + { |
|
| 133 | + $resultat=''; |
|
| 134 | + } |
|
| 135 | + else |
|
| 136 | + { |
|
| 137 | + $resultat='<option value="'.$obj->rowid.'"'; |
|
| 138 | + if ($disabled) $resultat.=' disabled'; |
|
| 139 | + //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; |
|
| 140 | + //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
|
| 141 | + $resultat.='>'.$labeltoshow; |
|
| 142 | + $resultat.='</option>'; |
|
| 143 | + } |
|
| 144 | + print $resultat; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $i++; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + print '</select>'; |
|
| 151 | + $db->free($resql); |
|
| 152 | 152 | |
| 153 | - if (!empty($conf->use_javascript_ajax)) |
|
| 154 | - { |
|
| 155 | - // Make select dynamic |
|
| 156 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 157 | - print ajax_combobox($htmlname); |
|
| 158 | - } |
|
| 153 | + if (!empty($conf->use_javascript_ajax)) |
|
| 154 | + { |
|
| 155 | + // Make select dynamic |
|
| 156 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 157 | + print ajax_combobox($htmlname); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - return $num; |
|
| 161 | - } |
|
| 162 | - else |
|
| 163 | - { |
|
| 164 | - dol_print_error($db); |
|
| 165 | - return -1; |
|
| 166 | - } |
|
| 167 | - } |
|
| 160 | + return $num; |
|
| 161 | + } |
|
| 162 | + else |
|
| 163 | + { |
|
| 164 | + dol_print_error($db); |
|
| 165 | + return -1; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Show a form to select a contract |
|
| 171 | - * |
|
| 172 | - * @param int $page Page |
|
| 173 | - * @param int $socid Id third party (-1=all, 0=only contracts not linked to a third party, id=contracts not linked or linked to third party id) |
|
| 174 | - * @param int $selected Id contract preselected |
|
| 175 | - * @param string $htmlname Nom de la zone html |
|
| 176 | - * @param int $maxlength Maximum length of label |
|
| 177 | - * @param int $showempty Show empty line |
|
| 178 | - * @return int Nbr of project if OK, <0 if KO |
|
| 179 | - */ |
|
| 180 | - function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1) |
|
| 181 | - { |
|
| 169 | + /** |
|
| 170 | + * Show a form to select a contract |
|
| 171 | + * |
|
| 172 | + * @param int $page Page |
|
| 173 | + * @param int $socid Id third party (-1=all, 0=only contracts not linked to a third party, id=contracts not linked or linked to third party id) |
|
| 174 | + * @param int $selected Id contract preselected |
|
| 175 | + * @param string $htmlname Nom de la zone html |
|
| 176 | + * @param int $maxlength Maximum length of label |
|
| 177 | + * @param int $showempty Show empty line |
|
| 178 | + * @return int Nbr of project if OK, <0 if KO |
|
| 179 | + */ |
|
| 180 | + function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1) |
|
| 181 | + { |
|
| 182 | 182 | global $langs; |
| 183 | 183 | |
| 184 | 184 | print "\n"; |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | public $db; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * @var string Error code (or message) |
|
| 38 | - */ |
|
| 39 | - public $error=''; |
|
| 37 | + * @var string Error code (or message) |
|
| 38 | + */ |
|
| 39 | + public $error=''; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -51,234 +51,234 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * get array with margin information from lines of object |
|
| 56 | - * TODO Move this in common class. |
|
| 57 | - * |
|
| 58 | - * @param CommonObject $object Object we want to get margin information for |
|
| 59 | - * @param boolean $force_price True of not |
|
| 60 | - * @return array Array with info |
|
| 61 | - */ |
|
| 62 | - function getMarginInfosArray($object, $force_price=false) |
|
| 63 | - { |
|
| 64 | - global $conf, $db; |
|
| 54 | + /** |
|
| 55 | + * get array with margin information from lines of object |
|
| 56 | + * TODO Move this in common class. |
|
| 57 | + * |
|
| 58 | + * @param CommonObject $object Object we want to get margin information for |
|
| 59 | + * @param boolean $force_price True of not |
|
| 60 | + * @return array Array with info |
|
| 61 | + */ |
|
| 62 | + function getMarginInfosArray($object, $force_price=false) |
|
| 63 | + { |
|
| 64 | + global $conf, $db; |
|
| 65 | 65 | |
| 66 | - // Default returned array |
|
| 67 | - $marginInfos = array( |
|
| 68 | - 'pa_products' => 0, |
|
| 69 | - 'pv_products' => 0, |
|
| 70 | - 'margin_on_products' => 0, |
|
| 71 | - 'margin_rate_products' => '', |
|
| 72 | - 'mark_rate_products' => '', |
|
| 73 | - 'pa_services' => 0, |
|
| 74 | - 'pv_services' => 0, |
|
| 75 | - 'margin_on_services' => 0, |
|
| 76 | - 'margin_rate_services' => '', |
|
| 77 | - 'mark_rate_services' => '', |
|
| 78 | - 'pa_total' => 0, |
|
| 79 | - 'pv_total' => 0, |
|
| 80 | - 'total_margin' => 0, |
|
| 81 | - 'total_margin_rate' => '', |
|
| 82 | - 'total_mark_rate' => '' |
|
| 83 | - ); |
|
| 66 | + // Default returned array |
|
| 67 | + $marginInfos = array( |
|
| 68 | + 'pa_products' => 0, |
|
| 69 | + 'pv_products' => 0, |
|
| 70 | + 'margin_on_products' => 0, |
|
| 71 | + 'margin_rate_products' => '', |
|
| 72 | + 'mark_rate_products' => '', |
|
| 73 | + 'pa_services' => 0, |
|
| 74 | + 'pv_services' => 0, |
|
| 75 | + 'margin_on_services' => 0, |
|
| 76 | + 'margin_rate_services' => '', |
|
| 77 | + 'mark_rate_services' => '', |
|
| 78 | + 'pa_total' => 0, |
|
| 79 | + 'pv_total' => 0, |
|
| 80 | + 'total_margin' => 0, |
|
| 81 | + 'total_margin_rate' => '', |
|
| 82 | + 'total_mark_rate' => '' |
|
| 83 | + ); |
|
| 84 | 84 | |
| 85 | - foreach($object->lines as $line) |
|
| 86 | - { |
|
| 87 | - if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) |
|
| 88 | - { |
|
| 89 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
| 90 | - $product = new ProductFournisseur($db); |
|
| 91 | - if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) |
|
| 92 | - $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); |
|
| 93 | - } |
|
| 94 | - // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente |
|
| 95 | - if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { |
|
| 96 | - $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100)); |
|
| 97 | - } |
|
| 85 | + foreach($object->lines as $line) |
|
| 86 | + { |
|
| 87 | + if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) |
|
| 88 | + { |
|
| 89 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
| 90 | + $product = new ProductFournisseur($db); |
|
| 91 | + if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) |
|
| 92 | + $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); |
|
| 93 | + } |
|
| 94 | + // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente |
|
| 95 | + if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { |
|
| 96 | + $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100)); |
|
| 97 | + } |
|
| 98 | 98 | |
| 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 |
|
| 101 | - $pa = $line->qty * $pa_ht; |
|
| 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 |
|
| 101 | + $pa = $line->qty * $pa_ht; |
|
| 102 | 102 | |
| 103 | - // calcul des marges |
|
| 104 | - if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise |
|
| 105 | - if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit |
|
| 106 | - $marginInfos['pa_products'] += $pa; |
|
| 107 | - $marginInfos['pv_products'] += $pv; |
|
| 108 | - $marginInfos['pa_total'] += $pa; |
|
| 109 | - $marginInfos['pv_total'] += $pv; |
|
| 110 | - // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 111 | - //if ($pv < 0) |
|
| 112 | - //{ |
|
| 113 | - // $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); |
|
| 114 | - //} |
|
| 115 | - //else |
|
| 116 | - $marginInfos['margin_on_products'] += $pv - $pa; |
|
| 117 | - } |
|
| 118 | - elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service |
|
| 119 | - $marginInfos['pa_services'] += $pa; |
|
| 120 | - $marginInfos['pv_services'] += $pv; |
|
| 121 | - $marginInfos['pa_total'] += $pa; |
|
| 122 | - $marginInfos['pv_total'] += $pv; |
|
| 123 | - // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 124 | - //if ($pv < 0) |
|
| 125 | - // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
|
| 126 | - //else |
|
| 127 | - $marginInfos['margin_on_services'] += $pv - $pa; |
|
| 128 | - } |
|
| 129 | - elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total |
|
| 130 | - $marginInfos['pa_total'] += $pa; |
|
| 131 | - $marginInfos['pv_total'] += $pv; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - else { |
|
| 135 | - $type=$line->product_type?$line->product_type:$line->fk_product_type; |
|
| 136 | - if ($type == 0) { // product |
|
| 137 | - $marginInfos['pa_products'] += $pa; |
|
| 138 | - $marginInfos['pv_products'] += $pv; |
|
| 139 | - $marginInfos['pa_total'] += $pa; |
|
| 140 | - $marginInfos['pv_total'] += $pv; |
|
| 141 | - // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 142 | - //if ($pv < 0) |
|
| 143 | - //{ |
|
| 144 | - // $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); |
|
| 145 | - //} |
|
| 146 | - //else |
|
| 147 | - //{ |
|
| 148 | - $marginInfos['margin_on_products'] += $pv - $pa; |
|
| 149 | - //} |
|
| 150 | - } |
|
| 151 | - elseif ($type == 1) { // service |
|
| 152 | - $marginInfos['pa_services'] += $pa; |
|
| 153 | - $marginInfos['pv_services'] += $pv; |
|
| 154 | - $marginInfos['pa_total'] += $pa; |
|
| 155 | - $marginInfos['pv_total'] += $pv; |
|
| 156 | - // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 157 | - //if ($pv < 0) |
|
| 158 | - // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
|
| 159 | - //else |
|
| 160 | - $marginInfos['margin_on_services'] += $pv - $pa; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - if ($marginInfos['pa_products'] > 0) |
|
| 165 | - $marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products']; |
|
| 166 | - if ($marginInfos['pv_products'] > 0) |
|
| 167 | - $marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products']; |
|
| 103 | + // calcul des marges |
|
| 104 | + if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise |
|
| 105 | + if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit |
|
| 106 | + $marginInfos['pa_products'] += $pa; |
|
| 107 | + $marginInfos['pv_products'] += $pv; |
|
| 108 | + $marginInfos['pa_total'] += $pa; |
|
| 109 | + $marginInfos['pv_total'] += $pv; |
|
| 110 | + // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 111 | + //if ($pv < 0) |
|
| 112 | + //{ |
|
| 113 | + // $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); |
|
| 114 | + //} |
|
| 115 | + //else |
|
| 116 | + $marginInfos['margin_on_products'] += $pv - $pa; |
|
| 117 | + } |
|
| 118 | + elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service |
|
| 119 | + $marginInfos['pa_services'] += $pa; |
|
| 120 | + $marginInfos['pv_services'] += $pv; |
|
| 121 | + $marginInfos['pa_total'] += $pa; |
|
| 122 | + $marginInfos['pv_total'] += $pv; |
|
| 123 | + // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 124 | + //if ($pv < 0) |
|
| 125 | + // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
|
| 126 | + //else |
|
| 127 | + $marginInfos['margin_on_services'] += $pv - $pa; |
|
| 128 | + } |
|
| 129 | + elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total |
|
| 130 | + $marginInfos['pa_total'] += $pa; |
|
| 131 | + $marginInfos['pv_total'] += $pv; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + else { |
|
| 135 | + $type=$line->product_type?$line->product_type:$line->fk_product_type; |
|
| 136 | + if ($type == 0) { // product |
|
| 137 | + $marginInfos['pa_products'] += $pa; |
|
| 138 | + $marginInfos['pv_products'] += $pv; |
|
| 139 | + $marginInfos['pa_total'] += $pa; |
|
| 140 | + $marginInfos['pv_total'] += $pv; |
|
| 141 | + // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 142 | + //if ($pv < 0) |
|
| 143 | + //{ |
|
| 144 | + // $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); |
|
| 145 | + //} |
|
| 146 | + //else |
|
| 147 | + //{ |
|
| 148 | + $marginInfos['margin_on_products'] += $pv - $pa; |
|
| 149 | + //} |
|
| 150 | + } |
|
| 151 | + elseif ($type == 1) { // service |
|
| 152 | + $marginInfos['pa_services'] += $pa; |
|
| 153 | + $marginInfos['pv_services'] += $pv; |
|
| 154 | + $marginInfos['pa_total'] += $pa; |
|
| 155 | + $marginInfos['pv_total'] += $pv; |
|
| 156 | + // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 157 | + //if ($pv < 0) |
|
| 158 | + // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
|
| 159 | + //else |
|
| 160 | + $marginInfos['margin_on_services'] += $pv - $pa; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + if ($marginInfos['pa_products'] > 0) |
|
| 165 | + $marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products']; |
|
| 166 | + if ($marginInfos['pv_products'] > 0) |
|
| 167 | + $marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products']; |
|
| 168 | 168 | |
| 169 | - if ($marginInfos['pa_services'] > 0) |
|
| 170 | - $marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services']; |
|
| 171 | - if ($marginInfos['pv_services'] > 0) |
|
| 172 | - $marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services']; |
|
| 169 | + if ($marginInfos['pa_services'] > 0) |
|
| 170 | + $marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services']; |
|
| 171 | + if ($marginInfos['pv_services'] > 0) |
|
| 172 | + $marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services']; |
|
| 173 | 173 | |
| 174 | - // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 175 | - //if ($marginInfos['pv_total'] < 0) |
|
| 176 | - // $marginInfos['total_margin'] = -1 * (abs($marginInfos['pv_total']) - $marginInfos['pa_total']); |
|
| 177 | - //else |
|
| 178 | - $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total']; |
|
| 179 | - if ($marginInfos['pa_total'] > 0) |
|
| 180 | - $marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total']; |
|
| 181 | - if ($marginInfos['pv_total'] > 0) |
|
| 182 | - $marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total']; |
|
| 174 | + // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
|
| 175 | + //if ($marginInfos['pv_total'] < 0) |
|
| 176 | + // $marginInfos['total_margin'] = -1 * (abs($marginInfos['pv_total']) - $marginInfos['pa_total']); |
|
| 177 | + //else |
|
| 178 | + $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total']; |
|
| 179 | + if ($marginInfos['pa_total'] > 0) |
|
| 180 | + $marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total']; |
|
| 181 | + if ($marginInfos['pv_total'] > 0) |
|
| 182 | + $marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total']; |
|
| 183 | 183 | |
| 184 | - return $marginInfos; |
|
| 185 | - } |
|
| 184 | + return $marginInfos; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Show the array with all margin infos |
|
| 189 | - * |
|
| 190 | - * @param CommonObject $object Object we want to get margin information for |
|
| 191 | - * @param boolean $force_price Force price |
|
| 192 | - * @return void |
|
| 193 | - */ |
|
| 194 | - function displayMarginInfos($object, $force_price=false) |
|
| 195 | - { |
|
| 196 | - global $langs, $conf, $user; |
|
| 187 | + /** |
|
| 188 | + * Show the array with all margin infos |
|
| 189 | + * |
|
| 190 | + * @param CommonObject $object Object we want to get margin information for |
|
| 191 | + * @param boolean $force_price Force price |
|
| 192 | + * @return void |
|
| 193 | + */ |
|
| 194 | + function displayMarginInfos($object, $force_price=false) |
|
| 195 | + { |
|
| 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 | - $marginInfo = $this->getMarginInfosArray($object, $force_price); |
|
| 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 |
|
| 207 | - { |
|
| 208 | - print $langs->trans('ShowMarginInfos').' : '; |
|
| 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>'; |
|
| 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 | + { |
|
| 208 | + print $langs->trans('ShowMarginInfos').' : '; |
|
| 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>'; |
|
| 212 | 212 | |
| 213 | - print '<script>$(document).ready(function() { |
|
| 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");})}); |
| 215 | 215 | $("span#hideMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 1); $(".margininfos").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject");})}); |
| 216 | 216 | });</script>'; |
| 217 | - if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
| 218 | - } |
|
| 217 | + if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - print '<div class="div-table-responsive-no-min">'; |
|
| 221 | - print '<!-- Margin table -->'."\n"; |
|
| 220 | + print '<div class="div-table-responsive-no-min">'; |
|
| 221 | + print '<!-- Margin table -->'."\n"; |
|
| 222 | 222 | |
| 223 | - print '<table class="noborder margintable centpercent">'; |
|
| 224 | - print '<tr class="liste_titre">'; |
|
| 225 | - print '<td class="liste_titre">'.$langs->trans('Margins').'</td>'; |
|
| 226 | - print '<td class="liste_titre" align="right">'.$langs->trans('SellingPrice').'</td>'; |
|
| 227 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 228 | - print '<td class="liste_titre" align="right">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 229 | - else |
|
| 230 | - print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>'; |
|
| 231 | - print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>'; |
|
| 232 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 233 | - print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>'; |
|
| 234 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 235 | - print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>'; |
|
| 236 | - print '</tr>'; |
|
| 223 | + print '<table class="noborder margintable centpercent">'; |
|
| 224 | + print '<tr class="liste_titre">'; |
|
| 225 | + print '<td class="liste_titre">'.$langs->trans('Margins').'</td>'; |
|
| 226 | + print '<td class="liste_titre" align="right">'.$langs->trans('SellingPrice').'</td>'; |
|
| 227 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 228 | + print '<td class="liste_titre" align="right">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 229 | + else |
|
| 230 | + print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>'; |
|
| 231 | + print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>'; |
|
| 232 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 233 | + print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>'; |
|
| 234 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 235 | + print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>'; |
|
| 236 | + print '</tr>'; |
|
| 237 | 237 | |
| 238 | - if (! empty($conf->product->enabled)) |
|
| 239 | - { |
|
| 240 | - //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { |
|
| 241 | - print '<tr class="oddeven">'; |
|
| 242 | - print '<td>'.$langs->trans('MarginOnProducts').'</td>'; |
|
| 243 | - print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>'; |
|
| 244 | - print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>'; |
|
| 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>'; |
|
| 250 | - print '</tr>'; |
|
| 251 | - } |
|
| 238 | + if (! empty($conf->product->enabled)) |
|
| 239 | + { |
|
| 240 | + //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { |
|
| 241 | + print '<tr class="oddeven">'; |
|
| 242 | + print '<td>'.$langs->trans('MarginOnProducts').'</td>'; |
|
| 243 | + print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>'; |
|
| 244 | + print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>'; |
|
| 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>'; |
|
| 250 | + print '</tr>'; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - if (! empty($conf->service->enabled)) |
|
| 254 | - { |
|
| 255 | - print '<tr class="oddeven">'; |
|
| 256 | - print '<td>'.$langs->trans('MarginOnServices').'</td>'; |
|
| 257 | - print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>'; |
|
| 258 | - print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>'; |
|
| 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>'; |
|
| 264 | - print '</tr>'; |
|
| 265 | - } |
|
| 253 | + if (! empty($conf->service->enabled)) |
|
| 254 | + { |
|
| 255 | + print '<tr class="oddeven">'; |
|
| 256 | + print '<td>'.$langs->trans('MarginOnServices').'</td>'; |
|
| 257 | + print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>'; |
|
| 258 | + print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>'; |
|
| 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>'; |
|
| 264 | + print '</tr>'; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) |
|
| 268 | - { |
|
| 269 | - print '<tr class="liste_total">'; |
|
| 270 | - print '<td>'.$langs->trans('TotalMargin').'</td>'; |
|
| 271 | - print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>'; |
|
| 272 | - print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>'; |
|
| 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>'; |
|
| 278 | - print '</tr>'; |
|
| 279 | - } |
|
| 280 | - print '</table>'; |
|
| 281 | - print '</div>'; |
|
| 282 | - } |
|
| 267 | + if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) |
|
| 268 | + { |
|
| 269 | + print '<tr class="liste_total">'; |
|
| 270 | + print '<td>'.$langs->trans('TotalMargin').'</td>'; |
|
| 271 | + print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>'; |
|
| 272 | + print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>'; |
|
| 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>'; |
|
| 278 | + print '</tr>'; |
|
| 279 | + } |
|
| 280 | + print '</table>'; |
|
| 281 | + print '</div>'; |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |