| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- <?php
- namespace MGModule\DNSManager2\models\whmcs\service;
- use \MGModule\DNSManager2 as main;
- use \MGModule\DNSManager2\mgLibs\custom\dns\utils\IP;
- /**
- * Description of account
- * @Table(name=tblhosting,preventUpdate,prefixed=false)
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class service extends main\mgLibs\models\orm{
- /**
- * @Column()
- * @var type
- */
- public $id;
-
- /**
- * @Column(name=userid,as=userid)
- * @var int
- */
- public $clientID = 0;
- public $userid;
- /**
- *
- * @var client
- */
- private $_client;
- /**
- * @Column(name=dedicatedip,as=dedicatedip)
- * @var string
- */
- public $dedicatedIP = null;
-
- /**
- * @Column(name=assignedips,as=assingedips)
- * @var array
- */
- public $IPList = array();
-
- /**
- *
- * @Column(name=server,as=serverid)
- * @var int
- */
- public $serverID;
-
- /**
- *
- * @var server
- */
- private $_server;
-
- /**
- *
- * @Column(name=packageid,as=pid)
- * @var int
- */
- public $productID;
-
- /**
- *
- * @var main\models\whmcs\product\product
- */
- private $_product;
-
- /**
- *
- * @Column()
- * @var string
- */
- public $domain;
-
- /**
- *
- * @Column()
- * @var string
- */
- public $username;
-
- /**
- *
- * @Column(as=passwordEncrypted)
- * @var string
- */
- public $password;
-
- /**
- *
- * @Column(name=orderid)
- * @var int
- */
- protected $_orderid;
-
- /**
- *
- * @Column(name=domainstatus,as=_domainstatus)
- * @var string
- */
- protected $_status;
-
- /**
- *
- * @Column(name=billingcycle,as=_billingcycle)
- * @var string
- */
- protected $_billingcycle;
-
- /**
- *
- * @var main\models\whmcs\service\customFields\repository
- */
- private $_customFields;
-
- /**
- *
- * @var main\models\whmcs\service\configOption\repository
- */
- private $_configOptions;
-
- /**
- * Load Account
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param int $id
- * @param array $data
- * @throws main\mgLibs\exceptions\systemLoad
- */
- function __construct($id = null, $data = array()) {
- $this->id = $id;
- $this->load($data);
- }
-
- /**
- * Load Account Server
- * Function allows to easy overwrite server object
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param int $id
- * @param array $data
- * @return main\models\whmcs\servers\server
- */
- protected function loadServer($id,$data = array()){
- return new main\models\whmcs\servers\server($id,$data);
- }
-
- /**
- * Load Product
- * Function allows to easy overwrite product object
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param array $data
- * @return main\models\whmcs\product\product
- */
- protected function loadProduct($data = array()){
- return new main\models\whmcs\product\product($this->productID,$data);
- }
-
- /**
- * Load Client
- * Function allows to easy overwrite product object
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param type $data
- * @return main\models\whmcs\service\client
- */
- protected function loadClient($data = array()){
- return new main\models\whmcs\client\client($this->clientID,$data);
- }
-
- /**
- * Get Server Connected With Service
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return main\models\whmcs\servers\server
- */
- public function server(){
- if(empty($this->_server))
- {
- $this->_server = $this->loadServer($this->serverID);
- }
- return $this->_server;
- }
-
- /**
- * Get Client Connected with Service
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return main\models\whmcs\client\client
- */
- function client(){
- if(empty($this->_client))
- {
- $this->_client = $this->loadClient();
- }
-
- return $this->_client;
- }
-
- function clientID(){
- return $this->clientID;
- }
-
- /**
- * Get Product Service
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return main\models\whmcs\product\product
- */
- public function product(){
- if(empty($this->_product))
- {
- $this->_product = $this->loadProduct();
- }
- return $this->_product;
- }
-
- /**
- * Get Custom Fields
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return customFields
- */
- function customFields(){
- if(empty($this->_customFields))
- {
- $this->_customFields = new main\models\whmcs\service\customFields\repository($this->id);
- }
-
- return $this->_customFields;
- }
-
- /**
- * Get Config Options
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return configOptions
- */
- function configOptions(){
- if(empty($this->_configOptions))
- {
- $this->_configOptions = new main\models\whmcs\service\configOptions\repository($this->id);
- }
-
- return $this->_configOptions;
- }
-
- /**
- * Get Merged Configs from product configuration & custom fields & confi optins
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return \stdClass
- */
- function mergedConfig(){
-
- $obj = new \stdClass();
-
- foreach ($this->product()->configuration as $name => $value)
- {
- if(!empty($value))
- {
- $obj->$name = $value;
- }
- }
-
- foreach ($this->customFields()->toArray(false) as $name => $value)
- {
- if(!empty($value))
- {
- $obj->$name = $value;
- }
- }
-
- foreach ($this->configOptions()->toArray(false) as $name => $value)
- {
- if(!empty($value))
- {
- $obj->$name = $value;
- }
- }
-
- return $obj;
- }
- /**
- * Save Account Settings
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- function save($cols = array()){
- $cols['password'] = encrypt($this->password);
-
- if(($key = array_search($this->dedicatedIP, $this->IPList)) !== false) {
- unset($this->IPList[$key]);
- }
-
- $cols['assignedips'] = implode("\n", $this->IPList);
-
- parent::save($cols);
- }
-
- /**
- * Set Object Properties
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param array $data
- * @throws main\mgLibs\exceptions\system
- */
- function load(array $data = array()){
- if(empty($this->id) && !empty($data['serviceid']))
- {
- $this->id = $data['serviceid'];
- }
-
- if($this->id !== null && empty($data))
- {
- $data = main\mgLibs\MySQL\query::select(
- static::fieldDeclaration()
- , static::tableName()
- , array(
- 'id' => $this->id
- )
- )->fetch();
-
- if(empty($data))
- {
- throw new main\mgLibs\exceptions\system('Unable to find Item with ID:'.$this->id);
- }
- }
-
- if(isset($data['passwordEncrypted']))
- {
- $data['password'] = decrypt($data['passwordEncrypted']);
- }
-
- if(!empty($data['dedicatedip']))
- {
- $ipo = new IP(trim($data['dedicatedip']));
- $this->dedicatedIP = $this->IPList[] = (string) $ipo;
- }
-
- if(!empty($data['assingedips']))
- {
- foreach(explode("\n",$data['assingedips']) as $ip)
- {
- if($ip) {
- $ipo = new IP(trim($ip));
- $ip = (string) $ipo;
-
- if(!in_array($ip, $this->IPList))
- {
- $this->IPList[] = trim($ip);
- }
- }
-
- }
- }
-
- if(!empty($data['_domainstatus']))
- {
- $this->_status = $data['_domainstatus'];
- $this->_billingcycle = $data['_billingcycle'];
- }
-
- if(!empty($data['userid']))
- {
- $this->userid = $data['userid'];
- $this->clientID = $data['userid'];
- $this->serverID = $data['serverid'];
- $this->domain = $data['domain'];
- $this->productID = $data['pid'];
- $this->username = $data['username'];
- $this->password = $data['password'];
- }
- if(!empty($data['server']))
- {
- $this->_server = $this->loadServer($data['serverid'], array(
- 'hostname' => $data['serverhostname']
- ,'username' => $data['serverusername']
- ,'password' => $data['serverpassword']
- ,'accesshash' => $data['serveraccesshash']
- ,'secure' => $data['serversecure']
- ,'ip' => $data['serverip']
- ));
- }
-
- if(!empty($data['customfields']))
- {
- $this->_customFields = new main\models\whmcs\service\customFields\repository($this->id,$data['customfields']);
- }
-
- if(!empty($data['configoptions']))
- {
- $this->_configOptions = new configOptions\repository($this->id);
- }
-
- if(!empty($data['_orderid']))
- {
- $this->_orderid = $data['_orderid'];
- }
- }
-
-
- function billingcycle(){
- if(empty($this->_billingcycle)){
- $this->load();
- }
- return $this->_billingcycle;
- }
-
- function getBillingCycleNumMonth(){
- switch ($this->billingcycle())
- {
- case 'Monthly':
- return 1;
- case 'Quarterly':
- return 3;
- case 'Semi-Annually':
- return 6;
- case 'Annually':
- return 12;
- case 'Biennially':
- return 24;
- case 'Triennially':
- return 36;
- }
-
- return 0;
- }
-
- public function status(){
- if(empty($this->_status)){
- $this->load();
- }
- return $this->_status;
- }
-
- function orderId(){
- if(empty($this->_orderid)){
- $this->load();
- }
- return $this->_orderid;
- }
-
- public function getIPs() {
- return $this->IPList;
- }
- }
|