Fix for show/hide menu link formatting issues in IE, Chrome, Safari.
[openemr.git] / library / classes / Controller.class.php
blob7e3f2f4fb259b56da744ccc1303feff9468066d0
1 <?php
3 require_once(dirname(__FILE__) . "/../Smarty.class.php");
4 require_once(dirname(__FILE__) . "/../formdata.inc.php");
5 define("SMARTY_DIR", dirname(__FILE__) . "/../");
7 class Controller extends Smarty {
9 var $_current_action;
10 var $_state;
11 var $_args = array();
13 function Controller() {
14 parent::Smarty();
15 $this->template_mod = "general";
16 $this->_current_action = "";
17 $this->_state = true;
18 $this->compile_dir = $GLOBALS['fileroot'] . "/interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
19 $this->compile_check = true;
20 $this->assign("PROCESS", "true");
21 $this->assign("HEADER", "<html><head>
22 <?php html_header_show();?></head><body>");
23 $this->assign("FOOTER", "</body></html>");
24 $this->assign("CONTROLLER", "controller.php?");
25 $this->assign("CONTROLLER_THIS", "controller.php?" . $_SERVER['QUERY_STRING']);
26 $this->assign("WEBROOT", $GLOBALS['webroot']);
29 function set_current_action($action) {
30 $this->_current_action = $action;
33 function default_action() {
34 echo "<html><body></body></html>";
37 function process_action() {
38 $this->default_action();
41 function populate_object(&$obj) {
42 if(!is_object($obj)) {
43 $this->function_argument_error();
46 foreach($_POST as $varname => $var) {
47 $varname = preg_replace("/[^A-Za-z0-9_]/","",$varname);
48 $func = "set_" . $varname;
49 if ( (!(strpos("_",$varname) === 0)) && is_callable(array($obj,$func)) ) {
50 //echo "c: $func on w: " . $var . "<br />";
52 //modified 01-2010 by BGM to centralize to formdata.inc.php
53 // have place several debug statements to allow standardized testing over next several months
54 if (!is_array($var)) {
55 //DEBUG LINE - error_log("Controller populate before strip: ".$var, 0);
56 $var = strip_escape_custom($var);
57 //DEBUG LINE - error_log("Controller populate after strip: ".$var, 0);
60 call_user_func_array(array(&$obj,$func),array($var, $_POST));
64 return true;
67 function function_argument_error() {
68 $this->display($GLOBALS['template_dir'] . "error/" . $this->template_mod . "_function_argument.html");
69 exit;
72 function i_once($file) {
73 return include_once($file);
76 function act($qarray) {
78 if (isset($_GET['process'])){
79 unset($_GET['process']);
80 unset($qarray['process']);
81 $_POST['process'] = "true";
83 $args = array_reverse(array_keys($qarray));
84 $c_name = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
85 $parts = split("_",$c_name);
86 $name = "";
88 foreach($parts as $p) {
89 $name .= ucfirst($p);
92 $c_name = $name;
93 $c_action = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
94 $args = array_reverse($args);
96 if(!@call_user_func(array(Controller,"i_once"),$GLOBALS['fileroot'] ."/controllers/C_" . $c_name . ".class.php")) {
97 echo "Unable to load controller $name\n, please check the first argument supplied in the URL and try again";
98 exit;
101 $obj_name = "C_" . $c_name;
102 $c_obj = new $obj_name();
104 if (empty ($c_action)) {
105 $c_action = "default";
108 $c_obj->_current_action = $c_action;
109 $args_array = array();
111 foreach ($args as $arg) {
112 $arg = preg_replace("/[^A-Za-z0-9_]/","",$arg);
113 //this is a workaround because call user func does funny things with passing args if they have no assigned value
114 if (empty($qarray[$arg])) {
115 //if argument is empty pass null as value and arg as assoc array key
116 $args_array[$arg] = null;
118 else {
119 $args_array[$arg] = $qarray[$arg];
123 $output = "";
124 //print_r($args_array);
125 if ($_POST['process'] == "true") {
127 if (is_callable(array(&$c_obj,$c_action . "_action_process"))) {
128 //echo "ca: " . $c_action . "_action_process";
129 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action_process"),$args_array);
130 if ($c_obj->_state == false) {
131 return $output;
134 //echo "ca: " . $c_action . "_action";
135 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
138 else {
139 if (is_callable(array(&$c_obj,$c_action . "_action"))) {
140 //echo "ca: " . $c_action . "_action";
141 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
143 else {
144 echo "The action trying to be performed: " . $c_action ." does not exist controller: ". $name;
149 return $output;
152 function _link($action = "default",$inlining = false) {
153 $url_parts = split("&",$_SERVER['REQUEST_URI']);
154 $link = array_shift($url_parts);
155 //print_r($url_parts);
157 if (strpos($url_parts[0],"=") === false) {
158 $inline_arg = $url_parts[0];
159 $url_parts[0] = $action;
161 else {
162 array_unshift($url_parts,$action);
164 if ($inlining) {
165 $link .= "&" . $inline_arg;
166 $link .= "&action=" . $url_parts[0];
168 else {
169 $link .= "&" . $url_parts[0];
172 foreach ($this->_args as $arg_name => $arg) {
173 $link .= "&" . $arg_name . "=" . $arg;
175 $link .= "&";
176 return $link;