page refreshing

crinch - November 2, 2007 - 07:59

Hi

I want to know how to refresh a page in drupal.

Thanks
CRINCH

Clear the cache (or...

pobster - November 2, 2007 - 09:27

Clear the cache (or... don't use the cache?) to have an admin menu item to do this, install the devel module.

Pobster

thanks for your

crinch - November 2, 2007 - 09:58

thanks for your consideration.......
I have used cache_clear_all() but could not get my desired result. I think I should explain my issue.... I am using a function that inserts/makes the user's root album in the database after that beneath it I have created a form to select the user its root or desired album to create its own album in that one. Logically it should show show the user's root album with other albums also. But it does not show that and show if I refresh the page with F5. It is true that the user's root album ID is inserted in the database but doesn't show unless refresh the page. I think the whole structure/data is extracted from the database before creating the user's root album in the database. Therefore I need to refresh the page but it is useless.
The code is......

function test_page($gid = NULL) {
cache_clear_all();
        global $user;
  if(module_exists('acidfree')){
          if (variable_get('acidfree_per_user_albums', false)) {
  drupal_set_message(t('per user album'));  
        $tid = acidfree_get_root($user->uid, true);
        if (!$tid)
            return drupal_not_found();
        $nid = _nid_from_tid($tid);
  } // end of if for acidfree_per_user_albums
              }// end of if for module_exist
  $forms_arr = array('blog','acidfree','article','event','invitation');
  for($i=0; $i<count($forms_arr); $i++){
  $output .= drupal_get_form('test_form_'.$forms_arr[$i], $forms_arr[$i], $gid);
  }     
  return $output;
} // end of function test_page

function test_form_acidfree($cat_arr, $gid = NULL){
global $user;
  if(module_exists('acidfree')){  
$gids[]=$gid;

  $row_acidfree_form = Array();
  if($user->uid)
  $row_acidfree_form['uid'] = $user->uid;
  else 
  $row_acidfree_form['uid'] = '0';
  $group_type = 'acidfree';
  $sql = "SELECT * from node_type where type='acidfree'";
  $result = db_query($sql);
  $row_acidfree_form = db_fetch_object($result);
//  $form['#id'] = 'newsite_acidfree'; 
$form['#id'] = 'test_form_'.$cat_arr;   
$form['newsite_acidfree'] = array(
  '#type' => 'fieldset',
  '#title' => t('Would you start your photo album now?'),
  '#weight' => 3,
   '#collapsible' => TRUE,
   '#collapsed' => TRUE,
   '#prefix' => '<div class="node-form">',
   '#suffix' => '</div>',
);
  $form['newsite_acidfree']['gid'] = array('#type' => 'hidden',  
   '#title' => t(''),
   '#value' => $gid,
  );
$form['newsite_acidfree'] = array_merge_recursive($form['newsite_acidfree'], node_invoke($row_acidfree_form->type, 'form', $gids));
    $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $group_type);
    while ($vocabulary = db_fetch_object($c)) {
      if ($vocabulary->tags) {
        $typed_terms = array();
        foreach ($terms as $term) {
          // Extract terms belonging to the vocabulary in question.
          if ($term->vid == $vocabulary->vid) {

            // Commas and quotes in terms are special cases, so encode 'em.
            if (strpos($term->name, ',') !== FALSE || strpos($term->name, '"') !== FALSE) {
              $term->name = '"'.str_replace('"', '""', $term->name).'"';
            }

            $typed_terms[] = $term->name;
          }
        }
        $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);

        if ($vocabulary->help) {
          $help = $vocabulary->help;
        }
        else {
          $help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
        }
        $form['newsite_acidfree']['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
          '#title' => $vocabulary->name,
          '#description' => $help,
          '#required' => $vocabulary->required,
          '#default_value' => $typed_string,
          '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
          '#weight' => $vocabulary->weight,
          '#maxlength' => 255,
        );
      }
      else {
        // Extract terms belonging to the vocabulary in question.
        $default_terms = array();
        foreach ($terms as $term) {
          if ($term->vid == $vocabulary->vid) {
            $default_terms[$term->tid] = $term;
          }
        }
        $form['newsite_acidfree']['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
        $form['newsite_acidfree']['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
        $form['newsite_acidfree']['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
      }
    }
    if (is_array($form['newsite_acidfree']['taxonomy']) && !empty($form['newsite_acidfree']['taxonomy'])) {
      if (count($form['newsite_acidfree']['taxonomy']) > 1) { // Add fieldset only if form has more than 1 element.
        $form['newsite_acidfree']['taxonomy'] += array(
          '#type' => 'fieldset',
          '#title' => t('Categories'),
          '#collapsible' => TRUE,
          '#collapsed' => FALSE,
        );
      }
      $form['newsite_acidfree']['taxonomy']['#weight'] = -3;
      $form['newsite_acidfree']['taxonomy']['#tree'] = TRUE;
    }
///////////////////////////////////////////////getting from og/////////////////////////////////
  $required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
  if (user_access('administer nodes')) {
    $options = og_all_groups_options();
  }
  else {
    $subs = og_get_subscriptions($user->uid);   //changed
    foreach ($subs as $key => $val) {
      $options[$key] = $val['title'];
    }
  }
$vis = variable_get('og_visibility', 0);
  if (user_access('administer organic groups') && $vis < 2) {
    $vis = $vis == OG_VISIBLE_GROUPONLY ? OG_VISIBLE_CHOOSE_PRIVATE : OG_VISIBLE_CHOOSE_PUBLIC;
  }
  elseif (!count($options)) {
    // don't show checkbox if no subscriptions. must be public.
    $vis = OG_VISIBLE_BOTH;
  }
  switch ($vis) {
    case OG_VISIBLE_BOTH:
      $form['newsite_acidfree']['og_public'] = array('#type' => 'value', '#value' => 1);
      break;
    case OG_VISIBLE_GROUPONLY:
      $form['newsite_acidfree']['og_public'] = array('#type' => 'value', '#value' => 0);
      break;

    //user decides how public the post is.
    case OG_VISIBLE_CHOOSE_PUBLIC:
      $form['newsite_acidfree']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 1, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
      break;
    case OG_VISIBLE_CHOOSE_PRIVATE:
      $form['newsite_acidfree']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 0, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
      break;
  }
  $simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE) && count($gids);
    if (count($options) == 1 && $required) {
    $gids = array_keys($options);
    $gid = $gids[0];
    $groups = array($gid);
    // also show read only mode if user has 1 option and we are in required mode
    $simple = TRUE;
  }
  elseif ($gids) {
   // populate field from the querystring if sent
   $groups = $gids;  
   if (!user_access('administer nodes')) {
     // filter out any groups where author is not a member. we cannot rely on fapi to do this when in simple mode.
     $groups = array_intersect($gids, array_keys($options));
   }
  }
  elseif ($node->nid || $node->og_groups) {
    $groups = $node->og_groups;
  }
  else {
    $groups = array();
  }

  if ($simple) {
    // 'simple' mode. read only.
    if (count($groups)) {
      foreach ($groups as $gid) {
        $titles[] = $options[$gid];
        $item_value = implode(', ', $titles);
      }
      $form['newsite_acidfree']['visible']['og_groups_visible'] = array('#type' => 'item', '#title' => t('Audience'), '#value' => $item_value);
      $assoc_groups = drupal_map_assoc($groups);
      // this hidden element persists audience values during a Preview cycle. avoids errors on Preview.
      $form['newsite_acidfree']['invisible']['og_groups_hidden'] = array('#type' => 'hidden', '#value' => serialize($assoc_groups));
      // this 'value' element persists the audience value during submit process
      $form['newsite_acidfree']['invisible']['og_groups'] = array('#type' => 'value', '#value' => $assoc_groups);
    }
  }
  elseif ($cnt = count($options)) {
    drupal_add_js(drupal_get_path('module', 'og'). '/og.js');
    // show multi-select. if less than 20 choices, use checkboxes.
    $type = $cnt >= 20 ? 'select' : 'checkboxes';
    $form['newsite_acidfree']['visible']['og_groups'] = array(
      '#type' => $type,
      '#title' => t('Audience'),
      '#attributes' => array('class' => 'og-audience'),
      '#options' => $options,
      '#required' => $required,
      '#description' =>  format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.'),
      '#default_value' => $gids,
      '#required' => $required,
      '#multiple' => TRUE);
  }
  else if ($required) {
    form_set_error('title', t('You must !join before posting a %type.', array('!join' => l(t('join a group'), 'og'), '%type' => node_get_types('name', $node->type))));
  }
 
  if (count($form['newsite_acidfree']['visible']) > 1) {
    $form['newsite_acidfree']['#type'] = 'fieldset';
    $form['newsite_acidfree']['#title'] = t('Groups');
    $form['newsite_acidfree']['#collapsible'] = TRUE;
    $form['newsite_acidfree']['#collapsed'] = $gids ? TRUE : FALSE;
  }
  if (module_exists('og_author')){
$form['newsite_acidfree']['author']['og_author'] = array('#type' => 'select',
                                                       '#title' => t('Author group'),
                                                       '#options' => $options,
                                                       '#required' => $required,
                                                       '#description' =>  t('Select the group that will be authoring this post.'),
                                                       '#required' => $required,
                                                       '#multiple' => FALSE);
    $form['newsite_acidfree']['author']['#type'] = 'fieldset';
    $form['newsite_acidfree']['author']['#title'] = t('Author group');
    $form['newsite_acidfree']['author']['#collapsible'] = TRUE;
    $form['newsite_acidfree']['author']['#weight'] = 1;  
} // end of if for module_exists('og_author')
//////////////////////////////////////////////end /////////////////////////////////////////////
//////////////////////////////////////start upload module////////////////////////////////////////////////////////////////////
      drupal_add_js('misc/progress.js');
      drupal_add_js('misc/upload.js');
      $form['newsite_acidfree']['attachments'] = array(
        '#type' => 'fieldset',
        '#access' => user_access('upload files'),
        '#title' => t('File attachments'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($node->files),
        '#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
        '#prefix' => '<div class="attachments">',
        '#suffix' => '</div>',
        '#weight' => 30,
      );
      // Wrapper for fieldset contents (used by upload JS).
      $form['newsite_acidfree']['attachments']['wrapper'] = array(
        '#prefix' => '<div id="attach-wrapper">',
        '#suffix' => '</div>',
      );
      // Make sure necessary directories for upload.module exist and are
      // writable before displaying the attachment form.
      $path = file_directory_path();
      $temp = file_directory_temp();
      // Note: pass by reference
      if (!file_check_directory($path, FILE_CREATE_DIRECTORY) || !file_check_directory($temp, FILE_CREATE_DIRECTORY)) {  
        $form['newsite_acidfree']['attachments']['#description'] =  t('File attachments are disabled. The file directories have not been properly configured.');
        if (user_access('administer site configuration')) {
  drupal_set_message(t('I am in fifth if condition')); 
          $form['newsite_acidfree']['attachments']['#description'] .= ' '. t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/settings/file-system')));
        }
        else {
          $form['newsite_acidfree']['attachments']['#description'] .= ' '. t('Please contact the site administrator.');
        }
      }
      else {
        $form['newsite_acidfree']['attachments']['wrapper'] += _upload_form($node);
        $form['newsite_acidfree']['#attributes']['enctype'] = 'multipart/form-data';
      }    
//////////////////////////////////////////////end /////////////////////////////////////////////
      $form['newsite_acidfree']['Submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit Album',
'#weight' => 45,
      );
return $form;
  }  // end of if for module_exist
  else
  drupal_set_message('Acidfree module does not active/exist');

} // end of function test_form_album

If the desired the result is not get after refreshing(cache_clear_all()) the page, the information of the nodes should be extracted from the database after inserting the user's root album in the database to show the user's root album in the parent dropdown(albums).

Is there any solution, help is required, I have already spent a lot of time on it.

Thanks
CRINCH

Sorry but I took one look at

pobster - November 2, 2007 - 22:36

Sorry but I took one look at all that unstructured code and lost interest...

I tried to follow it, but it's unclear and uncommented and I'm really not interested enough to actually install it on one of my own installations to debug it - I can see several things weird about it without even trying (an 'else' without any curly brackets, foreach ($terms... and $terms is undefined... I could go on but I've lost interest). Honestly, I can't see anyone helping you with this unless perhaps you post in the Drupal 'paid help' forum... There's just too much wrong here...

Pobster

 
 

Drupal is a registered trademark of Dries Buytaert.