Update to use new schema

This commit is contained in:
Miles Lott 2001-05-23 20:50:35 +00:00
parent 93db684a70
commit 956c6d97b0

View File

@ -65,26 +65,26 @@
'fn' => 'cn', // 'prefix given middle family suffix' 'fn' => 'cn', // 'prefix given middle family suffix'
'n_given' => 'givenname', // firstname 'n_given' => 'givenname', // firstname
'n_family' => 'sn', // lastname 'n_family' => 'sn', // lastname
'n_middle' => 'middlename', 'n_middle' => 'phpgwmiddlename',
'n_prefix' => 'prefix', 'n_prefix' => 'phpgwprefix',
'n_suffix' => 'suffix', 'n_suffix' => 'phpgwsuffix',
'sound' => 'audio', 'sound' => 'phpgwaudio',
'bday' => 'birthday', 'bday' => 'phpgwbirthday',
'note' => 'description', 'note' => 'description',
'tz' => 'tz', 'tz' => 'phpgwtz',
'geo' => 'geo', 'geo' => 'phpgwgeo',
'url' => 'url', 'url' => 'phpgwurl',
'pubkey' => 'publickey', 'pubkey' => 'phpgwpublickey',
'org_name' => 'o', // company 'org_name' => 'o', // company
'org_unit' => 'ou', // division 'org_unit' => 'ou', // division
'title' => 'title', 'title' => 'title',
'adr_one_street' => 'streetaddress', 'adr_one_street' => 'street',
'adr_one_locality' => 'locality', 'adr_one_locality' => 'l',
'adr_one_region' => 'st', 'adr_one_region' => 'st',
'adr_one_postalcode' => 'postalcode', 'adr_one_postalcode' => 'postalcode',
'adr_one_countryname' => 'countryname', 'adr_one_countryname' => 'co',
'adr_one_type' => 'phpgwadronetype', // address is domestic/intl/postal/parcel/work/home 'adr_one_type' => 'phpgwadronetype', // address is domestic/intl/postal/parcel/work/home
'label' => 'phpgwaddresslabel', // address label 'label' => 'phpgwaddresslabel', // address label
@ -97,30 +97,30 @@
'tel_work' => 'telephonenumber', 'tel_work' => 'telephonenumber',
'tel_home' => 'homephone', 'tel_home' => 'homephone',
'tel_voice' => 'voicetelephonenumber', 'tel_voice' => 'phpgwvoicetelephonenumber',
'tel_fax' => 'facsimiletelephonenumber', 'tel_fax' => 'facsimiletelephonenumber',
'tel_msg' => 'msgtelephonenumber', 'tel_msg' => 'phpgwmsgtelephonenumber',
'tel_cell' => 'cellphone', 'tel_cell' => 'phpgwcelltelephonenumber',
'tel_pager' => 'pagertelephonenumber', 'tel_pager' => 'phpgwpagertelephonenumber',
'tel_bbs' => 'bbstelephonenumber', 'tel_bbs' => 'phpgwbbstelephonenumber',
'tel_modem' => 'modemtelephonenumber', 'tel_modem' => 'phpgwmodemtelephonenumber',
'tel_car' => 'mobiletelephonenumber', 'tel_car' => 'phpgwmobiletelephonenumber',
'tel_isdn' => 'isdnphonenumber', 'tel_isdn' => 'phpgwisdnphonenumber',
'tel_video' => 'videophonenumber', 'tel_video' => 'phpgwvideophonenumber',
'tel_prefer' => 'preferphone', // home, work, voice, etc 'tel_prefer' => 'phpgwpreferphone', // home, work, voice, etc
'email' => 'mail', 'email' => 'mail',
'email_type' => 'mailtype', //'INTERNET','CompuServe',etc... 'email_type' => 'phpgwmailtype', //'INTERNET','CompuServe',etc...
'email_home' => 'mailhome', 'email_home' => 'phpgwmailhome',
'email_home_type' => 'mailhometype' //'INTERNET','CompuServe',etc... 'email_home_type' => 'phpgwmailhometype' //'INTERNET','CompuServe',etc...
); );
$this->non_contact_fields = array( $this->non_contact_fields = array(
'id' => 'uidnumber', 'id' => 'uidnumber',
'lid' => 'uid', 'lid' => 'uid',
'tid' => 'phpgwtypeid', 'tid' => 'phpgwcontacttypeid',
'cat_id' => 'phpgwcatid', 'cat_id' => 'phpgwcontactcatid',
'access' => 'phpgwaccess', 'access' => 'phpgwcontactaccess',
'owner' => 'phpgwowner' 'owner' => 'phpgwcontactowner'
); );
/* Used to flag an address as being: /* Used to flag an address as being:
@ -192,11 +192,10 @@
$return_fields[0]['id'] = $ldap_fields[0]['uidnumber'][0]; $return_fields[0]['id'] = $ldap_fields[0]['uidnumber'][0];
$return_fields[0]['lid'] = $ldap_fields[0]['uid'][0]; $return_fields[0]['lid'] = $ldap_fields[0]['uid'][0];
$return_fields[0]['tid'] = $ldap_fields[0]['phpgwtypeid'][0]; $return_fields[0]['tid'] = $ldap_fields[0]['phpgwcontacttypeid'][0];
$return_fields[0]['owner'] = $ldap_fields[0]['phpgwowner'][0]; $return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0];
$return_fields[0]['access'] = $ldap_fields[0]['phpgwaccess'][0]; $return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcatid'][0]; $return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array') if (gettype($stock_fieldnames) == 'array')
{ {
while(list($name,$value)=each($stock_fieldnames)) while(list($name,$value)=each($stock_fieldnames))
@ -263,10 +262,10 @@
$return_fields[0]['id'] = $ldap_fields[0]['uidnumber'][0]; $return_fields[0]['id'] = $ldap_fields[0]['uidnumber'][0];
$return_fields[0]['lid'] = $ldap_fields[0]['uid'][0]; $return_fields[0]['lid'] = $ldap_fields[0]['uid'][0];
$return_fields[0]['tid'] = $ldap_fields[0]['phpgwtypeid'][0]; $return_fields[0]['tid'] = $ldap_fields[0]['phpgwcontacttypeid'][0];
$return_fields[0]['owner'] = $ldap_fields[0]['phpgwowner'][0]; $return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0];
$return_fields[0]['access'] = $ldap_fields[0]['phpgwaccess'][0]; $return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcatid'][0]; $return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array') if (gettype($stock_fieldnames) == 'array')
{ {
@ -351,18 +350,18 @@
} }
else else
{ {
$filterfields += array('phpgwtypeid' => 'n'); $filterfields += array('phpgwcontacttypeid' => 'n');
if ($DEBUG) { echo "<br>DEBUG - Filter strings: #phpgwtypeid=n#"; } if ($DEBUG) { echo "<br>DEBUG - Filter strings: #phpgwtypeid=n#"; }
} }
if (is_array($this->grants)) if (is_array($this->grants))
{ {
$filterfields += array('phpgwaccess' => 'public'); $filterfields += array('phpgwcontactaccess' => 'public');
$grants = $this->grants; $grants = $this->grants;
while (list($user) = each($grants)) while (list($user) = each($grants))
{ {
if ($DEBUG) { echo "<br>DEBUG - Grant from owner: ".$user; } if ($DEBUG) { echo "<br>DEBUG - Grant from owner: ".$user; }
$filterfields += array('phpgwowner' => $user); $filterfields += array('phpgwcontactowner' => $user);
} }
} }
//if ($DEBUG) { //if ($DEBUG) {
@ -441,7 +440,7 @@
} }
else else
{ {
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwowner=*'); $sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwcontactowner=*');
$ldap_fields = ldap_get_entries($this->ldap, $sri); $ldap_fields = ldap_get_entries($this->ldap, $sri);
$this->total_records = ldap_count_entries($this->ldap, $sri); $this->total_records = ldap_count_entries($this->ldap, $sri);
@ -483,15 +482,21 @@
if ($i<$this->total_records && $ldap_fields[$i]['uid'][0]) if ($i<$this->total_records && $ldap_fields[$i]['uid'][0])
{ {
//echo '<br>j:'.$j; //echo '<br>j:'.$j;
//echo '<br>i:'.$i;
// unique id, lid for group/account records, // unique id, lid for group/account records,
// type id (g/u) for groups/accounts, and // type id (g/u) for groups/accounts, and
// id of owner/parent for the record // id of owner/parent for the record
$return_fields[$j]['id'] = $ldap_fields[$i]['uidnumber'][0]; $return_fields[$j]['id'] = $ldap_fields[$i]['uidnumber'][0];
$return_fields[$j]['lid'] = $ldap_fields[$i]['uid'][0]; $return_fields[$j]['lid'] = $ldap_fields[$i]['uid'][0];
$return_fields[$j]['tid'] = $ldap_fields[$i]['phpgwtypeid'][0]; $return_fields[$j]['tid'] = $ldap_fields[$i]['phpgwcontacttypeid'][0];
$return_fields[$j]['owner'] = $ldap_fields[$i]['phpgwowner'][0]; $return_fields[$j]['owner'] = $ldap_fields[$i]['phpgwcontactowner'][0];
$return_fields[$j]['access'] = $ldap_fields[$i]['phpgwaccess'][0]; $return_fields[$j]['access'] = $ldap_fields[$i]['phpgwcontactaccess'][0];
$return_fields[$j]['cat_id'] = $ldap_fields[$i]['phpgwcatid'][0]; $return_fields[$j]['cat_id'] = $ldap_fields[$i]['phpgwcontactcatId'][0];
//echo '<br>uidnumber: "'.$ldap_fields[$i]['uidnumber'][0].'"';
//echo '<br>tid: "'.$ldap_fields[$i]['phpgwcontacttypeid'][0].'"';
//echo '<br>owner: "'.$ldap_fields[$i]['phpgwcontactowner'][0].'"';
//echo '<br>access: "'.$ldap_fields[$i]['phpgwcontactaccess'][0].'"';
//echo '<br>catid: "'.$ldap_fields[$i]['phpgwcontactcatid'][0].'"';
if (gettype($stock_fieldnames) == 'array') if (gettype($stock_fieldnames) == 'array')
{ {
@ -552,29 +557,35 @@
if (gettype($stock_fieldnames) == 'array') if (gettype($stock_fieldnames) == 'array')
{ {
while(list($name,$value)=each($stock_fieldnames)) while(list($name,$value)=each($stock_fieldnames))
{
if ($stock_fields[$name] != '')
{ {
$ldap_fields[$value] = $stock_fields[$name]; $ldap_fields[$value] = $stock_fields[$name];
} }
} }
}
$time = gettimeofday(); $time = gettimeofday();
$ldap_fields['uid'] = time().$time['usec'].':'.$ldap_fields['givenname']; $ldap_fields['uid'] = time().$time['usec'].':'.$ldap_fields['givenname'];
$dn = 'uid=' . $ldap_fields['uid'].',' . $phpgw_info['server']['ldap_contact_context']; $dn = 'uid=' . $ldap_fields['uid'].',' . $phpgw_info['server']['ldap_contact_context'];
$ldap_fields['phpgwtypeid'] = $tid; $ldap_fields['phpgwcontacttypeid'] = $tid;
$ldap_fields['phpgwowner'] = $owner; $ldap_fields['phpgwcontactowner'] = $owner;
$ldap_fields['phpgwaccess'] = $access; $ldap_fields['phpgwcontactaccess'] = $access;
$ldap_fields['phpgwcatid'] = $cat_id; $ldap_fields['phpgwcontactcatid'] = $cat_id;
$ldap_fields['uidnumber'] = $this->nextid; $ldap_fields['uidnumber'] = $this->nextid;
$ldap_fields['objectclass'][0] = 'person'; //$ldap_fields['objectclass'][0] = 'person';
$ldap_fields['objectclass'][1] = 'organizationalPerson'; $ldap_fields['objectclass'][0] = 'organizationalPerson';
$ldap_fields['objectclass'][2] = 'inetOrgPerson'; $ldap_fields['objectclass'][1] = 'inetOrgPerson';
$ldap_fields['objectclass'][3] = 'phpgwContact'; $ldap_fields['objectclass'][2] = 'phpgwContact';
/* /*
@reset($ldap_fields);
while (list($name,$value) = each($ldap_fields) ) { while (list($name,$value) = each($ldap_fields) ) {
if ($value)
{
echo '<br>fieldname ="'.$name.'", value ="'.$value.'"'; echo '<br>fieldname ="'.$name.'", value ="'.$value.'"';
} }
}
exit; exit;
*/ */
$err = ldap_add($this->ldap, $dn, $ldap_fields); $err = ldap_add($this->ldap, $dn, $ldap_fields);
@ -659,79 +670,90 @@
// Verify objectclasses are there // Verify objectclasses are there
if (empty($ldap_fields[0]['objectclass'])) if (empty($ldap_fields[0]['objectclass']))
{ {
$stock_fields['objectclass'][0] = 'person'; //$stock_fields['objectclass'][0] = 'person';
$stock_fields['objectclass'][1] = 'organizationalPerson'; $stock_fields['objectclass'][0] = 'organizationalPerson';
$stock_fields['objectclass'][2] = 'inetOrgPerson'; $stock_fields['objectclass'][1] = 'inetOrgPerson';
$stock_fields['objectclass'][3] = 'phpgwContact'; $stock_fields['objectclass'][2] = 'phpgwContact';
$err = ldap_modify($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass'])); $err = ldap_modify($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass']));
} }
elseif (!$ldap_fields[0]['objectclass']) elseif (!$ldap_fields[0]['objectclass'])
{ {
$stock_fields['objectclass'][0] = 'person'; //$stock_fields['objectclass'][0] = 'person';
$stock_fields['objectclass'][1] = 'organizationalPerson'; $stock_fields['objectclass'][0] = 'organizationalPerson';
$stock_fields['objectclass'][2] = 'inetOrgPerson'; $stock_fields['objectclass'][1] = 'inetOrgPerson';
$stock_fields['objectclass'][3] = 'phpgwContact'; $stock_fields['objectclass'][2] = 'phpgwContact';
$err = ldap_mod_add($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass'])); $err = ldap_mod_add($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass']));
} }
// Verify owner // Verify owner
$stock_fields['owner'] = $owner; $stock_fields['owner'] = $owner;
if (empty($ldap_fields[0]['phpgwowner'])) if (empty($ldap_fields[0]['phpgwcontactowner']))
{ {
$err = ldap_modify($this->ldap,$dn,array('phpgwowner' => $stock_fields['owner'])); $err = ldap_modify($this->ldap,$dn,array('phpgwcontactowner' => $stock_fields['owner']));
} }
elseif (!$ldap_fields[0]['phpgwowner']) elseif (!$ldap_fields[0]['phpgwcontactowner'])
{ {
$err = ldap_mod_add($this->ldap,$dn,array('phpgwowner' => $stock_fields['owner'])); $err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactowner' => $stock_fields['owner']));
} }
// Verify access // Verify access
$stock_fields['access'] = $access; $stock_fields['access'] = $access;
if (empty($ldap_fields[0]['phpgwaccess'])) if (empty($ldap_fields[0]['phpgwcontactaccess']))
{ {
$err = ldap_modify($this->ldap,$dn,array('phpgwaccess' => $stock_fields['access'])); $err = ldap_modify($this->ldap,$dn,array('phpgwcontactaccess' => $stock_fields['access']));
} }
elseif (!$ldap_fields[0]['phpgwaccess']) elseif (!$ldap_fields[0]['phpgwcontactaccess'])
{ {
$err = ldap_mod_add($this->ldap,$dn,array('phpgwaccess' => $stock_fields['access'])); $err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactaccess' => $stock_fields['access']));
} }
// Verify cat_id // Verify cat_id
$stock_fields['cat_id'] = $cat_id; $stock_fields['cat_id'] = $cat_id;
if (empty($ldap_fields[0]['phpgwcatid'])) if (empty($ldap_fields[0]['phpgwcontactcatid']))
{ {
$err = ldap_modify($this->ldap,$dn,array('phpgwcatid' => $stock_fields['cat_id'])); $err = ldap_modify($this->ldap,$dn,array('phpgwcontactcatid' => $stock_fields['cat_id']));
} }
elseif (!$ldap_fields[0]['phpgwcatid']) elseif (!$ldap_fields[0]['phpgwcontactcatid'])
{ {
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcatid' => $stock_fields['cat_id'])); $err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactcatid' => $stock_fields['cat_id']));
} }
// Verify tid // Verify tid
$stock_fields['tid'] = $tid; $stock_fields['tid'] = $tid;
if (empty($ldap_fields[0]['phpgwtypeid'])) if (empty($ldap_fields[0]['phpgwcontacttypeid']))
{ {
$err = ldap_modify($this->ldap,$dn,array('phpgwtypeid' => $stock_fields['tid'])); $err = ldap_modify($this->ldap,$dn,array('phpgwcontacttypeid' => $stock_fields['tid']));
} }
elseif (!$ldap_fields[0]['phpgwtypeid']) elseif (!$ldap_fields[0]['phpgwcontacttypeid'])
{ {
$err = ldap_mod_add($this->ldap,$dn,array('phpgwtypeid' => $stock_fields['tid'])); $err = ldap_mod_add($this->ldap,$dn,array('phpgwcontacttypeid' => $stock_fields['tid']));
} }
// OK, just mod the data already // OK, just mod the data already
$allfields = $stock_fieldnames + $nonfields; $allfields = $stock_fieldnames + $nonfields;
while ( list($fname,$fvalue) = each($allfields) ) while ( list($fname,$fvalue) = each($allfields) )
{ {
if ($ldap_fields[0][$fvalue]) //if ($ldap_fields[0][$fvalue])
if ($ldap_fields[0][$fvalue] && $stock_fields[$fname] && $ldap_fields[0][$fvalue][0] != $stock_fields[$fname] )
{ {
//echo "<br>".$fname." => ".$fvalue." was there"; //echo "<br>".$fname." => ".$fvalue." was there";
$err = ldap_modify($this->ldap,$dn,array($fvalue => $stock_fields[$fname])); $err = ldap_modify($this->ldap,$dn,array($fvalue => $stock_fields[$fname]));
} }
elseif (!$ldap_fields[0][$fvalue]) //elseif (!$ldap_fields[0][$fvalue])
elseif (!$ldap_fields[0][$fvalue] && $stock_fields[$fname])
{ {
//echo "<br>".$fname." not there"; //echo "<br>".$fname." not there - '".$fvalue."'";
$err = ldap_mod_add($this->ldap,$dn,array($fvalue => $stock_fields[$fname])); $err = ldap_mod_add($this->ldap,$dn,array($fvalue => $stock_fields[$fname]));
} }
elseif ($ldap_fields[0][$fvalue] && !$stock_fields[$fname])
{
//echo "<br>".$fname." gone... deleting - '".$fvalue."'";
// NOTE: we use the ldap_fields because we need to send the
// _ORIGINAL_ contents as the value. see:
// http://www.php.net/manual/en/function.ldap-mod-del.php
$err = ldap_mod_del($this->ldap,$dn,array($fvalue => $ldap_fields[0][$fvalue][0]));
}
// Else we have nothing to do.
} }
} }
@ -770,13 +792,13 @@
return False; return False;
} }
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwowner='.$old_owner); $sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwcontactowner='.$old_owner);
$ldap_fields = ldap_get_entries($this->ldap, $sri); $ldap_fields = ldap_get_entries($this->ldap, $sri);
$entry = ""; $entry = "";
while (list($null,$entry) = each($ldap_fields)) while (list($null,$entry) = each($ldap_fields))
{ {
$err = ldap_modify($this->ldap,$dn,array('phpgwowner' => $new_owner)); $err = ldap_modify($this->ldap,$dn,array('phpgwcontactowner' => $new_owner));
} }
$this->db->query("update $this->ext_table set contact_owner='$new_owner' WHERE contact_owner=$owner",__LINE__,__FILE__); $this->db->query("update $this->ext_table set contact_owner='$new_owner' WHERE contact_owner=$owner",__LINE__,__FILE__);
@ -820,7 +842,7 @@
if ($owner) if ($owner)
{ {
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwowner='.$owner); $sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwcontactowner='.$owner);
$ldap_fields = ldap_get_entries($this->ldap, $sri); $ldap_fields = ldap_get_entries($this->ldap, $sri);
$entry = ''; $entry = '';