From ef2302601682589db19854d598d2fbfb15646bb4 Mon Sep 17 00:00:00 2001 From: Ramendra Date: Sun, 6 Feb 2022 21:44:43 +0530 Subject: [PATCH 1/8] save contacts on cloud --- .../Contacts/Ext/LogicHooks/records.php | 20 +++ custom/modules/Contacts/prv_cloud_class.php | 149 ++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 custom/Extension/modules/Contacts/Ext/LogicHooks/records.php create mode 100644 custom/modules/Contacts/prv_cloud_class.php diff --git a/custom/Extension/modules/Contacts/Ext/LogicHooks/records.php b/custom/Extension/modules/Contacts/Ext/LogicHooks/records.php new file mode 100644 index 00000000000..0bc867157e3 --- /dev/null +++ b/custom/Extension/modules/Contacts/Ext/LogicHooks/records.php @@ -0,0 +1,20 @@ + diff --git a/custom/modules/Contacts/prv_cloud_class.php b/custom/modules/Contacts/prv_cloud_class.php new file mode 100644 index 00000000000..c389558a123 --- /dev/null +++ b/custom/modules/Contacts/prv_cloud_class.php @@ -0,0 +1,149 @@ +setClient(); + $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1, ], "record_type_id" => $this->record_type_id, "workspace_id" => $this->workspace_id, "container_guid" => $this->container_guid, ]; + + $this->createRecord($data); + + } + private function setClient() + { + global $sugar_config; + + $stack = HandlerStack::create(); + $this->host = $sugar_config['PVT_HOST']; + $this->client = new GuzzleClient(['base_uri' => $this->host, 'timeout' => 15, 'connect_timeout' => 15, 'handler' => $stack, 'debug' => true, 'http_errors' => false, ]); + + $this->authTok = $sugar_config['PVT_AUTH']; + $this->record_type_id = $sugar_config['PVT_record_type_id']; + $this->workspace_id = $sugar_config['PVT_workspace_id']; + $this->container_guid = $sugar_config['PVT_container_guid']; + } + private function makeAuth() + { + if (session_id() == "") + { + session_start(); + } + $this->token = $_SESSION["PVT_TOKEN"]; + + if (empty($this->token)) + { + $res = $this + ->client + ->request("POST", $this->host . "/api/refresh_token", ["headers" => ["Accept" => "application/json", "Authorization" => "Bearer " . $this->authTok, ], ]); + $response = (array)json_decode($res->getBody() + ->getContents()); + + if (isset($response["access_token"]) && !empty($response["access_token"])) + { + $_SESSION["PVT_TOKEN"] = $response["access_token"]; + $this->token = $response["access_token"]; + } + else + { + $this->RedirectBack("There some error in API authentication. Try again"); + #$response['code'] $response['message'] + + } + } + } + private function createRecord($data, $depth = 0) + { + /*start httpclient*/ + $this->makeAuth(); + + if ($this->token) + { + + try + { + + $res = $this + ->client + ->post("/api/record", [ + + 'headers' => ['Content-Type' => 'application/json', 'Authorization' => "Bearer " . $this->token], 'body' => json_encode($data) ]); + + $response = (array)json_decode($res->getBody() + ->getContents()); + + /**check if authentication fail try to recreate token****/ + if (trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->createRecord($data, ++$depth); + } + else + { + $this->RedirectBack($response['message']); + } + + } + elseif(isset($response['record']) && !empty($response['record'])) + { + #"Record added"; + $this->RedirectBack("Record added successfully guid - ".$response['guid'],1); + + }else{ + $this->RedirectBack($response['message']); + + } + + } + catch(RequestException $e) + { + if ($e->hasResponse()) + { + $exception = (string)$e->getResponse() + ->getBody(); + $exception = json_decode($exception); + $GLOBALS["log"]->fatal("PVT - error " . var_export($exception, true)); + return new JsonResponse($exception, $e->getCode()); + } + else + { + $GLOBALS["log"]->fatal("PVT = error" . var_export($e, true)); + return new JsonResponse($e->getMessage() , 503); + } + + } + } + } + function RedirectBack($msg,$type=0) + { + $queryParams = ["module" => 'Contacts', "action" => "ListView", ]; + if($type==0){ + SugarApplication::appendErrorMessage($msg); + }else{ + SugarApplication::appendSuccessMessage($msg); + } + + + SugarApplication::redirect("index.php?" . http_build_query($queryParams)); + + } +} + +?> From 9df8ed42d6d086f7b6a3b2f6a3e60b12fb6327d3 Mon Sep 17 00:00:00 2001 From: Ramendra Date: Mon, 7 Feb 2022 20:33:32 +0530 Subject: [PATCH 2/8] Update - Contact save --- .../application/Ext/Extensions/PrvCloud.php | 6 + .../Ext/PrvCloud/prv_cloud.ext.php | 139 ++++++++++++++++++ custom/modules/Contacts/prv_cloud_class.php | 136 +---------------- 3 files changed, 151 insertions(+), 130 deletions(-) create mode 100755 custom/Extension/application/Ext/Extensions/PrvCloud.php create mode 100755 custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php mode change 100644 => 100755 custom/modules/Contacts/prv_cloud_class.php diff --git a/custom/Extension/application/Ext/Extensions/PrvCloud.php b/custom/Extension/application/Ext/Extensions/PrvCloud.php new file mode 100755 index 00000000000..5b3faf40bc8 --- /dev/null +++ b/custom/Extension/application/Ext/Extensions/PrvCloud.php @@ -0,0 +1,6 @@ + "prv_cloud_class", + "extdir" => "PrvCloud", + "file" => 'prv_cloud.ext.php', + "module" => ""); diff --git a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php new file mode 100755 index 00000000000..21a30d5304a --- /dev/null +++ b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php @@ -0,0 +1,139 @@ +host = $sugar_config['PVT_HOST']; + $this->client = new GuzzleClient(['base_uri' => $this->host, 'timeout' => 15, 'connect_timeout' => 15, 'handler' => $stack, 'debug' => true, 'http_errors' => false, ]); + + $this->authTok = $sugar_config['PVT_AUTH']; + $this->record_type_id = $sugar_config['PVT_record_type_id']; + $this->workspace_id = $sugar_config['PVT_workspace_id']; + $this->container_guid = $sugar_config['PVT_container_guid']; + $GLOBALS["log"]->fatal("RSR Working...." . $sugar_config['PVT_HOST']); + } + /********Generate Token********/ + private function makeAuth() + { + if (session_id() == "") + { + session_start(); + } + $this->token = $_SESSION["PVT_TOKEN"]; + + if (empty($this->token)) + { + $res = $this + ->client + ->request("POST", $this->host . "/api/refresh_token", ["headers" => ["Accept" => "application/json", "Authorization" => "Bearer " . $this->authTok, ], ]); + $response = (array)json_decode($res->getBody() + ->getContents()); + + if (isset($response["access_token"]) && !empty($response["access_token"])) + { + $_SESSION["PVT_TOKEN"] = $response["access_token"]; + $this->token = $response["access_token"]; + } + else + { + $this->RedirectBack("There some error in API authentication. Try again"); + #$response['code'] $response['message'] + + } + } + } + /*******create record*********/ + public function createRecord($data, $depth = 0) + { + $this->setClient(); + /*start httpclient*/ + $this->makeAuth(); + $data_t = ["record_type_id" => $this->record_type_id, "workspace_id" => $this->workspace_id, "container_guid" => $this->container_guid]; + $data_f = array_merge($data, $data_t); + + if ($this->token) + { + + try + { + + $res = $this + ->client + ->post("/api/record", [ + + 'headers' => ['Content-Type' => 'application/json', 'Authorization' => "Bearer " . $this->token], 'body' => json_encode($data_f) ]); + + $response = (array)json_decode($res->getBody()->getContents()); + + /**check if authentication fail try to recreate token****/ + if (trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->createRecord($data_f, ++$depth); + } + else + { + $this->RedirectBack($response['message']); + } + + } + elseif (isset($response['record']) && !empty($response['record'])) + { + #"Record added"; + $this->RedirectBack("Record added successfully guid - " . $response['guid'], 1); + + } + else + { + $this->RedirectBack($response['message']); + + } + + } + catch(RequestException $e) + { + if ($e->hasResponse()) + { + $exception = (string)$e->getResponse() + ->getBody(); + $exception = json_decode($exception); + $GLOBALS["log"]->fatal("PVT - error " . var_export($exception, true)); + return new JsonResponse($exception, $e->getCode()); + } + else + { + $GLOBALS["log"]->fatal("PVT = error" . var_export($e, true)); + return new JsonResponse($e->getMessage() , 503); + } + + } + } + } + function RedirectBack($msg, $type = 0) + { + $queryParams = ["module" => 'Contacts', "action" => "ListView", ]; + if ($type == 0) + { + SugarApplication::appendErrorMessage($msg); + } + else + { + SugarApplication::appendSuccessMessage($msg); + } + + SugarApplication::redirect("index.php?" . http_build_query($queryParams)); + + } + +} +?> diff --git a/custom/modules/Contacts/prv_cloud_class.php b/custom/modules/Contacts/prv_cloud_class.php old mode 100644 new mode 100755 index c389558a123..dbafcb1976a --- a/custom/modules/Contacts/prv_cloud_class.php +++ b/custom/modules/Contacts/prv_cloud_class.php @@ -1,149 +1,25 @@ setClient(); - $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1, ], "record_type_id" => $this->record_type_id, "workspace_id" => $this->workspace_id, "container_guid" => $this->container_guid, ]; - - $this->createRecord($data); - - } - private function setClient() - { - global $sugar_config; + $prv = new PrvCloudMethods(); - $stack = HandlerStack::create(); - $this->host = $sugar_config['PVT_HOST']; - $this->client = new GuzzleClient(['base_uri' => $this->host, 'timeout' => 15, 'connect_timeout' => 15, 'handler' => $stack, 'debug' => true, 'http_errors' => false, ]); + $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1, ]]; + $GLOBALS["log"]->fatal("Token" . var_export($data, true)); + $prv->createRecord($data); - $this->authTok = $sugar_config['PVT_AUTH']; - $this->record_type_id = $sugar_config['PVT_record_type_id']; - $this->workspace_id = $sugar_config['PVT_workspace_id']; - $this->container_guid = $sugar_config['PVT_container_guid']; } - private function makeAuth() - { - if (session_id() == "") - { - session_start(); - } - $this->token = $_SESSION["PVT_TOKEN"]; - - if (empty($this->token)) - { - $res = $this - ->client - ->request("POST", $this->host . "/api/refresh_token", ["headers" => ["Accept" => "application/json", "Authorization" => "Bearer " . $this->authTok, ], ]); - $response = (array)json_decode($res->getBody() - ->getContents()); - - if (isset($response["access_token"]) && !empty($response["access_token"])) - { - $_SESSION["PVT_TOKEN"] = $response["access_token"]; - $this->token = $response["access_token"]; - } - else - { - $this->RedirectBack("There some error in API authentication. Try again"); - #$response['code'] $response['message'] - - } - } - } - private function createRecord($data, $depth = 0) - { - /*start httpclient*/ - $this->makeAuth(); - - if ($this->token) - { - - try - { - $res = $this - ->client - ->post("/api/record", [ - - 'headers' => ['Content-Type' => 'application/json', 'Authorization' => "Bearer " . $this->token], 'body' => json_encode($data) ]); - - $response = (array)json_decode($res->getBody() - ->getContents()); - - /**check if authentication fail try to recreate token****/ - if (trim($response['code']) == 401) - { - if ($depth <= 3) - { - unset($_SESSION["PVT_TOKEN"]); - $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); - $this->createRecord($data, ++$depth); - } - else - { - $this->RedirectBack($response['message']); - } - - } - elseif(isset($response['record']) && !empty($response['record'])) - { - #"Record added"; - $this->RedirectBack("Record added successfully guid - ".$response['guid'],1); - - }else{ - $this->RedirectBack($response['message']); - - } - - } - catch(RequestException $e) - { - if ($e->hasResponse()) - { - $exception = (string)$e->getResponse() - ->getBody(); - $exception = json_decode($exception); - $GLOBALS["log"]->fatal("PVT - error " . var_export($exception, true)); - return new JsonResponse($exception, $e->getCode()); - } - else - { - $GLOBALS["log"]->fatal("PVT = error" . var_export($e, true)); - return new JsonResponse($e->getMessage() , 503); - } - - } - } - } - function RedirectBack($msg,$type=0) - { - $queryParams = ["module" => 'Contacts', "action" => "ListView", ]; - if($type==0){ - SugarApplication::appendErrorMessage($msg); - }else{ - SugarApplication::appendSuccessMessage($msg); - } - - - SugarApplication::redirect("index.php?" . http_build_query($queryParams)); - - } } ?> From bcf1d66f71bcb4c44ff2a1586a07cd4e25c8a646 Mon Sep 17 00:00:00 2001 From: Ramendra Date: Thu, 10 Feb 2022 21:46:27 +0530 Subject: [PATCH 3/8] Code for list,delete and update records --- .../Ext/PrvCloud/prv_cloud.ext.php | 203 +++++++++++++++++- custom/modules/Contacts/controller.php | 22 ++ custom/modules/Contacts/prv_cloud_class.php | 27 ++- custom/modules/Contacts/templates/list.tpl | 65 ++++++ custom/modules/Contacts/views/view.edit.php | 33 +++ custom/modules/Contacts/views/view.list.php | 37 ++++ 6 files changed, 377 insertions(+), 10 deletions(-) create mode 100644 custom/modules/Contacts/controller.php create mode 100755 custom/modules/Contacts/templates/list.tpl create mode 100755 custom/modules/Contacts/views/view.edit.php create mode 100755 custom/modules/Contacts/views/view.list.php diff --git a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php index 21a30d5304a..1a2da965c54 100755 --- a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php +++ b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php @@ -2,6 +2,7 @@ use GuzzleHttp\Client as GuzzleClient; use Guzzle\Http\Exception\ClientErrorResponseException; use GuzzleHttp\HandlerStack; + class PrvCloudMethods { /********Set variables*********/ @@ -11,13 +12,13 @@ public function setClient() $stack = HandlerStack::create(); $this->host = $sugar_config['PVT_HOST']; - $this->client = new GuzzleClient(['base_uri' => $this->host, 'timeout' => 15, 'connect_timeout' => 15, 'handler' => $stack, 'debug' => true, 'http_errors' => false, ]); + $this->client = new GuzzleClient(['base_uri' => $this->host, 'timeout' => 15, 'connect_timeout' => 15, 'handler' => $stack, 'debug' => false, 'http_errors' => false, ]); $this->authTok = $sugar_config['PVT_AUTH']; $this->record_type_id = $sugar_config['PVT_record_type_id']; $this->workspace_id = $sugar_config['PVT_workspace_id']; $this->container_guid = $sugar_config['PVT_container_guid']; - $GLOBALS["log"]->fatal("RSR Working...." . $sugar_config['PVT_HOST']); + } /********Generate Token********/ private function makeAuth() @@ -58,6 +59,7 @@ public function createRecord($data, $depth = 0) $data_t = ["record_type_id" => $this->record_type_id, "workspace_id" => $this->workspace_id, "container_guid" => $this->container_guid]; $data_f = array_merge($data, $data_t); + if ($this->token) { @@ -71,7 +73,7 @@ public function createRecord($data, $depth = 0) 'headers' => ['Content-Type' => 'application/json', 'Authorization' => "Bearer " . $this->token], 'body' => json_encode($data_f) ]); $response = (array)json_decode($res->getBody()->getContents()); - + /**check if authentication fail try to recreate token****/ if (trim($response['code']) == 401) { @@ -92,6 +94,201 @@ public function createRecord($data, $depth = 0) #"Record added"; $this->RedirectBack("Record added successfully guid - " . $response['guid'], 1); + } + else + { + + $this->RedirectBack($response['message']); + + } + + } + catch(RequestException $e) + { + if ($e->hasResponse()) + { + $exception = (string)$e->getResponse() + ->getBody(); + $exception = json_decode($exception); + $GLOBALS["log"]->fatal("PVT - error " . var_export($exception, true)); + return new JsonResponse($exception, $e->getCode()); + } + else + { + $GLOBALS["log"]->fatal("PVT = error" . var_export($e, true)); + return new JsonResponse($e->getMessage() , 503); + } + + } + } + } + /**fetch records from container***/ + public function listContainerRecords($depth = 0) + { + $this->setClient(); + /*start httpclient*/ + $this->makeAuth(); + $res = $this + ->client + ->request('GET', '/api/container/' . $this->container_guid . '/records', ['headers' => ['accept' => 'application/json', 'Authorization' => "Bearer " . $this->token]]); + + $response = (array)json_decode($res->getBody() + ->getContents()); + + /**check if authentication fail try to recreate token****/ + if (trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->listContainerRecords(++$depth); + } + else + { + $GLOBALS["log"]->fatal($response['message']); + } + + } + elseif (isset($response[0]) && !empty($response[0]->guid)) + { + #"Record added"; + $GLOBALS["log"]->fatal("Record loaded successfully container - " . $this->container_guid); + return $response; + + } + else + { + $GLOBALS["log"]->fatal($response['message']); + + } + + } + /**fetch records by guid***/ + public function listRecords($id,$depth = 0) + { + $this->setClient(); + /*start httpclient*/ + $this->makeAuth(); + $res = $this + ->client + ->request('GET', '/api/record/' . $id.'/decrypt', ['headers' => ['accept' => 'application/json', 'Authorization' => "Bearer " . $this->token]]); + + $response = (array)json_decode($res->getBody() + ->getContents()); + + /**check if authentication fail try to recreate token****/ + if (isset($response['code']) && trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->listRecords($id,++$depth); + } + else + { + $GLOBALS["log"]->fatal($response['message']); + } + + } + elseif (isset($response['record']) && !empty($response['record'])) + { + #"Record added"; + $GLOBALS["log"]->fatal("Record loaded successfully - " . $id); + return $response; + + } + else + { + $GLOBALS["log"]->fatal($response['message']); + + } + + } + public function deleteRecord($id,$depth = 0){ + $this->setClient(); + /*start httpclient*/ + $this->makeAuth(); + $res = $this + ->client + ->request('DELETE', '/api/record/' . $id, ['headers' => ['accept' => 'application/json', 'Authorization' => "Bearer " . $this->token]]); + + + + /**check if authentication fail try to recreate token****/ + if (isset($response['code']) && trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->deleteRecord($id,++$depth); + } + else + { + $GLOBALS["log"]->fatal($response['message']); + } + + } + elseif (isset($response) && empty($response)) + { + #"Record added"; + $GLOBALS["log"]->fatal("Record Deleted successfully - " . $id); + + + } + else + { + $GLOBALS["log"]->fatal($response['message']); + + } + } + /*******Update record*********/ + public function updateRecord($data, $id,$depth = 0) + { + $this->setClient(); + /*start httpclient*/ + $this->makeAuth(); + $data_t = ["record_type_id" => $this->record_type_id, "workspace_id" => $this->workspace_id, "container_guid" => $this->container_guid]; + $data_f = array_merge($data, $data_t); + + if ($this->token) + { + + try + { + + $res = $this + ->client + ->PATCH("/api/record/".$id, [ + + 'headers' => ['accept' => 'application/json','Content-Type' => 'application/json', 'Authorization' => "Bearer " . $this->token], 'body' => json_encode($data_f) ]); + + $response = (array)json_decode($res->getBody()->getContents()); + + /**check if authentication fail try to recreate token****/ + if (trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->updateRecord($data_f, $id,++$depth); + } + else + { + $this->RedirectBack($response['message']); + } + + } + elseif (isset($response['record']) && !empty($response['record'])) + { + #"Record added"; + + $this->RedirectBack("Record updated successfully guid - " . $response['guid'], 1); + + } else { diff --git a/custom/modules/Contacts/controller.php b/custom/modules/Contacts/controller.php new file mode 100644 index 00000000000..1ebdf88ab60 --- /dev/null +++ b/custom/modules/Contacts/controller.php @@ -0,0 +1,22 @@ +deleteRecord($re); + } + SugarApplication::appendSuccessMessage("Record Deleted!"); + echo 1; + die; + } +} \ No newline at end of file diff --git a/custom/modules/Contacts/prv_cloud_class.php b/custom/modules/Contacts/prv_cloud_class.php index dbafcb1976a..cc4ba0c8f74 100755 --- a/custom/modules/Contacts/prv_cloud_class.php +++ b/custom/modules/Contacts/prv_cloud_class.php @@ -4,19 +4,32 @@ { die("Not A Valid Entry Point"); } -include ("custom/application/Ext/PrvCloud/prv_cloud.ext.php"); +require_once ("custom/application/Ext/PrvCloud/prv_cloud.ext.php"); class PrvCloud { function PrvSave($bean, $event, $arguments) { - - $prv = new PrvCloudMethods(); - - $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1, ]]; - $GLOBALS["log"]->fatal("Token" . var_export($data, true)); - $prv->createRecord($data); + $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1, ]]; + + + if (isset($_REQUEST['record']) && !empty($_REQUEST['record'])) { + //Update Record + + $prv = new PrvCloudMethods(); + $prv->updateRecord($data,$_REQUEST['record']); + + }else{ + //New Record + + + + $prv = new PrvCloudMethods(); + + $prv->createRecord($data); + } + } diff --git a/custom/modules/Contacts/templates/list.tpl b/custom/modules/Contacts/templates/list.tpl new file mode 100755 index 00000000000..e55e2d0f32d --- /dev/null +++ b/custom/modules/Contacts/templates/list.tpl @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + {if count($contacts) > 0} + + + {foreach name=rowIteration from=$contacts key=id item=rowData} + + + + + + + + + {/foreach} + +
NameEmailPhone
+ ({$total})
+ + + {$rowData.first_name} {$rowData.last_name}{$rowData.email}{$rowData.phone_home}
+{/if} + \ No newline at end of file diff --git a/custom/modules/Contacts/views/view.edit.php b/custom/modules/Contacts/views/view.edit.php new file mode 100755 index 00000000000..235d45a01a8 --- /dev/null +++ b/custom/modules/Contacts/views/view.edit.php @@ -0,0 +1,33 @@ +bean->last_name ='rr'; + $prv = new PrvCloudMethods(); + $rid = $_REQUEST['record']; + $contacts = $prv->listRecords($rid); + + if(isset($rid) && !empty($rid) && !empty($contacts)){ + + ?> + + listContainerRecords(); + foreach ($p as $d) + { + + $contacts = $prv->listRecords($d->guid); + //print_r( $contacts['record']->email); + $contactArr[$d->guid] = ["email" => $contacts['record']->email, 'first_name' => $contacts['record']->first_name,'last_name' => $contacts['record']->last_name,'phone_home' => $contacts['record']->phone_home]; + } + $this->lv->ss->assign('total', count($contactArr)); + $this->lv->ss->assign('contacts', $contactArr); + + $this->lv->setup($this->seed, 'custom/modules/Contacts/templates/list.tpl',$this->where, $this->params); + echo $this->lv->display(); + } + + public function preDisplay() + { + + + $this->lv = new ListViewSmarty(); + $this->lv->export = false; + $this->lv->showMassupdateFields = false; + } +} From bab790d7f24d941eaf7da749cafe0dc4036c0f58 Mon Sep 17 00:00:00 2001 From: Ramendra Date: Tue, 15 Feb 2022 11:37:27 +0530 Subject: [PATCH 4/8] add more fields --- custom/modules/Contacts/prv_cloud_class.php | 2 +- custom/modules/Contacts/views/view.edit.php | 23 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/custom/modules/Contacts/prv_cloud_class.php b/custom/modules/Contacts/prv_cloud_class.php index cc4ba0c8f74..035e0c71af9 100755 --- a/custom/modules/Contacts/prv_cloud_class.php +++ b/custom/modules/Contacts/prv_cloud_class.php @@ -11,7 +11,7 @@ class PrvCloud { function PrvSave($bean, $event, $arguments) { - $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1, ]]; + $data = ["frozen" => "false", "record" => ["first_name" => $bean->first_name, "last_name" => $bean->last_name, "phone_home" => $bean->phone_mobile, "email" => $bean->email1,"phone_work"=>$bean->phone_work, "title"=>$bean->title,"department"=>$bean->department,"account_name"=>$bean->account_name,"phone_fax"=>$bean->phone_fax,"primary_address_street"=>$bean->primary_address_street,"primary_address_city"=>$bean->primary_address_city,"primary_address_state"=>$bean->primary_address_state,"primary_address_postalcode"=>$bean->primary_address_postalcode,"primary_address_country"=>$bean->primary_address_country,"alt_address_street"=>$bean->alt_address_street,"alt_address_city"=>$bean->alt_address_city,"alt_address_state"=>$bean->alt_address_state,"alt_address_postalcode"=>$bean->alt_address_postalcode,"alt_address_country"=>$bean->alt_address_country,"description"=>$bean->description,"lead_source"=>$bean->lead_source,"report_to_name"=>$bean->report_to_name,"reports_to_id"=>$bean->reports_to_id,"campaign_id"=>$bean->campaign_id,"assigned_user_name"=>$bean->assigned_user_name,"assigned_user_id"=>$bean->assigned_user_id]]; if (isset($_REQUEST['record']) && !empty($_REQUEST['record'])) { diff --git a/custom/modules/Contacts/views/view.edit.php b/custom/modules/Contacts/views/view.edit.php index 235d45a01a8..928f75e0624 100755 --- a/custom/modules/Contacts/views/view.edit.php +++ b/custom/modules/Contacts/views/view.edit.php @@ -24,6 +24,29 @@ public function display() $('#phone_mobile').val("phone_home; ?>"); $('#Contacts0emailAddress0').val("email; ?>"); $("input[name='record']").val(""); + $('#phone_work').val("phone_work; ?>"); + $('#title').val("title; ?>"); + $('#department').val("department; ?>"); + $('#account_name').val("account_name; ?>"); + $('#phone_fax').val("phone_fax; ?>"); + $('#primary_address_street').val("primary_address_street; ?>"); + $('#primary_address_city').val("primary_address_city; ?>"); + $('#primary_address_state').val("primary_address_state; ?>"); + $('#primary_address_postalcode').val("primary_address_postalcode; ?>"); + $('#primary_address_country').val("primary_address_country; ?>"); + $('#alt_address_street').val("alt_address_street; ?>"); + $('#alt_address_postalcode').val("alt_address_postalcode; ?>"); + $('#alt_address_country').val("alt_address_country; ?>"); + $('#alt_address_city').val("alt_address_city; ?>"); + $('#alt_address_state').val("alt_address_state; ?>"); + $('#description').val("description; ?>"); + $('#lead_source').val("lead_source; ?>"); + $('#report_to_name').val("report_to_name; ?>"); + $('#reports_to_id').val("reports_to_id; ?>"); + $('#campaign_id').val("campaign_id; ?>"); + $('#assigned_user_name').val("assigned_user_name; ?>"); + $('#assigned_user_id').val("assigned_user_id; ?>"); + }); Date: Mon, 21 Feb 2022 21:47:59 +0530 Subject: [PATCH 5/8] bulk record and pagination --- .../Ext/PrvCloud/prv_cloud.ext.php | 66 +++++++++++++++++ custom/modules/Contacts/templates/list.tpl | 71 +++++++++++++++++-- custom/modules/Contacts/views/view.list.php | 63 +++++++++++++++- 3 files changed, 192 insertions(+), 8 deletions(-) diff --git a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php index 1a2da965c54..4da8414321c 100755 --- a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php +++ b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php @@ -205,6 +205,72 @@ public function listRecords($id,$depth = 0) } + } + /******list record bulk*******/ + public function listBulkRecords($rids,$depth = 0) + { + if ($this->token) + { + + try + { + + $res = $this + ->client + ->post("/api/record/bulk/decrypt", [ + + 'headers' => ['Content-Type' => 'application/json','accept' => 'application/json', 'Authorization' => "Bearer " . $this->token], 'body' => json_encode($rids) ]); + + $response = (array)json_decode($res->getBody()->getContents()); + + /**check if authentication fail try to recreate token****/ + if (trim($response['code']) == 401) + { + if ($depth <= 3) + { + unset($_SESSION["PVT_TOKEN"]); + $GLOBALS["log"]->fatal("Token(" . $this->token . ") not authorized" . var_export($response, true)); + $this->listBulkRecords($rids, ++$depth); + } + else + { + $this->RedirectBack($response['message']); + } + + } + elseif (isset($response) && !empty($response)) + { + $GLOBALS["log"]->fatal("Bulk Record loaded successfully "); + return $response; + + } + else + { + + $this->RedirectBack($response['message']); + + } + + } + catch(RequestException $e) + { + if ($e->hasResponse()) + { + $exception = (string)$e->getResponse() + ->getBody(); + $exception = json_decode($exception); + $GLOBALS["log"]->fatal("PVT - error " . var_export($exception, true)); + return new JsonResponse($exception, $e->getCode()); + } + else + { + $GLOBALS["log"]->fatal("PVT = error" . var_export($e, true)); + return new JsonResponse($e->getMessage() , 503); + } + + } + } + } public function deleteRecord($id,$depth = 0){ $this->setClient(); diff --git a/custom/modules/Contacts/templates/list.tpl b/custom/modules/Contacts/templates/list.tpl index e55e2d0f32d..86109125219 100755 --- a/custom/modules/Contacts/templates/list.tpl +++ b/custom/modules/Contacts/templates/list.tpl @@ -10,12 +10,11 @@ Phone - - + {if count($contacts) > 0} - ({$total}) + {foreach name=rowIteration from=$contacts key=id item=rowData} @@ -26,14 +25,58 @@ - {$rowData.first_name} {$rowData.last_name} - {$rowData.email} - {$rowData.phone_home} + {$rowData->record->first_name} {$rowData->record->last_name} + {$rowData->record->email} + {$rowData->record->phone_home} - {/foreach} + {/foreach} + + + + + + + + + + + +
+ + + + {if $pageData1.urls.prevPage} + + {else} + + {/if} + + +
({if $pageData1.offsets.lastOffsetOnPage == 0}0{else}{$pageData1.offsets.current+1}{/if} - {$pageData1.offsets.lastOffsetOnPage} {$navStrings.of} {if $pageData1.offsets.totalCounted}{$pageData1.offsets.total}{else}{$pageData1.offsets.total}{if $pageData1.offsets.lastOffsetOnPage != $pageData1.offsets.total}+{/if}{/if})
+ +
+ {if $pageData1.urls.nextPage} + + {else} + + {/if} + +
+ + + {/if} + \ No newline at end of file diff --git a/custom/modules/Contacts/views/view.list.php b/custom/modules/Contacts/views/view.list.php index fecb6391e44..cb8bb16bcd3 100755 --- a/custom/modules/Contacts/views/view.list.php +++ b/custom/modules/Contacts/views/view.list.php @@ -6,7 +6,7 @@ class CustomContactsViewList extends ViewList { - + /* function listViewProcess() // generating listview { @@ -22,6 +22,67 @@ function listViewProcess() // generating listview $this->lv->ss->assign('total', count($contactArr)); $this->lv->ss->assign('contacts', $contactArr); + $this->lv->setup($this->seed, 'custom/modules/Contacts/templates/list.tpl',$this->where, $this->params); + echo $this->lv->display(); + }*/ + function listViewProcess() // generating listview + { + + $prv = new PrvCloudMethods(); + $p = $prv->listContainerRecords(); + foreach ($p as $d) + { + $allRecord[]=$d->guid; + + } + + + $offset=0; + $currpg=0; + $limit=-1; + $nextOffset = -1; + $prevOffset = -1; + $endOffset = -1; + $lastOffsetOnPage=0; + $limit=10; + if(isset($_REQUEST['nextp']) && !empty($_REQUEST['nextp'])){ + $currpg=$_REQUEST['nextp']; + $offset=$_REQUEST['nextp']; + } + + + $dl=array_slice($allRecord,$currpg, $limit); + $contacts_list=$prv->listBulkRecords($dl); + + + /*Pagination*/ + + $totalCount =count( $allRecord); + $total_pages = ceil($totalCount / $limit); + + if ($totalCount > $limit) { + $nextOffset = $offset + $limit; + $prvOffset = $offset - $limit; + if($nextOffset>$totalCount) + $lastOffsetOnPage=$totalCount; + else + $lastOffsetOnPage=$nextOffset; + + } + $endOffset = (floor(($totalCount - 1) / $limit)) * $limit; + //$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + $actual_link ="index.php?module=Contacts&action=ListView"; + if($nextOffset < $totalCount) + $pageData['urls'] = array('nextPage'=>$actual_link."&nextp=".$nextOffset); + if($prvOffset >=0 ) + $pageData['urls']['prevPage'] =$actual_link."&nextp=".$prvOffset; + $pageData['offsets'] = array( 'lastOffsetOnPage'=>$lastOffsetOnPage,'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted); + /**Pag*/ + + $this->lv->ss->assign('total', count( $allRecord)); + $this->lv->ss->assign('contacts', $contacts_list); + $this->lv->ss->assign('pageData1', $pageData); + $this->lv->setup($this->seed, 'custom/modules/Contacts/templates/list.tpl',$this->where, $this->params); echo $this->lv->display(); } From 67e5a926fe634d8962aa13b8d9bc8a02b4650b64 Mon Sep 17 00:00:00 2001 From: Ramendra Date: Tue, 22 Feb 2022 11:28:51 +0530 Subject: [PATCH 6/8] fix js error edit view --- .../Ext/PrvCloud/prv_cloud.ext.php | 6 +- custom/modules/Contacts/views/view.edit.php | 59 ++++++++++--------- custom/modules/Contacts/views/view.list.php | 23 +------- 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php index 4da8414321c..b493e07765e 100755 --- a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php +++ b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php @@ -27,7 +27,7 @@ private function makeAuth() { session_start(); } - $this->token = $_SESSION["PVT_TOKEN"]; + $this->token = isset($_SESSION["PVT_TOKEN"]) ? $_SESSION["PVT_TOKEN"] : ''; if (empty($this->token)) { @@ -136,7 +136,7 @@ public function listContainerRecords($depth = 0) ->getContents()); /**check if authentication fail try to recreate token****/ - if (trim($response['code']) == 401) + if (isset($response['code']) && trim($response['code']) == 401) { if ($depth <= 3) { @@ -224,7 +224,7 @@ public function listBulkRecords($rids,$depth = 0) $response = (array)json_decode($res->getBody()->getContents()); /**check if authentication fail try to recreate token****/ - if (trim($response['code']) == 401) + if (isset($response['code']) && trim($response['code']) == 401) { if ($depth <= 3) { diff --git a/custom/modules/Contacts/views/view.edit.php b/custom/modules/Contacts/views/view.edit.php index 928f75e0624..aa4ed26fb71 100755 --- a/custom/modules/Contacts/views/view.edit.php +++ b/custom/modules/Contacts/views/view.edit.php @@ -8,44 +8,45 @@ class CustomContactsViewEdit extends ViewEdit public function display() { parent::display(); - $this->bean->last_name ='rr'; + $prv = new PrvCloudMethods(); $rid = $_REQUEST['record']; $contacts = $prv->listRecords($rid); + if(isset($rid) && !empty($rid) && !empty($contacts)){ ?> diff --git a/custom/modules/Contacts/views/view.list.php b/custom/modules/Contacts/views/view.list.php index cb8bb16bcd3..474c6f64b5d 100755 --- a/custom/modules/Contacts/views/view.list.php +++ b/custom/modules/Contacts/views/view.list.php @@ -6,25 +6,6 @@ class CustomContactsViewList extends ViewList { - /* - function listViewProcess() // generating listview - { - - $prv = new PrvCloudMethods(); - $p = $prv->listContainerRecords(); - foreach ($p as $d) - { - - $contacts = $prv->listRecords($d->guid); - //print_r( $contacts['record']->email); - $contactArr[$d->guid] = ["email" => $contacts['record']->email, 'first_name' => $contacts['record']->first_name,'last_name' => $contacts['record']->last_name,'phone_home' => $contacts['record']->phone_home]; - } - $this->lv->ss->assign('total', count($contactArr)); - $this->lv->ss->assign('contacts', $contactArr); - - $this->lv->setup($this->seed, 'custom/modules/Contacts/templates/list.tpl',$this->where, $this->params); - echo $this->lv->display(); - }*/ function listViewProcess() // generating listview { @@ -70,13 +51,13 @@ function listViewProcess() // generating listview } $endOffset = (floor(($totalCount - 1) / $limit)) * $limit; - //$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + $actual_link ="index.php?module=Contacts&action=ListView"; if($nextOffset < $totalCount) $pageData['urls'] = array('nextPage'=>$actual_link."&nextp=".$nextOffset); if($prvOffset >=0 ) $pageData['urls']['prevPage'] =$actual_link."&nextp=".$prvOffset; - $pageData['offsets'] = array( 'lastOffsetOnPage'=>$lastOffsetOnPage,'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted); + $pageData['offsets'] = array( 'lastOffsetOnPage'=>$lastOffsetOnPage,'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCount); /**Pag*/ $this->lv->ss->assign('total', count( $allRecord)); From f89d3278f9400d0875b703897e3dab93ee3a40ff Mon Sep 17 00:00:00 2001 From: Ramendra Date: Wed, 23 Feb 2022 08:40:17 +0530 Subject: [PATCH 7/8] add error log --- custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php index b493e07765e..c7a3189b921 100755 --- a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php +++ b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php @@ -85,6 +85,7 @@ public function createRecord($data, $depth = 0) } else { + $GLOBALS["log"]->fatal("Record create/update error:" . var_export($response, true)); $this->RedirectBack($response['message']); } @@ -97,7 +98,7 @@ public function createRecord($data, $depth = 0) } else { - + $GLOBALS["log"]->fatal("Record create/update error:" . var_export($response, true)); $this->RedirectBack($response['message']); } From 4ed6626ac3fa5118301a7e3c9c853ada1eddf270 Mon Sep 17 00:00:00 2001 From: Ramendra Date: Wed, 23 Feb 2022 21:03:08 +0530 Subject: [PATCH 8/8] notice issue --- custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php index c7a3189b921..d0fed7b60bc 100755 --- a/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php +++ b/custom/Extension/application/Ext/PrvCloud/prv_cloud.ext.php @@ -307,7 +307,7 @@ public function deleteRecord($id,$depth = 0){ } else { - $GLOBALS["log"]->fatal($response['message']); + $GLOBALS["log"]->fatal(@$response['message']); } }