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']);
27 function set_current_action($action) {
28 $this->_current_action
= $action;
31 function default_action() {
32 echo "<html><body></body></html>";
35 function process_action() {
36 $this->default_action();
39 function populate_object(&$obj) {
40 if(!is_object($obj)) {
41 $this->function_argument_error();
44 foreach($_POST as $varname => $var) {
45 $varname = preg_replace("/[^A-Za-z0-9_]/","",$varname);
46 $func = "set_" . $varname;
47 if ( (!(strpos("_",$varname) === 0)) && is_callable(array($obj,$func)) ) {
48 //echo "c: $func on w: " . $var . "<br />";
49 if ((get_magic_quotes_gpc() ||
get_magic_quotes_runtime()) && !is_array($var) ) {
50 $var = stripslashes($var);
52 call_user_func_array(array(&$obj,$func),array($var, $_POST));
59 function function_argument_error() {
60 $this->display($GLOBALS['template_dir'] . "error/" . $this->template_mod
. "_function_argument.html");
64 function i_once($file) {
65 return include_once($file);
68 function act($qarray) {
70 if (isset($_GET['process'])){
71 unset($_GET['process']);
72 unset($qarray['process']);
73 $_POST['process'] = "true";
75 $args = array_reverse(array_keys($qarray));
76 $c_name = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
77 $parts = split("_",$c_name);
80 foreach($parts as $p) {
85 $c_action = preg_replace("/[^A-Za-z0-9_]/","",array_pop($args));
86 $args = array_reverse($args);
88 // load dutch version for C_Prescription.class
89 if ( (LANGUAGE
== '5') && ($c_name == "Prescription") ) $c_name .= 'dutch';
91 if(!@call_user_func
(array(Controller
,"i_once"),$GLOBALS['fileroot'] ."/controllers/C_" . $c_name . ".class.php")) {
92 echo "Unable to load controller $name\n, please check the first argument supplied in the URL and try again";
96 $obj_name = "C_" . $c_name;
97 $c_obj = new $obj_name();
99 if (empty ($c_action)) {
100 $c_action = "default";
103 $c_obj->_current_action
= $c_action;
104 $args_array = array();
106 foreach ($args as $arg) {
107 $arg = preg_replace("/[^A-Za-z0-9_]/","",$arg);
108 //this is a workaround because call user func does funny things with passing args if they have no assigned value
109 if (empty($qarray[$arg])) {
110 //if argument is empty pass null as value and arg as assoc array key
111 $args_array[$arg] = null;
114 $args_array[$arg] = $qarray[$arg];
119 //print_r($args_array);
120 if ($_POST['process'] == "true") {
122 if (is_callable(array(&$c_obj,$c_action . "_action_process"))) {
123 //echo "ca: " . $c_action . "_action_process";
124 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action_process"),$args_array);
125 if ($c_obj->_state
== false) {
129 //echo "ca: " . $c_action . "_action";
130 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
134 if (is_callable(array(&$c_obj,$c_action . "_action"))) {
135 //echo "ca: " . $c_action . "_action";
136 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
139 echo "The action trying to be performed: " . $c_action ." does not exist controller: ". $name;
147 function _link($action = "default",$inlining = false) {
148 $url_parts = split("&",$_SERVER['REQUEST_URI']);
149 $link = array_shift($url_parts);
150 //print_r($url_parts);
152 if (strpos($url_parts[0],"=") === false) {
153 $inline_arg = $url_parts[0];
154 $url_parts[0] = $action;
157 array_unshift($url_parts,$action);
160 $link .= "&" . $inline_arg;
161 $link .= "&action=" . $url_parts[0];
164 $link .= "&" . $url_parts[0];
167 foreach ($this->_args
as $arg_name => $arg) {
168 $link .= "&" . $arg_name . "=" . $arg;