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\"");
53 $smarty->display($template);
55 $smarty->display('header.tpl');
56 $smarty->display($template);
57 $smarty->display('footer.tpl');
60 //--------------------------------------------------------------
63 * fetches the Data from the LDAP directory and assigns it to
64 * the global smarty object using tpl_entry()
66 function _fetchData($dn){
70 global $users; //contains the users for manager role
72 $sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)');
73 if(!ldap_count_entries($LDAP_CON,$sr)){
76 $result = ldap_get_binentries($LDAP_CON, $sr);
79 //remove dn from entry when copy
80 if($_REQUEST[mode] == 'copy'){
84 //assign entry to template:
91 // make username from dn for manager:
92 $smarty->assign('managername',$users[$entry[manager][0]]);
97 * saves the data from $_REQUEST[entry] to the LDAP directory
99 * returns given or constructed dn
101 function _saveData(){
104 $entries = namedentries();
105 $entries['mail']='mail'; //special field mail isn't in entries so we add it here
107 $entries['marker']='marker'; //same for marker inextended schema
110 $entry = $_REQUEST[entry];
114 $newdn = 'uid='.$now;
115 if($_REQUEST[type] == 'private'){
116 $newdn .= ', '.$conf[privatebook].', '.$_SESSION[ldapab][binddn];
118 $newdn .= ', '.$conf[publicbook];
120 $entry[cn] = $entry[givenname].' '.$entry[name];;
121 $entry = prepare_ldap_entry($entry);
129 $entry[uid][] = $now;
130 $r = ldap_add($LDAP_CON,$newdn,$entry);
134 // in extended mode we have to make sure the right classes are set
136 ldap_store_objectclasses($dn,array('inetOrgPerson','contactPerson'));
138 // in openxchange mode we have to make sure the right classes are set
139 if ($conf[openxchange]){
140 ldap_store_objectclasses($dn,array('inetOrgPerson','OXUserObject'));
142 //modify entry (touches only our attributes)
143 foreach (array_keys($entries) as $key){
146 }elseif(empty($entry[$key])){
147 if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){
152 $r = @ldap_mod_replace($LDAP_CON,$dn,$del);
153 tpl_ldaperror("del $key");
156 $add[$key]=$entry[$key];
157 $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
158 tpl_ldaperror("mod $key");
166 * does as the name says - delete the whole entry
168 function _delEntry($dn){
170 if(ldap_full_delete($LDAP_CON,$dn,true)){
171 header("Location: index.php");
177 * gets the binary data from an uploaded file
179 function _getUploadData(){
180 $file = $_FILES[photoupload];
182 if (is_uploaded_file($file[tmp_name])) {
183 if(preg_match('=image/p?jpe?g=',$file[type])){
184 $fh = fopen($file[tmp_name],'r');
185 $data = fread($fh,$file[size]);
187 unlink($file[tmp_name]);