1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
<?php
/*
* Knowledgeroot
* class for ajax functions that return xml
* Frank Habermann
*/
class ajax_xml {
// global array with classes
var $CLASS = array();
// var with xmlcode to return
var $xmlcode = "";
function start(&$CLASS) {
$this->CLASS =& $CLASS;
}
// check what to do
function check_vars() {
//check if userid and groupid is set, if not set to 0
if($_SESSION['userid'] == "" || $_SESSION['groupid'] == "") {
$_SESSION['userid'] = 0;
$_SESSION['groupid'] = 0;
}
// try to work only with POST
if($_POST['ajaxopen'] != "") {
$this->tree_open($_POST['ajaxopen']);
} elseif ($_POST['ajaxclose'] != "") {
$this->tree_close($_POST['ajaxclose']);
} elseif ($_POST['reloadtree'] != "") {
$this->tree_reload();
} elseif ($_POST['expandtree'] != "") {
$this->tree_expand();
} elseif ($_POST['collapsetree'] != "") {
$this->tree_collapse();
}
}
// generate xml to open tree part
function tree_open($id) {
// get all elements to open
$elements = $this->getOpenTreeElements($id);
// generate xmloutput
$this->xmlcode = '<?xml version="1.0" ?>' . "\n";
$this->xmlcode .= "<root>\n";
$this->xmlcode .= "\t<parentid>".$id."</parentid>\n";
$this->xmlcode .= "\t<html>\n";
$this->xmlcode .= "<![CDATA[\n";
//$this->xmlcode .= htmlentities($elements);
$this->xmlcode .= $elements;
$this->xmlcode .= "]]>\n";
$this->xmlcode .= "\t</html>\n";
$this->xmlcode .= "</root>\n";
// save tree status to session and to db
$_SESSION['open'][$id] = 1;
if(!empty($_SESSION['userid'])) {
$res = $this->CLASS['db']->query("UPDATE users SET treecache='".serialize($_SESSION['open'])."' WHERE id=".$_SESSION['userid']."");
}
}
// generate xml to close treepart
function tree_close($id) {
// get all elements to close
$elements = $this->getCloseTreeElements($id);
// generate xmloutput
$this->xmlcode = '<?xml version="1.0" ?>' . "\n";
$this->xmlcode .= "<root>\n";
$this->xmlcode .= $elements;
$this->xmlcode .= "</root>\n";
// save tree status to session and to db
$_SESSION['open'][$id] = 0;
if(!empty($_SESSION['userid'])) {
$res = $this->CLASS['db']->query("UPDATE users SET treecache='".serialize($_SESSION['open'])."' WHERE id=".$_SESSION['userid']."");
}
}
// returns elements to close of an treeparentelement
function getCloseTreeElements($id) {
// check if the user have permissions
if($this->CLASS['knowledgeroot']->checkRecursivPerm($id, $_SESSION['userid']) != 0) {
if($_SESSION['admin'] == 1) {
$query = "SELECT id FROM tree WHERE belongs_to=".$id." AND deleted=0 ORDER BY title ASC";
} else {
// get groups from user
$res = $this->CLASS['db']->query("SELECT groupid FROM user_group WHERE userid=".$_SESSION['userid']."");
$orclause = "";
while($rowuser = $this->CLASS['db']->fetch_assoc($res)) {
if($this->CLASS['db']->dbtype == "pgsql") {
$orclause .= "OR (\"group\"=".$rowuser['groupid']." AND grouprights > 0) ";
} else {
$orclause .= "OR (`group`=".$rowuser['groupid']." AND grouprights > 0) ";
}
}
if($this->CLASS['db']->dbtype == "pgsql") {
$query = "SELECT id FROM tree WHERE belongs_to=".$id." AND deleted=0 AND ((otherrights > 0) OR (\"group\"=".$_SESSION['groupid']." AND grouprights > 0) ".$orclause."OR (owner=".$_SESSION['userid']." AND userrights>0)) ORDER BY title ASC";
} else {
$query = "SELECT id FROM tree WHERE belongs_to=".$id." AND deleted=0 AND ((otherrights > 0) OR (`group`=".$_SESSION['groupid']." AND grouprights > 0) ".$orclause."OR (owner=".$_SESSION['userid']." AND userrights>0)) ORDER BY title ASC";
}
}
$line = "";
// get all elements to close in tree
$res = $this->CLASS['db']->query($query);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$line .= "<element>".$row['id']."</element>\n";
// try to get childs of this element
if($_SESSION['open'][$row['id']] == 1) {
$line .= $this->getCloseTreeElements($row['id']);
}
}
}
return $line;
}
// returns elements to open in tree
function getOpenTreeElements($id) {
$this->CLASS['tree'] = new categoryTree();
// check if page is movingpage
if($_POST['move'] == "1") {
$this->CLASS['tree']->start($this->CLASS,TRUE,"#");
} else {
$this->CLASS['tree']->start($this->CLASS);
}
$lines = $this->CLASS['tree']->buildAjaxTreePart($id);
return $lines;
}
// return xmlcode
function get_xml() {
return $this->xmlcode;
}
// returns the hole tree for reloading
function tree_reload($expand = "") {
$this->CLASS['tree'] = new categoryTree();
// check if page is movingpage
if($_POST['move'] == "1") {
$this->CLASS['tree']->start($this->CLASS,TRUE,"#");
} else {
$this->CLASS['tree']->start($this->CLASS);
}
if($expand != "") {
$this->CLASS['tree']->doexpand = $expand;
$this->CLASS['tree']->expand = $expand;
}
$lines = $this->CLASS['tree']->buildAjaxTreePart("0");
// generate tree
$tree = "<table id=\"treeelementtable\" class=\"treeelements\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
$tree .= $lines;
$tree .= "</table>\n";
// generate xmloutput
$this->xmlcode = '<?xml version="1.0" ?>' . "\n";
$this->xmlcode .= "<root>\n";
$this->xmlcode .= "\t<html>\n";
$this->xmlcode .= "<![CDATA[\n";
$this->xmlcode .= $tree;
$this->xmlcode .= "]]>\n";
$this->xmlcode .= "\t</html>\n";
$this->xmlcode .= "</root>\n";
}
// expand tree
function tree_expand() {
$_SESSION['firstrun'] = "no";
if ($_SESSION['open'] != null) {
foreach($_SESSION['open'] as $key => $value) {
$_SESSION['open'][$key] = 1;
}
}
// save treecache
if(!empty($_SESSION['userid'])) {
$res = $this->CLASS['db']->query("UPDATE users SET treecache='".serialize($_SESSION['open'])."' WHERE id=".$_SESSION['userid']."");
}
$this->tree_reload("1");
}
// collapse tree
function tree_collapse() {
$_SESSION['firstrun'] = "no";
if ($_SESSION['open'] != null) {
foreach($_SESSION['open'] as $key => $value) {
$_SESSION['open'][$key] = 0;
}
}
// save treecache
if(!empty($_SESSION['userid'])) {
$res = $this->CLASS['db']->query("UPDATE users SET treecache='".serialize($_SESSION['open'])."' WHERE id=".$_SESSION['userid']."");
}
$this->tree_reload();
}
}
?>
|