|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Infolog - document merge |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://www.egroupware.org |
|
6
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
|
7
|
|
|
* @author Nathan Gray |
|
8
|
|
|
* @package infolog |
|
9
|
|
|
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de> |
|
10
|
|
|
* @copyright 2011 Nathan Gray |
|
11
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
|
12
|
|
|
* @version $Id$ |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
use EGroupware\Api; |
|
16
|
|
|
use EGroupware\Api\Link; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Infolog - document merge object |
|
20
|
|
|
*/ |
|
21
|
|
|
class infolog_merge extends Api\Storage\Merge |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Functions that can be called via menuaction |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
var $public_functions = array( |
|
29
|
|
|
'download_by_request' => true, |
|
30
|
|
|
'show_replacements' => true, |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Business object to pull records from |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $bo = null; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Constructor |
|
40
|
|
|
* |
|
41
|
|
|
*/ |
|
42
|
|
|
function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
parent::__construct(); |
|
45
|
|
|
$this->bo = new infolog_bo(); |
|
46
|
|
|
|
|
47
|
|
|
$this->date_fields += array( |
|
48
|
|
|
'info_startdate', |
|
49
|
|
|
'info_enddate', |
|
50
|
|
|
'info_datecompleted', |
|
51
|
|
|
'info_datemodified', |
|
52
|
|
|
'info_created', |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
// switch of handling of Api\Html formated content, if Api\Html is not used |
|
56
|
|
|
$this->parse_html_styles = Api\Storage\Customfields::use_html('infolog'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get infolog replacements |
|
61
|
|
|
* |
|
62
|
|
|
* @param int $id id of entry |
|
63
|
|
|
* @param string &$content=null content to create some replacements only if they are use |
|
64
|
|
|
* @return array|boolean |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function get_replacements($id,&$content=null) |
|
67
|
|
|
{ |
|
68
|
|
|
if (!($replacements = $this->infolog_replacements($id, '', $content))) |
|
69
|
|
|
{ |
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
return $replacements; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get infolog replacements |
|
77
|
|
|
* |
|
78
|
|
|
* @param int $id id of entry |
|
79
|
|
|
* @param string $prefix='' prefix like eg. 'erole' |
|
80
|
|
|
* @return array|boolean |
|
81
|
|
|
*/ |
|
82
|
|
|
public function infolog_replacements($id,$prefix='', &$content = '') |
|
83
|
|
|
{ |
|
84
|
|
|
$record = new infolog_egw_record($id); |
|
85
|
|
|
$info = array(); |
|
86
|
|
|
|
|
87
|
|
|
// Convert to human friendly values |
|
88
|
|
|
$types = infolog_egw_record::$types; |
|
89
|
|
|
$_selects = $this->bo->enums + array('status' => $this->bo->status[$record->info_type]); |
|
|
|
|
|
|
90
|
|
|
foreach($_selects as $name => $value) |
|
91
|
|
|
{ |
|
92
|
|
|
$selects['info_'.$name] = $value; |
|
93
|
|
|
if(!in_array('info_'.$name, $types['select'])) $types['select'][] = 'info_'.$name; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if($content && strpos($content, '$$#') !== FALSE) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->cf_link_to_expand($record->get_record_array(), $content, $info); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
importexport_export_csv::convert($record, $types, 'infolog', $selects); |
|
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
$array = $record->get_record_array(); |
|
104
|
|
|
if($record->info_contact) |
|
105
|
|
|
{ |
|
106
|
|
|
$array['info_contact'] = $array['info_link']['title']; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// Set any missing custom fields, or the marker will stay |
|
110
|
|
|
foreach($this->bo->customfields as $name => $field) |
|
111
|
|
|
{ |
|
112
|
|
|
if(!$array['#'.$name]) |
|
113
|
|
|
{ |
|
114
|
|
|
$array['#'.$name] = ''; |
|
115
|
|
|
} |
|
116
|
|
|
// Format date cfs per user Api\Preferences |
|
117
|
|
|
if($array['#'.$name] && ($field['type'] == 'date' || $field['type'] == 'date-time')) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->date_fields[] = '#'.$name; |
|
120
|
|
|
$array['#'.$name] = Api\DateTime::to($array['#'.$name], $field['type'] == 'date' ? true : ''); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
// Timesheet time |
|
125
|
|
|
if(strpos($content, 'info_sum_timesheets')) |
|
126
|
|
|
{ |
|
127
|
|
|
$links = Link::get_links('infolog',$id,'timesheet'); |
|
128
|
|
|
$sum = ExecMethod('timesheet.timesheet_bo.sum',$links); |
|
|
|
|
|
|
129
|
|
|
$info['$$info_sum_timesheets$$'] = $sum['duration']; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
// Check for linked project ID |
|
133
|
|
|
$links = Link::get_links('infolog', $id, 'projectmanager'); |
|
134
|
|
|
foreach($links as $app_id) |
|
135
|
|
|
{ |
|
136
|
|
|
$array['pm_id'] = $app_id; |
|
137
|
|
|
$array['project'] = Link::title('projectmanager', $app_id); |
|
138
|
|
|
break; |
|
139
|
|
|
} |
|
140
|
|
|
if (strpos($content, '$$project/') !== false && $array['pm_id'] && class_exists('projectmanager_merge')) |
|
141
|
|
|
{ |
|
142
|
|
|
$pm_merge = new projectmanager_merge($array['pm_id']); |
|
|
|
|
|
|
143
|
|
|
$info += $pm_merge->projectmanager_replacements($array['pm_id'],'project',$content); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
// Add markers |
|
147
|
|
|
foreach($array as $key => &$value) |
|
148
|
|
|
{ |
|
149
|
|
|
if(!$value) $value = ''; |
|
150
|
|
|
$info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
// Links |
|
154
|
|
|
$info += $this->get_all_links('infolog', $id, $prefix, $content); |
|
155
|
|
|
|
|
156
|
|
|
// Add contact fields |
|
157
|
|
|
if($array['info_link'] && $array['info_link']['app'] && $array['info_link']['id']) |
|
158
|
|
|
{ |
|
159
|
|
|
$info+=$this->get_app_replacements($array['info_link']['app'], $array['info_link']['id'], $content, 'info_contact'); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
// Add parent |
|
163
|
|
|
if($record->info_id_parent) |
|
164
|
|
|
{ |
|
165
|
|
|
$info += $this->infolog_replacements($record->info_id_parent, 'info_id_parent', $content); |
|
166
|
|
|
} |
|
167
|
|
|
return $info; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Generate table with replacements for the Api\Preferences |
|
172
|
|
|
* |
|
173
|
|
|
*/ |
|
174
|
|
|
public function show_replacements() |
|
175
|
|
|
{ |
|
176
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('infolog').' - '.lang('Replacements for inserting entries into documents'); |
|
177
|
|
|
$GLOBALS['egw_info']['flags']['nonavbar'] = false; |
|
178
|
|
|
echo $GLOBALS['egw']->framework->header(); |
|
179
|
|
|
|
|
180
|
|
|
echo "<table width='90%' align='center'>\n"; |
|
181
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Infolog fields:')."</h3></td></tr>"; |
|
182
|
|
|
|
|
183
|
|
|
$n = 0; |
|
184
|
|
|
$tracking = new infolog_tracking($this->bo); |
|
185
|
|
|
$fields = array('info_id' => lang('Infolog ID'), 'pm_id' => lang('Project ID'), 'project' => lang('Project name')) + $tracking->field2label + array('info_sum_timesheets' => lang('Used time')); |
|
186
|
|
|
Api\Translation::add_app('projectmanager'); |
|
187
|
|
|
foreach($fields as $name => $label) |
|
188
|
|
|
{ |
|
189
|
|
|
if (in_array($name,array('custom'))) continue; // dont show them |
|
190
|
|
|
|
|
191
|
|
|
if (in_array($name,array('info_subject', 'info_des')) && $n&1) // main values, which should be in the first column |
|
192
|
|
|
{ |
|
193
|
|
|
echo "</tr>\n"; |
|
194
|
|
|
$n++; |
|
195
|
|
|
} |
|
196
|
|
|
if (!($n&1)) echo '<tr>'; |
|
197
|
|
|
echo '<td>{{'.$name.'}}</td><td>'.lang($label).'</td>'; |
|
198
|
|
|
if ($n&1) echo "</tr>\n"; |
|
199
|
|
|
$n++; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>"; |
|
203
|
|
|
$contact_custom = false; |
|
204
|
|
|
foreach($this->bo->customfields as $name => $field) |
|
205
|
|
|
{ |
|
206
|
|
|
echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label'].($field['type'] == 'select-account' ? '*':'')."</td></tr>\n"; |
|
207
|
|
|
if($field['type'] == 'select-account') $contact_custom = true; |
|
208
|
|
|
} |
|
209
|
|
|
if($contact_custom) |
|
210
|
|
|
{ |
|
211
|
|
|
echo '<tr><td /><td colspan="3">* '.lang('Addressbook placeholders available'). '</td></tr>'; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Parent').":</h3></td></tr>"; |
|
215
|
|
|
echo '<tr><td>{{info_id_parent/info_subject}}</td><td colspan="3">'.lang('All other %1 fields are valid',lang('infolog'))."</td></tr>\n"; |
|
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Contact fields').':</h3></td></tr>'; |
|
218
|
|
|
$i = 0; |
|
219
|
|
|
foreach($this->contacts->contact_fields as $name => $label) |
|
220
|
|
|
{ |
|
221
|
|
|
if (in_array($name,array('tid','label','geo'))) continue; // dont show them, as they are not used in the UI atm. |
|
222
|
|
|
|
|
223
|
|
|
if (in_array($name,array('email','org_name','tel_work','url')) && $n&1) // main values, which should be in the first column |
|
224
|
|
|
{ |
|
225
|
|
|
echo "</tr>\n"; |
|
226
|
|
|
$i++; |
|
227
|
|
|
} |
|
228
|
|
|
if (!($i&1)) echo '<tr>'; |
|
229
|
|
|
echo '<td>{{info_contact/'.$name.'}}</td><td>'.$label.'</td>'; |
|
230
|
|
|
if ($i&1) echo "</tr>\n"; |
|
231
|
|
|
$i++; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>"; |
|
235
|
|
|
foreach($this->contacts->customfields as $name => $field) |
|
236
|
|
|
{ |
|
237
|
|
|
echo '<tr><td>{{info_contact/#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n"; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>"; |
|
241
|
|
|
foreach(array( |
|
242
|
|
|
'link' => lang('HTML link to the current record'), |
|
243
|
|
|
'links' => lang('Titles of any entries linked to the current record, excluding attached files'), |
|
244
|
|
|
'attachments' => lang('List of files linked to the current record'), |
|
245
|
|
|
'links_attachments' => lang('Links and attached files'), |
|
246
|
|
|
'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'), |
|
247
|
|
|
'links/href' => lang('Links wrapped in an HREF tag with download link'), |
|
248
|
|
|
'links/link' => lang('Download url for links'), |
|
249
|
|
|
'date' => lang('Date'), |
|
250
|
|
|
'user/n_fn' => lang('Name of current user, all other contact fields are valid too'), |
|
251
|
|
|
'user/account_lid' => lang('Username'), |
|
252
|
|
|
'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'), |
|
253
|
|
|
'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'), |
|
254
|
|
|
'labelplacement' => lang('Tag to mark positions for address labels'), |
|
255
|
|
|
'IF fieldname' => lang('Example {{IF n_prefix~Mr~Hello Mr.~Hello Ms.}} - search the field "n_prefix", for "Mr", if found, write Hello Mr., else write Hello Ms.'), |
|
256
|
|
|
'NELF' => lang('Example {{NELF role}} - if field role is not empty, you will get a new line with the value of field role'), |
|
257
|
|
|
'NENVLF' => lang('Example {{NENVLF role}} - if field role is not empty, set a LF without any value of the field'), |
|
258
|
|
|
'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is emty for example'), |
|
259
|
|
|
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'), |
|
260
|
|
|
) as $name => $label) |
|
261
|
|
|
{ |
|
262
|
|
|
echo '<tr><td>{{'.$name.'}}</td><td colspan="3">'.$label."</td></tr>\n"; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
echo "</table>\n"; |
|
266
|
|
|
|
|
267
|
|
|
echo $GLOBALS['egw']->framework->footer(); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|