VTiger: Workflow - Invoke Custom Function - php

I'm trying to setup workflow in vtiger that export invoice to pdf once the invoice has certain status.
To do it, I was thinking of using the "Invoke Custom Function". There is a documentation on it, but it is not clear, like: where/which file to register the event manager??
I also found that the same questions was actually asked and solved by another person, but when i opened the link in the post, it direct me to "Page not found" error.

require_once 'include/utils/utils.php';
require 'modules/com_vtiger_workflow/VTEntityMethodManager.inc';
$emm = new VTEntityMethodManager($adb);
//$emm->addEntityMethod("Module Name","Label", "Path to file" , "Method Name" );
$emm->addEntityMethod("Invoice", "Update Inventory", "include/InventoryHandler.php", "handleInventoryProductRel");
Add these lines of code in a php file replace with your module name, label,path,method name and add the file to vtiger instance, run the file. It will be added in database table "com_vtiger_workflowtasks_entitymethod". You can use now your invoke custom function in workflow section for the particular module.

done all according to Answer before
<?php
require_once 'include/utils/utils.php';
require 'modules/com_vtiger_workflow/VTEntityMethodManager.inc';
$emm = new VTEntityMethodManager($adb);
#addEntityMethod("Module", "LABEL", "FILENAME", "FUNCTION_NAME");
$emm->addEntityMethod("Accounts", "Update Account","modules/Accounts/updateAccountData.php", "updateAccountData");
?>
2- This file was executed by http://IP/registerworkflow.php
and i can see Update Account in custom Script
3- create simple function
<?php
function updateAccountData($entity){
$file = '/tmp/people.txt';
$current = file_get_contents($file);
$current .= "John Smith\n";
file_put_contents($file, __LINE__.':'.print_r($current, true)."\r\n");
}
?>
4-file /tmp/people.txt was created by me and 777 chmod
5- email send was added to test workflow is executed
(so first step execute Update Account function second email )
But strange is that i can reseive imail but script not put data to a test file

Related

PHP: Can anyone help me how to create a payment request using wysow repository?

I'm trying to figure out how to include PostFinance (Swiss Bank) payment processor, but unfortunately it is a very unclear documentation here and I cannot figure out how to handle it.
I found a repo https://github.com/wysow/wysow-postfinance
so if there're some php experts out there, I would appreciate if you can give me an example code to include on my clean index.php file, based on this library.
I already installed composer and included the library, but cannot make a test payment.
Last code I tried is the example in README file:
<?php
require 'vendor/autoload.php';
use PostFinance\Passphrase;
use PostFinance\Ecommerce\EcommercePaymentRequest;
use PostFinance\ShaComposer\AllParametersShaComposer;
use PostFinance\FormGenerator\SimpleFormGenerator;
$passphrase = new Passphrase('MySecretSig123');
$shaComposer = new AllParametersShaComposer($passphrase);
//$shaComposer->addParameterFilter(new ShaInParameterFilter); //optional
$ecommercePaymentRequest = new EcommercePaymentRequest($shaComposer);
// Optionally set PostFinance uri, defaults to TEST account
//$ecommercePaymentRequest->setPostFinanceUri(EcommercePaymentRequest::PRODUCTION);
// Set various params:
$ecommercePaymentRequest->setPspid('mypspid');
$ecommercePaymentRequest->setOrderid('123456');
$ecommercePaymentRequest->setAmount(1500); // in cents
$ecommercePaymentRequest->setCurrency('EUR');
// ...
$ecommercePaymentRequest->validate();
$formGenerator = new SimpleFormGenerator;
$html = $formGenerator->render($ecommercePaymentRequest);
echo $html;
// Or use your own generator. Or pass $ecommercePaymentRequest to a view
?>
But the result is showing that it doesn't send all information, like total amount and beneficiary.
How do I fix that?

Send a mail to Admin with a BO link to specific customer in Prestashop 1.6

In Prestashop 1.6, from a FrontController, I have to send a mail to the administrator of the Shop.
This part works well but I got problems to include a link to the administration page of a specific customer.
The only thing I miss is the name of the administration directory. I would be able to parse and concatenate the PS_ADMIN_DIR constant but it is not available from the FrontController.
I'm kinda stuck here.
Here is the code :
$admin_customer_link =
_PS_BASE_URL_
.__PS_BASE_URI__
/* Missing the Administration directory name here */
.$this->context->link->getAdminLink('AdminCustomers', false)
."&id_customer=".(int)$customer->id."&viewcustomer";
The output I got :
http://127.0.0.1:8080/prestashop/index.php?controller=AdminCustomers&id_customer=2&viewcustomer
The output I need :
http://127.0.0.1:8080/prestashop/administration/index.php?controller=AdminCustomers&id_customer=2&viewcustomer
Any help will be appreciated.
There is no (standard) way to know the administration folder from a front controller, otherwise all the security will flushed down the toilet :).
What you can do is to retrieve the administration folder from the module 'configuration' or when you install it, and save it somewhere, at the moment I suggest into the database but maybe there is a more safely mode.
Something like:
public function install()
{
// your stuff
$current_dir = $_SERVER['PHP_SELF']; // this give you the current dir (administration folder included)
$administration_folder = /* Clean your string with a string replace or preg */
Configuration::updateValue('PS_MYMOD_ADMIN_DIR', $administration_folder);
return true;
}
Then in your front controller retrieve it by:
$adminfolder = Configuration::get('PS_MYMOD_ADMIN_DIR');
However I hope you know that you're creating a security breach through e-mail...
Hope it helps
Since the use of the administration directory name from the Front End and sending a link to the administration in e-mail is not a good idea for security purpose, I choose to implement this another way.
Instead of send the administration customer's page link to the webmaster by e-mail, I create a new customer Thread and message. After that, I send an e-mail to the customer service. So, when they log in the Back Office, they see a new notification who leads them to the specific user.
Here is the code :
ModuleFrontController
// Create a new Customer Thread
$ct = new CustomerThread();
if (isset($customer->id)) {
$ct->id_customer = (int)$customer->id;
}
$ct->id_shop = (int)$this->context->shop->id;
$ct->id_contact = $contact->id;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $customer->email;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
// Add a new message to the Customer Thread
if ($ct->id) {
$cm = new CustomerMessage();
$cm->id_customer_thread = $ct->id;
$cm->message = $message;
$cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
$cm->add();
}
Hope it helps someone in the same situation.

How to integrate Mailerlite API on my registration form?

I'm a total noob at programming. I'm currently creating a website where a user can register.
What I want to happen is the following:
When the user registers, he/she will be added to my MailerLite subscriber list.
All the information will also be saved to my website's database.
I played around with the MailerLite documentation but I can't seem to get anything to work.
I installed all the libraries found here: https://github.com/mailerlite/mailerlite-api-php-v1#installation using composer then I created a php file with this code:
`
<?php
require_once 'vendor/autoload.php';
$ML_Subscribers = new MailerLite\Subscribers("*my API*");
$subscriber = array(
'email' => 'first#example.com',
'name' => 'First name'
);
$result = $ML_Subscribers->setId( *my GROUP ID* )->add($subscriber);
?>'
but it appears to do nothing, once I submit the form, it will load the php file that I created and shows nothing, I check my subscriber list in MailerLite and nothing is added.
Please check what does the script return - add var_dump($result); in the end of the file.
And MailerLite doesn't accept "#example.com" emails, so be sure to change this

how to make queries to db in custom script using zen cart?

hi i have a custom script that I call with ajax to retrieve some db info but for some reason it will not allow me to make the calls from this file. yet when i put the code in a page in the templates diretory lets say tpl_products_all_default.php they run fine. what do i need to do to be able to run queries from a custom script?
$sql = "select products_model from products where products_model = :productMdel:";
$sql = $db->bindVars($sql, ':productMdel:', 'C021', 'string');
$result = $db->Execute($sql);
if ($result->RecordCount() > 0) {
echo 'Model number = ' . $result->fields['products_model'];
} else {
echo 'Sorry, no record found for product number ' . $theProductId;
}
I may have an answer for you, though I'll admit it's not an optimal setup as it requires your custom file to be placed into the root directory.
If your custom file is being placed in the root (/your_custom_file.php) you can do the following to get access to the $db with the following require statement:
require('includes/application_top.php');
This will initialize all of the globals, and also call the includes/initsystem.php, which will spin through the values in the autoloader and include each script. The auto_loader can be viewed at includes/auto_loaders/config.core.php. In v1.5, you can see it finally includes the init_database.php script on lines 81-82. The init_database.php file finally initializes $db.
I initially ran into the same issue you had, and almost missed this setup because I had originally added my custom files to a custom directory like /my_module_extensions/my_file.php which failed. It seems the application_top.php loads everything with relative paths, so when executing under a directory other than the root, it would fail.
I hope this helps!
EDIT: Originally thought you were talking about an admin customization. I reworded this to relate to the public side. This also works from the admin side, if you need to extend the admin console.
Not true you can use an include from anywhere.
such as:
require_once('inc/php/application_top.php');
or
require_once('http://example.com/inc/php/application_top.php');

Open file, write to file, save file as a zip and stream to user for download

I'd like if someone could give me some advice on creating this script, which I will add to the existing plug-in (see code below) script below.
So what I have now (with the script below) is a means to insert a predefined set of defaults into the wordpress site. What I'm wanting to add, is a helper utility, activated by a button or link that just reads "Copy Settings", that will take a site's existing settings (the sb2_options), write that to a file, then package the resulting file, along with the original file into a new zip file that essentially becomes a custom copy of the original plug-in for use in another site.
So the code needs to take an existing .php file containing the static code, open it up for writing, then insert all the name/value pairs from the wordpress options table matching a specific prefix (for example, all my custom options are prefixed with "sb2_"). Once it's done this, it would save the resulting file as "plugin.zip", for example and stream it to the user for download.
Here is the code that I have now, which sets up the site's defaults...
<?php
/**
* Plugin Name: my plugin
* Description: Sets up your sites defaults.
* Version: 1.0
*/
function sb2_plugin_init()
{
if ( get_option( 'sb2_plugin' ) == "")
{
//Begin Insert List here. Open the file and write out all the name value pairs, just like in the example.
//Option 1",
$sb2_option1 = "test";
//Option 2",
$sb2_option2 = "test";
//Option 1",
$sb2_option3 = "test";
//End insert list here
//update site defaults
update_option('sb2_option1', sb2_option1);
update_option('sb2_option2', sb2_option2);
update_option('sb2_option3', sb2_option3);
//etc
// Create post objects
$my_post = array();
$my_post['post_title'] = 'Main Blog Post Title';
$my_post['post_content'] = 'Main Blog Post Content';
$my_post['post_type'] = 'post';
//TODO >>> NEED TO MAKE THE POST STICKY
// Insert the post into the database
wp_insert_post($my_post);
wp_cache_flush();
update_option('sb2_plugin', "1");
}
}
add_action( 'init','sb2_plugin_init');
Reading and writing to file shouldn't be difficult for you but here is a good way to create zip files.

Categories