function save_to_db()
 {
     global $projects_dir, $pguser;
     $postednum_str = $this->postednum == "" ? "NULL" : "'{$this->postednum}'";
     // Call addslashes() on any members of $this that might contain
     // single-quotes/apostrophes (because they are unescaped, and
     // would otherwise break the query).
     $common_project_settings = "\n            t_last_edit    = UNIX_TIMESTAMP(),\n            up_projectid   = '{$this->up_projectid}',\n            nameofwork     = '" . addslashes($this->nameofwork) . "',\n            authorsname    = '" . addslashes($this->authorsname) . "',\n            language       = '{$this->language}',\n            genre          = '{$this->genre}',\n            difficulty     = '{$this->difficulty_level}',\n            special_code   = '{$this->special_code}',\n            clearance      = '" . addslashes($this->clearance) . "',\n            comments       = '" . addslashes($this->comments) . "',\n            image_source   = '{$this->image_source}',\n            scannercredit  = '" . addslashes($this->scannercredit) . "',\n            checkedoutby   = '{$this->checkedoutby}',\n            postednum      = {$postednum_str},\n            image_preparer = '{$this->image_preparer}',\n            text_preparer  = '{$this->text_preparer}',\n            extra_credits  = '" . addslashes($this->extra_credits) . "',\n            deletion_reason= '" . addslashes($this->deletion_reason) . "'\n        ";
     $pm_setter = '';
     if (user_is_a_sitemanager()) {
         // can change PM
         $pm_setter = " username = '******',";
     } else {
         if (isset($this->clone_projectid)) {
             // cloning a project. The PM should be the same as
             // that of the project being cloned, if the user
             // isn't an SA
             $res = mysql_query("\n                SELECT username\n                FROM projects\n                WHERE projectid='{$this->clone_projectid}'\n            ") or die(mysql_error());
             list($projectmanager) = mysql_fetch_row($res);
             $pm_setter = " username = '******',";
         }
     }
     if (isset($this->projectid)) {
         // We are updating an already-existing project.
         // needn't change $pm_setter, as there is no change if the user
         // isn't an SA
         // find out what we are changing from
         $old_pih = new ProjectInfoHolder();
         $fatal_error = $old_pih->set_from_db(TRUE, $this->projectid);
         if ($fatal_error != '') {
             $fatal_error = _('site error') . ': ' . $fatal_error;
             echo "<br><center><font size='+1' color='#ff0000'><b>{$fatal_error}</b></font></center>";
             exit;
         }
         $changed_fields = get_changed_fields($this, $old_pih);
         // We're particularly interested in knowing
         // when the project comments change.
         if (!in_array('comments', $changed_fields)) {
             // no change
             $tlcc_setter = '';
         } else {
             // changed!
             $tlcc_setter = 't_last_change_comments = UNIX_TIMESTAMP(),';
         }
         // We also want to know if the edit is resulting in the project
         // effectively being checked out to a new PPer
         if ($old_pih->state == PROJ_POST_FIRST_CHECKED_OUT && in_array('checkedoutby', $changed_fields)) {
             $md_setter = 'modifieddate = UNIX_TIMESTAMP(),';
             $PPer_checkout = TRUE;
         } else {
             $md_setter = '';
             $PPer_checkout = FALSE;
         }
         // Update the projects database with the updated info
         mysql_query("\n                UPDATE projects SET\n                    {$pm_setter}\n                    {$tlcc_setter}\n                    {$md_setter}\n                    {$common_project_settings}\n                WHERE projectid='{$this->projectid}'\n            ") or die(mysql_error());
         $details1 = implode(' ', $changed_fields);
         if ($details1 == '') {
             // There are no changed fields.
             // Don't just save '' for the details1 column,
             // because then do_history() won't be able to distinguish
             // this case (no changed fields) from old cases
             // (edit occurred before we started recording changed fields).
             // Instead, use a special value.
             $details1 = 'NONE';
         }
         $e = log_project_event($this->projectid, $GLOBALS['pguser'], 'edit', $details1);
         if (!empty($e)) {
             die($e);
         }
         if ($PPer_checkout) {
             // we fake the project transition...
             $e = log_project_event($this->projectid, $GLOBALS['pguser'], 'transition', PROJ_POST_FIRST_CHECKED_OUT, PROJ_POST_FIRST_CHECKED_OUT, $this->checkedoutby);
             if (!empty($e)) {
                 die($e);
             }
         }
         // Update the MARC record with any info we've received.
         $project = new Project($this->projectid);
         $marc_record = $project->load_marc_record();
         $this->update_marc_record_from_post($marc_record);
         $project->save_marc_record($marc_record);
     } else {
         // We are creating a new project
         $this->projectid = uniqid("projectID");
         // The project ID
         if ('' == $pm_setter) {
             $pm_setter = "username = '******',";
         }
         // Insert a new row into the projects table
         mysql_query("\n                INSERT INTO projects\n                SET\n                    projectid    = '{$this->projectid}',\n                    {$pm_setter}\n                    state        = '" . PROJ_NEW . "',\n                    modifieddate = UNIX_TIMESTAMP(),\n                    t_last_change_comments = UNIX_TIMESTAMP(),\n                    {$common_project_settings}\n            ") or die(mysql_error());
         $e = log_project_event($this->projectid, $GLOBALS['pguser'], 'creation');
         if (!empty($e)) {
             die($e);
         }
         $e = project_allow_pages($this->projectid);
         if (!empty($e)) {
             die($e);
         }
         // Make a directory in the projects_dir for this project
         mkdir("{$projects_dir}/{$this->projectid}", 0777) or die("System error: unable to mkdir '{$projects_dir}/{$this->projectid}'");
         chmod("{$projects_dir}/{$this->projectid}", 0777);
         // Do MARC record manipulations
         $project = new Project($this->projectid);
         $marc_record = new MARCRecord();
         // Save original MARC record, if provided
         $yaz_array = unserialize(base64_decode($this->original_marc_array_encd));
         if ($yaz_array !== FALSE) {
             $marc_record->load_yaz_array($yaz_array);
             $project->init_marc_record($marc_record);
             // Update the MARC record with data from POST
             $this->update_marc_record_from_post($marc_record);
             $project->save_marc_record($marc_record);
         }
         // Create the project's 'good word list' and 'bad word list'.
         if (isset($this->clone_projectid)) {
             // We're creating a project via cloning.
             // Copy the original project's word-lists.
             $good_words = load_project_good_words($this->clone_projectid);
             if (is_string($good_words)) {
                 // It's an error message.
                 echo "{$good_words}<br>\n";
                 $good_words = array();
             }
             $bad_words = load_project_bad_words($this->clone_projectid);
             if (is_string($bad_words)) {
                 // It's an error message.
                 echo "{$bad_words}<br>\n";
                 $bad_words = array();
             }
         } else {
             // We're creating a project by means other than cloning
             // (from_nothing, from_marc_record, from_uberproject).
             // Initialize its GWL and BWL to empty.
             $good_words = array();
             $bad_words = array();
         }
         save_project_good_words($this->projectid, $good_words);
         save_project_bad_words($this->projectid, $bad_words);
     }
     // Create/update the Dublin Core file for the project.
     // When we get here, the project's database entry has been fully
     // updated, so we can create a Project object and allow it
     // to pull the relevant fields from the database.
     $project = new Project($this->projectid);
     $project->create_dc_xml_oai($marc_record);
     // If the project has been posted to PG, make the appropriate transition.
     if ($this->posted) {
         $err = project_transition($this->projectid, PROJ_SUBMIT_PG_POSTED, $pguser);
         if ($err != '') {
             echo "{$err}<br>\n";
             exit;
         }
     }
 }
        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}')";
            }
            $sql = "\n                INSERT INTO project_holds\n                VALUES {$values}\n            ";
            $event_type = 'add_holds';
        }
        if ($sql) {
            // echo $sql;
            mysql_query($sql) or die(mysql_error());
            log_project_event($projectid, $pguser, $event_type, join($states, ' '));
        }
    }
}
echo "<a href='{$return_uri}'>", _("Click here to return"), "</a>";
// vim: sw=4 ts=4 expandtab
     echo "{$error_msg}<br>\n";
 }
 // special handling for smooth reading, which does not involve a state change
 // but still needs some changes recorded in project table
 // the comments get recorded even if it's just a replacement
 if ($stage == 'smooth_avail') {
     $qstring = "\n                          UPDATE projects SET ";
     if ($weeks != "replace") {
         $qstring .= "smoothread_deadline = {$deadline}, ";
     }
     $qstring .= "postcomments = CONCAT(postcomments,'{$postcomments}')\n                          WHERE projectid = '{$projectid}'\n                      ";
     $qry = mysql_query($qstring);
     if ($weeks == "replace") {
         log_project_event($projectid, $pguser, 'smooth-reading', 'text replaced');
     } else {
         log_project_event($projectid, $pguser, 'smooth-reading', 'text available', $deadline);
     }
     notify_project_event_subscribers($project, 'sr_available');
     if ($auto_post_to_project_topic) {
         // Add an auto-post to the project's discussion topic.
         $project->ensure_topic();
         topic_add_post($project->topic_id, "Project made available for smooth-reading", "The project has just been made available for smooth-reading for {$weeks} weeks." . "\n\n" . "(This post is automatically generated.)", '[Smooth Reading Monitor]', FALSE);
     }
 }
 // let them know file uploaded and send back to the right place
 $msg1 = _("File uploaded. Thank you!");
 $msg2 = _("Project returned to pool");
 if ($have_file && $returning_to_pool) {
     $msg = $msg1 . "\n" . $msg2;
 } else {
     if ($have_file) {