[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - News * 4 * http://www.egroupware.org * 5 * -------------------------------------------- * 6 * This program is free software; you can redistribute it and/or modify it * 7 * under the terms of the GNU General Public License as published by the * 8 * Free Software Foundation; either version 2 of the License, or (at your * 9 * option) any later version. * 10 * -------------------------------------------- * 11 * This program was sponsered by Golden Glair productions * 12 * http://www.goldenglair.com * 13 \**************************************************************************/ 14 15 /* $Id: class.bonews.inc.php 22671 2006-10-18 06:15:59Z ralfbecker $ */ 16 17 class bonews 18 { 19 var $sonews; 20 var $acl; 21 var $start = 0; 22 var $query = ''; 23 var $sort = ''; 24 var $cat_id; 25 var $total = 0; 26 var $debug; 27 var $use_session = False; 28 var $unixtimestampmax; 29 var $dateformat; 30 var $cats = array(); 31 32 function bonews($session=False) 33 { 34 $this->acl =& CreateObject('news_admin.boacl'); 35 $this->sonews =& CreateObject('news_admin.sonews'); 36 $this->accounts = $GLOBALS['egw']->accounts->get_list(); 37 $this->debug = False; 38 if($session) 39 { 40 $this->read_sessiondata(); 41 $this->use_session = True; 42 foreach(array('start','query','sort','order','cat_id') as $var) 43 { 44 $this->$var = get_var($var, array('POST', 'GET'), ''); 45 } 46 47 $this->cat_id = $this->cat_id ? $this->cat_id : 'all'; 48 $this->save_sessiondata(); 49 } 50 $this->catbo =& CreateObject('phpgwapi.categories','','news_admin'); 51 $this->cats = $this->catbo->return_array('all',0,False,'','','cat_name',True); 52 settype($this->cats,'array'); 53 //change this around 19 Jan 2038 03:14:07 GMT 54 $this->unixtimestampmax = 2147483647; 55 $this->dateformat = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; 56 $c =& CreateObject('phpgwapi.config','news_admin'); 57 $c->read_repository(); 58 $this->config = $c->config_data; 59 } 60 61 function save_sessiondata() 62 { 63 $data = array( 64 'start' => $this->start, 65 'query' => $this->query, 66 'sort' => $this->sort, 67 'order' => $this->order, 68 'cat_id' => $this->cat_id, 69 ); 70 if($this->debug) { echo '<br>Save:'; _debug_array($data); } 71 $GLOBALS['egw']->session->appsession('session_data','news_admin',$data); 72 } 73 74 function read_sessiondata() 75 { 76 $data = $GLOBALS['egw']->session->appsession('session_data','news_admin'); 77 if($this->debug) { echo '<br>Read:'; _debug_array($data); } 78 79 $this->start = $data['start']; 80 $this->query = $data['query']; 81 $this->sort = $data['sort']; 82 $this->order = $data['order']; 83 $this->cat_id = $data['cat_id']; 84 } 85 86 function get_newslist($cat_id, $start=0, $order='',$sort='',$limit=0,$activeonly=False) 87 { 88 $charset = $GLOBALS['egw']->translation->charset(); 89 90 $cats = False; 91 if ($cat_id == 'all') 92 { 93 foreach($this->cats as $cat) 94 { 95 if ($this->acl->is_readable($cat['id'])) 96 { 97 $cats[] = $cat['id']; 98 } 99 } 100 } 101 elseif($this->acl->is_readable($cat_id)) 102 { 103 $cats = $cat_id; 104 } 105 106 if($cats) 107 { 108 $news = $this->sonews->get_newslist($cats, $start,$order,$sort,$limit,$activeonly,$this->total); 109 foreach($news as $id => $item) 110 { 111 $news[$id]['content'] = ($item['is_html'] ? 112 $item['content'] : 113 nl2br(@htmlspecialchars($item['content'],ENT_COMPAT,$charset) 114 )); 115 } 116 return $news; 117 } 118 else 119 { 120 return array(); 121 } 122 } 123 124 function get_all_public_news($limit = 5) 125 { 126 $charset = $GLOBALS['egw']->translation->charset(); 127 128 $news = $this->sonews->get_all_public_news($limit); 129 foreach($news as $id => $item) 130 { 131 $news[$id]['content'] = ($item['is_html'] ? 132 $item['content'] : 133 nl2br(@htmlspecialchars($item['content'],ENT_COMPAT,$charset) 134 )); 135 } 136 return $news; 137 } 138 139 function delete($news_id) 140 { 141 $this->sonews->delete($news_id); 142 } 143 144 function add($news) 145 { 146 return $this->acl->is_writeable($news['category']) ? 147 $this->sonews->add($news) : 148 false; 149 } 150 151 function edit($news) 152 { 153 $oldnews = $this->sonews->get_news($news['id']); 154 return ($this->acl->is_writeable($oldnews['category']) && 155 $this->acl->is_writeable($news['category'])) ? 156 $this->sonews->edit($news) : 157 False; 158 } 159 160 function get_visibility(&$news) 161 { 162 $now = time(); 163 164 if ($news['end'] < $now) 165 { 166 return lang('Never'); 167 } 168 else 169 { 170 if ($news['begin'] < $now) 171 { 172 if ($news['end'] == $this->unixtimestampmax) 173 { 174 return lang('Always'); 175 } 176 else 177 { 178 return lang('until') . date($this->dateformat,$news['end']); 179 } 180 } 181 else 182 { 183 if ($news['end'] == $this->unixtimestampmax) 184 { 185 return lang('from') . date($this->dateformat,$news['begin']); 186 187 } 188 else 189 { 190 return lang('from') . ' ' . date($this->dateformat,$news['begin']) . ' ' . 191 lang('until') . ' ' . date($this->dateformat,$news['end']); 192 } 193 } 194 } 195 } 196 197 //return the selectboxes with calculated defaults, and change begin and end by sideaffect 198 function get_options(&$news) 199 { 200 $now = time(); 201 //always is default 202 if (!isset($news['begin'])) 203 { 204 //these are only displayed values not necessarily the ones that will get stored 205 $news['begin'] = $now; 206 $news['end'] = $now; 207 $from = 1; 208 $until = 1; 209 } 210 //if enddate is in the past set option to never 211 elseif ($news['end'] < $now) 212 { 213 $news['begin'] = $now; 214 $news['end'] = $now; 215 $from = 0; 216 $until = 1; 217 } 218 else 219 { 220 if ($news['begin'] < $now) 221 { 222 $news['begin'] = $now; 223 if ($news['end'] == $this->unixtimestampmax) 224 { 225 $news['end'] = $now; 226 $from = 1; 227 $until = 1; 228 } 229 else 230 { 231 $from = 0.5; 232 $until = 0.5; 233 } 234 } 235 else 236 { 237 if ($news['end'] == $this->unixtimestampmax) 238 { 239 $news['end'] = $now; 240 $from = 0.5; 241 $until = 1; 242 } 243 else 244 { 245 $from = 0.5; 246 $until = 0.5; 247 } 248 } 249 } 250 $options['from'] = '<option value="1"' . (($from == 1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>'; 251 $options['from'] .= '<option value="0"' . (($from == 0) ? ' selected="selected"' : '') . '>' . lang('Never') . '</option>'; 252 $options['from'] .= '<option value="0.5"' . (($from == 0.5) ? ' selected="selected"' : '') . '>' . lang('From') . '</option>'; 253 $options['until'] = '<option value="1"' . (($until == 1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>'; 254 $options['until'] .= '<option value="0.5"' . (($until == 0.5) ? ' selected="selected"' : '') . '>' . lang('until') . '</option>'; 255 return $options; 256 } 257 258 //set the begin and end dates 259 function set_dates($from,$until,&$news) 260 { 261 switch($from) 262 { 263 //always 264 case 1: 265 $news['begin'] = $news['date']; 266 $news['end'] = $this->unixtimestampmax; 267 break; 268 //never 269 case 0: 270 $news['begin'] = 0; 271 $news['end'] = 0; 272 break; 273 default: 274 $news['begin'] = mktime(0,0,0,(int)$news['begin_m'], (int)$news['begin_d'], (int)$news['begin_y']); 275 switch($until) 276 { 277 case 1: 278 $news['end'] = $this->unixtimestampmax; 279 break; 280 default: 281 $news['end'] = mktime(0,0,0,(int)$news['end_m'], (int)$news['end_d'], (int)$news['end_y']); 282 } 283 } 284 } 285 286 // function format_fields($fields) 287 // { 288 // $cat =& CreateObject('phpgwapi.categories','news_admin'); 289 290 // $item = array( 291 // 'id' => $fields['id'], 292 // 'date' => $GLOBALS['egw']->common->show_date($fields['date']), 293 // 'subject' => $GLOBALS['egw']->strip_html($fields['subject']), 294 // 'submittedby' => $fields['submittedby'], 295 // 'content' => $fields['content'], 296 // 'status' => lang($fields['status']), 297 // 'cat' => $cat->id2name($fields['cat']) 298 // ); 299 // return $item; 300 // } 301 302 function get_news($news_id) 303 { 304 $news = $this->sonews->get_news($news_id); 305 306 if ($this->acl->is_readable($news['category'])) 307 { 308 $this->total = 1; 309 $news['content'] = ($news['is_html'] ? 310 $news['content']: 311 nl2br(htmlspecialchars($news['content'],ENT_COMPAT,$GLOBALS['egw']->translation->charset()) 312 )); 313 return $news; 314 } 315 else 316 { 317 return False; 318 } 319 } 320 321 // The following functions are added by wbshang @ realss, 2005-2-21 322 323 // Get addressbook categories that have received mails 324 function get_receiver_cats($news_id) 325 { 326 if(!$news_id) 327 { 328 return array(); 329 } 330 return ($cat_id = $this->sonews->get_receiver_cats($news_id)) ? explode(",", $cat_id) : array(); 331 } 332 333 // Send mail to $news['mailto'] with the content of $news 334 function send_mail($news) 335 { 336 // first, get all members who are gonna to receive this mail 337 if(!is_object($GLOBALS['egw']->contacts)) 338 { 339 $GLOBALS['egw']->contacts =& CreateObject('phpgwapi.contacts'); 340 } 341 $fields = array( 342 'n_family' => True, 343 'n_given' => True, 344 'email' => True, 345 'email_home' => True, 346 // 'cat_id' => True 347 ); 348 $members = array(); 349 foreach($news['mailto'] as $cat_id) 350 { 351 $filter = 'tid=n,cat_id=' . $cat_id; 352 $members = array_merge($members,$GLOBALS['egw']->contacts->read('','',$fields,'',$filter)); 353 } 354 355 // then, prepare to send mail 356 $mail =& CreateObject('phpgwapi.send'); 357 358 // build subject 359 $subject = lang('News') . ': ' . $news['subject']; 360 361 // build body 362 $body = ''; 363 $body .= lang('URL') . ": http://" . $GLOBALS['egw_info']['server']['hostname'] . "<br/>"; 364 $body .= lang('Subject') . ': ' . $news['subject'] . "<br/>"; 365 $body .= lang('Submitted By') . ': ' . $GLOBALS['egw']->common->grab_owner_name($news['submittedby']) . "<br/>"; 366 $body .= lang('Date') . ': ' . $GLOBALS['egw']->common->show_date($news['date']) . "<br/><br/>"; 367 $body .= lang('Content') . ":<br/>"; 368 369 $body .= $news['content'] . "<br/><br/>"; 370 371 $tempdata = explode ( "," , $GLOBALS['egw']->common->grab_owner_name($news['submittedby'])); 372 $tempfromname = ""; 373 foreach($tempdata as $tempname) 374 { 375 $tempfromname .= ' ' . $tempname; 376 } 377 $mail->Subject = $subject; 378 $mail->Body = $body; 379 $mail->From = $GLOBALS['egw_info']['user']['preferences']['news_admin']['EmailFrom']; 380 $mail->FromName = $tempfromname; 381 $replyto = $GLOBALS['egw_info']['user']['preferences']['news_admin']['EmailReplyto']; 382 $mail->AddReplyTo($replyto); 383 $mail->Sender = $replyto; // the Return-Path 384 $mail->IsHTML(true); 385 /* attach files, no use now 386 if(!empty($news['fileadded'])) 387 { 388 foreach($news['fileadded'] as $file) 389 { 390 $p = $this->vfs->path_parts(array( 391 'string' => '/news_admin/'.$news['id'].'/'.$file['name'], 392 'relatives' => array( 393 RELATIVE_NONE) 394 )); 395 $mail->AddAttachment($p->real_full_path,$file['name'],'base64',$file['type']); 396 } // it seems that the sumsize of attachments is limited 397 } */ 398 399 foreach($members as $member) 400 { 401 if($sent[$member['id']]) 402 { 403 continue; 404 } 405 $sent[$member['id']] = True; 406 if($GLOBALS['egw_info']['user']['preferences']['news_admin']['SendtohomeEmail']) /* send to the home_email if business_email is empty */ 407 { 408 $to = strpos($member['email'],'@') ? $member['email'] : $member['email_home']; 409 } 410 else 411 { 412 $to = $member['email']; 413 } 414 if(!strpos($to,'@')) 415 { 416 continue; // no email address available, just skip it 417 } 418 $toname = $member['n_given'] . ' ' . $member['n_family']; 419 420 $mail->ClearAddresses(); 421 $mail->AddAddress($to,$toname); 422 423 if (!$mail->Send()) 424 { 425 $errors[] = "Error sending mail to $toname <$to>"; 426 // echo $mail->ErrorInfo; 427 } 428 } 429 if(is_array($errors)) 430 { 431 return $errors; 432 } 433 } 434 } 435 ?>
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 |