| | 436 | |
| | 437 | /* |
| | 438 | * function api_searchByEmail |
| | 439 | * @param array $requestData Array containing a key named "email" |
| | 440 | * @param bool $returnUuid If true, returns result's uuid , if |
| | 441 | * false, the id. |
| | 442 | * @return array An array containing response information |
| | 443 | * @returnf string 'type' The type of response (e.g. 'error' or 'result') |
| | 444 | * @returnf string 'message' Message explaining the type / result |
| | 445 | * @returnf array details Either the array of uuid / ids if no errors |
| | 446 | * were encountered, or the original $requestData if there was an error |
| | 447 | */ |
| | 448 | |
| | 449 | function api_searchByEmail($requestData, $returnUuid = true) { |
| | 450 | |
| | 451 | /** |
| | 452 | * Check for required fields and return error if not there. |
| | 453 | */ |
| | 454 | if(!isset($requestData["email"])){ |
| | 455 | $response["type"] = "error"; |
| | 456 | $response["message"] = "Data does not contain a key of 'email'"; |
| | 457 | $response["details"] = $requestData; |
| | 458 | return $response; |
| | 459 | }//end if |
| | 460 | |
| | 461 | /** |
| | 462 | * Do sql search |
| | 463 | */ |
| | 464 | $querystatement = " |
| | 465 | SELECT |
| | 466 | `id`, |
| | 467 | `uuid` |
| | 468 | FROM |
| | 469 | `clients` |
| | 470 | WHERE |
| | 471 | `email` = '".mysql_real_escape_string($requestData["email"])."' |
| | 472 | "; |
| | 473 | |
| | 474 | $queryresult = $this->db->query($querystatement); |
| | 475 | |
| | 476 | /** |
| | 477 | * Construct return array |
| | 478 | */ |
| | 479 | $thereturn["type"] = "result"; |
| | 480 | $thereturn["message"] = "The function api_searchByEmail has been run successfully."; |
| | 481 | $thereturn["details"] = array(); |
| | 482 | while($therecord = $this->db->fetchArray($queryresult)){ |
| | 483 | |
| | 484 | if($returnUuid) |
| | 485 | $thereturn["details"][] = $therecord["uuid"]; |
| | 486 | else |
| | 487 | $thereturn["details"][] = $therecord["id"]; |
| | 488 | |
| | 489 | }//end while |
| | 490 | |
| | 491 | return $thereturn; |
| | 492 | |
| | 493 | }//end function --api_serchByEmail-- |
| | 494 | |
| | 495 | /* |
| | 496 | * function api_searchByNameAndPostalcode |
| | 497 | * @param array $requestData Array containing the keys 'postalcode', |
| | 498 | * 'firstname', or 'lastname'. |
| | 499 | * @param bool $returnUuid If true, returns result's uuid , if |
| | 500 | * false, the id. |
| | 501 | * @return array An array containing response information |
| | 502 | * @returnf string 'type' The type of response (e.g. 'error' or 'result') |
| | 503 | * @returnf string 'message' Message explaining the type / result |
| | 504 | * @returnf array details Either the array of uuid / ids if no errors |
| | 505 | * were encountered, or the original $requestData if there was an error |
| | 506 | */ |
| | 507 | |
| | 508 | function api_searchByNameAndPostalcode($requestData, $returnUuid = true) { |
| | 509 | |
| | 510 | /** |
| | 511 | * check for required fields |
| | 512 | */ |
| | 513 | $requiredArray = array( |
| | 514 | "postalcode", |
| | 515 | "firstname", |
| | 516 | "lastname" |
| | 517 | ); |
| | 518 | |
| | 519 | $missingArray = array(); |
| | 520 | |
| | 521 | foreach($requiredArray as $requiredField) |
| | 522 | if(!isset($requestData[$requiredField])) |
| | 523 | $missingArray[] = $requiredField; |
| | 524 | |
| | 525 | $count = count($missingArray); |
| | 526 | if($count){ |
| | 527 | |
| | 528 | $response["type"] = "error"; |
| | 529 | $response["details"] = $requestData; |
| | 530 | $response["message"] = ""; |
| | 531 | |
| | 532 | $i=0; |
| | 533 | foreach($missingArray as $missingField){ |
| | 534 | |
| | 535 | if(++$i == $count){ |
| | 536 | if($response["message"]) |
| | 537 | $response["message"] .= "and '".$missingField."'"; |
| | 538 | else |
| | 539 | $response["message"] .= "'".$missingField."'"; |
| | 540 | }else |
| | 541 | $response["message"] .= "'".$missingField."', "; |
| | 542 | |
| | 543 | }//end foreach |
| | 544 | |
| | 545 | $response["messsage"] = "Data does not contain the key(s): ".$response["message"]; |
| | 546 | |
| | 547 | return $response; |
| | 548 | |
| | 549 | }//end if |
| | 550 | |
| | 551 | /** |
| | 552 | * do sql search |
| | 553 | */ |
| | 554 | $querystatement = " |
| | 555 | SELECT |
| | 556 | `clients`.`id`, |
| | 557 | `clients`.`uuid` |
| | 558 | FROM |
| | 559 | ( |
| | 560 | (clients INNER JOIN addresstorecord on clients.uuid = addresstorecord.recordid AND addresstorecord.tabledefid='tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' AND addresstorecord.primary=1) |
| | 561 | INNER JOIN addresses ON addresstorecord.addressid = addresses.uuid |
| | 562 | ) |
| | 563 | WHERE |
| | 564 | `clients`.`firstname` = '".mysql_real_escape_string($requestData["firstname"])."' |
| | 565 | AND |
| | 566 | `clients`.`lastname` = '".mysql_real_escape_string($requestData["lastname"])."' |
| | 567 | AND |
| | 568 | `addresses`.`postalcode` = '".mysql_real_escape_string($requestData["postalcode"])."' |
| | 569 | "; |
| | 570 | |
| | 571 | $queryresult = $this->db->query($querystatement); |
| | 572 | |
| | 573 | /** |
| | 574 | * report findings |
| | 575 | */ |
| | 576 | $thereturn["details"] = array(); |
| | 577 | $thereturn["type"] = "result"; |
| | 578 | $thereturn["message"] = "The function api_searchByNameAndPostalcode has been run successfully."; |
| | 579 | while($therecord = $this->db->fetchArray($queryresult)){ |
| | 580 | |
| | 581 | if($returnUuid) |
| | 582 | $thereturn["details"][] = $therecord["uuid"]; |
| | 583 | else |
| | 584 | $thereturn["details"][] = $therecord["id"]; |
| | 585 | |
| | 586 | }//end while |
| | 587 | |
| | 588 | return $thereturn; |
| | 589 | |
| | 590 | }//end function --api_searchByNameAndPostalcode |
| | 591 | |
| | 592 | /* |
| | 593 | * function api_searchByUsernameAndPassword |
| | 594 | * @param array $requestData Array containing the keys 'username' and |
| | 595 | * 'password'. |
| | 596 | * @param bool $returnUuid If true, returns result's uuid , if |
| | 597 | * false, the id. |
| | 598 | * @return array An array containing response information |
| | 599 | * @returnf string 'type' The type of response (e.g. 'error' or 'result') |
| | 600 | * @returnf string 'message' Message explaining the type / result |
| | 601 | * @returnf array details Either the array of uuid / ids if no errors |
| | 602 | * were encountered, or the original $requestData if there was an error |
| | 603 | */ |
| | 604 | |
| | 605 | function api_searchByUsernameAndPassword($requestData, $returnUuid = true) { |
| | 606 | |
| | 607 | /** |
| | 608 | * check for required fields |
| | 609 | */ |
| | 610 | $requiredArray = array( |
| | 611 | "username", |
| | 612 | "password" |
| | 613 | ); |
| | 614 | |
| | 615 | $missingArray = array(); |
| | 616 | |
| | 617 | foreach($requiredArray as $requiredField) |
| | 618 | if(!isset($requestData[$requiredField])) |
| | 619 | $missingArray[] = $requiredField; |
| | 620 | |
| | 621 | $count = count($missingArray); |
| | 622 | if($count){ |
| | 623 | |
| | 624 | $response["type"] = "error"; |
| | 625 | $response["details"] = $requestData; |
| | 626 | $response["message"] = ""; |
| | 627 | |
| | 628 | $i=0; |
| | 629 | foreach($missingArray as $missingField){ |
| | 630 | |
| | 631 | if(++$i == $count){ |
| | 632 | if($response["message"]) |
| | 633 | $response["message"] .= "and '".$missingField."'"; |
| | 634 | else |
| | 635 | $response["message"] .= "'".$missingField."'"; |
| | 636 | }else |
| | 637 | $response["message"] .= "'".$missingField."', "; |
| | 638 | |
| | 639 | }//end foreach |
| | 640 | |
| | 641 | $response["messsage"] = "Data does not contain the key(s): ".$response["message"]; |
| | 642 | |
| | 643 | return $response; |
| | 644 | |
| | 645 | }//end if |
| | 646 | |
| | 647 | /** |
| | 648 | * do sql search |
| | 649 | */ |
| | 650 | $querystatement = " |
| | 651 | SELECT |
| | 652 | `id`, |
| | 653 | `uuid` |
| | 654 | FROM |
| | 655 | `clients` |
| | 656 | WHERE |
| | 657 | `username` = '".mysql_real_escape_string($requestData["username"])."' |
| | 658 | AND |
| | 659 | `password` = '".mysql_real_escape_string($requestData["password"])."' |
| | 660 | "; |
| | 661 | |
| | 662 | $queryresult = $this->db->query($querystatement); |
| | 663 | |
| | 664 | /** |
| | 665 | * report findings |
| | 666 | */ |
| | 667 | $thereturn["details"] = array(); |
| | 668 | $thereturn["type"] = "result"; |
| | 669 | $thereturn["message"] = "The function api_searchByUsernameAndPassword has been run successfully."; |
| | 670 | while($therecord = $this->db->fetchArray($queryresult)){ |
| | 671 | |
| | 672 | if($returnUuid) |
| | 673 | $thereturn["details"][] = $therecord["uuid"]; |
| | 674 | else |
| | 675 | $thereturn["details"][] = $threturn["id"]; |
| | 676 | |
| | 677 | }//end while |
| | 678 | |
| | 679 | return $thereturn; |
| | 680 | |
| | 681 | }//end function --api_searchByUsernameAndPassword-- |