/** * Saves $plan as this user's plan. * @param plan Text to save. * @param archive Archive settings for this plan. * @param timestamp Timestamp to save archive with. * @public */ function setPlan($plan, $archive = 'N', $name = '', $timestamp = null) { if (!isset($timestamp)) { $timestamp = mktime(); } /* save it in the archives */ if ($archive == 'P' || $archive == 'Y') { $success = ARCHIVE_OK == Archive::saveEntry($this->userID, $timestamp, addslashes($plan), addslashes(htmlspecialchars($name)), $archive == 'Y' ? true : false); } else { $success = true; } $oldplan = $this->getPlan($this); $query = "DELETE FROM plans WHERE uid=" . $this->userID; $success = $success && !DB::isError($this->dbh->query($query)); /* format the journalled plan */ if ($this->getPreference('journal')) { if (!($divider = $this->getPreference('journal_divider'))) { $divider = PW_DIVIDER; } if ($this->getPreference('journal_order') == 'new') { $tmp = ''; for ($i = 0; $i < $this->getPreference('journal_entries'); $i++) { list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i); if ($ts == 0) { break; } $tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n"; $tmp .= $txt . "\n"; } $plan = $tmp; } else { $tmp = ''; for ($i = $this->getPreference('journal_entries') - 1; $i >= 0; $i--) { list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i); if ($ts == 0) { break; } $tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n"; $tmp .= $txt . "\n"; } $plan = $tmp; } } /* process snoop references */ $success = $success && Snoop::process($this, $plan, $oldplan); $success = $success && $this->deleteDrafts(); /* save the plan */ $query = "INSERT INTO plans (uid, content) VALUES (" . $this->userID . ", '" . addslashes($plan) . "')"; return $success && !DB::isError($this->dbh->query($query)); }