Aide pour message d'erreur sur aMember

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Aide pour message d'erreur sur aMember

Re: Aide pour message d'erreur sur aMember

par Damien34 » 12 oct. 2011, 17:53

En mettant "==" j'ai :
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php
WARNING: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in line 243 of file setup.php

Voici le fichier setup.php complet :
require "../config.inc.php";
$t = new_smarty();
require "login.inc.php";

$_default_notebook = 'Global';
$_notebooks = array();
$_config_fields = array();

function config_set_notebook_comment($nb, $comment){
    global $_notebooks;
    $_notebooks[$nb]['comment'] = $comment;
}
function config_set_readme($nb, $readme){
    global $_notebooks;
    $_notebooks[$nb]['readme'] = $readme;
}
function add_config_field($name, $title,
    $type, $desc, $nb,
    $validate_func='',
    $get_func='', $set_func='',
    $params=''){
    global $_notebooks, $_config_fields;
    
    if (isset($_config_fields[$name])){
        
        //echo "Warning: config field '$name' added more than once!";
        //
        // Move field with same name to bottom
        //
        // Add new notebook name
        $notebooks = $_config_fields[$name]['notebook'];
        if (!is_array($notebooks)) $notebooks = array($notebooks);
        if (!in_array($nb, $notebooks)){
            $_config_fields[$name]['notebook'][] = $nb;
        
            // Store old notebook values, unset and add it again
            $store = $_config_fields[$name];
            unset ($_config_fields[$name]);
            $_config_fields[$name] = $store;
        }
        
    } else {
        
        $_config_fields[$name] = array(
            'name'  => $name,
            'title' => $title,
            'type'  => $type,
            'desc'  => $desc,
            'notebook' => array($nb),
            'validate_func' => $validate_func,
            'get_func'      => $get_func,
            'set_func'      => $set_func,
            'params'        => $params
        );
        
    }
    return 1;
}
function show_config_edit_field(&$field, &$vars){
    $fname = $field['name'];
    $val   = $vars[$fname];
    if ($func = $field['get_func']){
        $field['edit'] = $func($field, $vars);
        $field['special_edit']++;
        return;
    }
    switch ($ftype = $field['type']){
        case 'text': 
        case 'integer':
            if ($ftype == 'integer'){
                $size=5;
            } else {
                $size=30;
                if ($field['params']['size']) $size = $field['params']['size'];
            }
            if (!strlen($val)) $val = $field['params']['default'];
            $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); 
            $field['edit'] = "
             <input type=text name=\"$fname\" 
                value=\"$val\" size=$size maxlength=255>
             ";
        break;
        case 'dbprefix': 
            $r = split('\.', $field['name']);
            $field['edit'] = "";
            if (!strlen($val)) $val = $field['params']['default'];
            $val = htmlspecialchars($val, ENT_QUOTES); 
            $hideDbText = '';
            if ($r[0] == 'protect' && $r[1] && class_exists($class='protect_'.$r[1])){
                $obj = & new $class(amConfig('protect.'.$r[1]));
                $options = "";
                foreach ($dbs = $obj->guess_db_settings() as $s){
                    $sel = ($val == $s)  ? 'selected' : '';
                    if ($val == $s) $hideDbText = true;
                    $options .= "<option $sel>" . htmlentities($s) . "</option>\n";
                }
                $user = amConfig('db.mysql.user');
                $field['edit'] = <<<CUT
<b>Auto-detected values for the field:</b><br />
<small>if there are no choices, it means that your third-party<br />
script database is unaccessible with aMember MySQL settings. You<br />
can fix it by going to Webhosting Control Panel -> MySQL Databases<br />
and allowing access to your third-party script table for aMember's <br />
Mysql user (<b>$user</b>), or your can specify MySQL database user,<br /> 
hostname and password on this page specially for use with <br />
the integration plugin and press <b>Save</b> button to see new choices.<br />
</small>
<select id='s_db' name="$fname" onchange="this.selectedIndex ? \$('#f_db').hide().attr('disabled', 1) : \$('#f_db').show().attr('disabled', 0)">
<option value=''>** Use Text Field **</option>
$options
</select>
<br /><br />
CUT;
            }
            if ($hideDbText)
                $hideDbText = 'style="display: none;" disabled="disabled"';
            $field['edit'] .= "
             <input type=text name=\"$fname\" id='f_db' $hideDbText
                value=\"$val\" size=$size maxlength=255>
             ";
        break;
        case 'color': 
            if ($ftype == 'integer'){
                $size=5;
            } 
            if (!strlen($val)) $val = $field['params']['default'];
            $val = htmlspecialchars($val, ENT_QUOTES); 
            $field['edit'] = "
             <input type=text name=\"$fname\" style='behavior: url(ColorPick.htc)'
                value=\"$val\" size=$size maxlength=255
                onchange=\"document.getElementById('$fname'+'span').style.background=this.value\"
                onkeyup=\"document.getElementById('$fname'+'span').style.background=this.value\"
                >
                &nbsp;&nbsp;
             <span id='{$fname}span' style='font-size: 16pt; background-color: $val'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
             ";
        break;
        case 'textarea': 
            $cols=40; $rows=4;
            if ($field['params']['rows']) $rows = $field['params']['rows'];
            if ($field['params']['cols']) $cols = $field['params']['cols'];
            if (!strlen($val)) $val = $field['params']['default'];
            $val = htmlspecialchars($val, ENT_QUOTES); 
            $field['edit'] = "
             <textarea name=\"$fname\" cols=$cols rows=$rows>$val</textarea>
             ";
        break;
        case 'password': 
        case 'password_c':
            $size=10;
            $field['edit'] = "
             <input type=password name=\"$fname\" 
                 size=$size maxlength=255>
             <input type=password name=\"{$fname}_confirm\" 
                 size=$size maxlength=255>
             <br /><small>enter password and confirmation><br />
             keep empty if you don't want change it</small>
             ";
        break;
        case 'select': 
        case 'multi_select': 
            if ($ftype == 'multi_select') $multi=1;
            if (!isset($vars[$fname])) 
                $val = $field['params']['default'];
            $options = "";
            foreach ($field['params']['options'] as $k=>$v){
                $k = htmlspecialchars($k, ENT_QUOTES); 
                $v = htmlspecialchars($v, ENT_QUOTES); 
                $sel = ($multi ? in_array($k, (array)$val) : $val == $k) ? 'selected' : '';
                $options .= "<option value=\"$k\" $sel>$v";
            }
            $multiple = $multi ? 'multiple' : '';
            $fname = $multi ? $fname."[]" : $fname;
            $size = $multi ? min(10, count($field['params']['options'])) : 1;
            $field['edit'] = "<select name=\"$fname\" size=$size $multiple>
            $options
            </select>
             ";
        break;
        case 'checkbox': 
            if (!isset($vars[$fname])) 
                $val = $field['params']['default'];
            $checked = $val ? 'checked' : '';
            $field['edit'] = "<input type='hidden' name='$fname' value='' />
        <input style='border-width: 0px;' type='checkbox' name='$fname' value='1' $checked />
        ";
        break;
        case 'multi_checkbox': 
            if (!isset($vars[$fname])) 
                $val = $field['params']['default'];
            $size = $field['params']['size'];
            if (!$size)
                $size = '5em';
            $field['edit'] = "<div class='checkbox_list' style='height: $size;'>
            <table class='checkbox_list'>
            \n";
            $i = -1;
            foreach ($field['params']['options'] as $k=>$v){
                $i++;
                $k = htmlspecialchars($k, ENT_QUOTES); 
                $v = htmlspecialchars($v, ENT_QUOTES); 
                $sel = in_array($k, (array)$val) ? 'checked' : '';
                $class = $sel ? 'sel' : '';
                $field['edit'] .= "
                <tr><td class='$class' nowrap='nowrap' id='td_{$fname}_$i'><label for='{$fname}_$i'>
                <input type='checkbox' id='{$fname}_$i' name='{$fname}[]' value='$k' $sel
                onclick='document.getElementById(\"td_{$fname}_$i\").className = this.checked ? \"sel\" : \"\";'>
                $v</label></td></tr>
                ";
            }
            $field['edit'] .= "</table></div>";
        break;
    };
}


function save_config_edit_field(&$field, &$vars, &$db_vars){
    $fname = $field['name'];
    $val   = $vars[str_replace('.', '_', $fname)];
    global $error;
    if ($func = $field['set_func']){
        $func($field,$vars,$db_vars);
        return;
    }
    if ($vf = $field['validate_func']){
        $err = call_user_func($vf, $field, $vars);

        if ($err) { $error[] = $err; return; }
    }
    switch ($ftype = $field['type']){
        case 'password':
            if ($val) 
                $db_vars[$fname] = crypt($val);
        break;
        case 'password_c':
            if ($val) 
                $db_vars[$fname] = $val;
        break;
        default:
            $db_vars[$fname] = $val;
    };
}
function show_config_notebook($notebook, $vars){
    global $t, $error;
    global $_notebooks, $_config_fields;
    read_plugins_configs();
    $t->assign('notebooks', $_notebooks);
    $t->assign('notebook', $notebook);
    $t->assign('error', $error);
    $fields = array();
    foreach ($_config_fields as $f){
        
        $notebooks = $f['notebook'];
        if (!is_array($notebooks)) $notebooks = array($notebooks);
        if (!in_array($notebook, $notebooks)) continue;
        
        //if ($f['notebook'] != $notebook) continue;
        $tname = str_replace('.', '_', $f['name']);
        if (!isset($vars[$f['name']]) && isset($vars[$tname]))
            $vars[$f['name']] = $vars[$tname];
        show_config_edit_field($f, $vars);
        $fields[] = $f;
    }
    $t->assign('fields', $fields);
    /// readme
    if ($rm = $_notebooks[$notebook]['readme']) {
        $f = join('', file($rm));
        $f=preg_replace_callback('/\{\$config\.(.+?)\}/', 
            'smarty_prefilter_put_config_cb',$f);
        $f = preg_replace("/(http(s?):\/\/)([\S\.]+)/i", '<a href="\\1\\3" target="_blank">\\1\\3</a>', $f);        
        $t->assign('readme', $f);
    }
    $t->display('admin/setup.html');
}

function show_config_countries($notebook){
    global $t;
    global $_notebooks, $_config_fields;
    read_plugins_configs();
    $t->assign('notebooks', $_notebooks);
    $t->assign('notebook', $notebook);
    $t->display('admin/countries.html');
}

function save_config_notebook($notebook, $vars){
    global $t, $error, $db, $config;
    global $_notebooks, $_config_fields;
    $db_vars = array();
    read_plugins_configs();
    foreach ($_config_fields as $f){

        $notebooks = $f['notebook'];
        if (!is_array($notebooks)) $notebooks = array($notebooks);
        if (!in_array($notebook, $notebooks)) continue;
        //if ($f['notebook'] != $notebook) continue;
        
        $tname = str_replace('.', '_', $f['name']);
        if (!isset($vars[$f['name']]) && isset($vars[$tname]))
            $vars[$f['name']] = $vars[$tname];
        save_config_edit_field($f, $vars, $db_vars);
    }
    if (!$error){
        $db->config_update($_config_fields, $db_vars);
        admin_log("Config changed ($vars[notebook])");
        header("Location:".$config['root_url']."/admin/setup.php?notebook=".urlencode($notebook));
        exit();
    }
    if ($notebook == 'Plugins'){
        global $config;
        $config['plugins']['payment'] = $db_vars['plugins.payment'];
        $config['plugins']['protect'] = $db_vars['plugins.protect'];
    }
    show_config_notebook($notebook, $vars);
}

function apply_plain_cf($k, $v, &$vars){
    foreach ($v as $kk=>$vv){
        if (is_array($vv) && ($keys = array_keys($vv)) && !is_integer($keys[0])){ // apply
            apply_plain_cf($k . '.' . $kk, $vv, $vars);
        } else { //next iteration
            $vars[ $k.'.'.$kk ] = $vv;
        }
    }
}

function config_to_vars($config){
    $vars = array();
    foreach ($config as $k=>$v){
        if (is_array($v) && ($keys = array_keys($v)) && !is_integer($keys[0])){
            apply_plain_cf($k, $v, $vars);
        } else {
            $vars[$k] = $v;
        }
    }
#    print "<pre>";print_r($vars);
    return $vars;
}

function read_plugins_configs(){
    global $config;
    // find all plugins and read their config
    foreach ((array)$config['plugins']['payment'] as $p)
        if (file_exists($fn="$config[root_dir]/plugins/payment/$p/config.inc.php"))
            include_once($fn);
    foreach ((array)$config['plugins']['protect'] as $p)
        if (file_exists($fn="$config[root_dir]/plugins/protect/$p/config.inc.php"))
            include_once($fn);
}

function tpl_display_notebooks(){
$cnt = 0;
$rowc = 8;
$_notebooks = $GLOBALS['_notebooks'];

foreach ($_notebooks as $name=>$nb){
  if ($cnt % $rowc == 0) { // first column
    echo "<tr>\n";    
  } 
  $colspan=1;
  $xx = $_POST['notebook'] ? $_POST['notebook'] : $_GET['notebook'];
  $cl = ($name == $xx) ? 'sel' : 'notsel';
  $href = "setup.php?notebook=" . urlencode($name);
  $comment = htmlentities($nb['comment']);
  echo "<td colspan=$colspan class=$cl><a href=\"$href\" title=\"$comment\">$name</a></td>\n";
  if ($cnt % $rowc == ($rowc - 1)){
    echo "</tr>\n";
  }
  $cnt++;
}
if ($ost = ($cnt % $rowc)) {
    $ost = $rowc - $ost;
    echo "<td colspan=$ost class=notsel>&nbsp;</td></tr>";
}

echo "
";
}
#####################################################
require "$config[root_dir]/admin/config.inc.php";

admin_check_permissions('setup');

$vars = get_input_vars();
$error = array();

if (!$vars['notebook']) $vars['notebook'] = $_default_notebook;
$vars['notebook'] = preg_replace('[\\\/]', '', $vars['notebook']);
if ($vars['save']){
   save_config_notebook($vars['notebook'], $vars);
} else {
   if ($vars['notebook'] == 'Countries') {
      show_config_countries($vars['notebook']);
   } else {
      show_config_notebook($vars['notebook'], config_to_vars($config));
   }
}



?>

Re: Aide pour message d'erreur sur aMember

par xTG » 12 oct. 2011, 16:26

Il a déjà dans ce code quelque chose qui est bizarre. Le test est en fait le test de réussite d'une affectation.
if ($vf = $field['validate_func']){
Cela n'a aucun sens puisqu'en théorie c'est toujours vrai, donc je pense qu'il manque un égal. ;)

Ensuite pour débugguer il faudrait afficher la valeur de $vf et comprendre d'où elle provient dans le code.

Re: Aide pour message d'erreur sur aMember

par Damien34 » 12 oct. 2011, 14:05

Merci pour l'explication, une idée pour mettre sous silence ou debugger?

En tout cas merci pour l'aide.

Re: Aide pour message d'erreur sur aMember

par xTG » 12 oct. 2011, 13:53

$vf ne contient pas le nom d'une fonction qui existe (ou qui est accessible).
De ce fait cela génère le premier warning.

Ce warning étant envoyé au navigateur, le buffer contient quelque chose. Or avant un header() il ne faut rien envoyer.
Cela occasionne donc le dernier warning.

Aide pour message d'erreur sur aMember

par Damien34 » 12 oct. 2011, 12:40

Bonjour,

J'utilise aMember pour un système de membre, le soucis est lorsque je
veux changer la valeur par défaut j'ai un message d'erreur :
WARNING: call_user_func(validate_root_url) [function.call-user-func]:
First argument is expected to be
a valid callback in line 243 of file setup.php
WARNING: call_user_func(validate_root_url) [function.call-user-func]:
First argument is expected to be
a valid callback in line 243 of file setup.php
WARNING: Cannot modify header information - headers already sent by
(output started at /amember/rconfig.inc.php:282) in line 322 of file
setup.php

Sur setup.php aux lignes 242 et suivantes j'ai :
if ($vf = $field['validate_func']){
$err = call_user_func($vf, $field, $vars);

if ($err) { $error[] = $err; return; }
}

et lignes 319 et suivantes j'ai :
if (!$error){
$db->config_update($_config_fields, $db_vars);
admin_log("Config changed ($vars[notebook])");
header("Location:".$config['root_url']."/admin/setup.php?notebook=".urlencode($notebook));
exit();
}

Je ne sais pas vraiment d'où vient le problème, mais que je mette $ ou
€ j'ai le message d'erreur, sauf que dans la BDD ça me prend
le $ mais pas €...

Merci d'avance pour votre aide.