Apache-DnsZone

 view release on metacpan or  search on metacpan

lib/Apache/DnsZone.pm  view on Meta::CPAN

#    # language sensitive help
#
#    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
#    $tpl->define(layout => 'layout.tpl', help => 'help.tpl');
#    $tpl->assign(%lang);
#    $tpl->assign(TITLE => $lang{'PAGE_HELP'});
#    $tpl->assign(DEBUG => '');
#
#    $tpl->assign(HELP => qq{$type});
#    $tpl->parse(HELP => "help");
#
#    $tpl->parse(MAIN => ["help", "layout"]);
#
#    my $content_ref = $tpl->fetch("MAIN");
#
#    output_headers($r, 1, length(${$content_ref}));
#
#    $r->print(${$content_ref});
#
#    $dbh->close();
#    return OK;
#}

sub cancel {
    my $r = shift || Apache->request();
    Debug(3, qq{calling cancel()});
    init($r);
    if (apr()->param('dom_id')) {
	my $dom_id = apr()->param('dom_id');
	($dom_id) = ($dom_id =~ /(\d+)/)[0];
	if ($dom_id =~ /^\d+$/) {
	    output_redirect($r, 1, qq{/admin?action=view&dom_id=$dom_id});
	    $dbh->close();
	    return REDIRECT;
	}
    }
    output_redirect($r, 1, '/admin?action=default');
    $dbh->close();
    return REDIRECT;
}

sub settings {
    my $r = shift || Apache->request();
    Debug(3, qq{calling settings()});
    init($r); 
    my $user = $r->connection->user;

    if (apr()->param('button') && lc(apr()->param('button')) eq lc($lang{'SUBMIT'})) {
        Debug(5, qq{This is an update of settings request});
	my ($uid) = $dbh->get_user_id($user);

	my $all_set = 1;
	my $user_email = apr()->param('user_email');
	if (!($user_email = check_email($user_email))) {
	    $all_set = 0;
	}
	my $lang_id = apr()->param('lang');
	if (!check_lang($lang_id)) {
	    $all_set = 0;
	}
        if (apr()->param('password') && apr()->param('password_confirm')) {
	    if (apr()->param('password') ne apr()->param('password_confirm')) {
		$all_set = 0;
	    } 
	}
	if ((apr()->param('password') && !apr()->param('password_confirm')) || (!apr()->param('password') && apr()->param('password_confirm'))) {
	    $all_set = 0;
	}
	if ($all_set) {
	    # update email and language
	    Debug(5, qq{Updating email and language settings});
	    $dbh->set_user_lang_email($uid, $lang_id, $user_email);
	    if (apr()->param('password') && apr()->param('password') ne '' && apr()->param('password_confirm') && apr()->param('password_confirm') ne '' && apr()->param('password') eq apr()->param('password_confirm')) {
	        Debug(5, qq{Updating password});
		$dbh->set_user_password($uid, apr()->param('password'));
	    }
	} else {
	    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
	    $tpl->define(layout => 'layout.tpl', settings => 'settings.tpl', menu => 'menu.tpl');
	    $tpl->assign(%lang);
	    $tpl->assign(TITLE => $lang{'PAGE_SETTINGS'});
	    $tpl->assign(DEBUG => '');
	    
	    if ($dbh->get_domain_count($uid) == 1) {
		$tpl->assign(ADDITIONAL_MENU => '');
	    } else {
		$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
	    }

	    $tpl->assign(LANG_VALUE => $dbh->lang_select_box($uid, $lang_id));
	    $tpl->assign(EMAIL_VALUE => encode_entities(apr()->param('user_email')));
	    
	    $tpl->assign(NEW_PASSWORD_VALUE => encode_entities(apr()->param('password')));
	    $tpl->assign(CONFIRM_PASSWORD_VALUE => encode_entities(apr()->param('password_confirm')));
	    
	    if (!($user_email = check_email($user_email))) {
		$tpl->assign(EMAIL => qq{<font color="red">} . $lang{EMAIL} . qq{</font>});
	    }
	    if (!check_lang($lang_id)) {
		$tpl->assign(LANGUAGE => qq{<font color="red">} . $lang{LANGUAGE} . qq{</font>});
	    }
	    if (apr()->param('password') && apr()->param('password') ne '' && apr()->param('password_confirm') && apr()->param('password_confirm') ne '') {
		if (!(apr()->param('password') eq apr()->param('confirm_password'))) {
		    $tpl->assign(NEW_PASSWORD => qq{<font color="red">} . $lang{NEW_PASSWORD} . qq{</font>});
		    $tpl->assign(CONFIRM_PASSWORD => qq{<font color="red">} . $lang{CONFIRM_PASSWORD} . qq{</font>});
		}
	    }
	    if ((apr()->param('password') && !apr()->param('password_confirm')) || (!apr()->param('password') && apr()->param('password_confirm'))) {
		    $tpl->assign(NEW_PASSWORD => qq{<font color="red">} . $lang{NEW_PASSWORD} . qq{</font>});
		    $tpl->assign(CONFIRM_PASSWORD => qq{<font color="red">} . $lang{CONFIRM_PASSWORD} . qq{</font>});
	    }

	    $tpl->parse(MENU => "menu");
	    $tpl->parse(MAIN => ["settings", "layout"]);
	    
	    my $content_ref = $tpl->fetch("MAIN");  
	    
	    output_headers($r, 1, length(${$content_ref}));
	  
	    $r->print(${$content_ref});
    
            $dbh->close();
	    return OK;
	}

        output_redirect($r, 1, '/admin?action=default');

	$dbh->close();
	return REDIRECT;
    } else {
        Debug(5, qq{This is a view of settings request});
	my ($uid, $user_email, $lang_id, $lang) = $dbh->get_user_info($user);

        my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
        $tpl->define(layout => 'layout.tpl', settings => 'settings.tpl', menu => 'menu.tpl');
        $tpl->assign(%lang);
        $tpl->assign(TITLE => $lang{'PAGE_SETTINGS'});
        $tpl->assign(DEBUG => '');
        $tpl->assign(LANG_VALUE => $dbh->lang_select_box($uid, $lang_id));
        $tpl->assign(EMAIL_VALUE => $user_email);

        if ($dbh->get_domain_count($uid) == 1) {
	    $tpl->assign(ADDITIONAL_MENU => '');
	} else {
	    $tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
	}
	  
        $tpl->assign(NEW_PASSWORD_VALUE => '');
	$tpl->assign(CONFIRM_PASSWORD_VALUE => '');

        $tpl->parse(MENU => "menu");
	$tpl->parse(MAIN => ["settings", "layout"]);

	my $content_ref = $tpl->fetch("MAIN");  

        output_headers($r, 1, length(${$content_ref}));

        $r->print(${$content_ref});

	$dbh->close();
	return OK;
    }
}

sub delete_record {
    my $r = shift || Apache->request();
    Debug(3, qq{calling delete_record()});
    init($r);



( run in 0.983 second using v1.01-cache-2.11-cpan-5a3173703d6 )