protected function formProcess($form, $request, $config) { if ($request->isXmlHttpRequest()) { if ($request->query->get('clear_cache')) { FileProcessor::clearDir(Container::get('params')->getCacheDir()); return; } } $cacheConfJson = file_get_contents(Container::get('params')->getConfigDir() . '/' . 'cache.json'); $cacheConf = json_decode($cacheConfJson); $form->configure($config); $form->addElement(new Element\HTML('<legend>' . Container::get('params')->langArray['cache_control'] . '</legend>')); $form->addElement(new Element\Hidden($this->formName, $this->formName)); $options = array(); $hidden = array(); $states = array(); foreach ($cacheConf as $name => $state) { $options[$name] = $name; if ($state) { $states[$name] = $name; } } $form->addElement(new Element\Button(Container::get('params')->langArray['clear_cache'], "button", array("onclick" => "\$.ajax({\n url: '',\n context: document.body,\n data: {\"clear_cache\":true},\n success: function(){\n alert('done');\n }\n });"))); $form->addElement(new Element\Checkbox("", "enable_cache", $options, array("value" => $states, "class" => $hidden))); $form->addElement(new Element\Button(Container::get('params')->langArray['save'])); $form->addElement(new Element\Button(Container::get('params')->langArray['cancel'], "button", array("onclick" => "history.go(-1);"))); return $form; }
public function submit(Request $request, $form) { if ($this->operation == 'view') { $requestedModules = $request->request->get('modules'); $modulesConfJson = file_get_contents(Container::get('params')->getConfigDir() . '/' . 'modules.json'); $modulesConf = json_decode($modulesConfJson, true); $modulesConf = array_fill_keys(array_keys($modulesConf), false); foreach ($requestedModules as $key => $mName) { $modulesConf[$mName] = true; } file_put_contents(Container::get('params')->getConfigDir() . '/' . 'modules.json', json_encode($modulesConf)); } if ($this->operation == 'create') { if ($request->request->has('name')) { $name = ucfirst($request->request->get('name')); $model = new ModuleModel(); if (!is_dir('Src/Modules/' . $name)) { mkdir('Src/Modules/' . $name, 0775); chmod('Src/Modules/' . $name, 0775); } if (!is_dir('Src/Modules/' . $name . '/Controllers')) { mkdir('Src/Modules/' . $name . '/Controllers', 0775); chmod('Src/Modules/' . $name . '/Controllers', 0775); } if (!is_dir('Src/Modules/' . $name . '/Models')) { mkdir('Src/Modules/' . $name . '/Models', 0775); chmod('Src/Modules/' . $name . '/Models', 0775); } if (!is_dir('Src/Modules/' . $name . '/Libs')) { mkdir('Src/Modules/' . $name . '/Libs', 0775); chmod('Src/Modules/' . $name . '/Libs', 0775); } if (!is_dir('Src/Modules/' . $name . '/Forms')) { mkdir('Src/Modules/' . $name . '/Forms', 0775); chmod('Src/Modules/' . $name . '/Forms', 0775); } if (!is_dir('Src/Modules/' . $name . '/Views')) { mkdir('Src/Modules/' . $name . '/Views', 0775); chmod('Src/Modules/' . $name . '/Views', 0775); } if (!file_exists('Src/Modules/' . $name . '/Controllers/MainController.php')) { file_put_contents('Src/Modules/' . $name . '/Controllers/MainController.php', $model->getStdControllerContent($name)); chmod('Src/Modules/' . $name . '/Controllers/MainController.php', 0664); } if (!file_exists('Src/Modules/' . $name . '/Module.php')) { file_put_contents('Src/Modules/' . $name . '/Module.php', $model->getStdModuleContent($name)); chmod('Src/Modules/' . $name . '/Module.php', 0664); } $modulesConfJson = file_get_contents(Container::get('params')->getConfigDir() . '/' . 'modules.json'); $modulesConf = json_decode($modulesConfJson, true); $modulesConf[strtolower($name)] = true; file_put_contents(Container::get('params')->getConfigDir() . '/' . 'modules.json', json_encode($modulesConf)); } } if ($this->operation == 'delete') { FileProcessor::recursiveDelete('Src/Modules/' . ucfirst($request->query->get('key'))); $modulesConfJson = file_get_contents(Container::get('params')->getConfigDir() . '/' . 'modules.json'); $modulesConf = json_decode($modulesConfJson, true); unset($modulesConf[strtolower($request->query->get('key'))]); file_put_contents(Container::get('params')->getConfigDir() . '/' . 'modules.json', json_encode($modulesConf)); $module = 'Src\\Modules\\' . ucfirst($request->query->get('key')) . '\\Module'; $module = new $module(); $module->uninstall(); } Container::get('router')->redirect('/admin/module'); }