CTL Revision (#1950)
[openemr.git] / controllers / C_DocumentCategory.class.php
blobe577a44fbf05c6ac55569cbc6fe8b93cdcf9dc24
1 <?php
4 class C_DocumentCategory extends Controller
7 var $template_mod;
8 var $document_categories;
9 var $tree;
10 var $link;
12 function __construct($template_mod = "general")
14 parent::__construct();
15 $this->document_categories = array();
16 $this->template_mod = $template_mod;
17 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . attr($_SERVER['QUERY_STRING']));
18 $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&document_category&");
19 $this->link = $GLOBALS['webroot']."/controller.php?" . "document_category&";
20 $this->assign("STYLE", $GLOBALS['style']);
21 $this->assign("V_JS_INCLUDES", $GLOBALS['v_js_includes']);
23 $t = new CategoryTree(1);
24 //print_r($t->tree);
25 $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") {
68 return;
71 $name = $_POST['name'];
72 $parent_is = $_POST['parent_is'];
73 $parent_name = $this->tree->get_node_name($parent_is);
74 $this->tree->add_node($parent_is, $name, $_POST['value'], $_POST['aco_spec']);
75 $trans_message = xl('Sub-category', '', '', ' ') . "'" . xl_document_category($name) . "'" . xl('successfully added to category,', '', ' ', ' ') . "'" . $parent_name . "'";
76 $this->assign("message", $trans_message);
77 $this->_state = false;
78 return $this->list_action();
81 function edit_node_action($parent_is)
83 $info = $this->tree->get_node_info($parent_is);
84 $this->assign("parent_is", $parent_is);
85 $this->assign("NAME", $this->tree->get_node_name($parent_is));
86 $this->assign("VALUE", $info['value']);
87 $this->assign("ACO_OPTIONS", "<option value=''></option>" . gen_aco_html_options($info['aco_spec']));
88 $this->assign("add_node", false);
89 $this->assign("edit_node", true);
90 return $this->list_action();
93 function edit_node_action_process()
95 if ($_POST['process'] != "true") {
96 return;
99 $parent_is = $_POST['parent_is'];
100 $this->tree->edit_node($parent_is, $_POST['name'], $_POST['value'], $_POST['aco_spec']);
101 $trans_message = xl('Category changed.');
102 $this->assign("message", $trans_message);
103 $this->_state = false;
104 return $this->list_action();
107 function delete_node_action_process($id)
109 if ($_POST['process'] != "true") {
110 return;
113 $category_name = $this->tree->get_node_name($id);
114 $category_info = $this->tree->get_node_info($id);
115 $parent_name = $this->tree->get_node_name($category_info['parent']);
117 if ($parent_name != false && $parent_name != '') {
118 $this->tree->delete_node($id);
119 $trans_message = xl('Category', '', '', ' ') . "'" . $category_name . "'" . xl('had been successfully deleted. Any sub-categories if present were moved below', '', ' ', ' ') . "'" . $parent_name . "'" . xl('.') . "<br>";
120 $this->assign("message", $trans_message);
122 if (is_numeric($id)) {
123 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id ."'";
124 $this->tree->_db->Execute($sql);
126 } else {
127 $trans_message = xl('Category', '', '', ' ') . "'" . $category_name . "'" . xl('is a root node and can not be deleted.', '', ' ') . "<br>";
128 $this->assign("message", $trans_message);
131 $this->_state = false;
133 return $this->list_action();
136 function &_array_recurse($array)
138 if (!is_array($array)) {
139 $array = array();
142 $node = &$this->_last_node;
143 $icon = 'folder.gif';
144 $expandedIcon = 'folder-expanded.gif';
145 foreach ($array as $id => $ar) {
146 if (is_array($ar) || !empty($id)) {
147 if ($node == null) {
148 //echo "r:" . $this->tree->get_node_name($id) . "<br>";
149 $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));
150 $this->_last_node = &$rnode;
151 $node = &$rnode;
152 } else {
153 //echo "p:" . $this->tree->get_node_name($id) . "<br>";
154 $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)));
157 if (is_array($ar)) {
158 $this->_array_recurse($ar);
160 } else {
161 if ($id === 0 && !empty($ar)) {
162 $info = $this->tree->get_node_info($id);
163 //echo "b:" . $this->tree->get_node_name($id) . "<br>";
164 $node->addItem(new HTML_TreeNode(array('text' => $info['value'], 'link' => $this->_link("add_node", true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
165 } else {
166 //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
167 //this conditional tree could be more efficient but working with trees makes my head hurt, TODO
168 if ($id !== 0 && is_object($node)) {
169 //echo "n:" . $this->tree->get_node_name($id) . "<br>";
170 $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)));
176 return $node;