function getRecord($id, $useUuid = false) { if ($useUuid) { $id = mysql_real_escape_string($id); $whereField = "uuid"; } else { $id = (int) $id; $whereField = "id"; } //endif $querystatement = "\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\taddresstorecord\n\t\t\t\tWHERE\n\t\t\t\t\t`" . $whereField . "` = " . $id; $queryresult = $this->db->query($querystatement); if ($this->db->numRows($queryresult)) { $therecord = $this->db->fetchArray($queryresult); $querystatement = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`id` AS `addressid`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`addresses`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`uuid`='" . mysql_real_escape_string($therecord["addressid"]) . "'\n\t\t\t\t"; $queryresult = $this->db->query($querystatement); if ($this->db->numRows($queryresult)) { $addressID = $this->db->fetchArray($queryresult); $therecord["addressuuid"] = $therecord["addressid"]; //artificial uuid field... maybe bad $therecord["addressid"] = $addressID["addressid"]; $addressrecord = parent::getRecord($therecord["addressid"]); unset($therecord["id"], $addressrecord["createdby"], $addressrecord["creationdate"], $addressrecord["modifiedby"], $addressrecord["modifieddate"]); $therecord = array_merge($addressrecord, $therecord); } else { $therecord = $this->getDefaults(); } } else { $therecord = $this->getDefaults(); } return $therecord; }
function addressUpdate($variables, $invoiceid, $modifiedby, $method) { // Updates/Inserts address records (billing or shipping )for the sales order's corresponding client switch ($method) { case "shipping": $varprefix = "shipto"; $idprefix = "shipto"; break; case "billing": $varprefix = ""; $idprefix = "billing"; break; } //endswitch switch ($variables[$idprefix . "saveoptions"]) { case "updateAddress": if ($variables[$idprefix . "addressid"]) { $address = new addresses($this->db, "tbld:27b99bda-7bec-b152-8397-a3b09c74cb23"); $querystatment = "\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t`id`\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t`addresses`\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t`uuid` = '" . mysql_real_escape_string($variables[$idprefix . "addressid"]) . "'\n\t\t\t\t\t\t"; $queryresult = $this->db->query($querystatment); $arecord = $this->db->fetchArray($queryresult); $addressRecord = $address->getRecord($arecord["id"]); if ($varprefix == "shipto") { $addressRecord["shiptoname"] = $variables["shiptoname"]; } $addressRecord["address1"] = $variables[$varprefix . "address1"]; $addressRecord["address2"] = $variables[$varprefix . "address2"]; $addressRecord["city"] = $variables[$varprefix . "city"]; $addressRecord["state"] = $variables[$varprefix . "state"]; $addressRecord["postalcode"] = $variables[$varprefix . "postalcode"]; $addressRecord["country"] = $variables[$varprefix . "country"]; $address->updateRecord($addressRecord, $modifiedby); } //endif break; case "createAddress": $addresstorecord = new addresstorecord($this->db, "tbld:27b99bda-7bec-b152-8397-a3b09c74cb23"); if ($varprefix == "shipto") { $addressRecord["shiptoname"] = $variables["shiptoname"]; } $atrRecord["uuid"] = uuid($addresstorecord->prefix . ":"); $atrRecord["address1"] = $variables[$varprefix . "address1"]; $atrRecord["address2"] = $variables[$varprefix . "address2"]; $atrRecord["city"] = $variables[$varprefix . "city"]; $atrRecord["state"] = $variables[$varprefix . "state"]; $atrRecord["postalcode"] = $variables[$varprefix . "postalcode"]; $atrRecord["country"] = $variables[$varprefix . "country"]; $atrRecord["recordid"] = $variables["clientid"]; $atrRecord["tabledefid"] = "tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083"; $atrRecord["primary"] = 0; $atrRecord["defaultshipto"] = 0; $atrRecord["existingaddressid"] = 0; $atrRecord["notes"] = "Created from sales order #" . $invoiceid; $newAtrID = $addresstorecord->insertRecord($atrRecord, $modifiedby); $atrRecord = $addresstorecord->getRecord($newAtrID); //Need to connect the sales order to the new address record $updatestatement = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tinvoices\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t" . $idprefix . "addressid = '" . $atrRecord["uuid"] . "'\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tuuid = '" . $invoiceid . "'\n\t\t\t\t\t"; $this->db->query($updatestatement); break; } //endswitch - saveoptions }