Added access controls for encounter categories
[openemr.git] / controllers / C_DocumentCategory.class.php
blobb413b768e55308738a95be1319396b8815087470
1 <?php
4 class C_DocumentCategory extends Controller {
6 var $template_mod;
7 var $document_categories;
8 var $tree;
9 var $link;
11 function __construct($template_mod = "general")
13 parent::__construct();
14 $this->document_categories = array();
15 $this->template_mod = $template_mod;
16 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
17 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&document_category&");
18 $this->link = $GLOBALS['webroot']."/controller.php?" . "document_category&";
19 $this->assign("STYLE", $GLOBALS['style']);
20 $this->assign("V_JS_INCLUDES", $GLOBALS['v_js_includes']);
22 $t = new CategoryTree(1);
23 //print_r($t->tree);
24 $this->tree = $t;
28 function default_action()
30 return $this->list_action();
33 function list_action()
35 //$this->tree->rebuild_tree(1,1);
37 $icon = 'folder.gif';
38 $expandedIcon = 'folder-expanded.gif';
39 $menu = new HTML_TreeMenu();
40 $this->_last_node = null;
41 $rnode = $this->_array_recurse($this->tree->tree);
43 $menu->addItem($rnode);
44 $treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
45 $this->assign("tree_html",$treeMenu->toHTML());
47 return $this->fetch($GLOBALS['template_dir'] . "document_categories/" . $this->template_mod . "_list.html");
50 function add_node_action($parent_is)
52 //echo $parent_is ."<br>";
53 //echo $this->tree->get_node_name($parent_is);
54 $info = $this->tree->get_node_info($parent_is);
55 $this->assign("parent_name",$this->tree->get_node_name($parent_is));
56 $this->assign("parent_is",$parent_is);
57 $this->assign("add_node",true);
58 $this->assign("edit_node", false);
59 $this->assign("VALUE", '');
60 // Access control defaults to that of the parent.
61 $this->assign("ACO_OPTIONS", "<option value=''></option>" . gen_aco_html_options($info['aco_spec']));
62 return $this->list_action();
65 function add_node_action_process()
67 if ($_POST['process'] != "true") return;
68 $name = $_POST['name'];
69 $parent_is = $_POST['parent_is'];
70 $parent_name = $this->tree->get_node_name($parent_is);
71 $this->tree->add_node($parent_is, $name, $_POST['value'], $_POST['aco_spec']);
72 $trans_message = xl('Sub-category','','',' ') . "'" . xl_document_category($name) . "'" . xl('successfully added to category,','',' ',' ') . "'" . $parent_name . "'";
73 $this->assign("message",$trans_message);
74 $this->_state = false;
75 return $this->list_action();
78 function edit_node_action($parent_is)
80 $info = $this->tree->get_node_info($parent_is);
81 $this->assign("parent_is",$parent_is);
82 $this->assign("NAME" , $this->tree->get_node_name($parent_is));
83 $this->assign("VALUE", $info['value']);
84 $this->assign("ACO_OPTIONS", "<option value=''></option>" . gen_aco_html_options($info['aco_spec']));
85 $this->assign("add_node",false);
86 $this->assign("edit_node",true);
87 return $this->list_action();
90 function edit_node_action_process()
92 if ($_POST['process'] != "true") return;
93 $parent_is = $_POST['parent_is'];
94 $this->tree->edit_node($parent_is, $_POST['name'], $_POST['value'], $_POST['aco_spec']);
95 $trans_message = xl('Category changed.');
96 $this->assign("message", $trans_message);
97 $this->_state = false;
98 return $this->list_action();
101 function delete_node_action_process($id)
103 if ($_POST['process'] != "true")
104 return;
105 $category_name = $this->tree->get_node_name($id);
106 $category_info = $this->tree->get_node_info($id);
107 $parent_name = $this->tree->get_node_name($category_info['parent']);
109 if($parent_name != false && $parent_name != '')
111 $this->tree->delete_node($id);
112 $trans_message = xl('Category','','',' ') . "'" . $category_name . "'" . xl('had been successfully deleted. Any sub-categories if present were moved below','',' ',' ') . "'" . $parent_name . "'" . xl('.') . "<br>";
113 $this->assign("message",$trans_message);
115 if (is_numeric($id)) {
116 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id ."'";
117 $this->tree->_db->Execute($sql);
120 else
122 $trans_message = xl('Category','','',' ') . "'" . $category_name . "'" . xl('is a root node and can not be deleted.','',' ') . "<br>";
123 $this->assign("message",$trans_message);
125 $this->_state = false;
127 return $this->list_action();
130 function &_array_recurse($array)
132 if (!is_array($array)) {
133 $array = array();
135 $node = &$this->_last_node;
136 $icon = 'folder.gif';
137 $expandedIcon = 'folder-expanded.gif';
138 foreach($array as $id => $ar) {
139 if (is_array($ar) || !empty($id)) {
140 if ($node == null) {
142 //echo "r:" . $this->tree->get_node_name($id) . "<br>";
143 $rnode = new HTML_TreeNode(array('text' => $this->tree->get_node_name($id), 'link' => $this->_link("add_node",true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false));
144 $this->_last_node = &$rnode;
145 $node = &$rnode;
147 else {
148 //echo "p:" . $this->tree->get_node_name($id) . "<br>";
149 $this->_last_node = &$node->addItem(new HTML_TreeNode(array('text' => $this->tree->get_node_name($id), 'link' => $this->_link("add_node",true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
151 if (is_array($ar)) {
152 $this->_array_recurse($ar);
155 else {
156 if ($id === 0 && !empty($ar)) {
157 $info = $this->tree->get_node_info($id);
158 //echo "b:" . $this->tree->get_node_name($id) . "<br>";
159 $node->addItem(new HTML_TreeNode(array('text' => $info['value'], 'link' => $this->_link("add_node",true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
161 else {
162 //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
163 //this conditional tree could be more efficient but working with trees makes my head hurt, TODO
164 if ($id !== 0 && is_object($node)) {
165 //echo "n:" . $this->tree->get_node_name($id) . "<br>";
166 $node->addItem(new HTML_TreeNode(array('text' => $this->tree->get_node_name($id), 'link' => $this->_link("add_node",true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
171 return $node;