1 <?php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 19 20 21 22 23
24 function loadMagratheaEnv($env = null){
25 global $magdb;
26 if( empty($env) ){
27 $env = MagratheaConfig::Instance()->GetEnvironment();
28 }
29 $configSection = MagratheaConfig::Instance()->GetConfigSection($env);
30 $magdb = MagratheaDatabase::Instance();
31 return $magdb->SetConnection($configSection["db_host"], $configSection["db_name"], $configSection["db_user"], $configSection["db_pass"]);
32 }
33
34
35 36 37 38 39
40 function p_r($debugme, $beautyme=false){
41
42 if( $beautyme ){
43 echo nice_p_r($debugme);
44 } else {
45 echo "<pre>"; print_r($debugme); echo "</pre>";
46 }
47 }
48
49 50 51 52 53
54 function nice_p_r($debugme, $prev_char = ""){
55 $html = "";
56 $html .= (empty($prev_char) ? "<div>" : "");
57 if( is_array( $debugme ) ){
58 $html .= $prev_char."<span class='p_r_title'> Array: [</span><br/><div style='margin-right: 20px;'>";
59 foreach( $debugme as $key => $item ){
60 $html .= "<div style='padding-right: 20px;'><span class='p_r_title'>[".$key."] =></span><br/>";
61 $html .= nice_p_r($item, $prev_char." ");
62 $html .= "</div>";
63 }
64 $html .= $prev_char."</div><hr/>";
65 } else {
66 $html .= $prev_char.$debugme;
67 }
68 $html .= (empty($prev_char) ? "</div>" : "");
69 return $html;
70 }
71
72 73 74 75
76 function now(){
77 return date("Y-m-d H:i:s");
78 }
79
80 81 82 83 84 85
86 function magrathea_printFields($fields_arr, $selected = null){
87 $options = "";
88 $selected = false;
89 foreach($fields_arr as $field){
90 if( $field == $selected ){
91 $selected = true;
92 $options .= "<option value='".$field."' selected>".$field."</option>";
93 } else {
94 $options .= "<option value='".$field."'>".$field."</option>";
95 }
96 }
97 echo $options;
98 return $selected;
99 }
100
101 102 103 104
105 function magrathea_getTypesArr(){
106 $types = array("int", "boolean", "string", "text", "float", "datetime");
107 return $types;
108 }
109
110 111 112 113 114
115 function shutdown(){
116 if(MagratheaDebugger::Instance()->GetType() == MagratheaDebugger::DEBUG){
117 MagratheaDebugger::Instance()->Show();
118 }
119 }
120 register_shutdown_function('shutdown');
121
122
123
124