diff --git a/htdocs/core/modules/modPartnership.class.php b/htdocs/core/modules/modPartnership.class.php index 442e01b56f6..9f8c1437eee 100644 --- a/htdocs/core/modules/modPartnership.class.php +++ b/htdocs/core/modules/modPartnership.class.php @@ -180,10 +180,10 @@ class modPartnership extends DolibarrModules $tabtoadd = ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') ? 'member' : 'thirdparty'; if ($tabtoadd == 'member') { - $this->tabs[] = array('data'=>'member:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/partnership/partnership.php?socid=__ID__'); + $this->tabs[] = array('data'=>'member:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/adherents/partnership.php?socid=__ID__'); $fk_mainmenu = "members"; } else { - $this->tabs[] = array('data'=>'thirdparty:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/partnership/partnership.php?socid=__ID__'); + $this->tabs[] = array('data'=>'thirdparty:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/societe/partnership.php?socid=__ID__'); $fk_mainmenu = "companies"; } diff --git a/htdocs/langs/en_US/partnership.lang b/htdocs/langs/en_US/partnership.lang index 63b3bec0bb6..e9fb30d1fd6 100644 --- a/htdocs/langs/en_US/partnership.lang +++ b/htdocs/langs/en_US/partnership.lang @@ -37,6 +37,7 @@ PartnershipAboutPage = Partnership about page # # Object # +PartnershipDedicatedToThisThirdParty=Partnership dedicated to this third party DatePartnershipStart=Start date DatePartnershipEnd=End date diff --git a/htdocs/partnership/admin/setup.php b/htdocs/partnership/admin/setup.php index d55daab2347..6ba689cbd00 100644 --- a/htdocs/partnership/admin/setup.php +++ b/htdocs/partnership/admin/setup.php @@ -91,10 +91,10 @@ if ($action == 'setting') { $partnership->tabs = array(); if ($modulemenu == 'member') { - $partnership->tabs[] = array('data'=>'member:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/partnership/partnership.php?socid=__ID__'); + $partnership->tabs[] = array('data'=>'member:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/adherents/partnership.php?socid=__ID__'); $fk_mainmenu = "members"; } else { - $partnership->tabs[] = array('data'=>'thirdparty:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/partnership/partnership.php?socid=__ID__'); + $partnership->tabs[] = array('data'=>'thirdparty:+partnership:Partnership:partnership@partnership:$user->rights->partnership->read:/societe/partnership.php?socid=__ID__'); $fk_mainmenu = "companies"; } diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 019d72a6012..6a676bf24e9 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -100,26 +100,7 @@ class Partnership extends CommonObject /** * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. */ - public $fields=array( - 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"), - '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"), - '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,), - 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,), - 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,), - 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,), - 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,), - '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',), - 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,), - 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,), - 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,), - 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,), - 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Accepté', '2'=>'Refusé', '9'=>'Annulé'),), - 'fk_member' => array('type'=>'integer:Adherent:adherents/class/adherent.class.php:1', 'label'=>'Member', 'enabled'=>'1', 'position'=>51, 'notnull'=>-1, 'visible'=>1, 'index'=>1,), - 'date_partnership_start' => array('type'=>'datetime', 'label'=>'DatePartnershipStart', 'enabled'=>'1', 'position'=>52, 'notnull'=>1, 'visible'=>1,), - 'date_partnership_end' => array('type'=>'datetime', 'label'=>'DatePartnershipEnd', 'enabled'=>'1', 'position'=>53, 'notnull'=>1, 'visible'=>1,), - 'count_last_url_check_error' => array('type'=>'integer', 'label'=>'CountLastUrlCheckError', 'enabled'=>'1', 'position'=>63, 'notnull'=>0, 'visible'=>-2, 'default'=>'0',), - 'reason_decline_or_cancel' => array('type'=>'text', 'label'=>'ReasonDeclineOrCancel', 'enabled'=>'1', 'position'=>64, 'notnull'=>0, 'visible'=>-2,), - ); + public $fields=array(); public $rowid; public $ref; public $fk_soc; @@ -188,12 +169,37 @@ class Partnership extends CommonObject $this->db = $db; + $fk_soc_visible = ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') ? 0 : 1; + $fk_member_visible = ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') ? 1 : 0; + + $this->fields=array( + 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"), + '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"), + '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'=>$fk_soc_visible, 'index'=>1,), + 'fk_member' => array('type'=>'integer:Adherent:adherents/class/adherent.class.php:1', 'label'=>'Member', 'enabled'=>'1', 'position'=>51, 'notnull'=>-1, 'visible'=>$fk_member_visible, 'index'=>1,), + 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1), + 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,), + 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,), + 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,), + 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,), + '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',), + 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,), + 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,), + 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,), + 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,), + 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Accepté', '2'=>'Refusé', '9'=>'Annulé'),), + 'date_partnership_start' => array('type'=>'date', 'label'=>'DatePartnershipStart', 'enabled'=>'1', 'position'=>52, 'notnull'=>1, 'visible'=>1,), + 'date_partnership_end' => array('type'=>'date', 'label'=>'DatePartnershipEnd', 'enabled'=>'1', 'position'=>53, 'notnull'=>1, 'visible'=>1,), + 'count_last_url_check_error' => array('type'=>'integer', 'label'=>'CountLastUrlCheckError', 'enabled'=>'1', 'position'=>63, 'notnull'=>0, 'visible'=>-2, 'default'=>'0',), + 'reason_decline_or_cancel' => array('type'=>'text', 'label'=>'ReasonDeclineOrCancel', 'enabled'=>'1', 'position'=>64, 'notnull'=>0, 'visible'=>-2,), + ); + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) { $this->fields['rowid']['visible'] = 0; } - if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) { - $this->fields['entity']['enabled'] = 0; - } + // if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) { + // $this->fields['entity']['enabled'] = 0; + // } // Example to show how to set values of fields definition dynamically /*if ($user->rights->partnership->read) { @@ -229,6 +235,7 @@ class Partnership extends CommonObject */ public function create(User $user, $notrigger = false) { + $this->status = 0; return $this->createCommon($user, $notrigger); } @@ -333,20 +340,97 @@ class Partnership extends CommonObject /** * Load object in memory from the database + * Get object from database. Get also lines. * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id of object to load + * @param string $ref Ref of object + * @param int $fk_soc_or_member fk_soc or fk_member + * @return int >0 if OK, <0 if KO, 0 if not found */ - public function fetch($id, $ref = null) + public function fetch($id, $ref = null, $fk_soc_or_member = null) { - $result = $this->fetchCommon($id, $ref); - if ($result > 0 && !empty($this->table_element_line)) { - $this->fetchLines(); + global $conf; + + // Check parameters + if (empty($id) && empty($ref) && empty($fk_soc_or_member)) { + return -1; + } + + $sql = 'SELECT p.rowid, p.ref, p.fk_soc, p.fk_member, p.status'; + $sql .= ', p.entity, p.date_partnership_start, p.date_partnership_end, p.date_creation'; + $sql .= ', p.fk_user_creat, p.tms, p.fk_user_modif, p.fk_user_modif'; + $sql .= ', p.note_private, p.note_public'; + $sql .= ', p.last_main_doc, p.count_last_url_check_error, p.reason_decline_or_cancel'; + $sql .= ', p.import_key, p.model_pdf'; + + $sql .= ' FROM '.MAIN_DB_PREFIX.'partnership as p'; + + if ($id) { + $sql .= " WHERE p.rowid=".$id; + } else { + $sql .= " WHERE p.entity IN (0,".getEntity('partnership').")"; // Dont't use entity if you use rowid + } + + if ($ref) { + $sql .= " AND p.ref='".$this->db->escape($ref)."'"; + } + + if($fk_soc_or_member){ + $sql .= ' AND'; + if($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') + $sql .= ' p.fk_member = '; + else + $sql .= ' p.fk_soc = '; + $sql .= $fk_soc_or_member; + $sql .= ' ORDER BY p.date_partnership_end DESC'; + } + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $obj = $this->db->fetch_object($result); + if ($obj) { + $this->id = $obj->rowid; + $this->entity = $obj->entity; + $this->rowid = $obj->rowid; + $this->ref = $obj->ref; + $this->fk_soc = $obj->fk_soc; + $this->fk_member = $obj->fk_member; + $this->status = $obj->status; + $this->date_partnership_start = $this->db->jdate($obj->date_partnership_start); + $this->date_partnership_end = $this->db->jdate($obj->date_partnership_end); + $this->date_creation = $this->db->jdate($obj->date_creation); + $this->fk_user_creat = $obj->fk_user_creat; + $this->tms = $obj->tms; + $this->fk_user_modif = $obj->fk_user_modif; + $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->last_main_doc = $obj->last_main_doc; + $this->count_last_url_check_error = $obj->count_last_url_check_error; + $this->reason_decline_or_cancel = $obj->reason_decline_or_cancel; + $this->import_key = $obj->import_key; + $this->model_pdf = $obj->model_pdf; + + $this->lines = array(); + + // Retrieve all extrafield + // fetch optionals attributes and labels + $this->fetch_optionals(); + + $this->db->free($result); + + return 1; + } else { + $this->error = 'Partnership with id '.$id.' not found sql='.$sql; + return 0; + } + } else { + $this->error = $this->db->error(); + return -1; } - return $result; } + /** * Load object lines in memory from the database * @@ -768,9 +852,9 @@ class Partnership extends CommonObject public function refused($user, $notrigger = '') { // Protection - // if ($this->status != self::STATUS_DRAFT) { - // return 0; - // } + if ($this->status == self::STATUS_REFUSED) { + return 0; + } /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->partnership->write)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->partnership_advance->validate)))) @@ -816,7 +900,7 @@ class Partnership extends CommonObject public function reopen($user, $notrigger = 0) { // Protection - if ($this->status != self::STATUS_CANCELED) { + if ($this->status != self::STATUS_CANCELED && $this->status != self::STATUS_REFUSED) { return 0; } diff --git a/htdocs/partnership/class/partnershiputils.class.php b/htdocs/partnership/class/partnershiputils.class.php index 61659e6075c..08c61b3454c 100644 --- a/htdocs/partnership/class/partnershiputils.class.php +++ b/htdocs/partnership/class/partnershiputils.class.php @@ -35,7 +35,7 @@ dol_include_once('partnership/lib/partnership.lib.php'); class PartnershipUtils { public $db; //!< To store db handler - public $error; //!< To return error code (or message) + public $error; //!< To return error code (or message) public $errors=array(); //!< To return several error codes (or messages) diff --git a/htdocs/partnership/partnership_card.php b/htdocs/partnership/partnership_card.php index dbf889137d8..c44174af52c 100644 --- a/htdocs/partnership/partnership_card.php +++ b/htdocs/partnership/partnership_card.php @@ -108,9 +108,7 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen // Initialize array of search criterias $search_all = GETPOST("search_all", 'alpha'); $search = array(); -if ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') - unset($object->fields['fk_soc']); -else unset($object->fields['fk_member']); + foreach ($object->fields as $key => $val) { if (GETPOST('search_'.$key, 'alpha')) { $search[$key] = GETPOST('search_'.$key, 'alpha'); @@ -581,7 +579,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Back to draft - if ($object->status == $object::STATUS_ACCEPTED) { + if ($object->status != $object::STATUS_DRAFT) { print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes', '', $permissiontoadd); } @@ -598,23 +596,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - // Clone - // print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=scrumsprint', '', $permissiontoadd); - - - // if ($permissiontoadd) { - // if ($object->status == $object::STATUS_ENABLED) { - // print ''.$langs->trans("Disable").''."\n"; - // } else { - // print ''.$langs->trans("Enable").''."\n"; - // } - // } - // Cancel if ($permissiontoadd) { if ($object->status == $object::STATUS_ACCEPTED) { print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken(), '', $permissiontoadd); - } elseif ($object->status == $object::STATUS_CANCELED) { + } elseif ($object->status > $object::STATUS_ACCEPTED) { // print ''.$langs->trans("Re-Open").''."\n"; print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken(), '', $permissiontoadd); } @@ -622,7 +608,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Refuse if ($permissiontoadd) { - if ($object->status != $object::STATUS_CANCELED) { + if ($object->status != $object::STATUS_CANCELED && $object->status != $object::STATUS_REFUSED) { print ''.$langs->trans("Refuse").''."\n"; } } diff --git a/htdocs/societe/partnership.php b/htdocs/societe/partnership.php new file mode 100644 index 00000000000..2484936f686 --- /dev/null +++ b/htdocs/societe/partnership.php @@ -0,0 +1,614 @@ + + * Copyright (C) 2021 NextGestion + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file partnership_card.php + * \ingroup partnership + * \brief Page to create/edit/view partnership + */ + +//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db +//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user +//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs +//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters +//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters +//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on). +//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on) +//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data +//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu +//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library +//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too. +//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value +//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler +//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message +//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies +//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET +//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification + +// Load Dolibarr environment +$res = 0; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { + $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; +} +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { + $i--; $j--; +} +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { + $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; +} +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { + $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; +} +// Try main.inc.php using relative path +if (!$res && file_exists("../main.inc.php")) { + $res = @include "../main.inc.php"; +} +if (!$res && file_exists("../../main.inc.php")) { + $res = @include "../../main.inc.php"; +} +if (!$res && file_exists("../../../main.inc.php")) { + $res = @include "../../../main.inc.php"; +} +if (!$res) { + die("Include of main fails"); +} + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +dol_include_once('/partnership/class/partnership.class.php'); +dol_include_once('/partnership/lib/partnership.lib.php'); + +// Load translation files required by the page +$langs->loadLangs(array("companies","partnership@partnership", "other")); + +// Get parameters +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'alpha'); +$cancel = GETPOST('cancel', 'aZ09'); +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'partnershipcard'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); +//$lineid = GETPOST('lineid', 'int'); + +// Security check +$socid = GETPOST('socid', 'int'); +if (!empty($user->socid)) { + $socid = $user->socid; +} + +$societe = new Societe($db); +if ($socid > 0) { + $societe->fetch($socid); +} + +// Initialize technical objects +$object = new Partnership($db); +$extrafields = new ExtraFields($db); +$diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id; +$hookmanager->initHooks(array('partnershipthirdparty', 'globalcard')); // Note that conf->hooks_modules contains array + +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); + +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); + +// Initialize array of search criterias +$search_all = GETPOST("search_all", 'alpha'); +$search = array(); + +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha')) { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } +} + +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. + +$permissiontoread = $user->rights->partnership->read; +$permissiontoadd = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontodelete = $user->rights->partnership->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$permissionnote = $user->rights->partnership->write; // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->rights->partnership->write; // Used by the include of actions_dellink.inc.php +$usercanclose = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1]; + + +if (empty($conf->partnership->enabled)) accessforbidden(); +if (empty($permissiontoread)) accessforbidden(); +if ($action == 'edit' && empty($permissiontoadd)) accessforbidden(); + +$partnershipid = $object->fetch(0, "", $socid); +if(empty($action) && empty($partnershipid)){ + $action = 'create'; +} +if (($action == 'update' || $action == 'edit') && $object->status != $object::STATUS_DRAFT && !empty($user->socid)) accessforbidden(); + +if(empty($socid) && $object){ + $socid = $object->fk_soc; +} +/* + * Actions + */ + +$parameters = array(); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +$date_start = dol_mktime(0, 0, 0, GETPOST('date_partnership_startmonth', 'int'), GETPOST('date_partnership_startday', 'int'), GETPOST('date_partnership_startyear', 'int')); +$date_end = dol_mktime(0, 0, 0, GETPOST('date_partnership_endmonth', 'int'), GETPOST('date_partnership_endday', 'int'), GETPOST('date_partnership_endyear', 'int')); + +if (empty($reshook)) { + $error = 0; + + $backtopage = dol_buildpath('/partnership/partnership.php', 1).'?socid='.($socid > 0 ? $socid : '__ID__'); + + $triggermodname = 'PARTNERSHIP_MODIFY'; // Name of trigger action code to execute when we modify record + + if ($action == 'add' && $permissiontoread) { + $error = 0; + + $db->begin(); + + $now = dol_now(); + + if (!$error) { + $old_start_date = $object->date_partnership_start; + + $object->fk_soc = $socid; + $object->date_partnership_start = (!GETPOST('date_partnership_start')) ? '' : $date_start; + $object->date_partnership_end = (!GETPOST('date_partnership_end')) ? '' : $date_end; + $object->date_creation = $now; + $object->fk_user_creat = $user->id; + $object->entity = $conf->entity; + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) { + $error++; + } + } + + if (!$error) { + $result = $object->create($user); + if ($result < 0) { + $error++; + if ($result == -4) { + setEventMessages($langs->trans("ErrorRefAlreadyExists"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + if ($error) { + $db->rollback(); + $action = 'edit'; + } else { + $db->commit(); + } + } elseif ($action == 'update' && $permissiontoread) { + $error = 0; + + $db->begin(); + + $now = dol_now(); + + if (!$error) { + $object->oldcopy = clone $object; + + $old_start_date = $object->date_partnership_start; + + $object->date_partnership_start = (!GETPOST('date_partnership_start')) ? '' : $date_start; + $object->date_partnership_end = (!GETPOST('date_partnership_end')) ? '' : $date_end; + $object->fk_user_creat = $user->id; + $object->fk_user_modif = $user->id; + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) { + $error++; + } + } + + if (!$error) { + $result = $object->update($user); + if ($result < 0) { + $error++; + if ($result == -4) { + setEventMessages($langs->trans("ErrorRefAlreadyExists"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + if ($error) { + $db->rollback(); + $action = 'edit'; + } else { + $db->commit(); + } + } elseif ($action == 'confirm_close' || $action == 'update_extras') { + include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; + + header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); + exit; + } + + // Actions when linking object each other + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; + + // // Actions to send emails + // $triggersendname = 'PARTNERSHIP_SENTBYMAIL'; + // $autocopy = 'MAIN_MAIL_AUTOCOPY_PARTNERSHIP_TO'; + // $trackid = 'partnership'.$object->id; + // include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; +} + + + +/* + * View + * + * Put here all code to build page + */ + +$form = new Form($db); +$formfile = new FormFile($db); +$formproject = new FormProjets($db); + +$title = $langs->trans("Partnership"); +llxHeader('', $title); + +$form = new Form($db); + +if ($socid) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + + $langs->load("companies"); + + $societe = new Societe($db); + $result = $societe->fetch($socid); + + if (!empty($conf->notification->enabled)) { + $langs->load("mails"); + } + $head = societe_prepare_head($societe); + + print dol_get_fiche_head($head, 'partnership', $langs->trans("ThirdParty"), -1, 'company'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($societe, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); + + print '
'; + + print '
'; + print ''; + + if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field + print ''; + } + + if ($societe->client) { + print ''; + } + + if ($societe->fournisseur) { + print ''; + } + + print '
'.$langs->trans('Prefix').''.$societe->prefix_comm.'
'; + print $langs->trans('CustomerCode').''; + print showValueWithClipboardCPButton(dol_escape_htmltag($societe->code_client)); + $tmpcheck = $societe->check_codeclient(); + if ($tmpcheck != 0 && $tmpcheck != -5) { + print ' ('.$langs->trans("WrongCustomerCode").')'; + } + print '
'; + print $langs->trans('SupplierCode').''; + print showValueWithClipboardCPButton(dol_escape_htmltag($societe->code_fournisseur)); + $tmpcheck = $societe->check_codefournisseur(); + if ($tmpcheck != 0 && $tmpcheck != -5) { + print ' ('.$langs->trans("WrongSupplierCode").')'; + } + print '
'; + + print '
'; + + print dol_get_fiche_end(); + + $params = ''; + + $newcardbutton .= dolGetButtonTitle($langs->trans("NewProject"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?action=create&socid='.$societe->id.'&backtopage='.urlencode($backtopage), '', 1, $params); + + print '
'; + +} else { + dol_print_error('', 'Parameter socid not defined'); +} + +$object->fields['fk_soc']['visible'] = 0; + +// Part to create +if ($action == 'create') { + print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Partnership")), '', ''); + + $backtopageforcancel = DOL_URL_ROOT.'/partnership/partnership.php?socid='.$socid; + + print '
'; + print ''; + print ''; + print ''; + print ''; + + if ($backtopage) { + print ''; + } + if ($backtopageforcancel) { + print ''; + } + + print dol_get_fiche_head(array(), ''); + + print ''."\n"; + + // Common attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; + + print '
'."\n"; + + print dol_get_fiche_end(); + + print '
'; + print ''; + print '  '; + // print ''; // Cancel for create does not post form if we don't know the backtopage + print '
'; + + print '
'; +} + +// Part to edit record +if (($partnershipid || $ref) && $action == 'edit') { + print load_fiche_titre($langs->trans("Partnership"), '', ''); + + $backtopageforcancel = DOL_URL_ROOT.'/partnership/partnership.php?socid='.$socid; + + print '
'; + print ''; + print ''; + print ''; + print ''; + if ($backtopage) { + print ''; + } + if ($backtopageforcancel) { + print ''; + } + + print dol_get_fiche_head(); + + print ''."\n"; + + // Common attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php'; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; + + print '
'; + + print dol_get_fiche_end(); + + print '
'; + print '   '; + print '
'; + + print '
'; +} + +// Part to show record +if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { + + + print load_fiche_titre($langs->trans("PartnershipDedicatedToThisThirdParty", $langs->transnoentitiesnoconv("Partnership")), '', ''); + + $res = $object->fetch_optionals(); + + // $head = partnershipPrepareHead($object); + // print dol_get_fiche_head($head, 'card', $langs->trans("Partnership"), -1, $object->picto); + + $linkback = ''; + dol_banner_tab($object, 'id', $linkback, 0, 'rowid', 'ref'); + + $formconfirm = ''; + + // Close confirmation + if ($action == 'close') { + // Create an array for form + $formquestion = array(); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClose'), $langs->trans('ConfirmCloseAsk', $object->ref), 'confirm_close', $formquestion, 'yes', 1); + } + // Reopon confirmation + if ($action == 'reopen') { + // Create an array for form + $formquestion = array(); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToReopon'), $langs->trans('ConfirmReoponAsk', $object->ref), 'confirm_reopen', $formquestion, 'yes', 1); + } + + // Refuse confirmatio + if ($action == 'refuse') { + //Form to close proposal (signed or not) + $formquestion = array( + array('type' => 'text', 'name' => 'reason_decline_or_cancel', 'label' => $langs->trans("Note"), 'morecss' => 'reason_decline_or_cancel', 'value' => '') // Field to complete private note (not replace) + ); + + // if (!empty($conf->notification->enabled)) { + // require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; + // $notify = new Notify($db); + // $formquestion = array_merge($formquestion, array( + // array('type' => 'onecolumn', 'value' => $notify->confirmMessage('PROPAL_CLOSE_SIGNED', $object->socid, $object)), + // )); + // } + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReasonDecline'), $text, 'confirm_refuse', $formquestion, '', 1, 250); + } + + // Call Hook formConfirm + $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } + + // Print form confirm + print $formconfirm; + + + // Object card + // ------------------------------------------------------------ + $linkback = ''.$langs->trans("BackToList").''; + + print '
'; + print '
'; + print '
'; + print ''."\n"; + + // Common attributes + //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field + //unset($object->fields['fk_project']); // Hide field already shown in banner + //unset($object->fields['fk_soc']); // Hide field already shown in banner + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; + + // Other attributes. Fields from hook formObjectOptions and Extrafields. + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'; + print '
'; + + print '
'; + + print dol_get_fiche_end(); + + // Buttons for actions + + if ($action != 'presend') { + print '
'."\n"; + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + + if (empty($reshook)) { + + if ($object->status == $object::STATUS_DRAFT) { + print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?socid='.$socid.'&action=edit', '', $permissiontoadd); + } + + // Cancel + if ($permissiontoadd) { + if ($object->status == $object::STATUS_ACCEPTED) { + print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd); + } + } + } + print '
'."\n"; + } + + + // Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } + + // if ($action != 'presend') { + // print '
'; + // print ''; // ancre + + // $includedocgeneration = 0; + + // // Documents + // if ($includedocgeneration) { + // $objref = dol_sanitizeFileName($object->ref); + // $relativepath = $objref.'/'.$objref.'.pdf'; + // $filedir = $conf->partnership->dir_output.'/'.$object->element.'/'.$objref; + // $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; + // $genallowed = $user->rights->partnership->read; // If you can read, you can build the PDF to read content + // $delallowed = $user->rights->partnership->write; // If you can create/edit, you can remove a file on card + // print $formfile->showdocuments('partnership:Partnership', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); + // } + + // // Show links to link elements + // $linktoelem = $form->showLinkToObjectBlock($object, null, array('partnership')); + // $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); + + + // print '
'; + + // $MAXEVENT = 10; + + // $morehtmlright = ''; + // $morehtmlright .= $langs->trans("SeeAll"); + // $morehtmlright .= ''; + + // // List of actions on element + // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + // $formactions = new FormActions($db); + // $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright); + + // print '
'; + // } + + //Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } + + // Presend form + $modelmail = 'partnership'; + $defaulttopic = 'InformationMessage'; + $diroutput = $conf->partnership->dir_output; + $trackid = 'partnership'.$object->id; + + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; +} + +// End of page +llxFooter(); +$db->close();