| 1 | 1420 | Luisehahne | <?php
 | 
      
        | 2 |  |  | /**
 | 
      
        | 3 |  |  |  *
 | 
      
        | 4 |  |  |  * @category        module
 | 
      
        | 5 |  |  |  * @package         droplet
 | 
      
        | 6 | 1741 | Luisehahne |  * @author          Ruud Eisinga (Ruud) John (PCWacht),WebsiteBaker Project
 | 
      
        | 7 |  |  |  * @copyright       2009-2012, WebsiteBaker Org. e.V.
 | 
      
        | 8 | 1420 | Luisehahne |  * @link			http://www.websitebaker2.org/
 | 
      
        | 9 |  |  |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
      
        | 10 |  |  |  * @platform        WebsiteBaker 2.8.x
 | 
      
        | 11 |  |  |  * @requirements    PHP 5.2.2 and higher
 | 
      
        | 12 |  |  |  * @version         $Id$
 | 
      
        | 13 |  |  |  * @filesource		$HeadURL$
 | 
      
        | 14 |  |  |  * @lastmodified    $Date$
 | 
      
        | 15 |  |  |  *
 | 
      
        | 16 |  |  |  */
 | 
      
        | 17 | 1503 | Luisehahne | /* -------------------------------------------------------- */
 | 
      
        | 18 |  |  | // Must include code to stop this file being accessed directly
 | 
      
        | 19 | 1741 | Luisehahne | if(!defined('WB_URL')) {
 | 
      
        | 20 | 1420 | Luisehahne | 
 | 
      
        | 21 | 1503 | Luisehahne | 	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
 | 
      
        | 22 |  |  | 	throw new IllegalFileException();
 | 
      
        | 23 |  |  | }
 | 
      
        | 24 |  |  | /* -------------------------------------------------------- */
 | 
      
        | 25 | 1420 | Luisehahne | 
 | 
      
        | 26 | 1543 | Luisehahne | $msg = array();
 | 
      
        | 27 | 1420 | Luisehahne | // Load Language file
 | 
      
        | 28 |  |  | if(LANGUAGE_LOADED) {
 | 
      
        | 29 |  |  | 	if(!file_exists(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php')) {
 | 
      
        | 30 |  |  | 		require_once(WB_PATH.'/modules/droplets/languages/EN.php');
 | 
      
        | 31 |  |  | 	} else {
 | 
      
        | 32 |  |  | 		require_once(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php');
 | 
      
        | 33 |  |  | 	}
 | 
      
        | 34 |  |  | }
 | 
      
        | 35 |  |  | 
 | 
      
        | 36 |  |  | // check if backend.css file needs to be included into the <body></body>
 | 
      
        | 37 |  |  | if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/droplets/backend.css')) {
 | 
      
        | 38 |  |  | 	echo '<style type="text/css">';
 | 
      
        | 39 |  |  | 	include(WB_PATH .'/modules/droplets/backend.css');
 | 
      
        | 40 |  |  | 	echo "\n</style>\n";
 | 
      
        | 41 |  |  | }
 | 
      
        | 42 |  |  | 
 | 
      
        | 43 | 1676 | Luisehahne | $temp_dir = '/temp/droplets/';
 | 
      
        | 44 | 1420 | Luisehahne | // Get userid for showing admin only droplets or not
 | 
      
        | 45 | 1676 | Luisehahne | $loggedin_user = ($admin->ami_group_member('1') ? 1 : $admin->get_user_id());
 | 
      
        | 46 | 1457 | Luisehahne | $loggedin_group = $admin->get_groups_id();
 | 
      
        | 47 |  |  | $admin_user = ( ($admin->get_home_folder() == '') && ($admin->ami_group_member('1') ) || ($loggedin_user == '1'));
 | 
      
        | 48 |  |  | 
 | 
      
        | 49 | 1420 | Luisehahne | // 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 | 1543 | Luisehahne | $sql = 'DELETE FROM `'.TABLE_PREFIX.'mod_droplets` ';
 | 
      
        | 54 | 1503 | Luisehahne | $sql .= 'WHERE name = \'\' ';
 | 
      
        | 55 | 1543 | Luisehahne | if( !$database->query($sql) ) {
 | 
      
        | 56 |  |  | 	$msg[] = $database->get_error();
 | 
      
        | 57 |  |  | }
 | 
      
        | 58 |  |  | // if import failed after installation, should be only 1 time
 | 
      
        | 59 |  |  | $sql = 'SELECT COUNT(`id`) FROM `'.TABLE_PREFIX.'mod_droplets` ';
 | 
      
        | 60 |  |  | if( !$database->get_one($sql) ) {
 | 
      
        | 61 |  |  | 	include('install.php');
 | 
      
        | 62 |  |  | }
 | 
      
        | 63 | 1676 | Luisehahne | // delete backup folder if possible
 | 
      
        | 64 |  |  | if(is_writeable(dirname(WB_PATH.$temp_dir))) {
 | 
      
        | 65 |  |  |  	rm_full_dir ( WB_PATH.$temp_dir );
 | 
      
        | 66 |  |  | }
 | 
      
        | 67 | 1741 | Luisehahne | ?><div class="droplets" style="margin-top: -6px; border-top: 1px solid #DDD;">
 | 
      
        | 68 |  |  | 
 | 
      
        | 69 | 1457 | Luisehahne | <table summary="" cellpadding="0" cellspacing="0" border="0" width="100%">
 | 
      
        | 70 | 1420 | Luisehahne | <tr>
 | 
      
        | 71 |  |  | 	<td valign="bottom" width="50%">
 | 
      
        | 72 | 1543 | Luisehahne | 		<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>
 | 
      
        | 73 | 1420 | Luisehahne | 	</td>
 | 
      
        | 74 |  |  | 	<!-- commentet out the droplets logo for a more similar backend design with other admin tools
 | 
      
        | 75 |  |  | 	<td align="center"><img src="<?php /*echo WB_URL;*/ ?>/modules/droplets/img/droplets_logo.png" border="1" alt=""/></td>
 | 
      
        | 76 |  |  | 	-->
 | 
      
        | 77 |  |  | 	<td valign="top" width="50%" align="right">
 | 
      
        | 78 |  |  | 		<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>
 | 
      
        | 79 |  |  | 		<br /><br />
 | 
      
        | 80 | 1457 | Luisehahne | 		<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>
 | 
      
        | 81 | 1420 | Luisehahne | 	</td>
 | 
      
        | 82 |  |  | </tr>
 | 
      
        | 83 |  |  | </table>
 | 
      
        | 84 |  |  | <br />
 | 
      
        | 85 |  |  | 
 | 
      
        | 86 |  |  | <h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$DR_TEXT['DROPLETS']; ?></h2>
 | 
      
        | 87 |  |  | <?php
 | 
      
        | 88 | 1503 | Luisehahne | 
 | 
      
        | 89 |  |  | $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets` ';
 | 
      
        | 90 |  |  | if (!$admin_user) {
 | 
      
        | 91 |  |  | 	$sql .= 'WHERE `admin_view` <> 1 ';
 | 
      
        | 92 | 1420 | Luisehahne | }
 | 
      
        | 93 | 1503 | Luisehahne | $sql .= 'ORDER BY `modified_when` DESC';
 | 
      
        | 94 |  |  | $query_droplets = $database->query($sql);
 | 
      
        | 95 | 1420 | Luisehahne | $num_droplets = $query_droplets->numRows();
 | 
      
        | 96 |  |  | if($num_droplets > 0) {
 | 
      
        | 97 |  |  | 	?>
 | 
      
        | 98 | 1658 | darkviper | 	<table summary="" class="row_0" border="0" cellspacing="0" cellpadding="3" width="100%">
 | 
      
        | 99 | 1420 | Luisehahne | 	<thead>
 | 
      
        | 100 |  |  | 		<tr>
 | 
      
        | 101 |  |  | 			<td width="3%"></td>
 | 
      
        | 102 |  |  | 			<td width="21%"><?php echo $TEXT['NAME']; ?></td>
 | 
      
        | 103 |  |  | 			<td width="68%"><?php echo $TEXT['DESCRIPTION']; ?></td>
 | 
      
        | 104 |  |  | 			<td width="4%"><?php echo $TEXT['ACTIVE']; ?></td>
 | 
      
        | 105 |  |  | 			<td width="3%"></td>
 | 
      
        | 106 |  |  | 		</tr>
 | 
      
        | 107 |  |  | 	</thead>
 | 
      
        | 108 |  |  | 	<?php
 | 
      
        | 109 | 1658 | darkviper | 	$row = 0;
 | 
      
        | 110 | 1420 | Luisehahne | 	while($droplet = $query_droplets->fetchRow()) {
 | 
      
        | 111 |  |  | 		$get_modified_user = $database->query("SELECT display_name,username, user_id FROM ".TABLE_PREFIX."users WHERE user_id = '".$droplet['modified_by']."' LIMIT 1");
 | 
      
        | 112 |  |  | 		if($get_modified_user->numRows() > 0) {
 | 
      
        | 113 |  |  | 			$fetch_modified_user = $get_modified_user->fetchRow();
 | 
      
        | 114 |  |  | 			$modified_user = $fetch_modified_user['username'];
 | 
      
        | 115 |  |  | 			$modified_userid = $fetch_modified_user['user_id'];
 | 
      
        | 116 |  |  | 		} else {
 | 
      
        | 117 |  |  | 			$modified_user = $TEXT['UNKNOWN'];
 | 
      
        | 118 |  |  | 			$modified_userid = 0;
 | 
      
        | 119 |  |  | 		}
 | 
      
        | 120 | 1503 | Luisehahne |         $iDropletIdKey = $admin->getIDKEY($droplet['id']);
 | 
      
        | 121 | 1420 | Luisehahne | 		$comments = str_replace(array("\r\n", "\n", "\r"), '<br />', $droplet['comments']);
 | 
      
        | 122 |  |  | 		if (!strpos($comments,"[[")) $comments = "Use: [[".$droplet['name']."]]<br />".$comments;
 | 
      
        | 123 |  |  | 		$comments = str_replace(array("[[", "]]"), array('<b>[[',']]</b>'), $comments);
 | 
      
        | 124 |  |  | 		$valid_code = check_syntax($droplet['code']);
 | 
      
        | 125 |  |  | 		if (!$valid_code === true) $comments = '<font color=\'red\'><strong>'.$DR_TEXT['INVALIDCODE'].'</strong></font><br /><br />'.$comments;
 | 
      
        | 126 |  |  | 		$unique_droplet = check_unique ($droplet['name']);
 | 
      
        | 127 | 1503 | Luisehahne | 		if ($unique_droplet === false ) {$comments = '<font color=\'red\'><strong>'.$DR_TEXT['NOTUNIQUE'].'</strong></font><br /><br />'.$comments;}
 | 
      
        | 128 | 1420 | Luisehahne | 		$comments = '<span>'.$comments.'</span>';
 | 
      
        | 129 |  |  | 		?>
 | 
      
        | 130 | 1503 | Luisehahne | 
 | 
      
        | 131 | 1420 | Luisehahne | 		<tr class="row_<?php echo $row; ?>" >
 | 
      
        | 132 |  |  | 			<td >
 | 
      
        | 133 | 1503 | Luisehahne | 				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" title="<?php echo $TEXT['MODIFY']; ?>">
 | 
      
        | 134 |  |  | 					<img src="<?php echo THEME_URL; ?>/images/modify_16.png" border="0" alt="Modify" />
 | 
      
        | 135 | 1420 | Luisehahne | 				</a>
 | 
      
        | 136 |  |  | 			</td>
 | 
      
        | 137 |  |  | 			<td >
 | 
      
        | 138 | 1503 | Luisehahne | 				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" class="tooltip">
 | 
      
        | 139 | 1420 | Luisehahne | 							<?php if ($valid_code && $unique_droplet) { ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplet.png" border="0" alt=""/>
 | 
      
        | 140 |  |  | 							<?php } else {  ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/invalid.gif" border="0" title="" alt=""/><?php }  ?>
 | 
      
        | 141 |  |  | 					<?php echo $droplet['name']; ?><?php echo $comments; ?>
 | 
      
        | 142 |  |  | 				</a>
 | 
      
        | 143 |  |  | 			</td>
 | 
      
        | 144 |  |  | 			<td >
 | 
      
        | 145 |  |  | 				<small><?php echo substr($droplet['description'],0,90); ?></small>
 | 
      
        | 146 |  |  | 			</td>
 | 
      
        | 147 |  |  | 			<td >
 | 
      
        | 148 |  |  | 				<b><?php if($droplet['active'] == 1){ echo '<span style="color: green;">'. $TEXT['YES']. '</span>'; } else { echo '<span style="color: red;">'.$TEXT['NO'].'</span>';  } ?></b>
 | 
      
        | 149 |  |  | 			</td>
 | 
      
        | 150 |  |  | 			<td >
 | 
      
        | 151 | 1503 | Luisehahne | 				<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']; ?>">
 | 
      
        | 152 | 1420 | Luisehahne | 					<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
 | 
      
        | 153 |  |  | 				</a>
 | 
      
        | 154 |  |  | 			</td>
 | 
      
        | 155 |  |  | 		</tr>
 | 
      
        | 156 |  |  | 		<?php
 | 
      
        | 157 | 1658 | darkviper | 		// Alternate row color (toggle between 0 and 1)
 | 
      
        | 158 |  |  | 		$row = ++$row & 1;
 | 
      
        | 159 | 1420 | Luisehahne | 	}
 | 
      
        | 160 |  |  | 	?>
 | 
      
        | 161 |  |  | 	</table>
 | 
      
        | 162 | 1741 | Luisehahne | </div>
 | 
      
        | 163 | 1420 | Luisehahne | 	<?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 | 1503 | Luisehahne | 	$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 | 1420 | Luisehahne | }
 |