| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       *
 
     | 
  
  
    | 
      4
     | 
    
       * @category        module
 
     | 
  
  
    | 
      5
     | 
    
       * @package         droplet
 
     | 
  
  
    | 
      6
     | 
    
       * @author          Ruud Eisinga (Ruud) John (PCWacht),WebsiteBaker Project
 
     | 
  
  
    | 
      7
     | 
    
       * @copyright       2009-2012, WebsiteBaker Org. e.V.
 
     | 
  
  
    | 
      8
     | 
    
       * @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: tool.php 1741 2012-09-07 00:42:30Z Luisehahne $
 
     | 
  
  
    | 
      13
     | 
    
       * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/tool.php $
 
     | 
  
  
    | 
      14
     | 
    
       * @lastmodified    $Date: 2012-09-07 02:42:30 +0200 (Fri, 07 Sep 2012) $
 
     | 
  
  
    | 
      15
     | 
    
       *
 
     | 
  
  
    | 
      16
     | 
    
       */
 
     | 
  
  
    | 
      17
     | 
    
      /* -------------------------------------------------------- */
 
     | 
  
  
    | 
      18
     | 
    
      // Must include code to stop this file being accessed directly
 
     | 
  
  
    | 
      19
     | 
    
      if(!defined('WB_URL')) {
     | 
  
  
    | 
      20
     | 
    
      
 
     | 
  
  
    | 
      21
     | 
    
      	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
 
     | 
  
  
    | 
      22
     | 
    
      	throw new IllegalFileException();
 
     | 
  
  
    | 
      23
     | 
    
      }
 
     | 
  
  
    | 
      24
     | 
    
      /* -------------------------------------------------------- */
 
     | 
  
  
    | 
      25
     | 
    
      
 
     | 
  
  
    | 
      26
     | 
    
      $msg = array();
 
     | 
  
  
    | 
      27
     | 
    
      // 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
     | 
    
      $temp_dir = '/temp/droplets/';
 
     | 
  
  
    | 
      44
     | 
    
      // Get userid for showing admin only droplets or not
 
     | 
  
  
    | 
      45
     | 
    
      $loggedin_user = ($admin->ami_group_member('1') ? 1 : $admin->get_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
     | 
    
      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
     | 
    
      // delete backup folder if possible
 
     | 
  
  
    | 
      64
     | 
    
      if(is_writeable(dirname(WB_PATH.$temp_dir))) {
     | 
  
  
    | 
      65
     | 
    
       	rm_full_dir ( WB_PATH.$temp_dir );
 
     | 
  
  
    | 
      66
     | 
    
      }
 
     | 
  
  
    | 
      67
     | 
    
      ?><div class="droplets" style="margin-top: -6px; border-top: 1px solid #DDD;">
 
     | 
  
  
    | 
      68
     | 
    
      
 
     | 
  
  
    | 
      69
     | 
    
      <table summary="" cellpadding="0" cellspacing="0" border="0" width="100%">
 
     | 
  
  
    | 
      70
     | 
    
      <tr>
 
     | 
  
  
    | 
      71
     | 
    
      	<td valign="bottom" width="50%">
 
     | 
  
  
    | 
      72
     | 
    
      		<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
     | 
    
      	</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
     | 
    
      		<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
     | 
    
      	</td>
 
     | 
  
  
    | 
      82
     | 
    
      </tr>
 
     | 
  
  
    | 
      83
     | 
    
      </table>
 
     | 
  
  
    | 
      84
     | 
    
      <br />
 
     | 
  
  
    | 
      85
     | 
    
      
 
     | 
  
  
    | 
      86
     | 
    
      <h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$DR_TEXT['DROPLETS']; ?></h2>
 
     | 
  
  
    | 
      87
     | 
    
      <?php
 
     | 
  
  
    | 
      88
     | 
    
      
 
     | 
  
  
    | 
      89
     | 
    
      $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets` ';
 
     | 
  
  
    | 
      90
     | 
    
      if (!$admin_user) {
     | 
  
  
    | 
      91
     | 
    
      	$sql .= 'WHERE `admin_view` <> 1 ';
 
     | 
  
  
    | 
      92
     | 
    
      }
 
     | 
  
  
    | 
      93
     | 
    
      $sql .= 'ORDER BY `modified_when` DESC';
 
     | 
  
  
    | 
      94
     | 
    
      $query_droplets = $database->query($sql);
 
     | 
  
  
    | 
      95
     | 
    
      $num_droplets = $query_droplets->numRows();
 
     | 
  
  
    | 
      96
     | 
    
      if($num_droplets > 0) {
     | 
  
  
    | 
      97
     | 
    
      	?>
 
     | 
  
  
    | 
      98
     | 
    
      	<table summary="" class="row_0" border="0" cellspacing="0" cellpadding="3" width="100%">
 
     | 
  
  
    | 
      99
     | 
    
      	<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
     | 
    
      	$row = 0;
 
     | 
  
  
    | 
      110
     | 
    
      	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
     | 
    
              $iDropletIdKey = $admin->getIDKEY($droplet['id']);
 
     | 
  
  
    | 
      121
     | 
    
      		$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
     | 
    
      		if ($unique_droplet === false ) {$comments = '<font color=\'red\'><strong>'.$DR_TEXT['NOTUNIQUE'].'</strong></font><br /><br />'.$comments;}
     | 
  
  
    | 
      128
     | 
    
      		$comments = '<span>'.$comments.'</span>';
 
     | 
  
  
    | 
      129
     | 
    
      		?>
 
     | 
  
  
    | 
      130
     | 
    
      
 
     | 
  
  
    | 
      131
     | 
    
      		<tr class="row_<?php echo $row; ?>" >
 
     | 
  
  
    | 
      132
     | 
    
      			<td >
 
     | 
  
  
    | 
      133
     | 
    
      				<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
     | 
    
      				</a>
 
     | 
  
  
    | 
      136
     | 
    
      			</td>
 
     | 
  
  
    | 
      137
     | 
    
      			<td >
 
     | 
  
  
    | 
      138
     | 
    
      				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $iDropletIdKey; ?>" class="tooltip">
 
     | 
  
  
    | 
      139
     | 
    
      							<?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
     | 
    
      				<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
     | 
    
      					<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
 
     | 
  
  
    | 
      153
     | 
    
      				</a>
 
     | 
  
  
    | 
      154
     | 
    
      			</td>
 
     | 
  
  
    | 
      155
     | 
    
      		</tr>
 
     | 
  
  
    | 
      156
     | 
    
      		<?php
 
     | 
  
  
    | 
      157
     | 
    
      		// Alternate row color (toggle between 0 and 1)
 
     | 
  
  
    | 
      158
     | 
    
      		$row = ++$row & 1;
 
     | 
  
  
    | 
      159
     | 
    
      	}
 
     | 
  
  
    | 
      160
     | 
    
      	?>
 
     | 
  
  
    | 
      161
     | 
    
      	</table>
 
     | 
  
  
    | 
      162
     | 
    
      </div>
 
     | 
  
  
    | 
      163
     | 
    
      	<?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
     | 
    
      	$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
     | 
    
      }
 
     |