[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/addressbook/inc/ -> class.boaddressbook.inc.php (source)

   1  <?php
   2    /**************************************************************************\
   3    * eGroupWare - Addressbook                                                 *
   4    * http://www.egroupware.org                                                *
   5    * Written by Joseph Engo <jengo@phpgroupware.org                           *
   6    *  and Miles Lott <milos@groupwhere.org>                                   *
   7    * --------------------------------------------                             *
   8    *  This program is free software; you can redistribute it and/or modify it *
   9    *  under the terms of the GNU General Public License as published by the   *
  10    *  Free Software Foundation; either version 2 of the License, or (at your  *
  11    *  option) any later version.                                              *
  12    \**************************************************************************/
  13  
  14    /* $Id: class.boaddressbook.inc.php 22506 2006-09-27 04:16:09Z ralfbecker $ */
  15  
  16      class boaddressbook
  17      {
  18          var $public_functions = array(
  19              'read_entries'    => True,
  20              'read_entry'      => True,
  21              'read_last_entry' => True,
  22              'add_entry'       => True,
  23              'add_vcard'       => True,
  24              'add_email'       => True,
  25              'update_entry'    => True,
  26              'delete_entry'    => True
  27          );
  28  
  29          var $xml_functions  = array();
  30          var $xmlrpc_methods = array();
  31          var $soap_functions = array(
  32              'read_entries' => array(
  33                  'in'  => array('int','int','struct','string','int'),
  34                  'out' => array('array')
  35              ),
  36              'read_entry' => array(
  37                  'in'  => array('int','struct'),
  38                  'out' => array('array')
  39              ),
  40              'read_last_entry' => array(
  41                  'in'  => array('struct'),
  42                  'out' => array('array')
  43              ),
  44              'add_entry' => array(
  45                  'in'  => array('int','struct'),
  46                  'out' => array()
  47              ),
  48              'update_entry' => array(
  49                  'in'  => array('int','struct'),
  50                  'out' => array()
  51              ),
  52              'categories' => array(
  53                  'in'  => array('bool'),
  54                  'out' => array('struct')
  55              ),
  56              'customfields' => array(
  57                  'in' => array('array'),
  58                  'out'=> array('struct')
  59              )
  60          );
  61  
  62          var $debug = False;
  63  
  64          var $so;
  65          var $start;
  66          var $limit;
  67          var $query;
  68          var $sort;
  69          var $order;
  70          var $filter;
  71          var $cat_id;
  72          var $total;
  73          var $contact_cache = array();
  74  
  75          var $use_session = False;
  76  
  77  		function boaddressbook($session=False)
  78          {
  79              $this->so = CreateObject('addressbook.soaddressbook');
  80              // make some fields of the contacts-object availible
  81              $this->grants = &$this->so->grants;
  82              $this->stock_contact_fields = &$this->so->contacts->stock_contact_fields;
  83              $this->tel_types = &$this->so->contacts->tel_types;
  84              $this->email_types = &$this->so->contacts->email_types;
  85              $this->adr_types = &$this->so->contacts->adr_types;
  86  
  87              if($session)
  88              {
  89                  $this->read_sessiondata();
  90                  $this->use_session = True;
  91              }
  92              // are we called via xmlrpc?
  93              $this->xmlrpc = is_object($GLOBALS['server']) && $GLOBALS['server']->last_method;
  94  
  95              /* _debug_array($_POST); */
  96              $_start   = get_var('start',array('POST','GET'));
  97              $_query   = get_var('query',array('POST','GET'),'_UNSET_');
  98              $_cquery  = get_var('cquery', array('GET','POST'),'_UNSET_');
  99              $_sort    = get_var('sort',array('POST','GET'));
 100              $_order   = get_var('order',array('POST','GET'));
 101              $_filter  = get_var('filter',array('POST','GET'));
 102  //            $_cat_id  = get_var('cat_id',array('POST','GET'));
 103              $_fcat_id = get_var('fcat_id',array('POST','GET'));
 104              $_typeid  = get_var('typeid',array('POST','GET'),'_UNSET_');
 105  
 106              if(!empty($_start) || ($_start === '0') || ($_start === 0))
 107              {
 108                  if($this->debug) { echo '<br>overriding $start: "' . $this->start . '" now "' . $_start . '"'; }
 109                  $this->start = $_start;
 110              }
 111              if($_limit)
 112              {
 113                  $this->limit  = $_limit;
 114              }
 115  
 116              if($_query != '_UNSET_')
 117              {
 118                  $this->query = $_query;
 119              }
 120              if($_cquery != '_UNSET_')
 121              {
 122                  $this->cquery = $_cquery;
 123              }
 124  
 125              if($_typeid != '_UNSET_')
 126              {
 127                  $this->typeid = $_typeid;
 128              }
 129              if(!@in_array($this->typeid,array('n','c')))
 130              {
 131                  $this->typeid = 'n';
 132              }
 133  
 134              if(isset($_POST['fcat_id']) || isset($_POST['fcat_id']))
 135              {
 136                   // reset start if category changes
 137                  if($this->cat_id != $_fcat_id) { $this->start = 0; }
 138                  
 139                  $this->cat_id = $_fcat_id;
 140              }
 141              elseif(empty($this->cat_id))
 142              {
 143                  $this->cat_id = -1;
 144              }
 145              
 146              /*
 147              if(isset($_POST['typeid']) || isset($_POST['typeid']))
 148              {
 149                  $this->typeid = $typeid;
 150              }
 151              else
 152              {
 153                  $this->typeid = 'n';
 154              }
 155              */
 156  
 157              if(isset($_sort)   && !empty($_sort))
 158              {
 159                  if($this->debug) { echo '<br>overriding $sort: "' . $this->sort . '" now "' . $_sort . '"'; }
 160                  $this->sort   = $_sort;
 161              }
 162  
 163              if(isset($_order)  && !empty($_order))
 164              {
 165                  if($this->debug) { echo '<br>overriding $order: "' . $this->order . '" now "' . $_order . '"'; }
 166                  $this->order  = $_order;
 167              }
 168  
 169              if(isset($_filter) && !empty($_filter))
 170              {
 171                  if($this->debug) { echo '<br>overriding $filter: "' . $this->filter . '" now "' . $_filter . '"'; }
 172                  $this->filter = $_filter;
 173              }
 174  
 175              if($this->debug) { $this->_debug_sqsof(); }
 176          }
 177  
 178  		function _debug_sqsof()
 179          {
 180              $data = array(
 181                  'start'  => $this->start,
 182                  'limit'  => $this->limit,
 183                  'query'  => $this->query,
 184                  'cquery' => $this->cquery,
 185                  'sort'   => $this->sort,
 186                  'order'  => $this->order,
 187                  'filter' => $this->filter,
 188                  'cat_id' => $this->cat_id,
 189                  'typeid' => $this->typeid
 190              );
 191              echo '<br>BO:';
 192              _debug_array($data);
 193          }
 194  
 195  		function save_sessiondata($data)
 196          {
 197              if($this->use_session)
 198              {
 199                  if($this->debug) { echo '<br>Save:'; _debug_array($data); }
 200                  $GLOBALS['egw']->session->appsession('session_data','addressbook',$data);
 201              }
 202          }
 203  
 204  		function read_sessiondata()
 205          {
 206              $data = $GLOBALS['egw']->session->appsession('session_data','addressbook');
 207              if($this->debug) { echo '<br>Read:'; _debug_array($data); }
 208  
 209              $this->start  = $data['start'];
 210              $this->limit  = $data['limit'];
 211              $this->query  = $data['query'];
 212              $this->cquery = $data['cquery'];
 213              $this->sort   = $data['sort'];
 214              $this->order  = $data['order'];
 215              $this->filter = $data['filter'];
 216              $this->cat_id = $data['cat_id'];
 217              $this->typeid = $data['typeid'];
 218              if($this->debug) { echo '<br>read_sessiondata();'; $this->_debug_sqsof(); }
 219          }
 220  
 221  		function strip_html($dirty='')
 222          {
 223              if($dirty == '')
 224              {
 225                  $dirty = array();
 226              }
 227              for($i=0;$i<count($dirty);$i++)
 228              {
 229                  if(@is_array($dirty[$i]))
 230                  {
 231                      foreach($dirty[$i] as $name => $value)
 232                      {
 233                          $cleaned[$i][$name] = $GLOBALS['egw']->strip_html($dirty[$i][$name]);
 234                      }
 235                  }
 236                  else
 237                  {
 238                      $cleaned[$i] == $GLOBALS['egw']->strip_html($dirty[$i]);
 239                  }
 240              }
 241              return $cleaned;
 242          }
 243  
 244          // return array with all addressbook categories (for xmlrpc)
 245  		function categories($complete = False)
 246          {
 247              return $this->xmlrpc ? $GLOBALS['server']->categories($complete) : False;
 248          }
 249  
 250          // return array with all addressbook customfields (for xmlrpc)
 251  		function customfields($new_fields=False)
 252          {
 253              $fields = CreateObject('addressbook.bofields');
 254  
 255              if(is_array($new_fields) && count($new_fields))
 256              {
 257                  if(!$GLOBALS['egw_info']['user']['apps']['admin'])
 258                  {
 259                      $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
 260                  }
 261                  foreach($new_fields as $new)
 262                  {
 263                      $fields->_save('',$new);
 264                  }
 265              }
 266              $customfields = array();
 267              foreach($fields->_read() as $data)
 268              {
 269                  $customfields[$data['name']] = $data['title'];
 270              }
 271              if($this->xmlrpc && !isset($customfields['freebusy_url']))
 272              {
 273                  $fields->_save('','freebusy URL');
 274                  $customfields['freebusy_url'] = 'freebusy URL';
 275              }
 276              return $customfields;
 277          }
 278  
 279          // translate array of internal datas to xmlrpc, eg. format bday as iso8601
 280  		function data2xmlrpc($datas)
 281          {
 282              if(is_array($datas))
 283              {
 284                  foreach($datas as $n => $data)
 285                  {
 286                      // translate birthday to a iso8601 date
 287                      if(isset($data['bday']))
 288                      {
 289                          if(strlen($data['bday']) > 2)
 290                          {
 291                              list($m,$d,$y) = explode('/',$data['bday']);
 292                          }
 293                          else
 294                          {
 295                              $y = $m = $d = 0;
 296                          }
 297                          $datas[$n]['bday'] = $GLOBALS['server']->date2iso8601(array('year'=>$y,'month'=>$m,'mday'=>$d));
 298                      }
 299                      // translate modification time
 300                      if(isset($data['last_mod']))
 301                      {
 302                          $datas[$n]['last_mod'] = $GLOBALS['server']->date2iso8601($data['last_mod']);
 303                      }
 304                      // translate categories-id-list to array with id-name pairs
 305                      if(isset($data['cat_id']))
 306                      {
 307                          $datas[$n]['cat_id'] = $GLOBALS['server']->cats2xmlrpc(explode(',',$data['cat_id']));
 308                      }
 309                  }
 310              }
 311              return $datas;
 312          }
 313  
 314          // retranslate from xmlrpc / iso8601 to internal format
 315  		function xmlrpc2data($data)
 316          {
 317              if(isset($data['bday']))
 318              {
 319                  $arr = $GLOBALS['server']->iso86012date($data['bday']);
 320                  $data['bday'] = $arr['year'] && $arr['month'] && $arr['mday'] ? sprintf('%d/%02d/%04d',$arr['month'],$arr['mday'],$arr['year']) : '';
 321              }
 322              if(isset($data['last_mod']))
 323              {
 324                  $data['last_mod']  = $GLOBALS['server']->iso86012date($data['last_mod'],True);
 325              }
 326              if(isset($data['cat_id']))
 327              {
 328                  $cats = $GLOBALS['server']->xmlrpc2cats($data['cat_id']);
 329                  $data['cat_id'] = count($cats) > 1 ? ','.implode(',',$cats).',' : (int)$cats[0];
 330              }
 331              return $data;
 332          }
 333  
 334          // return a pseudo addressbook-entry for a user
 335  		function user_pseudo_entry($account)
 336          {
 337              static $prefs=False;
 338              if(!is_object($prefs))
 339              {
 340                  $prefs = CreateObject('phpgwapi.preferences');    // wie need a new copy, as wie change the user
 341              }
 342              if(!is_array($account))
 343              {
 344                  $GLOBALS['egw']->accounts->account_id = $account;
 345                  $account = $GLOBALS['egw']->accounts->read_repository();
 346              }
 347              $prefs->account_id = $account['account_id'];
 348              $prefs->read_repository();
 349              $freebusy_url = $GLOBALS['egw_info']['server']['webserver_url'].'/calendar/freebusy.php?user='.$account['account_lid'];
 350              if($freebusy_url[0] == '/')
 351              {
 352                  $freebusy_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$freebusy_url;
 353              }
 354              $firstname = $account['account_firstname'] ? $account['account_firstname'] : $account['firstname'];
 355              $lastname  = $account['account_lastname'] ? $account['account_lastname'] : $account['lastname'];
 356              $ret = array(
 357                  'n_family' => $lastname,
 358                  'n_given'  => $firstname,
 359                  'fn'       => $GLOBALS['egw']->common->display_fullname($account['account_lid'],$firstname,$lastname),
 360                  'email'    => $prefs->email_address($account['account_id']),
 361                  'freebusy_url' => $freebusy_url,
 362                  'rights'   => PHPGW_ACL_READ,    // readonly access
 363                  'id'       => -$account['account_id'],
 364                  'tid'      => 'p',    // Profil
 365              );
 366              //echo "<p>user_pseudo_entry(".print_r($account,True).")=".print_r($ret,True)."</p>";
 367              return $ret;
 368          }
 369  
 370  		function get_users($type='all')
 371          {
 372              $users = array();
 373              switch($type)
 374              {
 375                  case 'all':            // all
 376                      $accounts = $GLOBALS['egw']->accounts->get_list('accounts');
 377                      break;
 378                  case 'calendar':    // Calendar users
 379                      $accounts = $GLOBALS['egw']->acl->get_ids_for_location('run',1,'calendar');
 380                      break;
 381                  case 'groupmates':    // Groupmates
 382                      $accounts = array();
 383                      foreach($GLOBALS['egw']->accounts->membership() as $group)
 384                      {
 385                          $accounts[] = $group['account_id'];
 386                      }
 387                      break;
 388              }
 389              foreach($accounts as $key => $account)
 390              {
 391                  if($type == 'calendar' && $GLOBALS['egw']->accounts->get_type($account) == 'g' || $type == 'groupmates')
 392                  {
 393                      // $account is a group
 394                      unset($accounts[$key]);
 395                      $members = $GLOBALS['egw']->accounts->member($account);
 396                      if(is_array($members))
 397                      {
 398                          foreach($members as $member)
 399                          {
 400                              $accounts[] = $member['account_id'];
 401                          }
 402                      }
 403                  }
 404              }
 405              if($type != 'all')
 406              {
 407                  $accounts = array_unique($accounts);    // remove doubles
 408              }
 409              $prefs = CreateObject('phpgwapi.preferences');    // wie need a new copy, as wie change the user
 410              foreach($accounts as $account)
 411              {
 412                  $users[] = $this->user_pseudo_entry($account);
 413              }
 414              return $users;
 415          }
 416  
 417  		function read_entries($data)
 418          {
 419              if($this->xmlrpc && !isset($data['fields']))
 420              {
 421                  $data['fields'] = array_keys(array_merge($this->so->contacts->non_contact_fields,$this->so->contacts->stock_contact_fields,$this->customfields()));
 422              }
 423              $entries = $this->so->read_entries($data);
 424              $this->total = $this->so->contacts->total_records;
 425              if(!is_array($entries))
 426              {
 427                  $entries = array();
 428              }
 429              else
 430              {
 431                  $entries = $this->strip_html($entries);
 432              }
 433              // evtl. get uses as read-only addressbook entries, just with Name, Firstname, Email
 434              if(@$data['include_users'])
 435              {
 436                  $entries = array_merge($entries,$this->get_users($data['include_users']));
 437              }
 438              if($this->xmlrpc)
 439              {
 440                  $entries = $this->data2xmlrpc($entries);
 441              }
 442              if($this->debug) { echo '<br>Total records="' . $this->total . '"'; }
 443              return $entries;
 444          }
 445  
 446  		function read_entry($data)
 447          {
 448              if($this->xmlrpc && !isset($data['fields']))
 449              {
 450                  $data['fields'] = array_keys(array_merge($this->so->contacts->non_contact_fields,$this->so->contacts->stock_contact_fields,$this->customfields()));
 451              }
 452              if($data['id'] < 0)
 453              {
 454                  $entry = array($this->user_pseudo_entry(-$data['id']));
 455                  if($this->xmlrpc)
 456                  {
 457                      $entry = $this->data2xmlrpc($entry);
 458                  }
 459                  return $entry;
 460              }
 461              if($this->check_perms($data,PHPGW_ACL_READ))
 462              {
 463                  $entry = $this->so->read_entry($data['id'],$data['fields']);
 464                  $entry = $this->strip_html($entry);
 465                  if($this->xmlrpc)
 466                  {
 467                      $entry = $this->data2xmlrpc($entry);
 468                  }
 469                  return $entry;
 470              }
 471              if($this->xmlrpc)
 472              {
 473                  $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
 474              }
 475              return False;
 476          }
 477  
 478  		function read_last_entry($fields)
 479          {
 480              if($this->check_perms($fields,PHPGW_ACL_READ))
 481              {
 482                  $entry = $this->so->read_last_entry($fields);
 483                  $entry = $this->strip_html($entry);
 484                  if($this->xmlrpc)
 485                  {
 486                      $entry = $this->data2xmlrpc($entry);
 487                  }
 488                  return $entry;
 489              }
 490              if($this->xmlrpc)
 491              {
 492                  $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
 493              }
 494              return False;
 495          }
 496  
 497  		function add_vcard($uploadedfile='')
 498          {
 499              if($uploadedfile == 'none' || $uploadedfile == '' || substr($uploadedfile['name'],-4) != '.vcf')
 500              {
 501                  return False;
 502              }
 503              else
 504              {
 505                  $filename = $uploadedfile['tmp_name'];
 506  
 507                  $vcard = CreateObject('phpgwapi.vcard');
 508                  $entry = $vcard->in_file($filename);
 509                  /* _debug_array($entry);exit; */
 510                  $entry['owner'] = (int)$GLOBALS['egw_info']['user']['account_id'];
 511                  $entry['access'] = 'private';
 512                  $entry['tid'] = 'n';
 513                  /* _debug_array($entry);exit; */
 514  
 515                  $this->so->add_entry($entry);
 516                  $ab_id = $this->get_lastid();
 517  
 518                  return(int)$ab_id;
 519              }
 520          }
 521  
 522  		function add_email()
 523          {
 524              global $name,$referer;
 525  
 526              $named = explode(' ', $name);
 527              for($i=count($named);$i>=0;$i--) { $names[$i] = $named[$i]; }
 528              if($names[2])
 529              {
 530                  $fields['n_given']  = $names[0];
 531                  $fields['n_middle'] = $names[1];
 532                  $fields['n_family'] = $names[2];
 533              }
 534              else
 535              {
 536                  $fields['n_given']  = $names[0];
 537                  $fields['n_family'] = $names[1];
 538              }
 539              $fields['email']    = $add_email;
 540              $referer = urlencode($referer);
 541  
 542              $this->so->add_entry($GLOBALS['egw_info']['user']['account_id'],$fields,'private','','n');
 543              $ab_id = $this->get_lastid();
 544  
 545              Header('Location: '
 546                  . $GLOBALS['egw']->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer"));
 547          }
 548  
 549  		function add_entry($fields)
 550          {
 551              // setting some defaults, if not set eg. via xmlrpc
 552              $fields['tid'] = trim($fields['tid']);
 553              if(empty($fields['tid']))
 554              {
 555                  $fields['tid'] = 'n';
 556              }
 557              if(!@$fields['owner'])
 558              {
 559                  $fields['owner'] = (int)$GLOBALS['egw_info']['user']['account_id'];
 560              }
 561              if(empty($fields['access']))
 562              {
 563                  $fields['access'] = 'public';
 564              }
 565              if($this->xmlrpc)
 566              {
 567                  $fields = $this->xmlrpc2data($fields);
 568              }
 569              $id = $this->so->add_entry($fields);
 570              
 571              if($id)
 572              {
 573                  $GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'add', time());
 574              }
 575  
 576              if($this->xmlrpc && !$id)
 577              {
 578                  $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
 579              }
 580              return $id;
 581          }
 582  
 583  		function get_lastid()
 584          {
 585              return $this->so->get_lastid();
 586          }
 587  
 588  		function update_entry($fields)
 589          {
 590              if(!$fields['id'] && !$fields['ab_id'])
 591              {
 592                  return $this->add_entry($fields);
 593              }
 594              $ok = False;
 595              if($this->check_perms($fields,PHPGW_ACL_EDIT))
 596              {
 597                  if($this->xmlrpc)
 598                  {
 599                      $fields = $this->xmlrpc2data($fields);
 600                  }
 601                  $ok = $this->so->update_entry($fields);
 602                  if($ok)
 603                  {
 604                      $GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $fields['ab_id'], 'modify', time());
 605                  }
 606              }
 607              if($this->xmlrpc && !$ok)
 608              {
 609                  $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
 610              }
 611              return $ok;
 612          }
 613  
 614  		function delete_entry($addr)
 615          {
 616              if(!is_array($addr))
 617              {
 618                  $id = (int)$addr;
 619              }
 620              else
 621              {
 622                  if(is_numeric($addr[0]))    // xmlrpc liefert array($id)
 623                  {
 624                      $id = (int)$addr[0];
 625                  }
 626                  else
 627                  {
 628                      $id = isset($addr['id']) ? $addr['id'] : $addr['ab_id'];
 629                  }
 630              }
 631              if($this->check_perms($id,PHPGW_ACL_DELETE))
 632              {
 633                  $this->so->delete_entry($id);
 634                  $GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
 635              }
 636              elseif($this->xmlrpc)
 637              {
 638                  $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']);
 639              }
 640          }
 641  
 642          /*!
 643          @function check_perms
 644          @abstract checks if user has the necessary rights on the given address or address-id
 645          @syntax check_perms($addr,$rights)
 646          @param $addr mixed address-record with id and owner or addr-id
 647          @param $rights integer PHPGW_ACL_{READ|EDIT|ADD|DELETE}
 648          @return True if the user has the requested rights, else False
 649          */
 650  		function check_perms($addr,$rights)
 651          {
 652              $id = (int) (!is_array($addr) ? $addr : (isset($addr['id']) ? $addr['id'] : $addr['ab_id']));
 653  
 654              if($id < 0)
 655              {
 656                  return $rights == PHPGW_ACL_READ;
 657              }
 658              if(!is_array($addr) || !isset($addr['rights']) && !isset($addr['owner']))
 659              {
 660                  $addr = $this->so->read_entry($id,array('owner'));
 661                  if(!$addr && $this->xmlrpc)
 662                  {
 663                      $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_exist'],$GLOBALS['xmlrpcstr']['not_exist']);
 664                  }
 665                  $addr = $addr[0];
 666              }
 667              $ret = $this->so->contacts->check_perms(False,$rights,$addr);
 668              //echo "<p>boaddressbook::check_perms(".print_r($addr,True).",$rights) = ".($ret?'True':'False')."</p>\n";
 669              return $ret;
 670          }
 671  
 672  		function save_preferences($prefs,$other,$qfields,$fcat_id)
 673          {
 674              $GLOBALS['egw']->preferences->read_repository();
 675              if(is_array($prefs))
 676              {
 677                  /* _debug_array($prefs);exit; */
 678                  while(list($pref,$x) = each($qfields))
 679                  {
 680                      /* echo '<br>checking: ' . $pref . '=' . $prefs[$pref]; */
 681                      if($prefs[$pref] == 'on')
 682                      {
 683                          $GLOBALS['egw']->preferences->add('addressbook',$pref,'addressbook_on');
 684                      }
 685                      else
 686                      {
 687                          $GLOBALS['egw']->preferences->delete('addressbook',$pref);
 688                      }
 689                  }
 690              }
 691              if(is_array($other))
 692              {
 693                  $GLOBALS['egw']->preferences->delete('addressbook','mainscreen_showbirthdays');
 694                  if($other['mainscreen_showbirthdays'])
 695                  {
 696                      $GLOBALS['egw']->preferences->add('addressbook','mainscreen_showbirthdays',True);
 697                  }
 698  
 699                  $GLOBALS['egw']->preferences->delete('addressbook','default_filter');
 700                  if($other['default_filter'])
 701                  {
 702                      $GLOBALS['egw']->preferences->add('addressbook','default_filter',$other['default_filter']);
 703                  }
 704  
 705                  $GLOBALS['egw']->preferences->delete('addressbook','autosave_category');
 706                  if($other['autosave_category'])
 707                  {
 708                      $GLOBALS['egw']->preferences->add('addressbook','autosave_category',True);
 709                  }
 710              }
 711  
 712              $GLOBALS['egw']->preferences->delete('addressbook','default_category');
 713              $GLOBALS['egw']->preferences->add('addressbook','default_category',$fcat_id);
 714  
 715              $GLOBALS['egw']->preferences->save_repository(True);
 716          }
 717  
 718  		function list_methods($_type='xmlrpc')
 719          {
 720              /*
 721                This handles introspection or discovery by the logged in client,
 722                in which case the input might be an array.  The server always calls
 723                this function to fill the server dispatch map using a string.
 724              */
 725              if(is_array($_type))
 726              {
 727                  $_type = $_type['type'] ? $_type['type'] : $_type[0];
 728              }
 729              switch($_type)
 730              {
 731                  case 'xmlrpc':
 732                      $xml_functions = array(
 733                          'read' => array(
 734                              'function'  => 'read_entry',
 735                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
 736                              'docstring' => lang('Read a single entry by passing the id and fieldlist.')
 737                          ),
 738                          'add' => array(
 739                              'function'  => 'add_entry',
 740                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
 741                              'docstring' => lang('Add a single entry by passing the fields.')
 742                          ),
 743                          'save' => array(
 744                              'function'  => 'update_entry',
 745                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
 746                              'docstring' => lang('Update a single entry by passing the fields.')
 747                          ),
 748                          'write' => array(    // alias for consistent nameing
 749                              'function'  => 'update_entry',
 750                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
 751                              'docstring' => lang('Write (update or add) a single entry by passing the fields.')
 752                          ),
 753                          'delete' => array(
 754                              'function'  => 'delete_entry',
 755                              'signature' => array(array(xmlrpcString,xmlrpcString)),
 756                              'docstring' => lang('Delete a single entry by passing the id.')
 757                          ),
 758                          'read_list' => array(
 759                              'function'  => 'read_entries',
 760                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
 761                              'docstring' => lang('Read a list / search for entries.')
 762                          ),
 763                          'search' => array(    // alias for consitent nameing
 764                              'function'  => 'read_entries',
 765                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
 766                              'docstring' => lang('Read a list / search for entries.')
 767                          ),
 768                          'categories' => array(
 769                              'function'  => 'categories',
 770                              'signature' => array(array(xmlrpcBoolean,xmlrpcBoolean)),
 771                              'docstring' => lang('List all categories')
 772                          ),
 773                          'customfields' => array(
 774                              'function'  => 'customfields',
 775                              'signature' => array(array(xmlrpcArray,xmlrpcArray)),
 776                              'docstring' => lang('List all customfields')
 777                          ),
 778                          'list_methods' => array(
 779                              'function'  => 'list_methods',
 780                              'signature' => array(array(xmlrpcStruct,xmlrpcString)),
 781                              'docstring' => lang('Read this list of methods.')
 782                          )
 783                      );
 784                      return $xml_functions;
 785                      break;
 786                  case 'soap':
 787                      return $this->soap_functions;
 788                      break;
 789                  default:
 790                      return array();
 791                      break;
 792              }
 793          }
 794      }
 795  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7