function user_edit_conf($uid, $data = array()) { global $user_config; $ret['status'] = FALSE; $ret['error_string'] = _('No changes made'); $fields = array('footer', 'datetime_timezone', 'language_module', 'fwd_to_inbox', 'fwd_to_email', 'fwd_to_mobile', 'local_length', 'replace_zero', 'new_token', 'enable_webservices', 'webservices_ip', 'sender', 'acl_id'); $up = array(); foreach ($fields as $field) { $up[$field] = trim($data[$field]); } $up['lastupdate_datetime'] = core_adjust_datetime(core_get_datetime()); if ($uid) { if ($up['new_token']) { $up['token'] = md5(mktime() . $uid . _PID_); } unset($up['new_token']); // if sender ID is sent then validate it if ($c_sender = core_sanitize_sender($up['sender'])) { $check_sender = sender_id_check($uid, $c_sender) ? TRUE : FALSE; } else { $check_sender = TRUE; } if ($check_sender) { $up['sender'] = $c_sender; $c_footer = core_sanitize_footer($up['footer']); $up['footer'] = strlen($c_footer) > 30 ? substr($c_footer, 0, 30) : $c_footer; // acl exception for admins $c_status = (int) user_getfieldbyuid($uid, 'status'); if ($c_status == 2) { $up['acl_id'] = 0; } // self edit can't save acl if ($uid == $user_config['uid']) { unset($up['acl_id']); } if (dba_update(_DB_PREF_ . '_tblUser', $up, array('flag_deleted' => 0, 'uid' => $uid))) { if ($up['token']) { $ret['error_string'] = _('User configuration has been saved and webservices token updated'); } else { $ret['error_string'] = _('User configuration has been saved'); } $ret['status'] = TRUE; } else { $ret['error_string'] = _('Fail to save configuration'); } } else { $ret['error_string'] = _('Invalid sender ID'); } } else { $ret['error_string'] = _('Unknown error'); } return $ret; }
/** * Update sender ID * * @param integer $uid * User ID * @param string $sender_id * Sender ID * @param string $sender_id_description * Sender ID description * @param integer $isdefault * Flag 1 for default sender ID * @param integer $isapproved * Flag 1 for approved sender ID * @return boolean TRUE when new sender ID has been updated */ function sender_id_update($uid, $sender_id, $sender_id_description = '', $isdefault = '_', $isapproved = '_') { global $user_config; if (sender_id_check($uid, $sender_id)) { $default = '_'; if ($isdefault !== '_') { $default = (int) $isdefault ? 1 : 0; } if ($isapproved !== '_') { if (auth_isadmin()) { $approved = (int) $isapproved ? 1 : 0; $data_sender_id = array($sender_id => $approved); } } $sender_id_description = trim($sender_id_description) ? trim($sender_id_description) : $sender_id; $data_description = array($sender_id => $sender_id_description); $uid = auth_isadmin() && $uid ? $uid : $user_config['uid']; if ($uid) { if ($data_sender_id) { registry_update($uid, 'features', 'sender_id', $data_sender_id); } registry_update($uid, 'features', 'sender_id_desc', $data_description); } else { // unknown error return FALSE; } // set default if ($default !== '_') { if (auth_isadmin() && $default && $approved) { // set default if isadmin, default and approved sender_id_default_set($uid, $sender_id); } else { // set to empty (remove default) sender_id_default_set($uid, ''); } } return TRUE; } else { // not found return FALSE; } }