From c71060dc5e1de38aebdf5d60fea7075ed946c170 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 7 Jul 2010 10:34:47 +0000
Subject: [PATCH] Implemented: FS#556 - See limits in control panel
 Implemented: FS#951 - Dashboard module

---
 interface/web/dashboard/dashboard.php         |  53 ++++--
 interface/web/dashboard/dashlets/limits.php   | 163 ++++++++++++++++++
 interface/web/dashboard/dashlets/modules.php  |  52 ++++++
 .../dashboard/dashlets/templates/limits.htm   |  11 ++
 .../dashboard/dashlets/templates/modules.htm  |  10 ++
 .../dashboard/lib/lang/en_dashlet_limits.lng  |  28 +++
 .../dashboard/lib/lang/en_dashlet_modules.lng |   3 +
 .../web/dashboard/templates/dashboard.htm     |  19 +-
 .../default/css/screen/content_ispc.css       |  30 ++--
 9 files changed, 329 insertions(+), 40 deletions(-)
 create mode 100644 interface/web/dashboard/dashlets/limits.php
 create mode 100644 interface/web/dashboard/dashlets/modules.php
 create mode 100644 interface/web/dashboard/dashlets/templates/limits.htm
 create mode 100644 interface/web/dashboard/dashlets/templates/modules.htm
 create mode 100644 interface/web/dashboard/lib/lang/en_dashlet_limits.lng
 create mode 100644 interface/web/dashboard/lib/lang/en_dashlet_modules.lng

diff --git a/interface/web/dashboard/dashboard.php b/interface/web/dashboard/dashboard.php
index c14e7b8a3..a874affb1 100644
--- a/interface/web/dashboard/dashboard.php
+++ b/interface/web/dashboard/dashboard.php
@@ -99,27 +99,44 @@ if($_SESSION["s"]["user"]["typ"] == 'admin') {
 
 $app->tpl->setloop('info', $info);
 
-/*
- * Show all modules, the user is allowed to use
-*/
-$modules = explode(',', $_SESSION['s']['user']['modules']);
-$mod = array();
-if(is_array($modules)) {
-	foreach($modules as $mt) {
-		if(is_file('../' . $mt . '/lib/module.conf.php')) {
-			if(!preg_match("/^[a-z]{2,20}$/i", $mt)) die('module name contains unallowed chars.');
-			include_once('../' . $mt.'/lib/module.conf.php');
-			/* We don't want to show the dashboard */
-			if ($mt != 'dashboard') {
-				$mod[] = array(	'modules_title' 	=> $app->lng($module['title']),
-						'modules_startpage'	=> $module['startpage'],
-						'modules_name'  	=> $module['name']);
-			}
-		}
+/* Load the dashlets*/
+$dashlet_list = array();
+$handle = @opendir(ISPC_WEB_PATH.'/dashboard/dashlets'); 
+while ($file = @readdir ($handle)) { 
+    if ($file != '.' && $file != '..' && !is_dir($file)) {
+        $dashlet_name = substr($file,0,-4);
+		$dashlet_class = 'dashlet_'.$dashlet_name;
+		include_once(ISPC_WEB_PATH.'/dashboard/dashlets/'.$file);
+		$dashlet_list[$dashlet_name] = new $dashlet_class;
 	}
+}
+
+
+/* Which dashlets in which column */
+/******************************************************************************/
+$leftcol_dashlets = array('modules');
+$rightcol_dashlets = array('limits');
+/******************************************************************************/
+
 
-	$app->tpl->setloop('modules', $mod);
+/* Fill the left column */
+$leftcol = array();
+foreach($leftcol_dashlets as $name) {
+	if(isset($dashlet_list[$name])) {
+		$leftcol[]['content'] = $dashlet_list[$name]->show();
+	}
 }
+$app->tpl->setloop('leftcol', $leftcol);
+
+/* Fill the right columnn */
+$rightcol = array();
+foreach($rightcol_dashlets as $name) {
+	if(isset($dashlet_list[$name])) {
+		$rightcol[]['content'] = $dashlet_list[$name]->show();
+	}
+}
+$app->tpl->setloop('rightcol', $rightcol);
+
 
 //* Do Output
 $app->tpl->pparse();
diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php
new file mode 100644
index 000000000..95e85fd02
--- /dev/null
+++ b/interface/web/dashboard/dashlets/limits.php
@@ -0,0 +1,163 @@
+<?php
+
+class dashlet_limits {
+	
+	function show() {
+		global $app, $conf;
+		
+		$limits = array();
+		
+		/* Limits to be shown*/
+		
+		$limits[] = array('field' => 'limit_maildomain',
+						  'db_table' => 'mail_domain',
+						  'db_where' => '');
+		
+		$limits[] = array('field' => 'limit_mailbox',
+						  'db_table' => 'mail_user',
+						  'db_where' => '');
+		
+		$limits[] = array('field' => 'limit_mailalias',
+						  'db_table' => 'mail_forwarding',
+						  'db_where' => "type = 'alias'");
+		
+		$limits[] = array('field' => 'limit_mailaliasdomain',
+						  'db_table' => 'mail_forwarding',
+						  'db_where' => "type = 'aliasdomain'");
+		
+		$limits[] = array('field' => 'limit_mailforward',
+						  'db_table' => 'mail_forwarding',
+						  'db_where' => "type = 'forward'");
+		
+		$limits[] = array('field' => 'limit_mailcatchall',
+						  'db_table' => 'mail_forwarding',
+						  'db_where' => "type = 'catchall'");
+		
+		$limits[] = array('field' => 'limit_mailrouting',
+						  'db_table' => 'mail_transport',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_mailfilter',
+						  'db_table' => 'mail_user_filter',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_fetchmail',
+						  'db_table' => 'mail_get',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_spamfilter_wblist',
+						  'db_table' => 'spamfilter_wblist',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_spamfilter_user',
+						  'db_table' => 'spamfilter_users',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_spamfilter_policy',
+						  'db_table' => 'spamfilter_policy',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_web_domain',
+						  'db_table' => 'web_domain',
+						  'db_where' => "type = 'vhost'");
+		
+		$limits[] = array('field' => 'limit_web_subdomain',
+						  'db_table' => 'web_domain',
+						  'db_where' => "type = 'subdomain'");
+		
+		$limits[] = array('field' => 'limit_web_aliasdomain',
+						  'db_table' => 'web_domain',
+						  'db_where' => "type = 'aliasdomain'");
+		
+		$limits[] = array('field' => 'limit_ftp_user',
+						  'db_table' => 'ftp_user',
+						  'db_where' => "");
+
+		$limits[] = array('field' => 'limit_shell_user',
+						  'db_table' => 'shell_user',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_dns_zone',
+						  'db_table' => 'dns_soa',
+						  'db_where' => "");
+
+		$limits[] = array('field' => 'limit_dns_record',
+						  'db_table' => 'dns_rr',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_database',
+						  'db_table' => 'web_database',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_cron',
+						  'db_table' => 'cron',
+						  'db_where' => "");
+		
+		$limits[] = array('field' => 'limit_client',
+						  'db_table' => 'client',
+						  'db_where' => "");
+		
+		
+		
+		
+		//* Loading Template
+		$app->uses('tpl,tform');
+		
+		$tpl = new tpl;
+		$tpl->newTemplate("dashlets/templates/limits.htm");
+		
+		$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_limits.lng';
+		include($lng_file);
+		$tpl->setVar($wb);
+		
+		if($app->auth->is_admin()) {
+			$user_is_admin = 1;
+		} else {
+			$user_is_admin = 0;
+		}
+		$tpl->setVar('is_admin',$user_is_admin);
+		
+		if($user_is_admin == 0) {
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			$rows = array();
+			foreach($limits as $limit) {
+				$field = $limit['field'];
+				if($client[$field] != 0) {
+					$value = ($client[$field] == '-1')?$wb['unlimited_txt']:$client[$field];
+					$rows[] = array('field' => $field,
+									'field_txt' => $wb[$field.'_txt'],
+									'value' => $value,
+									'usage' => $this->_get_limit_usage($limit));
+				}
+			}
+			$tpl->setLoop('rows',$rows);
+		}
+		
+		
+		return $tpl->grab();
+		
+	}
+	
+	function _get_limit_usage($limit) {
+		global $app;
+		
+		$sql = "SELECT count(sys_userid) as number FROM ".$limit['db_table']." WHERE ";
+		if($limit['db_where'] != '') $sql .= $limit['db_where']." AND ";
+		$sql .= $app->tform->getAuthSQL('r');
+		$rec = $app->db->queryOneRecord($sql);
+		return $rec['number'];
+		
+	}
+	
+}
+
+
+
+
+
+
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/dashboard/dashlets/modules.php b/interface/web/dashboard/dashlets/modules.php
new file mode 100644
index 000000000..7824cd5a1
--- /dev/null
+++ b/interface/web/dashboard/dashlets/modules.php
@@ -0,0 +1,52 @@
+<?php
+
+class dashlet_modules {
+	
+	function show() {
+		global $app, $conf;
+		
+		//* Loading Template
+		$app->uses('tpl');
+		
+		$tpl = new tpl;
+		$tpl->newTemplate("dashlets/templates/modules.htm");
+		
+		$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_modules.lng';
+		include($lng_file);
+		$tpl->setVar($wb);
+		
+		/*
+		 * Show all modules, the user is allowed to use
+		*/
+		$modules = explode(',', $_SESSION['s']['user']['modules']);
+		$mod = array();
+		if(is_array($modules)) {
+			foreach($modules as $mt) {
+				if(is_file('../' . $mt . '/lib/module.conf.php')) {
+					if(!preg_match("/^[a-z]{2,20}$/i", $mt)) die('module name contains unallowed chars.');
+					include_once('../' . $mt.'/lib/module.conf.php');
+					/* We don't want to show the dashboard */
+					if ($mt != 'dashboard') {
+						$mod[] = array(	'modules_title' 	=> $app->lng($module['title']),
+								'modules_startpage'	=> $module['startpage'],
+								'modules_name'  	=> $module['name']);
+					}
+				}
+			}
+
+			$tpl->setloop('modules', $mod);
+		}
+		
+		return $tpl->grab();
+		
+	}
+}
+
+
+
+
+
+
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/dashboard/dashlets/templates/limits.htm b/interface/web/dashboard/dashlets/templates/limits.htm
new file mode 100644
index 000000000..9a10abd78
--- /dev/null
+++ b/interface/web/dashboard/dashlets/templates/limits.htm
@@ -0,0 +1,11 @@
+	<h2>{tmpl_var name='limits_txt'}</h2>
+	<div style="width:350px;">
+	<table class="list">
+	<tmpl_loop name='rows'>
+		<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
+		  <td>{tmpl_var name='field_txt'}</td>
+		  <td>{tmpl_var name='usage'} {tmpl_var name='of_txt'} {tmpl_var name='value'}</td>
+		</tr>
+	</tmpl_loop>
+	</table>
+	</div>
\ No newline at end of file
diff --git a/interface/web/dashboard/dashlets/templates/modules.htm b/interface/web/dashboard/dashlets/templates/modules.htm
new file mode 100644
index 000000000..03fb8cb88
--- /dev/null
+++ b/interface/web/dashboard/dashlets/templates/modules.htm
@@ -0,0 +1,10 @@
+	<h2>{tmpl_var name='available_modules_txt'}</h2>
+	<div style="width:350px;">
+	<tmpl_loop name='modules'>
+		<div class="dashboard-modules {tmpl_var name='modules_name'}">
+			<a href="#" onclick="capp('{tmpl_var name='modules_name'}')">
+			{tmpl_var name='modules_title'}
+			</a>
+		</div>
+	</tmpl_loop>
+	</div>
\ No newline at end of file
diff --git a/interface/web/dashboard/lib/lang/en_dashlet_limits.lng b/interface/web/dashboard/lib/lang/en_dashlet_limits.lng
new file mode 100644
index 000000000..3154fa1aa
--- /dev/null
+++ b/interface/web/dashboard/lib/lang/en_dashlet_limits.lng
@@ -0,0 +1,28 @@
+<?php
+$wb['limits_txt'] = "Account limits";
+$wb['of_txt'] = "of";
+$wb['unlimited_txt'] = "Unlimited";
+$wb['limit_maildomain_txt'] = "Number of email domains";
+$wb['limit_mailbox_txt'] = "Number of mailboxes";
+$wb["limit_mailalias_txt"] = 'Number of email aliases';
+$wb["limit_mailaliasdomain_txt"] = 'Number of domain aliases';
+$wb["limit_mailforward_txt"] = 'Number of email forwarders';
+$wb["limit_mailcatchall_txt"] = 'Number of email catchall accounts';
+$wb["limit_mailrouting_txt"] = 'Number of email routes';
+$wb["limit_mailfilter_txt"] = 'Number of email filters';
+$wb["limit_fetchmail_txt"] = 'Number of fetchmail accounts';
+$wb["limit_spamfilter_wblist_txt"] = 'Number of spamfilter white / blacklist filters';
+$wb["limit_spamfilter_user_txt"] = 'Number of spamfilter users';
+$wb["limit_spamfilter_policy_txt"] = 'Number of spamfilter policys';
+$wb["limit_cron_txt"] = 'Number of cron jobs';
+$wb["limit_web_domain_txt"] = 'Number of web domains';
+$wb["limit_web_aliasdomain_txt"] = 'Number of web aliasdomains';
+$wb["limit_web_subdomain_txt"] = 'Number of web subdomains';
+$wb["limit_ftp_user_txt"] = 'Number of FTP users';
+$wb["limit_dns_zone_txt"] = 'Number of DNS zones';
+$wb["limit_dns_record_txt"] = 'Number DNS records';
+$wb["limit_shell_user_txt"] = 'Number of Shell users';
+$wb["limit_webdav_user_txt"] = 'Number of Webdav users';
+$wb["limit_client_txt"] = 'Number of Clients';
+$wb["limit_database_txt"] = 'Number of Databases';
+?>
diff --git a/interface/web/dashboard/lib/lang/en_dashlet_modules.lng b/interface/web/dashboard/lib/lang/en_dashlet_modules.lng
new file mode 100644
index 000000000..4bc94f7cb
--- /dev/null
+++ b/interface/web/dashboard/lib/lang/en_dashlet_modules.lng
@@ -0,0 +1,3 @@
+<?php
+$wb['available_modules_txt'] = "Available Modules";
+?>
diff --git a/interface/web/dashboard/templates/dashboard.htm b/interface/web/dashboard/templates/dashboard.htm
index dd46147f9..71e3ee363 100644
--- a/interface/web/dashboard/templates/dashboard.htm
+++ b/interface/web/dashboard/templates/dashboard.htm
@@ -1,6 +1,6 @@
 
 <h1><tmpl_var name="welcome_user"></h1>
-
+<hr />
 <div class="panel panel_dashboard">
 	<div>
 		<tmpl_if name='error'>
@@ -25,15 +25,16 @@
 		</div>
 		</tmpl_if>
 	</div>
+	<div style="float:left; width:350px;">
+	<tmpl_loop name='leftcol'>
+	{tmpl_var name='content'}
+	<p>&nbsp;</p>
+	</tmpl_loop>
+	</div>
+	<div style="float:left; width:350px;">
+	<tmpl_loop name='rightcol'>
+	{tmpl_var name='content'}
 	<p>&nbsp;</p>
-	<h2>{tmpl_var name='available_modules_txt'}</h2>
-	<div style="width:700px;">
-	<tmpl_loop name='modules'>
-		<div class="dashboard-modules {tmpl_var name='modules_name'}">
-			<a href="#" onclick="capp('{tmpl_var name='modules_name'}')">
-			{tmpl_var name='modules_title'}
-			</a>
-		</div>
 	</tmpl_loop>
 	</div>
 </div>
diff --git a/interface/web/themes/default/css/screen/content_ispc.css b/interface/web/themes/default/css/screen/content_ispc.css
index 74f982b5b..db36d661f 100644
--- a/interface/web/themes/default/css/screen/content_ispc.css
+++ b/interface/web/themes/default/css/screen/content_ispc.css
@@ -233,8 +233,8 @@
 	/* Dashboard */
 	.dashboard-modules {
 		float:left;
-		width:100px;
-		height: 100px;
+		width:60px;
+		height: 60px;
 		border:1px dotted #888888;
 		background-color: #cccccc;
 		margin:10px;
@@ -248,20 +248,24 @@
 		display:block;
 		font-weight:bold;
 		height:30px;
-		padding-top:70px;
-		width:100px;
+		padding-top:42px;
+		width:60px;
 		text-decoration: none;
 	}
 
-	.dashboard-modules.admin { background-image: url('../../icons/x64/system.png') !important; }
-	.dashboard-modules.client { background-image: url('../../icons/x64/client.png') !important; }
-	.dashboard-modules.mail { background-image: url('../../icons/x64/email.png') !important; }
-	.dashboard-modules.monitor { background-image: url('../../icons/x64/monitor.png') !important; }
-	.dashboard-modules.dns { background-image: url('../../icons/x64/dns.png') !important; }
-	.dashboard-modules.tools { background-image: url('../../icons/x64/tools.png') !important; }
-	.dashboard-modules.help { background-image: url('../../icons/x64/help.png') !important; }
-	.dashboard-modules.domain { background-image: url('../../icons/x64/domain.png') !important; }
-	.dashboard-modules.sites { background-image: url('../../icons/x64/sites.png') !important; }
+	.dashboard-modules.admin { background-image: url('../../icons/x32/system.png') !important; }
+	.dashboard-modules.client { background-image: url('../../icons/x32/client.png') !important; }
+	.dashboard-modules.mail { background-image: url('../../icons/x32/email.png') !important; }
+	.dashboard-modules.monitor { background-image: url('../../icons/x32/monitor.png') !important; }
+	.dashboard-modules.dns { background-image: url('../../icons/x32/dns.png') !important; }
+	.dashboard-modules.tools { background-image: url('../../icons/x32/tools.png') !important; }
+	.dashboard-modules.help { background-image: url('../../icons/x32/help.png') !important; }
+	.dashboard-modules.domain { background-image: url('../../icons/x32/domain.png') !important; }
+	.dashboard-modules.sites { background-image: url('../../icons/x32/sites.png') !important; }
+	
+	.panel_dashboard h2 {
+		font-size:20px;
+	}
 
 	/* Image-Replacement */
 	.swap { background-repeat:no-repeat; }
-- 
GitLab