[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /***************************************************************************\ 3 * eGroupWare - FeLaMiMail * 4 * http://www.linux-at-work.de * 5 * http://www.phpgw.de * 6 * http://www.egroupware.org * 7 * Written by : Lars Kneschke [lkneschke@linux-at-work.de] * 8 * ------------------------------------------------- * 9 * This program is free software; you can redistribute it and/or modify it * 10 * under the terms of the GNU General Public License as published by the * 11 * Free Software Foundation; either version 2 of the License, or (at your * 12 * option) any later version. * 13 \***************************************************************************/ 14 15 /* $Id: class.ajaxfelamimail.inc.php 21375 2006-04-16 07:07:00Z ralfbecker $ */ 16 17 class ajaxfelamimail 18 { 19 function ajaxfelamimail() 20 { 21 $this->bofelamimail =& CreateObject('felamimail.bofelamimail',$GLOBALS['egw']->translation->charset()); 22 $this->uiwidgets =& CreateObject('felamimail.uiwidgets'); 23 $this->bofelamimail->openConnection(); 24 25 $this->sessionDataAjax = $GLOBALS['egw']->session->appsession('ajax_session_data'); 26 $this->sessionData = $GLOBALS['egw']->session->appsession('session_data'); 27 28 if(!isset($this->sessionDataAjax['folderName'])) 29 $this->sessionDataAjax['folderName'] = 'INBOX'; 30 31 $this->bofelamimail->openConnection($this->sessionDataAjax['folderName']); 32 } 33 34 function addACL($_accountName, $_aclData) 35 { 36 if(!empty($_accountName)) 37 { 38 $acl = implode('',(array)$_aclData['acl']); 39 $data = $this->bofelamimail->addACL($this->sessionDataAjax['folderName'], $_accountName, $acl); 40 #$response =& new xajaxResponse(); 41 #$response->addScript("window.close();"); 42 #$response->addAssign("accountName", "value", $this->sessionDataAjax['folderName'].'-'.$_accountName.'-'.$acl); 43 #return $response->getXML(); 44 } 45 } 46 47 function addFolder($_parentFolder, $_newSubFolder) 48 { 49 $folderData = $this->bofelamimail->getFolderStatus('INBOX'); 50 $folderName = ($_parentFolder == '--topfolder--'?$_newSubFolder:$_parentFolder.$folderData['delimiter'].$_newSubFolder); 51 $response =& new xajaxResponse(); 52 if($this->bofelamimail->imap_createmailbox($folderName)) 53 { 54 $response->addScript("tree.insertNewItem('$_parentFolder','$folderName','$_newSubFolder',onNodeSelect,'folderClosed.gif',0,0,'CHILD,CHECKED,SELECT,CALL');"); 55 $response->addScript("tree.setCheck('$folderName','0');"); 56 $response->addAssign("newSubFolder", "value", ''); 57 } 58 else 59 { 60 $response->addScript("alert('".addslashes(lang("Could not add folder %1 (%2) !!!",$folderName,imap_last_error()))."');"); 61 } 62 return $response->getXML(); 63 } 64 65 function changeSorting($_sortBy) 66 { 67 $this->sessionData['startMessage'] = 1; 68 69 switch($_sortBy) 70 { 71 case 'date': 72 $this->sessionData['sort'] = ($this->sessionData['sort'] == 0?1:0); 73 break; 74 case 'from': 75 $this->sessionData['sort'] = ($this->sessionData['sort'] == 3?2:3); 76 break; 77 case 'size': 78 $this->sessionData['sort'] = ($this->sessionData['sort'] == 6?7:6); 79 break; 80 case 'subject': 81 $this->sessionData['sort'] = ($this->sessionData['sort'] == 5?4:5); 82 break; 83 } 84 85 $this->saveSessionData(); 86 87 return $this->generateMessageList($this->sessionData['mailbox']); 88 } 89 90 function compressFolder() 91 { 92 $this->bofelamimail->restoreSessionData(); 93 $this->bofelamimail->reopen($this->sessionData['mailbox']); 94 $this->bofelamimail->compressFolder(); 95 96 $bofilter =& CreateObject('felamimail.bofilter'); 97 $caching =& CreateObject('felamimail.bocaching', 98 $this->bofelamimail->mailPreferences['imapServerAddress'], 99 $this->bofelamimail->mailPreferences['username'], 100 $this->sessionData['mailbox']); 101 102 $messageCounter = $caching->getMessageCounter($bofilter->getFilter($this->sessionData['activeFilter'])); 103 104 // $lastPage is the first message ID of the last page 105 if($messageCounter > $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]) 106 { 107 $lastPage = $messageCounter - ($messageCounter % $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]) + 1; 108 if($lastPage > $messageCounter) 109 $lastPage -= $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]; 110 if($this->sessionData['startMessage'] > $lastPage) 111 $this->sessionData['startMessage'] = $lastPage; 112 } 113 else 114 { 115 $this->sessionData['startMessage'] = 1; 116 } 117 118 $this->saveSessionData(); 119 120 return $this->generateMessageList($this->sessionData['mailbox']); 121 } 122 123 function createACLTable($_acl) 124 { 125 $aclList = array('l','r','s','w','i','p','c','d','a'); 126 127 ksort($_acl); 128 129 foreach($_acl as $accountName => $accountAcl) 130 { 131 $row .= '<tr class="row_on">'; 132 133 $row .= "<td><input type=\"checkbox\" name=\"accountName[]\" id=\"accountName\" value=\"$accountName\"></td>"; 134 135 $row .= "<td>$accountName</td>"; 136 137 foreach($aclList as $acl) 138 { 139 $row .= "<td><input type=\"checkbox\" name=\"acl[$accountName][$acl]\" id=\"acl_$accountName_$acl\"". 140 (strpos($accountAcl,$acl) !== false ? 'checked' : '') . 141 " onclick=\"xajax_doXMLHTTP('felamimail.ajaxfelamimail.updateSingleACL','$accountName','$acl',this.checked)\"</td>"; 142 } 143 144 $row .= "</tr>"; 145 } 146 147 return "<table border=\"0\"><tr class=\"th\"><th> </th><th style=\"width:100px;\">Name</th><th>L</th><th>R</th><th>S</th><th>W</th><th>I</th><th>P</th><th>C</th><th>D</th><th>A</th></tr>$row</table>"; 148 } 149 150 function deleteACL($_aclData) 151 { 152 if(is_array($_aclData)) 153 { 154 foreach($_aclData['accountName'] as $accountName) 155 { 156 $data = $this->bofelamimail->addACL($this->sessionDataAjax['folderName'], $accountName, ''); 157 } 158 159 $folderACL = $this->bofelamimail->getIMAPACL($this->sessionDataAjax['folderName']); 160 161 $response =& new xajaxResponse(); 162 $response->addAssign("aclTable", "innerHTML", $this->createACLTable($folderACL)); 163 return $response->getXML(); 164 } 165 } 166 167 function deleteFolder($_folderName) 168 { 169 if($_folderName == 'INBOX' || $_folderName == '--topfolder--') 170 return false; 171 172 // we need to select a different fold first, as Courier wont delete the open folder 173 $this->bofelamimail->openConnection($this->sessionDataAjax['folderName']='INBOX'); 174 $this->saveSessionData(); 175 176 $response =& new xajaxResponse(); 177 if($this->bofelamimail->imap_deletemailbox($_folderName)) 178 { 179 $response->addScript("tree.deleteItem('$_folderName',1);"); 180 } 181 else 182 { 183 $response->addScript("alert('".addslashes(lang("Could not delete folder %1 (%2) !!!",$_folderName,imap_last_error()))."');"); 184 } 185 return $response->getXML(); 186 } 187 188 function deleteMessages($_messageList) 189 { 190 $this->bofelamimail->deleteMessages($_messageList['msg']); 191 192 return $this->generateMessageList($this->sessionData['mailbox']); 193 } 194 195 function emptyTrash() 196 { 197 $preferences = ExecMethod('felamimail.bopreferences.getPreferences'); 198 199 if(!empty($preferences['trash_folder'])) 200 { 201 $this->bofelamimail->closeConnection(); 202 $this->bofelamimail->openConnection($preferences['trash_folder']); 203 $this->bofelamimail->compressFolder($preferences['trash_folder']); 204 } 205 206 return $this->generateMessageList($this->sessionData['mailbox']); 207 } 208 209 function extendedSearch($_filterID) 210 { 211 // start displaying at message 1 212 $this->sessionData['startMessage'] = 1; 213 $this->sessionData['activeFilter'] = (int)$_filterID; 214 $this->saveSessionData(); 215 216 // generate the new messageview 217 return $this->generateMessageList($this->sessionData['mailbox']); 218 } 219 220 function flagMessages($_flag, $_messageList) 221 { 222 $this->bofelamimail->flagMessages($_flag, $_messageList['msg']); 223 224 return $this->generateMessageList($this->sessionData['mailbox']); 225 } 226 227 function generateMessageList($_folderName) 228 { 229 $this->bofelamimail->restoreSessionData(); 230 231 $isSentFolder = $this->bofelamimail->isSentFolder($_folderName); 232 233 $maxMessages = $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]; 234 $headers = $this->bofelamimail->getHeaders($this->sessionData['startMessage'], $maxMessages, $this->sessionData['sort']); 235 236 $headerTable = $this->uiwidgets->messageTable($headers, $isSentFolder, $GLOBALS['egw_info']['user']['preferences']['felamimail']['message_newwindow']); 237 238 $response =& new xajaxResponse(); 239 $firstMessage = (int)$headers['info']['first']; 240 $lastMessage = (int)$headers['info']['last']; 241 $totalMessage = (int)$headers['info']['total']; 242 if($totalMessage == 0) 243 $response->addAssign("messageCounter", "innerHTML", lang('no messages found...')); 244 else 245 $response->addAssign("messageCounter", "innerHTML", lang('Viewing messages')." <b>$firstMessage</b> - <b>$lastMessage</b> ($totalMessage ".lang("total").')'); 246 if($isSentFolder) 247 { 248 $response->addAssign("from_or_to", "innerHTML", lang('to')); 249 } 250 else 251 { 252 $response->addAssign("from_or_to", "innerHTML", lang('from')); 253 } 254 255 $response->addAssign("divMessageList", "innerHTML", $headerTable); 256 257 $response->addScript("tree.selectItem('".$_folderName."',false);"); 258 259 return $response->getXML(); 260 } 261 262 function getFolderInfo($_folderName) 263 { 264 #$response =& new xajaxResponse(); 265 #$response->addAssign("folderName", "innerHTML", 'Name: '.$folderName); 266 #return $response->getXML(); 267 if($_folderName != '--topfolder--' && $folderStatus = $this->bofelamimail->getFolderStatus($_folderName)) 268 { 269 $response =& new xajaxResponse(); 270 271 if($this->sessionDataAjax['oldFolderName'] == '--topfolder--') 272 { 273 $this->sessionDataAjax['oldFolderName'] = ''; 274 $response->addScript("document.getElementById('newMailboxName').disabled = false;"); 275 $response->addScript("document.getElementById('mailboxRenameButton').disabled = false;"); 276 } 277 $this->sessionDataAjax['folderName'] = $_folderName; 278 $this->saveSessionData(); 279 280 $folderACL = $this->bofelamimail->getIMAPACL($_folderName); 281 282 $response->addAssign("newMailboxName", "value", $folderStatus['shortName']); 283 $response->addAssign("folderName", "innerHTML", $_folderName); 284 $response->addAssign("aclTable", "innerHTML", $this->createACLTable($folderACL)); 285 286 return $response->getXML(); 287 } 288 else 289 { 290 $this->sessionDataAjax['oldFolderName'] = $_folderName; 291 $this->saveSessionData(); 292 293 $response =& new xajaxResponse(); 294 $response->addAssign("newMailboxName", "value", ''); 295 $response->addAssign("folderName", "innerHTML", ''); 296 $response->addScript("document.getElementById('newMailboxName').disabled = true;"); 297 $response->addScript("document.getElementById('mailboxRenameButton').disabled = true;"); 298 $response->addAssign("aclTable", "innerHTML", ''); 299 return $response->getXML(); 300 } 301 } 302 303 function gotoStart() 304 { 305 $this->sessionData['startMessage'] = 1; 306 $this->saveSessionData(); 307 308 return $this->generateMessageList($this->sessionData['mailbox']); 309 } 310 311 function jumpEnd() 312 { 313 $bofilter =& CreateObject('felamimail.bofilter'); 314 $caching =& CreateObject('felamimail.bocaching', 315 $this->bofelamimail->mailPreferences['imapServerAddress'], 316 $this->bofelamimail->mailPreferences['username'], 317 $this->sessionData['mailbox']); 318 319 $messageCounter = $caching->getMessageCounter($bofilter->getFilter($this->sessionData['activeFilter'])); 320 321 $lastPage = $messageCounter - ($messageCounter % $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]) + 1; 322 if($lastPage > $messageCounter) 323 $lastPage -= $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]; 324 325 $this->sessionData['startMessage'] = $lastPage; 326 327 $this->saveSessionData(); 328 329 return $this->generateMessageList($this->sessionData['mailbox']); 330 } 331 332 function jumpStart() 333 { 334 $this->sessionData['startMessage'] = 1; 335 $this->saveSessionData(); 336 337 return $this->generateMessageList($this->sessionData['mailbox']); 338 } 339 340 function moveMessages($_folder, $_selectedMessages) 341 { 342 $this->bofelamimail->moveMessages($_folder, $_selectedMessages['msg']); 343 344 return $this->generateMessageList($this->sessionData['mailbox']); 345 346 } 347 348 function quickSearch($_searchString) 349 { 350 // save the filter 351 $bofilter =& CreateObject('felamimail.bofilter'); 352 353 $filter['filterName'] = lang('Quicksearch'); 354 $filter['from'] = $_searchString; 355 $filter['subject'] = $_searchString; 356 357 $bofilter->saveFilter($filter,0); 358 359 // start displaying at message 1 360 $this->sessionData['startMessage'] = 1; 361 if($_searchString != '') 362 $this->sessionData['activeFilter'] = 0; 363 else 364 $this->sessionData['activeFilter'] = -1; 365 366 #$response =& new xajaxResponse(); 367 #$response->addScript("document.getElementById('quickSearch').select();"); 368 #return $response->getXML(); 369 $this->saveSessionData(); 370 371 // generate the new messageview 372 return $this->generateMessageList($this->sessionData['mailbox']); 373 } 374 375 function refreshMessageList() 376 { 377 return $this->generateMessageList($this->sessionData['mailbox']); 378 } 379 380 function renameFolder($_oldName, $_newParent, $_newName) 381 { 382 $newName = $_newParent.'.'.$_newName; 383 384 // we need to select a different fold first, as Courier wont delete the open folder 385 $this->bofelamimail->openConnection($this->sessionDataAjax['folderName']='INBOX'); 386 387 $response =& new xajaxResponse(); 388 if($this->bofelamimail->imap_renamemailbox($_oldName, $newName)) 389 { 390 $this->sessionDataAjax['folderName']=$newName; 391 $this->saveSessionData(); 392 393 $response->addScript("tree.deleteItem('$_oldName',0);"); 394 $response->addScript("tree.insertNewItem('$_newParent','$newName','$_newName',onNodeSelect,'folderClosed.gif',0,0,'CHILD,CHECKED,SELECT,CALL');"); 395 } 396 else 397 { 398 $response->addScript("alert('".addslashes(lang("Could not rename folder %1 to %2 (%3) !!!",$_oldName,$newName,imap_last_error()))."');"); 399 } 400 return $response->getXML(); 401 } 402 403 function saveSessionData() 404 { 405 $GLOBALS['egw']->session->appsession('ajax_session_data','',$this->sessionDataAjax); 406 $GLOBALS['egw']->session->appsession('session_data','',$this->sessionData); 407 } 408 409 function skipForward() 410 { 411 $bofilter =& CreateObject('felamimail.bofilter'); 412 $caching =& CreateObject('felamimail.bocaching', 413 $this->bofelamimail->mailPreferences['imapServerAddress'], 414 $this->bofelamimail->mailPreferences['username'], 415 $this->sessionData['mailbox']); 416 417 $messageCounter = $caching->getMessageCounter($bofilter->getFilter($this->sessionData['activeFilter'])); 418 // $lastPage is the first message ID of the last page 419 if($messageCounter > $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]) 420 { 421 $lastPage = $messageCounter - ($messageCounter % $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]) + 1; 422 if($lastPage > $messageCounter) 423 $lastPage -= $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]; 424 $this->sessionData['startMessage'] += $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]; 425 if($this->sessionData['startMessage'] > $lastPage) 426 $this->sessionData['startMessage'] = $lastPage; 427 } 428 else 429 { 430 $this->sessionData['startMessage'] = 1; 431 } 432 433 $this->saveSessionData(); 434 435 $response = $this->generateMessageList($this->sessionData['mailbox']); 436 437 return $response; 438 } 439 440 function skipPrevious() 441 { 442 $this->sessionData['startMessage'] -= $GLOBALS['egw_info']["user"]["preferences"]["common"]["maxmatchs"]; 443 if($this->sessionData['startMessage'] < 1) 444 $this->sessionData['startMessage'] = 1; 445 $this->saveSessionData(); 446 447 return $this->generateMessageList($this->sessionData['mailbox']); 448 } 449 450 function updateACLView() 451 { 452 $folderACL = $this->bofelamimail->getIMAPACL($this->sessionDataAjax['folderName']); 453 454 $response =& new xajaxResponse(); 455 $response->addAssign("aclTable", "innerHTML", $this->createACLTable($folderACL)); 456 return $response->getXML(); 457 } 458 459 function updateFolderStatus($_folderName, $_status) 460 { 461 $this->bofelamimail->subscribe($_folderName,($_status == '1' ? 'subscribe' : 'unsubscribe')); 462 #$this->deleteFolder('--topfolder--.xxx.yyy'); 463 #$response =& new xajaxResponse(); 464 #$response->addAssign("folderName", "innerHTML", $_folderName.$_status); 465 #return $response->getXML(); 466 467 #return($this->getFolderInfo($folderName)); 468 } 469 470 function updateMessageView($_folderName) 471 { 472 $this->sessionData['mailbox'] = $_folderName; 473 $this->sessionData['startMessage'] = 1; 474 $this->saveSessionData(); 475 476 return $this->generateMessageList($_folderName); 477 } 478 479 function updateSingleACL($_accountName, $_aclType, $_aclStatus) 480 { 481 $data = $this->bofelamimail->updateSingleACL($this->sessionDataAjax['folderName'], $_accountName, $_aclType, $_aclStatus); 482 #$response =& new xajaxResponse(); 483 #$response->addAssign("newMailboxName", "value", $_accountName.' '.$_aclType.' '.$_aclStatus.' '.$data); 484 #return $response->getXML(); 485 } 486 487 function xajaxFolderInfo($_formValues) 488 { 489 $response =& new xajaxResponse(); 490 $response->addAssign("field1", "value", $_formValues['num1']); 491 $response->addAssign("field2", "value", $_formValues['num2']); 492 $response->addAssign("field3", "value", $_formValues['num1'] * $_formValues['num2']); 493 494 return $response->getXML(); 495 } 496 } 497 ?>
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 |