For basic information on plugins, please refer: Infocapture plugins
In this section we would see following things:
1. Populate all the sub-folders of the specified parent folder in a Select List
2. Create a folder with the specified name under the folder selected from the Select List, while updating an issue
3. Create a link to the newly created folder
You can find the xml file of the test project here:
Lets suppose we have got this test project with ID = 44
To achive the above three things, we need five files, which are to be placed in the folder: /httpdocs/intranet/helpdesk/plugins/
1. get_folders.php, which contains function to retrive all sub-folders of the specified parent id
NOTE: Change the parent_id to the id of the folder whose sub-folders are to be retrived
<?php function getFolders() { global $db; $folders = "Please Select,#0\n"; $result = $db->query("SELECT title, id FROM ERMS_file_plan WHERE parent_id = 0 order by id"); while($row = $result->fetchArray()) { $folders = "$folders" . $row["title"] . ",#" . $row["id"] . "\n"; } return ($folders); } ?>
We get list of sub-folders under the parent folder with ID = 0 in the Select List as shown in figure below:
2. plugin_44_update_issue.php
<?php include_once('/var/www/vhosts/54.claromentis.com/httpdocs/intranet/common/erms_pkg.php'); require_once("get_folders.php"); function hd_plugin_44_update_issue($params) { global $db; $project_info = $params["project"]; $issue_info = $params["issue"]; $issue_fields = $params["issue"]["fields_values"]; $name = $issue_fields["name"]; $folder_added_old = $issue_fields["folder_added"]; $reporter_id = $_SESSION["SESSION_UID"]; $project = new HDProject(); $fbform = new FBForm(); $pid = 44; if(!$project->Load($pid)) { $errno = "Cannot load current project"; vard2($errno); exit; } $fbform = $project->getForm(); $fbform->loadFields(); $folder_added = $fbform->getFieldBySymname("folder_added"); $folders = getFolders(); $folder_added->setFBValue("items","$folders"); //If a folder is selected then create a sub-folder under it if($folder_added_old != 0) { $folder = new ERMSFolder(); $folder->Load($folder_added_old); $childfolder = new ERMSFolder(); $childfolder->SetTitle($name); $childfolder->SetCreator($reporter_id); $folder->addChild($childfolder); $folder->Save(); } } ?>
3. plugin_44_view_issue.php, it is used to create a link to the newly created folder in update_issue plugin
<?php require_once("get_folders.php"); function hd_plugin_44_view_issue($params) { global $db; $project_info = $params["project"]; $issue_info = $params["issue"]; $issue_fields = $params["issue"]["fields_values"]; $name = $issue_fields["name"]; $folder_added_old = $issue_fields["folder_added"]; $reporter_id = $_SESSION["SESSION_UID"]; $project = new HDProject(); $fbform = new FBForm(); $pid = 44; if(!$project->Load($pid)) { $errno = "Cannot load current project"; vard2($errno); exit; } $fbform = $project->getForm(); $fbform->loadFields(); $folder_added = $fbform->getFieldBySymname("folder_added"); $folders = getFolders(); $folder_added->setFBValue("items","$folders"); if($folder_added_old != 0) { $ret = array(); $sym_name = "sub_folder"; //create link to the folder $ret["issue"]["fields_values"][$sym_name] = '<a href="../documents/'.$folder_added_old.'">'.$name.'</a>'; } else { $ret["issue"]["fields_values"][$sym_name] = ''; } return $ret; } ?>
4. plugin_44_view_form.php, it is used to enable HTML tags
<?php require_once("get_folders.php"); function hd_plugin_44_view_form($params) { global $db; $sym_name = "sub_folder"; $folders = getFolders(); $ret = array(); $ret["form_fields"][$sym_name]["html_view"] = 1; $ret["form_fields"][$sym_name]["disabled"] = 1; //To display the folders list in the select list $ret["form_fields"]["folder_added"]["items"] = $folders; return $ret; } ?>
5. plugin_44_has_field_edit_rights.php
<?php function hd_plugin_44_has_field_edit_rights($params) { if ($params["optional_params"]["symname"] == "sub_folder") return false; return NULL; } ?>
After saving the above five files in the specified folder, if you update an issue and select the “Parent Folder Name”, a folder with the name specified would be created under the specified “Parent” folder and a link to the newly created folder would be displayed as shown in the figure below:
Discussion