Пример #1
0
function drawInterface($settings, $fid, $frid, $groups, $mid, $gperm_handler, $loadview = "", $loadOnlyView = 0, $screen, $searches, $pageNav, $messageText, $hiddenQuickSearches)
{
    global $xoopsDB;
    global $xoopsUser;
    // unpack the $settings
    foreach ($settings as $k => $v) {
        ${$k} = $v;
    }
    // get single/multi entry status of this form...
    $singleMulti = q("SELECT singleentry FROM " . $xoopsDB->prefix("formulize_id") . " WHERE id_form = {$fid}");
    // flatten columns array and convert handles to ids so that we can send them to the change columns popup
    // Since 4.0 columns and columnhandles are identical...this is a cleanup job for later
    $colhandles = implode(",", $columnhandles);
    // part of $settings
    $flatcols = implode(",", $columns);
    // part of $settings (will be IDs if no framework in effect)
    $useWorking = true;
    $useDefaultInterface = true;
    $useSearch = 1;
    if ($screen) {
        $useWorking = !$screen->getVar('useworkingmsg') ? false : true;
        $useDefaultInterface = $screen->getTemplate('toptemplate') != "" ? false : true;
        $title = $screen->getVar('title');
        // otherwise, title of the form is in the settings array for when no screen is in use
        $useSearch = ($screen->getVar('usesearch') and !$screen->getTemplate('listtemplate')) ? 1 : 0;
    }
    $submitButton = "<input type=submit name=submitx style=\"position: absolute; left: -10000px;\" value='' ></input>\n";
    // need to establish these here because they are used in conditions lower down
    $add_own_entry = $gperm_handler->checkRight("add_own_entry", $fid, $groups, $mid);
    $proxy = $gperm_handler->checkRight("add_proxy_entries", $fid, $groups, $mid);
    $uid = $xoopsUser ? $xoopsUser->getVar('uid') : "0";
    $user_can_delete = formulizePermHandler::user_can_delete_from_form($fid, $uid);
    $edit_form = $gperm_handler->checkRight("edit_form", $fid, $groups, $mid);
    $module_admin_rights = $gperm_handler->checkRight("module_admin", $mid, $groups, 1);
    // establish text and code for buttons, whether a screen is in effect or not
    $screenButtonText = array();
    $screenButtonText['modifyScreenLink'] = ($edit_form and $screen and $module_admin_rights) ? _formulize_DE_MODIFYSCREEN : "";
    $screenButtonText['changeColsButton'] = _formulize_DE_CHANGECOLS;
    $screenButtonText['calcButton'] = _formulize_DE_CALCS;
    $screenButtonText['advCalcButton'] = _formulize_DE_ADVCALCS;
    $screenButtonText['advSearchButton'] = _formulize_DE_ADVSEARCH;
    $screenButtonText['exportButton'] = _formulize_DE_EXPORT;
    $screenButtonText['exportCalcsButton'] = _formulize_DE_EXPORT_CALCS;
    $screenButtonText['importButton'] = _formulize_DE_IMPORTDATA;
    $screenButtonText['notifButton'] = _formulize_DE_NOTBUTTON;
    $screenButtonText['cloneButton'] = _formulize_DE_CLONESEL;
    $screenButtonText['deleteButton'] = _formulize_DE_DELETESEL;
    $screenButtonText['selectAllButton'] = _formulize_DE_SELALL;
    $screenButtonText['clearSelectButton'] = _formulize_DE_CLEARALL;
    $screenButtonText['resetViewButton'] = _formulize_DE_RESETVIEW;
    $screenButtonText['saveViewButton'] = _formulize_DE_SAVE;
    $screenButtonText['deleteViewButton'] = _formulize_DE_DELETE;
    $screenButtonText['currentViewList'] = _formulize_DE_CURRENT_VIEW;
    $screenButtonText['saveButton'] = _formulize_SAVE;
    $screenButtonText['globalQuickSearch'] = _formulize_GLOBAL_SEARCH;
    $screenButtonText['addButton'] = $singleMulti[0]['singleentry'] == "" ? _formulize_DE_ADDENTRY : _formulize_DE_UPDATEENTRY;
    $screenButtonText['addMultiButton'] = _formulize_DE_ADD_MULTIPLE_ENTRY;
    $screenButtonText['addProxyButton'] = _formulize_DE_PROXYENTRY;
    if ($screen) {
        if ($add_own_entry) {
            $screenButtonText['addButton'] = $screen->getVar('useaddupdate');
            $screenButtonText['addMultiButton'] = $screen->getVar('useaddmultiple');
        } else {
            $screenButtonText['addButton'] = "";
            $screenButtonText['addMultiButton'] = "";
        }
        if ($proxy) {
            $screenButtonText['addProxyButton'] = $screen->getVar('useaddproxy');
        } else {
            $screenButtonText['addProxyButton'] = "";
        }
        $screenButtonText['exportButton'] = $screen->getVar('useexport');
        $screenButtonText['importButton'] = $screen->getVar('useimport');
        $screenButtonText['notifButton'] = $screen->getVar('usenotifications');
        $screenButtonText['currentViewList'] = $screen->getVar('usecurrentviewlist');
        $screenButtonText['saveButton'] = $screen->getVar('desavetext');
        $screenButtonText['changeColsButton'] = $screen->getVar('usechangecols');
        $screenButtonText['calcButton'] = $screen->getVar('usecalcs');
        $screenButtonText['advCalcButton'] = $screen->getVar('useadvcalcs');
        $screenButtonText['advSearchButton'] = $screen->getVar('useadvsearch');
        $screenButtonText['exportCalcsButton'] = $screen->getVar('useexportcalcs');
        // only include clone and delete if the checkboxes are in effect (2 means do not use checkboxes)
        if ($screen->getVar('usecheckboxes') != 2) {
            $screenButtonText['cloneButton'] = $screen->getVar('useclone');
            if ($user_can_delete and !$settings['lockcontrols']) {
                $screenButtonText['deleteButton'] = $screen->getVar('usedelete');
            } else {
                $screenButtonText['deleteButton'] = "";
            }
            $screenButtonText['selectAllButton'] = $screen->getVar('useselectall');
            $screenButtonText['clearSelectButton'] = $screen->getVar('useclearall');
        } else {
            $screenButtonText['cloneButton'] = "";
            $screenButtonText['deleteButton'] = "";
            $screenButtonText['selectAllButton'] = "";
            $screenButtonText['clearSelectButton'] = "";
        }
        // only include the reset, save, deleteview buttons if the current view list is in effect
        if ($screen->getVar('usecurrentviewlist')) {
            $screenButtonText['resetViewButton'] = $screen->getVar('usereset');
            $screenButtonText['saveViewButton'] = $screen->getVar('usesave');
            $screenButtonText['deleteViewButton'] = $screen->getVar('usedeleteview');
        } else {
            $screenButtonText['resetViewButton'] = "";
            $screenButtonText['saveViewButton'] = "";
            $screenButtonText['deleteViewButton'] = "";
        }
    }
    if ($delete_other_reports = $gperm_handler->checkRight("delete_other_reports", $fid, $groups, $mid)) {
        $pubstart = 10000;
    }
    if ($screenButtonText['saveButton']) {
        $screenButtonText['goButton'] = $screenButtonText['saveButton'];
    }
    // want this button accessible by two names, essentially, since it serves two purposes semantically/logically
    $onActionButtonCounter = 0;
    $atLeastOneActionButton = false;
    foreach ($screenButtonText as $scrButton => $scrText) {
        formulize_benchmark("before creating button: " . $scrButton);
        $buttonCodeArray[$scrButton] = formulize_screenLOEButton($scrButton, $scrText, $settings, $fid, $frid, $colhandles, $flatcols, $pubstart, $loadOnlyView, $calc_cols, $calc_calcs, $calc_blanks, $calc_grouping, $singleMulti[0]['singleentry'], $lastloaded, $currentview, $endstandard, $pickgroups, $viewoptions, $loadviewname, $advcalc_acid, $screen);
        formulize_benchmark("button done");
        if ($buttonCodeArray[$scrButton] and $onActionButtonCounter < 14) {
            // first 14 items in the array should be the action buttons only
            $atLeastOneActionButton = true;
        }
        $onActionButtonCounter++;
    }
    if ($hlist) {
        // if we're on the calc side, then the export button should be the export calcs one
        $buttonCodeArray['exportButton'] = $buttonCodeArray['exportCalcsButton'];
    }
    $buttonCodeArray['pageNavControls'] = $pageNav;
    // put this unique UI element into the buttonCodeArray for use elsewhere if necessary
    $currentViewName = $settings['loadviewname'];
    if ($useDefaultInterface) {
        // if search is not used, generate the search boxes
        if (!$useSearch and $hcalc) {
            print "<div style=\"display: none;\"><table>";
            // enclose in a table, since drawSearches puts in <tr><td> tags
            drawSearches($searches, $settings['columns'], $useCheckboxes, $useViewEntryLinks, 0, false, $hiddenQuickSearches);
            print "</table></div>";
        }
        print "<table cellpadding=10><tr><td id='titleTable' style=\"vertical-align: top;\" width=100%>";
        print "<h1>" . trans($title) . "</h1>";
        if ($thisButtonCode = $buttonCodeArray['modifyScreenLink']) {
            print "{$thisButtonCode}<br />";
        }
        if ($loadview and $lockcontrols) {
            print "<h3>" . $loadviewname . "</h3></td><td>";
            print "<input type=hidden name=currentview id=currentview value=\"{$currentview}\"></input>\n<input type=hidden name=loadviewname id=loadviewname value=\"{$loadviewname}\"></input>{$submitButton}";
        } else {
            print "</td>";
            if (!$settings['lockcontrols']) {
                print "<td id='buttonsTable' class='outerTable' rowspan=3 style=\"vertical-align: bottom;\">";
                print "<table><tr><td id='leftButtonColumn' class='innerTable' style=\"vertical-align: bottom;\">";
                print "<p>{$submitButton}<br>";
                if ($atLeastOneActionButton) {
                    print "<b>" . _formulize_DE_ACTIONS . "</b>";
                }
                print "\n";
                if ($thisButtonCode = $buttonCodeArray['changeColsButton']) {
                    print "<br>{$thisButtonCode}";
                }
                if ($thisButtonCode = $buttonCodeArray['resetViewButton']) {
                    print "<br>{$thisButtonCode}";
                }
                // there is a create reports permission, but we are currently allowing everyone to save their own views regardless of that permission.  The publishing permissions do kick in on the save popup.
                if ($thisButtonCode = $buttonCodeArray['saveViewButton']) {
                    print "<br>{$thisButtonCode}";
                }
                // you can always create and delete your own reports right now (delete_own_reports perm has no effect).  If can delete other reports, then set $pubstart to 10000 -- which is done above -- (ie: can delete published as well as your own, because the javascript will consider everything beyond the start of 'your saved views' to be saved instead of published (published be thought to never begin))
                if ($thisButtonCode = $buttonCodeArray['deleteViewButton']) {
                    print "<br>{$thisButtonCode}";
                }
                print "</p></td><td id='middleButtonColumn' class='innerTable' style=\"vertical-align: bottom;\"><p style=\"text-align: center;\">";
                if ($add_own_entry and $singleMulti[0]['singleentry'] == "" or $user_can_delete and !$settings['lockcontrols']) {
                    if ($thisButtonCode = $buttonCodeArray['selectAllButton']) {
                        print "{$thisButtonCode}";
                    }
                    if ($thisButtonCode = $buttonCodeArray['clearSelectButton']) {
                        print "<br>{$thisButtonCode}<br>";
                    }
                }
                if ($add_own_entry and $singleMulti[0]['singleentry'] == "") {
                    if ($thisButtonCode = $buttonCodeArray['cloneButton']) {
                        print "{$thisButtonCode}<br>";
                    }
                }
                if ($user_can_delete and !$settings['lockcontrols']) {
                    if ($thisButtonCode = $buttonCodeArray['deleteButton']) {
                        print "{$thisButtonCode}<br>";
                    }
                }
                print "</p></td><td id='rightButtonColumn' class='innerTable' style=\"vertical-align: bottom;\"><p style=\"text-align: center;\">";
                if ($thisButtonCode = $buttonCodeArray['calcButton']) {
                    print "<br>{$thisButtonCode}";
                }
                if ($thisButtonCode = $buttonCodeArray['advCalcButton']) {
                    print "<br>{$thisButtonCode}";
                }
                if ($thisButtonCode = $buttonCodeArray['advSearchButton']) {
                    print "<br>{$thisButtonCode}";
                }
                if ($thisButtonCode = $buttonCodeArray['exportButton']) {
                    print "<br>{$thisButtonCode}";
                }
                if ($import_data = $gperm_handler->checkRight("import_data", $fid, $groups, $mid) and !$frid and $thisButtonCode = $buttonCodeArray['importButton']) {
                    // cannot import into a framework currently
                    print "<br>{$thisButtonCode}";
                }
                if ($thisButtonCode = $buttonCodeArray['notifButton']) {
                    print "{$thisButtonCode}";
                }
                print "</p>";
                print "</td></tr></table></td></tr>\n";
            } else {
                // if lockcontrols set, then write in explanation...
                print "<td></td></tr></table>";
                print "<table><tr><td style=\"vertical-align: bottom;\">";
                print "<input type=hidden name=curviewid id=curviewid value={$curviewid}></input>";
                print "<p>{$submitButton}<br>" . _formulize_DE_WARNLOCK . "</p>";
                print "</td></tr>";
            }
            // end of if controls are locked
            // cell for add entry buttons
            print "<tr><td id='outerAddEntryPanel' style=\"vertical-align: top;\">\n";
            if (!$settings['lockcontrols']) {
                // added October 18 2006 -- moved add entry buttons to left side to emphasize them more
                print "<table><tr><td id='innerAddEntryPanel' style=\"vertical-align: bottom;\"><p>\n";
                $addButton = $buttonCodeArray['addButton'];
                $addMultiButton = $buttonCodeArray['addMultiButton'];
                $addProxyButton = $buttonCodeArray['addProxyButton'];
                if ($add_own_entry and $singleMulti[0]['singleentry'] == "" and ($addButton or $addMultiButton)) {
                    print "<b>" . _formulize_DE_FILLINFORM . "</b>\n";
                    if ($addButton) {
                        print "<br>{$addButton}";
                    }
                    // this will include proxy box if necessary
                    if ($addMultiButton) {
                        print "<br>{$addMultiButton}";
                    }
                } elseif ($add_own_entry and $proxy and ($addButton or $addProxyButton)) {
                    // this is a single entry form, so add in the update and proxy buttons if they have proxy, otherwise, just add in update button
                    print "<b>" . _formulize_DE_FILLINFORM . "</b>\n";
                    if ($addButton) {
                        print "<br>{$addButton}";
                    }
                    if ($addProxyButton) {
                        print "<br>{$addProxyButton}";
                    }
                } elseif ($add_own_entry and $addButton) {
                    print "<b>" . _formulize_DE_FILLINFORM . "</b>\n";
                    if ($addButton) {
                        print "<br>{$addButton}";
                    }
                } elseif ($proxy and $addProxyButton) {
                    print "<b>" . _formulize_DE_FILLINFORM . "</b>\n";
                    if ($addProxyButton) {
                        print "<br>{$addProxyButton}";
                    }
                }
                print "<br><br></p></td></tr></table>\n";
            }
            print "</td></tr><tr><td id=currentViewSelectTable style=\"vertical-align: bottom;\">";
            if ($currentViewList = $buttonCodeArray['currentViewList']) {
                print $currentViewList;
            }
        }
        // end of if there's a loadview or not
        // regardless of if a view is loaded and/or controls are locked, always print the page navigation controls
        if ($pageNavControls = $buttonCodeArray['pageNavControls']) {
            print $pageNavControls;
        }
        print "</td></tr></table>";
    } else {
        // IF THERE IS A CUSTOM TOP TEMPLATE IN EFFECT, DO SOMETHING COMPLETELY DIFFERENT
        if (!$screen->getVar('usecurrentviewlist') or !strstr($screen->getTemplate('toptemplate'), 'currentViewList') and !strstr($screen->getTemplate('toptemplate'), 'currentViewList')) {
            print "<input type=hidden name=currentview id=currentview value=\"{$currentview}\"></input>\n";
        }
        // print it even if the text is blank, it will be a hidden value in this case
        // if search is not used, generate the search boxes and make them available in the template
        // also setup searches when calculations are in effect, or there's a custom list template
        // (essentially, whenever the search boxes would not be drawn in for whatever reason)
        if (!$useSearch or $calc_cols and !$hcalc or $screen->getTemplate('listtemplate')) {
            formulize_benchmark("before calling draw searches");
            $quickSearchBoxes = drawSearches($searches, $settings['columns'], $useCheckboxes, $useViewEntryLinks, 0, true, $hiddenQuickSearches, true);
            // first true means we will receive back the code instead of having it output to the screen, second (last) true means that all allowed filters should be generated
            formulize_benchmark("after calling draw searches");
            $quickSearchesNotInTemplate = array();
            foreach ($quickSearchBoxes as $handle => $qscode) {
                $handle = str_replace("-", "_", $handle);
                $foundQS = false;
                if (strstr($screen->getTemplate('toptemplate'), 'quickSearch' . $handle) or strstr($screen->getTemplate('bottomtemplate'), 'quickSearch' . $handle)) {
                    $buttonCodeArray['quickSearch' . $handle] = $qscode['search'];
                    // set variables for use in the template
                    $foundQS = true;
                }
                if (strstr($screen->getTemplate('toptemplate'), 'quickFilter' . $handle) or strstr($screen->getTemplate('bottomtemplate'), 'quickFilter' . $handle)) {
                    $buttonCodeArray['quickFilter' . $handle] = $qscode['filter'];
                    // set variables for use in the template
                    $foundQS = true;
                }
                if (strstr($screen->getTemplate('toptemplate'), 'quickDateRange' . $handle) or strstr($screen->getTemplate('bottomtemplate'), 'quickDateRange' . $handle)) {
                    $buttonCodeArray['quickDateRange' . $handle] = $qscode['dateRange'];
                    // set variables for use in the template
                    $foundQS = true;
                }
                if ($foundQS) {
                    continue;
                }
                // skip next line
                $quickSearchesNotInTemplate[] = $qscode['search'];
                // if it's not used in the template, then save the box version for hidden output to screen below, so searches still work
            }
            if (count($quickSearchesNotInTemplate) > 0) {
                print "<div style=\"display: none;\">";
                foreach ($quickSearchesNotInTemplate as $qscode) {
                    print $qscode . "\n";
                }
                print "</div>";
            }
        }
        formulize_benchmark("before rendering top template");
        formulize_screenLOETemplate($screen, "top", $buttonCodeArray, $settings, $messageText);
        formulize_benchmark("after rendering top template");
        $buttonCodeArray['submitButton'] = $submitButton;
        // send this back so that we can put it at the bottom of the page if necessary
    }
    print "<input type=hidden name=newcols id=newcols value=\"\"></input>\n";
    print "<input type=hidden name=oldcols id=oldcols value='{$flatcols}'></input>\n";
    print "<input type=hidden name=ventry id=ventry value=\"\"></input>\n";
    print "<input type=\"hidden\" name=\"overridescreen\" id=\"overridescreen\" value=\"\"></input>\n";
    print "<input type=hidden name=delconfirmed id=delconfirmed value=\"\"></input>\n";
    print "<input type=hidden name=cloneconfirmed id=cloneconfirmed value=\"\"></input>\n";
    print "<input type=hidden name=xport id=xport value=\"\"></input>\n";
    print "<input type=hidden name=xport_cust id=xport_cust value=\"\"></input>\n";
    print "<input type=hidden name=loadreport id=loadreport value=\"\"></input>\n";
    print "<input type=hidden name=lastloaded id=lastloaded value=\"{$lastloaded}\"></input>\n";
    print "<input type=hidden name=saveviewname id=saveviewname value=\"\"></input>\n";
    print "<input type=hidden name=saveviewoptions id=saveviewoptions value=\"\"></input>\n";
    // setup HTML to receive custom button values -- javascript function sets these based on which button is clicked
    print "<input type=hidden name=caid id=caid value=\"\"></input>\n";
    print "<input type=hidden name=caentries id=caentries value=\"\"></input>\n";
    // hidden fields used by UI in the Entries section
    print "<input type=hidden name=sort id=sort value=\"{$sort}\"></input>\n";
    print "<input type=hidden name=order id=order value=\"{$order}\"></input>\n";
    print "<input type=hidden name=hlist id=hlist value=\"{$hlist}\"></input>\n";
    print "<input type=hidden name=hcalc id=hcalc value=\"{$hcalc}\"></input>\n";
    print "<input type=hidden name=lockcontrols id=lockcontrols value=\"{$lockcontrols}\"></input>\n";
    print "<input type=hidden name=resetview id=resetview value=\"\"></input>\n";
    // hidden fields used by calculations
    print "<input type=hidden name=calc_cols id=calc_cols value=\"{$calc_cols}\"></input>\n";
    print "<input type=hidden name=calc_calcs id=calc_calcs value=\"{$calc_calcs}\"></input>\n";
    print "<input type=hidden name=calc_blanks id=calc_blanks value=\"{$calc_blanks}\"></input>\n";
    print "<input type=hidden name=calc_grouping id=calc_grouping value=\"{$calc_grouping}\"></input>\n";
    // advanced calculations
    print "<input type=hidden name=advcalc_acid id=advcalc_acid value=\"{$advcalc_acid}\"></input>\n";
    // advanced search
    $asearch = str_replace("\"", "&quot;", $asearch);
    print "<input type=hidden name=asearch id=asearch value=\"" . stripslashes($asearch) . "\"></input>\n";
    // advanced scope
    print "<input type=hidden name=advscope id=advscope value=\"\"></input>\n";
    // delete view
    print "<input type=hidden name=delview id=delview value=\"\"></input>\n";
    print "<input type=hidden name=delviewid_formulize id=delviewid_formulize value=\"{$loadedview}\"></input>\n";
    // related to saving a new view
    print "<input type=hidden name=saveid_formulize id=saveid_formulize value=\"\"></input>\n";
    print "<input type=hidden name=savename id=savename value=\"\"></input>\n";
    print "<input type=hidden name=savegroups id=savegroups value=\"\"></input>\n";
    print "<input type=hidden name=savelock id=savelock value=\"\"></input>\n";
    print "<input type=hidden name=savescope id=savescope value=\"\"></input>\n";
    // forcequery value, perpetuates from pageload to pageload
    print "<input type=hidden name=forcequery id=forcequery value=\"" . intval($_POST['forcequery']) . "\"></input>\n";
    // lockedColumns is the list of columns that the user has locked in place...however it is relative to the currently active columns...changing columns while columns are locked may have unexpected results!
    print "<input type=hidden name=formulize_lockedColumns id=formulize_lockedColumns value=\"" . implode(",", $lockedColumns) . "\"></input>\n";
    // scroll x and y are used to retain the scroll position after the page reloads
    print "<input type=hidden name=formulize_scrollx id=formulize_scrollx value=\"\"></input>\n";
    print "<input type=hidden name=formulize_scrolly id=formulize_scrolly value=\"\"></input>\n";
    $useXhr = false;
    if ($screen) {
        if ($screen->getVar('dedisplay')) {
            $useXhr = true;
        }
    }
    interfaceJavascript($fid, $frid, $currentview, $useWorking, $useXhr, $settings['lockedColumns']);
    // must be called after form is drawn, so that the javascript which clears ventry can operate correctly (clearing is necessary to avoid displaying the form after clicking the Back button on the form and then clicking a button or doing an operation that causes a posting of the controls form).
    $returnArray = array();
    $returnArray[0] = $buttonCodeArray;
    // send this back so it's available in the bottom template if necessary.  MUST USE NUMERICAL KEYS FOR list TO WORK ON RECEIVING END.
    return $returnArray;
}