[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpgwapi/inc/ -> class.contacts.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare API - Contact Management Shared Routines                      *
   4      * Written by Joseph Engo <jengo@phpgroupware.org>                          *
   5      *        and Miles Lott <milosch@groupwhere.org>                           *
   6      *        and Bettina Gille <ceb@phpgroupware.org>                          *
   7      * View and manipulate contact records                                      *
   8      * Copyright (C) 2001, 2002 Joseph Engo, Miles Lott, Bettina Gille          *
   9      * ------------------------------------------------------------------------ *
  10      * This library is part of the eGroupWare API                               *
  11      * http://www.egroupware.org                                                *
  12      * ------------------------------------------------------------------------ *
  13      * This library is free software; you can redistribute it and/or modify it  *
  14      * under the terms of the GNU Lesser General Public License as published by *
  15      * the Free Software Foundation; either version 2.1 of the License,         *
  16      * or any later version.                                                    *
  17      * This library is distributed in the hope that it will be useful, but      *
  18      * WITHOUT ANY WARRANTY; without even the implied warranty of               *
  19      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  20      * See the GNU Lesser General Public License for more details.              *
  21      * You should have received a copy of the GNU Lesser General Public License *
  22      * along with this library; if not, write to the Free Software Foundation,  *
  23      * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
  24      \**************************************************************************/
  25      /* $Id: class.contacts.inc.php 20295 2006-02-15 12:31:25Z  $ */
  26  
  27      if (!isset($GLOBALS['egw_info']['server']['contact_repository']))
  28      {
  29          $GLOBALS['egw_info']['server']['contact_repository'] = 'sql';
  30      }
  31      require_once(EGW_API_INC . '/class.contacts_'.$GLOBALS['egw_info']['server']['contact_repository'] . '.inc.php');
  32  
  33      class contacts extends contacts_
  34      {
  35  		function contacts()
  36          {
  37              $this->contacts_();    // call constructor of extended class
  38          }
  39  
  40          /*!
  41          @function check_perms
  42          @abstract checks if user has the necessary permissions on a contact
  43          @syntax check_perms($rights,$needed,$addr=False)
  44          @param $rights integer the rights the user has / grants from the owner of the contact, only used if $addr not given
  45          @param $needed integer PHPGW_ACL_{READ|EDIT|DELETE}
  46          @param $addr mixed contact-array or contact-id, if False rights have to be supplyed in $rights
  47          */
  48  		function check_perms($rights,$needed,$addr=False)
  49          {
  50              //echo "<p>contacts::check_perms($rights,$needed,".print_r($addr,True).")";
  51              if ($addr !== False)    // addr-record or id given
  52              {
  53                  if(@is_array($addr))
  54                  {
  55                      if (isset($addr['rights']))
  56                      {
  57                          $rights = $addr['rights'];
  58                      }
  59                      elseif (isset($addr['owner']))
  60                      {
  61                          $rights = $this->grants[$addr['owner']];
  62                      }
  63                      else
  64                      {
  65                          $id = (int)(isset($addr['id']) ? $addr['id'] : $addr['ab_id']);
  66                      }
  67                  }
  68                  else
  69                  {
  70                      $id = (int)$addr;
  71                  }
  72                  if (isset($id))
  73                  {
  74                      $addr = $this->read_single_entry($id,array('owner' => 'owner'));
  75                      $rights = @$addr[0]['rights'];
  76                      //echo "addr($id)=<pre>".print_r($addr[0],True)."</pre>\n";
  77                  }
  78              }
  79              $ret = !!((int)$rights & $needed);
  80              //echo " rights=$rights, id=$id => ".($ret?'True':'False')."</p>\n";
  81              //echo "grants=<pre>".print_r($this->grants,True)."</pre>\n";
  82  
  83              return $ret;
  84          }
  85  
  86          /**
  87          * Get the the person data what you want. Wrapper function to stay compatible with egroupware.
  88          *
  89          * @author Lars Kneschke <lars@kneschke.de>
  90          * @param array $fields The fields that you can see from person
  91          * @param integer $limit Limit of records that you want
  92          * @param integer $ofset Ofset of record that you want start
  93          * @param string $orderby The field which you want order
  94          * @param string $sort ASC | DESC depending what you want
  95          * @param mixed $criteria All criterias what you want
  96          * @param mixed $criteria_token same like $criteria but builded<br>with sql_criteria class, more powerfull
  97          * @return array with records
  98          */
  99  		function get_persons($_fields, $start='', $limit='', $orderby='', $sort='', $_criteria='', $token_criteria='')
 100          {
 101              // transform fields from phpgw to egw structure
 102              foreach($_fields as $fieldValue)
 103              {
 104                  switch($fieldValue)
 105                  {
 106                      case 'per_first_name':
 107                          $fields['n_given']='n_given';
 108                      case 'per_last_name':
 109                          $fields['n_family']='n_family';
 110                      default:
 111                          $fields[$fieldValue]=$fieldValue;
 112                  }
 113              }
 114  
 115              // transform criteria from phpgw to egw structure
 116              if(is_array($_criteria))
 117              {
 118                  foreach($_criteria as $criteriaKey => $criteriaValue)
 119                  {
 120                      if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap')
 121                      {
 122                          switch($criteriaKey)
 123                          {
 124                              case 'contact_id':
 125                              $criteria['uid']=$criteriaValue;
 126                                      break;
 127                              default:
 128                                  $criteria[$criteriaKey] = $criteria[$criteriaValue];
 129                                  break;
 130                          }
 131                      }
 132                      else
 133                      {
 134                          switch($criteriaKey)
 135                          {
 136                              case 'contact_id':
 137                              $criteria['id']=$criteriaValue;
 138                                      break;
 139                              default:
 140                                  $criteria[$criteriaKey] = $criteria[$criteriaValue];
 141                                  break;
 142                          }
 143                      }
 144                  }
 145              }
 146              $entries = $this->read($start,$limit,$fields,$criteria,'',$sort,$orderby);
 147  
 148              // transform entries from egw to phpgw structure
 149              if(is_array($entries))
 150              {
 151                  foreach($entries as $entryKey => $entryValue)
 152                  {
 153                      $entryValue['per_first_name']     = $entryValue['n_given'];
 154                      $entryValue['per_last_name']     = $entryValue['n_family'];
 155                      $entryValue['contact_id']    = $entryValue['id'];
 156                      $entries[$entryKey]        = $entryValue;
 157                  }
 158              }
 159              return $entries;
 160          }
 161  
 162  		function split_stock_and_extras($fields)
 163          {
 164              settype($fields, 'array');
 165              foreach($fields as $field => $value)
 166              {
 167                  /* Depending on how the array was built, this is needed. */
 168                  if (is_int($field))
 169                  {
 170                      $field = $value;
 171                  }
 172                  if(@is_int($value))
 173                  {
 174                      $value = $field;
 175                  }
 176                  if ($this->stock_contact_fields[$field])
 177                  {
 178                      $stock_fields[$field]     = $value;
 179                      $stock_fieldnames[$field] = $this->stock_contact_fields[$field];
 180                  }
 181                  elseif (!isset($this->non_contact_fields[$field]))
 182                  {
 183                      $extra_fields[$field] = $value;
 184                  }
 185              }
 186              return array($stock_fields,$stock_fieldnames,$extra_fields);
 187          }
 188  
 189  		function loop_addslashes($fields)
 190          {
 191              $absf = $this->stock_contact_fields;
 192              foreach($absf as $t => $nul)
 193              {
 194                  $ta[] = $this->db->db_addslashes($fields[$t]);
 195              }
 196              return $ta;
 197          }
 198  
 199          /* This will take an array or integer */
 200  		function delete($id)
 201          {
 202              if(@is_array($id))
 203              {
 204                  foreach($id as $nul => $t_id)
 205                  {
 206                      $this->delete_($t_id);
 207                  }
 208              }
 209              else
 210              {
 211                  $this->delete_($id);
 212              }
 213          }
 214  
 215  		function asc_sort($a,$b)
 216          {
 217              echo "<br>A:'".$a."' B:'".$b;
 218              if($a[1] == $b[1])
 219              {
 220                  return 0;
 221              }
 222              return ($a[1]>$b[1])?1:-1;
 223          }
 224  
 225  		function desc_sort($a,$b)
 226          {
 227              echo "<br>A:'".$a."' B:'".$b;
 228              if($a[1]==$b[1])
 229              {
 230                  return 0;
 231              }
 232              return ($a[1]<$b[1])?1:-1;
 233          }
 234  
 235          /**
 236          * To be used in usort()
 237          *
 238          * compares two 2-dimensional arrays a and b.
 239          * The first dimension holds the key, the array is sorted by.
 240          * The second dimension holds the data, that's actually string-compared.
 241          *
 242          * @author Carsten Wolff <wolffc@egroupware.org>
 243          * @param array $fields The fields, the array is to be sorted by. Use of multiple keys is for subsorting.
 244          * @param string $order ASC | DESC ascending or descending order
 245          * @param array $a one item
 246          * @param array $b the other item
 247          * @return integer -1 | 0 | 1 equals: a is smaller | the same | larger than b.
 248          */
 249  		function _cmp($fields, $order, $a, $b)
 250          {
 251              foreach ($fields as $field)
 252              {
 253                  $result = strcasecmp($a[$field][0], $b[$field][0]);
 254                  if ($result == 0)
 255                  {
 256                      continue;
 257                  }
 258                  if ($order == "DESC")
 259                  {
 260                      return -$result;
 261                  }
 262                  else
 263                  {
 264                      return $result;
 265                  }
 266              }
 267              return 0;
 268          }
 269  
 270  		function formatted_address($id, $business = True, $afont = '', $asize = '2')
 271          {
 272              $t = CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir('addressbook'));
 273              $s = CreateObject('phpgwapi.sbox');
 274  
 275              $fields = array(
 276                  'n_given'  => 'n_given',
 277                  'n_family' => 'n_family',
 278                  'title'    => 'title',
 279                  'org_name' => 'org_name',
 280                  'org_unit' => 'org_unit',
 281                  'adr_one_street'      => 'adr_one_street',
 282                  'adr_one_locality'    => 'adr_one_locality',
 283                  'adr_one_postalcode'  => 'adr_one_postalcode',
 284                  'adr_one_region'      => 'adr_one_region',
 285                  'adr_one_countryname' => 'adr_one_countryname',
 286                  'adr_two_street'      => 'adr_two_street',
 287                  'adr_two_locality'    => 'adr_two_locality',
 288                  'adr_two_postalcode'  => 'adr_two_postalcode',
 289                  'adr_two_region'      => 'adr_two_region',
 290                  'adr_two_countryname' => 'adr_two_countryname'
 291              );
 292  
 293              list($address) = $this->read_single_entry($id,$fields);
 294              foreach($address as $k => $val)
 295              {
 296                  $address[$k] = $GLOBALS['egw']->strip_html($val);
 297              }
 298  
 299              if ($address['title'])
 300              {
 301                  $title = $address['title'] . '&nbsp;';
 302              }
 303  
 304              if ($business)
 305              {
 306                  if ($address['org_name'])
 307                  {
 308                      $company = $address['org_name'];
 309                  }
 310                  else
 311                  {
 312                      $company = $title . $address['n_given'] . '&nbsp;' . $address['n_family'];
 313                  }
 314  
 315                  $street  = $address['adr_one_street'];
 316                  $city    = $address['adr_one_locality'];
 317                  $zip     = $address['adr_one_postalcode'];
 318                  $state   = $address['adr_one_region'];
 319                  $country = $address['adr_one_countryname'];
 320              }
 321              else
 322              {
 323                  $company = $title . $address['n_given'] . '&nbsp;' . $address['n_family'];
 324                  $street  = $address['adr_two_street'];
 325                  $city    = $address['adr_two_locality'];
 326                  $zip     = $address['adr_two_postalcode'];
 327                  $state   = $address['adr_two_region'];
 328                  $country = $address['adr_two_countryname'];
 329              }
 330  
 331              if (! $country)
 332              {
 333                  $country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
 334              }
 335  
 336              if (file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'format_' . strtolower($country) . '.tpl'))
 337              {
 338                  $a = $t->set_file(array('address_format' => 'format_' . strtolower($country) . '.tpl'));
 339              }
 340              else
 341              {
 342                  $a = $t->set_file(array('address_format' => 'format_us.tpl'));
 343              }
 344  
 345              if (!$afont)
 346              {
 347                  $afont = $GLOBALS['egw_info']['theme']['font'];
 348              }
 349  
 350              $a .= $t->set_var('font',$afont);
 351              $a .= $t->set_var('fontsize',$asize);
 352              $a .= $t->set_var('company',$company);
 353              $a .= $t->set_var('department',$address['org_unit']);
 354              $a .= $t->set_var('street',$street);
 355              $a .= $t->set_var('city',$city);
 356              $a .= $t->set_var('zip',$zip);
 357              $a .= $t->set_var('state',$state);
 358  
 359              if ($country != $GLOBALS['egw_info']['user']['preferences']['common']['country'])
 360              {
 361                  $countryname = $s->get_full_name($country);
 362                  $a .= $t->set_var('country',lang($countryname));
 363              }
 364  
 365              $a .= $t->fp('out','address_format');
 366              return $a;
 367          }
 368  
 369  		function formatted_address_full($id, $business = True, $afont = '', $asize = '2')
 370          {
 371              $t = CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir('addressbook'));
 372              $s = CreateObject('phpgwapi.sbox');
 373  
 374              $fields = array(
 375                  'n_given'                => 'n_given',
 376                  'n_family'                => 'n_family',
 377                  'title'                    => 'title',
 378                  'org_name'                => 'org_name',
 379                  'org_unit'                => 'org_unit',
 380                  'adr_one_street'        => 'adr_one_street',
 381                  'adr_one_locality'        => 'adr_one_locality',
 382                  'adr_one_postalcode'    => 'adr_one_postalcode',
 383                  'adr_one_region'        => 'adr_one_region',
 384                  'tel_work'                => 'tel_work',
 385                  'tel_fax'                => 'tel_fax',
 386                  'email'                    => 'email',
 387                  'url'                    => 'url',
 388                  'adr_one_countryname'    => 'adr_one_countryname',
 389                  'adr_two_street'        => 'adr_two_street',
 390                  'adr_two_locality'        => 'adr_two_locality',
 391                  'adr_two_postalcode'    => 'adr_two_postalcode',
 392                  'adr_two_region'        => 'adr_two_region',
 393                  'adr_two_countryname'    => 'adr_two_countryname',
 394                  'tel_home'                => 'tel_home',
 395                  'email_home'            => 'email_home'
 396              );
 397  
 398              list($address) = $this->read_single_entry($id,$fields);
 399              foreach($address as $k => $val)
 400              {
 401                  $address[$k] = $GLOBALS['egw']->strip_html($val);
 402              }
 403  
 404              if($address['title'])
 405              {
 406                  $title = $address['title'] . '&nbsp;';
 407              }
 408  
 409              if($business)
 410              {
 411                  if($address['org_name'])
 412                  {
 413                      $company = $address['org_name'];
 414                  }
 415                  else
 416                  {
 417                      $company = $title . $address['n_given'] . '&nbsp;' . $address['n_family'];
 418                  }
 419  
 420                  $street        = $address['adr_one_street'];
 421                  $city        = $address['adr_one_locality'];
 422                  $zip        = $address['adr_one_postalcode'];
 423                  $state        = $address['adr_one_region'];
 424                  $country    = $address['adr_one_countryname'];
 425                  $tel        = $address['tel_work'];
 426                  $email        = $address['email'];
 427              }
 428              else
 429              {
 430                  $company    = $title . $address['n_given'] . '&nbsp;' . $address['n_family'];
 431                  $street        = $address['adr_two_street'];
 432                  $city        = $address['adr_two_locality'];
 433                  $zip        = $address['adr_two_postalcode'];
 434                  $state        = $address['adr_two_region'];
 435                  $country    = $address['adr_two_countryname'];
 436                  $tel        = $address['tel_home'];
 437                  $email        = $address['email_home'];
 438              }
 439  
 440              if(!$country)
 441              {
 442                  $country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
 443              }
 444  
 445              if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'full_format_' . strtolower($country) . '.tpl'))
 446              {
 447                  $a = $t->set_file(array('address_format' => 'full_format_' . strtolower($country) . '.tpl'));
 448              }
 449              else
 450              {
 451                  $a = $t->set_file(array('address_format' => 'full_format_us.tpl'));
 452              }
 453  
 454              if(!$afont)
 455              {
 456                  $afont = $GLOBALS['egw_info']['theme']['font'];
 457              }
 458  
 459              $a .= $t->set_var('font',$afont);
 460              $a .= $t->set_var('fontsize',$asize);
 461              $a .= $t->set_var('lang_url',lang('url'));
 462              $a .= $t->set_var('lang_email',lang('email'));
 463              $a .= $t->set_var('lang_fax',lang('fax number'));
 464              $a .= $t->set_var('lang_fon',lang('phone number'));
 465              $a .= $t->set_var('company',$company);
 466              $a .= $t->set_var('department',$address['org_unit']);
 467              $a .= $t->set_var('street',$street);
 468              $a .= $t->set_var('city',$city);
 469              $a .= $t->set_var('zip',$zip);
 470              $a .= $t->set_var('state',$state);
 471              $a .= $t->set_var('email',$email);
 472              $a .= $t->set_var('tel',$tel);
 473              $a .= $t->set_var('fax',$address['tel_fax']);
 474              $a .= $t->set_var('url',$address['url']);
 475  
 476              if($country != $GLOBALS['egw_info']['user']['preferences']['common']['country'])
 477              {
 478                  $countryname = $s->get_full_name($country);
 479                  $a .= $t->set_var('country',lang($countryname));
 480              }
 481  
 482              $a .= $t->fp('out','address_format');
 483              return $a;
 484          }
 485  
 486  		function formatted_address_line($id, $business = True, $afont = '', $asize = '2')
 487          {
 488              $t = CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir('addressbook'));
 489              $s = CreateObject('phpgwapi.sbox');
 490  
 491              $fields = array(
 492                  'n_given'                => 'n_given',
 493                  'n_family'                => 'n_family',
 494                  'title'                    => 'title',
 495                  'org_name'                => 'org_name',
 496                  'adr_one_street'        => 'adr_one_street',
 497                  'adr_one_locality'        => 'adr_one_locality',
 498                  'adr_one_postalcode'    => 'adr_one_postalcode',
 499                  'adr_one_region'        => 'adr_one_region',
 500                  'adr_one_countryname'    => 'adr_one_countryname',
 501                  'adr_two_street'        => 'adr_two_street',
 502                  'adr_two_locality'        => 'adr_two_locality',
 503                  'adr_two_postalcode'    => 'adr_two_postalcode',
 504                  'adr_two_region'        => 'adr_two_region',
 505                  'adr_two_countryname'    => 'adr_two_countryname'
 506              );
 507  
 508              list($address) = $this->read_single_entry($id,$fields);
 509              foreach($address as $k => $val)
 510              {
 511                  $address[$k] = $GLOBALS['egw']->strip_html($val);
 512              }
 513  
 514              if($address['title'])
 515              {
 516                  $title = $address['title'] . '&nbsp;';
 517              }
 518  
 519              if($business)
 520              {
 521                  if($address['org_name'])
 522                  {
 523                      $company = $address['org_name'];
 524                  }
 525                  else
 526                  {
 527                      $company = $title . $address['n_given'] . '&nbsp;' . $address['n_family'];
 528                  }
 529  
 530                  $street  = $address['adr_one_street'];
 531                  $city    = $address['adr_one_locality'];
 532                  $zip     = $address['adr_one_postalcode'];
 533                  $state   = $address['adr_one_region'];
 534                  $country = $address['adr_one_countryname'];
 535              }
 536              else
 537              {
 538                  $company = $title . $address['n_given'] . '&nbsp;' . $address['n_family'];
 539                  $street  = $address['adr_two_street'];
 540                  $city    = $address['adr_two_locality'];
 541                  $zip     = $address['adr_two_postalcode'];
 542                  $state   = $address['adr_two_region'];
 543                  $country = $address['adr_two_countryname'];
 544              }
 545  
 546              if(!$country)
 547              {
 548                  $country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
 549              }
 550  
 551              if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'line_format_' . strtolower($country) . '.tpl'))
 552              {
 553                  $a = $t->set_file(array('address_format' => 'line_format_' . strtolower($country) . '.tpl'));
 554              }
 555              else
 556              {
 557                  $a = $t->set_file(array('address_format' => 'line_format_us.tpl'));
 558              }
 559  
 560              if(!$afont)
 561              {
 562                  $afont = $GLOBALS['egw_info']['theme']['font'];
 563              }
 564  
 565              $a .= $t->set_var('font',$afont);
 566              $a .= $t->set_var('fontsize',$asize);
 567              $a .= $t->set_var('company',$company);
 568              $a .= $t->set_var('street',$street);
 569              $a .= $t->set_var('city',$city);
 570              $a .= $t->set_var('zip',$zip);
 571              $a .= $t->set_var('state',$state);
 572  
 573              if($country != $GLOBALS['egw_info']['user']['preferences']['common']['country'])
 574              {
 575                  $countryname = $s->get_full_name($country);
 576                  $a .= $t->set_var('country','&nbsp;°&nbsp;' . lang($countryname));
 577              }
 578  
 579              $a .= $t->fp('out','address_format');
 580              return $a;
 581          }
 582      }
 583  ?>


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