Browse Source

add ressources

andre 2 years ago
parent
commit
9c53db277b
2 changed files with 52 additions and 21 deletions
  1. 23 0
      api/KerioWhmcs.php
  2. 29 21
      app/UI/Client/Ressource/Providers/RessourceDataProvider.php

+ 23 - 0
api/KerioWhmcs.php

@@ -438,6 +438,29 @@ class KerioWhmcs extends KerioConnectApi {
 		return $result['list'];
 	}
 
+	/**
+	 * Create resource.
+	 *
+	 * @param	array	Resource attributes
+	 * @param	string	Domain ID
+	 * @return	array	Result
+	 */
+	function createResouce($attr, $domain) {
+		$params = array(
+			'resources' => array(array(
+				'name' => $attr['name'],
+				'description' => $attr['description'],
+				'type' => $attr['type'],
+				'isEnabled' => $attr['status'] === 'active' ? TRUE : FALSE,
+				'resourceUsers' => array('id' => $domain, 'type' => 'AuthDomainPrincipal'),
+				'manager' => array('id' => $attr['manager'], 'type' => 'UserPrincipal'),
+				'domainId' => $domain
+			))
+		);
+		$result = $this->sendRequest('Resources.create', $params);
+		return $result;
+	}
+
 	/**
 	 * Get list of aliases from a domain
 	 * 

+ 29 - 21
app/UI/Client/Ressource/Providers/RessourceDataProvider.php

@@ -74,7 +74,7 @@ class RessourceDataProvider extends BaseDataProvider
 
         foreach($users as $user) {
             if($user['isEnabled']){
-                $this->availableValues['manager'][ $user['loginName']] = $user['loginName'] . '@' . $this->getWhmcsParamByKey('domain');
+                $this->availableValues['manager'][ $user['id']] = $user['loginName'] . '@' . $this->getWhmcsParamByKey('domain');
             }
         }
 
@@ -88,33 +88,14 @@ class RessourceDataProvider extends BaseDataProvider
             Kerio::RES_TYPE_LOCATION        => $lang->absoluteT('kerio','ressource','type','location'),
             Kerio::RES_TYPE_EQUIPMENT       => $lang->absoluteT('kerio','ressource','type','equipment')
         ];
-        logModuleCall(
-            'kerioEmail',
-            __FUNCTION__,
-            $this->availableValues,
-            'Debug Error',
-            $this
-        );
     }
 
     public function create()
     {
-        /**
-         * hosting id
-         */
-        $hid = $this->request->get('id');
-
-        logModuleCall(
-            'kerioEmail',
-            __FUNCTION__,
-            $this->formData,
-            'Debug Error',
-            $this
-        );
-
         $fieldToProtection = [
             'name',
             'status',
+            'manager',
             'type',
             'description'
         ];
@@ -124,6 +105,33 @@ class RessourceDataProvider extends BaseDataProvider
             $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $value;
         }
 
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
+            $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $ressourceID = $api->createR;
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }
 
         return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenAdded')->setStatusSuccess();