$strQuery = "SELECT MAX(nID) FROM cf_circulationhistory";
 $nResult = mysql_query($strQuery, $nConnection);
 if ($nResult) {
     if (mysql_num_rows($nResult) > 0) {
         $arrRow = mysql_fetch_array($nResult);
         $nCirculationHistoryID = $arrRow[0];
     }
 }
 // - - - - - - - - - - - - START RESTART OPTIONS - - - - - - - - - - - -
 if ($_REQUEST['MailingList'][0] != 0) {
     // User has decided to start the circulation from a chosen Station - and not from beginning
     $arrSplit = split('---', $_REQUEST['MailingList']);
     $nChoosenSlotId = $arrSplit[1];
     $nChoosenUserId = $arrSplit[2];
     $nChoosenPosition = $arrSplit[3];
     $arrSender = $objCirculation->getSenderDetails($nCirculationFormID);
     $arrMailinglist = $objCirculation->getMailinglist($nMailinglistID);
     $nFormTemplateID = $arrMailinglist['nTemplateId'];
     $arrUsers = $objCirculation->getUsers();
     $arrSlots = $objCirculation->getFormslots($nFormTemplateID);
     $tsNow = time();
     $tsDelayed = mktime(date("H") - 2, date("i"), date("s"), date("m"), date("d"), date("Y"));
     $nMax = sizeof($arrSlots);
     for ($nIndex = 0; $nIndex < $nMax; $nIndex++) {
         $arrSlot = $arrSlots[$nIndex];
         $nSlotID = $arrSlot['nID'];
         $strSlot = $arrSlot['strName'];
         $strQuery = "SELECT * FROM cf_slottouser WHERE nMailingListId = '{$nMailinglistID}' AND nSlotId = '{$nSlotID}' ORDER BY nPosition ASC";
         $nResult = mysql_query($strQuery, $nConnection);
         if ($nResult) {
             if (mysql_num_rows($nResult) > 0) {
                     $SP_MINUTES = $SP_VALUE * 24 * 60;
                     break;
                 case 'HOURS':
                     $SP_MINUTES = $SP_VALUE * 60;
                     break;
                 case 'MINUTES':
                     $SP_MINUTES = $SP_VALUE;
                     break;
             }
             $tsCurrentSendSP = mktime(date("H"), date("i") - $SP_MINUTES, date("s"), date("m"), date("d"), date("Y"));
         }
         if ($dateInProcessSince < $tsCurrentSendSP) {
             $nSubstituteId = $arrSubstitutes[0]['substitute_id'];
             if ($nSubstituteId == -3) {
                 // in this case the substitute is the sender of the circulation - let's find his user_id
                 $arrSenderDetails = $objCirculation->getSenderDetails($nCirculationFormId);
                 $nSubstituteId = $arrSenderDetails['nID'];
             }
             //--- change decission state
             $strQuery = "UPDATE cf_circulationprocess SET nDecissionState = '8', dateDecission = '{$TStoday}' WHERE nID = '{$nCirculationProcessId}'";
             mysql_query($strQuery, $nConnection);
             //--- send substitute mail
             sendToUser($nSubstituteId, $nCirculationFormId, $nSlotId, $nCirculationProcessId, $nCirculationHistoryId);
         }
     }
 } else {
     // user is a substitute
     // let's see who this substitute belongs to
     // it's NOT saved in "nIsSubstituteOf" -.-
     $strQuery = "SELECT MAX(dateInProcessSince) as nMaxDateInProcessSince FROM cf_circulationprocess WHERE nCirculationFormId = '{$nCirculationFormId}' AND nIsSubstitiuteOf = '0' AND dateInProcessSince < '{$TSsendSP}' LIMIT 1;";
     $result = mysql_query($strQuery, $nConnection);