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 1503 2011-08-18 02:18:59Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/tool.php $
16
 * @lastmodified    $Date: 2011-08-18 04:18:59 +0200 (Thu, 18 Aug 2011) $
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
// Load Language file
29
if(LANGUAGE_LOADED) {
30
	if(!file_exists(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php')) {
31
		require_once(WB_PATH.'/modules/droplets/languages/EN.php');
32
	} else {
33
		require_once(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php');
34
	}
35
}
36

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

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

    
49
// And... action
50
$admintool_url = ADMIN_URL .'/admintools/index.php';
51

    
52
//removes empty entries from the table so they will not be displayed
53
$sql = 'DELETE FROM '.TABLE_PREFIX.'mod_droplets ';
54
$sql .= 'WHERE name = \'\' ';
55
$database->query($sql);
56

    
57
?>
58

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

    
77
<h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$DR_TEXT['DROPLETS']; ?></h2>
78
<?php
79

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

    
122
		<tr class="row_<?php echo $row; ?>" >
123
			<td >
124
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" title="<?php echo $TEXT['MODIFY']; ?>">
125
					<img src="<?php echo THEME_URL; ?>/images/modify_16.png" border="0" alt="Modify" />
126
				</a>
127
			</td>
128
			<td >
129
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" class="tooltip">
130
							<?php if ($valid_code && $unique_droplet) { ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplet.png" border="0" alt=""/>
131
							<?php } else {  ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/invalid.gif" border="0" title="" alt=""/><?php }  ?>
132
					<?php echo $droplet['name']; ?><?php echo $comments; ?>
133
				</a>
134
			</td>
135
			<td >
136
				<small><?php echo substr($droplet['description'],0,90); ?></small>
137
			</td>
138
			<td >
139
				<b><?php if($droplet['active'] == 1){ echo '<span style="color: green;">'. $TEXT['YES']. '</span>'; } else { echo '<span style="color: red;">'.$TEXT['NO'].'</span>';  } ?></b>
140
			</td>
141
			<td >
142
				<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']; ?>">
143
					<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
144
				</a>
145
			</td>
146
		</tr>
147
		<?php
148
		// Alternate row color
149
		if($row == 'a') {
150
			$row = 'b';
151
		} else {
152
			$row = 'a';
153
		}
154
	}
155
	?>
156
	</table>
157
	<?php
158
}
159

    
160
function check_syntax($code) {
161
    return @eval('return true;' . $code);
162
}
163

    
164
function check_unique($name) {
165
	global $database;
166
	$retVal = 0;
167
	$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'mod_droplets` ';
168
	$sql .= 'WHERE `name` = \''.$name.'\'';
169
	$retVal = intval($database->get_one($sql));
170
	return ($retVal == 1);
171
}
(12-12/14)