return parent::getAuth();
}
- function get($pi)
+ function get($pi='')
{
// non 'json' request...
+
if (!isset($_REQUEST['ajax_body'])) {
- $this->title = "Browse: " . $this->pi;
+ $this->title = "Browse: " . $pi;
return;
}
- $p = DB_DataObject::Factory('mtrack_wiki');
+ $p = DB_DataObject::Factory('Mtrack_wiki');
$p->project_id = $this->currentProject();
+
$p->path = $pi;
+
+ // we add stuff on the end..
+ if (empty($pi)) {
+ $px = DB_DataObject::Factory('Mtrack_wiki');
+ $px->project_id = $this->currentProject();
+ $px->orderBy('path');
+
+ $pr = DB_DataObject::factory('core_project');
+ $pr->get($px->project_id);
+
+ $ar = $px->fetchAll('path');
+ $wikidata = "## Index of pages in Wiki - {$pr->name} \n\n";
+ foreach($ar as $pp) {
+ $wikidata .= " * [$pp](wiki:$pp)\n";
+ }
+ $p->wikidata = $wikidata;
+ $this->jdata($p->toArray());
+
+
+
+
+ }
+
+ //var_dump($p);
if (!$p->find(true)) {
- $this->returnNotFound($pi);
+ $p->id = 0;
+ $this->jdata($p->toArray());
}
$this->jdata($p->toArray());
//echo '<PRE>';print_r($this);echo '</PRE>';
}
- function post()
+
+ function returnNotFound($p) {
+
+
+
+
+
+ }
+
+ function post($request)
{
+ //DB_DataObject::debugLevel(1);
+
+ $au = $this->getAuthUser();
+ if (!$au) {
+ // autherr?
+ $this->jerr("permission denied");
+ }
$p = DB_DataObject::factory('mtrack_wiki');
- $p->project_id = $this->currentProject();
-
- if (empty($_REQUEST['id']) && !$p->get($_REQUEST['id'])) {
+ $p->project_id = $this->currentProject();
+
+ $id = empty($_REQUEST['id']) ? 0 : $_REQUEST['id'] * 1;
+ if (!empty($id) && !$p->get($id)) {
$this->jerr('invalid id');
}
$o = clone($p);
- $this->setFrom($_POST);
+ $p->setFrom($_POST);
if ($o->project_id != $p->project_id) {
$this->jerr("changing project id not permitted");
}
+ // check change of path...
+ if (!$o->id || ($o->path != $p->path)) {
+ $c = DB_DataObject::factory('mtrack_wiki');
+ $c->project_id = $p->project_id;
+ $c->path = $p->path;
+ if ($c->count()) {
+ $this->jerr("Path is not valid - that path already exists");
+ }
+ }
+
- }
\ No newline at end of file
+ call_user_func(array($p, $o->id ? 'update' : 'insert'), $o);
+
+ $this->jok($p->toArray());
+
+ }
+}
\ No newline at end of file