For basic information on plugins, please refer: Infocapture plugins
In this section we would see how to populate data in a select list from a CSV file.
You can find the xml file of the test project here:
Lets suppose we have got this test project with ID = 43
To fetch data from a csv file you need four files, which are to be placed in the folder: /httpdocs/intranet/helpdesk/plugins/
1. groups.csv file, which contains comma seperated data to be populated in the select list
2. get_csv.php file, contains function to read data from a .csv file
<?php function getCsvData() { $group = "Please Select,#0\n"; $file = fopen("/var/www/vhosts/54.claromentis.com/httpdocs/intranet/helpdesk/plugins/groups.csv","r"); $row = 1; while (($data = fgetcsv($file, 1000, ",")) !== FALSE) { $num = count($data); $row++; for ($c=0; $c < $num; $c++) { $no = $c+1; $group = "$group" . $data[$c] . ",#" . $no . "\n"; } } return($group); fclose($file); } ?>
3. plugin_43_add_issue.php file, an add_issue plugin used while reporting an issue
<?php require_once("get_csv.php"); function hd_plugin_43_add_issue($params) { $project = new HDProject(); $fbform = new FBForm(); $pid = 43; if (!$project->Load($pid)) { $errno = "Cannot load current project"; vard2($errno); exit; } $fbform = $project->getForm(); $fbform->loadFields(); $csv_data = $fbform->getFieldBySymname("csv_data"); $csv_data1 = getCsvData(); $csv_data->setFBValue("items","$csv_data1"); } ?>
4. plugin_43_view_form.php file, an view_form plugin used to populate CSV file data while viewing the form
<?php require_once("get_csv.php"); function hd_plugin_43_view_form($params) { $csv_data1 = getCsvData(); //To get groups from a .csv file $ret = array(); $ret["form_fields"]["csv_data"]["items"] = $csv_data1; return ($ret); } ?>
After uploading above four files in the specified folder, while reporting a issue you would get a list of values populated from a CSV file in the select list as shown in figure below:
Discussion