* Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2015 Marcos GarcĂ­a * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/societe/notify/card.php * \ingroup societe notification * \brief Tab for notifications of third party */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php'; $langs->loadLangs(array("companies", "mails", "admin", "other", "errors")); $socid = GETPOST("socid", 'int'); $action = GETPOST('action', 'aZ09'); $contactid = GETPOST('contactid', 'alpha'); // May be an int or 'thirdparty' $actionid = GETPOST('actionid', 'int'); $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') // Security check if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'societe', '', ''); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "n.daten"; } if (empty($page) || $page == -1) { $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $now = dol_now(); $object = new Societe($db); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('thirdpartynotification', 'globalcard')); /* * Actions */ $parameters = array('id'=>$socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { $error = 0; // Add a notification if ($action == 'add') { if (empty($contactid)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors'); $error++; } if ($actionid <= 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Action")), null, 'errors'); $error++; } if (!$error) { $db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; $sql .= " WHERE fk_soc=".((int) $socid)." AND fk_contact=".((int) $contactid)." AND fk_action=".((int) $actionid); if ($db->query($sql)) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)"; $sql .= " VALUES ('".$db->idate($now)."',".((int) $socid).",".((int) $contactid).",".((int) $actionid).")"; if (!$db->query($sql)) { $error++; dol_print_error($db); } } else { dol_print_error($db); } if (!$error) { $db->commit(); } else { $db->rollback(); } } } // Remove a notification if ($action == 'delete') { $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def where rowid=".GETPOST('actid', 'int'); $db->query($sql); } } /* * View */ $form = new Form($db); $object = new Societe($db); $result = $object->fetch($socid); $title = $langs->trans("ThirdParty").' - '.$langs->trans("Notification"); if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { $title = $object->name.' - '.$langs->trans("Notification"); } $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('', $title, $help_url); if ($result > 0) { $langs->load("other"); $head = societe_prepare_head($object); print dol_get_fiche_head($head, 'notify', $langs->trans("ThirdParty"), -1, 'company'); $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); print '
'; print '
'; print ''; // Type Prospect/Customer/Supplier print ''; // Prefix if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field print ''; } if ($object->client) { print ''; } if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $object->fournisseur && !empty($user->rights->fournisseur->lire)) { print ''; } /*print ''; // Notification for this thirdparty print '';*/ print '
'.$langs->trans('NatureOfThirdParty').''; print $object->getTypeUrl(1); print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; print $langs->trans('CustomerCode').''; print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client)); $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) { print ' ('.$langs->trans("WrongCustomerCode").')'; } print '
'; print $langs->trans('SupplierCode').''; print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur)); $tmpcheck = $object->check_codefournisseur(); if ($tmpcheck != 0 && $tmpcheck != -5) { print ' ('.$langs->trans("WrongSupplierCode").')'; } print '
'.$langs->trans("NbOfActiveNotifications").''; $nbofrecipientemails=0; $notify=new Notify($db); $tmparray = $notify->getNotificationsArray('', $object->id, null, 0, array('thirdparty')); foreach($tmparray as $tmpkey => $tmpval) { if (!empty($tmpkey)) $nbofrecipientemails++; } print $nbofrecipientemails; print '
'; print '
'; print dol_get_fiche_end(); print "\n"; // Help print '
'; print $langs->trans("NotificationsDesc"); print '
'.$langs->trans("NotificationsDescUser"); print '
'.$langs->trans("NotificationsDescContact"); print '
'.$langs->trans("NotificationsDescGlobal"); print '
'; print '
'; print '
'."\n"; // List of notifications enabled for contacts $sql = "SELECT n.rowid, n.type,"; $sql .= " a.code, a.label,"; $sql .= " c.rowid as contactid, c.lastname, c.firstname, c.email"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; $sql .= " ".MAIN_DB_PREFIX."socpeople c"; $sql .= " WHERE a.rowid = n.fk_action"; $sql .= " AND c.rowid = n.fk_contact"; $sql .= " AND c.fk_soc = ".((int) $object->id); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); } else { dol_print_error($db); } // Add notification form print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')', '', ''); print '
'; print ''; print ''; $param = "&socid=".$socid; // Line with titles print '
'; print ''; print ''; print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, 'width="45%"', $sortfield, $sortorder); print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, 'width="35%"', $sortfield, $sortorder); print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, 'width="10%"', $sortfield, $sortorder); print_liste_field_titre(''); print "\n"; // Line to add a new subscription $listofemails = $object->thirdparty_and_contact_email_array(); if (count($listofemails) > 0) { $actions = array(); // Load array of available notifications $notificationtrigger = new InterfaceNotification($db); $listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents(); foreach ($listofmanagedeventfornotification as $managedeventfornotification) { $label = ($langs->trans("Notify_".$managedeventfornotification['code']) != "Notify_".$managedeventfornotification['code'] ? $langs->trans("Notify_".$managedeventfornotification['code']) : $managedeventfornotification['label']); $actions[$managedeventfornotification['rowid']] = $label; } print ''; print ''; print ''; print ''; print ''; print ''; } else { print ''; } if ($num) { $i = 0; $contactstatic = new Contact($db); while ($i < $num) { $obj = $db->fetch_object($resql); $contactstatic->id = $obj->contactid; $contactstatic->lastname = $obj->lastname; $contactstatic->firstname = $obj->firstname; print ''; print ''; print ''; print ''; print ''; print ''; $i++; } $db->free($resql); } // List of notifications enabled for fixed email /* foreach($conf->global as $key => $val) { if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue; print ''; print ''; print ''; print ''; print ''; }*/ /*if ($user->admin) { print ''; }*/ print '
'; print img_picto('', 'contact', '', false, 0, 0, '', 'paddingright').$form->selectarray("contactid", $listofemails, '', 1, 0, 0, '', 0, 0, 0, '', 'minwidth100imp maxwidthonsmartphone'); print ''; print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').$form->selectarray("actionid", $actions, '', 1, 0, 0, '', 0, 0, 0, '', 'minwidth100imp maxwidthonsmartphone'); print ''; $type = array('email'=>$langs->trans("EMail")); print $form->selectarray("typeid", $type, '', 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp'); print '
'; print $langs->trans("YouMustCreateContactFirst"); print '
'.$contactstatic->getNomUrl(1); if ($obj->type == 'email') { if (isValidEmail($obj->email)) { print ' <'.$obj->email.'>'; } else { $langs->load("errors"); print ' '.img_warning().' '.$langs->trans("ErrorBadEMail", $obj->email).''; } } print ''; $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label); print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').$label; print ''; if ($obj->type == 'email') { print $langs->trans("Email"); } if ($obj->type == 'sms') { print $langs->trans("SMS"); } print ''.img_delete().'
'; $listtmp=explode(',',$val); $first=1; foreach($listtmp as $keyemail => $valemail) { if (! $first) print ', '; $first=0; $valemail=trim($valemail); //print $keyemail.' - '.$valemail.' - '.$reg[1].'
'; if (isValidEmail($valemail, 1)) { if ($valemail == '__SUPERVISOREMAIL__') print $valemail; else print ' <'.$valemail.'>'; } else { $langs->load("errors"); print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail).'; } } print '
'; $notifcode=preg_replace('/_THRESHOLD_.*$/','',$reg[1]); $notifcodecond=preg_replace('/^.*_(THRESHOLD_)/','$1',$reg[1]); $label=($langs->trans("Notify_".$notifcode)!="Notify_".$notifcode?$langs->trans("Notify_".$notifcode):$notifcode); print $label; if (preg_match('/^THRESHOLD_HIGHER_(.*)$/',$notifcodecond,$regcond) && ($regcond[1] > 0)) { print ' - '.$langs->trans("IfAmountHigherThan",$regcond[1]); } print ''; print $langs->trans("Email"); print ''.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'
'; print '+ '.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).''; print '
'; print '
'; print '
'; print '

'."\n"; // List $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,"; $sql .= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,"; $sql .= " a.code, a.label"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql .= " ".MAIN_DB_PREFIX."notify as n "; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid"; $sql .= " WHERE a.rowid = n.fk_action"; $sql .= " AND n.fk_soc = ".((int) $object->id); $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } } $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); } else { dol_print_error($db); } $param = '&socid='.$object->id; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.$contextpage; } if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.$limit; } print '
'; if ($optioncss != '') { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; // List of active notifications print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); // Line with titles print '
'; print ''; print ''; print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '', $sortfield, $sortorder); print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder); print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '', $sortfield, $sortorder); //print_liste_field_titre("Object",$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder); print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "n.daten", '', $param, '', $sortfield, $sortorder, 'right '); print ''; if ($num > 0) { $i = 0; $contactstatic = new Contact($db); while ($i < $num) { $obj = $db->fetch_object($resql); print ''; print ''; print ''; // TODO Add link to object here for other types /*print '';*/ // print print''; print ''; $i++; } $db->free($resql); } else { print ''; } print '
'; if ($obj->id > 0) { $contactstatic->id = $obj->id; $contactstatic->lastname = $obj->lastname; $contactstatic->firstname = $obj->firstname; print $contactstatic->getNomUrl(1); print $obj->email ? ' <'.$obj->email.'>' : $langs->trans("NoMail"); } else { print $obj->email; } print ''; $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label); print $label; print ''; if ($obj->type == 'email') { print $langs->trans("Email"); } if ($obj->type == 'sms') { print $langs->trans("Sms"); } print ''; if ($obj->object_type == 'order') { $orderstatic->id=$obj->object_id; $orderstatic->ref=... print $orderstatic->getNomUrl(1); } print ''.dol_print_date($db->jdate($obj->daten), 'dayhour').'
'.$langs->trans("None").'
'; print '
'; print '
'; } else { dol_print_error('', 'RecordNotFound'); } // End of page llxFooter(); $db->close();