Ejemplo n.º 1
0
/**
* returns NULL on failure
*/
function getDateTimeFieldValue($field_id)
{
    $value_date = get($field_id . '_date');
    if ($value_date === "" || $value_date === "-") {
        $value_date = "0000-00-00";
    }
    $value_time = get($field_id . '_time');
    if ($value_time === "" || $value_time === "-") {
        $value_time = "00:00:00";
    }
    if ($value_date && $value_time) {
        $value = $value_date . " " . $value_time;
        # dd.mm.yyyyy hh:mm:ss
        if (preg_match("/\\b(\\d?\\d)[^\\d](\\d?\\d)[^\\d](\\d\\d\\d\\d)\\s+(\\d\\d)[^\\d](\\d?\\d)[^\\d](\\d?\\d)\\b/", $value, $matches) && count($matches) == 7) {
            $value = $matches[3] . '-' . $matches[2] . '-' . $matches[1] . ' ' . $matches[4] . ':' . $matches[5] . ':' . $matches[6];
        } else {
            if (preg_match("/\\b(\\d\\d\\d\\d)[^\\d](\\d?\\d)[^\\d](\\d?\\d)\\s+(\\d\\d)[^\\d](\\d\\d)[^\\d](\\d\\d)\\b/", $value, $matches) && count($matches) == 7) {
                # $value=$value;        # just fine...
            } else {
                if (preg_match("/(\\w*)\\s(\\d\\d),\\s*(\\d\\d\\d\\d)\\s+(\\d\\d)[^\\d](\\d\\d)[^\\d](\\d\\d)/i", $value, $matches) && count($matches) == 7 && ($mon = string2month($matches[1]))) {
                    $value = $matches[3] . '-' . $mon . '-' . $matches[2] . ' ' . $matches[4] . ':' . $matches[5] . ':' . $matches[6];
                } else {
                    if (preg_match("/(\\w*)\\s(\\d\\d),\\s*(\\d\\d\\d\\d)\\s+(\\d\\d)[^\\d](\\d\\d)/i", $value, $matches) && count($matches) == 6 && ($mon = string2month($matches[1]))) {
                        $value = $matches[3] . '-' . $mon . '-' . $matches[2] . ' ' . $matches[4] . ':' . $matches[5] . ':00';
                    } else {
                        if (preg_match("/(\\w*)\\s(\\d\\d),\\s*(\\d\\d\\d\\d)/i", $value, $matches) && count($matches) == 4 && ($mon = string2month($matches[1]))) {
                            $value = $matches[3] . '-' . $mon . '-' . $matches[2] . ' 00-00-00';
                        } else {
                            if (preg_match("/(\\d?\\d)\\.\\s*(\\w*)\\s*(\\d\\d\\d\\d)\\s+(\\d\\d)[^\\d](\\d\\d)[^\\d](\\d\\d)/i", $value, $matches) && count($matches) == 7 && ($mon = string2month($matches[2]))) {
                                $value = $matches[3] . '-' . $mon . '-' . $matches[1] . ' ' . $matches[4] . ':' . $matches[5] . ':' . $matches[6];
                            } else {
                                if (preg_match("/(\\d\\d)\\.\\s*(\\d\\d)\\.\\s*(\\d\\d\\d\\d)\\s+(\\d\\d)[^\\d](\\d\\d)[^\\d](\\d\\d)/i", $value, $matches) && count($matches) == 7) {
                                    $value = $matches[3] . '-' . $mon . '-' . $matches[1] . ' ' . $matches[4] . ':' . $matches[5] . ':' . $matches[6];
                                } else {
                                    if (preg_match("/(\\d\\d)\\.\\s*(\\d\\d)\\.\\s*(\\d\\d\\d\\d)\\s+(\\d?\\d)[^\\d](\\d?\\d)/i", $value, $matches) && count($matches) == 6) {
                                        $value = $matches[3] . '-' . $matches[2] . '-' . $matches[1] . ' ' . $matches[4] . ':' . $matches[5] . ':00';
                                    } else {
                                        new FeedbackMessage(sprintf(__("<b>%s</b> is not a known format for date."), $value));
                                        $value = "0000-00-00 00:00:00";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        global $auth;
        if ($value != "0000-00-00 00:00:00") {
            $value = clientTimeStrToGMTString($value);
        }
        return $value;
    }
}
Ejemplo n.º 2
0
/**
* Edit an effort @ingroup pages
*/
function effortEdit($effort = NULL)
{
    global $PH;
    global $g_effort_status_names;
    global $g_effort_billing_names;
    if (!$effort) {
        $ids = getPassedIds('effort', 'efforts_*');
        if (!$ids) {
            $PH->abortWarning(__("Select some efforts(s) to edit"), ERROR_NOTE);
            return;
        } else {
            if (count($ids) > 1) {
                $PH->show('effortEditMultiple');
                exit;
            } else {
                if (!($effort = Effort::getEditableById($ids[0]))) {
                    $PH->abortWarning("ERROR: could not get Effort");
                    return;
                }
            }
        }
    }
    if (!($project = Project::getVisibleById($effort->project))) {
        $PH->abortWarning("ERROR: could not get Project", ERROR_BUG);
    }
    $task = Task::getVisibleById($effort->task);
    $page = new Page(array('use_jscalendar' => true, 'autofocus_field' => 'effort_name'));
    $page->cur_tab = 'projects';
    $page->type = __('Edit Effort', 'page type');
    $page->title = $effort->name;
    /**
     * @@@ refactor with initPageForEffort()
     */
    #        if($task) {
    #            $page->crumbs= build_task_crumbs($task);
    #        }
    #        else {
    $page->crumbs = build_project_crumbs($project);
    #        }
    $page->crumbs[] = new NaviCrumb(array('target_id' => 'effortEdit'));
    if ($effort->id) {
        $page->title = __('Edit Effort', 'page title');
    } else {
        $page->title = __('New Effort', 'page title');
    }
    $page->title_minor = sprintf(__('On project %s', 'page title add on'), $project->name);
    echo new PageHeader();
    echo new PageContentOpen();
    $block = new PageBlock(array('id' => 'edit'));
    $block->render_blockStart();
    require_once confGet('DIR_STREBER') . 'render/render_form.inc.php';
    $form = new PageForm();
    $form->button_cancel = true;
    ### automatically write fields ###
    #   foreach($effort->fields as $field) {
    #    $form->add($field->getFormElement($effort));
    #   }
    $form->add($effort->fields['name']->getFormElement($effort));
    if ($effort->as_duration) {
        /**
         * NOTE:
         * - Durations are stored with two datetimes in GMT. The first is
         * starting at 00:00:00 GMT the second defined the distant also in GMT.
         * Since the edit form would try to convert the time_end into client time
         * we overwrite it here. This might be called a hack.
         */
        $effort->time_end = clientTimeStrToGMTString($effort->time_end);
        $tmp_edit = $effort->fields['time_end']->getFormElement($effort);
        $tmp_edit->title = __("Date / Duration", "Field label when booking time-effort as duration");
        $form->add($tmp_edit);
    } else {
        $form->add($effort->fields['time_start']->getFormElement($effort));
        $form->add($effort->fields['time_end']->getFormElement($effort));
    }
    $form->add($effort->fields['description']->getFormElement($effort));
    $form->add(new Form_Dropdown("effort_status", __('Status'), array_flip($g_effort_status_names), $effort->status));
    $form->add(new Form_Dropdown("effort_billing", __('Billing'), array_flip($g_effort_billing_names), $effort->billing));
    $form->add(new Form_Dropdown("effort_productivity", __('Productivity'), array("*****" => 5, "****" => 4, "***" => 3, "**" => 2, "*" => 1), $effort->productivity));
    ### get meta-tasks / folders ###
    #$folders= $project->getFolders();
    $folders = Task::getAll(array('sort_hierarchical' => true, 'parent_task' => 0, 'show_folders' => true, 'folders_only' => false, 'status_min' => STATUS_UPCOMING, 'status_max' => STATUS_CLOSED, 'project' => $project->id));
    if ($folders) {
        $folder_list = array("undefined" => "0");
        if ($effort->task) {
            if ($task = Task::getVisibleById($effort->task)) {
                ### add, if normal task (folders will added below) ###
                if (!$task->category == TCATEGORY_FOLDER) {
                    $folder_list[$task->name] = $task->id;
                }
            }
        }
        foreach ($folders as $f) {
            $str = '';
            foreach ($f->getFolder() as $pf) {
                $str .= $pf->getShort() . " > ";
            }
            $str .= $f->name;
            $folder_list[$str] = $f->id;
        }
        $form->add(new Form_Dropdown('effort_task', __("For task"), $folder_list, $effort->task));
    }
    ### public-level ###
    if (($pub_levels = $effort->getValidUserSetPublicLevels()) && count($pub_levels) > 1) {
        $form->add(new Form_Dropdown('effort_pub_level', __("Publish to"), $pub_levels, $effort->pub_level));
    }
    echo $form;
    $block->render_blockEnd();
    $PH->go_submit = 'effortEditSubmit';
    echo "<input type=hidden name='effort_as_duration' value='{$effort->as_duration}'>";
    echo "<input type=hidden name='effort' value='{$effort->id}'>";
    echo "<input type=hidden name='effort_project' value='{$effort->project}'>";
    echo "<input type=hidden name='effort_person' value='{$effort->person}'>";
    echo new PageContentClose();
    echo new PageHtmlEnd();
}