Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 7907)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 7908)
@@ -236,4 +236,93 @@
 }
 
-
-
+function getdbsetup()
+{
+   db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
+   pw=`grep Password $mars/sql.rc | grep -v '#' | sed -e 's/Password: //' -e 's/ //g'`
+   us=`grep User $mars/sql.rc | grep -v '#' | sed -e 's/User: //' -e 's/ //g'`
+#   echo "setup: "
+#   echo " db: "$db
+#   echo " pw: "$pw
+#   echo " us: "$us
+}
+
+function getstepinfo()
+{
+   if [ "$singleprocess" = "yes" ]
+   then 
+      column=${scriptscolname[$i]}
+   fi
+   table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'`
+   coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
+   needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
+   influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
+   primary=`grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"`
+#   echo " column $column - table $table - coltab $coltab"
+#   echo " needs: $needs"
+#   echo " influences: $influences"
+#   echo " primary: $primary"
+}
+
+function contex()
+{
+   echo ""
+   if [ "$singleprocess" = "yes" ]
+   then 
+      continue
+   else
+      exit
+   fi
+}
+
+function gettodo()
+{
+   echo "getting todo..."
+   getdbsetup 
+   getstepinfo
+   # get query
+   query=" select $primary from $table where "
+   if ! echo $needs | grep '#' > /dev/null 
+   then 
+      for need in $needs
+      do
+         query=$query" not isnull($need) and"
+      done
+   fi
+   if ! echo $influences | grep '#' > /dev/null 
+   then 
+      for influence in $influences
+      do 
+         query=$query" isnull($influence) and"
+      done
+   fi
+   query=$query" isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) order by $primary desc "
+   if [ "$singleprocess" = "yes" ]
+   then 
+      query=$query" limit 0, 1 "
+   fi
+#   echo " QUERY: "$query
+   process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
+
+   if [ "$process" = "" ]
+   then
+      echo "  => nothing to do" 
+      contex 
+   else 
+      if [ "$singleprocess" = "yes" ]
+      then 
+         listfile=$listpath/ToDo-$table-$column-$process.txt
+         echo "  => found $process"
+      else
+         listfile=$listpath/ToDo-$table-$column.txt
+         echo "found processes"
+      fi
+#      echo " list: "$listfile
+      
+      if ls $listfile > /dev/null 2>&1
+      then
+         echo "$listfile exists already"
+         contex 
+      fi
+      echo $process > $listfile
+   fi
+}
