Beispiel #1
0
 /**
  * Overwrites the parent method. This method combines messages with the same
  * content and prepares them for sending them as a mail with multiple 
  * recepients instead of one mail for each recipient.
  * The actual sending task is done bulkSend().
  * 
  * @global object $user
  * 
  * @param string $rec_user_id  user_id of recipient
  * @param string $snd_user_id  user_id of sender
  * @param string $message      the message
  * @param string $subject      subject for the message
  * @param string $message_id   the message_id in the database
  */
 function sendingEmail($rec_user_id, $snd_user_id, $message, $subject, $message_id)
 {
     global $user;
     $db4 = new DB_Seminar("SELECT user_id, Email FROM auth_user_md5 WHERE user_id = '{$rec_user_id}';");
     $db4->next_record();
     if ($to = $db4->f("Email")) {
         $rec_fullname = 'Sie';
         setTempLanguage($db4->f("user_id"));
         if (empty($this->bulk_mail[md5($message)][getenv('LANG')])) {
             $title = "[Stud.IP - " . $GLOBALS['UNI_NAME_CLEAN'] . "] " . stripslashes(kill_format(str_replace(array("\r", "\n"), '', $subject)));
             if ($snd_user_id != "____%system%____") {
                 $snd_fullname = get_fullname($snd_user_id);
                 $db4->query("SELECT Email FROM auth_user_md5 WHERE user_id = '{$user->id}'");
                 $db4->next_record();
                 $reply_to = $db4->f("Email");
             }
             $template = $GLOBALS['template_factory']->open('mail/text');
             $template->set_attribute('message', kill_format(stripslashes($message)));
             $template->set_attribute('rec_fullname', $rec_fullname);
             $mailmessage = $template->render();
             $template = $GLOBALS['template_factory']->open('mail/html');
             $template->set_attribute('lang', getUserLanguagePath($rec_user_id));
             $template->set_attribute('message', stripslashes($message));
             $template->set_attribute('rec_fullname', $rec_fullname);
             $mailhtml = $template->render();
             $this->bulk_mail[md5($message)][getenv('LANG')] = array('text' => $mailmessage, 'html' => $mailhtml, 'title' => $title, 'reply_to' => $reply_to, 'message_id' => $message_id, 'users' => array());
         }
         $this->bulk_mail[md5($message)][getenv('LANG')]['users'][$db4->f('user_id')] = $to;
         restoreLanguage();
     }
 }
 function getResult($level_id = null)
 {
     global $_fullname_sql, $SEM_TYPE, $SEM_CLASS;
     $add_fields = '';
     $add_query = '';
     $sem_tree_query = '';
     $limit_sql = '';
     $orderby_field = $this->config->getValue('Main', 'resultorderby') ? $this->config->getValue('Main', 'resultorderby') : 'VeranstaltungsNummer';
     if ($this->sem_browse_data['group_by'] == 1 || sizeof($this->config->getValue('SelectSubjectAreas', 'subjectareasselected')) && !($this->config->getValue('SelectSubjectAreas', 'selectallsubjectareas') || $this->sem_browse_data['start_item_id'] == 'root')) {
         if ($this->config->getValue('Main', 'mode') == 'show_sem_range' && $this->sem_browse_data['start_item_id'] != 'root') {
             $allowed_ranges = array();
             if (is_null($level_id)) {
                 if (!is_object($this->sem_tree)) {
                     $this->sem_tree = TreeAbstract::GetInstance('StudipSemTree');
                 }
                 if ($kids = $this->sem_tree->getKidsKids($this->sem_browse_data['start_item_id'])) {
                     $allowed_ranges = $kids;
                 }
                 $allowed_ranges[] = $this->sem_browse_data['start_item_id'];
             } else {
                 $allowed_ranges[] = $level_id;
             }
             if ($this->config->getValue('SelectSubjectAreas', 'selectallsubjectareas')) {
                 $sem_tree_query = " AND sem_tree_id IN('" . join("','", $allowed_ranges) . "') ";
             } elseif (is_array($this->config->getValue('SelectSubjectAreas', 'subjectareasselected'))) {
                 if ($this->config->getValue('SelectSubjectAreas', 'reverseselection')) {
                     $allowed_ranges = array_diff($allowed_ranges, $this->config->getValue('SelectSubjectAreas', 'subjectareasselected'));
                 } else {
                     $allowed_ranges = array_intersect($allowed_ranges, $this->config->getValue('SelectSubjectAreas', 'subjectareasselected'));
                 }
                 $sem_tree_query = " AND sem_tree_id IN('" . join("','", $allowed_ranges) . "') ";
             } else {
                 return array(array(), array());
             }
         }
         $add_fields = 'seminar_sem_tree.sem_tree_id AS bereich,';
         $add_query = "LEFT JOIN seminar_sem_tree ON (seminare.Seminar_id = seminar_sem_tree.seminar_id)";
     } else {
         if ($this->config->getValue('Main', 'maxnumberofhits')) {
             $limit_sql = ' ORDER BY sem_number DESC, ' . $orderby_field . ' ASC LIMIT ' . ($this->module_params['start'] ? intval($this->module_params['start']) : '0') . ',' . $this->config->getValue('Main', 'maxnumberofhits');
         }
     }
     if ($this->sem_browse_data['group_by'] == 4) {
         $add_fields = 'Institute.Name AS Institut,Institute.Institut_id,';
         $add_query = 'LEFT JOIN seminar_inst ON (seminare.Seminar_id = seminar_inst.Seminar_id)
         LEFT JOIN Institute ON (Institute.Institut_id = seminar_inst.institut_id)';
     }
     // show only selected SemTypes
     $selected_semtypes = $this->config->getValue('ReplaceTextSemType', 'visibility');
     $sem_types_array = array();
     if (count($selected_semtypes)) {
         for ($i = 0; $i < count($selected_semtypes); $i++) {
             if ($selected_semtypes[$i] == '1') {
                 $sem_types_array[] = $i + 1;
             }
         }
         $sem_types_query = "AND seminare.status IN ('" . implode("','", $sem_types_array) . "')";
     } else {
         $sem_types_query = '';
     }
     // participated institutes (or show only courses located at this faculty)
     /*
     $sem_inst_query = '';
     if (!$this->config->getValue('Main', 'allseminars')) {
         $tree = TreeAbstract::GetInstance('StudipRangeTree');
         $kidskids = $tree->getKidsKids($this->sem_browse_data['start_item_id']);
         $institute_ids = array($tree->tree_data[$this->sem_browse_data['start_item_id']]['studip_object_id']);
         foreach ($kidskids as $kid) {
             $institute_ids[] = $tree->tree_data[$kid]['studip_object_id'];
         }
         $sem_inst_query = " AND seminare.Institut_id IN ('" . join("','", $institute_ids) . "')";
     }
     */
     if (!($nameformat = $this->config->getValue('Main', 'nameformat'))) {
         $nameformat = 'full_rev';
     }
     $dbv = DbView::getView('sem_tree');
     $query = "SELECT seminare.Seminar_id, VeranstaltungsNummer, seminare.status, seminare.Untertitel, seminare.Ort, seminare.art, seminare.Beschreibung, seminare.ects, IF(seminare.visible=0,CONCAT(seminare.Name, ' " . _("(versteckt)") . "'), seminare.Name) AS Name,\n                {$add_fields}" . $_fullname_sql[$nameformat] . " AS fullname, auth_user_md5.username, title_front, title_rear, Vorname, Nachname,\n                " . $dbv->sem_number_sql . " AS sem_number, " . $dbv->sem_number_end_sql . " AS sem_number_end, seminar_user.position AS position FROM seminare\n                LEFT JOIN seminar_user ON (seminare.Seminar_id=seminar_user.Seminar_id AND seminar_user.status='dozent')\n                LEFT JOIN auth_user_md5 USING (user_id)\n                LEFT JOIN user_info USING (user_id)\n                {$add_query}\n                WHERE seminare.Seminar_id IN('" . join("','", array_keys($this->sem_browse_data['search_result'])) . "') {$sem_types_query} {$sem_inst_query} {$sem_tree_query} {$limit_sql}";
     $db = new DB_Seminar($query);
     if (!$db->num_rows()) {
         return array(array(), array());
     }
     $snap = new DbSnapshot($db);
     $group_field = $this->group_by_fields[$this->sem_browse_data['group_by']]['group_field'];
     $data_fields[0] = 'Seminar_id';
     if ($this->group_by_fields[$this->sem_browse_data['group_by']]['unique_field']) {
         $data_fields[1] = $this->group_by_fields[$this->sem_browse_data['group_by']]['unique_field'];
     }
     $group_by_data = $snap->getGroupedResult($group_field, $data_fields);
     $sem_data = $snap->getGroupedResult('Seminar_id');
     if ($this->sem_browse_data['group_by'] == 0) {
         $semester = SemesterData::GetSemesterArray();
         $group_by_duration = $snap->getGroupedResult('sem_number_end', array('sem_number', 'Seminar_id'));
         foreach ($group_by_duration as $sem_number_end => $detail) {
             if ($sem_number_end != -1 && ($detail['sem_number'][$sem_number_end] && count($detail['sem_number']) == 1)) {
                 continue;
             } else {
                 foreach ($detail['Seminar_id'] as $seminar_id => $foo) {
                     $start_sem = key($sem_data[$seminar_id]['sem_number']);
                     if ($sem_number_end == -1) {
                         $sem_number_end = count($semester) - 1;
                     }
                     for ($i = $start_sem; $i <= $sem_number_end; ++$i) {
                         if ($this->sem_number === false || is_array($this->sem_number) && in_array($i, $this->sem_number)) {
                             if ($group_by_data[$i] && !$tmp_group_by_data[$i]) {
                                 foreach ($group_by_data[$i]['Seminar_id'] as $id => $bar) {
                                     $tmp_group_by_data[$i]['Seminar_id'][$id] = true;
                                 }
                             }
                             $tmp_group_by_data[$i]['Seminar_id'][$seminar_id] = true;
                         }
                     }
                 }
             }
         }
         if (is_array($tmp_group_by_data)) {
             if ($this->sem_number !== false) {
                 unset($group_by_data);
             }
             foreach ($tmp_group_by_data as $start_sem => $detail) {
                 $group_by_data[$start_sem] = $detail;
             }
         }
     }
     //release memory
     unset($snap);
     unset($tmp_group_by_data);
     foreach ($group_by_data as $group_field => $sem_ids) {
         foreach ($sem_ids['Seminar_id'] as $seminar_id => $foo) {
             if ($orderby_field) {
                 $name = strtolower(key($sem_data[$seminar_id][$orderby_field]));
             } else {
                 $name = strtolower(key($sem_data[$seminar_id]["VeranstaltungsNummer"]));
             }
             $name = str_replace(array('ä', 'ö', 'ü'), array('ae', 'oe', 'ue'), $name);
             $group_by_data[$group_field]['Seminar_id'][$seminar_id] = $name;
         }
         uasort($group_by_data[$group_field]['Seminar_id'], 'strnatcmp');
     }
     switch ($this->sem_browse_data['group_by']) {
         case 0:
             krsort($group_by_data, SORT_NUMERIC);
             break;
         case 1:
             uksort($group_by_data, create_function('$a,$b', '$the_tree = TreeAbstract::GetInstance("StudipSemTree", false);
         $the_tree->buildIndex();
         return (int)($the_tree->tree_data[$a]["index"] - $the_tree->tree_data[$b]["index"]);
         '));
             break;
         case 3:
             uksort($group_by_data, create_function('$a,$b', 'global $SEM_CLASS,$SEM_TYPE;
         return strnatcasecmp($SEM_TYPE[$a]["name"]." (". $SEM_CLASS[$SEM_TYPE[$a]["class"]]["name"].")",
         $SEM_TYPE[$b]["name"]." (". $SEM_CLASS[$SEM_TYPE[$b]["class"]]["name"].")");'));
             break;
         default:
             uksort($group_by_data, 'strnatcasecmp');
             break;
     }
     return array($group_by_data, $sem_data);
 }
function set_highscore($score = 0)
{
    $db = new DB_Seminar("INSERT INTO murmeln_highscore (score,user_id,name) VALUES (\n\t\t\t\t\t\t\t{$score}, '" . $GLOBALS['user']->id . "','" . mysql_escape_string(get_fullname()) . "')");
    return $db->affected_rows();
}
    private function getContentListCharacters () {
        $selected_item_ids = $this->config->getValue('SelectInstitutes', 'institutesselected');
        // at least one institute has to be selected in the configuration
        if (!is_array($selected_item_ids)) {
            return array();
        }
        $content = array();

        // at least one institute has to be selected in the configuration
        if (!is_array($selected_item_ids)) {
            return array();
        }
        $db = new DB_Seminar();
        $dbv = DbView::getView('sem_tree');
        if ($this->config->getValue('Main', 'onlylecturers')) {
            $current_semester = get_sem_num(time());
                $query = sprintf("SELECT COUNT(DISTINCT aum.user_id) as count_user, "
                . "UPPER(LEFT(TRIM(aum.Nachname),1)) AS initiale "
                . "FROM user_inst ui "
                . "LEFT JOIN seminar_user su ON ui.user_id = su.user_id "
                . "LEFT JOIN seminare s ON su.Seminar_id = s.Seminar_id "
                . "LEFT JOIN auth_user_md5 aum ON su.user_id = aum.user_id "
                . "WHERE su.status = 'dozent' AND s.visible = 1 "
                . "AND ((%s) = %s OR ((%s) <= %s  AND ((%s) >= %s OR (%s) = -1))) "
                . "AND TRIM(aum.Nachname) != '' "
                . "AND ui.Institut_id IN ('%s') "
                . "AND ui.externdefault = 1 "
                . "AND " . get_ext_vis_query()
                . "GROUP BY initiale",
                $dbv->sem_number_sql,
                $current_semester,
                $dbv->sem_number_sql,
                $current_semester,
                $dbv->sem_number_end_sql,
                $current_semester,
                $dbv->sem_number_end_sql,
                implode("','", $selected_item_ids));
        } else {
            $query = sprintf("SELECT COUNT(DISTINCT ui.user_id) as count_user, "
                . "UPPER(LEFT(TRIM(aum.Nachname),1)) AS initiale "
                . "FROM user_inst ui "
                . "LEFT JOIN auth_user_md5 aum USING (user_id) "
                . "WHERE ui.inst_perms IN ('%s') "
                . "AND ui.Institut_id IN ('%s') "
                . "AND ui.externdefault = 1 "
                . "AND TRIM(aum.Nachname) != '' "
                . "GROUP BY initiale",
                implode("','", $this->config->getValue('Main', 'instperms')),
                implode("','", $selected_item_ids));
        }
        
        $db->query($query);
        while ($db->next_record()) {
            $content['LIST_CHARACTERS']['CHARACTER'][] = array(
                'CHARACTER_USER' => ExternModule::ExtHtmlReady($db->f('initiale')),
                'CHARACTER_COUNT_USER' => ExternModule::ExtHtmlReady($db->f('count_user')),
                'URL_LIST_PERSONS' => $this->getLinkToModule('LinkInternListCharacters', array('initiale' => $db->f('initiale'))));
        }
        return $content;
    }
    function convert_data( $logfile_handle, $secret_password){
        
        // data conversion code:
                
        // we need enough memory
        ini_set( "memory_limit", "256M");
               
        // set URL of subroutine file
        // (needed because of PHP memory problems, if the conversion would be done in one step)
        $CONVERSION_SUBROUTINE_URL = $GLOBALS["ABSOLUTE_URI_STUDIP"] ."raumzeit_conversion_subroutine.php";
        
        // define step size (number of rows) for subroutine proccessing
        $STEP_SIZE= 300;
        
                
        // include business logic
        require_once('lib/classes/Seminar.class.php');
        require_once('lib/resources/lib/VeranstaltungResourcesAssign.class.php');

        
        
        // lets go...
        fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") Starting conversion of imported seminar dates.\n");
        
        
        // STEP 1:
        //      convert the title of dates (="content") to real themes
        //      converts all dates, that don't have content==''
        fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") Step 1: Converting the title of dates to real themes:\n");
        
        // create database connectors
        $db  = new DB_Seminar();
        $db2 = new DB_Seminar();
        
        // get all dates (=termine) with content!=''
        $db->query("SELECT termine.* FROM seminare LEFT JOIN termine ON (seminare.Seminar_id = termine.range_id) WHERE (content != '' OR description != '')");
        
        $counter = 0;
        
        // create new theme for each date
        while ($db->next_record()) {
            $counter++;
            $new_issue_id = md5(uniqid("Issue"));
                $db2->query("INSERT INTO themen_termine (issue_id, termin_id) VALUES ('$new_issue_id', '".$db->f('termin_id')."')");
                $db2->query("INSERT INTO themen (issue_id, seminar_id, author_id, title, description, mkdate, chdate) VALUES ('$new_issue_id', '".$db->f('range_id')."', '".$db->f('author_id')."', '".mysql_escape_string($db->f('content'))."', '".mysql_escape_string($db->f('description'))."', '".$db->f('mkdate')."', '".$db->f('chdate')."')");
                $db2->query("UPDATE termine SET content = '', description = '' WHERE termin_id = '".$db->f('termin_id')."'");
                $db2->query("UPDATE folder SET range_id = '$new_issue_id' WHERE range_id = '".$db->f('termin_id')."'"); 
                if($db->f('topic_id')){ 
                    $db2->query("UPDATE px_topics SET topic_id = '$new_issue_id' WHERE topic_id = '".$db->f('topic_id')."'"); 
                    $db2->query("UPDATE px_topics SET root_id = '$new_issue_id'  WHERE root_id = '".$db->f('topic_id')."'"); 
                    $db2->query("UPDATE px_topics SET parent_id = '$new_issue_id'  WHERE parent_id = '".$db->f('topic_id')."'"); 
                } 
            fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") converting termin_id='".$db->f('termin_id')."', added theme_id='".$new_issue_id."'\n");
            flush();
        }
        
        fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") Finished Step 1. Converted $counter dates.\n");
        
        // END OF STEP 1
        
        
        // STEP 2:
        //      create single dates for all regular dates (turnus_data in metadata_dates)
        fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") Step 2: Creating single dates for all regular dates:\n");
        
        // reset counter
        $counter = 0;
        
        // set number of record to start with
        $start_at = 0;
        
        do {
            // call the conversion subroutine with number of rows that should get processed           

            $subroutine_url = $CONVERSION_SUBROUTINE_URL ."?step_size=".$STEP_SIZE."&start_at=".$start_at."&secret=".$secret_password; 

// curl:
            // create cURL-Handle
            $ch = curl_init();

            // set url and other option
            curl_setopt($ch, CURLOPT_URL, $subroutine_url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

            // make the call to the url
            $response = curl_exec ($ch);

            // close cURL-Handle und gebe die Systemresourcen frei
            curl_close($ch);

// file_get_contents (fopen wrappers)
//   removed file_get_contents access, in favor of curl because file_get_contents could not access the desired URL with 
//   every data we had for testing; it was not possible to reproduce this error e.g. by calling file_get_contents 
//   directly from the shell
//            // open URL via fopen = "call" subroutine
//            $response = file_get_contents( $subroutine_url );

            // success ?
            if( $response == FALSE ){
                $this->write( get_class($this)." - Error while executing subroutine. Can't open URL. Stopping.\n");
                fwrite($logfile_handle, "Error while executing subroutine. Can't open URL '$subroutine_url'. Stopping.\n");
                throw new Exception("Error while executing subroutine.");
            }            
            

            // some not quite nice error handling:
            if( substr($response,0,5) == "ERROR" ){
                // write output to logfile
                $this->write( get_class($this)." - Error while executing subroutine. Please see logfile for details. Stopping.\n");
                fwrite( $logfile_handle, $response);
                fwrite($logfile_handle, "Error while executing subroutine. Stopping.\n");
                throw new Exception("Error while executing subroutine.". $response);
            }

            // get last line (holds the number of converted rows)
            $begin_of_last_line = strrpos( $response, "\n")+1;
            $numberOfConvertedRows = substr($response, $begin_of_last_line, strlen($response)-$begin_of_last_line);

            // check, if $numberOfConvertedRows is really a number
            if( !is_numeric($numberOfConvertedRows) ){
                $this->write( get_class($this)." - Error while executing subroutine. Please see logfile for details. Stopping.\n");
                // write output to logfile
                fwrite( $logfile_handle, $response."\n");
                fwrite($logfile_handle, "Error while executing subroutine. Invalid number of converted lines found. Stopping.\n");
                throw new Exception("Error while executing subroutine.\n ". $response);
            }

            // cutoff last line
            $response = substr($response, 0, $begin_of_last_line);
            
            // write output to logfile
            fwrite( $logfile_handle, $response);
        
            // count total amount of converted seminars
            $counter += $numberOfConvertedRows;

            // step to next record package            
            $start_at += $STEP_SIZE;
            
        } while( $numberOfConvertedRows != 0);
        
        fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") Finished Step 2. Converted $counter seminars.\n");
        
        fwrite($logfile_handle, "(". date("Y-m-d H:i:s T") .") Conversion finished.");

        $this->write( get_class($this).": Converted $counter seminars.");        
    }