function getUserDn($username)
 {
     if ($this->send_utf8_credentials) {
         $username = studip_utf8encode($username);
         $reader_password = studip_utf8encode($this->reader_password);
     }
     $user_dn = "";
     if (!($r = @ldap_bind($this->conn, $this->reader_dn, $this->reader_password))) {
         $this->error_msg = sprintf(_("Anmeldung von %s fehlgeschlagen."), $this->reader_dn) . $this->getLdapError();
         return false;
     }
     if (!($result = @ldap_search($this->conn, $this->base_dn, $this->getLdapFilter($username), array('dn')))) {
         $this->error_msg = _("Durchsuchen des LDAP Baumes fehlgeschlagen.") . $this->getLdapError();
         return false;
     }
     if (!ldap_count_entries($this->conn, $result)) {
         $this->error_msg = sprintf(_("%s wurde nicht unterhalb von %s gefunden."), $username, $this->base_dn);
         return false;
     }
     if (!($entry = @ldap_first_entry($this->conn, $result))) {
         $this->error_msg = $this->getLdapError();
         return false;
     }
     if (!($user_dn = @ldap_get_dn($this->conn, $entry))) {
         $this->error_msg = $this->getLdapError();
         return false;
     }
     return $user_dn;
 }
 /**
  * Converts a given string to our xml friendly text.
  * This step involves purifying the string
  *
  * @param String $string Input string to reformat
  * @return String Reformatted string (optional HTML -> Markdown, UTF-8)
  */
 public function xml_ready($string, $convert_to_markdown = true)
 {
     static $purifier = null;
     static $fixer = null;
     static $markdown = null;
     if ($purifier === null) {
         $purifier_config = HTMLPurifier_Config::createDefault();
         $purifier_config->set('Cache.SerializerPath', realpath($GLOBALS['TMP_PATH']));
         $purifier = new HTMLPurifier($purifier_config);
         $markdown = new HTML_To_Markdown();
         $markdown->set_option('strip_tags', true);
     }
     $string = studip_utf8encode($string);
     $string = $purifier->purify($string);
     if ($convert_to_markdown) {
         $string = $markdown->convert($string);
         $string = preg_replace('/\\[\\]\\((\\w+:\\/\\/.*?)\\)/', '', $string);
         $string = preg_replace('/\\[(\\w+:\\/\\/.*?)\\/?\\]\\(\\1\\/?\\s+"(.*?)"\\)/isxm', '$2: $1', $string);
         $string = preg_replace('/\\[(\\w+:\\/\\/.*?)\\/?\\]\\(\\1\\/?\\)/isxm', '$1', $string);
         $string = preg_replace('/\\[(.*?)\\]\\((\\w+:\\/\\/.*?)\\)/', '$1: $2', $string);
     }
     $string = preg_replace('/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/', '', $string);
     $string = trim($string);
     $string = htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
     return $string;
 }
Example #3
0
 public function toJSON()
 {
     $json_array = array();
     foreach (get_object_vars($this) as $name => $value) {
         $json_array[$name] = studip_utf8encode($value);
     }
     return json_encode($json_array);
 }
Example #4
0
 public function configuration_action()
 {
     $template_factory = new Flexi_TemplateFactory(__DIR__ . '/templates');
     $template = $template_factory->open('edit');
     $template->links = Navigation::getItem('/start');
     $template->config = WidgetHelper::getWidgetUserConfig($GLOBALS['user']->id, 'QUICK_SELECTION');
     $template->plugin = $this;
     header('X-Title: ' . _('Schnellzugriff konfigurieren'));
     echo studip_utf8encode($template->render());
 }
Example #5
0
 /**
  * Export of a single user
  * 
  * @param User $user Userobject
  * @return String vCard export string
  */
 private static function exportUser(User $user)
 {
     // If user is not visible export nothing
     if (!get_visibility_by_id($user->id)) {
         return "";
     }
     // vCard exportheader
     $vCard['BEGIN'] = 'VCARD';
     $vCard['VERSION'] = '3.0';
     $vCard['PRODID'] = 'Stud.IP//' . $GLOBALS['UNI_NAME_CLEAN'] . '//DE';
     $vCard['REV'] = date('Y-m-d  H:i:s');
     $vCard['TZ'] = date('O');
     // User specific data
     //Fullname
     $vCard['FN'] = studip_utf8encode($user->getFullname());
     //Name
     $vCard['N'][] = studip_utf8encode($user->Nachname);
     $vCard['N'][] = studip_utf8encode($user->Vorname);
     $vCard['N'][] = studip_utf8encode($user->info->title_rear);
     $vCard['N'][] = studip_utf8encode($user->info->title_front);
     // Adress
     if (Visibility::verify('privadr', $user->id)) {
         $vCard['ADR;TYPE=HOME'] = studip_utf8encode($user->info->privadr);
     }
     // Tel
     if (Visibility::verify('private_phone', $user->id)) {
         $vCard['TEL;TYPE=HOME'] = studip_utf8encode($user->info->privatnr);
     }
     if (Visibility::verify('private_cell', $user->id)) {
         $vCard['TEL;TYPE=CELL'] = studip_utf8encode($user->info->privatcell);
     }
     // Email
     if (get_local_visibility_by_id($user->id, 'email')) {
         $vCard['EMAIL'] = studip_utf8encode($user->email);
     }
     // Photo
     if (Visibility::verify('picture', $user->id)) {
         // Fetch avatar
         $avatar = Avatar::getAvatar($user->id);
         // Only export if
         if ($avatar->is_customized()) {
             $vCard['PHOTO;JPEG;ENCODING=BASE64'] = base64_encode(file_get_contents($avatar->getFilename(Avatar::NORMAL)));
         }
     }
     // vCard end
     $vCard['END'] = 'VCARD';
     // Produce string
     foreach ($vCard as $index => $value) {
         $exportString .= $value ? $index . ':' . (is_array($value) ? join(';', $value) : $value) . "\r\n" : "";
     }
     return $exportString;
 }
Example #6
0
 function up()
 {
     DBManager::get()->exec("ALTER TABLE `config` MODIFY `type` enum('boolean','integer','string','array') NOT NULL DEFAULT 'boolean'");
     DBManager::get()->exec("CREATE TABLE IF NOT EXISTS `user_online` (\n                                  `user_id` char(32) NOT NULL,\n                                  `last_lifesign` int(10) unsigned NOT NULL,\n                                  PRIMARY KEY (`user_id`),\n                                  KEY `last_lifesign` (`last_lifesign`)\n                                ) ENGINE=MyISAM");
     DBManager::get()->exec("INSERT INTO user_online (user_id,last_lifesign) SELECT sid,UNIX_TIMESTAMP(changed) FROM user_data INNER JOIN auth_user_md5 ON sid = user_id");
     $stmt = DBManager::get()->prepare("\n            REPLACE INTO config\n            (config_id, field, value, is_default, `type`, `range`, mkdate, chdate, description, comment)\n            VALUES\n            (MD5(:name), :name, :value, 1, :type, :range, UNIX_TIMESTAMP(),  UNIX_TIMESTAMP(), :description, '')\n            ");
     foreach ($this->new_configs as $values) {
         $stmt->execute($values);
     }
     $check = DBManager::get()->prepare("DELETE FROM user_config WHERE field=? AND user_id=?");
     $stmt = DBManager::get()->prepare("\n            REPLACE INTO user_config (userconfig_id, user_id, field, value, mkdate, chdate, comment)\n            VALUES (?,?,?,?,UNIX_TIMESTAMP(),UNIX_TIMESTAMP(),'')");
     //for all users:
     $db = DBManager::get()->query("SELECT sid,val FROM user_data INNER JOIN auth_user_md5 ON sid = user_id");
     while ($rs = $db->fetch(PDO::FETCH_ASSOC)) {
         $user_id = $rs['sid'];
         $vars = @unserialize($rs['val']);
         if (is_array($vars)) {
             foreach (array('my_messaging_settings', 'forum', 'my_schedule_settings', 'calendar_user_control_data') as $key) {
                 $option = $this->new_configs[$key];
                 $defaults = json_decode($option['value'], true);
                 if (is_array($vars[$key])) {
                     $old_values = array_intersect_key((array) $vars[$key], $defaults);
                     $new_values = array_merge($defaults, $old_values);
                     $check->execute(array($option['name'], $user_id));
                     $stmt->execute(array(md5($option['name'] . $user_id), $user_id, $option['name'], json_encode(studip_utf8encode($new_values))));
                 }
             }
             foreach (array('homepage_cache_own', 'CurrentLogin', 'LastLogin', '_my_sem_group_field', '_my_admin_inst_id') as $key) {
                 $option = $this->new_configs[$key];
                 if (isset($vars[$key])) {
                     $check->execute(array($option['name'], $user_id));
                     $stmt->execute(array(md5($option['name'] . $user_id), $user_id, $option['name'], (string) $vars[$key]));
                 }
             }
             if (isset($vars['my_studip_settings']['startpage_redirect'])) {
                 $option = $this->new_configs['my_studip_settings'];
                 $check->execute(array($option['name'], $user_id));
                 $stmt->execute(array(md5($option['name'] . $user_id), $user_id, $option['name'], (int) $vars['my_studip_settings']['startpage_redirect']));
             }
             if (isset($vars['_my_sem_open'])) {
                 $option = $this->new_configs['_my_sem_open'];
                 $check->execute(array($option['name'], $user_id));
                 $stmt->execute(array(md5($option['name'] . $user_id), $user_id, $option['name'], json_encode($vars['_my_sem_open'])));
             }
         }
     }
     DBManager::get()->exec("DROP TABLE `user_data`");
 }
Example #7
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)));
     }
 }
Example #8
0
 /**
  * Toggles whether a certain smiley is favored for the current user
  *
  * @param int    $id    Id of the smiley to favor/disfavor
  * @param String $view  View to return to
  */
 function favor_action($id, $view)
 {
     try {
         $state = $this->favorites->toggle($id);
         $message = $state ? _('Der Smiley wurde zu Ihren Favoriten hinzugefügt.') : _('Der Smiley gehört nicht mehr zu Ihren Favoriten.');
         $msg_box = MessageBox::success($message);
     } catch (OutOfBoundsException $e) {
         $state = $this->favorites->contain($id);
         $message = _('Maximale Favoritenzahl erreicht. Vielleicht sollten Sie mal ausmisten? :)');
         $msg_box = MessageBox::error($message);
     }
     if (Request::isXhr()) {
         $this->response->add_header('Content-Type', 'application/json');
         $this->render_text(json_encode(array('state' => $state, 'message' => studip_utf8encode($msg_box))));
     } else {
         PageLayout::postMessage($msg_box);
         $this->redirect('smileys/index/' . $view . '#smiley' . $id);
     }
 }
 public static function triggerFollowingStudips($eventname, $release)
 {
     $output = array();
     $payload = json_encode(studip_utf8encode($output));
     foreach ($release->followers as $follower) {
         $header = array();
         if ($follower['security_token']) {
             $calculatedHash = hash_hmac("sha1", $payload, $follower['security_token']);
             $header[] = "X_HUB_SIGNATURE: sha1=" . $calculatedHash;
         }
         $header[] = "Content-Type: application/json";
         $r = curl_init();
         curl_setopt($r, CURLOPT_URL, $follower['url']);
         curl_setopt($r, CURLOPT_POST, true);
         curl_setopt($r, CURLOPT_HTTPHEADER, $header);
         curl_setopt($r, CURLOPT_POSTFIELDS, $payload);
         $result = curl_exec($r);
         curl_close($r);
     }
 }
Example #10
0
/**
 * Prepares a string for use in .po file.
 *
 * @param String $string String to use in .po file
 * @return String Processed string
 */
function po_stringify($string)
{
    $string = studip_utf8encode($string);
    $string = str_replace("\r", '', $string);
    $chunks = explode("\n", $string);
    if (count($chunks) === 1 && strlen($chunks[0]) < MAX_LINE_LENGTH) {
        return '"' . po_escape($chunks[0]) . '"';
    }
    $result = '""' . "\n";
    foreach ($chunks as $index => $chunk) {
        $chunk = wordwrap($chunk, MAX_LINE_LENGTH);
        $parts = explode("\n", $chunk);
        foreach ($parts as $idx => $line) {
            $current_last = $idx === count($parts) - 1;
            $last = $current_last && $index === count($chunks) - 1;
            $result .= '"' . po_escape($line) . ($last ? '' : ($current_last ? '\\n' : ' ')) . '"' . "\n";
        }
    }
    return rtrim($result, "\n");
}
Example #11
0
 /**
  * This function tries to encode data of any type from Windows-1252 to
  * UTF-8, and returns the encoded version.
  *
  * If the argument `$data` is an array or an object that implements
  * `Traversable`, this function returns an associative array. Its keys
  * are encoded to UTF-8 and its values are send to this function
  * again.
  *
  * If the argument `$data` is a string or an object that responds to
  * `__toString`, this function casts it to a string and encodes it to
  * UTF-8.
  *
  * If the argument `$data` is of another scalar type (integer, float
  * or boolean) or is null, this function just returns that value
  * unchanged.
  *
  * If neither of these criteria match, this functions throws an
  * InvalidArgumentException.
  *
  * @param $data mixed  some data of any type that shall be encoded to
  *                     UTF-8 in the aforementioned manner
  *
  * @return mixed  that data encoded to UTF-8 as far as possible, see above
  *
  * @throws InvalidArgumentException This exception is thrown if there
  * is no way to encode such an object to UTF-8, e.g. database
  * connections, file handles etc.
  */
 private static function utf8encodeRecursive($data)
 {
     // array-artiges wird rekursiv durchlaufen
     if (is_array($data) || $data instanceof \Traversable) {
         $new_data = array();
         foreach ($data as $key => $value) {
             $key = studip_utf8encode((string) $key);
             $new_data[$key] = self::utf8encodeRecursive($value);
         }
         return $new_data;
     } else {
         if (is_string($data) || is_callable(array($data, '__toString'))) {
             return studip_utf8encode((string) $data);
         } elseif (is_null($data) || is_scalar($data)) {
             return $data;
         }
     }
     // alles andere ist ungültig
     throw new \InvalidArgumentException();
 }
Example #12
0
 /**
  * Common actions before any other action
  *
  * @param String $action Action to be executed
  * @param Array $args Arguments passed to the action
  * @throws Trails_Exception when either no course was found or the user
  *                          may not access this area
  */
 public function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     // Try to find a valid course
     if (Course::findCurrent()) {
         $course_id = Course::findCurrent()->id;
     } else {
         throw new Trails_Exception(404, _('Es wurde keine Veranstaltung ausgewählt!'));
     }
     if (!$GLOBALS['perm']->have_studip_perm('tutor', $course_id)) {
         throw new Trails_Exception(400);
     }
     // Get seminar instance
     $this->course = Seminar::getInstance($course_id);
     if (Navigation::hasItem('course/admin/dates')) {
         Navigation::activateItem('course/admin/dates');
     }
     $this->show = array('regular' => true, 'irregular' => true, 'roomRequest' => true);
     PageLayout::setHelpKeyword('Basis.Veranstaltungen');
     PageLayout::addSqueezePackage('raumzeit');
     $title = _('Verwaltung von Zeiten und Räumen');
     $title = $this->course->getFullname() . ' - ' . $title;
     PageLayout::setTitle($title);
     $_SESSION['raumzeitFilter'] = Request::get('newFilter');
     // bind linkParams for chosen semester and opened dates
     URLHelper::bindLinkParam('raumzeitFilter', $_SESSION['raumzeitFilter']);
     $this->checkFilter();
     $this->selection = $this->getSemestersForCourse($this->course, $_SESSION['raumzeitFilter']);
     if (!Request::isXhr()) {
         $this->setSidebar();
     } elseif (Request::isXhr() && $this->flash['update-times']) {
         $semester_id = $GLOBALS['user']->cfg->MY_COURSES_SELECTED_CYCLE;
         if ($semester_id === 'all') {
             $semester_id = '';
         }
         $this->response->add_header('X-Raumzeit-Update-Times', json_encode(studip_utf8encode(array('course_id' => $this->course->id, 'html' => Seminar::GetInstance($this->course->id)->getDatesHTML(array('semester_id' => $semester_id, 'show_room' => true)) ?: _('nicht angegeben')))));
     }
 }
Example #13
0
 /**
  * Call HTMLPurifier to create safe HTML.
  *
  * @param   string $dirty_html  Unsafe or 'uncleaned' HTML code.
  * @return  string              Clean and safe HTML code.
  */
 public static function purify($dirty_html)
 {
     // remember created purifier so it doesn't have to be created again
     static $purifier = NULL;
     if ($purifier === NULL) {
         $purifier = self::createPurifier();
     }
     return studip_utf8decode($purifier->purify(studip_utf8encode($dirty_html)));
 }
Example #14
0
 /**
  * store new value for existing config entry in database
  * posts notification ConfigValueChanged if entry is changed
  * @param string $field
  * @param string $data
  * @throws InvalidArgumentException
  * @return boolean
  */
 function store($field, $data)
 {
     if (!is_array($data) || !isset($data['value'])) {
         $values['value'] = $data;
     } else {
         $values = $data;
     }
     switch ($this->metadata[$field]['type']) {
         case 'boolean':
             $values['value'] = (bool) $values['value'];
             break;
         case 'integer':
             $values['value'] = (int) $values['value'];
             break;
         case 'array':
             $values['value'] = json_encode(studip_utf8encode($values['value']));
             break;
         default:
             $values['value'] = (string) $values['value'];
     }
     $entries = ConfigEntry::findByField($field);
     if (count($entries) === 0) {
         throw new InvalidArgumentException($field . " not found in config table");
     }
     if (isset($values['value'])) {
         if (count($entries) == 1 && $entries[0]->is_default == 1) {
             $entries[1] = clone $entries[0];
             $entries[1]->setId($entries[1]->getNewId());
             $entries[1]->setNew(true);
             $entries[1]->is_default = 0;
         }
         $value_entry = $entries[0]->is_default == 1 ? $entries[1] : $entries[0];
         $old_value = $value_entry->value;
         $value_entry->value = $values['value'];
     }
     foreach ($entries as $entry) {
         if (isset($values['section'])) {
             $entry->section = $values['section'];
         }
         if (isset($values['comment'])) {
             $entry->comment = $values['comment'];
         }
         // store the default-type for the modified entry
         $entry->type = $this->metadata[$field]['type'];
         if (count($entries) > 1 && !$entry->is_default && $entry->value == $entries[0]->value) {
             $ret += $entry->delete();
         } else {
             $ret += $entry->store();
         }
     }
     if ($ret) {
         $this->fetchData();
         if (isset($value_entry)) {
             NotificationCenter::postNotification('ConfigValueDidChange', $this, array('field' => $field, 'old_value' => $old_value, 'new_value' => $value_entry->value));
         }
     }
     return $ret > 0;
 }
Example #15
0
<? foreach ($items as $id => $item): ?>
        <item>
            <title><?php 
echo htmlReady(studip_utf8encode($item['topic']));
?>
</title>
            <link><?php 
echo htmlReady(studip_utf8encode(sprintf($item_url_fmt, $studip_url, $id)));
?>
</link>
            <description><![CDATA[<?php 
echo studip_utf8encode(formatready($item['body'], 1, 1));
?>
]]></description>
            <dc:contributor><![CDATA[<?php 
echo studip_utf8encode($item['author']);
?>
]]></dc:contributor>
            <dc:date><?php 
echo gmstrftime('%Y-%m-%dT%H:%MZ', $item['date']);
?>
</dc:date>
            <pubDate><?php 
echo date('r', $item['date']);
?>
</pubDate>
        </item>
<? endforeach; ?>
    </channel>
</rss>
Example #16
0
 public function context_action($questionnaire_id)
 {
     $this->questionnaire = new Questionnaire($questionnaire_id);
     if (!$this->questionnaire->isEditable()) {
         throw new AccessDeniedException("Der Fragebogen ist nicht bearbeitbar.");
     }
     foreach ($this->questionnaire->assignments as $relation) {
         if ($relation['range_type'] === "user") {
             $this->profile = $relation;
         }
         if ($relation['range_id'] === "public") {
             $this->public = $relation;
         }
         if ($relation['range_id'] === "start") {
             $this->start = $relation;
         }
     }
     if (Request::isPost()) {
         if (Request::get("user")) {
             if (!$this->profile) {
                 $this->profile = new QuestionnaireAssignment();
                 $this->profile['questionnaire_id'] = $this->questionnaire->getId();
                 $this->profile['range_id'] = $GLOBALS['user']->id;
                 $this->profile['range_type'] = "user";
                 $this->profile['user_id'] = $GLOBALS['user']->id;
                 $this->profile->store();
             }
         } else {
             if ($this->profile) {
                 $this->profile->delete();
             }
         }
         if (Request::get("public")) {
             if (!$this->public) {
                 $this->public = new QuestionnaireAssignment();
                 $this->public['questionnaire_id'] = $this->questionnaire->getId();
                 $this->public['range_id'] = "public";
                 $this->public['range_type'] = "static";
                 $this->public['user_id'] = $GLOBALS['user']->id;
                 $this->public->store();
             }
         } else {
             if ($this->public) {
                 $this->public->delete();
             }
         }
         if ($GLOBALS['perm']->have_perm("root")) {
             if (Request::get("start")) {
                 if (!$this->start) {
                     $this->start = new QuestionnaireAssignment();
                     $this->start['questionnaire_id'] = $this->questionnaire->getId();
                     $this->start['range_id'] = "start";
                     $this->start['range_type'] = "static";
                     $this->start['user_id'] = $GLOBALS['user']->id;
                     $this->start->store();
                 }
             } else {
                 if ($this->start) {
                     $this->start->delete();
                 }
             }
         }
         if (Request::option("add_seminar_id") && $GLOBALS['perm']->have_studip_perm("tutor", Request::option("add_seminar_id"))) {
             $course_assignment = new QuestionnaireAssignment();
             $course_assignment['questionnaire_id'] = $this->questionnaire->getId();
             $course_assignment['range_id'] = Request::option("add_seminar_id");
             $course_assignment['range_type'] = "course";
             $course_assignment['user_id'] = $GLOBALS['user']->id;
             $course_assignment->store();
         }
         if (Request::option("add_institut_id") && $GLOBALS['perm']->have_studip_perm("admin", Request::option("add_institut_id"))) {
             $course_assignment = new QuestionnaireAssignment();
             $course_assignment['questionnaire_id'] = $this->questionnaire->getId();
             $course_assignment['range_id'] = Request::option("add_institut_id");
             $course_assignment['range_type'] = "institute";
             $course_assignment['user_id'] = $GLOBALS['user']->id;
             $course_assignment->store();
         }
         foreach (Request::getArray("remove_sem") as $seminar_id) {
             if ($GLOBALS['perm']->have_studip_perm("tutor", $seminar_id)) {
                 $course_assignment = QuestionnaireAssignment::findBySeminarAndQuestionnaire($seminar_id, $this->questionnaire->getId());
                 $course_assignment->delete();
             }
         }
         PageLayout::postMessage(MessageBox::success(_("Die Bereichszuweisungen wurden gespeichert.")));
         $this->questionnaire->restore();
         $this->questionnaire->resetRelation("assignments");
         $output = array('func' => "STUDIP.Questionnaire.updateOverviewQuestionnaire", 'payload' => array('questionnaire_id' => $this->questionnaire->getId(), 'html' => $this->render_template_as_string("questionnaire/_overview_questionnaire.php")));
         $this->response->add_header("X-Dialog-Execute", json_encode(studip_utf8encode($output)));
     }
     PageLayout::setTitle(sprintf(_("Bereiche für Fragebogen: %s"), $this->questionnaire->title));
 }
Example #17
0
 /**
  * render given data as json, data is converted to utf-8
  *
  * @param unknown $data
  */
 function render_json($data)
 {
     $this->set_content_type('application/json;charset=utf-8');
     return $this->render_text(json_encode(studip_utf8encode($data)));
 }
Example #18
0
 /**
  * TODO
  */
 function toJSON($with_counter = true)
 {
     $answers = array();
     foreach ($this->answerArray as $answer) {
         $ary = array(
             'id'      => studip_utf8encode($answer['answer_id']),
             'text'    => studip_utf8encode($answer['text']));
         if ($with_counter) {
             $ary['counter'] = (int)$answer['counter'];
         }
         $answers[] = $ary;
     }
     return array(
         'id'             => $this->objectID,
         //'range_id'       => studip_utf8encode($this->rangeID),
         'question'       => studip_utf8encode($this->question),
         'question_html'  => studip_utf8encode(formatReady($this->question)),
         'startdate'      => (int)$this->getStartdate(),
         'stopdate'       => (int)$this->getStopdate(),
         'state'          => $this->getState(),
         'answers'        => $answers
     );
 }
Example #19
0
/**
 * escapes special characters for xml use
 * optinally encodes to utf8
 *
 * @param string $string the string to escape
 * @param bool $utf8encode encode the string as utf-8
 * @return string
 */
function xml_escape($string, $utf8encode = true)
{
    $string = preg_replace('/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string);
    if ($utf8encode) {
        return htmlspecialchars(studip_utf8encode($string), ENT_QUOTES, 'UTF-8');
    } else {
        return htmlspecialchars(html_entity_decode($string, ENT_QUOTES, 'cp1252'), ENT_QUOTES, 'cp1252', false);
    }
}
Example #20
0
<? if (count($vote->answers) > 0 && count($data['options']) > 0) : ?>
    <div style="max-height: none; opacity: 1;" id="questionnaire_<?php 
echo $vote->getId();
?>
_chart" class="ct-chart"></div>
    <script>
    <?php 
echo Request::isAjax() ? 'jQuery(document).add(".questionnaire_results").one("dialog-open", function () {' : 'jQuery(function () {';
?>
        var data = {
            labels: <?php 
echo json_encode(studip_utf8encode($ordered_options));
?>
,
            series: [<?php 
echo json_encode(studip_utf8encode($ordered_results));
?>
]
        };
        <? if ($vote['questiondata']['multiplechoice']) : ?>
            new Chartist.Bar('#questionnaire_<?php 
echo $vote->getId();
?>
_chart', data, { onlyInteger: true, axisY: { onlyInteger: true } });
        <? else : ?>
            data.series = data.series[0];
            new Chartist.Pie('#questionnaire_<?php 
echo $vote->getId();
?>
_chart', data, { labelPosition: 'outside' });
        <? endif ?>
Example #21
0
 /**
  * sends tour object as json data
  *
  * @param  string $tour_id    id of tour object
  * @param  String $step_nr    number of step to start with
  */
 function get_data_action($tour_id, $step_nr = 1)
 {
     $this->route = get_route(Request::get('route'));
     $this->tour = new HelpTour($tour_id);
     if (!$this->tour->isVisible() or !$this->route) {
         return $this->render_nothing();
     }
     $this->user_visit = new HelpTourUser(array($tour_id, $GLOBALS['user']->user_id));
     if ($this->user_visit->step_nr > 1 and !$_SESSION['active_tour']['step_nr'] and $this->tour->type == 'tour') {
         $data['last_run'] = sprintf(_('Wollen Sie die Tour "%s" an der letzten Position fortsetzen?'), $this->tour->name);
         $data['last_run_step'] = $this->user_visit->step_nr;
         $data['last_run_href'] = URLHelper::getURL($this->tour->steps[$this->user_visit->step_nr - 1]->route, NULL, true);
     } else {
         $_SESSION['active_tour'] = array('tour_id' => $tour_id, 'step_nr' => $step_nr, 'last_route' => $this->tour->steps[$step_nr - 1]->route, 'previous_route' => '', 'next_route' => '');
         $this->user_visit->step_nr = $step_nr;
         $this->user_visit->store();
     }
     $first_step = $step_nr;
     while ($first_step > 1 and $this->route == $this->tour->steps[$first_step - 2]->route) {
         $first_step--;
     }
     if ($first_step > 1 and $this->tour->type == 'tour') {
         $data['back_link'] = URLHelper::getURL($this->tour->steps[$first_step - 2]->route, NULL, true);
         $_SESSION['active_tour']['previous_route'] = $this->tour->steps[$first_step - 2]->route;
     }
     $data['route_step_nr'] = $first_step;
     $next_first_step = $first_step;
     while ($this->route == $this->tour->steps[$next_first_step - 1]->route) {
         $data['data'][] = array('step_nr' => $this->tour->steps[$next_first_step - 1]->step, 'element' => $this->tour->steps[$next_first_step - 1]->css_selector, 'title' => htmlReady($this->tour->steps[$next_first_step - 1]->title), 'tip' => formatReady($this->tour->steps[$next_first_step - 1]->tip), 'route' => $this->tour->steps[$next_first_step - 1]->route, 'action_next' => $this->tour->steps[$next_first_step - 1]->action_next, 'action_prev' => $this->tour->steps[$next_first_step - 1]->action_prev, 'interactive' => $this->tour->steps[$next_first_step - 1]->interactive ? '1' : '', 'orientation' => $this->tour->steps[$next_first_step - 1]->orientation);
         $next_first_step++;
     }
     if ($this->tour->steps[$step_nr - 1]->route != $this->route) {
         $data['redirect'] = URLHelper::getURL($this->tour->steps[$step_nr - 1]->route, NULL, true);
     } elseif (!count($data['data'])) {
         return $this->render_nothing();
     }
     if ($next_first_step <= count($this->tour->steps)) {
         if ($this->tour->type == 'tour') {
             $data['proceed_link'] = URLHelper::getURL($this->tour->steps[$next_first_step - 1]->route, NULL, true);
         }
         $_SESSION['active_tour']['next_route'] = $this->tour->steps[$next_first_step - 1]->route;
     }
     $data['edit_mode'] = $this->help_admin;
     $data['step_count'] = count($this->tour->steps);
     $data['controls_position'] = 'BR';
     $data['tour_type'] = $this->tour->type;
     $data['tour_title'] = htmlReady($this->tour->name);
     $template = $GLOBALS['template_factory']->open('tour/tour.php');
     $template->set_layout(null);
     $data['tour_html'] = $template->render();
     $this->set_content_type('application/json; charset=UTF-8');
     return $this->render_text(json_encode(studip_utf8encode($data)));
 }
Example #22
0
*
* @author Jan-Hendrik Willms <*****@*****.**>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 3.1
* @todo Parameter handling!
*/
require_once 'studip_cli_env.inc.php';
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];
$opts = getopt('hl', array('help', 'list'));
if (isset($opts['l']) || isset($opts['list'])) {
    $tasks = CronjobTask::findBySql('1');
    foreach ($tasks as $task) {
        $description = call_user_func(array($task->class, 'getDescription'));
        fwrite(STDOUT, sprintf('%s %s' . PHP_EOL, $task->id, studip_utf8encode($description)));
    }
    exit(0);
}
if ($argc < 2 || isset($opts['h']) || isset($opts['help'])) {
    fwrite(STDOUT, 'Usage: ' . basename(__FILE__) . ' [--help] [--list] <task_id> [last_result]' . PHP_EOL);
    exit(0);
}
$id = $_SERVER['argv'][1];
$last_result = $argc > 2 ? $_SERVER['argv'][2] : null;
$task = CronjobTask::find($id);
if (!$task) {
    fwrite(STDOUT, 'Unknown task id' . PHP_EOL);
    exit(0);
}
if (!file_exists($GLOBALS['STUDIP_BASE_PATH'] . '/' . $task->filename)) {
Example #23
0
 /**
  * @see lib/classes/Config::store()
  */
 function store($field, $value)
 {
     $entry = UserConfigEntry::findByFieldAndUser($field, $this->user_id);
     if ($entry === null) {
         $entry = new UserConfigEntry();
         $entry->user_id = $this->user_id;
         $entry->field = $field;
         $entry->comment = '';
     }
     $metadata = Config::get()->getMetadata($field);
     switch ($metadata['type']) {
         case 'integer':
         case 'boolean':
             $value = (int) $value;
             break;
         case 'array':
             $value = json_encode(studip_utf8encode($value));
             break;
         default:
             $value = (string) $value;
     }
     $entry->value = $value;
     $ret = $entry->store();
     if ($ret) {
         $this->fetchData();
     }
     return $ret;
 }
 public function load_action()
 {
     $db = DBManager::get();
     if (!$GLOBALS['perm']->have_perm("root")) {
         $range_ids = $db->query("SELECT Seminar_id FROM seminar_user WHERE user_id = " . $db->quote($GLOBALS['user']->id) . " ")->fetchAll(PDO::FETCH_COLUMN, 0);
         $range_ids[] = $GLOBALS['user']->id;
     } else {
         $range_ids = array();
     }
     $searchstring = $_SESSION['search_parameter']['search'];
     $filter = array();
     if ($_SESSION['search_parameter']['study_area']) {
         //Auf Studienbereich einschränken:
         $study_areas = TreeAbstract::getInstance('StudipSemTree', false);
         $path = $study_areas->getParents($_SESSION['search_parameter']['study_area']);
         $filter[] = "sem_tree_" . implode("_", $path);
     }
     $output = array('more' => 0);
     $results = Globalsearch::get()->search($searchstring, $range_ids, null, $filter, Request::int("offset") * $this->maximum_results, $this->maximum_results + 1);
     if (count($results) > $this->maximum_results) {
         array_pop($results);
         $output['more'] = 1;
     }
     //Ergebnisse nochmal prozessieren:
     foreach ($results as $key => $result) {
         $result = (object) $result;
         $result->tools = array();
         NotificationCenter::postNotification("WillDisplaySearchResultItem", $result);
         if (!$result->forbidden) {
             $results[$key] = $result;
         } else {
             //Wenn Rechte fehlen, sollte das Objekt nicht angezeigt werden.
             //Der Observer der Notification schreibt dann: $result->forbidden = true;
             unset($results[$key]);
         }
         $template = $this->getTemplate("result.php", null);
         $template->set_attribute('result', $result);
         $output['results'][] = studip_utf8encode($template->render());
     }
     echo json_encode($output);
 }
Example #25
0
 public function save_action()
 {
     if (count($_POST) === 0) {
         throw new Exception("Kein Zugriff über GET");
     }
     $sem_class = $GLOBALS['SEM_CLASS'][Request::int("sem_class_id")];
     foreach (Request::getArray("core_module_slots") as $slot => $module) {
         $sem_class->setSlotModule($slot, studip_utf8decode($module));
     }
     $sem_class->setModules(Request::getArray("modules"));
     $sem_class->set('name', Request::get("sem_class_name"));
     $sem_class->set('description', studip_utf8decode(Request::get("sem_class_description")));
     $sem_class->set('title_dozent', Request::get("title_dozent") ? studip_utf8decode(Request::get("title_dozent")) : null);
     $sem_class->set('title_dozent_plural', Request::get("title_dozent_plural") ? studip_utf8decode(Request::get("title_dozent_plural")) : null);
     $sem_class->set('title_tutor', Request::get("title_tutor") ? studip_utf8decode(Request::get("title_tutor")) : null);
     $sem_class->set('title_tutor_plural', Request::get("title_tutor_plural") ? studip_utf8decode(Request::get("title_tutor_plural")) : null);
     $sem_class->set('title_autor', Request::get("title_autor") ? studip_utf8decode(Request::get("title_autor")) : null);
     $sem_class->set('title_autor_plural', Request::get("title_autor_plural") ? studip_utf8decode(Request::get("title_autor_plural")) : null);
     $sem_class->set('compact_mode', Request::int("compact_mode"));
     $sem_class->set('workgroup_mode', Request::int("workgroup_mode"));
     $sem_class->set('studygroup_mode', Request::int("studygroup_mode"));
     $sem_class->set('only_inst_user', Request::int("only_inst_user"));
     $sem_class->set('turnus_default', Request::int("turnus_default"));
     $sem_class->set('default_read_level', Request::int("default_read_level"));
     $sem_class->set('default_write_level', Request::int("default_write_level"));
     $sem_class->set('bereiche', Request::int("bereiche"));
     $sem_class->set('show_browse', Request::int("show_browse"));
     $sem_class->set('write_access_nobody', Request::int("write_access_nobody"));
     $sem_class->set('topic_create_autor', Request::int("topic_create_autor"));
     $sem_class->set('visible', Request::int("visible"));
     $sem_class->set('course_creation_forbidden', Request::int("course_creation_forbidden"));
     $sem_class->set('create_description', studip_utf8decode(Request::get("create_description")));
     $sem_class->set('admission_prelim_default', Request::int("admission_prelim_default"));
     $sem_class->set('admission_type_default', Request::int("admission_type_default"));
     $sem_class->store();
     if (!count($sem_class->getSemTypes())) {
         $notice = "<br>" . _("Beachten Sie, dass es noch keine Veranstaltungstypen gibt!");
     }
     $output = array('html' => studip_utf8encode((string) MessageBox::success(_("Änderungen wurden gespeichert." . " " . '<a href="' . URLHelper::getLink("dispatch.php/admin/sem_classes/overview") . '">' . _("Zurück zur Übersichtsseite.") . '</a>') . $notice)));
     echo json_encode($output);
     $this->render_nothing();
 }
Example #26
0
 /**
  * edit one room requests in a dialog
  */
 public function edit_dialog_action()
 {
     if (Request::isXhr()) {
         $request = Request::getInstance();
         foreach ($request as $key => $value) {
             $request[$key] = studip_utf8decode($value);
         }
         if ($this->course_id != '-') {
             $this->edit_action();
             $title = PageLayout::getTitle();
         } else {
             $sem_create_data =& $_SESSION['sem_create_data'];
             if (Request::option('new_room_request_type')) {
                 if ($sem_create_data['room_requests'][Request::option('new_room_request_type')] instanceof RoomRequest) {
                     $request = clone $sem_create_data['room_requests'][Request::option('new_room_request_type')];
                 } else {
                     $request = new RoomRequest();
                     $request->seminar_id = '-';
                     $request->user_id = $GLOBALS['user']->id;
                     list($new_type, $id) = explode('_', Request::option('new_room_request_type'));
                     if ($new_type == 'date') {
                         $request->termin_id = Request::option('new_room_request_type');
                     } elseif ($new_type == 'cycle') {
                         $request->metadate_id = Request::option('new_room_request_type');
                     }
                 }
                 $room_request_form_attributes = self::process_form($request, $sem_create_data['sem_turnout']);
                 $this->search_result = $room_request_form_attributes['search_result'];
                 $this->search_by_properties = $room_request_form_attributes['search_by_properties'];
                 $this->admission_turnout = $sem_create_data['sem_turnout'];
                 $this->request = $request;
                 $room_categories = array_values(array_filter(getResourcesCategories(), create_function('$a', 'return $a["is_room"] == 1;')));
                 if (!$request->getCategoryId() && count($room_categories) == 1) {
                     $request->setCategoryId($room_categories[0]['category_id']);
                 }
                 $this->room_categories = $room_categories;
                 $this->new_room_request_type = Request::option('new_room_request_type');
                 $this->is_resources_admin = getGlobalPerms($GLOBALS['user']->id);
                 $title = _("Verwaltung von Raumanfragen");
                 if (Request::submitted('save') || Request::submitted('save_close')) {
                     if ($request->getSettedPropertiesCount() || $request->getResourceId()) {
                         $sem_create_data['room_requests'][Request::option('new_room_request_type')] = $request;
                         $this->request_stored = true;
                         if (Request::submitted('save')) {
                             PageLayout::postMessage(MessageBox::success(_("Die Raumanfrage und gewünschte Raumeigenschaften wurden gespeichert")));
                         }
                     } else {
                         PageLayout::postMessage(MessageBox::error(_("Die Anfrage kann noch nicht gespeichert werden, da Sie mindestens einen Raum oder mindestens eine Eigenschaft (z.B. Anzahl der Sitzplätze) angeben müssen!")));
                     }
                 }
                 $old_request = $sem_create_data['room_requests'][Request::option('new_room_request_type')];
                 if (!is_object($old_request) || $request->category_id != $old_request->category_id || $request->resource_id != $old_request->resource_id || $request->getProperties() != $old_request->getProperties() || $request->comment != $old_request->comment) {
                     PageLayout::postMessage(MessageBox::info(_("Die Änderungen an der Raumanfrage wurden noch nicht gespeichert!")));
                 }
             }
         }
         if (Request::submitted('save_close') && isset($this->request_stored)) {
             return $this->render_json(array('auto_close' => true, 'auto_reload' => $this->request_stored));
         } else {
             $this->render_template('course/room_requests/edit_dialog.php', null);
             $this->flash->discard();
             $content = $this->get_response()->body;
             $this->erase_response();
             return $this->render_json(array('title' => studip_utf8encode($title), 'content' => studip_utf8encode($content)));
         }
     } else {
         return $this->render_text('');
     }
 }
Example #27
0
 /**
  * check reference by title
  *
  * gets reference-id by object-title
  * @access public
  * @param string key keyword
  * @param string type object-type
  * @return string reference-id
  */
 function checkReferenceById($id)
 {
     $param = array('sid' => $this->getSID(), 'reference_id' => studip_utf8encode($id));
     $result = $this->call('getObjectByReference', $param);
     if ($result != false) {
         $objects = $this->parseXML($result);
         //echo "<pre><hr>".print_r($objects,1);
         //echo "\n</pre><hr>";
         if (is_array($objects)) {
             foreach ($objects as $index => $object_data) {
                 if (is_array($object_data['references'])) {
                     foreach ($object_data['references'] as $reference) {
                         if ($reference['ref_id'] == $id && $reference['accessInfo'] != 'object_deleted') {
                             return $object_data['obj_id'];
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Example #28
0
 public function post_files_action()
 {
     $context = Request::option("context") ? Request::get("context") : $GLOBALS['user']->id;
     $context_type = Request::option("context_type");
     if (!Request::isPost() || $context_type === "course" && !$GLOBALS['perm']->have_studip_perm("autor", $context)) {
         throw new AccessDeniedException("Kein Zugriff");
     }
     //check folders
     $db = DBManager::get();
     $folder_id = md5("Blubber_" . $context . "_" . $GLOBALS['user']->id);
     $parent_folder_id = md5("Blubber_" . $context);
     if ($context_type !== "course") {
         $folder_id = $parent_folder_id;
     }
     $folder = $db->query("SELECT * " . "FROM folder " . "WHERE folder_id = " . $db->quote($folder_id) . " " . "")->fetch(PDO::FETCH_COLUMN, 0);
     if (!$folder) {
         $folder = $db->query("SELECT * " . "FROM folder " . "WHERE folder_id = " . $db->quote($parent_folder_id) . " " . "")->fetch(PDO::FETCH_COLUMN, 0);
         if (!$folder) {
             $db->exec("INSERT IGNORE INTO folder " . "SET folder_id = " . $db->quote($parent_folder_id) . ", " . "range_id = " . $db->quote($context) . ", " . "user_id = " . $db->quote($GLOBALS['user']->id) . ", " . "name = " . $db->quote("BlubberDateien") . ", " . "permission = '7', " . "mkdate = " . $db->quote(time()) . ", " . "chdate = " . $db->quote(time()) . " " . "");
         }
         if ($context_type === "course") {
             $db->exec("INSERT IGNORE INTO folder " . "SET folder_id = " . $db->quote($folder_id) . ", " . "range_id = " . $db->quote($parent_folder_id) . ", " . "user_id = " . $db->quote($GLOBALS['user']->id) . ", " . "name = " . $db->quote(get_fullname()) . ", " . "permission = '7', " . "mkdate = " . $db->quote(time()) . ", " . "chdate = " . $db->quote(time()) . " " . "");
         }
     }
     $output = array();
     foreach ($_FILES as $file) {
         $GLOBALS['msg'] = '';
         if ($context_type === "course") {
             validate_upload($file);
             if ($GLOBALS['msg']) {
                 $output['errors'][] = $file['name'] . ': ' . studip_utf8encode(html_entity_decode(trim(substr($GLOBALS['msg'], 6), '§')));
                 continue;
             }
         }
         if ($file['size']) {
             $document['name'] = $document['filename'] = studip_utf8decode(strtolower($file['name']));
             $document['user_id'] = $GLOBALS['user']->id;
             $document['author_name'] = get_fullname();
             $document['seminar_id'] = $context;
             $document['range_id'] = $context_type === "course" ? $folder_id : $parent_folder_id;
             $document['filesize'] = $file['size'];
             if ($newfile = StudipDocument::createWithFile($file['tmp_name'], $document)) {
                 $type = null;
                 strpos($file['type'], 'image') === false || ($type = "img");
                 strpos($file['type'], 'video') === false || ($type = "video");
                 if (strpos($file['type'], 'audio') !== false || strpos($document['filename'], '.ogg') !== false) {
                     $type = "audio";
                 }
                 $url = GetDownloadLink($newfile->getId(), $newfile['filename']);
                 if ($type) {
                     $output['inserts'][] = "[" . $type . "]" . $url;
                 } else {
                     $output['inserts'][] = "[" . $newfile['filename'] . "]" . $url;
                 }
             }
         }
     }
     $this->render_json($output);
 }
Example #29
0
 /**
  * Converts all strings within an array (except for indexes)
  * from windows 1252 to utf8. PHP-objects are ignored.
  * @param array $data: any array with strings in windows-1252 encoded
  * @return array: almost the same array but strings are now utf8-encoded
  */
 protected function recursive_studip_utf8encode(array $data)
 {
     foreach ($data as $key => $component) {
         if (is_array($component)) {
             $data[$key] = $this->recursive_studip_utf8encode($component);
         } elseif (is_string($component)) {
             $data[$key] = studip_utf8encode($component);
         }
     }
     return $data;
 }
Example #30
0
 public static function correctText($text)
 {
     return Helper::url_to_link(studip_utf8encode($text));
 }