1<?php
2/**
3 * Database Management functions
4 * There is a dokuwiki folder called db and selecting this namespace triggers the DB plugin
5 *
6 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author   Langham Associates <enquiries@langhamAssociates.com>
8 *
9 * v1.0.4
10 */
11 // Folder called database required and selecting this namespace triggers DB plugin
12
13// must be run within Dokuwiki
14if(!defined('DOKU_INC')) die();
15
16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
17require_once(DOKU_PLUGIN.'action.php');
18// The code secific to the  db plugin
19require_once('database.php');
20
21/**
22 * All DokuWiki plugins to extend the action function
23 * need to inherit from this class
24 */
25class action_plugin_database extends DokuWiki_Action_Plugin {
26
27        function admin_plugin_acl(){
28            $this->setupLocale();
29        }
30/**
31 * return some info
32 *
33 * this function is required by dokuwiki
34 *
35 */
36    function getInfo(){
37      return array(
38        'author' => 'Langham Associates',
39        'email'  => 'enquiries@langhamassociates.com',
40        'date'   => '2008-04-06',
41        'name'   => 'Database Manager',
42        'desc'   => 'Manage your own Database within the wiki',
43        'url'    => 'http://www.langhamassociates.com/wiki/doku.php?id=start',
44      );
45    }
46/**
47 * Register the functionality with dokuwiki
48 *
49 * this function is required by dokuwiki
50 *
51 */
52    function register(&$controller) {
53
54        global $dbName;
55        $dbName = 'database';
56        $controller->register_hook('TPL_ACT_RENDER',
57                                   'BEFORE',
58                                    $this,
59                                   'handle_render',
60                                    array());
61
62    }
63/**
64 *
65 * Handle the hook declared before dokuwiki renders the body
66 *
67 *
68 */
69    function handle_render(&$event, $param) {
70        global $IDX;
71        global $ACT;
72        $ID=getID();
73        global $dbName;
74        global $environment;
75        global $myLang;
76        global $action;
77        global $tableId;
78        global $recordId;
79        global $conf;
80        global $lookupPath;
81        global $dictionaryPath;
82        $this->setupLocale();
83        $myLang=$this->lang;
84        $environment= new Environment();
85        $command = substr($IDX,strlen($dbName)+1);
86        $tableId = substr($command,0,strpos($command,'-')+1); // bypass the default if the following apply
87
88
89        if (isset($_REQUEST['action']) || isset($_REQUEST['fn'])  // already in db code
90           ||                                         // or
91             (
92             substr($IDX,0,strlen($dbName))==$dbName  // in db nameSpace
93             &&                                       // and
94             strlen($IDX)>strlen($dbName)             // selected a folder
95             )
96              ) {
97// There are two methods of determing the action
98// 1. Using an icon with name='fn[action][param(s)]' and params separated by |
99// 2. Using a form with hidden fields of action, table and record
100
101    // Handle buttons and convert into actions
102            if (isset($_REQUEST['fn'])) {
103        // extract the command and any specific parameters
104        // submit button name is of the form - fn[cmd][param(s)]
105                $fn   = $_REQUEST['fn'];
106
107                if (is_array($fn)) {
108                    $action = key($fn);
109                    $param = is_array($fn[$action]) ? key($fn[$action]) : null;
110                    $elements = explode($environment->COLUMN_SEPARATOR, $param);
111                    $tableId  = $elements[0];
112                    $recordId = $elements[1];
113                }
114            } else {
115// Pick up the action
116                if (isset($_REQUEST["action"])) {
117                    $action=$_REQUEST["action"];
118// Pick up the table and record if they have been set
119                    if (isset($_REQUEST["table"]))
120                        $tableId  = $_REQUEST["table"];
121                    if (isset($_REQUEST["record"]))
122                        $recordId = $_REQUEST["record"];
123                }
124            }
125// prevent the default dokuwiki output
126            if ($action != 'home' ) {
127// ************ Main call to database code ****************************
128                $event->preventDefault();
129
130// call the db functions which will handle the processing from now on
131                action_db();
132// *********************************************************************
133            } else {
134// home - so run the main wiki page
135                $_REQUEST['id']='start';
136                $_REQUEST['idx']=$dbName;
137            }
138        }
139    }
140}
141?>