26 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/partnership/lib/partnership.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
67 global $conf, $langs, $user;
71 if ($managedfor !=
'member') {
76 $MAXPERCALL = (empty($conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL) ? 25 : $conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL);
78 $langs->loadLangs(array(
"partnership",
"member"));
84 $partnershipsprocessed = array();
86 $gracedelay = $conf->global->PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL;
87 if ($gracedelay < 1) {
88 $this->error =
'BadValueForDelayBeforeCancelCheckSetup';
92 dol_syslog(get_class($this).
"::doCancelStatusOfMemberPartnership cancel expired partnerships with grace delay of ".$gracedelay);
99 $sql =
"SELECT p.rowid, p.fk_member, p.status";
100 $sql .=
", d.datefin, d.fk_adherent_type, dty.subscription";
101 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p";
102 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as d on (d.rowid = p.fk_member)";
103 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent_type as dty on (dty.rowid = d.fk_adherent_type)";
104 $sql .=
" WHERE fk_member > 0";
105 $sql .=
" AND (d.datefin < '".$this->db->idate($datetotest).
"' AND dty.subscription = 1)";
106 $sql .=
" AND p.status = ".((int) $partnership::STATUS_APPROVED);
107 $sql .= $this->
db->order(
'd.rowid',
'ASC');
112 $numofexpiredmembers = $this->
db->num_rows(
$resql);
114 $somethingdoneonpartnership = 0;
116 while ($ifetchpartner < $numofexpiredmembers) {
119 $obj = $this->
db->fetch_object(
$resql);
121 if (!empty($partnershipsprocessed[$obj->rowid]))
continue;
123 if ($somethingdoneonpartnership >= $MAXPERCALL) {
124 dol_syslog(
"We reach the limit of ".$MAXPERCALL.
" partnership processed, so we quit loop for this batch doCancelStatusOfMemberPartnership to avoid to reach email quota.", LOG_WARNING);
129 $object->fetch($obj->rowid);
132 $expirationdate = $obj->datefin;
134 if ($expirationdate && $expirationdate < $now) {
135 $somethingdoneonpartnership++;
137 $result = $object->cancel($user, 0);
141 $this->error = $object->error;
142 if (is_array($object->errors) && count($object->errors)) {
143 if (is_array($this->errors)) $this->errors = array_merge($this->errors, $object->errors);
144 else $this->errors = $object->errors;
147 $partnershipsprocessed[$object->id] = $object->ref;
150 $labeltemplate =
'(SendingEmailOnPartnershipCanceled)';
152 dol_syslog(
"Now we will send an email to member id=".$object->fk_member.
" with label ".$labeltemplate);
155 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
156 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
160 $outputlangs = $langs;
163 if (!empty($newlang)) {
165 $outputlangs->setDefaultLang($newlang);
166 $outputlangs->loadLangs(array(
'main',
'member',
'partnership'));
169 $arraydefaultmessage = $formmail->getEMailTemplate($this->
db,
'partnership_send', $user, $outputlangs, 0, 1, $labeltemplate);
174 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
175 $msg =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
176 $from =
dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM,
' ', array(
",")).
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
179 $adherent->fetch($object->fk_member);
180 $to = $adherent->email;
182 $cmail =
new CMailFile($subject, $to, $from, $msg, array(), array(), array(),
'',
'', 0, 1);
183 $result = $cmail->sendfile();
184 if (!$result || $cmail->error) {
185 $erroremail .= ($erroremail ?
', ' :
'').$cmail->error;
186 $this->errors[] = $cmail->error;
187 if (is_array($cmail->errors) && count($cmail->errors) > 0) $this->errors += $cmail->errors;
195 $this->error = $this->
db->lasterror();
200 $this->output = $numofexpiredmembers.
' expired partnership members found'.
"\n";
201 if ($erroremail) $this->output .=
'. Got errors when sending some email : '.$erroremail;
203 $this->
db->rollback();
204 $this->output =
"Rollback after error\n";
205 $this->output .= $numofexpiredmembers.
' expired partnership members found'.
"\n";
206 if ($erroremail) $this->output .=
'. Got errors when sending some email : '.$erroremail;
222 global $conf, $langs, $user;
227 $MAXPERCALL = (empty($conf->global->PARTNERSHIP_MAX_WARNING_BACKLINK_PER_CALL) ? 10 : $conf->global->PARTNERSHIP_MAX_WARNING_BACKLINK_PER_CALL);
229 $langs->loadLangs(array(
"partnership",
"member"));
235 $partnershipsprocessed = array();
237 $gracedelay = $conf->global->PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL;
238 if ($gracedelay < 1) {
239 $this->error =
'BadValueForDelayBeforeCancelCheckSetup';
243 $fk_partner = ($managedfor ==
'member') ?
'fk_member' :
'fk_soc';
245 dol_syslog(get_class($this).
"::doWarningOfPartnershipIfDolibarrBacklinkNotfound Warning of partnership");
252 $sql =
"SELECT p.rowid, p.status, p.".$fk_partner;
253 $sql .=
", p.last_check_backlink";
255 $sql .=
', partner.url, partner.email';
257 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p";
259 if ($managedfor ==
'member') {
260 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as partner on (partner.rowid = p.fk_member)";
262 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as partner on (partner.rowid = p.fk_soc)";
265 $sql .=
" WHERE 1 = 1";
266 $sql .=
" AND p.".$fk_partner.
" > 0";
267 $sql .=
" AND p.status = ".((int) $partnership::STATUS_APPROVED);
268 $sql .=
" AND (p.last_check_backlink IS NULL OR p.last_check_backlink <= '".$this->db->idate($now - 7 * 24 * 3600).
"')";
269 $sql .= $this->
db->order(
'p.rowid',
'ASC');
274 $numofexpiredmembers = $this->
db->num_rows(
$resql);
275 $somethingdoneonpartnership = 0;
277 $websitenotfound =
'';
278 while ($ifetchpartner < $numofexpiredmembers) {
281 $obj = $this->
db->fetch_object(
$resql);
283 if (!empty($partnershipsprocessed[$obj->rowid]))
continue;
285 if ($somethingdoneonpartnership >= $MAXPERCALL) {
286 dol_syslog(
"We reach the limit of ".$MAXPERCALL.
" partnership processed, so we quit loop for this batch doWarningOfPartnershipIfDolibarrBacklinkNotfound to avoid to reach email quota.", LOG_WARNING);
293 $object->fetch($obj->rowid);
295 if ($managedfor ==
'member') {
296 $fk_partner = $object->fk_member;
298 $fk_partner = $object->fk_soc;
301 $website = $obj->url;
303 if (empty($website)) {
304 $websitenotfound .= ($websitenotfound ?
', ' :
'').
'Website not found for id="'.$fk_partner.
'"'.
"\n";
309 if (!$backlinkfound) {
310 $tmpcount = $object->count_last_url_check_error + 1;
312 if ($tmpcount > 2 && $tmpcount <= 4) {
313 if (!empty($obj->email)) {
314 $emailnotfound .= ($emailnotfound ?
', ' :
'').
'Email not found for id="'.$fk_partner.
'"'.
"\n";
316 $labeltemplate =
'(SendingEmailOnPartnershipWillSoonBeCanceled)';
318 dol_syslog(
"Now we will send an email to partner id=".$fk_partner.
" with label ".$labeltemplate);
321 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
322 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
326 $outputlangs = $langs;
329 if (!empty($newlang)) {
331 $outputlangs->setDefaultLang($newlang);
332 $outputlangs->loadLangs(array(
'main',
'member',
'partnership'));
335 $arraydefaultmessage = $formmail->getEMailTemplate($this->
db,
'partnership_send', $user, $outputlangs, 0, 1, $labeltemplate);
340 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
341 $msg =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
342 $from =
dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM,
' ', array(
",")).
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
346 $cmail =
new CMailFile($subject, $to, $from, $msg, array(), array(), array(),
'',
'', 0, 1);
347 $result = $cmail->sendfile();
348 if (!$result || $cmail->error) {
349 $erroremail .= ($erroremail ?
', ' :
'').$cmail->error;
350 $this->errors[] = $cmail->error;
351 if (is_array($cmail->errors) && count($cmail->errors) > 0) $this->errors += $cmail->errors;
354 } elseif ($tmpcount > 4) {
355 $object->status = $object::STATUS_CANCELED;
356 $object->reason_decline_or_cancel = $langs->trans(
'BacklinkNotFoundOnPartnerWebsite');
359 $object->count_last_url_check_error = $tmpcount;
361 $object->count_last_url_check_error = 0;
362 $object->reason_decline_or_cancel =
'';
365 $partnershipsprocessed[$object->id] = $object->ref;
367 $object->last_check_backlink = $this->
db->idate($now);
369 $object->update($user);
374 $this->error = $this->
db->lasterror();
379 $this->output = $numofexpiredmembers.
' partnership checked'.
"\n";
380 if ($erroremail) $this->output .=
'. Got errors when sending some email : '.$erroremail.
"\n";
381 if ($emailnotfound) $this->output .=
'. Email not found for some partner : '.$emailnotfound.
"\n";
382 if ($websitenotfound) $this->output .=
'. Website not found for some partner : '.$websitenotfound.
"\n";
384 $this->
db->rollback();
385 $this->output =
"Rollback after error\n";
386 $this->output .= $numofexpiredmembers.
' partnership checked'.
"\n";
387 if ($erroremail) $this->output .=
'. Got errors when sending some email : '.$erroremail.
"\n";
388 if ($emailnotfound) $this->output .=
'. Email not found for some partner : '.$emailnotfound.
"\n";
389 if ($websitenotfound) $this->output .=
'. Website not found for some partner : '.$websitenotfound.
"\n";
403 global $conf, $langs, $user;
410 $tmpgeturl =
getURLContent($website,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
411 if ($tmpgeturl[
'curl_error_no']) {
413 dol_syslog(
'Error getting '.$website.
': '.$tmpgeturl[
'curl_error_msg']);
414 } elseif ($tmpgeturl[
'http_code'] !=
'200') {
416 dol_syslog(
'Error getting '.$website.
': '.$tmpgeturl[
'curl_error_msg']);
418 $urlContent = $tmpgeturl[
'content'];
419 $dom =
new DOMDocument();
420 @$dom->loadHTML($urlContent);
422 $xpath =
new DOMXPath($dom);
423 $hrefs = $xpath->evaluate(
"//a");
425 for ($i = 0; $i < $hrefs->length; $i++) {
426 $href = $hrefs->item($i);
427 $url = $href->getAttribute(
'href');
428 $url = filter_var($url, FILTER_SANITIZE_URL);
429 if (!filter_var($url, FILTER_VALIDATE_URL) ===
false) {
435 if ($webcontent && !empty($conf->global->PARTNERSHIP_BACKLINKS_TO_CHECK) && preg_match(
'/'.$conf->global->PARTNERSHIP_BACKLINKS_TO_CHECK.
'/', $webcontent)) {
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class with cron tasks of Partnership module.
doWarningOfPartnershipIfDolibarrBacklinkNotfound()
Action executed by scheduler to check if Dolibarr backlink not found on partner website.
checkDolibarrBacklink($website=null)
Action to check if Dolibarr backlink not found on partner website.
__construct($db)
Constructor.
$errors
To return several error codes (or messages)
$error
To return error code (or message)
doCancelStatusOfMemberPartnership()
Action executed by scheduler to cancel status of partnership when subscription is expired + x days.
Class to manage translations.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$conf db
API class for accounts.