Skip to content

Commit 77f628d

Browse files
authored
Merge pull request #166 from ltb-project/163-possibility-to-update-photo
Update photo feature
2 parents 455349c + 6a7e0bc commit 77f628d

File tree

9 files changed

+169
-0
lines changed

9 files changed

+169
-0
lines changed

conf/config.inc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
$use_updateinfos = false;
169169
$update_items = array('firstname', 'lastname', 'mail', 'phone', 'mobile');
170170
$update_items_macros = array('fullname' => '%firstname% %lastname%');
171+
$update_photo = false;
172+
#$update_photo_maxsize = 500000;
173+
$update_photo_ldap = true;
174+
$update_photo_directory = false;
171175

172176
# HTTP
173177
$http_url = "http://localhost/wp";

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LDAP Tool Box White Pages documentation
2424
mapmenu.rst
2525
csvexport.rst
2626
vcardexport.rst
27+
updateinfos.rst

docs/updateinfos.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Update informations
2+
===================
3+
4+
To let connected user update its own information, enable this feature:
5+
6+
.. code-block:: php
7+
8+
$use_updateinfos = true;
9+
10+
.. warning::
11+
12+
This requires to enable authentication, see :doc:`authentication configuration page <authentication>`.
13+
14+
Items
15+
_____
16+
17+
The list of items that are available for modification is configured in:
18+
19+
.. code-block:: php
20+
21+
$update_items = array('firstname', 'lastname', 'mail', 'phone', 'mobile');
22+
23+
.. tip::
24+
25+
Be sure not to put the item corresponding to the RDN of the entry, as this will raise an error.
26+
27+
Macros
28+
------
29+
30+
Some fields can be automatically updated:
31+
32+
.. code-block:: php
33+
34+
$update_items_macros = array('fullname' => '%firstname% %lastname%');
35+
36+
Photo
37+
-----
38+
39+
To let user update its photo:
40+
41+
.. code-block:: php
42+
43+
$update_photo = false;
44+
45+
To configure maximum file size:
46+
47+
.. code-block:: php
48+
49+
$update_photo_maxsize = 500000;
50+
51+
Depending on where is stored the photo, adjust these settings:
52+
53+
.. code-block:: php
54+
55+
$update_photo_ldap = true;
56+
$update_photo_directory = false;
57+
58+
.. tip::
59+
60+
The parameters for photo storage are available in the :doc:`photos section <photos>`.

htdocs/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
$smarty->assign('usergroup_dn_link_label_attributes',implode(",",$usergroup_dn_link_label_attributes));
112112
$smarty->assign('require_auth',$require_auth);
113113
$smarty->assign('display_myaccount_menu',$display_myaccount_menu);
114+
$smarty->assign('update_photo',$update_photo);
114115

115116
# Assign custom template variables
116117
foreach (get_defined_vars() as $key => $value) {

htdocs/updateinfos.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
if (isset($_POST["dn"]) and $_POST["dn"]) {
1111
$action = "updateentry";
12+
if (isset($_FILES['photo'])) {
13+
$action = "updatephoto";
14+
}
1215
}
1316

1417
if (!$dn) {
@@ -110,6 +113,51 @@ function ($matches) use ($item, $update_attributes, $attributes_map) {
110113
}
111114
}
112115

116+
# Update photo
117+
if ($action == "updatephoto") {
118+
if ( $_FILES['photo']['error'] ) {
119+
switch( $_FILES['photo']['error']) {
120+
case 1:
121+
case 2:
122+
$result = "phototoobig";
123+
break;
124+
case 4:
125+
$result = "nophoto";
126+
break;
127+
default:
128+
$result = "photonotuploaded";
129+
}
130+
error_log("Upload photo for $dn failed with error $result (error code ".$_FILES['photo']['error'].")");
131+
$action = "displayform";
132+
} elseif (isset($update_photo_maxsize) and (filesize($_FILES['photo']['tmp_name']) >= $update_photo_maxsize)) {
133+
$result = "phototoobig";
134+
$action = "displayform";
135+
} else {
136+
137+
if ($update_photo_ldap) {
138+
$update_attributes = array($photo_ldap_attribute => file_get_contents($_FILES['photo']['tmp_name']));
139+
if (!ldap_mod_replace($ldap, $dn, $update_attributes)) {
140+
$result = "photonotuploaded";
141+
$action = "displayform";
142+
} else {
143+
$action = "displayentry";
144+
}
145+
}
146+
147+
if ($update_photo_directory) {
148+
$search = ldap_read($ldap, $dn, '(objectClass=*)', array($photo_local_ldap_attribute));
149+
$entry = ldap_get_entries($ldap, $search);
150+
$photo_name = $entry[0][$photo_local_ldap_attribute][0];
151+
if (!move_uploaded_file($_FILES['photo']['tmp_name'], $photo_local_directory . $photo_name . $photo_local_extension )) {
152+
$result = "photonotuploaded";
153+
$action = "displayform";
154+
} else {
155+
$action = "displayentry";
156+
}
157+
}
158+
}
159+
}
160+
113161
# Display form
114162
if ($action == "displayform") {
115163

lang/en.inc.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$messages['advancedsearch'] = "Advanced search";
88
$messages['auth_sso_fail'] = "Authentication failed";
99
$messages['authenticate'] = "Please authenticate yourself";
10+
$messages['cancel'] = "Cancel";
1011
$messages['cancelbacktoentry'] = "Cancel and go back to entry";
1112
$messages['displayentry'] = "Display entry";
1213
$messages['dnrequired'] = "Entry identifier required";
@@ -62,13 +63,17 @@
6263
$messages['map'] = "Map";
6364
$messages['myaccount'] = "My account";
6465
$messages['noentriesfound'] = "No entries found";
66+
$messages['nophoto'] = "No photo provided";
6567
$messages['notdefined'] = "Not defined";
6668
$messages['negates'] = "Check to negates this value";
6769
$messages['password'] = "Password";
6870
$messages['passwordinvalid'] = "Login or password incorrect";
71+
$messages['photonotuploaded'] = "Photo upload failed";
72+
$messages['phototoobig'] = "File is too big";
6973
$messages['search'] = "Search";
7074
$messages['search_object'] = "Objects to search";
7175
$messages['searchrequired'] = "Please enter your search";
76+
$messages['select_photo'] = "Select a file and send it";
7277
$messages['sizelimit'] = "Size limit has been reached, some entries could not be displayed";
7378
$messages['submit'] = "Submit";
7479
$messages['title'] = "White Pages";
@@ -78,6 +83,7 @@
7883
$messages['tooltip_emailto'] = "Send an email";
7984
$messages['tooltip_phoneto'] = "Dial this number";
8085
$messages['true'] = "Yes";
86+
$messages['update_photo'] = "Update photo";
8187
$messages['user_object'] = "Users";
8288
$messages['welcome'] = "Welcome to LDAP Tool Box White Pages";
8389

lang/fr.inc.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$messages['advancedsearch'] = "Recherche avancée";
88
$messages['auth_sso_fail'] = "L'authentification a échoué";
99
$messages['authenticate'] = "Veuillez vous authentifier";
10+
$messages['cancel'] = "Annuler";
1011
$messages['cancelbacktoentry'] = "Annuler et revenir à l'entrée";
1112
$messages['displayentry'] = "Afficher l'entrée";
1213
$messages['dnrequired'] = "L'identifiant de l'entrée est requis";
@@ -62,13 +63,17 @@
6263
$messages['map'] = "Carte";
6364
$messages['myaccount'] = "Mon compte";
6465
$messages['noentriesfound'] = "Aucune entrée trouvée";
66+
$messages['nophoto'] = "Aucune photo fournie";
6567
$messages['notdefined'] = "Non renseigné";
6668
$messages['password'] = "Mot de passe";
6769
$messages['passwordinvalid'] = "Identifiant ou mot de passe incorrect";
70+
$messages['photonotuploaded'] = "Erreur lors de l'enregistrement de la photo";
71+
$messages['phototoobig'] = "Le fichier est trop volumineux";
6872
$messages['negates'] = "Cocher la case pour nier la valeur";
6973
$messages['search'] = "Rechercher";
7074
$messages['search_object'] = "Objets à rechercher";
7175
$messages['searchrequired'] = "Veuillez saisir votre recherche";
76+
$messages['select_photo'] = "Sélectionnez un fichier puis envoyez-le";
7277
$messages['sizelimit'] = "La limite de recherche a été atteinte, certaines entrées n'ont pas pu être affichées";
7378
$messages['submit'] = "Envoyer";
7479
$messages['title'] = "Pages blanches";
@@ -78,6 +83,7 @@
7883
$messages['tooltip_emailto'] = "Envoyer un email";
7984
$messages['tooltip_phoneto'] = "Composer ce numéro";
8085
$messages['true'] = "Oui";
86+
$messages['update_photo'] = "Modifier la photo";
8187
$messages['user_object'] = "Utilisateurs";
8288
$messages['welcome'] = "Bienvenue sur les pages blanches LDAP Tool Box";
8389

lang/it.inc.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$messages['advancedsearch'] = "Ricerca avanzata";
88
$messages['auth_sso_fail'] = "Authentication failed";
99
$messages['authenticate'] = "Please authenticate yourself";
10+
$messages['cancel'] = "Cancel";
1011
$messages['cancelbacktoentry'] = "Cancel and go back to entry";
1112
$messages['displayentry'] = "Visualizza";
1213
$messages['dnrequired'] = "Necessario identificativo record";
@@ -62,13 +63,17 @@
6263
$messages['map'] = "Carta";
6364
$messages['myaccount'] = "My account";
6465
$messages['noentriesfound'] = "Nessun record trovato";
66+
$messages['nophoto'] = "No photo provided";
6567
$messages['notdefined'] = "Non definito";
6668
$messages['negates'] = "Check to negates this value";
6769
$messages['password'] = "Password";
6870
$messages['passwordinvalid'] = "Login or password incorrect";
71+
$messages['photonotuploaded'] = "Photo upload failed";
72+
$messages['phototoobig'] = "File is too big";
6973
$messages['search'] = "Cerca";
7074
$messages['search_object'] = "Oggetti da cercare";
7175
$messages['searchrequired'] = "Inserisci il termine di ricerca";
76+
$messages['select_photo'] = "Select a file and send it";
7277
$messages['sizelimit'] = "Limite dimensioni raggiunto, alcuni record non saranno visualizzati";
7378
$messages['submit'] = "Submit";
7479
$messages['title'] = "White Pages";
@@ -78,6 +83,7 @@
7883
$messages['tooltip_emailto'] = "Manda una mail";
7984
$messages['tooltip_phoneto'] = "Componi questo numero";
8085
$messages['true'] = "Si";
86+
$messages['update_photo'] = "Update photo";
8187
$messages['user_object'] = "Utenti";
8288
$messages['welcome'] = "Benvenuto in LDAP Tool Box White Pages";
8389

templates/updateinfos.tpl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
{if $type === "user"}
1919
<img src="photo.php?dn={$entry.dn|escape:'url'}" alt="{$entry.{$attributes_map.{$card_title}.attribute}.0}" class="img-fluid mx-auto d-block" />
20+
{if $update_photo}
21+
<div class="d-grid gap-2 col-md-4 mx-auto my-3">
22+
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#updatePhotoModal">
23+
<i class="fa fa-fw fa-file-image"></i> {$msg_update_photo}
24+
</button>
25+
</div>
26+
{/if}
2027
{/if}
2128

2229
<div class="table-responsive">
@@ -76,3 +83,33 @@
7683
</div>
7784
<div class="col-md-2"></div>
7885
</div>
86+
87+
{if $update_photo}
88+
<div class="modal fade" id="updatePhotoModal" tabindex="-1" aria-labelledby="updatePhotoModalLabel" aria-hidden="true">
89+
<form method="post" enctype="multipart/form-data">
90+
<input type="hidden" name="dn" value="{$dn}"/>
91+
<div class="modal-dialog">
92+
<div class="modal-content">
93+
<div class="modal-header">
94+
<h1 class="modal-title fs-5" id="updatePhotoModalLabel">{$msg_update_photo}</h1>
95+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
96+
</div>
97+
<div class="modal-body">
98+
<div class="alert alert-warning">
99+
{$msg_select_photo}
100+
</div>
101+
<input class="form-control" type="file" id="formFile" name="photo">
102+
</div>
103+
<div class="modal-footer">
104+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
105+
<i class="fa fa-fw fa-cancel"></i> {$msg_cancel}
106+
</button>
107+
<button type="submit" class="btn btn-success">
108+
<i class="fa fa-fw fa-check-square-o"></i> {$msg_submit}
109+
</button>
110+
</div>
111+
</div>
112+
</div>
113+
</form>
114+
</div>
115+
{/if}

0 commit comments

Comments
 (0)