diff --git a/include/ajax_get_profile.php b/include/ajax_get_profile.php index 1b7577f5f..468dd02df 100644 --- a/include/ajax_get_profile.php +++ b/include/ajax_get_profile.php @@ -82,6 +82,9 @@ Effacer ce profil'; echo $add_one; echo "

Action gestion accessible

"; $profile_menu->available_profile($p_id); + echo "

Dépôt de stock accessible

"; + $profile_menu->available_repository($p_id); + } ?> diff --git a/include/class_profile_menu.php b/include/class_profile_menu.php index 06463e387..4b3baffb1 100644 --- a/include/class_profile_menu.php +++ b/include/class_profile_menu.php @@ -208,6 +208,10 @@ class Profile_Menu $gDossier = Dossier::id(); $this->sub_menu($ret, $p_id); } + /** + * Show the available profile for the profile $p_id, it concerns only the action of management (action-gestion) + * @param $p_id is the profile p_id + */ function available_profile($p_id) { $array=$this->cn->get_array(" @@ -228,7 +232,30 @@ class Profile_Menu ); require_once 'template/user_sec_profile.php'; } + /** + * Show the available repository for the profile $p_id + * @param $p_id is the profile p_id + */ + function available_repository($p_id) + { + $array=$this->cn->get_array(" + select p.r_id,p.r_name,s.ur_id,s.ur_right + from stock_repository as p + join user_sec_repository as s on (s.r_id=p.r_id) + where s.p_id=$1 + union + select p2.r_id, p2.r_name,null,'X' + from stock_repository as p2 + where + p2.r_id not in (select r_id from user_sec_repository where p_id = $1) order by r_name; + ",array($p_id)); + $aright_value=array( + array('value'=>'R','label'=>_('Lecture')), + array('value'=>'W','label'=>_('Ecriture')), + array('value'=>'X','label'=>_('Aucun accès')) + ); + require_once 'template/user_sec_repository.php'; + } } - //end class ?> \ No newline at end of file diff --git a/include/class_stock_sql.php b/include/class_stock_sql.php new file mode 100644 index 000000000..95e44e254 --- /dev/null +++ b/include/class_stock_sql.php @@ -0,0 +1,64 @@ +table = "public.stock_repository"; + $this->primary_key = "r_id"; + + $this->name=array( + "id"=>"r_id", + "name"=>"r_name", + "adress"=>"r_adress", + "city"=>"r_city", + "country"=>"r_country", + "phone"=>"r_phone" + ); + + $this->type = array( + "r_id"=>"numeric", + "r_name"=>"text", + "r_adress"=>"text", + "r_city"=>"text", + "r_country"=>"text", + "r_phone"=>"text" + + ); + + $this->default = array( + "r_id" => "auto", + ); + global $cn; + + parent::__construct($cn,$p_id); + } +} +?> diff --git a/include/profile.inc.php b/include/profile.inc.php index 8bca1dafe..f01b739ce 100644 --- a/include/profile.inc.php +++ b/include/profile.inc.php @@ -58,6 +58,41 @@ if (isset($_POST['change_profile'])) } } //********************************************** +// Save avail. profiles +//********************************************** +if (isset($_POST['change_stock'])) +{ + extract($_POST); + try + { + for ($e = 0; $e < count($right); $e++) + { + if ($right[$e] == 'X' && $ur_id[$e]=='') + continue; + if ($right[$e] == 'X' && $ur_id[$e]!='') + { + $cn->exec_sql("delete from user_sec_repository where p_id=$1 and r_id=$2", array($p_id, $ar_id[$e])); + continue; + } + if ($ur_id[$e] == "") + { + $cn->exec_sql("insert into user_sec_repository (p_id,r_id,ur_right) values($1,$2,$3)", array($p_id, $ar_id[$e], $right[$e])); + continue; + } + if ($ur_id[$e] != '') + { + $cn->exec_sql("update user_sec_repository set ur_right=$3 where p_id=$1 and r_id=$2 ", array($p_id, $ar_id[$e], $right[$e])); + continue; + } + } + } + catch (Exception $exc) + { + echo $exc->getTraceAsString(); + throw $exc; + } +} +//********************************************** // Save_name // ********************************************* diff --git a/include/template/user_sec_repository.php b/include/template/user_sec_repository.php new file mode 100644 index 000000000..8da5d5279 --- /dev/null +++ b/include/template/user_sec_repository.php @@ -0,0 +1,53 @@ + +
+ + + + + + + + + + + + +
+ + + + + value=$aright_value; + $isel->selected=$array[$i]['ur_right']; + echo $isel->input();?> +
+ diff --git a/sql/upgrade.sql b/sql/upgrade.sql index f0dc25a99..cd8690d11 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -240,4 +240,25 @@ COMMENT ON COLUMN stock_repository.r_country IS 'country of the stock'; COMMENT ON COLUMN stock_repository.r_city IS 'City of the stock'; COMMENT ON COLUMN stock_repository.r_phone IS 'Phone number'; -insert into stock_repository(r_name) values ('Dépôt par défaut'); \ No newline at end of file +insert into stock_repository(r_name) values ('Dépôt par défaut'); + +CREATE TABLE user_sec_repository +( + ur_id bigserial NOT NULL, -- pk + p_id bigint, -- fk to profile + r_id bigint, + ur_right character(1), -- Type of right : R for readonly W for write + CONSTRAINT user_sec_repository_pkey PRIMARY KEY (ur_id ), + CONSTRAINT user_sec_repository_p_id_fkey FOREIGN KEY (p_id) + REFERENCES profile (p_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT user_sec_repository_r_id_fkey FOREIGN KEY (r_id) + REFERENCES stock_repository (r_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT user_sec_profile_ur_right_check CHECK (ur_right = ANY (ARRAY['R'::bpchar, 'W'::bpchar])) +); +COMMENT ON TABLE user_sec_repository IS 'Available profile for user'; +COMMENT ON COLUMN user_sec_repository.ur_id IS 'pk'; +COMMENT ON COLUMN user_sec_repository.p_id IS 'fk to profile'; +COMMENT ON COLUMN user_sec_repository.r_id IS 'fk to stock_repository'; +COMMENT ON COLUMN user_sec_repository.ur_right IS 'Type of right : R for readonly W for write'; \ No newline at end of file