/dev/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/trunk

« back to all changes in this revision

Viewing changes to admin/do.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-06-17 23:19:26 UTC
  • Revision ID: csa@dside.dyndns.org-20080617231926-w9mpfxw6lv0r0450
Administrative interface and better handling of missing group channels

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
    function PlaceJS() {
 
4
        global $action;
 
5
        global $postfix;
 
6
?>
 
7
<script type="text/javascript">
 
8
//<![CDATA[
 
9
    function Confirm() {
 
10
        window.location = "index.php?page=do.php&confirm&action=<?echo $action;?>&postfix=<?echo urlencode(json_encode($postfix));?>";
 
11
    }
 
12
//]]>
 
13
</script>
 
14
<?}
 
15
 
 
16
    function RequestConfirmation($msg, $list) {
 
17
        echo "<b>$msg</b>";
 
18
        echo "<div class=\"list\">";
 
19
        foreach ($list as $postfix) {
 
20
            echo "cache*$postfix<br/>";
 
21
        }
 
22
        echo "</div>";
 
23
        echo "<br/>";
 
24
        echo "<button onclick=\"Confirm();\">" . translate("Confirm") . "</button>";
 
25
    }
 
26
 
 
27
 
 
28
    function GetAdminFile($prefix = false) {
 
29
        global $TMP_PATH;
 
30
    
 
31
        $dir = "admin/";
 
32
 
 
33
        if (!is_dir($TMP_PATH . "/" .  $dir)) {
 
34
            if (!@mkdir($TMP_PATH . "/" . $dir, 0755, true)) 
 
35
                throw new ADEIException(translate("Access to the temporary directory is denied"));
 
36
        }
 
37
 
 
38
        $fn = tempnam($TMP_PATH . "/" .  $dir, $prefix);
 
39
 
 
40
        if ($fn) unlink($fn);
 
41
 
 
42
        return $fn . ".php";
 
43
    }
 
44
 
 
45
 
 
46
 
 
47
    $action = $_REQUEST['action'];
 
48
    $confirm = isset($_REQUEST['confirm']);
 
49
 
 
50
    echo "<br/><br/>";
 
51
 
 
52
    if (isset($_GET['postfix']))
 
53
        $postfix = json_decode(stripslashes($_GET['postfix']), true);
 
54
    else {
 
55
        $postfix = array();
 
56
        foreach ($_POST as $key => $value) {
 
57
            if (($value == 1)&&(preg_match("/^postfix(.*)$/", $key, $m))) {
 
58
                array_push($postfix, $m[1]);
 
59
            }
 
60
        }
 
61
    }
 
62
    
 
63
    if (!$postfix) {
 
64
        ?><span class="error"><?echo translate("Error: The list of items is not supplied");?></span><?
 
65
        exit;
 
66
    }
 
67
    
 
68
    if (!is_array($postfix)) $postfix = array($postfix);
 
69
 
 
70
    if (!$confirm) PlaceJS();
 
71
    
 
72
    switch ($action) {
 
73
        case "drop":
 
74
            if ($confirm) {
 
75
                try {
 
76
                    $cache = new CACHEDB();
 
77
                    foreach ($postfix as $p) {
 
78
                        $cache->Drop($p);
 
79
                    }
 
80
                    echo translate("Done. All CACHES are droped.");
 
81
                } catch (ADEIException $ae) {
 
82
                    ?><span class="error"><?echo translate("Error: %s", $ae->getMessage());?></span><?
 
83
                }
 
84
            } else RequestConfirmation(
 
85
                translate("Do you really want to drop following tables: "),
 
86
                $postfix);
 
87
            break;
 
88
        case "rewidth":
 
89
            if ($confirm) {
 
90
                try {
 
91
                    $name = GetAdminFile("resize-");
 
92
                    $f = fopen($name, "w");
 
93
                    if (!$f)
 
94
                        throw new ADEIException(translate('Error creating temporary file: %s', $name));
 
95
                    
 
96
                    fwrite ($f, '<?php
 
97
                        require("../../adei.php");
 
98
                        try {
 
99
                            $cache = new CACHEDB();
 
100
                    ');
 
101
                    foreach ($postfix as $p) {
 
102
                        fwrite($f, '$cache->Rewidth("' . $p . '", true);' . "\n");
 
103
                    }
 
104
                    fwrite($f, '
 
105
                        } catch (ADEIException $ae) {
 
106
                            echo translate("Error: %s", $ae->getMessage()) . "\n";
 
107
                            exit;
 
108
                        }
 
109
                        echo translate("done...") . "\n";?>');
 
110
                    fclose($f);
 
111
                    
 
112
                    if ($SETUP) {
 
113
                        echo "Please, login to the server and run: php $name -setup $SETUP";
 
114
                    } else {
 
115
                        echo "Please, login to the server and run: php $name";
 
116
                    }
 
117
 
 
118
/*
 
119
                    $cache = new CACHEDB();
 
120
                    foreach ($postfix as $p) {
 
121
                        $cache->Rewidth($p);
 
122
                    }
 
123
*/
 
124
                } catch (ADEIException $ae) {
 
125
                    ?><span class="error"><?echo translate("Error: %s", $ae->getMessage());?></span><?
 
126
                }
 
127
            } else RequestConfirmation(
 
128
                translate("Do you really want to resize following tables: "),
 
129
                $postfix);
 
130
            break;
 
131
        default:
 
132
        ?><span class="error"><?
 
133
            if ($action)
 
134
                echo translate("Error: Invalid action \"%s\" is specified", $action);
 
135
            else
 
136
                echo translate("Error: Action is not specified");
 
137
        ?></span><?
 
138
    }   
 
139
    
 
140
    
 
141
 
 
142
?>
 
 
b'\\ No newline at end of file'