コード例 #1
0
function getGoodDistanceNew(SmrSector &$sector, $goodID, $transaction)
{
    global $var, $container;
    // check if we already did this
    if (isset($var['good_distance'])) {
        // transfer this value
        transfer('good_distance');
        // return this value
        return $var['good_distance'];
    }
    $x = Globals::getGood($goodID);
    switch ($transaction) {
        case 'Buy':
            $x['TransactionType'] = 'Sell';
            break;
        case 'Sell':
            $x['TransactionType'] = 'Buy';
    }
    $di = Plotter::findDistanceToX($x, $sector, true);
    if (is_object($di)) {
        $di = $di->getRelativeDistance();
    }
    $container['good_distance'] = $di;
    return $di;
}
コード例 #2
0
ファイル: oldStats.php プロジェクト: nikosv/openeclass
    $date_start->sub(new DateInterval('P1M'));
    $u_date_end = $date_end->format('Y-m-d H:i');
    $user_date_end = $date_end->format('d-m-Y H:i');        
}

$date_fmt = '%Y-%m-%d';
$date_where = " (start_date BETWEEN '$u_date_start' AND '$u_date_end') ";
$query = "SELECT MONTH(start_date) AS month, YEAR(start_date) AS year, SUM(login_sum) AS visits
                        FROM loginout_summary
                        WHERE $date_where
                        GROUP BY MONTH(start_date)";

$result = Database::get()->queryArray($query);

if (count($result) > 0) {
    $chart = new Plotter();
    $chart->setTitle($langOldStats);

    //add points to chart
    foreach ($result as $row) {
        $mont = $langMonths[$row->month];
        $chart->growWithPoint($mont . " - " . $row->year, $row->visits);
    }
    $tool_content .= "<p>" . $langVisits . "</p>" . $chart->plot();
} else {
    $tool_content .= "<div class='alert alert-warning'>$langNoStatistics</div>";
}

$tool_content .= '<div class="form-wrapper"><form class="form-horizontal" role="form" method="post">';
$tool_content .= "<div class='input-append date form-group' id='user_date_start' data-date = '" . q($user_date_start) . "' data-date-format='dd-mm-yyyy'>
    <label class='col-sm-2 control-label'>$langStartDate:</label>
コード例 #3
0
ファイル: index.php プロジェクト: kostastzo/openeclass
function show_assignment($id, $display_graph_results = false)
{
    global $tool_content, $m, $langBack, $langNoSubmissions, $langSubmissions, $langEndDeadline, $langWEndDeadline, $langNEndDeadline, $langDays, $langDaysLeft, $langGradeOk, $course_code, $webDir, $urlServer, $langGraphResults, $m, $course_code, $themeimg, $works_url, $course_id, $langDelWarnUserAssignment, $langAutoJudgeShowWorkResultRpt;
    $row = Database::get()->querySingle("SELECT *, CAST(UNIX_TIMESTAMP(deadline)-UNIX_TIMESTAMP(NOW()) AS SIGNED) AS time\n                                FROM assignment\n                                WHERE course_id = ?d AND id = ?d", $course_id, $id);
    $nav[] = $works_url;
    assignment_details($id, $row);
    $rev = @($_REQUEST['rev'] == 1) ? ' DESC' : '';
    if (isset($_REQUEST['sort'])) {
        if ($_REQUEST['sort'] == 'am') {
            $order = 'am';
        } elseif ($_REQUEST['sort'] == 'date') {
            $order = 'submission_date';
        } elseif ($_REQUEST['sort'] == 'grade') {
            $order = 'grade';
        } elseif ($_REQUEST['sort'] == 'filename') {
            $order = 'file_name';
        } else {
            $order = 'surname';
        }
    } else {
        $order = 'surname';
    }
    $result = Database::get()->queryArray("SELECT * FROM assignment_submit AS assign, user\n                                 WHERE assign.assignment_id = ?d AND user.id = assign.uid\n                                 ORDER BY ?s ?s", $id, $order, $rev);
    $num_results = count($result);
    if ($num_results > 0) {
        if ($num_results == 1) {
            $num_of_submissions = $m['one_submission'];
        } else {
            $num_of_submissions = sprintf("{$m['more_submissions']}", $num_results);
        }
        $gradeOccurances = array();
        // Named array to hold grade occurances/stats
        $gradesExists = 0;
        foreach ($result as $row) {
            $theGrade = $row->grade;
            if ($theGrade) {
                $gradesExists = 1;
                if (!isset($gradeOccurances[$theGrade])) {
                    $gradeOccurances[$theGrade] = 1;
                } else {
                    if ($gradesExists) {
                        ++$gradeOccurances[$theGrade];
                    }
                }
            }
        }
        if (!$display_graph_results) {
            $result = Database::get()->queryArray("SELECT assign.id id, assign.file_name file_name,\n                                                   assign.uid uid, assign.group_id group_id,\n                                                   assign.submission_date submission_date,\n                                                   assign.grade_submission_date grade_submission_date,\n                                                   assign.grade grade, assign.comments comments,\n                                                   assign.grade_comments grade_comments,\n                                                   assignment.deadline deadline\n                                                   FROM assignment_submit AS assign, user, assignment\n                                                   WHERE assign.assignment_id = ?d AND assign.assignment_id = assignment.id AND user.id = assign.uid\n                                                   ORDER BY ?s ?s", $id, $order, $rev);
            $tool_content .= "\n                        <form action='{$_SERVER['SCRIPT_NAME']}?course={$course_code}' method='post'>\n                        <input type='hidden' name='grades_id' value='{$id}' />\n                        <p><div class='sub_title1'>{$langSubmissions}:</div><p>\n                        <p>{$num_of_submissions}</p>\n                        <table width='100%' class='sortable'>\n                        <tr>\n                      <th width='3'>&nbsp;</th>";
            sort_link($m['username'], 'username');
            sort_link($m['am'], 'am');
            sort_link($m['filename'], 'filename');
            sort_link($m['sub_date'], 'date');
            sort_link($m['grade'], 'grade');
            $tool_content .= "</tr>";
            $i = 1;
            foreach ($result as $row) {
                //is it a group assignment?
                if (!empty($row->group_id)) {
                    $subContentGroup = "{$m['groupsubmit']} " . "<a href='../group/group_space.php?course={$course_code}&amp;group_id={$row->group_id}'>" . "{$m['ofgroup']} " . gid_to_name($row->group_id) . "</a>";
                } else {
                    $subContentGroup = '';
                }
                $uid_2_name = display_user($row->uid);
                $stud_am = Database::get()->querySingle("SELECT am FROM user WHERE id = ?d", $row->uid)->am;
                if ($i % 2 == 1) {
                    $row_color = "class='even'";
                } else {
                    $row_color = "class='odd'";
                }
                $filelink = empty($row->file_name) ? '&nbsp;' : "<a href='{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;get={$row->id}'>" . q($row->file_name) . "</a>";
                $late_sub_text = (int) $row->deadline && $row->submission_date > $row->deadline ? '<div style="color:red;">$m[late_submission]</div>' : '';
                $tool_content .= "\n                                <tr {$row_color}>\n                                <td align='right' width='4' rowspan='2' valign='top'>{$i}.</td>\n                                <td>{$uid_2_name}</td>\n                                <td width='85'>" . q($stud_am) . "</td>\n                                <td width='180'>{$filelink}\n                                <a href='{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;id={$id}&amp;as_id={$row->id}' onClick='return confirmation(\"{$langDelWarnUserAssignment}\");'>\n                                 <img src='{$themeimg}/delete.png' title='{$m['WorkDelete']}' />\n                                </a>\n                                </td>\n                                <td width='100'>" . nice_format($row->submission_date, TRUE) . $late_sub_text . "</td>\n                                <td width='5'>\n                                <div align='center'><input type='text' value='{$row->grade}' maxlength='3' size='3' name='grades[{$row->id}]'></div>\n                                </td>\n                                </tr>\n                                <tr {$row_color}>\n                                <td colspan='5'>\n                                <div>{$subContentGroup}</div>";
                if (trim($row->comments != '')) {
                    $tool_content .= "<div style='margin-top: .5em;'><b>{$m['comments']}:</b> " . q($row->comments) . '</div>';
                }
                //professor comments
                $gradelink = "grade_edit.php?course={$course_code}&amp;assignment={$id}&amp;submission={$row->id}";
                $reportlink = "work_result_rpt.php?course={$course_code}&amp;assignment={$id}&amp;submission={$row->id}";
                if (trim($row->grade_comments)) {
                    $label = $m['gradecomments'] . ':';
                    $icon = 'edit.png';
                    $comments = "<div class='smaller'>" . standard_text_escape($row->grade_comments) . "</div>";
                } else {
                    $label = $m['addgradecomments'];
                    $icon = 'add.png';
                    $comments = '';
                }
                if ($row->grade_comments || $row->grade != '') {
                    $comments .= "<div class='smaller'><i>({$m['grade_comment_date']}: " . nice_format($row->grade_submission_date) . ")</i></div>";
                }
                $tool_content .= "<div style='padding-top: .5em;'><a href='{$gradelink}'><b>{$label}</b></a>\n\t\t\t\t  <a href='{$gradelink}'><img src='{$themeimg}/{$icon}'></a>\n\t\t\t\t  {$comments}\n\t\t\t\t  <a href='{$reportlink}'><b>{$langAutoJudgeShowWorkResultRpt}</b></a>\n                                </td>\n                                </tr>";
                $i++;
            }
            //END of Foreach
            $tool_content .= "</table>\n                        <p class='smaller right'><img src='{$themeimg}/email.png' alt='' >\n                                {$m['email_users']}: <input type='checkbox' value='1' name='email'></p>\n                        <p><input class='btn btn-primary' type='submit' name='submit_grades' value='{$langGradeOk}'></p>\n                        </form>";
        } else {
            // display pie chart with grades results
            if ($gradesExists) {
                // Used to display grades distribution chart
                $graded_submissions_count = Database::get()->querySingle("SELECT COUNT(*) AS count FROM assignment_submit AS assign, user\n                                                             WHERE assign.assignment_id = ?d AND user.id = assign.uid AND\n                                                             assign.grade <> ''", $id)->count;
                $chart = new Plotter();
                $chart->setTitle("{$langGraphResults}");
                foreach ($gradeOccurances as $gradeValue => $gradeOccurance) {
                    $percentage = round(100.0 * $gradeOccurance / $graded_submissions_count, 2);
                    $chart->growWithPoint("{$gradeValue} ({$percentage}%)", $percentage);
                }
                $tool_content .= $chart->plot();
            }
        }
    } else {
        $tool_content .= "\n                      <p class='sub_title1'>{$langSubmissions}:</p>\n                      <div class='alert alert-warning'>{$langNoSubmissions}</div>";
    }
}
コード例 #4
0
if ($player->getTurns() < 1) {
    create_error('You do not have enough turns to dump cargo!');
}
//lets make sure there is actually that much on the ship
if ($amount > $ship->getCargo($good_id)) {
    create_error('You can\'t dump more than you have.');
}
$sector =& $player->getSector();
if ($sector->offersFederalProtection()) {
    create_error('You can\'t dump cargo in a Federal Sector!');
}
require_once 'shop_goods.inc';
// get the distance
$x = Globals::getGood($good_id);
$x['TransactionType'] = 'Sell';
$good_distance = Plotter::findDistanceToX($x, $sector, true);
if (is_object($good_distance)) {
    $good_distance = $good_distance->getRelativeDistance();
}
$good_distance = max(1, $good_distance);
$lost_xp = round(SmrPort::getBaseExperience($amount, $good_distance));
$player->decreaseExperience($lost_xp);
$player->increaseHOF($lost_xp, array('Trade', 'Experience', 'Jettisoned'), HOF_PUBLIC);
// take turn
$player->takeTurns(1, 1);
$ship->decreaseCargo($good_id, $amount);
$player->increaseHOF($amount, array('Trade', 'Goods', 'Jettisoned'), HOF_PUBLIC);
// log action
$account->log(LOG_TYPE_TRADING, 'Dumps ' . $amount . ' of ' . $good_name . ' and looses ' . $lost_xp . ' experience', $player->getSectorID());
$container = array();
$container['url'] = 'skeleton.php';
コード例 #5
0
    if (!isset($_REQUEST['xtype']) || !isset($_REQUEST['X'])) {
        create_error('You have to select what you would like to find.');
    }
    $xType = $_REQUEST['xtype'];
    $X = $_REQUEST['X'];
    $realX = Plotter::getX($xType, $X, $player->getGameID());
    if ($realX === false) {
        create_error('Invalid search.');
    }
    $account->log(LOG_TYPE_MOVEMENT, 'Player plots to nearest ' . $xType . ': ' . $X . '.', $player->getSectorID());
}
$container = create_container('skeleton.php', 'course_plot_result.php');
$sector =& $player->getSector();
if ($sector->hasX($realX, $player)) {
    create_error('Current sector has what you\'re looking for!');
}
$path =& Plotter::findDistanceToX($realX, $sector, true, $player, $player);
if ($path === false) {
    create_error('Unable to find what you\'re looking for, it either hasn\'t been added to this game or you haven\'t explored it yet.');
}
if ($path->getEndSectorID() < $sector->getSectorID()) {
    //If sector we find is a lower sector id we replot so we always use the plot from lowest to highest sector.
    $path =& Plotter::findDistanceToX($sector, $path->getEndSector(), true);
    $path->reversePath();
}
$container['Distance'] = serialize($path);
$path->removeStart();
if ($sector->isLinked($path->getNextOnPath()) && $path->getTotalSectors() > 0) {
    $player->setPlottedCourse($path);
}
forward($container);
コード例 #6
0
ファイル: results.php プロジェクト: nikosv/openeclass
        $date_what .= " DATE_FORMAT(`day` - INTERVAL WEEKDAY(`day`) DAY, '$date_fmt') AS week_start " .
                ", DATE_FORMAT(`day` + INTERVAL (6 - WEEKDAY(`day`)) DAY, '$date_fmt') AS week_end, ";
        $date_group = " GROUP BY WEEK(`day`) ";
        break;
    case "monthly":
        $date_what .= " MONTH(`day`) AS `month`, ";
        $date_group = " GROUP BY MONTH(`day`) ";
        break;
    case "yearly":
        $date_what .= " YEAR(`day`) AS `year`, ";
        $date_group = " GROUP BY YEAR(`day`) ";
        break;
}


$chart = new Plotter(300, 300);

switch ($u_stats_value) {
    case "visits":        
        $result = Database::get()->queryArray("SELECT  $date_what SUM(hits) AS cnt FROM actions_daily
                                            WHERE $date_where
                                            AND $mod_where
                                            AND course_id = ?d
                                           $date_group ORDER BY `day` ASC", $course_id);

        switch ($u_interval) {
            case "summary":
                foreach ($result as $row) {
                    $chart->growWithPoint($langSummary, $row->cnt);
                }
                break;
コード例 #7
0
foreach ($galaxies as &$galaxy) {
    if ($galaxy->contains($start)) {
        $startExists = true;
    }
    if ($galaxy->contains($target)) {
        $targetExists = true;
    }
}
unset($galaxy);
if ($startExists === false || $targetExists === false) {
    create_error('The sectors have to exist!');
}
$account->log(LOG_TYPE_MOVEMENT, 'Player plots to ' . $target . '.', $player->getSectorID());
$container = array();
$container['url'] = 'skeleton.php';
$container['body'] = 'course_plot_result.php';
require_once get_file_loc('Plotter.class.inc');
$path =& Plotter::findDistanceToX(SmrSector::getSector($player->getGameID(), max($target, $start)), SmrSector::getSector($player->getGameID(), min($target, $start)), true);
if ($path === false) {
    create_error('Unable to plot from ' . $start . ' to ' . $target . '.');
}
if ($start > $target) {
    //We always plot lowest to highest, so reverse if need be.
    $path->reversePath();
}
$container['Distance'] = serialize($path);
$path->removeStart();
if ($sector->isLinked($path->getNextOnPath()) && $path->getTotalSectors() > 0) {
    $player->setPlottedCourse($path);
}
forward($container);
コード例 #8
0
    }

    $chart = new Plotter();
    $chart->setTitle($langVisits);
    //add points to chart
    while ($newp = current($point)) {
        $chart->growWithPoint(key($point), $newp);
        next($point);
    }
} else {    //show chart for a specific course
    $cid = course_code_to_id($u_course_id);

    $result = Database::get()->queryArray("SELECT " . $date_what . " SUM(hits) AS cnt FROM actions_daily
                WHERE course_id = $cid AND $date_where $date_group ORDER BY day ASC");

    $chart = new Plotter();
    $chart->setTitle($langVisits);

    switch ($u_interval) {
        case "summary":
            foreach ($result as $$row) {
                $chart->growWithPoint($langSummary, $row->cnt);
            }
            break;
        case "daily":
            foreach ($result as $$row) {
                $chart->growWithPoint($row->date, $row->cnt);
            }
            break;
        case "weekly":
            foreach ($result as $$row) {
コード例 #9
0
    foreach ($result as $row) {
        $course_codes[] = $row->code;
        $course_names[$row->code] = $row->title;
    }
    foreach ($course_codes as $code) {
        $cid = course_code_to_id($code);
        $row = Database::get()->querySingle("SELECT SUM(hits) AS cnt FROM actions_daily\n                                WHERE user_id = ?d\n                                AND course_id =?d", $uid, $cid);
        if ($row) {
            $totalHits += $row->cnt;
            $hits[$code] = $row->cnt;
        }
        $result = Database::get()->querySingle("SELECT SUM(duration) AS duration FROM actions_daily\n                                        WHERE user_id = ?d\n                                        AND course_id = ?d", $uid, $cid);
        $duration[$code] = $result->duration;
        $totalDuration += $duration[$code];
    }
    $chart = new Plotter(600, 300);
    $chart->setTitle($langCourseVisits);
    foreach ($hits as $code => $count) {
        if ($count > 0) {
            $chart->addPoint($course_names[$code], $count);
            $chart->modDimension(7, 0);
        }
    }
    $tool_content .= $chart->plot();
    $totalDuration = format_time_duration(0 + $totalDuration);
    $tool_content .= "<fieldset>\n                <legend>{$langPlatformGenStats}</legend>\n                <table class='table-default'>\n                <tr>\n                <th>{$langTotalVisitsCourses}:</th>\n                <td>{$totalHits}</td>\n                </tr>\n                <tr>\n                <th>{$langDurationVisits}:</th>\n                <td>{$totalDuration}</td>\n                </tr>\n                <tr>\n                <th valign='top'>{$langDurationVisitsPerCourse}:</th>\n                <td>\n                <table class='table-default' width='550'>\n                <tr>\n                <th>{$langCourseTitle}</th>                   \n                <th width='160'>{$langDuration}</th>\n                </tr>";
    foreach ($duration as $code => $time) {
        $tool_content .= "                \n                <td>" . q(course_code_to_title($code)) . "</td>\n                <td width='140'>" . format_time_duration(0 + $time) . "</td>\n                </tr>";
    }
    $tool_content .= "</table></td></tr>";
}
コード例 #10
0
ファイル: oldStats.php プロジェクト: nikosv/openeclass
    } else {
        $$key = $_POST[$key];
    }
}

$date_fmt = '%Y-%m-%d';
$date_where = " (start_date BETWEEN '$u_date_start 00:00:00' AND '$u_date_end 23:59:59') ";


if ($u_module_id != -1) {
    $mod_where = " (module_id = '$u_module_id') ";
} else {
    $mod_where = " (1) ";
}

$chart = new Plotter(600, 300);
$chart->setTitle("$langOldStats");
switch ($u_stats_value) {
    case "visits":
        $result = Database::get()->queryArray("SELECT module_id, MONTH(start_date) AS month,
                        YEAR(start_date) AS year,
                        SUM(visits) AS visits
                        FROM actions_summary
                        WHERE $date_where
                        AND $mod_where
                        AND course_id = ?d
                        GROUP BY MONTH(start_date)", $course_id);

        foreach ($result as $row) {
            $mont = $langMonths[$row->month];
            $chart->growWithPoint($mont . " - " . $row->year, $row->visits);
コード例 #11
0
function getPlotDistanceNew(SmrSector &$sector, SmrSector &$target)
{
    $path =& Plotter::findDistanceToX($target, $sector, true);
    return $path->getRelativeDistance();
}
コード例 #12
0
ファイル: userstats.php プロジェクト: nikosv/openeclass
        foreach ($course_code_result as $row) {
            $course_codes[] = $row->code;
            $course_names[$row->code] = $row->title;
        }
        $course_code_result = null;

        foreach ($course_codes as $code) {
            Database::get()->queryFunc("SELECT SUM(hits) AS cnt FROM actions_daily
                                       WHERE user_id = ?d AND course_id =?d", function($row) use (&$totalHits, &$hits, $code) {
                $totalHits += $row->cnt;
                $hits[$code] = $row->cnt;
            }, $u, course_code_to_id($code));
        }
    }
    $tool_content .= "<b>$totalHits</b></p>";
    $chart = new Plotter(220, 200);
    $chart->setTitle($langCourseVisits);
    foreach ($hits as $code => $count) {
        $chart->growWithPoint(q($course_names[$code]), $count);
    }
    $tool_content .= $chart->plot();
    // End of chart display; chart unlinked at end of script.
    $tool_content .= "<p>$langLastUserVisits " . q($info) . "</p>";
    $tool_content .= "<div class='table-responsive'><table class='table-default'>
	      <tr>
		<th class='text-left'>&nbsp;&nbsp;$langDate</th>
		<th class='text-center'>$langAction</th>
	      </tr>";
    $Action["LOGIN"] = "******";
    $Action["LOGOUT"] = "<font color='#FF0000'>$langLogout</font>";
    
コード例 #13
0
ファイル: pollresults.php プロジェクト: kostastzo/openeclass
             $names = Database::get()->queryArray("SELECT CONCAT(b.surname, ' ', b.givenname) AS fullname FROM poll_answer_record AS a, user AS b WHERE a.aid = ?d AND a.user_id = b.id", $aid);
             foreach ($names as $name) {
                 $names_array[] = $name->fullname;
             }
             $names_str = implode(', ', $names_array);
             $ellipsized_names_str = q(ellipsize($names_str, 60));
         }
         $answers_table .= "\n                    <tr>\n                            <td>" . $q_answer . "</td>\n                            <td>{$answer->count}</td>" . ($thePoll->anonymized == 1 ? '' : '<td>' . $ellipsized_names_str . ($ellipsized_names_str != $names_str ? ' <a href="#" class="trigger_names" data-type="multiple" id="show">' . $showall . '</a>' : '') . '</td><td class="hidden_names" style="display:none;">' . q($names_str) . ' <a href="#" class="trigger_names" data-type="multiple" id="hide">' . $shownone . '</a></td>') . "</tr>";
         unset($names_array);
     }
     $answers_table .= "</table><br>";
     $chart->normalize();
     $tool_content .= $chart->plot();
     $tool_content .= $answers_table;
 } elseif ($theQuestion->qtype == QTYPE_SCALE) {
     $chart = new Plotter(800, 300);
     for ($i = 1; $i <= $theQuestion->q_scale; $i++) {
         $chart->addPoint($i, 0);
     }
     $answers = Database::get()->queryArray("SELECT answer_text, count(answer_text) as count FROM poll_answer_record WHERE qid = ?d GROUP BY answer_text", $theQuestion->pqid);
     $answer_total = Database::get()->querySingle("SELECT COUNT(*) AS total FROM poll_answer_record WHERE qid= ?d", $theQuestion->pqid)->total;
     $answers_table = "\n                <table class='table-default'>\n                    <tr>\n                        <th>{$langAnswer}</th>\n                        <th>{$langSurveyTotalAnswers}</th>" . ($thePoll->anonymized == 1 ? '' : '<th>' . $langStudents . '</th>') . "</tr>";
     foreach ($answers as $answer) {
         $percentage = round(100 * ($answer->count / $answer_total), 2);
         $chart->addPoint(q($answer->answer_text), $percentage);
         if ($thePoll->anonymized != 1) {
             $names = Database::get()->queryArray("SELECT CONCAT(b.surname, ' ', b.givenname) AS fullname FROM poll_answer_record AS a, user AS b WHERE a.answer_text = ?s AND a.user_id = b.id", $answer->answer_text);
             foreach ($names as $name) {
                 $names_array[] = $name->fullname;
             }
             $names_str = implode(', ', $names_array);
コード例 #14
0
ファイル: npc.php プロジェクト: smrealms/smrv2.0
function &findRoutes(&$player)
{
    debug('Finding Routes');
    $galaxies =& SmrGalaxy::getGameGalaxies($player->getGameID());
    $tradeGoods = array(GOOD_NOTHING => false);
    $goods =& Globals::getGoods();
    foreach ($goods as $goodID => &$good) {
        if ($player->meetsAlignmentRestriction($good['AlignRestriction'])) {
            $tradeGoods[$goodID] = true;
        } else {
            $tradeGoods[$goodID] = false;
        }
    }
    unset($good);
    $tradeRaces = array();
    $races =& Globals::getRaces();
    foreach ($races as $raceID => &$race) {
        $tradeRaces[$raceID] = false;
    }
    unset($race);
    $tradeRaces[$player->getRaceID()] = true;
    $galaxy =& $player->getSector()->getGalaxy();
    $maxNumberOfPorts = 2;
    $routesForPort = -1;
    $numberOfRoutes = 1000;
    $maxDistance = 15;
    $startSectorID = $galaxy->getStartSector();
    $endSectorID = $galaxy->getEndSector();
    $db = new SmrMySqlDatabase();
    $db->query('SELECT routes FROM route_cache WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' AND max_ports=' . $db->escapeNumber($maxNumberOfPorts) . ' AND goods_allowed=' . $db->escapeObject($tradeGoods) . ' AND races_allowed=' . $db->escapeObject($tradeRaces) . ' AND start_sector_id=' . $db->escapeNumber($startSectorID) . ' AND end_sector_id=' . $db->escapeNumber($endSectorID) . ' AND routes_for_port=' . $db->escapeNumber($routesForPort) . ' AND max_distance=' . $db->escapeNumber($maxDistance));
    if ($db->nextRecord()) {
        $routes = unserialize(gzuncompress($db->getField('routes')));
        debug('Using Cached Routes: #' . count($routes));
        return $routes;
    } else {
        debug('Generating Routes');
        $allSectors = array();
        foreach ($galaxies as &$galaxy) {
            $allSectors += $galaxy->getSectors();
            //Merge arrays
        }
        unset($galaxy);
        $distances =& Plotter::calculatePortToPortDistances($allSectors, $maxDistance, $startSectorID, $endSectorID);
        if ($maxNumberOfPorts == 1) {
            $allRoutes = RouteGenerator::generateOneWayRoutes($allSectors, $distances, $tradeGoods, $tradeRaces, $routesForPort);
        } else {
            $allRoutes = RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes);
        }
        unset($distances);
        $allRoutes =& $allRoutes[RouteGenerator::EXP_ROUTE];
        $routesMerged = array();
        foreach ($allRoutes as $multi => &$routesByMulti) {
            $routesMerged += $routesByMulti;
            //Merge arrays
        }
        unset($routesByMulti);
        unset($allSectors);
        SmrPort::clearCache();
        SmrSector::clearCache();
        $db->query('INSERT INTO route_cache ' . '(game_id, max_ports, goods_allowed, races_allowed, start_sector_id, end_sector_id, routes_for_port, max_distance, routes)' . ' VALUES (' . $db->escapeNumber($player->getGameID()) . ', ' . $db->escapeNumber($maxNumberOfPorts) . ', ' . $db->escapeObject($tradeGoods) . ', ' . $db->escapeObject($tradeRaces) . ', ' . $db->escapeNumber($startSectorID) . ', ' . $db->escapeNumber($endSectorID) . ', ' . $db->escapeNumber($routesForPort) . ', ' . $db->escapeNumber($maxDistance) . ', ' . $db->escapeObject($routesMerged, true) . ')');
        debug('Found Routes: #' . count($routesMerged));
        return $routesMerged;
    }
}
コード例 #15
0
ファイル: portfolio.php プロジェクト: kostastzo/openeclass
/**
* draws statistics graph
* @global type $uid
* @global type $langCourseVisits
s * @return type
*/
function courseVisitsPlot()
{
    global $uid, $langCourseVisits, $langNoStats;
    $totalHits = 0;
    $totalDuration = 0;
    $result = Database::get()->queryArray("SELECT a.code code, a.title title\n                                        FROM course AS a LEFT JOIN course_user AS b\n                                             ON a.id = b.course_id\n                                        WHERE b.user_id = ?d\n                                        AND a.visible != " . COURSE_INACTIVE . "\n                                        ORDER BY a.title", $uid);
    if (count($result) > 0) {
        // found courses ?
        foreach ($result as $row) {
            $course_codes[] = $row->code;
            $course_names[$row->code] = $row->title;
        }
        foreach ($course_codes as $code) {
            $cid = course_code_to_id($code);
            $row = Database::get()->querySingle("SELECT SUM(hits) AS cnt FROM actions_daily\n                                WHERE user_id = ?d\n                                AND course_id =?d", $uid, $cid);
            if ($row) {
                $totalHits += $row->cnt;
                $hits[$code] = $row->cnt;
            }
            $result = Database::get()->querySingle("SELECT SUM(duration) AS duration FROM actions_daily\n                                        WHERE user_id = ?d\n                                        AND course_id = ?d", $uid, $cid);
            $duration[$code] = $result->duration;
            $totalDuration += $duration[$code];
        }
        $chart = new Plotter(600, 300);
        $chart->setTitle($langCourseVisits);
        foreach ($hits as $code => $count) {
            if ($count > 0) {
                $chart->addPoint($course_names[$code], $count);
                $chart->modDimension(7, 0);
            }
        }
        return $chart->plot();
    } else {
        return "{$langNoStats}";
    }
}
コード例 #16
0
ファイル: favourite.php プロジェクト: nikosv/openeclass
                            AND course_id = ?d
                            AND module_id > 0
                        GROUP BY module_id", $terms, $course_id);
        foreach ($result as $row) {
            $mid = $row->module_id;
            if ($mid == MODULE_ID_UNITS) { // course units
                $chart->growWithPoint($langCourseUnits, $row->cnt);
            } else { // other modules
                $chart->growWithPoint($modules[$mid]['title'], $row->cnt);
            }
        }
        $chart_error = $langNoStatistics;
        break;

    case "duration":
        $chart = new Plotter(400, 300);
        $chart->setTitle($langFavourite);
        $result = Database::get()->queryArray("SELECT module_id, SUM(duration) AS tot_dur FROM actions_daily
                        WHERE $date_where $user_where
                            AND course_id = ?d
                            AND module_id > 0
                        GROUP BY module_id", $terms, $course_id);
        foreach ($result as $row) {
            $mid = $row->module_id;
            if ($mid == MODULE_ID_UNITS) { // course inits
                $chart->growWithPoint($langCourseUnits, $row->tot_dur);
            } else { // other modules
                $chart->growWithPoint($modules[$mid]['title'], $row->tot_dur);
            }
        }
        $chart_error = $langDurationExpl;
コード例 #17
0
}
// send scout msg
$sector->leavingSector($player, MOVEMENT_JUMP);
// Move the user around
// TODO: (Must be done while holding both sector locks)
$distance = $path->getRelativeDistance();
$turnsToJump = max(TURNS_JUMP_MINIMUM, round($distance * TURNS_PER_JUMP_DISTANCE));
// check for turns
if ($player->getTurns() < $turnsToJump) {
    create_error('You don\'t have enough turns for that jump!');
}
$maxMisjump = max(0, round(($distance - $turnsToJump) * MISJUMP_DISTANCE_DIFF_FACTOR / (1 + $player->getLevelID() * MISJUMP_LEVEL_FACTOR)));
$misjump = mt_rand(0, $maxMisjump);
if ($misjump > 0) {
    // we missed the sector
    $distances = Plotter::findDistanceToX('Distance', $targetSector, false, null, null, $misjump);
    while (count($distances[$misjump]) == 0) {
        $misjump--;
    }
    $misjumpSector = array_rand($distances[$misjump]);
    if ($misjumpSector == null) {
        throw new Exception('Misjump sector is null, distances: ' . var_export($distances, true));
    }
    $player->setSectorID($misjumpSector);
    unset($distances);
} else {
    // we hit it. exactly
    $player->setSectorID($targetSector->getSectorID());
}
$player->takeTurns($turnsToJump, $turnsToJump);
// log action
コード例 #18
0
ファイル: index.php プロジェクト: nikosv/openeclass
function show_assignment($id, $display_graph_results = false) {
    global $tool_content, $m, $langBack, $langNoSubmissions, $langSubmissions,
    $langEndDeadline, $langWEndDeadline, $langNEndDeadline, $langWorkOnlineText,
    $langDays, $langDaysLeft, $langGradeOk, $course_code, $webDir, $urlServer,
    $langGraphResults, $m, $course_code, $themeimg, $works_url, $course_id,
    $langDelWarnUserAssignment, $langQuestionView, $langDelete, $langEditChange,
    $langAutoJudgeShowWorkResultRpt;

    $assign = Database::get()->querySingle("SELECT *, CAST(UNIX_TIMESTAMP(deadline)-UNIX_TIMESTAMP(NOW()) AS SIGNED) AS time
                                FROM assignment
                                WHERE course_id = ?d AND id = ?d", $course_id, $id);

    $nav[] = $works_url;
    assignment_details($id, $assign);

    $rev = (@($_REQUEST['rev'] == 1)) ? 'DESC' : 'ASC';
    if (isset($_REQUEST['sort'])) {
        if ($_REQUEST['sort'] == 'am') {
            $order = 'am';
        } elseif ($_REQUEST['sort'] == 'date') {
            $order = 'submission_date';
        } elseif ($_REQUEST['sort'] == 'grade') {
            $order = 'grade';
        } elseif ($_REQUEST['sort'] == 'filename') {
            $order = 'file_name';
        } else {
            $order = 'surname';
        }
    } else {
        $order = 'surname';
    }

    $result1 = Database::get()->queryArray("SELECT * FROM assignment_submit AS assign, user
                                 WHERE assign.assignment_id = ?d AND user.id = assign.uid
                                 ORDER BY ?s ?s", $id, $order, $rev);

    $num_results = count($result1);
    if ($num_results > 0) {
        if ($num_results == 1) {
            $num_of_submissions = $m['one_submission'];
        } else {
            $num_of_submissions = sprintf("$m[more_submissions]", $num_results);
        }

        $gradeOccurances = array(); // Named array to hold grade occurances/stats
        $gradesExists = 0;
        foreach ($result1 as $row) {
            $theGrade = $row->grade;
            if ($theGrade) {
                $gradesExists = 1;
                if (!isset($gradeOccurances[$theGrade])) {
                    $gradeOccurances[$theGrade] = 1;
                } else {
                    if ($gradesExists) {
                        ++$gradeOccurances[$theGrade];
                    }
                }
            }
        }
        if (!$display_graph_results) {

            $result = Database::get()->queryArray("SELECT assign.id id, assign.file_name file_name,
                                                   assign.uid uid, assign.group_id group_id,
                                                   assign.submission_date submission_date,
                                                   assign.grade_submission_date grade_submission_date,
                                                   assign.grade grade, assign.comments comments,
                                                   assign.grade_comments grade_comments,
                                                   assignment.grading_scale_id grading_scale_id,
                                                   assignment.deadline deadline
                                                   FROM assignment_submit AS assign, user, assignment
                                                   WHERE assign.assignment_id = ?d AND assign.assignment_id = assignment.id AND user.id = assign.uid
                                                   ORDER BY $order $rev", $id);
            $tool_content .= "
                        <form action='$_SERVER[SCRIPT_NAME]?course=$course_code' method='post' class='form-inline'>
                        <input type='hidden' name='grades_id' value='$id' />
                        <br>
                        <div class='margin-bottom-thin'>
                            <b>$langSubmissions:</b>&nbsp; $num_results
                        </div>
                        <div class='table-responsive'>
                        <table class='table-default'>
                        <tbody>
                        <tr class='list-header'>
                      <th width='3'>&nbsp;</th>";
            sort_link($m['username'], 'username');
            sort_link($m['am'], 'am');
            $assign->submission_type ? $tool_content .= "<th>$langWorkOnlineText</th>" : sort_link($m['filename'], 'filename');
            sort_link($m['sub_date'], 'date');
            sort_link($m['grade'], 'grade');
            $tool_content .= "<th width='5%' class='text-center'><i class='fa fa-cogs'></i></th></tr>";

            $i = 1;
            foreach ($result as $row) {
                //is it a group assignment?
                if (!empty($row->group_id)) {
                    $subContentGroup = "$m[groupsubmit] " .
                            "<a href='../group/group_space.php?course=$course_code&amp;group_id=$row->group_id'>" .
                            "$m[ofgroup] " . gid_to_name($row->group_id) . "</a>";
                } else {
                    $subContentGroup = '';
                }
                $uid_2_name = display_user($row->uid);
                $stud_am = Database::get()->querySingle("SELECT am FROM user WHERE id = ?d", $row->uid)->am;
                if ($assign->submission_type) {
                    $filelink = "<a href='#' class='onlineText btn btn-xs btn-default' data-id='$row->id'>$langQuestionView</a>";
                } else {
                    $filelink = empty($row->file_name) ? '&nbsp;' :
                            ("<a href='$_SERVER[SCRIPT_NAME]?course=$course_code&amp;get=$row->id'>" .
                            q($row->file_name) . "</a>");
                }
                if(Session::has("grades")) {
                    $grades = Session::get('grades');
                    $grade = $grades[$row->id]['grade'];
                } else {
                    $grade = $row->grade;
                }
                if ($row->grading_scale_id) {
                    $serialized_scale_data = Database::get()->querySingle('SELECT scales FROM grading_scale WHERE id = ?d AND course_id = ?d', $row->grading_scale_id, $course_id)->scales;
                    $scales = unserialize($serialized_scale_data);
                    $scale_options = "<option value> - </option>";
                    $scale_values = array_value_recursive('scale_item_value', $scales);
                    if (!in_array($grade, $scale_values) && !is_null($grade)) {
                        $grade = closest($grade, $scale_values)['value'];
                    }
                    foreach ($scales as $scale) {
                        $scale_options .= "<option value='$scale[scale_item_value]'".($scale['scale_item_value'] == $grade ? " selected" : "").">$scale[scale_item_name]</option>";
                    }
                    $grade_field = "
                            <select name='grades[$row->id][grade]' class='form-control' id='scales'>
                                $scale_options
                            </select>";
                } else {
                    $grade_field = "<input class='form-control' type='text' value='$grade' name='grades[$row->id][grade]' maxlength='4' size='3'>";
                }
                $late_sub_text = $row->deadline && $row->submission_date > $row->deadline ?  "<div style='color:red;'><small>$m[late_submission]</small></div>" : '';
                $tool_content .= "
                                <tr>
                                <td align='right' width='4' rowspan='2' valign='top'>$i.</td>
                                <td>${uid_2_name}</td>
                                <td width='85'>" . q($stud_am) . "</td>
                                <td class='text-center' width='180'>
                                        $filelink
                                </td>
                                <td width='100'>" . nice_format($row->submission_date, TRUE) .$late_sub_text. "</td>
                                <td width='5'>
                                    <div class='form-group ".(Session::getError("grade.$row->id") ? "has-error" : "")."'>
                                        $grade_field
                                        <span class='help-block'>".Session::getError("grade.$row->id")."</span>
                                    </div>
                                </td>
                                <td class='option-btn-cell'>".
                                    action_button(array(
                                        array(
                                            'title' => $langEditChange,
                                            'url' => "grade_edit.php?course=$course_code&amp;assignment=$id&amp;submission=$row->id",
                                            'level' => 'primary',
                                            'icon' => 'fa-edit'
                                        ),
                                        array(
                                            'title' => $langDelete,
                                            'url' => "$_SERVER[SCRIPT_NAME]?course=$course_code&amp;id=$id&amp;as_id=$row->id",
                                            'class' => 'delete',
                                            'icon' => 'fa-times',
                                            'confirm' => $langDelWarnUserAssignment
                                        )
                                    ))."
                                </td>
                                </tr>
                                <tr>
                                <td colspan='6'>
                                <div>$subContentGroup</div>";
                if (trim($row->comments != '')) {
                    $tool_content .= "<div style='margin-top: .5em;'>" .
                            q($row->comments) . '</div>';
                }
                //professor comments
                if ($row->grade_comments || $row->grade != '') {
                    $comments = "<br><div class='label label-primary'>" .
                            nice_format($row->grade_submission_date) . "</div>";
                }
                if (trim($row->grade_comments)) {
                    $label = '<b>'.$m['gradecomments'] . '</b>:';
                    $comments .= "&nbsp;<span>" . standard_text_escape($row->grade_comments) . "</span>";
                } else {
                    $label = '';
                    $comments = '';
                }
                $tool_content .= "<div style='padding-top: .5em;'>$label
				  $comments
                                ";
                if(AutojudgeApp::getAutojudge()->isEnabled()) {
                    $reportlink = "work_result_rpt.php?course=$course_code&amp;assignment=$id&amp;submission=$row->id";
                    $tool_content .= "<a href='$reportlink'><b>$langAutoJudgeShowWorkResultRpt</b></a>";
                }
                $tool_content .= "
                                </td>
                                </tr>";
                $i++;
            } //END of Foreach

            $tool_content .= "
                    </tbody>
                </table>
            </div>
            <div class='form-group'>
                <div class='col-xs-12'>
                    <div class='checkbox'>
                      <label>
                        <input type='checkbox' value='1' name='email'> $m[email_users]
                      </label>
                    </div>
                </div>
            </div>
            <div class='pull-right'>
                <button class='btn btn-primary' type='submit' name='submit_grades'>$langGradeOk</button>
            </div>
        </form>";
        } else {
        // display pie chart with grades results
            if ($gradesExists) {
                // Used to display grades distribution chart
                $graded_submissions_count = Database::get()->querySingle("SELECT COUNT(*) AS count FROM assignment_submit AS assign, user
                                                             WHERE assign.assignment_id = ?d AND user.id = assign.uid AND
                                                             assign.grade <> ''", $id)->count;
                $chart = new Plotter();
                $chart->setTitle("$langGraphResults");
                if ($assign->grading_scale_id) {
                    $serialized_scale_data = Database::get()->querySingle('SELECT scales FROM grading_scale WHERE id = ?d AND course_id = ?d', $assign->grading_scale_id, $course_id)->scales;
                    $scales = unserialize($serialized_scale_data);
                    $scale_values = array_value_recursive('scale_item_value', $scales);
                }
                foreach ($gradeOccurances as $gradeValue => $gradeOccurance) {
                    $percentage = round((100.0 * $gradeOccurance / $graded_submissions_count),2);
                    if ($assign->grading_scale_id) {
                        $key = closest($gradeValue, $scale_values, true)['key'];
                        $gradeValue = $scales[$key]['scale_item_name'];
                    }
                    $chart->growWithPoint("$gradeValue ($percentage%)", $percentage);
                }
                $tool_content .= $chart->plot();
            }
        }
    } else {
        $tool_content .= "
                      <p class='sub_title1'>$langSubmissions:</p>
                      <div class='alert alert-warning'>$langNoSubmissions</div>";
    }
}
コード例 #19
0
ファイル: testRouteGen.php プロジェクト: smrealms/smrv2.0
require_once '../htdocs/config.inc';
require_once LIB . 'Default/Globals.class.inc';
require_once get_file_loc('RouteGenerator.class.inc');
require_once get_file_loc('SmrGalaxy.class.inc');
$gameID = 108;
$galaxies =& SmrGalaxy::getGameGalaxies($gameID);
$allSectors = array();
foreach ($galaxies as &$galaxy) {
    $allSectors = $allSectors + $galaxy->getSectors();
}
unset($galaxy);
$maxNumberOfPorts = 2;
$goods = array(true, true, true, true, false, false, false, false, false, false, false, false, false);
$races = array(true, true, true, true, false, false, false, false, false, false, false, false, false, false);
//$distances =& Plotter::calculatePortToPortDistances($allSectors,10,0,1440);
$distances =& Plotter::calculatePortToPortDistances($allSectors, 10, 0, 14);
//var_dump($distances);
$routesForPort = -1;
$numberOfRoutes = 5;
if ($maxNumberOfPorts == 1) {
    $allRoutes = RouteGenerator::generateOneWayRoutes($allSectors, $distances, $goods, $races, $routesForPort);
} else {
    $allRoutes = RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $goods, $races, $distances, $routesForPort, $numberOfRoutes);
}
//var_dump($allRoutes);
foreach ($allRoutes as $routeType) {
    $c = 0;
    foreach ($routeType as $routeMulti) {
        $c += count($routeMulti);
        //		foreach($routeMulti as $multi => $route) {
        //			echo $multi . ":  ".$route->getRouteString();