Ejemplo n.º 1
0
function addSubmitButton($form, $subButtonText, $go_back = "", $currentURL, $button_text, $settings, $entry, $fids, $formframe, $mainform, $cur_entry, $profileForm, $elements_allowed = "", $allDoneOverride = false, $printall = 0, $screen = null)
{
    //nmc 2007.03.24 - added $printall
    if ($printall == 2) {
        // 2 is special setting in multipage screens that means do not include any printable buttons of any kind
        return $form;
    }
    if (strstr($currentURL, "printview.php")) {
        // don't do anything if we're on the print view
        return $form;
    } else {
        drawGoBackForm($go_back, $currentURL, $settings, $entry);
        if (!$button_text or $button_text == "{NOBUTTON}" and $go_back['form'] > 0) {
            // presence of a goback form (ie: parent form) overrides {NOBUTTON} -- assumption is the save button will not also be overridden at the same time
            $button_text = _formulize_DONE;
        } elseif (is_array($button_text)) {
            if (!$button_text[0]) {
                $done_text_temp = _formulize_DONE;
            } else {
                $done_text_temp = $button_text[0];
            }
            if (!$button_text[1]) {
                $save_text_temp = _formulize_SAVE;
            } else {
                $save_text_temp = $button_text[1];
            }
        }
        // override -- the "no-all-done-button" config option turns off the all done button and changes save into a save-and-leave button
        // need to grab the $nosubforms variable created by the multiple page function, so we know to put the printable view button (and nothing else) on the screen for multipage forms
        global $nosubforms;
        if (!$profileForm and ($save_text_temp != "{NOBUTTON}" or $nosubforms)) {
            // do not use printable button for profile forms, or forms where there is no Save button (ie: a non-standard saving process is in use and access to the normal printable option may be prohibited)
            $printbutton = new XoopsFormButton('', 'printbutton', _formulize_PRINTVIEW, 'button');
            if (is_array($elements_allowed)) {
                $ele_allowed = implode(",", $elements_allowed);
            }
            $printbutton->setExtra("onclick='javascript:PrintPop(\"{$ele_allowed}\");'");
            $rendered_buttons = $printbutton->render();
            // nmc 2007.03.24 - added
            if ($printall) {
                // nmc 2007.03.24 - added
                $printallbutton = new XoopsFormButton('', 'printallbutton', _formulize_PRINTALLVIEW, 'button');
                // nmc 2007.03.24 - added
                $printallbutton->setExtra("onclick='javascript:PrintAllPop();'");
                // nmc 2007.03.24 - added
                $rendered_buttons .= "   " . $printallbutton->render();
                // nmc 2007.03.24 - added
            }
            $buttontray = new XoopsFormElementTray($rendered_buttons, " ");
            // nmc 2007.03.24 - amended [nb: FormElementTray 'caption' is actually either 1 or 2 buttons]
        } else {
            $buttontray = new XoopsFormElementTray("", " ");
        }
        $buttontray->setClass("no-print");
        if ($subButtonText == _formulize_SAVE) {
            // _formulize_SAVE is passed only when the save button is allowed to be drawn
            if ($save_text_temp) {
                $subButtonText = $save_text_temp;
            }
            if ($subButtonText != "{NOBUTTON}") {
                $saveButton = new XoopsFormButton('', 'submitx', trans($subButtonText), 'button');
                // doesn't use name submit since that conflicts with the submit javascript function
                $saveButton->setExtra("onclick=javascript:validateAndSubmit();");
                $buttontray->addElement($saveButton);
                // also add in the save and leave button
                $saveAndLeaveButton = new XoopsFormButton('', 'submit_save_and_leave', trans(_formulize_SAVE_AND_LEAVE), 'button');
                $saveAndLeaveButton->setExtra("onclick=javascript:validateAndSubmit('leave');");
                $buttontray->addElement($saveAndLeaveButton);
            }
        }
        if (($button_text != "{NOBUTTON}" and !$done_text_temp or isset($done_text_temp) and $done_text_temp != "{NOBUTTON}") and !$allDoneOverride) {
            if ($done_text_temp) {
                $button_text = $done_text_temp;
            }
            $donebutton = new XoopsFormButton('', 'donebutton', trans($button_text), 'button');
            $donebutton->setExtra("onclick=javascript:verifyDone();");
            $buttontray->addElement($donebutton);
        }
        if (!$profileForm) {
            // do not use printable button for profile forms
            $newcurrentURL = XOOPS_URL . "/modules/formulize/printview.php";
            print "<form name='printview' action='" . $newcurrentURL . "' method=post target=_blank>\n";
            // add security token
            if (isset($GLOBALS['xoopsSecurity'])) {
                print $GLOBALS['xoopsSecurity']->getTokenHTML();
            }
            $currentPage = "";
            $screenid = "";
            if ($screen) {
                $screenid = $screen->getVar('sid');
                // check for a current page setting
                if (isset($settings['formulize_currentPage'])) {
                    $currentPage = $settings['formulize_currentPage'];
                }
            }
            print "<input type=hidden name=screenid value='" . $screenid . "'>";
            print "<input type=hidden name=currentpage value='" . $currentPage . "'>";
            print "<input type=hidden name=lastentry value=" . $cur_entry . ">";
            if ($go_back['form']) {
                // we're on a sub, so display this form only
                print "<input type=hidden name=formframe value=" . $fids[0] . ">";
            } else {
                // otherwise, display like normal
                print "<input type=hidden name=formframe value='" . $formframe . "'>";
                print "<input type=hidden name=mainform value='" . $mainform . "'>";
            }
            if (is_array($elements_allowed)) {
                $ele_allowed = implode(",", $elements_allowed);
                print "<input type=hidden name=elements_allowed value='" . $ele_allowed . "'>";
            } else {
                print "<input type=hidden name=elements_allowed value=''>";
            }
            print "</form>";
            //added by Cory Aug 27, 2005 to make forms printable
        }
        $trayElements = $buttontray->getElements();
        if (count($trayElements) > 0 or $nosubforms) {
            $form->addElement($buttontray);
        }
        return $form;
    }
}