$users = get_users();
//select template to use
- if( $_SESSION[ldapab][username] &&
- ($_REQUEST[mode]=='edit' || $_REQUEST[mode]=='copy')){
+ if (empty($_REQUEST['mode'])) { $_REQUEST['mode']='show'; }
+ if( $_SESSION['ldapab']['username'] &&
+ ($_REQUEST['mode']=='edit' || $_REQUEST['mode']=='copy')){
$template='entry_edit.tpl';
- }elseif($_REQUEST[mode]=='vcf'){
+ }elseif($_REQUEST['mode']=='vcf'){
$template='entry_vcf.tpl';
}else{
$template='entry_show.tpl';
}
- $dn = $_REQUEST[dn];
- #$dn = 'cn=bar foo, ou=contacts, o=cosmocode, c=de';
+ if (empty($_REQUEST['dn'])) {
+ $dn = "";
+ }else{
+ $dn = $_REQUEST['dn'];
+ #$dn = 'cn=bar foo, ou=contacts, o=cosmocode, c=de';
+ }
//save data if asked for
- if($_SESSION[ldapab][username] && $_REQUEST[save]){
- $_REQUEST[entry][jpegPhoto][]=_getUploadData();
+ if($_SESSION['ldapab']['username'] && !empty($_REQUEST['save']) && $_REQUEST['save']){
+ // prepare special data
+ $_REQUEST['entry']['photo'] = _getUploadData();
+ $_REQUEST['entry']['marker'] = explode(',',$_REQUEST['entry']['markers']);
+ unset($_REQUEST['entry']['markers']);
+
+ foreach(array_keys($_REQUEST['entry']) as $field){
+ if($FIELDS['_'.$field]){
+ // entry has to be handled as array -> clean it up (trim, unique, sort)
+ $_REQUEST['entry'][$field] = array_map('trim',$_REQUEST['entry'][$field]);
+ $_REQUEST['entry'][$field] = array_unique($_REQUEST['entry'][$field]);
+ $_REQUEST['entry'][$field] = array_filter($_REQUEST['entry'][$field]);
+ natcasesort($_REQUEST['entry'][$field]);
+ }
+ }
$dn = _saveData();
}
if(empty($dn)){
- if(!$_REQUEST[mode]=='edit'){
+ if(!$_REQUEST['mode']=='edit'){
$smarty->assign('error','No dn was given');
$template = 'error.tpl';
}
- }elseif($_REQUEST[del]){
+ }elseif(!empty($_REQUEST['del']) && $_REQUEST['del']){
_delEntry($dn);
}elseif(!_fetchData($dn)){
$smarty->assign('error',"The requested entry '$dn' was not found");
tpl_timezone();
tpl_country();
//display templates
- if($_REQUEST[mode]=='vcf'){
+ if($_REQUEST['mode']=='vcf'){
$entry = $smarty->get_template_vars('entry');
- $filename = $entry[givenname].'_'.$entry[name].'.vcf';
+ $filename = $entry['givenname'].'_'.$entry['name'].'.vcf';
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
$smarty->display($template);
}else{
header('Content-Type: text/html; charset=utf-8');
- $smarty->display('header.tpl');
$smarty->display($template);
- $smarty->display('footer.tpl');
}
//--------------------------------------------------------------
$entry = $result[0];
//remove dn from entry when copy
- if($_REQUEST[mode] == 'copy'){
- $entry[dn]='';
+ if(!empty($_REQUEST['mode']) && $_REQUEST['mode'] == 'copy'){
+ $entry['dn']='';
}
//assign entry to template:
print '</pre>';*/
// make username from dn for manager:
- $smarty->assign('managername',$users[$entry[manager][0]]);
+ if (empty($entry['manager'])) { $entry['manager']=array(""); }
+ if (empty($users[$entry['manager'][0]])) { $users[$entry['manager'][0]]=''; }
+ $smarty->assign('managername',$users[$entry['manager'][0]]);
return true;
}
/**
- * saves the data from $_REQUEST[entry] to the LDAP directory
+ * saves the data from $_REQUEST['entry'] to the LDAP directory
*
* returns given or constructed dn
*/
function _saveData(){
global $LDAP_CON;
global $conf;
- $entries = namedentries();
- $entries['mail']='mail'; //special field mail isn't in entries so we add it here
- if($conf[extended]){
- $entries['marker']='marker'; //same for marker inextended schema
- }
+ global $FIELDS;
+ global $OCLASSES;
- $entry = $_REQUEST[entry];
- $dn = $_REQUEST[dn];
+ $entry = $_REQUEST['entry'];
+ $dn = $_REQUEST['dn'];
//construct new dn
$now = time();
$newdn = 'uid='.$now;
- if($_REQUEST[type] == 'private'){
- $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
+ if (empty($_REQUEST['type'])) { $_REQUEST['type']='public'; }
+ if($_REQUEST['type'] == 'private'){
+ $newdn .= ', '.$conf['privatebook'].', '.$_SESSION['ldapab']['binddn'];
}else{
- $newdn .= ', '.$conf[publicbook];
+ $newdn .= ', '.$conf['publicbook'];
}
- $entry[cn] = $entry[givenname].' '.$entry[name];;
+ $entry['displayname'] = $entry['givenname'].' '.$entry['name'];;
$entry = prepare_ldap_entry($entry);
-/*print '<pre>';
+/*
+print '<pre>';
print_r($entry);
-print '</pre>';*/
+print '</pre>';
+*/
if(empty($dn)){
//new entry
- $entry[uid][] = $now;
+ $entry['uid'][] = $now;
$r = ldap_add($LDAP_CON,$newdn,$entry);
tpl_ldaperror();
return $newdn;
}else{
- // in extended mode we have to make sure the right classes are set
- if($conf[extended]){
- ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
- }
- // in openxchange mode we have to make sure the right classes are set
- if ($conf[openxchange]){
- ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
- }
- //modify entry (touches only our attributes)
- foreach (array_keys($entries) as $key){
+ // update the objectClasses
+ ldap_store_objectclasses($dn,$OCLASSES);
+ unset($entry['objectclass']);
+
+ //modify entry attribute by attribute - this ensure we don't delete unknown stuff
+ foreach (array_values($FIELDS) as $key){
if($key == 'dn'){
continue;
}elseif(empty($entry[$key])){
+ // field is empty -> handle deletion (except for photo unless deletion triggered)
+ if (empty($_REQUEST['delphoto'])) { $_REQUEST['delphoto']=0; }
if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
continue;
}
* gets the binary data from an uploaded file
*/
function _getUploadData(){
- $file = $_FILES[photoupload];
+ $file = $_FILES['photoupload'];
- if (is_uploaded_file($file[tmp_name])) {
- if(preg_match('=image/p?jpe?g=',$file[type])){
- $fh = fopen($file[tmp_name],'r');
- $data = fread($fh,$file[size]);
+ if (is_uploaded_file($file['tmp_name'])) {
+ if(preg_match('=image/p?jpe?g=',$file['type'])){
+ $fh = fopen($file['tmp_name'],'r');
+ $data = fread($fh,$file['size']);
fclose($fh);
- unlink($file[tmp_name]);
+ unlink($file['tmp_name']);
return $data;
}
}
return '';
}
-?>
+