added appointments-encounters report
[openemr.git] / controllers / C_DocumentCategory.class.php
blobcfd31d684ba3273e747092371e014d96950509d3
1 <?php
3 require_once (dirname(__FILE__) . "/../library/classes/Controller.class.php");
4 require_once(dirname(__FILE__) . "/../library/classes/CategoryTree.class.php");
5 require_once(dirname(__FILE__) . "/../library/classes/TreeMenu.php");
7 class C_DocumentCategory extends Controller {
9 var $template_mod;
10 var $document_categories;
11 var $tree;
12 var $link;
14 function C_DocumentCategory($template_mod = "general") {
15 parent::Controller();
16 $this->document_categories = array();
17 $this->template_mod = $template_mod;
18 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_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']);
23 $t = new CategoryTree(1);
24 //print_r($t->tree);
25 $this->tree = $t;
29 function default_action() {
30 return $this->list_action();
33 function list_action() {
34 //$this->tree->rebuild_tree(1,1);
36 $icon = 'folder.gif';
37 $expandedIcon = 'folder-expanded.gif';
38 $menu = new HTML_TreeMenu();
39 $this->_last_node = null;
40 $rnode = $this->_array_recurse($this->tree->tree);
42 $menu->addItem($rnode);
43 $treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
44 $this->assign("tree_html",$treeMenu->toHTML());
46 return $this->fetch($GLOBALS['template_dir'] . "document_categories/" . $this->template_mod . "_list.html");
49 function add_node_action($parent_is) {
50 //echo $parent_is ."<br>";
51 //echo $this->tree->get_node_name($parent_is);
52 $this->assign("parent_name",$this->tree->get_node_name($parent_is));
53 $this->assign("parent_is",$parent_is);
54 $this->assign("add_node",true);
55 return $this->list_action();
58 function add_node_action_process() {
59 if ($_POST['process'] != "true")
60 return;
61 $name = $_POST['name'];
62 $parent_is = $_POST['parent_is'];
63 $parent_name = $this->tree->get_node_name($parent_is);
64 $this->tree->add_node($parent_is,$name);
65 $this->assign("message", "Sub-category $name successfully added to category $parent_name");
66 $this->_state = false;
67 return $this->list_action();
70 function delete_node_action_process($id) {
71 if ($_POST['process'] != "true")
72 return;
73 $category_name = $this->tree->get_node_name($id);
74 $category_info = $this->tree->get_node_info($id);
75 $parent_name = $this->tree->get_node_name($category_info['parent']);
77 if($parent_name != false && $parent_name != '')
79 $this->tree->delete_node($id);
80 $this->assign("message", "Category '$category_name' had been successfully deleted. Any sub-categories if present were moved below '$parent_name'.<br>");
82 if (is_numeric($id)) {
83 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id ."'";
84 $this->tree->_db->Execute($sql);
87 else
89 $this->assign("message", "Category '$category_name' is a root node and can not be deleted.<br>");
91 $this->_state = false;
93 return $this->list_action();
96 function edit_action_process() {
97 if ($_POST['process'] != "true")
98 return;
99 //print_r($_POST);
100 if (is_numeric($_POST['id'])) {
101 $this->document_categories[0] = new Pharmacy($_POST['id']);
103 else {
104 $this->document_categories[0] = new Pharmacy();
106 parent::populate_object($this->document_categories[0]);
107 //print_r($this->document_categories[0]);
108 //echo $this->document_categories[0]->toString(true);
109 $this->document_categories[0]->persist();
110 //echo "action processeed";
111 $_POST['process'] = "";
114 function &_array_recurse($array) {
115 if (!is_array($array)) {
116 $array = array();
118 $node = &$this->_last_node;
119 $icon = 'folder.gif';
120 $expandedIcon = 'folder-expanded.gif';
121 foreach($array as $id => $ar) {
122 if (is_array($ar) || !empty($id)) {
123 if ($node == null) {
125 //echo "r:" . $this->tree->get_node_name($id) . "<br>";
126 $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));
127 $this->_last_node = &$rnode;
128 $node = &$rnode;
130 else {
131 //echo "p:" . $this->tree->get_node_name($id) . "<br>";
132 $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)));
134 if (is_array($ar)) {
135 $this->_array_recurse($ar);
138 else {
139 if ($id === 0 && !empty($ar)) {
140 $info = $this->tree->get_node_info($id);
141 //echo "b:" . $this->tree->get_node_name($id) . "<br>";
142 $node->addItem(new HTML_TreeNode(array('text' => $info['value'], 'link' => $this->_link("add_node",true) . "parent_id=" . ($id) . "&", 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
144 else {
145 //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
146 //this conditional tree could be more efficient but working with trees makes my head hurt, TODO
147 if ($id !== 0 && is_object($node)) {
148 //echo "n:" . $this->tree->get_node_name($id) . "<br>";
149 $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)));
154 return $node;