3 require_once(dirname(__FILE__
) . "/../Smarty.class.php");
4 define("SMARTY_DIR", dirname(__FILE__
) . "/../");
6 class Controller
extends Smarty
{
12 function Controller() {
14 $this->template_mod
= "general";
15 $this->_current_action
= "";
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>
21 <? html_header_show();?></head><body>");
22 $this->assign("FOOTER", "</body></html>");
23 $this->assign("CONTROLLER", "controller.php?");
24 $this->assign("CONTROLLER_THIS", "controller.php?" . $_SERVER['QUERY_STRING']);
25 $this->assign("WEBROOT", $GLOBALS['webroot']);
28 function set_current_action($action) {
29 $this->_current_action
= $action;
32 function default_action() {
33 echo "<html><body></body></html>";
36 function process_action() {
37 $this->default_action();
40 function populate_object(&$obj) {
41 if(!is_object($obj)) {
42 $this->function_argument_error();
45 foreach($_POST as $varname => $var) {
46 $varname = preg_replace("/[^A-Za-z0-9_]/","",$varname);
47 $func = "set_" . $varname;
48 if ( (!(strpos("_",$varname) === 0)) && is_callable(array($obj,$func)) ) {
49 //echo "c: $func on w: " . $var . "<br />";
50 if ((get_magic_quotes_gpc() ||
get_magic_quotes_runtime()) && !is_array($var) ) {
51 $var = stripslashes($var);
53 call_user_func_array(array(&$obj,$func),array($var, $_POST));
60 function function_argument_error() {
61 $this->display($GLOBALS['template_dir'] . "error/" . $this->template_mod
. "_function_argument.html");
65 function i_once($file) {
66 return include_once($file);
69 function act($qarray) {
71 if (isset($_GET['process'])){
72 unset($_GET['process']);
73 unset($qarray['process']);
74 $_POST['process'] = "true";
76 $args = array_reverse(array_keys($qarray));
77 $c_name = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
78 $parts = split("_",$c_name);
81 foreach($parts as $p) {
86 $c_action = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
87 $args = array_reverse($args);
89 // load dutch version for C_Prescription.class
90 if ( (LANGUAGE
== '5') && ($c_name == "Prescription") ) $c_name .= 'dutch';
92 if(!@call_user_func
(array(Controller
,"i_once"),$GLOBALS['fileroot'] ."/controllers/C_" . $c_name . ".class.php")) {
93 echo "Unable to load controller $name\n, please check the first argument supplied in the URL and try again";
97 $obj_name = "C_" . $c_name;
98 $c_obj = new $obj_name();
100 if (empty ($c_action)) {
101 $c_action = "default";
104 $c_obj->_current_action
= $c_action;
105 $args_array = array();
107 foreach ($args as $arg) {
108 $arg = preg_replace("/[^A-Za-z0-9_]/","",$arg);
109 //this is a workaround because call user func does funny things with passing args if they have no assigned value
110 if (empty($qarray[$arg])) {
111 //if argument is empty pass null as value and arg as assoc array key
112 $args_array[$arg] = null;
115 $args_array[$arg] = $qarray[$arg];
120 //print_r($args_array);
121 if ($_POST['process'] == "true") {
123 if (is_callable(array(&$c_obj,$c_action . "_action_process"))) {
124 //echo "ca: " . $c_action . "_action_process";
125 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action_process"),$args_array);
126 if ($c_obj->_state
== false) {
130 //echo "ca: " . $c_action . "_action";
131 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
135 if (is_callable(array(&$c_obj,$c_action . "_action"))) {
136 //echo "ca: " . $c_action . "_action";
137 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
140 echo "The action trying to be performed: " . $c_action ." does not exist controller: ". $name;
148 function _link($action = "default",$inlining = false) {
149 $url_parts = split("&",$_SERVER['REQUEST_URI']);
150 $link = array_shift($url_parts);
151 //print_r($url_parts);
153 if (strpos($url_parts[0],"=") === false) {
154 $inline_arg = $url_parts[0];
155 $url_parts[0] = $action;
158 array_unshift($url_parts,$action);
161 $link .= "&" . $inline_arg;
162 $link .= "&action=" . $url_parts[0];
165 $link .= "&" . $url_parts[0];
168 foreach ($this->_args
as $arg_name => $arg) {
169 $link .= "&" . $arg_name . "=" . $arg;