Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_install_plugin.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 /* $Revision$ */
21 
22 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
23 
24 /**\file
25  * \brief this class manages the installation and the patch of the plugin
26  */
27 define ('ATTR_IMMEUBLE',5000);
28 define ('ATTR_COPROP',5001);
29 
30 class Install_Plugin
31 {
32 
33  function __construct($p_cn)
34  {
35  $this->cn = $p_cn;
36  }
37 
38  /**
39  * @brief install the plugin, create all the needed schema, tables, proc
40  * in the database
41  * @param $p_dossier is the dossier id
42  */
43  function install()
44  {
45  $this->cn->start();
46  // create the schema
47  $this->create_schema();
48 
49  // create table + put default values
50  $this->create_card();
51 
52  $this->create_table_parameter();
53 
54  $this->create_table();
55 
56  $this->cn->commit();
57  }
58 
59  function create_schema()
60  {
61  $this->cn->exec_sql('create schema coprop');
62  $this->cn->exec_sql("create sequence coprop.appel_fond_id");
63  }
64 
65  function create_card()
66  {
67  // create categorie immeuble, lot et coprop.
68  $fiche_def = new Fiche_Def($this->cn);
69 
70  // Create categorie pour lot immeuble et coprop + attribut
71  $fiche_def->add(array(
72  'FICHE_REF' => 9,
73  'nom_mod' => 'Copropriétaires - plugin',
74  'fd_description'=>'Liste des copropriétaires, catégorie créée par le plugin copropriété',
75  'class_base' => null)
76  );
77  $copro = $fiche_def->id;
78  $lot_def = new Fiche_Def($this->cn);
79 
80  $lot_def->add(array(
81  'FICHE_REF' => 15,
82  'nom_mod' => 'Lots - plugin',
83  'fd_description'=>'Liste des lots, catégorie créée par le plugin copropriété',
84  'class_base' => null)
85  );
86  $lot = $lot_def->id;
87 
88  $imm_def = new Fiche_Def($this->cn);
89  $imm_def->add(array(
90  'FICHE_REF' => 15,
91  'nom_mod' => 'immeuble - plugin',
92  'fd_description'=>'Liste des immeubles, catégorie créée par le plugin copropriété',
93  'class_base' => null)
94  );
95  $immeuble = $imm_def->id;
96 
97  // creation attribut
98  $this->cn->exec_sql("insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_extra)
99  values (".ATTR_COPROP.",'Copropriétaire','select','22','select f_id,vw_name from vw_fiche_attr where fd_id = $copro ')");
100  $this->cn->exec_sql("insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_extra) values
101  (".ATTR_IMMEUBLE.",'Immeuble','select','22','select f_id,vw_name from vw_fiche_attr where fd_id = $immeuble ');");
102 
103  $lot_def->InsertAttribut(ATTR_COPROP); // lien vers coprop
104  $lot_def->InsertAttribut(ATTR_IMMEUBLE);// lien vers immeuble
105 
106  $imm_def->InsertAttribut(14); // adresse
107  $imm_def->InsertAttribut(15); // code postale
108  $imm_def->InsertAttribut(24); //ville
109  $imm_def->InsertAttribut(16); // pays
110 
111  $fiche_def->InsertAttribut(27); // gsm
112  $fiche_def->InsertAttribut(32); // prénom
113  $fiche_def->InsertAttribut(10); // date début
114  $fiche_def->InsertAttribut(33); // date fin
115  //
116  // creation vue (create_view_summary)
117  $this->cn->exec_sql("CREATE OR REPLACE VIEW coprop.summary AS
118  SELECT a.f_id AS lot_id, m.ad_value AS building_id, c.ad_value AS coprop_id
119  FROM fiche_detail a
120  JOIN fiche f1 ON f1.f_id = a.f_id
121  JOIN ( SELECT fd1.f_id, fd1.ad_value
122  FROM fiche_detail fd1
123  WHERE fd1.ad_id = ".ATTR_IMMEUBLE.") m ON m.f_id = a.f_id
124  JOIN ( SELECT fd1.f_id, fd1.ad_value
125  FROM fiche_detail fd1
126  WHERE fd1.ad_id = ".ATTR_COPROP.") c ON c.f_id = a.f_id
127  WHERE f1.fd_id = ".$lot." AND a.ad_id = 1");
128  $this->lot_id=$lot;
129  $this->immeuble_id=$immeuble;
130  $this->coprop_id=$copro;
131 
132  }
133 
135  {
136  $sql = <<<EOF
137 CREATE TABLE coprop.parameter
138 (
139  pr_id text NOT NULL,
140  pr_value text,
141  CONSTRAINT copro_parameter_pkey PRIMARY KEY (pr_id)
142  );
143 EOF;
144  $this->cn->exec_sql($sql);
145 // load default value
146  $array = array(
147  'categorie_lot' => $this->lot_id,
148  'categorie_coprop' => $this->coprop_id,
149  'categorie_immeuble' => $this->immeuble_id,
150  'categorie_appel' => 0,
151  'poste_appel' => 0,
152  'categorie_charge'=>0,
153  'journal_appel' => 0
154  );
155 
156  foreach ($array as $code => $value)
157  {
158  $this->cn->exec_sql('insert into coprop.parameter(pr_id,pr_value) values ($1,$2)', array($code, $value));
159  }
160  }
161  function create_table()
162  {
163 
164  $file=dirname(__FILE__)."/../sql/create_table.sql";
165  $this->cn->execute_script($file);
166 
167  }
168  function upgrade()
169  {
170  global $cn;
171  $version=$cn->get_value('select max(v_id) from coprop.version');
172  for ($i=$version+1;$i<=COPROP_VERSION;$i++)
173  {
174  $file=dirname(__FILE__)."/../sql/upgrade$i.sql";
175  $this->cn->execute_script($file);
176  }
177  }
178 
179 }
const COPROP_VERSION
const ATTR_IMMEUBLE
install()
install the plugin, create all the needed schema, tables, proc in the database
if(isset($_POST['remove'])) $array
$version
Definition: index.php:89
const ATTR_COPROP
$lot
Definition: lot.inc.php:69
$sql
$file
Definition: import_bank.php:60
global $cn