[LON-CAPA-cvs] cvs: modules /ferrydia cse101-bot.php

felicia felicia@source.lon-capa.org
Wed, 07 Oct 2009 20:34:28 -0000


felicia		Wed Oct  7 20:34:28 2009 EDT

  Added files:                 
    /modules/ferrydia	cse101-bot.php 
  Log:
  Reza Ferrydiansyah's cse101 bot script
  
  

Index: modules/ferrydia/cse101-bot.php
+++ modules/ferrydia/cse101-bot.php
<?
    $inc_root = "var/www/test/";
    $server = "live";
    $grader_root = "/home/ferrydia/cse101server/scripts/auto_grader";
    $NOSESSION = true;
    $debug = false;
   
    require_once("/{$inc_root}lib/php/base_header.php");
    require_once("/{$inc_root}lib/php/lib_loncapa.php");
     global $lc_role;
     lc_setExpectedRole('Course Coordinator');

    // read bt level
    $level = 10;
    $trk = "";
    $reload = false;
    $fileName = "bt{$level}{$trk}.task";
    $secarray['all'] = 'all';
    $savefilename = $fileName."list";
    print "attempting to read list of users \n";

       
   
   
    $row = $mainDB->get_results("SELECT s.pid, n.msunetid, s.attempt, 
h.status, h.grader_pid, h.bt_id
FROM bt_grading_history h INNER JOIN students_grades s ON 
h.bt_id=s.bt_id INNER JOIN students n ON s.pid=n.pid
WHERE (h.grader_pid=12345678 AND h.status = 'P') OR (s.attempt=3 AND 
h.status='F' AND h.grader_pid=12345678)
ORDER BY s.pid asc, s.attempt desc
;");
  
    foreach($row as $person)
    {
        print "Getting data for person {$person->msunetid} ";
        // read the file from lon capa
        //$debug=true;
        $pagedata = getBT("bt".$level.$trk.".task", 
$person->msunetid);       
        //print_r($pagedata);
        preg_match_all("/<a 
href=\"\/adm\/msu\/([a-z0-9]+)\/aboutme\".*?<tt>([a-z]+)<\/tt>/s", 
$pagedata, $match);
        //print_r($match);
        // find the person
        $graders = $match[1];
        $lg = array_unique($graders);
        //print_r($lg);
        foreach($lg as $gd)
        {
            if ($gd!='cse101bot')
            {
                $gd=trim($gd);
                // get userid;
                // update with the first grader
                print "Changed grader to $gd bt id: {$person->bt_id}";
                //print "\nUPDATE bt_grading_history SET 
grader_pid=(SELECT pid FROM person WHERE msunetid='$gd') WHERE 
grader_pid=12345678 AND bt_id={$person->bt_id}";
                $row = $mainDB->query("UPDATE bt_grading_history SET 
grader_pid=(SELECT pid FROM person WHERE msunetid='$gd') WHERE 
grader_pid=12345678 AND bt_id={$person->bt_id}");
               
                // delete
            }
           
        }
        print "\n";
        //print "$pagedata";
        preg_match_all("/<input 
type=\"hidden\"\s*name=\"([^\"]*)\"\s*value=\"([^\"]*)\"/", $pagedata, 
$inputs);
        $i=0;
        //print_r($inputs);
        while 
($inputs[1][$i]&&($inputs[1][$i]!='symb'||$inputs[2][$i]=='none'))
        {
            $i++;
        }
        while ($inputs[1][$i])
        {
            $post[$inputs[1][$i]] = $inputs[2][$i];
            $i++;
        }
        $post['stop'] = "Cancel";
        $page = 
lc_postData("/res/msu/cse101/bridge_tasks/tasks/{$fileName}", $post);
        //print "Finished";
    //if (strpos($page, "Not allowed to grade the requested user.") !== 
FALSE) {
    if (strpos($page, "Return to resource") === FALSE) {
        print ("Unable to unlock BT.\n");
    }
    }

   
?>