Project

General

Profile

1
<?php
2

    
3
// $Id: tool.php 1069 2009-07-15 20:28:15Z Ruebenwurzel $
4

    
5
/*
6
*	@version	1.0
7
*	@author		Ruud Eisinga (Ruud) John (PCWacht)
8
*	@date		June 2009
9
*
10
*	droplets are small codeblocks that are called from anywhere in the template. 
11
* 	To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value&parameter2=value]]
12
*/
13

    
14
// Direct access prevention
15
defined('WB_PATH') OR die(header('Location: ../index.php'));
16

    
17
// Load Language file
18
if(LANGUAGE_LOADED) {
19
	if(!file_exists(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php')) {
20
		require_once(WB_PATH.'/modules/droplets/languages/EN.php');
21
	} else {
22
		require_once(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php');
23
	}
24
}
25

    
26
// check if backend.css file needs to be included into the <body></body>
27
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/droplets/backend.css')) {
28
	echo '<style type="text/css">';
29
	include(WB_PATH .'/modules/droplets/backend.css');
30
	echo "\n</style>\n";
31
}
32

    
33
// Get userid for showing admin only droplets or not
34
$loggedin_user = $admin->get_user_id();
35
	
36
// And... action
37
$admintool_url = ADMIN_URL .'/admintools/index.php';
38

    
39
//removes empty entries from the table so they will not be displayed
40
$database->query("DELETE FROM ".TABLE_PREFIX."mod_droplets WHERE name=''");
41
?>
42

    
43
<br />
44
<table cellpadding="0" cellspacing="0" border="0" width="100%">
45
<tr>
46
	<td valign="bottom" width="30%">
47
		<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>	
48
	</td>
49
	<td align="center"><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplets_logo.png" border="1" alt=""/></td>
50
	<td valign="top" width="30%" align="right">
51
		<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>
52
		<br /><br />
53
		<a href="#" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/droplets/backup_droplets.php';"><?php echo $DR_TEXT['BACKUP']; ?></a>
54
	</td>
55
</tr>
56
</table>
57
<br />
58

    
59
<h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$DR_TEXT['DROPLETS']; ?></h2>
60
<?php
61
if ($loggedin_user == '1') {
62
	$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets ORDER BY modified_when DESC");
63
} else { 
64
	$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets WHERE admin_view <> '1' ORDER BY modified_when DESC");
65
}
66
$num_droplets = $query_droplets->numRows();
67
if($num_droplets > 0) {
68
	?>
69
	<table class="row_a" border="0" cellspacing="0" cellpadding="3" width="100%">
70
	<thead>
71
		<tr>
72
			<td width="3%"></td>
73
			<td width="21%"><?php echo $TEXT['NAME']; ?></td>
74
			<td width="68%"><?php echo $TEXT['DESCRIPTION']; ?></td>
75
			<td width="4%"><?php echo $TEXT['ACTIVE']; ?></td>
76
			<td width="3%"></td>
77
		</tr>
78
	</thead>
79
	<?php
80
	$row = 'a';
81
	while($droplet = $query_droplets->fetchRow()) {
82
		$get_modified_user = $database->query("SELECT display_name,username, user_id FROM ".TABLE_PREFIX."users WHERE user_id = '".$droplet['modified_by']."' LIMIT 1");
83
		if($get_modified_user->numRows() > 0) {
84
			$fetch_modified_user = $get_modified_user->fetchRow();
85
			$modified_user = $fetch_modified_user['username'];
86
			$modified_userid = $fetch_modified_user['user_id'];
87
		} else {
88
			$modified_user = $TEXT['UNKNOWN'];
89
			$modified_userid = 0;
90
		}
91
		$comments = str_replace(array("\r\n", "\n", "\r"), '<br />', $droplet['comments']);
92
		if (!strpos($comments,"[[")) $comments = "Use: [[".$droplet['name']."]]<br />".$comments;
93
		$comments = str_replace(array("[[", "]]"), array('<b>[[',']]</b>'), $comments);
94
		$valid_code = check_syntax($droplet['code']);
95
		if (!$valid_code === true) $comments = '<font color=\'red\'><strong>'.$DR_TEXT['INVALIDCODE'].'</strong></font><br /><br />'.$comments;
96
		$unique_droplet = check_unique ($droplet['name']);
97
		if ($unique_droplet === false) $comments = '<font color=\'red\'><strong>'.$DR_TEXT['NOTUNIQUE'].'</strong></font><br /><br />'.$comments;
98
		$comments = '<span>'.$comments.'</span>';
99
		?>
100
		
101
		<tr class="row_<?php echo $row; ?>" >
102
			<td >
103
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $droplet['id']?>" title="<?php echo $TEXT['MODIFY']; ?>">
104
					<img src="<?php echo THEME_URL; ?>/images/modify_16.png" border="0" alt="Modify" /> 
105
				</a>
106
			</td>
107
			<td >
108
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $droplet['id']?>" class="tooltip">
109
							<?php if ($valid_code && $unique_droplet) { ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplet.png" border="0" alt=""/>
110
							<?php } else {  ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/invalid.gif" border="0" title="" alt=""/><?php }  ?>
111
					<?php echo $droplet['name']; ?><?php echo $comments; ?>
112
				</a>
113
			</td>
114
			<td >
115
				<small><?php echo substr($droplet['description'],0,90); ?></small>
116
			</td>
117
			<td >
118
				<b><?php if($droplet['active'] == 1){ echo '<span style="color: green;">'. $TEXT['YES']. '</span>'; } else { echo '<span style="color: red;">'.$TEXT['NO'].'</span>';  } ?></b>
119
			</td>
120
			<td >
121
				<a href="javascript: confirm_link('<?php echo $TEXT['ARE_YOU_SURE']; ?>', '<?php echo WB_URL; ?>/modules/droplets/delete_droplet.php?droplet_id=<?php echo $droplet['id']?>');" title="<?php echo $TEXT['DELETE']; ?>">
122
					<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
123
				</a>
124
			</td>
125
		</tr>
126
		<?php
127
		// Alternate row color
128
		if($row == 'a') {
129
			$row = 'b';
130
		} else {
131
			$row = 'a';
132
		}
133
	}
134
	?>
135
	</table>
136
	<?php
137
}
138

    
139
function check_syntax($code) {
140
    return @eval('return true;' . $code);
141
}
142

    
143
function check_unique($name) {
144
	global $database;
145
	$query_droplets = $database->query("SELECT name FROM ".TABLE_PREFIX."mod_droplets WHERE name = '$name'");
146
	return ($query_droplets->numRows() == 1);
147
}
148
?>
(11-11/13)