dolibarr 21.0.0-alpha
partnership.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 NextGestion <contact@nextgestion.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
36{
40 public $module = 'partnership';
41
45 public $element = 'partnership';
46
50 public $table_element = 'partnership';
51
55 public $picto = 'partnership';
56
60 public $type_code;
64 public $type_label;
65
66
67 const STATUS_DRAFT = 0;
68 const STATUS_VALIDATED = 1; // Validate (no more draft)
69 const STATUS_APPROVED = 2; // Approved
70 const STATUS_REFUSED = 3; // Refused
71 const STATUS_CANCELED = 9;
72
73
100 // BEGIN MODULEBUILDER PROPERTIES
104 public $fields = array(
105 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
106 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object", 'csslist' => 'tdoverflowmax150'),
107 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 'isModEnabled("multicompany")', 'position' => 15, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
108 'fk_type' => array('type' => 'integer:PartnershipType:partnership/class/partnership_type.class.php:0:(active:=:1)', 'label' => 'Type', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 1, 'csslist' => 'tdoverflowmax125'),
109 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'picto' => 'company', 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'css' => 'maxwidth500', 'csslist' => 'tdoverflowmax125',),
110 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
111 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
112 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'csslist' => 'nowraponall'),
113 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2, 'csslist' => 'nowraponall'),
114 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax125'),
115 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2, 'csslist' => 'tdoverflowmax125'),
116 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
117 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
118 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
119 'date_partnership_start' => array('type' => 'date', 'label' => 'DatePartnershipStart', 'enabled' => 1, 'position' => 52, 'notnull' => 1, 'visible' => 1,),
120 'date_partnership_end' => array('type' => 'date', 'label' => 'DatePartnershipEnd', 'enabled' => 1, 'position' => 53, 'notnull' => 0, 'visible' => 1,),
121 'url_to_check' => array('type' => 'url', 'label' => 'UrlToCheck', 'enabled' => 'getDolGlobalString("PARTNERSHIP_BACKLINKS_TO_CHECK")', 'position' => 70, 'notnull' => 0, 'visible' => -1, 'csslist' => 'tdoverflowmax150'),
122 'count_last_url_check_error' => array('type' => 'integer', 'label' => 'CountLastUrlCheckError', 'enabled' => 'getDolGlobalString("PARTNERSHIP_BACKLINKS_TO_CHECK")', 'position' => 71, 'notnull' => 0, 'visible' => -4, 'default' => '0',),
123 'last_check_backlink' => array('type' => 'datetime', 'label' => 'LastCheckBacklink', 'enabled' => 'getDolGlobalString("PARTNERSHIP_BACKLINKS_TO_CHECK")', 'position' => 72, 'notnull' => 0, 'visible' => -4, 'csslist' => 'nowraponall'),
124 'reason_decline_or_cancel' => array('type' => 'text', 'label' => 'ReasonDeclineOrCancel', 'enabled' => 1, 'position' => 73, 'notnull' => 0, 'visible' => -2,),
125 'ip' => array('type' => 'ip', 'label' => 'IPOfApplicant', 'enabled' => 1, 'position' => 74, 'notnull' => 0, 'visible' => -2,),
126 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'visible' => 2, 'default' => '0', 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '2' => 'Approved', '3' => 'Refused', '9' => 'Terminated'),),
127 );
131 public $rowid;
135 public $ref;
139 public $entity;
143 public $fk_type;
147 public $note_public;
151 public $note_private;
155 public $fk_user_creat;
159 public $fk_user_modif;
163 public $last_main_doc;
167 public $import_key;
171 public $model_pdf;
175 public $date_partnership_start;
179 public $date_partnership_end;
183 public $url_to_check;
187 public $count_last_url_check_error;
191 public $last_check_backlink;
195 public $reason_decline_or_cancel;
199 public $fk_soc;
203 public $fk_member;
207 public $ip;
211 public $status;
212 // END MODULEBUILDER PROPERTIES
213
214
220 public function __construct(DoliDB $db)
221 {
222 global $conf, $langs;
223
224 $this->db = $db;
225
226 $this->ismultientitymanaged = 0;
227 $this->isextrafieldmanaged = 1;
228
229 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
230 $this->fields['fk_member'] = array('type' => 'integer:Adherent:adherents/class/adherent.class.php:1', 'label' => 'Member', 'enabled' => '1', 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'picto' => 'member', 'csslist' => 'tdoverflowmax150');
231 } else {
232 $this->fields['fk_soc'] = array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => '1', 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'picto' => 'company', 'css' => 'maxwidth500', 'csslist' => 'tdoverflowmax150');
233 }
234
235 // @phan-suppress-next-line PhanTypeMismatchProperty
236 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
237 $this->fields['rowid']['visible'] = 0;
238 }
239
240 // Unset fields that are disabled
241 foreach ($this->fields as $key => $val) {
242 if (isset($val['enabled']) && empty($val['enabled'])) {
243 unset($this->fields[$key]);
244 }
245 }
246
247 // Translate some data of arrayofkeyval
248 if (is_object($langs)) {
249 foreach ($this->fields as $key => $val) {
250 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
251 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
252 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
253 }
254 }
255 }
256 }
257 }
258
266 public function create(User $user, $notrigger = 0)
267 {
268 if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
269 $this->errors[] = "ErrorThirpdartyOrMemberidIsMandatory";
270 return -1;
271 }
272
273 $this->status = 0;
274 return $this->createCommon($user, $notrigger);
275 }
276
284 public function createFromClone(User $user, $fromid)
285 {
286 global $langs, $extrafields;
287 $error = 0;
288
289 dol_syslog(__METHOD__, LOG_DEBUG);
290
291 $object = new self($this->db);
292
293 $this->db->begin();
294
295 // Load source object
296 $result = $object->fetchCommon($fromid);
297 if ($result > 0 && !empty($object->table_element_line)) {
298 $object->fetchLines();
299 }
300
301 // get lines so they will be clone
302 //foreach($this->lines as $line)
303 // $line->fetch_optionals();
304
305 // Reset some properties
306 unset($object->id);
307 unset($object->fk_user_creat);
308 unset($object->import_key);
309
310 // Clear fields
311 if (property_exists($object, 'ref')) {
312 // @phan-suppress-next-line PhanTypeMismatchProperty
313 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
314 }
315 if (property_exists($object, 'label')) {
316 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
317 }
318 if (property_exists($object, 'status')) {
319 $object->status = self::STATUS_DRAFT;
320 }
321 if (property_exists($object, 'date_creation')) {
322 $object->date_creation = dol_now();
323 }
324 if (property_exists($object, 'date_modification')) {
325 $object->date_modification = null;
326 }
327 // ...
328 // Clear extrafields that are unique
329 if (is_array($object->array_options) && count($object->array_options) > 0) {
330 $extrafields->fetch_name_optionals_label($this->table_element);
331 foreach ($object->array_options as $key => $option) {
332 $shortkey = preg_replace('/options_/', '', $key);
333 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
334 //var_dump($key);
335 //var_dump($clonedObj->array_options[$key]); exit;
336 unset($object->array_options[$key]);
337 }
338 }
339 }
340
341 // Create clone
342 $object->context['createfromclone'] = 'createfromclone';
343 $result = $object->createCommon($user);
344 if ($result < 0) {
345 $error++;
346 $this->error = $object->error;
347 $this->errors = $object->errors;
348 }
349
350 if (!$error) {
351 // copy internal contacts
352 if ($this->copy_linked_contact($object, 'internal') < 0) {
353 $error++;
354 }
355 }
356
357 if (!$error) {
358 // copy external contacts if same company
359 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
360 if ($this->copy_linked_contact($object, 'external') < 0) {
361 $error++;
362 }
363 }
364 }
365
366 unset($object->context['createfromclone']);
367
368 // End
369 if (!$error) {
370 $this->db->commit();
371 return $object;
372 } else {
373 $this->db->rollback();
374 return -1;
375 }
376 }
377
388 public function fetch($id, $ref = null, $fk_member = null, $fk_soc = null)
389 {
390 // Check parameters
391 if (empty($id) && empty($ref) && empty($fk_member) && empty($fk_soc)) {
392 return -1;
393 }
394
395 $sql = 'SELECT p.rowid, p.ref, p.fk_type, p.fk_soc, p.fk_member, p.status';
396 $sql .= ', p.entity, p.date_partnership_start, p.date_partnership_end, p.date_creation';
397 $sql .= ', p.fk_user_creat, p.tms, p.fk_user_modif, p.fk_user_modif';
398 $sql .= ', p.note_private, p.note_public, p.url_to_check';
399 $sql .= ', p.last_main_doc, p.count_last_url_check_error, p.last_check_backlink, p.reason_decline_or_cancel';
400 $sql .= ', p.import_key, p.model_pdf';
401 $sql .= ', pt.code as type_code, pt.label as type_label';
402 $sql .= ' FROM '.MAIN_DB_PREFIX.'partnership as p';
403 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_partnership_type as pt ON p.fk_type = pt.rowid';
404
405 if ($id) {
406 $sql .= " WHERE p.rowid = ".((int) $id);
407 } else {
408 $sql .= " WHERE p.entity IN (0,".getEntity('partnership').")"; // Don't use entity if you use rowid
409 }
410
411 if ($ref) {
412 $sql .= " AND p.ref='".$this->db->escape($ref)."'";
413 }
414
415 if ($fk_member > 0) {
416 $sql .= ' AND p.fk_member = '.((int) $fk_member);
417 }
418 if ($fk_soc > 0) {
419 $sql .= ' AND p.fk_soc = '.((int) $fk_soc);
420 }
421 $sql .= ' ORDER BY p.date_partnership_end DESC';
422
423 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
424 $result = $this->db->query($sql);
425 if ($result) {
426 $obj = $this->db->fetch_object($result);
427 if ($obj) {
428 $this->id = $obj->rowid;
429 $this->entity = $obj->entity;
430 $this->ref = $obj->ref;
431
432 $this->fk_type = $obj->fk_type;
433 $this->type_code = $obj->type_code;
434 $this->type_label = $obj->type_label;
435
436 $this->fk_soc = $obj->fk_soc;
437 $this->fk_member = $obj->fk_member;
438 $this->status = $obj->status;
439 $this->date_partnership_start = $this->db->jdate($obj->date_partnership_start);
440 $this->date_partnership_end = $this->db->jdate($obj->date_partnership_end);
441 $this->date_creation = $this->db->jdate($obj->date_creation);
442 $this->fk_user_creat = $obj->fk_user_creat;
443 $this->tms = $obj->tms;
444 $this->fk_user_modif = $obj->fk_user_modif;
445 $this->note_private = $obj->note_private;
446 $this->note_public = $obj->note_public;
447 $this->last_main_doc = $obj->last_main_doc;
448 $this->count_last_url_check_error = $obj->count_last_url_check_error;
449 $this->last_check_backlink = $this->db->jdate($obj->last_check_backlink);
450 $this->reason_decline_or_cancel = $obj->reason_decline_or_cancel;
451 $this->import_key = $obj->import_key;
452 $this->model_pdf = $obj->model_pdf;
453 $this->url_to_check = $obj->url_to_check;
454
455 // Retrieve all extrafield
456 // fetch optionals attributes and labels
457 $this->fetch_optionals();
458
459 $this->db->free($result);
460
461 return 1;
462 } else {
463 // $this->error = 'Partnership with id '.$id.' not found sql='.$sql;
464 return 0;
465 }
466 } else {
467 $this->error = $this->db->error();
468 return -1;
469 }
470 }
471
472
478 public function fetchLines()
479 {
480 $this->lines = array();
481
482 $result = $this->fetchLinesCommon();
483 return $result;
484 }
485
486
498 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
499 {
500 dol_syslog(__METHOD__, LOG_DEBUG);
501
502 $records = array();
503
504 $sql = 'SELECT ';
505 $sql .= $this->getFieldList('t');
506 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
507 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
508 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
509 } else {
510 $sql .= ' WHERE 1 = 1';
511 }
512
513 // Manage filter
514 if (is_array($filter)) {
515 $sqlwhere = array();
516 if (count($filter) > 0) {
517 foreach ($filter as $key => $value) {
518 if ($key == 't.rowid') {
519 $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
520 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
521 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
522 } elseif (strpos($value, '%') === false) {
523 $sqlwhere[] = $this->db->sanitize($key)." IN (".$this->db->sanitize($this->db->escape($value)).")";
524 } else {
525 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
526 }
527 }
528 }
529 if (count($sqlwhere) > 0) {
530 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
531 }
532
533 $filter = '';
534 }
535
536 // Manage filter
537 $errormessage = '';
538 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
539 if ($errormessage) {
540 $this->errors[] = $errormessage;
541 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
542 return -1;
543 }
544
545 if (!empty($sortfield)) {
546 $sql .= $this->db->order($sortfield, $sortorder);
547 }
548 if (!empty($limit)) {
549 $sql .= $this->db->plimit($limit, $offset);
550 }
551
552 $resql = $this->db->query($sql);
553 if ($resql) {
554 $num = $this->db->num_rows($resql);
555 $i = 0;
556 while ($i < ($limit ? min($limit, $num) : $num)) {
557 $obj = $this->db->fetch_object($resql);
558
559 $record = new self($this->db);
560 $record->setVarsFromFetchObj($obj);
561
562 $records[$record->id] = $record;
563
564 $i++;
565 }
566 $this->db->free($resql);
567
568 return $records;
569 } else {
570 $this->errors[] = 'Error '.$this->db->lasterror();
571 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
572
573 return -1;
574 }
575 }
576
584 public function update(User $user, $notrigger = 0)
585 {
586 if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
587 $this->errors[] = "ErrorThirpdartyOrMemberidIsMandatory"; // Mistyping in key is in translations
588 return -1;
589 }
590 if (empty($this->fk_user_creat)) { // For the case the object was created with empty user (from public page).
591 $this->fk_user_creat = $user->id;
592 }
593
594 return $this->updateCommon($user, $notrigger);
595 }
596
604 public function delete(User $user, $notrigger = 0)
605 {
606 return $this->deleteCommon($user, $notrigger);
607 //return $this->deleteCommon($user, $notrigger, 1);
608 }
609
618 public function deleteLine(User $user, $idline, $notrigger = 0)
619 {
620 if ($this->status < 0) {
621 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
622 return -2;
623 }
624
625 return $this->deleteLineCommon($user, $idline, $notrigger);
626 }
627
628
636 public function validate($user, $notrigger = 0)
637 {
638 global $conf;
639
640 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
641
642 $error = 0;
643
644 // Protection
645 if ($this->status == self::STATUS_VALIDATED) {
646 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
647 return 0;
648 }
649
650 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
651 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->partnership_advance->validate))))
652 {
653 $this->error='NotEnoughPermissions';
654 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
655 return -1;
656 }*/
657
658 $now = dol_now();
659
660 $this->db->begin();
661
662 // Define new ref
663 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
664 $num = $this->getNextNumRef();
665 } else {
666 $num = $this->ref;
667 }
668 $this->newref = $num;
669
670 if (!empty($num)) {
671 // Validate
672 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
673 $sql .= " SET ref = '".$this->db->escape($num)."',";
674 $sql .= " status = ".self::STATUS_VALIDATED;
675 if (!empty($this->fields['date_validation'])) {
676 $sql .= ", date_validation = '".$this->db->idate($now)."'";
677 }
678 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
679 $sql .= ", fk_user_valid = ".((int) $user->id);
680 }
681 $sql .= " WHERE rowid = ".((int) $this->id);
682
683 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
684 $resql = $this->db->query($sql);
685 if (!$resql) {
686 dol_print_error($this->db);
687 $this->error = $this->db->lasterror();
688 $error++;
689 }
690
691 if (!$error && !$notrigger) {
692 // Call trigger
693 $result = $this->call_trigger('PARTNERSHIP_VALIDATE', $user);
694 if ($result < 0) {
695 $error++;
696 }
697 // End call triggers
698 }
699 }
700
701 if (!$error) {
702 $this->oldref = $this->ref;
703
704 // Rename directory if dir was a temporary ref
705 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
706 // Now we rename also files into index
707 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'partnership/".$this->db->escape($this->newref)."'";
708 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
709 $resql = $this->db->query($sql);
710 if (!$resql) {
711 $error++;
712 $this->error = $this->db->lasterror();
713 }
714 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'partnership/".$this->db->escape($this->newref)."'";
715 $sql .= " WHERE filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
716 $resql = $this->db->query($sql);
717 if (!$resql) {
718 $error++;
719 $this->error = $this->db->lasterror();
720 }
721
722 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
723 $oldref = dol_sanitizeFileName($this->ref);
724 $newref = dol_sanitizeFileName($num);
725 $dirsource = $conf->partnership->dir_output.'/partnership/'.$oldref;
726 $dirdest = $conf->partnership->dir_output.'/partnership/'.$newref;
727 if (!$error && file_exists($dirsource)) {
728 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
729
730 if (@rename($dirsource, $dirdest)) {
731 dol_syslog("Rename ok");
732 // Rename docs starting with $oldref with $newref
733 $listoffiles = dol_dir_list($conf->partnership->dir_output.'/partnership/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
734 foreach ($listoffiles as $fileentry) {
735 $dirsource = $fileentry['name'];
736 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
737 $dirsource = $fileentry['path'].'/'.$dirsource;
738 $dirdest = $fileentry['path'].'/'.$dirdest;
739 @rename($dirsource, $dirdest);
740 }
741 }
742 }
743 }
744 }
745
746 // Set new ref and current status
747 if (!$error) {
748 $this->ref = $num;
749 $this->status = self::STATUS_VALIDATED;
750 }
751
752 if (!$error) {
753 $this->db->commit();
754 return 1;
755 } else {
756 $this->db->rollback();
757 return -1;
758 }
759 }
760
768 public function approve($user, $notrigger = 0)
769 {
770 global $conf;
771
772 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
773
774 $error = 0;
775
776 // Protection
777 if ($this->status == self::STATUS_APPROVED) {
778 dol_syslog(get_class($this)."::accept action abandoned: already acceptd", LOG_WARNING);
779 return 0;
780 }
781
782 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
783 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->partnership_advance->accept))))
784 {
785 $this->error='NotEnoughPermissions';
786 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
787 return -1;
788 }*/
789
790 $now = dol_now();
791
792 $this->db->begin();
793
794 // Define new ref
795 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
796 $num = $this->getNextNumRef();
797 } else {
798 $num = $this->ref;
799 }
800 $this->newref = $num;
801
802 if (!empty($num)) {
803 // Accept
804 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
805 $sql .= " SET ref = '".$this->db->escape($num)."',";
806 $sql .= " status = ".self::STATUS_APPROVED;
807 $sql .= " WHERE rowid = ".((int) $this->id);
808
809 dol_syslog(get_class($this)."::accept()", LOG_DEBUG);
810 $resql = $this->db->query($sql);
811 if (!$resql) {
812 dol_print_error($this->db);
813 $this->error = $this->db->lasterror();
814 $error++;
815 }
816
817 if (!$error && !$notrigger) {
818 // Call trigger
819 $result = $this->call_trigger('PARTNERSHIP_ACCEPT', $user);
820 if ($result < 0) {
821 $error++;
822 }
823 // End call triggers
824 }
825 }
826
827 if (!$error) {
828 $this->oldref = $this->ref;
829
830 // Rename directory if dir was a temporary ref
831 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
832 // Now we rename also files into index
833 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'partnership/".$this->db->escape($this->newref)."'";
834 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
835 $resql = $this->db->query($sql);
836 if (!$resql) {
837 $error++;
838 $this->error = $this->db->lasterror();
839 }
840 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'partnership/".$this->db->escape($this->newref)."'";
841 $sql .= " WHERE filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
842 $resql = $this->db->query($sql);
843 if (!$resql) {
844 $error++;
845 $this->error = $this->db->lasterror();
846 }
847
848 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
849 $oldref = dol_sanitizeFileName($this->ref);
850 $newref = dol_sanitizeFileName($num);
851 $dirsource = $conf->partnership->dir_output.'/partnership/'.$oldref;
852 $dirdest = $conf->partnership->dir_output.'/partnership/'.$newref;
853 if (!$error && file_exists($dirsource)) {
854 dol_syslog(get_class($this)."::accept() rename dir ".$dirsource." into ".$dirdest);
855
856 if (@rename($dirsource, $dirdest)) {
857 dol_syslog("Rename ok");
858 // Rename docs starting with $oldref with $newref
859 $listoffiles = dol_dir_list($conf->partnership->dir_output.'/partnership/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
860 foreach ($listoffiles as $fileentry) {
861 $dirsource = $fileentry['name'];
862 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
863 $dirsource = $fileentry['path'].'/'.$dirsource;
864 $dirdest = $fileentry['path'].'/'.$dirdest;
865 @rename($dirsource, $dirdest);
866 }
867 }
868 }
869 }
870 }
871
872 // Set new ref and current status
873 if (!$error) {
874 $this->ref = $num;
875 $this->status = self::STATUS_APPROVED;
876 }
877
878 if (!$error) {
879 $this->db->commit();
880 return 1;
881 } else {
882 $this->db->rollback();
883 return -1;
884 }
885 }
886
887
895 public function setDraft($user, $notrigger = 0)
896 {
897 // Protection
898 if ($this->status <= self::STATUS_DRAFT) {
899 return 0;
900 }
901
902 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
903 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
904 {
905 $this->error='Permission denied';
906 return -1;
907 }*/
908
909 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PARTNERSHIP_UNVALIDATE');
910 }
911
920 public function refused($user, $reasondeclinenote = '', $notrigger = 0)
921 {
922 // Protection
923 if ($this->status == self::STATUS_REFUSED) {
924 return 0;
925 }
926
927 $this->status = self::STATUS_REFUSED;
928 $this->reason_decline_or_cancel = $reasondeclinenote;
929
930 $result = $this->update($user);
931
932 if ($result) {
933 $this->reason_decline_or_cancel = $reasondeclinenote;
934 return 1;
935 }
936
937 return -1;
938 }
939
947 public function cancel($user, $notrigger = 0)
948 {
949 // Protection
950 if ($this->status != self::STATUS_APPROVED) {
951 return 0;
952 }
953
954 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
955 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
956 {
957 $this->error='Permission denied';
958 return -1;
959 }*/
960
961 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PARTNERSHIP_CANCEL');
962 }
963
971 public function reopen($user, $notrigger = 0)
972 {
973 // Protection
974 if ($this->status != self::STATUS_CANCELED && $this->status != self::STATUS_REFUSED) {
975 return 0;
976 }
977
978 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
979 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
980 {
981 $this->error='Permission denied';
982 return -1;
983 }*/
984
985 return $this->setStatusCommon($user, self::STATUS_APPROVED, $notrigger, 'PARTNERSHIP_REOPEN');
986 }
987
994 public function getTooltipContentArray($params)
995 {
996 global $langs;
997
998 $langs->load('partnership');
999
1000 $datas = [];
1001 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Partnership").'</u>';
1002 if (isset($this->status)) {
1003 $datas['picto'] .= ' '.$this->getLibStatut(5);
1004 }
1005 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1006
1007 return $datas;
1008 }
1009
1020 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1021 {
1022 global $conf, $langs, $hookmanager;
1023
1024 if (!empty($conf->dol_no_mouse_hover)) {
1025 $notooltip = 1; // Force disable tooltips
1026 }
1027
1028 $result = '';
1029 $params = [
1030 'id' => $this->id,
1031 'objecttype' => $this->element,
1032 'option' => $option,
1033 ];
1034 $classfortooltip = 'classfortooltip';
1035 $dataparams = '';
1036 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1037 $classfortooltip = 'classforajaxtooltip';
1038 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1039 $label = '';
1040 } else {
1041 $label = implode($this->getTooltipContentArray($params));
1042 }
1043
1044 $url = DOL_URL_ROOT.'/partnership/partnership_card.php?id='.$this->id;
1045
1046 if ($option != 'nolink') {
1047 // Add param to save lastsearch_values or not
1048 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1049 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1050 $add_save_lastsearch_values = 1;
1051 }
1052 if ($add_save_lastsearch_values) {
1053 $url .= '&save_lastsearch_values=1';
1054 }
1055 }
1056
1057 $linkclose = '';
1058 if (empty($notooltip)) {
1059 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1060 $label = $langs->trans("ShowPartnership");
1061 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1062 }
1063 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1064 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1065 } else {
1066 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1067 }
1068
1069 if ($option == 'nolink') {
1070 $linkstart = '<span';
1071 } else {
1072 $linkstart = '<a href="'.$url.'"';
1073 }
1074 $linkstart .= $linkclose.'>';
1075 if ($option == 'nolink') {
1076 $linkend = '</span>';
1077 } else {
1078 $linkend = '</a>';
1079 }
1080
1081 $result .= $linkstart;
1082
1083 if (empty($this->showphoto_on_popup)) {
1084 if ($withpicto) {
1085 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
1086 }
1087 } else {
1088 if ($withpicto) {
1089 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1090
1091 list($class, $module) = explode('@', $this->picto);
1092 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
1093 $filearray = dol_dir_list($upload_dir, "files");
1094 $filename = $filearray[0]['name'];
1095 if (!empty($filename)) {
1096 $pospoint = strpos($filearray[0]['name'], '.');
1097
1098 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
1099 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
1100 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
1101 } else {
1102 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
1103 }
1104
1105 $result .= '</div>';
1106 } else {
1107 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1108 }
1109 }
1110 }
1111
1112 if ($withpicto != 2) {
1113 $result .= $this->ref;
1114 }
1115
1116 $result .= $linkend;
1117 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1118
1119 global $action, $hookmanager;
1120 $hookmanager->initHooks(array('partnershipdao'));
1121 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1122 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1123 if ($reshook > 0) {
1124 $result = $hookmanager->resPrint;
1125 } else {
1126 $result .= $hookmanager->resPrint;
1127 }
1128
1129 return $result;
1130 }
1131
1140 public static function replaceThirdparty($db, $origin_id, $dest_id)
1141 {
1142 $tables = array('partnership');
1143
1144 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1145 }
1146
1153 public function getLibStatut($mode = 0)
1154 {
1155 return $this->LibStatut($this->status, $mode);
1156 }
1157
1158 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1166 public function LibStatut($status, $mode = 0)
1167 {
1168 // phpcs:enable
1169 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1170 global $langs;
1171 //$langs->load("partnership");
1172 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1173 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1174 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
1175 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
1176 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Terminated');
1177 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1178 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1179 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
1180 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
1181 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Terminated');
1182 }
1183
1184 $statusType = 'status'.$status;
1185 if ($status == self::STATUS_APPROVED) {
1186 $statusType = 'status4';
1187 }
1188 if ($status == self::STATUS_REFUSED) {
1189 $statusType = 'status9';
1190 }
1191 if ($status == self::STATUS_CANCELED) {
1192 $statusType = 'status6';
1193 }
1194
1195 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1196 }
1197
1204 public function info($id)
1205 {
1206 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1207 $sql .= ' fk_user_creat, fk_user_modif';
1208 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1209 $sql .= ' WHERE t.rowid = '.((int) $id);
1210 $result = $this->db->query($sql);
1211 if ($result) {
1212 if ($this->db->num_rows($result)) {
1213 $obj = $this->db->fetch_object($result);
1214
1215 $this->id = $obj->rowid;
1216
1217 $this->user_creation_id = $obj->fk_user_creat;
1218 $this->user_modification_id = $obj->fk_user_modif;
1219 $this->date_creation = $this->db->jdate($obj->datec);
1220 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1221 }
1222
1223 $this->db->free($result);
1224 } else {
1225 dol_print_error($this->db);
1226 }
1227 }
1228
1235 public function initAsSpecimen()
1236 {
1237 return $this->initAsSpecimenCommon();
1238 }
1239
1245 public function getLinesArray()
1246 {
1247 $this->lines = array();
1248
1249 $objectline = new PartnershipLine($this->db);
1250 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_partnership:=:'.((int) $this->id).')');
1251
1252 if (is_numeric($result)) {
1253 $this->error = $objectline->error;
1254 $this->errors = $objectline->errors;
1255 return $result;
1256 } else {
1257 $this->lines = $result;
1258 // @phpstan-ignore-next-line
1259 return $result; // @phan-suppress-current-line PhanTypeMismatchReturn
1260 }
1261 }
1262
1268 public function getNextNumRef()
1269 {
1270 global $langs, $conf;
1271 $langs->load("partnership");
1272
1273 if (!getDolGlobalString('PARTNERSHIP_ADDON')) {
1274 $conf->global->PARTNERSHIP_ADDON = 'mod_partnership_standard';
1275 }
1276
1277 if (getDolGlobalString('PARTNERSHIP_ADDON')) {
1278 $mybool = false;
1279
1280 $file = getDolGlobalString('PARTNERSHIP_ADDON') . ".php";
1281 $classname = getDolGlobalString('PARTNERSHIP_ADDON');
1282
1283 // Include file with class
1284 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1285 foreach ($dirmodels as $reldir) {
1286 $dir = dol_buildpath($reldir."core/modules/partnership/");
1287
1288 // Load file with numbering class (if found)
1289 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1290 }
1291
1292 if (!$mybool) {
1293 dol_print_error(null, "Failed to include file ".$file);
1294 return '';
1295 }
1296
1297 if (class_exists($classname)) {
1298 $obj = new $classname();
1299 '@phan-var-force ModeleNumRefPartnership $obj';
1300 $numref = $obj->getNextValue($this);
1301
1302 if ($numref != '' && $numref != '-1') {
1303 return $numref;
1304 } else {
1305 $this->error = $obj->error;
1306 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1307 return "";
1308 }
1309 } else {
1310 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1311 return "";
1312 }
1313 } else {
1314 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1315 return "";
1316 }
1317 }
1318
1330 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1331 {
1332 global $conf, $langs;
1333
1334 $result = 0;
1335 $includedocgeneration = 0;
1336
1337 $langs->load("partnership");
1338
1339 if (!dol_strlen($modele)) {
1340 $modele = 'standard_partnership';
1341
1342 if (!empty($this->model_pdf)) {
1343 $modele = $this->model_pdf;
1344 } elseif (getDolGlobalString('PARTNERSHIP_ADDON_PDF')) {
1345 $modele = getDolGlobalString('PARTNERSHIP_ADDON_PDF');
1346 }
1347 }
1348
1349 $modelpath = "core/modules/partnership/doc/";
1350
1351 if ($includedocgeneration && !empty($modele)) {
1352 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1353 }
1354
1355 return $result;
1356 }
1357
1365 public function doScheduledJob()
1366 {
1367 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1368
1369 $error = 0;
1370 $this->output = '';
1371 $this->error = '';
1372
1373 dol_syslog(__METHOD__, LOG_DEBUG);
1374
1375 //$now = dol_now();
1376
1377 $this->db->begin();
1378
1379 // ...
1380
1381 $this->db->commit();
1382
1383 return $error;
1384 }
1385
1393 public function getKanbanView($option = '', $arraydata = null)
1394 {
1395 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1396
1397 $return = '<div class="box-flex-item box-flex-grow-zero">';
1398 $return .= '<div class="info-box info-box-sm">';
1399 $return .= '<span class="info-box-icon bg-infobox-action">';
1400 $return .= img_picto('', $this->picto);
1401 $return .= '</span>';
1402 $return .= '<div class="info-box-content">';
1403 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1404 if ($selected >= 0) {
1405 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1406 }
1407 if (property_exists($this, 'label')) {
1408 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
1409 }
1410 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
1411 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
1412 }
1413 if (method_exists($this, 'getLibStatut')) {
1414 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1415 }
1416 $return .= '</div>';
1417 $return .= '</div>';
1418 $return .= '</div>';
1419
1420 return $return;
1421 }
1422}
1423
1424
1425require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1426
1431{
1432 // To complete with content of an object PartnershipLine
1433 // We should have a field rowid, fk_partnership and position
1434
1435
1441 public function __construct(DoliDB $db)
1442 {
1443 $this->db = $db;
1444
1445 $this->isextrafieldmanaged = 0;
1446 }
1447}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Partnership.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
validate($user, $notrigger=0)
Validate object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
createFromClone(User $user, $fromid)
Clone an object into another one.
setDraft($user, $notrigger=0)
Set draft status.
refused($user, $reasondeclinenote='', $notrigger=0)
Set refused status.
fetch($id, $ref=null, $fk_member=null, $fk_soc=null)
Load object in memory from the database Get object from database.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
getLinesArray()
Create an array of lines.
getTooltipContentArray($params)
getTooltipContentArray
cancel($user, $notrigger=0)
Set cancel status.
reopen($user, $notrigger=0)
Set back to validated status.
fetchLines()
Load object lines in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
info($id)
Load the info information in the object.
approve($user, $notrigger=0)
Approve object.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
Class PartnershipLine.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:162
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.