Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035
00036 require_once('class_database.php');
00037 require_once('ac_common.php');
00038
00039 class Dossier
00040 {
00041 private static $variable=array("id"=>"dos_id",
00042 "name"=>"dos_name",
00043 "desc"=>"dos_description");
00044 function __construct($p_id)
00045 {
00046 $this->cn=new Database();
00047 $this->dos_id=$p_id;
00048 }
00049
00050 static function id()
00051 {
00052 self::check();
00053 return $_REQUEST['gDossier'];
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 function show_dossier($p_type,$p_first=0,$p_max=0,$p_Num=0)
00063 {
00064 $l_user=$_SESSION['g_user'];
00065 if ( $p_max == 0 )
00066 {
00067 $l_step="";
00068 }
00069 else
00070 {
00071 $l_step="LIMIT $p_max OFFSET $p_first";
00072 }
00073
00074 if ( $p_type == "all")
00075 {
00076 $l_sql="select *, 'W' as priv_priv from ac_dossier ORDER BY dos_name ";
00077 $p_Num=$this->cn->count_sql($l_sql);
00078 }
00079 else
00080 {
00081 $l_sql="select * from jnt_use_dos
00082 natural join ac_dossier
00083 natural join ac_users
00084 inner join priv_user on priv_jnt=jnt_id where
00085 use_login='".$l_user."' and priv_priv !='NO'
00086 order by dos_name ";
00087 $p_Num=$this->cn->count_sql($l_sql);
00088 }
00089 $l_sql=$l_sql.$l_step;
00090 $p_res=$this->cn->exec_sql($l_sql);
00091
00092
00093 $Max=$this->cn->size();
00094 if ( $Max == 0 ) return null;
00095 for ( $i=0;$i<$Max; $i++)
00096 {
00097 $row[]=$this->cn->fetch($i);
00098 }
00099 return $row;
00100 }
00101
00102
00103
00104
00105
00106 function get_user_folder($sql="")
00107 {
00108
00109 $sql="
00110 select
00111 use_id,
00112 use_first_name,
00113 use_name,
00114 use_login,
00115 use_active,
00116 use_admin,
00117 ag_dossier
00118 from
00119 ac_users as ac
00120 left join (select array_to_string(array_agg(dos_name),',') as ag_dossier,jt.use_id as jt_use_id
00121 from ac_dossier as ds
00122 join jnt_use_dos as jt on (jt.dos_id=ds.dos_id)
00123 join priv_user as pu on (pu.priv_jnt=jt.jnt_id)
00124 where
00125 pu.priv_priv != 'X'
00126 group by jt.use_id) as dossier_name on (jt_use_id=ac.use_id)
00127 where
00128 use_login!='phpcompta'
00129 $sql
00130 ";
00131
00132 $res=$this->cn->get_array($sql);
00133 return $res;
00134 }
00135
00136
00137 static function check()
00138 {
00139 if ( ! isset ($_REQUEST['gDossier']) )
00140 {
00141 echo_error ('Dossier inconnu ');
00142 exit('Dossier invalide ');
00143 }
00144 $id=$_REQUEST['gDossier'];
00145 if ( is_numeric ($id) == 0 ||
00146 strlen($id)> 6 ||
00147 $id > 999999)
00148 exit('gDossier Invalide : '.$id);
00149
00150 }
00151
00152 static function get()
00153 {
00154 self::check();
00155 return "gDossier=".$_REQUEST['gDossier'];
00156
00157 }
00158
00159
00160 static function hidden()
00161 {
00162 self::check();
00163 return '<input type="hidden" id="gDossier" name="gDossier" value="'.$_REQUEST['gDossier'].'">';
00164 }
00165
00166 static function name($id=0)
00167 {
00168 self::check();
00169
00170 $cn=new Database();
00171 $id=($id==0)?$_REQUEST['gDossier']:$id;
00172 $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",array($_REQUEST['gDossier']));
00173 return $name;
00174 }
00175
00176 public function get_parameter($p_string)
00177 {
00178 if ( array_key_exists($p_string,self::$variable) )
00179 {
00180 $idx=self::$variable[$p_string];
00181 return $this->$idx;
00182 }
00183 else
00184 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00185 }
00186 public function set_parameter($p_string,$p_value)
00187 {
00188 if ( array_key_exists($p_string,self::$variable) )
00189 {
00190 $idx=self::$variable[$p_string];
00191 $this->$idx=$p_value;
00192 }
00193 else
00194 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00195
00196
00197 }
00198 public function get_info()
00199 {
00200 return var_export(self::$variable,true);
00201 }
00202
00203 public function save()
00204 {
00205 $this->update();
00206 }
00207
00208 public function update()
00209 {
00210 if ( strlen(trim($this->dos_name))== 0 ) return;
00211
00212 if ( $this->cn->get_value("select count(*) from ac_dossier where dos_name=$1 and dos_id<>$2",
00213 array($this->dos_name,$this->dos_id)) !=0 )
00214 return ;
00215
00216 $sql="update ac_dossier set dos_name=$1,dos_description=$2 ".
00217 " where dos_id = $3";
00218 $res=$this->cn->exec_sql(
00219 $sql,
00220 array(trim($this->dos_name),
00221 trim($this->dos_description),
00222 $this->dos_id)
00223 );
00224 }
00225
00226 public function load()
00227 {
00228
00229 $sql="select dos_name,dos_description from ac_dossier where dos_id=$1";
00230
00231 $res=$this->cn->exec_sql(
00232 $sql,
00233 array($this->dos_id)
00234 );
00235
00236 if ( Database::num_row($res) == 0 ) return;
00237 $row=Database::fetch_array($res,0);
00238 foreach ($row as $idx=>$value)
00239 {
00240 $this->$idx=$value;
00241 }
00242
00243 }
00244
00245 static function get_version($p_cn)
00246 {
00247 return $p_cn->get_value('select val from version');
00248 }
00249
00250 static function connect()
00251 {
00252 $id = Dossier::id();
00253 $cn = new Database($id);
00254 return $cn;
00255 }
00256
00257
00258
00259
00260 static function synchro_admin($p_id)
00261 {
00262
00263 $cn=new Database($p_id);
00264
00265 if (! $cn->exist_table("profile_menu"))
00266 {
00267 echo_warning("Dossier invalide");
00268 return;
00269 }
00270
00271 $repo=new Database();
00272
00273 $a_admin=$repo->get_array("select use_login from ac_users where
00274 use_admin=1 and use_active=1");
00275 try
00276 {
00277
00278
00279
00280 $cn->start();
00281 for ($i=0;$i<count($a_admin);$i++)
00282 {
00283 $exist=$cn->get_value("select p_id from profile_user
00284 where user_name=$1",array($a_admin[$i]['use_login']));
00285 if ( $exist == "")
00286 {
00287 $cn->exec_sql("insert into profile_user(user_name,p_id) values($1,1)",
00288 array($a_admin[$i]['use_login']));
00289 }
00290
00291 }
00292 $cn->commit();
00293 } catch(Exception $e)
00294 {
00295 echo_warning($e->getMessage());
00296 $cn->rollback();
00297 }
00298 }
00299 }