[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare SiteMgr - Web Content Management * 4 * http://www.egroupware.org * 5 * SQL reworked by RalfBecker@outdoor-training.de to get everything quoted * 6 * -------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: class.Categories_SO.inc.php 20295 2006-02-15 12:31:25Z $ */ 14 15 class Categories_SO 16 { 17 var $cats; 18 var $db; 19 var $site_id; 20 21 function Categories_SO() 22 { 23 $this->cats =& CreateObject('phpgwapi.categories',-1,'sitemgr'); 24 $this->db = clone($GLOBALS['egw']->db); 25 $this->db->set_app('sitemgr'); 26 $this->state_table = 'egw_sitemgr_categories_state'; 27 $this->lang_table = 'egw_sitemgr_categories_lang'; 28 } 29 30 function isactive($cat_id,$states=false) 31 { 32 if (!$states) 33 { 34 $states = $GLOBALS['Common_BO']->visiblestates; 35 } 36 $this->db->select($this->state_table,'cat_id',array( 37 'cat_id' => $cat_id, 38 'state' => $states, 39 ),__LINE__,__FILE__); 40 41 return $this->db->num_rows(); 42 } 43 44 function getChildrenIDList($parent) 45 { 46 // we need to sort after our sort-order in the cat-data-column as integer (!) not char 47 $order_by = 'cat_data'; 48 switch($this->db->Type) 49 { 50 case 'sapdb': case 'maxdb': 51 break; // cant cast text/LONG to int 52 case 'mysql': 53 // cast is mysql 4 only and has differnt types, eg. CAST(cat_data AS signed) 54 $order_by = "round($order_by)"; 55 break; 56 case 'mssql': 57 // mssql cant cast direct from text to int 58 $order_by = "CAST($order_by AS varchar)"; 59 // fall through 60 default: 61 $order_by = "CAST($order_by AS integer)"; 62 break; 63 } 64 $cats = $this->cats->return_array('all','',False,'','',$order_by,False,$parent,-1,'id'); 65 $result = array(); 66 67 while (list(,$subs) = @each($cats)) 68 { 69 $result[] = $subs['id']; 70 } 71 return $result; 72 } 73 74 function addCategory($name, $description, $parent = False) 75 { 76 $cat_id = (int) $this->cats->add(array( 77 'name' => $name, 78 'descr' => $description, 79 'access' => 'public', 80 'parent' => $parent, 81 'old_parent' => $parent 82 )); 83 $this->db->insert($this->state_table,array('cat_id'=>$cat_id),False, __LINE__,__FILE__); 84 85 return $cat_id; 86 } 87 88 function removeCategory($cat_id) 89 { 90 $this->cats->delete($cat_id,False,True); 91 92 $this->db->delete($this->lang_table,array('cat_id'=>$cat_id),__LINE__,__FILE__); 93 $this->db->delete($this->state_table,array('cat_id'=>$cat_id),__LINE__,__FILE__); 94 95 return True; 96 } 97 98 function saveCategory($cat_info) 99 { 100 $data = array 101 ( 102 'name' => $cat_info->name, 103 'descr' => $cat_info->description, 104 'data' => sprintf('%04d',$cat_info->sort_order), 105 'access' => 'public', 106 'id' => (int) $cat_info->id, 107 'parent' => (int) $cat_info->parent, 108 'old_parent' => (int) $cat_info->old_parent, 109 ); 110 $this->cats->edit($data); 111 112 return $this->db->update($this->state_table,array( 113 'state' => $cat_info->state, 114 'index_page_id' => $cat_info->index_page_id, 115 ),array('cat_id'=>$cat_info->id),__LINE__,__FILE__); 116 } 117 118 function saveCategoryLang($cat_id, $cat_name, $cat_description, $lang) 119 { 120 return $this->db->insert($this->lang_table,array( 121 'name' => $cat_name, 122 'description' => $cat_description, 123 ),array( 124 'cat_id' => $cat_id, 125 'lang' => $lang, 126 ),__LINE__,__FILE__); 127 } 128 129 function getlangarrayforcategory($cat_id) 130 { 131 $retval = array(); 132 $this->db->select($this->lang_table,'lang',array('cat_id'=>$cat_id),__LINE__,__FILE__); 133 while ($this->db->next_record()) 134 { 135 $retval[] = $this->db->f('lang'); 136 } 137 return $retval; 138 } 139 140 function getCategory($cat_id,$lang=False) 141 { 142 list($cat) = $this->cats->return_single($cat_id); 143 144 if (is_array($cat)) 145 { 146 $cat_info =& CreateObject('sitemgr.Category_SO', True); 147 $cat_info->id = $cat['id']; 148 $cat_info->sort_order = (int) $cat['data']; 149 $cat_info->parent = $cat['parent']; 150 $cat_info->depth = $cat['level']; 151 $cat_info->root = $cat['main']; 152 153 $this->db->select($this->state_table,array('state','index_page_id'),array('cat_id'=>$cat_id),__LINE__,__FILE__); 154 if ($this->db->next_record()) 155 { 156 $cat_info->state = $this->db->f('state'); 157 $cat_info->index_page_id = (int) $this->db->f('index_page_id'); 158 } 159 if ($lang) 160 { 161 $this->db->select($this->lang_table,'*',array( 162 'cat_id' => $cat_id, 163 'lang' => $lang, 164 ),__LINE__,__FILE__); 165 if ($this->db->next_record()) 166 { 167 $cat_info->name = stripslashes($this->db->f('name')); 168 $cat_info->description = stripslashes($this->db->f('description')); 169 } 170 } 171 else //if there is no lang argument we return the content in whatever languages turns up first 172 { 173 $this->db->select($this->lang_table,'*',array('cat_id' => $cat_id,),__LINE__,__FILE__); 174 if ($this->db->next_record()) 175 { 176 $cat_info->name = stripslashes($this->db->f('name')); 177 $cat_info->description = stripslashes($this->db->f('description')); 178 $cat_info->lang = $this->db->f('lang'); 179 } 180 else 181 { 182 $cat_info->name = "This category has no data in any langugage: this should not happen"; 183 } 184 } 185 return $cat_info; 186 } 187 return False; 188 } 189 190 function removealllang($lang) 191 { 192 $this->db->delete($this->lang_table,array('lang'=>$lang), __LINE__,__FILE__); 193 } 194 195 function migratealllang($oldlang,$newlang) 196 { 197 $this->db->update($this->lang_table,array('lang'=>$newlang),array('lang'=>$old_lang), __LINE__,__FILE__); 198 } 199 200 function commit($cat_id) 201 { 202 $this->db->update($this->state_table,array('state'=>SITEMGR_STATE_PUBLISH),array('state'=>SITEMGR_STATE_PREPUBLISH), __LINE__,__FILE__); 203 $this->db->update($this->state_table,array('state'=>SITEMGR_STATE_ARCHIVE),array('state'=>SITEMGR_STATE_PREUNPUBLISH), __LINE__,__FILE__); 204 } 205 206 function reactivate($cat_id) 207 { 208 $this->db->update($this->state_table,array('state'=>SITEMGR_STATE_DRAFT),array('state'=>SITEMGR_STATE_ARCHIVE), __LINE__,__FILE__); 209 } 210 } 211 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |