Skip to content

Commit

Permalink
v 0.8.0
Browse files Browse the repository at this point in the history
Random assignation to an owner
  • Loading branch information
Darklg committed Sep 16, 2024
1 parent e04df9c commit 133c0d8
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lang/wpucontactforms_zohocrm-fr_FR.l10n.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['Help'=>'Aide','Settings'=>'Réglages','No'=>'Non','Yes'=>'Oui','Check all'=>'Tout cocher','Uncheck all'=>'Tout décocher','Settings saved.'=>'Paramètres sauvegardés.','Upload New Media'=>'Envoi d\'un nouveau média','Language'=>'Langue','Save'=>'Sauvegarder','Submit'=>'Envoyer','Previous'=>'Précédent','Next'=>'Suivant','The field “%s” is required'=>'Le champ « %s » est obligatoire','The field “%s” should be an email'=>'Le champ « %s » doit être un email','The plugin <b>%s</b> depends on the following plugins. Please install and activate them:'=>'Le plugin <b>%s</b> dépend des plugins suivants. Veuillez les installer et les activer :','The plugin <b>%s</b> depends on the <b>%s</b> plugin. Please install and activate it.'=>'Le plugin <b>%s</b> dépend du plugin <b>%s</b>. Merci de l’installer et de l’activer.','Connect WPU Contact Forms to ZohoCRM'=>'Connecter WPU Contact Forms à ZohoCRM','App Settings'=>'Paramètre de l\'App','Plugin Settings'=>'Paramètres du plugin','Token Settings'=>'Paramètres du token','Client ID'=>'Client ID','Client Secret'=>'Client Secret','Update Records'=>'Mettre à jour les enregistrements','Access token'=>'Access token','Token expiration'=>'Expiration du token','Last update'=>'Dernière mise à jour','Refresh token'=>'Refresh token','Accounts server'=>'Accounts server','API Domain'=>'API Domain','Token was successfully updated.'=>'Le token a été mis à jour avec succès.','Refresh your access token'=>'Actualiser votre access token','Last update: %s ago.'=>'Dernière mise à jour : il y a %s.','No application installed'=>'Aucune application installée','Please <a target="_blank" href="%s">create an new Server-based application here</a> and specify the following redirect_uri : <br /><strong contenteditable>%s</strong>'=>'Veuillez <a target="_blank" href="%s">créer une nouvelle application « server-based » ici</a> en spécifiant la redirect_uri suivante : <br /><strong contenteditable>%s</strong>','Get the client ID and client Secret and paste it below.'=>'Obtenez le client ID et le client Secret et collez-les ci-dessous.','Connect to your account'=>'Connectez-vous à votre compte','Connection seems to work'=>'La connexion semble fonctionner','Test the API'=>'Tester l’API','Create or update a test lead.'=>'Créez ou mettez à jour un prospect de test.','Fields'=>'Champs','You can map your contact form fields to ZohoCRM fields.'=>'Vous pouvez mapper les champs de votre formulaire de contact aux champs ZohoCRM.','Map fields'=>'Mapper les champs','Update fields'=>'Actualiser les champs','Fields list'=>'Liste des champs','API Test : <a href="%s" target="_blank">View the lead</a>'=>'Test API : <a href="%s" target="_blank">Voir le lead</a>','Fields have been updated'=>'Les champs ont été mis à jour','Save Changes'=>'Sauvegarder','An error occured while refreshing the token.'=>'Une erreur s’est produite lors de l’actualisation du token.','The response did not contain a token.'=>'La réponse ne contenait pas de token.','There was an error'=>'Il y a eu une erreur'],'language'=>'fr_FR','x-generator'=>'Poedit 3.5'];
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['Help'=>'Aide','Settings'=>'Réglages','No'=>'Non','Yes'=>'Oui','Check all'=>'Tout cocher','Uncheck all'=>'Tout décocher','Settings saved.'=>'Paramètres sauvegardés.','Upload New Media'=>'Envoi d\'un nouveau média','Language'=>'Langue','Save'=>'Sauvegarder','Submit'=>'Envoyer','Previous'=>'Précédent','Next'=>'Suivant','The field “%s” is required'=>'Le champ « %s » est obligatoire','The field “%s” should be an email'=>'Le champ « %s » doit être un email','The plugin <b>%s</b> depends on the following plugins. Please install and activate them:'=>'Le plugin <b>%s</b> dépend des plugins suivants. Veuillez les installer et les activer :','The plugin <b>%s</b> depends on the <b>%s</b> plugin. Please install and activate it.'=>'Le plugin <b>%s</b> dépend du plugin <b>%s</b>. Merci de l’installer et de l’activer.','Connect WPU Contact Forms to ZohoCRM'=>'Connecter WPU Contact Forms à ZohoCRM','App Settings'=>'Paramètre de l\'App','Plugin Settings'=>'Paramètres du plugin','Token Settings'=>'Paramètres du token','Client ID'=>'Client ID','Client Secret'=>'Client Secret','Update Records'=>'Mettre à jour les enregistrements','Access token'=>'Access token','Token expiration'=>'Expiration du token','Last update'=>'Dernière mise à jour','Refresh token'=>'Refresh token','Accounts server'=>'Accounts server','API Domain'=>'API Domain','Owners'=>'Propriétaires','Randomly assign to %s'=>'Attribuer au hasard à %s','Token was successfully updated.'=>'Le token a été mis à jour avec succès.','Refresh your access token'=>'Actualiser votre access token','Last update: %s ago.'=>'Dernière mise à jour : il y a %s.','No application installed'=>'Aucune application installée','Please <a target="_blank" href="%s">create an new Server-based application here</a> and specify the following redirect_uri : <br /><strong contenteditable>%s</strong>'=>'Veuillez <a target="_blank" href="%s">créer une nouvelle application « server-based » ici</a> en spécifiant la redirect_uri suivante : <br /><strong contenteditable>%s</strong>','Get the client ID and client Secret and paste it below.'=>'Obtenez le client ID et le client Secret et collez-les ci-dessous.','Connect to your account'=>'Connectez-vous à votre compte','Connection seems to work'=>'La connexion semble fonctionner','Test the API'=>'Tester l’API','Create or update a test lead.'=>'Créez ou mettez à jour un prospect de test.','Users'=>'Utilisateurs','You can get a list of active users in Zoho.'=>'Vous pouvez obtenir une liste d’utilisateurs actifs dans Zoho.','Get users'=>'Obtenir des utilisateurs','Update users'=>'Actualiser les utilisateurs/utilisatrices','Users list'=>'Liste des Utilisateurs','Fields'=>'Champs','You can map your contact form fields to ZohoCRM fields.'=>'Vous pouvez mapper les champs de votre formulaire de contact aux champs ZohoCRM.','Map fields'=>'Mapper les champs','Update fields'=>'Actualiser les champs','Fields list'=>'Liste des champs','API Test : <a href="%s" target="_blank">View the lead</a>'=>'Test API : <a href="%s" target="_blank">Voir le lead</a>','Fields have been updated'=>'Les champs ont été mis à jour','Users have been updated'=>'Les utilisateurs ont été mis à jour','Save Changes'=>'Sauvegarder','An error occured while refreshing the token.'=>'Une erreur s’est produite lors de l’actualisation du token.','The response did not contain a token.'=>'La réponse ne contenait pas de token.','There was an error'=>'Il y a eu une erreur'],'language'=>'fr_FR','x-generator'=>'Poedit 3.5'];
Binary file modified lang/wpucontactforms_zohocrm-fr_FR.mo
Binary file not shown.
77 changes: 55 additions & 22 deletions lang/wpucontactforms_zohocrm-fr_FR.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: WPU Contact Forms ZohoCRM\n"
"POT-Creation-Date: 2024-09-10 17:30+0200\n"
"POT-Creation-Date: 2024-09-16 15:26+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -155,24 +155,33 @@ msgstr "Accounts server"
msgid "API Domain"
msgstr "API Domain"

#: .././wpucontactforms_zohocrm.php:226 .././wpucontactforms_zohocrm.php:507
#: .././wpucontactforms_zohocrm.php:164
msgid "Owners"
msgstr "Propriétaires"

#: .././wpucontactforms_zohocrm.php:170
#, php-format
msgid "Randomly assign to %s"
msgstr "Attribuer au hasard à %s"

#: .././wpucontactforms_zohocrm.php:242 .././wpucontactforms_zohocrm.php:622
msgid "Token was successfully updated."
msgstr "Le token a été mis à jour avec succès."

#: .././wpucontactforms_zohocrm.php:231
#: .././wpucontactforms_zohocrm.php:247
msgid "Refresh your access token"
msgstr "Actualiser votre access token"

#: .././wpucontactforms_zohocrm.php:233
#: .././wpucontactforms_zohocrm.php:249
#, php-format
msgid "Last update: %s ago."
msgstr "Dernière mise à jour : il y a %s."

#: .././wpucontactforms_zohocrm.php:237
#: .././wpucontactforms_zohocrm.php:253
msgid "No application installed"
msgstr "Aucune application installée"

#: .././wpucontactforms_zohocrm.php:238
#: .././wpucontactforms_zohocrm.php:254
#, php-format
msgid ""
"Please <a target=\"_blank\" href=\"%s\">create an new Server-based "
Expand All @@ -183,70 +192,94 @@ msgstr ""
"« server-based » ici</a> en spécifiant la redirect_uri suivante : <br /"
"><strong contenteditable>%s</strong>"

#: .././wpucontactforms_zohocrm.php:239
#: .././wpucontactforms_zohocrm.php:255
msgid "Get the client ID and client Secret and paste it below."
msgstr "Obtenez le client ID et le client Secret et collez-les ci-dessous."

#: .././wpucontactforms_zohocrm.php:243
#: .././wpucontactforms_zohocrm.php:259
msgid "Connect to your account"
msgstr "Connectez-vous à votre compte"

#: .././wpucontactforms_zohocrm.php:245
#: .././wpucontactforms_zohocrm.php:261
msgid "Connection seems to work"
msgstr "La connexion semble fonctionner"

#: .././wpucontactforms_zohocrm.php:259 .././wpucontactforms_zohocrm.php:261
#: .././wpucontactforms_zohocrm.php:277 .././wpucontactforms_zohocrm.php:279
msgid "Test the API"
msgstr "Tester l’API"

#: .././wpucontactforms_zohocrm.php:260
#: .././wpucontactforms_zohocrm.php:278
msgid "Create or update a test lead."
msgstr "Créez ou mettez à jour un prospect de test."

#: .././wpucontactforms_zohocrm.php:265
#: .././wpucontactforms_zohocrm.php:284
msgid "Users"
msgstr "Utilisateurs"

#: .././wpucontactforms_zohocrm.php:285
msgid "You can get a list of active users in Zoho."
msgstr "Vous pouvez obtenir une liste d’utilisateurs actifs dans Zoho."

#: .././wpucontactforms_zohocrm.php:287
msgid "Get users"
msgstr "Obtenir des utilisateurs"

#: .././wpucontactforms_zohocrm.php:289
msgid "Update users"
msgstr "Actualiser les utilisateurs/utilisatrices"

#: .././wpucontactforms_zohocrm.php:291
msgid "Users list"
msgstr "Liste des Utilisateurs"

#: .././wpucontactforms_zohocrm.php:303
msgid "Fields"
msgstr "Champs"

#: .././wpucontactforms_zohocrm.php:266
#: .././wpucontactforms_zohocrm.php:304
msgid "You can map your contact form fields to ZohoCRM fields."
msgstr ""
"Vous pouvez mapper les champs de votre formulaire de contact aux champs "
"ZohoCRM."

#: .././wpucontactforms_zohocrm.php:269
#: .././wpucontactforms_zohocrm.php:307
msgid "Map fields"
msgstr "Mapper les champs"

#: .././wpucontactforms_zohocrm.php:271
#: .././wpucontactforms_zohocrm.php:309
msgid "Update fields"
msgstr "Actualiser les champs"

#: .././wpucontactforms_zohocrm.php:283
#: .././wpucontactforms_zohocrm.php:321
msgid "Fields list"
msgstr "Liste des champs"

#: .././wpucontactforms_zohocrm.php:316
#: .././wpucontactforms_zohocrm.php:354
#, php-format
msgid "API Test : <a href=\"%s\" target=\"_blank\">View the lead</a>"
msgstr "Test API : <a href=\"%s\" target=\"_blank\">Voir le lead</a>"

#: .././wpucontactforms_zohocrm.php:325
#: .././wpucontactforms_zohocrm.php:363
msgid "Fields have been updated"
msgstr "Les champs ont été mis à jour"

#: .././wpucontactforms_zohocrm.php:337
#: .././wpucontactforms_zohocrm.php:381
msgid "Users have been updated"
msgstr "Les utilisateurs ont été mis à jour"

#: .././wpucontactforms_zohocrm.php:393
msgid "Save Changes"
msgstr "Sauvegarder"

#: .././wpucontactforms_zohocrm.php:392
#: .././wpucontactforms_zohocrm.php:502
msgid "An error occured while refreshing the token."
msgstr "Une erreur s’est produite lors de l’actualisation du token."

#: .././wpucontactforms_zohocrm.php:397
#: .././wpucontactforms_zohocrm.php:507
msgid "The response did not contain a token."
msgstr "La réponse ne contenait pas de token."

#: .././wpucontactforms_zohocrm.php:510
#: .././wpucontactforms_zohocrm.php:625
msgid "There was an error"
msgstr "Il y a eu une erreur"

Expand Down
2 changes: 2 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
$options = array(
'wpucontactforms_zohocrm_options',
'wpucontactforms_zohocrm_fields',
'wpucontactforms_zohocrm_users',
'wpucontactforms_zohocrm_last_owner',
'wpucontactforms_zohocrm__cron_hook_croninterval',
'wpucontactforms_zohocrm__cron_hook_lastexec'
);
Expand Down
119 changes: 117 additions & 2 deletions wpucontactforms_zohocrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/WordPressUtilities/wpucontactforms_zohocrm
Update URI: https://github.com/WordPressUtilities/wpucontactforms_zohocrm
Description: Connect WPU Contact Forms to ZohoCRM
Version: 0.7.2
Version: 0.8.0
Author: darklg
Author URI: https://darklg.me/
Text Domain: wpucontactforms_zohocrm
Expand All @@ -27,7 +27,7 @@ class WPUContactFormsZohoCRM {
public $basecron;
public $settings_update;
private $user_level = 'manage_options';
private $plugin_version = '0.7.2';
private $plugin_version = '0.8.0';
private $plugin_settings = array(
'id' => 'wpucontactforms_zohocrm',
'name' => 'WPU Contact Forms - ZohoCRM'
Expand Down Expand Up @@ -158,6 +158,22 @@ public function plugins_loaded() {
'section' => 'token'
)
);
$users = $this->get_owners();
if ($users) {
$this->settings_details['sections']['owners'] = array(
'name' => __('Owners', 'wpucontactforms_zohocrm'),
'wpubasesettings_checkall' => true
);
foreach ($users as $user_id => $user) {
$this->settings['owner_' . $user_id] = array(
'label' => $user,
'label_check' => sprintf(__('Randomly assign to %s', 'wpucontactforms_zohocrm'), $user),
'section' => 'owners',
'type' => 'checkbox'
);
}
}

require_once __DIR__ . '/inc/WPUBaseSettings/WPUBaseSettings.php';
$this->settings_obj = new \wpucontactforms_zohocrm\WPUBaseSettings($this->settings_details, $this->settings);
require_once __DIR__ . '/inc/WPUBaseCron/WPUBaseCron.php';
Expand Down Expand Up @@ -250,6 +266,8 @@ public function page_content__main() {
if ($token_validity == 'valid') {
$this->page_content__main__display_api_test();
echo '<hr />';
$this->page_content__main__display_users();
echo '<hr />';
$this->page_content__main__display_fields();
}
}
Expand All @@ -261,6 +279,26 @@ public function page_content__main__display_api_test() {
submit_button(__('Test the API', 'wpucontactforms_zohocrm'), 'primary', 'test_connection', false);
}

public function page_content__main__display_users() {

echo '<h3>' . __('Users', 'wpucontactforms_zohocrm') . '</h3>';
echo '<p>' . __('You can get a list of active users in Zoho.', 'wpucontactforms_zohocrm') . '</p>';
$users = $this->get_owners();
$label_button = __('Get users', 'wpucontactforms_zohocrm');
if ($users) {
$label_button = __('Update users', 'wpucontactforms_zohocrm');
echo '<details style="margin:1em 0">';
echo '<summary>' . __('Users list', 'wpucontactforms_zohocrm') . '</summary>';
echo '<ul>';
foreach ($users as $user_id => $user) {
echo '<li>' . $user_id . ' : ' . $user . '</li>';
}
echo '</ul>';
echo '</details>';
}
submit_button($label_button, 'primary', 'update_users', false);
}

public function page_content__main__display_fields() {
echo '<h3>' . __('Fields', 'wpucontactforms_zohocrm') . '</h3>';
echo '<p>' . __('You can map your contact form fields to ZohoCRM fields.', 'wpucontactforms_zohocrm') . '</p>';
Expand Down Expand Up @@ -325,6 +363,24 @@ public function page_action__main() {
$this->set_message('map_fields', __('Fields have been updated', 'wpucontactforms_zohocrm'), 'updated');
}
}

if (isset($_POST['update_users'])) {
$req_search_users = $this->build_request('/users', 'GET');
if (!is_wp_error($req_search_users)) {
$users_details = json_decode(wp_remote_retrieve_body($req_search_users), 1);
$main_user_list = array();
if ($users_details && isset($users_details['users'])) {
foreach ($users_details['users'] as $user) {
if ($user['status'] != 'active') {
continue;
}
$main_user_list["user-" . $user['id']] = $user['full_name'];
}
}
update_option('wpucontactforms_zohocrm_users', $main_user_list, false);
$this->set_message('update_users', __('Users have been updated', 'wpucontactforms_zohocrm'), 'updated');
}
}
}

/* Settings
Expand All @@ -338,6 +394,60 @@ public function page_content__settings() {
echo '</form>';
}

/* ----------------------------------------------------------
Owners
---------------------------------------------------------- */

/* Retrieve a list of all owners
-------------------------- */

public function get_owners() {
$users = get_option('wpucontactforms_zohocrm_users');
if (!$users) {
return array();
}
return $users;
}

/* Get a random owner
-------------------------- */

public function get_random_owner() {
$default_users = $this->get_owners();
if (!$default_users || !is_array($default_users)) {
return false;
}

/* Get active users */
$active_users = array();
$settings = $this->settings_obj->get_settings();

foreach ($default_users as $user_id => $user) {
if (isset($settings['owner_' . $user_id]) && $settings['owner_' . $user_id] == '1') {
$active_users[$user_id] = $user;
}
}

/* Use default user */
if (empty($active_users)) {
return false;
}

/* Return only selected user */
if (count($active_users) < 2) {
return key($active_users);
}
/* Remove last owner from choice */
$last_owner = get_option('wpucontactforms_zohocrm_last_owner');
if ($last_owner && $active_users[$last_owner]) {
unset($active_users[$last_owner]);
}
/* Get a random owner */
$user_id = array_rand($active_users);
update_option('wpucontactforms_zohocrm_last_owner', $user_id, false);
return $user_id;
}

/* ----------------------------------------------------------
Contact
---------------------------------------------------------- */
Expand Down Expand Up @@ -416,6 +526,11 @@ public function create_or_update_lead($data = array(), $return_data = false) {
$this->refresh_token();
}

$owner_id = $this->get_random_owner();
if ($owner_id) {
$data['Owner'] = (int) str_replace('user-', '', $owner_id);
}

$settings = $this->settings_obj->get_settings();
$access_token = $this->settings_obj->get_setting('access_token');
$api_domain = $this->settings_obj->get_setting('api_domain');
Expand Down

0 comments on commit 133c0d8

Please sign in to comment.