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></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));
58 function function_argument_error() {
59 $this->display($GLOBALS['template_dir'] . "error/" . $this->template_mod
. "_function_argument.html");
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);
79 foreach($parts as $p) {
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";
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;
109 $args_array[$arg] = $qarray[$arg];
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) {
124 //echo "ca: " . $c_action . "_action";
125 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
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);
134 echo "The action trying to be performed: " . $c_action ." does not exist controller: ". $name;
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;
152 array_unshift($url_parts,$action);
155 $link .= "&" . $inline_arg;
156 $link .= "&action=" . $url_parts[0];
159 $link .= "&" . $url_parts[0];
162 foreach ($this->_args
as $arg_name => $arg) {
163 $link .= "&" . $arg_name . "=" . $arg;