From 27eb3ccd0685e5a86072be4d1872be75d2523a38 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Fri, 19 Aug 2022 21:53:17 +0100 Subject: [PATCH 01/10] draft --- htdocs/public/partnership/new.php | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index f6f0efc4fb2..9f8d996b35e 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -67,7 +67,7 @@ $backtopage = GETPOST('backtopage', 'alpha'); $action = GETPOST('action', 'aZ09'); // Load translation files -$langs->loadLangs(array("main", "members", "companies", "install", "other")); +$langs->loadLangs(array("main", "members", "companies", "install", "other")); // maybe change this one // Security check if (empty($conf->partnership->enabled)) { @@ -177,11 +177,15 @@ if (empty($reshook) && $action == 'add') { $urlback = ''; $db->begin(); - + /*if (GETPOST('typeid') <= 0) { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."
\n"; }*/ + if (!GETPOST('societe')) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("societe"))."
\n"; + } if (!GETPOST('lastname')) { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."
\n"; @@ -190,6 +194,7 @@ if (empty($reshook) && $action == 'add') { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."
\n"; } + if (empty(GETPOST('email'))) { $error++; $errmsg .= $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Email'))."
\n"; @@ -211,7 +216,8 @@ if (empty($reshook) && $action == 'add') { $partnership->fk_soc = 0; } - $partnership->statut = -1; + // need to change this part + $partnership->statut = 0; $partnership->firstname = GETPOST('firstname'); $partnership->lastname = GETPOST('lastname'); $partnership->address = GETPOST('address'); @@ -235,10 +241,10 @@ if (empty($reshook) && $action == 'add') { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $object = $partnership; - /* + /* $partnershipt = new PartnershipType($db); $partnershipt->fetch($object->typeid); - + if ($object->email) { $subject = ''; $msg = ''; @@ -278,6 +284,7 @@ if (empty($reshook) && $action == 'add') { */ // Send email to the foundation to say a new member subscribed with autosubscribe form + /* if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') && !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT) && !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL)) { // Define link to login card @@ -314,7 +321,33 @@ if (empty($reshook) && $action == 'add') { if (!$mailfile->sendfile()) { dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR); } + }*/ + + // test if societe or email already exist + $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); } + if ($num = 0) { + //create thirdparty + $company = new Societe($db); + $resultat=$company->create($user); + if ($result < 0) { + $error++; + $errmsg .= join('
', $company->errors); + } + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; + $sql .= " SET name = ".(GETPOST('societe')).", email = ".(GETPOST('email')); + $sql .= ", address = ".(($GETPOSTISSET('address') ? GETPOST('address') : "null")).", zip = ".(($GETPOSTISSET('zipcode') ? GETPOST('zipcode') : "null")); + $sql .= ", town = ".(($GETPOSTISSET('town') ? GETPOST('town') : "null")).", fk_pays = ".(($GETPOSTISSET('country_id') ? GETPOST('country_id') : "null")); + $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null")); + $sql .= " WHERE rowid = ".((int) $company->id); + $resql = $db->query($sql); + + $object->fk_soc = $company->id; + } + if (!empty($backtopage)) { $urlback = $backtopage; From b74d2636fe09da57df890ce82ce3a4934158cbcb Mon Sep 17 00:00:00 2001 From: bagtaib Date: Fri, 19 Aug 2022 21:53:29 +0100 Subject: [PATCH 02/10] hook --- htdocs/public/partnership/new.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 9f8d996b35e..14c921d2254 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -177,7 +177,7 @@ if (empty($reshook) && $action == 'add') { $urlback = ''; $db->begin(); - + /*if (GETPOST('typeid') <= 0) { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."
\n"; @@ -194,7 +194,7 @@ if (empty($reshook) && $action == 'add') { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."
\n"; } - + if (empty(GETPOST('email'))) { $error++; $errmsg .= $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Email'))."
\n"; @@ -241,10 +241,10 @@ if (empty($reshook) && $action == 'add') { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $object = $partnership; - /* + /* $partnershipt = new PartnershipType($db); $partnershipt->fetch($object->typeid); - + if ($object->email) { $subject = ''; $msg = ''; @@ -322,7 +322,7 @@ if (empty($reshook) && $action == 'add') { dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR); } }*/ - + // test if societe or email already exist $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; $result = $db->query($sql); @@ -344,7 +344,7 @@ if (empty($reshook) && $action == 'add') { $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null")); $sql .= " WHERE rowid = ".((int) $company->id); $resql = $db->query($sql); - + $object->fk_soc = $company->id; } From b342560e4dc116b2548501005ce7f0095024f809 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Mon, 22 Aug 2022 00:35:34 +0100 Subject: [PATCH 03/10] modified create partnership --- .../partnership/class/partnership.class.php | 65 ++++++++++++++++++- htdocs/public/partnership/new.php | 46 ++++++------- 2 files changed, 87 insertions(+), 24 deletions(-) diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 38d8c333749..0783f330843 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -248,7 +248,70 @@ class Partnership extends CommonObject } $this->status = 0; - return $this->createCommon($user, $notrigger); + + global $conf, $langs; + + $error = 0; + + $now = dol_now(); + + // Clean parameters + $this->import_key = trim($this->import_key); + + if (!$this->date_creation) { + $this->date_creation = $now; + } + + + $this->db->begin(); + + // Insert partnership + $sql = "INSERT INTO ".MAIN_DB_PREFIX."partnership"; + $sql .= " (ref, date_creation,fk_user_creat,fk_user_modif,fk_type,entity,import_key)"; + $sql .= " VALUES ("; + $sql .= " '(PROV)'"; + $sql .= ", '".$this->db->idate($this->datec)."'"; + $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because partnership can be created by a guest or a script + $sql .= ", null "; + $sql .= ", ".((int) $this->fk_type); + $sql .= ", ".$conf->entity; + $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); + $sql .= ")"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."partnership"); + if ($id > 0) { + $this->id = $id; + $this->ref = (string) $id; + + // Update minor fields + $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user + if ($result < 0) { + $this->db->rollback(); + return -1; + } + + if (count($this->errors)) { + dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR); + $this->db->rollback(); + return -3; + } else { + $this->db->commit(); + return $this->id; + } + } else { + $this->error = 'Failed to get last insert id'; + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } else { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } } /** diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 14c921d2254..38660fbcdfd 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -236,6 +236,28 @@ if (empty($reshook) && $action == 'add') { $error++; } + $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + } + if ($num = 0) { + //create thirdparty + $company = new Societe($db); + $resultat=$company->create($user); + if ($result < 0) { + $error++; + $errmsg .= join('
', $company->errors); + } + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; + $sql .= " SET name = ".(GETPOST('societe')).", email = ".(GETPOST('email')); + $sql .= ", address = ".(($GETPOSTISSET('address') ? GETPOST('address') : "null")).", zip = ".(($GETPOSTISSET('zipcode') ? GETPOST('zipcode') : "null")); + $sql .= ", town = ".(($GETPOSTISSET('town') ? GETPOST('town') : "null")).", fk_pays = ".(($GETPOSTISSET('country_id') ? GETPOST('country_id') : "null")); + $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null")); + $sql .= " WHERE rowid = ".((int) $company->id); + $resql = $db->query($sql); + $partnership->fk_soc = $company->id; + } $result = $partnership->create($user); if ($result > 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; @@ -324,29 +346,7 @@ if (empty($reshook) && $action == 'add') { }*/ // test if societe or email already exist - $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - } - if ($num = 0) { - //create thirdparty - $company = new Societe($db); - $resultat=$company->create($user); - if ($result < 0) { - $error++; - $errmsg .= join('
', $company->errors); - } - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; - $sql .= " SET name = ".(GETPOST('societe')).", email = ".(GETPOST('email')); - $sql .= ", address = ".(($GETPOSTISSET('address') ? GETPOST('address') : "null")).", zip = ".(($GETPOSTISSET('zipcode') ? GETPOST('zipcode') : "null")); - $sql .= ", town = ".(($GETPOSTISSET('town') ? GETPOST('town') : "null")).", fk_pays = ".(($GETPOSTISSET('country_id') ? GETPOST('country_id') : "null")); - $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null")); - $sql .= " WHERE rowid = ".((int) $company->id); - $resql = $db->query($sql); - - $object->fk_soc = $company->id; - } + if (!empty($backtopage)) { From 9e71d491e611a9f09ba10f61adbbcbe5f33c2bf4 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Mon, 22 Aug 2022 00:36:23 +0100 Subject: [PATCH 04/10] hook --- htdocs/partnership/class/partnership.class.php | 4 ++-- htdocs/public/partnership/new.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 0783f330843..05d37ac9ee1 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -261,11 +261,11 @@ class Partnership extends CommonObject if (!$this->date_creation) { $this->date_creation = $now; } - + $this->db->begin(); - // Insert partnership + // Insert partnership $sql = "INSERT INTO ".MAIN_DB_PREFIX."partnership"; $sql .= " (ref, date_creation,fk_user_creat,fk_user_modif,fk_type,entity,import_key)"; $sql .= " VALUES ("; diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 38660fbcdfd..1c3e945b375 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -346,7 +346,7 @@ if (empty($reshook) && $action == 'add') { }*/ // test if societe or email already exist - + if (!empty($backtopage)) { From 6cc872abd85d94c58b0de0ebad71924cf094d48c Mon Sep 17 00:00:00 2001 From: bagtaib Date: Mon, 22 Aug 2022 09:50:45 +0100 Subject: [PATCH 05/10] . --- htdocs/public/partnership/new.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 1c3e945b375..f08a23cd406 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -217,7 +217,7 @@ if (empty($reshook) && $action == 'add') { } // need to change this part - $partnership->statut = 0; + $partnership->status = 0; $partnership->firstname = GETPOST('firstname'); $partnership->lastname = GETPOST('lastname'); $partnership->address = GETPOST('address'); @@ -235,8 +235,8 @@ if (empty($reshook) && $action == 'add') { if ($ret < 0) { $error++; } - - $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; + // test if societe already exist + $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".GETPOST('societe')."'"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -258,6 +258,10 @@ if (empty($reshook) && $action == 'add') { $resql = $db->query($sql); $partnership->fk_soc = $company->id; } + else { + $don=$result->fetch(); + $partnership->fk_soc =$don['rowid']; + } $result = $partnership->create($user); if ($result > 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; @@ -345,7 +349,6 @@ if (empty($reshook) && $action == 'add') { } }*/ - // test if societe or email already exist From 376a2288b7b8b668792d058282c7b19e926b0ff0 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Mon, 22 Aug 2022 09:50:58 +0100 Subject: [PATCH 06/10] . --- htdocs/public/partnership/new.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index f08a23cd406..b5ff6eecf57 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -257,8 +257,7 @@ if (empty($reshook) && $action == 'add') { $sql .= " WHERE rowid = ".((int) $company->id); $resql = $db->query($sql); $partnership->fk_soc = $company->id; - } - else { + } else { $don=$result->fetch(); $partnership->fk_soc =$don['rowid']; } From 056fa0aba9ba8955051dda3293245ad53b4acfbf Mon Sep 17 00:00:00 2001 From: bagtaib Date: Wed, 24 Aug 2022 00:20:11 +0100 Subject: [PATCH 07/10] added mods suggested --- .../partnership/class/partnership.class.php | 65 +--- htdocs/public/partnership/new.php | 365 +++++++++--------- 2 files changed, 191 insertions(+), 239 deletions(-) diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 05d37ac9ee1..38d8c333749 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -248,70 +248,7 @@ class Partnership extends CommonObject } $this->status = 0; - - global $conf, $langs; - - $error = 0; - - $now = dol_now(); - - // Clean parameters - $this->import_key = trim($this->import_key); - - if (!$this->date_creation) { - $this->date_creation = $now; - } - - - $this->db->begin(); - - // Insert partnership - $sql = "INSERT INTO ".MAIN_DB_PREFIX."partnership"; - $sql .= " (ref, date_creation,fk_user_creat,fk_user_modif,fk_type,entity,import_key)"; - $sql .= " VALUES ("; - $sql .= " '(PROV)'"; - $sql .= ", '".$this->db->idate($this->datec)."'"; - $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because partnership can be created by a guest or a script - $sql .= ", null "; - $sql .= ", ".((int) $this->fk_type); - $sql .= ", ".$conf->entity; - $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); - $sql .= ")"; - - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."partnership"); - if ($id > 0) { - $this->id = $id; - $this->ref = (string) $id; - - // Update minor fields - $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user - if ($result < 0) { - $this->db->rollback(); - return -1; - } - - if (count($this->errors)) { - dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR); - $this->db->rollback(); - return -3; - } else { - $this->db->commit(); - return $this->id; - } - } else { - $this->error = 'Failed to get last insert id'; - dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); - $this->db->rollback(); - return -2; - } - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } + return $this->createCommon($user, $notrigger); } /** diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index b5ff6eecf57..aced814a9b3 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -67,7 +67,7 @@ $backtopage = GETPOST('backtopage', 'alpha'); $action = GETPOST('action', 'aZ09'); // Load translation files -$langs->loadLangs(array("main", "members", "companies", "install", "other")); // maybe change this one +$langs->loadLangs(array("main", "members", "companies", "install", "other")); // Security check if (empty($conf->partnership->enabled)) { @@ -208,6 +208,7 @@ if (empty($reshook) && $action == 'add') { if (!$error) { $partnership = new Partnership($db); + $partnershipt = new PartnershipType($db); // We try to find the thirdparty or the member if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') { @@ -218,16 +219,20 @@ if (empty($reshook) && $action == 'add') { // need to change this part $partnership->status = 0; - $partnership->firstname = GETPOST('firstname'); - $partnership->lastname = GETPOST('lastname'); - $partnership->address = GETPOST('address'); - $partnership->zip = GETPOST('zipcode'); - $partnership->town = GETPOST('town'); - $partnership->email = GETPOST('email'); - $partnership->country_id = GETPOST('country_id', 'int'); - $partnership->state_id = GETPOST('state_id', 'int'); - //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int'); $partnership->note_private = GETPOST('note_private'); + $partnership->date_creation = dol_now(); + $partnership->date_partnership_start = dol_now(); + $partnership->$partnershipt->fetch(0, 'default'); + $partnership->fk_user_creat=$user->id; + //$partnership->firstname = GETPOST('firstname'); + //$partnership->lastname = GETPOST('lastname'); + //$partnership->address = GETPOST('address'); + //$partnership->zip = GETPOST('zipcode'); + //$partnership->town = GETPOST('town'); + //$partnership->email = GETPOST('email'); + //$partnership->country_id = GETPOST('country_id', 'int'); + //$partnership->state_id = GETPOST('state_id', 'int'); + //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int'); // Fill array 'array_options' with data from add form $extrafields->fetch_name_optionals_label($partnership->table_element); @@ -236,7 +241,7 @@ if (empty($reshook) && $action == 'add') { $error++; } // test if societe already exist - $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".GETPOST('societe')."'"; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -244,196 +249,206 @@ if (empty($reshook) && $action == 'add') { if ($num = 0) { //create thirdparty $company = new Societe($db); + + $company->address = GETPOST('address'); + $company->zip = GETPOST('zipcode'); + $company->town = GETPOST('town'); + $company->email = GETPOST('email'); + $company->country_id = GETPOST('country_id', 'int'); + $company->state_id = GETPOST('state_id', 'int'); + $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); + $resultat=$company->create($user); if ($result < 0) { $error++; $errmsg .= join('
', $company->errors); } - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; - $sql .= " SET name = ".(GETPOST('societe')).", email = ".(GETPOST('email')); - $sql .= ", address = ".(($GETPOSTISSET('address') ? GETPOST('address') : "null")).", zip = ".(($GETPOSTISSET('zipcode') ? GETPOST('zipcode') : "null")); - $sql .= ", town = ".(($GETPOSTISSET('town') ? GETPOST('town') : "null")).", fk_pays = ".(($GETPOSTISSET('country_id') ? GETPOST('country_id') : "null")); - $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null")); - $sql .= " WHERE rowid = ".((int) $company->id); - $resql = $db->query($sql); + $partnership->fk_soc = $company->id; + } elseif ($num > 1) { + $error++; + $errmsg = 'Message'; } else { - $don=$result->fetch(); - $partnership->fk_soc =$don['rowid']; + $company = $db->fetch_object($result); + $partnership->fk_soc = $company->rowid; } - $result = $partnership->create($user); - if ($result > 0) { - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $object = $partnership; + if (!$error) { + $result = $partnership->create($user); + if ($result > 0) { + /* + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $object = $partnership; - /* - $partnershipt = new PartnershipType($db); - $partnershipt->fetch($object->typeid); - if ($object->email) { - $subject = ''; - $msg = ''; + $partnershipt = new PartnershipType($db); + $partnershipt->fetch($object->typeid); - // Send subscription email - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - // Set output language - $outputlangs = new Translate('', $conf); - $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); - // Load traductions files required by page - $outputlangs->loadLangs(array("main", "members")); - // Get email content from template - $arraydefaultmessage = null; - $labeltouse = $conf->global->PARTNERSHIP_EMAIL_TEMPLATE_AUTOREGISTER; + if ($object->email) { + $subject = ''; + $msg = ''; - if (!empty($labeltouse)) { - $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); + // Send subscription email + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + // Set output language + $outputlangs = new Translate('', $conf); + $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); + // Load traductions files required by page + $outputlangs->loadLangs(array("main", "members")); + // Get email content from template + $arraydefaultmessage = null; + $labeltouse = $conf->global->PARTNERSHIP_EMAIL_TEMPLATE_AUTOREGISTER; + + if (!empty($labeltouse)) { + $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); + } + + if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { + $subject = $arraydefaultmessage->topic; + $msg = $arraydefaultmessage->content; + } + + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); + $texttosend = make_substitutions(dol_concatdesc($msg, $partnershipt->getMailOnValid()), $substitutionarray, $outputlangs); + + if ($subjecttosend && $texttosend) { + $moreinheader = 'X-Dolibarr-Info: send_an_email by public/members/new.php'."\r\n"; + + $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); + } } - if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { - $subject = $arraydefaultmessage->topic; - $msg = $arraydefaultmessage->content; - } - $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); - complete_substitutions_array($substitutionarray, $outputlangs, $object); - $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); - $texttosend = make_substitutions(dol_concatdesc($msg, $partnershipt->getMailOnValid()), $substitutionarray, $outputlangs); - - if ($subjecttosend && $texttosend) { - $moreinheader = 'X-Dolibarr-Info: send_an_email by public/members/new.php'."\r\n"; - - $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); - } - } - */ - - // Send email to the foundation to say a new member subscribed with autosubscribe form - /* - if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') && !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT) && - !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL)) { - // Define link to login card - $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { - $appli = $conf->global->MAIN_APPLICATION_TITLE; - if (preg_match('/\d\.\d/', $appli)) { - if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) { - $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core + // Send email to the foundation to say a new member subscribed with autosubscribe form + /* + if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') && !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT) && + !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL)) { + // Define link to login card + $appli = constant('DOL_APPLICATION_TITLE'); + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $appli = $conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) { + if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) { + $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + } else { + $appli .= " ".DOL_VERSION; } } else { $appli .= " ".DOL_VERSION; } + + $to = $partnership->makeSubstitution(getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')); + $from = getDolGlobalString('PARTNERSHIP_MAIL_FROM'); + $mailfile = new CMailFile( + '['.$appli.'] '.getDolGlobalString('PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT', 'Partnership request'), + $to, + $from, + $partnership->makeSubstitution(getDolGlobalString('PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL')), + array(), + array(), + array(), + "", + "", + 0, + -1 + ); + + if (!$mailfile->sendfile()) { + dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR); + } + }*/ + + + + + if (!empty($backtopage)) { + $urlback = $backtopage; + } elseif (!empty($conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION)) { + $urlback = $conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION; + // TODO Make replacement of __AMOUNT__, etc... } else { - $appli .= " ".DOL_VERSION; + $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken(); } - $to = $partnership->makeSubstitution(getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')); - $from = getDolGlobalString('PARTNERSHIP_MAIL_FROM'); - $mailfile = new CMailFile( - '['.$appli.'] '.getDolGlobalString('PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT', 'Partnership request'), - $to, - $from, - $partnership->makeSubstitution(getDolGlobalString('PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL')), - array(), - array(), - array(), - "", - "", - 0, - -1 - ); + /* + if (!empty($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE) && $conf->global->PARTNERSHIP_NEWFORM_PAYONLINE != '-1') { + if ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'all') { + $urlback = DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); + if (price2num(GETPOST('amount', 'alpha'))) { + $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); + } + if (GETPOST('email')) { + $urlback .= '&email='.urlencode(GETPOST('email')); + } + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { + $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); + } else { + $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); + } + } + } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'paybox') { + $urlback = DOL_MAIN_URL_ROOT.'/public/paybox/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); + if (price2num(GETPOST('amount', 'alpha'))) { + $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); + } + if (GETPOST('email')) { + $urlback .= '&email='.urlencode(GETPOST('email')); + } + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { + $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); + } else { + $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); + } + } + } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'paypal') { + $urlback = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); + if (price2num(GETPOST('amount', 'alpha'))) { + $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); + } + if (GETPOST('email')) { + $urlback .= '&email='.urlencode(GETPOST('email')); + } + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { + $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); + } else { + $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); + } + } + } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'stripe') { + $urlback = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.$partnership->ref; + if (price2num(GETPOST('amount', 'alpha'))) { + $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); + } + if (GETPOST('email')) { + $urlback .= '&email='.urlencode(GETPOST('email')); + } + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { + if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { + $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); + } else { + $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); + } + } + } else { + dol_print_error('', "Autosubscribe form is setup to ask an online payment for a not managed online payment"); + exit; + } + }*/ - if (!$mailfile->sendfile()) { - dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR); + if (!empty($entity)) { + $urlback .= '&entity='.$entity; } - }*/ - - - - - if (!empty($backtopage)) { - $urlback = $backtopage; - } elseif (!empty($conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION)) { - $urlback = $conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION; - // TODO Make replacement of __AMOUNT__, etc... + dol_syslog("partnership ".$partnership->ref." was created, we redirect to ".$urlback); } else { - $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken(); + $error++; + $errmsg .= join('
', $partnership->errors); } - - if (!empty($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE) && $conf->global->PARTNERSHIP_NEWFORM_PAYONLINE != '-1') { - if ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'all') { - $urlback = DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); - if (price2num(GETPOST('amount', 'alpha'))) { - $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); - } - if (GETPOST('email')) { - $urlback .= '&email='.urlencode(GETPOST('email')); - } - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { - $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); - } else { - $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); - } - } - } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'paybox') { - $urlback = DOL_MAIN_URL_ROOT.'/public/paybox/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); - if (price2num(GETPOST('amount', 'alpha'))) { - $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); - } - if (GETPOST('email')) { - $urlback .= '&email='.urlencode(GETPOST('email')); - } - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { - $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); - } else { - $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); - } - } - } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'paypal') { - $urlback = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); - if (price2num(GETPOST('amount', 'alpha'))) { - $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); - } - if (GETPOST('email')) { - $urlback .= '&email='.urlencode(GETPOST('email')); - } - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { - $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); - } else { - $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); - } - } - } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'stripe') { - $urlback = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.$partnership->ref; - if (price2num(GETPOST('amount', 'alpha'))) { - $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha')); - } - if (GETPOST('email')) { - $urlback .= '&email='.urlencode(GETPOST('email')); - } - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) { - if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { - $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2)); - } else { - $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN); - } - } - } else { - dol_print_error('', "Autosubscribe form is setup to ask an online payment for a not managed online payment"); - exit; - } - } - - if (!empty($entity)) { - $urlback .= '&entity='.$entity; - } - dol_syslog("partnership ".$partnership->ref." was created, we redirect to ".$urlback); - } else { - $error++; - $errmsg .= join('
', $partnership->errors); } } From f36303a951e5cc08316ccab20b37edfb27dcdeaf Mon Sep 17 00:00:00 2001 From: bagtaib Date: Wed, 24 Aug 2022 00:23:39 +0100 Subject: [PATCH 08/10] debug --- htdocs/public/partnership/new.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index aced814a9b3..f817a36aa1b 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -222,7 +222,7 @@ if (empty($reshook) && $action == 'add') { $partnership->note_private = GETPOST('note_private'); $partnership->date_creation = dol_now(); $partnership->date_partnership_start = dol_now(); - $partnership->$partnershipt->fetch(0, 'default'); + $partnership->fk_type = $partnershipt->fetch(0, 'default'); $partnership->fk_user_creat=$user->id; //$partnership->firstname = GETPOST('firstname'); //$partnership->lastname = GETPOST('lastname'); From 17dccc2a6d766ef811d58a80ef1fea727c5c0449 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Wed, 24 Aug 2022 12:02:38 +0100 Subject: [PATCH 09/10] added email check --- htdocs/public/partnership/new.php | 64 +++++++++++++++++-------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index f817a36aa1b..9026aacce4d 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -217,7 +217,6 @@ if (empty($reshook) && $action == 'add') { $partnership->fk_soc = 0; } - // need to change this part $partnership->status = 0; $partnership->note_private = GETPOST('note_private'); $partnership->date_creation = dol_now(); @@ -234,44 +233,56 @@ if (empty($reshook) && $action == 'add') { //$partnership->state_id = GETPOST('state_id', 'int'); //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int'); - // Fill array 'array_options' with data from add form - $extrafields->fetch_name_optionals_label($partnership->table_element); - $ret = $extrafields->setOptionalsFromPost(null, $partnership); - if ($ret < 0) { - $error++; - } // test if societe already exist $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); } - if ($num = 0) { - //create thirdparty - $company = new Societe($db); - - $company->address = GETPOST('address'); - $company->zip = GETPOST('zipcode'); - $company->town = GETPOST('town'); - $company->email = GETPOST('email'); - $company->country_id = GETPOST('country_id', 'int'); - $company->state_id = GETPOST('state_id', 'int'); - $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); - - $resultat=$company->create($user); - if ($result < 0) { - $error++; - $errmsg .= join('
', $company->errors); + if ($num = 0) { // si il ya pas d'entree sur le nom on teste l'email + $sql1 = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE email='".$db->escape(GETPOST('email'))."'"; + $result1 = $db->query($sql1); + if ($result1) { + $num1 = $db->num_rows($result1); } + if ($num1 != 0) { + $error++; + $errmsg = "email already exists please rewrite your company name"; + } else { + //create thirdparty + $company = new Societe($db); - $partnership->fk_soc = $company->id; + $company->address = GETPOST('address'); + $company->zip = GETPOST('zipcode'); + $company->town = GETPOST('town'); + $company->email = GETPOST('email'); + $company->country_id = GETPOST('country_id', 'int'); + $company->state_id = GETPOST('state_id', 'int'); + $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); + + $resultat=$company->create($user); + if ($resultat < 0) { + $error++; + $errmsg .= join('
', $company->errors); + } + + $partnership->fk_soc = $company->id; + } } elseif ($num > 1) { $error++; - $errmsg = 'Message'; + $errmsg = 'more than one entry exist for this company please contact us to complete your partnership request'; } else { $company = $db->fetch_object($result); $partnership->fk_soc = $company->rowid; } + + // Fill array 'array_options' with data from add form + $extrafields->fetch_name_optionals_label($partnership->table_element); + $ret = $extrafields->setOptionalsFromPost(null, $partnership); + if ($ret < 0) { + $error++; + } + if (!$error) { $result = $partnership->create($user); if ($result > 0) { @@ -361,9 +372,6 @@ if (empty($reshook) && $action == 'add') { } }*/ - - - if (!empty($backtopage)) { $urlback = $backtopage; } elseif (!empty($conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION)) { From 5e910361ac60fd51d919ac93aab4baad0b808124 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Thu, 25 Aug 2022 09:57:18 +0100 Subject: [PATCH 10/10] fix fetch errror --- htdocs/public/partnership/new.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 9026aacce4d..b9332b32366 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -221,8 +221,14 @@ if (empty($reshook) && $action == 'add') { $partnership->note_private = GETPOST('note_private'); $partnership->date_creation = dol_now(); $partnership->date_partnership_start = dol_now(); - $partnership->fk_type = $partnershipt->fetch(0, 'default'); $partnership->fk_user_creat=$user->id; + + $partnershipt->fetch(0, 'default'); + if ($partnershipt->id > 0) { + $partnership->fk_type = $partnershipt->id; + } + + //$partnership->firstname = GETPOST('firstname'); //$partnership->lastname = GETPOST('lastname'); //$partnership->address = GETPOST('address');