1<?php
2/**
3 * Federated Login for DokuWiki - toggle enabled providers class
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @link       http://www.dokuwiki.org/plugin:fedauth
7 * @author     Aoi Karasu <aoikarasu@gmail.com>
8 */
9
10/**
11 * Authorization providers management class responsible
12 * for toggling the enabled state of the providers.
13 *
14 * @author     Aoi Karasu <aoikarasu@gmail.com>
15 */
16class fa_toggle extends fa_manage {
17
18    /**
19     * Creates the class instance bound with the admin plugin and an authorization provider.
20     *
21     * @param objref $manager object reference to the admin plugin
22     * @param string $cmd name of the command to handle
23     * @param string $provid (optional) an authorization provider id
24     */
25    function __construct(&$manager, $cmd, $provid='') {
26        parent::__construct(&$manager, $cmd, $provid);
27    }
28
29    /**
30     * Performs either enable or disable action depending on checked items.
31     *
32     * @return string the processing result message
33     */
34    function process_toggle() {
35        if (!$this->isValidListSource()) return '';
36
37        $enable = is_array($_REQUEST['toggle']) ? $_REQUEST['toggle'] : array();
38        foreach ($this->getProvidersByListSource() as $id => $pro) {
39            if ($pro->toggle(in_array($id, $enable))) {
40                $save = true;
41            }
42        }
43        $this->success = true; // always success, even with no changes
44        if ($save) {
45            $this->saveConfig();
46            return 'Your changes have been saved.';
47        }
48        return '';
49    }
50
51    /**
52     * Handles AJAX call to display updated provider list.
53     *
54     * @return bool true on success
55     */
56    function handle_ajax_toggle() {
57        if (!$this->isValidListSource()) return false;
58
59        print $this->html_providers_list($this->getProvidersByListSource(), $this->listSource == 'large');
60        return true;
61    }
62
63} /* fa_toggle */
64
65/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
66