2 require_once('init.php');
7 //select template to use
8 if( $_SESSION['ldapab']['username'] &&
9 ($_REQUEST['mode']=='edit' || $_REQUEST['mode']=='copy')){
10 $template='entry_edit.tpl';
11 }elseif($_REQUEST['mode']=='vcf'){
12 $template='entry_vcf.tpl';
14 $template='entry_show.tpl';
17 $dn = $_REQUEST['dn'];
18 #$dn = 'cn=bar foo, ou=contacts, o=cosmocode, c=de';
20 //save data if asked for
21 if($_SESSION['ldapab']['username'] && $_REQUEST['save']){
22 // prepare special data
23 $_REQUEST['entry']['jpegPhoto'][]=_getUploadData();
24 $_REQUEST['entry']['marker'] = explode(',',$_REQUEST['entry']['markers']);
25 $_REQUEST['entry']['marker'] = array_map('trim',$_REQUEST['entry']['marker']);
26 $_REQUEST['entry']['marker'] = array_unique($_REQUEST['entry']['marker']);
27 $_REQUEST['entry']['marker'] = array_filter($_REQUEST['entry']['marker']);
28 sort($_REQUEST['entry']['marker']);
29 unset($_REQUEST['entry']['markers']);
31 $_REQUEST['entry']['mail'] = array_map('trim',$_REQUEST['entry']['mail']);
32 $_REQUEST['entry']['mail'] = array_unique($_REQUEST['entry']['mail']);
33 $_REQUEST['entry']['mail'] = array_filter($_REQUEST['entry']['mail']);
34 sort($_REQUEST['entry']['mail']);
40 if(!$_REQUEST['mode']=='edit'){
41 $smarty->assign('error','No dn was given');
42 $template = 'error.tpl';
44 }elseif($_REQUEST['del']){
46 }elseif(!_fetchData($dn)){
47 $smarty->assign('error',"The requested entry '$dn' was not found");
48 $template = 'error.tpl';
52 $smarty->assign('dn',$dn);
53 $smarty->assign('managers',$users);
61 if($_REQUEST['mode']=='vcf'){
62 $entry = $smarty->get_template_vars('entry');
63 $filename = $entry['givenname'].'_'.$entry['name'].'.vcf';
64 header("Content-Disposition: attachment; filename=\"$filename\"");
65 header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
66 $smarty->display($template);
68 header('Content-Type: text/html; charset=utf-8');
69 $smarty->display($template);
72 //--------------------------------------------------------------
75 * fetches the Data from the LDAP directory and assigns it to
76 * the global smarty object using tpl_entry()
78 function _fetchData($dn){
82 global $users; //contains the users for manager role
84 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
85 if(!ldap_count_entries($LDAP_CON,$sr)){
88 $result = ldap_get_binentries($LDAP_CON, $sr);
91 //remove dn from entry when copy
92 if($_REQUEST['mode'] == 'copy'){
96 //assign entry to template:
103 // make username from dn for manager:
104 $smarty->assign('managername',$users[$entry['manager'][0]]);
109 * saves the data from $_REQUEST['entry'] to the LDAP directory
111 * returns given or constructed dn
113 function _saveData(){
116 $entries = namedentries();
117 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
118 if($conf['extended']){
119 $entries['marker']='marker'; //same for marker inextended schema
122 $entry = $_REQUEST['entry'];
123 $dn = $_REQUEST['dn'];
126 $newdn = 'uid='.$now;
127 if($_REQUEST['type'] == 'private'){
128 $newdn .= ', '.$conf['privatebook'].', '.$_SESSION['ldapab']['binddn'];
130 $newdn .= ', '.$conf['publicbook'];
132 $entry['cn'] = $entry['givenname'].' '.$entry['name'];;
133 $entry = prepare_ldap_entry($entry);
143 $entry['uid'][] = $now;
144 $r = ldap_add($LDAP_CON,$newdn,$entry);
148 // in extended mode we have to make sure the right classes are set
149 if($conf['extended']){
150 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
152 // in openxchange mode we have to make sure the right classes are set
153 if ($conf['openxchange']){
154 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
156 //modify entry (touches only our attributes)
157 foreach (array_keys($entries) as $key){
160 }elseif(empty($entry[$key])){
161 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
166 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
167 tpl_ldaperror("del $key");
170 $add[$key]=$entry[$key];
171 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
172 tpl_ldaperror("mod $key");
180 * does as the name says - delete the whole entry
182 function _delEntry($dn){
184 if(ldap_full_delete($LDAP_CON,$dn,true)){
185 header("Location: index.php");
191 * gets the binary data from an uploaded file
193 function _getUploadData(){
194 $file = $_FILES['photoupload'];
196 if (is_uploaded_file($file['tmp_name'])) {
197 if(preg_match('=image/p?jpe?g=',$file['type'])){
198 $fh = fopen($file['tmp_name'],'r');
199 $data = fread($fh,$file['size']);
201 unlink($file['tmp_name']);