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);
45 if($_REQUEST[mode]=='vcf'){
46 $entry = $smarty->get_template_vars('entry');
47 $filename = $entry[givenname].'_'.$entry[name].'.vcf';
48 header("Content-Disposition: attachment; filename=\"$filename\"");
49 header("Content-type: text/x-vcard; name=\"$filename\"");
50 $smarty->display($template);
52 $smarty->display('header.tpl');
53 $smarty->display($template);
54 $smarty->display('footer.tpl');
57 //--------------------------------------------------------------
60 * fetches the Data from the LDAP directory and assigns it to
61 * the global smarty object using tpl_entry()
63 function _fetchData($dn){
67 global $users; //contains the users for manager role
69 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
70 if(!ldap_count_entries($LDAP_CON,$sr)){
73 $result = ldap_get_binentries($LDAP_CON, $sr);
76 //remove dn from entry when copy
77 if($_REQUEST[mode] == 'copy'){
81 //assign entry to template:
88 // make username from dn for manager:
89 $smarty->assign('managername',$users[$entry[manager][0]]);
94 * saves the data from $_REQUEST[entry] to the LDAP directory
96 * returns given or constructed dn
101 $entries = namedentries();
102 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
104 $entries['marker']='marker'; //same for marker inextended schema
107 $entry = $_REQUEST[entry];
111 $newdn = 'uid='.$now;
112 if($_REQUEST[type] == 'private'){
113 $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
115 $newdn .= ', '.$conf[publicbook];
117 $entry[cn] = $entry[givenname].' '.$entry[name];;
118 $entry = prepare_ldap_entry($entry);
126 $entry[uid][] = $now;
127 $r = ldap_add($LDAP_CON,$newdn,$entry);
131 // in extended mode we have to make sure the right classes are set
133 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
135 //modify entry (touches only our attributes)
136 foreach (array_keys($entries) as $key){
139 }elseif(empty($entry[$key])){
140 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
145 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
146 tpl_ldaperror("del $key");
149 $add[$key]=$entry[$key];
150 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
151 tpl_ldaperror("mod $key");
159 * does as the name says - delete the whole entry
161 function _delEntry($dn){
163 if(ldap_full_delete($LDAP_CON,$dn,true)){
164 header("Location: index.php");
170 * gets the binary data from an uploaded file
172 function _getUploadData(){
173 $file = $_FILES[photoupload];
175 if (is_uploaded_file($file[tmp_name])) {
176 if(preg_match('=image/p?jpe?g=',$file[type])){
177 $fh = fopen($file[tmp_name],'r');
178 $data = fread($fh,$file[size]);
180 unlink($file[tmp_name]);