You are here

function birthdays_sync_form_submit in Birthdays 5

Implementation of hook_form_submit().

File

./birthdays.module, line 244
The Birthdays module allows users to add their birthday to their profile. It lists birthdays on a seperate page and in different blocks. Users can receive an e-mail on their birthday automatically, and the administrator can receive daily reminders of…

Code

function birthdays_sync_form_submit($form_id, $values) {
  global $_birthdays_field;
  if ($values['op'] == t('Copy Profile data to Birthdays module')) {
    $result = db_query('SELECT uid FROM {users}');
    while ($uid = db_fetch_object($result)) {
      $account = user_load(array(
        'uid' => $uid->uid,
      ));
      if ($account->{$_birthdays_field->name}) {
        user_save($account, array(
          $_birthdays_field->name => $account->{$_birthdays_field->name},
        ));
      }
    }
  }
  else {
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $result = db_query('SELECT {dob}.uid, MONTH({dob}.birthday) AS month, YEAR({dob}.birthday) AS year, DAYOFMONTH({dob}.birthday) AS day FROM {dob}');
        break;
      case 'pgsql':
        $result = db_query("SELECT uid, date_part('month',{dob}.birthday) AS month, date_part('year',{dob}.birthday) AS year, date_part('day',{dob}.birthday) AS day FROM {dob}");
        break;
    }
    while ($birthday = db_fetch_object($result)) {
      $account = user_load(array(
        'uid' => $birthday->uid,
      ));
      $dob = array(
        'day' => $birthday->day,
        'month' => $birthday->month,
        'year' => $birthday->year,
      );
      user_save($account, array(
        $_birthdays_field->name => $dob,
      ));
    }
  }
  drupal_set_message(t('Modules have been synchronized.'));
}