Exemplo n.º 1
0
/**
 *	admin_table_postadd() - update the database based on a submitted change
 *
 *	@param $table - the table to act on
 *	@param $unit - the name of the "units" described by the table's records
 *	@param $primary_key - the primary key of the table
 */
function admin_table_postadd($table, $unit, $primary_key)
{
    if (!form_key_is_valid(getStringFromRequest('form_key'))) {
        exit_form_double_submit();
    }
    $field_list = getStringFromRequest('__fields__');
    $fields = split(",", $field_list);
    $values = array();
    foreach ($fields as $field) {
        $values[] = "'" . getStringFromPost($field) . "'";
    }
    $sql = "INSERT INTO {$table} (" . $field_list . ") VALUES (" . implode(",", $values) . ")";
    if (db_query($sql)) {
        printf(_('%1$s successfully added.'), ucfirst(getUnitLabel($unit)));
    } else {
        form_release_key(getStringFromRequest('form_key'));
        echo db_error();
    }
}
Exemplo n.º 2
0
     snippet_footer(array());
 } else {
     if ($type == 'package') {
         /*
         	Handle insertion of a new package version
         */
         /*
         	See if the package exists first
         */
         $result = db_query("SELECT * FROM snippet_package WHERE snippet_package_id='{$id}'");
         if (!$result || db_numrows($result) < 1) {
             exit_error(_('Error - snippet_package doesn\'t exist'));
         }
         if (getStringFromRequest('post_changes')) {
             if (!form_key_is_valid(getStringFromRequest('form_key'))) {
                 exit_form_double_submit();
             }
             $snippet_package_id = getIntFromRequest('snippet_package_id');
             $changes = getStringFromRequest('changes');
             $version = getStringFromRequest('version');
             /*
             	Create a new snippet entry, then create a new snippet version entry
             */
             if ($changes && $snippet_package_id) {
                 /*
                 	create the snippet package version
                 */
                 $sql = "INSERT INTO snippet_package_version " . "(snippet_package_id,changes,version,submitted_by,post_date) " . "VALUES ('{$snippet_package_id}','" . htmlspecialchars($changes) . "','" . htmlspecialchars($version) . "','" . user_getid() . "','" . time() . "')";
                 $result = db_query($sql);
                 if (!$result) {
                     //error in database