Changeset 12662
- Timestamp:
- 10/04/07 19:32:24 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midgard.admin.acl/acl_editor.php
r5538 r12662 52 52 * @access private 53 53 */ 54 var $_privileges = Array(); 54 var $_privileges = array(); 55 56 var $_header = ''; 57 var $_row_labels = array(); 58 var $_rendered_row_labels = array(); 55 59 56 60 function midgard_admin_acl_editor_plugin() 57 { 61 { 58 62 parent::midcom_baseclasses_components_handler(); 59 63 60 64 $this->_privileges[] = 'midgard:read'; 61 65 $this->_privileges[] = 'midgard:create'; … … 71 75 $this->_privileges[] = 'midcom:approve'; 72 76 } 77 78 $_MIDCOM->enable_jquery(); 79 $script = "function submit_privileges(form){jQuery('#submit_action',form).attr({name: 'midcom_helper_datamanager2_save', value: 'Save'});form.submit();};"; 80 $_MIDCOM->add_jscript($script); 73 81 } 74 82 … … 194 202 // Populate all resources having existing privileges 195 203 $existing_privileges = $this->_object->get_privileges(); 204 196 205 foreach ($existing_privileges as $privilege) 197 206 { … … 201 210 { 202 211 // This is a magic assignee 203 $ assignees[$privilege->assignee] = $_MIDCOM->i18n->get_string($privilege->assignee, 'midgard.admin.acl');212 $label = $_MIDCOM->i18n->get_string($privilege->assignee, 'midgard.admin.acl'); 204 213 } 205 214 else 206 215 { 207 $assignees[$privilege->assignee] = $assignee->name; 216 $label = $assignee->name; 217 } 218 $assignees[$privilege->assignee] = $label; 219 220 $key = str_replace(':', '_', $privilege->assignee); 221 if (! isset($this->_row_labels[$key])) 222 { 223 $this->_row_labels[$key] = $label; 208 224 } 209 225 … … 218 234 $this->_schemadb['privileges']->fields['add_assignee']['type_config']['options'] = $additional_assignees; 219 235 220 //$sitegroup = mgd_get_sitegroup($_MIDGARD['sitegroup']); 236 $header = "<table width=\"100%\" border=\"0\">\n"; 237 $header_start = "<tr>\n"; 238 $header_end = "</tr>\n"; 239 $header_items = array(); 240 241 $header .= $header_start; 221 242 222 243 foreach ($assignees as $assignee => $label) 223 244 { 224 $prepended = false;245 225 246 foreach ($this->_privileges as $privilege) 226 247 { 227 $prepend = '';228 if (!$prepended)229 {230 $prepend = "<h3 style='clear: left;'>{$label}</h3>\n";231 $prepended = true;232 }233 $prepend .= '<fieldset class="radio">';234 $append = '</fieldset>';235 248 236 249 $privilege_components = explode(':', $privilege); … … 246 259 $privilege_label = $_MIDCOM->i18n->get_string("privilege {$privilege_components[1]}", $privilege_components[0]); 247 260 } 248 261 262 if (! isset($header_items[$privilege_label])) 263 { 264 $header_items[$privilege_label] = "<th scope=\"col\">{$_MIDCOM->i18n->get_string($privilege_label, 'midgard.admin.acl')}</th>\n"; 265 } 266 249 267 $this->_schemadb['privileges']->append_field(str_replace(':', '_', $assignee) . '_' . str_replace(':', '_', str_replace('.', '_', $privilege)), Array 250 268 ( 251 'title' => $privilege_label,269 'title' => $privilege_label, 252 270 'helptext' => sprintf($_MIDCOM->i18n->get_string('sets privilege %s', 'midgard.admin.acl'), $privilege), 253 'storage' => null,254 'type' => 'privilege',271 'storage' => null, 272 'type' => 'privilege', 255 273 'type_config' => Array 256 274 ( … … 258 276 'assignee' => $assignee, 259 277 ), 260 'widget' => 'privilege', 261 'static_prepend' => $prepend, 262 'static_append' => $append, 278 'widget' => 'privilegeselection', 263 279 ) 264 280 ); 265 281 } 266 282 } 283 $header .= "<th align=\"left\" scope=\"col\"> </th>\n"; 284 foreach ($header_items as $key => $item) 285 { 286 $header .= $item; 287 } 288 $header .= $header_end; 289 $this->_header = $header; 267 290 } 268 291 … … 288 311 function _handler_edit($handler_id, $args, &$data) 289 312 { 313 $_MIDCOM->auth->require_valid_user(); 314 290 315 $this->_object = $_MIDCOM->dbfactory->get_object_by_guid($args[0]); 291 316 if (!$this->_object) … … 295 320 $this->_object->require_do('midgard:privileges'); 296 321 297 if (! is_a($this->_object, 'midcom_baseclasses_database_topic'))322 if (! is_a($this->_object, 'midcom_baseclasses_database_topic')) 298 323 { 299 324 $_MIDCOM->bind_view_to_object($this->_object); … … 321 346 // This will exit. 322 347 } 323 324 348 case 'cancel': 325 349 $_MIDCOM->relocate($_MIDCOM->permalinks->create_permalink($this->_object->guid)); … … 367 391 } 368 392 $data['title'] = sprintf($_MIDCOM->i18n->get_string('permissions for %s %s', 'midgard.admin.acl'), $type, $this->_resolve_object_title($this->_object)); 369 $_MIDCOM->set_pagetitle($data['title']); 370 371 // $_MIDCOM->set_pagetitle(sprintf($this->_request_data['l10n']->get('interview %s'), $this->_object->title)); 393 $_MIDCOM->set_pagetitle($data['title']); 372 394 373 395 return true; … … 377 399 { 378 400 echo "<h1>{$data['title']}</h1>\n"; 379 $this->_controller->display_form(); 401 402 // var_dump($this->_controller->formmanager->form, 1); 403 404 $form_start = "<form "; 405 foreach ($this->_controller->formmanager->form->_attributes as $key => $value) 406 { 407 $form_start .= "{$key}=\"{$value}\" "; 408 } 409 $form_start .= "/>\n"; 410 echo $form_start; 411 412 $table_start = "<table width=\"100%\" border=\"0\">\n"; 413 echo $table_start; 414 415 $priv_item_cnt = count($this->_privileges); 416 417 foreach ($this->_controller->formmanager->form->_elements as $i => $row) 418 { 419 if (is_a($row, 'HTML_QuickForm_hidden')) 420 { 421 $html = "<input type=\"hidden\" "; 422 foreach ($row->_attributes as $key => $value) 423 { 424 $html .= "{$key}=\"{$value}\" "; 425 } 426 $html .= "/>\n"; 427 echo $html; 428 } 429 430 if (is_a($row, 'HTML_QuickForm_select')) 431 { 432 $html = "<tr></td>\n"; 433 $html .= "<label for=\"{$row->_attributes['id']}\">\n<span class=\"field_text\">{$row->_label}</span>\n"; 434 $html .= $this->_render_select($row); 435 $html .= "</label>\n"; 436 $html .= "</td></tr>\n"; 437 438 echo $html; 439 440 $this->_render_header(); 441 } 442 443 if (is_a($row, 'HTML_QuickForm_group')) 444 { 445 $html = ''; 446 447 if ($row->_name == 'form_toolbar') 448 { 449 $html .= "<tr><td>\n"; 450 foreach ($row->_elements as $k => $element) 451 { 452 if (is_a($element, 'HTML_QuickForm_submit')) 453 { 454 $html .= $this->_render_button($element); 455 } 456 $html .= $row->_separator; 457 } 458 $html .= "</td></tr>\n"; 459 460 echo $html; 461 continue; 462 } 463 464 $label = $this->_render_row_label($row->_name); 465 $html .= $label; 466 467 foreach ($row->_elements as $k => $element) 468 { 469 if (is_a($element, 'HTML_QuickForm_select')) 470 { 471 $html .= $this->_render_select($element); 472 } 473 if (is_a($element, 'HTML_QuickForm_static')) 474 { 475 if (strpos($element->_attributes['name'], 'holder_start') !== false) 476 { 477 $html .= '<td align="center">'; 478 } 479 480 $html .= $this->_render_static($element); 481 if (strpos($element->_attributes['name'], 'initscripts') !== false) 482 { 483 $html .= '</td>'; 484 } 485 } 486 487 } 488 489 if ($i == $priv_item_cnt+1) 490 { 491 $html .= "</tr>\n"; 492 } 493 494 echo $html; 495 } 496 } 497 498 $table_end = '</table>'; 499 echo $table_end; 500 501 echo "<input type=\"hidden\" name=\"\" value=\"\" id=\"submit_action\"/>\n"; 502 503 echo "</form>\n"; 504 } 505 506 function _render_select($object) 507 { 508 $html = ''; 509 $element_name = ''; 510 511 $html .= "<select "; 512 foreach ($object->_attributes as $key => $value) 513 { 514 $html .= "{$key}=\"{$value}\" "; 515 if ($key == 'name') 516 { 517 $element_name = $value; 518 } 519 } 520 $html .= ">\n"; 521 522 $selected_val = ''; 523 if (isset($this->_controller->formmanager->form->_defaultValues[$element_name])) 524 { 525 $selected_val = $this->_controller->formmanager->form->_defaultValues[$element_name]; 526 } 527 if (isset($this->_controller->formmanager->form->_submitValues[$element_name])) 528 { 529 $selected_val = $this->_controller->formmanager->form->_submitValues[$element_name]; 530 } 531 532 foreach ($object->_options as $k => $item) 533 { 534 $selected = ''; 535 if ( $selected_val != '' 536 && $selected_val == $item['attr']['value']) 537 { 538 $selected = 'selected="selected"'; 539 } 540 541 $html .= "<option value=\"{$item['attr']['value']}\" {$selected}>{$item['text']}</option>\n"; 542 } 543 544 $html .= "</select>\n"; 545 546 return $html; 547 } 548 549 function _render_button($object) 550 { 551 $html = "<input type=\"$object->_type\" "; 552 foreach ($object->_attributes as $key => $value) 553 { 554 $html .= "{$key}=\"{$value}\" "; 555 if ($key == 'name') 556 { 557 $element_name = $value; 558 } 559 } 560 $html .= ">\n"; 561 562 return $html; 563 } 564 565 function _render_static($object) 566 { 567 $html = $object->_text; 568 569 return $html; 570 } 571 572 function _render_header() 573 { 574 if ($this->_header != '') 575 { 576 echo $this->_header; 577 $this->_header = ''; 578 } 579 } 580 581 function _render_row_label($row_name) 582 { 583 foreach ($this->_row_labels as $key => $label) 584 { 585 if ( strpos($row_name, $key) !== false 586 && !isset($this->_rendered_row_labels[$key])) 587 { 588 $this->_rendered_row_labels[$key] = true; 589 590 $actions = "<div class=\"actions\" id=\"privilege_row_actions_{$key}\">"; 591 $actions .= "<script type=\"text/javascript\">"; 592 $actions .= "jQuery('#privilege_row_{$key}').privilege_actions('{$key}');"; 593 $actions .= "</script>"; 594 $actions .= "</div>"; 595 596 return "<tr id=\"privilege_row_{$key}\">\n<td align=\"left\">{$actions}{$label}</td>\n"; 597 } 598 } 599 600 return ''; 380 601 } 381 602 } trunk/midcom/midgard.admin.acl/config/schemadb_default.inc
r4121 r12662 20 20 ), 21 21 'widget' => 'select', 22 'widget_config' => array 23 ( 24 'jsevents' => array 25 ( 26 'onchange' => 'submit_privileges(this.form);', 27 ), 28 ), 22 29 ), 23 30 // This is dynamically filled later
