1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4require_once(DOKU_PLUGIN.'admin.php');
5
6/**
7 * All DokuWiki plugins to extend the admin function
8 * need to inherit from this class
9 */
10class admin_plugin_message extends DokuWiki_Admin_Plugin {
11
12    /**
13     * Constructor
14     */
15    function admin_plugin_message() {
16        $this->setupLocale();
17    }
18
19    /**
20     * return some info
21     */
22    function getInfo() {
23        return array(
24            'author' => 'Etienne M.',
25            'email'  => 'emauvaisfr@yahoo.fr',
26            'date'   => @file_get_contents(DOKU_PLUGIN.'message/VERSION'),
27            'name'   => 'message Plugin',
28            'desc'   => 'Gestion des messages / Messages administration',
29            'url'    => 'http://www.dokuwiki.org/plugin:message',
30        );
31    }
32
33    /**
34     * return prompt for admin menu
35     */
36    function getMenuText($language) {
37      if (!$this->disabled)
38        return parent::getMenuText($language);
39      return '';
40    }
41
42    /**
43     * return sort order for position in admin menu
44     */
45    function getMenuSort() {
46        return 5000;
47    }
48
49    /**
50     * handle user request
51     */
52    function handle() {
53    }
54
55    /**
56     * output appropriate html
57     */
58    function html() {
59      global $lang;
60      global $conf;
61
62      print "<h1>".$this->getLang('mess_titre')."</h1>";
63      print $this->getLang('mess_texte');
64      print "<br /><br />";
65
66      if (isset($_POST['sauver']) && $_POST['sauver']==1) {
67        $ok=true;
68        $ok = $ok & $this->ecritFichier($conf['cachedir'].'/message_error.txt', $_POST['err']);
69        $ok = $ok & $this->ecritFichier($conf['cachedir'].'/message_info.txt', $_POST['info']);
70        $ok = $ok & $this->ecritFichier($conf['cachedir'].'/message_valid.txt', $_POST['valid']);
71        $ok = $ok & $this->ecritFichier($conf['cachedir'].'/message_remind.txt', $_POST['rappel']);
72
73        if ($ok) {
74          print "<form name=\"message_form\" method=\"POST\"><input type=\"hidden\" name=\"sauver\" value=\"0\" /></form>";
75          print "<script>document.forms['message_form'].submit();</script>";
76        }
77        else {
78          msg("<b>".$this->getLang('mess_erreurs')."</b>",-1);
79          print "<br />";
80        }
81      }
82
83      print "<form method=\"POST\">";
84      print "<input type=\"hidden\" name=\"sauver\" value=\"1\" />";
85
86      msg($this->getLang('mess_err'),-1);
87      $file=$conf['cachedir'].'/message_error.txt';
88      print "<textarea name=\"err\" style=\"width:100%\">";
89      print @file_get_contents($file);
90      print "</textarea>";
91      print "<br /><br />";
92
93      msg($this->getLang('mess_info'),0);
94      $file=$conf['cachedir'].'/message_info.txt';
95      print "<textarea name=\"info\" style=\"width:100%\">";
96      print @file_get_contents($file);
97      print "</textarea>";
98      print "<br /><br />";
99
100      msg($this->getLang('mess_ok'),1);
101      $file=$conf['cachedir'].'/message_valid.txt';
102      print "<textarea name=\"valid\" style=\"width:100%\">";
103      print @file_get_contents($file);
104      print "</textarea>";
105      print "<br /><br />";
106
107      msg($this->getLang('mess_rappel'),2);
108      $file=$conf['cachedir'].'/message_remind.txt';
109      print "<textarea name=\"rappel\" style=\"width:100%\">";
110      print @file_get_contents($file);
111      print "</textarea>";
112      print "<br /><br />";
113
114      print "<input type=\"submit\" value=\"".$this->getLang('mess_sauver')."\" title=\"".$this->getLang('mess_sauver')." [S]\" accesskey=\"s\" />";
115      print "</form>";
116
117    }
118
119    function ecritFichier($fic,$chaine) {
120      //if (is_writable($fic)) {
121      if (is_writable( $fic ) || (is_writable(dirname( $fic ).'/.') && !file_exists( $fic ))) {
122        if (!$handle = fopen($fic, 'w')) {
123          msg($this->getLang('mess_err_ouvrir')." ($fic).",-1);
124          return false;
125        }
126
127        if (fwrite($handle, $chaine) === FALSE) {
128          msg($this->getLang('mess_err_ecrire')." ($fic).",-1);
129          return false;
130        }
131
132        fclose($handle);
133        return true;
134
135    } else {
136      msg($this->getLang('mess_err_lectureseule')." ($fic).",-1);
137      return false;
138    }
139  }
140}
141// vim:ts=4:sw=4:et:enc=utf-8:
142