phpBMS

Changeset 689

Show
Ignore:
Timestamp:
12/22/09 16:46:21 (2 years ago)
Author:
nate
Message:
  • Added a few standard api functions in clients, invoices, and products.
Location:
trunk/phpbms/modules
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/api/include/apiclass.php

    r645 r689  
    389389                        $methodName = $request["command"]; 
    390390 
    391                         $this->response[] = $processor->$methodName($request["data"]); 
     391                        $this->response[] = $processor->$methodName($request["data"], $this->options->useUuid); 
    392392 
    393393                    }//endif 
     
    420420                    $methodName = $request["command"]; 
    421421 
    422                     $this->response[] = $processor->$methodName($request["data"]); 
     422                    $this->response[] = $processor->$methodName($request["data"], $this->options->useUuid); 
    423423 
    424424                }//endif 
  • trunk/phpbms/modules/bms/include/clients.php

    r682 r689  
    434434 
    435435                }//end method - insertRecord 
     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-- 
    436682 
    437683        }//end class 
  • trunk/phpbms/modules/bms/include/invoices.php

    r638 r689  
    12121212 
    12131213                }//end method - insertRecord 
     1214                 
     1215                /* 
     1216                 * function api_searchByClientUuid 
     1217                 * @param array $requestData Array containting the key "clientid", and, 
     1218                 * optionally, the keys "type" (relating to the invoice type, e.g. "Quote"), 
     1219                 * "startdate", and "enddate" which put an upper and lower bound to the 
     1220                 * invoice's datetime (with sql format). 
     1221                 * @param bool $returnUuid If true, returns result's uuid , if 
     1222                 * false, the id. 
     1223                 * @return array An array containing response information 
     1224                 * @returnf string 'type' The type of response (e.g. 'error' or 'result') 
     1225                 * @returnf string 'message' Message explaining the type / result 
     1226                 * @returnf array details Either the array of uuid / ids if no errors 
     1227                 * were encountered, or the original $requestData if there was an error 
     1228                 */ 
     1229                 
     1230                function api_searchByClientUuid($requestData, $returnUuid = true) { 
     1231                         
     1232                        /** 
     1233                          *  check for required field  
     1234                          */ 
     1235                        if(!isset($requestData["clientid"])){ 
     1236                                $response["type"] = "error"; 
     1237                                $response["message"] = "Data does not contain a key of 'clientid'."; 
     1238                                $response["details"] = $requestData; 
     1239                                 
     1240                                return $response; 
     1241                        }//end if 
     1242                         
     1243                        /** 
     1244                          *  do sql search  
     1245                          */ 
     1246                        $querystatement = " 
     1247                                SELECT 
     1248                                        `id`, 
     1249                                        `uuid` 
     1250                                FROM 
     1251                                        `invoices` 
     1252                                WHERE 
     1253                                        `clientid` = '".mysql_real_escape_string($requestData["clientid"])."' 
     1254                        "; 
     1255                         
     1256                        if(isset($requestData["type"])) 
     1257                                $querystatement .= "AND `type` = '".mysql_real_escape_string($requestData["type"])."'"; 
     1258                         
     1259                        if(isset($requestData["startdate"])) 
     1260                                $querystatement .= "AND `creationdate` >= '".mysql_real_escape_string($requestData["startdate"])."'"; 
     1261                                 
     1262                        if(isset($requestData["enddate"])) 
     1263                                $querystatement .= "AND `creationdate` <= '".mysql_real_escape_string($requestData["enddate"])."'"; 
     1264                         
     1265                        $queryresult = $this->db->query($querystatement); 
     1266                         
     1267                        /** 
     1268                          *  report findings  
     1269                          */ 
     1270                        $thereturn["details"] = array(); 
     1271                        $thereturn["message"] = "The function api_searchByPartNumber has been run successfully."; 
     1272                        $thereturn["type"] = "result"; 
     1273                        while($therecord = $this->db->fetchArray($queryresult)){ 
     1274                                 
     1275                                if($returnUuid) 
     1276                                        $thereturn["details"][] = $therecord["uuid"]; 
     1277                                else 
     1278                                        $thereturn["details"][] = $therecord["id"]; 
     1279                                 
     1280                        }//end while 
     1281                         
     1282                        return $thereturn; 
     1283                         
     1284                }//end function --api_searchByClientUuid-- 
    12141285 
    12151286        }//end class 
  • trunk/phpbms/modules/bms/include/products.php

    r641 r689  
    531531 
    532532                }//end function updateCategories 
     533                 
     534                /* 
     535                 * function api_searchByPartNumber 
     536                 * @param array $requestData Array containing the "partnumber" key. 
     537                 * @param bool $returnUuid If true, returns result's uuid , if 
     538                 * false, the id. 
     539                 * @return array An array containing response information 
     540                 * @returnf string 'type' The type of response (e.g. 'error' or 'result') 
     541                 * @returnf string 'message' Message explaining the type / result 
     542                 * @returnf array details Either the array of uuid / ids if no errors 
     543                 * were encountered, or the original $requestData if there was an error 
     544                 */ 
     545                 
     546                function api_searchByPartNumber($requestData, $returnUuid = true) { 
     547                         
     548                        /** 
     549                          *  do error search  
     550                          */ 
     551                        if(!isset($requestData["partnumber"])){ 
     552                                $response["type"] = "error"; 
     553                                $response["message"] = "Data does not contain a key of 'partnumber'."; 
     554                                $response["details"] = $requestData; 
     555                                return $response; 
     556                        }//end if 
     557                         
     558                        /** 
     559                          *  do query search  
     560                          */ 
     561                        $querystatement = " 
     562                                SELECT 
     563                                        `id`, 
     564                                        `uuid` 
     565                                FROM 
     566                                        `products` 
     567                                WHERE 
     568                                        `partnumber` = '".mysql_real_escape_string($requestData["partnumber"])."' 
     569                        "; 
     570                         
     571                        $queryresult = $this->db->query($querystatement); 
     572                         
     573                        /** 
     574                          *  report result  
     575                          */ 
     576                        $thereturn["message"] = "The function api_searchByPartNumber has been run successfully."; 
     577                        $thereturn["type"] = ""; 
     578                        $thereturn["details"] = array(); 
     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_searchByPartNumber-- 
    533591 
    534592        }//end class products 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.