#var_dump( $where ); // -------------------------- Search function end -------------------------- // // Access Management if (tkCheckTags("viewAll")) { $grant = 1; } else { if (tkCheckTags("viewOwn,viewPublic") == 2) { $where["access"] = "( author='" . $tkUser["id"] . "' OR visibility>0 )"; } else { if (tkCheckTags("viewOwn")) { $where["access"] = "( author='" . $tkUser["id"] . "' )"; } else { if (tkCheckTags("viewOwn,viewPublic")) { $where["access"] = "( visibility=1 )"; } else { tkSendError($ln_no_rights); } } } } // Set up where string $whereStr = tkWhereArrayToStr($where); // Request the list of Threads $thread->requestList($whereStr, $limit, "lastchange", "DESC", $addTables); // How many unread threads for the logged in user? $newThreadNum = $thread->numListElements; #$newThreadNum = $thread->countNotifies( $where, $addTables ); #echo "num".$newThreadNum; // EXIT POINT if the Host script just wanted to know, how many unread tickets we hav if (tkREMOTE != "fetchNewThreadNum") { $rowsHtml = "";
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); } }
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; }