Index: openid_ax.pages.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/openid_ax/openid_ax.pages.inc,v retrieving revision 1.16 diff -u -p -r1.16 openid_ax.pages.inc --- openid_ax.pages.inc 10 Aug 2008 18:33:57 -0000 1.16 +++ openid_ax.pages.inc 9 Oct 2008 21:20:01 -0000 @@ -45,31 +45,34 @@ function openid_ax_form(&$form_state,&$a global $user; $form_state['ax_response'] = $ax_response; $realm = $form_state['post']['openid_realm']; - if($realm == '') { - $realm = $_SESSION['openid_ax']['realm']; - unset($_SESSION['openid_ax']['realm']); + + if ($realm == '') { + $realm = $_SESSION['openid_ax']['realm']; + unset($_SESSION['openid_ax']['realm']); } + $form = array(); $form['intro'] = array( '#type' => 'markup', '#value' => '

'. t('Your following details are being send to %site, would you like to continue?', array('%site' => $realm)) . '

' ); - foreach($ax_response as $name=>$value) { - if(strstr($name,'value')){ - $form[$name] = array( - '#type' => 'textfield', - '#title' => t(substr(strrchr($name,'value.'),6)), - '#value' => $value, - '#size' => 14, - '#maxlength' => 100 - ); + + foreach ($ax_response as $name => $value) { + if (strstr($name,'value')) { + $form[$name] = array( + '#type' => 'textfield', + '#title' => t(substr(strrchr($name,'value.'),6)), + '#value' => $value, + '#size' => 14, + '#maxlength' => 100 + ); } else { $form[$name] = array( - '#type' => 'hidden', - '#title' => $name, - '#value' => $value - ); + '#type' => 'hidden', + '#title' => $name, + '#value' => $value + ); } } $form['#action'] = url('openid/ax/send'); @@ -108,24 +111,29 @@ function openid_ax_persona() { */ function openid_ax_persona_form(&$form_state) { global $user; + $form = array(); - if(isset($form_state['storage']['personas'])) { - $personas = $form_state['storage']['personas']; + if (isset($form_state['storage']['personas'])) { + $personas = $form_state['storage']['personas']; + } + elseif (isset($_GET['persona'])) { + $personas = $_GET['persona']; } - elseif(isset($_GET['persona'])) { - $personas = $_GET['persona']; - } else { - $personas = 0; + $personas = 0; } + $persona = db_query("SELECT * FROM {openid_ax_persona} where uid=%d", $user->uid); $options = array(t('Default'), 'openid_ax_create_new' =>t('Create new'), 'manage_ax_personas' => t('Manage AX Personas')); - while($persona_value = db_fetch_array($persona)) { - $options[$persona_value['persona_id']] = $persona_value['persona_name']; + + while ($persona_value = db_fetch_array($persona)) { + $options[$persona_value['persona_id']] = $persona_value['persona_name']; } - if(count($options) == 3) { - unset($options['manage_ax_personas']); + + if (count($options) == 3) { + unset($options['manage_ax_personas']); } + $form['personas'] = array( '#type' => 'select', '#title' => 'Personas', @@ -136,72 +144,78 @@ function openid_ax_persona_form(&$form_s '#type' => 'submit', '#value' => 'Select Persona', '#submit' => array('openid_ax_persona_form_submit_select_persona') - ); + ); $identifiers = db_query("SELECT * FROM {openid_ax_attributes}"); - while($id = db_fetch_array($identifiers)) { - $identifier[$id['ax_id']] = $id['identifier']; + + while ($id = db_fetch_array($identifiers)) { + $identifier[$id['ax_id']] = $id['identifier']; } - $ax_values = db_query("SELECT * FROM {openid_ax_values} WHERE uid=%d and persona_id='%d'",$user->uid, $personas); + + $ax_values = db_query("SELECT * FROM {openid_ax_values} WHERE uid = %d and persona_id = '%d'", $user->uid, $personas); + $valueExist = array(); - while($row = db_fetch_array($ax_values)) { - $valueExist[] = $row['ax_id']; - $form[$row['vid']] = array( - '#type' => 'textfield', - '#title' => t($identifier[$row['ax_id']]), - '#default_value' => $row['ax_values'], - '#size' => 25, - '#maxlength' => 100 + while ($row = db_fetch_array($ax_values)) { + $valueExist[] = $row['ax_id']; + $form[$row['vid']] = array( + '#type' => 'textfield', + '#title' => t($identifier[$row['ax_id']]), + '#default_value' => $row['ax_values'], + '#size' => 25, + '#maxlength' => 100 ); - $form['has_value'.$row['vid']] = array( - '#type' => 'hidden', - '#value' => $row['vid'], - ); - static $count = 0; - $count++; - static $submit_btn = 1; - if($count == 10) { - $form['submit'.$submit_btn] = array( + $form['has_value'.$row['vid']] = array( + '#type' => 'hidden', + '#value' => $row['vid'], + ); + static $count = 0; + $count++; + static $submit_btn = 1; + if ($count == 10) { + $form['submit'.$submit_btn] = array( '#type' => 'submit', '#value' => t('Submit'), ); $count = 0; $submit_btn++; - } - $hasValues = TRUE; + } + $hasValues = TRUE; } - if($hasValues){ - $form['intro'] = array( - '#type' => 'markup', - '#value' => t('To delete a value, delete the value in the particular field and then submit'), - '#weight' => -1 + + if ($hasValues) { + $form['intro'] = array( + '#type' => 'markup', + '#value' => t('To delete a value, delete the value in the particular field and then submit'), + '#weight' => -1 ); } - foreach($identifier as $key => $value) { - if(!(in_array($key, $valueExist))){ - $form['vac'.$key] = array( - '#type' => 'textfield', - '#title' => t($value), - '#default_value' => '', - '#size' => 25, - '#maxlength' => 100 + + foreach ($identifier as $key => $value) { + if (!(in_array($key, $valueExist))) { + $form['vac'.$key] = array( + '#type' => 'textfield', + '#title' => t($value), + '#default_value' => '', + '#size' => 25, + '#maxlength' => 100 ); $form['no_value'.$key] = array( - '#type' => 'hidden', - '#value' => $key, - ); + '#type' => 'hidden', + '#value' => $key, + ); static $count = 0; - $count++; - static $submit_btn = 1; - if($count == 10) { - $form['submit'.$submit_btn] = array( + $count++; + static $submit_btn = 1; + if ($count == 10) { + $form['submit'.$submit_btn] = array( '#type' => 'submit', '#value' => t('Submit'), ); $count = 0; $submit_btn++; - } - } - } + } + } + } + $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), @@ -214,14 +228,14 @@ function openid_ax_persona_form(&$form_s */ function openid_ax_persona_form_submit_select_persona(&$form, &$form_state) { global $user; - if($form_state['values']['personas']=='openid_ax_create_new') { - drupal_goto('user/'.$user->uid.'/persona/create'); + if ($form_state['values']['personas'] == 'openid_ax_create_new') { + drupal_goto('user/'. $user->uid .'/persona/create'); } - elseif($form_state['values']['personas']=='manage_ax_personas') { - drupal_goto('user/'.$user->uid.'/persona/manage'); + elseif ($form_state['values']['personas'] == 'manage_ax_personas') { + drupal_goto('user/'. $user->uid .'/persona/manage'); } else { - $form_state['storage']['personas'] = $form_state['values']['personas']; + $form_state['storage']['personas'] = $form_state['values']['personas']; } } @@ -230,28 +244,31 @@ function openid_ax_persona_form_submit_s */ function openid_ax_persona_form_submit(&$form, &$form_state) { global $user; - $result = db_query("SELECT vid FROM {openid_ax_values} WHERE uid='%d' and persona_id='%d'",$user->uid, $form_state['values']['personas']); - static $success; - $success = FALSE; - while($vid = db_fetch_array($result)) { + + $result = db_query("SELECT vid FROM {openid_ax_values} WHERE uid= '%d' AND persona_id = '%d'", $user->uid, $form_state['values']['personas']); + static $success = FALSE; + + while ($vid = db_fetch_array($result)) { $ax_value = trim($form_state['values'][$vid['vid']]); - if(isset($form_state['values'][has_value.$vid['vid']])){ - if($ax_value != ''){ - $success = db_query("UPDATE {openid_ax_values} SET ax_values='%s' WHERE vid='%d'", $form_state['values'][$vid['vid']], $vid['vid']); - } - else { - $success = db_query("DELETE FROM {openid_ax_values} WHERE vid='%d'", $vid['vid']); - } - } + if (isset($form_state['values'][has_value.$vid['vid']])) { + if ($ax_value != '') { + $success = db_query("UPDATE {openid_ax_values} SET ax_values='%s' WHERE vid='%d'", $form_state['values'][$vid['vid']], $vid['vid']); + } + else { + $success = db_query("DELETE FROM {openid_ax_values} WHERE vid='%d'", $vid['vid']); + } + } } + $ax_ids = db_query("SELECT ax_id FROM {openid_ax_attributes}"); - while($ax_id=db_fetch_array($ax_ids)) { - if((isset($form_state['values'][no_value.$ax_id['ax_id']]))&&($form_state['values'][vac.$ax_id['ax_id']] != '')){ - $success = db_query("INSERT INTO {openid_ax_values}(ax_id, uid, persona_id, ax_values) VALUES ('%d', '%d', '%d', '%s')",$ax_id['ax_id'], $user->uid, $form_state['values']['personas'], $form_state['values'][$ax_id['ax_id']]); - } + while ($ax_id = db_fetch_array($ax_ids)) { + if ((isset($form_state['values'][no_value.$ax_id['ax_id']])) && ($form_state['values'][vac.$ax_id['ax_id']] != '')) { + $success = db_query("INSERT INTO {openid_ax_values} (ax_id, uid, persona_id, ax_values) VALUES ('%d', '%d', '%d', '%s')", $ax_id['ax_id'], $user->uid, $form_state['values']['personas'], $form_state['values'][$ax_id['ax_id']]); + } } - if($success) { - drupal_set_message(t('Your persona values have been saved')); + + if ($success) { + drupal_set_message(t('Your persona values have been saved')); } } @@ -259,7 +276,7 @@ function openid_ax_persona_form_submit(& * Page callback for creating new persona */ function openid_ax_create_persona() { - return drupal_get_form('openid_ax_new_persona_form'); + return drupal_get_form('openid_ax_new_persona_form'); } /** @@ -268,12 +285,12 @@ function openid_ax_create_persona() { function openid_ax_new_persona_form() { $form = array(); $form['persona'] = array( - '#type' =>'textfield', - '#title' => t('New Persona name'), - '#default_value' => '', - '#required' => TRUE, - '#size' => 20 - ); + '#type' =>'textfield', + '#title' => t('New Persona name'), + '#default_value' => '', + '#required' => TRUE, + '#size' => 20 + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), @@ -286,26 +303,27 @@ function openid_ax_new_persona_form() { */ function openid_ax_new_persona_form_submit(&$form, $form_state) { global $user; - $persona_exists = db_result(db_query("SELECT * FROM {openid_ax_persona} WHERE uid=%d AND persona_name='%s'", $user->uid, $form_state['values']['persona'])); - if($persona_exists) { - drupal_set_message(t('A persona with that name already exists. Please select another persona name.'),'error'); + + $persona_exists = db_result(db_query("SELECT * FROM {openid_ax_persona} WHERE uid= %d AND persona_name = '%s'", $user->uid, $form_state['values']['persona'])); + if ($persona_exists) { + drupal_set_message(t('A persona with that name already exists. Please select another persona name.'), 'error'); } else { - $max_persona_id = db_result(db_query("SELECT MAX(persona_id) FROM {openid_ax_persona} WHERE uid='%d'", $user->uid)); - $create_persona = db_query("INSERT INTO {openid_ax_persona} (uid, persona_id, persona_name) VALUES ('%d', '%d', '%s')", $user->uid, $max_persona_id+1, $form_state['values']['persona']); - if($create_persona) { - drupal_set_message(t('New Persona created')); - drupal_goto('user/'.$user->uid.'/persona'); - } + $max_persona_id = db_result(db_query("SELECT MAX(persona_id) FROM {openid_ax_persona} WHERE uid = '%d'", $user->uid)); + $create_persona = db_query("INSERT INTO {openid_ax_persona} (uid, persona_id, persona_name) VALUES ('%d', '%d', '%s')", $user->uid, $max_persona_id+1, $form_state['values']['persona']); + if ($create_persona) { + drupal_set_message(t('New Persona created')); + drupal_goto('user/'. $user->uid .'/persona'); + } } -} +} /** * Page to manage AX personas, viz, rename, delete, copy, etc. */ function openid_ax_manage_personas() { global $user; - $profiles = (db_query("SELECT * FROM {openid_ax_persona} WHERE uid=%d",$user->uid)); + $header = array ( 'Persona Name', 'Edit Persona Values', @@ -313,47 +331,52 @@ function openid_ax_manage_personas() { 'Delete Persona', ); $rows['default'] = array ( - 'Default', - 'Edit', - '-N/A-', - '-N/A-' - ); - while($profile = db_fetch_array($profiles)) { - $rows[$profile['persona_name']] = array ( - $profile['persona_name'], - 'Edit ', - 'Rename', - 'Delete', - ); + 'Default', + 'Edit', + '-N/A-', + '-N/A-' + ); + + $profiles = db_query("SELECT * FROM {openid_ax_persona} WHERE uid = %d", $user->uid); + while ($profile = db_fetch_array($profiles)) { + $rows[$profile['persona_name']] = array ( + $profile['persona_name'], + 'Edit ', + 'Rename', + 'Delete', + ); } + $content = theme_table($header, $rows); $content .= drupal_get_form('copy_persona_values_form'); return $content; } /** - * Form for selecting from to persona for values to be copied + * Form for selecting from to persona for values to be copied */ function copy_persona_values_form() { global $user; + $form = array(); - $persona = db_query("SELECT * FROM {openid_ax_persona} WHERE uid='%d'",$user->uid); $options = array(t('Default')); - while($persona_value = db_fetch_array($persona)) { - $options[$persona_value['persona_id']] = $persona_value['persona_name']; + $persona = db_query("SELECT * FROM {openid_ax_persona} WHERE uid = '%d'", $user->uid); + while ($persona_value = db_fetch_array($persona)) { + $options[$persona_value['persona_id']] = $persona_value['persona_name']; } + $form['intro'] = array( '#type' => 'markup', '#value' => t('Copy values from one persona into another:'), ); $form['from_personas'] = array( '#type' => 'select', - '#title' => 'From', + '#title' => t('From'), '#options' => $options, ); $form['to_personas'] = array( '#type' => 'select', - '#title' => 'To', + '#title' => t('To'), '#options' => $options, ); $form['submit'] = array( @@ -368,10 +391,11 @@ function copy_persona_values_form() { */ function copy_persona_values_form_submit(&$form, $form_state) { global $user; + $target_persona = $form_state['values']['to_personas']; - $copySrc = db_query("SELECT ax_id,ax_values FROM {openid_ax_values} WHERE uid='%d' AND persona_id='%d'",$user->uid, $form_state['values']['from_personas']); - while($vals = db_fetch_array($copySrc)) { - $copyTrg = db_query("INSERT INTO {openid_ax_values}(ax_id, uid, persona_id, ax_values) VALUES ('%d','%d','%d','%s')", $vals['ax_id'], $target_persona, $user->uid, $vals['ax_values']); + $copySrc = db_query("SELECT ax_id, ax_values FROM {openid_ax_values} WHERE uid = '%d' AND persona_id = '%d'", $user->uid, $form_state['values']['from_personas']); + while ($vals = db_fetch_array($copySrc)) { + $copyTrg = db_query("INSERT INTO {openid_ax_values} (ax_id, uid, persona_id, ax_values) VALUES ('%d','%d','%d','%s')", $vals['ax_id'], $target_persona, $user->uid, $vals['ax_values']); } drupal_set_message(t('Persona values copied.')); } @@ -382,7 +406,7 @@ function copy_persona_values_form_submit function openid_ax_rename_personas() { $content = drupal_get_form('openid_ax_rename_persona_form', $_GET['p']); $content .= openid_ax_manage_personas(); - return $content; + return $content; } /** @@ -390,9 +414,11 @@ function openid_ax_rename_personas() { */ function openid_ax_rename_persona_form(&$form, $form_state) { global $user; - isset($_GET['p'])?$persona_id=$_GET['p']:$persona_id=$form_state['storage']['persona_id']; + + $persona_id = (isset($_GET['p'])) ? $_GET['p'] : $form_state['storage']['persona_id']; $form = array(); - $persona = db_result(db_query("SELECT persona_name FROM {openid_ax_persona} WHERE persona_id='%d' AND uid='%d'",$persona_id, $user->uid)); + $persona = db_result(db_query("SELECT persona_name FROM {openid_ax_persona} WHERE persona_id = '%d' AND uid = '%d'", $persona_id, $user->uid)); + $form['persona'] = array( '#type' => 'textfield', '#default_value' => $persona, @@ -404,7 +430,7 @@ function openid_ax_rename_persona_form(& ); $form['submit'] = array ( '#type' => 'submit', - '#value' => 'Rename', + '#value' => t('Rename'), ); return $form; } @@ -414,7 +440,8 @@ function openid_ax_rename_persona_form(& */ function openid_ax_rename_persona_form_submit(&$form, &$form_state) { global $user; - $rename = db_query("UPDATE {openid_ax_persona} SET persona_name='%s' WHERE uid='%d' AND persona_id='%d'", $form_state['values']['persona'], $user->uid, $form_state['values']['persona_id']); + + $rename = db_query("UPDATE {openid_ax_persona} SET persona_name = '%s' WHERE uid = '%d' AND persona_id = '%d'", $form_state['values']['persona'], $user->uid, $form_state['values']['persona_id']); drupal_set_message(t('Your persona has been renamed')); $form_state['storage']['persona_id'] = $form_state['values']['persona_id']; } @@ -424,9 +451,10 @@ function openid_ax_rename_persona_form_s */ function openid_ax_persona_delete() { global $user; - $persona_id=$_GET['p']; - $persona = db_result(db_query("SELECT persona_name FROM {openid_ax_persona} WHERE persona_id='%d' AND uid='%d'",$persona_id, $user->uid)); - $content = t('Are you sure you want to delete your %profile profile.', array('%profile' => $persona)); + + $persona_id = $_GET['p']; + $persona = db_result(db_query("SELECT persona_name FROM {openid_ax_persona} WHERE persona_id = '%d' AND uid = '%d'", $persona_id, $user->uid)); + $content = t('Are you sure you want to delete your %profile profile.', array('%profile' => $persona)); $content .= t(' This cannot be reversed and all your profile related details will be lost.'); $content .= drupal_get_form('openid_ax_persona_delete_confirm_form'); return $content; @@ -458,11 +486,12 @@ function openid_ax_persona_delete_confir */ function openid_ax_persona_delete_confirm_form_submit($form, &$form_state) { global $user; - $delValues = db_query("DELETE FROM {openid_ax_values} WHERE uid='%d' AND persona_id='%d'", $user->uid, $form_state['values']['persona_id']); - $deletePersona = db_query("DELETE FROM {openid_ax_persona} WHERE uid='%d' AND persona_id='%d'", $user->uid, $form_state['values']['persona_id']); - if($delValues && $deletePersona) { - drupal_set_message(t('Persona deleted.')); - drupal_goto('user/'.$user->uid.'/persona/manage'); + + $delValues = db_query("DELETE FROM {openid_ax_values} WHERE uid = '%d' AND persona_id = '%d'", $user->uid, $form_state['values']['persona_id']); + $deletePersona = db_query("DELETE FROM {openid_ax_persona} WHERE uid = '%d' AND persona_id = '%d'", $user->uid, $form_state['values']['persona_id']); + if ($delValues && $deletePersona) { + drupal_set_message(t('Persona deleted.')); + drupal_goto('user/'. $user->uid .'/persona/manage'); } } @@ -471,5 +500,5 @@ function openid_ax_persona_delete_confir */ function openid_ax_persona_delete_confirm_form_cancel() { global $user; - drupal_goto('user/'.$user->uid.'/persona/manage'); -} \ No newline at end of file + drupal_goto('user/'. $user->uid .'/persona/manage'); +}