le systeme permet de gerer de la pub: il s'agit de myphp pub.
voici la notice du systeme:
http://www.asp-magazine.com/fr/php/exem ... phppub.asp
j'ai donc creer 3 tables:
Code : Tout sélectionner
CREATE TABLE pub_pub (
id_pub int(11) NOT NULL auto_increment,
id_groupe int(11) NOT NULL default '0',
id_campagne int(11) NOT NULL default '0',
url_img varchar(255) NOT NULL default '',
url_lien varchar(255) NOT NULL default '',
nbclick int(11) NOT NULL default '0',
nbvu int(11) NOT NULL default '0',
valid_pub tinyint(4) NOT NULL default '0',
unbclick int(11) NOT NULL default '0',
ipclick varchar(30) NOT NULL default '',
datefin date NOT NULL default '0000-00-00',
datedebut date NOT NULL default '0000-00-00',
uclickmax int(11) NOT NULL default '0',
clickmax int(11) NOT NULL default '0',
vumax int(11) NOT NULL default '0',
typefin tinyint(4) NOT NULL default '0',
typ_tag tinyint(4) NOT NULL default '0',
tag_text text NOT NULL,
pourcent float NOT NULL default '0',
affiche_jour int(11) NOT NULL default '0',
date_vu date NOT NULL default '0000-00-00',
titre varchar(255) NOT NULL default '',
PRIMARY KEY (id_pub)
) TYPE=MyISAM;
Code : Tout sélectionner
CREATE TABLE pub_campagne (
id_campagne int(11) NOT NULL auto_increment,
nom_campagne varchar(255) NOT NULL default '',
PRIMARY KEY (id_campagne)
) TYPE=MyISAM;
Code : Tout sélectionner
CREATE TABLE pub_groupe (
id_grp int(11) NOT NULL auto_increment,
nom_groupe varchar(255) NOT NULL default '',
PRIMARY KEY (id_grp)
) TYPE=MyISAM;
et voici :
le code de la page qui m'indique l'erreur a la ligne 149:
<?
header("Cache-Control: no-cache, must-revalidate"); /* Pour HTTP/1.1 */
require "connexion.php";
$msg="";
session_start();
function diff_date($day , $month , $year , $day2 , $month2 , $year2){
// fonction de calcul de différence de date
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$timestamp2 = mktime(0, 0, 0, $month2, $day2, $year2);
$diff_date = floor(($timestamp - $timestamp2) / (3600 * 24));
return $diff_date;
}
if ($init=="yes") {
// initialisation
$uclickmax="0";
$datedebut=date("d/m/Y");
$clickmax="0";
$vumax="0";
$R1="1";
$nbvu="0";
$nbclick="0";
$unbclick="0";
$auto="yes";
$typ_tag="0";
}
if ($action!="") {
if ($titre=="") {
$msg="Veuillez donner un nom à cette publicité";
}
if ($R1=="") {
$msg="Veuillez sélectionner le type d'expiration";
}
if ($datedebut!="") {
$ec1=explode("/",$datedebut);
if (checkdate($ec1[1],$ec1[0],$ec1[2])) {
if (strlen($ec1[2])!=4) {
$msg="La date de début de publicité doit être de la forme jj/mm/aaaa";
} else {
$datedeb=$ec1[2]."/".$ec1[1]."/".$ec1[0];
}
} else {
$msg="La date de début de publicité est incorrecte";
}
}
if (!is_numeric($nbclick)) {
$msg="Le nombre de click initial est incorrect";
}
if (!is_numeric($nbvu)) {
$msg="Le nombre d'affichage initial est incorrect";
}
if (!is_numeric($unbclick)) {
$msg="Le nombre de click unique initial est incorrect";
}
if ($auto=="") {
if (!is_numeric($pourcent)) {
$msg="Le pourcentage est incorrect";
} else {
if (($pourcent>1) && (pourcent<=0)) {
$msg="Le pourcentage est incorrect";
}
}
}
if ($R1!="") {
switch ($R1) {
case "0":
if ($datefin=="") {
$msg="La date de fin de publicité est incorrecte";
} else {
$ec1=explode("/",$datefin);
if (checkdate($ec1[1],$ec1[0],$ec1[2])) {
if (strlen($ec1[2])!=4) {
$msg="La date de fin de publicité doit être de la forme jj/mm/aaaa";
} else {
$datefi=$ec1[2]."/".$ec1[1]."/".$ec1[0];
}
} else {
$msg="La date de fin de publicité est incorrecte";
}
}
break;
case "1":
if (!is_numeric($vumax)) {
$msg="Le nombre de pages vues à l'expiration est incorrect";
}
break;
case "2":
if (!is_numeric($uclickmax)) {
$msg="Le nombre de clicks unique à l'expiration est incorrect";
}
break;
case "3":
if (!is_numeric($clickmax)) {
$msg="Le nombre de clicks à l'expiration est incorrect";
}
break;
}
}
if ($typ_tag=="1") {
// pub textuelle
if ($tag_text=="") {
$msg="Veuillez renseigner le champ textuel";
}
}
if ($typ_tag=="0") {
// pub classique
}
if ($id_campagne=="0") {
$msg="Veuillez sélectionner une campagne";
}
if ($id_groupe=="0") {
$msg="Veuillez sélectionner un groupe";
}
if ($msg=="") {
// upload du fichier
if ($x_fichier1_name!="") {
if(!is_writeable($cfg_upload_path)){
print("Le répertoire n'est pas accessible en écriture.<br>\n");
}
$ext=substr($x_fichier1_name,strrpos($x_fichier1_name,"."));
if (!Isset($SIID)) {
$SIID=0;
} else {
$SIID=$SIID+1;
}
session_register("SIID");
if ($xname!="") {
unlink($cfg_upload_path.$xname);
}
$xname="pub".$SIID.$ext;
if (copy($x_fichier1, $cfg_upload_path.$xname)){
unlink($x_fichier1);
// enregistrer le fichier dans une session
session_register("xname");
$direc="1";
}
else{
print("Impossible d'uploader ".$x_fichier1_name."<br>\n");
exit();
}
}
if ($auto!="") {
$pourcent=1;
$sql="select count(*) FROM pub_pub WHERE id_campagne=$id_campagne AND id_groupe=$id_groupe";
if ($p = @mysql_query($sql,$connpub)){
if ($rs = @mysql_fetch_array($p)){
if ($rs[0]>0) {
$pourcent=1/($rs[0]+1);
$sql="UPDATE pub_pub SET pourcent=$pourcent WHERE id_campagne=$id_campagne AND id_groupe=$id_groupe";
@mysql_query($sql,$connpub);
}
}
}
}
if ($action=="Valider") {
// Uniquement si pas mode apercu
if ($xname!="") {
// copie du fichier temporaire
$ext=substr($xname,strrpos($xname,"."));
$img_pub="pub".$id.$ext;
copy($cfg_upload_path.$xname, $cfg_final_path."pub".$id.$ext) ;
$xname="";
}
$sql="INSERT INTO pub_pub (id_groupe,id_campagne,url_lien,valid_pub,
datefin,datedebut,uclickmax,clickmax,vumax,typefin,typ_tag,tag_text,pourcent
,nbvu,nbclick,unbclick,url_img,titre)
VALUES($id_groupe,$id_campagne,'".addslashes($url_lien)."',
1,'".$datefi."','".$datedeb."',$uclickmax,$clickmax,$vumax,$R1,
$typ_tag,'".addslashes($tag_text)."',$pourcent,$nbvu,$nbclick,$unbclick,'".addslashes($img_pub)."','".addslashes($titre)."')";
@mysql_query($sql,$connpub);
//echo $sql;
//$sql="INSERT INTO pub_campagne (nom_campagne) VALUES('".addslashes($nom)."')";
//$p = @mysql_query($sql,$connpub);
@mysql_close($connpub);
header("Location:puba.php?valid=1");
exit();
}
}
}
?>
<html>
<head>
<title>Ajouter une campagne</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
<!--
A
{
COLOR: #000080
}
A:hover
{
COLOR: red;
}
.titrecat { font-family: Arial; font-size: 11 pt; color: #000080; font-weight: bold }
.titrecat1 { font-size: 9 pt; font-family: Arial; color: #0080C0; font-weight: bold }
.titrenorm1 { font-size: 11 pt; font-family: Arial; color: #000080; font-weight: bold }
.textepetit { font-size: 8 pt; font-family: Arial }
.spetit { font-size: 6 pt; font-family: Arial }
.titrenorm { font-size: 14 pt; font-family: Arial; font-weight: bold }
.textearticle { color: #333333; font-family: Arial, Verdana,Helvetica, sans-serif; font-size:
9pt; font-style: normal; line-height: 13pt; text-decoration:
none; margin-top: 6pt }
.textecourant { font-family:Verdana, Arial; font-size: 9pt }
.textenormal { font-family: Arial; font-size: 9pt }
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" class=textenormal>
<tr>
<td><b>Ajouter une publicité</b></td>
</tr>
<tr>
<td>
<p><font color=red>Aperçu :<br>
</font></p>
<? if ($typ_tag=="1") {
echo $tag_text;
} else {
if ($xname!="") {
echo "<a href=$url_lien><img src=".$cfg_upload_web.$xname." border=0></a>";
}
} ?>
<br><font color=red>
<? echo $msg; ?></font>
<form action="add_pub.php" Method="POST" ENCTYPE="multipart/form-data">
<table width="100%" border="0" class=textenormal>
<tr>
<td><b>Titre</b><br>
<input type="text" name="titre" value="<? echo $titre; ?>">
</td>
<td> </td>
</tr>
<tr>
<td><b>Campagne :</b><br>
<select name="id_campagne" >
<option value="0" >-----------------</option>
<? $sql = "SELECT * from pub_campagne ORDER by nom_campagne";
if ($p = @mysql_query($sql,$connpub)){
while ($rs = @mysql_fetch_array($p)){
?>
<option value="<? echo $rs["id_campagne"]; ?>" <? if ($rs["id_campagne"]==$id_campagne) { echo "selected";} ?>><? echo $rs["nom_campagne"]; ?></option>
<?
}
}
?>
</select>
<br>
</td>
<td><b>Groupe :<br>
<select name="id_groupe" >
<option value="0" >-----------------</option>
<? $sql = "SELECT * from pub_groupe ORDER by nom_groupe";
if ($p = @mysql_query($sql,$connpub)){
while ($rs = @mysql_fetch_array($p)){
?>
<option value="<? echo $rs["id_groupe"]; ?>" <? if ($rs["id_groupe"]==$id_groupe) { echo "selected";} ?>>
<? echo $rs["nom_groupe"]; ?>
</option>
<?
}
}
?>
</select>
</b></td>
</tr>
<tr>
<td>
<input type="radio" name="typ_tag" value="1" <? if ($typ_tag=="1") { echo "checked"; } ?>>
<b> Publicité textuelle, javascript, flash ...</b><br>
<textarea name="tag_text" cols="50" rows="5"><? echo $tag_text ?></textarea>
</td>
<td> </td>
</tr>
<tr>
<td>
<input type="radio" name="typ_tag" value="0" <? if ($typ_tag=="0") { echo "checked"; } ?>>
<b>Publicité classique (url + img)</b><br>
</td>
<td> </td>
</tr>
<tr>
<td>
<p>Lien :<br>
<input type="text" name="url_lien" value="<? echo $url_lien ?>">
</p>
<p>Image :<br>
<input type="file" name="x_fichier1" >
<br>
</p>
</td>
<td> </td>
</tr>
<tr>
<td> <b>Pourcentage d'affichage :</b><br>
<input type="checkbox" name="auto" value="auto" <? if ($auto!="") { echo "checked";}?>>
Automatique (gestion auto des pourcentages)<br>
<input type="text" name="pourcent" value="<? echo $pourcent ?>">
</td>
<td> </td>
</tr>
<tr>
<td>
<b>Informations de démarrage :</b>
<table width="100%" border="0" class=textenormal>
<tr>
<td>
<div align="center">Date de début</div>
</td>
<td>
<div align="center">Nombre d'affichage</div>
</td>
<td>
<div align="center">Nombre de clicks</div>
</td>
<td>
<div align="center">Nombres de clicks uniques</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type="text" name="datedebut" value="<? echo date($datedebut,"d/m/Y") ?>">
</div>
</td>
<td>
<div align="center">
<input type="text" name="nbvu" value="<? echo $nbvu ?>">
</div>
</td>
<td>
<div align="center">
<input type="text" name="nbclick" value="<? echo $nbclick ?>">
</div>
</td>
<td>
<div align="center">
<input type="text" name="unbclick" value="<? echo $unbclick ?>">
</div>
</td>
</tr>
</table>
</td>
<td> </td>
</tr>
<tr>
<td><b>Type d'expiration :</b><br>
<table width="100%" border="0" class=textenormal>
<tr>
<td>
<input type="radio" name="R1" value="0" <? if ($R1=="0") {echo "checked";}?>>
Expire à la date de fin suivante</td>
<td>
<input type="text" name="datefin" value="<? echo $datefin ?>">
</td>
</tr>
<tr>
<td>
<input type="radio" name="R1" value="1" <? if ($R1=="1") {echo "checked";}?>>
Expire après avoir affichée</td>
<td>
<input type="text" name="vumax" value="<? echo $vumax ?>">
</td>
</tr>
<tr>
<td>
<input type="radio" name="R1" value="2" <? if ($R1=="2") {echo "checked";}?>>
Expire avoir été clickée (unique)</td>
<td>
<input type="text" name="uclickmax" value="<? echo $uclickmax ?>">
</td>
</tr>
<tr>
<td>
<input type="radio" name="R1" value="3" <? if ($R1=="3") {echo "checked";}?>>
Expire après avoir été clickée</td>
<td>
<input type="text" name="clickmax" value="<? echo $clickmax ?>">
</td>
</tr>
</table>
</td>
<td> </td>
</tr>
</table>
<p> </p>
<p>
<input type="submit" name="action" value="Aperçu">
<input type="submit" name="action" value="Valider">
</p>
</form>
<p> </p>
</td>
</tr>
</table>
</body>
</html>
<?
@mysql_close($connpub);
?>
et le bout de fichiers que je vous est donné au prélable:
<?
// Expliquation du fonctionnement de ce fichier
// http://www.asp-magazine.com/fr/php/exemples/myphppub.asp
// paramètres de connexion à la base de données
$connpub = @mysql_connect("xxxx","xxxx","xxxx") or die("Erreur de connection au serveur Mysql, vérifiez vos paramètres login et password");
@mysql_select_db("xxxx",$connpub) or die("selection impossible");
// Fonction utilisée pour l'affichage des dates
function ddateMySql($aDate, $l){
list($annee,$mois,$jour) = explode("-",$aDate);
if ($l==1) {
return "$jour/$mois/$annee";
} else {
return "$jour/$mois";
}
}
// *************************************
// paramètre des répertoires d'upload
// *************************************
// Répertoire temporaire d'upload des images
// Ce répertoire doit être ouvert en écriture
// Adresse physique du répertoire par ex. /home/user/wwww/pi_pub/temp/
$cfg_upload_path="C:/Documents and Settings/ludovic/Bureau/infohosp2.3/docs/pi_pub/";
// Adresse mappée Internet : par ex. /pi_pub/temp/
$cfg_upload_web="docs/pi_pub/";
// Répertoire destination final des upload d'image
// Ce répertoire doit être ouvert en écriture
// Adresse physique du répertoire par ex. /home/user/wwww/pubs/
$cfg_final_path="c:/Documents and Settings/ludovic/Bureau/infohosp2.3/docs/pubs";
// Adresse mappée Internet : par ex. /pubs/
$cfg_final_web="docs/pubs";
?>
merci