home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / tasks / view.php < prev    next >
Encoding:
PHP Script  |  2004-02-02  |  16.5 KB  |  464 lines

  1. <?php /* $Id: view.php,v 1.58 2004/02/01 22:41:07 gnome444 Exp $ */
  2.  
  3. $task_id = intval( dPgetParam( $_GET, "task_id", 0 ) );
  4.  
  5. // check permissions for this record
  6. $canRead = !getDenyRead( $m, $task_id );
  7. $canEdit = !getDenyEdit( $m, $task_id );
  8.  
  9. // check permissions for this record
  10. $canReadModule = !getDenyRead( $m );
  11.  
  12.  
  13. if (!$canRead) {
  14.     $AppUI->redirect( "m=public&a=access_denied" );
  15. }
  16.  
  17. $sql = "
  18. SELECT tasks.*,
  19.     project_name, project_color_identifier,
  20.     u1.user_username as username,
  21.     ROUND(SUM(task_log_hours),2) as log_hours_worked
  22. FROM tasks
  23. LEFT JOIN users u1 ON u1.user_id = task_owner
  24. LEFT JOIN projects ON project_id = task_project
  25. LEFT JOIN task_log ON task_log_task=$task_id
  26. WHERE task_id = $task_id
  27. GROUP BY task_id
  28. ";
  29.  
  30. // check if this record has dependancies to prevent deletion
  31. $msg = '';
  32. $obj = new CTask();
  33. $canDelete = $obj->canDelete( $msg, $task_id );
  34.  
  35. //$obj = null;
  36. if (!db_loadObject( $sql, $obj, true )) {
  37.     $AppUI->setMsg( 'Task' );
  38.     $AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
  39.     $AppUI->redirect();
  40. } else {
  41.     $AppUI->savePlace();
  42. }
  43.  
  44. if (!$obj->canAccess( $AppUI->user_id )) {
  45.     $AppUI->redirect( "m=public&a=access_denied" );
  46. }
  47.  
  48. // retrieve any state parameters
  49. if (isset( $_GET['tab'] )) {
  50.     $AppUI->setState( 'TaskLogVwTab', $_GET['tab'] );
  51. }
  52. $tab = $AppUI->getState( 'TaskLogVwTab' ) !== NULL ? $AppUI->getState( 'TaskLogVwTab' ) : 0;
  53.  
  54. // get the prefered date format
  55. $df = $AppUI->getPref('SHDATEFORMAT');
  56. //Also view the time
  57. $df .= " " . $AppUI->getPref('TIMEFORMAT');
  58.  
  59. $start_date = intval( $obj->task_start_date ) ? new CDate( $obj->task_start_date ) : null;
  60. $end_date = intval( $obj->task_end_date ) ? new CDate( $obj->task_end_date ) : null;
  61.  
  62. //check permissions for the associated project
  63. $canReadProject = !getDenyRead( 'projects', $obj->task_project);
  64.  
  65. // get the users on this task
  66. $sql = "
  67. SELECT u.user_id, u.user_username, u.user_first_name,u.user_last_name, u.user_email
  68. FROM users u, user_tasks t
  69. WHERE t.task_id =$task_id AND
  70.     t.user_id = u.user_id
  71. ORDER by u.user_last_name, u.user_first_name
  72. ";
  73. $users = db_loadList( $sql );
  74.  
  75. //Pull files on this task
  76. $sql = "
  77. SELECT file_id, file_name, file_size,file_type
  78. FROM files
  79. WHERE file_task = $task_id
  80.     AND file_task <> 0
  81. ORDER by file_name
  82. ";
  83. $files = db_loadList( $sql );
  84.  
  85. $durnTypes = dPgetSysVal( 'TaskDurationType' );
  86.  
  87. // setup the title block
  88. $titleBlock = new CTitleBlock( 'View Task', 'applet-48.png', $m, "$m.$a" );
  89. $titleBlock->addCell(
  90. );
  91. if ($canEdit) {
  92.     $titleBlock->addCell(
  93.         '<input type="submit" class="button" value="'.$AppUI->_('new task').'">', '',
  94.         '<form action="?m=tasks&a=addedit&task_project='.$obj->task_project.'&task_parent=' . $task_id . '" method="post">', '</form>'
  95.     );
  96. }
  97. $titleBlock->addCrumb( "?m=tasks", "tasks list" );
  98. if ($canReadProject) {
  99.     $titleBlock->addCrumb( "?m=projects&a=view&project_id=$obj->task_project", "view this project" );
  100. }
  101. if ($canEdit) {
  102.     $titleBlock->addCrumb( "?m=tasks&a=addedit&task_id=$task_id", "edit this task" );
  103. }
  104. if ($canEdit) {
  105.     $titleBlock->addCrumbDelete( 'delete task', $canDelete, $msg );
  106. }
  107. $titleBlock->show();
  108.  
  109. ?>
  110.  
  111. <script language="JavaScript">
  112. var calendarField = '';
  113.  
  114. function popCalendar( field ){
  115.     calendarField = field;
  116.     idate = eval( 'document.editFrm.task_' + field + '.value' );
  117.     window.open( 'index.php?m=public&a=calendar&dialog=1&callback=setCalendar&date=' + idate, 'calwin', 'top=250,left=250,width=250, height=220, scollbars=false' );
  118. }
  119.  
  120. /**
  121.  *    @param string Input date in the format YYYYMMDD
  122.  *    @param string Formatted date
  123.  */
  124. function setCalendar( idate, fdate ) {
  125.     fld_date = eval( 'document.editFrm.task_' + calendarField );
  126.     fld_fdate = eval( 'document.editFrm.' + calendarField );
  127.     fld_date.value = idate;
  128.     fld_fdate.value = fdate;
  129. }
  130.  
  131. function updateTask() {
  132.     var f = document.editFrm;
  133.     if (f.task_log_description.value.length < 1) {
  134.         alert( "<?php echo $AppUI->_('tasksComment');?>" );
  135.         f.task_log_description.focus();
  136.     } else if (isNaN( parseInt( f.task_percent_complete.value+0 ) )) {
  137.         alert( "<?php echo $AppUI->_('tasksPercent');?>" );
  138.         f.task_percent_complete.focus();
  139.     } else if(f.task_percent_complete.value  < 0 || f.task_percent_complete.value > 100) {
  140.         alert( "<?php echo $AppUI->_('tasksPercentValue');?>" );
  141.         f.task_percent_complete.focus();
  142.     } else {
  143.         f.submit();
  144.     }
  145. }
  146. function delIt() {
  147.     if (confirm( "<?php echo $AppUI->_('doDelete').' '.$AppUI->_('Task').'?';?>" )) {
  148.         document.frmDelete.submit();
  149.     }
  150. }
  151. </script>
  152.  
  153. <table border="0" cellpadding="4" cellspacing="0" width="100%" class="std">
  154.  
  155. <form name="frmDelete" action="./index.php?m=tasks" method="post">
  156.     <input type="hidden" name="dosql" value="do_task_aed">
  157.     <input type="hidden" name="del" value="1" />
  158.     <input type="hidden" name="task_id" value="<?php echo $task_id;?>" />
  159. </form>
  160.  
  161. <tr valign="top">
  162.     <td width="50%">
  163.         <table width="100%" cellspacing="1" cellpadding="2">
  164.         <tr>
  165.             <td nowrap="nowrap" colspan=2><strong><?php echo $AppUI->_('Details');?></strong></td>
  166.         </tr>
  167.         <tr>
  168.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Project');?>:</td>
  169.             <td style="background-color:#<?php echo $obj->project_color_identifier;?>">
  170.                 <font color="<?php echo bestColor( $obj->project_color_identifier ); ?>">
  171.                     <?php echo @$obj->project_name;?>
  172.                 </font>
  173.             </td>
  174.         </tr>
  175.         <tr>
  176.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Task');?>:</td>
  177.             <td class="hilite"><strong><?php echo @$obj->task_name;?></strong></td>
  178.         </tr>
  179.         <?php if ( $obj->task_parent != $obj->task_id ) { 
  180.             $obj_parent = new CTask();
  181.             $obj_parent->load($obj->task_parent);
  182.         ?>
  183.         <tr>
  184.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Task Parent');?>:</td>
  185.             <td class="hilite"><a href="<?php echo "./index.php?m=tasks&a=view&task_id=" . @$obj_parent->task_id; ?>"><?php echo @$obj_parent->task_name;?></a></td>
  186.         </tr>
  187.         <?php } ?>
  188.         <tr>
  189.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Creator');?>:</td>
  190.             <td class="hilite"> <?php echo @$obj->username;?></td>
  191.         </tr>                <tr>
  192.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Priority');?>:</td>
  193.             <td class="hilite">
  194.         <?php
  195.             if ($obj->task_priority == 0) {
  196.                 echo $AppUI->_('normal');
  197.             } else if ($obj->task_priority < 0){
  198.                 echo $AppUI->_('low');
  199.             } else {
  200.                 echo $AppUI->_('high');
  201.             }
  202.         ?>
  203.             </td>
  204.         </tr>
  205.         <tr>
  206.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Web Address');?>:</td>
  207.             <td class="hilite" width="300"><a href="<?php echo @$obj->task_related_url;?>" target="task<?php echo $task_id;?>"><?php echo @$obj->task_related_url;?></a></td>
  208.         </tr>
  209.         <tr>
  210.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Milestone');?>:</td>
  211.             <td class="hilite" width="300"><?php if($obj->task_milestone){echo $AppUI->_("Yes");}else{echo $AppUI->_("No");}?></td>
  212.         </tr>
  213.         <tr>
  214.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Progress');?>:</td>
  215.             <td class="hilite" width="300"><?php echo @$obj->task_percent_complete;?>%</td>
  216.         </tr>
  217.         <tr>
  218.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Time Worked');?>:</td>
  219.             <td class="hilite" width="300"><?php echo (@$obj->task_hours_worked + @rtrim($obj->log_hours_worked, "0"));?></td>
  220.         </tr>
  221.         <tr>
  222.             <td nowrap="nowrap" colspan=2><strong><?php echo $AppUI->_('Dates and Targets');?></strong></td>
  223.         </tr>
  224.         <tr>
  225.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Start Date');?>:</td>
  226.             <td class="hilite" width="300"><?php echo $start_date ? $start_date->format( $df ) : '-';?></td>
  227.         </tr>
  228.         <tr>
  229.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Finish Date');?>:</td>
  230.             <td class="hilite" width="300"><?php echo $end_date ? $end_date->format( $df ) : '-';?></td>
  231.         </tr>
  232.         <tr>
  233.             <td align="right" nowrap="nowrap" valign="top"><?php echo $AppUI->_('Expected Duration');?>:</td>
  234.             <td class="hilite" width="300"><?php echo $obj->task_duration.' '.$AppUI->_( $durnTypes[$obj->task_duration_type] );?></td>
  235.         </tr>
  236.         <tr>
  237.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Target Budget');?> <?php echo $dPconfig['currency_symbol'] ?>:</td>
  238.             <td class="hilite" width="300"><?php echo $obj->task_target_budget;?></td>
  239.         </tr>
  240.         <tr>
  241.             <td nowrap="nowrap" colspan="2"><strong><?php echo $AppUI->_('Description');?></strong></td>
  242.         </tr>
  243.         <tr>
  244.             <td valign="top" height="75" colspan="2" class="hilite">
  245.                 <?php $newstr = str_replace( chr(10), "<br />", $obj->task_description);echo $newstr;?>
  246.             </td>
  247.         </tr>
  248.  
  249.         </table>
  250.     </td>
  251.  
  252.     <td width="50%">
  253.         <table cellspacing="1" cellpadding="2" border="0" width="100%">
  254.         <tr>
  255.             <td colspan="3"><strong><?php echo $AppUI->_('Assigned Users');?></strong></td>
  256.         </tr>
  257.         <tr>
  258.             <td colspan="3">
  259.             <?php
  260.                 $s = '';
  261.                 $s = count( $users ) == 0 ? "<tr><td bgcolor=#ffffff>".$AppUI->_('none')."</td></tr>" : '';
  262.                 foreach($users as $row) {
  263.                     $s .= '<tr>';
  264.                     $s .= '<td class="hilite">'.$row["user_first_name"].' '.$row["user_last_name"].'</td>';
  265.                     $s .= '<td class="hilite"><a href="mailto:'.$row["user_email"].'">'.$row["user_email"].'</a></td>';
  266.                     $s .= '</tr>';
  267.                 }
  268.                 echo '<table width="100%" cellspacing=1 bgcolor="black">'.$s.'</table>';
  269.             ?>
  270.             </td>
  271.         </tr>
  272.  
  273.         <?php
  274.             // Pull tasks dependencies
  275.             $sql = "
  276.             SELECT t.task_id, t.task_name
  277.             FROM tasks t, task_dependencies td
  278.             WHERE td.dependencies_task_id = $task_id
  279.             AND t.task_id = td.dependencies_req_task_id
  280.             ";
  281.             $taskDep = db_loadHashList( $sql );
  282.         ?>
  283.         <tr>
  284.             <td colspan="3"><strong><?php echo $AppUI->_('Dependencies');?></strong></td>
  285.         </tr>
  286.         <tr>
  287.             <td colspan="3">
  288.             <?php 
  289.                 $s = count( $taskDep ) == 0 ? "<tr><td bgcolor=#ffffff>".$AppUI->_('none')."</td></tr>" : '';
  290.                 foreach($taskDep as $key => $value) {
  291.                     $s .= '<tr><td class="hilite">';
  292.                     $s .= '<a href="./index.php?m=tasks&a=view&task_id='.$key.'">'.$value.'</a>';
  293.                     $s .= '</td></tr>';
  294.                 }
  295.                 echo '<table width="100%" cellspacing=1 bgcolor="black">'.$s.'</table>';
  296.             ?>
  297.             </td>
  298.         </tr>
  299.  
  300.     <?php // check access to files module
  301.         if (!getDenyRead( 'files' )) {
  302.     ?>
  303.         <tr>
  304.             <td width="100%"><strong><?php echo $AppUI->_('Attached Files');?></strong></td>
  305.             <td align="right" nowrap="nowrap">
  306.             <?php if (!getDenyEdit( 'files' )) { ?>
  307.                 <a href="./index.php?m=files&a=addedit&project_id=<?php echo $obj->task_project;?>&file_task=<?php echo $task_id;?>"><?php echo $AppUI->_('Attach a file');?>
  308.                 </a>
  309.             <?php } ?>
  310.             </td>
  311.             <td width="20">
  312.                 <?php echo dPshowImage( dPfindImage( 'stock_attach-16.png', $m ), 16, 16, '' ); ?>
  313.             </td>
  314.         </tr>
  315.         <tr>
  316.             <td colspan="3">
  317.             <?php
  318.                 $s = count( $files ) == 0 ? "<tr><td bgcolor=#ffffff>".$AppUI->_('none')."</td></tr>" : '';
  319.                 foreach ($files as $row) {
  320.                     $s .= '<tr>';
  321.                     $s .= '<td class="hilite"><a href="./fileviewer.php?file_id='.$row["file_id"].'">'.$row["file_name"].'</a></td>';
  322.                     $s .= '<td class="hilite">'.$row["file_type"].'</td>';
  323.                     $s .= '<td class="hilite">'.$row["file_size"].'</td>';
  324.                     $s .= '</tr>';
  325.                 }
  326.                 echo '<table width="100%" cellspacing="1" bgcolor="black">'.$s.'</table';
  327.             ?>
  328.             </td>
  329.         </tr>
  330.     <?php } // end files access 
  331.         if($obj->task_departments != "") {
  332.             ?>
  333.             <tr>
  334.                 <td><strong><?php echo $AppUI->_("Departments"); ?></strong></td>
  335.             </tr>
  336.             <tr>
  337.                 <td colspan='3' class="hilite">
  338.                     <?php
  339.                         $depts = db_loadHashList("select dept_id, dept_name, dept_phone
  340.                                                   from departments
  341.                                                   where dept_id in (".$obj->task_departments.")", "dept_id");
  342.                         foreach($depts as $dept_id => $dept_info){
  343.                             echo "<div>".$dept_info["dept_name"];
  344.                             if($dept_info["dept_phone"] != ""){
  345.                                 echo "( ".$dept_info["dept_phone"]." )";
  346.                             }
  347.                             echo "</div>";
  348.                         }
  349.                     ?>
  350.                 </td>
  351.             </tr>
  352.              <?php
  353.         }
  354.         
  355.         if($obj->task_contacts != "") {
  356.             $contacts = db_loadHashList("select contact_id, contact_first_name, contact_last_name, contact_email, contact_phone, contact_department
  357.                                          from contacts
  358.                                          where contact_id in (".$obj->task_contacts.")
  359.                                                and (contact_owner = '$AppUI->user_id' or contact_private='0')", "contact_id");
  360.             if(count($contacts)>0){
  361.                 ?>
  362.                 <tr>
  363.                     <td><strong><?php echo $AppUI->_("Contacts"); ?></strong></td>
  364.                 </tr>
  365.                 <tr>
  366.                     <td colspan='3' class="hilite">
  367.                         <?php
  368.                             echo "<table cellspacing='1' cellpadding='2' border='0' width='100%' bgcolor='black'>";
  369.                             echo "<tr><th>".$AppUI->_("Name")."</th><th>".$AppUI->_("Email")."</th><th>".$AppUI->_("Phone")."</th><th>".$AppUI->_("Department")."</th></tr>";
  370.                             foreach($contacts as $contact_id => $contact_data){
  371.                                 echo "<tr>";
  372.                                 echo "<td class='hilite'><a href='index.php?m=contacts&a=addedit&contact_id=$contact_id'>".$contact_data["contact_first_name"]." ".$contact_data["contact_last_name"]."</a></td>";
  373.                                 echo "<td class='hilite'>".$contact_data["contact_email"]."</td>";
  374.                                 echo "<td class='hilite'>".$contact_data["contact_phone"]."</td>";
  375.                                 echo "<td class='hilite'>".$contact_data["contact_department"]."</td>";
  376.                                 echo "</tr>";
  377.                             }
  378.                             echo "</table>";
  379.                         ?>
  380.                     </td>
  381.                 </tr>
  382.                  <?php
  383.             }
  384.         }
  385.         
  386.         $custom_fields = dPgetSysVal("TaskCustomFields");
  387.         if ( count($custom_fields) > 0 ){
  388.             //We have custom fields, parse them!
  389.             //Custom fields are stored in the sysval table under TaskCustomFields, the format is
  390.             //key|serialized array of ("name", "type", "options", "selects")
  391.             
  392.             if ( $obj->task_custom != "" || !is_null($obj->task_custom))  {
  393.                 //Custom info previously saved, retrieve it
  394.                 $custom_field_previous_data = unserialize($obj->task_custom);
  395.             }
  396.             
  397.             $output = '<tr><table cellspacing="1" cellpadding="2" >';
  398.             foreach ( $custom_fields as $key => $array) {
  399.                 $output .= "<tr id='custom_tr_$key' >";
  400.                 $field_options = unserialize($array);
  401.                 $output .= "<td align='right' nowrap='nowrap' >". ($field_options["type"] == "label" ? "<b>". $field_options['name']. "</b>" : $field_options['name'] . ":") ."</td>";
  402.                 switch ( $field_options["type"]){
  403.                     case "text":
  404.                         $output .= "<td class='hilite' width='300'>" . dPformSafe(( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "")) . "</td>";
  405.                         break;
  406.                     case "select":
  407.                         $optionarray = explode(",",$field_options["selects"]);
  408.                         $output .= "<td class='hilite' width='300'>". dPformSafe(( isset($custom_field_previous_data[$key]) ? $optionarray[$custom_field_previous_data[$key]] : "")) . "</td>";
  409.                         break;
  410.                     case "textarea":
  411.                         $output .=  "<td valign='top' class='hilite'>" . dPformSafe(( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "")) . "</td>";
  412.                         break;
  413.                     case "checkbox":
  414.                         $optionarray = explode(",",$field_options["selects"]);
  415.                                                 $output .= "<td align='left'>";
  416.                                                 foreach ( $optionarray as $option ) {
  417.                                                         if ( isset($custom_field_previous_data[$key]) && array_key_exists( $option, array_flip($custom_field_previous_data[$key]) ) ) {
  418.                                                                 $checked = "checked";
  419.                                                         }
  420.                                                         $output .=  "<input type='checkbox' value='$option' name='custom_" . $key ."[]' class='text' style='border:0' $checked " . $field_options["options"] . ">$option<br />";
  421.                                                         $checked = "";
  422.                                                 }
  423.                                                 $output .= "</td>";
  424.                                                 break;
  425.                 }
  426.                 $output .= "</tr>";
  427.             }
  428.             $output .= "</table></tr>";
  429.             echo $output;
  430.         }
  431.      ?>
  432.         </table>
  433.     </td>
  434. </tr>
  435. </table>
  436.  
  437. <?php
  438. $query_string = "?m=tasks&a=view&task_id=$task_id";
  439. $tabBox = new CTabBox( "?m=tasks&a=view&task_id=$task_id", "", $tab );
  440.  
  441. if ( $obj->task_dynamic == 0 ) {
  442.     // tabbed information boxes
  443.     $tabBox->add( "{$AppUI->cfg['root_dir']}/modules/tasks/vw_logs", 'Task Logs' );
  444.     // fixed bug that dP automatically jumped to access denied if user does not
  445.     // have read-write permissions on task_id and this tab is opened by default (session_vars)
  446.     // only if user has r-w perms on this task, new or edit log is beign showed
  447.     if (!getDenyEdit( $m, $task_id )) {
  448.         $tabBox->add( "{$AppUI->cfg['root_dir']}/modules/tasks/vw_log_update", 'New Log' );
  449.     }
  450.     $tabBox_show = 1;
  451. }
  452.  
  453. if ( count($obj->getChildren()) > 0 ) {
  454.     // Has children
  455.     // settings for tasks
  456.     $f = 'children';
  457.     $min_view = true;
  458.     $tabBox_show = 1;
  459.     $tabBox->add( "{$AppUI->cfg['root_dir']}/modules/tasks/tasks", 'Child Tasks' );
  460. }
  461.     
  462. if ( $tabBox_show == 1)    $tabBox->show();
  463. ?>
  464.