/** * @abstract Displays and processes the edit news form * @param integer $id * @access public */ public function edit($id = false) { if (!files()->setUploadDirectory()) { sml()->say("The file upload directory does not appear to be writable. Please create the folder and set proper permissions."); } $form = new Form('news', $id); if (!$id) { $form->setCurrentValue('timestamp', date("Y-m-d H:i:s")); } // if form has been submitted if ($form->isSubmitted()) { $file = files()->upload('pdf_filename'); if (is_array($file) && !empty($file[0])) { $form->setCurrentValue('pdf_filename', $file[0]['file_name']); } if ($form->save($id)) { sml()->say('News entry has successfully been updated.'); router()->redirect('view'); } } // make sure the template has access to all current values $data['form'] = $form; template()->addCss('admin/datepicker.css'); template()->addJs('admin/datepicker.js'); template()->addJs('edit.js'); template()->display($data); }
/** * @abstract Displays and processes the signup form * @access public * @param integer $id */ public function signup() { // if the user is logged in, send to interface if ($this->isLoggedIn()) { router()->redirectToUrl(app()->router->interfaceUrl()); } $result = false; $form = new Form('users', false, array('groups')); $form->addFields(array('password_confirm')); // process the form if submitted if ($form->isSubmitted()) { $form->setCurrentValue('allow_login', 1); $form->setCurrentValue('Groups', array(2)); $result = $form->save(); } template()->set(array('form' => $form)); return $result; }
/** * @abstract Add a new page * @access public */ public function add() { $form = new Form('pages'); // process the form if submitted if ($form->isSubmitted()) { $form->setCurrentValue('page_sort_order', $model->quickValue('SELECT MAX(page_sort_order) FROM pages', 'MAX(page_sort_order)') + 1); // form field validation if (!$form->isFilled('page_title')) { $form->addError('page_title', 'You must enter a page title.'); } // if we have no errors, save the record if (!$form->error()) { // set the link text field to the page title if blank if (!$form->isFilled('page_link_text')) { $form->setCurrentValue('page_link_text', $form->cv('page_title')); } return $form->save(); } } return false; }
/** * @abstract Edits a page and all content sections * @param integer $id */ public function edit($id) { template()->addCss('style.css'); template()->addJs('admin/datepicker.js'); template()->addJs('edit.js'); template()->addJsVar('last_id', app()->Pages_Admin->section_count); $data['templates'] = $this->scanTemplateList(); $data['available_sections'] = director()->getPageSections(); $form = new Form('pages', $id); // load sections $data['sections'] = array(); // pull all references to sections for this page $model = model()->open('section_list'); $model->where('page_id', $id); $sections = $model->results(); if ($sections) { foreach ($sections as $section) { $section_results = model()->open('section_' . strtolower($section['section_type']), $section['section_id']); $data['sections'][$section['id']]['meta'] = $section; $data['sections'][$section['id']]['content'] = $section_results; } $this->section_count = count($data['sections']) - 1; } // add in section field names so our form handler can see them foreach (director()->getPageSections() as $section_field) { $form->addField($section_field['option_value']); } // process the form if submitted if ($form->isSubmitted()) { // set checkboxes to false if they're not sent from browser // @todo is this really needed? if (!post()->keyExists('show_in_menu')) { $form->setCurrentValue('show_in_menu', false); } if (!post()->keyExists('page_is_live')) { $form->setCurrentValue('page_is_live', false); } if (!post()->keyExists('is_parent_default')) { $form->setCurrentValue('is_parent_default', false); } if (!post()->keyExists('login_required')) { $form->setCurrentValue('login_required', false); } // update page information if ($form->save($id)) { $model = model()->open('section_list'); // remove all current sections references $model->delete($id, 'page_id'); $sections = director()->savePageSections($id); // store references to the specifc sections foreach ($sections as $key => $section) { $model->insert(array('page_id' => $id, 'section_type' => $section['type'], 'section_id' => $section['id'], 'sort_order' => $key, 'called_in_template' => $section['called_in_template'], 'placement_group' => $section['placement_group'])); } sml()->say('Page changes have been saved successfully. ' . template()->link('Edit Again', 'edit', array($id))); router()->redirect('view'); } else { sml()->say('An error occurred. Please try again.'); } } $data['form'] = $form; template()->display($data); }