* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2010-2012 Juanjo Menent * * 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/fiche.php * \ingroup societe notification * \brief Tab for notifications of third party */ require '../../main.inc.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->load("companies"); $langs->load("mails"); $langs->load("admin"); $langs->load("other"); $socid = GETPOST("socid",'int'); $action = GETPOST('action'); $contactid=GETPOST('contactid'); // May be an int or 'thirdparty' $actionid=GETPOST('actionid'); // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="c.lastname"; $now=dol_now(); /* * Actions */ // Add a notification if ($action == 'add') { $error=0; if (empty($contactid)) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")).'
'; $error++; } if ($actionid <= 0) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")).'
'; $error++; } if (! $error) { $db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; $sql .= " WHERE fk_soc=".$socid." AND fk_contact=".$contactid." AND fk_action=".$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)."',".$socid.",".$contactid.",".$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=".$_GET["actid"]; $db->query($sql); } /* * View */ $form = new Form($db); llxHeader(); $object = new Societe($db); $result=$object->fetch($socid); if ($result > 0) { $langs->load("other"); $head = societe_prepare_head($object); dol_fiche_head($head, 'notify', $langs->trans("ThirdParty"),0,'company'); print ''; print ''; // Prefix if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { print ''; } if ($object->client) { print ''; } if ($object->fournisseur) { print ''; } print ''; print ''; print '
'.$langs->trans("ThirdPartyName").''; print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom'); print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; print $langs->trans('CustomerCode').''; print $object->code_client; if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; print '
'; print $langs->trans('SupplierCode').''; print $object->code_fournisseur; if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; print '
'.$langs->trans("NbOfActiveNotifications").''; $sql = "SELECT COUNT(n.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n"; $sql.= " WHERE fk_soc = ".$object->id; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $nb=$obj->nb; $i++; } } else { dol_print_error($db); } print $nb; print '
'; // Help print '
'.$langs->trans("NotificationsDesc").'
'; dol_fiche_end(); print "\n"; // Add notification form print_fiche_titre($langs->trans("AddNewNotification"),'',''); print '
'; print ''; print ''; $param="&socid=".$socid; // Line with titles print ''; print ''; print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.lastname",'',$param,'"width="45%"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Type"),"fiche.php","",'',$param,'"width="10%"',$sortfield,$sortorder); print_liste_field_titre(''); print ''; $var=false; $listofemails=$object->thirdparty_and_contact_email_array(); if (count($listofemails) > 0) { $actions=array(); // Load array of available notifications $notificationtrigger=new InterfaceNotification($db); $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents(); foreach($listofnotifiedevents as $notifiedevent) { $label=($langs->trans("Notify_".$notifiedevent['code'])!="Notify_".$notifiedevent['code']?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']); $actions[$notifiedevent['rowid']]=$label; } print ''; print ''; print ''; print ''; print ''; } else { print ''; } print '
'; print $form->selectarray("contactid",$listofemails); print ''; print $form->selectarray("actionid",$actions,'',1); print ''; $type=array('email'=>$langs->trans("EMail")); print $form->selectarray("typeid",$type); print '
'; print $langs->trans("YouMustCreateContactFirst"); print '
'; print '
'; print '
'; dol_htmloutput_mesg($mesg); // List of active notifications print_fiche_titre($langs->trans("ListOfActiveNotifications"),'',''); $var=true; // Line with titles print ''; print ''; print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.lastname",'',$param,'"width="45%"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Type"),"fiche.php","",'',$param,'"width="10%"',$sortfield,$sortorder); print_liste_field_titre('','',''); print ''; // List of notifications 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 = ".$object->id; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $contactstatic=new Contact($db); while ($i < $num) { $var = !$var; $obj = $db->fetch_object($resql); $contactstatic->id=$obj->contactid; $contactstatic->lastname=$obj->lastname; $contactstatic->firstname=$obj->firstname; print ''; print ''; print ''; print ''; print ''; $i++; } $db->free($resql); } else { dol_print_error($db); } 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 $label; print ''; if ($obj->type == 'email') print $langs->trans("Email"); if ($obj->type == 'sms') print $langs->trans("SMS"); print ''.img_delete().'
'; print '
'; // List of notifications done print_fiche_titre($langs->trans("ListOfNotificationsDone"),'',''); $var=true; // Line with titles print ''; print ''; print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.lastname",'',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),"fiche.php","a.daten",'',$param,'align="right"',$sortfield,$sortorder); print ''; // List $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type, n.objet_id,"; $sql.= " c.rowid as id, c.lastname, c.firstname, c.email,"; $sql.= " a.code, a.label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql.= " ".MAIN_DB_PREFIX."notify as n, "; $sql.= " ".MAIN_DB_PREFIX."socpeople as c"; $sql.= " WHERE a.rowid = n.fk_action"; $sql.= " AND c.rowid = n.fk_contact"; $sql.= " AND c.fk_soc = ".$object->id; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $contactstatic=new Contact($db); while ($i < $num) { $var = !$var; $obj = $db->fetch_object($resql); $contactstatic->id=$obj->id; $contactstatic->lastname=$obj->lastname; $contactstatic->firstname=$obj->firstname; print ''; print ''; // TODO Add link to object here // print print''; print ''; $i++; } $db->free($resql); } else { dol_print_error($db); } print '
'.$contactstatic->getNomUrl(1); print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); print ''; $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); print $label; print ''.dol_print_date($db->jdate($obj->daten), 'dayhour').'
'; } else dol_print_error('','RecordNotFound'); $db->close(); llxFooter(); ?>