Changeset 1249 for trunk/wifidog-auth/wifidog/classes/ProfileTemplate.php
- Timestamp:
- 07/12/07 16:05:42 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/ProfileTemplate.php
r1194 r1249 43 43 * @link http://www.wifidog.org/ 44 44 */ 45 45 46 46 require_once ('classes/ProfileTemplateField.php'); 47 47 require_once ('classes/ContentTypeFilter.php'); … … 52 52 53 53 private $id = null; 54 private $ mRow;54 private $_row; 55 55 56 56 private function __construct($profile_template_id) … … 69 69 } 70 70 71 $this-> mRow = $row;71 $this->_row = $row; 72 72 $this->id = $db->escapeString($row['profile_template_id']); 73 73 } … … 85 85 * @access public 86 86 */ 87 public static function getObject($id)87 public static function &getObject($id) 88 88 { 89 89 if(!isset(self::$instanceArray[$id])) … … 141 141 public function getLabel() 142 142 { 143 return $this-> mRow['profile_template_label'];143 return $this->_row['profile_template_label']; 144 144 } 145 145 … … 177 177 public function getCreationDate() 178 178 { 179 return $this-> mRow['creation_date'];179 return $this->_row['creation_date']; 180 180 } 181 181 … … 251 251 252 252 /** 253 * Get an interface to pick a ContentTypeFilter253 * Get an interface to pick an object of this class 254 254 * 255 255 * If there is only one server available, no interface is actually shown … … 258 258 * programmer to recognise it's generated 259 259 * html form 260 * @param object $pre_content_type_filter An optional ContenTypeFilter object 261 * 262 * @param string $additional_where Additional SQL conditions for the 263 * servers to select 264 * 260 * @param string $userData=null Array of contextual data optionally sent to the method. 261 * The function must still function if none of it is present. 262 * 263 * This method understands: 264 * $userData['preSelectedId'] An optional ProfileTemplate object id. 265 * $userData['additionalWhere'] Additional SQL conditions for the 266 * objects to select 267 * $userData['typeInterface'] 'select' or 'add'. 'select' is the default 265 268 * @return string HTML markup 266 269 267 270 */ 268 public static function getSelect ProfileTemplateUI($user_prefix, $pre_selected_profile_template = null, $additional_where = null, $type_interface = "select")271 public static function getSelectUI($user_prefix, $userData=null) 269 272 { 270 273 $db = AbstractDb::getObject(); … … 274 277 $_profile_template_rows = null; 275 278 276 if ($pre_selected_profile_template) { 277 $_selectedId = $pre_selected_profile_template->getId(); 278 } else { 279 $_selectedId = null; 280 } 281 282 $_sql = "SELECT * FROM profile_templates WHERE 1=1 $additional_where ORDER BY profile_template_label ASC"; 283 $db->execSql($_sql, $_profile_template_rows, false); 279 !empty($userData['preSelectedId'])?$selectedId=$userData['preSelectedId']:$selectedId=null; 280 !empty($userData['additionalWhere'])?$additional_where=$userData['additionalWhere']:$additional_where=null; 281 !empty($userData['typeInterface'])?$type_interface=$userData['typeInterface']:$type_interface=null; 282 283 $sql = "SELECT * FROM profile_templates WHERE 1=1 $additional_where ORDER BY profile_template_label ASC"; 284 $db->execSql($sql, $_profile_template_rows, false); 284 285 285 286 if ($_profile_template_rows != null) { … … 295 296 } 296 297 297 $_html .= FormSelectGenerator::generateFromArray($_tab, $ _selectedId, $_name, null, false);298 $_html .= FormSelectGenerator::generateFromArray($_tab, $selectedId, $_name, null, false); 298 299 299 300 if ($type_interface == "add") { … … 377 378 $html .= "<td colspan ='2'>\n"; 378 379 $name = "{$user_prefix}_new_existing"; 379 $profileTemplateSelector = self :: getSelect ProfileTemplateUI($name, null, "AND profile_template_id NOT IN (SELECT profile_template_id FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key')", "add");380 $profileTemplateSelector = self :: getSelectUI($name, Array('additionalWhere' => "AND profile_template_id NOT IN (SELECT profile_template_id FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key')", 'typeInterface' => "add")); 380 381 $html .= $profileTemplateSelector; 381 382 $html .= "</td>\n"; … … 448 449 public function getAdminUI() 449 450 { 451 Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 450 452 $db = AbstractDb::getObject(); 451 453 $sql = "SELECT COUNT(*) as num_used_profiles FROM profile_templates JOIN profiles USING (profile_template_id) WHERE profile_template_id = '" . $this->getId() . "'"; … … 453 455 454 456 // Init values 455 $ _html = '';456 457 $ _html .= "<fieldset class='admin_container ".get_class($this)."'>\n";458 $ _html .= "<legend>"._("Profile template management")."</legend>\n";459 $ _html .= "<ul class='admin_element_list'>\n";457 $html = ''; 458 459 $html .= "<fieldset class='admin_container ".get_class($this)."'>\n"; 460 $html .= "<legend>"._("Profile template management")."</legend>\n"; 461 $html .= "<ul class='admin_element_list'>\n"; 460 462 461 463 // profile_template_id 462 464 $_value = htmlspecialchars($this->getId(), ENT_QUOTES); 463 465 464 $ _html .= "<li class='admin_element_item_container'>\n";465 $ _html .= "<div class='admin_element_label'>" . _("ProfileTemplate ID") . ":</div>\n";466 $ _html .= "<div class='admin_element_data'>\n";467 $ _html .= $_value;468 $ _html .= "</div>\n";469 $ _html .= "</li>\n";466 $html .= "<li class='admin_element_item_container'>\n"; 467 $html .= "<div class='admin_element_label'>" . _("ProfileTemplate ID") . ":</div>\n"; 468 $html .= "<div class='admin_element_data'>\n"; 469 $html .= $_value; 470 $html .= "</div>\n"; 471 $html .= "</li>\n"; 470 472 471 473 // label … … 473 475 $_value = htmlspecialchars($this->getLabel(), ENT_QUOTES); 474 476 475 $ _html .= "<li class='admin_element_item_container'>\n";476 $ _html .= "<div class='admin_element_label'>" . _("Label") . ":</div>\n";477 $ _html .= "<div class='admin_element_data'>\n";478 $ _html .= "<input type='text' size='50' value='$_value' name='$_name'>\n";479 $ _html .= "</div>\n";480 $ _html .= "</li>\n";477 $html .= "<li class='admin_element_item_container'>\n"; 478 $html .= "<div class='admin_element_label'>" . _("Label") . ":</div>\n"; 479 $html .= "<div class='admin_element_data'>\n"; 480 $html .= "<input type='text' size='50' value='$_value' name='$_name'>\n"; 481 $html .= "</div>\n"; 482 $html .= "</li>\n"; 481 483 482 484 // creation date 483 485 $_value = htmlspecialchars($this->getCreationDate(), ENT_QUOTES); 484 486 485 $ _html .= "<li class='admin_element_item_container'>\n";486 $ _html .= "<div class='admin_element_label'>" . _("Creation date") . ":</div>\n";487 $ _html .= "<div class='admin_element_data'>\n";488 $ _html .= $_value;489 $ _html .= "</div>\n";490 $ _html .= "</li>\n";487 $html .= "<li class='admin_element_item_container'>\n"; 488 $html .= "<div class='admin_element_label'>" . _("Creation date") . ":</div>\n"; 489 $html .= "<div class='admin_element_data'>\n"; 490 $html .= $_value; 491 $html .= "</div>\n"; 492 $html .= "</li>\n"; 491 493 492 494 // profile template fields 493 $ _html .= "<li class='admin_element_item_container'>\n";494 $ _html .= "<fieldset class='admin_element_group'>\n";495 $ _html .= "<legend>"._("Profile template fields")."</legend>\n";496 497 $ _html .= "<ul class='admin_element_list'>\n";495 $html .= "<li class='admin_element_item_container'>\n"; 496 $html .= "<fieldset class='admin_element_group'>\n"; 497 $html .= "<legend>"._("Profile template fields")."</legend>\n"; 498 499 $html .= "<ul class='admin_element_list'>\n"; 498 500 foreach ($this->getFields() as $field) { 499 $ _html .= "<li class='admin_element_item_container'>\n";500 $ _html .= $field->getAdminUI(null, sprintf(_("%s %d"), get_class($field), $field->getDisplayOrder()));501 $ _html .= "<div class='admin_element_tools'>\n";501 $html .= "<li class='admin_element_item_container'>\n"; 502 $html .= $field->getAdminUI(null, sprintf(_("%s %d"), get_class($field), $field->getDisplayOrder())); 503 $html .= "<div class='admin_element_tools'>\n"; 502 504 $sql = "SELECT COUNT(*) as num_used_fields FROM profile_template_fields JOIN profile_fields USING (profile_template_field_id) WHERE profile_template_field_id = '" . $field->getId() . "'"; 503 505 $db->execSqlUniqueRes($sql, $num_used_fields_row, false); 504 506 $name = "profile_template_" . $this->id . "_field_" . $field->GetId() . "_erase"; 505 $ _html .= "<input type='submit' class='submit' name='$name' value='" . sprintf(_("Delete %s %d, used in %d/%d profiles"), get_class($field), $field->getDisplayOrder(), $num_used_fields_row['num_used_fields'], $num_used_profiles['num_used_profiles']) . "'>";506 $ _html .= "</div>\n";507 $ _html .= "</li>\n";508 } 509 $ _html .= "<li class='admin_element_item_container'>\n";510 $ _html .= ProfileTemplateField :: getCreateFieldUI("profile_template_{$this->id}_new_field");511 $ _html .= "</li>\n";512 $ _html .= "</ul>\n";513 $ _html .= "</fieldset>\n";514 $ _html .= "</li>\n";515 516 $ _html .= "</ul>\n";517 $ _html .= "</fieldset>\n";518 return $ _html;507 $html .= "<input type='submit' class='submit' name='$name' value='" . sprintf(_("Delete %s %d, used in %d/%d profiles"), get_class($field), $field->getDisplayOrder(), $num_used_fields_row['num_used_fields'], $num_used_profiles['num_used_profiles']) . "'>"; 508 $html .= "</div>\n"; 509 $html .= "</li>\n"; 510 } 511 $html .= "<li class='admin_element_item_container'>\n"; 512 $html .= ProfileTemplateField :: getCreateFieldUI("profile_template_{$this->id}_new_field"); 513 $html .= "</li>\n"; 514 $html .= "</ul>\n"; 515 $html .= "</fieldset>\n"; 516 $html .= "</li>\n"; 517 518 $html .= "</ul>\n"; 519 $html .= "</fieldset>\n"; 520 return $html; 519 521 } 520 522 … … 526 528 public function processAdminUI() 527 529 { 530 Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 528 531 require_once('classes/User.php'); 529 530 try {531 if (!User::getCurrentUser()->isSuperAdmin()) {532 throw new Exception(_('Access denied!'));533 }534 } catch (Exception $e) {535 $ui = MainUI::getObject();536 $ui->setToolSection('ADMIN');537 $ui->displayError($e->getMessage(), false);538 exit;539 }540 532 541 533 $errmsg = ""; … … 573 565 $_retVal = false; 574 566 575 if ( !User::getCurrentUser()->isSuperAdmin()) {576 $errmsg = _('Access denied (must have super admin access)');567 if (Security::hasPermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer())) { 568 $errmsg = _('Access denied'); 577 569 } else { 578 570 $_id = $db->escapeString($this->getId()); … … 600 592 } 601 593 594 /** Menu hook function */ 595 static public function hookMenu() { 596 $items = array(); 597 $server = Server::getServer(); 598 if(Security::hasPermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), $server)) 599 { 600 $items[] = array('path' => 'server/profile_templates', 601 'title' => _("Profile templates"), 602 'url' => BASE_URL_PATH."admin/generic_object_admin.php?object_class=ProfileTemplate&action=list" 603 ); 604 } 605 return $items; 606 } 602 607 } //end class 603 608 /*
