// expects: tag_type_id & tagname & description & category & min_role_id
$known_actions []= "delete-tag-types";
// expects: tag_type_ids
+$known_actions []= "remove-roles-from-tag-type";
+// expects: tag_type_id & role_ids
+$known_actions []= "add-role-to-tag-type";
+// expects: tag_type_id_id & id
//////////////////////////////////////// tags
$known_actions []= "set-tag-on-node";
break;
}
+ case 'remove-roles-from-tag-type' : {
+ $tag_type_id=$_POST['tag_type_id'];
+ $role_ids=$_POST['role_ids'];
+ if ( ! $role_ids) {
+ drupal_set_error("You have not selected role(s) to remove");
+ } else {
+ foreach( $role_ids as $role_id)
+ if ( $api->DeleteRoleFromTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1 )
+ drupal_set_error ("Could not remove role $role_id from tag type $tag_type_id");
+ }
+ plc_redirect (l_tag_roles($tag_type_id));
+ }
+
+ case 'add-role-to-tag-type' : {
+ $tag_type_id=$_POST['tag_type_id'];
+ $role_id=$_POST['role_id'];
+ if ( ! $role_id) {
+ drupal_set_error ("You have not selected a role to add");
+ } else if ($api->AddRoleToTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1) {
+ drupal_set_error("Could not add role $role_id to tag $tag_type_id");
+ }
+ plc_redirect (l_tag_roles($tag_type_id));
+ }
+
//////////////////////////////////////// tags
case 'set-tag-on-node':
case 'set-tag-on-interface': {
<?php
-// $Id$
-
// Require login
require_once 'plc_login.php';
$tag_type=$tag_types[0];
$tagname=$tag_type['tagname'];
-$min_role_id= $tag_type['min_role_id'];
+$role_ids= $tag_type['role_ids'];
+$roles= $tag_type['roles'];
$description= $tag_type['description'];
$category=$tag_type['category'];
$filter=array('tag_type_id'=>$tag_type_id);
$node_tags=$api->GetNodeTags($filter);
$interface_tags=$api->GetInterfaceTags($filter);
+$person_tags=$api->GetPersonTags($filter);
+$site_tags=$api->GetSiteTags($filter);
// split slice tags into 3 families, whether this applies to the whole slice, or a nodegroup, or a node
// using filters for this purpose does not work out very well, maybe a bug in the filter stuff
// anyway this is more efficient, and we compute the related node(groups) in the same pass
drupal_set_title("Details for tag type $tagname");
plekit_linetabs($tabs);
-// ----------
+//////////////////// details
$toggle = new PlekitToggle ('details','Details');
$toggle->start();
$can_update=plc_is_admin();
$details->th_td("Category",$category,"category",array('width'=>30));
$details->th_td("Description",$description,"description",array('width'=>40));
-if ($can_update) {
-// select the option corresponding with min_role_id
- $selectors = $details->form()->role_selectors($api->GetRoles(),$min_role_id);
- $select_field = $details->form()->select_html("min_role_id",$selectors);
- // xxx would need to turn role_id into role name
- $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id));
- } else {
- $details->th_td("Min role",$min_role_id);
- }
if ($can_update)
$details->tr_submit('update-tag-type',"Update tag type");
$details->form_end();
$toggle->end();
+//////////////////// 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',false)));
+$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
+
// common options for tables below
$table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10);
$toggle->end();
}
+if (count ($site_tags)) {
+ $toggle=new PlekitToggle('tag_sites',"Sites");
+ $toggle->start();
+ $table=new PlekitTable("tag_sites",array("L"=>"login_base","value"=>"string"),0,$table_options);
+ $table->start();
+ foreach ($site_tags as $site_tag) {
+ $table->row_start();
+ $table->cell(href(l_site($site_tag['site_id']),$site_tag['login_base']));
+ $table->cell($site_tag['value']);
+ $table->row_end();
+ }
+ $table->end();
+ $toggle->end();
+}
+
+if (count ($person_tags)) {
+ $toggle=new PlekitToggle('tag_persons',"Persons");
+ $toggle->start();
+ $table=new PlekitTable("tag_persons",array("E"=>"email","value"=>"string"),0,$table_options);
+ $table->start();
+ foreach ($person_tags as $person_tag) {
+ $table->row_start();
+ $table->cell(href(l_person($person_tag['person_id']),$person_tag['email']));
+ $table->cell($person_tag['value']);
+ $table->row_end();
+ }
+ $table->end();
+ $toggle->end();
+}
+
if (count ($slice_tags)) {
$toggle=new PlekitToggle('tag_slices',"Slice tags");
$toggle->start();
<?php
-// $Id$
-
// Require login
require_once 'plc_login.php';
drupal_set_title($title);
plekit_linetabs($tabs);
-$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "min_role_id" );
+$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "roles");
$tag_type_filter=NULL;
if ($pattern)
$headers['Name']="string";
$headers['Description']="string";
$headers['Category']="string";
-$headers['MR']="string";
-$notes []= "MR: Min Role, needed to manage this tag";
+$headers['Roles']="string";
// xxx ref count would be helpful but seem too expensive to compute at this stage
// the individual tag page show those ref counts per type
$table = new PlekitTable("tags",$headers,0,array('notes'=>$notes));
$table->start();
-$roles_hash=plc_role_global_hash($api);
-
$description_width=40;
foreach( $tag_types as $tag_type ) {
- $role_name=$roles_hash[$tag_type['min_role_id']];
$table->row_start();
$tag_type_id=$tag_type['tag_type_id'];
$table->cell(href(l_tag($tag_type_id),$tag_type['tagname']));
$table->cell(wordwrap($tag_type['description'],$description_width,"<br/>"));
$table->cell($tag_type['category']);
- $table->cell($role_name);
- // ref count
- // if (plc_is_admin()) $table->cell('xxx');
+ $table->cell(plc_vertical_table ($tag_type['roles']));
$table->cell($tag_type_id);
if (plc_is_admin())
$table->cell ($form->checkbox_html('tag_type_ids[]',$tag_type_id));
// an inline area to add a tag type
$table->row_start();
- // build the role selector
- $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
- function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); }
- $selectors=array_map("selector_argument",$relevant_roles);
- $role_input=$form->select_html("min_role_id",$selectors,array('label'=>"Role"));
-
$table->cell($form->text_html('tagname',''));
$table->cell($form->textarea_html('description','',$description_width,2));
$table->cell($form->text_html('category',''));
- $table->cell($role_input);
+ $table->cell("<span class='note_roles'>add roles later</span>");
$table->cell($form->submit_html("add-tag-type","Add"),2);
$table->row_end();
}