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';
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 $_REQUEST[entry][jpegPhoto][]=_getUploadData();
27 if(!$_REQUEST[mode]=='edit'){
28 $smarty->assign('error','No dn was given');
29 $template = 'error.tpl';
31 }elseif($_REQUEST[del]){
33 }elseif(!_fetchData($dn)){
34 $smarty->assign('error',"The requested entry '$dn' was not found");
35 $template = 'error.tpl';
39 $smarty->assign('dn',$dn);
40 $smarty->assign('managers',$users);
48 if($_REQUEST[mode]=='vcf'){
49 $entry = $smarty->get_template_vars('entry');
50 $filename = $entry[givenname].'_'.$entry[name].'.vcf';
51 header("Content-Disposition: attachment; filename=\"$filename\"");
52 header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
53 $smarty->display($template);
55 header('Content-Type: text/html; charset=utf-8');
56 $smarty->display('header.tpl');
57 $smarty->display($template);
58 $smarty->display('footer.tpl');
61 //--------------------------------------------------------------
64 * fetches the Data from the LDAP directory and assigns it to
65 * the global smarty object using tpl_entry()
67 function _fetchData($dn){
71 global $users; //contains the users for manager role
73 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
74 if(!ldap_count_entries($LDAP_CON,$sr)){
77 $result = ldap_get_binentries($LDAP_CON, $sr);
80 //remove dn from entry when copy
81 if($_REQUEST[mode] == 'copy'){
85 //assign entry to template:
92 // make username from dn for manager:
93 $smarty->assign('managername',$users[$entry[manager][0]]);
98 * saves the data from $_REQUEST[entry] to the LDAP directory
100 * returns given or constructed dn
102 function _saveData(){
105 $entries = namedentries();
106 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
108 $entries['marker']='marker'; //same for marker inextended schema
111 $entry = $_REQUEST[entry];
115 $newdn = 'uid='.$now;
116 if($_REQUEST[type] == 'private'){
117 $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
119 $newdn .= ', '.$conf[publicbook];
121 $entry[cn] = $entry[givenname].' '.$entry[name];;
122 $entry = prepare_ldap_entry($entry);
130 $entry[uid][] = $now;
131 $r = ldap_add($LDAP_CON,$newdn,$entry);
135 // in extended mode we have to make sure the right classes are set
137 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
139 // in openxchange mode we have to make sure the right classes are set
140 if ($conf[openxchange]){
141 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
143 //modify entry (touches only our attributes)
144 foreach (array_keys($entries) as $key){
147 }elseif(empty($entry[$key])){
148 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
153 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
154 tpl_ldaperror("del $key");
157 $add[$key]=$entry[$key];
158 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
159 tpl_ldaperror("mod $key");
167 * does as the name says - delete the whole entry
169 function _delEntry($dn){
171 if(ldap_full_delete($LDAP_CON,$dn,true)){
172 header("Location: index.php");
178 * gets the binary data from an uploaded file
180 function _getUploadData(){
181 $file = $_FILES[photoupload];
183 if (is_uploaded_file($file[tmp_name])) {
184 if(preg_match('=image/p?jpe?g=',$file[type])){
185 $fh = fopen($file[tmp_name],'r');
186 $data = fread($fh,$file[size]);
188 unlink($file[tmp_name]);