Changed function SLConnect() to use $GLOBALS['oer_config']['ws_accounting']['server...
[openemr.git] / library / classes / Controller.class.php
blobcdcae41eea072713bef20385166decb8912534e3
1 <?php
3 require_once(dirname(__FILE__) . "/../Smarty.class.php");
4 define("SMARTY_DIR", dirname(__FILE__) . "/../");
6 class Controller extends Smarty {
8 var $_current_action;
9 var $_state;
10 var $_args = array();
12 function Controller() {
13 parent::Smarty();
14 $this->template_mod = "general";
15 $this->_current_action = "";
16 $this->_state = true;
17 $this->compile_dir = $GLOBALS['fileroot'] . "/interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
18 $this->compile_check = true;
19 $this->assign("PROCESS", "true");
20 $this->assign("HEADER", "<html><head></head><body>");
21 $this->assign("FOOTER", "</body></html>");
22 $this->assign("CONTROLLER", "controller.php?");
23 $this->assign("CONTROLLER_THIS", "controller.php?" . $_SERVER['QUERY_STRING']);
26 function set_current_action($action) {
27 $this->_current_action = $action;
30 function default_action() {
31 echo "<html><body></body></html>";
34 function process_action() {
35 $this->default_action();
38 function populate_object(&$obj) {
39 if(!is_object($obj)) {
40 $this->function_argument_error();
43 foreach($_POST as $varname => $var) {
44 $varname = preg_replace("/[^A-Za-z0-9_]/","",$varname);
45 $func = "set_" . $varname;
46 if ( (!(strpos("_",$varname) === 0)) && is_callable(array($obj,$func)) ) {
47 //echo "c: $func on w: " . $var . "<br />";
48 if ((get_magic_quotes_gpc() || get_magic_quotes_runtime()) && !is_array($var) ) {
49 $var = stripslashes($var);
51 call_user_func_array(array(&$obj,$func),array($var, $_POST));
55 return true;
58 function function_argument_error() {
59 $this->display($GLOBALS['template_dir'] . "error/" . $this->template_mod . "_function_argument.html");
60 exit;
63 function i_once($file) {
64 return include_once($file);
67 function act($qarray) {
69 if (isset($_GET['process'])){
70 unset($_GET['process']);
71 unset($qarray['process']);
72 $_POST['process'] = "true";
74 $args = array_reverse(array_keys($qarray));
75 $c_name = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
76 $parts = split("_",$c_name);
77 $name = "";
79 foreach($parts as $p) {
80 $name .= ucfirst($p);
83 $c_name = $name;
84 $c_action = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
85 $args = array_reverse($args);
86 if(!@call_user_func(array(Controller,"i_once"),$GLOBALS['fileroot'] ."/controllers/C_" . $c_name . ".class.php")) {
87 echo "Unable to load controller $name\n, please check the first argument supplied in the URL and try again";
88 exit;
91 $obj_name = "C_" . $c_name;
92 $c_obj = new $obj_name();
94 if (empty ($c_action)) {
95 $c_action = "default";
98 $c_obj->_current_action = $c_action;
99 $args_array = array();
101 foreach ($args as $arg) {
102 $arg = preg_replace("/[^A-Za-z0-9_]/","",$arg);
103 //this is a workaround because call user func does funny things with passing args if they have no assigned value
104 if (empty($qarray[$arg])) {
105 //if argument is empty pass null as value and arg as assoc array key
106 $args_array[$arg] = null;
108 else {
109 $args_array[$arg] = $qarray[$arg];
113 $output = "";
114 //print_r($args_array);
115 if ($_POST['process'] == "true") {
117 if (is_callable(array(&$c_obj,$c_action . "_action_process"))) {
118 //echo "ca: " . $c_action . "_action_process";
119 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action_process"),$args_array);
120 if ($c_obj->_state == false) {
121 return $output;
124 //echo "ca: " . $c_action . "_action";
125 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
128 else {
129 if (is_callable(array(&$c_obj,$c_action . "_action"))) {
130 //echo "ca: " . $c_action . "_action";
131 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
133 else {
134 echo "The action trying to be performed: " . $c_action ." does not exist controller: ". $name;
139 return $output;
142 function _link($action = "default",$inlining = false) {
143 $url_parts = split("&",$_SERVER['REQUEST_URI']);
144 $link = array_shift($url_parts);
145 //print_r($url_parts);
147 if (strpos($url_parts[0],"=") === false) {
148 $inline_arg = $url_parts[0];
149 $url_parts[0] = $action;
151 else {
152 array_unshift($url_parts,$action);
154 if ($inlining) {
155 $link .= "&" . $inline_arg;
156 $link .= "&action=" . $url_parts[0];
158 else {
159 $link .= "&" . $url_parts[0];
162 foreach ($this->_args as $arg_name => $arg) {
163 $link .= "&" . $arg_name . "=" . $arg;
165 $link .= "&";
166 return $link;