示例#1
0
 function getRecord($id = 0, $useUuid = false)
 {
     $therecord = parent::getRecord($id, $useUuid);
     if ($therecord["job"]) {
         $therecord["scripttype"] = "job";
     } else {
         $therecord["scripttype"] = "pushrecord";
     }
     $datearray = explode(" ", $therecord["startdatetime"]);
     $therecord["startdate"] = $datearray[0];
     if (isset($datearray[1])) {
         $therecord["starttime"] = $datearray[1];
     } else {
         $therecord["starttime"] = "";
     }
     $datearray = explode(" ", $therecord["enddatetime"]);
     $therecord["enddate"] = $datearray[0];
     if (isset($datearray[1])) {
         $therecord["endtime"] = $datearray[1];
     } else {
         $therecord["endtime"] = "";
     }
     $cronarray = explode("::", $therecord["crontab"]);
     if (isset($cronarray[0])) {
         $therecord["min"] = $cronarray[0];
     } else {
         $therecord["min"] = "*";
     }
     if (isset($cronarray[1])) {
         $therecord["hrs"] = $cronarray[1];
     } else {
         $therecord["hrs"] = "*";
     }
     if (isset($cronarray[2])) {
         $therecord["date"] = $cronarray[2];
     } else {
         $therecord["date"] = "*";
     }
     if (isset($cronarray[3])) {
         $therecord["mo"] = $cronarray[3];
     } else {
         $therecord["mo"] = "*";
     }
     if (isset($cronarray[4])) {
         $therecord["day"] = $cronarray[4];
     } else {
         $therecord["day"] = "*";
     }
     $therecord["lastrun"] = formatFromSQLDatetime($therecord["lastrun"]);
     return $therecord;
 }
示例#2
0
 function getRecord($id, $useUuid = false)
 {
     $therecord = parent::getRecord($id, $useUuid);
     /**
      *   If type is credit, get the receipt id
      *   else get the invoice id
      */
     if ($therecord["type"] == "credit") {
         $therecord["editrelatedid"] = getId($this->db, "tbld:43678406-be25-909b-c715-7e2afc7db601", $therecord["relatedid"]);
     } else {
         $therecord["editrelatedid"] = getId($this->db, "tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883", $therecord["relatedid"]);
     }
     return $therecord;
 }
示例#3
0
 /**
  *  function getRecord()
  */
 function getRecord($id, $useUuid = false)
 {
     $therecord = parent::getRecord($id, $useUuid);
     /**
      *  Custom api command
      */
     $therecord["customcommand"] = "";
     switch ($therecord["apicommand"]) {
         case "insert":
         case "update":
             break;
         default:
             $therecord["customcommand"] = $therecord["apicommand"];
             $therecord["apicommand"] = "custom";
             break;
     }
     //end switch
     /**
      *  Custom where (saved search)
      */
     $therecord["customwhere"] = "";
     $therecord["whereselection"] = "";
     switch ($therecord["whereclause"]) {
         case "all":
         case "select":
             $therecord["whereselection"] = $therecord["whereclause"];
             break;
         default:
             $therecord["customwhere"] = $therecord["whereclause"];
             $therecord["whereselection"] = "custom";
             break;
     }
     //end switch
     /**
      *  Custom destination tabledefuuid
      */
     $querystatement = "\n            SELECT\n                `id`\n            FROM\n                `tabledefs`\n            WHERE\n                `uuid` = '" . mysql_real_escape_string($therecord["destuuid"]) . "'\n            ";
     $queryresult = $this->db->query($querystatement);
     $therecord["usecustomdestuuid"] = 0;
     $therecord["customdestuuid"] = "";
     if (!$this->db->numRows($queryresult)) {
         $therecord["usecustomdestuuid"] = 1;
         $therecord["customdestuuid"] = $therecord["destuuid"];
     }
     //end if
     return $therecord;
 }
示例#4
0
 function getRecord($id, $useUuid = false)
 {
     $therecord = parent::getRecord($id, $useUuid);
     $therecord["typeCheck"] = $therecord["type"];
     return $therecord;
 }
示例#5
0
 /**
  * function getRecord
  *
  * Retrieves a single record from the database
  *
  * @param integer|string $id the record id or uuid
  * @param bool $useUuid specifies whther the $id is a uuid (true) or not.  Default is false
  *
  * @return array the record as an associative array
  */
 function getRecord($id, $useUuid = false)
 {
     $therecord = parent::getRecord($id, $useUuid);
     $therecord["catschanged"] = 1;
     $therecord["addcats"] = $this->getAdditionalCategories($therecord["uuid"]);
     return $therecord;
 }
示例#6
0
 function getRecord($id, $useUuid = false)
 {
     $id = !$useUuid ? (int) $id : mysql_real_escape_string($id);
     $therecord = parent::getRecord($id, $useUuid);
     if ($therecord["id"]) {
         //need to grab the address as well
         $querystatement = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tid\n\t\t\t\t\tFROM\n\t\t\t\t\t\taddresstorecord\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`tabledefid` = 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083'\n\t\t\t\t\t\tAND `primary` = '1'\n\t\t\t\t\t\tAND `recordid` = '" . $therecord["uuid"] . "'\n\t\t\t\t";
         $queryresult = $this->db->query($querystatement);
         $addressinfo = $this->db->fetchArray($queryresult);
         if (count($addressinfo)) {
             $addressinfo = $this->address->getRecord($addressinfo["id"]);
         } else {
             $addressinfo = $this->address->getDefaults();
             $addressinfo["addressid"] = NULL;
         }
         //endif
         unset($addressinfo["id"], $addressinfo["uuid"], $addressinfo["notes"], $addressinfo["email"], $addressinfo["createdby"], $addressinfo["creationdate"], $addressinfo["modifiedby"], $addressinfo["modifieddate"]);
         $therecord = array_merge($therecord, $addressinfo);
     }
     //endif
     return $therecord;
 }
示例#7
0
 /**
  *
  * function getRecord
  * retrieves sales order record
  *
  * @param int|string $id the id or uuid of the sales order record
  * @param bool $useUuid is the passed $id is referenceing an id (false/default) or a uuid (true)
  *
  * @return array associateive array with the record information
  */
 function getRecord($id, $useUuid = false)
 {
     $therecord = parent::getRecord($id, $useUuid);
     if ((int) $therecord["posted"] != 0 && ENCRYPT_PAYMENT_FIELDS) {
         $querystatement = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`ccnumber`,\n\t\t\t\t\t\t`ccverification`,\n\t\t\t\t\t\t`ccexpiration`,\n\t\t\t\t\t\t`accountnumber`,\n\t\t\t\t\t\t`routingnumber`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`receipts`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`uuid` = '" . $therecord["uuid"] . "'\n\t\t\t\t";
         $queryresult = $this->db->query($querystatement);
         $unEncryptedRecord = $this->db->fetchArray($queryresult);
         $therecord["ccnumber"] = $unEncryptedRecord["ccnumber"];
         $therecord["ccverification"] = $unEncryptedRecord["ccverification"];
         $therecord["ccexpiration"] = $unEncryptedRecord["ccexpiration"];
         $therecord["accountnumber"] = $unEncryptedRecord["accountnumber"];
         $therecord["routingnumber"] = $unEncryptedRecord["routingnumber"];
     }
     //end if
     if (ENCRYPT_PAYMENT_FIELDS && (int) $therecord["posted"] == 0) {
         if ($therecord["ccverification"]) {
             $therecord["ccverification"] = str_repeat("*", strlen($therecord["ccverification"]));
         }
         if ($therecord["ccnumber"]) {
             $therecord["ccnumber"] = str_repeat("*", strlen($therecord["ccnumber"] - 4)) . substr($therecord["ccnumber"], -4);
         }
         if ($therecord["routingnumber"]) {
             $therecord["routingnumber"] = str_repeat("*", strlen($therecord["routingnumber"] - 4)) . substr($therecord["routingnumber"], -4);
         }
         if ($therecord["accountnumber"]) {
             $therecord["accountnumber"] = str_repeat("*", strlen($therecord["accountnumber"] - 4)) . substr($therecord["accountnumber"], -4);
         }
     }
     //end if
     /**
      *  Now, need to get receiptitems.
      */
     if ($this->receiptitems === NULL) {
         $this->receiptitems = new receiptitems($this->db);
     }
     $therecord["itemslist"] = $this->receiptitems->get($therecord["uuid"]);
     $therecord["itemschanged"] = 1;
     return $therecord;
 }
示例#8
0
 /**
  * function process
  * Process request array posted to api
  *
  * The method process() loops through the request array, and attempts to
  * find a corresponding function to run for the request. It first looks for
  * a corresponding api class to load. If it does not find it, it next to
  * see if there is an overriden table class file, and finally if none of
  * these are present, it uses the standard table class.
  *
  */
 function process()
 {
     $i = 1;
     $tabledefid = null;
     if (!is_array($this->data)) {
         $this->sendError("Passed data malformed.  Was expecting an array.", $this->data, true);
     }
     foreach ($this->data as $request) {
         if (!is_array($request)) {
             $this->sendError("Malformed request number " . $i, $request);
         }
         if (!isset($request["tabledefid"]) || !isset($request["command"]) || !isset($request["data"])) {
             $this->sendError("Malformed request number " . $i, $request);
         }
         /**
          *  Process the options and populate the options object.
          */
         if (!isset($request["options"])) {
             $request["options"] = NULL;
         }
         $this->processOptions($request["options"]);
         if ((int) $request["tabledefid"] !== $tabledefid) {
             $tabledefid = mysql_real_escape_string($request["tabledefid"]);
             //First let's get the table information from the tabledef
             $querystatement = "\n                    SELECT\n                        `maintable`,\n                        `deletebutton`,\n                        `querytable`,\n                        `modules`.`name`,\n                        `apiaccessible`\n                    FROM\n                        `tabledefs` INNER JOIN `modules` ON tabledefs.moduleid = modules.uuid\n                    WHERE\n                        tabledefs.uuid = '" . $tabledefid . "'\n                ";
             $queryresult = $this->db->query($querystatement);
             if ($this->db->numRows($queryresult) == 0) {
                 if (!in_array($request["command"], array("procedure", "getsetting"))) {
                     $this->sendError("Invalid tabledefid (" . $tabledefid . ") from request number " . $i);
                     continue;
                 } else {
                     $deletebutton = "delete";
                     $maintable = "settings";
                     $modulename = "base";
                     $hasAPIOveride = false;
                     $hasTableClassOveride = false;
                 }
                 //endif
             } else {
                 $therecord = $this->db->fetchArray($queryresult);
                 if (!$therecord["apiaccessible"]) {
                     $this->sendError("Invalid tabledefid (" . $tabledefid . ") from request number " . $i . ": This table definition is inaccessible via api.");
                     continue;
                 }
                 //endif
                 $deletebutton = $therecord["deletebutton"];
                 $maintable = $therecord["maintable"];
                 $modulename = $therecord["name"];
                 //check for ovridding classes only once.
                 $hasAPIOveride = file_exists("../extendedapi/" . $maintable . ".php");
                 $hasTableClassOveride = file_exists("../" . $modulename . "/include/" . $maintable . ".php");
             }
             //endif
         }
         //endif
         /* Order in which to check for processors is as follows:
         
                        If the extendedAPI module is present, look for a file matching the main
                        table name of the table def.
                        Example: modules/extendedapi/clients.php
         
                        If a table class file exists in the module's include folder
                        use that.
                        Example: modules/bms/include/clients.php
         
                        Use the standard class module.
         
                     */
         $methodName = "";
         if ($hasAPIOveride) {
             // Found an API module table php
             @(include_once "modules/extendedapi/" . $maintable . ".php");
             $className = $className . "Api";
             if (class_exists($className)) {
                 $processor = new $className($this->db);
                 $processor->dateFormat = $this->options->dateFormat;
                 $processor->timeFormat = $this->options->timeFormat;
                 if (!method_exists($processor, $request["command"])) {
                     $methodName = $request["command"];
                     $this->response[] = $processor->{$methodName}($request["data"], $this->options->useUuid);
                 }
                 //endif
             }
             //end if
         }
         //endif
         /* If the command starts with api_, and there is a request overload, let's assume they
               are trying to call a homeade function in the ovveriden phpBMS table that they created.
            */
         if (!$methodName && substr($request["command"], 0, 4) == "api_" && $hasTableClassOveride) {
             include_once "include/tables.php";
             @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
             if (class_exists($maintable)) {
                 $processor = new $maintable($this->db, $tabledefid);
                 $processor->dateFormat = $this->options->dateFormat;
                 $processor->timeFormat = $this->options->timeFormat;
             } else {
                 $processor = new phpbmsTable($this->db, $tabledefid);
                 $processor->dateFormat = $this->options->dateFormat;
                 $processor->timeFormat = $this->options->timeFormat;
             }
             if (method_exists($processor, $request["command"])) {
                 $methodName = $request["command"];
                 $this->response[] = $processor->{$methodName}($request["data"], $this->options->useUuid);
             }
             //endif
         }
         //endif
         if (!$methodName) {
             /* Either using the modules overriden table class or search
                                functions class or the standard one There are several
                                standard commands that can be passed:
             
                                * insert - calls the tabledefs insertRecord command, the
                                             same command that is called on standard
                                             phpBMS forms. a variable array should be
                                             passed in the request data.
             
                                * update - calls the tabledefs iupdateRecord command, the
                                             same command that is called on standard
                                             phpBMS forms. a variable array should be
                                             passed in the request data
             
                                * delete (or the corresponding delete button command)
                                         - calls the deleteRecord searchFunctions command
                                         data should be an array of ids
             
                                * procedure - This calls a stored MySQL stored procedure
                                              request data should pass an object with the
                                              (name) and optionally an array of any
                                              (parameters)
             
                                 In addition, you can pass a command that corresponds to
                                 any additional commands as defined in the table definition
                                 the request data passed should contain an array of ids
                             */
             switch ($request["command"]) {
                 case "ping":
                     //======================================================
                     $this->_addToResponse("message", "Everything is phpBMSy!");
                     break;
                 case "getDefaults":
                     include_once "include/tables.php";
                     if ($hasTableClassOveride) {
                         @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
                         if (class_exists($maintable)) {
                             $processor = new $maintable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         } else {
                             $processor = new phpbmsTable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         }
                         //end if
                     } else {
                         $processor = new phpbmsTable($this->db, $tabledefid);
                         $processor->dateFormat = $this->options->dateFormat;
                         $processor->timeFormat = $this->options->timeFormat;
                     }
                     //end if
                     $therecord = $processor->getDefaults();
                     $this->_addToResponse("retrieved", "defaults retrieved in tabledef " . $tabledefid, $therecord);
                     break;
                 case "insert":
                     //======================================================
                     include_once "include/tables.php";
                     if ($hasTableClassOveride) {
                         @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
                         if (class_exists($maintable)) {
                             $processor = new $maintable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         } else {
                             $processor = new phpbmsTable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         }
                         //end if
                     } else {
                         $processor = new phpbmsTable($this->db, $tabledefid);
                         $processor->dateFormat = $this->options->dateFormat;
                         $processor->timeFormat = $this->options->timeFormat;
                     }
                     //end if
                     $errorArray = $processor->verifyVariables((array) $request["data"]);
                     if (count($errorArray)) {
                         $this->sendError("Insert failed from request number " . $i, $errorArray);
                     } else {
                         $overrideID = false;
                         if (is_array($request["data"])) {
                             if (isset($request["data"]["id"])) {
                                 if ((int) $request["data"]["id"] !== 0) {
                                     $overrideID = true;
                                 }
                                 if ($this->options->keepDestId && isset($request["data"]["uuid"]) && $this->options->useUuid) {
                                     $request["data"]["id"] = getId($this->db, $processor->uuid, $request["data"]["uuid"]);
                                 }
                             } elseif ($this->options->keepDestId && isset($request["data"]["uuid"]) && $this->options->useUuid) {
                                 $request["data"]["id"] = getId($this->db, $processor->uuid, $request["data"]["uuid"]);
                             }
                         }
                         $createUuid = true;
                         if (is_array($request["data"])) {
                             if (isset($request["data"]["uuid"])) {
                                 if ((string) $request["data"]["uuid"] !== "") {
                                     $overrideID = true;
                                     $createUuid = false;
                                 }
                             }
                         }
                         //end if
                         if (!isset($processor->fields["uuid"])) {
                             $createUuid = false;
                         }
                         $newid = $processor->insertRecord($request["data"], NULL, $overrideID, true, $createUuid);
                         if ($newid) {
                             if ($createUuid) {
                                 $this->_addToResponse("added", "record added to tabledef " . $tabledefid, $newid["uuid"]);
                             } elseif (isset($processor->fields["uuid"])) {
                                 $this->_addToResponse("added", "record added to tabledef " . $tabledefid, $request["data"]["uuid"]);
                             } else {
                                 $this->_addToResponse("added", "record added to tabledef " . $tabledefid, $newid);
                             }
                             //end if
                         } else {
                             $this->sendError("Insert failed from request number " . $i);
                         }
                     }
                     //endif
                     break;
                 case "update":
                     //======================================================
                     include_once "include/tables.php";
                     if ($hasTableClassOveride) {
                         @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
                         if (class_exists($maintable)) {
                             $processor = new $maintable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         } else {
                             $processor = new phpbmsTable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         }
                         //end if
                     } else {
                         $processor = new phpbmsTable($this->db, $tabledefid);
                         $processor->dateFormat = $this->options->dateFormat;
                         $processor->timeFormat = $this->options->timeFormat;
                     }
                     //end if
                     $errorArray = $processor->verifyVariables($request["data"]);
                     if ($this->options->useUuid) {
                         if (!isset($request["data"]["uuid"])) {
                             $errorArray[] = "The `uuid` field must be set.";
                         }
                     } else {
                         if (!isset($request["data"]["id"])) {
                             $errorArray[] = "The `id` field must be set.";
                         }
                     }
                     //end if
                     if (count($errorArray)) {
                         $this->sendError("Update failed from request number " . $i, $errorArray);
                     } else {
                         $processor->updateRecord($request["data"], NULL, (bool) $this->options->useUuid);
                         $this->_addToResponse("updated", "record updated in tabledef " . $tabledefid);
                     }
                     //endif
                     break;
                 case "get":
                     //======================================================
                     include_once "include/tables.php";
                     if ($hasTableClassOveride) {
                         @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
                         if (class_exists($maintable)) {
                             $processor = new $maintable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         } else {
                             $processor = new phpbmsTable($this->db, $tabledefid);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                         }
                         //end if
                     } else {
                         $processor = new phpbmsTable($this->db, $tabledefid);
                         $processor->dateFormat = $this->options->dateFormat;
                         $processor->timeFormat = $this->options->timeFormat;
                     }
                     //end if
                     $errorMessage = "";
                     if ($this->options->useUuid) {
                         if (!isset($request["data"]["uuid"])) {
                             $errorMessage = "The `uuid` field must be set.";
                         }
                     } else {
                         if (!isset($request["data"]["id"])) {
                             $errorMessage = "The `id` field must be set.";
                         }
                     }
                     //end if
                     if ($errorMessage) {
                         $this->sendError("Get failed from request number " . $i, $errorMessage);
                     } elseif (!$this->options->useUuid) {
                         $therecord = $processor->getRecord((int) $request["data"]["id"], $this->options->useUuid);
                         $thereturn = $therecord["id"];
                         $thevalue = (int) $request["data"]["id"];
                     } else {
                         $therecord = $processor->getRecord(mysql_real_escape_string($request["data"]["uuid"]), $this->options->useUuid);
                         $thereturn = $therecord["uuid"];
                         $thevalue = $request["data"]["uuid"];
                     }
                     if ($thereturn == $thevalue) {
                         $this->_addToResponse("retrieved", "record (" . htmlQuotes($thevalue) . ") retrieved in tabledef " . $tabledefid, $therecord);
                     } else {
                         $this->_addToResponse("retrieved", "no record found (" . htmlQuotes($thevalue) . ") in tabledef " . $tabledefid);
                     }
                     break;
                 case "delete":
                 case $deletebutton:
                     //======================================================
                     if (!is_array($request["data"])) {
                         $this->sendError("Passed data is not array in request number " . $i, $request["data"]);
                     } else {
                         include_once "include/search_class.php";
                         if ($hasTableClassOveride) {
                             @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
                             $className = $maintable . "SearchFunctions";
                             if (class_exists($className)) {
                                 $processor = new $className($this->db, $tabledefid, $request["data"]);
                             } else {
                                 $processor = new searchFunctions($this->db, $tabledefid, $request["data"]);
                             }
                         } else {
                             $processor = new searchFunctions($this->db, $tabledefid, $request["data"]);
                         }
                         $result = $processor->delete_record($this->options->useUuid);
                         $this->_addToResponse($request["command"], $result);
                     }
                     //endif
                     break;
                 case "procedure":
                     //======================================================
                     if (!is_array($request["data"])) {
                         $this->sendError("Wrong passed procedure format, expected object in request number " . $i, $request["data"]);
                     } else {
                         if (!isset($request["data"]["name"])) {
                             $this->sendError("Wrong passed procedure format, name missing in request number " . $i, $request["data"]);
                         } else {
                             //check to see if stored procedure exists
                             $querystatement = "\n                                    SHOW PROCEDURE STATUS LIKE '" . mysql_real_escape_string($request["data"]["name"]) . "'\n                                ";
                             $queryresult = $this->db->query($querystatement);
                             if ($this->db->numRows($queryresult) === 0) {
                                 $this->sendError("Procedure '" . $request["data"]["name"] . "' does not exist in request number " . $i, $request["data"]);
                             } else {
                                 $parameterList = "";
                                 if (isset($request["data"]["parameters"])) {
                                     foreach ($request["data"]["parameters"] as $parameter) {
                                         $parameterList .= ", '" . mysql_real_escape_string($parameter) . "'";
                                     }
                                 }
                                 if ($parameterList) {
                                     $parameterList = substr(1, $parameterList);
                                 }
                                 $procedurestatement = "\n                                        CALL " . $request["data"]["name"] . "(" . $parameterList . ")";
                                 $queryresult = $this->db->query($procedurestatement);
                                 $result = array();
                                 while ($therecord = $this->db->fetchArray($queryresult)) {
                                     $result[] = $therecord;
                                 }
                                 $this->_addToResponse("result", "Procedure '" . $request["data"]["name"] . "' returned (" . $this->db->numRows($queryresult) . ") in request number " . $i, $result);
                             }
                             //endif
                         }
                         //endif
                     }
                     //endif
                     break;
                 case "getsetting":
                     //======================================================
                     if (!is_array($request["data"])) {
                         $this->sendError("Wrong passed data format, expected array in request number " . $i, $request["data"]);
                     } else {
                         $whereclause = "";
                         foreach ($request["data"] as $settingName) {
                             $whereclause = "OR `name` = '" . mysql_real_escape_string($settingName) . "' ";
                         }
                         if ($whereclause) {
                             $whereclause = "WHERE " . substr($whereclause, 2);
                         }
                         $querystatement = "\n                                SELECT\n                                    `name`,\n                                    `value`\n                                FROM\n                                    `settings`\n                                " . $whereclause;
                         $queryresult = $this->db->query($querystatement);
                         $settings = array();
                         while ($therecord = $this->db->fetchArray($queryresult)) {
                             $settings[$therecord["name"]] = $therecord["value"];
                         }
                         $this->_addToResponse("result", "GetSettings returned (" . count($settings) . ") in request number " . $i, $settings);
                     }
                     //endif
                     break;
                 default:
                     //======================================================
                     // a catch all for other requests.  This should correspond
                     // to an ovrriden search class function only. Calling
                     // some commands can cause response errors so be careful
                     if (!is_array($request["data"]) && !$hasTableClassOveride) {
                         $this->sendError("Passaed data is not array or function (" . $request["command"] . ") does not exist in request number " . $i, $request["data"]);
                     } else {
                         @(include_once "modules/" . $modulename . "/include/" . $maintable . ".php");
                         $className = $maintable . "SearchFunctions";
                         if (!class_exists($className)) {
                             $this->sendError("Function (" . $request["command"] . ") does not exist in request number " . $i, $request["data"]);
                         } else {
                             $processor = new $className($this->db, $tabledefid, $request["data"]);
                             $processor->dateFormat = $this->options->dateFormat;
                             $processor->timeFormat = $this->options->timeFormat;
                             $methodName = $request["command"];
                             if (!method_exists($processor, $methodName)) {
                                 $this->sendError("Function (" . $request["command"] . ") does not exist in request number " . $i, $request["data"]);
                             } else {
                                 $result = $processor->{$methodName}();
                                 $this->_addToResponse($request["command"], $result);
                             }
                             //endif method_exists
                         }
                         //endif $className
                     }
                     //endif
                     break;
             }
             //endswitch $request["command"]
         }
         //endif $modulename
         $i++;
     }
     //endforeach
     $this->displayResult();
 }
示例#9
0
 /**
  *  function create_credit_memo
  *
  *
  *  @param bool $useUuid Whether the ids in $this->idsArray are
  *  uuids or ids.
  */
 function create_credit_memo($useUuid = false)
 {
     if (!$useUuid) {
         $whereclause = $this->buildWhereClause();
     } else {
         $whereclause = $this->buildWhereClause($this->maintable . ".uuid");
     }
     if (isset($_SESSION["userinfo"]["id"])) {
         $createdby = $_SESSION["userinfo"]["id"];
     } else {
         $error = new appError(-841, "Session Timed Out.", "Creating New Record");
     }
     $invoicestatusQuery = "\n\t\t\t\tSELECT\n\t\t\t\t\t`uuid`\n\t\t\t\tFROM\n\t\t\t\t\t`invoicestatuses`\n\t\t\t\tWHERE\n\t\t\t\t\t`invoicedefault` != '0'\n\t\t\t";
     $queryresult = $this->db->query($invoicestatusQuery);
     $statusRecord = $this->db->fetchArray($queryresult);
     if (!class_exists("phpbmsTable")) {
         include_once "include/tables.php";
     }
     $invoices = new phpbmsTable($this->db, "tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883");
     $count = 0;
     if (count($this->idsArray)) {
         foreach ($this->idsArray as $id) {
             $invoiceRecord = $invoices->getRecord($id, $useUuid);
             if ($invoiceRecord["type"] == "Invoice" && !$invoiceRecord["iscreditmemo"]) {
                 $count++;
                 $fieldsList = "";
                 $insertValues = "";
                 foreach ($invoiceRecord as $name => $value) {
                     switch ($name) {
                         case "id":
                         case "ccexpiration":
                         case "bankname":
                         case "checkno":
                         case "routingnumber":
                         case "accountnumber":
                         case "transactionid":
                         case "postingsessionid":
                         case "readytopost":
                         case "assignedtoid":
                         case "invoicedate":
                         case "requireddate":
                         case "amountpaid":
                         case "cmuuid":
                             break;
                         case "type":
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",'Order'";
                             break;
                         case "iscreditmemo":
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",'1'";
                             break;
                         case "createdby":
                         case "modifiedby":
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",'" . (int) $createdby . "'";
                             break;
                         case "uuid":
                             $fieldsList .= ",`cmuuid`";
                             $insertValues .= ",'" . $value . "'";
                             $fieldsList .= ",`uuid`";
                             $newUuid = uuid($invoices->prefix . ":");
                             $insertValues .= ",'" . $newUuid . "'";
                             break;
                         case "creationdate":
                         case "modifieddate":
                         case "statusdate":
                         case "orderdate":
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",NOW()";
                             break;
                         case "statusid":
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",'" . $statusRecord["uuid"] . "'";
                             break;
                         case "discountamount":
                         case "totaltni":
                         case "totaltaxable":
                         case "tax":
                         case "shipping":
                         case "totalcost":
                         case "totalti":
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",'" . -(double) $value . "'";
                             break;
                         default:
                             $fieldsList .= ",`" . $name . "`";
                             $insertValues .= ",'" . $value . "'";
                             break;
                     }
                     //end switch
                 }
                 //end foreach
                 $fieldsList = substr($fieldsList, 1);
                 $insertValues = substr($insertValues, 1);
                 $insertstatement = "\n\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t`invoices`\n\t\t\t\t\t\t\t(" . $fieldsList . ")\n\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t(" . $insertValues . ")\n\t\t\t\t\t\t";
                 $queryresult = $this->db->query($insertstatement);
                 $newid = $this->db->insertId();
                 //invoice status history
                 $statushistoryquery = "\n\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t`invoicestatushistory`\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\tinvoiceid,\n\t\t\t\t\t\t\t\t\tinvoicestatusid,\n\t\t\t\t\t\t\t\t\tstatusdate,\n\t\t\t\t\t\t\t\t\tassignedtoid\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t'" . mysql_real_escape_string($newUuid) . "',\n\t\t\t\t\t\t\t\t\t'" . $statusRecord["uuid"] . "',\n\t\t\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t";
                 $this->db->query($statushistoryquery);
                 // Line items
                 $lineitemstatement = "\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tlineitems.productid,\n\t\t\t\t\t\t\t\tlineitems.taxable,\n\t\t\t\t\t\t\t\t-(`lineitems`.`quantity`) AS `quantity`,\n\t\t\t\t\t\t\t\tlineitems.unitprice,\n\t\t\t\t\t\t\t\tlineitems.unitcost,\n\t\t\t\t\t\t\t\tlineitems.unitweight,\n\t\t\t\t\t\t\t\tlineitems.memo,\n\t\t\t\t\t\t\t\tlineitems.displayorder,\n\t\t\t\t\t\t\t\tlineitems.custom1,\n\t\t\t\t\t\t\t\tlineitems.custom2,\n\t\t\t\t\t\t\t\tlineitems.custom3,\n\t\t\t\t\t\t\t\tlineitems.custom4,\n\t\t\t\t\t\t\t\tlineitems.custom5,\n\t\t\t\t\t\t\t\tlineitems.custom6,\n\t\t\t\t\t\t\t\tlineitems.custom7,\n\t\t\t\t\t\t\t\tlineitems.custom8,\n\t\t\t\t\t\t\t\tlineitems.createdby,\n\t\t\t\t\t\t\t\tlineitems.modifiedby,\n\t\t\t\t\t\t\t\tlineitems.creationdate,\n\t\t\t\t\t\t\t\tlineitems.modifieddate\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tlineitems\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tinvoiceid = '" . $id . "'";
                 $lineitemresult = $this->db->query($lineitemstatement);
                 while ($lineitemrecord = $this->db->fetchArray($lineitemresult)) {
                     $fieldsList = "";
                     $insertValues = "";
                     $fieldsList .= "`invoiceid`";
                     $insertValues .= "'" . $newid . "'";
                     foreach ($lineitemrecord as $name => $value) {
                         switch ($name) {
                             case "createdby":
                             case "modifiedby":
                                 $fieldsList .= ",`" . $name . "`";
                                 $insertValues .= ",'" . (int) $createdby . "'";
                                 break;
                             case "creationdate":
                             case "modifieddate":
                                 $fieldsList .= ",`" . $name . "`";
                                 $insertValues .= ",NOW()";
                                 break;
                             default:
                                 $fieldsList .= ",`" . $name . "`";
                                 $insertValues .= ",'" . $value . "'";
                                 break;
                         }
                         //end switch
                     }
                     //end foreach
                     $lineinsertstatement = "\n\t\t\t\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t\t\t\t`lineitems`\n\t\t\t\t\t\t\t\t(" . $fieldsList . ")\n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t(" . $insertValues . ")\n\t\t\t\t\t\t\t";
                     $this->db->query($lineinsertstatement);
                 }
                 //end while
             }
             //end if
         }
     }
     //end foreach
     if ($count == count($this->idsArray)) {
         $message = $count . " related credit memo(s) have been created.";
     } else {
         $message = $count . " related credit memo(s) (of " . count($this->idsArray) . " selected) have been created.";
     }
     return $message;
 }