~ubuntu-branches/ubuntu/trusty/phpldapadmin/trusty-proposed

« back to all changes in this revision

Viewing changes to htdocs/mass_update.php

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2010-05-10 06:15:32 UTC
  • mfrom: (1.1.9 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100510061532-s4m6ytom0eb7oam1
Tags: 1.2.0.5-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Merged call to dh_install to install debian/additional-templates/*
  - added groupOfNames.xml
  - Adds php_value memory_limit 32M to the apache.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Main command page for phpLDAPadmin
 
4
 * This script will handle bulk updates.
 
5
 *
 
6
 * @package phpLDAPadmin
 
7
 * @subpackage Page
 
8
 */
 
9
 
 
10
/**
 
11
 */
 
12
 
 
13
require_once './common.php';
 
14
 
 
15
$request = array();
 
16
$request['dn'] = get_request('dn','REQUEST',true);
 
17
$request['mass_values'] = get_request('mass_values','REQUEST',true);
 
18
 
 
19
# Check if the entries exist.
 
20
$request['update'] = array();
 
21
 
 
22
foreach ($request['dn'] as $index => $dn) {
 
23
        # Check if the entry exists.
 
24
        if (! $dn || ! $app['server']->dnExists($dn)) {
 
25
                system_message(array(
 
26
                        'title'=>_('Entry does not exist'),
 
27
                        'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn),
 
28
                        'type'=>'error'));
 
29
 
 
30
                continue;
 
31
        }
 
32
 
 
33
        # Simulate the requirements for *Render->accept()
 
34
        if (! isset($request['mass_values'][$index]))
 
35
                continue;
 
36
 
 
37
        $_REQUEST['new_values'] = $request['mass_values'][$index];
 
38
 
 
39
        $render = new MassRender($app['server']->getIndex(),'none');
 
40
        $render->setDN($dn);
 
41
        $render->accept(true);
 
42
 
 
43
        if ($render->getTemplate()->getLDAPmodify(false,$index))
 
44
                $request['update'][$index] = $render;
 
45
}
 
46
 
 
47
# We can use the $render to give us a title
 
48
$render->drawTitle(_('Bulk update the following DNs'));
 
49
$render->drawSubTitle(sprintf('%s: <b>%s</b>',_('Server'),$app['server']->getName()));
 
50
 
 
51
if (count($request['update'])) {
 
52
        if (get_request('confirm','REQUEST')) {
 
53
                foreach ($request['update'] as $index => $page) {
 
54
                        $template = $page->getTemplate();
 
55
 
 
56
                        # Perform the modification
 
57
                        $result = $app['server']->modify($template->getDN(),$template->getLDAPmodify(false,$index));
 
58
 
 
59
                        if ($result)
 
60
                                printf('%s: <b>%s</b><br>',$template->getDN(),_('Modification successful!'));
 
61
                        else
 
62
                                printf('%s: <b>%s</b><br>',$template->getDN(),_('Modification NOT successful!'));
 
63
                }
 
64
 
 
65
        } else {
 
66
                echo '<form action="cmd.php" method="post">';
 
67
                echo '<input type="hidden" name="cmd" value="mass_update" />';
 
68
                printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
 
69
                echo '<input type="hidden" name="confirm" value="1" />';
 
70
 
 
71
                foreach ($request['update'] as $j => $page)
 
72
                        printf('<input type="hidden" name="dn[%s]" value="%s" />',$j,$page->getTemplate()->getDN());
 
73
 
 
74
                echo '<table class="result_box" width=100% border=1>';
 
75
                echo '<tr><td>';
 
76
 
 
77
                echo '<br/>';
 
78
 
 
79
                echo '<table class="result" border=0>';
 
80
                echo '<tr><td>';
 
81
                printf(_('There will be %s updates done with this mass update'),sprintf('<b>%s</b>',count($request['update'])));
 
82
                echo '</td></tr>';
 
83
                echo '</table>';
 
84
 
 
85
                echo '<br/>';
 
86
 
 
87
                foreach ($request['update'] as $index => $page) {
 
88
                        $template = $page->getTemplate();
 
89
 
 
90
                        echo '<table class="result" border=0>';
 
91
                        echo '<tr class="list_title">';
 
92
                        printf('<td class="icon"><img src="%s/%s" alt="icon" /></td>',IMGDIR,get_icon($app['server']->getIndex(),$template->getDN()));
 
93
 
 
94
                        printf('<td colspan=3><a href="cmd.php?cmd=template_engine&amp;server_id=%s&amp;dn=%s">%s</a></td>',
 
95
                                $app['server']->getIndex(),rawurlencode(dn_unescape($template->getDN())),htmlspecialchars(get_rdn($template->getDN())));
 
96
                        echo '</tr>';
 
97
 
 
98
                        printf('<tr class="list_item"><td class="blank">&nbsp;</td><td class="heading">dn</td><td class="value" width="45%%">%s</td><td class="value" width="45%%"><b>%s</b></td></tr>',
 
99
                                htmlspecialchars(dn_unescape($template->getDN())),_('Old Value'));
 
100
 
 
101
                        foreach ($template->getLDAPmodify(true,$index) as $attribute) {
 
102
                                echo '<tr class="list_item">';
 
103
                                echo '<td class="blank">&nbsp;</td>';
 
104
 
 
105
                                echo '<td class="heading">';
 
106
                                $page->draw('Name',$attribute);
 
107
                                echo '</td>';
 
108
 
 
109
                                # Show NEW Values
 
110
                                echo '<td><span style="white-space: nowrap;">';
 
111
 
 
112
                                if (! $attribute->getValueCount() || $attribute->isForceDelete()) {
 
113
                                        printf('<span style="color: red">[%s]</span>',_('attribute deleted'));
 
114
                                        printf('<input type="hidden" name="mass_values[%s][%s][%s]" value="%s" />',$index,$attribute->getName(),0,'');
 
115
                                }
 
116
 
 
117
                                foreach ($attribute->getValues() as $key => $value) {
 
118
                                        # For multiple values, we'll highlight the changed ones
 
119
                                        if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues()))
 
120
                                                echo '<span style="color:#004400; background:#FFFFA0">';
 
121
 
 
122
                                        $page->draw('CurrentValue',$attribute,$key);
 
123
 
 
124
                                        # For multiple values, close the highlighting
 
125
                                        if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues()))
 
126
                                                echo '</span>';
 
127
 
 
128
                                        echo '<br />';
 
129
                                        printf('<input type="hidden" name="mass_values[%s][%s][%s]" value="%s" />',$index,$attribute->getName(),$key,$value);
 
130
                                }
 
131
 
 
132
                                echo '</span></td>';
 
133
 
 
134
                                # Show OLD Values
 
135
                                echo '<td><span style="white-space: nowrap;">';
 
136
 
 
137
                                if (! $attribute->getOldValues())
 
138
                                        printf('<span style="color: green">[%s]</span>',_('attribute doesnt exist'));
 
139
 
 
140
                                        foreach ($attribute->getOldValues() as $key => $value) {
 
141
                                        # For multiple values, we'll highlight the changed ones
 
142
                                        if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues()))
 
143
                                                echo '<span style="color:#880000; background:#FFFFA0">';
 
144
 
 
145
                                        $page->draw('OldValue',$attribute,$key);
 
146
 
 
147
                                        # For multiple values, close the highlighting
 
148
                                        if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues()))
 
149
                                                echo '</span>';
 
150
 
 
151
                                        echo '<br />';
 
152
                                }
 
153
 
 
154
                                echo '</span></td>';
 
155
 
 
156
                                echo '</tr>';
 
157
                        }
 
158
 
 
159
                        echo '</table>';
 
160
 
 
161
                        echo '<br/>';
 
162
                }
 
163
 
 
164
                echo '</td></tr>';
 
165
                echo '</table>';
 
166
                printf('<input type="submit" id="save_button" name="submit" value="%s" />',_('Update Values'));
 
167
                echo '</form>';
 
168
        }
 
169
 
 
170
} else {
 
171
        echo '<center>';
 
172
        echo _('You made no changes');
 
173
        echo '</center>';
 
174
}
 
175
?>