require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/Default.php';
class form extends outBlueContent
{
var $content = array('body' => '');
var $current_rec;
var $current_section;
var $db;
function xmail($email_address,$email_from,$subject,$msg,$attach_filepath) {
$b = 0;
$mail_attached = "";
$boundary = md5(uniqid(time(),1))."_xmail";
if (count($attach_filepath)>0) {
for ($a=0;$adb->query($sql);
if(($row = $result->fetchRow()))
{
$xml_string .= "";
$form_id = $row['id'];
$message = $row['message'];
$xml_string = addslashes($xml_string);
$string = addslashes($string);
$sql = "insert into form_results(form_id, result_text, result_xml) values($form_id,'$string','$xml_string')";
$this->db->query($sql);
if($row['email_to'] != '')
{
$headers = "From: webmaster@" . BLUECMS_SITENAME . "\r\nReply-To: webmaster@" . BLUECMS_SITENAME . "\r\n";
$string = "Generated by page $base \r\n" . $string;
if(count($files) >0)
$this->xmail($row['email_to'],"webmaster@" . BLUECMS_SITENAME , "Form generated mail from " . BLUECMS_SITENAME . "...", $string, $files);
else
mail($row['email_to'], "Form generated mail from " . BLUECMS_SITENAME . "...", $string, $headers);
}
}
$this->content['body'] = '
' . $message . '
';
return($this->content['body']);
}
else
{
return( stripslashes($this->content['body']));
}
}
/**
load should retrieve from the db and stuff in the content array.
*/
function load($template_var)
{
$this->content['body'] = $this->get_content_from_db($template_var);
}
function get_content_from_db($template_var)
{
if(isset($this->current_rec))
{
$f = new HTML_QuickForm('form', 'POST');
$r = & new HTML_QuickForm_Renderer_Default();
$el="\n\t
\n\t\t
*{label} {error} \t{element}
\n\t
";
$r->setElementTemplate($el);
$groupT="
{content}
";
$elT = '
{label}
{element}
';
$r->setGroupTemplate($groupT, 'grpLabel');
$r->setGroupElementTemplate($elT, 'grpLabel');
$sql = "select form.id as form_id, form_url, form.description as form_description, title, form_description.* from form
inner join form_description on form.id=form_id
where form.id=" . $this->current_rec . ' order by id';
$result = $this->db->query($sql);
$first = true;
$els = array();
$grp = array();
while($row = $result->fetchRow())
{
if($first == true)
{
$top = '
' . $row['title'] . '
' . "\n" .
'
' . $row['form_description'] . '
';
$first = false;
}
if($row['grp'] != 0)
if(count($grp) ==0) #first item in group
{
$labels = $row['labels'];
$grplabel = $row['description'];
$grpnum = $row['grp'];
$grpname = $row['name']; //first in group..
}
switch($row['form_type'])
{
case 'text':
$el = &HTML_QuickForm::createElement('text', $row['name'], $row['description'], array('size'=>$row['data_size']));
break;
case 'textarea':
list($rows, $cols) = explode(',', $row['data_size']);
$el = &HTML_QuickForm::createElement('textarea', $row['name'],$row['description'], array('rows'=>$rows, 'cols'=>$cols));
break;
case 'checkbox':
$el = &HTML_QuickForm::createElement('checkbox', $row['name'], $row['description'], array('value'=>'True'));
break;
case 'radio':
#only added as a group. It's a rule!, so use first name in group
$el = &HTML_QuickForm::createElement('radio', $grpname, 'some laberl',$row['select_values'], $row['select_values']);
break;
case 'file':
$el = &HTML_QuickForm::createElement('file', $row['name'], $row['description']);
break;
case 'select':
$list = explode(',', $row['select_values']);
if(is_array($list))
{
foreach($list as $key => $value)
$list[$key] = trim($value);
}
else
{
$list = array();
}
$el = &HTML_QuickForm::createElement('select', $row['name'],$row['description']);
$el->loadArray($list);
break;
default:
$el = &HTML_QuickForm::createElement(array('text', $row['name'], $row['description'], 'size'=>$row['data_size']));
break;
}
if($row['grp'] != 0)
{
if($grpnum == $row['grp'])
{
$grp[] = $el;
}
else #else if starting a new group
{
if(count($grp) > 0)
{
$this->addGroup($f, $labels, $grplabel, $grp);
$grp = array();
$grp[] = $el;
}
}
}
else
{
if(count($grp) > 0)
{
$this->addGroup($f, $labels, $grplabel, $grp);
$grp = array();
}
$f->addElement($el);
}
}
#oh yeah, and if last el was part of group, then wasn't added yet
if(count($grp) > 0)
$this->addGroup($f, $labels, $grplabel, $grp);
if($first == false)
{
$el = &HTML_QuickForm::createElement('submit', '__auto_gen_form_submit','Submit');
$f->addElement($el);
$f->accept($r);
return($top . $r->toHtml());
}
else
{
return('');
}
}
else
{
return('');
}
}
function addGroup(&$f, $labels, $grplabel, &$grp)
{
if($labels==1)
{
$f->addGroup($grp, 'grpLabel', '',' ',False);
}
else
{
$f->addGroup($grp, 'grpNoLabels', $grplabel,' ',False);
}
}
function handle_nav()
{
$base = current_path();
$sql = "select form.id as form_id from form
where form_url='$base'";
$result = $this->db->query($sql);
if($row = $result->fetchRow())
{
$this->set_current($row['form_id']);
}
}
function get_admin()
{
return('