From: <ni...@us...> - 2007-08-06 21:47:18
|
Update of /cvsroot/tikiwiki/tiki/lib/mypage In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30856/lib/mypage Modified Files: mypagelib.php Log Message: [FIX] mypage: mypage_edit now allow editing and creating mypages Index: mypagelib.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/mypage/mypagelib.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- mypagelib.php 6 Aug 2007 19:34:06 -0000 1.8 +++ mypagelib.php 6 Aug 2007 21:47:19 -0000 1.9 @@ -39,13 +39,19 @@ */ class MyPage { var $id; + var $id_users; var $windows; var $lastid; + var $params; + var $modified; - function MyPage($id=NULL) { + function MyPage($id=NULL, $id_users) { $this->id=$id; + $this->id_users=$id_users; $this->windows=array(); $this->lastid=0; + $this->params=array(); + $this->modified=array(); $this->checkout(); } @@ -109,6 +115,15 @@ return $pages; } + function setParam($param, $value) { + $this->params[$param]=$value; + $this->modified[$param]=true; + } + + function getParam($param) { + return $this->params[$param]; + } + function checkout() { global $tikilib; @@ -117,9 +132,9 @@ if (!is_null($this->id)) { $res=$tikilib->query("SELECT * FROM tiki_mypage WHERE `id`=?", array($this->id)); if ($line = $res->fetchRow()) { - + $this->params=$line; } else { // bad... no mypage found - $this->id=NULL; + $this->id=0; return FALSE; } @@ -136,7 +151,35 @@ if (is_null($this->id)) { // create a new mypage id + + $res=$tikilib->query("INSERT INTO tiki_mypage (`id_users`) values (?)", + array($this->id_users)); + if (!$res) return; + + $id=$tikilib->getOne("SELECT LAST_INSERT_ID()"); + if (!$id) return; + + $this->id=$id; + + // now run again for update ;) + return $this->commit(); + } else { + if (count($this->modified) > 0) { + $l=array(); + $r=array(); + foreach($this->modified as $k => $v) { + $l[]="`$k`=?"; + $r[]=$this->params[$k]; + } + + $query="UPDATE tiki_mypage SET ".implode(',', $l)." WHERE `id`=?"; + $r[]=$this->id; + + $res=$tikilib->query($query, $r); + + $this->modified=array(); + } } } |