Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / plugins / anet_epacks / front / plugin_anet_epacks.generate_odt_revendeur2.form.php @ 97e94661

Historique | Voir | Annoter | Télécharger (2,73 ko)

1
<?php
2

    
3
// Génère le fichier ODT/PDF pour le revendeur avec son numéro de pack à utiliser. Ce fichier doit contenir un certain nombre d'informations (url pour enregistrer son pack etc.)
4

    
5
if(!defined('GLPI_ROOT')){
6
  define('GLPI_ROOT', '../../..');
7
}
8
include_once (GLPI_ROOT . "/inc/includes.php");
9
include_once("tools.php");
10

    
11
//checkSeveralRightsOr(array("config" => "w", "profile" => "w"));
12
checkRight("config","w");
13

    
14
require_once('lib/odf.php');
15
$odf = new odf("abuledu-epack.odt");
16
//$odf->exportAsAttachedFile();
17
//$odf->printVars();
18
//print_r($odf);
19
//$odf->saveToDisk('tmp/fichier.odt');
20

    
21
global $DB;
22

    
23
//Un pack non attribué
24
$query="SELECT * FROM glpi_plugin_anet_epacks WHERE FK_clientderyxeo='0' AND creation_date='0000-00-00' AND code LIKE 'RVD11%' LIMIT 1;";
25
//$DB->query($query) or die($DB->error());
26
$result = $DB->query($query);
27
$data=$DB->fetch_array($result);
28

    
29
if($data['code'] == "") {
30
  print "Erreur, il n'y a plus de pack disponible ... ";
31
  print "On vient d'en créer un nouveau, actualisez la page pour l'utiliser ...";
32
  $nb_packs = 1;
33
  $prefix = "RVD11-01-";
34
  for($i = 0; $i < $nb_packs; $i++) {
35
    srand();
36
    $code=$prefix . rand(1000,9999) . "-" . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)) . "-" . rand(1000,9999);
37
    $password=rand(1000,9999) . "-" . rand(1000,9999);
38
    $query="INSERT into glpi_plugin_anet_epacks(creation_date,expiration_date,code,password) values( '0000-00-00' ,'2011-12-31','$code','$password');";
39
    print $query;
40
    $DB->query($query);// or die($DB->error());
41
  }
42
  exit;
43
}
44

    
45
$odf->setVars('code', $data['code']);
46
$odf->setVars('password', $data['password']);
47

    
48

    
49
setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8'); 
50
$odf->setVars('date', strftime("%A %e %B %Y"), true, 'UTF-8');
51

    
52
//Les coordonnées du client
53
$fk_entitee = $_POST['FK_entitee'];
54

    
55
$query2="SELECT * FROM glpi_entities, glpi_entities_data WHERE glpi_entities.ID=FK_entities AND glpi_entities.ID='$fk_entitee';";
56
//$DB->query($query2) or die($DB->error());
57
$result2 = $DB->query($query2);
58
$data2=$DB->fetch_array($result2);
59

    
60
$odf->setVars('correspondant', $data2['name'], true, 'UTF-8');
61
$odf->setVars('adresse', $data2['address'], true, 'UTF-8');
62
$odf->setVars('cp', $data2['postcode']);
63
$odf->setVars('ville', $data2['town'], true, 'UTF-8');
64

    
65
//On "grille" le epack pour eviter de l'affecter a qqn d'autre
66
$query3="UPDATE glpi_plugin_anet_epacks set FK_clientderyxeo='$fk_entitee',creation_date='" . date("Y-m-d") . "' WHERE ID='" . $data['ID'] . "';";
67
$DB->query($query3) or die($DB->error());
68

    
69
//On créé un fichier local pour archive ...
70
$fichier="archives/" . date("Ymd") . "-" . $data['code'] . ".odt";
71
$odf->saveToDisk($fichier);
72

    
73
pushfile($fichier);
74

    
75
//On génère le fichier
76
//$odf->exportAsAttachedFile();
77

    
78
?>
Redmine Appliance - Powered by TurnKey Linux