phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: phpgwapi/inc class.categories.inc.php,1.72,1.73


From: Bettina gille <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpgwapi/inc class.categories.inc.php,1.72,1.73
Date: Fri, 11 Jan 2002 23:08:38 -0500

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv21777

Modified Files:
        class.categories.inc.php 
Log Message:
added new function to sort cats list

Index: class.categories.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.categories.inc.php,v
retrieving revision 1.72
retrieving revision 1.73
diff -C2 -r1.72 -r1.73
*** class.categories.inc.php    3 Jan 2002 17:16:56 -0000       1.72
--- class.categories.inc.php    12 Jan 2002 04:08:35 -0000      1.73
***************
*** 193,196 ****
--- 193,310 ----
                }
  
+ 
+               function return_sorted_array($start,$limit = True,$query = 
'',$sort = '',$order = '',$public = False)
+               {
+                       if ($public)
+                       {
+                               $public_cats = " OR cat_appname='phpgw'";
+                       }
+ 
+                       if (!$sort)
+                       {
+                               $sort = 'ASC';
+                       }
+ 
+                       if ($order)
+                       {
+                               $ordermethod = " ORDER BY $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' ORDER BY cat_name ASC';
+                       }
+ 
+                       if (is_array($this->grants))
+                       {
+                               $grants = $this->grants;
+                               while(list($user) = each($grants))
+                               {
+                                       $public_user_list[] = $user;
+                               }
+                               reset($public_user_list);
+                               $grant_cats = " (cat_owner='" . 
$this->account_id . "' OR cat_access='public' AND cat_owner in(" . 
implode(',',$public_user_list) . ")) ";
+                       }
+                       else
+                       {
+                               $grant_cats = " cat_owner='" . 
$this->account_id . "' ";
+                       }
+ 
+                       if ($query)
+                       {
+                               $querymethod = " AND (cat_name LIKE '%$query%' 
OR cat_description LIKE '%$query%') ";
+                       }
+ 
+                       $sql = "SELECT * from phpgw_categories WHERE 
(cat_appname='" . $this->app_name . "' AND" . $grant_cats . $public_cats . ")"
+                                       . $querymethod;
+ 
+                       $mainselect = ' AND cat_level=0';
+ 
+                       $this->db->query($sql . $mainselect . 
$ordermethod,__LINE__,__FILE__);
+ 
+                       $i = 0;
+                       while ($this->db->next_record())
+                       {
+                               $cats[$i]['id']          = 
$this->db->f('cat_id');
+                               $cats[$i]['owner']       = 
$this->db->f('cat_owner');
+                               $cats[$i]['access']      = 
$this->db->f('cat_access');
+                               $cats[$i]['app_name']    = 
$this->db->f('cat_appname');
+                               $cats[$i]['main']        = 
$this->db->f('cat_main');
+                               $cats[$i]['level']       = 
$this->db->f('cat_level');
+                               $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++;
+                       }
+ 
+                       $num_cats = count($cats);
+                       for ($i=0;$i < $num_cats;$i++)
+                       {
+                               $subselect = " AND cat_parent='" . 
$cats[$i]['id'] . "' AND cat_level='" . ($cats[$i]['level']+1) . "'";
+ 
+                               $this->db->query($sql . $subselect . 
$ordermethod,__LINE__,__FILE__);
+ 
+                               $subcats = array();
+                               $j = 0;
+                               while ($this->db->next_record())
+                               {
+                                       $subcats[$j]['id']          = 
$this->db->f('cat_id');
+                                       $subcats[$j]['owner']       = 
$this->db->f('cat_owner');
+                                       $subcats[$j]['access']      = 
$this->db->f('cat_access');
+                                       $subcats[$j]['app_name']    = 
$this->db->f('cat_appname');
+                                       $subcats[$j]['main']        = 
$this->db->f('cat_main');
+                                       $subcats[$j]['level']       = 
$this->db->f('cat_level');
+                                       $subcats[$j]['parent']      = 
$this->db->f('cat_parent');
+                                       $subcats[$j]['name']        = 
$this->db->f('cat_name');
+                                       $subcats[$j]['description'] = 
$this->db->f('cat_description');
+                                       $subcats[$j]['data']        = 
$this->db->f('cat_data');
+                                       $j++;
+                               }
+ 
+                               $num_subcats = count($subcats);
+                               if ($num_subcats != 0)
+                               {
+                                       $newcats = array();
+                                       for ($k = 0; $k <= $i; $k++)
+                                       {
+                                               $newcats[$k] = $cats[$k];
+                                       }
+                                       for ($k = 0; $k < $num_subcats; $k++)
+                                       {
+                                               $newcats[$k+$i+1] = 
$subcats[$k];
+                                       }
+                                       for ($k = $i+1; $k < $num_cats; $k++)
+                                       {
+                                               $newcats[$k+$num_subcats] = 
$cats[$k];
+                                       }
+                                       $cats = $newcats;
+                                       $num_cats = count($cats);
+                               }
+                       }
+                       $this->total_records = count($cats);
+ 
+                       return $cats;
+               }
+ 
                /*!
                @function return_single
***************
*** 220,224 ****
  
                /*!
!               @function formatted_list
                @abstract return into a select box, list or other formats
                @param $format currently only supports select (select box)
--- 334,338 ----
  
                /*!
!               @function formated_list
                @abstract return into a select box, list or other formats
                @param $format currently only supports select (select box)
***************
*** 227,235 ****
                @result $s array - populated with categories
                */
!               function formated_list($format,$type,$selected = '',$public = 
False,$site_link = 'site')
                {
!                       return 
$this->formatted_list($format,$type,$selected,$public,$site_link);
                }
!               function formatted_list($format,$type,$selected = '',$public = 
False,$site_link = 'site')
                {
                        if(is_array($format))
--- 341,349 ----
                @result $s array - populated with categories
                */
!               function formatted_list($format,$type,$selected = '',$public = 
False,$site_link = 'site')
                {
!                       return 
$this->formated_list($format,$type,$selected,$public,$site_link);
                }
!               function formated_list($format,$type,$selected = '',$public = 
False,$site_link = 'site')
                {
                        if(is_array($format))
***************
*** 245,250 ****
                        }
  
-                       $filter = $this->filter($type);
- 
                        if (!is_array($selected))
                        {
--- 359,362 ----
***************
*** 252,259 ****
                        }
  
!                       if ($format == 'select')
                        {
                                $cats = 
$this->return_array($type,$start,False,$query,$sort,$order,$public);
  
                                for ($i=0;$i<count($cats);$i++)
                                {
--- 364,378 ----
                        }
  
!                       if ($type != 'all')
                        {
                                $cats = 
$this->return_array($type,$start,False,$query,$sort,$order,$public);
+                       }
+                       else
+                       {
+                               $cats = 
$this->return_sorted_array($start,False,$query,$sort,$order,$public);
+                       }
  
+                       if ($format == 'select')
+                       {
                                for ($i=0;$i<count($cats);$i++)
                                {
***************
*** 263,267 ****
                                                $s .= ' selected';
                                        }
!                                       $s .= '>' . 
$GLOBALS['phpgw']->strip_html($cats[$i]['name']);
                                        if ($cats[$i]['app_name'] == 'phpgw')
                                        {
--- 382,391 ----
                                                $s .= ' selected';
                                        }
!                                       $s .= '>';
!                                       for ($j=0;$j<$cats[$i]['level'];$j++)
!                                       {
!                                               $s .= '&nbsp;';
!                                       }
!                                       $s .= 
$GLOBALS['phpgw']->strip_html($cats[$i]['name']);
                                        if ($cats[$i]['app_name'] == 'phpgw')
                                        {
***************
*** 277,282 ****
                                $space = '&nbsp;&nbsp;';
  
-                               $cats = 
$this->return_array($type,$start,False,$query,$sort,$order,$public);
- 
                                $s  = '<table border="0" cellpadding="2" 
cellspacing="2">' . "\n";
  
--- 401,404 ----
***************
*** 330,333 ****
--- 452,456 ----
                        $cat_values['descr'] = 
$this->db->db_addslashes($cat_values['descr']);
                        $cat_values['name'] = 
$this->db->db_addslashes($cat_values['name']);
+                       $cat_values['data'] = 
$this->db->db_addslashes($cat_values['data']);
  
                        $this->db->query("INSERT INTO phpgw_categories 
(cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,cat_data,"
***************
*** 385,388 ****
--- 508,512 ----
                        $cat_values['descr'] = 
$this->db->db_addslashes($cat_values['descr']);
                        $cat_values['name'] = 
$this->db->db_addslashes($cat_values['name']);
+                       $cat_values['data'] = 
$this->db->db_addslashes($cat_values['data']);
  
                        $sql = "UPDATE phpgw_categories SET cat_name='" . 
$cat_values['name'] . "', cat_description='" . $cat_values['descr']




reply via email to

[Prev in Thread] Current Thread [Next in Thread]