public function checkLine($line)
 {
     $errors = "";
     if (!FleximportTable::findOneByName("fleximport_semiro_course_import")) {
         return "Tabelle fleximport_semiro_course_import existiert nicht. ";
     }
     $dilp_kennung_feld = FleximportConfig::get("SEMIRO_DILP_KENNUNG_FIELD");
     if (!$dilp_kennung_feld) {
         $dilp_kennung_feld = "dilp_teilnehmer";
     }
     if (!$line[$dilp_kennung_feld]) {
         $errors .= "Teilnehmer hat keinen Wert für '{$dilp_kennung_feld}''. ";
     } else {
         $datafield = Datafield::findOneByName(FleximportConfig::get("SEMIRO_USER_DATAFIELD_NAME"));
         if (!$datafield) {
             $errors .= "System hat kein Datenfeld " . FleximportConfig::get("SEMIRO_USER_DATAFIELD_NAME") . ", womit die Nutzer identifiziert werden. ";
         } else {
             $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ? ", array($datafield->getId(), $line[$dilp_kennung_feld]));
             if (!$entry || !User::find($entry['range_id'])) {
                 $errors .= "Nutzer konnte nicht durch id_teilnehmer identifiziert werden. ";
             }
         }
     }
     if (!$line['teilnehmergruppe']) {
         $errors .= "Keine Teilnehmergruppe. ";
     } else {
         $statement = DBManager::get()->prepare("\n                SELECT 1\n                FROM fleximport_semiro_course_import\n                WHERE teilnehmergruppe = ?\n            ");
         $statement->execute(array($line['teilnehmergruppe']));
         if (!$statement->fetch()) {
             $errors .= "Nicht verwendete Teilnehmergruppe. ";
         }
     }
     return $errors;
 }
 public function afterUpdate(SimpleORMap $object, $line)
 {
     $old_domains = array_map(function ($domain) {
         return $domain->getID();
     }, $this->old_domains);
     $new_domains = UserDomain::getUserDomainsForUser($object->getId());
     foreach ($new_domains as $domain_id) {
         if (!in_array($domain_id, $old_domains)) {
             if ($domain_id === "alumni") {
                 if (count($new_domains) == 1) {
                     $statement = DBManager::get()->prepare("\n                            SELECT seminar_user.Seminar_id \n                            FROM seminar_user\n                                LEFT JOIN seminar_userdomain ON (seminar_user.Seminar_id = seminar_userdomain.Seminar_id)\n                            WHERE seminar_user.user_id = :user_id\n                                AND seminar_user.Seminar_id NOT IN (SELECT seminar_id FROM seminar_userdomain WHERE userdomain_id = 'alumni')\n                        ");
                     $statement->execute(array('user_id' => $object->getId()));
                     foreach ($statement->fetchAll(PDO::FETCH_COLUMN, 0) as $seminar_id) {
                         $seminar = new Seminar($seminar_id);
                         $seminar->deleteMember($object->getId());
                     }
                 }
                 $datafield = Datafield::findOneBySQL("name = 'Ich will weiterhin als Alumni in Stud.IP geführt werden' AND object_type = 'user'");
                 $user_wants_to_stay = DatafieldEntry::findOneBySQL("datafield_id = ? AND range_id = ?", array($datafield->getId(), $object->getId()));
                 if ($user_wants_to_stay['content']) {
                     //In Veranstaltung ALUMNI die Statusgruppe anlegen:
                     $datafield = Datafield::findOneBySQL("name = 'Alumni' AND object_type = 'user'");
                     $entry = DatafieldEntry::findOneBySQL("datafield_id = ? AND range_id = ?", array($datafield->getId(), $object->getId()));
                     $course = Course::findOneByName("ALUMNI");
                     $gruppenname = $entry ? $entry['content'] : null;
                     if ($course && $gruppenname) {
                         $statusgruppe = Statusgruppen::findOneBySQL("name = ? range_id = ?", array($gruppenname, $course->getId()));
                         if (!$statusgruppe) {
                             $statusgruppe = new Statusgruppen();
                             $statusgruppe['name'] = $gruppenname;
                             $statusgruppe['range_id'] = $course->getId();
                             $statusgruppe->store();
                         }
                         if (!$statusgruppe->isMember($object->getId())) {
                             $statusgruppe->addUser($object->getId());
                         }
                     }
                 } else {
                     $object->delete();
                     $deleted = true;
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public function tablemapping_action($table_id)
 {
     PageLayout::setTitle(_("Datenmapping einstellen"));
     $this->table = new FleximportTable($table_id);
     Navigation::activateItem("/fleximport/process_" . $this->table['process_id']);
     if (Request::isPost()) {
         $tabledata = Request::getArray("tabledata");
         $tabledata = array_merge($this->table['tabledata'], $tabledata);
         $this->table['tabledata'] = $tabledata;
         $this->table->store();
         PageLayout::postMessage(MessageBox::success(_("Daten wurden gespeichert.")));
     }
     $datafield_object_types = array('User' => "user", 'Course' => "sem", 'CourseMember' => "usersemdata");
     $this->datafields = Datafield::findBySQL("object_type = :object_type", array('object_type' => $datafield_object_types[$this->table['import_type']]));
     if (Request::isAjax() && Request::isPost()) {
         $output = array('func' => "STUDIP.Fleximport.updateTable", 'payload' => array('table_id' => $table_id, 'name' => $this->table['name'], 'html' => $this->render_template_as_string("import/_table.php")));
         $this->response->add_header("X-Dialog-Execute", json_encode(studip_utf8encode($output)));
     }
 }
Esempio n. 4
0
</option>
                        <option value="email"<?php 
echo $table['tabledata']['simplematching'][$field]['format'] === "email" ? " selected" : "";
?>
><?php 
echo _("Format: Emails (mit Leerzeichen getrennt)");
?>
</option>
                        <option value="fullname"<?php 
echo $table['tabledata']['simplematching'][$field]['format'] === "fullname" ? " selected" : "";
?>
><?php 
echo _("Format: Vorname Nachname (mit Kommata getrennt)");
?>
</option>
                        <? foreach (Datafield::findBySQL("object_type = 'user'") as $datafield) : ?>
                            <option value="<?php 
echo htmlReady($datafield->getId());
?>
"<?php 
echo $table['tabledata']['simplematching'][$field]['format'] === $datafield->getId() ? " selected" : "";
?>
><?php 
echo htmlReady(sprintf(_("Format: %s (mit Leerzeichen getrennt)"), $datafield['name']));
?>
</option>
                        <? endforeach ?>
                    </select>
                </div>
            <? endif ?>
            <? if (($table['import_type'] === "Course") && ($field === "status")) : ?>
 public function afterUpdate($object, $line)
 {
     if (FleximportConfig::get("SEMIRO_SEND_MESSAGES")) {
         $messaging = new messaging();
         //Email an Dozenten:
         foreach ((array) $this->new_dozenten as $user_id) {
             $message = sprintf(_('Sie wurden von Semiro als DozentIn in die Veranstaltung **%s** eingetragen.'), $object->name);
             $messaging->insert_message($message, get_username($user_id), '____%system%____', FALSE, FALSE, '1', FALSE, sprintf('%s %s', _('Systemnachricht:'), _('Eintragung in Veranstaltung')), TRUE);
         }
     }
     $teilnehmergruppe = $line['teilnehmergruppe'];
     $import_type = "semiro_participant_import_" . $object->getId() . "_" . md5($teilnehmergruppe);
     $imported_items = array();
     if ($teilnehmergruppe && $object->getId()) {
         $seminar = new Seminar($object->getId());
         $datafield = Datafield::findOneByName(FleximportConfig::get("SEMIRO_USER_DATAFIELD_NAME"));
         $dilp_kennung_feld = FleximportConfig::get("SEMIRO_DILP_KENNUNG_FIELD");
         if (!$dilp_kennung_feld) {
             $dilp_kennung_feld = "dilp_teilnehmer";
         }
         if ($datafield) {
             $statement = DBManager::get()->prepare("\n                    SELECT `" . addslashes($dilp_kennung_feld) . "`\n                    FROM fleximport_semiro_participant_import\n                    WHERE teilnehmergruppe = ?\n                ");
             $statement->execute(array($teilnehmergruppe));
             while ($id_teilnehmer = $statement->fetch(PDO::FETCH_COLUMN, 0)) {
                 //$ids = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
                 //foreach ($ids as $id_teilnehmer) {
                 $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ? ", array($datafield->getId(), $id_teilnehmer));
                 if ($entry) {
                     $was_member = CourseMember::findOneBySQL("seminar_id = ? AND user_id = ?", array($object->getId(), $entry['range_id']));
                     $seminar->addMember($entry['range_id']);
                     if (!$was_member && FleximportConfig::get("SEMIRO_SEND_MESSAGES")) {
                         $message = sprintf(_('Sie wurden von Semiro als TeilnehmerIn in die Veranstaltung **%s** eingetragen.'), $seminar->name);
                         $messaging->insert_message($message, get_username($entry['range_id']), '____%system%____', FALSE, FALSE, '1', FALSE, sprintf('%s %s', _('Systemnachricht:'), _('Eintragung in Veranstaltung')), TRUE);
                     }
                     //Zu Statusgruppe hinzufügen:
                     $gruppe = Statusgruppen::findOneBySQL("range_id = ? AND name = ?", array($object->getId(), $teilnehmergruppe));
                     if (!$gruppe) {
                         $gruppe = new Statusgruppen();
                         $gruppe['range_id'] = $object->getId();
                         $gruppe['name'] = $teilnehmergruppe;
                         $gruppe->store();
                     }
                     if (!$gruppe->isMember($entry['range_id'])) {
                         $gruppe->addUser($entry['range_id']);
                     }
                     //$gruppe->updateFolder(true);
                     if (!$gruppe->hasFolder()) {
                         create_folder(_("Dateiordner der Gruppe:") . ' ' . $teilnehmergruppe, _("Ablage für Ordner und Dokumente dieser Gruppe"), $gruppe->id, 15, $object->getId());
                     }
                     $item_id = $entry['range_id'];
                     if (!in_array($item_id, $imported_items)) {
                         $mapped = FleximportMappedItem::findbyItemId($item_id, $import_type) ?: new FleximportMappedItem();
                         $mapped['import_type'] = $import_type;
                         $mapped['item_id'] = $item_id;
                         $mapped['chdate'] = time();
                         $mapped->store();
                         $imported_items[] = $item_id;
                     }
                 }
             }
         }
         //Dozent zu Statusgruppe hinzufügen:
         $gruppe = Statusgruppen::findOneBySQL("range_id = ? AND name = ?", array($object->getId(), $teilnehmergruppe));
         foreach ($object->members->filter(function ($member, $value) {
             return $member['status'] === "dozent";
         }) as $teacher) {
             if (!$gruppe->isMember($teacher->getId())) {
                 $gruppe->addUser($teacher->getId());
             }
         }
         $items = FleximportMappedItem::findBySQL("import_type = :import_type AND item_id NOT IN (:ids)", array('import_type' => $import_type, 'ids' => $imported_items ?: ""));
         foreach ($items as $item) {
             $user_id = $item['item_id'];
             //check if user is in another group of this course
             $statement = DBManager::get()->prepare("\n                    SELECT 1\n                    FROM fleximport_semiro_participant_import\n                        INNER JOIN fleximport_semiro_course_import ON (fleximport_semiro_course_import.teilnehmergruppe = fleximport_semiro_participant_import.teilnehmergruppe)\n                    WHERE `" . addslashes($dilp_kennung_feld) . "` = :user_dilp\n                        AND fleximport_semiro_course_import.name_veranstaltung = :name\n                ");
             $dilp_entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND range_id = ? ", array($datafield->getId(), $user_id));
             $statement->execute(array('user_dilp' => $dilp_entry['content'], 'name' => $object['name']));
             $is_still_in_course = $statement->fetch(PDO::FETCH_COLUMN, 0);
             if (!$is_still_in_course) {
                 $seminar->deleteMember($user_id);
             }
             $item->delete();
         }
     }
 }
Esempio n. 6
0
 public function getMappedData($line)
 {
     $plugin = $this->getPlugin();
     $fields = $this->getTargetFields();
     //dynamic additional fields:
     switch ($this['import_type']) {
         case "Course":
             foreach (Datafield::findBySQL("object_type = 'sem'") as $datafield) {
                 $fields[] = $datafield['name'];
             }
             $fields[] = "fleximport_dozenten";
             $fields[] = "fleximport_related_institutes";
             $fields[] = "fleximport_studyarea";
             $fields[] = "fleximport_locked";
             $fields[] = "fleximport_course_userdomains";
             break;
         case "User":
             foreach (Datafield::findBySQL("object_type = 'user'") as $datafield) {
                 $fields[] = $datafield['name'];
             }
             $fields[] = "fleximport_username_prefix";
             $fields[] = "fleximport_userdomains";
             $fields[] = "fleximport_user_inst";
             $fields[] = "fleximport_expiration_date";
             $fields[] = "fleximport_welcome_message";
             break;
     }
     $data = array();
     foreach ($fields as $field) {
         $mapping = false;
         //important: false means no mapping, null means mapping to database null
         if ($plugin && in_array($field, $plugin->fieldsToBeMapped())) {
             $mapping = $plugin->mapField($field, $line);
         }
         if ($mapping !== false) {
             $data[$field] = $mapping;
         } else {
             if ($this['tabledata']['simplematching'][$field]['column']) {
                 if ($this['tabledata']['simplematching'][$field]['column'] === "static value") {
                     //use a static value
                     $data[$field] = $this['tabledata']['simplematching'][$field]['static'];
                 } else {
                     if (strpos($this['tabledata']['simplematching'][$field]['column'], "fleximportconfig_") === 0) {
                         $config = substr($this['tabledata']['simplematching'][$field]['column'], strlen("fleximportconfig_"));
                         $template = FleximportConfig::get($config);
                         foreach ($data as $index => $value) {
                             $template = str_replace("{{" . $index . "}}", $value, $template);
                         }
                         foreach ($line as $index => $value) {
                             if (!in_array($index, $data)) {
                                 $template = str_replace("{{" . $index . "}}", $value, $template);
                             }
                         }
                         $data[$field] = $template;
                     } else {
                         //use a matched column
                         $data[$field] = $line[$this['tabledata']['simplematching'][$field]['column']];
                     }
                 }
             } else {
                 //else no mapping, don't even overwrite old value.
             }
         }
     }
     foreach ($fields as $field) {
         //mapper:
         if (strpos($this['tabledata']['simplematching'][$field]['column'], "fleximport_mapper__") === 0) {
             list($prefix, $mapperclass, $format) = explode("__", $this['tabledata']['simplematching'][$field]['column']);
             if (class_exists($mapperclass)) {
                 $mapper = new $mapperclass();
                 if (is_a($mapper, "FleximportMapper")) {
                     $mapfrom = $this['tabledata']['simplematching'][$field]['mapfrom'];
                     $data[$field] = $mapper->map($format, $data[$mapfrom] ?: $line[$mapfrom]);
                 }
             }
         }
     }
     //special mapping
     if ($this['import_type'] === "Course") {
         //Map seminar_id :
         if (!$data['seminar_id'] && $this['tabledata']['simplematching']["seminar_id"]['column'] === "fleximport_map_from_veranstaltungsnummer_and_semester") {
             $course = Course::findOneBySQL("name = ? AND start_time = ?", array($data['name'], $data['start_time']));
             if ($course) {
                 $data['seminar_id'] = $course->getId();
             }
         }
         //Map dozenten:
         if ($this['tabledata']['simplematching']["fleximport_dozenten"]['column'] && !in_array("fleximport_dozenten", $this->fieldsToBeDynamicallyMapped())) {
             $data['fleximport_dozenten'] = (array) preg_split($this['tabledata']['simplematching']["fleximport_dozenten"]['format'] === "fullname" ? "/\\s*,\\s*/" : "/\\s+/", $data['fleximport_dozenten'], null, PREG_SPLIT_NO_EMPTY);
             switch ($this['tabledata']['simplematching']["fleximport_dozenten"]['format']) {
                 case "user_id":
                     $data['fleximport_dozenten'] = array_map(function ($user_id) {
                         $user = User::find($user_id);
                         if ($user) {
                             return $user->getId();
                         } else {
                             return null;
                         }
                     }, $data['fleximport_dozenten']);
                     break;
                 case "username":
                     $data['fleximport_dozenten'] = array_map("get_userid", $data['fleximport_dozenten']);
                     break;
                 case "email":
                     $data['fleximport_dozenten'] = array_map(function ($email) {
                         $user = User::findOneByEmail($email);
                         if ($user) {
                             return $user->getId();
                         } else {
                             return null;
                         }
                     }, $data['fleximport_dozenten']);
                     break;
                 case "fullname":
                     $data['fleximport_dozenten'] = array_map(function ($fullname) {
                         list($vorname, $nachname) = (array) preg_split("/\\s+/", $fullname, null, PREG_SPLIT_NO_EMPTY);
                         $user = User::findOneBySQL("Vorname = ? AND Nachname = ? AND perms = 'dozent'", array($vorname, $nachname));
                         if ($user) {
                             return $user->getId();
                         } else {
                             return null;
                         }
                     }, $data['fleximport_dozenten']);
                     break;
                 default:
                     //map by datafield
                     $datafield_id = $this['tabledata']['simplematching']["fleximport_dozenten"]['format'];
                     foreach ($data['fleximport_dozenten'] as $key => $value) {
                         $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ?", array($datafield_id, $value));
                         if ($entry) {
                             $data['fleximport_dozenten'][$key] = $entry['range_id'];
                         } else {
                             unset($data['fleximport_dozenten'][$key]);
                         }
                     }
                     break;
             }
         }
         //Map sem_type:
         if ($this['tabledata']['simplematching']["status"]['column'] && $this['tabledata']['simplematching']["status"]['format']) {
             if ($this['tabledata']['simplematching']["status"]['format'] === "name") {
                 $sem_type_id = null;
                 foreach ($GLOBALS['SEM_TYPE'] as $id => $sem_type) {
                     if ($sem_type['name'] === $data['status']) {
                         $sem_type_id = $id;
                     }
                 }
                 $data['status'] = $sem_type_id;
             }
         }
         //Map Studienbereiche
         if ($this['tabledata']['simplematching']["fleximport_studyarea"]['column'] && !in_array("fleximport_studyarea", $this->fieldsToBeDynamicallyMapped())) {
             if ($this['tabledata']['simplematching']["fleximport_studyarea"]['column'] === "static value") {
                 $data['fleximport_studyarea'] = (array) explode(";", $this['tabledata']['simplematching']["fleximport_studyarea"]['static']);
             } else {
                 $data['fleximport_studyarea'] = (array) explode(";", $data['fleximport_studyarea']);
                 $study_areas = array();
                 foreach ($data['fleximport_studyarea'] as $key => $name) {
                     foreach (StudipStudyArea::findBySQL("name = ?", array($name)) as $study_area) {
                         $study_areas[] = $study_area->getId();
                     }
                 }
                 $data['fleximport_studyarea'] = $study_areas;
             }
         }
         if ($this['tabledata']['simplematching']["fleximport_course_userdomains"]['column'] && !in_array("fleximport_course_userdomains", $this->fieldsToBeDynamicallyMapped())) {
             $data['fleximport_course_userdomains'] = (array) preg_split("/\\s*,\\s*/", $data['fleximport_course_userdomains'], null, PREG_SPLIT_NO_EMPTY);
             $statement = DBManager::get()->prepare("SELECT userdomain_id FROM userdomains WHERE name IN (:domains) OR userdomain_id IN (:domains)");
             $statement->execute(array('domains' => $data['fleximport_course_userdomains']));
             $data['fleximport_course_userdomains'] = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
         }
     }
     if ($this['import_type'] === "User") {
         if ($this['tabledata']['simplematching']["username"]['column']) {
             if ($this['tabledata']['simplematching']["username"]['format'] === "email_first_part") {
                 list($data['username']) = explode("@", $data['username']);
             }
             if ($this['tabledata']['simplematching']["fleximport_username_prefix"]['column']) {
                 $data['username'] = $data['fleximport_username_prefix'] . $data['username'];
             }
         }
         if ($this['tabledata']['simplematching']["fleximport_user_inst"]['column']) {
             $data['fleximport_user_inst'] = (array) preg_split("/\\s*,\\s*/", $data['fleximport_user_inst'], null, PREG_SPLIT_NO_EMPTY);
             $institut_ids = array();
             foreach ($data['fleximport_user_inst'] as $inst_name) {
                 $statement = DBManager::get()->prepare("\n                        SELECT Institut_id\n                        FROM Institute\n                        WHERE Name = ?\n                    ");
                 $statement->execute(array($inst_name));
                 $institut_id = $statement->fetch(PDO::FETCH_COLUMN, 0);
                 if ($institut_id) {
                     $institut_ids[] = $institut_id;
                 }
             }
             $data['fleximport_user_inst'] = $institut_ids;
         }
         if ($this['tabledata']['simplematching']["fleximport_userdomains"]['column'] && !in_array("fleximport_userdomains", $this->fieldsToBeDynamicallyMapped())) {
             $data['fleximport_userdomains'] = (array) preg_split("/\\s*,\\s*/", $data['fleximport_userdomains'], null, PREG_SPLIT_NO_EMPTY);
             $statement = DBManager::get()->prepare("SELECT userdomain_id FROM userdomains WHERE name IN (:domains) OR userdomain_id IN (:domains)");
             $statement->execute(array('domains' => $data['fleximport_userdomains']));
             $data['fleximport_userdomains'] = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
         }
         if ($this['tabledata']['simplematching']["fleximport_expiration_date"]['column'] && !in_array("fleximport_expiration_date", $this->fieldsToBeDynamicallyMapped())) {
             if (!is_numeric($data['fleximport_expiration_date'])) {
                 $data['fleximport_expiration_date'] = strtotime($data['fleximport_expiration_date']);
             }
         }
     }
     if ($this['import_type'] === "User" && !$data['user_id']) {
         if (!$data['user_id'] && $data['auth_plugin'] === "standard" && !$data['password']) {
             $usermanager = new UserManagement();
             $data['password'] = $usermanager->generate_password(6);
         }
     }
     return $data;
 }