00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class StudentThesisForm extends Form {
00021
00023 var $validDegrees;
00024
00026 var $captchaEnabled;
00027
00029 var $uploadCodeEnabled;
00030
00035 function StudentThesisForm($thesisId = null) {
00036 $journal = &Request::getJournal();
00037 $journalId = $journal->getJournalId();
00038 $thesisPlugin = &PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00039 $thesisPlugin->import('Thesis');
00040
00041 $this->validDegrees = array (
00042 THESIS_DEGREE_MASTERS => Locale::translate('plugins.generic.thesis.manager.degree.masters'),
00043 THESIS_DEGREE_DOCTORATE => Locale::translate('plugins.generic.thesis.manager.degree.doctorate')
00044 );
00045
00046 import('captcha.CaptchaManager');
00047 $captchaManager =& new CaptchaManager();
00048 $this->captchaEnabled = $captchaManager->isEnabled() ? true : false;
00049
00050 $this->uploadCodeEnabled = $thesisPlugin->getSetting($journalId, 'enableUploadCode');
00051
00052 parent::Form($thesisPlugin->getTemplatePath() . 'studentThesisForm.tpl');
00053
00054
00055
00056 if ($this->captchaEnabled) {
00057 $this->addCheck(new FormValidatorCaptcha($this, 'captcha', 'captchaId', 'common.captchaField.badCaptcha'));
00058 }
00059
00060
00061 $this->addCheck(new FormValidator($this, 'degree', 'required', 'plugins.generic.thesis.form.degreeRequired'));
00062 $this->addCheck(new FormValidatorInSet($this, 'degree', 'required', 'plugins.generic.thesis.form.degreeValid', array_keys($this->validDegrees)));
00063
00064
00065 $this->addCheck(new FormValidator($this, 'degreeName', 'required', 'plugins.generic.thesis.form.degreeNameRequired'));
00066
00067
00068 $this->addCheck(new FormValidator($this, 'department', 'required', 'plugins.generic.thesis.form.departmentRequired'));
00069
00070
00071 $this->addCheck(new FormValidator($this, 'university', 'required', 'plugins.generic.thesis.form.universityRequired'));
00072
00073
00074 $this->addCheck(new FormValidator($this, 'dateApprovedYear', 'required', 'plugins.generic.thesis.form.dateApprovedRequired'));
00075 $this->addCheck(new FormValidatorCustom($this, 'dateApprovedYear', 'required', 'plugins.generic.thesis.form.dateApprovedValid', create_function('$dateApprovedYear', '$minYear = date(\'Y\') + THESIS_APPROVED_YEAR_OFFSET_PAST; $maxYear = date(\'Y\'); return ($dateApprovedYear >= $minYear && $dateApprovedYear <= $maxYear) ? true : false;')));
00076
00077 $this->addCheck(new FormValidator($this, 'dateApprovedMonth', 'required', 'plugins.generic.thesis.form.dateApprovedRequired'));
00078 $this->addCheck(new FormValidatorCustom($this, 'dateApprovedMonth', 'required', 'plugins.generic.thesis.form.dateApprovedValid', create_function('$dateApprovedMonth', 'return ($dateApprovedMonth >= 1 && $dateApprovedMonth <= 12) ? true : false;')));
00079
00080 $this->addCheck(new FormValidator($this, 'dateApprovedDay', 'required', 'plugins.generic.thesis.form.dateApprovedRequired'));
00081 $this->addCheck(new FormValidatorCustom($this, 'dateApprovedDay', 'required', 'plugins.generic.thesis.form.dateApprovedValid', create_function('$dateApprovedDay', 'return ($dateApprovedDay >= 1 && $dateApprovedDay <= 31) ? true : false;')));
00082
00083
00084 $this->addCheck(new FormValidator($this, 'title', 'required', 'plugins.generic.thesis.form.titleRequired'));
00085
00086
00087 $this->addCheck(new FormValidator($this, 'studentFirstName', 'required', 'plugins.generic.thesis.form.studentFirstNameRequired'));
00088
00089
00090 $this->addCheck(new FormValidator($this, 'studentLastName', 'required', 'plugins.generic.thesis.form.studentLastNameRequired'));
00091
00092
00093 $this->addCheck(new FormValidatorEmail($this, 'studentEmail', 'required', 'plugins.generic.thesis.form.studentEmailValid'));
00094
00095
00096 $this->addCheck(new FormValidator($this, 'supervisorFirstName', 'required', 'plugins.generic.thesis.form.supervisorFirstNameRequired'));
00097
00098
00099 $this->addCheck(new FormValidator($this, 'supervisorLastName', 'required', 'plugins.generic.thesis.form.supervisorLastNameRequired'));
00100
00101
00102 $this->addCheck(new FormValidatorEmail($this, 'supervisorEmail', 'required', 'plugins.generic.thesis.form.supervisorEmailValid'));
00103
00104
00105 $this->addCheck(new FormValidator($this, 'abstract', 'required', 'plugins.generic.thesis.form.abstractRequired'));
00106
00107 $this->addCheck(new FormValidatorPost($this));
00108 }
00109
00113 function display() {
00114 $thesisPlugin = &PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00115 $thesisPlugin->import('Thesis');
00116 $templateMgr = &TemplateManager::getManager();
00117
00118 if ($this->captchaEnabled) {
00119 import('captcha.CaptchaManager');
00120 $captchaManager =& new CaptchaManager();
00121 $captcha =& $captchaManager->createCaptcha();
00122 if ($captcha) {
00123 $templateMgr->assign('captchaEnabled', $this->captchaEnabled);
00124 $this->setData('captchaId', $captcha->getCaptchaId());
00125 }
00126 }
00127
00128 $templateMgr->assign('uploadCodeEnabled', $this->uploadCodeEnabled);
00129 $templateMgr->assign('validDegrees', $this->validDegrees);
00130 $templateMgr->assign('yearOffsetPast', THESIS_APPROVED_YEAR_OFFSET_PAST);
00131
00132 parent::display();
00133 }
00134
00138 function initData() {
00139 }
00140
00144 function readInputData() {
00145 $userVars = array(
00146 'degree',
00147 'degreeName',
00148 'department',
00149 'university',
00150 'dateApprovedYear',
00151 'dateApprovedMonth',
00152 'dateApprovedDay',
00153 'title',
00154 'url',
00155 'abstract',
00156 'uploadCode',
00157 'comment',
00158 'studentFirstName',
00159 'studentMiddleName',
00160 'studentLastName',
00161 'studentEmail',
00162 'studentEmailPublish',
00163 'studentBio',
00164 'supervisorFirstName',
00165 'supervisorMiddleName',
00166 'supervisorLastName',
00167 'supervisorEmail',
00168 'discipline',
00169 'subjectClass',
00170 'keyword',
00171 'coverageGeo',
00172 'coverageChron',
00173 'coverageSample',
00174 'method',
00175 'language'
00176 );
00177
00178 if ($this->captchaEnabled) {
00179 $userVars[] = 'captchaId';
00180 $userVars[] = 'captcha';
00181 }
00182
00183 $this->readUserVars($userVars);
00184 $this->_data['dateApproved'] = $this->_data['dateApprovedYear'] . '-' . $this->_data['dateApprovedMonth'] . '-' . $this->_data['dateApprovedDay'];
00185
00186
00187 if (!empty($this->_data['url'])) {
00188 $this->addCheck(new FormValidatorCustom($this, 'url', 'required', 'plugins.generic.thesis.form.urlPrefixIncluded', create_function('$url', 'return strpos(trim(strtolower($url)), \'http://\') === 0 || strpos(trim(strtolower($url)), \'ftp://\') === 0 ? true : false;'), array()));
00189 }
00190
00191 }
00192
00196 function execute() {
00197 $thesisPlugin = &PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00198 $thesisPlugin->import('Thesis');
00199
00200 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00201 $journal = &Request::getJournal();
00202 $journalId = $journal->getJournalId();
00203
00204 $thesis = &new Thesis();
00205
00206 $thesis->setJournalId($journalId);
00207 $thesis->setStatus(THESIS_STATUS_INACTIVE);
00208 $thesis->setDegree($this->getData('degree'));
00209 $thesis->setDegreeName($this->getData('degreeName'));
00210 $thesis->setDepartment($this->getData('department'));
00211 $thesis->setUniversity($this->getData('university'));
00212 $thesis->setTitle($this->getData('title'));
00213 $thesis->setDateApproved($this->getData('dateApprovedYear') . '-' . $this->getData('dateApprovedMonth') . '-' . $this->getData('dateApprovedDay'));
00214 $thesis->setUrl(strtolower($this->getData('url')));
00215 $thesis->setAbstract($this->getData('abstract'));
00216 $thesis->setComment($this->getData('comment'));
00217 $thesis->setStudentFirstName($this->getData('studentFirstName'));
00218 $thesis->setStudentMiddleName($this->getData('studentMiddleName'));
00219 $thesis->setStudentLastName($this->getData('studentLastName'));
00220 $thesis->setStudentEmail($this->getData('studentEmail'));
00221 $thesis->setStudentEmailPublish($this->getData('studentEmailPublish') == null ? 0 : 1);
00222 $thesis->setStudentBio($this->getData('studentBio'));
00223 $thesis->setSupervisorFirstName($this->getData('supervisorFirstName'));
00224 $thesis->setSupervisorMiddleName($this->getData('supervisorMiddleName'));
00225 $thesis->setSupervisorLastName($this->getData('supervisorLastName'));
00226 $thesis->setSupervisorEmail($this->getData('supervisorEmail'));
00227 $thesis->setDiscipline($this->getData('discipline'));
00228 $thesis->setSubjectClass($this->getData('subjectClass'));
00229 $thesis->setSubject($this->getData('keyword'));
00230 $thesis->setCoverageGeo($this->getData('coverageGeo'));
00231 $thesis->setCoverageChron($this->getData('coverageChron'));
00232 $thesis->setCoverageSample($this->getData('coverageSample'));
00233 $thesis->setMethod($this->getData('method'));
00234 $thesis->setLanguage($this->getData('language'));
00235 $thesis->setDateSubmitted(Core::getCurrentDate());
00236
00237 $thesisDao->insertThesis($thesis);
00238
00239
00240 if (!empty($this->uploadCodeEnabled)) {
00241 $uploadCode = $thesisPlugin->getSetting($journalId, 'uploadCode');
00242 $submittedUploadCode = $this->getData('uploadCode');
00243 }
00244
00245 if (empty($uploadCode) || ($uploadCode != $submittedUploadCode)) {
00246 $journalName = $journal->getJournalTitle();
00247 $thesisName = $thesisPlugin->getSetting($journalId, 'thesisName');
00248 $thesisEmail = $thesisPlugin->getSetting($journalId, 'thesisEmail');
00249 $thesisPhone = $thesisPlugin->getSetting($journalId, 'thesisPhone');
00250 $thesisFax = $thesisPlugin->getSetting($journalId, 'thesisFax');
00251 $thesisMailingAddress = $thesisPlugin->getSetting($journalId, 'thesisMailingAddress');
00252 $thesisContactSignature = $thesisName;
00253
00254 if (!empty($thesisMailingAddress)) {
00255 $thesisContactSignature .= "\n" . $thesisMailingAddress;
00256 }
00257 if (!empty($thesisPhone)) {
00258 $thesisContactSignature .= "\n" . Locale::Translate('user.phone') . ': ' . $thesisPhone;
00259 }
00260 if (!empty($thesisFax)) {
00261 $thesisContactSignature .= "\n" . Locale::Translate('user.fax') . ': ' . $thesisFax;
00262 }
00263
00264 $thesisContactSignature .= "\n" . Locale::Translate('user.email') . ': ' . $thesisEmail;
00265 $studentName = $thesis->getStudentFirstName() . ' ' . $thesis->getStudentLastName();
00266 $supervisorName = $thesis->getSupervisorFirstName() . ' ' . $thesis->getSupervisorLastName();
00267
00268 $paramArray = array(
00269 'journalName' => $journalName,
00270 'thesisName' => $thesisName,
00271 'thesisEmail' => $thesisEmail,
00272 'title' => $thesis->getTitle(),
00273 'studentName' => $studentName,
00274 'degree' => Locale::Translate($thesis->getDegreeString()),
00275 'degreeName' => $thesis->getDegreeName(),
00276 'department' => $thesis->getDepartment(),
00277 'university' => $thesis->getUniversity(),
00278 'dateApproved' => $thesis->getDateApproved(),
00279 'supervisorName' => $supervisorName,
00280 'abstract' => $thesis->getAbstract(),
00281 'thesisContactSignature' => $thesisContactSignature
00282 );
00283
00284 import('mail.MailTemplate');
00285 $mail = &new MailTemplate('THESIS_ABSTRACT_CONFIRM');
00286 $mail->setFrom($thesisEmail, "\"" . $thesisName . "\"");
00287 $mail->assignParams($paramArray);
00288 $mail->addRecipient($thesis->getSupervisorEmail(), "\"" . $supervisorName . "\"");
00289 $mail->addCc($thesis->getStudentEmail(), "\"" . $studentName . "\"");
00290 $mail->send();
00291 }
00292
00293 }
00294
00295 }
00296
00297 ?>