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$contextpage =
GETPOST(
'contextpage');
48$optioncss =
GETPOST(
'optioncss',
'aZ');
50$contactid =
GETPOST(
'contactid',
'alpha');
55 $socid = $user->socid;
59$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;
88$permissiontoadd = $user->hasRight(
'societe',
'write');
95if (
GETPOST(
'cancel',
'alpha')) {
99$parameters = array(
'id' => $socid);
100$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
102 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
105if (empty($reshook)) {
109 if ($action ==
'add' && $permissiontoadd) {
110 if (empty($contactid)) {
111 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Contact")),
null,
'errors');
114 if ($actionid <= 0) {
115 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Action")),
null,
'errors');
123 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
124 $sql .=
" WHERE fk_soc=".((int) $socid).
" AND fk_contact=".((int) $contactid).
" AND fk_action = ".((int) $actionid);
125 if ($db->query($sql)) {
126 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"notify_def (datec,fk_soc, fk_contact, fk_action)";
127 $sql .=
" VALUES ('".$db->idate($now).
"', ".((int) $socid).
",".((int) $contactid).
",".((int) $actionid).
")";
129 if (!$db->query($sql)) {
131 dol_print_error($db);
134 dol_print_error($db);
147 if ($action ==
'delete' && $permissiontoadd) {
148 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
149 $sql .=
" WHERE rowid = ".GETPOSTINT(
'actid');
150 $sql .=
" AND fk_soc = ".((int) $socid);
161$form =
new Form($db);
163$title = $langs->trans(
"ThirdParty").
' - '.$langs->trans(
"Notification");
165 $title =
$object->name.
' - '.$langs->trans(
"Notification");
167$help_url =
'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
173 $langs->load(
"other");
177 print
dol_get_fiche_head($head,
'notify', $langs->trans(
"ThirdParty"), -1,
'company');
179 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
181 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
183 print
'<div class="fichecenter">';
185 print
'<div class="underbanner clearboth"></div>';
186 print
'<table class="border centpercent tableforfield">';
189 print
'<tr><td class="titlefield">'.$langs->trans(
'NatureOfThirdParty').
'</td><td>';
194 print
'<tr><td class="titlefield">';
195 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
197 $tmpcheck =
$object->check_codeclient();
198 if ($tmpcheck != 0 && $tmpcheck != -5) {
199 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
205 print
'<tr><td class="titlefield">';
206 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
208 $tmpcheck =
$object->check_codefournisseur();
209 if ($tmpcheck != 0 && $tmpcheck != -5) {
210 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
237 print
'<div class="info hideonsmartphone">';
238 print $langs->trans(
"NotificationsDesc");
239 print
'<br>'.$langs->trans(
"NotificationsDescUser");
240 print
'<br>'.$langs->trans(
"NotificationsDescContact").
' - '.$langs->trans(
"YouAreHere");
241 print
'<br>'.$langs->trans(
"NotificationsDescGlobal");
249 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.urlencode((
string) $socid).
'" method="POST">';
250 print
'<input type="hidden" name="token" value="'.newToken().
'">';
251 print
'<input type="hidden" name="page_y" value="">';
252 if ($action ==
'create') {
253 print
'<input type="hidden" name="action" id="action" value="add">';
256 $nbtotalofrecords =
'';
259 $sql =
"SELECT n.rowid, n.type,";
260 $sql .=
" a.code, a.label,";
261 $sql .=
" c.rowid as contactid, c.lastname, c.firstname, c.email";
262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as a,";
263 $sql .=
" ".MAIN_DB_PREFIX.
"notify_def as n,";
264 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as c";
265 $sql .=
" WHERE a.rowid = n.fk_action";
266 $sql .=
" AND c.rowid = n.fk_contact";
267 $sql .=
" AND c.fk_soc = ".((int)
$object->id);
269 $resql = $db->query($sql);
271 $nbtotalofrecords = $db->num_rows($resql);
273 dol_print_error($db);
276 $param =
"&socid=".((int) $socid);
278 $listofemails =
$object->thirdparty_and_contact_email_array();
281 $buttonstatus = $permissiontoadd ? 1 : 0;
282 if (empty($listofemails)) {
284 $helptext = $langs->trans(
"YouMustCreateContactFirst");
288 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'New'), $helptext,
'fa fa-plus-circle', $_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'&action=create&backtopage='.urlencode($_SERVER[
'PHP_SELF']),
'', $buttonstatus);
290 $titlelist = $form->textwithpicto($langs->trans(
"ListOfActiveNotifications"), $langs->trans(
"ListOfActiveNotificationsHelp", $langs->transnoentitiesnoconv(
"Target"), $langs->transnoentitiesnoconv(
"Event")));
292 $num = $nbtotalofrecords;
294 $limitforsubscription = 0;
297 print_barre_liste($titlelist, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, (empty($nbtotalofrecords) ? -1 : $nbtotalofrecords),
'email', 0, $newcardbutton,
'', $limitforsubscription, 0, 0, 1);
300 print
'<div class="div-table-responsive-no-min">';
301 print
'<table class="noborder centpercent">';
302 print
'<tr class="liste_titre">';
303 print_liste_field_titre(
"Target", $_SERVER[
"PHP_SELF"],
"c.lastname,c.firstname",
'', $param,
'width="45%"', $sortfield, $sortorder);
305 print_liste_field_titre(
"Type", $_SERVER[
"PHP_SELF"],
"n.type",
'', $param,
'width="10%"', $sortfield, $sortorder);
310 if ($action ==
'create') {
311 if (count($listofemails) > 0) {
316 $listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents();
318 foreach ($listofmanagedeventfornotification as $managedeventfornotification) {
319 $label = ($langs->trans(
"Notify_".$managedeventfornotification[
'code']) !=
"Notify_".$managedeventfornotification[
'code'] ? $langs->trans(
"Notify_".$managedeventfornotification[
'code']) : $managedeventfornotification[
'label']);
320 $actions[$managedeventfornotification[
'rowid']] = $label;
323 $newlistofemails = array();
324 foreach ($listofemails as $tmpkey => $tmpval) {
325 $labelhtml = str_replace(array(
'<',
'>'), array(
' - <span class="opacitymedium">',
'</span>'), $tmpval);
326 $newlistofemails[$tmpkey] = array(
'label' =>
dol_string_nohtmltag($tmpval),
'id' => $tmpkey,
'data-html' => $labelhtml);
329 print
'<tr class="oddeven nohover">';
330 print
'<td class="nowraponall">';
331 print img_picto(
'',
'contact',
'', 0, 0, 0,
'',
'paddingright');
332 print $form->selectarray(
"contactid", $newlistofemails,
'', 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100imp maxwidthonsmartphone');
334 print
'<td class="tdoverflowmax200">';
335 print img_picto(
'',
'object_action',
'', 0, 0, 0,
'',
'paddingright');
336 print $form->selectarray(
"actionid", $actions,
'', 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100imp maxwidthonsmartphone');
339 $type = array(
'email' => $langs->trans(
"EMail"));
340 print $form->selectarray(
"typeid", $type,
'', 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth75imp');
342 print
'<td class="right nowraponall">';
343 print
'<input type="submit" class="button button-add small" value="'.$langs->trans(
"Add").
'">';
345 print
'<input type="submit" class="button button-cancel small" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
349 print
'<tr class="oddeven"><td colspan="4" class="opacitymedium">';
350 print $langs->trans(
"YouMustCreateContactFirst");
357 $contactstatic =
new Contact($db);
360 $obj = $db->fetch_object($resql);
362 $contactstatic->id = $obj->contactid;
363 $contactstatic->lastname = $obj->lastname;
364 $contactstatic->firstname = $obj->firstname;
366 print
'<tr class="oddeven">';
367 print
'<td>'.$contactstatic->getNomUrl(1);
368 if ($obj->type ==
'email') {
370 print
' <'.$obj->email.
'>';
372 $langs->load(
"errors");
373 print
' '.img_warning().
' <span class="warning">'.$langs->trans(
"ErrorBadEMail", $obj->email).
'</span>';
378 $label = ($langs->trans(
"Notify_".$obj->code) !=
"Notify_".$obj->code ? $langs->trans(
"Notify_".$obj->code) : $obj->label);
379 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($label).
'">';
380 print img_picto(
'',
'object_action',
'', 0, 0, 0,
'',
'pictofixedwidth').$label;
383 if ($obj->type ==
'email') {
384 print $langs->trans(
"Email");
386 if ($obj->type ==
'sms') {
387 print $langs->trans(
"SMS");
390 print
'<td class="right"><a href="card.php?socid='.$socid.
'&action=delete&token='.
newToken().
'&actid='.$obj->rowid.
'">'.img_delete().
'</a></td>';
396 print
'<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
406 print
'<br><br>'.
"\n";
410 $sql =
"SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,";
411 $sql .=
" c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
412 $sql .=
" a.code, a.label";
413 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as a,";
414 $sql .=
" ".MAIN_DB_PREFIX.
"notify as n ";
415 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as c ON n.fk_contact = c.rowid";
416 $sql .=
" WHERE a.rowid = n.fk_action";
417 $sql .=
" AND n.fk_soc = ".((int)
$object->id);
418 $sql .= $db->order($sortfield, $sortorder);
421 $nbtotalofrecords =
'';
423 $result = $db->query($sql);
424 $nbtotalofrecords = $db->num_rows($result);
425 if (($page * $limit) > (int) $nbtotalofrecords) {
431 $sql .= $db->plimit($limit + 1, $offset);
433 $resql = $db->query($sql);
435 $num = $db->num_rows($resql);
437 dol_print_error($db);
440 $param =
'&socid='.$object->id;
441 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
442 $param .=
'&contextpage='.$contextpage;
444 if ($limit > 0 && $limit !=
$conf->liste_limit) {
445 $param .=
'&limit='.$limit;
448 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'" name="formfilter">';
449 if ($optioncss !=
'') {
450 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
452 print
'<input type="hidden" name="token" value="'.newToken().
'">';
453 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
454 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
455 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
456 print
'<input type="hidden" name="page" value="'.$page.
'">';
457 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
459 $titlelist = $form->textwithpicto($langs->trans(
"ListOfNotificationsDone"), $langs->trans(
"ListOfNotificationsDoneHelp"));
462 print_barre_liste($titlelist, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, empty($nbtotalofrecords) ? -1 : $nbtotalofrecords,
'email', 0,
'',
'', $limit,
'');
465 print
'<div class="div-table-responsive-no-min">';
466 print
'<table class="centpercent noborder">';
467 print
'<tr class="liste_titre">';
468 print_liste_field_titre(
"Target", $_SERVER[
"PHP_SELF"],
"c.lastname,c.firstname",
'', $param,
'', $sortfield, $sortorder);
472 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"n.daten",
'', $param,
'', $sortfield, $sortorder,
'right ');
478 $contactstatic =
new Contact($db);
481 $obj = $db->fetch_object($resql);
483 print
'<tr class="oddeven"><td>';
485 $contactstatic->id = $obj->id;
486 $contactstatic->lastname = $obj->lastname;
487 $contactstatic->firstname = $obj->firstname;
488 print $contactstatic->getNomUrl(1);
489 print $obj->email ?
' <'.$obj->email.
'>' : $langs->trans(
"NoMail");
495 $label = ($langs->trans(
"Notify_".$obj->code) !=
"Notify_".$obj->code ? $langs->trans(
"Notify_".$obj->code) : $obj->label);
499 if ($obj->type ==
'email') {
500 print $langs->trans(
"Email");
502 if ($obj->type ==
'sms') {
503 print $langs->trans(
"Sms");
516 print
'<td class="right">'.dol_print_date($db->jdate($obj->daten),
'dayhour').
'</td>';
522 print
'<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
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.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.