diff --git a/.gitignore b/.gitignore index 18815d1..e4b97a9 100755 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/app/Config/routes.php b/app/Config/routes.php index c7935a0..555ddf0 100755 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -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]+")); diff --git a/app/Controller/Component/MiconwareSessionComponent.php b/app/Controller/Component/MiconwareSessionComponent.php index 3f0300b..5fa1cde 100755 --- a/app/Controller/Component/MiconwareSessionComponent.php +++ b/app/Controller/Component/MiconwareSessionComponent.php @@ -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",'

'); $controller->set('default_sForm',array( 'inputDefaults' => array( 'div' => array('class' => 'control-group'), diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index b572eb9..5840fa9 100755 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -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); diff --git a/app/Model/AppUser.php b/app/Model/AppUser.php index b5a79ca..ccdc641 100755 --- a/app/Model/AppUser.php +++ b/app/Model/AppUser.php @@ -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( diff --git a/app/Model/DreamjobPageImage.php b/app/Model/DreamjobPageImage.php index a52a385..5e28520 100644 --- a/app/Model/DreamjobPageImage.php +++ b/app/Model/DreamjobPageImage.php @@ -132,11 +132,16 @@ public function saveAndUpload($data){ if($result){ $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) )); } } diff --git a/app/View/Elements/job_opening_item.ctp b/app/View/Elements/job_opening_item.ctp index ca44f17..a214ee5 100644 --- a/app/View/Elements/job_opening_item.ctp +++ b/app/View/Elements/job_opening_item.ctp @@ -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; + } } ?> @@ -46,13 +51,7 @@ if($opening['AppUser']['take_systemwide']){
- +
- +
diff --git a/app/View/Elements/user_worker_header.ctp b/app/View/Elements/user_worker_header.ctp index 54285bb..a9af000 100644 --- a/app/View/Elements/user_worker_header.ctp +++ b/app/View/Elements/user_worker_header.ctp @@ -4,21 +4,28 @@ */ ?>
-
- + "/> -
-
+ if($profil['AppUser']['avatar']) + $url = $MEDIA.DS.$profil['AppUser']['avatar']; + + ?> + + +
+ '.__('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)); + ?> +
+ +
+

- "/> + +
diff --git a/app/View/Job/application.ctp b/app/View/Job/application.ctp index 16c7aac..2bc881d 100644 --- a/app/View/Job/application.ctp +++ b/app/View/Job/application.ctp @@ -92,7 +92,7 @@
- +
diff --git a/app/View/Job/opening.ctp b/app/View/Job/opening.ctp index 5229142..eb56cbf 100644 --- a/app/View/Job/opening.ctp +++ b/app/View/Job/opening.ctp @@ -42,9 +42,9 @@ element('job_opening_head_extra');?>
- +
- +
Html->link(__('dreamjob.applicate'),array('controller'=>'job', 'action'=>'applicationSend', 'id'=> $opening['DreamjobJobOpening']['id']),array("class" => "btn btn-primary")); diff --git a/app/View/User/company.ctp b/app/View/User/company.ctp index a281eef..4f34e97 100644 --- a/app/View/User/company.ctp +++ b/app/View/User/company.ctp @@ -12,7 +12,7 @@ if($profil['AppUser']['take_systemwide']){ } ?>
- +
+ +
+ '.__('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)); + ?> +
+

diff --git a/app/View/User/settings_account_delete.ctp b/app/View/User/settings_account_delete.ctp index cc36fdd..ed600a0 100644 --- a/app/View/User/settings_account_delete.ctp +++ b/app/View/User/settings_account_delete.ctp @@ -1,3 +1,8 @@ +