4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
10 if (! isset($_GET['type']) || $_GET['type']=='all') {
11 $title="All tag types";
12 $tag_type_filter=array("-SORT"=>"tagname");
14 $title="Tag Types for " . $_GET['type'] . "s";
15 $pattern=$_GET['type'] . '*';
16 $tag_type_filter=array("category"=>$pattern,"-SORT"=>"tagname");
21 require_once 'plc_drupal.php';
22 drupal_set_title($title);
23 include 'plc_header.php';
26 require_once 'plc_functions.php';
27 require_once 'plc_sorts.php';
30 $_person= $plc->person;
31 $_roles= $_person['role_ids'];
33 //print_r( $_person );
35 // if no id, display list of tag types
36 if( !$_GET['id'] && !$_GET['add'] && !$_GET['add_type'] && !$_GET['edit_type'] ) {
38 $tag_types= $api->GetTagTypes($tag_type_filter,
39 array( "tag_type_id", "tagname", "category", "description", "min_role_id" ) );
41 // get role names for the min role_ids
42 foreach( $tag_types as $tag_type ) {
43 $roles= $api->GetRoles();
44 foreach( $roles as $role ) {
45 if( $tag_type['min_role_id'] == $role['role_id'] )
46 $role_name= $role['name'];
49 $tag_type_info[]= array( "tag_type_id" => $tag_type['tag_type_id'],
50 "tagname" => $tag_type['tagname'],
51 "description" => $tag_type['description'],
52 "min_role" => $role_name,
53 "category" => $tag_type['category']);
57 echo "<h2>Tag Types</h2>\n";
59 echo "<table cellpadding=2><thead><tr><th>Name</th><th>Category></th><th>Min Role</th><th>Description</th>";
60 // if admin we need to more cells
61 if( in_array( "10", $_person['role_ids'] ) )
62 echo "<th></th><th></th>";
63 echo "</thead><tbody>";
65 foreach( $tag_type_info as $type ) {
67 echo "<td>". $type['tagname'] ."</td>";
68 echo "<td>". $type['category'] ."</td>";
69 echo "<td>". $type['min_role'] ."</td>";
70 echo "<td>". $type['description'] ."</td>";
71 // if admin display edit/delet links
72 if( in_array( "10", $_person['role_ids'] ) ) {
73 echo "<td><a href='tags.php?type=slice&edit_type=". $type['tag_type_id'] ."'>Edit</a></td>";
75 echo plc_delete_link_button ('tag_action.php?del_type='. $type['tag_type_id'],
83 echo "</tbody></table>\n";
85 if( in_array( "10", $_person['role_ids'] ) )
86 echo "<p><a href='tags.php?type=slice&add_type=1'>Add a Tag Type</a>";
89 elseif( $_GET['add_type'] || $_GET['edit_type'] ) {
90 // if its edit get the tag info
91 if( $_GET['edit_type'] ) {
92 $type_id= intval( $_GET['edit_type'] );
93 $type_info= $api->GetTagTypes( array( $type_id ) );
95 $tagname= $type_info[0]['tagname'];
96 $min_role_id= $type_info[0]['min_role_id'];
97 $description= $type_info[0]['description'];
98 $category=$type_info[0]['category'];
102 // display form for tag types
103 echo "<form action='tag_action.php' method='post'>\n";
104 echo "<h2>Add Tag Type</h2>\n";
105 echo "<p><strong>Name: </strong> <input type=text name='name' size=20 value='$tagname'>\n";
106 echo "<p><strong>Category: </strong><input type=text name='category' size=30 value='$category'>\n";
107 echo "<p><strong>Min Role: </strong><select name='min_role_id'>\n";
108 echo "<option value='10'"; if( $min_role_id == 10 ) echo " selected"; echo ">Admin</option>\n";
109 echo "<option value='20'"; if( $min_role_id == 20 ) echo " selected"; echo ">PI</option>\n";
110 echo "<option value='30'"; if( $min_role_id == 30 ) echo " selected"; echo ">User</option>\n";
111 echo "<option value='40'"; if( $min_role_id == 40 ) echo " selected"; echo ">Tech</option>\n";
113 echo "<p><strong>Description: </strong><br>\n";
114 echo "<textarea name='description' cols=40 rows=5>$description</textarea>\n";
115 echo "<p><input type=submit ";
116 if( $_GET['edit_type'] ) {
117 echo "name='edit_type' value='Edit Tag Type'>\n";
118 echo "<input type=hidden name='tag_type_id' value='$type_id'>\n";
121 echo "name='add_type' value='Add Tag Type'>\n";
126 elseif( $_GET['add'] ) {
127 // get slice id from GET
128 $slice_id= intval( $_GET['add'] );
131 $tag_types= $api->GetTagTypes( $tag_type_filter , array( "tag_type_id", "tagname" ) );
133 foreach( $tag_types as $tag_type ) {
134 $all_tags[$tag_type['tag_type_id']]= $tag_type['tagname'];
137 // get slice's tag types
138 $slice_info= $api->GetSlices( array( $slice_id ), array( "slice_tag_ids" ) );
139 $tag_info= $api->GetSliceTags( $slice_info[0]['slice_tag_ids'], array( "tag_type_id", "tagname" ) );
141 foreach( $tag_info as $info ) {
142 $slice_tag_types[$info['tag_type_id']]= $info['tagname'];
146 $tag_types= $all_tags;
149 echo "<form action='tag_action.php' method='post'>\n";
150 echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
152 echo "<select name='tag_type_id'><option value=''>Choose a type to add</option>\n";
154 foreach( $tag_types as $key => $val ) {
155 echo "<option value='". $key ."'>". $val ."</option>\n";
160 echo "<p><strong>Value: </strong><input type=text name='value'>\n";
162 echo "<p><input type=submit name='add_tag' value='Add Tag'>\n";
163 echo "<input type=hidden name='slice_id' value='$slice_id'>\n";
168 $tag_id= intval( $_GET['id'] );
171 $slice_tag= $api->GetSliceTags( array( $tag_id ), array( "slice_id", "slice_tag_id", "tag_type_id", "value", "description", "min_role_id" ) );
174 $tag_type= $api->GetTagTypes( array( $slice_tag[0]['tag_type_id'] ), array( "tag_type_id", "tagname", "description" ) );
177 $slice_info= $api->GetSlices( array( $slice_tag[0]['slice_id'] ), array( "name" ) );
179 // start form and put values in to be edited.
180 echo "<form action='tag_action.php' method='post'>\n";
181 echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
183 echo $slice_tag[0]['description'] ."<br />\n";
184 echo "<strong>Value:</strong> <input type=text name=value value='". $slice_tag[0]['value'] ."'><br /><br />\n";
186 echo "<input type=submit value='Edit Tag' name='edit_tag'>\n";
187 echo "<input type=hidden name='slice_id' value='". $slice_tag[0]['slice_id'] ."'>\n";
188 echo "<input type=hidden name='tag_id' value='". $tag_id ."'>\n";
193 echo "<p><a href='index.php?id=$slice_id'>Back to Slices</a>\n";
196 include 'plc_footer.php';