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 $_REQUEST[entry][marker] = array_unique($_REQUEST[entry][marker]);
27 unset($_REQUEST[entry][markers]);
32 if(!$_REQUEST[mode]=='edit'){
33 $smarty->assign('error','No dn was given');
34 $template = 'error.tpl';
36 }elseif($_REQUEST[del]){
38 }elseif(!_fetchData($dn)){
39 $smarty->assign('error',"The requested entry '$dn' was not found");
40 $template = 'error.tpl';
44 $smarty->assign('dn',$dn);
45 $smarty->assign('managers',$users);
53 if($_REQUEST[mode]=='vcf'){
54 $entry = $smarty->get_template_vars('entry');
55 $filename = $entry[givenname].'_'.$entry[name].'.vcf';
56 header("Content-Disposition: attachment; filename=\"$filename\"");
57 header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
58 $smarty->display($template);
60 header('Content-Type: text/html; charset=utf-8');
61 $smarty->display($template);
64 //--------------------------------------------------------------
67 * fetches the Data from the LDAP directory and assigns it to
68 * the global smarty object using tpl_entry()
70 function _fetchData($dn){
74 global $users; //contains the users for manager role
76 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
77 if(!ldap_count_entries($LDAP_CON,$sr)){
80 $result = ldap_get_binentries($LDAP_CON, $sr);
83 //remove dn from entry when copy
84 if($_REQUEST[mode] == 'copy'){
88 //assign entry to template:
95 // make username from dn for manager:
96 $smarty->assign('managername',$users[$entry[manager][0]]);
101 * saves the data from $_REQUEST[entry] to the LDAP directory
103 * returns given or constructed dn
105 function _saveData(){
108 $entries = namedentries();
109 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
111 $entries['marker']='marker'; //same for marker inextended schema
114 $entry = $_REQUEST[entry];
118 $newdn = 'uid='.$now;
119 if($_REQUEST[type] == 'private'){
120 $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
122 $newdn .= ', '.$conf[publicbook];
124 $entry[cn] = $entry[givenname].' '.$entry[name];;
125 $entry = prepare_ldap_entry($entry);
135 $entry[uid][] = $now;
136 $r = ldap_add($LDAP_CON,$newdn,$entry);
140 // in extended mode we have to make sure the right classes are set
142 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
144 // in openxchange mode we have to make sure the right classes are set
145 if ($conf[openxchange]){
146 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
148 //modify entry (touches only our attributes)
149 foreach (array_keys($entries) as $key){
152 }elseif(empty($entry[$key])){
153 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
158 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
159 tpl_ldaperror("del $key");
162 $add[$key]=$entry[$key];
163 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
164 tpl_ldaperror("mod $key");
172 * does as the name says - delete the whole entry
174 function _delEntry($dn){
176 if(ldap_full_delete($LDAP_CON,$dn,true)){
177 header("Location: index.php");
183 * gets the binary data from an uploaded file
185 function _getUploadData(){
186 $file = $_FILES[photoupload];
188 if (is_uploaded_file($file[tmp_name])) {
189 if(preg_match('=image/p?jpe?g=',$file[type])){
190 $fh = fopen($file[tmp_name],'r');
191 $data = fread($fh,$file[size]);
193 unlink($file[tmp_name]);