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');
44 $cl_project_id = (int)$request->getParameter('id');
46 $users = ttTeamHelper::getActiveUsers();
47 foreach ($users as $user_item)
48 $all_users[$user_item['id']] = $user_item['name'];
50 $tasks = ttTeamHelper::getActiveTasks($user->team_id);
51 foreach ($tasks as $task_item)
52 $all_tasks[$task_item['id']] = $task_item['name'];
54 if ($request->isPost()) {
55 $cl_name = trim($request->getParameter('project_name'));
56 $cl_description = trim($request->getParameter('description'));
57 $cl_status = $request->getParameter('status');
58 $cl_users = $request->getParameter('users', array());
59 $cl_tasks = $request->getParameter('tasks', array());
61 $project = ttProjectHelper::get($cl_project_id);
62 $cl_name = $project['name'];
63 $cl_description = $project['description'];
64 $cl_status = $project['status'];
66 $mdb2 = getConnection();
67 $sql = "select user_id from tt_user_project_binds where status = 1 and project_id = $cl_project_id";
68 $res = $mdb2->query($sql);
69 if (is_a($res, 'PEAR_Error'))
70 die($res->getMessage());
71 while ($row = $res->fetchRow())
72 $cl_users[] = $row['user_id'];
74 $cl_tasks = explode(',', $project['tasks']);
77 $form = new Form('projectForm');
78 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_project_id));
79 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'project_name','style'=>'width: 250px;','value'=>$cl_name));
80 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
81 $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status,
82 'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive'))));
83 $form->addInput(array('type'=>'checkboxgroup','name'=>'users','data'=>$all_users,'layout'=>'H','value'=>$cl_users));
84 if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
85 $form->addInput(array('type'=>'checkboxgroup','name'=>'tasks','data'=>$all_tasks,'layout'=>'H','value'=>$cl_tasks));
86 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
87 $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->get('button.copy')));
89 if ($request->isPost()) {
90 // Validate user input.
91 if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
92 if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
95 if ($request->getParameter('btn_save')) {
96 $existing_project = ttProjectHelper::getProjectByName($cl_name);
97 if (!$existing_project || ($cl_project_id == $existing_project['id'])) {
98 // Update project information.
99 if (ttProjectHelper::update(array(
100 'id' => $cl_project_id,
102 'description' => $cl_description,
103 'status' => $cl_status,
104 'users' => $cl_users,
105 'tasks' => $cl_tasks))) {
106 header('Location: projects.php');
109 $err->add($i18n->get('error.db'));
111 $err->add($i18n->get('error.project_exists'));
114 if ($request->getParameter('btn_copy')) {
115 if (!ttProjectHelper::getProjectByName($cl_name)) {
116 if (ttProjectHelper::insert(array(
117 'team_id' => $user->team_id,
119 'description' => $cl_description,
120 'users' => $cl_users,
121 'tasks' => $cl_tasks,
122 'status' => ACTIVE))) {
123 header('Location: projects.php');
126 $err->add($i18n->get('error.db'));
128 $err->add($i18n->get('error.project_exists'));
133 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
134 $smarty->assign('onload', 'onLoad="document.projectForm.name.focus()"');
135 $smarty->assign('title', $i18n->get('title.edit_project'));
136 $smarty->assign('content_page_name', 'project_edit.tpl');
137 $smarty->display('index.tpl');