4 class C_DocumentCategory
extends Controller
{
7 var $document_categories;
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);
26 function default_action() {
27 return $this->list_action();
30 function list_action() {
31 //$this->tree->rebuild_tree(1,1);
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 $this->assign("parent_name",$this->tree
->get_node_name($parent_is));
50 $this->assign("parent_is",$parent_is);
51 $this->assign("add_node",true);
52 return $this->list_action();
55 function add_node_action_process() {
56 if ($_POST['process'] != "true")
58 $name = $_POST['name'];
59 $parent_is = $_POST['parent_is'];
60 $parent_name = $this->tree
->get_node_name($parent_is);
61 $this->tree
->add_node($parent_is,$name);
62 $trans_message = xl('Sub-category','','',' ') . "'" . xl_document_category($name) . "'" . xl('successfully added to category,','',' ',' ') . "'" . $parent_name . "'";
63 $this->assign("message",$trans_message);
64 $this->_state
= false;
65 return $this->list_action();
68 function delete_node_action_process($id) {
69 if ($_POST['process'] != "true")
71 $category_name = $this->tree
->get_node_name($id);
72 $category_info = $this->tree
->get_node_info($id);
73 $parent_name = $this->tree
->get_node_name($category_info['parent']);
75 if($parent_name != false && $parent_name != '')
77 $this->tree
->delete_node($id);
78 $trans_message = xl('Category','','',' ') . "'" . $category_name . "'" . xl('had been successfully deleted. Any sub-categories if present were moved below','',' ',' ') . "'" . $parent_name . "'" . xl('.') . "<br>";
79 $this->assign("message",$trans_message);
81 if (is_numeric($id)) {
82 $sql = "UPDATE categories_to_documents set category_id = '" . $category_info['parent'] . "' where category_id = '" . $id ."'";
83 $this->tree
->_db
->Execute($sql);
88 $trans_message = xl('Category','','',' ') . "'" . $category_name . "'" . xl('is a root node and can not be deleted.','',' ') . "<br>";
89 $this->assign("message",$trans_message);
91 $this->_state
= false;
93 return $this->list_action();
96 function edit_action_process() {
97 if ($_POST['process'] != "true")
100 if (is_numeric($_POST['id'])) {
101 $this->document_categories
[0] = new Pharmacy($_POST['id']);
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)) {
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)) {
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;
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)));
135 $this->_array_recurse($ar);
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)));
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)));