1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public function save(){
if(!_root::getRequest()->isPost() or _root::getParam('formmodule')!=self::$sModuleName ){ //si ce n'est pas une requete POST on ne soumet pas
return null;
}
$oPluginXsrf=new plugin_xsrf();
if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide
return array('token'=>$oPluginXsrf->getMessage() );
}
$iId=module_machines::getParam('id',null);
if($iId==null){
$oMachines=new row_machines;
}else{
$oMachines=model_machines::getInstance()->findById( module_machines::getParam('id',null) );
}
$tId=model_machines::getInstance()->getIdTab();
$tColumn=model_machines::getInstance()->getListColumn();
foreach($tColumn as $sColumn){
if(isset($_FILES[$sColumn]) and $_FILES[$sColumn]['size'] > 0){
$sNewFileName='data/upload/'.$sColumn.'_'.date('Ymdhis');
$oPluginUpload=new plugin_upload($_FILES[$sColumn]);
$oPluginUpload->saveAs($sNewFileName);
$oMachines->$sColumn=$oPluginUpload->getPath();
continue;
}else if( _root::getParam($sColumn,null) ==null ){
continue;
}else if( in_array($sColumn,$tId)){
continue;
}
$oMachines->$sColumn=_root::getParam($sColumn,null) ;
}
if($oMachines->isValid()){
//on force la classe de machines à enregistrer l'id de l'atelier dans la collonne machine_id
$oMachines->atelier_id=_root::getParam('id');
$oMachines->save();
//une fois enregistre on redirige (vers la page liste)
$this->redirect('list');
}else{
return $oMachines->getListError();
}
} |