2 require_once (dirname(__FILE__
) ."/../sql.inc");
3 require_once (dirname(__FILE__
) ."/../formdata.inc.php");
4 require_once("Patient.class.php");
5 require_once("Person.class.php");
6 require_once("Provider.class.php");
7 require_once("Pharmacy.class.php");
19 function ORDataObject() {
20 $this->_db
= $GLOBALS['adodb']['db'];
24 $sql = "REPLACE INTO " . $_prefix . $this->_table
. " SET ";
26 $fields = sqlListFields($this->_table
);
28 $pkeys = $db->MetaPrimaryKeys($this->_table
);
30 foreach ($fields as $field) {
31 $func = "get_" . $field;
32 //echo "f: $field m: $func status: " . (is_callable(array($this,$func))? "yes" : "no") . "<br>";
33 if (is_callable(array($this,$func))) {
34 $val = call_user_func(array($this,$func));
36 //modified 01-2010 by BGM to centralize to formdata.inc.php
37 // have place several debug statements to allow standardized testing over next several months
38 if (!is_array($val)) {
39 //DEBUG LINE - error_log("ORDataObject persist before strip: ".$val, 0);
40 $val = strip_escape_custom($val);
41 //DEBUG LINE - error_log("ORDataObject persist after strip: ".$val, 0);
44 if (in_array($field,$pkeys) && empty($val)) {
45 $last_id = generate_id();
46 call_user_func(array(&$this,"set_".$field),$last_id);
51 //echo "s: $field to: $val <br>";
53 //modified 01-2010 by BGM to centralize to formdata.inc.php
54 // have place several debug statements to allow standardized testing over next several months
55 $sql .= " `" . $field . "` = '" . add_escape_custom(strval($val)) ."',";
56 //DEBUG LINE - error_log("ORDataObject persist after escape: ".add_escape_custom(strval($val)), 0);
57 //DEBUG LINE - error_log("ORDataObject persist after escape and then stripslashes test: ".stripslashes(add_escape_custom(strval($val))), 0);
58 //DEBUG LINE - error_log("ORDataObject original before the escape and then stripslashes test: ".strval($val), 0);
63 if (strrpos($sql,",") == (strlen($sql) -1)) {
64 $sql = substr($sql,0,(strlen($sql) -1));
67 //echo "<br>sql is: " . $sql . "<br /><br>";
73 $sql = "SELECT * from " . $this->_prefix
. $this->_table
. " WHERE id = '" . add_escape_custom(strval($this->id
)) . "'";
74 $results = sqlQuery($sql);
75 if (is_array($results)) {
76 foreach ($results as $field_name => $field) {
77 $func = "set_" . $field_name;
78 //echo "f: $field m: $func status: " . (is_callable(array($this,$func))? "yes" : "no") . "<br>";
79 if (is_callable(array($this,$func))) {
82 //echo "s: $field_name to: $field <br>";
83 call_user_func(array(&$this,$func),$field);
91 function populate_array($results) {
92 if (is_array($results)) {
93 foreach ($results as $field_name => $field) {
94 $func = "set_" . $field_name;
95 //echo "f: $field m: $func status: " . (is_callable(array($this,$func))? "yes" : "no") . "<br>";
96 if (is_callable(array($this,$func))) {
99 //echo "s: $field_name to: $field <br>";
100 call_user_func(array(&$this,$func),$field);
109 * Helper function that loads enumerations from the data as an array, this is also efficient
110 * because it uses psuedo-class variables so that it doesnt have to do database work for each instance
112 * @param string $field_name name of the enumeration in this objects table
113 * @param boolean $blank optional value to include a empty element at position 0, default is true
114 * @return array array of values as name to index pairs found in the db enumeration of this field
116 function _load_enum($field_name,$blank = true) {
117 if (!empty($GLOBALS['static']['enums'][$this->_table
][$field_name])
118 && is_array($GLOBALS['static']['enums'][$this->_table
][$field_name])
119 && !empty($this->_table
)) {
121 return $GLOBALS['static']['enums'][$this->_table
][$field_name];
124 $cols = $this->_db
->MetaColumns($this->_table
);
125 if ($cols && !$cols->EOF
) {
126 //why is there a foreach here? at some point later there will be a scheme to autoload all enums
127 //for an object rather than 1x1 manually as it is now
128 foreach($cols as $col) {
129 if ($col->name
== $field_name && $col->type
== "enum") {
130 for($idx=0;$idx<count($col->enums
);$idx++
)
132 $col->enums
[$idx]=str_replace("'","",$col->enums
[$idx]);
136 //$enum[$col->name] = $enum_types[1];
139 array_unshift($enum," ");
141 //keep indexing consistent whether or not a blank is present
145 $enum = array_flip($enum);
146 $GLOBALS['static']['enums'][$this->_table
][$field_name] = $enum;
152 function _utility_array($obj_ar,$reverse=false,$blank=true, $name_func="get_name", $value_func="get_id") {
157 if (!is_array($obj_ar)) return $ar;
158 foreach($obj_ar as $obj) {
159 $ar[$obj->$value_func()] = $obj->$name_func();
162 $ar = array_flip($ar);
167 } // end of ORDataObject