Example #1
0
function cle_accept($d1, $d2, $d3, $d4, $d5)
{
    $m1 = luhn($d1 . $d5);
    $m2 = luhn($d2 . $d5);
    $m3 = luhn($d3 . $d5);
    $m4 = luhn($d4 . $d5);
    $n = $m1 + $m2 + $m3 + $m4;
    $alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    return $alpha[$n - 1] . $m1 . $m2 . $m3 . $m4;
}
 /**
  * Generate a new random valid Meid (Imei).
  */
 protected function generateMeid()
 {
     // Use a well known tac as the base of the Imei.
     // In this case: Google Nexus 5.
     $tac = '35824005';
     // Generate a 6 digits random serial number.
     $serial = rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9);
     // Calculate luhn checksum digit.
     $luhn = luhn($tac . $serial);
     return $tac . $serial . $luhn;
 }
 /**
  * @see parent::checkProperty()
  */
 function checkProperty($object)
 {
     $propValue = $object->{$this->fieldName};
     // control
     if ($this->control) {
         // Luhn control
         if ($this->control == "luhn" && !luhn($propValue)) {
             return "La clé est incorrecte";
         }
     }
     return null;
 }
Example #4
0
 protected function luhn($number)
 {
     if (defined('STRICT_TYPES') && CAMEL_CASE == '1') {
         return (bool) self::parameters(['number' => [DT::INT64, DT::UINT64]])->call(__FUNCTION__)->with($number)->returning(DT::BOOL);
     } else {
         return (bool) luhn($number);
     }
 }
 /**
  * @see parent::checkProperty()
  */
 function checkProperty($object)
 {
     $propValue = $object->{$this->fieldName};
     // ccam
     if ($this->ccam) {
         //^[A-Z]{4}[0-9]{3}(-[0-9](-[0-9])?)?$
         // ancienne expression reguliere ([a-z0-9]){0,7}
         if (!preg_match("/^[A-Z]{4}[0-9]{3}(-[0-9](-[0-9])?)?\$/i", $propValue)) {
             return "Code CCAM incorrect";
         }
     } elseif ($this->cim10) {
         if (!preg_match("/^[a-z][0-9x]{2,4}\$/i", $propValue)) {
             // $codeCim = new CCodeCIM10($propValue);
             // if ($codeCim->loadLite()) {
             //   return "Code CIM inconnu";
             // }
             return "Code CIM incorrect, doit contenir une lettre, puis de 2 à 4 chiffres ou la lettre X";
         }
     } elseif ($this->cim10Pmsi) {
         if (!preg_match("/^[a-z]([0-9]{1,5})((\\+|x)[0-9])?\$/i", $propValue)) {
             return "Code CIM incorrect, doit contenir une lettre, puis de 2 à 5 chiffres ou la lettre X";
         }
     } elseif ($this->adeli) {
         if (!preg_match("/^([0-9]){9}\$/i", $propValue)) {
             return "Code Adeli incorrect, doit contenir exactement 9 chiffres";
         }
     } elseif ($this->rib) {
         $compte_banque = substr($propValue, 0, 5);
         $compte_guichet = substr($propValue, 5, 5);
         $compte_numero = substr($propValue, 10, 11);
         $compte_cle = substr($propValue, 21, 2);
         $tabcompte = "";
         $len = strlen($compte_numero);
         for ($i = 0; $i < $len; $i++) {
             $car = substr($compte_numero, $i, 1);
             if (!is_numeric($car)) {
                 $c = ord($car) - 64;
                 $b = $c < 10 ? $c : ($c < 19 ? $c - 9 : $c - 17);
                 $tabcompte .= $b;
             } else {
                 $tabcompte .= $car;
             }
         }
         $int = $compte_banque . $compte_guichet . $tabcompte . $compte_cle;
         if (!(strlen($int) >= 21 && bcmod($int, 97) == 0)) {
             return "Rib incorrect";
         }
     } elseif ($this->insee) {
         if (preg_match("/^([0-9]{7,8}[A-Z])\$/i", $propValue)) {
             return;
         }
         return self::checkInsee($propValue);
     } elseif ($this->siret) {
         if (!luhn($propValue)) {
             return "Code SIRET incorrect, doit contenir exactement 14 chiffres";
         }
     } elseif ($this->order_number) {
         if (!preg_match('#\\%id#', $propValue)) {
             return "Format de numéro de serie incorrect, doit contenir au moins une fois %id";
         }
     } else {
         return "Spécification de code invalide";
     }
 }
Example #6
0
 // If character is numeric, also add it to the check buffer.
 if (is_numeric($char)) {
     $check_buffer .= $char;
 }
 // If more than max chars in check buffer, remove front values to keep it within max length
 if (strlen($check_buffer) > MAX_LENGTH) {
     $check_buffer = substr($check_buffer, strlen($check_buffer) - MAX_LENGTH);
 }
 // If there are more than min integers in the check buffer, it's a potential credit card number
 if (strlen($check_buffer) >= MIN_LENGTH) {
     // Check all min-max digit sub-strings since credit card could be surrounded by valid numbers.
     // Do max first to match longer ones before any sub-matches.
     for ($i = 0; $i <= strlen($check_buffer) - MIN_LENGTH; $i++) {
         $to_check = substr($check_buffer, $i, MAX_LENGTH);
         while (strlen($to_check) >= MIN_LENGTH) {
             if (luhn($to_check)) {
                 $matched = $to_check;
                 break 2;
             }
             $to_check = substr($to_check, $i, -1);
         }
     }
 }
 // If matched, then mask from full_buffer.
 if ($matched != "") {
     // Go over the check_buffer, replacing each number with an X in the full buffer.
     // Work backwards to account for overlapping values.
     $pos = strlen($matched) - 1;
     for ($i = strlen($full_buffer) - 1; $i >= 0 && $pos != -1; $i--) {
         // Skip over any already masked values.
         if ($full_buffer[$i] == "X") {
 /**
  * Return or create the doctor of the message
  *
  * @param DOMNode $node Node
  *
  * @return CMediusers|int|null
  */
 function getDoctor($node)
 {
     $xpath = new CHPrimSanteMessageXPath($node ? $node->ownerDocument : $this);
     $nodeDoctor = $xpath->query("P.13", $node);
     $code = null;
     $nom = null;
     $prenom = null;
     $type_code = null;
     foreach ($nodeDoctor as $_node_doctor) {
         $code = $xpath->queryTextNode("CNA.1", $_node_doctor);
         $nom = $xpath->queryTextNode("CNA.2/PN.1", $_node_doctor);
         $prenom = $xpath->queryTextNode("CNA.2/PN.2", $_node_doctor);
         $type_code = $xpath->queryTextNode("CNA.3", $_node_doctor);
         if ($code && $nom) {
             break;
         }
     }
     $mediuser = new CMediusers();
     $mediuser->_user_last_name = $nom;
     switch ($type_code) {
         case "R":
             $mediuser->rpps = $code;
             break;
         case "A":
             $mediuser->adeli = $code;
             break;
         default:
             if (strlen($code) == 9 && luhn($code)) {
                 $mediuser->adeli = $code;
             }
             if (strlen($code) == 11 && luhn($code)) {
                 $mediuser->rpps = $code;
             }
     }
     // Cas où l'on a aucune information sur le médecin
     if (!$mediuser->rpps && !$mediuser->adeli && !$mediuser->_id && !$mediuser->_user_last_name) {
         return null;
     }
     $sender = $this->_ref_sender;
     $ds = $mediuser->getDS();
     $ljoin = array();
     $ljoin["functions_mediboard"] = "functions_mediboard.function_id = users_mediboard.function_id";
     $where = array();
     $where["functions_mediboard.group_id"] = " = '{$sender->group_id}'";
     if ($mediuser->rpps || $mediuser->adeli) {
         if ($mediuser->rpps) {
             $where[] = $ds->prepare("rpps = %", $mediuser->rpps);
         }
         if ($mediuser->adeli) {
             $where[] = $ds->prepare("adeli = %", $mediuser->adeli);
         }
         // Dans le cas où le praticien recherché par son ADELI ou RPPS est multiple
         if ($mediuser->countList($where, null, $ljoin) > 1) {
             $ljoin["users"] = "users_mediboard.user_id = users.user_id";
             $where[] = $ds->prepare("users.user_last_name = %", $nom);
         }
         $mediuser->loadObject($where, null, null, $ljoin);
         if ($mediuser->_id) {
             return $mediuser;
         }
     }
     $user = new CUser();
     $ljoin = array();
     $ljoin["users_mediboard"] = "users.user_id = users_mediboard.user_id";
     $ljoin["functions_mediboard"] = "functions_mediboard.function_id = users_mediboard.function_id";
     $where = array();
     $where["functions_mediboard.group_id"] = " = '{$sender->group_id}'";
     $where[] = $ds->prepare("users.user_first_name = %", $prenom);
     $where[] = $ds->prepare("users.user_last_name = %", $nom);
     $order = "users.user_id ASC";
     if ($user->loadObject($where, $order, null, $ljoin)) {
         return $user->loadRefMediuser();
     }
     $mediuser->_user_first_name = $prenom;
     $mediuser->_user_last_name = $nom;
     return $this->createDoctor($mediuser);
 }