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('ttTeamHelper');
35 if (!ttAccessAllowed('manage_projects')) {
36 header('Location: access_denied.php');
39 if (MODE_PROJECTS != $user->tracking_mode && MODE_PROJECTS_AND_TASKS != $user->tracking_mode) {
40 header('Location: feature_disabled.php');
43 $cl_project_id = (int)$request->getParameter('id');
44 $project = ttProjectHelper::get($cl_project_id);
46 header('Location: access_denied.php');
49 // End of access checks.
51 $users = ttTeamHelper::getActiveUsers();
52 foreach ($users as $user_item)
53 $all_users[$user_item['id']] = $user_item['name'];
55 $tasks = ttTeamHelper::getActiveTasks($user->getGroup());
56 foreach ($tasks as $task_item)
57 $all_tasks[$task_item['id']] = $task_item['name'];
59 if ($request->isPost()) {
60 $cl_name = trim($request->getParameter('project_name'));
61 $cl_description = trim($request->getParameter('description'));
62 $cl_status = $request->getParameter('status');
63 $cl_users = $request->getParameter('users', array());
64 $cl_tasks = $request->getParameter('tasks', array());
66 $cl_name = $project['name'];
67 $cl_description = $project['description'];
68 $cl_status = $project['status'];
70 $mdb2 = getConnection();
71 $sql = "select user_id from tt_user_project_binds where status = 1 and project_id = $cl_project_id";
72 $res = $mdb2->query($sql);
73 if (is_a($res, 'PEAR_Error'))
74 die($res->getMessage());
75 while ($row = $res->fetchRow())
76 $cl_users[] = $row['user_id'];
78 $cl_tasks = explode(',', $project['tasks']);
81 $form = new Form('projectForm');
82 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_project_id));
83 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'project_name','style'=>'width: 250px;','value'=>$cl_name));
84 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
85 $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status,
86 'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive'))));
87 $form->addInput(array('type'=>'checkboxgroup','name'=>'users','data'=>$all_users,'layout'=>'H','value'=>$cl_users));
88 if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
89 $form->addInput(array('type'=>'checkboxgroup','name'=>'tasks','data'=>$all_tasks,'layout'=>'H','value'=>$cl_tasks));
90 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
91 $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->get('button.copy')));
93 if ($request->isPost()) {
94 // Validate user input.
95 if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
96 if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
99 if ($request->getParameter('btn_save')) {
100 $existing_project = ttProjectHelper::getProjectByName($cl_name);
101 if (!$existing_project || ($cl_project_id == $existing_project['id'])) {
102 // Update project information.
103 if (ttProjectHelper::update(array(
104 'id' => $cl_project_id,
106 'description' => $cl_description,
107 'status' => $cl_status,
108 'users' => $cl_users,
109 'tasks' => $cl_tasks))) {
110 header('Location: projects.php');
113 $err->add($i18n->get('error.db'));
115 $err->add($i18n->get('error.object_exists'));
118 if ($request->getParameter('btn_copy')) {
119 if (!ttProjectHelper::getProjectByName($cl_name)) {
120 if (ttProjectHelper::insert(array(
121 'group_id' => $user->getGroup(),
122 'org_id' => $user->org_id,
124 'description' => $cl_description,
125 'users' => $cl_users,
126 'tasks' => $cl_tasks,
127 'status' => ACTIVE))) {
128 header('Location: projects.php');
131 $err->add($i18n->get('error.db'));
133 $err->add($i18n->get('error.object_exists'));
138 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
139 $smarty->assign('onload', 'onLoad="document.projectForm.name.focus()"');
140 $smarty->assign('title', $i18n->get('title.edit_project'));
141 $smarty->assign('content_page_name', 'project_edit.tpl');
142 $smarty->display('index.tpl');