Exemplo n.º 1
0
function save($task)
{
    $old = false;
    $mainframe = JFactory::getApplication();
    $row = JTable::getInstance('formmaker', 'Table');
    if (!$row->bind(JRequest::get('post'))) {
        JError::raiseError(500, $row->getError());
    }
    $new = !isset($row->id);
    if (isset($row->form)) {
        $old = true;
    }
    $fid = $row->id;
    if ($fid && ($old == true && $row->form != '')) {
        $row->form = JRequest::getVar('form', '', 'post', 'string', JREQUEST_ALLOWRAW);
    } else {
        $row->form_fields = JRequest::getVar('form_fields', '', 'post', 'string', JREQUEST_ALLOWRAW);
    }
    $row->form_front = JRequest::getVar('form_front', '', 'post', 'string', JREQUEST_ALLOWRAW);
    $row->sortable = JRequest::getVar('sortable', '', 'post', 'string', JREQUEST_ALLOWRAW);
    if (!$row->store()) {
        JError::raiseError(500, $row->getError());
    }
    if ($new) {
        $db = JFactory::getDBO();
        $db->setQuery("INSERT INTO #__formmaker_views (form_id, views) VALUES('" . $row->id . "', 0)");
        $db->query();
        if ($db->getErrorNum()) {
            echo $db->stderr();
            return false;
        }
    }
    switch ($task) {
        case 'apply':
            HTML_contact::forchrome($row->id);
            break;
        case 'save_and_new':
            $msg = 'The form has been saved successfully.';
            $link = 'index.php?option=com_formmaker&task=add';
            $mainframe->redirect($link, $msg, 'message');
            break;
        case 'save':
            $msg = 'The form has been saved successfully.';
            $link = 'index.php?option=com_formmaker';
            $mainframe->redirect($link, $msg, 'message');
            break;
        case 'return_id':
            return $row->id;
            break;
        default:
            break;
    }
}