--- /dev/null
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Displays a picture
+ *
+ * PHP version 5
+ *
+ * Copyright © 2004-2011 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Main
+ * @package Galette
+ *
+ * @author Frédéric Jaqcuot <unknown@unknow.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2004-2011 The Galette Team
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version SVN: $Id: picture.php 877 2011-06-01 06:08:18Z trashy $
+ * @link http://galette.tuxfamily.org
+ * @since Available since 0.62
+ */
+
+/** @ignore */
+require_once 'includes/galette.inc.php';
+
+if ( !$login->isLogged() || !$login->isAdmin() && !$login->isStaff() ) {
+ $log->log(
+ 'Trying to display ajax_members.php without appropriate permissions',
+ PEAR_LOG_INFO
+ );
+ die();
+}
+
+require_once 'classes/adherent.class.php';
+
+if ( !isset($_POST)
+ || !isset($_POST['member_id'])
+ || !isset($_POST['file'])
+ || !isset($_POST['filename'])
+ || !isset($_POST['filesize'])
+) {
+ die('Required argument not present.');
+}
+
+$mid = $_POST['member_id'];
+$fsize = $_POST['filesize'];
+$fname = $_POST['filename'];
+$tmpname = GALETTE_TEMPIMAGES_PATH . 'ajax_upload_' . $fname;
+
+$temp = explode('base64,', $_POST['file']);
+$mime = str_replace('data:', '', trim($temp[0], ';'));
+$raw_file = base64_decode($temp[1]);
+
+//write temporary file
+$fp = fopen($tmpname, 'w');
+fwrite($fp, $raw_file);
+fclose($fp);
+
+$adh = new Adherent((int)$mid);
+
+$ret = array();
+$res = $adh->picture->store(
+ array(
+ 'name' => $fname,
+ 'tmp_name' => $tmpname,
+ 'size' => $fsize
+ ),
+ true
+);
+if ( $res < 0 ) {
+ $ret['result'] = false;
+ $ret['message'] = $adh->picture->getErrorMessage($res);
+} else {
+ $ret['result'] = true;
+}
+
+echo json_encode($ret);
+?>
/**
* Stores an image on the disk and in the database
*
- * @param object $file the uploaded file
+ * @param object $file the uploaded file
+ * @param boolean $ajax If the image cames from an ajax call (dnd)
*
* @return true|false result of the storage process
*/
- public function store($file)
+ public function store($file, $ajax = false)
{
/** TODO:
- fix max size (by preferences ?)
$new_file = $this->store_path .
$this->id . '.' . $extension;
- move_uploaded_file($tmpfile, $new_file);
+ if ( $ajax === true ) {
+ rename($tmpfile, $new_file);
+ } else {
+ move_uploaded_file($tmpfile, $new_file);
+ }
// current[0] gives width ; current[1] gives height
if ( $current[0] > $this->max_width || $current[1] > $this->max_height ) {
if ( !defined('GALETTE_PHOTOS_PATH') ) {
define('GALETTE_PHOTOS_PATH', WEB_ROOT . 'photos/');
}
+if ( !defined('GALETTE_TEMPIMAGES_PATH') ) {
+ define('GALETTE_TEMPIMAGES_PATH', WEB_ROOT . 'tempimages/');
+}
?>
margin-bottom: 5px;
}
+.dndhover {
+ opacity:0.4;
+}
+
#details_menu{
padding:0;
text-align:center;
{if !$self_adh}
<p>
<span class="bline">{_T string="Picture:"}</span>
- <img src="{$galette_base_path}picture.php?id_adh={$member->id}&rand={$time}" class="picture" width="{$member->picture->getOptimalWidth()}" height="{$member->picture->getOptimalHeight()}" alt="{_T string="Picture"}"/><br/>
+ <img id="photo_adh" src="{$galette_base_path}picture.php?id_adh={$member->id}&rand={$time}" class="picture" width="{$member->picture->getOptimalWidth()}" height="{$member->picture->getOptimalHeight()}" alt="{_T string="Picture"}"/><br/>
{if $member->hasPicture() eq 1 }
<span class="labelalign"><label for="del_photo">{_T string="Delete image"}</label></span><input type="checkbox" name="del_photo" id="del_photo" value="1"/><br/>
{/if}
{rdelim});
{rdelim}
+
+ {include file="photo_dnd.tpl"}
{rdelim});
</script>
{/if}
\ No newline at end of file
--- /dev/null
+ //Photo dnd
+ // Check if window.FileReader exists to make
+ // sure the browser supports file uploads
+ if ( typeof(window.FileReader) ) {ldelim}
+ var _dz = $('#photo_adh');
+
+ // Add a nice drag effect
+ _dz[0].ondragover = function() {ldelim}
+ _dz.addClass('dndhover');
+ return false;
+ {rdelim};
+
+ // Remove the drag effect when stopping our drag
+ _dz[0].ondragend = function() {ldelim}
+ _dz.removeClass('dndhover');
+ return false;
+ {rdelim};
+
+ // The drop event handles the file sending
+ _dz[0].ondrop = function(event) {ldelim}
+ // Stop the browser from opening the file in the window
+ event.preventDefault();
+ _dz.removeClass('dndhover');
+
+ var file = event.dataTransfer.files[0];
+ var reader = new FileReader();
+ reader.readAsDataURL(file);
+
+ reader.onload = function(evt) {ldelim}
+ $.ajax({ldelim}
+ type: 'POST',
+ dataType: 'json',
+ url : 'ajax_photo.php',
+ data: {ldelim}
+ member_id: {$member->id},
+ filename: file.name,
+ filesize: file.size,
+ file: evt.target.result
+ {rdelim},
+ success: function(res){ldelim}
+ if ( res.result == true ) {ldelim}
+ d = new Date();
+ var _photo = $('#photo_adh');
+ _photo.removeAttr('width').removeAttr('height');
+ _photo.attr('src', $('#photo_adh')[0].src + '&' + d.getTime());
+ alert('{_T string="Member photo has been changed."}');
+ {rdelim} else {ldelim}
+ alert(res.message);
+ {rdelim}
+ {rdelim},
+ error: function() {ldelim}
+ alert("{_T string="An error occured sending photo :(" escape="js"}");
+ {rdelim}
+ {rdelim});
+ {rdelim}
+ {rdelim}
+ {rdelim}
src="{$galette_base_path}picture.php?id_adh={$member->id}&rand={$time}"
width="{$member->picture->getOptimalWidth()}"
height="{$member->picture->getOptimalHeight()}"
- alt="{_T string="Picture"}"/>
+ alt="{_T string="Picture"}"
+ id="photo_adh"/>
</td>
</tr>
{if $member->isCompany()}
{include file="display_dynamic_fields.tpl" is_form=false}
</div>
+{if $login->isAdmin() or $login->isStaff() or $login->login eq $member->login}
+ <script type="text/javascript">
+ $(function() {ldelim}
+ {include file="photo_dnd.tpl"}
+ {rdelim});
+ </script>
+{/if}
\ No newline at end of file