diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 24e06b37242..642156d9f4d 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -32,9 +32,6 @@ require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once("../../cactioncomm.class.php"); require_once("../../actioncomm.class.php"); -if ($conf->webcal->enabled) { - require_once("../../lib/webcal.class.php"); -} $langs->load("companies"); $langs->load("commercial"); @@ -96,88 +93,29 @@ if ($_POST["action"] == 'add_action') } } $actioncomm->date = mktime($_POST["heurehour"], - $_POST["heuremin"], - 0, - $_POST["acmonth"], - $_POST["acday"], - $_POST["acyear"]); + $_POST["heuremin"], + 0, + $_POST["acmonth"], + $_POST["acday"], + $_POST["acyear"]); + $actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60; $actioncomm->percent = isset($_POST["percentage"])?$_POST["percentage"]:0; $actioncomm->user = $user; - if (isset($_POST["contactid"])) - { - $actioncomm->contact = $contact; - } - if (isset($_POST["socid"])) - { - $actioncomm->societe = $societe; - } $actioncomm->note = $_POST["note"]; + if (isset($_POST["contactid"])) $actioncomm->contact = $contact; + if (isset($_POST["socid"])) $actioncomm->societe = $societe; + if ($_POST["todo_webcal"] == 'on') $actioncomm->use_webcal=1; - - // On definit la ressource webcal si le module webcal est actif - $webcal=0; - if ($conf->webcal->enabled && $_POST["todo_webcal"] == 'on') - { - // Si action complete ou si action de type rendez-vous -// if ($actioncomm->percent == 100 || $actioncomm->type_code == 'AC_RDV') -// { - // Crée objet webcal et connexion avec params $conf->webcal->db->xxx - $webcal = new Webcal(); - - if (! $webcal->localdb->ok) - { - // Si la creation de l'objet n'as pu se connecter - $error ="Dolibarr n'a pu se connecter à la base Webcalendar avec les identifiants définis (host=".$conf->webcal->db->host." dbname=".$conf->webcal->db->name." user=".$conf->webcal->db->user.")."; - $error.=" L'option de mise a jour Webcalendar a été ignorée."; - $webcal->error=$error; - } - else - { - // Initialisation donnees webcal - if ($_POST["actionid"] == 5 && $contact->fullname) - { - $libellecal =$langs->trans("TaskRDVWith",$contact->fullname)."\n"; - $libellecal.=$_POST["label"]; - } - else - { - $libellecal=""; - if ($langs->trans("Action".$actioncomm->type_code) != "Action".$actioncomm->type_code) - { - $libellecal.=$langs->trans("Action".$actioncomm->type_code)."\n"; - } - $libellecal.=$_POST["label"]; - } - - $webcal->date=$actioncomm->date; - $webcal->duree=($_POST["dureehour"] * 60) + $_POST["dureemin"]; - $webcal->texte=$societe->nom; - $webcal->desc=$libellecal; - } -// } - } - - // On crée l'action (avec ajout eventuel dans webcal si défini) - $idaction=$actioncomm->add($user, ($webcal->localdb->ok?$webcal:0) ); + // On crée l'action + $idaction=$actioncomm->add($user); if ($idaction > 0) { if (! $actioncomm->error) { - // Si pas d'erreur creation action - if (! $webcal->error) - { - // Pas d'erreur webcal - $db->commit(); - Header("Location: ".$_POST["from"]); - return; - } - else - { - // Pas d'erreur action mais erreur webcal - $db->commit(); - $_GET["id"]=$idaction; - } + $db->commit(); + Header("Location: ".$_POST["from"]); + exit; } else { @@ -195,7 +133,7 @@ if ($_POST["action"] == 'add_action') } else { - print "Le type d'action n'a pas été choisi"; + dolibarr_print_error('',"Le type d'action n'a pas été choisi"); } } @@ -412,14 +350,14 @@ if ($_GET["action"] == 'create') } else if ($_GET["afaire"] == 2) { - $html->select_date('','ac',1,1); + $html->select_date('','ac'); print ''.$langs->trans("Hour").''; print_heure_select("heure",8,20); print ''; } else { - $html->select_date('','ac',1,1); + $html->select_date('','ac'); print ''.$langs->trans("Hour").''; print_heure_select("heure",8,20); print ''; @@ -594,7 +532,7 @@ function add_row_for_webcal_link() $langs->load("other"); if (! $user->webcal_login) { - print ''.$langs->trans("AddCalendarEntry").''; + print ''.$langs->trans("AddCalendarEntry").''; print ''; print ' '.$langs->transnoentities("ErrorWebcalLoginNotDefined","id."\">".$user->login.""); print ''; @@ -609,7 +547,7 @@ function add_row_for_webcal_link() } else { - print ''.$langs->trans("AddCalendarEntry").''; + print ''.$langs->trans("AddCalendarEntry").''; print 'webcal->syncro=='always' || $conf->webcal->syncro=='yesbydefault')?' checked':'').'>'; print ''; $nbtr++; diff --git a/htdocs/includes/triggers/interface_webcal.class.php b/htdocs/includes/triggers/interface_webcal.class.php new file mode 100644 index 00000000000..6386a7e9ab0 --- /dev/null +++ b/htdocs/includes/triggers/interface_webcal.class.php @@ -0,0 +1,166 @@ + + * + * 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/includes/triggers/interface_webcal.class.php + \ingroup webcalendar + \brief Fichier de demo de personalisation des actions du workflow + \remarks Son propre fichier d'actions peut etre créé par recopie de celui-ci: + - Le nom du fichier doit etre interface_xxx.class.php + - Le fichier doit rester stocké dans includes/triggers + - Le nom de la classe doit etre InterfaceXxx +*/ + +include_once(DOL_DOCUMENT_ROOT.'/lib/webcal.class.php'); + + +/** + \class InterfaceWebCal + \brief Classe des fonctions triggers des actions personalisées du workflow +*/ + +class InterfaceWebCal +{ + var $db; + var $error; + + + /** + * \brief Constructeur. + * \param DB handler d'accès base + */ + function InterfaceWebCal($DB) + { + $this->db = $DB ; + + $this->name = "WebCal"; + $this->family = "webcal"; + $this->description = "Les triggers de ce composant permettent d'insérer un évênement dans le calendrier webcalendar pour chaque grand évênement Dolibarr."; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + } + + /** + * \brief Renvoi nom du lot de triggers + * \return string Nom du lot de triggers + */ + function getName() + { + return $this->name; + } + + /** + * \brief Renvoi descriptif du lot de triggers + * \return string Descriptif du lot de triggers + */ + function getDesc() + { + return $this->description; + } + + /** + * \brief Renvoi version du lot de triggers + * \return string Version du lot de triggers + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'experimental') return $langs->trans("Experimental"); + elseif ($this->version == 'dolibarr') return DOL_VERSION; + elseif ($this->version) return $this->version; + else return $langs->trans("Unknown"); + } + + /** + * \brief Fonction appelée lors du déclenchement d'un évènement Dolibarr. + * D'autres fonctions run_trigger peuvent etre présentes dans includes/triggers + * \param action Code de l'evenement + * \param object Objet concerné + * \param user Objet user + * \param lang Objet lang + * \param conf Objet conf + * \return int <0 si ko, >0 si ok + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + // Mettre ici le code à exécuter en réaction de l'action + // Les données de l'action sont stockées dans $object + + if (! $conf->webcal->enabled) return 0; // Module non actif + if (! $object->use_webcal) return 0; // Option syncro webcal non active + + // Actions + if ($action == 'ACTION_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + + // Crée objet webcal et connexion avec params $conf->webcal->db->xxx + $webcal = new Webcal(); + + if (! $webcal->localdb->ok) + { + // Si la creation de l'objet n'as pu se connecter + $error ="Dolibarr n'a pu se connecter à la base Webcalendar avec les identifiants définis (host=".$conf->webcal->db->host." dbname=".$conf->webcal->db->name." user=".$conf->webcal->db->user.")."; + $error.=" L'option de mise a jour Webcalendar a été ignorée."; + $this->error=$error; + return -1; + } + + // Initialisation donnees webcal + if ($object->type_id == 5 && $object->contact->fullname) + { + $libellecal =$langs->trans("TaskRDVWith",$object->contact->fullname)."\n"; + $libellecal.=$object->note; + } + else + { + $libellecal=""; + if ($langs->trans("Action".$object->type_code) != "Action".$object->type_code) + { + $libellecal.=$langs->trans("Action".$object->type_code)."\n"; + } + $libellecal.=($object->label!=$libellecal?$object->label."\n":""); + $libellecal.=($object->note?$object->note:""); + } + $webcal->date=$object->date; + $webcal->duree=$object->duree; + $webcal->texte=$object->societe->nom; + $webcal->desc=$libellecal; + + // Ajoute entrée dans webcal + $result=$webcal->add($user); + if ($result) + { + return 1; + } + else + { + $this->error="Echec insertion dans webcal: ".$webcal->error; + return -1; + } + } + + } + +} +?> diff --git a/htdocs/langs/en_US/commercial.lang b/htdocs/langs/en_US/commercial.lang index 3c4a5ab3c3e..6f84f230f3f 100644 --- a/htdocs/langs/en_US/commercial.lang +++ b/htdocs/langs/en_US/commercial.lang @@ -7,6 +7,7 @@ Customers=Customers Prospect=Prospect Prospects=Prospects DeleteAction=Delete a task +NewAction=New action AddAction=Add action AddAnAction=Add an action AddActionRendezVous=Add a Rendez-Vous task diff --git a/htdocs/langs/fr_FR/commercial.lang b/htdocs/langs/fr_FR/commercial.lang index 0dd145ceeb0..6c8bcb786c9 100644 --- a/htdocs/langs/fr_FR/commercial.lang +++ b/htdocs/langs/fr_FR/commercial.lang @@ -7,6 +7,7 @@ Customers=Clients Prospect=Prospect Prospects=Prospects DeleteAction=Effacer une action +NewAction=Nouvelle action AddAction=Créer action AddAnAction=Créer une action AddActionRendezVous=Créer un Rendez-Vous diff --git a/htdocs/lib/webcal.class.php b/htdocs/lib/webcal.class.php index 0d30b841391..ea31cfef89c 100644 --- a/htdocs/lib/webcal.class.php +++ b/htdocs/lib/webcal.class.php @@ -22,15 +22,13 @@ /** \file htdocs/lib/webcal.class.php - \ingroup webcal + \ingroup webcalendar \brief Ensemble des fonctions permettant d'acceder a la database webcalendar. \author Rodolphe Quiedeville. \author Laurent Destailleur. \version $Revision$ */ -require_once (DOL_DOCUMENT_ROOT ."/lib/".$conf->webcal->db->type.".lib.php"); - /** \class Webcal @@ -42,9 +40,10 @@ class Webcal { var $localdb; var $date; - var $duree = 0; + var $duree = 0; // Secondes var $texte; var $desc; + var $error; @@ -56,6 +55,7 @@ class Webcal { global $conf; // On initie la connexion à la base Webcalendar + require_once (DOL_DOCUMENT_ROOT ."/lib/".$conf->webcal->db->type.".lib.php"); $this->localdb = new DoliDb( $conf->webcal->db->type, $conf->webcal->db->host, @@ -66,25 +66,24 @@ class Webcal { /** - \brief Ajoute une entree dans le calendrier de l'utilisateur - \param[in] user le login de l'utilisateur - \param[in] date la date et l'heure de l'evenement dans le calendrier - \param[in] texte le titre a indiquer dans l'evenement - \param[in] desc la description a indiquer dans l'evenement + \brief Ajoute objet en tant qu'entree dans le calendrier de l'utilisateur + \param[in] user Le login de l'utilisateur \return int 1 en cas de succès, -1,-2,-3 en cas d'erreur, -4 si login webcal non défini */ - function add($user, $date, $texte, $desc) + function add($user) { global $langs; - dolibarr_syslog("Webcal::add user=$user date=$date texte=$texte desc=$desc"); - + dolibarr_syslog("Webcal::add user=$user"); + // Test si login webcal défini pour le user if (! $user->webcal_login) { - $this->error=$langs->trans("ErrorWebcalLoginNotDefined","id."\">".$user->login.""); - return -4; + $this->error=$langs->trans("ErrorWebcalLoginNotDefined","id."\">".$user->login.""); + return -4; } + $this->localdb->begin(); + // Recupère l'id max+1 dans la base webcalendar $id = $this->get_next_id(); @@ -92,23 +91,20 @@ class Webcal { { $cal_id = $id; $cal_create_by = $user->webcal_login; - $cal_date = strftime('%Y%m%d', $date); - $cal_time = strftime('%H%M%S', $date); + $cal_date = strftime('%Y%m%d', $this->date); + $cal_time = strftime('%H%M%S', $this->date); $cal_mod_date = strftime('%Y%m%d', time()); $cal_mod_time = strftime('%H%M%S', time()); - $cal_duration = $this->duree; + $cal_duration = round($this->duree / 60); $cal_priority = 2; $cal_type = "E"; $cal_access = "P"; - $cal_name = $texte; - $cal_description = $desc; - - $sql = "INSERT INTO webcal_entry (cal_id, cal_create_by,cal_date,cal_time,cal_mod_date, - cal_mod_time,cal_duration,cal_priority,cal_type, cal_access, cal_name,cal_description)"; - - $sql .= " VALUES ($cal_id, '$cal_create_by', '$cal_date', '$cal_time', '$cal_mod_date', '$cal_mod_time', - $cal_duration,$cal_priority,'$cal_type', '$cal_access', '$cal_name','$cal_description')"; - + $cal_name = $this->texte; + $cal_description = $this->desc; + + $sql = "INSERT INTO webcal_entry (cal_id, cal_create_by,cal_date,cal_time,cal_mod_date, cal_mod_time,cal_duration,cal_priority,cal_type, cal_access, cal_name,cal_description)"; + $sql.= " VALUES ($cal_id, '$cal_create_by', '$cal_date', '$cal_time', '$cal_mod_date', '$cal_mod_time', $cal_duration, $cal_priority, '$cal_type', '$cal_access', '$cal_name','$cal_description')"; + if ($this->localdb->query($sql)) { $sql = "INSERT INTO webcal_entry_user (cal_id, cal_login, cal_status)"; @@ -117,22 +113,26 @@ class Webcal { if ( $this->localdb->query($sql) ) { // OK + $this->localdb->commit(); return 1; } else { + $this->localdb->rollback(); $this->error = $this->localdb->error() . '
' .$sql; return -1; } } else { + $this->localdb->rollback(); $this->error = $this->localdb->error() . '
' .$sql; return -2; } } else { + $this->localdb->rollback(); $this->error = $this->localdb->error() . '
' .$sql; return -3; } @@ -141,20 +141,21 @@ class Webcal { /** \brief Obtient l'id suivant dans le webcalendar - \return int retourne l'id suivant dans le webcalendar ou -1 si erreur + \return int Retourne l'id suivant dans webcalendar, <0 si ko */ function get_next_id() { - $sql = "SELECT max(cal_id) FROM webcal_entry"; + $sql = "SELECT max(cal_id) as id FROM webcal_entry"; - if ($this->localdb->query($sql)) + $resql=$this->localdb->query($sql); + if ($resql) { - $id = $this->localdb->result(0, 0) + 1; - return $id; + $obj=$this->localdb->fetch_object($resql); + return ($obj->id + 1); } else { - print $this->localdb->error(); + $this->error=$this->localdb->error(); return -1; } }