Esempio n. 1
1
 public function index()
 {
     error_reporting(0);
     header('Content-type: text/plain');
     set_time_limit(100);
     //get inputs
     $sessionId = $_REQUEST["sessionId"];
     $serviceCode = $_REQUEST["serviceCode"];
     $phoneNumber = $_REQUEST["phoneNumber"];
     $text = $_REQUEST["text"];
     //
     $data = ['phone' => $phoneNumber, 'text' => $text, 'service_code' => $serviceCode, 'session_id' => $sessionId];
     //log USSD request
     ussd_logs::create($data);
     $no = substr($phoneNumber, -4);
     $no2 = substr($phoneNumber, -9);
     $no2 = "+254" . $no2;
     $jokes = array("Q: Why did the 30-60-90 triangle marry the 45-45-90 triangle?\n            A: They were right for each other", "Q: Why didn't the Romans find algebra very challenging?\nA: Because X was always 10", "Q: What do you get if you divide the circumference of a jack-o-lantern by its diameter?\nA: Pumpkin Pi\n\n", "Q: Why couldn't the angle get a loan?\n            A: His parents wouldn't Cosine\n\n", "Q: Why is beer never served at a math party?\nA: Because you can't drink and derive.\n\n        ", "Q: Why didn't the number 4 get into the nightclub?\nA: Because he is 2 square", "\n\nQ. Why was the math book sad?\nA. Because it had so many problems.\n", "Q: What is a bird's favorite type of math?\n            A: Owl-gebra\n\n", "Q: What is a French mathematician's favorite pick up line?\nA: 'Voulez vous Cauchy avec moi?'\n", "Q: Why did the obtuse angle go to the beach?\nA: Because it was over 90 degrees\n\n", "Q: Why do plants hate math?\nA: Because it gives them square roots.\n\n", "Q: What is the first derivative of a cow?\nA: Prime Rib!\n", "Q: What's the integral of (1/cabin)d(cabin)?\n                A: A natural log cabin!\n\n            ", "Q: What do you call a man who spent all summer at the beach?\n                A: A Tangent\n\n", "Q: What do you call a snake after it drinks five cups of coffee?\n                A: A hyper boa\n", "Q: What did Al Gore play on his guitar?\n                A: An Algorithm\n", "Q: What do you call an angle that is adorable?\n                A: acute angle\n", "Q: What do you call a destroyed angle?\n                A: A Rect-angle\n", "Q: Why did the student get upset when his teacher called him average?\n                A: It was a 'mean' thing to say!\n\n            ", "Q: Why was the Calculus teacher bad at baseball?\n                A: He was better at fitting curves than hitting them\n", "Q: Why did the polynomial plant die?\n                A: Its roots were imaginary.\n            ", "Q: Why does nobody talk to circles?\n                A: Because there is no point!\n            ", "Q: What is a math teacher's favorite type of tree?\nA: A 'Geome-tree'", "\nQ. What do you get if you cross a math teacher and a clock?\nA. Arithma-ticks!\n", "Q: What happened to the indeterminate form that got sick?\nA: It had to go to L'Hospital\n", "Q: What's the contour integral around Western Europe? \nA: Zero, because all the Poles are in Eastern Europe!\n", "Q: What do you call a teapot of boiling water on top of mount everest?\nA: A high-pot-in-use\n", "Q: Why did the two 4's skip lunch?\n                A: They already 8!\n\n            ", "Q: Why didn't Bob drink a glass of water with 8 pieces of ice in it?\nA: It was too cubed\n", "Q: What did one Calculus book say to the other?\nA: Don't bother me I've got my own problems!\n", "Q: Which triangles are the coldest?\nA: Ice-sosceles triangles\n", "Q: Who invented the Round Table?\nA: Sir Cumference\n", "Q: Why is Ms. Radian such a good reporter?\nA: She covers the story from every angle\n", "Q: Why do you rarely find mathematicians spending time at the beach?\nA: Because they have sine and cosine to get a tan and don't need the sun!\n            ", "Q: Why didn't the chicken cross to the other side of the inequality?\nA: It couldn't get past the boundary line\n", "Q: How can a fisherman determine how many fish he needs to catch to make a profit?\n                A: By using a cod-ratic inequality\n", "Q: What does the little mermaid wear?\n                A: An algae-bra\n", "Q: What is the definition of a polar bear?\n                A: A rectangular bear after a coordinate transformation\n", "Q: Why is the Rational Root Theorem so polite?\n                A: It minds its p's and q's\n", "Q: What did the student say when the witch doctor removed his curse?\n                A: Hexagon\n\n", "Q: Why did the boy eat his math homework?\n                A: Because the teacher told him it was a piece of cake.\n\n            ", "Q: Have you heard the latest statistics joke?\n                A: Probably\n", "Q: How do you know that your dentist studied algebra?\n                A: She said all that candy gave me exponential decay\n", "Q: What do you call more than one L?\n                A: A Parallel\n", "Q: Why didn't sin and tan go to the party?\nA: Just cos\n", "Q: What did the complementary angle say to the isosceles triangle?\nA: Nice Legs\n", "Q: What is polite and works for the phone company?\nA: A deferential operator\n", "Q: What do you get when you cross a mosquito with a mountain climber?\nA: Nothing. You can't cross a vector and a scalar.\n            ", "Q: What's nonorientable and lives in the sea? \nA: Moebius Dick. ", "\nQ. Why was 6 afraid of 7?\nA. Because 7 8 9!\n", "Q: What do you call a dead parrot?\nA: Polygon", "\nQ. What's the king of the pencil case?\nA. The ruler.\n            ", "Q: What did the zero say to the the eight?\n                A: Nice belt!", "\n            Q. What's the difference between a diameter and a radius?\nA. A Radius", "\nQ. What tool do you use in mathematics?\nA. Multi-plyers.\n", "Q: How does a mathematician call his dog?\nA: Cauchy, because it leaves a residue at every pole.", "\nQ: What's purple and commutes?\n                A. An Abelian grape.\n            ", "Q: What's yellow and imaginary?\nA: The square-root of negative banana\n", "Q: How do deaf mathematicians communicate?\nA: They use sine language\n", "Q: What do organic mathematicians throw into their fireplaces?\nA: Natural Logs\n", "Q: Why was a student's rubber band pistol confiscated during algebra class?\nA: It was considered a weapon of math disruption.\n            ", "Q: How do you make one vanish?\n                A: Add a 'g' to the beginning and it's gone!\n", "Q: Why shouldn't you argue with a decimal?\n                A: Decimals always have a point.\n            ", "Q: What did the baby tree say when it looked in a mirror?\n                A: Gee-Im-A-Tree\n", "Q: How can you tell that a mathematician is extroverted?\n                A: When he talks to you, he looks at YOUR shoes instead of his shoes.\n            ", "Q: How is an artificial christmas tree like the fourth root of -68?\n                A: Neither has real roots.\n            ", "Q: What do you call a number that can't keep still?\nA: A roamin' numeral.\n            ", "Q: Why don't you do arithmetic in the jungle?\nA: Because if you add 4+4 you get ate!\n", "Q: What does a mathematician do about constipation?\nA: He works it out with a pencil\n", "Q: What is the world's longest song?\n                A: 'Aleph-naught Bottles of Beer on the Wall.'\n", "Q: How does a mathematician induce good behavior in her children?\n                A: 'I've told you n times, I've told you n+1 times…'\n", "Q: What is the difference between a Ph.D. in mathematics and a large pizza?\n                A: A large pizza can feed a family of four\n", "Q: What polygon is also a card trick?\n                A: Decagon\n", "Q: Why did the statistician drown while crossing a river?\n                A: It was 3 feet deep... on average\n", "Q: What do you call it when a mathematician's parrot hasn't been fed?\n                A: Poly'no meal'\n", "Q: How do you solve any equation?\n                A: Multiply both sides by zero.\n            ", "Q: How does one insult a mathematician?\n                A: Tell them that their brain is smaller than any ε > 0\n", "Q: What did 2 say to 4 after 2 beat him in a race?\n                A: I'm 2 Fast 4 U!");
     if ($no == '9038' || $no == '5429') {
         //check if they have received airtime in the past and how much
         $airtime = airtime::wherePhone($phoneNumber)->orderBy('id', 'DESC')->first();
         $time_from_creation = Carbon::now()->diffInMinutes(Carbon::createFromTimestamp($airtime->created_at->timestamp));
         if ($time_from_creation) {
             if ($time_from_creation > airtime_time) {
                 $recipients = array();
                 $data = array();
                 $data['phoneNumber'] = $no2;
                 $data['amount'] = "KES 20";
                 array_push($recipients, $data);
                 //sending the airtime
                 $notify = new NotifyController();
                 $data = ['phone' => $phoneNumber, 'amount' => 20];
                 //log USSD request
                 airtime::create($data);
                 $notify->sendAirtime($recipients);
                 shuffle($jokes);
                 $response = "Sawa mummy, airtime is on it's way" . PHP_EOL . trim($jokes[0]);
             } else {
                 $diff = airtime_time - $time_from_creation;
                 shuffle($jokes);
                 $response = "Eish Mummy, retry after " . $diff . " minutes" . PHP_EOL . trim($jokes[0]);
             }
         } else {
             $recipients = array();
             $data = array();
             $data['phoneNumber'] = $phoneNumber;
             $data['amount'] = "KES 20";
             array_push($recipients, $data);
             //sending the airtime
             $notify = new NotifyController();
             $data = ['phone' => $phoneNumber, 'amount' => 20];
             //log USSD request
             airtime::create($data);
             $notify->sendAirtime($recipients);
             $response = "Sawa mummy, airtime is on it's way";
         }
     } else {
         $response = "Eish yawa, it is only for Mummy Sly. Talk to Le-yo nicely." . PHP_EOL . trim($jokes[0]);
     }
     self::sendresponse($response, 3);
 }
Esempio n. 2
0
 public function confirmUssdProcess($user, $message)
 {
     $menu = ussd_menu::find($user->menu_id);
     if (self::validationVariations($message, 1, "yes")) {
         //if confirmed
         if (self::postUssdConfirmationProcess($user)) {
             $response = $menu->confirmation_message;
         } else {
             $response = "We had a problem processing your request. Please contact Watu Credit Customer Care on 0729 405 464";
         }
         self::resetUser($user);
         $notify = new NotifyController();
         $notify->sendSms($user->phone_no, $response);
         self::sendResponse($response, 2, $user);
     } elseif (self::validationVariations($message, 2, "no")) {
         if ($user->menu_id == 3) {
             self::resetUser($user);
             $menu = menu::find(2);
             $user->menu_id = 2;
             $user->session = 2;
             $user->progress = 1;
             $user->save();
             //get home menu
             $menu = menu::find(2);
             $menu_items = self::getMenuItems($menu->id);
             $i = 1;
             $response = $menu->title . PHP_EOL;
             foreach ($menu_items as $key => $value) {
                 $response = $response . $i . ": " . $value->description . PHP_EOL;
                 $i++;
             }
             self::sendResponse($response, 1, $user);
         }
         $response = self::nextMenuSwitch($user, $menu);
         return $response;
     } else {
         //not confirmed
         $response = "We could not understand your response";
         //restart the process
         $output = self::confirmBatch($user, $menu);
         $response = $response . PHP_EOL . $output;
         return $response;
         //request to confirm again
     }
 }