Skip to content

Commit

Permalink
Serious enhancement in auto subscription for member module
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 23, 2018
1 parent 53edb86 commit c7e93a5
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 43 deletions.
14 changes: 4 additions & 10 deletions htdocs/adherents/card.php
Expand Up @@ -1378,7 +1378,7 @@ function initfieldrequired()
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
Expand Down Expand Up @@ -1438,15 +1438,9 @@ function initfieldrequired()
if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) {
$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
if ($action == 'resign')
{
Expand Down Expand Up @@ -1499,15 +1493,15 @@ function initfieldrequired()
$formquestion=array();
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"]));
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
if ($action == 'delete')
{
$formquestion=array();
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
Expand Down
2 changes: 2 additions & 0 deletions htdocs/adherents/class/adherent.class.php
Expand Up @@ -1668,6 +1668,8 @@ function validate($user)
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers

$this->datevalid = $now;

$this->db->commit();
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/paiement/class/paiement.class.php
Expand Up @@ -531,7 +531,7 @@ function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_
{
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);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/payments.lib.php
Expand Up @@ -210,7 +210,7 @@ function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='yo
}

// 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;
}
Expand Down
68 changes: 50 additions & 18 deletions htdocs/public/members/new.php
Expand Up @@ -142,12 +142,17 @@ function llxFooterVierge()
// Action called when page is submitted
if ($action == 'add')
{
$error = 0;
$urlback='';

$db->begin();

// test if login already exists
if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
{
if(! GETPOST('login'))
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Login"))."<br>\n";
}
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape(GETPOST('login'))."'";
Expand All @@ -158,60 +163,60 @@ function llxFooterVierge()
}
if ($num !=0)
{
$error+=1;
$error++;
$langs->load("errors");
$errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n";
}
if (!isset($_POST["pass1"]) || !isset($_POST["pass2"]) || $_POST["pass1"] == '' || $_POST["pass2"] == '' || $_POST["pass1"]!=$_POST["pass2"])
{
$error+=1;
$error++;
$langs->load("errors");
$errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n";
}
if (! GETPOST("email"))
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("EMail"))."<br>\n";
}
}
if (GETPOST('type') <= 0)
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"))."<br>\n";
}
if (! in_array(GETPOST('morphy'),array('mor','phy')))
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Nature'))."<br>\n";
}
if (empty($_POST["lastname"]))
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Lastname"))."<br>\n";
}
if (empty($_POST["firstname"]))
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Firstname"))."<br>\n";
}
if (GETPOST("email") && ! isValidEmail(GETPOST("email")))
{
$error+=1;
$error++;
$langs->load("errors");
$errmsg .= $langs->trans("ErrorBadEMail",GETPOST("email"))."<br>\n";
}
$birthday=dol_mktime($_POST["birthhour"],$_POST["birthmin"],$_POST["birthsec"],$_POST["birthmonth"],$_POST["birthday"],$_POST["birthyear"]);
if ($_POST["birthmonth"] && empty($birthday))
{
$error+=1;
$error++;
$langs->load("errors");
$errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n";
}
if (! empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER))
{
if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0)
{
$error+=1;
$error++;
$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n";
}
}
Expand Down Expand Up @@ -258,6 +263,9 @@ function llxFooterVierge()
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$object = $adh;

$adht = new AdherentType($db);
$adht->fetch($object->typeid);

if ($object->email)
{
$subject = '';
Expand Down Expand Up @@ -302,10 +310,23 @@ function llxFooterVierge()
if (! empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && ! empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) &&
! 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);
$from=$conf->global->ADHERENT_MAIL_FROM;
$mailfile = new CMailFile(
$conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT,
'['.$appli.'] '.$conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT,
$to,
$from,
$adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL),
Expand All @@ -332,7 +353,7 @@ function llxFooterVierge()
}
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')
{
Expand All @@ -343,7 +364,7 @@ function llxFooterVierge()
{
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
{
Expand Down Expand Up @@ -377,7 +398,7 @@ function llxFooterVierge()
{
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
{
Expand All @@ -394,7 +415,7 @@ function llxFooterVierge()
{
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
{
Expand All @@ -411,14 +432,25 @@ function llxFooterVierge()

if (! empty($entity)) $urlback.='&entity='.$entity;
dol_syslog("member ".$adh->ref." was created, we redirect to ".$urlback);
Header("Location: ".$urlback);
exit;
}
else
{
$error++;
$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
Expand Down
50 changes: 37 additions & 13 deletions htdocs/public/payment/paymentok.php
Expand Up @@ -312,13 +312,26 @@
// 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)
{
$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
$datesubscription=$object->datevalid;
if ($object->datefin > 0)
{
$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;
$amount = $FinalPaymentAmt;
$label='Online subscription '.dol_print_date($now, 'standard').' using '.$paymentmethod.' from '.$ipaddress.' - Transaction ID = '.$TRANSACTIONID;
Expand All @@ -328,6 +341,14 @@
if ($paymentmethod == 'paybox') $accountid = $conf->global->PAYBOX_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 ($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
$num_chq='';
$emetteur_nom='';
Expand All @@ -344,18 +365,21 @@
$db->begin();

// Create subscription
$crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
if ($crowid <= 0)
{
$error++;
$errmsg=$object->error;
$postactionmessages[] = $errmsg;
$ispostactionok = -1;
}
else
if (! $error)
{
$postactionmessages[]='Subscription created';
$ispostactionok=1;
$crowid=$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
if ($crowid <= 0)
{
$error++;
$errmsg=$object->error;
$postactionmessages[] = $errmsg;
$ispostactionok = -1;
}
else
{
$postactionmessages[]='Subscription created';
$ispostactionok=1;
}
}

if (! $error)
Expand Down Expand Up @@ -404,7 +428,7 @@
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
$outputlangs->loadLangs(array("main", "members"));
// Get email content fro mtemplae
// Get email content from templae
$arraydefaultmessage=null;
$labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;

Expand Down

0 comments on commit c7e93a5

Please sign in to comment.