diff --git a/instance/classes/erlhcoreclassmodelinstance.php b/instance/classes/erlhcoreclassmodelinstance.php index e101d69..e732347 100644 --- a/instance/classes/erlhcoreclassmodelinstance.php +++ b/instance/classes/erlhcoreclassmodelinstance.php @@ -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, ); } @@ -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); @@ -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; @@ -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() { @@ -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'; diff --git a/instance/design/instancetheme/tpl/lhinstance/edit.tpl.php b/instance/design/instancetheme/tpl/lhinstance/edit.tpl.php index 70bde3c..04c34cb 100644 --- a/instance/design/instancetheme/tpl/lhinstance/edit.tpl.php +++ b/instance/design/instancetheme/tpl/lhinstance/edit.tpl.php @@ -33,6 +33,8 @@ @@ -57,6 +59,28 @@ + +
+

getTranslation('instance/edit','Reseller')?>

+
+
+
+
+ +
    +
  • +
+
+
+
+
    +
  • reseller_instances_count?>/reseller_max_instances?>
  • +
+
+
+
+
+

getTranslation('instance/edit','Login information')?>

diff --git a/instance/design/instancetheme/tpl/lhinstance/form.tpl.php b/instance/design/instancetheme/tpl/lhinstance/form.tpl.php index 4bf3e58..2d74f2d 100644 --- a/instance/design/instancetheme/tpl/lhinstance/form.tpl.php +++ b/instance/design/instancetheme/tpl/lhinstance/form.tpl.php @@ -15,4 +15,3 @@ - diff --git a/instance/design/instancetheme/tpl/lhinstance/form_reseller.tpl.php b/instance/design/instancetheme/tpl/lhinstance/form_reseller.tpl.php new file mode 100644 index 0000000..6bc584b --- /dev/null +++ b/instance/design/instancetheme/tpl/lhinstance/form_reseller.tpl.php @@ -0,0 +1,20 @@ +id !== null) : ?> +

getTranslation('instance/edit','Reseller ID');?> - id);?>

+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/instance/design/instancetheme/tpl/lhinstance/list.tpl.php b/instance/design/instancetheme/tpl/lhinstance/list.tpl.php index 947b689..986066d 100644 --- a/instance/design/instancetheme/tpl/lhinstance/list.tpl.php +++ b/instance/design/instancetheme/tpl/lhinstance/list.tpl.php @@ -9,6 +9,10 @@ getTranslation('instance/edit','Status');?> getTranslation('instance/edit','Request left');?> getTranslation('instance/edit','Expires');?> + getTranslation('instance/edit','Owner');?> + getTranslation('instance/edit','Is reseller');?> + getTranslation('instance/edit','Number of instances');?> + getTranslation('instance/edit','Request left to sell');?>   @@ -17,9 +21,27 @@ id?> email)?> address)?> - status == 0) : ?>getTranslation('instance/edit','pending initialization');?>getTranslation('instance/edit','created');?> + status == 0) : ?>cgetTranslation('instance/edit','created');?> request)?> expires))?> + + reseller !== false) : ?> + reseller->reseller_tite)?> + + + + is_reseller == 1) : ?> + getTranslation('instance/edit','Yes');?> + + getTranslation('instance/edit','No');?> + + + + is_reseller == 1) : ?> + reseller_instances_count?>/reseller_max_instances?> + + + reseller_request?> getTranslation('system/buttons','Edit');?> diff --git a/instance/design/instancetheme/tpl/lhinstance/new.tpl.php b/instance/design/instancetheme/tpl/lhinstance/new.tpl.php index bd3c924..0c7af95 100644 --- a/instance/design/instancetheme/tpl/lhinstance/new.tpl.php +++ b/instance/design/instancetheme/tpl/lhinstance/new.tpl.php @@ -10,6 +10,8 @@ + +