00001 <?php
00002
00010 class TKPostAction extends TKAction {
00011 protected $action;
00012 protected $vars;
00013 protected $postId;
00014
00015 protected static $allPostId = 0;
00016
00023 public function __construct($vars = array(), $action = "") {
00024 parent::__construct();
00025
00026 if($action == "") {
00027 $action = $_SERVER['REQUEST_URI'];
00028 }
00029 $this->action = $action;
00030 $this->vars = $vars;
00031
00032 $this->postId = self::$allPostId;
00033 self::$allPostId++;
00034 }
00035
00037 public function getInvocation() {
00038 if($this->vars instanceof TKForm || $this->vars instanceof TKFormTable) {
00039 $formName = $this->vars->getId();
00040 }
00041 else {
00042 $formName = "post_" . $this->postId . "_action";
00043 $form = "<form id=\"$formName\" method=\"post\""
00044 . " action=\"" . $this->action . "\">";
00045 foreach($this->vars as $name => $value) {
00046 $form .= "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
00047 }
00048 $form .= "</form>";
00049 $this->addHiddenForm($formName, $form);
00050 }
00051 return "Toolkit.doPost('" . $formName . "')";
00052 }
00053
00055 public static function createFromXML($attrs, $children) {
00056 $varStr = isset($attrs['vars']) ? (string)$attrs['vars'] : "";
00057 $action = isset($attrs['faction']) ? (string)$attrs['faction'] : "";
00058 $vars = array();
00059 $tmp = split(";", $varStr);
00060 foreach($tmp as $t) {
00061 if($t == '')
00062 continue;
00063 $tmp2 = split("::", $t);
00064 $vars[$tmp2[0]] = $tmp2[1];
00065 }
00066 $obj = new TKPostAction($vars, $action);
00067 return $obj;
00068 }
00069 }
00070
00071 ?>