Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ContextSiteSettingsForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.db.DBDataXMLParser');
17 import('lib.pkp.classes.form.Form');
18 
20 
23 
29  parent::Form('admin/contextSettings.tpl');
30 
31  $this->contextId = isset($contextId) ? (int) $contextId : null;
32 
33  // Validation checks for this form
34  $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'admin.contexts.form.titleRequired'));
35  $this->addCheck(new FormValidator($this, 'path', 'required', 'admin.contexts.form.pathRequired'));
36  $this->addCheck(new FormValidatorAlphaNum($this, 'path', 'required', 'admin.contexts.form.pathAlphaNumeric'));
37  $this->addCheck(new FormValidatorCustom($this, 'path', 'required', 'admin.contexts.form.pathExists', create_function('$path,$form,$contextDao', 'return !$contextDao->existsByPath($path) || ($form->getData(\'oldPath\') != null && $form->getData(\'oldPath\') == $path);'), array(&$this, Application::getContextDAO())));
38  $this->addCheck(new FormValidatorPost($this));
39  }
40 
44  function fetch($args, $request) {
45  $json = new JSONMessage();
46 
47  $templateMgr = TemplateManager::getManager($request);
48  $templateMgr->assign('contextId', $this->contextId);
49 
50  return parent::fetch($request);
51  }
52 
56  function initData() {
57  if (isset($this->contextId)) {
58  $contextDao = Application::getContextDAO();
59  $context = $contextDao->getById($this->contextId);
60 
61  $this->setData('name', $context->getName(null));
62  $this->setData('description', $context->getDescription(null));
63  $this->setData('path', $context->getPath());
64  $this->setData('enabled', $context->getEnabled());
65  } else {
66  $this->setData('enabled', 1);
67  }
68  }
69 
73  function readInputData() {
74  $this->readUserVars(array('name', 'description', 'path', 'enabled'));
75 
76  if ($this->contextId) {
77  $contextDao = Application::getContextDAO();
78  $context = $contextDao->getById($this->contextId);
79  if ($context) $this->setData('oldPath', $context->getPath());
80  }
81  }
82 
87  function getLocaleFieldNames() {
88  return array('name', 'description');
89  }
90 
96  AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_PKP_DEFAULT);
97  // Install default user groups
98  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
99  $userGroupDao->installSettings($contextId, 'registry/userGroups.xml');
100  }
101 
107  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
108  $sessionManager = SessionManager::getManager();
109  $userSession = $sessionManager->getUserSession();
110  if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($contextId)) {
111  // get the default site admin user group
112  $managerUserGroup = $userGroupDao->getDefaultByRoleId($contextId, ROLE_ID_MANAGER);
113  $userGroupDao->assignUserToGroup($userSession->getUserId(), $managerUserGroup->getId());
114  }
115  }
116 }
117 
118 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
Form validation check with a custom user function performing the validation check.
Form validation check to make sure the form is POSTed.
static requireComponents()
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
Class to represent a JSON (Javascript Object Notation) message.
Class to represent a form validation check for localized fields.
Form validation check for alphanumeric (plus interior dash/underscore) characters only...
Class to represent a form validation check.
static getContextDAO()
Form for site administrator to edit basic context settings.