3 require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php');
5 use OpenEMR\Common\Acl\AclExtended
;
6 use OpenEMR\Common\Twig\TwigContainer
;
7 use OpenEMR\Services\CodeTypesService
;
9 class C_DocumentCategory
extends Controller
12 var $document_categories;
17 function __construct($template_mod = "general")
19 parent
::__construct();
20 $this->document_categories
= array();
21 $this->template_mod
= $template_mod;
22 $this->assign("FORM_ACTION", $GLOBALS['webroot'] . "/controller.php?" . attr($_SERVER['QUERY_STRING']));
23 $this->assign("CURRENT_ACTION", $GLOBALS['webroot'] . "/controller.php?" . "practice_settings&document_category&");
24 $this->link
= $GLOBALS['webroot'] . "/controller.php?" . "document_category&";
25 $this->assign("STYLE", $GLOBALS['style']);
26 $this->assign("V_JS_INCLUDES", $GLOBALS['v_js_includes']);
28 $t = new CategoryTree(1);
33 function default_action()
35 return $this->list_action();
38 function list_action()
40 //$this->tree->rebuild_tree(1,1);
43 $expandedIcon = 'folder-expanded.gif';
44 $menu = new HTML_TreeMenu();
45 $this->_last_node
= null;
46 $rnode = $this->_array_recurse($this->tree
->tree
);
48 $menu->addItem($rnode);
49 $treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => 'public/images', 'defaultClass' => 'treeMenuDefault'));
50 $this->assign("tree_html", $treeMenu->toHTML());
51 $this->assign('add_node', (($this->getTemplateVars('add_node') ??
false) == true));
52 $this->assign('edit_node', (($this->getTemplateVars('edit_node') ??
false) == true));
54 $twig = new TwigContainer(null, $GLOBALS['kernel']);
55 return $twig->getTwig()->render("document_categories/" . $this->template_mod
. "_list.html.twig", $this->getTemplateVars());
58 function add_node_action($parent_is)
60 //echo $parent_is ."<br />";
61 //echo $this->tree->get_node_name($parent_is);
62 $info = $this->tree
->get_node_info($parent_is);
63 $this->assign("parent_name", $this->tree
->get_node_name($parent_is));
64 $this->assign("parent_is", $parent_is);
65 $this->assign("add_node", true);
66 $this->assign("edit_node", false);
67 $this->assign("VALUE", '');
68 // Access control defaults to that of the parent.
69 $this->assign("ACO_OPTIONS", "<option value=''></option>" . AclExtended
::genAcoHtmlOptions($info['aco_spec']));
70 $this->assign("CODES", ""); // empty value here
71 $this->assign("CODE_TEXT", ""); // empty value here
72 return $this->list_action();
75 function add_node_action_process()
77 if ($_POST['process'] != "true") {
81 $name = $_POST['name'];
82 $parent_is = $_POST['parent_is'];
83 $parent_name = $this->tree
->get_node_name($parent_is);
84 $this->tree
->add_node($parent_is, $name, $_POST['value'], $_POST['aco_spec'], $_POST['codes']);
85 $trans_message = xlt('Sub-category') . " '" . text(xl_document_category($name)) . "' " . xlt('successfully added to category,') . " '" . text($parent_name) . "'";
86 $this->assign("message", $trans_message);
87 $this->_state
= false;
88 return $this->list_action();
91 function edit_node_action($parent_is)
93 $info = $this->tree
->get_node_info($parent_is);
94 $this->assign("parent_is", $parent_is);
95 $this->assign("NAME", $this->tree
->get_node_name($parent_is));
96 $this->assign("VALUE", $info['value']);
97 $this->assign("ACO_OPTIONS", "<option value=''></option>" . AclExtended
::genAcoHtmlOptions($info['aco_spec']));
98 $this->assign("add_node", false);
99 $this->assign("edit_node", true);
100 $this->assign("CODES", $info['codes'] ??
'');
102 if (!empty($info['codes'])) {
103 $codeTypeService = new CodeTypesService();
104 $description = $codeTypeService->lookup_code_description($info['codes']);
105 $this->assign('CODE_TEXT', $description ??
"");
107 $this->assign('CODE_TEXT', "");
109 return $this->list_action();
112 function edit_node_action_process()
114 if ($_POST['process'] != "true") {
118 $parent_is = $_POST['parent_is'];
119 $this->tree
->edit_node($parent_is, $_POST['name'], $_POST['value'], $_POST['aco_spec'], $_POST['codes']);
120 $trans_message = xlt('Category changed.');
121 $this->assign("message", $trans_message);
122 $this->_state
= false;
123 return $this->list_action();
126 function delete_node_action_process($id)
128 if ($_POST['process'] != "true") {
132 $category_name = $this->tree
->get_node_name($id);
133 $category_info = $this->tree
->get_node_info($id);
134 $parent_name = $this->tree
->get_node_name($category_info['parent']);
136 if ($parent_name != false && $parent_name != '') {
137 $this->tree
->delete_node($id);
138 $trans_message = xlt('Category') . " '" . text($category_name) . "' " . xlt('had been successfully deleted. Any sub-categories if present were moved below') . " '" . text($parent_name) . "'<br />";
139 $this->assign("message", $trans_message);
141 if (is_numeric($id)) {
142 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id . "'";
143 $this->tree
->_db
->Execute($sql);
146 $trans_message = xlt('Category') . " '" . text($category_name) . "' " . xlt('is a root node and can not be deleted.') . "<br />";
147 $this->assign("message", $trans_message);
150 $this->_state
= false;
152 return $this->list_action();
155 function &_array_recurse($array)
157 if (!is_array($array)) {
161 $node = &$this->_last_node
;
162 $icon = 'folder.gif';
163 $expandedIcon = 'folder-expanded.gif';
164 foreach ($array as $id => $ar) {
165 if (is_array($ar) ||
!empty($id)) {
167 //echo "r:" . $this->tree->get_node_name($id) . "<br />";
168 $rnode = new HTML_TreeNode(array('text' => $this->tree
->get_node_name($id), 'link' => $this->_link("add_node", true) . "parent_id=" . urlencode($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false));
169 $this->_last_node
= &$rnode;
172 //echo "p:" . $this->tree->get_node_name($id) . "<br />";
173 $this->_last_node
= &$node->addItem(new HTML_TreeNode(array('text' => $this->tree
->get_node_name($id), 'link' => $this->_link("add_node", true) . "parent_id=" . urlencode($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
177 $this->_array_recurse($ar);
180 if ($id === 0 && !empty($ar)) {
181 $info = $this->tree
->get_node_info($id);
182 //echo "b:" . $this->tree->get_node_name($id) . "<br />";
183 $node->addItem(new HTML_TreeNode(array('text' => $info['value'], 'link' => $this->_link("add_node", true) . "parent_id=" . urlencode($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
185 //there is a third case that is implicit here when title === 0 and $ar is empty, in that case we do not want to do anything
186 //this conditional tree could be more efficient but working with trees makes my head hurt, TODO
187 if ($id !== 0 && is_object($node)) {
188 //echo "n:" . $this->tree->get_node_name($id) . "<br />";
189 $node->addItem(new HTML_TreeNode(array('text' => $this->tree
->get_node_name($id), 'link' => $this->_link("add_node", true) . "parent_id=" . urlencode($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));