Ejemplo n.º 1
0
 public function __construct($db)
 {
     $this->db = $db;
     $this->msgs = array();
     $this->template_dir = SMARTY_TEMPLATE_POINTSNOIRS;
     $this->compile_dir = SMARTY_COMPILE_POINTSNOIRS;
     if (!file_exists($this->compile_dir)) {
         mkdir($this->compile_dir);
     }
     if (!array_key_exists('p', $_GET)) {
         $_GET['p'] = 'accueil';
     }
     if (!array_key_exists('id_utilisateur', $_SESSION)) {
         $_SESSION['id_utilisateur'] = false;
     }
     switch ($_GET['p']) {
         case 'espece_autocomplete2':
             $this->before_espece_autocomplete2();
             break;
         case 'accueil':
             $this->before_accueil();
             $this->display('accueil.tpl');
             break;
         case 'actu':
             $this->before_actu();
             $this->display('actu.tpl');
             break;
         case 'enregistre':
             $id_utilisateur = get_config()->query_nv('/clicnat/pointsnoirs/id_utilisateur');
             $tag_point_noir = get_config()->query_nv('/clicnat/pointsnoirs/id_tag');
             $tag_mort = get_config()->query_nv('/clicnat/pointsnoirs/id_tag_mort');
             $id_espace = bobs_espace_point::insert($this->db, array('id_utilisateur' => $id_utilisateur, 'reference' => '', 'nom' => '', 'x' => $_GET['lon'], 'y' => $_GET['lat']));
             $id_obs = bobs_observation::insert($this->db, array('id_utilisateur' => $id_utilisateur, 'date_observation' => $_GET['date'], 'id_espace' => $id_espace, 'table_espace' => 'espace_point'));
             $observation = new bobs_observation($this->db, $id_obs);
             if (!empty($_GET['heure_h'])) {
                 $observation->set_heure($_GET['heure_h'], $_GET['heure_m']);
             }
             if (isset($_GET['diff_ok'])) {
                 $_GET['diff_ok'] = false;
             }
             if (isset($_GET['particip_ok'])) {
                 $_GET['diff_ok'] = false;
             }
             $comtr2 = "INFORMATIONS DU FORMULAIRE\n\n";
             $comtr2 .= "Nom: {$_GET['nom']}\n";
             $comtr2 .= "Prenom: {$_GET['prenom']}\n";
             $comtr2 .= "Structure: {$_GET['structure']}\n";
             $comtr2 .= "Adresse:\n";
             $comtr2 .= "{$_GET['adresse']}\n\n";
             $comtr2 .= "Ville: {$_GET['ville']}\n";
             $comtr2 .= "Tel: {$_GET['tel']}\n";
             $comtr2 .= "EMail: {$_GET['email']}\n";
             $comtr2 .= "DiffusionNom: {$_GET['diff_ok']}\n";
             $comtr2 .= "ParticipOk: {$_GET['particip_ok']}\n";
             $a_enregistrer = explode(',', self::elem_a_enregistrer);
             foreach ($a_enregistrer as $k) {
                 $this->sess_store($k, $_GET[$k]);
             }
             $observation->add_observateur($id_utilisateur);
             for ($x = 0; $x < 10; $x++) {
                 if (array_key_exists("id_espece_{$x}", $_GET)) {
                     if ($_GET["n_vivant_{$x}"] > 0) {
                         $id_citation = $observation->add_citation($_GET["id_espece_{$x}"]);
                         $citation = new bobs_citation($this->db, $id_citation);
                         $citation->set_effectif($_GET["n_vivant_{$x}"]);
                         $citation->set_indice_qualite($_GET["indice_q_vivant_{$x}"]);
                         $citation->set_commentaire($_GET["commentaire_0"]);
                         $citation->ajoute_tag($tag_point_noir);
                         $citation->ajoute_commentaire('info', $id_utilisateur, $comtr2);
                     }
                     if ($_GET["n_mort_{$x}"] > 0) {
                         $id_citation = $observation->add_citation($_GET["id_espece_{$x}"]);
                         $citation = new bobs_citation($this->db, $id_citation);
                         $citation->set_effectif($_GET["n_mort_{$x}"]);
                         $citation->set_indice_qualite($_GET["indice_q_mort_{$x}"]);
                         $citation->set_commentaire($_GET["commentaire_0"]);
                         $citation->ajoute_tag($tag_point_noir);
                         $citation->ajoute_tag($tag_mort);
                         $citation->ajoute_commentaire('info', $id_utilisateur, $comtr2);
                     }
                 }
             }
             $observation->send();
             header('Location: ?p=complements');
             $_SESSION['id_observation'] = $observation->id_observation;
             exit;
         case 'complements':
             $id_utilisateur = get_config()->query_nv('/clicnat/pointsnoirs/id_utilisateur');
             $observation = get_observation($this->db, $_SESSION['id_observation']);
             if (!isset($_POST['a'])) {
                 $this->assign_by_ref('obs', $observation);
                 $this->display('complements.tpl');
             } else {
                 // enregistrement
                 $citations = $observation->get_citations()->ids();
                 foreach ($_FILES as $nom => $data) {
                     if ($data['error'] != 0) {
                         continue;
                     }
                     if (preg_match('/^image_(\\d+)$/', $nom, $m)) {
                         echo "{$nom}\n";
                         $citation = get_citation($this->db, $m[1]);
                         if (array_search($citation->id_citation, $citations) === false) {
                             continue;
                         }
                         $doc_id = bobs_document::sauve($_FILES[$nom]);
                         $image = new bobs_document_image($doc_id);
                         $citation->document_associer($doc_id);
                     }
                 }
                 if (!empty($_POST['observateurs_supplementaires'])) {
                     $observation->ajoute_commentaire('info', $id_utilisateur, $_POST['observateurs_supplementaires']);
                 }
                 header('Location: ?p=accueil&eok=1');
                 exit;
             }
             break;
         default:
             echo "404";
             exit;
     }
 }
Ejemplo n.º 2
0
 public function before_creer_visite_colonie()
 {
     $this->header_json();
     $visite = ["id_espace" => $_POST['id_espace'], "n_nid_occupe_r" => $_POST['n_nid_occupe_r'], "n_nid_vide_r" => $_POST['n_nid_vide_r'], "n_nid_detruit_r" => $_POST['n_nid_detruit_r'], "n_nid_occupe_f" => $_POST['n_nid_occupe_f'], "n_nid_vide_f" => $_POST['n_nid_vide_f'], "n_nid_detruit_f" => $_POST['n_nid_detruit_f'], "n_nid_occupe_ri" => $_POST['n_nid_occupe_ri'], "n_nid_vide_ri" => $_POST['n_nid_vide_ri'], "n_nid_detruit_ri" => $_POST['n_nid_detruit_ri'], "id_utilisateur" => $_SESSION['id_utilisateur'], "date_visite_nid" => $_POST['date_visite_nid']];
     try {
         $id_visite = clicnat_visite_espace_hirondelle::insert($this->db, clicnat_visite_espace_hirondelle::table, $visite);
         $visite = new clicnat_visite_espace_hirondelle($this->db, $id_visite);
         $observation = ['datedeb' => $visite->date_visite_nid, 'datefin' => $visite->date_visite_nid, 'id_utilisateur' => $_SESSION['id_utilisateur'], 'table_espace' => 'espace_point', 'id_espace' => $visite->id_espace];
         $id_observation = bobs_observation::insert($this->db, $observation);
         $observation = get_observation($this->db, $id_observation);
         $visite->observation_ajouter($observation);
         if ($espace = clicnat_iterateur_visites_espace_hirondelle::from_session($this->db, $visite->id_espace)) {
             $espace->ajout_id($id_visite);
             $espace->to_session();
         }
         if (isset($_POST['commentaire_observation']) && $_POST['commentaire_observation'] != "") {
             $observation->ajoute_commentaire("info", $_SESSION['id_utilisateur'], htmlentities($_POST['commentaire_observation'], ENT_COMPAT, 'UTF-8'));
         }
         /***  Ajoute la citation si les nids sont vide ou detruit
          *
          **/
         foreach ($_POST as $key => $value) {
             $espece = false;
             $effectif = false;
             switch ($key) {
                 case 'n_nid_vide_r':
                     if ($value > 0) {
                         $espece = CLICNAT_HIRONDELLE_ID_ESPECE_RUSTIQUE;
                         $effectif = 0;
                     }
                     break;
                 case 'n_nid_vide_ri':
                     if ($value > 0) {
                         $espece = CLICNAT_HIRONDELLE_ID_ESPECE_RIVIERE;
                         $effectif = 0;
                     }
                     break;
                 case 'n_nid_vide_f':
                     if ($value > 0) {
                         $espece = CLICNAT_HIRONDELLE_ID_ESPECE_FENETRE;
                         $effectif = 0;
                     }
                     break;
                 case 'n_nid_detruit_r':
                     if ($value > 0) {
                         $espece = CLICNAT_HIRONDELLE_ID_ESPECE_RUSTIQUE;
                         $effectif = -1;
                     }
                     break;
                 case 'n_nid_detruit_ri':
                     if ($value > 0) {
                         $espece = CLICNAT_HIRONDELLE_ID_ESPECE_RIVIERE;
                         $effectif = -1;
                     }
                     break;
                 case 'n_nid_detruit_f':
                     if ($value > 0) {
                         $espece = CLICNAT_HIRONDELLE_ID_ESPECE_FENETRE;
                         $effectif = -1;
                     }
                     break;
             }
             if ($espece && $effectif !== false) {
                 $id_citation = $observation->add_citation($espece);
                 $citation = get_citation($this->db, $id_citation);
                 $citation->set_effectif($effectif);
                 $citation->ajoute_tag(CLICNAT_HIRONDELLE_TAG, $id_visite, "visite_espace_hirondelle.id_visite");
             }
         }
     } catch (Exception $e) {
         echo json_encode(["etat" => "err", "message" => $e->getMessage()]);
         exit(0);
     }
     echo json_encode(["etat" => "ok", "id_visite_nid" => $visite->id_visite_nid, "date_visite_nid" => $visite->date_visite_nid, "n_nid_occupe_r" => $_POST['n_nid_occupe_r'], "n_nid_occupe_f" => $_POST['n_nid_occupe_f'], "n_nid_occupe_ri" => $_POST['n_nid_occupe_ri'], "id_observation" => $id_observation]);
     exit(0);
 }