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','value'=>$cl_name));
80 $form->addInput(array('type'=>'textarea','name'=>'description','class'=>'mobile-textarea','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')));
88 $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
90 if ($request->isPost()) {
91 // Validate user input.
92 if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
93 if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
96 if ($request->getParameter('btn_save')) {
97 $existing_project = ttProjectHelper::getProjectByName($cl_name);
98 if (!$existing_project || ($cl_project_id == $existing_project['id'])) {
99 // Update project information.
100 if (ttProjectHelper::update(array(
101 'id' => $cl_project_id,
103 'description' => $cl_description,
104 'status' => $cl_status,
105 'users' => $cl_users,
106 'tasks' => $cl_tasks))) {
107 header('Location: projects.php');
110 $err->add($i18n->get('error.db'));
112 $err->add($i18n->get('error.project_exists'));
115 if ($request->getParameter('btn_copy')) {
116 if (!ttProjectHelper::getProjectByName($cl_name)) {
117 if (ttProjectHelper::insert(array(
118 'team_id' => $user->team_id,
120 'description' => $cl_description,
121 'users' => $cl_users,
122 'tasks' => $cl_tasks,
123 'status' => ACTIVE))) {
124 header('Location: projects.php');
127 $err->add($i18n->get('error.db'));
129 $err->add($i18n->get('error.project_exists'));
132 if ($request->getParameter('btn_delete')) {
133 header("Location: project_delete.php?id=$cl_project_id");
139 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
140 $smarty->assign('onload', 'onLoad="document.projectForm.project_name.focus()"');
141 $smarty->assign('title', $i18n->get('title.edit_project'));
142 $smarty->assign('content_page_name', 'mobile/project_edit.tpl');
143 $smarty->display('mobile/index.tpl');