37if (!defined(
'NOLOGIN')) {
40if (!defined(
'NOCSRFCHECK')) {
41 define(
"NOCSRFCHECK", 1);
43if (!defined(
'NOBROWSERNOTIF')) {
44 define(
'NOBROWSERNOTIF',
'1');
51$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
53define(
"DOLENTITY", $entity);
58require
'../../main.inc.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
66require_once DOL_DOCUMENT_ROOT.
'/core/class/cunits.class.php';
67require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
69 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
73$backtopage =
GETPOST(
'backtopage',
'alpha');
74$action =
GETPOST(
'action',
'aZ09');
76$paymentmethod =
GETPOST(
'paymentmethod',
'aZ09');
92$langs->loadLangs(array(
"main",
"donations",
"companies",
"install",
"other",
"errors"));
114$user->loadDefaultValues();
131function llxHeaderVierge($title, $head =
"", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $ws =
'')
133 global $conf, $langs,
$mysoc;
135 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
137 print
'<body id="mainbody" class="publicnewmemberform">';
140 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
144 print
'<div class="divmainbodylarge">';
156 global $conf, $langs;
162 if (!empty($conf->use_javascript_ajax)) {
163 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
164 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
177$parameters = array();
179$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
185if (empty($reshook) && $action ==
'add') {
189 $email =
GETPOST(
"email",
"aZ09arobase");
190 $firstname =
GETPOST(
"firstname",
"aZ09");
191 $lastname =
GETPOST(
"lastname",
"aZ09");
192 $societe =
GETPOST(
"societe",
"aZ09");
193 $idprof2 =
GETPOST(
"idprof2",
"aZ09");
194 $tva_intra =
GETPOST(
"tva_intra",
"aZ09");
196 $zipcode =
GETPOST(
"zipcode",
"aZ09");
197 $town =
GETPOST(
"town",
"aZ09");
199 $amount = (float)
GETPOST(
"amount",
"int");
201 $productIdForFreeAmountInvoice = (int)
getDolGlobalString(
'PRODUCT_ID_FOR_FREE_AMOUNT_INVOICE');
204 $langs->load(
'errors');
206 $errmsg .= $langs->trans(
"ErrorBadEMail", $email).
"<br>\n";
208 if ($firstname && !preg_match(
'/^[a-zA-Z0-9À-ÖØ-öø-ÿ \'\-]*$/u', $firstname)) {
209 $langs->load(
'errors');
211 $errmsg .= $langs->trans(
"firstnameContainsLettersOnly").
"<br>\n";
213 if ($lastname && !preg_match(
'/^[a-zA-Z0-9À-ÖØ-öø-ÿ \'\-]*$/u', $lastname)) {
214 $langs->load(
'errors');
216 $errmsg .= $langs->trans(
"lastnameContainsLettersOnly").
"<br>\n";
219 $langs->load(
'errors');
221 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"companyBusinessNumber")).
"<br>\n";
224 $langs->load(
'errors');
226 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Address")).
"<br>\n";
229 $langs->load(
'errors');
231 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Zip")).
"<br>\n";
234 $langs->load(
'errors');
236 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Town")).
"<br>\n";
239 $langs->load(
'errors');
241 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Country")).
"<br>\n";
244 $langs->load(
'errors');
246 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Company")).
"<br>\n";
250 $result = $company->findNearest(0,
'',
'',
'',
'', $idprof2,
'',
'',
'',
'', $email);
252 $companyId = $result;
253 } elseif ($result < 0) {
255 $errmsg .= $langs->trans(
"donationErrorMessageContactEmail",
$mysoc->email).
"<br>\n";
258 if (!$amount || $amount <= (
float)
getDolGlobalString(
"DONATION_INVOICE_MIN_AMOUNT")) {
260 $errmsg .= $langs->trans(
"ErrorFieldMinimumAmount", (
float)
getDolGlobalString(
"DONATION_INVOICE_MIN_AMOUNT")).
"<br>\n";
264 $sessionkey =
'dol_antispam_value';
265 $ok = (array_key_exists($sessionkey, $_SESSION) && (strtolower($_SESSION[$sessionkey]) == strtolower(
GETPOST(
'code'))));
268 $langs->load(
"errors");
269 $errmsg .= $langs->trans(
"ErrorBadValueForCode").
"<br>\n";
279 if (!$error && $companyId <= 0) {
283 if (!empty($societe)) {
284 $company->name = $societe;
289 $company->name_alias =
"";
290 $company->idprof2 = $idprof2;
291 $company->address = $address;
292 $company->zip = $zipcode;
293 $company->town = $town;
294 $company->country_id = $country_id;
295 $company->email = $email;
296 $company->client = 1;
297 $company->code_client =
'auto';
298 $company->status = 1;
299 $company->tva_intra = $tva_intra;
303 $result = $company->create($user);
305 $langs->load(
'errors');
307 $errmsg .= implode(
'<br>', $company->errors).
"<br>\n";
309 $companyId = $result;
313 if (!$error && $companyId > 0) {
314 $invoice->socid = $companyId;
316 $invoice->cond_reglement_id = 1;
318 $invoice->module_source =
'donation';
320 $invoice->module_source .=
'@' . $ws;
325 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 1);
330 if ($nb_post_max > 0) {
331 $sql =
"SELECT COUNT(rowid) as nb_invoice";
332 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture";
333 $sql .=
" WHERE ip = '".$db->escape($invoice->ip).
"'";
334 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
335 $resql = $db->query($sql);
337 $num = $db->num_rows($resql);
341 $obj = $db->fetch_object($resql);
342 $nb_post_ip = $obj->nb_invoice;
347 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
349 $errmsg .= $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
350 array_push($invoice->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
354 $result = $invoice->create($user);
357 $errmsg .= $invoice->error.
"<br>\n";
362 $issuerCompany =
new Societe($db);
363 $result = $issuerCompany->fetch($companyId);
366 $errmsg .= $issuerCompany->error.
"<br>\n";
373 $result = $product->fetch($productIdForFreeAmountInvoice);
376 $errmsg .= $product->error.
"<br>\n";
378 $desc = $product->label;
379 $productId = $product->id;
381 $result = $invoice->addline($desc, $amount, 1, $tva_tx, 0, 0, $productId, 0,
"",
"", 0, 0, 0,
'TTC', $amount);
384 $errmsg .= $invoice->error.
"<br>\n";
398 $urlback = getOnlinePaymentUrl(0,
'invoice', (
string) $invoice->ref, 0,
'');
400 $urlback .= (strpos($urlback,
'?') ?
'&' :
'?').
'ws='.urlencode($ws);
402 if ($paymentmethod) {
403 $urlback .= (strpos($urlback,
'?') ?
'&' :
'?').
'paymentmethod='.urlencode($paymentmethod);
407 header(
"Location: ".$urlback);
419if (empty($reshook) && $action ==
'added') {
424 print
'<div class="center">';
425 print $langs->trans(
"NewDonationbyWeb").
'<br>';
437$form =
new Form($db);
439$extrafields->fetch_name_optionals_label(
$object->table_element);
442llxHeaderVierge($langs->trans(
"NewDonation"),
'', 0, 0, array(), array(), $ws);
445 print
load_fiche_titre(
img_picto(
'',
'',
'class="pictofixedwidth"').
' '.$langs->trans(
"NewDonation"),
'',
'', 0,
'',
'center');
448 print
'<div align="center">';
449 print
'<div id="divsubscribe">';
451 print
'<div class="center subscriptionformhelptext opacitymedium justify">';
452 print $langs->trans(
"NewDonationDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
461print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newdonation">'.
"\n";
462print
'<input type="hidden" name="token" value="'.newToken().
'" />';
463print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
464print
'<input type="hidden" name="page_y" value="" />';
466if (!$action || $action ==
'create') {
467 print
'<input type="hidden" name="action" value="add" />';
468 print
'<input type="hidden" name="ws" value="'.$ws.
'">';
469 print
'<input type="hidden" name="paymentmethod" value="'.$paymentmethod.
'">';
472 $messagemandatory =
'<span class="">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span>';
478 print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
483 print
'<td class="project-label">' . $langs->trans(
"project") .
'</td>';
489 print
'<tr id="tremail"><td class="fieldrequired minwidth300">'.$langs->trans(
"Email").
'</td><td>';
490 print
'<input type="email" name="email" maxlength="255" class="minwidth200" value="'.dol_escape_htmltag(
GETPOST(
'email',
"aZ09arobase")).
'"></td></tr>'.
"\n";
493 print
'<tr id="trcompany" class="trcompany"><td class="fieldrequired">'.$langs->trans(
"Company").
'</td><td>';
494 print
img_picto(
'',
'company',
'class="pictofixedwidth paddingright"');
495 print
'<input type="text" name="societe" class="minwidth300" value="'.dol_escape_htmltag(
GETPOST(
'societe')).
'"></td></tr>'.
"\n";
498 print
'<tr id="trfirstname"><td class="classfortooltip">'.$langs->trans(
"Firstname").
'</td><td><input type="text" name="firstname" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'firstname')).
'"></td></tr>'.
"\n";
501 print
'<tr id="trlastname"><td class="classfortooltip">'.$langs->trans(
"Lastname").
'</td><td><input type="text" name="lastname" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'lastname')).
'"></td></tr>'.
"\n";
504 print
'<tr id="tradress"><td class="fieldrequired">'.$langs->trans(
"Address").
'</td><td>'.
"\n";
505 print
'<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
dol_escape_htmltag(
GETPOST(
'address',
'restricthtml'), 0, 1).
'</textarea></td></tr>'.
"\n";
508 print
'<tr id="trzip"><td class="fieldrequired">'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
509 print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 0, 1,
'',
'width75');
511 print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
515 print
'<tr id="trcountry"><td class="fieldrequired">'.$langs->trans(
'Country').
'</td><td>';
516 print
img_picto(
'',
'country',
'class="pictofixedwidth paddingright"');
518 if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
522 $new_country_id =
getCountry($country_code,
'3', $db, $langs);
524 if ($new_country_id) {
525 $country_id = $new_country_id;
529 $country_code =
getCountry($country_id,
'2', $db, $langs);
530 print $form->select_country($country_id,
'country_id');
534 print
'<tr id="trsiret"><td class="fieldrequired">'.$langs->trans(
"companyBusinessNumber").
'</td><td><input type="text" name="idprof2" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'idprof2')).
'"></td></tr>'.
"\n";
537 print
'<tr id="trtva"><td>'.$langs->trans(
"companyTIN").
'</td><td><input type="text" name="tva_intra" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'tva_intra')).
'"></td></tr>'.
"\n";
539 print
'<tr><td colspan="2"><hr></td></tr>';
545 $amount = max(0, (
float) $amount, (
float)
getDolGlobalInt(
"DONATION_INVOICE_MIN_AMOUNT"));
549 $showedamount = $amount > 0 ? $amount : 5;
550 print
'<tr><td class="fieldrequired">'.$langs->trans(
"donationAmount");
551 print
'</td><td class="nowrap">';
553 print
'<input type="text" name="amount" id="amount" class="flat amount width50" value="'.$showedamount.
'">';
554 print
' '.$langs->trans(
"Currency".
getDolCurrency()).
'<span class="opacitymedium hideifautoturnover"> - ';
555 print $langs->trans(
"AnyAmountForDonation");
561 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
562 print
'<tr><td class="titlefield"><label><span class="fieldrequired">'.$langs->trans(
"SecurityCode").
'</span></label></td><td>';
563 print
'<span class="span-icon-security inline-block">';
564 print
'<input id="securitycode" placeholder="'.$langs->trans(
"SecurityCode").
'" class="flat input-icon-security width150" type="text" maxlength="5" name="code" tabindex="3" />';
566 print
'<span class="nowrap inline-block">';
567 print
'<img class="inline-block valignmiddle" src="'.DOL_URL_ROOT.
'/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />';
568 print
'<a class="inline-block valignmiddle" href="" tabindex="4" data-role="button">'.img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"').
'</a>';
579 print
'<div class="center">';
580 print
'<input type="submit" value="'.$langs->trans(
"GetDonationButtonLabel").
'" id="submitsave" class="button">';
581 if (!empty($backtopage)) {
582 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
589 print
'</div></div>';
if(! $sortfield) if(! $sortorder) $object
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
Show header for new prospect.
llxFooterVierge()
Show footer for new societe.
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_user_country()
Return country code for current user.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.