2 require_once('init.php');
7 //select template to use
8 if (empty($_REQUEST['mode'])) { $_REQUEST['mode']='show'; }
9 if( $_SESSION['ldapab']['username'] &&
10 ($_REQUEST['mode']=='edit' || $_REQUEST['mode']=='copy')){
11 $template='entry_edit.tpl';
12 }elseif($_REQUEST['mode']=='vcf'){
13 $template='entry_vcf.tpl';
15 $template='entry_show.tpl';
18 if (empty($_REQUEST['dn'])) {
21 $dn = $_REQUEST['dn'];
22 #$dn = 'cn=bar foo, ou=contacts, o=cosmocode, c=de';
25 //save data if asked for
26 if($_SESSION['ldapab']['username'] && !empty($_REQUEST['save']) && $_REQUEST['save']){
27 // prepare special data
28 $_REQUEST['entry']['jpegPhoto'][]=_getUploadData();
29 $_REQUEST['entry']['marker'] = explode(',',$_REQUEST['entry']['markers']);
30 $_REQUEST['entry']['marker'] = array_map('trim',$_REQUEST['entry']['marker']);
31 $_REQUEST['entry']['marker'] = array_unique($_REQUEST['entry']['marker']);
32 $_REQUEST['entry']['marker'] = array_filter($_REQUEST['entry']['marker']);
33 sort($_REQUEST['entry']['marker']);
34 unset($_REQUEST['entry']['markers']);
36 $_REQUEST['entry']['mail'] = array_map('trim',$_REQUEST['entry']['mail']);
37 $_REQUEST['entry']['mail'] = array_unique($_REQUEST['entry']['mail']);
38 $_REQUEST['entry']['mail'] = array_filter($_REQUEST['entry']['mail']);
39 sort($_REQUEST['entry']['mail']);
45 if(!$_REQUEST['mode']=='edit'){
46 $smarty->assign('error','No dn was given');
47 $template = 'error.tpl';
49 }elseif(!empty($_REQUEST['del']) && $_REQUEST['del']){
51 }elseif(!_fetchData($dn)){
52 $smarty->assign('error',"The requested entry '$dn' was not found");
53 $template = 'error.tpl';
57 $smarty->assign('dn',$dn);
58 $smarty->assign('managers',$users);
66 if($_REQUEST['mode']=='vcf'){
67 $entry = $smarty->get_template_vars('entry');
68 $filename = $entry['givenname'].'_'.$entry['name'].'.vcf';
69 header("Content-Disposition: attachment; filename=\"$filename\"");
70 header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
71 $smarty->display($template);
73 header('Content-Type: text/html; charset=utf-8');
74 $smarty->display($template);
77 //--------------------------------------------------------------
80 * fetches the Data from the LDAP directory and assigns it to
81 * the global smarty object using tpl_entry()
83 function _fetchData($dn){
87 global $users; //contains the users for manager role
89 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
90 if(!ldap_count_entries($LDAP_CON,$sr)){
93 $result = ldap_get_binentries($LDAP_CON, $sr);
96 //remove dn from entry when copy
97 if(!empty($_REQUEST['mode']) && $_REQUEST['mode'] == 'copy'){
101 //assign entry to template:
108 // make username from dn for manager:
109 if (empty($entry['manager'])) { $entry['manager']=array(""); }
110 if (empty($users[$entry['manager'][0]])) { $users[$entry['manager'][0]]=''; }
111 $smarty->assign('managername',$users[$entry['manager'][0]]);
116 * saves the data from $_REQUEST['entry'] to the LDAP directory
118 * returns given or constructed dn
120 function _saveData(){
123 $entries = namedentries();
124 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
125 if($conf['extended']){
126 $entries['marker']='marker'; //same for marker in extended schema
129 $entry = $_REQUEST['entry'];
130 $dn = $_REQUEST['dn'];
133 $newdn = 'uid='.$now;
134 if (empty($_REQUEST['type'])) { $_REQUEST['type']='public'; }
135 if($_REQUEST['type'] == 'private'){
136 $newdn .= ', '.$conf['privatebook'].', '.$_SESSION['ldapab']['binddn'];
138 $newdn .= ', '.$conf['publicbook'];
140 $entry['cn'] = $entry['givenname'].' '.$entry['name'];;
141 $entry = prepare_ldap_entry($entry);
151 $entry['uid'][] = $now;
152 $r = ldap_add($LDAP_CON,$newdn,$entry);
156 // in extended mode we have to make sure the right classes are set
157 if($conf['extended']){
158 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
160 // in openxchange mode we have to make sure the right classes are set
161 if ($conf['openxchange']){
162 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
164 //modify entry (touches only our attributes)
165 foreach (array_keys($entries) as $key){
168 }elseif(empty($entry[$key])){
169 if (empty($_REQUEST['delphoto'])) { $_REQUEST['delphoto']=0; }
170 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
175 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
176 tpl_ldaperror("del $key");
179 $add[$key]=$entry[$key];
180 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
181 tpl_ldaperror("mod $key");
189 * does as the name says - delete the whole entry
191 function _delEntry($dn){
193 if(ldap_full_delete($LDAP_CON,$dn,true)){
194 header("Location: index.php");
200 * gets the binary data from an uploaded file
202 function _getUploadData(){
203 $file = $_FILES['photoupload'];
205 if (is_uploaded_file($file['tmp_name'])) {
206 if(preg_match('=image/p?jpe?g=',$file['type'])){
207 $fh = fopen($file['tmp_name'],'r');
208 $data = fread($fh,$file['size']);
210 unlink($file['tmp_name']);