forked from Ben0it-T/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate_add.php
More file actions
71 lines (63 loc) · 2.94 KB
/
template_add.php
File metadata and controls
71 lines (63 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/* Copyright (c) Anuko International Ltd. https://www.anuko.com
License: See license.txt */
require_once('initialize.php');
import('form.Form');
import('ttTemplateHelper');
// Access checks.
if (!ttAccessAllowed('manage_advanced_settings')) {
header('Location: access_denied.php');
exit();
}
if (!$user->isPluginEnabled('tp')) {
header('Location: feature_disabled.php');
exit();
}
// End of access checks.
$config = new ttConfigHelper($user->getConfig());
$bindTemplatesWithProjects = $config->getDefinedValue('bind_templates_with_projects');
$projects = $cl_projects = array();
if ($bindTemplatesWithProjects)
$projects = ttGroupHelper::getActiveProjects();
$cl_name = $cl_description = $cl_content = null;
if ($request->isPost()) {
$cl_name = is_null($request->getParameter('name')) ? '' : trim($request->getParameter('name'));
$cl_description = is_null($request->getParameter('description')) ? '' : trim($request->getParameter('description'));
$cl_content = is_null($request->getParameter('content')) ? '' : trim($request->getParameter('content'));
$cl_projects = $request->getParameter('projects');
} else {
if ($bindTemplatesWithProjects) {
foreach ($projects as $project_item)
$cl_projects[] = $project_item['id'];
}
}
$form = new Form('templateForm');
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name));
$form->addInput(array('type'=>'textarea','name'=>'description','value'=>$cl_description));
$form->addInput(array('type'=>'textarea','name'=>'content','value'=>$cl_content));
$form->addInput(array('type'=>'checkboxgroup','name'=>'projects','layout'=>'H','data'=>$projects,'datakeys'=>array('id','name'),'value'=>$cl_projects));
$form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->get('button.add')));
if ($request->isPost()) {
// Validate user input.
if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
if (!ttValidString($cl_content)) $err->add($i18n->get('error.field'), $i18n->get('label.template'));
if (!ttGroupHelper::validateCheckboxGroupInput($cl_projects, 'tt_projects')) $err->add($i18n->get('error.field'), $i18n->get('label.projects'));
// Finished validating user input.
if ($err->no()) {
if (ttTemplateHelper::insert(array(
'name' => $cl_name,
'description' => $cl_description,
'content' => $cl_content,
'projects' => $cl_projects))) {
header('Location: templates.php');
exit();
} else
$err->add($i18n->get('error.db'));
}
} // isPost
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('show_projects', $bindTemplatesWithProjects && count($projects) > 0);
$smarty->assign('title', $i18n->get('title.add_template'));
$smarty->assign('content_page_name', 'template_add.tpl');
$smarty->display('index.tpl');