Jump to content

Help with Panels


suportgc

Recommended Posts

Hello good day.

 

I wonder what I'm doing wrong.

 

I have the code below

 

<?php
// Desenvolvido por Joel - WHMCS.RED || Modificações de search inteligente feita por Luciano - WHMCS.RED
// Pegar Conexão com Banco de Dados
use WHMCS\Database\Capsule;
// Bloqueia o acesso direto ao arquivo
if (!defined("WHMCS")){
die("Acesso restrito!");
}
// Monta o PIN
function montar_pin($id){
$limite = 8;
$montar = md5($id);
$montar = preg_replace("/[^0-9]/", "", $montar);
$resultado = substr($montar, $limite, $limite);
return $resultado;
}
// Página de Administrador
add_hook("AdminAreaClientSummaryPage", 1, function($vars){
return "<div class='alert alert-success'><strong>PIN: ".montar_pin($vars["userid"])."</strong></div>";
});
// Página do Cliente
add_hook("ClientAreaHomepage", 2, function($vars){
return "<div class='alert alert-success'><i class=\"fa fa-lock\"></i> <strong>CÓDIGO PIN: ".montar_pin($_SESSION["uid"])."</strong></strong></br></br>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.</div>";
});
// Adicionando função de pesquisa do PIN
add_hook("IntelligentSearch", 1, function($vars){
$pesquisa = array();
foreach (capsule::table("tblclients")->get() as $clientes){
	$resultado = montar_pin($clientes->id);
	if($resultado == $vars["searchTerm"]){
		$idcliente = $clientes->id;
		$pin = $resultado;
	}
}
foreach (capsule::table("tblclients")->WHERE("id", $idcliente)->get() as $cliente){
	$pesquisa[] = '
	<div class="searchresult">
		<a href="clientssummary.php?userid='.$cliente->id.'">
			<strong>'.$cliente->firstname.' '.$cliente->lastname.'</strong>
			(PIN: '.$pin.')<br />
			<span class="desc">' . $cliente->email . '</span>
		</a>
	</div>';
}
return $pesquisa;
});
// Adiciona string para os templates de email
add_hook("EmailPreSend", 1, function($vars){
$pinstring = array();
$pinstring["pin"] = montar_pin($vars["userid"]);
return $pinstring; 
});

 

 

I would like to change the part of the code below, to display in a panel.

However, the pin code is not loaded.

 

// Página do Cliente
add_hook("ClientAreaHomepage", 2, function($vars){
return "<div class='alert alert-success'><i class=\"fa fa-lock\"></i> <strong>CÓDIGO PIN: ".montar_pin($_SESSION["uid"])."</strong></strong></br></br>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.</div>";
});

 

 

This is the code I am using.

 

add_hook('ClientAreaHomepagePanels', 1, function($homePagePanels) {
   $newPanel = $homePagePanels->addChild(
       'unique-css-name',
       array(
           'name' => 'Pin',
           'label' => '<strong>CÓDIGO PIN: ".montar_pin($_SESSION["uid"])."</strong>',
           'icon' => 'fa-lock',
           'order' => '99',
           'extras' => array(
               'color' => 'pomegranate',
           ),
       )
   );
// Repeat as needed to add enough children
   $newPanel->addChild(
       'unique-css-name-id1',
       array(
           'label' => '</strong></br></br>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.',
           'order' => 10,
       )
   );
});

 

See how it is displayed

 

Screenshot_1.png

 

Could you help me understand where I'm going wrong?

Link to comment
Share on other sites

the problem might be this line...

 

'label' => '<strong>CÓDIGO PIN: ".montar_pin($_SESSION["uid"])."</strong>',

you've got double quotes in the middle of it, and they should be single (and assuming the panel hook can call the montar function correctly)...

 

'label' => '<strong>CÓDIGO PIN: '.montar_pin($_SESSION["uid"]).'</strong>',

ultimately, the hook below would work independently if you can't get the above working...

 

<?php
add_hook('ClientAreaHomepagePanels', 1, function($homePagePanels) {

   $client = Menu::context('client');
   $limite = 8;
   $resultado = substr(preg_replace("/[^0-9]/", "", md5($client->id)), $limite, $limite);

   $newPanel = $homePagePanels->addChild('panel PIN',
       array(
           'name' => 'Pin',
           'label' => '<strong>CÓDIGO PIN: '.$resultado.'</strong>',
           'icon' => 'fa-lock',
           'order' => '99',
           'extras' => array(
               'color' => 'pomegranate',
           ),
           'bodyHtml' => '<p><small>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.</small></p>'
       )
   );
});

note the changes that I made - my hook is using client->id from the Class docs (though it's value will be the same as the session UID value), and i've used bodyHtml where you were trying to use 'label' to display text in the body of the panel.

 

5ZqeePK.png

Link to comment
Share on other sites

Incredible, worked perfectly.

 

 

Thank you again Brian

 

- - - Updated - - -

 

Brian, if not ask too much, can you tell me how can I make this system generate a pim every 24 hours for example?:

 

Currently it generates a unique and immutable pin.

Link to comment
Share on other sites

And to finish my doubts today.

 

I have a small mistake too.

 

The code below should send the customer his pin by email, but he creates another pin.

 

Did I write something wrong?

 

// Adiciona string para os templates de email
add_hook("EmailPreSend", 1, function($vars){
$pinstring = array();
$pinstring["pin"] = montar_pin($vars["userid"]);
return $pinstring; 
});

 

 

The code below, regarding search works normally

 

// Adicionando função de pesquisa do PIN
add_hook("IntelligentSearch", 1, function($vars){
$pesquisa = array();
foreach (capsule::table("tblclients")->get() as $clientes){
	$resultado = montar_pin($clientes->id);
	if($resultado == $vars["searchTerm"]){
		$idcliente = $clientes->id;
		$pin = $resultado;
	}
}
foreach (capsule::table("tblclients")->WHERE("id", $idcliente)->get() as $cliente){
	$pesquisa[] = '
	<div class="searchresult">
		<a href="clientssummary.php?userid='.$cliente->id.'">
			<strong>'.$cliente->firstname.' '.$cliente->lastname.'</strong>
			(PIN: '.$pin.')<br />
			<span class="desc">' . $cliente->email . '</span>
		</a>
	</div>';
}
return $pesquisa;
});

Link to comment
Share on other sites

Brian, if not ask too much, can you tell me how can I make this system generate a pim every 24 hours for example?:

Currently it generates a unique and immutable pin.

do you need it to generate every 24 hours or do you just need it to be unique each day ?

 

if just unique, why not multiply the client ID by today's date (strtotime) - that way, the PIN will be one number today, tomorrow it will be different...

 

$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);

 

with regards to the email hook, have you confirmed the value of $vars['userid'] is correct?

Link to comment
Share on other sites

Just to understand better.

 

This code

$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);  

 

Generate a new pin for each client, as it multiplies the current code by the value of the day?

 

Would it be this?

 

Ex: Pin 080585 * 27 = 2175795

 

And tomorrow it would be 080585 * 28 = 2256380

 

 

Basically, I would like the system to generate a random pin for every customer every day.

 

Being renovated, to maintain security.

 

So each customer will have a new pin every day.

 

 

About $ vars ['userid'], I believe it is not correct because it displays a different pin.

 

Can you tell me how I can test?

 

Sorry if my English is bad.

I'm Brazilian and I use google translate

Link to comment
Share on other sites

Just to understand better.

 

This code

$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);  

 

Generate a new pin for each client, as it multiplies the current code by the value of the day?

Would it be this?

Ex: Pin 080585 * 27 = 2175795

And tomorrow it would be 080585 * 28 = 2256380

it multiplies the client ID by strtotime(today), so if the client-id equals 123, it will be 123x1503529200 and then converted to an 8-digit PIN... tomorrow, it will be 123x1503615600 and so on...

 

Basically, I would like the system to generate a random pin for every customer every day.

Being renovated, to maintain security.

So each customer will have a new pin every day.

the above would do that - a different PIN value for every client each day... though if they don't use support on a given day, why do they need a new PIN - it would be irrelevant. :?:

 

... but if you're going to email them each day with a new pin, then you might need a cron hook to run the script daily.

 

btw - there are commercial PIN products in Marketplace, so i'm a little uncomfortable discussing how to do this here.

Link to comment
Share on other sites

I tested this code, but it actually generates a unique pin for all clients.

 

I need an individual pin for each customer that is renewed every day or every period of hours.

 

$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);

 

 

 

Also follows the test I did in the email, as you can see, in the admin panel and search, it works normally, however, in the email it takes a crazy code

 

Incorrect pin.png

Correct pin serch.png

Admin pin viewer.png

Edited by suportgc
Link to comment
Share on other sites

I tested this code, but it actually generates a unique pin for all clients.

I need an individual pin for each customer that is renewed every day or every period of hours.

that's what it will do... each client has a unique code that changes daily... here's 2 clients from my v7.2.3 dev... if I visit the homepage tomorrow, those values will be different.

 

xRfl8ml.pngcCfFc26.png

Link to comment
Share on other sites

How strange, is it that I put your code in the wrong place or did something different.

 

Here's how I left the code.

 

// Monta o PIN
function montar_pin($id){
$limite = 8;
$montar = md5($id);
$montar = preg_replace("/[^0-9]/", "", $montar);
$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);
return $resultado;
}

0.png

1.png

 

 

As for sending to email, I was able to find the solution.

 

Double quotes again

 

comparison

montar_pin($vars["userid"])

montar_pin($vars['pincode'])

 

 

// Adiciona string para os templates de email
add_hook("EmailPreSend", 1, function($vars){
$pinstring = array();
$pinstring["pin"] = montar_pin($vars['pincode']);
return $pinstring;
});

 

- - - Updated - - -

 

Sorry if I left you uncomfortable with the questions.

I'm just curious.

 

This configuration that you proposed is perfect for what I need.

 

Just generate a new daily code, as is happening with your current one.

 

To end our chat, can you just tell me how to use the code below?

 

$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);

 

 

// Monta o PIN
function montar_pin($id){
$limite = 8;
$montar = md5($id);
$montar = preg_replace("/[^0-9]/", "", $montar);
$resultado = substr(preg_replace("/[^0-9]/", "", md5(($client->id)*strtotime(today))), $limite, $limite);
return $resultado;
}

Edited by suportgc
Link to comment
Share on other sites

Hello, good night friend.

 

I was able to solve the problem with the code below

 

// Monta o PIN Modelo novo (Renova a cada dia)
function montar_pin($id){
$limite = 8;
$resultado = substr(preg_replace("/[^0-9]/", "", md5(($id)*strtotime(today))), $limite, $limite);
return $resultado;
}

 

The error was at this point

md5(($id)

 

 

A doubt, with the current code it is possible to create a button, for the client to click and generate a new pin, with the same logic, but multiplied by the hour?

 

Ex: Create new PIN

 

// Botão Novo Pin
function montar_pin($id){
$limite = 8;
$resultado = substr(preg_replace("/[^0-9]/", "", md5(($id)*strtotime(date('Y-m-d H:i:s')))), $limite, $limite);
return $resultado;
}

 

How would it be to create a new button that performs this function?

 

 

If it is possible to create this button that generates a new pon every click (Multiplying by date and time) I would not need to display the pin to the client.

 

It only appears if it clicks generate pin

Edited by suportgc
Link to comment
Share on other sites

Can you share you code for the admin template to display the clients PIN code ?

 

 

Hello how are you.

Yes, this function is already implemented.

Just like pin searching, see

 

 

// Admin Page
add_hook("AdminAreaClientSummaryPage", 1, function($vars){
return "<div class='alert alert-success'><strong>PIN: ".montar_pin($vars["userid"])."</strong></div>";
});

// Admin search
add_hook("IntelligentSearch", 1, function($vars){
$pesquisa = array();
foreach (capsule::table("tblclients")->get() as $clientes){
	$resultado = montar_pin($clientes->id);
	if($resultado == $vars["searchTerm"]){
		$idcliente = $clientes->id;
		$pin = $resultado;
	}
}
foreach (capsule::table("tblclients")->WHERE("id", $idcliente)->get() as $cliente){
	$pesquisa[] = '
	<div class="searchresult">
		<a href="clientssummary.php?userid='.$cliente->id.'">
			<strong>'.$cliente->firstname.' '.$cliente->lastname.'</strong>
			(PIN: '.$pin.')<br />
			<span class="desc">' . $cliente->email . '</span>
		</a>
	</div>';
}
return $pesquisa;
});

Link to comment
Share on other sites

It would be interesting too, display this pin on the sidebar

As in the photo below,

Screenshot_3.png

 

including the button on the footer, as in this one

Screenshot_4.png

 

 

Unfortunately my knowledge is limited to insert this set in the sidebar

 

 

I got up to the header and body, however, I could not get the footer

 

 

 

If any of you know how I can do this, I am immensely grateful.

 

I really need help with this encoding.

 

The button to generate the pin is a priority and will help a lot

Link to comment
Share on other sites

<?php

add_hook('ClientAreaHomepagePanels', 1, function($homePagePanels) {

   $client = Menu::context('client');
   $limite = 8;
   $resultado = substr(preg_replace("/[^0-9]/", "", md5($client->id)), $limite, $limite);

   $newPanel = $homePagePanels->addChild('panel PIN',
       array(
           'name' => 'Pin',
           'label' => '<strong>CÓDIGO PIN: '.$resultado.'</strong>',
           'icon' => 'fa-lock',
           'order' => '99',
           'extras' => array(
               'color' => 'pomegranate',
           ),
           'bodyHtml' => '<p><small>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.</small></p>'
       )

   );
   // Admin Page
add_hook("AdminAreaClientSummaryPage", 1, function($vars){
   return "<div class='alert alert-success'><strong>PIN: ".montar_pin($vars["userid"])."</strong></div>";
});


// Admin search
add_hook("IntelligentSearch", 1, function($vars){
   $pesquisa = array();
   foreach (capsule::table("tblclients")->get() as $clientes){
       $resultado = montar_pin($clientes->id);
       if($resultado == $vars["searchTerm"]){
           $idcliente = $clientes->id;
           $pin = $resultado;
       }
   }
   foreach (capsule::table("tblclients")->WHERE("id", $idcliente)->get() as $cliente){
       $pesquisa[] = '
       <div class="searchresult">
           <a href="clientssummary.php?userid='.$cliente->id.'">
               <strong>'.$cliente->firstname.' '.$cliente->lastname.'</strong>
               (PIN: '.$pin.')<br />
               <span class="desc">' . $cliente->email . '</span>
           </a>
       </div>';
   }
   return $pesquisa;
});

});

 

This is what I have and its not showing on the admin area client summery page at all. Also when I search the Pin Code, it is not found.

Link to comment
Share on other sites

<?php

add_hook('ClientAreaHomepagePanels', 1, function($homePagePanels) {

   $client = Menu::context('client');
   $limite = 8;
   $resultado = substr(preg_replace("/[^0-9]/", "", md5($client->id)), $limite, $limite);

   $newPanel = $homePagePanels->addChild('panel PIN',
       array(
           'name' => 'Pin',
           'label' => '<strong>CÓDIGO PIN: '.$resultado.'</strong>',
           'icon' => 'fa-lock',
           'order' => '99',
           'extras' => array(
               'color' => 'pomegranate',
           ),
           'bodyHtml' => '<p><small>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.</small></p>'
       )

   );
   // Admin Page
add_hook("AdminAreaClientSummaryPage", 1, function($vars){
   return "<div class='alert alert-success'><strong>PIN: ".montar_pin($vars["userid"])."</strong></div>";
});


// Admin search
add_hook("IntelligentSearch", 1, function($vars){
   $pesquisa = array();
   foreach (capsule::table("tblclients")->get() as $clientes){
       $resultado = montar_pin($clientes->id);
       if($resultado == $vars["searchTerm"]){
           $idcliente = $clientes->id;
           $pin = $resultado;
       }
   }
   foreach (capsule::table("tblclients")->WHERE("id", $idcliente)->get() as $cliente){
       $pesquisa[] = '
       <div class="searchresult">
           <a href="clientssummary.php?userid='.$cliente->id.'">
               <strong>'.$cliente->firstname.' '.$cliente->lastname.'</strong>
               (PIN: '.$pin.')<br />
               <span class="desc">' . $cliente->email . '</span>
           </a>
       </div>';
   }
   return $pesquisa;
});

});

 

This is what I have and its not showing on the admin area client summery page at all. Also when I search the Pin Code, it is not found.

 

 

 

Try this.

 

This is the complete code

 

 

<?php
// Desenvolvido por Joel - WHMCS.RED || Modificações de search inteligente feita por Luciano - WHMCS.RED
// Pegar Conexão com Banco de Dados
use WHMCS\Database\Capsule;
// Bloqueia o acesso direto ao arquivo
if (!defined("WHMCS")){
die("Acesso restrito!");
}
// Monta o PIN
//function montar_pin($id){
//	$limite = 8;
//	$montar = md5($id);
//	$montar = preg_replace("/[^0-9]/", "", $montar);
//	$resultado = substr($montar, $limite, $limite);
//	return $resultado;

// Monta o PIN Modelo novo (Renova a cada dia)
function montar_pin($id){
$limite = 8;
$resultado = substr(preg_replace("/[^0-9]/", "", md5(($id)*strtotime(today))), $limite, $limite);
return $resultado;
}
// Página de Administrador
add_hook("AdminAreaClientSummaryPage", 1, function($vars){
return "<div class='alert alert-success'><strong>PIN: ".montar_pin($vars["userid"])."</strong></div>";
});

//Pagina do Cliente Painel
add_hook('ClientAreaHomepagePanels', 1, function($homePagePanels) {
   $newPanel = $homePagePanels->addChild(
       'unique-css-name',
       array(
           'name' => 'Pin',
           'label' => '<strong>CÓDIGO PIN: '.montar_pin($_SESSION["uid"]).'</strong>',  
           'icon' => 'fa-lock',
           'order' => '99',
           'extras' => array(
               'color' => 'green',
           ),
           'footerHtml' => '<i class="fa fa-info-circle" aria-hidden="true"></i>  <strong>Um novo PIN será gerado todos os dias!</strong>',
       )
   );
// Repeat as needed to add enough children
   $newPanel->addChild(
       'unique-css-name-id1',
       array(
           'label' => '</strong>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos. Por exemplo, em atendimentos via E-mail ou Chat Online.',
           'order' => 10,
       )
   );
});

// Página do Cliente
//add_hook("ClientAreaHomepage", 2, function($vars){
//	return "<div class='alert alert-success'><i class=\"fa fa-lock\"></i> <strong>CÓDIGO PIN: ".montar_pin($_SESSION["uid"])."</strong></strong></br></br>Forneça este código, quando solicitado pela nossa equipe de atendimento. Por questões de segurança, ele será solicitado em determinados tipos de atendimentos, por exemplo em atendimentos via E-mail ou Chat Online.</div>";
//});

// Adicionando função de pesquisa do PIN
add_hook("IntelligentSearch", 1, function($vars){
$pesquisa = array();
foreach (capsule::table("tblclients")->get() as $clientes){
	$resultado = montar_pin($clientes->id);
	if($resultado == $vars["searchTerm"]){
		$idcliente = $clientes->id;
		$pin = $resultado;
	}
}
foreach (capsule::table("tblclients")->WHERE("id", $idcliente)->get() as $cliente){
	$pesquisa[] = '
	<div class="searchresult">
		<a href="clientssummary.php?userid='.$cliente->id.'">
			<strong>'.$cliente->firstname.' '.$cliente->lastname.'</strong>
			(PIN: '.$pin.')<br />
			<span class="desc">' . $cliente->email . '</span>
		</a>
	</div>';
}
return $pesquisa;
});
// Adiciona string para os templates de email
add_hook("EmailPreSend", 1, function($vars){
$pinstring = array();
$pinstring["pin"] = montar_pin($vars['relid']);
return $pinstring;
});

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated