$w = 'keepout';
            }
        }
        $delta_[$w][] = $state;
    }
}
// -----------------------------------------------
// Restate the requested changes, and perform them.
$headers = array('remove' => _("Removing holds for the following states:"), 'keep' => _("Keeping holds for the following states:"), 'add' => _("Adding holds for the following states:"));
foreach ($headers as $w => $header) {
    $states = $delta_[$w];
    if (count($states)) {
        echo "<p>{$header}</p>\n";
        echo "<ul>\n";
        foreach ($states as $state) {
            echo "<li>", get_medium_label_for_project_state($state), "</li>\n";
        }
        echo "</ul>\n";
        // -----------------------------------
        $sql = NULL;
        if ($w == 'remove') {
            $states_str = surround_and_join($states, "'", "'", ", ");
            $sql = "\n                DELETE FROM project_holds\n                WHERE projectid='{$projectid}'\n                    AND state in ({$states_str})\n            ";
            $event_type = 'remove_holds';
        } elseif ($w == 'add') {
            $values = '';
            foreach ($states as $state) {
                if ($values) {
                    $values .= ",\n";
                }
                $values .= "('{$projectid}', '{$state}')";
function echo_project_state_option($project_state, $selected)
{
    echo "<option value='{$project_state}'";
    if ($selected) {
        echo " SELECTED";
    }
    echo ">";
    if ($project_state == 'automodify') {
        echo _('automodify');
    } else {
        echo get_medium_label_for_project_state($project_state);
    }
    echo "</option>\n";
}
    $total_n_w_diff_percent = sprintf("%d", $total_n_w_diff / $total_n_latered * 100);
} else {
    $total_n_w_diff_percent = 0;
}
echo "<tr>";
echo "<th>{$total_valid_projects}</th>";
echo "<th></th>";
echo "<th></th>";
echo "<th align='center'>{$total_n_saved}</th>";
echo "<th align='center'>{$total_n_latered}</th>";
echo "<th align='center'>{$total_n_w_diff} ({$total_n_w_diff_percent}%)</th>";
echo "</tr>";
echo "</table>";
// show messages
$total_invalid_projects = count($messages);
if ($total_invalid_projects) {
    echo "<h2>" . _("Other projects") . "</h2>";
    echo "<table border='1'>";
    echo "<tr><th>" . _("Project") . "</th><th>" . _("Current State") . "</th><th>" . _("Status") . "</th></tr>";
    foreach ($messages as $message) {
        echo "<tr><td>{$message[0]}</td>";
        echo "<td nowrap>";
        echo get_medium_label_for_project_state($message[1]);
        echo "</td>";
        echo "<td>{$message[2]}</td></tr>";
    }
    echo "<tr><th>{$total_invalid_projects}</th><th></th><th></th></tr>";
    echo "</table>";
}
echo "<br>";
// vim: sw=4 ts=4 expandtab
Example #4
0
function do_history()
{
    global $project;
    echo "<h4>", _("Project History"), "</h4>\n";
    $res = mysql_query("\n        SELECT timestamp, who, event_type, details1, details2, details3\n        FROM project_events\n        WHERE projectid = '{$project->projectid}'\n        ORDER BY event_id\n    ") or die(mysql_error());
    $events = array();
    while ($event = mysql_fetch_assoc($res)) {
        $events[] = $event;
    }
    $events2 = fill_gaps_in_events($events);
    // The project history is only partially translated right now.
    $event_type_labels = array("archive" => _("archive"), "creation" => _("creation"), "deletion" => _("deletion"), "edit" => _("edit"), "smooth-reading" => _("smoothreading"), "transition" => _("transition"), "transition(s)" => _("transition(s)"), "add_holds" => _("add hold(s)"), "remove_holds" => _("remove hold(s)"));
    echo "<table border='1'>\n";
    foreach ($events2 as $event) {
        echo "<tr>\n";
        echo "<td>";
        echo $event['timestamp'] == '?' ? '?' : strftime('%Y-%m-%d %H:%M:%S', $event['timestamp']);
        echo "</td>\n";
        echo "<td>{$event['who']}</td>\n";
        $event_type = $event['event_type'];
        echo "<td>", array_get($event_type_labels, $event_type, $event_type), "</td>\n";
        if ($event['event_type'] == 'transition' || $event['event_type'] == 'transition(s)') {
            $from_state = $event['details1'];
            $from_state_t = $from_state == '?' ? _('unknown state') : get_medium_label_for_project_state($from_state);
            if ($from_state_t == '') {
                $from_state_t = $from_state;
            }
            $to_state = $event['details2'];
            $to_state_t = $to_state == '?' ? _('unknown state') : get_medium_label_for_project_state($to_state);
            if ($to_state_t == '') {
                $to_state_t = $to_state;
            }
            $details3 = $event['details3'];
            $details3_t = $details3;
            // but that can be overridden by ...
            $mappings = array('/^via_q:\\s*$/' => _('via no queue'), '/^via_q:\\s*(.*)/' => _('via "%s" queue'), '/^out_to:\\s*(.*)/' => _('checked out to %s'));
            foreach ($mappings as $pattern => $format) {
                if (preg_match($pattern, $details3, $matches)) {
                    unset($matches[0]);
                    // the (sub)string that matched the whole pattern
                    $details3_t = vsprintf($format, $matches);
                    break;
                }
            }
            echo "<td>", sprintf(_("from %s"), $from_state_t), "</td>\n";
            echo "<td>", sprintf(_("to %s"), $to_state_t), "</td>\n";
            echo "<td>{$details3_t}</td>\n";
        } elseif ($event['event_type'] == 'smooth-reading') {
            echo "<td>{$event['details1']}</td>\n";
            if ($event['details1'] == 'text available') {
                $deadline_f = strftime('%Y-%m-%d %H:%M:%S', $event['details2']);
                echo "<td>until {$deadline_f}</td>\n";
            }
        } elseif ($event['event_type'] == 'edit') {
            $changed_fields = $event['details1'];
            if ($changed_fields == '') {
                // This is an old edit event,
                // from before we recorded changed fields.
                // Just leave the rest of the row blank.
            } else {
                // List the changed fields (localized for the current user).
                if ($changed_fields == 'NONE') {
                    $list_of_changed_fields = _("none");
                } else {
                    // Maybe move this array to Project.inc
                    $label_for_project_field_ = array('deletion_reason' => _("Reason for Deletion"), 'nameofwork' => _("Name of Work"), 'authorsname' => _("Author's Name"), 'projectmanager' => _("Project Manager"), 'language' => _("Language"), 'genre' => _("Genre"), 'difficulty_level' => _("Difficulty Level"), 'special_code' => _("Special Day"), 'checkedoutby' => _("PPer/PPVer"), 'image_source' => _("Original Image Source"), 'image_preparer' => _("Image Preparer"), 'text_preparer' => _("Text Preparer"), 'extra_credits' => _("Extra Credits"), 'scannercredit' => _("Scanner Credit"), 'clearance' => _("Clearance Information"), 'postednum' => _("Posted Number"), 'comments' => _("Project Comments"));
                    $labels = array();
                    foreach (explode(' ', $changed_fields) as $fieldname) {
                        $labels[] = array_get($label_for_project_field_, $fieldname, $fieldname);
                    }
                    // Note that this lists the changed fields in the same order
                    // as they appear in the 'details1' field of the events table,
                    // which isn't necessarily consistent (or logical).
                    // However, I'm not sure it's worth doing anything about that.
                    if (count($labels) == 0) {
                        // This shouldn't happen.
                        $list_of_changed_fields = _("none");
                    } else {
                        $list_of_changed_fields = implode(', ', $labels);
                    }
                }
                echo "<td colspan='3'>";
                echo _("Changed fields:");
                echo " ", $list_of_changed_fields;
                echo "</td>\n";
            }
        } elseif ($event['event_type'] == 'add_holds' || $event['event_type'] == 'remove_holds') {
            $state_labels = array();
            foreach (explode(' ', $event['details1']) as $state) {
                $state_labels[] = get_medium_label_for_project_state($state);
            }
            echo "<td colspan='3'>";
            echo join($state_labels, ", ");
            echo "</td>\n";
        }
        echo "</tr>\n";
    }
    echo "</table>\n";
}
$result = dpsql_query($query);
if (mysql_num_rows($result) > 0) {
    echo "<a name='reserved' id='reserved'></a><h2>{$heading_reserved}</h2>\n";
    echo sprintf("(%d projects)", mysql_num_rows($result));
    echo "<table border='1'>";
    show_headings($colspecs, 'reserved', $username);
    while ($row = mysql_fetch_object($result)) {
        echo "<tr>\n";
        echo "<td>";
        echo "<a href='{$code_url}/project.php?id={$row->projectid}'>{$row->nameofwork}</a>";
        echo "</td>\n";
        echo "<td align='center'>";
        echo $row->username;
        echo "</td>\n";
        echo "<td nowrap>";
        echo get_medium_label_for_project_state($row->state);
        echo "</td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n";
    echo "<br>\n";
}
// -----------------
function get_sort_col_and_dir()
{
    global $colspecs, $default_order_col, $default_order_dir;
    $order_col = array_get($_GET, 'order_col', $default_order_col);
    $order_dir = array_get($_GET, 'order_dir', $default_order_dir);
    if (!isset($colspecs[$order_col])) {
        echo "Invalid order_col parameter: '{$order_col}'. Assuming '{$default_order_col}'.<br>\n";
        $order_col = $default_order_col;