Go to the documentation of this file.00001 <?php
00002 require_once ('class_icard.php');
00003 require_once('class_ifile.php');
00004 require_once('class_database.php');
00005 require_once('class_iselect.php');
00006 require_once('class_dossier.php');
00007 require_once('class_fiche.php');
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 $cn=new Database(dossier::id());
00019
00020
00021
00022
00023
00024
00025
00026
00027 echo '<form METHOD="get" action="extension.php">';
00028 echo dossier::hidden();
00029
00030 echo HtmlInput::extension();
00031
00032 echo "Choix de la catégorie de fiche";
00033 $select_cat=new ISelect('fd_id');
00034 $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
00035 FICHE_TYPE_CLIENT);
00036 echo $select_cat->input();
00037 echo HtmlInput::submit('display_prop','Afficher les propriétés');
00038
00039 echo '</FORM>';
00040
00041
00042
00043 if ( isset($_GET['display_prop'])){
00044 $a=new Fiche($cn);
00045 $prop=$a->to_array($_GET['fd_id']);
00046 foreach ($prop as $key=>$value) echo "Index : $key valeur $value <br/>";
00047
00048 echo '<form method="POST" action="extension.php" enctype="multipart/form-data">';
00049 echo dossier::hidden();
00050 echo HtmlInput::extension();
00051 echo HtmlInput::hidden('fd_id',$_GET['fd_id']);
00052 $file=new IFile('fichier_csv');
00053 echo $file->input();
00054 echo HtmlInput::submit('start_import','Démarrez importation');
00055 echo '</form>';
00056 exit;
00057 }
00058
00059
00060
00061
00062
00063 if ( isset($_POST['start_import'])){
00064 $fd_id=$_POST['fd_id'];
00065 $tmp_file=$_FILES['fichier_csv']['tmp_name'];
00066 if ( ! is_uploaded_file($tmp_file))
00067 die ('Je ne peux charger ce fichier');
00068
00069 $f=fopen($tmp_file,'r');
00070
00071 $client=new Fiche($cn);
00072
00073 $array=$client->to_array($_POST['fd_id']);
00074
00075 while ( ($data=fgetcsv($f))==true) {
00076
00077
00078
00079 foreach(array_keys($array) as $key) $array[$key]="";
00080
00081
00082 $array['av_text1']=$data[0].' '.$data[1];
00083
00084 $array['av_text30']=$data[2];
00085
00086 $array['av_text14']=$data[3];
00087
00088 $array['av_text23']="CLI".$data[2];
00089 $client->insert($fd_id,$array);
00090 }
00091 exit;
00092 }
00093
00094 ?>
00095
00096 Voici le fichier plugin_client.txt (dans le répertoire dev)
00097 "Nom client1","Prénom","C1","Rue de la boite,55"
00098 "Nom client2","Prénom","C2","Rue du couvercle,55"
00099 "Nom client3","Prénom","C3","Rue de la chaussure,55"
00100 "Nom client4","Prénom","C4","Rue de la couleur,55"
00101
00102 Si vous vérifiez dans VW_CLIENT, vous verrez que toutes vos fiches ont été ajoutées. Dans l'exemple, il faudra rajouter un traitement d'erreur plus élaborée, le fait que si une fiche echoue , l'opération est annulée (Database::rollback) ou alors création d'un fichier avec les enregistrements "ratés"...
00103
00104