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
{
13 function Controller() {
15 $this->template_mod
= "general";
16 $this->_current_action
= "";
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 <? 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));
67 function function_argument_error() {
68 $this->display($GLOBALS['template_dir'] . "error/" . $this->template_mod
. "_function_argument.html");
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);
88 foreach($parts as $p) {
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";
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;
119 $args_array[$arg] = $qarray[$arg];
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) {
134 //echo "ca: " . $c_action . "_action";
135 $output .= call_user_func_array(array(&$c_obj,$c_action . "_action"),$args_array);
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);
144 echo "The action trying to be performed: " . $c_action ." does not exist controller: ". $name;
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;
162 array_unshift($url_parts,$action);
165 $link .= "&" . $inline_arg;
166 $link .= "&action=" . $url_parts[0];
169 $link .= "&" . $url_parts[0];
172 foreach ($this->_args
as $arg_name => $arg) {
173 $link .= "&" . $arg_name . "=" . $arg;