home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / tasks / addedit.php next >
Encoding:
PHP Script  |  2004-02-01  |  24.5 KB  |  711 lines

  1. <?php /* TASKS $Id: addedit.php,v 1.67 2004/02/01 08:24:28 gregorerhardt Exp $ */
  2. /**
  3. * Tasks :: Add/Edit Form
  4. *
  5. */
  6.  
  7. $task_id = intval( dPgetParam( $_GET, "task_id", 0 ) );
  8. $task_parent = intval( dPgetParam( $_GET, "task_parent", 0 ) );
  9.  
  10. // load the record data
  11. $obj = new CTask();
  12.  
  13. if (!$obj->load( $task_id ) && $task_id > 0) {
  14.     $AppUI->setMsg( 'Task' );
  15.     $AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
  16.     $AppUI->redirect();
  17. }
  18.  
  19. // check for a valid project parent
  20. $task_project = intval( $obj->task_project );
  21. if (!$task_project) {
  22.     $task_project = dPgetParam( $_GET, 'task_project', 0 );
  23.     if (!$task_project) {
  24.         $AppUI->setMsg( "badTaskProject", UI_MSG_ERROR );
  25.         $AppUI->redirect();
  26.     }
  27. }
  28.  
  29. // check permissions
  30. if ( $task_id ) {
  31.     // we are editing an existing task
  32.     $canEdit = !getDenyEdit( $m, $task_id );
  33. } else {
  34.     // we are trying to add a new task
  35.     
  36.     // do we have write access on this project?
  37.     $canEdit = ( !getDenyEdit( 'projects', $task_project ) );
  38.     
  39.     // Asumption: if a user has write access on a project, he will also
  40.     // be able to add tasks, files and events. There is no way for
  41.     // allowing someone to edit a project information and not editing
  42.     // its tasks, files and events.
  43. }
  44.  
  45. if (!$canEdit) {
  46.     $AppUI->redirect( "m=public&a=access_denied" );
  47. }
  48.  
  49. //check permissions for the associated project
  50. $canReadProject = !getDenyRead( 'projects', $obj->task_project);
  51.  
  52. $durnTypes = dPgetSysVal( 'TaskDurationType' );
  53.  
  54. // check the document access (public, participant, private)
  55. if (!$obj->canAccess( $AppUI->user_id )) {
  56.     $AppUI->redirect( "m=public&a=access_denied" );
  57. }
  58. $task_parent = isset( $obj->task_parent ) ? $obj->task_parent : $task_parent;
  59.  
  60. // format dates
  61. $df = $AppUI->getPref('SHDATEFORMAT');
  62.  
  63. $start_date = intval( $obj->task_start_date ) ? new CDate( $obj->task_start_date ) : null;
  64. $end_date = intval( $obj->task_end_date ) ? new CDate( $obj->task_end_date ) : null;
  65.  
  66. // pull the related project
  67. $project = new CProject();
  68. $project->load( $task_project );
  69.  
  70. //Pull all users
  71. $sql = "
  72. SELECT user_id, CONCAT_WS(' ',user_first_name,user_last_name)
  73. FROM users
  74. ORDER BY user_first_name, user_last_name
  75. ";
  76. $users = db_loadHashList( $sql );
  77.  
  78. if ( $task_id == 0 ) {
  79.     // Add task creator to assigned users by default
  80.     $assigned = array($AppUI->user_id => "$AppUI->user_first_name $AppUI->user_last_name");
  81. } else {
  82.     // Pull users on this task
  83.     $sql = "
  84.              SELECT u.user_id, CONCAT_WS(' ',u.user_first_name,u.user_last_name)
  85.                FROM users u, user_tasks t
  86.              WHERE t.task_id =$task_id
  87.              AND t.task_id <> 0
  88.              AND t.user_id = u.user_id
  89.              ";
  90.     $assigned = db_loadHashList( $sql );
  91. }
  92.  
  93. // Pull tasks for the parent task list
  94. $sql="
  95. SELECT task_id, task_name
  96. FROM tasks
  97. WHERE task_project = $task_project
  98.     AND task_id <> $task_id
  99. ORDER BY task_project
  100. ";
  101.  
  102.  
  103. $projTasks = array( $obj->task_id => $AppUI->_('None') );
  104. $res = db_exec( $sql );
  105. while ($row = db_fetch_row( $res )) {
  106.     /*
  107.     if (strlen( $row[1] ) > 30) {
  108.         $row[1] = substr( $row[1], 0, 27 ).'...';
  109.     }
  110.     */
  111.     $projTasks[$row[0]] = $row[1];
  112. }
  113.  
  114. // Pull tasks dependencies
  115. $sql = "
  116. SELECT t.task_id, t.task_name
  117. FROM tasks t, task_dependencies td
  118. WHERE td.dependencies_task_id = $task_id
  119.     AND t.task_id = td.dependencies_req_task_id
  120. ";
  121. $taskDep = db_loadHashList( $sql );
  122.  
  123. // setup the title block
  124. $ttl = $task_id > 0 ? "Edit Task" : "Add Task";
  125. $titleBlock = new CTitleBlock( $ttl, 'applet-48.png', $m, "$m.$a" );
  126. $titleBlock->addCrumb( "?m=tasks", "tasks list" );
  127. if ( $canReadProject ) {
  128.     $titleBlock->addCrumb( "?m=projects&a=view&project_id=$task_project", "view this project" );
  129. }
  130. if ($task_id > 0)
  131.   $titleBlock->addCrumb( "?m=tasks&a=view&task_id=$obj->task_id", "view this task" );
  132. $titleBlock->show();
  133.  
  134. // Let's gather all the necessary information from the department table
  135. // collect all the departments in the company
  136. $depts = array( 0 => '' );
  137.  
  138. // ALTER TABLE `tasks` ADD `task_departments` CHAR( 100 ) ;
  139. $company_id                = $project->project_company;
  140. $selected_departments      = $obj->task_departments != "" ? explode(",", $obj->task_departments) : array();
  141. $departments_count         = 0;
  142. $department_selection_list = getDepartmentSelectionList($company_id, $selected_departments);
  143. if($department_selection_list!=""){
  144.     $department_selection_list = "<select name='dept_ids[]' size='$departments_count' multiple style='width:12em'>
  145.                                   $department_selection_list
  146.                                   </select>";
  147. }
  148.  
  149. function getDepartmentSelectionList($company_id, $checked_array = array(), $dept_parent=0, $spaces = 0){
  150.     global $departments_count;
  151.     
  152.     if($departments_count < 10) $departments_count++;
  153.     $sql = "select dept_id, dept_name
  154.             from departments
  155.             where dept_parent      = '$dept_parent'
  156.                   and dept_company = '$company_id'";
  157.     $depts_list = db_loadHashList($sql, "dept_id");
  158.  
  159.     foreach($depts_list as $dept_id => $dept_info){
  160.         $selected = in_array($dept_id, $checked_array) ? "selected" : "";
  161.  
  162.         $parsed .= "<option value='$dept_id' $selected>".str_repeat(" ", $spaces).$dept_info["dept_name"]."</option>";
  163.         $parsed .= getDepartmentSelectionList($company_id, $checked_array, $dept_id, $spaces+5);
  164.     }
  165.     
  166.     return $parsed;
  167. }
  168.  
  169. //Dynamic tasks are by default now off because of dangerous behavior if incorrectly used
  170. if ( is_null($obj->task_dynamic) ) $obj->task_dynamic = 0 ;
  171.  
  172. //Time arrays for selects
  173. $start = $AppUI->getConfig('cal_day_start');
  174. $end   = $AppUI->getConfig('cal_day_end');
  175. $inc   = $AppUI->getConfig('cal_day_increment');
  176. if ($start === null ) $start = 8;
  177. if ($end   === null ) $end = 17;
  178. if ($inc   === null)  $inc = 15;
  179. $hours = array();
  180. for ( $current = $start; $current < $end + 1; $current++ ) {
  181.     if ( $current < 10 ) { 
  182.         $current_key = "0" . $current;
  183.     } else {
  184.         $current_key = $current;
  185.     }
  186.     
  187.     if ( stristr($AppUI->getPref('TIMEFORMAT'), "%p") ){
  188.         //User time format in 12hr
  189.         $hours[$current_key] = ( $current > 12 ? $current-12 : $current );
  190.     } else {
  191.         //User time format in 24hr
  192.         $hours[$current_key] = $current;
  193.     }
  194. }
  195.  
  196. $minutes = array();
  197. $minutes["00"] = "00";
  198. for ( $current = 0 + $inc; $current < 60; $current += $inc ) {
  199.     $minutes[$current] = $current;
  200. }
  201.  
  202. ?>
  203.  
  204. <SCRIPT language="JavaScript">
  205. var calendarField = '';
  206. var calWin = null;
  207. var selected_contacts_id = "<?= $obj->task_contacts; ?>";
  208.  
  209. function popContacts() {
  210.     window.open('./index.php?m=public&a=contact_selector&dialog=1&call_back=setContacts&company_id=<?php echo $company_id; ?>&selected_contacts_id='+selected_contacts_id, 'contacts','left=50,top=50,height=250,width=400,resizable,scrollbars=yes');
  211. }
  212.  
  213. function popCalendar( field ){
  214.     calendarField = field;
  215.     idate = eval( 'document.editFrm.task_' + field + '.value' );
  216.     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' );
  217. }
  218.  
  219. /**
  220.  *    @param string Input date in the format YYYYMMDD
  221.  *    @param string Formatted date
  222.  */
  223. function setCalendar( idate, fdate ) {
  224.     fld_date = eval( 'document.editFrm.task_' + calendarField );
  225.     fld_fdate = eval( 'document.editFrm.' + calendarField );
  226.     fld_date.value = idate;
  227.     fld_fdate.value = fdate;
  228. }
  229.  
  230. function setContacts(contact_id_string){
  231.     if(!contact_id_string){
  232.         contact_id_string = "";
  233.     }
  234.     document.editFrm.task_contacts.value = contact_id_string;
  235.     selected_contacts_id = contact_id_string;
  236. }
  237.  
  238. function submitIt(){
  239.     var form = document.editFrm;
  240.     var fl = form.assigned.length -1;
  241.     var dl = form.task_dependencies.length -1;
  242.  
  243.     if (form.task_name.value.length < 3) {
  244.         alert( "<?php echo $AppUI->_('taskName');?>" );
  245.         form.task_name.focus();
  246.     }
  247. <?php 
  248.     if ( $AppUI->getConfig( 'check_task_dates' )  ) {
  249. ?>
  250.     else if (!form.task_start_date.value) {
  251.         alert( "<?php echo $AppUI->_('taskValidStartDate');?>" );
  252.         form.task_start_date.focus();
  253.     }
  254.     else if (!form.task_end_date.value) {
  255.         alert( "<?php echo $AppUI->_('taskValidEndDate');?>" );
  256.         form.task_end_date.focus();
  257.     }
  258. <?php
  259.     }
  260. ?>    
  261.     else {
  262.         form.hassign.value = "";
  263.         for (fl; fl > -1; fl--){
  264.             form.hassign.value = "," + form.hassign.value +","+ form.assigned.options[fl].value
  265.         }
  266.  
  267.         form.hdependencies.value = "";
  268.         for (dl; dl > -1; dl--){
  269.             form.hdependencies.value = "," + form.hdependencies.value +","+ form.task_dependencies.options[dl].value
  270.         }
  271.  
  272.         if ( form.task_start_date.value.length > 0 ) {
  273.             form.task_start_date.value += form.start_hour.value + form.start_minute.value;
  274.         }
  275.         
  276.         if ( form.task_end_date.value.length > 0 ) {
  277.             form.task_end_date.value += form.end_hour.value + form.end_minute.value;
  278.         }
  279.         
  280.         form.submit();
  281.     }
  282. }
  283.  
  284. function addUser() {
  285.     var form = document.editFrm;
  286.     var fl = form.resources.length -1;
  287.     var au = form.assigned.length -1;
  288.     var users = "x";
  289.  
  290.     //build array of assiged users
  291.     for (au; au > -1; au--) {
  292.         users = users + "," + form.assigned.options[au].value + ","
  293.     }
  294.  
  295.     //Pull selected resources and add them to list
  296.     for (fl; fl > -1; fl--) {
  297.         if (form.resources.options[fl].selected && users.indexOf( "," + form.resources.options[fl].value + "," ) == -1) {
  298.             t = form.assigned.length
  299.             opt = new Option( form.resources.options[fl].text, form.resources.options[fl].value );
  300.             form.assigned.options[t] = opt
  301.         }
  302.     }
  303. }
  304.  
  305. function removeUser() {
  306.     var form = document.editFrm;
  307.     fl = form.assigned.length -1;
  308.  
  309.     for (fl; fl > -1; fl--) {
  310.         if (form.assigned.options[fl].selected) {
  311.             form.assigned.options[fl] = null;
  312.         }
  313.     }
  314. }
  315.  
  316. function addTaskDependency() {
  317.     var form = document.editFrm;
  318.     var at = form.all_tasks.length -1;
  319.     var td = form.task_dependencies.length -1;
  320.     var tasks = "x";
  321.  
  322.     //build array of task dependencies
  323.     for (td; td > -1; td--) {
  324.         tasks = tasks + "," + form.task_dependencies.options[td].value + ","
  325.     }
  326.  
  327.     //Pull selected resources and add them to list
  328.     for (at; at > -1; at--) {
  329.         if (form.all_tasks.options[at].selected && tasks.indexOf( "," + form.all_tasks.options[at].value + "," ) == -1) {
  330.             t = form.task_dependencies.length
  331.             opt = new Option( form.all_tasks.options[at].text, form.all_tasks.options[at].value );
  332.             form.task_dependencies.options[t] = opt
  333.         }
  334.     }
  335. }
  336.  
  337. function removeTaskDependency() {
  338.     var form = document.editFrm;
  339.     td = form.task_dependencies.length -1;
  340.  
  341.     for (td; td > -1; td--) {
  342.         if (form.task_dependencies.options[td].selected) {
  343.             form.task_dependencies.options[td] = null;
  344.         }
  345.     }
  346. }
  347.  
  348. function setAMPM( field) {
  349.     if ( field.value > 11 ){
  350.         document.editFrm[field.name + "_ampm"].value = "pm";
  351.     } else {
  352.         document.editFrm[field.name + "_ampm"].value = "am";
  353.     }
  354. }
  355.  
  356. var workHours = <?php echo $AppUI->getConfig( 'daily_working_hours' );?>;
  357. var hourMSecs = 3600*1000;
  358.  
  359. function calcDuration() {
  360.     var f = document.editFrm;
  361.     var int_st_date = new String(f.task_start_date.value);
  362.     var int_en_date = new String(f.task_end_date.value);
  363.  
  364.     var s = Date.UTC(int_st_date.substring(0,4),(int_st_date.substring(4,6)-1),int_st_date.substring(6,8));
  365.     var e = Date.UTC(int_en_date.substring(0,4),(int_en_date.substring(4,6)-1),int_en_date.substring(6,8));
  366.     var durn = (e - s) / hourMSecs;
  367.     var durnType = parseFloat(f.task_duration_type.value);
  368.     durn /= durnType;
  369.  
  370.     if (durnType == 1)
  371.         durn *= (workHours / 24);
  372.  
  373.     if ( s > e )
  374.         alert( 'End date is before start date!');
  375.     else
  376.         f.task_duration.value = Math.round(durn);
  377.  
  378. }
  379.  
  380. function calcFinish() {
  381.     var f = document.editFrm;
  382.     var int_st_date = new String(f.task_start_date.value);
  383.  
  384.     var s = new Date(int_st_date.substring(0,4),eval(int_st_date.substring(4,6))-1,int_st_date.substring(6,8));
  385.     var durn = parseFloat(f.task_duration.value);
  386.     var durnType = parseFloat(f.task_duration_type.value);
  387.     var inc = durn;
  388.  
  389.     if (durnType == 1)
  390.         inc /= workHours;
  391.  
  392.     var e = s;
  393.     e.setDate( s.getDate() + Math.round(inc) );
  394.  
  395.     var tz1 = "";
  396.     var tz2 = "";
  397.  
  398.     if ( e.getDate() < 10 ) tz1 = "0";
  399.     if ( (e.getMonth()+1) < 10 ) tz2 = "0";
  400.  
  401.     f.task_end_date.value = e.getUTCFullYear()+tz2+(e.getMonth()+1)+tz1+e.getDate();
  402.     f.end_date.value = tz1+e.getDate()+"/"+tz2+(e.getMonth()+1)+"/"+e.getUTCFullYear();
  403.  
  404. }
  405.  
  406. </script>
  407.  
  408. <table border="1" cellpadding="4" cellspacing="0" width="100%" class="std">
  409. <form name="editFrm" action="?m=tasks&project_id=<?php echo $task_project;?>" method="post">
  410.     <input name="dosql" type="hidden" value="do_task_aed" />
  411.     <input name="task_id" type="hidden" value="<?php echo $task_id;?>" />
  412.     <input name="task_project" type="hidden" value="<?php echo $task_project;?>" />
  413.     <input name='task_contacts' type='hidden' value="<?php echo $obj->task_contacts; ?>" />
  414. <tr>
  415.     <td colspan="2" style="border: outset #eeeeee 1px;background-color:#<?php echo $project->project_color_identifier;?>" >
  416.         <font color="<?php echo bestColor( $project->project_color_identifier ); ?>">
  417.             <strong><?php echo $AppUI->_('Project');?>: <?php echo @$project->project_name;?></strong>
  418.         </font>
  419.     </td>
  420. </tr>
  421.  
  422. <tr valign="top" width="50%">
  423.     <td>
  424.         <?php echo $AppUI->_( 'Task Name' );?> *
  425.         <br /><input type="text" class="text" name="task_name" value="<?php echo dPformSafe( $obj->task_name );?>" size="40" maxlength="255" />
  426.     </td>
  427.     <td>
  428.         <table cellspacing="0" cellpadding="2" border="0" width="100%">
  429.         <tr>
  430.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Status' );?></td>
  431.             <td>
  432.                 <?php echo arraySelect( $status, 'task_status', 'size="1" class="text"', $obj->task_status, true );?>
  433.             </td>
  434.  
  435.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Priority' );?> *</td>
  436.             <td nowrap>
  437.                 <?php echo arraySelect( $priority, 'task_priority', 'size="1" class="text"', $obj->task_priority, true );?>
  438.             </td>
  439.         </tr>
  440.         <tr>
  441.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Progress' );?></td>
  442.             <td>
  443.                 <?php echo arraySelect( $percent, 'task_percent_complete', 'size="1" class="text"', $obj->task_percent_complete ) . '%';?>
  444.             </td>
  445.  
  446.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Milestone' );?>?</td>
  447.             <td>
  448.                 <input type="checkbox" value=1 name="task_milestone" <?php if($obj->task_milestone){?>checked<?php }?> />
  449.             </td>
  450.         </tr>
  451.         </table>
  452.     </td>
  453. </tr>
  454. <tr valign="top">
  455.     <td width="50%">
  456.         <table>
  457.             <tr>
  458.                 <td>
  459.                     <?php echo $AppUI->_( 'Task Creator' );?>
  460.                     <br />
  461.                 <?php echo arraySelect( $users, 'task_owner', 'class="text"', !isset($obj->task_owner) ? $AppUI->user_id : $obj->task_owner );?>
  462.                     <br />
  463.                     <?php echo $AppUI->_( 'Access' );?>
  464.                     <br />
  465.                     <?php echo arraySelect( $task_access, 'task_access', 'class="text"', intval( $obj->task_access ), true );?>
  466.                     <br /><br /><?php echo $AppUI->_( 'Web Address' );?>
  467.                     <br /><input type="text" class="text" name="task_related_url" value="<?php echo @$obj->task_related_url;?>" size="40" maxlength="255" />
  468.                     <br />
  469.                 </td>
  470.                 <td>
  471.                     <?php
  472.                         // Let's check if the actual company has departments registered
  473.                         if($department_selection_list != ""){
  474.                             ?>
  475.                                     <?php echo $AppUI->_("Departments"); ?><br />
  476.                                     <?php echo $department_selection_list; ?>
  477.                                     <?php echo "<hr />"; ?>
  478.                             <?php
  479.                         }
  480.                         
  481.                         // Let's check if there are available contacts for this company
  482.                         $sql = "select c.company_name
  483.                                 from companies as c, tasks as t, projects as p
  484.                                 where t.task_id = $task_id
  485.                                       and t.task_project = p.project_id
  486.                                       and p.project_company = company_id";
  487.                         $company_name = db_loadResult($sql);
  488.                         
  489.                         if($department_selection_list != "" || !is_null($company_name) ) {
  490.                             echo "<input type='button' class='button' value='".$AppUI->_("Select contacts...")."' onclick='javascript:popContacts();' />";
  491.                         }
  492.                     ?>
  493.                 </td>
  494.             </tr>
  495.         </table>
  496.         <table>
  497.         <tr>
  498.             <td><?php echo $AppUI->_( 'Task Parent' );?>:</td>
  499.             <td><img src="./images/shim.gif" width="30" height="1"></td>
  500.             <td><?php echo $AppUI->_( 'Target Budget' );?></td>
  501.         </tr>
  502.         <tr>
  503.             <td>
  504.                 <?php echo arraySelect( $projTasks, 'task_parent', 'class="text"', $task_parent ); ?>
  505.             </td>
  506.             <td><img src="./images/shim.gif" width=30 height=1></td>
  507.             <td><?php echo $dPconfig['currency_symbol'] ?><input type="text" class="text" name="task_target_budget" value="<?php echo @$obj->task_target_budget;?>" size="10" maxlength="10" /></td>
  508.         </tr>
  509.         </table>
  510.     </td>
  511.     <td  align="center" width="50%">
  512.         <table cellspacing="0" cellpadding="2" border="0">
  513.             <tr>
  514.                 <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Start Date' );?></td>
  515.                 <td nowrap="nowrap">
  516.                     <input type="hidden" name="task_start_date" value="<?php echo $start_date ? $start_date->format( FMT_TIMESTAMP_DATE ) : "" ;?>" />
  517.                     <input type="text" name="start_date" value="<?php echo $start_date ? $start_date->format( $df ) : "" ;?>" class="text" disabled="disabled" />
  518.                     <a href="#" onClick="popCalendar('start_date')">
  519.                         <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0">
  520.                     </a>
  521.                 </td>
  522.                 <td>
  523.                     <table><tr>
  524.                         
  525.                 <?php
  526.                     echo "<td>" . arraySelect($hours, "start_hour",'size="1" onchange="setAMPM(this)" class="text"', $start_date ? $start_date->getHour() : $start ) . "</td><td>" . " : " . "</td>";
  527.                     echo "<td>" . arraySelect($minutes, "start_minute",'size="1" class="text"', $start_date ? $start_date->getMinute() : "0" ) . "</td>";
  528.                     if ( stristr($AppUI->getPref('TIMEFORMAT'), "%p") ) {
  529.                         echo '<td><input type="text" name="start_hour_ampm" value="' . ( $start_date ? $start_date->getAMPM() : ( $start > 11 ? "pm" : "am" ) ) . '" disabled="disabled" class="text" size="2" /></td>';
  530.                     }
  531.                 ?>
  532.                     </tr></table>
  533.                 </td>
  534.             </tr>
  535.             <tr>
  536.                 <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Finish Date' );?></td>
  537.                 <td nowrap="nowrap">
  538.                     <input type="hidden" name="task_end_date" value="<?php echo $end_date ? $end_date->format( FMT_TIMESTAMP_DATE ) : '';?>" />
  539.                     <input type="text" name="end_date" value="<?php echo $end_date ? $end_date->format( $df ) : '';?>" class="text" disabled="disabled" />
  540.                     <a href="#" onClick="popCalendar('end_date')">
  541.                         <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0">
  542.                     </a>
  543.                 </td>
  544.                 <td>
  545.                 <table><tr>
  546.                 <?php
  547.                     echo "<td>" . arraySelect($hours, "end_hour",'size="1" onchange="setAMPM(this)" class="text"', $end_date ? $end_date->getHour() : $end ) . "</td><td>" . " : " . "</td>";
  548.                     echo "<td>" .arraySelect($minutes, "end_minute",'size="1" class="text"', $end_date ? $end_date->getMinute() : "00" ) . "</td>";
  549.                     if ( stristr($AppUI->getPref('TIMEFORMAT'), "%p") ) {
  550.                         echo '<td><input type="text" name="end_hour_ampm" value="' . ( $end_date ? $end_date->getAMPM() : ( $end > 11 ? "pm" : "am" ) ) . '" disabled="disabled" class="text" size="2" /></td>';
  551.                     }
  552.                 ?>
  553.                 </tr></table>
  554.                 </td>
  555.             </tr>
  556.             <tr>
  557.                 <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Expected Duration' );?>:</td>
  558.                 <td nowrap="nowrap">
  559.                     <input type="text" class="text" name="task_duration" maxlength="8" size="6" value="<?php echo $obj->task_duration ? $obj->task_duration : 1;?>" />
  560.                 <?php
  561.                     echo arraySelect( $durnTypes, 'task_duration_type', 'class="text"', $obj->task_duration_type, true );
  562.                 ?>
  563.                 </td>
  564.             </tr>
  565.             <tr>
  566.                 <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Calculate' );?>:</td>
  567.                 <td nowrap="nowrap">
  568.                     <input type="button" value="<?php echo $AppUI->_('Duration');?>" onclick="calcDuration()" class="button" />
  569.                     <input type="button" value="<?php echo $AppUI->_('Finish Date');?>" onclick="calcFinish()" class="button" />
  570.                 </td>
  571.             </tr>
  572.             <tr>
  573.                 <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Dynamic Task' );?>?</td>
  574.                 <td nowrap="nowrap">
  575.                     <input type="checkbox" name="task_dynamic" value="1" <?php if($obj->task_dynamic!="0") echo "checked"?> />
  576.                 </td>
  577.             </tr>
  578.         </table>
  579.     </td>
  580. </tr>
  581. <tr>
  582.     <td valign="top" align="center">
  583.         <table cellspacing="0" cellpadding="2" border="0">
  584.             <tr>
  585.                 <td><?php echo $AppUI->_( 'All Tasks' );?></td>
  586.                 <td><?php echo $AppUI->_( 'Task Dependencies' );?></td>
  587.             </tr>
  588.             <tr>
  589.                 <td>
  590.                     <?php echo arraySelect( $projTasks, 'all_tasks', 'style="width:180px" size="10" style="font-size:9pt;" multiple="multiple"', null ); ?>
  591.                 </td>
  592.                 <td>
  593.                     <?php echo arraySelect( $taskDep, 'task_dependencies', 'style="width:180px" size="10" style="font-size:9pt;" multiple="multiple"', null ); ?>
  594.                 </td>
  595.             </tr>
  596.             <tr>
  597.                 <td align="right"><input type="button" class="button" value=">" onClick="addTaskDependency()" /></td>
  598.                 <td align="left"><input type="button" class="button" value="<" onClick="removeTaskDependency()" /></td>
  599.             </tr>
  600.         </table>
  601.     </td>
  602.     <td valign="top" align="center">
  603.         <table cellspacing="0" cellpadding="2" border="0">
  604.             <tr>
  605.                 <td><?php echo $AppUI->_( 'Resources' );?></td>
  606.                 <td><?php echo $AppUI->_( 'Assigned to Task' );?></td>
  607.             </tr>
  608.             <tr>
  609.                 <td>
  610.                     <?php echo arraySelect( $users, 'resources', 'style="width:180px" size="10" style="font-size:9pt;" multiple="multiple"', null ); ?>
  611.                 </td>
  612.                 <td>
  613.                     <?php echo arraySelect( $assigned, 'assigned', 'style="width:180px" size="10" style="font-size:9pt;" multiple="multiple"', null ); ?>
  614.                 </td>
  615.             <tr>
  616.                 <td align="right"><input type="button" class="button" value=">" onClick="addUser()" /></td>
  617.                 <td align="left"><input type="button" class="button" value="<" onClick="removeUser()" /></td>
  618.             </tr>
  619.             </tr>
  620.             <tr>
  621.                 <td colspan=3 align="center">
  622.                     <input type="checkbox" name="task_notify" value="1" <?php if($obj->task_notify!="0") echo "checked"?> /> <?php echo $AppUI->_( 'notifyChange' );?>
  623.                 </td>
  624.             </tr>
  625.         </table>
  626.     </td>
  627. </tr>
  628. <tr>
  629.     <td valign="top">
  630.         <?php echo $AppUI->_( 'Description' );?>:
  631.         <br />
  632.         <textarea name="task_description" class="textarea" cols="60" rows="10" wrap="virtual"><?php echo @$obj->task_description;?></textarea>
  633.     </td>
  634.     <td align="center">
  635. <?php
  636.     $custom_fields = dPgetSysVal("TaskCustomFields");
  637.     if ( count($custom_fields) > 0 ){
  638.         //We have custom fields, parse them!
  639.         //Custom fields are stored in the sysval table under TaskCustomFields, the format is
  640.         //key|serialized array of ("name", "type", "options", "selects")
  641.         //Ej: 0|a:3:{s:4:"name";s:22:"Quote number";s:4:"type";s:4:"text";s:7:"options";s:24:"maxlength="12" size="10"";} 
  642.         if ( $obj->task_custom != "" || !is_null($obj->task_custom))  {
  643.             //Custom info previously saved, retrieve it
  644.             $custom_field_previous_data = unserialize($obj->task_custom);
  645.         }
  646.         
  647.         $output = '<table cellspacing="0" cellpadding="2" border="0">';
  648.         foreach ( $custom_fields as $key => $array) {
  649.             $output .= "<tr colspan='3' valign='top' id='custom_tr_$key' >";
  650.             $field_options = unserialize($array);
  651.             $output .= "<td align='right' nowrap='nowrap' >". ($field_options["type"] == "label" ? "<strong>". $field_options['name']. "</strong>" : $field_options['name']) . ":" ."</td>";
  652.             switch ( $field_options["type"]){
  653.                 case "text":
  654.                     $output .= "<td align='left'><input type='text' name='custom_$key' class='text'" . $field_options["options"] . "value='" . ( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "") . "' /></td>";
  655.                     break;
  656.                 case "select":
  657.                     $output .= "<td align='left'>". arraySelect(explode(",",$field_options["selects"]), "custom_$key", 'size="1" class="text" ' . $field_options["options"] ,( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "")) . "</td>";
  658.                     break;
  659.                 case "textarea":
  660.                     $output .=  "<td align='left'><textarea name='custom_$key' class='textarea'" . $field_options["options"] . ">" . ( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "") . "</textarea></td>";
  661.                     break;
  662.                 case "checkbox":
  663.                     $options_array = explode(",",$field_options["selects"]);
  664.                     $output .= "<td align='left'>";
  665.                     foreach ( $options_array as $option ) {
  666.                         if ( isset($custom_field_previous_data[$key]) && array_key_exists( $option, array_flip($custom_field_previous_data[$key]) ) ) {
  667.                             $checked = "checked";
  668.                         } 
  669.                         $output .=  "<input type='checkbox' value='$option' name='custom_" . $key ."[]' class='text' style='border:0' $checked " . $field_options["options"] . ">$option<br />";
  670.                         $checked = "";
  671.                     }
  672.                     $output .= "</td>";
  673.                     break;
  674.             }
  675.             $output .= "</tr>";
  676.         }
  677.         $output .= "</table>";
  678.         echo $output;
  679.     }
  680. ?>
  681.     </td>
  682. </tr>
  683. </table>
  684.  
  685. <table border="0" cellspacing="0" cellpadding="3" width="100%">
  686. <tr>
  687.     <td height="40" width="35%">
  688.         * <?php echo $AppUI->_( 'requiredField' );?>
  689.     </td>
  690.     <td height="40" width="30%"> </td>
  691.     <td  height="40" width="35%" align="right">
  692.         <table>
  693.         <tr>
  694.             <td>
  695.                 <input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel');?>" onClick="javascript:if(confirm('<?php echo $AppUI->_('taskCancel');?>')){location.href = '?<?php echo $AppUI->getPlace();?>';}" />
  696.             </td>
  697.             <td>
  698.                 <input class="button" type="button" name="btnFuseAction" value="<?php echo $AppUI->_('save');?>" onClick="submitIt();" />
  699.             </td>
  700.         </tr>
  701.         </table>
  702.     </td>
  703. </tr>
  704. </table>
  705. <input type="hidden" name="hassign" />
  706. <input type="hidden" name="hdependencies" />
  707. </form>
  708.  
  709. </body>
  710. </html>
  711.