コード例 #1
0
function process_prior($window, $id)
{
    global $mainwin, $prior_table;
    switch ($id) {
        case ID_PRIORITYLIST:
            update_prior_controls($window);
            break;
        case ID_NEWITEM:
            $name = wb_get_text(wb_get_control($window, ID_NAME));
            db_edit_record($prior_table, 0, "name", array($name));
            update_priors($window);
            update_prior_controls($window);
            break;
        case ID_SETITEM:
            $name = wb_get_text(wb_get_control($window, ID_NAME));
            $itemlist = wb_get_control($window, ID_PRIORITYLIST);
            $id = db_get_id($prior_table, wb_get_selected($itemlist));
            db_edit_record($prior_table, $id, "name", array($name));
            update_priors($window);
            update_prior_controls($window);
            break;
        case ID_DELETEITEM:
            $itemlist = wb_get_control($window, ID_PRIORITYLIST);
            $selected = wb_get_selected($itemlist);
            $id = db_get_id($prior_table, $selected);
            db_delete_records($prior_table, db_get_id($prior_table, $selected));
            update_priors($window);
            update_prior_controls($window);
            break;
        case ID_MOVEUP:
            $itemlist = wb_get_control($window, ID_PRIORITYLIST);
            $selected = wb_get_selected($itemlist);
            $id = db_get_id($prior_table, $selected);
            db_swap_records($prior_table, db_get_id($prior_table, $selected), db_get_id($prior_table, $selected - 1));
            update_priors($window);
            update_prior_controls($window);
            break;
        case ID_MOVEDOWN:
            $itemlist = wb_get_control($window, ID_PRIORITYLIST);
            $selected = wb_get_selected($itemlist);
            $id = db_get_id($prior_table, $selected);
            db_swap_records($prior_table, db_get_id($prior_table, $selected), db_get_id($prior_table, $selected + 1));
            update_priors($window);
            update_prior_controls($window);
            break;
        case IDCANCEL:
        case IDCLOSE:
        case IDOK:
            wb_destroy_window($window);
            break;
    }
}
コード例 #2
0
function update_item($window)
{
    global $id_edit;
    $name = wb_get_text(wb_get_control($window, ID_NAME));
    $descr = wb_get_text(wb_get_control($window, ID_DESCRIPTION));
    // Fetch the id from table 'cat'
    $id_cat = (int) db_get_id("cat", wb_get_selected(wb_get_control($window, ID_CATLIST)));
    $id_prior = (int) db_get_id("priority", wb_get_selected(wb_get_control($window, ID_PRIORLIST)));
    $id_sever = (int) db_get_id("severity", wb_get_selected(wb_get_control($window, ID_SEVERLIST)));
    $res = db_edit_record("item", $id_edit, "name\ndescription\ncat\npriority\nseverity", array($name, $descr, $id_cat, $id_prior, $id_sever));
    if (!$res) {
        wb_message_box($window, "Problem editing this record.", null, WBC_WARNING);
    }
    return $res;
}
コード例 #3
0
/**
* db_swap_records()
*
* Swaps values from two records, including the id field or not according to $xchangeid.
*
* @param  $tablename
* @param  $id1
* @param  $id2
* @param string $idfield
* @param boolean $xchangeid
* @return bool
*/
function db_swap_records($tablename, $id1, $id2, $idfield = "id", $xchangeid = true)
{
    global $g_lasttable;
    // Table name
    if (!$tablename) {
        $tablename = $g_lasttable;
    }
    $g_lasttable = $tablename;
    $table = APPPREFIX . "{$tablename}";
    // Build SQL strings
    $result = raw_db_query("SELECT * FROM {$table} WHERE {$idfield} = {$id1}");
    if (!$result) {
        trigger_error(__FUNCTION__ . ": could not read record {$id1} in table {$tablename}.");
        return false;
    }
    $a = db_fetch_array($result, FETCH_ASSOC);
    $fieldvalues1 = array_values($a);
    $fieldnames1 = array_keys($a);
    array_shift($fieldvalues1);
    array_shift($fieldnames1);
    $result = raw_db_query("SELECT * FROM {$table} WHERE {$idfield} = {$id2}");
    if (!$result) {
        trigger_error(__FUNCTION__ . ": could not read record {$id2} in table {$tablename}.");
        return false;
    }
    $a = db_fetch_array($result, FETCH_ASSOC);
    $fieldvalues2 = array_values($a);
    $fieldnames2 = array_keys($a);
    array_shift($fieldvalues2);
    array_shift($fieldnames2);
    // Exchange values
    if (db_edit_record($tablename, $id1, $fieldnames2, $fieldvalues2, $idfield) === false) {
        return false;
    }
    if (db_edit_record($tablename, $id2, $fieldnames1, $fieldvalues1, $idfield) === false) {
        return false;
    }
    // Exchange id's
    if ($xchangeid) {
        $unique = db_get_next_free_id($tablename);
        if (db_edit_record($tablename, $id1, array($idfield), array($unique), $idfield) === false) {
            return false;
        }
        if (db_edit_record($tablename, $id2, array($idfield), array($id1), $idfield) === false) {
            return false;
        }
        if (db_edit_record($tablename, $unique, array($idfield), array($id2), $idfield) === false) {
            return false;
        }
    }
    return true;
}