php8
[web.mtrack] / MTrackWeb / Wiki.php
index d0b41f7..5d18bd1 100644 (file)
@@ -27,6 +27,8 @@ class MTrackWeb_Wiki extends MTrackWeb
     var $conflicted = 0;
     var $message = false;
     var $hasHistory = false;
+    var $title;
+    var $authUserArray;
     
     function getAuth()
     {
@@ -36,20 +38,44 @@ class MTrackWeb_Wiki extends MTrackWeb
     function get($pi='')
     {
         // non 'json' request...
+      
         if (!isset($_REQUEST['ajax_body'])) {
             $this->title = "Browse: " . $pi;
             return;
         }
-        //DB_DataObject::debugLevel(1);
+        
         $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);
+        //var_dump($p);
         if (!$p->find(true)) {
-            $this->returnNotFound($pi);
+            $p->id = 0;
+            $this->jdata($p->toArray());
         }
         $this->jdata($p->toArray());
  
@@ -57,35 +83,51 @@ class MTrackWeb_Wiki extends MTrackWeb
     }
  
  
-    function returnNotFound($pi) {
-        $this->jdata(array(
-            'id' => 0,
-            'path' => $pi,
-            'wikidata' => ''
+    function returnNotFound($p) {
+        
         
-        ));
         
         
         
     }
  
-    function post()
+    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'])) {
+        
+        $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");
         }
-        call_user_method($o->id ? 'update' : 'insert', $p, $o);
+        
+        // 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");
+            }
+        }
+        
+        
+        call_user_func(array($p, $o->id ? 'update' : 'insert'),  $o);
         
         $this->jok($p->toArray());