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;
 }
Example #2
0
 public static function delete($name)
 {
     if (!self::$instance) {
         self::$instance = new FleximportConfig();
     }
     self::$instance->{$name} = null;
 }
Example #3
0
 function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     if (FleximportConfig::get("MAXIMUM_EXECUTION_TIME")) {
         set_time_limit(FleximportConfig::get("MAXIMUM_EXECUTION_TIME"));
     }
 }
Example #4
0
 function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     if (!$GLOBALS['perm']->have_perm("root")) {
         throw new AccessDeniedException();
     }
     if (FleximportConfig::get("MAXIMUM_EXECUTION_TIME")) {
         set_time_limit(FleximportConfig::get("MAXIMUM_EXECUTION_TIME"));
     }
     PageLayout::addScript($this->plugin->getPluginURL() . "/assets/fleximport.js");
     Navigation::activateItem("/fleximport");
 }
Example #5
0
 public function edit_action()
 {
     if (Request::isPost()) {
         $configs = Request::getArray("configs");
         foreach ($configs as $name => $data) {
             if ($name !== $data['name'] || !$data['value']) {
                 FleximportConfig::delete($name);
             }
             if ($data['name'] && $data['value']) {
                 FleximportConfig::set($data['name'], $data['value']);
             }
         }
         if (Request::get("new_name") && Request::get("new_value")) {
             FleximportConfig::set(Request::get("new_name"), Request::get("new_value"));
         }
     }
     $this->redirect("config/overview");
 }
Example #6
0
echo _("Wird von einem Plugin dynamisch gemapped");
?>
                    <? else : ?>
                        <select name="tabledata[simplematching][fleximport_welcome_message][column]">
                            <option value=""><?php 
echo _("Standardnachricht mit Passwort an Nutzer");
?>
</option>
                            <option value="none"<?php 
echo "none" === $table['tabledata']['simplematching']['fleximport_welcome_message']['column'] ? " selected" : "";
?>
><?php 
echo _("Keine Nachricht versenden");
?>
</option>
                            <? foreach (FleximportConfig::all() as $config => $value) : ?>
                                <option value="<?php 
echo htmlReady($config);
?>
"<?php 
echo $config === $table['tabledata']['simplematching']['fleximport_welcome_message']['column'] ? " selected" : "";
?>
><?php 
echo htmlReady($config);
?>
</option>
                            <? endforeach ?>
                        </select>
                    <? endif ?>
                </td>
            </tr>
Example #7
0
<? $limit = ($limit === false) || ($limit > 0) ? $limit : (FleximportConfig::get("FLEXIMPORT_DISPLAY_LINES") ?: 20) ?>
<? $count = $table->fetchCount() ?>
<? $displayed_lines = 0 ?>
<table class="default" style="margin-bottom: 50px;" id="<?php 
echo $table->getId();
?>
">
    <caption>
        <div class="caption-container">
            <div class="caption-content">
                <? switch ($table['import_type']) {
                    case "User":
                        echo version_compare($GLOBALS['SOFTWARE_VERSION'], "3.4", ">=")
                            ? Icon::create("person", "info")->asImg(20, array('class' => "text-bottom", 'title' => _("Es werden Nutzer import.")))
                            : Assets::img("icons/20/black/person", array('class' => "text-bottom", 'title' => _("Es werden Nutzer import.")));
                        break;
                    case "CourseMember":
                        echo version_compare($GLOBALS['SOFTWARE_VERSION'], "3.4", ">=")
                            ? Icon::create("group2", "info")->asImg(20, array('class' => "text-bottom", 'title' => _("Es werden Teilnehmer an veranstaltungen import.")))
                            : Assets::img("icons/20/black/group2", array('class' => "text-bottom", 'title' => _("Es werden Teilnehmer an veranstaltungen import.")));
                        break;
                    case "Course":
                        echo version_compare($GLOBALS['SOFTWARE_VERSION'], "3.4", ">=")
                            ? Icon::create("seminar", "info")->asImg(20, array('class' => "text-bottom", 'title' => _("Es werden Veranstaltungen import.")))
                            : Assets::img("icons/20/black/seminar", array('class' => "text-bottom", 'title' => _("Es werden Veranstaltungen import.")));
                        break;
                    case "":
                        echo version_compare($GLOBALS['SOFTWARE_VERSION'], "3.4", ">=")
                            ? Icon::create("remove-circle", "info")->asImg(20, array('class' => "text-bottom", 'title' => _("Dies ist eine Hilfstabelle und wird nicht für sich importiert.")))
                            : Assets::img("icons/20/black/remove-circle", array('class' => "text-bottom", 'title' => _("Dies ist eine Hilfstabelle und wird nicht für sich importiert.")));
 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();
         }
     }
 }
Example #9
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;
 }
Example #10
0
 public function triggerImport()
 {
     $processes = FleximportProcess::findBySQL("triggered_by_cronjob = '1' ORDER BY name ASC");
     if ($GLOBALS['FLEXIMPORT_IS_CRONJOB']) {
         echo "Starting Import at " . date("c") . "\n\n";
     }
     foreach ($processes as $process) {
         foreach ($process->tables as $table) {
             //import data if needed
             $table->fetchData();
         }
     }
     if ($GLOBALS['FLEXIMPORT_IS_CRONJOB']) {
         echo "Fetching data finished at " . date("c") . "\n";
     }
     $protocol = array();
     foreach ($processes as $process) {
         foreach ($process->tables as $table) {
             if ($GLOBALS['FLEXIMPORT_IS_CRONJOB']) {
                 echo "\nStarting Import of " . $table['name'] . " at " . date("c") . "\n";
             }
             $protocol = array_merge($protocol, $table->doImport());
         }
     }
     if (count($protocol) && $GLOBALS['FLEXIMPORT_IS_CRONJOB'] && FleximportConfig::get("REPORT_CRONJOB_ERRORS")) {
         $message = _("Es hat folgende Probleme beim Import gegeben:");
         $message .= "\n" . implode("\n", $protocol);
         $mail = new StudipMail();
         $mail->setSubject(_("Fleximport Fehlerbericht von Stud.IP"));
         $mail->setBodyText($message);
         $emails = preg_split("/\\s*[,;\\s]+\\s*/", FleximportConfig::get("REPORT_CRONJOB_ERRORS"), null, PREG_SPLIT_NO_EMPTY);
         foreach ($emails as $email) {
             $mail->addRecipient($email);
         }
         $mail->send();
     }
     if ($GLOBALS['FLEXIMPORT_IS_CRONJOB']) {
         echo implode("\n", $protocol);
     }
     if ($GLOBALS['FLEXIMPORT_IS_CRONJOB']) {
         echo "\nImport ends at " . date("c") . "\n";
     }
 }