Example #1
0
 function handleField($fieldName, $fieldVal)
 {
     global $ln_no_checkout;
     switch ($fieldName) {
         case "author":
             $user = tkCbGetUserById($fieldVal);
             if ($user && is_array($user)) {
                 return $user["name"];
             } else {
                 tkLog("Unkown User, User id: " . $fieldVal);
                 return "";
             }
             break;
         case "build":
             return intelliDate($fieldVal);
             break;
         case "text":
             $text = $fieldVal;
             #        $text = wordwrap( $text, 150, "<br />" );
             #        $text = str_replace( "\n", "<br />", $text );
             //         onClick=\"return window.confirm('Bist du sicher, dass du den externen Link $1$2$3 öffnen willst?')\"
             // Important for the mail function
             $text = str_replace('\\r\\n', "\r\n", $text);
             $text = stripslashes($text);
             global $textile;
             $text = htmlspecialchars($text);
             // Extract all [code] lines an check them on beginning whitespaces
             preg_match_all("/\\[code\\]([\\s\\S]*)\\[\\/code\\]/U", $text, $subpatterns);
             #var_dump ($subpatterns ); exit;
             $codeReps = array();
             $cI = 0;
             // For every [code][/code] element in the post
             foreach ($subpatterns[1] as $num => $inner) {
                 $lines = explode("\n", $inner);
                 foreach ($lines as $key => $line) {
                     if (substr($line, 0, 1) != " ") {
                         $lines[$key] = " " . $line;
                     }
                 }
                 $code = implode("\n", $lines);
                 $text = preg_replace("/\\[code\\]([\\s\\S]*)\\[\\/code\\]/U", "[codework" . $cI . "]", $text, 1);
                 $codeReps[$cI++] = $code;
                 #var_dump( $lines );
             }
             #exit;
             $text = $textile->TextileThis($text);
             $text = preg_replace("#(http://)(www\\.)?([\\w\\./\\-\\?\\/%=&;\\+:\\#]+)#", "<a target=\"_blank\" href=\"\$1\$2\$3\">\$1\$2\$3</a>", $text);
             // Special replacements
             #$replace = Array( "[codework]" => "<pre><code>", "[/codework]" => "</code></pre>" );
             foreach ($codeReps as $key => $code) {
                 $text = str_replace("[codework" . $key . "]", "<pre><code>" . $code . "</code></pre>", $text);
             }
             #$replace = Array( "[codework]" => "<pre><code>" );
             #$text = str_replace( array_keys( $replace ), $replace, $text );
             return $text;
         default:
             return $fieldVal;
             break;
     }
 }
Example #2
0
function tkSendError($errorMsg)
{
    global $ln_error_heading, $ln_to_mainpage;
    tkLog($errorMsg);
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title>' . $ln_error_heading . '</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  </head>
  <body>
    <h4>' . $ln_error_heading . '</h4>
    ' . $errorMsg . '
    <br />
    <br />
    <a href="' . tkMakeURL("", "_all") . '">' . $ln_to_mainpage . '</a>
  </body>
</html>';
    exit;
}
Example #3
0
 function writeParams()
 {
     if ($this->real) {
         // Update
         // Kick all static fields
         $update = array();
         foreach ($this->dataRaw as $name => $val) {
             if (!in_array($name, $this->confStaticFields)) {
                 $update[$name] = $val;
             }
         }
         // Create the update string
         $updateStr = "";
         $spacer = ", ";
         foreach ($update as $name => $val) {
             if (end(array_keys($update)) == $name) {
                 $spacer = "";
             }
             $updateStr .= "`" . $name . "` = '" . $update[$name] . "'" . $spacer;
         }
         $sql = "\n      UPDATE\n        " . PRFX . $this->table . "\n      SET\n        " . $updateStr . "\n      WHERE\n        id='" . $this->dataRaw["id"] . "'\n        ;";
     } else {
         // Insert
         $fieldStr = "( ";
         $valStr = "( ";
         $spacer = ", ";
         foreach ($this->confFields as $field) {
             if (end($this->confFields) == $field) {
                 $spacer = "";
             }
             $fieldStr .= "`" . $field . "`" . $spacer;
             $valStr .= "'" . $this->dataRaw[$field] . "'" . $spacer;
         }
         $fieldStr .= " )";
         $valStr .= " )";
         $sql = "\n      INSERT INTO\n        " . PRFX . $this->table . "\n        " . $fieldStr . "\n      VALUES\n        " . $valStr . "\n        ;";
     }
     #die( $sql );
     // Make the Query
     $res = $this->query($sql);
     if ($res) {
         // We need a id to work in both cases, update and insert
         if (!$this->real) {
             $this->dataRaw["id"] = mysql_insert_id();
         }
         return TRUE;
     } else {
         tkLog("MySQL Error @ setting Parrams for element: {$sql} , " . mysql_error());
         tkSendError($ln_db_update_error);
     }
 }
Example #4
0
 function sendNotify($cause, $type)
 {
     global $tmpl, $tkConfBotMail, $tkConfSysName, $ln_eNotify_titles, $tkUser;
     // Get all users who need to be identified
     $users = array();
     // First option - all users who subscribed to the current thread
     /*if( $type == "_subscribers" )#$this->checkFrontidExistance( $type ) )
       {
         // Get the ids of the users who described to this thread
         $sql = "
         SELECT
           id, userid, email_last_notify
         FROM
          ".PRFX."threads_marks
         WHERE
           threadid='".$this->dataRaw["id"]."' AND
           email_notification LIKE '%".$cause."%'
         ;";
         
         
         
         $res = $this->query( $sql );
       
         while( $row = $this->assoc( $res ) )
         {
           // don't spam the users
           if( time() > $row["email_last_notify"] + 60 * 60 * 24 * 7 ) // maximum is: once a week
             $users[] = $row["userid"];
         }
         
       }
       
       // Second Option - all users, who want to be notified when there is a new thread
       else if( $type == "_new" )
       {
         global $confEmailNotifyUsers;
         
         $users = $confEmailNotifyUsers;
       }*/
     // add the Global Subscription Users
     #$users = Array();
     // We are just notifying users who want it.
     $users = globGetUsers();
     #foreach ( $globUser as $userid )
     #{
     # if( !in_array( $userid, $users ) )
     #   $users[] = $userid;
     #}
     // Give the users for debug reasons
     #var_dump( $users );
     /*foreach( $users as $userid )
       {
         echo "-------------<br />";
         $user = tkCbGetUserById( $userid );
         echo $user["name"];
         echo " -".$user["email"]."-<br />";
       
       }
       exit;*/
     // Now it's time to notify the users
     foreach ($users as $userid) {
         // get the details for each user
         $user = tkCbGetUserById($userid);
         // check the users mail
         if (!validateMail($user["email"])) {
             tkLog("bad mail for user \"" . $user["name"] . "\": " . $user["email"]);
             continue;
         }
         // Is the user even allowed to view this thread?
         if (tkCheckTags("viewAll", $userid) || tkCheckTags("viewOwn", $userid) && $this->dataRaw["author"] == $userid) {
             $access = true;
         } else {
             continue;
         }
         // only send the mail, if the user checked the rhead since last mail
         //   (meaning, if the email_last_notify column in threads_marks != 0, then no mail)
         $marks = $this->getMarks($user["id"]);
         if ($marks["email_last_notify"] > 0) {
             continue;
         }
         #marker3
         // send a notification mail
         switch ($cause) {
             case "onComment":
                 $eTmpl = $tmpl["email:newComment"];
                 #$content = $this->posts["create"]->handleField( "text", $this->posts["create"]->dataRaw["text"] );
                 $content = $this->posts["create"]->dataRaw["text"];
                 $author = $this->posts["create"]->handleField("author", $this->posts["create"]->dataRaw["author"]);
                 break;
             case "onStatusChange":
                 $eTmpl = $tmpl["email:statusChange"];
                 break;
             case "onNew":
                 $eTmpl = $tmpl["email:newThread"];
                 $content = $this->posts["create"]->dataRaw["text"];
                 $author = $this->handleField("author", $this->dataRaw["author"]);
                 break;
             default:
                 tkSendError("System Error: unkown notify status");
                 break;
         }
         $htmlContent = $this->posts["create"]->handleField("text", $content);
         $lastCheckOnThread = $this->getLastCheck($tkUser["id"], $dataRaw["id"]);
         $unreadPosts = 0;
         $allPosts = 0;
         // First unread post
         foreach ($this->posts as $post) {
             if ($post->dataRaw["build"] > $lastCheckOnThread) {
                 if (!isset($firstUnreadPost)) {
                     $firstUnreadPost = $post->dataRaw["id"];
                 }
                 $unreadPosts++;
             }
             $allPosts++;
         }
         $subjval = $this->handleField("subject", $this->dataRaw["subject"]);
         $subject = $ln_eNotify_titles[$cause] . ': \'' . $subjval . '\'';
         global $tkConfPath;
         // No Br in Mails
         #$text = $content;
         #$text = str_replace( "\n", "<br />", $text );
         #$text = stripslashes( $text );
         #$content = $text;
         $params = array("username" => $user["name"], "author" => $author, "subject" => $subjval, "status" => $this->dataRaw["status"], "content" => $htmlContent, "link" => $tkConfPath . "index.php?id=" . $this->dataRaw["frontid"] . "&p=" . $firstUnreadPost . "#comment" . $firstUnreadPost, "frontid" => $this->dataRaw["frontid"]);
         #$message = $tkConfNotMailTmpl;
         $message = tkMakeHtml($eTmpl, $params);
         /*$headers = 'From: KG-Ticket-Notify <'.$tkConfBotMail . ">\r\n" .
               'Reply-To: KG-Ticket-Notify <'.$tkConfBotMail . ">\r\n" . 
               "MIME-Version: 1.0" . "\r\n";
               "Content-type: text/html; charset=ISO-8859-1" ;
               "\n\n" ;
           
           $trans_table = array (
             'ä' => 'ae',
             'ö' => 'oe',
             'ü' => 'ue',
             'Ä' => 'Ae',
             'Ö' => 'Oe',
             'Ü' => 'Ue'
           );
           $subject = str_replace( array_keys( $trans_table), $trans_table, $subject );*/
         // don't notify the user himself
         if ($user["id"] != $tkUser["id"]) {
             // Send the notification mail
             #die( $htmlContent );
             mailLog($user["email"], $user["name"], $subject, $message, $headers);
             #echo $user["name"];
             #$x = mail( $to, $subject, $message, $headers );
             #sendMail( $subject, $message, $user["email"], $user["name"], "Dies ist eine HTML-Email...man kann sie nur mit einem HTML-Email-View ansehen..." );
             #die( "stop" );
             #echo "sendmail";
             /*echo "<pre>"."Send Mail
             To: $to; 
             Subject: $subject; 
             Message: $message"."</pre>";*/
             #exit;
         }
         // prevent spam ( also at creation of ticket )
         $sql = "\n      UPDATE \n        " . PRFX . "threads_marks\n      SET\n        email_last_notify='" . time() . "'\n      WHERE\n        threadid='" . $this->dataRaw["id"] . "' AND\n        userid='" . $user["id"] . "'\n    ;";
         $this->query($sql);
     }
     // Send all Mails in the background
     #> /dev/null &
     system("php includes/sendmails.php > includes/maillog &", $ret);
     // attention, works only with Linux!
     #echo $ret;
     #die("stop");
     return 0;
     #exit;
 }