[1] | 1 | <?php |
---|
| 2 | /** |
---|
[42] | 3 | * versions.php |
---|
[1] | 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(); |
---|
[136] | 10 | $app->sslOn(); |
---|
[1] | 11 | |
---|
[137] | 12 | require_once 'codebase/lib/Version.inc.php'; |
---|
| 13 | require_once 'codebase/lib/Lock.inc.php'; |
---|
[1] | 14 | |
---|
| 15 | /****************************************************************************** |
---|
| 16 | * CODE CONFIG |
---|
| 17 | *****************************************************************************/ |
---|
| 18 | |
---|
[159] | 19 | $version = Version::getInstance($auth); |
---|
[1] | 20 | |
---|
[20] | 21 | // Query arguments to retain their values between page requests. |
---|
[136] | 22 | $app->carryQuery('record_table'); |
---|
| 23 | $app->carryQuery('record_key'); |
---|
| 24 | $app->carryQuery('record_val'); |
---|
| 25 | $app->carryQuery('version_title'); |
---|
[1] | 26 | |
---|
| 27 | // Titles and navigation header. |
---|
[202] | 28 | $nav->add(_("Versions"), null); |
---|
[1] | 29 | |
---|
[143] | 30 | /******************************************************************** |
---|
| 31 | * MAIN |
---|
| 32 | ********************************************************************/ |
---|
[1] | 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 | |
---|
| 40 | if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) { |
---|
[136] | 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(); |
---|
[1] | 44 | } |
---|
| 45 | |
---|
[20] | 46 | if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) { |
---|
[1] | 47 | // We remember which page we came from so we can go back there. |
---|
[136] | 48 | $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions'); |
---|
[1] | 49 | } |
---|
| 50 | |
---|
| 51 | // What action to take. |
---|
| 52 | switch (getFormData('op')) { |
---|
| 53 | |
---|
| 54 | case _("Cancel") : |
---|
[136] | 55 | $app->dieBoomerangURL('versions', false); |
---|
[1] | 56 | break; |
---|
| 57 | |
---|
| 58 | case 'view' : |
---|
| 59 | $data = $version->getData($version_id); |
---|
| 60 | $versionrecord = $version->getVerson($version_id); |
---|
[202] | 61 | $nav->add(sprintf(_("View <em>%s</em> version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime'])); |
---|
[1] | 62 | $main_template = 'versions_view.ihtml'; |
---|
| 63 | break; |
---|
| 64 | |
---|
| 65 | case '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)) { |
---|
[141] | 70 | $app->raiseMsg(sprintf(_("Version <em>%s</em> is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__); |
---|
[1] | 71 | } |
---|
[202] | 72 | $nav->add(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime'])); |
---|
[1] | 73 | $main_template = 'versions_diff.ihtml'; |
---|
| 74 | break; |
---|
| 75 | |
---|
| 76 | case 'restore' : |
---|
[137] | 77 | if (!isset($lock) || !is_a($lock, 'Lock')) { |
---|
| 78 | $lock =& Lock::getInstance($auth); |
---|
[22] | 79 | } |
---|
[1] | 80 | $lock->select($record_table, $record_key, $record_val); |
---|
| 81 | if ($lock->isLocked() && !$lock->isMine()) { |
---|
| 82 | $lock->dieErrorPage(); |
---|
[21] | 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']); |
---|
[141] | 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__); |
---|
[136] | 89 | $app->dieBoomerangURL('versions', array('break_list_cache'=>'true', false)); |
---|
[1] | 90 | } else { |
---|
[136] | 91 | $app->raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__); |
---|
| 92 | $app->dieURL($_SERVER['PHP_SELF']); |
---|
[1] | 93 | } |
---|
| 94 | break; |
---|
| 95 | |
---|
| 96 | default : |
---|
| 97 | $versions = $version->getList($record_table, $record_key, $record_val); |
---|
| 98 | if (is_array($versions) && !empty($versions)) { |
---|
[255] | 99 | $_POST['version_title'] = $versions[0]['version_title']; |
---|
[202] | 100 | $nav->add(sprintf(_("%s versions of record <em>%s</em>"), sizeof($versions), $versions[0]['version_title'])); |
---|
[1] | 101 | $main_template = 'versions_list.ihtml'; |
---|
| 102 | } else { |
---|
[136] | 103 | $app->raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__); |
---|
| 104 | $app->dieBoomerangURL('versions'); |
---|
[1] | 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | /****************************************************************************** |
---|
| 110 | * TEMPLATE INITIALIZATION |
---|
| 111 | *****************************************************************************/ |
---|
[42] | 112 | |
---|
[1] | 113 | include 'header.ihtml'; |
---|
| 114 | include 'codebase/services/templates/' . $main_template; |
---|
| 115 | include 'footer.ihtml'; |
---|
| 116 | |
---|
| 117 | ?> |
---|