function update_prefs() { prepare_company_website_controller($this, 'account'); $user = logged_user(); if (!$user instanceof User) { flash_error(lang('user dnx')); $this->redirectTo('dashboard'); } // if $company = $user->getCompany(); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectToReferer(get_url('administration')); } // if if (!$user->canUpdateProfile(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard'); } // if $redirect_to = array_var($_GET, 'redirect_to'); if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) { $redirect_to = $user->getCardUrl(); } // if $this->setTemplate('edit_preferences'); $reminder_prefs = Reminders::findById(logged_user()->getId()); if (!$reminder_prefs instanceof Reminder) { $reminder_prefs = new Reminder(); } $prefs_form = array_var($_POST, 'prefs_form'); $reminder_prefs->setUserId(logged_user()->getId()); $reminder_prefs->setRemindersEnabled($prefs_form['reminders_enabled']); $reminder_prefs->setSummarizedBy($prefs_form['summarized_by']); $reminder_prefs->setRemindersFuture($prefs_form['future']); $reminder_prefs->setIncludeEveryone($prefs_form['ivsteam']); $weekArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); $days = ''; for ($i = 0; $i < 7; $i++) { if (isset($prefs_form[$weekArray[$i]])) { $days .= "" . $weekArray[$i] . ","; } } $reminder_prefs->setReminderDaysToSend($days); $reminder_prefs->setReportsEnabled($prefs_form['reports_enabled']); $reminder_prefs->setReportsSummarizedBy($prefs_form['reports_summarized']); $reminder_prefs->setReportsIncludeEveryone($prefs_form['ivsteam2']); $reminder_prefs->setReportDay($prefs_form['reportDay']); $reminder_prefs->setReportsIncludeActivity($prefs_form['report_activity']); try { DB::beginWork(); $reminder_prefs->save(); DB::commit(); flash_success(lang('prefs updated')); } catch (Exception $e) { DB::rollback(); flash_error('Error: ' . $e); } $dayOfWeek = ConfigOptions::getByName('calendar_first_day_of_week'); tpl_assign('dayOfWeek', $dayOfWeek->getValue()); tpl_assign('redirect_to', $redirect_to); tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('reminder_prefs', $reminder_prefs); }