protected function projectSaveFile($sContent, $sFilename)
 {
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/' . $sFilename);
     if ($oFile->exist()) {
         return false;
     }
     $oFile->setContent($sContent);
     $oFile->save();
     $oFile->chmod(0666);
 }
示例#2
0
 private function genModuleMain($sModule, $tAction)
 {
     $sContent = module_builder::getTools()->stringReplaceIn(array('_examplemodule' => '_' . $sModule), 'data/sources/projet/module/example/main.php');
     preg_match_all('/#debutaction#(.*)?#finaction#/s', $sContent, $tMatch);
     $sMethodeSource = $tMatch[1][0];
     $sMethodes = '';
     foreach ($tAction as $sAction) {
         $sAction = trim($sAction);
         if ($sAction == '') {
             continue;
         }
         $sMethodes .= preg_replace('/examplemodule/', $sModule, preg_replace('/exampleaction/', $sAction, $sMethodeSource));
         $oFileTpl = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModule . '/view/' . $sAction . '.php');
         $oFileTpl->setContent('vue ' . $sModule . '::' . $sAction);
         $oFileTpl->save();
         $oFileTpl->chmod(0666);
     }
     $sContent = preg_replace('/\\/\\/ICI--/', $sMethodes, $sContent);
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModule . '/main.php');
     $oFile->setContent($sContent);
     $oFile->save();
     $oFile->chmod(0666);
 }
示例#3
0
 public function genModelTplCrudembeddedReadonly($sModule, $sClass, $tColumn, $sTableName)
 {
     //$tColumn=_root::getParam('tColumn');
     $tType = _root::getParam('tType');
     $tTpl = array('list', 'show');
     foreach ($tTpl as $sTpl) {
         $oFile = new _file('data/sources/fichiers/module/crudembeddedreadonly/view/' . $sTpl . '.php');
         $sContent = $oFile->getContent();
         preg_match_all('/#lignetd(.*)?#fin_lignetd/s', $sContent, $tMatch);
         $sLigne = $tMatch[1][0];
         preg_match_all('/#input(.*)?#fin_input/s', $sContent, $tMatch);
         $sInputText = $tMatch[1][0];
         preg_match_all('/#textarea(.*)?#fin_textarea/s', $sContent, $tMatch);
         $sInputTextarea = $tMatch[1][0];
         preg_match_all('/#select(.*)?#fin_select/s', $sContent, $tMatch);
         $sInputSelect = $tMatch[1][0];
         preg_match_all('/#upload(.*)?#fin_upload/s', $sContent, $tMatch);
         $sInputUpload = $tMatch[1][0];
         if ($sTpl == 'list') {
             //TH
             preg_match_all('/#ligneth(.*)?#fin_ligneth/s', $sContent, $tMatch);
             $sLigneTH = $tMatch[1][0];
         }
         $sTable = '';
         $sTableTh = '';
         $sEnctype = '';
         foreach ($tColumn as $i => $sColumn) {
             $sType = $tType[$i];
             if ($sType == 'text' or $sType == 'date') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputText);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
             } elseif ($sType == 'textarea') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputTextarea);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
             } elseif (substr($sType, 0, 7) == 'select;') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputSelect);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
                 $sInput = preg_replace('/examplemodel/', substr($sType, 7), $sInput);
             } elseif ($sType == 'upload') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputUpload);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
                 $sEnctype = ' enctype="multipart/form-data"';
                 //changement du enctype du formulaire
             }
             $sTable .= preg_replace('/examplecolumn/', $sColumn, preg_replace('/exampletd/', $sInput, $sLigne));
             $sTableTh .= preg_replace('/exampleth/', $sColumn, $sLigneTH);
         }
         $sContent = module_builder::getTools()->stringReplaceIn(array('oExamplemodel' => 'o' . ucfirst($sTableName), 'tExamplemodel' => 't' . ucfirst($sTableName), 'examplemodule' => $sModule, '<\\?php \\/\\/enctype\\?>' => $sEnctype, '<\\?php \\/\\/ici\\?>' => $sTable, '<\\?php \\/\\/icith\\?>' => $sTableTh, '<\\?php\\/\\*variables(.*)variables\\*\\/\\?>' => ''), 'data/sources/fichiers/module/crudembeddedreadonly/view/' . $sTpl . '.php');
         $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModule . '/view/' . $sTpl . '.php');
         $oFile->setContent($sContent);
         $oFile->save();
         $oFile->chmod(0777);
     }
 }
示例#4
0
 private function genModelTpl($sModule, $sClass, $tColumn, $sTableName, $tCrud, $tLabel)
 {
     //$tColumn=_root::getParam('tColumn');
     $tType = _root::getParam('tType');
     $tCrud[] = 'list';
     $tTpl = array('list', 'show', 'edit', 'new', 'delete');
     $tTplCrud = array('show' => 'crudShow', 'new' => 'crudNew', 'delete' => 'crudDelete', 'edit' => 'crudEdit', 'list' => 'list');
     foreach ($tTpl as $sTpl) {
         //print $sTpl;
         if (!in_array($tTplCrud[$sTpl], $tCrud)) {
             //print "skip $sTpl ";
             continue;
         }
         $oFile = new _file('data/sources/fichiers/module/crudBootstrap/view/' . $sTpl . '.php');
         $sContent = $oFile->getContent();
         $oVar = simplexml_load_file('data/sources/fichiers/module/crudBootstrap/view/' . $sTpl . '.php.xml');
         $sLigne = (string) $oVar->lignetd;
         $sInputText = (string) $oVar->input;
         $sInputTextarea = (string) $oVar->textarea;
         $sInputSelect = (string) $oVar->select;
         $sInputUpload = (string) $oVar->upload;
         $sLinks = '';
         $sLinkNew = '';
         if ($sTpl == 'list') {
             //TH
             $sLigneTH = (string) $oVar->ligneth;
             //liens
             $tLink['crudNew'] = (string) $oVar->linkNew;
             $tLink['crudEdit'] = (string) $oVar->linkEdit;
             $tLink['crudShow'] = (string) $oVar->linkShow;
             $tLink['crudDelete'] = (string) $oVar->linkDelete;
             $iMaxCrud = count($tCrud);
             $iMaxCrud -= 2;
             foreach ($tCrud as $i => $sAction) {
                 if (in_array($sAction, array('crudNew', 'list'))) {
                     continue;
                 }
                 if (!isset($tLink[$sAction])) {
                     continue;
                 }
                 $sLinks .= $tLink[$sAction];
                 if ($i < $iMaxCrud) {
                     //$sLinks .= '| ';
                 }
             }
             if (in_array('crudNew', $tCrud)) {
                 $sLinkNew = $tLink['crudNew'];
             }
         }
         $sTable = '';
         $sTableTh = '';
         $sEnctype = '';
         foreach ($tColumn as $i => $sColumn) {
             $sLabel = $tLabel[$i];
             $sType = $tType[$i];
             if ($sType == 'text' or $sType == 'date') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputText);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
             } elseif ($sType == 'textarea') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputTextarea);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
             } elseif (substr($sType, 0, 7) == 'select;') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputSelect);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
                 $sInput = preg_replace('/examplemodel/', substr($sType, 7), $sInput);
             } elseif ($sType == 'upload') {
                 $sInput = preg_replace('/examplecolumn/', $sColumn, $sInputUpload);
                 $sInput = preg_replace('/oExamplemodel/', 'o' . ucfirst($sTableName), $sInput);
                 $sEnctype = ' enctype="multipart/form-data"';
                 //changement du enctype du formulaire
             }
             $sTable .= preg_replace('/examplecolumn/', $sLabel, preg_replace('/exampletd/', $sInput, $sLigne));
             $sTableTh .= preg_replace('/exampleth/', $sLabel, $sLigneTH);
         }
         $tReplace = array('<\\?php \\/\\/linknew\\?>' => $sLinkNew, '<\\?php \\/\\/links\\?>' => $sLinks, 'oExamplemodel' => 'o' . ucfirst($sTableName), 'tExamplemodel' => 't' . ucfirst($sTableName), 'examplemodule' => $sModule, '<\\?php \\/\\/enctype\\?>' => $sEnctype, '<\\?php \\/\\/ici\\?>' => $sTable, '<\\?php \\/\\/icith\\?>' => $sTableTh, '<\\?php \\/\\/colspan\\?>' => count($tColumn) + 1);
         $sContent = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/crudBootstrap/view/' . $sTpl . '.php');
         $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModule . '/view/' . $sTpl . '.php');
         $oFile->setContent($sContent);
         $oFile->save();
         $oFile->chmod(0666);
     }
 }
示例#5
0
 private function genModuleMenuMain($sModuleMenuName, $tMethod, $tLabel)
 {
     $sData = null;
     foreach ($tMethod as $i => $sLink) {
         $sData .= '\'' . $tLabel[$i] . '\' => \'' . $sLink . '\',' . "\n";
     }
     $oMainFile = new _file('data/sources/fichiers/module/menuBootstrap/main.php');
     $sContentMain = $oMainFile->getContent();
     $sContentMain = preg_replace('/\\/\\/TABLEAUICI/', $sData, $sContentMain);
     $sContentMain = preg_replace('/examplemenu/', $sModuleMenuName, $sContentMain);
     $oFileTpl = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleMenuName . '/main.php');
     $oFileTpl->setContent($sContentMain);
     $oFileTpl->save();
     $oFileTpl->chmod(0666);
     $oViewFile = new _file('data/sources/fichiers/module/menuBootstrap/view/index.php');
     $sContentView = $oViewFile->getContent();
     $oFileTpl2 = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleMenuName . '/view/index.php');
     $oFileTpl2->setContent($sContentView);
     $oFileTpl2->save();
     $oFileTpl2->chmod(0666);
     //update title
     $oTools = new module_builderTools();
     $oTools->updateFile(_root::getParam('id'), array('examplesite' => _root::getParam('id')), 'module/' . $sModuleMenuName . '/view/index.php');
 }
示例#6
0
 public function updateFile($sProject, $tMatch, $sFile)
 {
     $sContent = $this->stringReplaceIn($tMatch, _root::getConfigVar('path.generation') . $sProject . '/' . $sFile);
     $oFile = new _file(_root::getConfigVar('path.generation') . $sProject . '/' . $sFile);
     $oFile->setContent($sContent);
     $oFile->save();
     $oFile->chmod(0666);
 }
示例#7
0
 private function generate()
 {
     if (!_root::getRequest()->isPost() or _root::getParam('formu') != 'generate') {
         return null;
     }
     $oPluginValid = new plugin_valid(_root::getRequest()->getParams());
     $oPluginValid->isNotEmpty('modulename', 'Le champ doit &ecirc;tre rempli');
     $oPluginValid->isNotEmpty('classmodel', 'Le champ doit &ecirc;tre rempli');
     $oPluginValid->isNotEmpty('redirect', 'Le champ doit &ecirc;tre rempli');
     if (!$oPluginValid->isValid()) {
         return $oPluginValid->getListError();
     }
     $sModuleName = _root::getParam('modulename');
     $sClassModuleName = 'module_' . $sModuleName;
     $sRedirectModuleAction = _root::getParam('redirect');
     $sModelName = _root::getParam('classmodel');
     $sViewName = $sModuleName . '::login';
     $sContent = module_builder::getTools()->stringReplaceIn(array('module_exampleauth' => $sClassModuleName, 'privatemodule_action' => $sRedirectModuleAction, 'model_example' => $sModelName, 'auth_login' => $sViewName), 'data/sources/fichiers/module/auth/main.php');
     module_builder::getTools()->projetmkdir('module/' . $sModuleName);
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleName . '/main.php');
     $oFile->setContent($sContent);
     $oFile->save();
     $oFile->chmod(0666);
     module_builder::getTools()->projetmkdir('module/' . $sModuleName . '/view');
     $oFile = new _file('data/sources/fichiers/module/auth/view/login.php');
     $sContent = $oFile->getContent();
     $oNewViewFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleName . '/view/login.php');
     $oNewViewFile->setContent($sContent);
     $oNewViewFile->save();
     return array('success' => 1);
 }
示例#8
0
    private function processSimple()
    {
        if (!_root::getRequest()->isPost()) {
            return array(null, null);
        }
        $ret = "\n";
        $t = "\t";
        $sModule = _root::getParam('module');
        $sView = _root::getParam('view');
        $tEnable = _root::getParam('tEnable');
        $tColumn = _root::getParam('tColumn');
        $tLabel = _root::getParam('tLabel');
        $tType = _root::getParam('tType');
        $sModel = _root::getParam('class');
        $sModel = str_replace('.php', '', $sModel);
        $sId = _root::getParam('sId');
        $sViewContent = '<?php ';
        $sViewContent .= $ret;
        $sViewContent .= '$oForm = new plugin_form($this->oData);' . $ret;
        $sViewContent .= '$oForm->setMessage($this->tMessage);' . $ret;
        $sViewContent .= '?>';
        $sViewContent .= $ret;
        $sViewContent .= '<form action="" method="POST" />' . $ret;
        $sViewContent .= '<table class="tb_edit">' . $ret;
        foreach ($tColumn as $i => $sColumn) {
            if (!in_array($sColumn, $tEnable)) {
                continue;
            }
            $tVar = array();
            if ($tType[$i] == 'text') {
                $sFormInput = '<?php echo $oForm->getInputText(\'' . $sColumn . '\');?>';
            } else {
                if ($tType[$i] == 'textarea') {
                    $sFormInput = '<?php echo $oForm->getInputTextarea(\'' . $sColumn . '\');?>';
                } else {
                    if (substr($tType[$i], 0, 6) == 'select') {
                        $tVar[] = $t . '$oView->tJoin' . $sColumn . '=' . substr($tType[$i], 7) . '::getInstance()->getSelect();';
                        $sFormInput = '<?php echo $oForm->getSelect(\'' . $sColumn . '\',$this->tJoin' . $sColumn . ');?>';
                    } else {
                        if ($tType[$i] == 'upload') {
                            $sFormInput = '<input type="file" name="<?php echo $' . $sColumn . ';?>"/>';
                        } else {
                            $sFormInput = 'getInputText(\'' . $sColumn . '\')';
                        }
                    }
                }
            }
            $sViewContent .= $t . '<tr>' . $ret;
            $sViewContent .= $t . $t . '<th>' . $tLabel[$i] . '</th>' . $ret;
            $sViewContent .= $t . $t . '<td>' . $sFormInput . '</td>' . $ret;
            $sViewContent .= $t . '</tr>' . $ret;
        }
        $sViewContent .= '</table>' . $ret;
        $sViewContent .= '<p> <input type="submit" value="Modifier" /> </p>' . $ret;
        $sViewContent .= '<?php echo $oForm->getToken(\'token\',$this->token)?>' . $ret;
        $sViewContent .= '</form>' . $ret;
        $oFile = new _file('data/genere/' . _root::getParam('id') . '/module/' . $sModule . '/view/' . $sView . '.php');
        if ($oFile->exist()) {
            return array('Vue deja existante', null);
        }
        $oFile->setContent($sViewContent);
        $oFile->save();
        $oFile->chmod(0666);
        $sModel = str_replace('.php', '', $sModel);
        $msg = 'Vue ' . $sView . '.php' . ' g&eacute;n&eacute;r&eacute; avec succ&egrave;s';
        $detail = '';
        $detail .= 'Cr&eacute;ation fichier module/' . $sModule . '/view/' . $sView . '.php ';
        $sCode = '<?php ' . "\n";
        $sCode .= 'public function _edit(){' . $ret;
        $sCode .= $t . '$tMessage=$this->processSave();' . $ret;
        $sCode .= $t . '//recupere l\'enregistrement' . "\n";
        $sCode .= $t . '$oData=' . $sModel . '::getInstance()->findById(_root::getParam(\'id\'));' . $ret . $ret;
        $sColumn = '';
        if ($tEnable) {
            foreach ($tEnable as $sEnable) {
                $sColumn .= ',' . "'" . $sEnable . "'";
            }
            $sColumn = substr($sColumn, 1);
        }
        $sCode .= $t . '//recupere la vue du module' . "\n";
        $sCode .= $t . '$oView=new _view(\'' . $sModule . '::' . $sView . '\');' . "\n";
        $sCode .= $t . '$oView->oData=$oData;' . $ret;
        $sCode .= $t . '$oView->tMessage=$tMessage;' . $ret;
        $sCode .= $ret;
        $sCode .= $t . '$oPluginXsrf=new plugin_xsrf();' . $ret;
        $sCode .= $t . '$oView->token=$oPluginXsrf->getToken();' . $ret;
        if ($tVar) {
            foreach ($tVar as $sVar) {
                $sCode .= $sVar . $ret;
            }
        }
        $sCode .= "\n";
        $sCode .= $t . '//assigner la vue retournee a votre layout' . "\n";
        $sCode .= $t . '$this->oLayout->add(\'main\',$oView);' . "\n";
        $sCode .= '}' . $ret;
        $sCode .= 'private function processSave(){' . $ret;
        //post
        $sCode .= $t . 'if(!_root::getRequest()->isPost()){' . $ret;
        $sCode .= $t . $t . 'return null;' . $ret;
        $sCode .= $t . '}' . $ret;
        $sCode .= $ret;
        $sCode .= $t . '$oPluginXsrf=new plugin_xsrf();' . $ret;
        $sCode .= $t . 'if(!$oPluginXsrf->checkToken( _root::getParam(\'token\') ) ){ //on verifie que le token est valide' . $ret;
        $sCode .= $t . $t . 'return array(\'token\'=>$oPluginXsrf->getMessage() );' . $ret;
        $sCode .= $t . '}' . $ret;
        $sCode .= $t . '$oData=' . $sModel . '::getInstance()->findById(_root::getParam(\'id\'));' . $ret . $ret;
        $sCode .= $t . '$tColumn=array(' . $sColumn . ');' . $ret;
        $sCode .= $t . 'foreach($tColumn as $sColumn){' . $ret;
        $sCode .= $t . $t . '$oData->$sColumn=_root::getParam($sColumn);' . $ret;
        $sCode .= $t . '}' . $ret;
        $sCode .= $t . 'if($oData->save() ){' . $ret;
        $sCode .= $t . $t . '//redirection vers la page d\'apres' . $ret;
        $sCode .= $t . '}else{' . $ret;
        $sCode .= $t . $t . '$tMessage=$oData->getListError();' . $ret;
        $sCode .= $t . '}' . $ret;
        $sCode .= '}' . $ret . $ret;
        $detail .= '<br/><br/>Pour l\'utiliser, indiquez dans votre module:<br />
		' . highlight_string($sCode, 1);
        return array($msg, $detail);
    }
示例#9
0
文件: main.php 项目: clavat/mkMarket
    private function processComplexWithOrder()
    {
        if (!_root::getRequest()->isPost()) {
            return array(null, null);
        }
        if (_root::getParam('model') == '' or _root::getParam('method') == '') {
            return array(null, null);
        }
        if (!file_exists('data/genere/' . _root::getParam('id') . '/module/table')) {
            //copie module table + images
            $this->importModuleTable();
        }
        $sModule = _root::getParam('module');
        $sView = _root::getParam('view');
        $tableClass = _root::getParam('tableClass');
        $enableAlt = _root::getParam('enableAlt');
        $sModel = _root::getParam('model');
        $sMethod = _root::getParam('method');
        $arrayAlt = _root::getParam('arrayAlt');
        $tColumn = _root::getParam('tColumn');
        $tLabel = _root::getParam('tLabel');
        $tType = _root::getParam('tType');
        $tEnable = _root::getParam('tEnable');
        $tOrderEnable = _root::getParam('tOrderEnable');
        $defaultOrder = _root::getParam('tOrderDefault');
        foreach ($tColumn as $i => $sColumn) {
            if (!in_array($sColumn, $tEnable)) {
                unset($tColumn[$i]);
                unset($tLabel[$i]);
            }
        }
        $ret = "\n";
        $t = "\t";
        $sViewContent = '<?php ' . $ret;
        $sViewContent .= '$oTable = new module_table(\'complex1\');' . $ret;
        $sViewContent .= '$oTable->setClass(\'' . $tableClass . '\');' . $ret;
        if (!$enableAlt) {
            $sViewContent .= '/*';
        }
        $sViewContent .= '$oTable->setCycleClass( ' . var_export($arrayAlt, true) . ');' . $ret;
        if (!$enableAlt) {
            $sViewContent .= '*/';
        }
        //header
        $sViewContent .= $ret;
        foreach ($tLabel as $i => $sLabel) {
            if (in_array($tColumn[$i], $tOrderEnable)) {
                $sViewContent .= '$oTable->addHeaderWithOrder(\'' . $sLabel . '\',\'' . $tColumn[$i] . '\');' . $ret;
            } else {
                $sViewContent .= '$oTable->addHeader(\'' . $sLabel . '\');' . $ret;
            }
        }
        $sViewContent .= $ret;
        $sViewContent .= 'if($this->tData){' . $ret;
        $sViewContent .= $t . 'foreach($this->tData as $oData){' . $ret;
        $sViewContent .= $t . $t . '$oTable->addLine(array(' . $ret;
        foreach ($tColumn as $sColumn) {
            $sViewContent .= $t . $t . $t . '$oData->' . $sColumn . ',' . $ret;
        }
        $sViewContent .= $t . $t . '));' . $ret;
        $sViewContent .= $t . '}' . $ret;
        $sViewContent .= '}' . $ret;
        $sViewContent .= $ret;
        $sViewContent .= 'echo $oTable->build()->show();';
        $oFile = new _file('data/genere/' . _root::getParam('id') . '/module/' . $sModule . '/view/' . $sView . '.php');
        if ($oFile->exist()) {
            //return array('Vue deja existante',null);
        }
        $oFile->setContent($sViewContent);
        $oFile->save();
        $oFile->chmod(0666);
        $msg = 'Vue ' . $sView . '.php' . ' g&eacute;n&eacute;r&eacute; avec succ&egrave;s';
        $detail = '';
        $detail .= 'Cr&eacute;ation fichier module/' . $sModule . '/view/' . $sView . '.php ';
        $sCode = '<?php ' . "\n";
        $sCode .= '//recupere les enregistrements avec en parametre le champ de tri + le sens' . "\n";
        $sCode .= '$tData=new ' . $sModel . '::getInstance()->' . $sMethod . '(module_table::getParam(\'order\',\'' . $defaultOrder . '\'),module_table::getParam(\'side\',\'ASC\'));' . $ret;
        $sCode .= '//recupere la vue du module' . "\n";
        $sCode .= '$oView=new _view(\'' . $sModule . '::' . $sView . '\');' . "\n";
        $sCode .= '$oView->tData=$tData;' . $ret;
        $sCode .= "\n";
        $sCode .= '//assigner la vue retournee a votre layout' . "\n";
        $sCode .= '$this->oLayout->add(\'main\',$oView);' . "\n";
        $detail .= '<br/><br/>Pour l\'utiliser, indiquez dans votre module:<br />
		' . highlight_string($sCode, 1);
        return array($msg, $detail);
    }
示例#10
0
 private function processIndex()
 {
     if (!_root::getRequest()->isPost() or _root::getParam('actioncode') != 'generate') {
         return null;
     }
     $tField = $this->tField;
     $oValid = new plugin_valid(_root::getRequest()->getParams());
     foreach ($tField as $sField) {
         $oValid->isLongerOrEqualThan($sField, 2, 'obligatoire');
     }
     if (!$oValid->isValid()) {
         return $oValid->getListError();
     }
     //ok
     $sClassModelRightsManager = 'model_' . _root::getParam('modelToGenerate');
     $sClassRowRightsManager = 'row_' . _root::getParam('modelToGenerate');
     $sModuleRightsManager = _root::getParam('moduleToGenerate');
     //permissions
     $classModelPermission = _root::getParam('classModelPermission');
     include_once _root::getConfigVar('path.generation') . _root::getParam('id') . '/model/' . $classModelPermission . '.php';
     $oPermission = new $classModelPermission();
     //actions
     $classModelAction = _root::getParam('classModelAction');
     include_once _root::getConfigVar('path.generation') . _root::getParam('id') . '/model/' . $classModelAction . '.php';
     $oAction = new $classModelAction();
     //items
     $classModelItem = _root::getParam('classModelItem');
     include_once _root::getConfigVar('path.generation') . _root::getParam('id') . '/model/' . $classModelItem . '.php';
     $oItem = new $classModelItem();
     //groups
     $classModelGroup = _root::getParam('classModelGroup');
     include_once _root::getConfigVar('path.generation') . _root::getParam('id') . '/model/' . $classModelGroup . '.php';
     $oGroup = new $classModelGroup();
     //users
     $classModelUser = _root::getParam('classModelUser');
     include_once _root::getConfigVar('path.generation') . _root::getParam('id') . '/model/' . $classModelUser . '.php';
     $oUser = new $classModelUser();
     $exampleConfig = $oPermission->getConfig();
     $exampleTable = $oPermission->getTable();
     $exampleRequeteFindListByGroup = null;
     $exampleUserGroups_id = _root::getParam('classModelUser_groups_id');
     $exampleAction_name = _root::getParam('classModelAction_name');
     $exampleItem_name = _root::getParam('classModelItem_name');
     //exampleGroups_id
     //exampleAction_name
     //exampleItem_name
     $sPermissionTable = $oPermission->getTable();
     $sPermissionActionId = _root::getParam('classModelPermission_actions_id');
     $sPermissionItemId = _root::getParam('classModelPermission_items_id');
     $sPermissionGroupId = _root::getParam('classModelPermission_groups_id');
     $sPermissionId = _root::getParam('classModelPermission_id');
     $sActionTable = $oAction->getTable();
     $sActionId = _root::getParam('classModelAction_id');
     $sActionName = _root::getParam('classModelAction_name');
     $sItemTable = $oItem->getTable();
     $sItemId = _root::getParam('classModelItem_id');
     $sItemName = _root::getParam('classModelItem_name');
     $sGroupTable = $oGroup->getTable();
     $sGroupId = _root::getParam('classModelGroup_id');
     $sGroupName = _root::getParam('classModelGroup_name');
     $sUserTable = $oUser->getTable();
     $sUserId = _root::getParam('classModelUser_id');
     $sUserGroupId = _root::getParam('classModelUser_groups_id');
     $sUserLogin = _root::getParam('classModelUser_login');
     $r = "\n";
     $t = "\t";
     //requete findByGroupId
     $sRequest = $r;
     $sRequest .= $t . $t . 'SELECT ' . $r;
     $sRequest .= $t . $t . $t . '' . $sActionTable . '.' . $sActionName . ' as actionName';
     $sRequest .= ' , ' . $sItemTable . '.' . $sItemName . ' as itemName' . $r;
     $sRequest .= $t . $t . 'FROM ' . $sPermissionTable . '' . $r;
     $sRequest .= $t . $t . $t . 'INNER JOIN ' . $sActionTable . '' . $r;
     $sRequest .= $t . $t . $t . $t . 'ON ' . $sActionTable . '.' . $sActionId . '=' . $sPermissionTable . '.' . $sPermissionActionId . $r;
     $sRequest .= $t . $t . $t . 'INNER JOIN ' . $sItemTable . '' . $r;
     $sRequest .= $t . $t . $t . $t . ' ON ' . $sItemTable . '.' . $sItemId . '=' . $sPermissionTable . '.' . $sPermissionItemId . $r;
     $sRequest .= $t . $t . 'WHERE ' . $sPermissionTable . '.' . $sPermissionGroupId . '=?';
     $exampleRequeteFindListByGroup = $sRequest;
     //requete findAll
     $sRequest = $r;
     $sRequest .= $t . $t . 'SELECT ' . $r;
     $sRequest .= $t . $t . $t . '' . $sActionTable . '.' . $sActionName . ' as actionName';
     $sRequest .= ' , ' . $sItemTable . '.' . $sItemName . ' as itemName' . $r;
     $sRequest .= ' , ' . $sGroupTable . '.' . $sGroupName . ' as groupName' . $r;
     $sRequest .= ' , ' . $sPermissionTable . '.' . $sPermissionId . $r;
     $sRequest .= $t . $t . 'FROM ' . $sPermissionTable . '' . $r;
     $sRequest .= $t . $t . $t . 'INNER JOIN ' . $sActionTable . '' . $r;
     $sRequest .= $t . $t . $t . $t . 'ON ' . $sActionTable . '.' . $sActionId . '=' . $sPermissionTable . '.' . $sPermissionActionId . $r;
     $sRequest .= $t . $t . $t . 'INNER JOIN ' . $sItemTable . '' . $r;
     $sRequest .= $t . $t . $t . $t . ' ON ' . $sItemTable . '.' . $sItemId . '=' . $sPermissionTable . '.' . $sPermissionItemId . $r;
     $sRequest .= $t . $t . $t . 'INNER JOIN ' . $sGroupTable . '' . $r;
     $sRequest .= $t . $t . $t . $t . ' ON ' . $sGroupTable . '.' . $sGroupId . '=' . $sPermissionTable . '.' . $sPermissionGroupId . $r;
     $exampleRequeteFindAll = $sRequest;
     //---model
     $sContentModel = module_builder::getTools()->stringReplaceIn(array('exampleTable' => $exampleTable, 'exampleConfig' => $exampleConfig, 'exampleRequeteFindListByGroup' => $exampleRequeteFindListByGroup, 'exampleRequeteFindAll' => $exampleRequeteFindAll, 'examplePermission_id' => $sPermissionId, 'exampleUserGroups_id' => $sUserGroupId, 'exampleAction_name' => $sActionName, 'exampleItem_name' => $sItemName, 'exampleGroupTable' => $sGroupTable, 'exampleGroup_id' => $sGroupId, 'exampleGroup_name' => $sGroupName, 'exampleActionTable' => $sActionTable, 'exampleAction_id' => $sActionId, 'exampleAction_name' => $sActionName, 'exampleItemTable' => $sItemTable, 'exampleItem_id' => $sItemId, 'exampleItem_name' => $sItemName, 'exampleUserTable' => $sUserTable, 'exampleUser_id' => $sUserId, 'exampleUser_login' => $sUserLogin, 'exampleUser_groupsId' => $sUserGroupId), 'data/sources/fichiers/model/model_rightsManager.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/model/' . $sClassModelRightsManager . '.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier model/' . $sClassModelRightsManager . '.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     $tReplace = array('examplemodule' => $sModuleRightsManager, 'model_examplemodel' => $sClassModelRightsManager, 'row_examplemodel' => $sClassRowRightsManager, 'examplePermissionId' => $sPermissionId, 'exampleGroupId' => $sPermissionGroupId, 'exampleActionId' => $sPermissionActionId, 'exampleItemId' => $sPermissionItemId, 'exampleUserTable' => $sUserTable, 'exampleUser_id' => $sUserId, 'exampleUser_login' => $sUserLogin, 'exampleUser_groupsId' => $sUserGroupId, 'exampleUserTable' => $sUserTable, 'exampleUser_id' => $sUserId, 'exampleUser_login' => $sUserLogin, 'exampleUser_groupsId' => $sUserGroupId);
     //-module
     //---main
     module_builder::getTools()->projetmkdir('module/' . $sModuleRightsManager);
     module_builder::getTools()->projetmkdir('module/' . $sModuleRightsManager . '/view');
     $sContentModel = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/rightsManager/main.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleRightsManager . '/main.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier module/' . $sModuleRightsManager . '/view/main.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     //--view index
     $sContentModel = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/rightsManager/view/index.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleRightsManager . '/view/index.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier module/' . $sModuleRightsManager . '/view/index.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     //--view new
     $sContentModel = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/rightsManager/view/new.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleRightsManager . '/view/new.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier module/' . $sModuleRightsManager . '/view/new.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     //--view edit
     $sContentModel = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/rightsManager/view/edit.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleRightsManager . '/view/edit.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier module/' . $sModuleRightsManager . '/view/edit.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     //--view delete
     $sContentModel = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/rightsManager/view/delete.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleRightsManager . '/view/delete.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier module/' . $sModuleRightsManager . '/view/delete.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     //--view editUser
     $sContentModel = module_builder::getTools()->stringReplaceIn($tReplace, 'data/sources/fichiers/module/rightsManager/view/userEdit.php');
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/module/' . $sModuleRightsManager . '/view/userEdit.php');
     if ($oFile->exist()) {
         return array('error' => 'Fichier module/' . $sModuleRightsManager . '/view/userEdit.php exite deja');
     }
     $oFile->setContent($sContentModel);
     $oFile->save();
     $oFile->chmod(0666);
     //-----------
     $sMsg = null;
     $sDetail = null;
     $sMsg = 'Model ' . $sClassModelRightsManager . ' et Module ' . $sModuleRightsManager . ' g&eacute;n&eacute;r&eacute;s avec succ&egrave;s';
     $sDetail .= 'Cr&eacute;ation fichier model/' . $sClassModelRightsManager . '.php <br/><br/>';
     $sDetail .= 'Cr&eacute;ation du repertoire module/' . $sModuleRightsManager . '/ <br/>';
     $sDetail .= 'Cr&eacute;ation du repertoire module/' . $sModuleRightsManager . '/view/ <br/>';
     $sDetail .= 'Cr&eacute;ation fichier module/' . $sModuleRightsManager . '/main.php <br/>';
     $sDetail .= 'Cr&eacute;ation fichier module/' . $sModuleRightsManager . '/view/index.php <br/>';
     $sDetail .= 'Cr&eacute;ation fichier module/' . $sModuleRightsManager . '/view/new.php <br/>';
     $sDetail .= 'Cr&eacute;ation fichier module/' . $sModuleRightsManager . '/view/edit.php <br/>';
     $sDetail .= 'Cr&eacute;ation fichier module/' . $sModuleRightsManager . '/view/delete.php <br/>';
     $sDetail .= '<br/><br/>Pour y acc&eacute;der <a href="' . _root::getConfigVar('path.generation') . _root::getParam('id') . '/public/index.php?:nav=' . $sModuleRightsManager . '::index">cliquer ici (index.php?:nav=' . $sModuleRightsManager . '::index)</a>';
     $sModuleAuth = 'auth';
     $tConfig = module_builder::getTools()->rootAddConf('conf/site.ini.php');
     if (isset($tConfig['auth']) and isset($tConfig['auth']['module'])) {
         $sModuleAuthAndAction = $tConfig['auth']['module'];
         if (preg_match('/:/', $sModuleAuthAndAction)) {
             list($sModuleAuth, $foo) = explode(':', $sModuleAuthAndAction);
         }
     }
     $r = "\n";
     $t = "\t";
     $sCode = null;
     $sCode = '<?php ' . "\n";
     $sCode .= 'private function checkLoginPass(){' . $r;
     $sCode .= $t . '(...)' . $r;
     $sCode .= $t . '$oUser=_root::getAuth()->getAccount();' . $r;
     $sCode .= $t . $sClassModelRightsManager . '::getInstance()->loadForUser($oUser);' . $r;
     $sCode .= $r;
     $sCode .= $t . '_root::redirect(\'privatemodule_action\');' . $r;
     $sCode .= '}' . $r;
     $sCodeHighli = highlight_string($sCode, 1);
     return array('msg' => $sMsg, 'detail' => $sDetail, 'code' => $sCodeHighli, 'auth' => $sModuleAuth);
 }
示例#11
0
 private function genModelAndRowByTableConfigAndId($sTable, $sConfig, $sId, $tSelect = null)
 {
     $r = "\n";
     $t = "\t";
     $sTable = trim($sTable);
     $sContentGetSelect = null;
     if (is_array($tSelect)) {
         $sContentGetSelect = module_builder::getTools()->stringReplaceIn(array('exampleselectkey' => $tSelect['key'], 'exampleselectval' => $tSelect['val']), 'data/sources/fichiers/model/getSelect.php');
     }
     $sSave = 'parent::save();';
     $sSaveDuplicateKey = null;
     if (_root::getParam('mysqlOnDuplicateKey') == 1) {
         $soData = '$o' . ucfirst($sTable);
         $tColumn = module_builder::getTools()->getListColumnFromConfigAndTable($sConfig, $sTable);
         foreach ($tColumn as $sColumn) {
             if ($sColumn == $sId) {
                 continue;
             }
             $tFieldSql[] = $sColumn;
             $tSqlInsert[] = '?';
             $tSqlUpdate[] = $sColumn . '=?';
             $tParam[] = $soData . '->' . $sColumn;
         }
         foreach ($tColumn as $sColumn) {
             if ($sColumn == $sId) {
                 continue;
             }
             $tParam[] = $soData . '->' . $sColumn;
         }
         //$tParam[]=$soData.'->'.$sId;
         $sSqlUpdateId = $sId;
         $sSaveDuplicateKey .= 'public function save(' . $soData . '){' . "\n";
         $sSaveDuplicateKey .= "\t" . "\t" . '$this->execute(\'INSERT INTO \'.$this->sTable.\' (' . implode(',', $tFieldSql) . ') VALUES (' . implode(',', $tSqlInsert) . ') ON DUPLICATE KEY UPDATE ' . implode(',', $tSqlUpdate) . '  \',array(' . implode(',', $tParam) . '));' . "\n";
         $sSaveDuplicateKey .= "\t" . '}' . "\n";
         $sSave = 'model_' . $sTable . '::getInstance()->save($this);';
     }
     $sRules = null;
     if (_root::getParam('tRuleColumn' . $sTable)) {
         $tRuleColumn = _root::getParam('tRuleColumn' . $sTable);
         $tRuleName = _root::getParam('tRuleName' . $sTable);
         $tRuleParam = _root::getParam('tRuleParam' . $sTable);
         $tRuleMsg = _root::getParam('tRuleMsg' . $sTable);
         if ($tRuleColumn) {
             $sRules = $r;
             foreach ($tRuleColumn as $key => $sRuleColumn) {
                 if ($sRuleColumn == '') {
                     continue;
                 }
                 $sRuleName = $tRuleName[$key];
                 $sRuleParam = $tRuleParam[$key];
                 $sRuleMsg = $tRuleMsg[$key];
                 $sRules .= $t . $t;
                 //$oPluginValid->isEqual('champ','valeurB','Le champ n\est pas &eacute;gal &agrave; '.$valeurB);
                 $sRules .= '$oPluginValid->' . $sRuleName . '(' . "'{$sRuleColumn}'";
                 if (!in_array($sRuleName, array('isEmpty', 'isNotEmpty', 'isEmailValid'))) {
                     $sRules .= ",'{$sRuleParam}'";
                 }
                 $sRules .= ",'{$sRuleMsg}'";
                 $sRules .= ');' . $r;
             }
         }
     }
     $sFileModel = 'data/sources/projet/model/model_example.sample.php';
     if (_root::getConfigVar('db.' . _root::getParam('sConfig') . '.sgbd') == 'mongodb') {
         $sFileModel = 'data/sources/fichiers/model/model_exampleMongodb.php';
     }
     $sContent = module_builder::getTools()->stringReplaceIn(array('exampletb' => $sTable, 'exampleid' => $sId, 'exampleconfig' => $sConfig, '\\/\\/ICI' => $sContentGetSelect, '\\/\\/sSaveDuplicateKey' => $sSaveDuplicateKey, '\\/\\/save' => $sSave, '\\/\\/checkContraint' => $sRules), $sFileModel);
     $oFile = new _file(_root::getConfigVar('path.generation') . _root::getParam('id') . '/model/model_' . $sTable . '.php');
     if ($oFile->exist()) {
         return false;
     }
     $oFile->setContent($sContent);
     $oFile->save();
     $oFile->chmod(0666);
     return true;
 }