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 1457 2011-06-25 17:18:50Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/tool.php $
16
 * @lastmodified    $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
17
 *
18
 */
19

    
20
// Must include code to stop this file being access directly
21
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
22

    
23
// Load Language file
24
if(LANGUAGE_LOADED) {
25
	if(!file_exists(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php')) {
26
		require_once(WB_PATH.'/modules/droplets/languages/EN.php');
27
	} else {
28
		require_once(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php');
29
	}
30
}
31

    
32
// check if backend.css file needs to be included into the <body></body>
33
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/droplets/backend.css')) {
34
	echo '<style type="text/css">';
35
	include(WB_PATH .'/modules/droplets/backend.css');
36
	echo "\n</style>\n";
37
}
38

    
39
// Get userid for showing admin only droplets or not
40
$loggedin_user = $admin->get_user_id();
41
$loggedin_group = $admin->get_groups_id();
42
$admin_user = ( ($admin->get_home_folder() == '') && ($admin->ami_group_member('1') ) || ($loggedin_user == '1'));
43

    
44
// And... action
45
$admintool_url = ADMIN_URL .'/admintools/index.php';
46

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

    
51
<br />
52
<table summary="" cellpadding="0" cellspacing="0" border="0" width="100%">
53
<tr>
54
	<td valign="bottom" width="50%">
55
		<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>	
56
	</td>
57
	<!-- commentet out the droplets logo for a more similar backend design with other admin tools
58
	<td align="center"><img src="<?php /*echo WB_URL;*/ ?>/modules/droplets/img/droplets_logo.png" border="1" alt=""/></td>
59
	-->
60
	<td valign="top" width="50%" align="right">
61
		<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>
62
		<br /><br />
63
		<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>
64
	</td>
65
</tr>
66
</table>
67
<br />
68

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

    
150
function check_syntax($code) {
151
    return @eval('return true;' . $code);
152
}
153

    
154
function check_unique($name) {
155
	global $database;
156
	$query_droplets = $database->query("SELECT name FROM ".TABLE_PREFIX."mod_droplets WHERE name = '$name'");
157
	return ($query_droplets->numRows() == 1);
158
}
(11-11/13)