/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui
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

    function PlaceJS() {
	global $action;
	global $postfix;
?>
<script type="text/javascript">
//<![CDATA[
    function Confirm() {
	window.location = "index.php?page=do.php&confirm&action=<?echo $action;?>&postfix=<?echo urlencode(json_encode($postfix));?>";
    }
//]]>
</script>
<?
    }

    function RequestConfirmation($msg, $list) {
	echo "<b>$msg</b>";
	echo "<div class=\"list\">";
	foreach ($list as $postfix) {
	    echo "cache*$postfix<br/>";
	}
	echo "</div>";
	echo "<br/>";
	echo "<button onclick=\"Confirm();\">" . translate("Confirm") . "</button>";
    }


    function GetAdminFile($prefix = false) {
	global $TMP_PATH;
    
	$dir = "adminscripts/";

	if (!is_dir($TMP_PATH . "/" .  $dir)) {
	    if (!@mkdir($TMP_PATH . "/" . $dir, 0755, true)) 
		throw new ADEIException(translate("Access to the temporary directory is denied"));
	}

	$fn = tempnam($TMP_PATH . "/" .  $dir, $prefix);

	if ($fn) unlink($fn);

	return $fn . ".php";
    }



    $action = $_REQUEST['action'];
    $confirm = isset($_REQUEST['confirm']);

    echo "<br/><br/>";

    if (isset($_GET['postfix']))
	$postfix = json_decode(stripslashes($_GET['postfix']), true);
    else {
	$postfix = array();
	foreach ($_POST as $key => $value) {
	    if (($value == 1)&&(preg_match("/^postfix(.*)$/", $key, $m))) {
		array_push($postfix, $m[1]);
	    }
	}
    }
    
    if (!$postfix) {
	?><span class="error"><?echo translate("Error: The list of items is not supplied");?></span><?
	exit;
    }
    
    if (!is_array($postfix)) $postfix = array($postfix);

    if (!$confirm) PlaceJS();
    
    switch ($action) {
	case "drop":
	    if ($confirm) {
		try {
		    $cache = new CACHEDB();
		    foreach ($postfix as $p) {
			$cache->Drop($p);
		    }
		    echo translate("Done. All CACHES are droped.");
		} catch (ADEIException $ae) {
		    ?><span class="error"><?echo translate("Error: %s", $ae->getInfo());?></span><?
		}
	    } else RequestConfirmation(
		translate("Do you really want to drop following tables: "),
		$postfix);
	    break;
	case "rewidth":
	    if ($confirm) {
		try {
		    $name = GetAdminFile("resize-");
		    $f = fopen($name, "w");
		    if (!$f)
			throw new ADEIException(translate('Error creating temporary file: %s', $name));
		    
		    fwrite ($f, '<?php
			require(dirname($_SERVER[\'SCRIPT_FILENAME\']) . "/../../adei.php");
			try {
			    $cache = new CACHEDB();
		    ');
		    foreach ($postfix as $p) {
			fwrite($f, '$cache->Rewidth("' . $p . '", true);' . "\n");
		    }
		    fwrite($f, '
			} catch (ADEIException $ae) {
			    echo translate("Error: %s", $ae->getInfo()) . "\n";
			    exit;
			}
			echo translate("done...") . "\n";?>');
		    fclose($f);
		    
		    if ($SETUP) {
			echo "Please, login to the server and run: php $name -setup $SETUP";
		    } else {
			echo "Please, login to the server and run: php $name";
		    }

/*
		    $cache = new CACHEDB();
		    foreach ($postfix as $p) {
			$cache->Rewidth($p);
		    }
*/
		} catch (ADEIException $ae) {
		    ?><span class="error"><?echo translate("Error: %s", $ae->getInfo());?></span><?
		}
	    } else RequestConfirmation(
		translate("Do you really want to resize following tables: "),
		$postfix);
	    break;
	default:
	?><span class="error"><?
	    if ($action)
		echo translate("Error: Invalid action \"%s\" is specified", $action);
	    else
		echo translate("Error: Action is not specified");
	?></span><?
    }	
?>