forked from practical-solutions/addressbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
89 lines (60 loc) · 2.81 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* DokuWiki Plugin Addressbook
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author: Gero Gothe <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
define('DEBUG',false);
/**
* Class action_plugin_addressbook
*/
class action_plugin_addressbook extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller) { $controller->register_hook('FORM_SEARCH_OUTPUT', 'AFTER', $this,'addSearchResults');}
public function addSearchResults(Doku_Event $event, $param)
{
global $INPUT;
$searchForm = $event->data;
$list = $this->searchResult($_REQUEST['q']);
if (!$list) return;
$res .= '<div class="plugin_addressbook_searchpage">';
$res .= '<h2>'.$this->getLang('results msg').':</h2>';
$syntax = plugin_load('syntax', 'addressbook');
if (count($list)<5) {
foreach ($list as $l) $res .= $syntax->showcontact($l['id'],($this->getConf('search link target') != ''? $this->getConf('search link target'):false));
} else $res .= $syntax->buildIndex($list,false,($this->getConf('search link target') != ''? $this->getConf('search link target'):false));
foreach ($found as $f) $res .= $syntax->showcontact($f['id']);
$res .= '</div>';
$searchForm->addHTML($res);
}
/* Maximum 20 results ! */
function searchResult ($text=false,$order='surname,firstname,cfunction'){
if ($text == false || strlen($text) < 2) return false;
try {
$db_helper = plugin_load('helper', 'addressbook_db');
$sqlite = $db_helper->getDB();
} catch (Exception $e) {
msg($e->getMessage(), -1);
return false;
}
$text = explode(" ",$text);
$sql = "select * from addresslist WHERE instr(lower(surname || firstname || tel1 || tel2 || fax || description || cfunction || department) ,'".$text[0]."') > 0";
for ($c=1;$c<count($text);$c++) $sql .= " AND instr(lower(' ' || surname || firstname || tel1 || tel2 || fax || description || cfunction || department) ,'".$text[$c]."') > 0";
$sql .= " ORDER BY $order LIMIT 20";
$query = $sqlite->query($sql);
$res = $sqlite->res2arr($query);
if ($sqlite->res2count($sqlite->query($sql)) == 0) {
return false;
}
return $res;
}
}
// vim:ts=4:sw=4:et: