1 : <?php
2 :
3 :
4 :
5 :
6 :
7 :
8 :
9 :
10 :
11 : function array_union($campos, $cmp, $ws, $db) {
12 0 : $ret = array();
13 0 : if (!$ws || !count($ws) || !$db) return $ret;
14 0 : foreach ($ws as $_ws) {
15 0 : if (!isset($_ws["$cmp"])) continue;
16 0 : $_db = array_pop(array_filter($db, create_function('$c', 'return $c["'.$cmp.'"] == "'.$_ws["$cmp"].'";')));
17 0 : if ($_db) array_push($ret, array_intersect_key(array_merge($_ws, $_db), array_flip($campos)));
18 0 : }
19 0 : return $ret;
20 : }
21 :
22 :
23 :
24 :
25 : function array_inter($campos, $cmp, $ws, $db) {
26 0 : $ret = array();
27 0 : if (!$ws || !$db) return $ret;
28 0 : foreach ($ws as $_ws) {
29 0 : if (!isset($_ws["$cmp"])) continue;
30 0 : $_db = array_pop(array_filter($db, create_function('$c', 'if (isset($c["'.$cmp.'"])) return $c["'.$cmp.'"] == "'.$_ws["$cmp"].'";')));
31 0 : if (!$_db) array_push($ret, array_intersect_key($_ws, array_flip($campos)));
32 0 : }
33 0 : return $ret;
34 : }
35 :
36 :
37 :
38 :
39 :
40 : function array_filters($args, $campos, $replace = null) {
41 0 : if (is_assoc($args))
42 0 : return array_filters_assoc($args, $campos, $replace);
43 0 : elseif (is_array($args)) {
44 0 : $ret = array();
45 0 : foreach ($args as $row)
46 0 : array_push($ret, array_filters_assoc($row, $campos, $replace));
47 0 : return $ret;
48 : }
49 0 : }
50 :
51 :
52 :
53 :
54 :
55 : function array_filters_assoc($args, $campos, $replace = null) {
56 0 : if (!$replace && is_assoc($campos)) {
57 0 : foreach ($args as $key => $val) {
58 0 : if ($val && isset($campos[$key]["date_in"]) && isset($campos[$key]["date_out"]))
59 0 : $val = change_date_format($val, $campos[$key]["date_in"], $campos[$key]["date_out"]);
60 0 : if (isset($campos[$key]["name"])) $_args[$campos[$key]["name"]] = $val;
61 0 : }
62 0 : } else {
63 0 : foreach ($args as $key => $val) {
64 0 : if ($val && isset($replace[$key]["date_in"]) && isset($replace[$key]["date_out"]))
65 0 : $val = change_date_format($val, $replace[$key]["date_in"], $replace[$key]["date_out"]);
66 0 : if (in_array($key, $campos)) {
67 0 : if (isset($replace[$key]["name"]))
68 0 : $_args[$replace[$key]["name"]] = $val;
69 : else
70 0 : $_args[$key] = $val;
71 0 : }
72 0 : }
73 : }
74 0 : if (isset($_args)) return $_args;
75 0 : }
76 :
77 :
78 :
79 :
80 :
81 : function array_replace_assoc($from, $to, $array, $assoc = null) {
82 0 : if (!is_assoc($array[0])) {
83 0 : $ret = array();
84 0 : foreach ($assoc as $element) {
85 0 : if (in_array($element[$from], $array))
86 0 : array_push($ret, $element[$to]);
87 0 : }
88 0 : return $ret;
89 : } else {
90 0 : for($i=0; $i<count($array); $i++) {
91 0 : if (array_key_exists($from, $array[$i])) {
92 0 : $array[$i][$to] = $array[$i][$from];
93 0 : unset($array[$i][$from]);
94 0 : }
95 0 : }
96 0 : return $array;
97 : }
98 : }
99 :
100 :
101 :
102 :
103 :
104 : function is_assoc($array) {
105 0 : return (is_array($array) &&
106 0 : (0 !== count(array_diff_key($array, array_keys(array_keys($array)))) || count($array)==0));
107 : }
108 :
109 :
110 :
111 :
112 :
113 : function objectToArray($object) {
114 6 : if(!is_object($object) && !is_array($object))
115 6 : return $object;
116 6 : if(is_object($object))
117 6 : $object = get_object_vars( $object );
118 6 : return array_map('objectToArray', $object);
119 : }
120 :
121 :
122 :
123 :
124 : function debug($title, $content) {
125 9 : global $debug;
126 9 : if (!$debug) return;
127 1 : echo "<br><table bgcolor='#DDDDDD'><tr><td><h2>".$title."</h2>".htmlentities($content)."<br></td></tr></table>";
128 1 : }
129 :
130 :
131 :
132 :
133 : function error($msg, $e = null) {
134 0 : echo "<br><table bgcolor='#aa9999'><tr><td><h3>Error</h3>".$msg."<br>";
135 0 : if ($e) var_dump($e->getMessage());
136 0 : echo "</td></tr></table>";
137 0 : }
138 :
139 : ?>
|