source: trunk/services/versions.php @ 255

Last change on this file since 255 was 255, checked in by jordan, 17 years ago

Bugs fixed via Jordan.

File size: 4.4 KB
Line 
1<?php
2/**
3 * versions.php
4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
5 */
6
7// require_once dirname(__FILE__) . '/_config.inc.php';
8
9$auth->requireLogin();
10$app->sslOn();
11
12require_once 'codebase/lib/Version.inc.php';
13require_once 'codebase/lib/Lock.inc.php';
14
15/******************************************************************************
16 * CODE CONFIG
17 *****************************************************************************/
18
19$version = Version::getInstance($auth);
20
21// Query arguments to retain their values between page requests.
22$app->carryQuery('record_table');
23$app->carryQuery('record_key');
24$app->carryQuery('record_val');
25$app->carryQuery('version_title');
26
27// Titles and navigation header.
28$nav->add(_("Versions"), null);
29
30/********************************************************************
31* MAIN
32********************************************************************/
33
34// Request arguments.
35$version_id = getFormData('version_id');
36$record_table = getFormData('record_table');
37$record_key = getFormData('record_key');
38$record_val = getFormData('record_val');
39
40if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) {
41    $app->raiseMsg(_("Record not specified for versioning."), MSG_WARNING, __FILE__, __LINE__);
42    $app->logMsg('Record not specified for versioning.', LOG_WARNING, __FILE__, __LINE__);
43    $app->dieBoomerangURL();
44}
45
46if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
47    // We remember which page we came from so we can go back there.
48    $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions');
49}
50
51// What action to take.
52switch (getFormData('op')) {
53
54case _("Cancel") :
55    $app->dieBoomerangURL('versions', false);
56    break;
57
58case 'view' :
59    $data = $version->getData($version_id);
60    $versionrecord = $version->getVerson($version_id);
61    $nav->add(sprintf(_("View <em>%s</em> version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime']));
62    $main_template = 'versions_view.ihtml';
63    break;
64
65case 'diff' :
66    $data = $version->getData($version_id);
67    $versionrecord = $version->getVerson($version_id);
68    $current = $version->getCurrent($record_table, $record_key, $record_val);
69    if (serialize($data) == serialize($current)) {
70        $app->raiseMsg(sprintf(_("Version <em>%s</em> is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__);
71    }
72    $nav->add(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime']));
73    $main_template = 'versions_diff.ihtml';
74    break;
75
76case 'restore' :
77    if (!isset($lock) || !is_a($lock, 'Lock')) {
78        $lock =& Lock::getInstance($auth);
79    }
80    $lock->select($record_table, $record_key, $record_val);
81    if ($lock->isLocked() && !$lock->isMine()) {
82        $lock->dieErrorPage();
83    }
84
85    if ($v = $version->restore($version_id)) {
86        // Create version of this restored record as the "current" version.
87        $version->create($record_table, $record_key, $record_val, $v['version_title']);
88        $app->raiseMsg(sprintf(_("The record <em>%s</em> has been replaced with <em>%s</em> version <em>%s</em> from <em>%s</em>."), getFormData('version_title'), $v['version_title'], $version_id, $v['version_datetime']), MSG_SUCCESS, __FILE__, __LINE__);
89        $app->dieBoomerangURL('versions', array('break_list_cache'=>'true', false));
90    } else {
91        $app->raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__);
92        $app->dieURL($_SERVER['PHP_SELF']);
93    }
94    break;
95
96default :
97    $versions = $version->getList($record_table, $record_key, $record_val);
98    if (is_array($versions) && !empty($versions)) {
99        $_POST['version_title'] = $versions[0]['version_title'];
100        $nav->add(sprintf(_("%s versions of record <em>%s</em>"), sizeof($versions), $versions[0]['version_title']));
101        $main_template = 'versions_list.ihtml';
102    } else {
103        $app->raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__);
104        $app->dieBoomerangURL('versions');
105    }
106}
107
108
109/******************************************************************************
110 * TEMPLATE INITIALIZATION
111 *****************************************************************************/
112
113include 'header.ihtml';
114include 'codebase/services/templates/' . $main_template;
115include 'footer.ihtml';
116
117?>
Note: See TracBrowser for help on using the repository browser.