1<?php 2 3use dokuwiki\Form\Form; 4 5/** 6 * Plugin timetrack 7 * 8 * @package dokuwiki\plugin\timetrack 9 * @author peterfromearth <coder@peterfromearth.de> 10 */ 11 12/** 13 * All DokuWiki plugins to extend the admin function 14 * need to inherit from this class 15 */ 16class admin_plugin_timetrack extends DokuWiki_Admin_Plugin { 17 18 /** 19 * @var helper_plugin_timetrack will hold the timetrack helper plugin 20 */ 21 public $tthlp = null; 22 23 //constructor 24 function __construct() { 25 global $conf; 26 $this->tmp = $conf['tmpdir'] .'/'; 27 28 $this->tthlp = plugin_load('helper', 'timetrack'); 29 if(!$this->tthlp) msg('Loading the timetrack helper failed. Make sure the timetrack plugin is installed.', -1); 30 } 31 32 33 /** 34 * handle user request 35 */ 36 function handle() { 37 global $INPUT; 38 39 if($INPUT->bool('export') && checkSecurityToken()){ 40 require_once(DOKU_INC.'inc/fetch.functions.php'); 41 $data = $this->tthlp->getAll(); 42 if(!is_array($data)) $data = array('empty'); 43 $filename = 'timetrack'.time() . '.csv'; 44 $fp = fopen($this->tmp.$filename, 'w'); 45 if($fp) { 46 47 $keys = array_keys($data[0]); 48 fputcsv($fp,$keys); 49 foreach($data as $line){ 50 fputcsv($fp,$line); 51 } 52 53 sendFile($this->tmp . $filename, 'text/comma-separated-values', true, 0); 54 exit; 55 } 56 } 57 } 58 59 /** 60 * output appropriate html 61 */ 62 function html() { 63 echo '<h1>' . $this->getLang('timetrack') . '</h1>'; 64 65 ptln ( '<form action="' . wl ( $ID ) . '" method="post">' ); 66 67 $form = new Form(array( 68 'id'=>'timetrack-form' 69 )); 70 $form->setHiddenField('do', 'admin'); 71 $form->setHiddenField('page', 'timetrack'); 72 73 74 $form->addButton('export', 'Excel'); 75 echo $form->toHTML(); 76 77 } 78 79} 80 81