![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: addedit.php 156 2008-04-11 15:47:40Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/tasks/addedit.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 /** 7 * Tasks :: Add/Edit Form 8 * 9 */ 10 11 $task_id = intval(w2PgetParam($_REQUEST, 'task_id', 0)); 12 $perms = &$AppUI->acl(); 13 14 // load the record data 15 $obj = new CTask(); 16 17 // check if we are in a subform 18 if ($task_id > 0 && !$obj->load($task_id)) { 19 $AppUI->setMsg('Task'); 20 $AppUI->setMsg('invalidID', UI_MSG_ERROR, true); 21 $AppUI->redirect(); 22 } 23 24 $task_parent = isset($_REQUEST['task_parent']) ? w2PgetParam($_REQUEST, 'task_parent', $obj->task_parent) : $obj->task_parent; 25 26 // check for a valid project parent 27 $task_project = intval($obj->task_project); 28 if (!$task_project) { 29 $task_project = w2PgetParam($_REQUEST, 'task_project', 0); 30 if (!$task_project) { 31 $AppUI->setMsg('badTaskProject', UI_MSG_ERROR); 32 $AppUI->redirect(); 33 } 34 } 35 36 // check permissions 37 if ($task_id) { 38 // we are editing an existing task 39 $canEdit = $perms->checkModuleItem('tasks', 'edit', $task_id); 40 } else { 41 // do we have access on this project? 42 $canEdit = $perms->checkModuleItem('projects', 'view', $task_project); 43 // And do we have add permission to tasks? 44 if ($canEdit) { 45 $canEdit = $perms->checkModule('tasks', 'add'); 46 } 47 } 48 49 if (!$canEdit) { 50 $AppUI->redirect('m=public&a=access_denied&err=noedit'); 51 } 52 53 //check permissions for the associated project 54 $canReadProject = $perms->checkModuleItem('projects', 'view', $obj->task_project); 55 56 $durnTypes = w2PgetSysVal('TaskDurationType'); 57 58 // check the document access (public, participant, private) 59 if (!$obj->canAccess($AppUI->user_id)) { 60 $AppUI->redirect('m=public&a=access_denied&err=noaccess'); 61 } 62 63 // pull the related project 64 $project = new CProject(); 65 $project->load($task_project); 66 67 //Pull all users 68 $users = $perms->getPermittedUsers('tasks'); 69 70 function getSpaces($amount) { 71 if ($amount == 0) { 72 return ''; 73 } 74 return str_repeat(' ', $amount); 75 } 76 77 function constructTaskTree($task_data, $depth = 0) { 78 global $projTasks, $all_tasks, $parents, $task_parent_options, $task_parent, $task_id; 79 80 $projTasks[$task_data['task_id']] = $task_data['task_name']; 81 82 $selected = $task_data['task_id'] == $task_parent ? 'selected="selected"' : ''; 83 $task_data['task_name'] = strlen($task_data[1]) > 45 ? substr($task_data['task_name'], 0, 45) . '...' : $task_data['task_name']; 84 85 $task_parent_options .= '<option value="' . $task_data['task_id'] . '" ' . $selected . '>' . getSpaces($depth * 3) . w2PFormSafe($task_data['task_name']) . '</option>'; 86 87 if (isset($parents[$task_data['task_id']])) { 88 foreach ($parents[$task_data['task_id']] as $child_task) { 89 if ($child_task != $task_id) 90 constructTaskTree($all_tasks[$child_task], ($depth + 1)); 91 } 92 } 93 } 94 95 function build_date_list(&$date_array, $row) { 96 global $tracked_dynamics, $project; 97 // if this task_dynamic is not tracked, set end date to proj start date 98 if (!in_array($row['task_dynamic'], $tracked_dynamics)) { 99 $date = new CDate($project->project_start_date); 100 } elseif ($row['task_milestone'] == 0) { 101 $date = new CDate($row['task_end_date']); 102 } else { 103 $date = new CDate($row['task_start_date']); 104 } 105 $sdate = $date->format('%d/%m/%Y'); 106 $shour = $date->format('%H'); 107 $smin = $date->format('%M'); 108 109 $date_array[$row['task_id']] = array($row['task_name'], $sdate, $shour, $smin); 110 } 111 112 // let's get root tasks 113 $q = new DBQuery; 114 $q->addTable('tasks'); 115 $q->addQuery('task_id, task_name, task_end_date, task_start_date, task_milestone, task_parent, task_dynamic'); 116 $q->addWhere('task_project = ' . (int)$task_project); 117 $q->addWhere('task_id = task_parent'); 118 $q->addOrder('task_start_date'); 119 $root_tasks = $q->loadHashList('task_id'); 120 $q->clear(); 121 122 $projTasks = array(); 123 $task_parent_options = ''; 124 125 // Now lets get non-root tasks, grouped by the task parent 126 $q = new DBQuery; 127 $q->addTable('tasks'); 128 $q->addQuery('task_id, task_name, task_end_date, task_start_date, task_milestone, task_parent, task_dynamic'); 129 $q->addWhere('task_project = ' . (int)$task_project); 130 $q->addWhere('task_id <> task_parent'); 131 $q->addOrder('task_start_date'); 132 133 $parents = array(); 134 $projTasksWithEndDates = array($obj->task_id => $AppUI->_('None')); //arrays contains task end date info for setting new task start date as maximum end date of dependenced tasks 135 $all_tasks = array(); 136 $sub_tasks = $q->exec(); 137 if ($sub_tasks) { 138 while ($sub_task = $q->fetchRow()) { 139 // Build parent/child task list 140 $parents[$sub_task['task_parent']][] = $sub_task['task_id']; 141 $all_tasks[$sub_task['task_id']] = $sub_task; 142 build_date_list($projTasksWithEndDates, $sub_task); 143 } 144 } 145 $q->clear(); 146 147 // let's iterate root tasks 148 foreach ($root_tasks as $root_task) { 149 build_date_list($projTasksWithEndDates, $root_task); 150 if ($root_task['task_id'] != $task_id) 151 constructTaskTree($root_task); 152 } 153 154 // setup the title block 155 $ttl = $task_id > 0 ? 'Edit Task' : 'Add Task'; 156 $titleBlock = new CTitleBlock($ttl, 'applet-48.png', $m, $m . '.' . $a); 157 $titleBlock->addCrumb('?m=tasks', 'tasks list'); 158 if ($canReadProject) { 159 $titleBlock->addCrumb('?m=projects&a=view&project_id=' . $task_project, 'view this project'); 160 } 161 if ($task_id > 0) 162 $titleBlock->addCrumb('?m=tasks&a=view&task_id=' . $obj->task_id, 'view this task'); 163 $titleBlock->show(); 164 165 // Let's gather all the necessary information from the department table 166 // collect all the departments in the company 167 $depts = array(0 => ''); 168 169 // ALTER TABLE `tasks` ADD `task_departments` CHAR( 100 ) ; 170 $company_id = $project->project_company; 171 $selected_departments = $obj->task_departments != '' ? explode(',', $obj->task_departments) : array(); 172 $departments_count = 0; 173 $department_selection_list = getDepartmentSelectionList($company_id, $selected_departments); 174 if ($department_selection_list != '') { 175 $department_selection_list = ('<select name="dept_ids[]" class="text"><option value="0"></option>' . $department_selection_list . '</select>'); 176 } 177 178 function getDepartmentSelectionList($company_id, $checked_array = array(), $dept_parent = 0, $spaces = 0) { 179 global $departments_count, $AppUI; 180 $parsed = ''; 181 182 if ($departments_count < 10) { 183 $departments_count++; 184 } 185 $q = new DBQuery; 186 $q->addTable('departments'); 187 $q->addQuery('dept_id, dept_name'); 188 $q->addWhere('dept_parent = ' . (int)$dept_parent); 189 $q->addWhere('dept_company = ' . (int)$company_id); 190 $department = new CDepartment; 191 $department->setAllowedSQL($AppUI->user_id, $q); 192 193 $depts_list = $q->loadHashList('dept_id'); 194 $q->clear(); 195 196 foreach ($depts_list as $dept_id => $dept_info) { 197 $selected = in_array($dept_id, $checked_array) ? ' selected="selected"' : ''; 198 199 if (strlen($dept_info['dept_name']) > 30) { 200 $dept_info['dept_name'] = substr($dept_info['dept_name'], 0, 28) . '...'; 201 } 202 203 $parsed .= '<option value="' . $dept_id . '"' . $selected. '>' . str_repeat(' ', $spaces) . $dept_info['dept_name'] . '</option>'; 204 $parsed .= getDepartmentSelectionList($company_id, $checked_array, $dept_id, $spaces + 5); 205 } 206 207 return $parsed; 208 } 209 210 //Dynamic tasks are by default now off because of dangerous behavior if incorrectly used 211 if (is_null($obj->task_dynamic)) { 212 $obj->task_dynamic = 0; 213 } 214 215 $can_edit_time_information = $obj->canUserEditTimeInformation(); 216 //get list of projects, for task move drop down list. 217 //require_once $AppUI->getModuleClass('projects'); 218 //$project =& new CProject; 219 $pq = new DBQuery; 220 $pq->addQuery('pr.project_id, project_name'); 221 $pq->addTable('projects', 'pr'); 222 $pq->addWhere('project_company = ' . (int)$company_id); 223 $pq->addWhere('( project_active = 1 or pr.project_id = ' . (int)$task_project . ')'); 224 $pq->addOrder('project_name'); 225 $project->setAllowedSQL($AppUI->user_id, $pq, null, 'pr'); 226 $projects = $pq->loadHashList(); 227 ?> 228 <script language="JavaScript"> 229 var selected_contacts_id = '<?php echo $obj->task_contacts; ?>'; 230 var task_id = '<?php echo $obj->task_id; ?>'; 231 232 var check_task_dates = <?php 233 if (isset($w2Pconfig['check_task_dates']) && $w2Pconfig['check_task_dates']) 234 echo 'true'; 235 else 236 echo 'false'; 237 ?>; 238 var can_edit_time_information = <?php echo $can_edit_time_information ? 'true' : 'false'; ?>; 239 240 var task_name_msg = '<?php echo $AppUI->_('taskName'); ?>'; 241 var task_start_msg = '<?php echo $AppUI->_('taskValidStartDate'); ?>'; 242 var task_end_msg = '<?php echo $AppUI->_('taskValidEndDate'); ?>'; 243 244 var workHours = <?php echo w2PgetConfig('daily_working_hours'); ?>; 245 //working days array from config.php 246 var working_days = new Array(<?php echo w2PgetConfig('cal_working_days'); ?>); 247 var cal_day_start = <?php echo intval(w2PgetConfig('cal_day_start')); ?>; 248 var cal_day_end = <?php echo intval(w2PgetConfig('cal_day_end')); ?>; 249 var daily_working_hours = <?php echo intval(w2PgetConfig('daily_working_hours')); ?>; 250 </script> 251 252 <form name="editFrm" action="?m=tasks&project_id=<?php echo $task_project; ?>" method="post"> 253 <input name="dosql" type="hidden" value="do_task_aed" /> 254 <input name="task_id" type="hidden" value="<?php echo $task_id; ?>" /> 255 <input name="task_project" type="hidden" value="<?php echo $task_project; ?>" /> 256 <input name='task_contacts' id='task_contacts' type='hidden' value="<?php echo $obj->task_contacts; ?>" /> 257 <table border="1" cellpadding="4" cellspacing="0" width="100%" class="std"> 258 <tr> 259 <td colspan="2" style="border: outset #eeeeee 1px;background-color:#<?php echo $project->project_color_identifier; ?>" > 260 <font color="<?php echo bestColor($project->project_color_identifier); ?>"> 261 <strong><?php echo $AppUI->_('Project'); ?>: <?php echo $project->project_name; ?></strong> 262 </font> 263 </td> 264 </tr> 265 266 <tr valign="top"> 267 <td> 268 <?php echo $AppUI->_('Task Name'); ?> * 269 <br /><input type="text" class="text" name="task_name" value="<?php echo ($obj->task_name); ?>" size="40" maxlength="255" /> 270 </td> 271 <td> 272 <table cellspacing="0" cellpadding="2" border="0" width="100%"> 273 <tr> 274 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Status'); ?></td> 275 <td> 276 <?php echo arraySelect($status, 'task_status', 'size="1" class="text"', ($obj->task_status ? $obj->task_status : 0) , true); ?> 277 </td> 278 279 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Priority'); ?> *</td> 280 <td nowrap="nowrap"> 281 <?php echo arraySelect($priority, 'task_priority', 'size="1" class="text"', ($obj->task_priority ? $obj->task_priority : 0) , true); ?> 282 </td> 283 </tr> 284 <tr> 285 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Progress'); ?></td> 286 <td> 287 <?php echo arraySelect($percent, 'task_percent_complete', 'size="1" class="text"', $obj->task_percent_complete) . '%'; ?> 288 </td> 289 290 <td align="right" nowrap="nowrap"><label for="task_milestone"><?php echo $AppUI->_('Milestone'); ?>?</label></td> 291 <td> 292 <input type="checkbox" value="1" name="task_milestone" id="task_milestone" <?php if ($obj->task_milestone) { ?>checked="checked"<?php } ?> /> 293 </td> 294 </tr> 295 </table> 296 </td> 297 </tr> 298 <tr> 299 <td colspan="2"> 300 <table border="0" cellspacing="0" cellpadding="3" width="100%"> 301 <tr> 302 <td height="40" width="35%"> 303 * <?php echo $AppUI->_('requiredField'); ?> 304 </td> 305 <td height="40" width="30%"> </td> 306 <td height="40" width="35%" align="right"> 307 <table> 308 <tr> 309 <td> 310 <input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel'); ?>" onclick="if(confirm('<?php echo $AppUI->_('taskCancel', UI_OUTPUT_JS); ?>')){location.href = '?<?php echo $AppUI->getPlace(); ?>';}" /> 311 </td> 312 <td> 313 <input class="button" type="button" name="btnFuseAction" value="<?php echo $AppUI->_('save'); ?>" onclick="submitIt(document.editFrm);" /> 314 </td> 315 </tr> 316 </table> 317 </td> 318 </tr> 319 </table> 320 </td> 321 </tr> 322 </form> 323 </table> 324 325 <?php 326 if (isset($_GET['tab'])) { 327 $AppUI->setState('TaskAeTabIdx', w2PgetParam($_GET, 'tab', 0)); 328 } 329 $tab = $AppUI->getState('TaskAeTabIdx', 0); 330 $tabBox = &new CTabBox('?m=tasks&a=addedit&task_id=' . $task_id, '', $tab, ''); 331 $tabBox->add(W2P_BASE_DIR . '/modules/tasks/ae_desc', 'Details'); 332 $tabBox->add(W2P_BASE_DIR . '/modules/tasks/ae_dates', 'Dates'); 333 $tabBox->add(W2P_BASE_DIR . '/modules/tasks/ae_depend', 'Dependencies'); 334 $tabBox->add(W2P_BASE_DIR . '/modules/tasks/ae_resource', 'Human Resources'); 335 $tabBox->show('', true); 336 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jan 8 03:00:03 2009 | Cross-referenced by PHPXref 0.7 |