Plugins  LAST
 All Data Structures Files Functions Variables Pages
Static Public Member Functions
Formulaire_Param Class Reference

manage the table rapport_avance.formulaire_param More...

Inheritance diagram for Formulaire_Param:
Inheritance graph
Collaboration diagram for Formulaire_Param:
Collaboration graph

Static Public Member Functions

static factory (Formulaire_Param_Sql $form)
 Factory, create an object following the $form->p_type,. More...
 
static to_csv ($p_id)
 export a form to CSV to stdout type $cn database connx More...
 
static from_csv ($filename)
 

Detailed Description

manage the table rapport_avance.formulaire_param

Definition at line 35 of file class_formulaire_param.php.

Member Function Documentation

static Formulaire_Param::factory ( Formulaire_Param_Sql  $form)
static

Factory, create an object following the $form->p_type,.

Parameters
Formulaire_Param_Sql$form
Returns
Formulaire_Title1| Formulaire_Title2| Formulaire_Title3| Formulaire_Formula

Definition at line 43 of file class_formulaire_param.php.

Referenced by RAPAV_Formulaire\input_parameter().

44  {
45  switch ($form->p_type)
46  {
47  case 1:
48  return new Formulaire_Title1($form);
49  case 2:
50  return new Formulaire_Title2($form);
51  case 6:
52  return new Formulaire_Title3($form);
53  case 3:
54  return new Formulaire_Formula($form);
55  case 7:
56  return new Formulaire_Text($form);
57  case 8:
58  return new Formulaire_Notice($form);
59  case 9:
60  return new Formulaire_Child($form);
61  }
62  }
display the formula : depending of the type of formula, a factory is used and an object RAPAV_Formula...
static Formulaire_Param::from_csv (   $filename)
static

Update now the table rapport_advanced.restore_formulaire_param and set the correct pk $cn->exec_sql("update rapport_advanced.restore_formulaire_param set p_id=nextval('rapport_advanced.formulaire_param_p_id_seq')");

Definition at line 100 of file class_formulaire_param.php.

References $a, $array, $cn, $form, and $rapav_version.

101  {
102  global $cn;
103  $in = fopen($filename, "r");
104  $cn->start();
105  try
106  {
107  $a = fgetcsv($in, 0, ";");
108  if ($a[0] != "RAPAV")
109  {
110  throw new Exception('Formulaire invalide');
111  }
112  // $a[1] contains the version
113  $rapav_version=$a[1];
114  // first line is the title and description
115  $form = new formulaire_sql();
116  $first = fgetcsv($in, 0, ";");
117  $form->f_title = $first[0];
118  if (isset($first[1]))
119  $form->f_description = $first[1];
120  $form->insert();
121  // now come the formulaire_param until the keyword RAPAV_DETAIL is met
122  while (($csv = fgetcsv($in, 0, ";")) != FALSE)
123  {
124  if ($csv[0] != "RAPAV_DETAIL")
125  {
126  if ( $rapav_version == 2 ) {
127  unset($csv[6]);
128  }
129  $csv[5]=$form->f_id;
130  $cn->get_array("INSERT INTO rapport_advanced.restore_formulaire_param(
131  p_id, p_code, p_libelle, p_type, p_order, f_id, t_id)
132  VALUES ($1, $2, $3, $4, $5, $6, $7)", $csv);
133  } else
134  break;
135  }
136  while (($csv = fgetcsv($in, 0, ";")) != FALSE)
137  {
138  $t = array();
139  for ($o = 0; $o < count($csv); $o++)
140  {
141  if ($csv[$o] == "")
142  $t[$o] = null;
143  else
144  {
145  $t[$o] = $csv[$o];
146  }
147  }
148  if ($rapav_version < 4 )
149  {
150  $t[12]=0;
151  }
152  $cn->get_array("INSERT INTO rapport_advanced.restore_formulaire_param_detail(
153  fp_id, p_id, tmp_val, tva_id, fp_formula, fp_signed, jrn_def_type,
154  tt_id, type_detail, with_tmp_val, type_sum_account, operation_pcm_val,date_paid)
155  VALUES ($1, $2, $3, $4, $5, $6, $7,$8, $9, $10, $11, $12,$13)", $t);
156  }
157  /// Update now the table rapport_advanced.restore_formulaire_param and set the correct pk
158  /// $cn->exec_sql("update rapport_advanced.restore_formulaire_param set p_id=nextval('rapport_advanced.formulaire_param_p_id_seq')");
159 
160  // Insert row by row + detail
161  $array=$cn->get_array("select p_id,p_code,p_libelle,p_order,f_id,t_id from rapport_advanced.restore_formulaire_param where f_id=$1",array($form->f_id));
162  // Prepare stmt for the details
163  $cn->prepare('detail','select p_id,tmp_val,tva_id,fp_formula,fp_signed, jrn_def_type,tt_id,type_detail,with_tmp_val,type_sum_account,operation_pcm_val,date_paid
164  from rapport_advanced.restore_formulaire_param_detail where p_id=$1');
165  $nb=count($array);
166  for ($e=0;$e<$nb;$e++)
167  {
168  // Insert first into rapport_advanced.formulaire_param
169  $new_pid=$cn->get_value("insert into rapport_advanced.formulaire_param (p_code, p_libelle, p_type, p_order, f_id, t_id)
170  select p_code, p_libelle, p_type, p_order, f_id, t_id
171  from rapport_advanced.restore_formulaire_param where p_id=$1 returning p_id",array($array[$e]['p_id']));
172  // Insert detail
173  $cn->exec_sql("insert into rapport_advanced.formulaire_param_detail
174  (fp_id,
175  p_id,
176  tmp_val,
177  tva_id,
178  fp_formula,
179  fp_signed,
180  jrn_def_type,
181  tt_id,
182  type_detail,
183  with_tmp_val,
184  type_sum_account,
185  operation_pcm_val,
186  jrn_def_id,
187  date_paid
188  )
189  select
190  nextval('rapport_advanced.formulaire_param_detail_fp_id_seq'),
191  $new_pid,
192  tmp_val,
193  tva_id,
194  fp_formula,
195  fp_signed,
196  jrn_def_type,
197  tt_id,
198  type_detail,
199  with_tmp_val,
200  type_sum_account,
201  operation_pcm_val,
202  -1,
203  date_paid
204  from
205  rapport_advanced.restore_formulaire_param_detail where p_id =$1
206  ",array($array[$e]['p_id']));
207  }
208 
209 
210  $cn->exec_sql('delete from rapport_advanced.restore_formulaire_param where f_id=$1',array($form->f_id));
211  $cn->commit();
212  }
213  catch (Exception $exc)
214  {
215  echo $exc->getMessage();
216  error_log($exc->getMessage());
217  error_log($exc->getTraceAsString());
218  throw $exc;
219  }
220  }
global $rapav_version
if(isset($_POST['remove'])) $array
global $cn
static Formulaire_Param::to_csv (   $p_id)
static

export a form to CSV to stdout type $cn database connx

Parameters
type$p_idthe formulaire.f_id

Definition at line 69 of file class_formulaire_param.php.

References $array, $cn, $form, and $title.

70  {
71  global $cn;
72  $form = new formulaire_sql($p_id);
73  $form->load();
74  $title = mb_strtolower($form->f_title, 'UTF-8');
75  $title = str_replace(array('/', '*', '<', '>', '*', '.', '+', ':', '?', '!', " ", ";"), "_", $title);
76 
77  $out = fopen("php://output", "w");
78  header('Pragma: public');
79  header('Content-type: application/bin');
80  header('Content-Disposition: attachment;filename="' . $title . '.bin"', FALSE);
81  fputcsv($out, array("RAPAV", '4'), ";");
82  fputcsv($out, array($form->f_title, $form->f_description), ";");
83  $array = $cn->get_array("select p_id,p_code, p_libelle, p_type, p_order, f_id, t_id
84  from rapport_advanced.formulaire_param where f_id=$1", array($p_id));
85  for ($i = 0; $i < count($array); $i++)
86  {
87  fputcsv($out, $array[$i], ";");
88  }
89  fputcsv($out, array('RAPAV_DETAIL'), ";");
90  $array = $cn->get_array("select
91  fp_id, p_id, tmp_val, tva_id, fp_formula, fp_signed, jrn_def_type,
92  tt_id, type_detail, with_tmp_val, type_sum_account, operation_pcm_val,date_paid
93  from rapport_advanced.formulaire_param_detail where p_id in (select p_id from rapport_advanced.formulaire_param where f_id=$1)", array($p_id));
94  for ($i = 0; $i < count($array); $i++)
95  {
96  fputcsv($out, $array[$i], ";");
97  }
98  }
if(isset($_POST['remove'])) $array
global $cn

The documentation for this class was generated from the following file: