2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
31 import('ttProjectHelper');
32 import('ttGroupHelper');
33 import('ttFileHelper');
34 import('ttWorkHelper');
37 if (!ttAccessAllowed('manage_work')) {
38 header('Location: access_denied.php');
41 if (!$user->isPluginEnabled('wk')) {
42 header('Location: feature_disabled.php');
45 // End of access checks.
47 $showFiles = $user->isPluginEnabled('at');
49 if ($request->isPost()) {
50 $cl_name = trim($request->getParameter('work_name'));
51 $cl_description = trim($request->getParameter('description'));
52 $cl_currency = $request->getParameter('currency');
55 $form = new Form('workForm');
56 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'work_name','style'=>'width: 250px;','value'=>$cl_name));
57 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
59 $form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit')));
60 // Add a dropdown for currency.
61 $currencies = ttWorkHelper::getCurrencies();
62 $form->addInput(array('type'=>'combobox','name'=>'currency','data'=>$currencies,'datakeys'=>array('id','name'),'value'=>$cl_currency));
64 // TODO: design how to handle one-time vs ongoing work. Apparently, with a conditional display of relevant controls.
65 // Ongoing work - rate per hour control.
66 // One-time work - budget dropdown control.
67 // When selection changes, we hide and show required controls.
69 // TODO: design how to handle categories and sub-categories.
70 // One major complication is localization of names.
72 // Coding and design are currently ongoing.
75 if ($request->isPost()) {
76 // Validate user input.
77 if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
78 if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
79 if (!ttGroupHelper::validateCheckboxGroupInput($cl_users, 'tt_users')) $err->add($i18n->get('error.field'), $i18n->get('label.users'));
80 if (!ttGroupHelper::validateCheckboxGroupInput($cl_tasks, 'tt_tasks')) $err->add($i18n->get('error.field'), $i18n->get('label.tasks'));
83 if (!ttProjectHelper::getProjectByName($cl_name)) {
84 $id = ttProjectHelper::insert(array('name' => $cl_name,
85 'description' => $cl_description,
90 // Put a new file in storage if we have it.
91 if ($id && $showFiles && $_FILES['newfile']['name']) {
92 $fileHelper = new ttFileHelper($err);
93 $fields = array('entity_type'=>'project',
95 'file_name' => $_FILES['newfile']['name']);
96 $fileHelper->putFile($fields);
99 header('Location: projects.php');
102 $err->add($i18n->get('error.db'));
104 $err->add($i18n->get('error.object_exists'));
108 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
109 $smarty->assign('onload', 'onLoad="document.projectForm.project_name.focus()"');
110 $smarty->assign('show_files', $showFiles);
111 $smarty->assign('show_users', count($users) > 0);
112 $smarty->assign('show_tasks', $show_tasks);
113 $smarty->assign('title', $i18n->get('title.add_work'));
114 $smarty->assign('content_page_name', 'work_add.tpl');
115 $smarty->display('index.tpl');