00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.GenericPlugin');
00019
00020 class ThesisPlugin extends GenericPlugin {
00021
00028 function register($category, $path) {
00029 $success = parent::register($category, $path);
00030 $this->addLocaleData();
00031 if ($success && $this->getEnabled()) {
00032 $this->import('ThesisDAO');
00033 $thesisDao = &new ThesisDAO();
00034 $returner = &DAORegistry::registerDAO('ThesisDAO', $thesisDao);
00035
00036
00037 HookRegistry::register('LoadHandler', array($this, 'setupPublicHandler'));
00038
00039
00040 HookRegistry::register('Templates::Common::Header::Navbar::CurrentJournal', array($this, 'displayHeaderLink'));
00041
00042
00043 HookRegistry::register('Templates::Manager::Index::ManagementPages', array($this, 'displayManagerLink'));
00044
00045
00046 HookRegistry::register('Templates::Search::SearchResults::PreResults', array($this, 'displaySearchLink'));
00047 }
00048 return $success;
00049 }
00050
00057 function getName() {
00058 return 'ThesisPlugin';
00059 }
00060
00061 function getDisplayName() {
00062 return Locale::translate('plugins.generic.thesis.displayName');
00063 }
00064
00065 function getDescription() {
00066 return Locale::translate('plugins.generic.thesis.description');
00067 }
00068
00072 function getInstallSchemaFile() {
00073 return $this->getPluginPath() . '/' . 'schema.xml';
00074 }
00075
00079 function getInstallDataFile() {
00080 return $this->getPluginPath() . '/' . 'data.xml';
00081 }
00082
00086 function smartyPluginUrl($params, &$smarty) {
00087 $path = array($this->getCategory(), $this->getName());
00088 if (is_array($params['path'])) {
00089 $params['path'] = array_merge($path, $params['path']);
00090 } elseif (!empty($params['path'])) {
00091 $params['path'] = array_merge($path, array($params['path']));
00092 } else {
00093 $params['path'] = $path;
00094 }
00095
00096 if (!empty($params['id'])) {
00097 $params['path'] = array_merge($params['path'], array($params['id']));
00098 unset($params['id']);
00099 }
00100 return $smarty->smartyUrl($params, $smarty);
00101 }
00102
00108 function setBreadcrumbs($isSubclass = false) {
00109 $templateMgr = &TemplateManager::getManager();
00110 $pageCrumbs = array(
00111 array(
00112 Request::url(null, 'user'),
00113 'navigation.user'
00114 ),
00115 array(
00116 Request::url(null, 'manager'),
00117 'user.role.manager'
00118 )
00119 );
00120 if ($isSubclass) $pageCrumbs[] = array(
00121 Request::url(null, 'manager', 'plugin', array('generic', $this->getName(), 'theses')),
00122 $this->getDisplayName(),
00123 true
00124 );
00125
00126 $templateMgr->assign('pageHierarchy', $pageCrumbs);
00127 }
00128
00132 function getManagementVerbs() {
00133 $verbs = array();
00134 if ($this->getEnabled()) {
00135 $verbs[] = array(
00136 'disable',
00137 Locale::translate('manager.plugins.disable')
00138 );
00139 $verbs[] = array(
00140 'theses',
00141 Locale::translate('plugins.generic.thesis.manager.theses')
00142 );
00143 $verbs[] = array(
00144 'settings',
00145 Locale::translate('plugins.generic.thesis.manager.settings')
00146 );
00147 } else {
00148 $verbs[] = array(
00149 'enable',
00150 Locale::translate('manager.plugins.enable')
00151 );
00152 }
00153 return $verbs;
00154 }
00155
00159 function getEnabled() {
00160 $journal = &Request::getJournal();
00161 if (!$journal) return false;
00162 return $this->getSetting($journal->getJournalId(), 'enabled');
00163 }
00164
00165 function setupPublicHandler($hookName, $params) {
00166 $page = &$params[0];
00167 if ($page == 'thesis') {
00168 define('HANDLER_CLASS', 'ThesisHandler');
00169 $handlerFile = &$params[2];
00170 $handlerFile = $this->getPluginPath() . '/' . 'ThesisHandler.inc.php';
00171 }
00172 }
00173
00174 function displayHeaderLink($hookName, $params) {
00175 if ($this->getEnabled()) {
00176 $smarty = &$params[1];
00177 $output = &$params[2];
00178 $output .= '<li><a href="' . TemplateManager::smartyUrl(array('page'=>'thesis'), $smarty) . '">' . TemplateManager::smartyTranslate(array('key'=>'plugins.generic.thesis.headerLink'), $smarty) . '</a></li>';
00179 }
00180 return false;
00181 }
00182
00183 function displayManagerLink($hookName, $params) {
00184 if ($this->getEnabled()) {
00185 $smarty = &$params[1];
00186 $output = &$params[2];
00187 $output .= '<li>» <a href="' . $this->smartyPluginUrl(array('op'=>'plugin', 'path'=>'theses'), $smarty) . '">' . TemplateManager::smartyTranslate(array('key'=>'plugins.generic.thesis.manager.theses'), $smarty) . '</a></li>';
00188 }
00189 return false;
00190 }
00191
00192 function displaySearchLink($hookName, $params) {
00193 if ($this->getEnabled()) {
00194 $smarty = &$params[1];
00195 $output = &$params[2];
00196 $currentJournal = $smarty->get_template_vars('currentJournal');
00197 if (!empty($currentJournal)) {
00198 $output .= '<a href="' . TemplateManager::smartyUrl(array('page'=>'thesis'), $smarty) . '" class="action">' . TemplateManager::smartyTranslate(array('key'=>'plugins.generic.thesis.searchLink'), $smarty) . '</a><br /><br />';
00199 }
00200 }
00201 return false;
00202 }
00203
00207 function setEnabled($enabled) {
00208 $journal = &Request::getJournal();
00209 if ($journal) {
00210 $this->updateSetting($journal->getJournalId(), 'enabled', $enabled ? true : false);
00211 return true;
00212 }
00213 return false;
00214 }
00215
00219 function manage($verb, $args) {
00220 $templateMgr = &TemplateManager::getManager();
00221 $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00222 $journal = &Request::getJournal();
00223 $returner = true;
00224
00225 switch ($verb) {
00226 case 'enable':
00227 $this->setEnabled(true);
00228 $returner = false;
00229 break;
00230 case 'disable':
00231 $this->setEnabled(false);
00232 $returner = false;
00233 break;
00234 case 'settings':
00235 if ($this->getEnabled()) {
00236 $this->import('ThesisSettingsForm');
00237 $form = &new ThesisSettingsForm($this, $journal->getJournalId());
00238 if (Request::getUserVar('save')) {
00239 $form->readInputData();
00240 if ($form->validate()) {
00241 $form->execute();
00242 Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'theses'));
00243 } else {
00244 $this->setBreadCrumbs(true);
00245 $form->display();
00246 }
00247 } else {
00248 $this->setBreadCrumbs(true);
00249 $form->initData();
00250 $form->display();
00251 }
00252 } else {
00253 Request::redirect(null, 'manager');
00254 }
00255 break;
00256 case 'delete':
00257 if ($this->getEnabled()) {
00258 if (!empty($args)) {
00259 $thesisId = (int) $args[0];
00260 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00261
00262
00263 if ($thesisDao->getThesisJournalId($thesisId) == $journal->getJournalId()) {
00264 $thesisDao->deleteThesisById($thesisId);
00265 }
00266 }
00267 Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'theses'));
00268 } else {
00269 Request::redirect(null, 'manager');
00270 }
00271 break;
00272 case 'create':
00273 case 'edit':
00274 if ($this->getEnabled()) {
00275 $thesisId = !isset($args) || empty($args) ? null : (int) $args[0];
00276 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00277
00278
00279 if (($thesisId != null && $thesisDao->getThesisJournalId($thesisId) == $journal->getJournalId()) || ($thesisId == null)) {
00280 $this->import('ThesisForm');
00281
00282 if ($thesisId == null) {
00283 $templateMgr->assign('thesisTitle', 'plugins.generic.thesis.manager.createTitle');
00284 } else {
00285 $templateMgr->assign('thesisTitle', 'plugins.generic.thesis.manager.editTitle');
00286 }
00287
00288 $journalSettingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00289 $journalSettings = &$journalSettingsDao->getJournalSettings($journal->getJournalId());
00290
00291 $thesisForm = &new ThesisForm($thesisId);
00292 $thesisForm->initData();
00293 $this->setBreadCrumbs(true);
00294 $templateMgr->assign('journalSettings', $journalSettings);
00295 $thesisForm->display();
00296 } else {
00297 Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'theses'));
00298 }
00299 } else {
00300 Request::redirect(null, 'manager');
00301 }
00302 break;
00303 case 'update':
00304 if ($this->getEnabled()) {
00305 $this->import('ThesisForm');
00306 $thesisId = Request::getUserVar('thesisId') == null ? null : (int) Request::getUserVar('thesisId');
00307 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00308
00309 if (($thesisId != null && $thesisDao->getThesisJournalId($thesisId) == $journal->getJournalId()) || $thesisId == null) {
00310
00311 $thesisForm = &new ThesisForm($thesisId);
00312 $thesisForm->readInputData();
00313
00314 if ($thesisForm->validate()) {
00315 $thesisForm->execute();
00316
00317 if (Request::getUserVar('createAnother')) {
00318 Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'create'));
00319 } else {
00320 Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'theses'));
00321 }
00322 } else {
00323 if ($thesisId == null) {
00324 $templateMgr->assign('thesisTitle', 'plugins.generic.thesis.manager.createTitle');
00325 } else {
00326 $templateMgr->assign('thesisTitle', 'plugins.generic.thesis.manager.editTitle');
00327 }
00328
00329 $journalSettingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00330 $journalSettings = &$journalSettingsDao->getJournalSettings($journal->getJournalId());
00331
00332 $this->setBreadCrumbs(true);
00333 $templateMgr->assign('journalSettings', $journalSettings);
00334 $thesisForm->display();
00335 }
00336 } else {
00337 Request::redirect(null, 'manager', 'plugin', array('generic', $this->getName(), 'theses'));
00338 }
00339 } else {
00340 Request::redirect(null, 'manager');
00341 }
00342 break;
00343 default:
00344 if ($this->getEnabled()) {
00345 $this->import('Thesis');
00346 $searchField = null;
00347 $searchMatch = null;
00348 $search = Request::getUserVar('search');
00349 $dateFrom = Request::getUserDateVar('dateFrom', 1, 1);
00350 if ($dateFrom !== null) $dateFrom = date('Y-m-d H:i:s', $dateFrom);
00351 $dateTo = Request::getUserDateVar('dateTo', 32, 12, null, 23, 59, 59);
00352 if ($dateTo !== null) $dateTo = date('Y-m-d H:i:s', $dateTo);
00353
00354 if (isset($search)) {
00355 $searchField = Request::getUserVar('searchField');
00356 $searchMatch = Request::getUserVar('searchMatch');
00357 }
00358
00359 $rangeInfo = &Handler::getRangeInfo('theses');
00360 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00361 $theses = &$thesisDao->getThesesByJournalId($journal->getJournalId(), $searchField, $search, $searchMatch, $dateFrom, $dateTo, null, $rangeInfo);
00362
00363 $templateMgr->assign('theses', $theses);
00364 $this->setBreadCrumbs();
00365
00366
00367 $duplicateParameters = array(
00368 'searchField', 'searchMatch', 'search',
00369 'dateFromMonth', 'dateFromDay', 'dateFromYear',
00370 'dateToMonth', 'dateToDay', 'dateToYear'
00371 );
00372 foreach ($duplicateParameters as $param)
00373 $templateMgr->assign($param, Request::getUserVar($param));
00374
00375 $templateMgr->assign('dateFrom', $dateFrom);
00376 $templateMgr->assign('dateTo', $dateTo);
00377 $templateMgr->assign('yearOffsetPast', THESIS_APPROVED_YEAR_OFFSET_PAST);
00378
00379 $fieldOptions = Array(
00380 THESIS_FIELD_FIRSTNAME => 'plugins.generic.thesis.manager.studentFirstName',
00381 THESIS_FIELD_LASTNAME => 'plugins.generic.thesis.manager.studentLastName',
00382 THESIS_FIELD_EMAIL => 'plugins.generic.thesis.manager.studentEmail',
00383 THESIS_FIELD_DEPARTMENT => 'plugins.generic.thesis.manager.department',
00384 THESIS_FIELD_UNIVERSITY => 'plugins.generic.thesis.manager.university',
00385 THESIS_FIELD_TITLE => 'plugins.generic.thesis.manager.title',
00386 THESIS_FIELD_ABSTRACT => 'plugins.generic.thesis.manager.abstract',
00387 THESIS_FIELD_SUBJECT => 'plugins.generic.thesis.manager.keyword'
00388 );
00389 $templateMgr->assign('fieldOptions', $fieldOptions);
00390
00391 $templateMgr->display($this->getTemplatePath() . 'theses.tpl');
00392 } else {
00393 Request::redirect(null, 'manager');
00394 }
00395 }
00396 return $returner;
00397 }
00398
00399 }
00400 ?>