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 get_highscore_list()
{
    $db = new DB_Seminar("SELECT murmeln_highscore.*,username FROM murmeln_highscore LEFT JOIN auth_user_md5 USING(user_id) ORDER BY score DESC LIMIT 20");
    $ret = '<ol>';
    $maxscore = 0;
    while ($db->next_record()) {
        $ret .= '<li><b>' . $db->f('score') . '</b> - 
				' . ($db->f('username') ? '<a href="' . UrlHelper::getLink('about.php?username='******'username')) . '">' . htmlReady(get_fullname_from_uname($db->f('username'))) . '</a>' : htmlready($db->f('name'))) . '</li>';
        $maxscore = $db->f('score');
    }
    $ret .= '</ol>';
    $db->query("DELETE FROM murmeln_highscore WHERE score < " . $maxscore);
    return $ret;
}
    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.");        
    }