diff --git a/include/class-MailboxQuota.php b/include/class-MailboxQuota.php
new file mode 100644
index 0000000..0f07f71
--- /dev/null
+++ b/include/class-MailboxQuota.php
@@ -0,0 +1,76 @@
+.
+
+// load dependent traits
+class_exists( 'Mailbox' );
+
+/**
+ * Methods for a MailboxQuota class
+ */
+trait MailboxQuotaTrait {
+
+ /**
+ * Get the Mailbox quota date
+ *
+ * @return DateTime
+ */
+ public function getMailboxQuotaDate() {
+ return $this->get( 'mailboxquota_date' );
+ }
+
+ /**
+ * Get the Mailbox quota bytes
+ *
+ * @return int
+ */
+ public function getMailboxQuotaBytes() {
+ return $this->get( 'mailboxquota_bytes' );
+ }
+
+ /**
+ * Get the Mailbox quota size readable for humans
+ *
+ * @return string
+ */
+ public function getMailboxQuotaHumanSize() {
+ $size = $this->getMailboxQuotaBytes();
+ return human_filesize( $size );
+ }
+
+ /**
+ * Normalize a MailboxQuota object after being retrieved from database
+ */
+ protected static function normalizeMailboxQuota() {
+ $this->integers( 'mailboxquota_bytes' );
+ $this->datetimes( 'mailboxquota_date' );
+ }
+
+}
+
+/**
+ * Rappresentation of a Mailbox quota size
+ */
+class MailboxQuota extends Queried {
+
+ /**
+ * Constructor
+ */
+ public function __construct() {
+ $this->normalizeMailboxQuota();
+ }
+
+}
diff --git a/include/class-MailboxQuotaAPI.php b/include/class-MailboxQuotaAPI.php
new file mode 100644
index 0000000..966fadd
--- /dev/null
+++ b/include/class-MailboxQuotaAPI.php
@@ -0,0 +1,118 @@
+.
+
+// load dependend traits
+class_exists( 'MailboxAPI' );
+
+/**
+ * Methods for a MailboxQuotaAPI class
+ */
+trait MailboxQuotaAPITrait {
+
+ use MailboxAPITrait;
+
+ /**
+ * Limit to a specific mailbox
+ *
+ * @param object $mailbox MailboxQuota
+ * @return self
+ */
+ public function whereMailboxQuota( $mailbox ) {
+ return $this->whereDomain( $mailbox )
+ ->whereMaiboxUsername( $mailbox->getMailboxQuotaUsername() );
+ }
+
+ /**
+ * Filter a specific MailboxQuota username
+ *
+ * @param string $username MailboxQuota username (without domain name)
+ * @return self
+ */
+ public function whereMailboxQuotaUsername( $username ) {
+ return $this->whereStr( 'mailbox_username', $username );
+ }
+
+ /**
+ * Where the MailboxQuota is Active (or not)
+ *
+ * @param boolean $active If you want the active, or the inactive
+ * @return self
+ */
+ public function whereMailboxQuotaIsActive( $active = true ) {
+ return $this->whereInt( 'mailbox_active', $active );
+ }
+
+ /**
+ * Join mailboxes and domain (once)
+ *
+ * @return self
+ */
+ public function joinMailboxQuotaDomain() {
+ if( empty( $this->joinedMailboxQuotaDomain ) ) {
+ $this->from( 'domain' );
+ $this->equals( 'domain.domain_ID', 'mailbox.domain_ID' );
+
+ $this->joinedMailboxQuotaDomain = true;
+ }
+ return $this;
+ }
+
+ /**
+ * Check if I can edit this mailbox
+ *
+ * Actually it just checks if you can edit the whole domain.
+ *
+ * @return boolean
+ */
+ public function whereMailboxQuotaIsEditable() {
+ return $this->whereDomainIsEditable();
+ }
+
+}
+
+/**
+ * MailboxQuota API
+ */
+class MailboxQuotaAPI extends Query {
+
+ use MailboxQuotaAPITrait;
+
+ /**
+ * Univoque Domain ID column name
+ *
+ * Used by DomainAPITrait
+ */
+ const DOMAIN_ID = 'mailbox.domain_ID';
+
+ /**
+ * Univoque Plan ID column name
+ */
+ const PLAN_ID = 'domain.plan_ID';
+
+ /**
+ * Constructor
+ */
+ public function __construct( $db = null ) {
+
+ // set database and class name
+ parent::__construct( $db, MailboxQuota::class );
+
+ // set database table
+ $this->from( MailboxQuota::T );
+ }
+
+}
diff --git a/template/user.php b/template/user.php
index 339bcfe..766c912 100644
--- a/template/user.php
+++ b/template/user.php
@@ -1,98 +1,111 @@
.
/*
* This is the template for an User
*
* Called from:
* user.php
*
* Available variables:
* $user object|null
* $new_password string|null
* $user_domains object|null (generator)
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
-
-
-
-
-
+valid() ): ?>
= esc_html( __( "Domains" ) ) ?>
- = HTML::a(
$domain->getDomainPermalink(),
esc_html( $domain->getDomainName() )
) ?>
-
+
+
+
+
+
+
+
diff --git a/www/user.php b/www/user.php
index 7156f9f..917fccf 100644
--- a/www/user.php
+++ b/www/user.php
@@ -1,204 +1,209 @@
.
/*
* This is the single User creation/edit page
*/
// load framework
require '../load.php';
// require the permission to see the backend
require_permission( 'backend' );
// wanted informations
$user = null;
// URL paramenters (user_uid)
list( $user_uid ) = url_parts( 1, 0 );
// eventually retrieve mailforward from database
if( $user_uid ) {
$user = ( new UserAPI() )
->whereUserUID( $user_uid )
->whereUserIsEditable()
->queryRow();
// 404
if( !$user || !$user->isUserEditable() ) {
PageNotFound::spawn();
}
} else {
// to create an FTP user, must edit all FTP users
require_permission( 'edit-user-all' );
}
-// save destination action
+// register save User action
if( is_action( 'save-user' ) ) {
$email = $_POST['email'] ?? null;
$uid = $_POST['uid'] ?? null;
$name = $_POST['name'] ?? null;
$surname = $_POST['surname'] ?? null;
if( $email && $uid && $name && $surname ) {
$email = (string) $email;
// data to be saved
$data = [];
$data['user_email'] = $email;
$data['user_name'] = $name;
$data['user_surname'] = $surname;
if( $user ) {
// update existing User
( new UserAPI() )
->whereUser( $user )
->update( $data );
} else {
// insert new User
$data['user_uid'] = $uid;
- $data['user_active'] = 1;
- $data['user_password'] = '!';
- $data['user_role'] = 'user';
+ $data['user_active'] = 0; // disable login as default
+ $data['user_password'] = '!'; // assign an invalid password
+ $data['user_role'] = 'user'; // assign low privileges
$data[] = new DBCol( 'user_registration_date', 'NOW()', '-' );
( new UserAPI() )
->insertRow( $data );
}
+
+ // POST -> redirect -> GET (See Other)
+ http_redirect( User::permalink( $uid ), 303 );
}
}
+// end register Save user action
// add a Domain to the user
if( is_action( 'add-domain' ) ){
// check for permissions
if( !has_permission( 'edit-user-all' ) ) {
error_die( "Not authorized to add a Domain" );
}
// get the Domain by name
$domain_name = $_POST['domain_name'] ?? null;
if( !$domain_name ) {
die( "Please fill that damn Domain name" );
}
// search the Domain name
$domain =
( new DomainAPI() )
->whereDomainName( $domain_name )
->queryRow();
query( 'START TRANSACTION' );
// domain ID to be assigned to the User
$domain_ID = null;
// does the Domain already exist?
if( $domain ) {
$domain_ID = $domain->getDomainID();
} else {
// can I add this Domain?
if( has_permission( 'edit-domain-all' ) ) {
// add this Domain
( new DomainAPI() )
->insertRow( [
'domain_name' => $domain_name,
'domain_active' => 1,
new DBCol( 'domain_born', 'NOW()', '-' ),
] );
$domain_ID = last_inserted_ID();
}
}
if( $domain_ID ) {
$is_domain_mine =
( new DomainUserAPI() )
->whereUserIsMe()
->whereDomainID( $domain_ID )
->queryRow();
// is it already mine?
if( !$is_domain_mine ) {
// associate this domain to myself
( new DomainUserAPI() )
->insertRow( [
'domain_ID' => $domain_ID,
'user_ID' => $user->getUserID(),
new DBCol( 'domain_user_creation_date', 'NOW()', '-' ),
] );
}
} else {
die( "this Domain is not registered and can't be added" );
}
query( 'COMMIT' );
-
- // end add Domain to User
}
+// end add Domain to User
// register action to generate a new password
$new_password = null;
if( is_action( 'change-password' ) && $user ) {
// generate a new password and save
$new_password = generate_password();
$encrypted = User::encryptPassword( $new_password );
( new UserAPI() )
->whereUser( $user )
->update( [
User::IS_ACTIVE => 1,
User::PASSWORD => $encrypted,
] );
+
+ // do not refresh the page
}
// expose the User domains
$user_domains = [];
if( $user ) {
// get User domains
$user_domains =
( new DomainUserAPI() )
->joinDomain()
->whereUser( $user )
->orderByDomainName()
->queryGenerator();
}
// spawn header
Header::spawn( [
'uid' => false,
'title-prefix' => __( "User" ),
'title' => $user
? $user->getUserUID()
: __( "create" ),
] );
// spawn the page content
template( 'user', [
'user' => $user,
'new_password' => $new_password,
'user_domains' => $user_domains,
] );
// spawn the footer
Footer::spawn();