mysql_query("update " . $prefix . "adcat set ads=ads+1 where id='{$in['catid']}'") or died("Database Query Error");
         mysql_query("update " . $prefix . "adsubcat set ads=ads+1,notify='1' where id='{$in['subcatid']}'") or died("Database Query Error");
         mysql_query("update " . $prefix . "userdata set ads=ads+1,lastaddate=now(),lastad={$timestamp} where id='{$in['userid']}'") or died("Database Query Error");
         $_SESSION[suserlastad] = $timestamp;
     } else {
         $textmessage = $text_msg[1];
     }
     if ($ad_notify) {
         $mailto = "{$ad_notify}";
         $from = "From: {$admin_email}";
         $subject = "NOTIFY new AD from {$in['uname']}";
         $message = "User: {$in['userid']} ({$in['uname']})\nCat: {$in['catid']} ({$in['cat']})\nSubcat: {$in['subcatid']} ({$in['subcat']})\nLocation: {$in['location']}\nHeader: {$in['header']}\n\nText: {$in['text']}";
         @mail($mailto, $subject, $message, $from);
     }
     if ($sales_option) {
         sales_countevent(2, $in[userid], $in[catid]);
     }
     logging("X", "{$_SESSION['suserid']}", "{$_SESSION['susername']}", "AD: new", "Cat: {$in['catid']} ({$in['cat']}) - Subcat: {$in['subcatid']} ({$in['subcat']}) - Header: {$in['header']}");
 }
 #  some functions at update time
 #################################################################################################
 if ($timeoutnotify > 0) {
     $sql = "select * FROM " . $prefix . "ads WHERE (TO_DAYS(addate)<TO_DAYS(now())-(durationdays+timeoutdays-'{$timeoutnotify}')) AND timeoutdays<'{$timeoutmax}' AND deleted!='1' AND publicview='1' AND timeoutnotify=''";
     $result = mysql_query($sql) or died("Database Query Error");
     while ($db = mysql_fetch_array($result)) {
         $result2 = mysql_query("SELECT * FROM " . $prefix . "userdata WHERE id={$db['userid']}") or died("Record NOT Found:" . mysql_error());
         $dbu = mysql_fetch_array($result2);
         $mdhash = md5($timestamp . $db[header] . $db[id] . $secret);
         $mailto = "{$dbu['email']}";
         $from = "From: {$admin_email}";
         $subject = "{$mail_msg['19']}";
             //WebMail or NOT ???
             mail($mail_notify, $subject_notify, stripslashes($body), "From:{$admin_email}");
         } else {
             $mail->ClearAllRecipients();
             $mail->AddAddress($mail_notify);
             $mail->From = "{$admin_email}";
             $mail->Subject = "{$subject}";
             $mail->Send();
         }
     }
     if ($webmail_notify && $webmail_enable && !$friend) {
         //WebMail AND Notify or NOT ???
         mail($toemail, $mail_msg[23], $mail_msg[24], "From:{$admin_email}");
     }
     if ($sales_option && $fromid) {
         sales_countevent(3, $fromid, $catid);
     }
     if ($adid) {
         // Stat Answered Counter
         mysql_query("update " . $prefix . "ads set answered=answered+1 where id={$adid}") or died(mysql_error());
     }
     logging("X", "{$_SESSION['suserid']}", "{$_SESSION['susername']}", "MAIL: sent", "E-Mail from {$fromname}<{$fromemail}> to {$toname}<{$toemail}>, Subject: {$subject}");
     include "{$language_dir}/sendmail_done.inc";
 } else {
     // Empty Field
     logging("X", "{$_SESSION['suserid']}", "{$_SESSION['susername']}", "MAIL: error", "E-Mail from {$fromname}<{$fromemail}> to {$toname}<{$toemail}>, Subject: {$subject}");
     include "{$language_dir}/sendmail_error.inc";
 }
 echo "<center><table><tr><td>\n";
 echo "<form action=javascript:history.back(1) METHOD=POST><input type=submit value={$back}></form>\n";
 echo "</td><td>\n";