+//////////////////// roles
+$form=new PlekitForm(l_actions(), array("tag_type_id"=>$tag_type_id));
+$form->start();
+
+$toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles')));
+$toggle->start();
+
+if (! $roles) plc_warning ("This tag type has no role !");
+
+$can_manage_roles= plc_is_admin();
+
+$headers=array("Role"=>"string");
+if ($can_manage_roles) $headers [plc_delete_icon()]="none";
+
+$table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
+$table=new PlekitTable("tag_roles",$headers,0,$table_options);
+$table->start();
+
+// construct array of role objs
+$role_objs=array();
+for ($n=0; $n<count($roles); $n++) {
+ $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
+}
+
+if ($role_objs) foreach ($role_objs as $role_obj) {
+ $table->row_start();
+ $table->cell($role_obj['name']);
+ if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
+ $table->row_end();
+ }
+
+// footers : the remove and add buttons
+if ($can_manage_roles) {
+
+ // remove
+ $table->tfoot_start();
+ if ($roles) {
+ $table->row_start();
+ $table->cell($form->submit_html("remove-roles-from-tag-type","Remove Roles"),
+ array('hfill'=>true,'align'=>'right'));
+ $table->row_end();
+ }
+
+ // add
+ // compute the roles that can be added
+ if ($can_manage_roles)
+ // all roles
+ $exclude_role_ids=array();
+ else
+ // all roles except admin and pi
+ $exclude_role_ids=array(10,20);
+ $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids);
+ $roles_to_add = roles_except ($possible_roles,$role_ids);
+ if ( $roles_to_add ) {
+ $selectors=$form->role_selectors($roles_to_add);
+ $table->row_start();
+ $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
+ // add a role : the button
+ $add_role_right_area=$form->submit_html("add-role-to-tag-type","Add role");
+ $table->cell ($add_role_left_area . $add_role_right_area,
+ array('hfill'=>true,'align'=>'right'));
+ $table->row_end();
+ }
+}
+$table->end();
+$toggle->end();
+$form->end();
+
+//////////////////// the 5 flavours of objects that the tag may be attached to
+