- case 'update-tag-type': {
- // get post vars
- $tag_type_id= intval( $_POST['tag_type_id'] );
- $tagname = $_POST['tagname'];
- $min_role_id= intval( $_POST['min_role_id'] );
- $description= $_POST['description'];
- $category= $_POST['category'];
-
- // make tag_type_fields dict
- $tag_type_fields= array( "min_role_id" => $min_role_id,
- "tagname" => $tagname,
- "description" => $description,
- "category" => $category,
- );
-
- if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1)
- drupal_set_message ("Tag type $tagname updated");
- else
- drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
- plc_redirect(l_tag($tag_type_id));
- break;
- }
-
- case 'add-tag-type': {
- // get post vars
- $tagname = $_POST['tagname'];
- $min_role_id= intval( $_POST['min_role_id'] );
- $description= $_POST['description'];
- $category= $_POST['category'];
-
- // make tag_type_fields dict
- $tag_type_fields= array( "min_role_id" => $min_role_id,
- "tagname" => $tagname,
- "description" => $description,
- "category" => $category,
- );
-
- // Add it!
- $tag_type_id=$api->AddTagType( $tag_type_fields );
- if ($tag_type_id > 0)
- drupal_set_message ("tag type $tag_type_id created");
- else
- drupal_set_error ("Could not create tag type $tagname");
- plc_redirect( l_tags());
- break;
- }
-
- case 'delete-tag-types': {
- $tag_type_ids = $_POST['tag_type_ids'];
- if ( ! $tag_type_ids) {
- drupal_set_message("action=$action - No tag selected");
- return;
- }
- $success=true;
- $counter=0;
- foreach ($tag_type_ids as $tag_type_id)
- if ($api->DeleteTagType(intval($tag_type_id)) != 1)
- $success=false;
- else
- $counter++;
- if ($success)
- drupal_set_message ("Deleted $counter tag(s)");
- else
- drupal_set_error ("Could not delete all selected tags, only $counter were removed");
- plc_redirect (l_tags());
- 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-site':
- case 'set-tag-on-person':
- case 'set-tag-on-interface':
- {
-
- $mode = NULL;
- if ($action == 'set-tag-on-node') $mode='node';
- if ($action == 'set-tag-on-site') $mode='site';
- if ($action == 'set-tag-on-person') $mode='person';
- if ($action == 'set-tag-on-interface') $mode='interface';
-
- if ($mode=='node')
- $id = intval($_POST['node_id']);
- else if ($mode=='site')
- $id = intval($_POST['site_id']);
- else if ($mode=='person')
- $id = intval($_POST['person_id']);
- else
- $id = intval($_POST['interface_id']);
- $tag_type_id = intval($_POST['tag_type_id']);
- $value = $_POST['value'];
-
- $tag_types=$api->GetTagTypes(array($tag_type_id));
- if (count ($tag_types) != 1) {
- drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
- } else {
- if ($mode=='node')
- $tags = $api->GetNodeTags (array('node_id'=>$id, 'tag_type_id'=> $tag_type_id));
- else if ($mode=='site')
- $tags = $api->GetSiteTags (array('site_id'=>$id, 'tag_type_id'=> $tag_type_id));
- else if ($mode=='person')
- $tags = $api->GetPersonTags (array('person_id'=>$id, 'tag_type_id'=> $tag_type_id));
- else
- $tags = $api->GetInterfaceTags (array('interface_id'=>$id, 'tag_type_id'=> $tag_type_id));
-
- // already has a tag set
- if ( count ($tags) == 1) {
- $tag=$tags[0];
- if ($mode=='node')
- $result=$api->UpdateNodeTag($tag['node_tag_id'],$value);
- else if ($mode=='site')
- $result=$api->UpdateSiteTag($tag['site_tag_id'],$value);
- else if ($mode=='person')
- $result=$api->UpdatePersonTag($tag['person_tag_id'],$value);
- else
- $result=$api->UpdateInterfaceTag($tag['interface_tag_id'],$value);
-
- if ($result == 1)
- drupal_set_message ("Updated tag, new value = $value");
- else
- drupal_set_error ("Could not update tag");
-
- // no such tag set yet on that object
- } else {
- if ($mode=='node')
- $tag_id = $api->AddNodeTag($id,$tag_type_id,$value);
- else if ($mode=='site')
- $tag_id = $api->AddSiteTag($id,$tag_type_id,$value);
- else if ($mode=='person')
- $tag_id = $api->AddPersonTag($id,$tag_type_id,$value);
- else
- $tag_id = $api->AddInterfaceTag($id,$tag_type_id,$value);
- if ($tag_id)
- drupal_set_message ("Created tag, new value = $value");
- else
- drupal_set_error ("Could not create tag");
- }
- }
-
- if ($mode=='node')
- plc_redirect (l_node_tags($id));
- else if ($mode=='site')
- plc_redirect (l_site_tags($id));
- else if ($mode=='person')
- plc_redirect (l_person_tags($id));
- else
- plc_redirect (l_interface_tags($id));
- }
-
- case 'delete-node-tags':
- case 'delete-site-tags':
- case 'delete-person-tags':
- case 'delete-interface-tags': {
-
- $mode = NULL;
- if ($action == 'delete-node-tags') $mode='node';
- if ($action == 'delete-site-tags') $mode='site';
- if ($action == 'delete-person-tags') $mode='person';
- if ($action == 'delete-interface-tags') $mode='interface';
-
- if ($mode=='node') {
- $id=$_POST['node_id'];
- $tag_ids=$_POST['node_tag_ids'];
- } else if ($mode=='site') {
- $id=$_POST['site_id'];
- $tag_ids=$_POST['site_tag_ids'];
- } else if ($mode=='person') {
- $id=$_POST['person_id'];
- $tag_ids=$_POST['person_tag_ids'];
- } else {
- $id=$_POST['interface_id'];
- $tag_ids=$_POST['interface_tag_ids'];
- }
-
- if ( ! $tag_ids) {
- drupal_set_message("action=$action - No tag selected");
- return;
- }
- $success=true;
- $counter=0;
- foreach( $tag_ids as $tag_id ) {
- if ($mode=='node')
- $retcod = $api->DeleteNodeTag( intval( $tag_id ));
- else if ($mode=='site')
- $retcod = $api->DeleteSiteTag( intval( $tag_id ));
- else if ($mode=='person')
- $retcod = $api->DeletePersonTag( intval( $tag_id ));
- else
- $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
- if ($retcod != 1)
- $success=false;
- else
- $counter++;
- }
- if ($success)
- drupal_set_message ("Deleted $counter tag(s)");
- else
- drupal_set_error ("Could not delete all selected tags, only $counter were removed");
-
- if ($mode=='node')
- plc_redirect (l_node_tags($id));
- else if ($mode=='site')
- plc_redirect (l_site_tags($id));
- else if ($mode=='person')
- plc_redirect (l_person_tags($id));
- else
- plc_redirect (l_interface_tags($id));
-
- }
+ case 'update-tag-type':{
+ // get post vars
+ $tag_type_id = intval($_POST['tag_type_id']);
+ $tagname = $_POST['tagname'];
+ $min_role_id = intval($_POST['min_role_id']);
+ $description = $_POST['description'];
+ $category = $_POST['category'];
+
+ // make tag_type_fields dict
+ $tag_type_fields = array("min_role_id" => $min_role_id,
+ "tagname" => $tagname,
+ "description" => $description,
+ "category" => $category,
+ );
+
+ if ($api->UpdateTagType($tag_type_id, $tag_type_fields) == 1) {
+ drupal_set_message("Tag type $tagname updated");
+ } else {
+ drupal_set_error("Could not update tag type $tag_type_id\n" . $api->error());
+ }
+
+ plc_redirect(l_tag($tag_type_id));
+ break;
+ }
+
+ case 'add-tag-type':{
+ // get post vars
+ $tagname = $_POST['tagname'];
+ $min_role_id = intval($_POST['min_role_id']);
+ $description = $_POST['description'];
+ $category = $_POST['category'];
+
+ // make tag_type_fields dict
+ $tag_type_fields = array("min_role_id" => $min_role_id,
+ "tagname" => $tagname,
+ "description" => $description,
+ "category" => $category,
+ );
+
+ // Add it!
+ $tag_type_id = $api->AddTagType($tag_type_fields);
+ if ($tag_type_id > 0) {
+ drupal_set_message("tag type $tag_type_id created");
+ } else {
+ drupal_set_error("Could not create tag type $tagname");
+ }
+
+ plc_redirect(l_tags());
+ break;
+ }
+
+ case 'delete-tag-types':{
+ $tag_type_ids = $_POST['tag_type_ids'];
+ if (!$tag_type_ids) {
+ drupal_set_message("action=$action - No tag selected");
+ return;
+ }
+ $success = true;
+ $counter = 0;
+ foreach ($tag_type_ids as $tag_type_id) {
+ if ($api->DeleteTagType(intval($tag_type_id)) != 1) {
+ $success = false;
+ } else {
+ $counter++;
+ }
+ }
+
+ if ($success) {
+ drupal_set_message("Deleted $counter tag(s)");
+ } else {
+ drupal_set_error("Could not delete all selected tags, only $counter were removed");
+ }
+
+ plc_redirect(l_tags());
+ 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-site':
+ case 'set-tag-on-person':
+ case 'set-tag-on-interface':
+ {
+
+ $mode = null;
+ if ($action == 'set-tag-on-node') {
+ $mode = 'node';
+ }
+
+ if ($action == 'set-tag-on-site') {
+ $mode = 'site';
+ }
+
+ if ($action == 'set-tag-on-person') {
+ $mode = 'person';
+ }
+
+ if ($action == 'set-tag-on-interface') {
+ $mode = 'interface';
+ }
+
+ if ($mode == 'node') {
+ $id = intval($_POST['node_id']);
+ } else if ($mode == 'site') {
+ $id = intval($_POST['site_id']);
+ } else if ($mode == 'person') {
+ $id = intval($_POST['person_id']);
+ } else {
+ $id = intval($_POST['interface_id']);
+ }
+
+ $tag_type_id = intval($_POST['tag_type_id']);
+ $value = $_POST['value'];
+
+ $tag_types = $api->GetTagTypes(array($tag_type_id));
+ if (count($tag_types) != 1) {
+ drupal_set_error("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
+ } else {
+ if ($mode == 'node') {
+ $tags = $api->GetNodeTags(array('node_id' => $id, 'tag_type_id' => $tag_type_id));
+ } else if ($mode == 'site') {
+ $tags = $api->GetSiteTags(array('site_id' => $id, 'tag_type_id' => $tag_type_id));
+ } else if ($mode == 'person') {
+ $tags = $api->GetPersonTags(array('person_id' => $id, 'tag_type_id' => $tag_type_id));
+ } else {
+ $tags = $api->GetInterfaceTags(array('interface_id' => $id, 'tag_type_id' => $tag_type_id));
+ }
+
+ // already has a tag set
+ if (count($tags) == 1) {
+ $tag = $tags[0];
+ if ($mode == 'node') {
+ $result = $api->UpdateNodeTag($tag['node_tag_id'], $value);
+ } else if ($mode == 'site') {
+ $result = $api->UpdateSiteTag($tag['site_tag_id'], $value);
+ } else if ($mode == 'person') {
+ $result = $api->UpdatePersonTag($tag['person_tag_id'], $value);
+ } else {
+ $result = $api->UpdateInterfaceTag($tag['interface_tag_id'], $value);
+ }
+
+ if ($result == 1) {
+ drupal_set_message("Updated tag, new value = $value");
+ } else {
+ drupal_set_error("Could not update tag");
+ }
+
+ // no such tag set yet on that object
+ } else {
+ if ($mode == 'node') {
+ $tag_id = $api->AddNodeTag($id, $tag_type_id, $value);
+ } else if ($mode == 'site') {
+ $tag_id = $api->AddSiteTag($id, $tag_type_id, $value);
+ } else if ($mode == 'person') {
+ $tag_id = $api->AddPersonTag($id, $tag_type_id, $value);
+ } else {
+ $tag_id = $api->AddInterfaceTag($id, $tag_type_id, $value);
+ }
+
+ if ($tag_id) {
+ drupal_set_message("Created tag, new value = $value");
+ } else {
+ drupal_set_error("Could not create tag");
+ }
+
+ }
+ }
+
+ if ($mode == 'node') {
+ plc_redirect(l_node_tags($id));
+ } else if ($mode == 'site') {
+ plc_redirect(l_site_tags($id));
+ } else if ($mode == 'person') {
+ plc_redirect(l_person_tags($id));
+ } else {
+ plc_redirect(l_interface_tags($id));
+ }
+
+ }
+
+ case 'delete-node-tags':
+ case 'delete-site-tags':
+ case 'delete-person-tags':
+ case 'delete-interface-tags':{
+
+ $mode = null;
+ if ($action == 'delete-node-tags') {
+ $mode = 'node';
+ }
+
+ if ($action == 'delete-site-tags') {
+ $mode = 'site';
+ }
+
+ if ($action == 'delete-person-tags') {
+ $mode = 'person';
+ }
+
+ if ($action == 'delete-interface-tags') {
+ $mode = 'interface';
+ }
+
+ if ($mode == 'node') {
+ $id = $_POST['node_id'];
+ $tag_ids = $_POST['node_tag_ids'];
+ } else if ($mode == 'site') {
+ $id = $_POST['site_id'];
+ $tag_ids = $_POST['site_tag_ids'];
+ } else if ($mode == 'person') {
+ $id = $_POST['person_id'];
+ $tag_ids = $_POST['person_tag_ids'];
+ } else {
+ $id = $_POST['interface_id'];
+ $tag_ids = $_POST['interface_tag_ids'];
+ }
+
+ if (!$tag_ids) {
+ drupal_set_message("action=$action - No tag selected");
+ return;
+ }
+ $success = true;
+ $counter = 0;
+ foreach ($tag_ids as $tag_id) {
+ if ($mode == 'node') {
+ $retcod = $api->DeleteNodeTag(intval($tag_id));
+ } else if ($mode == 'site') {
+ $retcod = $api->DeleteSiteTag(intval($tag_id));
+ } else if ($mode == 'person') {
+ $retcod = $api->DeletePersonTag(intval($tag_id));
+ } else {
+ $retcod = $api->DeleteInterfaceTag(intval($tag_id));
+ }
+
+ if ($retcod != 1) {
+ $success = false;
+ } else {
+ $counter++;
+ }
+
+ }
+ if ($success) {
+ drupal_set_message("Deleted $counter tag(s)");
+ } else {
+ drupal_set_error("Could not delete all selected tags, only $counter were removed");
+ }
+
+ if ($mode == 'node') {
+ plc_redirect(l_node_tags($id));
+ } else if ($mode == 'site') {
+ plc_redirect(l_site_tags($id));
+ } else if ($mode == 'person') {
+ plc_redirect(l_person_tags($id));
+ } else {
+ plc_redirect(l_interface_tags($id));
+ }
+
+ }