Serious enhancement in auto subscription for member module

This commit is contained in:
Laurent Destailleur 2018-03-23 20:45:35 +01:00
parent 53edb86ffb
commit c7e93a5a3b
6 changed files with 95 additions and 43 deletions

View File

@ -1378,7 +1378,7 @@ else
array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"') array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
); );
print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1); print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 'yes');
} }
// Confirm validate member // Confirm validate member
@ -1438,15 +1438,9 @@ else
if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) { if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) {
$formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>''); $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>'');
} }
print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ValidateMember"), $langs->trans("ConfirmValidateMember"), "confirm_valid", $formquestion, '1', 1, 220); print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ValidateMember"), $langs->trans("ConfirmValidateMember"), "confirm_valid", $formquestion, 'yes', 1, 220);
} }
// Confirm send card by mail
/*if ($action == 'sendinfo')
{
print $form->formconfirm("card.php?rowid=".$id,$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail",$object->email),"confirm_sendinfo",'',0,1);
}*/
// Confirm terminate // Confirm terminate
if ($action == 'resign') if ($action == 'resign')
{ {
@ -1499,7 +1493,7 @@ else
$formquestion=array(); $formquestion=array();
if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?'true':'false')); if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?'true':'false'));
if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])); if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
print $form->formconfirm("card.php?rowid=".$id,$langs->trans("ResiliateMember"),$langs->trans("ConfirmResiliateMember"),"confirm_resign",$formquestion,'no',1); print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ResiliateMember"), $langs->trans("ConfirmResiliateMember"), "confirm_resign", $formquestion, 'no', 1, 220);
} }
// Confirm remove member // Confirm remove member
@ -1507,7 +1501,7 @@ else
{ {
$formquestion=array(); $formquestion=array();
if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])); if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
print $form->formconfirm("card.php?rowid=".$id,$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete",$formquestion,0,1); print $form->formconfirm("card.php?rowid=".$id, $langs->trans("DeleteMember"), $langs->trans("ConfirmDeleteMember"), "confirm_delete", $formquestion, 'no', 1);
} }
// Confirm add in spip // Confirm add in spip

View File

@ -1668,6 +1668,8 @@ class Adherent extends CommonObject
if ($result < 0) { $error++; $this->db->rollback(); return -1; } if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers // End call triggers
$this->datevalid = $now;
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }

View File

@ -531,7 +531,7 @@ class Paiement extends CommonObject
{ {
if ($accountid <= 0) if ($accountid <= 0)
{ {
$this->error='Bad value for parameter accountid'; $this->error='Bad value for parameter accountid='.$accountid;
dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR); dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
return -1; return -1;
} }

View File

@ -210,7 +210,7 @@ function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='yo
} }
// For multicompany // For multicompany
if (! empty($out)) $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities if (! empty($out) && ! empty($conf->multicompany->enabled)) $out.="&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
return $out; return $out;
} }

View File

@ -142,12 +142,17 @@ function llxFooterVierge()
// Action called when page is submitted // Action called when page is submitted
if ($action == 'add') if ($action == 'add')
{ {
$error = 0;
$urlback='';
$db->begin();
// test if login already exists // test if login already exists
if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
{ {
if(! GETPOST('login')) if(! GETPOST('login'))
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Login"))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Login"))."<br>\n";
} }
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape(GETPOST('login'))."'"; $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape(GETPOST('login'))."'";
@ -158,52 +163,52 @@ if ($action == 'add')
} }
if ($num !=0) if ($num !=0)
{ {
$error+=1; $error++;
$langs->load("errors"); $langs->load("errors");
$errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n"; $errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n";
} }
if (!isset($_POST["pass1"]) || !isset($_POST["pass2"]) || $_POST["pass1"] == '' || $_POST["pass2"] == '' || $_POST["pass1"]!=$_POST["pass2"]) if (!isset($_POST["pass1"]) || !isset($_POST["pass2"]) || $_POST["pass1"] == '' || $_POST["pass2"] == '' || $_POST["pass1"]!=$_POST["pass2"])
{ {
$error+=1; $error++;
$langs->load("errors"); $langs->load("errors");
$errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n"; $errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n";
} }
if (! GETPOST("email")) if (! GETPOST("email"))
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("EMail"))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("EMail"))."<br>\n";
} }
} }
if (GETPOST('type') <= 0) if (GETPOST('type') <= 0)
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"))."<br>\n";
} }
if (! in_array(GETPOST('morphy'),array('mor','phy'))) if (! in_array(GETPOST('morphy'),array('mor','phy')))
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Nature'))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Nature'))."<br>\n";
} }
if (empty($_POST["lastname"])) if (empty($_POST["lastname"]))
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Lastname"))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Lastname"))."<br>\n";
} }
if (empty($_POST["firstname"])) if (empty($_POST["firstname"]))
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Firstname"))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Firstname"))."<br>\n";
} }
if (GETPOST("email") && ! isValidEmail(GETPOST("email"))) if (GETPOST("email") && ! isValidEmail(GETPOST("email")))
{ {
$error+=1; $error++;
$langs->load("errors"); $langs->load("errors");
$errmsg .= $langs->trans("ErrorBadEMail",GETPOST("email"))."<br>\n"; $errmsg .= $langs->trans("ErrorBadEMail",GETPOST("email"))."<br>\n";
} }
$birthday=dol_mktime($_POST["birthhour"],$_POST["birthmin"],$_POST["birthsec"],$_POST["birthmonth"],$_POST["birthday"],$_POST["birthyear"]); $birthday=dol_mktime($_POST["birthhour"],$_POST["birthmin"],$_POST["birthsec"],$_POST["birthmonth"],$_POST["birthday"],$_POST["birthyear"]);
if ($_POST["birthmonth"] && empty($birthday)) if ($_POST["birthmonth"] && empty($birthday))
{ {
$error+=1; $error++;
$langs->load("errors"); $langs->load("errors");
$errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n"; $errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n";
} }
@ -211,7 +216,7 @@ if ($action == 'add')
{ {
if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0) if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0)
{ {
$error+=1; $error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n"; $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n";
} }
} }
@ -258,6 +263,9 @@ if ($action == 'add')
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$object = $adh; $object = $adh;
$adht = new AdherentType($db);
$adht->fetch($object->typeid);
if ($object->email) if ($object->email)
{ {
$subject = ''; $subject = '';
@ -302,10 +310,23 @@ if ($action == 'add')
if (! empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && ! empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) && if (! empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && ! empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) &&
! empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL) ) ! empty($conf->global->ADHERENT_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=$adh->makeSubstitution($conf->global->MAIN_INFO_SOCIETE_MAIL); $to=$adh->makeSubstitution($conf->global->MAIN_INFO_SOCIETE_MAIL);
$from=$conf->global->ADHERENT_MAIL_FROM; $from=$conf->global->ADHERENT_MAIL_FROM;
$mailfile = new CMailFile( $mailfile = new CMailFile(
$conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT, '['.$appli.'] '.$conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT,
$to, $to,
$from, $from,
$adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL), $adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL),
@ -332,7 +353,7 @@ if ($action == 'add')
} }
else $urlback=$_SERVER["PHP_SELF"]."?action=added"; else $urlback=$_SERVER["PHP_SELF"]."?action=added";
if (! empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) if (! empty($conf->global->MEMBER_NEWFORM_PAYONLINE) && $conf->global->MEMBER_NEWFORM_PAYONLINE != '-1')
{ {
if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'all') if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'all')
{ {
@ -343,7 +364,7 @@ if ($action == 'add')
{ {
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{ {
$urlback.='&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2)); $urlback.='&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2));
} }
else else
{ {
@ -377,7 +398,7 @@ if ($action == 'add')
{ {
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
{ {
$urlback.='&securekey='.urlencode(dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2)); $urlback.='&securekey='.urlencode(dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2));
} }
else else
{ {
@ -394,7 +415,7 @@ if ($action == 'add')
{ {
if (! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
{ {
$urlback.='&securekey='.urlencode(dol_hash($conf->global->STRIPE_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2)); $urlback.='&securekey='.urlencode(dol_hash($conf->global->STRIPE_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2));
} }
else else
{ {
@ -411,14 +432,25 @@ if ($action == 'add')
if (! empty($entity)) $urlback.='&entity='.$entity; if (! empty($entity)) $urlback.='&entity='.$entity;
dol_syslog("member ".$adh->ref." was created, we redirect to ".$urlback); dol_syslog("member ".$adh->ref." was created, we redirect to ".$urlback);
Header("Location: ".$urlback);
exit;
} }
else else
{ {
$error++;
$errmsg .= join('<br>',$adh->errors); $errmsg .= join('<br>',$adh->errors);
} }
} }
if (! $error)
{
$db->commit();
Header("Location: ".$urlback);
exit;
}
else
{
$db->rollback();
}
} }
// Action called after a submitted was send and member created successfully // Action called after a submitted was send and member created successfully

View File

@ -312,13 +312,26 @@ if ($ispaymentok)
// Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
if (! empty($FinalPaymentAmt) && $paymentTypeId > 0) if (! empty($FinalPaymentAmt) && $paymentTypeId > 0)
{ {
$result = $object->validate($user);
if ($result < 0 || empty($object->datevalid))
{
$error++;
$errmsg=$object->error;
$postactionmessages[] = $errmsg;
$postactionmessages = array_merge($postactionmessages, $object->errors);
$ispostactionok = -1;
}
// Subscription informations // Subscription informations
$datesubscription=$object->datevalid; $datesubscription=$object->datevalid;
if ($object->datefin > 0) if ($object->datefin > 0)
{ {
$datesubscription=dol_time_plus_duree($object->datefin,1,'d'); $datesubscription=dol_time_plus_duree($object->datefin,1,'d');
} }
$datesubend=dol_time_plus_duree(dol_time_plus_duree($datesubscription,$defaultdelay,$defaultdelayunit),-1,'d');
$datesubend = null;
if ($datesubscription && $defaultdelay && $defaultdelayunit) $datesubend=dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit),-1,'d');
$paymentdate=$now; $paymentdate=$now;
$amount = $FinalPaymentAmt; $amount = $FinalPaymentAmt;
$label='Online subscription '.dol_print_date($now, 'standard').' using '.$paymentmethod.' from '.$ipaddress.' - Transaction ID = '.$TRANSACTIONID; $label='Online subscription '.dol_print_date($now, 'standard').' using '.$paymentmethod.' from '.$ipaddress.' - Transaction ID = '.$TRANSACTIONID;
@ -328,6 +341,14 @@ if ($ispaymentok)
if ($paymentmethod == 'paybox') $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; if ($paymentmethod == 'paybox') $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
if ($paymentmethod == 'paypal') $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; if ($paymentmethod == 'paypal') $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
if ($paymentmethod == 'stripe') $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; if ($paymentmethod == 'stripe') $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
if ($accountid < 0)
{
$error++;
$errmsg='Setup of bank accout to use for payment is not correctly done for payment method '.$paymentmethod;
$postactionmessages[] = $errmsg;
$ispostactionok = -1;
}
$operation=$paymentType; // Payment mode code $operation=$paymentType; // Payment mode code
$num_chq=''; $num_chq='';
$emetteur_nom=''; $emetteur_nom='';
@ -344,18 +365,21 @@ if ($ispaymentok)
$db->begin(); $db->begin();
// Create subscription // Create subscription
$crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend); if (! $error)
if ($crowid <= 0)
{ {
$error++; $crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
$errmsg=$object->error; if ($crowid <= 0)
$postactionmessages[] = $errmsg; {
$ispostactionok = -1; $error++;
} $errmsg=$object->error;
else $postactionmessages[] = $errmsg;
{ $ispostactionok = -1;
$postactionmessages[]='Subscription created'; }
$ispostactionok=1; else
{
$postactionmessages[]='Subscription created';
$ispostactionok=1;
}
} }
if (! $error) if (! $error)
@ -404,7 +428,7 @@ if ($ispaymentok)
$outputlangs = new Translate('', $conf); $outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
$outputlangs->loadLangs(array("main", "members")); $outputlangs->loadLangs(array("main", "members"));
// Get email content fro mtemplae // Get email content from templae
$arraydefaultmessage=null; $arraydefaultmessage=null;
$labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION; $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;