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]);
26 unset($_REQUEST[entry][markers]);
31 if(!$_REQUEST[mode]=='edit'){
32 $smarty->assign('error','No dn was given');
33 $template = 'error.tpl';
35 }elseif($_REQUEST[del]){
37 }elseif(!_fetchData($dn)){
38 $smarty->assign('error',"The requested entry '$dn' was not found");
39 $template = 'error.tpl';
43 $smarty->assign('dn',$dn);
44 $smarty->assign('managers',$users);
52 if($_REQUEST[mode]=='vcf'){
53 $entry = $smarty->get_template_vars('entry');
54 $filename = $entry[givenname].'_'.$entry[name].'.vcf';
55 header("Content-Disposition: attachment; filename=\"$filename\"");
56 header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
57 $smarty->display($template);
59 header('Content-Type: text/html; charset=utf-8');
60 $smarty->display('header.tpl');
61 $smarty->display('list_filter.tpl');
62 $smarty->display($template);
63 $smarty->display('footer.tpl');
66 //--------------------------------------------------------------
69 * fetches the Data from the LDAP directory and assigns it to
70 * the global smarty object using tpl_entry()
72 function _fetchData($dn){
76 global $users; //contains the users for manager role
78 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
79 if(!ldap_count_entries($LDAP_CON,$sr)){
82 $result = ldap_get_binentries($LDAP_CON, $sr);
85 //remove dn from entry when copy
86 if($_REQUEST[mode] == 'copy'){
90 //assign entry to template:
97 // make username from dn for manager:
98 $smarty->assign('managername',$users[$entry[manager][0]]);
103 * saves the data from $_REQUEST[entry] to the LDAP directory
105 * returns given or constructed dn
107 function _saveData(){
110 $entries = namedentries();
111 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
113 $entries['marker']='marker'; //same for marker inextended schema
116 $entry = $_REQUEST[entry];
120 $newdn = 'uid='.$now;
121 if($_REQUEST[type] == 'private'){
122 $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
124 $newdn .= ', '.$conf[publicbook];
126 $entry[cn] = $entry[givenname].' '.$entry[name];;
127 $entry = prepare_ldap_entry($entry);
137 $entry[uid][] = $now;
138 $r = ldap_add($LDAP_CON,$newdn,$entry);
142 // in extended mode we have to make sure the right classes are set
144 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
146 // in openxchange mode we have to make sure the right classes are set
147 if ($conf[openxchange]){
148 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
150 //modify entry (touches only our attributes)
151 foreach (array_keys($entries) as $key){
154 }elseif(empty($entry[$key])){
155 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
160 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
161 tpl_ldaperror("del $key");
164 $add[$key]=$entry[$key];
165 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
166 tpl_ldaperror("mod $key");
174 * does as the name says - delete the whole entry
176 function _delEntry($dn){
178 if(ldap_full_delete($LDAP_CON,$dn,true)){
179 header("Location: index.php");
185 * gets the binary data from an uploaded file
187 function _getUploadData(){
188 $file = $_FILES[photoupload];
190 if (is_uploaded_file($file[tmp_name])) {
191 if(preg_match('=image/p?jpe?g=',$file[type])){
192 $fh = fopen($file[tmp_name],'r');
193 $data = fread($fh,$file[size]);
195 unlink($file[tmp_name]);