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