[1] | 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 | |
---|
| 12 | require_once 'codebase/lib/RecordVersion.inc.php'; |
---|
| 13 | require_once 'codebase/lib/RecordLock.inc.php'; |
---|
| 14 | |
---|
| 15 | /****************************************************************************** |
---|
| 16 | * CODE CONFIG |
---|
| 17 | *****************************************************************************/ |
---|
| 18 | |
---|
| 19 | $version = new RecordVersion(); |
---|
| 20 | |
---|
| 21 | // These values must be kept across requests. |
---|
| 22 | $carry_queries = array('record_table', 'record_key', 'record_val', 'version_title'); |
---|
| 23 | |
---|
| 24 | // Titles and navigation header. |
---|
| 25 | $nav->addPage(_("Versions"), $_SERVER['PHP_SELF']); |
---|
| 26 | |
---|
| 27 | /****************************************************************************** |
---|
| 28 | * MAIN |
---|
| 29 | *****************************************************************************/ |
---|
| 30 | |
---|
| 31 | // Request arguments. |
---|
| 32 | $version_id = getFormData('version_id'); |
---|
| 33 | $record_table = getFormData('record_table'); |
---|
| 34 | $record_key = getFormData('record_key'); |
---|
| 35 | $record_val = getFormData('record_val'); |
---|
| 36 | |
---|
| 37 | if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) { |
---|
| 38 | App::raiseMsg(_("Record not specified for versioning."), MSG_WARNING, __FILE__, __LINE__); |
---|
| 39 | App::logMsg('Record not specified for versioning.', LOG_WARNING, __FILE__, __LINE__); |
---|
| 40 | App::dieBoomerangURL(); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | if (getFormData('boomerang', false)) { |
---|
| 44 | // We remember which page we came from so we can go back there. |
---|
| 45 | App::setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions'); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | // What action to take. |
---|
| 49 | switch (getFormData('op')) { |
---|
| 50 | |
---|
| 51 | case _("Cancel") : |
---|
| 52 | App::dieBoomerangURL('versions', false); |
---|
| 53 | break; |
---|
| 54 | |
---|
| 55 | case 'view' : |
---|
| 56 | $data = $version->getData($version_id); |
---|
| 57 | $versionrecord = $version->getVerson($version_id); |
---|
| 58 | $nav->addPage(sprintf(_("View <em>%s</em> version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime'])); |
---|
| 59 | $main_template = 'versions_view.ihtml'; |
---|
| 60 | break; |
---|
| 61 | |
---|
| 62 | case 'diff' : |
---|
| 63 | $data = $version->getData($version_id); |
---|
| 64 | $versionrecord = $version->getVerson($version_id); |
---|
| 65 | $current = $version->getCurrent($record_table, $record_key, $record_val); |
---|
| 66 | if (serialize($data) == serialize($current)) { |
---|
| 67 | App::raiseMsg(sprintf(_("Version <strong>%s</strong> is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__); |
---|
| 68 | } |
---|
| 69 | $nav->addPage(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime'])); |
---|
| 70 | $main_template = 'versions_diff.ihtml'; |
---|
| 71 | break; |
---|
| 72 | |
---|
| 73 | case 'restore' : |
---|
| 74 | $lock =& RecordLock::getInstance($GLOBALS['auth']); |
---|
| 75 | $lock->select($record_table, $record_key, $record_val); |
---|
| 76 | if ($lock->isLocked() && !$lock->isMine()) { |
---|
| 77 | $lock->dieErrorPage(); |
---|
| 78 | } else { |
---|
| 79 | if ($v = $version->restore($version_id)) { |
---|
| 80 | // Create version of this restored record as the "current" version. |
---|
| 81 | $version->create($record_table, $record_key, $record_val, $v['version_title']); |
---|
| 82 | App::raiseMsg(sprintf(_("The record <strong>%s</strong> has been replaced with <strong>%s</strong> version <strong>%s</strong> from <strong>%s</strong>."), getFormData('version_title'), $v['version_title'], $version_id, $v['version_datetime']), MSG_SUCCESS, __FILE__, __LINE__); |
---|
| 83 | App::dieBoomerangURL('versions', array('break_list_cache'=>'true', false)); |
---|
| 84 | } else { |
---|
| 85 | App::raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__); |
---|
| 86 | App::dieURL($_SERVER['PHP_SELF']); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | break; |
---|
| 90 | |
---|
| 91 | default : |
---|
| 92 | $versions = $version->getList($record_table, $record_key, $record_val); |
---|
| 93 | $_POST['version_title'] = $versions[0]['version_title']; |
---|
| 94 | if (is_array($versions) && !empty($versions)) { |
---|
| 95 | $nav->addPage(sprintf(_("%s versions of record <em>%s</em>"), sizeof($versions), $versions[0]['version_title'])); |
---|
| 96 | $main_template = 'versions_list.ihtml'; |
---|
| 97 | } else { |
---|
| 98 | App::raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__); |
---|
| 99 | App::dieBoomerangURL('versions'); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | /****************************************************************************** |
---|
| 105 | * TEMPLATE INITIALIZATION |
---|
| 106 | *****************************************************************************/ |
---|
| 107 | |
---|
| 108 | include 'header.ihtml'; |
---|
| 109 | include 'codebase/services/templates/' . $main_template; |
---|
| 110 | include 'footer.ihtml'; |
---|
| 111 | |
---|
| 112 | ?> |
---|