Ejemplo n.º 1
0
 public static function submit_contact($values, $mode)
 {
     switch ($mode) {
         case 'cloning':
             $values['login'] = '';
             return $values;
         case 'display':
             // display copy company data button and do update if needed
             self::copy_company_data_subroutine($values);
             $is_employee = false;
             if (isset($values['related_companies']) && is_array($values['related_companies']) && in_array(CRM_ContactsCommon::get_main_company(), $values['related_companies'])) {
                 $is_employee = true;
             }
             if (isset($values['company_name']) && $values['company_name'] == CRM_ContactsCommon::get_main_company()) {
                 $is_employee = true;
             }
             $me = CRM_ContactsCommon::get_my_record();
             $emp = array($me['id']);
             $cus = array();
             if ($is_employee) {
                 $emp[] = $values['id'];
             } else {
                 $cus[] = 'P:' . $values['id'];
             }
             $ret = array();
             $ret['new'] = array();
             $ret['new']['crm_filter'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('Set CRM Filter')) . ' ' . Module::create_href(array('set_crm_filter' => 1)) . '>F</a>';
             if (isset($_REQUEST['set_crm_filter'])) {
                 CRM_FiltersCommon::set_profile('c' . $values['id']);
             }
             if (ModuleManager::is_installed('CRM/Meeting') !== -1 && Utils_RecordBrowserCommon::get_access('crm_meeting', 'add')) {
                 $ret['new']['event'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Meeting')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png') . '"></a>';
             }
             if (ModuleManager::is_installed('CRM/Tasks') !== -1 && Utils_RecordBrowserCommon::get_access('task', 'add')) {
                 $ret['new']['task'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Task')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('task', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png') . '"></a>';
             }
             if (ModuleManager::is_installed('CRM/PhoneCall') !== -1 && Utils_RecordBrowserCommon::get_access('phonecall', 'add')) {
                 $ret['new']['phonecall'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Phonecall')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('phonecall', array('date_and_time' => date('Y-m-d H:i:s'), 'customer' => 'P:' . $values['id'], 'employees' => $me['id'], 'status' => 0, 'permission' => 0, 'priority' => 1), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_PhoneCall', 'icon-small.png') . '"></a>';
             }
             $ret['new']['note'] = Utils_RecordBrowser::$rb_obj->add_note_button('contact/' . $values['id']);
             return $ret;
         case 'adding':
             $values['permission'] = Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission');
             break;
         case 'add':
             if (isset($values['email']) && $values['email'] == '' && $values['login'] != 0 && $mode == 'add') {
                 $values['email'] = DB::GetOne('SELECT mail FROM user_password WHERE user_login_id=%d', array($values['login']));
             }
         case 'edit':
             if (isset($values['create_company'])) {
                 $comp_id = Utils_RecordBrowserCommon::new_record('company', array('company_name' => $values['create_company_name'], 'address_1' => $values['address_1'], 'address_2' => $values['address_2'], 'country' => $values['country'], 'city' => $values['city'], 'zone' => isset($values['zone']) ? $values['zone'] : '', 'postal_code' => $values['postal_code'], 'phone' => $values['work_phone'], 'fax' => $values['fax'], 'web_address' => $values['web_address'], 'permission' => $values['permission']));
                 if (!isset($values['company_name'])) {
                     $values['company_name'] = null;
                 }
                 if (!isset($values['related_companies'])) {
                     $values['related_companies'] = array();
                 }
                 if (!is_array($values['related_companies'])) {
                     $values['related_companies'] = array($values['related_companies']);
                 }
                 if (!$values['company_name']) {
                     $values['company_name'] = $comp_id;
                 } else {
                     $values['related_companies'][] = $comp_id;
                 }
             }
             if (Base_AclCommon::i_am_admin()) {
                 if ($values['login'] == 'new') {
                     if (!$values['set_password']) {
                         $values['set_password'] = null;
                     }
                     Base_User_LoginCommon::add_user($values['username'], $values['email'], $values['set_password']);
                     $values['login'] = Base_UserCommon::get_user_id($values['username']);
                 } else {
                     if ($values['login']) {
                         Base_User_LoginCommon::change_user_preferences($values['login'], isset($values['email']) ? $values['email'] : '', isset($values['set_password']) ? $values['set_password'] : null);
                         if (isset($values['username']) && $values['username']) {
                             Base_UserCommon::rename_user($values['login'], $values['username']);
                         }
                     }
                 }
                 if (Base_AclCommon::i_am_sa() && $values['login'] && isset($values['admin']) && $values['admin'] !== '') {
                     $old_admin = Base_AclCommon::get_admin_level($values['login']);
                     if ($old_admin != $values['admin']) {
                         $admin_arr = array(0 => 'No', 1 => 'Administrator', 2 => 'Super Administrator');
                         if (Base_UserCommon::change_admin($values['login'], $values['admin']) !== true) {
                             Utils_RecordBrowserCommon::new_record_history('contact', $values['id'], 'Admin set from "' . $admin_arr[$old_admin] . '" to "' . $admin_arr[$values['admin']]);
                         }
                     }
                 }
             }
             unset($values['admin']);
             unset($values['username']);
             unset($values['set_password']);
             unset($values['confirm_password']);
     }
     return $values;
 }
Ejemplo n.º 2
0
 public function submit_edit_user_form($data)
 {
     $mail = $data['mail'];
     $username = $data['username'];
     if (DEMO_MODE) {
         print 'You cannot change user password or e-mail address in demo';
         return false;
     }
     $pass = $data['pass'];
     $edit_id = $this->get_unique_href_variable('edit_user');
     if ($edit_id < 0) {
         if (!Base_User_LoginCommon::add_user($username, $mail, $pass)) {
             return false;
         }
         $edit_id = Base_UserCommon::get_user_id($username);
     } else {
         Base_UserCommon::rename_user($edit_id, $username);
         if (Base_User_LoginCommon::change_user_preferences($edit_id, $mail, $pass) === false) {
             print __('Unable to update account data (password and mail).');
             return false;
         }
         if (!Base_UserCommon::change_active_state($edit_id, $data['active'])) {
             print __('Unable to update account data (active).');
             return false;
         }
     }
     if (!Base_UserCommon::change_admin($edit_id, $data['admin'])) {
         print __('Unable to update account data (admin).');
         return false;
     }
     return true;
 }