Ejemplo n.º 1
0
 /**
  * Stores the changed or created institute data
  *
  * @param String $i_id Institute id or 'new' to create
  * @throws MethodNotAllowedException
  */
 public function store_action($i_id)
 {
     // We won't accept anything but a POST request
     if (!Request::isPost()) {
         throw new MethodNotAllowedException();
     }
     $create_institute = $i_id === 'new';
     $institute = new Institute($create_institute ? null : $i_id);
     $institute->name = trim(Request::get('Name', $institute->name));
     $institute->fakultaets_id = Request::option('Fakultaet', $institute->fakultaets_id);
     $institute->strasse = Request::get('strasse', $institute->strasse);
     // Beware: Despite the name, this contains both zip code AND city name
     $institute->plz = Request::get('plz', $institute->plz);
     $institute->url = Request::get('home', $institute->url);
     $institute->telefon = Request::get('telefon', $institute->telefon);
     $institute->email = Request::get('email', $institute->email);
     $institute->fax = Request::get('fax', $institute->fax);
     $institute->type = Request::int('type', $institute->type);
     $institute->lit_plugin_name = Request::get('lit_plugin_name', $institute->lit_plugin_name);
     $institute->lock_rule = Request::option('lock_rule', $institute->lock_rule);
     // Do we have all necessary data?
     if (!$institute->name) {
         PageLayout::postMessage(MessageBox::error(_('Bitte geben Sie eine Bezeichnung für die Einrichtung ein!')));
         return $this->redirect('institute/basicdata/index/' . $i_id);
     }
     if ($create_institute) {
         $institute->id = $institute->getNewId();
         // Is the user allowed to create new faculties
         if (!$institute->fakultaets_id && !$GLOBALS['perm']->have_perm('root')) {
             PageLayout::postMessage(MessageBox::error(_('Sie haben nicht die Berechtigung, neue Fakultäten zu erstellen')));
             return $this->redirect('institute/basicdata/index/new');
         }
         // Is the user allowed to create new institutes
         if (!$GLOBALS['perm']->have_perm('root') && !($GLOBALS['perm']->is_fak_admin() && get_config('INST_FAK_ADMIN_PERMS') !== 'none')) {
             PageLayout::postMessage(MessageBox::error(_('Sie haben nicht die Berechtigung, um neue Einrichtungen zu erstellen!')));
             return $this->redirect('institute/basicdata/index/new');
         }
         // Does an institute with the given name already exist in the given faculty?
         if ($institute->fakultaets_id && Institute::findOneBySQL('Name = ? AND fakultaets_id = ?', array($institute->name, $institute->fakultaets_id)) !== null) {
             $message = sprintf(_('Die Einrichtung "%s" existiert bereits innerhalb der angegebenen Fakultät!'), $institute->name);
             PageLayout::postMessage(MessageBox::error($message));
             return $this->redirect('institute/basicdata/index/new');
         }
         // Does a faculty with the given name already exist
         if (!$institute->fakultaets_id && Institute::findOneBySQL('Name = ? AND fakultaets_id = Institut_id', array($institute->name)) !== null) {
             $message = sprintf(_('Die Fakultät "%s" existiert bereits!'), $institute->name);
             PageLayout::postMessage(MessageBox::error($message));
             return $this->redirect('institute/basicdata/index/new');
         }
         // Initialize modules
         $modules = new Modules();
         $institute->modules = $modules->getDefaultBinValue('', 'inst', $institute->type);
         // Declare faculty status if neccessary
         if (!$institute->fakultaets_id) {
             $institute->fakultaets_id = $institute->getId();
         }
     } else {
         // Is the user allowed to change the institute/faculty?
         if (!$GLOBALS['perm']->have_studip_perm('admin', $institute->id)) {
             PageLayout::postMessage(MessageBox::error(_('Sie haben nicht die Berechtigung diese Einrichtung zu verändern!')));
             return $this->redirect('institute/basicdata/index/' . $institute->id);
         }
         // Save datafields
         $datafields = Request::getArray('datafields');
         $invalidEntries = array();
         $datafields_stored = 0;
         foreach (DataFieldEntry::getDataFieldEntries($institute->id, 'inst') as $entry) {
             if (isset($datafields[$entry->getId()])) {
                 $valueBefore = $entry->getValue();
                 $entry->setValueFromSubmit($datafields[$entry->getId()]);
                 if ($valueBefore != $entry->getValue()) {
                     if ($entry->isValid()) {
                         $datafields_stored += 1;
                         $entry->store();
                     } else {
                         $invalidEntries[] = $entry->getId();
                     }
                 }
             }
         }
         // If any errors occured while updating the datafields, report them
         if (count($invalidEntries) > 0) {
             $this->flash['invalid_entries'] = $invalidEntries;
             PageLayout::postMessage(MessageBox::error(_('ungültige Eingaben (s.u.) wurden nicht gespeichert')));
         }
     }
     // Try to store the institute, report any errors
     if ($institute->isDirty() && !$institute->store()) {
         if ($institute->isNew()) {
             PageLayout::postMessage(MessageBox::error(_('Die Einrichtung konnte nicht angelegt werden.')));
         } else {
             PageLayout::postMessage(MessageBox::error(_('Die Änderungen konnten nicht gespeichert werden.')));
         }
         return $this->redirect('institute/basicdata/index/' . $i_id);
     }
     if ($create_institute) {
         // Log creation of institute
         log_event('INST_CREATE', $institute->id, null, null, '');
         // logging
         // Further initialize modules (the modules class setup is in
         // no way expensive, so it can be constructed twice, don't worry)
         $modules = new Modules();
         $module_list = $modules->getLocalModules($institute->id, 'inst', $institute->modules, $institute->type);
         if (isset($module_list['documents'])) {
             create_folder(_('Allgemeiner Dateiordner'), _('Ablage für allgemeine Ordner und Dokumente der Einrichtung'), $institute->id, 7, $institute->id);
         }
         // Report success
         $message = sprintf(_('Die Einrichtung "%s" wurde erfolgreich angelegt.'), $institute->name);
         PageLayout::postMessage(MessageBox::success($message));
         openInst($institute->id);
     } else {
         // Report success
         $message = sprintf(_('Die Änderung der Einrichtung "%s" wurde erfolgreich gespeichert.'), htmlReady($institute->name));
         PageLayout::postMessage(MessageBox::success($message));
     }
     $this->redirect('institute/basicdata/index/' . $institute->id, array('cid' => $institute->id));
 }