Exemplo n.º 1
0
function valeur_colonne_table_dist($type, $col, $id)
{
    // Table introuvable ou sans clé primaire
    if (!($infos = crayons_get_table_name_and_primary($type))) {
        return false;
    }
    $table = reset($infos);
    $r = array();
    // valeurs non SQL
    foreach ($col as $champ) {
        if (function_exists($f = 'valeur_champ_' . $table . '_' . $champ) or function_exists($f = 'valeur_champ_' . $champ)) {
            $r[$champ] = $f($table, $id, $champ);
            $col = array_diff($col, array($champ));
        }
    }
    // valeurs SQL
    if (count($col)) {
        list($distant, $table) = distant_table($type);
        list($nom_table, $where) = table_where($type, $id);
        if ($s = spip_query('SELECT `' . implode($col, '`, `') . '` FROM ' . $nom_table . ' WHERE ' . $where, $distant) and $t = sql_fetch($s)) {
            $r = array_merge($r, $t);
        }
    }
    return $r;
}
Exemplo n.º 2
0
function crayons_update($id, $colval = array(), $type = '')
{
    if (!$colval or !count($colval)) {
        return false;
    }
    list($distant, $table) = distant_table($type);
    if ($distant) {
        list($nom_table, $where) = table_where($type, $id);
        if (!$nom_table) {
            return false;
        }
        $update = $sep = '';
        foreach ($colval as $col => $val) {
            $update .= $sep . '`' . $col . '`=' . _q($val);
            $sep = ', ';
        }
        $a = spip_query($q = 'UPDATE `' . $nom_table . '` SET ' . $update . ' WHERE ' . $where, $distant);
        #spip_log($q);
        include_spip('inc/invalideur');
        suivre_invalideur($cond, $modif = true);
    } else {
        // cle primaire composee : 3-4-rubrique
        // calculer un where approprie
        // et modifier sans passer par la fonction destinee aux tables principales
        // on limite a SPIP 2 mini car sql_updateq n'est pas mappe dans les crayons_compat
        if (is_scalar($id) and $GLOBALS['spip_version_code'] >= '1.93') {
            list($nom_table, $where) = table_where($type, $id, true);
            // where sous forme de tableau
            $a = sql_updateq($nom_table, $colval, $where);
        } else {
            // modification d'une table principale
            include_spip('inc/modifier');
            $a = modifier_contenu($type, $id, array(), $colval);
        }
    }
    return $a;
}
Exemplo n.º 3
0
function valeur_colonne_table_dist($type, $col, $id) {
	list($distant,$table) = distant_table($type);
	list($nom_table, $where) = table_where($type, $id);

	if (!$nom_table)
		return false;

	$r = array();

	// valeurs non SQL
	foreach ($col as $champ) {
		if (function_exists($f = 'valeur_champ_'.$table.'_'.$champ) OR function_exists($f = 'valeur_champ_'.$champ)) {
			$r[$champ] = $f($table, $id, $champ);
			$col = array_diff($col, array($champ));
		}
	}

	// valeurs SQL
	if (count($col)
	AND $s = spip_query(
			'SELECT `' . implode($col, '`, `') .
			'` FROM ' . $nom_table . ' WHERE ' . $where, $distant)
	AND $t = sql_fetch($s))
		$r = array_merge($r, $t);

	return $r;
}