$group_id = $user->getGroup();
$org_id = $user->org_id;
- $sql = "select p.id, p.name, if(Sub1.entity_id is null, 0, 1) as has_files from tt_projects p".
+ $sql = "select p.id, p.name, p.description, if(Sub1.entity_id is null, 0, 1) as has_files from tt_projects p".
" left join (select distinct entity_id from tt_files".
" where entity_type = 'project' and group_id = $group_id and org_id = $org_id and status = 1) Sub1".
" on (p.id = Sub1.entity_id)".
import('form.Form');
import('ttProjectHelper');
import('ttGroupHelper');
+import('ttFileHelper');
// Access checks.
if (!ttAccessAllowed('manage_projects')) {
}
// End of access checks.
+$showFiles = $user->isPluginEnabled('at');
$users = ttGroupHelper::getActiveUsers();
foreach ($users as $user_item)
$all_users[$user_item['id']] = $user_item['name'];
$form = new Form('projectForm');
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'project_name','style'=>'width: 250px;','value'=>$cl_name));
$form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
+if ($showFiles)
+ $form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit')));
$form->addInput(array('type'=>'checkboxgroup','name'=>'users','data'=>$all_users,'layout'=>'H','value'=>$cl_users));
if ($show_tasks)
$form->addInput(array('type'=>'checkboxgroup','name'=>'tasks','data'=>$all_tasks,'layout'=>'H','value'=>$cl_tasks));
if ($err->no()) {
if (!ttProjectHelper::getProjectByName($cl_name)) {
- if (ttProjectHelper::insert(array('name' => $cl_name,
+ $id = ttProjectHelper::insert(array('name' => $cl_name,
'description' => $cl_description,
'users' => $cl_users,
'tasks' => $cl_tasks,
- 'status' => ACTIVE))) {
- header('Location: projects.php');
- exit();
- } else
- $err->add($i18n->get('error.db'));
+ 'status' => ACTIVE));
+
+ // Put a new file in storage if we have it.
+ if ($id && $showFiles && $_FILES['newfile']['name']) {
+ $fileHelper = new ttFileHelper($err);
+ $fields = array('entity_type'=>'project',
+ 'entity_id' => $id,
+ 'file_name' => $_FILES['newfile']['name']);
+ $fileHelper->putFile($fields);
+ }
+ if ($id) {
+ header('Location: projects.php');
+ exit();
+ } else
+ $err->add($i18n->get('error.db'));
} else
$err->add($i18n->get('error.object_exists'));
}
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('onload', 'onLoad="document.projectForm.project_name.focus()"');
+$smarty->assign('show_files', $showFiles);
$smarty->assign('show_users', count($users) > 0);
$smarty->assign('show_tasks', $show_tasks);
$smarty->assign('title', $i18n->get('title.add_project'));