Add appointment service status methods. (#4757)
[openemr.git] / controllers / C_DocumentCategory.class.php
blob52f03060f18d3a41dd70b6c716659edb737d08cd
1 <?php
3 use OpenEMR\Common\Acl\AclExtended;
5 class C_DocumentCategory extends Controller
8 var $template_mod;
9 var $document_categories;
10 var $tree;
11 var $link;
13 function __construct($template_mod = "general")
15 parent::__construct();
16 $this->document_categories = array();
17 $this->template_mod = $template_mod;
18 $this->assign("FORM_ACTION", $GLOBALS['webroot'] . "/controller.php?" . attr($_SERVER['QUERY_STRING']));
19 $this->assign("CURRENT_ACTION", $GLOBALS['webroot'] . "/controller.php?" . "practice_settings&document_category&");
20 $this->link = $GLOBALS['webroot'] . "/controller.php?" . "document_category&";
21 $this->assign("STYLE", $GLOBALS['style']);
22 $this->assign("V_JS_INCLUDES", $GLOBALS['v_js_includes']);
24 $t = new CategoryTree(1);
25 //print_r($t->tree);
26 $this->tree = $t;
29 function default_action()
31 return $this->list_action();
34 function list_action()
36 //$this->tree->rebuild_tree(1,1);
38 $icon = 'folder.gif';
39 $expandedIcon = 'folder-expanded.gif';
40 $menu = new HTML_TreeMenu();
41 $this->_last_node = null;
42 $rnode = $this->_array_recurse($this->tree->tree);
44 $menu->addItem($rnode);
45 $treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => 'public/images', 'defaultClass' => 'treeMenuDefault'));
46 $this->assign("tree_html", $treeMenu->toHTML());
48 return $this->fetch($GLOBALS['template_dir'] . "document_categories/" . $this->template_mod . "_list.html");
51 function add_node_action($parent_is)
53 //echo $parent_is ."<br />";
54 //echo $this->tree->get_node_name($parent_is);
55 $info = $this->tree->get_node_info($parent_is);
56 $this->assign("parent_name", $this->tree->get_node_name($parent_is));
57 $this->assign("parent_is", $parent_is);
58 $this->assign("add_node", true);
59 $this->assign("edit_node", false);
60 $this->assign("VALUE", '');
61 // Access control defaults to that of the parent.
62 $this->assign("ACO_OPTIONS", "<option value=''></option>" . AclExtended::genAcoHtmlOptions($info['aco_spec']));
63 return $this->list_action();
66 function add_node_action_process()
68 if ($_POST['process'] != "true") {
69 return;
72 $name = $_POST['name'];
73 $parent_is = $_POST['parent_is'];
74 $parent_name = $this->tree->get_node_name($parent_is);
75 $this->tree->add_node($parent_is, $name, $_POST['value'], $_POST['aco_spec']);
76 $trans_message = xlt('Sub-category') . " '" . text(xl_document_category($name)) . "' " . xlt('successfully added to category,') . " '" . text($parent_name) . "'";
77 $this->assign("message", $trans_message);
78 $this->_state = false;
79 return $this->list_action();
82 function edit_node_action($parent_is)
84 $info = $this->tree->get_node_info($parent_is);
85 $this->assign("parent_is", $parent_is);
86 $this->assign("NAME", $this->tree->get_node_name($parent_is));
87 $this->assign("VALUE", $info['value']);
88 $this->assign("ACO_OPTIONS", "<option value=''></option>" . AclExtended::genAcoHtmlOptions($info['aco_spec']));
89 $this->assign("add_node", false);
90 $this->assign("edit_node", true);
91 return $this->list_action();
94 function edit_node_action_process()
96 if ($_POST['process'] != "true") {
97 return;
100 $parent_is = $_POST['parent_is'];
101 $this->tree->edit_node($parent_is, $_POST['name'], $_POST['value'], $_POST['aco_spec']);
102 $trans_message = xlt('Category changed.');
103 $this->assign("message", $trans_message);
104 $this->_state = false;
105 return $this->list_action();
108 function delete_node_action_process($id)
110 if ($_POST['process'] != "true") {
111 return;
114 $category_name = $this->tree->get_node_name($id);
115 $category_info = $this->tree->get_node_info($id);
116 $parent_name = $this->tree->get_node_name($category_info['parent']);
118 if ($parent_name != false && $parent_name != '') {
119 $this->tree->delete_node($id);
120 $trans_message = xlt('Category') . " '" . text($category_name) . "' " . xlt('had been successfully deleted. Any sub-categories if present were moved below') . " '" . text($parent_name) . "'<br />";
121 $this->assign("message", $trans_message);
123 if (is_numeric($id)) {
124 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id . "'";
125 $this->tree->_db->Execute($sql);
127 } else {
128 $trans_message = xlt('Category') . " '" . text($category_name) . "' " . xlt('is a root node and can not be deleted.') . "<br />";
129 $this->assign("message", $trans_message);
132 $this->_state = false;
134 return $this->list_action();
137 function &_array_recurse($array)
139 if (!is_array($array)) {
140 $array = array();
143 $node = &$this->_last_node;
144 $icon = 'folder.gif';
145 $expandedIcon = 'folder-expanded.gif';
146 foreach ($array as $id => $ar) {
147 if (is_array($ar) || !empty($id)) {
148 if ($node == null) {
149 //echo "r:" . $this->tree->get_node_name($id) . "<br />";
150 $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));
151 $this->_last_node = &$rnode;
152 $node = &$rnode;
153 } else {
154 //echo "p:" . $this->tree->get_node_name($id) . "<br />";
155 $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)));
158 if (is_array($ar)) {
159 $this->_array_recurse($ar);
161 } else {
162 if ($id === 0 && !empty($ar)) {
163 $info = $this->tree->get_node_info($id);
164 //echo "b:" . $this->tree->get_node_name($id) . "<br />";
165 $node->addItem(new HTML_TreeNode(array('text' => $info['value'], 'link' => $this->_link("add_node", true) . "parent_id=" . urlencode($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
166 } else {
167 //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
168 //this conditional tree could be more efficient but working with trees makes my head hurt, TODO
169 if ($id !== 0 && is_object($node)) {
170 //echo "n:" . $this->tree->get_node_name($id) . "<br />";
171 $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 return $node;