Skip to content

Commit

Permalink
1.1v
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Sep 18, 2014
1 parent 654e23f commit 2495273
Show file tree
Hide file tree
Showing 23 changed files with 816 additions and 14 deletions.
55 changes: 53 additions & 2 deletions instance/classes/erlhcoreclassmodelinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public function getState()
'terminate' => $this->terminate,
'locale' => $this->locale,
'siteaccess' => $this->siteaccess,
'is_reseller' => $this->is_reseller,
'reseller_tite' => $this->reseller_tite,
'reseller_max_instance_request' => $this->reseller_max_instance_request,
'reseller_secret_hash' => $this->reseller_secret_hash,
'reseller_max_instances' => $this->reseller_max_instances,
'reseller_id' => $this->reseller_id,
'reseller_request' => $this->reseller_request,
'reseller_suspended' => $this->reseller_suspended,
);
}

Expand All @@ -45,6 +53,17 @@ public function __toString() {

public function removeThis() {
try {

$clients = self::getList(array('limit' => 1000000,'filter' => array('reseller_id' => $this->id)));
foreach ($clients as $client) {
$statusRemove = $client->removeThis();

// Something failed
if ($statusRemove == false) {
return false;
}
}

// Instance was created so we have to remove customer data first
if ($this->status == 1) {
erLhcoreClassInstance::removeCustomer($this);
Expand All @@ -60,10 +79,24 @@ public function removeThis() {
public function __get($var) {
switch ($var) {
case 'is_active':
$this->is_active = $this->request > 0 && $this->expires > time() && $this->suspended == 0;
$this->is_active = $this->request > 0 && $this->expires > time() && $this->suspended == 0 && $this->reseller_suspended == 0;
return $this->is_active;
break;


case 'reseller':
try {
$this->reseller = $this->reseller_id > 0 ? self::fetch( $this->reseller_id): false;
} catch (Exception $e) {
$this->reseller = false;
}
return $this->reseller;
break;

case 'reseller_instances_count':
$this->reseller_instances_count = self::getCount(array('filter' => array('reseller_id' => $this->id)));
return $this->reseller_instances_count;
break;

default:
;
break;
Expand All @@ -72,6 +105,13 @@ public function __get($var) {

public function saveThis(){
erLhcoreClassInstance::getSession()->saveOrUpdate($this);
if ($this->is_reseller == 1) {
$db = ezcDbInstance::get();
$stmt = $db->prepare('UPDATE lhc_instance_client SET reseller_suspended = :reseller_suspended WHERE reseller_id = :reseller_id');
$stmt->bindValue( ':reseller_suspended',$this->suspended);
$stmt->bindValue( ':reseller_id',$this->id);
$stmt->execute();
}
}

public function saveToInstanceThis() {
Expand Down Expand Up @@ -213,6 +253,17 @@ public static function getList($paramsSearch = array())
public $date_hour_format = 'H:i:s';
public $date_date_hour_format = 'Y-m-d H:i:s';

public $is_reseller = 0;
public $reseller_tite = '';
public $reseller_max_instance_request = 0;
public $reseller_secret_hash = '';
public $reseller_max_instances = 0;
public $reseller_id = 0;
public $reseller_request = 0;

// Then reseller get's suspended this attribute is set to 1, to avoid double fetching each time in instance part.
public $reseller_suspended = 0;

public $locale = '';
public $siteaccess = 'eng';

Expand Down
24 changes: 24 additions & 0 deletions instance/design/instancetheme/tpl/lhinstance/edit.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<ul class="circle">
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Active');?>: <?php if ($instance->is_active) : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','yes');?><?php else : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','no');?><?php endif;?></li>
<li><a target="_blank" href="http://<?php echo $instance->address?>.<?php echo erConfigClassLhConfig::getInstance()->getSetting( 'site', 'seller_domain')?>/site_admin">http://<?php echo $instance->address?>.<?php echo erConfigClassLhConfig::getInstance()->getSetting( 'site', 'seller_domain')?>/site_admin</a></li>
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Suspended by reseller');?> - <?php if ($instance->reseller_suspended) : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','yes');?><?php else : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','no');?><?php endif;?></li>
<?php if ($instance->is_reseller) : ?><li><?php echo $instance->reseller_instances_count?>/<?php echo $instance->reseller_max_instances?></li><?php endif;?>
</ul>
</div>
</div>
Expand All @@ -57,6 +59,28 @@
</div>
</div>
</section>

<section>
<p class="title" data-section-title><a href="#reseller" ><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Reseller')?></a></p>
<div class="content" data-section-content data-slug="reseller">
<div><div class="row">
<div class="columns large-8">
<form action="<?php echo erLhcoreClassDesign::baseurl('instance/edit')?>/<?php echo $instance->id?>#reseller" method="post" autocomplete="off">
<?php include(erLhcoreClassDesign::designtpl('lhinstance/form_reseller.tpl.php'));?>
<ul class="button-group radius">
<li><input type="submit" class="small button" name="UpdateReseller" value="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Update');?>"/></li>
</ul>
</form>
</div>
<div class="columns large-4">
<ul class="circle">
<li><?php echo $instance->reseller_instances_count?>/<?php echo $instance->reseller_max_instances?></li>
</ul>
</div>
</div>
</div>
</div>
</section>

<section>
<p class="title" data-section-title><a href="#login" ><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Login information')?></a></p>
Expand Down
1 change: 0 additions & 1 deletion instance/design/instancetheme/tpl/lhinstance/form.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Expires');?></label>
<input type="text" name="Expires" value="<?php echo htmlspecialchars($instance->expires > 0 ? date('Y-m-d H:i:s',$instance->expires) : date('Y-m-d H:i:s',time()+6*31*24*3600));?>" />

20 changes: 20 additions & 0 deletions instance/design/instancetheme/tpl/lhinstance/form_reseller.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php if ($instance->id !== null) : ?>
<h4><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Reseller ID');?> - <?php echo htmlspecialchars($instance->id);?></h4>
<?php endif;?>

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Is reseller');?> <input type="checkbox" name="Reseller" value="on" <?php echo $instance->is_reseller ? 'checked="checked"' : '';?> /></label>

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Reseller title');?></label>
<input type="text" name="ResellerTitle" value="<?php echo htmlspecialchars($instance->reseller_tite);?>" />

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Max number of request per instance');?></label>
<input type="text" name="ResellerMaxRequest" value="<?php echo htmlspecialchars($instance->reseller_max_instance_request);?>" />

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Max number of instances reseller can have');?></label>
<input type="text" name="ResellerMaxInstance" value="<?php echo htmlspecialchars($instance->reseller_max_instances);?>" />

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','How many request reseller has to sell');?></label>
<input type="text" name="ResellerRequest" value="<?php echo htmlspecialchars($instance->reseller_request);?>" />

<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Reseller secret hash. Used by API dedicated to reseller');?></label>
<input type="text" name="ResellerSecretHash" value="<?php echo htmlspecialchars($instance->reseller_secret_hash);?>" />
24 changes: 23 additions & 1 deletion instance/design/instancetheme/tpl/lhinstance/list.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Status');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Request left');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Expires');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Owner');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Is reseller');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Number of instances');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Request left to sell');?></th>
<th width="1%">&nbsp;</th>
</tr>
</thead>
Expand All @@ -17,9 +21,27 @@
<td><?php echo $departament->id?></td>
<td><?php echo htmlspecialchars($departament->email)?></td>
<td><?php echo htmlspecialchars($departament->address)?></td>
<td><?php if ($departament->status == 0) : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','pending initialization');?><?php else : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','created');?><?php endif;?></td>
<td><?php if ($departament->status == 0) : ?>c<?php else : ?><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','created');?><?php endif;?></td>
<td><?php echo htmlspecialchars($departament->request)?></td>
<td><?php echo htmlspecialchars(date('Y-m-d H:i:s',$departament->expires))?></td>
<td>
<?php if ($departament->reseller !== false) : ?>
<?php echo htmlspecialchars($departament->reseller->reseller_tite)?>
<?php endif;?>
</td>
<td>
<?php if ($departament->is_reseller == 1) : ?>
<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','Yes');?>
<?php else : ?>
<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit','No');?>
<?php endif;?>
</td>
<td>
<?php if ($departament->is_reseller == 1) : ?>
<?php echo $departament->reseller_instances_count?>/<?php echo $departament->reseller_max_instances?>
<?php endif;?>
</td>
<td><?php echo $departament->reseller_request?></td>
<td nowrap><a class="small button round" href="<?php echo erLhcoreClassDesign::baseurl('instance/edit')?>/<?php echo $departament->id?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/buttons','Edit');?></a></td>
</tr>
<?php endforeach; ?>
Expand Down
2 changes: 2 additions & 0 deletions instance/design/instancetheme/tpl/lhinstance/new.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<?php include(erLhcoreClassDesign::designtpl('lhinstance/form_attributes.tpl.php'));?>

<?php include(erLhcoreClassDesign::designtpl('lhinstance/form_reseller.tpl.php'));?>

<?php include(erLhcoreClassDesign::designtpl('lhkernel/csfr_token.tpl.php'));?>

<ul class="button-group radius">
Expand Down
2 changes: 2 additions & 0 deletions instance/doc/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.1v
Reseller layer on top of instances and API for reseller.
15 changes: 12 additions & 3 deletions instance/doc/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ CREATE TABLE `lhc_instance_client` (
`address` varchar(30) NOT NULL,
`email` varchar(250) NOT NULL,
`status` int(11) NOT NULL,
`locale` varchar(200) NOT NULL,
`siteaccess` varchar(200) NOT NULL,
`time_zone` varchar(200) NOT NULL,
`date_format` varchar(200) NOT NULL DEFAULT 'Y-m-d',
`date_hour_format` varchar(200) NOT NULL DEFAULT 'H:i:s',
`date_date_hour_format` varchar(200) NOT NULL DEFAULT 'Y-m-d H:i:s',
`locale` varchar(10) NOT NULL,
`siteaccess` varchar(3) NOT NULL,
`is_reseller` tinyint(1) NOT NULL DEFAULT '0',
`reseller_tite` varchar(50) NOT NULL,
`reseller_max_instance_request` int(11) NOT NULL,
`reseller_secret_hash` varchar(20) NOT NULL,
`reseller_max_instances` int(11) NOT NULL,
`reseller_id` int(11) NOT NULL,
`reseller_request` int(11) NOT NULL,
`reseller_suspended` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `address` (`address`)
KEY `address` (`address`),
KEY `reseller_id` (`reseller_id`)
) ENGINE=InnoDB;
Loading

0 comments on commit 2495273

Please sign in to comment.