30require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/triggers/interface_50_modNotification_Notification.class.php';
43$langs->loadLangs(array(
"companies",
"mails",
"admin",
"other",
"errors"));
46$action =
GETPOST(
'action',
'aZ09');
47$contactid =
GETPOST(
'contactid',
'alpha');
49$optioncss =
GETPOST(
'optioncss',
'aZ');
53 $socid = $user->socid;
57$hookmanager->initHooks(array(
'thirdpartynotification',
'globalcard'));
62$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
63$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
69 $sortfield =
"n.daten";
71if (empty($page) || $page == -1) {
74$offset = $limit * $page;
83$permissiontoadd = $user->hasRight(
'societe',
'write');
90if (
GETPOST(
'cancel',
'alpha')) {
94$parameters = array(
'id' => $socid);
95$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
100if (empty($reshook)) {
104 if ($action ==
'add' && $permissiontoadd) {
105 if (empty($contactid)) {
106 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Contact")),
null,
'errors');
109 if ($actionid <= 0) {
110 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Action")),
null,
'errors');
118 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
119 $sql .=
" WHERE fk_soc=".((int) $socid).
" AND fk_contact=".((int) $contactid).
" AND fk_action = ".((int) $actionid);
120 if (
$db->query($sql)) {
121 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"notify_def (datec,fk_soc, fk_contact, fk_action)";
122 $sql .=
" VALUES ('".$db->idate($now).
"', ".((int) $socid).
",".((int) $contactid).
",".((int) $actionid).
")";
124 if (!
$db->query($sql)) {
142 if ($action ==
'delete' && $permissiontoadd) {
143 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def where rowid = ".
GETPOSTINT(
'actid');
157$result =
$object->fetch($socid);
159$title = $langs->trans(
"ThirdParty").
' - '.$langs->trans(
"Notification");
161 $title =
$object->name.
' - '.$langs->trans(
"Notification");
163$help_url =
'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
169 $langs->load(
"other");
173 print
dol_get_fiche_head($head,
'notify', $langs->trans(
"ThirdParty"), -1,
'company');
175 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
177 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
179 print
'<div class="fichecenter">';
181 print
'<div class="underbanner clearboth"></div>';
182 print
'<table class="border centpercent tableforfield">';
185 print
'<tr><td class="titlefield">'.$langs->trans(
'NatureOfThirdParty').
'</td><td>';
190 print
'<tr><td class="titlefield">';
191 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
193 $tmpcheck =
$object->check_codeclient();
194 if ($tmpcheck != 0 && $tmpcheck != -5) {
195 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
201 print
'<tr><td class="titlefield">';
202 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
204 $tmpcheck =
$object->check_codefournisseur();
205 if ($tmpcheck != 0 && $tmpcheck != -5) {
206 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
233 print
'<div class="info hideonsmartphone">';
234 print $langs->trans(
"NotificationsDesc");
235 print
'<br>'.$langs->trans(
"NotificationsDescUser");
236 print
'<br>'.$langs->trans(
"NotificationsDescContact").
' - '.$langs->trans(
"YouAreHere");
237 print
'<br>'.$langs->trans(
"NotificationsDescGlobal");
245 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.urlencode((
string) $socid).
'" method="POST">';
246 print
'<input type="hidden" name="token" value="'.newToken().
'">';
247 print
'<input type="hidden" name="page_y" value="">';
248 if ($action ==
'create') {
249 print
'<input type="hidden" name="action" id="action" value="add">';
252 $nbtotalofrecords =
'';
255 $sql =
"SELECT n.rowid, n.type,";
256 $sql .=
" a.code, a.label,";
257 $sql .=
" c.rowid as contactid, c.lastname, c.firstname, c.email";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as a,";
259 $sql .=
" ".MAIN_DB_PREFIX.
"notify_def as n,";
260 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as c";
261 $sql .=
" WHERE a.rowid = n.fk_action";
262 $sql .=
" AND c.rowid = n.fk_contact";
263 $sql .=
" AND c.fk_soc = ".((int)
$object->id);
265 $resql =
$db->query($sql);
267 $nbtotalofrecords =
$db->num_rows($resql);
272 $param =
"&socid=".((int) $socid);
274 $listofemails =
$object->thirdparty_and_contact_email_array();
277 $buttonstatus = $permissiontoadd ? 1 : 0;
278 if (empty($listofemails)) {
280 $helptext = $langs->trans(
"YouMustCreateContactFirst");
284 $newcardbutton .= dolGetButtonTitle($langs->trans(
'New'), $helptext,
'fa fa-plus-circle', $_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'&action=create&backtopage='.urlencode($_SERVER[
'PHP_SELF']),
'', $buttonstatus);
286 $titlelist = $form->textwithpicto($langs->trans(
"ListOfActiveNotifications"), $langs->trans(
"ListOfActiveNotificationsHelp", $langs->transnoentitiesnoconv(
"Target"), $langs->transnoentitiesnoconv(
"Event")));
288 $num = $nbtotalofrecords;
290 $limitforsubscription = 0;
293 print_barre_liste($titlelist, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, (empty($nbtotalofrecords) ? -1 : $nbtotalofrecords),
'email', 0, $newcardbutton,
'', $limitforsubscription, 0, 0, 1);
296 print
'<div class="div-table-responsive-no-min">';
297 print
'<table class="noborder centpercent">';
298 print
'<tr class="liste_titre">';
299 print_liste_field_titre(
"Target", $_SERVER[
"PHP_SELF"],
"c.lastname,c.firstname",
'', $param,
'width="45%"', $sortfield, $sortorder);
301 print_liste_field_titre(
"Type", $_SERVER[
"PHP_SELF"],
"n.type",
'', $param,
'width="10%"', $sortfield, $sortorder);
306 if ($action ==
'create') {
307 if (count($listofemails) > 0) {
312 $listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents();
314 foreach ($listofmanagedeventfornotification as $managedeventfornotification) {
315 $label = ($langs->trans(
"Notify_".$managedeventfornotification[
'code']) !=
"Notify_".$managedeventfornotification[
'code'] ? $langs->trans(
"Notify_".$managedeventfornotification[
'code']) : $managedeventfornotification[
'label']);
316 $actions[$managedeventfornotification[
'rowid']] = $label;
319 $newlistofemails = array();
320 foreach ($listofemails as $tmpkey => $tmpval) {
321 $labelhtml = str_replace(array(
'<',
'>'), array(
' - <span class="opacitymedium">',
'</span>'), $tmpval);
322 $newlistofemails[$tmpkey] = array(
'label' =>
dol_string_nohtmltag($tmpval),
'id' => $tmpkey,
'data-html' => $labelhtml);
325 print
'<tr class="oddeven nohover">';
326 print
'<td class="nowraponall">';
327 print
img_picto(
'',
'contact',
'', 0, 0, 0,
'',
'paddingright');
328 print $form->selectarray(
"contactid", $newlistofemails,
'', 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100imp maxwidthonsmartphone');
330 print
'<td class="tdoverflowmax200">';
331 print
img_picto(
'',
'object_action',
'', 0, 0, 0,
'',
'paddingright');
332 print $form->selectarray(
"actionid", $actions,
'', 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100imp maxwidthonsmartphone');
335 $type = array(
'email' => $langs->trans(
"EMail"));
336 print $form->selectarray(
"typeid", $type,
'', 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth75imp');
338 print
'<td class="right nowraponall">';
339 print
'<input type="submit" class="button button-add small" value="'.$langs->trans(
"Add").
'">';
341 print
'<input type="submit" class="button button-cancel small" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
345 print
'<tr class="oddeven"><td colspan="4" class="opacitymedium">';
346 print $langs->trans(
"YouMustCreateContactFirst");
356 $obj =
$db->fetch_object($resql);
358 $contactstatic->id = $obj->contactid;
359 $contactstatic->lastname = $obj->lastname;
360 $contactstatic->firstname = $obj->firstname;
362 print
'<tr class="oddeven">';
363 print
'<td>'.$contactstatic->getNomUrl(1);
364 if ($obj->type ==
'email') {
366 print
' <'.$obj->email.
'>';
368 $langs->load(
"errors");
369 print
' '.img_warning().
' <span class="warning">'.$langs->trans(
"ErrorBadEMail", $obj->email).
'</span>';
374 $label = ($langs->trans(
"Notify_".$obj->code) !=
"Notify_".$obj->code ? $langs->trans(
"Notify_".$obj->code) : $obj->label);
375 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($label).
'">';
376 print
img_picto(
'',
'object_action',
'', 0, 0, 0,
'',
'pictofixedwidth').$label;
379 if ($obj->type ==
'email') {
380 print $langs->trans(
"Email");
382 if ($obj->type ==
'sms') {
383 print $langs->trans(
"SMS");
386 print
'<td class="right"><a href="card.php?socid='.$socid.
'&action=delete&token='.newToken().
'&actid='.$obj->rowid.
'">'.
img_delete().
'</a></td>';
392 print
'<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
402 print
'<br><br>'.
"\n";
406 $sql =
"SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,";
407 $sql .=
" c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
408 $sql .=
" a.code, a.label";
409 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as a,";
410 $sql .=
" ".MAIN_DB_PREFIX.
"notify as n ";
411 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as c ON n.fk_contact = c.rowid";
412 $sql .=
" WHERE a.rowid = n.fk_action";
413 $sql .=
" AND n.fk_soc = ".((int)
$object->id);
414 $sql .=
$db->order($sortfield, $sortorder);
417 $nbtotalofrecords =
'';
419 $result =
$db->query($sql);
420 $nbtotalofrecords =
$db->num_rows($result);
421 if (($page * $limit) > (int) $nbtotalofrecords) {
427 $sql .=
$db->plimit($limit + 1, $offset);
429 $resql =
$db->query($sql);
431 $num =
$db->num_rows($resql);
436 $param =
'&socid='.$object->id;
437 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
438 $param .=
'&contextpage='.$contextpage;
440 if ($limit > 0 && $limit !=
$conf->liste_limit) {
441 $param .=
'&limit='.$limit;
444 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'" name="formfilter">';
445 if ($optioncss !=
'') {
446 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
448 print
'<input type="hidden" name="token" value="'.newToken().
'">';
449 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
450 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
451 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
452 print
'<input type="hidden" name="page" value="'.$page.
'">';
453 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
455 $titlelist = $form->textwithpicto($langs->trans(
"ListOfNotificationsDone"), $langs->trans(
"ListOfNotificationsDoneHelp"));
458 print_barre_liste($titlelist, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, empty($nbtotalofrecords) ? -1 : $nbtotalofrecords,
'email', 0,
'',
'', $limit,
'');
461 print
'<div class="div-table-responsive-no-min">';
462 print
'<table class="centpercent noborder">';
463 print
'<tr class="liste_titre">';
464 print_liste_field_titre(
"Target", $_SERVER[
"PHP_SELF"],
"c.lastname,c.firstname",
'', $param,
'', $sortfield, $sortorder);
468 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"n.daten",
'', $param,
'', $sortfield, $sortorder,
'right ');
477 $obj =
$db->fetch_object($resql);
479 print
'<tr class="oddeven"><td>';
481 $contactstatic->id = $obj->id;
482 $contactstatic->lastname = $obj->lastname;
483 $contactstatic->firstname = $obj->firstname;
484 print $contactstatic->getNomUrl(1);
485 print $obj->email ?
' <'.$obj->email.
'>' : $langs->trans(
"NoMail");
491 $label = ($langs->trans(
"Notify_".$obj->code) !=
"Notify_".$obj->code ? $langs->trans(
"Notify_".$obj->code) : $obj->label);
495 if ($obj->type ==
'email') {
496 print $langs->trans(
"Email");
498 if ($obj->type ==
'sms') {
499 print $langs->trans(
"Sms");
512 print
'<td class="right">'.dol_print_date(
$db->jdate($obj->daten),
'dayhour').
'</td>';
518 print
'<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
526 recordNotFound(
'', 0);
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class of triggers for notification module.
Class to manage third parties objects (customers, suppliers, prospects...)
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.