upload Image

This commit is contained in:
Martin Müller 2014-04-15 19:47:57 +02:00
parent 87ba3e4ebc
commit b59886c2cf
16 changed files with 162 additions and 47 deletions

2
.gitignore vendored
View File

@ -3,7 +3,7 @@
/app/Config/database.php
/app/Config/email.php
/app/webroot/uploads/
/app/webroot/avatar/
/app/webroot/img/avatar/
/app/webroot/dreamjob/
/app/tmp
/lib/Cake/Console/Templates/skel/tmp/

View File

@ -44,7 +44,7 @@
Router::connect('/settings/pages/:page', array('controller' => 'user', 'action' => 'settings_pageInh'),array("page" => "[0-9]+"));
Router::connect('/settings/isearch', array('controller' => 'user', 'action' => 'settings_isearch'));
Router::connect('/settings/delete', array('controller' => 'user', 'action' => 'profil_delete'));
Router::connect('/settings/img', array('controller' => 'user', 'action' => 'avatar_upload'));
Router::connect('/user/:id', array('controller' => 'user', 'action' => 'profil'),array("id" => "[0-9]+"));
Router::connect('/user/:id/page/:page', array('controller' => 'user', 'action' => 'profil'),array("id" => "[0-9]+","page" => "[0-9]+"));

View File

@ -19,7 +19,8 @@ class MiconwareSessionComponent extends Component {
$controller->set("COMPANY",($this->self_company_obj)?$this->self_company_obj:false);
}
$controller->set("isStaff",$this->isStaff());
$controller->set("MEDIA_URL","/");
$controller->set("MEDIA",'/uploads');
$controller->set("strip_tags",'<p><a><img><span><div>');
$controller->set('default_sForm',array(
'inputDefaults' => array(
'div' => array('class' => 'control-group'),

View File

@ -10,7 +10,7 @@ class UserController extends AppController {
* @var array
*/
public $uses = array('DreamjobListGraducation', 'DreamjobWorker', 'DreamjobCompany', 'DreamjobPageText','DreamjobPageInh', 'DreamjobPageImage', 'DreamjobJobOpening', 'DreamjobCvEntry', 'DreamjobListCvCategory', 'DreamjobListGraducation', 'DreamjobListJob','DreamjobListKindofjob','DreamjobListBranch','Mannerofaddress','DreamjobISearch','User');
public $uses = array('DreamjobListGraducation', 'DreamjobWorker', 'DreamjobCompany', 'DreamjobPageText','DreamjobPageInh', 'DreamjobPageImage', 'DreamjobJobOpening', 'DreamjobCvEntry', 'DreamjobListCvCategory', 'DreamjobListGraducation', 'DreamjobListJob','DreamjobListKindofjob','DreamjobListBranch','Mannerofaddress','DreamjobISearch','User','AppUser');
public $components = array('MiconwareSession','RequestHandler');
/**
@ -500,6 +500,37 @@ class UserController extends AppController {
$this->render('/User/settings_account_delete');
}
}
public function avatar_upload() {
$this->MiconwareSession->init($this);
$this->layout = 'default';
$this->MiconwareSession->initWeb($this);
$this->RequestHandler->setContent('html', 'application/html' );
$profil = $this->MiconwareSession->getApplication('AppUser');
if(empty($profil) or count($profil) <= 0){
$this->MiconwareSession->setFlash(__('dreamjob.error.page.notFound'),'flash',array('alert'=>'danger'));
$this->set('error', 'dreamjob.error.noPermision');
$this->render('/Home/error');
}else{
if($this->request->is('put') or $this->request->is('post')){
$data['AppUser']['id'] = $profil['AppUser']['id'];
$data['AppUser']['take_systemwide'] = $profil['AppUser']['take_systemwide'];
$data['AppUser']['user_id'] = $profil['AppUser']['user_id'];
$data['AppUser']['avatar'] = $this->request->data['AppUser']['avatar'];
$result = $this->AppUser->imageUpload($data);
if($result){
$this->MiconwareSession->setFlash('dreamjob.settings.avatar.done','flash',array('alert'=>'success'));
}else{
$this->MiconwareSession->setFlash('dreamjob.settings.avatar.error','flash',array('alert'=>'danger'));
}
}
$this->request->data = $profil;
$this->render('/User/settings_imageUpload');
}
}
public function test() {
$this->MiconwareSession->init($this);

View File

@ -28,12 +28,40 @@ class AppUser extends AppModel {
* @var string
*/
public $displayField = 'id';
public $uploadDir = 'uploads';
/**
* Validation rules
*
* @var array
*/
public function imageUpload($data){
$dataSource = $this->getDataSource();
$dataSource->begin();
$this->id = $data["AppUser"]['id'];
$this->User->id = $data["AppUser"]['user_id'];
$filename = $this->id . "_-profil.". pathinfo($data[$this->alias]['avatar']['name'], PATHINFO_EXTENSION);
$filename = WWW_ROOT . $this->uploadDir . DS . $filename;
if(file_exists($filename)){
chmod($filename,0755); //Change the file permissions if allowed
unlink($filename); //remove the file
}
if (!move_uploaded_file($data[$this->alias]['avatar']['tmp_name'], $filename)) {
$result = false;
} else {
$result = $this->saveField('avatar', str_replace(DS, "/", str_replace(WWW_ROOT.$this->uploadDir.DS, "", $filename) ));
if($data["AppUser"]['take_systemwide'])
$result = $this->User->saveField('avatar', str_replace(DS, "/", str_replace(WWW_ROOT.$this->uploadDir.DS, "", $filename) ));
}
if ($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
public $validate = array(
'id' => array(
'naturalNumber' => array(

View File

@ -133,10 +133,15 @@ public function saveAndUpload($data){
$filename = $data["DreamjobPageInh"]['user_id'] . "_-page-_" . $this->id .".". pathinfo($data[$this->alias]['image']['name'], PATHINFO_EXTENSION);
$filename = WWW_ROOT . $this->uploadDir . DS . $filename;
if(file_exists($filename)){
chmod($filename,0755); //Change the file permissions if allowed
unlink($filename); //remove the file
}
if (!move_uploaded_file($data[$this->alias]['image']['tmp_name'], $filename)) {
$result = false;
} else {
$this->saveField('image', str_replace(DS, "/", str_replace(WWW_ROOT, "", $filename) ));
$result = $this->saveField('image', str_replace(DS, "/", str_replace(WWW_ROOT.$this->uploadDir.DS, "", $filename) ));
}
}

View File

@ -18,12 +18,17 @@
}
$avatar = false;
$url = '';
if($opening['AppUser']['take_systemwide']){
if($opening['User']['avatar'])
if($opening['User']['avatar']){
$url = $MEDIA.DS.$opening['User']['avatar'];
$avatar = true;
}
}else{
if($opening['AppUser']['avatar'])
if($opening['AppUser']['avatar']){
$url = $MEDIA.DS.$opening['AppUser']['avatar'];
$avatar = true;
}
}
?>
<?php if(!empty($opening_MINI) or !($opening_in_app or $opening_in_fav)){ ?>
@ -46,13 +51,7 @@ if($opening['AppUser']['take_systemwide']){
<div class="icon">
<span><?=$opening['AppUser']['nickname']." ".$opening['DreamjobCompany']['corporateform'];?></span>
<div>
<img src="<?php
if($opening['AppUser']['take_systemwide']){
echo $MEDIA_URL.$opening['User']['avatar'];
}else{
echo $MEDIA_URL.$opening['AppUser']['avatar'];
}
?>"/>
<img src="<?=$url;?>"/>
</div>
</div>
<?php

View File

@ -8,10 +8,10 @@
if(isset($page['DreamjobPageImage'])){
?>
<center>
<img src="<?=$MEDIA_URL.$page['DreamjobPageImage']['image'];?>"/>
<img src="<?=$MEDIA.DS.$page['DreamjobPageImage']['image'];?>"/>
</center>
<?php
}else{
echo $page['DreamjobPageText']['text'];
echo strip_tags($page['DreamjobPageText']['text'],$strip_tags);
}
?>

View File

@ -4,21 +4,28 @@
*/
?>
<div class="columns">
<div class="bar avatar">
<img src="<?php
if($profil['AppUser']['take_systemwide'])
if($profil['User']['avatar'])
echo $MEDIA_URL.$profil['User']['avatar'];
else
echo $STATIC_URL."img/icon_user.png";
<div class="bar avatar">
<?php
$url='img/icon_user.png';
if($profil['AppUser']['take_systemwide'])
if($profil['User']['avatar'])
$url = $MEDIA.DS.$profil['User']['avatar'];
else
if($profil['AppUser']['avatar'])
echo $MEDIA_URL.$profil['AppUser']['avatar'];
else
echo $STATIC_URL."img/icon_user.png";
?>"/>
</div>
<div class="bar">
if($profil['AppUser']['avatar'])
$url = $MEDIA.DS.$profil['AppUser']['avatar'];
?>
<img src="<?=$url;?>"/>
<?php if($edit): ?>
<div class="imgsubtitle edit">
<?php
$link = '<span class="glyphicon glyphicon-picture"></span>'.__('dreamjob.image.edit');
echo $this->Html->link($link,array('controller' => 'user', 'action' => 'avatar_upload'),array('data-target'=>'#popup','data-toggle'=>"modal",'title'=>__('dreamjob.image.edit'),"ref"=>"eventOff",'escape'=>false));
?>
</div>
<?php endif; ?>
</div>
<div class="bar">
<h1>
<?php
if($profil['AppUser']['take_systemwide'])

View File

@ -24,18 +24,17 @@
?>
</h3>
<div class="icon">
<img src="<?php
if($profil[$AppUser]['take_systemwide'])
if($profil[$User]['avatar'])
echo $MEDIA_URL.$profil[$User]['avatar'];
else
echo $STATIC_URL."img/icon_user.png";
else
if($profil[$AppUser]['avatar'])
echo $MEDIA_URL.$profil[$AppUser]['avatar'];
else
echo $STATIC_URL."img/icon_user.png";
?>"/>
<?php
$url='img/icon_user.png';
if($profil[$AppUser]['take_systemwide'])
if($profil[$User]['avatar'])
$url = $MEDIA.DS.$profil[$User]['avatar'];
else
if($profil[$AppUser]['avatar'])
$url = $MEDIA.DS.$profil[$AppUser]['avatar'];
?>
<img src="<?=$url;?>"/>
</div>
<div class="left">
<span><?=__('dreamjob.city').': '.$profil[$DreamjobUser]['city'];?></span>

View File

@ -92,7 +92,7 @@
</span>
</legend>
<div class="text">
<?=$msgitem['text']; ?>
<?=strip_tags($msgitem['text'],$strip_tags); ?>
</div>
</div>

View File

@ -42,9 +42,9 @@
<?=$this->element('job_opening_head_extra');?>
<br/>
<div>
<?=$opening['DreamjobJobOpening']['text'];?>
<?=strip_tags($opening['DreamjobJobOpening']['text'],$strip_tags);?>
</div>
<?php if($WORKER){ ?>
<?php if(!empty($WORKER)){ ?>
<div class="buttonrow">
<?php
echo $this->Html->link(__('dreamjob.applicate'),array('controller'=>'job', 'action'=>'applicationSend', 'id'=> $opening['DreamjobJobOpening']['id']),array("class" => "btn btn-primary"));

View File

@ -12,7 +12,7 @@ if($profil['AppUser']['take_systemwide']){
}
?>
<div class="box-extra">
<?php if($avatar){ ?>
<?php if($avatar or $edit){ ?>
<div class="box-extra-left infofield">
<div class="box">
<img src="<?php
@ -22,6 +22,14 @@ if($profil['AppUser']['take_systemwide']){
echo $MEDIA_URL.$profil['AppUser']['avatar'];
}
?>"/>
<?php if($edit):?>
<div class="imgsubtitle edit">
<?php
$link = '<span class="glyphicon glyphicon-picture"></span>'.__('dreamjob.image.edit');
echo $this->Html->link($link,array('controller' => 'user', 'action' => 'avatar_upload'),array('data-target'=>'#popup','data-toggle'=>"modal",'title'=>__('dreamjob.image.edit'),"ref"=>"eventOff",'escape'=>false));
?>
</div>
<?php endif; ?>
</div>
<?php if(!empty($profil['DreamjobCompany']['website'])){?>
<p>

View File

@ -1,3 +1,8 @@
<?php
/*
*
*/
?>
<div class="box">
<div class="tabs-below">
<ul class="nav nav-tabs pull-right">

View File

@ -0,0 +1,20 @@
<?php
/*
*
*/
?>
<div class="box">
<h1><?=__('dreamjob.image.edit');?></h1>
<?php
$default_Form['type']='file';
echo $this->Form->create('AppUser',$default_Form);
echo $this->Form->input('AppUser.avatar',array('type'=>'file'));
?>
<div class="buttonrow">
<?=$this->Form->button('<span class="glyphicon glyphicon-floppy-disk"></span> '.__('dreamjob.settings.save'),array('div' => false,'class'=>"btn btn-primary ",'type' => 'submit'));?>
</div>
<?php
echo $this->Form->end();
?>
</div>

View File

@ -419,3 +419,15 @@ body.loading #container{
display:none;
}
.imgsubtitle.edit{
background:rgba(0,0,0,0.8);
color:white;
width:200px;
float:none;
height:20px;
margin-top:-20px;
position:absolute;
}
.imgsubtitle.edit a{
color:white;
}