File size: 5,355 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
 * methodsPermissions.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 *
 */

/*
 * Esto no deberias borrarlo
 */
$tree = new PmTree();

reView(PATH_TRUNK, $tree);
print( $tree->render());

function reView($path, &$tree)
{
    $tree->name = $path;
    $tree->value = $path . '&nbsp;' .
        setHeader('Set Header', 'setDirHeader("' . $path . '",this);') .
        selectPermissions('Set Permission', 'setDirPermission("' . $path . '",this);') .
        selectPermissions('Remove Permission', 'removeDirPermission("' . $path . '",this);');
    $tree->contracted = true;
    foreach (glob($path . '*', GLOB_MARK) as $file) {
        if (is_dir($file)) {
            reView($file, $tree->addChild($file, $file));
        } elseif (substr($file, -4, 4) === '.php') {
            $nodeFile = &$tree->addChild($file, $file . '&nbsp;' .
                    selectPermissions('Set Permission', 'setPermission("' . $file . '",this);') .
                    selectPermissions('Remove Permission', 'removePermission("' . $file . '",this);')
            );
            $nodeFile->addChild("View Permissions", '<div style="cursor:hand;" onclick="loadFile(&quot;' . htmlentities($file, ENT_QUOTES, 'UTF-8') . '&quot;,this.nextSibling);">View Permissions</div><div id="divPerms[' . htmlentities($file, ENT_QUOTES, 'UTF-8') . ']"></div>');
            $nodeFile->addChild("Add Line", '<a href="#" onclick="addPermission(&quot;' . htmlentities($file, ENT_QUOTES, 'UTF-8') . '&quot;,this.nextSibling.nextSibling);return false;">Add Permission</a><br/><input style="width:100%;"/>');
            $nodeFile->contracted = true;
        }
    }
}

function selectPermissions($label, $onchange)
{
    return '<select onchange="' . htmlentities($onchange, ENT_QUOTES, 'UTF-8') . '">' .
        '<option>' . $label . '</option>' .
        '<option value="PM_LOGIN">PM_LOGIN</option>' .
        '<option value="PM_USERS">PM_USERS</option>' .
        '<option value="PM_CASES">PM_CASES</option>' .
        '<option value="PM_FACTORY">PM_FACTORY</option>' .
        '<option value="PM_SETUP">PM_SETUP</option>' .
        '</select>';
}

function setHeader($label, $onchange)
{
    return '<input type="button" onclick="' . htmlentities($onchange, ENT_QUOTES, 'UTF-8') . '" value="set header"/>';
}
?>
<textarea id="headerText" cols="80" rows="25"></textarea>
<script>
    var headerText = document.getElementById("headerText");
    var phpFile = WebResource('methodsPermissions_Ajax');
    function loadFile(file, div)
    {
        div.innerHTML = phpFile.get_permissions(file);
    }
    function switchViewEdit(txt, inp)
    {
        showHideElement(txt);
        showHideElement(inp);
        inp.focus();
        var file = inp.name.split('?')[0];
        var row = parseInt(inp.name.split('?')[1]);
        //phpFile.modify_line(file,row,inp.value);
    }
    function switchEditView(txt, inp)
    {
        showHideElement(txt);
        showHideElement(inp);
        var file = inp.name.split('?')[0];
        var row = parseInt(inp.name.split('?')[1]);
        var res = phpFile.modify_line(file, row, inp.value);
        txt.innerHTML = res[0];
        inp.value = res[1];
    }
    function addPermission(file, inp)
    {
        var res = phpFile.add_permission(file, inp.value);
        document.getElementById('divPerms[' + file + ']').innerHTML = res;
    }
    function removeLine(btn)
    {
        var file = btn.name.split('?')[0];
        var row = parseInt(btn.name.split('?')[1]);
        var res = phpFile.remove_line(file, row);
        document.getElementById('divPerms[' + file + ']').innerHTML = res;
    }
    function setDirPermission(file, inp)
    {
        var res = phpFile.set_path_permission(file, inp.value);
        inp.selectedIndex = 0;
    }
    function setDirHeader(file, inp)
    {
        var res = phpFile.set_path_header(file, headerText.value);
        inp.selectedIndex = 0;
    }
    function removeDirPermission(file, inp)
    {
        var res = phpFile.remove_path_permission(file, headerText.value);
        inp.selectedIndex = 0;
    }
    function setPermission(file, inp)
    {
        var res = phpFile.set_permission(file, inp.value);
        document.getElementById('divPerms[' + file + ']').innerHTML = res;
        inp.selectedIndex = 0;
    }
    function removePermission(file, inp)
    {
        var res = phpFile.remove_permission(file, inp.value);
        document.getElementById('divPerms[' + file + ']').innerHTML = res;
        inp.selectedIndex = 0;
    }
</script>