00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 require_once 'class_anc_key_sql.php';
00029
00030 class Anc_Key
00031 {
00032
00033 private $key;
00034
00035
00036
00037
00038
00039
00040
00041
00042 static function key_avaiable($p_jrn)
00043 {
00044 global $cn;
00045 $count=$cn->get_value (' select count(*)
00046 from key_distribution_ledger
00047 join key_distribution using (kd_id)
00048 where
00049 jrn_def_id=$1', array($p_jrn));
00050 return $count;
00051 }
00052 function __construct($p_id=-1)
00053 {
00054 global $cn;
00055 $this->key=new Anc_Key_SQL($cn, $p_id);
00056 $this->a_ledger=null;
00057 $this->a_activity=null;
00058 $this->a_row=null;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 static function display_choice($p_amount, $p_target,$p_ledger)
00068 {
00069 global $cn;
00070 $a_key=$cn->get_array(' select kd_id,
00071 kd_name,
00072 kd_description
00073 from
00074 key_distribution
00075 join key_distribution_ledger using (kd_id)
00076 where
00077 jrn_def_id=$1',
00078 array(
00079 $p_ledger
00080 ));
00081 if (empty($a_key))
00082 {
00083 echo _('Aucune clef disponible');
00084 echo _('Allez dans ANCKEY pour en ajouter pour ce journal');
00085 }
00086 include 'template/anc_key_display_choice.php';
00087 }
00088
00089
00090
00091
00092
00093 static function display_list()
00094 {
00095 global $cn;
00096 $a_key=$cn->get_array('select b.kd_id,b.kd_name,b.kd_description,
00097 (select sum(ke_percent) from key_distribution_detail as a where a.kd_id=b.kd_id) as distrib
00098 from key_distribution as b order by b.kd_name');
00099 if (empty($a_key))
00100 {
00101 echo _('Aucune clef disponible');
00102 }
00103 include 'template/anc_key_display_list.php';
00104 }
00105
00106
00107
00108
00109
00110 function input()
00111 {
00112 global $cn;
00113
00114 $plan=$cn->get_array('
00115 select
00116 pa_id,
00117 pa_name ,
00118 pa_description
00119 from
00120 plan_analytique
00121 order by pa_name');
00122 $count_max=count($plan);
00123
00124 $a_row=$cn->get_array('select ke_id,ke_row,ke_percent from key_distribution_detail
00125 where
00126 kd_id=$1 order by ke_row', array($this->key->getp('id')));
00127
00128 require_once 'template/anc_key_input.php';
00129 }
00130
00131
00132
00133
00134
00135 function verify($p_array)
00136 {
00137 $a_percent=$p_array['percent'];
00138 if (count($a_percent)==0)
00139 {
00140 throw Exception(_('Aucune répartition'));
00141 }
00142 $tot_percent=0;
00143 bcscale(4);
00144 for ($i=0; $i<count($a_percent); $i++)
00145 {
00146 $tot_percent=bcadd($tot_percent, $a_percent[$i]);
00147 }
00148 if ($tot_percent >100)
00149 {
00150 throw new Exception(_('Le total ne vaut pas 100, total calculé = ').$tot_percent);
00151 }
00152 if ($p_array['name_key']=='') {
00153 throw new Exception (_('Le nom ne peut être vide'));
00154 }
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 function save($p_array)
00210 {
00211 global $cn;
00212 $this->verify($p_array);
00213 $cn->start();
00214
00215 $a_row=$p_array['row'];
00216 $a_ledger=HtmlInput::default_value("jrn",array(),$p_array);
00217 $a_percent=$p_array['percent'];
00218 $a_po_id=$p_array['po_id'];
00219 $a_plan=$p_array['pa'];
00220 try
00221 {
00222 $this->key->setp('name',$p_array['name_key']);
00223 $this->key->setp('description',$p_array['description_key']);
00224 $this->key->save();
00225 for ($i=0; $i<count($a_row); $i++)
00226 {
00227
00228 $key_row=new Anc_Key_Detail_SQL($cn);
00229 $key_row->setp('id', $a_row[$i]);
00230 $key_row->setp('key', $this->key->getp('id'));
00231 $key_row->setp('row', $i+1);
00232 $key_row->setp('percent', $a_percent[$i]);
00233 $key_row->save();
00234
00235
00236 $cn->exec_sql('delete from key_distribution_activity where ke_id=$1', array($key_row->getp('id')));
00237
00238
00239 if ($a_percent[$i]==0)
00240 {
00241 $key_row->delete();
00242 continue;
00243 }
00244 for ($j=0; $j<count($a_po_id[$i]); $j++)
00245 {
00246 $activity=new Anc_Key_Activity_SQL($cn);
00247 $activity->setp('detail', $key_row->ke_id);
00248 $value=($a_po_id[$i][$j]==-1)?null:$a_po_id[$i][$j];
00249 $activity->setp('activity', $value);
00250 $activity->setp('plan',$a_plan[$j]);
00251 $activity->save();
00252 }
00253 }
00254
00255 $cn->exec_sql('delete from key_distribution_ledger where kd_id=$1', array($this->key->getp('id')));
00256 for ($k=0; $k<count($a_ledger); $k++)
00257 {
00258 $ledger=new Anc_Key_Ledger_SQL($cn);
00259 $ledger->kd_id=$this->key->getp('id');
00260 $ledger->jrn_def_id=$a_ledger[$k];
00261 $ledger->save();
00262 }
00263
00264 $cn->commit();
00265 }
00266 catch (Exception $e)
00267 {
00268 if ( DEBUG ) { echo $e->getTraceAsString(); var_dump($_POST);} else { echo _('erreur');}
00269 $cn->rollback();
00270 }
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 function fill_table($p_target,$p_amount)
00282 {
00283 global $cn;
00284
00285 $number=preg_replace('/det[0-9]/', '', $p_target);
00286 $number=str_replace('t', '', $number);
00287 $number=str_replace('popup', '', $number);
00288
00289 $op[$number]=$p_amount;
00290 $array['op']=$op;
00291 $a_plan=$cn->get_array('select pa_id from plan_analytique order by pa_id');
00292 for ($i=0;$i < count($a_plan);$i++)
00293 {
00294 $array['pa_id'][$i]=$a_plan[$i]['pa_id'];
00295 }
00296
00297 $a_poste=$cn->get_array('select po_id,ke_percent,pa_id,ke_row
00298 from key_distribution_activity
00299 join key_distribution_detail using (ke_id)
00300 where
00301 kd_id=$1
00302 order by ke_row,pa_id',
00303 array($this->key->getp('id')));
00304
00305 for ($i=0;$i< count($a_poste);$i++)
00306 {
00307 $hplan[$number][$i]=($a_poste[$i]['po_id']==null)?-1:$a_poste[$i]['po_id'];
00308 }
00309 $array['hplan']=$hplan;
00310
00311 $a_amount=$cn->get_array("select distinct ke_row,ke_percent
00312 from key_distribution_activity
00313 join key_distribution_detail using (ke_id)
00314 where
00315 kd_id=$1
00316 and pa_id=$2
00317 order by ke_row",
00318 array($this->key->getp('id'),$a_plan[0]['pa_id']));
00319 bcscale(2);
00320 for ($i=0;$i< count($a_amount);$i++)
00321 {
00322 $val[$number][$i]=bcmul($p_amount,$a_amount[$i]['ke_percent'])/100;
00323 }
00324 $array['val']=$val;
00325
00326 $anc_operation=new Anc_Operation($cn);
00327 echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount,'',false);
00328
00329 }
00330
00331
00332
00333
00334 static function key_add()
00335 {
00336 $key=new Anc_Key();
00337 $key->key->setp('name',_('Nouvelle clef'));
00338 $key->key->setp('description',_('Description de la nouvelle clef'));
00339 ?>
00340 <input type="button" class="smallbutton" value="<?php echo _('Ajout')?>" onclick="$('key_add_div_id').show()">
00341 <div id="key_add_div_id" style="display: none">
00342 <?php
00343 $key->input();
00344 echo '</div>';
00345
00346 }
00347
00348
00349
00350 function delete ()
00351 {
00352 $this->key->delete();
00353 }
00354 }