X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvcard.inc.php;h=778cd1f22d0dfd9fad1656f56f16b601c7a6bf0d;hb=c56a253e5a51c7953be1224225e1b1190f8f1c1d;hp=2a1402a4579494f8893c3915a1dec645e132146e;hpb=0073747ac81cc9cff9e43847eb008f0e815255f0;p=platal.git diff --git a/include/vcard.inc.php b/include/vcard.inc.php index 2a1402a..778cd1f 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -56,8 +56,9 @@ class VCard extends PlVCard protected function buildEntry($pf) { global $globals; + $pf = $pf['value']; - $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames, null, null, $pf->nickname); + $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames(), null, null, $pf->nickname); $user = $pf->owner(); @@ -67,8 +68,7 @@ class VCard extends PlVCard $freetext .= "\n" . $this->freetext; } $entry->set('NOTE', $freetext); - // Mobile - if (!empty($pf->mobile)) { + if ($pf->mobile) { $entry->addTel(null, $pf->mobile, false, true, true, false, true, true); } @@ -85,42 +85,52 @@ class VCard extends PlVCard // Homes $adrs = $pf->iterAddresses(Profile::ADDRESS_PERSO); while ($adr = $adrs->next()) { - // TODO : find a way to fetch only the "street" part of the address - $group = $entry->addHome($adr['text'], null, null, $adr['postalCode'], - $adr['locality'], $adr['administrativeArea'], $adr['country'], - $adr['current'], $adr['mail'], $adr['mail']); - if (!empty($adr['fixed_tel'])) { - $entry->addTel($group, $adr['fixed_tel'], false, true, true, false, false, $adr['current'] && empty($pf->mobile)); + if (!$adr->postalCode || !$adr->locality || !$adr->country) { + $group = $entry->addHome($adr->text, null, null, null, + null, $adr->administrativeArea, null, + $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail')); + } else { + // TODO : find a way to fetch only the "street" part of the address + $group = $entry->addHome($adr->text, null, null, $adr->postalCode, + $adr->locality, $adr->administrativeArea, $adr->country, + $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail')); } - if (!empty($adr['fax_tel'])) { - $entry->addTel($group, $adr['fax_tel'], true, false, false, false, false, false); + foreach ($adr->phones() as $phone) { + if ($phone->linkType() == Phone::TYPE_FIXED) { + $entry->addTel($group, $phone->display, false, true, true, false, false, + $adr->hasFlag('current') && empty($pf->mobile)); + } else if ($phone->linkType() == Phone::TYPE_FAX) { + $entry->addTel($group, $phone->display, true, false, false, false, false, false); + } } } // Pro $adrs = $pf->iterAddresses(Profile::ADDRESS_PRO); while ($adr = $adrs->next()) { - // TODO : link address to company - $group = $entry->addWork(null, null, null, null, - $adr['text'], null, null, $adr['postalCode'], - $adr['locality'], $adr['administrativeArea'], $adr['country']); - if (!empty($adr['fixed_tel'])) { - $entry->addTel($group, $adr['fixed_tel']); - } - if (!empty($adr['fax_tel'])) { - $entry->addTel($group, $adr['display_tel'], true); + if (!$adr->postalCode || !$adr->locality || !$adr->country) { + $group = $entry->addWork(null, null, null, null, + $adr->text, null, null, null, + null, $adr->administrativeArea, null); + } else { + // TODO : link address to company + $group = $entry->addWork(null, null, null, null, + $adr->text, null, null, $adr->postalCode, + $adr->locality, $adr->administrativeArea, $adr->country); } - /* TODO : fetch email for jobs, too - if (!empty($pro['email'])) { - $entry->addMail($group, $pro['email']); + foreach ($adr->phones() as $phone) { + if ($phone->linkType() == Phone::TYPE_FIXED) { + $entry->addTel($group, $phone->display); + } else if ($phone->linkType() == Phone::TYPE_FAX) { + $entry->addTel($group, $phone->display, true); } - */ + } } // Melix if (!is_null($user)) { $alias = $user->emailAlias(); - if (!is_null($alias)) { + if (!is_null($alias) && $pf->alias_pub == 'pub') { $entry->addMail(null, $alias); } } @@ -146,7 +156,7 @@ class VCard extends PlVCard foreach ($binets as $bid) { $bns[$bid] = $bn[$bid]; } - $entry->set('X-BINETS', join(', ', $bid)); + $entry->set('X-BINETS', join(', ', $bns)); } if (!empty($pf->section)) { $sections = DirEnum::getOptions(DirEnum::SECTIONS); @@ -157,8 +167,8 @@ class VCard extends PlVCard if ($this->photos) { $res = XDB::query( "SELECT attach, attachmime - FROM photo AS p - WHERE p.uid = {?}", $pf->id()); + FROM profile_photos AS p + WHERE p.pid = {?}", $pf->id()); if ($res->numRows()) { list($data, $type) = $res->fetchOneRow(); $entry->setPhoto($data, strtoupper($type));