From 84fccb098870ae8871bfc821d011f167ace5312e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 May 2022 13:57:11 +0200 Subject: [PATCH] Debug v16 --- htdocs/core/class/extrafields.class.php | 31 ++++++++++++----- htdocs/core/lib/project.lib.php | 12 ++++--- htdocs/projet/admin/project.php | 2 +- htdocs/public/project/new.php | 45 ++++++++++++++++++++++--- htdocs/societe/class/societe.class.php | 2 +- 5 files changed, 72 insertions(+), 20 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 3a396e365d7..768031467bc 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1948,14 +1948,15 @@ class ExtraFields /** * Fill array_options property of object by extrafields value (using for data sent by forms) * - * @param array $extralabels Deprecated (old $array of extrafields, now set this to null) - * @param object $object Object - * @param string $onlykey Only some keys are filled: - * 'string' => When we make update of only one extrafield ($action = 'update_extras'), calling page can set this to avoid to have other extrafields being reset. - * '@GETPOSTISSET' => When we make update of several extrafields ($action = 'update'), calling page can set this to avoid to have fields not into POST being reset. - * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) + * @param array $extralabels Deprecated (old $array of extrafields, now set this to null) + * @param object $object Object + * @param string $onlykey Only some keys are filled: + * 'string' => When we make update of only one extrafield ($action = 'update_extras'), calling page can set this to avoid to have other extrafields being reset. + * '@GETPOSTISSET' => When we make update of several extrafields ($action = 'update'), calling page can set this to avoid to have fields not into POST being reset. + * @param int $todefaultifmissing 1=Set value to the default value in database if value is mandatory and missing + * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) */ - public function setOptionalsFromPost($extralabels, &$object, $onlykey = '') + public function setOptionalsFromPost($extralabels, &$object, $onlykey = '', $todefaultifmissing = 0) { global $_POST, $langs; @@ -2015,8 +2016,10 @@ class ExtraFields || (!is_array($_POST["options_".$key]) && isset($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] == 'sellist' && $_POST['options_'.$key] == '0') || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) { //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; + + // Field is not defined. We mark this as a problem. We may fix it later if there is a default value and $todefaultifmissing is set. $nofillrequired++; - $error_field_required[] = $langs->transnoentitiesnoconv($value); + $error_field_required[$key] = $langs->transnoentitiesnoconv($value); } } @@ -2047,12 +2050,22 @@ class ExtraFields } } + if (!empty($error_field_required[$key]) && $todefaultifmissing) { + // Value is required but we have a default value and we asked to set empty value to the default value + if (!empty($this->attributes[$object->table_element]['default']) && !is_null($this->attributes[$object->table_element]['default'][$key])) { + $value_key = $this->attributes[$object->table_element]['default'][$key]; + unset($error_field_required[$key]); + $nofillrequired--; + } + } + $object->array_options["options_".$key] = $value_key; } if ($nofillrequired) { $langs->load('errors'); - setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors'); + $this->error = $langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required); + setEventMessages($this->error, null, 'errors'); return -1; } else { return 1; diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 68e76e85ca3..56aa24a8523 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -509,12 +509,14 @@ function project_admin_prepare_head() $head[$h][2] = 'attributes_task'; $h++; - $langs->load("members"); + if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { + $langs->load("members"); - $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php'; - $head[$h][1] = $langs->trans("BlankSubscriptionForm"); - $head[$h][2] = 'website'; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php'; + $head[$h][1] = $langs->trans("BlankSubscriptionForm"); + $head[$h][2] = 'website'; + $h++; + } complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove'); diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index 4bfb899cffe..36ef3a501ff 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -265,7 +265,7 @@ print ' '."\n"; print ''; print ''.$langs->trans("ManageOpportunitiesStatus").''; print ''; -print ajax_constantonoff("PROJECT_USE_OPPORTUNITIES"); +print ajax_constantonoff("PROJECT_USE_OPPORTUNITIES", null, null, 0, 0, 1); print ''; print ""; print ''; diff --git a/htdocs/public/project/new.php b/htdocs/public/project/new.php index 85106ce51de..4838c88c5a1 100644 --- a/htdocs/public/project/new.php +++ b/htdocs/public/project/new.php @@ -206,16 +206,53 @@ if (empty($reshook) && $action == 'add') { $errmsg .= $langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Project"))."
\n"; } - if (!$error) { - $proj = new Project($db); - $thirdparty = new Societe($db); + $proj = new Project($db); + $thirdparty = new Societe($db); + if (!$error) { // Search thirdparty and set it if found to the new created project $result = $thirdparty->fetch(0, '', '', '', '', '', '', '', '', '', $object->email); if ($result > 0) { $proj->socid = $thirdparty->id; - } + } else { + // Create the prospect + if (GETPOST('societe')) { + $thirdparty->name = GETPOST('societe'); + $thirdparty->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); + } else { + $thirdparty->name = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); + } + $thirdparty->address = GETPOST('address'); + $thirdparty->zip = GETPOST('zip'); + $thirdparty->town = GETPOST('town'); + $thirdparty->country_id = GETPOST('country_id', 'int'); + $thirdparty->state_id = GETPOST('state_id'); + $thirdparty->client = $thirdparty::PROSPECT; + $thirdparty->code_client = 'auto'; + $thirdparty->code_fournisseur = 'auto'; + // Fill array 'array_options' with data from the form + $extrafields->fetch_name_optionals_label($thirdparty->table_element); + $ret = $extrafields->setOptionalsFromPost(null, $thirdparty, '', 1); + //var_dump($thirdparty->array_options);exit; + if ($ret < 0) { + $error++; + $errmsg = ($extrafields->error ? $extrafields->error.'
' : '').join('
', $extrafields->errors); + } + + if (!$error) { + $result = $thirdparty->create($user); + if ($result <= 0) { + $error++; + $errmsg = ($thirdparty->error ? $thirdparty->error.'
' : '').join('
', $thirdparty->errors); + } else { + $proj->socid = $thirdparty->id; + } + } + } + } + + if (!$error) { // Defined the ref into $defaultref $defaultref = ''; $modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1d32063c27b..30f8515e92c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -956,7 +956,7 @@ class Societe extends CommonObject $sql .= ", accountancy_code_sell"; $sql .= ") VALUES ("; $sql .= $this->id; - $sql .= ", ".$conf->entity; + $sql .= ", ".((int) $conf->entity); $sql .= ", '".$this->db->escape($this->accountancy_code_customer)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_supplier)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'";