Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         droplet
6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.x
13
 * @requirements    PHP 5.2.2 and higher
14
 * @version         $Id: tool.php 1676 2012-04-24 09:16:23Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/tool.php $
16
 * @lastmodified    $Date: 2012-04-24 11:16:23 +0200 (Tue, 24 Apr 2012) $
17
 *
18
 */
19
/* -------------------------------------------------------- */
20
// Must include code to stop this file being accessed directly
21
if(!defined('WB_PATH')) {
22

    
23
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
24
	throw new IllegalFileException();
25
}
26
/* -------------------------------------------------------- */
27

    
28
$msg = array();
29
// Load Language file
30
if(LANGUAGE_LOADED) {
31
	if(!file_exists(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php')) {
32
		require_once(WB_PATH.'/modules/droplets/languages/EN.php');
33
	} else {
34
		require_once(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php');
35
	}
36
}
37

    
38
// check if backend.css file needs to be included into the <body></body>
39
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/droplets/backend.css')) {
40
	echo '<style type="text/css">';
41
	include(WB_PATH .'/modules/droplets/backend.css');
42
	echo "\n</style>\n";
43
}
44

    
45
$temp_dir = '/temp/droplets/';
46
// Get userid for showing admin only droplets or not
47
$loggedin_user = ($admin->ami_group_member('1') ? 1 : $admin->get_user_id());
48
$loggedin_group = $admin->get_groups_id();
49
$admin_user = ( ($admin->get_home_folder() == '') && ($admin->ami_group_member('1') ) || ($loggedin_user == '1'));
50

    
51
// And... action
52
$admintool_url = ADMIN_URL .'/admintools/index.php';
53

    
54
//removes empty entries from the table so they will not be displayed
55
$sql = 'DELETE FROM `'.TABLE_PREFIX.'mod_droplets` ';
56
$sql .= 'WHERE name = \'\' ';
57
if( !$database->query($sql) ) {
58
	$msg[] = $database->get_error();
59
}
60
// if import failed after installation, should be only 1 time
61
$sql = 'SELECT COUNT(`id`) FROM `'.TABLE_PREFIX.'mod_droplets` ';
62
if( !$database->get_one($sql) ) {
63
	include('install.php');
64
}
65
// delete backup folder if possible
66
if(is_writeable(dirname(WB_PATH.$temp_dir))) {
67
 	rm_full_dir ( WB_PATH.$temp_dir );
68
}
69
?><br />
70
<table summary="" cellpadding="0" cellspacing="0" border="0" width="100%">
71
<tr>
72
	<td valign="bottom" width="50%">
73
		<button class="add" type="button" name="add_droplet" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/droplets/add_droplet.php';"><?php echo $TEXT['ADD'].' '.$DR_TEXT['DROPLETS']; ?></button>
74
	</td>
75
	<!-- commentet out the droplets logo for a more similar backend design with other admin tools
76
	<td align="center"><img src="<?php /*echo WB_URL;*/ ?>/modules/droplets/img/droplets_logo.png" border="1" alt=""/></td>
77
	-->
78
	<td valign="top" width="50%" align="right">
79
		<a href="#" onclick="javascript: window.open('<?php echo WB_URL; ?>/modules/droplets/readme/<?php echo $DR_TEXT['README']; ?>','helpwindow','width=700,height=550,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes');"><?php echo $DR_TEXT['HELP']; ?></a>
80
		<br /><br />
81
		<a href="#" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/droplets/backup_droplets.php?id=<?php echo $admin->getIDKEY(999); ?>'"><?php echo $DR_TEXT['BACKUP']; ?></a>
82
	</td>
83
</tr>
84
</table>
85
<br />
86

    
87
<h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$DR_TEXT['DROPLETS']; ?></h2>
88
<?php
89

    
90
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets` ';
91
if (!$admin_user) {
92
	$sql .= 'WHERE `admin_view` <> 1 ';
93
}
94
$sql .= 'ORDER BY `modified_when` DESC';
95
$query_droplets = $database->query($sql);
96
$num_droplets = $query_droplets->numRows();
97
if($num_droplets > 0) {
98
	?>
99
	<table summary="" class="row_0" border="0" cellspacing="0" cellpadding="3" width="100%">
100
	<thead>
101
		<tr>
102
			<td width="3%"></td>
103
			<td width="21%"><?php echo $TEXT['NAME']; ?></td>
104
			<td width="68%"><?php echo $TEXT['DESCRIPTION']; ?></td>
105
			<td width="4%"><?php echo $TEXT['ACTIVE']; ?></td>
106
			<td width="3%"></td>
107
		</tr>
108
	</thead>
109
	<?php
110
	$row = 0;
111
	while($droplet = $query_droplets->fetchRow()) {
112
		$get_modified_user = $database->query("SELECT display_name,username, user_id FROM ".TABLE_PREFIX."users WHERE user_id = '".$droplet['modified_by']."' LIMIT 1");
113
		if($get_modified_user->numRows() > 0) {
114
			$fetch_modified_user = $get_modified_user->fetchRow();
115
			$modified_user = $fetch_modified_user['username'];
116
			$modified_userid = $fetch_modified_user['user_id'];
117
		} else {
118
			$modified_user = $TEXT['UNKNOWN'];
119
			$modified_userid = 0;
120
		}
121
        $iDropletIdKey = $admin->getIDKEY($droplet['id']);
122
		$comments = str_replace(array("\r\n", "\n", "\r"), '<br />', $droplet['comments']);
123
		if (!strpos($comments,"[[")) $comments = "Use: [[".$droplet['name']."]]<br />".$comments;
124
		$comments = str_replace(array("[[", "]]"), array('<b>[[',']]</b>'), $comments);
125
		$valid_code = check_syntax($droplet['code']);
126
		if (!$valid_code === true) $comments = '<font color=\'red\'><strong>'.$DR_TEXT['INVALIDCODE'].'</strong></font><br /><br />'.$comments;
127
		$unique_droplet = check_unique ($droplet['name']);
128
		if ($unique_droplet === false ) {$comments = '<font color=\'red\'><strong>'.$DR_TEXT['NOTUNIQUE'].'</strong></font><br /><br />'.$comments;}
129
		$comments = '<span>'.$comments.'</span>';
130
		?>
131

    
132
		<tr class="row_<?php echo $row; ?>" >
133
			<td >
134
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" title="<?php echo $TEXT['MODIFY']; ?>">
135
					<img src="<?php echo THEME_URL; ?>/images/modify_16.png" border="0" alt="Modify" />
136
				</a>
137
			</td>
138
			<td >
139
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" class="tooltip">
140
							<?php if ($valid_code && $unique_droplet) { ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplet.png" border="0" alt=""/>
141
							<?php } else {  ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/invalid.gif" border="0" title="" alt=""/><?php }  ?>
142
					<?php echo $droplet['name']; ?><?php echo $comments; ?>
143
				</a>
144
			</td>
145
			<td >
146
				<small><?php echo substr($droplet['description'],0,90); ?></small>
147
			</td>
148
			<td >
149
				<b><?php if($droplet['active'] == 1){ echo '<span style="color: green;">'. $TEXT['YES']. '</span>'; } else { echo '<span style="color: red;">'.$TEXT['NO'].'</span>';  } ?></b>
150
			</td>
151
			<td >
152
				<a href="javascript: confirm_link('<?php echo $TEXT['ARE_YOU_SURE']; ?>', '<?php echo WB_URL; ?>/modules/droplets/delete_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>');" title="<?php echo $TEXT['DELETE']; ?>">
153
					<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
154
				</a>
155
			</td>
156
		</tr>
157
		<?php
158
		// Alternate row color (toggle between 0 and 1)
159
		$row = ++$row & 1;
160
	}
161
	?>
162
	</table>
163
	<?php
164
}
165

    
166
function check_syntax($code) {
167
    return @eval('return true;' . $code);
168
}
169

    
170
function check_unique($name) {
171
	global $database;
172
	$retVal = 0;
173
	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'mod_droplets` ';
174
	$sql .= 'WHERE `name` = \''.$name.'\'';
175
	$retVal = intval($database->get_one($sql));
176
	return ($retVal == 1);
177
}
(12-12/15)