Exemplo n.º 1
0
 function new_list_tasks()
 {
     //load config options into cache for better performance
     load_user_config_options_by_category_name('task panel');
     $isJson = array_var($_GET, 'isJson', false);
     if ($isJson) {
         ajx_current("empty");
     }
     $request_conditions = $this->get_tasks_request_conditions();
     $conditions = $request_conditions['conditions'];
     $filter_value = $request_conditions['filterValue'];
     $filter = $request_conditions['filter'];
     $status = $request_conditions['status'];
     $tasks = array();
     $pendingstr = $status == 0 ? " AND `e`.`completed_on` = " . DB::escape(EMPTY_DATETIME) . " " : "";
     $milestone_conditions = " AND `is_template` = false " . $pendingstr;
     //Find all internal milestones for these tasks
     $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();
     $task_ids = array();
     if ($tasks) {
         foreach ($tasks as $task) {
             $task_ids[] = $task['id'];
             if ($task['milestone_id'] != 0) {
                 $milestone_ids[$task['milestone_id']] = $task['milestone_id'];
             }
         }
         // generate request cache
         ObjectMembers::instance()->getCachedObjectMembers(0, $task_ids);
         ProjectTasks::instance()->findByRelatedCached(0, $task_ids);
     }
     $cp_values = array();
     if (count($task_ids) > 0) {
         $cp_rows = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "custom_property_values WHERE object_id IN (" . implode(',', $task_ids) . ")");
         if (is_array($cp_rows)) {
             foreach ($cp_rows as $row) {
                 if (!isset($cp_values[$row['object_id']])) {
                     $cp_values[$row['object_id']] = array();
                 }
                 if (!isset($cp_values[$row['object_id']][$row['custom_property_id']])) {
                     $cp_values[$row['object_id']][$row['custom_property_id']] = array();
                 }
                 $cp_values[$row['object_id']][$row['custom_property_id']][] = $row['value'];
             }
         }
     }
     tpl_assign('cp_values', $cp_values);
     $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
     if (logged_user()->isGuest()) {
         $users = array(logged_user());
     } else {
         $users = allowed_users_in_context(ProjectTasks::instance()->getObjectTypeId(), active_context(), ACCESS_LEVEL_READ, '', true);
     }
     $allUsers = Contacts::getAllUsers(null, true);
     $user_ids = array(-1);
     foreach ($allUsers 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 \r\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 (!$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);
         if (strtotime(user_config_option('tasksDateStart'))) {
             //this return null if date is 0000-00-00 00:00:00
             $dateStart = new DateTime('@' . strtotime(user_config_option('tasksDateStart')));
             $dateStart = $dateStart->format(user_config_option('date_format'));
         } else {
             $dateStart = '';
         }
         if (strtotime(user_config_option('tasksDateEnd'))) {
             //this return null if date is 0000-00-00 00:00:00
             $dateEnd = new DateTime('@' . strtotime(user_config_option('tasksDateEnd')));
             $dateEnd = $dateEnd->format(user_config_option('date_format'));
         } else {
             $dateEnd = '';
         }
         $userPref = array();
         $showDimensionCols = array_map('intval', explode(',', user_config_option('tasksShowDimensionCols')));
         $userPref = array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'dateStart' => $dateStart, 'dateEnd' => $dateEnd, 'status' => $status, 'showTime' => user_config_option('tasksShowTime'), 'showDates' => user_config_option('tasksShowDates'), 'showStartDates' => user_config_option('tasksShowStartDates'), 'showEndDates' => user_config_option('tasksShowEndDates'), 'showBy' => user_config_option('tasksShowAssignedBy'), 'showClassification' => user_config_option('tasksShowClassification'), 'showSubtasksStructure' => user_config_option('tasksShowSubtasksStructure'), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 1), 'showTimeEstimates' => user_config_option('tasksShowTimeEstimates', 1), 'showTimePending' => user_config_option('tasksShowTimePending', 1), 'showTimeWorked' => user_config_option('tasksShowTimeWorked', 1), 'showPercentCompletedBar' => user_config_option('tasksShowPercentCompletedBar', 1), 'showQuickEdit' => user_config_option('tasksShowQuickEdit', 1), 'showQuickComplete' => user_config_option('tasksShowQuickComplete', 1), 'showQuickComment' => user_config_option('tasksShowQuickComment', 1), 'showQuickAddSubTasks' => user_config_option('tasksShowQuickAddSubTasks', 1), 'showDimensionCols' => $showDimensionCols, 'groupBy' => user_config_option('tasksGroupBy'), 'orderBy' => user_config_option('tasksOrderBy'), 'previousPendingTasks' => user_config_option('tasksPreviousPendingTasks', 1), 'defaultNotifyValue' => user_config_option('can notify from quick add'));
         hook::fire('tasks_user_preferences', null, $userPref);
         tpl_assign('userPreferences', $userPref);
         tpl_assign('userPermissions', array('can_add' => ProjectTask::canAdd(logged_user(), active_context()) ? 1 : 0));
         ajx_set_no_toolbar(true);
     }
 }
	function list_users() {
		$this->setTemplate(get_template_path("json"));
		ajx_current("empty");
		$usr_data = array();
		$users = Contacts::findAll(array("conditions"=>"is_company = 0"));
		if ($users) {
			foreach ($users as $usr) {
				$usr_data[] = array(
					"id" => $usr->getId(),
					"name" => $usr->getObjectName()
				);
			}
		}
		$extra = array();
		$extra['users'] = $usr_data;
		ajx_extra_data($extra);
	}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
		$mnames = array();
		$allowed_contact_ids = array();
		foreach ($active_members as $member) {
			$allowed_contact_ids[] = $member->getAllowedContactIds();
			$mnames[] = clean($member->getName());
		}
		$intersection = $allowed_contact_ids[0];
		if (count($allowed_contact_ids) > 1) {
			for ($i = 1; $i < count($allowed_contact_ids); $i++) {
				$intersection = array_intersect($intersection, $allowed_contact_ids[$i]);
			}
		}
		
		$contacts = Contacts::findAll(array(
			'conditions' => 'object_id IN ('.implode(',',$intersection).') AND `is_company` = 0 AND disabled = 0',
			'limit' => $limit,
			'order' => 'last_activity, updated_on',
			'order_dir' => 'desc',
		));
		$total = count($contacts);
		
		$widget_title = lang("people in", implode(", ", $mnames));
	
	} else {
		
		$result = Contacts::instance()->listing(array(
			"order" => "last_activity, updated_on",
			"order_dir" => "desc",
			"extra_conditions" => " AND `is_company` = 0 AND disabled = 0 AND user_type > 0",
			"start" => 0,
			"limit" => $limit
		));
Exemplo n.º 5
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);
     }
 }
Exemplo n.º 6
0
 /**
  * Return array of all company members
  *
  * @access public
  * @param void
  * @return array
  */
 function getContacts()
 {
     return Contacts::findAll(array('conditions' => '`company_id` = ' . DB::escape($this->getId()), 'order' => '`display_name` ASC'));
     // findAll
 }
Exemplo n.º 7
0
 /**
  * Return all client companies
  *
  * @access public
  * @param void
  * @return array
  */
 function getClientCompanies()
 {
     return Contacts::findAll(array('conditions' => '`object_id` <> 1 AND `is_company` = 1'));
 }
Exemplo n.º 8
0
	/**
	 * Edit email account
	 *
	 * @access public
	 * @param void
	 * @return null
	 */
	function edit_account() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		$this->setTemplate('add_account', $this->plugin_name);

		$mailAccount = MailAccounts::findById(get_id());
		if(!($mailAccount instanceof MailAccount)) {
			flash_error(lang('mailAccount dnx'));
			ajx_current("empty");
			return;
		} // if

		if(!$mailAccount->canEdit(logged_user())) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		} // if

		// get mail account users
		$mailAccountUsers = MailAccountContacts::getByAccount($mailAccount);
		$mau = array();
		foreach ($mailAccountUsers as $au) {
			$contact = $au->getContact();
			if (!$contact instanceof Contact) continue;
			
			$mau[$au->getContactId()] = array(
				'name' => $contact->getObjectName(),
				'can_edit' => $au->getCanEdit(),
			);
		}
		tpl_assign('mailAccountUsers', $mau);
		
		$is_admin = logged_user()->isAdministrator();
		tpl_assign('is_admin', $is_admin);
		
		$mailAccount_data = array_var($_POST, 'mailAccount');
		if(!is_array($mailAccount_data)) {
			$mailAccount_data = array(
		          'user_id' => logged_user()->getId(),
		          'name' => $mailAccount->getName(),
		          'email' => $mailAccount->getEmail(),
		          'email_addr' => $mailAccount->getEmailAddress(),
		          'password' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getPassword()),
		          'server' => $mailAccount->getServer(),
		          'is_imap' => $mailAccount->getIsImap(),
		          'incoming_ssl' => $mailAccount->getIncomingSsl(),
		          'incoming_ssl_port' => $mailAccount->getIncomingSslPort(),
		          'smtp_server' => $mailAccount->getSmtpServer(),
		          'smtp_port' => $mailAccount->getSmtpPort(),
		          'smtp_username' => $mailAccount->getSmtpUsername(),
		          'smtp_password' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSmtpPassword()),
		          'smtp_use_auth' => $mailAccount->getSmtpUseAuth(),
		          'del_from_server' => $mailAccount->getDelFromServer(),
		          'outgoing_transport_type' => $mailAccount->getOutgoingTrasnportType(),
				  'workspace' => $mailAccount->getColumnValue('workspace',0),			
			); // array
			if(config_option('sent_mails_sync')){								
				$sync_details = array('sync_server' => $mailAccount->getSyncServer(),
				  'sync_addr' => $mailAccount->getSyncAddr(),
				  'sync_pass' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSyncPass()),
				  'sync_ssl' => $mailAccount->getSyncSsl(),
				  'sync_sslport' => $mailAccount->getSyncSslPort());
				$mailAccount_data = array_merge ($mailAccount_data, $sync_details);
			}
		} else {
			if (!isset($mailAccount_data['sync_ssl']))
				$mailAccount_data['sync_ssl'] = false;
			if (!isset($mailAccount_data['incoming_ssl']))
				$mailAccount_data['incoming_ssl'] = false;
			if (!isset($mailAccount_data['is_default']))
				$mailAccount_data['is_default'] = false;
		}
		
		if ($mailAccount->getIsImap()) {
			try {
				$real_folders = MailUtilities::getImapFolders($mailAccount);
				DB::beginWork();
				foreach ($real_folders as $folder_name) {
					if (!MailAccountImapFolders::findById(array('account_id' => $mailAccount->getId(), 'folder_name' => $folder_name))) {
						$acc_folder = new MailAccountImapFolder();
						$acc_folder->setAccountId($mailAccount->getId());
						$acc_folder->setFolderName($folder_name);
						$acc_folder->setCheckFolder($folder_name == 'INBOX');// By default only INBOX is checked
					 
						$acc_folder->save();
					}
				}
				DB::commit();
			} catch (Exception $e) {
				DB::rollback();
				flash_error($e->getMessage());
			}
			 
			$imap_folders = MailAccountImapFolders::getMailAccountImapFolders($mailAccount->getId());
			tpl_assign('imap_folders', $imap_folders);
		}

		tpl_assign('mailAccount', $mailAccount);
		tpl_assign('mailAccount_data', $mailAccount_data);

		if(array_var($_POST, 'submitted')) {
			try {
				$user_changed = false;
				$selected_user = array_var($_POST, 'users_select_box');					
				if (!$is_admin){
					$mail_account_user = Contacts::findById($mailAccount->getContactId());
				}
				else{
					$mail_account_user = Contacts::findById($selected_user);
					$old_user_id = $mailAccount->getContactId();					
					if ($old_user_id != $mail_account_user->getId())
						$user_changed = true;
				}
				$mailAccount_data['user_id'] = $mail_account_user->getId();
				$mailAccount_data['sync_ssl'] = array_var($mailAccount_data, 'sync_ssl') == "checked";
				
				DB::beginWork();
				$logged_user_settings = MailAccountContacts::getByAccountAndContact($mailAccount, logged_user());
				$logged_user_can_edit = $logged_user_settings instanceof MailAccountContact && $logged_user_settings->getCanEdit() || $mailAccount->getContactId() == logged_user()->getId();
				if ($logged_user_can_edit) {
					if (!array_var($mailAccount_data, 'del_mails_from_server', false)) $mailAccount_data['del_from_server'] = 0;
					$mailAccount->setFromAttributes($mailAccount_data);
					$mailAccount->setPassword(MailUtilities::ENCRYPT_DECRYPT($mailAccount->getPassword()));
					$mailAccount->setSmtpPassword(MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSmtpPassword()));
					$outbox_folder = array_var($_POST, 'outbox_select_box');
					if (config_option("sent_mails_sync") && isset($outbox_folder)){		
						$mailAccount->setSyncPass(MailUtilities::ENCRYPT_DECRYPT($mailAccount_data['sync_pass']));						
						$mailAccount->setSyncFolder($outbox_folder);					
					}
					
					
					//in case there is a new owner of the email account
					if ($user_changed){						
						$conditions = array("conditions" => "`created_by_id` = '$old_user_id' AND `account_id` = ".$mailAccount->getId()."");
						$all_emails = MailContents::findAll($conditions);					
						foreach ($all_emails as $e){							
							$e->setCreatedById($mail_account_user->getId());
							$e->save();
						}						
					}
					
					//If imap, save folders to check
					if($mailAccount->getIsImap() && is_array(array_var($_POST, 'check'))) {
					  	$checks = array_var($_POST, 'check');
					  	if (is_array($imap_folders) && count($imap_folders)) {
						  	foreach ($imap_folders as $folder) {
						  		$folder->setCheckFolder(false);
						  		foreach ($checks as $name => $cf) {
						  			$name = str_replace(array('¡','!'), array('[',']'), $name);//to avoid a mistaken array if name contains [ 
						  			if (strcasecmp($name, $folder->getFolderName()) == 0) {
						  				$folder->setCheckFolder($cf == 'checked');
						  				break;
						  			}
						  		}
						  		$folder->save();
						  	}
					  	}
					}
					
					$member_ids = json_decode(array_var($_POST, 'members'));
					if ( count($member_ids) > 0  ){
						$member = $member_ids[0];
					}else{
						$member = 0;
					}
					$mailAccount->setMemberId($member);
					
					$mailAccount->save();
					
					// process users
					
					$account_users = Contacts::findAll();
					$user_access = array_var($_POST, 'user_access');
					foreach ($account_users as $account_user) {
						$user_id = $account_user->getId();
						$access = array_var($user_access, $user_id, 'none');
						$account_user = MailAccountContacts::getByAccountAndContact($mailAccount, $account_user);
						if ($access != 'none' || $user_id == $mail_account_user->getId()) {
							if (!$account_user instanceof MailAccountContact) {
								$account_user = new MailAccountContact();
								$account_user->setAccountId($mailAccount->getId());
								$account_user->setContactId($user_id);
							}
							$account_user->setCanEdit($access == 'write');
							$account_user->save();
						} else if ($account_user instanceof MailAccountContact) {
							$account_user->delete();
						}
					}
					/*// delete any remaining ones
					$account_users = MailAccountContacts::getByAccount($mailAccount);
					foreach ($account_users as $account_user) {
						if ($access = array_var($user_access, $account_user->getId(), 'none') == 'none') {
							$account_user->delete();
						}
					}*/
					
					evt_add("mail account edited", array(
							"id" => $mailAccount->getId(),
							"name" => $mailAccount->getName(),
							"email" => $mailAccount->getEmail()
					));
				}
				
				// personal settings
				if (array_var($_POST, 'is_default')) {
					$user_accounts = MailAccountContacts::getByContact(logged_user());
					foreach ($user_accounts as $acc) {
						if ($acc->getAccountId() != $mailAccount->getId()) {
							$acc->setIsDefault(false);
							$acc->save();				
						} else {
							$acc->setIsDefault(true);
							$acc->save();
						}
					}
				}
				$logged_user_settings = MailAccountContacts::getByAccountAndContact($mailAccount, logged_user());
				if ($logged_user_settings instanceof MailAccountContact) { 
					$logged_user_settings->setSignature(array_var($_POST, 'signature'));
					$logged_user_settings->setSenderName(array_var($_POST, 'sender_name'));
					$logged_user_settings->save();
				}
				DB::commit();

				flash_success(lang('success edit mail account', $mailAccount->getName()));
				ajx_current("back");

		  // Error...
			} catch(Exception $e) {
				DB::rollback();
				ajx_current("empty");
				flash_error($e->getMessage());
			} // try
		} // if
	} // edit
Exemplo n.º 9
0
function permission_member_form_parameters($member = null)
{
    if ($member) {
        $dim = $member->getDimension();
    } elseif (array_var($_REQUEST, 'dim_id')) {
        $dim = Dimensions::getDimensionById(array_var($_REQUEST, 'dim_id'));
    }
    if (logged_user()->isMemberOfOwnerCompany()) {
        $companies = Contacts::findAll(array("conditions" => "is_company = 1", 'order' => 'name'));
    } else {
        $companies = array(owner_company());
        if (logged_user()->getCompany() instanceof Contact) {
            $companies[] = logged_user()->getCompany();
        }
    }
    $allowed_object_types = array();
    $dim_obj_types = $dim->getAllowedObjectTypeContents();
    foreach ($dim_obj_types as $dim_obj_type) {
        // To draw a row for each object type of the dimension
        if (!array_key_exists($dim_obj_type->getContentObjectTypeId(), $allowed_object_types) && (!$member || $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId())) {
            $allowed_object_types[$dim_obj_type->getContentObjectTypeId()] = ObjectTypes::findById($dim_obj_type->getContentObjectTypeId());
            $allowed_object_types_json[] = $dim_obj_type->getContentObjectTypeId();
        }
    }
    $permission_groups = array();
    foreach ($companies as $company) {
        $users = $company->getUsersByCompany();
        foreach ($users as $u) {
            $permission_groups[] = $u->getPermissionGroupId();
        }
    }
    $no_company_users = Contacts::getAllUsers("AND `company_id` = 0", true);
    foreach ($no_company_users as $noc_user) {
        $permission_groups[] = $noc_user->getPermissionGroupId();
    }
    $non_personal_groups = PermissionGroups::getNonRolePermissionGroups();
    foreach ($non_personal_groups as $group) {
        $permission_groups[] = $group->getId();
    }
    foreach ($permission_groups as $pg_id) {
        if ($dim->hasAllowAllForContact($pg_id)) {
            $member_permissions[$pg_id] = array();
            foreach ($dim_obj_types as $dim_obj_type) {
                if ($member && $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) {
                    $member_permissions[$pg_id][] = array('o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 1, 'd' => 1, 'r' => 1);
                } elseif (!$member) {
                    // WHEN CREATING a new member dont allow any user
                    $member_permissions[$pg_id][] = array('o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 0, 'd' => 0, 'r' => 0);
                }
            }
        } else {
            if (!$dim->deniesAllForContact($pg_id)) {
                $member_permissions[$pg_id] = array();
                if ($member) {
                    $mpgs = ContactMemberPermissions::findAll(array("conditions" => array("`permission_group_id` = ? AND `member_id` = ?", $pg_id, $member->getId())));
                    if (is_array($mpgs)) {
                        foreach ($mpgs as $mpg) {
                            $member_permissions[$mpg->getPermissionGroupId()][] = array('o' => $mpg->getObjectTypeId(), 'w' => $mpg->getCanWrite() ? 1 : 0, 'd' => $mpg->getCanDelete() ? 1 : 0, 'r' => 1);
                        }
                    }
                }
            }
        }
    }
    return array('member' => $member, 'allowed_object_types' => $allowed_object_types, 'allowed_object_types_json' => $allowed_object_types_json, 'permission_groups' => $permission_groups, 'member_permissions' => $member_permissions);
}
Exemplo n.º 10
0
	function permission_member_form_parameters($member = null, $dimension_id = null) {
		
		if ( $member ) {
			$dim = $member->getDimension();
		}elseif (array_var( $_REQUEST,'dim_id')) {
			$dim = Dimensions::getDimensionById(array_var( $_REQUEST,'dim_id'));
		}elseif (!is_null($dimension_id)) {
			$dim = Dimensions::getDimensionById($dimension_id);
		}
		
		if (!$dim instanceof Dimension) {
			Logger::log("Invalid dimension: " . ($member instanceof Member ? " for member ".$member->getId() : "request: ".print_r($_REQUEST, 1)));
			throw new Exception("Invalid dimension");
		}
		
		if (logged_user()->isMemberOfOwnerCompany()) {
			$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'));
		} else {
			$companies = array(owner_company());
			if (logged_user()->getCompany() instanceof Contact) $companies[] = logged_user()->getCompany();
		}
		
		$allowed_object_types = array();
		$dim_obj_types = $dim->getAllowedObjectTypeContents();
		foreach ($dim_obj_types as $dim_obj_type) {
			// To draw a row for each object type of the dimension
			if ( !array_key_exists($dim_obj_type->getContentObjectTypeId(), $allowed_object_types) && (!$member || $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) ) {
				$allowed_object_types[$dim_obj_type->getContentObjectTypeId()] = ObjectTypes::findById($dim_obj_type->getContentObjectTypeId());
				$allowed_object_types_json[] = $dim_obj_type->getContentObjectTypeId();
			}
		}
		
		$permission_groups = array();
		foreach ($companies as $company) {
			$users = $company->getUsersByCompany();
			foreach ($users as $u) $permission_groups[] = $u->getPermissionGroupId();
		}
		
		$no_company_users = Contacts::getAllUsers("AND `company_id` = 0", true);
		foreach ($no_company_users as $noc_user) {
			$permission_groups[] = $noc_user->getPermissionGroupId();
		}
		
		$non_personal_groups = PermissionGroups::getNonRolePermissionGroups();
		foreach ($non_personal_groups as $group) {
			$permission_groups[] = $group->getId();
		}
		
		foreach ($permission_groups as $pg_id) {
			if ($dim->hasAllowAllForContact($pg_id)) {
				$member_permissions[$pg_id] = array();
				foreach ($dim_obj_types as $dim_obj_type) {
					if ($member && $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) {
						$member_permissions[$pg_id][] = array(
							'o' => $dim_obj_type->getContentObjectTypeId(),
							'w' => 1,
							'd' => 1,
							'r' => 1
						);
					}elseif(!$member){
						// WHEN CREATING a new member dont allow any user 
						$member_permissions[$pg_id][] = array(
							'o' => $dim_obj_type->getContentObjectTypeId(),
							'w' => 0,
							'd' => 0,
							'r' => 0
						);
					}
				}
			} else if (!$dim->deniesAllForContact($pg_id)) {
				$member_permissions[$pg_id] = array();
				if ($member) {
					$mpgs = ContactMemberPermissions::findAll(array("conditions" => array("`permission_group_id` = ? AND `member_id` = ?", $pg_id, $member->getId())));
					if (is_array($mpgs)) {
						foreach ($mpgs as $mpg) {
							$member_permissions[$mpg->getPermissionGroupId()][] = array(
								'o' => $mpg->getObjectTypeId(),
								'w' => $mpg->getCanWrite() ? 1 : 0,
								'd' => $mpg->getCanDelete() ? 1 : 0,
								'r' => 1
							);
						}
					}
				}
			}
		}
		
		return array(
			'member' => $member,
			'allowed_object_types' => $allowed_object_types,
			'allowed_object_types_json' => $allowed_object_types_json,
			'permission_groups' => $permission_groups,
			'member_permissions' => $member_permissions,
		);
	}
Exemplo n.º 11
0
	function getCategoryUsers() {
		return Contacts::findAll(array('conditions' => 'default_billing_id = ' . $this->getId()));
	}
Exemplo n.º 12
0
function get_default_member_permission($parent, $permission_parameters)
{
    //inherit permission from parent
    if ($parent != 0 && config_option('inherit_permissions_from_parent_member')) {
        $parent_member = Members::getMemberById($parent);
        if ($parent_member instanceof Member) {
            $parent_permissions = permission_member_form_parameters($parent_member);
            $permission_parameters['permission_groups'] = $parent_permissions['permission_groups'];
            $permission_parameters['member_permissions'] = $parent_permissions['member_permissions'];
        }
    }
    // Add default permissions for executives, managers and administrators
    if (config_option('add_default_permissions_for_users')) {
        if ($parent == 0) {
            $user_types = implode(',', config_option('give_member_permissions_to_new_users'));
            if (trim($user_types) != "") {
                $users = Contacts::findAll(array('conditions' => "user_type IN (" . $user_types . ")"));
                foreach ($users as $user) {
                    if (!isset($permission_parameters['member_permissions'][$user->getPermissionGroupId()]) || count($permission_parameters['member_permissions'][$user->getPermissionGroupId()]) == 0) {
                        $user_pg = array();
                        foreach ($permission_parameters['allowed_object_types'] as $ot) {
                            $role_perm = RoleObjectTypePermissions::findOne(array('conditions' => array("role_id=? AND object_type_id=?", $user->getUserType(), $ot->getId())));
                            $user_pg[] = array('o' => $ot->getId(), 'w' => $role_perm instanceof RoleObjectTypePermission ? $role_perm->getCanWrite() ? 1 : 0 : 0, 'd' => $role_perm instanceof RoleObjectTypePermission ? $role_perm->getCanDelete() ? 1 : 0 : 0, 'r' => $role_perm instanceof RoleObjectTypePermission ? 1 : 0);
                        }
                        $permission_parameters['member_permissions'][$user->getPermissionGroupId()] = $user_pg;
                    }
                }
            }
        }
    }
    return $permission_parameters;
}
Exemplo n.º 13
0
        if ($v == '') {
            unset($intersection[$k]);
        }
    }
    //user to display on the widget
    $intersection_condition = count($intersection) > 0 ? 'object_id IN (' . implode(',', $intersection) . ') AND' : '';
    $intersection_condition = "";
    $result = Contacts::instance()->listing(array("order" => $order, "order_dir" => "DESC", "extra_conditions" => " AND `is_company` = 0 AND disabled = 0", "start" => 0, "limit" => $limit));
    $total = $result->total;
    $contacts = $result->objects;
    $contacts_for_combo = null;
    //if logged user can assign permissions
    if (can_manage_security(logged_user())) {
        //users to display on the combo
        $intersection_condition = count($intersection) > 0 ? 'o.id NOT IN (' . implode(',', $intersection) . ') AND' : '';
        $contacts_for_combo = Contacts::findAll(array('conditions' => $intersection_condition . ' `is_company` = 0 AND `user_type` > ' . logged_user()->getUserType() . ' AND disabled = 0', 'order' => 'first_name', 'order_dir' => 'desc'));
    }
    //add people button name
    if (isset($mnames[0])) {
        $add_people_btn = true;
    }
    //widget title
    $widget_title = lang("users in", implode(", ", $mnames));
    $mids = implode(",", $mids);
} else {
    $widget_title = lang("users");
    $result = Contacts::instance()->listing(array("order" => $order, "order_dir" => "DESC", "extra_conditions" => " AND `is_company` = 0 AND disabled = 0 AND `user_type` > 0", "start" => 0, "limit" => $limit));
    $total = $result->total;
    $contacts = $result->objects;
}
$render_add = can_manage_security(logged_user());
Exemplo n.º 14
0
 function getContacts()
 {
     return Contacts::findAll(array('conditions' => '`company_id` = ' . DB::escape($this->getId())));
     // findAll
 }
Exemplo n.º 15
0
function core_dimensions_after_save_member_permissions($member, &$ignored) {
	if (!$member instanceof Member || !($member->getId()>0)) return;
	$permission_group_ids = array();
	
	$cmp_rows = DB::executeAll("SELECT DISTINCT permission_group_id FROM ".TABLE_PREFIX."contact_member_permissions WHERE member_id = '".$member->getId()."' AND permission_group_id IN (SELECT id FROM ".TABLE_PREFIX."permission_groups WHERE type IN ('permission_groups','user_groups'))");
	foreach ($cmp_rows as $row) {
		$permission_group_ids[$row['permission_group_id']] = $row['permission_group_id'];
	}
	
	$contacts = array();
	// users
	if (count($permission_group_ids) > 0) {
		$contacts = Contacts::findAll(array('conditions' => 'user_type > 0 && permission_group_id IN ('.implode(',', $permission_group_ids).')'));
	}
	// contacts
	$contact_rows = DB::executeAll("SELECT DISTINCT om.object_id FROM ".TABLE_PREFIX."object_members om INNER JOIN ".TABLE_PREFIX."contacts c ON c.object_id=om.object_id 
		WHERE om.member_id='".$member->getId()."' AND c.user_type=0");
	$no_user_ids = array();
	if (is_array($contact_rows)) {
		foreach ($contact_rows as $row) {
			$no_user_ids[] = $row['object_id'];
		}
	}
	$more_contacts = Contacts::findAll(array('conditions' => 'object_id IN ('.implode(',', $no_user_ids).')'));
	
	$contacts = array_merge($contacts, $more_contacts);
	$contact_ids = array(0);
	
	$persons_dim = Dimensions::findByCode("feng_persons");

	core_dim_remove_contacts_member_associations($member);
	
	foreach ($contacts as $contact) {
		$contact_id = $contact->getId();
		$contact_member = Members::findOneByObjectId($contact_id, $persons_dim->getId());
		if ($contact_member instanceof Member) {
			core_dim_add_contact_member_associations($contact_member, $member);
			
			if ($contact instanceof Contact && $contact->isUser()) {
				$has_project_permissions = ContactMemberPermissions::instance()->count("permission_group_id = '".$contact->getPermissionGroupId()."' AND member_id = ".$member->getId()) > 0;
				if (!$has_project_permissions) {
					RoleObjectTypePermissions::createDefaultUserPermissions($contact, $member);
				}
			}
		}
		// add user content object to customer member
		ObjectMembers::addObjectToMembers($contact_id, array($member));
		$contact->addToSharingTable();
		$contact_ids[] = $contact_id;
	}
	
	// remove contacts whose members are no longer associated to the customer member
	$previous_users_in_member = Contacts::instance()->listing(array(
		'member_ids' => array($member->getId()),
		'ignore_context' => true,
		'extra_conditions' => ' AND e.user_type > 0 AND e.object_id NOT IN ('.implode(',', $contact_ids).')',
	))->objects;
	foreach ($previous_users_in_member as $prev_u) {
		ObjectMembers::removeObjectFromMembers($prev_u, logged_user(), array($member), array($member->getId()));
	}
	
	// refresh dimensions
	evt_add("reload dimension tree", array('dim_id' => $persons_dim->getId(), 'node' => null));
}
 /**
  * Edit email account
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_account()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_account', $this->plugin_name);
     $mailAccount = MailAccounts::findById(get_id());
     if (!$mailAccount instanceof MailAccount) {
         flash_error(lang('mailAccount dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$mailAccount->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     // get mail account users
     $mailAccountUsers = MailAccountContacts::getByAccount($mailAccount);
     $mau = array();
     foreach ($mailAccountUsers as $au) {
         $contact = $au->getContact();
         if (!$contact instanceof Contact) {
             continue;
         }
         $mau[$au->getContactId()] = array('name' => $contact->getObjectName(), 'can_edit' => $au->getCanEdit());
     }
     tpl_assign('mailAccountUsers', $mau);
     $is_admin = logged_user()->isAdministrator();
     tpl_assign('is_admin', $is_admin);
     $mailAccount_data = array_var($_POST, 'mailAccount');
     if (!is_array($mailAccount_data)) {
         $mailAccount_data = array('user_id' => logged_user()->getId(), 'name' => $mailAccount->getName(), 'email' => $mailAccount->getEmail(), 'email_addr' => $mailAccount->getEmailAddress(), 'password' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getPassword()), 'server' => $mailAccount->getServer(), 'is_imap' => $mailAccount->getIsImap(), 'incoming_ssl' => $mailAccount->getIncomingSsl(), 'incoming_ssl_port' => $mailAccount->getIncomingSslPort(), 'smtp_server' => $mailAccount->getSmtpServer(), 'smtp_port' => $mailAccount->getSmtpPort(), 'smtp_username' => $mailAccount->getSmtpUsername(), 'smtp_password' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSmtpPassword()), 'smtp_use_auth' => $mailAccount->getSmtpUseAuth(), 'del_from_server' => $mailAccount->getDelFromServer(), 'mark_read_on_server' => $mailAccount->getMarkReadOnServer(), 'outgoing_transport_type' => $mailAccount->getOutgoingTrasnportType());
         // array
         if (config_option('sent_mails_sync')) {
             $sync_details = array('sync_server' => $mailAccount->getSyncServer(), 'sync_addr' => $mailAccount->getSyncAddr(), 'sync_pass' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSyncPass()), 'sync_ssl' => $mailAccount->getSyncSsl(), 'sync_sslport' => $mailAccount->getSyncSslPort());
             $mailAccount_data = array_merge($mailAccount_data, $sync_details);
         }
     } else {
         if (!isset($mailAccount_data['sync_ssl'])) {
             $mailAccount_data['sync_ssl'] = false;
         }
         if (!isset($mailAccount_data['incoming_ssl'])) {
             $mailAccount_data['incoming_ssl'] = false;
         }
         if (!isset($mailAccount_data['is_default'])) {
             $mailAccount_data['is_default'] = false;
         }
     }
     if ($mailAccount->getIsImap()) {
         /*try {
         			$real_folders = MailUtilities::getImapFolders($mailAccount);
         			DB::beginWork();
         			foreach ($real_folders as $folder_name) {
         				if (!MailAccountImapFolders::findById(array('account_id' => $mailAccount->getId(), 'folder_name' => $folder_name))) {
         					$acc_folder = new MailAccountImapFolder();
         					$acc_folder->setAccountId($mailAccount->getId());
         					$acc_folder->setFolderName($folder_name);
         					$acc_folder->setCheckFolder($folder_name == 'INBOX');// By default only INBOX is checked
         				 
         					$acc_folder->save();
         				}
         			}
         			DB::commit();
         		} catch (Exception $e) {
         			DB::rollback();
         			flash_error($e->getMessage());
         		}*/
         $imap_folders = MailAccountImapFolders::getMailAccountImapFolders($mailAccount->getId());
         tpl_assign('imap_folders', $imap_folders);
     }
     tpl_assign('mailAccount', $mailAccount);
     tpl_assign('mailAccount_data', $mailAccount_data);
     if (array_var($_POST, 'submitted')) {
         try {
             $user_changed = false;
             $selected_user = array_var($_POST, 'users_select_box');
             if (!$is_admin) {
                 $selected_user = $mailAccount->getContactId();
             }
             $mail_account_user = Contacts::findById($selected_user);
             if ($mail_account_user instanceof Contact) {
                 $old_user_id = $mailAccount->getContactId();
                 if ($old_user_id != $mail_account_user->getId()) {
                     $user_changed = true;
                 }
                 $mailAccount_data['user_id'] = $mail_account_user->getId();
             }
             $mailAccount_data['sync_ssl'] = array_var($mailAccount_data, 'sync_ssl') == "checked";
             DB::beginWork();
             $logged_user_settings = MailAccountContacts::getByAccountAndContact($mailAccount, logged_user());
             $logged_user_can_edit = $logged_user_settings instanceof MailAccountContact && $logged_user_settings->getCanEdit() || $mailAccount->getContactId() == logged_user()->getId() || logged_user()->isAdministrator();
             if ($logged_user_can_edit || $is_admin) {
                 if (!array_var($mailAccount_data, 'del_mails_from_server', false)) {
                     $mailAccount_data['del_from_server'] = 0;
                 }
                 if (!array_var($mailAccount_data, 'mark_read_on_server', false)) {
                     $mailAccount_data['mark_read_on_server'] = 0;
                 }
                 $mailAccount->setFromAttributes($mailAccount_data);
                 $mailAccount->setServer(trim($mailAccount->getServer()));
                 $mailAccount->setPassword(MailUtilities::ENCRYPT_DECRYPT($mailAccount->getPassword()));
                 $mailAccount->setSmtpPassword(MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSmtpPassword()));
                 $outbox_folder = array_var($_POST, 'outbox_select_box');
                 if (config_option("sent_mails_sync") && isset($outbox_folder)) {
                     $mailAccount->setSyncPass(MailUtilities::ENCRYPT_DECRYPT($mailAccount_data['sync_pass']));
                     $mailAccount->setSyncFolder($outbox_folder);
                 }
                 //in case there is a new owner of the email account
                 if ($user_changed && $mail_account_user instanceof Contact) {
                     DB::executeAll("UPDATE " . TABLE_PREFIX . "objects SET created_by_id=" . $mail_account_user->getId() . " WHERE  \r\n\t\t\t\t\t\t\t`created_by_id` = '{$old_user_id}' AND (select `account_id` FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=id) = " . $mailAccount->getId());
                     $mailAccount->setContactId($mail_account_user->getId());
                 }
                 //If imap, save folders to check
                 if ($mailAccount->getIsImap() && is_array(array_var($_POST, 'check'))) {
                     $checks = array_var($_POST, 'check');
                     $names = array();
                     foreach ($checks as $name => $checked) {
                         $name = str_replace(array('¡', '!'), array('[', ']'), $name);
                         //to avoid a mistaken array if name contains [
                         $names[] = $name;
                         $imap_folder = MailAccountImapFolders::instance()->findOne(array('conditions' => array('folder_name = ? AND account_id = ?', $name, $mailAccount->getId())));
                         if (!$imap_folder instanceof MailAccountImapFolder) {
                             $imap_folder = new MailAccountImapFolder();
                             $imap_folder->setAccountId($mailAccount->getId());
                             $imap_folder->setFolderName($name);
                         }
                         $imap_folder->setCheckFolder($checked == 'checked');
                         $imap_folder->save();
                     }
                     if (count($names) > 0) {
                         DB::execute("UPDATE " . TABLE_PREFIX . "mail_account_imap_folder SET check_folder=0 WHERE account_id=" . $mailAccount->getId() . " AND folder_name NOT IN ('" . implode("','", $names) . "')");
                     }
                 }
                 $member_ids = json_decode(array_var($_POST, 'members'));
                 $member_ids_str = "";
                 foreach ($member_ids as $mid) {
                     if (is_numeric($mid)) {
                         $member_ids_str .= ($member_ids_str == "" ? "" : ",") . $mid;
                     }
                 }
                 $mailAccount->setMemberId($member_ids_str);
                 $mailAccount->save();
                 // process users
                 $account_users = Contacts::findAll();
                 $user_access = array_var($_POST, 'user_access');
                 foreach ($account_users as $account_user) {
                     $user_id = $account_user->getId();
                     $access = array_var($user_access, $user_id, 'none');
                     $account_user = MailAccountContacts::getByAccountAndContact($mailAccount, $account_user);
                     if ($mail_account_user instanceof Contact && ($access != 'none' || $user_id == $mail_account_user->getId())) {
                         if (!$account_user instanceof MailAccountContact) {
                             $account_user = new MailAccountContact();
                             $account_user->setAccountId($mailAccount->getId());
                             $account_user->setContactId($user_id);
                         }
                         $account_user->setCanEdit($access == 'write');
                         $account_user->save();
                     } else {
                         if ($account_user instanceof MailAccountContact) {
                             $account_user->delete();
                         }
                     }
                 }
                 /*// delete any remaining ones
                 		$account_users = MailAccountContacts::getByAccount($mailAccount);
                 		foreach ($account_users as $account_user) {
                 			if ($access = array_var($user_access, $account_user->getId(), 'none') == 'none') {
                 				$account_user->delete();
                 			}
                 		}*/
                 evt_add("mail account edited", array("id" => $mailAccount->getId(), "name" => $mailAccount->getName(), "email" => $mailAccount->getEmail()));
             }
             // personal settings
             if (array_var($_POST, 'is_default')) {
                 $user_accounts = MailAccountContacts::getByContact(logged_user());
                 foreach ($user_accounts as $acc) {
                     if ($acc->getAccountId() != $mailAccount->getId()) {
                         $acc->setIsDefault(false);
                         $acc->save();
                     } else {
                         $acc->setIsDefault(true);
                         $acc->save();
                     }
                 }
             }
             $logged_user_settings = MailAccountContacts::getByAccountAndContact($mailAccount, logged_user());
             if ($logged_user_settings instanceof MailAccountContact) {
                 $logged_user_settings->setSignature(array_var($_POST, 'signature'));
                 $logged_user_settings->setSenderName(array_var($_POST, 'sender_name'));
                 $logged_user_settings->save();
             }
             DB::commit();
             flash_success(lang('success edit mail account', $mailAccount->getName()));
             ajx_current("back");
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
Exemplo n.º 17
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);
}
Exemplo n.º 18
0
 /**
  * Return contacts grouped by company
  *
  * @param void
  * @return array
  */
 static function getGroupedByCompany($include_disabled = true)
 {
     $companies = self::findAll(array('conditions' => array("`is_company` = 1")));
     if (!is_array($companies) || !count($companies)) {
         //return null;
     }
     $result = array();
     $comp_ids = array(0);
     foreach ($companies as $company) {
         $comp_ids[] = $company->getId();
         $result[$company->getId()] = array('details' => $company, 'users' => array());
     }
     $company_users = Contacts::findAll(array('order' => 'company_id, first_name, surname', 'conditions' => 'user_type<>0 AND company_id IN (' . implode(',', $comp_ids) . ')' . ($include_disabled ? "" : " AND disabled=0")));
     foreach ($company_users as $user) {
         $result[$user->getCompanyId()]['users'][] = $user;
     }
     $res = array();
     foreach ($result as $comp_info) {
         if (array_var($comp_info, 'details') instanceof Contact) {
             $res[$comp_info['details']->getObjectName()] = $comp_info;
         }
     }
     $result = $res;
     $no_company_users = Contacts::getAllUsers("AND `company_id` = 0", $include_disabled);
     if (count($no_company_users) > 0) {
         $result[lang('without company')] = array('details' => null, 'users' => $no_company_users);
     }
     return count($result) ? $result : null;
 }
Exemplo n.º 19
0
 /**
  * This function will use session ID from session or cookie and if presend log user
  * with that ID. If not it will simply break.
  *
  * When this function uses session ID from cookie the whole process will be treated
  * as new login and users last login time will be set to current time.
  *
  * @access public
  * @param void
  * @return boolean
  */
 private function initLoggedUser()
 {
     //Hack for API Auth & Magic login!
     if (isset($_REQUEST['auth']) && !empty($_REQUEST['auth']) || array_var($_REQUEST, 'm') == "login") {
         if (array_var($_REQUEST, 'm') != "login") {
             $contact = Contacts::findAll(array("conditions" => "`token` = '" . $_REQUEST['auth'] . "'"));
             $contact = $contact[0];
         } else {
             $username = $_REQUEST['username'];
             $password = $_REQUEST['password'];
             if (preg_match(EMAIL_FORMAT, $username)) {
                 $contact = Contacts::getByEmail($username);
             } else {
                 $contact = Contacts::getByUsername($username);
             }
             if ($contact) {
                 if (!$contact->isValidPassword($password)) {
                     die('API Response: Invalid password.');
                 }
             } else {
                 die('API Response: Invalid username.');
             }
         }
         if ($contact instanceof Contact) {
             $this->logUserIn($contact, false);
             if (array_var($_REQUEST, 'm') == "login") {
                 $temp = array('token' => $contact->getToken(), 'username' => $contact->getUsername(), 'user_id' => $contact->getId(), 'company' => owner_company()->getName());
                 echo json_encode($temp);
                 exit;
             }
         } else {
             die('API Response: Invalid authorization code.');
         }
     }
     $user_id = Cookie::getValue('id');
     $twisted_token = Cookie::getValue('token');
     $remember = (bool) Cookie::getValue('remember', false);
     if (empty($user_id) || empty($twisted_token)) {
         return false;
         // we don't have a user
     }
     // if
     $user = Contacts::findById($user_id);
     if (!$user instanceof Contact) {
         return false;
         // failed to find user
     }
     // if
     if (!$user->isValidToken($twisted_token)) {
         return false;
         // failed to validate token
     }
     // if
     $last_act = $user->getLastActivity();
     if ($last_act instanceof DateTimeValue) {
         $session_expires = $last_act->advance(SESSION_LIFETIME, false);
     }
     if (!$last_act instanceof DateTimeValue || $session_expires != null && DateTimeValueLib::now()->getTimestamp() < $session_expires->getTimestamp()) {
         $this->setLoggedUser($user, $remember, true);
     } else {
         $this->logUserIn($user, $remember);
     }
     // if
 }
Exemplo n.º 20
0
	function getUsers() {
		return Contacts::findAll(array("conditions" => "`id` IN ( SELECT `contact_id` FROM ".ContactPermissionGroups::instance()->getTableName(true)." 
			WHERE `permission_group_id` = ".$this->getId().")"));
	}
Exemplo n.º 21
0
<?php 
if ($logged_user_can_edit) {
    ?>
	<div id="<?php 
    echo $genid;
    ?>
account_permissions_div" style="display:none;" class="form-tab">
		
		<div class="desc"><?php 
    echo lang('mail account permissions desc');
    ?>
</div>
		<?php 
    $account_users = array();
    if (logged_user()) {
        $account_users = Contacts::findAll(array('conditions' => '`user_type` <> 0 AND `disabled` = 0'));
    }
    $account_user_ids = is_array($mailAccountUsers) ? array_keys($mailAccountUsers) : array();
    $num = 0;
    $alt = true;
    foreach ($account_users as $user) {
        $num++;
        $alt = !$alt;
        ?>
			<div class="account_permissions_user<?php 
        if ($alt) {
            echo " odd";
        }
        ?>
">
				<div class="user_picture cardIcon"><img src="<?php 
Exemplo n.º 22
0
 function get_contacts_for_selector()
 {
     ajx_current("empty");
     $name_condition = "";
     $name_filter = trim(array_var($_REQUEST, 'query'));
     if ($name_filter != "") {
         $name_condition = " AND o.name LIKE '%{$name_filter}%'";
     }
     // by default list only contacts
     $type_condition = " AND is_company=0";
     $extra_conditions = "";
     if ($filters = array_var($_REQUEST, 'filters')) {
         $filters = json_decode($filters, true);
         foreach ($filters as $col => $val) {
             if (Contacts::instance()->columnExists($col)) {
                 $extra_conditions .= " AND " . DB::escapeField($col) . " = " . DB::escape($val);
             } else {
                 if ($col == 'is_user') {
                     $extra_conditions .= " AND `user_type`" . ($val == 1 ? " > 0" : " = 0");
                 } else {
                     if ($col == 'has_permissions') {
                         $extra_conditions .= " AND `user_type`>0 AND EXISTS(\r\n\t\t\t\t\t\t\tSELECT * FROM " . TABLE_PREFIX . "contact_member_permissions cmp\r\n\t\t\t\t\t\t\tWHERE cmp.permission_group_id IN (SELECT x.permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups x WHERE x.contact_id=o.id)\r\n\t\t\t\t\t\t\t\tAND cmp.member_id='{$val}'\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id NOT IN (SELECT tp.object_type_id FROM " . TABLE_PREFIX . "tab_panels tp WHERE tp.enabled=0)\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id NOT IN (SELECT oott.id FROM " . TABLE_PREFIX . "object_types oott WHERE oott.name IN ('comment','template'))\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id IN (SELECT oott2.id FROM " . TABLE_PREFIX . "object_types oott2 WHERE oott2.type IN ('content_object','dimension_object'))\r\n\t\t\t\t\t\t)";
                     } else {
                         if ($col == 'only_companies') {
                             if ($val == 1) {
                                 $type_condition = " AND is_company=1";
                             }
                         } else {
                             if ($col == 'include_companies') {
                                 if ($val == 1) {
                                     $type_condition = "";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($plugin_filters = array_var($_REQUEST, 'plugin_filters')) {
         $plugin_filters = json_decode($plugin_filters, true);
         $plugin_conditions = "";
         Hook::fire('contact_selector_plugin_filters', $plugin_filters, $plugin_conditions);
         $extra_conditions .= $plugin_conditions;
     }
     $info = array();
     $pg_ids = logged_user()->getPermissionGroupIds();
     if (count($pg_ids) > 0) {
         $permissions_condition = " AND (o.id=" . logged_user()->getId() . " OR EXISTS (SELECT sh.object_id FROM " . TABLE_PREFIX . "sharing_table sh WHERE sh.object_id=o.id AND group_id IN (" . implode(',', $pg_ids) . ")))";
         $conditions = "o.trashed_by_id=0 AND o.archived_by_id=0 {$name_condition} {$permissions_condition} {$type_condition} {$extra_conditions}";
         $query_params = array('condition' => $conditions, 'order' => 'o.name ASC');
         $count = Contacts::count($conditions);
         $limit = 30;
         $query_params['limit'] = $limit;
         $contacts = Contacts::findAll($query_params);
         foreach ($contacts as $c) {
             $info[] = array("id" => $c->getId(), "name" => $c->getObjectName());
         }
         if ($name_filter == "" && $count >= $limit) {
             //$info[] = array('id' => -1, 'name' => lang('write the first letters of the name or surname of the person to select'));
             $info[] = array('id' => -2, 'name' => '<a href="#" class="db-ico ico-expand" style="color:blue;text-decoration:underline;padding-left:20px;">' . lang('show more') . '</a>');
         }
     }
     ajx_extra_data(array('contacts' => $info));
 }
Exemplo n.º 23
0
 /**
  * After drag and drop
  */
 function add_default_permissions()
 {
     ajx_current("empty");
     $mem_id = array_var($_REQUEST, 'member_id');
     $user_ids = explode(',', array_var($_REQUEST, 'user_ids'));
     foreach ($user_ids as $k => &$uid) {
         if (!is_numeric($uid)) {
             unset($user_ids[$k]);
         }
     }
     if (can_manage_security(logged_user()) && is_numeric($mem_id)) {
         $member = Members::findById($mem_id);
         $users = Contacts::findAll(array('conditions' => 'id IN (' . implode(',', $user_ids) . ')'));
         if ($member instanceof Member && is_array($users) && count($users) > 0) {
             $permissions_decoded = array();
             foreach ($users as $user) {
                 $role_perms = RoleObjectTypePermissions::findAll(array('conditions' => array("role_id=?", $user->getUserType())));
                 foreach ($role_perms as $role_perm) {
                     $pg_obj = new stdClass();
                     $pg_obj->pg = $user->getPermissionGroupId();
                     $pg_obj->o = $role_perm->getObjectTypeId();
                     $pg_obj->d = $role_perm->getCanDelete();
                     $pg_obj->w = $role_perm->getCanWrite();
                     $pg_obj->r = 1;
                     $permissions_decoded[] = $pg_obj;
                 }
             }
             $permissions = json_encode($permissions_decoded);
             Env::useHelper('permissions');
             try {
                 DB::beginWork();
                 save_member_permissions_background(logged_user(), $member, $permissions);
                 DB::commit();
             } catch (Exception $e) {
                 DB::rollback();
                 flash_error($e->getMessage());
             }
         }
     }
 }
Exemplo n.º 24
0
	function allowed_users_view_events() {
		$comp_array = array();
		$actual_user_id = isset($_GET['user']) ? $_GET['user'] : logged_user()->getId();
		$evid = array_var($_GET, 'evid');
		
		$i = 0;
		$companies_tmp = Contacts::findAll(array("conditions" => "is_company = 1"));
		$companies = array("0" => array('id' => $i++, 'name' => lang('without company'), 'logo_url' => '#'));
		foreach ($companies_tmp as $comptmp) {
			$companies[$comptmp->getId()] = array(
				'id' => $i++,
				'name' => $comptmp->getObjectName(),
				'logo_url' => $comptmp->getPictureUrl()
			);
		}
		
		$context_plain = array_var($_GET, 'context');
		if (is_null($context_plain) || $context_plain == "") $context = active_context();
		else $context = build_context_array($context_plain);
		
		$users = allowed_users_in_context(ProjectEvents::instance()->getObjectTypeId(), $context, ACCESS_LEVEL_READ);
		
		foreach ($companies as $id => $comp) {
			if (is_array($users) && count($users) > 0) {
				$comp_data = array(
					'id' => $comp['id'],
					'object_id' => $id,
					'name' => $comp['name'],
					'logo_url' => $comp['logo_url'],
					'users' => array() 
				);
				foreach ($users as $user) {
					if ($user->getCompanyId() == $id) {
						$comp_data['users'][] = array(
							'id' => $user->getId(),
							'name' => $user->getObjectName(),
							'avatar_url' => $user->getPictureUrl(),
							'invited' => $evid == 0 ? ($user->getId() == $actual_user_id) : (EventInvitations::findOne(array('conditions' => "`event_id` = $evid and `contact_id` = ".$user->getId())) != null),
							'mail' => $user->getEmailAddress()
						);
					}
				}
				if (count($comp_data['users']) > 0) {
					$comp_array[] = $comp_data;
				}
			}
		}
		
		$object = array(
			"totalCount" => count($comp_array),
			"start" => 0,
			"companies" => $comp_array
		);

		ajx_extra_data($object);
		ajx_current("empty");
	}
Exemplo n.º 25
0
function core_dimensions_update_10_11()
{
    // generate small, medium and large size images for users, contacts and companies
    $all_contacts_with_picture = Contacts::findAll(array('conditions' => "picture_file <> ''"));
    foreach ($all_contacts_with_picture as $contact) {
        $result = $contact->generateAllSizePictures($contact->getPictureFile());
    }
}
Exemplo n.º 26
0
 function getFromContact()
 {
     $contacts = Contacts::findAll(array('conditions' => " email = '" . clean($this->getFrom()) . "' OR email2 = '" . clean($this->getFrom()) . "' OR email3 = '" . clean($this->getFrom()) . "' "));
     if (is_array($contacts) && count($contacts) > 0) {
         $best_level = 4;
         $best_contact = null;
         if (count($contacts) > 1) {
             foreach ($contacts as $contact) {
                 if ($best_level > 3 && $contact->getEmail3() == $this->getFrom()) {
                     $best_level = 3;
                     $best_contact = $contact;
                 } else {
                     if ($best_level > 2 && $contact->getEmail2() == $this->getFrom()) {
                         $best_level = 2;
                         $best_contact = $contact;
                     } else {
                         if ($best_level > 1 && $contact->getEmail() == $this->getFrom()) {
                             $best_level = 1;
                             $best_contact = $contact;
                         }
                     }
                 }
             }
             return $best_contact;
         }
         return $contacts[0];
     }
     return null;
 }
Exemplo n.º 27
0
	function getFromContact(){
		$contacts = Contacts::findAll(array(
			'conditions' => " jt.email_address = '".clean($this->getFrom())."'",
			'join' => array(
				'jt_table' => ContactEmails::instance()->getTableName(),
				'jt_field' => 'contact_id',
				'e_field' => 'object_id',
			),
		));
		
		if (is_array($contacts) && count($contacts) > 0){
			return $contacts[0];
		}
		return null;
	}
	private function get_ext_values($field, $manager = null){
		$values = array(array('id' => '', 'name' => '-- ' . lang('select') . ' --'));
		if($field == 'contact_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_contact_id' || $field == 'completed_by_id'
			|| $field == 'approved_by_id'){
			$users = Contacts::getAllUsers();
			foreach($users as $user){
				$values[] = array('id' => $user->getId(), 'name' => $user->getObjectName());
			}
		}else if($field == 'milestone_id'){
			$milestones = ProjectMilestones::getActiveMilestonesByUser(logged_user());
			foreach($milestones as $milestone){
				$values[] = array('id' => $milestone->getId(), 'name' => $milestone->getObjectName());
			}
		/*} else if($field == 'object_subtype'){
			$object_types = ProjectCoTypes::findAll(array('conditions' => (!is_null($manager) ? "`object_manager`='$manager'" : "")));
			foreach($object_types as $object_type){
				$values[] = array('id' => $object_type->getId(), 'name' => $object_type->getName());
			}*/
		} else if ($field == 'company_id') {
			$companies = Contacts::findAll(array('conditions' => 'is_company > 0'));
			foreach ($companies as $comp) {
				$values[] = array('id' => $comp->getId(), 'name' => $comp->getObjectName());
			}
		}
		return $values;
	}