431 lines
18 KiB
PHP
431 lines
18 KiB
PHP
<?php
|
|
|
|
if (!isset($page))
|
|
$page=str_replace('.php', '', basename(__FILE__));
|
|
|
|
include_once('tables.php');
|
|
include_once('qs_functions.php');
|
|
include_once('default.php');
|
|
if (!isset($titre))
|
|
$titre='Edition "'.$table.'"';
|
|
|
|
mysql_query('SET CHARACTER SET utf8;');
|
|
$result = mysql_query($sql_select . " " . $sql_ext . " limit 0,1")
|
|
or die("Invalid query : $sql_select $sql_ext limit 0,1\n" . mysql_error() );
|
|
$qry_string = "";
|
|
$value_sql = "";
|
|
$currentrow_sql = "";
|
|
$hidden_tag = "";
|
|
$hiddenrow_tag = "";
|
|
$i = 0;
|
|
//$cleChoisie=false; // Initialisation de l'édition par une autre clé que la clé de début de table
|
|
while ($i < mysql_num_fields($result)) {
|
|
$meta = mysql_fetch_field($result);
|
|
$field_name = $meta->name;
|
|
$field_type = $meta->type;
|
|
if (qsvalidRequest("search_fd" .$i)) {
|
|
if ($qry_string == "") {
|
|
$qry_string = "search_fd" . $i . "=" . qsrequest("search_fd" . $i);
|
|
} else {
|
|
$qry_string .= "&search_fd" .$i . "=" . qsrequest("search_fd" . $i);
|
|
}
|
|
$hidden_tag .= "<input type=\"hidden\" name=\"search_fd" . $i . "\" value=\"" . qsrequest("search_fd" . $i) . "\">\n";
|
|
if ($qry_string == "") {
|
|
$qry_string = "multisearch_fd" . $i . "=" . urlencode(stripslashes(qsrequest("multisearch_fd" . $i)));
|
|
} else {
|
|
$qry_string .= "&multisearch_fd" .$i . "=" . urlencode(stripslashes(qsrequest("multisearch_fd" . $i)));
|
|
}
|
|
$hidden_tag .= "<input type=\"hidden\" name=\"multisearch_fd" .$i . "\" value=\"" . qsreplace_html_quote(stripslashes(qsrequest("multisearch_fd" . $i))) . "\">\n";
|
|
}
|
|
$type_field = "";
|
|
$type_field = returntype($field_type);
|
|
$quotedata = "";
|
|
switch ($type_field) {
|
|
case "type_datetime": $quotedata = $quotedate; break;
|
|
case "type_string": $quotedata = "'"; break;
|
|
case "type_integer": $quotedata = ""; break;
|
|
case "type_unknown": $quotedata = "'"; break;
|
|
default: $quotedata = "'";
|
|
}
|
|
if ($meta) {
|
|
if (qsrequest("currentrow_fd" .$i) != "") {
|
|
if ($currentrow_sql == "") {
|
|
$currentrow_sql = $fields[$i] . " = " . $quotedata . ereg_replace("'","''",stripslashes(qsrequest("currentrow_fd" . $i))) . $quotedata;
|
|
} else {
|
|
$currentrow_sql .= " and " .$fields[$i] . " = " . $quotedata . ereg_replace("'","''",stripslashes(qsrequest("currentrow_fd" . $i))) . $quotedata;
|
|
}
|
|
$hiddenrow_tag .= "<input type=\"hidden\" name=\"currentrow_fd" . $i . "\" value=\"" . qsreplace_html_quote(stripslashes(qsrequest("currentrow_fd" . $i))) . "\">\n";
|
|
}
|
|
elseif (qsrequest('uniqueKey') !='' && $champ[$i]['nom']==qsrequest('uniqueKey') ) {
|
|
//elseif () //{.$tmp[2].'&='.$itemvalue;))
|
|
//$cleChoisie=true;
|
|
if ($currentrow_sql == '') {
|
|
$currentrow_sql = qsrequest('uniqueKey') .'='. $quotedata . ereg_replace("'","''",stripslashes(qsrequest('value'))) . $quotedata;
|
|
} else {
|
|
$currentrow_sql .= ' AND '. qsrequest('uniqueKey') .'='. $quotedata . ereg_replace("'","''",stripslashes(qsrequest('value'))) . $quotedata;
|
|
}
|
|
$hiddenrow_tag .= '<input type="hidden" name="currentrow_fd'.$i.'" value="'. qsreplace_html_quote(stripslashes(qsrequest('value'))) . "\">\n";
|
|
}
|
|
if($isEditables[$i])
|
|
{
|
|
if ($type_field == "type_datetime") {
|
|
if (qsvalidRequest("edit_fd" . $i)) {
|
|
$idata = qsrequest("edit_fd" . $i);
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = " . $quotedate . qsconvertdate2ansi($idata,$formatdate[$i],$seperatedate[$i]) . $quotedate;
|
|
}
|
|
else if($isEditables[$i] != 2) {
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = null";
|
|
}
|
|
} elseif ($type_field == "type_integer") {
|
|
if (qsvalidRequest("edit_fd" . $i)) {
|
|
if (isset($champ[$i]['libs']['table'])) {
|
|
$tmp=qsrequest("edit_fd" . $i);
|
|
$idata =$tmp[0];
|
|
} else
|
|
$idata = qsrequest("edit_fd" . $i);
|
|
if (is_numeric($idata)) {
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = " . $idata;
|
|
} else {
|
|
$err_string .= "<strong>Erreur :</strong> lors de l'enregistrement de la zone '<strong>" . $field_name . "</strong>'.<br/>";
|
|
$err_string .= "Description : type de donnée incohérent.<br>";
|
|
}
|
|
}
|
|
else if($isEditables[$i] != 2) {
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = null";
|
|
}
|
|
} elseif ($type_field == "type_string") {
|
|
if (qsvalidRequest("edit_fd" . $i)) {
|
|
if (isset($champ[$i]['libs']['table']))
|
|
$idata = implode(';', qsrequest("edit_fd" . $i));
|
|
else
|
|
$idata = qsrequest("edit_fd" . $i);
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = '" . ereg_replace("'","''",stripslashes($idata)) . "'";
|
|
}
|
|
else if($isEditables[$i] != 2) {
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = null";
|
|
}
|
|
} else {
|
|
if (qsvalidRequest("edit_fd" . $i)) {
|
|
$idata = qsrequest("edit_fd" . $i);
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = '" . ereg_replace("'","''",stripslashes($idata)) . "'";
|
|
}
|
|
else if($isEditables[$i] != 2) {
|
|
$value_sql .= "," . $quotechar . $field_name . $quotechar . " = null";
|
|
}
|
|
}
|
|
}//if ($isEditables[$i])
|
|
}//if ($meta)
|
|
$i++;
|
|
}
|
|
if (isset($_POST["act"])) {
|
|
//print_r($_POST);die();
|
|
if (($err_string)=="") {
|
|
if (($value_sql)!="") {
|
|
if (substr($value_sql, 0, 1) == ",") {
|
|
$value_sql = substr($value_sql, 1);
|
|
}
|
|
$sql = 'UPDATE ' . $quotechar . mysql_field_table($result,0) . $quotechar;
|
|
$sql .= ' SET ' . $value_sql;
|
|
$sql .= ' WHERE ';
|
|
$sql .= $currentrow_sql;/*
|
|
print_r($_POST);
|
|
echo $sql;
|
|
die();*/
|
|
if ($result > 0) {mysql_free_result($result);}
|
|
if (!$result = @mysql_query($sql)){
|
|
$err_string .= "<strong>Erreur : </strong> lors de l'enregistrement en base (<strong>" . mysql_errno() . "</strong>).<br/>";
|
|
$err_string .= "Description : " . mysql_error();
|
|
}
|
|
}
|
|
#----get submit url page----
|
|
if (qsrequest('referer')<>'')//$_SERVER['HTTP_REFERER']))
|
|
$submiturl=genereUrl(qsrequest('referer'));
|
|
else
|
|
$submiturl='./list.php';
|
|
if ($err_string == "") {
|
|
if ($qry_string != "") {
|
|
$URL= $submiturl . "&" . $qry_string;
|
|
} else {
|
|
$URL= $submiturl;
|
|
}
|
|
header ("Location: $URL");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ($result > 0) mysql_free_result($result);
|
|
$sql = $sql_select;
|
|
if ($currentrow_sql != "") {
|
|
$sql .= " where ".$currentrow_sql ;
|
|
}
|
|
$result = mysql_query($sql) or die("Invalid query : $sql");
|
|
$row = mysql_fetch_array($result);
|
|
}
|
|
?>
|
|
|
|
<html>
|
|
<head>
|
|
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
|
|
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
|
|
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />-->
|
|
<title><?=htmlentities($titre)?></title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<link rel="stylesheet" type="text/css" href="../nonimg/gestion.css">
|
|
<script src="../nonimg/validate.js"></script>
|
|
|
|
<SCRIPT language='javascript' src='../nonimg/calendar.js'></script>
|
|
|
|
<script language="javascript">
|
|
function check(frm) {
|
|
var szAlert = "Erreur(s) :\n";
|
|
var nIndex = 0;
|
|
<?php
|
|
|
|
foreach ($champ as $i=>$field) {
|
|
if (!$field['hidden'] && $isEditables[$i])
|
|
{
|
|
/* // On test si le champ peut être vide
|
|
?>
|
|
if (!RequiredField(frm.edit_fd<?=$i?>.value)) {
|
|
nIndex++;
|
|
szAlert += "- " +"'<?=htmlentities($field['libelleColonne'])?>' ne peut être vide\n";
|
|
}
|
|
<?
|
|
*/ // Si le champ est au format date, ajout du test de contrôle de la date en JavaScript
|
|
if ($formatdate[$i]<>'') {
|
|
?>
|
|
if (frm.edit_fd<?=$i?>.value!="" && !isDate(frm.edit_fd<?=$i?>.value)) {
|
|
nIndex++;
|
|
szAlert += "- " +"'<?=htmlentities($field['libelleColonne'])?>' n'est pas une date valide\n";
|
|
}
|
|
<?
|
|
}
|
|
|
|
// Si le champ est de type int au sens large, ajout du test de contrôle de validité en JavaScript
|
|
if ($format[$i]=='int') {
|
|
?>
|
|
if (frm.edit_fd<?=$i?>.value!="" && !NumberValidate(frm.edit_fd<?=$i?>.value)) {
|
|
nIndex++;
|
|
szAlert += "- " +"'<?=htmlentities($field['libelleColonne'])?>' n'est pas un nombre\n";
|
|
}
|
|
<?
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
if(nIndex > 0) {
|
|
alert(szAlert) ;
|
|
return false ;
|
|
}
|
|
<?php
|
|
foreach ($champ as $i=>$field) {
|
|
if (!$field['hidden'] && $isEditables[$i] && isset($champ[$i]['libs']['table'])) {
|
|
?>
|
|
for(i=0;i<frm.edit_fd<?=$i?>.length;i++){
|
|
frm.edit_fd<?=$i?>.options[i].selected = true;
|
|
}
|
|
frm.edit_fd<?=$i?>.name = "edit_fd<?=$i?>[]";
|
|
<?php
|
|
}
|
|
}
|
|
?>
|
|
return true ;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<center>
|
|
<center><strong><font size="5"><?=htmlentities($titre)?></font></strong></center><br>
|
|
|
|
<a name="top"></a>
|
|
|
|
<script>
|
|
function getURLParam(strParamName){
|
|
var strReturn = "";
|
|
var strHref = window.location.href;
|
|
if ( strHref.indexOf("?") > -1 ){
|
|
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
|
|
var aQueryString = strQueryString.split("&");
|
|
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
|
|
if (
|
|
aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
|
|
var aParam = aQueryString[iParam].split("=");
|
|
strReturn = aParam[1];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return strReturn;
|
|
}
|
|
</script>
|
|
|
|
|
|
<form name="qs_edit_form" method="post" action="./edit.php" onSubmit="return check(this)">
|
|
|
|
<?php
|
|
print $hidden_tag;
|
|
print $hiddenrow_tag;
|
|
$css_class = '"TrOdd"';
|
|
?>
|
|
<table Border="0" Cellpadding="2" Cellspacing="1" BgColor="#177AE9">
|
|
<tr>
|
|
<td colspan="2" class="ThRows" align="center"><?=htmlentities($titre)?></td>
|
|
</tr>
|
|
<?php
|
|
if ($err_string != '') {
|
|
print '<tr>';
|
|
print '<td align="left" class="ThRows"><b><font color="red">Erreur :</font></b></td>';
|
|
print '<td align="left" colspan="2" class=' . $css_class . '>' . $err_string . '</td>';
|
|
print '</tr>';
|
|
}
|
|
|
|
foreach ($champ as $i=>$field) {
|
|
if (!$field['hidden'])
|
|
{
|
|
?>
|
|
<tr>
|
|
<td align="left" class="ThRows"><?=htmlentities($field['libelleColonne'])?></td>
|
|
<?php
|
|
$cellvalue = "";
|
|
if ((!isset($_GET["edit_fd".$i])) && (!isset($_POST["edit_fd".$i]))) {
|
|
if ($formatdate[$i]<>'')
|
|
$itemvalue = qsconvertdate($row[$i],"dd/mm/yyyy");
|
|
else
|
|
$itemvalue = $row[$i];
|
|
} else {
|
|
$itemvalue = qsrequest("edit_fd".$i);
|
|
}
|
|
if ($isEditables[$i]) {
|
|
$cellvalue = '<input type="text" name="edit_fd'.$i.'" value="' . qsreplace_html_quote(stripslashes($itemvalue)) . '"';
|
|
if (isset($long[$i]) && $long[$i]>0) {
|
|
$size=$long[$i]+1;
|
|
if ($size>80) $size=80;
|
|
$cellvalue.=' size="'.$size.'" maxlength="'.$long[$i].'">';
|
|
} else
|
|
$cellvalue.='>';
|
|
if (isset($champ[$i]['libs']['table'])){
|
|
$libs=$champ[$i]['libs'];
|
|
if ($format[$i]=='int') {
|
|
$multiple='';
|
|
$testMutipe1="if (!Selectbox.hasOneOption(this.form.edit_fd$i)) { ";
|
|
$testMutipe2=' } ';
|
|
} else {
|
|
$multiple='multiple';
|
|
$testMutipe1='';
|
|
$testMutipe2='';
|
|
}
|
|
//$cellvalue='<input type="text" name="edit_fd'.$i.'" value="'. htmlentities($itemvalue).'">';
|
|
$cellvalue ='<table><tr><td valign="top"><i>Sélectionné(s) :</i><br/><select align="top" name="edit_fd'.$i.'" size="10" '.$multiple.
|
|
' onDblClick="Selectbox.moveSelectedOptions(this.form.edit_fd'.$i.',this.form.edit_fd'.$i.'out, true)">'.EOL;
|
|
if ($itemvalue<>'') {//mysql_query('SET CHARACTER SET utf8;');
|
|
$cellvalue.=qsmysqlgen_listbox('SELECT '.$libs['key'].', '.$libs['lib'].' FROM '.$libs['table'].' WHERE '.$libs['key']." IN ('".str_replace(';',"','",$itemvalue)."')",
|
|
'edit_fd'.$i, $libs['key'], $libs['lib'],$itemvalue);}
|
|
$cellvalue.='</select></td><td align="center">'.EOL;
|
|
// onDblClick="Selectbox.moveSelectedOptions(this.form.list1,this.form.list2,this.form.movesort.checked,this.form.movepattern1.value)">
|
|
// onClick="Selectbox.moveSelectedOptions(this.form.list1,this.form.list2,this.form.movesort.checked,this.form.movepattern1.value)"><br><br>
|
|
$cellvalue.='<input type="button" VALUE=">" onClick="Selectbox.moveSelectedOptions(this.form.edit_fd'.$i.', this.form.edit_fd'.$i.'out, true)"><br/>'.EOL;
|
|
if ($multiple<>'')
|
|
$cellvalue.='<input type="button" VALUE=">>" onClick="Selectbox.moveAllOptions(this.form.edit_fd'.$i.', this.form.edit_fd'.$i.'out, true)"><br/>'.EOL;
|
|
$cellvalue.='<br/><input type="button" VALUE="<" onClick="'.$testMutipe1.'Selectbox.moveSelectedOptions(this.form.edit_fd'.$i.'out, this.form.edit_fd'.$i.', true)'.$testMutipe2.'"><br/>'.EOL;
|
|
if ($multiple<>'')
|
|
$cellvalue.='<input type="button" VALUE="<<" onClick="Selectbox.moveAllOptions(this.form.edit_fd'.$i.'out, this.form.edit_fd'.$i.', true)"><br/>'.EOL;
|
|
|
|
$cellvalue.='</td><td><i>Disponible(s) :</i><br/><select align="top" name="edit_fd'.$i.'out" SIZE="10" '.$multiple.
|
|
'onDblClick="'.$testMutipe1.'Selectbox.moveSelectedOptions(this.form.edit_fd'.$i.'out,this.form.edit_fd'.$i.', true)'.$testMutipe2.'">'.EOL;
|
|
if ($itemvalue<>'')
|
|
$cellvalue.=qsmysqlgen_listbox('SELECT '.$libs['key'].', '.$libs['lib'].' FROM '.$libs['table'].' WHERE '.$libs['key']." NOT IN ('".str_replace(';',"','",$itemvalue)."')",
|
|
'edit_fd'.$i.'out', $libs['key'], $libs['lib'],$itemvalue);
|
|
else
|
|
$cellvalue.=qsmysqlgen_listbox('SELECT '.$libs['key'].', '.$libs['lib'].' FROM '.$libs['table'],
|
|
'edit_fd'.$i.'out', $libs['key'], $libs['lib'],$itemvalue);
|
|
$cellvalue.='</select></td></tr></table>'.EOL;
|
|
}
|
|
elseif ($format[$i]=='date') $cellvalue.='<a href="#edit_fd'.$i.'"></a><a name="edit_fd'.$i.'"><img src="../images/Calendar.gif" onclick="popUpCalendar(this, document.forms[0].edit_fd'.$i.', \'dd/mm/yyyy\', 0, 0)" align="absmiddle" border="0" height="21" width="20"></a>';
|
|
elseif ($format[$i]=='text') $cellvalue ='<textarea name="edit_fd'.$i.'" rows=4 cols=40>' . qsreplace_html_quote(stripslashes($itemvalue)) . '</textarea>';
|
|
elseif ($format[$i]=='enum') {
|
|
$cellvalue='';
|
|
foreach ($formatEnum[$i] as $value) {
|
|
$value=utf8_encode($value);
|
|
$cellvalue.= '<input type="radio" name="edit_fd'.$i.'" value="'.$value. '" ';
|
|
$cellvalue.= qscheckselected($value,$itemvalue,' checked="checked"') .'>'.$value.'<br/>';
|
|
}
|
|
}
|
|
/*'fields_libs' =>array( 'typeEven'=>array('table'=>'jo.tabEvenements',
|
|
'key'=>'codEven',
|
|
'lib'=>'libEven')),*/
|
|
if ($champ[$i]['link']<>'') { // Le champ comporte un lien vers une autre source de données
|
|
$tmp=explode('.', $champ[$i]['link']);
|
|
$database = $tmp[0];
|
|
$table = $tmp[1];
|
|
if (isset($tmp[2])) $cles = 'uniqueKey='.$tmp[2].'&value='.$itemvalue;
|
|
else $cles = 'currentrow_fd'.$i.'='.$itemvalue;
|
|
$cellvalue.= ' <a href="./edit.php?dbtable='.$database.'.'.$table.'&'.$cles.'&refererUrl='.urlencode($_SERVER['REQUEST_URI']).'">Lien</a>';
|
|
}
|
|
}
|
|
else { // Le champ n'est pas éditable
|
|
if ($champ[$i]['link']<>'') { // Le champ comporte un lien vers une autre source de données
|
|
$tmp=explode('.', $champ[$i]['link']);
|
|
$database = $tmp[0];
|
|
$table = $tmp[1];
|
|
if (isset($tmp[2])) $cles = 'uniqueKey='.$tmp[2].'&value='.$itemvalue;
|
|
else $cles = 'currentrow_fd'.$i.'='.$itemvalue;
|
|
$cellvalue = '<a href="./edit.php?dbtable='.$database.'.'.$table.'&'.$cles.'&refererUrl='.urlencode($_SERVER['REQUEST_URI']).'">'.$itemvalue.'</a>';
|
|
}
|
|
elseif (isset($champ[$i]['libs']['table'])) { // Le champ a une table liée
|
|
$libs=$champ[$i]['libs'];
|
|
//$cellvalue='<input type="text" name="edit_fd'.$i.'" value="'. htmlentities($itemvalue).'">';
|
|
$cellvalue =str_replace(array("\n\r","\r\n","\n","\r"),"<br>",qsmysqlgen_listvisu('SELECT '.$libs['key'].', '.$libs['lib'].' FROM '.$libs['table'].' WHERE '.$libs['key']." IN ('".str_replace(';',"','",$itemvalue)."')",
|
|
'edit_fd'.$i, $libs['key'], $libs['lib'],$itemvalue));
|
|
}
|
|
else // On afiche laa valeur du champ
|
|
$cellvalue = $itemvalue;
|
|
}
|
|
if ($cellvalue == '') {
|
|
$cellvalue = ' ';
|
|
}
|
|
print '<td class=' . $css_class . ' align="left">' . $cellvalue . '</td>';
|
|
|
|
?>
|
|
</tr>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
#----get back url page----
|
|
if (qsrequest('referer')<>'')//$_SERVER['HTTP_REFERER']))
|
|
$backurl=genereUrl(qsrequest('referer'));
|
|
elseif (qsrequest('refererUrl')<>'')//))
|
|
$backurl=qsrequest('refererUrl');
|
|
elseif ($_SERVER['HTTP_REFERER'])
|
|
$backurl = $_SERVER['HTTP_REFERER'];
|
|
else
|
|
$backurl = "./list.php";
|
|
//else $backurl=$_SERVER['HTTP_REFERER'];
|
|
?>
|
|
<tr>
|
|
<td class="ThRows"> </td>
|
|
<td class="TrOdd" align="center">
|
|
<input type="hidden" name="act" value="n">
|
|
<input type="hidden" name="referer" value="<?=qsrequest('referer')?>">
|
|
<input type="button" name="QS_Back" value="Retour" OnClick="javascript:window.location='<?=$backurl?>'">
|
|
<?php if (@!$tablesInfo[$dbtable]['table_readOnly']) { ?>
|
|
<input type="submit" name="QS_Submit" value="Sauvegarde">
|
|
<input type="reset" name="QS_Reset" value="Réinitialisation">
|
|
<?php } elseif ($page=='view') { ?>
|
|
<input type="button" name="QS_Edit" value="Edition" onclick="javascript:window.location='<?=str_replace('/view.php?', '/edit.php?', $_SERVER['REQUEST_URI'])?>'">
|
|
<?php } ?>
|
|
</td>
|
|
</tr>
|
|
</Table><br>
|
|
</Form>
|
|
<?php
|
|
if ($link > 0) {mysql_close($link);}
|
|
?>
|
|
<a name="bottom"></a>
|
|
</center>
|
|
</body>>
|
|
</html>
|