示例#1
0
 function create_task($name, $start, $end, $project_id, $milestone_flag, $status, $project_task_id, $predecessors, $rel_type, $duration, $duration_unit, $resource, $percent_complete, $description, $actual_duration, $order_number)
 {
     $task = new AM_TaskTemplates();
     $task->name = $name;
     //$task->date_start = $start;
     //$task->date_finish = $end;
     //$task->project_id = $project_id;
     $task->milestone_flag = $milestone_flag;
     $task->status = $status;
     $task->task_number = $project_task_id;
     $task->predecessors = $predecessors;
     $task->relationship_type = $rel_type;
     $task->duration = $duration + 1;
     //+1 to make duration appear correct in project table
     //$task->duration_unit = $duration_unit;
     $task->assigned_user_id = $resource;
     $task->percent_complete = $percent_complete;
     $task->description = $description;
     //$task->actual_duration = $actual_duration;
     $task->order_number = $order_number;
     $task_id = $task->save();
     $project_template = new AM_ProjectTemplates();
     $project_template->retrieve($project_id);
     $project_template->load_relationship('am_tasktemplates_am_projecttemplates');
     $project_template->get_linked_beans('am_tasktemplates_am_projecttemplates', 'AM_TaskTemplates');
     $project_template->am_tasktemplates_am_projecttemplates->add($task_id);
 }
    public function display()
    {
        global $db, $mod_strings, $app_list_strings;
        echo '<link rel="stylesheet" type="text/css" href="modules/AM_ProjectTemplates/css/style.css" />';
        echo '<link rel="stylesheet" type="text/css" href="modules/AM_ProjectTemplates/qtip/jquery.qtip.min.css" />';
        echo '<script type="text/javascript" src="modules/AM_ProjectTemplates/js/splitter.js"></script>';
        echo '<script type="text/javascript" src="modules/AM_ProjectTemplates/js/jquery.blockUI.js"></script>';
        echo '<script type="text/javascript" src="modules/AM_ProjectTemplates/js/jquery.validate.min.js"></script>';
        echo '<script type="text/javascript" src="modules/AM_ProjectTemplates/js/main_lib.js"></script>';
        $project_template = new AM_ProjectTemplates();
        if (!isset($_REQUEST["record"]) || trim($_REQUEST["record"]) == "") {
            $_REQUEST["record"] = $_REQUEST["project_id"];
        }
        $project_template->retrieve($_REQUEST["record"]);
        //Get project_template resources (users & contacts)
        $resources1 = $project_template->get_linked_beans('am_projecttemplates_users_1', 'User');
        $resources2 = $project_template->get_linked_beans('am_projecttemplates_contacts_1', 'Contact');
        //Combine resources into array of objects
        $resource_array = array();
        foreach ($resources1 as $user) {
            $resource = new stdClass();
            $resource->id = $user->id;
            $resource->name = $user->name;
            $resource->type = 'user';
            $resource_array[] = $resource;
        }
        foreach ($resources2 as $contact) {
            $resource = new stdClass();
            $resource->id = $contact->id;
            $resource->name = $contact->name;
            $resource->type = 'contact';
            $resource_array[] = $resource;
        }
        //Get the start and end date of the project in database format
        $start_date = Date('Y-m-d');
        $end_date = Date('Y-m-d', strtotime("+30 days"));
        ?>
        <!--Create task pop-up-->
        <div style="display: none;">
            <div id="dialog"  title="<?php 
        echo $mod_strings['LBL_ADD_NEW_TASK'];
        ?>
">
                <p>
                    <?php 
        echo $mod_strings['LBL_EDIT_TASK_PROPERTIES'];
        ?>
                </p>
                <form id="popup_form">
                    <fieldset>
						<table width="100%">
							<tr><td width="50%">
						
							<input type="hidden" name="project_template_id" id="project_template_id" value="<?php 
        echo $project_template->id;
        ?>
">
							<input type="hidden" name="override_business_hours" id="override_business_hours" value="<?php 
        echo $project_template->override_business_hours;
        ?>
">
							<input type="text" style="display: none;" name="task_id" id="task_id" value="">
							<input type="radio" name="Milestone" value="Subtask" checked="checked" id="Subtask" />
							<label id="Subtask_label" for="Subtask"><?php 
        echo $mod_strings['LBL_SUBTASK'];
        ?>
</label>
							<input type="radio" name="Milestone" value="Milestone" id="Milestone" />
							<label id="Milestone_label" for="Milestone"><?php 
        echo $mod_strings['LBL_MILESTONE_FLAG'];
        ?>
</label>&nbsp;<br /><br />
							<label id="parent_task_id" for="parent_task" style="display: none;"><?php 
        echo $mod_strings['LBL_PARENT_TASK_ID'];
        ?>
</label>
							<input id="parent_task" class="text ui-widget-content ui-corner-all" style="display: none;" type="text" name="parent_task" value="" />
							<label for="name"><?php 
        echo $mod_strings['LBL_TASK_NAME'];
        ?>
</label>
							<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
							<label for="Predecessor"><?php 
        echo $mod_strings['LBL_PREDECESSORS'];
        ?>
</label>
							<?php 
        echo '<select id="Predecessor" name="Predecessor" class="text ui-widget-content ui-corner-all" />';
        foreach ($tasks as $task) {
            echo '<option rel="' . $task->id . '" value="' . $task->order_number . '">' . $task->name . '</opion>';
        }
        echo '</select>';
        ?>
							<label for="relation_type"><?php 
        echo $mod_strings['LBL_RELATIONSHIP_TYPE'];
        ?>
</label>
							<?php 
        echo '<select id="relation_type" name="relation_type" class="text ui-widget-content ui-corner-all">
									' . get_select_options_with_id($app_list_strings['relationship_type_list'], '') . '
							</select>';
        ?>

					
						</td><td width="50%"> 

							<label for="Duration"><?php 
        echo $mod_strings['LBL_DURATION_TITLE'];
        ?>
</label>
							<input type="text" name="Duration" id="Duration" class="text ui-widget-content ui-corner-all" />
							<select id="Duration_unit" name="Duration_unit" class="text ui-widget-content ui-corner-all" />
								<option value="Days">Days</option>
							</select>

							<label for="Resources"><?php 
        echo $mod_strings['LBL_ASSIGNED_USER_ID'];
        ?>
</label>
							<?php 
        echo '<select id="Resources" name="Resources" class="text ui-widget-content ui-corner-all" />';
        echo '<option value="0">' . $mod_strings['LBL_UNASSIGNED'] . '</option>';
        foreach ($resource_array as $resource) {
            echo '<option rel="' . $resource->type . '" value="' . $resource->id . '">' . $resource->name . '</opion>';
        }
        echo '</select>';
        ?>
							<label for="%Complete"><?php 
        echo $mod_strings['LBL_PERCENT_COMPLETE'];
        ?>
</label>
							<input type="text" name="Complete" id="Complete" value="0" class="text ui-widget-content ui-corner-all" />
							<input type="hidden" name="Notes" id="Notes" />
							<!--label for="Notes"><?php 
        echo $mod_strings['LBL_DESCRIPTION'];
        ?>
</label>
							<textarea id="Notes" cols="34" name="Notes" class="text ui-widget-content ui-corner-all"></textarea-->
						</td>
						</tr>
						</table>
					</fieldset>
                </form>
            </div>
            <!--Delete task pop-up-->
            <div id="delete_dialog" title="<?php 
        echo $mod_strings['LBL_DELETE_TASK'];
        ?>
">
                <p>
                    Are you sure you want to delete this task?
                </p>
            </div>
        </div>
        <!-- Pop-up End -->


        <!--Mark-up for the main body of the view-->
        
			<div class="moduleTitle">
				<h2> <?php 
        echo $project_template->name;
        ?>
 </h2>
				<div class="clear"></div><br>
				<a class="utilsLink" href="index.php?module=AM_ProjectTemplates&action=DetailView&record=<?php 
        echo $_REQUEST["record"];
        ?>
&return_module=AM_ProjectTemplates&return_action=view_GanttChart" id="create_link"><?php 
        echo $mod_strings['LBL_VIEW_DETAIL'];
        ?>
</a></span>
				<span class="utils">&nbsp; 
				
				<div class="clear"></div>
			</div>

			<div class="yui-navset detailview_tabs yui-navset-top" id="Project_detailview_tabs">
				<!--ul class="yui-nav"-->
				<div class="yui-content">    
					<div id="tabcontent0">
						<div id="detailpanel_1" class="detail view  detail508 expanded">
							<table id="project_information" class="panelContainer" cellspacing="0">
							<tbody
							<tr>
							<td scope="col" width="12.5%"><?php 
        echo $mod_strings['LBL_VIEW_GANTT_DURATION'];
        ?>
</td>
							<td class="inlineEdit" width="37.5%"><?php 
        echo $this->time_range($start_date, $end_date);
        ?>
</td>
							<td scope="col" width="12.5%"><?php 
        echo $mod_strings['LBL_STATUS'];
        ?>
</td>
							<td class="inlineEdit" width="37.5%"><?php 
        echo $app_list_strings['project_status_dom'][$project_template->status];
        ?>
</td>
							</tr>
							<tr>
							<td scope="col" width="12.5%"><?php 
        echo $mod_strings['LBL_ASSIGNED_USER_NAME'];
        ?>
</td>
							<td class="inlineEdit" width="37.5%"><?php 
        echo $project_template->assigned_user_name;
        ?>
</td>
							<td scope="col" width="12.5%"><?php 
        echo $mod_strings['LBL_PRIORITY'];
        ?>
</td>
							<td class="" width="37.5%"><?php 
        echo $project_template->priority;
        ?>
</td>
							</tr>
							<!--tr>
							<td scope="col" width="12.5%"><?php 
        echo $mod_strings['LBL_DESCRIPTION'];
        ?>
</td>
							<td class="inlineEdit" type="text" colspan="3" width="87.5%"><?php 
        echo $project_template->description;
        ?>
</td>
							</tr-->
							</tbody></table>
						</div>
					</div>
				</div>
				<br>
				<?php 
        if (ACLController::checkAccess('AM_ProjectTemplates', 'edit', true)) {
            echo '<button id="add_button" class="gantt_button">' . $mod_strings['LBL_ADD_NEW_TASK'] . '</button>';
            echo '<input id="is_editable" name="is_editable" type="hidden" value="1" >';
        }
        ?>
			</div>


        <div id="wrapper" >

            <input id="record" type="hidden" name="record" value="<?php 
        echo $_REQUEST["record"];
        ?>
" />
            <div id="project_wrapper">

            </div>
        </div>
        <!--Main body end-->
<?php 
    }
示例#3
0
 function action_create_project()
 {
     global $current_user, $db;
     $project_name = $_POST['p_name'];
     $template_id = $_POST['template_id'];
     $project_start = $_POST['start_date'];
     //Get project start date
     $dateformat = $current_user->getPreference('datef');
     $startdate = DateTime::createFromFormat($dateformat, $project_start);
     $start = $startdate->format('Y-m-d');
     $duration_unit = 'Days';
     //$GLOBALS['log']->fatal("name:". $project_name." id:".$template_id);
     //Get the project template
     $template = new AM_ProjectTemplates();
     $template->retrieve($template_id);
     //create project from template
     $project = new Project();
     $project->name = $project_name;
     $project->estimated_start_date = $start;
     $project->status = $template->status;
     $project->priority = $template->priority;
     $project->description = $template->description;
     $project->assigned_user_id = $template->assigned_user_id;
     $project->save();
     $template->load_relationship('am_projecttemplates_project_1');
     $template->am_projecttemplates_project_1->add($project->id);
     //Get related project template tasks. Using sql query so that the results can be ordered.
     $get_tasks = "SELECT * FROM am_tasktemplates\n                        WHERE id\n                        IN (\n                            SELECT am_tasktemplates_am_projecttemplatesam_tasktemplates_idb\n                            FROM am_tasktemplates_am_projecttemplates_c\n                            WHERE am_tasktemplates_am_projecttemplatesam_projecttemplates_ida = '" . $template_id . "'\n                            AND deleted =0\n                        )\n                        AND deleted =0\n                        ORDER BY am_tasktemplates.order_number ASC";
     $tasks = $db->query($get_tasks);
     //Create new project tasks from the template tasks
     $count = 1;
     while ($row = $db->fetchByAssoc($tasks)) {
         $project_task = new ProjectTask();
         $project_task->name = $row['name'];
         $project_task->status = $row['status'];
         $project_task->priority = $row['priority'];
         $project_task->percent_complete = $row['percent_complete'];
         $project_task->predecessors = $row['predecessors'];
         $project_task->milestone_flag = $row['milestone_flag'];
         $project_task->relationship_type = $row['relationship_type'];
         $project_task->task_number = $row['task_number'];
         $project_task->order_number = $row['order_number'];
         $project_task->estimated_effort = $row['estimated_effort'];
         $project_task->utilization = $row['utilization'];
         $project_task->assigned_user_id = $row['assigned_user_id'];
         $project_task->description = $row['description'];
         $project_task->duration = $row['duration'];
         $project_task->project_task_id = $count;
         //Flag to prevent after save logichook running when project_tasks are created (see custom/modules/ProjectTask/updateProject.php)
         $project_task->set_project_end_date = 0;
         if ($count == '1') {
             $project_task->date_start = $start;
             $enddate = $startdate->modify('+' . $row['duration'] . ' ' . $duration_unit);
             $end = $enddate->format('Y-m-d');
             $project_task->date_finish = $end;
             $enddate_array[$count] = $end;
             $GLOBALS['log']->fatal("DATE:" . $end);
         } else {
             $start_date = $count - 1;
             $startdate = DateTime::createFromFormat('Y-m-d', $enddate_array[$start_date]);
             $GLOBALS['log']->fatal("DATE:" . $enddate_array[$start_date]);
             $start = $startdate->format('Y-m-d');
             $project_task->date_start = $start;
             $enddate = $startdate->modify('+' . $row['duration'] . ' ' . $duration_unit);
             $end = $enddate->format('Y-m-d');
             $project_task->date_finish = $end;
             $enddate = $end;
             $enddate_array[$count] = $end;
         }
         $project_task->save();
         //link tasks to the newly created project
         $project_task->load_relationship('projects');
         $project_task->projects->add($project->id);
         //Add assinged users from each task to the project resourses subpanel
         $project->load_relationship('project_users_1');
         $project->project_users_1->add($row['assigned_user_id']);
         $count++;
     }
     //set project end date to the same as end date of the last task
     $project->estimated_end_date = $end;
     $project->save();
     //redirct to new project
     SugarApplication::appendErrorMessage('New project created.');
     $params = array('module' => 'Project', 'action' => 'DetailView', 'record' => $project->id);
     SugarApplication::redirect('index.php?' . http_build_query($params));
 }
示例#4
0
 public function draw($project_template_id, $tasks)
 {
     global $mod_strings, $app_list_strings;
     // Instantiate the TimeDate Class
     $timeDate = new TimeDate();
     echo '<table id="Task_table" class="project_table_header">
             <tr class="disable_sort">
                 <td style="min-width:32px;" class="project_table_headings">' . $mod_strings['LBL_TASK_ID'] . '</td>
                 <td style="min-width:85px;" class="project_table_headings">' . $mod_strings['LBL_TASK_NAME'] . '</td>
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_PREDECESSORS'] . '</td>
                 <!-- td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_START'] . '</td>
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_FINISH'] . '</td -->
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_DURATION'] . '</td>
                 <td style="min-width:120px;" class="project_table_headings">' . $mod_strings['LBL_ASSIGNED_USER_ID'] . '</td>
                 <td style="min-width:48px;" class="project_table_headings">' . $mod_strings['LBL_PERCENT_COMPLETE'] . '</td>
                 <td style="min-width:80px;" class="project_table_headings">' . $mod_strings['LBL_MILESTONE_FLAG'] . '</td>
                 <td style="min-width:30px;" class="project_table_headings"></td>
             </tr>
     ';
     $task_count = 0;
     //Get resources
     $project_template = new AM_ProjectTemplates();
     $project_template->retrieve($project_template_id);
     //Get project resources (users & contacts)
     $resources1 = $project_template->get_linked_beans('am_projecttemplates_users_1', 'User');
     $resources2 = $project_template->get_linked_beans('am_projecttemplates_contacts_1', 'Contact');
     //Combine resources into array of objects
     $resource_array = array();
     foreach ($resources1 as $user) {
         $resource = new stdClass();
         $resource->id = $user->id;
         $resource->name = $user->name;
         $resource->type = 'user';
         $resource_array[] = $resource;
     }
     foreach ($resources2 as $contact) {
         $resource = new stdClass();
         $resource->id = $contact->id;
         $resource->name = $contact->name;
         $resource->type = 'contact';
         $resource_array[] = $resource;
     }
     if (!is_null($tasks)) {
         foreach ($tasks as $task) {
             $task->duration_unit = "Days";
             $task->date_start = Date('Y-m-d');
             $task->date_finish = Date('Y-m-d', strtotime("+" . $task->duration . " days"));
             echo '<tr class="row_sortable">
                     <td class="project_table_cells"><input class="order_number" name="order_number[]" rel="' . $task->id . '" type="hidden" value="' . $task->order_number . '" />' . $task->task_number . '</td>';
             if (ACLController::checkAccess('AM_ProjectTemplates', 'edit', true)) {
                 echo '<td class="project_table_cells" ><span class="Task_name" ><a data = "' . $task->id . ',' . $task->predecessors . ',' . $task->relationship_type . ',' . $timeDate->to_display_date($task->date_start, true) . ',' . $task->duration . ',' . $task->duration_unit . ',' . $task->assigned_user_id . ',' . $task->milestone_flag . ',' . $task->percent_complete . ',' . $task->description . '" onclick = "edit_task($(this));"title = "' . $mod_strings['LBL_TASK_TITLE'] . '" href = "#" > ' . $task->name . '</a ></span ></td>';
             } else {
                 echo '<td class="project_table_cells" ><span class="Task_name" >' . $task->name . '</span ></td>';
             }
             echo '<td class="project_table_cells">';
             foreach ($tasks as $predecessor) {
                 if ($predecessor->task_number == $task->predecessors) {
                     echo $predecessor->name;
                 }
             }
             echo '
                     </td>
                     <!-- td class="project_table_cells">' . $timeDate->to_display_date($task->date_start, true) . '</td>
                     <td class="project_table_cells">' . $timeDate->to_display_date($task->date_finish, true) . '</td -->
                     <td class="project_table_cells">' . $task->duration . ' ' . $app_list_strings['duration_unit_dom'][$task->duration_unit] . '</td>
                     <td style="min-width:105px;" class="project_table_cells" >';
             $rflag = '0';
             foreach ($resource_array as $resource) {
                 if ($resource->id == $task->assigned_user_id) {
                     if ($resource->type == 'user') {
                         echo '<a target="blank" href="index.php?module=Users&action=DetailView&record=' . $resource->id . '">' . $resource->name . '</a>';
                         $rflag = '1';
                     } elseif ($resource->type == 'contact') {
                         echo '<a target="blank" href="index.php?module=Contacts&action=DetailView&record=' . $resource->id . '">' . $resource->name . '</a>';
                         $rflag = '1';
                     }
                 }
             }
             if ($rflag == '0') {
                 echo $mod_strings['LBL_UNASSIGNED'];
             }
             if ($task->milestone_flag == '1') {
                 $checked = $app_list_strings['checkbox_dom']['1'];
             } else {
                 $checked = $app_list_strings['checkbox_dom']['2'];
             }
             echo '</td>
                     <td class="project_table_cells">' . $task->percent_complete . '</td>
                     <td class="project_table_cells">' . $checked . '</td>
                     <td class="project_table_cells">
                         <span id="exportToPDFSpan">';
             if (ACLController::checkAccess('AM_ProjectTemplates', 'delete', true)) {
                 echo '<button style = "height:20px;width:20px;" class="remove_button" value = "' . $task->id . '" class="gantt_button" > Delete Task </button >';
             } else {
                 echo '<button disabled="disabled" style = "height:20px;width:20px;" class="remove_button" value = "' . $task->id . '" class="gantt_button" > Delete Task </button >';
             }
             echo '</span>
                      </td>
                 </tr>';
             $task_count++;
         }
     }
     echo '</table>';
 }