diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index bcc1ddcc4b6..a0ade0ee56d 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -29,13 +29,16 @@ require("./pre.inc.php"); -$langs->load("company"); -$langs->load("commercial"); - require("../../contact.class.php"); -require("../../lib/webcal.class.php"); require("../../cactioncomm.class.php"); require("../../actioncomm.class.php"); +if ($conf->webcal->enabled) { + require("../../lib/webcal.class.php"); +} + +$langs->load("companies"); +$langs->load("commercial"); +$langs->load("other"); /* @@ -87,31 +90,54 @@ if ($_POST["action"] == 'add_action') $actioncomm->societe = isset($_POST["socid"])?$_POST["socid"]:0; $actioncomm->contact = isset($_POST["contactid"])?$_POST["contactid"]:0; $actioncomm->note = $_POST["note"]; - - $actioncomm->add($user); - if ($conf->webcal && $todo_webcal == 'on') - { - $webcal = new Webcal(); + // On definit la ressource webcal si le module webcal est actif + $webcal=0; + if ($conf->webcal->enabled && $_POST["todo_webcal"] == 'on') + { + $webcal = new Webcal(); - $webcal->heure = $heurehour . $heuremin . '00'; - $webcal->duree = ($dureehour * 60) + $dureemin; - - if ($_POST["actionid"] == 5) - { - $libelle = "Rendez-vous avec ".$contact->fullname; - $libelle .= "\n" . $actioncomm->libelle; - } - else - { - $libelle = $actioncomm->libelle; - } - - $webcal->add($user, $actioncomm->date, $societe->nom, $libelle); - } + 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."). L'option de mise a jour Webcalendar a été ignorée."; + $webcal=-1; + } + else + { + $webcal->heure = $heurehour . $heuremin . '00'; + $webcal->duree = ($dureehour * 60) + $dureemin; + + if ($_POST["actionid"] == 5) + { + $libelle = "Rendez-vous avec ".$contact->fullname; + $libelle .= "\n" . $actioncomm->libelle; + } + else + { + $libelle = $actioncomm->libelle; + } + + $webcal->date=$actioncomm->date; + $webcal->texte=$societe->nom; + $webcal->desc=$libelle; + } + } - Header("Location: ".$_POST["from"]); + // On crée l'action (avec ajout eventuel dans webcal si défini) + $idaction=$actioncomm->add($user, $webcal); + if ($idaction > 0) { + if ($webcal >= 0) { + // Si pas de module webcal ou si pas d'erreur avec + Header("Location: ".$_POST["from"]); + } + else { + // Si erreur dans module webcal + $_GET["id"]=$idaction; + } + } else { + dolibarr_print_error($db); + } } else { print "Le type d'action n'a pas été choisi"; @@ -224,6 +250,13 @@ if ($_GET["action"] == 'create') print_duree_select("duree"); print ''; + // Lien avec calendrier si module activé + if ($conf->webcal->enabled) + { + $langs->load("other"); + print '