Project

General

Profile

1
<?php
2

    
3
// $Id: tool.php 1122 2009-08-11 16:19:01Z 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="50%">
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
	<!-- commentet out the droplets logo for a more similar backend design with other admin tools
50
	<td align="center"><img src="<?php /*echo WB_URL;*/ ?>/modules/droplets/img/droplets_logo.png" border="1" alt=""/></td>
51
	-->
52
	<td valign="top" width="50%" align="right">
53
		<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>
54
		<br /><br />
55
		<a href="#" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/droplets/backup_droplets.php';"><?php echo $DR_TEXT['BACKUP']; ?></a>
56
	</td>
57
</tr>
58
</table>
59
<br />
60

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

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

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