1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
10	header('location: index.php');
11	exit;
12}
13
14/**
15 * @return array
16 */
17function module_quick_edit_info()
18{
19	return [
20		'name' => tra('Quick Edit'),
21		// Search actually lacks customTip, customTipTitle and headerwiki, added in r27746.
22		'description' => tra('Enables to quickly create or edit Wiki pages.') . ' ' . tra('Deprecated - use the Search module instead.'),
23		'prefs' => ['feature_wiki'],
24		'params' => [
25			'templateId' => [
26				'name' => tra('Template identifier'),
27				'description' => tra('If set to a template identifier, the specified template is used for creating new Wiki pages.') . ' ' . tra('Not set by default.')
28			],
29			'action' => [
30				'name' => 'FORM ACTION',
31				'description' => tra('If set, send the form to the given location (relative to Tiki\'s root) for processing.') . ' ' . tra('Default:') . ' tiki-editpage.php'
32			],
33			'submit' => [
34				'name' => tra('SUBMIT label'),
35				'description' => tra('The label on the button to submit the form.') . ' ' . tra('Default:') . ' ' . tra('Create/Edit')
36			],
37			'size' => [
38				'name' => tra('INPUT SIZE'),
39				'description' => tra('Size attribute (horizontal, in characters) of the text input field for page names.') . ' ' . tra('Default:') . ' 15',
40				'filter' => 'int'
41			],
42			'mod_quickedit_heading' => [
43				'name' => tra('Heading'),
44				'description' => tra('Optional heading to display at the top of the module\'s content.')
45			],
46			'addcategId' => [
47				'name' => tra('Category to preselect'),
48				'description' => tra('If set, pages created through the module have this category prechecked to be categorized in.') . ' ' . tra('Not set by default.'),
49				'profile_reference' => 'category',
50			],
51			'customTip' => [
52				'name' => tra('Tip to be shown'),
53				'description' => tra('Custom text to be shown as a tip at the top of the edit page'),
54			],
55			'customTipTitle' => [
56				'name' => tra('Title of tip to be shown'),
57				'description' => tra('Custom title to be shown for the tip at the top of the edit page'),
58			],
59			'headerwiki' => [
60				'name' => tra('Custom header template'),
61				'description' => tra('Wiki page to be used as a template to show content on top of edit page'),
62			],
63		]
64	];
65}
66
67/**
68 * @param $mod_reference
69 * @param $module_params
70 */
71function module_quick_edit($mod_reference, $module_params)
72{
73	global $prefs;
74	$smarty = TikiLib::lib('smarty');
75	$smarty->assign('tpl_module_title', tra('Quick Edit a Wiki Page'));
76
77
78	if (isset($module_params['templateId'])) {
79		$templateId = $module_params['templateId'];
80	} else {
81		$templateId = false;
82	}
83
84	if (isset($module_params['action'])) {
85		$qe_action = $module_params['action'];
86	} else {
87		$qe_action = 'tiki-editpage.php';
88	}
89
90	if (isset($module_params['submit'])) {
91		$submit = $module_params['submit'];
92	} else {
93		$submit = tra('Create/Edit', '', true);
94	}
95
96	$size = isset($module_params['size']) ? $module_params['size'] : 15;
97
98	if (isset($module_params['mod_quickedit_heading'])) {
99		$mod_quickedit_heading = $module_params['mod_quickedit_heading'];
100	} else {
101		$mod_quickedit_heading = false;
102	}
103
104	if (isset($module_params['addcategId'])) {
105		$addcategId = $module_params['addcategId'];
106	} else {
107		$addcategId = '';
108	}
109
110	if (isset($module_params['customTip'])) {
111		$customTip = $module_params['customTip'];
112	} else {
113		$customTip = '';
114	}
115
116	if (isset($module_params['customTipTitle'])) {
117		$customTipTitle = $module_params['customTipTitle'];
118	} else {
119		$customTipTitle = '';
120	}
121
122	if (isset($module_params['headerwiki'])) {
123		$wikiHeaderTpl = $module_params['headerwiki'];
124	} else {
125		$wikiHeaderTpl = '';
126	}
127
128	$smarty->assign('wikiHeaderTpl', $wikiHeaderTpl);
129	$smarty->assign('customTip', $customTip);
130	$smarty->assign('customTipTitle', $customTipTitle);
131	$smarty->assign('addcategId', $addcategId);
132	$smarty->assign('size', $size);
133	$smarty->assign('mod_quickedit_heading', $mod_quickedit_heading);
134	$smarty->assign('templateId', $templateId);
135	$smarty->assign('qe_action', $qe_action);
136	$smarty->assign('submit', $submit);
137
138	// Used for jQuery, which refers to the INPUT HTML element using an id which the following makes unique
139	static $qe_usage_counter = 0;
140	$smarty->assign('qefield', 'qe-' . ++$qe_usage_counter);
141}
142