phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] CVS: phpbrain/inc class.bokb.inc.php,1.7,1.8 class.s


From: Dave Hall <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpbrain/inc class.bokb.inc.php,1.7,1.8 class.sokb.inc.php,1.6,1.7
Date: Mon, 14 Apr 2003 02:47:11 -0400

Update of /cvsroot/phpgroupware/phpbrain/inc
In directory subversions:/tmp/cvs-serv25806/inc

Modified Files:
        class.bokb.inc.php class.sokb.inc.php 
Log Message:
forgot to save one change and to run dos2unix

Index: class.bokb.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpbrain/inc/class.bokb.inc.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** class.bokb.inc.php  14 Apr 2003 06:42:48 -0000      1.7
--- class.bokb.inc.php  14 Apr 2003 06:47:09 -0000      1.8
***************
*** 1,231 ****
! <?php
!       
/**************************************************************************\
!       * phpGroupWare - KnowledgeBase                                          
   *
!       * http://www.phpgroupware.org                                           
   *
!       * Written by Dave Hall [skwashd AT phpgroupware DOT org]                
   *
!       * 
------------------------------------------------------------------------ *
!       * Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/     
   *
!       *  but quickly became a full rewrite                                    
   *
!       * 
------------------------------------------------------------------------ *
!       *  This program is free software; you can redistribute it and/or modify 
it *
!       *  under the terms of the GNU General Public License as published by 
the   *
!       *  Free Software Foundation; either version 2 of the License, or (at 
your  *
!       *  option) any later version.                                           
   *
!       
\**************************************************************************/
! 
!       class bokb
!       {
!       var $so;
!       
!       function bokb()
!       {
!               $this->so = createObject('phpbrain.sokb');
!                       $this->cats = createObject('phpgwapi.categories');
!                       $GLOBALS['phpgw_info']['apps']['phpkb']['config'] = 
$this->get_config();
!       }
!               
!               function get_cat_data($cat_id)
!               {
!                       $cat_id = (int) $cat_id;
!                       $cats = $this->cats->return_array('all', 0, False, '', 
'', '', False, $cat_id);
!                       if(is_array($cats))
!                       {
!                       foreach ($cats as $c_key => $c_vals)
!                       {
!                               $id = $c_vals['id'];
!                               $return_cats[$id] = array('name'                
=> $c_vals['name'],
!                                                                               
'num_entries'   => $this->so->get_count($id)
!                                                                               
);
!   
!                               $sub_cats = $this->cats->return_array('subs', 
0, False, '', '', '', False, $id);
!                               if(is_array($sub_cats))
!                               {
!                                       foreach($sub_cats as $sub_key => 
$sub_vals)
!                                       {
!                                               $sub_id = $sub_vals['id'];
!                                               
$return_cats[$id]['subs'][$sub_id] 
!                                                       = array('name'  => 
$sub_vals['name'],
!                                                               'num_entries'   
=> $this->so->get_count($sub_id)
!                                                               );
!                                       }//end foreach(subcats)
!                                       unset($sub_cats);
!                               }//end if is_array(sub_cats)
!                       }//end foreach(cats)
!                               return $return_cats;
!                       }
!                       else //no cats
!                       {
!                               return false;
!                       }//end if is_array(cats)
! 
!               }//end get_cat_data
! 
!               function get_comments($faq_id)
!               {
!                       $comments = $this->so->get_comments($faq_id);
!                       if(is_array($comments))
!                       {
!                               foreach($comments as $key => $vals)
!                               {
!                                       $comments[$key]['comment_date'] = 
date('d-M-Y', $vals['entered']);
!                                       $comments[$key]['comment_user'] = 
$GLOBALS['phpgw']->common->grab_owner_name($vals['user_id']);
!                               }//end foreach(comment)
!                       }//end is_array(comments)
!                       return $comments;
!               }//end get_comments
! 
!               function get_config()
!               {
!                       if(!is_object($GLOBALS['phpgw']->config))
!                       {
!                               $config = createObject('phpgwapi.config');
!                       }
!                       else
!                       {
!                               $config = $GLOBALS['phpgw']->config;
!                       }
!                       
!                       $config->read_repository();
!                       return $config->config_data;
!                       
!               }//end get_config
!               
!               function get_faq_list($cat_id = '', $unpublished = false)
!               {
!                       if(!$this->is_admin() && $unpublished)
!                       {
!                               $unpublished = false;
!                       }
! 
!                       $faqs = $this->so->get_faq_list($cat_id, $unpublished);
!                       if(is_array($faqs))
!                       {
!                       foreach($faqs as $faq_id => $faq_vals)
!                       {
!                               $faqs[$faq_id]['vote_avg'] = 
(($faq_vals['total'] && $faq_vals['votes'])
!                                                                               
                ? round(($faq_vals['total'] / $faq_vals['votes']),2) : 0);
!                               $faqs[$faq_id]['last_mod'] = date('d-M-Y', 
$faqs[$faq_id]['modified']);
!                                       $faqs[$faq_id]['score'] = '1.00'; 
!                       }
!                       }
!                       return $faqs;
!               }//end get_faq_list
! 
!               function get_item($faq_id)
!               {
!                       $item = $this->so->get_item($faq_id);
!                       if(is_array($item))
!                       {
!                       $item['last_mod']       = date('d-M-Y', 
$item['modified']);
!                               $item['username']       = 
$GLOBALS['phpgw']->common->grab_owner_name($item['user_id']);
!                       $item['rating']         = ($item['votes'] 
!                                                                       ? 
round(($item['total']/$item['votes']),2) : 0);
!                               $item['comments']       = 
$this->get_comments($faq_id); 
!                               $item['title'] = ($item['is_faq'] 
!                                                               ? 
lang('question') . ': '. $item['title']
!                                                               : 
lang('tutorial') . ': '. $item['title']);
! 
!                       }//end if is_array(item)
! 
!                       return $item;
! 
!               }//end get_item
!               
!               function get_latest()
!               {
!                       return $this->so->get_latest();
!               }// end get_latest
!               
!               function get_questions($pending = false)
!               {
!                       if(!$this->is_admin() && $pending)
!                       {
!                               return null;
!                       }
!                       else
!                       {
!                               return $this->so->get_questions($pending);
!                       }
!               }//end questions
! 
!               function get_search_results($search, $show)
!               {
!                       $results = $this->so->get_search_results($search, 
$show);
!                       if(is_array($results))
!                       {
!                       foreach($results as $id => $vals)
!                       {
!                               $results[$id]['vote_avg'] = (($vals['total'] && 
$vals['votes'])
!                                                                               
                ? round(($vals['total'] / $vals['votes']),2) : 0);
!                               $results[$id]['last_mod'] = date('d-M-Y', 
$vals['modified']);
! 
!                                               $results[$id]['title'] = 
($results[$id]['is_faq'] 
!                                                                               
                ? lang('question') . ': '. $results[$id]['title']
!                                                                               
                : lang('tutorial') . ': '. $results[$id]['title']);
!                       }
!                       }
!                       return $results;
!               }//end get search results
!               
!               function get_stats()
!               {
!                       return $this->so->get_stats();
!               }//end get_stats
! 
!               function is_admin()
!               {
!                       return 
isset($GLOBALS['phpgw_info']['user']['apps']['admin']);
!               }//end is_admin
!               
!               function is_anon()
!               {
!                       return 
($GLOBALS['phpgw_info']['apps']['phpkb']['config']['anon_user'] 
!                                               == 
$GLOBALS['phpgw_info']['user']['account_id']);
!               }//end is_anon
! 
!               function save($faq_id, $faq, $question_id)
!               {
!                       
if(!$GLOBALS['phpgw_info']['apps']['phpkb']['config']['alow_tags'])
!                       {
!                       $faq['title'] = strip_tags($faq['title']);
!                       $faq['keywords'] = strip_tags($faq['keywords']);
!                       $faq['text'] = strip_tags($faq['text']);
!                       }
!                       $faq['user_id'] = 
$GLOBALS['phpgw_info']['user']['account_id'];
!                       $new_faq_id = $this->so->save($faq_id, $faq, 
$this->is_admin());
!                       if($new_faq_id && $question_id && !$faq_id)
!                       {
!                               $this->so->delete_question($question_id);
!                       }
!                       return $new_faq_id;
!                       
!               }//end save
!               
!               function set_active_answer($faq_ids)
!               {
!                       return $this->so->set_active_answer($faq_ids);
!               }//end set active answer
!               
!               function set_active_question($question_ids)
!               {
!                       return $this->so->set_active_question($question_ids);
!               }//end set active question
! 
!               function set_comment($faq_id, $comment)
!               {
!                       $this->so->set_comment($faq_id, $comment, 
$GLOBALS['phpgw_info']['user']['account_id']);
!               }//end set comment
! 
!               function set_question($question)
!               {
!                       return $this->so->set_question($question, 
$this->is_admin());
!               }//end set question
!               
!               function set_rating($faq_id, $rating)
!               {
!                       $this->so->set_rating($faq_id, $rating);
!               }//end set_rating
!               
!       }//end class bokb
!       
!       
--- 1,235 ----
! <?php
!       
/**************************************************************************\
!       * phpGroupWare - KnowledgeBase                                          
   *
!       * http://www.phpgroupware.org                                           
   *
!       * Written by Dave Hall [skwashd AT phpgroupware DOT org]                
   *
!       * 
------------------------------------------------------------------------ *
!       * Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/     
   *
!       *  but quickly became a full rewrite                                    
   *
!       * 
------------------------------------------------------------------------ *
!       *  This program is free software; you can redistribute it and/or modify 
it *
!       *  under the terms of the GNU General Public License as published by 
the   *
!       *  Free Software Foundation; either version 2 of the License, or (at 
your  *
!       *  option) any later version.                                           
   *
!       
\**************************************************************************/
! 
!       class bokb
!       {
!       var $so;
!       
!       function bokb()
!       {
!               $this->so = createObject('phpbrain.sokb');
!                       $this->cats = createObject('phpgwapi.categories');
!                       $GLOBALS['phpgw_info']['apps']['phpkb']['config'] = 
$this->get_config();
!       }
!               
!               function get_cat_data($cat_id)
!               {
!                       $cat_id = (int) $cat_id;
!                       $cats = $this->cats->return_array('all', 0, False, '', 
'', '', False, $cat_id);
!                       if(is_array($cats))
!                       {
!                       foreach ($cats as $c_key => $c_vals)
!                       {
!                               $id = $c_vals['id'];
!                               $return_cats[$id] = array('name'                
=> $c_vals['name'],
!                                                                               
'num_entries'   => $this->so->get_count($id)
!                                                                               
);
!   
!                               $sub_cats = $this->cats->return_array('subs', 
0, False, '', '', '', False, $id);
!                               if(is_array($sub_cats))
!                               {
!                                       foreach($sub_cats as $sub_key => 
$sub_vals)
!                                       {
!                                               $sub_id = $sub_vals['id'];
!                                               
$return_cats[$id]['subs'][$sub_id] 
!                                                       = array('name'  => 
$sub_vals['name'],
!                                                               'num_entries'   
=> $this->so->get_count($sub_id)
!                                                               );
!                                       }//end foreach(subcats)
!                                       unset($sub_cats);
!                               }//end if is_array(sub_cats)
!                       }//end foreach(cats)
!                               return $return_cats;
!                       }
!                       else //no cats
!                       {
!                               return false;
!                       }//end if is_array(cats)
! 
!               }//end get_cat_data
! 
!               function get_comments($faq_id)
!               {
!                       $comments = $this->so->get_comments($faq_id);
!                       if(is_array($comments))
!                       {
!                               foreach($comments as $key => $vals)
!                               {
!                                       $comments[$key]['comment_date'] = 
date('d-M-Y', $vals['entered']);
!                                       $comments[$key]['comment_user'] = 
$GLOBALS['phpgw']->common->grab_owner_name($vals['user_id']);
!                               }//end foreach(comment)
!                       }//end is_array(comments)
!                       return $comments;
!               }//end get_comments
! 
!               function get_config()
!               {
!                       if(!is_object($GLOBALS['phpgw']->config))
!                       {
!                               $config = createObject('phpgwapi.config');
!                       }
!                       else
!                       {
!                               $config = $GLOBALS['phpgw']->config;
!                       }
!                       
!                       $config->read_repository();
!                       return $config->config_data;
!                       
!               }//end get_config
!               
!               function get_faq_list($cat_id = '', $unpublished = false)
!               {
!                       if(!$this->is_admin() && $unpublished)
!                       {
!                               $unpublished = false;
!                       }
! 
!                       $faqs = $this->so->get_faq_list($cat_id, $unpublished);
!                       if(is_array($faqs))
!                       {
!                       foreach($faqs as $faq_id => $faq_vals)
!                       {
!                               $faqs[$faq_id]['vote_avg'] = 
(($faq_vals['total'] && $faq_vals['votes'])
!                                                                               
                ? round(($faq_vals['total'] / $faq_vals['votes']),2) : 0);
!                               $faqs[$faq_id]['last_mod'] = date('d-M-Y', 
$faqs[$faq_id]['modified']);
!                                       $faqs[$faq_id]['score'] = '1.00'; 
!                                       $faqs[$faq_id]['title'] = 
($item['is_faq'] 
!                                                                               
        ? lang('question') . ': '. $faqs[$faq_id]['title']
!                                                                               
        : lang('tutorial') . ': '. $faqs[$faq_id]['title']);
! 
!                       }
!                       }
!                       return $faqs;
!               }//end get_faq_list
! 
!               function get_item($faq_id)
!               {
!                       $item = $this->so->get_item($faq_id);
!                       if(is_array($item))
!                       {
!                       $item['last_mod']       = date('d-M-Y', 
$item['modified']);
!                               $item['username']       = 
$GLOBALS['phpgw']->common->grab_owner_name($item['user_id']);
!                       $item['rating']         = ($item['votes'] 
!                                                                       ? 
round(($item['total']/$item['votes']),2) : 0);
!                               $item['comments']       = 
$this->get_comments($faq_id); 
!                               $item['title'] = ($item['is_faq'] 
!                                                               ? 
lang('question') . ': '. $item['title']
!                                                               : 
lang('tutorial') . ': '. $item['title']);
! 
!                       }//end if is_array(item)
! 
!                       return $item;
! 
!               }//end get_item
!               
!               function get_latest()
!               {
!                       return $this->so->get_latest();
!               }// end get_latest
!               
!               function get_questions($pending = false)
!               {
!                       if(!$this->is_admin() && $pending)
!                       {
!                               return null;
!                       }
!                       else
!                       {
!                               return $this->so->get_questions($pending);
!                       }
!               }//end questions
! 
!               function get_search_results($search, $show)
!               {
!                       $results = $this->so->get_search_results($search, 
$show);
!                       if(is_array($results))
!                       {
!                       foreach($results as $id => $vals)
!                       {
!                               $results[$id]['vote_avg'] = (($vals['total'] && 
$vals['votes'])
!                                                                               
                ? round(($vals['total'] / $vals['votes']),2) : 0);
!                               $results[$id]['last_mod'] = date('d-M-Y', 
$vals['modified']);
! 
!                                               $results[$id]['title'] = 
($results[$id]['is_faq'] 
!                                                                               
                ? lang('question') . ': '. $results[$id]['title']
!                                                                               
                : lang('tutorial') . ': '. $results[$id]['title']);
!                       }
!                       }
!                       return $results;
!               }//end get search results
!               
!               function get_stats()
!               {
!                       return $this->so->get_stats();
!               }//end get_stats
! 
!               function is_admin()
!               {
!                       return 
isset($GLOBALS['phpgw_info']['user']['apps']['admin']);
!               }//end is_admin
!               
!               function is_anon()
!               {
!                       return 
($GLOBALS['phpgw_info']['apps']['phpkb']['config']['anon_user'] 
!                                               == 
$GLOBALS['phpgw_info']['user']['account_id']);
!               }//end is_anon
! 
!               function save($faq_id, $faq, $question_id)
!               {
!                       
if(!$GLOBALS['phpgw_info']['apps']['phpkb']['config']['alow_tags'])
!                       {
!                       $faq['title'] = strip_tags($faq['title']);
!                       $faq['keywords'] = strip_tags($faq['keywords']);
!                       $faq['text'] = strip_tags($faq['text']);
!                       }
!                       $faq['user_id'] = 
$GLOBALS['phpgw_info']['user']['account_id'];
!                       $new_faq_id = $this->so->save($faq_id, $faq, 
$this->is_admin());
!                       if($new_faq_id && $question_id && !$faq_id)
!                       {
!                               $this->so->delete_question($question_id);
!                       }
!                       return $new_faq_id;
!                       
!               }//end save
!               
!               function set_active_answer($faq_ids)
!               {
!                       return $this->so->set_active_answer($faq_ids);
!               }//end set active answer
!               
!               function set_active_question($question_ids)
!               {
!                       return $this->so->set_active_question($question_ids);
!               }//end set active question
! 
!               function set_comment($faq_id, $comment)
!               {
!                       $this->so->set_comment($faq_id, $comment, 
$GLOBALS['phpgw_info']['user']['account_id']);
!               }//end set comment
! 
!               function set_question($question)
!               {
!                       return $this->so->set_question($question, 
$this->is_admin());
!               }//end set question
!               
!               function set_rating($faq_id, $rating)
!               {
!                       $this->so->set_rating($faq_id, $rating);
!               }//end set_rating
!               
!       }//end class bokb
!       
!       

Index: class.sokb.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpbrain/inc/class.sokb.inc.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** class.sokb.inc.php  14 Apr 2003 06:42:48 -0000      1.6
--- class.sokb.inc.php  14 Apr 2003 06:47:09 -0000      1.7
***************
*** 1,377 ****
! <?php
!       
/**************************************************************************\
!       * phpGroupWare - KnowledgeBase                                          
   *
!       * http://www.phpgroupware.org                                           
   *
!       * Written by Dave Hall [skwashd AT phpgroupware DOT org]                
   *
!       * 
------------------------------------------------------------------------ *
!       * Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/     
         *
!       *  but quickly became a full rewrite                                    
                                         *
!       * 
------------------------------------------------------------------------ *
!       *  This program is free software; you can redistribute it and/or modify 
it *
!       *  under the terms of the GNU General Public License as published by 
the   *
!       *  Free Software Foundation; either version 2 of the License, or (at 
your  *
!       *  option) any later version.                                           
   *
!       
\**************************************************************************/
!       
!       class sokb
!       {
!               var $db;
!               
!               function sokb()
!               {
!                       $this->db = $GLOBALS['phpgw']->db;
!               }
! 
!               function delete_answer($faq_ids)
!               {
!                       if(is_array($faq_ids))
!                       {
!                               $i=0;
!                       foreach($faq_ids as $key => $val)
!                       {
!                               $this->db->query("DELETE FROM phpgw_kb_faq 
WHERE faq_id = $key");
!                               $i++;
!                       }//end foreach(q_id)
!                       }
!                       elseif(is_int($faq_ids))
!                       {
!                               $this->db->query("DELETE FROM phpgw_kb_faq 
WHERE faq_id = $faq_ids");
!                               $i = 1;
!                       }//end is_type
!                       return $i;
!               }//end delete_answer
! 
!               function delete_question($question_ids)
!               {
!                       if(is_array($question_ids))
!                       {
!                               $i=0;
!                       foreach($question_ids as $key => $val)
!                       {
!                               $this->db->query("DELETE FROM 
phpgw_kb_questions WHERE question_id = $key");
!                               $i++;
!                       }//end foreach(q_id)
!                       }
!                       elseif(is_int($question_ids))
!                       {
!                               $this->db->query("DELETE FROM 
phpgw_kb_questions WHERE question_id = $question_ids");
!                               $i = 1;
!                       }//end is_type
!                       return $i;
!               }//end delete question
! 
!               function get_stats()
!               {       
!                       $stats = array();
!       /* how many faqs*/
!       $this->db->query('SELECT COUNT(*) FROM phpgw_kb_faq WHERE published = 1 
AND is_faq = 0', __LINE__, __FILE__);
!       $this->db->next_record();
!       $stats['num_faqs'] = $this->db->f(0);
!     
!       /* how many tutorials? */
!       $this->db->query('SELECT COUNT(*) FROM phpgw_kb_faq WHERE published = 1 
AND is_faq = 1', __LINE__, __FILE__);
!       $this->db->next_record();
!       $stats['num_tutes'] = $this->db->f(0);
!     
!       /* how many open questions? */
!       $this->db->query('SELECT COUNT(*) FROM phpgw_kb_questions WHERE pending 
= 0', __LINE__, __FILE__);
!                       $this->db->next_record();
!       $stats['num_open'] = $this->db->f(0);
!                       
!                       return $stats;
!               }
!               
!               function get_latest()
!               {
!       /* latest questions */
!       $this->db->limit_query('SELECT * FROM phpgw_kb_questions WHERE pending 
= 0 ORDER BY question_id DESC', 0, __LINE__, __FILE__, 3);
! 
!                       $questions = array();
!       while($this->db->next_record())
!                       {
!               $questions[$this->db->f('question_id')] = 
$this->db->f('question', true);
!       }
!                       return $questions;
!       }//end get latest
!               
!               function get_faq_list($cat_id = '', $unpublished = false)
!               {
!       $where  = ((strlen($cat_id) != 0) ? "cat_id = $cat_id " : '');
!                       $where .= ((strlen($where) > 0) ? 'AND ' : '');
!                       $where .= ($unpublished ? 'published = 0' : 'published 
= 1'); 
!                       $this->db->query("SELECT * FROM phpgw_kb_faq WHERE 
$where", __LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $faqs[$this->db->f('faq_id')] = array('title'   
=> $this->db->f('title', true),
!                                                                       'text'  
        => substr($this->db->f('text', true),0,50) . ' ...',
!                                                                       
'modified'      => $this->db->f('modified'),
!                                                                       'views' 
        => $this->db->f('views'),
!                                                                       'votes' 
        => $this->db->f('votes'),
!                                                                       'total' 
        => $this->db->f('total')
!                                                                               
                );
!                       }
!                       return $faqs;
!               }
!               
!               function get_item($faq_id)
!               {
!                       $this->db->query("SELECT * FROM phpgw_kb_faq WHERE 
faq_id = $faq_id", __LINE__, __FILE__);
!                       if($this->db->next_record())
!                       {
!                               $item = array('faq_id'          => 
$this->db->f('faq_id'),
!                                               'title'                 => 
$this->db->f('title', true),
!                                               'text'                  => 
$this->db->f('text', true),
!                                               'cat_id'                => 
$this->db->f('cat_id', true),
!                                               'published'             => 
$this->db->f('published'),
!                                               'keywords'              => 
$this->db->f('keywords', true),
!                                               'user_id'               => 
$this->db->f('user_id'),
!                                               'views'                 => 
$this->db->f('views'),
!                                               'modified'              => 
$this->db->f('modified'),
!                                               'type'                  => 
$this->db->f('type'),
!                                               'url'                   => 
$this->db->f('url', true),
!                                               'votes'                 => 
$this->db->f('votes'),
!                                               'total'                 => 
$this->db->f('total')
!                                                       );
! 
!                               $this->set_view($this->db->f('faq_id'));
!                       }
!                       return $item;
!               }
!               
!               function get_comments($faq_id)
!               {
!                       $this->db->query("SELECT * FROM phpgw_kb_comment WHERE 
faq_id = $faq_id", __LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $comment[$this->db->f('comment_id')] = 
array('user_id'  => $this->db->f('user_id'),
!                                                                               
'comment_text'                  => $this->db->f('comment', true),
!                                                                               
'entered'                       => $this->db->f('entered')
!                                                                               
                        );
!                       }
!                       return $comment;
!               }
! 
!     function get_count($cat_id)
!     {
!       $this->db->query("SELECT COUNT(*) FROM phpgw_kb_faq WHERE cat_id = 
$cat_id AND published = 1", __LINE__, __FILE__);
!                       if($this->db->next_record())
!                       {
!                               return $this->db->f(0); 
!                       }
!                       else
!                       {
!                               return 0;
!                       }
!     }//end get count
!               
!               function get_pending()
!               {
!                       $this->db->query('SELECT faq_id, text FROM phpgw_kb_faq 
WHERE published = 0');
!                       while($this->db->next_record())
!                       {
!                               $faq[$this->db->f('faq_id')] = 
$this->db->f('text', true); 
!                       }
!                       return $faq;
!               }//end get pending
! 
!               
!               function get_search_results($search, $show = null)
!               {
!                       switch 
(trim($GLOBALS['phpgw_info']['server']['db_type']))
!                       {
!                               case 'mysql':
!                                       $ver = explode('-', 
mysql_get_server_info());
!                                       $ver = $ver[0];
!                                       
if($GLOBALS['phpgw']->common->cmp_version_long($ver, '3.23.23') <= 1)
!                                       {
!                                               return 
$this->search_mysql($search, $show);
!                                       }
!                                       else
!                                       {
!                                               return 
$this->search_ansisql($search, $show);
!                                       }
!                                       break;
!                               //case 'pgsql': - //future use
!                               //case 'mssql': - //future use
!                               default:
!                                       return $this->search_ansisql($search, 
$show);
!                       }//end case db
!                               
!               }
! 
!               function get_questions($pending = false)
!               {
!                       $where = ($pending ? 'pending = 1' : 'pending = 0');
!                       $this->db->query("SELECT * FROM phpgw_kb_questions 
WHERE $where", __LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $open_q[$this->db->f('question_id')] = 
$this->db->f('question', true); 
!                       }
!                       return $open_q;
!               }
!               
!               function save($faq_id, $faq, $admin)
!               {
!                       if(is_int($faq_id) && is_array($faq))
!                       {
!                               if($faq_id)//is new?
!                               {
!                                       $sql  =  'UPDATE phpgw_kb_faq';
!                                       $sql .= ' SET cat_id = ' . 
$faq['cat_id'] . ',';
!                                       $sql .= ' title = "' . 
$this->db->db_addslashes($faq['title']) . '",';
!                                       $sql .= ' keyword = "' . 
$this->db->db_addslashes($faq['keyword']) . '",';
!                                       $sql .= ' text = "' . 
$this->db->db_addslashes($faq['text']) . '",';
!                                       $sql .= ' modified = ' . time() .',';
!                                       $sql .= ' user_id = ' . $faq['user_id'] 
.',';
!                                       $sql .= ' published = ' . ($admin ? 1 : 
0) . ', ';
!                                       $sql .= ' is_faq = ' . $faq['is_faq'];
!                                       $sql .= " WHERE faq_id = $faq_id";
!                                       $this->db->query($sql);
!                                       if($this->db->affected_rows() == 1)
!                                       {
!                                               return $faq_id;
!                                       }
!                                       else//something went wrong
!                                       {
!                                               return false;
!                                       } 
!                               }
!                               else//must be new
!                               {
!                                       $sql  = 'INSERT INTO phpgw_kb_faq 
(title, text, cat_id, published, keywords, user_id, views, modified, is_faq, 
url) ';
!                                       $sql .= "VALUES('" . 
$this->db->db_addslashes($faq['title']) . "', ";
!                                       $sql .= "'" . 
$this->db->db_addslashes($faq['text']) . "', ";
!                                       $sql .= $faq['cat_id'] . ", ";
!                                       $sql .= "1, '" . 
$this->db->db_addslashes($faq['keywords']) . "',";
!                                       $sql .= $faq['user_id'] . ', ';
!                                       $sql .= '0, ' . time() . ',  ' . 
$faq['is_faq'] . ", '')";//url is empty for now
!                                       $this->db->query($sql);
!                                       return 
$this->db->get_last_insert_id('phpgw_kb_faq', 'faq_id');
!                               }//end is new
!                       }//end if is valid
!               }//end save
!               
!               function set_active_answer($faq_ids)
!               {
!                       $i=0;
!                       foreach($faq_ids as $key => $val)
!                       {
!                               $this->db->query("UPDATE phpgw_kb_faq SET 
published = 1 WHERE faq_id = $key", __LINE__, __FILE__);
!                               $i++;
!                       }
!                       return $i;
!               }//end set_active_answer
! 
!               function set_active_question($question_ids)
!               {
!                       $i=0;
!                       foreach($question_ids as $key => $val)
!                       {
!                               $this->db->query("UPDATE phpgw_kb_questions SET 
pending = 0 WHERE question_id = $key", __LINE__, __FILE__);
!                               $i++;
!                       }
!                       return $i;
!               }//end set_active_question
! 
!               function set_comment($faq_id, $comment, $user_id)
!               {
!                       $sql  = 'INSERT INTO phpgw_kb_comment(user_id, comment, 
entered, faq_id) ';
!                       $sql .= "VALUES($user_id, '" . 
$this->db->db_addslashes($comment) . "', ". time() .", $faq_id)";
!                       $this->db->query($sql); 
!               }
! 
!               
!               //generic 
!               function search_ansisql($search, $show)
!               {
!                       $select  = 'SELECT * FROM phpgw_kb_faq ';
!                       $select .= 'WHERE published = 1 ';
!                       if(is_int($show))
!                       {
!                               $select .= "AND is_faq = $show ";
!                       }
!                       $search_words = expode(' ', $search);
!                       $cycle = 0;
!                       foreach($search_words as $id => $word)
!                       {
!                               if($cycle)
!                               {
!                                       $title .= "OR title LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $keywords .= "OR keywords LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $text .= "OR text LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                               }
!                               else
!                               {
!                                       $title .= "(title LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $keywords .= "(keywords LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $text .= "(text LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                               }
!                       }
!                       $title .= ") ";
!                       $keywords .= ") ";
!                       $text .= ") ";
!                       
!                       $sql = $select . 'AND' . $title . 'OR' . $keywords . 
'OR' . $text;
!                       $this->db->query($sql);
!                       while($this->db->next_record())
!                       {
!                               $rows[$this->db->f('faq_id')] = 
$this->db->Record;
!                               $rows[$this->db->f('faq_id')]['score'] = 0.00;
!                       }
!                       return $rows;
!               }//end search ansisql
! 
!               function search_mysql($search)
!               {
!                       $sql  = 'SELECT *, ';
!                       $sql .= "MATCH text,keywords,title AGAINST('" . 
addslashes($search) ."') AS score ";
!                       $sql .= 'FROM phpgw_kb_faq ';
!                       $sql .= 'WHERE published = 1 ';
!                       if(is_int($show))
!                       {
!                               $sql .= "AND is_faq = $show ";
!                       }
!                       //$sql .= 'HAVING (score > 0) '; //- this isn't working 
properly afaik
!                       $sql .= 'ORDER BY score DESC';
!                       $this->db->query($sql);
!                       while($this->db->next_record())
!                       {
!                               $rows[$this->db->f('faq_id')] = 
$this->db->Record;
!                       }
!                       return $rows;
!               }//end search mysql
!               
!               function set_rating($faq_id, $rating)
!               {
!                       $this->db->query("UPDATE phpgw_kb_faq "
!                                                       ."SET votes=votes+1, 
total=total+$rating "
!                                                       ."WHERE 
faq_id=$faq_id",__LINE__, __FILE__
!                                                       );
!               }//end set rating
!               
!               function set_question($question, $admin)
!               {
!                       $sql  = 'INSERT INTO phpgw_kb_questions(question, 
pending) ';
!                       $sql .= 'VALUES("' . 
$this->db->db_addslashes($question) .'", ';
!                       $sql .= ($admin ? 0 : 1) .')';
!                       $this->db->query($sql, __LINE__, __FILE__);
!                       if($this->db->get_last_insert_id('phpgw_kb_questions', 
' question_id'))//worked
!                       {
!                               return true;
!                       }
!                       else//must have failed
!                       {
!                               return false;
!                       }//end if worked
!               }//end set question
! 
!               function set_view($faq_id)
!               {
!                       $this->db->query("UPDATE phpgw_kb_faq "
!                                                       ."SET views=views+1 "
!                                                       ."WHERE 
faq_id=$faq_id",__LINE__, __FILE__
!                                                       );
!               }
!               
!       }
! ?>
--- 1,377 ----
! <?php
!       
/**************************************************************************\
!       * phpGroupWare - KnowledgeBase                                          
   *
!       * http://www.phpgroupware.org                                           
   *
!       * Written by Dave Hall [skwashd AT phpgroupware DOT org]                
   *
!       * 
------------------------------------------------------------------------ *
!       * Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/     
         *
!       *  but quickly became a full rewrite                                    
                                         *
!       * 
------------------------------------------------------------------------ *
!       *  This program is free software; you can redistribute it and/or modify 
it *
!       *  under the terms of the GNU General Public License as published by 
the   *
!       *  Free Software Foundation; either version 2 of the License, or (at 
your  *
!       *  option) any later version.                                           
   *
!       
\**************************************************************************/
!       
!       class sokb
!       {
!               var $db;
!               
!               function sokb()
!               {
!                       $this->db = $GLOBALS['phpgw']->db;
!               }
! 
!               function delete_answer($faq_ids)
!               {
!                       if(is_array($faq_ids))
!                       {
!                               $i=0;
!                       foreach($faq_ids as $key => $val)
!                       {
!                               $this->db->query("DELETE FROM phpgw_kb_faq 
WHERE faq_id = $key");
!                               $i++;
!                       }//end foreach(q_id)
!                       }
!                       elseif(is_int($faq_ids))
!                       {
!                               $this->db->query("DELETE FROM phpgw_kb_faq 
WHERE faq_id = $faq_ids");
!                               $i = 1;
!                       }//end is_type
!                       return $i;
!               }//end delete_answer
! 
!               function delete_question($question_ids)
!               {
!                       if(is_array($question_ids))
!                       {
!                               $i=0;
!                       foreach($question_ids as $key => $val)
!                       {
!                               $this->db->query("DELETE FROM 
phpgw_kb_questions WHERE question_id = $key");
!                               $i++;
!                       }//end foreach(q_id)
!                       }
!                       elseif(is_int($question_ids))
!                       {
!                               $this->db->query("DELETE FROM 
phpgw_kb_questions WHERE question_id = $question_ids");
!                               $i = 1;
!                       }//end is_type
!                       return $i;
!               }//end delete question
! 
!               function get_stats()
!               {       
!                       $stats = array();
!       /* how many faqs*/
!       $this->db->query('SELECT COUNT(*) FROM phpgw_kb_faq WHERE published = 1 
AND is_faq = 0', __LINE__, __FILE__);
!       $this->db->next_record();
!       $stats['num_faqs'] = $this->db->f(0);
!     
!       /* how many tutorials? */
!       $this->db->query('SELECT COUNT(*) FROM phpgw_kb_faq WHERE published = 1 
AND is_faq = 1', __LINE__, __FILE__);
!       $this->db->next_record();
!       $stats['num_tutes'] = $this->db->f(0);
!     
!       /* how many open questions? */
!       $this->db->query('SELECT COUNT(*) FROM phpgw_kb_questions WHERE pending 
= 0', __LINE__, __FILE__);
!                       $this->db->next_record();
!       $stats['num_open'] = $this->db->f(0);
!                       
!                       return $stats;
!               }
!               
!               function get_latest()
!               {
!       /* latest questions */
!       $this->db->limit_query('SELECT * FROM phpgw_kb_questions WHERE pending 
= 0 ORDER BY question_id DESC', 0, __LINE__, __FILE__, 3);
! 
!                       $questions = array();
!       while($this->db->next_record())
!                       {
!               $questions[$this->db->f('question_id')] = 
$this->db->f('question', true);
!       }
!                       return $questions;
!       }//end get latest
!               
!               function get_faq_list($cat_id = '', $unpublished = false)
!               {
!       $where  = ((strlen($cat_id) != 0) ? "cat_id = $cat_id " : '');
!                       $where .= ((strlen($where) > 0) ? 'AND ' : '');
!                       $where .= ($unpublished ? 'published = 0' : 'published 
= 1'); 
!                       $this->db->query("SELECT * FROM phpgw_kb_faq WHERE 
$where", __LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $faqs[$this->db->f('faq_id')] = array('title'   
=> $this->db->f('title', true),
!                                                                       'text'  
        => substr($this->db->f('text', true),0,50) . ' ...',
!                                                                       
'modified'      => $this->db->f('modified'),
!                                                                       'views' 
        => $this->db->f('views'),
!                                                                       'votes' 
        => $this->db->f('votes'),
!                                                                       'total' 
        => $this->db->f('total')
!                                                                               
                );
!                       }
!                       return $faqs;
!               }
!               
!               function get_item($faq_id)
!               {
!                       $this->db->query("SELECT * FROM phpgw_kb_faq WHERE 
faq_id = $faq_id", __LINE__, __FILE__);
!                       if($this->db->next_record())
!                       {
!                               $item = array('faq_id'          => 
$this->db->f('faq_id'),
!                                               'title'                 => 
$this->db->f('title', true),
!                                               'text'                  => 
$this->db->f('text', true),
!                                               'cat_id'                => 
$this->db->f('cat_id', true),
!                                               'published'             => 
$this->db->f('published'),
!                                               'keywords'              => 
$this->db->f('keywords', true),
!                                               'user_id'               => 
$this->db->f('user_id'),
!                                               'views'                 => 
$this->db->f('views'),
!                                               'modified'              => 
$this->db->f('modified'),
!                                               'type'                  => 
$this->db->f('type'),
!                                               'url'                   => 
$this->db->f('url', true),
!                                               'votes'                 => 
$this->db->f('votes'),
!                                               'total'                 => 
$this->db->f('total')
!                                                       );
! 
!                               $this->set_view($this->db->f('faq_id'));
!                       }
!                       return $item;
!               }
!               
!               function get_comments($faq_id)
!               {
!                       $this->db->query("SELECT * FROM phpgw_kb_comment WHERE 
faq_id = $faq_id", __LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $comment[$this->db->f('comment_id')] = 
array('user_id'  => $this->db->f('user_id'),
!                                                                               
'comment_text'                  => $this->db->f('comment', true),
!                                                                               
'entered'                       => $this->db->f('entered')
!                                                                               
                        );
!                       }
!                       return $comment;
!               }
! 
!     function get_count($cat_id)
!     {
!       $this->db->query("SELECT COUNT(*) FROM phpgw_kb_faq WHERE cat_id = 
$cat_id AND published = 1", __LINE__, __FILE__);
!                       if($this->db->next_record())
!                       {
!                               return $this->db->f(0); 
!                       }
!                       else
!                       {
!                               return 0;
!                       }
!     }//end get count
!               
!               function get_pending()
!               {
!                       $this->db->query('SELECT faq_id, text FROM phpgw_kb_faq 
WHERE published = 0');
!                       while($this->db->next_record())
!                       {
!                               $faq[$this->db->f('faq_id')] = 
$this->db->f('text', true); 
!                       }
!                       return $faq;
!               }//end get pending
! 
!               
!               function get_search_results($search, $show = null)
!               {
!                       switch 
(trim($GLOBALS['phpgw_info']['server']['db_type']))
!                       {
!                               case 'mysql':
!                                       $ver = explode('-', 
mysql_get_server_info());
!                                       $ver = $ver[0];
!                                       
if($GLOBALS['phpgw']->common->cmp_version_long($ver, '3.23.23') <= 1)
!                                       {
!                                               return 
$this->search_mysql($search, $show);
!                                       }
!                                       else
!                                       {
!                                               return 
$this->search_ansisql($search, $show);
!                                       }
!                                       break;
!                               //case 'pgsql': - //future use
!                               //case 'mssql': - //future use
!                               default:
!                                       return $this->search_ansisql($search, 
$show);
!                       }//end case db
!                               
!               }
! 
!               function get_questions($pending = false)
!               {
!                       $where = ($pending ? 'pending = 1' : 'pending = 0');
!                       $this->db->query("SELECT * FROM phpgw_kb_questions 
WHERE $where", __LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $open_q[$this->db->f('question_id')] = 
$this->db->f('question', true); 
!                       }
!                       return $open_q;
!               }
!               
!               function save($faq_id, $faq, $admin)
!               {
!                       if(is_int($faq_id) && is_array($faq))
!                       {
!                               if($faq_id)//is new?
!                               {
!                                       $sql  =  'UPDATE phpgw_kb_faq';
!                                       $sql .= ' SET cat_id = ' . 
$faq['cat_id'] . ',';
!                                       $sql .= ' title = "' . 
$this->db->db_addslashes($faq['title']) . '",';
!                                       $sql .= ' keyword = "' . 
$this->db->db_addslashes($faq['keyword']) . '",';
!                                       $sql .= ' text = "' . 
$this->db->db_addslashes($faq['text']) . '",';
!                                       $sql .= ' modified = ' . time() .',';
!                                       $sql .= ' user_id = ' . $faq['user_id'] 
.',';
!                                       $sql .= ' published = ' . ($admin ? 1 : 
0) . ', ';
!                                       $sql .= ' is_faq = ' . $faq['is_faq'];
!                                       $sql .= " WHERE faq_id = $faq_id";
!                                       $this->db->query($sql);
!                                       if($this->db->affected_rows() == 1)
!                                       {
!                                               return $faq_id;
!                                       }
!                                       else//something went wrong
!                                       {
!                                               return false;
!                                       } 
!                               }
!                               else//must be new
!                               {
!                                       $sql  = 'INSERT INTO phpgw_kb_faq 
(title, text, cat_id, published, keywords, user_id, views, modified, is_faq, 
url) ';
!                                       $sql .= "VALUES('" . 
$this->db->db_addslashes($faq['title']) . "', ";
!                                       $sql .= "'" . 
$this->db->db_addslashes($faq['text']) . "', ";
!                                       $sql .= $faq['cat_id'] . ", ";
!                                       $sql .= "1, '" . 
$this->db->db_addslashes($faq['keywords']) . "',";
!                                       $sql .= $faq['user_id'] . ', ';
!                                       $sql .= '0, ' . time() . ',  ' . 
$faq['is_faq'] . ", '')";//url is empty for now
!                                       $this->db->query($sql);
!                                       return 
$this->db->get_last_insert_id('phpgw_kb_faq', 'faq_id');
!                               }//end is new
!                       }//end if is valid
!               }//end save
!               
!               function set_active_answer($faq_ids)
!               {
!                       $i=0;
!                       foreach($faq_ids as $key => $val)
!                       {
!                               $this->db->query("UPDATE phpgw_kb_faq SET 
published = 1 WHERE faq_id = $key", __LINE__, __FILE__);
!                               $i++;
!                       }
!                       return $i;
!               }//end set_active_answer
! 
!               function set_active_question($question_ids)
!               {
!                       $i=0;
!                       foreach($question_ids as $key => $val)
!                       {
!                               $this->db->query("UPDATE phpgw_kb_questions SET 
pending = 0 WHERE question_id = $key", __LINE__, __FILE__);
!                               $i++;
!                       }
!                       return $i;
!               }//end set_active_question
! 
!               function set_comment($faq_id, $comment, $user_id)
!               {
!                       $sql  = 'INSERT INTO phpgw_kb_comment(user_id, comment, 
entered, faq_id) ';
!                       $sql .= "VALUES($user_id, '" . 
$this->db->db_addslashes($comment) . "', ". time() .", $faq_id)";
!                       $this->db->query($sql); 
!               }
! 
!               
!               //generic 
!               function search_ansisql($search, $show)
!               {
!                       $select  = 'SELECT * FROM phpgw_kb_faq ';
!                       $select .= 'WHERE published = 1 ';
!                       if(is_int($show))
!                       {
!                               $select .= "AND is_faq = $show ";
!                       }
!                       $search_words = expode(' ', $search);
!                       $cycle = 0;
!                       foreach($search_words as $id => $word)
!                       {
!                               if($cycle)
!                               {
!                                       $title .= "OR title LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $keywords .= "OR keywords LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $text .= "OR text LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                               }
!                               else
!                               {
!                                       $title .= "(title LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $keywords .= "(keywords LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                                       $text .= "(text LIKE '%" . 
$this->db->db_addslashes($word) . "%' ";
!                               }
!                       }
!                       $title .= ") ";
!                       $keywords .= ") ";
!                       $text .= ") ";
!                       
!                       $sql = $select . 'AND' . $title . 'OR' . $keywords . 
'OR' . $text;
!                       $this->db->query($sql);
!                       while($this->db->next_record())
!                       {
!                               $rows[$this->db->f('faq_id')] = 
$this->db->Record;
!                               $rows[$this->db->f('faq_id')]['score'] = 0.00;
!                       }
!                       return $rows;
!               }//end search ansisql
! 
!               function search_mysql($search)
!               {
!                       $sql  = 'SELECT *, ';
!                       $sql .= "MATCH text,keywords,title AGAINST('" . 
addslashes($search) ."') AS score ";
!                       $sql .= 'FROM phpgw_kb_faq ';
!                       $sql .= 'WHERE published = 1 ';
!                       if(is_int($show))
!                       {
!                               $sql .= "AND is_faq = $show ";
!                       }
!                       //$sql .= 'HAVING (score > 0) '; //- this isn't working 
properly afaik
!                       $sql .= 'ORDER BY score DESC';
!                       $this->db->query($sql);
!                       while($this->db->next_record())
!                       {
!                               $rows[$this->db->f('faq_id')] = 
$this->db->Record;
!                       }
!                       return $rows;
!               }//end search mysql
!               
!               function set_rating($faq_id, $rating)
!               {
!                       $this->db->query("UPDATE phpgw_kb_faq "
!                                                       ."SET votes=votes+1, 
total=total+$rating "
!                                                       ."WHERE 
faq_id=$faq_id",__LINE__, __FILE__
!                                                       );
!               }//end set rating
!               
!               function set_question($question, $admin)
!               {
!                       $sql  = 'INSERT INTO phpgw_kb_questions(question, 
pending) ';
!                       $sql .= 'VALUES("' . 
$this->db->db_addslashes($question) .'", ';
!                       $sql .= ($admin ? 0 : 1) .')';
!                       $this->db->query($sql, __LINE__, __FILE__);
!                       if($this->db->get_last_insert_id('phpgw_kb_questions', 
' question_id'))//worked
!                       {
!                               return true;
!                       }
!                       else//must have failed
!                       {
!                               return false;
!                       }//end if worked
!               }//end set question
! 
!               function set_view($faq_id)
!               {
!                       $this->db->query("UPDATE phpgw_kb_faq "
!                                                       ."SET views=views+1 "
!                                                       ."WHERE 
faq_id=$faq_id",__LINE__, __FILE__
!                                                       );
!               }
!               
!       }
! ?>





reply via email to

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