コード例 #1
0
ファイル: main.php プロジェクト: clavat/mkframework
 public function save()
 {
     if (!_root::getRequest()->isPost()) {
         //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());
     }
     $oAccountModel = new model_account();
     $iId = _root::getParam('id', null);
     if ($iId == null) {
         $oAccount = new row_account();
     } else {
         $oAccount = $oAccountModel->findById(_root::getParam('id', null));
     }
     foreach ($oAccountModel->getListColumn() as $sColumn) {
         if (_root::getParam($sColumn, null) == null) {
             continue;
         }
         if (in_array($sColumn, $oAccountModel->getIdTab())) {
             continue;
         }
         $oAccount->{$sColumn} = _root::getParam($sColumn, null);
     }
     $oAccount->pass = sha1(_root::getParam('pass'));
     if ($oAccount->save()) {
         //une fois enregistre on redirige (vers la page d'edition)
         _root::redirect('account::list');
     } else {
         return $oAccount->getListError();
     }
 }