diff --git a/include/class-Domain.php b/include/class-Domain.php index b3859ab..95295ce 100644 --- a/include/class-Domain.php +++ b/include/class-Domain.php @@ -1,185 +1,194 @@ . // load Plan trait class_exists( 'Plan' ); /** * Methods for a Domain class */ trait DomainTrait { use PlanTrait; /** * Count of the Domain's Mailboxes * * This is a kind of cache * * @var int */ private $domainMailboxCount = null; /** * Get domain ID * * @return int */ public function getDomainID() { return $this->get( 'domain_ID' ); } /* * Get domain name * * @return string */ public function getDomainName() { return $this->get( 'domain_name' ); } /** * Get the domain edit URl * * @param boolean $absolute True for an absolute URL * @return string */ public function getDomainPermalink( $absolute = false ) { return Domain::permalink( $this->get( 'domain_name' ), $absolute ); } /** * Factory mailbox from this domain * * @return MailboxFullAPI */ public function factoryMailbox() { return ( new MailboxFullAPI() )->whereDomain( $this ); } /** * Factory e-mail forward from this domain * * @return MailforwardFullAPI */ public function factoryMailforwardfrom() { return ( new MailforwardfromAPI() )->whereDomain( $this ); } /** * Set a count of Domain's Mailboxes * * @param $count int * @return self */ public function setDomainMailboxCount( $count ) { $this->domainMailboxCount = $count; } /** * Get the number of Mailboxes of this Domain * * This method has a layer of cache. * * @return int */ public function getDomainMailboxCount() { // check if we already know the count if( !isset( $this->domainMailboxCount ) ) { // count the number of mailboxes associated to this Domain $count = $this->factoryMailbox() ->select( 'COUNT(*) count' ) ->queryValue( 'count' ); // save in cache $this->domainMailboxCount = (int) $count; } return $this->domainMailboxCount; } /** - * Check if you can create a new mailbox for this Domain + * Check if you can create a new Mailbox for this Domain * - * The Domain must have plan informations. + * The Domain must have Plan informations. * * @return boolean */ public function canCreateMailboxInDomain() { return $this->getPlanMailboxes() > $this->getDomainMailboxCount() || has_permission( 'edit-email-all' ); } + /** + * Check if you can create a new FTP account for this Domain + * + * The Domain must have Plan informations. + */ + public function canCreateFTPAccountForDomain() { + return has_permission( 'edit-ftp-all' ); + } + /** * Factory FTP users from this domain * * @return FTPAPI */ public function factoryFTP() { return ( new FTPAPI() )->whereDomain( $this ); } /** * Normalize a Domain object after being retrieved from database */ protected function normalizeDomain() { $this->integers( 'domain_ID' ); $this->booleans( 'domain_active' ); $this->dates( 'domain_born', 'domain_expiration' ); $this->normalizePlan(); } } /** * Describe the 'domain' table */ class Domain extends Queried { use DomainTrait; /** * Table name */ const T = 'domain'; const UID = 'domain_name'; /** * Constructor */ public function __construct() { $this->normalizeDomain(); } /** * Get the domain permalink * * @param string $domain_name Domain name * @param boolean $absolute True for an absolute URL */ public static function permalink( $domain_name = null, $absolute = false ) { $url = 'domain.php'; if( $domain_name ) { $url .= _ . $domain_name; } return site_page( $url, $absolute ); } } diff --git a/template/ftp-users.php b/template/ftp-users.php index c0fdf77..7cc5afe 100644 --- a/template/ftp-users.php +++ b/template/ftp-users.php @@ -1,70 +1,70 @@ . /* * This is the template for the FTP user list * * Called from: * domain.php * * Available variables: * $domain Domain object */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; // domain FTP users $ftps = $domain->factoryFTP() ->select( [ 'ftp_login', ] ) ->queryGenerator(); ?>

valid() ): ?>

- + canCreateFTPAccountForDomain() ): ?>

getDomainName() ), __( "Create" ) ) ?>