You are here

function template_preprocess_filedepot_notifications in filedepot 7

Same name and namespace in other branches
  1. 6 lib-theme.php \template_preprocess_filedepot_notifications()

File

./lib-theme.php, line 918
lib-theme.php Theme support functions for the module

Code

function template_preprocess_filedepot_notifications(&$variables) {
  global $user;
  $filedepot = filedepot_filedepot();
  $variables['LANG_files_menuitem'] = t('Files');
  $variables['LANG_folder_menuitem'] = t('Folders');
  $variables['LANG_history_menuitem'] = t('Notification History');
  $variables['LANG_settings_menuitem'] = t('Settings');
  $variables['LANG_filename'] = t('File Name');
  $variables['LANG_folder'] = t('Folder');
  $variables['LANG_dateadded'] = t('Date Added');
  $variables['LANG_action'] = t('Action');
  $variables['LANG_newfiles'] = t('New Files');
  $variables['LANG_changes'] = t('Changes');
  $variables['LANG_historymsg'] = t('Log of notification emails sent - max 100');
  $variables['LANG_clearhistory'] = t('Clear History');
  $variables['LANG_date'] = t('Date');
  $variables['LANG_type'] = t('Type');
  $variables['LANG_submitter'] = t('Submitter');
  $variables['LANG_file'] = t('File');
  $variables['LANG_savesettings'] = t('Save Settings');
  $variables['LANG_settingheading'] = t('Setup your personal notification defaults. Individual folder and file notifications can also be used to over-ride these defaults.');
  $variables['LANG_settingline1'] = t('If you want to be notified of all new new files being added for all folders you have access, then you only need to enable the setting here');
  $variables['LANG_settingline2'] = t('If you only want to be notified of new files being added to selected folders, then disable the setting here and enable the notification for those selected folders only');
  $variables['LANG_settingline3'] = t('Folder Notification options are set by first selecting that folder and once the folder listing is in the main right panel, click on the folder name in the main right panel above the file listing to view/update the notification options');
  $variables['LANG_settingline4'] = t('Broadcast Notifications can be sent out by folder administrators  even if you are not subscribed to updates unless you disable broadcasts here');
  $variables['LANG_personalsettings'] = t('Personal Notification Setting');
  $variables['LANG_default'] = t('Default');
  $variables['LANG_newfilesadded'] = t('New Files being added');
  $variables['LANG_filesupdated'] = t('Files updated');
  $variables['LANG_allowadminbroadcasts'] = t('Allow Admin Broadcasts');
  $variables['history_records'] = '';
  $variables['file_records'] = '';
  $variables['folder_records'] = '';
  $sql = "SELECT a.id,a.fid,a.cid,a.date,cid_newfiles,cid_changes FROM {filedepot_notifications} a ";
  $sql .= "WHERE uid={$user->uid} AND a.ignore_filechanges = 0 ORDER BY a.date DESC";
  $query = db_query($sql);
  while ($A = $query
    ->fetchAssoc()) {
    if ($A['fid'] != 0) {
      $variables['file_records'] .= theme('filedepot_notifications_file', array(
        'rec' => $A,
      ));
    }
    elseif ($A['cid'] > 0) {
      $variables['folder_records'] .= theme('filedepot_notifications_folder', array(
        'rec' => $A,
      ));
    }
  }
  if (variable_get('filedepot_default_notify_newfile', 0) == 1) {
    $variables['chk_fileadded_on'] = 'CHECKED=checked';
  }
  else {
    $variables['chk_fileadded_off'] = 'CHECKED=checked';
  }
  if (variable_get('filedepot_default_notify_filechange', 0) == 1) {
    $variables['chk_filechanged_on'] = 'CHECKED=checked';
  }
  else {
    $variables['chk_filechanged_off'] = 'CHECKED=checked';
  }
  if (variable_get('filedepot_default_allow_broadcasts', 0) == 1) {
    $variables['chk_broadcasts_on'] = 'CHECKED=checked';
  }
  else {
    $variables['chk_broadcasts_off'] = 'CHECKED=checked';
  }
  $qsettings = db_query("SELECT * FROM {filedepot_usersettings} WHERE uid=:uid", array(
    ':uid' => $user->uid,
  ));
  if ($qsettings) {
    $A = $qsettings
      ->fetchAssoc();
    if ($A['notify_newfile'] == 1) {
      $variables['chk_fileadded_off'] = '';
      $variables['chk_fileadded_on'] = 'CHECKED=checked';
    }
    else {
      $variables['chk_fileadded_on'] = '';
      $variables['chk_fileadded_off'] = 'CHECKED=checked';
    }
    if ($A['notify_changedfile'] == 1) {
      $variables['chk_filechanged_off'] = '';
      $variables['chk_filechanged_on'] = 'CHECKED=checked';
    }
    else {
      $variables['chk_filechanged_on'] = '';
      $variables['chk_filechanged_off'] = 'CHECKED=checked';
    }
    if ($A['allow_broadcasts'] == 1) {
      $variables['chk_broadcasts_off'] = '';
      $variables['chk_broadcasts_on'] = 'CHECKED=checked';
    }
    else {
      $variables['chk_broadcasts_on'] = '';
      $variables['chk_broadcasts_off'] = 'CHECKED=checked';
    }
  }

  // Generate the user notification history - last 100 records
  $sql = "SELECT a.submitter_uid,a.notification_type,a.fid,b.fname,b.title,a.cid,c.name,a.datetime,d.name " . "FROM {filedepot_notificationlog} a " . "LEFT JOIN {filedepot_files} b ON b.fid=a.fid " . "LEFT JOIN {filedepot_categories} c ON c.cid=a.cid " . "LEFT JOIN {users} d ON d.uid=a.submitter_uid " . "WHERE a.target_uid={$user->uid} " . "ORDER BY a.datetime DESC ";
  $query = db_query_range($sql, 0, 100);
  $cssid = 1;
  while ($A = $query
    ->fetchAssoc()) {
    $variables['history_records'] .= theme('filedepot_notifications_history', array(
      'rec' => $A,
    ));
  }
}