diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 199a747..70812cf 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -34,7 +34,5 @@ class AppController extends Controller { public $components = array('Security','MiconwareSession'); - function beforeFilter(){ - parent::beforeFilter(); - } + } diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index b6dea94..d56065c 100755 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -21,6 +21,13 @@ class UserController extends AppController { * @throws NotFoundException When the view file could not be found * or MissingViewException in debug mode. */ + function beforeFilter(){ + $this->Security->unlockedActions[]="settings_isearch"; + /*if($this->request->action=="settings_isearch") + $this->Security->=false;*/ + parent::beforeFilter(); + } + public function profil() { $this->MiconwareSession->init($this); @@ -412,11 +419,13 @@ class UserController extends AppController { $this->render('/Home/error'); }else{ if($this->request->is('post')){ - $tosave = array(); - $tosave['DreamjobISerach'] = $this->data['DreamjobISerach']; - var_dump($tosave); - $result = $this->DreamjobISearch->saveMany($tosave); + $tosave = $this->request->data['DreamjobISearch']; + foreach($tosave as $i => $a) + $tosave[$i]['worker_id']=$profil['AppUser']['id']; + $result = $this->DreamjobISearch->saveAndDelete($tosave,$profil['DreamjobISearch']); if($result){ + $this->MiconwareSession->refreshCache(); + $profil = $this->MiconwareSession->getWorker(); $this->MiconwareSession->setFlash('dreamjob.settings.save','flash',array('alert'=>'success')); }else{ $this->MiconwareSession->setFlash('dreamjob.settings.save.error','flash',array('alert'=>'danger')); diff --git a/app/Model/DreamjobISearch.php b/app/Model/DreamjobISearch.php index 50cd983..ccfac06 100644 --- a/app/Model/DreamjobISearch.php +++ b/app/Model/DreamjobISearch.php @@ -34,6 +34,33 @@ class DreamjobISearch extends AppModel { * * @var array */ + public function saveAndDelete($data,$old){ + $dataSource = $this->getDataSource(); + $dataSource->begin(); + + $result = $this->saveMany($data); + if($result){ + $array1 = array(); + $array2 = array(); + foreach($data as $a) + if(isset($a['id'])) + $array1[]=$a['id']; + foreach($old as $a) + if(isset($a['id'])) + $array2[]=$a['id']; + $diff=array_diff($array2, $array1); + if(count($diff)>0) + $result = $this->delete($diff); + } + + if ($result) { + $dataSource->commit(); + return true; + } else { + $dataSource->rollback(); + } + return false; + } public $validate = array( 'worker_id' => array( 'numeric' => array( diff --git a/app/webroot/js/dreamjob.js b/app/webroot/js/dreamjob.js index 378623b..aaa0205 100755 --- a/app/webroot/js/dreamjob.js +++ b/app/webroot/js/dreamjob.js @@ -52,16 +52,12 @@ that = this; newRow = $(".new").html(); $(this).change(function(){ + tosave = true; $("tr",that).each(function(){ see = true; - save = true; $("select",this).each(function(){ if(see) see = $(this).val()==''; - if(save){ - save = $(this).val()!=''; - console.log($(this).val()!=''); - } }); if(see && $(this).attr("data")=="set"){ $(this).attr("data",""); @@ -73,9 +69,20 @@ $(that).append("