00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00022 require_once 'class_profile_sql.php';
00023 global $cn;
00024
00025
00026
00027
00028 if (isset($_POST['change_profile']))
00029 {
00030 extract($_POST);
00031 try
00032 {
00033 for ($e = 0; $e < count($right); $e++)
00034 {
00035 if ($right[$e] == 'X' && $ua_id[$e]=='')
00036 continue;
00037 if ($right[$e] == 'X' && $ua_id[$e]!='')
00038 {
00039 $cn->exec_sql("delete from user_sec_action_profile where p_id=$1 and p_granted=$2", array($p_id, $ap_id[$e]));
00040 continue;
00041 }
00042 if ($ua_id[$e] == "")
00043 {
00044 $cn->exec_sql("insert into user_sec_action_profile (p_id,p_granted,ua_right) values($1,$2,$3)", array($p_id, $ap_id[$e], $right[$e]));
00045 continue;
00046 }
00047 if ($ua_id[$e] != '')
00048 {
00049 $cn->exec_sql("update user_sec_action_profile set ua_right=$3 where p_id=$1 and p_granted=$2 ", array($p_id, $ap_id[$e], $right[$e]));
00050 continue;
00051 }
00052 }
00053 }
00054 catch (Exception $exc)
00055 {
00056 echo $exc->getTraceAsString();
00057 throw $exc;
00058 }
00059 }
00060
00061
00062
00063 if (isset($_POST['change_stock']))
00064 {
00065 extract($_POST);
00066 try
00067 {
00068 for ($e = 0; $e < count($right); $e++)
00069 {
00070 if ($right[$e] == 'X' && $ur_id[$e]=='')
00071 continue;
00072 if ($right[$e] == 'X' && $ur_id[$e]!='')
00073 {
00074 $cn->exec_sql("delete from profile_sec_repository where p_id=$1 and r_id=$2", array($p_id, $ar_id[$e]));
00075 continue;
00076 }
00077 if ($ur_id[$e] == "")
00078 {
00079 $cn->exec_sql("insert into profile_sec_repository (p_id,r_id,ur_right) values($1,$2,$3)", array($p_id, $ar_id[$e], $right[$e]));
00080 continue;
00081 }
00082 if ($ur_id[$e] != '')
00083 {
00084 $cn->exec_sql("update profile_sec_repository set ur_right=$3 where p_id=$1 and r_id=$2 ", array($p_id, $ar_id[$e], $right[$e]));
00085 continue;
00086 }
00087 }
00088 }
00089 catch (Exception $exc)
00090 {
00091 echo $exc->getTraceAsString();
00092 throw $exc;
00093 }
00094 }
00095
00096
00097
00098
00099 if (isset($_POST['save_name']))
00100 {
00101
00102 extract($_POST);
00103 try
00104 {
00105 if (strlen(trim($p_name)) == 0)
00106 throw new Exception("Nom ne peut être vide");
00107 if (isNumber($p_id) == 0)
00108 throw new Exception("profile Invalide");
00109 $wc = (isset($with_calc)) ? 1 : 0;
00110 $wd = (isset($with_direct_form)) ? 1 : 0;
00111 $p_desc = (strlen(trim($p_desc)) == 0) ? null : trim($p_desc);
00112 if ($p_id != -1)
00113 {
00114 $cn->exec_sql("update profile set p_name=$1,p_desc=$2,
00115 with_calc=$3, with_direct_form=$4 where p_id=$5", array($p_name,
00116 $p_desc, $wc, $wd, $p_id));
00117 }
00118 else
00119 {
00120 $p_id = $cn->get_value("insert into profile (p_name,
00121 p_desc,with_calc,with_direct_form) values
00122 ($1,$2,$3,$4) returning p_id", array(
00123 $p_name, $p_desc, $wc, $wd
00124 ));
00125 }
00126 }
00127 catch (Exception $e)
00128 {
00129 alert($e->getMessage());
00130 }
00131 }
00132
00133
00134
00135 if (isset($_POST['clone']))
00136 {
00137 extract($_POST);
00138 try
00139 {
00140 $cn->start();
00141 $new_id = $cn->get_value("insert into profile(p_name,p_desc,with_calc,
00142 with_direct_form)
00143 select 'copie de '||p_name,p_desc,with_calc,
00144 with_direct_form from profile where p_id=$1 returning p_id", array($p_id));
00145 $cn->exec_sql("
00146 insert into profile_menu (p_id,me_code,me_code_dep,p_order,p_type_display,pm_default)
00147 select $1,me_code,me_code_dep,p_order,p_type_display,pm_default from profile_menu
00148 where p_id=$2
00149 ", array($new_id, $p_id));
00150 $cn->commit();
00151 $p_id = $new_id;
00152 }
00153 catch (Exception $exc)
00154 {
00155 echo alert($exc->getMessage());
00156 $cn->rollback();
00157 }
00158 }
00159
00160
00161
00162 if (isset($_POST['delete_profil']))
00163 {
00164 extract($_POST);
00165 try
00166 {
00167 $cn->start();
00168 if ($p_id == 1)
00169 {
00170 throw new Exception('On ne peut pas effacer le profil par défaut');
00171 }
00172 $new_id = $cn->get_value("delete from profile
00173 where p_id=$1 ", array($p_id));
00174 $cn->commit();
00175
00176 }
00177 catch (Exception $exc)
00178 {
00179 echo alert($exc->getMessage());
00180 $cn->rollback();
00181 }
00182 }
00183
00184
00185
00186 if (isset($_POST['mod']))
00187 {
00188 extract($_POST);
00189 if (isset($delete) || isset($del_dep))
00190 {
00191 try
00192 {
00193 $cn->start();
00194 if (isset($del_dep))
00195 {
00196 $cn->exec_sql("delete from profile_menu where pm_id in (select * from get_menu_dependency($1))", array($pm_id));
00197 }
00198 $cn->exec_sql("delete from profile_menu where pm_id=$1", array($pm_id));
00199 $cn->commit();
00200 }
00201 catch (Exception $exc)
00202 {
00203 echo $exc->getMessage();
00204 $cn->rollback();
00205 }
00206 }
00207 else
00208 try
00209 {
00210
00211
00212
00213 $menu_type = $cn->get_value("select me_type from menu_ref
00214 where me_code=$1", array($me_code));
00215
00216 if ($menu_type == 'PR')
00217 {
00218 $p_type = 'P';
00219 $me_code_dep = -1;
00220 }
00221
00222
00223
00224 if ( $me_code == $me_code_dep )
00225 throw new Exception("Un menu ne peut pas dépendre de lui-même");
00226 $cn->start();
00227 $me_code_dep = ($me_code_dep == -1) ? null : $me_code_dep;
00228 $pm_default = (isset($pm_default)) ? 1 : 0;
00229 $p_order = (strlen(trim($p_order)) == 0) ? "0" : $p_order;
00230 if ($pm_default == 1)
00231 {
00232 $cn->exec_sql("update profile_menu set pm_default=0
00233 where p_id=(select p_id from profile_menu
00234 where
00235 pm_id=$1)", array($pm_id));
00236 }
00237 $cn->exec_sql("update profile_menu set me_code=$1,me_code_dep=$2,p_order=$3,pm_default=$4
00238 where pm_id=$5", array($me_code, $me_code_dep, $p_order, $pm_default, $pm_id));
00239 $cn->commit();
00240 }
00241 catch (Exception $e)
00242 {
00243 $cn->rollback();
00244 alert($e->getMessage());
00245 }
00246 }
00247
00248
00249
00250
00251 if (isset($_POST['add_menu']) || isset($_POST['add_impress']))
00252 {
00253 extract($_POST);
00254 try
00255 {
00256 $cn->start();
00257
00258
00259
00260
00261 $menu_type = $cn->get_value("select me_type from menu_ref
00262 where me_code=$1", array($me_code));
00263
00264 if ($menu_type == 'PR')
00265 {
00266 $p_type = 'P';
00267 $me_code_dep = -1;
00268 }
00269
00270
00271 if ($p_type == 'M')
00272 {
00273 $me_code_dep = -1;
00274 }
00275
00276
00277
00278 $inf = $cn->get_value("select count(*) from profile_menu
00279 where p_id=$1 and me_code_dep=$2 and me_code=$3", array($p_id, $me_code, $me_code_dep));
00280 if ($inf > 0)
00281 throw new Exception("Boucle infinie");
00282
00283
00284
00285 if ( $me_code == $me_code_dep )
00286 throw new Exception("Un menu ne peut pas dépendre de lui-même");
00287
00288
00289
00290
00291
00292 $me_code_dep = ($me_code_dep == -1) ? null : $me_code_dep;
00293
00294 $pm_default = (isset($pm_default)) ? 1 : 0;
00295 $cn->exec_sql("
00296 insert into profile_menu (me_code,me_code_dep,p_id,p_order,pm_default,p_type_display)
00297 values ($1,$2,$3,$4,$5,$6)
00298 ", array($me_code, $me_code_dep, $p_id, $p_order, $pm_default, $p_type));
00299
00300 $cn->commit();
00301 }
00302 catch (Exception $exc)
00303 {
00304 alert($exc->getMessage());
00305 }
00306 }
00307
00308 echo '<div id="list_profile" class="content">';
00309 $table = new Sort_Table();
00310 $url = $_SERVER['REQUEST_URI'];
00311
00312 $table->add('Nom', $url, "order by p_name asc", "order by p_name desc", "na", "nd");
00313 $table->add('Description', $url, "order by p_desc asc", "order by p_desc desc", "da", "dd");
00314 $table->add('Calculatrice visible', $url, "order by with_calc asc", "order by with_calc desc", "ca", "cd");
00315 $table->add('Form Direct visible', $url, "order by with_direct_form asc", "order by with_direct_form desc", "fa", "fd");
00316
00317 $ord = (isset($_REQUEST['ord'])) ? $_REQUEST['ord'] : 'na';
00318
00319 $order = $table->get_sql_order($ord);
00320
00321 $menu = new Profile_sql($cn);
00322 $ret = $menu->seek("where p_id > 0 ".$order);
00323 echo '<table class="result">';
00324 echo '<tr>';
00325 echo '<th>' . $table->get_header(0) . '</th>';
00326 echo '<th>' . $table->get_header(1) . '</th>';
00327 echo '<th>' . $table->get_header(2) . '</th>';
00328 echo '<th>' . $table->get_header(3) . '</th>';
00329 echo '</tr>';
00330 $gDossier = Dossier::id();
00331 for ($i = 0; $i < Database::num_row($ret); $i++)
00332 {
00333 $row = $menu->get_object($ret, $i);
00334
00335 $js = sprintf('<a href="javascript:void(0)" style="text-decoration:underline" onclick="get_profile_detail(\'%s\',\'%s\')">', $gDossier, $row->p_id);
00336 echo '<tr>';
00337 echo "<td>" . $js . $row->p_name . '</a>' . '</td>';
00338 echo td($row->p_desc);
00339 echo td($row->with_calc);
00340 echo td($row->with_direct_form);
00341 echo '</tr>';
00342 }
00343 $js = sprintf('<a href="javascript:void(0)" class="button" onclick="get_profile_detail(\'%s\',\'%s\')">', $gDossier, -1);
00344 echo '<tr>';
00345 echo "<td>" . $js . "Ajouter un profil </td>";
00346 echo '</tr>';
00347 echo '</table>';
00348 echo '</div>';
00349
00350
00351
00352
00353
00354 echo '<div id="detail_profile" class="content">';
00355 if (isset($_POST['p_id']))
00356 {
00357 require_once 'ajax_get_profile.php';
00358 }
00359 echo '</div>';
00360 if ( isset($_POST['delete_profil'] ))
00361 {
00362 echo create_script(" $('detail_profile').hide()");
00363 }
00364 ?>