fn conf_enable_cssedit {
    enable_cssedit=yes
    cssedit_editors_groups=$*
    conf_enable_app cssedit
    css_file='_werc/style.css'  # Default location, can be changed
}

fn cssedit_init {
    if(! ~ $#enable_cssedit 0 && check_user $cssedit_editors_groups) {
        lp=$local_path
        lp=`{echo $lp | sed 's/index$//'}
        cssedit_file=$"lp$"css_file

        if(~ 1 $#post_arg_cssedit_edit $#post_arg_cssedit_preview) {
            handler_body_main=(tpl_handler `{get_lib_file cssedit/edit.tpl apps/cssedit/edit.tpl})
        }

        if not if(! ~ '' $"post_arg_cssedit_save $"post_arg_css_text) {
            save_css
        }
        
        if not if(~ $"handler_body_main  '' || {~ $REQUEST_METHOD GET && test -f $cssedit_file}) {
            ll_add handlers_bar_left tpl_handler apps/cssedit/sidebar_controls.tpl
        }
    }
}

fn save_css {
    umask 002
    echo $post_arg_css_text > $cssedit_file
    post_redirect $base_url^$req_path
}

