Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2031

Přidáno uživatelem Michal Kliment před více než 11 roky(ů)

Upravy:
fixes #660: Chyba v js controleru nastaveni
Pridani Honzovych zapomenutych zmen v kontroleru members.

Zobrazit rozdíly:

freenetis/branches/1.1/application/controllers/members.php
*
*/
require_once APPPATH."libraries/vtwsclib/Vtiger/WSClient.php";
/**
* Controller performs members actions such as viewing, editing profile,
* registration export, applicants approval, etc.
......
if (!$hide_grid && $this->acl_check_view(get_class($this), 'members'))
{
// export contacts
$grid->add_new_button(
'export/vcard/members' . server::query_string(),
'Export contacts', array
(
'title' => __('Export contacts'),
'class' => 'popup_link'
)
);
// csv export of members
$grid->add_new_button(
'export/csv/members' . server::query_string(),
......
$view->render(TRUE);
}
} // end of registered function
/**
* Form for approving multiple members
*
......
'members_whitelists/show_by_member/'.$member->id, __('Whitelists')
);
}
// export contacts
$member_links[] = html::anchor(
'export/vcard/' . $member_id . server::query_string(),
__('Export contacts'),
array
(
'title' => __('Export contacts'),
'class' => 'popup_link'
)
);
$member_links[] = html::anchor(
'members/registration_export/'.$member->id,
......
$arr_countries = ORM::factory('country')->select_list('id', 'country_name');
// streets
// loads all streets if GET parametr with name 'street_id' exists.
// otherwise it loads just streets for selected town (request #614)
$arr_streets = array
(
NULL => '--- ' . __('Without street') . ' ---'
) + $member->address_point->town->streets->select_list('id', 'street');
);
if (array_key_exists('street_id', $_GET))
$arr_streets += ORM::factory('street')->select_list('id', 'street');
else
$arr_streets += $member->address_point->town->streets->select_list('id', 'street');
// streets
$arr_domicile_streets = array
(
......
$member->transaction_start();
$member->leaving_date = date('Y-m-d', $form_data['leaving_date']);
// leaving date is in past or today
if ($member->leaving_date <= date('Y-m-d'))
{
......
Devices_Controller::delete_device($device->id);
}
}
// reactivate messages
$member->reactivate_messages();
......
Accounts_Controller::recalculate_member_fees(
$member->get_credit_account()->id
);
// leaving date is in past or today
if ($member->leaving_date <= date('Y-m-d'))
{
......
return $filter_form;
}
/**
* Syncs contacts from FreenetIS to Vtiger CRM.
*
* @author Jan Dubina
*/
public static function vtiger_sync()
{
ini_set('max_execution_time', 3600);
//set size of chucks used to create and update records vie webservice
$chunk_size = 100;
// vtiger web service client
$client = new Vtiger_WSClient(Settings::get('vtiger_domain'));
//login
$login = $client->doLogin(Settings::get('vtiger_username'),
Settings::get('vtiger_user_access_key'));
// if logged in
if ($login)
{
//number of contact (phone and email) fields in vtiger
$contacts_max = 3;
// module names
$module_contacts = 'Contacts';
$module_accounts = 'Accounts';
$user_model = new User_Model();
$member_model = new Member_Model();
// get vtiger field names from settings
$account_fields = json_decode(Settings::get('vtiger_member_fields'), true);
$contact_fields = json_decode(Settings::get('vtiger_user_fields'), true);
//check fields in vtiger - accounts
$accounts_desc = $client->doDescribe($module_accounts);
if (is_array($accounts_desc))
{
$fields = array();
foreach ($accounts_desc['fields'] as $desc)
{
$fields[] = $desc['name'];
// check mandatory fields
if ($desc['mandatory'] == 1 && !in_array($desc['name'], $account_fields) &&
$desc['name'] != 'assigned_user_id')
throw new Exception(__('Error - wrong vtiger fields settings'));
}
foreach ($account_fields as $field)
if (!in_array($field, $fields))
throw new Exception(__('Error - wrong vtiger fields settings'));
}
else
throw new Exception(__('Error - vtiger webservice not responding'));
//check fields in vtiger - contacts
$contacts_desc = $client->doDescribe($module_contacts);
if(is_array($contacts_desc))
{
$fields = array();
foreach ($contacts_desc['fields'] as $desc)
{
$fields[] = $desc['name'];
//check mandatory fields
if ($desc['mandatory'] == 1 && !in_array($desc['name'], $contact_fields) &&
$desc['name'] != 'assigned_user_id')
throw new Exception(__('Error - wrong vtiger fields settings'));
}
foreach ($contact_fields as $field)
if (!in_array($field, $fields))
throw new Exception(__('Error - wrong vtiger fields settings'));
}
else
throw new Exception(__('Error - vtiger webservice not responding'));
// create new accounts
// get member ids from vtiger
$query = 'SELECT id,' . $account_fields['id'] . ' FROM ' . $module_accounts;
$accounts_create_ids = array();
$result = $client->doQueryNotLimited($query);
if(is_array($result))
{
// array with links between vtiger ids and fntis ids
$links = array();
foreach ($result as $value) {
$links[$value['id']] = $value[$account_fields['id']];
}
$vtiger_ids = array_values($links);
// get member ids from freenetis
$result = $member_model->select_list('id');
$freenetis_ids = array();
foreach ($result as $key => $value) {
$freenetis_ids[] = $key;
}
// ids of members that need to be created
$accounts_create_ids = array_unique(array_filter(array_diff($freenetis_ids, $vtiger_ids)));
//if there are members to be created
if(!empty($accounts_create_ids))
{
$accounts_create = $member_model->get_members_to_sync_vtiger($accounts_create_ids, true);
$accounts_create_vtiger = array();
foreach ($accounts_create as $account)
{
$acc_arr = array();
$acc_arr[$account_fields['id']] = $account->id;
$acc_arr[$account_fields['name']] = $account->name;
$acc_arr[$account_fields['acc_type']] = 'Customer';
$acc_arr[$account_fields['entrance_date']] = strtotime($account->entrance_date);
$acc_arr[$account_fields['organization_identifier']] = $account->organization_identifier;
$acc_arr[$account_fields['var_sym']] = $account->variable_symbol;
$acc_arr[$account_fields['type']] = Member_Model::get_type($account->type);
$acc_arr[$account_fields['street']] = address::street_join($account->street,
$account->street_number);
$acc_arr[$account_fields['town']] = $account->town;
$acc_arr[$account_fields['country']] = $account->country_name;
$acc_arr[$account_fields['zip_code']] = $account->zip_code;
$acc_arr[$account_fields['employees']] = $account->employees;
$acc_arr[$account_fields['do_not_send_emails']] = false;
$acc_arr[$account_fields['notify_owner']] = true;
$acc_arr[$account_fields['comment']] = $account->comment;
$phone = explode(';', $account->phone);
for ($i = 0; $i<$contacts_max; $i++)
{
$key = 'phone' . ($i + 1);
if(array_key_exists($i, $phone))
$acc_arr[$account_fields[$key]] = $phone[$i];
}
$email = explode(';', $account->email);
for ($i = 0; $i<$contacts_max; $i++)
{
$key = 'email' . ($i + 1);
if(array_key_exists($i, $email))
$acc_arr[$account_fields[$key]] = $email[$i];
}
$accounts_create_vtiger[] = $acc_arr;
}
if (count($accounts_create_vtiger) > $chunk_size)
{
$create_arrays = array_chunk($accounts_create_vtiger, $chunk_size);
foreach ($create_arrays as $create_array)
{
$records = $client->doCreateBulk($module_accounts, $create_array);
if(is_array($records))
foreach ($records as $record)
if (array_key_exists($account_fields['id'], $record))
$links[$record['id']] = $record[$account_fields['id']];
}
}
else
{
$records = $client->doCreateBulk($module_accounts, $accounts_create_vtiger);
//create array with links between freenetis ID and vtiger ID
if(is_array($records))
foreach ($records as $record)
if (array_key_exists($account_fields['id'], $record))
$links[$record['id']] = $record[$account_fields['id']];
}
}
}
// create new contacts
// get user ids from vtiger
$query = 'SELECT ' . $contact_fields['id'] . ' FROM ' . $module_contacts;
$contacts_create_ids = array();
$result = $client->doQueryNotLimited($query);
if(is_array($result) && isset($links))
{
$vtiger_ids = array();
foreach ($result as $value) {
$vtiger_ids[] = $value[$contact_fields['id']];
}
//get member ids from freenetis
$result = $user_model->select_list('id');
$freenetis_ids = array();
foreach ($result as $key => $value)
$freenetis_ids[] = $key;
// ids of users that need to be created
$contacts_create_ids = array_unique(array_filter(array_diff($freenetis_ids, $vtiger_ids)));
//if there are users to be created
if(!empty($contacts_create_ids))
{
$contacts_create = $user_model->get_users_to_sync_vtiger($contacts_create_ids, true);
$contacts_create_vtiger = array();
foreach ($contacts_create as $contact)
{
$con_arr = array();
$con_arr[$contact_fields['id']] = $contact->id;
$con_arr[$contact_fields['name']] = $contact->name;
$con_arr[$contact_fields['middle_name']] = $contact->middle_name;
$con_arr[$contact_fields['surname']] = $contact->surname;
$con_arr[$contact_fields['pre_title']] = $contact->pre_title;
$con_arr[$contact_fields['post_title']] = $contact->post_title;
$con_arr[$contact_fields['birthday']] = date("d-m-Y", strtotime($contact->birthday));
$con_arr[$contact_fields['comment']] = $contact->comment;
$con_arr[$contact_fields['street']] = address::street_join($contact->street,
$contact->street_number);
$con_arr[$contact_fields['town']] = $contact->town;
$con_arr[$contact_fields['zip_code']] = $contact->zip_code;
$con_arr[$contact_fields['country']] = $contact->country_name;
$con_arr[$contact_fields['do_not_call']] = false;
$con_arr[$contact_fields['do_not_send_emails']] = false;
$con_arr[$contact_fields['notify_owner']] = true;
// try to link member and user record
$key = array_search($contact->member_id, $links);
if(!empty($key))
$con_arr[$contact_fields['member_id']] = $key;
else
{
// create new array with links
$query = 'SELECT id,' . $account_fields['id'] . ' FROM ' . $module_accounts;
$result = $client->doQueryNotLimited($query);
if(is_array($result))
{
$links = array();
foreach ($result as $value) {
$links[$value['id']] = $value[$account_fields['id']];
}
}
}
$phone = explode(';', $contact->phone);
for ($i = 0; $i<$contacts_max; $i++)
{
$key = 'phone' . ($i + 1);
if(array_key_exists($i, $phone))
$con_arr[$contact_fields[$key]] = $phone[$i];
}
$email = explode(';', $contact->email);
for ($i = 0; $i<$contacts_max; $i++)
{
$key = 'email' . ($i + 1);
if(array_key_exists($i, $email))
$con_arr[$contact_fields[$key]] = $email[$i];
}
$contacts_create_vtiger[] = $con_arr;
}
if (count($contacts_create_vtiger) > $chunk_size)
{
$create_arrays = array_chunk($contacts_create_vtiger, $chunk_size);
foreach ($create_arrays as $create_array)
$records = $client->doCreateBulk($module_contacts, $create_array);
}
else
{
$records = $client->doCreateBulk($module_contacts, $contacts_create_vtiger);
}
}
}
// delete users
$contacts_delete_ids = array_unique(array_filter(array_diff($vtiger_ids, $freenetis_ids)));
if (!empty($contacts_delete_ids))
{
$query = 'SELECT id FROM ' . $module_contacts . ' WHERE ' .
$contact_fields['id'] . ' IN (' .
implode(',', $contacts_delete_ids) . ')';
$results = $client->doQueryNotLimited($query);
if(is_array($results))
foreach ($results as $result)
$client->doDelete($result['id']);
}
// update accounts
$accounts_update = $member_model->get_members_to_sync_vtiger($accounts_create_ids, false);
if($accounts_update->count() != 0)
{
$query = 'SELECT * FROM ' . $module_accounts;
$results = $client->doQueryNotLimited($query);
if(is_array($results))
{
$accounts_update_vtiger = array();
// "NOT IN" statement not working in vtiger ws query
foreach ($results as $result)
if (!in_array($result[$account_fields['id']], $accounts_create_ids))
$accounts_update_vtiger[$result[$account_fields['id']]] = $result;
$update = array();
foreach ($accounts_update as $record)
{
$record_vtiger = $accounts_update_vtiger[$record->id];
if ($record->name != $record_vtiger[$account_fields['name']])
$record_vtiger[$account_fields['name']] = $record->name;
if ($record->organization_identifier != $record_vtiger[$account_fields['organization_identifier']])
$record_vtiger[$account_fields['organization_identifier']] = $record->organization_identifier;
if ($record->entrance_date != $record_vtiger[$account_fields['entrance_date']] &&
!(empty($record->entrance_date) && $record_vtiger[$account_fields['entrance_date']] == '1970-01-01'))
$record_vtiger[$account_fields['entrance_date']] = $record->entrance_date;
if ($record->variable_symbol != $record_vtiger[$account_fields['var_sym']])
$record_vtiger[$account_fields['var_sym']] = $record->variable_symbol;
if (Member_Model::get_type($record->type) != $record_vtiger[$account_fields['type']])
$record_vtiger[$account_fields['type']] = Member_Model::get_type($record->type);
$street = address::street_join($record->street, $record->street_number);
if ($street != $record_vtiger[$account_fields['street']])
$record_vtiger[$account_fields['street']] = $street;
if ($record->town != $record_vtiger[$account_fields['town']])
$record_vtiger[$account_fields['town']] = $record->town;
if ($record->country_name != $record_vtiger[$account_fields['country']])
$record_vtiger[$account_fields['country']] = $record->country_name;
if ($record->zip_code != $record_vtiger[$account_fields['zip_code']])
$record_vtiger[$account_fields['zip_code']] = $record->zip_code;
if ($record->employees != $record_vtiger[$account_fields['employees']])
$record_vtiger[$account_fields['employees']] = $record->employees;
if ($record->comment != $record_vtiger[$account_fields['comment']])
$record_vtiger[$account_fields['comment']] = $record->comment;
// update contact information - phone
$phone = explode(';', $record->phone);
$phone_vtiger = array(
$accounts_update_vtiger[$record->id][$account_fields['phone1']],
$accounts_update_vtiger[$record->id][$account_fields['phone2']],
$accounts_update_vtiger[$record->id][$account_fields['phone3']]
);
$phone_vtiger_orig = $phone_vtiger;
$phone_vtiger = array_filter($phone_vtiger);
$add_phone_nos = array_diff($phone, $phone_vtiger);
$phone_diff = array_diff($phone_vtiger, $phone);
if (!empty($phone_diff) || !empty($add_phone_nos))
{
if (!empty($phone_diff))
foreach($phone_diff as $key => $value)
unset($phone_vtiger[$key]);
if (!empty($add_phone_nos) && (count($phone_vtiger) < $contacts_max))
foreach($add_phone_nos as $phone_no)
if (count($phone_vtiger) < $contacts_max)
$phone_vtiger[] = $phone_no;
$new_phone_nos = array_values(array_diff($phone_vtiger, array_filter($phone_vtiger_orig)));
for ($i = 0; $i < $contacts_max; $i++)
{
if (!in_array($phone_vtiger_orig[$i], $phone_vtiger))
{
if (!empty($new_phone_nos))
{
$record_vtiger[$account_fields['phone'.($i+1)]] = $new_phone_nos[0];
unset($new_phone_nos[0]);
$new_phone_nos = array_values($new_phone_nos);
}
else
$record_vtiger[$account_fields['phone'.($i+1)]] = '';
}
}
}
// update contact information - email
$email = explode(';', $record->email);
$email_vtiger = array(
$accounts_update_vtiger[$record->id][$account_fields['email1']],
$accounts_update_vtiger[$record->id][$account_fields['email2']],
$accounts_update_vtiger[$record->id][$account_fields['email3']]
);
$email_vtiger_orig = $email_vtiger;
$email_vtiger = array_filter($email_vtiger);
$add_emails = array_diff($email, $email_vtiger);
$email_diff = array_diff($email_vtiger, $email);
if (!empty($email_diff) || !empty($add_emails))
{
if (!empty($email_diff))
foreach($email_diff as $key => $value)
unset($email_vtiger[$key]);
if (!empty($add_emails) && (count($email_vtiger) < $contacts_max))
foreach($add_emails as $emails)
if (count($email_vtiger) < $contacts_max)
$email_vtiger[] = $emails;
$new_emails = array_values(array_diff($email_vtiger, $email_vtiger_orig));
for ($i = 0; $i < $contacts_max; $i++)
{
if (!in_array($email_vtiger_orig[$i], $email_vtiger))
{
if (!empty($new_emails))
{
$record_vtiger[$account_fields['email'.($i+1)]] = $new_emails[0];
unset($new_emails[0]);
$new_emails = array_values($new_emails);
}
else
$record_vtiger[$account_fields['email'.($i+1)]] = '';
}
}
}
// checks if original and updated records are different
$update_diff = array_diff($record_vtiger, $accounts_update_vtiger[$record->id]);
if (!empty($update_diff))
$update[] = $record_vtiger;
}
if (count($update) > $chunk_size)
{
$create_arrays = array_chunk($update, $chunk_size);
foreach ($create_arrays as $create_array)
$client->doUpdateBulk($module_accounts, $create_array);
}
else
{
$client->doUpdateBulk($module_accounts, $update);
}
}
}
//update contacts
$contacts_update = $user_model->get_users_to_sync_vtiger($contacts_create_ids, false);
if ($contacts_update->count() != 0)
{
$query = 'SELECT * FROM ' . $module_contacts;
$results = $client->doQueryNotLimited($query);
if(is_array($results))
{
$contacts_update_vtiger = array();
// "NOT IN" statement not working in vtiger ws query
foreach ($results as $result)
if (!in_array($result[$contact_fields['id']], $contacts_create_ids))
$contacts_update_vtiger[$result[$contact_fields['id']]] = $result;
$update = array();
foreach ($contacts_update as $record)
{
$record_vtiger = $contacts_update_vtiger[$record->id];
if ($record->name != $record_vtiger[$contact_fields['name']])
$record_vtiger[$contact_fields['name']] = $record->name;
if ($record->middle_name != $record_vtiger[$contact_fields['middle_name']])
$record_vtiger[$contact_fields['middle_name']] = $record->middle_name;
if ($record->surname != $record_vtiger[$contact_fields['surname']])
$record_vtiger[$contact_fields['surname']] = $record->surname;
if ($record->pre_title != $record_vtiger[$contact_fields['pre_title']])
$record_vtiger[$contact_fields['pre_title']] = $record->pre_title;
if ($record->post_title != $record_vtiger[$contact_fields['post_title']])
$record_vtiger[$contact_fields['post_title']] = $record->post_title;
if ($record->birthday != $record_vtiger[$contact_fields['birthday']] &&
!(empty($record->birthday) && $record_vtiger[$contact_fields['birthday']] == '1970-01-01'))
$record_vtiger[$contact_fields['birthday']] = $record->birthday;
if ($record->comment != $record_vtiger[$contact_fields['comment']])
$record_vtiger[$contact_fields['comment']] = $record->comment;
$street = address::street_join($record->street, $record->street_number);
if ($street != $record_vtiger[$contact_fields['street']])
$record_vtiger[$contact_fields['street']] = $street;
if ($record->town != $record_vtiger[$contact_fields['town']])
$record_vtiger[$contact_fields['town']] = $record->town;
if ($record->zip_code != $record_vtiger[$contact_fields['zip_code']])
$record_vtiger[$contact_fields['zip_code']] = $record->zip_code;
if ($record->country_name != $record_vtiger[$contact_fields['country']])
$record_vtiger[$contact_fields['country']] = $record->country_name;
if ($record->member_id != $links[$record_vtiger[$contact_fields['member_id']]])
{
$key = array_search ($record->member_id, $links);
if(!empty($key))
$record_vtiger[$contact_fields['member_id']] = $key;
}
//update contact information - phone
$phone = explode(';', $record->phone);
$phone_vtiger = array(
$contacts_update_vtiger[$record->id][$contact_fields['phone1']],
$contacts_update_vtiger[$record->id][$contact_fields['phone2']],
$contacts_update_vtiger[$record->id][$contact_fields['phone3']]
);
$phone_vtiger_orig = $phone_vtiger;
$phone_vtiger = array_filter($phone_vtiger);
$add_phone_nos = array_diff($phone, $phone_vtiger);
$phone_diff = array_diff($phone_vtiger, $phone);
if (!empty($phone_diff) || !empty($add_phone_nos))
{
if (!empty($phone_diff))
foreach($phone_diff as $key => $value)
unset($phone_vtiger[$key]);
if (!empty($add_phone_nos) && (count($phone_vtiger) < $contacts_max))
foreach($add_phone_nos as $phone_no)
if (count($phone_vtiger) < $contacts_max)
$phone_vtiger[] = $phone_no;
$new_phone_nos = array_values(array_diff($phone_vtiger, array_filter($phone_vtiger_orig)));
for ($i = 0; $i < $contacts_max; $i++)
{
if (!in_array($phone_vtiger_orig[$i], $phone_vtiger))
{
if (!empty($new_phone_nos))
{
$record_vtiger[$contact_fields['phone'.($i+1)]] = $new_phone_nos[0];
unset($new_phone_nos[0]);
$new_phone_nos = array_values($new_phone_nos);
}
else
$record_vtiger[$contact_fields['phone'.($i+1)]] = '';
}
}
}
//update contact information - email
$email = explode(';', $record->email);
$email_vtiger = array(
$contacts_update_vtiger[$record->id][$contact_fields['email1']],
$contacts_update_vtiger[$record->id][$contact_fields['email2']],
$contacts_update_vtiger[$record->id][$contact_fields['email3']]
);
$email_vtiger_orig = $email_vtiger;
$email_vtiger = array_filter($email_vtiger);
$add_emails = array_diff($email, $email_vtiger);
$email_diff = array_diff($email_vtiger, $email);
if (!empty($email_diff) || !empty($add_emails))
{
if (!empty($email_diff))
foreach($email_diff as $key => $value)
unset($email_vtiger[$key]);
if (!empty($add_emails) && (count($email_vtiger) < $contacts_max))
foreach($add_emails as $emails)
if (count($email_vtiger) < $contacts_max)
$email_vtiger[] = $emails;
$new_emails = array_values(array_diff($email_vtiger, $email_vtiger_orig));
for ($i = 0; $i < $contacts_max; $i++)
{
if (!in_array($email_vtiger_orig[$i], $email_vtiger))
{
if (!empty($new_emails))
{
$record_vtiger[$contact_fields['email'.($i+1)]] = $new_emails[0];
unset($new_emails[0]);
$new_emails = array_values($new_emails);
}
else
$record_vtiger[$contact_fields['email'.($i+1)]] = '';
}
}
}
// checks if original and updated records are different
$update_diff = array_diff($record_vtiger, $contacts_update_vtiger[$record->id]);
if (!empty($update_diff))
$update[] = $record_vtiger;
}
if (count($update) > $chunk_size)
{
$create_arrays = array_chunk($update, $chunk_size);
foreach ($create_arrays as $create_array)
$client->doUpdateBulk($module_contacts, $create_array);
}
else
{
$client->doUpdateBulk($module_contacts, $update);
}
}
}
}
else
{
//login failed
throw new Exception(__('Connection to vtiger server has failed'));
}
}
}
freenetis/branches/1.1/application/controllers/settings.php
{
private $links;
/**
* Definitions of modules and their dependencies
*
* @author Michal Kliment
* @var array
*/
public static $modules = array
(
'allowed_subnets' => array
(
'name' => 'allowed_subnets_enabled',
'dependencies' => array('redirection')
),
'approval' => array
(
'name' => 'approval_enabled',
'dependencies' => array()
),
'connection_request' => array
(
'name' => 'connection_request_enable',
'dependencies' => array('networks'),
),
'email' => array
(
'name' => 'email_enabled',
'dependencies' => array()
),
'finance' => array
(
'name' => 'finance_enabled',
'dependencies' => array()
),
'forgotten_password' => array
(
'name' => 'forgotten_password',
'dependencies' => array('email')
),
'membership_interrupt' => array
(
'name' => 'membership_interrupt_enabled',
'dependencies' => array()
),
'monitoring' => array
(
'name' => 'monitoring_enabled',
'dependencies' => array('networks')
),
'networks' => array
(
'name' => 'networks_enabled',
'dependencies' => array()
),
'phone_invoices' => array
(
'name' => 'users_enabled',
'dependencies' => array()
),
'qos' => array
(
'name' => 'qos_enabled',
'dependencies' => array()
),
'redirection' => array
(
'name' => 'redirection_enabled',
'dependencies' => array('networks')
),
'self_registration' => array
(
'name' => 'self_registration',
'dependencies' => array()
),
'sms' => array
(
'name' => 'sms_enabled',
'dependencies' => array()
),
'ulogd' => array
(
'name' => 'ulogd_enabled',
'dependencies' => array('networks')
),
'users' => array
(
'name' => 'users_enabled',
'dependencies' => array()
),
'voip' => array
(
'name' => 'voip_enabled',
'dependencies' => array()
),
'vtiger' => array
(
'name' => 'vtiger_integration',
'dependencies' => array()
),
'works' => array
(
'name' => 'works_enabled',
'dependencies' => array('approval')
),
);
/**
* Test whether module is enabled
*
* @author Michal Kliment
* @param type $module
* @return type
* @throws Exception
*/
private static function isModuleEnabled($module)
{
if (isset(self::$modules[$module]['name']))
return Settings::get(self::$modules[$module]['name']);
else
throw new Exception('Unknown module: '.$module);
}
/**
* Disable given module
*
* @author Michal Kliment
* @param type $module
* @return type
* @throws Exception
*/
private static function disableModule($module)
{
if (isset(self::$modules[$module]['name']))
return Settings::set(self::$modules[$module]['name'], 0);
else
throw new Exception('Unknown module: '.$module);
}
/**
* Contruct of controller sets tabs names
......
$this->sections['users'] = __('Users');
// are finance enabled
if (Settings::get('finance_enabled'))
if (self::isModuleEnabled('finance'))
$this->sections['finance'] = __('Finance');
// is approval enabled
if (Settings::get('approval_enabled'))
if (self::isModuleEnabled('approval'))
$this->sections['approval'] = __('Approval');
// are networks enabled
if (Settings::get('networks_enabled'))
if (self::isModuleEnabled('networks'))
$this->sections['networks'] = __('Networks');
if (Settings::get('email_enabled'))
if (self::isModuleEnabled('email'))
$this->sections['email'] = __('Email');
// are SMS enabled
if (Settings::get('sms_enabled'))
if (self::isModuleEnabled('sms'))
$this->sections['sms'] = __('SMS');
// is voip enabled
if (Settings::get('voip_enabled'))
if (self::isModuleEnabled('voip'))
$this->sections['voip'] = __('VoIP');
$this->sections['notifications'] = __('Notifications');
// is QoS enabled
if (Settings::get('qos_enabled'))
if (self::isModuleEnabled('qos'))
$this->sections['qos'] = __('QoS');
// is monitoring enabled
if (Settings::get('monitoring_enabled'))
if (self::isModuleEnabled('monitoring'))
$this->sections['monitoring'] = __('Monitoring');
// is vtiger integration enabled
if (self::isModuleEnabled('vtiger'))
$this->sections['vtiger'] = __('Vtiger');
$this->sections['logging'] = __('Logging');
}
}
......
// creating of new forge
$this->form = new Forge('settings/system');
$this->form->set_attr('id', 'settings-system-form');
$this->form->group('System variables');
......
->options(arr::bool())
->default(Settings::get('grid_hide_on_first_load'))
->help('grid_hide_on_first_load');
$form_modules = array();
$this->form->group(__('Modules').' '.help::hint('modules'));;
$this->form->group(__('Modules').' '.help::hint('modules'));
// self-registration
$this->form->radio('self_registration')
$form_modules['self_registration'] = $this->form->radio('self_registration')
->label('Self-registration')
->options(arr::bool())
->default(Settings::get('self_registration'));
// connection requests
$this->form->radio('connection_request_enable')
$form_modules['connection_request'] = $this->form->radio('connection_request_enable')
->label('Connection requests')
->options(arr::bool())
->default(Settings::get('connection_request_enable'));
// forgotten password
$this->form->radio('forgotten_password')
$form_modules['forgotten_password'] = $this->form->radio('forgotten_password')
->label('Forgotten password')
->options(arr::bool())
->default(Settings::get('forgotten_password'));
// membership interrupts
$this->form->radio('membership_interrupt_enabled')
$form_modules['membership_interrupt'] = $this->form->radio('membership_interrupt_enabled')
->label('Membership interrupt')
->options(arr::bool())
->default(Settings::get('membership_interrupt_enabled'));
// finance
$this->form->radio('finance_enabled')
$form_modules['finance'] = $this->form->radio('finance_enabled')
->label('Finance')
->options(arr::bool())
->default(Settings::get('finance_enabled'));
// approval
$this->form->radio('approval_enabled')
$form_modules['approval'] = $this->form->radio('approval_enabled')
->label('Approval')
->options(arr::bool())
->default(Settings::get('approval_enabled'));
// Works
$this->form->radio('works_enabled')
$form_modules['works'] = $this->form->radio('works_enabled')
->label('Works')
->options(arr::bool())
->default(Settings::get('works_enabled'));
// Phone invoice
$this->form->radio('phone_invoices_enabled')
$form_modules['phone_invoices'] = $this->form->radio('phone_invoices_enabled')
->label('Phone invoices')
->options(arr::bool())
->default(Settings::get('phone_invoices_enabled'));
// e-mail
$this->form->radio('email_enabled')
$form_modules['email'] = $this->form->radio('email_enabled')
->label('E-mail')
->options(arr::bool())
->default(Settings::get('email_enabled'));
// SMS
$this->form->radio('sms_enabled')
$form_modules['sms'] = $this->form->radio('sms_enabled')
->label('SMS')
->options(arr::bool())
->default(Settings::get('sms_enabled'));
// VoIP
$this->form->radio('voip_enabled')
$form_modules['voip'] = $this->form->radio('voip_enabled')
->label('VoIP')
->options(arr::bool())
->default(Settings::get('voip_enabled'));
// Network
$this->form->radio('networks_enabled')
$form_modules['networks'] = $this->form->radio('networks_enabled')
->label('Networks')
->options(arr::bool())
->default(Settings::get('networks_enabled'));
// QoS
$this->form->radio('qos_enabled')
$form_modules['qos'] = $this->form->radio('qos_enabled')
->label('QoS')
->options(arr::bool())
->default(Settings::get('qos_enabled'));
// Monitoring
$this->form->radio('monitoring_enabled')
$form_modules['monitoring'] = $this->form->radio('monitoring_enabled')
->label('Monitoring')
->options(arr::bool())
->default(Settings::get('monitoring_enabled'));
// Redirection
$this->form->radio('redirection_enabled')
$form_modules['redirection'] = $this->form->radio('redirection_enabled')
->label('Redirection')
->options(arr::bool())
->default(Settings::get('redirection_enabled'));
// vtiger CRM integration
$form_modules['vtiger'] = $this->form->radio('vtiger_integration')
->label('Vtiger integration')
->options(arr::bool())
->default(Settings::get('vtiger_integration'));
// add info about modules dependencies
foreach ($form_modules as $module => $item)
{
// module have at least one dependency
if (count(self::$modules[$module]['dependencies']))
{
$form_modules[$module]->additional_info(
__('Require module') . ': <b>' .
implode(', ', array_map(
'__', self::$modules[$module]['dependencies'])
) . '</b>'
);
}
}
$this->form->group('Module settings');
$timeout = Settings::get('module_status_timeout');
......
$issaved = $issaved && Settings::set($name, $value);
}
// without networks disabled monitoring, ulogd, connection request and redirection
if (!Settings::get('networks_enabled'))
foreach (self::$modules as $module => $module_info)
{
Settings::set('monitoring_enabled', FALSE);
Settings::set('ulogd_enabled', FALSE);
Settings::set('connection_request_enable', FALSE);
Settings::set('redirection_enabled', FALSE);
foreach ($module_info['dependencies'] as $dependency)
{
if (self::isModuleEnabled($module) && !self::isModuleEnabled($dependency))
{
status::error(__('Cannot enable module %s, enabled module %s is required.', array($module, $dependency)));
self::disableModule($module);
break;
}
}
}
// without redirection allowed subnet cannot be enabled
if (!Settings::get('redirection_enabled'))
{
Settings::set('allowed_subnets_enabled', FALSE);
}
// without approval works cannot be enabled
if (!Settings::get('approval_enabled'))
{
Settings::set('works_enabled', FALSE);
}
// without email forgotten password cannot be enabled
if (!Settings::get('email_enabled'))
{
Settings::set('forgotten_password', FALSE);
}
if ($issaved)
// if all action were succesfull
{
......
$view->render(TRUE);
}
/**
* Form to set up vtiger variables
*
* @author Jan Dubina
*/
public function vtiger()
{
// access control
if (!$this->acl_check_edit('Settings_Controller', 'system'))
Controller::error(ACCESS);
$values_member = json_decode(Settings::get('vtiger_member_fields'), true);
$values_user = json_decode(Settings::get('vtiger_user_fields'), true);
// creating of new forge
$this->form = new Forge();
$this->form->group('Vtiger integration');
$this->form->input('vtiger_domain')
->label('Domain')
->rules('valid_url|required')
->value(Settings::get('vtiger_domain'));
$this->form->input('vtiger_username')
->label('Username')
->rules('required')
->value(Settings::get('vtiger_username'));
$this->form->input('vtiger_user_access_key')
->label('User access key')
->rules('required')
->value(Settings::get('vtiger_user_access_key'));
$this->form->group(__('Vtiger field names').' - '.__('Accounts'));
$this->form->input('member_id')
->label('FreenetIS ID')
->rules('required')
->value($values_member['id']);
$this->form->input('member_name')
->rules('required')
->value($values_member['name']);
$this->form->input('member_acc_type')
->label('Account type')
->rules('required')
->value($values_member['acc_type']);
$this->form->input('member_employees')
->label('Employees')
->rules('required')
->value($values_member['employees']);
$this->form->input('member_type')
->label('Type')
->rules('required')
->value($values_member['type']);
$this->form->input('member_entrance_date')
->label('Entrance date')
->rules('required')
->value($values_member['entrance_date']);
$this->form->input('member_var_sym')
->label('Variable symbol')
->rules('required')
->value($values_member['var_sym']);
$this->form->input('member_organization_identifier')
->label('Organization identifier')
->rules('required')
->value($values_member['organization_identifier']);
$this->form->input('member_do_not_send_emails')
->label('Do not send emails')
->rules('required')
->value($values_member['do_not_send_emails']);
$this->form->input('member_notify_owner')
->label('notify owner')
->rules('required')
->value($values_member['notify_owner']);
$this->form->input('member_phone1')
->label('Phone')
->rules('required')
->value($values_member['phone1']);
$this->form->input('member_phone2')
->label(__('Phone').' 2')
->rules('required')
->value($values_member['phone2']);
$this->form->input('member_phone3')
->label(__('Phone').' 3')
->rules('required')
->value($values_member['phone3']);
$this->form->input('member_email1')
->label('Email')
->rules('required')
->value($values_member['email1']);
$this->form->input('member_email2')
->label(__('Email').' 2')
->rules('required')
->value($values_member['email2']);
$this->form->input('member_email3')
->label(__('Email').' 3')
->rules('required')
->value($values_member['email3']);
$this->form->input('member_street')
->label('Street')
->rules('required')
->value($values_member['street']);
$this->form->input('member_town')
->label('Town')
->rules('required')
->value($values_member['town']);
$this->form->input('member_country')
->label('Country')
->rules('required')
->value($values_member['country']);
$this->form->input('member_zip_code')
->label('Zip code')
->rules('required')
->value($values_member['zip_code']);
$this->form->input('member_comment')
->label('Comment')
->rules('required')
->value($values_member['comment']);
$this->form->group(__('Vtiger field names').' - '.__('Contacts'));
$this->form->input('user_id')
->label('FreenetIS ID')
->rules('required')
->value($values_user['id']);
$this->form->input('user_name')
->label('Name')
->rules('required')
->value($values_user['name']);
$this->form->input('user_middle_name')
->label('Middle name')
->rules('required')
->value($values_user['middle_name']);
$this->form->input('user_surname')
->label('surname')
->rules('required')
->value($values_user['surname']);
$this->form->input('user_pre_title')
->label('Pre title')
->rules('required')
->value($values_user['pre_title']);
$this->form->input('user_post_title')
->label('Post title')
->rules('required')
->value($values_user['post_title']);
$this->form->input('user_member_id')
->label('Member ID')
->rules('required')
->value($values_user['member_id']);
$this->form->input('user_birthday')
->label('Birthday')
->rules('required')
->value($values_user['birthday']);
$this->form->input('user_do_not_call')
->label('Do not call')
->rules('required')
->value($values_user['do_not_call']);
$this->form->input('user_do_not_send_emails')
->label('Do not send emails')
->rules('required')
->value($values_user['do_not_send_emails']);
$this->form->input('user_notify_owner')
->label('Notify owner')
->rules('required')
->value($values_user['notify_owner']);
$this->form->input('user_phone1')
->label('Phone')
->rules('required')
->value($values_user['phone1']);
$this->form->input('user_phone2')
->label(__('Phone').' 2')
->rules('required')
->value($values_user['phone2']);
$this->form->input('user_phone3')
->label(__('Phone').' 3')
->rules('required')
->value($values_user['phone3']);
$this->form->input('user_email1')
->label('Email')
->rules('required')
->value($values_user['email1']);
$this->form->input('user_email2')
->label(__('Email').' 2')
->rules('required')
->value($values_user['email2']);
$this->form->input('user_email3')
->label(__('Email').' 3')
->rules('required')
->value($values_user['email3']);
$this->form->input('user_street')
->label('Street')
->rules('required')
->value($values_user['street']);
$this->form->input('user_town')
->label('Town')
->rules('required')
->value($values_user['town']);
$this->form->input('user_country')
->label('Country')
->rules('required')
->value($values_user['country']);
$this->form->input('user_zip_code')
->label('Zip code')
->rules('required')
->value($values_user['zip_code']);
$this->form->input('user_comment')
->label('Comment')
->rules('required')
->value($values_user['comment']);
$this->form->submit('Save');
// form validate
if ($this->form->validate())
{
$form_data = $this->form->as_array();
$values_member['id'] = $form_data['member_id'];
$values_member['name'] = $form_data['member_name'];
$values_member['acc_type'] = $form_data['member_acc_type'];
$values_member['employees'] = $form_data['member_employees'];
$values_member['type'] = $form_data['member_type'];
$values_member['entrance_date'] = $form_data['member_entrance_date'];
$values_member['var_sym'] = $form_data['member_var_sym'];
$values_member['organization_identifier'] = $form_data['member_organization_identifier'];
$values_member['do_not_send_emails'] = $form_data['member_do_not_send_emails'];
$values_member['notify_owner'] = $form_data['member_notify_owner'];
$values_member['phone1'] = $form_data['member_phone1'];
$values_member['phone2'] = $form_data['member_phone2'];
$values_member['phone3'] = $form_data['member_phone3'];
$values_member['email1'] = $form_data['member_email1'];
$values_member['email2'] = $form_data['member_email2'];
$values_member['email3'] = $form_data['member_email3'];
$values_member['street'] = $form_data['member_street'];
$values_member['town'] = $form_data['member_town'];
$values_member['country'] = $form_data['member_country'];
$values_member['zip_code'] = $form_data['member_zip_code'];
$values_member['comment'] = $form_data['member_comment'];
$values_user['id'] = $form_data['user_id'];
$values_user['name'] = $form_data['user_name'];
$values_user['middle_name'] = $form_data['user_middle_name'];
$values_user['surname'] = $form_data['user_surname'];
$values_user['pre_title'] = $form_data['user_pre_title'];
$values_user['post_title'] = $form_data['user_post_title'];
$values_user['member_id'] = $form_data['user_member_id'];
$values_user['birthday'] = $form_data['user_birthday'];
$values_user['do_not_call'] = $form_data['user_do_not_call'];
$values_user['do_not_send_emails'] = $form_data['user_do_not_send_emails'];
$values_user['notify_owner'] = $form_data['user_notify_owner'];
$values_user['phone1'] = $form_data['user_phone1'];
$values_user['phone2'] = $form_data['user_phone2'];
$values_user['phone3'] = $form_data['user_phone3'];
$values_user['email1'] = $form_data['user_email1'];
$values_user['email2'] = $form_data['user_email2'];
$values_user['email3'] = $form_data['user_email3'];
$values_user['street'] = $form_data['user_street'];
$values_user['town'] = $form_data['user_town'];
$values_user['country'] = $form_data['user_country'];
$values_user['zip_code'] = $form_data['user_zip_code'];
$values_user['comment'] = $form_data['user_comment'];
$issaved = true;
$issaved = $issaved && Settings::set('vtiger_domain', $form_data['vtiger_domain']);
$issaved = $issaved && Settings::set('vtiger_username', $form_data['vtiger_username']);
$issaved = $issaved && Settings::set('vtiger_user_access_key', $form_data['vtiger_user_access_key']);
$issaved = $issaved && Settings::set('vtiger_member_fields', json_encode($values_member));
$issaved = $issaved && Settings::set('vtiger_user_fields', json_encode($values_user));
if ($issaved)
// if all action were succesfull
{
status::success('System variables have been successfully updated.');
}
else
// if not
{
status::error('System variables havent been successfully updated.');
}
url::redirect('settings/vtiger');
}
$view = new View('main');
$view->title = __('Settings') . ' - ' . __('Vtiger integration');
$view->content = new View('settings/main');
$view->content->current = 'vtiger';
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff