示例#1
0
     $mail = phamm_set_var('mail');
 } else {
     $mail = $_SESSION["login"]["username"];
 }
 if ($_SESSION["login"]["level"] > 4) {
     $domain = phamm_set_var('domain');
 } else {
     $domain = $_SESSION["phamm"]["domain"];
 }
 // Create domain object
 if (isset($domain) && !empty($domain)) {
     $domain_obj = new PhammLdap();
     $domain_val = $domain_obj->phamm_self_values('vd=' . $domain . ',' . LDAP_BASE, $filter = "(vd={$domain})");
     $myObjectClass = isset($pv[$pn]["ACCOUNT"]["OBJECTCLASSES"]) ? key($pv[$pn]["ACCOUNT"]["OBJECTCLASSES"]) : 'virtualMailAccount';
     $accounts_obj = new PhammLdap();
     $accounts_val = $accounts_obj->phamm_search('vd=' . $domain . ',' . LDAP_BASE, '(&(objectClass=' . $myObjectClass . ')(!(cn=postmaster))(!(mail=abuse@*)))');
 }
 // Overwrite action for user login
 if (!in_array($action, array('update_account')) && $_SESSION["login"]["level"] == 2) {
     $action = 'modify_account';
 } elseif (!in_array($action, array('add_account', 'insert_account', 'modify_account', 'update_account', 'domain_property', 'catch_all', 'group_actions')) && $_SESSION["login"]["level"] == 4) {
     $action = 'domain_view';
 }
 // Link to logount and language select
 phamm_print_xhtml('<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">');
 phamm_print_xhtml('<ul class="nav navbar-nav">');
 phamm_print_xhtml("<li><a href=\"?exit=1\">");
 printf(_("Logout %s"), $_SESSION["login"]["username"]);
 phamm_print_xhtml('</a></li>');
 phamm_print_xhtml('</ul>');
 phamm_print_xhtml('<ul class="nav navbar-form navbar-right">');
示例#2
0
/**
* Create a XHTML form for plugin attribute
*
* @author Alessandro De Zorzi <*****@*****.**>
*
* @param string $p_name The plugin name
* @param array $attributes The attributes
* @return mixed
**/
function form_template($p_name, $attributes, $myvalues, $skip_table = null)
{
    global $action;
    global $minAuthLevel;
    global $domain;
    $dn_domain = 'vd=' . $domain . ',' . LDAP_BASE;
    $domain_values = PhammLdap::phamm_self_values($dn_domain, $filter = "(objectClass=*)");
    $tag = '';
    if (!isset($skip_table)) {
        $tag .= '<table class="">';
    }
    if (is_array($attributes)) {
        foreach ($attributes as $key => $attr) {
            if (!isset($hidden)) {
                $tag .= '<tr><td>';
            }
            // Set attributes
            $name = strtolower($key);
            $hidden = isset($attr["HIDDEN"]) ? 'type="hidden"' : null;
            $minAuthLevel = isset($attr["MINAUTHLEVEL"]) ? $attr["MINAUTHLEVEL"] : 0;
            $size = isset($attr["SIZE"]) && !isset($attr["HIDDEN"]) ? 'size="' . $attr["SIZE"] . '"' : null;
            $disabled = isset($attr["DISABLED"]) ? 'disabled="disabled"' : null;
            $maxlength = isset($attr["MAXLENGHT"]) ? strtolower($attr["MAXLENGTH"]) : null;
            $subordinated = isset($attr["SUBORDINATED"]) ? strtoupper($attr["SUBORDINATED"]) : null;
            $subordinatedreverse = isset($attr["SUBORDINATEDREVERSE"]) ? strtoupper($attr["SUBORDINATEDREVERSE"]) : null;
            $max_key = strtolower('max' . $key);
            if (isset($domain_values[0][$max_key][0])) {
                // Disable value is possible only from TRUE to FALSE
                if (isset($myvalues[0][$name][0]) || $myvalues[0][$name][0] == 'FALSE') {
                    $max_val = $domain_values[0][$max_key][0];
                    // For Bool attrbute only check the sum of total account with attribute set TRUE
                    if ($attr["BOOL"] == 1) {
                        $active_val = PhammLdap::phamm_self_values($dn_domain, '(&(objectClass=*)(' . $key . '=TRUE))');
                        $current_val_count = $active_val["count"];
                    } else {
                        $active_val = PhammLdap::phamm_search('vd=' . $domain . ',' . LDAP_BASE, '(&(objectClass=VirtualMailAccount))', array($key));
                        $total_key = 0;
                        foreach ($active_val as $one_val) {
                            if ($one_val[$key][0]) {
                                $total_key = $total_key + $one_val[$key][0];
                            }
                        }
                        // @todo
                        if ('quota' == $key) {
                            $total_key = $total_key / 1024 / 1024 - $active_val['count'] * 2000;
                        }
                        $current_val_count = $total_key;
                    }
                    if ($current_val_count >= $max_val) {
                        phamm_print_message('info', sprintf(_("The maximum number of attribute %s (%s) has been reached or exceeded. Attribute has been disabled!"), $key, $max_val));
                        $disabled = 'disabled="disabled"';
                    }
                }
            }
            // Set XHTML Tags
            $required = isset($attr["REQUIRED"]) ? ' *' : null;
            // Set Default value
            $value = '';
            // Set standard value
            if (isset($myvalues[$p_name][$name])) {
                $value = $myvalues[$p_name][$name];
            } elseif (isset($myvalues[0][$name][0])) {
                // If attr is multiple
                if (isset($attr["MULTIPLE"])) {
                    $value = $myvalues[0][$name];
                } else {
                    $value = $myvalues[0][$name][0];
                }
            }
            // Multiplier (Ex. Quota x 1024)
            if (isset($attr["MULTIPLIER"]) && in_array($action, array('modify_account', 'domain_property'))) {
                $value = $value / $attr["MULTIPLIER"];
            } elseif (isset($attr["DEFAULT"]) && ($action == 'add_account' || $action == 'add_domain')) {
                if (preg_match('/^=php\\.(\\w+)\\((.*)\\)$/', $attr["DEFAULT"], $matches)) {
                    $args = preg_split('/,/', $matches[2]);
                    $function_name = $matches[1];
                    switch ($function_name) {
                        case "Value":
                            foreach ($args as $arg) {
                                // Global vars
                                if (preg_match('/^%(\\w+)(\\|.+)?(\\/[lU])?%/U', $arg, $matches)) {
                                    $var_name = $matches[1];
                                    global ${$var_name};
                                    $value .= ${$var_name};
                                } elseif (preg_match('/^\\+(\\w+)(\\|.+)?(\\/[lU])?\\+/U', $arg, $matches)) {
                                    $var_name = $matches[1];
                                    $value .= $_POST[$var_name];
                                } else {
                                    $value .= $arg;
                                }
                            }
                            break;
                            // Call PHP Function
                        // Call PHP Function
                        default:
                            if (function_exists($function_name)) {
                                // Escape a string to be used as a shell argument
                                foreach ($args as $arg) {
                                    $args_escaped = escapeshellarg($arg);
                                }
                                $value = call_user_func_array($function_name, $args_escaped);
                            }
                            break;
                    }
                } else {
                    $value = $attr["DEFAULT"];
                }
            }
            // Hide values if SUBORDINATED to another
            if (isset($attr["SUBORDINATED"])) {
                if (isset($myvalues[0][strtolower($subordinated)][0])) {
                    $hidden = $myvalues[0][strtolower($subordinated)][0] == "TRUE" ? null : 1;
                } elseif (isset($myvalues[$p_name][strtolower($subordinated)])) {
                    $hidden = $myvalues[$p_name][strtolower($subordinated)] == "TRUE" ? null : 1;
                } else {
                    $hidden = 1;
                }
            }
            if (isset($attr["SUBORDINATEDREVERSE"])) {
                if (isset($myvalues[0][strtolower($subordinatedreverse)][0])) {
                    $hidden = $myvalues[0][strtolower($subordinatedreverse)][0] == "FALSE" ? null : 1;
                } elseif (isset($myvalues[$p_name][strtolower($subordinatedreverse)])) {
                    $hidden = $myvalues[$p_name][strtolower($subordinatedreverse)] == "FALSE" ? null : 1;
                } else {
                    $hidden = 1;
                }
            }
            if (!isset($hidden)) {
                $label = isset($attr["PRETTYNAME"]) ? $attr["PRETTYNAME"] : $key;
                $tag .= gettext($label);
                $tag .= $required;
                $tag .= "</td><td>";
            }
            if (isset($attr["BOOL"]) && !isset($hidden)) {
                $reverse = isset($attr["REVERSE"]) ? 1 : null;
                $tag .= trueorfalse("values[" . $p_name . "]", $value, $name, $reverse, $disabled);
            } elseif (isset($attr["OPTIONS"]) && !isset($hidden)) {
                if ($_SESSION["login"]["level"] < $minAuthLevel) {
                    $tag .= $value;
                } else {
                    $tag .= '<select class="form-control" name="values[' . $p_name . '][' . $name . ']">';
                    foreach ($attr["OPTIONS"] as $k => $v) {
                        $label = isset($attr["PRETTYNAME"]) ? $attr["PRETTYNAME"] : $k;
                        $label = $k;
                        $selected = $value == $v["VALUE"] ? 'selected="selected"' : '';
                        $tag .= '<option value="' . $v["VALUE"] . '" ' . $selected . '>' . $label . ' (' . $v["VALUE"] . ')</option>' . "\n";
                    }
                    $tag .= '</select>' . "\n\n";
                }
            } elseif (isset($attr["DATE"]) && !isset($hidden)) {
                $current_date = $value ? $value : date('Y' . '-' . 'm' . '-' . 'd');
                if ($_SESSION["login"]["level"] < $minAuthLevel) {
                    $tag .= $value;
                } else {
                    $tag .= date_input('values_date[' . $p_name . '][' . $name . ']', $current_date, $format = 'ymd');
                }
            } elseif (isset($attr["TEXTAREA"]) && !isset($hidden)) {
                if ($_SESSION["login"]["level"] < $minAuthLevel) {
                    $tag .= nl2br($value);
                } else {
                    // Show box to add multiple values
                    $tag .= '<textarea name="values[' . $p_name . '][' . $name . ']" cols="35" rows="5">';
                    $tag .= stripslashes($value);
                    $tag .= "</textarea><br/>";
                }
            } elseif (isset($attr["MULTIPLE"]) && !isset($hidden)) {
                // Show box to add multiple values
                $tag .= '<textarea name="values_multi[' . $p_name . '][' . $name . ']" cols="35" rows="5">';
                if (isset($attr["TEXTAREA"])) {
                    $tag .= stripslashes($value);
                }
                $tag .= "</textarea><br/>";
                // Show the values
                if (is_array($value)) {
                    for ($i = 0; $i < $value["count"]; $i++) {
                        $tag .= '<input type="checkbox" name="values_multi_del[' . $p_name . '][' . $name . '][]" value="' . $value[$i] . '" />';
                        $tag .= $value[$i] . "<br/>";
                    }
                }
            } elseif (isset($attr["SUBORDINATEDDELETE"]) && $value) {
                $tag .= '<input type="checkbox" name="values_multi_del[' . $p_name . '][' . $name . ']" value="' . $value . '" id="subordinatedelete" />';
                $tag .= $value . "<br/>";
            } else {
                if (isset($hidden)) {
                    $input_type = 'hidden';
                } else {
                    $input_type = 'text';
                }
                // Show Value Only if auth level > level required
                if ($_SESSION["login"]["level"] >= $minAuthLevel) {
                    $tag .= '<input type="' . $input_type . '" class="form-control" value="' . $value . '" name="values[' . $p_name . '][' . $name . ']" ' . $size . ' ' . $disabled . ' />';
                } elseif (!isset($hidden)) {
                    $tag .= $value;
                }
            }
            if (!isset($hidden)) {
                $tag .= "</td></tr>";
            }
        }
    }
    // Exception, if last array attribute is hidden
    // XHTML Syntax required to close a TR
    if (isset($hidden)) {
        $tag .= "</td><td></td></tr>";
    }
    if (!isset($skip_table)) {
        $tag .= "</table>";
    }
    return $tag;
}
示例#3
0
/**
*
**/
function accounts_list($domain, $values, $initial, $domain_val)
{
    global $pn;
    global $pv;
    global $action;
    // Rapresentative ObjectClass
    $myObjectClass = isset($pv[$pn]["ACCOUNT"]["OBJECTCLASSES"]) ? key($pv[$pn]["ACCOUNT"]["OBJECTCLASSES"]) : 'virtualMailAccount';
    if (isset($initial)) {
        $account_array = PhammLdap::phamm_search('vd=' . $domain . ',' . LDAP_BASE, '(&(objectClass=' . $myObjectClass . ')(!(cn=postmaster))(!(mail=abuse@*))(mail=' . $initial . '*))');
    } else {
        $account_array = PhammLdap::phamm_search('vd=' . $domain . ',' . LDAP_BASE, '(&(objectClass=' . $myObjectClass . ')(!(cn=postmaster))(!(mail=abuse@*)))');
    }
    $max_account = $pn == 'alias' ? $domain_val[0]["maxalias"][0] : $domain_val[0]["maxmail"][0];
    $tag = '<form method="post" action="' . $_SERVER["PHP_SELF"] . '" name="accounts" id="post-checks">';
    $tag .= '<table class="table table-striped">';
    $tag .= '<thead>';
    $tag .= '<tr>';
    $tag .= '<th><input type="checkbox" name="all" onclick="checkAll();" /></th>';
    $tag .= '<th>';
    if (isset($max_account)) {
        $tag .= sprintf(ngettext("Account <span class=\"badge\">%d/" . $max_account . "</span>", "Accounts <span class=\"badge\">%d/" . $max_account . "</span>", $account_array["count"]), $account_array["count"]);
    } else {
        $tag .= sprintf(ngettext("Account <span class=\"badge\">%d</span>", "Accounts <span class=\"badge\">%d</span>", $account_array["count"]), $account_array["count"]);
    }
    $tag .= '</th>' . "\n";
    $tag .= '<th>' . _("Common Name") . '</th>' . "\n";
    if (count($values) > 0) {
        foreach ($values["ATTRIBUTES"] as $key => $value) {
            if (isset($values["ATTRIBUTES"][$key]["TABLE"])) {
                $label = isset($values["ATTRIBUTES"][$key]["PRETTYNAME"]) ? $values["ATTRIBUTES"][$key]["PRETTYNAME"] : $key;
                $tag .= '<th>' . gettext($label) . '</th>' . "\n";
            }
        }
    }
    $tag .= '</tr>';
    $tag .= '</thead>';
    $tag .= '<tbody>';
    foreach ($account_array as $account) {
        $mail = $account["mail"][0];
        if (isset($mail)) {
            $tag .= '<tr class="data">';
            // Group action checkbox
            $tag .= '<td><input type="checkbox" name="accounts[' . $mail . ']" value="1" /></td>';
            // Account name and link
            $tag .= '<td><a href="?action=modify_account&amp;mail=' . $mail . '" class="inside">';
            $tag .= $mail;
            $tag .= '</a></td>';
            $tag .= '<td>' . stripslashes($account["cn"][0]) . '</td>';
            // Other attributes (current plugin)
            if (isset($values["ATTRIBUTES"])) {
                foreach ($values["ATTRIBUTES"] as $key => $value) {
                    $reverse = isset($values["ATTRIBUTES"][$key]["REVERSE"]) ? 1 : null;
                    $cron = isset($values["ATTRIBUTES"][$key]["CRON"]) ? 1 : null;
                    if (isset($values["ATTRIBUTES"][$key]["TABLE"])) {
                        $key_lower = strtolower($key);
                        $tag .= '<td>';
                        if (isset($account[$key_lower][0])) {
                            $val = $account[$key_lower][0];
                            $rev = $val == 'TRUE' ? 'FALSE' : 'TRUE';
                            if (isset($values["ATTRIBUTES"][$key]["TABLENOEDIT"])) {
                                $tag .= $val;
                            } elseif (isset($values["ATTRIBUTES"][$key]["BOOL"])) {
                                $tag .= tof_icon('accounts[' . $mail . ']', $val, 'group_actions&amp;command=account;' . $key . ';' . $rev, $reverse, $cron);
                            } else {
                                if (isset($value["MULTIPLIER"]) && in_array($action, array('modify_account', 'domain_property', 'domain_view'))) {
                                    $tag .= $account[$key_lower][0] / $value["MULTIPLIER"];
                                } else {
                                    $tag .= $val;
                                }
                            }
                        }
                        $tag .= '</td>' . "\n";
                    }
                }
            }
            $tag .= '</tr>' . "\n";
        }
    }
    $tag .= '</tbody>';
    $tag .= '</table>';
    return $tag;
}