/**
  * Constructor: ONLY TO BE CALLED like this: Page::newPage(classname,$id,$add) factory method!! 
  * 
  * @param $idOrContact integer|Contact the id of the contact, or the contact that is to be edited
  * @param $add boolean whether the contact is to be added or not (cannot be detected through {@link $id}, because a contact can be passed if an error occurs to preserve already inserted information)
  * @param $xsltProcessing boolean allows to deactivate XSLT processing if FALSE. default: TRUE
  * @global Options admin options
  */
 function PageContactEdit($idOrContact, $add = false, $enableXSLTProcessing = TRUE)
 {
     global $options;
     $this->counters = array();
     $this->add = $add;
     $this->enableXSLTProcessing = $enableXSLTProcessing;
     if ($idOrContact === null) {
         $this->contact = Contact::newContact();
         $this->add = TRUE;
     } elseif (is_numeric($idOrContact)) {
         $this->contact = Contact::newContact($idOrContact);
     } else {
         $this->contact =& $idOrContact;
     }
     // MANDATORY SECURITY CHECK IN CONSTRUCTOR OF EACH PAGE
     $rightsManager = RightsManager::getSingleton();
     if ($add) {
         if (!$rightsManager->currentUserIsAllowedTo('create')) {
             ErrorHandler::getSingleton()->standardError('PERMISSION_DENIED', basename($_SERVER['SCRIPT_NAME']));
         }
         $this->Page('Add new entry');
     } else {
         if (!$rightsManager->currentUserIsAllowedTo('edit', $this->contact)) {
             ErrorHandler::getSingleton()->standardError('PERMISSION_DENIED', basename($_SERVER['SCRIPT_NAME']));
         }
         $this->Page($this->contact->contact['firstname'] . ' ' . $this->contact->contact['lastname']);
     }
     $this->menu = new Navigation('edit-menu');
     // disable save when XSLT will be processed. XSLT files MUST provide their own save button.
     if (!($this->enableXSLTProcessing && !empty($this->contact->contact['xsltDisplayType']))) {
         $this->menu->addEntry('save', 'save', 'javascript:saveEntry();');
     }
     if (isset($this->contact->contact['id'])) {
         $this->menu->addEntry('cancel', 'cancel', '?id=' . $this->contact->contact['id']);
     } else {
         $this->menu->addEntry('cancel', 'cancel', Navigation::previousPageUrl());
     }
     if (!$this->add) {
         $rightsManager = RightsManager::getSingleton();
         if ($rightsManager->mayDeleteContact($this->contact)) {
             $this->menu->addEntry('delete', 'delete', 'javascript:deleteEntry(' . $this->contact->contact['id'] . ');');
             if ($_SESSION['user']->isAtLeast('admin') && $options->getOption('deleteTrashMode')) {
                 $this->menu->addEntry('trash', 'trash', '?mode=trash&id=' . $this->contact->contact['id']);
             }
         }
     }
     if ($_SESSION['user']->isAtLeast('admin')) {
         // no putting on changed list
         $this->menu->addEntry('adminsave', '[adminsave]', 'javascript:adminsaveEntry();');
     }
 }
 /**
  * Constructor
  * 
  * init superclass, create navigation, init variables {@link $contact}, {@link $cardMenu}, {@link $pluginMenu} and {@link $image}
  * if passed value is an integer, the contact with this id is loaded, else it is considered as the contact class itself
  * @param integer|Contact $idOrContact contact, contact id when adding
  * @param boolean $enableXsltProcessing Allows to disable XSLT processing (Default: TRUE)
  * @global Options used to determine options
  * @global PluginManager used to generate plugin menu
  */
 function PageContact($idOrContact, $enableXsltProcessing = TRUE)
 {
     global $options, $pluginManager, $errorHandler;
     $this->noXSLT = !$enableXsltProcessing;
     if (is_numeric($idOrContact)) {
         $this->contact = Contact::newContact($idOrContact);
     } else {
         $this->contact =& $idOrContact;
     }
     // MANDATORY SECURITY CHECK IN CONSTRUCTOR OF EACH PAGE
     $rightsManager = RightsManager::getSingleton();
     if (!$rightsManager->currentUserIsAllowedTo('view', $this->contact)) {
         $errorHandler->standardError('PERMISSION_DENIED', basename($_SERVER['SCRIPT_NAME']));
     }
     $this->Page($this->contact->contact['firstname'] . ' ' . $this->contact->contact['lastname']);
 }
 /**
  * Constructor: ONLY TO BE CALLED like this: Page::newPage(classname,$id,$add) factory method!! 
  * 
  * @param $idOrContact integer|Contact the id of the contact, or the contact that is to be edited
  * @param $add boolean whether the contact is to be added or not (cannot be detected through {@link $id}, because a contact can be passed if an error occurs to preserve already inserted information)
  * @global Options admin options
  */
 function PageProjectContactEdit($idOrContact, $add = false)
 {
     global $options;
     $this->counters = array();
     $this->add = $add;
     if ($idOrContact === null) {
         $this->contact = Contact::newContact();
         $this->add = TRUE;
     } elseif (is_numeric($idOrContact)) {
         $this->contact = Contact::newContact($idOrContact);
     } else {
         $this->contact =& $idOrContact;
     }
     if ($add) {
         $this->Page('Add new entry');
     } else {
         $this->Page('Edit entry for <span>' . $this->contact->contact['firstname'] . ' ' . $this->contact->contact['lastname'] . '</span>');
     }
     $this->menu = new Navigation('edit-menu');
     $this->menu->addEntry('save', 'save', 'javascript:saveEntry();');
     if (isset($this->contact->contact['id'])) {
         $this->menu->addEntry('cancel', 'cancel', '?id=' . $this->contact->contact['id']);
     } else {
         $this->menu->addEntry('cancel', 'cancel', Navigation::mainPageUrl());
     }
     if (!$this->add) {
         $rightsManager = RightsManager::getSingleton();
         if ($rightsManager->mayDeleteContact($this->contact)) {
             $this->menu->addEntry('delete', 'delete', 'javascript:deleteEntry(' . $this->contact->contact['id'] . ');');
             if ($_SESSION['user']->isAtLeast('admin') && $options->getOption('deleteTrashMode')) {
                 $this->menu->addEntry('trash', 'trash', '?mode=trash&amp;id=' . $this->contact->contact['id']);
             }
         }
     }
     if ($_SESSION['user']->isAtLeast('admin')) {
         // no putting on changed list
         $this->menu->addEntry('adminsave', 'adminsave', 'javascript:adminsaveEntry();');
     }
 }
 /**
  * create the content of recently changed
  * @return string html-content
  * @global Options determine how many days after change the contact should still be shown
  * @param boolean $compact whether list should be displayed with imported link and user who changed contact
  */
 function innerCreate()
 {
     global $db, $CONFIG_DB_PREFIX, $CONFIG_ADMIN_REQUEST_INTERFACE, $CONFIG_ADMIN_REQUEST_BREAKS;
     $db->query("SELECT * FROM `{$CONFIG_DB_PREFIX}AdministrativeRequests` AS request WHERE dateProcessed IS NULL OR ( DATE_ADD(dateProcessed, INTERVAL 14 DAY) >= NOW() )", 'AdministrativeRequest');
     //. TABLE_PROPERTIES . " AS prop
     //WHERE contact.id=prop.id AND prop.label=" . $db->escape($this->featureLabel) . '
     //ORDER BY prop.value ' . ($this->ascending ? 'ASC' : 'DESC') . ($this->limit > 0 ? ' LIMIT '.$this->limit : ''));
     $fields = array('contactId', 'dateAdded', 'requesterId', 'dateProcessed', 'whoProcessedId');
     foreach ($CONFIG_ADMIN_REQUEST_INTERFACE as $k => $v) {
         if (substr($k, 0, 4) != 'html' && $k != 'submit') {
             // not for DB!
             $fields[] = $k;
         }
     }
     $data = array();
     $i = 0;
     while ($c = $db->next('AdministrativeRequest')) {
         $data[$i] = $c;
         if (empty($data[$i]['dateProcessed'])) {
             $id = $data[$i]['requestId'];
             $data[$i]['dateProcessed'] = "<a href='todo?mode=done&id={$id}'>set done</a>";
         }
         if (!empty($data[$i]['whoProcessedId'])) {
             $contact = Contact::newContact($data[$i]['whoProcessedId']);
             $data[$i]['whoProcessedId'] = '<a href="../contact/contact.php?id=' . $contact->contact['id'] . '">' . $contact->contact['lastname'] . (!empty($contact->contact['firstname']) ? ', ' . $contact->contact['firstname'] : '') . '</a>';
         }
         $contact = Contact::newContact($data[$i]['contactId']);
         $data[$i]['contactId'] = '<a href="../contact/contact.php?id=' . $contact->contact['id'] . '">' . $contact->contact['lastname'] . (!empty($contact->contact['firstname']) ? ', ' . $contact->contact['firstname'] : '') . '</a>';
         $contact = Contact::newContact($data[$i]['requesterId']);
         $data[$i]['requesterId'] = '<a href="../contact/contact.php?id=' . $contact->contact['id'] . '">' . $contact->contact['lastname'] . (!empty($contact->contact['firstname']) ? ', ' . $contact->contact['firstname'] : '') . '</a>';
         $i++;
     }
     $cont = '<style>.parr-list { margin: 20px auto 20px auto; width: 90%; } .parr-list th { border: 1px solid; } .parr-list td { border: 1px solid  #AAA; } td.parr-list-tdblank { border: none; } </style>';
     $tGen = new TableGenerator('parr-list', $fields, $CONFIG_ADMIN_REQUEST_BREAKS);
     $cont .= $tGen->generateTable($data, $fields);
     $cont .= '<div><a href="' . Navigation::previousPageUrl() . '">return</a></div><br>';
     return $cont;
 }
 *  Map PLUGIN for THE ADDRESS BOOK
 *************************************************************
* @package plugins
* @author Thomas Katzlberger
*/
chdir('../../');
require_once 'lib/init.php';
require_once 'Contact.class.php';
require_once 'DB.class.php';
require_once 'StringHelper.class.php';
require_once 'ErrorHandler.class.php';
if (isset($_GET['id'])) {
    $address_id = StringHelper::cleanGPC($_GET['id']);
}
if (isset($_GET['cid'])) {
    $contact = Contact::newContact(intval(StringHelper::cleanGPC($_GET['cid'])));
}
// use for the google-bubble?
// search correct address in value group ... not very efficient
$adds = $contact->getValueGroup('addresses');
foreach ($adds as $a) {
    if ($a['refid'] == $address_id) {
        $add =& $a;
        break;
    }
}
if (!isset($add)) {
    $errorHandler->error('argVal', 'The address with id=' . $address_id . ' does not exist');
}
$errorMessage = 'Unable to map this address. The address may not be included in any geocoder currently available here, or it is simply misspelled. Sorry!';
// Cache Geocode ... currently not available, needs API key
 *  contact/media.php
 *  Returns a media of a contact (currently only images).
 *
 *************************************************************/
// If a whitespace is output from header files
ob_start();
chdir('..');
require_once 'lib/init.php';
require_once 'Contact.class.php';
require_once 'RightsManager.class.php';
require_once 'ErrorHandler.class.php';
// kill whitespaces
ob_end_clean();
$rightsManager = RightsManager::getSingleton();
if (!isset($_GET['id'])) {
    $_GET['id'] = '';
}
$contact = Contact::newContact(intval($_GET['id']));
if (!$rightsManager->mayViewContact($contact)) {
    $errorHandler->standardError('PERMISSION_DENIED', basename($_SERVER['SCRIPT_NAME']));
}
$length = 0;
$mimeType = '';
$media =& $contact->getMedia('pictureData', $mimeType, $length);
if ($media == null) {
    $errorHandler->standardError('PERMISSION_DENIED', basename($_SERVER['SCRIPT_NAME']));
}
header('Content-Type: ' . $mimeType);
header('Content-Length: ' . $length);
echo $media;
exit;
 *
 *************************************************************/
chdir('../../');
require_once 'lib/init.php';
require_once 'ContactImportExport.class.php';
// logged in?
$rightsManager = RightsManager::getSingleton();
if (!isset($_GET['mode'])) {
    $_GET['mode'] = 'default';
}
if (!isset($_GET['id'])) {
    // invalid
    $errorHandler->error('invArg', 'Contact id missing.', basename($_SERVER['SCRIPT_NAME']));
}
// export whom?
$contact = Contact::newContact($_GET['id']);
// allowed to view?
if (!$rightsManager->mayViewContact($contact)) {
    $errorHandler->standardError('PERMISSION_DENIED', basename($_SERVER['SCRIPT_NAME']));
}
// ** EXPORT FORMATS **
switch ($_GET['format']) {
    // How about this? http://www.oasis-open.org/committees/ciq/ciq.html#6
    default:
        /* SEE: http://vcardmaker.wackomenace.co.uk/, http://tools.ietf.org/html/rfc2426
         * There is still lots of info missing: Occupation -> TITLE:, Company -> ?, Department
         * Please post improvements to: http://sourceforge.net/tracker/?group_id=172286&atid=861164 as attachment!!
         * Or to the developer forums at: http://sourceforge.net/forum/forum.php?forum_id=590644
         */
    /* SEE: http://vcardmaker.wackomenace.co.uk/, http://tools.ietf.org/html/rfc2426
     * There is still lots of info missing: Occupation -> TITLE:, Company -> ?, Department
 /**
  * create form to create a new user (only used by admin)
  * @global ErrorHandler used to catch errors that occured
  * @return string html-content
  */
 function createCreateUser()
 {
     global $errorHandler;
     $cont = '<div class="login-form">';
     $cont .= '<img class="tab-title" src="../images/banner.png" />';
     switch ($this->flag) {
         case 'ok':
             $cont .= '<div class="login-message">Successfully added user</div>';
             break;
         case 'error':
             ($err = $errorHandler->getLastError('register')) || ($err = $errorHandler->getLastError('login'));
             $cont .= '<div class="login-error">' . $err['cause'] . '</div>';
             break;
         default:
             if (!isset($_GET['id'])) {
                 $_GET['id'] = '';
             }
             $contact = Contact::newContact(intval($_GET['id']));
             $mails = $contact->getValueGroup('email');
             if ($contact->isUser()) {
                 $cont .= '<div class="login-error">This contact is already a user</div>';
                 break;
             }
             if (count($mails) <= 0) {
                 $cont .= '<div class="login-error">This contact has no email-address</div>';
                 break;
             }
             $cont .= '<div class="login-message">Please choose the email address to use and enter a password.</div>';
             $cont .= '<form action="../user/register.php?mode=cuser&amp;id=' . $contact->contact['id'] . '" method="post">';
             $cont .= '<div><label class="register-label" for="email">email</label></div>';
             $cont .= '<div><select name="email" id="email">';
             foreach ($mails as $m) {
                 $cont .= '<option>' . $m['value'] . '</option>';
             }
             $cont .= '</select></div>';
             $cont .= '<br/><div><label class="register-label" for="password1">password</label>';
             $cont .= '<input class="register-input" type="password" name="password1" id="password1" /></div>';
             $cont .= '<br/><div><label class="register-label" for="password2">repeat</label>';
             $cont .= '<input class="register-input" type="password" name="password2" id="password2" /></div>';
             $cont .= '<br/><div><input class="register-input" type="submit" value="ok" /></div>';
             $cont .= '</form>';
     }
     $cont .= '<br/><div><a href="../contact/contact.php?id=' . $_GET['id'] . '">return</a></div>';
     $cont .= '</div>';
     return $cont;
 }
 /**
  * Decode a contact as vCard version 3.0.
  * @param string $vCardString string holding the vCard text
  * @return Contact $contact already stored in database or NULL on error
  */
 function vCardImport($vCardString)
 {
     global $errorHandler;
     require_once 'lib/vcard/vcardclass.inc';
     $vc = new VCARD('3.0');
     $vc->setvCard($vCardString);
     if ($vc->lasterror_num != 0) {
         $errorHandler->error('import', $vc->lasterror_msg, basename($_SERVER['SCRIPT_NAME']));
         return null;
     }
     $data['contact']['lastname'] = $vc->getName('LAST');
     $data['contact']['firstname'] = $vc->getName('FIRST');
     $data['contact']['middlename'] = $vc->getName('MIDDLE');
     $data['contact']['namePrefix'] = $vc->getName('PREF');
     $data['contact']['nameSuffix'] = $vc->getName('SUFF');
     $data['contact']['nickname'] = $vc->getNickName();
     // ADDRESSES
     list($key, $a) = each($vc->getAdr('CITY', 'WORK', 'OR'));
     // this retrieval is strannnnge
     if ($a != null) {
         $data['address'][0]['type'] = 'work';
         list($key, $a) = each($vc->getAdr('STREET', 'WORK', 'OR'));
         $data['address'][0]['line1'] = $a;
         list($key, $a) = each($vc->getAdr('POBOX', 'WORK', 'OR'));
         $data['address'][0]['line2'] = $a;
         list($key, $a) = each($vc->getAdr('CITY', 'WORK', 'OR'));
         $data['address'][0]['city'] = $a;
         list($key, $a) = each($vc->getAdr('PROVINCE', 'WORK', 'OR'));
         $data['address'][0]['state'] = $a;
         list($key, $a) = each($vc->getAdr('POSTAL', 'WORK', 'OR'));
         $data['address'][0]['zip'] = $a;
         /*     list($key,$a) = each($vc->getAdr('COUNTRY','WORK','OR'));*/
         //$data['address'][0]['country'] = $a['COUNTRY']; // decode how?
     }
     list($key, $a) = each($vc->getAdr('CITY', 'HOME', 'OR'));
     if ($a != null) {
         $data['address'][1]['type'] = 'home';
         list($key, $a) = each($vc->getAdr('STREET', 'HOME', 'OR'));
         $data['address'][1]['line1'] = $a;
         list($key, $a) = each($vc->getAdr('POBOX', 'HOME', 'OR'));
         $data['address'][1]['line2'] = $a;
         list($key, $a) = each($vc->getAdr('CITY', 'HOME', 'OR'));
         $data['address'][1]['city'] = $a;
         list($key, $a) = each($vc->getAdr('PROVINCE', 'HOME', 'OR'));
         $data['address'][1]['state'] = $a;
         list($key, $a) = each($vc->getAdr('POSTAL', 'HOME', 'OR'));
         $data['address'][1]['zip'] = $a;
         /*     list($key,$a) = each($vc->getAdr('COUNTRY','HOME','OR'));*/
         //$data['address'][1]['country'] = $a['COUNTRY']; // decode how?
     }
     $i = 0;
     // other data email OR www OR other OR chat OR phone;
     // 5. TELECOMMUNICATIONS ADDRESSING TYPES methods:
     $x = $vc->getTel('WORK');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'phone';
         $data['blank'][$i]['label'] = 'work';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getTel('HOME');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'phone';
         $data['blank'][$i]['label'] = 'home';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getTel('CELL');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'phone';
         $data['blank'][$i]['label'] = 'cell';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getTel('FAX');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'phone';
         $data['blank'][$i]['label'] = 'fax';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getTel('PAGER');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'phone';
         $data['blank'][$i]['label'] = 'pager';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getTel('VIDEO');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'phone';
         $data['blank'][$i]['label'] = 'video';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     // delivers only one result!!
     list($key, $x) = each($vc->getEmail('INTERNET', 'OR'));
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'email';
         $data['blank'][$i]['label'] = '';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     // 7. ORGANIZATIONAL TYPES methods:
     $x = $vc->getTitle();
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'other';
         $data['blank'][$i]['label'] = 'Job Title';
         $data['blank'][$i]['value'] = $vc->getTitle();
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getRole();
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'other';
         $data['blank'][$i]['label'] = 'Role';
         $data['blank'][$i]['value'] = $vc->getRole();
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getOrg();
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'other';
         $data['blank'][$i]['label'] = 'Organization';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     // cannot go into OU of SSL_CA bacause may not be admin importer here
     $x = $vc->getOrg('ORGUNIT');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'other';
         $data['blank'][$i]['label'] = 'Organizational Unit';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     // what is ORGUNITS ???
     // 8. EXPLANATORY TYPES methods:
     $x = $vc->getUrl('WORK');
     $y = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'www';
         $data['blank'][$i]['label'] = 'Work';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     $x = $vc->getUrl('HOME');
     $x = ContactImportExport::vCardUnEscape($x);
     if (!empty($x)) {
         $data['blank'][$i]['type'] = 'www';
         $data['blank'][$i]['label'] = 'Home';
         $data['blank'][$i]['value'] = $x;
         $data['blank'][$i++]['visibility'] = 'visible';
     }
     //$data['contact']['notes'] = $vc->getNote();
     // Attach picture ...
     $url = $vc->getBinary('PHOTO', 'URL');
     if (!empty($url)) {
         $data['contact']['pictureURL'] = $url;
     }
     //import_change_encoding(&$data);
     // save it to the DB
     $contact = Contact::newContact();
     // curretly this must go before save! When we have the Media class it may need to go after save (?)
     $pic = $vc->getBinary('PHOTO', 'JPEG');
     if (!empty($pic) && $options->getOption('picAllowUpload')) {
         $binaryPicture = base64_decode($pic);
         //  future:  $contact->setMedia('pictureData');
         $contact->setMedia('pictureData', 'image/jpeg', $binaryPicture);
     }
     $contact->saveContactFromArray($data);
     $errorHandler->success('Imported: ' . $data['contact']['firstname'] . ' ' . $data['contact']['lastname'], basename($_SERVER['SCRIPT_NAME']));
     return $contact;
 }
 /**
  * creates a contact from the passed data
  * @param array $r data from database
  */
 function processQueryResult($r)
 {
     $this->contacts[] = Contact::newContact($r);
 }