summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbitweaver.org <bitweaver@users.sourceforge.net>2005-06-19 05:02:20 +0000
committerbitweaver.org <bitweaver@users.sourceforge.net>2005-06-19 05:02:20 +0000
commit9896c8e5b5aa9b110bea5c4dbc438525489e15c0 (patch)
treecb1237f32a289854859c5ca4930074f60d639d45
downloadquota-9896c8e5b5aa9b110bea5c4dbc438525489e15c0.tar.gz
quota-9896c8e5b5aa9b110bea5c4dbc438525489e15c0.tar.bz2
quota-9896c8e5b5aa9b110bea5c4dbc438525489e15c0.zip
IMPORT TikiPro CLYDE FINAL
-rw-r--r--LibertyQuota.php244
-rw-r--r--admin/admin_quota_inc.php50
-rw-r--r--admin/schema_inc.php76
-rw-r--r--bit_setup_inc.php9
-rw-r--r--icons/pkg_quota.pngbin0 -> 3932 bytes
-rw-r--r--index.php44
-rw-r--r--templates/admin_quota.tpl80
-rw-r--r--templates/quota.tpl35
8 files changed, 538 insertions, 0 deletions
diff --git a/LibertyQuota.php b/LibertyQuota.php
new file mode 100644
index 0000000..4d6cc09
--- /dev/null
+++ b/LibertyQuota.php
@@ -0,0 +1,244 @@
+<?php
+/**
+* $Header: /cvsroot/bitweaver/_bit_quota/LibertyQuota.php,v 1.1 2005/06/19 05:02:20 bitweaver Exp $
+*
+* Copyright (c) 2004 bitweaver.org
+* Copyright (c) 2003 tikwiki.org
+* Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
+* All Rights Reserved. See copyright.txt for details and a complete list of authors.
+* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
+*
+* $Id: LibertyQuota.php,v 1.1 2005/06/19 05:02:20 bitweaver Exp $
+*/
+/**
+* Quota class to illustrate best practices when creating a new bitweaver package that
+* builds on core bitweaver functionality, such as the Liberty CMS engine
+*
+* @date created 2004/8/15
+*
+* @author spider <spider@steelsun.com>
+*
+* @version $Revision: 1.1 $ $Date: 2005/06/19 05:02:20 $ $Author: bitweaver $
+*
+* @class LibertyQuota
+*/
+
+
+require_once( LIBERTY_PKG_PATH.'LibertyAttachable.php' );
+
+class LibertyQuota extends LibertyBase {
+ /**
+ * Primary key for our mythical Quota class object & table
+ * @public
+ */
+ var $mQuotaId;
+
+ /**
+ * During initialisation, be sure to call our base constructors
+ **/
+ function LibertyQuota( $pQuotaId=NULL, $pContentId=NULL ) {
+ $this->mQuotaId = $pQuotaId;
+ LibertyBase::LibertyBase();
+ }
+
+
+ /**
+ * Any method named Store inherently implies data will be written to the database
+ * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
+ **/
+ function store( &$pParamHash ) {
+ if( $this->verify( $pParamHash ) ) {
+ $this->mDb->StartTrans();
+ $table = BIT_DB_PREFIX."tiki_quotas";
+ if( $this->mQuotaId ) {
+ $locId = array ( "name" => "quota_id", "value" => $pParamHash['quota_id'] );
+ $result = $this->associateUpdate( $table, $pParamHash['quota_store'], $locId );
+ } else {
+ $this->mQuotaId = $this->GenID( 'tiki_quota_id_seq' );
+ $pParamHash['quota_store']['quota_id'] = $this->mQuotaId;
+ $result = $this->associateInsert( $table, $pParamHash['quota_store'] );
+ }
+ $this->mDb->CompleteTrans();
+ $this->load();
+ }
+ return( count( $this->mErrors ) == 0 );
+ }
+
+ /**
+ * Make sure the data is safe to store
+ * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
+ **/
+ function verify( &$pParamHash ) {
+ if( isset( $pParamHash['description'] ) ) {
+ // insure we don't have column overflow, etc.
+ $pParamHash['quota_store']['description'] = trim( $pParamHash['description'], 0, 160 );
+ }
+ if( !empty( $pParamHash['title'] ) ) {
+ // insure we don't have column overflow, etc.
+ $pParamHash['quota_store']['title'] = substr( trim( $pParamHash['title'] ), 0, 160 );
+ } else {
+ $this->mErrors['title'] = "Your quota needs a title";
+ }
+
+ if( empty( $pParamHash['disk_usage'] ) || !is_numeric( $pParamHash['disk_usage'] ) ) {
+ $this->mErrors['disk_usage'] = "Invalid disk usage quantity";
+ } else {
+ $pParamHash['quota_store']['disk_usage'] = $pParamHash['disk_usage'] * 1000000;
+ }
+
+ if( empty( $pParamHash['monthly_transfer'] ) || !is_numeric( $pParamHash['monthly_transfer'] ) ) {
+ $this->mErrors['monthly_transfer'] = "Invalid disk usage quantity";
+ } else {
+ $pParamHash['quota_store']['monthly_transfer'] = $pParamHash['monthly_transfer'] * 1000000;
+ }
+
+ return( count( $this->mErrors ) == 0 );
+ }
+
+ /**
+ * Load the data from the database
+ * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
+ **/
+ function load() {
+ if( $this->mQuotaId ) {
+ // LibertyContent::load() assumes you have joined already, and will not execute any sql!
+ // This is a significant performance optimization
+ $query = "SELECT tq.* FROM `".BIT_DB_PREFIX."tiki_quotas` tq WHERE tq.`quota_id`=?";
+ $result = $this->query( $query, array( $this->mQuotaId ) );
+ if ( $result && $result->numRows() ) {
+ $this->mInfo = $result->fields;
+ $query = "SELECT ug.`group_id`, ug.* FROM `".BIT_DB_PREFIX."users_groups` ug INNER JOIN `".BIT_DB_PREFIX."tiki_quotas_group_map` tqm ON( ug.`group_id`=tqm.`group_id` ) WHERE tqm.`quota_id`=?";
+ if( $rs = $this->query( $query, array( $this->mQuotaId ) ) ) {
+ $this->mInfo['quota_groups'] = $rs->fields;
+ }
+ }
+ }
+ return( count( $this->mInfo ) == 0 );
+ }
+
+ /**
+ *
+ **/
+ function getList() {
+ $query = "SELECT tq.`quota_id`, tq.* FROM `".BIT_DB_PREFIX."tiki_quotas` tq";
+ $ret = $this->GetAssoc($query);
+ return ( $ret );
+ }
+
+ /**
+ *
+ **/
+ function getQuotaMenu( $pName='quota_menu', $pSelectId=NULL ) {
+ $query = "SELECT tq.`title`, tq.`quota_id` FROM `".BIT_DB_PREFIX."tiki_quotas` tq";
+ if( $rs = $this->query($query) ) {
+ $ret = $rs->GetMenu2( $pName, $pSelectId );
+ }
+ return ( $ret );
+ }
+
+ function getQuotaGroups() {
+ $sql = "SELECT ug.`group_id`, ug.*, tqm.`quota_id`
+ FROM `".BIT_DB_PREFIX."users_groups` ug LEFT OUTER JOIN `".BIT_DB_PREFIX."tiki_quotas_group_map` tqm ON( tqm.`group_id`=ug.`group_id` )
+ WHERE ug.`user_id`=".ROOT_USER_ID."
+ ORDER BY ug.`group_name` ASC";
+ return $this->mDb->GetAssoc( $sql );
+ }
+
+
+
+ /**
+ *
+ **/
+ function assignQuotaToGroup( $pQuotaId, $pGroupId ) {
+ if( is_numeric( $pQuotaId ) && is_numeric( $pGroupId ) ) {
+ $hasRow = $this->GetOne( 'SELECT `quota_id` FROM `'.BIT_DB_PREFIX.'tiki_quotas_group_map` WHERE `group_id`=?',array( $pGroupId ) );
+ if( $hasRow ) {
+ $query = 'UPDATE `'.BIT_DB_PREFIX.'tiki_quotas_group_map` SET `quota_id`=? WHERE `group_id`=?';
+ $rs = $this->query( $query, array( $pQuotaId, $pGroupId ) );
+ } else {
+ $query = 'INSERT INTO `'.BIT_DB_PREFIX.'tiki_quotas_group_map` (`quota_id`, `group_id`) VALUES (?,?)';
+ $rs = $this->query( $query, array( $pQuotaId, $pGroupId ) );
+ }
+ } elseif( is_numeric( $pGroupId ) && empty( $pQuotaId ) ) {
+ $query = 'DELETE FROM `'.BIT_DB_PREFIX.'tiki_quotas_group_map` WHERE `group_id`=?';
+ $rs = $this->query( $query, array( $pGroupId ) );
+ }
+ }
+
+
+ /**
+ * returns the quota and consumption if a user is under usage level
+ **/
+ function isUserUnderQuota( $pUserId ) {
+ $ret = FALSE;
+ if( is_numeric( $pUserId) ) {
+ $query = 'SELECT MAX(tq.`disk_usage`) AS `disk_usage`
+ FROM `'.BIT_DB_PREFIX.'users_users` uu
+ INNER JOIN `'.BIT_DB_PREFIX.'users_groups_map` ugm ON ( ugm.`user_id`=uu.`user_id` )
+ INNER JOIN `'.BIT_DB_PREFIX.'tiki_quotas_group_map` tqm ON( tqm.`group_id`=ugm.`group_id` )
+ INNER JOIN `'.BIT_DB_PREFIX.'tiki_quotas` tq ON( tq.`quota_id`=tqm.`quota_id` )
+ WHERE uu.`user_id`=?';
+ if( $rs = $this->query( $query, array( $pUserId ) ) ) {
+ $diskQuota = $rs->fields['disk_usage'];
+ $diskConsumed = $this->getUserUsage( $pUserId );
+ if( $diskQuota > $diskConsumed ) {
+ $ret = array($diskQuota, $diskConsumed);
+ }
+ }
+ }
+ return $ret;
+ }
+
+
+ /**
+ * Given a user_id, this will return the max quota for the given user. If the user belongs to more than one group, it will chose the max values
+ * @param pUserId user_id of the user for usage to be calculated for
+ * @returns an integer of the total bytes used
+ */
+ function getUserQuota( $pUserId ) {
+ $ret = 0;
+ if( is_numeric( $pUserId ) ) {
+ $query = 'SELECT MAX(tq.`disk_usage`) AS `disk_usage`
+ FROM `'.BIT_DB_PREFIX.'users_users` uu
+ INNER JOIN `'.BIT_DB_PREFIX.'users_groups_map` ugm ON ( ugm.`user_id`=uu.`user_id` )
+ INNER JOIN `'.BIT_DB_PREFIX.'tiki_quotas_group_map` tqm ON( tqm.`group_id`=ugm.`group_id` )
+ INNER JOIN `'.BIT_DB_PREFIX.'tiki_quotas` tq ON( tq.`quota_id`=tqm.`quota_id` )
+ WHERE uu.`user_id`=?';
+ $ret = $this->getOne( $query, array( $pUserId ) );
+ }
+ return $ret;
+ }
+
+ /**
+ * Given a user_id, this will return this disk space used for the given user
+ * @param pUserId user_id of the user for usage to be calculated for
+ * @returns an integer of the total bytes used
+ */
+ function getUserUsage( $pUserId ) {
+ $ret = 0;
+ if( is_numeric( $pUserId ) ) {
+ $ret = $this->getOne( "SELECT SUM(`size`) FROM `".BIT_DB_PREFIX."tiki_files` WHERE `user_id`=?", array( $pUserId ) );
+ }
+ return $ret;
+ }
+
+ /**
+ * Generates the URL to the quota page
+ * @param pExistsHash the hash that was returned by LibertyContent::pageExists
+ * @return the link to display the page.
+ */
+ function getDisplayUrl() {
+ $ret = NULL;
+ if( !empty( $this->mQuotaId ) ) {
+ $ret = QUOTA_PKG_URL."index.php?quota_id=".$this->mQuotaId;
+ }
+ return $ret;
+ }
+
+ function isValid() {
+ return( !empty( $this->mQuotaId ) );
+ }
+
+}
+
+?>
diff --git a/admin/admin_quota_inc.php b/admin/admin_quota_inc.php
new file mode 100644
index 0000000..af2e6c7
--- /dev/null
+++ b/admin/admin_quota_inc.php
@@ -0,0 +1,50 @@
+<?php
+// $Header: /cvsroot/bitweaver/_bit_quota/admin/admin_quota_inc.php,v 1.1 2005/06/19 05:02:20 bitweaver Exp $
+// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+if (isset($_REQUEST["quotaset"]) && isset($_REQUEST["homeSample"])) {
+ $gBitSystem->storePreference("home_quota", $_REQUEST["homeSample"]);
+ $smarty->assign('home_quota', $_REQUEST["homeSample"]);
+}
+
+require_once( QUOTA_PKG_PATH.'LibertyQuota.php' );
+
+if( !empty( $_REQUEST['cancelquota'] ) ) {
+ unset( $_REQUEST['quota_id'] );
+}
+
+$gQuota = new LibertyQuota( !empty( $_REQUEST['quota_id'] ) ? $_REQUEST['quota_id'] : NULL );
+
+if( !empty( $_REQUEST['savequota'] ) ) {
+ if( $gQuota->store( $_REQUEST ) ) {
+ header( 'Location: '.KERNEL_PKG_URL.'admin/index.php?page=quota' );
+ die;
+ } else {
+ $saveError = TRUE;
+ $smarty->assign_by_ref( 'errors', $gQuota->mErrors );
+ }
+} elseif( !empty( $_REQUEST['assignquota'] ) ) {
+ foreach( array_keys( $_REQUEST ) as $key ) {
+ if( preg_match( '/^quota_group_([-0-9]*)/', $key, $match ) ) {
+ $groupId = $match[1];
+ $gQuota->assignQuotaToGroup( $_REQUEST[$key], $groupId );
+//vd( $match );
+ }
+ }
+}
+$gQuota->load();
+if( $gQuota->isValid() || isset( $_REQUEST['newquota'] ) || !empty( $saveError ) ) {
+ $smarty->assign_by_ref('gQuota', $gQuota);
+} else {
+ $quotas = $gQuota->getList();
+ $systemGroups = $gQuota->getQuotaGroups();
+ $smarty->assign_by_ref('systemGroups', $systemGroups );
+foreach( array_keys( $systemGroups ) as $groupId ) {
+ $groupQuota[$groupId] = $gQuota->getQuotaMenu( 'quota_group_'.$groupId, $systemGroups[$groupId]['quota_id'] );
+}
+ $smarty->assign_by_ref('groupQuota', $groupQuota );
+ $smarty->assign_by_ref('quotaList', $quotas);
+}
+
+?>
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
new file mode 100644
index 0000000..64a0a53
--- /dev/null
+++ b/admin/schema_inc.php
@@ -0,0 +1,76 @@
+<?php
+
+$tables = array(
+
+'users_quota_units' => "
+ user_id I4 PRIMARY,
+ units I4 NOTNULL
+",
+
+'tiki_quotas' => "
+ quota_id I4 PRIMARY,
+ disk_usage I8,
+ monthly_transfer I8,
+ title C(160) NOTNULL,
+ description X
+",
+
+'tiki_quotas_group_map' => "
+ quota_id I4 PRIMARY,
+ group_id I4 PRIMARY
+ CONSTRAINTS ', CONSTRAINT `tiki_quotas_group_ref` FOREIGN KEY (`group_id`) REFERENCES `".BIT_DB_PREFIX."users_groups`( `group_id` )
+ , CONSTRAINT `tiki_quotas_map_ref` FOREIGN KEY (`quota_id`) REFERENCES `".BIT_DB_PREFIX."tiki_quotas`( `quota_id` )'
+",
+
+);
+
+global $gBitInstaller;
+
+$gBitInstaller->makePackageHomeable('quota');
+
+foreach( array_keys( $tables ) AS $tableName ) {
+ $gBitInstaller->registerSchemaTable( QUOTA_PKG_DIR, $tableName, $tables[$tableName] );
+}
+
+$gBitInstaller->registerPackageInfo( QUOTA_PKG_DIR, array(
+ 'description' => "Quota system limits user disk and bandwidth usage for Liberty content",
+ 'license' => '<a href="http://www.gnu.org/licenses/licenses.html#LGPL">LGPL</a>',
+ 'version' => '0.1',
+ 'state' => 'beta',
+ 'dependencies' => 'liberty',
+) );
+
+// ### Indexes
+$indices = array (
+ 'tiki_quotas_group_idx' => array( 'table' => 'tiki_quotas_group_map', 'cols' => 'group_id', 'opts' => array( 'UNIQUE' ) ),
+);
+$gBitInstaller->registerSchemaIndexes( QUOTA_PKG_DIR, $indices );
+
+// ### Sequences
+$sequences = array (
+ 'tiki_quota_id_seq' => array( 'start' => 3 )
+);
+$gBitInstaller->registerSchemaSequences( QUOTA_PKG_DIR, $sequences );
+
+$gBitInstaller->registerSchemaDefault( QUOTA_PKG_DIR, array(
+
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_quotas` ( `quota_id`, `disk_usage`, `monthly_transfer`, `title`, `description` ) VALUES ('1', 2000000, 20000000, 'Free Trial', 'A little space to try out site features' )",
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_quotas` ( `quota_id`, `disk_usage`, `monthly_transfer`, `title`, `description` ) VALUES ('2', 10000000, 100000000, 'Site Supporters', 'Extra space for site supporters.' )",
+
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_quotas_group_map` ( `quota_id`, `group_id` ) VALUES ( 1, 3 )",
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_quotas_group_map` ( `quota_id`, `group_id` ) VALUES ( 2, 2 )",
+
+
+ "INSERT INTO `".BIT_DB_PREFIX."users_permissions` (`perm_name`, `perm_desc`, `level`, `package`) VALUES ('bit_p_create_quota', 'Can create a quota', 'registered', 'quota')",
+ "INSERT INTO `".BIT_DB_PREFIX."users_permissions` (`perm_name`, `perm_desc`, `level`, `package`) VALUES ('bit_p_quota_edit', 'Can edit any quota', 'editors', 'quota')",
+ "INSERT INTO `".BIT_DB_PREFIX."users_permissions` (`perm_name`, `perm_desc`, `level`, `package`) VALUES ('bit_p_quota_admin', 'Can admin quota', 'editors', 'quota')",
+ "INSERT INTO `".BIT_DB_PREFIX."users_permissions` (`perm_name`, `perm_desc`, `level`, `package`) VALUES ('bit_p_read_quota', 'Can read quota', 'basic', 'quota')",
+
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_preferences`(`package`,`name`,`value`) VALUES ('quota', 'quota_default_ordering','title_desc')",
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_preferences`(`package`,`name`,`value`) VALUES ('quota', 'quota_list_content_id','y')",
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_preferences`(`package`,`name`,`value`) VALUES ('quota', 'quota_list_title','y')",
+ "INSERT INTO `".BIT_DB_PREFIX."tiki_preferences`(`package`,`name`,`value`) VALUES ('quota', 'quota_list_description','y')",
+
+
+) );
+?>
diff --git a/bit_setup_inc.php b/bit_setup_inc.php
new file mode 100644
index 0000000..e7c6799
--- /dev/null
+++ b/bit_setup_inc.php
@@ -0,0 +1,9 @@
+<?php
+global $gBitSystem, $smarty;
+$gBitSystem->registerPackage( 'quota', dirname( __FILE__).'/' );
+
+if( $gBitSystem->isPackageActive( 'quota' ) ) {
+
+}
+
+?>
diff --git a/icons/pkg_quota.png b/icons/pkg_quota.png
new file mode 100644
index 0000000..b798826
--- /dev/null
+++ b/icons/pkg_quota.png
Binary files differ
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..2913f4f
--- /dev/null
+++ b/index.php
@@ -0,0 +1,44 @@
+<?php
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2004, bitweaver.org
+// +----------------------------------------------------------------------+
+// | All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
+// |
+// | For comments, please use phpdocu.sourceforge.net documentation standards!!!
+// | -> see http://phpdocu.sourceforge.net/
+// +----------------------------------------------------------------------+
+// | Authors: spider <spider@steelsun.com>
+// +----------------------------------------------------------------------+
+//
+// $Id: index.php,v 1.1 2005/06/19 05:02:20 bitweaver Exp $
+
+require_once( '../bit_setup_inc.php' );
+
+$gBitSystem->verifyPackage( 'quota' );
+
+require_once( QUOTA_PKG_PATH.'LibertyQuota.php' );
+
+$quota = new LibertyQuota();
+$diskUsage = $quota->getUserUsage( $gBitUser->mUserId );
+$diskQuota = $quota->getUserQuota( $gBitUser->mUserId );
+
+if( $diskQuota != 0 ) {
+ $quotaPercent = round( (($diskUsage / $diskQuota) * 100), 0 );
+} else {
+ $quotaPercent = 0;
+}
+
+if( $quotaPercent > 100 ) {
+ $errors['disk_quota'] = "You are over your disk quota.";
+ $smarty->assign_by_ref( 'errors', $errors );
+ $quotaPercent = 100;
+}
+
+$smarty->assign( 'usage', round( ($diskUsage / 1000000), 2 ) );
+$smarty->assign( 'quota', round( ($diskQuota / 1000000), 2 ) );
+$smarty->assign_by_ref( 'quotaPercent', $quotaPercent );
+
+$gBitSystem->display( 'bitpackage:quota/quota.tpl', 'View Quota' );
+
+?>
diff --git a/templates/admin_quota.tpl b/templates/admin_quota.tpl
new file mode 100644
index 0000000..e2a3a98
--- /dev/null
+++ b/templates/admin_quota.tpl
@@ -0,0 +1,80 @@
+{strip}
+{if $quotaList}
+ {form legend="Assign Quota to Groups"}
+ <input type="hidden" name="page" value="{$page}" />
+
+ {formfeedback error=`$errors.group`}
+
+ <div class="row">
+ {formlabel label="Group" for=""}
+ {forminput}
+ <strong>{tr}Quota{/tr}</strong>
+ {/forminput}
+ </div>
+ {foreach item=grp key=groupId from=$systemGroups}
+ <div class="row">
+ {formlabel label=$grp.group_name for=""}
+ {forminput}
+ {$groupQuota.$groupId}
+ {/forminput}
+ </div>
+ {/foreach}
+
+ <div class="row submit">
+ <input type="submit" name="assignquota" value="{tr}Assign quota{/tr}" />
+ </div>
+ {/form}
+
+ <a href="{$smarty.server.PHP_SELF}?page=quota&newquota=1">{tr}Create New Quota{/tr}</a>
+ <table class="data">
+ <caption>{tr}Defined Quotas{/tr}</caption>
+ <tr>
+ <th>{tr}Quota{/tr}</th>
+ <th>{tr}Disk Usage{/tr}</th>
+ <th>{tr}Monthly Transfer{/tr}</th>
+ </tr>
+ {foreach key=quotaId item=quota from=$quotaList}
+ <tr class="{cycle values=odd,even}">
+ <td><a href="{$smarty.server.PHP_SELF}?page=quota&quota_id={$quotaId}">{$quota.title}</a></td>
+ <td align="right">{$quota.disk_usage/1000000} MB</td>
+ <td align="right">{$quota.monthly_transfer/1000000} MB</td>
+ </tr>
+ {/foreach}
+ </table>
+{else}
+ {assign var=editLabel value=$gQuota->mInfo.title|default:"New Quota"}
+ {form legend="Edit `$editLabel`"}
+ <input type="hidden" name="page" value="{$page}" />
+ <input type="hidden" name="quota_id" value="{$gQuota->mQuotaId}" />
+ <div class="row">
+ {formfeedback error=`$errors.title`}
+ {formlabel label="Quota Title" for="title"}
+ {forminput}
+ <input size="40" type="text" name="title" id="title" value="{$gQuota->mInfo.title|escape}" />
+ {formhelp note="This title is used to identify the quota limitations when you assign them to users and groups."}
+ {/forminput}
+ </div>
+ <div class="row">
+ {formfeedback error=`$errors.disk_usage`}
+ {formlabel label="Disk Usage" for="disk_usage"}
+ {forminput}
+ <input size="10" type="text" name="disk_usage" id="disk_usage" value="{$gQuota->mInfo.disk_usage/1000000}" />
+ {formhelp note="Please enter the desired value in MegaBytes."}
+ {/forminput}
+ </div>
+ <div class="row">
+ {formfeedback error=`$errors.monthly_transfer`}
+ {formlabel label="Monthly Transfer" for="monthly_transfer"}
+ {forminput}
+ <input size="10" type="text" name="monthly_transfer" id="monthly_transfer" value="{$gQuota->mInfo.monthly_transfer/1000000}" />
+ {formhelp note="Please enter the desired value in MegaBytes."}
+ {/forminput}
+ </div>
+
+ <div class="row submit">
+ <input type="submit" name="cancelquota" value="{tr}Cancel{/tr}" />&nbsp;
+ <input type="submit" name="savequota" value="{tr}Save quota{/tr}" />
+ </div>
+ {/form}
+{/if}
+{/strip}
diff --git a/templates/quota.tpl b/templates/quota.tpl
new file mode 100644
index 0000000..07ba1ce
--- /dev/null
+++ b/templates/quota.tpl
@@ -0,0 +1,35 @@
+<div class="quota">
+ <div class="header">
+ <h1>{tr}Usage Quota{/tr}</h1>
+ </div>
+
+ <div class="body">
+ {legend legend="Your Personal Usage Quota"}
+ {if $gBitUser->isAdmin()}
+ Administrators have no enforced quota limit
+ {else}
+ {formfeedback error=$errors.disk_quota}
+
+ <div class="row">
+ {formlabel label="Your disk quota"}
+ {forminput}
+ {formfeedback note="$quota MB"}
+ {/forminput}
+ </div>
+
+ <div class="row">
+ {formlabel label="Your current usage"}
+ {forminput}
+ {formfeedback note="$usage MB <small>( `$quotaPercent`% )</small>"}
+ {/forminput}
+ </div>
+
+ <div class="row">
+ <div style="border:1px solid #ccc;background:#eee;">
+ <div style="width:{$quotaPercent}%;background:#f80;text-align:left;color:#000;line-height:30px;"><small>{$quotaPercent}%</small></div>
+ </div>
+ </div>
+ {/if}
+ {/legend}
+ </div> <!-- end .body -->
+</div> <!-- end .fisheye -->