/** * */ private function _build_formset($data = NULL) { $base_form_name = Arr::get($this->__options, "base_form"); for ($i = 1; $i <= Arr::get($this->__options, "count", 1); $i++) { $this->__forms[] = Form::factory($base_form_name, isset($data[$i - 1]) ? $data[$i - 1] : NULL)->is_formset_element(true)->number($i); } }
public function action_view() { $uri = $this->request->detect_uri(); if ($uri == '') { $this->redirect(URL::to('page@view:home')); } $id = $this->request->param('id'); $query = $this->request->query(); $username = $this->request->post('username'); $password = $this->request->post('password'); $login = $this->request->post('login'); $identity = Identity::instance(); $info = ORM::factory('Page')->filter('alias', $id)->load(); if ($info->loaded()) { //downloads if ($id == 'download') { $downloads = true; } //contact if ($id == 'contact') { $form = Form::factory('Contact'); //$form = Form:: if ($form->valid()) { //var_dump($form->values()); $this->redirect(URL::to('page@view:contact') . '?form=sent'); } } else { $form = FALSE; } //login mechanism if (empty($username) && $login == 'Login') { $this->redirect(URL::current() . '?auth=nameError'); } elseif (empty($password) && $login == 'Login') { $this->redirect(URL::current() . '?auth=false'); } elseif (!empty($username) && !empty($password) && $login == 'Login') { $auth = $identity->authenticate($username, $password); if ($auth) { $this->redirect(URL::current()); } else { $this->redirect(URL::current() . '?auth=false'); } } //logout mechanism if ($login == 'Logout') { $identity->destroy(); $this->redirect(URL::current()); } $view = View::factory('page/item', array('item' => Viewer::factory($info), 'form' => $form, 'query' => $query, 'downloads' => isset($downloads) ? $downloads : null)); $this->response->body($view->render()); } else { throw HTTP_Exception::factory(404, 'Page not found'); } }
/** * create items */ public function action_store() { // get the hash of the temp dir $hash = $this->request->param('id'); // create a form $form = Form::factory($this->_settings->get('form_store')); // urls $form->urls(array('submit' => URL::to($this->request->controller() . '@store:' . $hash), 'back' => URL::to($this->request->controller()))); Event::raise($this, Event::AFTER_STORE_FORM, array('form' => $form)); // store them if ($this->store($form, $hash)) { $this->redirect_done('uploaded'); } }
/** * Popup launched from wysiwyg to embed an image * @return void */ public function action_embed() { $id = $this->request->param('id', 0); $sizes = $this->_settings->get('sizes_embed'); if ($id > 0) { // get size from qs $size = $this->param('param1'); } else { // get first size $size = $sizes[0]; } // create form $form = Form::factory($this->_settings->get('form_embed')); // set urls $form->urls(array('submit' => URL::to($this->request->controller() . '@embed:' . $id, array('query' => 'after=embed')), 'submit_back' => URL::to($this->request->controller() . '@embed:' . $id, array('query' => 'after=close')), 'back' => URL::to($this->request->controller() . '@close'))); // set vars in from $form->controller($this->request->controller()); $form->sizes($sizes); // populate form $form->value('id', $id); $form->value('size', $size); // proces form if ($form->valid()) { $data = $form->values(); // get the image model $model = ORM::factory($this->_settings->get('model'), $data['id']); // get actual base url for the current website $base_url = Website::instance()->base_url($this->_website, Kohana::$base_url) . $this->_settings->get('url_images'); // get the source $data['src'] = $model->src($data['size'], $base_url); // check if it can be enlarged $data['enlarge'] = $model->size($this->_settings->get('size_enlarge')) === FALSE ? '0' : '1'; // get callback $callback = $this->request->param('callback', ''); // render close dialog $view = View::factory($this->_settings->get('view.close'), array('data' => $data, 'callback' => $callback)); $this->response->body($view->render()); } else { // create view $viewer = Viewer::factory('Form', $form)->text(Text::instance()); $view = View::factory($this->_settings->get('view.update'), array('viewer' => $viewer)); $this->response->body($view->render()); } }
/** * do login * * @param string $username * @param string $password */ public function action_login() { // create text $text = Text::instance(); // create form $form = Form::factory('Login'); $form->urls(array('submit' => URL::to('Auth@login'))); // check form $authenticated = false; $message = false; if ($form->valid()) { // get the values $values = $form->values(); // create identity $identity = Identity::instance(); // check if these are valid credentials $authenticated = $identity->authenticate($values['username'], $values['password']); // add error if not authenticated if ($authenticated) { // check if user is blocked if ($identity->user && $identity->user->status == Model_User::STATUS_ACTIVE) { } else { $identity->destroy(); $authenticated = false; $message = $text->get('error.blocked'); } } else { $message = $text->get('error.credentials'); } } if ($authenticated) { // if ok, set flash message and redirect to default page // set message $message = array('status' => 'success', 'message' => $text->get('message.success')); Session::instance('database')->set('message', $message); //redirect $url = URL::to('Default@redirect_website'); $this->redirect($url); } else { // else show form $body = View::factory('login', array('viewer' => Viewer::factory('Form', $form)->text(Text::instance()), 'message' => $message, 'text' => $text))->render(); $this->response->body($body); } }
/** * update */ public function action_update() { // get model $model = ORM::factory($this->_settings->get('model'))->filter('website_id', $this->_website)->find(); // create form $form = Form::factory($this->_settings->get('form')); // add request to form $form->request($this->request); // add text to form $form->text(Text::instance()); // add model to form $form->model($model); // add urls $form->urls(array('submit' => URL::to($this->request->controller() . '@update'), 'back' => URL::to($this->request->controller()))); // do the action if ($this->update($model, $form)) { //redirect $this->redirect_done('updated'); } }
/** * add or remove roles from user */ public function action_roles() { $id = $this->param('id'); $user = ORM::factory($this->_settings->get('model'), $id); $acl = Acl::instance(); $form = Form::factory('Roles'); $form->urls(array('submit' => URL::to($this->request->controller() . '@roles:' . $id, array('query' => 'after=roles')), 'submit_back' => URL::to($this->request->controller() . '@roles:' . $id), 'back' => URL::to($this->request->controller()))); // get roles $roles = $acl->roles(); sort($roles); $options = array(); $text = Text::instance(); foreach ($roles as $role) { $parts = explode('_', $role); if ($parts[0] === 'manager') { $label = $text->get('option.roles.manager') . ' ' . $parts[1]; } else { $label = $text->get('option.roles.' . $role); } $options[$role] = $label; } // set all the available roles $form->roles($options); // set roles in form $form->value('roles', $user->roles); if ($form->valid()) { // filter out illegal attempts to upgrade roles $roles = array_intersect($form->value('roles'), $acl->roles()); // set & save roles $user->roles = $roles; $user->save(); $this->redirect_done('updated'); } // create viewer $viewer = Viewer::factory('Form', $form)->text(Text::instance()); // create view $view = View::factory($this->_settings->get('view.update'), array('viewer' => $viewer)); // response $this->response->body($view->render()); }
/** * update */ public function action_update() { // get id $id = $this->param('id'); // create new model $model = ORM::factory($this->_settings->get('model'), $id); // add item to navigation Viewer::instance('Navigation')->item($model); // create form $form = Form::factory($this->_settings->get('form')); // add request to form $form->request($this->request); // add text to form $form->text(Text::instance()); // add alias settings to form $form->alias($this->_settings->get('alias.global') ? 'multiple' : ($this->_settings->get('alias.module') ? 'single' : FALSE)); // add model to form $form->model($model); // get viewport $viewport = $this->request->param('viewport'); // add urls if ($viewport === 'item') { // urls when directly updating in a dialog $form->urls(array('submit' => URL::to($this->request->controller() . '@update:' . $id, array('query' => 'after=update')), 'submit_back' => URL::to($this->request->controller() . '@update:' . $id, array('query' => 'after=close')), 'back' => URL::to($this->request->controller() . '@close'), 'preview' => URL::to($this->request->controller() . '@preview:' . $id))); } else { // default urls $url_back = State::instance()->get('url.back', FALSE); State::instance()->set('url.back', FALSE); $form->urls(array('submit' => URL::to($this->request->controller() . '@update:' . $id, array('query' => 'after=update')), 'submit_back' => URL::to($this->request->controller() . '@update:' . $id), 'back' => $url_back ? $url_back : URL::to($this->request->controller()), 'preview' => URL::to($this->request->controller() . '@preview:' . $id))); } // raise event Event::raise($this, Event::AFTER_UPDATE_FORM, array('form' => $form, 'model' => $model)); // do the action if ($this->update($model, $form)) { // get after if ($this->request->query('after') === 'update') { $params = array('controller' => $this->request->controller(), 'action' => 'update', 'id' => $id); } elseif ($this->request->query('after') === 'close') { $params = array('controller' => $this->request->controller(), 'action' => 'close', 'id' => $id); } else { $params = array(); } //redirect $this->redirect_done('updated', $params); } }
public function action_create() { $form = Form::factory('module'); $languages = array('nl' => 'Dutch', 'en' => 'English', 'de' => 'German', 'fr' => 'French', 'es' => 'Spanish'); $form->languages($languages); if ($form->valid()) { $this->response->body('done'); $name = ucfirst($form->value('name')); $file = ucfirst($form->value('name')) . '.php'; $values = $_POST; $generate = $values['generate']; $create = array(); // FRONTEND CONTROLLER if (in_array('controller_frontend', $generate)) { $content = "<?php\n" . View::factory('manager/file/controller_frontend', array('name' => $name, 'extends' => isset($values['controller_frontend_extends']) ? ucfirst($values['controller_frontend_extends']) : 'Controller'))->render(); $create[] = array('path' => FRONTENDPATH . 'classes/Controller/' . $file, 'content' => $content); } // FRONTEND SETTINGS if (in_array('settings_frontend', $generate)) { $content = "<?php\n" . View::factory('manager/file/settings_frontend', array('extends' => isset($values['settings_frontend_extends']) ? strtolower($values['settings_frontend_extends']) : FALSE))->render(); $create[] = array('path' => FRONTENDPATH . 'settings/' . strtolower($file), 'content' => $content); } // FRONTEND TEXT if (in_array('text_frontend', $generate)) { foreach ($languages as $language => $label) { if (in_array($language, $values['text_frontend_language'])) { $content = "<?php\n" . View::factory('manager/file/text_frontend', array('text' => $values['text_frontend_' . $language], 'extends' => isset($values['text_frontend_extends']) ? strtolower($values['text_frontend_extends']) : FALSE))->render(); $create[] = array('path' => FRONTENDPATH . 'text/' . strtolower($language) . '/' . strtolower($file), 'content' => $content); } } } // BACKEND CONTROLLER if (in_array('controller_backend', $generate)) { $content = "<?php\n" . View::factory('manager/file/controller_backend', array('name' => $name, 'extends' => isset($values['controller_backend_extends']) ? ucfirst($values['controller_backend_extends']) : 'Controller_Module'))->render(); $create[] = array('path' => BACKENDPATH . 'classes/Controller/' . $file, 'content' => $content); } // BACKEND SETTINGS if (in_array('settings_backend', $generate)) { $content = "<?php\n" . View::factory('manager/file/settings_backend', array('extends' => isset($values['settings_backend_extends']) ? strtolower($values['settings_backend_extends']) : FALSE))->render(); $create[] = array('path' => BACKENDPATH . 'settings/' . strtolower($file), 'content' => $content); } // BACKEND TEXT if (in_array('text_backend', $generate)) { foreach ($languages as $language => $label) { if (in_array($language, $values['text_backend_language'])) { $content = "<?php\n" . View::factory('manager/file/text_backend', array('text' => $values['text_backend_' . $language], 'labels' => isset($values['text_backend_labels']) && $values['text_backend_labels'] == '1', 'errors' => isset($values['text_backend_errors']) && $values['text_backend_errors'] == '1', 'fields' => $values['model_fields'], 'belongs' => $values['model_belongs'], 'collections' => $values['model_collections'], 'extends' => isset($values['text_backend_extends']) ? strtolower($values['text_backend_extends']) : FALSE))->render(); $create[] = array('path' => BACKENDPATH . 'text/' . strtolower($language) . '/' . strtolower($file), 'content' => $content); } } } // BACKEND FORM if (in_array('form', $generate)) { $content = "<?php\n" . View::factory('manager/file/form', array('name' => $name, 'buttons' => isset($values['form_buttons']) ? $values['form_buttons'] : array(), 'title' => isset($values['form_title']) && $values['form_title'] == '1', 'alias' => isset($values['form_alias']) && $values['form_alias'] == '1', 'seo' => isset($values['form_seo']) && $values['form_seo'] == '1', 'fields' => isset($values['form_fields']) && $values['form_fields'] == '1' ? $values['model_fields'] : array(), 'collections' => isset($values['form_collections']) && $values['form_collections'] == '1' ? $values['model_collections'] : array(), 'belongs' => isset($values['form_belongs']) && $values['form_belongs'] == '1' ? $values['model_belongs'] : array(), 'extends' => isset($values['form_extends']) ? ucfirst($values['form_extends']) : 'Form_Base'))->render(); $create[] = array('path' => BACKENDPATH . 'classes/Form/' . $file, 'content' => $content); } // MODEL if (in_array('model', $generate)) { $content = "<?php\n" . View::factory('manager/file/model', array('name' => $name, 'extends' => isset($values['model_extends']) ? ucfirst($values['model_extends']) : 'Model_Base', 'table' => $values['model_table'], 'parent' => isset($values['model_parent']) && $values['model_parent'] == '1', 'item_fields' => isset($values['model_item_fields']) && $values['model_item_fields'] == '1', 'fields' => $values['model_fields'], 'meta' => isset($values['model_meta']) && $values['model_meta'] == '1', 'belongs' => $values['model_belongs'], 'collections' => $values['model_collections'], 'sortable' => isset($values['model_sortable']) && $values['model_sortable'] == '1'))->render(); $create[] = array('path' => COMMONPATH . 'classes/Model/' . $file, 'content' => $content); } // COLLECTION MODEL if (in_array('collection', $generate)) { $content = "<?php\n" . View::factory('manager/file/model_collection', array('name' => $name, 'table' => $values['model_table']))->render(); $create[] = array('path' => COMMONPATH . 'classes/Model/Collection/' . $file, 'content' => $content); } // TABLE if (in_array('table', $generate)) { $content = View::factory('manager/file/table', array('overwrite' => isset($values['overwrite']) && in_array('tables', $values['overwrite']), 'table' => $values['model_table'], 'parent' => isset($values['model_parent']) && $values['model_parent'] == '1', 'item_fields' => isset($values['model_item_fields']) && $values['model_item_fields'] == '1', 'fields' => $values['model_fields'], 'meta' => isset($values['model_meta']) && $values['model_meta'] == '1', 'belongs' => $values['model_belongs'], 'collections' => $values['model_collections']))->render(); $create[] = array('path' => 'database', 'content' => $content); } // COLLECTION TABLE if (in_array('collection_table', $generate)) { $content = View::factory('manager/file/table_collection', array('overwrite' => isset($values['overwrite']) && in_array('tables', $values['overwrite']), 'table' => $values['model_table']))->render(); $create[] = array('path' => 'database', 'content' => $content); } // EXECUTE $body = ''; foreach ($create as $item) { if ($item['path'] == 'database') { $body .= 'Query is executed:<br />'; $body .= nl2br(htmlspecialchars($item['content'])) . '<br />'; DB::query(NULL, $item['content'])->execute(); } else { if (file_exists($item['path'])) { if (isset($values['overwrite']) && in_array('files', $values['overwrite'])) { $body .= 'File is OVERWRITEN: ' . $item['path'] . '<br />'; $body .= nl2br(htmlspecialchars($item['content'])) . '<br />'; file_put_contents($item['path'], $item['content']); } else { $body .= 'File EXISTS: ' . $item['path'] . '<br />'; } } else { $body .= 'File is writen: ' . $item['path'] . '<br />'; $body .= nl2br(htmlspecialchars($item['content'])) . '<br />'; file_put_contents($item['path'], $item['content']); } } } $body .= <<<YUNA <br /> <br /> ---------------------------------===================<br /> Volgende stappen: <br /> 1. Module toevoegen aan application/backend/settings/modules.php<br /> 3. Module toevoegen aan application/backend/settings/navigation.php<br /> 3. Module toevoegen aan application/common/Model/Rights.php<br /> YUNA; $this->response->body($body); } else { $this->response->body(View::factory('manager/module', array('form' => $form))->render()); } }
/** * Get related Form instance or create it * * @param bool|Form * @return Form */ public function form($instance = true) { if ($instance instanceof Form) { $this->form = $instance; return $instance; } if (empty($this->form) and $instance === true) { $this->form = \Form::factory($this); } return $this->form; }
/** * Get related Form instance or create it * * @return Form */ public function form() { if (empty($this->form)) { $this->form = Form::factory($this->name, $this); } return $this->form; }
/** * Builds and returns form * * @return Form Html Form */ function form() { global $ACCESS_PORT_LIST, $DESTINATION, $ENCRYPTION_KEY, $SERVER_PORT; $form = new Form('knock'); if (is_array($DESTINATION)) { /** @var $element FormElementDropdown */ $element = $form->factory('Dropdown', 'destination', 'Server', $DESTINATION)->setMaximumSize(10)->setIsMultiple(true)->setNotNull(); } elseif ($DESTINATION === null) { /** @var $element FormElementText */ $element = $form->factory('Text', 'destination', 'Server IP/Hostname')->setHint('You may enter multiple server IPs or hostnames separated by a semicolon.')->setNotNull(); } if ($SERVER_PORT === null) { /** @var $element FormElementInteger */ $element = $form->factory('Integer', 'serverPort', 'Server port'); $element->setMinimum(1); $element->setMaximum(65535); } if ($ACCESS_PORT_LIST === null) { /** @var $element FormElementText */ $element = $form->factory('Text', 'accessPortList', 'Access port list')->setHint('Provide a list of ports and protocols to access on a remote computer. The format of this list is "<proto>/<port>...<proto>/<port>", e.g. "tcp/22,udp/53".')->setValidRegExp('(^(tcp|udp)/[0-9]+( *, *(tcp|udp)/[0-9]+)*$)i'); } if ($ENCRYPTION_KEY === null) { /** @var $element FormElementPassword */ $element = $form->factory('Password', 'encryptionKey', 'Encryption key'); } /** @var $element FormElementText */ $element = $form->factory('Text', 'allowIp', 'Source IP')->setDefaultValue($_SERVER['REMOTE_ADDR'])->setValidRegExp('(^(?P<first>[1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(?P<second>[1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(?P<third>[1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(?P<fourth>[1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])$)')->setNotNull(); /** @var $element FormElementHidden */ $element = $form->factory('Hidden', 'doKnock')->setDefaultValue(1); return $form; }
public function action_create_module() { /** * FORM CREATE */ $form = Form::factory(); // NAME $form->element('name', 'text', array('label' => 'Naam module', 'comment' => '')); $form->markup('custom', array('html' => '<hr />')); // FRONTEND CONTROLLER $form->markup('section_start'); $form->markup('line_start'); $form->element('create_frontend_controller', 'checkbox', array('options' => array('1' => 'Frontend Controller maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('frontend_controller_extends', 'text', array('label' => 'extends Controller_', 'comment' => ''))->value('Base'); // FRONTEND TEXT $form->markup('section_start'); $form->markup('line_start'); $form->element('create_frontend_Text', 'checkbox', array('options' => array('1' => 'Frontend ModelText maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('frontend_Text_extends', 'text', array('label' => 'extends Text_', 'comment' => ''))->value('Base'); $form->markup('custom', array('html' => '<hr />')); // BACKEND CONTROLLER $form->markup('section_start'); $form->markup('line_start'); $form->element('create_backend_controller', 'checkbox', array('options' => array('1' => 'Backend Controller maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('backend_controller_extends', 'text', array('label' => 'extends Controller_', 'comment' => ''))->value('Item'); // BACKEND SETTINGS $form->markup('section_start'); $form->markup('line_start'); $form->element('create_backend_settings', 'checkbox', array('options' => array('1' => 'Backend Settings maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('backend_settings_extends', 'text', array('label' => 'extends Settings_', 'comment' => ''))->value('Item'); // BACKEND TEXT $form->markup('section_start'); $form->markup('line_start'); $form->element('create_backend_Text', 'checkbox', array('options' => array('1' => 'Backend ModelText maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('backend_Text_extends', 'text', array('label' => 'extends Text_', 'comment' => ''))->value('Item'); $form->markup('line_end'); $form->markup('custom', array('html' => 'LET OP: escape single quotes! \\\' dus')); $form->element('backend_Text_module', 'text', array('label' => 'Modulenaam', 'comment' => ''))->value(''); $form->element('backend_Text_module_single', 'text', array('label' => 'Itemnaam', 'comment' => ''))->value(''); $form->element('backend_Text_module_plural', 'text', array('label' => 'Meervoud', 'comment' => ''))->value(''); $form->element('backend_Text_module_member', 'text', array('label' => 'de / het', 'comment' => ''))->value('de'); $form->element('backend_Text_module_this', 'text', array('label' => 'deze / dit', 'comment' => ''))->value('deze'); $form->element('backend_Text_module_that', 'text', array('label' => 'die / dat', 'comment' => ''))->value('die'); $form->element('backend_Text_module_new', 'text', array('label' => 'nieuw / nieuwe', 'comment' => ''))->value('nieuwe'); $form->element('create_backend_Text_en', 'checkbox', array('options' => array('1' => 'Engels toevoegen'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('backend_Text_module_en', 'text', array('label' => 'Modulenaam (EN)', 'comment' => ''))->value(''); $form->element('backend_Text_module_single_en', 'text', array('label' => 'Itemnaam (EN)', 'comment' => ''))->value(''); $form->element('backend_Text_module_plural_en', 'text', array('label' => 'Meervoud (EN)', 'comment' => ''))->value(''); $form->element('backend_Text_module_member_en', 'text', array('label' => 'the', 'comment' => ''))->value('the'); $form->element('backend_Text_module_this_en', 'text', array('label' => 'this', 'comment' => ''))->value('this'); $form->element('backend_Text_module_that_en', 'text', array('label' => 'that', 'comment' => ''))->value('that'); $form->element('backend_Text_module_new_en', 'text', array('label' => 'new', 'comment' => ''))->value('new'); // BACKEND FORM $form->markup('section_start'); $form->markup('line_start'); $form->element('create_backend_Form', 'checkbox', array('options' => array('1' => 'Backend ModelForm maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('backend_Form_extends', 'text', array('label' => 'extends Form_', 'comment' => ''))->value('Item'); $form->markup('custom', array('html' => '<hr />')); // MODEL $form->markup('section_start'); $form->markup('line_start'); $form->element('create_model', 'checkbox', array('options' => array('1' => 'Model maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('model_extends', 'text', array('label' => 'extends Model_', 'comment' => ''))->value('Item'); $form->markup('line_end'); $form->element('model_item_fields', 'checkbox', array('options' => array('1' => 'reguliere item-velden toevoegen'), 'single' => TRUE, 'label' => '', 'comment' => ''))->value(1); $form->markup('custom', array('html' => '<hr />Extra velden')); for ($i = 0; $i < 20; $i++) { $form->markup('section_start'); $form->element('model_field_name_' . $i, 'text', array('label' => 'Veld', 'comment' => '')); $form->element('model_field_type_' . $i, 'select', array('options' => array('int(11)' => 'int(11)', 'tinyint(4)' => 'tinyint(4)', 'varchar(15)' => 'varchar(15)', 'varchar(63)' => 'varchar(63)', 'varchar(255)' => 'varchar(255)', 'text' => 'text', 'timestamp' => 'timestamp'), 'label' => 'Type', 'comment' => '')); $form->element('model_field_notnull_' . $i, 'checkbox', array('options' => array('1' => 'not null'), 'single' => TRUE, 'label' => '', 'comment' => ''))->value('1'); $form->element('model_field_default_' . $i, 'text', array('label' => 'Default. Gebruik \' (single quotes) om stringwaarden aan te geven (ook lege)', 'comment' => '')); } $form->markup('custom', array('html' => '<hr />')); $form->element('create_table', 'checkbox', array('options' => array('1' => 'probeer automatisch tabel te maken'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->markup('custom', array('html' => '<hr />')); $form->element('overwrite_files', 'checkbox', array('options' => array('1' => 'bestaande bestanden overschrijven'), 'single' => TRUE, 'label' => '', 'comment' => '')); $form->element('go', 'submit', array('label' => 'verder', 'comment' => '')); /** * FORM PARSE */ if ($form->valid()) { $name = ucfirst($form->value('name')); $file = ucfirst($form->value('name')) . '.php'; $overwrite = $form->value('overwrite_files') == '1' ? TRUE : FALSE; $create = array(); // FRONTEND CONTROLLER if ($form->value('create_frontend_controller') == '1') { $extends = $form->value('frontend_controller_extends') != '' ? 'Controller_' . ucfirst($form->value('frontend_controller_extends')) : 'Controller'; $content = <<<YUNA <?php class Controller_{$name} extends {$extends} { } YUNA; $create[] = array('path' => FRONTENDPATH . 'classes/Controller/' . $file, 'content' => $content); } // FRONTEND TEXT if ($form->value('create_frontend_Text') == '1') { $extends = $form->value('frontend_Text_extends') != '' ? 'Text_' . ucfirst($form->value('frontend_Text_extends')) : 'Text'; $content = <<<YUNA <?php class Text_{$name} extends {$extends} { \tprotected function init() \t{ \t\tparent::init(); \t\t \t} } YUNA; $create[] = array('path' => FRONTENDPATH . 'classes/Model/Text/' . $file, 'content' => $content); } // BACEKND CONTROLLER if ($form->value('create_backend_controller') == '1') { $extends = $form->value('backend_controller_extends') != '' ? 'Controller_' . ucfirst($form->value('backend_controller_extends')) : 'Controller_Module'; $content = <<<YUNA <?php class Controller_{$name} extends {$extends} { } YUNA; $create[] = array('path' => BACKENDPATH . 'classes/Controller/' . $file, 'content' => $content); } // BACKEND SETTINGS if ($form->value('create_backend_settings') == '1') { $extends = $form->value('backend_settings_extends') != '' ? 'Settings_' . ucfirst($form->value('backend_settings_extends')) : 'Settings'; $content = <<<YUNA <?php class Settings_{$name} extends {$extends} { \tprotected function init() \t{ \t\tparent::init(); \t\t \t} } YUNA; $create[] = array('path' => BACKENDPATH . 'classes/Settings/' . $file, 'content' => $content); } // BACKEND TEXT if ($form->value('create_backend_Text') == '1') { $extends = $form->value('backend_Text_extends') != '' ? 'Text_' . ucfirst($form->value('backend_Text_extends')) : 'Text_Base'; if ($extends != 'Text_Base') { // add item text data $data = <<<YUNA \t\t\$this->_data['nl']['module'] = '{$form->value('backend_Text_module')}'; \t\t\$this->_data['nl']['substitutes'][':module'] = '{$form->value('backend_Text_module_single')}'; \t\t\$this->_data['nl']['substitutes'][':module_plural'] = '{$form->value('backend_Text_module_plural')}'; \t\t\$this->_data['nl']['substitutes'][':module_member'] = '{$form->value('backend_Text_module_member')}'; \t\t\$this->_data['nl']['substitutes'][':module_this'] = '{$form->value('backend_Text_module_this')}'; \t\t\$this->_data['nl']['substitutes'][':module_that'] = '{$form->value('backend_Text_module_that')}'; \t\t\$this->_data['nl']['substitutes'][':module_new'] = '{$form->value('backend_Text_module_new')}'; YUNA; // add en text data if ($form->value('create_backend_Text') == '1') { $data .= <<<YUNA \t\t \t\t \t\t\$this->_data['en']['module'] = '{$form->value('backend_Text_module_en')}'; \t\t\$this->_data['en']['substitutes'][':module'] = '{$form->value('backend_Text_module_single_en')}'; \t\t\$this->_data['en']['substitutes'][':module_plural'] = '{$form->value('backend_Text_module_plural_en')}'; \t\t\$this->_data['en']['substitutes'][':module_member'] = '{$form->value('backend_Text_module_member_en')}'; \t\t\$this->_data['en']['substitutes'][':module_this'] = '{$form->value('backend_Text_module_this_en')}'; \t\t\$this->_data['en']['substitutes'][':module_that'] = '{$form->value('backend_Text_module_that_en')}'; \t\t\$this->_data['en']['substitutes'][':module_new'] = '{$form->value('backend_Text_module_new_en')}'; YUNA; } } else { $data = ''; } $content = <<<YUNA <?php class Text_{$name} extends {$extends} { \tprotected function init() \t{ \t\tparent::init(); {$data} \t} } YUNA; $create[] = array('path' => BACKENDPATH . 'classes/Model/Text/' . $file, 'content' => $content); } // BACKEND FORM if ($form->value('create_backend_Form') == '1') { $extends = $form->value('backend_Form_extends') != '' ? 'Form_' . ucfirst($form->value('backend_Form_extends')) : 'Form_Base'; $content = <<<YUNA <?php class Form_{$name} extends {$extends} { \tprotected function init() \t{ \t} } YUNA; $create[] = array('path' => BACKENDPATH . 'classes/Model/Form/' . $file, 'content' => $content); } // BACKEND MODEL if ($form->value('create_model') == '1') { $tableName = strtolower($name); $extends = $form->value('model_extends') != '' ? 'Model_' . ucfirst($form->value('model_extends')) : 'Model_Base'; $data = ''; for ($i = 0; $i < 20; $i++) { if ($form->value('model_field_name_' . $i) != '') { $fieldName = $form->value('model_field_name_' . $i); $fieldType = $form->value('model_field_type_' . $i) != '' ? $form->value('model_field_type_' . $i) : 'NULL'; $data .= <<<YUNA \t\t \t\t'{$fieldName}'=>'{$fieldType}', YUNA; } } if ($form->value('model_item_fields') == '1') { $table = <<<YUNA \tprotected \$_table_columns = array( \t\t'id'=>'int', \t\t'parent_id'=>'int', \t\t'alias'=>'varchar', \t\t'created'=>'datetime', \t\t'timestamp'=>'timestamp', \t\t'rank'=>'int', \t\t'branch'=>'int', \t\t'deletable'=>'int', \t\t'updatable'=>'int', \t\t'movable'=>'int', \t\t'status'=>'varchar', \t\t'title'=>'varchar',{$data} \t\t'website_id'=>'varchar', \t\t'owner_id'=>'int', \t\t'editor_id'=>'int', \t); YUNA; } else { $table = <<<YUNA \tprotected \$_table_columns = array( {$data} \t); YUNA; } $content = <<<YUNA <?php class Model_{$name} extends {$extends} { \tprotected \$_table_name = '{$tableName}'; \t\t {$table} } YUNA; $create[] = array('path' => COMMONPATH . 'classes/Model/' . $file, 'content' => $content); } // TABLE if ($form->value('create_table') == '1') { $data = ''; for ($i = 0; $i < 20; $i++) { if ($form->value('model_field_name_' . $i) != '') { $fieldName = $form->value('model_field_name_' . $i); $fieldType = $form->value('model_field_type_' . $i) != '' ? $form->value('model_field_type_' . $i) : 'varchar(255)'; $fieldNotNull = $form->value('model_field_notnull_' . $i) == '1' ? 'NOT NULL' : ''; $default = $form->value('model_field_default_' . $i) != '' ? ' DEFAULT ' . $form->value('model_field_default_' . $i) : ''; $data .= <<<YUNA \t\t \t\t`{$fieldName}` {$fieldType} {$fieldNotNull} {$default}, YUNA; } } if ($form->value('model_item_fields') == '1') { $query = <<<YUNA `parent_id` int(11) NOT NULL DEFAULT '0', `alias` varchar(255) NOT NULL DEFAULT '', `created` datetime DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `branch` tinyint(4) NOT NULL DEFAULT '0', `deletable` tinyint(4) NOT NULL DEFAULT '1', `updatable` tinyint(4) NOT NULL DEFAULT '1', `movable` tinyint(4) NOT NULL DEFAULT '1', `status` enum('new','edit','review','live') NOT NULL DEFAULT 'live', `rank` int(11) NOT NULL DEFAULT '0', `title` varchar(255) NOT NULL DEFAULT '', \t{$data} `owner_id` int(11) NOT NULL DEFAULT '0', `editor_id` int(11) NOT NULL DEFAULT '0', `website_id` varchar(63) NOT NULL DEFAULT '', KEY `owner_id` (`owner_id`), KEY `parent_id` (`parent_id`), KEY `website_id` (`website_id`), YUNA; } else { $query = <<<YUNA {$data} YUNA; } $tableName = strtolower($name); $content = <<<YUNA CREATE TABLE `{$tableName}` ( `id` int(11) NOT NULL AUTO_INCREMENT, {$query} PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; YUNA; $create[] = array('path' => 'mysql', 'content' => $content); } $body = ''; foreach ($create as $item) { if ($item['path'] == 'mysql') { $body .= 'query wordt uitgevoerd:<br />'; $body .= nl2br(htmlspecialchars($item['content'])) . '<br />'; DB::query(NULL, $item['content'])->execute(); } else { if (file_exists($item['path'])) { if ($overwrite === TRUE) { $body .= 'file wordt OVERschreven: ' . $item['path'] . '<br />'; $body .= nl2br(htmlspecialchars($item['content'])) . '<br />'; file_put_contents($item['path'], $item['content']); } else { $body .= 'file bestaat al: ' . $item['path'] . '<br />'; } } else { $body .= 'file wordt geschreven: ' . $item['path'] . '<br />'; $body .= nl2br(htmlspecialchars($item['content'])) . '<br />'; file_put_contents($item['path'], $item['content']); } } } $body .= <<<YUNA <br /> <br /> Volgende stappen: <br /> 1. Modules toevoegen aan application/backend/config/modules.php<br /> 2. Modules toevoegen aan application/common/model/rights<br /> YUNA; // create files $this->response->body($body); } else { $style = <<<YUNA <head> <style> \t.section{ \t\tbackground-color: #EEEEEE; \t\tmargin: 5px; \t} \t \t.label{ \t\tfloat: left; \t} \t \tli{ \t\tlist-style: none; \t} </style> </head> YUNA; $this->response->body($style . View::factory('form', array('form' => $form))->render()); } }