4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
12 drupal_set_title('Attributes');
13 include 'plc_header.php';
16 require_once 'plc_functions.php';
17 require_once 'plc_sorts.php';
20 $_person= $plc->person;
21 $_roles= $_person['role_ids'];
23 //print_r( $_person );
25 // if no id, display list of attributes types
26 if( !$_GET['id'] && !$_GET['add'] && !$_GET['add_type'] && !$_GET['edit_type'] ) {
28 $attrib_types= $api->GetSliceTagTypes( NULL, array( "attribute_type_id", "name", "description", "min_role_id" ) );
30 // get role names for the min role_ids
31 foreach( $attrib_types as $attrib_type ) {
32 $roles= $api->GetRoles();
33 foreach( $roles as $role ) {
34 if( $attrib_type['min_role_id'] == $role['role_id'] )
35 $role_name= $role['name'];
38 $attrib_type_info[]= array( "attribute_type_id" => $attrib_type['attribute_type_id'], "name" => $attrib_type['name'], "description" => $attrib_type['description'], "min_role" => $role_name );
42 echo "<h2>Slice Attribute Types</h2>\n";
44 echo "<table cellpadding=2><thead><tr><th>Name</th><th>Min Role</th><th>Description</th>";
45 // if admin we need to more cells
46 if( in_array( "10", $_person['role_ids'] ) )
47 echo "<th></th><th></th>";
48 echo "</thead><tbody>";
50 foreach( $attrib_type_info as $type ) {
51 echo "<tr><td>". $type['name'] ."</td><td>". $type['min_role'] ."</td><td>". $type['description'] ."</td>";
52 // if admin display edit/delet links
53 if( in_array( "10", $_person['role_ids'] ) ) {
54 echo "<td><a href='attributes.php?edit_type=". $type['attribute_type_id'] ."'>Edit</a></td>";
56 echo plc_delete_link_button ('attrib_action.php?del_type='. $type['attribute_type_id'],
64 echo "</tbody></table>\n";
66 if( in_array( "10", $_person['role_ids'] ) )
67 echo "<p><a href='attributes.php?add_type=1'>Add an Attribute Type</a>";
70 elseif( $_GET['add_type'] || $_GET['edit_type'] ) {
71 // if its edit get the attribute info
72 if( $_GET['edit_type'] ) {
73 $type_id= intval( $_GET['edit_type'] );
74 $type_info= $api->GetSliceTagTypes( array( $type_id ) );
76 $name= $type_info[0]['name'];
77 $min_role_id= $type_info[0]['min_role_id'];
78 $description= $type_info[0]['description'];
82 // display form for attribute types
83 echo "<form action='attrib_action.php' method='post'>\n";
84 echo "<h2>Add Attribute Type</h2>\n";
85 echo "<p><strong>Name: </strong> <input type=text name='name' size=20 value='$name'>\n";
86 echo "<p><strong>Min Role: </strong><select name='min_role_id'>\n";
87 echo "<option value='10'"; if( $min_role_id == 10 ) echo " selected"; echo ">Admin</option>\n";
88 echo "<option value='20'"; if( $min_role_id == 20 ) echo " selected"; echo ">PI</option>\n";
89 echo "<option value='30'"; if( $min_role_id == 30 ) echo " selected"; echo ">User</option>\n";
90 echo "<option value='40'"; if( $min_role_id == 40 ) echo " selected"; echo ">Tech</option>\n";
92 echo "<p><strong>Description: </strong><br>\n";
93 echo "<textarea name='description' cols=40 rows=5>$description</textarea>\n";
94 echo "<p><input type=submit ";
95 if( $_GET['edit_type'] ) {
96 echo "name='edit_type' value='Edit Attribute Type'>\n";
97 echo "<input type=hidden name='attribute_type_id' value='$type_id'>\n";
100 echo "name='add_type' value='Add Attribute Type'>\n";
105 elseif( $_GET['add'] ) {
106 // get slice id from GET
107 $slice_id= intval( $_GET['add'] );
109 // get all attribute types
110 $attrib_types= $api->GetSliceTagTypes( NULL, array( "attribute_type_id", "name" ) );
112 foreach( $attrib_types as $attrib_type ) {
113 $all_attribs[$attrib_type['attribute_type_id']]= $attrib_type['name'];
116 // get slice's attribute types
117 $slice_info= $api->GetSlices( array( $slice_id ), array( "slice_tag_ids" ) );
118 $attrib_info= $api->GetSliceTags( $slice_info[0]['slice_tag_ids'], array( "attribute_type_id", "name" ) );
120 foreach( $attrib_info as $info ) {
121 $slice_attrib_types[$info['attribute_type_id']]= $info['name'];
125 $attribute_types= $all_attribs;
128 echo "<form action='attrib_action.php' method='post'>\n";
129 echo "<h2>Edit ". $slice_info[0]['name'] ." attribute: ". $attrib_type[0]['name'] ."</h2>\n";
131 echo "<select name='attribute_type_id'><option value=''>Choose a type to add</option>\n";
133 foreach( $attribute_types as $key => $val ) {
134 echo "<option value='". $key ."'>". $val ."</option>\n";
139 echo "<p><strong>Value: </strong><input type=text name='value'>\n";
141 echo "<p><input type=submit name='add_attribute' value='Add Attribute'>\n";
142 echo "<input type=hidden name='slice_id' value='$slice_id'>\n";
147 $attribute_id= intval( $_GET['id'] );
149 // get attribute info
150 $slice_attib= $api->GetSliceTags( array( $attribute_id ), array( "slice_id", "slice_tag_id", "attribute_type_id", "value", "description", "min_role_id" ) );
153 $attrib_type= $api->GetSliceTagTypes( array( $slice_attib[0]['attribute_type_id'] ), array( "attribute_type_id", "name", "description" ) );
156 $slice_info= $api->GetSlices( array( $slice_attib[0]['slice_id'] ), array( "name" ) );
158 // start form and put values in to be edited.
159 echo "<form action='attrib_action.php' method='post'>\n";
160 echo "<h2>Edit ". $slice_info[0]['name'] ." attribute: ". $attrib_type[0]['name'] ."</h2>\n";
162 echo $slice_attib[0]['description'] ."<br />\n";
163 echo "<strong>Value:</strong> <input type=text name=value value='". $slice_attib[0]['value'] ."'><br /><br />\n";
165 echo "<input type=submit value='Edit Attribute' name='edit_attribute'>\n";
166 echo "<input type=hidden name='slice_id' value='". $slice_attib[0]['slice_id'] ."'>\n";
167 echo "<input type=hidden name='attribute_id' value='". $attribute_id ."'>\n";
172 echo "<p><a href='index.php?id=$slice_id'>Back to Slices</a>\n";
175 include 'plc_footer.php';