Esempio n. 1
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["type"] = "prospect";
     $therecord["webaddress"] = "http://";
     return $therecord;
 }
Esempio n. 2
0
 /**
  * Overriden phpbmstable function
  */
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["type"] = "Inventory";
     $therecord["status"] = "In Stock";
     $therecord["taxable"] = 1;
     $therecord["categoryid"] = "";
     $therecord["addcats"] = array();
     return $therecord;
 }
Esempio n. 3
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["moduleid"] = "mod:29873ee8-c12a-e3f6-9010-4cd24174ffd7";
     $therecord["deletebutton"] = "delete";
     $therecord["type"] = "table";
     $therecord["searchroleid"] = "";
     $therecord["importroleid"] = "Admin";
     $therecord["advsearchroleid"] = "Admin";
     $therecord["viewsqlroleid"] = "Admin";
     return $therecord;
 }
Esempio n. 4
0
 /**
  *  function getDefaults
  */
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["apicommand"] = "insert";
     $therecord["whereselection"] = "all";
     $therecord["customwhere"] = "";
     $therecord["usecustomdestuuid"] = 0;
     $therecord["customdestuuid"] = "";
     $therecord["customcommand"] = "";
     $therecord["keepdestid"] = 1;
     $therecord["useuuid"] = 1;
     return $therecord;
 }
Esempio n. 5
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["crontab"] = "*::*::*::*::*";
     $therecord["min"] = "*";
     $therecord["hrs"] = "*";
     $therecord["date"] = "*";
     $therecord["mo"] = "*";
     $therecord["day"] = "*";
     $therecord["startdate"] = dateToString(mktime(), "SQL");
     $therecord["starttime"] = sqlTimeFromString(timeToString(time()));
     $therecord["enddate"] = "";
     $therecord["endtime"] = "";
     $therecord["scripttype"] = "job";
     return $therecord;
 }
Esempio n. 6
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["type"] = DEFAULT_CLIENTTYPE;
     if ($therecord["type"] == "client") {
         $therecord["becameclient"] = dateToString(mktime(), "SQL");
         $therecord["hascredit"] = DEFAULT_HASCREDIT;
         $therecord["creditlimit"] = DEFAULT_CREDITLIMIT;
     }
     //end if
     //set the order defaults
     $therecord["discountid"] = DEFAULT_DISCOUNT;
     $therecord["taxareaid"] = DEFAULT_TAXAREA;
     $therecord["shippingmethodid"] = DEFAULT_SHIPPING;
     $therecord["paymentmethodid"] = DEFAULT_PAYMENT;
     $therecord["webaddress"] = "http://";
     //now for the address information.
     $addressinfo = $this->address->getDefaults();
     unset($addressinfo["id"], $addressinfo["uuid"], $addressinfo["createdby"], $addressinfo["creationdate"], $addressinfo["modifiedby"], $addressinfo["modifieddate"]);
     $addressinfo["addressid"] = NULL;
     return array_merge($therecord, $addressinfo);
 }
Esempio n. 7
0
 /**
  * function getDefaults
  *
  * Retrieves default values for a single record
  *
  * Uses the field names to guess a default value.  If it cannot find
  * one of the standard names it sets the default value based on the type
  *
  * @retrun array associative array with record defaults
  */
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["apifileurl"] = "";
     return $therecord;
 }
Esempio n. 8
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     if (isset($_GET["ty"])) {
         $therecord["type"] = $_GET["ty"];
     } else {
         $therecord["type"] = "NT";
     }
     $therecord["typeCheck"] = $therecord["type"];
     $therecord["private"] = true;
     $therecord["attachedtabledefid"] = isset($_GET["tabledefid"]) ? $_GET["tabledefid"] : NULL;
     $therecord["attachedid"] = isset($_GET["refid"]) ? $_GET["refid"] : NULL;
     //from quickview
     if (isset($_GET["cid"])) {
         $therecord["attachedtabledefid"] = "tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083";
         $therecord["attachedid"] = $_GET["cid"];
     }
     $therecord["repeatevery"] = 1;
     $therecord["repeattype"] = "Daily";
     return $therecord;
 }
Esempio n. 9
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["clientid"] = "";
     $therecord["status"] = "open";
     $therecord["receiptdate"] = dateToString(mktime(), "SQL");
     $therecord["itemslist"] = array();
     return $therecord;
 }
Esempio n. 10
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     $therecord["type"] = "report";
     return $therecord;
 }
Esempio n. 11
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();
 }
Esempio n. 12
0
 function getDefaults()
 {
     $therecord = parent::getDefaults();
     if (isset($_GET["cid"])) {
         $therecord["clientid"] = $_GET["cid"];
     } else {
         $therecord["clientid"] = "";
     }
     $therecord["clientrealid"] = 0;
     $therecord["type"] = "Order";
     $therecord["statusid"] = $this->getDefaultStatus();
     $therecord["orderdate"] = dateToString(mktime(), "SQL");
     $therecord["statusdate"] = dateToString(mktime(), "SQL");
     $therecord["printedinstructions"] = INVOICE_DEFAULT_PRINTINSTRUC;
     $therecord["discountid"] = DEFAULT_DISCOUNT;
     $therecord["taxareaid"] = DEFAULT_TAXAREA;
     $therecord["shippingmethodid"] = DEFAULT_SHIPPING;
     $therecord["paymentmethodid"] = DEFAULT_PAYMENT;
     $discountinfo = $this->getDiscount($therecord["discountid"]);
     $therecord["discountname"] = $discountinfo["name"];
     $therecord["discount"] = $discountinfo["value"];
     $taxinfo = $this->getTax($therecord["taxareaid"]);
     $therecord["taxname"] = $taxinfo["name"];
     $therecord["taxpercentage"] = $taxinfo["percentage"];
     $therecord["amountdue"] = 0;
     $therecord["amountpaid"] = 0;
     $therecord["hascredit"] = 0;
     $therecord["creditlimit"] = 0;
     $therecord["creditleft"] = 0;
     $therecord["thelineitems"] = array();
     $therecord["cmid"] = "";
     $therecord["lineitemschanged"] = "";
     return $therecord;
 }