Advertisement
Guest User

php function not working

a guest
Feb 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.81 KB | None | 0 0
  1.  public function addNewSubscriberApi()
  2.     {
  3.         header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
  4.         header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
  5.         header('Access-Control-Max-Age: 1000');
  6.         header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
  7.  
  8.  
  9.         $nameRegExp='!|\^|\$|\*|\\|\[|\]|\(|\)|\{|\}|\+|\||\?|@|#|%|&|:|;|"|<|>|=|,|\.|\/';
  10.         // // $regexp="^([ \u00c0-\u01ffa-zA-Z'\-])+$";
  11.         $phoneRegExp  = "^(\+[0-9]* [0-9]*|\+[0-9]*) [0-9]*$";
  12.        
  13.         $firstname = $_GET['firstName'];  
  14.         $lastname  = $_GET['lastName'];
  15.         $email = $_GET['email'];
  16.         $phonenumber = $_GET['phoneNumber'];
  17.        
  18.         $debug = array("fileName"=>__FILE__);
  19.         $debug["line"]= __LINE__;
  20.         $message = "Unknown error.";
  21.         $success = false;
  22.         $errorCode = -1;
  23.  
  24.         if(isset($firstname)  && !ereg($nameRegExp , $firstname) ){
  25.                 if(isset($lastname) && !ereg($nameRegExp , $lastname) ){
  26.                     if(isset($email)){
  27.                         if(isset($phonenumber) && ereg($phoneRegExp,$phonenumber) ){
  28.                                
  29.                                 $subscriber = new NewsletterSubscription();
  30.                                 $subscriber->firstName = $firstname;          
  31.                                 $subscriber->lastName = $lastname;
  32.                                 $subscriber->email = $email;
  33.                                 $subscriber->verified = $subscriber->isNotVerified ;
  34.                                 $subscriber->phoneNumber = $phonenumber;
  35.                                 $id = $subscriber->insert();
  36.                                 if($id)
  37.                                 {
  38.                                     $debug["line"]= __LINE__;
  39.                                     $success = true;
  40.                                     $addedNewEntryMessage = "Succesfully added new Entry.";
  41.                                     // might change to be the api link
  42.                                     $link="http://www.appsandgamesinc.com/backoffice/modules/newsletter/emailVerification.php";
  43.  
  44.                                     $verificationArray = $this->sendVerificationEmail($email , $link);
  45.                                     $success= $verificationArray['success'];
  46.                                     $addedNewEntryMessage = $verificationArray['message'];
  47.                                     if($success){
  48.                                         $errorCode = 200;
  49.                                     }
  50.  
  51.                                 }
  52.                                 else {
  53.                                     $debug["line"]= __LINE__;
  54.                                     $addedNewEntryMessage = "Error Something went wrong.";
  55.  
  56.                                 }
  57.  
  58.                         }else {
  59.                             $debug["line"]= __LINE__;
  60.                             $addedNewEntryMessage ="Phone number not valid or not set.";
  61.  
  62.                         }  
  63.                        
  64.                     }else {
  65.                         $debug["line"]= __LINE__;
  66.                         $addedNewEntryMessage ="email not valid or not set.";
  67.                     }
  68.  
  69.                 }else {
  70.                     $debug["line"]= __LINE__;
  71.                     $addedNewEntryMessage ="Last name not valid or not set.";
  72.  
  73.                 }
  74.  
  75.             }else{
  76.                 $debug["line"]= __LINE__;
  77.                 $addedNewEntryMessage ="First name not set or invalid.";
  78.             }
  79.  
  80.  
  81.         $json_reply = array("success"=>$success, "errorCode" => $errorCode, "message"=>$message , "debug"=>$debug);
  82.         echo $_GET['callback'] . "(" . json_encode($json_reply, true) . ");";
  83.         // echo json_encode($json_reply, true);
  84.  
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement