function SitefaqEditForm() { parent::MailForm(); global $page, $cgi; $this->extra = 'id="cms-edit-form"'; // get copy from repository loader_import('cms.Versioning.Rex'); $rex = new Rex($cgi->_collection); // default: database, database $_document = $rex->getCurrent($cgi->_key); $widgets = $rex->getStruct(); if (!$widgets) { $widgets = array(); } // edit widgets go here $this->widgets = array_merge($this->widgets, $widgets); foreach ($this->widgets as $k => $v) { if (isset($_document->{$k})) { $this->widgets[$k]->setValue($_document->{$k}); } } $w =& $this->addWidget('hidden', '_key'); $w =& $this->addWidget('hidden', '_collection'); $w =& $this->addWidget('hidden', '_return'); if ($rex->isVersioned) { $t =& $this->addWidget('textarea', 'changelog'); $t->alt = intl_get('Change Summary'); $t->rows = 3; $t->labelPosition = 'left'; $t->extra = 'id="changelog"'; } // submit buttons $w =& $this->addWidget('msubmit', 'submit_button'); $b =& $w->getButton(); $b->setValues(intl_get('Save')); $b =& $w->addButton('submit_button', intl_get('Cancel')); $b->extra = 'onclick="return cms_cancel (this.form)"'; $this->error_mode = 'all'; if ($rex->info['Collection']['singular']) { page_title(intl_get('Editing') . ' ' . $rex->info['Collection']['singular'] . ': ' . $_document->{$rex->key}); } else { page_title(intl_get('Editing Item') . ': ' . $_document->{$rex->key}); } // the SiteFAQ additions: if (appconf('user_anonymity')) { unset($this->widgets['name']); unset($this->widgets['email']); unset($this->widgets['url']); unset($this->widgets['ip']); unset($this->widgets['member_id']); } $admin_roles = session_admin_roles(); $this->widgets['assigned_to']->setValues(db_pairs('select username, concat(lastname, ", ", firstname, " (", username, ")") from sitellite_user where role in("' . join('", "', $admin_roles) . '") order by lastname, firstname, username')); if (!$_document->assigned_to) { $this->widgets['assigned_to']->setValue(session_username()); } }
function onSubmit($vals) { // 1. insert into sitefaq_submission table if ($vals['url'] == 'http://') { $vals['url'] = ''; } $member_id = session_username(); if (!$member_id) { $member_id = ''; } if (!$vals['name']) { $vals['name'] = ''; } if (!$vals['age']) { $vals['age'] = ''; } if (!$vals['url']) { $vals['url'] = ''; } db_execute('insert into sitefaq_submission (id, question, answer, ts, assigned_to, email, member_id, ip, name, age, url, sitellite_status, sitellite_access, sitellite_owner, sitellite_team) values (null, ?, "", now(), "", ?, ?, ?, ?, ?, ?, "draft", "private", "", "none")', $vals['question'], $vals['email'], $member_id, $_SERVER['REMOTE_ADDR'], $vals['name'], $vals['age'], $vals['url']); // 2. email all admins $admin_roles = session_admin_roles(); $emails = db_shift_array('select distinct email from sitellite_user where role in("' . join('", "', $admin_roles) . '")'); foreach ($emails as $email) { @mail($email, intl_get('FAQ Submission Notice'), template_simple('email_notice.spt', $vals), 'From: faq@' . str_replace('www.', '', site_domain())); } // 4. if the user provided an email address, send a thank you if (!empty($vals['email'])) { @mail($vals['email'], intl_get('FAQ Submission Received'), template_simple('email_thank_you.spt', $vals), 'From: faq@' . str_replace('www.', '', site_domain())); } // 3. output a thank you page_title(intl_get('Thank You')); echo template_simple('thank_you.spt', $vals); }