[ PHPXref.com ] [ Generated: Sun Jul 20 20:47:44 2008 ] [ TUTOS 1.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/php/ -> address.pinc (source)

   1  <?php
   2  /**
   3   * Copyright 1999 - 2004 by Gero Kohnert
   4   *
   5   *  CVS Info:  $Id: address.pinc,v 1.113.2.1 2004/07/26 19:54:56 gokohnert Exp $
   6   *  $Author: gokohnert $
   7   *
   8   * @modulegroup address
   9   * @module address
  10   */
  11  include_once  'location.pinc';
  12  
  13  /**
  14   * a person (names and birthday)
  15   *
  16   * @package address
  17   */
  18  class tutos_address extends tutos_base {
  19  
  20    /* ---------------------------------------------------------------------------
  21     */
  22    function tutos_address(&$dbconn) {
  23      global $lang,$current_user,$tutos;
  24  
  25  
  26      $this->init($dbconn);
  27      $this->larray = array();
  28      $this->birthday = new DateTime(0);
  29      $this->f_name   = "";
  30      $this->l_name   = "";
  31      $this->m_name   = "";
  32      $this->title    = "";
  33      $this->pic_id   = -1;
  34      if (class_exists('tutos_file')) {
  35        $this->pic_file = new tutos_file($this->dbconn);
  36      } else {
  37        $this->pic_file = -1;
  38      }
  39      $this->rl1 = false;
  40      $this->rl2 = false;
  41      if (isset($dbconn)) {
  42        $this->tablename = $this->dbconn->prefix ."addresses";
  43      }
  44      $this->user = 0;
  45    }
  46  
  47    /**
  48     * fill the object data with a given resultset
  49     *
  50     * @param Object $r    a result set object 
  51     * @param int    $pos  a index in the resultset
  52     */
  53    function read_result(&$r,$pos) {
  54      global $g_hash;
  55  
  56      if ( ! isset($pos) ) return;
  57  
  58      $this->id       = $r->get($pos, "id");
  59  
  60      $this->larray[] = "title";
  61      $this->larray[] = "l_name";
  62      $this->larray[] = "f_name";
  63      $this->larray[] = "m_name";
  64  
  65      foreach($this->larray as $f) {
  66        $this->$f = $r->get($pos, $f);
  67        if (!isset($this->$f)) {
  68          $this->$f = "";
  69        }
  70      }
  71  
  72      $this->birthday->setDateTime($r->get($pos, "birthday"),1);
  73  
  74      $this->pic_id = $r->get($pos, "pic_id");
  75  
  76      $cid = $r->get($pos, "creator");
  77      if ( isset($cid) )  {
  78        if ( $cid != $this->id )  {
  79          $this->creator     = getObject($this->dbconn,$cid);
  80        } else {
  81          $this->creator = $this;
  82        }
  83      }
  84      $this->read_locs();
  85      parent::read_result($r,$pos);
  86  #    acl_read($this);
  87  #    $g_hash[$this->id] = &$this;
  88    }
  89    /**
  90     * Read picture object
  91     */
  92    function read_picture () {
  93      if ( $this->pic_id < 1 ) {
  94        return;
  95      }
  96      if ( $this->pic_file == -1 ) {
  97        return;
  98      }
  99      $this->pic_file = $this->pic_file->read($this->pic_id,$this->pic_file);
 100    }
 101  
 102    /**
 103     * Read all locations references
 104     */
 105    function read_locs () {
 106      if ( ! class_exists ("location") ) {
 107        require ("location.pinc");
 108      }
 109      read_locs($this);
 110    }
 111  
 112    /**
 113     * Read all locations data
 114     */
 115    function read_locs_data () {
 116      if ( ! class_exists ("location") ) {
 117        require ("location.pinc");
 118      }
 119      read_locs_data($this);
 120    }
 121    /**
 122     * search for a address 
 123     * return a array of possible addresses
 124     */
 125    function search_by_name(&$arr,&$user,$name) {
 126      if ( trim($name) == "" ) return;
 127  
 128      $q = "SELECT * from ". $user->dbconn->prefix ."addresses WHERE". $user->dbconn->Like ("f_name",$name,"m_name","l_name");
 129      $q .= " OR ". $user->dbconn->Like ("l_name",$name,"f_name","m_name");
 130      $q .= " order by l_name ";
 131      check_dbacl( $q, $user->id);
 132      $r = $user->dbconn->Exec($q);
 133      $n = $r->numrows();
 134      $a = 0;
 135      while ( $a < $n ) {
 136        $x = new tutos_address($user->dbconn);
 137        $x->read_result($r,$a);
 138        $arr[$x->id] = &$x;
 139  #      echo $x->getFullName() ."<br />";
 140        unset($x);
 141        $a++;
 142      }
 143      $r->free();
 144  
 145      return;
 146    }
 147    /**
 148     * Return the Short Name if useful
 149     */
 150    function getShortname() {
 151      global $lang;
 152      if ( trim($this->l_name) == "" ) {
 153        return sprintf($lang['AdrFormatShort1'],$this->f_name, $this->m_name);
 154      }
 155      return sprintf($lang['AdrFormatShort2'],substr($this->f_name,0,1), $this->l_name);
 156    }
 157    /**
 158     * Return the Long Name
 159     */
 160    function getFullname() {
 161      global $lang;
 162      if ( $this->m_name != "") {
 163        return sprintf($lang['AdrFormat1'],$this->f_name, $this->m_name ,$this->l_name);
 164      } else {
 165        return sprintf($lang['AdrFormat2'],$this->f_name, $this->l_name);
 166      }
 167    }
 168    /**
 169     * get the info as text
 170     */
 171    function getAsText (&$lang) {
 172      $r = "";
 173      $r .= format_asText($lang['AdrName'],$this->getFullName());
 174      $r .= format_asText($lang['AdrBirthday'],$this->birthday->getDate());
 175      return $r;
 176    }
 177    /**
 178     * Returns HTML for popup infos
 179     */
 180    function getPopInfo() {
 181      global $lang;
 182  
 183      $fn =myentities($this->getFullName());
 184      $fn =str_replace("'","\'",$fn);
 185  
 186      $this->read_locs_data();
 187      $info = "";
 188      $info .= "<html>";
 189      $info .= "<body>";
 190      $info .= "<table class=\"single\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">";
 191      $info .= "<tr><th colspan=\"2\">". $fn ."</th></tr>";
 192      $info .= "<tr><td valign=\"top\"><font size=\"-2\">". $lang['Phone'] .":</font></td><td><font size=\"-2\">";
 193  
 194      if ( isset($this->location) ) {
 195        @reset($this->location);
 196        $pre = "";
 197        while( list ($i,$f) = @each ($this->location)) {
 198          if ( $f->phone_1 != "" ) {
 199            $info .= $pre . myentities($f->phone_1);
 200            $pre = "<br />";
 201          }
 202          if ( $f->phone_2 != "" ) {
 203            $info .= $pre . myentities($f->phone_2);
 204            $pre = "<br />";
 205          }
 206        }
 207      }
 208      $info .= "</font>&nbsp;</td></tr>";
 209      $info .= "</table>";
 210      $info .= "</body>";
 211      $info .= "</html>";
 212      return $info;
 213    }
 214    /**
 215     * set the title
 216     */
 217    function setTitle($new) {
 218      $this->setStrField("title",$new,"AdrTitle");
 219    }
 220    /**
 221     * set the first name
 222     */
 223    function setFName($value) {
 224      $this->setStrField("f_name",$value,"AdrFirstName");
 225    }
 226    /**
 227     * set the last name
 228     */
 229    function setLName($value) {
 230      $this->setStrField("l_name",$value,"AdrLastName");
 231    }
 232    /**
 233     * set the middle name
 234     */
 235    function setMName($value) {
 236      $this->setStrField("m_name",$value,"AdrMiddleName");
 237    }
 238    /**
 239     * set the birthday date
 240     */
 241    function setBirthday(&$name) {
 242      $a = $this->birthday->getYYYYMMDD();
 243      $b = $name->getYYYYMMDD();
 244  
 245      if ( $a != $b ) {
 246        $this->modified[] = array ( "field" => "AdrBirthday", "old" => $a , "new" => $b );
 247        $this->birthday = $name;
 248      }
 249      return;
 250    }
 251    /**
 252     * save the objects data to the database
 253     */
 254    function save () {
 255      global $table,$current_user, $tutos;
 256  
 257      $msg = "";
 258      $q = new query($this->dbconn);
 259      $q->setTable($this->tablename);
 260      $q->addFV("birthday",$this->birthday,"DATE");
 261      $q->addFV("title",$this->title,"STRING",$table['address']['title'][size]);
 262      $q->addFV("f_name",$this->f_name,"STRING",$table['address']['f_name'][size]);
 263      $q->addFV("m_name",$this->m_name,"STRING",$table['address']['m_name'][size]);
 264      $q->addFV("l_name",$this->l_name,"STRING",$table['address']['l_name'][size]);
 265      $q->addFV("pic_id",$this->pic_id,"INT");
 266  
 267      if ( $this->id < 0 ) {
 268        $this->modified = array();
 269        if ( isset($this->newid) ) {
 270          $this->id = $this->newid;
 271          $q->addFV("id",$this->id,"");
 272        } else {
 273          /* Get an new ID */
 274          $this->id = $q->addFV("id",-1,"NEXTID");
 275          # Defaut Access Control
 276          $this->acl[$this->id]          = $tutos[modok];                   # if this one becomes a user he could change it
 277          acl_default($this,$current_user);
 278  
 279          $this->modified[] = array ( "field" => "created" ,
 280                                      "old" => $this->getType() ,
 281                                      "new" => $this->id,
 282                                      "obj_id" => $this->id
 283                                    );
 284        }
 285        $q->addFV("creator",$this->creator,"OBJ");
 286        $query = $q->getInsert();
 287      } else {
 288        $q->addWC("id",$this->id,"");
 289        $query = $q->getUpdate();
 290      }
 291  
 292  
 293      $this->dbconn->Exec($query);
 294      $msg .= parent::save();
 295  
 296      # The Owner can delete his picture
 297      if ( ($this->pic_file != -1) && ($this->pic_file->id > 0) ) {
 298        acl_raise($this->pic_file,$this->id,$tutos[delok]);
 299        $msg .= acl_save($this->pic_file);
 300      }
 301  
 302      return $msg;
 303    }
 304    /**
 305     * fill mailing list
 306     * this will work recursive and add all members
 307     * and subteam members to the given mailing list
 308     */
 309    function fill_maillist(&$ml) {
 310      $ml[$this->id] = &$this;
 311      return;
 312    }
 313    /**
 314     * Read all locations data and find the email adr.
 315     */
 316    function default_email() {
 317      if ( ! $this->rl2 ) {
 318        $this->read_locs_data();
 319      };
 320      $e = "";
 321  
 322      if ( isset($this->locall) ) {
 323        foreach($this->locall as $i => $f) {
 324          if ( $f->email_1 != "") {
 325            $e = $f->email_1;
 326            if ( $f->category == 2 ) {
 327              return $e;
 328            }
 329          } elseif ( $f->email_2 != "" ) {
 330            $e = $f->email_1;
 331            if ( $f->category == 2 ) {
 332              return $e;
 333            }
 334          }
 335        }
 336      }
 337      return $e;
 338    }
 339    /**
 340     * Return a URL to this address
 341     */
 342    function getURL() {
 343      return "address_show.php?id=". $this->id;
 344    }
 345    /**
 346     * Return a URL to modify this address
 347     */
 348    function getModURL() {
 349      return "address_new.php?id=". $this->id;
 350    }
 351    /**
 352     * Return a URL to delete this address
 353     */
 354    function getDelURL() {
 355      return "address_del.php?id=". $this->id;
 356    }
 357    /**
 358     * Return a link to this address
 359     */
 360    function getLink($text = "") {
 361      global $lang;
 362  
 363      if (empty($this->id)) return;
 364      if ($this->id == -1) {
 365        return $this->getFullName();
 366      }
 367      if ( empty($text) ) {
 368        $text = $this->getFullname();
 369      }
 370  
 371      if ( ! $this->see_ok() ) {
 372        return myentities($text);
 373      }
 374  
 375      $plus = $this->getPopInfo();
 376  
 377      return makelink($this->getURL(),myentities($text),sprintf($lang['SeeAddress'],$this->getFullname()),$plus);
 378    }
 379    /**
 380     * Return a Mail link to this address
 381     */
 382    function getMailLink($email = "" ,$text = "" ) {
 383      global $lang;
 384  
 385      if (empty($this->id)) return "";
 386  
 387      $fn = $this->getFullname();
 388  
 389      if ( $email == "" ) {
 390        $email = $this->default_email();
 391      }
 392      if ( $text == "" ) {
 393        $text = myentities($fn);
 394      }
 395  
 396      if (empty($email)) {
 397        return $this->getLink($text);
 398      } else {
 399        return asEmail($fn,$email,$fn);
 400      }
 401    }
 402    /**
 403     * Delete this address from the DB
 404     */
 405    function delete () {
 406      global $current_user;
 407  
 408      $msg = "";
 409      if ($this->gettype() == "address") {
 410        $this->read_locs_data();
 411  
 412        foreach($this->location as $f) {
 413          $msg .= $f->delete();
 414        }
 415  
 416        $q = "DELETE FROM ". $this->tablename ." WHERE id = ". $this->id;
 417        $r = $this->dbconn->Exec($q);
 418  
 419        if ( $this->pic_id > 0 ) {
 420          $q = "DELETE FROM ". $this->dbconn->prefix ."files WHERE id = ". $this->pic_id;
 421          $r = $this->dbconn->Exec($q);
 422        }
 423  
 424  #    $msg .= tutos_file::obj_delete($current_user,$this);
 425        $msg .= appointment::obj_delete($current_user,$this);
 426        $msg .= task::obj_delete($current_user,$this);
 427        $msg .= product::obj_delete($current_user,$this);
 428        $msg .= team::obj_delete($current_user,$this);
 429      }
 430      $msg .= parent::delete();
 431      return $msg;
 432    }
 433    /**
 434     * Checks if this person is a user of the system
 435     */
 436    function isUser () {
 437      if ( is_object($this->user) ) {
 438        return 1;
 439      } 
 440      $q = "SELECT a.* ,p.*,p.id as u_id FROM ". $this->dbconn->prefix ."addresses a, ". $this->dbconn->prefix ."people p WHERE a.id = ". $this->id ." AND a.id = p.adr_id";
 441      $r = $this->dbconn->Exec($q);
 442      $n = $r->numrows();
 443      if ( $n > 0 ) {
 444        $this->user = new tutos_user($this->dbconn);
 445        $this->user->read_result($r,0);
 446      }
 447      $r->free();
 448      return $n;
 449    }
 450    /**
 451     * Data of XML export
 452     */
 453    function exportXML_body ($only_ids = false) {
 454      $this->read_locs_data();
 455      $r = parent::exportXML_body();
 456      if (!$only_ids) {
 457      $r .=  "<title>". utf8_encode(htmlspecialchars($this->title)) ."</title>\n";
 458      $r .=  "<firstname>". utf8_encode(htmlspecialchars($this->f_name)) ."</firstname>\n";
 459      $r .=  "<middlename>". utf8_encode(htmlspecialchars($this->m_name)) ."</middlename>\n";
 460      $r .=  "<lastname>". utf8_encode(htmlspecialchars($this->l_name)) ."</lastname>\n";
 461      if ( $this->birthday->notime != 1 ) {
 462        $r .=  "<birthday>". $this->birthday->exportXML_body() ."</birthday>\n";
 463      }
 464      if ( isset($this->location) && (count($this->location) > 0) ) {
 465        foreach($this->location as $i => $f) {
 466          $r .= $f->exportXML_start();
 467            $r .= $f->exportXML_body($only_ids);
 468          $r .= $f->exportXML_end();
 469        }
 470      }
 471      }
 472      return $r;
 473    }
 474    /**
 475     * parse XML import
 476     */
 477    function parseXML ($fld,$data,$attrs) {
 478      parent::parseXML($fld,$data,$attrs);
 479      if ($fld == "title") {
 480        $this->setTitle($data);
 481      } else if ($fld == "firstname") {
 482        $this->setFName($data);
 483      } else if ($fld == "middlename") {
 484        $this->setMName($data);
 485      } else if ($fld == "lastname") {
 486        $this->setLName($data);
 487      } else if ($fld == "birthday") {
 488        $d = new DateTime($data);
 489        $this->setBirthday($d);
 490      }
 491      return;
 492    }
 493    /**
 494     * Return a vcard for this address
 495     */
 496    function getVcard() {
 497      $this->read_locs_data();
 498      $ical = "";
 499      $ical .= "BEGIN:VCARD\n";
 500      $ical .= "VERSION:3.0\n";
 501      $ical .= "UID:". $this->id ."\n";
 502      $ical .= "N:" . $this->l_name .";". $this->f_name ."\n";
 503      $ical .= "FN:" . $this->getFullName() ."\n";
 504      if ( isset($this->location) && (count($this->location) > 0) ) {
 505        foreach($this->location as $i => $f) {
 506          if ( $f->email_1 != "" ) {
 507            $ical .= "EMAIL;TYPE=INTERNET:" . $f->email_1 ."\n";
 508          }
 509          if ( $f->email_2 != "" ) {
 510            $ical .= "EMAIL;TYPE=INTERNET:" . $f->email_2 ."\n";
 511          }
 512          if ( $f->phone_1 != "" ) {
 513            if ( $f->category == 2 ) {
 514              $ical .= "TEL;TYPE=WORK:" . $f->phone_1 ."\n";
 515            } else {
 516              $ical .= "TEL;TYPE=HOME:" . $f->phone_1 ."\n";
 517            }
 518          }
 519          if ( $f->phone_2 != "" ) {
 520            if ( $f->category == 2 ) {
 521              $ical .= "TEL;TYPE=WORK:" . $f->phone_2 ."\n";
 522            } else {
 523              $ical .= "TEL;TYPE=HOME:" . $f->phone_2 ."\n";
 524            }
 525          }
 526          if ( $f->fax_1 != "" ) {
 527            if ( $f->category == 2 ) {
 528              $ical .= "TEL;TYPE=WORK,FAX:" . $f->fax_1 ."\n";
 529            } else {
 530              $ical .= "TEL;TYPE=HOME,FAX:" . $f->fax_1 ."\n";
 531            }
 532          }
 533          if ( ($f->company->id != -1) && ($f->company->name != "") ) {
 534            $ical .= "ORG:" . $f->company->name ."\n";
 535          }
 536        }
 537      }
 538      if ( $this->birthday->notime != 1 ) {
 539        $ical .= "BDAY:". $this->birthday->year ."-". $this->birthday->month ."-". $this->birthday->day ."\n";
 540      }
 541      $ical .= "END:VCARD\n";
 542      return $ical;
 543    }
 544    /**
 545     * get the type of object
 546     */
 547    function gettype () {
 548      return "address";
 549    }
 550    /**
 551     * get the type id of object
 552     */
 553    function gettypeid () {
 554      return useaddressbook;
 555    }
 556    /**
 557     * get the type id of object
 558     */
 559    function getHtmlIcon () {
 560      return 'addresses';
 561    }
 562    /* ---------------------------------------------------------------------------
 563     * The following methods are abstract factory functions for groups
 564     * which handle the membership list of an object
 565     * --------------------------------------------------------------------------- */
 566    /**
 567     * create a link to a select page
 568     */
 569    function getSelectLink (&$user,$text = "") {
 570      global $lang,$tutos;
 571      if ( ! $user->feature_ok(useaddressbook,PERM_SEL) ) {
 572        return;
 573      }
 574      return array( url => "address_select.php",
 575                    image => $user->layout->theme->getImage(tutos_address::getHtmlIcon(),'menu'),
 576                    text => ($text == "" ? $lang['Addresses'] : $text),
 577                    info => $lang['SearchForAdr'],
 578                    category => array("search","address")
 579                  );
 580    }
 581    /**
 582     * get the help index
 583     */
 584    function getHelpIndex () {
 585      global $lang;
 586  
 587      $r = "";
 588      $r .= "<h3>". makelink("help.php?p=glossary#address",$lang['Address'],$lang['Address']) ."</h3><ul>\n";
 589      $r .= "<li>". makelink("help.php?p=address_new",$lang["NewEntry"]."/". $lang["Modify"],$lang["NewEntry"]."/". $lang["Modify"]) ."</li>\n";
 590      $r .= "<li>". makelink("help.php?p=address_show",$lang["show"],$lang["show"]) ."</li>\n";
 591      $r .= "<li>". makelink("help.php?p=address_overview",$lang['AddressOverview'],$lang['AddressOverview'])."</li>\n";
 592      $r .= "</ul>\n";
 593      return $r;
 594    }
 595  }
 596  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]