* Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ */ /** \file htdocs/comm/action/fiche.php \ingroup commercial \brief Page de la fiche action \version $Revision$ */ require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/cactioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/actioncomm.class.php"); $langs->load("companies"); $langs->load("commercial"); $langs->load("other"); $langs->load("bills"); $langs->load("orders"); // Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } if (isset($_GET["error"])) $error=$_GET["error"]; /* * Action création de l'action * */ if ($_POST["action"] == 'add_action') { // Nettoyage parametres if ($_POST["aphour"] == -1) $_POST["aphour"]='0'; if ($_POST["apmin"] == -1) $_POST["apmin"]='0'; if ($_POST["adhour"] == -1) $_POST["adhour"]='0'; if ($_POST["admin"] == -1) $_POST["admin"]='0'; $datep=@mktime($_POST["aphour"], $_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datea=@mktime($_POST["adhour"], $_POST["admin"], 0, $_POST["admonth"], $_POST["adday"], $_POST["adyear"]); // Si param incorrects, mktime renvoi false en PHP 5.1, -1 avant if (! ($datep > 0)) $datep=''; if (! ($datea > 0)) $datea=''; if ($_POST["contactid"]) { $contact = new Contact($db); $contact->fetch($_POST["contactid"]); } if (! $_POST["actioncode"]) { $error=1; $_GET["action"] = 'create'; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Type")).'
'; } if ($datea && $_POST["percentage"] == 0) { $error=1; $_GET["action"] = 'create'; $mesg='
'.$langs->trans("ErrorStatusCantBeZeroIfStarted").'
'; } if (! $_POST["apyear"] && ! $_POST["adyear"]) { $error=1; $_GET["action"] = 'create'; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; } if (! $error) { $db->begin(); $cactioncomm = new CActionComm($db); $cactioncomm->fetch($_POST["actioncode"]); // Initialisation objet actioncomm $actioncomm = new ActionComm($db); $actioncomm->type_id = $cactioncomm->id; $actioncomm->type_code = $cactioncomm->code; $actioncomm->priority = isset($_POST["priority"])?$_POST["priority"]:0; $actioncomm->label = trim($_POST["label"]); if (! $_POST["label"]) { if ($_POST["actioncode"] == 'AC_RDV' && $contact->getFullName($langs)) { $actioncomm->label = $langs->trans("TaskRDVWith",$contact->getFullName($langs)); } else { if ($langs->trans("Action".$actioncomm->type_code) != "Action".$actioncomm->type_code) { $actioncomm->label = $langs->trans("Action".$actioncomm->type_code)."\n"; } } } // print $_POST["aphour"]." ".$_POST["apmin"]." ".$_POST["apday"]; $actioncomm->datep = $datep; $actioncomm->date = $datea; if ($_POST["percentage"] < 100 && ! $actioncomm->datep) $actioncomm->datep=$actioncomm->date; if ($actioncomm->type_code == 'AC_RDV') { // RDV if ($actioncomm->date) { $actioncomm->percentage = 100; } else { $actioncomm->percentage = 0; } } else { $actioncomm->percentage = isset($_POST["percentage"])?$_POST["percentage"]:0; } $actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60; $actioncomm->user = $user; $actioncomm->note = trim($_POST["note"]); if (isset($_POST["contactid"])) $actioncomm->contact = $contact; if (isset($_REQUEST["socid"]) && $_REQUEST["socid"] > 0) { $societe = new Societe($db); $societe->fetch($_REQUEST["socid"]); $actioncomm->societe = $societe; } if ($_POST["add_webcal"] == 'on') $actioncomm->use_webcal=1; // On crée l'action $idaction=$actioncomm->add($user); if ($idaction > 0) { if (! $actioncomm->error) { $db->commit(); if ($_POST["from"]) { dolibarr_syslog("Back to ".$_POST["from"]); Header("Location: ".$_POST["from"]); } elseif($idaction) { Header("Location: ".DOL_URL_ROOT.'/comm/action/fiche.php?id='.$idaction); } else { Header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'); } exit; } else { // Si erreur $db->rollback(); $_GET["id"]=$idaction; $error='
'.$actioncomm->error.'
'; } } else { $db->rollback(); $error='
'.$actioncomm->error.'
'; } } // print $_REQUEST["from"]."rr"; } /* * Action suppression de l'action * */ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { $actioncomm = new ActionComm($db); $actioncomm->fetch($_GET["id"]); $result=$actioncomm->delete(); if ($result >= 0) { Header("Location: index.php"); exit; } else { $mesg=$actioncomm->error; } } /* * Action mise à jour de l'action * */ if ($_POST["action"] == 'update') { if (! $_POST["cancel"]) { if ($_POST["aphour"] == -1) $_POST["aphour"]='0'; if ($_POST["apmin"] == -1) $_POST["apmin"]='0'; if ($_POST["adhour"] == -1) $_POST["adhour"]='0'; if ($_POST["admin"] == -1) $_POST["admin"]='0'; $actioncomm = new Actioncomm($db); $actioncomm->fetch($_POST["id"]); $actioncomm->datep = @mktime($_POST["aphour"], $_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $actioncomm->date = @mktime($_POST["adhour"], $_POST["admin"], 0, $_POST["admonth"], $_POST["adday"], $_POST["adyear"]); //print $_POST["apmonth"].",".$_POST["apday"].",".$_POST["apyear"].",".$_POST["aphour"].",".$_POST["apmin"]."
\n"; //print $actioncomm->datep; $actioncomm->label = $_POST["label"]; $actioncomm->percentage = $_POST["percentage"]; $actioncomm->contact->id = $_POST["contactid"]; $actioncomm->note = $_POST["note"]; if ($actioncomm->type_code == 'AC_RDV' && $actioncomm->percentage == 100 && ! $actioncomm->date) { $actioncomm->date = $actioncomm->datep; } $result=$actioncomm->update(); } if ($result < 0) { $mesg='
'.$actioncomm->error.'
'; $_GET["id"]=$_POST["id"]; } else { Header("Location: ".$_POST["from"]); exit; } } llxHeader(); $html = new Form($db); /* ************************************************************************** */ /* */ /* Affichage fiche en mode création */ /* */ /* ************************************************************************** */ if ($_GET["action"] == 'create') { $caction = new CActioncomm($db); if ($_GET["contactid"]) { $contact = new Contact($db); $contact->fetch($_GET["contactid"]); } print '
'; print ''; print ''; /* * Si action de type Rendez-vous * */ if ($_GET["actioncode"] == 'AC_RDV') { print_titre ($langs->trans("AddActionRendezVous")); print "
"; if ($mesg) print $mesg.'
'; print ''."\n"; print ''; // Type d'action print ''; // Societe, contact print ''; // Si la societe est imposée, on propose ces contacts if ($_REQUEST["socid"]) { print ''; } // Affecte a print ''; // Realise par print ''; // Date planification print ''; // Date done print ''; // Duration print ''; add_row_for_webcal_link(); // Note print ''; print ''; print '
'.$langs->trans("ActionOnCompany").''; if ($_REQUEST["socid"]) { $societe = new Societe($db); $societe->fetch($_REQUEST["socid"]); print $societe->getNomUrl(1); print ''; } else { print $html->select_societes('','socid',1,1); } print '
'.$langs->trans("ActionOnContact").''; $html->select_contacts($_REQUEST["socid"],'','contactid',1,1); print '
'.$langs->trans("ActionAffectedTo").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("ActionDoneBy").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("DateActionPlanned").''; if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2) { $html->select_date(-1,'ap',1,1,1,"action"); } else { $html->select_date(-1,'ap',1,1,1,"action"); } print '
'.$langs->trans("DateActionDone").''; if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2) { $html->select_date(-1,'ad',1,1,1,"action"); } else { $html->select_date(-1,'ad',1,1,1,"action"); } print '
'.$langs->trans("Duration").''; $html->select_duree("duree"); print '
'.$langs->trans("Note").''; if ($conf->fckeditor->enabled) { // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('note','',280,'dolibarr_notes','In',true); $doleditor->Create(); } else { print ''; } print '
'; } /* * Si action de type autre que rendez-vous * */ else { /* * Click to dial * */ if ($conf->clicktodial->enabled) { $user->fetch_clicktodial(); if ($_GET["call"] && $user->clicktodial_enabled == 1) { print '\n"; } } print_titre ($langs->trans("AddAnAction")); print "
"; if ($mesg) print $mesg.'
'; print ''; // Type d'action actifs print ''; print ''; // Societe, contact print ''; // Si la societe est imposée, on propose ces contacts if ($_REQUEST["socid"]) { print ''; } // Affecte a print ''; // Realise par print ''; // Avancement if ($_GET["afaire"] == 1) { print ''; print ''; print ''; } elseif ($_GET["afaire"] == 2) { print ''; print ''; } else { print ''; } // Date planification print ''; // Date done print ''; add_row_for_webcal_link(); // Note print ''; print ''; print '
'.$langs->trans("Type").''; if ($_GET["actioncode"]) { print ''."\n"; $caction->fetch($_GET["actioncode"]); print $caction->getNomUrl(); } else { $arraylist=$caction->liste_array(1,'code'); $arraylist[0]=' '; asort($arraylist); $html->select_array("actioncode", $arraylist, 0); } print '
'.$langs->trans("Title").'
'.$langs->trans("ActionOnCompany").''; if ($_REQUEST["socid"]) { $societe = new Societe($db); $societe->fetch($_REQUEST["socid"]); print $societe->getNomUrl(1); print ''; } else { print $html->select_societes('','socid',1,1); } print '
'.$langs->trans("ActionOnContact").''; $html->select_contacts($_REQUEST["socid"],'','contactid',1,1); print '
'.$langs->trans("ActionAffectedTo").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("ActionDoneBy").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("Status").' / '.$langs->trans("Percentage").''.$langs->trans("StatusActionToDo").' / 0%
'.$langs->trans("Status").' / '.$langs->trans("Percentage").''.$langs->trans("StatusActionDone").' / 100%
'.$langs->trans("Status").' / '.$langs->trans("Percentage").'%
'.$langs->trans("DateActionPlanned").''; if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2) { $html->select_date('','ap',1,1,0,"action"); } else { $html->select_date('','ap',1,1,0,"action"); } print '
'.$langs->trans("DateActionDone").''; if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2) { $html->select_date(-1,'ad',1,1,1,"action"); } elseif ($_GET["afaire"] != 1) { $html->select_date(-1,'ad',1,1,1,"action"); } print '
'.$langs->trans("Note").''; if ($conf->fckeditor->enabled) { // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('note','',280,'dolibarr_notes','In',true); $doleditor->Create(); } else { print ''; } print '
'; } print "
"; } /* * Affichage action en mode edition ou visu * */ if ($_GET["id"]) { if ($error) { print '
'.$error.'

'; } if ($mesg) { print $mesg.'
'; } $act = new ActionComm($db); $act->fetch($_GET["id"]); $res=$act->societe->fetch($act->societe->id); $res=$act->author->fetch(); // Le paramètre est le login, hors seul l'id est chargé. $res=$act->contact->fetch($act->contact->id); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/comm/action/fiche.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("CardAction"); $hselected=$h; $h++; $head[$h][0] = DOL_URL_ROOT.'/comm/action/document.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans('Documents'); $h++; $head[$h][0] = DOL_URL_ROOT.'/comm/action/info.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans('Info'); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Action")); // Confirmation suppression action if ($_GET["action"] == 'delete') { $html->form_confirm("fiche.php?id=".$_GET["id"],$langs->trans("DeleteAction"),$langs->trans("ConfirmDeleteAction"),"confirm_delete"); print '
'; } if ($_GET["action"] == 'edit') { // Fiche action en mode edition print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Priorite print ''; // Affecte a print ''; // Realise par print ''; // Date planification print ''; // Date done print ''; // Etat print ''; // Objet lié if ($act->objet_url) { print ''; print ''; } // Note print ''; print ''; print '
'.$langs->trans("Ref").''.$act->id.'
'.$langs->trans("Type").''.$act->type.'
'.$langs->trans("Title").'
'.$langs->trans("Company").''.img_object($langs->trans("ShowCompany"),'company').' '.$act->societe->nom.''.$langs->trans("Contact").''; $html->select_array("contactid", $act->societe->contact_array(), $act->contact->id, 1); print '
'.$langs->trans("Priority").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("ActionAffectedTo").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("ActionDoneBy").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("DateActionPlanned").''; $html->select_date(($act->datep?$act->datep:-1),'ap',1,1,1,"action"); if ($act->percentage < 100 && $act->datep < (time() - $conf->global->MAIN_DELAY_ACTIONS_TODO)) print img_warning($langs->trans("Late")); print '
'.$langs->trans("DateActionDone").''; $html->select_date(($act->date?$act->date:-1),'ad',1,1,1,"action"); print '
'.$langs->trans("Status").' / '.$langs->trans("Percentage").'%
'.$langs->trans("LinkedObject").''.$act->objet_url.'
'.$langs->trans("Note").''; if ($conf->fckeditor->enabled) { // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('note',$act->note,280,'dolibarr_notes','In',true); $doleditor->Create(); } else { print ''; } print '
'; print '     '; print '
'; } else { // Affichage fiche action en mode visu print ''; // Ref print ''; // Type print ''; // Libelle print ''; // Societe - contact print ''; print ''; print ''; // Priorite print ''; // Affecte a print ''; // Realise par print ''; // Date planification print ''; // Date fin real print ''; // Statut print ''; // Objet lié if ($act->objet_url) { print ''; print ''; } // Note print ''; print '
'.$langs->trans("Ref").''.$act->id.'
'.$langs->trans("Type").''.$act->type.'
'.$langs->trans("Title").''.$act->label.'
'.$langs->trans("Company").''.$act->societe->getNomUrl(1).''.$langs->trans("Contact").''; if ($act->contact->id > 0) { print $act->contact->getNomUrl(1); } else { print $langs->trans("None"); } print '
'.$langs->trans("Priority").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("ActionAffectedTo").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("ActionDoneBy").''; print $langs->trans("FeatureNotYetSupported"); print '
'.$langs->trans("DateActionPlanned").''; print dolibarr_print_date($act->datep,'dayhour'); if ($act->percentage < 100 && $act->datep < (time() - $conf->global->MAIN_DELAY_ACTIONS_TODO)) print img_warning($langs->trans("Late")); print '
'.$langs->trans("DateActionDone").''.dolibarr_print_date($act->date,'dayhour').'
'.$langs->trans("Status").' / '.$langs->trans("Percentage").''; print $act->getLibStatut(4); print '
'.$langs->trans("LinkedObject").''.$act->objet_url.'
'.$langs->trans("Note").''; if ($conf->fckeditor->enabled) print nl2br($act->note); else print nl2br(htmlentities($act->note)); print '
'; } print "\n"; /** * Barre d'actions * */ print '
'; if ($_GET["action"] != 'edit' && $_GET["action"] != 'delete') { print ''.$langs->trans("Edit").''; print ''.$langs->trans("Delete").''; } print '
'; } $db->close(); llxFooter('$Date$ - $Revision$'); /** \brief Ajoute une ligne de tableau a 2 colonnes pour avoir l'option webcalendar \return int Retourne le nombre de lignes ajoutées */ function add_row_for_webcal_link() { global $conf,$langs,$user; $nbtr=0; // Lien avec calendrier si module activé if ($conf->webcal->enabled) { if ($conf->global->PHPWEBCALENDAR_SYNCRO != 'never') { $langs->load("other"); if (! $user->webcal_login) { print ''.$langs->trans("AddCalendarEntry").''; print ''; print ' '.$langs->transnoentities("ErrorWebcalLoginNotDefined","id."\">".$user->login.""); print ''; print ''; $nbtr++; } else { if ($conf->global->PHPWEBCALENDAR_SYNCRO == 'always') { print ''; } else { print ''.$langs->trans("AddCalendarEntry").''; print 'global->PHPWEBCALENDAR_SYNCRO=='always' || $conf->global->PHPWEBCALENDAR_SYNCRO=='yesbydefault')?' checked':'').'>'; print ''; $nbtr++; } } } } return $nbtr; } ?>