Ejemplo n.º 1
0
 function _adminPage_UpdateLinkType($group_id, $link_type_id)
 {
     global $HTML, $Language;
     if (isset($link_type_id)) {
         $db_res = db_query("SELECT link_type_id, group_id, name,\n                reverse_name, description, uri_plus\n                FROM plugin_projectlinks_link_type\n                WHERE ((group_id = " . db_ei($group_id) . ")\n                    AND (link_type_id = " . db_ei($link_type_id) . "));");
         if (db_numrows($db_res) != 1) {
             exit_error("invalid data", "2.2");
             // unexpected - no i18l
         }
         $row = db_fetch_array($db_res);
         $def = array('name' => htmlentities($row['name']), 'reverse_name' => htmlentities($row['reverse_name']), 'description' => htmlentities($row['description']), 'uri_plus' => htmlentities($row['uri_plus']));
     } else {
         $def = array('name' => "", 'reverse_name' => "", 'description' => "", 'uri_plus' => '/projects/$projname/');
     }
     $HTML->box1_top($Language->getText('plugin_plinks', 'project_links') . " " . $this->_icon('main') . " " . $Language->getText('plugin_plinks', 'link_type_update'));
     print mkAH("[" . $Language->getText('global', 'btn_cancel') . "]", $this->_adminURI() . "?group_id={$group_id}");
     print "<hr>\n";
     print "<table><tr><td>\n";
     $HTML->box1_top("");
     form_Start("");
     form_HiddenParams(array("func" => 'pl_type_update', "group_id" => $group_id));
     if (isset($link_type_id)) {
         form_HiddenParams(array("link_type_id" => $link_type_id));
     }
     form_GenTextBox("name", htmlentities($Language->getText('plugin_plinks', 'dbfn_name')), $def['name'], 20);
     form_Validation("name", FORM_VAL_IS_NOT_ZERO_LENGTH);
     form_NewRow();
     form_GenTextBox("reverse_name", htmlentities($Language->getText('plugin_plinks', 'dbfn_reverse_name')), $def['reverse_name'], 20);
     form_NewRow();
     form_GenTextArea("description", htmlentities($Language->getText('plugin_plinks', 'dbfn_description')), $def['description']);
     /** **1 commented out for now - until we can decide how to deal with project links functionality
         form_NewRow();
         form_GenTextBox("uri_plus",
         htmlentities($Language->getText('plugin_plinks', 'dbfn_uri_plus')),
         $def['uri_plus'], 85);
         form_Validation("uri_plus", FORM_VAL_IS_NOT_ZERO_LENGTH);
         **/
     foreach (array("uri_plus", "name", "reverse_name", "description") as $ref) {
         $formRefs[$ref] = form_JS_ElementRef($ref) . ".value";
     }
     form_End();
     $HTML->box1_bottom();
     print "</td><td>\n";
     $HTML->box1_top($Language->getText('plugin_plinks', 'set_to_defaults'));
     print "<div style='padding: 5px; border: solid thin;\n            vertical-align: middle;'>";
     print $Language->getText('plugin_plinks', 'replace_form_details') . ":<p>";
     form_genJSButton($Language->getText('plugin_plinks', 'def_sp_name'), "if (confirm('" . $Language->getText('plugin_plinks', 'replace_form_details') . "?')){" . $formRefs["name"] . "='" . $Language->getText('plugin_plinks', 'def_sp_name') . "';" . $formRefs["reverse_name"] . "='" . $Language->getText('plugin_plinks', 'def_sp_rname') . "';" . $formRefs["description"] . "='" . $Language->getText('plugin_plinks', 'def_sp_desc') . "';" . "}");
     print "<p>";
     form_genJSButton($Language->getText('plugin_plinks', 'def_rp_name'), "if (confirm('" . $Language->getText('plugin_plinks', 'replace_form_details') . "?')){" . $formRefs["name"] . "='" . $Language->getText('plugin_plinks', 'def_rp_name') . "';" . $formRefs["reverse_name"] . "='" . $Language->getText('plugin_plinks', 'def_rp_rname') . "';" . $formRefs["description"] . "='" . $Language->getText('plugin_plinks', 'def_rp_desc') . "';" . "}");
     print "</div><p>";
     /** **1 commented out for now - until we can decide how to deal with project links functionality
         print "<div style='padding: 5px; border: solid thin;
         vertical-align: middle;'>";
         form_genJSButton($Language->getText('plugin_plinks', 'def_link_summary'),
         $formRefs["uri_plus"]."='/projects/\$projname/';");
         print "<p>";
         form_genJSButton($Language->getText('plugin_plinks', 'def_link_doc'),
         $formRefs["uri_plus"]."='/plugins/docman/?group_id=\$group_id';"
         );
         print "</div>";
         **/
     $HTML->box1_bottom();
     print "</td></tr></table>\n";
     if (isset($link_type_id)) {
         // Display list of linked projects
         $HTML->box1_top('Projects linked');
         print $this->_admin_links_table($link_type_id);
         // Admin can add new link
         print '<form name="plugin_projectlinks_add_link" method="post" action="?func=pl_link_update">';
         print '<input type="hidden" name="link_type_id" value="' . $link_type_id . '" />';
         print '<input type="hidden" name="group_id" value="' . $group_id . '" />';
         print '<input type="hidden" name="disp" value="edit_link_type" />';
         print '<p><label for="plugin_projectlinks_link_project">' . $GLOBALS['Language']->getText('plugin_plinks', 'add_project') . '</label>';
         print '<input type="text" name="target_group" value="' . $GLOBALS['Language']->getText('plugin_plinks', 'add_project_autocompleter') . '" size="60" id="plugin_projectlinks_link_project" /></p>';
         print '<input type="submit" value="' . $GLOBALS['Language']->getText('global', 'btn_create') . '" />';
         print '</form>';
         $HTML->box1_bottom();
         $HTML->includeFooterJavascriptSnippet("new ProjectAutoCompleter('plugin_projectlinks_link_project', '" . util_get_dir_image_theme() . "', false);");
     }
     $HTML->box1_bottom();
 }
Ejemplo n.º 2
0
function form_End($SubmitLegend = DEFAULT_SUBMIT_BUTTON, $HaveResetButton = FORM_HAVE_RESET_BUTTON)
{
    global $gInForm, $gFormName, $gFormUsedDateBox, $gFormHiddenParams, $gValidationCollection, $gFormSectionLevel, $gFormGroupLevel, $gPageDateCodeWritten, $gFormCaptions, $Language;
    if (!$gInForm) {
        trigger_error("Nested forms - form_End() outside of form");
    }
    if ($gFormSectionLevel < 0) {
        trigger_error("Unbalanced form_SectionStart/End()");
    }
    if ($gFormGroupLevel < 0) {
        trigger_error("Unbalanced form_GroupStart/End()");
    }
    if (is_null($SubmitLegend)) {
        // passing an empty string is different from defaulting to standard button
        $SubmitLegend = $Language->getText('global', 'btn_update');
    }
    if (strlen($SubmitLegend) > 0 || $HaveResetButton) {
        form_NewRow();
        if (strlen($SubmitLegend) > 0) {
            form_genSubmit($SubmitLegend);
        }
        if ($HaveResetButton) {
            print "<td><INPUT TYPE='reset' Value='" . $Language->getText('form_utils', 'Cancel_Changes') . "'></td>\n";
        }
    }
    while ($gFormGroupLevel > 0) {
        form_GroupEnd();
    }
    while ($gFormSectionLevel > 0) {
        form_SectionEnd();
    }
    form_TableEnd();
    // place them here to avoid silly form formatting problem when a table is used
    foreach ($gFormHiddenParams as $key => $value) {
        print "<INPUT TYPE='hidden' NAME='{$key}' VALUE='{$value}'>\n";
    }
    print "</form>\n";
    // write date code if needed, but only once
    if ($gFormUsedDateBox && !$gPageDateCodeWritten) {
        print "<script type='text/javascript' language='javascript' src='/scripts/datechooser.js'></script>\n";
        $gPageDateCodeWritten = True;
    }
    // Write form validation code
    print "<script type='text/javascript' language='javascript'>\n";
    print "<!--\n";
    print "function Validate" . $gFormName . "()\n";
    print "{\n";
    print "var result = true;\n";
    $EmitEmailCode = False;
    $EmitNumberCode = False;
    foreach ($gValidationCollection as $valItemKey => $valItem) {
        if (!isset($gFormCaptions[$valItem->ParamName])) {
            trigger_error("Validation item '" . $valItem->ParamName . "' is not a form item ({$valItemKey} => {$valItem})");
        }
        $jsItemRef = form_JS_ElementRef($valItem->ParamName) . ".value";
        $jsItemErrStart = "{result=false;alert('" . addslashes($gFormCaptions[$valItem->ParamName]) . ": ";
        $jsItemErrEnd = "');}\n";
        $jsItemPresent = "if ({$jsItemRef} == '')" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be_completed') . $jsItemErrEnd;
        $jsItemNumeric = "if (!isNumber({$jsItemRef}))" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be_a_number') . $jsItemErrEnd;
        switch ($valItem->Test) {
            case FORM_VAL_IS_NOT_ZERO_LENGTH:
                print $jsItemPresent;
                break;
            case FORM_VAL_IS_EMAIL:
                $EmitEmailCode = True;
                print $jsItemPresent;
                print "else if (!isEmailAddr({$jsItemRef}))" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be_a_valid_email_address') . $jsItemErrEnd;
                break;
            case FORM_VAL_IS_NUMBER:
                $EmitNumberCode = True;
                print $jsItemPresent . " else " . $jsItemNumeric;
                break;
            case FORM_VAL_IS_LT:
                $EmitNumberCode = True;
                print $jsItemPresent . " else " . $jsItemNumeric . " else if ({$jsItemRef}>=" . $valItem->Param . ")" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be_less_than', $valItem->Param) . $jsItemErrEnd;
                break;
            case FORM_VAL_IS_GT:
                $EmitNumberCode = True;
                print $jsItemPresent . " else " . $jsItemNumeric . " else if ({$jsItemRef}<=" . $valItem->Param . ")" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be_greater_than', $valItem->Param) . $jsItemErrEnd;
                break;
            case FORM_VAL_IS_EQ:
                $cmp = is_string($valItem->Param) ? "'" . $valItem->Param . "'" : $valItem->Param;
                print "if ({$jsItemRef}!={$cmp})" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be', $valItem->Param) . $jsItemErrEnd;
                break;
            case FORM_VAL_IS_CHECKED:
                print "if (!" . form_JS_ElementRef($valItem->ParamName) . ".checked)" . $jsItemErrStart . $Language->getText('form_utils_error', 'must_be_checked') . $jsItemErrEnd;
                break;
            default:
                trigger_error("Can't handle requested validation: " . $valItem->ParamName . " (" . $valItem->Test . ")");
                break;
        }
    }
    print "return result;\n";
    print "}\n";
    if ($EmitEmailCode) {
        print "function isEmailAddr(str)\n";
        print "{\n";
        print "    return str.match(/^[\\w-]+(\\.[\\w-]+)*@([\\w-]+\\.)+[a-zA-Z]{2,7}\$/);\n";
        print "}\n";
    }
    if ($EmitNumberCode) {
        print "function isNumber(str)\n";
        print "{\n";
        print "    return str.match(/^[+-]?[0-9]+[\\.]?[0-9]*\$/);\n";
        print "}\n";
    }
    print "//-->\n";
    print "</script>\n";
    $gInForm = False;
}