X-Git-Url: https://git.sur5r.net/?p=contagged;a=blobdiff_plain;f=entry.php;h=1e5e7552976de876ee184fccb105b3866df15614;hp=e22452267af40da0d26eaf22ced382c8dec81c77;hb=HEAD;hpb=64fca63a29fb2a863d159734627795acfb17c853 diff --git a/entry.php b/entry.php index e224522..1e5e755 100644 --- a/entry.php +++ b/entry.php @@ -2,6 +2,11 @@ require_once('inc/init.php'); ldap_login(); +if ($conf['userlogreq'] && !isset($_SESSION['ldapab']['username'])){ + header('Location: login.php'); + exit(); +} + $users = get_users(); //select template to use @@ -11,6 +16,8 @@ if( $_SESSION['ldapab']['username'] && $template='entry_edit.tpl'; }elseif($_REQUEST['mode']=='vcf'){ $template='entry_vcf.tpl'; +}elseif($_REQUEST['mode']=='map'){ + $template='entry_map.tpl'; }else{ $template='entry_show.tpl'; } @@ -26,7 +33,8 @@ if (empty($_REQUEST['dn'])) { if($_SESSION['ldapab']['username'] && !empty($_REQUEST['save']) && $_REQUEST['save']){ // prepare special data $_REQUEST['entry']['photo'] = _getUploadData(); - $_REQUEST['entry']['marker'] = explode(',',$_REQUEST['entry']['markers']); + if($_REQUEST['entry']['markers']) + $_REQUEST['entry']['marker'] = explode(',',$_REQUEST['entry']['markers']); unset($_REQUEST['entry']['markers']); foreach(array_keys($_REQUEST['entry']) as $field){ @@ -63,7 +71,9 @@ if($_REQUEST['mode']=='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); + $output = $smarty->fetch($template) . "\n"; + $output = str_replace("\n", "\r\n", $output); + echo $output; }else{ header('Content-Type: text/html; charset=utf-8'); $smarty->display($template); @@ -81,8 +91,9 @@ function _fetchData($dn){ global $smarty; global $users; //contains the users for manager role - $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)'); - if(!ldap_count_entries($LDAP_CON,$sr)){ + $sr = @ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)'); + tpl_ldaperror(); + if(!@ldap_count_entries($LDAP_CON,$sr)){ return false; } $result = ldap_get_binentries($LDAP_CON, $sr); @@ -121,13 +132,13 @@ function _saveData(){ $entry = $_REQUEST['entry']; $dn = $_REQUEST['dn']; //construct new dn - $now = time(); - $newdn = 'uid='.$now; + $new_uid = time().str_pad(mt_rand(0,99999999),8,"0", STR_PAD_LEFT); + $newdn = 'uid='.$new_uid; if (empty($_REQUEST['type'])) { $_REQUEST['type']='public'; } - if($_REQUEST['type'] == 'private'){ - $newdn .= ', '.$conf['privatebook'].', '.$_SESSION['ldapab']['binddn']; + if($_REQUEST['type'] == 'private' && $conf['privatebook']){ + $newdn .= ','.$conf['privatebook'].','.$_SESSION['ldapab']['binddn']; }else{ - $newdn .= ', '.$conf['publicbook']; + $newdn .= ','.$conf['publicbook']; } $entry['displayname'] = $entry['givenname'].' '.$entry['name'];; $entry = prepare_ldap_entry($entry); @@ -140,8 +151,8 @@ print ''; if(empty($dn)){ //new entry - $entry['uid'][] = $now; - $r = ldap_add($LDAP_CON,$newdn,$entry); + $entry['uid'][] = $new_uid; + $r = @ldap_add($LDAP_CON,$newdn,$entry); tpl_ldaperror(); return $newdn; }else{ @@ -170,6 +181,27 @@ print ''; tpl_ldaperror("mod $key"); } } + + // special tag handling for Thunderbird + if($conf['tbtaghack'] && in_array('contactPerson',$OCLASSES)){ + for($i=1;$i<5;$i++){ + if(empty($entry["custom$i"])){ + // deletion + unset($del); + $del["custom$i"]=array(); + $r = @ldap_mod_replace($LDAP_CON,$dn,$del); + tpl_ldaperror("del custom$i"); + }else{ + // modification + unset($add); + $add["custom$i"]=$entry["custom$i"]; + $r = @ldap_mod_replace($LDAP_CON,$dn,$add); + tpl_ldaperror("mod custom$i"); + } + } + } + + return $dn; } } @@ -189,6 +221,8 @@ function _delEntry($dn){ * gets the binary data from an uploaded file */ function _getUploadData(){ + global $smarty; + global $lang; $file = $_FILES['photoupload']; if (is_uploaded_file($file['tmp_name'])) { @@ -198,7 +232,19 @@ function _getUploadData(){ fclose($fh); unlink($file['tmp_name']); return $data; + } else { + $smarty->assign('jpegError',$lang['err_wrongFileType']); + } + } elseif (preg_match('/http:\/\//', $_REQUEST["photo"])) { + $fd = fopen($_REQUEST["photo"], "rb"); + $data = ''; + while (!feof($fd)) { + $data .= fread($fd, 8192); } + fclose($fd); + return $data; + } else { + $smarty->assign('jpegError',$lang['err_fileNotUploaded']); } return ''; }