/**
 * Render select contact box
 *
 * @param integer $selected ID of selected contact
 * @param array $exclude_contacts Array of IDs of contacts that need to be excluded (already attached to project etc)
 * @param array $attributes Additional attributes
 * @return string
 */
function select_contact($name, $selected = null, $exclude_contacts = null, $attributes = null)
{
    $grouped_contacts = Contacts::getGroupedByCompany();
    $all_options = array(option_tag(lang('none'), 0));
    if (is_array($grouped_contacts)) {
        foreach ($grouped_contacts as $company_name => $contacts) {
            if (is_array($contacts) && is_array($contacts['contacts']) && count($contacts['contacts'])) {
                $options = array();
                foreach ($contacts['contacts'] as $contact) {
                    if (is_array($exclude_contacts) && in_array($contact->getId(), $exclude_contacts)) {
                        continue;
                    }
                    $contact_name = $contact->getDisplayName();
                    if ($contact->isAdministrator()) {
                        $contact_name .= ' (' . lang('administrator') . ')';
                    }
                    $option_attributes = $contact->getId() == $selected ? array('selected' => 'selected') : null;
                    $options[] = option_tag($contact_name, $contact->getId(), $option_attributes);
                }
                // foreach
                if (count($options)) {
                    $all_options[] = option_tag('', 0);
                    // separator
                    $all_options[] = option_group_tag($company_name, $options);
                }
                // if
            }
            // if
        }
        // foreach
    }
    // if
    return select_box($name, $all_options, $attributes);
}
Example #2
0
/**
 * Render assign to SELECT
 * @param string $list_name Name of the select control
 * @param Project $project Selected project, if NULL active project will be used
 * @param integer $selected ID of selected user
 * @param array $attributes Array of select box attributes, if needed
 * @return null
 */ 
function filter_assigned_to_select_box($list_name, $project = null, $selected = null, $attributes = null) {
	$grouped_users = Contacts::getGroupedByCompany(false);
	$options = array(option_tag(lang('anyone'), '0:0'),option_tag(lang('unassigned'), '-1:-1', '-1:-1' == $selected ? array('selected' => 'selected') : null));
	
	if(is_array($grouped_users) && count($grouped_users)) {
		foreach($grouped_users as $company_id => $users) {
			$company = Contacts::findById($company_id);
			if(!($company instanceof Contact)) {
				continue;
			} // if

			$options[] = option_tag('--', '0:0'); // separator

			$option_attributes = $company->getId() . ':0' == $selected ? array('selected' => 'selected') : null;
			$options[] = option_tag($company->getName(), $company_id . ':0', $option_attributes);

			if(is_array($users)) {
				foreach($users as $user) {
					$option_attributes = $company_id . ':' . $user->getId() == $selected ? array('selected' => 'selected') : null;
					$options[] = option_tag($user->getObjectName() . ' : ' . $company->getObjectName() , $company_id . ':' . $user->getId(), $option_attributes);
				} // foreach
			} // if

		} // foreach
	} // if

	return select_box($list_name, $options, $attributes);
} // assign_to_select_box
 /**
  * Show owner company members
  *
  * @access public
  * @param void
  * @return null
  */
 function members()
 {
     if (!can_manage_security(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     tpl_assign('isMemberList', true);
     tpl_assign('company', owner_company());
     tpl_assign('users_by_company', Contacts::getGroupedByCompany());
 }
 function assign_users()
 {
     if (!can_manage_billing(logged_user())) {
         flash_error(lang("no access permissions"));
         ajx_current("empty");
         return;
     }
     $users_data = array_var($_POST, 'users');
     if (is_array($users_data)) {
         try {
             DB::beginWork();
             foreach ($users_data as $user_id => $user_billing) {
                 $user = Contacts::findById($user_id);
                 if ($user_billing != $user->getDefaultBillingId()) {
                     $user->setDefaultBillingId($user_billing);
                     $user->save();
                 }
             }
             DB::commit();
             flash_success(lang("success assign user billing categories"));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
     tpl_assign('users_by_company', Contacts::getGroupedByCompany(false));
     tpl_assign('billing_categories', BillingCategories::findAll());
 }