groups fix in the add appt screen
[openemr.git] / controllers / C_DocumentCategory.class.php
blob86cc5f3475787a3f7910ca94532f1cd4c4692974
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") {
12 parent::__construct();
13 $this->document_categories = array();
14 $this->template_mod = $template_mod;
15 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
16 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&document_category&");
17 $this->link = $GLOBALS['webroot']."/controller.php?" . "document_category&";
18 $this->assign("STYLE", $GLOBALS['style']);
20 $t = new CategoryTree(1);
21 //print_r($t->tree);
22 $this->tree = $t;
26 function default_action() {
27 return $this->list_action();
30 function list_action() {
31 //$this->tree->rebuild_tree(1,1);
33 $icon = 'folder.gif';
34 $expandedIcon = 'folder-expanded.gif';
35 $menu = new HTML_TreeMenu();
36 $this->_last_node = null;
37 $rnode = $this->_array_recurse($this->tree->tree);
39 $menu->addItem($rnode);
40 $treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
41 $this->assign("tree_html",$treeMenu->toHTML());
43 return $this->fetch($GLOBALS['template_dir'] . "document_categories/" . $this->template_mod . "_list.html");
46 function add_node_action($parent_is) {
47 //echo $parent_is ."<br>";
48 //echo $this->tree->get_node_name($parent_is);
49 $info = $this->tree->get_node_info($parent_is);
50 $this->assign("parent_name",$this->tree->get_node_name($parent_is));
51 $this->assign("parent_is",$parent_is);
52 $this->assign("add_node",true);
53 $this->assign("edit_node", false);
54 $this->assign("VALUE", '');
55 // Access control defaults to that of the parent.
56 $this->assign("ACO_OPTIONS", "<option value=''></option>" . gen_aco_html_options($info['aco_spec']));
57 return $this->list_action();
60 function add_node_action_process() {
61 if ($_POST['process'] != "true") return;
62 $name = $_POST['name'];
63 $parent_is = $_POST['parent_is'];
64 $parent_name = $this->tree->get_node_name($parent_is);
65 $this->tree->add_node($parent_is, $name, $_POST['value'], $_POST['aco_spec']);
66 $trans_message = xl('Sub-category','','',' ') . "'" . xl_document_category($name) . "'" . xl('successfully added to category,','',' ',' ') . "'" . $parent_name . "'";
67 $this->assign("message",$trans_message);
68 $this->_state = false;
69 return $this->list_action();
72 function edit_node_action($parent_is) {
73 $info = $this->tree->get_node_info($parent_is);
74 $this->assign("parent_is",$parent_is);
75 $this->assign("NAME" , $this->tree->get_node_name($parent_is));
76 $this->assign("VALUE", $info['value']);
77 $this->assign("ACO_OPTIONS", "<option value=''></option>" . gen_aco_html_options($info['aco_spec']));
78 $this->assign("add_node",false);
79 $this->assign("edit_node",true);
80 return $this->list_action();
83 function edit_node_action_process() {
84 if ($_POST['process'] != "true") return;
85 $parent_is = $_POST['parent_is'];
86 $this->tree->edit_node($parent_is, $_POST['name'], $_POST['value'], $_POST['aco_spec']);
87 $trans_message = xl('Category changed.');
88 $this->assign("message", $trans_message);
89 $this->_state = false;
90 return $this->list_action();
93 function delete_node_action_process($id) {
94 if ($_POST['process'] != "true")
95 return;
96 $category_name = $this->tree->get_node_name($id);
97 $category_info = $this->tree->get_node_info($id);
98 $parent_name = $this->tree->get_node_name($category_info['parent']);
100 if($parent_name != false && $parent_name != '')
102 $this->tree->delete_node($id);
103 $trans_message = xl('Category','','',' ') . "'" . $category_name . "'" . xl('had been successfully deleted. Any sub-categories if present were moved below','',' ',' ') . "'" . $parent_name . "'" . xl('.') . "<br>";
104 $this->assign("message",$trans_message);
106 if (is_numeric($id)) {
107 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id ."'";
108 $this->tree->_db->Execute($sql);
111 else
113 $trans_message = xl('Category','','',' ') . "'" . $category_name . "'" . xl('is a root node and can not be deleted.','',' ') . "<br>";
114 $this->assign("message",$trans_message);
116 $this->_state = false;
118 return $this->list_action();
121 function &_array_recurse($array) {
122 if (!is_array($array)) {
123 $array = array();
125 $node = &$this->_last_node;
126 $icon = 'folder.gif';
127 $expandedIcon = 'folder-expanded.gif';
128 foreach($array as $id => $ar) {
129 if (is_array($ar) || !empty($id)) {
130 if ($node == null) {
132 //echo "r:" . $this->tree->get_node_name($id) . "<br>";
133 $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));
134 $this->_last_node = &$rnode;
135 $node = &$rnode;
137 else {
138 //echo "p:" . $this->tree->get_node_name($id) . "<br>";
139 $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)));
141 if (is_array($ar)) {
142 $this->_array_recurse($ar);
145 else {
146 if ($id === 0 && !empty($ar)) {
147 $info = $this->tree->get_node_info($id);
148 //echo "b:" . $this->tree->get_node_name($id) . "<br>";
149 $node->addItem(new HTML_TreeNode(array('text' => $info['value'], 'link' => $this->_link("add_node",true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
151 else {
152 //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
153 //this conditional tree could be more efficient but working with trees makes my head hurt, TODO
154 if ($id !== 0 && is_object($node)) {
155 //echo "n:" . $this->tree->get_node_name($id) . "<br>";
156 $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)));
161 return $node;