panier.module
<?php
// $Id: panier.module,v 1.113.2.70.2.73 2008/10/14 21:51:45 quicksketch Exp $
/**
* Implementation of hook_perm().
*/
function panier_perm() {
return array('Panier Inereach');
}
/**
* Implementation of hook_menu().
*/
function panier_menu($section = "admin/menu#panier") {
$items = array();
$item[] = array(
'path' => 'panier/listing',
'title' => t('Panier inereach'),
'description' => t('Panier Inereach'),
'callback' => 'visu_panier_form', //nom de la fonction de creation
'access' => user_access('Panier Inereach'),
'type' => MENU_CALLBACK
);
return $item;
}
function visu_panier_form() {
$html .=drupal_get_form(panier_form);
return $html;
}
/**
* Implementation of hook_form().
*/
function panier_form() {
$form = array();
//recuperer l'id client de la session
$id_prosclt = ;
$resultat = db_query("SELECT *
FROM inereach_panier
WHERE inereach_panier.id_prosclt = '".$id_prosclt."'
");
$i = 0;
while($row = db_fetch_array($resultat))
{
$form[$i]['cas'] = array(
'#type'=> 'textfield',
'#title'=> 'CAS',
'#description'=> t("Numérom CAS"),
'#attributes' => array('readonly' => 'readonly'),
'#value'=> t($row['cas']),
);
$form[$i]['fiche'] = array(
'#type'=> 'textfield',
'#title'=> 'Fiche',
'#description'=> t("Nom de la fiche"),
'#attributes' => array('readonly' => 'readonly'),
'#value'=> t($row['fiche']),
);
$form[$i]['date'] = array(
'#type'=> 'textfield',
'#title'=> 'Date',
'#description'=> t("Date d'ajout"),
'#attributes' => array('readonly' => 'readonly'),
'#value'=> t($row['date']),
);
$form[$i]['suppr'] = array(
'#type'=> 'submit',
'#value'=> t("Supprimer"),
);
$form[$i]['submit'] = array(
'#type'=> 'submit',
'#value'=> t("Acheter"),
);
$i++;
}
return $form;
}
/**
* Implementation of hook_submit().
*/
function inscription_form_submit($form_id, $form_values) {
$resultat = db_query("SELECT *
FROM inereach_panier
WHERE inereach_panier.id_prosclt = '".$id_prosclt."'
");
$cpt = 0;
while($row = db_fetch_array($resultat))
{
if(isset($form_values[$i]['submit'])) {
//recuperer le nombre de fiches que le client peut acheter
$provision = db_query("SELECT provision
FROM inereach_prosclt
WHERE inereach_prosclt.id_prosclt = '".$id_prosclt."'
");
if($provision > 0){
db_query("INSERT INTO inereach_suivi(
id_prosclt,
cas,
fiche,
date
)
VALUES(
'".$id_prosclt."',
'".$form_values[$i]['cas']."',
'".$form_values[$i]['fiche']."',
'".$form_values[$i]['date']."'
)"
);
db_query("DELETE FROM inereach_panier
WHERE inereach_panier.id_prosclt = '".$id_prosclt."'
AND inereach_panier.cas = '".$form_values[$i]['cas']."'
");
drupal_set_message('Fiche commandée.');
else drupal_set_message('Vous ne pouvez plus acheter de fiches, veuillez nous contacter pour réapprovisionner votre compte.');
}
if(isset($form_values[$i]['suppr'])) {
db_query("DELETE FROM inereach_panier
WHERE inereach_panier.cas = '".$form_values[$i]['cas']."'
");
drupal_set_message('Fiche supprimée.');
}
}
$chemin = "panier/listing";
return $chemin;
}