1<?php 2/** 3 * 4 * Admin Panle for epub plugin 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Myron Turner <turnermm02@shaw.ca> 7 */ 8 9class admin_plugin_epub extends DokuWiki_Admin_Plugin { 10 11 var $output = ''; 12 private $helper; 13 private $cache; 14 private $req; 15 private $metadir; 16 private $dbg=false; 17 private $results = ""; 18 function __construct () { 19 $this->helper = $this->loadHelper('epub', true); 20 $this->cache = $this->helper->getCache() ; 21 $this->metadir = metaFN('epub',""); 22 } 23 /** 24 * handle user request 25 */ 26 function handle() { 27 28 if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do 29 30 $msg=""; 31 if (!checkSecurityToken()) return; 32 if (!is_array($_REQUEST['cmd'])) return; 33 $epub_deletions = array(); 34 $which = key($_REQUEST['cmd']); 35 foreach($_REQUEST['book_id'] as $md5=>$id) { 36 if($which == 'media') { 37 $epub_deletions[] = $this->helper->delete_media($md5); 38 } 39 $this->helper->delete_page($md5); 40 } 41 if(is_array($_REQUEST['book_id'])) $this->cache = $this->helper->getCache() ; 42 if(count($epub_deletions)) { 43 $this->results = "<b>Results</b><br />"; 44 $this->results .= implode('<br />', $epub_deletions); 45 } 46 /* if debugging */ 47 if($this->dbg) { 48 $this->req = print_r($_REQUEST,true) . $msg . "which=$which\n"; 49 $this->req .= print_r($epub_deletions,true); 50 $this->req = str_replace("\n","<br />",$this->req); 51 } 52 53 } 54 55 56 function html() { 57 58 ptln( $this->locale_xhtml('admin_header')); 59 60 $cache = $this->cache; 61 $current_books = $this->cache['current_books']; 62 unset ($cache['current_books']); 63 64 //ptln('<form action="'.wl($ID).'" method="post" onsubmit="return epub_admin_confirm(this);" id="epub_admin" name="epub_admin">' ); 65 ptln('<form action="'.wl($ID).'" method="post" id="epub_admin" name="epub_admin">' ); 66 echo "<ul>\n"; 67 foreach($cache as $md5=>$id) { 68 $id=trim($id); 69 if(!$id) $id = '<undefined>'; 70 ptln('<li style="list-style-type:none; color: #333;"><input name="book_id[' . $md5 .']" type="checkbox" value="' . $id. '"> ' . $id ); 71 ptln(' <ul><li style="color:#333">' . $current_books[$md5]['title'] . "\n" . ' <li style="color:#333">' . $current_books[$md5]['epub']); 72 ptln(" <!--input type = 'hidden' name='$md5' value='" . $current_books[$md5]['epub'] ."'/ -->\n </ul>"); 73 74 75 } 76 echo " </ul>\n"; 77 78 ptln(' <input type="hidden" name="do" value="admin" />'); 79 ptln(' <input type="hidden" name="page" value="'.$this->getPluginName().'" />'); 80 formSecurityToken(); 81 ptln(' <input type="submit" name="cmd[cache]" onclick="return epub_admin_confirm(\'cache\');" id="epub_cache_btn" value="'.$this->getLang('btn_submit').'" />'); 82 ptln(' <input type="submit" onclick="return epub_admin_confirm(\'media\');" name="cmd[media]" id="epub_media_btn" value="'.$this->getLang('btn_del').'" />'); 83 ptln('</form>'); 84 85 if($this->dbg) { 86 echo $this->req . "<br />"; 87 } 88 if($this->results) { 89 ptln('<p><br />' .$this->results . '</p>'); 90 } 91 } 92 93} 94