tiki-references.php 2.72 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
10 11 12

require_once ('tiki-setup.php');
$access->check_feature('feature_references');
13
$access->check_permission(array('tiki_p_edit_references'), tra('Edit Library References'));
14 15

global $dbTiki;
16
$referenceslib = TikiLib::lib('references');
17 18

$smarty->assign('page', $_REQUEST["page"]);
19
$page = $_REQUEST['page'];
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

$page_id = TikiLib::lib('tiki')->get_page_id_from_name($page);
$action = $_REQUEST['action'];
$ref_id = $_REQUEST['referenceId'];
$ref_biblio_code = $_REQUEST['ref_biblio_code'];
$ref_author = $_REQUEST['ref_author'];
$ref_title = $_REQUEST['ref_title'];
$ref_part = $_REQUEST['ref_part'];
$ref_uri = $_REQUEST['ref_uri'];
$ref_code = $_REQUEST['ref_code'];
$ref_publisher = $_REQUEST['ref_publisher'];
$ref_location = $_REQUEST['ref_location'];
$ref_year = $_REQUEST['ref_year'];
$ref_style = $_REQUEST['ref_style'];
$ref_template = $_REQUEST['ref_template'];

if (isset($_REQUEST['addreference'])) {
	$errors = array();
38

39
	if ($ref_biblio_code == '') {
40 41 42 43
		$errors[] = 'Please enter Biblio Code.';
	}

	$exists = $referenceslib->check_lib_existence($ref_biblio_code);
arildb's avatar
arildb committed
44
	if ($exists > 0) {
45 46 47
		$errors[] = 'This reference already exists.';
	}

48
	if (count($errors) < 1) {
49
		$id = $referenceslib->add_reference(
50 51 52 53 54 55 56 57 58 59 60
			$ref_biblio_code,
			$ref_author,
			$ref_title,
			$ref_part,
			$ref_uri,
			$ref_code,
			$ref_year,
			$ref_style,
			$ref_template,
			$ref_publisher,
			$ref_location
61
		);
62
	} else {
arildb's avatar
arildb committed
63
		foreach ($errors as $error) {
64 65 66 67 68 69 70 71 72 73
			$msg .= tra($error);
		}
		$access->display_error(basename(__FILE__), $msg);
	}
}

if (isset($_REQUEST['editreference'])) {

	$errors = array();

74
	if ($ref_id == '') {
75 76
		$errors[] = 'Reference not found.';
	}
77
	if ($ref_biblio_code == '') {
78 79 80
		$errors[] = 'Please enter Biblio Code.';
	}

81
	if (count($errors) < 1) {
82
		$referenceslib->edit_reference(
83 84 85 86 87 88 89 90 91 92 93 94
			$ref_id,
			$ref_biblio_code,
			$ref_author,
			$ref_title,
			$ref_part,
			$ref_uri,
			$ref_code,
			$ref_year,
			$ref_style,
			$ref_template,
			$ref_publisher,
			$ref_location
95
		);
96
	} else {
arildb's avatar
arildb committed
97
		foreach ($errors as $error) {
98 99 100 101 102 103 104 105 106
			$msg .= tra($error);
		}
		$access->display_error(basename(__FILE__), $msg);
	}
}

if (isset($_REQUEST['action']) && isset($ref_id)) {
	if ($_REQUEST['action'] == 'delete') {
		$access->check_authenticity();
107
		$referenceslib->remove_reference($ref_id);
108 109 110 111
	}
}

$references = $referenceslib->list_lib_references();
112
$smarty->assign('references', $references['data']);
113 114

// Display the template
115
$smarty->assign('mid', 'tiki-references.tpl');
116
$smarty->display('tiki.tpl');