diff --git a/controllers/internalConsole.php b/controllers/internalConsole.php index 9927236..142a73a 100755 --- a/controllers/internalConsole.php +++ b/controllers/internalConsole.php @@ -403,9 +403,22 @@ { foreach ($receiveds as $received) { - echo "Transfer d'un SMS du " . $received['send_by'] . " à l'email " . $user['email']; + // vérifie en base si le numéro est trouvé parmis les contacts + $contact = $db->getContactFromNumber($received['send_by']); + $contact = $contact ? $contact[0] : null; + // si un contact a été trouvé et que l'option des informations de contact avancé est active + if ($contact && RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) { + $expediteur = "de "; + $expediteur .= $contact['contacts_infos.first_name'] ? $contact['contacts_infos.first_name']." " : ""; + $expediteur .= $contact['contacts_infos.last_name'] ? $contact['contacts_infos.last_name'] : $contact['contacts.name']; + $expediteur .= " (" . $received['send_by'] .")"; + } else { + $expediteur = $contact ? sprintf("de %s (%s)", $contact['name'], $received['send_by']) : sprintf("du %s", $received['send_by']); + } + echo "Transfer d'un SMS " . $expediteur . " à l'email " . $user['email']; + $to = $user['email']; - $subject = '[RaspiSMS] - Transfert d\'un SMS du ' . $received['send_by']; + $subject = '[RaspiSMS] - Transfert d\'un SMS ' . $expediteur; $message = "Le numéro " . $received['send_by'] . " vous a envoyé un SMS : \n" . $received['content']; $ok = mail($to, $subject, $message); diff --git a/model/DataBase.php b/model/DataBase.php index 1f934a8..0d0c5ea 100755 --- a/model/DataBase.php +++ b/model/DataBase.php @@ -290,6 +290,44 @@ return $this->runQuery($query, $params); } + /** + * Récupère le contact avec le numéro fourni + * @param $number : Le numéro + * @return string : Retourne le nom du contact ou null si il n'est pas trouvé + */ + public function getContactFromNumber($number) + { + if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) { + $extended_contact_join = ' + LEFT JOIN contacts_infos + ON (contacts_infos.id_contact = contacts.id) + '; + $tableToDescribe = "contacts,contacts_infos"; + } else { + $extended_contact_join = ''; + $tableToDescribe = "contacts"; + } + + $fields = $this->describeTable($tableToDescribe); + + // liste les champs disponibles pour ajouter des alias et éviter des problèmes en cas de colonnes avec le même nom + $fieldNames = array_keys($fields); + foreach ($fieldNames as $key => $fieldName) { + $fieldNames[$key] = $fieldName . " AS '" . $fieldName . "'"; + } + + $query = "SELECT " . implode(', ', $fieldNames) . " + FROM contacts + ".$extended_contact_join." + WHERE contacts.number = (:number)"; + + $params = array( + 'number' => $number, + ); + + return $this->runQuery($query, $params); + } + /******************************/ /* PARTIE DES REQUETES GROUPS */ /******************************/