예제 #1
0
<?php
$genid = gen_id();
$limit = 20;
$total = $limit;
$page = 10;

$task_assignment_conditions = "";
if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) {
	$task_assignment_conditions = " AND assigned_to_contact_id = ".logged_user()->getId();
}

$tasks_result = ProjectTasks::instance()->listing(array(
	"order" => "completed_on",
	"order_dir" => "DESC",
	"extra_conditions" => " AND is_template = 0 AND completed_by_id > 0 $task_assignment_conditions",
	"limit" => $limit + 1,
));

$tasks = $tasks_result->objects;

$active_members = array();
$context = active_context();
foreach ($context as $selection) {
	if ($selection instanceof Member) $active_members[] = $selection;
}
if (count($active_members) > 0) {
	$mnames = array();
	$allowed_contact_ids = array();
	foreach ($active_members as $member) {
		$mnames[] = clean($member->getName());
	}
예제 #2
0
 function new_list_tasks()
 {
     //load config options into cache for better performance
     load_user_config_options_by_category_name('task panel');
     // get query parameters, save user preferences if necessary
     $status = array_var($_GET, 'status', null);
     if (is_null($status) || $status == '') {
         $status = user_config_option('task panel status', 2);
     } else {
         if (user_config_option('task panel status') != $status) {
             set_user_config_option('task panel status', $status, logged_user()->getId());
         }
     }
     $previous_filter = user_config_option('task panel filter', 'no_filter');
     $filter = array_var($_GET, 'filter');
     if (is_null($filter) || $filter == '') {
         $filter = $previous_filter;
     } else {
         if ($previous_filter != $filter) {
             set_user_config_option('task panel filter', $filter, logged_user()->getId());
         }
     }
     if ($filter != 'no_filter') {
         $filter_value = array_var($_GET, 'fval');
         if (is_null($filter_value) || $filter_value == '') {
             $filter_value = user_config_option('task panel filter value', null, logged_user()->getId());
             set_user_config_option('task panel filter value', $filter_value, logged_user()->getId());
             $filter = $previous_filter;
             set_user_config_option('task panel filter', $filter, logged_user()->getId());
         } else {
             if (user_config_option('task panel filter value') != $filter_value) {
                 set_user_config_option('task panel filter value', $filter_value, logged_user()->getId());
             }
         }
     }
     $isJson = array_var($_GET, 'isJson', false);
     if ($isJson) {
         ajx_current("empty");
     }
     $template_condition = "`is_template` = 0 ";
     //Get the task query conditions
     $task_filter_condition = "";
     switch ($filter) {
         case 'assigned_to':
             $assigned_to = $filter_value;
             if ($assigned_to > 0) {
                 $task_filter_condition = " AND (`assigned_to_contact_id` = " . $assigned_to . ") ";
             } else {
                 if ($assigned_to == -1) {
                     $task_filter_condition = " AND `assigned_to_contact_id` = 0";
                 }
             }
             break;
         case 'assigned_by':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `assigned_by_id` = " . $filter_value . " ";
             }
             break;
         case 'created_by':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `created_by_id` = " . $filter_value . " ";
             }
             break;
         case 'completed_by':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `completed_by_id` = " . $filter_value . " ";
             }
             break;
         case 'milestone':
             $task_filter_condition = " AND  `milestone_id` = " . $filter_value . " ";
             break;
         case 'priority':
             $task_filter_condition = " AND  `priority` = " . $filter_value . " ";
             break;
         case 'subtype':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `object_subtype` = " . $filter_value . " ";
             }
             break;
         case 'no_filter':
             $task_filter_condition = "";
             break;
         default:
             flash_error(lang('task filter criteria not recognised', $filter));
     }
     $task_status_condition = "";
     $now = DateTimeValueLib::now()->format('Y-m-j 00:00:00');
     switch ($status) {
         case 0:
             // Incomplete tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME);
             break;
         case 1:
             // Complete tasks
             $task_status_condition = " AND `completed_on` > " . DB::escape(EMPTY_DATETIME);
             break;
         case 10:
             // Active tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}'";
             break;
         case 11:
             // Overdue tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` < '{$now}'";
             break;
         case 12:
             // Today tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` = '{$now}'";
             break;
         case 13:
             // Today + Overdue tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'";
             break;
         case 14:
             // Today + Overdue tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'";
             break;
         case 20:
             // Actives task by current user
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}' AND `assigned_to_contact_id` = " . logged_user()->getId();
             break;
         case 21:
             // Subscribed tasks by current user
             $res20 = DB::execute("SELECT object_id FROM " . TABLE_PREFIX . "object_subscriptions WHERE `contact_id` = " . logged_user()->getId());
             $subs_rows = $res20->fetchAll($res20);
             foreach ($subs_rows as $row) {
                 $subs[] = $row['object_id'];
             }
             unset($res20, $subs_rows, $row);
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `id` IN(" . implode(',', $subs) . ")";
             break;
         case 2:
             // All tasks
             break;
         default:
             throw new Exception('Task status "' . $status . '" not recognised');
     }
     $conditions = "AND {$template_condition} {$task_filter_condition} {$task_status_condition}";
     //Now get the tasks
     //$tasks = ProjectTasks::getContentObjects(active_context(), ObjectTypes::findById(ProjectTasks::instance()->getObjectTypeId()), null, null, $conditions,null)->objects;
     $tasks = ProjectTasks::instance()->listing(array("extra_conditions" => $conditions, "start" => 0, "limit" => 501, "count_results" => false))->objects;
     $pendingstr = $status == 0 ? " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " " : "";
     $milestone_conditions = " AND `is_template` = false " . $pendingstr;
     //Find all internal milestones for these tasks
     //$internalMilestones = ProjectMilestones::getContentObjects(active_context(), ObjectTypes::findById(ProjectMilestones::instance()->getObjectTypeId()), null, null, $milestone_conditions,null)->objects;
     $internalMilestones = ProjectMilestones::instance()->listing(array("extra_conditions" => $milestone_conditions))->objects;
     //Find all external milestones for these tasks, external milestones are the ones that belong to a parent member and have tasks in the current member
     $milestone_ids = array();
     if ($tasks) {
         foreach ($tasks as $task) {
             if ($task->getMilestoneId() != 0) {
                 $milestone_ids[$task->getMilestoneId()] = $task->getMilestoneId();
             }
         }
     }
     $int_milestone_ids = array();
     foreach ($internalMilestones as $milestone) {
         $int_milestone_ids[] = $milestone->getId();
     }
     $milestone_ids = array_diff($milestone_ids, $int_milestone_ids);
     if (count($milestone_ids) == 0) {
         $milestone_ids[] = 0;
     }
     $ext_milestone_conditions = " `is_template` = false " . $pendingstr . ' AND `object_id` IN (' . implode(',', $milestone_ids) . ')';
     $externalMilestones = ProjectMilestones::findAll(array('conditions' => $ext_milestone_conditions));
     // Get Users Info
     $users = allowed_users_in_context(ProjectTasks::instance()->getObjectTypeId(), active_context(), ACCESS_LEVEL_READ);
     $allUsers = Contacts::getAllUsers();
     $user_ids = array(-1);
     foreach ($users as $user) {
         $user_ids[] = $user->getId();
     }
     // only companies with users
     $companies = Contacts::findAll(array("conditions" => "e.is_company = 1", "join" => array("table" => Contacts::instance()->getTableName(), "jt_field" => "object_id", "j_sub_q" => "SELECT xx.object_id FROM " . Contacts::instance()->getTableName(true) . " xx WHERE \n\t\t\t\t\txx.is_company=0 AND xx.company_id = e.object_id AND xx.object_id IN (" . implode(",", $user_ids) . ") LIMIT 1")));
     tpl_assign('tasks', $tasks);
     if (config_option('use tasks dependencies')) {
         $dependency_count = array();
         foreach ($tasks as $task) {
             $previous = 0;
             $ptasks = ProjectTaskDependencies::getDependenciesForTask($task->getId());
             foreach ($ptasks as $pdep) {
                 $ptask = ProjectTasks::findById($pdep->getPreviousTaskId());
                 if ($ptask instanceof ProjectTask && !$ptask->isCompleted()) {
                     $previous++;
                 }
             }
             $dependants = ProjectTaskDependencies::getDependantsForTask($task->getId());
             $dep_csv = "";
             foreach ($dependants as $dep) {
                 $dep_csv .= ($dep_csv == "" ? "" : ",") . $dep->getTaskId();
             }
             $dependency_count[] = array('id' => $task->getId(), 'count' => $previous, 'dependants' => $dep_csv);
         }
         tpl_assign('dependency_count', $dependency_count);
     }
     if (!$isJson) {
         $all_templates = COTemplates::findAll(array('conditions' => '`trashed_by_id` = 0 AND `archived_by_id` = 0'));
         tpl_assign('all_templates', $all_templates);
         if (user_config_option('task_display_limit') > 0 && count($tasks) > user_config_option('task_display_limit')) {
             tpl_assign('displayTooManyTasks', true);
             array_pop($tasks);
         }
         tpl_assign('object_subtypes', array());
         tpl_assign('internalMilestones', $internalMilestones);
         tpl_assign('externalMilestones', $externalMilestones);
         tpl_assign('users', $users);
         tpl_assign('allUsers', $allUsers);
         tpl_assign('companies', $companies);
         $userPref = array();
         $userPref = array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'status' => $status, 'showWorkspaces' => user_config_option('tasksShowWorkspaces', 1), 'showTime' => user_config_option('tasksShowTime'), 'showDates' => user_config_option('tasksShowDates'), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 1), 'showTimeEstimates' => user_config_option('tasksShowTimeEstimates', 1), 'groupBy' => user_config_option('tasksGroupBy', 'milestone'), 'orderBy' => user_config_option('tasksOrderBy', 'priority'), 'defaultNotifyValue' => user_config_option('can notify from quick add'));
         hook::fire('tasks_user_preferences', null, $userPref);
         tpl_assign('userPreferences', $userPref);
         ajx_set_no_toolbar(true);
     }
 }
예제 #3
0
function format_value_to_print($col, $value, $type, $obj_type_id, $textWrapper = '', $dateformat = 'Y-m-d')
{
    switch ($type) {
        case DATA_TYPE_STRING:
            if (preg_match(EMAIL_FORMAT, strip_tags($value))) {
                $formatted = strip_tags($value);
            } else {
                if ($col == 'is_user') {
                    $formatted = $value == 1 ? lang('yes') : lang('no');
                } else {
                    if (strpos($value, "�") !== false) {
                        $value = preg_replace('/\\xA0/s', ' ', $value);
                    }
                    $value = utf8_safe($value);
                    $formatted = $textWrapper . $value . $textWrapper;
                }
            }
            break;
        case DATA_TYPE_INTEGER:
            if ($col == 'priority') {
                switch ($value) {
                    case 100:
                        $formatted = lang('low priority');
                        break;
                    case 200:
                        $formatted = lang('normal priority');
                        break;
                    case 300:
                        $formatted = lang('high priority');
                        break;
                    case 400:
                        $formatted = lang('urgent priority');
                        break;
                    default:
                        $formatted = clean($value);
                }
            } elseif ($col == 'time_estimate') {
                if ($value > 0) {
                    $formatted = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($value * 60), 'hm', 60);
                } else {
                    $formatted = clean($value);
                }
            } else {
                $formatted = clean($value);
            }
            break;
        case DATA_TYPE_BOOLEAN:
            $formatted = $value == 1 ? lang('yes') : lang('no');
            break;
        case DATA_TYPE_DATE:
            if ($value != 0) {
                if (str_ends_with($value, "00:00:00")) {
                    $dateformat .= " H:i:s";
                }
                try {
                    $dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value);
                } catch (Exception $e) {
                    $formatted = $value;
                }
                if (!isset($formatted)) {
                    $formatted = format_date($dtVal, null, 0);
                }
            } else {
                $formatted = '';
            }
            break;
        case DATA_TYPE_DATETIME:
            if ($value != 0) {
                try {
                    $dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value);
                } catch (Exception $e) {
                    $formatted = $value;
                }
                if ($dtVal instanceof DateTimeValue) {
                    if ($obj_type_id == ProjectEvents::instance()->getObjectTypeId() || $obj_type_id == ProjectTasks::instance()->getObjectTypeId()) {
                        $dtVal->advance(logged_user()->getTimezone() * 3600, true);
                    }
                    if ($obj_type_id == ProjectEvents::instance()->getObjectTypeId() && ($col == 'start' || $col == 'duration')) {
                        $formatted = format_datetime($dtVal);
                    } else {
                        $formatted = format_date($dtVal, null, 0);
                    }
                }
            } else {
                $formatted = '';
            }
            break;
        default:
            $formatted = $value;
    }
    if ($formatted == '') {
        $formatted = '--';
    }
    return $formatted;
}
예제 #4
0
 /**
  * @deprecated
  * @author Ignacio Vazquez - elpepe.uy@gmail.com
  */
 static function _findAllowed()
 {
     //1.  Find members where user can add tasks
     //$sqlMembers = "
     $sql = "\n\t\t\tSELECT distinct(id) AS id\n\t\t\tFROM " . TABLE_PREFIX . "object_members om\n\t\t\tINNER JOIN " . TABLE_PREFIX . "templates t ON t.object_id = om.object_id\n\t\t\tINNER JOIN " . TABLE_PREFIX . "objects o ON om.object_id = o.id\n\t\t\tWHERE\n\t\t\t    member_id IN (  \n\t\t\t    \tSELECT distinct(member_id) \n\t\t\t\t\tFROM " . TABLE_PREFIX . "contact_member_permissions o \n\t\t\t\t\tWHERE object_type_id = " . ProjectTasks::instance()->getObjectTypeId() . " \n\t\t\t\t\tAND permission_group_id IN ( " . ContactPermissionGroups::getPermissionGroupIdsByContactCSV(logged_user()->getId()) . " ) AND can_write= 1 \n\t\t\t\t)\n\t\t\t\tAND is_optimization = 0\n\t\t\tGROUP BY om.object_id\t\t\n\t\t";
     $res = DB::execute($sql);
     $tpls = array();
     // Iterate on the results and make som filtering
     while ($row = $res->fetchRow()) {
         $tpl = COTemplates::instance()->findById($row['id']);
         $tpls[] = $tpl;
     }
     return $tpls;
 }
예제 #5
0
        /**
	 * Return manager instance
	 *
	 * @access protected
	 * @param void
	 * @return ProjectTasks
	 */
	function manager() {
		if(!($this->manager instanceof ProjectTasks)) $this->manager = ProjectTasks::instance();
		return $this->manager;
	} // manager
예제 #6
0
if (!(isset($tasks) || $userPreferences['groupBy'] == 'milestone')) {
    ?>
			<div style="font-size:130%;width:100%;text-align:center;padding-top:10px;color:#777;"><?php 
    echo lang('no tasks to display');
    ?>
</div>
	<?php 
}
?>
		</div>
	</div>
</div>

<script type="text/javascript">
	if (!ogTasks.tasks_object_type_id) ogTasks.tasks_object_type_id = '<?php 
echo ProjectTasks::instance()->getObjectTypeId();
?>
';
	if (rx__TasksDrag)
		rx__TasksDrag.initialize();

	ogTasks.userPreferences = Ext.util.JSON.decode(document.getElementById('hfUserPreferences').value);

	var mili = 0;
	if (og.TasksTopToolbar == 'undefined') {
		mili = 500;
	}

	// to prevent js execution before the js files are received
	setTimeout(function () {
		var ogTasksTT = new og.TasksTopToolbar({
 function new_list_tasks()
 {
     //load config options into cache for better performance
     load_user_config_options_by_category_name('task panel');
     // get query parameters, save user preferences if necessary
     $status = array_var($_GET, 'status', null);
     if (is_null($status) || $status == '') {
         $status = user_config_option('task panel status', 2);
     } else {
         if (user_config_option('task panel status') != $status) {
             set_user_config_option('task panel status', $status, logged_user()->getId());
         }
     }
     $previous_filter = user_config_option('task panel filter', 'assigned_to');
     $filter = array_var($_GET, 'filter');
     if (is_null($filter) || $filter == '') {
         $filter = user_config_option('task panel filter', 'assigned_to');
     } else {
         if (user_config_option('task panel filter') != $filter) {
             set_user_config_option('task panel filter', $filter, logged_user()->getId());
         }
     }
     if ($filter != 'no_filter') {
         $filter_value = array_var($_GET, 'fval');
         if (is_null($filter_value) || $filter_value == '') {
             $filter_value = user_config_option('task panel filter value', logged_user()->getCompanyId() . ':' . logged_user()->getId());
             set_user_config_option('task panel filter value', $filter_value, logged_user()->getId());
             $filter = $previous_filter;
             set_user_config_option('task panel filter', $filter, logged_user()->getId());
         } else {
             if (user_config_option('task panel filter value') != $filter_value) {
                 set_user_config_option('task panel filter value', $filter_value, logged_user()->getId());
             }
         }
     }
     $isJson = array_var($_GET, 'isJson', false);
     if ($isJson) {
         ajx_current("empty");
     }
     $project = active_project();
     $tag = active_tag();
     $template_condition = "`is_template` = 0 ";
     //Get the task query conditions
     $task_filter_condition = "";
     switch ($filter) {
         case 'assigned_to':
             $assigned_to = explode(':', $filter_value);
             $assigned_to_user = array_var($assigned_to, 1, 0);
             $assigned_to_company = array_var($assigned_to, 0, 0);
             if ($assigned_to_user > 0) {
                 $task_filter_condition = " AND (`assigned_to_user_id` = " . $assigned_to_user . " OR (`assigned_to_company_id` = " . $assigned_to_company . " AND `assigned_to_user_id` = 0)) ";
             } else {
                 if ($assigned_to_company > 0) {
                     $task_filter_condition = " AND  `assigned_to_company_id` = " . $assigned_to_company . " AND `assigned_to_user_id` = 0";
                 } else {
                     if ($assigned_to_company == -1 && $assigned_to_user == -1) {
                         $task_filter_condition = "  AND `assigned_to_company_id` = 0 AND `assigned_to_user_id` = 0 ";
                     }
                 }
             }
             break;
         case 'assigned_by':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `assigned_by_id` = " . $filter_value . " ";
             }
             break;
         case 'created_by':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `created_by_id` = " . $filter_value . " ";
             }
             break;
         case 'completed_by':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `completed_by_id` = " . $filter_value . " ";
             }
             break;
         case 'milestone':
             $task_filter_condition = " AND  `milestone_id` = " . $filter_value . " ";
             break;
         case 'priority':
             $task_filter_condition = " AND  `priority` = " . $filter_value . " ";
             break;
         case 'subtype':
             if ($filter_value != 0) {
                 $task_filter_condition = " AND  `object_subtype` = " . $filter_value . " ";
             }
             break;
         case 'no_filter':
             $task_filter_condition = "";
             break;
         default:
             flash_error(lang('task filter criteria not recognised', $filter));
     }
     if ($project instanceof Project) {
         $pids = $project->getAllSubWorkspacesQuery(true);
         $projectstr = " AND " . ProjectTasks::getWorkspaceString($pids);
     } else {
         $pids = "";
         $projectstr = "";
     }
     $permissions = " AND " . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user());
     $task_status_condition = "";
     switch ($status) {
         case 0:
             // Incomplete tasks
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME);
             break;
         case 1:
             // Complete tasks
             $task_status_condition = " AND `completed_on` > " . DB::escape(EMPTY_DATETIME);
             break;
         case 10:
             // Active tasks
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}'";
             break;
         case 11:
             // Overdue tasks
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` < '{$now}'";
             break;
         case 12:
             // Today tasks
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` = '{$now}'";
             break;
         case 13:
             // Today + Overdue tasks
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'";
             break;
         case 14:
             // Today + Overdue tasks
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'";
             break;
         case 20:
             // Actives task by current user
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}' AND `assigned_to_user_id` = " . logged_user()->getId();
             break;
         case 21:
             // Subscribed tasks by current user
             $res20 = DB::execute("SELECT object_id FROM " . TABLE_PREFIX . "object_subscriptions WHERE `object_manager` LIKE 'ProjectTasks' AND `user_id` = " . logged_user()->getId());
             $subs_rows = $res20->fetchAll($res20);
             foreach ($subs_rows as $row) {
                 $subs[] = $row['object_id'];
             }
             unset($res20, $subs_rows, $row);
             $now = date('Y-m-j 00:00:00');
             $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `id` IN(" . implode(',', $subs) . ")";
             break;
         case 2:
             // All tasks
             break;
         default:
             throw new Exception('Task status "' . $status . '" not recognised');
     }
     if (!$tag) {
         $tagstr = "";
     } else {
         $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_tasks.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectTasks' ) > 0 ";
     }
     $conditions = $template_condition . $task_filter_condition . $task_status_condition . $permissions . $tagstr . $projectstr . " AND `trashed_by_id` = 0 AND `archived_by_id` = 0";
     //Now get the tasks
     $tasks = ProjectTasks::findAll(array('conditions' => $conditions, 'order' => 'created_on DESC', 'limit' => user_config_option('task_display_limit') > 0 ? user_config_option('task_display_limit') + 1 : null));
     ProjectTasks::populateData($tasks);
     //Find all internal milestones for these tasks
     $internalMilestones = ProjectMilestones::getProjectMilestones(active_or_personal_project(), null, 'DESC', "", null, null, null, $status == 0, false);
     ProjectMilestones::populateData($internalMilestones);
     //Find all external milestones for these tasks
     $milestone_ids = array();
     if ($tasks) {
         foreach ($tasks as $task) {
             if ($task->getMilestoneId() != 0) {
                 $milestone_ids[$task->getMilestoneId()] = $task->getMilestoneId();
             }
         }
     }
     $milestone_ids_condition = '';
     if (count($milestone_ids) > 0) {
         $milestone_ids_condition = ' OR id in (' . implode(',', $milestone_ids) . ')';
     }
     if ($status == 0) {
         $pendingstr = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " ";
     } else {
         $pendingstr = "";
     }
     if (!$tag) {
         $tagstr = "";
     } else {
         $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_milestones.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectMilestones' ) > 0 ";
     }
     $projectstr = " AND (" . ProjectMilestones::getWorkspaceString($pids) . $milestone_ids_condition . ")";
     $archivedstr = " AND `archived_by_id` = 0 ";
     $milestone_conditions = " `is_template` = false " . $archivedstr . $projectstr . $pendingstr;
     $externalMilestonesTemp = ProjectMilestones::findAll(array('conditions' => $milestone_conditions));
     $externalMilestones = array();
     if ($externalMilestonesTemp) {
         foreach ($externalMilestonesTemp as $em) {
             $found = false;
             if ($internalMilestones) {
                 foreach ($internalMilestones as $im) {
                     if ($im->getId() == $em->getId()) {
                         $found = true;
                         break;
                     }
                 }
             }
             if (!$found) {
                 $externalMilestones[] = $em;
             }
         }
     }
     ProjectMilestones::populateData($externalMilestones);
     //Get Users Info
     if (logged_user()->isMemberOfOwnerCompany()) {
         $users = Users::getAll();
         $allUsers = array();
     } else {
         $users = logged_user()->getAssignableUsers();
         $allUsers = Users::getAll();
     }
     //Get Companies Info
     if (logged_user()->isMemberOfOwnerCompany()) {
         $companies = Companies::getCompaniesWithUsers();
     } else {
         $companies = logged_user()->getAssignableCompanies();
     }
     if (!$isJson) {
         if (active_project() instanceof Project) {
             $task_templates = WorkspaceTemplates::getTemplatesByWorkspace(active_project()->getId());
         } else {
             $task_templates = array();
         }
         tpl_assign('project_templates', $task_templates);
         tpl_assign('all_templates', COTemplates::findAll());
         if (user_config_option('task_display_limit') > 0 && count($tasks) > user_config_option('task_display_limit')) {
             tpl_assign('displayTooManyTasks', true);
             array_pop($tasks);
         }
         tpl_assign('tasks', $tasks);
         tpl_assign('object_subtypes', ProjectCoTypes::getObjectTypesByManager('ProjectTasks'));
         tpl_assign('internalMilestones', $internalMilestones);
         tpl_assign('externalMilestones', $externalMilestones);
         tpl_assign('users', $users);
         tpl_assign('allUsers', $allUsers);
         tpl_assign('companies', $companies);
         tpl_assign('userPreferences', array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'status' => $status, 'showWorkspaces' => user_config_option('tasksShowWorkspaces', 1), 'showTime' => user_config_option('tasksShowTime', 0), 'showDates' => user_config_option('tasksShowDates', 0), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 0), 'groupBy' => user_config_option('tasksGroupBy', 'milestone'), 'orderBy' => user_config_option('tasksOrderBy', 'priority'), 'defaultNotifyValue' => user_config_option('can notify from quick add')));
         ajx_set_no_toolbar(true);
     }
 }
 /**
  * Adds the custom properties of an object into the database.
  * 
  * @param $object
  * @return unknown_type
  */
 function add_custom_properties($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $obj_custom_properties = array_var($_POST, 'object_custom_properties');
     if (is_array($obj_custom_properties)) {
         foreach ($obj_custom_properties as $id => &$val) {
             $val = remove_scripts($val);
         }
     }
     $date_format = user_config_option('date_format');
     $date_format_tip = date_format_tip($date_format);
     $required_custom_props = array();
     $object_type_id = $object instanceof TemplateTask ? ProjectTasks::instance()->getObjectTypeId() : $object->getObjectTypeId();
     $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object_type_id);
     //Sets all boolean custom properties to 0. If any boolean properties are returned, they are subsequently set to 1.
     foreach ($customProps as $cp) {
         if ($cp->getType() == 'boolean') {
             $custom_property_value = CustomPropertyValues::getCustomPropertyValue($object->getId(), $cp->getId());
             if (!$custom_property_value instanceof CustomPropertyValue) {
                 $custom_property_value = new CustomPropertyValue();
             }
             $custom_property_value->setObjectId($object->getId());
             $custom_property_value->setCustomPropertyId($cp->getId());
             $custom_property_value->setValue(0);
             $custom_property_value->save();
         }
         if ($cp->getIsRequired()) {
             $required_custom_props[] = $cp;
         }
     }
     foreach ($required_custom_props as $req_cp) {
         if (!isset($obj_custom_properties[$req_cp->getId()])) {
             throw new Exception(lang('custom property value required', $req_cp->getName()));
         }
     }
     if (is_array($obj_custom_properties)) {
         // check required custom properties
         foreach ($obj_custom_properties as $id => $value) {
             //Get the custom property
             $custom_property = null;
             foreach ($customProps as $cp) {
                 if ($cp->getId() == $id) {
                     $custom_property = $cp;
                     break;
                 }
             }
             if ($custom_property instanceof CustomProperty) {
                 // save dates in standard format "Y-m-d H:i:s", because the column type is string
                 if ($custom_property->getType() == 'date') {
                     if (is_array($value)) {
                         $newValues = array();
                         foreach ($value as $val) {
                             if (trim($val) != '' && trim($val) != $date_format_tip) {
                                 $dtv = DateTimeValueLib::dateFromFormatAndString($date_format, $val);
                                 $newValues[] = $dtv->format("Y-m-d H:i:s");
                             }
                         }
                         $value = $newValues;
                     } else {
                         if (trim($value) != '' && trim($val) != $date_format_tip) {
                             $dtv = DateTimeValueLib::dateFromFormatAndString($date_format, $value);
                             $value = $dtv->format("Y-m-d H:i:s");
                         } else {
                             $value = '';
                         }
                     }
                 }
                 foreach (array_var($_REQUEST, 'remove_custom_properties', array()) as $cpropid => $remove) {
                     if ($remove) {
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $cpropid);
                     }
                 }
                 Hook::fire('before_save_custom_property_value', array('custom_prop' => $custom_property), $value);
                 if (is_array($value)) {
                     if ($custom_property->getType() == 'address') {
                         if ($custom_property->getIsRequired()) {
                             if (array_var($value, 'street') == '' && array_var($value, 'city') == '' && array_var($value, 'state') == '' && array_var($value, 'country') == '' && array_var($value, 'zip_code') == '') {
                                 throw new Exception(lang('custom property value required', $custom_property->getName()));
                             }
                             $errors = array(lang('error form validation'));
                             Env::useHelper('form');
                             $ok = checkAddressInputMandatoryFields($value, $custom_property->getName(), $errors);
                             if (!$ok) {
                                 throw new Exception(implode("\n - ", $errors));
                             }
                         }
                         // Address custom property
                         $val = array_var($value, 'type') . '|' . array_var($value, 'street') . '|' . array_var($value, 'city') . '|' . array_var($value, 'state') . '|' . array_var($value, 'country') . '|' . array_var($value, 'zip_code');
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                         $custom_property_value = new CustomPropertyValue();
                         $custom_property_value->setObjectId($object->getId());
                         $custom_property_value->setCustomPropertyId($id);
                         $custom_property_value->setValue($val);
                         $custom_property_value->save();
                     } else {
                         //Save multiple values
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                         foreach ($value as &$val) {
                             if (is_array($val)) {
                                 // CP type == table
                                 $str_val = '';
                                 foreach ($val as $col_val) {
                                     $col_val = str_replace("|", "\\|", $col_val);
                                     $str_val .= ($str_val == '' ? '' : '|') . $col_val;
                                 }
                                 $val = $str_val;
                             }
                             if ($val != '') {
                                 $custom_property_value = new CustomPropertyValue();
                                 $custom_property_value->setObjectId($object->getId());
                                 $custom_property_value->setCustomPropertyId($id);
                                 $custom_property_value->setValue($val);
                                 $custom_property_value->save();
                             }
                         }
                     }
                 } else {
                     if ($custom_property->getType() == 'boolean') {
                         $value = isset($value);
                     }
                     $cpv = CustomPropertyValues::getCustomPropertyValue($object->getId(), $id);
                     if ($cpv instanceof CustomPropertyValue) {
                         $custom_property_value = $cpv;
                     } else {
                         $custom_property_value = new CustomPropertyValue();
                         $custom_property_value->setObjectId($object->getId());
                         $custom_property_value->setCustomPropertyId($id);
                     }
                     $custom_property_value->setValue($value);
                     $custom_property_value->save();
                 }
                 //Add to searchable objects
                 if ($object->isSearchable() && ($custom_property->getType() == 'text' || $custom_property->getType() == 'list' || $custom_property->getType() == 'numeric')) {
                     $name = str_replace("'", "\\'", $custom_property->getName());
                     if (is_array($value)) {
                         $value = implode(', ', $value);
                     }
                     $value = str_replace("'", "\\'", $value);
                     $sql = "INSERT INTO " . TABLE_PREFIX . "searchable_objects (rel_object_id, column_name, content)\r\n\t\t\t\t\t\tVALUES ('" . $object->getId() . "', '" . $name . "', '" . $value . "')\r\n\t\t\t\t\t\tON DUPLICATE KEY UPDATE content='" . $value . "'";
                     DB::execute($sql);
                 }
             }
         }
     }
     //Save the key - value pair custom properties (object_properties table)
     $object->clearObjectProperties();
     $names = array_var($_POST, 'custom_prop_names');
     $values = array_var($_POST, 'custom_prop_values');
     if (!is_array($names)) {
         return;
     }
     for ($i = 0; $i < count($names); $i++) {
         $name = trim($names[$i]);
         $value = trim($values[$i]);
         if ($name != '' && $value != '') {
             $property = new ObjectProperty();
             $property->setObject($object);
             $property->setPropertyName($name);
             $property->setPropertyValue($value);
             $property->save();
             if ($object->isSearchable()) {
                 $object->addPropertyToSearchableObject($property);
             }
         }
     }
 }
 /**
  * Moves the tasks that do not comply with the following rule: Tasks of a milestone must belong to its workspace or any of its subworkspaces.
  * 
  * @param Project $newWorkspace The new workspace
  * @return unknown_type
  */
 function move_inconsistent_tasks(Project $newWorkspace)
 {
     $oldWorkspace = $this->getProject();
     $nwCSV = explode(',', $newWorkspace->getAllSubWorkspacesCSV(true));
     $owCSV = explode(',', $oldWorkspace->getAllSubWorkspacesCSV(true));
     $inconsistentWs = array();
     foreach ($owCSV as $ow) {
         $found = false;
         foreach ($nwCSV as $nw) {
             if ($ow == $nw) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $inconsistentWs[] = $ow;
         }
     }
     if (count($inconsistentWs) > 0) {
         try {
             DB::execute('UPDATE ' . WorkspaceObjects::instance()->getTableName(true) . ' SET workspace_id = ' . $newWorkspace->getId() . ' WHERE object_manager = \'ProjectTasks\' and object_id in (SELECT id from ' . ProjectTasks::instance()->getTableName(true) . ' WHERE milestone_id = ' . $this->getId() . ') and workspace_id in (' . implode(',', $inconsistentWs) . ')');
         } catch (Exception $e) {
             throw $e;
         }
         // try
     }
 }
예제 #10
0
 /**
  * Return Day tasks this user have access on
  *
  * @access public
  * @param void
  * @return array
  */
 function getRangeTasksByUser(DateTimeValue $date_start, DateTimeValue $date_end, $assignedUser, $tags = '', $project = null, $archived = false)
 {
     $from_date = new DateTimeValue($date_start->getTimestamp());
     $from_date = $from_date->beginningOfDay();
     $to_date = new DateTimeValue($date_end->getTimestamp());
     $to_date = $to_date->endOfDay();
     $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user(), 'project_id') . ')';
     if ($project instanceof Project) {
         $pids = $project->getAllSubWorkspacesQuery(!$archived);
         $wsstring = " AND " . self::getWorkspaceString($pids);
     } else {
         $wsstring = "";
     }
     if (isset($tags) && $tags && $tags != '') {
         $tag_str = " AND exists (SELECT * from " . TABLE_PREFIX . "tags t WHERE tag=" . DB::escape($tags) . " AND  " . TABLE_PREFIX . "project_tasks.id=t.rel_object_id AND t.rel_object_manager='ProjectTasks') ";
     } else {
         $tag_str = "";
     }
     $assignedFilter = '';
     if ($assignedUser instanceof User) {
         $assignedFilter = ' AND (`assigned_to_user_id` = ' . $assignedUser->getId() . ' OR (`assigned_to_user_id` = 0 AND `assigned_to_company_id` = ' . $assignedUser->getCompanyId() . ')) ';
     }
     $rep_condition = " (`repeat_forever` = 1 OR `repeat_num` > 0 OR (`repeat_end` > 0 AND `repeat_end` >= '" . $from_date->toMySQL() . "')) ";
     if ($archived) {
         $archived_cond = " AND `archived_by_id` <> 0";
     } else {
         $archived_cond = " AND `archived_by_id` = 0";
     }
     $result = self::findAll(array('conditions' => array('`is_template` = false AND `completed_on` = ? AND ((`due_date` >= ? AND `due_date` < ?) OR (`start_date` >= ? AND `start_date` < ?) OR ' . $rep_condition . ') ' . $archived_cond . $assignedFilter . $permissions . $wsstring . $tag_str, EMPTY_DATETIME, $from_date, $to_date, $from_date, $to_date)));
     // findAll
     return $result;
 }
예제 #11
0
/**
 * Return true if $user can add an object of type $object_type_id in $member. False otherwise.
 *
 * @param Contact $user
 * @param Member $member
 * @param array $context_members
 * @param $object_type_id
 * @return boolean
 */
function can_add_to_member(Contact $user, $member, $context_members, $object_type_id, $check_dimension = true)
{
    if (TemplateTasks::instance()->getObjectTypeId() == $object_type_id) {
        $object_type_id = ProjectTasks::instance()->getObjectTypeId();
    }
    if (TemplateMilestones::instance()->getObjectTypeId() == $object_type_id) {
        $object_type_id = ProjectMilestones::instance()->getObjectTypeId();
    }
    if (!$member instanceof Member && is_array($member) && isset($member['id'])) {
        $member = Members::findById($member['id']);
    }
    if ($user->isGuest() || !$member || !$member->canContainObject($object_type_id)) {
        return false;
    }
    try {
        $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
        if ($check_dimension) {
            $dimension = $member->getDimension();
        }
        //dimension does not define permissions - user can freely add in all members
        if ($check_dimension && !$dimension->getDefinesPermissions()) {
            return true;
        }
        //dimension defines permissions and user has maximum level of permissions so can freely in all members
        if ($check_dimension && $dimension->hasAllowAllForContact($contact_pg_ids)) {
            return true;
        }
        //check
        if (ContactMemberPermissions::contactCanReadObjectTypeinMember($contact_pg_ids, $member->getId(), $object_type_id, true, false, $user)) {
            $max_role_ot_perm = MaxRoleObjectTypePermissions::instance()->findOne(array('conditions' => "object_type_id='{$object_type_id}' AND role_id = '" . $user->getUserType() . "'"));
            // if user max permission cannot write this object type then return false
            if ($max_role_ot_perm && $max_role_ot_perm->getCanWrite()) {
                return true;
            } else {
                return false;
            }
        }
        //check for context permissions that allow user to add in this member
        if ($context_members) {
            $member_ids = array();
            foreach ($context_members as $member_obj) {
                $member_ids[] = $member_obj->getId();
            }
            $allowed_members = ContactMemberPermissions::getActiveContextPermissions($user, $object_type_id, $context_members, $member_ids, true);
            if (in_array($member, $allowed_members)) {
                return true;
            }
        }
    } catch (Exception $e) {
        tpl_assign('error', $e);
        return false;
    }
    return false;
}
예제 #12
0
<?php

$genid = gen_id();
$limit = 20;
$total = $limit;
$page = 10;
$task_assignment_conditions = "";
if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) {
    $task_assignment_conditions = " AND assigned_to_contact_id = " . logged_user()->getId();
}
$tasks_result = ProjectTasks::instance()->listing(array("order" => "completed_on", "order_dir" => "DESC", "extra_conditions" => " AND is_template = 0 AND completed_by_id > 0 {$task_assignment_conditions}", "limit" => $limit + 1));
$tasks = $tasks_result->objects;
$active_members = array();
$context = active_context();
if (is_array($context)) {
    foreach ($context as $selection) {
        if ($selection instanceof Member) {
            $active_members[] = $selection;
        }
    }
}
if (count($active_members) > 0) {
    $mnames = array();
    $allowed_contact_ids = array();
    foreach ($active_members as $member) {
        $mnames[] = clean($member->getName());
    }
    $widget_title = lang('completed tasks') . ' ' . lang('in') . ' ' . implode(", ", $mnames);
}
if ($tasks_result->total > 0) {
    include 'template.php';
예제 #13
0
	function canAdd(Contact $user, $context, &$notAllowedMember = ''){
		return can_add($user, $context, ProjectTasks::instance()->getObjectTypeId(), $notAllowedMember);
	}
예제 #14
0
function allowed_users_to_assign_all($context = null)
{
    if ($context == null) {
        $context = active_context();
    }
    // only companies with users
    $companies = Contacts::findAll(array("conditions" => "e.is_company = 1 AND EXISTS (SELECT object_id FROM " . TABLE_PREFIX . "contacts WHERE is_company = 0 AND user_type > 0 AND company_id = o.id  )", "join" => array("table" => Contacts::instance()->getTableName(), "jt_field" => "object_id", "j_sub_q" => "SELECT xx.object_id FROM " . Contacts::instance()->getTableName(true) . " xx WHERE xx.is_company=0 AND xx.company_id = e.object_id LIMIT 1"), "order" => "name"));
    $comp_ids = array("0");
    $comp_array = array("0" => array('id' => "0", 'name' => lang('without company'), 'users' => array()));
    foreach ($companies as $company) {
        $comp_ids[] = $company->getId();
        $comp_array[$company->getId()] = array('id' => $company->getId(), 'name' => $company->getObjectName(), 'users' => array());
    }
    if (!can_manage_tasks(logged_user()) && can_task_assignee(logged_user())) {
        $contacts = array(logged_user());
    } else {
        if (can_manage_tasks(logged_user())) {
            $contacts = allowed_users_in_context(ProjectTasks::instance()->getObjectTypeId(), $context, ACCESS_LEVEL_READ, "AND `is_company`=0 AND `company_id` IN (" . implode(",", $comp_ids) . ")");
        } else {
            $contacts = array();
        }
    }
    foreach ($contacts as $contact) {
        /* @var $contact Contact */
        if (TabPanelPermissions::instance()->count(array("conditions" => "permission_group_id = " . $contact->getPermissionGroupId() . " AND tab_panel_id = 'tasks-panel' "))) {
            $comp_array[]['users'][] = array('id' => $contact->getId(), 'name' => $contact->getObjectName(), 'isCurrent' => $contact->getId() == logged_user()->getId());
        }
    }
    return array_values($comp_array);
}
예제 #15
0
 private function save_object($request)
 {
     $response = false;
     if (!empty($request['args'])) {
         $service = $request['srv'];
         switch ($service) {
             case "task":
                 if ($request['args']['id']) {
                     $object = ProjectTasks::instance()->findByid($request['args']['id']);
                 } else {
                     $object = new ProjectTask();
                 }
                 if ($object instanceof ProjectTask) {
                     if (!empty($request['args']['title'])) {
                         $object->setObjectName($request['args']['title']);
                     }
                     if (!empty($request['args']['description'])) {
                         $object->setText($request['args']['description']);
                     }
                     if (!empty($request['args']['due_date'])) {
                         if ($request['args']['due_date'] != '' && $request['args']['due_date'] != date_format_tip('dd/mm/yyyy')) {
                             $date_format = 'dd/mm/yyyy';
                             $object->setDueDate(DateTimeValueLib::dateFromFormatAndString($date_format, $value));
                         }
                     }
                     if (!empty($request['args']['completed'])) {
                         $object->setPercentCompleted($request['args']['completed']);
                     }
                     if (!empty($request['args']['assign_to'])) {
                         $object->setAssignedToContactId($request['args']['assign_to']);
                     }
                     if (!empty($request['args']['priority'])) {
                         $object->setPriority($request['args']['priority']);
                     }
                 }
                 break;
             case 'note':
                 if ($request['args']['id']) {
                     $object = ProjectMessages::instance()->findByid($request['args']['id']);
                 } else {
                     $object = new ProjectMessage();
                 }
                 if ($object instanceof ProjectMessage) {
                     if (!empty($request['args']['title'])) {
                         $object->setObjectName($request['args']['title']);
                     }
                     if (!empty($request['args']['title'])) {
                         $object->setText($request['args']['text']);
                     }
                 }
                 break;
         }
         // END SWITCH
         if ($object) {
             try {
                 $context = array();
                 $members = array();
                 if (!empty($request['args']['members'])) {
                     $members = $request['args']['members'];
                     $context = get_context_from_array($members);
                 }
                 //Check permissions:
                 if ($request['args']['id'] && $object->canEdit(logged_user()) || !$request['args']['id'] && $object->canAdd(logged_user(), $context)) {
                     DB::beginWork();
                     $object->save();
                     $object_controller = new ObjectController();
                     if (!$request['args']['id']) {
                         $object_controller->add_to_members($object, $members);
                     }
                     DB::commit();
                     $response = true;
                 }
             } catch (Exception $e) {
                 DB::rollback();
                 return false;
             }
         }
     }
     return $this->response('json', $response);
 }
    $form_url = $task->getEditListUrl();
}
if (!isset($additional_onsubmit)) {
    $additional_onsubmit = "";
}
// on submit functions
if (array_var($_REQUEST, 'modal')) {
    $on_submit = "og.setDescription(); og.submit_modal_form('" . $genid . "submit-edit-form', og.redrawTemplateObjectsLists); return false;";
} else {
    $on_submit = "return App.modules.addTaskForm.checkSubmitAddTask('" . $genid . "','" . $task->manager()->getObjectTypeId() . "') && og.setDescription()" . ($additional_onsubmit != "" ? " && {$additional_onsubmit}" : "") . (array_var($task_data, 'multi_assignment') && Plugins::instance()->isActivePlugin('crpm') ? "&& typeof('og.TaskMultiAssignment')=='function' ? og.TaskMultiAssignment() : true" : "") . ";";
}
$co_type = array_var($task_data, 'object_subtype');
if (config_option('use tasks dependencies')) {
    require_javascript('og/tasks/task_dependencies.js');
}
$has_custom_properties = CustomProperties::countAllCustomPropertiesByObjectType(ProjectTasks::instance()->getObjectTypeId()) > 0;
$categories = array();
Hook::fire('object_edit_categories', $task, $categories);
$loc = user_config_option('localization');
if (strlen($loc) > 2) {
    $loc = substr($loc, 0, 2);
}
$projectTask = new ProjectTask();
?>
<script>
og.genid = '<?php 
echo $genid;
?>
';
og.config.multi_assignment = '<?php 
echo config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm') ? '1' : '0';
예제 #17
0
파일: index.php 프로젝트: rorteg/fengoffice
 }
 //user_config_option('show_two_weeks_calendar',null,logged_user()->getId())? $my_weeks = 2 : $my_weeks = 1 ;
 $my_weeks = 2;
 $endday = $startday + 7 * $my_weeks;
 $today = DateTimeValueLib::now()->add('h', logged_user()->getTimezone());
 $currentday = $today->getDay();
 $currentmonth = $today->getMonth();
 $currentyear = $today->getYear();
 $user_comp_filter = user_config_option('pending tasks widget assigned to filter');
 $exploded = explode(":", $user_comp_filter);
 $user_filter_id = array_var($exploded, 1);
 $user_filter = $user_filter_id > 0 ? Users::findById($user_filter_id) : null;
 $date_start = new DateTimeValue(mktime(0, 0, 0, $currentmonth, $startday, $currentyear));
 $date_end = new DateTimeValue(mktime(0, 0, 0, $currentmonth, $endday, $currentyear));
 //$milestones = ProjectMilestones::getRangeMilestonesByUser($date_start, $date_end, $user_filter, $tags, active_project());
 $tmp_tasks = ProjectTasks::instance()->getRangeTasksByUser($date_start, $date_end, $user_filter);
 $birthdays = Contacts::instance()->getRangeContactsByBirthday($date_start, $date_end);
 $milestones = ProjectMilestones::getRangeMilestones($date_start, $date_end);
 $tasks = array();
 if ($tmp_tasks) {
     foreach ($tmp_tasks as $task) {
         $tasks = array_merge($tasks, replicateRepetitiveTaskForCalendar($task, $date_start, $date_end));
     }
 }
 $use_24_hours = user_config_option('time_format_use_24');
 if ($use_24_hours) {
     $timeformat = 'G:i';
 } else {
     $timeformat = 'g:i A';
 }
 // load the day we are currently viewing in the calendar
 /**
  * Returns array of queries that will return Dashboard Objects
  *
  * @param string $proj_ids
  * @param string $tag
  * @param boolean $count if false the query will return objects, if true it will return object count
  */
 static function getDashboardObjectQueries($project = null, $tag = null, $count = false, $trashed = false, $linkedObject = null, $order = 'updatedOn', $filterName = '', $archived = false, $filterManager = '')
 {
     if ($trashed && $trashed !== 'all') {
         $order = 'trashedOn';
     } else {
         if ($archived) {
             $order = 'archivedOn';
         }
     }
     switch ($order) {
         case 'dateCreated':
             $order_crit_companies = '`created_on`';
             $order_crit_contacts = '`created_on`';
             $order_crit_file_revisions = '`created_on`';
             $order_crit_calendar = '`created_on`';
             $order_crit_tasks = '`created_on`';
             $order_crit_milestones = '`created_on`';
             $order_crit_webpages = '`created_on`';
             $order_crit_files = '`created_on`';
             $order_crit_emails = '`received_date`';
             $order_crit_comments = '`created_on`';
             $order_crit_messages = '`created_on`';
             $order_crit_workspaces = '`created_on`';
             break;
         case 'trashedOn':
             $order_crit_companies = '`trashed_on`';
             $order_crit_contacts = '`trashed_on`';
             $order_crit_file_revisions = '`trashed_on`';
             $order_crit_calendar = '`trashed_on`';
             $order_crit_tasks = '`trashed_on`';
             $order_crit_milestones = '`trashed_on`';
             $order_crit_webpages = '`trashed_on`';
             $order_crit_files = '`trashed_on`';
             $order_crit_emails = '`trashed_on`';
             $order_crit_comments = '`trashed_on`';
             $order_crit_messages = '`trashed_on`';
             $order_crit_workspaces = '`updated_on`';
             break;
         case 'archivedOn':
             $order_crit_companies = '`archived_on`';
             $order_crit_contacts = '`archived_on`';
             $order_crit_file_revisions = '`updated_on`';
             $order_crit_calendar = '`archived_on`';
             $order_crit_tasks = '`archived_on`';
             $order_crit_milestones = '`archived_on`';
             $order_crit_webpages = '`archived_on`';
             $order_crit_files = '`archived_on`';
             $order_crit_emails = '`archived_on`';
             $order_crit_comments = '`updated_on`';
             $order_crit_messages = '`archived_on`';
             $order_crit_workspaces = '`completed_on`';
             break;
         case 'name':
             $order_crit_companies = '`name`';
             $order_crit_contacts = "TRIM(CONCAT(' ', `lastname`, `firstname`, `middlename`))";
             $order_crit_file_revisions = "'zzzzzzzzzzzzzz'";
             //Revisar
             $order_crit_calendar = '`subject`';
             $order_crit_tasks = '`title`';
             $order_crit_milestones = '`name`';
             $order_crit_webpages = '`title`';
             $order_crit_files = '`filename`';
             $order_crit_emails = '`subject`';
             $order_crit_comments = '`text`';
             $order_crit_messages = '`title`';
             $order_crit_workspaces = '`name`';
             break;
         default:
             $order_crit_companies = '`updated_on`';
             $order_crit_contacts = '`updated_on`';
             $order_crit_file_revisions = '`updated_on`';
             $order_crit_calendar = '`updated_on`';
             $order_crit_tasks = '`updated_on`';
             $order_crit_milestones = '`updated_on`';
             $order_crit_webpages = '`updated_on`';
             $order_crit_files = '`updated_on`';
             $order_crit_emails = '`received_date`';
             $order_crit_comments = '`updated_on`';
             $order_crit_messages = '`updated_on`';
             $order_crit_workspaces = '`updated_on`';
             break;
     }
     if ($project instanceof Project) {
         $proj_ids = $project->getAllSubWorkspacesQuery(true);
         $proj_cond_companies = Companies::getWorkspaceString($proj_ids);
         $proj_cond_messages = ProjectMessages::getWorkspaceString($proj_ids);
         $proj_cond_documents = ProjectFiles::getWorkspaceString($proj_ids);
         $proj_cond_emails = MailContents::getWorkspaceString($proj_ids);
         $proj_cond_events = ProjectEvents::getWorkspaceString($proj_ids);
         $proj_cond_tasks = ProjectTasks::getWorkspaceString($proj_ids);
         $proj_cond_charts = ProjectCharts::getWorkspaceString($proj_ids);
         $proj_cond_milestones = ProjectMilestones::getWorkspaceString($proj_ids);
         $proj_cond_weblinks = ProjectWebpages::getWorkspaceString($proj_ids);
         $proj_cond_contacts = Contacts::getWorkspaceString($proj_ids);
     } else {
         $proj_cond_companies = "true";
         $proj_cond_messages = "true";
         $proj_cond_documents = "true";
         $proj_cond_emails = "true";
         $proj_cond_events = "true";
         $proj_cond_tasks = "true";
         $proj_cond_charts = "true";
         $proj_cond_milestones = "true";
         $proj_cond_weblinks = "true";
         $proj_cond_contacts = "true";
     }
     if ($trashed) {
         if ($trashed === 'all') {
             $trashed_cond = '`trashed_on` >= ' . DB::escape(EMPTY_DATETIME);
         } else {
             $trashed_cond = '`trashed_on` > ' . DB::escape(EMPTY_DATETIME);
         }
         $archived_cond = '1 = 1';
         // Show all objects in trash
         $comments_arch_cond = "1 = 1";
     } else {
         $trashed_cond = '`trashed_on` = ' . DB::escape(EMPTY_DATETIME);
         if ($archived) {
             $archived_cond = "`archived_by_id` > 0";
             $comments_arch_cond = "1 = 0";
             // Don't show comments in archived objects listings
         } else {
             $archived_cond = "`archived_by_id` = 0";
             $comments_arch_cond = "1 = 1";
         }
     }
     if (isset($tag) && $tag && $tag != '') {
         $tag_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag`= " . DB::escape($tag) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = `object_manager_value`) ";
     } else {
         $tag_str = ' ';
     }
     if ($linkedObject instanceof ProjectDataObject) {
         $link_id = $linkedObject->getId();
         $link_mgr = get_class($linkedObject->manager());
         $link_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "linked_objects` `t` WHERE\n\t\t\t(`t`.`object_id`=" . DB::escape($link_id) . " AND `t`.object_manager = " . DB::escape($link_mgr) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = `object_manager_value`) OR\n\t\t\t(`t`.`rel_object_id`=" . DB::escape($link_id) . " AND `t`.rel_object_manager = " . DB::escape($link_mgr) . " AND `co`.`id` = `t`.`object_id` AND `t`.`object_manager` = `object_manager_value`)) ";
     } else {
         $link_str = ' ';
     }
     $tag_str .= $link_str;
     $res = array();
     /** If the name of the query ends with Comments it is assumed to be a list of Comments **/
     $cfn = '';
     if ($filterName != '') {
         $cfn = " AND text LIKE '%" . $filterName . "%'";
     }
     // Notes
     if (module_enabled('notes')) {
         $fn = '';
         if ($filterName != '') {
             $fn = " AND title LIKE '%" . $filterName . "%'";
         }
         $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectMessages::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "ProjectMessages") {
             $res['ProjectMessages'] = "SELECT  'ProjectMessages' AS `object_manager_value`, `id` AS `oid`, {$order_crit_messages} AS `order_value` FROM `" . TABLE_PREFIX . "project_messages` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_messages . str_replace('= `object_manager_value`', "= 'ProjectMessages'", $tag_str) . $permissions . $fn;
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['ProjectMessagesComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectMessages' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_messages` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_messages . str_replace('= `object_manager_value`', "= 'ProjectMessages'", $tag_str) . $permissions . $cfn . ")";
         }
     }
     // Events
     if (module_enabled("calendar")) {
         $fn = '';
         if ($filterName != '') {
             $fn = " AND subject LIKE '%" . $filterName . "%'";
         }
         $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectEvents::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "ProjectEvents") {
             $res['ProjectEvents'] = "SELECT  'ProjectEvents' AS `object_manager_value`, `id` AS `oid`, {$order_crit_calendar} AS `order_value` FROM `" . TABLE_PREFIX . "project_events` `co` WHERE  " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_events . str_replace('= `object_manager_value`', "= 'ProjectEvents'", $tag_str) . $permissions . $fn;
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['ProjectEventsComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectEvents' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_events` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_events . str_replace('= `object_manager_value`', "= 'ProjectEvents'", $tag_str) . $permissions . $cfn . ")";
         }
     }
     // Documents
     if (module_enabled("documents")) {
         $fn = '';
         if ($filterName != '') {
             $fn = " AND filename LIKE '%" . $filterName . "%'";
         }
         $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectFiles::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         $typestring = array_var($_GET, "typestring");
         if ($typestring) {
             $typecond = " AND  ((SELECT count(*) FROM `" . TABLE_PREFIX . "project_file_revisions` `pfr` WHERE `" . "pfr`.`type_string` LIKE " . DB::escape($typestring) . " AND `" . "co`.`id` = `pfr`.`file_id`) > 0)";
         } else {
             $typecond = "";
         }
         if ($filterManager == '' || $filterManager == "ProjectFiles") {
             $res['ProjectFiles'] = "SELECT  'ProjectFiles' AS `object_manager_value`, `id` as `oid`, {$order_crit_files} AS `order_value` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $typecond . $fn;
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['ProjectFilesComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectFiles' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $cfn . ")";
         }
         if ($trashed) {
             $file_rev_docs = "SELECT `id` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE `trashed_by_id` = 0 AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $typecond;
             $res['FileRevisions'] = "SELECT 'ProjectFileRevisions' AS `object_manager_value`, `id` AS `oid`, {$order_crit_file_revisions} AS `order_value` FROM `" . TABLE_PREFIX . "project_file_revisions` `co` WHERE {$trashed_cond} AND `file_id` IN (" . $file_rev_docs . ")";
         }
     }
     // Tasks and Milestones
     if (module_enabled("tasks")) {
         $fn = '';
         if ($filterName != '') {
             $fn = " AND title LIKE '%" . $filterName . "%'";
         }
         $completed = $trashed || $archived ? '' : 'AND `completed_on` = ' . DB::escape(EMPTY_DATETIME);
         $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "ProjectTasks") {
             $res['ProjectTasks'] = "SELECT  'ProjectTasks' AS `object_manager_value`, `id` AS `oid`, {$order_crit_tasks} AS `order_value` FROM `" . TABLE_PREFIX . "project_tasks` `co` WHERE `is_template` = false {$completed} AND " . $trashed_cond . " AND {$archived_cond} AND `is_template` = false AND " . $proj_cond_tasks . str_replace('= `object_manager_value`', "= 'ProjectTasks'", $tag_str) . $permissions . $fn;
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['ProjectTasksComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectTasks' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_tasks` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND `is_template` = false AND " . $proj_cond_tasks . str_replace('= `object_manager_value`', "= 'ProjectTasks'", $tag_str) . $permissions . $cfn . ")";
         }
         $fn = '';
         if ($filterName != '') {
             $fn = " AND name LIKE '%" . $filterName . "%'";
         }
         $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectMilestones::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "ProjectMilestones") {
             $res['ProjectMilestones'] = "SELECT  'ProjectMilestones' AS `object_manager_value`, `id` AS `oid`, {$order_crit_milestones} AS `order_value` FROM `" . TABLE_PREFIX . "project_milestones` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND `is_template` = false AND " . $proj_cond_milestones . str_replace('= `object_manager_value`', "= 'ProjectMilestones'", $tag_str) . $permissions . $fn;
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['ProjectMilestonesComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectMilestones' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_milestones` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND `is_template` = false AND " . $proj_cond_milestones . str_replace('= `object_manager_value`', "= 'ProjectMilestones'", $tag_str) . $permissions . $cfn . ")";
         }
     }
     // Weblinks
     if (module_enabled("weblinks")) {
         $fn = '';
         if ($filterName != '') {
             $fn = " AND title LIKE '%" . $filterName . "%'";
         }
         $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectWebpages::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "ProjectWebpages") {
             $res['ProjectWebPages'] = "SELECT  'ProjectWebPages' AS `object_manager_value`, `id` AS `oid`, {$order_crit_webpages} AS `order_value` FROM `" . TABLE_PREFIX . "project_webpages` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_weblinks . str_replace('= `object_manager_value`', "= 'ProjectWebpages'", $tag_str) . $permissions . $fn;
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['ProjectWebPagesComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectWebpages' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_webpages` `co` WHERE " . $trashed_cond . " AND {$comments_arch_cond} AND " . $proj_cond_weblinks . str_replace('= `object_manager_value`', "= 'ProjectWebpages'", $tag_str) . $permissions . $cfn . ")";
         }
     }
     // Email
     if (module_enabled("email")) {
         $fn = '';
         if ($filterName != '') {
             $fn = " AND subject LIKE '%" . $filterName . "%'";
         }
         $permissions = ' AND ( ' . permissions_sql_for_listings(MailContents::instance(), ACCESS_LEVEL_READ, logged_user(), $project instanceof Project ? $project->getId() : 0, '`co`') . ')';
         if ($filterManager == '' || $filterManager == "MailContents") {
             $res['MailContents'] = "SELECT  'MailContents' AS `object_manager_value`, `id` AS `oid`, {$order_crit_emails} AS `order_value` FROM `" . TABLE_PREFIX . "mail_contents` `co` WHERE (" . $trashed_cond . " AND {$archived_cond} AND `is_deleted` = 0 AND " . $proj_cond_emails . str_replace('= `object_manager_value`', "= 'MailContents'", $tag_str) . $permissions . ") {$fn}";
         }
         if ($filterManager == '' || $filterManager == "Comments") {
             $res['MailContentsComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "mail_contents` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_emails . str_replace('= `object_manager_value`', "= 'MailContents'", $tag_str) . $permissions . $cfn . ")";
         }
     }
     // Conacts and Companies
     if (module_enabled("contacts")) {
         $fn = '';
         $fn2 = '';
         if ($filterName != '') {
             $fn = " AND firstname LIKE '%" . $filterName . "%'";
             $fn2 = " AND name LIKE '%" . $filterName . "%'";
         }
         // companies
         $permissions = ' AND ( ' . permissions_sql_for_listings(Companies::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "Companies") {
             $res['Companies'] = "SELECT  'Companies' AS `object_manager_value`, `id` as `oid`, {$order_crit_companies} AS `order_value` FROM `" . TABLE_PREFIX . "companies` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_companies . str_replace('= `object_manager_value`', "= 'Companies'", $tag_str) . $permissions . $fn2;
         }
         $res['CompaniesComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'Companies' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "companies` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'Companies'", $tag_str) . $permissions . $cfn . ")";
         // contacts
         $permissions = ' AND ( ' . permissions_sql_for_listings(Contacts::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')';
         if ($filterManager == '' || $filterManager == "Contacts") {
             $res['Contacts'] = "SELECT 'Contacts' AS `object_manager_value`, `id` AS `oid`, {$order_crit_contacts} AS `order_value` FROM `" . TABLE_PREFIX . "contacts` `co` WHERE {$trashed_cond} AND {$archived_cond} AND {$proj_cond_contacts} " . str_replace('= `object_manager_value`', "= 'Contacts'", $tag_str) . $permissions . $fn;
         }
         $res['ContactsComments'] = "SELECT  'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'Contacts' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "contacts` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'Contacts'", $tag_str) . $permissions . $cfn . ")";
     }
     // Workspaces (only for archived objects view)
     if ($archived) {
         if ($filterManager == '' || $filterManager == "Projects") {
             $res['Projects'] = "SELECT  'Projects' AS `object_manager_value`, `id` AS `oid`, {$order_crit_workspaces} AS `order_value` FROM `" . TABLE_PREFIX . "projects` `co` WHERE `completed_on` <> " . DB::escape(EMPTY_DATETIME) . " AND `id` IN (" . logged_user()->getWorkspacesQuery() . ")";
         }
     }
     if ($count) {
         foreach ($res as $p => $q) {
             $res[$p] = "SELECT count(*) AS `quantity`, '{$p}' AS `objectName` FROM ( {$q} ) `table_alias`";
         }
     }
     return $res;
 }
예제 #19
0
 /**
  * Save subtasks added in task form, at 'subtasks' tab
  * @param $parent_task: ProjectTask - The parent task to set in the subtasks to save
  * @param $subtasks_data: array - An array with all the subtasks data
  * @param $member_ids: array with the member ids to classify the subtasks
  * @return array with the application logs to generate
  */
 private function saveSubtasks($parent_task, $subtasks_data, $member_ids)
 {
     $to_log = array('add' => array(), 'edit' => array(), 'trash' => array(), 'assigned' => array());
     $subs = $parent_task->getSubscriberIds();
     $subs_array = array();
     foreach ($subs as $sid) {
         $subs_array['user_' . $sid] = 1;
     }
     if ($parent_task instanceof ProjectTask && is_array($subtasks_data)) {
         foreach ($subtasks_data as $stdata) {
             $st = null;
             if ($stdata['id'] > 0) {
                 $st = ProjectTasks::instance()->findById($stdata['id']);
                 // subtask has been deleted, delete object and continue with next subtask
                 if ($stdata['deleted'] == 1 && $st instanceof ProjectTask) {
                     /*$st->trash(false);
                     		$st->save();*/
                     DB::execute("UPDATE " . TABLE_PREFIX . "objects SET trashed_by_id=" . logged_user()->getId() . ", trashed_on=NOW() WHERE id=" . $st->getId());
                     $to_log['trash'][] = $st;
                     continue;
                 }
             }
             $new_subtask = false;
             // new subtask
             if (!$st instanceof ProjectTask) {
                 $st = new ProjectTask();
                 $new_subtask = true;
             }
             if (trim($stdata['name'] == '')) {
                 continue;
             }
             $changed = false;
             if ($st->getObjectName() != $stdata['name'] || $st->getAssignedToContactId() != $stdata['assigned_to']) {
                 $changed = true;
             }
             if ($new_subtask || $changed) {
                 if ($stdata['assigned_to'] > 0 && $stdata['assigned_to'] != $st->getAssignedToContactId()) {
                     $to_log['assigned'][] = $st;
                 }
                 $st->setParentId($parent_task->getId());
                 $st->setObjectName($stdata['name']);
                 $st->setAssignedToContactId($stdata['assigned_to']);
                 $st->setPriority(array_var($stdata, 'priority', ProjectTasks::PRIORITY_NORMAL));
                 $st->setTypeContent(config_option("wysiwyg_tasks") ? 'html' : 'text');
                 $st->save();
                 $object_controller = new ObjectController();
                 $object_controller->add_to_members($st, $member_ids);
                 $st_subs_array = $subs_array;
                 if ($stdata['assigned_to'] > 0 && !in_array($stdata['assigned_to'], $subs)) {
                     $st_subs_array['user_' . $stdata['assigned_to']] = 1;
                 }
                 $object_controller->add_subscribers($st, $st_subs_array);
                 if ($new_subtask) {
                     $to_log['add'][] = $st;
                 } else {
                     $to_log['edit'][] = $st;
                 }
             }
         }
     }
     return $to_log;
 }
예제 #20
0
 $today = DateTimeValueLib::now()->add('h', logged_user()->getTimezone());
 $currentday = $today->getDay();
 $currentmonth = $today->getMonth();
 $currentyear = $today->getYear();
 $user_filter_myself = true;
 $user_filter = null;
 $w_option_user_filter = ContactWidgetOptions::instance()->getContactOption('calendar', logged_user()->getId(), 'filter_by_myself');
 if (array_var($w_option_user_filter, 'option')) {
     $user_filter_myself = array_var($w_option_user_filter, 'value');
 }
 if ($user_filter_myself) {
     $user_filter = logged_user();
 }
 $date_start = new DateTimeValue(mktime(0, 0, 0, $currentmonth, $startday, $currentyear));
 $date_end = new DateTimeValue(mktime(0, 0, 0, $currentmonth, $endday, $currentyear));
 $tmp_tasks = ProjectTasks::instance()->getRangeTasksByUser($date_start, $date_end, $user_filter, null, false, true);
 $birthdays = Contacts::instance()->getRangeContactsByBirthday($date_start, $date_end);
 $milestones = ProjectMilestones::getRangeMilestones($date_start, $date_end);
 $tasks = array();
 if ($tmp_tasks) {
     foreach ($tmp_tasks as $task) {
         $tasks = array_merge($tasks, replicateRepetitiveTaskForCalendarRawTask($task, $date_start, $date_end));
     }
 }
 $use_24_hours = user_config_option('time_format_use_24');
 if ($use_24_hours) {
     $timeformat = 'G:i';
 } else {
     $timeformat = 'g:i A';
 }
 // load the day we are currently viewing in the calendar
예제 #21
0
function allowed_users_to_assign_all_mobile($member_id = null) {
	if ($member_id == null) {
		$context = active_context();
	}else{
		$member = Members::findById($member_id);
		if ($member instanceof Member){
			$context[] = $member;
		}
	}
	
	// only companies with users
	$companies = Contacts::findAll(array("conditions" => "is_company = 1 AND object_id IN (SELECT company_id FROM ".TABLE_PREFIX."contacts WHERE user_type>0 AND disabled=0)", "order" => "first_name ASC"));

	$comp_ids = array("0");
	$comp_array = array("0" => array('id' => "0", 'name' => lang('without company'), 'users' => array() ));
	
	foreach ($companies as $company) {
		$comp_ids[] = $company->getId();
		$comp_array[$company->getId()] = array('id' => $company->getId(), 'name' => $company->getObjectName(), 'users' => array() );
	}
	
	if(!can_manage_tasks(logged_user()) && can_task_assignee(logged_user())) {
		$contacts = array(logged_user());
	} else if (can_manage_tasks(logged_user())) {
		$contacts = allowed_users_in_context(ProjectTasks::instance()->getObjectTypeId(), $context, ACCESS_LEVEL_READ, "AND `is_company`=0 AND `company_id` IN (".implode(",", $comp_ids).")");
	} else {
		$contacts = array();
	}
	
	foreach ($contacts as $contact) { /* @var $contact Contact */
		if ( TabPanelPermissions::instance()->count( array( "conditions" => "permission_group_id = ".$contact->getPermissionGroupId(). " AND tab_panel_id = 'tasks-panel' " ))){
			$comp_array[$contact->getCompanyId()]['users'][] = array('id' => $contact->getId(), 'name' => $contact->getObjectName(), 'isCurrent' => $contact->getId() == logged_user()->getId());
		}
	}
	foreach ($comp_array as $company_id => &$comp_data) {
		if (count($comp_data['users']) == 0) {
			unset($comp_array[$company_id]);
		}
	}
	return array_values($comp_array);
}
<div class="custom-properties"><?php 
require_javascript("og/CustomProperties.js");
$object_type_id = $_custom_properties_object instanceof TemplateTask ? ProjectTasks::instance()->getObjectTypeId() : $_custom_properties_object->getObjectTypeId();
$cps = CustomProperties::getAllCustomPropertiesByObjectType($object_type_id, $co_type);
$ti = 0;
if (!isset($genid)) {
    $genid = gen_id();
}
if (!isset($startTi)) {
    $startTi = 10000;
}
if (count($cps) > 0) {
    $print_table_functions = false;
    foreach ($cps as $customProp) {
        if (!isset($required) || $required && ($customProp->getIsRequired() || $customProp->getVisibleByDefault()) || !$required && !($customProp->getIsRequired() || $customProp->getVisibleByDefault())) {
            $ti++;
            $cpv = CustomPropertyValues::getCustomPropertyValue($_custom_properties_object->getId(), $customProp->getId());
            $default_value = $customProp->getDefaultValue();
            if ($cpv instanceof CustomPropertyValue) {
                $default_value = $cpv->getValue();
            }
            $name = 'object_custom_properties[' . $customProp->getId() . ']';
            echo '<div style="margin-top:12px">';
            if ($customProp->getType() == 'boolean') {
                echo checkbox_field($name, $default_value, array('tabindex' => $startTi + $ti, 'style' => 'margin-right:4px', 'id' => $genid . 'cp' . $customProp->getId()));
            }
            echo label_tag(clean($customProp->getName()), $genid . 'cp' . $customProp->getId(), $customProp->getIsRequired(), array('style' => 'display:inline'), $customProp->getType() == 'boolean' ? '' : ':');
            echo '</div>';
            switch ($customProp->getType()) {
                case 'text':
                case 'numeric':
예제 #23
0
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ProjectTasks
  */
 function manager()
 {
     if (!$this->manager instanceof ProjectTasks) {
         $this->manager = ProjectTasks::instance();
     }
     return $this->manager;
 }
예제 #24
0
 /**
  * Trash this object and reset all relationship. This function will not trash any of related objects
  *
  * @access public
  * @param void
  * @return boolean
  */
 function trash($trashDate = null)
 {
     try {
         DB::execute("UPDATE " . ProjectTasks::instance()->getTableName(true) . " SET `milestone_id` = '0' WHERE `milestone_id` = " . DB::escape($this->getId()));
         return parent::trash($trashDate);
     } catch (Exception $e) {
         throw $e;
     }
     // try
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ProjectTasks')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ProjectTasks::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ProjectTasks::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
예제 #26
0
 function getBillingTotalByUsers(User $user, $user_id = null)
 {
     //$project_ids = $this->getAllSubWorkspacesQuery($user);
     $user_cond = '';
     if (isset($user_id)) {
         $user_cond = ' AND timeslots.user_id = ' . $user_id;
     }
     $rows = DB::executeAll('SELECT SUM(timeslots.fixed_billing) as total_billing, timeslots.user_id as user from ' . Timeslots::instance()->getTableName() . ' as timeslots, ' . ProjectTasks::instance()->getTableName() . ' as tasks WHERE ((tasks.' . trim(ProjectTasks::getWorkspaceString($this->getId())) . ' AND timeslots.object_id = tasks.id AND timeslots.object_manager = \'ProjectTasks\')' . ' OR (timeslots.object_manager = \'Project\' AND timeslots.object_id = ' . $this->getId() . '))' . $user_cond . ' GROUP BY user');
     if (!is_array($rows) || !count($rows)) {
         return null;
     } else {
         for ($i = 0; $i < count($rows); $i++) {
             if ($rows[$i]['total_billing'] == 0) {
                 unset($rows[$i]);
             }
         }
         return $rows;
     }
 }
예제 #27
0
 /**
  * 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() . '">&nbsp;</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;
 }
예제 #28
0
foreach ($columns as $col) {
    $sorted = false;
    $asc = false;
    if ($col != '' && $col != lang('located_under') && array_var($db_columns, $col) == $order_by) {
        $sorted = true;
        $asc = $order_by_asc;
    }
    ?>
	<td style="padding-right:10px;border-bottom:1px solid #666" class="bold">
<?php 
    if ($to_print) {
        echo clean($col);
    } else {
        if ($col != '') {
            $allow_link = true;
            if ($model == 'Timeslots' && in_array(array_var($db_columns, $col), ProjectTasks::instance()->getColumns())) {
                $allow_link = false;
            }
            $echo_link = $allow_link && !(is_numeric(array_var($db_columns, $col)) || str_starts_with(array_var($db_columns, $col), "dim_") || array_var($db_columns, $col) == 'time' || array_var($db_columns, $col) == 'billing');
            ?>
		<a href="<?php 
            echo $echo_link ? get_url('reporting', 'view_custom_report', array('id' => $id, 'replace' => true, 'order_by' => array_var($db_columns, $col), 'order_by_asc' => $asc ? 0 : 1)) . $parameterURL : "#";
            ?>
" <?php 
            echo $echo_link ? "" : 'style="cursor:default;"';
            ?>
>
			<?php 
            echo clean($col);
            ?>
		</a>
예제 #29
0
	<div id="tasksPanelContent" style="background-color:white;padding:7px;padding-top:0px;overflow-y:scroll;position:relative;">
	<?php if (isset($displayTooManyTasks) && $displayTooManyTasks){ ?>
	<div class="tasksPanelWarning ico-warning32" style="font-size:10px;color:#666;background-repeat:no-repeat;padding-left:40px;max-width:920px; margin:20px;border:1px solid #E3AD00;background-color:#FFF690;background-position:4px 4px;">
		<div style="font-weight:bold;width:99%;text-align:center;padding:4px;color:#AF8300;"><?php echo lang('too many tasks to display', user_config_option('task_display_limit')) ?></div>
	</div>
	<?php } ?>
		<div id="tasksPanelContainer" style="background-color:white;padding:7px;padding-top:0px;">
	<?php if(!(isset($tasks) || $userPreferences['groupBy'] == 'milestone')) { ?>
			<div style="font-size:130%;width:100%;text-align:center;padding-top:10px;color:#777;"><?php echo lang('no tasks to display') ?></div>
	<?php } ?>
		</div>
	</div>
</div>

<script type="text/javascript">
	if (!ogTasks.tasks_object_type_id) ogTasks.tasks_object_type_id = '<?php echo ProjectTasks::instance()->getObjectTypeId() ?>';
	if (rx__TasksDrag)
		rx__TasksDrag.initialize();

	ogTasks.userPreferences = Ext.util.JSON.decode(document.getElementById('hfUserPreferences').value);

	var mili = 0;
	if (og.TasksTopToolbar == 'undefined') {
		mili = 500;
	}

	// to prevent js execution before the js files are received
	setTimeout(function () {
		var ogTasksTT = new og.TasksTopToolbar({
			projectTemplatesHfId:'hfProjectTemplates',
			allTemplatesHfId:'hfAllTemplates',
 /**
  * Return all tasks from this list
  *
  * @access public
  * @param void
  * @return array
  */
 function getSubTasksIds()
 {
     $subtasks_ids = array();
     $condition = ' AND `parent_id` = ' . DB::escape($this->getId());
     $subtasks_rows = ProjectTasks::instance()->listing(array("select_columns" => array("`object_id`"), "extra_conditions" => $condition, "count_results" => false, "raw_data" => true))->objects;
     for ($i = 0; $i < count($subtasks_rows); $i++) {
         $subtasks_ids[] = (int) $subtasks_rows[$i]['object_id'];
     }
     return $subtasks_ids;
 }