00001 <?php
00002
00016 import('lib.pkp.classes.form.Form');
00017
00018 class SponsorForm extends Form {
00020 var $sponsorId;
00021
00025 function SponsorForm($sponsorId = null) {
00026 $this->sponsorId = $sponsorId;
00027 parent::Form('controllers/grid/settings/sponsor/form/sponsorForm.tpl');
00028
00029
00030 $this->addCheck(new FormValidator($this, 'institution', 'required', 'manager.setup.form.sponsors.institutionRequired'));
00031 $this->addCheck(new FormValidatorUrl($this, 'url', 'required', 'manager.emails.form.sponsors.urlRequired'));
00032 $this->addCheck(new FormValidatorPost($this));
00033 }
00034
00040 function initData($args, &$request) {
00041 $press =& $request->getPress();
00042
00043 $sponsors = $press->getSetting('sponsors');
00044 if ( $this->sponsorId && isset($sponsors[$this->sponsorId]) ) {
00045 $this->_data = array(
00046 'sponsorId' => $this->sponsorId,
00047 'institution' => $sponsors[$this->sponsorId]['institution'],
00048 'url' => $sponsors[$this->sponsorId]['url']
00049 );
00050 } else {
00051 $this->_data = array(
00052 'institution' => '',
00053 'url' => ''
00054 );
00055 }
00056
00057
00058 $this->_data['gridId'] = $args['gridId'];
00059 $this->_data['rowId'] = isset($args['rowId']) ? $args['rowId'] : null;
00060 }
00061
00067 function fetch(&$request) {
00068 AppLocale::requireComponents(LOCALE_COMPONENT_OMP_MANAGER);
00069 $templateMgr =& TemplateManager::getManager();
00070 $templateMgr->assign('institution', $this->_data['institution']);
00071 $templateMgr->assign('url', $this->_data['url']);
00072 return parent::fetch($request);
00073 }
00074
00079 function readInputData() {
00080 $this->readUserVars(array('sponsorId', 'institution', 'url'));
00081 $this->readUserVars(array('gridId', 'rowId'));
00082 }
00083
00088 function execute($request) {
00089 $press =& $request->getPress();
00090 $sponsors = $press->getSetting('sponsors');
00091 if (empty($sponsors)) {
00092 $sponsors = array();
00093 $this->sponsorId = 1;
00094 } else {
00095
00096 $this->sponsorId = ($this->sponsorId?$this->sponsorId:(max(array_keys($sponsors)) + 1));
00097 }
00098 $sponsors[$this->sponsorId] = array('institution' => $this->getData('institution'),
00099 'url' => $this->getData('url'));
00100
00101 $press->updateSetting('sponsors', $sponsors, 'object', false);
00102 return true;
00103 }
00104 }
00105
00106 ?>