Beispiel #1
0
 public function processSave()
 {
     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_posts::getParam('id', null);
     if ($iId == null) {
         $oPosts = new row_posts();
     } else {
         $oPosts = model_posts::getInstance()->findById(module_posts::getParam('id', null));
     }
     $tId = model_posts::getInstance()->getIdTab();
     $tColumn = model_posts::getInstance()->getListColumn();
     foreach ($tColumn as $sColumn) {
         $oPluginUpload = new plugin_upload($sColumn);
         if ($oPluginUpload->isValid()) {
             $sNewFileName = _root::getConfigVar('path.upload') . $sColumn . '_' . date('Ymdhis');
             $oPluginUpload->saveAs($sNewFileName);
             $oPosts->{$sColumn} = $oPluginUpload->getPath();
             continue;
         } else {
             if (_root::getParam($sColumn, null) === null) {
                 continue;
             } else {
                 if (in_array($sColumn, $tId)) {
                     continue;
                 }
             }
         }
         $oPosts->{$sColumn} = _root::getParam($sColumn, null);
     }
     if ($oPosts->save()) {
         //une fois enregistre on redirige (vers la page liste)
         $this->redirect('list');
     } else {
         return $oPosts->getListError();
     }
 }
Beispiel #2
0
 public function processDelete()
 {
     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());
     }
     $oPosts = model_posts::getInstance()->findById(_root::getParam('id', null));
     $oPosts->delete();
     //une fois enregistre on redirige (vers la page liste)
     _root::redirect('privatePosts::list');
 }