static function getPreviousTasks($task_id) { $previous_tasks = array(); $deps = self::getDependenciesForTask($task_id); foreach ($deps as $dep) { /* @var $dep ProjectTaskDependency */ $task = ProjectTasks::findById($dep->getPreviousTaskId()); if ($task instanceof ProjectTask) { $previous_tasks[] = $task; } } return $previous_tasks; }
function percent_complete_delete($time_slot) { $timeslot_time = ($time_slot->getEndTime()->getTimestamp() - ($time_slot->getStartTime()->getTimestamp() + $time_slot->getSubtract())) / 3600; $task = ProjectTasks::findById($time_slot->getRelObjectId()); if ($task->getTimeEstimate() > 0) { $timeslot_percent = round($timeslot_time * 100 / ($task->getTimeEstimate() / 60)); $total_percentComplete = $task->getPercentCompleted() - $timeslot_percent; if ($total_percentComplete < 0) { $total_percentComplete = 0; } $task->setPercentCompleted($total_percentComplete); $task->save(); } }
function index() { $tasksUserId = array_var($_GET, 'tu'); if (is_null($tasksUserId)) { $tasksUserId = user_config_option('TM tasks user filter', logged_user()->getId()); } else { if (user_config_option('TM tasks user filter') != $tasksUserId) { set_user_config_option('TM tasks user filter', $tasksUserId, logged_user()->getId()); } } $timeslotsUserId = array_var($_GET, 'tsu'); if (is_null($timeslotsUserId)) { $timeslotsUserId = user_config_option('TM user filter', 0); } else { if (user_config_option('TM user filter') != $timeslotsUserId) { set_user_config_option('TM user filter', $timeslotsUserId, logged_user()->getId()); } } $showTimeType = array_var($_GET, 'stt'); if (is_null($showTimeType)) { $showTimeType = user_config_option('TM show time type', 0); } else { if (user_config_option('TM show time type') != $showTimeType) { set_user_config_option('TM show time type', $showTimeType, logged_user()->getId()); } } $start = array_var($_GET, 'start', 0); $limit = 20; $tasksUser = Contacts::findById($tasksUserId); $timeslotsUser = Contacts::findById($timeslotsUserId); //Active tasks view $open_timeslots = Timeslots::instance()->listing(array("extra_conditions" => " AND end_time = '" . EMPTY_DATETIME . "' AND contact_id = " . $tasksUserId))->objects; $tasks = array(); foreach ($open_timeslots as $open_timeslot) { $task = ProjectTasks::findById($open_timeslot->getRelObjectId()); if ($task instanceof ProjectTask && !$task->isCompleted() && !$task->isTrashed() && !$task->isArchived()) { $tasks[] = $task; } } ProjectTasks::populateTimeslots($tasks); //Timeslots view $total = 0; switch ($showTimeType) { case 0: //Show only timeslots added through the time panel $result = Timeslots::getGeneralTimeslots(active_context(), $timeslotsUser, $start, $limit); $timeslots = $result->objects; $total = $result->total; break; default: throw new Error('Unrecognised TM show time type: ' . $showTimeType); } //Get Users Info $users = array(); $context = active_context(); if (!can_manage_time(logged_user())) { if (can_add(logged_user(), $context, Timeslots::instance()->getObjectTypeId())) { $users = array(logged_user()); } } else { if (logged_user()->isMemberOfOwnerCompany()) { $users = Contacts::getAllUsers(); } else { $users = logged_user()->getCompanyId() > 0 ? Contacts::getAllUsers(" AND `company_id` = " . logged_user()->getCompanyId()) : array(logged_user()); } $tmp_users = array(); foreach ($users as $user) { if (can_add($user, $context, Timeslots::instance()->getObjectTypeId())) { $tmp_users[] = $user; } } $users = $tmp_users; } //Get Companies Info if (logged_user()->isMemberOfOwnerCompany() || logged_user()->isAdminGroup()) { $companies = Contacts::getCompaniesWithUsers(); } else { $companies = array(); if (logged_user()->getCompanyId() > 0) { $companies[] = logged_user()->getCompany(); } } $required_dimensions = DimensionObjectTypeContents::getRequiredDimensions(Timeslots::instance()->getObjectTypeId()); $draw_inputs = !$required_dimensions || count($required_dimensions) == 0; if (!$draw_inputs) { $ts_ots = DimensionObjectTypeContents::getDimensionObjectTypesforObject(Timeslots::instance()->getObjectTypeId()); $context = active_context(); foreach ($context as $sel) { if ($sel instanceof Member) { foreach ($ts_ots as $ts_ot) { if ($sel->getDimensionId() == $ts_ot->getDimensionId() && $sel->getObjectTypeId() == $ts_ot->getDimensionObjectTypeId()) { $draw_inputs = true; break; } } if ($draw_inputs) { break; } } } } tpl_assign('draw_inputs', $draw_inputs); tpl_assign('selected_user', logged_user()->getId()); tpl_assign('timeslots', $timeslots); tpl_assign('tasks', $tasks); if (count($tasks) > 0) { tpl_assign('all_users', Contacts::getAllUsers()); } tpl_assign('users', $users); tpl_assign('start', $start); tpl_assign('limit', $limit); tpl_assign('total', $total); tpl_assign('companies', $companies); ajx_set_no_toolbar(true); }
/** * Save this list * * @param void * @return boolean */ function save() { if (!$this->isNew()) { $old_me = ProjectTasks::findById($this->getId(), true); if (!$old_me instanceof ProjectTask) { return; } // TODO: check this!!! // This was added cause deleting some tasks was giving an error, couldn't reproduce it again, but this solved it } if ($this->isNew() || $this->getAssignedToContactId() != $old_me->getAssignedToContactId()) { $this->setAssignedBy(logged_user()); $this->setAssignedOn(DateTimeValueLib::now()); } $due_date_changed = false; if (!$this->isNew()) { $old_due_date = $old_me->getDueDate(); $due_date = $this->getDueDate(); if ($due_date instanceof DateTimeValue) { if (!$old_due_date instanceof DateTimeValue || $old_due_date->getTimestamp() != $due_date->getTimestamp()) { $due_date_changed = true; } } else { if ($old_due_date instanceof DateTimeValue) { $due_date_changed = true; } } } //update Depth And Parents Path $parent_id_changed = false; $new_parent_id = $this->getParentId(); if (!$this->isNew()) { $old_parent_id = $old_me->getParentId(); if ($old_parent_id != $new_parent_id) { $this->updateDepthAndParentsPath($new_parent_id); } } else { $this->updateDepthAndParentsPath($new_parent_id); } parent::save(); if ($due_date_changed) { $id = $this->getId(); $sql = "UPDATE `" . TABLE_PREFIX . "object_reminders` SET\r\n\t\t\t\t`date` = date_sub((SELECT `due_date` FROM `" . TABLE_PREFIX . "project_tasks` WHERE `object_id` = {$id}),\r\n\t\t\t\t\tinterval `minutes_before` minute) WHERE `object_id` = {$id};"; DB::execute($sql); } $old_parent_id = isset($old_me) && $old_me instanceof ProjectTask ? $old_me->getParentId() : 0; if ($this->isNew() || $old_parent_id != $new_parent_id) { //update Depth And Parents Path for subtasks $subtasks = $this->getSubTasks(); if (is_array($subtasks)) { foreach ($subtasks as $subtask) { $subtask->updateDepthAndParentsPath($this->getId()); $subtask->save(); } // if } // if } return true; }
/** * Execute a report and return results * * @param $id * @param $params * * @return array */ static function executeReport($id, $params, $order_by_col = '', $order_by_asc = true, $offset = 0, $limit = 50, $to_print = false) { if (is_null(active_context())) { CompanyWebsite::instance()->setContext(build_context_array(array_var($_REQUEST, 'context'))); } $results = array(); $report = self::getReport($id); $show_archived = false; if ($report instanceof Report) { $conditionsFields = ReportConditions::getAllReportConditionsForFields($id); $conditionsCp = ReportConditions::getAllReportConditionsForCustomProperties($id); $ot = ObjectTypes::findById($report->getReportObjectTypeId()); $table = $ot->getTableName(); if ($ot->getType() == 'dimension_object' || $ot->getType() == 'dimension_group') { $hook_parameters = array('report' => $report, 'params' => $params, 'order_by_col' => $order_by_col, 'order_by_asc' => $order_by_asc, 'offset' => $offset, 'limit' => $limit, 'to_print' => $to_print); $report_result = null; Hook::fire('replace_execute_report_function', $hook_parameters, $report_result); if ($report_result) { return $report_result; } } eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();"); eval('$item_class = ' . $ot->getHandlerClass() . '::instance()->getItemClass(); $object = new $item_class();'); $order_by = ''; if (is_object($params)) { $params = get_object_vars($params); } $report_columns = ReportColumns::getAllReportColumns($id); $allConditions = ""; $contact_extra_columns = self::get_extra_contact_columns(); if (count($conditionsFields) > 0) { foreach ($conditionsFields as $condField) { if ($condField->getFieldName() == "archived_on") { $show_archived = true; } $skip_condition = false; $model = $ot->getHandlerClass(); $model_instance = new $model(); $col_type = $model_instance->getColumnType($condField->getFieldName()); $allConditions .= ' AND '; $dateFormat = 'm/d/Y'; if (isset($params[$condField->getId()])) { $value = $params[$condField->getId()]; if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) { $dateFormat = user_config_option('date_format'); } } else { $value = $condField->getValue(); } if ($ot->getHandlerClass() == 'Contacts' && in_array($condField->getFieldName(), $contact_extra_columns)) { $allConditions .= self::get_extra_contact_column_condition($condField->getFieldName(), $condField->getCondition(), $value); } else { if ($value == '' && $condField->getIsParametrizable()) { $skip_condition = true; } if (!$skip_condition) { $field_name = $condField->getFieldName(); if (in_array($condField->getFieldName(), Objects::getColumns())) { $field_name = 'o`.`' . $condField->getFieldName(); } if ($condField->getCondition() == 'like' || $condField->getCondition() == 'not like') { $value = '%' . $value . '%'; } if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) { if ($value == date_format_tip($dateFormat)) { $value = EMPTY_DATE; } else { $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d'); } } if ($condField->getCondition() != '%') { if ($col_type == DATA_TYPE_INTEGER || $col_type == DATA_TYPE_FLOAT) { $allConditions .= '`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value); } else { if ($condField->getCondition() == '=' || $condField->getCondition() == '<=' || $condField->getCondition() == '>=') { if ($col_type == DATA_TYPE_DATETIME || $col_type == DATA_TYPE_DATE) { $equal = 'datediff(' . DB::escape($value) . ', `' . $field_name . '`)=0'; } else { $equal = '`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value); } switch ($condField->getCondition()) { case '=': $allConditions .= $equal; break; case '<=': case '>=': $allConditions .= '(`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value) . ' OR ' . $equal . ') '; break; } } else { $allConditions .= '`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value); } } } else { $allConditions .= '`' . $field_name . '` like ' . DB::escape("%{$value}"); } } else { $allConditions .= ' true'; } } } } if (count($conditionsCp) > 0) { $dateFormat = user_config_option('date_format'); $date_format_tip = date_format_tip($dateFormat); foreach ($conditionsCp as $condCp) { $cp = CustomProperties::getCustomProperty($condCp->getCustomPropertyId()); $skip_condition = false; if (isset($params[$condCp->getId() . "_" . $cp->getName()])) { $value = $params[$condCp->getId() . "_" . $cp->getName()]; } else { $value = $condCp->getValue(); } if ($value == '' && $condCp->getIsParametrizable()) { $skip_condition = true; } if (!$skip_condition) { $current_condition = ' AND '; $current_condition .= 'o.id IN ( SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv WHERE '; $current_condition .= ' cpv.custom_property_id = ' . $condCp->getCustomPropertyId(); $fieldType = $object->getColumnType($condCp->getFieldName()); if ($condCp->getCondition() == 'like' || $condCp->getCondition() == 'not like') { $value = '%' . $value . '%'; } if ($cp->getType() == 'date') { if ($value == $date_format_tip) { continue; } $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d H:i:s'); } if ($condCp->getCondition() != '%') { if ($cp->getType() == 'numeric') { $current_condition .= ' AND cpv.value ' . $condCp->getCondition() . ' ' . DB::escape($value); } else { if ($cp->getType() == 'boolean') { $current_condition .= ' AND cpv.value ' . $condCp->getCondition() . ' ' . ($value ? '1' : '0'); if (!$value) { $current_condition .= ') OR o.id NOT IN (SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv2 WHERE cpv2.object_id=o.id AND cpv2.value=1 AND cpv2.custom_property_id = ' . $condCp->getCustomPropertyId(); } } else { $current_condition .= ' AND cpv.value ' . $condCp->getCondition() . ' ' . DB::escape($value); } } } else { $current_condition .= ' AND cpv.value like ' . DB::escape("%{$value}"); } $current_condition .= ')'; $allConditions .= $current_condition; } } } $select_columns = array('*'); $join_params = null; if ($order_by_col == '') { $order_by_col = $report->getOrderBy(); } if ($ot->getHandlerClass() == 'Contacts' && in_array($order_by_col, $contact_extra_columns)) { $join_params = self::get_extra_contact_column_order_by($order_by_col, $order_by_col, $select_columns); } $original_order_by_col = $order_by_col; if (in_array($order_by_col, self::$external_columns)) { $order_by_col = 'name_order'; $join_params = array('table' => Objects::instance()->getTableName(), 'jt_field' => 'id', 'e_field' => $original_order_by_col, 'join_type' => 'left'); $select_columns = array(); $tmp_cols = $managerInstance->getColumns(); foreach ($tmp_cols as $col) { $select_columns[] = "e.{$col}"; } $tmp_cols = Objects::instance()->getColumns(); foreach ($tmp_cols as $col) { $select_columns[] = "o.{$col}"; } $select_columns[] = 'jt.name as name_order'; } if ($order_by_asc == null) { $order_by_asc = $report->getIsOrderByAsc(); } if ($ot->getName() == 'task' && !SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) { $allConditions .= " AND assigned_to_contact_id = " . logged_user()->getId(); } if ($managerInstance) { if ($order_by_col == "order") { $order_by_col = "`{$order_by_col}`"; } $listing_parameters = array("select_columns" => $select_columns, "order" => "{$order_by_col}", "order_dir" => $order_by_asc ? "ASC" : "DESC", "extra_conditions" => $allConditions, "count_results" => true, "join_params" => $join_params); if ($limit > 0) { $listing_parameters["start"] = $offset; $listing_parameters["limit"] = $limit; } if ($show_archived) { $listing_parameters["archived"] = true; } $result = $managerInstance->listing($listing_parameters); } else { // TODO Performance Killer $result = ContentDataObjects::getContentObjects(active_context(), $ot, $order_by_col, $order_by_asc ? "ASC" : "DESC", $allConditions); } $objects = $result->objects; $totalResults = $result->total; $results['pagination'] = Reports::getReportPagination($id, $params, $original_order_by_col, $order_by_asc, $offset, $limit, $totalResults); $dimensions_cache = array(); foreach ($report_columns as $column) { if ($column->getCustomPropertyId() == 0) { $field = $column->getFieldName(); if (str_starts_with($field, 'dim_')) { $dim_id = str_replace("dim_", "", $field); $dimension = Dimensions::getDimensionById($dim_id); $dimensions_cache[$dim_id] = $dimension; $column_name = $dimension->getName(); $results['columns'][$field] = $column_name; $results['db_columns'][$column_name] = $field; } else { if ($managerInstance->columnExists($field) || Objects::instance()->columnExists($field)) { $column_name = Localization::instance()->lang('field ' . $ot->getHandlerClass() . ' ' . $field); if (is_null($column_name)) { $column_name = lang('field Objects ' . $field); } $results['columns'][$field] = $column_name; $results['db_columns'][$column_name] = $field; } else { if ($ot->getHandlerClass() == 'Contacts') { if (in_array($field, $contact_extra_columns)) { $results['columns'][$field] = lang($field); $results['db_columns'][lang($field)] = $field; } } else { if ($ot->getHandlerClass() == 'Timeslots') { if (in_array($field, array('time', 'billing'))) { $results['columns'][$field] = lang('field Objects ' . $field); $results['db_columns'][lang('field Objects ' . $field)] = $field; } } else { if ($ot->getHandlerClass() == 'MailContents') { if (in_array($field, array('to', 'cc', 'bcc', 'body_plain', 'body_html'))) { $results['columns'][$field] = lang('field Objects ' . $field); $results['db_columns'][lang('field Objects ' . $field)] = $field; } } } } } } } else { $results['columns'][$column->getCustomPropertyId()] = $column->getCustomPropertyId(); } } $report_rows = array(); foreach ($objects as &$object) { /* @var $object Object */ $obj_name = $object->getObjectName(); $icon_class = $object->getIconClass(); $row_values = array('object_type_id' => $object->getObjectTypeId()); if (!$to_print) { $row_values['link'] = '<a class="link-ico ' . $icon_class . '" title="' . clean($obj_name) . '" target="new" href="' . $object->getViewUrl() . '"> </a>'; } foreach ($report_columns as $column) { if ($column->getCustomPropertyId() == 0) { $field = $column->getFieldName(); if (str_starts_with($field, 'dim_')) { $dim_id = str_replace("dim_", "", $field); if (!array_var($dimensions_cache, $dim_id) instanceof Dimension) { $dimension = Dimensions::getDimensionById($dim_id); $dimensions_cache[$dim_id] = $dimension; } else { $dimension = array_var($dimensions_cache, $dim_id); } $om_object_id = $object instanceof Timeslot ? $object->getRelObjectId() : $object->getId(); $members = ObjectMembers::getMembersByObjectAndDimension($om_object_id, $dim_id, " AND om.is_optimization=0"); $value = ""; foreach ($members as $member) { /* @var $member Member */ $val = $member->getPath(); $val .= ($val == "" ? "" : "/") . $member->getName(); if ($value != "") { $val = " - {$val}"; } $value .= $val; } $row_values[$field] = $value; } else { if ($object instanceof Timeslot) { if ($field == 'id') { $value = $object->getObjectId(); } else { $value = $object->getColumnValue($field); // if it is a task column if (in_array($field, ProjectTasks::instance()->getColumns())) { $task = ProjectTasks::findById($object->getRelObjectId()); // if task exists if ($task instanceof ProjectTask) { $value = $task->getColumnValue($field); // if it is an external task column if (in_array($field, ProjectTasks::instance()->getExternalColumns())) { $value = self::instance()->getExternalColumnValue($field, $value, ProjectTasks::instance()); } else { // if is a date then use format if (ProjectTasks::instance()->getColumnType($field) == DATA_TYPE_DATETIME && $value instanceof DateTimeValue) { $value = format_value_to_print($field, $value->toMySQL(), DATA_TYPE_DATETIME, $report->getReportObjectTypeId()); } } } $results['columns'][$field] = lang('field ProjectTasks ' . $field); $results['db_columns'][lang('field ProjectTasks ' . $field)] = $field; } } } else { $value = $object->getColumnValue($field); } if ($value instanceof DateTimeValue) { $dateFormat = user_config_option('date_format'); Hook::fire("custom_property_date_format", null, $dateFormat); $tz = logged_user()->getTimezone(); if ($object instanceof ProjectTask) { if ($field == 'due_date' && !$object->getUseDueTime() || $field == 'start_date' && !$object->getUseStartTime()) { $dateFormat = user_config_option('date_format'); $tz = 0; } } $value = format_date($value, $dateFormat, $tz * 3600); } if (in_array($field, $managerInstance->getExternalColumns())) { if ($object instanceof Timeslot && $field == 'time') { $lastStop = $object->getEndTime() != null ? $object->getEndTime() : ($object->isPaused() ? $object->getPausedOn() : DateTimeValueLib::now()); $seconds = $lastStop->getTimestamp() - $object->getStartTime()->getTimestamp(); $hours = number_format($seconds / 3600, 2, ',', '.'); $value = $hours; //$value = DateTimeValue::FormatTimeDiff($object->getStartTime(), $lastStop, "hm", 60, $object->getSubtract()); } else { if ($object instanceof Timeslot && $field == 'billing') { $value = config_option('currency_code', '$') . ' ' . $object->getFixedBilling(); } else { $value = self::instance()->getExternalColumnValue($field, $value, $managerInstance); } } } else { if ($field != 'link') { //$value = html_to_text(html_entity_decode($value)); if ($object->getColumnType($field) == DATA_TYPE_STRING) { // change html block end tags and brs to \n, then remove all other html tags, then replace \n with <br>, to remove all styles and keep the enters $value = str_replace(array("</div>", "</p>", "<br>", "<br />", "<br/>"), "\n", $value); $value = nl2br(strip_tags($value)); } } } if (self::isReportColumnEmail($value)) { if (logged_user()->hasMailAccounts()) { $value = '<a class="internalLink" href="' . get_url('mail', 'add_mail', array('to' => clean($value))) . '">' . clean($value) . '</a></div>'; } else { $value = '<a class="internalLink" target="_self" href="mailto:' . clean($value) . '">' . clean($value) . '</a></div>'; } } $row_values[$field] = $value; if ($ot->getHandlerClass() == 'Contacts') { if ($managerInstance instanceof Contacts) { $contact = Contacts::findOne(array("conditions" => "object_id = " . $object->getId())); if ($field == "email_address") { $row_values[$field] = $contact->getEmailAddress(); } if ($field == "is_user") { $row_values[$field] = $contact->getUserType() > 0 && !$contact->getIsCompany(); } if ($field == "im_values") { $str = ""; foreach ($contact->getAllImValues() as $type => $value) { $str .= ($str == "" ? "" : " | ") . "{$type}: {$value}"; } $row_values[$field] = $str; } if (in_array($field, array("mobile_phone", "work_phone", "home_phone"))) { if ($field == "mobile_phone") { $row_values[$field] = $contact->getPhoneNumber('mobile', null, false); } else { if ($field == "work_phone") { $row_values[$field] = $contact->getPhoneNumber('work', null, false); } else { if ($field == "home_phone") { $row_values[$field] = $contact->getPhoneNumber('home', null, false); } } } } if (in_array($field, array("personal_webpage", "work_webpage", "other_webpage"))) { if ($field == "personal_webpage") { $row_values[$field] = $contact->getWebpageUrl('personal'); } else { if ($field == "work_webpage") { $row_values[$field] = $contact->getWebpageUrl('work'); } else { if ($field == "other_webpage") { $row_values[$field] = $contact->getWebpageUrl('other'); } } } } if (in_array($field, array("home_address", "work_address", "other_address"))) { if ($field == "home_address") { $row_values[$field] = $contact->getStringAddress('home'); } else { if ($field == "work_address") { $row_values[$field] = $contact->getStringAddress('work'); } else { if ($field == "other_address") { $row_values[$field] = $contact->getStringAddress('other'); } } } } } } else { if ($ot->getHandlerClass() == 'MailContents') { if (in_array($field, array('to', 'cc', 'bcc', 'body_plain', 'body_html'))) { $mail_data = MailDatas::findById($object->getId()); $row_values[$field] = $mail_data->getColumnValue($field); if ($field == "body_html") { if (class_exists("DOMDocument")) { $d = new DOMDocument(); $mock = new DOMDocument(); $d->loadHTML(remove_css_and_scripts($row_values[$field])); $body = $d->getElementsByTagName('body')->item(0); foreach ($body->childNodes as $child) { $mock->appendChild($mock->importNode($child, true)); } // if css is inside an html comment => remove it $row_values[$field] = preg_replace('/<!--(.*)-->/Uis', '', remove_css($row_values[$field])); } else { $row_values[$field] = preg_replace('/<!--(.*)-->/Uis', '', remove_css_and_scripts($row_values[$field])); } } } } } if (!$to_print && $field == "name") { $row_values[$field] = '<a target="new-' . $object->getId() . '" href="' . $object->getViewUrl() . '">' . $value . '</a>'; } } } else { $colCp = $column->getCustomPropertyId(); $cp = CustomProperties::getCustomProperty($colCp); if ($cp instanceof CustomProperty) { /* @var $cp CustomProperty */ $row_values[$cp->getName()] = get_custom_property_value_for_listing($cp, $object); $results['columns'][$colCp] = $cp->getName(); $results['db_columns'][$cp->getName()] = $colCp; } } } Hook::fire("report_row", $object, $row_values); $report_rows[] = $row_values; } if (!$to_print) { if (is_array($results['columns'])) { array_unshift($results['columns'], ''); } else { $results['columns'] = array(''); } Hook::fire("report_header", $ot, $results['columns']); } $results['rows'] = $report_rows; } return $results; }
function total_task_times_by_task_print() { $this->setLayout("html"); $task = ProjectTasks::findById(get_id()); $st = DateTimeValueLib::make(0, 0, 0, 1, 1, 1900); $et = DateTimeValueLib::make(23, 59, 59, 12, 31, 2036); $timeslotsArray = Timeslots::getTaskTimeslots(null, null, null, $st, $et, get_id()); tpl_assign('estimate', $task->getTimeEstimate()); //tpl_assign('timeslots', $timeslots); tpl_assign('timeslotsArray', $timeslotsArray); tpl_assign('workspace', $task->getProject()); tpl_assign('template_name', 'total_task_times'); tpl_assign('title', lang('task time report')); tpl_assign('task_title', $task->getTitle()); $this->setTemplate('report_printer'); }
/** * Same that getContentObjects but reading from sahring table * @deprecated by parent::listing() **/ static function findByContext( $options = array () ) { // Initialize method result $result = new stdClass(); $result->total = 0 ; $result->objects = array() ; // Read arguments and Init Vars $limit = array_var($options,'limit'); $members = active_context_members(false); // 70 $type_id = self::instance()->getObjectTypeId(); if (!count($members)) return $res ; $uid = logged_user()->getId() ; if ($limit>0){ $limit_sql = "LIMIT $limit"; }else{ $limit_sql = '' ; } // Build Main SQL $sql = " SELECT distinct(id) FROM ".TABLE_PREFIX."objects WHERE id IN ( SELECT object_id FROM ".TABLE_PREFIX."sharing_table WHERE group_id IN ( SELECT permission_group_id FROM ".TABLE_PREFIX."contact_permission_groups WHERE contact_id = $uid ) ) AND id IN ( SELECT object_id FROM ".TABLE_PREFIX."object_members WHERE member_id IN (".implode(',', $members).") GROUP BY object_id HAVING count(member_id) = ".count($members)." ) AND object_type_id = $type_id AND ".SQL_NOT_DELETED." $limit_sql"; // Execute query and build the resultset $rows = DB::executeAll($sql); foreach ($rows as $row) { $task = ProjectTasks::findById($row['id']); if ( ( $task && $task instanceof ProjectTask ) && !$task->isTemplate() ) { if($task->getDueDate()){ $k = "#".$task->getDueDate()->getTimestamp().$task->getId(); $result->objects[$k] = $task ; }else{ $result->objects[] = $task ; } $result->total++; } } // Sort by key ksort($result->objects); // Remove keys $result->objects = array_values($result->objects); return $result; }
function change_start_due_date() { $task = ProjectTasks::findById(get_id()); if (!$task->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $tochange = array_var($_GET, 'tochange', ''); if (($tochange == 'both' || $tochange == 'due') && $task->getDueDate() instanceof DateTimeValue) { $year = array_var($_GET, 'year', $task->getDueDate()->getYear()); $month = array_var($_GET, 'month', $task->getDueDate()->getMonth()); $day = array_var($_GET, 'day', $task->getDueDate()->getDay()); $new_date = new DateTimeValue(mktime(0, 0, 0, $month, $day, $year)); $task->setDueDate($new_date); } if (($tochange == 'both' || $tochange == 'start') && $task->getStartDate() instanceof DateTimeValue) { $year = array_var($_GET, 'year', $task->getStartDate()->getYear()); $month = array_var($_GET, 'month', $task->getStartDate()->getMonth()); $day = array_var($_GET, 'day', $task->getStartDate()->getDay()); $new_date = new DateTimeValue(mktime(0, 0, 0, $month, $day, $year)); $task->setStartDate($new_date); } try { DB::beginWork(); $task->save(); DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error(lang('error change date')); } // try ajx_current("empty"); }
function add_timeslot() { $object_id = array_var($_REQUEST, "object_id", false); ajx_current("empty"); $timeslot_data = array_var($_POST, 'timeslot'); if ($object_id) { $object = Objects::findObject($object_id); if (!$object instanceof ContentDataObject || !$object->canAddTimeslot(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $member_ids = $object->getMemberIds(); } else { $member_ids = json_decode(array_var($_POST, 'members', array())); // clean member_ids $tmp_mids = array(); foreach ($member_ids as $mid) { if (!is_null($mid) && trim($mid) != "") { $tmp_mids[] = $mid; } } $member_ids = $tmp_mids; if (empty($member_ids)) { if (!can_add(logged_user(), active_context(), Timeslots::instance()->getObjectTypeId())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } } else { if (count($member_ids) > 0) { $enteredMembers = Members::findAll(array('conditions' => 'id IN (' . implode(",", $member_ids) . ')')); } else { $enteredMembers = array(); } if (!can_add(logged_user(), $enteredMembers, Timeslots::instance()->getObjectTypeId())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } } $object_id = 0; } try { $hoursToAdd = array_var($timeslot_data, 'hours', 0); $minutes = array_var($timeslot_data, 'minutes', 0); if (strpos($hoursToAdd, ',') && !strpos($hoursToAdd, '.')) { $hoursToAdd = str_replace(',', '.', $hoursToAdd); } if (strpos($hoursToAdd, ':') && !strpos($hoursToAdd, '.')) { $pos = strpos($hoursToAdd, ':') + 1; $len = strlen($hoursToAdd) - $pos; $minutesToAdd = substr($hoursToAdd, $pos, $len); if (!strlen($minutesToAdd) <= 2 || !strlen($minutesToAdd) > 0) { $minutesToAdd = substr($minutesToAdd, 0, 2); } $mins = $minutesToAdd / 60; $hours = substr($hoursToAdd, 0, $pos - 1); $hoursToAdd = $hours + $mins; } if ($minutes) { $min = str_replace('.', '', $minutes / 6); $hoursToAdd = $hoursToAdd + ("0." . $min); } if ($hoursToAdd <= 0) { flash_error(lang('time has to be greater than 0')); return; } $startTime = getDateValue(array_var($timeslot_data, 'date')); $startTime = $startTime->add('h', 8 - logged_user()->getTimezone()); $endTime = getDateValue(array_var($timeslot_data, 'date')); $endTime = $endTime->add('h', 8 - logged_user()->getTimezone() + $hoursToAdd); //use current time if (array_var($_REQUEST, "use_current_time", false)) { $currentStartTime = DateTimeValueLib::now(); $currentEndTime = DateTimeValueLib::now(); $currentStartTime = $currentStartTime->add('h', -$hoursToAdd); $startTime->setHour($currentStartTime->getHour()); $startTime->setMinute($currentStartTime->getMinute()); $endTime->setHour($currentEndTime->getHour()); $endTime->setMinute($currentEndTime->getMinute()); } $timeslot_data['start_time'] = $startTime; $timeslot_data['end_time'] = $endTime; $timeslot_data['description'] = html_to_text($timeslot_data['description']); $timeslot_data['name'] = $timeslot_data['description']; $timeslot_data['rel_object_id'] = $object_id; //array_var($timeslot_data,'project_id'); $timeslot = new Timeslot(); //Only admins can change timeslot user if (!array_var($timeslot_data, 'contact_id', false) || !SystemPermissions::userHasSystemPermission(logged_user(), 'can_manage_time')) { $timeslot_data['contact_id'] = logged_user()->getId(); } $timeslot->setFromAttributes($timeslot_data); $user = Contacts::findById($timeslot_data['contact_id']); $billing_category_id = $user->getDefaultBillingId(); $bc = BillingCategories::findById($billing_category_id); if ($bc instanceof BillingCategory) { $timeslot->setBillingId($billing_category_id); $hourly_billing = $bc->getDefaultValue(); $timeslot->setHourlyBilling($hourly_billing); $timeslot->setFixedBilling($hourly_billing * $hoursToAdd); $timeslot->setIsFixedBilling(false); } DB::beginWork(); $timeslot->save(); $task = ProjectTasks::findById($object_id); if ($task instanceof ProjectTask) { $task->calculatePercentComplete(); } if (!isset($member_ids) || !is_array($member_ids) || count($member_ids) == 0) { $member_ids = json_decode(array_var($_POST, 'members')); } $object_controller = new ObjectController(); $object_controller->add_to_members($timeslot, $member_ids); DB::commit(); ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_ADD); $show_billing = can_manage_billing(logged_user()); ajx_extra_data(array("timeslot" => $timeslot->getArrayInfo($show_billing), "real_obj_id" => $timeslot->getRelObjectId())); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } // try }
/** * Edit timeslot * * @param void * @return null */ function edit() { $this->setTemplate('add_timeslot'); $timeslot = Timeslots::findById(get_id()); if(!($timeslot instanceof Timeslot)) { flash_error(lang('timeslot dnx')); ajx_current("empty"); return; } $object = $timeslot->getRelObject(); if(!($object instanceof ContentDataObject)) { flash_error(lang('object dnx')); ajx_current("empty"); return; } if(!($object->canAddTimeslot(logged_user()))) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } if(!($timeslot->canEdit(logged_user()))) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $timeslot_data = array_var($_POST, 'timeslot'); if(!is_array($timeslot_data)) { $timeslot_data = array( 'contact_id' => $timeslot->getContactId(), 'description' => $timeslot->getDescription(), 'start_time' => $timeslot->getStartTime(), 'end_time' => $timeslot->getEndTime(), 'is_fixed_billing' => $timeslot->getIsFixedBilling(), 'hourly_billing' => $timeslot->getHourlyBilling(), 'fixed_billing' => $timeslot->getFixedBilling() ); } tpl_assign('timeslot_form_object', $object); tpl_assign('timeslot', $timeslot); tpl_assign('timeslot_data', $timeslot_data); tpl_assign('show_billing', BillingCategories::count() > 0); if(is_array(array_var($_POST, 'timeslot'))) { try { $timeslot->setContactId(array_var($timeslot_data, 'contact_id', logged_user()->getId())); $timeslot->setDescription(array_var($timeslot_data, 'description')); $st = getDateValue(array_var($timeslot_data, 'start_value'),DateTimeValueLib::now()); $st->setHour(array_var($timeslot_data, 'start_hour')); $st->setMinute(array_var($timeslot_data, 'start_minute')); $et = getDateValue(array_var($timeslot_data, 'end_value'),DateTimeValueLib::now()); $et->setHour(array_var($timeslot_data, 'end_hour')); $et->setMinute(array_var($timeslot_data, 'end_minute')); $st = new DateTimeValue($st->getTimestamp() - logged_user()->getTimezone() * 3600); $et = new DateTimeValue($et->getTimestamp() - logged_user()->getTimezone() * 3600); $timeslot->setStartTime($st); $timeslot->setEndTime($et); if ($timeslot->getStartTime() > $timeslot->getEndTime()){ flash_error(lang('error start time after end time')); ajx_current("empty"); return; } $seconds = array_var($timeslot_data,'subtract_seconds',0); $minutes = array_var($timeslot_data,'subtract_minutes',0); $hours = array_var($timeslot_data,'subtract_hours',0); $subtract = $seconds + 60 * $minutes + 3600 * $hours; if ($subtract < 0){ flash_error(lang('pause time cannot be negative')); ajx_current("empty"); return; } $testEndTime = new DateTimeValue($timeslot->getEndTime()->getTimestamp()); $testEndTime->add('s',-$subtract); if ($timeslot->getStartTime() > $testEndTime){ flash_error(lang('pause time cannot exceed timeslot time')); ajx_current("empty"); return; } $timeslot->setSubtract($subtract); if ($timeslot->getUser()->getDefaultBillingId()) { $timeslot->setIsFixedBilling(array_var($timeslot_data,'is_fixed_billing',false)); $timeslot->setHourlyBilling(array_var($timeslot_data,'hourly_billing',0)); if ($timeslot->getIsFixedBilling()){ $timeslot->setFixedBilling(array_var($timeslot_data,'fixed_billing',0)); } else { $timeslot->setFixedBilling($timeslot->getHourlyBilling() * $timeslot->getMinutes() / 60); } if ($timeslot->getBillingId() == 0 && ($timeslot->getHourlyBilling() > 0 || $timeslot->getFixedBilling() > 0)){ $timeslot->setBillingId($timeslot->getUser()->getDefaultBillingId()); } } DB::beginWork(); $timeslot->save(); $task = ProjectTasks::findById($timeslot->getRelObjectId()); if($task instanceof ProjectTask) { $task->calculatePercentComplete(); } ApplicationLogs::createLog($timeslot, ApplicationLogs::ACTION_EDIT); $this->notifier_work_estimate($task); DB::commit(); flash_success(lang('success edit timeslot')); ajx_current("back"); } catch(Exception $e) { DB::rollback(); Logger::log($e->getTraceAsString()); flash_error(lang('error edit timeslot').": ".$e->getMessage()); ajx_current("empty"); } } } // edit
echo $task->getId(); ?> ', '<?php echo $template_id; ?> ')"><?php echo lang('set parent task'); ?> </a> <?php } else { if (array_var($_GET, 'template_task', false)) { $parentTask = TemplateTasks::findById($task_data['parent_id']); } else { $parentTask = ProjectTasks::findById($task_data['parent_id']); } if ($parentTask instanceof ProjectTask || $parentTask instanceof TemplateTask) { ?> <span style="display: none;" id="no-task-selected<?php echo $genid; ?> "><?php echo lang('none'); ?> </span> <a style="display: none;margin-left: 10px" id="<?php echo $genid; ?> parent_before" href="#" onclick="og.pickParentTemplateTask(this, '<?php echo $genid;
function close($description = null) { if ($this->isPaused()) { $this->setEndTime($this->getPausedOn()); } else { $dt = DateTimeValueLib::now(); $this->setEndTime($dt); } $timeslot_time = ($this->getEndTime()->getTimestamp() - ($this->getStartTime()->getTimestamp() + $this->getSubtract())) / 3600; $task = ProjectTasks::findById($this->getRelObjectId()); if ($task->getTimeEstimate() > 0) { $timeslot_percent = $timeslot_time * 100 / ($task->getTimeEstimate() / 60); $total_percentComplete = $timeslot_percent + $task->getPercentCompleted(); if ($total_percentComplete < 0) { $total_percentComplete = 0; } $task->setPercentCompleted($total_percentComplete); $task->save(); } //FIXME: Set billing info /* if ($this->getRelObject() instanceof ContentDataObject && $this->getRelObject()->getProject() instanceof Project){ $hours = $this->getMinutes() / 60; $user = $this->getUser(); $billing_category_id = $user->getDefaultBillingId(); $project = $this->getRelObject()->getProject(); $this->setBillingId($billing_category_id); $hourly_billing = $project->getBillingAmount($billing_category_id); $this->setHourlyBilling($hourly_billing); $this->setFixedBilling(round($hourly_billing * $hours, 2)); $this->setIsFixedBilling(false); } */ if ($description) { $this->setDescription($description); } }
/** * Save this list * * @param void * @return boolean */ function save() { if (!$this->isNew()) { $old_me = ProjectTasks::findById($this->getId(), true); if (!$old_me instanceof ProjectTask) return; // TODO: check this!!! // This was added cause deleting some tasks was giving an error, couldn't reproduce it again, but this solved it } if ($this->isNew() || $this->getAssignedToContactId() != $old_me->getAssignedToContactId()) { $this->setAssignedBy(logged_user()); $this->setAssignedOn(DateTimeValueLib::now()); } $due_date_changed = false; if (!$this->isNew()) { $old_due_date = $old_me->getDueDate(); $due_date = $this->getDueDate(); if ($due_date instanceof DateTimeValue) { if (!$old_due_date instanceof DateTimeValue || $old_due_date->getTimestamp() != $due_date->getTimestamp()) { $due_date_changed = true; } } else { if ($old_due_date instanceof DateTimeValue) { $due_date_changed = true; } } } parent::save(); if ($due_date_changed) { $id = $this->getId(); $sql = "UPDATE `".TABLE_PREFIX."object_reminders` SET `date` = date_sub((SELECT `due_date` FROM `".TABLE_PREFIX."project_tasks` WHERE `id` = $id), interval `minutes_before` minute) WHERE `object_id` = $id;"; DB::execute($sql); } $tasks = $this->getSubTasks(); if(is_array($tasks)) { $task_ids = array(); foreach($tasks as $task) { $task_ids[] = $task->getId(); } // if } // if return true; } // save
/** * Render select task list box * * @param string $name Form control name * @param Project $project * @param integer $selected ID of selected object * @param boolean $open_only List only active task lists (skip completed) * @param array $attach_data Additional attributes * @return string */ function select_task_list($name, $project = null, $selected = null, $open_only = false, $attributes = null) { if (is_null($project)) { $project = active_or_personal_project(); } //if (!($project instanceof Project)) throw new InvalidInstanceError('$project', $project, 'Project'); if (is_array($attributes)) { if (!isset($attributes['class'])) { $attributes['class'] = 'select_task_list'; } } else { $attributes = array('class' => 'select_task_list'); } // if $options = array(option_tag(lang('none'), 0)); if ($project instanceof Project) { $task_lists = $open_only ? $project->getOpenTasks() : $project->getTasks(); } else { $task_lists = $open_only ? ProjectTasks::getProjectTasks(null, null, 'ASC', null, null, null, null, null, null, true) : ProjectTasks::getProjectTasks(null, null, 'ASC', 0, null, null, null, null, null, false); } $selected_exists = is_null($selected); if (is_array($task_lists)) { foreach ($task_lists as $task_list) { if ($task_list->getId() == $selected) { $selected_exists = true; $option_attributes = array('selected' => 'selected'); } else { $option_attributes = null; } $options[] = option_tag($task_list->getTitle(), $task_list->getId(), $option_attributes); } // foreach } // if if (!$selected_exists) { $task = ProjectTasks::findById($selected); if ($task instanceof ProjectTask) { $options[] = option_tag($task->getTitle(), $task->getId(), array("selected" => "selected")); } } return select_box($name, $options, $attributes); }
/*if($task_list->canReorderTasks(logged_user()) && is_array($task_list->getOpenSubTasks())) { add_page_action(lang('reorder sub tasks'), $task_list->getReorderTasksUrl($on_list_page), 'ico-properties'); } // if*/ $this->assign('on_list_page', true); ?> <div style="padding: 7px"> <div class="tasks"><?php /* * This section builds the task title */ $title = $task_list->getObjectName() != '' ? $task_list->getObjectName() : $task_list->getText(); $description = ''; $parentInf = ''; // $task = ProjectTasks::findById(get_id()); //start if ($task_list->getParent() instanceof ProjectTask && $task->canEdit(logged_user())) { $parent = $task_list->getParent(); $parentInf = '<div class="member-path-dim-block"><b>' . lang('subtask of', $parent->getViewUrl(), $parent->getObjectName() != '' ? clean($parent->getObjectName()) : clean($parent->getText())) . " " . '</b></div>'; } //end $status = '<div class="taskStatus">'; if (!$task_list->isCompleted()) { if ($task_list->canEdit(logged_user()) && !$task_list->isTrashed()) { $status .= '<b>' . lang('status') . ': </b><a class=\'internalLink \' style="background-position:0 -501px !important;" href=\'' . $task_list->getCompleteUrl(rawurlencode(get_url('task', 'view', array('id' => $task_list->getId())))) . '\' title=\'' . escape_single_quotes(lang('complete task')) . '\'>' . lang('pending') . '</a>'; } else { $status .= '<div style="display:inline;"><b>' . lang('status') . ': </b>' . lang('pending') . '</div>'; } } else { $status .= lang('status') . ': ';
function total_task_times_by_task_print() { $this->setLayout("html"); $task = ProjectTasks::findById(get_id()); $st = DateTimeValueLib::make(0, 0, 0, 1, 1, 1900); $et = DateTimeValueLib::make(23, 59, 59, 12, 31, 2036); $timeslotsArray = Timeslots::getTaskTimeslots(active_context(), null, null, $st, $et, get_id()); tpl_assign('columns', array()); tpl_assign('user', array()); tpl_assign('group_by', array()); tpl_assign('grouped_timeslots', array()); tpl_assign('template_name', 'total_task_times'); tpl_assign('estimate', $task->getTimeEstimate()); tpl_assign('timeslotsArray', $timeslotsArray); tpl_assign('title', lang('task time report')); tpl_assign('task_title', $task->getTitle()); tpl_assign('start_time', $st); tpl_assign('end_time', $et); $this->setTemplate('report_printer'); }
/** * Reopen completed project task * * @access public * @param void * @return null */ function open_task() { $task = ProjectTasks::findById(get_id()); if (!($task instanceof ProjectTask)) { flash_error(lang('task dnx')); $this->redirectTo('task'); } // if $task_list = $task->getTaskList(); if (!($task_list instanceof ProjectTaskList)) { flash_error(lang('task list dnx')); $this->redirectTo('task'); } // if if (!$task->canChangeStatus(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('task'); } // if $redirect_to = array_var($_GET, 'redirect_to'); if ((trim($redirect_to) == '') || !is_valid_url($redirect_to)) { $redirect_to = get_referer($task_list->getViewUrl()); } // if try { DB::beginWork(); $task->openTask(); ApplicationLogs::createLog($task, active_project(), ApplicationLogs::ACTION_OPEN); DB::commit(); flash_success(lang('success open task')); } catch(Exception $e) { flash_error(lang('error open task')); DB::rollback(); } // try $this->redirectToUrl($redirect_to); } // open_task
/** * Reopen completed project task * * @access public * @param void * @return null */ function edit_score() { $task = ProjectTasks::findById(get_id()); if (!$task instanceof ProjectTask) { flash_error(lang('task dnx')); //$this->redirectTo('task'); } // if include '../views/editscore.html'; }
} // if ?> </td> <td class="timeDetails"> <a href="<?php echo $time->getViewUrl(); ?> "><?php echo clean($time->getName()); ?> </a> </td> <td class="timeTaskDetails"> <?php $task = ProjectTasks::findById($time->getTaskId()); if ($task instanceof ProjectTask) { ?> <a href="<?php echo $task->getViewUrl(); ?> "><?php echo clean($task->getObjectName()); ?> </a> <?php } else { // if ?> <?php
/** * Show and process edit time form * * @access public * @param void * @return null */ function edit() { $this->setTemplate('add_time'); $time = ProjectTimes::findById(get_id()); if (!$time instanceof ProjectTime) { flash_error(lang('time dnx')); $this->redirectTo('time', 'index'); } // if if (!$time->canEdit(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('time')); } $time_data = array_var($_POST, 'time'); if (!is_array($time_data)) { $time_data = array('name' => $time->getName(), 'hours' => $time->getHours(), 'is_billable' => $time->getBillable(), 'done_date' => $time->getDoneDate(), 'description' => $time->getDescription(), 'assigned_to' => $time->getAssignedToCompanyId() . ':' . $time->getAssignedToUserId(), 'is_private' => $time->isPrivate(), 'task_id' => $time->getTaskId(), 'task_list_id' => $time->getTaskListId()); // array } // if tpl_assign('time_data', $time_data); tpl_assign('time', $time); // Attiks - BEGIN tpl_assign('open_task_lists', active_project()->getOpenTaskLists()); // Attiks - END if (is_array(array_var($_POST, 'time'))) { $old_owner = $time->getAssignedTo(); // remember the old owner if (isset($_POST['time_done_date'])) { $time_data['done_date'] = DateTimeValueLib::makeFromString($_POST['time_done_date']); } else { $time_data['done_date'] = DateTimeValueLib::make(0, 0, 0, array_var($_POST, 'time_done_date_month', 1), array_var($_POST, 'time_done_date_day', 1), array_var($_POST, 'time_done_date_year', 1970)); } // Attiks - BEGIN if (isset($time_data['task_id'])) { if (substr($time_data['task_id'], 0, 5) == 'task_') { $time_data['task_id'] = substr($time_data['task_id'], 5); $t = ProjectTasks::findById($time_data['task_id']); if (!$t instanceof ProjectTask) { flash_error(lang('task dnx')); $this->redirectTo('task'); } // if $time_data['task_list_id'] = $t->getTaskListId(); } else { $time_data['task_list_id'] = $time_data['task_id']; $time_data['task_id'] = null; } } // Attiks - END $assigned_to = explode(':', array_var($time_data, 'assigned_to', '')); $old_is_private = $time->isPrivate(); $time->setFromAttributes($time_data); if (!logged_user()->isMemberOfOwnerCompany()) { $time->setIsPrivate($old_is_private); } $time->setProjectId(active_project()->getId()); $time->setAssignedToCompanyId(array_var($assigned_to, 0, 0)); $time->setAssignedToUserId(array_var($assigned_to, 1, 0)); try { DB::beginWork(); $time->save(); ApplicationLogs::createLog($time, active_project(), ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success edit time', $time->getName())); $this->redirectTo('time'); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
/** * Open this task and check if we need to reopen list again * * @access public * @param void * @return null */ function openTask() { if (!$this->canChangeStatus(logged_user())) { flash_error('no access permissions'); ajx_current("empty"); return; } $this->setCompletedOn(null); $this->setCompletedById(0); $this->save(); $this->calculatePercentComplete(); $log_info = ""; if (config_option('use tasks dependencies')) { //Seeking the subscribers of the open task not to repeat in the notifications $contact_notification = array(); foreach ($this->getSubscribers() as $task_sub) { $contact_notification[] = $task_sub->getId(); } $saved_stasks = ProjectTaskDependencies::findAll(array('conditions' => 'previous_task_id = ' . $this->getId())); foreach ($saved_stasks as $sdep) { $stask = ProjectTasks::findById($sdep->getTaskId()); if ($stask instanceof ProjectTask && $stask->isCompleted()) { $stask->openTask(); } foreach ($stask->getSubscribers() as $task_dep) { if (!in_array($task_dep->getId(), $contact_notification)) { $log_info .= $task_dep->getId() . ","; } } } } /* * this is done in the controller $task_list = $this->getParent(); if(($task_list instanceof ProjectTask) && $task_list->isCompleted()) { $open_tasks = $task_list->getOpenSubTasks(); if(!empty($open_tasks)) $task_list->open(); } // if*/ ApplicationLogs::createLog($this, ApplicationLogs::ACTION_OPEN, false, false, true, substr($log_info, 0, -1)); }
function check_related_task() { ajx_current("empty"); //I find all those related to the task to find out if the original $task_related = ProjectTasks::findByRelated(array_var($_REQUEST, 'related_id')); if (!$task_related) { $task_related = ProjectTasks::findById(array_var($_REQUEST, 'related_id')); //is not the original as the original look plus other related if ($task_related->getOriginalTaskId() != "0") { ajx_extra_data(array("status" => true)); } else { ajx_extra_data(array("status" => false)); } } else { ajx_extra_data(array("status" => true)); } }
function close($description = null){ if ($this->isPaused()) { $this->setEndTime($this->getPausedOn()); } else { $dt = DateTimeValueLib::now(); $this->setEndTime($dt); } $task = ProjectTasks::findById($this->getRelObjectId()); if($task instanceof ProjectTask) { $task->calculatePercentComplete(); } //FIXME: Set billing info /* if ($this->getRelObject() instanceof ContentDataObject && $this->getRelObject()->getProject() instanceof Project){ $hours = $this->getMinutes() / 60; $user = $this->getUser(); $billing_category_id = $user->getDefaultBillingId(); $project = $this->getRelObject()->getProject(); $this->setBillingId($billing_category_id); $hourly_billing = $project->getBillingAmount($billing_category_id); $this->setHourlyBilling($hourly_billing); $this->setFixedBilling(round($hourly_billing * $hours, 2)); $this->setIsFixedBilling(false); } */ if ($description) $this->setDescription($description); }
else $previous_tasks = array(); ?> <div> <?php if (count($previous_tasks) == 0) { ?> <span id="<?php echo $genid?>no_previous_selected"><?php echo lang('none') ?></span> <script>if (!og.previousTasks) og.previousTasks = []; og.previousTasksIdx = og.previousTasks.length;</script> <?php } else { $k=0; ?> <script> og.previousTasks=[]; og.previousTasksIdx = '<?php echo count($previous_tasks)?>'; </script> <input type="hidden" name="task[clean_dep]" value="1" /> <?php foreach ($previous_tasks as $task_dep) { $task = ProjectTasks::findById($task_dep->getPreviousTaskId()); ?> <div class="og-add-template-object ico-task"> <input type="hidden" name="task[previous]['<?php echo $k?>']" value="<?php echo $task->getId()?>" /> <span class="name"><?php echo clean($task->getTitle()) ?></span> <a href="#" onclick="og.removePreviousTask(this.parentNode, '<?php echo $genid?>', '<?php echo $k?>')" class="removeDiv" style="display: block;"><?php echo lang('remove') ?></a> </div> <script> var obj={id:'<?php echo $task_dep->getPreviousTaskId() ?>'}; og.previousTasks[og.previousTasks.length] = obj; </script> <?php $k++; } } ?> </div><a class="coViewAction ico-add" id="<?php echo $genid?>previous_before" href="#" onclick="og.pickPreviousTask(this, '<?php echo $genid?>',<?php echo $task->getId()?>)"><?php echo lang('add previous task') ?></a>
/** * Save this list * * @param void * @return boolean */ function save() { if (!$this->isNew()) { $old_me = ProjectTasks::findById($this->getId(), true); if (!$old_me instanceof ProjectTask) { return; } // TODO: check this!!! /* This was added cause deleting some tasks was giving an error, couldn't reproduce it again, but this solved it */ } if ($this->isNew() || $this->getAssignedToCompanyId() != $old_me->getAssignedToCompanyId() || $this->getAssignedToUserId() != $old_me->getAssignedToUserId()) { $this->setAssignedBy(logged_user()); $this->setAssignedOn(DateTimeValueLib::now()); } $due_date_changed = false; if (!$this->isNew()) { $old_due_date = $old_me->getDueDate(); $due_date = $this->getDueDate(); if ($due_date instanceof DateTimeValue) { if (!$old_due_date instanceof DateTimeValue || $old_due_date->getTimestamp() != $due_date->getTimestamp()) { $due_date_changed = true; } } else { if ($old_due_date instanceof DateTimeValue) { $due_date_changed = true; } } } parent::save(); if ($due_date_changed) { $id = $this->getId(); $sql = "UPDATE `" . TABLE_PREFIX . "object_reminders` SET\n\t\t\t\t`date` = date_sub((SELECT `due_date` FROM `" . TABLE_PREFIX . "project_tasks` WHERE `id` = {$id}),\n\t\t\t\t\tinterval `minutes_before` minute) WHERE\n\t\t\t\t\t`object_manager` = 'ProjectTasks' AND `object_id` = {$id};"; DB::execute($sql); } $tasks = $this->getSubTasks(); if (is_array($tasks)) { $task_ids = array(); foreach ($tasks as $task) { $task_ids[] = $task->getId(); } // if if (count($task_ids) > 0) { ApplicationLogs::setIsPrivateForType($this->isPrivate(), 'ProjectTasks', $task_ids); } // if } // if return true; }