/** * @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 Processes the registration * @access public */ public function process_registration() { $form = new Form('users', false, array('groups')); $form->addField('password_confirm'); if ($form->isSubmitted()) { if ($form->save()) { $this->mail->AddAddress($form->cv('username')); $this->mail->From = $this->config('email_sender'); $this->mail->FromName = $this->config('email_sender_name'); $this->mail->Mailer = "mail"; $this->mail->ContentType = 'text/html'; $this->mail->Subject = $this->website_title() . " Registration Confirmation"; $body = $this->config('registration_email_body'); $body = str_replace('{website}', $this->website_title(), $body); $body = str_replace('{user}', $form->cv('username'), $body); $body = str_replace('{pass}', post()->getRaw('password'), $body); $this->mail->Body = $body; $this->mail->Send(); $this->mail->ClearAddresses(); // send to thanks page $thanks = $this->cms_lib->url($this->config('registration_thanks_page_id')); header("Location: " . (empty($thanks) ? 'index.php' : $thanks)); exit; } } return $form; }
/** * @abstract Edits an event recprd * @param integer $id * @access public */ public function edit($id = false) { $form = new Form('courses', $id); // grab existing groups settings $model = model()->open('course_groups_link'); $model->where('course_id', $id); $group_records = $model->results(); $groups = array(); if ($group_records) { foreach ($group_records as $course_record) { $groups[] = $course_record['group_id']; } } $form->addField('groups', $groups, $groups); // proces the form if submitted if ($form->isSubmitted()) { // validation if (!$form->isFilled('title')) { $form->addError('title', 'You must enter a course title.'); } // if we have no errors, process sql if (!$form->error()) { if ($res_id = $form->save($id)) { $id = $id ? $id : $res_id; // update course groups $model->delete('course_groups_link', $id, 'course_id'); $groups = $form->cv('groups'); foreach ($groups as $group) { $sql = sprintf('INSERT INTO course_groups_link (course_id, group_id) VALUES ("%s", "%s")', $id, $group); $model->query($sql); } // if successful insert, redirect to the list sml()->say('The course has successfully been saved.'); router()->redirect('view'); } } } $data['form'] = $form; template()->addView(template()->getTemplateDir() . DS . 'header.tpl.php'); template()->addView(template()->getModuleTemplateDir() . DS . 'edit.tpl.php'); template()->addView(template()->getTemplateDir() . DS . 'footer.tpl.php'); template()->display($data); }
/** * Displays and processes the forgotten password system * @access public */ public function forgot() { $form = new Form(); $form->addFields(array('user')); // process the form if submitted if ($form->isSubmitted()) { // generate a new password $new_pass = $this->makePassword(); // load the account $auth = model()->open('users'); $user = $auth->quickSelectSingle($form->cv('user'), 'username'); if (is_array($user)) { // update the account $user['password'] = $user['password_confirm'] = $new_pass; $auth->update($user, $user['id']); if (app()->db->Affected_Rows()) { app()->mail->AddAddress($form->cv('user')); app()->mail->From = app()->config('email_sender'); app()->mail->FromName = app()->config('email_sender_name'); app()->mail->Mailer = "mail"; app()->mail->ContentType = 'text/html'; app()->mail->Subject = app()->config('password_reset_subject'); app()->mail->Body = str_replace('{new_pass}', $new_pass, app()->config('password_reset_body')); app()->mail->Send(); app()->mail->ClearAddresses(); return 1; } } else { return -1; } } template()->set(array('form' => $form)); return false; }
/** * @abstract Edits an event recprd * @param integer $id * @access public */ public function edit_event($id = false) { template()->addCss('admin/datepicker.css'); template()->addJs('admin/datepicker.js'); template()->addJs('edit.js'); if ($id) { $form = new Form('events', $id, array('event_groups')); if ($form->cv('end_date') == '0000-00-00') { $form->setDefaultValue('end_date', ''); } $start_time = strtotime($form->cv('start_time')); if ($form->cv('start_time') != '00:00:00') { $form->addField('start_hour', date("h", $start_time), date("h", $start_time)); $form->addField('start_minute', date("i", $start_time), date("i", $start_time)); $form->addField('start_ampm', date("a", $start_time), date("a", $start_time)); } else { $form->addField('start_hour'); $form->addField('start_minute'); $form->addField('start_ampm'); } $end_time = strtotime($form->cv('end_time')); if ($form->cv('end_time') != '00:00:00') { $form->addField('end_hour', date("h", $end_time), date("h", $end_time)); $form->addField('end_minute', date("i", $end_time), date("i", $end_time)); $form->addField('end_ampm', date("a", $end_time), date("a", $end_time)); } else { $form->addField('end_hour'); $form->addField('end_minute'); $form->addField('end_ampm'); } $data['form'] = $form; // proces the form if submitted if ($form->isSubmitted()) { $this->timeString('start', $form); $this->timeString('end', $form); // @todo move to model if (!post()->keyExists('recurring')) { $form->setCurrentValue('recurring', false); } else { $form->setCurrentValue('start_date', ''); $form->setCurrentValue('end_date', ''); } if ($form->save($id)) { sml()->say('Event has successfully been updated.'); router()->redirect('view'); } else { sml()->say('An error occurred. Please try again.'); } } } template()->display($data); }