function add($number, $email, $phone, $message) { global $db, $countrycode; $userId = getUser($number); $phone = normalizephonenumber($phone); $result = $db->query("SELECT number,mail,userName FROM users where number={$phone} OR mail='{$email}'"); if ($result->num_rows != 0) { $row = $result->fetch_assoc(); $oldPhone = $row["number"]; $oldName = $row["userName"]; $oldMail = $row["mail"]; sendSMS($number, _('Contact information conflict: This number already registered:') . " " . $oldMail . " +" . $oldPhone . " " . $oldName); return; } if ($phone < $countrycode . "000000000" || $phone > $countrycode + 1 . "000000000" || !preg_match("/add\\s+([a-z0-9._%+-]+@[a-z0-9.-]+)\\s+\\+?[0-9]+\\s+(.{2,}\\s.{2,})/i", $message, $matches)) { sendSMS($number, _('Contact information is in incorrect format. Use:') . " ADD king@earth.com 0901456789 Martin Luther King Jr."); return; } $userName = $db->conn->real_escape_string(trim($matches[2])); $email = $db->conn->real_escape_string(trim($matches[1])); $result = $db->query("INSERT into users SET userName='******',number={$phone},mail='{$email}'"); sendConfirmationEmail($email); sendSMS($number, _('User') . " " . $userName . " " . _('added. They need to read email and agree to rules before using the system.')); }
function smscode($number) { global $db, $gatewayId, $gatewayKey, $gatewaySenderNumber, $connectors; srand(); $number = normalizephonenumber($number); $number = $db->conn->real_escape_string($number); $userexists = 0; $result = $db->query("SELECT userId FROM users WHERE number='{$number}'"); if ($result->num_rows) { $userexists = 1; } $smscode = chr(rand(65, 90)) . chr(rand(65, 90)) . " " . rand(100000, 999999); $smscodenormalized = str_replace(" ", "", $smscode); $checkcode = md5("WB" . $number . $smscodenormalized); if (!$userexists) { $text = _('Enter this code to register:') . " " . $smscode; } else { $text = _('Enter this code to change password:'******'{$number}',text='{$text}'"); } $result = $db->query("INSERT INTO history SET userId=0,bikeNum=0,action='REGISTER',parameter='{$number};{$smscodenormalized};{$checkcode}'"); if (DEBUG === TRUE) { response($number, 0, array("checkcode" => $checkcode, "smscode" => $smscode, "existing" => $userexists)); } else { sendSMS($number, $text); if (issmssystemenabled() == TRUE) { response($number, 0, array("checkcode" => $checkcode, "existing" => $userexists)); } else { response($number, 0, array("checkcode" => $checkcode, "existing" => $userexists)); } } }