Пример #1
0
 /**
  * Cette fonction insert un nouveau contact
  * @param $csrf : Le jeton CSRF
  * @param string $_POST['name'] : Le nom du contact
  * @param string $_POST['phone'] : Le numero de téléphone du contact
  */
 public function create($csrf)
 {
     //On vérifie que le jeton csrf est bon
     if (!internalTools::verifyCSRF($csrf)) {
         $_SESSION['errormessage'] = 'Jeton CSRF invalide !';
         header('Location: ' . $this->generateUrl('contacts'));
         return false;
     }
     global $db;
     if (!isset($_POST['name']) || !isset($_POST['phone']) || RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS && !isset($_POST['civility'])) {
         $_SESSION['errormessage'] = 'Des champs sont manquants.';
         header('Location: ' . $this->generateUrl('contacts', 'add'));
         return false;
     }
     $nom = $_POST['name'];
     $phone = $_POST['phone'];
     // on enregistre les infos si elles ont été saisies par l'utilisateur
     $civility = isset($_POST['civility']) ? $_POST['civility'] : null;
     $prenom = isset($_POST['firstName']) ? $_POST['firstName'] : null;
     $birthday = isset($_POST['birthday']) ? $_POST['birthday'] : null;
     $loveSituation = isset($_POST['loveSituation']) ? $_POST['loveSituation'] : null;
     $nomComplet = $prenom ? $prenom . ' ' . $nom : $nom;
     if (!($phone = internalTools::parsePhone($phone))) {
         $_SESSION['errormessage'] = 'Numéro de téléphone incorrect.';
         header('Location: ' . $this->generateUrl('contacts', 'add'));
         return false;
     }
     if (!$db->insertIntoTable('contacts', ['name' => $nomComplet, 'number' => $phone])) {
         $_SESSION['errormessage'] = 'Impossible créer ce contact.';
         header('Location: ' . $this->generateUrl('contacts', 'add'));
         return false;
     }
     $id_contact = $db->lastId();
     $db->insertIntoTable('events', ['type' => 'CONTACT_ADD', 'text' => 'Ajout contact : ' . $nomComplet . ' (' . internalTools::phoneAddSpace($phone) . ')']);
     if (!RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) {
         $_SESSION['successmessage'] = 'Le contact a bien été créé.';
         header('Location: ' . $this->generateUrl('contacts'));
         return true;
     }
     if (!$db->insertIntoTable('contacts_infos', ['id_contact' => $id_contact, 'civility' => $civility, 'first_name' => $prenom, 'last_name' => $nom, 'birthday' => $birthday, 'love_situation' => $loveSituation])) {
         $_SESSION['errormessage'] = "Le contact a bien été créé, mais certaines informations n'ont pas pu être enregistrées.";
         header('Location: ' . $this->generateUrl('contacts'));
         return false;
     }
     $db->insertIntoTable('events', ['type' => 'CONTACT_EXTENTED_ADD', 'text' => 'Ajout infos pour le contact : ' . $nomComplet . ' (' . internalTools::phoneAddSpace($phone) . ')']);
     $_SESSION['successmessage'] = 'Le contact a bien été créé.';
     header('Location: ' . $this->generateUrl('contacts'));
     return true;
 }
Пример #2
0
 /**
  * Cette fonction insert un nouveau contact
  * @param $csrf : Le jeton CSRF
  * @param string $_POST['name'] : Le nom du contact
  * @param string $_POST['phone'] : Le numero de téléphone du contact
  */
 public function create($csrf)
 {
     //On vérifie que le jeton csrf est bon
     if (!internalTools::verifyCSRF($csrf)) {
         $_SESSION['errormessage'] = 'Jeton CSRF invalide !';
         header('Location: ' . $this->generateUrl('contacts'));
         return false;
     }
     global $db;
     if (empty($_POST['name']) || empty($_POST['phone'])) {
         $_SESSION['errormessage'] = 'Des champs sont manquants.';
         header('Location: ' . $this->generateUrl('contacts', 'add'));
         return false;
     }
     $nom = $_POST['name'];
     $phone = $_POST['phone'];
     if (!($phone = internalTools::parsePhone($phone))) {
         $_SESSION['errormessage'] = 'Numéro de téléphone incorrect.';
         header('Location: ' . $this->generateUrl('contacts', 'add'));
         return false;
     }
     if (!$db->insertIntoTable('contacts', ['name' => $nom, 'number' => $phone])) {
         $_SESSION['errormessage'] = 'Impossible créer ce contact.';
         header('Location: ' . $this->generateUrl('contacts', 'add'));
         return false;
     }
     $db->insertIntoTable('events', ['type' => 'CONTACT_ADD', 'text' => 'Ajout contact : ' . $nom . ' (' . internalTools::phoneAddSpace($phone) . ')']);
     $_SESSION['successmessage'] = 'Le contact a bien été créé.';
     header('Location: ' . $this->generateUrl('contacts'));
     return true;
 }