From 31f38a5d8e37b7fca1981caf84c3fd2edd28b1b6 Mon Sep 17 00:00:00 2001 From: jengo Date: Fri, 19 Jan 2001 23:45:37 +0000 Subject: [PATCH] Fixed a few problems with the result objects --- phpgwapi/inc/class.acl.inc.php | 26 +++++--- phpgwapi/inc/class.categories.inc.php | 86 ++++++++++++++++++++------- phpgwapi/inc/class.menutree.inc.php | 70 ++++++++++++++-------- phpgwapi/inc/class.nextmatchs.inc.php | 7 +++ phpgwapi/inc/class.utilities.inc.php | 16 ++--- 5 files changed, 144 insertions(+), 61 deletions(-) diff --git a/phpgwapi/inc/class.acl.inc.php b/phpgwapi/inc/class.acl.inc.php index 83511a795a..b40c3dbba3 100644 --- a/phpgwapi/inc/class.acl.inc.php +++ b/phpgwapi/inc/class.acl.inc.php @@ -25,6 +25,14 @@ class acl { + var $db; + + function acl() + { + global $phpgw; + $this->db = $phpgw->db; + } + /* This is a new class. These are sample table entries insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('filemanager', 'create', 1, 'u', 4); @@ -38,6 +46,8 @@ function check($location, $required, $appname = False){ global $phpgw, $phpgw_info; +// $this->db = $phpgw->db; + if ($appname == False){ $appname = $phpgw_info["flags"]["currentapp"]; } @@ -56,11 +66,11 @@ } $sql .= ")))"; $rights = 0; - $phpgw->db->query($sql ,__LINE__,__FILE__); - if ($phpgw->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; } - while ($phpgw->db->next_record()) { - if ($phpgw->db->f("acl_rights") == 0){ return False; } - $rights |= $phpgw->db->f("acl_rights"); + $this->db->query($sql ,__LINE__,__FILE__); + if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; } + while ($this->db->next_record()) { + if ($this->db->f("acl_rights") == 0){ return False; } + $rights |= $this->db->f("acl_rights"); } return !!($rights & $required); } @@ -68,7 +78,7 @@ function add($app, $location, $id, $id_type, $rights){ $sql = "insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)"; $sql .= " values('".$app."', '".$location."', ".$id.", '".$id_type."', ".$rights.")"; - $phpgw->db->query($sql ,__LINE__,__FILE__); + $this->db->query($sql ,__LINE__,__FILE__); return True; } @@ -76,7 +86,7 @@ $sql = "delete from phpgw_acl where acl_appname='".$app."'"; $sql .= " and acl_location ='".$location."' and "; $sql .= " acl_account_type = '".$id_type."' and acl_account = ".$id.")"; - $phpgw->db->query($sql ,__LINE__,__FILE__); + $this->db->query($sql ,__LINE__,__FILE__); return True; } @@ -84,4 +94,4 @@ } } //end of acl class -?> \ No newline at end of file +?> diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index 662b8ad234..bc879e843a 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -29,7 +29,36 @@ var $app_name; var $cats; var $db; - + + function filter($type) + { + switch ($type) + { + case "subs": $s = " and cat_parent != '0'"; break; + case "mains": $s = " and cat_parent = '0'"; break; + } + return $s; + } + + function return_array($type = "all") + { + $filter = $this->filter($type); + + $this->db->query("select * from phpgw_categories where cat_owner='" + . $this->account_id . "' and cat_appname='" + . $this->app_name . "' $filter",__LINE__,__FILE__); + $i = 0; + while ($this->db->next_record()) { + $cats[$i]["id"] = $this->db->f("cat_id"); + $cats[$i]["parent"] = $this->db->f("cat_parent"); + $cats[$i]["name"] = $this->db->f("cat_name"); + $cats[$i]["description"] = $this->db->f("cat_description"); + $cats[$i]["data"] = $this->db->f("cat_data"); + $i++; + } + return $cats; + } + function categories($account_id = "",$app_name = "") { global $phpgw, $phpgw_info; @@ -44,35 +73,25 @@ $this->account_id = $account_id; $this->app_name = $app_name; $this->db = $phpgw->db; - - $this->db->query("select * from phpgw_categories where cat_owner='$account_id' and cat_appname='" - . "$app_name'",__LINE__,__FILE__); - while ($this->db->next_record()) { - $this->cats[]["id"] = $this->db->f("cat_id"); - $this->cats[]["parent"] = $this->db->f("cat_parent"); - $this->cats[]["name"] = $this->db->f("cat_name"); - $this->cats[]["description"] = $this->db->f("cat_description"); - $this->cats[]["data"] = $this->db->f("cat_data"); - } + $this->cats = $this->return_array(); } // Return into a select box, list or other formats - function formated_list($format,$type) + function formated_list($format,$type,$selected = "") { global $phpgw; - - switch ($type) - { - case "onlymains": $method = "and cat_parent='0'"; break; - case "onlysubs": $method = "and cat_parent !='0'"; break; - } + $filter = $this->filter($type); if ($format == "select") { $this->db->query("select * from phpgw_categories where cat_owner='" . $this->account_id - . "' $method",__LINE__,__FILE__); + . "' $filter",__LINE__,__FILE__); while ($this->db->next_record()) { - $s .= ''; + $s .= ''; } return $s; } @@ -101,5 +120,28 @@ . $this->account_id . "' and cat_id='$cat_id'",__LINE__,__FILE__); } + function return_name($cat_id) + { + $this->db->query("select cat_name from phpgw_categories where cat_id='" + . "$cat_id'",__LINE__,__FILE__); + $this->db->next_record(); + return $this->db->f("cat_name"); + } + + function exists($type,$cat_name) + { + $filter = $this->filter($type); + + $this->db->query("select count(*) from phpgw_categories where cat_name='" + . addslashes($cat_name) . "' and cat_owner='" + . $this->account_id . "' and cat_appname='" + . $this->appname . "' $filter",__LINE__,__FILE__); + $this->db->next_record(); + if ($this->db->f(0)) { + return True; + } else { + return False; + } + } } -?> \ No newline at end of file +?> diff --git a/phpgwapi/inc/class.menutree.inc.php b/phpgwapi/inc/class.menutree.inc.php index c811dea464..04b2b423e2 100644 --- a/phpgwapi/inc/class.menutree.inc.php +++ b/phpgwapi/inc/class.menutree.inc.php @@ -25,6 +25,14 @@ /*********************************************/ class menutree { + var $read_from_file; // You can send the tree info from a string or file + var $root_level_value; // This is what the top level name or image will be + + function menutree() + { + $this->read_from_file = True; + } + function showtree($treefile, $expandlevels="", $num_menus = 50, $invisible_menus = Null){ global $phpgw_info, $phpgw; @@ -53,22 +61,36 @@ class menutree { $maxlevel=0; $cnt=0; - - $fd = fopen($treefile, "r"); - if ($fd==0) die("menutree.inc : Unable to open file ".$treefile); - while ($buffer = fgets($fd, 4096)) { - $tree[$cnt][0]=strspn($buffer,"."); - $tmp=rtrim(substr($buffer,$tree[$cnt][0])); - $node=explode("|",$tmp); - $tree[$cnt][1]=$node[0]; - $tree[$cnt][2]=$node[1]; - $tree[$cnt][3]=$node[2]; - $tree[$cnt][4]=0; - if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; - $cnt++; + + if ($this->read_from_file) { + $fd = fopen($treefile, "r"); + if ($fd==0) die("menutree.inc : Unable to open file ".$treefile); + while ($buffer = fgets($fd, 4096)) { + $tree[$cnt][0]=strspn($buffer,"."); + $tmp=rtrim(substr($buffer,$tree[$cnt][0])); + $node=explode("|",$tmp); + $tree[$cnt][1]=$node[0]; + $tree[$cnt][2]=$node[1]; + $tree[$cnt][3]=$node[2]; + $tree[$cnt][4]=0; + if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; + $cnt++; + } + fclose($fd); + } else { + $ta = explode("\n",$treefile); + while (list($null,$buffer) = each($ta)) { + $tree[$cnt][0]=strspn($buffer,"."); + $tmp=rtrim(substr($buffer,$tree[$cnt][0])); + $node=explode("|",$tmp); + $tree[$cnt][1]=$node[0]; + $tree[$cnt][2]=$node[1]; + $tree[$cnt][3]=$node[2]; + $tree[$cnt][4]=0; + if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; + $cnt++; + } } - fclose($fd); - for ($i=0; $i\n"; - $str .= "link("index.php",$params)."\" target=_parent>\n"; - $str .= ""; + $str .= '' . $this->root_level_value . ''; + $str .= "\n"; for ($i=0; $i<$maxlevel; $i++) $str .= ""; $str .= "\n"; } @@ -213,9 +235,9 @@ class menutree { $i=0; while ($i<$tree[$cnt][0]-1) { if ($levels[$i]==1) - $str .= ""; + $str .= '|'; else - $str .= ""; + $str .= ' '; $i++; } @@ -223,10 +245,10 @@ class menutree { /* corner at end of subtree or t-split */ /****************************************/ if ($tree[$cnt][4]==1) { - $str .= ""; + $str .= '\'; $levels[$tree[$cnt][0]-1]=0; } else { - $str .= ""; + $str .= '|-'; $levels[$tree[$cnt][0]-1]=1; } @@ -236,15 +258,15 @@ class menutree { if ($tree[$cnt+1][0]>$tree[$cnt][0]) { if ($expand[$cnt]==0) - $str .= "link($script,$params)."\">"; + $str .= "link($script,$params)."\">\"+\""; else - $str .= "link($script,$params)."\">"; + $str .= "link($script,$params)."\">\"-\""; } else { /*************************/ /* Tree Leaf */ /*************************/ - $str .= ""; + $str .= 'o'; } /****************************************/ diff --git a/phpgwapi/inc/class.nextmatchs.inc.php b/phpgwapi/inc/class.nextmatchs.inc.php index 0c7f47dac8..cff9012e3a 100644 --- a/phpgwapi/inc/class.nextmatchs.inc.php +++ b/phpgwapi/inc/class.nextmatchs.inc.php @@ -300,6 +300,13 @@ class nextmatchs return $tr_color; } + // If you are using the common bgcolor="{tr_color}" + // This function is a little cleanier approch + function template_alternate_row_color(&$tpl) + { + $tpl->set_var("tr_color",$this->alternate_row_color()); + } + function show_sort_order($sort,$var,$order,$program,$text,$extra="") { global $phpgw, $filter, $qfield, $start, $query; diff --git a/phpgwapi/inc/class.utilities.inc.php b/phpgwapi/inc/class.utilities.inc.php index bac277ee4c..7ea12080ab 100644 --- a/phpgwapi/inc/class.utilities.inc.php +++ b/phpgwapi/inc/class.utilities.inc.php @@ -30,6 +30,8 @@ } unset($d1); // Note: We should add a way to force the developer to say which ones to use. (jengo) + include("/home/httpd/html/phpgroupware/phpgwapi/inc/class.sbox.inc.php"); + class utilities { var $rssparser; @@ -41,13 +43,13 @@ function utilities_() { - $phpgw->rssparser = CreateObject("phpgwapi.rssparser"); - $phpgw->clientsniffer = CreateObject("phpgwapi.clientsniffer"); - $phpgw->http = CreateObject("phpgwapi.http"); - $phpgw->matrixview = CreateObject("phpgwapi.matrixview"); - $phpgw->menutree = CreateObject("phpgwapi.menutree"); - $phpgw->sbox = CreateObject("phpgwapi.sbox"); - $phpgw->sbox = CreateObject("phpgwapi.portalbox"); +// $phpgw->rssparser = CreateObject("phpgwapi.rssparser"); +// $phpgw->clientsniffer = CreateObject("phpgwapi.clientsniffer"); +// $phpgw->http = CreateObject("phpgwapi.http"); + // $phpgw->matrixview = CreateObject("phpgwapi.matrixview"); + // $phpgw->menutree = CreateObject("phpgwapi.menutree"); + $this->sbox = new sbox; +// $phpgw->sbox = CreateObject("phpgwapi.portalbox"); } } ?>