Exemplo n.º 1
0
/**
* Edit note on person
*
* @ingroup pages
*/
function taskNoteOnPersonEdit($task = NULL, $person = NULL)
{
    global $PH;
    global $auth;
    global $g_pub_level_names;
    global $g_prio_names;
    if (!$task) {
        $id = getOnePassedId('tsk');
        if (!($task = Task::getEditableById($id))) {
            $PH->abortWarning(__("Select a note to edit"), ERROR_NOTE);
            return;
        }
    }
    ## get person ##
    if (!$person) {
        $pid = getOnePassedId('person');
        if (!($person = Person::getById($pid))) {
            $PH->abortWarning(__("ERROR: could not get Person"), ERROR_NOTE);
            return;
        }
    }
    $page = new Page(array('use_jscalendar' => false, 'autofocus_field' => 'task_name'));
    $page->cur_tab = 'people';
    if ($person->id) {
        $page->crumbs = build_person_crumbs($person);
    }
    $page->crumbs[] = new NaviCrumb(array('target_id' => 'taskNoteOnPersonEdit'));
    $page->type = __("Note");
    if (!$task->id) {
        $page->title = __('Create new note');
        $page->title_minor = __('Edit');
        ## default title ##
        $date = gmdate("Y-m-d", time());
        $time = getGMTString();
        $dt = $date . " " . renderTime($time);
        $task->name = sprintf(__("New Note on %s, %s"), $person->name, $dt);
    }
    ## eventually needed later when note is a subcategory of task
    /*else {
          $page->title=$task->name;
          $page->title_minor=$task->short;
      }*/
    echo new PageHeader();
    echo new PageContentOpen();
    require_once confGet('DIR_STREBER') . 'render/render_form.inc.php';
    $form = new PageForm();
    $form->button_cancel = true;
    ## name field ##
    $form->add($task->fields['name']->getFormElement($task));
    ## description field ##
    $e = $task->fields['description']->getFormElement($task);
    $e->rows = 22;
    $form->add($e);
    ### public-level drop down menu ###
    $form->add(new Form_Dropdown('task_pub_level', __("Publish to", "Form label"), array_flip($g_pub_level_names), $task->pub_level));
    ## priority drop down menu##
    $form->add(new Form_Dropdown('task_prio', __("Prio", "Form label"), array_flip($g_prio_names), $task->prio));
    if ($task->id == 0) {
        $proj_select = 0;
    }
    $p_list = array();
    $count = 1;
    $p_projects = $person->getProjects();
    $num = count($p_projects);
    if ($num > 0) {
        $p_list[0] = __('Assigned Projects');
        foreach ($p_projects as $pp) {
            $p_list[$pp->id] = "- " . $pp->name;
            $count++;
        }
    }
    $p_companies = $person->getCompanies();
    $num = count($p_companies);
    if ($num > 0) {
        $p_list['-1'] = __('Company Projects');
        foreach ($p_companies as $pcs) {
            $c_id = $pcs->id;
            $c_projects = Project::getAll(array('company' => $c_id));
            $count2 = 0;
            foreach ($c_projects as $cp) {
                $p_list[$cp->id] = "- " . $cp->name;
            }
        }
    }
    if (!($projects = Project::getAll(array('order_by' => 'name ASC')))) {
    } else {
        $p_list['-2'] = __('All other Projects');
        foreach ($projects as $pj) {
            $p_list[$pj->id] = "- " . $pj->name;
        }
    }
    $form->add(new Form_Dropdown('project', __('For Project', 'form label'), array_flip($p_list), $proj_select, "id='proj_list'"));
    ## new project ##
    if ($task->id == 0) {
        $form->add(new Form_checkbox('new_project', __('New project', 'form label'), false, "id='proj_new_checkbox'"));
        $form->add(new Form_Input('new_project_name', __('Project name', 'form label'), false, NULL, false, "id='proj_new_input'", "style='display:none'"));
    }
    $checked1 = "";
    $checked2 = "";
    if ($task->id == 0) {
        $checked1 = "checked";
        $checked2 = "checked";
        $person_select = -1;
    }
    ## eventually needed later when note is a subcategory of task
    /*else {
          if(!$pperson = $task->getAssignedPeople()){
              $PH->abortWarning(__("ERROR: could not get assigned people"), ERROR_NOTE);
          }
          else{
              foreach($pperson as $pp){
                  if($pp->id == $person->id){
                      $checked1= "checked";
                  }
                  elseif($pp->id == $auth->cur_user->id){
                      $checked2= "checked";
                  }
                  else{
                      $person_select = $pp->id;
                  }
              }
          }
      }*/
    $form->add(new Form_customHTML('<p><label>' . __('Assign to') . '</lable></p>', 'assigne_note'));
    if ($person->id != $auth->cur_user->id) {
        $form->add(new Form_customHTML('<span class="checker"><input value="' . $person->id . '" name="task_assignement1" type="checkbox" ' . $checked1 . '><label for="task_assignement1">' . $person->name . '</label></span>', 'assigned_person1'));
        $form->add(new Form_customHTML('<span class="checker"><input value="' . $auth->cur_user->id . '" name="task_assignement2" type="checkbox" ' . $checked2 . '><label for="task_assignement2">' . $auth->cur_user->name . '</label></span>', 'assigned_person2'));
    } else {
        $form->add(new Form_customHTML('<span class="checker"><input value="' . $auth->cur_user->id . '" name="task_assignement2" type="checkbox" ' . $checked2 . '><label for="task_assignement2">' . $auth->cur_user->name . '</label></span>', 'assigned_person'));
    }
    $pers_list = array();
    $pers_list[-1] = __('undefined');
    if ($people = Person::getPeople(array('can_login' => 1))) {
        foreach ($people as $pers) {
            if ($auth->cur_user->name != $pers->name) {
                $pers_list[$pers->id] = $pers->name;
            }
        }
    }
    $form->add(new Form_Dropdown('task_also_assign', __('Also assign to'), array_flip($pers_list), $person_select));
    ## Book effort after submit ##
    $form->form_options[] = "<span class=option><input id='book_effort' name='book_effort' class='checker' type=checkbox>" . __("Book effort after submit") . "</span>";
    $form->add(new Form_HiddenField('tsk', '', $task->id));
    $form->add(new Form_HiddenField('person_id', '', $person->id));
    $form->add(new Form_HiddenField('creation_time', '', $time));
    echo $form;
    $PH->go_submit = 'taskNoteOnPersonEditSubmit';
    echo new PageContentClose();
    echo new PageHtmlEnd();
}
Exemplo n.º 2
0
 function render_tr(&$obj, $style = "")
 {
     if (!isset($obj) || !$obj instanceof Effort) {
         trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING);
         return;
     }
     if ($obj->as_duration) {
         $value = "";
     } else {
         $value = renderTime($obj->time_end);
     }
     print "<td>{$value}</td>";
 }
Exemplo n.º 3
0
/**
* renders a comparision between two versions of an item @ingroup pages
*/
function itemViewDiff()
{
    global $PH;
    global $auth;
    require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php';
    ### get task ####
    $item_id = get('item');
    if (!($item = DbProjectItem::getObjectById($item_id))) {
        $PH->abortWarning("invalid item-id", ERROR_FATAL);
    }
    if (!($project = Project::getVisibleById($item->project))) {
        $PH->abortWarning("this item has an invalid project id", ERROR_DATASTRUCTURE);
    }
    require_once confGet('DIR_STREBER') . "db/db_itemchange.inc.php";
    $versions = ItemVersion::getFromItem($item);
    $date1 = get('date1');
    $date2 = get('date2');
    if (!$date1) {
        #if(count($versions) > 1) {
        #    if($auth->cur_user->last_logout < $versions[count($versions)-2]->date_to)
        #    {
        #        $date1 = $auth->cur_user->last_logout;
        #    }
        #    else {
        #        $date1 = $versions[count($versions)-2]->date_from;
        #    }
        #}
        #else {
        foreach (array_reverse($versions) as $v) {
            if ($v->author == $auth->cur_user->id) {
                $date1 = $v->date_from;
                break;
            }
        }
        #}
    }
    if (!$date2) {
        $date2 = getGMTString();
    }
    $page = new Page();
    $page->cur_tab = 'projects';
    $page->crumbs = build_project_crumbs($project);
    $page->options = build_projView_options($project);
    $page->title = $item->name;
    $page->title_minor = __('changes');
    $page->add_function(new PageFunction(array('target' => 'itemView', 'params' => array('item' => $item->id), 'icon' => 'edit', 'name' => __('View item'))));
    ### render title ###
    echo new PageHeader();
    echo new PageContentOpen();
    if ($date1 > $date2) {
        new FeedbackMessage(__("date1 should be smaller than date2. Swapped"));
        $t = $date1;
        $date1 = $date2;
        $date2 = $t;
    }
    if (count($versions) == 1) {
        echo __("item has not been edited history");
    } else {
        $old_version = NULL;
        $version_right = NULL;
        $version_left = $versions[0];
        foreach ($versions as $v) {
            if ($v->date_from <= $date1) {
                $version_left = $v;
            }
            if ($v->date_from >= $date2) {
                if (isset($version_right)) {
                    if ($version_right->date_from > $v->date_from) {
                        $version_right = $v;
                    }
                } else {
                    $version_right = $v;
                }
            }
        }
        if (!isset($version_right)) {
            $version_right = $versions[count($versions) - 1];
        }
        $options_left = array();
        $options_right = array();
        ### list versions left ###
        for ($i = 0; $i < count($versions) - 1; $i++) {
            $v = $versions[$i];
            if ($person = Person::getVisibleById($v->author)) {
                $author = $person->name;
            } else {
                $author = __('unknown');
            }
            if ($v->version_number == $version_left->version_number) {
                $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to));
                $name = ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . " -- " . $v->date_from;
                $options_left[] = "<option selected=1 value='" . $str_link . "'>" . $name . "</option>";
            } else {
                if ($v->version_number > $version_left->version_number) {
                    if ($v->version_number < $version_right->version_number) {
                        $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to));
                        $name = '&gt; &nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from);
                    } else {
                        $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $version_right->date_to));
                        $name = '&gt;&gt;&nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from);
                    }
                    $options_left[] = "<option  value='" . $str_link . "'>" . $name . "</option>";
                } else {
                    $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $version_right->date_from));
                    $name = '&lt; &nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from);
                    $options_left[] = "<option  value='" . $str_link . "'>" . $name . "</option>";
                }
            }
        }
        ### list versions right ###
        for ($i = 1; $i < count($versions); $i++) {
            $v = $versions[$i];
            if ($person = Person::getVisibleById($v->author)) {
                $author = $person->name;
            } else {
                $author = __('unknown');
            }
            if ($v->version_number == $version_right->version_number) {
                $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to));
                $name = ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . " -- " . $v->date_from;
                $options_right[] = "<option selected=1 value='" . $str_link . "'>" . $name . "</option>";
            } else {
                if ($v->version_number > $version_right->version_number) {
                    $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $version_left->date_from, 'date2' => $versions[$i]->date_from));
                    $name = '&gt; &nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . ' -- ' . renderDate($v->date_from);
                    $options_right[] = "<option  value='" . $str_link . "'>" . $name . "</option>";
                } else {
                    if ($v->version_number > $version_left->version_number) {
                        $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $version_left->date_from, 'date2' => $versions[$i]->date_from));
                        $name = '&lt; &nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from);
                    } else {
                        $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to));
                        $name = '&lt;&lt;&nbsp;&nbsp; v.' . $v->version_number . ' -- ' . $author . ' -- ' . renderDate($v->date_from);
                    }
                    $options_right[] = "<option  value='" . $str_link . "'>" . $name . "</option>";
                }
            }
        }
        ### prev ###
        if ($version_left->version_number > 1) {
            $link_prev = $PH->getLink('itemViewDiff', '&lt;&lt; ' . __('prev change'), array('item' => $item->id, 'date1' => $versions[$version_left->version_number - 2]->date_from, 'date2' => $versions[$version_left->version_number - 2]->date_to), NULL, true);
        } else {
            $link_prev = '';
        }
        ### next ###
        if ($version_right->version_number < count($versions)) {
            $link_next = $PH->getLink('itemViewDiff', __('next') . '&gt;&gt;', array('item' => $item->id, 'date1' => $versions[$version_right->version_number - 1]->date_from, 'date2' => $versions[$version_right->version_number - 1]->date_to), NULL, true);
        } else {
            $link_next = '';
        }
        ### summary ###
        $link_summary = $PH->getLink('itemViewDiff', __('summary'), array('item' => $item->id, 'date1' => $auth->cur_user->last_logout, 'date2' => getGMTString()), NULL, true);
        echo "<div class=diff>";
        echo "<table class=nav><tr>";
        echo "<td class=older>" . "<select onChange='location.href=this.options[this.selectedIndex].value'>" . join(array_reverse($options_left)) . "</select>" . '<br><b class=doclear></b>' . $link_prev . "</td>";
        echo "<td class=newer>" . "<select onChange='location.href=this.options[this.selectedIndex].value'>" . join(array_reverse($options_right)) . "</select>" . '<br><b class=doclear></b>' . $link_next . $link_summary . "</td>";
        echo "</table>";
        #if(!$date2 || !$date1) {
        #    echo sprintf(__("Item did not exists at %s"), renderTime($date2));
        #}
        if ($old_version == $version_right) {
            echo sprintf(__('no changes between %s and %s'), renderTime($date1), renderTime($date2));
        }
        ### collect changes ###
        $old_field_values = array();
        $new_field_values = array();
        foreach ($versions as $v) {
            if ($v->version_number <= $version_left->version_number) {
                foreach ($v->values as $name => $value) {
                    $old_field_values[$name] = $value;
                }
            }
            if ($v->version_number >= $version_left->version_number && $v->version_number < $version_right->version_number) {
                foreach ($v->values_next as $name => $value) {
                    $new_field_values[$name] = $value;
                }
            }
        }
        foreach ($new_field_values as $field_name => $value) {
            echo "<h2>{$field_name}</h2>";
            $old_value = isset($old_field_values[$field_name]) ? $old_field_values[$field_name] : "";
            $new_value = isset($new_field_values[$field_name]) ? $new_field_values[$field_name] : '';
            $field_type = $item->fields[$field_name]->type;
            if ($field_type == 'FieldText') {
                echo render_changes($old_value, $new_value);
            } else {
                if ($field_type == 'FieldOption') {
                    if ($field_name == 'status') {
                        global $g_status_names;
                        $old_value = isset($g_status_names[$old_value]) ? $g_status_names[$old_value] : __('undefined');
                        $new_value = isset($g_status_names[$new_value]) ? $g_status_names[$new_value] : __('undefined');
                    } else {
                        if ($field_name == 'label') {
                            if ($project = Project::getVisibleById($item->project)) {
                                $labels = explode(",", $project->labels);
                                $old_value = isset($labels[$old_value - 1]) ? $labels[$old_value - 1] : __('undefined');
                                $new_value = isset($labels[$new_value - 1]) ? $labels[$new_value - 1] : __('undefined');
                            }
                        }
                    }
                    echo render_changes($old_value, $new_value);
                } else {
                    if ($field_type == 'FieldInternal') {
                        if ($field_name == 'parent_item') {
                            if ($task_parent_old = Task::getVisibleById($old_value)) {
                                $ar = array();
                                foreach ($task_parent_old->getFolder() as $f) {
                                    $ar[] = $f->name;
                                }
                                $ar[] = $task_parent_old->name;
                                $old_value = join($ar, " > ");
                            }
                            if ($task_parent_new = Task::getVisibleById($new_value)) {
                                $ar = array();
                                foreach ($task_parent_new->getFolder() as $f) {
                                    $ar[] = $f->name;
                                }
                                $ar[] = $task_parent_new->name;
                                $new_value = join($ar, " > ");
                            }
                        } else {
                            if ($field_name == 'state') {
                                $old_value = $old_value == -1 ? __('deleted') : __('ok');
                                $new_value = $new_value == -1 ? __('deleted') : __('ok');
                            } else {
                                if ($field_name == 'pub_level') {
                                    global $g_pub_level_names;
                                    $old_value = isset($g_pub_level_names[$old_value]) ? $g_pub_level_names[$old_value] : __('undefined');
                                    $new_value = isset($g_pub_level_names[$new_value]) ? $g_pub_level_names[$new_value] : __('undefined');
                                }
                            }
                        }
                        echo render_changes($old_value, $new_value);
                    } else {
                        if ($field_type == 'FieldPercentage') {
                            echo render_changes($old_value, $new_value);
                        } else {
                            if ($field_type == 'FieldInt') {
                                echo render_changes($old_value, $new_value);
                            } else {
                                if ($field_type == 'FieldString') {
                                    echo render_changes($old_value, $new_value);
                                } else {
                                    if ($field_type == 'FieldDate') {
                                        echo render_changes(renderDate($old_value), renderDate($new_value));
                                    } else {
                                        if ($field_type == 'FieldDatetime') {
                                            echo render_changes(renderTimestamp($old_value), renderTimestamp($new_value));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    echo "</div>";
    echo new PageContentClose();
    echo new PageHtmlEnd();
}