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 // 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]);
30 if(!$_REQUEST[mode]=='edit'){
31 $smarty->assign('error','No dn was given');
32 $template = 'error.tpl';
34 }elseif($_REQUEST[del]){
36 }elseif(!_fetchData($dn)){
37 $smarty->assign('error',"The requested entry '$dn' was not found");
38 $template = 'error.tpl';
42 $smarty->assign('dn',$dn);
43 $smarty->assign('managers',$users);
51 if($_REQUEST[mode]=='vcf'){
52 $entry = $smarty->get_template_vars('entry');
53 $filename = $entry[givenname].'_'.$entry[name].'.vcf';
54 header("Content-Disposition: attachment; filename=\"$filename\"");
55 header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
56 $smarty->display($template);
58 header('Content-Type: text/html; charset=utf-8');
59 $smarty->display('header.tpl');
60 $smarty->display('list_filter.tpl');
61 $smarty->display($template);
62 $smarty->display('footer.tpl');
65 //--------------------------------------------------------------
68 * fetches the Data from the LDAP directory and assigns it to
69 * the global smarty object using tpl_entry()
71 function _fetchData($dn){
75 global $users; //contains the users for manager role
77 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
78 if(!ldap_count_entries($LDAP_CON,$sr)){
81 $result = ldap_get_binentries($LDAP_CON, $sr);
84 //remove dn from entry when copy
85 if($_REQUEST[mode] == 'copy'){
89 //assign entry to template:
96 // make username from dn for manager:
97 $smarty->assign('managername',$users[$entry[manager][0]]);
102 * saves the data from $_REQUEST[entry] to the LDAP directory
104 * returns given or constructed dn
106 function _saveData(){
109 $entries = namedentries();
110 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
112 $entries['marker']='marker'; //same for marker inextended schema
115 $entry = $_REQUEST[entry];
119 $newdn = 'uid='.$now;
120 if($_REQUEST[type] == 'private'){
121 $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
123 $newdn .= ', '.$conf[publicbook];
125 $entry[cn] = $entry[givenname].' '.$entry[name];;
126 $entry = prepare_ldap_entry($entry);
134 $entry[uid][] = $now;
135 $r = ldap_add($LDAP_CON,$newdn,$entry);
139 // in extended mode we have to make sure the right classes are set
141 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
143 // in openxchange mode we have to make sure the right classes are set
144 if ($conf[openxchange]){
145 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
147 //modify entry (touches only our attributes)
148 foreach (array_keys($entries) as $key){
151 }elseif(empty($entry[$key])){
152 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
157 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
158 tpl_ldaperror("del $key");
161 $add[$key]=$entry[$key];
162 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
163 tpl_ldaperror("mod $key");
171 * does as the name says - delete the whole entry
173 function _delEntry($dn){
175 if(ldap_full_delete($LDAP_CON,$dn,true)){
176 header("Location: index.php");
182 * gets the binary data from an uploaded file
184 function _getUploadData(){
185 $file = $_FILES[photoupload];
187 if (is_uploaded_file($file[tmp_name])) {
188 if(preg_match('=image/p?jpe?g=',$file[type])){
189 $fh = fopen($file[tmp_name],'r');
190 $data = fread($fh,$file[size]);
192 unlink($file[tmp_name]);