added mods suggested

This commit is contained in:
bagtaib 2022-08-24 00:20:11 +01:00
parent 376a2288b7
commit 056fa0aba9
2 changed files with 191 additions and 239 deletions

View File

@ -248,70 +248,7 @@ class Partnership extends CommonObject
} }
$this->status = 0; $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;
}
} }
/** /**

View File

@ -67,7 +67,7 @@ $backtopage = GETPOST('backtopage', 'alpha');
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
// Load translation files // 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 // Security check
if (empty($conf->partnership->enabled)) { if (empty($conf->partnership->enabled)) {
@ -208,6 +208,7 @@ if (empty($reshook) && $action == 'add') {
if (!$error) { if (!$error) {
$partnership = new Partnership($db); $partnership = new Partnership($db);
$partnershipt = new PartnershipType($db);
// We try to find the thirdparty or the member // We try to find the thirdparty or the member
if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') { if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
@ -218,16 +219,20 @@ if (empty($reshook) && $action == 'add') {
// need to change this part // need to change this part
$partnership->status = 0; $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->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 // Fill array 'array_options' with data from add form
$extrafields->fetch_name_optionals_label($partnership->table_element); $extrafields->fetch_name_optionals_label($partnership->table_element);
@ -236,7 +241,7 @@ if (empty($reshook) && $action == 'add') {
$error++; $error++;
} }
// test if societe already exist // 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); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -244,29 +249,37 @@ if (empty($reshook) && $action == 'add') {
if ($num = 0) { if ($num = 0) {
//create thirdparty //create thirdparty
$company = new Societe($db); $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); $resultat=$company->create($user);
if ($result < 0) { if ($result < 0) {
$error++; $error++;
$errmsg .= join('<br>', $company->errors); $errmsg .= join('<br>', $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; $partnership->fk_soc = $company->id;
} elseif ($num > 1) {
$error++;
$errmsg = 'Message';
} else { } else {
$don=$result->fetch(); $company = $db->fetch_object($result);
$partnership->fk_soc =$don['rowid']; $partnership->fk_soc = $company->rowid;
} }
if (!$error) {
$result = $partnership->create($user); $result = $partnership->create($user);
if ($result > 0) { if ($result > 0) {
/*
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$object = $partnership; $object = $partnership;
/*
$partnershipt = new PartnershipType($db); $partnershipt = new PartnershipType($db);
$partnershipt->fetch($object->typeid); $partnershipt->fetch($object->typeid);
@ -306,7 +319,7 @@ if (empty($reshook) && $action == 'add') {
$result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); $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 // Send email to the foundation to say a new member subscribed with autosubscribe form
/* /*
@ -360,6 +373,7 @@ if (empty($reshook) && $action == 'add') {
$urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken(); $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken();
} }
/*
if (!empty($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE) && $conf->global->PARTNERSHIP_NEWFORM_PAYONLINE != '-1') { if (!empty($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE) && $conf->global->PARTNERSHIP_NEWFORM_PAYONLINE != '-1') {
if ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'all') { if ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'all') {
$urlback = DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref); $urlback = DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref);
@ -425,7 +439,7 @@ if (empty($reshook) && $action == 'add') {
dol_print_error('', "Autosubscribe form is setup to ask an online payment for a not managed online payment"); dol_print_error('', "Autosubscribe form is setup to ask an online payment for a not managed online payment");
exit; exit;
} }
} }*/
if (!empty($entity)) { if (!empty($entity)) {
$urlback .= '&entity='.$entity; $urlback .= '&entity='.$entity;
@ -436,6 +450,7 @@ if (empty($reshook) && $action == 'add') {
$errmsg .= join('<br>', $partnership->errors); $errmsg .= join('<br>', $partnership->errors);
} }
} }
}
if (!$error) { if (!$error) {
$db->commit(); $db->commit();